PebbleOS
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions

Input events from drivers to the listeners that consume them. More...

Data Structures

struct  pbl_input_event
 Input event. More...
 
struct  pbl_input_callback
 Listener of input events. More...
 

Macros

#define PBL_INPUT_CALLBACK_DEFINE(_callback, _user_data)
 Define a listener of every input event.
 

Enumerations

enum  pbl_input_type : uint8_t { PBL_INPUT_EV_KEY , PBL_INPUT_EV_ABS , PBL_INPUT_EV_GES }
 Event type. More...
 
enum  : uint16_t {
  PBL_INPUT_KEY_BACK , PBL_INPUT_KEY_UP , PBL_INPUT_KEY_SELECT , PBL_INPUT_KEY_DOWN ,
  PBL_INPUT_BTN_TOUCH
}
 PBL_INPUT_EV_KEY codes. More...
 
enum  : uint16_t { PBL_INPUT_ABS_X , PBL_INPUT_ABS_Y }
 PBL_INPUT_EV_ABS codes. More...
 
enum  : uint16_t { PBL_INPUT_GES_TAP , PBL_INPUT_GES_DOUBLE_TAP , PBL_INPUT_GES_PALM }
 PBL_INPUT_EV_GES codes, located at the report's PBL_INPUT_ABS_X and Y. More...
 

Functions

void pbl_input_report (enum pbl_input_type type, uint16_t code, int32_t value, bool sync)
 Report an input event to every listener.
 
static void pbl_input_report_key (uint16_t code, bool pressed, bool sync)
 Report a key event.
 
static void pbl_input_report_abs (uint16_t code, int32_t value, bool sync)
 Report an absolute axis event.
 
static void pbl_input_report_ges (uint16_t code, bool sync)
 Report a gesture event.
 

Detailed Description

Input events from drivers to the listeners that consume them.

Drivers report events with pbl_input_report() and know nothing about who consumes them. Listeners are defined with PBL_INPUT_CALLBACK_DEFINE() next to the code they drive, collected at link time, and called synchronously in the context of the report, which is an ISR for buttons. Listeners must therefore not block, and must check pbl_in_isr() before using APIs that are not ISR-safe.

A report is a group of events closed by one with sync set, such as a touch sample:

static void pbl_input_report_abs(uint16_t code, int32_t value, bool sync)
Report an absolute axis event.
Definition input.h:145
static void pbl_input_report_key(uint16_t code, bool pressed, bool sync)
Report a key event.
Definition input.h:134
@ PBL_INPUT_ABS_X
Definition input.h:65
@ PBL_INPUT_ABS_Y
Definition input.h:66
@ PBL_INPUT_BTN_TOUCH
Touch contact.
Definition input.h:60
static void prv_input_cb(const struct pbl_input_event *evt, void *user_data) {
if (evt->type == PBL_INPUT_EV_KEY && evt->code == PBL_INPUT_KEY_BACK && evt->value) {
...
}
}
PBL_INPUT_CALLBACK_DEFINE(prv_input_cb, NULL);
int32_t value
Value, depending on type.
Definition input.h:85
enum pbl_input_type type
Type.
Definition input.h:79
uint16_t code
Code, depending on type.
Definition input.h:83
Input event.
Definition input.h:77
#define PBL_INPUT_CALLBACK_DEFINE(_callback, _user_data)
Define a listener of every input event.
Definition input.h:107
@ PBL_INPUT_EV_KEY
Key or button, value 1 when pressed and 0 when released.
Definition input.h:46
@ PBL_INPUT_KEY_BACK
Definition input.h:55

Data Structure Documentation

◆ pbl_input_event

struct pbl_input_event

Input event.

Data Fields
uint16_t code Code, depending on type.
bool sync Last event of a report.
enum pbl_input_type type Type.
int32_t value Value, depending on type.

Macro Definition Documentation

◆ PBL_INPUT_CALLBACK_DEFINE

#define PBL_INPUT_CALLBACK_DEFINE (   _callback,
  _user_data 
)
Value:
static const struct pbl_input_callback pbl_input_callback_##_callback PBL_USED PBL_ALIGNED(4) \
PBL_SECTION(".pbl_input_callbacks." #_callback) = { \
.callback = (_callback), \
.user_data = (_user_data) \
}
#define PBL_USED
Keep the symbol even if it appears unreferenced.
Definition compiler.h:95
#define PBL_ALIGNED(bytes)
Align the symbol or type.
Definition compiler.h:92
#define PBL_SECTION(name)
Place the symbol in a linker section.
Definition compiler.h:134
Listener of input events.
Definition input.h:89
void(* callback)(const struct pbl_input_event *evt, void *user_data)
Called for every event, in the context of the report.
Definition input.h:91
void * user_data
Data passed to callback.
Definition input.h:93

Define a listener of every input event.

Parameters
_callbackFunction called for every event.
_user_dataData passed to _callback.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum : uint16_t

PBL_INPUT_EV_KEY codes.

Enumerator
PBL_INPUT_KEY_BACK 
PBL_INPUT_KEY_UP 
PBL_INPUT_KEY_SELECT 
PBL_INPUT_KEY_DOWN 
PBL_INPUT_BTN_TOUCH 

Touch contact.

◆ anonymous enum

anonymous enum : uint16_t

PBL_INPUT_EV_ABS codes.

Enumerator
PBL_INPUT_ABS_X 
PBL_INPUT_ABS_Y 

◆ anonymous enum

anonymous enum : uint16_t

PBL_INPUT_EV_GES codes, located at the report's PBL_INPUT_ABS_X and Y.

Enumerator
PBL_INPUT_GES_TAP 
PBL_INPUT_GES_DOUBLE_TAP 
PBL_INPUT_GES_PALM 

◆ pbl_input_type

enum pbl_input_type : uint8_t

Event type.

Enumerator
PBL_INPUT_EV_KEY 

Key or button, value 1 when pressed and 0 when released.

PBL_INPUT_EV_ABS 

Absolute axis, value in its own units (pixels for touch).

PBL_INPUT_EV_GES 

Gesture recognized by the device, value unused.

Function Documentation

◆ pbl_input_report()

void pbl_input_report ( enum pbl_input_type  type,
uint16_t  code,
int32_t  value,
bool  sync 
)

Report an input event to every listener.

ISR-safe. The listeners run before this returns.

Parameters
typeType.
codeCode, depending on type.
valueValue, depending on type.
syncWhether the event ends a report.

Referenced by pbl_input_report_abs(), pbl_input_report_ges(), and pbl_input_report_key().

◆ pbl_input_report_abs()

static void pbl_input_report_abs ( uint16_t  code,
int32_t  value,
bool  sync 
)
inlinestatic

Report an absolute axis event.

Parameters
codePBL_INPUT_EV_ABS code.
valuePosition.
syncWhether the event ends a report.

References pbl_input_event::code, PBL_INPUT_EV_ABS, pbl_input_report(), pbl_input_event::sync, and pbl_input_event::value.

◆ pbl_input_report_ges()

static void pbl_input_report_ges ( uint16_t  code,
bool  sync 
)
inlinestatic

Report a gesture event.

Parameters
codePBL_INPUT_EV_GES code.
syncWhether the event ends a report.

References pbl_input_event::code, PBL_INPUT_EV_GES, pbl_input_report(), and pbl_input_event::sync.

◆ pbl_input_report_key()

static void pbl_input_report_key ( uint16_t  code,
bool  pressed,
bool  sync 
)
inlinestatic

Report a key event.

Parameters
codePBL_INPUT_EV_KEY code.
pressedWhether the key is pressed.
syncWhether the event ends a report.

References pbl_input_event::code, PBL_INPUT_EV_KEY, pbl_input_report(), and pbl_input_event::sync.