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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define EEPROM12_REG_IDENTIFICATION_PAGE 0x0000u
70 #define EEPROM12_REG_IDENTIFICATION_PAGE_LOCK 0x0200u
71 #define EEPROM12_REG_CONFIG_DEVICE_ADDRESS 0xC000u
72  // eeprom12_reg
74 
89 #define EEPROM12_MEMORY_ADDRESS_MIN 0x0000u
90 #define EEPROM12_MEMORY_ADDRESS_MAX 0x7FFFu
91 #define EEPROM12_PAGE_SIZE 64
92 #define EEPROM12_PAGE_MAX 512
93 
98 #define EEPROM12_CDA_DAL_BIT_MASK 0x01
99 #define EEPROM12_CDA_CEA_BIT_MASK 0x07
100 
105 #define EEPROM12_DEFAULT_CHIP_ENABLE_ADDRESS 0x00
106 
112 #define EEPROM12_DEVICE_ADDRESS_MEMORY 0x50
113 #define EEPROM12_DEVICE_ADDRESS_PAGE 0x58
114  // eeprom12_set
116 
131 #define EEPROM12_MAP_MIKROBUS( cfg, mikrobus ) \
132  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
133  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
134  cfg.wc = MIKROBUS( mikrobus, MIKROBUS_PWM )
135  // eeprom12_map // eeprom12
138 
143 typedef struct
144 {
145  // Output pins
146  digital_out_t wc;
148  // Modules
149  i2c_master_t i2c;
151  // I2C slave address
152  uint8_t slave_address;
154  uint8_t chip_en_addr; /* Chip enable address */
155 
156 } eeprom12_t;
157 
162 typedef struct
163 {
164  pin_name_t scl;
165  pin_name_t sda;
167  pin_name_t wc;
169  uint32_t i2c_speed;
170  uint8_t i2c_address;
173 
178 typedef enum
179 {
181  EEPROM12_ERROR = -1
182 
184 
201 
216 
228 
240 
255 err_t eeprom12_generic_write ( eeprom12_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len );
256 
271 err_t eeprom12_generic_read ( eeprom12_t *ctx, uint16_t reg, uint8_t *data_out, uint8_t len );
272 
289 err_t eeprom12_memory_write ( eeprom12_t *ctx, uint16_t mem_addr, uint8_t *data_in, uint8_t len );
290 
307 err_t eeprom12_memory_read ( eeprom12_t *ctx, uint16_t mem_addr, uint8_t *data_out, uint8_t len );
308 
325 err_t eeprom12_memory_page_write ( eeprom12_t *ctx, uint16_t page_addr, uint8_t *data_in, uint8_t len );
326 
343 err_t eeprom12_memory_page_read ( eeprom12_t *ctx, uint16_t page_addr, uint8_t *data_out, uint8_t len );
344 
361 err_t eeprom12_id_page_write ( eeprom12_t *ctx, uint16_t id_page_addr, uint8_t *data_in );
362 
379 err_t eeprom12_id_page_read ( eeprom12_t *ctx, uint16_t id_page_addr, uint8_t *data_out );
380 
400 err_t eeprom12_config_dev_addr ( eeprom12_t *ctx, uint8_t cda, uint8_t dal );
401 
417 err_t eeprom12_read_lock_status ( eeprom12_t *ctx, uint8_t *lock_status );
418 
419 #ifdef __cplusplus
420 }
421 #endif
422 #endif // EEPROM12_H
423  // eeprom12
425 
426 // ------------------------------------------------------------------------ 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:170
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:165
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:152
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:146
eeprom12_return_value_t
eeprom12_return_value_t
EEPROM 12 Click return value data.
Definition: eeprom12.h:179
eeprom12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: eeprom12.h:169
EEPROM12_ERROR
@ EEPROM12_ERROR
Definition: eeprom12.h:181
eeprom12_t::i2c
i2c_master_t i2c
Definition: eeprom12.h:149
eeprom12_cfg_t::wc
pin_name_t wc
Definition: eeprom12.h:167
eeprom12_t
EEPROM 12 Click context object.
Definition: eeprom12.h:144
eeprom12_cfg_t::scl
pin_name_t scl
Definition: eeprom12.h:164
eeprom12_t::chip_en_addr
uint8_t chip_en_addr
Definition: eeprom12.h:154
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:180
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:163
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.