nrf51_pac/power/
pofcon.rs

1#[doc = "Register `POFCON` reader"]
2pub struct R(crate::R<POFCON_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<POFCON_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<POFCON_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<POFCON_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `POFCON` writer"]
17pub struct W(crate::W<POFCON_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<POFCON_SPEC>;
20    #[inline(always)]
21    fn deref(&self) -> &Self::Target {
22        &self.0
23    }
24}
25impl core::ops::DerefMut for W {
26    #[inline(always)]
27    fn deref_mut(&mut self) -> &mut Self::Target {
28        &mut self.0
29    }
30}
31impl From<crate::W<POFCON_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<POFCON_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `POF` reader - Power failure comparator enable."]
38pub type POF_R = crate::BitReader<POF_A>;
39#[doc = "Power failure comparator enable.\n\nValue on reset: 0"]
40#[derive(Clone, Copy, Debug, PartialEq)]
41pub enum POF_A {
42    #[doc = "0: Disabled."]
43    DISABLED = 0,
44    #[doc = "1: Enabled."]
45    ENABLED = 1,
46}
47impl From<POF_A> for bool {
48    #[inline(always)]
49    fn from(variant: POF_A) -> Self {
50        variant as u8 != 0
51    }
52}
53impl POF_R {
54    #[doc = "Get enumerated values variant"]
55    #[inline(always)]
56    pub fn variant(&self) -> POF_A {
57        match self.bits {
58            false => POF_A::DISABLED,
59            true => POF_A::ENABLED,
60        }
61    }
62    #[doc = "Checks if the value of the field is `DISABLED`"]
63    #[inline(always)]
64    pub fn is_disabled(&self) -> bool {
65        *self == POF_A::DISABLED
66    }
67    #[doc = "Checks if the value of the field is `ENABLED`"]
68    #[inline(always)]
69    pub fn is_enabled(&self) -> bool {
70        *self == POF_A::ENABLED
71    }
72}
73#[doc = "Field `POF` writer - Power failure comparator enable."]
74pub type POF_W<'a, const O: u8> = crate::BitWriter<'a, u32, POFCON_SPEC, POF_A, O>;
75impl<'a, const O: u8> POF_W<'a, O> {
76    #[doc = "Disabled."]
77    #[inline(always)]
78    pub fn disabled(self) -> &'a mut W {
79        self.variant(POF_A::DISABLED)
80    }
81    #[doc = "Enabled."]
82    #[inline(always)]
83    pub fn enabled(self) -> &'a mut W {
84        self.variant(POF_A::ENABLED)
85    }
86}
87#[doc = "Field `THRESHOLD` reader - Set threshold level."]
88pub type THRESHOLD_R = crate::FieldReader<u8, THRESHOLD_A>;
89#[doc = "Set threshold level.\n\nValue on reset: 0"]
90#[derive(Clone, Copy, Debug, PartialEq)]
91#[repr(u8)]
92pub enum THRESHOLD_A {
93    #[doc = "0: Set threshold to 2.1Volts."]
94    V21 = 0,
95    #[doc = "1: Set threshold to 2.3Volts."]
96    V23 = 1,
97    #[doc = "2: Set threshold to 2.5Volts."]
98    V25 = 2,
99    #[doc = "3: Set threshold to 2.7Volts."]
100    V27 = 3,
101}
102impl From<THRESHOLD_A> for u8 {
103    #[inline(always)]
104    fn from(variant: THRESHOLD_A) -> Self {
105        variant as _
106    }
107}
108impl THRESHOLD_R {
109    #[doc = "Get enumerated values variant"]
110    #[inline(always)]
111    pub fn variant(&self) -> THRESHOLD_A {
112        match self.bits {
113            0 => THRESHOLD_A::V21,
114            1 => THRESHOLD_A::V23,
115            2 => THRESHOLD_A::V25,
116            3 => THRESHOLD_A::V27,
117            _ => unreachable!(),
118        }
119    }
120    #[doc = "Checks if the value of the field is `V21`"]
121    #[inline(always)]
122    pub fn is_v21(&self) -> bool {
123        *self == THRESHOLD_A::V21
124    }
125    #[doc = "Checks if the value of the field is `V23`"]
126    #[inline(always)]
127    pub fn is_v23(&self) -> bool {
128        *self == THRESHOLD_A::V23
129    }
130    #[doc = "Checks if the value of the field is `V25`"]
131    #[inline(always)]
132    pub fn is_v25(&self) -> bool {
133        *self == THRESHOLD_A::V25
134    }
135    #[doc = "Checks if the value of the field is `V27`"]
136    #[inline(always)]
137    pub fn is_v27(&self) -> bool {
138        *self == THRESHOLD_A::V27
139    }
140}
141#[doc = "Field `THRESHOLD` writer - Set threshold level."]
142pub type THRESHOLD_W<'a, const O: u8> =
143    crate::FieldWriterSafe<'a, u32, POFCON_SPEC, u8, THRESHOLD_A, 2, O>;
144impl<'a, const O: u8> THRESHOLD_W<'a, O> {
145    #[doc = "Set threshold to 2.1Volts."]
146    #[inline(always)]
147    pub fn v21(self) -> &'a mut W {
148        self.variant(THRESHOLD_A::V21)
149    }
150    #[doc = "Set threshold to 2.3Volts."]
151    #[inline(always)]
152    pub fn v23(self) -> &'a mut W {
153        self.variant(THRESHOLD_A::V23)
154    }
155    #[doc = "Set threshold to 2.5Volts."]
156    #[inline(always)]
157    pub fn v25(self) -> &'a mut W {
158        self.variant(THRESHOLD_A::V25)
159    }
160    #[doc = "Set threshold to 2.7Volts."]
161    #[inline(always)]
162    pub fn v27(self) -> &'a mut W {
163        self.variant(THRESHOLD_A::V27)
164    }
165}
166impl R {
167    #[doc = "Bit 0 - Power failure comparator enable."]
168    #[inline(always)]
169    pub fn pof(&self) -> POF_R {
170        POF_R::new((self.bits & 1) != 0)
171    }
172    #[doc = "Bits 1:2 - Set threshold level."]
173    #[inline(always)]
174    pub fn threshold(&self) -> THRESHOLD_R {
175        THRESHOLD_R::new(((self.bits >> 1) & 3) as u8)
176    }
177}
178impl W {
179    #[doc = "Bit 0 - Power failure comparator enable."]
180    #[inline(always)]
181    pub fn pof(&mut self) -> POF_W<0> {
182        POF_W::new(self)
183    }
184    #[doc = "Bits 1:2 - Set threshold level."]
185    #[inline(always)]
186    pub fn threshold(&mut self) -> THRESHOLD_W<1> {
187        THRESHOLD_W::new(self)
188    }
189    #[doc = "Writes raw bits to the register."]
190    #[inline(always)]
191    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
192        self.0.bits(bits);
193        self
194    }
195}
196#[doc = "Power failure configuration.\n\nThis register you can [`read`](crate::generic::Reg::read), [`write_with_zero`](crate::generic::Reg::write_with_zero), [`reset`](crate::generic::Reg::reset), [`write`](crate::generic::Reg::write), [`modify`](crate::generic::Reg::modify). See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [pofcon](index.html) module"]
197pub struct POFCON_SPEC;
198impl crate::RegisterSpec for POFCON_SPEC {
199    type Ux = u32;
200}
201#[doc = "`read()` method returns [pofcon::R](R) reader structure"]
202impl crate::Readable for POFCON_SPEC {
203    type Reader = R;
204}
205#[doc = "`write(|w| ..)` method takes [pofcon::W](W) writer structure"]
206impl crate::Writable for POFCON_SPEC {
207    type Writer = W;
208}
209#[doc = "`reset()` method sets POFCON to value 0"]
210impl crate::Resettable for POFCON_SPEC {
211    #[inline(always)]
212    fn reset_value() -> Self::Ux {
213        0
214    }
215}