vibromotor3  2.0.0.0
vibromotor3.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 VIBROMOTOR3_H
29 #define VIBROMOTOR3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_pwm.h"
39 
60 #define VIBROMOTOR3_STATUS 0x00
61 #define VIBROMOTOR3_MODE 0x01
62 #define VIBROMOTOR3_RT_PB_IN 0x02
63 #define VIBROMOTOR3_LIB_SEL 0x03
64 #define VIBROMOTOR3_WV_SEQ_1 0x04
65 #define VIBROMOTOR3_WV_SEQ_2 0x05
66 #define VIBROMOTOR3_WV_SEQ_3 0x06
67 #define VIBROMOTOR3_WV_SEQ_4 0x07
68 #define VIBROMOTOR3_WV_SEQ_5 0x08
69 #define VIBROMOTOR3_WV_SEQ_6 0x09
70 #define VIBROMOTOR3_WV_SEQ_7 0x0A
71 #define VIBROMOTOR3_WV_SEQ_8 0x0B
72 #define VIBROMOTOR3_REG_GO 0x0C
73 #define VIBROMOTOR3_OVERDRIVE_OFFS 0x0D
74 #define VIBROMOTOR3_SUSTAIN_P_OFFS 0x0E
75 #define VIBROMOTOR3_SUSTAIN_N_OFFS 0x0F
76 #define VIBROMOTOR3_BRAKE_OFF 0x10
77 #define VIBROMOTOR3_A_TO_V_CTRL 0x11
78 #define VIBROMOTOR3_A_TO_V_MIN_INPUT 0x12
79 #define VIBROMOTOR3_A_TO_V_MAX_INPUT 0x13
80 #define VIBROMOTOR3_A_TO_V_MIN_OUT 0x14
81 #define VIBROMOTOR3_A_TO_V_MAX_OUT 0x15
82 #define VIBROMOTOR3_RATED_VOLT 0x16
83 #define VIBROMOTOR3_OD_CLAMP_VOLT 0x17
84 #define VIBROMOTOR3_CAL_COMP 0x18
85 #define VIBROMOTOR3_CAL_BACK_EMF 0x19
86 #define VIBROMOTOR3_FEEDBACK_CTRL 0x1A
87 #define VIBROMOTOR3_CTRL1 0x1B
88 #define VIBROMOTOR3_CTRL2 0x1C
89 #define VIBROMOTOR3_CTRL3 0x1D
90 #define VIBROMOTOR3_CTRL4 0x1E
91 #define VIBROMOTOR3_CTRL5 0x1F
92 #define VIBROMOTOR3_LRA_LOOP_PERIOD 0x20
93 #define VIBROMOTOR3_VBAT_MON 0x21
94 #define VIBROMOTOR3_LRA_RES_PERIOD 0x22
95  // vibromotor3_reg
97 
112 #define VIBROMOTOR3_STARTPPBOOST 0x80
113 #define VIBROMOTOR3_BYPASSCOMP 0x40
114 #define VIBROMOTOR3_AC_COUPLE 0x20
115 #define VIBROMOTOR3_DC_COUPLE 0x00
116 #define VIBROMOTOR3_DRV_TIME_0P5M 0x00
117 #define VIBROMOTOR3_DRV_TIME_0P6M 0x01
118 #define VIBROMOTOR3_DRV_TIME_0P7M 0x02
119 #define VIBROMOTOR3_DRV_TIME_0P8M 0x03
120 #define VIBROMOTOR3_DRV_TIME_0P9M 0x04
121 #define VIBROMOTOR3_DRV_TIME_1P0M 0x05
122 #define VIBROMOTOR3_DRV_TIME_1P1M 0x06
123 #define VIBROMOTOR3_DRV_TIME_1P2M 0x07
124 #define VIBROMOTOR3_DRV_TIME_1P3M 0x08
125 #define VIBROMOTOR3_DRV_TIME_1P4M 0x09
126 #define VIBROMOTOR3_DRV_TIME_1P5M 0x0A
127 #define VIBROMOTOR3_DRV_TIME_1P6M 0x0B
128 #define VIBROMOTOR3_DRV_TIME_1P7M 0x0C
129 #define VIBROMOTOR3_DRV_TIME_1P8M 0x0D
130 #define VIBROMOTOR3_DRV_TIME_1P9M 0x0E
131 #define VIBROMOTOR3_DRV_TIME_2P0M 0x0F
132 #define VIBROMOTOR3_DRV_TIME_2P1M 0x10
133 #define VIBROMOTOR3_DRV_TIME_2P2M 0x11
134 #define VIBROMOTOR3_DRV_TIME_2P3M 0x12
135 #define VIBROMOTOR3_DRV_TIME_2P4M 0x13
136 #define VIBROMOTOR3_DRV_TIME_2P5M 0x14
137 #define VIBROMOTOR3_DRV_TIME_2P6M 0x15
138 #define VIBROMOTOR3_DRV_TIME_2P7M 0x16
139 #define VIBROMOTOR3_DRV_TIME_2P8M 0x17
140 #define VIBROMOTOR3_DRV_TIME_2P9M 0x18
141 #define VIBROMOTOR3_DRV_TIME_3P0M 0x19
142 #define VIBROMOTOR3_DRV_TIME_3P1M 0x1A
143 #define VIBROMOTOR3_DRV_TIME_3P2M 0x1B
144 #define VIBROMOTOR3_DRV_TIME_3P3M 0x1C
145 #define VIBROMOTOR3_DRV_TIME_3P4M 0x1D
146 #define VIBROMOTOR3_DRV_TIME_3P5M 0x1E
147 #define VIBROMOTOR3_DRV_TIME_3P6M 0x1F
148 #define VIBROMOTOR3_BIDIR_IN 0x80
149 #define VIBROMOTOR3_UNIDIR_IN 0x00
150 #define VIBROMOTOR3_BRK_STABIL 0x40
151 #define VIBROMOTOR3_SAMP_TIME_150US 0x00
152 #define VIBROMOTOR3_SAMP_TIME_200US 0x10
153 #define VIBROMOTOR3_SAMP_TIME_250US 0x20
154 #define VIBROMOTOR3_SAMP_TIME_300US 0x30
155 #define VIBROMOTOR3_BLANK_TIME_V_SHORT 0x00
156 #define VIBROMOTOR3_BLANK_TIME_SHORT 0x04
157 #define VIBROMOTOR3_BLANK_TIME_MEDIUM 0x08
158 #define VIBROMOTOR3_BLANK_TIME_LONG 0x0C
159 #define VIBROMOTOR3_I_DIS_TIME_V_SHORT 0x00
160 #define VIBROMOTOR3_I_DIS_TIME_SHORT 0x01
161 #define VIBROMOTOR3_I_DIS_TIME_MEDIUM 0x02
162 #define VIBROMOTOR3_I_DIS_TIME_LONG 0x03
163 #define VIBROMOTOR3_NG_THRESH_OFF 0x00
164 #define VIBROMOTOR3_NG_THRESH_2_PERC 0x40
165 #define VIBROMOTOR3_NG_THRESH_4_PERC 0x80
166 #define VIBROMOTOR3_NG_THRESH_8_PERC 0xC0
167 #define VIBROMOTOR3_ERM_CLOSED_LOOP 0x00
168 #define VIBROMOTOR3_ERM_OPEN_LOOP 0x20
169 #define VIBROMOTOR3_SUP_COMP_DIS 0x10
170 #define VIBROMOTOR3_DATA_FORM_RTP_SIG 0x00
171 #define VIBROMOTOR3_DATA_FORM_RTP_UNS 0x08
172 #define VIBROMOTOR3_LRADRV_MODE 0x04
173 #define VIBROMOTOR3_LRADRV_MODE_ONCE 0x00
174 #define VIBROMOTOR3_LRADRV_MODE_TWICE 0x04
175 #define VIBROMOTOR3_IN_MODE_PWM 0x00
176 #define VIBROMOTOR3_IN_MODE_ANALOG 0x02
177 #define VIBROMOTOR3_LRA_AUTO_RESONA 0x00
178 #define VIBROMOTOR3_LRA_OPEN_LOOP 0x01
179 #define VIBROMOTOR3_LRA_CLOSED_LOOP 0x00
180 
185 #define VIBROMOTOR3_DEV_RESRT 0x80
186 #define VIBROMOTOR3_STANDBY 0x40
187 #define VIBROMOTOR3_ACTIVE 0x00
188 #define VIBROMOTOR3_INT_TRIG 0x00
189 #define VIBROMOTOR3_EXT_TRIG_EDGE 0x01
190 #define VIBROMOTOR3_EXT_TRIG_LEVEL 0x02
191 #define VIBROMOTOR3_PWM_ANALOG 0x03
192 #define VIBROMOTOR3_AUDIO2HAPTIC 0x04
193 #define VIBROMOTOR3_RTP 0x05
194 #define VIBROMOTOR3_DIAGNOSTICS 0x06
195 #define VIBROMOTOR3_AUTO_CALIBRATION 0x07
196 
201 #define VIBROMOTOR3_HIZ 0x10
202 #define VIBROMOTOR3_RAM 0x00
203 #define VIBROMOTOR3_ROM_A 0x01
204 #define VIBROMOTOR3_ROM_B 0x02
205 #define VIBROMOTOR3_ROM_C 0x03
206 #define VIBROMOTOR3_ROM_D 0x04
207 #define VIBROMOTOR3_ROM_E 0x05
208 #define VIBROMOTOR3_ROM_LRA 0x06
209 
214 #define VIBROMOTOR3_GO 0x01
215 #define VIBROMOTOR3_STOP 0x00
216 
221 #define VIBROMOTOR3_ERM_MODE 0x00
222 #define VIBROMOTOR3_LRA_MODE 0x80
223 #define VIBROMOTOR3_FB_BRAKE_FAC_1X 0x00
224 #define VIBROMOTOR3_FB_BRAKE_FAC_2X 0x10
225 #define VIBROMOTOR3_FB_BRAKE_FAC_3X 0x20
226 #define VIBROMOTOR3_FB_BRAKE_FAC_4X 0x30
227 #define VIBROMOTOR3_FB_BRAKE_FAC_6X 0x40
228 #define VIBROMOTOR3_FB_BRAKE_FAC_8X 0x50
229 #define VIBROMOTOR3_FB_BRAKE_FAC_16X 0x60
230 #define VIBROMOTOR3_FB_BRAKE_FAC_DIS 0x70
231 #define VIBROMOTOR3_LOOP_RESP_SLOW 0x00
232 #define VIBROMOTOR3_LOOP_RESP_MEDIUM 0x04
233 #define VIBROMOTOR3_LOOP_RESP_FAST 0x08
234 #define VIBROMOTOR3_LOOP_RESP_V_FAST 0x0C
235 #define VIBROMOTOR3_BEMF_GAIN_ERM_0P3X 0x00
236 #define VIBROMOTOR3_BEMF_GAIN_ERM_1X 0x01
237 #define VIBROMOTOR3_BEMF_GAIN_ERM_1P8X 0x02
238 #define VIBROMOTOR3_BEMF_GAIN_ERM_4X 0x03
239 #define VIBROMOTOR3_BEMF_GAIN_LRA_5X 0x00
240 #define VIBROMOTOR3_BEMF_GAIN_LRA_10X 0x01
241 #define VIBROMOTOR3_BEMF_GAIN_LRA_20X 0x02
242 #define VIBROMOTOR3_BEMF_GAIN_LRA_30X 0x03
243 
248 #define VIBROMOTOR3_AUTO_CAL_TIME_150MS 0x00
249 #define VIBROMOTOR3_AUTO_CAL_TIME_250MS 0x10
250 #define VIBROMOTOR3_AUTO_CAL_TIME_500MS 0x20
251 #define VIBROMOTOR3_AUTO_CAL_TIME_1000MS 0x30
252 #define VIBROMOTOR3_OTP_PROG 0x01
253 
258 #define VIBROMOTOR3_PROPERTY_DISABLE 0
259 #define VIBROMOTOR3_PROPERTY_ENABLE 1
260 
266 #define VIBROMOTOR3_SET_DEV_ADDR 0x5A
267 
272 #define VIBROMOTOR3_DEF_FREQ 235
273  // vibromotor3_set
275 
290 #define VIBROMOTOR3_MAP_MIKROBUS( cfg, mikrobus ) \
291  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
292  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
293  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
294  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
295  // vibromotor3_map // vibromotor3
298 
303 typedef struct
304 {
305  // Output pins
306  digital_out_t en;
308  // Modules
309  i2c_master_t i2c;
310  pwm_t pwm;
312  // I2C slave address
313  uint8_t slave_address;
315  uint32_t pwm_freq;
317 } vibromotor3_t;
318 
323 typedef struct
324 {
325  pin_name_t scl;
326  pin_name_t sda;
328  pin_name_t en;
329  pin_name_t pwm;
331  uint32_t i2c_speed;
332  uint8_t i2c_address;
334  uint32_t dev_pwm_freq;
337 
342 typedef enum
343 {
345  VIBROMOTOR3_ERROR = -1
346 
348 
366 
381 
396 
411 err_t vibromotor3_generic_write ( vibromotor3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
412 
427 err_t vibromotor3_generic_read ( vibromotor3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
428 
440 err_t vibromotor3_set_duty_cycle ( vibromotor3_t *ctx, float duty_cycle );
441 
452 err_t vibromotor3_pwm_stop ( vibromotor3_t *ctx );
453 
464 err_t vibromotor3_pwm_start ( vibromotor3_t *ctx );
465 
477 void vibromotor3_enable ( vibromotor3_t *ctx, uint8_t state );
478 
489 void vibromotor3_write_byte ( vibromotor3_t *ctx, uint8_t reg, uint8_t wr_data );
490 
501 uint8_t vibromotor3_read_byte ( vibromotor3_t *ctx, uint8_t reg );
502 
539 void vibromotor3_set_mode ( vibromotor3_t *ctx, uint8_t mode_sel );
540 
548 void vibromotor3_soft_rst ( vibromotor3_t *ctx );
549 
559 void vibromotor3_stb_mode ( vibromotor3_t *ctx, uint8_t state );
560 
572 uint8_t vibromotor3_get_stat ( vibromotor3_t *ctx );
573 
582 void vibromotor3_set_rtp_input ( vibromotor3_t *ctx, uint8_t data_in );
583 
594 void vibromotor3_set_state_hi_z ( vibromotor3_t *ctx, uint8_t state );
595 
613 void vibromotor3_set_library ( vibromotor3_t *ctx, uint8_t lib_sel );
614 
626 void vibromotor3_start_motor ( vibromotor3_t *ctx, uint8_t state );
627 
636 void vibromotor3_set_ovdr_offset ( vibromotor3_t *ctx, uint8_t data_in );
637 
646 void vibromotor3_set_sustain_offset_pos ( vibromotor3_t *ctx, uint8_t data_in );
647 
656 void vibromotor3_set_sustain_offset_neg ( vibromotor3_t *ctx, uint8_t data_in );
657 
666 void vibromotor3_set_brake_time_offset ( vibromotor3_t *ctx, uint8_t data_in );
667 
677 void vibromotor3_set_rated_volt ( vibromotor3_t *ctx, uint8_t data_in );
678 
686 void vibromotor3_set_ovdrv_clamp_volt ( vibromotor3_t *ctx, uint8_t data_in );
687 
697 
707 
716 
728 void vibromotor3_set_lra_mode ( vibromotor3_t *ctx, uint8_t state );
729 
749 void vibromotor3_set_brake_factor ( vibromotor3_t *ctx, uint8_t brk_fac );
750 
765 void vibromotor3_set_loop_gain ( vibromotor3_t *ctx, uint8_t gain );
766 
779 void vibromotor3_set_input ( vibromotor3_t *ctx, uint8_t data_in );
780 
789 
790 #ifdef __cplusplus
791 }
792 #endif
793 #endif // VIBROMOTOR3_H
794  // vibromotor3
796 
797 // ------------------------------------------------------------------------ END
vibromotor3_write_byte
void vibromotor3_write_byte(vibromotor3_t *ctx, uint8_t reg, uint8_t wr_data)
Generic write the byte of data function.
vibromotor3_get_calib_res_comp
uint8_t vibromotor3_get_calib_res_comp(vibromotor3_t *ctx)
Reads the voltage-compensation function.
vibromotor3_soft_rst
void vibromotor3_soft_rst(vibromotor3_t *ctx)
Reset function.
vibromotor3_cfg_t
Vibro Motor 3 Click configuration object.
Definition: vibromotor3.h:322
vibromotor3_pwm_stop
err_t vibromotor3_pwm_stop(vibromotor3_t *ctx)
Vibro Motor 3 stop PWM module.
vibromotor3_set_ovdr_offset
void vibromotor3_set_ovdr_offset(vibromotor3_t *ctx, uint8_t data_in)
Sets overdrive offset function.
vibromotor3_set_sustain_offset_pos
void vibromotor3_set_sustain_offset_pos(vibromotor3_t *ctx, uint8_t data_in)
Sets sustain offset - positive function.
vibromotor3_generic_write
err_t vibromotor3_generic_write(vibromotor3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Vibro Motor 3 I2C writing function.
vibromotor3_init
err_t vibromotor3_init(vibromotor3_t *ctx, vibromotor3_cfg_t *cfg)
Vibro Motor 3 initialization function.
vibromotor3_enable
void vibromotor3_enable(vibromotor3_t *ctx, uint8_t state)
Enable the device function.
vibromotor3_set_rated_volt
void vibromotor3_set_rated_volt(vibromotor3_t *ctx, uint8_t data_in)
Sets the reference voltage function.
vibromotor3_set_brake_time_offset
void vibromotor3_set_brake_time_offset(vibromotor3_t *ctx, uint8_t data_in)
Sets brake time offset function.
vibromotor3_set_library
void vibromotor3_set_library(vibromotor3_t *ctx, uint8_t lib_sel)
Set the desired vibrating patterns library.
VIBROMOTOR3_OK
Definition: vibromotor3.h:343
vibromotor3_set_sustain_offset_neg
void vibromotor3_set_sustain_offset_neg(vibromotor3_t *ctx, uint8_t data_in)
Sets sustain offset - negative function.
vibromotor3_set_input
void vibromotor3_set_input(vibromotor3_t *ctx, uint8_t data_in)
Sets the input to PWM or analog function.
vibromotor3_get_stat
uint8_t vibromotor3_get_stat(vibromotor3_t *ctx)
Get status register value function.
vibromotor3_read_byte
uint8_t vibromotor3_read_byte(vibromotor3_t *ctx, uint8_t reg)
Generic read the byte of data function.
vibromotor3_pwm_start
err_t vibromotor3_pwm_start(vibromotor3_t *ctx)
Vibro Motor 3 start PWM module.
vibromotor3_set_loop_gain
void vibromotor3_set_loop_gain(vibromotor3_t *ctx, uint8_t gain)
Selects a loop gain function.
vibromotor3_set_lra_mode
void vibromotor3_set_lra_mode(vibromotor3_t *ctx, uint8_t state)
Sets the device in LRA mode function.
vibromotor3_set_duty_cycle
err_t vibromotor3_set_duty_cycle(vibromotor3_t *ctx, float duty_cycle)
Vibro Motor 3 sets PWM duty cycle.
vibromotor3_stb_mode
void vibromotor3_stb_mode(vibromotor3_t *ctx, uint8_t state)
Software standby mode.
vibromotor3_t
Vibro Motor 3 Click context object.
Definition: vibromotor3.h:302
vibromotor3_cfg_setup
void vibromotor3_cfg_setup(vibromotor3_cfg_t *cfg)
Vibro Motor 3 configuration object setup function.
VIBROMOTOR3_ERROR
Definition: vibromotor3.h:344
vibromotor3_get_supply_volt_val
float vibromotor3_get_supply_volt_val(vibromotor3_t *ctx)
Reading of the supply voltage function.
vibromotor3_set_ovdrv_clamp_volt
void vibromotor3_set_ovdrv_clamp_volt(vibromotor3_t *ctx, uint8_t data_in)
Sets a clamp function.
vibromotor3_generic_read
err_t vibromotor3_generic_read(vibromotor3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Vibro Motor 3 I2C reading function.
vibromotor3_get_lra_resonance_period
float vibromotor3_get_lra_resonance_period(vibromotor3_t *ctx)
Reads the measurement of the LRA resonance period function.
vibromotor3_set_brake_factor
void vibromotor3_set_brake_factor(vibromotor3_t *ctx, uint8_t brk_fac)
Set brake factor function.
vibromotor3_set_state_hi_z
void vibromotor3_set_state_hi_z(vibromotor3_t *ctx, uint8_t state)
Set the devices in HI-Z state function.
vibromotor3_start_motor
void vibromotor3_start_motor(vibromotor3_t *ctx, uint8_t state)
Starts or stops moving the motor function.
vibromotor3_enable_ac_coulping
void vibromotor3_enable_ac_coulping(vibromotor3_t *ctx)
Applies a 0.9-V common mode voltage function.
vibromotor3_set_rtp_input
void vibromotor3_set_rtp_input(vibromotor3_t *ctx, uint8_t data_in)
Sets the desired input for RTP mode function.
vibromotor3_set_mode
void vibromotor3_set_mode(vibromotor3_t *ctx, uint8_t mode_sel)
Sets the desired mode function.
vibromotor3_return_value_t
vibromotor3_return_value_t
Vibro Motor 3 Click return value data.
Definition: vibromotor3.h:341
vibromotor3_default_cfg
err_t vibromotor3_default_cfg(vibromotor3_t *ctx)
Vibro Motor 3 default configuration function.