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 
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 HALLCURRENT_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 ); \
59  cfg.ocd = MIKROBUS( mikrobus, MIKROBUS_INT );
60 
66 #define HALLCURRENT_RETVAL uint8_t
67 
68 #define HALLCURRENT_OK 0x00
69 #define HALLCURRENT_INIT_ERROR 0xFF
70  // End group macro
73 // --------------------------------------------------------------- PUBLIC TYPES
82 typedef struct
83 {
84  digital_in_t ocd;
85  digital_out_t cs;
86 
87  // Modules
88 
89  spi_master_t spi;
90  pin_name_t chip_select;
91 
93 
97 typedef struct
98 {
99  // Communication gpio pins
100 
101  pin_name_t miso;
102  pin_name_t mosi;
103  pin_name_t sck;
104  pin_name_t cs;
105 
106  // Additional gpio pins
107 
108  pin_name_t ocd;
109 
110  // static variable
111 
112  uint32_t spi_speed;
113  uint8_t spi_mode;
114  spi_master_chip_select_polarity_t cs_polarity;
115 
117  // End types group
119 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
120 
125 #ifdef __cplusplus
126 extern "C"{
127 #endif
128 
138 
147 
160 (
161  hallcurrent_t *ctx,
162  uint8_t *wr_buf,
163  uint16_t wr_len,
164  uint8_t *rd_buf,
165  uint16_t rd_len
166 );
167 
177 uint16_t hallcurrent_read_data ( hallcurrent_t *ctx );
178 
190 uint8_t hallcurrent_chack_status ( hallcurrent_t *ctx );
191 
201 
202 #ifdef __cplusplus
203 }
204 #endif
205 #endif // _HALLCURRENT_H_
206  // End public_function group
209 
210 // ------------------------------------------------------------------------- END
hallcurrent_cfg_t::spi_mode
uint8_t spi_mode
Definition: hallcurrent.h:113
hallcurrent_t::chip_select
pin_name_t chip_select
Definition: hallcurrent.h:90
hallcurrent_init
HALLCURRENT_RETVAL hallcurrent_init(hallcurrent_t *ctx, hallcurrent_cfg_t *cfg)
Initialization function.
hallcurrent_read_data
uint16_t hallcurrent_read_data(hallcurrent_t *ctx)
Generic read 16-bit data function.
hallcurrent_cfg_t::cs
pin_name_t cs
Definition: hallcurrent.h:104
hallcurrent_cfg_t::miso
pin_name_t miso
Definition: hallcurrent.h:101
hallcurrent_cfg_t
Click configuration structure definition.
Definition: hallcurrent.h:97
hallcurrent_t
Click ctx object definition.
Definition: hallcurrent.h:82
hallcurrent_chack_status
uint8_t hallcurrent_chack_status(hallcurrent_t *ctx)
Check status of read data function.
hallcurrent_cfg_t::mosi
pin_name_t mosi
Definition: hallcurrent.h:102
hallcurrent_cfg_setup
void hallcurrent_cfg_setup(hallcurrent_cfg_t *cfg)
Config Object Initialization function.
hallcurrent_read_current
float hallcurrent_read_current(hallcurrent_t *ctx)
Read electric current function.
hallcurrent_cfg_t::ocd
pin_name_t ocd
Definition: hallcurrent.h:108
hallcurrent_cfg_t::sck
pin_name_t sck
Definition: hallcurrent.h:103
hallcurrent_generic_transfer
void hallcurrent_generic_transfer(hallcurrent_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
hallcurrent_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hallcurrent.h:114
HALLCURRENT_RETVAL
#define HALLCURRENT_RETVAL
Definition: hallcurrent.h:66
hallcurrent_t::cs
digital_out_t cs
Definition: hallcurrent.h:85
hallcurrent_t::spi
spi_master_t spi
Definition: hallcurrent.h:89
hallcurrent_t::ocd
digital_in_t ocd
Definition: hallcurrent.h:84
hallcurrent_cfg_t::spi_speed
uint32_t spi_speed
Definition: hallcurrent.h:112