1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
use crate::generic::*; #[doc = "Clock divider. If non-zero, CS_START_MANY will start conversions at regular intervals rather than back-to-back. The divider is reset when either of these fields are written. Total period is 1 + INT + FRAC / 256"] #[repr(transparent)] #[derive(Copy, Clone)] pub struct Div(pub u32); impl Div { #[doc = "Integer part of clock divisor."] pub const fn int(&self) -> u16 { let val = (self.0 >> 8u32) & 0xffff; val as u16 } #[doc = "Integer part of clock divisor."] pub fn set_int(&mut self, val: u16) { self.0 = (self.0 & !(0xffff << 8u32)) | (((val as u32) & 0xffff) << 8u32); } #[doc = "Fractional part of clock divisor. First-order delta-sigma."] pub const fn frac(&self) -> u8 { let val = (self.0 >> 0u32) & 0xff; val as u8 } #[doc = "Fractional part of clock divisor. First-order delta-sigma."] pub fn set_frac(&mut self, val: u8) { self.0 = (self.0 & !(0xff << 0u32)) | (((val as u32) & 0xff) << 0u32); } } impl Default for Div { fn default() -> Div { Div(0) } } #[doc = "Conversion result FIFO"] #[repr(transparent)] #[derive(Copy, Clone)] pub struct Fifo(pub u32); impl Fifo { #[doc = "1 if this particular sample experienced a conversion error. Remains in the same location if the sample is shifted."] pub const fn err(&self) -> bool { let val = (self.0 >> 15u32) & 0x01; val != 0 } #[doc = "1 if this particular sample experienced a conversion error. Remains in the same location if the sample is shifted."] pub fn set_err(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 15u32)) | (((val as u32) & 0x01) << 15u32); } pub const fn val(&self) -> u16 { let val = (self.0 >> 0u32) & 0x0fff; val as u16 } pub fn set_val(&mut self, val: u16) { self.0 = (self.0 & !(0x0fff << 0u32)) | (((val as u32) & 0x0fff) << 0u32); } } impl Default for Fifo { fn default() -> Fifo { Fifo(0) } } #[doc = "ADC Control and Status"] #[repr(transparent)] #[derive(Copy, Clone)] pub struct Cs(pub u32); impl Cs { #[doc = "Round-robin sampling. 1 bit per channel. Set all bits to 0 to disable. Otherwise, the ADC will cycle through each enabled channel in a round-robin fashion. The first channel to be sampled will be the one currently indicated by AINSEL. AINSEL will be updated after each conversion with the newly-selected channel."] pub const fn rrobin(&self) -> u8 { let val = (self.0 >> 16u32) & 0x1f; val as u8 } #[doc = "Round-robin sampling. 1 bit per channel. Set all bits to 0 to disable. Otherwise, the ADC will cycle through each enabled channel in a round-robin fashion. The first channel to be sampled will be the one currently indicated by AINSEL. AINSEL will be updated after each conversion with the newly-selected channel."] pub fn set_rrobin(&mut self, val: u8) { self.0 = (self.0 & !(0x1f << 16u32)) | (((val as u32) & 0x1f) << 16u32); } #[doc = "Select analog mux input. Updated automatically in round-robin mode."] pub const fn ainsel(&self) -> u8 { let val = (self.0 >> 12u32) & 0x07; val as u8 } #[doc = "Select analog mux input. Updated automatically in round-robin mode."] pub fn set_ainsel(&mut self, val: u8) { self.0 = (self.0 & !(0x07 << 12u32)) | (((val as u32) & 0x07) << 12u32); } #[doc = "Some past ADC conversion encountered an error. Write 1 to clear."] pub const fn err_sticky(&self) -> bool { let val = (self.0 >> 10u32) & 0x01; val != 0 } #[doc = "Some past ADC conversion encountered an error. Write 1 to clear."] pub fn set_err_sticky(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 10u32)) | (((val as u32) & 0x01) << 10u32); } #[doc = "The most recent ADC conversion encountered an error; result is undefined or noisy."] pub const fn err(&self) -> bool { let val = (self.0 >> 9u32) & 0x01; val != 0 } #[doc = "The most recent ADC conversion encountered an error; result is undefined or noisy."] pub fn set_err(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 9u32)) | (((val as u32) & 0x01) << 9u32); } #[doc = "1 if the ADC is ready to start a new conversion. Implies any previous conversion has completed. 0 whilst conversion in progress."] pub const fn ready(&self) -> bool { let val = (self.0 >> 8u32) & 0x01; val != 0 } #[doc = "1 if the ADC is ready to start a new conversion. Implies any previous conversion has completed. 0 whilst conversion in progress."] pub fn set_ready(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 8u32)) | (((val as u32) & 0x01) << 8u32); } #[doc = "Continuously perform conversions whilst this bit is 1. A new conversion will start immediately after the previous finishes."] pub const fn start_many(&self) -> bool { let val = (self.0 >> 3u32) & 0x01; val != 0 } #[doc = "Continuously perform conversions whilst this bit is 1. A new conversion will start immediately after the previous finishes."] pub fn set_start_many(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 3u32)) | (((val as u32) & 0x01) << 3u32); } #[doc = "Start a single conversion. Self-clearing. Ignored if start_many is asserted."] pub const fn start_once(&self) -> bool { let val = (self.0 >> 2u32) & 0x01; val != 0 } #[doc = "Start a single conversion. Self-clearing. Ignored if start_many is asserted."] pub fn set_start_once(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 2u32)) | (((val as u32) & 0x01) << 2u32); } #[doc = "Power on temperature sensor. 1 - enabled. 0 - disabled."] pub const fn ts_en(&self) -> bool { let val = (self.0 >> 1u32) & 0x01; val != 0 } #[doc = "Power on temperature sensor. 1 - enabled. 0 - disabled."] pub fn set_ts_en(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 1u32)) | (((val as u32) & 0x01) << 1u32); } #[doc = "Power on ADC and enable its clock. 1 - enabled. 0 - disabled."] pub const fn en(&self) -> bool { let val = (self.0 >> 0u32) & 0x01; val != 0 } #[doc = "Power on ADC and enable its clock. 1 - enabled. 0 - disabled."] pub fn set_en(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 0u32)) | (((val as u32) & 0x01) << 0u32); } } impl Default for Cs { fn default() -> Cs { Cs(0) } } #[doc = "Result of most recent ADC conversion"] #[repr(transparent)] #[derive(Copy, Clone)] pub struct Result(pub u32); impl Result { pub const fn result(&self) -> u16 { let val = (self.0 >> 0u32) & 0x0fff; val as u16 } pub fn set_result(&mut self, val: u16) { self.0 = (self.0 & !(0x0fff << 0u32)) | (((val as u32) & 0x0fff) << 0u32); } } impl Default for Result { fn default() -> Result { Result(0) } } #[doc = "FIFO control and status"] #[repr(transparent)] #[derive(Copy, Clone)] pub struct Fcs(pub u32); impl Fcs { #[doc = "DREQ/IRQ asserted when level >= threshold"] pub const fn thresh(&self) -> u8 { let val = (self.0 >> 24u32) & 0x0f; val as u8 } #[doc = "DREQ/IRQ asserted when level >= threshold"] pub fn set_thresh(&mut self, val: u8) { self.0 = (self.0 & !(0x0f << 24u32)) | (((val as u32) & 0x0f) << 24u32); } #[doc = "The number of conversion results currently waiting in the FIFO"] pub const fn level(&self) -> u8 { let val = (self.0 >> 16u32) & 0x0f; val as u8 } #[doc = "The number of conversion results currently waiting in the FIFO"] pub fn set_level(&mut self, val: u8) { self.0 = (self.0 & !(0x0f << 16u32)) | (((val as u32) & 0x0f) << 16u32); } #[doc = "1 if the FIFO has been overflowed. Write 1 to clear."] pub const fn over(&self) -> bool { let val = (self.0 >> 11u32) & 0x01; val != 0 } #[doc = "1 if the FIFO has been overflowed. Write 1 to clear."] pub fn set_over(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 11u32)) | (((val as u32) & 0x01) << 11u32); } #[doc = "1 if the FIFO has been underflowed. Write 1 to clear."] pub const fn under(&self) -> bool { let val = (self.0 >> 10u32) & 0x01; val != 0 } #[doc = "1 if the FIFO has been underflowed. Write 1 to clear."] pub fn set_under(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 10u32)) | (((val as u32) & 0x01) << 10u32); } pub const fn full(&self) -> bool { let val = (self.0 >> 9u32) & 0x01; val != 0 } pub fn set_full(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 9u32)) | (((val as u32) & 0x01) << 9u32); } pub const fn empty(&self) -> bool { let val = (self.0 >> 8u32) & 0x01; val != 0 } pub fn set_empty(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 8u32)) | (((val as u32) & 0x01) << 8u32); } #[doc = "If 1: assert DMA requests when FIFO contains data"] pub const fn dreq_en(&self) -> bool { let val = (self.0 >> 3u32) & 0x01; val != 0 } #[doc = "If 1: assert DMA requests when FIFO contains data"] pub fn set_dreq_en(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 3u32)) | (((val as u32) & 0x01) << 3u32); } #[doc = "If 1: conversion error bit appears in the FIFO alongside the result"] pub const fn err(&self) -> bool { let val = (self.0 >> 2u32) & 0x01; val != 0 } #[doc = "If 1: conversion error bit appears in the FIFO alongside the result"] pub fn set_err(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 2u32)) | (((val as u32) & 0x01) << 2u32); } #[doc = "If 1: FIFO results are right-shifted to be one byte in size. Enables DMA to byte buffers."] pub const fn shift(&self) -> bool { let val = (self.0 >> 1u32) & 0x01; val != 0 } #[doc = "If 1: FIFO results are right-shifted to be one byte in size. Enables DMA to byte buffers."] pub fn set_shift(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 1u32)) | (((val as u32) & 0x01) << 1u32); } #[doc = "If 1: write result to the FIFO after each conversion."] pub const fn en(&self) -> bool { let val = (self.0 >> 0u32) & 0x01; val != 0 } #[doc = "If 1: write result to the FIFO after each conversion."] pub fn set_en(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 0u32)) | (((val as u32) & 0x01) << 0u32); } } impl Default for Fcs { fn default() -> Fcs { Fcs(0) } } #[doc = "Interrupt Force"] #[repr(transparent)] #[derive(Copy, Clone)] pub struct Int(pub u32); impl Int { #[doc = "Triggered when the sample FIFO reaches a certain level. This level can be programmed via the FCS_THRESH field."] pub const fn fifo(&self) -> bool { let val = (self.0 >> 0u32) & 0x01; val != 0 } #[doc = "Triggered when the sample FIFO reaches a certain level. This level can be programmed via the FCS_THRESH field."] pub fn set_fifo(&mut self, val: bool) { self.0 = (self.0 & !(0x01 << 0u32)) | (((val as u32) & 0x01) << 0u32); } } impl Default for Int { fn default() -> Int { Int(0) } }