d1_pac/audio_codec/
hmic_ctrl.rs

1#[doc = "Register `hmic_ctrl` reader"]
2pub type R = crate::R<HMIC_CTRL_SPEC>;
3#[doc = "Register `hmic_ctrl` writer"]
4pub type W = crate::W<HMIC_CTRL_SPEC>;
5#[doc = "Field `mic_det_irq_en` reader - MIC Detect Interrupt Set"]
6pub type MIC_DET_IRQ_EN_R = crate::BitReader<MIC_DET_IRQ_EN_A>;
7#[doc = "MIC Detect Interrupt Set\n\nValue on reset: 0"]
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum MIC_DET_IRQ_EN_A {
10    #[doc = "0: Disabled"]
11    DISABLED = 0,
12    #[doc = "1: Enabled"]
13    ENABLED = 1,
14}
15impl From<MIC_DET_IRQ_EN_A> for bool {
16    #[inline(always)]
17    fn from(variant: MIC_DET_IRQ_EN_A) -> Self {
18        variant as u8 != 0
19    }
20}
21impl MIC_DET_IRQ_EN_R {
22    #[doc = "Get enumerated values variant"]
23    #[inline(always)]
24    pub const fn variant(&self) -> MIC_DET_IRQ_EN_A {
25        match self.bits {
26            false => MIC_DET_IRQ_EN_A::DISABLED,
27            true => MIC_DET_IRQ_EN_A::ENABLED,
28        }
29    }
30    #[doc = "Disabled"]
31    #[inline(always)]
32    pub fn is_disabled(&self) -> bool {
33        *self == MIC_DET_IRQ_EN_A::DISABLED
34    }
35    #[doc = "Enabled"]
36    #[inline(always)]
37    pub fn is_enabled(&self) -> bool {
38        *self == MIC_DET_IRQ_EN_A::ENABLED
39    }
40}
41#[doc = "Field `mic_det_irq_en` writer - MIC Detect Interrupt Set"]
42pub type MIC_DET_IRQ_EN_W<'a, REG> = crate::BitWriter<'a, REG, MIC_DET_IRQ_EN_A>;
43impl<'a, REG> MIC_DET_IRQ_EN_W<'a, REG>
44where
45    REG: crate::Writable + crate::RegisterSpec,
46{
47    #[doc = "Disabled"]
48    #[inline(always)]
49    pub fn disabled(self) -> &'a mut crate::W<REG> {
50        self.variant(MIC_DET_IRQ_EN_A::DISABLED)
51    }
52    #[doc = "Enabled"]
53    #[inline(always)]
54    pub fn enabled(self) -> &'a mut crate::W<REG> {
55        self.variant(MIC_DET_IRQ_EN_A::ENABLED)
56    }
57}
58#[doc = "Field `jack_in_irq_en` reader - MIC Detect Interrupt Set"]
59pub type JACK_IN_IRQ_EN_R = crate::BitReader<JACK_IN_IRQ_EN_A>;
60#[doc = "MIC Detect Interrupt Set\n\nValue on reset: 0"]
61#[derive(Clone, Copy, Debug, PartialEq, Eq)]
62pub enum JACK_IN_IRQ_EN_A {
63    #[doc = "0: Disabled"]
64    DISABLED = 0,
65    #[doc = "1: Enabled"]
66    ENABLED = 1,
67}
68impl From<JACK_IN_IRQ_EN_A> for bool {
69    #[inline(always)]
70    fn from(variant: JACK_IN_IRQ_EN_A) -> Self {
71        variant as u8 != 0
72    }
73}
74impl JACK_IN_IRQ_EN_R {
75    #[doc = "Get enumerated values variant"]
76    #[inline(always)]
77    pub const fn variant(&self) -> JACK_IN_IRQ_EN_A {
78        match self.bits {
79            false => JACK_IN_IRQ_EN_A::DISABLED,
80            true => JACK_IN_IRQ_EN_A::ENABLED,
81        }
82    }
83    #[doc = "Disabled"]
84    #[inline(always)]
85    pub fn is_disabled(&self) -> bool {
86        *self == JACK_IN_IRQ_EN_A::DISABLED
87    }
88    #[doc = "Enabled"]
89    #[inline(always)]
90    pub fn is_enabled(&self) -> bool {
91        *self == JACK_IN_IRQ_EN_A::ENABLED
92    }
93}
94#[doc = "Field `jack_in_irq_en` writer - MIC Detect Interrupt Set"]
95pub type JACK_IN_IRQ_EN_W<'a, REG> = crate::BitWriter<'a, REG, JACK_IN_IRQ_EN_A>;
96impl<'a, REG> JACK_IN_IRQ_EN_W<'a, REG>
97where
98    REG: crate::Writable + crate::RegisterSpec,
99{
100    #[doc = "Disabled"]
101    #[inline(always)]
102    pub fn disabled(self) -> &'a mut crate::W<REG> {
103        self.variant(JACK_IN_IRQ_EN_A::DISABLED)
104    }
105    #[doc = "Enabled"]
106    #[inline(always)]
107    pub fn enabled(self) -> &'a mut crate::W<REG> {
108        self.variant(JACK_IN_IRQ_EN_A::ENABLED)
109    }
110}
111#[doc = "Field `jack_out_irq_en` reader - MIC Detect Interrupt Set"]
112pub type JACK_OUT_IRQ_EN_R = crate::BitReader<JACK_OUT_IRQ_EN_A>;
113#[doc = "MIC Detect Interrupt Set\n\nValue on reset: 0"]
114#[derive(Clone, Copy, Debug, PartialEq, Eq)]
115pub enum JACK_OUT_IRQ_EN_A {
116    #[doc = "0: Disabled"]
117    DISABLED = 0,
118    #[doc = "1: Enabled"]
119    ENABLED = 1,
120}
121impl From<JACK_OUT_IRQ_EN_A> for bool {
122    #[inline(always)]
123    fn from(variant: JACK_OUT_IRQ_EN_A) -> Self {
124        variant as u8 != 0
125    }
126}
127impl JACK_OUT_IRQ_EN_R {
128    #[doc = "Get enumerated values variant"]
129    #[inline(always)]
130    pub const fn variant(&self) -> JACK_OUT_IRQ_EN_A {
131        match self.bits {
132            false => JACK_OUT_IRQ_EN_A::DISABLED,
133            true => JACK_OUT_IRQ_EN_A::ENABLED,
134        }
135    }
136    #[doc = "Disabled"]
137    #[inline(always)]
138    pub fn is_disabled(&self) -> bool {
139        *self == JACK_OUT_IRQ_EN_A::DISABLED
140    }
141    #[doc = "Enabled"]
142    #[inline(always)]
143    pub fn is_enabled(&self) -> bool {
144        *self == JACK_OUT_IRQ_EN_A::ENABLED
145    }
146}
147#[doc = "Field `jack_out_irq_en` writer - MIC Detect Interrupt Set"]
148pub type JACK_OUT_IRQ_EN_W<'a, REG> = crate::BitWriter<'a, REG, JACK_OUT_IRQ_EN_A>;
149impl<'a, REG> JACK_OUT_IRQ_EN_W<'a, REG>
150where
151    REG: crate::Writable + crate::RegisterSpec,
152{
153    #[doc = "Disabled"]
154    #[inline(always)]
155    pub fn disabled(self) -> &'a mut crate::W<REG> {
156        self.variant(JACK_OUT_IRQ_EN_A::DISABLED)
157    }
158    #[doc = "Enabled"]
159    #[inline(always)]
160    pub fn enabled(self) -> &'a mut crate::W<REG> {
161        self.variant(JACK_OUT_IRQ_EN_A::ENABLED)
162    }
163}
164#[doc = "Field `mdata_threshold_debounce` reader - MDATA Threshold Debounce"]
165pub type MDATA_THRESHOLD_DEBOUNCE_R = crate::FieldReader;
166#[doc = "Field `mdata_threshold_debounce` writer - MDATA Threshold Debounce"]
167pub type MDATA_THRESHOLD_DEBOUNCE_W<'a, REG> = crate::FieldWriter<'a, REG, 3>;
168#[doc = "Field `hmic_n` reader - Debounce when earphone plug in or pull out 125 ms to 2 s"]
169pub type HMIC_N_R = crate::FieldReader;
170#[doc = "Field `hmic_n` writer - Debounce when earphone plug in or pull out 125 ms to 2 s"]
171pub type HMIC_N_W<'a, REG> = crate::FieldWriter<'a, REG, 4>;
172#[doc = "Field `hmic_m` reader - Debounce when the MIC Key down or up.\n\n(HMIC_M + 1) sample data"]
173pub type HMIC_M_R = crate::FieldReader;
174#[doc = "Field `hmic_m` writer - Debounce when the MIC Key down or up.\n\n(HMIC_M + 1) sample data"]
175pub type HMIC_M_W<'a, REG> = crate::FieldWriter<'a, REG, 4>;
176#[doc = "Field `hmic_sf` reader - HMIC Smooth Filter setting"]
177pub type HMIC_SF_R = crate::FieldReader<HMIC_SF_A>;
178#[doc = "HMIC Smooth Filter setting\n\nValue on reset: 0"]
179#[derive(Clone, Copy, Debug, PartialEq, Eq)]
180#[repr(u8)]
181pub enum HMIC_SF_A {
182    #[doc = "0: bypass"]
183    BYPASS = 0,
184    #[doc = "1: (x1+x2)/2"]
185    MEAN_2 = 1,
186    #[doc = "2: (x1+x2+x3+x4)/4"]
187    MEAN_4 = 2,
188    #[doc = "3: (x1+x2+x3+x4+x5+x6+x7+x8)/8"]
189    MEAN_8 = 3,
190}
191impl From<HMIC_SF_A> for u8 {
192    #[inline(always)]
193    fn from(variant: HMIC_SF_A) -> Self {
194        variant as _
195    }
196}
197impl crate::FieldSpec for HMIC_SF_A {
198    type Ux = u8;
199}
200impl HMIC_SF_R {
201    #[doc = "Get enumerated values variant"]
202    #[inline(always)]
203    pub const fn variant(&self) -> HMIC_SF_A {
204        match self.bits {
205            0 => HMIC_SF_A::BYPASS,
206            1 => HMIC_SF_A::MEAN_2,
207            2 => HMIC_SF_A::MEAN_4,
208            3 => HMIC_SF_A::MEAN_8,
209            _ => unreachable!(),
210        }
211    }
212    #[doc = "bypass"]
213    #[inline(always)]
214    pub fn is_bypass(&self) -> bool {
215        *self == HMIC_SF_A::BYPASS
216    }
217    #[doc = "(x1+x2)/2"]
218    #[inline(always)]
219    pub fn is_mean_2(&self) -> bool {
220        *self == HMIC_SF_A::MEAN_2
221    }
222    #[doc = "(x1+x2+x3+x4)/4"]
223    #[inline(always)]
224    pub fn is_mean_4(&self) -> bool {
225        *self == HMIC_SF_A::MEAN_4
226    }
227    #[doc = "(x1+x2+x3+x4+x5+x6+x7+x8)/8"]
228    #[inline(always)]
229    pub fn is_mean_8(&self) -> bool {
230        *self == HMIC_SF_A::MEAN_8
231    }
232}
233#[doc = "Field `hmic_sf` writer - HMIC Smooth Filter setting"]
234pub type HMIC_SF_W<'a, REG> = crate::FieldWriterSafe<'a, REG, 2, HMIC_SF_A>;
235impl<'a, REG> HMIC_SF_W<'a, REG>
236where
237    REG: crate::Writable + crate::RegisterSpec,
238    REG::Ux: From<u8>,
239{
240    #[doc = "bypass"]
241    #[inline(always)]
242    pub fn bypass(self) -> &'a mut crate::W<REG> {
243        self.variant(HMIC_SF_A::BYPASS)
244    }
245    #[doc = "(x1+x2)/2"]
246    #[inline(always)]
247    pub fn mean_2(self) -> &'a mut crate::W<REG> {
248        self.variant(HMIC_SF_A::MEAN_2)
249    }
250    #[doc = "(x1+x2+x3+x4)/4"]
251    #[inline(always)]
252    pub fn mean_4(self) -> &'a mut crate::W<REG> {
253        self.variant(HMIC_SF_A::MEAN_4)
254    }
255    #[doc = "(x1+x2+x3+x4+x5+x6+x7+x8)/8"]
256    #[inline(always)]
257    pub fn mean_8(self) -> &'a mut crate::W<REG> {
258        self.variant(HMIC_SF_A::MEAN_8)
259    }
260}
261#[doc = "Field `mdata_threshold` reader - MIC DET EN Threshold Value"]
262pub type MDATA_THRESHOLD_R = crate::FieldReader;
263#[doc = "Field `mdata_threshold` writer - MIC DET EN Threshold Value"]
264pub type MDATA_THRESHOLD_W<'a, REG> = crate::FieldWriter<'a, REG, 5>;
265#[doc = "Field `hmic_sample_select` reader - Down Sample Setting Select"]
266pub type HMIC_SAMPLE_SELECT_R = crate::FieldReader<HMIC_SAMPLE_SELECT_A>;
267#[doc = "Down Sample Setting Select\n\nValue on reset: 0"]
268#[derive(Clone, Copy, Debug, PartialEq, Eq)]
269#[repr(u8)]
270pub enum HMIC_SAMPLE_SELECT_A {
271    #[doc = "0: Down by 1, 128 Hz"]
272    BY_1 = 0,
273    #[doc = "1: Down by 2, 64 Hz"]
274    BY_2 = 1,
275    #[doc = "2: Down by 4, 32 Hz"]
276    BY_4 = 2,
277    #[doc = "3: Down by 8, 16 Hz"]
278    BY_8 = 3,
279}
280impl From<HMIC_SAMPLE_SELECT_A> for u8 {
281    #[inline(always)]
282    fn from(variant: HMIC_SAMPLE_SELECT_A) -> Self {
283        variant as _
284    }
285}
286impl crate::FieldSpec for HMIC_SAMPLE_SELECT_A {
287    type Ux = u8;
288}
289impl HMIC_SAMPLE_SELECT_R {
290    #[doc = "Get enumerated values variant"]
291    #[inline(always)]
292    pub const fn variant(&self) -> HMIC_SAMPLE_SELECT_A {
293        match self.bits {
294            0 => HMIC_SAMPLE_SELECT_A::BY_1,
295            1 => HMIC_SAMPLE_SELECT_A::BY_2,
296            2 => HMIC_SAMPLE_SELECT_A::BY_4,
297            3 => HMIC_SAMPLE_SELECT_A::BY_8,
298            _ => unreachable!(),
299        }
300    }
301    #[doc = "Down by 1, 128 Hz"]
302    #[inline(always)]
303    pub fn is_by_1(&self) -> bool {
304        *self == HMIC_SAMPLE_SELECT_A::BY_1
305    }
306    #[doc = "Down by 2, 64 Hz"]
307    #[inline(always)]
308    pub fn is_by_2(&self) -> bool {
309        *self == HMIC_SAMPLE_SELECT_A::BY_2
310    }
311    #[doc = "Down by 4, 32 Hz"]
312    #[inline(always)]
313    pub fn is_by_4(&self) -> bool {
314        *self == HMIC_SAMPLE_SELECT_A::BY_4
315    }
316    #[doc = "Down by 8, 16 Hz"]
317    #[inline(always)]
318    pub fn is_by_8(&self) -> bool {
319        *self == HMIC_SAMPLE_SELECT_A::BY_8
320    }
321}
322#[doc = "Field `hmic_sample_select` writer - Down Sample Setting Select"]
323pub type HMIC_SAMPLE_SELECT_W<'a, REG> = crate::FieldWriterSafe<'a, REG, 2, HMIC_SAMPLE_SELECT_A>;
324impl<'a, REG> HMIC_SAMPLE_SELECT_W<'a, REG>
325where
326    REG: crate::Writable + crate::RegisterSpec,
327    REG::Ux: From<u8>,
328{
329    #[doc = "Down by 1, 128 Hz"]
330    #[inline(always)]
331    pub fn by_1(self) -> &'a mut crate::W<REG> {
332        self.variant(HMIC_SAMPLE_SELECT_A::BY_1)
333    }
334    #[doc = "Down by 2, 64 Hz"]
335    #[inline(always)]
336    pub fn by_2(self) -> &'a mut crate::W<REG> {
337        self.variant(HMIC_SAMPLE_SELECT_A::BY_2)
338    }
339    #[doc = "Down by 4, 32 Hz"]
340    #[inline(always)]
341    pub fn by_4(self) -> &'a mut crate::W<REG> {
342        self.variant(HMIC_SAMPLE_SELECT_A::BY_4)
343    }
344    #[doc = "Down by 8, 16 Hz"]
345    #[inline(always)]
346    pub fn by_8(self) -> &'a mut crate::W<REG> {
347        self.variant(HMIC_SAMPLE_SELECT_A::BY_8)
348    }
349}
350impl R {
351    #[doc = "Bit 0 - MIC Detect Interrupt Set"]
352    #[inline(always)]
353    pub fn mic_det_irq_en(&self) -> MIC_DET_IRQ_EN_R {
354        MIC_DET_IRQ_EN_R::new((self.bits & 1) != 0)
355    }
356    #[doc = "Bit 1 - MIC Detect Interrupt Set"]
357    #[inline(always)]
358    pub fn jack_in_irq_en(&self) -> JACK_IN_IRQ_EN_R {
359        JACK_IN_IRQ_EN_R::new(((self.bits >> 1) & 1) != 0)
360    }
361    #[doc = "Bit 2 - MIC Detect Interrupt Set"]
362    #[inline(always)]
363    pub fn jack_out_irq_en(&self) -> JACK_OUT_IRQ_EN_R {
364        JACK_OUT_IRQ_EN_R::new(((self.bits >> 2) & 1) != 0)
365    }
366    #[doc = "Bits 3:5 - MDATA Threshold Debounce"]
367    #[inline(always)]
368    pub fn mdata_threshold_debounce(&self) -> MDATA_THRESHOLD_DEBOUNCE_R {
369        MDATA_THRESHOLD_DEBOUNCE_R::new(((self.bits >> 3) & 7) as u8)
370    }
371    #[doc = "Bits 6:9 - Debounce when earphone plug in or pull out 125 ms to 2 s"]
372    #[inline(always)]
373    pub fn hmic_n(&self) -> HMIC_N_R {
374        HMIC_N_R::new(((self.bits >> 6) & 0x0f) as u8)
375    }
376    #[doc = "Bits 10:13 - Debounce when the MIC Key down or up.\n\n(HMIC_M + 1) sample data"]
377    #[inline(always)]
378    pub fn hmic_m(&self) -> HMIC_M_R {
379        HMIC_M_R::new(((self.bits >> 10) & 0x0f) as u8)
380    }
381    #[doc = "Bits 14:15 - HMIC Smooth Filter setting"]
382    #[inline(always)]
383    pub fn hmic_sf(&self) -> HMIC_SF_R {
384        HMIC_SF_R::new(((self.bits >> 14) & 3) as u8)
385    }
386    #[doc = "Bits 16:20 - MIC DET EN Threshold Value"]
387    #[inline(always)]
388    pub fn mdata_threshold(&self) -> MDATA_THRESHOLD_R {
389        MDATA_THRESHOLD_R::new(((self.bits >> 16) & 0x1f) as u8)
390    }
391    #[doc = "Bits 21:22 - Down Sample Setting Select"]
392    #[inline(always)]
393    pub fn hmic_sample_select(&self) -> HMIC_SAMPLE_SELECT_R {
394        HMIC_SAMPLE_SELECT_R::new(((self.bits >> 21) & 3) as u8)
395    }
396}
397impl W {
398    #[doc = "Bit 0 - MIC Detect Interrupt Set"]
399    #[inline(always)]
400    #[must_use]
401    pub fn mic_det_irq_en(&mut self) -> MIC_DET_IRQ_EN_W<HMIC_CTRL_SPEC> {
402        MIC_DET_IRQ_EN_W::new(self, 0)
403    }
404    #[doc = "Bit 1 - MIC Detect Interrupt Set"]
405    #[inline(always)]
406    #[must_use]
407    pub fn jack_in_irq_en(&mut self) -> JACK_IN_IRQ_EN_W<HMIC_CTRL_SPEC> {
408        JACK_IN_IRQ_EN_W::new(self, 1)
409    }
410    #[doc = "Bit 2 - MIC Detect Interrupt Set"]
411    #[inline(always)]
412    #[must_use]
413    pub fn jack_out_irq_en(&mut self) -> JACK_OUT_IRQ_EN_W<HMIC_CTRL_SPEC> {
414        JACK_OUT_IRQ_EN_W::new(self, 2)
415    }
416    #[doc = "Bits 3:5 - MDATA Threshold Debounce"]
417    #[inline(always)]
418    #[must_use]
419    pub fn mdata_threshold_debounce(&mut self) -> MDATA_THRESHOLD_DEBOUNCE_W<HMIC_CTRL_SPEC> {
420        MDATA_THRESHOLD_DEBOUNCE_W::new(self, 3)
421    }
422    #[doc = "Bits 6:9 - Debounce when earphone plug in or pull out 125 ms to 2 s"]
423    #[inline(always)]
424    #[must_use]
425    pub fn hmic_n(&mut self) -> HMIC_N_W<HMIC_CTRL_SPEC> {
426        HMIC_N_W::new(self, 6)
427    }
428    #[doc = "Bits 10:13 - Debounce when the MIC Key down or up.\n\n(HMIC_M + 1) sample data"]
429    #[inline(always)]
430    #[must_use]
431    pub fn hmic_m(&mut self) -> HMIC_M_W<HMIC_CTRL_SPEC> {
432        HMIC_M_W::new(self, 10)
433    }
434    #[doc = "Bits 14:15 - HMIC Smooth Filter setting"]
435    #[inline(always)]
436    #[must_use]
437    pub fn hmic_sf(&mut self) -> HMIC_SF_W<HMIC_CTRL_SPEC> {
438        HMIC_SF_W::new(self, 14)
439    }
440    #[doc = "Bits 16:20 - MIC DET EN Threshold Value"]
441    #[inline(always)]
442    #[must_use]
443    pub fn mdata_threshold(&mut self) -> MDATA_THRESHOLD_W<HMIC_CTRL_SPEC> {
444        MDATA_THRESHOLD_W::new(self, 16)
445    }
446    #[doc = "Bits 21:22 - Down Sample Setting Select"]
447    #[inline(always)]
448    #[must_use]
449    pub fn hmic_sample_select(&mut self) -> HMIC_SAMPLE_SELECT_W<HMIC_CTRL_SPEC> {
450        HMIC_SAMPLE_SELECT_W::new(self, 21)
451    }
452    #[doc = r" Writes raw bits to the register."]
453    #[doc = r""]
454    #[doc = r" # Safety"]
455    #[doc = r""]
456    #[doc = r" Passing incorrect value can cause undefined behaviour. See reference manual"]
457    #[inline(always)]
458    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
459        self.bits = bits;
460        self
461    }
462}
463#[doc = "HMIC Control Register\n\nYou can [`read`](crate::generic::Reg::read) this register and get [`hmic_ctrl::R`](R).  You can [`reset`](crate::generic::Reg::reset), [`write`](crate::generic::Reg::write), [`write_with_zero`](crate::generic::Reg::write_with_zero) this register using [`hmic_ctrl::W`](W). You can also [`modify`](crate::generic::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api)."]
464pub struct HMIC_CTRL_SPEC;
465impl crate::RegisterSpec for HMIC_CTRL_SPEC {
466    type Ux = u32;
467}
468#[doc = "`read()` method returns [`hmic_ctrl::R`](R) reader structure"]
469impl crate::Readable for HMIC_CTRL_SPEC {}
470#[doc = "`write(|w| ..)` method takes [`hmic_ctrl::W`](W) writer structure"]
471impl crate::Writable for HMIC_CTRL_SPEC {
472    const ZERO_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
473    const ONE_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
474}
475#[doc = "`reset()` method sets hmic_ctrl to value 0x08"]
476impl crate::Resettable for HMIC_CTRL_SPEC {
477    const RESET_VALUE: Self::Ux = 0x08;
478}