rlvgl_platform/hwcore/regs/
tim.rs1use core::mem::offset_of;
11
12use crate::hwcore::addr::MmioAddr;
13use crate::hwcore::regs::access::Rw;
14
15#[repr(C)]
17pub struct TimBasicRegs {
18 pub cr1: Rw<u32>,
20 pub cr2: Rw<u32>,
22 _reserved_08: u32,
24 pub dier: Rw<u32>,
26 pub sr: Rw<u32>,
28 pub egr: Rw<u32>,
30 _reserved_18: [u32; 3],
32 pub cnt: Rw<u32>,
34 pub psc: Rw<u32>,
36 pub arr: Rw<u32>,
38}
39
40const _: () = assert!(offset_of!(TimBasicRegs, cr1) == 0x00);
41const _: () = assert!(offset_of!(TimBasicRegs, cr2) == 0x04);
42const _: () = assert!(offset_of!(TimBasicRegs, dier) == 0x0C);
43const _: () = assert!(offset_of!(TimBasicRegs, sr) == 0x10);
44const _: () = assert!(offset_of!(TimBasicRegs, egr) == 0x14);
45const _: () = assert!(offset_of!(TimBasicRegs, cnt) == 0x24);
46const _: () = assert!(offset_of!(TimBasicRegs, psc) == 0x28);
47const _: () = assert!(offset_of!(TimBasicRegs, arr) == 0x2C);
48
49pub const TIM6_BASE: usize = 0x4000_1000;
51pub const TIM7_BASE: usize = 0x4000_1400;
53
54pub struct TimBasic {
56 base: MmioAddr<TimBasicRegs>,
57}
58
59impl TimBasic {
60 pub const unsafe fn new(base: usize) -> Self {
68 Self {
70 base: unsafe { MmioAddr::new(base) },
71 }
72 }
73
74 pub const unsafe fn tim6() -> Self {
80 unsafe { Self::new(TIM6_BASE) }
82 }
83
84 pub const unsafe fn tim7() -> Self {
90 unsafe { Self::new(TIM7_BASE) }
92 }
93
94 #[inline]
96 pub fn regs(&self) -> &TimBasicRegs {
97 unsafe { &*self.base.as_ptr() }
99 }
100}
101
102#[cfg(test)]
103mod tests {
104 use super::*;
105
106 #[test]
107 fn tim6_sr_matches_legacy_constant() {
108 assert_eq!(TIM6_BASE + offset_of!(TimBasicRegs, sr), 0x4000_1010);
109 }
110
111 #[test]
112 fn tim7_layout_matches_freertos_entry_constants() {
113 assert_eq!(TIM7_BASE + offset_of!(TimBasicRegs, cr1), 0x4000_1400);
114 assert_eq!(TIM7_BASE + offset_of!(TimBasicRegs, dier), 0x4000_140C);
115 assert_eq!(TIM7_BASE + offset_of!(TimBasicRegs, sr), 0x4000_1410);
116 assert_eq!(TIM7_BASE + offset_of!(TimBasicRegs, egr), 0x4000_1414);
117 assert_eq!(TIM7_BASE + offset_of!(TimBasicRegs, cnt), 0x4000_1424);
118 assert_eq!(TIM7_BASE + offset_of!(TimBasicRegs, psc), 0x4000_1428);
119 assert_eq!(TIM7_BASE + offset_of!(TimBasicRegs, arr), 0x4000_142C);
120 }
121}