Zephyr Project API 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
input.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
13#ifndef ZEPHYR_INCLUDE_INPUT_H_
14#define ZEPHYR_INCLUDE_INPUT_H_
15
30#include <stdint.h>
31#include <zephyr/device.h>
33#include <zephyr/kernel.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
62
81int input_report(const struct device *dev,
82 uint8_t type, uint16_t code, int32_t value, bool sync,
83 k_timeout_t timeout);
84
91static inline int input_report_key(const struct device *dev,
92 uint16_t code, int32_t value, bool sync,
93 k_timeout_t timeout)
94{
95 return input_report(dev, INPUT_EV_KEY, code, !!value, sync, timeout);
96}
97
103static inline int input_report_rel(const struct device *dev,
104 uint16_t code, int32_t value, bool sync,
105 k_timeout_t timeout)
106{
107 return input_report(dev, INPUT_EV_REL, code, value, sync, timeout);
108}
109
115static inline int input_report_abs(const struct device *dev,
116 uint16_t code, int32_t value, bool sync,
117 k_timeout_t timeout)
118{
119 return input_report(dev, INPUT_EV_ABS, code, value, sync, timeout);
120}
121
130
136 const struct device *dev;
138 void (*callback)(struct input_event *evt, void *user_data);
141};
142
150#define INPUT_CALLBACK_DEFINE_NAMED(_dev, _callback, _user_data, name) \
151 static const STRUCT_SECTION_ITERABLE(input_callback, \
152 _input_callback__##name) = { \
153 .dev = _dev, \
154 .callback = _callback, \
155 .user_data = _user_data, \
156 }
157
169#define INPUT_CALLBACK_DEFINE(_dev, _callback, _user_data) \
170 INPUT_CALLBACK_DEFINE_NAMED(_dev, _callback, _user_data, _callback)
171
172#ifdef __cplusplus
173}
174#endif
175
178#endif /* ZEPHYR_INCLUDE_INPUT_H_ */
#define INPUT_EV_REL
Relative coordinate event.
Definition input-event-codes.h:26
#define INPUT_EV_KEY
Key event.
Definition input-event-codes.h:25
#define INPUT_EV_ABS
Absolute coordinate event.
Definition input-event-codes.h:27
bool input_queue_empty(void)
Returns true if the input queue is empty.
static int input_report_key(const struct device *dev, uint16_t code, int32_t value, bool sync, k_timeout_t timeout)
Report a new INPUT_EV_KEY input event, note that value is converted to either 0 or 1.
Definition input.h:91
static int input_report_abs(const struct device *dev, uint16_t code, int32_t value, bool sync, k_timeout_t timeout)
Report a new INPUT_EV_ABS input event.
Definition input.h:115
int input_report(const struct device *dev, uint8_t type, uint16_t code, int32_t value, bool sync, k_timeout_t timeout)
Report a new input event.
static int input_report_rel(const struct device *dev, uint16_t code, int32_t value, bool sync, k_timeout_t timeout)
Report a new INPUT_EV_REL input event.
Definition input.h:103
Public kernel APIs.
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
Input callback structure.
Definition input.h:134
void(* callback)(struct input_event *evt, void *user_data)
The callback function.
Definition input.h:138
void * user_data
User data pointer.
Definition input.h:140
const struct device * dev
device pointer or NULL.
Definition input.h:136
Input event structure.
Definition input.h:47
uint8_t sync
Sync flag.
Definition input.h:51
const struct device * dev
Device generating the event or NULL.
Definition input.h:49
uint16_t code
Event code (see INPUT_KEY_CODES, INPUT_BTN_CODES, INPUT_ABS_CODES, INPUT_REL_CODES,...
Definition input.h:58
int32_t value
Event value.
Definition input.h:60
uint8_t type
Event type (see INPUT_EV_CODES).
Definition input.h:53
Kernel timeout type.
Definition clock.h:65