Skip to content

Commit

Permalink
pygamer: Update HAL 0.14->0.17
Browse files Browse the repository at this point in the history
This leaves NeoPixel examples in a broken state, it appears work will
need to be done in WS2812 crates and/or the HAL to get timing working
again.
  • Loading branch information
ianrrees committed Sep 6, 2024
1 parent a6d03b6 commit 363f1f5
Show file tree
Hide file tree
Showing 19 changed files with 278 additions and 186 deletions.
1 change: 1 addition & 0 deletions boards/pygamer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- update HAL v0.14 -> v0.17 and other dependencies, fix examples
- update path of Cargo config

# v0.9.0
Expand Down
19 changes: 12 additions & 7 deletions boards/pygamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edition = "2021"
exclude = ["assets"]

[dependencies]
cortex-m = "0.7"
cortex-m = {version = "0.7", features = ["critical-section-single-core"]}
st7735-lcd = "0.8.1"
ws2812-timer-delay = "0.3"

Expand All @@ -24,25 +24,27 @@ version = "0.7"
optional = true

[dependencies.atsamd-hal]
version = "0.14"
version = "0.17"
default-features = false

[dependencies.micromath]
version = "0.5.1"
optional = true

[dependencies.embedded-sdmmc]
version = "0.3.0"
version = "0.8.0"
optional = true

[dependencies.usb-device]
version = "0.2"
version = "0.3.1"
optional = true

[dev-dependencies]
usbd-serial = "0.1"
usbd-serial = "0.2"
panic-halt = "0.2"
embedded-graphics = "0.7.1"
embedded-hal-02 = {package = "embedded-hal", version = "0.2", features = ["unproven"]}
embedded-hal-bus = "0.2.0"
smart-leds = "0.3"
ws2812-spi = { version = "0.4.0", features = ["mosi_idle_high"] }
lis3dh = "0.1.0"
Expand All @@ -51,9 +53,8 @@ tinybmp = "0.3.1"

[features]
# ask the HAL to enable atsamd51j support
default = ["rt", "atsamd-hal/samd51j", "unproven"]
default = ["rt", "atsamd-hal/samd51j"]
rt = ["cortex-m-rt", "atsamd-hal/samd51j-rt"]
unproven = ["atsamd-hal/unproven"]
usb = ["atsamd-hal/usb", "usb-device"]
sd-card = ["embedded-sdmmc"]
math = ["micromath"]
Expand All @@ -69,6 +70,10 @@ lto = "thin" # thin for debug speed
lto = "fat"
opt-level = 's'

# Optimize dependencies for size
[profile.dev.package."*"]
opt-level = "s"

# for cargo flash
[package.metadata]
chip = "ATSAMD51J19A"
Expand Down
30 changes: 20 additions & 10 deletions boards/pygamer/examples/button_rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ use pygamer as bsp;

use hal::clock::GenericClockController;
use hal::prelude::*;
use hal::time::Hertz;
use hal::timer::TimerCounter;
use rtic::app;

#[app(device = crate::hal::pac, peripherals = true)]
const APP: () = {
mod app {
use super::*;

#[local]
struct Resources {
red_led: RedLed,
timer: hal::timer::TimerCounter3,
Expand All @@ -27,7 +32,7 @@ const APP: () = {
/// period.
#[task(binds = TC3, local = [timer, red_led, buttons])]
fn tc3(c: tc3::Context) {
if c.local.timer.wait().is_ok() {
if InterruptDrivenTimer::wait(c.local.timer).is_ok() {
for event in c.local.buttons.events() {
match event {
Keys::SelectDown => {
Expand All @@ -43,7 +48,7 @@ const APP: () = {
}

#[init]
fn init(c: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(c: init::Context) -> (Shared, Resources, init::Monotonics) {
let mut device = c.device;
let mut clocks = GenericClockController::with_internal_32kosc(
device.GCLK,
Expand All @@ -58,15 +63,20 @@ const APP: () = {
let gclk0 = clocks.gclk0();
let timer_clock = clocks.tc2_tc3(&gclk0).unwrap();

let mut tc3 = bsp::timer::TimerCounter::tc3_(&timer_clock, device.TC3, &mut device.MCLK);
let mut tc3 = TimerCounter::tc3_(&timer_clock, device.TC3, &mut device.MCLK);

InterruptDrivenTimer::start(&mut tc3, Hertz::Hz(200).into_duration());

tc3.start(200.hz());
tc3.enable_interrupt();

init::LateResources {
buttons: pins.buttons.init(),
red_led: pins.led_pin.into(),
timer: tc3,
}
(
Shared {},
Resources {
buttons: pins.buttons.init(),
red_led: pins.led_pin.into(),
timer: tc3,
},
init::Monotonics(),
)
}
}
11 changes: 5 additions & 6 deletions boards/pygamer/examples/clock_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
#![no_std]
#![no_main]

use bsp::{entry, hal, pac, Pins};
use bsp::{entry, hal, pac, GclkOut, Pins};
#[cfg(not(feature = "panic_led"))]
use panic_halt as _;
use pygamer as bsp;

use hal::clock::GenericClockController;
use hal::gpio::v2::AlternateM;
use pac::gclk::genctrl::SRC_A::DPLL0;
use pac::gclk::pchctrl::GEN_A::GCLK2;
use pac::gclk::genctrl::SRCSELECT_A::DPLL0;
use pac::gclk::pchctrl::GENSELECT_A::GCLK2;
use pac::Peripherals;

#[entry]
Expand All @@ -26,10 +25,10 @@ fn main() -> ! {
);
let pins = Pins::new(peripherals.PORT);

//3mhz
// Output 3 MHz clock on pin d5
let _gclk2 = clocks
.configure_gclk_divider_and_source(GCLK2, 40, DPLL0, false)
.unwrap();
pins.d5.into_mode::<AlternateM>();
let _clock_out_pin: GclkOut = pins.d5.into();
loop {}
}
9 changes: 4 additions & 5 deletions boards/pygamer/examples/neopixel_adc_battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ use panic_halt as _;
use pygamer as bsp;

use hal::adc::Adc;
use hal::pac::gclk::pchctrl::GEN_A::GCLK11;
use hal::pac::gclk::pchctrl::GENSELECT_A::GCLK11;
use hal::prelude::*;
use hal::timer::SpinTimer;
use hal::{clock::GenericClockController, delay::Delay};
use pac::{CorePeripherals, Peripherals};
use smart_leds::{brightness, hsv::RGB8, SmartLedsWrite};
Expand All @@ -35,9 +34,9 @@ fn main() -> ! {
let mut adc0 = Adc::adc0(peripherals.ADC0, &mut peripherals.MCLK, &mut clocks, GCLK11);
let mut battery = pins.battery.init();

// neopixels
let timer = SpinTimer::new(4);
let mut neopixel = pins.neopixel.init(timer);
let mut neopixel = pins
.neopixel
.init(&mut clocks, peripherals.TC4, &mut peripherals.MCLK);

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

Expand Down
27 changes: 17 additions & 10 deletions boards/pygamer/examples/neopixel_adc_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
#![no_std]
#![no_main]

use bsp::{entry, hal, pac, Pins};
use bsp::{entry, hal, pac, LightSensor, Pins};
#[cfg(not(feature = "panic_led"))]
use panic_halt as _;
use pygamer as bsp;

use embedded_hal_02::adc::OneShot;
use hal::adc::Adc;
use hal::gpio::v2::AlternateB;
use hal::prelude::*;
use hal::timer::SpinTimer;
use hal::{clock::GenericClockController, delay::Delay};
use pac::gclk::pchctrl::GEN_A::GCLK11;
use hal::clock::GenericClockController;
use hal::delay::Delay;
use hal::ehal::delay::DelayNs;
use hal::time::Hertz;
use hal::timer::TimerCounter;
use hal::timer_traits::InterruptDrivenTimer;
use pac::gclk::pchctrl::GENSELECT_A::GCLK11;
use pac::{CorePeripherals, Peripherals};
use smart_leds::hsv::{hsv2rgb, Hsv, RGB8};
use smart_leds::SmartLedsWrite;
Expand All @@ -36,10 +39,14 @@ fn main() -> ! {
let pins = Pins::new(peripherals.PORT);

let mut adc1 = Adc::adc1(peripherals.ADC1, &mut peripherals.MCLK, &mut clocks, GCLK11);
let mut light = pins.light.into_mode::<AlternateB>();
let mut light: LightSensor = pins.light.into();

let timer = SpinTimer::new(4);
let neopixel_pin: OldOutputPin<_> = pins.neopixel.into_push_pull_output().into();
let gclk0 = clocks.gclk0();
let tc2_3 = clocks.tc2_tc3(&gclk0).unwrap();
let mut timer = TimerCounter::tc3_(&tc2_3, peripherals.TC3, &mut peripherals.MCLK);
timer.start(Hertz::MHz(3).into_duration());

let neopixel_pin = pins.neopixel.into_push_pull_output();
let mut neopixel = ws2812::Ws2812::new(timer, neopixel_pin);

let mut delay = Delay::new(core.SYST, &mut clocks);
Expand Down Expand Up @@ -78,6 +85,6 @@ fn main() -> ! {
//incremement the hue easing
j = j.wrapping_add(1);

delay.delay_ms(10u8);
delay.delay_ms(10);
}
}
10 changes: 4 additions & 6 deletions boards/pygamer/examples/neopixel_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use pygamer as bsp;
use bsp::util::map_from;
use hal::adc::Adc;
use hal::prelude::*;
use hal::timer::SpinTimer;
use hal::{clock::GenericClockController, delay::Delay};
use pac::gclk::pchctrl::GEN_A::GCLK11;
use pac::gclk::pchctrl::GENSELECT_A::GCLK11;
use pac::{CorePeripherals, Peripherals};
use smart_leds::hsv::{hsv2rgb, Hsv, RGB8};
use smart_leds::SmartLedsWrite;
Expand All @@ -46,10 +45,9 @@ fn main() -> ! {
let mut adc1 = Adc::adc1(peripherals.ADC1, &mut peripherals.MCLK, &mut clocks, GCLK11);
let mut joystick = pins.joystick.init();

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

let mut neopixel = pins.neopixel.init(timer);
let mut neopixel = pins
.neopixel
.init(&mut clocks, peripherals.TC4, &mut peripherals.MCLK);

const NUM_LEDS: usize = 5;
let mut pos_button: usize = 2;
Expand Down
6 changes: 3 additions & 3 deletions boards/pygamer/examples/neopixel_easing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use core::f32::consts::FRAC_PI_2;
use hal::clock::GenericClockController;
use hal::delay::Delay;
use hal::prelude::*;
use hal::timer::SpinTimer;
use hal::trng::Trng;
use micromath::F32Ext;
use pac::{CorePeripherals, Peripherals};
Expand All @@ -35,9 +34,10 @@ fn main() -> ! {
);

let pins = Pins::new(peripherals.PORT).split();
let timer = SpinTimer::new(4);

let mut neopixel = pins.neopixel.init(timer);
let mut neopixel = pins
.neopixel
.init(&mut clocks, peripherals.TC4, &mut peripherals.MCLK);
let mut delay = Delay::new(core.SYST, &mut clocks);

let trng = Trng::new(&mut peripherals.MCLK, peripherals.TRNG);
Expand Down
4 changes: 2 additions & 2 deletions boards/pygamer/examples/neopixel_rainbow_spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use panic_halt as _;
use pygamer as bsp;

use hal::prelude::*;
use hal::sercom::v2::spi;
use hal::sercom::spi;
use hal::{clock::GenericClockController, delay::Delay};
use pac::{CorePeripherals, Peripherals};
use smart_leds::hsv::{hsv2rgb, Hsv};
Expand Down Expand Up @@ -41,7 +41,7 @@ fn main() -> ! {
.data_out(pins.neopixel)
.sclk(pins.scl);
let spi = spi::Config::new(mclk, sercom2, pads, clock.freq())
.baud(3.mhz())
.baud(3.MHz())
.enable();
let mut neopixel = ws2812::Ws2812::new(spi);
let mut delay = Delay::new(core.SYST, &mut clocks);
Expand Down
16 changes: 8 additions & 8 deletions boards/pygamer/examples/neopixel_rainbow_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ use bsp::{entry, hal, Pins};
use panic_halt as _;
use pygamer as bsp;

use hal::pac::{CorePeripherals, Peripherals};
use hal::pac::Peripherals;
use hal::prelude::*;
use hal::{clock::GenericClockController, delay::Delay, timer::TimerCounter};
use hal::{clock::GenericClockController, nb, timer::TimerCounter};
use smart_leds::hsv::{hsv2rgb, Hsv};
use smart_leds::SmartLedsWrite;

#[entry]
fn main() -> ! {
let mut peripherals = Peripherals::take().unwrap();
let core = CorePeripherals::take().unwrap();
let mut clocks = GenericClockController::with_internal_32kosc(
peripherals.GCLK,
&mut peripherals.MCLK,
Expand All @@ -33,13 +32,14 @@ fn main() -> ! {
);
let pins = Pins::new(peripherals.PORT).split();

let mut neopixel = pins
.neopixel
.init(&mut clocks, peripherals.TC4, &mut peripherals.MCLK);

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

let mut neopixel = pins.neopixel.init(timer);
let mut delay = Delay::new(core.SYST, &mut clocks);
InterruptDrivenTimer::start(&mut timer, 5.millis());

loop {
for j in 0..255u8 {
Expand Down Expand Up @@ -73,7 +73,7 @@ fn main() -> ! {
}),
];
neopixel.write(colors.iter().cloned()).unwrap();
delay.delay_ms(5u8);
nb::block!(InterruptDrivenTimer::wait(&mut timer)).unwrap();
}
}
}
Loading

0 comments on commit 363f1f5

Please sign in to comment.