Zephyr API Documentation 4.0.0
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
7#ifndef ZEPHYR_INCLUDE_INPUT_H_
8#define ZEPHYR_INCLUDE_INPUT_H_
9
19#include <stdint.h>
20#include <zephyr/device.h>
22#include <zephyr/kernel.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
51
70int input_report(const struct device *dev,
71 uint8_t type, uint16_t code, int32_t value, bool sync,
72 k_timeout_t timeout);
73
80static inline int input_report_key(const struct device *dev,
81 uint16_t code, int32_t value, bool sync,
82 k_timeout_t timeout)
83{
84 return input_report(dev, INPUT_EV_KEY, code, !!value, sync, timeout);
85}
86
92static inline int input_report_rel(const struct device *dev,
93 uint16_t code, int32_t value, bool sync,
94 k_timeout_t timeout)
95{
96 return input_report(dev, INPUT_EV_REL, code, value, sync, timeout);
97}
98
104static inline int input_report_abs(const struct device *dev,
105 uint16_t code, int32_t value, bool sync,
106 k_timeout_t timeout)
107{
108 return input_report(dev, INPUT_EV_ABS, code, value, sync, timeout);
109}
110
119
125 const struct device *dev;
127 void (*callback)(struct input_event *evt, void *user_data);
130};
131
139#define INPUT_CALLBACK_DEFINE_NAMED(_dev, _callback, _user_data, name) \
140 static const STRUCT_SECTION_ITERABLE(input_callback, \
141 _input_callback__##name) = { \
142 .dev = _dev, \
143 .callback = _callback, \
144 .user_data = _user_data, \
145 }
146
158#define INPUT_CALLBACK_DEFINE(_dev, _callback, _user_data) \
159 INPUT_CALLBACK_DEFINE_NAMED(_dev, _callback, _user_data, _callback)
160
161#ifdef __cplusplus
162}
163#endif
164
167#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:80
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:104
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:92
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:412
Input callback structure.
Definition input.h:123
void(* callback)(struct input_event *evt, void *user_data)
The callback function.
Definition input.h:127
void * user_data
User data pointer.
Definition input.h:129
const struct device * dev
device pointer or NULL.
Definition input.h:125
Input event structure.
Definition input.h:36
uint8_t sync
Sync flag.
Definition input.h:40
const struct device * dev
Device generating the event or NULL.
Definition input.h:38
uint16_t code
Event code (see INPUT_KEY_CODES, INPUT_BTN_CODES, INPUT_ABS_CODES, INPUT_REL_CODES,...
Definition input.h:47
int32_t value
Event value.
Definition input.h:49
uint8_t type
Event type (see INPUT_EV_CODES).
Definition input.h:42
Kernel timeout type.
Definition sys_clock.h:65