Go to the documentation of this file.
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
39 #include "drv_i2c_master.h"
41 #include "drv_analog_in.h"
63 #define DCMOTOR12_REG_STATUS1 0x01
64 #define DCMOTOR12_REG_STATUS2 0x02
65 #define DCMOTOR12_REG_STATUS3 0x03
66 #define DCMOTOR12_REG_CONFIG1 0x04
67 #define DCMOTOR12_REG_CONFIG2 0x05
68 #define DCMOTOR12_REG_CONFIG3 0x06
69 #define DCMOTOR12_REG_CONFIG4 0x07
70 #define DCMOTOR12_REG_CONFIG5 0x08
71 #define DCMOTOR12_REG_CONFIG6 0x09
72 #define DCMOTOR12_REG_CONFIG7 0x0A
78 #define DCMOTOR12_REG_INPUT 0x00
79 #define DCMOTOR12_REG_OUTPUT 0x01
80 #define DCMOTOR12_REG_POLARITY 0x02
81 #define DCMOTOR12_REG_CONFIG 0x03
99 #define DCMOTOR12_CONFIG12_OPEN_LOAD_NOP_100US 0x000000ul
100 #define DCMOTOR12_CONFIG12_OPEN_LOAD_NOP_50US 0x002000ul
101 #define DCMOTOR12_CONFIG12_OPEN_LOAD_NOP_500US 0x004000ul
102 #define DCMOTOR12_CONFIG12_OPEN_LOAD_NOP_MASK 0x006000ul
103 #define DCMOTOR12_CONFIG12_DUTY_OFF_LOW_SIDE 0x000000ul
104 #define DCMOTOR12_CONFIG12_DUTY_OFF_HIGH_SIDE 0x001000ul
105 #define DCMOTOR12_CONFIG12_DUTY_OFF_MASK 0x001000ul
106 #define DCMOTOR12_CONFIG12_VBAT_UVC_0US 0x000000ul
107 #define DCMOTOR12_CONFIG12_VBAT_UVC_100US 0x000800ul
108 #define DCMOTOR12_CONFIG12_VBAT_UVC_MASK 0x000800ul
109 #define DCMOTOR12_CONFIG12_CLIMIT_UP_6p5A 0x000000ul
110 #define DCMOTOR12_CONFIG12_CLIMIT_UP_4p6A 0x000400ul
111 #define DCMOTOR12_CONFIG12_CLIMIT_UP_MASK 0x000400ul
112 #define DCMOTOR12_CONFIG12_CLIMIT_LOW_0p25A 0x000000ul
113 #define DCMOTOR12_CONFIG12_CLIMIT_LOW_0p5A 0x000200ul
114 #define DCMOTOR12_CONFIG12_CLIMIT_LOW_MASK 0x000200ul
115 #define DCMOTOR12_CONFIG12_CLIMIT_LOW_0p25A 0x000000ul
116 #define DCMOTOR12_CONFIG12_CLIMIT_LOW_0p5A 0x000200ul
117 #define DCMOTOR12_CONFIG12_OPEN_LOAD_OP_200mA 0x000000ul
118 #define DCMOTOR12_CONFIG12_OPEN_LOAD_OP_100mA 0x000080ul
119 #define DCMOTOR12_CONFIG12_OPEN_LOAD_OP_300mA 0x000100ul
120 #define DCMOTOR12_CONFIG12_OPEN_LOAD_OP_MASK 0x000180ul
121 #define DCMOTOR12_CONFIG12_SR_MODE_NORMAL 0x000000ul
122 #define DCMOTOR12_CONFIG12_SR_MODE_SLOW1 0x000010ul
123 #define DCMOTOR12_CONFIG12_SR_MODE_SLOW2 0x000020ul
124 #define DCMOTOR12_CONFIG12_SR_MODE_SLOW3 0x000030ul
125 #define DCMOTOR12_CONFIG12_SR_MODE_SLOW4 0x000040ul
126 #define DCMOTOR12_CONFIG12_SR_MODE_FAST2 0x000050ul
127 #define DCMOTOR12_CONFIG12_SR_MODE_FAST1 0x000060ul
128 #define DCMOTOR12_CONFIG12_SR_MODE_MASK 0x000070ul
129 #define DCMOTOR12_CONFIG12_OC_LATCH 0x000000ul
130 #define DCMOTOR12_CONFIG12_OC_AUTO 0x000008ul
131 #define DCMOTOR12_CONFIG12_OC_MASK 0x000008ul
132 #define DCMOTOR12_CONFIG12_OC_LATCH 0x000000ul
133 #define DCMOTOR12_CONFIG12_OC_AUTO 0x000008ul
134 #define DCMOTOR12_CONFIG12_SPI_DISR_10mS 0x000000ul
135 #define DCMOTOR12_CONFIG12_SPI_DISR_100mS 0x000002ul
136 #define DCMOTOR12_CONFIG12_SPI_DISR_1S 0x000004ul
137 #define DCMOTOR12_CONFIG12_SPI_DISR_DISABLE 0x000006ul
138 #define DCMOTOR12_CONFIG12_SPI_DISR_MASK 0x000006ul
139 #define DCMOTOR12_CONFIG12_OPMODE_DISR_OFF 0x000000ul
140 #define DCMOTOR12_CONFIG12_OPMODE_DISR_CONTINUE 0x000001ul
141 #define DCMOTOR12_CONFIG12_OPMODE_DISR_MASK 0x000001ul
147 #define DCMOTOR12_CONFIG56_MOTOR_OPMODE_MAX 3u
148 #define DCMOTOR12_CONFIG56_MOTOR_OPMODE_SHIFT 22ul
149 #define DCMOTOR12_CONFIG56_MOTOR_OPMODE_MASK 0xC00000ul
150 #define DCMOTOR12_CONFIG56_DRV_FREQ_MAX 2047u
151 #define DCMOTOR12_CONFIG56_DRV_FREQ_SHIFT 11ul
152 #define DCMOTOR12_CONFIG56_DRV_FREQ_MASK 0x3FF800ul
153 #define DCMOTOR12_CONFIG56_DUTY_PERIOD_MAX 2047u
154 #define DCMOTOR12_CONFIG56_DUTY_PERIOD_SHIFT 0ul
155 #define DCMOTOR12_CONFIG56_DUTY_PERIOD_MASK 0x0007FFul
161 #define DCMOTOR12_DIAG1_PIN 0x01
162 #define DCMOTOR12_DIAG2_PIN 0x02
163 #define DCMOTOR12_EN1_PIN 0x04
164 #define DCMOTOR12_EN2_PIN 0x08
165 #define DCMOTOR12_CM_SEL_PIN 0x10
166 #define DCMOTOR12_SLP_PIN 0x20
172 #define DCMOTOR12_DEFAULT_CONFIG 0xE3
178 #define DCMOTOR12_MODE_OUTPUT_OFF 0x00
179 #define DCMOTOR12_MODE_FORWARD 0x01
180 #define DCMOTOR12_MODE_REVERSE 0x02
181 #define DCMOTOR12_MODE_BRAKE 0x03
187 #define DCMOTOR12_PIN_LOW_LEVEL 0
188 #define DCMOTOR12_PIN_HIGH_LEVEL 1
194 #define DCMOTOR12_VREF_3V3 3.3
195 #define DCMOTOR12_VREF_5V 5.0
201 #define DCMOTOR12_NUM_CONVERSIONS 5000
202 #define DCMOTOR12_RSENSE 220.0f
203 #define DCMOTOR12_VOLTAGE_TO_CURRENT 0.00238167f
209 #define DCMOTOR12_DEF_FREQ 20000
216 #define DCMOTOR12_DEVICE_ADDRESS_A1A0_00 0x70
217 #define DCMOTOR12_DEVICE_ADDRESS_A1A0_01 0x71
218 #define DCMOTOR12_DEVICE_ADDRESS_A1A0_10 0x72
219 #define DCMOTOR12_DEVICE_ADDRESS_A1A0_11 0x73
229 #define DCMOTOR12_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
230 #define DCMOTOR12_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
248 #define DCMOTOR12_MAP_MIKROBUS( cfg, mikrobus ) \
249 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
250 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
251 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
252 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
253 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
254 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
255 cfg.cm = MIKROBUS( mikrobus, MIKROBUS_AN ); \
256 cfg.slp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
257 cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
258 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
758 #endif // DCMOTOR12_H
err_t dcmotor12_get_en1_pin(dcmotor12_t *ctx, uint8_t *state)
DC Motor 12 get en1 pin function.
DC Motor 12 Click context object.
Definition: dcmotor12.h:268
DC Motor 12 Click configuration object.
Definition: dcmotor12.h:292
pin_name_t int_pin
Definition: dcmotor12.h:305
err_t dcmotor12_set_ch2_drive_frequency(dcmotor12_t *ctx, uint16_t drv_freq)
DC Motor 12 set ch2 drive frequency function.
err_t dcmotor12_set_en2_pin(dcmotor12_t *ctx, uint8_t state)
DC Motor 12 set en2 pin function.
uint32_t dev_pwm_freq
Definition: dcmotor12.h:315
void dcmotor12_enter_sleep_mode(dcmotor12_t *ctx)
DC Motor 12 enter sleep mode function.
err_t dcmotor12_read_register(dcmotor12_t *ctx, uint8_t reg, uint32_t *data_out)
DC Motor 12 read register function.
uint8_t slave_address
Definition: dcmotor12.h:282
err_t dcmotor12_get_en2_pin(dcmotor12_t *ctx, uint8_t *state)
DC Motor 12 get en2 pin function.
err_t dcmotor12_read_an_pin_value(dcmotor12_t *ctx, uint16_t *data_out)
DC Motor 12 read AN pin value function.
digital_out_t slp
Definition: dcmotor12.h:270
This file contains SPI specific macros, functions, etc.
err_t dcmotor12_get_diag1_pin(dcmotor12_t *ctx, uint8_t *state)
DC Motor 12 get diag1 pin function.
@ DCMOTOR12_ERROR
Definition: dcmotor12.h:329
spi_master_chip_select_polarity_t cs_polarity
Definition: dcmotor12.h:310
uint32_t i2c_speed
Definition: dcmotor12.h:312
pin_name_t cs
Definition: dcmotor12.h:299
pwm_t pwm
Definition: dcmotor12.h:278
digital_in_t int_pin
Definition: dcmotor12.h:273
pin_name_t mosi
Definition: dcmotor12.h:297
err_t dcmotor12_set_duty_cycle(dcmotor12_t *ctx, float duty_cycle)
DC Motor 12 sets PWM duty cycle.
err_t dcmotor12_pwm_start(dcmotor12_t *ctx)
DC Motor 12 start PWM module.
i2c_master_t i2c
Definition: dcmotor12.h:277
err_t dcmotor12_pwm_stop(dcmotor12_t *ctx)
DC Motor 12 stop PWM module.
err_t dcmotor12_write_register(dcmotor12_t *ctx, uint8_t reg, uint32_t data_in)
DC Motor 12 write register function.
err_t dcmotor12_set_en1_pin(dcmotor12_t *ctx, uint8_t state)
DC Motor 12 set en1 pin function.
analog_in_t adc
Definition: dcmotor12.h:279
pin_name_t miso
Definition: dcmotor12.h:296
@ DCMOTOR12_OK
Definition: dcmotor12.h:328
err_t dcmotor12_init(dcmotor12_t *ctx, dcmotor12_cfg_t *cfg)
DC Motor 12 initialization function.
err_t dcmotor12_pca9538a_read_register(dcmotor12_t *ctx, uint8_t reg, uint8_t *data_out)
DC Motor 12 pca9538a read register function.
void dcmotor12_wake_up_device(dcmotor12_t *ctx)
DC Motor 12 wake up device function.
err_t dcmotor12_get_motor_current(dcmotor12_t *ctx, float *current)
DC Motor 12 get motor current function.
err_t dcmotor12_set_ch2_duty_period(dcmotor12_t *ctx, uint16_t duty_period)
DC Motor 12 set ch1 duty period function.
pin_name_t clk
Definition: dcmotor12.h:304
void dcmotor12_cfg_setup(dcmotor12_cfg_t *cfg)
DC Motor 12 configuration object setup function.
err_t dcmotor12_get_cm_sel_pin(dcmotor12_t *ctx, uint8_t *state)
DC Motor 12 get cm sel pin function.
uint32_t spi_speed
Definition: dcmotor12.h:308
pin_name_t chip_select
Definition: dcmotor12.h:283
pin_name_t sck
Definition: dcmotor12.h:298
uint32_t pwm_freq
Definition: dcmotor12.h:281
uint8_t i2c_address
Definition: dcmotor12.h:313
err_t dcmotor12_default_cfg(dcmotor12_t *ctx)
DC Motor 12 default configuration function.
analog_in_resolution_t resolution
Definition: dcmotor12.h:317
pin_name_t scl
Definition: dcmotor12.h:294
pin_name_t slp
Definition: dcmotor12.h:303
err_t dcmotor12_set_ch1_operation_mode(dcmotor12_t *ctx, uint8_t mode)
DC Motor 12 set ch1 operation mode function.
spi_master_mode_t spi_mode
Definition: dcmotor12.h:309
err_t dcmotor12_set_ch2_operation_mode(dcmotor12_t *ctx, uint8_t mode)
DC Motor 12 set ch2 operation mode function.
err_t dcmotor12_set_ch1_duty_period(dcmotor12_t *ctx, uint16_t duty_period)
DC Motor 12 set ch1 duty period function.
err_t dcmotor12_read_an_pin_voltage(dcmotor12_t *ctx, float *data_out)
DC Motor 12 read AN pin voltage level function.
uint8_t dcmotor12_get_int_pin(dcmotor12_t *ctx)
DC Motor 12 get int pin function.
dcmotor12_return_value_t
DC Motor 12 Click return value data.
Definition: dcmotor12.h:327
err_t dcmotor12_set_ch1_drive_frequency(dcmotor12_t *ctx, uint16_t drv_freq)
DC Motor 12 set ch1 drive frequency function.
float vref
Definition: dcmotor12.h:318
err_t dcmotor12_pca9538a_write_register(dcmotor12_t *ctx, uint8_t reg, uint8_t data_in)
DC Motor 12 pca9538a write register function.
err_t dcmotor12_set_cm_sel_pin(dcmotor12_t *ctx, uint8_t state)
DC Motor 12 set cm sel pin function.
pin_name_t cm
Definition: dcmotor12.h:302
spi_master_t spi
Definition: dcmotor12.h:276
pin_name_t sda
Definition: dcmotor12.h:295
err_t dcmotor12_get_sleep_pin(dcmotor12_t *ctx, uint8_t *state)
DC Motor 12 get sleep pin function.
err_t dcmotor12_get_diag2_pin(dcmotor12_t *ctx, uint8_t *state)
DC Motor 12 get diag2 pin function.