Nut/OS  5.0.5
API Reference
Keys

Button handler. More...

Collaboration diagram for Keys:

Data Structures

struct  KEYEventT

Defines

#define KEY_NOT_PRESSED   0x00
 Key state definitions.
#define KEY_IS_DOWN   0x01
 Key state KEY_IS_DOWN.
#define KEY_PENDING   0x02
 Key state KEY_PENDING.
#define KEY_IS_LOCKED   0x04
 Key state KEY_NOT_PRESSED.
#define KEY_ACTION_DOWN   0x10
 Key state definitions.
#define KEY_ACTION_UP   0x20
 Key action KEY_ACTION_UP.
#define KEY_ACTION_HOLD   0x40
 Key action KEY_ACTION_HOLD.
#define KEY_ACTION_SHORT   0x80
 Key action KEY_ACTION_SHORT.

Functions

int NutGetKeyState (HANDLE *keyhp)
 reads actual state of a key
int NutGetKeyTime (HANDLE *keyhp)
 reads the time in ms of how long the key is or was pressed
void KeyTimerCb (HANDLE timer, void *arg)
 Key-Timer callback handler.
void sys_key (void *arg)
 Key-Thread.
int InitKEY (KEYEventT *key)
 Internal functionn to setup a GPIO port for reading a connected key.
int NutAssignKeyEvt (HANDLE *keyhp, HANDLE *event)
int NutAssignKeyFkt (HANDLE *keyhp, void(*callback)(void))
int NutRegisterKey (HANDLE *keyhp, int bank, int pin, int fx, uint32_t fxt)
 register a key and describe its function

Variables

HANDLE key_tmr = NULL
HANDLE key_evt = NULL

Detailed Description

Button handler.


Define Documentation

#define KEY_NOT_PRESSED   0x00

Key state definitions.

The key handler assignes the following states to a key.

The user should only use KEY_IS_DOWN and KEY_PENDING to determine what key released his NutEventWait() or if he uses the key functions without event handling.

Key state KEY_NOT_PRESSED.

State used internally.

Referenced by sys_key().

#define KEY_IS_DOWN   0x01

Key state KEY_IS_DOWN.

User can check if key is pressed by if ((NutGetKeyState( key) & KEY_IS_DOWN) == KEY_IS_DOWN)

Referenced by sys_key().

#define KEY_PENDING   0x02

Key state KEY_PENDING.

User can check if the action assigned to this key has released the event by using the folllowing if sequence: if ((NutGetKeyState( key) & KEY_PENDING) == KEY_PENDING) This state is reset on every call of NutGetKeyState().

Referenced by NutAssignKeyEvt(), NutAssignKeyFkt(), NutGetKeyState(), and sys_key().

#define KEY_IS_LOCKED   0x04

Key state KEY_NOT_PRESSED.

State used internally for locking a key and prevent pultiple event release if the key is pressed longer than any action requires.

Referenced by sys_key().

#define KEY_ACTION_DOWN   0x10

Key state definitions.

The key handler assignes the following states to a key depending

The user should only use KEY_IS_DOWN and KEY_PENDING to determine what key released his NutEventWait() or if he uses the key functions without event handling.

Key action KEY_ACTION_DOWN.

By assigning this action to a key, it will release a pending event wait if the button is pressed. Timing parameter is ignored.

Referenced by sys_key().

#define KEY_ACTION_UP   0x20

Key action KEY_ACTION_UP.

By assigning this action to a key, it will release a pending event wait if the button is released. Timing parameter is ignored.

Referenced by sys_key().

#define KEY_ACTION_HOLD   0x40

Key action KEY_ACTION_HOLD.

By assigning this action to a key, and givign a timing parameter in ms the assigned event will be released if the button was pressed for at least the given time.

Referenced by sys_key().

#define KEY_ACTION_SHORT   0x80

Key action KEY_ACTION_SHORT.

By assigning this action to a key, and givign a timing parameter in ms the assigned event will be released if the button was released before the given time elapsed.

Referenced by sys_key().


Function Documentation

int NutGetKeyState ( HANDLE keyhp)

reads actual state of a key

Applications can call this functions to determine which key issued the event to a calling thread. This helps if more than ome key has been assigned to a single event mutex. If the key was the one which raised the event, it has bit 1 set. This bit will be cleared on calling this function.

Parameters:
keyhHandle of the key to query.
Returns:
bit 0: 1 if key still pressed, bit 1: 1 if key raised the event.

References KEY_PENDING, KEYEventT::newState, NULL, and rc.

int NutGetKeyTime ( HANDLE keyhp)

reads the time in ms of how long the key is or was pressed

Applications can call this functions to determine how long a key is pressed.

Parameters:
keyhHandle of the key to query.
Returns:
time key was pressed in ms or -1 in case of error.

References NULL, NutGetMillis(), rc, and KEYEventT::TimeDown.

Here is the call graph for this function:

void KeyTimerCb ( HANDLE  timer,
void *  arg 
)

Key-Timer callback handler.

This is an internal function called by NutRegisterKey() and the EventTimer for key handling.

Parameters:
timerInternal Handle of the key timer.
argNot used.

References NutEventPostAsync().

Referenced by NutRegisterKey().

Here is the call graph for this function:

void sys_key ( void *  arg)

Key-Thread.

This is the internal key thread triggered by the key event timer.

References KEYEventT::bank, KEYEventT::fx, KEYEventT::fxt, GpioPinGet, IOExpRawRead(), IOXP_PORT0, KEY_ACTION_DOWN, KEY_ACTION_HOLD, KEY_ACTION_SHORT, KEY_ACTION_UP, KEY_IS_DOWN, KEY_IS_LOCKED, KEY_NOT_PRESSED, KEY_PENDING, KPRINTF, KEYEventT::lastState, KEYEventT::newState, KEYEventT::next, NULL, NUT_WAIT_INFINITE, NUTASSERT, NutEventPost(), NutEventWait(), NutGetMillis(), NutThreadSetPriority(), KEYEventT::pin, and KEYEventT::TimeDown.

Referenced by NutRegisterKey().

Here is the call graph for this function:

int InitKEY ( KEYEventT key)

Internal functionn to setup a GPIO port for reading a connected key.

Parameters:
keyHandle to the key, the port will be assigned to.
Returns:
0 if key could be set up, -1 if not.

References KEYEventT::bank, GPIO_CFG_DEBOUNCE, GPIO_CFG_PULLUP, GpioPinConfigSet(), IOExpPinConfigSet(), IOXP_PORT0, and KEYEventT::pin.

Referenced by NutRegisterKey().

Here is the call graph for this function:

int NutAssignKeyEvt ( HANDLE keyhp,
HANDLE event 
)
int NutAssignKeyFkt ( HANDLE keyhp,
void(*)(void)  callback 
)
int NutRegisterKey ( HANDLE keyhp,
int  bank,
int  pin,
int  fx,
uint32_t  fxt 
)

register a key and describe its function

Parameters:
keyhThe handle to the LED that should be controlled.
eventThe event handle for locking a task until the key is active.
bankThe GPIO or PCA9555 port, where key is connected to.
pinPin of the bank, where key is connected to.
fxAction of key for releasing the event.
fxtTime parameter for action.
Returns:
0 on success, -1 on any error.
Note:
Following actions can be assigned to a key:
fx fxtEvent released
>KEY_ACTION_DOWN 0 on Key press
>KEY_ACTION_UP 0 on Key release
>KEY_ACTION_HOLD n on Key pressed for n ms
>KEY_ACTION_SHORTn on Key released before n ms

References KEYEventT::bank, KEYEventT::callback, KEYEventT::event, KEYEventT::fx, KEYEventT::fxt, InitKEY(), key_evt, key_tmr, KeyTimerCb(), KPRINTF, KEYEventT::lastState, malloc(), KEYEventT::newState, KEYEventT::next, NULL, NUTASSERT, NutEnterCritical, NutExitCritical, NutThreadCreate(), NutTimerStart(), KEYEventT::pin, sys_key(), and KEYEventT::TimeDown.

Here is the call graph for this function:


Variable Documentation

HANDLE key_tmr = NULL

Referenced by NutRegisterKey().

HANDLE key_evt = NULL

Referenced by NutRegisterKey().