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 "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_spi_master.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
54#define CURRENT2_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 );
65#define CURRENT2_RETVAL uint8_t
66
67#define CURRENT2_OK 0x00
68#define CURRENT2_INIT_ERROR 0xFF // End group macro
72// --------------------------------------------------------------- PUBLIC TYPES
81typedef struct
82{
83 digital_out_t cs;
84
85 // Modules
86
87 spi_master_t spi;
88 pin_name_t chip_select;
89
91
95typedef struct
96{
97 // Communication gpio pins
98
99 pin_name_t miso;
100 pin_name_t mosi;
101 pin_name_t sck;
102 pin_name_t cs;
103
104
105 // static variable
106
107 uint32_t spi_speed;
108 spi_master_mode_t spi_mode;
109 spi_master_chip_select_polarity_t cs_polarity;
110
112 // End types group
114// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
115
120#ifdef __cplusplus
121extern "C"{
122#endif
123
133
142
155(
156 current2_t *ctx,
157 uint8_t *wr_buf,
158 uint16_t wr_len,
159 uint8_t *rd_buf,
160 uint16_t rd_len
161);
162
170uint16_t current2_get_adc ( current2_t *ctx );
171
180uint16_t current2_get_average_adc ( current2_t *ctx, uint8_t n_samp );
181
190uint16_t current2_get_current ( current2_t *ctx, uint8_t n_sample );
191
192#ifdef __cplusplus
193}
194#endif
195#endif // _CURRENT2_H_
196 // End public_function group
199
200// ------------------------------------------------------------------------- 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:96
spi_master_chip_select_polarity_t cs_polarity
Definition: current2.h:109
pin_name_t sck
Definition: current2.h:101
spi_master_mode_t spi_mode
Definition: current2.h:108
pin_name_t mosi
Definition: current2.h:100
uint32_t spi_speed
Definition: current2.h:107
pin_name_t miso
Definition: current2.h:99
pin_name_t cs
Definition: current2.h:102
Click ctx object definition.
Definition: current2.h:82
digital_out_t cs
Definition: current2.h:83
spi_master_t spi
Definition: current2.h:87
pin_name_t chip_select
Definition: current2.h:88