Refactors a lot
This commit is contained in:
parent
2c694ca104
commit
f3f17b7126
|
|
@ -13,9 +13,21 @@
|
|||
//! let mut dispatch_manager = DispatchManager::new();
|
||||
//! let macro_action = dispatch_manager.process_keypresses(); // Process captured keypresses and get the corresponding macro action
|
||||
//! ```
|
||||
use crate::keysend::send_keypress;
|
||||
use enum_dispatch::enum_dispatch;
|
||||
|
||||
use crate::keyboard::KeyCode;
|
||||
use crate::{keyboard::KeyCode, layout::KeypadKey};
|
||||
|
||||
pub(crate) async fn keydispatch_press(pressed_key: &KeypadKey) {
|
||||
// Big switchcase
|
||||
|
||||
// Return
|
||||
}
|
||||
pub(crate) async fn keydispatch_release(pressed_key: &KeypadKey) {
|
||||
// Big switchcase
|
||||
|
||||
// Return
|
||||
}
|
||||
|
||||
#[enum_dispatch]
|
||||
enum ActionsTypes {
|
||||
|
|
|
|||
|
|
@ -17,36 +17,42 @@
|
|||
//! ```
|
||||
|
||||
use core::sync::atomic::AtomicU32;
|
||||
|
||||
use defmt::info;
|
||||
|
||||
use crate::{
|
||||
dispatch::{keydispatch_press, keydispatch_release},
|
||||
layout::KeypadKey,
|
||||
};
|
||||
pub(crate) static KEYMASK: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
#[repr(u32)]
|
||||
pub(crate) enum Keyboard {
|
||||
A1 = 1,
|
||||
A2 = 1 << 1,
|
||||
A3 = 1 << 2,
|
||||
A4 = 1 << 3,
|
||||
B1 = 1 << 4,
|
||||
B2 = 1 << 5,
|
||||
B3 = 1 << 6,
|
||||
B4 = 1 << 7,
|
||||
C1 = 1 << 8,
|
||||
C2 = 1 << 9,
|
||||
C3 = 1 << 10,
|
||||
C4 = 1 << 11,
|
||||
pub(crate) async fn await_key<PINTYPE>(mut pin: PINTYPE, corresponding_key: KeypadKey)
|
||||
where
|
||||
PINTYPE: embedded_hal_async::digital::Wait,
|
||||
{
|
||||
loop {
|
||||
// Wait for keypress
|
||||
pin.wait_for_high().await;
|
||||
// Call dispatch
|
||||
keydispatch_press(&corresponding_key).await;
|
||||
|
||||
// Wait for keyrelease
|
||||
pin.wait_for_low().await;
|
||||
// Call dispatch
|
||||
keydispatch_release(&corresponding_key).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
enum KeyboardMask {
|
||||
A1 = 0b111111111111 - (1 << 0),
|
||||
A2 = 0b111111111111 - (1 << 1),
|
||||
A3 = 0b111111111111 - (1 << 2),
|
||||
A4 = 0b111111111111 - (1 << 3),
|
||||
B1 = 0b111111111111 - (1 << 4),
|
||||
B2 = 0b111111111111 - (1 << 5),
|
||||
B3 = 0b111111111111 - (1 << 6),
|
||||
B4 = 0b111111111111 - (1 << 7),
|
||||
C1 = 0b111111111111 - (1 << 8),
|
||||
C2 = 0b111111111111 - (1 << 9),
|
||||
C3 = 0b111111111111 - (1 << 10),
|
||||
C4 = 0b111111111111 - (1 << 11),
|
||||
pub(crate) fn await_chord<PINTYPE>(pin: PINTYPE, corresponding_key: KeypadKey)
|
||||
where
|
||||
PINTYPE: embedded_hal_async::digital::Wait,
|
||||
{
|
||||
todo!()
|
||||
// loop {
|
||||
// // Wait for keypressed
|
||||
// // Update modkeys
|
||||
// // Regulation loop
|
||||
// // If released within: Call dispatch
|
||||
// // Wait keyreleased
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,3 +12,9 @@
|
|||
//! let mut keysend_manager = KeysendManager::new();
|
||||
//! keysend_manager.send_keypress('A'); // Simulate sending a keypress event for the letter 'A'
|
||||
//! ```
|
||||
|
||||
use crate::keyboard::KeyCode;
|
||||
|
||||
pub(crate) async fn send_keypress(list_key: &[KeyCode]) {
|
||||
for key in list_key.iter() {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
//! Module: layout.rs
|
||||
//!
|
||||
//! This module contains the layout of the macro keyboard (macropad), defining the arrangement of keys and their corresponding actions.
|
||||
//!
|
||||
//! It provides functionality for defining the physical layout of the macropad, mapping keys to specific actions or macros, and managing the layout configuration.
|
||||
//!
|
||||
// #[derive(Debug)]
|
||||
pub(crate) enum KeypadKey {
|
||||
A1,
|
||||
A2,
|
||||
A3,
|
||||
A4,
|
||||
B1,
|
||||
B2,
|
||||
B3,
|
||||
B4,
|
||||
C1,
|
||||
C2,
|
||||
C3,
|
||||
C4,
|
||||
}
|
||||
101
src/main.rs
101
src/main.rs
|
|
@ -4,19 +4,20 @@ mod dispatch;
|
|||
mod keyboard;
|
||||
mod keypress;
|
||||
mod keysend;
|
||||
mod layout;
|
||||
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use crate::keyboard::KeyCode;
|
||||
use crate::keypress::{Keyboard, KEYMASK};
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::join::join;
|
||||
use embassy_futures::join::{join, join3};
|
||||
use embassy_rp::bind_interrupts;
|
||||
use embassy_rp::gpio::{Input, Pull};
|
||||
use embassy_rp::peripherals::USB;
|
||||
use embassy_rp::usb::{Driver, InterruptHandler};
|
||||
use embassy_usb::class::hid::{HidReaderWriter, ReportId, RequestHandler, State};
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::channel::Channel;
|
||||
use embassy_usb::class::hid::{HidReaderWriter, HidWriter, ReportId, RequestHandler, State};
|
||||
use embassy_usb::control::OutResponse;
|
||||
use embassy_usb::{Builder, Config, Handler};
|
||||
use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor};
|
||||
|
|
@ -27,6 +28,10 @@ bind_interrupts!(struct Irqs {
|
|||
USBCTRL_IRQ => InterruptHandler<USB>;
|
||||
});
|
||||
|
||||
type WriterType = HidWriter<'static, Driver<'static, USB>, 8>;
|
||||
// static LOCKED_WRITER: Mutex<CriticalSectionRawMutex, RefCell<Option<WriterType>>> =
|
||||
// Mutex::new(RefCell::new(None));
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
|
|
@ -86,52 +91,28 @@ async fn main(_spawner: Spawner) {
|
|||
pin.set_schmitt(true);
|
||||
|
||||
let (reader, mut writer) = hid.split();
|
||||
// let locked_writer = RefCell::new(BlockingMutex::new(writer));
|
||||
// Do stuff with the class!
|
||||
let in_fut = async {
|
||||
let mut channel = Channel::<CriticalSectionRawMutex, KeyboardReport, 12>::new();
|
||||
|
||||
let senderloop = async {
|
||||
loop {
|
||||
info!("Waiting for HIGH on pin 1");
|
||||
pin.wait_for_high().await;
|
||||
info!("HIGH DETECTED");
|
||||
// Create a report with the A key pressed. (no shift modifier)
|
||||
let a1 = KEYMASK.load(Ordering::Relaxed) & Keyboard::A1 as u32;
|
||||
KEYMASK.store(a1, Ordering::Relaxed);
|
||||
let report = KeyboardReport {
|
||||
keycodes: [KeyCode::Kb6 as u8, KeyCode::K as u8, 0, 0, 0, 0],
|
||||
leds: 0,
|
||||
modifier: 1 << (KeyCode::LShift as u8 - KeyCode::LCtrl as u8),
|
||||
reserved: 0,
|
||||
};
|
||||
info!("Awayting new messages");
|
||||
let report = channel.receive().await;
|
||||
// Send the report.
|
||||
match writer.write_serialize(&report).await {
|
||||
Ok(()) => {}
|
||||
Err(e) => warn!("Failed to send report: {:?}", e),
|
||||
};
|
||||
// let report = KeyboardReport {
|
||||
// keycodes: [55, 0, 0, 0, 0, 0],
|
||||
// leds: 0,
|
||||
// modifier: 0,
|
||||
// reserved: 0,
|
||||
// };
|
||||
// // Send the report.
|
||||
// match writer.write_serialize(&report).await {
|
||||
// Ok(()) => {}
|
||||
// Err(e) => warn!("Failed to send report: {:?}", e),
|
||||
// };
|
||||
}
|
||||
};
|
||||
|
||||
let in_fut = async {
|
||||
loop {
|
||||
info!("Waiting for HIGH on pin 1");
|
||||
pin.wait_for_high().await;
|
||||
info!("HIGH DETECTED");
|
||||
pin.wait_for_low().await;
|
||||
info!("LOW DETECTED");
|
||||
let report = KeyboardReport {
|
||||
keycodes: [0, 0, 0, 0, 0, 0],
|
||||
leds: 0,
|
||||
modifier: 0,
|
||||
reserved: 0,
|
||||
};
|
||||
match writer.write_serialize(&report).await {
|
||||
Ok(()) => {}
|
||||
Err(e) => warn!("Failed to send report: {:?}", e),
|
||||
};
|
||||
}
|
||||
// waitletter(pin, &writer, 4);
|
||||
};
|
||||
|
||||
let out_fut = async {
|
||||
|
|
@ -140,45 +121,9 @@ async fn main(_spawner: Spawner) {
|
|||
|
||||
// Run everything concurrently.
|
||||
// If we had made everything `'static` above instead, we could do this using separate tasks instead.
|
||||
join(usb_fut, join(in_fut, out_fut)).await;
|
||||
join(usb_fut, join3(in_fut, out_fut, senderloop)).await;
|
||||
}
|
||||
|
||||
// async fn waitletter<PINTYPE, S, M>(pin: PINTYPE, keysent: usize)
|
||||
// where
|
||||
// PINTYPE: embedded_hal_async::digital::Wait,
|
||||
// {
|
||||
// // let pin = gpin.degrade();
|
||||
// loop {
|
||||
// info!("Waiting for HIGH on pin 16");
|
||||
// pin.wait_for_high().await;
|
||||
// info!("HIGH DETECTED");
|
||||
// // Create a report with the A key pressed. (no shift modifier)
|
||||
// let report = KeyboardReport {
|
||||
// keycodes: [53, 0, 0, 0, 0, 0],
|
||||
// leds: 0,
|
||||
// modifier: 0,
|
||||
// reserved: 0,
|
||||
// };
|
||||
// // Send the report.
|
||||
// match writer.write_serialize(&report).await {
|
||||
// Ok(()) => {}
|
||||
// Err(e) => warn!("Failed to send report: {:?}", e),
|
||||
// };
|
||||
// pin.wait_for_low().await;
|
||||
// info!("LOW DETECTED");
|
||||
// let report = KeyboardReport {
|
||||
// keycodes: [0, 0, 0, 0, 0, 0],
|
||||
// leds: 0,
|
||||
// modifier: 0,
|
||||
// reserved: 0,
|
||||
// };
|
||||
// match writer.write_serialize(&report).await {
|
||||
// Ok(()) => {}
|
||||
// Err(e) => warn!("Failed to send report: {:?}", e),
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
|
||||
struct MyRequestHandler {}
|
||||
|
||||
impl RequestHandler for MyRequestHandler {
|
||||
|
|
|
|||
Reference in New Issue