gd32e2 0.9.1

Device support crate for GD32E2 devices
Documentation
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
#[doc = "Register `CS` reader"]
pub type R = crate::R<CsSpec>;
#[doc = "Register `CS` writer"]
pub type W = crate::W<CsSpec>;
#[doc = "Comparator enable\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Cmpen {
    #[doc = "0: Comparator disabled"]
    Disabled = 0,
    #[doc = "1: Comparator enabled"]
    Enabled = 1,
}
impl From<Cmpen> for bool {
    #[inline(always)]
    fn from(variant: Cmpen) -> Self {
        variant as u8 != 0
    }
}
#[doc = "Field `CMPEN` reader - Comparator enable"]
pub type CmpenR = crate::BitReader<Cmpen>;
impl CmpenR {
    #[doc = "Get enumerated values variant"]
    #[inline(always)]
    pub const fn variant(&self) -> Cmpen {
        match self.bits {
            false => Cmpen::Disabled,
            true => Cmpen::Enabled,
        }
    }
    #[doc = "Comparator disabled"]
    #[inline(always)]
    pub fn is_disabled(&self) -> bool {
        *self == Cmpen::Disabled
    }
    #[doc = "Comparator enabled"]
    #[inline(always)]
    pub fn is_enabled(&self) -> bool {
        *self == Cmpen::Enabled
    }
}
#[doc = "Field `CMPEN` writer - Comparator enable"]
pub type CmpenW<'a, REG> = crate::BitWriter<'a, REG, Cmpen>;
impl<'a, REG> CmpenW<'a, REG>
where
    REG: crate::Writable + crate::RegisterSpec,
{
    #[doc = "Comparator disabled"]
    #[inline(always)]
    pub fn disabled(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpen::Disabled)
    }
    #[doc = "Comparator enabled"]
    #[inline(always)]
    pub fn enabled(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpen::Enabled)
    }
}
#[doc = "Comparator switch\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Cmpsw {
    #[doc = "0: Switch open"]
    Open = 0,
    #[doc = "1: Switch closed"]
    Closed = 1,
}
impl From<Cmpsw> for bool {
    #[inline(always)]
    fn from(variant: Cmpsw) -> Self {
        variant as u8 != 0
    }
}
#[doc = "Field `CMPSW` reader - Comparator switch"]
pub type CmpswR = crate::BitReader<Cmpsw>;
impl CmpswR {
    #[doc = "Get enumerated values variant"]
    #[inline(always)]
    pub const fn variant(&self) -> Cmpsw {
        match self.bits {
            false => Cmpsw::Open,
            true => Cmpsw::Closed,
        }
    }
    #[doc = "Switch open"]
    #[inline(always)]
    pub fn is_open(&self) -> bool {
        *self == Cmpsw::Open
    }
    #[doc = "Switch closed"]
    #[inline(always)]
    pub fn is_closed(&self) -> bool {
        *self == Cmpsw::Closed
    }
}
#[doc = "Field `CMPSW` writer - Comparator switch"]
pub type CmpswW<'a, REG> = crate::BitWriter<'a, REG, Cmpsw>;
impl<'a, REG> CmpswW<'a, REG>
where
    REG: crate::Writable + crate::RegisterSpec,
{
    #[doc = "Switch open"]
    #[inline(always)]
    pub fn open(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpsw::Open)
    }
    #[doc = "Switch closed"]
    #[inline(always)]
    pub fn closed(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpsw::Closed)
    }
}
#[doc = "Comparator mode\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum Cmpm {
    #[doc = "0: High speed / full power"]
    HighSpeed = 0,
    #[doc = "1: Medium speed / medium power"]
    MediumSpeed = 1,
    #[doc = "2: Low speed / low power"]
    LowSpeed = 2,
    #[doc = "3: Very-low speed / ultra-low power"]
    VeryLowSpeed = 3,
}
impl From<Cmpm> for u8 {
    #[inline(always)]
    fn from(variant: Cmpm) -> Self {
        variant as _
    }
}
impl crate::FieldSpec for Cmpm {
    type Ux = u8;
}
#[doc = "Field `CMPM` reader - Comparator mode"]
pub type CmpmR = crate::FieldReader<Cmpm>;
impl CmpmR {
    #[doc = "Get enumerated values variant"]
    #[inline(always)]
    pub const fn variant(&self) -> Cmpm {
        match self.bits {
            0 => Cmpm::HighSpeed,
            1 => Cmpm::MediumSpeed,
            2 => Cmpm::LowSpeed,
            3 => Cmpm::VeryLowSpeed,
            _ => unreachable!(),
        }
    }
    #[doc = "High speed / full power"]
    #[inline(always)]
    pub fn is_high_speed(&self) -> bool {
        *self == Cmpm::HighSpeed
    }
    #[doc = "Medium speed / medium power"]
    #[inline(always)]
    pub fn is_medium_speed(&self) -> bool {
        *self == Cmpm::MediumSpeed
    }
    #[doc = "Low speed / low power"]
    #[inline(always)]
    pub fn is_low_speed(&self) -> bool {
        *self == Cmpm::LowSpeed
    }
    #[doc = "Very-low speed / ultra-low power"]
    #[inline(always)]
    pub fn is_very_low_speed(&self) -> bool {
        *self == Cmpm::VeryLowSpeed
    }
}
#[doc = "Field `CMPM` writer - Comparator mode"]
pub type CmpmW<'a, REG> = crate::FieldWriterSafe<'a, REG, 2, Cmpm>;
impl<'a, REG> CmpmW<'a, REG>
where
    REG: crate::Writable + crate::RegisterSpec,
    REG::Ux: From<u8>,
{
    #[doc = "High speed / full power"]
    #[inline(always)]
    pub fn high_speed(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpm::HighSpeed)
    }
    #[doc = "Medium speed / medium power"]
    #[inline(always)]
    pub fn medium_speed(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpm::MediumSpeed)
    }
    #[doc = "Low speed / low power"]
    #[inline(always)]
    pub fn low_speed(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpm::LowSpeed)
    }
    #[doc = "Very-low speed / ultra-low power"]
    #[inline(always)]
    pub fn very_low_speed(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpm::VeryLowSpeed)
    }
}
#[doc = "Comparator input selection\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum Cmpmsel {
    #[doc = "0: 1/4 of VRefint"]
    OneQuarterVref = 0,
    #[doc = "1: 1/2 of VRefint"]
    OneHalfVref = 1,
    #[doc = "2: 3/4 of VRefint"]
    ThreeQuarterVref = 2,
    #[doc = "3: VRefint"]
    Vref = 3,
    #[doc = "4: PA4 (DAC0"]
    Pa4 = 4,
    #[doc = "5: PA5"]
    Pa5 = 5,
    #[doc = "6: PA0"]
    Pa0 = 6,
}
impl From<Cmpmsel> for u8 {
    #[inline(always)]
    fn from(variant: Cmpmsel) -> Self {
        variant as _
    }
}
impl crate::FieldSpec for Cmpmsel {
    type Ux = u8;
}
#[doc = "Field `CMPMSEL` reader - Comparator input selection"]
pub type CmpmselR = crate::FieldReader<Cmpmsel>;
impl CmpmselR {
    #[doc = "Get enumerated values variant"]
    #[inline(always)]
    pub const fn variant(&self) -> Option<Cmpmsel> {
        match self.bits {
            0 => Some(Cmpmsel::OneQuarterVref),
            1 => Some(Cmpmsel::OneHalfVref),
            2 => Some(Cmpmsel::ThreeQuarterVref),
            3 => Some(Cmpmsel::Vref),
            4 => Some(Cmpmsel::Pa4),
            5 => Some(Cmpmsel::Pa5),
            6 => Some(Cmpmsel::Pa0),
            _ => None,
        }
    }
    #[doc = "1/4 of VRefint"]
    #[inline(always)]
    pub fn is_one_quarter_vref(&self) -> bool {
        *self == Cmpmsel::OneQuarterVref
    }
    #[doc = "1/2 of VRefint"]
    #[inline(always)]
    pub fn is_one_half_vref(&self) -> bool {
        *self == Cmpmsel::OneHalfVref
    }
    #[doc = "3/4 of VRefint"]
    #[inline(always)]
    pub fn is_three_quarter_vref(&self) -> bool {
        *self == Cmpmsel::ThreeQuarterVref
    }
    #[doc = "VRefint"]
    #[inline(always)]
    pub fn is_vref(&self) -> bool {
        *self == Cmpmsel::Vref
    }
    #[doc = "PA4 (DAC0"]
    #[inline(always)]
    pub fn is_pa4(&self) -> bool {
        *self == Cmpmsel::Pa4
    }
    #[doc = "PA5"]
    #[inline(always)]
    pub fn is_pa5(&self) -> bool {
        *self == Cmpmsel::Pa5
    }
    #[doc = "PA0"]
    #[inline(always)]
    pub fn is_pa0(&self) -> bool {
        *self == Cmpmsel::Pa0
    }
}
#[doc = "Field `CMPMSEL` writer - Comparator input selection"]
pub type CmpmselW<'a, REG> = crate::FieldWriter<'a, REG, 3, Cmpmsel>;
impl<'a, REG> CmpmselW<'a, REG>
where
    REG: crate::Writable + crate::RegisterSpec,
    REG::Ux: From<u8>,
{
    #[doc = "1/4 of VRefint"]
    #[inline(always)]
    pub fn one_quarter_vref(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpmsel::OneQuarterVref)
    }
    #[doc = "1/2 of VRefint"]
    #[inline(always)]
    pub fn one_half_vref(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpmsel::OneHalfVref)
    }
    #[doc = "3/4 of VRefint"]
    #[inline(always)]
    pub fn three_quarter_vref(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpmsel::ThreeQuarterVref)
    }
    #[doc = "VRefint"]
    #[inline(always)]
    pub fn vref(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpmsel::Vref)
    }
    #[doc = "PA4 (DAC0"]
    #[inline(always)]
    pub fn pa4(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpmsel::Pa4)
    }
    #[doc = "PA5"]
    #[inline(always)]
    pub fn pa5(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpmsel::Pa5)
    }
    #[doc = "PA0"]
    #[inline(always)]
    pub fn pa0(self) -> &'a mut crate::W<REG> {
        self.variant(Cmpmsel::Pa0)
    }
}
#[doc = "Comparator output selection\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum Cmposel {
    #[doc = "0: No selection"]
    NoSelection = 0,
    #[doc = "1: Timer 0 break input"]
    Timer0breakInput = 1,
    #[doc = "2: Timer 0 Input capture 0"]
    Timer0inputCapture0 = 2,
    #[doc = "3: Timer 0 OCPRE_CLR input"]
    Timer0ocpreclearInput = 3,
    #[doc = "4: Timer 1 input capture 3"]
    Timer1inputCapture3 = 4,
    #[doc = "5: Timer 1 OCPRE_CLR input"]
    Timer1ocpreclearInput = 5,
    #[doc = "6: Timer 2 input capture 0"]
    Timer2inputCapture0 = 6,
    #[doc = "7: Timer 2 OCPRE_CLR input"]
    Timer2ocpreclearInput = 7,
}
impl From<Cmposel> for u8 {
    #[inline(always)]
    fn from(variant: Cmposel) -> Self {
        variant as _
    }
}
impl crate::FieldSpec for Cmposel {
    type Ux = u8;
}
#[doc = "Field `CMPOSEL` reader - Comparator output selection"]
pub type CmposelR = crate::FieldReader<Cmposel>;
impl CmposelR {
    #[doc = "Get enumerated values variant"]
    #[inline(always)]
    pub const fn variant(&self) -> Cmposel {
        match self.bits {
            0 => Cmposel::NoSelection,
            1 => Cmposel::Timer0breakInput,
            2 => Cmposel::Timer0inputCapture0,
            3 => Cmposel::Timer0ocpreclearInput,
            4 => Cmposel::Timer1inputCapture3,
            5 => Cmposel::Timer1ocpreclearInput,
            6 => Cmposel::Timer2inputCapture0,
            7 => Cmposel::Timer2ocpreclearInput,
            _ => unreachable!(),
        }
    }
    #[doc = "No selection"]
    #[inline(always)]
    pub fn is_no_selection(&self) -> bool {
        *self == Cmposel::NoSelection
    }
    #[doc = "Timer 0 break input"]
    #[inline(always)]
    pub fn is_timer0break_input(&self) -> bool {
        *self == Cmposel::Timer0breakInput
    }
    #[doc = "Timer 0 Input capture 0"]
    #[inline(always)]
    pub fn is_timer0input_capture0(&self) -> bool {
        *self == Cmposel::Timer0inputCapture0
    }
    #[doc = "Timer 0 OCPRE_CLR input"]
    #[inline(always)]
    pub fn is_timer0ocpreclear_input(&self) -> bool {
        *self == Cmposel::Timer0ocpreclearInput
    }
    #[doc = "Timer 1 input capture 3"]
    #[inline(always)]
    pub fn is_timer1input_capture3(&self) -> bool {
        *self == Cmposel::Timer1inputCapture3
    }
    #[doc = "Timer 1 OCPRE_CLR input"]
    #[inline(always)]
    pub fn is_timer1ocpreclear_input(&self) -> bool {
        *self == Cmposel::Timer1ocpreclearInput
    }
    #[doc = "Timer 2 input capture 0"]
    #[inline(always)]
    pub fn is_timer2input_capture0(&self) -> bool {
        *self == Cmposel::Timer2inputCapture0
    }
    #[doc = "Timer 2 OCPRE_CLR input"]
    #[inline(always)]
    pub fn is_timer2ocpreclear_input(&self) -> bool {
        *self == Cmposel::Timer2ocpreclearInput
    }
}
#[doc = "Field `CMPOSEL` writer - Comparator output selection"]
pub type CmposelW<'a, REG> = crate::FieldWriterSafe<'a, REG, 3, Cmposel>;
impl<'a, REG> CmposelW<'a, REG>
where
    REG: crate::Writable + crate::RegisterSpec,
    REG::Ux: From<u8>,
{
    #[doc = "No selection"]
    #[inline(always)]
    pub fn no_selection(self) -> &'a mut crate::W<REG> {
        self.variant(Cmposel::NoSelection)
    }
    #[doc = "Timer 0 break input"]
    #[inline(always)]
    pub fn timer0break_input(self) -> &'a mut crate::W<REG> {
        self.variant(Cmposel::Timer0breakInput)
    }
    #[doc = "Timer 0 Input capture 0"]
    #[inline(always)]
    pub fn timer0input_capture0(self) -> &'a mut crate::W<REG> {
        self.variant(Cmposel::Timer0inputCapture0)
    }
    #[doc = "Timer 0 OCPRE_CLR input"]
    #[inline(always)]
    pub fn timer0ocpreclear_input(self) -> &'a mut crate::W<REG> {
        self.variant(Cmposel::Timer0ocpreclearInput)
    }
    #[doc = "Timer 1 input capture 3"]
    #[inline(always)]
    pub fn timer1input_capture3(self) -> &'a mut crate::W<REG> {
        self.variant(Cmposel::Timer1inputCapture3)
    }
    #[doc = "Timer 1 OCPRE_CLR input"]
    #[inline(always)]
    pub fn timer1ocpreclear_input(self) -> &'a mut crate::W<REG> {
        self.variant(Cmposel::Timer1ocpreclearInput)
    }
    #[doc = "Timer 2 input capture 0"]
    #[inline(always)]
    pub fn timer2input_capture0(self) -> &'a mut crate::W<REG> {
        self.variant(Cmposel::Timer2inputCapture0)
    }
    #[doc = "Timer 2 OCPRE_CLR input"]
    #[inline(always)]
    pub fn timer2ocpreclear_input(self) -> &'a mut crate::W<REG> {
        self.variant(Cmposel::Timer2ocpreclearInput)
    }
}
#[doc = "Polarity of comparator output\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Cmppl {
    #[doc = "0: Output is not inverted"]
    NotInverted = 0,
    #[doc = "1: Output is inverted"]
    Inverted = 1,
}
impl From<Cmppl> for bool {
    #[inline(always)]
    fn from(variant: Cmppl) -> Self {
        variant as u8 != 0
    }
}
#[doc = "Field `CMPPL` reader - Polarity of comparator output"]
pub type CmpplR = crate::BitReader<Cmppl>;
impl CmpplR {
    #[doc = "Get enumerated values variant"]
    #[inline(always)]
    pub const fn variant(&self) -> Cmppl {
        match self.bits {
            false => Cmppl::NotInverted,
            true => Cmppl::Inverted,
        }
    }
    #[doc = "Output is not inverted"]
    #[inline(always)]
    pub fn is_not_inverted(&self) -> bool {
        *self == Cmppl::NotInverted
    }
    #[doc = "Output is inverted"]
    #[inline(always)]
    pub fn is_inverted(&self) -> bool {
        *self == Cmppl::Inverted
    }
}
#[doc = "Field `CMPPL` writer - Polarity of comparator output"]
pub type CmpplW<'a, REG> = crate::BitWriter<'a, REG, Cmppl>;
impl<'a, REG> CmpplW<'a, REG>
where
    REG: crate::Writable + crate::RegisterSpec,
{
    #[doc = "Output is not inverted"]
    #[inline(always)]
    pub fn not_inverted(self) -> &'a mut crate::W<REG> {
        self.variant(Cmppl::NotInverted)
    }
    #[doc = "Output is inverted"]
    #[inline(always)]
    pub fn inverted(self) -> &'a mut crate::W<REG> {
        self.variant(Cmppl::Inverted)
    }
}
#[doc = "Comparator hysteresis\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum Cmphst {
    #[doc = "0: No hysteresis"]
    NoHysteresis = 0,
    #[doc = "1: Low hysteresis"]
    LowHysteresis = 1,
    #[doc = "2: Medium hysteresis"]
    MediumHysteresis = 2,
    #[doc = "3: High hysteresis"]
    HighHysteresis = 3,
}
impl From<Cmphst> for u8 {
    #[inline(always)]
    fn from(variant: Cmphst) -> Self {
        variant as _
    }
}
impl crate::FieldSpec for Cmphst {
    type Ux = u8;
}
#[doc = "Field `CMPHST` reader - Comparator hysteresis"]
pub type CmphstR = crate::FieldReader<Cmphst>;
impl CmphstR {
    #[doc = "Get enumerated values variant"]
    #[inline(always)]
    pub const fn variant(&self) -> Cmphst {
        match self.bits {
            0 => Cmphst::NoHysteresis,
            1 => Cmphst::LowHysteresis,
            2 => Cmphst::MediumHysteresis,
            3 => Cmphst::HighHysteresis,
            _ => unreachable!(),
        }
    }
    #[doc = "No hysteresis"]
    #[inline(always)]
    pub fn is_no_hysteresis(&self) -> bool {
        *self == Cmphst::NoHysteresis
    }
    #[doc = "Low hysteresis"]
    #[inline(always)]
    pub fn is_low_hysteresis(&self) -> bool {
        *self == Cmphst::LowHysteresis
    }
    #[doc = "Medium hysteresis"]
    #[inline(always)]
    pub fn is_medium_hysteresis(&self) -> bool {
        *self == Cmphst::MediumHysteresis
    }
    #[doc = "High hysteresis"]
    #[inline(always)]
    pub fn is_high_hysteresis(&self) -> bool {
        *self == Cmphst::HighHysteresis
    }
}
#[doc = "Field `CMPHST` writer - Comparator hysteresis"]
pub type CmphstW<'a, REG> = crate::FieldWriterSafe<'a, REG, 2, Cmphst>;
impl<'a, REG> CmphstW<'a, REG>
where
    REG: crate::Writable + crate::RegisterSpec,
    REG::Ux: From<u8>,
{
    #[doc = "No hysteresis"]
    #[inline(always)]
    pub fn no_hysteresis(self) -> &'a mut crate::W<REG> {
        self.variant(Cmphst::NoHysteresis)
    }
    #[doc = "Low hysteresis"]
    #[inline(always)]
    pub fn low_hysteresis(self) -> &'a mut crate::W<REG> {
        self.variant(Cmphst::LowHysteresis)
    }
    #[doc = "Medium hysteresis"]
    #[inline(always)]
    pub fn medium_hysteresis(self) -> &'a mut crate::W<REG> {
        self.variant(Cmphst::MediumHysteresis)
    }
    #[doc = "High hysteresis"]
    #[inline(always)]
    pub fn high_hysteresis(self) -> &'a mut crate::W<REG> {
        self.variant(Cmphst::HighHysteresis)
    }
}
#[doc = "Comparator 0 output\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Cmpo {
    #[doc = "0: Non-inverting input below inverting input"]
    Low = 0,
    #[doc = "1: Non-inverting input above inverting input"]
    High = 1,
}
impl From<Cmpo> for bool {
    #[inline(always)]
    fn from(variant: Cmpo) -> Self {
        variant as u8 != 0
    }
}
#[doc = "Field `CMPO` reader - Comparator 0 output"]
pub type CmpoR = crate::BitReader<Cmpo>;
impl CmpoR {
    #[doc = "Get enumerated values variant"]
    #[inline(always)]
    pub const fn variant(&self) -> Cmpo {
        match self.bits {
            false => Cmpo::Low,
            true => Cmpo::High,
        }
    }
    #[doc = "Non-inverting input below inverting input"]
    #[inline(always)]
    pub fn is_low(&self) -> bool {
        *self == Cmpo::Low
    }
    #[doc = "Non-inverting input above inverting input"]
    #[inline(always)]
    pub fn is_high(&self) -> bool {
        *self == Cmpo::High
    }
}
#[doc = "Comparator 0 lock\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Cmplk {
    #[doc = "0: Control bits are read-write"]
    ReadWrite = 0,
    #[doc = "1: Control bits are read-only"]
    ReadOnly = 1,
}
impl From<Cmplk> for bool {
    #[inline(always)]
    fn from(variant: Cmplk) -> Self {
        variant as u8 != 0
    }
}
#[doc = "Field `CMPLK` reader - Comparator 0 lock"]
pub type CmplkR = crate::BitReader<Cmplk>;
impl CmplkR {
    #[doc = "Get enumerated values variant"]
    #[inline(always)]
    pub const fn variant(&self) -> Cmplk {
        match self.bits {
            false => Cmplk::ReadWrite,
            true => Cmplk::ReadOnly,
        }
    }
    #[doc = "Control bits are read-write"]
    #[inline(always)]
    pub fn is_read_write(&self) -> bool {
        *self == Cmplk::ReadWrite
    }
    #[doc = "Control bits are read-only"]
    #[inline(always)]
    pub fn is_read_only(&self) -> bool {
        *self == Cmplk::ReadOnly
    }
}
#[doc = "Field `CMPLK` writer - Comparator 0 lock"]
pub type CmplkW<'a, REG> = crate::BitWriter<'a, REG, Cmplk>;
impl<'a, REG> CmplkW<'a, REG>
where
    REG: crate::Writable + crate::RegisterSpec,
{
    #[doc = "Control bits are read-write"]
    #[inline(always)]
    pub fn read_write(self) -> &'a mut crate::W<REG> {
        self.variant(Cmplk::ReadWrite)
    }
    #[doc = "Control bits are read-only"]
    #[inline(always)]
    pub fn read_only(self) -> &'a mut crate::W<REG> {
        self.variant(Cmplk::ReadOnly)
    }
}
impl R {
    #[doc = "Bit 0 - Comparator enable"]
    #[inline(always)]
    pub fn cmpen(&self) -> CmpenR {
        CmpenR::new((self.bits & 1) != 0)
    }
    #[doc = "Bit 1 - Comparator switch"]
    #[inline(always)]
    pub fn cmpsw(&self) -> CmpswR {
        CmpswR::new(((self.bits >> 1) & 1) != 0)
    }
    #[doc = "Bits 2:3 - Comparator mode"]
    #[inline(always)]
    pub fn cmpm(&self) -> CmpmR {
        CmpmR::new(((self.bits >> 2) & 3) as u8)
    }
    #[doc = "Bits 4:6 - Comparator input selection"]
    #[inline(always)]
    pub fn cmpmsel(&self) -> CmpmselR {
        CmpmselR::new(((self.bits >> 4) & 7) as u8)
    }
    #[doc = "Bits 8:10 - Comparator output selection"]
    #[inline(always)]
    pub fn cmposel(&self) -> CmposelR {
        CmposelR::new(((self.bits >> 8) & 7) as u8)
    }
    #[doc = "Bit 11 - Polarity of comparator output"]
    #[inline(always)]
    pub fn cmppl(&self) -> CmpplR {
        CmpplR::new(((self.bits >> 11) & 1) != 0)
    }
    #[doc = "Bits 12:13 - Comparator hysteresis"]
    #[inline(always)]
    pub fn cmphst(&self) -> CmphstR {
        CmphstR::new(((self.bits >> 12) & 3) as u8)
    }
    #[doc = "Bit 14 - Comparator 0 output"]
    #[inline(always)]
    pub fn cmpo(&self) -> CmpoR {
        CmpoR::new(((self.bits >> 14) & 1) != 0)
    }
    #[doc = "Bit 15 - Comparator 0 lock"]
    #[inline(always)]
    pub fn cmplk(&self) -> CmplkR {
        CmplkR::new(((self.bits >> 15) & 1) != 0)
    }
}
impl W {
    #[doc = "Bit 0 - Comparator enable"]
    #[inline(always)]
    #[must_use]
    pub fn cmpen(&mut self) -> CmpenW<CsSpec> {
        CmpenW::new(self, 0)
    }
    #[doc = "Bit 1 - Comparator switch"]
    #[inline(always)]
    #[must_use]
    pub fn cmpsw(&mut self) -> CmpswW<CsSpec> {
        CmpswW::new(self, 1)
    }
    #[doc = "Bits 2:3 - Comparator mode"]
    #[inline(always)]
    #[must_use]
    pub fn cmpm(&mut self) -> CmpmW<CsSpec> {
        CmpmW::new(self, 2)
    }
    #[doc = "Bits 4:6 - Comparator input selection"]
    #[inline(always)]
    #[must_use]
    pub fn cmpmsel(&mut self) -> CmpmselW<CsSpec> {
        CmpmselW::new(self, 4)
    }
    #[doc = "Bits 8:10 - Comparator output selection"]
    #[inline(always)]
    #[must_use]
    pub fn cmposel(&mut self) -> CmposelW<CsSpec> {
        CmposelW::new(self, 8)
    }
    #[doc = "Bit 11 - Polarity of comparator output"]
    #[inline(always)]
    #[must_use]
    pub fn cmppl(&mut self) -> CmpplW<CsSpec> {
        CmpplW::new(self, 11)
    }
    #[doc = "Bits 12:13 - Comparator hysteresis"]
    #[inline(always)]
    #[must_use]
    pub fn cmphst(&mut self) -> CmphstW<CsSpec> {
        CmphstW::new(self, 12)
    }
    #[doc = "Bit 15 - Comparator 0 lock"]
    #[inline(always)]
    #[must_use]
    pub fn cmplk(&mut self) -> CmplkW<CsSpec> {
        CmplkW::new(self, 15)
    }
}
#[doc = "control and status register\n\nYou can [`read`](crate::generic::Reg::read) this register and get [`cs::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 [`cs::W`](W). You can also [`modify`](crate::generic::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api)."]
pub struct CsSpec;
impl crate::RegisterSpec for CsSpec {
    type Ux = u32;
}
#[doc = "`read()` method returns [`cs::R`](R) reader structure"]
impl crate::Readable for CsSpec {}
#[doc = "`write(|w| ..)` method takes [`cs::W`](W) writer structure"]
impl crate::Writable for CsSpec {
    type Safety = crate::Unsafe;
    const ZERO_TO_MODIFY_FIELDS_BITMAP: u32 = 0;
    const ONE_TO_MODIFY_FIELDS_BITMAP: u32 = 0;
}
#[doc = "`reset()` method sets CS to value 0"]
impl crate::Resettable for CsSpec {
    const RESET_VALUE: u32 = 0;
}