forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
a774cbc
commit 0c7e877
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(drv2605) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.. zephyr:code-sample:: drv2605 | ||
:name: DRV2605 Haptic Driver | ||
:relevant-api: haptics_interface | ||
|
||
Drive an LRA using the DRV2605 haptic driver chip. | ||
|
||
Overview | ||
******** | ||
|
||
This sample demonstrates how to configure a ROM playback event on the DRV2605 and executes playback | ||
of a tapping rhythmic pattern. | ||
|
||
Building and Running | ||
******************** | ||
|
||
Build the application for the :ref:`nucleo_f401re_board` board, and connect a DRV2605 haptic driver | ||
on the bus I2C1 at the address 0x5A. | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/drivers/haptics/drv2605 | ||
:board: nucleo_f401re | ||
:goals: build | ||
:compact: | ||
|
||
For flashing the application, refer to the Flashing section of the :ref:`nucleo_f401re_board` board | ||
documentation. | ||
|
||
.. code-block:: none | ||
*** Booting Zephyr OS build v3.7.0-5-g3b4f8d80850e *** | ||
[00:00:00.103,000] <inf> main: Found DRV2605 device drv2605@5a | ||
References | ||
********** | ||
|
||
- DRV2605 Datasheet: https://www.ti.com/lit/ds/symlink/drv2605.pdf |
22 changes: 22 additions & 0 deletions
22
samples/drivers/haptics/drv2605/boards/nucleo_f401re.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2024 Cirrus Logic, Inc. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/dt-bindings/i2c/i2c.h> | ||
|
||
&arduino_i2c { | ||
status = "okay"; | ||
clock-frequency = <I2C_BITRATE_STANDARD>; | ||
|
||
haptic: drv2605@5a { | ||
compatible = "ti,drv2605"; | ||
reg = <0x5a>; | ||
status = "okay"; | ||
|
||
actuator-mode = "LRA"; | ||
loop-gain = "HIGH"; | ||
feedback-brake-factor = "2X"; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_LOG=y | ||
CONFIG_HAPTICS=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2024 Cirrus Logic, Inc. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <errno.h> | ||
|
||
#include <zephyr/device.h> | ||
#include <zephyr/devicetree.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/logging/log.h> | ||
#include <zephyr/drivers/haptics.h> | ||
#include <zephyr/drivers/haptics/drv2605.h> | ||
#include <zephyr/sys/util.h> | ||
#include <sys/_stdint.h> | ||
|
||
#define LOG_LEVEL 4 | ||
|
||
LOG_MODULE_REGISTER(main); | ||
|
||
static struct drv2605_rom_data rom_data = { | ||
.library = DRV2605_LIBRARY_LRA, | ||
.brake_time = 0, | ||
.overdrive_time = 0, | ||
.sustain_neg_time = 0, | ||
.sustain_pos_time = 0, | ||
.trigger = DRV2605_MODE_INTERNAL_TRIGGER, | ||
.seq_regs[0] = 1, | ||
.seq_regs[1] = 10 | 0x80, | ||
.seq_regs[2] = 2, | ||
.seq_regs[3] = 10 | 0x80, | ||
.seq_regs[4] = 3, | ||
.seq_regs[5] = 10 | 0x80, | ||
.seq_regs[6] = 4, | ||
}; | ||
|
||
int main(void) | ||
{ | ||
const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(haptic)); | ||
union drv2605_config_data config_data = {}; | ||
|
||
int ret; | ||
|
||
if (!dev) { | ||
LOG_ERR("DRV2605 device not found"); | ||
return -ENODEV; | ||
} else if (!device_is_ready(dev)) { | ||
LOG_ERR("DRV2605 device %s is not ready", dev->name); | ||
return -EIO; | ||
} | ||
|
||
LOG_INF("Found DRV2605 device %s", dev->name); | ||
|
||
config_data.rom_data = &rom_data; | ||
|
||
ret = drv2605_haptic_config(dev, DRV2605_HAPTICS_SOURCE_ROM, &config_data); | ||
if (ret < 0) { | ||
LOG_ERR("Failed to configure ROM event: %d", ret); | ||
return ret; | ||
} | ||
|
||
ret = haptics_start_output(dev); | ||
if (ret < 0) { | ||
LOG_ERR("Failed to start ROM event: %d", ret); | ||
return ret; | ||
} | ||
|
||
return 0; | ||
} |