Skip to content

drivers: input: add support for Renesas CTSU #92433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

thenguyenyf
Copy link
Contributor

This PR to add Input subsys support on Renesas CTSU HWIP

Update rev of hal_renesas to add support for CTSU

Signed-off-by: The Nguyen <the.nguyen.yf@renesas.com>
@github-actions github-actions bot added area: Input Input Subsystem and Drivers area: Pinctrl platform: Renesas RA Renesas Electronics Corporation, RA labels Jul 1, 2025
Copy link

github-actions bot commented Jul 1, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_renesas zephyrproject-rtos/hal_renesas@0769fe1 zephyrproject-rtos/hal_renesas#115 zephyrproject-rtos/hal_renesas#115/files

DNM label due to: 1 project with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added manifest manifest-hal_renesas DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Jul 1, 2025
@thenguyenyf thenguyenyf force-pushed the renesas_ra_ctsu_driver_support branch from 203be5e to c26a69a Compare July 1, 2025 09:29
@fabiobaltieri
Copy link
Member

Woops, added few comments on #92434, should have probably done it here, could you pick the initial comments from there? Sorry for the confusion.

Copy link
Contributor Author

@thenguyenyf thenguyenyf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabiobaltieri Move conversion from #92434 due to this PR should be the correct place for review

threshold = <769>;
hysteresis = <38>;
event-code = <INPUT_KEY_0>;
status = "okay";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#92434 (comment)

I understood that a status = "okay"; is not necessary in the node example for documentation, right? If its correct, I will remove it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also not necessary in the first place unless you are overriding a node that has been defined with status disabled, typically these would be the basic SoC device nodes defined under soc/ and enabled from boards/, but for these pseudo-device node things that are defined in board without overriding anything you don't need to set the status, they are enabled by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood. I will remove the status from the documentation and the board/shield dts

#define K_POLLING K_MSEC(CONFIG_INPUT_RENESAS_RA_CTSU_POLLING_INTERVAL_MS)
#define K_STABILIZATION K_USEC(CONFIG_INPUT_RENESAS_RA_CTSU_STABILIZATION_TIME_US)

static ALWAYS_INLINE void renesas_ra_ctsu_drv_handler(void *arg0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#92434 (comment)
#92434 (comment)

I refer it from some skeleton code that exist in Zephyr repo (ex: udc_skeleton.c). So, if it's not good/suitable for this driver, I will change as your suggestion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't bother unless you know that it is actually making a difference

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so back on this one, I'd suggest

  • drop the ALWAYS_INLINE
  • add the extra 2 dummy argument, drop the renesas_ra_ctsu_thread##inst generated wrapper and call this directly from k_thread_create

@fabiobaltieri
Copy link
Member

Thanks for porting the comments over from the other PR

@thenguyenyf thenguyenyf force-pushed the renesas_ra_ctsu_driver_support branch from c26a69a to 2d79335 Compare July 4, 2025 06:31
}; \
\
DEVICE_DT_INST_DEFINE(inst, ctsu_device_init, NULL, NULL, &ctsu_button_cfg##inst, \
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL);))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you formatting manually? I'd move the )) down a line and at the same indentation as the IF_ENABLED, this is a bit hard to follow as it is

#define K_POLLING K_MSEC(CONFIG_INPUT_RENESAS_RA_CTSU_POLLING_INTERVAL_MS)
#define K_STABILIZATION K_USEC(CONFIG_INPUT_RENESAS_RA_CTSU_STABILIZATION_TIME_US)

static ALWAYS_INLINE void renesas_ra_ctsu_drv_handler(void *arg0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so back on this one, I'd suggest

  • drop the ALWAYS_INLINE
  • add the extra 2 dummy argument, drop the renesas_ra_ctsu_thread##inst generated wrapper and call this directly from k_thread_create

Comment on lines 570 to 579
static void renesas_ra_ctsu_make_thread##inst(const struct device *dev) \
{ \
struct renesas_ra_ctsu_data *data = dev->data; \
\
k_thread_create(&data->thread_data, renesas_ra_ctsu_drv_stack##inst, \
K_THREAD_STACK_SIZEOF(renesas_ra_ctsu_drv_stack##inst), \
renesas_ra_ctsu_thread##inst, (void *)dev, NULL, NULL, \
K_PRIO_COOP(CTSU_DRV_THREAD_PRIORITY), K_ESSENTIAL, K_NO_WAIT); \
k_thread_name_set(&data->thread_data, dev->name); \
} \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this wrapper, declare the stack as part of renesas_ra_ctsu_data and move this code directly in renesas_ra_ctsu_init, you can check out input_analog_axis.c for reference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I moved stack memory into data structure.

PINCTRL_DT_INST_DEFINE(inst); \
K_THREAD_STACK_DEFINE(renesas_ra_ctsu_drv_stack##inst, CTSU_DRV_THREAD_STACK_SIZE); \
\
static void renesas_ra_ctsu_thread##inst(void *dev, void *arg1, void *arg2) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this wrapper, see the comment above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The thread creation was called directly in init() function.

const struct ctsu_device_cfg *cfg = dev->config;
uint16_t *p_data = data;

if (p_data != NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swap the condition, normal execution inline

if (p_data == NULL) {
        return;
}

input_report_abs(...);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 164 to 171
if (cfg->num_button > 0) {
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);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about refactoring this and the two below in their own functions? flag those as maybe_unused, have an early return for

if (cfg->num_button == 0) {
        return;
}

so you have one less indentation level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. 3 new reading function was created for buttons, wheels and sliders

@thenguyenyf thenguyenyf force-pushed the renesas_ra_ctsu_driver_support branch 2 times, most recently from 5331c27 to 07d5949 Compare July 14, 2025 03:42
First commit to add support for Renesas RA Capasitive Sensing Unit

Signed-off-by: The Nguyen <the.nguyen.yf@renesas.com>
Add CTSU pin function selection for Renesas RA devices

Signed-off-by: The Nguyen <the.nguyen.yf@renesas.com>
Add device node support for Renesas RA SoCs

Signed-off-by: The Nguyen <the.nguyen.yf@renesas.com>
Enable support for CTSU button on ek_ra2a1 board

Signed-off-by: The Nguyen <the.nguyen.yf@renesas.com>
@thenguyenyf thenguyenyf force-pushed the renesas_ra_ctsu_driver_support branch from 07d5949 to 0c1eaa3 Compare July 14, 2025 04:17
Copy link

Copy link
Member

@fabiobaltieri fabiobaltieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple more comments, then I guess this is waiting for the hal PR to be reviewed, can you get it approved by someone else working on renesas? then I can merge it

{
ARG_UNUSED(arg1);
ARG_UNUSED(arg2);
const struct device *ctsu_dev = (const struct device *)arg0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the casting, arg0 is a void * there's nothing the compiler can check for you

Comment on lines +175 to +195
#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) */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the #if condition inside the function body and let it be a no-op when this is not enabled, then you can remove the conditionals from renesas_ra_ctsu_group_reading_handler and always call these, they'll just get optimized out when they are not needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Input Input Subsystem and Drivers area: Pinctrl DNM (manifest) This PR should not be merged (controlled by action-manifest) manifest manifest-hal_renesas platform: Renesas RA Renesas Electronics Corporation, RA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants