Bump heapless and all that bumped it

This commit is contained in:
Nicolas Stalder
2021-06-10 18:25:18 -04:00
committed by Nicolas Stalder
parent 082242ea02
commit 4fb10fc65c
5 changed files with 41 additions and 47 deletions
+3 -3
View File
@@ -8,9 +8,9 @@ edition = "2018"
[dependencies]
delog = "0.1.0"
embedded-time = "0.10.1"
heapless = "0.6"
heapless-bytes = "0.2.0"
embedded-time = "0.12"
heapless = "0.7"
# heapless-bytes = "0.3"
interchange = "0.2.0"
iso7816 = { git = "https://github.com/ycrypto/iso7816", branch = "main" }
usb-device = { version = "0.2.3", features = ["control-buffer-256"] }
+19 -12
View File
@@ -1,7 +1,7 @@
use core::convert::TryFrom;
use embedded_time::duration::Extensions;
use heapless_bytes::Bytes;
use heapless::Vec;
use interchange::{Interchange, Requester};
use crate::{
@@ -17,11 +17,10 @@ use crate::{
use usb_device::class_prelude::*;
type Result<T> = core::result::Result<T, UsbError>;
pub struct Ccid<Bus, I, N>
pub struct Ccid<Bus, I, const N: usize>
where
Bus: 'static + UsbBus,
I: 'static + Interchange<REQUEST = Bytes<N>, RESPONSE = Bytes<N>>,
N: heapless::ArrayLength<u8>,
I: 'static + Interchange<REQUEST = Vec<u8, N>, RESPONSE = Vec<u8, N>>,
{
interface_number: InterfaceNumber,
string_index: StringIndex,
@@ -30,11 +29,10 @@ where
pipe: Pipe<Bus, I, N>,
}
impl<Bus, I, N> Ccid<Bus, I, N>
impl<Bus, I, const N: usize> Ccid<Bus, I, N>
where
Bus: 'static + UsbBus,
I: 'static + Interchange<REQUEST = Bytes<N>, RESPONSE = Bytes<N>>,
N: heapless::ArrayLength<u8>,
I: 'static + Interchange<REQUEST = Vec<u8, N>, RESPONSE = Vec<u8, N>>,
{
/// Class constructor.
///
@@ -85,11 +83,10 @@ where
}
}
impl<Bus, I, N> UsbClass<Bus> for Ccid<Bus, I, N>
impl<Bus, I, const N: usize> UsbClass<Bus> for Ccid<Bus, I, N>
where
Bus: 'static + UsbBus,
I: 'static + Interchange<REQUEST = Bytes<N>, RESPONSE = Bytes<N>>,
N: heapless::ArrayLength<u8>,
I: 'static + Interchange<REQUEST = Vec<u8, N>, RESPONSE = Vec<u8, N>>,
{
fn get_configuration_descriptors(&self, writer: &mut DescriptorWriter)
-> Result<()>
@@ -132,8 +129,18 @@ where
fn endpoint_out(&mut self, addr: EndpointAddress) {
if addr != self.read.address() { return; }
let maybe_packet = RawPacket::try_from(
|packet| self.read.read(packet));
// let maybe_packet = RawPacket::try_from(
// |packet| self.read.read(packet));
let maybe_packet = {
let mut packet = RawPacket::new();
packet.resize_default(packet.capacity()).unwrap();
let result = self.read.read(&mut packet);
result.map(|count| {
packet.resize_default(count).unwrap();
packet
})
};
// should we return an error message
// if the raw packet is invalid?
+3 -12
View File
@@ -1,16 +1,8 @@
#![allow(non_camel_case_types)]
use heapless_bytes::{
consts,
Unsigned as _
};
// can be 8, 16, 32, 64 or 512
#[cfg(feature = "highspeed-usb")]
pub type PACKET_SIZE_TYPE = consts::U512;
pub const PACKET_SIZE: usize = 512;
#[cfg(not(feature = "highspeed-usb"))]
pub type PACKET_SIZE_TYPE = consts::U64;
pub const PACKET_SIZE: usize = PACKET_SIZE_TYPE::USIZE;
pub const PACKET_SIZE: usize = 64;
pub const CLASS_CCID: u8 = 0x0B;
pub const SUBCLASS_NONE: u8 = 0x0;
@@ -46,8 +38,7 @@ pub const MAX_IFSD: [u8; 4] = [0xfe, 0x00, 0x00, 0x00];
// "The value shall be between 261 + 10 and 65544 + 10
// dwMaxCCIDMsgLen 3072
pub type MAX_MSG_LENGTH_TYPE = <consts::U2048 as core::ops::Add<consts::U1024>>::Output;
pub const MAX_MSG_LENGTH: usize = MAX_MSG_LENGTH_TYPE::USIZE;
pub const MAX_MSG_LENGTH: usize = 3072;
pub const MAX_MSG_LENGTH_LE: [u8; 4] = [0x00, 0x0C, 0x00, 0x00];
pub const NUM_SLOTS: u8 = 1;
+12 -16
View File
@@ -1,6 +1,5 @@
use core::convert::TryFrom;
use heapless_bytes::Bytes;
use heapless::Vec;
use interchange::{Interchange, Requester};
use crate::{
@@ -41,11 +40,10 @@ enum Error {
CommandNotSupported = 0x00,
}
pub struct Pipe<Bus, I, N>
pub struct Pipe<Bus, I, const N: usize>
where
Bus: 'static + UsbBus,
I: 'static + Interchange<REQUEST = Bytes<N>, RESPONSE = Bytes<N>>,
N: heapless::ArrayLength<u8>,
I: 'static + Interchange<REQUEST = Vec<u8, N>, RESPONSE = Vec<u8, N>>,
{
pub(crate) write: EndpointIn<'static, Bus>,
// pub(crate) rpc: TransportEndpoint<'rpc>,
@@ -62,14 +60,13 @@ where
long_packet_missing: usize,
in_chain: usize,
pub(crate) started_processing: bool,
atr: Bytes<heapless::consts::U32>,
atr: Vec<u8, 32>,
}
impl<Bus, I, N> Pipe<Bus, I, N>
impl<Bus, I, const N: usize> Pipe<Bus, I, N>
where
Bus: 'static + UsbBus,
I: 'static + Interchange<REQUEST = Bytes<N>, RESPONSE = Bytes<N>>,
N: heapless::ArrayLength<u8>,
I: 'static + Interchange<REQUEST = Vec<u8, N>, RESPONSE = Vec<u8, N>>,
{
pub(crate) fn new(
write: EndpointIn<'static, Bus>,
@@ -100,10 +97,10 @@ where
}
}
fn construct_atr(card_issuers_data: Option<&[u8]>, signal_t_equals_0: bool) -> Bytes<heapless::consts::U32> {
fn construct_atr(card_issuers_data: Option<&[u8]>, signal_t_equals_0: bool) -> Vec<u8, 32> {
assert!(card_issuers_data.map_or(true, |data| data.len() <= 13));
let k = card_issuers_data.map_or(0u8, |data| 2 + data.len() as u8);
let mut atr = Bytes::new();
let mut atr = Vec::new();
// TS: direct convention
atr.push(0x3B).ok();
// T0: encode length of historical bytes
@@ -140,11 +137,10 @@ where
}
impl<Bus, I, N> Pipe<Bus, I, N>
impl<Bus, I, const N: usize> Pipe<Bus, I, N>
where
Bus: 'static + UsbBus,
I: 'static + Interchange<REQUEST = Bytes<N>, RESPONSE = Bytes<N>>,
N: heapless::ArrayLength<u8>,
I: 'static + Interchange<REQUEST = Vec<u8, N>, RESPONSE = Vec<u8, N>>,
{
pub fn handle_packet(&mut self, packet: RawPacket) {
use crate::types::packet::RawPacketExt;
@@ -228,7 +224,7 @@ where
#[inline(never)]
fn reset_interchange(&mut self) {
let message = Bytes::new();
let message = Vec::new();
self.interchange.take_response();
// this may no longer be needed
// before the interchange change (adding the request_mut method),
@@ -378,7 +374,7 @@ where
if self.outbox.is_some() { panic!(); }
// if let Some(message) = self.interchange.response() {
let message: &mut Bytes<N> = unsafe { self.interchange.interchange.rp_mut() };
let message: &mut Vec<u8, N> = unsafe { self.interchange.interchange.rp_mut() };
let chunk_size = core::cmp::min(PACKET_SIZE - 10, message.len() - self.sent);
let chunk = &message[self.sent..][..chunk_size];
+4 -4
View File
@@ -3,8 +3,8 @@ use core::convert::TryInto;
use crate::constants::*;
pub type RawPacket = heapless_bytes::Bytes<PACKET_SIZE_TYPE>;
pub type ExtPacket = heapless_bytes::Bytes<MAX_MSG_LENGTH_TYPE>;
pub type RawPacket = heapless::Vec<u8, PACKET_SIZE>;
pub type ExtPacket = heapless::Vec<u8, MAX_MSG_LENGTH>;
pub trait RawPacketExt {
fn packet_len(&self) -> usize;
@@ -94,7 +94,7 @@ impl core::fmt::Debug for DataBlock<'_> {
;
let l = core::cmp::min(self.data.len(), 16);
let escaped_bytes: heapless::Vec<u8, heapless::consts::U64> =
let escaped_bytes: heapless::Vec<u8, 64> =
self.data.iter().take(l)
.flat_map(|byte| core::ascii::escape_default(*byte))
.collect();
@@ -342,7 +342,7 @@ impl core::fmt::Debug for Command {
match self {
Command::XfrBlock(block) => {
let l = core::cmp::min(self.len(), 8);
let escaped_bytes: heapless::Vec<u8, heapless::consts::U64> =
let escaped_bytes: heapless::Vec<u8, 64> =
block.data().iter().take(l)
.flat_map(|byte| core::ascii::escape_default(*byte))
.collect();