eeprom5 2.0.0.0
eeprom5.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef EEPROM5_H
29#define EEPROM5_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52
73#define EEPROM5_CMD_WREN 0x06
74#define EEPROM5_CMD_WRDI 0x04
75#define EEPROM5_CMD_RDSR 0x05
76#define EEPROM5_CMD_WRSR 0x01
77#define EEPROM5_CMD_READ 0x03
78#define EEPROM5_CMD_WRITE 0x02
79#define EEPROM5_CMD_READ_ID 0x83
80#define EEPROM5_CMD_WRITE_ID 0x82
81#define EEPROM5_CMD_READ_LOCK_STATUS 0x83
82#define EEPROM5_CMD_LOCK_ID 0x82
83
88#define EEPROM5_WRITE_MEMORY_DISABLE 0x00
89#define EEPROM5_WRITE_MEMORY_ENABLE 0x01
90
95#define EEPROM5_IDENT_PAGE_ADDR_START 0x0000
96#define EEPROM5_IDENT_PAGE_ADDR_END 0x01FF
97
102#define EEPROM5_SIGNIFICANT_ADDR_BIT_0 0xFB
103#define EEPROM5_SIGNIFICANT_ADDR_BIT_1 0x04
104
109#define EEPROM5_MEMORY_ADDR_START 0x00000000ul
110#define EEPROM5_MEMORY_ADDR_END 0x0007FFFFul
111
116#define EEPROM5_HOLD_DISABLE 0x00
117#define EEPROM5_HOLD_ENABLE 0x01
118
123#define EEPROM5_WRITE_PROTECT_DISABLE 0x00
124#define EEPROM5_WRITE_PROTECT_ENABLE 0x01
125
130#define EEPROM5_DUMMY 0xFF
131
132 // eeprom5_set
133
148#define EEPROM5_MAP_MIKROBUS( cfg, mikrobus ) \
149 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
150 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
151 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
152 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
153 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_RST ); \
154 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
155
156 // eeprom5_map
157 // eeprom5
158
163typedef struct
164{
165 // Output pins
166 digital_out_t hld;
167 digital_out_t wp;
169 // Modules
170 spi_master_t spi;
172 pin_name_t chip_select;
174} eeprom5_t;
175
180typedef struct
181{
182 // Communication gpio pins
183 pin_name_t miso;
184 pin_name_t mosi;
185 pin_name_t sck;
186 pin_name_t cs;
188 // Additional gpio pins
189 pin_name_t hld;
190 pin_name_t wp;
192 // static variable
193 uint32_t spi_speed;
194 spi_master_mode_t spi_mode;
195 spi_master_chip_select_polarity_t cs_polarity;
198
203typedef struct
204{
209
211
216typedef enum
217{
219 EEPROM5_ERROR = -1
220
222
239
254
270void eeprom5_generic_write ( eeprom5_t *ctx, uint32_t addr, uint8_t tx_data );
271
287uint8_t eeprom5_generic_read ( eeprom5_t *ctx, uint32_t addr );
288
300void eeprom5_set_hold ( eeprom5_t *ctx, uint8_t en_hold );
301
313void eeprom5_set_write_protect ( eeprom5_t *ctx, uint8_t en_wr_prot );
314
326void eeprom5_send_cmd ( eeprom5_t *ctx, uint8_t cmd );
327
339void eeprom5_enable_memory_write ( eeprom5_t *ctx, uint8_t en_wr_mem );
340
353
366
381void eeprom5_read_memory ( eeprom5_t *ctx, uint32_t addr, uint8_t *p_rx_data, uint8_t n_bytes );
382
397void eeprom5_write_memory ( eeprom5_t *ctx, uint32_t addr, uint8_t *p_tx_data, uint8_t n_bytes );
398
411uint8_t eeprom5_read_ident_page ( eeprom5_t *ctx, uint16_t addr );
412
425void eeprom5_write_ident_page ( eeprom5_t *ctx, uint16_t addr, uint8_t ident_data );
426
438
451void eeprom5_lock_id ( eeprom5_t *ctx, uint8_t lock_id );
452
453#ifdef __cplusplus
454}
455#endif
456#endif // EEPROM5_H
457
458 // eeprom5
459
460// ------------------------------------------------------------------------ END
eeprom5_return_value_t
EEPROM 5 Click return value data.
Definition eeprom5.h:217
@ EEPROM5_OK
Definition eeprom5.h:218
@ EEPROM5_ERROR
Definition eeprom5.h:219
void eeprom5_write_memory(eeprom5_t *ctx, uint32_t addr, uint8_t *p_tx_data, uint8_t n_bytes)
Write EEPROM memory function.
void eeprom5_write_ident_page(eeprom5_t *ctx, uint16_t addr, uint8_t ident_data)
Write dentification page function.
uint8_t eeprom5_read_ident_page(eeprom5_t *ctx, uint16_t addr)
Read identification page function.
void eeprom5_get_status(eeprom5_t *ctx, status_data_t *stat_data)
Get status function.
void eeprom5_enable_memory_write(eeprom5_t *ctx, uint8_t en_wr_mem)
Enable memory write function.
void eeprom5_lock_id(eeprom5_t *ctx, uint8_t lock_id)
Lock ID function.
uint8_t eeprom5_read_lock_status(eeprom5_t *ctx)
Reads the identification page lock status function.
void eeprom5_send_cmd(eeprom5_t *ctx, uint8_t cmd)
Send command function.
void eeprom5_read_memory(eeprom5_t *ctx, uint32_t addr, uint8_t *p_rx_data, uint8_t n_bytes)
Read EEPROM memory function.
void eeprom5_set_write_protect(eeprom5_t *ctx, uint8_t en_wr_prot)
Enable write protect function.
void eeprom5_set_hold(eeprom5_t *ctx, uint8_t en_hold)
Enable hold operation function.
void eeprom5_set_status(eeprom5_t *ctx, status_data_t stat_data)
Set status function.
err_t eeprom5_init(eeprom5_t *ctx, eeprom5_cfg_t *cfg)
EEPROM 5 initialization function.
void eeprom5_cfg_setup(eeprom5_cfg_t *cfg)
EEPROM 5 configuration object setup function.
uint8_t eeprom5_generic_read(eeprom5_t *ctx, uint32_t addr)
EEPROM 5 data reading function.
void eeprom5_generic_write(eeprom5_t *ctx, uint32_t addr, uint8_t tx_data)
EEPROM 5 data writing function.
EEPROM 5 Click configuration object.
Definition eeprom5.h:181
pin_name_t hld
Definition eeprom5.h:189
spi_master_chip_select_polarity_t cs_polarity
Definition eeprom5.h:195
pin_name_t sck
Definition eeprom5.h:185
spi_master_mode_t spi_mode
Definition eeprom5.h:194
pin_name_t mosi
Definition eeprom5.h:184
uint32_t spi_speed
Definition eeprom5.h:193
pin_name_t wp
Definition eeprom5.h:190
pin_name_t miso
Definition eeprom5.h:183
pin_name_t cs
Definition eeprom5.h:186
EEPROM 5 Click context object.
Definition eeprom5.h:164
digital_out_t hld
Definition eeprom5.h:166
spi_master_t spi
Definition eeprom5.h:170
pin_name_t chip_select
Definition eeprom5.h:172
digital_out_t wp
Definition eeprom5.h:167
EEPROM 5 Click status data object.
Definition eeprom5.h:204
uint8_t block_protect
Definition eeprom5.h:207
uint8_t write_protect
Definition eeprom5.h:208
uint8_t write_in_progress
Definition eeprom5.h:205
uint8_t write_enable_latch
Definition eeprom5.h:206