39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_analog_in.h"
75#define BRUSHLESS8_DAC_REG_DEVICE_CONFIG 0x01
76#define BRUSHLESS8_DAC_REG_STATUS_TRIGGER 0x02
77#define BRUSHLESS8_DAC_REG_BRDCAST 0x03
78#define BRUSHLESS8_DAC_REG_CHN_A_DVSP 0x08
79#define BRUSHLESS8_DAC_REG_CHN_B_FGC 0x09
80#define BRUSHLESS8_DAC_REG_CHN_C_LA 0x0A
81#define BRUSHLESS8_DAC_REG_CHN_D_LAS 0x0B
82#define BRUSHLESS8_DAC_REG_CHN_E_LAL 0x0C
83#define BRUSHLESS8_DAC_REG_CHN_F_LAAJ 0x0D
101#define BRUSHLESS8_DIRECTION_CW 1
102#define BRUSHLESS8_DIRECTION_CCW 0
109#define BRUSHLESS8_RESET_EN 1
110#define BRUSHLESS8_RESET_DIS 0
116#define BRUSHLESS8_VREF 5000
117#define BRUSHLESS8_RESOLUTION 1024
123#define BRUSHLESS8_RETVAL int8_t
124#define BRUSHLESS8_OK 0
125#define BRUSHLESS8_ERROR (-1)
126#define BRUSHLESS8_PARAM_ERROR (-2)
132#define BRUSHLESS8_FGC_STEP_0 0
133#define BRUSHLESS8_FGC_STEP_1 310
134#define BRUSHLESS8_FGC_STEP_2 630
135#define BRUSHLESS8_FGC_STEP_3 940
136#define BRUSHLESS8_FGC_STEP_4 1250
137#define BRUSHLESS8_FGC_STEP_5 1560
138#define BRUSHLESS8_FGC_STEP_6 1880
139#define BRUSHLESS8_FGC_STEP_7 2190
140#define BRUSHLESS8_FGC_STEP_8 2500
141#define BRUSHLESS8_FGC_STEP_9 2810
148#define BRUSHLESS8_LAS_AUTOMATIC_60_DEG_RST 0
149#define BRUSHLESS8_LAS_AUTOMATIC_360_DEG_RST 1250
150#define BRUSHLESS8_LAS_EXT_IN_60_DEG_RST 2500
151#define BRUSHLESS8_LAS_EXT_IN_360_DEG_RST 3750
158#define BRUSHLESS8_LA_STEP_0_DEG_0 0
159#define BRUSHLESS8_LA_STEP_1_DEG_1p9 160
160#define BRUSHLESS8_LA_STEP_2_DEG_3p8 310
161#define BRUSHLESS8_LA_STEP_3_DEG_5p6 470
162#define BRUSHLESS8_LA_STEP_4_DEG_7p5 630
163#define BRUSHLESS8_LA_STEP_5_DEG_9p4 780
164#define BRUSHLESS8_LA_STEP_6_DEG_11p3 940
165#define BRUSHLESS8_LA_STEP_7_DEG_13p1 1090
166#define BRUSHLESS8_LA_STEP_8_DEG_15 1250
167#define BRUSHLESS8_LA_STEP_9_DEG_16p9 1410
168#define BRUSHLESS8_LA_STEP_10_DEG_18p8 1560
169#define BRUSHLESS8_LA_STEP_11_DEG_20p6 1720
170#define BRUSHLESS8_LA_STEP_12_DEG_22p5 1880
171#define BRUSHLESS8_LA_STEP_13_DEG_24p4 2030
172#define BRUSHLESS8_LA_STEP_14_DEG_26p3 2190
173#define BRUSHLESS8_LA_STEP_15_DEG_28p1 2340
174#define BRUSHLESS8_LA_STEP_16_DEG_30 2500
175#define BRUSHLESS8_LA_STEP_17_DEG_31p9 2660
176#define BRUSHLESS8_LA_STEP_18_DEG_33p8 2810
177#define BRUSHLESS8_LA_STEP_19_DEG_35p6 2970
178#define BRUSHLESS8_LA_STEP_20_DEG_37p5 3130
179#define BRUSHLESS8_LA_STEP_21_DEG_39p4 3280
180#define BRUSHLESS8_LA_STEP_22_DEG_41p3 3440
181#define BRUSHLESS8_LA_STEP_23_DEG_43p1 3590
182#define BRUSHLESS8_LA_STEP_24_DEG_45 3750
183#define BRUSHLESS8_LA_STEP_25_DEG_46p9 3910
184#define BRUSHLESS8_LA_STEP_26_DEG_48p8 4060
185#define BRUSHLESS8_LA_STEP_27_DEG_50p6 4220
186#define BRUSHLESS8_LA_STEP_28_DEG_52p5 4380
187#define BRUSHLESS8_LA_STEP_29_DEG_54p4 4530
188#define BRUSHLESS8_LA_STEP_30_DEG_56p3 4690
189#define BRUSHLESS8_LA_STEP_31_DEG_58p1 4840
196#define BRUSHLESS8_LAL_STEP_0_DEG_0 0
197#define BRUSHLESS8_LAL_STEP_1_DEG_5p6 310
198#define BRUSHLESS8_LAL_STEP_2_DEG_0 630
199#define BRUSHLESS8_LAL_STEP_3_DEG_11p3 640
200#define BRUSHLESS8_LAL_STEP_4_DEG_5p6 1250
201#define BRUSHLESS8_LAL_STEP_5_DEG_0 1560
202#define BRUSHLESS8_LAL_STEP_6_DEG_12p2 1880
203#define BRUSHLESS8_LAL_STEP_7_DEG_6p6 2190
204#define BRUSHLESS8_LAL_STEP_8_DEG_0 2500
205#define BRUSHLESS8_LAL_STEP_9_DEG_13p1 2810
206#define BRUSHLESS8_LAL_STEP_10_DEG_7p5 3130
207#define BRUSHLESS8_LAL_STEP_11_DEG_0 3440
208#define BRUSHLESS8_LAL_STEP_12_DEG_18p8 3750
209#define BRUSHLESS8_LAL_STEP_13_DEG_13p1 4060
210#define BRUSHLESS8_LAL_STEP_14_DEG_7p5 4380
211#define BRUSHLESS8_LAL_STEP_15_DEG_0 4690
218#define BRUSHLESS8_LAAJ_STEP_0_PHASE_DEG_0 0
219#define BRUSHLESS8_LAAJ_STEP_1_PHASE_DEG_0 80
220#define BRUSHLESS8_LAAJ_STEP_2_PHASE_DEG_0 160
221#define BRUSHLESS8_LAAJ_STEP_3_PHASE_DEG_0 230
222#define BRUSHLESS8_LAAJ_STEP_4_PHASE_DEG_0 310
223#define BRUSHLESS8_LAAJ_STEP_5_PHASE_DEG_0 390
224#define BRUSHLESS8_LAAJ_STEP_6_PHASE_DEG_0 470
225#define BRUSHLESS8_LAAJ_STEP_7_PHASE_DEG_0 550
226#define BRUSHLESS8_LAAJ_STEP_8_PHASE_DEG_0p9 630
227#define BRUSHLESS8_LAAJ_STEP_9_PHASE_DEG_1p9 700
228#define BRUSHLESS8_LAAJ_STEP_10_PHASE_DEG_2p8 780
229#define BRUSHLESS8_LAAJ_STEP_11_PHASE_DEG_3p8 860
230#define BRUSHLESS8_LAAJ_STEP_12_PHASE_DEG_4p7 940
231#define BRUSHLESS8_LAAJ_STEP_13_PHASE_DEG_5p6 1020
232#define BRUSHLESS8_LAAJ_STEP_14_PHASE_DEG_6p6 1090
233#define BRUSHLESS8_LAAJ_STEP_15_PHASE_DEG_7p5 1170
234#define BRUSHLESS8_LAAJ_STEP_16_PHASE_DEG_8p4 1250
235#define BRUSHLESS8_LAAJ_STEP_17_PHASE_DEG_9p4 1330
236#define BRUSHLESS8_LAAJ_STEP_18_PHASE_DEG_10p3 1410
237#define BRUSHLESS8_LAAJ_STEP_19_PHASE_DEG_11p3 1480
238#define BRUSHLESS8_LAAJ_STEP_20_PHASE_DEG_12p2 1560
239#define BRUSHLESS8_LAAJ_STEP_21_PHASE_DEG_13p1 1640
240#define BRUSHLESS8_LAAJ_STEP_22_PHASE_DEG_13p1 1720
241#define BRUSHLESS8_LAAJ_STEP_23_PHASE_DEG_15 1800
242#define BRUSHLESS8_LAAJ_STEP_24_PHASE_DEG_15p9 1880
243#define BRUSHLESS8_LAAJ_STEP_25_PHASE_DEG_16p9 1950
244#define BRUSHLESS8_LAAJ_STEP_26_PHASE_DEG_17p8 2030
245#define BRUSHLESS8_LAAJ_STEP_27_PHASE_DEG_18p8 2110
246#define BRUSHLESS8_LAAJ_STEP_28_PHASE_DEG_19p7 2190
247#define BRUSHLESS8_LAAJ_STEP_29_PHASE_DEG_20p6 2270
248#define BRUSHLESS8_LAAJ_STEP_30_PHASE_DEG_21p6 2340
249#define BRUSHLESS8_LAAJ_STEP_31_PHASE_DEG_22p5 2420
250#define BRUSHLESS8_LAAJ_STEP_32_PHASE_DEG_23p4 2500
251#define BRUSHLESS8_LAAJ_STEP_33_PHASE_DEG_24p4 2580
252#define BRUSHLESS8_LAAJ_STEP_34_PHASE_DEG_25p3 2660
253#define BRUSHLESS8_LAAJ_STEP_35_PHASE_DEG_26p3 2730
254#define BRUSHLESS8_LAAJ_STEP_36_PHASE_DEG_27p2 2810
255#define BRUSHLESS8_LAAJ_STEP_37_PHASE_DEG_28p1 2890
256#define BRUSHLESS8_LAAJ_STEP_38_PHASE_DEG_29p1 2970
257#define BRUSHLESS8_LAAJ_STEP_39_PHASE_DEG_30 3050
258#define BRUSHLESS8_LAAJ_STEP_40_PHASE_DEG_30 3130
259#define BRUSHLESS8_LAAJ_STEP_41_PHASE_DEG_30 3200
260#define BRUSHLESS8_LAAJ_STEP_42_PHASE_DEG_30 3280
261#define BRUSHLESS8_LAAJ_STEP_43_PHASE_DEG_30 3360
262#define BRUSHLESS8_LAAJ_STEP_44_PHASE_DEG_30 3440
263#define BRUSHLESS8_LAAJ_STEP_45_PHASE_DEG_30 3520
264#define BRUSHLESS8_LAAJ_STEP_46_PHASE_DEG_30 3590
265#define BRUSHLESS8_LAAJ_STEP_47_PHASE_DEG_30 3670
266#define BRUSHLESS8_LAAJ_STEP_48_PHASE_DEG_30 3750
267#define BRUSHLESS8_LAAJ_STEP_49_PHASE_DEG_30 3830
268#define BRUSHLESS8_LAAJ_STEP_50_PHASE_DEG_30 3910
269#define BRUSHLESS8_LAAJ_STEP_51_PHASE_DEG_30 3980
270#define BRUSHLESS8_LAAJ_STEP_52_PHASE_DEG_30 4060
271#define BRUSHLESS8_LAAJ_STEP_53_PHASE_DEG_30 4140
272#define BRUSHLESS8_LAAJ_STEP_54_PHASE_DEG_30 4220
273#define BRUSHLESS8_LAAJ_STEP_55_PHASE_DEG_30 4300
274#define BRUSHLESS8_LAAJ_STEP_56_PHASE_DEG_30 4380
275#define BRUSHLESS8_LAAJ_STEP_57_PHASE_DEG_30 4450
276#define BRUSHLESS8_LAAJ_STEP_58_PHASE_DEG_30 4530
277#define BRUSHLESS8_LAAJ_STEP_59_PHASE_DEG_30 4610
278#define BRUSHLESS8_LAAJ_STEP_60_PHASE_DEG_30 4690
279#define BRUSHLESS8_LAAJ_STEP_61_PHASE_DEG_30 4770
280#define BRUSHLESS8_LAAJ_STEP_62_PHASE_DEG_30 4840
281#define BRUSHLESS8_LAAJ_STEP_63_PHASE_DEG_30 4920
288#define BRUSHLESS8_SLAVE_ADDRESS_1 0x47
289#define BRUSHLESS8_SLAVE_ADDRESS_2 0x48
295#define BRUSHLESS8_DAC 1
296#define BRUSHLESS8_PWM 2
314#define BRUSHLESS8_MAP_MIKROBUS( cfg, mikrobus ) \
315 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
316 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
317 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_CS ); \
318 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
319 cfg.res = MIKROBUS( mikrobus, MIKROBUS_RST ); \
320 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
321 cfg.fg = MIKROBUS( mikrobus, MIKROBUS_INT )
struct brushless8_s brushless8_t
Brushless 8 Click context object.
#define BRUSHLESS8_RETVAL
Brushless 8 function status.
Definition brushless8.h:123
void brushless8_pwm_start(brushless8_t *ctx)
Starts PWM module.
BRUSHLESS8_RETVAL brushless8_read_an_voltage(brushless8_t *ctx, float *data_out)
AN voltage read function.
uint16_t brushless8_dac_read_data(brushless8_t *ctx, uint8_t reg)
Brushless 8 I2C read function.
void brushless8_set_direction(brushless8_t *ctx, uint8_t status)
Brushless 8 dir pin setting.
int8_t brushless8_set_dac_vout(brushless8_t *ctx, uint8_t dac_chn, uint16_t vout)
Brushless 8 I2C function for setting vout.
uint8_t brushless8_get_fg(brushless8_t *ctx)
Brushless 8 fg state.
void brushless8_set_duty_cycle(brushless8_t *ctx, float duty_cycle)
Sets PWM duty cycle.
BRUSHLESS8_RETVAL brushless8_init(brushless8_t *ctx, brushless8_cfg_t *cfg)
Brushless 8 initialization function.
void brushless8_cfg_setup(brushless8_cfg_t *cfg)
Brushless 8 configuration object setup function.
void brushless8_set_reset(brushless8_t *ctx, uint8_t status)
Brushless 8 rst pin setting.
void brushless8_dac_write_data(brushless8_t *ctx, uint8_t reg, uint16_t write_data)
Brushless 8 I2C write function.
BRUSHLESS8_RETVAL brushless8_read_adc(brushless8_t *ctx, uint16_t *data_out)
ADC read function.
void brushless8_pwm_stop(brushless8_t *ctx)
Stops PWM module.
BRUSHLESS8_RETVAL brushless8_default_cfg(brushless8_t *ctx)
Brushless 8 default configuration function.
Brushless 8 Click configuration object.
Definition brushless8.h:355
pin_name_t fg
Definition brushless8.h:362
analog_in_resolution_t resolution
Definition brushless8.h:369
float vref
Definition brushless8.h:370
uint8_t ctrl_mod
Definition brushless8.h:372
uint32_t i2c_speed
Definition brushless8.h:364
uint32_t dev_pwm_freq
Definition brushless8.h:367
pin_name_t dir
Definition brushless8.h:358
pin_name_t scl
Definition brushless8.h:356
pin_name_t pwm
Definition brushless8.h:361
pin_name_t res
Definition brushless8.h:360
pin_name_t sda
Definition brushless8.h:357
pin_name_t an
Definition brushless8.h:359
uint8_t i2c_address
Definition brushless8.h:365
Brushless 8 Click context object.
Definition brushless8.h:331
digital_out_t res
Definition brushless8.h:333
uint8_t ctrl_mod
Definition brushless8.h:347
uint32_t pwm_freq
Definition brushless8.h:345
i2c_master_t i2c
Definition brushless8.h:338
digital_in_t an
Definition brushless8.h:335
uint8_t slave_address
Definition brushless8.h:342
digital_in_t fg
Definition brushless8.h:336
analog_in_t adc
Definition brushless8.h:340
pwm_t pwm
Definition brushless8.h:339
uint16_t pwm_period
Definition brushless8.h:344
digital_out_t dir
Definition brushless8.h:332