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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_analog_in.h"
38 
59 #define OOKRX_RSSI_VREF_3V3 3.3f
60 #define OOKRX_RSSI_MIN_DBM ( -110 )
61 #define OOKRX_RSSI_MAX_DBM ( -50 )
62 #define OOKRX_RSSI_RANGE_DBM ( OOKRX_RSSI_MAX_DBM - OOKRX_RSSI_MIN_DBM )
63 #define OOKRX_RSSI_MIN_V 0.4f
64 #define OOKRX_RSSI_MAX_V 2.06f
65 #define OOKRX_RSSI_RANGE_V ( OOKRX_RSSI_MAX_V - OOKRX_RSSI_MIN_V )
66 #define OOKRX_RSSI_DBM_PER_V ( OOKRX_RSSI_RANGE_DBM / OOKRX_RSSI_MAX_V )
67 #define OOKRX_RSSI_V_TO_DBM(x) ( OOKRX_RSSI_MIN_DBM + ( ( x - OOKRX_RSSI_MIN_V ) * OOKRX_RSSI_DBM_PER_V ) )
68 #define OOKRX_MAN_BIT_LEN_US 2000
69 #define OOKRX_MAX_DATA_LEN 255
70  // ookrx_cfg
72 
87 #define OOKRX_MAP_MIKROBUS( cfg, mikrobus ) \
88  cfg.rssi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
89  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
90  cfg.sqc = MIKROBUS( mikrobus, MIKROBUS_CS ); \
91  cfg.dout = MIKROBUS( mikrobus, MIKROBUS_INT )
92  // ookrx_map // ookrx
95 
100 typedef struct
101 {
102  digital_out_t en;
103  digital_out_t sqc;
105  digital_in_t dout;
107  analog_in_t adc;
109 } ookrx_t;
110 
115 typedef struct
116 {
117  pin_name_t rssi;
118  pin_name_t en;
119  pin_name_t sqc;
120  pin_name_t dout;
122  analog_in_resolution_t resolution;
123  float vref;
125 } ookrx_cfg_t;
126 
131 typedef enum
132 {
133  OOKRX_OK = 0,
134  OOKRX_ERROR = -1
135 
137 
154 
168 err_t ookrx_init ( ookrx_t *ctx, ookrx_cfg_t *cfg );
169 
179 
189 
199 
209 
218 uint8_t ookrx_get_data_pin ( ookrx_t *ctx );
219 
233 err_t ookrx_read_rssi_voltage ( ookrx_t *ctx, float *data_out );
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 #endif // OOKRX_H
239  // ookrx
241 
242 // ------------------------------------------------------------------------ END
ookrx_t
OOK RX Click context object.
Definition: ookrx.h:101
ookrx_cfg_t
OOK RX Click configuration object.
Definition: ookrx.h:116
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:117
ookrx_cfg_t::sqc
pin_name_t sqc
Definition: ookrx.h:119
ookrx_disable_device
void ookrx_disable_device(ookrx_t *ctx)
OOK RX disable device function.
OOKRX_OK
@ OOKRX_OK
Definition: ookrx.h:133
ookrx_t::dout
digital_in_t dout
Definition: ookrx.h:105
ookrx_t::adc
analog_in_t adc
Definition: ookrx.h:107
ookrx_cfg_t::en
pin_name_t en
Definition: ookrx.h:118
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:134
ookrx_cfg_t::vref
float vref
Definition: ookrx.h:123
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:102
ookrx_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ookrx.h:122
ookrx_return_value_t
ookrx_return_value_t
OOK RX Click return value data.
Definition: ookrx.h:132
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:103
ookrx_cfg_t::dout
pin_name_t dout
Definition: ookrx.h:120