eeprom  2.0.0.0
eeprom.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * 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
83 typedef hal_i2c_address_t eeprom_i2c_address_t;
84 typedef hal_i2c_data_t eeprom_i2c_data_t;
85 
89 typedef enum
90 {
99 
101 
105 typedef enum
106 {
110 
112 
116 typedef struct
117 {
118  // Click mikrobus DRV objects.
119  digital_out_t wp;
120  i2c_master_t i2c;
121  // Device slave address.
123 
124 } eeprom_t;
125 
129 typedef struct
130 {
131  // Used mikrobus pins.
132  pin_name_t wp;
133  pin_name_t scl;
134  pin_name_t sda;
135  // Device address selector.
137 
138 } eeprom_cfg_t;
139  // End types group
141 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
147 #ifdef __cplusplus
148 extern "C"{
149 #endif
150 
158 void eeprom_cfg_setup( eeprom_cfg_t *cfg );
159 
171 
181 void eeprom_write_byte( eeprom_t *context, uint8_t reg_addr, eeprom_i2c_data_t data_in );
182 
192 void eeprom_write_page( eeprom_t *context, uint8_t reg_addr, eeprom_i2c_data_t *data_in );
193 
204 eeprom_i2c_data_t eeprom_read_byte( eeprom_t *context, uint8_t reg_addr );
205 
218 eeprom_retval_t eeprom_read_sequential( eeprom_t *context, uint8_t reg_addr, uint16_t n_bytes, eeprom_i2c_data_t *data_out );
219 
227 void eeprom_write_enable( eeprom_t *context );
228 
236 void eeprom_write_protect( eeprom_t *context );
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 #endif // _EEPROM_H_
242  // End public_function group
245 
246 // ------------------------------------------------------------------------ END
EEPROM_I2C_ADDR_SEL_7
Definition: eeprom.h:98
EEPROM_I2C_ADDR_SEL_5
Definition: eeprom.h:96
EEPROM_I2C_ADDR_SEL_0
Definition: eeprom.h:91
eeprom_read_byte
eeprom_i2c_data_t eeprom_read_byte(eeprom_t *context, uint8_t reg_addr)
Byte Read function.
EEPROM_I2C_ADDR_SEL_2
Definition: eeprom.h:93
eeprom_cfg_t::scl
pin_name_t scl
Definition: eeprom.h:133
eeprom_write_byte
void eeprom_write_byte(eeprom_t *context, uint8_t reg_addr, eeprom_i2c_data_t data_in)
Byte Write function.
EEPROM_I2C_ADDR_SEL_1
Definition: eeprom.h:92
eeprom_init
eeprom_retval_t eeprom_init(eeprom_t *context, eeprom_cfg_t *cfg)
Click Initialization function.
eeprom_t::wp
digital_out_t wp
Definition: eeprom.h:119
eeprom_write_enable
void eeprom_write_enable(eeprom_t *context)
Write Enable function.
EEPROM_I2C_ADDR_SEL_4
Definition: eeprom.h:95
eeprom_write_protect
void eeprom_write_protect(eeprom_t *context)
Write Protect function.
eeprom_cfg_setup
void eeprom_cfg_setup(eeprom_cfg_t *cfg)
Config Structure Setup function.
eeprom_t::i2c
i2c_master_t i2c
Definition: eeprom.h:120
EEPROM_I2C_ADDR_SEL_6
Definition: eeprom.h:97
eeprom_i2c_address_selector_t
eeprom_i2c_address_selector_t
Click address (memory block) selection.
Definition: eeprom.h:89
eeprom_i2c_address_t
hal_i2c_address_t eeprom_i2c_address_t
Definition: eeprom.h:83
EEPROM_RETVAL_ERR_NBYTES
Definition: eeprom.h:109
eeprom_t
Click context object definition.
Definition: eeprom.h:116
eeprom_read_sequential
eeprom_retval_t eeprom_read_sequential(eeprom_t *context, uint8_t reg_addr, uint16_t n_bytes, eeprom_i2c_data_t *data_out)
Sequential Read function.
eeprom_cfg_t
Click configuration structure definition.
Definition: eeprom.h:129
eeprom_cfg_t::sda
pin_name_t sda
Definition: eeprom.h:134
EEPROM_RETVAL_OK
Definition: eeprom.h:107
eeprom_cfg_t::addr_sel
eeprom_i2c_address_selector_t addr_sel
Definition: eeprom.h:136
eeprom_retval_t
eeprom_retval_t
Click error code.
Definition: eeprom.h:105
EEPROM_I2C_ADDR_SEL_3
Definition: eeprom.h:94
eeprom_write_page
void eeprom_write_page(eeprom_t *context, uint8_t reg_addr, eeprom_i2c_data_t *data_in)
Page Write function.
eeprom_t::slave_addr
eeprom_i2c_address_t slave_addr
Definition: eeprom.h:122
eeprom_i2c_data_t
hal_i2c_data_t eeprom_i2c_data_t
Definition: eeprom.h:84
eeprom_cfg_t::wp
pin_name_t wp
Definition: eeprom.h:132
EEPROM_RETVAL_ERR_DRV_INIT
Definition: eeprom.h:108