LibDriver MB85RSXX
Loading...
Searching...
No Matches
driver_mb85rsxx.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_MB85RSXX_H
38#define DRIVER_MB85RSXX_H
39
40#include <stdio.h>
41#include <stdint.h>
42#include <string.h>
43
44#ifdef __cplusplus
45extern "C"{
46#endif
47
53
58
62#ifndef MB85RSXX_USE_DEVICE_ID
63 #define MB85RSXX_USE_DEVICE_ID 1
66#endif
67
71typedef enum
72{
73 MB85RS16 = 2048,
74 MB85RS64 = 8192,
75 MB85RS128 = 16384,
76 MB85RS256 = 32768,
77 MB85RS512 = 65536,
78 MB85RS1M = 131072,
79 MB85RS2M = 262144,
80 MB85RS4M = 524288,
82
86typedef enum
87{
93
97typedef struct mb85rsxx_handle_s
98{
99 uint8_t (*spi_init)(void);
100 uint8_t (*spi_deinit)(void);
101 uint8_t (*spi_read_write)(uint8_t *in_buf, uint32_t in_len,
102 uint8_t *out_buf, uint32_t out_len);
103 void (*delay_ms)(uint32_t ms);
104 void (*debug_print)(const char *const fmt, ...);
105 uint32_t id;
106 uint8_t inited;
107 uint8_t buf[512 + 4];
109
125
129
136
143#define DRIVER_MB85RSXX_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
144
151#define DRIVER_MB85RSXX_LINK_SPI_INIT(HANDLE, FUC) (HANDLE)->spi_init = FUC
152
159#define DRIVER_MB85RSXX_LINK_SPI_DEINIT(HANDLE, FUC) (HANDLE)->spi_deinit = FUC
160
167#define DRIVER_MB85RSXX_LINK_SPI_READ_WRITE(HANDLE, FUC) (HANDLE)->spi_read_write = FUC
168
175#define DRIVER_MB85RSXX_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
176
183#define DRIVER_MB85RSXX_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
184
188
195
204uint8_t mb85rsxx_info(mb85rsxx_info_t *info);
205
217uint8_t mb85rsxx_init(mb85rsxx_handle_t *handle);
218
229uint8_t mb85rsxx_deinit(mb85rsxx_handle_t *handle);
230
240uint8_t mb85rsxx_set_type(mb85rsxx_handle_t *handle, mb85rsxx_t type);
241
251uint8_t mb85rsxx_get_type(mb85rsxx_handle_t *handle, mb85rsxx_t *type);
252
267uint8_t mb85rsxx_read(mb85rsxx_handle_t *handle, uint32_t address, uint8_t *buf, uint16_t len);
268
284uint8_t mb85rsxx_write(mb85rsxx_handle_t *handle, uint32_t address, uint8_t *buf, uint16_t len);
285
297
309
321uint8_t mb85rsxx_set_status(mb85rsxx_handle_t *handle, uint8_t status);
322
334uint8_t mb85rsxx_get_status(mb85rsxx_handle_t *handle, uint8_t *status);
335
350uint8_t mb85rsxx_get_device_id(mb85rsxx_handle_t *handle, uint8_t *manufacturer_id, uint8_t *continuation_code,
351 uint8_t *product_id1, uint8_t *product_id2);
352
356
360
361#ifdef __cplusplus
362}
363#endif
364
365#endif
uint8_t mb85rsxx_info(mb85rsxx_info_t *info)
get chip's information
uint8_t mb85rsxx_enable_write(mb85rsxx_handle_t *handle)
enable write
uint8_t mb85rsxx_get_device_id(mb85rsxx_handle_t *handle, uint8_t *manufacturer_id, uint8_t *continuation_code, uint8_t *product_id1, uint8_t *product_id2)
get device id
uint8_t mb85rsxx_get_type(mb85rsxx_handle_t *handle, mb85rsxx_t *type)
get the chip type
uint8_t mb85rsxx_write(mb85rsxx_handle_t *handle, uint32_t address, uint8_t *buf, uint16_t len)
write bytes to the chip
uint8_t mb85rsxx_read(mb85rsxx_handle_t *handle, uint32_t address, uint8_t *buf, uint16_t len)
read bytes from the chip
struct mb85rsxx_info_s mb85rsxx_info_t
mb85rsxx information structure definition
uint8_t mb85rsxx_set_status(mb85rsxx_handle_t *handle, uint8_t status)
set status
uint8_t mb85rsxx_set_type(mb85rsxx_handle_t *handle, mb85rsxx_t type)
set the chip type
struct mb85rsxx_handle_s mb85rsxx_handle_t
mb85rsxx handle structure definition
uint8_t mb85rsxx_deinit(mb85rsxx_handle_t *handle)
close the chip
mb85rsxx_t
mb85rsxx type enumeration definition
uint8_t mb85rsxx_get_status(mb85rsxx_handle_t *handle, uint8_t *status)
get status
mb85rsxx_status_t
mb85rsxx status enumeration definition
uint8_t mb85rsxx_disable_write(mb85rsxx_handle_t *handle)
disable write
uint8_t mb85rsxx_init(mb85rsxx_handle_t *handle)
initialize the chip
@ MB85RS256
@ MB85RS64
@ MB85RS1M
@ MB85RS512
@ MB85RS128
@ MB85RS2M
@ MB85RS16
@ MB85RS4M
@ MB85RSXX_STATUS_BP0
@ MB85RSXX_STATUS_WEL
@ MB85RSXX_STATUS_WPEN
@ MB85RSXX_STATUS_BP1
mb85rsxx handle structure definition
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t buf[512+4]
void(* debug_print)(const char *const fmt,...)
uint8_t(* spi_deinit)(void)
uint8_t(* spi_read_write)(uint8_t *in_buf, uint32_t in_len, uint8_t *out_buf, uint32_t out_len)
mb85rsxx information structure definition
char manufacturer_name[32]