current 2.0.0.0
current.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
33// ----------------------------------------------------------------------------
34
35#ifndef CURRENT_H
36#define CURRENT_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 CURRENT_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 CURRENT_RETVAL uint8_t
79
80#define CURRENT_OK 0x00
81#define CURRENT_INIT_ERROR 0xFF
88#define CURRENT_FILTER_USEFULL_DATA 0x0FFF
89#define CURRENT_SAMPLE_NUM 10
96#define CURRENT_RSHUNT_0_05 0.05
97#define CURRENT_RSHUNT_0_2 0.2
98#define CURRENT_RSHUNT_1 1.0
99#define CURRENT_RSHUNT_10 10.0
100#define CURRENT_CAL_COEF 0.025
107#define RFMETER_DEF_LIMIT_HIGH 4096
108#define RFMETER_DEF_LIMIT_LOW 800
109#define CURRENT_OUT_OF_RANGE -1.0
112 // End group macro
113// --------------------------------------------------------------- PUBLIC TYPES
122typedef struct
123{
124 digital_out_t cs;
125
126 // Modules
127
128 spi_master_t spi;
129 pin_name_t chip_select;
130
131} current_t;
132
136typedef struct
137{
138 // Communication gpio pins
139
140 pin_name_t miso;
141 pin_name_t mosi;
142 pin_name_t sck;
143 pin_name_t cs;
144
145 // static variable
146
147 uint32_t spi_speed;
148 spi_master_mode_t spi_mode;
149 spi_master_chip_select_polarity_t cs_polarity;
150
152
153 // End types group
154// ------------------------------------------------------------------ CONSTANTS
162 // End constants group
163// ------------------------------------------------------------------ VARIABLES
170 // End variable group
171// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
172
177#ifdef __cplusplus
178extern "C"{
179#endif
180
190
199
209uint16_t current_data_read ( current_t *ctx );
210
221
233
246float current_get_current_data ( current_t *ctx, float r_hunt );
247
248#ifdef __cplusplus
249}
250#endif
251#endif // _CURRENT_H_
252
253 // End public_function group
255
256// ------------------------------------------------------------------------- END
#define CURRENT_RETVAL
Definition current.h:78
void current_cfg_setup(current_cfg_t *cfg)
Config Object Initialization function.
uint16_t current_get_raw_data(current_t *ctx)
Get raw data function.
float current_avg_rata(current_t *ctx)
Calculate average data function.
uint16_t current_data_read(current_t *ctx)
Data read function.
float current_get_current_data(current_t *ctx, float r_hunt)
Get current value function.
CURRENT_RETVAL current_init(current_t *ctx, current_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition current.h:137
spi_master_chip_select_polarity_t cs_polarity
Definition current.h:149
pin_name_t sck
Definition current.h:142
spi_master_mode_t spi_mode
Definition current.h:148
pin_name_t mosi
Definition current.h:141
uint32_t spi_speed
Definition current.h:147
pin_name_t miso
Definition current.h:140
pin_name_t cs
Definition current.h:143
Click ctx object definition.
Definition current.h:123
digital_out_t cs
Definition current.h:124
spi_master_t spi
Definition current.h:128
pin_name_t chip_select
Definition current.h:129