brushless30  2.1.0.0
brushless30.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef BRUSHLESS30_H
29 #define BRUSHLESS30_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define BRUSHLESS30_REG_OPSEL1 0x00
75 #define BRUSHLESS30_REG_OPSEL2 0x04
76 #define BRUSHLESS30_REG_STAT1 0x08
77 #define BRUSHLESS30_REG_STAT2 0x0C
78 #define BRUSHLESS30_REG_CP_RLY_CTRL 0x14
79 #define BRUSHLESS30_REG_PL_CTRL 0x18
80 #define BRUSHLESS30_REG_T_ILIM 0x1C
81 #define BRUSHLESS30_REG_FET_OPSEL 0x24
82 #define BRUSHLESS30_REG_HS_VDS_SEL 0x28
83 #define BRUSHLESS30_REG_LS_VDS_SEL 0x2C
84 #define BRUSHLESS30_REG_FET_DET_SEL 0x30
85 #define BRUSHLESS30_REG_AMP_CTRL 0x40
86 #define BRUSHLESS30_REG_AMP_STAT 0x44
87 #define BRUSHLESS30_REG_ALM_CTRL 0x48
88 #define BRUSHLESS30_REG_QA_CTRL 0x4C
89 #define BRUSHLESS30_REG_ANSWER 0x50
90 #define BRUSHLESS30_REG_BIST_DIAG 0x54
91 #define BRUSHLESS30_REG_BIST_STAT 0x58
92 #define BRUSHLESS30_REG_FET_TEST_CNT1 0x5C
93 #define BRUSHLESS30_REG_FET_TEST_CNT2 0x60
94 #define BRUSHLESS30_REG_FET_TEST_STAT 0x64
95 #define BRUSHLESS30_REG_VDS_COMP_STAT 0x68
96 #define BRUSHLESS30_REG_DUMMY 0x7C
97  // brushless30_reg
99 
114 #define BRUSHLESS30_HS_VDS_SEL 0x2444
115 #define BRUSHLESS30_LS_VDS_SEL 0x2444
116 #define BRUSHLESS30_AMP_CTRL 0x0333
117 #define BRUSHLESS30_CP_RLY_CTRL 0x1111
118 
127 #define BRUSHLESS30_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
128 #define BRUSHLESS30_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
129  // brushless30_set
131 
146 #define BRUSHLESS30_MAP_MIKROBUS( cfg, mikrobus ) \
147  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
148  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
149  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
150  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
151  cfg.alarm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
152  cfg.diag = MIKROBUS( mikrobus, MIKROBUS_INT )
153  // brushless30_map // brushless30
156 
161 typedef struct
162 {
163  // Output pins
164  digital_out_t alarm;
166  // Input pins
167  digital_in_t diag;
169  // Modules
170  spi_master_t spi;
172  pin_name_t chip_select;
174 } brushless30_t;
175 
180 typedef struct
181 {
182  // Communication gpio pins
183  pin_name_t miso;
184  pin_name_t mosi;
185  pin_name_t sck;
186  pin_name_t cs;
188  // Additional gpio pins
189  pin_name_t alarm;
190  pin_name_t diag;
192  // static variable
193  uint32_t spi_speed;
194  spi_master_mode_t spi_mode;
195  spi_master_chip_select_polarity_t cs_polarity;
198 
203 typedef enum
204 {
206  BRUSHLESS30_ERROR = -1
207 
209 
226 
241 
255 
268 err_t brushless30_write_reg ( brushless30_t *ctx, uint8_t reg, uint16_t data_in );
269 
282 err_t brushless30_read_reg ( brushless30_t *ctx, uint8_t reg, uint16_t *data_out );
283 
293 
303 
313 
314 #ifdef __cplusplus
315 }
316 #endif
317 #endif // BRUSHLESS30_H
318  // brushless30
320 
321 // ------------------------------------------------------------------------ END
brushless30_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: brushless30.h:194
brushless30_return_value_t
brushless30_return_value_t
Brushless 30 Click return value data.
Definition: brushless30.h:204
brushless30_cfg_t::miso
pin_name_t miso
Definition: brushless30.h:183
brushless30_cfg_t
Brushless 30 Click configuration object.
Definition: brushless30.h:181
brushless30_write_reg
err_t brushless30_write_reg(brushless30_t *ctx, uint8_t reg, uint16_t data_in)
Brushless 30 write reg function.
BRUSHLESS30_ERROR
@ BRUSHLESS30_ERROR
Definition: brushless30.h:206
brushless30_t::diag
digital_in_t diag
Definition: brushless30.h:167
brushless30_cfg_t::mosi
pin_name_t mosi
Definition: brushless30.h:184
spi_specifics.h
This file contains SPI specific macros, functions, etc.
brushless30_cfg_t::cs
pin_name_t cs
Definition: brushless30.h:186
brushless30_init
err_t brushless30_init(brushless30_t *ctx, brushless30_cfg_t *cfg)
Brushless 30 initialization function.
brushless30_cfg_t::alarm
pin_name_t alarm
Definition: brushless30.h:189
brushless30_get_diag_pin
uint8_t brushless30_get_diag_pin(brushless30_t *ctx)
Brushless 30 get diag pin function.
brushless30_default_cfg
err_t brushless30_default_cfg(brushless30_t *ctx)
Brushless 30 default configuration function.
brushless30_cfg_t::sck
pin_name_t sck
Definition: brushless30.h:185
brushless30_cfg_t::spi_speed
uint32_t spi_speed
Definition: brushless30.h:193
brushless30_cfg_setup
void brushless30_cfg_setup(brushless30_cfg_t *cfg)
Brushless 30 configuration object setup function.
brushless30_t::spi
spi_master_t spi
Definition: brushless30.h:170
BRUSHLESS30_OK
@ BRUSHLESS30_OK
Definition: brushless30.h:205
brushless30_t::alarm
digital_out_t alarm
Definition: brushless30.h:164
brushless30_t
Brushless 30 Click context object.
Definition: brushless30.h:162
brushless30_enable_driver
void brushless30_enable_driver(brushless30_t *ctx)
Brushless 30 enable driver function.
brushless30_disable_driver
void brushless30_disable_driver(brushless30_t *ctx)
Brushless 30 disable driver function.
brushless30_read_reg
err_t brushless30_read_reg(brushless30_t *ctx, uint8_t reg, uint16_t *data_out)
Brushless 30 read reg function.
brushless30_t::chip_select
pin_name_t chip_select
Definition: brushless30.h:172
brushless30_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: brushless30.h:195
brushless30_cfg_t::diag
pin_name_t diag
Definition: brushless30.h:190