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
41#ifdef PREINIT_SUPPORTED
42#include "preinit.h"
43#endif
44
45#ifdef MikroCCoreVersion
46 #if MikroCCoreVersion >= 1
47 #include "delays.h"
48 #endif
49#endif
50
51#include "drv_digital_out.h"
52#include "drv_digital_in.h"
53#include "drv_i2c_master.h"
54#include "drv_pwm.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define HAPTIC_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
77#define HAPTIC_RETVAL uint8_t
78
79#define HAPTIC_OK 0x00
80#define HAPTIC_INIT_ERROR 0xFF
87#define HAPTIC_I2C_ADDRESS 0x5A
94#define HAPTIC_REG_STATUS 0x00
95#define HAPTIC_REG_MODE 0x01
96#define HAPTIC_REG_RTPIN 0x02
97#define HAPTIC_REG_LIBRARY 0x03
98#define HAPTIC_REG_WAVESEQ1 0x04
99#define HAPTIC_REG_WAVESEQ2 0x05
100#define HAPTIC_REG_WAVESEQ3 0x06
101#define HAPTIC_REG_WAVESEQ4 0x07
102#define HAPTIC_REG_WAVESEQ5 0x08
103#define HAPTIC_REG_WAVESEQ6 0x09
104#define HAPTIC_REG_WAVESEQ7 0x0A
105#define HAPTIC_REG_WAVESEQ8 0x0B
106
107#define HAPTIC_REG_GO 0x0C
108#define HAPTIC_REG_OVERDRIVE 0x0D
109#define HAPTIC_REG_SUSTAINPOS 0x0E
110#define HAPTIC_REG_SUSTAINNEG 0x0F
111#define HAPTIC_REG_BREAK 0x10
112#define HAPTIC_REG_AUDIOCTRL 0x11
113#define HAPTIC_REG_AUDIOMININ 0x12
114#define HAPTIC_REG_AUDIOMAXIN 0x13
115#define HAPTIC_REG_AUDIOMINOUT 0x14
116#define HAPTIC_REG_AUDIOMAXOUT 0x15
117#define HAPTIC_REG_RATEDV 0x16
118#define HAPTIC_REG_CLAMPV 0x17
119#define HAPTIC_REG_AUTOCALCOMP 0x18
120#define HAPTIC_REG_AUTOCALEMF 0x19
121#define HAPTIC_REG_FEEDBACK 0x1A
122#define HAPTIC_REG_CONTROL1 0x1B
123#define HAPTIC_REG_CONTROL2 0x1C
124#define HAPTIC_REG_CONTROL3 0x1D
125#define HAPTIC_REG_CONTROL4 0x1E
126#define HAPTIC_REG_VBAT 0x21
127#define HAPTIC_REG_LRARESON 0x22
134#define HAPTIC_MODE_INTTRIG 0x00
135#define HAPTIC_MODE_EXTTRIGEDGE 0x01
136#define HAPTIC_MODE_EXTTRIGLVL 0x02
137#define HAPTIC_MODE_PWMANALOG 0x03
138#define HAPTIC_MODE_AUDIOVIBE 0x04
139#define HAPTIC_MODE_REALTIME 0x05
140#define HAPTIC_MODE_DIAGNOS 0x06
141#define HAPTIC_MODE_AUTOCAL 0x07
148#define HAPTIC_DEFAULT_MIN_INPUT 0x19
149#define HAPTIC_DEFAULT_MAX_INPUT 0xFF
152 // End group macro
153// --------------------------------------------------------------- PUBLIC TYPES
162typedef struct
163{
164 // Output pins
165
166 digital_out_t cs;
167
168 // Modules
169
170 i2c_master_t i2c;
171 pwm_t pwm;
172
173 // ctx variable
174
176 uint32_t pwm_freq;
177
178} haptic_t;
179
183typedef struct
184{
185 // Communication gpio pins
186
187 pin_name_t scl;
188 pin_name_t sda;
189 pin_name_t pwm;
190
191 // Additional gpio pins
192
193 pin_name_t cs;
194
195 // static variable
196
197 uint32_t i2c_speed;
198 uint8_t i2c_address;
199 uint32_t dev_pwm_freq;
200
202
203 // End types group
204// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
205
211#ifdef __cplusplus
212extern "C"{
213#endif
214
224
234
245void haptic_generic_write ( haptic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
246
257void haptic_generic_read ( haptic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
258
271
281
292void haptic_write_byte ( haptic_t *ctx, uint8_t reg_address, uint8_t write_data );
293
307uint8_t haptic_read_byte ( haptic_t *ctx, uint8_t reg_address );
308
318void haptic_set_mode ( haptic_t *ctx, uint8_t sel_mode );
319
329
342
352void haptic_set_rtp_input ( haptic_t *ctx, uint8_t input );
353
363
373uint8_t haptic_set_library ( haptic_t *ctx, uint8_t library );
374
385
396void haptic_set_overdrive_offset ( haptic_t *ctx, uint8_t temp_data );
397
408void haptic_set_sustain_offset_positive ( haptic_t *ctx, uint8_t temp_data );
409
420void haptic_set_sustain_offset_negative ( haptic_t *ctx, uint8_t temp_data );
421
432void haptic_set_brake_time_offset ( haptic_t *ctx, uint8_t temp_data );
433
444void haptic_set_audio_minimum_input ( haptic_t *ctx, uint8_t temp_data );
445
456void haptic_set_audio_maximum_input ( haptic_t *ctx, uint8_t temp_data );
457
468void haptic_set_audio_minimum_output ( haptic_t *ctx, uint8_t temp_data );
469
480void haptic_set_audio_maximum_output ( haptic_t *ctx, uint8_t temp_data );
481
492void haptic_set_rated_voltage ( haptic_t *ctx, uint8_t temp_data );
493
504void haptic_set_overdrive_clamp_voltage ( haptic_t *ctx, uint8_t temp_data );
505
519uint8_t haptic_set_audio_peak_time ( haptic_t *ctx, uint8_t temp_data );
520
531uint8_t haptic_set_audio_low_pass_filter ( haptic_t *ctx, uint8_t temp_data );
532
546
560
573
589
600
611
627uint8_t haptic_setBrakeFactor( haptic_t *ctx, uint8_t brake_factor );
628
642uint8_t haptic_set_loop_gain ( haptic_t *ctx, uint8_t gain );
643
654
665
680void haptic_set_sequence ( haptic_t *ctx, uint8_t temp_data );
681
692
702void haptic_set_duty_cycle ( haptic_t *ctx, float duty_cycle );
703
712
721
722#ifdef __cplusplus
723}
724#endif
725#endif // _HAPTIC_H_
726
727 // End public_function group
729
730// ------------------------------------------------------------------------- END
#define HAPTIC_RETVAL
Definition haptic.h:77
void haptic_cfg_setup(haptic_cfg_t *cfg)
Config Object Initialization function.
void haptic_set_to_erm_mode(haptic_t *ctx)
Sets the Haptic click in ERM mode function.
uint8_t haptic_get_calibration_result_emf(haptic_t *ctx)
Reads the rated back - EMF function.
uint8_t haptic_setBrakeFactor(haptic_t *ctx, uint8_t brake_factor)
Sets the feedback gain ratio function.
void haptic_soft_reset(haptic_t *ctx)
Resets all the registers function.
void haptic_set_brake_time_offset(haptic_t *ctx, uint8_t temp_data)
Sets desired brake time offset function.
void haptic_set_duty_cycle(haptic_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
void haptic_set_sustain_offset_positive(haptic_t *ctx, uint8_t temp_data)
Sets desired sustain offset - positive function.
void haptic_set_input_to_pwm(haptic_t *ctx)
Sets the input for PWM control function.
void haptic_set_to_lra_mode(haptic_t *ctx)
Sets the Haptic click in LRA mode function.
void haptic_set_audio_maximum_input(haptic_t *ctx, uint8_t temp_data)
Sets maximum input for audio to vibe mode function.
uint8_t haptic_set_audio_peak_time(haptic_t *ctx, uint8_t temp_data)
Sets the peak detection time function.
void haptic_enable(haptic_t *ctx)
Enable the device function.
void haptic_pwm_stop(haptic_t *ctx)
Stop PWM module.
void haptic_set_audio_minimum_input(haptic_t *ctx, uint8_t temp_data)
Sets minimum input for audio to vibe mode function.
void haptic_set_state_hi(haptic_t *ctx)
Generic read function.
void haptic_pwm_start(haptic_t *ctx)
Start PWM module.
void haptic_set_overdrive_clamp_voltage(haptic_t *ctx, uint8_t temp_data)
Sets a clamp function.
void haptic_set_rated_voltage(haptic_t *ctx, uint8_t temp_data)
Sets the reference voltage function.
uint8_t haptic_get_lra_resonance_period(haptic_t *ctx)
Reads the measurement of the LRA resonance period function.
void haptic_set_audio_maximum_output(haptic_t *ctx, uint8_t temp_data)
Sets maximum output for audio to vibe mode function.
uint8_t haptic_read_byte(haptic_t *ctx, uint8_t reg_address)
Generic read the byte of data function.
void haptic_set_sequence(haptic_t *ctx, uint8_t temp_data)
Sets the waveform identifier function.
void haptic_set_mode(haptic_t *ctx, uint8_t sel_mode)
Sets the Haptic click to desired mode function.
void haptic_set_sustain_offset_negative(haptic_t *ctx, uint8_t temp_data)
Sets desired sustain offset - negative function.
void haptic_write_byte(haptic_t *ctx, uint8_t reg_address, uint8_t write_data)
Generic write the byte of data function.
void haptic_disable(haptic_t *ctx)
Disable the device function.
HAPTIC_RETVAL haptic_init(haptic_t *ctx, haptic_cfg_t *cfg)
Initialization function.
uint8_t haptic_set_library(haptic_t *ctx, uint8_t library)
Sets the desired library of vibrating patterns to read function.
void haptic_set_overdrive_offset(haptic_t *ctx, uint8_t temp_data)
Sets overdrive offset function.
uint8_t haptic_set_audio_low_pass_filter(haptic_t *ctx, uint8_t temp_data)
Sets the low-pass filter frequency function.
uint8_t haptic_set_loop_gain(haptic_t *ctx, uint8_t gain)
Selects a loop gain function.
uint8_t haptic_get_calibration_result_comp(haptic_t *ctx)
Reads the voltage-compensation function.
void haptic_set_audio_minimum_output(haptic_t *ctx, uint8_t temp_data)
Sets minimum output for audio to vibe mode function.
void haptic_enable_ac_coulping(haptic_t *ctx)
Applies a 0.9-V common mode voltage function.
void haptic_generic_read(haptic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void haptic_set_rtp_input(haptic_t *ctx, uint8_t input)
Sets the desired input for RTP mode function.
uint8_t haptic_get_status(haptic_t *ctx)
Get status register value function.
void haptic_set_input_to_analog(haptic_t *ctx)
Sets the input to analog function.
uint8_t haptic_get_supply_voltage_value(haptic_t *ctx)
Reading of the supply voltage function.
void haptic_start_motor(haptic_t *ctx)
Starts moving the motor function.
void haptic_generic_write(haptic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
Click configuration structure definition.
Definition haptic.h:184
uint32_t i2c_speed
Definition haptic.h:197
uint32_t dev_pwm_freq
Definition haptic.h:199
pin_name_t scl
Definition haptic.h:187
pin_name_t pwm
Definition haptic.h:189
pin_name_t sda
Definition haptic.h:188
pin_name_t cs
Definition haptic.h:193
uint8_t i2c_address
Definition haptic.h:198
Click ctx object definition.
Definition haptic.h:163
digital_out_t cs
Definition haptic.h:166
uint32_t pwm_freq
Definition haptic.h:176
i2c_master_t i2c
Definition haptic.h:170
uint8_t slave_address
Definition haptic.h:175
pwm_t pwm
Definition haptic.h:171