rfmeter  2.0.0.0
rfmeter.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef RFMETER_H
36 #define RFMETER_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_spi_master.h"
54 
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
67 #define RFMETER_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
72 
78 #define RFMETER_RETVAL uint8_t
79 
80 #define RFMETER_OK 0x00
81 #define RFMETER_INIT_ERROR 0xFF
82 
88 #define RFMETER_FILTER_USEFULL_DATA 0x1FFE
89 #define RFMETER_ADC_RESOLUTION 4096
90 #define RFMETER_DATA_SAMPLE_NUM 10
91 #define RFMETER_DEF_VREF 2.5
92 #define RFMETER_DEF_SLOPE -0.025
93 #define RFMETER_DEF_INTERCEPT 20.0
94 #define RFMETER_DEF_LIMIT_HIGH 2.0
95 #define RFMETER_DEF_LIMIT_LOW 0.5
96  // End group macro
99 // --------------------------------------------------------------- PUBLIC TYPES
108 typedef struct
109 {
110  digital_out_t cs;
111 
112  // Modules
113 
114  spi_master_t spi;
115  pin_name_t chip_select;
116 
117 } rfmeter_t;
118 
122 typedef struct
123 {
124  // Communication gpio pins
125 
126  pin_name_t miso;
127  pin_name_t mosi;
128  pin_name_t sck;
129  pin_name_t cs;
130 
131  // static variable
132 
133  uint32_t spi_speed;
134  spi_master_mode_t spi_mode;
135  spi_master_chip_select_polarity_t cs_polarity;
136 
137 } rfmeter_cfg_t;
138  // End types group
140 // ------------------------------------------------------------------ CONSTANTS // End constants group
149 // ------------------------------------------------------------------ VARIABLES // End variable group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
163 #ifdef __cplusplus
164 extern "C"{
165 #endif
166 
176 
185 
195 uint16_t rfmeter_read_data ( rfmeter_t *ctx );
196 
206 uint16_t rfmeter_get_raw_data ( rfmeter_t *ctx );
207 
218 
230 float rfmeter_get_signal_strenght ( rfmeter_t *ctx, float slope, float intercept );
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 #endif // _RFMETER_H_
236  // End public_function group
239 
240 // ------------------------------------------------------------------------- END
rfmeter_cfg_t::sck
pin_name_t sck
Definition: rfmeter.h:128
rfmeter_t::chip_select
pin_name_t chip_select
Definition: rfmeter.h:115
rfmeter_get_raw_data
uint16_t rfmeter_get_raw_data(rfmeter_t *ctx)
Get raw data function.
rfmeter_t::spi
spi_master_t spi
Definition: rfmeter.h:114
rfmeter_cfg_setup
void rfmeter_cfg_setup(rfmeter_cfg_t *cfg)
Config Object Initialization function.
rfmeter_init
RFMETER_RETVAL rfmeter_init(rfmeter_t *ctx, rfmeter_cfg_t *cfg)
Initialization function.
rfmeter_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rfmeter.h:134
rfmeter_t
Click ctx object definition.
Definition: rfmeter.h:109
rfmeter_t::cs
digital_out_t cs
Definition: rfmeter.h:110
rfmeter_cfg_t::miso
pin_name_t miso
Definition: rfmeter.h:126
rfmeter_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rfmeter.h:135
rfmeter_get_voltage
float rfmeter_get_voltage(rfmeter_t *ctx)
Get voltage function.
rfmeter_read_data
uint16_t rfmeter_read_data(rfmeter_t *ctx)
Data read function.
rfmeter_cfg_t::spi_speed
uint32_t spi_speed
Definition: rfmeter.h:133
rfmeter_get_signal_strenght
float rfmeter_get_signal_strenght(rfmeter_t *ctx, float slope, float intercept)
Get signal strenght function.
rfmeter_cfg_t::mosi
pin_name_t mosi
Definition: rfmeter.h:127
RFMETER_RETVAL
#define RFMETER_RETVAL
Definition: rfmeter.h:78
rfmeter_cfg_t
Click configuration structure definition.
Definition: rfmeter.h:123
rfmeter_cfg_t::cs
pin_name_t cs
Definition: rfmeter.h:129