mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 06:40:47 +00:00
Read more bytes in one go in BleConnector (#3098)
This commit is contained in:
parent
806215fa43
commit
f0faa61a92
@ -50,20 +50,17 @@ impl ErrorType for BleConnector<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Read for BleConnector<'_> {
|
impl Read for BleConnector<'_> {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
|
fn read(&mut self, mut buf: &mut [u8]) -> Result<usize, Self::Error> {
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
for b in buf {
|
while !buf.is_empty() {
|
||||||
let mut buffer = [0u8];
|
let len = read_hci(buf);
|
||||||
let len = read_hci(&mut buffer);
|
if len == 0 {
|
||||||
|
break;
|
||||||
if len == 1 {
|
|
||||||
*b = buffer[0];
|
|
||||||
total += 1;
|
|
||||||
} else {
|
|
||||||
return Ok(total);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
buf = &mut buf[len..];
|
||||||
|
total += len;
|
||||||
|
}
|
||||||
Ok(total)
|
Ok(total)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,24 +102,24 @@ pub(crate) mod asynch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl embedded_io_async::Read for BleConnector<'_> {
|
impl embedded_io_async::Read for BleConnector<'_> {
|
||||||
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, BleConnectorError> {
|
async fn read(&mut self, mut buf: &mut [u8]) -> Result<usize, BleConnectorError> {
|
||||||
if !have_hci_read_data() {
|
if buf.is_empty() {
|
||||||
HciReadyEventFuture.await;
|
return Ok(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
for b in buf {
|
if !have_hci_read_data() {
|
||||||
let mut buffer = [0u8];
|
HciReadyEventFuture.await;
|
||||||
let len = read_hci(&mut buffer);
|
|
||||||
|
|
||||||
if len == 1 {
|
|
||||||
*b = buffer[0];
|
|
||||||
total += 1;
|
|
||||||
} else {
|
|
||||||
return Ok(total);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
while !buf.is_empty() {
|
||||||
|
let len = read_hci(buf);
|
||||||
|
if len == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = &mut buf[len..];
|
||||||
|
total += len;
|
||||||
|
}
|
||||||
Ok(total)
|
Ok(total)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user