atsamd51j/pac/
wrctrl.rs

1#[doc = "Register `WRCTRL` reader"]
2pub type R = crate::R<WrctrlSpec>;
3#[doc = "Register `WRCTRL` writer"]
4pub type W = crate::W<WrctrlSpec>;
5#[doc = "Field `PERID` reader - Peripheral identifier"]
6pub type PeridR = crate::FieldReader<u16>;
7#[doc = "Field `PERID` writer - Peripheral identifier"]
8pub type PeridW<'a, REG> = crate::FieldWriter<'a, REG, 16, u16>;
9#[doc = "Peripheral access control key\n\nValue on reset: 0"]
10#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11#[repr(u8)]
12pub enum Keyselect {
13    #[doc = "0: No action"]
14    Off = 0,
15    #[doc = "1: Clear protection"]
16    Clr = 1,
17    #[doc = "2: Set protection"]
18    Set = 2,
19    #[doc = "3: Set and lock protection"]
20    Setlck = 3,
21}
22impl From<Keyselect> for u8 {
23    #[inline(always)]
24    fn from(variant: Keyselect) -> Self {
25        variant as _
26    }
27}
28impl crate::FieldSpec for Keyselect {
29    type Ux = u8;
30}
31impl crate::IsEnum for Keyselect {}
32#[doc = "Field `KEY` reader - Peripheral access control key"]
33pub type KeyR = crate::FieldReader<Keyselect>;
34impl KeyR {
35    #[doc = "Get enumerated values variant"]
36    #[inline(always)]
37    pub const fn variant(&self) -> Option<Keyselect> {
38        match self.bits {
39            0 => Some(Keyselect::Off),
40            1 => Some(Keyselect::Clr),
41            2 => Some(Keyselect::Set),
42            3 => Some(Keyselect::Setlck),
43            _ => None,
44        }
45    }
46    #[doc = "No action"]
47    #[inline(always)]
48    pub fn is_off(&self) -> bool {
49        *self == Keyselect::Off
50    }
51    #[doc = "Clear protection"]
52    #[inline(always)]
53    pub fn is_clr(&self) -> bool {
54        *self == Keyselect::Clr
55    }
56    #[doc = "Set protection"]
57    #[inline(always)]
58    pub fn is_set(&self) -> bool {
59        *self == Keyselect::Set
60    }
61    #[doc = "Set and lock protection"]
62    #[inline(always)]
63    pub fn is_setlck(&self) -> bool {
64        *self == Keyselect::Setlck
65    }
66}
67#[doc = "Field `KEY` writer - Peripheral access control key"]
68pub type KeyW<'a, REG> = crate::FieldWriter<'a, REG, 8, Keyselect>;
69impl<'a, REG> KeyW<'a, REG>
70where
71    REG: crate::Writable + crate::RegisterSpec,
72    REG::Ux: From<u8>,
73{
74    #[doc = "No action"]
75    #[inline(always)]
76    pub fn off(self) -> &'a mut crate::W<REG> {
77        self.variant(Keyselect::Off)
78    }
79    #[doc = "Clear protection"]
80    #[inline(always)]
81    pub fn clr(self) -> &'a mut crate::W<REG> {
82        self.variant(Keyselect::Clr)
83    }
84    #[doc = "Set protection"]
85    #[inline(always)]
86    pub fn set_(self) -> &'a mut crate::W<REG> {
87        self.variant(Keyselect::Set)
88    }
89    #[doc = "Set and lock protection"]
90    #[inline(always)]
91    pub fn setlck(self) -> &'a mut crate::W<REG> {
92        self.variant(Keyselect::Setlck)
93    }
94}
95impl R {
96    #[doc = "Bits 0:15 - Peripheral identifier"]
97    #[inline(always)]
98    pub fn perid(&self) -> PeridR {
99        PeridR::new((self.bits & 0xffff) as u16)
100    }
101    #[doc = "Bits 16:23 - Peripheral access control key"]
102    #[inline(always)]
103    pub fn key(&self) -> KeyR {
104        KeyR::new(((self.bits >> 16) & 0xff) as u8)
105    }
106}
107impl W {
108    #[doc = "Bits 0:15 - Peripheral identifier"]
109    #[inline(always)]
110    #[must_use]
111    pub fn perid(&mut self) -> PeridW<WrctrlSpec> {
112        PeridW::new(self, 0)
113    }
114    #[doc = "Bits 16:23 - Peripheral access control key"]
115    #[inline(always)]
116    #[must_use]
117    pub fn key(&mut self) -> KeyW<WrctrlSpec> {
118        KeyW::new(self, 16)
119    }
120}
121#[doc = "Write control\n\nYou can [`read`](crate::Reg::read) this register and get [`wrctrl::R`](R). You can [`reset`](crate::Reg::reset), [`write`](crate::Reg::write), [`write_with_zero`](crate::Reg::write_with_zero) this register using [`wrctrl::W`](W). You can also [`modify`](crate::Reg::modify) this register. See [API](https://docs.rs/svd2rust/#read--modify--write-api)."]
122pub struct WrctrlSpec;
123impl crate::RegisterSpec for WrctrlSpec {
124    type Ux = u32;
125}
126#[doc = "`read()` method returns [`wrctrl::R`](R) reader structure"]
127impl crate::Readable for WrctrlSpec {}
128#[doc = "`write(|w| ..)` method takes [`wrctrl::W`](W) writer structure"]
129impl crate::Writable for WrctrlSpec {
130    type Safety = crate::Unsafe;
131    const ZERO_TO_MODIFY_FIELDS_BITMAP: u32 = 0;
132    const ONE_TO_MODIFY_FIELDS_BITMAP: u32 = 0;
133}
134#[doc = "`reset()` method sets WRCTRL to value 0"]
135impl crate::Resettable for WrctrlSpec {
136    const RESET_VALUE: u32 = 0;
137}