gb/mmio/serial.rs
1//! Serial transfer (`SB`, `SC`).
2
3use bitfield_struct::bitfield;
4use voladdress::{Safe, VolAddress};
5
6/// Serial transfer control (`SC`).
7///
8/// | Bit | Field | Access | Meaning |
9/// |-----|-------|--------|---------|
10/// | 7 | `transfer_enable` | R/W | Transfer requested / in progress. |
11/// | 6-2 | — | | Unused. |
12/// | 1 | `clock_speed` | R/W | Fast clock (CGB only). |
13/// | 0 | `clock_select` | R/W | Use the internal clock (this Game Boy drives the transfer). |
14#[bitfield(u8)]
15#[derive(PartialEq, Eq)]
16pub struct SerialCtrl {
17 /// Use the internal clock (this Game Boy drives the transfer).
18 pub clock_select: bool,
19 /// Fast clock (CGB only).
20 pub clock_speed: bool,
21 #[bits(5)]
22 __: u8,
23 /// Transfer requested / in progress.
24 pub transfer_enable: bool,
25}
26
27/// Serial transfer data (the byte shifted in/out).
28pub const SB: VolAddress<u8, Safe, Safe> = unsafe { VolAddress::new(0xFF01) };
29/// Serial transfer control.
30pub const SC: VolAddress<SerialCtrl, Safe, Safe> = unsafe { VolAddress::new(0xFF02) };
31
32const _: () = {
33 assert!(SerialCtrl::new().with_transfer_enable(true).into_bits() == 0b1000_0000);
34 assert!(SerialCtrl::new().with_clock_select(true).into_bits() == 0b0000_0001);
35};