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 
38 #include "drv_digital_out.h"
39 #include "drv_i2c_master.h"
40 
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define EEPROM_BLOCK_ADDR_START 0x00
53 #define EEPROM_BLOCK_ADDR_MIDDLE 0x80
54 #define EEPROM_BLOCK_ADDR_END 0xFF
55 
61 #define EEPROM_NBYTES_MIN 1
62 #define EEPROM_NBYTES_PAGE 16
63 #define EEPROM_NBYTES_MAX 256
64 
70 #define EEPROM_MAP_MIKROBUS( cfg, mikrobus ) \
71  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
72  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
73  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
74  // End macros group
77 // --------------------------------------------------------------- PUBLIC TYPES
78 
82 typedef enum
83 {
92 
94 
98 typedef enum
99 {
103 
105 
109 typedef struct
110 {
111  // Click mikrobus DRV objects.
112  digital_out_t wp;
113  i2c_master_t i2c;
114  // Device slave address.
115  uint8_t slave_addr;
116 
117 } eeprom_t;
118 
122 typedef struct
123 {
124  // Used mikrobus pins.
125  pin_name_t wp;
126  pin_name_t scl;
127  pin_name_t sda;
128  // Device address selector.
130  // static variable
131  uint32_t i2c_speed;
132  uint8_t i2c_address;
133 
134 } eeprom_cfg_t;
135  // End types group
137 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143 #ifdef __cplusplus
144 extern "C"{
145 #endif
146 
154 void eeprom_cfg_setup( eeprom_cfg_t *cfg );
155 
167 
177 void eeprom_write_byte( eeprom_t *context, uint8_t reg_addr, uint8_t data_in );
178 
188 void eeprom_write_page( eeprom_t *context, uint8_t reg_addr, uint8_t *data_in );
189 
200 uint8_t eeprom_read_byte( eeprom_t *context, uint8_t reg_addr );
201 
214 eeprom_retval_t eeprom_read_sequential( eeprom_t *context, uint8_t reg_addr, uint16_t n_bytes, uint8_t *data_out );
215 
223 void eeprom_write_enable( eeprom_t *context );
224 
232 void eeprom_write_protect( eeprom_t *context );
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 #endif // _EEPROM_H_
238  // End public_function group
241 
242 // ------------------------------------------------------------------------ END
EEPROM_I2C_ADDR_SEL_6
Definition: eeprom.h:90
EEPROM_I2C_ADDR_SEL_2
Definition: eeprom.h:86
eeprom_write_page
void eeprom_write_page(eeprom_t *context, uint8_t reg_addr, uint8_t *data_in)
Page Write function.
eeprom_cfg_t::scl
pin_name_t scl
Definition: eeprom.h:126
eeprom_init
eeprom_retval_t eeprom_init(eeprom_t *context, eeprom_cfg_t *cfg)
Click Initialization function.
EEPROM_RETVAL_ERR_DRV_INIT
Definition: eeprom.h:101
EEPROM_I2C_ADDR_SEL_7
Definition: eeprom.h:91
EEPROM_I2C_ADDR_SEL_3
Definition: eeprom.h:87
eeprom_i2c_address_selector_t
eeprom_i2c_address_selector_t
Click address (memory block) selection.
Definition: eeprom.h:82
eeprom_write_byte
void eeprom_write_byte(eeprom_t *context, uint8_t reg_addr, uint8_t data_in)
Byte Write function.
eeprom_t::wp
digital_out_t wp
Definition: eeprom.h:112
EEPROM_RETVAL_ERR_NBYTES
Definition: eeprom.h:102
EEPROM_I2C_ADDR_SEL_0
Definition: eeprom.h:84
eeprom_write_enable
void eeprom_write_enable(eeprom_t *context)
Write Enable function.
EEPROM_I2C_ADDR_SEL_5
Definition: eeprom.h:89
eeprom_write_protect
void eeprom_write_protect(eeprom_t *context)
Write Protect function.
EEPROM_I2C_ADDR_SEL_1
Definition: eeprom.h:85
eeprom_cfg_setup
void eeprom_cfg_setup(eeprom_cfg_t *cfg)
Config Structure Setup function.
eeprom_read_byte
uint8_t eeprom_read_byte(eeprom_t *context, uint8_t reg_addr)
Byte Read function.
eeprom_t::i2c
i2c_master_t i2c
Definition: eeprom.h:113
EEPROM_RETVAL_OK
Definition: eeprom.h:100
eeprom_cfg_t::i2c_address
uint8_t i2c_address
Definition: eeprom.h:132
eeprom_t
Click context object definition.
Definition: eeprom.h:109
eeprom_t::slave_addr
uint8_t slave_addr
Definition: eeprom.h:115
eeprom_cfg_t
Click configuration structure definition.
Definition: eeprom.h:122
eeprom_read_sequential
eeprom_retval_t eeprom_read_sequential(eeprom_t *context, uint8_t reg_addr, uint16_t n_bytes, uint8_t *data_out)
Sequential Read function.
eeprom_cfg_t::sda
pin_name_t sda
Definition: eeprom.h:127
eeprom_cfg_t::addr_sel
eeprom_i2c_address_selector_t addr_sel
Definition: eeprom.h:129
EEPROM_I2C_ADDR_SEL_4
Definition: eeprom.h:88
eeprom_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: eeprom.h:131
eeprom_retval_t
eeprom_retval_t
Click error code.
Definition: eeprom.h:98
eeprom_cfg_t::wp
pin_name_t wp
Definition: eeprom.h:125