#[cfg(feature="arduino_uno")]
pub use uno as board;
#[cfg(feature="arduino_nanoevery")]
pub use nanoevery as board;
#[cfg(feature="atmega_xplained")]
pub use xplained as board;
#[cfg(feature="arduino_uno")]
pub mod uno {
use avr_oxide::hal::generic::port::{Pin, PinMode};
pub fn pin_a(pin: u8) -> &'static dyn Pin {
match pin {
0 => avr_oxide::hardware::port::portc::pin(0),
1 => avr_oxide::hardware::port::portc::pin(1),
2 => avr_oxide::hardware::port::portc::pin(2),
3 => avr_oxide::hardware::port::portc::pin(3),
4 => avr_oxide::hardware::port::portc::pin(4),
5 => avr_oxide::hardware::port::portc::pin(5),
_ => avr_oxide::oserror::halt(avr_oxide::oserror::OsError::BadParams)
}
}
pub fn pin_d(pin: u8) -> &'static dyn Pin {
match pin {
0 => avr_oxide::hardware::port::portd::pin(0),
1 => avr_oxide::hardware::port::portd::pin(1),
2 => avr_oxide::hardware::port::portd::pin(2),
3 => avr_oxide::hardware::port::portd::pin(3),
4 => avr_oxide::hardware::port::portd::pin(4),
5 => avr_oxide::hardware::port::portd::pin(5),
6 => avr_oxide::hardware::port::portd::pin(6),
7 => avr_oxide::hardware::port::portd::pin(7),
8 => avr_oxide::hardware::port::portb::pin(0),
9 => avr_oxide::hardware::port::portb::pin(1),
10 => avr_oxide::hardware::port::portb::pin(2),
11 => avr_oxide::hardware::port::portb::pin(3),
12 => avr_oxide::hardware::port::portb::pin(4),
13 => avr_oxide::hardware::port::portb::pin(5),
_ => avr_oxide::oserror::halt(avr_oxide::oserror::OsError::BadParams)
}
}
pub fn debug_pin() -> &'static dyn Pin {
avr_oxide::hardware::port::portb::pin(5)
}
pub fn usb_serial() -> &'static mut avr_oxide::hardware::serial::usart0::SerialImpl {
avr_oxide::concurrency::interrupt::isolated(|isotoken|{
avr_oxide::hardware::serial::usart0::instance_isolated(isotoken)
})
}
pub fn usb_serial_pins() -> (&'static dyn Pin, &'static dyn Pin) {
(avr_oxide::hardware::port::portd::pin(1),avr_oxide::hardware::port::portd::pin(0))
}
pub fn initialise() {
debug_pin().set_mode(PinMode::Output);
debug_pin().set_low();
avr_oxide::oserror::set_debug_pin(debug_pin());
}
}
#[cfg(feature="arduino_nanoevery")]
pub mod nanoevery {
use avr_oxide::hal::generic::port::{Pin, PinMode};
pub fn pin_a(pin: u8) -> &'static dyn Pin {
match pin {
0 => avr_oxide::hardware::port::portd::pin(3),
1 => avr_oxide::hardware::port::portd::pin(2),
2 => avr_oxide::hardware::port::portd::pin(1),
3 => avr_oxide::hardware::port::portd::pin(0),
4 => avr_oxide::hardware::port::porta::pin(2),
5 => avr_oxide::hardware::port::porta::pin(3),
6 => avr_oxide::hardware::port::portd::pin(4),
7 => avr_oxide::hardware::port::portd::pin(5),
_ => avr_oxide::oserror::halt(avr_oxide::oserror::OsError::BadParams)
}
}
pub fn pin_d(pin: u8) -> &'static dyn Pin {
match pin {
0 => avr_oxide::hardware::port::portc::pin(4),
1 => avr_oxide::hardware::port::portc::pin(5),
2 => avr_oxide::hardware::port::porta::pin(0),
3 => avr_oxide::hardware::port::portf::pin(5),
4 => avr_oxide::hardware::port::portc::pin(6),
5 => avr_oxide::hardware::port::portb::pin(2),
6 => avr_oxide::hardware::port::portf::pin(4),
7 => avr_oxide::hardware::port::porta::pin(1),
8 => avr_oxide::hardware::port::porte::pin(3),
9 => avr_oxide::hardware::port::portb::pin(0),
10 => avr_oxide::hardware::port::portb::pin(1),
11 => avr_oxide::hardware::port::porte::pin(0),
12 => avr_oxide::hardware::port::porte::pin(1),
13 => avr_oxide::hardware::port::porte::pin(2),
_ => avr_oxide::oserror::halt(avr_oxide::oserror::OsError::BadParams)
}
}
pub fn debug_pin() -> &'static dyn Pin {
avr_oxide::hardware::port::porte::pin(2)
}
pub fn usb_serial() -> &'static mut avr_oxide::hardware::serial::usart3::SerialImpl {
avr_oxide::hardware::serial::usart3::instance().mux(avr_oxide::hal::atmega4809::serial::usart3::SerialPortPins::PortBhi)
}
pub fn usb_serial_pins() -> (&'static dyn Pin, &'static dyn Pin) {
(avr_oxide::hardware::port::portb::pin(4),avr_oxide::hardware::port::portb::pin(5))
}
pub fn initialise() {
debug_pin().set_mode(PinMode::Output);
debug_pin().set_low();
avr_oxide::oserror::set_debug_pin(debug_pin());
}
}
#[cfg(all(feature="atmega_xplained",feature="atmega4809"))]
pub mod xplained {
use avr_oxide::devices::inverter::Inverter;
use avr_oxide::devices::UsesPin;
use avr_oxide::hal::generic::port::{Pin, PinMode};
use avr_oxide::oserror::OsError;
pub fn sw0() -> &'static dyn Pin {
avr_oxide::hardware::port::portb::pin(2)
}
pub fn sw1() -> &'static dyn Pin {
avr_oxide::hardware::port::portf::pin(6)
}
pub fn led0() -> &'static dyn Pin {
avr_oxide::hardware::port::portb::pin(5)
}
static mut INVERTED_DEBUG : Option<Inverter> = None;
pub fn debug_pin() -> &'static dyn Pin {
unsafe {
match &INVERTED_DEBUG {
None => {
avr_oxide::oserror::halt(OsError::InternalError);
},
Some(pin) => {
pin
}
}
}
}
pub fn usb_serial() -> &'static mut avr_oxide::hardware::serial::usart1::SerialImpl {
avr_oxide::hardware::serial::usart1::instance().mux(avr_oxide::hal::atmega4809::serial::usart1::SerialPortPins::PortClow)
}
pub fn usb_serial_pins() -> (&'static dyn Pin, &'static dyn Pin) {
(avr_oxide::hardware::port::portc::pin(0),avr_oxide::hardware::port::portc::pin(1))
}
pub fn initialise() {
sw0().set_mode(PinMode::InputPullup);
unsafe {
INVERTED_DEBUG.replace(Inverter::with_pin(led0()));
}
debug_pin().set_mode(PinMode::Output);
debug_pin().set_low();
avr_oxide::oserror::set_debug_pin(debug_pin());
}
}