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