ookrx  2.1.0.0
ookrx.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 OOKRX_H
29 #define OOKRX_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_analog_in.h"
48 
69 #define OOKRX_RSSI_VREF_3V3 3.3f
70 #define OOKRX_RSSI_MIN_DBM ( -110 )
71 #define OOKRX_RSSI_MAX_DBM ( -50 )
72 #define OOKRX_RSSI_RANGE_DBM ( OOKRX_RSSI_MAX_DBM - OOKRX_RSSI_MIN_DBM )
73 #define OOKRX_RSSI_MIN_V 0.4f
74 #define OOKRX_RSSI_MAX_V 2.06f
75 #define OOKRX_RSSI_RANGE_V ( OOKRX_RSSI_MAX_V - OOKRX_RSSI_MIN_V )
76 #define OOKRX_RSSI_DBM_PER_V ( OOKRX_RSSI_RANGE_DBM / OOKRX_RSSI_MAX_V )
77 #define OOKRX_RSSI_V_TO_DBM(x) ( OOKRX_RSSI_MIN_DBM + ( ( x - OOKRX_RSSI_MIN_V ) * OOKRX_RSSI_DBM_PER_V ) )
78 #define OOKRX_MAN_BIT_LEN_US 2000
79 #define OOKRX_MAX_DATA_LEN 255
80  // ookrx_cfg
82 
97 #define OOKRX_MAP_MIKROBUS( cfg, mikrobus ) \
98  cfg.rssi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
99  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
100  cfg.sqc = MIKROBUS( mikrobus, MIKROBUS_CS ); \
101  cfg.dout = MIKROBUS( mikrobus, MIKROBUS_INT )
102  // ookrx_map // ookrx
105 
110 typedef struct
111 {
112  digital_out_t en;
113  digital_out_t sqc;
115  digital_in_t dout;
117  analog_in_t adc;
119 } ookrx_t;
120 
125 typedef struct
126 {
127  pin_name_t rssi;
128  pin_name_t en;
129  pin_name_t sqc;
130  pin_name_t dout;
132  analog_in_resolution_t resolution;
133  float vref;
135 } ookrx_cfg_t;
136 
141 typedef enum
142 {
143  OOKRX_OK = 0,
144  OOKRX_ERROR = -1
145 
147 
164 
178 err_t ookrx_init ( ookrx_t *ctx, ookrx_cfg_t *cfg );
179 
189 
199 
209 
219 
228 uint8_t ookrx_get_data_pin ( ookrx_t *ctx );
229 
243 err_t ookrx_read_rssi_voltage ( ookrx_t *ctx, float *data_out );
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 #endif // OOKRX_H
249  // ookrx
251 
252 // ------------------------------------------------------------------------ END
ookrx_t
OOK RX Click context object.
Definition: ookrx.h:111
ookrx_cfg_t
OOK RX Click configuration object.
Definition: ookrx.h:126
ookrx_init
err_t ookrx_init(ookrx_t *ctx, ookrx_cfg_t *cfg)
OOK RX initialization function.
ookrx_get_data_pin
uint8_t ookrx_get_data_pin(ookrx_t *ctx)
OOK RX get data pin function.
ookrx_cfg_t::rssi
pin_name_t rssi
Definition: ookrx.h:127
ookrx_cfg_t::sqc
pin_name_t sqc
Definition: ookrx.h:129
ookrx_disable_device
void ookrx_disable_device(ookrx_t *ctx)
OOK RX disable device function.
OOKRX_OK
@ OOKRX_OK
Definition: ookrx.h:143
ookrx_t::dout
digital_in_t dout
Definition: ookrx.h:115
ookrx_t::adc
analog_in_t adc
Definition: ookrx.h:117
ookrx_cfg_t::en
pin_name_t en
Definition: ookrx.h:128
ookrx_disable_squelch
void ookrx_disable_squelch(ookrx_t *ctx)
OOK RX disable squelch function.
ookrx_enable_device
void ookrx_enable_device(ookrx_t *ctx)
OOK RX enable device function.
OOKRX_ERROR
@ OOKRX_ERROR
Definition: ookrx.h:144
ookrx_cfg_t::vref
float vref
Definition: ookrx.h:133
ookrx_enable_squelch
void ookrx_enable_squelch(ookrx_t *ctx)
OOK RX enable squelch function.
ookrx_t::en
digital_out_t en
Definition: ookrx.h:112
ookrx_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ookrx.h:132
ookrx_return_value_t
ookrx_return_value_t
OOK RX Click return value data.
Definition: ookrx.h:142
ookrx_read_rssi_voltage
err_t ookrx_read_rssi_voltage(ookrx_t *ctx, float *data_out)
OOK RX read RSSI pin voltage level function.
ookrx_cfg_setup
void ookrx_cfg_setup(ookrx_cfg_t *cfg)
OOK RX configuration object setup function.
ookrx_t::sqc
digital_out_t sqc
Definition: ookrx.h:113
ookrx_cfg_t::dout
pin_name_t dout
Definition: ookrx.h:130