esp_flash_spi_init.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_types.h"
  16. #include "esp_flash.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /// Configurations for the SPI Flash to init
  21. typedef struct {
  22. spi_host_device_t host_id; ///< Bus to use
  23. int cs_io_num; ///< GPIO pin to output the CS signal
  24. esp_flash_io_mode_t io_mode; ///< IO mode to read from the Flash
  25. esp_flash_speed_t speed; ///< Speed of the Flash clock
  26. int input_delay_ns; ///< Input delay of the data pins, in ns. Set to 0 if unknown.
  27. /**
  28. * CS line ID, ignored when not `host_id` is not SPI1_HOST, or
  29. * `CONFIG_SPI_FLASH_SHARE_SPI1_BUS` is enabled. In this case, the CS line used is
  30. * automatically assigned by the SPI bus lock.
  31. */
  32. int cs_id;
  33. } esp_flash_spi_device_config_t;
  34. /**
  35. * Add a SPI Flash device onto the SPI bus.
  36. *
  37. * The bus should be already initialized by ``spi_bus_initialization``.
  38. *
  39. * @param out_chip Pointer to hold the initialized chip.
  40. * @param config Configuration of the chips to initialize.
  41. *
  42. * @return
  43. * - ESP_ERR_INVALID_ARG: out_chip is NULL, or some field in the config is invalid.
  44. * - ESP_ERR_NO_MEM: failed to allocate memory for the chip structures.
  45. * - ESP_OK: success.
  46. */
  47. esp_err_t spi_bus_add_flash_device(esp_flash_t **out_chip, const esp_flash_spi_device_config_t *config);
  48. /**
  49. * Remove a SPI Flash device from the SPI bus.
  50. *
  51. * @param chip The flash device to remove.
  52. *
  53. * @return
  54. * - ESP_ERR_INVALID_ARG: The chip is invalid.
  55. * - ESP_OK: success.
  56. */
  57. esp_err_t spi_bus_remove_flash_device(esp_flash_t *chip);
  58. #ifdef __cplusplus
  59. }
  60. #endif