Skip to content

Commit

Permalink
Add Framework LED Matrix Example
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Schaefer <[email protected]>
  • Loading branch information
JohnAZoidberg committed Oct 14, 2024
1 parent 3dca87a commit 4a84b89
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
- if: steps.changes.outputs.rust == 'true'
run: |
cargo build --target=thumbv6m-none-eabi
cd examples/adafruit_rgb
cargo build --target=thumbv6m-none-eabi
cd examples/adafruit_rgb && cargo build --target=thumbv6m-none-eabi
cd examples/ledmatrix && cargo build --target=thumbv6m-none-eabi
rustdoc:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build-all:
cd examples/adafruit_rgb && \
cargo build --target=thumbv6m-none-eabi --examples --all-features
cd examples/ledmatrix && \
cargo build --target=thumbv6m-none-eabi --examples --all-features
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Driver for [Lumissil Microsystem's IS31FL3741 integrated circuit](https://www.lu
1. Use of embedded HAL traits (works with any embedded device that supports the required traits). This means that this driver is platform agnostic.
2. Library features (only turn on what devices you need to save compiled binary space).
3. [Examples](./examples) on how to use this driver.
Right now there is only an example on how to use this crate with a stm32 nucleo.

## Install

Expand Down
16 changes: 16 additions & 0 deletions examples/ledmatrix/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "ledmatrix"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
is31fl3741 = { path = "../../", features = ["framework_ledmatrix"] }
embedded-hal = "0.2.7"
cortex-m-rt = "0.7.3"
cortex-m = "0.7.7"
fugit = "0.3.7"
rp2040-hal = { version = "0.8", features = ["rt", "critical-section-impl"] }
rp-pico = "0.7"
rp2040-panic-usb-boot = "0.5.0"
rp2040-boot2 = "0.3"
7 changes: 7 additions & 0 deletions examples/ledmatrix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Framework LED Matrix

## Build and run

```
cargo build --target=thumbv6m-none-eabi
```
124 changes: 124 additions & 0 deletions examples/ledmatrix/examples/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//! LED Matrix Module
#![no_std]
#![no_main]
#![allow(clippy::needless_range_loop)]

use embedded_hal::digital::v2::{InputPin, OutputPin};
//use rp2040_hal::{
// gpio::bank0::Gpio29,
//};
use rp2040_panic_usb_boot as _;
//use panic_halt as _;

/// Maximum brightness out of 255
///
/// 100/255 results in 250mA current draw and is plenty bright.
/// 50/255 results in 160mA current draw and is plenty bright.
const MAX_BRIGHTNESS: u8 = 50;

// Provide an alias for our BSP so we can switch targets quickly.
// Uncomment the BSP you included in Cargo.toml, the rest of the code does not need to change.
use bsp::entry;
use is31fl3741::devices::{LedMatrix, CALC_PIXEL};
use is31fl3741::{PwmFreq};
use rp_pico as bsp;

use bsp::hal::{
clocks::{init_clocks_and_plls, Clock},
gpio, pac,
sio::Sio,
watchdog::Watchdog,
};
use fugit::RateExtU32;

#[entry]
fn main() -> ! {
let mut pac = pac::Peripherals::take().unwrap();
let core = pac::CorePeripherals::take().unwrap();
let mut watchdog = Watchdog::new(pac.WATCHDOG);
let sio = Sio::new(pac.SIO);

let clocks = init_clocks_and_plls(
bsp::XOSC_CRYSTAL_FREQ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.ok()
.unwrap();
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());

let pins = bsp::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);

// Enable LED controller
// SDB - Gpio29
let mut led_enable = pins.voltage_monitor.into_push_pull_output();
led_enable.set_high().unwrap();
// INTB. Currently ignoring
pins.gpio28.into_floating_input();

let i2c = bsp::hal::I2C::i2c1(
pac.I2C1,
pins.gpio26.into_mode::<gpio::FunctionI2C>(),
pins.gpio27.into_mode::<gpio::FunctionI2C>(),
// 1000,
1000.kHz(),
&mut pac.RESETS,
&clocks.peripheral_clock,
);

// Gpio25 (LED on rp-pico)
let dip1 = pins.led.into_pull_up_input();

let mut matrix = LedMatrix::new(i2c, CALC_PIXEL);
matrix
.setup(&mut delay)
.expect("failed to setup RGB controller");

// Enable only the SW pins that we're using.
// Otherwise driving the unused pins might result in audible noise.
matrix
.device
.sw_enablement(is31fl3741::SwSetting::Sw1Sw8)
.unwrap();

matrix
.set_scaling(MAX_BRIGHTNESS)
.expect("failed to set scaling");

// Set to 29kHz PWM frequency
// TODO: Create enum
matrix.device.set_pwm_freq(PwmFreq::P29k).unwrap();


// Detect whether the sleep pin is connected
// Early revisions of the hardware didn't have it wired up, if that is the
// case we have to ignore its state.
let mut sleep_present = false;
let sleep = pins.gpio0.into_pull_up_input();
if sleep.is_low().unwrap() {
sleep_present = true;
}
let sleep = sleep.into_pull_down_input();
if sleep.is_high().unwrap() {
sleep_present = true;
}

loop {
let _dip1_state = dip1.is_low().unwrap();

if sleep_present {
let host_sleeping = sleep.is_low().unwrap();
}

// fill_grid_pixels(&state, &mut matrix);
}
}
1 change: 1 addition & 0 deletions examples/ledmatrix/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#![no_std]

0 comments on commit 4a84b89

Please sign in to comment.