| 1 | #![allow (clippy::missing_safety_doc)] |
| 2 | #![allow (clippy::identity_op)] |
| 3 | #![allow (clippy::unnecessary_cast)] |
| 4 | #![allow (clippy::erasing_op)] |
| 5 | |
| 6 | #[doc = "Cyclic Redundancy Check calculation unit" ] |
| 7 | #[derive (Copy, Clone, Eq, PartialEq)] |
| 8 | pub struct Crc { |
| 9 | ptr: *mut u8, |
| 10 | } |
| 11 | unsafe impl Send for Crc {} |
| 12 | unsafe impl Sync for Crc {} |
| 13 | impl Crc { |
| 14 | #[inline (always)] |
| 15 | pub const unsafe fn from_ptr(ptr: *mut ()) -> Self { |
| 16 | Self { ptr: ptr as _ } |
| 17 | } |
| 18 | #[inline (always)] |
| 19 | pub const fn as_ptr(&self) -> *mut () { |
| 20 | self.ptr as _ |
| 21 | } |
| 22 | #[doc = "Data register - half-word sized" ] |
| 23 | #[inline (always)] |
| 24 | pub const fn dr16(self) -> crate::common::Reg<u16, crate::common::RW> { |
| 25 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x0usize) as _) } |
| 26 | } |
| 27 | #[doc = "Data register" ] |
| 28 | #[inline (always)] |
| 29 | pub const fn dr32(self) -> crate::common::Reg<u32, crate::common::RW> { |
| 30 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x0usize) as _) } |
| 31 | } |
| 32 | #[doc = "Data register - byte sized" ] |
| 33 | #[inline (always)] |
| 34 | pub const fn dr8(self) -> crate::common::Reg<u8, crate::common::RW> { |
| 35 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x0usize) as _) } |
| 36 | } |
| 37 | #[doc = "Independent Data register" ] |
| 38 | #[inline (always)] |
| 39 | pub const fn idr(self) -> crate::common::Reg<u32, crate::common::RW> { |
| 40 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x04usize) as _) } |
| 41 | } |
| 42 | #[doc = "Control register" ] |
| 43 | #[inline (always)] |
| 44 | pub const fn cr(self) -> crate::common::Reg<regs::Cr, crate::common::RW> { |
| 45 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x08usize) as _) } |
| 46 | } |
| 47 | #[doc = "Initial CRC value" ] |
| 48 | #[inline (always)] |
| 49 | pub const fn init(self) -> crate::common::Reg<u32, crate::common::RW> { |
| 50 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x10usize) as _) } |
| 51 | } |
| 52 | #[doc = "CRC polynomial" ] |
| 53 | #[inline (always)] |
| 54 | pub const fn pol(self) -> crate::common::Reg<u32, crate::common::RW> { |
| 55 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x14usize) as _) } |
| 56 | } |
| 57 | } |
| 58 | pub mod regs { |
| 59 | #[doc = "Control register" ] |
| 60 | #[repr (transparent)] |
| 61 | #[derive (Copy, Clone, Eq, PartialEq)] |
| 62 | pub struct Cr(pub u32); |
| 63 | impl Cr { |
| 64 | #[doc = "RESET bit" ] |
| 65 | #[inline (always)] |
| 66 | pub const fn reset(&self) -> bool { |
| 67 | let val = (self.0 >> 0usize) & 0x01; |
| 68 | val != 0 |
| 69 | } |
| 70 | #[doc = "RESET bit" ] |
| 71 | #[inline (always)] |
| 72 | pub fn set_reset(&mut self, val: bool) { |
| 73 | self.0 = (self.0 & !(0x01 << 0usize)) | (((val as u32) & 0x01) << 0usize); |
| 74 | } |
| 75 | #[doc = "Polynomial size" ] |
| 76 | #[inline (always)] |
| 77 | pub const fn polysize(&self) -> super::vals::Polysize { |
| 78 | let val = (self.0 >> 3usize) & 0x03; |
| 79 | super::vals::Polysize::from_bits(val as u8) |
| 80 | } |
| 81 | #[doc = "Polynomial size" ] |
| 82 | #[inline (always)] |
| 83 | pub fn set_polysize(&mut self, val: super::vals::Polysize) { |
| 84 | self.0 = (self.0 & !(0x03 << 3usize)) | (((val.to_bits() as u32) & 0x03) << 3usize); |
| 85 | } |
| 86 | #[doc = "Reverse input data" ] |
| 87 | #[inline (always)] |
| 88 | pub const fn rev_in(&self) -> super::vals::RevIn { |
| 89 | let val = (self.0 >> 5usize) & 0x03; |
| 90 | super::vals::RevIn::from_bits(val as u8) |
| 91 | } |
| 92 | #[doc = "Reverse input data" ] |
| 93 | #[inline (always)] |
| 94 | pub fn set_rev_in(&mut self, val: super::vals::RevIn) { |
| 95 | self.0 = (self.0 & !(0x03 << 5usize)) | (((val.to_bits() as u32) & 0x03) << 5usize); |
| 96 | } |
| 97 | #[doc = "Reverse output data" ] |
| 98 | #[inline (always)] |
| 99 | pub const fn rev_out(&self) -> super::vals::RevOut { |
| 100 | let val = (self.0 >> 7usize) & 0x01; |
| 101 | super::vals::RevOut::from_bits(val as u8) |
| 102 | } |
| 103 | #[doc = "Reverse output data" ] |
| 104 | #[inline (always)] |
| 105 | pub fn set_rev_out(&mut self, val: super::vals::RevOut) { |
| 106 | self.0 = (self.0 & !(0x01 << 7usize)) | (((val.to_bits() as u32) & 0x01) << 7usize); |
| 107 | } |
| 108 | } |
| 109 | impl Default for Cr { |
| 110 | #[inline (always)] |
| 111 | fn default() -> Cr { |
| 112 | Cr(0) |
| 113 | } |
| 114 | } |
| 115 | impl core::fmt::Debug for Cr { |
| 116 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 117 | f.debug_struct("Cr" ) |
| 118 | .field("reset" , &self.reset()) |
| 119 | .field("polysize" , &self.polysize()) |
| 120 | .field("rev_in" , &self.rev_in()) |
| 121 | .field("rev_out" , &self.rev_out()) |
| 122 | .finish() |
| 123 | } |
| 124 | } |
| 125 | #[cfg (feature = "defmt" )] |
| 126 | impl defmt::Format for Cr { |
| 127 | fn format(&self, f: defmt::Formatter) { |
| 128 | #[derive (defmt :: Format)] |
| 129 | struct Cr { |
| 130 | reset: bool, |
| 131 | polysize: super::vals::Polysize, |
| 132 | rev_in: super::vals::RevIn, |
| 133 | rev_out: super::vals::RevOut, |
| 134 | } |
| 135 | let proxy = Cr { |
| 136 | reset: self.reset(), |
| 137 | polysize: self.polysize(), |
| 138 | rev_in: self.rev_in(), |
| 139 | rev_out: self.rev_out(), |
| 140 | }; |
| 141 | defmt::write!(f, "{}" , proxy) |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | pub mod vals { |
| 146 | #[repr (u8)] |
| 147 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
| 148 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 149 | pub enum Polysize { |
| 150 | #[doc = "32-bit polynomial" ] |
| 151 | POLYSIZE32 = 0x0, |
| 152 | #[doc = "16-bit polynomial" ] |
| 153 | POLYSIZE16 = 0x01, |
| 154 | #[doc = "8-bit polynomial" ] |
| 155 | POLYSIZE8 = 0x02, |
| 156 | #[doc = "7-bit polynomial" ] |
| 157 | POLYSIZE7 = 0x03, |
| 158 | } |
| 159 | impl Polysize { |
| 160 | #[inline (always)] |
| 161 | pub const fn from_bits(val: u8) -> Polysize { |
| 162 | unsafe { core::mem::transmute(val & 0x03) } |
| 163 | } |
| 164 | #[inline (always)] |
| 165 | pub const fn to_bits(self) -> u8 { |
| 166 | unsafe { core::mem::transmute(self) } |
| 167 | } |
| 168 | } |
| 169 | impl From<u8> for Polysize { |
| 170 | #[inline (always)] |
| 171 | fn from(val: u8) -> Polysize { |
| 172 | Polysize::from_bits(val) |
| 173 | } |
| 174 | } |
| 175 | impl From<Polysize> for u8 { |
| 176 | #[inline (always)] |
| 177 | fn from(val: Polysize) -> u8 { |
| 178 | Polysize::to_bits(val) |
| 179 | } |
| 180 | } |
| 181 | #[repr (u8)] |
| 182 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
| 183 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 184 | pub enum RevIn { |
| 185 | #[doc = "Bit order not affected" ] |
| 186 | NORMAL = 0x0, |
| 187 | #[doc = "Bit reversal done by byte" ] |
| 188 | BYTE = 0x01, |
| 189 | #[doc = "Bit reversal done by half-word" ] |
| 190 | HALF_WORD = 0x02, |
| 191 | #[doc = "Bit reversal done by word" ] |
| 192 | WORD = 0x03, |
| 193 | } |
| 194 | impl RevIn { |
| 195 | #[inline (always)] |
| 196 | pub const fn from_bits(val: u8) -> RevIn { |
| 197 | unsafe { core::mem::transmute(val & 0x03) } |
| 198 | } |
| 199 | #[inline (always)] |
| 200 | pub const fn to_bits(self) -> u8 { |
| 201 | unsafe { core::mem::transmute(self) } |
| 202 | } |
| 203 | } |
| 204 | impl From<u8> for RevIn { |
| 205 | #[inline (always)] |
| 206 | fn from(val: u8) -> RevIn { |
| 207 | RevIn::from_bits(val) |
| 208 | } |
| 209 | } |
| 210 | impl From<RevIn> for u8 { |
| 211 | #[inline (always)] |
| 212 | fn from(val: RevIn) -> u8 { |
| 213 | RevIn::to_bits(val) |
| 214 | } |
| 215 | } |
| 216 | #[repr (u8)] |
| 217 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
| 218 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 219 | pub enum RevOut { |
| 220 | #[doc = "Bit order not affected" ] |
| 221 | NORMAL = 0x0, |
| 222 | #[doc = "Bit reversed output" ] |
| 223 | REVERSED = 0x01, |
| 224 | } |
| 225 | impl RevOut { |
| 226 | #[inline (always)] |
| 227 | pub const fn from_bits(val: u8) -> RevOut { |
| 228 | unsafe { core::mem::transmute(val & 0x01) } |
| 229 | } |
| 230 | #[inline (always)] |
| 231 | pub const fn to_bits(self) -> u8 { |
| 232 | unsafe { core::mem::transmute(self) } |
| 233 | } |
| 234 | } |
| 235 | impl From<u8> for RevOut { |
| 236 | #[inline (always)] |
| 237 | fn from(val: u8) -> RevOut { |
| 238 | RevOut::from_bits(val) |
| 239 | } |
| 240 | } |
| 241 | impl From<RevOut> for u8 { |
| 242 | #[inline (always)] |
| 243 | fn from(val: RevOut) -> u8 { |
| 244 | RevOut::to_bits(val) |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |