haptic  2.0.0.0
haptic.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef HAPTIC_H
35 #define HAPTIC_H
36 
37 #include "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_out.h"
48 #include "drv_digital_in.h"
49 #include "drv_i2c_master.h"
50 #include "drv_pwm.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define HAPTIC_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
66  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
67 
73 #define HAPTIC_RETVAL uint8_t
74 
75 #define HAPTIC_OK 0x00
76 #define HAPTIC_INIT_ERROR 0xFF
77 
83 #define HAPTIC_I2C_ADDRESS 0x5A
84 
90 #define HAPTIC_REG_STATUS 0x00
91 #define HAPTIC_REG_MODE 0x01
92 #define HAPTIC_REG_RTPIN 0x02
93 #define HAPTIC_REG_LIBRARY 0x03
94 #define HAPTIC_REG_WAVESEQ1 0x04
95 #define HAPTIC_REG_WAVESEQ2 0x05
96 #define HAPTIC_REG_WAVESEQ3 0x06
97 #define HAPTIC_REG_WAVESEQ4 0x07
98 #define HAPTIC_REG_WAVESEQ5 0x08
99 #define HAPTIC_REG_WAVESEQ6 0x09
100 #define HAPTIC_REG_WAVESEQ7 0x0A
101 #define HAPTIC_REG_WAVESEQ8 0x0B
102 
103 #define HAPTIC_REG_GO 0x0C
104 #define HAPTIC_REG_OVERDRIVE 0x0D
105 #define HAPTIC_REG_SUSTAINPOS 0x0E
106 #define HAPTIC_REG_SUSTAINNEG 0x0F
107 #define HAPTIC_REG_BREAK 0x10
108 #define HAPTIC_REG_AUDIOCTRL 0x11
109 #define HAPTIC_REG_AUDIOMININ 0x12
110 #define HAPTIC_REG_AUDIOMAXIN 0x13
111 #define HAPTIC_REG_AUDIOMINOUT 0x14
112 #define HAPTIC_REG_AUDIOMAXOUT 0x15
113 #define HAPTIC_REG_RATEDV 0x16
114 #define HAPTIC_REG_CLAMPV 0x17
115 #define HAPTIC_REG_AUTOCALCOMP 0x18
116 #define HAPTIC_REG_AUTOCALEMF 0x19
117 #define HAPTIC_REG_FEEDBACK 0x1A
118 #define HAPTIC_REG_CONTROL1 0x1B
119 #define HAPTIC_REG_CONTROL2 0x1C
120 #define HAPTIC_REG_CONTROL3 0x1D
121 #define HAPTIC_REG_CONTROL4 0x1E
122 #define HAPTIC_REG_VBAT 0x21
123 #define HAPTIC_REG_LRARESON 0x22
124 
130 #define HAPTIC_MODE_INTTRIG 0x00
131 #define HAPTIC_MODE_EXTTRIGEDGE 0x01
132 #define HAPTIC_MODE_EXTTRIGLVL 0x02
133 #define HAPTIC_MODE_PWMANALOG 0x03
134 #define HAPTIC_MODE_AUDIOVIBE 0x04
135 #define HAPTIC_MODE_REALTIME 0x05
136 #define HAPTIC_MODE_DIAGNOS 0x06
137 #define HAPTIC_MODE_AUTOCAL 0x07
138 
144 #define HAPTIC_DEFAULT_MIN_INPUT 0x19
145 #define HAPTIC_DEFAULT_MAX_INPUT 0xFF
146  // End group macro
149 // --------------------------------------------------------------- PUBLIC TYPES
158 typedef struct
159 {
160  // Output pins
161 
162  digital_out_t cs;
163 
164  // Modules
165 
166  i2c_master_t i2c;
167  pwm_t pwm;
168 
169  // ctx variable
170 
171  uint8_t slave_address;
172  uint32_t pwm_freq;
173 
174 } haptic_t;
175 
179 typedef struct
180 {
181  // Communication gpio pins
182 
183  pin_name_t scl;
184  pin_name_t sda;
185  pin_name_t pwm;
186 
187  // Additional gpio pins
188 
189  pin_name_t cs;
190 
191  // static variable
192 
193  uint32_t i2c_speed;
194  uint8_t i2c_address;
195  uint32_t dev_pwm_freq;
196 
197 } haptic_cfg_t;
198  // End types group
200 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
201 
207 #ifdef __cplusplus
208 extern "C"{
209 #endif
210 
220 
230 
241 void haptic_generic_write ( haptic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
242 
253 void haptic_generic_read ( haptic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
254 
266 void haptic_enable ( haptic_t *ctx );
267 
276 void haptic_disable ( haptic_t *ctx );
277 
288 void haptic_write_byte ( haptic_t *ctx, uint8_t reg_address, uint8_t write_data );
289 
303 uint8_t haptic_read_byte ( haptic_t *ctx, uint8_t reg_address );
304 
314 void haptic_set_mode ( haptic_t *ctx, uint8_t sel_mode );
315 
325 
337 uint8_t haptic_get_status ( haptic_t *ctx );
338 
348 void haptic_set_rtp_input ( haptic_t *ctx, uint8_t input );
349 
359 
369 uint8_t haptic_set_library ( haptic_t *ctx, uint8_t library );
370 
381 
392 void haptic_set_overdrive_offset ( haptic_t *ctx, uint8_t temp_data );
393 
404 void haptic_set_sustain_offset_positive ( haptic_t *ctx, uint8_t temp_data );
405 
416 void haptic_set_sustain_offset_negative ( haptic_t *ctx, uint8_t temp_data );
417 
428 void haptic_set_brake_time_offset ( haptic_t *ctx, uint8_t temp_data );
429 
440 void haptic_set_audio_minimum_input ( haptic_t *ctx, uint8_t temp_data );
441 
452 void haptic_set_audio_maximum_input ( haptic_t *ctx, uint8_t temp_data );
453 
464 void haptic_set_audio_minimum_output ( haptic_t *ctx, uint8_t temp_data );
465 
476 void haptic_set_audio_maximum_output ( haptic_t *ctx, uint8_t temp_data );
477 
488 void haptic_set_rated_voltage ( haptic_t *ctx, uint8_t temp_data );
489 
500 void haptic_set_overdrive_clamp_voltage ( haptic_t *ctx, uint8_t temp_data );
501 
515 uint8_t haptic_set_audio_peak_time ( haptic_t *ctx, uint8_t temp_data );
516 
527 uint8_t haptic_set_audio_low_pass_filter ( haptic_t *ctx, uint8_t temp_data );
528 
542 
556 
569 
585 
596 
607 
623 uint8_t haptic_setBrakeFactor( haptic_t *ctx, uint8_t brake_factor );
624 
638 uint8_t haptic_set_loop_gain ( haptic_t *ctx, uint8_t gain );
639 
650 
661 
676 void haptic_set_sequence ( haptic_t *ctx, uint8_t temp_data );
677 
688 
698 void haptic_set_duty_cycle ( haptic_t *ctx, float duty_cycle );
699 
707 void haptic_pwm_stop ( haptic_t *ctx );
708 
717 
718 #ifdef __cplusplus
719 }
720 #endif
721 #endif // _HAPTIC_H_
722  // End public_function group
725 
726 // ------------------------------------------------------------------------- END
haptic_set_audio_minimum_output
void haptic_set_audio_minimum_output(haptic_t *ctx, uint8_t temp_data)
Sets minimum output for audio to vibe mode function.
haptic_set_to_lra_mode
void haptic_set_to_lra_mode(haptic_t *ctx)
Sets the Haptic click in LRA mode function.
haptic_set_audio_minimum_input
void haptic_set_audio_minimum_input(haptic_t *ctx, uint8_t temp_data)
Sets minimum input for audio to vibe mode function.
haptic_set_duty_cycle
void haptic_set_duty_cycle(haptic_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
haptic_set_brake_time_offset
void haptic_set_brake_time_offset(haptic_t *ctx, uint8_t temp_data)
Sets desired brake time offset function.
haptic_soft_reset
void haptic_soft_reset(haptic_t *ctx)
Resets all the registers function.
haptic_cfg_t::cs
pin_name_t cs
Definition: haptic.h:189
haptic_set_sustain_offset_positive
void haptic_set_sustain_offset_positive(haptic_t *ctx, uint8_t temp_data)
Sets desired sustain offset - positive function.
haptic_set_rated_voltage
void haptic_set_rated_voltage(haptic_t *ctx, uint8_t temp_data)
Sets the reference voltage function.
haptic_t
Click ctx object definition.
Definition: haptic.h:159
haptic_pwm_start
void haptic_pwm_start(haptic_t *ctx)
Start PWM module.
haptic_cfg_t
Click configuration structure definition.
Definition: haptic.h:180
haptic_set_library
uint8_t haptic_set_library(haptic_t *ctx, uint8_t library)
Sets the desired library of vibrating patterns to read function.
haptic_get_calibration_result_comp
uint8_t haptic_get_calibration_result_comp(haptic_t *ctx)
Reads the voltage-compensation function.
haptic_t::cs
digital_out_t cs
Definition: haptic.h:162
haptic_set_audio_maximum_input
void haptic_set_audio_maximum_input(haptic_t *ctx, uint8_t temp_data)
Sets maximum input for audio to vibe mode function.
haptic_set_input_to_analog
void haptic_set_input_to_analog(haptic_t *ctx)
Sets the input to analog function.
haptic_cfg_t::scl
pin_name_t scl
Definition: haptic.h:183
haptic_init
HAPTIC_RETVAL haptic_init(haptic_t *ctx, haptic_cfg_t *cfg)
Initialization function.
HAPTIC_RETVAL
#define HAPTIC_RETVAL
Definition: haptic.h:73
haptic_generic_read
void haptic_generic_read(haptic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
haptic_set_rtp_input
void haptic_set_rtp_input(haptic_t *ctx, uint8_t input)
Sets the desired input for RTP mode function.
haptic_pwm_stop
void haptic_pwm_stop(haptic_t *ctx)
Stop PWM module.
haptic_read_byte
uint8_t haptic_read_byte(haptic_t *ctx, uint8_t reg_address)
Generic read the byte of data function.
haptic_set_audio_maximum_output
void haptic_set_audio_maximum_output(haptic_t *ctx, uint8_t temp_data)
Sets maximum output for audio to vibe mode function.
haptic_set_loop_gain
uint8_t haptic_set_loop_gain(haptic_t *ctx, uint8_t gain)
Selects a loop gain function.
haptic_get_lra_resonance_period
uint8_t haptic_get_lra_resonance_period(haptic_t *ctx)
Reads the measurement of the LRA resonance period function.
haptic_enable
void haptic_enable(haptic_t *ctx)
Enable the device function.
haptic_t::i2c
i2c_master_t i2c
Definition: haptic.h:166
haptic_cfg_t::pwm
pin_name_t pwm
Definition: haptic.h:185
haptic_set_audio_low_pass_filter
uint8_t haptic_set_audio_low_pass_filter(haptic_t *ctx, uint8_t temp_data)
Sets the low-pass filter frequency function.
haptic_set_audio_peak_time
uint8_t haptic_set_audio_peak_time(haptic_t *ctx, uint8_t temp_data)
Sets the peak detection time function.
haptic_set_overdrive_clamp_voltage
void haptic_set_overdrive_clamp_voltage(haptic_t *ctx, uint8_t temp_data)
Sets a clamp function.
haptic_t::pwm
pwm_t pwm
Definition: haptic.h:167
haptic_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: haptic.h:195
haptic_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: haptic.h:193
haptic_setBrakeFactor
uint8_t haptic_setBrakeFactor(haptic_t *ctx, uint8_t brake_factor)
Sets the feedback gain ratio function.
haptic_get_calibration_result_emf
uint8_t haptic_get_calibration_result_emf(haptic_t *ctx)
Reads the rated back - EMF function.
haptic_disable
void haptic_disable(haptic_t *ctx)
Disable the device function.
haptic_set_sustain_offset_negative
void haptic_set_sustain_offset_negative(haptic_t *ctx, uint8_t temp_data)
Sets desired sustain offset - negative function.
haptic_set_to_erm_mode
void haptic_set_to_erm_mode(haptic_t *ctx)
Sets the Haptic click in ERM mode function.
haptic_enable_ac_coulping
void haptic_enable_ac_coulping(haptic_t *ctx)
Applies a 0.9-V common mode voltage function.
haptic_get_status
uint8_t haptic_get_status(haptic_t *ctx)
Get status register value function.
haptic_generic_write
void haptic_generic_write(haptic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
haptic_t::slave_address
uint8_t slave_address
Definition: haptic.h:171
haptic_set_overdrive_offset
void haptic_set_overdrive_offset(haptic_t *ctx, uint8_t temp_data)
Sets overdrive offset function.
haptic_t::pwm_freq
uint32_t pwm_freq
Definition: haptic.h:172
haptic_set_sequence
void haptic_set_sequence(haptic_t *ctx, uint8_t temp_data)
Sets the waveform identifier function.
haptic_set_mode
void haptic_set_mode(haptic_t *ctx, uint8_t sel_mode)
Sets the Haptic click to desired mode function.
haptic_start_motor
void haptic_start_motor(haptic_t *ctx)
Starts moving the motor function.
haptic_get_supply_voltage_value
uint8_t haptic_get_supply_voltage_value(haptic_t *ctx)
Reading of the supply voltage function.
haptic_cfg_t::i2c_address
uint8_t i2c_address
Definition: haptic.h:194
haptic_write_byte
void haptic_write_byte(haptic_t *ctx, uint8_t reg_address, uint8_t write_data)
Generic write the byte of data function.
haptic_cfg_t::sda
pin_name_t sda
Definition: haptic.h:184
haptic_set_state_hi
void haptic_set_state_hi(haptic_t *ctx)
Generic read function.
haptic_cfg_setup
void haptic_cfg_setup(haptic_cfg_t *cfg)
Config Object Initialization function.
haptic_set_input_to_pwm
void haptic_set_input_to_pwm(haptic_t *ctx)
Sets the input for PWM control function.