current  2.0.0.0
current.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 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  // Modules
111 
112  spi_master_t spi;
113 
114 } current_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t miso;
124  pin_name_t mosi;
125  pin_name_t sck;
126  pin_name_t cs;
127 
128  // static variable
129 
130  hal_spi_speed_t spi_speed;
131  hal_spi_mode_t spi_mode;
132 
133 } current_cfg_t;
134  // End types group
136 // ------------------------------------------------------------------ CONSTANTS // End constants group
145 // ------------------------------------------------------------------ VARIABLES // End variable group
153 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154 
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
171 void current_cfg_setup ( current_cfg_t *cfg );
172 
181 
191 uint16_t current_data_read ( current_t *ctx );
192 
202 uint16_t current_get_raw_data ( current_t *ctx );
203 
214 float current_avg_rata ( current_t *ctx );
215 
228 float current_get_current_data ( current_t *ctx, float r_hunt );
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 #endif // _CURRENT_H_
234  // End public_function group
237 
238 // ------------------------------------------------------------------------- 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_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:119
current_cfg_t::mosi
pin_name_t mosi
Definition: current.h:124
current_t
Click ctx object definition.
Definition: current.h:108
current_cfg_t::sck
pin_name_t sck
Definition: current.h:125
current_cfg_t::spi_speed
hal_spi_speed_t spi_speed
Definition: current.h:130
current_get_raw_data
uint16_t current_get_raw_data(current_t *ctx)
Get raw data function.
current_cfg_t::cs
pin_name_t cs
Definition: current.h:126
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:112
current_cfg_t::miso
pin_name_t miso
Definition: current.h:123
current_cfg_t::spi_mode
hal_spi_mode_t spi_mode
Definition: current.h:131
current_avg_rata
float current_avg_rata(current_t *ctx)
Calculate average data function.