nrf52/lpcomp/hyst/
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::HYST {
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 `HYST`"]
46#[derive(Clone, Copy, Debug, PartialEq)]
47pub enum HYSTR {
48    #[doc = "Comparator hysteresis disabled"]
49    NOHYST,
50    #[doc = "Comparator hysteresis disabled (typ. 50 mV)"]
51    HYST50MV,
52}
53impl HYSTR {
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            HYSTR::NOHYST => false,
69            HYSTR::HYST50MV => true,
70        }
71    }
72    #[allow(missing_docs)]
73    #[doc(hidden)]
74    #[inline]
75    pub fn _from(value: bool) -> HYSTR {
76        match value {
77            false => HYSTR::NOHYST,
78            true => HYSTR::HYST50MV,
79        }
80    }
81    #[doc = "Checks if the value of the field is `NOHYST`"]
82    #[inline]
83    pub fn is_no_hyst(&self) -> bool {
84        *self == HYSTR::NOHYST
85    }
86    #[doc = "Checks if the value of the field is `HYST50MV`"]
87    #[inline]
88    pub fn is_hyst50m_v(&self) -> bool {
89        *self == HYSTR::HYST50MV
90    }
91}
92#[doc = "Values that can be written to the field `HYST`"]
93pub enum HYSTW {
94    #[doc = "Comparator hysteresis disabled"]
95    NOHYST,
96    #[doc = "Comparator hysteresis disabled (typ. 50 mV)"]
97    HYST50MV,
98}
99impl HYSTW {
100    #[allow(missing_docs)]
101    #[doc(hidden)]
102    #[inline]
103    pub fn _bits(&self) -> bool {
104        match *self {
105            HYSTW::NOHYST => false,
106            HYSTW::HYST50MV => true,
107        }
108    }
109}
110#[doc = r" Proxy"]
111pub struct _HYSTW<'a> {
112    w: &'a mut W,
113}
114impl<'a> _HYSTW<'a> {
115    #[doc = r" Writes `variant` to the field"]
116    #[inline]
117    pub fn variant(self, variant: HYSTW) -> &'a mut W {
118        {
119            self.bit(variant._bits())
120        }
121    }
122    #[doc = "Comparator hysteresis disabled"]
123    #[inline]
124    pub fn no_hyst(self) -> &'a mut W {
125        self.variant(HYSTW::NOHYST)
126    }
127    #[doc = "Comparator hysteresis disabled (typ. 50 mV)"]
128    #[inline]
129    pub fn hyst50m_v(self) -> &'a mut W {
130        self.variant(HYSTW::HYST50MV)
131    }
132    #[doc = r" Sets the field bit"]
133    pub fn set_bit(self) -> &'a mut W {
134        self.bit(true)
135    }
136    #[doc = r" Clears the field bit"]
137    pub fn clear_bit(self) -> &'a mut W {
138        self.bit(false)
139    }
140    #[doc = r" Writes raw bits to the field"]
141    #[inline]
142    pub fn bit(self, value: bool) -> &'a mut W {
143        const MASK: bool = true;
144        const OFFSET: u8 = 0;
145        self.w.bits &= !((MASK as u32) << OFFSET);
146        self.w.bits |= ((value & MASK) as u32) << OFFSET;
147        self.w
148    }
149}
150impl R {
151    #[doc = r" Value of the register as raw bits"]
152    #[inline]
153    pub fn bits(&self) -> u32 {
154        self.bits
155    }
156    #[doc = "Bit 0 - Comparator hysteresis enable"]
157    #[inline]
158    pub fn hyst(&self) -> HYSTR {
159        HYSTR::_from({
160            const MASK: bool = true;
161            const OFFSET: u8 = 0;
162            ((self.bits >> OFFSET) & MASK as u32) != 0
163        })
164    }
165}
166impl W {
167    #[doc = r" Reset value of the register"]
168    #[inline]
169    pub fn reset_value() -> W {
170        W { bits: 0 }
171    }
172    #[doc = r" Writes raw bits to the register"]
173    #[inline]
174    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
175        self.bits = bits;
176        self
177    }
178    #[doc = "Bit 0 - Comparator hysteresis enable"]
179    #[inline]
180    pub fn hyst(&mut self) -> _HYSTW {
181        _HYSTW { w: self }
182    }
183}