| 1 | #![allow (clippy::missing_safety_doc)] |
| 2 | #![allow (clippy::identity_op)] |
| 3 | #![allow (clippy::unnecessary_cast)] |
| 4 | #![allow (clippy::erasing_op)] |
| 5 | |
| 6 | #[doc = "Comparator." ] |
| 7 | #[derive (Copy, Clone, Eq, PartialEq)] |
| 8 | pub struct Comp { |
| 9 | ptr: *mut u8, |
| 10 | } |
| 11 | unsafe impl Send for Comp {} |
| 12 | unsafe impl Sync for Comp {} |
| 13 | impl Comp { |
| 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 = "Comparator control and status register." ] |
| 23 | #[inline (always)] |
| 24 | pub const fn csr(self) -> crate::common::Reg<regs::Csr, crate::common::RW> { |
| 25 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(count:0x0usize) as _) } |
| 26 | } |
| 27 | } |
| 28 | pub mod regs { |
| 29 | #[doc = "control and status register." ] |
| 30 | #[repr (transparent)] |
| 31 | #[derive (Copy, Clone, Eq, PartialEq)] |
| 32 | pub struct Csr(pub u32); |
| 33 | impl Csr { |
| 34 | #[doc = "Enable" ] |
| 35 | #[inline (always)] |
| 36 | pub const fn en(&self) -> bool { |
| 37 | let val = (self.0 >> 0usize) & 0x01; |
| 38 | val != 0 |
| 39 | } |
| 40 | #[doc = "Enable" ] |
| 41 | #[inline (always)] |
| 42 | pub fn set_en(&mut self, val: bool) { |
| 43 | self.0 = (self.0 & !(0x01 << 0usize)) | (((val as u32) & 0x01) << 0usize); |
| 44 | } |
| 45 | #[doc = "Input minus selection bits." ] |
| 46 | #[inline (always)] |
| 47 | pub const fn inmsel(&self) -> super::vals::Inm { |
| 48 | let val = (self.0 >> 4usize) & 0x0f; |
| 49 | super::vals::Inm::from_bits(val as u8) |
| 50 | } |
| 51 | #[doc = "Input minus selection bits." ] |
| 52 | #[inline (always)] |
| 53 | pub fn set_inmsel(&mut self, val: super::vals::Inm) { |
| 54 | self.0 = (self.0 & !(0x0f << 4usize)) | (((val.to_bits() as u32) & 0x0f) << 4usize); |
| 55 | } |
| 56 | #[doc = "Input plus selection bit." ] |
| 57 | #[inline (always)] |
| 58 | pub const fn inpsel(&self) -> u8 { |
| 59 | let val = (self.0 >> 8usize) & 0x07; |
| 60 | val as u8 |
| 61 | } |
| 62 | #[doc = "Input plus selection bit." ] |
| 63 | #[inline (always)] |
| 64 | pub fn set_inpsel(&mut self, val: u8) { |
| 65 | self.0 = (self.0 & !(0x07 << 8usize)) | (((val as u32) & 0x07) << 8usize); |
| 66 | } |
| 67 | #[doc = "Comparator 1 noninverting input selector for window mode." ] |
| 68 | #[inline (always)] |
| 69 | pub const fn winmode(&self) -> super::vals::WindowMode { |
| 70 | let val = (self.0 >> 11usize) & 0x01; |
| 71 | super::vals::WindowMode::from_bits(val as u8) |
| 72 | } |
| 73 | #[doc = "Comparator 1 noninverting input selector for window mode." ] |
| 74 | #[inline (always)] |
| 75 | pub fn set_winmode(&mut self, val: super::vals::WindowMode) { |
| 76 | self.0 = (self.0 & !(0x01 << 11usize)) | (((val.to_bits() as u32) & 0x01) << 11usize); |
| 77 | } |
| 78 | #[doc = "Comparator 1 output selector." ] |
| 79 | #[inline (always)] |
| 80 | pub const fn winout(&self) -> super::vals::WindowOut { |
| 81 | let val = (self.0 >> 14usize) & 0x01; |
| 82 | super::vals::WindowOut::from_bits(val as u8) |
| 83 | } |
| 84 | #[doc = "Comparator 1 output selector." ] |
| 85 | #[inline (always)] |
| 86 | pub fn set_winout(&mut self, val: super::vals::WindowOut) { |
| 87 | self.0 = (self.0 & !(0x01 << 14usize)) | (((val.to_bits() as u32) & 0x01) << 14usize); |
| 88 | } |
| 89 | #[doc = "Polarity selection bit." ] |
| 90 | #[inline (always)] |
| 91 | pub const fn polarity(&self) -> super::vals::Polarity { |
| 92 | let val = (self.0 >> 15usize) & 0x01; |
| 93 | super::vals::Polarity::from_bits(val as u8) |
| 94 | } |
| 95 | #[doc = "Polarity selection bit." ] |
| 96 | #[inline (always)] |
| 97 | pub fn set_polarity(&mut self, val: super::vals::Polarity) { |
| 98 | self.0 = (self.0 & !(0x01 << 15usize)) | (((val.to_bits() as u32) & 0x01) << 15usize); |
| 99 | } |
| 100 | #[doc = "Hysteresis selection bits." ] |
| 101 | #[inline (always)] |
| 102 | pub const fn hyst(&self) -> super::vals::Hysteresis { |
| 103 | let val = (self.0 >> 16usize) & 0x03; |
| 104 | super::vals::Hysteresis::from_bits(val as u8) |
| 105 | } |
| 106 | #[doc = "Hysteresis selection bits." ] |
| 107 | #[inline (always)] |
| 108 | pub fn set_hyst(&mut self, val: super::vals::Hysteresis) { |
| 109 | self.0 = (self.0 & !(0x03 << 16usize)) | (((val.to_bits() as u32) & 0x03) << 16usize); |
| 110 | } |
| 111 | #[doc = "Power Mode." ] |
| 112 | #[inline (always)] |
| 113 | pub const fn pwrmode(&self) -> super::vals::PowerMode { |
| 114 | let val = (self.0 >> 18usize) & 0x03; |
| 115 | super::vals::PowerMode::from_bits(val as u8) |
| 116 | } |
| 117 | #[doc = "Power Mode." ] |
| 118 | #[inline (always)] |
| 119 | pub fn set_pwrmode(&mut self, val: super::vals::PowerMode) { |
| 120 | self.0 = (self.0 & !(0x03 << 18usize)) | (((val.to_bits() as u32) & 0x03) << 18usize); |
| 121 | } |
| 122 | #[doc = "Blanking source selection bits." ] |
| 123 | #[inline (always)] |
| 124 | pub const fn blanksel(&self) -> super::vals::Blanking { |
| 125 | let val = (self.0 >> 20usize) & 0x1f; |
| 126 | super::vals::Blanking::from_bits(val as u8) |
| 127 | } |
| 128 | #[doc = "Blanking source selection bits." ] |
| 129 | #[inline (always)] |
| 130 | pub fn set_blanksel(&mut self, val: super::vals::Blanking) { |
| 131 | self.0 = (self.0 & !(0x1f << 20usize)) | (((val.to_bits() as u32) & 0x1f) << 20usize); |
| 132 | } |
| 133 | #[doc = "Output status bit." ] |
| 134 | #[inline (always)] |
| 135 | pub const fn value(&self) -> bool { |
| 136 | let val = (self.0 >> 30usize) & 0x01; |
| 137 | val != 0 |
| 138 | } |
| 139 | #[doc = "Output status bit." ] |
| 140 | #[inline (always)] |
| 141 | pub fn set_value(&mut self, val: bool) { |
| 142 | self.0 = (self.0 & !(0x01 << 30usize)) | (((val as u32) & 0x01) << 30usize); |
| 143 | } |
| 144 | #[doc = "Register lock bit." ] |
| 145 | #[inline (always)] |
| 146 | pub const fn lock(&self) -> bool { |
| 147 | let val = (self.0 >> 31usize) & 0x01; |
| 148 | val != 0 |
| 149 | } |
| 150 | #[doc = "Register lock bit." ] |
| 151 | #[inline (always)] |
| 152 | pub fn set_lock(&mut self, val: bool) { |
| 153 | self.0 = (self.0 & !(0x01 << 31usize)) | (((val as u32) & 0x01) << 31usize); |
| 154 | } |
| 155 | } |
| 156 | impl Default for Csr { |
| 157 | #[inline (always)] |
| 158 | fn default() -> Csr { |
| 159 | Csr(0) |
| 160 | } |
| 161 | } |
| 162 | impl core::fmt::Debug for Csr { |
| 163 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 164 | f.debug_struct("Csr" ) |
| 165 | .field("en" , &self.en()) |
| 166 | .field("inmsel" , &self.inmsel()) |
| 167 | .field("inpsel" , &self.inpsel()) |
| 168 | .field("winmode" , &self.winmode()) |
| 169 | .field("winout" , &self.winout()) |
| 170 | .field("polarity" , &self.polarity()) |
| 171 | .field("hyst" , &self.hyst()) |
| 172 | .field("pwrmode" , &self.pwrmode()) |
| 173 | .field("blanksel" , &self.blanksel()) |
| 174 | .field("value" , &self.value()) |
| 175 | .field("lock" , &self.lock()) |
| 176 | .finish() |
| 177 | } |
| 178 | } |
| 179 | #[cfg (feature = "defmt" )] |
| 180 | impl defmt::Format for Csr { |
| 181 | fn format(&self, f: defmt::Formatter) { |
| 182 | #[derive (defmt :: Format)] |
| 183 | struct Csr { |
| 184 | en: bool, |
| 185 | inmsel: super::vals::Inm, |
| 186 | inpsel: u8, |
| 187 | winmode: super::vals::WindowMode, |
| 188 | winout: super::vals::WindowOut, |
| 189 | polarity: super::vals::Polarity, |
| 190 | hyst: super::vals::Hysteresis, |
| 191 | pwrmode: super::vals::PowerMode, |
| 192 | blanksel: super::vals::Blanking, |
| 193 | value: bool, |
| 194 | lock: bool, |
| 195 | } |
| 196 | let proxy = Csr { |
| 197 | en: self.en(), |
| 198 | inmsel: self.inmsel(), |
| 199 | inpsel: self.inpsel(), |
| 200 | winmode: self.winmode(), |
| 201 | winout: self.winout(), |
| 202 | polarity: self.polarity(), |
| 203 | hyst: self.hyst(), |
| 204 | pwrmode: self.pwrmode(), |
| 205 | blanksel: self.blanksel(), |
| 206 | value: self.value(), |
| 207 | lock: self.lock(), |
| 208 | }; |
| 209 | defmt::write!(f, "{}" , proxy) |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | pub mod vals { |
| 214 | #[repr (transparent)] |
| 215 | #[derive (Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 216 | pub struct Blanking(pub u8); |
| 217 | impl Blanking { |
| 218 | #[doc = "No blanking." ] |
| 219 | pub const NO_BLANKING: Self = Self(0x0); |
| 220 | #[doc = "Check data sheet for blanking options" ] |
| 221 | pub const BLANK1: Self = Self(0x01); |
| 222 | #[doc = "Check data sheet for blanking options" ] |
| 223 | pub const BLANK2: Self = Self(0x02); |
| 224 | #[doc = "Check data sheet for blanking options" ] |
| 225 | pub const BLANK3: Self = Self(0x04); |
| 226 | } |
| 227 | impl Blanking { |
| 228 | pub const fn from_bits(val: u8) -> Blanking { |
| 229 | Self(val & 0x1f) |
| 230 | } |
| 231 | pub const fn to_bits(self) -> u8 { |
| 232 | self.0 |
| 233 | } |
| 234 | } |
| 235 | impl core::fmt::Debug for Blanking { |
| 236 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 237 | match self.0 { |
| 238 | 0x0 => f.write_str("NO_BLANKING" ), |
| 239 | 0x01 => f.write_str("BLANK1" ), |
| 240 | 0x02 => f.write_str("BLANK2" ), |
| 241 | 0x04 => f.write_str("BLANK3" ), |
| 242 | other => core::write!(f, "0x {:02X}" , other), |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | #[cfg (feature = "defmt" )] |
| 247 | impl defmt::Format for Blanking { |
| 248 | fn format(&self, f: defmt::Formatter) { |
| 249 | match self.0 { |
| 250 | 0x0 => defmt::write!(f, "NO_BLANKING" ), |
| 251 | 0x01 => defmt::write!(f, "BLANK1" ), |
| 252 | 0x02 => defmt::write!(f, "BLANK2" ), |
| 253 | 0x04 => defmt::write!(f, "BLANK3" ), |
| 254 | other => defmt::write!(f, "0x{:02X}" , other), |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | impl From<u8> for Blanking { |
| 259 | #[inline (always)] |
| 260 | fn from(val: u8) -> Blanking { |
| 261 | Blanking::from_bits(val) |
| 262 | } |
| 263 | } |
| 264 | impl From<Blanking> for u8 { |
| 265 | #[inline (always)] |
| 266 | fn from(val: Blanking) -> u8 { |
| 267 | Blanking::to_bits(val) |
| 268 | } |
| 269 | } |
| 270 | #[repr (u8)] |
| 271 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
| 272 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 273 | pub enum Hysteresis { |
| 274 | NONE = 0x0, |
| 275 | LOW = 0x01, |
| 276 | MEDIUM = 0x02, |
| 277 | HIGH = 0x03, |
| 278 | } |
| 279 | impl Hysteresis { |
| 280 | #[inline (always)] |
| 281 | pub const fn from_bits(val: u8) -> Hysteresis { |
| 282 | unsafe { core::mem::transmute(val & 0x03) } |
| 283 | } |
| 284 | #[inline (always)] |
| 285 | pub const fn to_bits(self) -> u8 { |
| 286 | unsafe { core::mem::transmute(self) } |
| 287 | } |
| 288 | } |
| 289 | impl From<u8> for Hysteresis { |
| 290 | #[inline (always)] |
| 291 | fn from(val: u8) -> Hysteresis { |
| 292 | Hysteresis::from_bits(val) |
| 293 | } |
| 294 | } |
| 295 | impl From<Hysteresis> for u8 { |
| 296 | #[inline (always)] |
| 297 | fn from(val: Hysteresis) -> u8 { |
| 298 | Hysteresis::to_bits(val) |
| 299 | } |
| 300 | } |
| 301 | #[repr (u8)] |
| 302 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
| 303 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 304 | pub enum Inm { |
| 305 | #[doc = "Inverting input set to 1/4 VRef" ] |
| 306 | QUARTER_VREF = 0x0, |
| 307 | #[doc = "Inverting input set to 1/2 VRef" ] |
| 308 | HALF_VREF = 0x01, |
| 309 | #[doc = "Inverting input set to 3/4 VRef" ] |
| 310 | THREE_QUARTER_VREF = 0x02, |
| 311 | #[doc = "Inverting input set to VRef" ] |
| 312 | VREF = 0x03, |
| 313 | #[doc = "Inverting input set to DAC1 output" ] |
| 314 | DAC1 = 0x04, |
| 315 | #[doc = "Inverting input set to DAC2 output" ] |
| 316 | DAC2 = 0x05, |
| 317 | #[doc = "Inverting input set to IO1 (PB7)" ] |
| 318 | INM1 = 0x06, |
| 319 | #[doc = "Inverting input set to IO2 (PB3)" ] |
| 320 | INM2 = 0x07, |
| 321 | _RESERVED_8 = 0x08, |
| 322 | _RESERVED_9 = 0x09, |
| 323 | _RESERVED_a = 0x0a, |
| 324 | _RESERVED_b = 0x0b, |
| 325 | _RESERVED_c = 0x0c, |
| 326 | _RESERVED_d = 0x0d, |
| 327 | _RESERVED_e = 0x0e, |
| 328 | _RESERVED_f = 0x0f, |
| 329 | } |
| 330 | impl Inm { |
| 331 | #[inline (always)] |
| 332 | pub const fn from_bits(val: u8) -> Inm { |
| 333 | unsafe { core::mem::transmute(val & 0x0f) } |
| 334 | } |
| 335 | #[inline (always)] |
| 336 | pub const fn to_bits(self) -> u8 { |
| 337 | unsafe { core::mem::transmute(self) } |
| 338 | } |
| 339 | } |
| 340 | impl From<u8> for Inm { |
| 341 | #[inline (always)] |
| 342 | fn from(val: u8) -> Inm { |
| 343 | Inm::from_bits(val) |
| 344 | } |
| 345 | } |
| 346 | impl From<Inm> for u8 { |
| 347 | #[inline (always)] |
| 348 | fn from(val: Inm) -> u8 { |
| 349 | Inm::to_bits(val) |
| 350 | } |
| 351 | } |
| 352 | #[repr (u8)] |
| 353 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
| 354 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 355 | pub enum Polarity { |
| 356 | #[doc = "Output is not inverted." ] |
| 357 | NOT_INVERTED = 0x0, |
| 358 | #[doc = "Output is inverted." ] |
| 359 | INVERTED = 0x01, |
| 360 | } |
| 361 | impl Polarity { |
| 362 | #[inline (always)] |
| 363 | pub const fn from_bits(val: u8) -> Polarity { |
| 364 | unsafe { core::mem::transmute(val & 0x01) } |
| 365 | } |
| 366 | #[inline (always)] |
| 367 | pub const fn to_bits(self) -> u8 { |
| 368 | unsafe { core::mem::transmute(self) } |
| 369 | } |
| 370 | } |
| 371 | impl From<u8> for Polarity { |
| 372 | #[inline (always)] |
| 373 | fn from(val: u8) -> Polarity { |
| 374 | Polarity::from_bits(val) |
| 375 | } |
| 376 | } |
| 377 | impl From<Polarity> for u8 { |
| 378 | #[inline (always)] |
| 379 | fn from(val: Polarity) -> u8 { |
| 380 | Polarity::to_bits(val) |
| 381 | } |
| 382 | } |
| 383 | #[repr (u8)] |
| 384 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
| 385 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 386 | pub enum PowerMode { |
| 387 | #[doc = "High speed / full power." ] |
| 388 | HIGH_SPEED = 0x0, |
| 389 | #[doc = "Medium speed / medium power." ] |
| 390 | MEDIUM_SPEED = 0x01, |
| 391 | _RESERVED_2 = 0x02, |
| 392 | #[doc = "Very-low speed / ultra-low power." ] |
| 393 | ULTRA_LOW = 0x03, |
| 394 | } |
| 395 | impl PowerMode { |
| 396 | #[inline (always)] |
| 397 | pub const fn from_bits(val: u8) -> PowerMode { |
| 398 | unsafe { core::mem::transmute(val & 0x03) } |
| 399 | } |
| 400 | #[inline (always)] |
| 401 | pub const fn to_bits(self) -> u8 { |
| 402 | unsafe { core::mem::transmute(self) } |
| 403 | } |
| 404 | } |
| 405 | impl From<u8> for PowerMode { |
| 406 | #[inline (always)] |
| 407 | fn from(val: u8) -> PowerMode { |
| 408 | PowerMode::from_bits(val) |
| 409 | } |
| 410 | } |
| 411 | impl From<PowerMode> for u8 { |
| 412 | #[inline (always)] |
| 413 | fn from(val: PowerMode) -> u8 { |
| 414 | PowerMode::to_bits(val) |
| 415 | } |
| 416 | } |
| 417 | #[repr (u8)] |
| 418 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
| 419 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 420 | pub enum WindowMode { |
| 421 | #[doc = "Signal selected with INPSEL \\[2:0 \\] |
| 422 | bitfield of this register." ] |
| 423 | THIS_INPSEL = 0x0, |
| 424 | #[doc = "Signal selected with INPSEL \\[2:0 \\] |
| 425 | bitfield of the other register (required for window mode)." ] |
| 426 | OTHER_INPSEL = 0x01, |
| 427 | } |
| 428 | impl WindowMode { |
| 429 | #[inline (always)] |
| 430 | pub const fn from_bits(val: u8) -> WindowMode { |
| 431 | unsafe { core::mem::transmute(val & 0x01) } |
| 432 | } |
| 433 | #[inline (always)] |
| 434 | pub const fn to_bits(self) -> u8 { |
| 435 | unsafe { core::mem::transmute(self) } |
| 436 | } |
| 437 | } |
| 438 | impl From<u8> for WindowMode { |
| 439 | #[inline (always)] |
| 440 | fn from(val: u8) -> WindowMode { |
| 441 | WindowMode::from_bits(val) |
| 442 | } |
| 443 | } |
| 444 | impl From<WindowMode> for u8 { |
| 445 | #[inline (always)] |
| 446 | fn from(val: WindowMode) -> u8 { |
| 447 | WindowMode::to_bits(val) |
| 448 | } |
| 449 | } |
| 450 | #[repr (u8)] |
| 451 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
| 452 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 453 | pub enum WindowOut { |
| 454 | #[doc = "Comparator 1 value." ] |
| 455 | COMP1_VALUE = 0x0, |
| 456 | #[doc = "Comparator 1 value XOR comparator 2 value (required for window mode)." ] |
| 457 | COMP1_VALUE_XOR_COMP2_VALUE = 0x01, |
| 458 | } |
| 459 | impl WindowOut { |
| 460 | #[inline (always)] |
| 461 | pub const fn from_bits(val: u8) -> WindowOut { |
| 462 | unsafe { core::mem::transmute(val & 0x01) } |
| 463 | } |
| 464 | #[inline (always)] |
| 465 | pub const fn to_bits(self) -> u8 { |
| 466 | unsafe { core::mem::transmute(self) } |
| 467 | } |
| 468 | } |
| 469 | impl From<u8> for WindowOut { |
| 470 | #[inline (always)] |
| 471 | fn from(val: u8) -> WindowOut { |
| 472 | WindowOut::from_bits(val) |
| 473 | } |
| 474 | } |
| 475 | impl From<WindowOut> for u8 { |
| 476 | #[inline (always)] |
| 477 | fn from(val: WindowOut) -> u8 { |
| 478 | WindowOut::to_bits(val) |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |