Skip to content

Commit 0c7e877

Browse files
rriveramcruscarlescufi
authored andcommitted
samples: drv2605: Adds a DRV2605 sample application
Adds a sample application for the DRV2605 haptic driver IC. Signed-off-by: Ricardo Rivera-Matos <[email protected]>
1 parent a774cbc commit 0c7e877

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(drv2605)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. zephyr:code-sample:: drv2605
2+
:name: DRV2605 Haptic Driver
3+
:relevant-api: haptics_interface
4+
5+
Drive an LRA using the DRV2605 haptic driver chip.
6+
7+
Overview
8+
********
9+
10+
This sample demonstrates how to configure a ROM playback event on the DRV2605 and executes playback
11+
of a tapping rhythmic pattern.
12+
13+
Building and Running
14+
********************
15+
16+
Build the application for the :ref:`nucleo_f401re_board` board, and connect a DRV2605 haptic driver
17+
on the bus I2C1 at the address 0x5A.
18+
19+
.. zephyr-app-commands::
20+
:zephyr-app: samples/drivers/haptics/drv2605
21+
:board: nucleo_f401re
22+
:goals: build
23+
:compact:
24+
25+
For flashing the application, refer to the Flashing section of the :ref:`nucleo_f401re_board` board
26+
documentation.
27+
28+
.. code-block:: none
29+
30+
*** Booting Zephyr OS build v3.7.0-5-g3b4f8d80850e ***
31+
[00:00:00.103,000] <inf> main: Found DRV2605 device drv2605@5a
32+
33+
References
34+
**********
35+
36+
- DRV2605 Datasheet: https://www.ti.com/lit/ds/symlink/drv2605.pdf
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2024 Cirrus Logic, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/i2c/i2c.h>
8+
9+
&arduino_i2c {
10+
status = "okay";
11+
clock-frequency = <I2C_BITRATE_STANDARD>;
12+
13+
haptic: drv2605@5a {
14+
compatible = "ti,drv2605";
15+
reg = <0x5a>;
16+
status = "okay";
17+
18+
actuator-mode = "LRA";
19+
loop-gain = "HIGH";
20+
feedback-brake-factor = "2X";
21+
};
22+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_LOG=y
2+
CONFIG_HAPTICS=y
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2024 Cirrus Logic, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <errno.h>
8+
9+
#include <zephyr/device.h>
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/kernel.h>
12+
#include <zephyr/logging/log.h>
13+
#include <zephyr/drivers/haptics.h>
14+
#include <zephyr/drivers/haptics/drv2605.h>
15+
#include <zephyr/sys/util.h>
16+
#include <sys/_stdint.h>
17+
18+
#define LOG_LEVEL 4
19+
20+
LOG_MODULE_REGISTER(main);
21+
22+
static struct drv2605_rom_data rom_data = {
23+
.library = DRV2605_LIBRARY_LRA,
24+
.brake_time = 0,
25+
.overdrive_time = 0,
26+
.sustain_neg_time = 0,
27+
.sustain_pos_time = 0,
28+
.trigger = DRV2605_MODE_INTERNAL_TRIGGER,
29+
.seq_regs[0] = 1,
30+
.seq_regs[1] = 10 | 0x80,
31+
.seq_regs[2] = 2,
32+
.seq_regs[3] = 10 | 0x80,
33+
.seq_regs[4] = 3,
34+
.seq_regs[5] = 10 | 0x80,
35+
.seq_regs[6] = 4,
36+
};
37+
38+
int main(void)
39+
{
40+
const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(haptic));
41+
union drv2605_config_data config_data = {};
42+
43+
int ret;
44+
45+
if (!dev) {
46+
LOG_ERR("DRV2605 device not found");
47+
return -ENODEV;
48+
} else if (!device_is_ready(dev)) {
49+
LOG_ERR("DRV2605 device %s is not ready", dev->name);
50+
return -EIO;
51+
}
52+
53+
LOG_INF("Found DRV2605 device %s", dev->name);
54+
55+
config_data.rom_data = &rom_data;
56+
57+
ret = drv2605_haptic_config(dev, DRV2605_HAPTICS_SOURCE_ROM, &config_data);
58+
if (ret < 0) {
59+
LOG_ERR("Failed to configure ROM event: %d", ret);
60+
return ret;
61+
}
62+
63+
ret = haptics_start_output(dev);
64+
if (ret < 0) {
65+
LOG_ERR("Failed to start ROM event: %d", ret);
66+
return ret;
67+
}
68+
69+
return 0;
70+
}

0 commit comments

Comments
 (0)