Compare commits
4 Commits
ui
...
display-fr
| Author | SHA1 | Date | |
|---|---|---|---|
| 06a158623d | |||
| a687122696 | |||
| a42cfb6bc5 | |||
| cf479cc00a |
55
Cargo.lock
generated
55
Cargo.lock
generated
@@ -27,12 +27,6 @@ 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"
|
||||||
@@ -765,27 +759,6 @@ 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"
|
||||||
@@ -1033,9 +1006,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.10.0"
|
version = "2.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661"
|
checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
@@ -1363,7 +1336,6 @@ 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",
|
||||||
@@ -1380,16 +1352,15 @@ 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",
|
||||||
|
"spin",
|
||||||
"st7365p-lcd",
|
"st7365p-lcd",
|
||||||
"static_cell",
|
"static_cell",
|
||||||
|
"talc",
|
||||||
"trouble-host",
|
"trouble-host",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1758,6 +1729,15 @@ dependencies = [
|
|||||||
"rgb",
|
"rgb",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spin"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d5fe4ccb98d9c292d56fec89a5e07da7fc4cf0dc11e156b41793132775d3e591"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "st7365p-lcd"
|
name = "st7365p-lcd"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
@@ -1823,6 +1803,15 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "talc"
|
||||||
|
version = "4.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a3ae828aa394de34c7de08f522d1b86bd1c182c668d27da69caadda00590f26d"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "term"
|
name = "term"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
|||||||
13
Cargo.toml
13
Cargo.toml
@@ -60,22 +60,21 @@ 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", branch = "async" }
|
# st7365p-lcd = { git = "https://github.com/legitcamper/st7365p-lcd-rs" }
|
||||||
st7365p-lcd = { path = "../ST7365P-lcd-rs" }
|
st7365p-lcd = { path = "../ST7365P-lcd-rs" }
|
||||||
|
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
bitflags = "2.9.1"
|
||||||
|
talc = "4.4.3"
|
||||||
|
spin = "0.10.0"
|
||||||
|
|||||||
245
src/display.rs
245
src/display.rs
@@ -1,5 +1,3 @@
|
|||||||
use arrform::{ArrForm, arrform};
|
|
||||||
use core::fmt::Debug;
|
|
||||||
use defmt::info;
|
use defmt::info;
|
||||||
use embassy_rp::{
|
use embassy_rp::{
|
||||||
gpio::{Level, Output},
|
gpio::{Level, Output},
|
||||||
@@ -9,35 +7,17 @@ use embassy_rp::{
|
|||||||
use embassy_time::{Delay, Timer};
|
use embassy_time::{Delay, Timer};
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
Drawable,
|
Drawable,
|
||||||
draw_target::DrawTarget,
|
mono_font::{MonoFont, MonoTextStyle, ascii::FONT_10X20},
|
||||||
mono_font::{
|
|
||||||
MonoTextStyle,
|
|
||||||
ascii::{FONT_6X10, FONT_9X15, FONT_10X20},
|
|
||||||
},
|
|
||||||
pixelcolor::Rgb565,
|
pixelcolor::Rgb565,
|
||||||
prelude::{Point, RgbColor, Size},
|
prelude::{Point, WebColors},
|
||||||
primitives::{PrimitiveStyle, Rectangle, StyledDrawable},
|
text::{Baseline, Text, TextStyle},
|
||||||
text::Text,
|
|
||||||
};
|
};
|
||||||
use embedded_hal_1::digital::OutputPin;
|
use embedded_hal_bus::spi::ExclusiveDevice;
|
||||||
use embedded_hal_async::spi::SpiDevice;
|
use st7365p_lcd::{FrameBuffer, ST7365P};
|
||||||
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};
|
|
||||||
|
|
||||||
pub const SCREEN_WIDTH: usize = 320;
|
type SPI = Spi<'static, SPI1, Async>;
|
||||||
pub const SCREEN_HEIGHT: usize = 320;
|
|
||||||
|
|
||||||
pub const STATUS_BAR_WIDTH: usize = 320;
|
type FRAMEBUFFER = FrameBuffer<
|
||||||
pub const STATUS_BAR_HEIGHT: usize = 40;
|
|
||||||
|
|
||||||
pub type FRAMEBUFFER = FrameBuffer<
|
|
||||||
SCREEN_WIDTH,
|
SCREEN_WIDTH,
|
||||||
SCREEN_HEIGHT,
|
SCREEN_HEIGHT,
|
||||||
ExclusiveDevice<Spi<'static, SPI1, Async>, Output<'static>, Delay>,
|
ExclusiveDevice<Spi<'static, SPI1, Async>, Output<'static>, Delay>,
|
||||||
@@ -45,136 +25,117 @@ pub type FRAMEBUFFER = FrameBuffer<
|
|||||||
Output<'static>,
|
Output<'static>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
pub struct UI<const MAX_SELECTIONS: usize, const MAX_STR_LEN: usize> {
|
const SCREEN_WIDTH: usize = 320;
|
||||||
pub status_bar: StatusBar,
|
const SCREEN_HEIGHT: usize = 320;
|
||||||
pub selections_list: SelectionList<MAX_SELECTIONS, MAX_STR_LEN>,
|
const SCREEN_ROWS: usize = 15;
|
||||||
|
const SCREEN_COLS: usize = 31;
|
||||||
|
const FONT: MonoFont = FONT_10X20;
|
||||||
|
const COLOR: Rgb565 = Rgb565::CSS_LAWN_GREEN;
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
pub async fn display_task(spi: SPI, cs: PIN_13, data: PIN_14, reset: PIN_15) {
|
||||||
|
let spi_device = ExclusiveDevice::new(spi, Output::new(cs, Level::Low), Delay).unwrap();
|
||||||
|
let display = ST7365P::new(
|
||||||
|
spi_device,
|
||||||
|
Output::new(data, Level::Low),
|
||||||
|
Some(Output::new(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_offset(0, 0);
|
||||||
|
framebuffer
|
||||||
|
.display
|
||||||
|
.set_custom_orientation(0x60)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut textbuffer = TextBuffer::new();
|
||||||
|
textbuffer.fill('A');
|
||||||
|
textbuffer.draw(&mut framebuffer);
|
||||||
|
info!("finished rendering");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
framebuffer.draw().await.unwrap();
|
||||||
|
Timer::after_millis(500).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const MAX_SELECTIONS: usize, const MAX_STR_LEN: usize> UI<MAX_SELECTIONS, MAX_STR_LEN> {
|
pub struct Cursor {
|
||||||
|
x: u16,
|
||||||
|
y: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cursor {
|
||||||
|
fn new(x: u16, y: u16) -> Self {
|
||||||
|
Self { x, y }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TextBuffer {
|
||||||
|
grid: [[Option<char>; SCREEN_COLS]; SCREEN_ROWS],
|
||||||
|
cursor: Cursor,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextBuffer {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
status_bar: StatusBar {
|
grid: [[None; SCREEN_COLS]; SCREEN_ROWS],
|
||||||
battery: 100,
|
cursor: Cursor { x: 0, y: 0 },
|
||||||
backlight: 100,
|
|
||||||
volume: 100,
|
|
||||||
},
|
|
||||||
selections_list: SelectionList::new(Vec::new()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw<D: DrawTarget<Color = Rgb565>>(&mut self, target: &mut D)
|
/// writes char at cursor
|
||||||
where
|
pub fn write_char(&mut self, ch: char) {
|
||||||
<D as DrawTarget>::Error: Debug,
|
for (i, row) in self.grid.iter_mut().enumerate() {
|
||||||
{
|
for (j, col) in row.iter_mut().enumerate() {
|
||||||
self.draw_status_bar(target);
|
if i as u16 == self.cursor.x && j as u16 == self.cursor.y {
|
||||||
self.draw_selection(target);
|
*col = Some(ch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_selection<D: DrawTarget<Color = Rgb565>>(&mut self, target: &mut D) {
|
/// fills text buffer with char
|
||||||
let text_style = MonoTextStyle::new(&FONT_9X15, Rgb565::WHITE);
|
pub fn fill(&mut self, ch: char) {
|
||||||
|
for i in 0..SCREEN_ROWS {
|
||||||
|
for j in 0..SCREEN_COLS {
|
||||||
|
self.cursor = Cursor::new(i as u16, j as u16);
|
||||||
|
self.write_char(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let selection = Rectangle::new(
|
pub fn scroll_up(&mut self) {
|
||||||
Point::new(0, STATUS_BAR_HEIGHT as i32 + 1),
|
let (top, bottom) = self.grid.split_at_mut(SCREEN_ROWS - 1);
|
||||||
Size::new(
|
for (dest, src) in top.iter_mut().zip(&bottom[1..]) {
|
||||||
SCREEN_WIDTH as u32,
|
dest.copy_from_slice(src);
|
||||||
(SCREEN_HEIGHT - STATUS_BAR_HEIGHT) as u32 - 1,
|
}
|
||||||
),
|
|
||||||
|
self.grid[SCREEN_ROWS - 1].fill(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn draw(&mut self, target: &mut FRAMEBUFFER) {
|
||||||
|
let baseline = TextStyle::with_baseline(Baseline::Top);
|
||||||
|
let style = MonoTextStyle::new(&FONT, COLOR);
|
||||||
|
|
||||||
|
for (i, row) in self.grid.iter().enumerate() {
|
||||||
|
for (j, cell) in row.iter().enumerate() {
|
||||||
|
if let Some(ch) = cell {
|
||||||
|
let pos = Point::new(
|
||||||
|
(j as i32) * FONT.character_size.width as i32,
|
||||||
|
(i as i32) * FONT.character_size.height as i32 + baseline.baseline as i32,
|
||||||
);
|
);
|
||||||
|
|
||||||
let _ = if self.selections_list.selections.is_empty() {
|
Text::new(ch.as_ascii().unwrap().as_str(), pos, style)
|
||||||
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)
|
.draw(target)
|
||||||
};
|
.unwrap();
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn down(&mut self) {
|
|
||||||
if self.current_selection + 1 < self.selections.len() as u16 {
|
|
||||||
self.current_selection += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn up(&mut self) {
|
|
||||||
if self.current_selection > self.selections.len() as u16 {
|
|
||||||
self.current_selection -= 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
99
src/main.rs
99
src/main.rs
@@ -1,23 +1,14 @@
|
|||||||
#![feature(impl_trait_in_assoc_type)]
|
#![feature(impl_trait_in_assoc_type)]
|
||||||
|
#![feature(ascii_char)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
#[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, PIN_13, PIN_14, PIN_15, SPI1};
|
use embassy_rp::peripherals::I2C1;
|
||||||
use embassy_rp::spi::Spi;
|
use embassy_rp::spi::Spi;
|
||||||
use embassy_rp::{
|
use embassy_rp::{
|
||||||
bind_interrupts,
|
bind_interrupts,
|
||||||
@@ -28,84 +19,42 @@ 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::{Delay, Timer};
|
use embassy_time::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 display;
|
|
||||||
mod peripherals;
|
mod peripherals;
|
||||||
|
use peripherals::{keyboard::KeyEvent, peripherals_task};
|
||||||
|
mod display;
|
||||||
|
use display::display_task;
|
||||||
|
|
||||||
embassy_rp::bind_interrupts!(
|
embassy_rp::bind_interrupts!(struct Irqs {
|
||||||
struct Irqs {
|
|
||||||
I2C1_IRQ => i2c::InterruptHandler<I2C1>;
|
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());
|
||||||
|
|
||||||
let mut i2c1_config = i2c::Config::default();
|
static KEYBOARD_EVENTS: StaticCell<Channel<NoopRawMutex, KeyEvent, 10>> = StaticCell::new();
|
||||||
i2c1_config.frequency = 100_000;
|
let keyboard_events = KEYBOARD_EVENTS.init(Channel::new());
|
||||||
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();
|
// // configure keyboard event handler
|
||||||
spi1_config.frequency = 16_000_000;
|
// let mut config = i2c::Config::default();
|
||||||
let spi1 = Spi::new(
|
// config.frequency = 100_000;
|
||||||
p.SPI1,
|
// let i2c1 = I2c::new_async(p.I2C1, p.PIN_7, p.PIN_6, Irqs, config);
|
||||||
p.PIN_10,
|
// spawner
|
||||||
p.PIN_11,
|
// .spawn(peripherals_task(i2c1, keyboard_events.sender()))
|
||||||
p.PIN_12,
|
// .unwrap();
|
||||||
p.DMA_CH0,
|
|
||||||
p.DMA_CH1,
|
// configure display handler
|
||||||
spi1_config,
|
let mut config = spi::Config::default();
|
||||||
|
config.frequency = 16_000_000;
|
||||||
|
let spi1 = spi::Spi::new(
|
||||||
|
p.SPI1, p.PIN_10, p.PIN_11, p.PIN_12, p.DMA_CH0, p.DMA_CH1, config,
|
||||||
);
|
);
|
||||||
|
|
||||||
spawner
|
spawner
|
||||||
.spawn(main_task(spi1, p.PIN_13, p.PIN_14, p.PIN_15))
|
.spawn(display_task(spi1, p.PIN_13, p.PIN_14, p.PIN_15))
|
||||||
.unwrap();
|
.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();
|
|
||||||
|
|
||||||
// let mut ui: UI<50, 25> = UI::new();
|
|
||||||
|
|
||||||
// read_keyboard_fifo().await;
|
|
||||||
Rectangle::new(Point::new(0, 0), Size::new(319, 319))
|
|
||||||
.draw_styled(&PrimitiveStyle::with_fill(Rgb565::RED), &mut framebuffer)
|
|
||||||
.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() -> Option<KeyEvent> {
|
pub async fn read_keyboard_fifo(channel: &mut Sender<'static, NoopRawMutex, KeyEvent, 10>) {
|
||||||
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,15 +40,16 @@ pub async fn read_keyboard_fifo() -> Option<KeyEvent> {
|
|||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
return Some(KeyEvent {
|
channel
|
||||||
|
.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,7 +25,11 @@ 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;
|
||||||
|
|
||||||
pub async fn conf_peripherals(i2c: I2CBUS) {
|
#[embassy_executor::task]
|
||||||
|
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);
|
||||||
@@ -33,6 +37,11 @@ pub async fn conf_peripherals(i2c: I2CBUS) {
|
|||||||
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