current2  2.0.0.0
current2.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 CURRENT2_H
36 #define CURRENT2_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define CURRENT2_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
69 
75 #define CURRENT2_RETVAL uint8_t
76 
77 #define CURRENT2_OK 0x00
78 #define CURRENT2_INIT_ERROR 0xFF
79  // End group macro
82 // --------------------------------------------------------------- PUBLIC TYPES
91 typedef struct
92 {
93  digital_out_t cs;
94 
95  // Modules
96 
97  spi_master_t spi;
98  pin_name_t chip_select;
99 
100 } current2_t;
101 
105 typedef struct
106 {
107  // Communication gpio pins
108 
109  pin_name_t miso;
110  pin_name_t mosi;
111  pin_name_t sck;
112  pin_name_t cs;
113 
114 
115  // static variable
116 
117  uint32_t spi_speed;
118  spi_master_mode_t spi_mode;
119  spi_master_chip_select_polarity_t cs_polarity;
120 
122  // End types group
124 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
125 
130 #ifdef __cplusplus
131 extern "C"{
132 #endif
133 
143 
151 uint8_t current2_init ( current2_t *ctx, current2_cfg_t *cfg );
152 
165 (
166  current2_t *ctx,
167  uint8_t *wr_buf,
168  uint16_t wr_len,
169  uint8_t *rd_buf,
170  uint16_t rd_len
171 );
172 
180 uint16_t current2_get_adc ( current2_t *ctx );
181 
190 uint16_t current2_get_average_adc ( current2_t *ctx, uint8_t n_samp );
191 
200 uint16_t current2_get_current ( current2_t *ctx, uint8_t n_sample );
201 
202 #ifdef __cplusplus
203 }
204 #endif
205 #endif // _CURRENT2_H_
206  // End public_function group
209 
210 // ------------------------------------------------------------------------- END
current2_get_adc
uint16_t current2_get_adc(current2_t *ctx)
Get ADC function.
current2_t::spi
spi_master_t spi
Definition: current2.h:97
current2_t::cs
digital_out_t cs
Definition: current2.h:93
current2_cfg_t
Click configuration structure definition.
Definition: current2.h:106
current2_cfg_t::spi_speed
uint32_t spi_speed
Definition: current2.h:117
current2_t::chip_select
pin_name_t chip_select
Definition: current2.h:98
current2_get_current
uint16_t current2_get_current(current2_t *ctx, uint8_t n_sample)
Get Current function.
current2_cfg_t::miso
pin_name_t miso
Definition: current2.h:109
current2_get_average_adc
uint16_t current2_get_average_adc(current2_t *ctx, uint8_t n_samp)
Get Averaged ADC function.
current2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: current2.h:119
current2_cfg_t::cs
pin_name_t cs
Definition: current2.h:112
current2_cfg_t::sck
pin_name_t sck
Definition: current2.h:111
current2_cfg_t::mosi
pin_name_t mosi
Definition: current2.h:110
current2_init
uint8_t current2_init(current2_t *ctx, current2_cfg_t *cfg)
Initialization function.
current2_generic_transfer
void current2_generic_transfer(current2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
current2_cfg_setup
void current2_cfg_setup(current2_cfg_t *cfg)
Config Object Initialization function.
current2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: current2.h:118
current2_t
Click ctx object definition.
Definition: current2.h:92