| LibDriver W25QXX 1.0.0 W25QXX full function driver

driver_w25qxx_basic.c
Go to the documentation of this file.
1
37 #include "driver_w25qxx_basic.h"
38
39 static w25qxx_handle_t gs_handle;
51 uint8_t w25qxx_basic_init(w25qxx_type_t type, w25qxx_interface_t interface, w25qxx_bool_t dual_quad_spi_enable)
52 {
53 uint8_t res;
54
55 /* link interface function */
56 DRIVER_W25QXX_LINK_INIT(&gs_handle, w25qxx_handle_t);
57 DRIVER_W25QXX_LINK_SPI_QSPI_INIT(&gs_handle, w25qxx_interface_spi_qspi_init);
58 DRIVER_W25QXX_LINK_SPI_QSPI_DEINIT(&gs_handle, w25qxx_interface_spi_qspi_deinit);
59 DRIVER_W25QXX_LINK_SPI_QSPI_WRITE_READ(&gs_handle, w25qxx_interface_spi_qspi_write_read);
60 DRIVER_W25QXX_LINK_DELAY_MS(&gs_handle, w25qxx_interface_delay_ms);
61 DRIVER_W25QXX_LINK_DELAY_US(&gs_handle, w25qxx_interface_delay_us);
62 DRIVER_W25QXX_LINK_DEBUG_PRINT(&gs_handle, w25qxx_interface_debug_print);
63
64 /* set chip type */
65 res = w25qxx_set_type(&gs_handle, type);
66 if (res != 0)
67 {
68 w25qxx_interface_debug_print("w25qxx: set type failed.\n");
69
70 return 1;
71 }
72
73 /* set chip interface */
74 res = w25qxx_set_interface(&gs_handle, interface);
75 if (res != 0)
76 {
77 w25qxx_interface_debug_print("w25qxx: set interface failed.\n");
78
79 return 1;
80 }
81
82 /* set dual quad spi */
83 res = w25qxx_set_dual_quad_spi(&gs_handle, dual_quad_spi_enable);
84 if (res != 0)
85 {
86 w25qxx_interface_debug_print("w25qxx: set dual quad spi failed.\n");
87 (void)w25qxx_deinit(&gs_handle);
88
89 return 1;
90 }
91
92 /* chip init */
93 res = w25qxx_init(&gs_handle);
94 if (res != 0)
95 {
96 w25qxx_interface_debug_print("w25qxx: init failed.\n");
97
98 return 1;
99 }
100 else
101 {
102 if (type >= W25Q256)
103 {
104 res = w25qxx_set_address_mode(&gs_handle, W25QXX_ADDRESS_MODE_4_BYTE);
105 if (res != 0)
106 {
107 w25qxx_interface_debug_print("w25qxx: set address mode failed.\n");
108 (void)w25qxx_deinit(&gs_handle);
109
110 return 1;
111 }
112 }
113
114 return 0;
115 }
116 }
117
125 uint8_t w25qxx_basic_deinit(void)
126 {
127 if (w25qxx_deinit(&gs_handle) != 0)
128 {
129 return 1;
130 }
131 else
132 {
133 return 0;
134 }
135 }
136
144 uint8_t w25qxx_basic_power_down(void)
145 {
146 if (w25qxx_power_down(&gs_handle) != 0)
147 {
148 return 1;
149 }
150 else
151 {
152 return 0;
153 }
154 }
155
163 uint8_t w25qxx_basic_wake_up(void)
164 {
165 if (w25qxx_release_power_down(&gs_handle) != 0)
166 {
167 return 1;
168 }
169 else
170 {
171 return 0;
172 }
173 }
174
182 uint8_t w25qxx_basic_chip_erase(void)
183 {
184 if (w25qxx_chip_erase(&gs_handle) != 0)
185 {
186 return 1;
187 }
188 else
189 {
190 return 0;
191 }
192 }
193
203 uint8_t w25qxx_basic_get_id(uint8_t *manufacturer, uint8_t *device_id)
204 {
205 if (w25qxx_get_manufacturer_device_id(&gs_handle, manufacturer, device_id) != 0)
206 {
207 return 1;
208 }
209 else
210 {
211 return 0;
212 }
213 }
214
225 uint8_t w25qxx_basic_write(uint32_t addr, uint8_t *data, uint32_t len)
226 {
227 if (w25qxx_write(&gs_handle, addr, data, len) != 0)
228 {
229 return 1;
230 }
231 else
232 {
233 return 0;
234 }
235 }
236
247 uint8_t w25qxx_basic_read(uint32_t addr, uint8_t *data, uint32_t len)
248 {
249 if (w25qxx_read(&gs_handle, addr, data, len) != 0)
250 {
251 return 1;
252 }
253 else
254 {
255 return 0;
256 }
257 }
driver_w25qxx_basic.h
driver w25qxx basic header file
w25qxx_chip_erase
uint8_t w25qxx_chip_erase(w25qxx_handle_t *handle)
erase the chip
Definition: driver_w25qxx.c:1459
w25qxx_release_power_down
uint8_t w25qxx_release_power_down(w25qxx_handle_t *handle)
release power down
Definition: driver_w25qxx.c:1875
w25qxx_set_interface
uint8_t w25qxx_set_interface(w25qxx_handle_t *handle, w25qxx_interface_t interface)
set the chip interface
Definition: driver_w25qxx.c:259
w25qxx_set_dual_quad_spi
uint8_t w25qxx_set_dual_quad_spi(w25qxx_handle_t *handle, w25qxx_bool_t enable)
enable or disable the dual quad spi
Definition: driver_w25qxx.c:175
w25qxx_type_t
w25qxx_type_t
w25qxx type enumeration definition
Definition: driver_w25qxx.h:63
w25qxx_init
uint8_t w25qxx_init(w25qxx_handle_t *handle)
initialize the chip
Definition: driver_w25qxx.c:6819
w25qxx_get_manufacturer_device_id
uint8_t w25qxx_get_manufacturer_device_id(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id)
get the manufacturer && device id information
Definition: driver_w25qxx.c:1952
w25qxx_deinit
uint8_t w25qxx_deinit(w25qxx_handle_t *handle)
close the chip
Definition: driver_w25qxx.c:7195
w25qxx_set_type
uint8_t w25qxx_set_type(w25qxx_handle_t *handle, w25qxx_type_t type)
set the chip type
Definition: driver_w25qxx.c:217
w25qxx_write
uint8_t w25qxx_write(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
write data
Definition: driver_w25qxx.c:8415
w25qxx_interface_t
w25qxx_interface_t
w25qxx interface enumeration definition
Definition: driver_w25qxx.h:76
w25qxx_set_address_mode
uint8_t w25qxx_set_address_mode(w25qxx_handle_t *handle, w25qxx_address_mode_t mode)
set the chip address mode
Definition: driver_w25qxx.c:304
w25qxx_power_down
uint8_t w25qxx_power_down(w25qxx_handle_t *handle)
power down
Definition: driver_w25qxx.c:1792
w25qxx_read
uint8_t w25qxx_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read data
Definition: driver_w25qxx.c:7289
w25qxx_bool_t
w25qxx_bool_t
w25qxx bool enumeration definition
Definition: driver_w25qxx.h:85
W25Q256
@ W25Q256
Definition: driver_w25qxx.h:69
W25QXX_ADDRESS_MODE_4_BYTE
@ W25QXX_ADDRESS_MODE_4_BYTE
Definition: driver_w25qxx.h:96
w25qxx_basic_wake_up
uint8_t w25qxx_basic_wake_up(void)
basic example wake up
Definition: driver_w25qxx_basic.c:163
w25qxx_basic_read
uint8_t w25qxx_basic_read(uint32_t addr, uint8_t *data, uint32_t len)
basic example read
Definition: driver_w25qxx_basic.c:247
w25qxx_basic_init
uint8_t w25qxx_basic_init(w25qxx_type_t type, w25qxx_interface_t interface, w25qxx_bool_t dual_quad_spi_enable)
basic example init
Definition: driver_w25qxx_basic.c:51
w25qxx_basic_power_down
uint8_t w25qxx_basic_power_down(void)
basic example power down
Definition: driver_w25qxx_basic.c:144
w25qxx_basic_write
uint8_t w25qxx_basic_write(uint32_t addr, uint8_t *data, uint32_t len)
basic example write
Definition: driver_w25qxx_basic.c:225
w25qxx_basic_get_id
uint8_t w25qxx_basic_get_id(uint8_t *manufacturer, uint8_t *device_id)
basic example get the manufacturer && device id information
Definition: driver_w25qxx_basic.c:203
w25qxx_basic_deinit
uint8_t w25qxx_basic_deinit(void)
basic example deinit
Definition: driver_w25qxx_basic.c:125
w25qxx_basic_chip_erase
uint8_t w25qxx_basic_chip_erase(void)
basic example chip erase
Definition: driver_w25qxx_basic.c:182
w25qxx_interface_spi_qspi_deinit
uint8_t w25qxx_interface_spi_qspi_deinit(void)
interface spi qspi bus deinit
Definition: driver_w25qxx_interface_template.c:58
w25qxx_interface_spi_qspi_init
uint8_t w25qxx_interface_spi_qspi_init(void)
interface spi qspi bus init
Definition: driver_w25qxx_interface_template.c:46
w25qxx_interface_delay_us
void w25qxx_interface_delay_us(uint32_t us)
interface delay us
Definition: driver_w25qxx_interface_template.c:108
w25qxx_interface_spi_qspi_write_read
uint8_t w25qxx_interface_spi_qspi_write_read(uint8_t instruction, uint8_t instruction_line, uint32_t address, uint8_t address_line, uint8_t address_len, uint32_t alternate, uint8_t alternate_line, uint8_t alternate_len, uint8_t dummy, uint8_t *in_buf, uint32_t in_len, uint8_t *out_buf, uint32_t out_len, uint8_t data_line)
interface spi qspi bus write read
Definition: driver_w25qxx_interface_template.c:84
w25qxx_interface_debug_print
void w25qxx_interface_debug_print(const char *const fmt,...)
interface print format data
Definition: driver_w25qxx_interface_template.c:118
w25qxx_interface_delay_ms
void w25qxx_interface_delay_ms(uint32_t ms)
interface delay ms
Definition: driver_w25qxx_interface_template.c:98
DRIVER_W25QXX_LINK_DELAY_MS
#define DRIVER_W25QXX_LINK_DELAY_MS(HANDLE, FUC)
link delay_ms function
Definition: driver_w25qxx.h:297
DRIVER_W25QXX_LINK_INIT
#define DRIVER_W25QXX_LINK_INIT(HANDLE, STRUCTURE)
initialize w25qxx_handle_t structure
Definition: driver_w25qxx.h:265
DRIVER_W25QXX_LINK_SPI_QSPI_INIT
#define DRIVER_W25QXX_LINK_SPI_QSPI_INIT(HANDLE, FUC)
link spi_qspi_init function
Definition: driver_w25qxx.h:273
DRIVER_W25QXX_LINK_DEBUG_PRINT
#define DRIVER_W25QXX_LINK_DEBUG_PRINT(HANDLE, FUC)
link debug_print function
Definition: driver_w25qxx.h:313
DRIVER_W25QXX_LINK_SPI_QSPI_WRITE_READ
#define DRIVER_W25QXX_LINK_SPI_QSPI_WRITE_READ(HANDLE, FUC)
link spi_qspi_write_read function
Definition: driver_w25qxx.h:289
DRIVER_W25QXX_LINK_SPI_QSPI_DEINIT
#define DRIVER_W25QXX_LINK_SPI_QSPI_DEINIT(HANDLE, FUC)
link spi_qspi_deinit function
Definition: driver_w25qxx.h:281
DRIVER_W25QXX_LINK_DELAY_US
#define DRIVER_W25QXX_LINK_DELAY_US(HANDLE, FUC)
link delay_us function
Definition: driver_w25qxx.h:305
w25qxx_handle_s
w25qxx handle structure definition
Definition: driver_w25qxx.h:210