Skip to content

Conversation

@MichaelOwen2022
Copy link

@MichaelOwen2022 MichaelOwen2022 commented Jul 27, 2022

Input subsystem support api for input devices (like keyboard, touscreen, etc).

Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a comment

Choose a reason for hiding this comment

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

In addition to the problems here, you need to fix your commit logs.

Please watch https://www.youtube.com/watch?v=mnVNLM7ynMQ or at least read the slides for an overview of the contribution process: https://static.sched.com/hosted_files/zephyr2022/a3/HOWTO_Get_Your_Zephyr_Patches_Merged_ZDS_2022.pdf

Copy link
Member

@dcpleung dcpleung left a comment

Choose a reason for hiding this comment

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

Can I suggest to rename this to keyboard instead of just key? This would make it more clear that these are keyboard related stuff.

@str4t0m
Copy link
Contributor

str4t0m commented Aug 22, 2022

Tagging @petejohanson as he might be interested and have some feedback.

@petejohanson
Copy link
Contributor

I think if this is intended just for simple "send a key" uses, this will work, but for anything as complex as https://github.com/zmkfirmware/zmk/ this abstraction would not work for us.

  • ZMK settled on using the existing kscan driver API, and implemented both matrix and direct wire versions. There seems a lot of overlap (potentially) between this new API and kscan.
  • By using KSCAN + GPIO abstraction that exists, our existing matrix driver, for instance, works fine with IO expanders, shift registers, etc. This, in theory, might also be able to do that, but something to be aware of.
  • On the above point this seems to mix a few concerns:
    • Assignment of "key values" to different hardware.
    • Debouncing
    • Hardware details
  • Debounce can actually be complicated, and should ideally not be duplicated. Eager debounce can be used to get key presses sent earlier, and debounce the release instead, etc.

Just a few thoughts, I'll think more and add more when I can.

@MichaelOwen2022
Copy link
Author

@petejohanson @dcpleung
Whether this commit has a chance to be merged?
If this commit doesn't have a chance to merge, I will close this pull request.
If I implement a new input module instand of kscan, userspace use poll mothed to get input events, like linux input subsystem. Is that can be merged?

@dcpleung
Copy link
Member

My issue is simply that setting up the callback should not be done from user thread. It can be done in kernel mode.

@MichaelOwen2022
Copy link
Author

My issue is simply that setting up the callback should not be done from user thread. It can be done in kernel mode.

I mean, If I solve the callback program, is there a chance to merge? this pull request is highly similar to kscan driver.

@dcpleung

@carlescufi
Copy link
Member

@MichaelOwen2022 sorry, this flew under my radar. Could you please rebase?
I've asked for a re-review from the other reviewers.

@mbolivar-nordic mbolivar-nordic requested review from galak and removed request for mbolivar-nordic and rosterloh December 6, 2022 18:10
@mbolivar-nordic mbolivar-nordic dismissed their stale review December 6, 2022 18:11

no longer working on dt bindings

Michael Owen added 3 commits December 17, 2022 17:04
Input subsystem support public API for input device.

Signed-off-by: Michael Owen <[email protected]>
This driver scan gpio keyboard status,
and report key event to input subsystem.

Signed-off-by: Michael Owen <[email protected]>
This sample use input api to get gpio keyboard event.

Signed-off-by: Michael Owen <[email protected]>
@MichaelOwen2022
Copy link
Author

@MichaelOwen2022 sorry, this flew under my radar. Could you please rebase? I've asked for a re-review from the other reviewers.

I've rebase already.

Copy link
Contributor

@tbursztyka tbursztyka left a comment

Choose a reason for hiding this comment

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

Input is a way too generic name, a keyboard being one of the many input devices (and we already have kscan for this).
Hard to see how this could be used for a mouse, or else...


#include "input_internal.h"

int input_internal_setup(struct input_dev *dev)
Copy link
Contributor

Choose a reason for hiding this comment

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

From one input device stand-point: are you going to call this more than once at runtime?

If not, then all of this can be integrated into a macro with relevant static intialization for each objects (rb, mutex, sem...)

*/
__syscall int input_setup(const struct device *dev);

static inline int z_impl_input_setup(const struct device *dev)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't this be done at device initialization? (see previous comment)

*/
__syscall int input_event_read(const struct device *dev, struct input_event *event);

static inline int z_impl_input_event_read(const struct device *dev, struct input_event *event)
Copy link
Contributor

Choose a reason for hiding this comment

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

as noted already, adding asynchronous input API would be a must here.

KEY_EVENT_NONE = 0xff,
};

struct kbd_gpio_driver {
Copy link
Contributor

Choose a reason for hiding this comment

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

weird naming, the whole code in keyboard_gpio.c is the driver.
Actually I don't see the point of not including of these attributes into kbd_gpio_data

struct input_dev *input = data->input;
int retval = 0;

retval = input_internal_attr_get(input, type, attr);
Copy link
Contributor

Choose a reason for hiding this comment

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

retval seems superfluous, just return from the called input_* function

struct input_dev *input = data->input;
int retval = 0;

retval = input_internal_attr_set(input, type, attr);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

struct input_dev *input = data->input;
int retval = 0;

retval = input_internal_event_read(input, event);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

struct input_dev *input = data->input;
int retval = 0;

retval = input_internal_event_write(input, event);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

*/
__syscall int input_release(const struct device *dev);

static inline int z_impl_input_release(const struct device *dev)
Copy link
Contributor

Choose a reason for hiding this comment

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

what would be the use case for this function?

Like the setup above. It seems to bring concepts (pluggin in/out a keyboard? pm perhaps?) to the user level that should not be its role to manage. Which is not the right way.

@MichaelOwen2022
Copy link
Author

Input is a way too generic name, a keyboard being one of the many input devices (and we already have kscan for this). Hard to see how this could be used for a mouse, or else...

With all due respect, I don't think you're good enough to understand this input subsysem framework.

* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT keyboard_gpio
Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't know why this isn't done as a kscan driver, and this input system doesn't have a mapping to consume a kscan driver and map to input system events.

Copy link
Author

Choose a reason for hiding this comment

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

I don't think you understand enough of this input subsystem framework either.

continue;
}

err = gpio_pin_interrupt_configure_dt(gpio, GPIO_INT_EDGE_TO_ACTIVE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not all gpio pins support interrupts. This will have limitations and only work on certain hardware configurations.

Also, using edge to active interrupt won't allow deep sleep/wake from deep sleep on nRF52.

enum keyboard_value {
KEY_RELEASE,
KEY_PRESSED,
KEY_LONG_PRESSED,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these added. As soon as you have long press/release, why not support double tap? Triple?

If the goal is a "lowest common denominator" API good enough for basic input to programs, this is probably fine.

I think maybe this is my disconnect, I come from developing featureful input devices.

If the goal of this API is to focus on the consumers of input data, then we should clearly document that, since the current system doesn't seem to be flexible/powerful enough to handle the other.


/* keyboard code */

#define KEY_CODE_RESERVED 0
Copy link
Contributor

Choose a reason for hiding this comment

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

The current code set may be fine for a basic sample program, but definitely won't allow a complex system that covers the full range of possible keyboard codes, other possible layouts/languages, etc.

#define KEY_CODE_Y 89
#define KEY_CODE_Z 90

#define KEY_CODE_KP0 96
Copy link
Contributor

Choose a reason for hiding this comment

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

There's far more keypad codes than these.

@MichaelOwen2022
Copy link
Author

It's been a few months since this commit and the code review that followed was disappointing. I can't speak highly of the entire zephyr team and have no interest in committing anything on this project.

@MichaelOwen2022
Copy link
Author

It's no fun to waste time with a bunch of elementary school students。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.