Compare commits
3 Commits
usb-mass-s
...
ui
| Author | SHA1 | Date | |
|---|---|---|---|
| e95774ae16 | |||
| bd7c4e3e27 | |||
| 55b7c2970c |
37
Cargo.lock
generated
37
Cargo.lock
generated
@@ -27,6 +27,12 @@ version = "0.7.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrform"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e7cf566ecc5c9d82b973e81d30babf6583c9b497f86295c952d538c3254ef4e6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ascii-canvas"
|
name = "ascii-canvas"
|
||||||
version = "3.0.0"
|
version = "3.0.0"
|
||||||
@@ -759,6 +765,27 @@ dependencies = [
|
|||||||
"embedded-io",
|
"embedded-io",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-layout"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a90553247f2b05c59ac7894ea13d830636c2b1203fa03bff400eddbd1fa9f52"
|
||||||
|
dependencies = [
|
||||||
|
"embedded-graphics",
|
||||||
|
"embedded-layout-macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-layout-macros"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4f6e621fe4c7e05b695274b722dc0a60bacd1c8696b58191baa0154713d52400"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.104",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embedded-sdmmc"
|
name = "embedded-sdmmc"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
@@ -1006,9 +1033,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.9.0"
|
version = "2.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
|
checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
@@ -1336,6 +1363,7 @@ checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315"
|
|||||||
name = "picocalc-os-rs"
|
name = "picocalc-os-rs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"arrform",
|
||||||
"bitflags 2.9.1",
|
"bitflags 2.9.1",
|
||||||
"bt-hci",
|
"bt-hci",
|
||||||
"cortex-m",
|
"cortex-m",
|
||||||
@@ -1352,9 +1380,12 @@ dependencies = [
|
|||||||
"embassy-time",
|
"embassy-time",
|
||||||
"embedded-graphics",
|
"embedded-graphics",
|
||||||
"embedded-hal 0.2.7",
|
"embedded-hal 0.2.7",
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
"embedded-hal-async",
|
"embedded-hal-async",
|
||||||
"embedded-hal-bus",
|
"embedded-hal-bus",
|
||||||
|
"embedded-layout",
|
||||||
"embedded-sdmmc",
|
"embedded-sdmmc",
|
||||||
|
"heapless",
|
||||||
"panic-probe",
|
"panic-probe",
|
||||||
"portable-atomic",
|
"portable-atomic",
|
||||||
"st7365p-lcd",
|
"st7365p-lcd",
|
||||||
@@ -1730,10 +1761,10 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "st7365p-lcd"
|
name = "st7365p-lcd"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
source = "git+https://github.com/legitcamper/st7365p-lcd-rs#d751e8d30f1a3f964ffe05e4bb16f82112fbefce"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"embedded-graphics-core",
|
"embedded-graphics-core",
|
||||||
"embedded-hal 1.0.0",
|
"embedded-hal 1.0.0",
|
||||||
|
"embedded-hal-async",
|
||||||
"nb 1.1.0",
|
"nb 1.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
12
Cargo.toml
12
Cargo.toml
@@ -60,18 +60,22 @@ cyw43-pio = { version = "0.3.0", optional = true }
|
|||||||
|
|
||||||
embedded-hal-bus = { version = "0.3.0", features = ["async"] }
|
embedded-hal-bus = { version = "0.3.0", features = ["async"] }
|
||||||
embedded-hal = "0.2.7"
|
embedded-hal = "0.2.7"
|
||||||
|
embedded-hal-1 = { version = "1.0.0", package = "embedded-hal" }
|
||||||
embedded-hal-async = "1.0.0"
|
embedded-hal-async = "1.0.0"
|
||||||
cortex-m = { version = "0.7.7" }
|
cortex-m = { version = "0.7.7" }
|
||||||
cortex-m-rt = "0.7.5"
|
cortex-m-rt = "0.7.5"
|
||||||
panic-probe = "0.3"
|
panic-probe = "0.3"
|
||||||
portable-atomic = { version = "1.11", features = ["critical-section"] }
|
portable-atomic = { version = "1.11", features = ["critical-section"] }
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
bitflags = "2.9.1"
|
||||||
|
heapless = "0.8.0"
|
||||||
|
arrform = "0.1.1"
|
||||||
|
|
||||||
defmt = { version = "0.3", optional = true }
|
defmt = { version = "0.3", optional = true }
|
||||||
defmt-rtt = "0.4.2"
|
defmt-rtt = "0.4.2"
|
||||||
|
|
||||||
embedded-graphics = { version = "0.8.1" }
|
embedded-graphics = { version = "0.8.1" }
|
||||||
|
embedded-layout = "0.4.2"
|
||||||
embedded-sdmmc = { git = "https://github.com/Be-ing/embedded-sdmmc-rs", branch = "bisync", default-features = false }
|
embedded-sdmmc = { git = "https://github.com/Be-ing/embedded-sdmmc-rs", branch = "bisync", default-features = false }
|
||||||
st7365p-lcd = { git = "https://github.com/legitcamper/st7365p-lcd-rs" }
|
# st7365p-lcd = { git = "https://github.com/legitcamper/st7365p-lcd-rs", branch = "async" }
|
||||||
|
st7365p-lcd = { path = "../ST7365P-lcd-rs" }
|
||||||
static_cell = "2.1.1"
|
|
||||||
bitflags = "2.9.1"
|
|
||||||
|
|||||||
243
src/display.rs
243
src/display.rs
@@ -1,113 +1,180 @@
|
|||||||
|
use arrform::{ArrForm, arrform};
|
||||||
|
use core::fmt::Debug;
|
||||||
|
use defmt::info;
|
||||||
use embassy_rp::{
|
use embassy_rp::{
|
||||||
gpio::{Level, Output},
|
gpio::{Level, Output},
|
||||||
peripherals::{PIN_13, PIN_14, PIN_15, SPI1},
|
peripherals::{PIN_13, PIN_14, PIN_15, SPI1},
|
||||||
spi::{Blocking, Spi},
|
spi::{Async, Spi},
|
||||||
};
|
};
|
||||||
use embassy_time::{Delay, Timer};
|
use embassy_time::{Delay, Timer};
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
Drawable, Pixel,
|
Drawable,
|
||||||
pixelcolor::{Rgb565, raw::RawU16},
|
draw_target::DrawTarget,
|
||||||
prelude::{DrawTarget, OriginDimensions, Point, Primitive, RawData, RgbColor, Size},
|
mono_font::{
|
||||||
primitives::{PrimitiveStyle, Rectangle},
|
MonoTextStyle,
|
||||||
|
ascii::{FONT_6X10, FONT_9X15, FONT_10X20},
|
||||||
|
},
|
||||||
|
pixelcolor::Rgb565,
|
||||||
|
prelude::{Point, RgbColor, Size},
|
||||||
|
primitives::{PrimitiveStyle, Rectangle, StyledDrawable},
|
||||||
|
text::Text,
|
||||||
};
|
};
|
||||||
use embedded_hal_bus::spi::ExclusiveDevice;
|
use embedded_hal_1::digital::OutputPin;
|
||||||
use st7365p_lcd::{Orientation, ST7365P};
|
use embedded_hal_async::spi::SpiDevice;
|
||||||
|
use embedded_hal_bus::spi::{ExclusiveDevice, NoDelay};
|
||||||
|
use embedded_layout::{
|
||||||
|
align::{horizontal, vertical},
|
||||||
|
layout::linear::LinearLayout,
|
||||||
|
object_chain::Chain,
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
use heapless::{String, Vec};
|
||||||
|
use st7365p_lcd::{FrameBuffer, Orientation, ST7365P};
|
||||||
|
|
||||||
#[embassy_executor::task]
|
pub const SCREEN_WIDTH: usize = 320;
|
||||||
pub async fn display_task(
|
pub const SCREEN_HEIGHT: usize = 320;
|
||||||
spi: Spi<'static, SPI1, Blocking>,
|
|
||||||
cs: PIN_13,
|
|
||||||
data: PIN_14,
|
|
||||||
reset: PIN_15,
|
|
||||||
) {
|
|
||||||
let spi_device = ExclusiveDevice::new(spi, Output::new(cs, Level::Low), Delay).unwrap();
|
|
||||||
let mut display = ST7365P::new(
|
|
||||||
spi_device,
|
|
||||||
Output::new(data, Level::Low),
|
|
||||||
Some(Output::new(reset, Level::High)),
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
320,
|
|
||||||
320,
|
|
||||||
);
|
|
||||||
display.init(&mut Delay).unwrap();
|
|
||||||
display.set_orientation(&Orientation::Landscape).unwrap();
|
|
||||||
let mut virtual_display = VirtualDisplay::new(display, 320 / 2, 320 / 2);
|
|
||||||
|
|
||||||
let thin_stroke = PrimitiveStyle::with_stroke(Rgb565::RED, 20);
|
pub const STATUS_BAR_WIDTH: usize = 320;
|
||||||
|
pub const STATUS_BAR_HEIGHT: usize = 40;
|
||||||
|
|
||||||
Rectangle::new(Point::new(10, 10), Size::new(100, 100))
|
pub type FRAMEBUFFER = FrameBuffer<
|
||||||
.into_styled(thin_stroke)
|
SCREEN_WIDTH,
|
||||||
.draw(&mut virtual_display)
|
SCREEN_HEIGHT,
|
||||||
.unwrap();
|
ExclusiveDevice<Spi<'static, SPI1, Async>, Output<'static>, Delay>,
|
||||||
|
Output<'static>,
|
||||||
|
Output<'static>,
|
||||||
|
>;
|
||||||
|
|
||||||
loop {
|
pub struct UI<const MAX_SELECTIONS: usize, const MAX_STR_LEN: usize> {
|
||||||
Timer::after_millis(500).await;
|
pub status_bar: StatusBar,
|
||||||
}
|
pub selections_list: SelectionList<MAX_SELECTIONS, MAX_STR_LEN>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// simple abstraction over real display & resolution to reduce frame buffer size
|
impl<const MAX_SELECTIONS: usize, const MAX_STR_LEN: usize> UI<MAX_SELECTIONS, MAX_STR_LEN> {
|
||||||
/// by cutting the resolution by 1/4
|
pub fn new() -> Self {
|
||||||
struct VirtualDisplay {
|
|
||||||
display: ST7365P<
|
|
||||||
ExclusiveDevice<Spi<'static, SPI1, Blocking>, Output<'static>, Delay>,
|
|
||||||
Output<'static>,
|
|
||||||
Output<'static>,
|
|
||||||
>,
|
|
||||||
width: u32,
|
|
||||||
height: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VirtualDisplay {
|
|
||||||
pub fn new(
|
|
||||||
display: ST7365P<
|
|
||||||
ExclusiveDevice<Spi<'static, SPI1, Blocking>, Output<'static>, Delay>,
|
|
||||||
Output<'static>,
|
|
||||||
Output<'static>,
|
|
||||||
>,
|
|
||||||
new_width: u32,
|
|
||||||
new_height: u32,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
display,
|
status_bar: StatusBar {
|
||||||
width: new_width,
|
battery: 100,
|
||||||
height: new_height,
|
backlight: 100,
|
||||||
|
volume: 100,
|
||||||
|
},
|
||||||
|
selections_list: SelectionList::new(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl DrawTarget for VirtualDisplay {
|
pub fn draw<D: DrawTarget<Color = Rgb565>>(&mut self, target: &mut D)
|
||||||
type Color = Rgb565;
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
|
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = Pixel<Self::Color>>,
|
<D as DrawTarget>::Error: Debug,
|
||||||
{
|
{
|
||||||
for Pixel(coord, color) in pixels.into_iter() {
|
self.draw_status_bar(target);
|
||||||
// Check bounds on the *virtual* (already reduced) resolution
|
self.draw_selection(target);
|
||||||
if coord.x >= 0
|
}
|
||||||
&& coord.y >= 0
|
|
||||||
&& coord.x < self.width as i32
|
|
||||||
&& coord.y < self.height as i32
|
|
||||||
{
|
|
||||||
let px = coord.x as u16 * 2;
|
|
||||||
let py = coord.y as u16 * 2;
|
|
||||||
let raw_color = RawU16::from(color).into_inner();
|
|
||||||
|
|
||||||
// Draw the 2x2 block on the underlying hardware
|
fn draw_selection<D: DrawTarget<Color = Rgb565>>(&mut self, target: &mut D) {
|
||||||
self.display.set_pixel(px, py, raw_color)?;
|
let text_style = MonoTextStyle::new(&FONT_9X15, Rgb565::WHITE);
|
||||||
self.display.set_pixel(px + 1, py, raw_color)?;
|
|
||||||
self.display.set_pixel(px, py + 1, raw_color)?;
|
let selection = Rectangle::new(
|
||||||
self.display.set_pixel(px + 1, py + 1, raw_color)?;
|
Point::new(0, STATUS_BAR_HEIGHT as i32 + 1),
|
||||||
}
|
Size::new(
|
||||||
|
SCREEN_WIDTH as u32,
|
||||||
|
(SCREEN_HEIGHT - STATUS_BAR_HEIGHT) as u32 - 1,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
let _ = if self.selections_list.selections.is_empty() {
|
||||||
|
LinearLayout::horizontal(Chain::new(Text::new(
|
||||||
|
"No Programs found on SD Card\nEnsure programs end with '.rhai',\nand are located in the root directory",
|
||||||
|
Point::zero(),
|
||||||
|
text_style,
|
||||||
|
)))
|
||||||
|
.arrange()
|
||||||
|
.align_to(&selection, horizontal::Center, vertical::Center).draw(target)
|
||||||
|
} else {
|
||||||
|
LinearLayout::horizontal(
|
||||||
|
Chain::new(Text::new(
|
||||||
|
arrform!(20, "Bat: {}", self.status_bar.battery).as_str(),
|
||||||
|
Point::zero(),
|
||||||
|
text_style,
|
||||||
|
))
|
||||||
|
.append(Text::new(" ", Point::zero(), text_style))
|
||||||
|
.append(Text::new(
|
||||||
|
arrform!(20, "Lght: {}", self.status_bar.backlight).as_str(),
|
||||||
|
Point::zero(),
|
||||||
|
text_style,
|
||||||
|
))
|
||||||
|
.append(Text::new(" ", Point::zero(), text_style))
|
||||||
|
.append(Text::new(
|
||||||
|
arrform!(20, "Vol: {}", self.status_bar.volume).as_str(),
|
||||||
|
Point::zero(),
|
||||||
|
text_style,
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
.arrange()
|
||||||
|
.align_to(&selection, horizontal::Left, vertical::Center)
|
||||||
|
.draw(target)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_status_bar<D: DrawTarget<Color = Rgb565>>(&mut self, target: &mut D) {
|
||||||
|
let text_style = MonoTextStyle::new(&FONT_9X15, Rgb565::WHITE);
|
||||||
|
|
||||||
|
let status_bar = Rectangle::new(
|
||||||
|
Point::new(0, 0),
|
||||||
|
Size::new(STATUS_BAR_WIDTH as u32, STATUS_BAR_HEIGHT as u32),
|
||||||
|
);
|
||||||
|
let _ = LinearLayout::horizontal(
|
||||||
|
Chain::new(Text::new(
|
||||||
|
arrform!(20, "Bat: {}", self.status_bar.battery).as_str(),
|
||||||
|
Point::zero(),
|
||||||
|
text_style,
|
||||||
|
))
|
||||||
|
.append(Text::new(
|
||||||
|
arrform!(20, "Lght: {}", self.status_bar.backlight).as_str(),
|
||||||
|
Point::zero(),
|
||||||
|
text_style,
|
||||||
|
))
|
||||||
|
.append(Text::new(
|
||||||
|
arrform!(20, "Vol: {}", self.status_bar.volume).as_str(),
|
||||||
|
Point::zero(),
|
||||||
|
text_style,
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
.arrange()
|
||||||
|
.align_to(&status_bar, horizontal::Center, vertical::Center)
|
||||||
|
.draw(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct StatusBar {
|
||||||
|
pub battery: u8,
|
||||||
|
pub backlight: u8,
|
||||||
|
pub volume: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SelectionList<const MAX_SELECTION: usize, const MAX_STR_LEN: usize> {
|
||||||
|
current_selection: u16,
|
||||||
|
selections: Vec<String<MAX_STR_LEN>, MAX_SELECTION>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const MAX_SELECTION: usize, const MAX_STR_LEN: usize>
|
||||||
|
SelectionList<MAX_SELECTION, MAX_STR_LEN>
|
||||||
|
{
|
||||||
|
pub fn new(selections: Vec<String<MAX_STR_LEN>, MAX_SELECTION>) -> Self {
|
||||||
|
Self {
|
||||||
|
selections,
|
||||||
|
current_selection: 0,
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl OriginDimensions for VirtualDisplay {
|
pub fn down(&mut self) {
|
||||||
fn size(&self) -> Size {
|
if self.current_selection + 1 < self.selections.len() as u16 {
|
||||||
Size::new(self.width, self.height)
|
self.current_selection += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn up(&mut self) {
|
||||||
|
if self.current_selection > self.selections.len() as u16 {
|
||||||
|
self.current_selection -= 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
98
src/main.rs
98
src/main.rs
@@ -4,10 +4,20 @@
|
|||||||
|
|
||||||
#[cfg(feature = "defmt")]
|
#[cfg(feature = "defmt")]
|
||||||
use defmt::*;
|
use defmt::*;
|
||||||
|
use embedded_graphics::{
|
||||||
|
pixelcolor::Rgb565,
|
||||||
|
prelude::{Point, RgbColor, Size},
|
||||||
|
primitives::{PrimitiveStyle, Rectangle, StyledDrawable},
|
||||||
|
};
|
||||||
use {defmt_rtt as _, panic_probe as _};
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
use crate::display::{FRAMEBUFFER, SCREEN_HEIGHT, SCREEN_WIDTH, UI};
|
||||||
|
use crate::peripherals::{
|
||||||
|
conf_peripherals,
|
||||||
|
keyboard::{KeyEvent, read_keyboard_fifo},
|
||||||
|
};
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_rp::peripherals::I2C1;
|
use embassy_rp::peripherals::{I2C1, PIN_13, PIN_14, PIN_15, SPI1};
|
||||||
use embassy_rp::spi::Spi;
|
use embassy_rp::spi::Spi;
|
||||||
use embassy_rp::{
|
use embassy_rp::{
|
||||||
bind_interrupts,
|
bind_interrupts,
|
||||||
@@ -18,40 +28,84 @@ use embassy_rp::{
|
|||||||
};
|
};
|
||||||
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
|
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
|
||||||
use embassy_sync::channel::Channel;
|
use embassy_sync::channel::Channel;
|
||||||
use embassy_time::Timer;
|
use embassy_time::{Delay, Timer};
|
||||||
|
use embedded_hal_1::spi::SpiDevice;
|
||||||
use embedded_hal_bus::spi::ExclusiveDevice;
|
use embedded_hal_bus::spi::ExclusiveDevice;
|
||||||
use embedded_sdmmc::asynchronous::{File, SdCard, ShortFileName, VolumeIdx, VolumeManager};
|
use embedded_sdmmc::asynchronous::{File, SdCard, ShortFileName, VolumeIdx, VolumeManager};
|
||||||
|
use st7365p_lcd::{FrameBuffer, ST7365P};
|
||||||
use static_cell::StaticCell;
|
use static_cell::StaticCell;
|
||||||
|
|
||||||
mod peripherals;
|
|
||||||
use peripherals::{keyboard::KeyEvent, peripherals_task};
|
|
||||||
mod display;
|
mod display;
|
||||||
use display::display_task;
|
mod peripherals;
|
||||||
|
|
||||||
embassy_rp::bind_interrupts!(struct Irqs {
|
embassy_rp::bind_interrupts!(
|
||||||
I2C1_IRQ => i2c::InterruptHandler<I2C1>;
|
struct Irqs {
|
||||||
});
|
I2C1_IRQ => i2c::InterruptHandler<I2C1>;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(spawner: Spawner) {
|
async fn main(spawner: Spawner) {
|
||||||
let p = embassy_rp::init(Default::default());
|
let p = embassy_rp::init(Default::default());
|
||||||
|
|
||||||
static KEYBOARD_EVENTS: StaticCell<Channel<NoopRawMutex, KeyEvent, 10>> = StaticCell::new();
|
let mut i2c1_config = i2c::Config::default();
|
||||||
let keyboard_events = KEYBOARD_EVENTS.init(Channel::new());
|
i2c1_config.frequency = 100_000;
|
||||||
|
let i2c1 = I2c::new_async(p.I2C1, p.PIN_7, p.PIN_6, Irqs, i2c1_config);
|
||||||
|
conf_peripherals(i2c1).await;
|
||||||
|
|
||||||
|
let mut spi1_config = spi::Config::default();
|
||||||
|
spi1_config.frequency = 16_000_000;
|
||||||
|
let spi1 = Spi::new(
|
||||||
|
p.SPI1,
|
||||||
|
p.PIN_10,
|
||||||
|
p.PIN_11,
|
||||||
|
p.PIN_12,
|
||||||
|
p.DMA_CH0,
|
||||||
|
p.DMA_CH1,
|
||||||
|
spi1_config,
|
||||||
|
);
|
||||||
|
|
||||||
// configure keyboard event handler
|
|
||||||
let mut config = i2c::Config::default();
|
|
||||||
config.frequency = 100_000;
|
|
||||||
let i2c1 = I2c::new_async(p.I2C1, p.PIN_7, p.PIN_6, Irqs, config);
|
|
||||||
spawner
|
spawner
|
||||||
.spawn(peripherals_task(i2c1, keyboard_events.sender()))
|
.spawn(main_task(spi1, p.PIN_13, p.PIN_14, p.PIN_15))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn main_task(
|
||||||
|
spi1: Spi<'static, SPI1, spi::Async>,
|
||||||
|
spi1_cs: PIN_13,
|
||||||
|
spi1_data: PIN_14,
|
||||||
|
spi1_reset: PIN_15,
|
||||||
|
) {
|
||||||
|
let spi_device = ExclusiveDevice::new(spi1, Output::new(spi1_cs, Level::Low), Delay).unwrap();
|
||||||
|
let display = ST7365P::new(
|
||||||
|
spi_device,
|
||||||
|
Output::new(spi1_data, Level::Low),
|
||||||
|
Some(Output::new(spi1_reset, Level::High)),
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
SCREEN_WIDTH as u32,
|
||||||
|
SCREEN_HEIGHT as u32,
|
||||||
|
);
|
||||||
|
let mut framebuffer: FRAMEBUFFER = FrameBuffer::new(display);
|
||||||
|
framebuffer.init(&mut Delay).await.unwrap();
|
||||||
|
framebuffer
|
||||||
|
.display
|
||||||
|
.set_custom_orientation(0x60)
|
||||||
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// // configure display handler
|
// let mut ui: UI<50, 25> = UI::new();
|
||||||
// let mut config = spi::Config::default();
|
|
||||||
// config.frequency = 16_000_000;
|
// read_keyboard_fifo().await;
|
||||||
// let spi1 = spi::Spi::new_blocking(p.SPI1, p.PIN_10, p.PIN_11, p.PIN_12, config);
|
Rectangle::new(Point::new(0, 0), Size::new(319, 319))
|
||||||
// spawner
|
.draw_styled(&PrimitiveStyle::with_fill(Rgb565::RED), &mut framebuffer)
|
||||||
// .spawn(display_task(spi1, p.PIN_13, p.PIN_14, p.PIN_15))
|
.unwrap();
|
||||||
// .unwrap();
|
// ui.draw(&mut framebuffer);
|
||||||
|
framebuffer.draw().await.unwrap();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
info!("Done");
|
||||||
|
Timer::after_millis(500).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const KEY_CAPSLOCK: u8 = 1 << 5;
|
|||||||
const KEY_NUMLOCK: u8 = 1 << 6;
|
const KEY_NUMLOCK: u8 = 1 << 6;
|
||||||
const KEY_COUNT_MASK: u8 = 0x1F; // 0x1F == 31
|
const KEY_COUNT_MASK: u8 = 0x1F; // 0x1F == 31
|
||||||
|
|
||||||
pub async fn read_keyboard_fifo(channel: &mut Sender<'static, NoopRawMutex, KeyEvent, 10>) {
|
pub async fn read_keyboard_fifo() -> Option<KeyEvent> {
|
||||||
let mut i2c = PERIPHERAL_BUS.get().lock().await;
|
let mut i2c = PERIPHERAL_BUS.get().lock().await;
|
||||||
let i2c = i2c.as_mut().unwrap();
|
let i2c = i2c.as_mut().unwrap();
|
||||||
|
|
||||||
@@ -40,16 +40,15 @@ pub async fn read_keyboard_fifo(channel: &mut Sender<'static, NoopRawMutex, KeyE
|
|||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
channel
|
return Some(KeyEvent {
|
||||||
.try_send(KeyEvent {
|
state: KeyState::from(event[0]),
|
||||||
state: KeyState::from(event[0]),
|
key: KeyCode::from(event[1]),
|
||||||
key: KeyCode::from(event[1]),
|
mods: Modifiers::NONE,
|
||||||
mods: Modifiers::NONE,
|
});
|
||||||
})
|
|
||||||
.expect("Failed to push key");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
const REG_ID_DEB: u8 = 0x06;
|
const REG_ID_DEB: u8 = 0x06;
|
||||||
|
|||||||
@@ -25,11 +25,7 @@ const REG_ID_VER: u8 = 0x01;
|
|||||||
const REG_ID_RST: u8 = 0x08;
|
const REG_ID_RST: u8 = 0x08;
|
||||||
const REG_ID_INT: u8 = 0x03;
|
const REG_ID_INT: u8 = 0x03;
|
||||||
|
|
||||||
#[embassy_executor::task]
|
pub async fn conf_peripherals(i2c: I2CBUS) {
|
||||||
pub async fn peripherals_task(
|
|
||||||
i2c: I2CBUS,
|
|
||||||
mut keyboard_channel: Sender<'static, NoopRawMutex, KeyEvent, 10>,
|
|
||||||
) {
|
|
||||||
Timer::after(embassy_time::Duration::from_millis(100)).await;
|
Timer::after(embassy_time::Duration::from_millis(100)).await;
|
||||||
|
|
||||||
PERIPHERAL_BUS.get().lock().await.replace(i2c);
|
PERIPHERAL_BUS.get().lock().await.replace(i2c);
|
||||||
@@ -37,11 +33,6 @@ pub async fn peripherals_task(
|
|||||||
configure_keyboard(200, 100).await;
|
configure_keyboard(200, 100).await;
|
||||||
set_lcd_backlight(255).await;
|
set_lcd_backlight(255).await;
|
||||||
set_key_backlight(0).await;
|
set_key_backlight(0).await;
|
||||||
|
|
||||||
loop {
|
|
||||||
Timer::after(Duration::from_millis(200)).await;
|
|
||||||
read_keyboard_fifo(&mut keyboard_channel).await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return major & minor mcu version
|
/// return major & minor mcu version
|
||||||
|
|||||||
Reference in New Issue
Block a user