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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define SRAM2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
66 
72 #define SRAM2_RETVAL uint8_t
73 
74 #define SRAM2_OK 0x00
75 #define SRAM2_INIT_ERROR 0xFF
76 
82 #define SRAM2_WR_ENABLE 0x01
83 #define SRAM2_WR_DISABLE 0x00
84 
90 #define SRAM2_SLAVE_ADDR_0_0 0x51
91 #define SRAM2_SLAVE_ADDR_0_1 0x53
92 #define SRAM2_SLAVE_ADDR_1_0 0x55
93 #define SRAM2_SLAVE_ADDR_1_1 0x57
94  // End group macro
97 // --------------------------------------------------------------- PUBLIC TYPES
106 typedef struct
107 {
108  // Output pins
109 
110  digital_out_t wp;
111 
112  // Modules
113 
114  i2c_master_t i2c;
115 
116  // ctx variable
117 
118  uint8_t slave_address;
119 
120 } sram2_t;
121 
125 typedef struct
126 {
127  // Communication gpio pins
128 
129  pin_name_t scl;
130  pin_name_t sda;
131 
132  // Additional gpio pins
133 
134  pin_name_t wp;
135 
136  // static variable
137 
138  uint32_t i2c_speed;
139  uint8_t i2c_address;
140 
141 } sram2_cfg_t;
142  // End types group
144 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
145 
151 #ifdef __cplusplus
152 extern "C"{
153 #endif
154 
164 
174 
184 void sram2_generic_write ( sram2_t *ctx, uint16_t reg, uint8_t wr_data );
185 
195 void sram2_generic_read ( sram2_t *ctx, uint16_t reg, uint8_t *rx_data );
196 
205 void sram2_write_protect( sram2_t *ctx, uint8_t state );
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 #endif // _SRAM2_H_
211  // End public_function group
214 
215 // ------------------------------------------------------------------------- END
sram2_t::slave_address
uint8_t slave_address
Definition: sram2.h:118
sram2_cfg_t
Click configuration structure definition.
Definition: sram2.h:126
sram2_t
Click ctx object definition.
Definition: sram2.h:107
sram2_cfg_t::scl
pin_name_t scl
Definition: sram2.h:129
sram2_cfg_t::wp
pin_name_t wp
Definition: sram2.h:134
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:130
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:110
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:138
SRAM2_RETVAL
#define SRAM2_RETVAL
Definition: sram2.h:72
sram2_cfg_t::i2c_address
uint8_t i2c_address
Definition: sram2.h:139
sram2_t::i2c
i2c_master_t i2c
Definition: sram2.h:114