diff --git a/samples/drivers/haptics/drv2605/CMakeLists.txt b/samples/drivers/haptics/drv2605/CMakeLists.txt new file mode 100644 index 000000000000..786a1dc9fc82 --- /dev/null +++ b/samples/drivers/haptics/drv2605/CMakeLists.txt @@ -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}) diff --git a/samples/drivers/haptics/drv2605/README.rst b/samples/drivers/haptics/drv2605/README.rst new file mode 100644 index 000000000000..4d6ca198b343 --- /dev/null +++ b/samples/drivers/haptics/drv2605/README.rst @@ -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] main: Found DRV2605 device drv2605@5a + +References +********** + +- DRV2605 Datasheet: https://www.ti.com/lit/ds/symlink/drv2605.pdf diff --git a/samples/drivers/haptics/drv2605/boards/nucleo_f401re.overlay b/samples/drivers/haptics/drv2605/boards/nucleo_f401re.overlay new file mode 100644 index 000000000000..324d32f6ff4c --- /dev/null +++ b/samples/drivers/haptics/drv2605/boards/nucleo_f401re.overlay @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Cirrus Logic, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +&arduino_i2c { + status = "okay"; + clock-frequency = ; + + haptic: drv2605@5a { + compatible = "ti,drv2605"; + reg = <0x5a>; + status = "okay"; + + actuator-mode = "LRA"; + loop-gain = "HIGH"; + feedback-brake-factor = "2X"; + }; +}; diff --git a/samples/drivers/haptics/drv2605/prj.conf b/samples/drivers/haptics/drv2605/prj.conf new file mode 100644 index 000000000000..32ef5e97454e --- /dev/null +++ b/samples/drivers/haptics/drv2605/prj.conf @@ -0,0 +1,2 @@ +CONFIG_LOG=y +CONFIG_HAPTICS=y diff --git a/samples/drivers/haptics/drv2605/src/main.c b/samples/drivers/haptics/drv2605/src/main.c new file mode 100644 index 000000000000..37e3369fa06a --- /dev/null +++ b/samples/drivers/haptics/drv2605/src/main.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 Cirrus Logic, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#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; +}