mirror of
https://github.com/trussed-dev/ctaphid-dispatch.git
synced 2026-06-20 04:16:18 -07:00
Update to heapless 0.9 and trussed-core 0.2
This commit is contained in:
+2
-2
@@ -9,8 +9,8 @@ license = "Apache-2.0 OR MIT"
|
||||
repository = "https://github.com/solokeys/ctaphid-dispatch"
|
||||
|
||||
[workspace.dependencies]
|
||||
heapless-bytes = "0.3"
|
||||
trussed-core = "0.1.0"
|
||||
heapless-bytes = "0.5"
|
||||
trussed-core = "0.2"
|
||||
|
||||
[patch.crates-io]
|
||||
ctaphid-app.path = "app"
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Update to `heapless-bytes` v0.5 and `trussed-core` v0.2
|
||||
|
||||
## [v0.1.0](https://github.com/trussed-dev/ctaphid-dispatch/releases/tag/app-v0.1.0) (2025-01-08)
|
||||
|
||||
Initial release that extracts the `app` and `command` modules from `ctaphid-dispatch` 0.1 into a separate crate.
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
#![no_std]
|
||||
|
||||
use heapless_bytes::Bytes;
|
||||
use heapless_bytes::BytesView;
|
||||
use trussed_core::InterruptFlag;
|
||||
|
||||
mod command;
|
||||
@@ -10,7 +10,7 @@ pub use command::{Command, VendorCommand};
|
||||
/// trait interface for a CTAPHID application.
|
||||
/// The application chooses which commands to register to, and will be called upon
|
||||
/// when the commands are received in the CTAPHID layer. Only one application can be registered to a particular command.
|
||||
pub trait App<'interrupt, const N: usize> {
|
||||
pub trait App<'interrupt> {
|
||||
/// Get access to the app interrupter
|
||||
fn interrupt(&self) -> Option<&'interrupt InterruptFlag> {
|
||||
None
|
||||
@@ -27,7 +27,7 @@ pub trait App<'interrupt, const N: usize> {
|
||||
&mut self,
|
||||
command: Command,
|
||||
request: &[u8],
|
||||
response: &mut Bytes<N>,
|
||||
response: &mut BytesView,
|
||||
) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
-
|
||||
- Update to `heapless-bytes` v0.5 and `trussed-core` v0.2
|
||||
|
||||
## [0.3.0] - 2025-03-21
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ impl<'pipe, 'interrupt, const N: usize> Dispatch<'pipe, 'interrupt, N> {
|
||||
|
||||
fn find_app<'a, 'b>(
|
||||
command: Command,
|
||||
apps: &'a mut [&'b mut dyn App<'interrupt, N>],
|
||||
) -> Option<&'a mut &'b mut dyn App<'interrupt, N>> {
|
||||
apps: &'a mut [&'b mut dyn App<'interrupt>],
|
||||
) -> Option<&'a mut &'b mut dyn App<'interrupt>> {
|
||||
apps.iter_mut()
|
||||
.find(|app| app.commands().contains(&command))
|
||||
}
|
||||
@@ -75,7 +75,7 @@ impl<'pipe, 'interrupt, const N: usize> Dispatch<'pipe, 'interrupt, N> {
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
fn call_app(&mut self, app: &mut dyn App<'interrupt, N>, command: Command, request: &Bytes<N>) {
|
||||
fn call_app(&mut self, app: &mut dyn App<'interrupt>, command: Command, request: &[u8]) {
|
||||
let response_buffer = self
|
||||
.responder
|
||||
.response_mut()
|
||||
@@ -106,18 +106,17 @@ impl<'pipe, 'interrupt, const N: usize> Dispatch<'pipe, 'interrupt, N> {
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn poll(&mut self, apps: &mut [&mut dyn App<'interrupt, N>]) -> bool {
|
||||
pub fn poll(&mut self, apps: &mut [&mut dyn App<'interrupt>]) -> bool {
|
||||
// We could call take_request directly, but for some reason this doubles stack usage.
|
||||
let mut message_buffer = Bytes::new();
|
||||
let mut buffer = Bytes::<N>::new();
|
||||
if let Ok((command, message)) = self.responder.request() {
|
||||
// info_now!("cmd: {}", u8::from(command));
|
||||
// info_now!("cmd: {:?}", command);
|
||||
|
||||
message_buffer.extend_from_slice(message).unwrap();
|
||||
|
||||
buffer.extend_from_slice(message).unwrap();
|
||||
if let Some(app) = Self::find_app(*command, apps) {
|
||||
// match app.call(command, self.responder.response_mut().unwrap()) {
|
||||
self.call_app(*app, *command, &message_buffer);
|
||||
self.call_app(*app, *command, &buffer);
|
||||
} else {
|
||||
self.reply_with_error(Error::InvalidCommand);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user