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 );
75 
81 #define HALLCURRENT_OK 0
82 #define HALLCURRENT_ERROR -1
83 
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  // End group macro
97 // --------------------------------------------------------------- PUBLIC TYPES
106 typedef struct
107 {
108  digital_in_t ocd;
109 
110  // Modules
111  spi_master_t spi;
112  pin_name_t chip_select;
113 
114 } hallcurrent_t;
115 
119 typedef 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  // End types group
138 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
139 
144 #ifdef __cplusplus
145 extern "C"{
146 #endif
147 
157 
166 
176 
188 
197 
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 #endif // _HALLCURRENT_H_
211  // End public_function group
214 
215 // ------------------------------------------------------------------------- END
hallcurrent_t::chip_select
pin_name_t chip_select
Definition: hallcurrent.h:112
spi_specifics.h
This file contains SPI specific macros, functions, etc.
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:125
hallcurrent_cfg_t::miso
pin_name_t miso
Definition: hallcurrent.h:122
hallcurrent_check_status
uint8_t hallcurrent_check_status(hallcurrent_t *ctx)
Check status of read data function.
hallcurrent_cfg_t
Click configuration structure definition.
Definition: hallcurrent.h:120
hallcurrent_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: hallcurrent.h:132
hallcurrent_t
Click ctx object definition.
Definition: hallcurrent.h:107
hallcurrent_cfg_t::mosi
pin_name_t mosi
Definition: hallcurrent.h:123
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_get_ocd_pin
uint8_t hallcurrent_get_ocd_pin(hallcurrent_t *ctx)
Read OCD pin state function.
hallcurrent_cfg_t::ocd
pin_name_t ocd
Definition: hallcurrent.h:128
hallcurrent_cfg_t::sck
pin_name_t sck
Definition: hallcurrent.h:124
hallcurrent_init
err_t hallcurrent_init(hallcurrent_t *ctx, hallcurrent_cfg_t *cfg)
Initialization function.
hallcurrent_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hallcurrent.h:133
hallcurrent_t::spi
spi_master_t spi
Definition: hallcurrent.h:111
hallcurrent_t::ocd
digital_in_t ocd
Definition: hallcurrent.h:108
hallcurrent_cfg_t::spi_speed
uint32_t spi_speed
Definition: hallcurrent.h:131