mirror of
https://github.com/italicsjenga/gba.git
synced 2025-01-10 02:51:31 +11:00
SioSerial improvements (#100)
Make a few improvements to the SioSerial struct: - Have init() return Self. It's more ergonomic to create and initialize the empty struct in one call. - Enable FIFO. The GBA has a 4-byte UART FIFO. This makes it less likely to lose received bytes. - Derive Clone on SioSerial so it can be split and shared with an interrupt. - Derive Debug on SioError so results can be unwrapped.
This commit is contained in:
parent
d52d627113
commit
00897a0657
|
@ -1,5 +1,5 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![feature(start)]
|
||||||
|
|
||||||
// _ Link Cable Pinout
|
// _ Link Cable Pinout
|
||||||
// ___/ \___ 1: VCC - 3.3V
|
// ___/ \___ 1: VCC - 3.3V
|
||||||
|
@ -20,8 +20,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||||
|
|
||||||
#[start]
|
#[start]
|
||||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||||
let mut serial = SioSerial;
|
let mut serial = SioSerial::init(BaudRate::Bps115200);
|
||||||
SioSerial::init(BaudRate::Bps115200);
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Ok(c) = block!(serial.read()) {
|
if let Ok(c) = block!(serial.read()) {
|
||||||
|
|
|
@ -124,12 +124,13 @@ newtype_enum! {
|
||||||
|
|
||||||
/// Empty stuct that implements embedded_hal traits.
|
/// Empty stuct that implements embedded_hal traits.
|
||||||
#[cfg(feature = "serial")]
|
#[cfg(feature = "serial")]
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct SioSerial;
|
pub struct SioSerial;
|
||||||
|
|
||||||
#[cfg(feature = "serial")]
|
#[cfg(feature = "serial")]
|
||||||
impl SioSerial {
|
impl SioSerial {
|
||||||
/// Initialize SioSerial with provided baud rate and default 8N1 settings.
|
/// Initialize SioSerial with provided baud rate and default 8N1 settings.
|
||||||
pub fn init(baud: BaudRate) {
|
pub fn init(baud: BaudRate) -> Self {
|
||||||
RCNT.write(IoControlSetting::new());
|
RCNT.write(IoControlSetting::new());
|
||||||
SIOCNT.write(
|
SIOCNT.write(
|
||||||
// default settings: 8N1
|
// default settings: 8N1
|
||||||
|
@ -137,14 +138,18 @@ impl SioSerial {
|
||||||
.with_baud_rate(baud)
|
.with_baud_rate(baud)
|
||||||
.with_data_length_8bit(true)
|
.with_data_length_8bit(true)
|
||||||
.with_mode(SioMode::Uart)
|
.with_mode(SioMode::Uart)
|
||||||
|
.with_fifo_enable(true)
|
||||||
.with_rx_enable(true)
|
.with_rx_enable(true)
|
||||||
.with_tx_enable(true),
|
.with_tx_enable(true),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
SioSerial
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serial IO error type.
|
/// Serial IO error type.
|
||||||
#[cfg(feature = "serial")]
|
#[cfg(feature = "serial")]
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum SioError {
|
pub enum SioError {
|
||||||
/// * Error bit in SIOCNT is set
|
/// * Error bit in SIOCNT is set
|
||||||
ErrorBitSet,
|
ErrorBitSet,
|
||||||
|
|
Loading…
Reference in a new issue