eeprom4 2.0.0.0
eeprom4.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 EEPROM4_H
36#define EEPROM4_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_spi_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
56
67#define EEPROM4_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
73 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM )
80#define EEPROM4_RETVAL uint8_t
82#define EEPROM4_OK 0x00
83#define EEPROM4_INIT_ERROR 0xFF
90#define EEPROM4_LOGIC_HIGH 1
91#define EEPROM4_LOGIC_LOW 0
98#define EEPROM4_READY_BIT 0x01
99#define EEPROM4_WRITE_ENABLE_LATCH_BIT 0x02
100#define EEPROM4_WRITE_PROTECT_ENABLE_BIT 0x80
107#define EEPROM4_LOW_POWER_WRITE_POLL_COMMAND 0x08
108#define EEPROM4_SET_WRITE_ENABLE_LATCH_COMMAND 0x06
109#define EEPROM4_RESET_WRITE_ENABLE_LATCH_COMMAND 0x04
116#define EEPROM4_FIRST_MEMORY_LOCATION 0x00000000
117#define EEPROM4_ONE_QUARTER_MEMORY_LOCATION 0x0000FFFF
118#define EEPROM4_HALF_MEMORY_LOCATION 0x0001FFFF
119#define EEPROM4_TWO_QUARTER_MEMORY_LOCATION 0x0002FFFF
120#define EEPROM4_LAST_MEMORY_LOCATION 0x0003FFFF
127#define EEPROM4_NONE_PROTECTED_MEMORY_LOCATION 0x00
128#define EEPROM4_ONE_QUARTER_PROTECTED_MEMORY_LOCATION 0x04
129#define EEPROM4_HALF_PROTECTED_MEMORY_LOCATION 0x08
130#define EEPROM4_ALL_PROTECTED_MEMORY_LOCATION 0x0C
133 // End group macro
134// --------------------------------------------------------------- PUBLIC TYPES
143typedef struct
144{
145 // Output pins
146
147 digital_out_t cs;
148 digital_out_t wp;
149 digital_out_t hld;
150
151 // Modules
152
153 spi_master_t spi;
154 pin_name_t chip_select;
155
156} eeprom4_t;
157
161typedef struct
162{
163 // Communication gpio pins
164
165 pin_name_t miso;
166 pin_name_t mosi;
167 pin_name_t sck;
168 pin_name_t cs;
169
170 // Additional gpio pins
171
172 pin_name_t wp;
173 pin_name_t hld;
174
175 // static variable
176
177 uint32_t spi_speed;
178 spi_master_mode_t spi_mode;
179 spi_master_chip_select_polarity_t cs_polarity;
180
182
183 // End types group
184// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
185
190#ifdef __cplusplus
191extern "C"{
192#endif
193
203
213
222
234void eeprom4_generic_transfer ( eeprom4_t *ctx, uint8_t *wr_buf,
235 uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
236
248uint8_t eeprom4_send_command ( eeprom4_t *ctx, uint8_t command_byte );
249
259void eeprom4_write_status_reg ( eeprom4_t *ctx, uint8_t data_value );
260
269
281void eeprom4_write_memory ( eeprom4_t *ctx, uint32_t memory_address, uint8_t *data_input, uint8_t n_bytes );
282
294void eeprom4_read_memory ( eeprom4_t *ctx, uint32_t memory_address, uint8_t *data_output, uint8_t n_bytes );
295
306void eeprom4_enable_write_protect ( eeprom4_t *ctx, uint8_t state );
307
317void eeprom4_enable_hold_operation ( eeprom4_t *ctx, uint8_t state );
318
327uint8_t eeprom4_check_status_reg ( eeprom4_t *ctx, uint8_t check_bit );
328
329
330#ifdef __cplusplus
331}
332#endif
333#endif // _EEPROM4_H_
334
335 // End public_function group
337
338// ------------------------------------------------------------------------- END
#define EEPROM4_RETVAL
Definition eeprom4.h:80
void eeprom4_enable_write_protect(eeprom4_t *ctx, uint8_t state)
Write Protect enable function.
void eeprom4_read_memory(eeprom4_t *ctx, uint32_t memory_address, uint8_t *data_output, uint8_t n_bytes)
Memory array read function.
void eeprom4_default_cfg(eeprom4_t *ctx)
Click Default Configuration function.
void eeprom4_write_status_reg(eeprom4_t *ctx, uint8_t data_value)
Status register write function.
void eeprom4_generic_transfer(eeprom4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
uint8_t eeprom4_check_status_reg(eeprom4_t *ctx, uint8_t check_bit)
Status register bits check function.
void eeprom4_cfg_setup(eeprom4_cfg_t *cfg)
Config Object Initialization function.
void eeprom4_write_memory(eeprom4_t *ctx, uint32_t memory_address, uint8_t *data_input, uint8_t n_bytes)
Memory array write function.
uint8_t eeprom4_read_status_reg(eeprom4_t *ctx)
Status register read function.
uint8_t eeprom4_send_command(eeprom4_t *ctx, uint8_t command_byte)
Command send function.
EEPROM4_RETVAL eeprom4_init(eeprom4_t *ctx, eeprom4_cfg_t *cfg)
Initialization function.
void eeprom4_enable_hold_operation(eeprom4_t *ctx, uint8_t state)
Hold operation enable function.
Click configuration structure definition.
Definition eeprom4.h:162
pin_name_t hld
Definition eeprom4.h:173
spi_master_chip_select_polarity_t cs_polarity
Definition eeprom4.h:179
pin_name_t sck
Definition eeprom4.h:167
spi_master_mode_t spi_mode
Definition eeprom4.h:178
pin_name_t mosi
Definition eeprom4.h:166
uint32_t spi_speed
Definition eeprom4.h:177
pin_name_t wp
Definition eeprom4.h:172
pin_name_t miso
Definition eeprom4.h:165
pin_name_t cs
Definition eeprom4.h:168
Click ctx object definition.
Definition eeprom4.h:144
digital_out_t cs
Definition eeprom4.h:147
digital_out_t hld
Definition eeprom4.h:149
spi_master_t spi
Definition eeprom4.h:153
pin_name_t chip_select
Definition eeprom4.h:154
digital_out_t wp
Definition eeprom4.h:148