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
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
57// -------------------------------------------------------------- PUBLIC MACROS
68#define CURRENT2_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
79#define CURRENT2_RETVAL uint8_t
80
81#define CURRENT2_OK 0x00
82#define CURRENT2_INIT_ERROR 0xFF
85 // End group macro
86// --------------------------------------------------------------- PUBLIC TYPES
95typedef struct
96{
97 digital_out_t cs;
98
99 // Modules
100
101 spi_master_t spi;
102 pin_name_t chip_select;
103
104} current2_t;
105
109typedef struct
110{
111 // Communication gpio pins
112
113 pin_name_t miso;
114 pin_name_t mosi;
115 pin_name_t sck;
116 pin_name_t cs;
117
118
119 // static variable
120
121 uint32_t spi_speed;
122 spi_master_mode_t spi_mode;
123 spi_master_chip_select_polarity_t cs_polarity;
124
126
127 // End types group
128// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
129
134#ifdef __cplusplus
135extern "C"{
136#endif
137
147
156
169(
170 current2_t *ctx,
171 uint8_t *wr_buf,
172 uint16_t wr_len,
173 uint8_t *rd_buf,
174 uint16_t rd_len
175);
176
184uint16_t current2_get_adc ( current2_t *ctx );
185
194uint16_t current2_get_average_adc ( current2_t *ctx, uint8_t n_samp );
195
204uint16_t current2_get_current ( current2_t *ctx, uint8_t n_sample );
205
206#ifdef __cplusplus
207}
208#endif
209#endif // _CURRENT2_H_
210
211 // End public_function group
213
214// ------------------------------------------------------------------------- END
uint16_t current2_get_current(current2_t *ctx, uint8_t n_sample)
Get Current function.
void current2_cfg_setup(current2_cfg_t *cfg)
Config Object Initialization function.
uint16_t current2_get_adc(current2_t *ctx)
Get ADC function.
uint16_t current2_get_average_adc(current2_t *ctx, uint8_t n_samp)
Get Averaged ADC function.
uint8_t current2_init(current2_t *ctx, current2_cfg_t *cfg)
Initialization function.
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.
Click configuration structure definition.
Definition current2.h:110
spi_master_chip_select_polarity_t cs_polarity
Definition current2.h:123
pin_name_t sck
Definition current2.h:115
spi_master_mode_t spi_mode
Definition current2.h:122
pin_name_t mosi
Definition current2.h:114
uint32_t spi_speed
Definition current2.h:121
pin_name_t miso
Definition current2.h:113
pin_name_t cs
Definition current2.h:116
Click ctx object definition.
Definition current2.h:96
digital_out_t cs
Definition current2.h:97
spi_master_t spi
Definition current2.h:101
pin_name_t chip_select
Definition current2.h:102