sram2  2.0.0.0
sram2.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 SRAM2_H
36 #define SRAM2_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_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define SRAM2_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
70 
76 #define SRAM2_RETVAL uint8_t
77 
78 #define SRAM2_OK 0x00
79 #define SRAM2_INIT_ERROR 0xFF
80 
86 #define SRAM2_WR_ENABLE 0x01
87 #define SRAM2_WR_DISABLE 0x00
88 
94 #define SRAM2_SLAVE_ADDR_0_0 0x51
95 #define SRAM2_SLAVE_ADDR_0_1 0x53
96 #define SRAM2_SLAVE_ADDR_1_0 0x55
97 #define SRAM2_SLAVE_ADDR_1_1 0x57
98  // End group macro
101 // --------------------------------------------------------------- PUBLIC TYPES
110 typedef struct
111 {
112  // Output pins
113 
114  digital_out_t wp;
115 
116  // Modules
117 
118  i2c_master_t i2c;
119 
120  // ctx variable
121 
122  uint8_t slave_address;
123 
124 } sram2_t;
125 
129 typedef struct
130 {
131  // Communication gpio pins
132 
133  pin_name_t scl;
134  pin_name_t sda;
135 
136  // Additional gpio pins
137 
138  pin_name_t wp;
139 
140  // static variable
141 
142  uint32_t i2c_speed;
143  uint8_t i2c_address;
144 
145 } sram2_cfg_t;
146  // End types group
148 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
149 
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
168 
178 
188 void sram2_generic_write ( sram2_t *ctx, uint16_t reg, uint8_t wr_data );
189 
199 void sram2_generic_read ( sram2_t *ctx, uint16_t reg, uint8_t *rx_data );
200 
209 void sram2_write_protect( sram2_t *ctx, uint8_t state );
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 #endif // _SRAM2_H_
215  // End public_function group
218 
219 // ------------------------------------------------------------------------- END
sram2_t::slave_address
uint8_t slave_address
Definition: sram2.h:122
sram2_cfg_t
Click configuration structure definition.
Definition: sram2.h:130
sram2_t
Click ctx object definition.
Definition: sram2.h:111
sram2_cfg_t::scl
pin_name_t scl
Definition: sram2.h:133
sram2_cfg_t::wp
pin_name_t wp
Definition: sram2.h:138
sram2_init
SRAM2_RETVAL sram2_init(sram2_t *ctx, sram2_cfg_t *cfg)
Initialization function.
sram2_cfg_t::sda
pin_name_t sda
Definition: sram2.h:134
sram2_generic_write
void sram2_generic_write(sram2_t *ctx, uint16_t reg, uint8_t wr_data)
Generic write function.
sram2_t::wp
digital_out_t wp
Definition: sram2.h:114
sram2_generic_read
void sram2_generic_read(sram2_t *ctx, uint16_t reg, uint8_t *rx_data)
Generic read function.
sram2_cfg_setup
void sram2_cfg_setup(sram2_cfg_t *cfg)
Config Object Initialization function.
sram2_write_protect
void sram2_write_protect(sram2_t *ctx, uint8_t state)
Set PWM pin for write protection.
sram2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: sram2.h:142
SRAM2_RETVAL
#define SRAM2_RETVAL
Definition: sram2.h:76
sram2_cfg_t::i2c_address
uint8_t i2c_address
Definition: sram2.h:143
sram2_t::i2c
i2c_master_t i2c
Definition: sram2.h:118