Skip to content

Commit 20b17d2

Browse files
authored
deps(circuit-playground-express): Update dependencies and HAL to 0.23.0 (#953)
1 parent 025e76a commit 20b17d2

File tree

6 files changed

+139
-106
lines changed

6 files changed

+139
-106
lines changed

boards/circuit_playground_express/Cargo.toml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,48 @@
11
[package]
22
name = "circuit_playground_express"
3+
categories = ["embedded", "hardware-support", "no-std"]
34
version = "0.11.1"
45
authors = ["Paul Sajna <paulsajna@gmail.com>"]
56
description = "Board Support crate for the Adafruit Circuit Playground Express"
67
keywords = ["no-std", "arm", "cortex-m", "embedded-hal"]
78
license = "MIT OR Apache-2.0"
89
repository = "https://github.com/atsamd-rs/atsamd"
910
readme = "README.md"
10-
edition = "2018"
11+
edition = "2024"
1112

1213
[dependencies.cortex-m-rt]
1314
version = "0.7"
1415
optional = true
1516

1617
[dependencies.atsamd-hal]
17-
version = "0.14"
18+
version = "0.23.0"
1819
default-features = false
1920

21+
[dependencies.cortex-m]
22+
features = ["critical-section-single-core"]
23+
version = "0.7"
24+
2025
[dependencies.usb-device]
21-
version = "0.2"
26+
version = "0.3.2"
2227
optional = true
2328

2429
[dev-dependencies]
25-
cortex-m = "0.7"
2630
panic-halt = "0.2"
27-
panic-semihosting = "0.5"
28-
usbd-serial = "0.1"
31+
panic-semihosting = "0.6"
32+
usbd-serial = "0.2"
2933
smart-leds = "0.3.0"
34+
heapless = "0.9.2"
3035

3136
[dev-dependencies.ws2812-timer-delay]
3237
features = ["slow"]
3338
version = "0.3.0"
3439

3540
[features]
3641
# ask the HAL to enable atsamd21g support
37-
default = ["rt", "atsamd-hal/samd21g"]
42+
# CPE uses all kinds of undoc'd i2c functionality.
43+
default = ["rt", "atsamd-hal/samd21g", "atsamd-hal/undoc-features"]
44+
dma = ["atsamd-hal/dma"]
3845
rt = ["cortex-m-rt", "atsamd-hal/samd21g-rt"]
39-
unproven = ["atsamd-hal/unproven"]
4046
usb = ["atsamd-hal/usb", "usb-device"]
4147
use_semihosting = []
4248

@@ -53,3 +59,4 @@ name = "uart"
5359
[[example]]
5460
name = "usb_serial"
5561
required-features = ["usb"]
62+
edition = "2021"

boards/circuit_playground_express/examples/blinky_basic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ fn main() -> ! {
2121
let mut peripherals = Peripherals::take().unwrap();
2222
let core = CorePeripherals::take().unwrap();
2323
let mut clocks = GenericClockController::with_internal_32kosc(
24-
peripherals.GCLK,
25-
&mut peripherals.PM,
26-
&mut peripherals.SYSCTRL,
27-
&mut peripherals.NVMCTRL,
24+
peripherals.gclk,
25+
&mut peripherals.pm,
26+
&mut peripherals.sysctrl,
27+
&mut peripherals.nvmctrl,
2828
);
29-
let pins = bsp::Pins::new(peripherals.PORT);
29+
let pins = bsp::Pins::new(peripherals.port);
3030
let mut red_led: bsp::RedLed = pins.d13.into();
3131
let mut delay = Delay::new(core.SYST, &mut clocks);
3232
loop {

boards/circuit_playground_express/examples/neopixel_rainbow.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ use circuit_playground_express as bsp;
2020
use bsp::entry;
2121
use hal::clock::GenericClockController;
2222
use hal::delay::Delay;
23-
use hal::prelude::*;
23+
use hal::fugit::ExtU32;
2424
use hal::timer::TimerCounter;
25+
use hal::timer_traits::InterruptDrivenTimer;
2526
use pac::{CorePeripherals, Peripherals};
2627

2728
use smart_leds::{
28-
hsv::{hsv2rgb, Hsv},
2929
SmartLedsWrite,
30+
hsv::{Hsv, hsv2rgb},
3031
};
3132
use ws2812_timer_delay as ws2812;
3233

@@ -35,24 +36,25 @@ fn main() -> ! {
3536
let mut peripherals = Peripherals::take().unwrap();
3637
let core = CorePeripherals::take().unwrap();
3738
let mut clocks = GenericClockController::with_internal_32kosc(
38-
peripherals.GCLK,
39-
&mut peripherals.PM,
40-
&mut peripherals.SYSCTRL,
41-
&mut peripherals.NVMCTRL,
39+
peripherals.gclk,
40+
&mut peripherals.pm,
41+
&mut peripherals.sysctrl,
42+
&mut peripherals.nvmctrl,
4243
);
43-
let pins = bsp::Pins::new(peripherals.PORT);
44+
let pins = bsp::Pins::new(peripherals.port);
4445
let mut delay = Delay::new(core.SYST, &mut clocks);
4546

4647
let gclk0 = clocks.gclk0();
4748
let timer_clock = clocks.tcc2_tc3(&gclk0).unwrap();
48-
let mut timer = TimerCounter::tc3_(&timer_clock, peripherals.TC3, &mut peripherals.PM);
49-
timer.start(3.mhz());
49+
let mut timer = TimerCounter::tc3_(&timer_clock, peripherals.tc3, &mut peripherals.pm);
50+
timer.start(1.micros());
5051

5152
let neopixel_pin: bsp::NeoPixel = pins.d8.into();
5253
let mut neopixel = ws2812::Ws2812::new(timer, neopixel_pin);
5354

5455
// Loop through all of the available hue values (colors) to make a
5556
// rainbow effect from the onboard neopixel
57+
use hal::ehal::delay::DelayNs;
5658
loop {
5759
for j in 0..255u8 {
5860
let colors = [hsv2rgb(Hsv {
@@ -61,7 +63,7 @@ fn main() -> ! {
6163
val: 2,
6264
}); 10];
6365
neopixel.write(colors.iter().cloned()).unwrap();
64-
delay.delay_ms(5u8);
66+
delay.delay_ms(5);
6567
}
6668
}
6769
}
Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! This example shows how to use the UART to perform transfers using the
2+
//! embedded-hal-nb traits.
3+
14
#![no_std]
25
#![no_main]
36

@@ -9,58 +12,62 @@ use panic_semihosting as _;
912
use bsp::hal;
1013
use bsp::pac;
1114
use circuit_playground_express as bsp;
15+
use hal::nb;
1216

13-
use bsp::entry;
17+
use bsp::{entry, periph_alias, pin_alias};
1418
use hal::clock::GenericClockController;
15-
use hal::prelude::*;
19+
use hal::ehal_nb::serial::{Read, Write};
20+
use hal::fugit::RateExtU32;
1621

17-
use pac::{CorePeripherals, Peripherals};
22+
use pac::Peripherals;
1823

1924
#[entry]
2025
fn main() -> ! {
2126
let mut peripherals = Peripherals::take().unwrap();
22-
let core = CorePeripherals::take().unwrap();
2327
let mut clocks = GenericClockController::with_internal_32kosc(
24-
peripherals.GCLK,
25-
&mut peripherals.PM,
26-
&mut peripherals.SYSCTRL,
27-
&mut peripherals.NVMCTRL,
28+
peripherals.gclk,
29+
&mut peripherals.pm,
30+
&mut peripherals.sysctrl,
31+
&mut peripherals.nvmctrl,
2832
);
2933

30-
let mut pm = peripherals.PM;
31-
let pins = bsp::Pins::new(peripherals.PORT);
32-
let mut delay = hal::delay::Delay::new(core.SYST, &mut clocks);
34+
let mut pm = peripherals.pm;
35+
let pins = bsp::Pins::new(peripherals.port);
3336

34-
let mut red_led = pins.d13.into_push_pull_output();
37+
// Take peripheral and pins
38+
let uart_sercom = periph_alias!(peripherals.uart_sercom);
39+
let uart_rx = pin_alias!(pins.uart_rx);
40+
let uart_tx = pin_alias!(pins.uart_tx);
3541

36-
// Setup UART peripheral.
37-
let (rx_pin, tx_pin) = (pins.a6, pins.a7);
38-
let mut uart = bsp::uart(
42+
// Setup UART peripheral
43+
let uart = bsp::uart(
3944
&mut clocks,
40-
9600.hz(),
41-
peripherals.SERCOM4,
45+
9600.Hz(),
46+
uart_sercom,
4247
&mut pm,
43-
rx_pin,
44-
tx_pin,
48+
uart_rx,
49+
uart_tx,
4550
);
4651

47-
// Write out a message on start up.
48-
for byte in b"Hello world!\r\n" {
49-
nb::block!(uart.write(*byte)).unwrap();
50-
}
52+
// Split uart in rx + tx halves
53+
let (mut rx, mut tx) = uart.split();
54+
55+
// Make buffers to store data to send/receive
56+
let mut rx_buffer = [0x00; 50];
57+
let tx_buffer = b"Hello, world!";
5158

5259
loop {
53-
match uart.read() {
54-
Ok(byte) => {
55-
// Echo all received characters.
56-
nb::block!(uart.write(byte)).unwrap();
60+
// Send data. We block on each byte, but we could also perform some tasks while
61+
// waiting for the byte to finish sending.
62+
for c in tx_buffer.iter() {
63+
nb::block!(tx.write(*c)).unwrap();
64+
}
5765

58-
// Blink the red led to show that a character has arrived.
59-
red_led.set_high().unwrap();
60-
delay.delay_ms(2u16);
61-
red_led.set_low().unwrap();
62-
}
63-
Err(_) => delay.delay_ms(5u16),
64-
};
66+
// Receive data. We block on each byte, but we could also perform some tasks
67+
// while waiting for the byte to finish sending.
68+
rx.flush_rx_buffer();
69+
for c in rx_buffer.iter_mut() {
70+
*c = nb::block!(rx.read()).unwrap();
71+
}
6572
}
6673
}

boards/circuit_playground_express/examples/usb_serial.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bsp::hal;
1616
use bsp::pac;
1717
use circuit_playground_express as bsp;
1818

19-
use bsp::entry;
19+
use bsp::{entry, pin_alias};
2020
use hal::clock::GenericClockController;
2121
use hal::prelude::*;
2222
use hal::usb::UsbBus;
@@ -27,32 +27,34 @@ fn main() -> ! {
2727
let mut peripherals = Peripherals::take().unwrap();
2828
let mut core = CorePeripherals::take().unwrap();
2929
let mut clocks = GenericClockController::with_internal_32kosc(
30-
peripherals.GCLK,
31-
&mut peripherals.PM,
32-
&mut peripherals.SYSCTRL,
33-
&mut peripherals.NVMCTRL,
30+
peripherals.gclk,
31+
&mut peripherals.pm,
32+
&mut peripherals.sysctrl,
33+
&mut peripherals.nvmctrl,
3434
);
35-
let pins = bsp::Pins::new(peripherals.PORT);
36-
let mut red_led: bsp::RedLed = pins.d13.into();
35+
let pins = bsp::Pins::new(peripherals.port);
36+
let mut red_led: bsp::RedLed = pin_alias!(pins.red_led).into();
3737

3838
let bus_allocator = unsafe {
3939
USB_ALLOCATOR = Some(bsp::usb_allocator(
40-
peripherals.USB,
40+
peripherals.usb,
4141
&mut clocks,
42-
&mut peripherals.PM,
42+
&mut peripherals.pm,
4343
pins.usb_dm,
4444
pins.usb_dp,
4545
));
4646
USB_ALLOCATOR.as_ref().unwrap()
4747
};
4848

4949
unsafe {
50-
USB_SERIAL = Some(SerialPort::new(&bus_allocator));
50+
USB_SERIAL = Some(SerialPort::new(bus_allocator));
5151
USB_BUS = Some(
52-
UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x16c0, 0x27dd))
53-
.manufacturer("Fake company")
54-
.product("Serial port")
55-
.serial_number("TEST")
52+
UsbDeviceBuilder::new(bus_allocator, UsbVidPid(0x16c0, 0x27dd))
53+
.strings(&[StringDescriptors::new(LangID::EN)
54+
.manufacturer("Fake company")
55+
.product("Serial port")
56+
.serial_number("TEST")])
57+
.expect("Failed to set strings")
5658
.device_class(USB_CLASS_CDC)
5759
.build(),
5860
);
@@ -67,9 +69,7 @@ fn main() -> ! {
6769
// entirely interrupt driven.
6870
loop {
6971
cycle_delay(15 * 1024 * 1024);
70-
red_led.set_high().ok();
71-
cycle_delay(15 * 1024 * 1024);
72-
red_led.set_low().ok();
72+
red_led.toggle().ok();
7373
}
7474
}
7575

@@ -79,8 +79,8 @@ static mut USB_SERIAL: Option<SerialPort<UsbBus>> = None;
7979

8080
fn poll_usb() {
8181
unsafe {
82-
USB_BUS.as_mut().map(|usb_dev| {
83-
USB_SERIAL.as_mut().map(|serial| {
82+
if let Some(usb_dev) = USB_BUS.as_mut() {
83+
if let Some(serial) = USB_SERIAL.as_mut() {
8484
usb_dev.poll(&mut [serial]);
8585
let mut buf = [0u8; 64];
8686

@@ -89,11 +89,11 @@ fn poll_usb() {
8989
if i >= count {
9090
break;
9191
}
92-
serial.write(&[c.clone()]).ok();
92+
serial.write(&[*c]).ok();
9393
}
9494
};
95-
});
96-
});
95+
};
96+
};
9797
};
9898
}
9999

0 commit comments

Comments
 (0)