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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define ACCURRENT_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  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
59 
65 #define ACCURRENT_RETVAL uint8_t
66 
67 #define ACCURRENT_OK 0x00
68 #define ACCURRENT_INIT_ERROR 0xFF
69 
75 #define ACCURRENT_ADC_12_BIT 12
76 #define ACCURRENT_ADC_10_BIT 10
77 #define ACCURRENT_ADC_8_BIT 8
78 
79 #define ACCURRENT_ADC_12_BIT_MSB_MASK 0x1F
80 #define ACCURRENT_ADC_10_BIT_MSB_MASK 0x03
81 #define ACCURRENT_ADC_8_BIT_MSB_MASK 0x00
82 
83 #define ACCURRENT_ADC_ITERATIONS 10
84 
85 #define ACCURRENT_ADC_CONVERSION_SIZE ACCURRENT_ADC_12_BIT
86 #define ACCURRENT_ADC_ITERATION_SIZE ACCURRENT_ADC_ITERATIONS
87  // End group macro
91 // --------------------------------------------------------------- PUBLIC TYPES
100 typedef struct
101 {
102  digital_out_t cs;
103 
104  // Input pins
105 
106  digital_in_t an;
107 
108  // Modules
109 
110  spi_master_t spi;
111  pin_name_t chip_select;
112 
113 } accurrent_t;
114 
118 typedef struct
119 {
120  // Communication gpio pins
121 
122  pin_name_t miso;
123  pin_name_t mosi;
124  pin_name_t sck;
125  pin_name_t cs;
126 
127  // Additional gpio pins
128 
129  pin_name_t an;
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 
138  // End types group
140 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
141 
146 #ifdef __cplusplus
147 extern "C"{
148 #endif
149 
159 
169 
181 void accurrent_generic_transfer ( accurrent_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
182 
190 float accurrent_get_ma ( accurrent_t *ctx );
191 
199 float accurrent_get_a ( accurrent_t *ctx );
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 #endif // _ACCURRENT_H_
205  // End public_function group
208 
209 // ------------------------------------------------------------------------- END
ACCURRENT_RETVAL
#define ACCURRENT_RETVAL
Definition: accurrent.h:65
accurrent_cfg_t
Click configuration structure definition.
Definition: accurrent.h:118
accurrent_t::chip_select
pin_name_t chip_select
Definition: accurrent.h:111
accurrent_t
Click ctx object definition.
Definition: accurrent.h:100
accurrent_cfg_t::cs
pin_name_t cs
Definition: accurrent.h:125
accurrent_cfg_setup
void accurrent_cfg_setup(accurrent_cfg_t *cfg)
Config Object Initialization function.
accurrent_t::an
digital_in_t an
Definition: accurrent.h:106
accurrent_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: accurrent.h:134
accurrent_t::cs
digital_out_t cs
Definition: accurrent.h:102
accurrent_get_a
float accurrent_get_a(accurrent_t *ctx)
Gets current value of AC Current in A.
accurrent_get_ma
float accurrent_get_ma(accurrent_t *ctx)
Gets current value of AC Current in mA.
accurrent_init
ACCURRENT_RETVAL accurrent_init(accurrent_t *ctx, accurrent_cfg_t *cfg)
Initialization function.
accurrent_cfg_t::spi_speed
uint32_t spi_speed
Definition: accurrent.h:133
accurrent_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: accurrent.h:135
accurrent_cfg_t::mosi
pin_name_t mosi
Definition: accurrent.h:123
accurrent_generic_transfer
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.
accurrent_cfg_t::an
pin_name_t an
Definition: accurrent.h:129
accurrent_t::spi
spi_master_t spi
Definition: accurrent.h:110
accurrent_cfg_t::miso
pin_name_t miso
Definition: accurrent.h:122
accurrent_cfg_t::sck
pin_name_t sck
Definition: accurrent.h:124