hallcurrent 2.0.0.0
hallcurrent.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 HALLCURRENT_H
36#define HALLCURRENT_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#include "spi_specifics.h"
56
57
58// -------------------------------------------------------------- PUBLIC MACROS
69#define HALLCURRENT_MAP_MIKROBUS( cfg, mikrobus ) \
70 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
71 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
72 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
73 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
74 cfg.ocd = MIKROBUS( mikrobus, MIKROBUS_INT );
81#define HALLCURRENT_OK 0
82#define HALLCURRENT_ERROR -1
93#define HALLCURRENT_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
94#define HALLCURRENT_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
95
96 // End group macro
97// --------------------------------------------------------------- PUBLIC TYPES
106typedef struct
107{
108 digital_in_t ocd;
109
110 // Modules
111 spi_master_t spi;
112 pin_name_t chip_select;
113
115
119typedef struct
120{
121 // Communication gpio pins
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 pin_name_t ocd;
129
130 // static variable
131 uint32_t spi_speed;
132 spi_master_mode_t spi_mode;
133 spi_master_chip_select_polarity_t cs_polarity;
134
136
137 // End types group
138// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
139
144#ifdef __cplusplus
145extern "C"{
146#endif
147
157
166
176
188
197
206
207#ifdef __cplusplus
208}
209#endif
210#endif // _HALLCURRENT_H_
211
212 // End public_function group
214
215// ------------------------------------------------------------------------- END
uint8_t hallcurrent_check_status(hallcurrent_t *ctx)
Check status of read data function.
err_t hallcurrent_init(hallcurrent_t *ctx, hallcurrent_cfg_t *cfg)
Initialization function.
float hallcurrent_read_current(hallcurrent_t *ctx)
Read electric current function.
void hallcurrent_cfg_setup(hallcurrent_cfg_t *cfg)
Config Object Initialization function.
uint8_t hallcurrent_get_ocd_pin(hallcurrent_t *ctx)
Read OCD pin state function.
uint16_t hallcurrent_read_data(hallcurrent_t *ctx)
Generic read 16-bit data function.
This file contains SPI specific macros, functions, etc.
Click configuration structure definition.
Definition hallcurrent.h:120
pin_name_t ocd
Definition hallcurrent.h:128
spi_master_chip_select_polarity_t cs_polarity
Definition hallcurrent.h:133
pin_name_t sck
Definition hallcurrent.h:124
spi_master_mode_t spi_mode
Definition hallcurrent.h:132
pin_name_t mosi
Definition hallcurrent.h:123
uint32_t spi_speed
Definition hallcurrent.h:131
pin_name_t miso
Definition hallcurrent.h:122
pin_name_t cs
Definition hallcurrent.h:125
Click ctx object definition.
Definition hallcurrent.h:107
digital_in_t ocd
Definition hallcurrent.h:108
spi_master_t spi
Definition hallcurrent.h:111
pin_name_t chip_select
Definition hallcurrent.h:112