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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define SRAM2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
56 
62 #define SRAM2_RETVAL uint8_t
63 
64 #define SRAM2_OK 0x00
65 #define SRAM2_INIT_ERROR 0xFF
66 
72 #define SRAM2_WR_ENABLE 0x01
73 #define SRAM2_WR_DISABLE 0x00
74 
80 #define SRAM2_SLAVE_ADDR_0_0 0x51
81 #define SRAM2_SLAVE_ADDR_0_1 0x53
82 #define SRAM2_SLAVE_ADDR_1_0 0x55
83 #define SRAM2_SLAVE_ADDR_1_1 0x57
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
96 typedef struct
97 {
98  // Output pins
99 
100  digital_out_t wp;
101 
102  // Modules
103 
104  i2c_master_t i2c;
105 
106  // ctx variable
107 
108  uint8_t slave_address;
109 
110 } sram2_t;
111 
115 typedef struct
116 {
117  // Communication gpio pins
118 
119  pin_name_t scl;
120  pin_name_t sda;
121 
122  // Additional gpio pins
123 
124  pin_name_t wp;
125 
126  // static variable
127 
128  uint32_t i2c_speed;
129  uint8_t i2c_address;
130 
131 } sram2_cfg_t;
132  // End types group
134 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
135 
141 #ifdef __cplusplus
142 extern "C"{
143 #endif
144 
153 void sram2_cfg_setup ( sram2_cfg_t *cfg );
154 
164 
174 void sram2_generic_write ( sram2_t *ctx, uint16_t reg, uint8_t wr_data );
175 
185 void sram2_generic_read ( sram2_t *ctx, uint16_t reg, uint8_t *rx_data );
186 
195 void sram2_write_protect( sram2_t *ctx, uint8_t state );
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 #endif // _SRAM2_H_
201  // End public_function group
204 
205 // ------------------------------------------------------------------------- END
sram2_t::slave_address
uint8_t slave_address
Definition: sram2.h:108
sram2_cfg_t
Click configuration structure definition.
Definition: sram2.h:115
sram2_t
Click ctx object definition.
Definition: sram2.h:96
sram2_cfg_t::scl
pin_name_t scl
Definition: sram2.h:119
sram2_cfg_t::wp
pin_name_t wp
Definition: sram2.h:124
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:120
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:100
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:128
SRAM2_RETVAL
#define SRAM2_RETVAL
Definition: sram2.h:62
sram2_cfg_t::i2c_address
uint8_t i2c_address
Definition: sram2.h:129
sram2_t::i2c
i2c_master_t i2c
Definition: sram2.h:104