Skip to content
Snippets Groups Projects
Commit 2fa7b3b9 authored by zdmx's avatar zdmx :crab:
Browse files

Split crates into bsp, runtime and template

parent 2b99b24c
No related branches found
No related tags found
No related merge requests found
Showing with 158 additions and 145 deletions
......@@ -704,6 +704,18 @@ dependencies = [
"tinybmp",
]
[[package]]
name = "flow3-rs-rt"
version = "0.1.0"
dependencies = [
"embassy-executor",
"embassy-time",
"esp32s3-hal",
"flow3-rs",
"shared-bus",
"static_cell",
]
[[package]]
name = "fnv"
version = "1.0.7"
......@@ -1272,6 +1284,39 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "template"
version = "0.1.0"
dependencies = [
"ad7147",
"bmi270",
"byte-slice-cast 1.2.2",
"display-interface 0.5.0-alpha.1",
"embassy-executor",
"embassy-futures",
"embassy-net",
"embassy-net-badgelink",
"embassy-sync",
"embassy-time",
"embedded-dma",
"embedded-graphics",
"embedded-graphics-framebuf",
"embedded-hal 0.2.7",
"embedded-hal 1.0.0-alpha.10",
"embedded-hal-async",
"embedded-hal-bus",
"esp-backtrace",
"esp-println",
"esp32s3-hal",
"flow3-rs",
"flow3-rs-rt",
"heapless",
"smart-leds",
"smoltcp",
"static_cell",
"tinybmp",
]
[[package]]
name = "tinybmp"
version = "0.5.0"
......
......@@ -4,12 +4,11 @@ version = "0.1.0"
edition = "2021"
authors = ["zdmx <hi@zdmx.me>"]
[dependencies]
ad7147 = { path = "./ad7147" }
bmi270 = { path = "./bmi270" }
ad7147 = { path = "./vendor/ad7147" }
bmi270 = { path = "./vendor/bmi270" }
byte-slice-cast = { version = "1.2.2", default-features = false }
display-interface = { path = "./display-interface", features = ["nightly", "async", "dma"] }
display-interface = { path = "./vendor/display-interface", features = ["nightly", "async", "dma"] }
embassy-executor = { version = "0.2.0", features = ["nightly", "arch-xtensa", "executor-thread", "integrated-timers"] }
embassy-futures = "0.1.0"
embassy-net = { version = "0.1.0", features = ["medium-ethernet", "udp", "proto-ipv6", "nightly", "unstable-traits"] }
......@@ -26,7 +25,7 @@ embedded-hal-bus = "0.1.0-alpha.2"
esp-backtrace = { version = "0.7.0", features = ["esp32s3", "panic-handler", "exception-handler", "print-uart"] }
esp-hal-smartled = { version = "0.3.0", features = ["esp32s3"] }
esp-println = { version = "0.5.0", features = ["esp32s3"] }
gc9a01 = { path = "./gc9a01" }
gc9a01 = { path = "./vendor/gc9a01" }
hal = { package = "esp32s3-hal", version = "0.10.0", features = ["embassy", "async", "embassy-time", "embassy-time-systick"] }
heapless = "0.7.16"
port-expander = "0.4.0"
......@@ -35,3 +34,12 @@ smart-leds = "0.3.0"
smoltcp = { version = "0.10.0", default-features = false }
static_cell = "1.2.0"
tinybmp = "0.5.0"
[workspace]
members = [
"vendor/ad7147",
"vendor/bmi270",
"embassy-net-badgelink",
"flow3-rs-rt",
"template"
]
\ No newline at end of file
[package]
name = "flow3-rs-rt"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
embassy-executor = { version = "0.2.0", features = ["nightly", "arch-xtensa", "executor-thread", "integrated-timers"] }
hal = { package = "esp32s3-hal", version = "0.10.0", features = ["embassy", "async", "embassy-time", "embassy-time-systick"] }
embassy-time = { version = "=0.1.1", features = ["nightly", "unstable-traits"] }
static_cell = "1.2.0"
shared-bus = { version = "0.3.0", features = ["xtensa"] }
flow3-rs = { path = "../" }
\ No newline at end of file
#![no_std]
#![feature(type_alias_impl_trait)]
mod runtime;
pub use runtime::start_runtime;
\ No newline at end of file
use embassy_executor::{Executor, Spawner};
use embassy_executor::{Executor, Spawner, SpawnToken};
use embassy_time::{Duration, Timer};
use esp_println::println;
use hal::{
clock::{ClockControl, Clocks},
cpu_control::CpuControl,
......@@ -13,11 +12,11 @@ use hal::{
pulse_control::ClockSource,
systimer::SystemTimer,
timer::TimerGroup,
PulseControl, Rng, Rtc, Spi, Uart, IO, uart::{self, TxRxPins}, gpio::{Gpio6, Unknown, Gpio4, Gpio7, Gpio5},
PulseControl, Rng, Rtc, Spi, Uart, IO, uart::{self, TxRxPins},
};
use static_cell::StaticCell;
use crate::flow3r::{
use flow3_rs::{
badgelink::BadgeLink,
captouch::{captouch_controller, CaptouchHandler},
display::Display,
......@@ -26,7 +25,6 @@ use crate::flow3r::{
leds::init_leds,
Flow3r,
};
use crate::main;
const READ_BUF_SIZE: usize = 64;
......@@ -35,10 +33,10 @@ static EXECUTOR: StaticCell<Executor> = StaticCell::new();
//static APP_CORE_EXECUTOR: StaticCell<Executor> = StaticCell::new();
static CLOCKS: StaticCell<Clocks> = StaticCell::new();
pub fn start_runtime() -> ! {
pub fn start_runtime(main_function: fn(Flow3r) -> SpawnToken<*mut fn()>) -> ! {
let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| {
spawner.spawn(init_runtime()).ok();
spawner.spawn(init_runtime(main_function)).ok();
});
}
......@@ -57,8 +55,7 @@ async fn start_app_core(mut cpu_control: CpuControl) -> ! {
}
#[embassy_executor::task]
async fn init_runtime() {
esp_println::println!("Init!");
async fn init_runtime(main_function: fn(Flow3r) -> SpawnToken<*mut fn()>) {
let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split();
let clocks = CLOCKS.init(ClockControl::boot_defaults(system.clock_control).freeze());
......@@ -199,7 +196,7 @@ async fn init_runtime() {
// Init Flow3r components
let mut badgelink = BadgeLink::new(i2c_busmanager.acquire_i2c());
let badgelink = BadgeLink::new(i2c_busmanager.acquire_i2c());
let imu = ImuHandler::new(i2c_busmanager.acquire_i2c());
let inputs = InputHandler;
let captouch = CaptouchHandler;
......@@ -228,55 +225,5 @@ async fn init_runtime() {
.ok();
// Hand over to main task
spawner.spawn(main(flow3r)).ok();
/*spawner.spawn(test_pins_a(io.pins.gpio5)).unwrap();
spawner.spawn(test_pins_b(io.pins.gpio6)).unwrap();
spawner.spawn(test_pins_c(io.pins.gpio4)).unwrap();
spawner.spawn(test_pins_d(io.pins.gpio7)).unwrap();*/
spawner.spawn::<*mut fn()>(main_function(flow3r)).ok();
}
\ No newline at end of file
/*
#[embassy_executor::task]
async fn test_pins_a(pin: Gpio5<Unknown>) -> ! {
let mut pin = pin.into_push_pull_output();
println!("toggle task running");
loop {
pin.set_high().unwrap();
Timer::after(Duration::from_secs(1)).await;
pin.set_low().unwrap();
Timer::after(Duration::from_secs(1)).await;
}
}
#[embassy_executor::task]
async fn test_pins_d(pin: Gpio7<Unknown>) -> ! {
let mut pin = pin.into_push_pull_output();
println!("toggle task running");
loop {
pin.set_high().unwrap();
Timer::after(Duration::from_secs(1)).await;
pin.set_low().unwrap();
Timer::after(Duration::from_secs(1)).await;
}
}
#[embassy_executor::task]
async fn test_pins_b(pin: Gpio6<Unknown>) -> ! {
let mut pin = pin.into_floating_input();
println!("wait task running");
loop {
pin.wait_for_any_edge().await.unwrap();
println!("pin 5 changed, is now {}", pin.is_high().unwrap());
}
}
#[embassy_executor::task]
async fn test_pins_c(pin: Gpio4<Unknown>) -> ! {
let mut pin = pin.into_floating_input();
println!("wait task running");
loop {
pin.wait_for_any_edge().await.unwrap();
println!("pin 4 changed, is now {}", pin.is_high().unwrap());
}
} */
\ No newline at end of file
use embassy_executor::Spawner;
use embassy_net::{Config, Ipv6Address, Ipv6Cidr, Stack, StackResources, StaticConfigV6};
use embassy_net::{Config, Stack, StackResources};
use embassy_net_badgelink::{Device, Runner, State};
use esp_println::println;
use hal::{
efuse::Efuse,
peripherals::{UART0, UART1, UART2},
Rng, Uart,
peripherals::{UART1, UART2},
Uart,
};
use heapless::Vec;
use static_cell::StaticCell;
static STATE_LEFT: StaticCell<State<8, 8>> = StaticCell::new();
......
use hal::{i2c::I2C, peripherals::{I2C0, UART0, UART1}, Uart, Rng};
use hal::{i2c::I2C, peripherals::I2C0};
use port_expander::{dev::max7321::Driver, Max7321};
use shared_bus::{I2cProxy, NullMutex, XtensaMutex};
......
......@@ -7,7 +7,6 @@ use embassy_futures::select::{select, Either};
use embassy_sync::{
blocking_mutex::raw::CriticalSectionRawMutex,
mutex::Mutex,
pubsub::{PubSubChannel, Subscriber},
};
use embassy_time::Delay;
use embedded_hal_async::digital::Wait;
......@@ -19,50 +18,37 @@ use hal::{
};
use shared_bus::{I2cProxy, XtensaMutex};
static CAPTOUCH_CHANNEL: PubSubChannel<CriticalSectionRawMutex, Flow3rCaptouchEvent, 32, 32, 32> =
PubSubChannel::<CriticalSectionRawMutex, Flow3rCaptouchEvent, 32, 32, 32>::new();
pub type CaptouchEventListener =
Subscriber<'static, CriticalSectionRawMutex, Flow3rCaptouchEvent, 32, 32, 32>;
static PETALS: Mutex<CriticalSectionRawMutex, [Flow3rPetal; 10]> = Mutex::new([
Flow3rPetal::new(0, Flow3rCaptouchController::TOP),
Flow3rPetal::new(1, Flow3rCaptouchController::BOTTOM),
Flow3rPetal::new(2, Flow3rCaptouchController::TOP),
Flow3rPetal::new(3, Flow3rCaptouchController::BOTTOM),
Flow3rPetal::new(4, Flow3rCaptouchController::TOP),
Flow3rPetal::new(5, Flow3rCaptouchController::BOTTOM),
Flow3rPetal::new(6, Flow3rCaptouchController::TOP),
Flow3rPetal::new(7, Flow3rCaptouchController::BOTTOM),
Flow3rPetal::new(8, Flow3rCaptouchController::TOP),
Flow3rPetal::new(9, Flow3rCaptouchController::BOTTOM),
Flow3rPetal::new(Flow3rCaptouchController::TOP),
Flow3rPetal::new(Flow3rCaptouchController::BOTTOM),
Flow3rPetal::new(Flow3rCaptouchController::TOP),
Flow3rPetal::new(Flow3rCaptouchController::BOTTOM),
Flow3rPetal::new(Flow3rCaptouchController::TOP),
Flow3rPetal::new(Flow3rCaptouchController::BOTTOM),
Flow3rPetal::new(Flow3rCaptouchController::TOP),
Flow3rPetal::new(Flow3rCaptouchController::BOTTOM),
Flow3rPetal::new(Flow3rCaptouchController::TOP),
Flow3rPetal::new(Flow3rCaptouchController::BOTTOM),
]);
#[derive(Debug, Clone, Copy)]
struct Flow3rCaptouchEvent {
petals: [Flow3rPetal; 5],
}
#[derive(Debug, Clone, Copy)]
pub enum Flow3rPetal {
enum Flow3rPetal {
TOP {
number: u8,
ccw: Flow3rPetalPart,
base: Flow3rPetalPart,
cw: Flow3rPetalPart,
},
BOTTOM {
number: u8,
base: Flow3rPetalPart,
tip: Flow3rPetalPart,
},
}
impl Flow3rPetal {
const fn new(num: u8, pos: Flow3rCaptouchController) -> Flow3rPetal {
const fn new(pos: Flow3rCaptouchController) -> Flow3rPetal {
match pos {
Flow3rCaptouchController::TOP => Self::TOP {
number: num,
ccw: Flow3rPetalPart {
pressed: false,
raw: 0,
......@@ -77,7 +63,6 @@ impl Flow3rPetal {
},
},
Flow3rCaptouchController::BOTTOM => Self::BOTTOM {
number: num,
base: Flow3rPetalPart {
pressed: false,
raw: 0,
......@@ -93,48 +78,22 @@ impl Flow3rPetal {
pub fn pressed(&self) -> bool {
match self {
Flow3rPetal::TOP {
number,
ccw,
base,
cw,
} => ccw.pressed | base.pressed | cw.pressed,
Flow3rPetal::BOTTOM { number, base, tip } => base.pressed | tip.pressed,
Flow3rPetal::BOTTOM { base, tip } => base.pressed | tip.pressed,
}
}
pub fn position(&self) -> i32 {
match self {
Flow3rPetal::TOP {
number,
ccw,
base,
cw,
} => (ccw.raw as i32 + cw.raw as i32) / 2 - base.raw as i32,
Flow3rPetal::BOTTOM { number, base, tip } => base.raw as i32 + tip.raw as i32 / 2,
}
}
pub fn number(&self) -> u8 {
match self {
Flow3rPetal::TOP {
number,
ccw,
base,
cw,
} => *number,
Flow3rPetal::BOTTOM { number, base, tip } => *number,
}
}
fn update(&mut self, pressed: &[bool], values: &[u16]) {
match self {
Flow3rPetal::TOP {
number,
ccw,
base,
cw,
} => ccw.pressed = pressed[0],
Flow3rPetal::BOTTOM { number, base, tip } => todo!(),
Flow3rPetal::BOTTOM {base, tip } => base.raw as i32 + tip.raw as i32 / 2,
}
}
}
......@@ -478,15 +437,15 @@ pub async fn captouch_controller(
loop {
match select(cap_bot_int.wait_for_low(), cap_top_int.wait_for_low()).await {
Either::First(_) => {
let interrupts = ad7147_bot.read_interrupt_registers().unwrap();
let _ = ad7147_bot.read_interrupt_registers().unwrap();
let measurements_bot = ad7147_bot.read_all_stages().unwrap();
// println!("pad 0: {}, {}, {}, {}", measurements_bot[0], measurements_bot[1], interrupts[1] & (1 << 0) != 0, interrupts[1] & (1 << 1) != 0);
update_petals_bot(interrupts[1], measurements_bot).await;
update_petals_bot(measurements_bot).await;
}
Either::Second(_) => {
let interrupts = ad7147_top.read_interrupt_registers().unwrap();
let _ = ad7147_top.read_interrupt_registers().unwrap();
let measurements_top = ad7147_top.read_all_stages().unwrap();
update_petals_top(interrupts[1], measurements_top).await;
update_petals_top(measurements_top).await;
}
}
}
......@@ -515,7 +474,7 @@ static PETAL_MAPPING_TOP: [(usize, PetalPosition); 12] = [
(6, PetalPosition::BASE),
];
async fn update_petals_top(interrupts: u16, measurements: [u16; 12]) {
async fn update_petals_top(measurements: [u16; 12]) {
let mut petals = PETALS.lock().await;
for (i, m) in PETAL_MAPPING_TOP.iter().enumerate() {
let pressed = measurements[i] > 50000;
......@@ -575,7 +534,7 @@ static PETAL_MAPPPING_BOT: [(usize, PetalPosition); 12] = [
(2, PetalPosition::CW),
];
async fn update_petals_bot(interrupts: u16, measurements: [u16; 12]) {
async fn update_petals_bot(measurements: [u16; 12]) {
let mut petals = PETALS.lock().await;
for (i, m) in PETAL_MAPPPING_BOT.iter().enumerate() {
let pressed = measurements[i] > 40000;
......
File moved
File moved
File moved
......@@ -11,7 +11,6 @@ impl ImuHandler {
pub fn new(i2c: I2cProxy<'static, XtensaMutex<I2C<'static, I2C0>>>) -> Self {
let mut bmi270 = Bmi270::new_i2c(i2c, bmi270::I2cAddr::Default, bmi270::Burst::Max);
/*
if let Some(chip_id) = bmi270.get_chip_id().ok() {
println!("imu chip id: {}", chip_id);
}
......@@ -24,7 +23,7 @@ impl ImuHandler {
acc_en: true,
temp_en: false,
};
bmi270.set_pwr_ctrl(pwr_ctrl).ok();*/
bmi270.set_pwr_ctrl(pwr_ctrl).ok();
Self { imu: bmi270 }
}
......
File moved
File moved
use hal::{Uart, Rng};
use hal::peripherals::{UART0, UART1};
#![no_std]
#![feature(type_alias_impl_trait, async_fn_in_trait)]
use hal::Rng;
use self::badgelink::BadgeLink;
use self::badgelink::badgenet::{BadgenetUartLeft, BadgenetUartRight};
......@@ -16,7 +18,6 @@ pub mod imu;
pub mod input;
pub mod leds;
pub mod sdcard;
pub mod ui;
pub struct Flow3r {
pub badgelink: BadgeLink,
......
File moved
[package]
name = "template"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ad7147 = { path = "../vendor/ad7147" }
bmi270 = { path = "../vendor/bmi270" }
byte-slice-cast = { version = "1.2.2", default-features = false }
display-interface = { path = "../vendor/display-interface", features = ["nightly", "async", "dma"] }
embassy-executor = { version = "0.2.0", features = ["nightly", "arch-xtensa", "executor-thread", "integrated-timers"] }
embassy-futures = "0.1.0"
embassy-net = { version = "0.1.0", features = ["medium-ethernet", "udp", "proto-ipv6", "nightly", "unstable-traits"] }
embassy-net-badgelink = { path = "../embassy-net-badgelink" }
embassy-sync = "0.2.0"
embassy-time = { version = "=0.1.1", features = ["nightly", "unstable-traits"] }
embedded-dma = "0.2.0"
embedded-graphics = "0.8.0"
embedded-graphics-framebuf = "0.5.0"
embedded-hal = "0.2.7"
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" }
embedded-hal-async = "0.2.0-alpha.1"
embedded-hal-bus = "0.1.0-alpha.2"
esp-backtrace = { version = "0.7.0", features = ["esp32s3", "panic-handler", "exception-handler", "print-uart"] }
esp-println = { version = "0.5.0", features = ["esp32s3"] }
hal = { package = "esp32s3-hal", version = "0.10.0", features = ["embassy", "async", "embassy-time", "embassy-time-systick"] }
heapless = "0.7.16"
smart-leds = "0.3.0"
smoltcp = { version = "0.10.0", default-features = false }
static_cell = "1.2.0"
tinybmp = "0.5.0"
flow3-rs = { path = "../" }
flow3-rs-rt = { path = "../flow3-rs-rt" }
\ No newline at end of file
use crate::flow3r::{captouch::CaptouchHandler, display::Display, imu::ImuHandler, badgelink::{BadgeLink, badgenet::{BadgenetUartLeft, BadgenetUartRight, start_badgenet_left, start_badgenet_right}}};
use flow3_rs::{captouch::CaptouchHandler, display::Display, imu::ImuHandler, badgelink::{BadgeLink, badgenet::{BadgenetUartLeft, BadgenetUartRight, start_badgenet_left, start_badgenet_right}}};
use embassy_executor::Spawner;
use embassy_futures::select::{select, select3, Either, Either3};
use embassy_net::{udp::{UdpSocket, PacketMetadata}, Ipv6Address, Stack, StaticConfigV6, Config, Ipv6Cidr};
......@@ -14,17 +14,17 @@ use embedded_graphics::{
};
use esp_backtrace as _;
use esp_println::println;
use hal::{Rng, uart};
use hal::Rng;
use heapless::Vec;
use smoltcp::wire::IpEndpoint;
use tinybmp::Bmp;
use smart_leds::SmartLedsWrite;
use crate::flow3r::input::InputHandler;
use flow3_rs::input::InputHandler;
#[embassy_executor::task]
pub async fn leds_fade(mut leds: crate::flow3r::leds::Leds) -> ! {
pub async fn leds_fade(mut leds: flow3_rs::leds::Leds) -> ! {
let mut b = (30, false);
loop {
......@@ -35,11 +35,11 @@ pub async fn leds_fade(mut leds: crate::flow3r::leds::Leds) -> ! {
.expect("failed to set leds");
Timer::after(Duration::from_millis(30)).await;
b = crate::flow3r::leds::brightness_fade_in_out(b, 30, 0);
b = flow3_rs::leds::brightness_fade_in_out(b, 30, 0);
}
}
pub async fn display_demo(display: &mut crate::flow3r::display::Display) {
pub async fn display_demo(display: &mut flow3_rs::display::Display) {
let input = InputHandler;
let mut inputs = input.split();
......@@ -94,7 +94,7 @@ async fn move_rectangle<'a>(
}
pub async fn draw_start_screen(display: &mut Display) {
let bmp_data = include_bytes!("../img/logo.bmp");
let bmp_data = include_bytes!("../../img/logo.bmp");
let bmp = Bmp::from_slice(bmp_data).unwrap();
display
.fill_solid(&display.bounding_box(), Rgb565::WHITE)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment