qirx  2.0.0.0
qirx.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef QIRX_H
29 #define QIRX_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define QIRX_RESOLUTION 4096
74 #define QIRX_12_BIT_DATA 0x0FFF
75 
80 #define QIRX_SET_DEV_ADDR 0x4D
81  // qirx_set
83 
98 #define QIRX_MAP_MIKROBUS( cfg, mikrobus ) \
99  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
100  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
101  // qirx_map // qirx
104 
109 typedef struct
110 {
111  // Modules
112  i2c_master_t i2c;
114  // I2C slave address
115  uint8_t slave_address;
117 } qirx_t;
118 
123 typedef struct
124 {
125  pin_name_t scl;
126  pin_name_t sda;
128  uint32_t i2c_speed;
129  uint8_t i2c_address;
131 } qirx_cfg_t;
132 
137 typedef enum
138 {
139  QIRX_OK = 0,
140  QIRX_ERROR = -1
141 
143 
160 
175 err_t qirx_init ( qirx_t *ctx, qirx_cfg_t *cfg );
176 
184 uint16_t qirx_read_data ( qirx_t *ctx );
185 
194 uint16_t qirx_read_voltage ( qirx_t *ctx, uint16_t v_ref );
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 #endif // QIRX_H
200  // qirx
202 
203 // ------------------------------------------------------------------------ END
qirx_cfg_setup
void qirx_cfg_setup(qirx_cfg_t *cfg)
Qi RX configuration object setup function.
qirx_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: qirx.h:128
qirx_t::i2c
i2c_master_t i2c
Definition: qirx.h:112
qirx_t
Qi RX Click context object.
Definition: qirx.h:110
qirx_cfg_t::sda
pin_name_t sda
Definition: qirx.h:126
QIRX_ERROR
@ QIRX_ERROR
Definition: qirx.h:140
qirx_cfg_t::scl
pin_name_t scl
Definition: qirx.h:125
qirx_cfg_t
Qi RX Click configuration object.
Definition: qirx.h:124
v_ref
uint16_t v_ref
Definition: main.c:29
qirx_read_voltage
uint16_t qirx_read_voltage(qirx_t *ctx, uint16_t v_ref)
Read voltage function.
qirx_t::slave_address
uint8_t slave_address
Definition: qirx.h:115
qirx_cfg_t::i2c_address
uint8_t i2c_address
Definition: qirx.h:129
qirx_return_value_t
qirx_return_value_t
Qi RX Click return value data.
Definition: qirx.h:138
QIRX_OK
@ QIRX_OK
Definition: qirx.h:139
qirx_read_data
uint16_t qirx_read_data(qirx_t *ctx)
Read data function.
qirx_init
err_t qirx_init(qirx_t *ctx, qirx_cfg_t *cfg)
Qi RX initialization function.