eeprom2 2.0.0.0
eeprom2.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 EEPROM2_H
36#define EEPROM2_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_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define EEPROM2_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 )
78#define EEPROM2_OK 0
79#define EEPROM2_ERROR -1
82 // End group macro
83// --------------------------------------------------------------- PUBLIC TYPES
92typedef struct
93{
94 digital_out_t cs;
95
96 // Modules
97
98 spi_master_t spi;
99 pin_name_t chip_select;
100
101} eeprom2_t;
102
106typedef struct
107{
108 // Communication gpio pins
109
110 pin_name_t miso;
111 pin_name_t mosi;
112 pin_name_t sck;
113 pin_name_t cs;
114
115 // static variable
116
117 uint32_t spi_speed;
118 spi_master_mode_t spi_mode;
119 spi_master_chip_select_polarity_t cs_polarity;
120
122
123 // End types group
124
125// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
126
131#ifdef __cplusplus
132extern "C"{
133#endif
134
144
154
164void eeprom2_write ( eeprom2_t *ctx, uint32_t memory_address, uint8_t value );
165
176void eeprom2_write_bytes( eeprom2_t *ctx, uint32_t memory_address, uint8_t *value, uint8_t count );
177
187uint8_t eeprom2_read( eeprom2_t *ctx, uint32_t memory_address );
188
199void eeprom2_read_bytes( eeprom2_t *ctx, uint32_t memory_address, uint8_t *value, uint8_t count );
200
209
218
219#ifdef __cplusplus
220}
221#endif
222#endif // _EEPROM2_H_
223
224 // End public_function group
226
227// ------------------------------------------------------------------------- END
void eeprom2_memory_disable(eeprom2_t *ctx)
Disable EEPROM memory.
void eeprom2_write(eeprom2_t *ctx, uint32_t memory_address, uint8_t value)
Generic write function.
void eeprom2_write_bytes(eeprom2_t *ctx, uint32_t memory_address, uint8_t *value, uint8_t count)
Function to write bytes.
void eeprom2_cfg_setup(eeprom2_cfg_t *cfg)
Config Object Initialization function.
void eeprom2_memory_enable(eeprom2_t *ctx)
Enable EEPROM memory.
uint8_t eeprom2_read(eeprom2_t *ctx, uint32_t memory_address)
Generic read function.
err_t eeprom2_init(eeprom2_t *ctx, eeprom2_cfg_t *cfg)
Initialization function.
void eeprom2_read_bytes(eeprom2_t *ctx, uint32_t memory_address, uint8_t *value, uint8_t count)
Function to read bytes.
Click configuration structure definition.
Definition eeprom2.h:107
spi_master_chip_select_polarity_t cs_polarity
Definition eeprom2.h:119
pin_name_t sck
Definition eeprom2.h:112
spi_master_mode_t spi_mode
Definition eeprom2.h:118
pin_name_t mosi
Definition eeprom2.h:111
uint32_t spi_speed
Definition eeprom2.h:117
pin_name_t miso
Definition eeprom2.h:110
pin_name_t cs
Definition eeprom2.h:113
Click ctx object definition.
Definition eeprom2.h:93
digital_out_t cs
Definition eeprom2.h:94
spi_master_t spi
Definition eeprom2.h:98
pin_name_t chip_select
Definition eeprom2.h:99