accurrent  2.0.0.0
accurrent.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 ACCURRENT_H
36 #define ACCURRENT_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define ACCURRENT_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN );
60 
66 #define ACCURRENT_RETVAL uint8_t
67 
68 #define ACCURRENT_OK 0x00
69 #define ACCURRENT_INIT_ERROR 0xFF
70 
76 #define ACCURRENT_ADC_12_BIT 12
77 #define ACCURRENT_ADC_10_BIT 10
78 #define ACCURRENT_ADC_8_BIT 8
79 
80 #define ACCURRENT_ADC_12_BIT_MSB_MASK 0x1F
81 #define ACCURRENT_ADC_10_BIT_MSB_MASK 0x03
82 #define ACCURRENT_ADC_8_BIT_MSB_MASK 0x00
83 
84 #define ACCURRENT_ADC_ITERATIONS 10
85 
86 #define ACCURRENT_ADC_CONVERSION_SIZE ACCURRENT_ADC_12_BIT
87 #define ACCURRENT_ADC_ITERATION_SIZE ACCURRENT_ADC_ITERATIONS
88  // End group macro
94 // --------------------------------------------------------------- PUBLIC TYPES
103 typedef struct
104 {
105  // Output pins
106 
107  // Input pins
108 
109  digital_in_t an;
110 
111 
112  // Modules
113 
114  spi_master_t spi;
115 
116 } accurrent_t;
117 
121 typedef struct
122 {
123  // Communication gpio pins
124 
125  pin_name_t miso;
126  pin_name_t mosi;
127  pin_name_t sck;
128  pin_name_t cs;
129 
130  // Additional gpio pins
131 
132  pin_name_t an;
133 
134  // static variable
135 
136  hal_spi_speed_t spi_speed;
137  hal_spi_mode_t spi_mode;
138 
140  // End types group
142 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
161 
170 
179 void accurrent_generic_transfer ( accurrent_t *ctx, spi_master_transfer_data_t *block );
180 
188 float accurrent_get_ma ( accurrent_t *ctx );
189 
197 float accurrent_get_a ( accurrent_t *ctx );
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 #endif // _ACCURRENT_H_
203  // End public_function group
206 
207 // ------------------------------------------------------------------------- END
#define ACCURRENT_RETVAL
Definition: accurrent.h:66
hal_spi_mode_t spi_mode
Definition: accurrent.h:137
pin_name_t mosi
Definition: accurrent.h:126
void accurrent_cfg_setup(accurrent_cfg_t *cfg)
Config Object Initialization function.
float accurrent_get_ma(accurrent_t *ctx)
Gets current value of AC Current in mA.
pin_name_t an
Definition: accurrent.h:132
Click ctx object definition.
Definition: accurrent.h:103
float accurrent_get_a(accurrent_t *ctx)
Gets current value of AC Current in A.
Click configuration structure definition.
Definition: accurrent.h:121
pin_name_t miso
Definition: accurrent.h:125
hal_spi_speed_t spi_speed
Definition: accurrent.h:136
void accurrent_generic_transfer(accurrent_t *ctx, spi_master_transfer_data_t *block)
Generic transfer function.
digital_in_t an
Definition: accurrent.h:109
pin_name_t sck
Definition: accurrent.h:127
pin_name_t cs
Definition: accurrent.h:128
ACCURRENT_RETVAL accurrent_init(accurrent_t *ctx, accurrent_cfg_t *cfg)
Initialization function.
spi_master_t spi
Definition: accurrent.h:114