rp2350 0.1.0

Hardware Abstraction Layer for RP2350 microcontrollers
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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
//! GPIO Pin Function Mapping for RP2350
//!
//! This module provides compile-time verified GPIO pin function mappings
//! using Rust's trait system. It enables type-safe peripheral initialization
//! where only valid pins can be used with each peripheral.
//!
//! # Design Philosophy
//!
//! The RP2350 has strict pin-to-peripheral mappings defined in its datasheet.
//! This module encodes these mappings as traits, allowing:
//!
//! 1. **Compile-time verification**: Invalid pin assignments fail to compile
//! 2. **Automatic configuration**: Peripherals configure pins automatically
//! 3. **Ownership transfer**: Pins are consumed by peripherals, preventing reuse
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────────────┐
//! │                     Pin Trait Hierarchy                                  │
//! ├─────────────────────────────────────────────────────────────────────────┤
//! │                                                                         │
//! │  GpioPin (base trait)                                                   │
//! │      │                                                                  │
//! │      ├── I2c0SdaPin ──────► Pin<0>, Pin<4>, Pin<8>, Pin<12>, ...       │
//! │      ├── I2c0SclPin ──────► Pin<1>, Pin<5>, Pin<9>, Pin<13>, ...       │
//! │      ├── I2c1SdaPin ──────► Pin<2>, Pin<6>, Pin<10>, Pin<14>, ...      │
//! │      ├── I2c1SclPin ──────► Pin<3>, Pin<7>, Pin<11>, Pin<15>, ...      │
//! │      │                                                                  │
//! │      ├── Uart0TxPin ──────► Pin<0>, Pin<12>, Pin<16>, Pin<28>          │
//! │      ├── Uart0RxPin ──────► Pin<1>, Pin<13>, Pin<17>, Pin<29>          │
//! │      ├── ...                                                            │
//! │      │                                                                  │
//! │      ├── Spi0RxPin ───────► Pin<0>, Pin<4>, Pin<16>, Pin<20>           │
//! │      ├── ...                                                            │
//! │      │                                                                  │
//! │      └── PwmAPin<SLICE> ──► Slice-specific pins                        │
//! │                                                                         │
//! └─────────────────────────────────────────────────────────────────────────┘
//! ```
//!
//! # Usage Example
//!
//! ```ignore
//! use rp2350::gpio::{Pins, Pin};
//! use rp2350::i2c::I2c0;
//!
//! let dp = Peripherals::take().unwrap();
//! let pins = Pins::init(dp.IO_BANK0, dp.PADS_BANK0);
//!
//! // I2C0::new requires pins that implement I2c0SdaPin and I2c0SclPin
//! // Pin<4> implements I2c0SdaPin, Pin<5> implements I2c0SclPin
//! let i2c = I2c0::init(dp.I2C0, pins.pin::<4>(), pins.pin::<5>(), 400_000, sys_clk);
//!
//! // Compile error: Pin<3> does not implement I2c0SdaPin!
//! // let i2c = I2c0::init(dp.I2C0, pins.pin::<3>(), pins.pin::<5>(), 400_000, sys_clk);
//!
//! // Note: the `Pin<4>` value returned above was moved into `I2c0::init`.
//! // `pins.pin::<4>()` itself can be called again to obtain a fresh token.
//! ```

use super::{Function, Pin};

// ============================================================================
// I2C Pin Traits
// ============================================================================

/// Marker trait for pins that can be used as I2C0 SDA.
///
/// Valid pins: 0, 4, 8, 12, 16, 20, 24, 28 (RP2350A)
/// Additional: 32, 36, 40, 44 (RP2350B)
pub trait I2c0SdaPin {
    /// Configure this pin for I2C0 SDA function
    fn configure_i2c0_sda(&mut self);
}

/// Marker trait for pins that can be used as I2C0 SCL.
///
/// Valid pins: 1, 5, 9, 13, 17, 21, 25, 29 (RP2350A)
/// Additional: 33, 37, 41, 45 (RP2350B)
pub trait I2c0SclPin {
    /// Configure this pin for I2C0 SCL function
    fn configure_i2c0_scl(&mut self);
}

/// Marker trait for pins that can be used as I2C1 SDA.
///
/// Valid pins: 2, 6, 10, 14, 18, 22, 26 (RP2350A)
/// Additional: 30, 34, 38, 42, 46 (RP2350B)
pub trait I2c1SdaPin {
    /// Configure this pin for I2C1 SDA function
    fn configure_i2c1_sda(&mut self);
}

/// Marker trait for pins that can be used as I2C1 SCL.
///
/// Valid pins: 3, 7, 11, 15, 19, 23, 27 (RP2350A)
/// Additional: 31, 35, 39, 43, 47 (RP2350B)
pub trait I2c1SclPin {
    /// Configure this pin for I2C1 SCL function
    fn configure_i2c1_scl(&mut self);
}

/// Macro for implementing I2C pin traits
macro_rules! impl_i2c_pins {
    // I2C0 SDA
    (i2c0_sda: $($n:literal),+ $(,)?) => {
        $(
            impl I2c0SdaPin for Pin<$n> {
                #[inline]
                fn configure_i2c0_sda(&mut self) {
                    self.init_pad();
                    self.set_function(Function::I2c);
                    self.set_pull_up();  // I2C requires pull-up
                }
            }
        )+
    };
    // I2C0 SCL
    (i2c0_scl: $($n:literal),+ $(,)?) => {
        $(
            impl I2c0SclPin for Pin<$n> {
                #[inline]
                fn configure_i2c0_scl(&mut self) {
                    self.init_pad();
                    self.set_function(Function::I2c);
                    self.set_pull_up();  // I2C requires pull-up
                }
            }
        )+
    };
    // I2C1 SDA
    (i2c1_sda: $($n:literal),+ $(,)?) => {
        $(
            impl I2c1SdaPin for Pin<$n> {
                #[inline]
                fn configure_i2c1_sda(&mut self) {
                    self.init_pad();
                    self.set_function(Function::I2c);
                    self.set_pull_up();
                }
            }
        )+
    };
    // I2C1 SCL
    (i2c1_scl: $($n:literal),+ $(,)?) => {
        $(
            impl I2c1SclPin for Pin<$n> {
                #[inline]
                fn configure_i2c1_scl(&mut self) {
                    self.init_pad();
                    self.set_function(Function::I2c);
                    self.set_pull_up();
                }
            }
        )+
    };
}

// ============================================================================
// UART Pin Traits
// ============================================================================

/// Marker trait for pins that can be used as UART0 TX.
///
/// Valid pins: 0, 12, 16, 28 (RP2350A)
pub trait Uart0TxPin {
    /// Configure this pin for UART0 TX function
    fn configure_uart0_tx(&mut self);
}

/// Marker trait for pins that can be used as UART0 RX.
///
/// Valid pins: 1, 13, 17, 29 (RP2350A)
pub trait Uart0RxPin {
    /// Configure this pin for UART0 RX function
    fn configure_uart0_rx(&mut self);
}

/// Marker trait for pins that can be used as UART0 CTS.
///
/// Valid pins: 2, 14, 18 (RP2350A)
pub trait Uart0CtsPin {
    /// Configure this pin for UART0 CTS function
    fn configure_uart0_cts(&mut self);
}

/// Marker trait for pins that can be used as UART0 RTS.
///
/// Valid pins: 3, 15, 19 (RP2350A)
pub trait Uart0RtsPin {
    /// Configure this pin for UART0 RTS function
    fn configure_uart0_rts(&mut self);
}

/// Marker trait for pins that can be used as UART1 TX.
///
/// Valid pins: 4, 8, 20, 24 (RP2350A)
pub trait Uart1TxPin {
    /// Configure this pin for UART1 TX function
    fn configure_uart1_tx(&mut self);
}

/// Marker trait for pins that can be used as UART1 RX.
///
/// Valid pins: 5, 9, 21, 25 (RP2350A)
pub trait Uart1RxPin {
    /// Configure this pin for UART1 RX function
    fn configure_uart1_rx(&mut self);
}

/// Marker trait for pins that can be used as UART1 CTS.
///
/// Valid pins: 6, 10, 22, 26 (RP2350A)
pub trait Uart1CtsPin {
    /// Configure this pin for UART1 CTS function
    fn configure_uart1_cts(&mut self);
}

/// Marker trait for pins that can be used as UART1 RTS.
///
/// Valid pins: 7, 11, 23, 27 (RP2350A)
pub trait Uart1RtsPin {
    /// Configure this pin for UART1 RTS function
    fn configure_uart1_rts(&mut self);
}

/// Macro for implementing UART pin traits
macro_rules! impl_uart_pins {
    (uart0_tx: $($n:literal),+ $(,)?) => {
        $(
            impl Uart0TxPin for Pin<$n> {
                #[inline]
                fn configure_uart0_tx(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Uart);
                }
            }
        )+
    };
    (uart0_rx: $($n:literal),+ $(,)?) => {
        $(
            impl Uart0RxPin for Pin<$n> {
                #[inline]
                fn configure_uart0_rx(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Uart);
                }
            }
        )+
    };
    (uart0_cts: $($n:literal),+ $(,)?) => {
        $(
            impl Uart0CtsPin for Pin<$n> {
                #[inline]
                fn configure_uart0_cts(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Uart);
                }
            }
        )+
    };
    (uart0_rts: $($n:literal),+ $(,)?) => {
        $(
            impl Uart0RtsPin for Pin<$n> {
                #[inline]
                fn configure_uart0_rts(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Uart);
                }
            }
        )+
    };
    (uart1_tx: $($n:literal),+ $(,)?) => {
        $(
            impl Uart1TxPin for Pin<$n> {
                #[inline]
                fn configure_uart1_tx(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Uart);
                }
            }
        )+
    };
    (uart1_rx: $($n:literal),+ $(,)?) => {
        $(
            impl Uart1RxPin for Pin<$n> {
                #[inline]
                fn configure_uart1_rx(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Uart);
                }
            }
        )+
    };
    (uart1_cts: $($n:literal),+ $(,)?) => {
        $(
            impl Uart1CtsPin for Pin<$n> {
                #[inline]
                fn configure_uart1_cts(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Uart);
                }
            }
        )+
    };
    (uart1_rts: $($n:literal),+ $(,)?) => {
        $(
            impl Uart1RtsPin for Pin<$n> {
                #[inline]
                fn configure_uart1_rts(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Uart);
                }
            }
        )+
    };
}

// ============================================================================
// SPI Pin Traits
// ============================================================================

/// Marker trait for pins that can be used as SPI0 RX (MISO).
///
/// Valid pins: 0, 4, 16, 20 (RP2350A)
pub trait Spi0RxPin {
    /// Configure this pin for SPI0 RX function
    fn configure_spi0_rx(&mut self);
}

/// Marker trait for pins that can be used as SPI0 CSn (Chip Select).
///
/// Valid pins: 1, 5, 17, 21 (RP2350A)
pub trait Spi0CsnPin {
    /// Configure this pin for SPI0 CSn function
    fn configure_spi0_csn(&mut self);
}

/// Marker trait for pins that can be used as SPI0 SCK (Clock).
///
/// Valid pins: 2, 6, 18, 22 (RP2350A)
pub trait Spi0SckPin {
    /// Configure this pin for SPI0 SCK function
    fn configure_spi0_sck(&mut self);
}

/// Marker trait for pins that can be used as SPI0 TX (MOSI).
///
/// Valid pins: 3, 7, 19, 23 (RP2350A)
pub trait Spi0TxPin {
    /// Configure this pin for SPI0 TX function
    fn configure_spi0_tx(&mut self);
}

/// Marker trait for pins that can be used as SPI1 RX (MISO).
///
/// Valid pins: 8, 12, 24, 28 (RP2350A)
pub trait Spi1RxPin {
    /// Configure this pin for SPI1 RX function
    fn configure_spi1_rx(&mut self);
}

/// Marker trait for pins that can be used as SPI1 CSn (Chip Select).
///
/// Valid pins: 9, 13, 25, 29 (RP2350A)
pub trait Spi1CsnPin {
    /// Configure this pin for SPI1 CSn function
    fn configure_spi1_csn(&mut self);
}

/// Marker trait for pins that can be used as SPI1 SCK (Clock).
///
/// Valid pins: 10, 14, 26 (RP2350A)
pub trait Spi1SckPin {
    /// Configure this pin for SPI1 SCK function
    fn configure_spi1_sck(&mut self);
}

/// Marker trait for pins that can be used as SPI1 TX (MOSI).
///
/// Valid pins: 11, 15, 27 (RP2350A)
pub trait Spi1TxPin {
    /// Configure this pin for SPI1 TX function
    fn configure_spi1_tx(&mut self);
}

/// Macro for implementing SPI pin traits
macro_rules! impl_spi_pins {
    (spi0_rx: $($n:literal),+ $(,)?) => {
        $(
            impl Spi0RxPin for Pin<$n> {
                #[inline]
                fn configure_spi0_rx(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Spi);
                }
            }
        )+
    };
    (spi0_csn: $($n:literal),+ $(,)?) => {
        $(
            impl Spi0CsnPin for Pin<$n> {
                #[inline]
                fn configure_spi0_csn(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Spi);
                }
            }
        )+
    };
    (spi0_sck: $($n:literal),+ $(,)?) => {
        $(
            impl Spi0SckPin for Pin<$n> {
                #[inline]
                fn configure_spi0_sck(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Spi);
                }
            }
        )+
    };
    (spi0_tx: $($n:literal),+ $(,)?) => {
        $(
            impl Spi0TxPin for Pin<$n> {
                #[inline]
                fn configure_spi0_tx(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Spi);
                }
            }
        )+
    };
    (spi1_rx: $($n:literal),+ $(,)?) => {
        $(
            impl Spi1RxPin for Pin<$n> {
                #[inline]
                fn configure_spi1_rx(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Spi);
                }
            }
        )+
    };
    (spi1_csn: $($n:literal),+ $(,)?) => {
        $(
            impl Spi1CsnPin for Pin<$n> {
                #[inline]
                fn configure_spi1_csn(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Spi);
                }
            }
        )+
    };
    (spi1_sck: $($n:literal),+ $(,)?) => {
        $(
            impl Spi1SckPin for Pin<$n> {
                #[inline]
                fn configure_spi1_sck(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Spi);
                }
            }
        )+
    };
    (spi1_tx: $($n:literal),+ $(,)?) => {
        $(
            impl Spi1TxPin for Pin<$n> {
                #[inline]
                fn configure_spi1_tx(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Spi);
                }
            }
        )+
    };
}

// ============================================================================
// PWM Pin Traits
// ============================================================================

/// Marker trait for pins that can be used as PWM channel A.
///
/// The `SLICE` const parameter indicates the PWM slice number (0-11).
pub trait PwmAPin {
    /// The PWM slice number (0-11)
    const PWM_SLICE: u8;
    /// Configure this pin for PWM channel A function
    fn configure_pwm_a(&mut self);
}

/// Marker trait for pins that can be used as PWM channel B.
///
/// The `SLICE` const parameter indicates the PWM slice number (0-11).
pub trait PwmBPin {
    /// The PWM slice number (0-11)
    const PWM_SLICE: u8;
    /// Configure this pin for PWM channel B function
    fn configure_pwm_b(&mut self);
}

/// Macro for implementing PWM pin traits
macro_rules! impl_pwm_pins {
    (pwm_a: $slice:literal, $($n:literal),+ $(,)?) => {
        $(
            impl PwmAPin for Pin<$n> {
                const PWM_SLICE: u8 = $slice;
                #[inline]
                fn configure_pwm_a(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Pwm);
                }
            }
        )+
    };
    (pwm_b: $slice:literal, $($n:literal),+ $(,)?) => {
        $(
            impl PwmBPin for Pin<$n> {
                const PWM_SLICE: u8 = $slice;
                #[inline]
                fn configure_pwm_b(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Pwm);
                }
            }
        )+
    };
}

// ============================================================================
// PIO Pin Traits
// ============================================================================

/// Marker trait for pins that can be used with PIO0.
///
/// All GPIO pins support PIO. On RP2350A, pins 0-29 are available.
/// On RP2350B, pins 0-47 are available.
pub trait Pio0Pin {
    /// Configure this pin for PIO0 function
    fn configure_pio0(&mut self);
}

/// Marker trait for pins that can be used with PIO1.
pub trait Pio1Pin {
    /// Configure this pin for PIO1 function
    fn configure_pio1(&mut self);
}

/// Marker trait for pins that can be used with PIO2.
pub trait Pio2Pin {
    /// Configure this pin for PIO2 function
    fn configure_pio2(&mut self);
}

/// Macro for implementing PIO pin traits
macro_rules! impl_pio_pins {
    (pio0: $($n:literal),+ $(,)?) => {
        $(
            impl Pio0Pin for Pin<$n> {
                #[inline]
                fn configure_pio0(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Pio0);
                }
            }
        )+
    };
    (pio1: $($n:literal),+ $(,)?) => {
        $(
            impl Pio1Pin for Pin<$n> {
                #[inline]
                fn configure_pio1(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Pio1);
                }
            }
        )+
    };
    (pio2: $($n:literal),+ $(,)?) => {
        $(
            impl Pio2Pin for Pin<$n> {
                #[inline]
                fn configure_pio2(&mut self) {
                    self.init_pad();
                    self.set_function(Function::Pio2);
                }
            }
        )+
    };
}

// I2C0 pins (RP2350A)
// SDA: Pins where (pin_num % 4 == 0)
// SCL: Pins where (pin_num % 4 == 1)
impl_i2c_pins!(i2c0_sda: 0, 4, 8, 12, 16, 20, 24, 28);
impl_i2c_pins!(i2c0_scl: 1, 5, 9, 13, 17, 21, 25, 29);

// I2C1 pins (RP2350A)
// SDA: Pins where (pin_num % 4 == 2)
// SCL: Pins where (pin_num % 4 == 3)
impl_i2c_pins!(i2c1_sda: 2, 6, 10, 14, 18, 22, 26);
impl_i2c_pins!(i2c1_scl: 3, 7, 11, 15, 19, 23, 27);

// UART0 pins (RP2350A)
impl_uart_pins!(uart0_tx: 0, 12, 16, 28);
impl_uart_pins!(uart0_rx: 1, 13, 17, 29);
impl_uart_pins!(uart0_cts: 2, 14, 18);
impl_uart_pins!(uart0_rts: 3, 15, 19);

// UART1 pins (RP2350A)
impl_uart_pins!(uart1_tx: 4, 8, 20, 24);
impl_uart_pins!(uart1_rx: 5, 9, 21, 25);
impl_uart_pins!(uart1_cts: 6, 10, 22, 26);
impl_uart_pins!(uart1_rts: 7, 11, 23, 27);

// SPI0 pins (RP2350A)
impl_spi_pins!(spi0_rx: 0, 4, 16, 20);
impl_spi_pins!(spi0_csn: 1, 5, 17, 21);
impl_spi_pins!(spi0_sck: 2, 6, 18, 22);
impl_spi_pins!(spi0_tx: 3, 7, 19, 23);

// SPI1 pins (RP2350A)
impl_spi_pins!(spi1_rx: 8, 12, 24, 28);
impl_spi_pins!(spi1_csn: 9, 13, 25, 29);
impl_spi_pins!(spi1_sck: 10, 14, 26);
impl_spi_pins!(spi1_tx: 11, 15, 27);

// PWM pins (RP2350A) - slices 0-7
// Each slice has two channels: A (even pins) and B (odd pins)
// Slice = (pin_num / 2) % 8
impl_pwm_pins!(pwm_a: 0, 0, 16);
impl_pwm_pins!(pwm_b: 0, 1, 17);
impl_pwm_pins!(pwm_a: 1, 2, 18);
impl_pwm_pins!(pwm_b: 1, 3, 19);
impl_pwm_pins!(pwm_a: 2, 4, 20);
impl_pwm_pins!(pwm_b: 2, 5, 21);
impl_pwm_pins!(pwm_a: 3, 6, 22);
impl_pwm_pins!(pwm_b: 3, 7, 23);
impl_pwm_pins!(pwm_a: 4, 8, 24);
impl_pwm_pins!(pwm_b: 4, 9, 25);
impl_pwm_pins!(pwm_a: 5, 10, 26);
impl_pwm_pins!(pwm_b: 5, 11, 27);
impl_pwm_pins!(pwm_a: 6, 12, 28);
impl_pwm_pins!(pwm_b: 6, 13, 29);
impl_pwm_pins!(pwm_a: 7, 14);
impl_pwm_pins!(pwm_b: 7, 15);

// ============================================================================
// RP2350A Pin Mappings (30 GPIO pins: 0-29)
// Based on RP2350 datasheet Table 294
// ============================================================================

// PIO pins (RP2350A) — all GPIO pins support all PIO blocks
impl_pio_pins!(pio0: 0, 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);
impl_pio_pins!(pio1: 0, 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);
impl_pio_pins!(pio2: 0, 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);

// ============================================================================
// RP2350B Additional Pin Mappings (pins 30-47)
// ============================================================================

#[cfg(feature = "rp2350b")]
mod rp2350b_pins {
    use super::*;

    // Additional I2C0 pins for RP2350B
    impl_i2c_pins!(i2c0_sda: 32, 36, 40, 44);
    impl_i2c_pins!(i2c0_scl: 33, 37, 41, 45);

    // Additional I2C1 pins for RP2350B
    impl_i2c_pins!(i2c1_sda: 30, 34, 38, 42, 46);
    impl_i2c_pins!(i2c1_scl: 31, 35, 39, 43, 47);

    // Additional UART0 pins for RP2350B
    impl_uart_pins!(uart0_tx: 32, 44);
    impl_uart_pins!(uart0_rx: 33, 45);
    impl_uart_pins!(uart0_cts: 34, 46);
    impl_uart_pins!(uart0_rts: 35, 47);

    // Additional UART1 pins for RP2350B
    impl_uart_pins!(uart1_tx: 36, 40);
    impl_uart_pins!(uart1_rx: 37, 41);
    impl_uart_pins!(uart1_cts: 38, 42);
    impl_uart_pins!(uart1_rts: 39, 43);

    // Additional SPI0 pins for RP2350B
    impl_spi_pins!(spi0_rx: 32, 36);
    impl_spi_pins!(spi0_csn: 33, 37);
    impl_spi_pins!(spi0_sck: 34, 38);
    impl_spi_pins!(spi0_tx: 35, 39);

    // Additional SPI1 pins for RP2350B
    impl_spi_pins!(spi1_rx: 40, 44);
    impl_spi_pins!(spi1_csn: 41, 45);
    impl_spi_pins!(spi1_sck: 42, 46);
    impl_spi_pins!(spi1_tx: 43, 47);

    // Additional PWM pins for RP2350B - slices 7-11
    impl_pwm_pins!(pwm_a: 7, 30);
    impl_pwm_pins!(pwm_b: 7, 31);
    impl_pwm_pins!(pwm_a: 8, 32, 40);
    impl_pwm_pins!(pwm_b: 8, 33, 41);
    impl_pwm_pins!(pwm_a: 9, 34, 42);
    impl_pwm_pins!(pwm_b: 9, 35, 43);
    impl_pwm_pins!(pwm_a: 10, 36, 44);
    impl_pwm_pins!(pwm_b: 10, 37, 45);
    impl_pwm_pins!(pwm_a: 11, 38, 46);
    impl_pwm_pins!(pwm_b: 11, 39, 47);

    // Additional PIO pins for RP2350B (pins 30-47, all PIO blocks)
    impl_pio_pins!(pio0: 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
                         40, 41, 42, 43, 44, 45, 46, 47);
    impl_pio_pins!(pio1: 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
                         40, 41, 42, 43, 44, 45, 46, 47);
    impl_pio_pins!(pio2: 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
                         40, 41, 42, 43, 44, 45, 46, 47);
}

/// ErasedPin — placeholder for unused or type-erased peripheral pins.
///
/// Use `ErasedPin` when a peripheral API requires a pin you don't need,
/// or when obtaining a pin-erased handle via `steal()`.
///
/// # Placeholder
///
/// - PWM: only one channel → pass `ErasedPin` for the other
/// - SPI TX-only: no RX needed → pass `ErasedPin` for RX
/// - SPI RX-only: no TX needed → pass `ErasedPin` for TX
///
/// # Type erasure
///
/// `steal()` methods return handles parameterised with `ErasedPin` so that
/// the concrete pin types are not required in ISR or global-storage context.
///
/// ```ignore
/// use rp2350::gpio::pins::ErasedPin;
/// use rp2350::spi::Spi0;
///
/// // TX-only SPI: no MISO pin needed
/// let spi = Spi0::init(dp.SPI0, sck_pin, tx_pin, ErasedPin, 1_000_000, sys_clk);
/// ```
pub struct ErasedPin;

// PWM
impl PwmAPin for ErasedPin {
    const PWM_SLICE: u8 = 255;
    fn configure_pwm_a(&mut self) {}
}

impl PwmBPin for ErasedPin {
    const PWM_SLICE: u8 = 255;
    fn configure_pwm_b(&mut self) {}
}

// SPI0
impl Spi0RxPin for ErasedPin {
    fn configure_spi0_rx(&mut self) {}
}
impl Spi0TxPin for ErasedPin {
    fn configure_spi0_tx(&mut self) {}
}
impl Spi0CsnPin for ErasedPin {
    fn configure_spi0_csn(&mut self) {}
}

// SPI0 SCK
impl Spi0SckPin for ErasedPin {
    fn configure_spi0_sck(&mut self) {}
}

// SPI1
impl Spi1RxPin for ErasedPin {
    fn configure_spi1_rx(&mut self) {}
}
impl Spi1TxPin for ErasedPin {
    fn configure_spi1_tx(&mut self) {}
}
impl Spi1CsnPin for ErasedPin {
    fn configure_spi1_csn(&mut self) {}
}
impl Spi1SckPin for ErasedPin {
    fn configure_spi1_sck(&mut self) {}
}

// UART0
impl Uart0TxPin for ErasedPin {
    fn configure_uart0_tx(&mut self) {}
}
impl Uart0RxPin for ErasedPin {
    fn configure_uart0_rx(&mut self) {}
}
impl Uart0CtsPin for ErasedPin {
    fn configure_uart0_cts(&mut self) {}
}
impl Uart0RtsPin for ErasedPin {
    fn configure_uart0_rts(&mut self) {}
}

// UART1
impl Uart1TxPin for ErasedPin {
    fn configure_uart1_tx(&mut self) {}
}
impl Uart1RxPin for ErasedPin {
    fn configure_uart1_rx(&mut self) {}
}
impl Uart1CtsPin for ErasedPin {
    fn configure_uart1_cts(&mut self) {}
}
impl Uart1RtsPin for ErasedPin {
    fn configure_uart1_rts(&mut self) {}
}

// I2C0
impl I2c0SdaPin for ErasedPin {
    fn configure_i2c0_sda(&mut self) {}
}
impl I2c0SclPin for ErasedPin {
    fn configure_i2c0_scl(&mut self) {}
}

// I2C1
impl I2c1SdaPin for ErasedPin {
    fn configure_i2c1_sda(&mut self) {}
}
impl I2c1SclPin for ErasedPin {
    fn configure_i2c1_scl(&mut self) {}
}