accurrent 2.0.0.0
accurrent.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 ACCURRENT_H
36#define ACCURRENT_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_digital_in.h"
54#include "drv_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define ACCURRENT_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 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
79#define ACCURRENT_OK 0
80#define ACCURRENT_ERROR -1
87#define ACCURRENT_ADC_ITERATIONS 10
88#define ACCURRENT_ADC_RESOLUTION 0x0FFF
89#define ACCURRENT_AC_TO_DC_V_SCALE 1.8f
90#define ACCURRENT_SENSOR_RESOLUTION 30.0f
91#define ACCURRENT_A_TO_MA_SCALE 1000.0f
95 // End group macro
96// --------------------------------------------------------------- PUBLIC TYPES
105typedef struct
106{
107 digital_out_t cs;
108
109 // Input pins
110 digital_in_t an;
111
112 // Modules
113 spi_master_t spi;
114 pin_name_t chip_select;
115
117
121typedef struct
122{
123 // Communication gpio pins
124 pin_name_t miso;
125 pin_name_t mosi;
126 pin_name_t sck;
127 pin_name_t cs;
128
129 // Additional gpio pins
130 pin_name_t an;
131
132 // static variable
133 uint32_t spi_speed;
134 spi_master_mode_t spi_mode;
135 spi_master_chip_select_polarity_t cs_polarity;
136
138
139 // End types group
140// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
141
146#ifdef __cplusplus
147extern "C"{
148#endif
149
159
169
181void accurrent_generic_transfer ( accurrent_t *ctx, uint8_t *wr_buf, uint16_t wr_len,
182 uint8_t *rd_buf, uint16_t rd_len );
183
192
201
202#ifdef __cplusplus
203}
204#endif
205#endif // _ACCURRENT_H_
206
207 // End public_function group
209
210// ------------------------------------------------------------------------- END
void accurrent_generic_transfer(accurrent_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void accurrent_cfg_setup(accurrent_cfg_t *cfg)
Config Object Initialization function.
err_t accurrent_init(accurrent_t *ctx, accurrent_cfg_t *cfg)
Initialization function.
float accurrent_get_ma(accurrent_t *ctx)
Gets current value of AC Current in mA.
float accurrent_get_a(accurrent_t *ctx)
Gets current value of AC Current in A.
Click configuration structure definition.
Definition accurrent.h:122
spi_master_chip_select_polarity_t cs_polarity
Definition accurrent.h:135
pin_name_t sck
Definition accurrent.h:126
spi_master_mode_t spi_mode
Definition accurrent.h:134
pin_name_t mosi
Definition accurrent.h:125
uint32_t spi_speed
Definition accurrent.h:133
pin_name_t miso
Definition accurrent.h:124
pin_name_t an
Definition accurrent.h:130
pin_name_t cs
Definition accurrent.h:127
Click ctx object definition.
Definition accurrent.h:106
digital_out_t cs
Definition accurrent.h:107
spi_master_t spi
Definition accurrent.h:113
digital_in_t an
Definition accurrent.h:110
pin_name_t chip_select
Definition accurrent.h:114