Skip to content

Commit a4039bf

Browse files
committed
Port pygamer to the v2 APIs
Port the pygamer BSP to the `gpio::v2` and `sercom::v2::spi` APIs. While implementing this, I discovered that the pygamer uses an undocumented combination of pins for `Sercom1`. It uses PA17, PB22 & PB23. The datasheet indicates that PA17 is in `IoSet1`, while the other two pins are in `IoSet3`. It shouldn't be possible to use these together, but it appears there is an undocumented `IoSet`. Add this as `IoSet5` for `Sercom1`. Also fix a warning from a trinket_m0 example.
1 parent 558d677 commit a4039bf

24 files changed

+494
-406
lines changed

boards/pygamer/examples/blinky_basic.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#![no_std]
44
#![no_main]
55

6+
use bsp::{entry, hal, pac, Pins, RedLed};
67
#[cfg(not(feature = "panic_led"))]
78
use panic_halt as _;
8-
use pygamer::{self as hal, entry, pac, Pins};
9+
use pygamer as bsp;
910

1011
use hal::clock::GenericClockController;
1112
use hal::delay::Delay;
@@ -27,8 +28,8 @@ fn main() -> ! {
2728
let mut delay = Delay::new(core.SYST, &mut clocks);
2829
delay.delay_ms(400u16);
2930

30-
let mut pins = Pins::new(peripherals.PORT);
31-
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
31+
let pins = Pins::new(peripherals.PORT);
32+
let mut red_led: RedLed = pins.d13.into();
3233

3334
let mut wdt = Watchdog::new(peripherals.WDT);
3435
wdt.start(WatchdogTimeout::Cycles256 as u8);

boards/pygamer/examples/button_rtic.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#![no_std]
22
#![no_main]
33

4+
use bsp::{hal, ButtonReader, Keys, Pins, RedLed};
45
#[cfg(not(feature = "panic_led"))]
56
use panic_halt as _;
6-
use pygamer::{self as hal, pins::ButtonReader, pins::Keys, Pins};
7+
use pygamer as bsp;
78

89
use hal::clock::GenericClockController;
9-
use hal::gpio::{OpenDrain, Output, Pa23};
1010
use hal::prelude::*;
1111
use rtic::app;
1212

1313
#[app(device = crate::hal::pac, peripherals = true)]
1414
const APP: () = {
1515
struct Resources {
16-
red_led: Pa23<Output<OpenDrain>>,
16+
red_led: RedLed,
1717
timer: hal::timer::TimerCounter3,
1818
buttons: ButtonReader,
1919
}
@@ -50,7 +50,7 @@ const APP: () = {
5050
&mut device.NVMCTRL,
5151
);
5252

53-
let mut pins = Pins::new(device.PORT).split();
53+
let pins = Pins::new(device.PORT).split();
5454

5555
let gclk0 = clocks.gclk0();
5656
let timer_clock = clocks.tc2_tc3(&gclk0).unwrap();
@@ -61,8 +61,8 @@ const APP: () = {
6161
tc3.enable_interrupt();
6262

6363
init::LateResources {
64-
buttons: pins.buttons.init(&mut pins.port),
65-
red_led: pins.led_pin.into_open_drain_output(&mut pins.port),
64+
buttons: pins.buttons.init(),
65+
red_led: pins.led_pin,
6666
timer: tc3,
6767
}
6868
}

boards/pygamer/examples/clock_out.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
#![no_std]
44
#![no_main]
55

6+
use bsp::{entry, hal, pac, Pins};
67
#[cfg(not(feature = "panic_led"))]
78
use panic_halt as _;
8-
use pygamer::{self as hal, entry, pac, Pins};
9+
use pygamer as bsp;
910

1011
use hal::clock::GenericClockController;
12+
use hal::gpio::v2::AlternateM;
1113
use pac::gclk::genctrl::SRC_A::DPLL0;
1214
use pac::gclk::pchctrl::GEN_A::GCLK2;
1315
use pac::Peripherals;
@@ -22,12 +24,12 @@ fn main() -> ! {
2224
&mut peripherals.OSCCTRL,
2325
&mut peripherals.NVMCTRL,
2426
);
25-
let mut pins = Pins::new(peripherals.PORT);
27+
let pins = Pins::new(peripherals.PORT);
2628

2729
//3mhz
2830
let _gclk2 = clocks
2931
.configure_gclk_divider_and_source(GCLK2, 40, DPLL0, false)
3032
.unwrap();
31-
pins.d5.into_function_m(&mut pins.port);
33+
pins.d5.into_mode::<AlternateM>();
3234
loop {}
3335
}

boards/pygamer/examples/ferris_img.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
#![no_std]
1111
#![no_main]
1212

13+
use bsp::{entry, hal, pac, Pins};
1314
#[cfg(not(feature = "panic_led"))]
1415
use panic_halt as _;
15-
use pygamer::{self as hal, entry, pac, Pins};
16+
use pygamer as bsp;
1617

1718
use embedded_graphics::pixelcolor::{Rgb565, RgbColor};
1819
use embedded_graphics::prelude::*;
@@ -32,7 +33,7 @@ fn main() -> ! {
3233
&mut peripherals.OSCCTRL,
3334
&mut peripherals.NVMCTRL,
3435
);
35-
let mut pins = Pins::new(peripherals.PORT).split();
36+
let pins = Pins::new(peripherals.PORT).split();
3637
let mut delay = hal::delay::Delay::new(core.SYST, &mut clocks);
3738

3839
let (mut display, _backlight) = pins
@@ -43,7 +44,6 @@ fn main() -> ! {
4344
&mut peripherals.MCLK,
4445
peripherals.TC2,
4546
&mut delay,
46-
&mut pins.port,
4747
)
4848
.unwrap();
4949

boards/pygamer/examples/neopixel_adc_battery.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#![no_std]
77
#![no_main]
88

9+
use bsp::{entry, hal, pac, Pins};
910
#[cfg(not(feature = "panic_led"))]
1011
use panic_halt as _;
11-
use pygamer::{self as hal, entry, pac, Pins};
12+
use pygamer as bsp;
1213

1314
use hal::adc::Adc;
1415
use hal::pac::gclk::pchctrl::GEN_A::GCLK11;
@@ -29,14 +30,14 @@ fn main() -> ! {
2930
&mut peripherals.OSCCTRL,
3031
&mut peripherals.NVMCTRL,
3132
);
32-
let mut pins = Pins::new(peripherals.PORT).split();
33+
let pins = Pins::new(peripherals.PORT).split();
3334

3435
let mut adc0 = Adc::adc0(peripherals.ADC0, &mut peripherals.MCLK, &mut clocks, GCLK11);
35-
let mut battery = pins.battery.init(&mut pins.port);
36+
let mut battery = pins.battery.init();
3637

3738
// neopixels
3839
let timer = SpinTimer::new(4);
39-
let mut neopixel = pins.neopixel.init(timer, &mut pins.port);
40+
let mut neopixel = pins.neopixel.init(timer);
4041

4142
let mut delay = Delay::new(core.SYST, &mut clocks);
4243

boards/pygamer/examples/neopixel_adc_light.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
#![no_std]
77
#![no_main]
88

9+
use bsp::{entry, hal, pac, Pins};
910
#[cfg(not(feature = "panic_led"))]
1011
use panic_halt as _;
11-
use pygamer::{self as hal, entry, pac, Pins};
12+
use pygamer as bsp;
1213

1314
use embedded_hal::digital::v1_compat::OldOutputPin;
1415
use hal::adc::Adc;
16+
use hal::gpio::v2::AlternateB;
1517
use hal::prelude::*;
1618
use hal::timer::SpinTimer;
1719
use hal::{clock::GenericClockController, delay::Delay};
@@ -32,13 +34,13 @@ fn main() -> ! {
3234
&mut peripherals.OSCCTRL,
3335
&mut peripherals.NVMCTRL,
3436
);
35-
let mut pins = Pins::new(peripherals.PORT);
37+
let pins = Pins::new(peripherals.PORT);
3638

3739
let mut adc1 = Adc::adc1(peripherals.ADC1, &mut peripherals.MCLK, &mut clocks, GCLK11);
38-
let mut light = pins.light.into_function_b(&mut pins.port);
40+
let mut light = pins.light.into_mode::<AlternateB>();
3941

4042
let timer = SpinTimer::new(4);
41-
let neopixel_pin: OldOutputPin<_> = pins.neopixel.into_push_pull_output(&mut pins.port).into();
43+
let neopixel_pin: OldOutputPin<_> = pins.neopixel.into_push_pull_output().into();
4244
let mut neopixel = ws2812::Ws2812::new(timer, neopixel_pin);
4345

4446
let mut delay = Delay::new(core.SYST, &mut clocks);

boards/pygamer/examples/neopixel_button.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
#![no_std]
1111
#![no_main]
1212

13+
use bsp::{entry, hal, pac, Keys, Pins};
1314
#[cfg(not(feature = "panic_led"))]
1415
use panic_halt as _;
15-
use pygamer::{self as hal, entry, pac, pins::Keys, Pins};
16+
use pygamer as bsp;
1617

18+
use bsp::util::map_from;
1719
use hal::adc::Adc;
1820
use hal::prelude::*;
1921
use hal::timer::SpinTimer;
20-
use hal::util::map_from;
2122
use hal::{clock::GenericClockController, delay::Delay};
2223
use pac::gclk::pchctrl::GEN_A::GCLK11;
2324
use pac::{CorePeripherals, Peripherals};
@@ -38,17 +39,17 @@ fn main() -> ! {
3839
);
3940

4041
let mut delay = Delay::new(core_peripherals.SYST, &mut clocks);
41-
let mut pins = Pins::new(peripherals.PORT).split();
42+
let pins = Pins::new(peripherals.PORT).split();
4243

43-
let mut buttons = pins.buttons.init(&mut pins.port);
44+
let mut buttons = pins.buttons.init();
4445

4546
let mut adc1 = Adc::adc1(peripherals.ADC1, &mut peripherals.MCLK, &mut clocks, GCLK11);
46-
let mut joystick = pins.joystick.init(&mut pins.port);
47+
let mut joystick = pins.joystick.init();
4748

4849
// neopixels
4950
let timer = SpinTimer::new(4);
5051

51-
let mut neopixel = pins.neopixel.init(timer, &mut pins.port);
52+
let mut neopixel = pins.neopixel.init(timer);
5253

5354
const NUM_LEDS: usize = 5;
5455
let mut pos_button: usize = 2;

boards/pygamer/examples/neopixel_easing.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#![no_std]
77
#![no_main]
88

9+
use bsp::{entry, hal, pac, Pins};
910
#[cfg(not(feature = "panic_led"))]
1011
use panic_halt as _;
11-
use pygamer::{self as hal, entry, pac, Pins};
12+
use pygamer as bsp;
1213

1314
use core::f32::consts::FRAC_PI_2;
1415
use hal::clock::GenericClockController;
@@ -33,10 +34,10 @@ fn main() -> ! {
3334
&mut peripherals.NVMCTRL,
3435
);
3536

36-
let mut pins = Pins::new(peripherals.PORT).split();
37+
let pins = Pins::new(peripherals.PORT).split();
3738
let timer = SpinTimer::new(4);
3839

39-
let mut neopixel = pins.neopixel.init(timer, &mut pins.port);
40+
let mut neopixel = pins.neopixel.init(timer);
4041
let mut delay = Delay::new(core.SYST, &mut clocks);
4142

4243
let trng = Trng::new(&mut peripherals.MCLK, peripherals.TRNG);

boards/pygamer/examples/neopixel_rainbow_spi.rs

+14-27
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
#![no_std]
88
#![no_main]
99

10+
use bsp::{entry, hal, pac, Pins};
1011
#[cfg(not(feature = "panic_led"))]
1112
use panic_halt as _;
12-
use pygamer::{self as hal, entry, pac, Pins};
13+
use pygamer as bsp;
1314

1415
use hal::prelude::*;
15-
use hal::sercom::PadPin;
16-
use hal::time::MegaHertz;
16+
use hal::sercom::v2::spi;
1717
use hal::{clock::GenericClockController, delay::Delay};
1818
use pac::{CorePeripherals, Peripherals};
1919
use smart_leds::hsv::{hsv2rgb, Hsv};
@@ -31,32 +31,20 @@ fn main() -> ! {
3131
&mut peripherals.OSCCTRL,
3232
&mut peripherals.NVMCTRL,
3333
);
34-
let mut pins = Pins::new(peripherals.PORT);
34+
let pins = Pins::new(peripherals.PORT);
35+
let mclk = &mut peripherals.MCLK;
3536
let gclk = clocks.gclk0();
36-
37-
let spi: hal::sercom::SPIMaster2<
38-
hal::sercom::Sercom2Pad0<hal::gpio::Pa12<hal::gpio::PfC>>,
39-
hal::sercom::Sercom2Pad3<hal::gpio::Pa15<hal::gpio::PfC>>,
40-
hal::sercom::Sercom2Pad1<hal::gpio::Pa13<hal::gpio::PfC>>,
41-
> = hal::sercom::SPIMaster2::new(
42-
&clocks.sercom2_core(&gclk).unwrap(),
43-
MegaHertz(3),
44-
embedded_hal::spi::Mode {
45-
phase: embedded_hal::spi::Phase::CaptureOnFirstTransition,
46-
polarity: embedded_hal::spi::Polarity::IdleLow,
47-
},
48-
peripherals.SERCOM2,
49-
&mut peripherals.MCLK,
50-
(
51-
pins.sda.into_pad(&mut pins.port),
52-
pins.neopixel.into_pad(&mut pins.port),
53-
pins.scl.into_pad(&mut pins.port),
54-
),
55-
);
56-
37+
let clock = &clocks.sercom2_core(&gclk).unwrap();
38+
let sercom2 = peripherals.SERCOM2;
39+
let pads = spi::Pads::default()
40+
.data_in(pins.sda)
41+
.data_out(pins.neopixel)
42+
.sclk(pins.scl);
43+
let spi = spi::Config::new(mclk, sercom2, pads, clock.freq())
44+
.baud(3.mhz())
45+
.enable();
5746
let mut neopixel = ws2812::Ws2812::new(spi);
5847
let mut delay = Delay::new(core.SYST, &mut clocks);
59-
6048
loop {
6149
for j in 0..255u8 {
6250
let colors = [
@@ -88,7 +76,6 @@ fn main() -> ! {
8876
val: 32,
8977
}),
9078
];
91-
9279
neopixel.write(colors.iter().cloned()).unwrap();
9380
delay.delay_ms(5u8);
9481
}

boards/pygamer/examples/neopixel_rainbow_timer.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#![no_std]
1010
#![no_main]
1111

12+
use bsp::{entry, hal, Pins};
1213
#[cfg(not(feature = "panic_led"))]
1314
use panic_halt as _;
14-
use pygamer::{self as hal, entry, Pins};
15+
use pygamer as bsp;
1516

1617
use hal::pac::{CorePeripherals, Peripherals};
1718
use hal::prelude::*;
@@ -30,14 +31,14 @@ fn main() -> ! {
3031
&mut peripherals.OSCCTRL,
3132
&mut peripherals.NVMCTRL,
3233
);
33-
let mut pins = Pins::new(peripherals.PORT).split();
34+
let pins = Pins::new(peripherals.PORT).split();
3435

3536
let gclk0 = clocks.gclk0();
3637
let timer_clock = clocks.tc2_tc3(&gclk0).unwrap();
3738
let mut timer = TimerCounter::tc3_(&timer_clock, peripherals.TC3, &mut peripherals.MCLK);
3839
timer.start(3.mhz());
3940

40-
let mut neopixel = pins.neopixel.init(timer, &mut pins.port);
41+
let mut neopixel = pins.neopixel.init(timer);
4142
let mut delay = Delay::new(core.SYST, &mut clocks);
4243

4344
loop {

boards/pygamer/examples/neopixel_tilt.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
#![no_std]
88
#![no_main]
99

10+
use bsp::{entry, hal, pac, Pins};
1011
#[cfg(not(feature = "panic_led"))]
1112
use panic_halt as _;
12-
use pygamer::{self as hal, entry, pac, Pins};
13+
use pygamer as bsp;
1314

1415
use hal::prelude::*;
1516
use hal::time::KiloHertz;
@@ -34,19 +35,18 @@ fn main() -> ! {
3435
);
3536

3637
let mut delay = Delay::new(core_peripherals.SYST, &mut clocks);
37-
let mut pins = Pins::new(peripherals.PORT).split();
38+
let pins = Pins::new(peripherals.PORT).split();
3839

3940
// neopixels
4041
let timer = SpinTimer::new(4);
41-
let mut neopixel = pins.neopixel.init(timer, &mut pins.port);
42+
let mut neopixel = pins.neopixel.init(timer);
4243

4344
// i2c
4445
let i2c = pins.i2c.init(
4546
&mut clocks,
4647
KiloHertz(400),
4748
peripherals.SERCOM2,
4849
&mut peripherals.MCLK,
49-
&mut pins.port,
5050
);
5151

5252
let mut lis3dh = Lis3dh::new(i2c, 0x19).unwrap();

0 commit comments

Comments
 (0)