Skip to main content

atsamv71n21/usbhs/
usbhs_devctrl.rs

1#[doc = "Register `USBHS_DEVCTRL` reader"]
2pub struct R(crate::R<USBHS_DEVCTRL_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<USBHS_DEVCTRL_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<USBHS_DEVCTRL_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<USBHS_DEVCTRL_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `USBHS_DEVCTRL` writer"]
17pub struct W(crate::W<USBHS_DEVCTRL_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<USBHS_DEVCTRL_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<USBHS_DEVCTRL_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<USBHS_DEVCTRL_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `UADD` reader - USB Address"]
38pub struct UADD_R(crate::FieldReader<u8, u8>);
39impl UADD_R {
40    #[inline(always)]
41    pub(crate) fn new(bits: u8) -> Self {
42        UADD_R(crate::FieldReader::new(bits))
43    }
44}
45impl core::ops::Deref for UADD_R {
46    type Target = crate::FieldReader<u8, u8>;
47    #[inline(always)]
48    fn deref(&self) -> &Self::Target {
49        &self.0
50    }
51}
52#[doc = "Field `UADD` writer - USB Address"]
53pub struct UADD_W<'a> {
54    w: &'a mut W,
55}
56impl<'a> UADD_W<'a> {
57    #[doc = r"Writes raw bits to the field"]
58    #[inline(always)]
59    pub unsafe fn bits(self, value: u8) -> &'a mut W {
60        self.w.bits = (self.w.bits & !0x7f) | (value as u32 & 0x7f);
61        self.w
62    }
63}
64#[doc = "Field `ADDEN` reader - Address Enable"]
65pub struct ADDEN_R(crate::FieldReader<bool, bool>);
66impl ADDEN_R {
67    #[inline(always)]
68    pub(crate) fn new(bits: bool) -> Self {
69        ADDEN_R(crate::FieldReader::new(bits))
70    }
71}
72impl core::ops::Deref for ADDEN_R {
73    type Target = crate::FieldReader<bool, bool>;
74    #[inline(always)]
75    fn deref(&self) -> &Self::Target {
76        &self.0
77    }
78}
79#[doc = "Field `ADDEN` writer - Address Enable"]
80pub struct ADDEN_W<'a> {
81    w: &'a mut W,
82}
83impl<'a> ADDEN_W<'a> {
84    #[doc = r"Sets the field bit"]
85    #[inline(always)]
86    pub fn set_bit(self) -> &'a mut W {
87        self.bit(true)
88    }
89    #[doc = r"Clears the field bit"]
90    #[inline(always)]
91    pub fn clear_bit(self) -> &'a mut W {
92        self.bit(false)
93    }
94    #[doc = r"Writes raw bits to the field"]
95    #[inline(always)]
96    pub fn bit(self, value: bool) -> &'a mut W {
97        self.w.bits = (self.w.bits & !(0x01 << 7)) | ((value as u32 & 0x01) << 7);
98        self.w
99    }
100}
101#[doc = "Field `DETACH` reader - Detach"]
102pub struct DETACH_R(crate::FieldReader<bool, bool>);
103impl DETACH_R {
104    #[inline(always)]
105    pub(crate) fn new(bits: bool) -> Self {
106        DETACH_R(crate::FieldReader::new(bits))
107    }
108}
109impl core::ops::Deref for DETACH_R {
110    type Target = crate::FieldReader<bool, bool>;
111    #[inline(always)]
112    fn deref(&self) -> &Self::Target {
113        &self.0
114    }
115}
116#[doc = "Field `DETACH` writer - Detach"]
117pub struct DETACH_W<'a> {
118    w: &'a mut W,
119}
120impl<'a> DETACH_W<'a> {
121    #[doc = r"Sets the field bit"]
122    #[inline(always)]
123    pub fn set_bit(self) -> &'a mut W {
124        self.bit(true)
125    }
126    #[doc = r"Clears the field bit"]
127    #[inline(always)]
128    pub fn clear_bit(self) -> &'a mut W {
129        self.bit(false)
130    }
131    #[doc = r"Writes raw bits to the field"]
132    #[inline(always)]
133    pub fn bit(self, value: bool) -> &'a mut W {
134        self.w.bits = (self.w.bits & !(0x01 << 8)) | ((value as u32 & 0x01) << 8);
135        self.w
136    }
137}
138#[doc = "Field `RMWKUP` reader - Remote Wake-Up"]
139pub struct RMWKUP_R(crate::FieldReader<bool, bool>);
140impl RMWKUP_R {
141    #[inline(always)]
142    pub(crate) fn new(bits: bool) -> Self {
143        RMWKUP_R(crate::FieldReader::new(bits))
144    }
145}
146impl core::ops::Deref for RMWKUP_R {
147    type Target = crate::FieldReader<bool, bool>;
148    #[inline(always)]
149    fn deref(&self) -> &Self::Target {
150        &self.0
151    }
152}
153#[doc = "Field `RMWKUP` writer - Remote Wake-Up"]
154pub struct RMWKUP_W<'a> {
155    w: &'a mut W,
156}
157impl<'a> RMWKUP_W<'a> {
158    #[doc = r"Sets the field bit"]
159    #[inline(always)]
160    pub fn set_bit(self) -> &'a mut W {
161        self.bit(true)
162    }
163    #[doc = r"Clears the field bit"]
164    #[inline(always)]
165    pub fn clear_bit(self) -> &'a mut W {
166        self.bit(false)
167    }
168    #[doc = r"Writes raw bits to the field"]
169    #[inline(always)]
170    pub fn bit(self, value: bool) -> &'a mut W {
171        self.w.bits = (self.w.bits & !(0x01 << 9)) | ((value as u32 & 0x01) << 9);
172        self.w
173    }
174}
175#[doc = "Mode Configuration\n\nValue on reset: 0"]
176#[derive(Clone, Copy, Debug, PartialEq)]
177#[repr(u8)]
178pub enum SPDCONF_A {
179    #[doc = "0: The peripheral starts in Full-speed mode and performs a high-speed reset to switch to High-speed mode if the host is high-speed-capable."]
180    NORMAL = 0,
181    #[doc = "1: For a better consumption, if high speed is not needed."]
182    LOW_POWER = 1,
183    #[doc = "2: Forced high speed."]
184    HIGH_SPEED = 2,
185    #[doc = "3: The peripheral remains in Full-speed mode whatever the host speed capability."]
186    FORCED_FS = 3,
187}
188impl From<SPDCONF_A> for u8 {
189    #[inline(always)]
190    fn from(variant: SPDCONF_A) -> Self {
191        variant as _
192    }
193}
194#[doc = "Field `SPDCONF` reader - Mode Configuration"]
195pub struct SPDCONF_R(crate::FieldReader<u8, SPDCONF_A>);
196impl SPDCONF_R {
197    #[inline(always)]
198    pub(crate) fn new(bits: u8) -> Self {
199        SPDCONF_R(crate::FieldReader::new(bits))
200    }
201    #[doc = r"Get enumerated values variant"]
202    #[inline(always)]
203    pub fn variant(&self) -> SPDCONF_A {
204        match self.bits {
205            0 => SPDCONF_A::NORMAL,
206            1 => SPDCONF_A::LOW_POWER,
207            2 => SPDCONF_A::HIGH_SPEED,
208            3 => SPDCONF_A::FORCED_FS,
209            _ => unreachable!(),
210        }
211    }
212    #[doc = "Checks if the value of the field is `NORMAL`"]
213    #[inline(always)]
214    pub fn is_normal(&self) -> bool {
215        **self == SPDCONF_A::NORMAL
216    }
217    #[doc = "Checks if the value of the field is `LOW_POWER`"]
218    #[inline(always)]
219    pub fn is_low_power(&self) -> bool {
220        **self == SPDCONF_A::LOW_POWER
221    }
222    #[doc = "Checks if the value of the field is `HIGH_SPEED`"]
223    #[inline(always)]
224    pub fn is_high_speed(&self) -> bool {
225        **self == SPDCONF_A::HIGH_SPEED
226    }
227    #[doc = "Checks if the value of the field is `FORCED_FS`"]
228    #[inline(always)]
229    pub fn is_forced_fs(&self) -> bool {
230        **self == SPDCONF_A::FORCED_FS
231    }
232}
233impl core::ops::Deref for SPDCONF_R {
234    type Target = crate::FieldReader<u8, SPDCONF_A>;
235    #[inline(always)]
236    fn deref(&self) -> &Self::Target {
237        &self.0
238    }
239}
240#[doc = "Field `SPDCONF` writer - Mode Configuration"]
241pub struct SPDCONF_W<'a> {
242    w: &'a mut W,
243}
244impl<'a> SPDCONF_W<'a> {
245    #[doc = r"Writes `variant` to the field"]
246    #[inline(always)]
247    pub fn variant(self, variant: SPDCONF_A) -> &'a mut W {
248        self.bits(variant.into())
249    }
250    #[doc = "The peripheral starts in Full-speed mode and performs a high-speed reset to switch to High-speed mode if the host is high-speed-capable."]
251    #[inline(always)]
252    pub fn normal(self) -> &'a mut W {
253        self.variant(SPDCONF_A::NORMAL)
254    }
255    #[doc = "For a better consumption, if high speed is not needed."]
256    #[inline(always)]
257    pub fn low_power(self) -> &'a mut W {
258        self.variant(SPDCONF_A::LOW_POWER)
259    }
260    #[doc = "Forced high speed."]
261    #[inline(always)]
262    pub fn high_speed(self) -> &'a mut W {
263        self.variant(SPDCONF_A::HIGH_SPEED)
264    }
265    #[doc = "The peripheral remains in Full-speed mode whatever the host speed capability."]
266    #[inline(always)]
267    pub fn forced_fs(self) -> &'a mut W {
268        self.variant(SPDCONF_A::FORCED_FS)
269    }
270    #[doc = r"Writes raw bits to the field"]
271    #[inline(always)]
272    pub fn bits(self, value: u8) -> &'a mut W {
273        self.w.bits = (self.w.bits & !(0x03 << 10)) | ((value as u32 & 0x03) << 10);
274        self.w
275    }
276}
277#[doc = "Field `LS` reader - Low-Speed Mode Force"]
278pub struct LS_R(crate::FieldReader<bool, bool>);
279impl LS_R {
280    #[inline(always)]
281    pub(crate) fn new(bits: bool) -> Self {
282        LS_R(crate::FieldReader::new(bits))
283    }
284}
285impl core::ops::Deref for LS_R {
286    type Target = crate::FieldReader<bool, bool>;
287    #[inline(always)]
288    fn deref(&self) -> &Self::Target {
289        &self.0
290    }
291}
292#[doc = "Field `LS` writer - Low-Speed Mode Force"]
293pub struct LS_W<'a> {
294    w: &'a mut W,
295}
296impl<'a> LS_W<'a> {
297    #[doc = r"Sets the field bit"]
298    #[inline(always)]
299    pub fn set_bit(self) -> &'a mut W {
300        self.bit(true)
301    }
302    #[doc = r"Clears the field bit"]
303    #[inline(always)]
304    pub fn clear_bit(self) -> &'a mut W {
305        self.bit(false)
306    }
307    #[doc = r"Writes raw bits to the field"]
308    #[inline(always)]
309    pub fn bit(self, value: bool) -> &'a mut W {
310        self.w.bits = (self.w.bits & !(0x01 << 12)) | ((value as u32 & 0x01) << 12);
311        self.w
312    }
313}
314#[doc = "Field `TSTJ` reader - Test mode J"]
315pub struct TSTJ_R(crate::FieldReader<bool, bool>);
316impl TSTJ_R {
317    #[inline(always)]
318    pub(crate) fn new(bits: bool) -> Self {
319        TSTJ_R(crate::FieldReader::new(bits))
320    }
321}
322impl core::ops::Deref for TSTJ_R {
323    type Target = crate::FieldReader<bool, bool>;
324    #[inline(always)]
325    fn deref(&self) -> &Self::Target {
326        &self.0
327    }
328}
329#[doc = "Field `TSTJ` writer - Test mode J"]
330pub struct TSTJ_W<'a> {
331    w: &'a mut W,
332}
333impl<'a> TSTJ_W<'a> {
334    #[doc = r"Sets the field bit"]
335    #[inline(always)]
336    pub fn set_bit(self) -> &'a mut W {
337        self.bit(true)
338    }
339    #[doc = r"Clears the field bit"]
340    #[inline(always)]
341    pub fn clear_bit(self) -> &'a mut W {
342        self.bit(false)
343    }
344    #[doc = r"Writes raw bits to the field"]
345    #[inline(always)]
346    pub fn bit(self, value: bool) -> &'a mut W {
347        self.w.bits = (self.w.bits & !(0x01 << 13)) | ((value as u32 & 0x01) << 13);
348        self.w
349    }
350}
351#[doc = "Field `TSTK` reader - Test mode K"]
352pub struct TSTK_R(crate::FieldReader<bool, bool>);
353impl TSTK_R {
354    #[inline(always)]
355    pub(crate) fn new(bits: bool) -> Self {
356        TSTK_R(crate::FieldReader::new(bits))
357    }
358}
359impl core::ops::Deref for TSTK_R {
360    type Target = crate::FieldReader<bool, bool>;
361    #[inline(always)]
362    fn deref(&self) -> &Self::Target {
363        &self.0
364    }
365}
366#[doc = "Field `TSTK` writer - Test mode K"]
367pub struct TSTK_W<'a> {
368    w: &'a mut W,
369}
370impl<'a> TSTK_W<'a> {
371    #[doc = r"Sets the field bit"]
372    #[inline(always)]
373    pub fn set_bit(self) -> &'a mut W {
374        self.bit(true)
375    }
376    #[doc = r"Clears the field bit"]
377    #[inline(always)]
378    pub fn clear_bit(self) -> &'a mut W {
379        self.bit(false)
380    }
381    #[doc = r"Writes raw bits to the field"]
382    #[inline(always)]
383    pub fn bit(self, value: bool) -> &'a mut W {
384        self.w.bits = (self.w.bits & !(0x01 << 14)) | ((value as u32 & 0x01) << 14);
385        self.w
386    }
387}
388#[doc = "Field `TSTPCKT` reader - Test packet mode"]
389pub struct TSTPCKT_R(crate::FieldReader<bool, bool>);
390impl TSTPCKT_R {
391    #[inline(always)]
392    pub(crate) fn new(bits: bool) -> Self {
393        TSTPCKT_R(crate::FieldReader::new(bits))
394    }
395}
396impl core::ops::Deref for TSTPCKT_R {
397    type Target = crate::FieldReader<bool, bool>;
398    #[inline(always)]
399    fn deref(&self) -> &Self::Target {
400        &self.0
401    }
402}
403#[doc = "Field `TSTPCKT` writer - Test packet mode"]
404pub struct TSTPCKT_W<'a> {
405    w: &'a mut W,
406}
407impl<'a> TSTPCKT_W<'a> {
408    #[doc = r"Sets the field bit"]
409    #[inline(always)]
410    pub fn set_bit(self) -> &'a mut W {
411        self.bit(true)
412    }
413    #[doc = r"Clears the field bit"]
414    #[inline(always)]
415    pub fn clear_bit(self) -> &'a mut W {
416        self.bit(false)
417    }
418    #[doc = r"Writes raw bits to the field"]
419    #[inline(always)]
420    pub fn bit(self, value: bool) -> &'a mut W {
421        self.w.bits = (self.w.bits & !(0x01 << 15)) | ((value as u32 & 0x01) << 15);
422        self.w
423    }
424}
425#[doc = "Field `OPMODE2` reader - Specific Operational mode"]
426pub struct OPMODE2_R(crate::FieldReader<bool, bool>);
427impl OPMODE2_R {
428    #[inline(always)]
429    pub(crate) fn new(bits: bool) -> Self {
430        OPMODE2_R(crate::FieldReader::new(bits))
431    }
432}
433impl core::ops::Deref for OPMODE2_R {
434    type Target = crate::FieldReader<bool, bool>;
435    #[inline(always)]
436    fn deref(&self) -> &Self::Target {
437        &self.0
438    }
439}
440#[doc = "Field `OPMODE2` writer - Specific Operational mode"]
441pub struct OPMODE2_W<'a> {
442    w: &'a mut W,
443}
444impl<'a> OPMODE2_W<'a> {
445    #[doc = r"Sets the field bit"]
446    #[inline(always)]
447    pub fn set_bit(self) -> &'a mut W {
448        self.bit(true)
449    }
450    #[doc = r"Clears the field bit"]
451    #[inline(always)]
452    pub fn clear_bit(self) -> &'a mut W {
453        self.bit(false)
454    }
455    #[doc = r"Writes raw bits to the field"]
456    #[inline(always)]
457    pub fn bit(self, value: bool) -> &'a mut W {
458        self.w.bits = (self.w.bits & !(0x01 << 16)) | ((value as u32 & 0x01) << 16);
459        self.w
460    }
461}
462impl R {
463    #[doc = "Bits 0:6 - USB Address"]
464    #[inline(always)]
465    pub fn uadd(&self) -> UADD_R {
466        UADD_R::new((self.bits & 0x7f) as u8)
467    }
468    #[doc = "Bit 7 - Address Enable"]
469    #[inline(always)]
470    pub fn adden(&self) -> ADDEN_R {
471        ADDEN_R::new(((self.bits >> 7) & 0x01) != 0)
472    }
473    #[doc = "Bit 8 - Detach"]
474    #[inline(always)]
475    pub fn detach(&self) -> DETACH_R {
476        DETACH_R::new(((self.bits >> 8) & 0x01) != 0)
477    }
478    #[doc = "Bit 9 - Remote Wake-Up"]
479    #[inline(always)]
480    pub fn rmwkup(&self) -> RMWKUP_R {
481        RMWKUP_R::new(((self.bits >> 9) & 0x01) != 0)
482    }
483    #[doc = "Bits 10:11 - Mode Configuration"]
484    #[inline(always)]
485    pub fn spdconf(&self) -> SPDCONF_R {
486        SPDCONF_R::new(((self.bits >> 10) & 0x03) as u8)
487    }
488    #[doc = "Bit 12 - Low-Speed Mode Force"]
489    #[inline(always)]
490    pub fn ls(&self) -> LS_R {
491        LS_R::new(((self.bits >> 12) & 0x01) != 0)
492    }
493    #[doc = "Bit 13 - Test mode J"]
494    #[inline(always)]
495    pub fn tstj(&self) -> TSTJ_R {
496        TSTJ_R::new(((self.bits >> 13) & 0x01) != 0)
497    }
498    #[doc = "Bit 14 - Test mode K"]
499    #[inline(always)]
500    pub fn tstk(&self) -> TSTK_R {
501        TSTK_R::new(((self.bits >> 14) & 0x01) != 0)
502    }
503    #[doc = "Bit 15 - Test packet mode"]
504    #[inline(always)]
505    pub fn tstpckt(&self) -> TSTPCKT_R {
506        TSTPCKT_R::new(((self.bits >> 15) & 0x01) != 0)
507    }
508    #[doc = "Bit 16 - Specific Operational mode"]
509    #[inline(always)]
510    pub fn opmode2(&self) -> OPMODE2_R {
511        OPMODE2_R::new(((self.bits >> 16) & 0x01) != 0)
512    }
513}
514impl W {
515    #[doc = "Bits 0:6 - USB Address"]
516    #[inline(always)]
517    pub fn uadd(&mut self) -> UADD_W {
518        UADD_W { w: self }
519    }
520    #[doc = "Bit 7 - Address Enable"]
521    #[inline(always)]
522    pub fn adden(&mut self) -> ADDEN_W {
523        ADDEN_W { w: self }
524    }
525    #[doc = "Bit 8 - Detach"]
526    #[inline(always)]
527    pub fn detach(&mut self) -> DETACH_W {
528        DETACH_W { w: self }
529    }
530    #[doc = "Bit 9 - Remote Wake-Up"]
531    #[inline(always)]
532    pub fn rmwkup(&mut self) -> RMWKUP_W {
533        RMWKUP_W { w: self }
534    }
535    #[doc = "Bits 10:11 - Mode Configuration"]
536    #[inline(always)]
537    pub fn spdconf(&mut self) -> SPDCONF_W {
538        SPDCONF_W { w: self }
539    }
540    #[doc = "Bit 12 - Low-Speed Mode Force"]
541    #[inline(always)]
542    pub fn ls(&mut self) -> LS_W {
543        LS_W { w: self }
544    }
545    #[doc = "Bit 13 - Test mode J"]
546    #[inline(always)]
547    pub fn tstj(&mut self) -> TSTJ_W {
548        TSTJ_W { w: self }
549    }
550    #[doc = "Bit 14 - Test mode K"]
551    #[inline(always)]
552    pub fn tstk(&mut self) -> TSTK_W {
553        TSTK_W { w: self }
554    }
555    #[doc = "Bit 15 - Test packet mode"]
556    #[inline(always)]
557    pub fn tstpckt(&mut self) -> TSTPCKT_W {
558        TSTPCKT_W { w: self }
559    }
560    #[doc = "Bit 16 - Specific Operational mode"]
561    #[inline(always)]
562    pub fn opmode2(&mut self) -> OPMODE2_W {
563        OPMODE2_W { w: self }
564    }
565    #[doc = "Writes raw bits to the register."]
566    #[inline(always)]
567    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
568        self.0.bits(bits);
569        self
570    }
571}
572#[doc = "Device General Control Register\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 [usbhs_devctrl](index.html) module"]
573pub struct USBHS_DEVCTRL_SPEC;
574impl crate::RegisterSpec for USBHS_DEVCTRL_SPEC {
575    type Ux = u32;
576}
577#[doc = "`read()` method returns [usbhs_devctrl::R](R) reader structure"]
578impl crate::Readable for USBHS_DEVCTRL_SPEC {
579    type Reader = R;
580}
581#[doc = "`write(|w| ..)` method takes [usbhs_devctrl::W](W) writer structure"]
582impl crate::Writable for USBHS_DEVCTRL_SPEC {
583    type Writer = W;
584}
585#[doc = "`reset()` method sets USBHS_DEVCTRL to value 0"]
586impl crate::Resettable for USBHS_DEVCTRL_SPEC {
587    #[inline(always)]
588    fn reset_value() -> Self::Ux {
589        0
590    }
591}