mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_flash: rename internal variables for better readability
chip_drv in HAL are renamed as host
This commit is contained in:
parent
2b7681ec4f
commit
41e64bd79c
@ -19,22 +19,22 @@
|
|||||||
|
|
||||||
#define ADDRESS_MASK_24BIT 0xFFFFFF
|
#define ADDRESS_MASK_24BIT 0xFFFFFF
|
||||||
|
|
||||||
static inline spi_dev_t *get_spi_dev(spi_flash_host_driver_t *chip_drv)
|
static inline spi_dev_t *get_spi_dev(spi_flash_host_driver_t *host)
|
||||||
{
|
{
|
||||||
return ((spi_flash_memspi_data_t *)chip_drv->driver_data)->spi;
|
return ((spi_flash_memspi_data_t *)host->driver_data)->spi;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_flash_hal_poll_cmd_done(spi_flash_host_driver_t *driver)
|
void spi_flash_hal_poll_cmd_done(spi_flash_host_driver_t *host)
|
||||||
{
|
{
|
||||||
while (!spi_flash_ll_cmd_is_done(get_spi_dev(driver))) {
|
while (!spi_flash_ll_cmd_is_done(get_spi_dev(host))) {
|
||||||
//nop
|
//nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t spi_flash_hal_device_config(spi_flash_host_driver_t *driver)
|
esp_err_t spi_flash_hal_device_config(spi_flash_host_driver_t *host)
|
||||||
{
|
{
|
||||||
spi_flash_memspi_data_t *drv_data = (spi_flash_memspi_data_t *)driver->driver_data;
|
spi_flash_memspi_data_t *drv_data = (spi_flash_memspi_data_t *)host->driver_data;
|
||||||
spi_dev_t *dev = get_spi_dev(driver);
|
spi_dev_t *dev = get_spi_dev(host);
|
||||||
spi_flash_ll_reset(dev);
|
spi_flash_ll_reset(dev);
|
||||||
spi_flash_ll_set_cs_pin(dev, drv_data->cs_num);
|
spi_flash_ll_set_cs_pin(dev, drv_data->cs_num);
|
||||||
spi_flash_ll_set_clock(dev, &drv_data->clock_conf);
|
spi_flash_ll_set_clock(dev, &drv_data->clock_conf);
|
||||||
@ -60,9 +60,9 @@ esp_err_t spi_flash_hal_configure_host_io_mode(
|
|||||||
esp_flash_io_mode_t io_mode)
|
esp_flash_io_mode_t io_mode)
|
||||||
{
|
{
|
||||||
// Add dummy cycles to compensate for latency of GPIO matrix and external delay, if necessary...
|
// Add dummy cycles to compensate for latency of GPIO matrix and external delay, if necessary...
|
||||||
int dummy_cyclelen = dummy_cyclelen_base + ((spi_flash_memspi_data_t *)driver->driver_data)->extra_dummy;
|
int dummy_cyclelen = dummy_cyclelen_base + ((spi_flash_memspi_data_t *)host->driver_data)->extra_dummy;
|
||||||
|
|
||||||
spi_dev_t *dev = get_spi_dev(driver);
|
spi_dev_t *dev = get_spi_dev(host);
|
||||||
spi_flash_ll_set_command8(dev, command);
|
spi_flash_ll_set_command8(dev, command);
|
||||||
spi_flash_ll_set_addr_bitlen(dev, addr_bitlen);
|
spi_flash_ll_set_addr_bitlen(dev, addr_bitlen);
|
||||||
spi_flash_ll_set_dummy(dev, dummy_cyclelen);
|
spi_flash_ll_set_dummy(dev, dummy_cyclelen);
|
||||||
@ -73,11 +73,11 @@ esp_err_t spi_flash_hal_configure_host_io_mode(
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t spi_flash_hal_common_command(spi_flash_host_driver_t *chip_drv, spi_flash_trans_t *trans)
|
esp_err_t spi_flash_hal_common_command(spi_flash_host_driver_t *host, spi_flash_trans_t *trans)
|
||||||
{
|
{
|
||||||
host->configure_host_io_mode(host, trans->command, 0, 0, SPI_FLASH_FASTRD);
|
host->configure_host_io_mode(host, trans->command, 0, 0, SPI_FLASH_FASTRD);
|
||||||
|
|
||||||
spi_dev_t *dev = get_spi_dev(chip_drv);
|
spi_dev_t *dev = get_spi_dev(host);
|
||||||
//disable dummy if no input phase
|
//disable dummy if no input phase
|
||||||
if (trans->miso_len == 0) {
|
if (trans->miso_len == 0) {
|
||||||
spi_flash_ll_set_dummy(dev, 0);
|
spi_flash_ll_set_dummy(dev, 0);
|
||||||
@ -89,61 +89,61 @@ esp_err_t spi_flash_hal_common_command(spi_flash_host_driver_t *chip_drv, spi_fl
|
|||||||
spi_flash_ll_write_word(dev, trans->mosi_data);
|
spi_flash_ll_write_word(dev, trans->mosi_data);
|
||||||
|
|
||||||
spi_flash_ll_user_start(dev);
|
spi_flash_ll_user_start(dev);
|
||||||
chip_drv->poll_cmd_done(chip_drv);
|
host->poll_cmd_done(host);
|
||||||
spi_flash_ll_get_buffer_data(dev, trans->miso_data, 8);
|
spi_flash_ll_get_buffer_data(dev, trans->miso_data, 8);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_flash_hal_erase_chip(spi_flash_host_driver_t *chip_drv)
|
void spi_flash_hal_erase_chip(spi_flash_host_driver_t *host)
|
||||||
{
|
{
|
||||||
spi_dev_t *dev = get_spi_dev(chip_drv);
|
spi_dev_t *dev = get_spi_dev(host);
|
||||||
spi_flash_ll_erase_chip(dev);
|
spi_flash_ll_erase_chip(dev);
|
||||||
chip_drv->poll_cmd_done(chip_drv);
|
host->poll_cmd_done(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_flash_hal_erase_sector(spi_flash_host_driver_t *chip_drv, uint32_t start_address)
|
void spi_flash_hal_erase_sector(spi_flash_host_driver_t *host, uint32_t start_address)
|
||||||
{
|
{
|
||||||
spi_dev_t *dev = get_spi_dev(chip_drv);
|
spi_dev_t *dev = get_spi_dev(host);
|
||||||
spi_flash_ll_set_addr_bitlen(dev, 24);
|
spi_flash_ll_set_addr_bitlen(dev, 24);
|
||||||
spi_flash_ll_set_address(dev, start_address & ADDRESS_MASK_24BIT);
|
spi_flash_ll_set_address(dev, start_address & ADDRESS_MASK_24BIT);
|
||||||
spi_flash_ll_erase_sector(dev);
|
spi_flash_ll_erase_sector(dev);
|
||||||
chip_drv->poll_cmd_done(chip_drv);
|
host->poll_cmd_done(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_flash_hal_erase_block(spi_flash_host_driver_t *chip_drv, uint32_t start_address)
|
void spi_flash_hal_erase_block(spi_flash_host_driver_t *host, uint32_t start_address)
|
||||||
{
|
{
|
||||||
spi_dev_t *dev = get_spi_dev(chip_drv);
|
spi_dev_t *dev = get_spi_dev(host);
|
||||||
spi_flash_ll_set_addr_bitlen(dev, 24);
|
spi_flash_ll_set_addr_bitlen(dev, 24);
|
||||||
spi_flash_ll_set_address(dev, start_address & ADDRESS_MASK_24BIT);
|
spi_flash_ll_set_address(dev, start_address & ADDRESS_MASK_24BIT);
|
||||||
spi_flash_ll_erase_block(dev);
|
spi_flash_ll_erase_block(dev);
|
||||||
chip_drv->poll_cmd_done(chip_drv);
|
host->poll_cmd_done(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_flash_hal_program_page(spi_flash_host_driver_t *chip_drv, const void *buffer, uint32_t address, uint32_t length)
|
void spi_flash_hal_program_page(spi_flash_host_driver_t *host, const void *buffer, uint32_t address, uint32_t length)
|
||||||
{
|
{
|
||||||
spi_dev_t *dev = get_spi_dev(chip_drv);
|
spi_dev_t *dev = get_spi_dev(host);
|
||||||
spi_flash_ll_set_addr_bitlen(dev, 24);
|
spi_flash_ll_set_addr_bitlen(dev, 24);
|
||||||
spi_flash_ll_set_address(dev, (address & ADDRESS_MASK_24BIT) | (length << 24));
|
spi_flash_ll_set_address(dev, (address & ADDRESS_MASK_24BIT) | (length << 24));
|
||||||
spi_flash_ll_program_page(dev, buffer, length);
|
spi_flash_ll_program_page(dev, buffer, length);
|
||||||
chip_drv->poll_cmd_done(chip_drv);
|
host->poll_cmd_done(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t spi_flash_hal_read(spi_flash_host_driver_t *chip_drv, void *buffer, uint32_t address, uint32_t read_len)
|
esp_err_t spi_flash_hal_read(spi_flash_host_driver_t *host, void *buffer, uint32_t address, uint32_t read_len)
|
||||||
{
|
{
|
||||||
spi_dev_t *dev = get_spi_dev(chip_drv);
|
spi_dev_t *dev = get_spi_dev(host);
|
||||||
//the command is already set by ``spi_flash_hal_configure_host_io_mode`` before.
|
//the command is already set by ``spi_flash_hal_configure_host_io_mode`` before.
|
||||||
spi_flash_ll_set_address(dev, address << 8);
|
spi_flash_ll_set_address(dev, address << 8);
|
||||||
spi_flash_ll_set_miso_bitlen(dev, read_len * 8);
|
spi_flash_ll_set_miso_bitlen(dev, read_len * 8);
|
||||||
spi_flash_ll_user_start(dev);
|
spi_flash_ll_user_start(dev);
|
||||||
chip_drv->poll_cmd_done(chip_drv);
|
host->poll_cmd_done(host);
|
||||||
spi_flash_ll_get_buffer_data(dev, buffer, read_len);
|
spi_flash_ll_get_buffer_data(dev, buffer, read_len);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool spi_flash_hal_host_idle(spi_flash_host_driver_t *chip_drv)
|
bool spi_flash_hal_host_idle(spi_flash_host_driver_t *host)
|
||||||
{
|
{
|
||||||
spi_dev_t *dev = get_spi_dev(chip_drv);
|
spi_dev_t *dev = get_spi_dev(host);
|
||||||
bool idle = spi_flash_ll_host_idle(dev);
|
bool idle = spi_flash_ll_host_idle(dev);
|
||||||
|
|
||||||
// Not clear if this is necessary, or only necessary if
|
// Not clear if this is necessary, or only necessary if
|
||||||
@ -155,10 +155,10 @@ bool spi_flash_hal_host_idle(spi_flash_host_driver_t *chip_drv)
|
|||||||
return idle;
|
return idle;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t spi_flash_hal_set_write_protect(spi_flash_host_driver_t *chip_drv, bool wp)
|
esp_err_t spi_flash_hal_set_write_protect(spi_flash_host_driver_t *host, bool wp)
|
||||||
{
|
{
|
||||||
spi_dev_t *dev = get_spi_dev(chip_drv);
|
spi_dev_t *dev = get_spi_dev(host);
|
||||||
spi_flash_ll_set_write_protect(dev, wp);
|
spi_flash_ll_set_write_protect(dev, wp);
|
||||||
chip_drv->poll_cmd_done(chip_drv);
|
host->poll_cmd_done(host);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ esp_err_t memspi_host_init_pointers(spi_flash_host_driver_t *host, memspi_host_d
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t memspi_host_read_id_hs(spi_flash_host_driver_t *chip_drv, uint32_t *id)
|
esp_err_t memspi_host_read_id_hs(spi_flash_host_driver_t *host, uint32_t *id)
|
||||||
{
|
{
|
||||||
//NOTE: we do have a read id function, however it doesn't work in high freq
|
//NOTE: we do have a read id function, however it doesn't work in high freq
|
||||||
spi_flash_trans_t t = {
|
spi_flash_trans_t t = {
|
||||||
@ -47,7 +47,7 @@ esp_err_t memspi_host_read_id_hs(spi_flash_host_driver_t *chip_drv, uint32_t *id
|
|||||||
.mosi_len = 0,
|
.mosi_len = 0,
|
||||||
.miso_len = 24
|
.miso_len = 24
|
||||||
};
|
};
|
||||||
chip_drv->common_command(chip_drv, &t);
|
host->common_command(host, &t);
|
||||||
uint32_t raw_flash_id = t.miso_data[0];
|
uint32_t raw_flash_id = t.miso_data[0];
|
||||||
ESP_EARLY_LOGV(TAG, "raw_chip_id: %X\n", raw_flash_id);
|
ESP_EARLY_LOGV(TAG, "raw_chip_id: %X\n", raw_flash_id);
|
||||||
if (raw_flash_id == 0xFFFFFF || raw_flash_id == 0) {
|
if (raw_flash_id == 0xFFFFFF || raw_flash_id == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user