stm32-metapac: remove all macrotables, deduplicate metadata files.
This commit is contained in:
80
stm32-metapac/src/common.rs
Normal file
80
stm32-metapac/src/common.rs
Normal file
@ -0,0 +1,80 @@
|
||||
use core::marker::PhantomData;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub struct RW;
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub struct R;
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub struct W;
|
||||
|
||||
mod sealed {
|
||||
use super::*;
|
||||
pub trait Access {}
|
||||
impl Access for R {}
|
||||
impl Access for W {}
|
||||
impl Access for RW {}
|
||||
}
|
||||
|
||||
pub trait Access: sealed::Access + Copy {}
|
||||
impl Access for R {}
|
||||
impl Access for W {}
|
||||
impl Access for RW {}
|
||||
|
||||
pub trait Read: Access {}
|
||||
impl Read for RW {}
|
||||
impl Read for R {}
|
||||
|
||||
pub trait Write: Access {}
|
||||
impl Write for RW {}
|
||||
impl Write for W {}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub struct Reg<T: Copy, A: Access> {
|
||||
ptr: *mut u8,
|
||||
phantom: PhantomData<*mut (T, A)>,
|
||||
}
|
||||
unsafe impl<T: Copy, A: Access> Send for Reg<T, A> {}
|
||||
unsafe impl<T: Copy, A: Access> Sync for Reg<T, A> {}
|
||||
|
||||
impl<T: Copy, A: Access> Reg<T, A> {
|
||||
pub fn from_ptr(ptr: *mut u8) -> Self {
|
||||
Self {
|
||||
ptr,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ptr(&self) -> *mut T {
|
||||
self.ptr as _
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy, A: Read> Reg<T, A> {
|
||||
pub unsafe fn read(&self) -> T {
|
||||
(self.ptr as *mut T).read_volatile()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy, A: Write> Reg<T, A> {
|
||||
pub unsafe fn write_value(&self, val: T) {
|
||||
(self.ptr as *mut T).write_volatile(val)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Default + Copy, A: Write> Reg<T, A> {
|
||||
pub unsafe fn write<R>(&self, f: impl FnOnce(&mut T) -> R) -> R {
|
||||
let mut val = Default::default();
|
||||
let res = f(&mut val);
|
||||
self.write_value(val);
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy, A: Read + Write> Reg<T, A> {
|
||||
pub unsafe fn modify<R>(&self, f: impl FnOnce(&mut T) -> R) -> R {
|
||||
let mut val = self.read();
|
||||
let res = f(&mut val);
|
||||
self.write_value(val);
|
||||
res
|
||||
}
|
||||
}
|
@ -3,5 +3,13 @@
|
||||
#![allow(unused)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
// GEN CUT HERE
|
||||
include!(concat!(env!("OUT_DIR"), "/src/lib_inner.rs"));
|
||||
pub mod common;
|
||||
|
||||
#[cfg(feature = "pac")]
|
||||
include!(env!("STM32_METAPAC_PAC_PATH"));
|
||||
|
||||
#[cfg(feature = "metadata")]
|
||||
pub mod metadata {
|
||||
include!("metadata.rs");
|
||||
include!(env!("STM32_METAPAC_METADATA_PATH"));
|
||||
}
|
||||
|
97
stm32-metapac/src/metadata.rs
Normal file
97
stm32-metapac/src/metadata.rs
Normal file
@ -0,0 +1,97 @@
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct Metadata {
|
||||
pub name: &'static str,
|
||||
pub family: &'static str,
|
||||
pub line: &'static str,
|
||||
pub memory: &'static [MemoryRegion],
|
||||
pub peripherals: &'static [Peripheral],
|
||||
pub interrupts: &'static [Interrupt],
|
||||
pub dma_channels: &'static [DmaChannel],
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct MemoryRegion {
|
||||
pub name: &'static str,
|
||||
pub kind: MemoryRegionKind,
|
||||
pub address: u32,
|
||||
pub size: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub enum MemoryRegionKind {
|
||||
Flash,
|
||||
Ram,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct Interrupt {
|
||||
pub name: &'static str,
|
||||
pub number: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct Package {
|
||||
pub name: &'static str,
|
||||
pub package: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct Peripheral {
|
||||
pub name: &'static str,
|
||||
pub address: u64,
|
||||
pub registers: Option<PeripheralRegisters>,
|
||||
pub rcc: Option<PeripheralRcc>,
|
||||
pub pins: &'static [PeripheralPin],
|
||||
pub dma_channels: &'static [PeripheralDmaChannel],
|
||||
pub interrupts: &'static [PeripheralInterrupt],
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct PeripheralRegisters {
|
||||
pub kind: &'static str,
|
||||
pub version: &'static str,
|
||||
pub block: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct PeripheralInterrupt {
|
||||
pub signal: &'static str,
|
||||
pub interrupt: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct PeripheralRcc {
|
||||
pub clock: &'static str,
|
||||
pub enable: Option<PeripheralRccRegister>,
|
||||
pub reset: Option<PeripheralRccRegister>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct PeripheralRccRegister {
|
||||
pub register: &'static str,
|
||||
pub field: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct PeripheralPin {
|
||||
pub pin: &'static str,
|
||||
pub signal: &'static str,
|
||||
pub af: Option<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct DmaChannel {
|
||||
pub name: &'static str,
|
||||
pub dma: &'static str,
|
||||
pub channel: u32,
|
||||
pub dmamux: Option<&'static str>,
|
||||
pub dmamux_channel: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub struct PeripheralDmaChannel {
|
||||
pub signal: &'static str,
|
||||
pub channel: Option<&'static str>,
|
||||
pub dmamux: Option<&'static str>,
|
||||
pub request: Option<u32>,
|
||||
}
|
Reference in New Issue
Block a user