esp_flash_spi_init.h 2.0 KB

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