Skip to content

Commit

Permalink
Fixed review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaibal-Microsoft committed Mar 6, 2025
1 parent d70cdd6 commit 6ba2ca9
Showing 1 changed file with 10 additions and 29 deletions.
39 changes: 10 additions & 29 deletions examples/rt685s-evk/src/bin/flexspi-storage-service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,26 @@ use embassy_imxrt::flexspi_nor_storage_bus::{
FlexspiAhbWriteWaitUnit, FlexspiConfig, FlexspiCsIntervalCycleUnit, FlexspiDeviceConfig, FlexspiNorStorageBus,
FlexspiReadSampleClock,
};
use embassy_imxrt::spi_nor_storage_bus::SpiNorStorageBus;
use embassy_imxrt::storage::{
BlockingNorStorageDriver, ConfigureCmdSeq, NorStorageCmd, NorStorageCmdMode, NorStorageCmdSeq, NorStorageCmdType,
BlockingNorStorageDriver, NorStorageCmd, NorStorageCmdMode, NorStorageCmdSeq, NorStorageCmdType,
};
use embassy_time::Timer;
use embedded_storage::nor_flash::{NorFlash as BlockingNorFlash, ReadNorFlash as BlockingReadNorFlash};
use {defmt_rtt as _, panic_probe as _};

static ADDR: u32 = 0x2F000;

struct MacronixDeviceDriver {
struct MacronixDeviceDriver<T: BlockingNorStorageDriver> {
// Bus driver dependency
spi_nor_storage_bus: Option<SpiNorStorageBus<embassy_imxrt::spi_nor_storage_bus::Blocking>>,
flexspi_nor_storage_bus: Option<FlexspiNorStorageBus<embassy_imxrt::flexspi_nor_storage_bus::Blocking>>,
storagebusdriver: T,
}

impl MacronixDeviceDriver {
pub fn new(
spidriver: Option<SpiNorStorageBus<embassy_imxrt::spi_nor_storage_bus::Blocking>>,
flexspidriver: Option<FlexspiNorStorageBus<embassy_imxrt::flexspi_nor_storage_bus::Blocking>>,
) -> Result<Self, ()> {
if let Some(spi) = spidriver {
return Ok(MacronixDeviceDriver {
spi_nor_storage_bus: Some(spi),
flexspi_nor_storage_bus: None,
});
};
if let Some(flexspi) = flexspidriver {
return Ok(MacronixDeviceDriver {
spi_nor_storage_bus: None,
flexspi_nor_storage_bus: Some(flexspi),
});
}

Err(())
impl<T: BlockingNorStorageDriver> MacronixDeviceDriver<T> {
pub fn new(storagebusdriver: T) -> Result<Self, ()> {
Ok(Self { storagebusdriver })
}

pub fn init(&self) {
let bus_ref = self.flexspi_nor_storage_bus.as_ref().unwrap();
let bus_ref = &self.storagebusdriver;
let cmdarr = NorStorageCmdSeq {
fast_read: Some(NorStorageCmd {
cmd_lb: 0xEE,
Expand Down Expand Up @@ -112,13 +93,13 @@ impl MacronixDeviceDriver {
}

pub fn read(&mut self, addr: u32, data: &mut [u8]) {
let bus_ref = self.flexspi_nor_storage_bus.as_mut().unwrap();
let bus_ref = &mut self.storagebusdriver;
// Read data from the storage device
bus_ref.read(addr as u32, data);
}

pub fn write(&mut self, addr: u32, data: &[u8]) {
let bus_ref = self.flexspi_nor_storage_bus.as_mut().unwrap();
let bus_ref = &mut self.storagebusdriver;
// Write data to the storage device
bus_ref.write_enable();

Expand Down Expand Up @@ -227,7 +208,7 @@ async fn main(_spawner: Spawner) {
.configure_flexspi_device(&flash_config, &flexspi_config); // Configure the Flash device specific parameters like CS time, etc

// Instanctiate the storage device driver and inject the bus driver dependency
let mut device_driver = MacronixDeviceDriver::new(None, Some(flexspi_storage)).unwrap();
let mut device_driver = MacronixDeviceDriver::new(flexspi_storage).unwrap();
device_driver.init();

// write data
Expand Down

0 comments on commit 6ba2ca9

Please sign in to comment.