sam3_hal/pio/
structure.rs

1//! Mirrors the structure of the register blocks for each PIO controller with traits to allow pins
2//! to be generic over PIO types.
3
4#[allow(clippy::wildcard_imports)]
5use crate::{structure::*, write_protect::*};
6
7macro_rules! def_pio_regs {
8    (
9        pios: $pios:tt,
10        regs: $regs:tt,
11    ) => {
12        def_pio_regs! {
13            @defregs $regs
14        }
15
16        def_pio_regs! {
17            @impls
18            pios: $pios,
19            regs: $regs,
20        }
21    };
22
23    (
24        @defregs [$($opts:tt),+$(,)?]
25    ) => {
26        /// PIO register methods as a trait. Each is prefixed with an underscore because Ferris got
27        /// upset if they weren't.
28        pub trait PioRegisters {
29            type Rb: PioRegisters;
30            const PTR: *const Self::Rb;
31            fn ptr() -> *const Self::Rb {
32                <Self as PioRegisters>::PTR
33            }
34            $(
35                def_pio_regs! {
36                    @defreg $opts
37                }
38            )+
39        }
40    };
41    (
42        @defreg [$(#[$meta:meta])*$reg:ident, r]
43    ) => {
44        paste::paste! {
45            $(#[$meta])*
46            type $reg: BReader;
47            $(#[$meta])*
48            fn [<_ $reg:snake>](&self) -> &Self::$reg;
49        }
50    };
51    (
52        @defreg [$(#[$meta:meta])*$reg:ident, w]
53    ) => {
54        paste::paste! {
55            $(#[$meta])*
56            type $reg: BWriter;
57            $(#[$meta])*
58            fn [<_ $reg:snake>](&self) -> &Self::$reg;
59        }
60    };
61    (
62        @defreg [$(#[$meta:meta])*$reg:ident, wwz]
63    ) => {
64        paste::paste! {
65            $(#[$meta])*
66            type $reg: BWriterWithZero;
67            $(#[$meta])*
68            fn [<_ $reg:snake>](&self) -> &Self::$reg;
69        }
70    };
71    (
72        @defreg [$(#[$meta:meta])*$reg:ident, mw]
73    ) => {
74        paste::paste! {
75            $(#[$meta])*
76            type $reg: BModify + BWriter;
77            $(#[$meta])*
78            fn [<_ $reg:snake>](&self) -> &Self::$reg;
79        }
80    };
81    (
82        @defreg [$(#[$meta:meta])*$reg:ident, mwz]
83    ) => {
84        paste::paste! {
85            $(#[$meta])*
86            type $reg: BModify;
87            $(#[$meta])*
88            fn [<_ $reg:snake>](&self) -> &Self::$reg;
89        }
90    };
91    (
92        @defreg [$(#[$meta:meta])*$reg:ident, $other:ident]
93    ) => {
94        paste::paste! {
95            $(#[$meta])*
96            type $reg: $other;
97            $(#[$meta])*
98            fn [<_ $reg:snake>](&self) -> &Self::$reg;
99        }
100    };
101
102    (
103        @impls
104        pios: [],
105        regs: $regs:tt,
106    ) => {};
107    (
108        @impls
109        pios: [$(#[$meta:meta])*$pio:ident$(, $(#[$metarest:meta])*$piorest:ident)*$(,)?],
110        regs: $regs:tt,
111    ) => {
112        def_pio_regs! {
113            @implpio
114            meta: [$(#[$meta])*],
115            pio: $pio,
116            regs: $regs,
117        }
118
119        def_pio_regs! {
120            @impls
121            pios: [$($(#[$metarest])*$piorest),*],
122            regs: $regs,
123        }
124    };
125    (
126        @implpio
127        meta: [$(#[$meta:meta])*],
128        pio: $pio:ident,
129        regs: [$($opts:tt),+$(,)?],
130    ) => {
131        $(#[$meta])*
132        const _: () = {
133            paste::paste! {
134                impl PioRegisters for crate::pac::$pio {
135                    type Rb = crate::pac::[<$pio:lower>]::RegisterBlock;
136                    const PTR: *const Self::Rb = crate::pac::$pio::PTR;
137                    $(
138                        def_pio_regs! {
139                            @implpioreg $pio, $opts
140                        }
141                    )+
142                }
143
144                impl PioRegisters for crate::pac::[<$pio:lower>]::RegisterBlock {
145                    type Rb = Self;
146                    const PTR: *const Self = crate::pac::$pio::PTR;
147                    $(
148                        def_pio_regs! {
149                            @implpioreg $pio, $opts
150                        }
151                    )+
152                }
153            }
154
155            $(
156                def_pio_regs! {
157                    @implpioregfields
158                    pio: $pio,
159                    reg: $opts,
160                }
161            )+
162        };
163    };
164    (
165        @implpioreg $pio:ident, [$(#[$meta:meta])*$reg:ident, $tag:tt]
166    ) => {
167        paste::paste! {
168            $(#[$meta])*
169            type $reg = crate::pac::[<$pio:lower>]::$reg;
170            $(#[$meta])*
171            fn [<_ $reg:snake>](&self) -> &Self::$reg {
172                self.[<$reg:snake>]()
173            }
174        }
175    };
176    (
177        @implpioregfields
178        pio: $pio:ident,
179        reg: [$(#[$meta:meta])*$reg:ident, r],
180    ) => {
181        $(#[$meta])*
182        const _: () = {
183            paste::paste! {
184                impl BReader for crate::pac::[<$pio:lower>]::$reg {
185                    type R = crate::pac::[<$pio:lower>]::[<$reg:lower>]::R;
186                    fn read(&self) -> Self::R {
187                        self.read()
188                    }
189                }
190            }
191
192            seq_macro::seq! {N in 0..32 {
193                paste::paste! {
194                    impl BReaderFields for crate::pac::[<$pio:lower>]::[<$reg:lower>]::R {
195                        #(
196                            type [<P~N R>] = crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<P~N R>];
197                            fn p~N(&self) -> Self::[<P~N R>] {
198                                self.p~N()
199                            }
200                        )*
201                        fn bits(&self) -> u32 {
202                            self.bits()
203                        }
204                    }
205                }
206            }}
207        };
208    };
209    (
210        @implpioregfields
211        pio: $pio:ident,
212        reg: [$(#[$meta:meta])*$reg:ident, w],
213    ) => {
214        $(#[$meta])*
215        const _: () = {
216            paste::paste! {
217                impl BWriter for crate::pac::[<$pio:lower>]::$reg {
218                    fn reset(&self) {
219                        self.reset();
220                    }
221                    type W = crate::pac::[<$pio:lower>]::[<$reg:lower>]::W;
222                    fn write<F>(&self, f: F)
223                    where
224                        F: FnOnce(&mut Self::W) -> &mut Self::W,
225                    {
226                        self.write(f)
227                    }
228                }
229            }
230
231            seq_macro::seq! {N in 0..32 {
232                paste::paste! {
233                    impl BWriterFields for crate::pac::[<$pio:lower>]::[<$reg:lower>]::W {
234                        #(
235                            type [<P~N W>]<'a> =
236                                crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<P~N W>]<
237                                    'a,
238                                    crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<$reg Spec>],
239                                >;
240                            fn p~N(&mut self) -> Self::[<P~N W>]<'_> {
241                                self.p~N()
242                            }
243                        )*
244                    }
245                }
246            }}
247
248            crate::structure::bwrite_impl! {
249                ty: $pio,
250                reg: $reg,
251            }
252        };
253    };
254    (
255        @implpioregfields
256        pio: $pio:ident,
257        reg: [$(#[$meta:meta])*$reg:ident, wwz],
258    ) => {
259        $(#[$meta])*
260        const _: () = {
261            paste::paste! {
262                impl BWriterWithZero for crate::pac::[<$pio:lower>]::$reg {
263                    type W = crate::pac::[<$pio:lower>]::[<$reg:lower>]::W;
264                    unsafe fn write_with_zero<F>(&self, f: F)
265                    where
266                        F: FnOnce(&mut Self::W) -> &mut Self::W,
267                    {
268                        self.write_with_zero(f)
269                    }
270                }
271            }
272
273            seq_macro::seq! {N in 0..32 {
274                paste::paste! {
275                    impl BWriterFields for crate::pac::[<$pio:lower>]::[<$reg:lower>]::W {
276                        #(
277                            type [<P~N W>]<'a> =
278                                crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<P~N W>]<
279                                    'a,
280                                    crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<$reg Spec>],
281                                >;
282                            fn p~N(&mut self) -> Self::[<P~N W>]<'_> {
283                                self.p~N()
284                            }
285                        )*
286                        unsafe fn bits(&mut self, bits: u32) -> &mut Self {
287                            self.bits(bits)
288                        }
289                    }
290                }
291            }}
292
293            crate::structure::bwrite_impl! {
294                ty: $pio,
295                reg: $reg,
296            }
297        };
298    };
299    (
300        @implpioregfields
301        pio: $pio:ident,
302        reg: [$(#[$meta:meta])*$reg:ident, mw],
303    ) => {
304        $(#[$meta])*
305        const _: () = {
306            paste::paste! {
307                impl BReader for crate::pac::[<$pio:lower>]::$reg {
308                    type R = crate::pac::[<$pio:lower>]::[<$reg:lower>]::R;
309                    fn read(&self) -> Self::R {
310                        self.read()
311                    }
312                }
313            }
314
315            seq_macro::seq! {N in 0..32 {
316                paste::paste! {
317                    impl BReaderFields for crate::pac::[<$pio:lower>]::[<$reg:lower>]::R {
318                        #(
319                            type [<P~N R>] = crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<P~N R>];
320                            fn p~N(&self) -> Self::[<P~N R>] {
321                                self.p~N()
322                            }
323                        )*
324                        fn bits(&self) -> u32 {
325                            self.bits()
326                        }
327                    }
328                }
329            }}
330
331            paste::paste! {
332                impl BWriter for crate::pac::[<$pio:lower>]::$reg {
333                    fn reset(&self) {
334                        self.reset();
335                    }
336                    type W = crate::pac::[<$pio:lower>]::[<$reg:lower>]::W;
337                    fn write<F>(&self, f: F)
338                    where
339                        F: FnOnce(&mut Self::W) -> &mut Self::W,
340                    {
341                        self.write(f)
342                    }
343                }
344            }
345
346            paste::paste! {
347                impl BWriterWithZero for crate::pac::[<$pio:lower>]::$reg {
348                    type W = crate::pac::[<$pio:lower>]::[<$reg:lower>]::W;
349                    unsafe fn write_with_zero<F>(&self, f: F)
350                    where
351                        F: FnOnce(&mut Self::W) -> &mut Self::W,
352                    {
353                        self.write_with_zero(f)
354                    }
355                }
356            }
357
358            seq_macro::seq! {N in 0..32 {
359                paste::paste! {
360                    impl BWriterFields for crate::pac::[<$pio:lower>]::[<$reg:lower>]::W {
361                        #(
362                            type [<P~N W>]<'a> =
363                                crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<P~N W>]<
364                                    'a,
365                                    crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<$reg Spec>],
366                                >;
367                            fn p~N(&mut self) -> Self::[<P~N W>]<'_> {
368                                self.p~N()
369                            }
370                        )*
371                        unsafe fn bits(&mut self, bits: u32) -> &mut Self {
372                            self.bits(bits)
373                        }
374                    }
375                }
376            }}
377
378            crate::structure::bwrite_impl! {
379                ty: $pio,
380                reg: $reg,
381            }
382
383            paste::paste! {
384                impl BModify for crate::pac::[<$pio:lower>]::$reg {
385                    fn modify<F>(&self, f: F)
386                    where
387                        for<'w> F: FnOnce(
388                            &<Self as BReader>::R,
389                            &'w mut <Self as BWriterWithZero>::W,
390                        ) -> &'w mut <Self as BWriterWithZero>::W,
391                    {
392                        self.modify(f);
393                    }
394                }
395            }
396        };
397    };
398    (
399        @implpioregfields
400        pio: $pio:ident,
401        reg: [$(#[$meta:meta])*$reg:ident, mwz],
402    ) => {
403        $(#[$meta])*
404        const _: () = {
405            paste::paste! {
406                impl BReader for crate::pac::[<$pio:lower>]::$reg {
407                    type R = crate::pac::[<$pio:lower>]::[<$reg:lower>]::R;
408                    fn read(&self) -> Self::R {
409                        self.read()
410                    }
411                }
412            }
413
414            seq_macro::seq! {N in 0..32 {
415                paste::paste! {
416                    impl BReaderFields for crate::pac::[<$pio:lower>]::[<$reg:lower>]::R {
417                        #(
418                            type [<P~N R>] = crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<P~N R>];
419                            fn p~N(&self) -> Self::[<P~N R>] {
420                                self.p~N()
421                            }
422                        )*
423                        fn bits(&self) -> u32 {
424                            self.bits()
425                        }
426                    }
427                }
428            }}
429
430            paste::paste! {
431                impl BWriterWithZero for crate::pac::[<$pio:lower>]::$reg {
432                    type W = crate::pac::[<$pio:lower>]::[<$reg:lower>]::W;
433                    unsafe fn write_with_zero<F>(&self, f: F)
434                    where
435                        F: FnOnce(&mut Self::W) -> &mut Self::W,
436                    {
437                        self.write_with_zero(f)
438                    }
439                }
440            }
441
442            seq_macro::seq! {N in 0..32 {
443                paste::paste! {
444                    impl BWriterFields for crate::pac::[<$pio:lower>]::[<$reg:lower>]::W {
445                        #(
446                            type [<P~N W>]<'a> =
447                                crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<P~N W>]<
448                                    'a,
449                                    crate::pac::[<$pio:lower>]::[<$reg:lower>]::[<$reg Spec>],
450                                >;
451                            fn p~N(&mut self) -> Self::[<P~N W>]<'_> {
452                                self.p~N()
453                            }
454                        )*
455                        unsafe fn bits(&mut self, bits: u32) -> &mut Self {
456                            self.bits(bits)
457                        }
458                    }
459                }
460            }}
461
462            crate::structure::bwrite_impl! {
463                ty: $pio,
464                reg: $reg,
465            }
466
467            paste::paste! {
468                impl BModify for crate::pac::[<$pio:lower>]::$reg {
469                    fn modify<F>(&self, f: F)
470                    where
471                        for<'w> F: FnOnce(
472                            &<Self as BReader>::R,
473                            &'w mut <Self as BWriterWithZero>::W,
474                        ) -> &'w mut <Self as BWriterWithZero>::W,
475                    {
476                        self.modify(f);
477                    }
478                }
479            }
480        };
481    };
482    (
483        @implpioregfields
484        pio: $pio:ident,
485        reg: [$(#[$imeta:meta])*$reg:ident, $other:ident],
486    ) => {};
487}
488
489def_pio_regs! {
490    pios: [
491        PIOA,
492        PIOB,
493        #[cfg(feature = "pioc")]
494        PIOC,
495        #[cfg(feature = "piod")]
496        PIOD,
497        #[cfg(feature = "pioe")]
498        PIOE,
499        #[cfg(feature = "piof")]
500        PIOF,
501    ],
502    regs: [
503        [
504            #[cfg(any(feature = "3fn", feature = "4fn"))]
505            Abcdsr0,
506            mwz
507        ],
508        [
509            #[cfg(any(feature = "3fn", feature = "4fn"))]
510            Abcdsr1,
511            mwz
512        ],
513        [
514            #[cfg(feature = "2fn")]
515            Absr,
516            mw
517        ],
518        [Aimdr, wwz],
519        [Aimer, wwz],
520        [Aimmr, r],
521        [Codr, wwz],
522        [
523            #[cfg(any(feature = "sam3a", feature = "sam3u", feature = "sam3x"))]
524            Difsr,
525            wwz
526        ],
527        [Elsr, r],
528        [Esr, wwz],
529        [Fellsr, wwz],
530        [Frlhsr, r],
531        [Idr, wwz],
532        [Ier, wwz],
533        [
534            #[cfg(any(feature = "sam3a", feature = "sam3u", feature = "sam3x"))]
535            Ifdgsr,
536            r
537        ],
538        [Ifdr, wwz],
539        [Ifer, wwz],
540        [
541            #[cfg(any(feature = "sam3n", feature = "sam3s", feature = "sam3s8"))]
542            Ifscdr,
543            wwz
544        ],
545        [
546            #[cfg(any(feature = "sam3n", feature = "sam3s", feature = "sam3s8"))]
547            Ifscer,
548            wwz
549        ],
550        [
551            #[cfg(any(feature = "sam3n", feature = "sam3s", feature = "sam3s8"))]
552            Ifscsr,
553            r
554        ],
555        [Ifsr, r],
556        [Imr, r],
557        [Isr, r],
558        [Locksr, r],
559        [Lsr, wwz],
560        [Mddr, wwz],
561        [Mder, wwz],
562        [Mdsr, r],
563        [Odr, wwz],
564        [Odsr, mwz],
565        [Oer, wwz],
566        [Osr, r],
567        [Owdr, wwz],
568        [Ower, wwz],
569        [Owsr, r],
570        [Pdr, wwz],
571        [Pdsr, r],
572        [Per, wwz],
573        [
574            #[cfg(feature = "ppd")]
575            Ppddr,
576            wwz
577        ],
578        [
579            #[cfg(feature = "ppd")]
580            Ppder,
581            wwz
582        ],
583        [
584            #[cfg(feature = "ppd")]
585            Ppdsr,
586            r
587        ],
588        [Psr, r],
589        [Pudr, wwz],
590        [Puer, wwz],
591        [Pusr, r],
592        [Rehlsr, wwz],
593        [Scdr, ScdrModify],
594        [
595            #[cfg(feature = "schmitt")]
596            Schmitt,
597            SchmittModify
598        ],
599        [
600            #[cfg(any(feature = "sam3a", feature = "sam3u", feature = "sam3x"))]
601            Scifsr,
602            wwz
603        ],
604        [Sodr, wwz],
605        [Wpmr, WpmrModify],
606        [Wpsr, WpsrRead],
607    ],
608}
609
610/// `Reg<ScdrSpec>::read` as a trait.
611pub trait ScdrRead {
612    type R: ScdrReadFields;
613    fn read(&self) -> Self::R;
614}
615
616/// `R<ScdrSpec>::div` as a trait.
617pub trait ScdrReadFields {
618    type Div: FRead<u16>;
619    fn div(&self) -> Self::Div;
620}
621
622/// `Reg<ScdrSpec>::reset` and `Reg<ScdrSpec>::write` as a trait.
623pub trait ScdrWrite {
624    fn reset(&self);
625    type W: ScdrWriteFields;
626    fn write<F>(&self, f: F)
627    where
628        F: FnOnce(&mut Self::W) -> &mut Self::W;
629}
630
631/// `Reg<ScdrSpec>::write_with_zero` as a trait.
632pub trait ScdrWriteWithZero {
633    type W: ScdrWriteFields;
634    #[allow(clippy::missing_safety_doc)]
635    /// See [`Reg::write_with_zero`](crate::pac::generic::Reg::write_with_zero).
636    unsafe fn write_with_zero<F>(&self, f: F)
637    where
638        F: FnOnce(&mut Self::W) -> &mut Self::W;
639}
640
641/// `W<ScdrSpec>::div` as a trait.
642pub trait ScdrWriteFields: Sized {
643    type Div<'a>: FWrite<'a, 14, u16, Self>
644    where
645        Self: 'a + Sized;
646    fn div(&mut self) -> Self::Div<'_>;
647}
648
649/// `Reg<ScdrSpec>::modify` as a trait.
650pub trait ScdrModify: ScdrRead + ScdrWrite + ScdrWriteWithZero {
651    fn modify<F>(&self, f: F)
652    where
653        for<'w> F: FnOnce(
654            &<Self as ScdrRead>::R,
655            &'w mut <Self as ScdrWrite>::W,
656        ) -> &'w mut <Self as ScdrWrite>::W;
657}
658
659#[cfg(feature = "schmitt")]
660/// `Reg<SchmittSpec>::read` as a trait.
661pub trait SchmittRead {
662    type R: SchmittReadFields;
663    fn read(&self) -> Self::R;
664}
665
666#[cfg(feature = "schmitt")]
667seq_macro::seq! {N in 0..32 {
668    paste::paste! {
669        /// Trait providing `.schmitt0()`, `.schmitt1()`, ..., `.schmitt31()`, and [`.bits()`][bits]
670        /// methods as readers.
671        ///
672        /// [bits]: crate::pac::generic::R#method.bits
673        pub trait SchmittReadFields {
674            #(
675                type [<Schmitt~N R>]: BRead;
676                fn schmitt~N(&self) -> Self::[<Schmitt~N R>];
677            )*
678            fn bits(&self) -> u32;
679        }
680
681        /// Trait providing `.schmitt0()`, `.schmitt1()`, ..., `.schmitt31()`, and
682        /// [`.bits(bits)`][bits] methods as writers.
683        ///
684        /// [bits]: crate::pac::generic::W#method.bits
685        pub trait SchmittWriteFields: Sized {
686            #(
687                type [<Schmitt~N W>]<'a>: BWrite<'a, Self>
688                where
689                    Self: 'a + Sized;
690                fn schmitt~N(&mut self) -> Self::[<Schmitt~N W>]<'_>;
691            )*
692            #[allow(clippy::missing_safety_doc)]
693            unsafe fn bits(&mut self, bits: u32) -> &mut Self;
694        }
695    }
696}}
697
698#[cfg(feature = "schmitt")]
699/// `Reg<SchmittSpec>::reset` and `Reg<SchmittSpec>::write` as a trait.
700pub trait SchmittWrite {
701    fn reset(&self);
702    type W: SchmittWriteFields;
703    fn write<F>(&self, f: F)
704    where
705        F: FnOnce(&mut Self::W) -> &mut Self::W;
706}
707
708#[cfg(feature = "schmitt")]
709/// `Reg<SchmittSpec>::write_with_zero` as a trait.
710pub trait SchmittWriteWithZero {
711    type W: SchmittWriteFields;
712    #[allow(clippy::missing_safety_doc)]
713    unsafe fn write_with_zero<F>(&self, f: F)
714    where
715        F: FnOnce(&mut Self::W) -> &mut Self::W;
716}
717
718#[cfg(feature = "schmitt")]
719/// `Reg<SchmittSpec>::modify` as a trait.
720pub trait SchmittModify: SchmittRead + SchmittWrite + SchmittWriteWithZero {
721    fn modify<F>(&self, f: F)
722    where
723        for<'w> F: FnOnce(
724            &<Self as SchmittRead>::R,
725            &'w mut <Self as SchmittWrite>::W,
726        ) -> &'w mut <Self as SchmittWrite>::W;
727}
728
729macro_rules! other_impls {
730    ($($(#[$meta:meta])*$pio:ident),+$(,)?) => {
731        $(
732            paste::paste! {
733                $(#[$meta])*
734                const _: () = {
735                    impl ScdrRead for crate::pac::[<$pio:lower>]::Scdr {
736                        type R = crate::pac::[<$pio:lower>]::scdr::R;
737                        fn read(&self) -> Self::R {
738                            self.read()
739                        }
740                    }
741
742                    impl ScdrReadFields for crate::pac::[<$pio:lower>]::scdr::R {
743                        type Div = crate::pac::[<$pio:lower>]::scdr::DivR;
744                        fn div(&self) -> Self::Div {
745                            self.div()
746                        }
747                    }
748
749                    impl ScdrWrite for crate::pac::[<$pio:lower>]::Scdr {
750                        fn reset(&self) {
751                            self.reset();
752                        }
753                        type W = crate::pac::[<$pio:lower>]::scdr::W;
754                        fn write<F>(&self, f: F)
755                        where
756                            F: FnOnce(&mut Self::W) -> &mut Self::W,
757                        {
758                            self.write(f)
759                        }
760                    }
761
762                    impl ScdrWriteWithZero for crate::pac::[<$pio:lower>]::Scdr {
763                        type W = crate::pac::[<$pio:lower>]::scdr::W;
764                        unsafe fn write_with_zero<F>(&self, f: F)
765                        where
766                            F: FnOnce(&mut Self::W) -> &mut Self::W,
767                        {
768                            self.write_with_zero(f)
769                        }
770                    }
771
772                    impl ScdrWriteFields for crate::pac::[<$pio:lower>]::scdr::W {
773                        type Div<'a> = crate::pac::[<$pio:lower>]::scdr::DivW<
774                            'a,
775                            crate::pac::[<$pio:lower>]::scdr::ScdrSpec,
776                        >;
777                        fn div(&mut self) -> Self::Div<'_> {
778                            self.div()
779                        }
780                    }
781
782                    impl<'a> FWrite<'a, 14, u16, crate::pac::[<$pio:lower>]::scdr::W>
783                        for crate::pac::[<$pio:lower>]::scdr::DivW<
784                            'a,
785                            crate::pac::[<$pio:lower>]::scdr::ScdrSpec,
786                        >
787                    {
788                        const WIDTH: u8 = Self::WIDTH;
789                        fn width(&self) -> u8 {
790                            self.width()
791                        }
792                        fn offset(&self) -> u8 {
793                            self.offset()
794                        }
795                        unsafe fn bits(self, value: u16)
796                            -> &'a mut crate::pac::[<$pio:lower>]::scdr::W
797                        {
798                            self.bits(value)
799                        }
800                    }
801
802                    impl ScdrModify for crate::pac::[<$pio:lower>]::Scdr {
803                        fn modify<F>(&self, f: F)
804                        where
805                            for<'w> F: FnOnce(
806                                &<Self as ScdrRead>::R,
807                                &'w mut <Self as ScdrWrite>::W,
808                            ) -> &'w mut <Self as ScdrWrite>::W,
809                        {
810                            self.modify(f)
811                        }
812                    }
813
814                    impl WpmrRead for crate::pac::[<$pio:lower>]::Wpmr {
815                        type R = crate::pac::[<$pio:lower>]::wpmr::R;
816                        fn read(&self) -> Self::R {
817                            self.read()
818                        }
819                    }
820
821                    impl WpmrReadFields for crate::pac::[<$pio:lower>]::wpmr::R {
822                        type Wpen = crate::pac::[<$pio:lower>]::wpmr::WpenR;
823                        fn wpen(&self) -> Self::Wpen {
824                            self.wpen()
825                        }
826                        type Wpkey = crate::pac::[<$pio:lower>]::wpmr::WpkeyR;
827                        fn wpkey(&self) -> Self::Wpkey {
828                            self.wpkey()
829                        }
830                    }
831
832                    impl WpmrWrite for crate::pac::[<$pio:lower>]::Wpmr {
833                        fn reset(&self) {
834                            self.reset();
835                        }
836                        type W = crate::pac::[<$pio:lower>]::wpmr::W;
837                        fn write<F>(&self, f: F)
838                        where
839                            F: FnOnce(&mut Self::W) -> &mut Self::W,
840                        {
841                            self.write(f)
842                        }
843                    }
844
845                    impl WpmrWriteWithZero for crate::pac::[<$pio:lower>]::Wpmr {
846                        type W = crate::pac::[<$pio:lower>]::wpmr::W;
847                        unsafe fn write_with_zero<F>(&self, f: F)
848                        where
849                            F: FnOnce(&mut Self::W) -> &mut Self::W,
850                        {
851                            self.write_with_zero(f)
852                        }
853                    }
854
855                    impl WpmrWriteFields for crate::pac::[<$pio:lower>]::wpmr::W {
856                        type Wpen<'a> = crate::pac::[<$pio:lower>]::wpmr::WpenW<
857                            'a,
858                            crate::pac::[<$pio:lower>]::wpmr::WpmrSpec,
859                        >;
860                        fn wpen(&mut self) -> Self::Wpen<'_> {
861                            self.wpen()
862                        }
863                        type Wpkey<'a> = crate::pac::[<$pio:lower>]::wpmr::WpkeyW<
864                            'a,
865                            crate::pac::[<$pio:lower>]::wpmr::WpmrSpec,
866                        >;
867                        fn wpkey(&mut self) -> Self::Wpkey<'_> {
868                            self.wpkey()
869                        }
870                    }
871
872                    crate::structure::bwrite_impl! {
873                        ty: $pio,
874                        reg: Wpmr,
875                    }
876
877                    impl<'a> FWrite<'a, 24, u32, crate::pac::[<$pio:lower>]::wpmr::W>
878                        for crate::pac::[<$pio:lower>]::wpmr::WpkeyW<
879                            'a,
880                            crate::pac::[<$pio:lower>]::wpmr::WpmrSpec,
881                        >
882                    {
883                        const WIDTH: u8 = Self::WIDTH;
884                        fn width(&self) -> u8 {
885                            self.width()
886                        }
887                        fn offset(&self) -> u8 {
888                            self.offset()
889                        }
890                        unsafe fn bits(self, value: u32)
891                            -> &'a mut crate::pac::[<$pio:lower>]::wpmr::W
892                        {
893                            self.bits(value)
894                        }
895                    }
896
897                    impl WpmrModify for crate::pac::[<$pio:lower>]::Wpmr {
898                        fn modify<F>(&self, f: F)
899                        where
900                            for<'w> F: FnOnce(
901                                &<Self as WpmrRead>::R,
902                                &'w mut <Self as WpmrWrite>::W,
903                            ) -> &'w mut <Self as WpmrWrite>::W,
904                        {
905                            self.modify(f)
906                        }
907                    }
908
909                    impl WpsrRead for crate::pac::[<$pio:lower>]::Wpsr {
910                        type R = crate::pac::[<$pio:lower>]::wpsr::R;
911                        fn read(&self) -> Self::R {
912                            self.read()
913                        }
914                    }
915
916                    impl WpsrReadFields for crate::pac::[<$pio:lower>]::wpsr::R {
917                        type Wpvs = crate::pac::[<$pio:lower>]::wpsr::WpvsR;
918                        fn wpvs(&self) -> Self::Wpvs {
919                            self.wpvs()
920                        }
921                        type Addr = u16;
922                        type Wpvsrc = crate::pac::[<$pio:lower>]::wpsr::WpvsrcR;
923                        fn wpvsrc(&self) -> Self::Wpvsrc {
924                            self.wpvsrc()
925                        }
926                    }
927                };
928            }
929
930            seq_macro::seq! {N in 0..32 {
931                paste::paste! {
932                    $(#[$meta])*
933                    #[cfg(feature = "schmitt")]
934                    const _: () = {
935                        impl SchmittReadFields for crate::pac::[<$pio:lower>]::schmitt::R {
936                            #(
937                                type [<Schmitt~N R>] =
938                                    crate::pac::[<$pio:lower>]::schmitt::[<Schmitt~N R>];
939                                fn schmitt~N(&self) -> Self::[<Schmitt~N R>] {
940                                    self.schmitt~N()
941                                }
942                            )*
943                            fn bits(&self) -> u32 {
944                                self.bits()
945                            }
946                        }
947
948                        impl SchmittWriteFields for crate::pac::[<$pio:lower>]::schmitt::W {
949                            #(
950                                type [<Schmitt~N W>]<'a> =
951                                    crate::pac::[<$pio:lower>]::schmitt::[<Schmitt~N W>]<
952                                        'a,
953                                        crate::pac::[<$pio:lower>]::schmitt::SchmittSpec,
954                                    >;
955                                fn schmitt~N(&mut self) -> Self::[<Schmitt~N W>]<'_> {
956                                    self.schmitt~N()
957                                }
958                            )*
959                            unsafe fn bits(&mut self, bits: u32) -> &mut Self {
960                                self.bits(bits)
961                            }
962                        }
963
964                        crate::structure::bwrite_impl! {
965                            ty: $pio,
966                            reg: Schmitt,
967                        }
968                    };
969                }
970            }}
971
972            paste::paste! {
973                $(#[$meta])*
974                #[cfg(feature = "schmitt")]
975                const _: () = {
976                    impl SchmittRead for crate::pac::[<$pio:lower>]::Schmitt {
977                        type R = crate::pac::[<$pio:lower>]::schmitt::R;
978                        fn read(&self) -> Self::R {
979                            self.read()
980                        }
981                    }
982
983                    impl SchmittWrite for crate::pac::[<$pio:lower>]::Schmitt {
984                        fn reset(&self) {
985                            self.reset();
986                        }
987                        type W = crate::pac::[<$pio:lower>]::schmitt::W;
988                        fn write<F>(&self, f: F)
989                        where
990                            F: FnOnce(&mut Self::W) -> &mut Self::W,
991                        {
992                            self.write(f)
993                        }
994                    }
995
996                    impl SchmittWriteWithZero for crate::pac::[<$pio:lower>]::Schmitt {
997                        type W = crate::pac::[<$pio:lower>]::schmitt::W;
998                        unsafe fn write_with_zero<F>(&self, f: F)
999                        where
1000                            F: FnOnce(&mut Self::W) -> &mut Self::W,
1001                        {
1002                            self.write_with_zero(f)
1003                        }
1004                    }
1005
1006                    impl SchmittModify for crate::pac::[<$pio:lower>]::Schmitt {
1007                        fn modify<F>(&self, f: F)
1008                        where
1009                            for<'w> F: FnOnce(
1010                                &<Self as SchmittRead>::R,
1011                                &'w mut <Self as SchmittWrite>::W,
1012                            ) -> &'w mut <Self as SchmittWrite>::W,
1013                        {
1014                            self.modify(f)
1015                        }
1016                    }
1017                };
1018            }
1019        )+
1020    }
1021}
1022
1023other_impls! {
1024    PIOA,
1025    PIOB,
1026    #[cfg(feature = "pioc")]
1027    PIOC,
1028    #[cfg(feature = "piod")]
1029    PIOD,
1030    #[cfg(feature = "pioe")]
1031    PIOE,
1032    #[cfg(feature = "piof")]
1033    PIOF,
1034}