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
61#define EEPROM_NBYTES_MIN 1
62#define EEPROM_NBYTES_PAGE 16
63#define EEPROM_NBYTES_MAX 256
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 ) // End macros group
77// --------------------------------------------------------------- PUBLIC TYPES
78
82typedef enum
83{
92
94
98typedef enum
99{
103
105
109typedef 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
122typedef 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
135 // End types group
137// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143#ifdef __cplusplus
144extern "C"{
145#endif
146
155
167
177void eeprom_write_byte( eeprom_t *context, uint8_t reg_addr, uint8_t data_in );
178
188void eeprom_write_page( eeprom_t *context, uint8_t reg_addr, uint8_t *data_in );
189
200uint8_t eeprom_read_byte( eeprom_t *context, uint8_t reg_addr );
201
214eeprom_retval_t eeprom_read_sequential( eeprom_t *context, uint8_t reg_addr, uint16_t n_bytes, uint8_t *data_out );
215
224
233
234#ifdef __cplusplus
235}
236#endif
237#endif // _EEPROM_H_
238 // End public_function group
241
242// ------------------------------------------------------------------------ END
eeprom_i2c_address_selector_t
Click address (memory block) selection.
Definition: eeprom.h:83
eeprom_retval_t
Click error code.
Definition: eeprom.h:99
@ EEPROM_I2C_ADDR_SEL_2
Definition: eeprom.h:86
@ EEPROM_I2C_ADDR_SEL_6
Definition: eeprom.h:90
@ EEPROM_I2C_ADDR_SEL_5
Definition: eeprom.h:89
@ EEPROM_I2C_ADDR_SEL_4
Definition: eeprom.h:88
@ EEPROM_I2C_ADDR_SEL_0
Definition: eeprom.h:84
@ EEPROM_I2C_ADDR_SEL_3
Definition: eeprom.h:87
@ EEPROM_I2C_ADDR_SEL_1
Definition: eeprom.h:85
@ EEPROM_I2C_ADDR_SEL_7
Definition: eeprom.h:91
@ EEPROM_RETVAL_OK
Definition: eeprom.h:100
@ EEPROM_RETVAL_ERR_DRV_INIT
Definition: eeprom.h:101
@ EEPROM_RETVAL_ERR_NBYTES
Definition: eeprom.h:102
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.
Click configuration structure definition.
Definition: eeprom.h:123
eeprom_i2c_address_selector_t addr_sel
Definition: eeprom.h:129
uint32_t i2c_speed
Definition: eeprom.h:131
pin_name_t wp
Definition: eeprom.h:125
pin_name_t scl
Definition: eeprom.h:126
pin_name_t sda
Definition: eeprom.h:127
uint8_t i2c_address
Definition: eeprom.h:132
Click context object definition.
Definition: eeprom.h:110
i2c_master_t i2c
Definition: eeprom.h:113
uint8_t slave_addr
Definition: eeprom.h:115
digital_out_t wp
Definition: eeprom.h:112