eeprom3  2.0.0.0
eeprom3.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 EEPROM3_H
36 #define EEPROM3_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_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define EEPROM3_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
69 
76 #define EEPROM3_OK 0
77 #define EEPROM3_ERROR -1
78  // End group macro
81 // --------------------------------------------------------------- PUBLIC TYPES
90 typedef struct
91 {
92  // Modules
93  i2c_master_t i2c;
94 
95  // ctx variable
96  uint8_t slave_address;
97 
98 } eeprom3_t;
99 
103 typedef struct
104 {
105  // Communication gpio pins
106  pin_name_t scl;
107  pin_name_t sda;
108 
109  // static variable
110  uint32_t i2c_speed;
111  uint8_t i2c_address;
112 
113 } eeprom3_cfg_t;
114  // End types group
116 
117 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
118 
124 #ifdef __cplusplus
125 extern "C"{
126 #endif
127 
137 
146 err_t eeprom3_init ( eeprom3_t *ctx, eeprom3_cfg_t *cfg );
147 
157 void eeprom3_write_byte ( eeprom3_t *ctx, uint16_t reg_address, uint8_t data_in );
158 
168 void eeprom3_write_page( eeprom3_t *ctx, uint16_t reg_address, uint8_t* data_in, uint8_t count );
169 
180 void eeprom3_read ( eeprom3_t *ctx, uint16_t reg_address, uint8_t *data_out, uint16_t count );
181 
182 #ifdef __cplusplus
183 }
184 #endif
185 #endif // _EEPROM3_H_
186  // End public_function group
189 
190 // ------------------------------------------------------------------------- END
eeprom3_read
void eeprom3_read(eeprom3_t *ctx, uint16_t reg_address, uint8_t *data_out, uint16_t count)
Generic read function.
eeprom3_write_byte
void eeprom3_write_byte(eeprom3_t *ctx, uint16_t reg_address, uint8_t data_in)
Generic write function.
eeprom3_write_page
void eeprom3_write_page(eeprom3_t *ctx, uint16_t reg_address, uint8_t *data_in, uint8_t count)
Generic write page function.
eeprom3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: eeprom3.h:110
eeprom3_t::slave_address
uint8_t slave_address
Definition: eeprom3.h:96
eeprom3_cfg_setup
void eeprom3_cfg_setup(eeprom3_cfg_t *cfg)
Config Object Initialization function.
eeprom3_init
err_t eeprom3_init(eeprom3_t *ctx, eeprom3_cfg_t *cfg)
Initialization function.
eeprom3_cfg_t::scl
pin_name_t scl
Definition: eeprom3.h:106
eeprom3_cfg_t::sda
pin_name_t sda
Definition: eeprom3.h:107
eeprom3_cfg_t::i2c_address
uint8_t i2c_address
Definition: eeprom3.h:111
eeprom3_cfg_t
Click configuration structure definition.
Definition: eeprom3.h:104
eeprom3_t
Click ctx object definition.
Definition: eeprom3.h:91
eeprom3_t::i2c
i2c_master_t i2c
Definition: eeprom3.h:93