Migrate sdmmc to macro tables.

This commit is contained in:
Bob McWhirter 2021-06-03 13:50:48 -04:00
parent fe47f781be
commit 2c722ec0ee
3 changed files with 49 additions and 100 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:]
@ -111,53 +69,7 @@ with open(output_file, 'w') as f:
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

@ -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,12 +1470,12 @@ 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 {
fn inner() -> SdmmcInner {
const INNER: crate::sdmmc::SdmmcInner = crate::sdmmc::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 crate::sdmmc::sealed::$signal<peripherals::$inst> for peripherals::$pin {
const AF_NUM: u8 = $af;
}
impl crate::sdmmc::$func<peripherals::$inst> for peripherals::$pin {}
impl crate::sdmmc::$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::*;