atsamv71n21/usbhs/
usbhs_fsm.rs

1#[doc = "Register `USBHS_FSM` reader"]
2pub struct R(crate::R<USBHS_FSM_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<USBHS_FSM_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<USBHS_FSM_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<USBHS_FSM_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Dual Role Device State\n\nValue on reset: 0"]
17#[derive(Clone, Copy, Debug, PartialEq)]
18#[repr(u8)]
19pub enum DRDSTATE_A {
20    #[doc = "0: This is the start state for A-devices (when the ID pin is 0)"]
21    A_IDLESTATE = 0,
22    #[doc = "1: In this state, the A-device waits for the voltage on VBus to rise above the A-device VBus Valid threshold (4.4 V)."]
23    A_WAIT_VRISE = 1,
24    #[doc = "2: In this state, the A-device waits for the B-device to signal a connection."]
25    A_WAIT_BCON = 2,
26    #[doc = "3: In this state, the A-device that operates in Host mode is operational."]
27    A_HOST = 3,
28    #[doc = "4: The A-device operating as a host is in the Suspend mode."]
29    A_SUSPEND = 4,
30    #[doc = "5: The A-device operates as a peripheral."]
31    A_PERIPHERAL = 5,
32    #[doc = "6: In this state, the A-device waits for the voltage on VBus to drop below the A-device Session Valid threshold (1.4 V)."]
33    A_WAIT_VFALL = 6,
34    #[doc = "7: In this state, the A-device waits for recovery of the over-current condition that caused it to enter this state."]
35    A_VBUS_ERR = 7,
36    #[doc = "8: In this state, the A-device waits for the data USB line to discharge (100 us)."]
37    A_WAIT_DISCHARGE = 8,
38    #[doc = "9: This is the start state for B-device (when the ID pin is 1)."]
39    B_IDLE = 9,
40    #[doc = "10: In this state, the B-device acts as the peripheral."]
41    B_PERIPHERAL = 10,
42    #[doc = "11: In this state, the B-device is in Suspend mode and waits until 3 ms before initiating the HNP protocol if requested."]
43    B_WAIT_BEGIN_HNP = 11,
44    #[doc = "12: In this state, the B-device waits for the data USB line to discharge (100 us)) before becoming Host."]
45    B_WAIT_DISCHARGE = 12,
46    #[doc = "13: In this state, the B-device waits for the A-device to signal a connect before becoming B-Host."]
47    B_WAIT_ACON = 13,
48    #[doc = "14: In this state, the B-device acts as the Host."]
49    B_HOST = 14,
50    #[doc = "15: In this state, the B-device attempts to start a session using the SRP protocol."]
51    B_SRP_INIT = 15,
52}
53impl From<DRDSTATE_A> for u8 {
54    #[inline(always)]
55    fn from(variant: DRDSTATE_A) -> Self {
56        variant as _
57    }
58}
59#[doc = "Field `DRDSTATE` reader - Dual Role Device State"]
60pub struct DRDSTATE_R(crate::FieldReader<u8, DRDSTATE_A>);
61impl DRDSTATE_R {
62    #[inline(always)]
63    pub(crate) fn new(bits: u8) -> Self {
64        DRDSTATE_R(crate::FieldReader::new(bits))
65    }
66    #[doc = r"Get enumerated values variant"]
67    #[inline(always)]
68    pub fn variant(&self) -> DRDSTATE_A {
69        match self.bits {
70            0 => DRDSTATE_A::A_IDLESTATE,
71            1 => DRDSTATE_A::A_WAIT_VRISE,
72            2 => DRDSTATE_A::A_WAIT_BCON,
73            3 => DRDSTATE_A::A_HOST,
74            4 => DRDSTATE_A::A_SUSPEND,
75            5 => DRDSTATE_A::A_PERIPHERAL,
76            6 => DRDSTATE_A::A_WAIT_VFALL,
77            7 => DRDSTATE_A::A_VBUS_ERR,
78            8 => DRDSTATE_A::A_WAIT_DISCHARGE,
79            9 => DRDSTATE_A::B_IDLE,
80            10 => DRDSTATE_A::B_PERIPHERAL,
81            11 => DRDSTATE_A::B_WAIT_BEGIN_HNP,
82            12 => DRDSTATE_A::B_WAIT_DISCHARGE,
83            13 => DRDSTATE_A::B_WAIT_ACON,
84            14 => DRDSTATE_A::B_HOST,
85            15 => DRDSTATE_A::B_SRP_INIT,
86            _ => unreachable!(),
87        }
88    }
89    #[doc = "Checks if the value of the field is `A_IDLESTATE`"]
90    #[inline(always)]
91    pub fn is_a_idlestate(&self) -> bool {
92        **self == DRDSTATE_A::A_IDLESTATE
93    }
94    #[doc = "Checks if the value of the field is `A_WAIT_VRISE`"]
95    #[inline(always)]
96    pub fn is_a_wait_vrise(&self) -> bool {
97        **self == DRDSTATE_A::A_WAIT_VRISE
98    }
99    #[doc = "Checks if the value of the field is `A_WAIT_BCON`"]
100    #[inline(always)]
101    pub fn is_a_wait_bcon(&self) -> bool {
102        **self == DRDSTATE_A::A_WAIT_BCON
103    }
104    #[doc = "Checks if the value of the field is `A_HOST`"]
105    #[inline(always)]
106    pub fn is_a_host(&self) -> bool {
107        **self == DRDSTATE_A::A_HOST
108    }
109    #[doc = "Checks if the value of the field is `A_SUSPEND`"]
110    #[inline(always)]
111    pub fn is_a_suspend(&self) -> bool {
112        **self == DRDSTATE_A::A_SUSPEND
113    }
114    #[doc = "Checks if the value of the field is `A_PERIPHERAL`"]
115    #[inline(always)]
116    pub fn is_a_peripheral(&self) -> bool {
117        **self == DRDSTATE_A::A_PERIPHERAL
118    }
119    #[doc = "Checks if the value of the field is `A_WAIT_VFALL`"]
120    #[inline(always)]
121    pub fn is_a_wait_vfall(&self) -> bool {
122        **self == DRDSTATE_A::A_WAIT_VFALL
123    }
124    #[doc = "Checks if the value of the field is `A_VBUS_ERR`"]
125    #[inline(always)]
126    pub fn is_a_vbus_err(&self) -> bool {
127        **self == DRDSTATE_A::A_VBUS_ERR
128    }
129    #[doc = "Checks if the value of the field is `A_WAIT_DISCHARGE`"]
130    #[inline(always)]
131    pub fn is_a_wait_discharge(&self) -> bool {
132        **self == DRDSTATE_A::A_WAIT_DISCHARGE
133    }
134    #[doc = "Checks if the value of the field is `B_IDLE`"]
135    #[inline(always)]
136    pub fn is_b_idle(&self) -> bool {
137        **self == DRDSTATE_A::B_IDLE
138    }
139    #[doc = "Checks if the value of the field is `B_PERIPHERAL`"]
140    #[inline(always)]
141    pub fn is_b_peripheral(&self) -> bool {
142        **self == DRDSTATE_A::B_PERIPHERAL
143    }
144    #[doc = "Checks if the value of the field is `B_WAIT_BEGIN_HNP`"]
145    #[inline(always)]
146    pub fn is_b_wait_begin_hnp(&self) -> bool {
147        **self == DRDSTATE_A::B_WAIT_BEGIN_HNP
148    }
149    #[doc = "Checks if the value of the field is `B_WAIT_DISCHARGE`"]
150    #[inline(always)]
151    pub fn is_b_wait_discharge(&self) -> bool {
152        **self == DRDSTATE_A::B_WAIT_DISCHARGE
153    }
154    #[doc = "Checks if the value of the field is `B_WAIT_ACON`"]
155    #[inline(always)]
156    pub fn is_b_wait_acon(&self) -> bool {
157        **self == DRDSTATE_A::B_WAIT_ACON
158    }
159    #[doc = "Checks if the value of the field is `B_HOST`"]
160    #[inline(always)]
161    pub fn is_b_host(&self) -> bool {
162        **self == DRDSTATE_A::B_HOST
163    }
164    #[doc = "Checks if the value of the field is `B_SRP_INIT`"]
165    #[inline(always)]
166    pub fn is_b_srp_init(&self) -> bool {
167        **self == DRDSTATE_A::B_SRP_INIT
168    }
169}
170impl core::ops::Deref for DRDSTATE_R {
171    type Target = crate::FieldReader<u8, DRDSTATE_A>;
172    #[inline(always)]
173    fn deref(&self) -> &Self::Target {
174        &self.0
175    }
176}
177impl R {
178    #[doc = "Bits 0:3 - Dual Role Device State"]
179    #[inline(always)]
180    pub fn drdstate(&self) -> DRDSTATE_R {
181        DRDSTATE_R::new((self.bits & 0x0f) as u8)
182    }
183}
184#[doc = "General Finite State Machine Register\n\nThis register you can [`read`](crate::generic::Reg::read). See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [usbhs_fsm](index.html) module"]
185pub struct USBHS_FSM_SPEC;
186impl crate::RegisterSpec for USBHS_FSM_SPEC {
187    type Ux = u32;
188}
189#[doc = "`read()` method returns [usbhs_fsm::R](R) reader structure"]
190impl crate::Readable for USBHS_FSM_SPEC {
191    type Reader = R;
192}
193#[doc = "`reset()` method sets USBHS_FSM to value 0"]
194impl crate::Resettable for USBHS_FSM_SPEC {
195    #[inline(always)]
196    fn reset_value() -> Self::Ux {
197        0
198    }
199}