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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define QIRX_RESOLUTION 4096
70 #define QIRX_12_BIT_DATA 0x0FFF
71 
76 #define QIRX_SET_DEV_ADDR 0x4D
77  // qirx_set
79 
94 #define QIRX_MAP_MIKROBUS( cfg, mikrobus ) \
95  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
96  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
97  // qirx_map // qirx
100 
105 typedef struct
106 {
107  // Modules
108  i2c_master_t i2c;
110  // I2C slave address
111  uint8_t slave_address;
113 } qirx_t;
114 
119 typedef struct
120 {
121  pin_name_t scl;
122  pin_name_t sda;
124  uint32_t i2c_speed;
125  uint8_t i2c_address;
127 } qirx_cfg_t;
128 
133 typedef enum
134 {
135  QIRX_OK = 0,
136  QIRX_ERROR = -1
137 
139 
156 
171 err_t qirx_init ( qirx_t *ctx, qirx_cfg_t *cfg );
172 
180 uint16_t qirx_read_data ( qirx_t *ctx );
181 
190 uint16_t qirx_read_voltage ( qirx_t *ctx, uint16_t v_ref );
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 #endif // QIRX_H
196  // qirx
198 
199 // ------------------------------------------------------------------------ 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:124
qirx_t::i2c
i2c_master_t i2c
Definition: qirx.h:108
qirx_t
Qi RX Click context object.
Definition: qirx.h:106
qirx_cfg_t::sda
pin_name_t sda
Definition: qirx.h:122
QIRX_ERROR
@ QIRX_ERROR
Definition: qirx.h:136
qirx_cfg_t::scl
pin_name_t scl
Definition: qirx.h:121
qirx_cfg_t
Qi RX Click configuration object.
Definition: qirx.h:120
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:111
qirx_cfg_t::i2c_address
uint8_t i2c_address
Definition: qirx.h:125
qirx_return_value_t
qirx_return_value_t
Qi RX Click return value data.
Definition: qirx.h:134
QIRX_OK
@ QIRX_OK
Definition: qirx.h:135
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.