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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define EEPROM2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
58 
64 #define EEPROM2_RETVAL uint8_t
65 
66 #define EEPROM2_OK 0x00
67 #define EEPROM2_INIT_ERROR 0xFF
68  // End group macro
71 // --------------------------------------------------------------- PUBLIC TYPES
80 typedef struct
81 {
82  digital_out_t cs;
83 
84  // Modules
85 
86  spi_master_t spi;
87  pin_name_t chip_select;
88 
89 } eeprom2_t;
90 
94 typedef struct
95 {
96  // Communication gpio pins
97 
98  pin_name_t miso;
99  pin_name_t mosi;
100  pin_name_t sck;
101  pin_name_t cs;
102 
103  // static variable
104 
105  uint32_t spi_speed;
106  spi_master_mode_t spi_mode;
107  spi_master_chip_select_polarity_t cs_polarity;
108 
109 } eeprom2_cfg_t;
110  // End types group
112 
113 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
114 
119 #ifdef __cplusplus
120 extern "C"{
121 #endif
122 
131 void eeprom2_cfg_setup ( eeprom2_cfg_t *cfg );
132 
142 
152 void eeprom2_write ( eeprom2_t *ctx, uint32_t memory_address, uint8_t value );
153 
164 void eeprom2_write_bytes( eeprom2_t *ctx, uint32_t memory_address, uint8_t *value, uint8_t count );
165 
175 uint8_t eeprom2_read( eeprom2_t *ctx, uint32_t memory_address );
176 
187 void eeprom2_read_bytes( eeprom2_t *ctx, uint32_t memory_address, uint8_t *value, uint8_t count );
188 
196 void eeprom2_memory_enable ( eeprom2_t *ctx );
197 
205 void eeprom2_memory_disable ( eeprom2_t *ctx );
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 #endif // _EEPROM2_H_
211  // End public_function group
214 
215 // ------------------------------------------------------------------------- END
eeprom2_cfg_t::sck
pin_name_t sck
Definition: eeprom2.h:100
eeprom2_write_bytes
void eeprom2_write_bytes(eeprom2_t *ctx, uint32_t memory_address, uint8_t *value, uint8_t count)
Function to write bytes.
eeprom2_cfg_t::mosi
pin_name_t mosi
Definition: eeprom2.h:99
eeprom2_memory_enable
void eeprom2_memory_enable(eeprom2_t *ctx)
Enable EEPROM memory.
eeprom2_t::cs
digital_out_t cs
Definition: eeprom2.h:82
eeprom2_t
Click ctx object definition.
Definition: eeprom2.h:80
eeprom2_t::chip_select
pin_name_t chip_select
Definition: eeprom2.h:87
eeprom2_cfg_t::miso
pin_name_t miso
Definition: eeprom2.h:98
eeprom2_cfg_t::spi_speed
uint32_t spi_speed
Definition: eeprom2.h:105
eeprom2_memory_disable
void eeprom2_memory_disable(eeprom2_t *ctx)
Disable EEPROM memory.
eeprom2_cfg_t::cs
pin_name_t cs
Definition: eeprom2.h:101
eeprom2_cfg_setup
void eeprom2_cfg_setup(eeprom2_cfg_t *cfg)
Config Object Initialization function.
eeprom2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: eeprom2.h:107
eeprom2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: eeprom2.h:106
eeprom2_cfg_t
Click configuration structure definition.
Definition: eeprom2.h:94
EEPROM2_RETVAL
#define EEPROM2_RETVAL
Definition: eeprom2.h:64
eeprom2_t::spi
spi_master_t spi
Definition: eeprom2.h:86
eeprom2_init
EEPROM2_RETVAL eeprom2_init(eeprom2_t *ctx, eeprom2_cfg_t *cfg)
Initialization function.
eeprom2_read
uint8_t eeprom2_read(eeprom2_t *ctx, uint32_t memory_address)
Generic read function.
eeprom2_read_bytes
void eeprom2_read_bytes(eeprom2_t *ctx, uint32_t memory_address, uint8_t *value, uint8_t count)
Function to read bytes.
eeprom2_write
void eeprom2_write(eeprom2_t *ctx, uint32_t memory_address, uint8_t value)
Generic write function.