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_spi_master.h"
74#define HBRIDGE9_OPCODE_WRITE 0x00
75#define HBRIDGE9_OPCODE_READ 0x40
76#define HBRIDGE9_OPCODE_READ_CLEAR 0x80
77#define HBRIDGE9_OPCODE_READ_DEV_INFO 0xC0
78#define HBRIDGE9_ADV_OPCODE_SET_DEFAULT 0xFF
79#define HBRIDGE9_ADV_OPCODE_CLEAR_STATUS 0xBF
80#define HBRIDGE9_OPCODE_BITS_MASK 0xC0
86#define HBRIDGE9_REG_CR0 0x00
87#define HBRIDGE9_REG_CR1 0x01
88#define HBRIDGE9_REG_CR2 0x02
89#define HBRIDGE9_REG_CR3 0x03
90#define HBRIDGE9_REG_CR4 0x04
91#define HBRIDGE9_REG_CR5 0x05
92#define HBRIDGE9_REG_CR6 0x06
93#define HBRIDGE9_REG_CR7 0x07
94#define HBRIDGE9_REG_CR8 0x08
100#define HBRIDGE9_REG_SR0 0x10
101#define HBRIDGE9_REG_SR1 0x11
102#define HBRIDGE9_REG_SR2 0x12
103#define HBRIDGE9_REG_SR3 0x13
104#define HBRIDGE9_REG_SR4 0x14
105#define HBRIDGE9_REG_SR5 0x15
106#define HBRIDGE9_REG_SR6 0x16
107#define HBRIDGE9_REG_SR7 0x17
108#define HBRIDGE9_REG_SR8 0x18
114#define HBRIDGE9_REG_INFO_COMPANY_CODE 0x00
115#define HBRIDGE9_REG_INFO_DEVICE_FAMILY 0x01
116#define HBRIDGE9_REG_INFO_DEVICE_NO_1 0x02
117#define HBRIDGE9_REG_INFO_DEVICE_NO_2 0x03
118#define HBRIDGE9_REG_INFO_DEVICE_NO_3 0x04
119#define HBRIDGE9_REG_INFO_DEVICE_NO_4 0x05
120#define HBRIDGE9_REG_INFO_SILICON_VER 0x0A
121#define HBRIDGE9_REG_INFO_SPI_MODE 0x10
122#define HBRIDGE9_REG_INFO_SPI_CPHA_TEST 0x20
140#define HBRIDGE9_SPI_CPHA_TEST 0x55
146#define HBRIDGE9_ODD_PARITY 0x01
152#define HBRIDGE9_CR0_PWM_FREQ_10p240 0x0000
153#define HBRIDGE9_CR0_PWM_FREQ_12p288 0x2000
154#define HBRIDGE9_CR0_PWM_FREQ_14p336 0x4000
155#define HBRIDGE9_CR0_PWM_FREQ_16p384 0x6000
156#define HBRIDGE9_CR0_PWM_FREQ_18p432 0x8000
157#define HBRIDGE9_CR0_PWM_FREQ_20p480 0xA000
158#define HBRIDGE9_CR0_PWM_FREQ_22p528 0xC000
159#define HBRIDGE9_CR0_PWM_FREQ_24p576 0xE000
160#define HBRIDGE9_CR0_PWM_FREQ_MASK 0xE000
161#define HBRIDGE9_CR0_OUT6_POL_HIGH 0x1000
162#define HBRIDGE9_CR0_OUT6_POL_LOW 0x0040
163#define HBRIDGE9_CR0_OUT6_POL_MASK 0x1040
164#define HBRIDGE9_CR0_OUT5_POL_HIGH 0x0800
165#define HBRIDGE9_CR0_OUT5_POL_LOW 0x0020
166#define HBRIDGE9_CR0_OUT5_POL_MASK 0x0820
167#define HBRIDGE9_CR0_OUT4_POL_HIGH 0x0400
168#define HBRIDGE9_CR0_OUT4_POL_LOW 0x0010
169#define HBRIDGE9_CR0_OUT4_POL_MASK 0x0410
170#define HBRIDGE9_CR0_OUT3_POL_HIGH 0x0200
171#define HBRIDGE9_CR0_OUT3_POL_LOW 0x0008
172#define HBRIDGE9_CR0_OUT3_POL_MASK 0x0208
173#define HBRIDGE9_CR0_OUT2_POL_HIGH 0x0100
174#define HBRIDGE9_CR0_OUT2_POL_LOW 0x0004
175#define HBRIDGE9_CR0_OUT2_POL_MASK 0x0104
176#define HBRIDGE9_CR0_OUT1_POL_HIGH 0x0080
177#define HBRIDGE9_CR0_OUT1_POL_LOW 0x0002
178#define HBRIDGE9_CR0_OUT1_POL_MASK 0x0082
184#define HBRIDGE9_CR1_EX_OUT2_ON 0x8000
185#define HBRIDGE9_CR1_EX_OUT1_ON 0x4000
186#define HBRIDGE9_CR1_EX_OUT_MASK 0xC000
187#define HBRIDGE9_CR1_OUT6_ON 0x2000
188#define HBRIDGE9_CR1_OUT5_ON 0x1000
189#define HBRIDGE9_CR1_OUT4_ON 0x0800
190#define HBRIDGE9_CR1_OUT3_ON 0x0400
191#define HBRIDGE9_CR1_OUT2_ON 0x0200
192#define HBRIDGE9_CR1_OUT1_ON 0x0100
193#define HBRIDGE9_CR1_OUT_MASK 0x3F00
194#define HBRIDGE9_CR1_EMCY_NORMAL_MODE 0x0000
195#define HBRIDGE9_CR1_EMCY_EMERGENCY_MODE 0x0080
196#define HBRIDGE9_CR1_EMCY_MASK 0x00C0
197#define HBRIDGE9_CR1_EX_OUT2_POL_HIGH 0x0020
198#define HBRIDGE9_CR1_EX_OUT2_POL_LOW 0x0008
199#define HBRIDGE9_CR1_EX_OUT2_POL_MASK 0x0028
200#define HBRIDGE9_CR1_EX_OUT1_POL_HIGH 0x0010
201#define HBRIDGE9_CR1_EX_OUT1_POL_LOW 0x0004
202#define HBRIDGE9_CR1_EX_OUT1_POL_MASK 0x0014
203#define HBRIDGE9_CR1_OUT_ON 0x0002
209#define HBRIDGE9_CR2_DBN_EX2 0x8000
210#define HBRIDGE9_CR2_DBN_EX1 0x4000
211#define HBRIDGE9_CR2_DBN_EX_MASK 0xC000
212#define HBRIDGE9_CR2_DBN_6 0x2000
213#define HBRIDGE9_CR2_DBN_5 0x1000
214#define HBRIDGE9_CR2_DBN_4 0x0800
215#define HBRIDGE9_CR2_DBN_3 0x0400
216#define HBRIDGE9_CR2_DBN_2 0x0200
217#define HBRIDGE9_CR2_DBN_1 0x0100
218#define HBRIDGE9_CR2_DBN_MASK 0x3F00
219#define HBRIDGE9_CR2_ON_TIME_DUR_100MS 0x0000
220#define HBRIDGE9_CR2_ON_TIME_DUR_120MS 0x0008
221#define HBRIDGE9_CR2_ON_TIME_DUR_140MS 0x0010
222#define HBRIDGE9_CR2_ON_TIME_DUR_160MS 0x0018
223#define HBRIDGE9_CR2_ON_TIME_DUR_180MS 0x0020
224#define HBRIDGE9_CR2_ON_TIME_DUR_200MS 0x0028
225#define HBRIDGE9_CR2_ON_TIME_DUR_220MS 0x0030
226#define HBRIDGE9_CR2_ON_TIME_DUR_240MS 0x0038
227#define HBRIDGE9_CR2_ON_TIME_DUR_260MS 0x0040
228#define HBRIDGE9_CR2_ON_TIME_DUR_280MS 0x0048
229#define HBRIDGE9_CR2_ON_TIME_DUR_300MS 0x0050
230#define HBRIDGE9_CR2_ON_TIME_DUR_320MS 0x0058
231#define HBRIDGE9_CR2_ON_TIME_DUR_340MS 0x0060
232#define HBRIDGE9_CR2_ON_TIME_DUR_360MS 0x0068
233#define HBRIDGE9_CR2_ON_TIME_DUR_380MS 0x0070
234#define HBRIDGE9_CR2_ON_TIME_DUR_400MS 0x0078
235#define HBRIDGE9_CR2_ON_TIME_DUR_440MS 0x0080
236#define HBRIDGE9_CR2_ON_TIME_DUR_480MS 0x0088
237#define HBRIDGE9_CR2_ON_TIME_DUR_520MS 0x0090
238#define HBRIDGE9_CR2_ON_TIME_DUR_560MS 0x0098
239#define HBRIDGE9_CR2_ON_TIME_DUR_600MS 0x00A0
240#define HBRIDGE9_CR2_ON_TIME_DUR_640MS 0x00A8
241#define HBRIDGE9_CR2_ON_TIME_DUR_680MS 0x00B0
242#define HBRIDGE9_CR2_ON_TIME_DUR_720MS 0x00B8
243#define HBRIDGE9_CR2_ON_TIME_DUR_760MS 0x00C0
244#define HBRIDGE9_CR2_ON_TIME_DUR_800MS 0x00C8
245#define HBRIDGE9_CR2_ON_TIME_DUR_840MS 0x00D0
246#define HBRIDGE9_CR2_ON_TIME_DUR_880MS 0x00D8
247#define HBRIDGE9_CR2_ON_TIME_DUR_920MS 0x00E0
248#define HBRIDGE9_CR2_ON_TIME_DUR_960MS 0x00E8
249#define HBRIDGE9_CR2_ON_TIME_DUR_1000MS 0x00F0
250#define HBRIDGE9_CR2_ON_TIME_DUR_1040MS 0x00F8
251#define HBRIDGE9_CR2_ON_TIME_DUR_MASK 0x00F8
252#define HBRIDGE9_CR2_BRAKING_DUR_0MS 0x0000
253#define HBRIDGE9_CR2_BRAKING_DUR_100MS 0x0002
254#define HBRIDGE9_CR2_BRAKING_DUR_200MS 0x0004
255#define HBRIDGE9_CR2_BRAKING_DUR_100MS_IND 0x0006
256#define HBRIDGE9_CR2_BRAKING_DUR_MASK 0x0006
262#define HBRIDGE9_CR3_GFI 0x0080
263#define HBRIDGE9_CR3_TSD_ACT 0x0040
264#define HBRIDGE9_CR3_DITHN 0x0020
265#define HBRIDGE9_CR3_NO_GROUP 0x0000
266#define HBRIDGE9_CR3_GROUP_1_2 0x0002
267#define HBRIDGE9_CR3_GROUP_1_3 0x0004
268#define HBRIDGE9_CR3_GROUP_1_2_3 0x0006
269#define HBRIDGE9_CR3_GROUP_4_5 0x0008
270#define HBRIDGE9_CR3_GROUP_4_6 0x0010
271#define HBRIDGE9_CR3_GROUP_4_5_6 0x0018
272#define HBRIDGE9_CR3_GROUP_MASK 0x001E
278#define HBRIDGE9_CR4_OCP1_SHIFT_BITS 0x0001
279#define HBRIDGE9_CR4_OCP2_SHIFT_BITS 0x0006
280#define HBRIDGE9_CR4_OCP3_SHIFT_BITS 0x000B
281#define HBRIDGE9_CR5_OCP4_SHIFT_BITS 0x0001
282#define HBRIDGE9_CR5_OCP5_SHIFT_BITS 0x0006
283#define HBRIDGE9_CR5_OCP6_SHIFT_BITS 0x000B
284#define HBRIDGE9_DUTY_CYCLE_6p25 0x0000
285#define HBRIDGE9_DUTY_CYCLE_12p5 0x0001
286#define HBRIDGE9_DUTY_CYCLE_18p75 0x0002
287#define HBRIDGE9_DUTY_CYCLE_25 0x0003
288#define HBRIDGE9_DUTY_CYCLE_31p25 0x0004
289#define HBRIDGE9_DUTY_CYCLE_37p5 0x0005
290#define HBRIDGE9_DUTY_CYCLE_43p75 0x0006
291#define HBRIDGE9_DUTY_CYCLE_50 0x0007
292#define HBRIDGE9_DUTY_CYCLE_56p25 0x0008
293#define HBRIDGE9_DUTY_CYCLE_62p5 0x0009
294#define HBRIDGE9_DUTY_CYCLE_68p75 0x000A
295#define HBRIDGE9_DUTY_CYCLE_75 0x000B
296#define HBRIDGE9_DUTY_CYCLE_81p25 0x000C
297#define HBRIDGE9_DUTY_CYCLE_87p5 0x000D
298#define HBRIDGE9_DUTY_CYCLE_93p75 0x000E
299#define HBRIDGE9_DUTY_CYCLE_100 0x000F
300#define HBRIDGE9_DUTY_CYCLE_MASK 0x001F
301#define HBRIDGE9_CURRENT_1A 0x0010
302#define HBRIDGE9_CURRENT_1p2A 0x0011
303#define HBRIDGE9_CURRENT_1p4A 0x0012
304#define HBRIDGE9_CURRENT_1p6A 0x0013
305#define HBRIDGE9_CURRENT_1p8A 0x0014
306#define HBRIDGE9_CURRENT_2A 0x0015
307#define HBRIDGE9_CURRENT_2p2A 0x0016
308#define HBRIDGE9_CURRENT_2p4A 0x0017
309#define HBRIDGE9_CURRENT_2p6A 0x0018
310#define HBRIDGE9_CURRENT_2p8A 0x0019
311#define HBRIDGE9_CURRENT_3A 0x001A
312#define HBRIDGE9_CURRENT_3p2A 0x001B
313#define HBRIDGE9_CURRENT_3p4A 0x001C
314#define HBRIDGE9_CURRENT_3p6A 0x001D
315#define HBRIDGE9_CURRENT_3p8A 0x001E
316#define HBRIDGE9_CURRENT_4A 0x001F
317#define HBRIDGE9_CURRENT_MASK 0x001F
323#define HBRIDGE9_CR6_HBDCL2 0x8000
324#define HBRIDGE9_CR6_HBDCH2 0x4000
325#define HBRIDGE9_CR6_HBDC2_MASK 0xC000
326#define HBRIDGE9_CR6_STBY1 0x2000
327#define HBRIDGE9_CR6_EXT2_VDT_1US 0x0000
328#define HBRIDGE9_CR6_EXT2_VDT_2US 0x0800
329#define HBRIDGE9_CR6_EXT2_VDT_3US 0x1000
330#define HBRIDGE9_CR6_EXT2_VDT_4US 0x1800
331#define HBRIDGE9_CR6_EXT2_VDT_MASK 0x1800
332#define HBRIDGE9_CR6_EXT1_VDT_1US 0x0000
333#define HBRIDGE9_CR6_EXT1_VDT_2US 0x0200
334#define HBRIDGE9_CR6_EXT1_VDT_3US 0x0400
335#define HBRIDGE9_CR6_EXT1_VDT_4US 0x0600
336#define HBRIDGE9_CR6_EXT1_VDT_MASK 0x0600
337#define HBRIDGE9_CR6_EXT2_VDS_OFF 0x0000
338#define HBRIDGE9_CR6_EXT2_VDS_0p25V 0x0100
339#define HBRIDGE9_CR6_EXT2_VDS_0p5V 0x0120
340#define HBRIDGE9_CR6_EXT2_VDS_0p75V 0x0140
341#define HBRIDGE9_CR6_EXT2_VDS_1V 0x0160
342#define HBRIDGE9_CR6_EXT2_VDS_1p25V 0x0180
343#define HBRIDGE9_CR6_EXT2_VDS_1p5V 0x01A0
344#define HBRIDGE9_CR6_EXT2_VDS_1p75V 0x01C0
345#define HBRIDGE9_CR6_EXT2_VDS_2V 0x01E0
346#define HBRIDGE9_CR6_EXT2_VDS_MASK 0x01E0
347#define HBRIDGE9_CR6_EXT1_VDS_OFF 0x0000
348#define HBRIDGE9_CR6_EXT1_VDS_0p25V 0x0010
349#define HBRIDGE9_CR6_EXT1_VDS_0p5V 0x0012
350#define HBRIDGE9_CR6_EXT1_VDS_0p75V 0x0014
351#define HBRIDGE9_CR6_EXT1_VDS_1V 0x0016
352#define HBRIDGE9_CR6_EXT1_VDS_1p25V 0x0018
353#define HBRIDGE9_CR6_EXT1_VDS_1p5V 0x001A
354#define HBRIDGE9_CR6_EXT1_VDS_1p75V 0x001C
355#define HBRIDGE9_CR6_EXT1_VDS_2V 0x001E
356#define HBRIDGE9_CR6_EXT1_VDS_MASK 0x001E
362#define HBRIDGE9_CR7_HBDCL1 0x8000
363#define HBRIDGE9_CR7_HBDCH1 0x4000
364#define HBRIDGE9_CR7_HBDC1_MASK 0xC000
365#define HBRIDGE9_CR7_STBY2 0x2000
366#define HBRIDGE9_CR7_ODCL6 0x1000
367#define HBRIDGE9_CR7_ODCH6 0x0800
368#define HBRIDGE9_CR7_ODC6_MASK 0x1800
369#define HBRIDGE9_CR7_ODCL5 0x0400
370#define HBRIDGE9_CR7_ODCH5 0x0200
371#define HBRIDGE9_CR7_ODC5_MASK 0x0600
372#define HBRIDGE9_CR7_ODCL4 0x0100
373#define HBRIDGE9_CR7_ODCH4 0x0080
374#define HBRIDGE9_CR7_ODC4_MASK 0x0180
375#define HBRIDGE9_CR7_ODCL3 0x0040
376#define HBRIDGE9_CR7_ODCH3 0x0020
377#define HBRIDGE9_CR7_ODC3_MASK 0x0060
378#define HBRIDGE9_CR7_ODCL2 0x0010
379#define HBRIDGE9_CR7_ODCH2 0x0008
380#define HBRIDGE9_CR7_ODC2_MASK 0x0018
381#define HBRIDGE9_CR7_ODCL1 0x0004
382#define HBRIDGE9_CR7_ODCH1 0x0002
383#define HBRIDGE9_CR7_ODC1_MASK 0x0006
389#define HBRIDGE9_CR8_KI_GAIN_1_OVER_128 0x0000
390#define HBRIDGE9_CR8_KI_GAIN_1_OVER_64 0x0010
391#define HBRIDGE9_CR8_KI_GAIN_1_OVER_32 0x0020
392#define HBRIDGE9_CR8_KI_GAIN_1_OVER_16 0x0030
393#define HBRIDGE9_CR8_KI_GAIN_1_OVER_8 0x0040
394#define HBRIDGE9_CR8_KI_GAIN_1_OVER_4 0x0050
395#define HBRIDGE9_CR8_KI_GAIN_1_OVER_2 0x0060
396#define HBRIDGE9_CR8_KI_GAIN_1 0x0070
397#define HBRIDGE9_CR8_KI_GAIN_MASK 0x0070
398#define HBRIDGE9_CR8_KP_GAIN_2 0x0000
399#define HBRIDGE9_CR8_KP_GAIN_4 0x0001
400#define HBRIDGE9_CR8_KP_GAIN_8 0x0002
401#define HBRIDGE9_CR8_KP_GAIN_16 0x0003
402#define HBRIDGE9_CR8_KP_GAIN_32 0x0004
403#define HBRIDGE9_CR8_KP_GAIN_64 0x0005
404#define HBRIDGE9_CR8_KP_GAIN_128 0x0006
405#define HBRIDGE9_CR8_KP_GAIN_256 0x0007
406#define HBRIDGE9_CR8_KP_GAIN_MASK 0x0007
416#define HBRIDGE9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
417#define HBRIDGE9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
435#define HBRIDGE9_MAP_MIKROBUS( cfg, mikrobus ) \
436 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
437 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
438 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
439 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
440 cfg.en_out = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
441 cfg.dout = MIKROBUS( mikrobus, MIKROBUS_INT )
err_t hbridge9_init(hbridge9_t *ctx, hbridge9_cfg_t *cfg)
H-Bridge 9 initialization function.
void hbridge9_send_actuation_pulse(hbridge9_t *ctx)
H-Bridge 9 send actuation pulse function.
err_t hbridge9_modify_register_bits(hbridge9_t *ctx, uint8_t reg, uint16_t clr_mask, uint16_t set_mask)
H-Bridge 9 modify register bits function.
err_t hbridge9_default_cfg(hbridge9_t *ctx)
H-Bridge 9 default configuration function.
err_t hbridge9_check_communication(hbridge9_t *ctx)
H-Bridge 9 check communication function.
err_t hbridge9_read_register_and_clear(hbridge9_t *ctx, uint8_t reg, uint16_t *data_out)
H-Bridge 9 read register and clear function.
err_t hbridge9_spi_transfer(hbridge9_t *ctx, uint8_t *data_in, uint8_t tx_len, uint8_t *data_out, uint8_t rx_len)
H-Bridge 9 spi transfer function.
err_t hbridge9_read_info_register(hbridge9_t *ctx, uint8_t reg, uint8_t *data_out)
H-Bridge 9 read info register function.
err_t hbridge9_write_register(hbridge9_t *ctx, uint8_t reg, uint16_t data_in)
H-Bridge 9 write register function.
err_t hbridge9_clear_all_status(hbridge9_t *ctx)
H-Bridge 9 clear all status function.
err_t hbridge9_read_register(hbridge9_t *ctx, uint8_t reg, uint16_t *data_out)
H-Bridge 9 read register function.
err_t hbridge9_set_default(hbridge9_t *ctx)
H-Bridge 9 set default function.
void hbridge9_set_en_out_pin(hbridge9_t *ctx, uint8_t state)
H-Bridge 9 set en out pin function.
void hbridge9_cfg_setup(hbridge9_cfg_t *cfg)
H-Bridge 9 configuration object setup function.
uint8_t hbridge9_get_dout_pin(hbridge9_t *ctx)
H-Bridge 9 get dout pin function.
hbridge9_return_value_t
H-Bridge 9 Click return value data.
Definition hbridge9.h:495
@ HBRIDGE9_OK
Definition hbridge9.h:496
@ HBRIDGE9_ERROR
Definition hbridge9.h:497
This file contains SPI specific macros, functions, etc.
H-Bridge 9 Click configuration object.
Definition hbridge9.h:472
spi_master_chip_select_polarity_t cs_polarity
Definition hbridge9.h:486
pin_name_t sck
Definition hbridge9.h:476
spi_master_mode_t spi_mode
Definition hbridge9.h:485
pin_name_t en_out
Definition hbridge9.h:480
pin_name_t mosi
Definition hbridge9.h:475
uint32_t spi_speed
Definition hbridge9.h:484
pin_name_t dout
Definition hbridge9.h:481
pin_name_t miso
Definition hbridge9.h:474
pin_name_t cs
Definition hbridge9.h:477
H-Bridge 9 Click context object.
Definition hbridge9.h:451
spi_master_t spi
Definition hbridge9.h:459
uint8_t global_status
Definition hbridge9.h:463
digital_in_t dout
Definition hbridge9.h:456
pin_name_t chip_select
Definition hbridge9.h:461
digital_out_t en_out
Definition hbridge9.h:453