fix: switch to bitfield macros in serial.rs
This commit is contained in:
parent
d0410c4dfd
commit
f57cf2b312
|
@ -1,29 +1,41 @@
|
||||||
|
use bitfield::bitfield;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Debug, Clone, Copy, Default)]
|
||||||
pub struct Serial {
|
pub struct Serial {
|
||||||
pub next: u8,
|
pub next: u8,
|
||||||
pub control: SerialControl,
|
pub control: SerialControl,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
bitfield! {
|
||||||
pub struct SerialControl {
|
pub struct SerialControl(u8);
|
||||||
transfer_start: bool,
|
impl Debug;
|
||||||
speed: ClockSpeed, // CGB Only
|
pub transfer_start, set_transfer_start: 7;
|
||||||
shift: ShiftClock,
|
// pub from into ClockSpeed, speed, set_speed: 1; (CGB Only)
|
||||||
|
pub from into ShiftClock, shift, set_shift: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Copy for SerialControl {}
|
||||||
|
impl Clone for SerialControl {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for SerialControl {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u8> for SerialControl {
|
impl From<u8> for SerialControl {
|
||||||
fn from(byte: u8) -> Self {
|
fn from(byte: u8) -> Self {
|
||||||
Self {
|
Self(byte)
|
||||||
transfer_start: byte >> 7 == 0x01,
|
|
||||||
speed: ((byte >> 1) & 0x01).into(),
|
|
||||||
shift: (byte & 0x01).into(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SerialControl> for u8 {
|
impl From<SerialControl> for u8 {
|
||||||
fn from(control: SerialControl) -> Self {
|
fn from(ctrl: SerialControl) -> Self {
|
||||||
(control.transfer_start as u8) << 7 | (control.speed as u8) << 1 | control.shift as u8
|
ctrl.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue