Skip to content

Commit b798ae0

Browse files
committed
Remove aligned dependency
1 parent 427a8e6 commit b798ae0

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

examples/i2s-controller-demo/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ cortex-m = "0.6.2"
1212
cortex-m-rtic = "0.5.3"
1313
rtt-target = {version = "0.2.0", features = ["cortex-m"] }
1414
nrf52840-hal = { features = ["rt"], path = "../../nrf52840-hal" }
15-
aligned = "0.3.4"
1615
heapless = "0.5.5"
1716
small_morse = "0.1.0"
1817

examples/i2s-controller-demo/src/main.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Generates Morse code audio signals for text from UART, playing back over I2S
66
// Tested with nRF52840-DK and a UDA1334a DAC
77

8-
use aligned::{Aligned, A4};
98
use embedded_hal::digital::v2::{InputPin, OutputPin};
109
use heapless::{
1110
consts::*,
@@ -30,6 +29,9 @@ use {
3029
rtt_target::{rprintln, rtt_init_print},
3130
};
3231

32+
#[repr(align(4))]
33+
struct Aligned<T: ?Sized>(T);
34+
3335
#[rtic::app(device = crate::hal::pac, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)]
3436
const APP: () = {
3537
struct Resources {
@@ -53,14 +55,14 @@ const APP: () = {
5355
#[init(resources = [queue], spawn = [tick])]
5456
fn init(mut ctx: init::Context) -> init::LateResources {
5557
// The I2S buffer address must be 4 byte aligned.
56-
static mut MUTE_BUF: Aligned<A4, [i16; 32]> = Aligned([0i16; 32]);
57-
static mut SIGNAL_BUF: Aligned<A4, [i16; 32]> = Aligned([0i16; 32]);
58+
static mut MUTE_BUF: Aligned<[i16; 32]> = Aligned([0i16; 32]);
59+
static mut SIGNAL_BUF: Aligned<[i16; 32]> = Aligned([0i16; 32]);
5860

5961
// Fill signal buffer with triangle waveform, 2 channels interleaved
60-
let len = SIGNAL_BUF.len() / 2;
62+
let len = SIGNAL_BUF.0.len() / 2;
6163
for x in 0..len {
62-
SIGNAL_BUF[2 * x] = triangle_wave(x as i32, len, 2048, 0, 1) as i16;
63-
SIGNAL_BUF[2 * x + 1] = triangle_wave(x as i32, len, 2048, 0, 1) as i16;
64+
SIGNAL_BUF.0[2 * x] = triangle_wave(x as i32, len, 2048, 0, 1) as i16;
65+
SIGNAL_BUF.0[2 * x + 1] = triangle_wave(x as i32, len, 2048, 0, 1) as i16;
6466
}
6567

6668
let _clocks = hal::clocks::Clocks::new(ctx.device.CLOCK).enable_ext_hfosc();
@@ -126,9 +128,9 @@ const APP: () = {
126128
led: p0.p0_13.into_push_pull_output(Level::High).degrade(),
127129
uarte,
128130
uarte_timer: Timer::new(ctx.device.TIMER0),
129-
transfer: i2s.tx(&**MUTE_BUF).ok(),
130-
signal_buf: &**SIGNAL_BUF,
131-
mute_buf: &**MUTE_BUF,
131+
transfer: i2s.tx(&MUTE_BUF.0).ok(),
132+
signal_buf: &SIGNAL_BUF.0,
133+
mute_buf: &MUTE_BUF.0,
132134
}
133135
}
134136

examples/i2s-peripheral-demo/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ cortex-m = "0.6.2"
1212
cortex-m-rtic = "0.5.3"
1313
rtt-target = {version = "0.2.0", features = ["cortex-m"] }
1414
nrf52840-hal = { features = ["rt"], path = "../../nrf52840-hal" }
15-
aligned = "0.3.4"
1615

1716
[dependencies.embedded-hal]
1817
version = "0.2.3"

examples/i2s-peripheral-demo/src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// I2S `peripheral mode` demo
55
// Signal average level indicator using an RGB LED (APA102 on ItsyBitsy nRF52840)
66

7-
use aligned::{Aligned, A4};
87
use embedded_hal::blocking::spi::Write;
98
use {
109
core::{
@@ -21,6 +20,9 @@ use {
2120
rtt_target::{rprintln, rtt_init_print},
2221
};
2322

23+
#[repr(align(4))]
24+
struct Aligned<T: ?Sized>(T);
25+
2426
const OFF: [u8; 9] = [0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF];
2527
const GREEN: [u8; 9] = [0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x00, 0xFF];
2628
const ORANGE: [u8; 9] = [0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x10, 0xFF];
@@ -36,7 +38,7 @@ const APP: () = {
3638
#[init]
3739
fn init(ctx: init::Context) -> init::LateResources {
3840
// The I2S buffer address must be 4 byte aligned.
39-
static mut RX_BUF: Aligned<A4, [i16; 128]> = Aligned([0; 128]);
41+
static mut RX_BUF: Aligned<[i16; 128]> = Aligned([0; 128]);
4042

4143
let _clocks = hal::clocks::Clocks::new(ctx.device.CLOCK).enable_ext_hfosc();
4244
rtt_init_print!();
@@ -80,7 +82,7 @@ const APP: () = {
8082
);
8183
init::LateResources {
8284
rgb,
83-
transfer: i2s.rx(&mut **RX_BUF).ok(),
85+
transfer: i2s.rx(&mut RX_BUF.0).ok(),
8486
}
8587
}
8688

0 commit comments

Comments
 (0)