hallcurrent  2.0.0.0
hallcurrent.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * 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 
86  // Modules
87 
88  spi_master_t spi;
89 
91 
95 typedef 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  // Additional gpio pins
105 
106  pin_name_t ocd;
107 
108  // static variable
109 
110  hal_spi_speed_t spi_speed;
111  hal_spi_mode_t spi_mode;
112 
114  // End types group
116 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
117 
122 #ifdef __cplusplus
123 extern "C"{
124 #endif
125 
135 
144 
153 void hallcurrent_generic_transfer ( hallcurrent_t *ctx, spi_master_transfer_data_t *block );
154 
164 uint16_t hallcurrent_read_data ( hallcurrent_t *ctx );
165 
177 uint8_t hallcurrent_chack_status ( hallcurrent_t *ctx );
178 
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 #endif // _HALLCURRENT_H_
193  // End public_function group
196 
197 // ------------------------------------------------------------------------- END
spi_master_t spi
Definition: hallcurrent.h:88
pin_name_t cs
Definition: hallcurrent.h:102
float hallcurrent_read_current(hallcurrent_t *ctx)
Read electric current function.
hal_spi_speed_t spi_speed
Definition: hallcurrent.h:110
pin_name_t ocd
Definition: hallcurrent.h:106
Click configuration structure definition.
Definition: hallcurrent.h:95
pin_name_t sck
Definition: hallcurrent.h:101
uint16_t hallcurrent_read_data(hallcurrent_t *ctx)
Generic read 16-bit data function.
pin_name_t miso
Definition: hallcurrent.h:99
digital_in_t ocd
Definition: hallcurrent.h:84
void hallcurrent_cfg_setup(hallcurrent_cfg_t *cfg)
Config Object Initialization function.
HALLCURRENT_RETVAL hallcurrent_init(hallcurrent_t *ctx, hallcurrent_cfg_t *cfg)
Initialization function.
Click ctx object definition.
Definition: hallcurrent.h:82
hal_spi_mode_t spi_mode
Definition: hallcurrent.h:111
pin_name_t mosi
Definition: hallcurrent.h:100
uint8_t hallcurrent_chack_status(hallcurrent_t *ctx)
Check status of read data function.
void hallcurrent_generic_transfer(hallcurrent_t *ctx, spi_master_transfer_data_t *block)
Generic transfer function.
#define HALLCURRENT_RETVAL
Definition: hallcurrent.h:66