Skip to content

Commit

Permalink
usb
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-gilligan committed Feb 28, 2025
1 parent 2398051 commit f353f61
Show file tree
Hide file tree
Showing 19 changed files with 414 additions and 240 deletions.
29 changes: 19 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["rp", "shared", "web", "clock", "hardware_test", "app_menu"]
members = ["rp", "shared", "web", "clock", "hardware_test", "keyboard"]

[workspace.dependencies]
# multi-tap = { path = "./multi-tap" }
Expand All @@ -13,7 +13,7 @@ embassy-executor = { git = "https://github.com/embassy-rs/embassy.git", features
embassy-futures = { git = "https://github.com/embassy-rs/embassy.git", version = "*" }
embassy-sync = { git = "https://github.com/embassy-rs/embassy.git", version = "*" }
embassy-time = { git = "https://github.com/embassy-rs/embassy.git", version = "*" }
embassy-usb = { git = "https://github.com/embassy-rs/embassy.git", version = "*", features = ["defmt"] }
embassy-usb = { git = "https://github.com/embassy-rs/embassy.git", version = "*", features = ["defmt", "max-interface-count-6"] }
embassy-usb-logger = { git = "https://github.com/embassy-rs/embassy.git", version = "*" }

embedded-graphics = "*"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ Because the board would need to fit into the chassis of a Nokia 3310 and because

### TODO
#### v0.3
- main branch: logging via USB
- create example that plays RTTTL (and writes it to screen)
- Snake
- USB text entry (just on branch because USB app API needs some thought nb. there's maybe a need for device to add/remove class depending on app. is that possible? what does web simulated device look like?)
- USB text entry

- power button (digital latch. can this be triggered by 'any key'? ie. any keypad press turns the device on. there's enough GPIO to spare that we should have a dedicated GPIO for any key too)
- double check power regulation, boot button
Expand All @@ -43,6 +42,7 @@ Because the board would need to fit into the chassis of a Nokia 3310 and because
- document app API

#### Later
- make all system work live on primary core. give apps dedicated secondary core.
- optional pico-w for wifi/bluetooth (using a module avoids need for recertification?)
- looks like RP will release such a module (RM2) so go ahead with designing with that in mind
- detect battery type to refuse NiMH
Expand Down
40 changes: 0 additions & 40 deletions app_menu/src/lib.rs

This file was deleted.

6 changes: 3 additions & 3 deletions clock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl Application for Clock {
_keypad: &mut impl shared::Keypad,
rtc: &mut impl shared::Rtc,
_backlight: &mut impl shared::Backlight,
_system_response: Option<Result<shared::SystemRequest, ()>>,
) -> Result<Option<shared::SystemRequest>, ()>
_system_response: Option<[u8; 64]>,
) -> Option<shared::UsbTx>
where
<D as DrawTarget>::Error: Debug,
{
Expand Down Expand Up @@ -88,6 +88,6 @@ impl Application for Clock {
.unwrap();
embassy_time::Timer::after_millis(10).await;

Ok(None)
None
}
}
1 change: 1 addition & 0 deletions hardware_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024"

[dependencies]
defmt.workspace = true
embassy-time = { workspace = true }
embedded-graphics = "0.8"
shared = { path = "../shared" }
35 changes: 31 additions & 4 deletions hardware_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use core::fmt::Debug;

use defmt::*;
use embedded_graphics::{
draw_target::DrawTarget,
pixelcolor::BinaryColor,
Expand Down Expand Up @@ -33,8 +34,8 @@ impl Application for HardwareTest {
keypad: &mut impl shared::Keypad,
_rtc: &mut impl shared::Rtc,
backlight: &mut impl shared::Backlight,
_system_response: Option<Result<shared::SystemRequest, ()>>,
) -> Result<Option<shared::SystemRequest>, ()>
_system_response: Option<[u8; 64]>,
) -> Option<shared::UsbTx>
where
<D as DrawTarget>::Error: Debug,
{
Expand All @@ -54,39 +55,65 @@ impl Application for HardwareTest {

match keypad.event().await {
KeyEvent::Down(Key::Down) => {
println!("Down");
self.0 -= 1;
}
KeyEvent::Down(Key::Up) => {
println!("Up");
self.0 += 1;
}
KeyEvent::Down(Key::One) => {
println!("One");
buzzer.unmute();
}
KeyEvent::Down(Key::Two) => {
println!("Two");
buzzer.mute();
}
KeyEvent::Down(Key::Four) => {
println!("Four");
buzzer.set_frequency(440);
}
KeyEvent::Down(Key::Five) => {
println!("Five");
buzzer.set_frequency(660);
}
KeyEvent::Down(Key::Six) => {
println!("Six");
buzzer.set_frequency(880);
}
KeyEvent::Down(Key::Eight) => {
println!("Eight");
vibration_motor.start();
}
KeyEvent::Down(Key::Seven) => {
println!("Seven");
vibration_motor.stop();
}
KeyEvent::Down(Key::Nine) => {
println!("Nine");
backlight.on();
}
KeyEvent::Down(Key::Three) => {
println!("Three");
backlight.off();
}
_ => {}
KeyEvent::Up(_) => {}
KeyEvent::Down(Key::Select) => {
println!("Select");
}
KeyEvent::Down(Key::Cancel) => {
println!("Cancel");
}
KeyEvent::Down(Key::Asterisk) => {
println!("*");
}
KeyEvent::Down(Key::Zero) => {
println!("0");
}
KeyEvent::Down(Key::Hash) => {
println!("#");
}
}

Triangle::new(
Expand All @@ -103,6 +130,6 @@ impl Application for HardwareTest {
.draw(display)
.unwrap();

Ok(None)
None
}
}
2 changes: 1 addition & 1 deletion app_menu/Cargo.toml → keyboard/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "app-menu"
name = "keyboard"
version = "0.1.0"
edition = "2024"

Expand Down
82 changes: 82 additions & 0 deletions keyboard/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#![no_std]

use core::fmt::Debug;

use embedded_graphics::{
draw_target::DrawTarget,
// mono_font::{MonoTextStyle, ascii::FONT_10X20},
pixelcolor::BinaryColor,
prelude::*,
primitives::PrimitiveStyle,
// text::{Alignment, Text},
};
use shared::{Application, Key, KeyEvent};

pub struct Keyboard;

impl Keyboard {
pub fn new() -> Self {
Self
}
}

impl Default for Keyboard {
fn default() -> Self {
Self
}
}

impl Application for Keyboard {
async fn run<D: DrawTarget<Color = BinaryColor>>(
&mut self,
_vibration_motor: &mut impl shared::VibrationMotor,
_buzzer: &mut impl shared::Buzzer,
display: &mut D,
keypad: &mut impl shared::Keypad,
_rtc: &mut impl shared::Rtc,
_backlight: &mut impl shared::Backlight,
_system_response: Option<[u8; 64]>,
) -> Option<shared::UsbTx>
where
<D as DrawTarget>::Error: Debug,
{
let fill = PrimitiveStyle::with_fill(BinaryColor::Off);
display
.bounding_box()
.into_styled(fill)
.draw(display)
.unwrap();

// let character_style = MonoTextStyle::new(&FONT_10X20, BinaryColor::Off);
// let now = chrono::DateTime::<chrono::Utc>::from_timestamp(rtc.timestamp(), 0).unwrap();
// let mut text: heapless::String<8> = heapless::String::new();
// Text::with_alignment(
// &text,
// display.bounding_box().center() + Point::new(0, 6),
// character_style,
// Alignment::Center,
// )
// .draw(display)
// .unwrap();

match keypad.event().await {
KeyEvent::Down(Key::Down) => Some(shared::UsbTx::HidChar('d')),
KeyEvent::Down(Key::Up) => Some(shared::UsbTx::HidChar('u')),
KeyEvent::Down(Key::One) => Some(shared::UsbTx::HidChar('1')),
KeyEvent::Down(Key::Two) => Some(shared::UsbTx::HidChar('2')),
KeyEvent::Down(Key::Four) => Some(shared::UsbTx::HidChar('4')),
KeyEvent::Down(Key::Five) => Some(shared::UsbTx::HidChar('5')),
KeyEvent::Down(Key::Six) => Some(shared::UsbTx::HidChar('6')),
KeyEvent::Down(Key::Eight) => Some(shared::UsbTx::HidChar('8')),
KeyEvent::Down(Key::Seven) => Some(shared::UsbTx::HidChar('7')),
KeyEvent::Down(Key::Nine) => Some(shared::UsbTx::HidChar('9')),
KeyEvent::Down(Key::Three) => Some(shared::UsbTx::HidChar('3')),
KeyEvent::Down(Key::Select) => Some(shared::UsbTx::HidChar('s')),
KeyEvent::Down(Key::Cancel) => Some(shared::UsbTx::HidChar('c')),
KeyEvent::Down(Key::Asterisk) => Some(shared::UsbTx::HidChar('*')),
KeyEvent::Down(Key::Zero) => Some(shared::UsbTx::HidChar('0')),
KeyEvent::Down(Key::Hash) => Some(shared::UsbTx::HidChar('#')),
KeyEvent::Up(_) => None,
}
}
}
3 changes: 3 additions & 0 deletions rp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ unofficial-piicodev = { git = "https://github.com/tommy-gilligan/piicodev-rs.git
critical-section = "*"
clock = { path = "../clock" }
hardware-test = { path = "../hardware_test" }
keyboard = { path = "../keyboard" }
log = "0.4"
assign-resources = { git = "https://github.com/adamgreig/assign-resources", rev = "94ad10e2729afdf0fd5a77cd12e68409a982f58a" }

# [lints.clippy]
# alloc_instead_of_core = "deny"
Expand Down
8 changes: 6 additions & 2 deletions rp/src/buzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ impl Beeper<'_> {
}

impl Buzzer for Beeper<'_> {
fn mute(&mut self) {}
fn mute(&mut self) {
self.0.set_duty_cycle_percent(0).unwrap();
}

fn unmute(&mut self) {}
fn unmute(&mut self) {
self.0.set_duty_cycle_percent(90).unwrap();
}

fn set_volume(&mut self, _volume: u8) {
// self.0.set_duty_cycle_percent(volume).unwrap();
Expand Down
Loading

0 comments on commit f353f61

Please sign in to comment.