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 "drv_digital_out.h"
39#include "drv_spi_master.h"
40
41
42// -------------------------------------------------------------- PUBLIC MACROS
53#define RFMETER_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
64#define RFMETER_RETVAL uint8_t
65
66#define RFMETER_OK 0x00
67#define RFMETER_INIT_ERROR 0xFF
74#define RFMETER_FILTER_USEFULL_DATA 0x1FFE
75#define RFMETER_ADC_RESOLUTION 4096
76#define RFMETER_DATA_SAMPLE_NUM 10
77#define RFMETER_DEF_VREF 2.5
78#define RFMETER_DEF_SLOPE -0.025
79#define RFMETER_DEF_INTERCEPT 20.0
80#define RFMETER_DEF_LIMIT_HIGH 2.0
81#define RFMETER_DEF_LIMIT_LOW 0.5 // End group macro
85// --------------------------------------------------------------- PUBLIC TYPES
94typedef struct
95{
96 digital_out_t cs;
97
98 // Modules
99
100 spi_master_t spi;
101 pin_name_t chip_select;
102
103} rfmeter_t;
104
108typedef struct
109{
110 // Communication gpio pins
111
112 pin_name_t miso;
113 pin_name_t mosi;
114 pin_name_t sck;
115 pin_name_t cs;
116
117 // static variable
118
119 uint32_t spi_speed;
120 spi_master_mode_t spi_mode;
121 spi_master_chip_select_polarity_t cs_polarity;
122
124 // End types group
126// ------------------------------------------------------------------ CONSTANTS // End constants group
135// ------------------------------------------------------------------ VARIABLES // End variable group
143// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
144
149#ifdef __cplusplus
150extern "C"{
151#endif
152
162
171
181uint16_t rfmeter_read_data ( rfmeter_t *ctx );
182
193
204
216float rfmeter_get_signal_strenght ( rfmeter_t *ctx, float slope, float intercept );
217
218#ifdef __cplusplus
219}
220#endif
221#endif // _RFMETER_H_
222 // End public_function group
225
226// ------------------------------------------------------------------------- END
#define RFMETER_RETVAL
Definition: rfmeter.h:64
void rfmeter_cfg_setup(rfmeter_cfg_t *cfg)
Config Object Initialization function.
uint16_t rfmeter_read_data(rfmeter_t *ctx)
Data read function.
RFMETER_RETVAL rfmeter_init(rfmeter_t *ctx, rfmeter_cfg_t *cfg)
Initialization function.
float rfmeter_get_voltage(rfmeter_t *ctx)
Get voltage function.
float rfmeter_get_signal_strenght(rfmeter_t *ctx, float slope, float intercept)
Get signal strenght function.
uint16_t rfmeter_get_raw_data(rfmeter_t *ctx)
Get raw data function.
Click configuration structure definition.
Definition: rfmeter.h:109
spi_master_chip_select_polarity_t cs_polarity
Definition: rfmeter.h:121
pin_name_t sck
Definition: rfmeter.h:114
spi_master_mode_t spi_mode
Definition: rfmeter.h:120
pin_name_t mosi
Definition: rfmeter.h:113
uint32_t spi_speed
Definition: rfmeter.h:119
pin_name_t miso
Definition: rfmeter.h:112
pin_name_t cs
Definition: rfmeter.h:115
Click ctx object definition.
Definition: rfmeter.h:95
digital_out_t cs
Definition: rfmeter.h:96
spi_master_t spi
Definition: rfmeter.h:100
pin_name_t chip_select
Definition: rfmeter.h:101