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 
38 #include "drv_digital_out.h"
39 #include "drv_spi_master.h"
40 
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define CURRENT_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 )
58 
64 #define CURRENT_RETVAL uint8_t
65 
66 #define CURRENT_OK 0x00
67 #define CURRENT_INIT_ERROR 0xFF
68 
74 #define CURRENT_FILTER_USEFULL_DATA 0x0FFF
75 #define CURRENT_SAMPLE_NUM 10
76 
82 #define CURRENT_RSHUNT_0_05 0.05
83 #define CURRENT_RSHUNT_0_2 0.2
84 #define CURRENT_RSHUNT_1 1.0
85 #define CURRENT_RSHUNT_10 10.0
86 #define CURRENT_CAL_COEF 0.025
87 
93 #define RFMETER_DEF_LIMIT_HIGH 4096
94 #define RFMETER_DEF_LIMIT_LOW 800
95 #define CURRENT_OUT_OF_RANGE -1.0
96  // End group macro
99 // --------------------------------------------------------------- PUBLIC TYPES
108 typedef struct
109 {
110  digital_out_t cs;
111 
112  // Modules
113 
114  spi_master_t spi;
115  pin_name_t chip_select;
116 
117 } current_t;
118 
122 typedef 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 
137 } current_cfg_t;
138  // End types group
140 // ------------------------------------------------------------------ CONSTANTS // End constants group
149 // ------------------------------------------------------------------ VARIABLES // End variable group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
163 #ifdef __cplusplus
164 extern "C"{
165 #endif
166 
175 void current_cfg_setup ( current_cfg_t *cfg );
176 
185 
195 uint16_t current_data_read ( current_t *ctx );
196 
206 uint16_t current_get_raw_data ( current_t *ctx );
207 
218 float current_avg_rata ( current_t *ctx );
219 
232 float current_get_current_data ( current_t *ctx, float r_hunt );
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 #endif // _CURRENT_H_
238  // End public_function group
241 
242 // ------------------------------------------------------------------------- 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:133
current_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: current.h:135
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:122
current_t::chip_select
pin_name_t chip_select
Definition: current.h:115
current_cfg_t::mosi
pin_name_t mosi
Definition: current.h:127
current_t
Click ctx object definition.
Definition: current.h:108
current_cfg_t::sck
pin_name_t sck
Definition: current.h:128
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:110
current_cfg_t::cs
pin_name_t cs
Definition: current.h:129
current_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: current.h:134
current_data_read
uint16_t current_data_read(current_t *ctx)
Data read function.
CURRENT_RETVAL
#define CURRENT_RETVAL
Definition: current.h:64
current_t::spi
spi_master_t spi
Definition: current.h:114
current_cfg_t::miso
pin_name_t miso
Definition: current.h:126
current_avg_rata
float current_avg_rata(current_t *ctx)
Calculate average data function.