memspi_host_driver.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include "hal/spi_flash_hal.h"
  16. /** Default configuration for the memspi (high speed version) */
  17. #define ESP_FLASH_DEFAULT_HOST_DRIVER() (spi_flash_host_driver_t) { \
  18. .dev_config = spi_flash_hal_device_config, \
  19. .common_command = spi_flash_hal_common_command, \
  20. .read_id = memspi_host_read_id_hs, \
  21. .erase_chip = spi_flash_hal_erase_chip, \
  22. .erase_sector = spi_flash_hal_erase_sector, \
  23. .erase_block = spi_flash_hal_erase_block, \
  24. .read_status = memspi_host_read_status_hs, \
  25. .set_write_protect = spi_flash_hal_set_write_protect, \
  26. .supports_direct_write = spi_flash_hal_supports_direct_write, \
  27. .supports_direct_read = spi_flash_hal_supports_direct_read, \
  28. .program_page = spi_flash_hal_program_page, \
  29. .max_write_bytes = SPI_FLASH_HAL_MAX_WRITE_BYTES, \
  30. .read = spi_flash_hal_read, \
  31. .max_read_bytes = SPI_FLASH_HAL_MAX_READ_BYTES, \
  32. .host_idle = spi_flash_hal_host_idle, \
  33. .configure_host_io_mode = spi_flash_hal_configure_host_io_mode, \
  34. .poll_cmd_done = spi_flash_hal_poll_cmd_done, \
  35. .flush_cache = memspi_host_flush_cache, \
  36. }
  37. /// configuration for the memspi host
  38. typedef spi_flash_memspi_config_t memspi_host_config_t;
  39. /// context for the memspi host
  40. typedef spi_flash_memspi_data_t memspi_host_data_t;
  41. /**
  42. * Initialize the memory SPI host.
  43. *
  44. * @param host Pointer to the host structure.
  45. * @param data Pointer to allocated space to hold the context of host driver.
  46. * @param cfg Pointer to configuration structure
  47. *
  48. * @return always return ESP_OK
  49. */
  50. esp_err_t memspi_host_init_pointers(spi_flash_host_driver_t *host, memspi_host_data_t *data, const memspi_host_config_t *cfg);
  51. /*******************************************************************************
  52. * NOTICE
  53. * Rest part of this file are part of the HAL layer
  54. * The HAL is not public api, don't use in application code.
  55. * See readme.md in soc/include/hal/readme.md
  56. ******************************************************************************/
  57. /**
  58. * @brief Read the Status Register read from RDSR (05h).
  59. *
  60. * High speed implementation of RDID through memspi interface relying on the
  61. * ``common_command``.
  62. *
  63. * @param driver The driver context.
  64. * @param id Output of the read ID from the slave.
  65. *
  66. * @return
  67. * - ESP_OK: if success
  68. * - ESP_ERR_FLASH_NO_RESPONSE: if no response from chip
  69. * - or other cases from ``spi_hal_common_command``
  70. */
  71. esp_err_t memspi_host_read_id_hs(spi_flash_host_driver_t *driver, uint32_t *id);
  72. /**
  73. * High speed implementation of RDSR through memspi interface relying on the
  74. * ``common_command``.
  75. *
  76. * @param driver The driver context.
  77. * @param id Output of the read ID from the slave.
  78. *
  79. * @return
  80. * - ESP_OK: if success
  81. * - or other cases from ``spi_hal_common_command``
  82. */
  83. esp_err_t memspi_host_read_status_hs(spi_flash_host_driver_t *driver, uint8_t *out_sr);
  84. /**
  85. * Flush the cache (if needed) after the contents are modified.
  86. *
  87. * @param driver The driver context.
  88. * @param addr Start address of the modified region
  89. * @param size Size of the region modified.
  90. *
  91. * @return always ESP_OK.
  92. */
  93. esp_err_t memspi_host_flush_cache(spi_flash_host_driver_t* driver, uint32_t addr, uint32_t size);