Skip to main content

nrf52/ccm/mode/
mod.rs

1#[doc = r" Value read from the register"]
2pub struct R {
3    bits: u32,
4}
5#[doc = r" Value to write to the register"]
6pub struct W {
7    bits: u32,
8}
9impl super::MODE {
10    #[doc = r" Modifies the contents of the register"]
11    #[inline]
12    pub fn modify<F>(&self, f: F)
13    where
14        for<'w> F: FnOnce(&R, &'w mut W) -> &'w mut W,
15    {
16        let bits = self.register.get();
17        let r = R { bits: bits };
18        let mut w = W { bits: bits };
19        f(&r, &mut w);
20        self.register.set(w.bits);
21    }
22    #[doc = r" Reads the contents of the register"]
23    #[inline]
24    pub fn read(&self) -> R {
25        R {
26            bits: self.register.get(),
27        }
28    }
29    #[doc = r" Writes to the register"]
30    #[inline]
31    pub fn write<F>(&self, f: F)
32    where
33        F: FnOnce(&mut W) -> &mut W,
34    {
35        let mut w = W::reset_value();
36        f(&mut w);
37        self.register.set(w.bits);
38    }
39    #[doc = r" Writes the reset value to the register"]
40    #[inline]
41    pub fn reset(&self) {
42        self.write(|w| w)
43    }
44}
45#[doc = "Possible values of the field `MODE`"]
46#[derive(Clone, Copy, Debug, PartialEq)]
47pub enum MODER {
48    #[doc = "AES CCM packet encryption mode"]
49    ENCRYPTION,
50    #[doc = "AES CCM packet decryption mode"]
51    DECRYPTION,
52}
53impl MODER {
54    #[doc = r" Returns `true` if the bit is clear (0)"]
55    #[inline]
56    pub fn bit_is_clear(&self) -> bool {
57        !self.bit()
58    }
59    #[doc = r" Returns `true` if the bit is set (1)"]
60    #[inline]
61    pub fn bit_is_set(&self) -> bool {
62        self.bit()
63    }
64    #[doc = r" Value of the field as raw bits"]
65    #[inline]
66    pub fn bit(&self) -> bool {
67        match *self {
68            MODER::ENCRYPTION => false,
69            MODER::DECRYPTION => true,
70        }
71    }
72    #[allow(missing_docs)]
73    #[doc(hidden)]
74    #[inline]
75    pub fn _from(value: bool) -> MODER {
76        match value {
77            false => MODER::ENCRYPTION,
78            true => MODER::DECRYPTION,
79        }
80    }
81    #[doc = "Checks if the value of the field is `ENCRYPTION`"]
82    #[inline]
83    pub fn is_encryption(&self) -> bool {
84        *self == MODER::ENCRYPTION
85    }
86    #[doc = "Checks if the value of the field is `DECRYPTION`"]
87    #[inline]
88    pub fn is_decryption(&self) -> bool {
89        *self == MODER::DECRYPTION
90    }
91}
92#[doc = "Possible values of the field `DATARATE`"]
93#[derive(Clone, Copy, Debug, PartialEq)]
94pub enum DATARATER {
95    #[doc = "In synch with 1 Mbit data rate"]
96    _1MBIT,
97    #[doc = "In synch with 2 Mbit data rate"]
98    _2MBIT,
99}
100impl DATARATER {
101    #[doc = r" Returns `true` if the bit is clear (0)"]
102    #[inline]
103    pub fn bit_is_clear(&self) -> bool {
104        !self.bit()
105    }
106    #[doc = r" Returns `true` if the bit is set (1)"]
107    #[inline]
108    pub fn bit_is_set(&self) -> bool {
109        self.bit()
110    }
111    #[doc = r" Value of the field as raw bits"]
112    #[inline]
113    pub fn bit(&self) -> bool {
114        match *self {
115            DATARATER::_1MBIT => false,
116            DATARATER::_2MBIT => true,
117        }
118    }
119    #[allow(missing_docs)]
120    #[doc(hidden)]
121    #[inline]
122    pub fn _from(value: bool) -> DATARATER {
123        match value {
124            false => DATARATER::_1MBIT,
125            true => DATARATER::_2MBIT,
126        }
127    }
128    #[doc = "Checks if the value of the field is `_1MBIT`"]
129    #[inline]
130    pub fn is_1mbit(&self) -> bool {
131        *self == DATARATER::_1MBIT
132    }
133    #[doc = "Checks if the value of the field is `_2MBIT`"]
134    #[inline]
135    pub fn is_2mbit(&self) -> bool {
136        *self == DATARATER::_2MBIT
137    }
138}
139#[doc = "Possible values of the field `LENGTH`"]
140#[derive(Clone, Copy, Debug, PartialEq)]
141pub enum LENGTHR {
142    #[doc = "Default length. Effective length of LENGTH field is 5-bit"]
143    DEFAULT,
144    #[doc = "Extended length. Effective length of LENGTH field is 8-bit"]
145    EXTENDED,
146}
147impl LENGTHR {
148    #[doc = r" Returns `true` if the bit is clear (0)"]
149    #[inline]
150    pub fn bit_is_clear(&self) -> bool {
151        !self.bit()
152    }
153    #[doc = r" Returns `true` if the bit is set (1)"]
154    #[inline]
155    pub fn bit_is_set(&self) -> bool {
156        self.bit()
157    }
158    #[doc = r" Value of the field as raw bits"]
159    #[inline]
160    pub fn bit(&self) -> bool {
161        match *self {
162            LENGTHR::DEFAULT => false,
163            LENGTHR::EXTENDED => true,
164        }
165    }
166    #[allow(missing_docs)]
167    #[doc(hidden)]
168    #[inline]
169    pub fn _from(value: bool) -> LENGTHR {
170        match value {
171            false => LENGTHR::DEFAULT,
172            true => LENGTHR::EXTENDED,
173        }
174    }
175    #[doc = "Checks if the value of the field is `DEFAULT`"]
176    #[inline]
177    pub fn is_default(&self) -> bool {
178        *self == LENGTHR::DEFAULT
179    }
180    #[doc = "Checks if the value of the field is `EXTENDED`"]
181    #[inline]
182    pub fn is_extended(&self) -> bool {
183        *self == LENGTHR::EXTENDED
184    }
185}
186#[doc = "Values that can be written to the field `MODE`"]
187pub enum MODEW {
188    #[doc = "AES CCM packet encryption mode"]
189    ENCRYPTION,
190    #[doc = "AES CCM packet decryption mode"]
191    DECRYPTION,
192}
193impl MODEW {
194    #[allow(missing_docs)]
195    #[doc(hidden)]
196    #[inline]
197    pub fn _bits(&self) -> bool {
198        match *self {
199            MODEW::ENCRYPTION => false,
200            MODEW::DECRYPTION => true,
201        }
202    }
203}
204#[doc = r" Proxy"]
205pub struct _MODEW<'a> {
206    w: &'a mut W,
207}
208impl<'a> _MODEW<'a> {
209    #[doc = r" Writes `variant` to the field"]
210    #[inline]
211    pub fn variant(self, variant: MODEW) -> &'a mut W {
212        {
213            self.bit(variant._bits())
214        }
215    }
216    #[doc = "AES CCM packet encryption mode"]
217    #[inline]
218    pub fn encryption(self) -> &'a mut W {
219        self.variant(MODEW::ENCRYPTION)
220    }
221    #[doc = "AES CCM packet decryption mode"]
222    #[inline]
223    pub fn decryption(self) -> &'a mut W {
224        self.variant(MODEW::DECRYPTION)
225    }
226    #[doc = r" Sets the field bit"]
227    pub fn set_bit(self) -> &'a mut W {
228        self.bit(true)
229    }
230    #[doc = r" Clears the field bit"]
231    pub fn clear_bit(self) -> &'a mut W {
232        self.bit(false)
233    }
234    #[doc = r" Writes raw bits to the field"]
235    #[inline]
236    pub fn bit(self, value: bool) -> &'a mut W {
237        const MASK: bool = true;
238        const OFFSET: u8 = 0;
239        self.w.bits &= !((MASK as u32) << OFFSET);
240        self.w.bits |= ((value & MASK) as u32) << OFFSET;
241        self.w
242    }
243}
244#[doc = "Values that can be written to the field `DATARATE`"]
245pub enum DATARATEW {
246    #[doc = "In synch with 1 Mbit data rate"]
247    _1MBIT,
248    #[doc = "In synch with 2 Mbit data rate"]
249    _2MBIT,
250}
251impl DATARATEW {
252    #[allow(missing_docs)]
253    #[doc(hidden)]
254    #[inline]
255    pub fn _bits(&self) -> bool {
256        match *self {
257            DATARATEW::_1MBIT => false,
258            DATARATEW::_2MBIT => true,
259        }
260    }
261}
262#[doc = r" Proxy"]
263pub struct _DATARATEW<'a> {
264    w: &'a mut W,
265}
266impl<'a> _DATARATEW<'a> {
267    #[doc = r" Writes `variant` to the field"]
268    #[inline]
269    pub fn variant(self, variant: DATARATEW) -> &'a mut W {
270        {
271            self.bit(variant._bits())
272        }
273    }
274    #[doc = "In synch with 1 Mbit data rate"]
275    #[inline]
276    pub fn _1mbit(self) -> &'a mut W {
277        self.variant(DATARATEW::_1MBIT)
278    }
279    #[doc = "In synch with 2 Mbit data rate"]
280    #[inline]
281    pub fn _2mbit(self) -> &'a mut W {
282        self.variant(DATARATEW::_2MBIT)
283    }
284    #[doc = r" Sets the field bit"]
285    pub fn set_bit(self) -> &'a mut W {
286        self.bit(true)
287    }
288    #[doc = r" Clears the field bit"]
289    pub fn clear_bit(self) -> &'a mut W {
290        self.bit(false)
291    }
292    #[doc = r" Writes raw bits to the field"]
293    #[inline]
294    pub fn bit(self, value: bool) -> &'a mut W {
295        const MASK: bool = true;
296        const OFFSET: u8 = 16;
297        self.w.bits &= !((MASK as u32) << OFFSET);
298        self.w.bits |= ((value & MASK) as u32) << OFFSET;
299        self.w
300    }
301}
302#[doc = "Values that can be written to the field `LENGTH`"]
303pub enum LENGTHW {
304    #[doc = "Default length. Effective length of LENGTH field is 5-bit"]
305    DEFAULT,
306    #[doc = "Extended length. Effective length of LENGTH field is 8-bit"]
307    EXTENDED,
308}
309impl LENGTHW {
310    #[allow(missing_docs)]
311    #[doc(hidden)]
312    #[inline]
313    pub fn _bits(&self) -> bool {
314        match *self {
315            LENGTHW::DEFAULT => false,
316            LENGTHW::EXTENDED => true,
317        }
318    }
319}
320#[doc = r" Proxy"]
321pub struct _LENGTHW<'a> {
322    w: &'a mut W,
323}
324impl<'a> _LENGTHW<'a> {
325    #[doc = r" Writes `variant` to the field"]
326    #[inline]
327    pub fn variant(self, variant: LENGTHW) -> &'a mut W {
328        {
329            self.bit(variant._bits())
330        }
331    }
332    #[doc = "Default length. Effective length of LENGTH field is 5-bit"]
333    #[inline]
334    pub fn default(self) -> &'a mut W {
335        self.variant(LENGTHW::DEFAULT)
336    }
337    #[doc = "Extended length. Effective length of LENGTH field is 8-bit"]
338    #[inline]
339    pub fn extended(self) -> &'a mut W {
340        self.variant(LENGTHW::EXTENDED)
341    }
342    #[doc = r" Sets the field bit"]
343    pub fn set_bit(self) -> &'a mut W {
344        self.bit(true)
345    }
346    #[doc = r" Clears the field bit"]
347    pub fn clear_bit(self) -> &'a mut W {
348        self.bit(false)
349    }
350    #[doc = r" Writes raw bits to the field"]
351    #[inline]
352    pub fn bit(self, value: bool) -> &'a mut W {
353        const MASK: bool = true;
354        const OFFSET: u8 = 24;
355        self.w.bits &= !((MASK as u32) << OFFSET);
356        self.w.bits |= ((value & MASK) as u32) << OFFSET;
357        self.w
358    }
359}
360impl R {
361    #[doc = r" Value of the register as raw bits"]
362    #[inline]
363    pub fn bits(&self) -> u32 {
364        self.bits
365    }
366    #[doc = "Bit 0 - The mode of operation to be used"]
367    #[inline]
368    pub fn mode(&self) -> MODER {
369        MODER::_from({
370            const MASK: bool = true;
371            const OFFSET: u8 = 0;
372            ((self.bits >> OFFSET) & MASK as u32) != 0
373        })
374    }
375    #[doc = "Bit 16 - Data rate that the CCM shall run in synch with"]
376    #[inline]
377    pub fn datarate(&self) -> DATARATER {
378        DATARATER::_from({
379            const MASK: bool = true;
380            const OFFSET: u8 = 16;
381            ((self.bits >> OFFSET) & MASK as u32) != 0
382        })
383    }
384    #[doc = "Bit 24 - Packet length configuration"]
385    #[inline]
386    pub fn length(&self) -> LENGTHR {
387        LENGTHR::_from({
388            const MASK: bool = true;
389            const OFFSET: u8 = 24;
390            ((self.bits >> OFFSET) & MASK as u32) != 0
391        })
392    }
393}
394impl W {
395    #[doc = r" Reset value of the register"]
396    #[inline]
397    pub fn reset_value() -> W {
398        W { bits: 1 }
399    }
400    #[doc = r" Writes raw bits to the register"]
401    #[inline]
402    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
403        self.bits = bits;
404        self
405    }
406    #[doc = "Bit 0 - The mode of operation to be used"]
407    #[inline]
408    pub fn mode(&mut self) -> _MODEW {
409        _MODEW { w: self }
410    }
411    #[doc = "Bit 16 - Data rate that the CCM shall run in synch with"]
412    #[inline]
413    pub fn datarate(&mut self) -> _DATARATEW {
414        _DATARATEW { w: self }
415    }
416    #[doc = "Bit 24 - Packet length configuration"]
417    #[inline]
418    pub fn length(&mut self) -> _LENGTHW {
419        _LENGTHW { w: self }
420    }
421}