Skip to content

Commit

Permalink
Add RP2040 QT PY Example
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Schaefer <dhs@frame.work>
  • Loading branch information
JohnAZoidberg committed Oct 9, 2023
1 parent c6e0710 commit f215351
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
target

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
12 changes: 12 additions & 0 deletions examples/qt-py-rp2040/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[build]
target = "thumbv6m-none-eabi"

[target.thumbv6m-none-eabi]
runner = "elf2uf2-rs -d"
# runner = "picotool load -x -t elf"
# runner = "probe-run --chip RP2040"

rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=--nmagic",
]
19 changes: 19 additions & 0 deletions examples/qt-py-rp2040/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
edition = "2021"
name = "is31fl3741-qt-py-rp2040"
version = "0.3.0"

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

cortex-m-rt = "0.7.3"
cortex-m = "0.7.7"
panic-halt = "0.2.0"
rp-pico = "0.7.0"
adafruit-qt-py-rp2040 = {version = "0.6.0", features = ["rt"]}
tinybmp = "0.5.0"
embedded-graphics = "0.8.1"
fugit = "0.3.7"

is31fl3743a = { path = "../.." }
31 changes: 31 additions & 0 deletions examples/qt-py-rp2040/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());

// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x");
}
15 changes: 15 additions & 0 deletions examples/qt-py-rp2040/memory.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MEMORY {
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
RAM : ORIGIN = 0x20000000, LENGTH = 256K
}

EXTERN(BOOT2_FIRMWARE)

SECTIONS {
/* ### Boot loader */
.boot2 ORIGIN(BOOT2) :
{
KEEP(*(.boot2));
} > BOOT2
} INSERT BEFORE .text;
77 changes: 77 additions & 0 deletions examples/qt-py-rp2040/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#![no_std]
#![no_main]

// pick a panicking behavior
use panic_halt as _;

use adafruit_qt_py_rp2040::entry;
use adafruit_qt_py_rp2040::{
hal::{
clocks::{init_clocks_and_plls, Clock},
i2c::I2C,
pac,
watchdog::Watchdog,
Sio,
},
Pins, XOSC_CRYSTAL_FREQ,
};
use fugit::RateExtU32;
use is31fl3743a::devices::UnknownDevice;

#[entry]
fn main() -> ! {
let mut pac = pac::Peripherals::take().unwrap();
let core = pac::CorePeripherals::take().unwrap();

let mut watchdog = Watchdog::new(pac.WATCHDOG);

let clocks = init_clocks_and_plls(
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 sio = Sio::new(pac.SIO);
let pins = Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);

// Using STEMMA QT connector
let sda = pins.sda1.into_mode(); // gpio22
let scl = pins.scl1.into_mode(); // gpio23

//let sda = pins.sda.into_mode(); // gpio24
//let scl = pins.scl.into_mode(); // gpio25

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

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

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

loop {
matrix.device.fill(0xFF).expect("couldn't turn on");
delay.delay_ms(100u32);
matrix.device.fill(0x00).expect("couldn't turn off");
}
}
46 changes: 0 additions & 46 deletions examples/stm32.rs

This file was deleted.

0 comments on commit f215351

Please sign in to comment.