eeprom12  2.1.0.0
eeprom12.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 EEPROM12_H
29 #define EEPROM12_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define EEPROM12_REG_IDENTIFICATION_PAGE 0x0000u
74 #define EEPROM12_REG_IDENTIFICATION_PAGE_LOCK 0x0200u
75 #define EEPROM12_REG_CONFIG_DEVICE_ADDRESS 0xC000u
76  // eeprom12_reg
78 
93 #define EEPROM12_MEMORY_ADDRESS_MIN 0x0000u
94 #define EEPROM12_MEMORY_ADDRESS_MAX 0x7FFFu
95 #define EEPROM12_PAGE_SIZE 64
96 #define EEPROM12_PAGE_MAX 512
97 
102 #define EEPROM12_CDA_DAL_BIT_MASK 0x01
103 #define EEPROM12_CDA_CEA_BIT_MASK 0x07
104 
109 #define EEPROM12_DEFAULT_CHIP_ENABLE_ADDRESS 0x00
110 
116 #define EEPROM12_DEVICE_ADDRESS_MEMORY 0x50
117 #define EEPROM12_DEVICE_ADDRESS_PAGE 0x58
118  // eeprom12_set
120 
135 #define EEPROM12_MAP_MIKROBUS( cfg, mikrobus ) \
136  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
137  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
138  cfg.wc = MIKROBUS( mikrobus, MIKROBUS_PWM )
139  // eeprom12_map // eeprom12
142 
147 typedef struct
148 {
149  // Output pins
150  digital_out_t wc;
152  // Modules
153  i2c_master_t i2c;
155  // I2C slave address
156  uint8_t slave_address;
158  uint8_t chip_en_addr; /* Chip enable address */
159 
160 } eeprom12_t;
161 
166 typedef struct
167 {
168  pin_name_t scl;
169  pin_name_t sda;
171  pin_name_t wc;
173  uint32_t i2c_speed;
174  uint8_t i2c_address;
177 
182 typedef enum
183 {
185  EEPROM12_ERROR = -1
186 
188 
205 
220 
232 
244 
259 err_t eeprom12_generic_write ( eeprom12_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len );
260 
275 err_t eeprom12_generic_read ( eeprom12_t *ctx, uint16_t reg, uint8_t *data_out, uint8_t len );
276 
293 err_t eeprom12_memory_write ( eeprom12_t *ctx, uint16_t mem_addr, uint8_t *data_in, uint8_t len );
294 
311 err_t eeprom12_memory_read ( eeprom12_t *ctx, uint16_t mem_addr, uint8_t *data_out, uint8_t len );
312 
329 err_t eeprom12_memory_page_write ( eeprom12_t *ctx, uint16_t page_addr, uint8_t *data_in, uint8_t len );
330 
347 err_t eeprom12_memory_page_read ( eeprom12_t *ctx, uint16_t page_addr, uint8_t *data_out, uint8_t len );
348 
365 err_t eeprom12_id_page_write ( eeprom12_t *ctx, uint16_t id_page_addr, uint8_t *data_in );
366 
383 err_t eeprom12_id_page_read ( eeprom12_t *ctx, uint16_t id_page_addr, uint8_t *data_out );
384 
404 err_t eeprom12_config_dev_addr ( eeprom12_t *ctx, uint8_t cda, uint8_t dal );
405 
421 err_t eeprom12_read_lock_status ( eeprom12_t *ctx, uint8_t *lock_status );
422 
423 #ifdef __cplusplus
424 }
425 #endif
426 #endif // EEPROM12_H
427  // eeprom12
429 
430 // ------------------------------------------------------------------------ END
eeprom12_memory_page_read
err_t eeprom12_memory_page_read(eeprom12_t *ctx, uint16_t page_addr, uint8_t *data_out, uint8_t len)
EEPROM 12 memory page read function.
eeprom12_id_page_write
err_t eeprom12_id_page_write(eeprom12_t *ctx, uint16_t id_page_addr, uint8_t *data_in)
EEPROM 12 identification page write function.
eeprom12_write_enable
void eeprom12_write_enable(eeprom12_t *ctx)
EEPROM 12 write enable function.
eeprom12_cfg_setup
void eeprom12_cfg_setup(eeprom12_cfg_t *cfg)
EEPROM 12 configuration object setup function.
eeprom12_cfg_t::i2c_address
uint8_t i2c_address
Definition: eeprom12.h:174
eeprom12_generic_write
err_t eeprom12_generic_write(eeprom12_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len)
EEPROM 12 I2C writing function.
eeprom12_cfg_t::sda
pin_name_t sda
Definition: eeprom12.h:169
eeprom12_config_dev_addr
err_t eeprom12_config_dev_addr(eeprom12_t *ctx, uint8_t cda, uint8_t dal)
EEPROM 12 configuate device address function.
eeprom12_memory_read
err_t eeprom12_memory_read(eeprom12_t *ctx, uint16_t mem_addr, uint8_t *data_out, uint8_t len)
EEPROM 12 memory read function.
eeprom12_t::slave_address
uint8_t slave_address
Definition: eeprom12.h:156
eeprom12_generic_read
err_t eeprom12_generic_read(eeprom12_t *ctx, uint16_t reg, uint8_t *data_out, uint8_t len)
EEPROM 12 I2C reading function.
eeprom12_t::wc
digital_out_t wc
Definition: eeprom12.h:150
eeprom12_return_value_t
eeprom12_return_value_t
EEPROM 12 Click return value data.
Definition: eeprom12.h:183
eeprom12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: eeprom12.h:173
EEPROM12_ERROR
@ EEPROM12_ERROR
Definition: eeprom12.h:185
eeprom12_t::i2c
i2c_master_t i2c
Definition: eeprom12.h:153
eeprom12_cfg_t::wc
pin_name_t wc
Definition: eeprom12.h:171
eeprom12_t
EEPROM 12 Click context object.
Definition: eeprom12.h:148
eeprom12_cfg_t::scl
pin_name_t scl
Definition: eeprom12.h:168
eeprom12_t::chip_en_addr
uint8_t chip_en_addr
Definition: eeprom12.h:158
eeprom12_init
err_t eeprom12_init(eeprom12_t *ctx, eeprom12_cfg_t *cfg)
EEPROM 12 initialization function.
eeprom12_write_disable
void eeprom12_write_disable(eeprom12_t *ctx)
EEPROM 12 write disable function.
EEPROM12_OK
@ EEPROM12_OK
Definition: eeprom12.h:184
eeprom12_memory_write
err_t eeprom12_memory_write(eeprom12_t *ctx, uint16_t mem_addr, uint8_t *data_in, uint8_t len)
EEPROM 12 memory write function.
eeprom12_id_page_read
err_t eeprom12_id_page_read(eeprom12_t *ctx, uint16_t id_page_addr, uint8_t *data_out)
EEPROM 12 identification page read function.
eeprom12_cfg_t
EEPROM 12 Click configuration object.
Definition: eeprom12.h:167
eeprom12_memory_page_write
err_t eeprom12_memory_page_write(eeprom12_t *ctx, uint16_t page_addr, uint8_t *data_in, uint8_t len)
EEPROM 12 memory page write function.
eeprom12_read_lock_status
err_t eeprom12_read_lock_status(eeprom12_t *ctx, uint8_t *lock_status)
EEPROM 12 read lock status function.