sam3x8e-pac 0.1.6-dev

Peripheral Access Crate (PAC) for the Atmel SAM3X8E.
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Anach {
    #[doc = "No analog change on channel switching: DIFF0, GAIN0 and OFF0 are used for all channels"]
    NONE = 0x0,
    #[doc = "Allows different analog settings for each channel. See ADC_CGR and ADC_COR Registers"]
    ALLOWED = 0x01,
}
impl Anach {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Anach {
        unsafe { core::mem::transmute(val & 0x01) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Anach {
    #[inline(always)]
    fn from(val: u8) -> Anach {
        Anach::from_bits(val)
    }
}
impl From<Anach> for u8 {
    #[inline(always)]
    fn from(val: Anach) -> u8 {
        Anach::to_bits(val)
    }
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Cmpmode {
    #[doc = "Generates an event when the converted data is lower than the low threshold of the window."]
    LOW = 0x0,
    #[doc = "Generates an event when the converted data is higher than the high threshold of the window."]
    HIGH = 0x01,
    #[doc = "Generates an event when the converted data is in the comparison window."]
    IN = 0x02,
    #[doc = "Generates an event when the converted data is out of the comparison window."]
    OUT = 0x03,
}
impl Cmpmode {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Cmpmode {
        unsafe { core::mem::transmute(val & 0x03) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Cmpmode {
    #[inline(always)]
    fn from(val: u8) -> Cmpmode {
        Cmpmode::from_bits(val)
    }
}
impl From<Cmpmode> for u8 {
    #[inline(always)]
    fn from(val: Cmpmode) -> u8 {
        Cmpmode::to_bits(val)
    }
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Freerun {
    #[doc = "Normal Mode"]
    OFF = 0x0,
    #[doc = "Free Run Mode: Never wait for any trigger."]
    ON = 0x01,
}
impl Freerun {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Freerun {
        unsafe { core::mem::transmute(val & 0x01) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Freerun {
    #[inline(always)]
    fn from(val: u8) -> Freerun {
        Freerun::from_bits(val)
    }
}
impl From<Freerun> for u8 {
    #[inline(always)]
    fn from(val: Freerun) -> u8 {
        Freerun::to_bits(val)
    }
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Fwup {
    #[doc = "If SLEEP is 1 then both ADC Core and reference voltage circuitry are OFF between conversions"]
    OFF = 0x0,
    #[doc = "If SLEEP is 1 then Fast Wake-up Sleep Mode: The Voltage reference is ON between conversions and ADC Core is OFF"]
    ON = 0x01,
}
impl Fwup {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Fwup {
        unsafe { core::mem::transmute(val & 0x01) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Fwup {
    #[inline(always)]
    fn from(val: u8) -> Fwup {
        Fwup::from_bits(val)
    }
}
impl From<Fwup> for u8 {
    #[inline(always)]
    fn from(val: Fwup) -> u8 {
        Fwup::to_bits(val)
    }
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Resolution {
    High = 0x0,
    Low = 0x01,
}
impl Resolution {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Resolution {
        unsafe { core::mem::transmute(val & 0x01) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Resolution {
    #[inline(always)]
    fn from(val: u8) -> Resolution {
        Resolution::from_bits(val)
    }
}
impl From<Resolution> for u8 {
    #[inline(always)]
    fn from(val: Resolution) -> u8 {
        Resolution::to_bits(val)
    }
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Settling {
    #[doc = "3 periods of ADCClock"]
    AST3 = 0x0,
    #[doc = "5 periods of ADCClock"]
    AST5 = 0x01,
    #[doc = "9 periods of ADCClock"]
    AST9 = 0x02,
    #[doc = "17 periods of ADCClock"]
    AST17 = 0x03,
}
impl Settling {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Settling {
        unsafe { core::mem::transmute(val & 0x03) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Settling {
    #[inline(always)]
    fn from(val: u8) -> Settling {
        Settling::from_bits(val)
    }
}
impl From<Settling> for u8 {
    #[inline(always)]
    fn from(val: Settling) -> u8 {
        Settling::to_bits(val)
    }
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Sleep {
    #[doc = "Normal Mode: The ADC Core and reference voltage circuitry are kept ON between conversions"]
    NORMAL = 0x0,
    #[doc = "Sleep Mode: The wake-up time can be modified by programming FWUP bit"]
    SLEEP = 0x01,
}
impl Sleep {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Sleep {
        unsafe { core::mem::transmute(val & 0x01) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Sleep {
    #[inline(always)]
    fn from(val: u8) -> Sleep {
        Sleep::from_bits(val)
    }
}
impl From<Sleep> for u8 {
    #[inline(always)]
    fn from(val: Sleep) -> u8 {
        Sleep::to_bits(val)
    }
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Startup {
    #[doc = "0 periods of ADCClock"]
    SUT0 = 0x0,
    #[doc = "8 periods of ADCClock"]
    SUT8 = 0x01,
    #[doc = "16 periods of ADCClock"]
    SUT16 = 0x02,
    #[doc = "24 periods of ADCClock"]
    SUT24 = 0x03,
    #[doc = "64 periods of ADCClock"]
    SUT64 = 0x04,
    #[doc = "80 periods of ADCClock"]
    SUT80 = 0x05,
    #[doc = "96 periods of ADCClock"]
    SUT96 = 0x06,
    #[doc = "112 periods of ADCClock"]
    SUT112 = 0x07,
    #[doc = "512 periods of ADCClock"]
    SUT512 = 0x08,
    #[doc = "576 periods of ADCClock"]
    SUT576 = 0x09,
    #[doc = "640 periods of ADCClock"]
    SUT640 = 0x0a,
    #[doc = "704 periods of ADCClock"]
    SUT704 = 0x0b,
    #[doc = "768 periods of ADCClock"]
    SUT768 = 0x0c,
    #[doc = "832 periods of ADCClock"]
    SUT832 = 0x0d,
    #[doc = "896 periods of ADCClock"]
    SUT896 = 0x0e,
    #[doc = "960 periods of ADCClock"]
    SUT960 = 0x0f,
}
impl Startup {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Startup {
        unsafe { core::mem::transmute(val & 0x0f) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Startup {
    #[inline(always)]
    fn from(val: u8) -> Startup {
        Startup::from_bits(val)
    }
}
impl From<Startup> for u8 {
    #[inline(always)]
    fn from(val: Startup) -> u8 {
        Startup::to_bits(val)
    }
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Trgen {
    #[doc = "Hardware triggers are disabled. Starting a conversion is only possible by software."]
    DIS = 0x0,
    #[doc = "Hardware trigger selected by TRGSEL field is enabled."]
    EN = 0x01,
}
impl Trgen {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Trgen {
        unsafe { core::mem::transmute(val & 0x01) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Trgen {
    #[inline(always)]
    fn from(val: u8) -> Trgen {
        Trgen::from_bits(val)
    }
}
impl From<Trgen> for u8 {
    #[inline(always)]
    fn from(val: Trgen) -> u8 {
        Trgen::to_bits(val)
    }
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Trgsel {
    #[doc = "External : ADCTRG"]
    ADC_TRIG0 = 0x0,
    #[doc = "TIOA Output of the Timer Counter Channel 0"]
    ADC_TRIG1 = 0x01,
    #[doc = "TIOA Output of the Timer Counter Channel 1"]
    ADC_TRIG2 = 0x02,
    #[doc = "TIOA Output of the Timer Counter Channel 2"]
    ADC_TRIG3 = 0x03,
    #[doc = "PWM Event Line 0"]
    ADC_TRIG4 = 0x04,
    #[doc = "PWM Event Line 0"]
    ADC_TRIG5 = 0x05,
    _RESERVED_6 = 0x06,
    _RESERVED_7 = 0x07,
}
impl Trgsel {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Trgsel {
        unsafe { core::mem::transmute(val & 0x07) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Trgsel {
    #[inline(always)]
    fn from(val: u8) -> Trgsel {
        Trgsel::from_bits(val)
    }
}
impl From<Trgsel> for u8 {
    #[inline(always)]
    fn from(val: Trgsel) -> u8 {
        Trgsel::to_bits(val)
    }
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Useq {
    #[doc = "Normal Mode: The controller converts channels in a simple numeric order depending only on the channel index."]
    NUM_ORDER = 0x0,
    #[doc = "User Sequence Mode: The sequence respects what is defined in ADC_SEQR1 and ADC_SEQR2 registers and can be used to convert several times the same channel."]
    REG_ORDER = 0x01,
}
impl Useq {
    #[inline(always)]
    pub const fn from_bits(val: u8) -> Useq {
        unsafe { core::mem::transmute(val & 0x01) }
    }
    #[inline(always)]
    pub const fn to_bits(self) -> u8 {
        unsafe { core::mem::transmute(self) }
    }
}
impl From<u8> for Useq {
    #[inline(always)]
    fn from(val: u8) -> Useq {
        Useq::from_bits(val)
    }
}
impl From<Useq> for u8 {
    #[inline(always)]
    fn from(val: Useq) -> u8 {
        Useq::to_bits(val)
    }
}
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct WpKey(u32);
impl WpKey {
    #[doc = "Writing any other value in this field aborts the write operation of the WPEN bit.Always reads as 0"]
    pub const PASSWD: Self = Self(0x0041_4443);
}
impl WpKey {
    pub const fn from_bits(val: u32) -> WpKey {
        Self(val & 0x00ff_ffff)
    }
    pub const fn to_bits(self) -> u32 {
        self.0
    }
}
impl core::fmt::Debug for WpKey {
    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
        match self.0 {
            0x0041_4443 => f.write_str("PASSWD"),
            other => core::write!(f, "0x{:02X}", other),
        }
    }
}
#[cfg(feature = "defmt")]
impl defmt::Format for WpKey {
    fn format(&self, f: defmt::Formatter) {
        match self.0 {
            0x0041_4443 => defmt::write!(f, "PASSWD"),
            other => defmt::write!(f, "0x{:02X}", other),
        }
    }
}
impl From<u32> for WpKey {
    #[inline(always)]
    fn from(val: u32) -> WpKey {
        WpKey::from_bits(val)
    }
}
impl From<WpKey> for u32 {
    #[inline(always)]
    fn from(val: WpKey) -> u32 {
        WpKey::to_bits(val)
    }
}