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 )
78#define RFMETER_RETVAL uint8_t
79
80#define RFMETER_OK 0x00
81#define RFMETER_INIT_ERROR 0xFF
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
98 // End group macro
99// --------------------------------------------------------------- PUBLIC TYPES
108typedef 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
122typedef 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
138
139 // End types group
140// ------------------------------------------------------------------ CONSTANTS
148 // End constants group
149// ------------------------------------------------------------------ VARIABLES
156 // End variable group
157// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158
163#ifdef __cplusplus
164extern "C"{
165#endif
166
176
185
195uint16_t rfmeter_read_data ( rfmeter_t *ctx );
196
207
218
230float rfmeter_get_signal_strenght ( rfmeter_t *ctx, float slope, float intercept );
231
232#ifdef __cplusplus
233}
234#endif
235#endif // _RFMETER_H_
236
237 // End public_function group
239
240// ------------------------------------------------------------------------- END
#define RFMETER_RETVAL
Definition rfmeter.h:78
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:123
spi_master_chip_select_polarity_t cs_polarity
Definition rfmeter.h:135
pin_name_t sck
Definition rfmeter.h:128
spi_master_mode_t spi_mode
Definition rfmeter.h:134
pin_name_t mosi
Definition rfmeter.h:127
uint32_t spi_speed
Definition rfmeter.h:133
pin_name_t miso
Definition rfmeter.h:126
pin_name_t cs
Definition rfmeter.h:129
Click ctx object definition.
Definition rfmeter.h:109
digital_out_t cs
Definition rfmeter.h:110
spi_master_t spi
Definition rfmeter.h:114
pin_name_t chip_select
Definition rfmeter.h:115