Hello world
This commit is contained in:
commit
04a6c0afd3
9 changed files with 1594 additions and 0 deletions
8
firmware/.cargo/config.toml
Normal file
8
firmware/.cargo/config.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||||
|
runner = "elf2uf2-rs -d"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
target = "thumbv6m-none-eabi"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
DEFMT_LOG = "info"
|
||||||
3
firmware/.gitignore
vendored
Normal file
3
firmware/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Cargo build artifacts
|
||||||
|
/target/
|
||||||
|
**/.idea
|
||||||
1371
firmware/Cargo.lock
generated
Normal file
1371
firmware/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
51
firmware/Cargo.toml
Normal file
51
firmware/Cargo.toml
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
[package]
|
||||||
|
edition = "2024"
|
||||||
|
name = "led-mask"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Adam Gausmann <adam@gaussian.dev>"]
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "led-mask"
|
||||||
|
test = false
|
||||||
|
bench = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
defmt = "1.0"
|
||||||
|
defmt-rtt = "1.1"
|
||||||
|
panic-probe = { version = "1.0", features = ["print-defmt"] }
|
||||||
|
|
||||||
|
embedded-hal = "1.0.0"
|
||||||
|
embedded-hal-async = "1.0.0"
|
||||||
|
embedded-io = "0.6.1"
|
||||||
|
embedded-io-async = "0.6.1"
|
||||||
|
embedded-storage = "0.3.1"
|
||||||
|
|
||||||
|
cortex-m-rt = "0.7.3"
|
||||||
|
|
||||||
|
embassy-executor = { version = "0.9", features = [
|
||||||
|
"arch-cortex-m",
|
||||||
|
"executor-thread",
|
||||||
|
"defmt",
|
||||||
|
"executor-interrupt",
|
||||||
|
] }
|
||||||
|
embassy-sync = "0.7"
|
||||||
|
embassy-time = { version = "0.5", features = [
|
||||||
|
"defmt",
|
||||||
|
"defmt-timestamp-uptime",
|
||||||
|
] }
|
||||||
|
cortex-m = { version = "0.7.7" }
|
||||||
|
embassy-rp = { version = "0.8", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl", "rp2040", "boot2-w25q080"] }
|
||||||
|
embedded-graphics = "0.8"
|
||||||
|
mipidsi = "0.9.0"
|
||||||
|
embedded-hal-bus = "0.3.0"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
debug = 2
|
||||||
|
lto = true
|
||||||
|
opt-level = 'z'
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
debug = 2
|
||||||
|
lto = true
|
||||||
|
opt-level = "z"
|
||||||
36
firmware/build.rs
Normal file
36
firmware/build.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
//! 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");
|
||||||
|
|
||||||
|
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||||
|
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||||
|
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||||
|
println!("cargo:rustc-link-arg-bins=-Tlink-rp.x");
|
||||||
|
}
|
||||||
7
firmware/memory.x
Normal file
7
firmware/memory.x
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
|
||||||
|
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
|
||||||
|
RAM : ORIGIN = 0x20000000, LENGTH = 264K
|
||||||
|
}
|
||||||
|
|
||||||
11
firmware/rust-toolchain.toml
Normal file
11
firmware/rust-toolchain.toml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Before upgrading check that everything is available on all tier1 targets here:
|
||||||
|
# https://rust-lang.github.io/rustup-components-history
|
||||||
|
[toolchain]
|
||||||
|
channel = "stable"
|
||||||
|
components = [ "rustfmt" ]
|
||||||
|
targets = [
|
||||||
|
"thumbv6m-none-eabi",
|
||||||
|
"thumbv7em-none-eabihf",
|
||||||
|
"thumbv8m.main-none-eabihf",
|
||||||
|
"riscv32imac-unknown-none-elf",
|
||||||
|
]
|
||||||
BIN
firmware/src/assets/ferris.raw
Normal file
BIN
firmware/src/assets/ferris.raw
Normal file
Binary file not shown.
107
firmware/src/main.rs
Normal file
107
firmware/src/main.rs
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_rp::gpio::{Input, Level, Output, Pull};
|
||||||
|
use embassy_rp::pwm::{self, Pwm};
|
||||||
|
use embassy_time::{Delay, Timer};
|
||||||
|
use embedded_hal_bus::spi::ExclusiveDevice;
|
||||||
|
use mipidsi::interface::SpiInterface;
|
||||||
|
use mipidsi::models::ST7789;
|
||||||
|
use mipidsi::options::Orientation;
|
||||||
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
use embassy_rp::spi;
|
||||||
|
use embassy_rp::spi::{Blocking, Spi};
|
||||||
|
use embedded_graphics::image::{Image, ImageRawLE};
|
||||||
|
use embedded_graphics::mono_font::MonoTextStyle;
|
||||||
|
use embedded_graphics::mono_font::ascii::FONT_10X20;
|
||||||
|
use embedded_graphics::pixelcolor::Rgb565;
|
||||||
|
use embedded_graphics::prelude::*;
|
||||||
|
use embedded_graphics::text::Text;
|
||||||
|
|
||||||
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
const DISPLAY_FREQ: u32 = 64_000_000;
|
||||||
|
|
||||||
|
#[embassy_executor::main]
|
||||||
|
async fn main(_spawner: Spawner) -> ! {
|
||||||
|
let p = embassy_rp::init(Default::default());
|
||||||
|
|
||||||
|
// display SPI
|
||||||
|
|
||||||
|
let mut display_buffer = [0u8; 512];
|
||||||
|
|
||||||
|
let mut display = {
|
||||||
|
let mut config = spi::Config::default();
|
||||||
|
config.frequency = DISPLAY_FREQ;
|
||||||
|
config.phase = spi::Phase::CaptureOnSecondTransition;
|
||||||
|
config.polarity = spi::Polarity::IdleHigh;
|
||||||
|
let clk = p.PIN_18;
|
||||||
|
let mosi = p.PIN_19;
|
||||||
|
let spi_bus: Spi<'_, _, Blocking> = Spi::new_blocking_txonly(p.SPI0, clk, mosi, config);
|
||||||
|
let cs = Output::new(p.PIN_17, Level::High);
|
||||||
|
let spi_dev = ExclusiveDevice::new(spi_bus, cs, Delay).expect("set cs high");
|
||||||
|
|
||||||
|
let dc = Output::new(p.PIN_16, Level::Low);
|
||||||
|
|
||||||
|
let di = SpiInterface::new(spi_dev, dc, &mut display_buffer);
|
||||||
|
mipidsi::Builder::new(ST7789, di)
|
||||||
|
.color_order(mipidsi::options::ColorOrder::Rgb)
|
||||||
|
.invert_colors(mipidsi::options::ColorInversion::Inverted)
|
||||||
|
.display_size(135, 240)
|
||||||
|
.display_offset(52, 40)
|
||||||
|
.orientation(Orientation::new().rotate(mipidsi::options::Rotation::Deg90))
|
||||||
|
.init(&mut Delay)
|
||||||
|
.expect("display init")
|
||||||
|
};
|
||||||
|
let _display_backlight = Output::new(p.PIN_20, Level::High);
|
||||||
|
display.clear(Rgb565::BLACK).unwrap();
|
||||||
|
|
||||||
|
let raw_image_data = ImageRawLE::new(include_bytes!("assets/ferris.raw"), 86);
|
||||||
|
let ferris = Image::new(&raw_image_data, Point::new(0, 0));
|
||||||
|
ferris.draw(&mut display).unwrap();
|
||||||
|
|
||||||
|
let style = MonoTextStyle::new(&FONT_10X20, Rgb565::GREEN);
|
||||||
|
Text::new(
|
||||||
|
"Hello embedded_graphics \n + embassy + RP2040!",
|
||||||
|
Point::new(0, 68),
|
||||||
|
style,
|
||||||
|
)
|
||||||
|
.draw(&mut display)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// setup RGB LED
|
||||||
|
let mut rg_config = pwm::Config::default();
|
||||||
|
rg_config.compare_a = 0xffff;
|
||||||
|
rg_config.compare_b = 0xffff;
|
||||||
|
let mut b_config = pwm::Config::default();
|
||||||
|
b_config.compare_a = 0xffff;
|
||||||
|
let mut rg_pwm = Pwm::new_output_ab(p.PWM_SLICE3, p.PIN_6, p.PIN_7, rg_config.clone());
|
||||||
|
let mut b_pwm = Pwm::new_output_a(p.PWM_SLICE4, p.PIN_8, b_config.clone());
|
||||||
|
|
||||||
|
let mut set_led = |r: u8, g: u8, b: u8| {
|
||||||
|
rg_config.compare_a = 0x101 * (255 - r as u16);
|
||||||
|
rg_config.compare_b = 0x101 * (255 - g as u16);
|
||||||
|
b_config.compare_a = 0x101 * (255 - b as u16);
|
||||||
|
rg_pwm.set_config(&rg_config);
|
||||||
|
b_pwm.set_config(&b_config);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Setup buzzer
|
||||||
|
let mut buzzer_config = pwm::Config::default();
|
||||||
|
buzzer_config.compare_b = 0x4000;
|
||||||
|
buzzer_config.enable = false;
|
||||||
|
let _buzzer_pwm = Pwm::new_output_b(p.PWM_SLICE5, p.PIN_11, buzzer_config.clone());
|
||||||
|
|
||||||
|
// Setup buttons
|
||||||
|
let _btn_a = Input::new(p.PIN_12, Pull::Up);
|
||||||
|
let _btn_b = Input::new(p.PIN_13, Pull::Up);
|
||||||
|
let _btn_x = Input::new(p.PIN_14, Pull::Up);
|
||||||
|
let _btn_y = Input::new(p.PIN_15, Pull::Up);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
Timer::after_millis(100).await;
|
||||||
|
set_led(0, 0, 63);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue