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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define EEPROM12_REG_IDENTIFICATION_PAGE 0x0000u
60 #define EEPROM12_REG_IDENTIFICATION_PAGE_LOCK 0x0200u
61 #define EEPROM12_REG_CONFIG_DEVICE_ADDRESS 0xC000u
62  // eeprom12_reg
64 
79 #define EEPROM12_MEMORY_ADDRESS_MIN 0x0000u
80 #define EEPROM12_MEMORY_ADDRESS_MAX 0x7FFFu
81 #define EEPROM12_PAGE_SIZE 64
82 #define EEPROM12_PAGE_MAX 512
83 
88 #define EEPROM12_CDA_DAL_BIT_MASK 0x01
89 #define EEPROM12_CDA_CEA_BIT_MASK 0x07
90 
95 #define EEPROM12_DEFAULT_CHIP_ENABLE_ADDRESS 0x00
96 
102 #define EEPROM12_DEVICE_ADDRESS_MEMORY 0x50
103 #define EEPROM12_DEVICE_ADDRESS_PAGE 0x58
104  // eeprom12_set
106 
121 #define EEPROM12_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
124  cfg.wc = MIKROBUS( mikrobus, MIKROBUS_PWM )
125  // eeprom12_map // eeprom12
128 
133 typedef struct
134 {
135  // Output pins
136  digital_out_t wc;
138  // Modules
139  i2c_master_t i2c;
141  // I2C slave address
142  uint8_t slave_address;
144  uint8_t chip_en_addr; /* Chip enable address */
145 
146 } eeprom12_t;
147 
152 typedef struct
153 {
154  pin_name_t scl;
155  pin_name_t sda;
157  pin_name_t wc;
159  uint32_t i2c_speed;
160  uint8_t i2c_address;
163 
168 typedef enum
169 {
171  EEPROM12_ERROR = -1
172 
174 
191 
206 
218 
230 
245 err_t eeprom12_generic_write ( eeprom12_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len );
246 
261 err_t eeprom12_generic_read ( eeprom12_t *ctx, uint16_t reg, uint8_t *data_out, uint8_t len );
262 
279 err_t eeprom12_memory_write ( eeprom12_t *ctx, uint16_t mem_addr, uint8_t *data_in, uint8_t len );
280 
297 err_t eeprom12_memory_read ( eeprom12_t *ctx, uint16_t mem_addr, uint8_t *data_out, uint8_t len );
298 
315 err_t eeprom12_memory_page_write ( eeprom12_t *ctx, uint16_t page_addr, uint8_t *data_in, uint8_t len );
316 
333 err_t eeprom12_memory_page_read ( eeprom12_t *ctx, uint16_t page_addr, uint8_t *data_out, uint8_t len );
334 
351 err_t eeprom12_id_page_write ( eeprom12_t *ctx, uint16_t id_page_addr, uint8_t *data_in );
352 
369 err_t eeprom12_id_page_read ( eeprom12_t *ctx, uint16_t id_page_addr, uint8_t *data_out );
370 
390 err_t eeprom12_config_dev_addr ( eeprom12_t *ctx, uint8_t cda, uint8_t dal );
391 
407 err_t eeprom12_read_lock_status ( eeprom12_t *ctx, uint8_t *lock_status );
408 
409 #ifdef __cplusplus
410 }
411 #endif
412 #endif // EEPROM12_H
413  // eeprom12
415 
416 // ------------------------------------------------------------------------ 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:160
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:155
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:142
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:136
eeprom12_return_value_t
eeprom12_return_value_t
EEPROM 12 Click return value data.
Definition: eeprom12.h:169
eeprom12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: eeprom12.h:159
EEPROM12_ERROR
@ EEPROM12_ERROR
Definition: eeprom12.h:171
eeprom12_t::i2c
i2c_master_t i2c
Definition: eeprom12.h:139
eeprom12_cfg_t::wc
pin_name_t wc
Definition: eeprom12.h:157
eeprom12_t
EEPROM 12 Click context object.
Definition: eeprom12.h:134
eeprom12_cfg_t::scl
pin_name_t scl
Definition: eeprom12.h:154
eeprom12_t::chip_en_addr
uint8_t chip_en_addr
Definition: eeprom12.h:144
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:170
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:153
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.