1#![no_std]
2#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3
4use gpio::Port;
5pub use va108xx;
6pub use va108xx as pac;
7
8pub mod clock;
9pub mod gpio;
10pub mod i2c;
11pub mod pins;
12pub mod prelude;
13pub mod pwm;
14pub mod spi;
15pub mod sysconfig;
16pub mod time;
17pub mod timer;
18pub mod uart;
19
20pub use vorago_shared_hal::{
21 disable_nvic_interrupt, enable_nvic_interrupt, FunctionSelect, InterruptConfig,
22 PeripheralSelect,
23};
24
25pub const IRQ_DST_NONE: u32 = 0xffffffff;
27
28#[derive(Debug, PartialEq, Eq, thiserror::Error)]
29#[cfg_attr(feature = "defmt", derive(defmt::Format))]
30#[error("invalid pin with number {0}")]
31pub struct InvalidPinError(u8);
32
33pub fn port_function_select(
39 ioconfig: &mut pac::Ioconfig,
40 port: Port,
41 pin: u8,
42 funsel: FunctionSelect,
43) -> Result<(), InvalidPinError> {
44 if (port == Port::A && pin >= 32) || (port == Port::B && pin >= 24) {
45 return Err(InvalidPinError(pin));
46 }
47
48 let reg_block = match port {
49 Port::A => ioconfig.porta(pin as usize),
50 Port::B => ioconfig.portb(pin as usize),
51 };
52
53 reg_block.modify(|_, w| unsafe { w.funsel().bits(funsel as u8) });
54 Ok(())
55}
56
57#[allow(dead_code)]
58pub(crate) mod sealed {
59 pub trait Sealed {}
60}