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