diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-08-18 13:12:19 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-08-18 13:21:21 +0200 |
| commit | b948e3776969ac488abb6507ce429fee33ceb48b (patch) | |
| tree | 5da36765d3e0b44b3fabb13ba9e8d620d25fb660 /embassy-rp/src | |
| parent | 94fa95c699df78c44750b63ba1a44c07802d0165 (diff) | |
rp/flash: change naming to `blocking_*`, `new_blocking`.
- Needed for consistency with other drivers.
- Having two `new()` functions sometimes resulted in 'multiple applicable methods' errors.
Diffstat (limited to 'embassy-rp/src')
| -rw-r--r-- | embassy-rp/src/flash.rs | 100 |
1 files changed, 52 insertions, 48 deletions
diff --git a/embassy-rp/src/flash.rs b/embassy-rp/src/flash.rs index 70d867319..1c1c2449e 100644 --- a/embassy-rp/src/flash.rs +++ b/embassy-rp/src/flash.rs | |||
| @@ -102,7 +102,7 @@ pub struct Flash<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> { | |||
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> Flash<'d, T, M, FLASH_SIZE> { | 104 | impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> Flash<'d, T, M, FLASH_SIZE> { |
| 105 | pub fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { | 105 | pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { |
| 106 | trace!( | 106 | trace!( |
| 107 | "Reading from 0x{:x} to 0x{:x}", | 107 | "Reading from 0x{:x} to 0x{:x}", |
| 108 | FLASH_BASE as u32 + offset, | 108 | FLASH_BASE as u32 + offset, |
| @@ -120,7 +120,7 @@ impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> Flash<'d, T, M, FLASH_SI | |||
| 120 | FLASH_SIZE | 120 | FLASH_SIZE |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | pub fn erase(&mut self, from: u32, to: u32) -> Result<(), Error> { | 123 | pub fn blocking_erase(&mut self, from: u32, to: u32) -> Result<(), Error> { |
| 124 | check_erase(self, from, to)?; | 124 | check_erase(self, from, to)?; |
| 125 | 125 | ||
| 126 | trace!( | 126 | trace!( |
| @@ -136,7 +136,7 @@ impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> Flash<'d, T, M, FLASH_SI | |||
| 136 | Ok(()) | 136 | Ok(()) |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | pub fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { | 139 | pub fn blocking_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { |
| 140 | check_write(self, offset, bytes.len())?; | 140 | check_write(self, offset, bytes.len())?; |
| 141 | 141 | ||
| 142 | trace!("Writing {:?} bytes to 0x{:x}", bytes.len(), FLASH_BASE as u32 + offset); | 142 | trace!("Writing {:?} bytes to 0x{:x}", bytes.len(), FLASH_BASE as u32 + offset); |
| @@ -233,13 +233,13 @@ impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> Flash<'d, T, M, FLASH_SI | |||
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | /// Read SPI flash unique ID | 235 | /// Read SPI flash unique ID |
| 236 | pub fn unique_id(&mut self, uid: &mut [u8]) -> Result<(), Error> { | 236 | pub fn blocking_unique_id(&mut self, uid: &mut [u8]) -> Result<(), Error> { |
| 237 | unsafe { self.in_ram(|| ram_helpers::flash_unique_id(uid))? }; | 237 | unsafe { self.in_ram(|| ram_helpers::flash_unique_id(uid))? }; |
| 238 | Ok(()) | 238 | Ok(()) |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | /// Read SPI flash JEDEC ID | 241 | /// Read SPI flash JEDEC ID |
| 242 | pub fn jedec_id(&mut self) -> Result<u32, Error> { | 242 | pub fn blocking_jedec_id(&mut self) -> Result<u32, Error> { |
| 243 | let mut jedec = None; | 243 | let mut jedec = None; |
| 244 | unsafe { | 244 | unsafe { |
| 245 | self.in_ram(|| { | 245 | self.in_ram(|| { |
| @@ -251,7 +251,7 @@ impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> Flash<'d, T, M, FLASH_SI | |||
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, Blocking, FLASH_SIZE> { | 253 | impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, Blocking, FLASH_SIZE> { |
| 254 | pub fn new(_flash: impl Peripheral<P = T> + 'd) -> Self { | 254 | pub fn new_blocking(_flash: impl Peripheral<P = T> + 'd) -> Self { |
| 255 | Self { | 255 | Self { |
| 256 | dma: None, | 256 | dma: None, |
| 257 | phantom: PhantomData, | 257 | phantom: PhantomData, |
| @@ -310,47 +310,8 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, Async, FLASH_SIZE> { | |||
| 310 | transfer, | 310 | transfer, |
| 311 | }) | 311 | }) |
| 312 | } | 312 | } |
| 313 | } | ||
| 314 | |||
| 315 | impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> ErrorType for Flash<'d, T, M, FLASH_SIZE> { | ||
| 316 | type Error = Error; | ||
| 317 | } | ||
| 318 | |||
| 319 | impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> ReadNorFlash for Flash<'d, T, M, FLASH_SIZE> { | ||
| 320 | const READ_SIZE: usize = READ_SIZE; | ||
| 321 | |||
| 322 | fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { | ||
| 323 | self.read(offset, bytes) | ||
| 324 | } | ||
| 325 | |||
| 326 | fn capacity(&self) -> usize { | ||
| 327 | self.capacity() | ||
| 328 | } | ||
| 329 | } | ||
| 330 | |||
| 331 | impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> MultiwriteNorFlash for Flash<'d, T, M, FLASH_SIZE> {} | ||
| 332 | |||
| 333 | impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> NorFlash for Flash<'d, T, M, FLASH_SIZE> { | ||
| 334 | const WRITE_SIZE: usize = WRITE_SIZE; | ||
| 335 | |||
| 336 | const ERASE_SIZE: usize = ERASE_SIZE; | ||
| 337 | |||
| 338 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { | ||
| 339 | self.erase(from, to) | ||
| 340 | } | ||
| 341 | 313 | ||
| 342 | fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { | 314 | pub async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { |
| 343 | self.write(offset, bytes) | ||
| 344 | } | ||
| 345 | } | ||
| 346 | |||
| 347 | #[cfg(feature = "nightly")] | ||
| 348 | impl<'d, T: Instance, const FLASH_SIZE: usize> embedded_storage_async::nor_flash::ReadNorFlash | ||
| 349 | for Flash<'d, T, Async, FLASH_SIZE> | ||
| 350 | { | ||
| 351 | const READ_SIZE: usize = ASYNC_READ_SIZE; | ||
| 352 | |||
| 353 | async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { | ||
| 354 | use core::mem::MaybeUninit; | 315 | use core::mem::MaybeUninit; |
| 355 | 316 | ||
| 356 | // Checked early to simplify address validity checks | 317 | // Checked early to simplify address validity checks |
| @@ -389,6 +350,49 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> embedded_storage_async::nor_flash | |||
| 389 | 350 | ||
| 390 | Ok(()) | 351 | Ok(()) |
| 391 | } | 352 | } |
| 353 | } | ||
| 354 | |||
| 355 | impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> ErrorType for Flash<'d, T, M, FLASH_SIZE> { | ||
| 356 | type Error = Error; | ||
| 357 | } | ||
| 358 | |||
| 359 | impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> ReadNorFlash for Flash<'d, T, M, FLASH_SIZE> { | ||
| 360 | const READ_SIZE: usize = READ_SIZE; | ||
| 361 | |||
| 362 | fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { | ||
| 363 | self.blocking_read(offset, bytes) | ||
| 364 | } | ||
| 365 | |||
| 366 | fn capacity(&self) -> usize { | ||
| 367 | self.capacity() | ||
| 368 | } | ||
| 369 | } | ||
| 370 | |||
| 371 | impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> MultiwriteNorFlash for Flash<'d, T, M, FLASH_SIZE> {} | ||
| 372 | |||
| 373 | impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> NorFlash for Flash<'d, T, M, FLASH_SIZE> { | ||
| 374 | const WRITE_SIZE: usize = WRITE_SIZE; | ||
| 375 | |||
| 376 | const ERASE_SIZE: usize = ERASE_SIZE; | ||
| 377 | |||
| 378 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { | ||
| 379 | self.blocking_erase(from, to) | ||
| 380 | } | ||
| 381 | |||
| 382 | fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { | ||
| 383 | self.blocking_write(offset, bytes) | ||
| 384 | } | ||
| 385 | } | ||
| 386 | |||
| 387 | #[cfg(feature = "nightly")] | ||
| 388 | impl<'d, T: Instance, const FLASH_SIZE: usize> embedded_storage_async::nor_flash::ReadNorFlash | ||
| 389 | for Flash<'d, T, Async, FLASH_SIZE> | ||
| 390 | { | ||
| 391 | const READ_SIZE: usize = ASYNC_READ_SIZE; | ||
| 392 | |||
| 393 | async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { | ||
| 394 | self.read(offset, bytes).await | ||
| 395 | } | ||
| 392 | 396 | ||
| 393 | fn capacity(&self) -> usize { | 397 | fn capacity(&self) -> usize { |
| 394 | self.capacity() | 398 | self.capacity() |
| @@ -404,11 +408,11 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> embedded_storage_async::nor_flash | |||
| 404 | const ERASE_SIZE: usize = ERASE_SIZE; | 408 | const ERASE_SIZE: usize = ERASE_SIZE; |
| 405 | 409 | ||
| 406 | async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { | 410 | async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { |
| 407 | self.erase(from, to) | 411 | self.blocking_erase(from, to) |
| 408 | } | 412 | } |
| 409 | 413 | ||
| 410 | async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { | 414 | async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { |
| 411 | self.write(offset, bytes) | 415 | self.blocking_write(offset, bytes) |
| 412 | } | 416 | } |
| 413 | } | 417 | } |
| 414 | 418 | ||
