Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent SPI Timing (Need review) #943

Closed
wants to merge 14 commits into from
20 changes: 11 additions & 9 deletions esp-hal-common/src/spi/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2708,23 +2708,25 @@ pub trait Instance {
// FIXME: Using something like `core::slice::from_raw_parts` and
// `copy_from_slice` on the receive registers works only for the esp32 and
// esp32c3 varaints. The reason for this is unknown.
#[inline]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guess the comment above this attribute is no longer right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, since the S3 and ESP32 should have the same processor?

fn read_bytes_from_fifo(&mut self, words: &mut [u8]) -> Result<(), Error> {
let reg_block = self.register_block();

for chunk in words.chunks_mut(FIFO_SIZE) {
self.configure_datalen(chunk.len() as u32 * 8);

let mut fifo_ptr = reg_block.w0.as_ptr();
for index in (0..chunk.len()).step_by(4) {
let reg_val = unsafe { *fifo_ptr };
let fifo_slice =
unsafe { core::slice::from_raw_parts(reg_block.w0.as_ptr(), FIFO_SIZE) };
for (blk, index) in (0..chunk.len()).step_by(4).enumerate() {
let reg_val = fifo_slice[blk];
let bytes = reg_val.to_le_bytes();

let len = usize::min(chunk.len(), index + 4) - index;
chunk[index..(index + len)].clone_from_slice(&bytes[0..len]);
if index + 4 > chunk.len() {
let len = usize::min(chunk.len(), index + 4) - index;
chunk[index..(index + len)].copy_from_slice(&bytes[0..len]);
break;
}

unsafe {
fifo_ptr = fifo_ptr.offset(1);
};
chunk[index..(index + 4)].copy_from_slice(&bytes);
}
}

Expand Down
Loading