nrf: Use .is_empty() instead of .len() == 0
This commit is contained in:
parent
377e58e408
commit
1aa999c2a8
5 changed files with 14 additions and 14 deletions
|
@ -185,7 +185,7 @@ impl<'d, T: Instance> Pdm<'d, T> {
|
|||
|
||||
/// Sample data into the given buffer
|
||||
pub async fn sample(&mut self, buffer: &mut [i16]) -> Result<(), Error> {
|
||||
if buffer.len() == 0 {
|
||||
if buffer.is_empty() {
|
||||
return Err(Error::BufferZeroLength);
|
||||
}
|
||||
if buffer.len() > EASY_DMA_SIZE {
|
||||
|
|
|
@ -402,7 +402,7 @@ impl<'d, T: Instance> Qspi<'d, T> {
|
|||
/// a raw bus, not with flash memory.
|
||||
pub async fn read_raw(&mut self, address: u32, data: &mut [u8]) -> Result<(), Error> {
|
||||
// Avoid blocking_wait_ready() blocking forever on zero-length buffers.
|
||||
if data.len() == 0 {
|
||||
if data.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -423,7 +423,7 @@ impl<'d, T: Instance> Qspi<'d, T> {
|
|||
/// a raw bus, not with flash memory.
|
||||
pub async fn write_raw(&mut self, address: u32, data: &[u8]) -> Result<(), Error> {
|
||||
// Avoid blocking_wait_ready() blocking forever on zero-length buffers.
|
||||
if data.len() == 0 {
|
||||
if data.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -444,7 +444,7 @@ impl<'d, T: Instance> Qspi<'d, T> {
|
|||
/// a raw bus, not with flash memory.
|
||||
pub fn blocking_read_raw(&mut self, address: u32, data: &mut [u8]) -> Result<(), Error> {
|
||||
// Avoid blocking_wait_ready() blocking forever on zero-length buffers.
|
||||
if data.len() == 0 {
|
||||
if data.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -460,7 +460,7 @@ impl<'d, T: Instance> Qspi<'d, T> {
|
|||
/// a raw bus, not with flash memory.
|
||||
pub fn blocking_write_raw(&mut self, address: u32, data: &[u8]) -> Result<(), Error> {
|
||||
// Avoid blocking_wait_ready() blocking forever on zero-length buffers.
|
||||
if data.len() == 0 {
|
||||
if data.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ impl<'d, T: Instance> Rng<'d, T> {
|
|||
|
||||
/// Fill the buffer with random bytes.
|
||||
pub async fn fill_bytes(&mut self, dest: &mut [u8]) {
|
||||
if dest.len() == 0 {
|
||||
if dest.is_empty() {
|
||||
return; // Nothing to fill
|
||||
}
|
||||
|
||||
|
|
|
@ -372,7 +372,7 @@ impl<'d, T: Instance> Twim<'d, T> {
|
|||
// Start write operation.
|
||||
r.shorts.write(|w| w.lasttx_stop().enabled());
|
||||
r.tasks_starttx.write(|w| unsafe { w.bits(1) });
|
||||
if buffer.len() == 0 {
|
||||
if buffer.is_empty() {
|
||||
// With a zero-length buffer, LASTTX doesn't fire (because there's no last byte!), so do the STOP ourselves.
|
||||
r.tasks_stop.write(|w| unsafe { w.bits(1) });
|
||||
}
|
||||
|
@ -403,7 +403,7 @@ impl<'d, T: Instance> Twim<'d, T> {
|
|||
// Start read operation.
|
||||
r.shorts.write(|w| w.lastrx_stop().enabled());
|
||||
r.tasks_startrx.write(|w| unsafe { w.bits(1) });
|
||||
if buffer.len() == 0 {
|
||||
if buffer.is_empty() {
|
||||
// With a zero-length buffer, LASTRX doesn't fire (because there's no last byte!), so do the STOP ourselves.
|
||||
r.tasks_stop.write(|w| unsafe { w.bits(1) });
|
||||
}
|
||||
|
@ -447,7 +447,7 @@ impl<'d, T: Instance> Twim<'d, T> {
|
|||
w
|
||||
});
|
||||
r.tasks_starttx.write(|w| unsafe { w.bits(1) });
|
||||
if wr_buffer.len() == 0 && rd_buffer.len() == 0 {
|
||||
if wr_buffer.is_empty() && rd_buffer.is_empty() {
|
||||
// With a zero-length buffer, LASTRX/LASTTX doesn't fire (because there's no last byte!), so do the STOP ourselves.
|
||||
// TODO handle when only one of the buffers is zero length
|
||||
r.tasks_stop.write(|w| unsafe { w.bits(1) });
|
||||
|
|
|
@ -386,7 +386,7 @@ impl<'d, T: Instance> UarteTx<'d, T> {
|
|||
|
||||
/// Same as [`write`](Self::write) but will fail instead of copying data into RAM. Consult the module level documentation to learn more.
|
||||
pub async fn write_from_ram(&mut self, buffer: &[u8]) -> Result<(), Error> {
|
||||
if buffer.len() == 0 {
|
||||
if buffer.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -456,7 +456,7 @@ impl<'d, T: Instance> UarteTx<'d, T> {
|
|||
|
||||
/// Same as [`write_from_ram`](Self::write_from_ram) but will fail instead of copying data into RAM. Consult the module level documentation to learn more.
|
||||
pub fn blocking_write_from_ram(&mut self, buffer: &[u8]) -> Result<(), Error> {
|
||||
if buffer.len() == 0 {
|
||||
if buffer.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -694,7 +694,7 @@ impl<'d, T: Instance> UarteRx<'d, T> {
|
|||
|
||||
/// Read bytes until the buffer is filled.
|
||||
pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
|
||||
if buffer.len() == 0 {
|
||||
if buffer.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
if buffer.len() > EASY_DMA_SIZE {
|
||||
|
@ -775,7 +775,7 @@ impl<'d, T: Instance, U: TimerInstance> UarteRxWithIdle<'d, T, U> {
|
|||
///
|
||||
/// Returns the amount of bytes read.
|
||||
pub async fn read_until_idle(&mut self, buffer: &mut [u8]) -> Result<usize, Error> {
|
||||
if buffer.len() == 0 {
|
||||
if buffer.is_empty() {
|
||||
return Ok(0);
|
||||
}
|
||||
if buffer.len() > EASY_DMA_SIZE {
|
||||
|
@ -848,7 +848,7 @@ impl<'d, T: Instance, U: TimerInstance> UarteRxWithIdle<'d, T, U> {
|
|||
///
|
||||
/// Returns the amount of bytes read.
|
||||
pub fn blocking_read_until_idle(&mut self, buffer: &mut [u8]) -> Result<usize, Error> {
|
||||
if buffer.len() == 0 {
|
||||
if buffer.is_empty() {
|
||||
return Ok(0);
|
||||
}
|
||||
if buffer.len() > EASY_DMA_SIZE {
|
||||
|
|
Loading…
Reference in a new issue