eeprom13 2.1.0.0
eeprom13.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 EEPROM13_H
29#define EEPROM13_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_i2c_master.h"
52
73#define EEPROM13_REG_DEV_TYPE_IDENTIFIER 0xE000u
74#define EEPROM13_REG_CFG_DEVICE_ADDRESS 0xC000u
75#define EEPROM13_REG_SW_WRITE_PROTECTION 0xA000u
76#define EEPROM13_REG_IDENTIFICATION_PAGE 0x0000u
77#define EEPROM13_REG_IDENTIFICATION_PAGE_LOCK 0x6000u
78
79
80 // eeprom13_reg
81
96#define EEPROM13_MEMORY_ADDRESS_MIN 0x00000000ul
97#define EEPROM13_MEMORY_ADDRESS_MAX 0x0001FFFFul
98#define EEPROM13_MEMORY_ADDRESS_16_BIT_MASK 0x00010000ul
99#define EEPROM13_MEMORY_ADDRESS_16_BIT 0x01
100#define EEPROM13_PAGE_SIZE 256
101#define EEPROM13_PAGE_MAX 512
102
107#define EEPROM13_CDA_DAL_BIT_MASK 0x01
108#define EEPROM13_CDA_CEA_BIT_MASK 0x03
109
114#define EEPROM13_SWP_WPL_MODIFIED 0x00
115#define EEPROM13_SWP_WPL_FROZEN 0x01
116#define EEPROM13_SWP_WPL_BIT_MASK 0x01
117#define EEPROM13_SWP_BP_UPPER_QUARTE 0x00
118#define EEPROM13_SWP_BP_UPPER_HALF 0x01
119#define EEPROM13_SWP_BP_UPPER_THREE_QUARTE 0x02
120#define EEPROM13_SWP_BP_WHOLE_MEM 0x03
121#define EEPROM13_SWP_BP_BIT_MASK 0x06
122#define EEPROM13_SWP_WPA_WRITE_ENABLE 0x00
123#define EEPROM13_SWP_WPA_BLOCK_WRITE 0x01
124#define EEPROM13_SWP_WPA_BIT_MASK 0x08
125
130#define EEPROM13_DEFAULT_CHIP_ENABLE_ADDRESS 0x00
131
137#define EEPROM13_DEVICE_ADDRESS_MEMORY 0x50
138#define EEPROM13_DEVICE_ADDRESS_PAGE 0x58
139
140 // eeprom13_set
141
156#define EEPROM13_MAP_MIKROBUS( cfg, mikrobus ) \
157 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
158 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
159 cfg.wc = MIKROBUS( mikrobus, MIKROBUS_RST )
160
161 // eeprom13_map
162 // eeprom13
163
168typedef struct
169{
170 // Output pins
171 digital_out_t wc;
173 // Modules
174 i2c_master_t i2c;
176 // I2C slave address
178 uint8_t chip_en_addr; /* Chip enable address */
179
180} eeprom13_t;
181
186typedef struct
187{
188 pin_name_t scl;
189 pin_name_t sda;
191 pin_name_t wc;
193 uint32_t i2c_speed;
194 uint8_t i2c_address;
197
202typedef enum
203{
205 EEPROM13_ERROR = -1
206
208
225
240
252
264
279err_t eeprom13_generic_write ( eeprom13_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len );
280
295err_t eeprom13_generic_read ( eeprom13_t *ctx, uint16_t reg, uint8_t *data_out, uint8_t len );
296
313err_t eeprom13_memory_write ( eeprom13_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint8_t len );
314
331err_t eeprom13_memory_read ( eeprom13_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint8_t len );
332
349err_t eeprom13_memory_page_write ( eeprom13_t *ctx, uint16_t page_addr, uint8_t *data_in, uint8_t len );
350
367err_t eeprom13_memory_page_read ( eeprom13_t *ctx, uint16_t page_addr, uint8_t *data_out, uint8_t len );
368
384err_t eeprom13_id_page_write ( eeprom13_t *ctx, uint16_t id_page_addr, uint8_t *data_in );
385
386
402err_t eeprom13_id_page_read ( eeprom13_t *ctx, uint16_t id_page_addr, uint8_t *data_out );
403
423err_t eeprom13_config_dev_addr ( eeprom13_t *ctx, uint8_t cda, uint8_t dal );
424
452err_t eeprom13_sw_write_protect ( eeprom13_t *ctx, uint8_t wpa, uint8_t bp, uint8_t wpl );
453
469err_t eeprom13_get_lock_status ( eeprom13_t *ctx, uint8_t *lock_status );
470
471#ifdef __cplusplus
472}
473#endif
474#endif // EEPROM13_H
475
476 // eeprom13
477
478// ------------------------------------------------------------------------ END
eeprom13_return_value_t
EEPROM 13 Click return value data.
Definition eeprom13.h:203
@ EEPROM13_OK
Definition eeprom13.h:204
@ EEPROM13_ERROR
Definition eeprom13.h:205
err_t eeprom13_get_lock_status(eeprom13_t *ctx, uint8_t *lock_status)
EEPROM 13 get lock/unlock status of the identification function.
err_t eeprom13_id_page_read(eeprom13_t *ctx, uint16_t id_page_addr, uint8_t *data_out)
EEPROM 13 identification page read function.
err_t eeprom13_memory_read(eeprom13_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint8_t len)
EEPROM 13 memory write function.
err_t eeprom13_sw_write_protect(eeprom13_t *ctx, uint8_t wpa, uint8_t bp, uint8_t wpl)
EEPROM 13 software write protection function.
err_t eeprom13_generic_write(eeprom13_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len)
EEPROM 13 I2C writing function.
err_t eeprom13_memory_page_read(eeprom13_t *ctx, uint16_t page_addr, uint8_t *data_out, uint8_t len)
EEPROM 13 memory page read function.
void eeprom13_hw_write_enable(eeprom13_t *ctx)
EEPROM 13 hardware write enable function.
err_t eeprom13_id_page_write(eeprom13_t *ctx, uint16_t id_page_addr, uint8_t *data_in)
EEPROM 13 identification page write function.
err_t eeprom13_memory_page_write(eeprom13_t *ctx, uint16_t page_addr, uint8_t *data_in, uint8_t len)
EEPROM 13 memory page write function.
void eeprom13_hw_write_disable(eeprom13_t *ctx)
EEPROM 13 hardware write enable function.
err_t eeprom13_config_dev_addr(eeprom13_t *ctx, uint8_t cda, uint8_t dal)
EEPROM 13 configuate device address function.
err_t eeprom13_init(eeprom13_t *ctx, eeprom13_cfg_t *cfg)
EEPROM 13 initialization function.
void eeprom13_cfg_setup(eeprom13_cfg_t *cfg)
EEPROM 13 configuration object setup function.
err_t eeprom13_generic_read(eeprom13_t *ctx, uint16_t reg, uint8_t *data_out, uint8_t len)
EEPROM 13 I2C reading function.
err_t eeprom13_memory_write(eeprom13_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint8_t len)
EEPROM 13 memory write function.
EEPROM 13 Click configuration object.
Definition eeprom13.h:187
uint32_t i2c_speed
Definition eeprom13.h:193
pin_name_t wc
Definition eeprom13.h:191
pin_name_t scl
Definition eeprom13.h:188
pin_name_t sda
Definition eeprom13.h:189
uint8_t i2c_address
Definition eeprom13.h:194
EEPROM 13 Click context object.
Definition eeprom13.h:169
digital_out_t wc
Definition eeprom13.h:171
uint8_t chip_en_addr
Definition eeprom13.h:178
i2c_master_t i2c
Definition eeprom13.h:174
uint8_t slave_address
Definition eeprom13.h:177