Skip to content

Commit

Permalink
feat: use slices for changing block sizes (#6)
Browse files Browse the repository at this point in the history
* feat: update passthru example

* update readme

* feat: make buffer size generic

* feat: failed passthru example build
fix: gh action
fix: wrong target
fix: github action
fix: github action
fix: github action

* fix: delay and flash examples

* fix: hid_blinky, knob, sine examples

* fix: sdram, switch, toggle, volume

* chore: linting fix

* wip: use slices
feat: use slices instead of generics

* fix: update missing slices
fix: use slice of audio buffer

* feat: base max transfer size on user set block size
chore: formatting

* fix: examples failing on real device

* chore: cleanup comments and linting

* chore: remove magic number

* fix: branching type change

* fix: noise

* chore: format document

* chore: remove magic numbers dma_block_size
  • Loading branch information
nathansbradshaw authored Aug 22, 2024
1 parent d7e0ca9 commit 6212ab7
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 90 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build LibDaisy Examples

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Install target
run: rustup target add thumbv7em-none-eabihf

- name: Cache cargo registry
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Build examples
run: |
excluded_examples="sdmmc usb_midi" # List of examples to exclude
for example in $(ls examples/*.rs); do
example_name=$(basename $example .rs)
if [[ ! " $excluded_examples " =~ " $example_name " ]]; then
cargo build --example $example_name
else
echo "Skipping $example_name"
fi
done
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ log = "0.4"
micromath = "2"
panic-halt = "0.2.0"
panic-itm = { version = "0.4", optional = true }
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"], optional = true }
panic-rtt-target = { version = "0.1.3", optional = true }
panic-semihosting = { version = "0.6", optional = true }
rtt-target = { version = "0.4.0", optional = true }
rtt-target = { version = "0.5.0", optional = true }
stm32-fmc = "0.3.0"
stm32h7xx-hal = { version = "0.15.1", features = ["stm32h750v","rt","fmc", "xspi", "sdmmc", "sdmmc-fatfs", "usb_hs"] }
stm32h7xx-hal = { version = "0.16.0", features = ["stm32h750v","rt","fmc", "xspi", "sdmmc", "sdmmc-fatfs", "usb_hs"] }

[features]
default = []
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ One of:
```bash
cargo embed --features log-rtt --example passthru
```
**note** You will need to specify the board IE `--chip stm32h750v` for the daisy seed, or create an `Embed.toml` that specifies the chip.

## Build Examples

Expand Down
23 changes: 14 additions & 9 deletions examples/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@

#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true)]
mod app {
use libdaisy::{gpio, system};
use stm32h7xx_hal::gpio::{Edge, ExtiPin};
use libdaisy::{
gpio,
hal::gpio::{Edge, ExtiPin},
logger, system,
};
use log::info;

#[shared]
struct SharedResources {}
struct Shared {}

#[local]
struct LocalResources {
struct Local {
button: gpio::SeedButton,
led: gpio::SeedLed,
}

use panic_halt as _;

#[init]
fn init(ctx: init::Context) -> (SharedResources, LocalResources, init::Monotonics) {
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
logger::init();
let mut core = ctx.core;
let mut device = ctx.device;
let ccdr = system::System::init_clocks(device.PWR, device.RCC, &device.SYSCFG);
let mut system = libdaisy::system_init!(core, device, ccdr);
info!("Startup done!");

// Button
system.gpio.button.make_interrupt_source(&mut device.SYSCFG);
Expand All @@ -34,8 +39,8 @@ mod app {
system.gpio.button.enable_interrupt(&mut device.EXTI);

(
SharedResources {},
LocalResources {
Shared {},
Local {
button: system.gpio.button,
led: system.gpio.led,
},
Expand Down
13 changes: 10 additions & 3 deletions examples/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
peripherals = true,
)]
mod app {
use libdaisy::{audio, logger, system};
use libdaisy::{
audio::{self, AudioBuffer},
logger, system,
};
use log::info;

#[shared]
Expand All @@ -16,14 +19,18 @@ mod app {
#[local]
struct Local {
audio: audio::Audio,
buffer: audio::AudioBuffer,
buffer: AudioBuffer,
sdram: &'static mut [f32],
}

#[init]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
logger::init();
let system = system::System::init(ctx.core, ctx.device);

let mut core = ctx.core;
let device = ctx.device;
let ccdr = system::System::init_clocks(device.PWR, device.RCC, &device.SYSCFG);
let system = libdaisy::system_init!(core, device, ccdr);
let buffer = [(0.0, 0.0); audio::BLOCK_SIZE_MAX];

info!("Startup done!");
Expand Down
19 changes: 14 additions & 5 deletions examples/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ mod app {
#[init]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
logger::init();
let mut system = system::System::init(ctx.core, ctx.device);
let mut core = ctx.core;
let device = ctx.device;
let ccdr = system::System::init_clocks(device.PWR, device.RCC, &device.SYSCFG);
let system = libdaisy::system_init!(core, device, ccdr);
info!("Startup done!");
let mut timer2 = stm32h7xx_hal::timer::TimerExt::timer(
device.TIM2,
MilliSeconds::from_ticks(100).into_rate(),
ccdr.peripheral.TIM2,
&ccdr.clocks,
);

system
.timer2
.set_freq(MilliSeconds::from_ticks(500).into_rate());
timer2.listen(stm32h7xx_hal::timer::Event::TimeOut);

timer2.set_freq(MilliSeconds::from_ticks(500).into_rate());

let mut flash = system.flash;

Expand Down Expand Up @@ -79,7 +88,7 @@ mod app {
Shared {},
Local {
seed_led: system.gpio.led,
timer2: system.timer2,
timer2,
},
init::Monotonics(),
)
Expand Down
21 changes: 16 additions & 5 deletions examples/hid_blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@ mod app {
#[init]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
logger::init();
let mut system = system::System::init(ctx.core, ctx.device);
let mut core = ctx.core;
let device = ctx.device;
let ccdr = system::System::init_clocks(device.PWR, device.RCC, &device.SYSCFG);
let mut system = libdaisy::system_init!(core, device, ccdr);
info!("Startup done!");

system
.timer2
.set_freq(MilliSeconds::from_ticks(1).into_rate());
let mut timer2 = stm32h7xx_hal::timer::TimerExt::timer(
device.TIM2,
MilliSeconds::from_ticks(100).into_rate(),
ccdr.peripheral.TIM2,
&ccdr.clocks,
);

timer2.listen(stm32h7xx_hal::timer::Event::TimeOut);

timer2.set_freq(MilliSeconds::from_ticks(1).into_rate());

let mut led1 = hid::Led::new(system.gpio.led, false, 1000);
led1.set_brightness(0.5);
Expand All @@ -55,7 +66,7 @@ mod app {
led1,
adc1,
control1,
timer2: system.timer2,
timer2,
},
init::Monotonics(),
)
Expand Down
20 changes: 17 additions & 3 deletions examples/knob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod app {
use libdaisy::logger;
use libdaisy::{gpio::*, hid, prelude::*, system};
use log::info;
use stm32h7xx_hal::time::MilliSeconds;
use stm32h7xx_hal::{adc, stm32, timer::Timer};

#[shared]
Expand All @@ -27,12 +28,25 @@ mod app {
#[init]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
logger::init();
let mut system = system::System::init(ctx.core, ctx.device);
let mut core = ctx.core;
let device = ctx.device;
let ccdr = system::System::init_clocks(device.PWR, device.RCC, &device.SYSCFG);
let mut system = libdaisy::system_init!(core, device, ccdr);
info!("Startup done!");

let mut timer2 = stm32h7xx_hal::timer::TimerExt::timer(
device.TIM2,
MilliSeconds::from_ticks(100).into_rate(),
ccdr.peripheral.TIM2,
&ccdr.clocks,
);

timer2.listen(stm32h7xx_hal::timer::Event::TimeOut);

let duty_cycle = 50;
let resolution = 20;

system.timer2.set_freq((duty_cycle * resolution).Hz());
timer2.set_freq((duty_cycle * resolution).Hz());

let daisy28 = system
.gpio
Expand Down Expand Up @@ -62,7 +76,7 @@ mod app {
led1,
adc1,
control1,
timer2: system.timer2,
timer2,
},
init::Monotonics(),
)
Expand Down
20 changes: 15 additions & 5 deletions examples/passthru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
peripherals = true,
)]
mod app {
use libdaisy::{audio, logger, system};
const BLOCK_SIZE: usize = 128;
use libdaisy::logger;
use libdaisy::{audio, system};
use log::info;

#[shared]
Expand All @@ -21,10 +23,18 @@ mod app {
#[init]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
logger::init();
let system = system::System::init(ctx.core, ctx.device);

// Latest changes here. This approach allows you to
// access peripherals and resources that were simply
// moved out of the function in the previous implementation.
let mut core = ctx.core;
let device = ctx.device;
let ccdr = system::System::init_clocks(device.PWR, device.RCC, &device.SYSCFG);
let system = libdaisy::system_init!(core, device, ccdr, BLOCK_SIZE);

let buffer = [(0.0, 0.0); audio::BLOCK_SIZE_MAX];

info!("Startup done!");
info!("Startup done!!");

(
Shared {},
Expand Down Expand Up @@ -52,8 +62,8 @@ mod app {
let buffer = ctx.local.buffer;

if audio.get_stereo(buffer) {
for (left, right) in buffer {
audio.push_stereo((*left, *right)).unwrap();
for (left, right) in &buffer.as_slice()[..BLOCK_SIZE] {
let _ = audio.push_stereo((*left, *right));
}
} else {
info!("Error reading data!");
Expand Down
19 changes: 14 additions & 5 deletions examples/sdram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ mod app {
#[init]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
logger::init();
let mut system = system::System::init(ctx.core, ctx.device);
let mut core = ctx.core;
let device = ctx.device;
let ccdr = system::System::init_clocks(device.PWR, device.RCC, &device.SYSCFG);
let system = libdaisy::system_init!(core, device, ccdr);
info!("Startup done!");
let mut timer2 = stm32h7xx_hal::timer::TimerExt::timer(
device.TIM2,
MilliSeconds::from_ticks(100).into_rate(),
ccdr.peripheral.TIM2,
&ccdr.clocks,
);
timer2.listen(stm32h7xx_hal::timer::Event::TimeOut);

system
.timer2
.set_freq(MilliSeconds::from_ticks(500).into_rate());
timer2.set_freq(MilliSeconds::from_ticks(500).into_rate());

let sdram = system.sdram;

Expand Down Expand Up @@ -72,7 +81,7 @@ mod app {
Shared {},
Local {
seed_led: system.gpio.led,
timer2: system.timer2,
timer2,
},
init::Monotonics(),
)
Expand Down
Loading

0 comments on commit 6212ab7

Please sign in to comment.