force4  2.0.0.0
force4.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 FORCE4_H
36 #define FORCE4_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 FORCE4_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
56 
62 #define FORCE4_RETVAL uint8_t
63 
64 #define FORCE4_OK 0x00
65 #define FORCE4_INIT_ERROR 0xFF
66 
72 #define FORCE4_SLAVE_ADDRES 0x4D
73  // End group macro
76 // --------------------------------------------------------------- PUBLIC TYPES
85 typedef struct
86 {
87  // Output pins
88 
89  digital_out_t an;
90 
91  // Modules
92 
93  i2c_master_t i2c;
94 
95  // ctx variable
96 
97  uint8_t slave_address;
98 
99 } force4_t;
100 
104 typedef struct
105 {
106  // Communication gpio pins
107 
108  pin_name_t scl;
109  pin_name_t sda;
110 
111  // Additional gpio pins
112 
113  pin_name_t an;
114 
115  // static variable
116 
117  uint32_t i2c_speed;
118  uint8_t i2c_address;
119 
120 } force4_cfg_t;
121  // End types group
123 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
124 
130 #ifdef __cplusplus
131 extern "C"{
132 #endif
133 
143 
153 
164 void force4_generic_write ( force4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
165 
176 void force4_generic_read ( force4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
177 
187 uint16_t force4_read_adc ( force4_t *ctx );
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 #endif // _FORCE4_H_
193  // End public_function group
196 
197 // ------------------------------------------------------------------------- END
force4_t::an
digital_out_t an
Definition: force4.h:89
force4_generic_read
void force4_generic_read(force4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
force4_cfg_t::an
pin_name_t an
Definition: force4.h:113
force4_init
FORCE4_RETVAL force4_init(force4_t *ctx, force4_cfg_t *cfg)
Initialization function.
force4_cfg_t
Click configuration structure definition.
Definition: force4.h:105
force4_cfg_t::i2c_address
uint8_t i2c_address
Definition: force4.h:118
force4_cfg_t::scl
pin_name_t scl
Definition: force4.h:108
force4_t::i2c
i2c_master_t i2c
Definition: force4.h:93
force4_read_adc
uint16_t force4_read_adc(force4_t *ctx)
Function for reading 12bit ADC data from device.
force4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: force4.h:117
force4_t
Click ctx object definition.
Definition: force4.h:86
force4_cfg_t::sda
pin_name_t sda
Definition: force4.h:109
force4_generic_write
void force4_generic_write(force4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
force4_cfg_setup
void force4_cfg_setup(force4_cfg_t *cfg)
Config Object Initialization function.
force4_t::slave_address
uint8_t slave_address
Definition: force4.h:97
FORCE4_RETVAL
#define FORCE4_RETVAL
Definition: force4.h:62