Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/FrameworkComputer/is31fl3741-rs"
readme = "README.md"

[dependencies]
embedded-hal = "0.2.7"
embedded-hal = "1.0"
embedded-graphics-core = { optional = true, version = "0.4.0" }

[package.metadata.docs.rs]
Expand Down
19 changes: 13 additions & 6 deletions examples/adafruit_rgb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
[package]
name = "stm3"
name = "adafruit_rgb"
version = "0.2.0"
edition = "2021"
publish = false

[dependencies]
is31fl3741 = { path = "../../", features = [ "adafruit_rgb_13x9", "embedded_graphics" ] }
embedded-hal = "0.2.7"
cortex-m-rt = "0.7.3"
embedded-hal = "1.0"
cortex-m = "0.7.7"
cortex-m-rt = "0.7.3"
fugit = "0.3.7"
panic-halt = { version = "0.2.0" }
stm32g0xx-hal = {version = "0.2.0", features = ["rt", "stm32g071"]}
panic-halt = "1.0.0"
rp2040-hal = { version = "0.11.0", features = ["rt", "critical-section-impl"] }
rp2040-boot2 = "0.3"
tinybmp = "0.5.0"
embedded-graphics = "0.8.1"

[[example]]
name = "stm32"
name = "rgbmatrix"

[[example]]
name = "gaypride"

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"
83 changes: 62 additions & 21 deletions examples/adafruit_rgb/examples/gaypride.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,84 @@
//! Adafruit RGB 13x9 Matrix - Pride Flag Example for QT Py RP2040
//!
//! Displays a pride flag image on the Adafruit IS31FL3741 RGB matrix.
//! Connect the matrix to the STEMMA QT connector on the QT Py RP2040.
//!
//! STEMMA QT pinout on QT Py RP2040:
//! - SDA: GPIO22
//! - SCL: GPIO23
#![no_std]
#![no_main]

// pick a panicking behavior
use panic_halt as _;

// use cortex_m::delay::Delay;
use cortex_m_rt::entry;
use is31fl3741::devices::AdafruitRGB13x9;
use fugit::RateExtU32;

use embedded_graphics::{image::Image, pixelcolor::Rgb888, prelude::*};
use stm32g0xx_hal::{
prelude::*,
rcc::{Config, Prescaler},
stm32,
use fugit::RateExtU32;
use rp2040_hal::{
self as hal,
clocks::init_clocks_and_plls,
entry,
gpio::{FunctionI2C, PullUp},
pac,
sio::Sio,
watchdog::Watchdog,
Timer, I2C,
};
use tinybmp::Bmp;

use is31fl3741::devices::AdafruitRGB13x9;

/// External crystal frequency (QT Py RP2040 uses 12MHz)
const XTAL_FREQ_HZ: u32 = 12_000_000;

#[link_section = ".boot2"]
#[used]
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GD25Q64CS;

#[entry]
fn main() -> ! {
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
let mut rcc = dp.RCC.freeze(Config::hsi(Prescaler::NotDivided));
let mut delay = dp.TIM15.delay(&mut rcc);
let mut pac = pac::Peripherals::take().unwrap();
let mut watchdog = Watchdog::new(pac.WATCHDOG);
let sio = Sio::new(pac.SIO);

let clocks = init_clocks_and_plls(
XTAL_FREQ_HZ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.ok()
.unwrap();

// let cp = cortex_m::Peripherals::take().unwrap();
// let dp = pac::Peripherals::take().unwrap();
let gpiob = dp.GPIOB.split(&mut rcc);
let timer = Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
let mut delay = timer;

let sda = gpiob.pb9.into_open_drain_output_in_state(PinState::High);
let scl = gpiob.pb8.into_open_drain_output_in_state(PinState::High);
let pins = hal::gpio::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);

let i2c = dp.I2C1.i2c(sda, scl, 100.kHz(), &mut rcc);
// STEMMA QT connector I2C1 pins on QT Py RP2040
let sda: hal::gpio::Pin<_, FunctionI2C, PullUp> = pins.gpio22.reconfigure();
let scl: hal::gpio::Pin<_, FunctionI2C, PullUp> = pins.gpio23.reconfigure();

// // https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3741/blob/main/adafruit_is31fl3 741/adafruit_rgbmatrixqt.py#L53-L65
let i2c = I2C::i2c1(
pac.I2C1,
sda,
scl,
400.kHz(),
&mut pac.RESETS,
&clocks.peripheral_clock,
);

let mut matrix = AdafruitRGB13x9::configure(i2c);
matrix
.setup(&mut delay)
.expect("failed to setup rgb controller");
.expect("failed to setup RGB controller");

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

Expand Down
96 changes: 96 additions & 0 deletions examples/adafruit_rgb/examples/rgbmatrix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//! Adafruit RGB 13x9 Matrix Example for QT Py RP2040
//!
//! Lights up each LED one by one on the Adafruit IS31FL3741 RGB matrix.
//! Connect the matrix to the STEMMA QT connector on the QT Py RP2040.
//!
//! STEMMA QT pinout on QT Py RP2040:
//! - SDA: GPIO22
//! - SCL: GPIO23
#![no_std]
#![no_main]

use panic_halt as _;

use embedded_hal::delay::DelayNs;
use fugit::RateExtU32;
use rp2040_hal::{
self as hal,
clocks::init_clocks_and_plls,
entry,
gpio::{FunctionI2C, PullUp},
pac,
sio::Sio,
watchdog::Watchdog,
Timer, I2C,
};

use is31fl3741::devices::AdafruitRGB13x9;

/// External crystal frequency (QT Py RP2040 uses 12MHz)
const XTAL_FREQ_HZ: u32 = 12_000_000;

#[link_section = ".boot2"]
#[used]
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GD25Q64CS;

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

let clocks = init_clocks_and_plls(
XTAL_FREQ_HZ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.ok()
.unwrap();

let timer = Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
let mut delay = timer;

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

// STEMMA QT connector I2C1 pins on QT Py RP2040
let sda: hal::gpio::Pin<_, FunctionI2C, PullUp> = pins.gpio22.reconfigure();
let scl: hal::gpio::Pin<_, FunctionI2C, PullUp> = pins.gpio23.reconfigure();

let i2c = I2C::i2c1(
pac.I2C1,
sda,
scl,
400.kHz(),
&mut pac.RESETS,
&clocks.peripheral_clock,
);

let mut matrix = AdafruitRGB13x9::configure(i2c);
matrix
.setup(&mut delay)
.expect("failed to setup RGB controller");

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

loop {
// Light up each LED one by one
for y in 0..9 {
for x in 0..13 {
matrix
.pixel_rgb(x, y, 0x1E, 0x90, 0xFF)
.expect("couldn't turn on");
delay.delay_ms(100);
matrix.pixel_rgb(x, y, 0, 0, 0).expect("couldn't turn off");
}
}
}
}
53 changes: 0 additions & 53 deletions examples/adafruit_rgb/examples/stm32.rs

This file was deleted.

17 changes: 11 additions & 6 deletions examples/ledmatrix/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
[package]
[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"
embedded-hal = "1.0"
cortex-m = "0.7.7"
cortex-m-rt = "0.7.3"
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-hal = { version = "0.11.0", features = ["rt", "critical-section-impl"] }
rp2040-panic-usb-boot = "0.6.0"
rp2040-boot2 = "0.3"

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"
14 changes: 13 additions & 1 deletion examples/ledmatrix/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Framework LED Matrix

## Build and run
## Build and run with flip-link

Make sure you're in bootloader mode and then run the following command, which
automatically flashes the matrix.
Expand All @@ -9,3 +9,15 @@ automatically flashes the matrix.
cargo install flip-link
cargo run --example ledtest
```

## Building a UF2 file

To create a UF2 file for manual flashing:

```
cargo install elf2uf2-rs
cargo build --example ledtest
elf2uf2-rs target/thumbv6m-none-eabi/debug/examples/ledtest ledtest.uf2
```

Then copy `ledtest.uf2` to the RP2040 mass storage device while in bootloader mode.
Loading