Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
17#include <stdint.h>
18#include <zephyr/device.h>
20#include <zephyr/kernel.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
36 const struct device *dev;
48};
49
68int input_report(const struct device *dev,
69 uint8_t type, uint16_t code, int32_t value, bool sync,
70 k_timeout_t timeout);
71
78static inline int input_report_key(const struct device *dev,
79 uint16_t code, int32_t value, bool sync,
80 k_timeout_t timeout)
81{
82 return input_report(dev, INPUT_EV_KEY, code, !!value, sync, timeout);
83}
84
90static inline int input_report_rel(const struct device *dev,
91 uint16_t code, int32_t value, bool sync,
92 k_timeout_t timeout)
93{
94 return input_report(dev, INPUT_EV_REL, code, value, sync, timeout);
95}
96
102static inline int input_report_abs(const struct device *dev,
103 uint16_t code, int32_t value, bool sync,
104 k_timeout_t timeout)
105{
106 return input_report(dev, INPUT_EV_ABS, code, value, sync, timeout);
107}
108
117
123 const struct device *dev;
125 void (*callback)(struct input_event *evt);
126};
127
138#define INPUT_CALLBACK_DEFINE(_dev, _callback) \
139 static const STRUCT_SECTION_ITERABLE(input_listener, \
140 _input_listener__##_callback) = { \
141 .dev = _dev, \
142 .callback = _callback, \
143 }
144
145#ifdef __cplusplus
146}
147#endif
148
151#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:78
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:102
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:90
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:381
Input event structure.
Definition: input.h:34
uint8_t sync
Sync flag.
Definition: input.h:38
const struct device * dev
Device generating the event or NULL.
Definition: input.h:36
uint16_t code
Event code (see INPUT_KEY_CODES, INPUT_BTN_CODES, INPUT_ABS_CODES, INPUT_REL_CODES,...
Definition: input.h:45
int32_t value
Event value.
Definition: input.h:47
uint8_t type
Event type (see INPUT_EV_CODES).
Definition: input.h:40
Input listener callback structure.
Definition: input.h:121
void(* callback)(struct input_event *evt)
The callback function.
Definition: input.h:125
const struct device * dev
device pointer or NULL.
Definition: input.h:123
Kernel timeout type.
Definition: sys_clock.h:65