esp_flash_spi_init.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. /// Configurations for the SPI Flash to init
  18. typedef struct {
  19. spi_host_device_t host_id; ///< Bus to use
  20. int cs_id; ///< CS pin (signal) to use
  21. int cs_io_num; ///< GPIO pin to output the CS signal
  22. esp_flash_io_mode_t io_mode; ///< IO mode to read from the Flash
  23. esp_flash_speed_t speed; ///< Speed of the Flash clock
  24. int input_delay_ns; ///< Input delay of the data pins, in ns. Set to 0 if unknown.
  25. } esp_flash_spi_device_config_t;
  26. /**
  27. * Add a SPI Flash device onto the SPI bus.
  28. *
  29. * The bus should be already initialized by ``spi_bus_initialization``.
  30. *
  31. * @param out_chip Pointer to hold the initialized chip.
  32. * @param config Configuration of the chips to initialize.
  33. *
  34. * @return
  35. * - ESP_ERR_INVALID_ARG: out_chip is NULL, or some field in the config is invalid.
  36. * - ESP_ERR_NO_MEM: failed to allocate memory for the chip structures.
  37. * - ESP_OK: success.
  38. */
  39. esp_err_t spi_bus_add_flash_device(esp_flash_t **out_chip, const esp_flash_spi_device_config_t *config);
  40. /**
  41. * Remove a SPI Flash device from the SPI bus.
  42. *
  43. * @param chip The flash device to remove.
  44. *
  45. * @return
  46. * - ESP_ERR_INVALID_ARG: The chip is invalid.
  47. * - ESP_OK: success.
  48. */
  49. esp_err_t spi_bus_remove_flash_device(esp_flash_t *chip);