Skip to content

Commit 5d3ce19

Browse files
committed
samples: shields: add rtk0eg0019b01002bj sample
First commit to add rtk0eg0019b01002bj shield sample Signed-off-by: The Nguyen <the.nguyen.yf@renesas.com>
1 parent bb76692 commit 5d3ce19

File tree

8 files changed

+952
-0
lines changed

8 files changed

+952
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(rtk0eg0019b01002bj)
7+
8+
target_sources(app PRIVATE src/main.c)
9+
10+
if(CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG)
11+
zephyr_include_directories(src)
12+
zephyr_sources(src/qe_touch_config.c)
13+
endif()
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
.. zephyr:code-sample:: rtk0eg0019b01002bj
2+
:name: RTK0EG0019B01002BJ Capacitive Touch Application Shield
3+
:relevant-api: input_events
4+
5+
Interact with the Capacitive Touch Sensor and LED matrix on the RTK0EG0019B01002BJ shield
6+
7+
Overview
8+
********
9+
10+
This sample demonstrates the usage of the Capacitive Touch Sensor using the
11+
:ref:`rtk0eg0019b01002bj` with `Renesas Capacitive Touch Sensor Solutions`_.
12+
13+
Requirements
14+
************
15+
16+
A Renesas Capacitive Touch Evaluation Kit is needed to run this sample. It includes:
17+
18+
- A MCU board which support CTSU driver (for example: RSSK-RA2L1).
19+
- A RTK0EG0019B01002BJ Touch Application board.
20+
21+
Building and Running
22+
********************
23+
24+
Build and flash with default settings for shield
25+
================================================
26+
The :ref:`rtk0eg0019b01002bj` comes with a default DTS configuration that is tuned in advance to
27+
make it ready for development.
28+
29+
Build and flash as follows, changing ``rssk_ra2l1`` for your board:
30+
31+
.. zephyr-app-commands::
32+
:zephyr-app: samples/shields/rtk0eg0019b01002bj
33+
:board: rssk_ra2l1
34+
:shield: rtk0eg0019b01002bj
35+
:goals: build flash
36+
:compact:
37+
38+
After startup, all LEDs on the shield will blink 5 times to indicate that the
39+
application has started.
40+
41+
You can monitor input events through the console output. Additionally, the LED
42+
corresponding to the touched sensor will turn on when you touch it.
43+
44+
.. code-block:: console
45+
46+
*** Booting Zephyr OS build v4.1.0-6697-gdc27367ff627 ***
47+
rtk0eg0019b01002bj sample started
48+
I: input event: dev=button1 type= 1 code= 11 value=0
49+
I: input event: dev=wheel type= 3 code= 8 value=61
50+
I: input event: dev=wheel type= 3 code= 8 value=67
51+
I: input event: dev=wheel type= 3 code= 8 value=82
52+
I: input event: dev=wheel type= 3 code= 8 value=111
53+
I: input event: dev=wheel type= 3 code= 8 value=124
54+
I: input event: dev=wheel type= 3 code= 8 value=134
55+
I: input event: dev=slider type= 3 code= 6 value=0
56+
I: input event: dev=slider type= 3 code= 6 value=2
57+
I: input event: dev=slider type= 3 code= 6 value=4
58+
I: input event: dev=slider type= 3 code= 6 value=6
59+
I: input event: dev=slider type= 3 code= 6 value=10
60+
I: input event: dev=slider type= 3 code= 6 value=23
61+
I: input event: dev=slider type= 3 code= 6 value=26
62+
I: input event: dev=slider type= 3 code= 6 value=27
63+
I: input event: dev=slider type= 3 code= 6 value=28
64+
65+
(Advanced) Using Configuration Output Generated by Renesas QE Capacitive Touch Workflow
66+
=======================================================================================
67+
This section is for advanced users who do not want to use the default configuration for the Cap
68+
Touch shield and would like to tune configuration parameters manually themselves using the
69+
`Renesas Development Assistance Tool for Capacitive Touch Sensors`_.
70+
71+
Requirements
72+
------------
73+
74+
- `e² studio`_ with Renesas QE Capacitive Touch plugin installed: recommended 2025-04.1 version
75+
- `RA Flexible Software Package`_: recommended FSP v5.8.0 or newer
76+
77+
Building and flashing with generated tuning code
78+
------------------------------------------------
79+
80+
1. Follow steps 6.1 to 6.5 of `Using QE and FSP to Develop Capacitive Touch Applications`_.
81+
82+
2. At step 8 in 6.5 Tuning the Capacitive Touch Interface Using QE for Capacitive Touch Plug-in,
83+
select 'Specify an output folder' and choose this application's subfolder.
84+
85+
3. Update the include path to qe_touch_config.h and qe_touch_define.h, and add qe_touch_config.c
86+
to the build sources in your application's CMake.
87+
88+
4. Build and flash the application with the command below:
89+
90+
.. zephyr-app-commands::
91+
:zephyr-app: samples/shields/rtk0eg0019b01002bj
92+
:board: rssk_ra2l1
93+
:shield: rtk0eg0019b01002bj
94+
:gen-args: -DCONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG=y
95+
:goals: build flash
96+
:compact:
97+
98+
References
99+
**********
100+
- `Renesas Capacitive Touch Sensor Solutions`_
101+
- `Renesas Development Assistance Tool for Capacitive Touch Sensors`_
102+
103+
.. _Renesas Capacitive Touch Sensor Solutions:
104+
https://www.renesas.com/en/key-technologies/hmi/capacitive-touch-sensor-solutions
105+
106+
.. _Renesas Development Assistance Tool for Capacitive Touch Sensors:
107+
https://www.renesas.com/en/software-tool/qe-capacitive-touch-development-assistance-tool-capacitive-touch-sensors
108+
109+
.. _Using QE and FSP to Develop Capacitive Touch Applications:
110+
https://www.renesas.com/en/document/apn/using-qe-and-fsp-develop-capacitive-touch-applications?r=1170071
111+
112+
.. _e² studio:
113+
https://www.renesas.com/en/software-tool/e-studio
114+
115+
.. _RA Flexible Software Package:
116+
https://www.renesas.com/en/software-tool/flexible-software-package
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_LOG=y
5+
CONFIG_LOG_MODE_MINIMAL=y
6+
7+
CONFIG_INPUT=y
8+
CONFIG_INPUT_EVENT_DUMP=y
9+
CONFIG_GPIO=y
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sample:
2+
name: RTK0EG0019B01002BJ Capacitive Touch Application Shield
3+
tests:
4+
sample.shields.rtk0eg0019b01002bj:
5+
harness: shield
6+
tags: shield
7+
platform_allow:
8+
- rssk_ra2l1
9+
extra_args: SHIELD=rtk0eg0019b01002bj
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdint.h>
8+
#include <zephyr/device.h>
9+
#include <zephyr/drivers/gpio.h>
10+
#include <zephyr/input/input.h>
11+
#include <zephyr/input/input_renesas_ra_ctsu.h>
12+
#include <zephyr/sys/printk.h>
13+
14+
#ifdef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG
15+
#include "qe_touch_config.h"
16+
#endif /* CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG*/
17+
18+
#define LED_MATRIX DT_NODELABEL(rtk0eg0019b01002bj_led_matrix)
19+
#define BUTTON1 DT_NODELABEL(rtk0eg0019b01002bj_bt1)
20+
#define BUTTON2 DT_NODELABEL(rtk0eg0019b01002bj_bt2)
21+
#define BUTTON3 DT_NODELABEL(rtk0eg0019b01002bj_bt3)
22+
#define SLIDER DT_NODELABEL(rtk0eg0019b01002bj_slider)
23+
#define WHEEL DT_NODELABEL(rtk0eg0019b01002bj_wheel)
24+
25+
#define QE_TOUCH_CFG1 DT_CHILD(DT_NODELABEL(rtk0eg0019b01002bj_ctsu), group1)
26+
#define QE_TOUCH_CFG2 DT_CHILD(DT_NODELABEL(rtk0eg0019b01002bj_ctsu), group2)
27+
#define QE_TOUCH_CFG3 DT_CHILD(DT_NODELABEL(rtk0eg0019b01002bj_ctsu), group3)
28+
29+
#define NUM_ROWS DT_PROP(LED_MATRIX, num_rows)
30+
#define NUM_COLS DT_PROP(LED_MATRIX, num_cols)
31+
32+
#define LED_MATRIX_ROWS(idx, nodeid) GPIO_DT_SPEC_GET_BY_IDX(nodeid, led_row_gpios, idx)
33+
#define LED_MATRIX_COLS(idx, nodeid) GPIO_DT_SPEC_GET_BY_IDX(nodeid, led_col_gpios, idx)
34+
35+
#define BUTTON_LED_NUM (3U)
36+
37+
#define SLIDER_LED_NUM (5U)
38+
#define SLIDER_RESOLUTION (100)
39+
40+
#define WHEEL_LED_NUM (8U)
41+
#define WHEEL_RESOLUTION_DEGREE (360)
42+
43+
static const struct gpio_dt_spec led_row[NUM_ROWS] = {
44+
LISTIFY(NUM_ROWS, LED_MATRIX_ROWS, (,), LED_MATRIX),
45+
};
46+
47+
static const struct gpio_dt_spec led_col[NUM_COLS] = {
48+
LISTIFY(NUM_COLS, LED_MATRIX_COLS, (,), LED_MATRIX),
49+
};
50+
51+
static const unsigned int wheel_leds_lut[WHEEL_LED_NUM] = {0, 1, 2, 3, 4, 5, 6, 7};
52+
static const unsigned int slider_leds_lut[SLIDER_LED_NUM] = {8, 9, 10, 11, 12};
53+
static const unsigned int button_leds_lut[BUTTON_LED_NUM] = {13, 14, 15};
54+
55+
static void rtk0eg0019b01002bj_led_output(unsigned int led_idx, bool on)
56+
{
57+
/* Refer to RTK0EG0022S01001BJ - Design Package for the Touch Application board layout */
58+
static const unsigned int led_map[NUM_ROWS * NUM_COLS][2] = {
59+
{0, 0}, {1, 0}, {2, 0}, {3, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1},
60+
{0, 3}, {1, 3}, {2, 3}, {3, 3}, {0, 2}, {1, 2}, {2, 2}, {3, 2},
61+
};
62+
const struct gpio_dt_spec *p_led_row = &led_row[led_map[led_idx][0]];
63+
const struct gpio_dt_spec *p_led_col = &led_col[led_map[led_idx][1]];
64+
65+
gpio_pin_set_dt(p_led_row, on ? 1 : 0);
66+
gpio_pin_set_dt(p_led_col, on ? 1 : 0);
67+
}
68+
69+
static void rtk0eg0019b01002bj_led_init(void)
70+
{
71+
for (int i = 0; i < NUM_ROWS; i++) {
72+
gpio_pin_configure_dt(&led_row[i], GPIO_OUTPUT_INACTIVE);
73+
}
74+
75+
for (int i = 0; i < NUM_COLS; i++) {
76+
gpio_pin_configure_dt(&led_col[i], GPIO_OUTPUT_INACTIVE);
77+
}
78+
}
79+
80+
static void blink_leds(unsigned int duration_ms)
81+
{
82+
for (int i = 0; i < 5; i++) {
83+
/* Turn all LEDs ON */
84+
for (int j = 0; j < NUM_ROWS * NUM_COLS; j++) {
85+
rtk0eg0019b01002bj_led_output(j, true);
86+
}
87+
k_msleep(duration_ms);
88+
89+
/* Turn all LEDs OFF */
90+
for (int j = 0; j < NUM_ROWS * NUM_COLS; j++) {
91+
rtk0eg0019b01002bj_led_output(j, false);
92+
}
93+
k_msleep(duration_ms);
94+
}
95+
}
96+
97+
static inline unsigned int wheel_get_current_step(unsigned int value)
98+
{
99+
return (value * WHEEL_LED_NUM) / WHEEL_RESOLUTION_DEGREE;
100+
}
101+
102+
static inline unsigned int slider_get_current_step(unsigned int value)
103+
{
104+
return (value * SLIDER_LED_NUM) / SLIDER_RESOLUTION;
105+
}
106+
107+
static void rtk0eg0019b01002bj_evt_handler(struct input_event *evt, void *user_data)
108+
{
109+
unsigned int led_idx;
110+
111+
/* Set all LEDs to OFF */
112+
for (int i = 0; i < NUM_ROWS * NUM_COLS; i++) {
113+
rtk0eg0019b01002bj_led_output(i, false);
114+
}
115+
116+
switch (evt->code) {
117+
case INPUT_KEY_0: {
118+
led_idx = button_leds_lut[0];
119+
break;
120+
}
121+
case INPUT_KEY_1: {
122+
led_idx = button_leds_lut[1];
123+
break;
124+
}
125+
case INPUT_KEY_2: {
126+
led_idx = button_leds_lut[2];
127+
break;
128+
}
129+
case INPUT_ABS_WHEEL: {
130+
led_idx = wheel_get_current_step(evt->value) + wheel_leds_lut[0];
131+
break;
132+
}
133+
case INPUT_ABS_THROTTLE: {
134+
led_idx = slider_get_current_step(evt->value) + slider_leds_lut[0];
135+
break;
136+
}
137+
default:
138+
/* Unexpected event */
139+
return;
140+
}
141+
142+
rtk0eg0019b01002bj_led_output(led_idx, true);
143+
}
144+
145+
INPUT_CALLBACK_DEFINE_NAMED(DEVICE_DT_GET(BUTTON1), rtk0eg0019b01002bj_evt_handler, NULL, button1);
146+
INPUT_CALLBACK_DEFINE_NAMED(DEVICE_DT_GET(BUTTON2), rtk0eg0019b01002bj_evt_handler, NULL, button2);
147+
INPUT_CALLBACK_DEFINE_NAMED(DEVICE_DT_GET(BUTTON3), rtk0eg0019b01002bj_evt_handler, NULL, button3);
148+
INPUT_CALLBACK_DEFINE_NAMED(DEVICE_DT_GET(SLIDER), rtk0eg0019b01002bj_evt_handler, NULL, slider);
149+
INPUT_CALLBACK_DEFINE_NAMED(DEVICE_DT_GET(WHEEL), rtk0eg0019b01002bj_evt_handler, NULL, wheel);
150+
151+
int main(void)
152+
{
153+
#ifdef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG
154+
const struct device *qe_touch_cfg1 = DEVICE_DT_GET(QE_TOUCH_CFG1);
155+
const struct device *qe_touch_cfg2 = DEVICE_DT_GET(QE_TOUCH_CFG2);
156+
const struct device *qe_touch_cfg3 = DEVICE_DT_GET(QE_TOUCH_CFG3);
157+
int ret;
158+
#endif
159+
rtk0eg0019b01002bj_led_init();
160+
161+
/* Blink all leds 5 times, each time is 200ms */
162+
blink_leds(200);
163+
164+
#ifdef CONFIG_INPUT_RENESAS_RA_QE_TOUCH_CFG
165+
ret = renesas_ra_ctsu_group_configure(
166+
qe_touch_cfg1, (struct renesas_ra_ctsu_touch_cfg *)&g_qe_touch_instance_config01);
167+
if (ret < 0) {
168+
printk("Failed to configure QE Touch Group 1: %d\n", ret);
169+
return ret;
170+
}
171+
172+
ret = renesas_ra_ctsu_group_configure(
173+
qe_touch_cfg2, (struct renesas_ra_ctsu_touch_cfg *)&g_qe_touch_instance_config02);
174+
if (ret < 0) {
175+
printk("Failed to configure QE Touch Group 2: %d\n", ret);
176+
return ret;
177+
}
178+
179+
ret = renesas_ra_ctsu_group_configure(
180+
qe_touch_cfg3, (struct renesas_ra_ctsu_touch_cfg *)&g_qe_touch_instance_config03);
181+
if (ret < 0) {
182+
printk("Failed to configure QE Touch Group 3: %d\n", ret);
183+
return ret;
184+
}
185+
#endif
186+
187+
printk("rtk0eg0019b01002bj sample started\n");
188+
return 0;
189+
}

0 commit comments

Comments
 (0)