Merge pull request #219 from bobmcwhirter/peripheral_pins

Create the new peripheral_pins! macro table.
This commit is contained in:
Dario Nieuwenhuis 2021-06-03 21:38:59 +02:00 committed by GitHub
commit ebd3be7425
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 312 additions and 179 deletions

View file

@ -48,48 +48,6 @@ with open(output_file, 'w') as f:
custom_singletons = False
if block_mod == 'usart':
f.write(f'impl_usart!({name});')
for pin, funcs in af.items():
if pin in pins:
if (func := funcs.get(f'{name}_RX')) != None:
f.write(f'impl_usart_pin!({name}, RxPin, {pin}, {func});')
if (func := funcs.get(f'{name}_TX')) != None:
f.write(f'impl_usart_pin!({name}, TxPin, {pin}, {func});')
if (func := funcs.get(f'{name}_CTS')) != None:
f.write(f'impl_usart_pin!({name}, CtsPin, {pin}, {func});')
if (func := funcs.get(f'{name}_RTS')) != None:
f.write(f'impl_usart_pin!({name}, RtsPin, {pin}, {func});')
if (func := funcs.get(f'{name}_CK')) != None:
f.write(f'impl_usart_pin!({name}, CkPin, {pin}, {func});')
if block_mod == 'rng':
for irq in chip['interrupts']:
if re.search('RNG', irq):
f.write(f'impl_rng!({name}, {irq});')
if block_mod == 'spi':
if 'clock' in peri:
clock = peri['clock']
f.write(f'impl_spi!({name}, {clock});')
for pin, funcs in af.items():
if pin in pins:
if (func := funcs.get(f'{name}_SCK')) != None:
f.write(f'impl_spi_pin!({name}, SckPin, {pin}, {func});')
if (func := funcs.get(f'{name}_MOSI')) != None:
f.write(f'impl_spi_pin!({name}, MosiPin, {pin}, {func});')
if (func := funcs.get(f'{name}_MISO')) != None:
f.write(f'impl_spi_pin!({name}, MisoPin, {pin}, {func});')
if block_mod == 'i2c':
f.write(f'impl_i2c!({name});')
for pin, funcs in af.items():
if pin in pins:
if func := funcs.get(f'{name}_SCL'):
f.write(f'impl_i2c_pin!({name}, SclPin, {pin}, {func});')
if func := funcs.get(f'{name}_SDA'):
f.write(f'impl_i2c_pin!({name}, SdaPin, {pin}, {func});')
if block_mod == 'gpio':
custom_singletons = True
port = name[4:]
@ -102,62 +60,11 @@ with open(output_file, 'w') as f:
if block_mod == 'dma':
custom_singletons = True
num_dmas += 1
dma_num = int(name[3:])-1 # substract 1 because we want DMA1=0, DMA2=1
for ch_num in range(8):
channel = f'{name}_CH{ch_num}'
singletons.append(channel)
f.write(f'impl_dma_channel!({channel}, {dma_num}, {ch_num});')
if peri['block'] == 'sdmmc_v2/SDMMC':
f.write(f'impl_sdmmc!({name});')
for pin, funcs in af.items():
if pin in pins:
if (func := funcs.get(f'{name}_CK')) != None:
f.write(f'impl_sdmmc_pin!({name}, CkPin, {pin}, {func});')
if (func := funcs.get(f'{name}_CMD')) != None:
f.write(f'impl_sdmmc_pin!({name}, CmdPin, {pin}, {func});')
if (func := funcs.get(f'{name}_D0')) != None:
f.write(f'impl_sdmmc_pin!({name}, D0Pin, {pin}, {func});')
if (func := funcs.get(f'{name}_D1')) != None:
f.write(f'impl_sdmmc_pin!({name}, D1Pin, {pin}, {func});')
if (func := funcs.get(f'{name}_D2')) != None:
f.write(f'impl_sdmmc_pin!({name}, D2Pin, {pin}, {func});')
if (func := funcs.get(f'{name}_D3')) != None:
f.write(f'impl_sdmmc_pin!({name}, D3Pin, {pin}, {func});')
if (func := funcs.get(f'{name}_D4')) != None:
f.write(f'impl_sdmmc_pin!({name}, D4Pin, {pin}, {func});')
if (func := funcs.get(f'{name}_D5')) != None:
f.write(f'impl_sdmmc_pin!({name}, D5Pin, {pin}, {func});')
if (func := funcs.get(f'{name}_D6')) != None:
f.write(f'impl_sdmmc_pin!({name}, D6Pin, {pin}, {func});')
if (func := funcs.get(f'{name}_D7')) != None:
f.write(f'impl_sdmmc_pin!({name}, D7Pin, {pin}, {func});')
if block_name == 'TimGp16':
if re.match('TIM[2345]$', name):
f.write(f'impl_timer!({name});')
if block_mod == 'exti':
for irq in chip['interrupts']:
if re.match('EXTI', irq):
exti_interrupts.append(irq)
if block_mod == 'dac':
f.write(f'impl_dac!({name});')
if 'dac_out1' in peri:
pin = peri['dac_out1']
f.write(f'impl_dac_pin!({name}, 1, {pin});')
if 'dac_out2' in peri:
pin = peri['dac_out2']
f.write(f'impl_dac_pin!({name}, 2, {pin});')
if not custom_singletons:
singletons.append(name)
f.write(f"embassy_extras::peripherals!({','.join(singletons)});")
# ========= exti interrupts
f.write(f"impl_exti_irq!({','.join(exti_interrupts)});")

View file

@ -10,6 +10,7 @@ use embassy::time::{Clock as EmbassyClock, TICKS_PER_SECOND};
use crate::interrupt::{CriticalSection, Interrupt, Mutex};
use crate::pac::timer::TimGp16;
use crate::peripherals;
use crate::time::Hertz;
// Clock timekeeping works with something we call "periods", which are time intervals
@ -362,15 +363,22 @@ pub trait Instance: sealed::Instance + Sized + 'static {}
macro_rules! impl_timer {
($inst:ident) => {
impl crate::clock::sealed::Instance for peripherals::$inst {
impl sealed::Instance for peripherals::$inst {
type Interrupt = crate::interrupt::$inst;
fn inner() -> crate::clock::TimerInner {
const INNER: crate::clock::TimerInner = crate::clock::TimerInner(crate::pac::$inst);
const INNER: TimerInner = TimerInner(crate::pac::$inst);
INNER
}
}
impl crate::clock::Instance for peripherals::$inst {}
impl Instance for peripherals::$inst {}
};
}
crate::pac::peripherals!(
(timer, TIM2) => { impl_timer!(TIM2); };
(timer, TIM3) => { impl_timer!(TIM3); };
(timer, TIM4) => { impl_timer!(TIM4); };
(timer, TIM5) => { impl_timer!(TIM5); };
);

View file

@ -3,6 +3,7 @@
#[cfg_attr(dac_v2, path = "v2.rs")]
mod _version;
use crate::gpio::NoPin;
use crate::peripherals;
pub use _version::*;
pub(crate) mod sealed {
@ -23,8 +24,8 @@ pub trait DacPin<T: Instance, const C: u8>: sealed::DacPin<T, C> + 'static {}
impl<T: Instance, const C: u8> DacPin<T, C> for NoPin {}
impl<T: Instance, const C: u8> sealed::DacPin<T, C> for NoPin {}
macro_rules! impl_dac {
($inst:ident) => {
crate::pac::peripherals!(
(dac, $inst:ident) => {
impl crate::dac::sealed::Instance for peripherals::$inst {
fn regs() -> &'static crate::pac::dac::Dac {
&crate::pac::$inst
@ -33,16 +34,21 @@ macro_rules! impl_dac {
impl crate::dac::Instance for peripherals::$inst {}
};
}
);
macro_rules! impl_dac_pin {
($inst:ident, $channel:expr, $pin:ident ) => {
impl crate::dac::DacPin<peripherals::$inst, $channel> for peripherals::$pin {}
crate::pac::peripheral_pins!(
($inst:ident, dac, DAC, $pin:ident, OUT1) => {
impl DacPin<peripherals::$inst, 1> for peripherals::$pin {}
impl crate::dac::sealed::DacPin<peripherals::$inst, $channel> for peripherals::$pin {
//fn af_num(&self) -> u8 {
//$af
//}
impl sealed::DacPin<peripherals::$inst, 1> for peripherals::$pin {
}
};
($inst:ident, dac, DAC, $pin:ident, OUT2) => {
impl DacPin<peripherals::$inst, 2> for peripherals::$pin {}
impl sealed::DacPin<peripherals::$inst, 2> for peripherals::$pin {
}
};
}
);

View file

@ -8,6 +8,7 @@ mod _version;
pub use _version::*;
use crate::pac;
use crate::peripherals;
pub(crate) mod sealed {
use super::*;
@ -31,8 +32,8 @@ pub trait Channel: sealed::Channel + Sized {}
macro_rules! impl_dma_channel {
($type:ident, $dma_num:expr, $ch_num:expr) => {
impl crate::dma::Channel for peripherals::$type {}
impl crate::dma::sealed::Channel for peripherals::$type {
impl Channel for peripherals::$type {}
impl sealed::Channel for peripherals::$type {
#[inline]
fn num(&self) -> u8 {
$dma_num * 8 + $ch_num
@ -40,3 +41,27 @@ macro_rules! impl_dma_channel {
}
};
}
crate::pac::peripherals!(
(dma,DMA1) => {
impl_dma_channel!(DMA1_CH0, 0, 0);
impl_dma_channel!(DMA1_CH1, 0, 1);
impl_dma_channel!(DMA1_CH2, 0, 2);
impl_dma_channel!(DMA1_CH3, 0, 3);
impl_dma_channel!(DMA1_CH4, 0, 4);
impl_dma_channel!(DMA1_CH5, 0, 5);
impl_dma_channel!(DMA1_CH6, 0, 6);
impl_dma_channel!(DMA1_CH7, 0, 7);
};
(dma,DMA2) => {
impl_dma_channel!(DMA2_CH0, 1, 0);
impl_dma_channel!(DMA2_CH1, 1, 1);
impl_dma_channel!(DMA2_CH2, 1, 2);
impl_dma_channel!(DMA2_CH3, 1, 3);
impl_dma_channel!(DMA2_CH4, 1, 4);
impl_dma_channel!(DMA2_CH5, 1, 5);
impl_dma_channel!(DMA2_CH6, 1, 6);
impl_dma_channel!(DMA2_CH7, 1, 7);
};
);

View file

@ -212,25 +212,63 @@ impl_exti!(EXTI13, 13);
impl_exti!(EXTI14, 14);
impl_exti!(EXTI15, 15);
pub(crate) unsafe fn init() {}
macro_rules! foreach_exti_irq {
($action:ident) => {
crate::pac::interrupts!(
(EXTI0) => { $action!(EXTI0); };
(EXTI1) => { $action!(EXTI1); };
(EXTI2) => { $action!(EXTI2); };
(EXTI3) => { $action!(EXTI3); };
(EXTI4) => { $action!(EXTI4); };
(EXTI5) => { $action!(EXTI5); };
(EXTI6) => { $action!(EXTI6); };
(EXTI7) => { $action!(EXTI7); };
(EXTI8) => { $action!(EXTI8); };
(EXTI9) => { $action!(EXTI9); };
(EXTI10) => { $action!(EXTI10); };
(EXTI11) => { $action!(EXTI11); };
(EXTI12) => { $action!(EXTI12); };
(EXTI13) => { $action!(EXTI13); };
(EXTI14) => { $action!(EXTI14); };
(EXTI15) => { $action!(EXTI15); };
macro_rules! impl_exti_irq {
($($e:ident),+) => {
/// safety: must be called only once
pub(crate) unsafe fn init_exti() {
use embassy::interrupt::Interrupt;
use embassy::interrupt::InterruptExt;
$(
crate::interrupt::$e::steal().enable();
)+
}
$(
#[crate::interrupt]
unsafe fn $e() {
crate::exti::on_irq()
}
)+
// plus the weird ones
(EXTI0_1) => { $action!( EXTI0_1 ); };
(EXTI15_10) => { $action!(EXTI15_10); };
(EXTI15_4) => { $action!(EXTI15_4); };
(EXTI1_0) => { $action!(EXTI1_0); };
(EXTI2_3) => { $action!(EXTI2_3); };
(EXTI2_TSC) => { $action!(EXTI2_TSC); };
(EXTI3_2) => { $action!(EXTI3_2); };
(EXTI4_15) => { $action!(EXTI4_15); };
(EXTI9_5) => { $action!(EXTI9_5); };
);
};
}
macro_rules! enable_irq {
($e:ident) => {
crate::interrupt::$e::steal().enable();
};
}
/// safety: must be called only once
pub(crate) unsafe fn init() {
use embassy::interrupt::Interrupt;
use embassy::interrupt::InterruptExt;
foreach_exti_irq!(enable_irq);
}
use crate::interrupt;
macro_rules! impl_irq {
($e:ident) => {
#[interrupt]
unsafe fn $e() {
on_irq()
}
};
}
foreach_exti_irq!(impl_irq);

View file

@ -3,6 +3,7 @@
#[cfg_attr(i2c_v1, path = "v1.rs")]
#[cfg_attr(i2c_v2, path = "v2.rs")]
mod _version;
use crate::peripherals;
pub use _version::*;
pub enum Error {
@ -37,26 +38,37 @@ pub trait SclPin<T: Instance>: sealed::SclPin<T> + 'static {}
pub trait SdaPin<T: Instance>: sealed::SdaPin<T> + 'static {}
macro_rules! impl_i2c {
($inst:ident) => {
impl crate::i2c::sealed::Instance for peripherals::$inst {
crate::pac::peripherals!(
(i2c, $inst:ident) => {
impl sealed::Instance for peripherals::$inst {
fn regs() -> &'static crate::pac::i2c::I2c {
&crate::pac::$inst
}
}
impl crate::i2c::Instance for peripherals::$inst {}
impl Instance for peripherals::$inst {}
};
}
);
macro_rules! impl_i2c_pin {
($inst:ident, $pin_func:ident, $pin:ident, $af:expr) => {
impl crate::i2c::$pin_func<peripherals::$inst> for peripherals::$pin {}
macro_rules! impl_pin {
($inst:ident, $pin:ident, $signal:ident, $af:expr) => {
impl $signal<peripherals::$inst> for peripherals::$pin {}
impl crate::i2c::sealed::$pin_func<peripherals::$inst> for peripherals::$pin {
impl sealed::$signal<peripherals::$inst> for peripherals::$pin {
fn af_num(&self) -> u8 {
$af
}
}
};
}
crate::pac::peripheral_pins!(
($inst:ident, i2c, I2C, $pin:ident, SDA, $af:expr) => {
impl_pin!($inst, $pin, SdaPin, $af);
};
($inst:ident, i2c, I2C, $pin:ident, SCL, $af:expr) => {
impl_pin!($inst, $pin, SclPin, $af);
};
);

View file

@ -83,7 +83,7 @@ pub fn init(config: Config) -> Peripherals {
#[cfg(dma)]
dma::init();
generated::init_exti();
exti::init();
rcc::init(config.rcc);
}

View file

@ -9,6 +9,7 @@ use futures::future::poll_fn;
use rand_core::{CryptoRng, RngCore};
use crate::pac;
use crate::peripherals;
pub(crate) static RNG_WAKER: AtomicWaker = AtomicWaker::new();
@ -134,16 +135,20 @@ pub(crate) mod sealed {
pub trait Instance: sealed::Instance {}
macro_rules! impl_rng {
($inst:ident, $irq:ident) => {
impl crate::rng::sealed::Instance for peripherals::RNG {
crate::pac::peripherals!(
(rng, $inst:ident) => {
impl Instance for peripherals::$inst {}
impl sealed::Instance for peripherals::$inst {
fn regs() -> crate::pac::rng::Rng {
crate::pac::RNG
}
}
};
);
impl crate::rng::Instance for peripherals::RNG {}
macro_rules! irq {
($irq:ident) => {
mod rng_irq {
use crate::interrupt;
@ -158,3 +163,25 @@ macro_rules! impl_rng {
}
};
}
crate::pac::interrupts!(
(RNG) => {
irq!(RNG);
};
(RNG_LPUART1) => {
irq!(RNG_LPUART1);
};
(AES_RNG_LPUART1) => {
irq!(AES_RNG_LPUART1);
};
(AES_RNG) => {
irq!(AES_RNG);
};
(HASH_RNG) => {
irq!(HASH_RNG);
};
);

View file

@ -1,6 +1,6 @@
#![macro_use]
#[cfg_attr(sdmmc_v1, path = "v1.rs")]
//#[cfg_attr(sdmmc_v1, path = "v1.rs")]
#[cfg_attr(sdmmc_v2, path = "v2.rs")]
mod _version;

View file

@ -15,6 +15,7 @@ use crate::interrupt::Interrupt;
use crate::pac;
use crate::pac::gpio::Gpio;
use crate::pac::sdmmc::Sdmmc as RegBlock;
use crate::peripherals;
use crate::time::Hertz;
/// The signalling scheme used on the SDMMC bus
@ -1469,13 +1470,13 @@ where
}
}
macro_rules! impl_sdmmc {
($inst:ident) => {
impl crate::sdmmc::sealed::Instance for peripherals::$inst {
crate::pac::peripherals!(
(sdmmc, $inst:ident) => {
impl sealed::Instance for peripherals::$inst {
type Interrupt = crate::interrupt::$inst;
fn inner() -> crate::sdmmc::SdmmcInner {
const INNER: crate::sdmmc::SdmmcInner = crate::sdmmc::SdmmcInner(crate::pac::$inst);
fn inner() -> SdmmcInner {
const INNER: SdmmcInner = SdmmcInner(crate::pac::$inst);
INNER
}
@ -1485,20 +1486,56 @@ macro_rules! impl_sdmmc {
}
}
impl crate::sdmmc::Instance for peripherals::$inst {}
impl Instance for peripherals::$inst {}
};
}
);
macro_rules! impl_sdmmc_pin {
($inst:ident, $func:ident, $pin:ident, $num:expr) => {
impl crate::sdmmc::sealed::$func<peripherals::$inst> for peripherals::$pin {
const AF_NUM: u8 = $num;
macro_rules! impl_pin {
($inst:ident, $pin:ident, $signal:ident, $af:expr) => {
impl sealed::$signal<peripherals::$inst> for peripherals::$pin {
const AF_NUM: u8 = $af;
}
impl crate::sdmmc::$func<peripherals::$inst> for peripherals::$pin {}
impl $signal<peripherals::$inst> for peripherals::$pin {}
};
}
crate::pac::peripheral_pins!(
($inst:ident, sdmmc, SDMMC, $pin:ident, CK, $af:expr) => {
impl_pin!($inst, $pin, CkPin, $af);
};
($inst:ident, sdmmc, SDMMC, $pin:ident, CMD, $af:expr) => {
impl_pin!($inst, $pin, CmdPin, $af);
};
($inst:ident, sdmmc, SDMMC, $pin:ident, D0, $af:expr) => {
impl_pin!($inst, $pin, D0Pin, $af);
};
($inst:ident, sdmmc, SDMMC, $pin:ident, D1, $af:expr) => {
impl_pin!($inst, $pin, D1Pin, $af);
};
($inst:ident, sdmmc, SDMMC, $pin:ident, D2, $af:expr) => {
impl_pin!($inst, $pin, D2Pin, $af);
};
($inst:ident, sdmmc, SDMMC, $pin:ident, D3, $af:expr) => {
impl_pin!($inst, $pin, D3Pin, $af);
};
($inst:ident, sdmmc, SDMMC, $pin:ident, D4, $af:expr) => {
impl_pin!($inst, $pin, D4Pin, $af);
};
($inst:ident, sdmmc, SDMMC, $pin:ident, D5, $af:expr) => {
impl_pin!($inst, $pin, D5Pin, $af);
};
($inst:ident, sdmmc, SDMMC, $pin:ident, D6, $af:expr) => {
impl_pin!($inst, $pin, D6Pin, $af);
};
($inst:ident, sdmmc, SDMMC, $pin:ident, D6, $af:expr) => {
impl_pin!($inst, $pin, D7Pin, $af);
};
($inst:ident, sdmmc, SDMMC, $pin:ident, D8, $af:expr) => {
impl_pin!($inst, $pin, D8Pin, $af);
};
);
#[cfg(feature = "sdmmc-rs")]
mod sdmmc_rs {
use super::*;

View file

@ -4,6 +4,7 @@
#[cfg_attr(spi_v2, path = "v2.rs")]
#[cfg_attr(spi_v3, path = "v3.rs")]
mod _version;
use crate::peripherals;
pub use _version::*;
use crate::gpio::Pin;
@ -71,26 +72,40 @@ pub trait MosiPin<T: Instance>: sealed::MosiPin<T> + 'static {}
pub trait MisoPin<T: Instance>: sealed::MisoPin<T> + 'static {}
macro_rules! impl_spi {
($inst:ident, $clk:ident) => {
impl crate::spi::sealed::Instance for peripherals::$inst {
crate::pac::peripherals!(
(spi, $inst:ident) => {
impl sealed::Instance for peripherals::$inst {
fn regs() -> &'static crate::pac::spi::Spi {
&crate::pac::$inst
}
}
impl crate::spi::Instance for peripherals::$inst {}
impl Instance for peripherals::$inst {}
};
}
);
macro_rules! impl_spi_pin {
($inst:ident, $pin_func:ident, $pin:ident, $af:expr) => {
impl crate::spi::$pin_func<peripherals::$inst> for peripherals::$pin {}
macro_rules! impl_pin {
($inst:ident, $pin:ident, $signal:ident, $af:expr) => {
impl $signal<peripherals::$inst> for peripherals::$pin {}
impl crate::spi::sealed::$pin_func<peripherals::$inst> for peripherals::$pin {
impl sealed::$signal<peripherals::$inst> for peripherals::$pin {
fn af_num(&self) -> u8 {
$af
}
}
};
}
crate::pac::peripheral_pins!(
($inst:ident, spi, SPI, $pin:ident, SCK, $af:expr) => {
impl_pin!($inst, $pin, SckPin, $af);
};
($inst:ident, spi, SPI, $pin:ident, MOSI, $af:expr) => {
impl_pin!($inst, $pin, MosiPin, $af);
};
($inst:ident, spi, SPI, $pin:ident, MISO, $af:expr) => {
impl_pin!($inst, $pin, MisoPin, $af);
};
);

View file

@ -3,6 +3,7 @@
#[cfg_attr(usart_v1, path = "v1.rs")]
#[cfg_attr(usart_v2, path = "v2.rs")]
mod _version;
use crate::peripherals;
pub use _version::*;
use crate::gpio::Pin;
@ -51,24 +52,48 @@ pub trait CtsPin<T: Instance>: sealed::CtsPin<T> {}
pub trait RtsPin<T: Instance>: sealed::RtsPin<T> {}
pub trait CkPin<T: Instance>: sealed::CkPin<T> {}
macro_rules! impl_usart {
($inst:ident) => {
impl crate::usart::sealed::Instance for peripherals::$inst {
crate::pac::peripherals!(
(usart, $inst:ident) => {
impl sealed::Instance for peripherals::$inst {
fn regs(&self) -> crate::pac::usart::Usart {
crate::pac::$inst
}
}
impl crate::usart::Instance for peripherals::$inst {}
};
}
macro_rules! impl_usart_pin {
($inst:ident, $func:ident, $pin:ident, $af:expr) => {
impl crate::usart::sealed::$func<peripherals::$inst> for peripherals::$pin {
impl Instance for peripherals::$inst {}
};
);
macro_rules! impl_pin {
($inst:ident, $pin:ident, $signal:ident, $af:expr) => {
impl sealed::$signal<peripherals::$inst> for peripherals::$pin {
fn af_num(&self) -> u8 {
$af
}
}
impl crate::usart::$func<peripherals::$inst> for peripherals::$pin {}
impl $signal<peripherals::$inst> for peripherals::$pin {}
};
}
crate::pac::peripheral_pins!(
($inst:ident, usart, USART, $pin:ident, TX, $af:expr) => {
impl_pin!($inst, $pin, TxPin, $af);
};
($inst:ident, usart, USART, $pin:ident, RX, $af:expr) => {
impl_pin!($inst, $pin, RxPin, $af);
};
($inst:ident, usart, USART, $pin:ident, CTS, $af:expr) => {
impl_pin!($inst, $pin, CtsPin, $af);
};
($inst:ident, usart, USART, $pin:ident, RTS, $af:expr) => {
impl_pin!($inst, $pin, RtsPin, $af);
};
($inst:ident, usart, USART, $pin:ident, CK, $af:expr) => {
impl_pin!($inst, $pin, CkPin, $af);
};
);

@ -1 +1 @@
Subproject commit dfc67fe255e1e70101e9f1e3fb8b4fd8bb37362f
Subproject commit 33dfa674865b1b5f0bfb86f3217055a6a057a6fb

View file

@ -40,12 +40,24 @@ pub struct Peripheral {
pub block: Option<String>,
#[serde(default)]
pub clock: Option<String>,
#[serde(default)]
pub pins: Vec<Pin>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct Pin {
pub pin: String,
pub signal: String,
pub af: Option<String>,
}
struct BlockInfo {
module: String, // usart_v1/USART -> usart
version: String, // usart_v1/USART -> v1
block: String, // usart_v1/USART -> USART
/// usart_v1/USART -> usart
module: String,
/// usart_v1/USART -> v1
version: String,
/// usart_v1/USART -> USART
block: String,
}
impl BlockInfo {
@ -123,6 +135,8 @@ fn main() {
let mut cfgs: HashSet<String> = HashSet::new();
let mut pin_table: Vec<Vec<String>> = Vec::new();
let mut interrupt_table: Vec<Vec<String>> = Vec::new();
let mut peripherals_table: Vec<Vec<String>> = Vec::new();
let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new();
let dma_base = chip
.peripherals
@ -149,8 +163,25 @@ fn main() {
if let Some(block) = &p.block {
let bi = BlockInfo::parse(block);
for pin in &p.pins {
let mut row = Vec::new();
row.push(name.clone());
row.push(bi.module.clone());
row.push(bi.block.clone());
row.push(pin.pin.clone());
row.push(pin.signal.clone());
if let Some(ref af) = pin.af {
row.push(af.clone());
}
peripheral_pins_table.push(row);
}
cfgs.insert(bi.module.clone());
cfgs.insert(format!("{}_{}", bi.module, bi.version));
let mut peripheral_row = Vec::new();
peripheral_row.push(bi.module.clone());
peripheral_row.push(name.clone());
peripherals_table.push(peripheral_row);
if let Some(old_version) =
peripheral_versions.insert(bi.module.clone(), bi.version.clone())
@ -226,7 +257,9 @@ fn main() {
make_table(&mut extra, "pins", &pin_table);
make_table(&mut extra, "interrupts", &interrupt_table);
make_table(&mut extra, "peripherals", &peripherals_table);
make_table(&mut extra, "peripheral_versions", &peripheral_version_table);
make_table(&mut extra, "peripheral_pins", &peripheral_pins_table);
for (module, version) in peripheral_versions {
println!("loading {} {}", module, version);