mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-27 07:45:28 +00:00
WIP
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1761,7 +1761,6 @@ 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?branch=async#9f8da568ff695a00afb6b8b8cf9573fad408a66f"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"embedded-graphics-core",
|
"embedded-graphics-core",
|
||||||
"embedded-hal 1.0.0",
|
"embedded-hal 1.0.0",
|
||||||
|
|||||||
@@ -77,4 +77,5 @@ defmt-rtt = "0.4.2"
|
|||||||
embedded-graphics = { version = "0.8.1" }
|
embedded-graphics = { version = "0.8.1" }
|
||||||
embedded-layout = "0.4.2"
|
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", branch = "async" }
|
||||||
|
st7365p-lcd = { path = "../ST7365P-lcd-rs" }
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
use arrform::{ArrForm, arrform};
|
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},
|
||||||
@@ -14,12 +16,12 @@ use embedded_graphics::{
|
|||||||
},
|
},
|
||||||
pixelcolor::Rgb565,
|
pixelcolor::Rgb565,
|
||||||
prelude::{Point, RgbColor, Size},
|
prelude::{Point, RgbColor, Size},
|
||||||
primitives::Rectangle,
|
primitives::{PrimitiveStyle, Rectangle, StyledDrawable},
|
||||||
text::Text,
|
text::Text,
|
||||||
};
|
};
|
||||||
use embedded_hal_1::digital::OutputPin;
|
use embedded_hal_1::digital::OutputPin;
|
||||||
use embedded_hal_async::spi::SpiDevice;
|
use embedded_hal_async::spi::SpiDevice;
|
||||||
use embedded_hal_bus::spi::ExclusiveDevice;
|
use embedded_hal_bus::spi::{ExclusiveDevice, NoDelay};
|
||||||
use embedded_layout::{
|
use embedded_layout::{
|
||||||
align::{horizontal, vertical},
|
align::{horizontal, vertical},
|
||||||
layout::linear::LinearLayout,
|
layout::linear::LinearLayout,
|
||||||
@@ -35,36 +37,13 @@ pub const SCREEN_HEIGHT: usize = 320;
|
|||||||
pub const STATUS_BAR_WIDTH: usize = 320;
|
pub const STATUS_BAR_WIDTH: usize = 320;
|
||||||
pub const STATUS_BAR_HEIGHT: usize = 40;
|
pub const STATUS_BAR_HEIGHT: usize = 40;
|
||||||
|
|
||||||
pub async fn init_display(
|
pub type FRAMEBUFFER = FrameBuffer<
|
||||||
spi: Spi<'static, SPI1, Async>,
|
|
||||||
cs: PIN_13,
|
|
||||||
data: PIN_14,
|
|
||||||
reset: PIN_15,
|
|
||||||
) -> 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>,
|
||||||
Output<'static>,
|
Output<'static>,
|
||||||
Output<'static>,
|
Output<'static>,
|
||||||
> {
|
>;
|
||||||
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).await.unwrap();
|
|
||||||
display
|
|
||||||
.set_orientation(&Orientation::Landscape)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
FrameBuffer::new(display)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct UI<const MAX_SELECTIONS: usize, const MAX_STR_LEN: usize> {
|
pub struct UI<const MAX_SELECTIONS: usize, const MAX_STR_LEN: usize> {
|
||||||
pub status_bar: StatusBar,
|
pub status_bar: StatusBar,
|
||||||
@@ -83,7 +62,10 @@ impl<const MAX_SELECTIONS: usize, const MAX_STR_LEN: usize> UI<MAX_SELECTIONS, M
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw<D: DrawTarget<Color = Rgb565>>(&mut self, target: &mut D) {
|
pub fn draw<D: DrawTarget<Color = Rgb565>>(&mut self, target: &mut D)
|
||||||
|
where
|
||||||
|
<D as DrawTarget>::Error: Debug,
|
||||||
|
{
|
||||||
self.draw_status_bar(target);
|
self.draw_status_bar(target);
|
||||||
self.draw_selection(target);
|
self.draw_selection(target);
|
||||||
}
|
}
|
||||||
@@ -114,11 +96,13 @@ impl<const MAX_SELECTIONS: usize, const MAX_STR_LEN: usize> UI<MAX_SELECTIONS, M
|
|||||||
Point::zero(),
|
Point::zero(),
|
||||||
text_style,
|
text_style,
|
||||||
))
|
))
|
||||||
|
.append(Text::new(" ", Point::zero(), text_style))
|
||||||
.append(Text::new(
|
.append(Text::new(
|
||||||
arrform!(20, "Lght: {}", self.status_bar.backlight).as_str(),
|
arrform!(20, "Lght: {}", self.status_bar.backlight).as_str(),
|
||||||
Point::zero(),
|
Point::zero(),
|
||||||
text_style,
|
text_style,
|
||||||
))
|
))
|
||||||
|
.append(Text::new(" ", Point::zero(), text_style))
|
||||||
.append(Text::new(
|
.append(Text::new(
|
||||||
arrform!(20, "Vol: {}", self.status_bar.volume).as_str(),
|
arrform!(20, "Vol: {}", self.status_bar.volume).as_str(),
|
||||||
Point::zero(),
|
Point::zero(),
|
||||||
|
|||||||
89
src/main.rs
89
src/main.rs
@@ -4,12 +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::{SCREEN_HEIGHT, SCREEN_WIDTH, UI, init_display};
|
use crate::display::{FRAMEBUFFER, SCREEN_HEIGHT, SCREEN_WIDTH, UI};
|
||||||
use crate::peripherals::{keyboard::KeyEvent, peripherals_task};
|
use crate::peripherals::{
|
||||||
|
conf_peripherals,
|
||||||
|
keyboard::{KeyEvent, read_keyboard_fifo},
|
||||||
|
};
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_rp::peripherals::{I2C1, SPI1};
|
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,
|
||||||
@@ -30,37 +38,74 @@ use static_cell::StaticCell;
|
|||||||
mod display;
|
mod display;
|
||||||
mod peripherals;
|
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();
|
||||||
|
|
||||||
let mut config = spi::Config::default();
|
// let mut ui: UI<50, 25> = UI::new();
|
||||||
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, config,
|
|
||||||
);
|
|
||||||
let mut framebuffer = init_display(spi1, p.PIN_13, p.PIN_14, p.PIN_15).await;
|
|
||||||
|
|
||||||
let mut ui: UI<50, 25> = UI::new();
|
// read_keyboard_fifo().await;
|
||||||
ui.draw(&mut framebuffer);
|
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 {
|
loop {
|
||||||
framebuffer.draw().await.unwrap();
|
info!("Done");
|
||||||
Timer::after_millis(500).await;
|
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