eeprom8  2.0.0.0
eeprom8.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 EEPROM8_H
29 #define EEPROM8_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
49 #define EEPROM8_WRITE_ENABLE 0
50 #define EEPROM8_WRITE_PROTECT 1
51 
70 #define EEPROM8_BLOCK_ADDR_START 0x0000
71 #define EEPROM8_BLOCK_ADDR_END 0xFFFFul
72 
84 #define EEPROM8_NBYTES_MIN 1
85 #define EEPROM8_NBYTES_PAGE 128
86 
93 #define EEPROM8_SET_DEV_ADDR 0x50
94  // eeprom8_set
96 
111 #define EEPROM8_MAP_MIKROBUS( cfg, mikrobus ) \
112  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
113  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
114  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM );
115 
116  // eeprom8_map // eeprom8
119 
124 typedef enum
125 {
134 
136 
141 typedef struct
142 {
143  // Output pins
144  digital_out_t wp;
146  // Modules
147  i2c_master_t i2c;
149  // I2C slave address
150  uint8_t slave_address;
152 } eeprom8_t;
153 
158 typedef struct
159 {
160  pin_name_t scl;
161  pin_name_t sda;
163  pin_name_t wp;
165  uint32_t i2c_speed;
166  uint8_t i2c_address;
168 } eeprom8_cfg_t;
169 
174 typedef enum
175 {
177  EEPROM8_ERROR = -1
178 
180 
197 
211 err_t eeprom8_init ( eeprom8_t *ctx, eeprom8_cfg_t *cfg );
212 
213 
225 err_t eeprom8_write_byte( eeprom8_t *ctx, uint16_t reg_addr, uint8_t data_in );
226 
238 err_t eeprom8_write_page( eeprom8_t *ctx, uint16_t reg_addr, uint8_t *data_in );
239 
251 err_t eeprom8_read_random_byte( eeprom8_t *ctx, uint16_t reg_addr, uint8_t *data_out );
252 
263 err_t eeprom8_read_current_byte( eeprom8_t *ctx, uint8_t *data_out );
264 
277 err_t eeprom8_read_sequential( eeprom8_t *ctx, uint16_t reg_addr, uint16_t n_bytes, uint8_t *data_out );
278 
287 
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 #endif // EEPROM8_H
301  // eeprom8
303 
304 // ------------------------------------------------------------------------ END
EEPROM_I2C_ADDR_SEL_1
@ EEPROM_I2C_ADDR_SEL_1
Definition: eeprom8.h:127
EEPROM_I2C_ADDR_SEL_7
@ EEPROM_I2C_ADDR_SEL_7
Definition: eeprom8.h:133
EEPROM_I2C_ADDR_SEL_2
@ EEPROM_I2C_ADDR_SEL_2
Definition: eeprom8.h:128
EEPROM_I2C_ADDR_SEL_5
@ EEPROM_I2C_ADDR_SEL_5
Definition: eeprom8.h:131
eeprom8_t
EEPROM 8 Click context object.
Definition: eeprom8.h:142
eeprom8_write_enable
void eeprom8_write_enable(eeprom8_t *ctx)
Write Enable function.
eeprom8_cfg_t::sda
pin_name_t sda
Definition: eeprom8.h:161
eeprom8_return_value_t
eeprom8_return_value_t
EEPROM 8 Click return value data.
Definition: eeprom8.h:175
eeprom8_write_page
err_t eeprom8_write_page(eeprom8_t *ctx, uint16_t reg_addr, uint8_t *data_in)
Page Write function.
EEPROM8_OK
@ EEPROM8_OK
Definition: eeprom8.h:176
EEPROM_I2C_ADDR_SEL_6
@ EEPROM_I2C_ADDR_SEL_6
Definition: eeprom8.h:132
eeprom8_read_random_byte
err_t eeprom8_read_random_byte(eeprom8_t *ctx, uint16_t reg_addr, uint8_t *data_out)
Random Byte Read function.
EEPROM_I2C_ADDR_SEL_0
@ EEPROM_I2C_ADDR_SEL_0
Definition: eeprom8.h:126
eeprom8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: eeprom8.h:165
EEPROM8_ERROR
@ EEPROM8_ERROR
Definition: eeprom8.h:177
eeprom8_read_sequential
err_t eeprom8_read_sequential(eeprom8_t *ctx, uint16_t reg_addr, uint16_t n_bytes, uint8_t *data_out)
Sequential Read function.
EEPROM_I2C_ADDR_SEL_3
@ EEPROM_I2C_ADDR_SEL_3
Definition: eeprom8.h:129
eeprom8_t::slave_address
uint8_t slave_address
Definition: eeprom8.h:150
eeprom8_cfg_t
EEPROM 8 Click configuration object.
Definition: eeprom8.h:159
eeprom8_write_byte
err_t eeprom8_write_byte(eeprom8_t *ctx, uint16_t reg_addr, uint8_t data_in)
Byte Write function.
eeprom8_cfg_t::i2c_address
uint8_t i2c_address
Definition: eeprom8.h:166
eeprom8_cfg_t::scl
pin_name_t scl
Definition: eeprom8.h:160
eeprom8_cfg_t::wp
pin_name_t wp
Definition: eeprom8.h:163
eeprom8_read_current_byte
err_t eeprom8_read_current_byte(eeprom8_t *ctx, uint8_t *data_out)
Byte Read function.
eeprom8_t::i2c
i2c_master_t i2c
Definition: eeprom8.h:147
EEPROM_I2C_ADDR_SEL_4
@ EEPROM_I2C_ADDR_SEL_4
Definition: eeprom8.h:130
eeprom8_cfg_setup
void eeprom8_cfg_setup(eeprom8_cfg_t *cfg)
EEPROM 8 configuration object setup function.
eeprom8_init
err_t eeprom8_init(eeprom8_t *ctx, eeprom8_cfg_t *cfg)
EEPROM 8 initialization function.
eeprom8_t::wp
digital_out_t wp
Definition: eeprom8.h:144
eeprom8_write_protect
void eeprom8_write_protect(eeprom8_t *ctx)
Write Protect function.
eeprom_i2c_address_selector_t
eeprom_i2c_address_selector_t
Click address (memory block) selection.
Definition: eeprom8.h:125