rmeter 2.0.0.0
rmeter.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
34#ifndef RMETER_H
35#define RMETER_H
36
41#ifdef PREINIT_SUPPORTED
42#include "preinit.h"
43#endif
44
45#ifdef MikroCCoreVersion
46 #if MikroCCoreVersion >= 1
47 #include "delays.h"
48 #endif
49#endif
50
51#include "drv_digital_out.h"
52#include "drv_analog_in.h"
53#include "drv_spi_master.h"
54
64#define RMETER_MAP_MIKROBUS( cfg, mikrobus ) \
65 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ) ; \
68 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ) ; \
69 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ) ; \
70 cfg.s3 = MIKROBUS( mikrobus, MIKROBUS_RST ) ; \
71 cfg.s2 = MIKROBUS( mikrobus, MIKROBUS_INT ) ; \
72 cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_PWM )
79#define RMETER_OK 0
80#define RMETER_INIT_ERROR (-1)
83 // End group macro
84
93typedef void ( *rmeter_callback_t )( char* );
94
98typedef struct
99{
100 // Auto scale control pins objects.
101
102 digital_out_t s3;
103 digital_out_t s2;
104 digital_out_t s1;
105
106 // Analog input pin object.
107
108 analog_in_t an;
109
110 // Communication module object.
111
112 spi_master_t spi;
113
114 pin_name_t chip_select;
115
116 // R Meter calculation operands.
117
118 float ifb;
120 // Callback handler.
121
123
124} rmeter_t;
125
129typedef struct
130{
131 // Communication pins descriptors.
132
133 pin_name_t miso;
134 pin_name_t mosi;
135 pin_name_t sck;
136 pin_name_t cs;
137
138 // Additional pins descriptors.
139
140 pin_name_t an;
141 pin_name_t s3;
142 pin_name_t s2;
143 pin_name_t s1;
144
145 // Module configuration settings.
146
147 uint32_t spi_speed;
148 spi_master_mode_t spi_mode;
149 spi_master_chip_select_polarity_t cs_polarity;
150
151 // ADC settings.
152
153 analog_in_resolution_t adc_resolution;
154 float adc_vref;
157
158 // End types group
159
165#ifdef __cplusplus
166extern "C"{
167#endif
168
178
189err_t rmeter_init ( rmeter_t *ctx, rmeter_cfg_t *cfg );
190
200
209
218
227
238err_t rmeter_read_measurement ( rmeter_t *ctx, uint16_t *data_out );
239
254err_t rmeter_calculate_resistance ( rmeter_t *ctx, float *data_out, uint16_t data_in );
255
266
277err_t rmeter_read_an ( rmeter_t *ctx, uint16_t *data_out );
278
290err_t rmeter_read_an_voltage ( rmeter_t *ctx, float *data_out );
291
292#ifdef __cplusplus
293}
294#endif
295#endif // RMETER_H
296
297 // End public_function group
298 // End click Driver group
299
300// ------------------------------------------------------------------------ END
err_t rmeter_calculate_resistance(rmeter_t *ctx, float *data_out, uint16_t data_in)
Resistance Calculation function.
void rmeter_set_range_up_to_17k_ohms(rmeter_t *ctx)
Range Setup Up To 17k Ohms function.
uint16_t rmeter_auto_scale_range_execution(rmeter_t *ctx)
Auto Scale Range Execution function.
void rmeter_set_range_up_to_1k9_ohms(rmeter_t *ctx)
Range Setup Up To 1k9 Ohms function.
err_t rmeter_read_an_voltage(rmeter_t *ctx, float *data_out)
AN Voltage Level Reading function.
void rmeter_cfg_setup(rmeter_cfg_t *cfg)
Config Object Setup function.
void rmeter_set_range_up_to_1M9_ohms(rmeter_t *ctx)
Range Setup Up To 1M9 Ohms function.
void rmeter_set_callback_handler(rmeter_t *ctx, rmeter_callback_t handler)
Callback Handler Setup function.
err_t rmeter_init(rmeter_t *ctx, rmeter_cfg_t *cfg)
Initialization function.
err_t rmeter_read_measurement(rmeter_t *ctx, uint16_t *data_out)
Measurement Reading function.
err_t rmeter_read_an(rmeter_t *ctx, uint16_t *data_out)
AN Pin Reading function.
void(* rmeter_callback_t)(char *)
Click callback handler definition.
Definition rmeter.h:93
Click configuration structure definition.
Definition rmeter.h:130
pin_name_t s2
Definition rmeter.h:142
pin_name_t s3
Definition rmeter.h:141
spi_master_chip_select_polarity_t cs_polarity
Definition rmeter.h:149
pin_name_t sck
Definition rmeter.h:135
pin_name_t s1
Definition rmeter.h:143
spi_master_mode_t spi_mode
Definition rmeter.h:148
float adc_vref
Definition rmeter.h:154
analog_in_resolution_t adc_resolution
Definition rmeter.h:153
pin_name_t mosi
Definition rmeter.h:134
uint32_t spi_speed
Definition rmeter.h:147
pin_name_t miso
Definition rmeter.h:133
pin_name_t an
Definition rmeter.h:140
pin_name_t cs
Definition rmeter.h:136
Click ctx object definition.
Definition rmeter.h:99
spi_master_t spi
Definition rmeter.h:112
digital_out_t s3
Definition rmeter.h:102
float ifb
Definition rmeter.h:118
digital_out_t s2
Definition rmeter.h:103
digital_out_t s1
Definition rmeter.h:104
rmeter_callback_t callback
Definition rmeter.h:122
analog_in_t an
Definition rmeter.h:108
pin_name_t chip_select
Definition rmeter.h:114