diff --git a/boards/renesas/ek_ra2a1/Kconfig.defconfig b/boards/renesas/ek_ra2a1/Kconfig.defconfig new file mode 100644 index 000000000000..842902a62b95 --- /dev/null +++ b/boards/renesas/ek_ra2a1/Kconfig.defconfig @@ -0,0 +1,9 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +if !INPUT_RENESAS_RA_QE_TOUCH_CFG + +config INPUT_RENESAS_RA_CTSU_NUM_SELF_ELEMENTS + default 1 + +endif # INPUT_RENESAS_RA_QE_TOUCH_CFG diff --git a/boards/renesas/ek_ra2a1/ek_ra2a1-pinctrl.dtsi b/boards/renesas/ek_ra2a1/ek_ra2a1-pinctrl.dtsi index 690f5736c759..79fe97458138 100644 --- a/boards/renesas/ek_ra2a1/ek_ra2a1-pinctrl.dtsi +++ b/boards/renesas/ek_ra2a1/ek_ra2a1-pinctrl.dtsi @@ -51,4 +51,12 @@ renesas,analog-enable; }; }; + + ctsu_default: ctsu_default { + group1 { + /* TS01 TSCAP */ + psels = , + ; + }; + }; }; diff --git a/boards/renesas/ek_ra2a1/ek_ra2a1.dts b/boards/renesas/ek_ra2a1/ek_ra2a1.dts index 39d5d372cd96..6004c429c1e7 100644 --- a/boards/renesas/ek_ra2a1/ek_ra2a1.dts +++ b/boards/renesas/ek_ra2a1/ek_ra2a1.dts @@ -83,6 +83,10 @@ status = "okay"; }; +&ioport4 { + status = "okay"; +}; + &port_irq6 { interrupts = <29 3>; status = "okay"; @@ -120,3 +124,40 @@ &wdt { status = "okay"; }; + +&ctsu { + pinctrl-0 = <&ctsu_default>; + pinctrl-names = "default"; + interrupts = <10 3>, <11 3>, <12 3>; + interrupt-names = "ctsuwr", "ctsurd", "ctsufn"; + clock-div = <1>; + pwr-supply-sel = "vcc"; + atune1 = "normal"; + measure-mode = "self-multi-scan"; + tscap-gpios = <&ioport4 9 0>; + status = "okay"; + + group1 { + ctsuchac = <0x00>, <0x80>, <0x00>, <0x00>, <0x00>; + ctsuchtrc = <0x00>, <0x00>, <0x00>, <0x00>, <0x00>; + rx-count = <1>; + tx-count = <0>; + ssdiv = "1.00"; + so = <0x108>; + snum = <0x01>; + sdpa = <0x0B>; + on-freq = <3>; + off-freq = <3>; + drift-freq = <255>; + cancel-freq = <0>; + num-moving-avg = <4>; + + ts1: button1 { + compatible = "renesas,ra-ctsu-button"; + event-code = ; + elements = <0>; + threshold = <2305>; + hysteresis = <115>; + }; + }; +}; diff --git a/boards/renesas/rssk_ra2l1/Kconfig.rssk_ra2l1 b/boards/renesas/rssk_ra2l1/Kconfig.rssk_ra2l1 new file mode 100644 index 000000000000..268835728962 --- /dev/null +++ b/boards/renesas/rssk_ra2l1/Kconfig.rssk_ra2l1 @@ -0,0 +1,5 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_RSSK_RA2L1 + select SOC_R7FA2L1ABXXFP diff --git a/boards/renesas/rssk_ra2l1/board.cmake b/boards/renesas/rssk_ra2l1/board.cmake new file mode 100644 index 000000000000..77d8090ea705 --- /dev/null +++ b/boards/renesas/rssk_ra2l1/board.cmake @@ -0,0 +1,8 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +board_runner_args(jlink "--device=r7fa2l1ab") +board_runner_args(pyocd "--target=r7fa2l1ab") + +include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) +include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake) diff --git a/boards/renesas/rssk_ra2l1/board.yml b/boards/renesas/rssk_ra2l1/board.yml new file mode 100644 index 000000000000..61447d9e96cd --- /dev/null +++ b/boards/renesas/rssk_ra2l1/board.yml @@ -0,0 +1,6 @@ +board: + name: rssk_ra2l1 + full_name: Capacitive Touch Evaluation System for RA2L1 + vendor: renesas + socs: + - name: r7fa2l1abxxfp diff --git a/boards/renesas/rssk_ra2l1/doc/index.rst b/boards/renesas/rssk_ra2l1/doc/index.rst new file mode 100644 index 000000000000..a8fb57ace932 --- /dev/null +++ b/boards/renesas/rssk_ra2l1/doc/index.rst @@ -0,0 +1,142 @@ +.. zephyr:board:: rssk_ra2l1 + +Overview +******** + +The RA2L1 MCU Group Capacitive Touch Evaluation System (RTK0EG0022S01001BJ) is a +kit created for evaluating the RA2L1 MCU Group Capacitive Touch Sensing Unit (CTSU). + +RTK0EG0022S01001BJ is composed of two boards: The RA2L1 Cap Touch CPU Board is mounted with an +RA2L1 MCU which includes an on-chip CTSU. The Capacitive Touch Application Board Capacitive Touch +Application Board is equipped with self-capacitance touch buttons, wheel and slider electrodes, and LEDs +touch electrodes. + +Renesas RA2L1 Microcontroller Group has following features + +- 48MHz, Arm Cortex-M23 core +- 256kB or 128kB Code Flash, 8kB Data Flash, 32kB SRAM (divided on 2 equal areas + with- and without- ECC support) +- SCI x 5 +- SPI x 2 +- I2C x 2 +- CAN x 1 +- 12-bit A/D Converter +- 12-bit D/A Converter +- Low-Power Analog Comparator x 2 +- Temperature Sensor +- General PWM Timer 32-bit x 4 +- General PWM Timer 16-bit x 6 +- Low Power Asynchronous General-Purpose Timer x 2 +- Watchdog Timer (WDT) +- Independent Watchdog Timer (IWDT) +- Up to 85 Input/Output pins (depends on the package type) + +Hardware +******** + +The main functions of the RA2L1 Cap Touch CPU board are as follows: + +- Renesas RA2L1 MCU Group + + - R7FA2L1AB2DFP + - 100-pin LFQFP package + - 48MHz Arm Cortex®-M23 Core with built-in Arm® MPU (Armv8-M architecture) + - 32KB SRAM + - 256KB code flash memory + - 8KB data flash memory + - 32-channel capacitive touch sensing unit (CTSU) pins + +- Connectivity + + - USB serial conversion interface (FT234XD manufactured by FTDI) + - 10-pin JTAG/SWD interface for connecting external debugger or programmer (option) + - Application board GPIO interface: 2.54mm pitch, 16 pins (8 x 2 DIL) + - Application board CTSU interface: 2.54mm pitch, 40 pins (20 x 2 DIL) + +- Other functions + + - MCU current measurement jumper + - User push button switches: 2 + - User LEDs: 2 + +.. figure:: rtk0eg0018c01001bj.webp + :width: 300 + :align: center + + RA2L1 Cap Touch CPU Board (Credit: Renesas Electronics Corporation) + +Key functions of the Capacitive Touch Application Board are as follows: + +- Self-capacitance detection touch electrodes + + - Buttons: 3 + - Wheel (4-electrode configuration): 1 + - Slider (5-electrode configuration): 1 + +- LEDs: 16 + +Supported Features +================== + +.. zephyr:board-supported-hw:: + +Programming and debugging +************************* + +Building & Flashing +=================== + +You can build and flash an application with an external J-Link debug adapter connect to +J1 connector. +:ref:`build_an_application` and +:ref:`application_run` for more details. + +Here is an example for building and flashing the :zephyr:code-sample:`blinky` application. + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/blinky + :board: rssk_ra2l1 + :goals: build flash + + +Debugging +========= + +Debugging also can be done with an external J-Link debug adapter connected to +J1 connector. +For the debug log output through UART console, you need to connect a USB cable +from the host PC to the USB Serial Conversion on CN5. +The following command is debugging the :zephyr:code-sample:`blinky` application. +Also, see the instructions specific to the debug server that you use. + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/blinky + :board: rssk_ra2l1 + :maybe-skip-config: + :goals: debug + +Or you can use Segger Ozone (`Segger Ozone Download`_) for a visual debug interface + +Once downloaded and installed, open Segger Ozone and configure the debug project +like so: + +* Target Device: R7FA2L1AB +* Target Interface: SWD +* Target Interface Speed: 4 MHz +* Host Interface: USB +* Program File: + + +References +********** +- `RSSK-RA2L1 Web site`_ +- `RA2L1 MCU Group Website`_ + +.. _RSSK-RA2L1 Web site: + https://www.renesas.com/en/products/microcontrollers-microprocessors/ra-cortex-m-mcus/rtk0eg0022s01001bj-capacitive-touch-evaluation-system-ra2l1 + +.. _RA2L1 MCU Group Website: + https://www.renesas.com/en/products/microcontrollers-microprocessors/ra-cortex-m-mcus/ra2l1-48mhz-arm-cortex-m23-ultra-low-power-general-purpose-microcontroller + +.. _Segger Ozone Download: + https://www.segger.com/downloads/jlink#Ozone diff --git a/boards/renesas/rssk_ra2l1/doc/rssk_ra2l1.webp b/boards/renesas/rssk_ra2l1/doc/rssk_ra2l1.webp new file mode 100644 index 000000000000..2951997525cd Binary files /dev/null and b/boards/renesas/rssk_ra2l1/doc/rssk_ra2l1.webp differ diff --git a/boards/renesas/rssk_ra2l1/doc/rtk0eg0018c01001bj.webp b/boards/renesas/rssk_ra2l1/doc/rtk0eg0018c01001bj.webp new file mode 100644 index 000000000000..044a84827475 Binary files /dev/null and b/boards/renesas/rssk_ra2l1/doc/rtk0eg0018c01001bj.webp differ diff --git a/boards/renesas/rssk_ra2l1/doc/rtk0eg0019b01002bj.webp b/boards/renesas/rssk_ra2l1/doc/rtk0eg0019b01002bj.webp new file mode 100644 index 000000000000..94cec21b4496 Binary files /dev/null and b/boards/renesas/rssk_ra2l1/doc/rtk0eg0019b01002bj.webp differ diff --git a/boards/renesas/rssk_ra2l1/rssk_ra2l1-pinctrl.dtsi b/boards/renesas/rssk_ra2l1/rssk_ra2l1-pinctrl.dtsi new file mode 100644 index 000000000000..2602d22f2f70 --- /dev/null +++ b/boards/renesas/rssk_ra2l1/rssk_ra2l1-pinctrl.dtsi @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&pinctrl { + sci9_default: sci9_default { + group1 { + /* TXD RXD */ + psels = , + ; + }; + }; + + ctsu_default: ctsu_default { + group1 { + psels = , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + }; + }; +}; diff --git a/boards/renesas/rssk_ra2l1/rssk_ra2l1.dts b/boards/renesas/rssk_ra2l1/rssk_ra2l1.dts new file mode 100644 index 000000000000..8baf7c2704d8 --- /dev/null +++ b/boards/renesas/rssk_ra2l1/rssk_ra2l1.dts @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; + +#include +#include +#include + +#include +#include +#include "rssk_ra2l1-pinctrl.dtsi" + +/ { + model = "Renesas RSSK-RA2L1"; + compatible = "renesas,r7fa2l1abxxfp", "renesas,ra2l1"; + + chosen { + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,console = &uart9; + zephyr,shell-uart = &uart9; + }; + + leds { + compatible = "gpio-leds"; + + led2: led2 { + gpios = <&ioport3 5 GPIO_ACTIVE_HIGH>; + label = "LED2"; + }; + + led3: led3 { + gpios = <&ioport3 4 GPIO_ACTIVE_HIGH>; + label = "LED3"; + }; + }; + + buttons { + compatible = "gpio-keys"; + + button0: s2 { + gpios = <&ioport2 6 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button switch 2"; + zephyr,code = ; + }; + + button1: s3 { + gpios = <&ioport2 5 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button switch 3"; + zephyr,code = ; + }; + }; + + aliases { + led0 = &led2; + led1 = &led3; + sw0 = &button0; + sw1 = &button1; + watchdog0 = &wdt; + }; + + rtk0eg0019b01002bj_cn1: rtk0eg0019b01002bj-cn1 { + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <4 0 &ioport5 4 0>, /* LED_COL0 */ + <5 0 &ioport4 0 0>, /* LED_COL1 */ + <6 0 &ioport7 14 0>, /* LED_COL2 */ + <7 0 &ioport4 6 0>, /* LED_COL3 */ + <11 0 &ioport7 8 0>, /* LED_ROW2 */ + <12 0 &ioport4 15 0>, /* LED_ROW3 */ + <13 0 &ioport4 14 0>, /* LED_ROW0 */ + <14 0 &ioport0 6 0>; /* LED_ROW1 */ + }; +}; + +&ioport0 { + status = "okay"; +}; + +&ioport1 { + status = "okay"; +}; + +&ioport2 { + status = "okay"; +}; + +&ioport3 { + status = "okay"; +}; + +&ioport4 { + status = "okay"; +}; + +&ioport5 { + status = "okay"; +}; + +&ioport7 { + status = "okay"; +}; + +&port_irq0 { + interrupts = <8 3>; + status = "okay"; +}; + +&port_irq1 { + interrupts = <9 3>; + status = "okay"; +}; + +&sci9 { + pinctrl-0 = <&sci9_default>; + pinctrl-names = "default"; + interrupts = <0 3>, <1 3>, <2 3>, <3 3>; + interrupt-names = "rxi", "txi", "tei", "eri"; + status = "okay"; + + uart9: uart { + current-speed = <115200>; + status = "okay"; + }; +}; + +&wdt { + status = "okay"; +}; + +&ctsu { + pinctrl-0 = <&ctsu_default>; + pinctrl-names = "default"; + interrupts = <5 3>, <6 3>, <7 3>; + interrupt-names = "ctsuwr", "ctsurd", "ctsufn"; + tscap-gpios = <&ioport1 12 0>; +}; + +rtk0eg0019b01002bj_ctsu: &ctsu {}; diff --git a/boards/renesas/rssk_ra2l1/rssk_ra2l1.yaml b/boards/renesas/rssk_ra2l1/rssk_ra2l1.yaml new file mode 100644 index 000000000000..829546610065 --- /dev/null +++ b/boards/renesas/rssk_ra2l1/rssk_ra2l1.yaml @@ -0,0 +1,16 @@ +identifier: rssk_ra2l1 +name: Renesas RSSK-RA2L1 +type: mcu +arch: arm +ram: 32 +flash: 256 +toolchain: + - zephyr + - gnuarmemb +supported: + - watchdog +vendor: renesas +testing: + ignore_tags: + - net + - bluetooth diff --git a/boards/renesas/rssk_ra2l1/rssk_ra2l1_defconfig b/boards/renesas/rssk_ra2l1/rssk_ra2l1_defconfig new file mode 100644 index 000000000000..f26066de3e52 --- /dev/null +++ b/boards/renesas/rssk_ra2l1/rssk_ra2l1_defconfig @@ -0,0 +1,11 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +# Enable GPIO +CONFIG_GPIO=y + +# Enable Console +CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_UART_CONSOLE=y +CONFIG_CONSOLE=y diff --git a/boards/shields/rtk0eg0019b01002bj/Kconfig.defconfig b/boards/shields/rtk0eg0019b01002bj/Kconfig.defconfig new file mode 100644 index 000000000000..2da067cd79a9 --- /dev/null +++ b/boards/shields/rtk0eg0019b01002bj/Kconfig.defconfig @@ -0,0 +1,10 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +if INPUT_RENESAS_RA_CTSU + +config INPUT_RENESAS_RA_CTSU_NUM_SELF_ELEMENTS + default 12 + depends on !INPUT_RENESAS_RA_QE_TOUCH_CFG + +endif # INPUT_RENESAS_RA_CTSU diff --git a/boards/shields/rtk0eg0019b01002bj/Kconfig.shield b/boards/shields/rtk0eg0019b01002bj/Kconfig.shield new file mode 100644 index 000000000000..7d5e30c1e424 --- /dev/null +++ b/boards/shields/rtk0eg0019b01002bj/Kconfig.shield @@ -0,0 +1,5 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +config SHIELD_RTK0EG0019B01002BJ + def_bool $(shields_list_contains,rtk0eg0019b01002bj) diff --git a/boards/shields/rtk0eg0019b01002bj/boards/rssk_ra2l1.conf b/boards/shields/rtk0eg0019b01002bj/boards/rssk_ra2l1.conf new file mode 100644 index 000000000000..e4cd90fa23eb --- /dev/null +++ b/boards/shields/rtk0eg0019b01002bj/boards/rssk_ra2l1.conf @@ -0,0 +1,4 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_INPUT_RENESAS_RA_DEVICE_VCC=5000 diff --git a/boards/shields/rtk0eg0019b01002bj/boards/rssk_ra2l1.overlay b/boards/shields/rtk0eg0019b01002bj/boards/rssk_ra2l1.overlay new file mode 100644 index 000000000000..f33505d135e1 --- /dev/null +++ b/boards/shields/rtk0eg0019b01002bj/boards/rssk_ra2l1.overlay @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&rtk0eg0019b01002bj_ctsu { + clock-div = <1>; + pwr-supply-sel = "internal-power"; + pwr-supply-sel2 = "pwr-supply-sel"; + atune1 = "normal"; + atune12 = <40>; + measure-mode = "self-multi-scan"; + po-sel = "same-pulse"; + status = "okay"; + + group1 { + ssdiv = "4.00", "4.00", "4.00"; + so = <0x03B>, <0x059>, <0x049>; + snum = <0x07>, <0x07>, <0x07>; + sdpa = <0x0F>, <0x0F>, <0x0F>; + num-moving-avg = <4>; + on-freq = <3>; + off-freq = <3>; + drift-freq = <255>; + cancel-freq = <0>; + status = "okay"; + + button1 { + threshold = <769>; + hysteresis = <38>; + status = "okay"; + }; + + button2 { + threshold = <740>; + hysteresis = <37>; + status = "okay"; + }; + + button3 { + threshold = <784>; + hysteresis = <39>; + status = "okay"; + }; + }; + + group2 { + ssdiv = "4.00", "4.00", "4.00", "4.00", "4.00"; + so = <0x02B>, <0x03B>, <0x036>, <0x03B>, <0x03A>; + snum = <0x07>, <0x07>, <0x07>, <0x07>, <0x07>; + sdpa = <0x0F>, <0x0F>, <0x0F>, <0x0F>, <0x0F>; + num-moving-avg = <4>; + on-freq = <3>; + off-freq = <3>; + drift-freq = <255>; + cancel-freq = <0>; + status = "okay"; + + slider { + threshold = <573>; + status = "okay"; + }; + }; + + group3 { + ssdiv = "4.00", "4.00", "4.00", "4.00"; + so = <0x047>, <0x046>, <0x049>, <0x040>; + snum = <0x07>, <0x07>, <0x07>, <0x07>; + sdpa = <0x0F>, <0x0F>, <0x0F>, <0x0F>; + num-moving-avg = <4>; + on-freq = <3>; + off-freq = <3>; + drift-freq = <255>; + cancel-freq = <0>; + status = "okay"; + + wheel { + threshold = <711>; + status = "okay"; + }; + }; +}; diff --git a/boards/shields/rtk0eg0019b01002bj/doc/img/rtk0eg0019b01002bj.webp b/boards/shields/rtk0eg0019b01002bj/doc/img/rtk0eg0019b01002bj.webp new file mode 100644 index 000000000000..371248495a84 Binary files /dev/null and b/boards/shields/rtk0eg0019b01002bj/doc/img/rtk0eg0019b01002bj.webp differ diff --git a/boards/shields/rtk0eg0019b01002bj/doc/index.rst b/boards/shields/rtk0eg0019b01002bj/doc/index.rst new file mode 100644 index 000000000000..f9e84c77bfe4 --- /dev/null +++ b/boards/shields/rtk0eg0019b01002bj/doc/index.rst @@ -0,0 +1,110 @@ +.. _rtk0eg0019b01002bj: + +RTK0EG0019B01002BJ Capacitive Touch Application Shield +###################################################### + +Overview +******** + +The RTK0EG0019B01002BJ Capacitive Touch Application Shield is designed to work with the Renesas +Capacitive Touch Evaluation Kit. + +The shield features a variety of touch sensors, including buttons, sliders, and wheels, making it +an ideal platform for developing touch-based applications. + +.. figure:: img/rtk0eg0019b01002bj.webp + :width: 300 + :align: center + + RTK0EG0019B01002BJ Capacitive Touch Application Shield (Credit: Renesas Electronics Corporation) + +Pins Assignment of the RTK0EG0019B01002BJ Shield +================================================ + +Application Header 1 (CN1) +-------------------------- + ++---------+-------------+---------+-------------+ +| CN1 Pin | Function | CN1 Pin | Function | ++=========+=============+=========+=============+ +| 15 | VCC | 16 | GND | ++---------+-------------+---------+-------------+ +| 13 | LED_ROW0 | 14 | LED_ROW1 | ++---------+-------------+---------+-------------+ +| 11 | LED_ROW2 | 12 | LED_ROW3 | ++---------+-------------+---------+-------------+ +| 9 | N/C | 10 | N/C | ++---------+-------------+---------+-------------+ +| 7 | LED_COL3 | 8 | N/C | ++---------+-------------+---------+-------------+ +| 5 | LED_COL1 | 6 | LED_COL2 | ++---------+-------------+---------+-------------+ +| 3 | N/C | 4 | LED_COL0 | ++---------+-------------+---------+-------------+ +| 1 | N/C | 2 | N/C | ++---------+-------------+---------+-------------+ + +Application Header 2 (CN2) +-------------------------- + ++---------+-------------------+---------+-------------------+ +| CN2 Pin | Touch Electrode | CN2 Pin | Touch Electrode | ++=========+===================+=========+===================+ +| 39 | N/C | 40 | TSCAP | ++---------+-------------------+---------+-------------------+ +| 37 | N/C | 38 | N/C | ++---------+-------------------+---------+-------------------+ +| 35 | N/C | 36 | TS-W1 | ++---------+-------------------+---------+-------------------+ +| 33 | N/C | 34 | TS-W2 | ++---------+-------------------+---------+-------------------+ +| 31 | TS-W3 | 32 | N/C | ++---------+-------------------+---------+-------------------+ +| 29 | N/C | 30 | N/C | ++---------+-------------------+---------+-------------------+ +| 27 | N/C | 28 | TS-W4 | ++---------+-------------------+---------+-------------------+ +| 25 | N/C | 26 | N/C | ++---------+-------------------+---------+-------------------+ +| 23 | N/C | 24 | N/C | ++---------+-------------------+---------+-------------------+ +| 21 | N/C | 22 | SHIELD-W1 | ++---------+-------------------+---------+-------------------+ +| 19 | N/C | 20 | N/C | ++---------+-------------------+---------+-------------------+ +| 17 | N/C | 18 | N/C | ++---------+-------------------+---------+-------------------+ +| 15 | N/C | 16 | N/C | ++---------+-------------------+---------+-------------------+ +| 13 | N/C | 14 | N/C | ++---------+-------------------+---------+-------------------+ +| 11 | N/C | 12 | N/C | ++---------+-------------------+---------+-------------------+ +| 9 | TS-B1 | 10 | TS-B2 | ++---------+-------------------+---------+-------------------+ +| 7 | SHIELD-B1 | 8 | TS-B3 | ++---------+-------------------+---------+-------------------+ +| 5 | TS-S1 | 6 | SHIELD-S1 | ++---------+-------------------+---------+-------------------+ +| 3 | TS-S3 | 4 | TS-S2 | ++---------+-------------------+---------+-------------------+ +| 1 | TS-S5 | 2 | TS-S4 | ++---------+-------------------+---------+-------------------+ + +Programming +*********** + +Set ``--shield rtk0eg0019b01002bj`` when you invoke ``west build``. For example: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/input/input_dump + :board: rssk_ra2l1 + :shield: rtk0eg0019b01002bj + :goals: build + +References +********** +- `Capacitive Touch Evaluation System for RA2L1`_ + +.. _Capacitive Touch Evaluation System for RA2L1: + https://www.renesas.com/en/products/microcontrollers-microprocessors/ra-cortex-m-mcus/rtk0eg0022s01001bj-capacitive-touch-evaluation-system-ra2l1 diff --git a/boards/shields/rtk0eg0019b01002bj/dts/bindings/rtk0eg0019b01002bj-led-matrix.yaml b/boards/shields/rtk0eg0019b01002bj/dts/bindings/rtk0eg0019b01002bj-led-matrix.yaml new file mode 100644 index 000000000000..8006c8ea172f --- /dev/null +++ b/boards/shields/rtk0eg0019b01002bj/dts/bindings/rtk0eg0019b01002bj-led-matrix.yaml @@ -0,0 +1,35 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +description: | + This binding provides resources required for the LED matrix + on the RTK0EG0019B01002BJ board. + +compatible: "rtk0eg0019b01002bj-led-matrix" + +properties: + led-row-gpios: + type: phandle-array + required: true + description: | + Identity of GPIOs that will be used to control the LED matrix. + Each entry in the array corresponds to a row of the matrix. + + led-col-gpios: + type: phandle-array + required: true + description: | + Identity of GPIOs that will be used to control the LED matrix. + Each entry in the array corresponds to a column of the matrix. + + num-rows: + type: int + required: true + description: | + Number of rows in the LED matrix. + + num-cols: + type: int + required: true + description: | + Number of columns in the LED matrix. diff --git a/boards/shields/rtk0eg0019b01002bj/rtk0eg0019b01002bj.overlay b/boards/shields/rtk0eg0019b01002bj/rtk0eg0019b01002bj.overlay new file mode 100644 index 000000000000..8a4d33ae80d9 --- /dev/null +++ b/boards/shields/rtk0eg0019b01002bj/rtk0eg0019b01002bj.overlay @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/ { + rtk0eg0019b01002bj_cn1: rtk0eg0019b01002bj-cn1 { + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + }; + + rtk0eg0019b01002bj_led_matrix: rtk0eg0019b01002bj-led-matrix { + compatible = "rtk0eg0019b01002bj-led-matrix"; + led-row-gpios = <&rtk0eg0019b01002bj_cn1 13 GPIO_ACTIVE_LOW>, + <&rtk0eg0019b01002bj_cn1 14 GPIO_ACTIVE_LOW>, + <&rtk0eg0019b01002bj_cn1 11 GPIO_ACTIVE_LOW>, + <&rtk0eg0019b01002bj_cn1 12 GPIO_ACTIVE_LOW>; + led-col-gpios = <&rtk0eg0019b01002bj_cn1 4 GPIO_ACTIVE_HIGH>, + <&rtk0eg0019b01002bj_cn1 5 GPIO_ACTIVE_HIGH>, + <&rtk0eg0019b01002bj_cn1 6 GPIO_ACTIVE_HIGH>, + <&rtk0eg0019b01002bj_cn1 7 GPIO_ACTIVE_HIGH>; + num-rows = <4>; + num-cols = <4>; + status = "okay"; + }; +}; + +&rtk0eg0019b01002bj_ctsu { + status = "okay"; + + group1 { + ctsuchac = <0x01 0x0E 0x00 0x00 0x00>; + ctsuchtrc = <0x01 0x00 0x00 0x00 0x00>; + rx-count = <3>; + tx-count = <0>; + status = "okay"; + + rtk0eg0019b01002bj_bt1: button1 { + compatible = "renesas,ra-ctsu-button"; + elements = <2>; + event-code = ; + status = "okay"; + }; + + rtk0eg0019b01002bj_bt2: button2 { + compatible = "renesas,ra-ctsu-button"; + elements = <1>; + event-code = ; + status = "okay"; + }; + + rtk0eg0019b01002bj_bt3: button3 { + compatible = "renesas,ra-ctsu-button"; + elements = <0>; + event-code = ; + status = "okay"; + }; + }; + + group2 { + ctsuchac = <0xF4 0x01 0x00 0x00 0x00>; + ctsuchtrc = <0x00 0x01 0x00 0x00 0x00>; + rx-count = <5>; + tx-count = <0>; + status = "okay"; + + rtk0eg0019b01002bj_slider: slider { + compatible = "renesas,ra-ctsu-slider"; + elements = <1>, <0>, <2>, <4>, <3>; + threshold = <703>; + event-code = ; + status = "okay"; + }; + }; + + group3 { + ctsuchac = <0x00 0x40 0xA4 0x00 0x01>; + ctsuchtrc = <0x00 0x40 0x00 0x00 0x00>; + rx-count = <4>; + tx-count = <0>; + status = "okay"; + + rtk0eg0019b01002bj_wheel: wheel { + compatible = "renesas,ra-ctsu-wheel"; + elements = <0>, <1>, <2>, <3>; + event-code = ; + status = "okay"; + }; + }; +}; diff --git a/boards/shields/rtk0eg0019b01002bj/shield.yml b/boards/shields/rtk0eg0019b01002bj/shield.yml new file mode 100644 index 000000000000..fe1b02b9ed3a --- /dev/null +++ b/boards/shields/rtk0eg0019b01002bj/shield.yml @@ -0,0 +1,7 @@ +shield: + name: rtk0eg0019b01002bj + full_name: RTK0EG0019B01002BJ Capacitive Touch Application Shield + vendor: renesas + supported_features: + - input + - gpio diff --git a/drivers/input/CMakeLists.txt b/drivers/input/CMakeLists.txt index 054c04ff60cd..832d08465555 100644 --- a/drivers/input/CMakeLists.txt +++ b/drivers/input/CMakeLists.txt @@ -31,6 +31,7 @@ zephyr_library_sources_ifdef(CONFIG_INPUT_PAW32XX input_paw32xx.c) zephyr_library_sources_ifdef(CONFIG_INPUT_PINNACLE input_pinnacle.c) zephyr_library_sources_ifdef(CONFIG_INPUT_PMW3610 input_pmw3610.c) zephyr_library_sources_ifdef(CONFIG_INPUT_REALTEK_RTS5912_KBD input_realtek_rts5912_kbd.c) +zephyr_library_sources_ifdef(CONFIG_INPUT_RENESAS_RA_CTSU input_renesas_ra_ctsu.c) zephyr_library_sources_ifdef(CONFIG_INPUT_SBUS input_sbus.c) zephyr_library_sources_ifdef(CONFIG_INPUT_STM32_TSC_KEYS input_tsc_keys.c) zephyr_library_sources_ifdef(CONFIG_INPUT_STMPE811 input_stmpe811.c) diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index b8dc0890b567..785f11a76ff2 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -32,6 +32,7 @@ source "drivers/input/Kconfig.pat912x" source "drivers/input/Kconfig.paw32xx" source "drivers/input/Kconfig.pinnacle" source "drivers/input/Kconfig.pmw3610" +source "drivers/input/Kconfig.renesas_ra" source "drivers/input/Kconfig.rts5912" source "drivers/input/Kconfig.sbus" source "drivers/input/Kconfig.sdl" diff --git a/drivers/input/Kconfig.renesas_ra b/drivers/input/Kconfig.renesas_ra new file mode 100644 index 000000000000..f6459fc3db57 --- /dev/null +++ b/drivers/input/Kconfig.renesas_ra @@ -0,0 +1,96 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +config INPUT_RENESAS_RA_CTSU + bool "Renesas RA Capacitive Touch driver" + default y + depends on DT_HAS_RENESAS_RA_CTSU_ENABLED + select USE_RA_FSP_CTSU + select USE_RA_FSP_TOUCH + select SYS_MEM_BLOCKS + select GPIO + select PINCTRL + help + Enable Renesas RA Touch Sensing driver. + +if INPUT_RENESAS_RA_CTSU + +config INPUT_RENESAS_RA_DEVICE_VCC + int "SoC VCC input in minivolt" + default 3300 + help + SoC VCC input in milivolt. + +config INPUT_RENESAS_RA_QE_TOUCH_CFG + bool "Using QE Touch Workflow to config this driver" + help + If this config was enabled, setting for CTSU and Cap + Touch driver will be reflected the setting that generated + from QE Touch Workflow. + Please add the generated C source files into the app CMakeLists + to make the driver can using it. + +if !INPUT_RENESAS_RA_QE_TOUCH_CFG + +config INPUT_RENESAS_RA_CTSU_NUM_SELF_ELEMENTS + int "Number of self-capacitance elements" + default 0 + help + Number of self-capacitance elements in the CTSU. + +config INPUT_RENESAS_RA_CTSU_NUM_MUTUAL_ELEMENTS + int "Number of mutual-capacitance elements" + default 0 + help + Number of mutual-capacitance elements in the CTSU. + +choice INPUT_RENESAS_RA_CTSU_CHATTERING_SUPPRESSION_TYPE + prompt "Type of chattering suppression" + default INPUT_RENESAS_RA_CTSU_CHATTERING_SUPPRESSION_TYPE_A + +config INPUT_RENESAS_RA_CTSU_CHATTERING_SUPPRESSION_TYPE_A + bool "Counter of exceed threshold is hold within hysteresis range" + help + Counter of exceed threshold is hold within hysteresis range. + +config INPUT_RENESAS_RA_CTSU_CHATTERING_SUPPRESSION_TYPE_B + bool "Counter of exceed threshold is reset within hysteresis range" + help + Counter of exceed threshold is reset within hysteresis range. + +endchoice # INPUT_RENESAS_RA_CTSU_CHATTERING_SUPPRESSION_TYPE + +endif # !INPUT_RENESAS_RA_QE_TOUCH_CFG + +config INPUT_RENESAS_RA_CTSU_POLLING_INTERVAL_MS + int "CTSU debounce interval time" + range 20 500 + default 100 + help + Debouncing interval time in milliseconds. + +config INPUT_RENESAS_RA_CTSU_STABILIZATION_TIME_US + int "CTSU stabilization time" + default 20 + help + Stabilization time required to wait between 2 scans. + +config INPUT_RENESAS_RA_CTSU_DRV_STACK_SIZE + int "CTSU internal thread stack size" + default 512 + help + CTSU driver internal thread stack size. + +config INPUT_RENESAS_RA_CTSU_DRV_PRIORITY + int "CTSU internal thread priority" + default 8 + help + CTSU driver internal thread priority. + +config INPUT_RENESAS_RA_CTSU_MSG_MEM_BLOCK_SIZE + int "CTSU internal sys_mem_blocks allocator size" + default 10 + help + CTSU driver internal sys_mem_blocks allocator maximum num blocks. + +endif # INPUT_RENESAS_RA_CTSU diff --git a/drivers/input/input_renesas_ra_ctsu.c b/drivers/input/input_renesas_ra_ctsu.c new file mode 100644 index 000000000000..f6f4ce663491 --- /dev/null +++ b/drivers/input/input_renesas_ra_ctsu.c @@ -0,0 +1,704 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +LOG_MODULE_REGISTER(renesas_ra_touch, CONFIG_INPUT_LOG_LEVEL); + +struct renesas_ra_ctsu_cfg { + const struct gpio_dt_spec tscap_pin; + const struct pinctrl_dev_config *pcfg; + const struct device *clock; + const struct clock_control_ra_subsys_cfg clock_subsys; + void (*irq_config)(void); +}; + +struct renesas_ra_ctsu_data { + struct k_sem scanning; + struct k_queue scan_q; + struct k_thread thread_data; + + K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_INPUT_RENESAS_RA_CTSU_DRV_STACK_SIZE); +}; + +struct renesas_ra_ctsu_group_cfg { + const struct device *ctsu_dev; + size_t num_button; + size_t num_slider; + size_t num_wheel; +}; + +struct renesas_ra_ctsu_device_cb { + const struct device *dev; + void (*device_cb)(const struct device *dev, void *data); +}; + +struct renesas_ra_ctsu_group_data { + const struct device *dev; + /* FSP Touch data */ + struct st_touch_instance touch_instance; +#ifndef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG + struct st_touch_instance_ctrl touch_ctrl; + struct st_touch_cfg touch_cfg; + /* FSP CTSU data */ + struct st_ctsu_instance ctsu_instance; + struct st_ctsu_instance_ctrl ctsu_ctrl; + struct st_ctsu_cfg ctsu_cfg; +#endif /* CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG */ + /* Touch driver private data */ + struct k_work reading_work; + struct k_timer sampling_timer; + /* Touch driver sample result */ + uint64_t *p_button_status; + uint16_t *p_slider_position; + uint16_t *p_wheel_position; + /* Touch device callback data */ + struct renesas_ra_ctsu_device_cb *p_button_cb; + struct renesas_ra_ctsu_device_cb *p_slider_cb; + struct renesas_ra_ctsu_device_cb *p_wheel_cb; +}; + +extern void ctsu_write_isr(void); +extern void ctsu_read_isr(void); +extern void ctsu_end_isr(void); + +struct ctsu_device_cfg { + const struct device *group_dev; + uint16_t event_code; +}; + +struct ctsu_scan_msg { + void *reserved; /* first word of queue data item reserved for the kernel */ + struct st_touch_instance *p_instance; +}; + +SYS_MEM_BLOCKS_DEFINE_STATIC(scan_msg_allocator, sizeof(struct ctsu_scan_msg), + CONFIG_INPUT_RENESAS_RA_CTSU_MSG_MEM_BLOCK_SIZE, sizeof(uint32_t)); + +static void renesas_ra_callback_adapter(touch_callback_args_t *p_args) +{ + const struct device *dev = p_args->p_context; + const struct renesas_ra_ctsu_group_cfg *cfg = dev->config; + const struct device *ctsu_dev = cfg->ctsu_dev; + struct renesas_ra_ctsu_data *ctsu_data = ctsu_dev->data; + struct renesas_ra_ctsu_group_data *data = dev->data; + + if (p_args->event == CTSU_EVENT_SCAN_COMPLETE) { + k_work_submit(&data->reading_work); + } + + k_sem_give(&ctsu_data->scanning); +} + +#define POLLING_INTERVAL_MS K_MSEC(CONFIG_INPUT_RENESAS_RA_CTSU_POLLING_INTERVAL_MS) +#define STABILIZATION_MS K_USEC(CONFIG_INPUT_RENESAS_RA_CTSU_STABILIZATION_TIME_US) + +static void renesas_ra_ctsu_drv_handler(void *arg0, void *arg1, void *arg2) +{ + ARG_UNUSED(arg1); + ARG_UNUSED(arg2); + const struct device *ctsu_dev = (const struct device *)arg0; + struct renesas_ra_ctsu_data *ctsu_data = ctsu_dev->data; + + while (true) { + struct ctsu_scan_msg *msg = k_queue_get(&ctsu_data->scan_q, K_FOREVER); + struct st_touch_instance *p_instance = msg->p_instance; + fsp_err_t err; + + k_sem_reset(&ctsu_data->scanning); + err = p_instance->p_api->scanStart(p_instance->p_ctrl); + if (err == FSP_SUCCESS) { + k_sem_take(&ctsu_data->scanning, K_FOREVER); + } + + sys_mem_blocks_free(&scan_msg_allocator, 1, (void **)&msg); + + k_sleep(STABILIZATION_MS); + } +} + +static void renesas_ra_ctsu_group_sampling_handler(struct k_timer *timer) +{ + struct renesas_ra_ctsu_group_data *data = + CONTAINER_OF(timer, struct renesas_ra_ctsu_group_data, sampling_timer); + const struct device *ctsu_dev = k_timer_user_data_get(timer); + struct renesas_ra_ctsu_data *ctsu_data = ctsu_dev->data; + struct ctsu_scan_msg *msg; + + if (sys_mem_blocks_alloc(&scan_msg_allocator, 1, (void **)&msg) != 0) { + return; + } + + msg->p_instance = (void *)&data->touch_instance; + k_queue_append(&ctsu_data->scan_q, msg); +} + +#if DT_HAS_COMPAT_STATUS_OKAY(renesas_ra_ctsu_button) +static void renesas_ra_ctsu_group_buttons_read(const struct device *dev) +{ + const struct renesas_ra_ctsu_group_cfg *cfg = dev->config; + struct renesas_ra_ctsu_group_data *data = dev->data; + + if (cfg->num_button == 0) { + return; + } + + if (*data->p_button_status != 0) { + uint64_t tmp_status = *data->p_button_status; + + while (tmp_status != 0) { + int num = u64_count_trailing_zeros(tmp_status); + struct renesas_ra_ctsu_device_cb *p_button_cb = &data->p_button_cb[num]; + + p_button_cb->device_cb(p_button_cb->dev, NULL); + WRITE_BIT(tmp_status, num, 0); + } + } +} +#endif /* DT_HAS_COMPAT_STATUS_OKAY(renesas_ra_ctsu_button) */ + +#if DT_HAS_COMPAT_STATUS_OKAY(renesas_ra_ctsu_slider) +static void renesas_ra_ctsu_group_sliders_read(const struct device *dev) +{ + const struct renesas_ra_ctsu_group_cfg *cfg = dev->config; + struct renesas_ra_ctsu_group_data *data = dev->data; + + if (cfg->num_slider == 0) { + return; + } + + for (int i = 0; i < cfg->num_slider; i++) { + uint16_t slider_position = data->p_slider_position[i]; + + if (slider_position != UINT16_MAX) { + struct renesas_ra_ctsu_device_cb *p_slider_cb = &data->p_slider_cb[i]; + + p_slider_cb->device_cb(p_slider_cb->dev, &slider_position); + } + } +} +#endif /* DT_HAS_COMPAT_STATUS_OKAY(renesas_ra_ctsu_slider) */ + +#if DT_HAS_COMPAT_STATUS_OKAY(renesas_ra_ctsu_wheel) +static void renesas_ra_ctsu_group_wheels_read(const struct device *dev) +{ + const struct renesas_ra_ctsu_group_cfg *cfg = dev->config; + struct renesas_ra_ctsu_group_data *data = dev->data; + + if (cfg->num_wheel == 0) { + return; + } + + for (int i = 0; i < cfg->num_wheel; i++) { + uint16_t wheel_position = data->p_wheel_position[i]; + + if (wheel_position != UINT16_MAX) { + struct renesas_ra_ctsu_device_cb *p_wheel_cb = &data->p_wheel_cb[i]; + + p_wheel_cb->device_cb(p_wheel_cb->dev, &wheel_position); + } + } +} +#endif /* DT_HAS_COMPAT_STATUS_OKAY(renesas_ra_ctsu_wheel) */ + +static void renesas_ra_ctsu_group_reading_handler(struct k_work *work) +{ + struct renesas_ra_ctsu_group_data *data = + CONTAINER_OF(work, struct renesas_ra_ctsu_group_data, reading_work); + const struct device *dev = data->dev; + const struct st_touch_instance *p_instance = &data->touch_instance; + fsp_err_t err; + + err = p_instance->p_api->dataGet(p_instance->p_ctrl, data->p_button_status, + data->p_slider_position, data->p_wheel_position); + if (err != FSP_SUCCESS) { + return; + } + + IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(renesas_ra_ctsu_button), + (renesas_ra_ctsu_group_buttons_read(dev);)) + + IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(renesas_ra_ctsu_slider), + (renesas_ra_ctsu_group_sliders_read(dev);)) + + IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(renesas_ra_ctsu_wheel), + (renesas_ra_ctsu_group_wheels_read(dev);)) +} + +static int input_renesas_ra_ctsu_group_configure(const struct device *dev, + const struct renesas_ra_ctsu_touch_cfg *cfg) +{ + const struct st_touch_instance *p_instance = &cfg->touch_instance; + const struct renesas_ra_ctsu_group_cfg *config = dev->config; + struct renesas_ra_ctsu_group_data *data = dev->data; + fsp_err_t err; + + err = p_instance->p_api->open(p_instance->p_ctrl, p_instance->p_cfg); + if (err != FSP_SUCCESS) { + return -EIO; + } + + err = p_instance->p_api->callbackSet(p_instance->p_ctrl, renesas_ra_callback_adapter, + (void *)dev, NULL); + if (err != FSP_SUCCESS) { + p_instance->p_api->close(p_instance->p_ctrl); + return -EIO; + } + +#ifdef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG + data->touch_instance = *p_instance; +#endif /* CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG */ + + k_work_init(&data->reading_work, renesas_ra_ctsu_group_reading_handler); + k_timer_init(&data->sampling_timer, renesas_ra_ctsu_group_sampling_handler, NULL); + k_timer_user_data_set(&data->sampling_timer, (void *)config->ctsu_dev); + k_timer_start(&data->sampling_timer, POLLING_INTERVAL_MS, POLLING_INTERVAL_MS); + + return 0; +} + +int z_impl_renesas_ra_ctsu_group_configure(const struct device *dev, + const struct renesas_ra_ctsu_touch_cfg *cfg) +{ +#ifndef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG + ARG_UNUSED(dev); + ARG_UNUSED(cfg); + return -ENOSYS; +#else + return input_renesas_ra_ctsu_group_configure(dev, cfg); +#endif /* CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG */ +} + +static int renesas_ra_ctsu_group_init(const struct device *dev) +{ + const struct renesas_ra_ctsu_group_cfg *cfg = dev->config; +#ifndef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG + struct renesas_ra_ctsu_group_data *data = dev->data; + const struct renesas_ra_ctsu_touch_cfg *touch_cfg = + (const struct renesas_ra_ctsu_touch_cfg *)&data->touch_instance; +#endif /* CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG */ + + if (!device_is_ready(cfg->ctsu_dev)) { + return -ENODEV; + } + +#ifndef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG + return input_renesas_ra_ctsu_group_configure(dev, touch_cfg); +#else + return 0; +#endif /* CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG */ +} + +static void renesas_ra_ctsu_write_isr(void *arg) +{ + ARG_UNUSED(arg); + ctsu_write_isr(); +} + +static void renesas_ra_ctsu_read_isr(void *arg) +{ + ARG_UNUSED(arg); + ctsu_read_isr(); +} + +static void renesas_ra_ctsu_end_isr(void *arg) +{ + ARG_UNUSED(arg); + ctsu_end_isr(); +} + +__maybe_unused static void ctsu_renesas_ra_button_cb(const struct device *dev, void *data) +{ + ARG_UNUSED(data); + const struct ctsu_device_cfg *cfg = dev->config; + + input_report_key(dev, cfg->event_code, 0, false, K_NO_WAIT); +} + +__maybe_unused static void ctsu_renesas_ra_slider_cb(const struct device *dev, void *data) +{ + const struct ctsu_device_cfg *cfg = dev->config; + uint16_t *p_data = data; + + if (p_data == NULL) { + return; + } + + input_report_abs(dev, cfg->event_code, *p_data, false, K_NO_WAIT); +} + +#define ctsu_renesas_ra_wheel_cb ctsu_renesas_ra_slider_cb + +#define FOREACH_CHILD_CB(node_id, fn, compat) \ + IF_ENABLED(DT_NODE_HAS_COMPAT(node_id, compat), (fn(node_id))) + +#define FOREACH_CHILD(node_id, fn, compat) \ + DT_FOREACH_CHILD_STATUS_OKAY_VARGS(node_id, FOREACH_CHILD_CB, fn, compat) + +/* CTSU instance define */ +#define DT_DRV_COMPAT renesas_ra_ctsu + +/* CTSU group instance define */ +#define CTSU_ELEMENT_CFG_GET_BY_IDX(idx, id) \ + { \ + .ssdiv = DT_ENUM_IDX_BY_IDX(id, ssdiv, idx), \ + .so = DT_PROP_BY_IDX(id, so, idx), \ + .snum = DT_PROP_BY_IDX(id, snum, idx), \ + .sdpa = DT_PROP_BY_IDX(id, sdpa, idx), \ + } + +#define RENESAS_RA_CTSU_ELEM_GET(idx, node_id) DT_PROP_BY_IDX(node_id, elements, idx) + +#define CTSU_ELEM_IDX_DEFINE(node_id) \ + static uint8_t CONCAT(DT_NODE_FULL_NAME_TOKEN(node_id), _elem_index)[] = { \ + LISTIFY(DT_PROP_LEN(node_id, elements), RENESAS_RA_CTSU_ELEM_GET, (,), node_id)}; + +#define CTSU_DEVICE_BUTTON_CALLBACK_DEFINE(node_id) \ + { \ + .dev = DEVICE_DT_GET(node_id), \ + .device_cb = ctsu_renesas_ra_button_cb, \ + }, + +#define CTSU_DEVICE_SLIDER_CALLBACK_DEFINE(node_id) \ + { \ + .dev = DEVICE_DT_GET(node_id), \ + .device_cb = ctsu_renesas_ra_slider_cb, \ + }, + +#define CTSU_DEVICE_WHEEL_CALLBACK_DEFINE(node_id) \ + { \ + .dev = DEVICE_DT_GET(node_id), \ + .device_cb = ctsu_renesas_ra_wheel_cb, \ + }, + +#define CTSU_BUTTON_DT_SPEC_GET(node_id) \ + { \ + .elem_index = DT_PROP(node_id, elements), \ + .threshold = DT_PROP(node_id, threshold), \ + .hysteresis = DT_PROP(node_id, hysteresis), \ + }, + +#define CTSU_SLIDER_DT_SPEC_GET(node_id) \ + { \ + .p_elem_index = CONCAT(DT_NODE_FULL_NAME_TOKEN(node_id), _elem_index), \ + .num_elements = ARRAY_SIZE(CONCAT(DT_NODE_FULL_NAME_TOKEN(node_id), _elem_index)), \ + .threshold = DT_PROP(node_id, threshold), \ + }, + +#define CTSU_WHEEL_DT_SPEC_GET(node_id) CTSU_SLIDER_DT_SPEC_GET(node_id) + +#define CTSU_GROUP_VAR_NAME(node_id, surfix) \ + CONCAT(renesas_ra_ctsu_, DT_NODE_FULL_NAME_TOKEN(node_id), surfix) + +#define CTSU_ELEMENTS_DEFINE(node_id) \ + {LISTIFY(DT_PROP_LEN(node_id, ssdiv), CTSU_ELEMENT_CFG_GET_BY_IDX, (,), node_id)} + +#ifndef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG +#define RENESAS_RA_CTSU_GROUP_DEFINE(id) \ + static const ctsu_element_cfg_t CTSU_GROUP_VAR_NAME(id, _elements_cfg)[] = \ + CTSU_ELEMENTS_DEFINE(id); \ + \ + FOREACH_CHILD(id, CTSU_ELEM_IDX_DEFINE, renesas_ra_ctsu_slider); \ + FOREACH_CHILD(id, CTSU_ELEM_IDX_DEFINE, renesas_ra_ctsu_wheel); \ + \ + static touch_button_cfg_t CTSU_GROUP_VAR_NAME(id, _button_cfg)[] = { \ + FOREACH_CHILD(id, CTSU_BUTTON_DT_SPEC_GET, renesas_ra_ctsu_button)}; \ + \ + static touch_slider_cfg_t CTSU_GROUP_VAR_NAME(id, _slider_cfg)[] = { \ + FOREACH_CHILD(id, CTSU_SLIDER_DT_SPEC_GET, renesas_ra_ctsu_slider)}; \ + \ + static touch_wheel_cfg_t CTSU_GROUP_VAR_NAME(id, _wheel_cfg)[] = { \ + FOREACH_CHILD(id, CTSU_WHEEL_DT_SPEC_GET, renesas_ra_ctsu_wheel)}; \ + \ + struct renesas_ra_ctsu_device_cb CTSU_GROUP_VAR_NAME(id, _button_cb)[] = { \ + FOREACH_CHILD(id, CTSU_DEVICE_BUTTON_CALLBACK_DEFINE, renesas_ra_ctsu_button)}; \ + struct renesas_ra_ctsu_device_cb CTSU_GROUP_VAR_NAME(id, _slider_cb)[] = { \ + FOREACH_CHILD(id, CTSU_DEVICE_SLIDER_CALLBACK_DEFINE, renesas_ra_ctsu_slider)}; \ + struct renesas_ra_ctsu_device_cb CTSU_GROUP_VAR_NAME(id, _wheel_cb)[] = { \ + FOREACH_CHILD(id, CTSU_DEVICE_WHEEL_CALLBACK_DEFINE, renesas_ra_ctsu_wheel)}; \ + \ + struct renesas_ra_ctsu_group_cfg CONCAT(renesas_ra_ctsu_, DT_NODE_FULL_NAME_TOKEN(id), \ + _cfg) = { \ + .ctsu_dev = DEVICE_DT_GET(DT_PARENT(id)), \ + .num_button = ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _button_cfg)), \ + .num_slider = ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _slider_cfg)), \ + .num_wheel = ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _wheel_cfg)), \ + }; \ + \ + static uint64_t CTSU_GROUP_VAR_NAME(id, _button_data); \ + static uint16_t CTSU_GROUP_VAR_NAME( \ + id, _slider_data)[ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _slider_cfg))]; \ + static uint16_t CTSU_GROUP_VAR_NAME( \ + id, _wheel_data)[ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _wheel_cfg))]; \ + \ + static struct renesas_ra_ctsu_group_data CTSU_GROUP_VAR_NAME(id, _data) = { \ + .dev = DEVICE_DT_GET(id), \ + .touch_instance = \ + { \ + .p_ctrl = &CTSU_GROUP_VAR_NAME(id, _data).touch_ctrl, \ + .p_cfg = &CTSU_GROUP_VAR_NAME(id, _data).touch_cfg, \ + .p_api = &g_touch_on_ctsu, \ + }, \ + .ctsu_instance = \ + { \ + .p_ctrl = &CTSU_GROUP_VAR_NAME(id, _data).ctsu_ctrl, \ + .p_cfg = &CTSU_GROUP_VAR_NAME(id, _data).ctsu_cfg, \ + .p_api = &g_ctsu_on_ctsu, \ + }, \ + .touch_cfg = \ + { \ + .on_freq = DT_PROP(id, on_freq), \ + .off_freq = DT_PROP(id, off_freq), \ + .drift_freq = DT_PROP(id, drift_freq), \ + .cancel_freq = DT_PROP(id, cancel_freq), \ + .p_ctsu_instance = &CTSU_GROUP_VAR_NAME(id, _data).ctsu_instance, \ + .p_buttons = CTSU_GROUP_VAR_NAME(id, _button_cfg), \ + .p_sliders = CTSU_GROUP_VAR_NAME(id, _slider_cfg), \ + .p_wheels = CTSU_GROUP_VAR_NAME(id, _wheel_cfg), \ + .num_sliders = ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _slider_cfg)), \ + .num_wheels = ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _wheel_cfg)), \ + .num_buttons = ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _button_cfg)), \ + }, \ + .ctsu_cfg = \ + { \ + .cap = CTSU_CAP_SOFTWARE, \ + .txvsel = DT_ENUM_IDX(DT_PARENT(id), pwr_supply_sel), \ + .txvsel2 = DT_ENUM_IDX(DT_PARENT(id), pwr_supply_sel2), \ + .atune1 = DT_ENUM_IDX(DT_PARENT(id), atune1), \ + .atune12 = DT_ENUM_IDX(DT_PARENT(id), atune12), \ + .md = CONCAT(CTSU_MODE_, \ + DT_STRING_UPPER_TOKEN(DT_PARENT(id), measure_mode)), \ + .posel = DT_ENUM_IDX(DT_PARENT(id), po_sel), \ + .ctsuchac0 = DT_PROP_BY_IDX(id, ctsuchac, 0), \ + .ctsuchac1 = DT_PROP_BY_IDX(id, ctsuchac, 1), \ + .ctsuchac2 = DT_PROP_BY_IDX(id, ctsuchac, 2), \ + .ctsuchac3 = DT_PROP_BY_IDX(id, ctsuchac, 3), \ + .ctsuchac4 = DT_PROP_BY_IDX(id, ctsuchac, 4), \ + .ctsuchtrc0 = DT_PROP_BY_IDX(id, ctsuchtrc, 0), \ + .ctsuchtrc1 = DT_PROP_BY_IDX(id, ctsuchtrc, 1), \ + .ctsuchtrc2 = DT_PROP_BY_IDX(id, ctsuchtrc, 2), \ + .ctsuchtrc3 = DT_PROP_BY_IDX(id, ctsuchtrc, 3), \ + .ctsuchtrc4 = DT_PROP_BY_IDX(id, ctsuchtrc, 4), \ + .num_rx = DT_PROP(id, rx_count), \ + .num_tx = DT_PROP(id, tx_count), \ + .num_moving_average = DT_PROP(id, num_moving_avg), \ + .p_elements = CTSU_GROUP_VAR_NAME(id, _elements_cfg), \ + .write_irq = DT_IRQ_BY_NAME(DT_PARENT(id), ctsuwr, irq), \ + .read_irq = DT_IRQ_BY_NAME(DT_PARENT(id), ctsurd, irq), \ + .end_irq = DT_IRQ_BY_NAME(DT_PARENT(id), ctsufn, irq), \ + }, \ + .p_button_status = &CTSU_GROUP_VAR_NAME(id, _button_data), \ + .p_slider_position = CTSU_GROUP_VAR_NAME(id, _slider_data), \ + .p_wheel_position = CTSU_GROUP_VAR_NAME(id, _wheel_data), \ + .p_button_cb = CTSU_GROUP_VAR_NAME(id, _button_cb), \ + .p_slider_cb = CTSU_GROUP_VAR_NAME(id, _slider_cb), \ + .p_wheel_cb = CTSU_GROUP_VAR_NAME(id, _wheel_cb), \ + }; \ + \ + DEVICE_DT_DEFINE(id, renesas_ra_ctsu_group_init, NULL, &CTSU_GROUP_VAR_NAME(id, _data), \ + &CTSU_GROUP_VAR_NAME(id, _cfg), POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \ + NULL); +#else +#define RENESAS_RA_CTSU_GROUP_DEFINE(id) \ + struct renesas_ra_ctsu_device_cb CTSU_GROUP_VAR_NAME(id, _button_cb)[] = { \ + FOREACH_CHILD(id, CTSU_DEVICE_BUTTON_CALLBACK_DEFINE, renesas_ra_ctsu_button)}; \ + struct renesas_ra_ctsu_device_cb CTSU_GROUP_VAR_NAME(id, _slider_cb)[] = { \ + FOREACH_CHILD(id, CTSU_DEVICE_SLIDER_CALLBACK_DEFINE, renesas_ra_ctsu_slider)}; \ + struct renesas_ra_ctsu_device_cb CTSU_GROUP_VAR_NAME(id, _wheel_cb)[] = { \ + FOREACH_CHILD(id, CTSU_DEVICE_WHEEL_CALLBACK_DEFINE, renesas_ra_ctsu_wheel)}; \ + \ + struct renesas_ra_ctsu_group_cfg CTSU_GROUP_VAR_NAME(id, _cfg) = { \ + .ctsu_dev = DEVICE_DT_GET(DT_PARENT(id)), \ + .num_button = ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _button_cb)), \ + .num_slider = ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _slider_cb)), \ + .num_wheel = ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _wheel_cb)), \ + }; \ + \ + static uint64_t CTSU_GROUP_VAR_NAME(id, _button_data); \ + static uint16_t CTSU_GROUP_VAR_NAME( \ + id, _slider_data)[ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _slider_cb))]; \ + static uint16_t CTSU_GROUP_VAR_NAME( \ + id, _wheel_data)[ARRAY_SIZE(CTSU_GROUP_VAR_NAME(id, _wheel_cb))]; \ + \ + static struct renesas_ra_ctsu_group_data CTSU_GROUP_VAR_NAME(id, _data) = { \ + .dev = DEVICE_DT_GET(id), \ + .p_button_status = &CTSU_GROUP_VAR_NAME(id, _button_data), \ + .p_slider_position = CTSU_GROUP_VAR_NAME(id, _slider_data), \ + .p_wheel_position = CTSU_GROUP_VAR_NAME(id, _wheel_data), \ + .p_button_cb = CTSU_GROUP_VAR_NAME(id, _button_cb), \ + .p_slider_cb = CTSU_GROUP_VAR_NAME(id, _slider_cb), \ + .p_wheel_cb = CTSU_GROUP_VAR_NAME(id, _wheel_cb), \ + }; \ + \ + DEVICE_DT_DEFINE(id, renesas_ra_ctsu_group_init, NULL, &CTSU_GROUP_VAR_NAME(id, _data), \ + &CTSU_GROUP_VAR_NAME(id, _cfg), POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \ + NULL); +#endif + +static int renesas_ra_ctsu_init(const struct device *dev) +{ + const struct renesas_ra_ctsu_cfg *ctsu_cfg = dev->config; + struct renesas_ra_ctsu_data *data = dev->data; + k_tid_t tid; + int ret; + + if (!device_is_ready(ctsu_cfg->clock)) { + return -ENODEV; + } + + /* Perform discharge process for the TSCAP pin */ + ret = gpio_pin_configure_dt(&ctsu_cfg->tscap_pin, GPIO_OUTPUT_LOW); + if (ret != 0) { + return ret; + } + + /* Wait 10 usec for discharge to complete before switching to the CTSU pin function */ + k_busy_wait(10); + + ret = pinctrl_apply_state(ctsu_cfg->pcfg, PINCTRL_STATE_DEFAULT); + if (ret != 0) { + return ret; + } + + ret = clock_control_on(ctsu_cfg->clock, (clock_control_subsys_t)&ctsu_cfg->clock_subsys); + if (ret != 0) { + return ret; + } + + k_sem_init(&data->scanning, 0, 1); + k_queue_init(&data->scan_q); + + tid = k_thread_create( + &data->thread_data, data->thread_stack, K_THREAD_STACK_SIZEOF(data->thread_stack), + renesas_ra_ctsu_drv_handler, (void *)dev, NULL, NULL, + K_PRIO_COOP(CONFIG_INPUT_RENESAS_RA_CTSU_DRV_PRIORITY), K_ESSENTIAL, K_NO_WAIT); + if (tid == NULL) { + LOG_ERR("thread creation failed"); + return -ENODEV; + } + + k_thread_name_set(&data->thread_data, dev->name); + + ctsu_cfg->irq_config(); + + return 0; +} + +#define RENESAS_RA_CTSU_DEFINE(inst) \ + PINCTRL_DT_INST_DEFINE(inst); \ + \ + static void renesas_ra_ctsu_irq_config##inst(void) \ + { \ + IRQ_CONNECT(DT_INST_IRQ_BY_NAME(inst, ctsuwr, irq), \ + DT_INST_IRQ_BY_NAME(inst, ctsuwr, priority), \ + renesas_ra_ctsu_write_isr, NULL, 0); \ + IRQ_CONNECT(DT_INST_IRQ_BY_NAME(inst, ctsurd, irq), \ + DT_INST_IRQ_BY_NAME(inst, ctsurd, priority), renesas_ra_ctsu_read_isr, \ + NULL, 0); \ + IRQ_CONNECT(DT_INST_IRQ_BY_NAME(inst, ctsufn, irq), \ + DT_INST_IRQ_BY_NAME(inst, ctsufn, priority), renesas_ra_ctsu_end_isr, \ + NULL, 0); \ + \ + R_ICU->IELSR[DT_INST_IRQ_BY_NAME(inst, ctsuwr, irq)] = \ + BSP_PRV_IELS_ENUM(EVENT_CTSU_WRITE); \ + R_ICU->IELSR[DT_INST_IRQ_BY_NAME(inst, ctsurd, irq)] = \ + BSP_PRV_IELS_ENUM(EVENT_CTSU_READ); \ + R_ICU->IELSR[DT_INST_IRQ_BY_NAME(inst, ctsufn, irq)] = \ + BSP_PRV_IELS_ENUM(EVENT_CTSU_END); \ + \ + irq_enable(DT_INST_IRQ_BY_NAME(inst, ctsuwr, irq)); \ + irq_enable(DT_INST_IRQ_BY_NAME(inst, ctsurd, irq)); \ + irq_enable(DT_INST_IRQ_BY_NAME(inst, ctsufn, irq)); \ + } \ + \ + static const struct renesas_ra_ctsu_cfg renesas_ra_ctsu_cfg##inst = { \ + .tscap_pin = GPIO_DT_SPEC_INST_GET(inst, tscap_gpios), \ + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ + .clock = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(inst)), \ + .clock_subsys = \ + { \ + .mstp = DT_INST_CLOCKS_CELL(inst, mstp), \ + .stop_bit = DT_INST_CLOCKS_CELL(inst, stop_bit), \ + }, \ + .irq_config = renesas_ra_ctsu_irq_config##inst, \ + }; \ + \ + static struct renesas_ra_ctsu_data renesas_ra_ctsu_data##inst; \ + \ + DEVICE_DT_INST_DEFINE(inst, renesas_ra_ctsu_init, NULL, &renesas_ra_ctsu_data##inst, \ + &renesas_ra_ctsu_cfg##inst, POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \ + NULL); \ + \ + DT_INST_FOREACH_CHILD_STATUS_OKAY(inst, RENESAS_RA_CTSU_GROUP_DEFINE) + +DT_INST_FOREACH_STATUS_OKAY(RENESAS_RA_CTSU_DEFINE) + +static int ctsu_device_init(const struct device *dev) +{ + const struct ctsu_device_cfg *cfg = dev->config; + + return device_is_ready(cfg->group_dev) ? 0 : -ENODEV; +} + +#undef DT_DRV_COMPAT +#define DT_DRV_COMPAT renesas_ra_ctsu_button + +#define RENESAS_RA_CTSU_BUTTON_DEFINE(inst) \ + IF_ENABLED(DT_NODE_HAS_STATUS_OKAY(DT_INST_PARENT(inst)), ( \ + const struct ctsu_device_cfg ctsu_button_cfg##inst = { \ + .group_dev = DEVICE_DT_GET(DT_INST_PARENT(inst)), \ + .event_code = DT_INST_PROP(inst, event_code), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(inst, ctsu_device_init, NULL, NULL, &ctsu_button_cfg##inst, \ + POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL); \ + )) + +DT_INST_FOREACH_STATUS_OKAY(RENESAS_RA_CTSU_BUTTON_DEFINE) + +#undef DT_DRV_COMPAT +#define DT_DRV_COMPAT renesas_ra_ctsu_slider + +#define RENESAS_RA_CTSU_SLIDER_DEFINE(inst) \ + IF_ENABLED(DT_NODE_HAS_STATUS_OKAY(DT_INST_PARENT(inst)), ( \ + const struct ctsu_device_cfg ctsu_slider_cfg##inst = { \ + .group_dev = DEVICE_DT_GET(DT_INST_PARENT(inst)), \ + .event_code = DT_INST_PROP(inst, event_code), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(inst, ctsu_device_init, NULL, NULL, &ctsu_slider_cfg##inst, \ + POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL); \ + )) + +DT_INST_FOREACH_STATUS_OKAY(RENESAS_RA_CTSU_SLIDER_DEFINE) + +#undef DT_DRV_COMPAT +#define DT_DRV_COMPAT renesas_ra_ctsu_wheel + +#define RENESAS_RA_CTSU_WHEEL_DEFINE(inst) \ + IF_ENABLED(DT_NODE_HAS_STATUS_OKAY(DT_INST_PARENT(inst)), ( \ + const struct ctsu_device_cfg ctsu_wheel_cfg##inst = { \ + .group_dev = DEVICE_DT_GET(DT_INST_PARENT(inst)), \ + .event_code = DT_INST_PROP(inst, event_code), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(inst, ctsu_device_init, NULL, NULL, &ctsu_wheel_cfg##inst, \ + POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL); \ + )) + +DT_INST_FOREACH_STATUS_OKAY(RENESAS_RA_CTSU_WHEEL_DEFINE) diff --git a/dts/arm/renesas/ra/ra2/r7fa2a1xh.dtsi b/dts/arm/renesas/ra/ra2/r7fa2a1xh.dtsi index 053bc9ac165d..2ae3d89839de 100644 --- a/dts/arm/renesas/ra/ra2/r7fa2a1xh.dtsi +++ b/dts/arm/renesas/ra/ra2/r7fa2a1xh.dtsi @@ -100,6 +100,14 @@ clocks = <&pclkb 0 0>; status = "disabled"; }; + + ctsu: ctsua@40081000 { + compatible = "renesas,ra-ctsu"; + reg = <0x40081000 0x24>; + clocks = <&pclkb MSTPC 3>; + variant = "ctsua"; + status = "disabled"; + }; }; clocks: clocks { diff --git a/dts/arm/renesas/ra/ra2/ra2l1.dtsi b/dts/arm/renesas/ra/ra2/ra2l1.dtsi index 23bb39e78524..d484f7ec2536 100644 --- a/dts/arm/renesas/ra/ra2/ra2l1.dtsi +++ b/dts/arm/renesas/ra/ra2/ra2l1.dtsi @@ -515,6 +515,14 @@ #port-irq-cells = <0>; status = "disabled"; }; + + ctsu: ctsu2@40082000 { + compatible = "renesas,ra-ctsu"; + reg = <0x40082000 0x70>; + clocks = <&pclkb MSTPC 3>; + variant = "ctsu2"; + status = "disabled"; + }; }; clocks: clocks { diff --git a/dts/arm/renesas/ra/ra4/r7fa4m2ax.dtsi b/dts/arm/renesas/ra/ra4/r7fa4m2ax.dtsi index 8a155a1f6e8f..98baf88cca8e 100644 --- a/dts/arm/renesas/ra/ra4/r7fa4m2ax.dtsi +++ b/dts/arm/renesas/ra/ra4/r7fa4m2ax.dtsi @@ -144,6 +144,14 @@ compatible = "renesas,ra-sce9-rng"; status = "disabled"; }; + + ctsu: ctsua@40081000 { + compatible = "renesas,ra-ctsu"; + reg = <0x40081000 0x24>; + clocks = <&pclkb MSTPC 3>; + variant = "ctsua"; + status = "disabled"; + }; }; clocks: clocks { diff --git a/dts/arm/renesas/ra/ra4/r7fa4m3ax.dtsi b/dts/arm/renesas/ra/ra4/r7fa4m3ax.dtsi index a34f041f1a41..3031ef7396e3 100644 --- a/dts/arm/renesas/ra/ra4/r7fa4m3ax.dtsi +++ b/dts/arm/renesas/ra/ra4/r7fa4m3ax.dtsi @@ -157,6 +157,14 @@ compatible = "renesas,ra-sce9-rng"; status = "disabled"; }; + + ctsu: ctsua@40081000 { + compatible = "renesas,ra-ctsu"; + reg = <0x40081000 0x24>; + clocks = <&pclkb MSTPC 3>; + variant = "ctsua"; + status = "disabled"; + }; }; clocks: clocks { diff --git a/dts/arm/renesas/ra/ra4/ra4-cm4-common.dtsi b/dts/arm/renesas/ra/ra4/ra4-cm4-common.dtsi index 7319a75f79f6..d6604128f23a 100644 --- a/dts/arm/renesas/ra/ra4/ra4-cm4-common.dtsi +++ b/dts/arm/renesas/ra/ra4/ra4-cm4-common.dtsi @@ -441,6 +441,14 @@ clocks = <&pclkb 0 0>; status = "disabled"; }; + + ctsu: ctsua@40081000 { + compatible = "renesas,ra-ctsu"; + reg = <0x40081000 0x24>; + clocks = <&pclkb MSTPC 3>; + variant = "ctsua"; + status = "disabled"; + }; }; usbfs_phy: usbfs-phy { diff --git a/dts/arm/renesas/ra/ra6/ra6-cm33-common.dtsi b/dts/arm/renesas/ra/ra6/ra6-cm33-common.dtsi index 9625343ec278..6ca8afabbaa4 100644 --- a/dts/arm/renesas/ra/ra6/ra6-cm33-common.dtsi +++ b/dts/arm/renesas/ra/ra6/ra6-cm33-common.dtsi @@ -560,6 +560,14 @@ #size-cells = <0>; status = "disabled"; }; + + ctsu: ctsua@40081000 { + compatible = "renesas,ra-ctsu"; + reg = <0x40081000 0x24>; + clocks = <&pclkb MSTPC 3>; + variant = "ctsua"; + status = "disabled"; + }; }; usbfs_phy: usbfs-phy { diff --git a/dts/arm/renesas/ra/ra6/ra6-cm4-common.dtsi b/dts/arm/renesas/ra/ra6/ra6-cm4-common.dtsi index dd2c9cacddff..fce62f0de81b 100644 --- a/dts/arm/renesas/ra/ra6/ra6-cm4-common.dtsi +++ b/dts/arm/renesas/ra/ra6/ra6-cm4-common.dtsi @@ -655,6 +655,14 @@ clocks = <&pclkb 0 0>; status = "disabled"; }; + + ctsu: ctsua@40081000 { + compatible = "renesas,ra-ctsu"; + reg = <0x40081000 0x24>; + clocks = <&pclkb MSTPC 3>; + variant = "ctsua"; + status = "disabled"; + }; }; usbfs_phy: usbfs-phy { diff --git a/dts/bindings/input/renesas,ra-ctsu-button.yaml b/dts/bindings/input/renesas,ra-ctsu-button.yaml new file mode 100644 index 000000000000..38083f949799 --- /dev/null +++ b/dts/bindings/input/renesas,ra-ctsu-button.yaml @@ -0,0 +1,69 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +description: | + Renesas RA Capacitive Touch Button instance. + + This node is a renesas,ra-ctsu grandchild node and applies filters and calculations + to detect an input event on a group which is the child of renesas,ra-ctsu. + For more information see input/renesas,ra-ctsu.yaml + + Example: + + #include + + &ctsu { + compatible = "renesas,ra-ctsu"; + + group1 { + ... + button1 { + compatible = "renesas,ra-ctsu-button"; + elements = <0>; + threshold = <769>; + hysteresis = <38>; + event-code = ; + }; + + button2 { + compatible = "renesas,ra-ctsu-button"; + elements = <1>; + threshold = <769>; + hysteresis = <38>; + event-code = ; + }; + }; + }; + + Notes: The order of the CTSU button nodes in the same group must follow these elements index. + +compatible: "renesas,ra-ctsu-button" + +include: [base.yaml] + +properties: + event-code: + type: int + required: true + description: | + The key code for the device. This is used to identify the device in the + input subsystem. It should be one of the values defined in + include/input-event-codes.h. + + elements: + type: int + default: 0 + description: | + Element number from CTSU group that this button located on. + + threshold: + type: int + default: 0 + description: | + Touch/non-touch judgement threshold for automatic judgement. + + hysteresis: + type: int + default: 0 + description: | + Threshold hysteresis for chattering prevention for automatic judgement. diff --git a/dts/bindings/input/renesas,ra-ctsu-slider.yaml b/dts/bindings/input/renesas,ra-ctsu-slider.yaml new file mode 100644 index 000000000000..2c3a1b64b571 --- /dev/null +++ b/dts/bindings/input/renesas,ra-ctsu-slider.yaml @@ -0,0 +1,52 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +description: | + Renesas RA Capacitive Touch Slider instance. + + This node is a renesas,ra-ctsu grandchild node and applies filters and calculations + to detect an input event on a group which is the child of renesas,ra-ctsu. + For more information see input/renesas,ra-ctsu.yaml + + Example: + + #include + + &ctsu { + compatible = "renesas,ra-ctsu"; + + group1 { + ... + slider { + compatible = "renesas,ra-ctsu-slider"; + elements = <1>, <0>, <2>, <4>, <3>; + threshold = <573>; + event-code = ; + }; + }; + }; + +compatible: "renesas,ra-ctsu-slider" + +include: [base.yaml] + +properties: + event-code: + type: int + required: true + description: | + The key code for the device. This is used to identify the device in the + input subsystem. It should be one of the values defined in + include/input-event-codes.h. + + elements: + type: array + description: | + Element number array from CTSU group that used by this node. It should have the same + order with electrode located on the Capacitive Pad. + + threshold: + type: int + default: 0 + description: | + Touch/non-touch judgement threshold for automatic judgement. diff --git a/dts/bindings/input/renesas,ra-ctsu-wheel.yaml b/dts/bindings/input/renesas,ra-ctsu-wheel.yaml new file mode 100644 index 000000000000..33b8dcb0c6b4 --- /dev/null +++ b/dts/bindings/input/renesas,ra-ctsu-wheel.yaml @@ -0,0 +1,52 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +description: | + Renesas RA Capacitive Touch Wheel + + This node is a renesas,ra-ctsu grandchild node and applies filters and calculations + to detect an input event on a group which is the child of renesas,ra-ctsu. + For more information see input/renesas,ra-ctsu.yaml + + Example: + + #include + + &ctsu { + compatible = "renesas,ra-ctsu"; + + group1 { + ... + wheel { + compatible = "renesas,ra-ctsu-wheel"; + elements = <0>, <3>, <2>, <1>; + threshold = <711>; + event-code = ; + }; + }; + }; + +compatible: "renesas,ra-ctsu-wheel" + +include: [base.yaml] + +properties: + event-code: + type: int + required: true + description: | + The key code for the device. This is used to identify the device in the + input subsystem. It should be one of the values defined in + include/input-event-codes.h. + + elements: + type: array + description: | + Element number array from CTSU group that used by this node. It should have the same + order with electrode located on the Capacitive Pad. + + threshold: + type: int + default: 0 + description: | + Touch/non-touch judgement threshold for automatic judgement. diff --git a/dts/bindings/input/renesas,ra-ctsu.yaml b/dts/bindings/input/renesas,ra-ctsu.yaml new file mode 100644 index 000000000000..91f528dc1a5f --- /dev/null +++ b/dts/bindings/input/renesas,ra-ctsu.yaml @@ -0,0 +1,199 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +description: Renesas RA Capacitive Sensing Unit + +compatible: "renesas,ra-ctsu" + +include: [base.yaml, pinctrl-device.yaml] + +properties: + pinctrl-0: + required: true + + clocks: + required: true + + interrupts: + required: true + description: IRQ number and priority to use for CTSU. + + interrupt-names: + required: true + description: | + Interrupts must be given corresponding names so that the shim driver can recognize them. + - "ctsuwr": write interrupt + - "ctsurd": read interrupt + - "ctsufn": end interrupt + + variant: + required: true + type: string + enum: ["ctsua", "ctsu2"] + description: Determine which ctsu device is in use + + clock-div: + type: int + enum: [1, 2, 4, 8] + default: 1 + description: Select divider value for operating input clock. Default as div by 1. + + pwr-supply-sel: + type: string + enum: ["vcc", "internal-power"] + default: "internal-power" + description: CTSU Transmission Power Supply Select (for both CTSUa and CTSU2). + + pwr-supply-sel2: + type: string + enum: ["pwr-supply-sel", "vcc-private"] + default: "pwr-supply-sel" + description: CTSU Transmission Power Supply Select 2 (CTSU2 Only) + + atune1: + type: string + enum: ["normal", "high"] + default: "normal" + description: | + CTSU Power Supply Capacity Adjustment (CTSUa Only): + - "normal": 40uA + - "high": 80uA + + atune12: + type: int + enum: [80, 40, 20, 160] + default: 40 + description: | + CTSU Power Supply Capacity Adjustment in uA (CTSU2 Only) + + measure-mode: + type: string + enum: + - "self-multi-scan" + - "mutual-full-scan" + - "mutual-cfc-scan" + - "current-scan" + - "correction-scan" + - "diagnosis-scan" + default: "self-multi-scan" + description: CTSU Measurement Mode Select + + po-sel: + type: string + enum: + - "low-gpio" + - "hi-z" + - "low" + - "same-pulse" + default: "same-pulse" + description: CTSU Non-Measured Channel Output Select (CTSU2 Only) + + tscap-gpios: + type: phandle-array + required: true + description: | + CTSU TSCAP Pin. This pin is used to discharge the capacitior by + control to output low, before switching to CTSU function. + +child-binding: + description: Renesas RA CTSU touch configuration + properties: + ctsuchac: + type: array + default: [0, 0, 0, 0, 0] + description: | + TSCAP pin enable mask. Expected fields, in order, are: + - ctsuchac0: TS00-TS07 enable mask + - ctsuchac1: TS08-TS15 enable mask + - ctsuchac2: TS16-TS23 enable mask + - ctsuchac3: TS24-TS31 enable mask + - ctsuchac4: TS32-TS39 enable mask + + ctsuchtrc: + type: array + default: [0, 0, 0, 0, 0] + description: | + TSCAP pin mutual-tx mask. Expected fields, in order, are: + - ctsuchtrc0: TS00-TS07 mutual-tx mask + - ctsuchtrc1: TS08-TS15 mutual-tx mask + - ctsuchtrc2: TS16-TS23 mutual-tx mask + - ctsuchtrc3: TS24-TS31 mutual-tx mask + - ctsuchtrc4: TS32-TS39 mutual-tx mask + + rx-count: + type: int + default: 0 + description: | + The number of RX channels to be used. This should be set to the number of + channels that are enabled in the ctsuchac0-4 properties. + + tx-count: + type: int + default: 0 + description: | + The number of TX channels to be used. This should be set to the number of + channels that are enabled in the ctsuchtrc0-4 properties. + + ssdiv: + type: string-array + default: ["4.00"] + enum: + - "4.00" + - "2.00" + - "1.33" + - "1.00" + - "0.80" + - "0.67" + - "0.57" + - "0.50" + - "0.44" + - "0.40" + - "0.36" + - "0.33" + - "0.31" + - "0.29" + - "0.27" + - "0.00" + description: CTSU Spectrum Diffusion Frequency Division Setting (CTSUa Only) + + so: + type: array + default: [0] + description: CTSU Sensor Offset Adjustment + + snum: + type: array + default: [0] + description: CTSU Measurement Count Setting + + sdpa: + type: array + default: [0] + description: CTSU Base Clock Setting + + on-freq: + type: int + default: 0 + description: The cumulative number of determinations of ON. + + off-freq: + type: int + default: 0 + description: The cumulative number of determinations of OFF. + + drift-freq: + type: int + default: 0 + description: Base value drift frequency (0 mean no use). + + cancel-freq: + type: int + default: 0 + description: Maximum continuous ON (0 mean no use). + + num-moving-avg: + type: int + default: 0 + description: | + The number of samples to use for moving average. If set to 0, no moving average is applied. + This is useful for smoothing the sensor readings. diff --git a/include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-ra.h b/include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-ra.h index a077cd226866..133ea0ca5760 100644 --- a/include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-ra.h +++ b/include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-ra.h @@ -48,6 +48,7 @@ #define RA_PSEL_ETH_RMII 0x17 #define RA_PSEL_GLCDC 0x19 #define RA_PSEL_OSPI 0x1c +#define RA_PSEL_CTSU 0x0c #define RA_PSEL_POS 8 #define RA_PSEL_MASK 0x1f diff --git a/include/zephyr/input/input_renesas_ra_ctsu.h b/include/zephyr/input/input_renesas_ra_ctsu.h new file mode 100644 index 000000000000..df890f4fc033 --- /dev/null +++ b/include/zephyr/input/input_renesas_ra_ctsu.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_ZEPHYR_INPUT_INPUT_RENESAS_RA_CTSU_H_ +#define ZEPHYR_INCLUDE_ZEPHYR_INPUT_INPUT_RENESAS_RA_CTSU_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct renesas_ra_ctsu_touch_cfg { + struct st_touch_instance touch_instance; +}; + +/** + * @brief Configure CTSU group device with a Renesas QE for Capacitive Touch Workflow generated + * configuration + * + * @param dev Pointer to the input device instance + * @param cfg Pointer to the configuration data for the device + * + * @retval 0 on success + * @retval -ENOSYS in case INPUT_RENESAS_RA_QE_TOUCH_CFG was not enabled + * @retval -errno on failure + */ +__syscall int renesas_ra_ctsu_group_configure(const struct device *dev, + const struct renesas_ra_ctsu_touch_cfg *cfg); + +#ifdef __cplusplus +} +#endif + +#include + +#endif /* ZEPHYR_INCLUDE_ZEPHYR_INPUT_INPUT_RENESAS_RA_CTSU_H_ */ diff --git a/modules/Kconfig.renesas b/modules/Kconfig.renesas index 12a898e2d8e8..78dd7fff951e 100644 --- a/modules/Kconfig.renesas +++ b/modules/Kconfig.renesas @@ -201,6 +201,23 @@ config USE_RA_FSP_SSI help Enable RA FSP I2S SSI driver +config USE_RA_FSP_IOPORT + bool + help + Enable RA FSP IOPORT driver + +config USE_RA_FSP_CTSU + bool + select USE_RA_FSP_IOPORT + help + Enable RA FSP CTSU driver + +config USE_RA_FSP_TOUCH + bool + depends on USE_RA_FSP_CTSU + help + Enable RA FSP TOUCH library + endif # HAS_RENESAS_RA_FSP if HAS_RENESAS_RZ_FSP diff --git a/samples/shields/rtk0eg0019b01002bj/CMakeLists.txt b/samples/shields/rtk0eg0019b01002bj/CMakeLists.txt new file mode 100644 index 000000000000..d5f0ae560839 --- /dev/null +++ b/samples/shields/rtk0eg0019b01002bj/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(rtk0eg0019b01002bj) + +target_sources(app PRIVATE src/main.c) + +if(CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG) + zephyr_include_directories(src) + zephyr_sources(src/qe_touch_config.c) +endif() diff --git a/samples/shields/rtk0eg0019b01002bj/README.rst b/samples/shields/rtk0eg0019b01002bj/README.rst new file mode 100644 index 000000000000..f23df417123c --- /dev/null +++ b/samples/shields/rtk0eg0019b01002bj/README.rst @@ -0,0 +1,116 @@ +.. zephyr:code-sample:: rtk0eg0019b01002bj + :name: RTK0EG0019B01002BJ Capacitive Touch Application Shield + :relevant-api: input_events + + Interact with the Capacitive Touch Sensor and LED matrix on the RTK0EG0019B01002BJ shield + +Overview +******** + +This sample demonstrates the usage of the Capacitive Touch Sensor using the +:ref:`rtk0eg0019b01002bj` with `Renesas Capacitive Touch Sensor Solutions`_. + +Requirements +************ + +A Renesas Capacitive Touch Evaluation Kit is needed to run this sample. It includes: + +- A MCU board which support CTSU driver (for example: RSSK-RA2L1). +- A RTK0EG0019B01002BJ Touch Application board. + +Building and Running +******************** + +Build and flash with default settings for shield +================================================ +The :ref:`rtk0eg0019b01002bj` comes with a default DTS configuration that is tuned in advance to +make it ready for development. + +Build and flash as follows, changing ``rssk_ra2l1`` for your board: + +.. zephyr-app-commands:: + :zephyr-app: samples/shields/rtk0eg0019b01002bj + :board: rssk_ra2l1 + :shield: rtk0eg0019b01002bj + :goals: build flash + :compact: + +After startup, all LEDs on the shield will blink 5 times to indicate that the +application has started. + +You can monitor input events through the console output. Additionally, the LED +corresponding to the touched sensor will turn on when you touch it. + +.. code-block:: console + + *** Booting Zephyr OS build v4.1.0-6697-gdc27367ff627 *** + rtk0eg0019b01002bj sample started + I: input event: dev=button1 type= 1 code= 11 value=0 + I: input event: dev=wheel type= 3 code= 8 value=61 + I: input event: dev=wheel type= 3 code= 8 value=67 + I: input event: dev=wheel type= 3 code= 8 value=82 + I: input event: dev=wheel type= 3 code= 8 value=111 + I: input event: dev=wheel type= 3 code= 8 value=124 + I: input event: dev=wheel type= 3 code= 8 value=134 + I: input event: dev=slider type= 3 code= 6 value=0 + I: input event: dev=slider type= 3 code= 6 value=2 + I: input event: dev=slider type= 3 code= 6 value=4 + I: input event: dev=slider type= 3 code= 6 value=6 + I: input event: dev=slider type= 3 code= 6 value=10 + I: input event: dev=slider type= 3 code= 6 value=23 + I: input event: dev=slider type= 3 code= 6 value=26 + I: input event: dev=slider type= 3 code= 6 value=27 + I: input event: dev=slider type= 3 code= 6 value=28 + +(Advanced) Using Configuration Output Generated by Renesas QE Capacitive Touch Workflow +======================================================================================= +This section is for advanced users who do not want to use the default configuration for the Cap +Touch shield and would like to tune configuration parameters manually themselves using the +`Renesas Development Assistance Tool for Capacitive Touch Sensors`_. + +Requirements +------------ + +- `e² studio`_ with Renesas QE Capacitive Touch plugin installed: recommended 2025-04.1 version +- `RA Flexible Software Package`_: recommended FSP v5.8.0 or newer + +Building and flashing with generated tuning code +------------------------------------------------ + + 1. Follow steps 6.1 to 6.5 of `Using QE and FSP to Develop Capacitive Touch Applications`_. + + 2. At step 8 in 6.5 Tuning the Capacitive Touch Interface Using QE for Capacitive Touch Plug-in, + select 'Specify an output folder' and choose this application's subfolder. + + 3. Update the include path to qe_touch_config.h and qe_touch_define.h, and add qe_touch_config.c + to the build sources in your application's CMake. + + 4. Build and flash the application with the command below: + +.. zephyr-app-commands:: + :zephyr-app: samples/shields/rtk0eg0019b01002bj + :board: rssk_ra2l1 + :shield: rtk0eg0019b01002bj + :gen-args: -DCONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG=y + :goals: build flash + :compact: + +References +********** +- `Renesas Capacitive Touch Sensor Solutions`_ +- `Renesas Development Assistance Tool for Capacitive Touch Sensors`_ + +.. _Renesas Capacitive Touch Sensor Solutions: + https://www.renesas.com/en/key-technologies/hmi/capacitive-touch-sensor-solutions + +.. _Renesas Development Assistance Tool for Capacitive Touch Sensors: + https://www.renesas.com/en/software-tool/qe-capacitive-touch-development-assistance-tool-capacitive-touch-sensors + +.. _Using QE and FSP to Develop Capacitive Touch Applications: + https://www.renesas.com/en/document/apn/using-qe-and-fsp-develop-capacitive-touch-applications?r=1170071 + +.. _e² studio: + https://www.renesas.com/en/software-tool/e-studio + +.. _RA Flexible Software Package: + https://www.renesas.com/en/software-tool/flexible-software-package diff --git a/samples/shields/rtk0eg0019b01002bj/prj.conf b/samples/shields/rtk0eg0019b01002bj/prj.conf new file mode 100644 index 000000000000..12b75f7b1df0 --- /dev/null +++ b/samples/shields/rtk0eg0019b01002bj/prj.conf @@ -0,0 +1,9 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_LOG=y +CONFIG_LOG_MODE_MINIMAL=y + +CONFIG_INPUT=y +CONFIG_INPUT_EVENT_DUMP=y +CONFIG_GPIO=y diff --git a/samples/shields/rtk0eg0019b01002bj/sample.yaml b/samples/shields/rtk0eg0019b01002bj/sample.yaml new file mode 100644 index 000000000000..3b6911e20ccf --- /dev/null +++ b/samples/shields/rtk0eg0019b01002bj/sample.yaml @@ -0,0 +1,9 @@ +sample: + name: RTK0EG0019B01002BJ Capacitive Touch Application Shield +tests: + sample.shields.rtk0eg0019b01002bj: + harness: shield + tags: shield + platform_allow: + - rssk_ra2l1 + extra_args: SHIELD=rtk0eg0019b01002bj diff --git a/samples/shields/rtk0eg0019b01002bj/src/main.c b/samples/shields/rtk0eg0019b01002bj/src/main.c new file mode 100644 index 000000000000..f617f63a09bd --- /dev/null +++ b/samples/shields/rtk0eg0019b01002bj/src/main.c @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG +#include "qe_touch_config.h" +#endif /* CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG*/ + +#define LED_MATRIX DT_NODELABEL(rtk0eg0019b01002bj_led_matrix) +#define BUTTON1 DT_NODELABEL(rtk0eg0019b01002bj_bt1) +#define BUTTON2 DT_NODELABEL(rtk0eg0019b01002bj_bt2) +#define BUTTON3 DT_NODELABEL(rtk0eg0019b01002bj_bt3) +#define SLIDER DT_NODELABEL(rtk0eg0019b01002bj_slider) +#define WHEEL DT_NODELABEL(rtk0eg0019b01002bj_wheel) + +#define QE_TOUCH_CFG1 DT_CHILD(DT_NODELABEL(rtk0eg0019b01002bj_ctsu), group1) +#define QE_TOUCH_CFG2 DT_CHILD(DT_NODELABEL(rtk0eg0019b01002bj_ctsu), group2) +#define QE_TOUCH_CFG3 DT_CHILD(DT_NODELABEL(rtk0eg0019b01002bj_ctsu), group3) + +#define NUM_ROWS DT_PROP(LED_MATRIX, num_rows) +#define NUM_COLS DT_PROP(LED_MATRIX, num_cols) + +#define LED_MATRIX_ROWS(idx, nodeid) GPIO_DT_SPEC_GET_BY_IDX(nodeid, led_row_gpios, idx) +#define LED_MATRIX_COLS(idx, nodeid) GPIO_DT_SPEC_GET_BY_IDX(nodeid, led_col_gpios, idx) + +#define BUTTON_LED_NUM (3U) + +#define SLIDER_LED_NUM (5U) +#define SLIDER_RESOLUTION (100) + +#define WHEEL_LED_NUM (8U) +#define WHEEL_RESOLUTION_DEGREE (360) + +static const struct gpio_dt_spec led_row[NUM_ROWS] = { + LISTIFY(NUM_ROWS, LED_MATRIX_ROWS, (,), LED_MATRIX), +}; + +static const struct gpio_dt_spec led_col[NUM_COLS] = { + LISTIFY(NUM_COLS, LED_MATRIX_COLS, (,), LED_MATRIX), +}; + +static const unsigned int wheel_leds_lut[WHEEL_LED_NUM] = {0, 1, 2, 3, 4, 5, 6, 7}; +static const unsigned int slider_leds_lut[SLIDER_LED_NUM] = {8, 9, 10, 11, 12}; +static const unsigned int button_leds_lut[BUTTON_LED_NUM] = {13, 14, 15}; + +static void rtk0eg0019b01002bj_led_output(unsigned int led_idx, bool on) +{ + /* Refer to RTK0EG0022S01001BJ - Design Package for the Touch Application board layout */ + static const unsigned int led_map[NUM_ROWS * NUM_COLS][2] = { + {0, 0}, {1, 0}, {2, 0}, {3, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, + {0, 3}, {1, 3}, {2, 3}, {3, 3}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, + }; + const struct gpio_dt_spec *p_led_row = &led_row[led_map[led_idx][0]]; + const struct gpio_dt_spec *p_led_col = &led_col[led_map[led_idx][1]]; + + gpio_pin_set_dt(p_led_row, on ? 1 : 0); + gpio_pin_set_dt(p_led_col, on ? 1 : 0); +} + +static void rtk0eg0019b01002bj_led_init(void) +{ + for (int i = 0; i < NUM_ROWS; i++) { + gpio_pin_configure_dt(&led_row[i], GPIO_OUTPUT_INACTIVE); + } + + for (int i = 0; i < NUM_COLS; i++) { + gpio_pin_configure_dt(&led_col[i], GPIO_OUTPUT_INACTIVE); + } +} + +static void blink_leds(unsigned int duration_ms) +{ + for (int i = 0; i < 5; i++) { + /* Turn all LEDs ON */ + for (int j = 0; j < NUM_ROWS * NUM_COLS; j++) { + rtk0eg0019b01002bj_led_output(j, true); + } + k_msleep(duration_ms); + + /* Turn all LEDs OFF */ + for (int j = 0; j < NUM_ROWS * NUM_COLS; j++) { + rtk0eg0019b01002bj_led_output(j, false); + } + k_msleep(duration_ms); + } +} + +static inline unsigned int wheel_get_current_step(unsigned int value) +{ + return (value * WHEEL_LED_NUM) / WHEEL_RESOLUTION_DEGREE; +} + +static inline unsigned int slider_get_current_step(unsigned int value) +{ + return (value * SLIDER_LED_NUM) / SLIDER_RESOLUTION; +} + +static void rtk0eg0019b01002bj_evt_handler(struct input_event *evt, void *user_data) +{ + unsigned int led_idx; + + /* Set all LEDs to OFF */ + for (int i = 0; i < NUM_ROWS * NUM_COLS; i++) { + rtk0eg0019b01002bj_led_output(i, false); + } + + switch (evt->code) { + case INPUT_KEY_0: { + led_idx = button_leds_lut[0]; + break; + } + case INPUT_KEY_1: { + led_idx = button_leds_lut[1]; + break; + } + case INPUT_KEY_2: { + led_idx = button_leds_lut[2]; + break; + } + case INPUT_ABS_WHEEL: { + led_idx = wheel_get_current_step(evt->value) + wheel_leds_lut[0]; + break; + } + case INPUT_ABS_THROTTLE: { + led_idx = slider_get_current_step(evt->value) + slider_leds_lut[0]; + break; + } + default: + /* Unexpected event */ + return; + } + + rtk0eg0019b01002bj_led_output(led_idx, true); +} + +INPUT_CALLBACK_DEFINE_NAMED(DEVICE_DT_GET(BUTTON1), rtk0eg0019b01002bj_evt_handler, NULL, button1); +INPUT_CALLBACK_DEFINE_NAMED(DEVICE_DT_GET(BUTTON2), rtk0eg0019b01002bj_evt_handler, NULL, button2); +INPUT_CALLBACK_DEFINE_NAMED(DEVICE_DT_GET(BUTTON3), rtk0eg0019b01002bj_evt_handler, NULL, button3); +INPUT_CALLBACK_DEFINE_NAMED(DEVICE_DT_GET(SLIDER), rtk0eg0019b01002bj_evt_handler, NULL, slider); +INPUT_CALLBACK_DEFINE_NAMED(DEVICE_DT_GET(WHEEL), rtk0eg0019b01002bj_evt_handler, NULL, wheel); + +int main(void) +{ +#ifdef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG + const struct device *qe_touch_cfg1 = DEVICE_DT_GET(QE_TOUCH_CFG1); + const struct device *qe_touch_cfg2 = DEVICE_DT_GET(QE_TOUCH_CFG2); + const struct device *qe_touch_cfg3 = DEVICE_DT_GET(QE_TOUCH_CFG3); + int ret; +#endif + rtk0eg0019b01002bj_led_init(); + + /* Blink all leds 5 times, each time is 200ms */ + blink_leds(200); + +#ifdef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG + ret = renesas_ra_ctsu_group_configure( + qe_touch_cfg1, (struct renesas_ra_ctsu_touch_cfg *)&g_qe_touch_instance_config01); + if (ret < 0) { + printk("Failed to configure QE Touch Group 1: %d\n", ret); + return ret; + } + + ret = renesas_ra_ctsu_group_configure( + qe_touch_cfg2, (struct renesas_ra_ctsu_touch_cfg *)&g_qe_touch_instance_config02); + if (ret < 0) { + printk("Failed to configure QE Touch Group 2: %d\n", ret); + return ret; + } + + ret = renesas_ra_ctsu_group_configure( + qe_touch_cfg3, (struct renesas_ra_ctsu_touch_cfg *)&g_qe_touch_instance_config03); + if (ret < 0) { + printk("Failed to configure QE Touch Group 3: %d\n", ret); + return ret; + } +#endif + + printk("rtk0eg0019b01002bj sample started\n"); + return 0; +} diff --git a/samples/shields/rtk0eg0019b01002bj/src/qe_touch_config.c b/samples/shields/rtk0eg0019b01002bj/src/qe_touch_config.c new file mode 100644 index 000000000000..57f405451bc2 --- /dev/null +++ b/samples/shields/rtk0eg0019b01002bj/src/qe_touch_config.c @@ -0,0 +1,473 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/************************************************************************************************** + * File Name : qe_touch_config.c + * Description : This file includes module implementations. + **************************************************************************************************/ +/************************************************************************************************** + * History : MM/DD/YYYY Version Description + * : 09/02/2019 1.00 First Release + * : 10/07/2019 1.00a Provisional Version for RA2L1 + * : 12/26/2019 1.10 Corresponding for FSP V0.10.0 + * : 02/20/2020 1.20 Corresponding for FSP V0.12.0 + * : 02/26/2020 1.21 Adding information for Temperature Correction + * : 03/04/2020 1.30 Corresponding for FSP V1.0.0 RC0 + * : 03/10/2020 1.31 Corresponding for FSP V1.0.0 RC1 + * : 09/10/2020 1.40 Corresponding for FSP V2.0.0 Beta2 + * : 05/26/2021 1.50 Adding Diagnosis Supporting + * : 06/01/2021 1.51 Fixing a Little + * : 07/15/2021 1.52 Fixing a Little + * : 08/20/2021 1.53 Fixing a Little + * : 11/13/2021 1.60 Adding information for Initial Offset Tuning + * : 03/31/2023 1.61 Improving Traceability + * : 04/18/2023 1.70 Adding 3 Frequency Judgement Supporting + * : 07/30/2024 1.80 Adding Auto Judgement Supporting + **************************************************************************************************/ +/************************************************************************************************** + * Touch I/F Configuration File : quickstart_rssk_ra2l1_ep.tifcfg + * Tuning Log File : quickstart_rssk_ra2l1_ep_log_tuning20230904134024.log + **************************************************************************************************/ + +#include "qe_touch_config.h" + +volatile uint8_t g_qe_touch_flag; +volatile ctsu_event_t g_qe_ctsu_event; + +void qe_touch_callback(touch_callback_args_t *p_args) +{ + g_qe_touch_flag = 1; + g_qe_ctsu_event = p_args->event; +} + +/************************************************************************************************** + * CTSU Related Information for [CONFIG01] configuration. + **************************************************************************************************/ + +const ctsu_element_cfg_t g_qe_ctsu_element_cfg_config01[] = { + {.ssdiv = CTSU_SSDIV_4000, .so = 0x000, .snum = 0x07, .sdpa = 0x1F}, + {.ssdiv = CTSU_SSDIV_4000, .so = 0x00F, .snum = 0x07, .sdpa = 0x1F}, + {.ssdiv = CTSU_SSDIV_4000, .so = 0x007, .snum = 0x07, .sdpa = 0x1F}, +}; + +const ctsu_cfg_t g_qe_ctsu_cfg_config01 = { + .cap = CTSU_CAP_SOFTWARE, + + .txvsel = CTSU_TXVSEL_INTERNAL_POWER, + .txvsel2 = CTSU_TXVSEL_MODE, + + .atune12 = CTSU_ATUNE12_40UA, + .md = CTSU_MODE_SELF_MULTI_SCAN, + .posel = CTSU_POSEL_SAME_PULSE, + + .ctsuchac0 = 0x01, /* ch0-ch7 enable mask */ + .ctsuchac1 = 0x0E, /* ch8-ch15 enable mask */ + .ctsuchac2 = 0x00, /* ch16-ch23 enable mask */ + .ctsuchac3 = 0x00, /* ch24-ch31 enable mask */ + .ctsuchac4 = 0x00, /* ch32-ch39 enable mask */ + .ctsuchtrc0 = 0x01, /* ch0-ch7 mutual tx mask */ + .ctsuchtrc1 = 0x00, /* ch8-ch15 mutual tx mask */ + .ctsuchtrc2 = 0x00, /* ch16-ch23 mutual tx mask */ + .ctsuchtrc3 = 0x00, /* ch24-ch31 mutual tx mask */ + .ctsuchtrc4 = 0x00, /* ch32-ch39 mutual tx mask */ + .num_rx = 3, + .num_tx = 0, + .p_elements = g_qe_ctsu_element_cfg_config01, + +#if (CTSU_TARGET_VALUE_CONFIG_SUPPORT == 1) + .tuning_self_target_value = 4608, + .tuning_mutual_target_value = 10240, +#endif + + .num_moving_average = 4, + .p_callback = &qe_touch_callback, +#if (CTSU_CFG_DTC_SUPPORT_ENABLE == 1) + .p_transfer_tx = &g_transfer0, + .p_transfer_rx = &g_transfer1, +#else + .p_transfer_tx = NULL, + .p_transfer_rx = NULL, +#endif + + .write_irq = CTSU_WRITE_IRQn, + .read_irq = CTSU_READ_IRQn, + .end_irq = CTSU_END_IRQn, + +}; + +ctsu_instance_ctrl_t g_qe_ctsu_ctrl_config01; + +const ctsu_instance_t g_qe_ctsu_instance_config01 = { + .p_ctrl = &g_qe_ctsu_ctrl_config01, + .p_cfg = &g_qe_ctsu_cfg_config01, + .p_api = &g_ctsu_on_ctsu, +}; + +/************************************************************************************************** + * Touch Related Information for [CONFIG01] configuration. + **************************************************************************************************/ + +#define QE_TOUCH_CONFIG01_NUM_BUTTONS (3) +#define QE_TOUCH_CONFIG01_NUM_SLIDERS (0) +#define QE_TOUCH_CONFIG01_NUM_WHEELS (0) +#define QE_TOUCH_CONFIG01_NUM_TOUCH_PADS (0) + +/* Button configurations */ +#if (QE_TOUCH_CONFIG01_NUM_BUTTONS != 0) +const touch_button_cfg_t g_qe_touch_button_cfg_config01[] = { + + /* VMM */ + /* button02 */ + { + .elem_index = 0, + .threshold = 306, + .hysteresis = 15, + }, + /* button01 */ + { + .elem_index = 1, + .threshold = 226, + .hysteresis = 11, + }, + /* button00 */ + { + .elem_index = 2, + .threshold = 261, + .hysteresis = 13, + }, +}; +#endif + +/* Slider configurations */ +#if (QE_TOUCH_CONFIG01_NUM_SLIDERS != 0) +const touch_slider_cfg_t g_qe_touch_slider_cfg_config01[] = {NULL}; +#endif + +/* Wheel configurations */ +#if (QE_TOUCH_CONFIG01_NUM_WHEELS != 0) +const touch_wheel_cfg_t g_qe_touch_wheel_cfg_config01[] = {NULL}; +#endif + +/* Touch pad configurations */ +#if (QE_TOUCH_CONFIG01_NUM_TOUCH_PADS != 0) +const touch_pad_cfg_t g_qe_touch_touch_pad_cfg_config01 = {NULL}; +#endif + +/* Touch configurations */ +const touch_cfg_t g_qe_touch_cfg_config01 = { + .p_buttons = g_qe_touch_button_cfg_config01, + .p_sliders = NULL, + .p_wheels = NULL, +#if (TOUCH_CFG_PAD_ENABLE != 0) + .p_pad = NULL, +#endif + .num_buttons = QE_TOUCH_CONFIG01_NUM_BUTTONS, + .num_sliders = QE_TOUCH_CONFIG01_NUM_SLIDERS, + .num_wheels = QE_TOUCH_CONFIG01_NUM_WHEELS, + + .number = 0, +#if ((TOUCH_CFG_UART_MONITOR_SUPPORT == 1) || (TOUCH_CFG_UART_TUNING_SUPPORT == 1)) + .p_uart_instance = &g_uart_qe, +#else + .p_uart_instance = NULL, +#endif + + .on_freq = 3, + .off_freq = 3, + .drift_freq = 255, + .cancel_freq = 0, + + .p_ctsu_instance = &g_qe_ctsu_instance_config01, +}; + +touch_instance_ctrl_t g_qe_touch_ctrl_config01; + +const touch_instance_t g_qe_touch_instance_config01 = { + .p_ctrl = &g_qe_touch_ctrl_config01, + .p_cfg = &g_qe_touch_cfg_config01, + .p_api = &g_touch_on_ctsu, +}; + +/************************************************************************************************** + * CTSU Related Information for [CONFIG02] configuration. + **************************************************************************************************/ + +const ctsu_element_cfg_t g_qe_ctsu_element_cfg_config02[] = { + {.ssdiv = CTSU_SSDIV_4000, .so = 0x021, .snum = 0x07, .sdpa = 0x0F}, + {.ssdiv = CTSU_SSDIV_4000, .so = 0x032, .snum = 0x07, .sdpa = 0x0F}, + {.ssdiv = CTSU_SSDIV_4000, .so = 0x02C, .snum = 0x07, .sdpa = 0x0F}, + {.ssdiv = CTSU_SSDIV_4000, .so = 0x034, .snum = 0x07, .sdpa = 0x0F}, + {.ssdiv = CTSU_SSDIV_4000, .so = 0x032, .snum = 0x07, .sdpa = 0x0F}, +}; + +const ctsu_cfg_t g_qe_ctsu_cfg_config02 = { + .cap = CTSU_CAP_SOFTWARE, + + .txvsel = CTSU_TXVSEL_INTERNAL_POWER, + .txvsel2 = CTSU_TXVSEL_MODE, + + .atune12 = CTSU_ATUNE12_40UA, + .md = CTSU_MODE_SELF_MULTI_SCAN, + .posel = CTSU_POSEL_SAME_PULSE, + + .ctsuchac0 = 0xF4, /* ch0-ch7 enable mask */ + .ctsuchac1 = 0x01, /* ch8-ch15 enable mask */ + .ctsuchac2 = 0x00, /* ch16-ch23 enable mask */ + .ctsuchac3 = 0x00, /* ch24-ch31 enable mask */ + .ctsuchac4 = 0x00, /* ch32-ch39 enable mask */ + .ctsuchtrc0 = 0x00, /* ch0-ch7 mutual tx mask */ + .ctsuchtrc1 = 0x01, /* ch8-ch15 mutual tx mask */ + .ctsuchtrc2 = 0x00, /* ch16-ch23 mutual tx mask */ + .ctsuchtrc3 = 0x00, /* ch24-ch31 mutual tx mask */ + .ctsuchtrc4 = 0x00, /* ch32-ch39 mutual tx mask */ + .num_rx = 5, + .num_tx = 0, + .p_elements = g_qe_ctsu_element_cfg_config02, + +#if (CTSU_TARGET_VALUE_CONFIG_SUPPORT == 1) + .tuning_self_target_value = 4608, + .tuning_mutual_target_value = 10240, +#endif + + .num_moving_average = 4, + .p_callback = &qe_touch_callback, +#if (CTSU_CFG_DTC_SUPPORT_ENABLE == 1) + .p_transfer_tx = &g_transfer0, + .p_transfer_rx = &g_transfer1, +#else + .p_transfer_tx = NULL, + .p_transfer_rx = NULL, +#endif + + .write_irq = CTSU_WRITE_IRQn, + .read_irq = CTSU_READ_IRQn, + .end_irq = CTSU_END_IRQn, + +}; + +ctsu_instance_ctrl_t g_qe_ctsu_ctrl_config02; + +const ctsu_instance_t g_qe_ctsu_instance_config02 = { + .p_ctrl = &g_qe_ctsu_ctrl_config02, + .p_cfg = &g_qe_ctsu_cfg_config02, + .p_api = &g_ctsu_on_ctsu, +}; + +/************************************************************************************************** + * Touch Related Information for [CONFIG02] configuration. + **************************************************************************************************/ + +#define QE_TOUCH_CONFIG02_NUM_BUTTONS (0) +#define QE_TOUCH_CONFIG02_NUM_SLIDERS (1) +#define QE_TOUCH_CONFIG02_NUM_WHEELS (0) +#define QE_TOUCH_CONFIG02_NUM_TOUCH_PADS (0) + +/* Button configurations */ +#if (QE_TOUCH_CONFIG02_NUM_BUTTONS != 0) +const touch_button_cfg_t g_qe_touch_button_cfg_config02[] = { + + /* VMM */ + NULL}; +#endif + +/* Slider configurations */ +const uint8_t g_qe_touch_elem_slider_config02_slider00[] = {1, 0, 2, 4, 3}; + +#if (QE_TOUCH_CONFIG02_NUM_SLIDERS != 0) +const touch_slider_cfg_t g_qe_touch_slider_cfg_config02[] = { + /* slider00 */ + { + .p_elem_index = g_qe_touch_elem_slider_config02_slider00, + .num_elements = 5, + .threshold = 570, + }, +}; +#endif + +/* Wheel configurations */ +#if (QE_TOUCH_CONFIG02_NUM_WHEELS != 0) +const touch_wheel_cfg_t g_qe_touch_wheel_cfg_config02[] = {NULL}; +#endif + +/* Touch pad configurations */ +#if (QE_TOUCH_CONFIG02_NUM_TOUCH_PADS != 0) +const touch_pad_cfg_t g_qe_touch_touch_pad_cfg_config02 = {NULL}; +#endif + +/* Touch configurations */ +const touch_cfg_t g_qe_touch_cfg_config02 = { + .p_buttons = NULL, + .p_sliders = g_qe_touch_slider_cfg_config02, + .p_wheels = NULL, +#if (TOUCH_CFG_PAD_ENABLE != 0) + .p_pad = NULL, +#endif + .num_buttons = QE_TOUCH_CONFIG02_NUM_BUTTONS, + .num_sliders = QE_TOUCH_CONFIG02_NUM_SLIDERS, + .num_wheels = QE_TOUCH_CONFIG02_NUM_WHEELS, + + .number = 1, +#if ((TOUCH_CFG_UART_MONITOR_SUPPORT == 1) || (TOUCH_CFG_UART_TUNING_SUPPORT == 1)) + .p_uart_instance = &g_uart_qe, +#else + .p_uart_instance = NULL, +#endif + + .on_freq = 3, + .off_freq = 3, + .drift_freq = 255, + .cancel_freq = 0, + + .p_ctsu_instance = &g_qe_ctsu_instance_config02, +}; + +touch_instance_ctrl_t g_qe_touch_ctrl_config02; + +const touch_instance_t g_qe_touch_instance_config02 = { + .p_ctrl = &g_qe_touch_ctrl_config02, + .p_cfg = &g_qe_touch_cfg_config02, + .p_api = &g_touch_on_ctsu, +}; + +/************************************************************************************************** + * CTSU Related Information for [CONFIG03] configuration. + **************************************************************************************************/ + +const ctsu_element_cfg_t g_qe_ctsu_element_cfg_config03[] = { + {.ssdiv = CTSU_SSDIV_4000, .so = 0x03F, .snum = 0x07, .sdpa = 0x0F}, + {.ssdiv = CTSU_SSDIV_4000, .so = 0x03D, .snum = 0x07, .sdpa = 0x0F}, + {.ssdiv = CTSU_SSDIV_4000, .so = 0x041, .snum = 0x07, .sdpa = 0x0F}, + {.ssdiv = CTSU_SSDIV_4000, .so = 0x037, .snum = 0x07, .sdpa = 0x0F}, +}; + +const ctsu_cfg_t g_qe_ctsu_cfg_config03 = { + .cap = CTSU_CAP_SOFTWARE, + + .txvsel = CTSU_TXVSEL_INTERNAL_POWER, + .txvsel2 = CTSU_TXVSEL_MODE, + + .atune12 = CTSU_ATUNE12_40UA, + .md = CTSU_MODE_SELF_MULTI_SCAN, + .posel = CTSU_POSEL_SAME_PULSE, + + .ctsuchac0 = 0x00, /* ch0-ch7 enable mask */ + .ctsuchac1 = 0x40, /* ch8-ch15 enable mask */ + .ctsuchac2 = 0xA4, /* ch16-ch23 enable mask */ + .ctsuchac3 = 0x00, /* ch24-ch31 enable mask */ + .ctsuchac4 = 0x01, /* ch32-ch39 enable mask */ + .ctsuchtrc0 = 0x00, /* ch0-ch7 mutual tx mask */ + .ctsuchtrc1 = 0x40, /* ch8-ch15 mutual tx mask */ + .ctsuchtrc2 = 0x00, /* ch16-ch23 mutual tx mask */ + .ctsuchtrc3 = 0x00, /* ch24-ch31 mutual tx mask */ + .ctsuchtrc4 = 0x00, /* ch32-ch39 mutual tx mask */ + .num_rx = 4, + .num_tx = 0, + .p_elements = g_qe_ctsu_element_cfg_config03, + +#if (CTSU_TARGET_VALUE_CONFIG_SUPPORT == 1) + .tuning_self_target_value = 4608, + .tuning_mutual_target_value = 10240, +#endif + + .num_moving_average = 4, + .p_callback = &qe_touch_callback, +#if (CTSU_CFG_DTC_SUPPORT_ENABLE == 1) + .p_transfer_tx = &g_transfer0, + .p_transfer_rx = &g_transfer1, +#else + .p_transfer_tx = NULL, + .p_transfer_rx = NULL, +#endif + + .write_irq = CTSU_WRITE_IRQn, + .read_irq = CTSU_READ_IRQn, + .end_irq = CTSU_END_IRQn, + +}; + +ctsu_instance_ctrl_t g_qe_ctsu_ctrl_config03; + +const ctsu_instance_t g_qe_ctsu_instance_config03 = { + .p_ctrl = &g_qe_ctsu_ctrl_config03, + .p_cfg = &g_qe_ctsu_cfg_config03, + .p_api = &g_ctsu_on_ctsu, +}; + +/************************************************************************************************** + * Touch Related Information for [CONFIG03] configuration. + **************************************************************************************************/ + +#define QE_TOUCH_CONFIG03_NUM_BUTTONS (0) +#define QE_TOUCH_CONFIG03_NUM_SLIDERS (0) +#define QE_TOUCH_CONFIG03_NUM_WHEELS (1) +#define QE_TOUCH_CONFIG03_NUM_TOUCH_PADS (0) + +/* Button configurations */ +#if (QE_TOUCH_CONFIG03_NUM_BUTTONS != 0) +const touch_button_cfg_t g_qe_touch_button_cfg_config03[] = { + + /* VMM */ + NULL}; +#endif + +/* Slider configurations */ +#if (QE_TOUCH_CONFIG03_NUM_SLIDERS != 0) +const touch_slider_cfg_t g_qe_touch_slider_cfg_config03[] = {NULL}; +#endif + +/* Wheel configurations */ +const uint8_t g_qe_touch_elem_wheel_config03_wheel00[] = {1, 0, 3, 2}; + +#if (QE_TOUCH_CONFIG03_NUM_WHEELS != 0) +const touch_wheel_cfg_t g_qe_touch_wheel_cfg_config03[] = { + /* wheel00 */ + { + .p_elem_index = g_qe_touch_elem_wheel_config03_wheel00, + .num_elements = 4, + .threshold = 585, + }, +}; +#endif + +/* Touch pad configurations */ +#if (QE_TOUCH_CONFIG03_NUM_TOUCH_PADS != 0) +const touch_pad_cfg_t g_qe_touch_touch_pad_cfg_config03 = {NULL}; +#endif + +/* Touch configurations */ +const touch_cfg_t g_qe_touch_cfg_config03 = { + .p_buttons = NULL, + .p_sliders = NULL, + .p_wheels = g_qe_touch_wheel_cfg_config03, +#if (TOUCH_CFG_PAD_ENABLE != 0) + .p_pad = NULL, +#endif + .num_buttons = QE_TOUCH_CONFIG03_NUM_BUTTONS, + .num_sliders = QE_TOUCH_CONFIG03_NUM_SLIDERS, + .num_wheels = QE_TOUCH_CONFIG03_NUM_WHEELS, + + .number = 2, +#if ((TOUCH_CFG_UART_MONITOR_SUPPORT == 1) || (TOUCH_CFG_UART_TUNING_SUPPORT == 1)) + .p_uart_instance = &g_uart_qe, +#else + .p_uart_instance = NULL, +#endif + + .on_freq = 3, + .off_freq = 3, + .drift_freq = 255, + .cancel_freq = 0, + + .p_ctsu_instance = &g_qe_ctsu_instance_config03, +}; + +touch_instance_ctrl_t g_qe_touch_ctrl_config03; + +const touch_instance_t g_qe_touch_instance_config03 = { + .p_ctrl = &g_qe_touch_ctrl_config03, + .p_cfg = &g_qe_touch_cfg_config03, + .p_api = &g_touch_on_ctsu, +}; diff --git a/samples/shields/rtk0eg0019b01002bj/src/qe_touch_config.h b/samples/shields/rtk0eg0019b01002bj/src/qe_touch_config.h new file mode 100644 index 000000000000..a5a6acd89299 --- /dev/null +++ b/samples/shields/rtk0eg0019b01002bj/src/qe_touch_config.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/************************************************************************************************** + * File Name : qe_touch_config.h + * Description : This file includes definitions. + **************************************************************************************************/ +/************************************************************************************************** + * History : MM/DD/YYYY Version Description + * : 09/02/2019 1.00 First Release + * : 01/16/2020 1.01 Visible CTSU control structure for API using + * : 02/20/2020 1.10 Corresponding for FSP V0.12.0 + * : 02/26/2020 1.11 Adding information for Temperature Correction + * : 03/02/2020 1.20 Corresponding for FSP V1.0.0 RC0 + * : 05/26/2021 1.30 Adding Diagnosis Supporting + * : 07/15/2021 1.31 Fixing a Little + * : 03/31/2023 1.32 Improving Traceability + * : 07/30/2024 1.40 Adding Auto Judgement Supporting + **************************************************************************************************/ +/************************************************************************************************** + * Touch I/F Configuration File : quickstart_rssk_ra2l1_ep.tifcfg + * Tuning Log File : quickstart_rssk_ra2l1_ep_log_tuning20230904134024.log + **************************************************************************************************/ + +#ifndef QE_TOUCH_CONFIG_H +#define QE_TOUCH_CONFIG_H + +#include "hal_data.h" +#include "qe_touch_define.h" + +/************************************************************************************************** + * Exported global variables + **************************************************************************************************/ +extern const ctsu_instance_t g_qe_ctsu_instance_config01; +extern const ctsu_instance_t g_qe_ctsu_instance_config02; +extern const ctsu_instance_t g_qe_ctsu_instance_config03; +extern const touch_instance_t g_qe_touch_instance_config01; +extern const touch_instance_t g_qe_touch_instance_config02; +extern const touch_instance_t g_qe_touch_instance_config03; + +extern volatile uint8_t g_qe_touch_flag; +extern volatile ctsu_event_t g_qe_ctsu_event; + +/************************************************************************************************** + * Exported global functions (to be accessed by other files) + **************************************************************************************************/ +extern void qe_touch_callback(touch_callback_args_t *p_args); + +#endif /* QE_TOUCH_CONFIG_H */ diff --git a/samples/shields/rtk0eg0019b01002bj/src/qe_touch_define.h b/samples/shields/rtk0eg0019b01002bj/src/qe_touch_define.h new file mode 100644 index 000000000000..7f618574e115 --- /dev/null +++ b/samples/shields/rtk0eg0019b01002bj/src/qe_touch_define.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/************************************************************************************************** + * File Name : qe_touch_define.h + * Description : This file includes definitions. + **************************************************************************************************/ +/************************************************************************************************** + * History : MM/DD/YYYY Version Description + * : 09/02/2019 1.00 First Release + * : 12/26/2019 1.10 Corresponding for FSP V0.10.0 + * : 01/16/2020 1.11 Adding "Button State Mask" macros + * : 02/20/2020 1.20 Corresponding for FSP V0.12.0 + * : 03/04/2020 1.21 Corresponding for FSP V1.0.0 RC0 + * : 06/26/2020 1.22 Corresponding for FSP V1.1.0 + * : 09/10/2020 1.30 Corresponding for FSP V2.0.0 Beta2 + * : 05/26/2021 1.40 Adding Diagnosis Supporting + * : 06/01/2021 1.41 Fixing a Little + * : 11/17/2021 1.50 Adding information for Initial Offset Tuning + * : 12/06/2021 1.51 Fixing a Little + * : 09/05/2022 1.52 Fixing a Little + * : 03/23/2023 1.60 Adding 3 Frequency Judgement Supporting + * : 03/31/2023 1.61 Improving Traceability + * : 07/25/2024 1.70 Adding Auto Correction / Auto Multi Clock Correction / MEC + *Supporting : 09/04/2024 1.71 Adding version info macro of QE : 12/06/2024 1.72 Adding macro + *for auto judgment + **************************************************************************************************/ +/************************************************************************************************** + * Touch I/F Configuration File : quickstart_rssk_ra2l1_ep.tifcfg + * Tuning Log File : quickstart_rssk_ra2l1_ep_log_tuning20230904134024.log + **************************************************************************************************/ + +#ifndef QE_TOUCH_DEFINE_H +#define QE_TOUCH_DEFINE_H + +/************************************************************************************************** + * Macro definitions + **************************************************************************************************/ +#define QE_TOUCH_VERSION (0x0410) + +#define CTSU_CFG_NUM_SELF_ELEMENTS (12) + +#define CTSU_CFG_NUM_MUTUAL_ELEMENTS (0) +#define CTSU_CFG_NUM_CFC (0) +#define CTSU_CFG_NUM_CFC_TX (0) + +#define TOUCH_CFG_MONITOR_ENABLE (1) +#define TOUCH_CFG_NUM_BUTTONS (3) +#define TOUCH_CFG_NUM_SLIDERS (1) +#define TOUCH_CFG_NUM_WHEELS (1) +#define TOUCH_CFG_PAD_ENABLE (0) + +#define QE_TOUCH_MACRO_CTSU_IP_KIND (2) + +#define CTSU_CFG_VCC_MV (5000) +#define CTSU_CFG_LOW_VOLTAGE_MODE (0) + +#define CTSU_CFG_PCLK_DIVISION (0) + +#define CTSU_CFG_TSCAP_PORT (0x010C) + +#define CTSU_CFG_NUM_SUMULTI (3) +#define CTSU_CFG_SUMULTI0 (0x3F) +#define CTSU_CFG_SUMULTI1 (0x36) +#define CTSU_CFG_SUMULTI2 (0x48) + +#define CTSU_CFG_CALIB_RTRIM_SUPPORT (0) +#define CTSU_CFG_TEMP_CORRECTION_SUPPORT (0) +#define CTSU_CFG_TEMP_CORRECTION_TS (0) +#define CTSU_CFG_TEMP_CORRECTION_TIME (0) + +#define CTSU_CFG_TARGET_VALUE_QE_SUPPORT (1) + +#define CTSU_CFG_MAJORITY_MODE (1) +#define CTSU_CFG_NUM_AUTOJUDGE_SELF_ELEMENTS (0) +#define CTSU_CFG_NUM_AUTOJUDGE_MUTUAL_ELEMENTS (0) + +/************************************************************************************************** + * Button State Mask for each configuration. + **************************************************************************************************/ +#define CONFIG01_INDEX_BUTTON00 (2) +#define CONFIG01_MASK_BUTTON00 (1ULL << CONFIG01_INDEX_BUTTON00) +#define CONFIG01_INDEX_BUTTON01 (1) +#define CONFIG01_MASK_BUTTON01 (1ULL << CONFIG01_INDEX_BUTTON01) +#define CONFIG01_INDEX_BUTTON02 (0) +#define CONFIG01_MASK_BUTTON02 (1ULL << CONFIG01_INDEX_BUTTON02) + +#endif /* QE_TOUCH_DEFINE_H */ diff --git a/west.yml b/west.yml index 7032362af5ce..1ac3f698bd47 100644 --- a/west.yml +++ b/west.yml @@ -226,7 +226,7 @@ manifest: - hal - name: hal_renesas path: modules/hal/renesas - revision: 0769fe1520f6c14e6301188588da758a609f181d + revision: pull/115/head groups: - hal - name: hal_rpi_pico