esp_flash_spi_init.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "hal/spi_types.h"
  8. #include "esp_flash.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /// Configurations for the SPI Flash to init
  13. typedef struct {
  14. spi_host_device_t host_id; ///< Bus to use
  15. int cs_io_num; ///< GPIO pin to output the CS signal
  16. esp_flash_io_mode_t io_mode; ///< IO mode to read from the Flash
  17. enum esp_flash_speed_s speed __attribute__((deprecated)); ///< Speed of the Flash clock. Replaced by freq_mhz
  18. int input_delay_ns; ///< Input delay of the data pins, in ns. Set to 0 if unknown.
  19. /**
  20. * CS line ID, ignored when not `host_id` is not SPI1_HOST, or
  21. * `CONFIG_SPI_FLASH_SHARE_SPI1_BUS` is enabled. In this case, the CS line used is
  22. * automatically assigned by the SPI bus lock.
  23. */
  24. int cs_id;
  25. int freq_mhz; ///< The frequency of flash chip(MHZ)
  26. } esp_flash_spi_device_config_t;
  27. /**
  28. * Add a SPI Flash device onto the SPI bus.
  29. *
  30. * The bus should be already initialized by ``spi_bus_initialization``.
  31. *
  32. * @param out_chip Pointer to hold the initialized chip.
  33. * @param config Configuration of the chips to initialize.
  34. *
  35. * @return
  36. * - ESP_ERR_INVALID_ARG: out_chip is NULL, or some field in the config is invalid.
  37. * - ESP_ERR_NO_MEM: failed to allocate memory for the chip structures.
  38. * - ESP_OK: success.
  39. */
  40. esp_err_t spi_bus_add_flash_device(esp_flash_t **out_chip, const esp_flash_spi_device_config_t *config);
  41. /**
  42. * Remove a SPI Flash device from the SPI bus.
  43. *
  44. * @param chip The flash device to remove.
  45. *
  46. * @return
  47. * - ESP_ERR_INVALID_ARG: The chip is invalid.
  48. * - ESP_OK: success.
  49. */
  50. esp_err_t spi_bus_remove_flash_device(esp_flash_t *chip);
  51. #ifdef __cplusplus
  52. }
  53. #endif