37
37
* implementations that also use the SPI peripheral.
38
38
*/
39
39
typedef struct {
40
+ spi_flash_host_inst_t inst ; ///< Host instance, containing host data and function pointer table. May update with the host (hardware version).
40
41
spi_dev_t * spi ; ///< Pointer to SPI peripheral registers (SP1, SPI2 or SPI3). Set before initialisation.
41
42
int cs_num ; ///< Which cs pin is used, 0-2.
42
- int extra_dummy ;
43
- spi_flash_ll_clock_reg_t clock_conf ;
44
- } spi_flash_memspi_data_t ;
43
+ int extra_dummy ; ///< Pre-calculated extra dummy used for compensation
44
+ spi_flash_ll_clock_reg_t clock_conf ; ///< Pre-calculated clock configuration value
45
+ uint32_t reserved_config [2 ]; ///< The ROM has reserved some memory for configurations with one set of driver code. (e.g. QPI mode, 64-bit address mode, etc.)
46
+ } spi_flash_hal_context_t ;
45
47
46
48
/// Configuration structure for the SPI driver.
47
49
typedef struct {
@@ -50,7 +52,7 @@ typedef struct {
50
52
bool iomux ; ///< Whether the IOMUX is used, used for timing compensation.
51
53
int input_delay_ns ; ///< Input delay on the MISO pin after the launch clock, used for timing compensation.
52
54
esp_flash_speed_t speed ;///< SPI flash clock speed to work at.
53
- } spi_flash_memspi_config_t ;
55
+ } spi_flash_hal_config_t ;
54
56
55
57
/**
56
58
* Configure SPI flash hal settings.
@@ -62,16 +64,16 @@ typedef struct {
62
64
* - ESP_OK: success
63
65
* - ESP_ERR_INVALID_ARG: the data buffer is not in the DRAM.
64
66
*/
65
- esp_err_t spi_flash_hal_init (spi_flash_memspi_data_t * data_out , const spi_flash_memspi_config_t * cfg );
67
+ esp_err_t spi_flash_hal_init (spi_flash_hal_context_t * data_out , const spi_flash_hal_config_t * cfg );
66
68
67
69
/**
68
70
* Configure the device-related register before transactions.
69
71
*
70
- * @param driver The driver context.
72
+ * @param host The driver context.
71
73
*
72
74
* @return always return ESP_OK.
73
75
*/
74
- esp_err_t spi_flash_hal_device_config (spi_flash_host_driver_t * driver );
76
+ esp_err_t spi_flash_hal_device_config (spi_flash_host_inst_t * host );
75
77
76
78
/**
77
79
* Send an user-defined spi transaction to the device.
@@ -80,60 +82,60 @@ esp_err_t spi_flash_hal_device_config(spi_flash_host_driver_t *driver);
80
82
* particular commands. Since this function supports timing compensation, it is
81
83
* also used to receive some data when the frequency is high.
82
84
*
83
- * @param driver The driver context.
85
+ * @param host The driver context.
84
86
* @param trans The transaction to send, also holds the received data.
85
87
*
86
88
* @return always return ESP_OK.
87
89
*/
88
- esp_err_t spi_flash_hal_common_command (spi_flash_host_driver_t * driver , spi_flash_trans_t * trans );
90
+ esp_err_t spi_flash_hal_common_command (spi_flash_host_inst_t * host , spi_flash_trans_t * trans );
89
91
90
92
/**
91
93
* Erase whole flash chip by using the erase chip (C7h) command.
92
94
*
93
- * @param driver The driver context.
95
+ * @param host The driver context.
94
96
*/
95
- void spi_flash_hal_erase_chip (spi_flash_host_driver_t * driver );
97
+ void spi_flash_hal_erase_chip (spi_flash_host_inst_t * host );
96
98
97
99
/**
98
100
* Erase a specific sector by its start address through the sector erase (20h)
99
101
* command.
100
102
*
101
- * @param driver The driver context.
103
+ * @param host The driver context.
102
104
* @param start_address Start address of the sector to erase.
103
105
*/
104
- void spi_flash_hal_erase_sector (spi_flash_host_driver_t * driver , uint32_t start_address );
106
+ void spi_flash_hal_erase_sector (spi_flash_host_inst_t * host , uint32_t start_address );
105
107
106
108
/**
107
109
* Erase a specific 64KB block by its start address through the 64KB block
108
110
* erase (D8h) command.
109
111
*
110
- * @param driver The driver context.
112
+ * @param host The driver context.
111
113
* @param start_address Start address of the block to erase.
112
114
*/
113
- void spi_flash_hal_erase_block (spi_flash_host_driver_t * driver , uint32_t start_address );
115
+ void spi_flash_hal_erase_block (spi_flash_host_inst_t * host , uint32_t start_address );
114
116
115
117
/**
116
118
* Program a page of the flash using the page program (02h) command.
117
119
*
118
- * @param driver The driver context.
120
+ * @param host The driver context.
119
121
* @param address Address of the page to program
120
122
* @param buffer Data to program
121
123
* @param length Size of the buffer in bytes, no larger than ``SPI_FLASH_HAL_MAX_WRITE_BYTES`` (64) bytes.
122
124
*/
123
- void spi_flash_hal_program_page (spi_flash_host_driver_t * driver , const void * buffer , uint32_t address , uint32_t length );
125
+ void spi_flash_hal_program_page (spi_flash_host_inst_t * host , const void * buffer , uint32_t address , uint32_t length );
124
126
125
127
/**
126
128
* Read from the flash. Call ``spi_flash_hal_configure_host_read_mode`` to
127
129
* configure the read command before calling this function.
128
130
*
129
- * @param driver The driver context.
131
+ * @param host The driver context.
130
132
* @param buffer Buffer to store the read data
131
133
* @param address Address to read
132
134
* @param length Length to read, no larger than ``SPI_FLASH_HAL_MAX_READ_BYTES`` (64) bytes.
133
135
*
134
136
* @return always return ESP_OK.
135
137
*/
136
- esp_err_t spi_flash_hal_read (spi_flash_host_driver_t * driver , void * buffer , uint32_t address , uint32_t read_len );
138
+ esp_err_t spi_flash_hal_read (spi_flash_host_inst_t * host , void * buffer , uint32_t address , uint32_t read_len );
137
139
138
140
/**
139
141
* @brief Send the write enable (06h) or write disable (04h) command to the flash chip.
@@ -143,16 +145,16 @@ esp_err_t spi_flash_hal_read(spi_flash_host_driver_t *driver, void *buffer, uint
143
145
*
144
146
* @return always return ESP_OK.
145
147
*/
146
- esp_err_t spi_flash_hal_set_write_protect (spi_flash_host_driver_t * chip_drv , bool wp );
148
+ esp_err_t spi_flash_hal_set_write_protect (spi_flash_host_inst_t * host , bool wp );
147
149
148
150
/**
149
151
* Check whether the SPI host is idle and can perform other operations.
150
152
*
151
- * @param driver The driver context.
153
+ * @param host The driver context.
152
154
*
153
155
* @return ture if idle, otherwise false.
154
156
*/
155
- bool spi_flash_hal_host_idle (spi_flash_host_driver_t * driver );
157
+ bool spi_flash_hal_host_idle (spi_flash_host_inst_t * host );
156
158
157
159
/**
158
160
* @brief Configure the SPI host hardware registers for the specified io mode.
@@ -177,42 +179,42 @@ bool spi_flash_hal_host_idle(spi_flash_host_driver_t *driver);
177
179
* - Common write: set command value, address value (or length to 0 if not
178
180
* used), disable dummy phase, and set output data.
179
181
*
180
- * @param driver The driver context
182
+ * @param host The driver context
181
183
* @param io_mode The HW read mode to use
182
184
* @param addr_bitlen Length of the address phase, in bits
183
185
* @param dummy_cyclelen_base Base cycles of the dummy phase, some extra dummy cycles may be appended to compensate the timing.
184
186
* @param command Actual reading command to send to flash chip on the bus.
185
187
*
186
188
* @return always return ESP_OK.
187
189
*/
188
- esp_err_t spi_flash_hal_configure_host_io_mode (spi_flash_host_driver_t * driver , uint32_t command , uint32_t addr_bitlen ,
190
+ esp_err_t spi_flash_hal_configure_host_io_mode (spi_flash_host_inst_t * host , uint32_t command , uint32_t addr_bitlen ,
189
191
int dummy_cyclelen_base , esp_flash_io_mode_t io_mode );
190
192
191
193
/**
192
194
* Poll until the last operation is done.
193
195
*
194
- * @param driver The driver context.
196
+ * @param host The driver context.
195
197
*/
196
- void spi_flash_hal_poll_cmd_done (spi_flash_host_driver_t * driver );
198
+ void spi_flash_hal_poll_cmd_done (spi_flash_host_inst_t * host );
197
199
198
200
/**
199
201
* Check whether the given buffer can be used as the write buffer directly. If 'chip' is connected to the main SPI bus, we can only write directly from
200
202
* regions that are accessible ith cache disabled. *
201
203
*
202
- * @param driver The driver context
204
+ * @param host The driver context
203
205
* @param p The buffer holding data to send.
204
206
*
205
207
* @return True if the buffer can be used to send data, otherwise false.
206
208
*/
207
- bool spi_flash_hal_supports_direct_write (spi_flash_host_driver_t * driver , const void * p );
209
+ bool spi_flash_hal_supports_direct_write (spi_flash_host_inst_t * host , const void * p );
208
210
209
211
/**
210
212
* Check whether the given buffer can be used as the read buffer directly. If 'chip' is connected to the main SPI bus, we can only read directly from
211
213
* regions that are accessible ith cache disabled. *
212
214
*
213
- * @param driver The driver context
215
+ * @param host The driver context
214
216
* @param p The buffer to hold the received data.
215
217
*
216
218
* @return True if the buffer can be used to receive data, otherwise false.
217
219
*/
218
- bool spi_flash_hal_supports_direct_read (spi_flash_host_driver_t * driver , const void * p );
220
+ bool spi_flash_hal_supports_direct_read (spi_flash_host_inst_t * host , const void * p );
0 commit comments