Skip to content

Commit bed4ad2

Browse files
kartbencfriedt
authored andcommitted
drivers: haptics: add DRV2605_SEQ_WAIT_MS macro
Add a macro to simplify the creation of wait/delay values for the waveform sequencer. Signed-off-by: Benjamin Cabé <[email protected]>
1 parent db3512d commit bed4ad2

File tree

2 files changed

+22
-3
lines changed
  • include/zephyr/drivers/haptics
  • samples/drivers/haptics/drv2605/src

2 files changed

+22
-3
lines changed

include/zephyr/drivers/haptics/drv2605.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,28 @@ extern "C" {
2626
* @{
2727
*/
2828

29+
/**
30+
* @name Helpers
31+
* @{
32+
*/
33+
2934
/** Maximum number of waveforms that can be stored in the sequencer */
3035
#define DRV2605_WAVEFORM_SEQUENCER_MAX 8
3136

37+
/**
38+
* @brief Creates a wait/delay value for the waveform sequencer.
39+
*
40+
* @details This macro generates a byte value that, when placed in the drv2605_rom_data::seq_regs
41+
* array, instructs the DRV2605 playback engine to idle for a specified duration.
42+
*
43+
* @param ms The desired delay in milliseconds (rounded down to the nearest 10ms). Valid range is
44+
* 10 to 1270.
45+
* @return A byte literal representing the wait time for the sequencer.
46+
*/
47+
#define DRV2605_WAVEFORM_SEQUENCER_WAIT_MS(ms) (0x80 | ((ms) / 10))
48+
49+
/** @} */
50+
3251
/**
3352
* @brief Effect libraries
3453
*

samples/drivers/haptics/drv2605/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ static struct drv2605_rom_data rom_data = {
2727
.sustain_pos_time = 0,
2828
.trigger = DRV2605_MODE_INTERNAL_TRIGGER,
2929
.seq_regs[0] = 1,
30-
.seq_regs[1] = 10 | 0x80,
30+
.seq_regs[1] = DRV2605_WAVEFORM_SEQUENCER_WAIT_MS(100),
3131
.seq_regs[2] = 2,
32-
.seq_regs[3] = 10 | 0x80,
32+
.seq_regs[3] = DRV2605_WAVEFORM_SEQUENCER_WAIT_MS(100),
3333
.seq_regs[4] = 3,
34-
.seq_regs[5] = 10 | 0x80,
34+
.seq_regs[5] = DRV2605_WAVEFORM_SEQUENCER_WAIT_MS(100),
3535
.seq_regs[6] = 4,
3636
};
3737

0 commit comments

Comments
 (0)