LibDriver W25QXX
Loading...
Searching...
No Matches
driver_w25qxx_basic.c
Go to the documentation of this file.
1
36
37#include "driver_w25qxx_basic.h"
38
39static w25qxx_handle_t gs_handle;
40
51uint8_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 */
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 {
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
126{
127 if (w25qxx_deinit(&gs_handle) != 0)
128 {
129 return 1;
130 }
131 else
132 {
133 return 0;
134 }
135}
136
145{
146 if (w25qxx_power_down(&gs_handle) != 0)
147 {
148 return 1;
149 }
150 else
151 {
152 return 0;
153 }
154}
155
164{
165 if (w25qxx_release_power_down(&gs_handle) != 0)
166 {
167 return 1;
168 }
169 else
170 {
171 return 0;
172 }
173}
174
183{
184 if (w25qxx_chip_erase(&gs_handle) != 0)
185 {
186 return 1;
187 }
188 else
189 {
190 return 0;
191 }
192}
193
203uint8_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
225uint8_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
247uint8_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 header file
uint8_t w25qxx_chip_erase(w25qxx_handle_t *handle)
erase the chip
uint8_t w25qxx_release_power_down(w25qxx_handle_t *handle)
release power down
uint8_t w25qxx_set_interface(w25qxx_handle_t *handle, w25qxx_interface_t interface)
set the chip interface
struct w25qxx_handle_s w25qxx_handle_t
w25qxx handle structure definition
uint8_t w25qxx_set_dual_quad_spi(w25qxx_handle_t *handle, w25qxx_bool_t enable)
enable or disable the dual quad spi
w25qxx_type_t
w25qxx type enumeration definition
uint8_t w25qxx_init(w25qxx_handle_t *handle)
initialize the chip
uint8_t w25qxx_get_manufacturer_device_id(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id)
get the manufacturer && device id information
uint8_t w25qxx_deinit(w25qxx_handle_t *handle)
close the chip
uint8_t w25qxx_set_type(w25qxx_handle_t *handle, w25qxx_type_t type)
set the chip type
uint8_t w25qxx_write(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
write data
w25qxx_interface_t
w25qxx interface enumeration definition
uint8_t w25qxx_set_address_mode(w25qxx_handle_t *handle, w25qxx_address_mode_t mode)
set the chip address mode
uint8_t w25qxx_power_down(w25qxx_handle_t *handle)
power down
uint8_t w25qxx_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read data
w25qxx_bool_t
w25qxx bool enumeration definition
@ W25Q256
@ W25QXX_ADDRESS_MODE_4_BYTE
uint8_t w25qxx_basic_wake_up(void)
basic example wake up
uint8_t w25qxx_basic_read(uint32_t addr, uint8_t *data, uint32_t len)
basic example read
uint8_t w25qxx_basic_init(w25qxx_type_t type, w25qxx_interface_t interface, w25qxx_bool_t dual_quad_spi_enable)
basic example init
uint8_t w25qxx_basic_power_down(void)
basic example power down
uint8_t w25qxx_basic_write(uint32_t addr, uint8_t *data, uint32_t len)
basic example write
uint8_t w25qxx_basic_get_id(uint8_t *manufacturer, uint8_t *device_id)
basic example get the manufacturer && device id information
uint8_t w25qxx_basic_deinit(void)
basic example deinit
uint8_t w25qxx_basic_chip_erase(void)
basic example chip erase
uint8_t w25qxx_interface_spi_qspi_deinit(void)
interface spi qspi bus deinit
uint8_t w25qxx_interface_spi_qspi_init(void)
interface spi qspi bus init
void w25qxx_interface_delay_us(uint32_t us)
interface delay us
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
void w25qxx_interface_debug_print(const char *const fmt,...)
interface print format data
void w25qxx_interface_delay_ms(uint32_t ms)
interface delay ms