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 )
72 
78 #define CURRENT_RETVAL uint8_t
79 
80 #define CURRENT_OK 0x00
81 #define CURRENT_INIT_ERROR 0xFF
82 
88 #define CURRENT_FILTER_USEFULL_DATA 0x0FFF
89 #define CURRENT_SAMPLE_NUM 10
90 
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
101 
107 #define RFMETER_DEF_LIMIT_HIGH 4096
108 #define RFMETER_DEF_LIMIT_LOW 800
109 #define CURRENT_OUT_OF_RANGE -1.0
110  // End group macro
113 // --------------------------------------------------------------- PUBLIC TYPES
122 typedef 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 
136 typedef 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 
151 } current_cfg_t;
152  // End types group
154 // ------------------------------------------------------------------ CONSTANTS // End constants group
163 // ------------------------------------------------------------------ VARIABLES // End variable group
171 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
172 
177 #ifdef __cplusplus
178 extern "C"{
179 #endif
180 
190 
199 
209 uint16_t current_data_read ( current_t *ctx );
210 
220 uint16_t current_get_raw_data ( current_t *ctx );
221 
233 
246 float current_get_current_data ( current_t *ctx, float r_hunt );
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 #endif // _CURRENT_H_
252  // End public_function group
255 
256 // ------------------------------------------------------------------------- END
current_cfg_setup
void current_cfg_setup(current_cfg_t *cfg)
Config Object Initialization function.
current_init
CURRENT_RETVAL current_init(current_t *ctx, current_cfg_t *cfg)
Initialization function.
current_cfg_t::spi_speed
uint32_t spi_speed
Definition: current.h:147
current_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: current.h:149
current_get_current_data
float current_get_current_data(current_t *ctx, float r_hunt)
Get current value function.
current_cfg_t
Click configuration structure definition.
Definition: current.h:137
current_t::chip_select
pin_name_t chip_select
Definition: current.h:129
current_cfg_t::mosi
pin_name_t mosi
Definition: current.h:141
current_t
Click ctx object definition.
Definition: current.h:123
current_cfg_t::sck
pin_name_t sck
Definition: current.h:142
current_get_raw_data
uint16_t current_get_raw_data(current_t *ctx)
Get raw data function.
current_t::cs
digital_out_t cs
Definition: current.h:124
current_cfg_t::cs
pin_name_t cs
Definition: current.h:143
current_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: current.h:148
current_data_read
uint16_t current_data_read(current_t *ctx)
Data read function.
CURRENT_RETVAL
#define CURRENT_RETVAL
Definition: current.h:78
current_t::spi
spi_master_t spi
Definition: current.h:128
current_cfg_t::miso
pin_name_t miso
Definition: current.h:140
current_avg_rata
float current_avg_rata(current_t *ctx)
Calculate average data function.