Skip to content

Commit

Permalink
Added PWM powered red led example
Browse files Browse the repository at this point in the history
  • Loading branch information
salsasteve committed Jan 22, 2024
1 parent ba6b540 commit 8678283
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion boards/matrix_portal_m4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ features = ["critical-section-single-core"]

[dev-dependencies]
panic-halt = "0.2"
micromath = "0.5.1"

[features]
# ask the HAL to enable atsamd51j support
Expand Down
5 changes: 4 additions & 1 deletion boards/matrix_portal_m4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ $ cargo hf2 --release --example blinky_basic --vid 0x239a --pid 0x00c9
Flashing "/Users/User/atsamd/boards/matrix_portal_m4/target/thumbv7em-none-eabihf/release/examples/blinky_basic"
Finished in 0.051s
$
```
```

## Matrix Portal M4
[PCB DOCs](https://github.com/adafruit/Adafruit-MatrixPortal-M4-PCB/tree/main)
9 changes: 5 additions & 4 deletions boards/matrix_portal_m4/examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
use matrix_portal_m4::{entry, hal, Pins, RedLedPwm};
use panic_halt as _;

use core::f32::consts::FRAC_PI_2;
use hal::clock::GenericClockController;
use hal::delay::Delay;
use hal::fugit::RateExtU32;
use hal::pac::{CorePeripherals, Peripherals};
use hal::prelude::*;
use hal::pwm::{Channel, TCC1Pinout, Tcc1Pwm};
use micromath::F32Ext;

#[entry]
fn main() -> ! {
Expand Down Expand Up @@ -43,12 +41,15 @@ fn main() -> ! {
&mut peripherals.MCLK,
);
let max_duty = tcc1pwm.get_max_duty();
let min_duty = 0;
let min_duty = max_duty / 8;

loop {
// board led is on channel 2 of tcc1
// Verfied by looking at adafrult pinout
// https://cdn-learn.adafruit.com/assets/assets/000/111/881/original/led_matrices_Adafruit_MatrixPortal_M4_Pinout.png?1653078587
tcc1pwm.set_duty(Channel::_2, max_duty);
delay.delay_ms(1000u16);
tcc1pwm.set_duty(Channel::_2, max_duty / 8);
tcc1pwm.set_duty(Channel::_2, min_duty);
delay.delay_ms(1000u16);
}
}
1 change: 1 addition & 0 deletions boards/matrix_portal_m4/src/pins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ hal::bsp_pins!(
aliases: {
PushPullOutput: RedLed,
Reset: RedLedReset,
AlternateG: RedLedPwm,
}
}

Expand Down

0 comments on commit 8678283

Please sign in to comment.