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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_spi_master.h"
50 
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define RFMETER_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
74 #define RFMETER_RETVAL uint8_t
75 
76 #define RFMETER_OK 0x00
77 #define RFMETER_INIT_ERROR 0xFF
78 
84 #define RFMETER_FILTER_USEFULL_DATA 0x1FFE
85 #define RFMETER_ADC_RESOLUTION 4096
86 #define RFMETER_DATA_SAMPLE_NUM 10
87 #define RFMETER_DEF_VREF 2.5
88 #define RFMETER_DEF_SLOPE -0.025
89 #define RFMETER_DEF_INTERCEPT 20.0
90 #define RFMETER_DEF_LIMIT_HIGH 2.0
91 #define RFMETER_DEF_LIMIT_LOW 0.5
92  // End group macro
95 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef struct
105 {
106  digital_out_t cs;
107 
108  // Modules
109 
110  spi_master_t spi;
111  pin_name_t chip_select;
112 
113 } rfmeter_t;
114 
118 typedef struct
119 {
120  // Communication gpio pins
121 
122  pin_name_t miso;
123  pin_name_t mosi;
124  pin_name_t sck;
125  pin_name_t cs;
126 
127  // static variable
128 
129  uint32_t spi_speed;
130  spi_master_mode_t spi_mode;
131  spi_master_chip_select_polarity_t cs_polarity;
132 
133 } rfmeter_cfg_t;
134  // End types group
136 // ------------------------------------------------------------------ CONSTANTS // End constants group
145 // ------------------------------------------------------------------ VARIABLES // End variable group
153 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154 
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
172 
181 
191 uint16_t rfmeter_read_data ( rfmeter_t *ctx );
192 
202 uint16_t rfmeter_get_raw_data ( rfmeter_t *ctx );
203 
214 
226 float rfmeter_get_signal_strenght ( rfmeter_t *ctx, float slope, float intercept );
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 #endif // _RFMETER_H_
232  // End public_function group
235 
236 // ------------------------------------------------------------------------- END
rfmeter_cfg_t::sck
pin_name_t sck
Definition: rfmeter.h:124
rfmeter_t::chip_select
pin_name_t chip_select
Definition: rfmeter.h:111
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:110
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:130
rfmeter_t
Click ctx object definition.
Definition: rfmeter.h:105
rfmeter_t::cs
digital_out_t cs
Definition: rfmeter.h:106
rfmeter_cfg_t::miso
pin_name_t miso
Definition: rfmeter.h:122
rfmeter_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rfmeter.h:131
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:129
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:123
RFMETER_RETVAL
#define RFMETER_RETVAL
Definition: rfmeter.h:74
rfmeter_cfg_t
Click configuration structure definition.
Definition: rfmeter.h:119
rfmeter_cfg_t::cs
pin_name_t cs
Definition: rfmeter.h:125