eeprom 2.0.0.0
eeprom.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef _EEPROM_H_
36#define _EEPROM_H_
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_i2c_master.h"
54
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define EEPROM_BLOCK_ADDR_START 0x00
67#define EEPROM_BLOCK_ADDR_MIDDLE 0x80
68#define EEPROM_BLOCK_ADDR_END 0xFF
75#define EEPROM_NBYTES_MIN 1
76#define EEPROM_NBYTES_PAGE 16
77#define EEPROM_NBYTES_MAX 256
84#define EEPROM_MAP_MIKROBUS( cfg, mikrobus ) \
85 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
86 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
87 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
90 // End macros group
91// --------------------------------------------------------------- PUBLIC TYPES
92
108
119
123typedef struct
124{
125 // Click mikrobus DRV objects.
126 digital_out_t wp;
127 i2c_master_t i2c;
128 // Device slave address.
129 uint8_t slave_addr;
130
131} eeprom_t;
132
136typedef struct
137{
138 // Used mikrobus pins.
139 pin_name_t wp;
140 pin_name_t scl;
141 pin_name_t sda;
142 // Device address selector.
144 // static variable
145 uint32_t i2c_speed;
146 uint8_t i2c_address;
147
149
150 // End types group
151// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
157#ifdef __cplusplus
158extern "C"{
159#endif
160
169
181
191void eeprom_write_byte( eeprom_t *context, uint8_t reg_addr, uint8_t data_in );
192
202void eeprom_write_page( eeprom_t *context, uint8_t reg_addr, uint8_t *data_in );
203
214uint8_t eeprom_read_byte( eeprom_t *context, uint8_t reg_addr );
215
228eeprom_retval_t eeprom_read_sequential( eeprom_t *context, uint8_t reg_addr, uint16_t n_bytes, uint8_t *data_out );
229
238
247
248#ifdef __cplusplus
249}
250#endif
251#endif // _EEPROM_H_
252
253 // End public_function group
255
256// ------------------------------------------------------------------------ END
void eeprom_write_page(eeprom_t *context, uint8_t reg_addr, uint8_t *data_in)
Page Write function.
void eeprom_write_enable(eeprom_t *context)
Write Enable function.
uint8_t eeprom_read_byte(eeprom_t *context, uint8_t reg_addr)
Byte Read function.
eeprom_retval_t eeprom_read_sequential(eeprom_t *context, uint8_t reg_addr, uint16_t n_bytes, uint8_t *data_out)
Sequential Read function.
void eeprom_cfg_setup(eeprom_cfg_t *cfg)
Config Structure Setup function.
void eeprom_write_byte(eeprom_t *context, uint8_t reg_addr, uint8_t data_in)
Byte Write function.
eeprom_retval_t eeprom_init(eeprom_t *context, eeprom_cfg_t *cfg)
Click Initialization function.
void eeprom_write_protect(eeprom_t *context)
Write Protect function.
eeprom_i2c_address_selector_t
Click address (memory block) selection.
Definition eeprom.h:97
eeprom_retval_t
Click error code.
Definition eeprom.h:113
@ EEPROM_I2C_ADDR_SEL_2
Definition eeprom.h:100
@ EEPROM_I2C_ADDR_SEL_6
Definition eeprom.h:104
@ EEPROM_I2C_ADDR_SEL_5
Definition eeprom.h:103
@ EEPROM_I2C_ADDR_SEL_4
Definition eeprom.h:102
@ EEPROM_I2C_ADDR_SEL_0
Definition eeprom.h:98
@ EEPROM_I2C_ADDR_SEL_3
Definition eeprom.h:101
@ EEPROM_I2C_ADDR_SEL_1
Definition eeprom.h:99
@ EEPROM_I2C_ADDR_SEL_7
Definition eeprom.h:105
@ EEPROM_RETVAL_OK
Definition eeprom.h:114
@ EEPROM_RETVAL_ERR_DRV_INIT
Definition eeprom.h:115
@ EEPROM_RETVAL_ERR_NBYTES
Definition eeprom.h:116
Click configuration structure definition.
Definition eeprom.h:137
eeprom_i2c_address_selector_t addr_sel
Definition eeprom.h:143
uint32_t i2c_speed
Definition eeprom.h:145
pin_name_t wp
Definition eeprom.h:139
pin_name_t scl
Definition eeprom.h:140
pin_name_t sda
Definition eeprom.h:141
uint8_t i2c_address
Definition eeprom.h:146
Click context object definition.
Definition eeprom.h:124
i2c_master_t i2c
Definition eeprom.h:127
uint8_t slave_addr
Definition eeprom.h:129
digital_out_t wp
Definition eeprom.h:126