#![no_std]
#![no_main]

use dma_gpio as _;
use panic_probe as _;
use defmt_rtt as _;

#[defmt_test::tests]
mod tests {
    use defmt::assert_eq;
    use dma_gpio::software_uart::uart_emulation::{
        encode_uart_byte_cfg, UartConfig, Parity, StopBits
    };

    const TX_PIN_BIT: u8 = 2;

    #[test]
    fn test_encode_8n1() {
        let cfg = UartConfig::default();
        let mut frame = [0u32; 12];
        let used = encode_uart_byte_cfg(TX_PIN_BIT, 0x55, &cfg, &mut frame);
        
        assert_eq!(used, 10);
        assert_eq!(frame[0], 1u32 << 18); // Start LOW
        assert_eq!(frame[9], 1u32 << 2);  // Stop HIGH
    }

    #[test]
    fn test_encode_parity() {
        let cfg = UartConfig {
            data_bits: 8,
            parity: Parity::Even,
            stop_bits: StopBits::One,
        };
        
        let mut frame = [0u32; 12];
        let used = encode_uart_byte_cfg(TX_PIN_BIT, 0x00, &cfg, &mut frame);
        
        assert_eq!(used, 11);
    }
}
