haptic3  2.0.0.0
haptic3.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 HAPTIC3_H
29 #define HAPTIC3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define HAPTIC3_REG_CHIP_REV 0x00
70 #define HAPTIC3_REG_IRQ_EVENT1 0x03
71 #define HAPTIC3_REG_IRQ_EVENT_WARNING_DIAG 0x04
72 #define HAPTIC3_REG_IRQ_EVENT_SEQ_DIAG 0x05
73 #define HAPTIC3_REG_IRQ_STATUS1 0x06
74 #define HAPTIC3_REG_IRQ_MASK1 0x07
75 #define HAPTIC3_REG_CIF_I2C1 0x08
76 #define HAPTIC3_REG_FRQ_LRA_PER_H 0x0A
77 #define HAPTIC3_REG_FRQ_LRA_PER_L 0x0B
78 #define HAPTIC3_REG_ACTUATOR1 0x0C
79 #define HAPTIC3_REG_ACTUATOR2 0x0D
80 #define HAPTIC3_REG_ACTUATOR3 0x0E
81 #define HAPTIC3_REG_CALIB_V2I_H 0x0F
82 #define HAPTIC3_REG_CALIB_V2I_L 0x10
83 #define HAPTIC3_REG_CALIB_IMP_H 0x11
84 #define HAPTIC3_REG_CALIB_IMP_L 0x12
85 #define HAPTIC3_REG_TOP_CFG1 0x13
86 #define HAPTIC3_REG_TOP_CFG2 0x14
87 #define HAPTIC3_REG_TOP_CFG3 0x15
88 #define HAPTIC3_REG_TOP_CFG4 0x16
89 #define HAPTIC3_REG_TOP_INT_CFG1 0x17
90 #define HAPTIC3_REG_TOP_INT_CFG6_H 0x1C
91 #define HAPTIC3_REG_TOP_INT_CFG6_L 0x1D
92 #define HAPTIC3_REG_TOP_INT_CFG7_H 0x1E
93 #define HAPTIC3_REG_TOP_INT_CFG7_L 0x1F
94 #define HAPTIC3_REG_TOP_INT_CFG8 0x20
95 #define HAPTIC3_REG_TOP_CTL1 0x22
96 #define HAPTIC3_REG_TOP_CTL2 0x23
97 #define HAPTIC3_REG_SEQ_CTL1 0x24
98 #define HAPTIC3_REG_SWG_C1 0x25
99 #define HAPTIC3_REG_SWG_C2 0x26
100 #define HAPTIC3_REG_SWG_C3 0x27
101 #define HAPTIC3_REG_SEQ_CTL2 0x28
102 #define HAPTIC3_REG_GPI_0_CTL 0x29
103 #define HAPTIC3_REG_GPI_1_CTL 0x2A
104 #define HAPTIC3_REG_GPI_2_CTL 0x2B
105 #define HAPTIC3_REG_MEM_CTL1 0x2C
106 #define HAPTIC3_REG_MEM_CTL2 0x2D
107 #define HAPTIC3_REG_ADC_DATA_H1 0x2E
108 #define HAPTIC3_REG_ADC_DATA_L1 0x2F
109 #define HAPTIC3_REG_POLARITY 0x43
110 #define HAPTIC3_REG_LRA_AVR_H 0x44
111 #define HAPTIC3_REG_LRA_AVR_L 0x45
112 #define HAPTIC3_REG_FRQ_LRA_PER_ACT_H 0x46
113 #define HAPTIC3_REG_FRQ_LRA_PER_ACT_L 0x47
114 #define HAPTIC3_REG_FRQ_PHASE_H 0x48
115 #define HAPTIC3_REG_FRQ_PHASE_L 0x49
116 #define HAPTIC3_REG_FRQ_CTL 0x4C
117 #define HAPTIC3_REG_TRIM3 0x5F
118 #define HAPTIC3_REG_TRIM4 0x60
119 #define HAPTIC3_REG_TRIM6 0x62
120 #define HAPTIC3_REG_TOP_CFG5 0x6E
121 #define HAPTIC3_REG_IRQ_EVENT_ACTUATOR_FAULT 0x81
122 #define HAPTIC3_REG_IRQ_STATUS2 0x82
123 #define HAPTIC3_REG_IRQ_MASK2 0x83
124 #define HAPTIC3_REG_SNP_MEM_X 0x84
125  // haptic3_reg
127 
142 #define HAPTIC3_CHIP_REV 0xDA
143 
148 #define HAPTIC3_TOP_CFG1_EMB_MODE_MANUAL 0x00
149 #define HAPTIC3_TOP_CFG1_EMB_MODE_AUTO 0x80
150 #define HAPTIC3_TOP_CFG1_EMB_MODE_MASK 0x80
151 #define HAPTIC3_TOP_CFG1_ACT_TYPE_LRA 0x00
152 #define HAPTIC3_TOP_CFG1_ACT_TYPE_ERM 0x20
153 #define HAPTIC3_TOP_CFG1_ACT_TYPE_MASK 0x20
154 #define HAPTIC3_TOP_CFG1_BEMF_SENSE_CUSTOM_WF 0x00
155 #define HAPTIC3_TOP_CFG1_BEMF_SENSE_STANDARD 0x10
156 #define HAPTIC3_TOP_CFG1_BEMF_SENSE_MASK 0x10
157 #define HAPTIC3_TOP_CFG1_FREQ_TRACK_DISABLE 0x00
158 #define HAPTIC3_TOP_CFG1_FREQ_TRACK_ENABLE 0x08
159 #define HAPTIC3_TOP_CFG1_FREQ_TRACK_MASK 0x08
160 #define HAPTIC3_TOP_CFG1_ACCEL_DISABLE 0x00
161 #define HAPTIC3_TOP_CFG1_ACCEL_ENABLE 0x04
162 #define HAPTIC3_TOP_CFG1_ACCEL_MASK 0x04
163 #define HAPTIC3_TOP_CFG1_RAPID_STOP_DISABLE 0x00
164 #define HAPTIC3_TOP_CFG1_RAPID_STOP_ENABLE 0x02
165 #define HAPTIC3_TOP_CFG1_RAPID_STOP_MASK 0x02
166 #define HAPTIC3_TOP_CFG1_AMPLITUDE_PID_DISABLE 0x00
167 #define HAPTIC3_TOP_CFG1_AMPLITUDE_PID_ENABLE 0x01
168 #define HAPTIC3_TOP_CFG1_AMPLITUDE_PID_MASK 0x01
169 
174 #define HAPTIC3_TOP_CTL1_SEQ_STOP 0x00
175 #define HAPTIC3_TOP_CTL1_SEQ_START 0x10
176 #define HAPTIC3_TOP_CTL1_SEQ_MASK 0x10
177 #define HAPTIC3_TOP_CTL1_STANDBY_DISABLE 0x00
178 #define HAPTIC3_TOP_CTL1_STANDBY_ENABLE 0x08
179 #define HAPTIC3_TOP_CTL1_STANDBY_MASK 0x08
180 #define HAPTIC3_TOP_CTL1_OP_MODE_INACTIVE 0x00
181 #define HAPTIC3_TOP_CTL1_OP_MODE_DRO 0x01
182 #define HAPTIC3_TOP_CTL1_OP_MODE_PWM 0x02
183 #define HAPTIC3_TOP_CTL1_OP_MODE_RTWM 0x03
184 #define HAPTIC3_TOP_CTL1_OP_MODE_ETWM 0x04
185 #define HAPTIC3_TOP_CTL1_OP_MODE_MASK 0x07
186 
191 #define HAPTIC3_ACTUATOR_VOLTAGE_MIN 0.0
192 #define HAPTIC3_ACTUATOR_VOLTAGE_MAX 6.0
193 #define HAPTIC3_ACTUATOR_VOLTAGE_RESOLUTION 0.0234
194 #define HAPTIC3_ACTUATOR_IMAX_MIN 28.6
195 #define HAPTIC3_ACTUATOR_IMAX_MAX 251.8
196 #define HAPTIC3_ACTUATOR_IMAX_DIVIDER 7.2
197 #define HAPTIC3_ACTUATOR_IMAX_RESOLUTION 0x1F
198 #define HAPTIC3_ACTUATOR_IMPEDANCE_MIN 4.0
199 #define HAPTIC3_ACTUATOR_IMPEDANCE_MAX 50.0
200 #define HAPTIC3_ACTUATOR_V2I_FACTOR_DIVIDER 1.6104
201 #define HAPTIC3_ACTUATOR_LRA_FREQ_MIN 0.0
202 #define HAPTIC3_ACTUATOR_LRA_FREQ_MAX 300.0
203 #define HAPTIC3_ACTUATOR_LRA_FREQ_RESOLUTION 0.00000133332
204 #define HAPTIC3_VIBRATION_LEVEL_MIN -1.0
205 #define HAPTIC3_VIBRATION_LEVEL_MAX 1.0
206 #define HAPTIC3_VIBRATION_LEVEL_MIN_ACC_EN 0.0
207 #define HAPTIC3_VIBRATION_LEVEL_RESOLUTION 0.008
208 #define HAPTIC3_ROUND_TO_NEAREST_INT 0.5
209 
214 #define HAPTIC3_DEFAULT_ACTUATOR_TYPE HAPTIC3_TOP_CFG1_ACT_TYPE_LRA
215 #define HAPTIC3_DEFAULT_ACTUATOR_ABS_VOLT 2.808
216 #define HAPTIC3_DEFAULT_ACTUATOR_NOM_VOLT 2.106
217 #define HAPTIC3_DEFAULT_ACTUATOR_IMAX 194.0
218 #define HAPTIC3_DEFAULT_ACTUATOR_IMPEDANCE 16.0
219 #define HAPTIC3_DEFAULT_ACTUATOR_LRA_FREQ 174.0
220 
226 #define HAPTIC3_DEVICE_ADDRESS 0x4A
227  // haptic3_set
229 
244 #define HAPTIC3_MAP_MIKROBUS( cfg, mikrobus ) \
245  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
246  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
247  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
248  cfg.irq = MIKROBUS( mikrobus, MIKROBUS_INT )
249  // haptic3_map // haptic3
252 
257 typedef struct
258 {
259  // Output pins
260  digital_out_t en;
262  // Input pins
263  digital_in_t irq;
265  // Modules
266  i2c_master_t i2c;
268  // I2C slave address
269  uint8_t slave_address;
271 } haptic3_t;
272 
277 typedef struct
278 {
279  pin_name_t scl;
280  pin_name_t sda;
282  pin_name_t en;
283  pin_name_t irq;
285  uint32_t i2c_speed;
286  uint8_t i2c_address;
288 } haptic3_cfg_t;
289 
294 typedef enum
295 {
297  HAPTIC3_ERROR = -1
298 
300 
317 
332 err_t haptic3_init ( haptic3_t *ctx, haptic3_cfg_t *cfg );
333 
348 
364 err_t haptic3_generic_write ( haptic3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
365 
381 err_t haptic3_generic_read ( haptic3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
382 
395 err_t haptic3_write_register ( haptic3_t *ctx, uint8_t reg, uint8_t data_in );
396 
409 err_t haptic3_read_register ( haptic3_t *ctx, uint8_t reg, uint8_t *data_out );
410 
425 err_t haptic3_write_register_bits ( haptic3_t *ctx, uint8_t reg, uint8_t mask, uint8_t data_in );
426 
438 
448 
458 
468 
481 err_t haptic3_set_actuator_type ( haptic3_t *ctx, uint8_t type );
482 
494 err_t haptic3_set_actuator_abs_volt ( haptic3_t *ctx, float abs_volt );
495 
507 err_t haptic3_set_actuator_nom_volt ( haptic3_t *ctx, float nom_volt );
508 
520 err_t haptic3_set_actuator_imax ( haptic3_t *ctx, float max_curr );
521 
534 err_t haptic3_set_actuator_impedance ( haptic3_t *ctx, float impedance );
535 
547 err_t haptic3_set_actuator_lra_freq ( haptic3_t *ctx, float frequency );
548 
564 err_t haptic3_set_operation_mode ( haptic3_t *ctx, uint8_t op_mode );
565 
578 err_t haptic3_set_freq_track ( haptic3_t *ctx, uint8_t freq_track_en );
579 
592 err_t haptic3_set_acceleration_mode ( haptic3_t *ctx, uint8_t accel_en );
593 
606 err_t haptic3_set_vibration_level ( haptic3_t *ctx, float level );
607 
620 err_t haptic3_get_vibration_level ( haptic3_t *ctx, float *level );
621 
622 #ifdef __cplusplus
623 }
624 #endif
625 #endif // HAPTIC3_H
626  // haptic3
628 
629 // ------------------------------------------------------------------------ END
haptic3_return_value_t
haptic3_return_value_t
HAPTIC 3 Click return value data.
Definition: haptic3.h:295
haptic3_set_actuator_lra_freq
err_t haptic3_set_actuator_lra_freq(haptic3_t *ctx, float frequency)
HAPTIC 3 set actuator lra freq function.
haptic3_set_operation_mode
err_t haptic3_set_operation_mode(haptic3_t *ctx, uint8_t op_mode)
HAPTIC 3 set operation mode function.
haptic3_t::irq
digital_in_t irq
Definition: haptic3.h:263
haptic3_write_register
err_t haptic3_write_register(haptic3_t *ctx, uint8_t reg, uint8_t data_in)
HAPTIC 3 write register function.
haptic3_get_vibration_level
err_t haptic3_get_vibration_level(haptic3_t *ctx, float *level)
HAPTIC 3 get vibration level function.
haptic3_cfg_t
HAPTIC 3 Click configuration object.
Definition: haptic3.h:278
haptic3_set_actuator_impedance
err_t haptic3_set_actuator_impedance(haptic3_t *ctx, float impedance)
HAPTIC 3 set actuator impedance function.
haptic3_init
err_t haptic3_init(haptic3_t *ctx, haptic3_cfg_t *cfg)
HAPTIC 3 initialization function.
haptic3_set_actuator_abs_volt
err_t haptic3_set_actuator_abs_volt(haptic3_t *ctx, float abs_volt)
HAPTIC 3 set actuator abs volt function.
haptic3_check_communication
err_t haptic3_check_communication(haptic3_t *ctx)
HAPTIC 3 check communication function.
haptic3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: haptic3.h:285
haptic3_default_cfg
err_t haptic3_default_cfg(haptic3_t *ctx)
HAPTIC 3 default configuration function.
haptic3_t
HAPTIC 3 Click context object.
Definition: haptic3.h:258
haptic3_disable_device
void haptic3_disable_device(haptic3_t *ctx)
HAPTIC 3 disable device function.
haptic3_set_actuator_imax
err_t haptic3_set_actuator_imax(haptic3_t *ctx, float max_curr)
HAPTIC 3 set actuator imax function.
haptic3_t::en
digital_out_t en
Definition: haptic3.h:260
HAPTIC3_OK
@ HAPTIC3_OK
Definition: haptic3.h:296
haptic3_set_freq_track
err_t haptic3_set_freq_track(haptic3_t *ctx, uint8_t freq_track_en)
HAPTIC 3 set freq track function.
haptic3_enable_device
void haptic3_enable_device(haptic3_t *ctx)
HAPTIC 3 enable device function.
haptic3_cfg_t::irq
pin_name_t irq
Definition: haptic3.h:283
HAPTIC3_ERROR
@ HAPTIC3_ERROR
Definition: haptic3.h:297
haptic3_t::slave_address
uint8_t slave_address
Definition: haptic3.h:269
haptic3_set_vibration_level
err_t haptic3_set_vibration_level(haptic3_t *ctx, float level)
HAPTIC 3 set vibration level function.
haptic3_write_register_bits
err_t haptic3_write_register_bits(haptic3_t *ctx, uint8_t reg, uint8_t mask, uint8_t data_in)
HAPTIC 3 write register bits function.
haptic3_get_int_pin
uint8_t haptic3_get_int_pin(haptic3_t *ctx)
HAPTIC 3 get INT pin function.
haptic3_cfg_t::i2c_address
uint8_t i2c_address
Definition: haptic3.h:286
haptic3_cfg_t::scl
pin_name_t scl
Definition: haptic3.h:279
haptic3_generic_read
err_t haptic3_generic_read(haptic3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
HAPTIC 3 I2C reading function.
haptic3_cfg_t::en
pin_name_t en
Definition: haptic3.h:282
haptic3_t::i2c
i2c_master_t i2c
Definition: haptic3.h:266
haptic3_set_actuator_type
err_t haptic3_set_actuator_type(haptic3_t *ctx, uint8_t type)
HAPTIC 3 set actuator type function.
haptic3_generic_write
err_t haptic3_generic_write(haptic3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
HAPTIC 3 I2C writing function.
haptic3_set_actuator_nom_volt
err_t haptic3_set_actuator_nom_volt(haptic3_t *ctx, float nom_volt)
HAPTIC 3 set actuator nom volt function.
haptic3_set_acceleration_mode
err_t haptic3_set_acceleration_mode(haptic3_t *ctx, uint8_t accel_en)
HAPTIC 3 set acceleration mode function.
haptic3_cfg_setup
void haptic3_cfg_setup(haptic3_cfg_t *cfg)
HAPTIC 3 configuration object setup function.
haptic3_cfg_t::sda
pin_name_t sda
Definition: haptic3.h:280
haptic3_read_register
err_t haptic3_read_register(haptic3_t *ctx, uint8_t reg, uint8_t *data_out)
HAPTIC 3 read register function.