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. | |
#define | LED_OFF 0 |
LED action definitions. | |
#define | LED_ON 1 |
Switch LED on. | |
#define | LED_FLIP 2 |
Flip the LED state (toggle). | |
#define | LED_BLINK 4 |
Let the LED blink continuously. | |
#define | LED_IS_ON 0 |
#define | LED_IS_OFF 1 |
Functions | |
int | NutGetKeyState (HANDLE keyh) |
reads actual state of a key | |
uint32_t | NutGetKeyTime (HANDLE keyh) |
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 | NutRegisterKey (HANDLE *keyhp, HANDLE *event, int bank, int pin, int fx, uint32_t fxt) |
register a key and describe its function | |
int | InitLED (LEDEventT *led) |
Configures LED connection port. | |
void | sys_led (void *arg) |
Thread to control blinking and flashing of all registered LEDs. | |
void | NutSetLed (HANDLE ledh, uint_fast8_t fxin, uint32_t timOn, uint32_t timOff) |
sets state of a LED | |
int | NutRegisterLed (HANDLE *ledh, int bank, int pin) |
Register an LED for handling. | |
Variables | |
HANDLE | key_tmr = NULL |
HANDLE | key_evt = NULL |
LEDEventT * | first_led = NULL |
HANDLE | led_tmr = NULL |
HANDLE | led_evt = NULL |
#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.
#define KEY_IS_DOWN 0x01 |
#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().
Definition at line 90 of file keys.h.
Referenced by Key1Thread(), Key2Thread(), NutGetKeyState(), and sys_key().
#define KEY_IS_LOCKED 0x04 |
#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.
#define KEY_ACTION_UP 0x20 |
#define KEY_ACTION_HOLD 0x40 |
#define KEY_ACTION_SHORT 0x80 |
#define LED_OFF 0 |
LED action definitions.
The LED modifies the LED according to these tokens when calling NutSetLed().
Switch LED off. The LED will be switched off immediately. If a timOff parameter of not 0 is given, the LED will be switched off for the given time in ms an then return to on state.
#define LED_ON 1 |
#define LED_FLIP 2 |
Flip the LED state (toggle).
Toggle the LED from its actual state the the other. Timing parameters are not supported.
Definition at line 90 of file led.h.
Referenced by Key2Thread(), NutSetLed(), and sys_led().
#define LED_BLINK 4 |
Let the LED blink continuously.
The parameter timOn specifies the on-time and parameter timOff the off-time. Together with higher timer settings a software dimming can as well be established as a simple blink effect or short / long flash effects. Be adviced that high timer rates can decrease overall system speed. Therefore you have to modify the timer rate in the led.c directly. Standard setting is 10ms cycle time.
Definition at line 102 of file led.h.
Referenced by Key1Thread(), main(), NutSetLed(), and sys_led().
#define LED_IS_ON 0 |
#define LED_IS_OFF 1 |
int NutGetKeyState | ( | HANDLE | keyh | ) |
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.
keyh | Handle of the key to query. |
Definition at line 119 of file keys.c.
References KEY_PENDING.
Referenced by Key1Thread(), and Key2Thread().
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.
keyh | Handle of the key to query. |
Definition at line 137 of file keys.c.
References NutGetMillis().
void KeyTimerCb | ( | HANDLE | timer, | |
void * | arg | |||
) |
Key-Timer callback handler.
This is an internal function called by NutRegisterKey() and the EventTimer for key handling.
timer | Internal Handle of the key timer. | |
arg | Not used. |
Definition at line 154 of file keys.c.
References NutEventPostAsync().
Referenced by NutRegisterKey().
void sys_key | ( | void * | arg | ) |
Key-Thread.
This is the internal key thread triggered by the key event timer.
Definition at line 165 of file keys.c.
References GpioPinGet(), IOExpRawRead(), IOXP_PORT0, KEY_ACTION_DOWN, KEY_ACTION_HOLD, KEY_ACTION_SHORT, KEY_ACTION_UP, KEY_IS_DOWN, KEY_IS_LOCKED, KEY_PENDING, KPRINTF, NUT_WAIT_INFINITE, NUTASSERT, NutEventPost(), NutEventWait(), NutGetMillis(), and NutThreadSetPriority().
Referenced by NutRegisterKey().
int InitKEY | ( | KEYEventT * | key | ) |
Internal functionn to setup a GPIO port for reading a connected key.
key | Handle to the key, the port will be assigned to. |
Definition at line 261 of file keys.c.
References GPIO_CFG_DEBOUNCE, GPIO_CFG_PULLUP, GpioPinConfigSet(), IOExpPinConfigSet(), and IOXP_PORT0.
Referenced by NutRegisterKey().
register a key and describe its function
keyh | The handle to the LED that should be controlled. | |
event | The event handle for locking a task until the key is active. | |
bank | The GPIO or PCA9555 port, where key is connected to. | |
pin | Pin of the bank, where key is connected to. | |
fx | Action of key for releasing the event. | |
fxt | Time parameter for action. |
fx | fxt | Event 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_SHORT | n | on Key released before n ms |
Definition at line 299 of file keys.c.
References InitKEY(), key_evt, key_tmr, KeyTimerCb(), KPRINTF, malloc, NUTASSERT, NutEnterCritical, NutExitCritical, NutThreadCreate(), NutTimerStart(), and sys_key().
Referenced by main().
int InitLED | ( | LEDEventT * | led | ) |
Configures LED connection port.
This is an internal function called by NutRegisterLED().
Definition at line 110 of file led.c.
References GPIO_CFG_OUTPUT, GpioPinConfigSet(), GpioPinSetHigh(), IOExpPinConfigSet(), IOExpSetBitHigh(), and IOXP_PORT0.
Referenced by NutRegisterLed().
void sys_led | ( | void * | arg | ) |
Thread to control blinking and flashing of all registered LEDs.
This is the internal LED handler thread. It si blocked by default, waiting for a timer event to run. The thread handles LED timing through reverse calculation of the actual timeout. This uses mor system time, but makes blinking effects more smooth even in situation where high priority tasks are delaying the timer interrupt or this threadf to be executed.
arg | Handle of an event queue. |
Definition at line 158 of file led.c.
References first_led, LED_BLINK, LED_FLIP, LED_OFF, LED_ON, NUT_WAIT_INFINITE, NUTASSERT, NutEventWait(), NutGetMillis(), NutSetLed(), and NutThreadSetPriority().
Referenced by NutRegisterLed().
void NutSetLed | ( | HANDLE | ledh, | |
uint_fast8_t | fxin, | |||
uint32_t | timOn, | |||
uint32_t | timOff | |||
) |
sets state of a LED
ledh | The handle to the LED that should be controlled. | |
fxin | Effect to set | |
timOn | Duration of the LED's on-time of the effect given. | |
timOff | Duration of the LED's off time of the effect given. |
Definition at line 221 of file led.c.
References GpioPinSet(), IOExpSetBit(), IOXP_PORT0, LED_BLINK, LED_FLIP, LED_IS_OFF, LED_IS_ON, LED_OFF, LED_ON, and NUTASSERT.
Referenced by Key1Thread(), Key2Thread(), main(), sys_led(), Thread1(), and Thread2().
int NutRegisterLed | ( | HANDLE * | ledh, | |
int | bank, | |||
int | pin | |||
) |
Register an LED for handling.
Register a LED for beeing controlled by this driver. LED can then be set by NutSetLed() by passing over the LEDs handler to that function. Also LEDs connectd through external (I2C / SPI) port chips can be driven, ne needs to enable the control for that chips first in Nutconf.
ledh | The led-handle for accessing the LED after registering. | |
bank | Port of CPU or IO-Expander the LED is connected to. | |
pin | Pin at the given port. |
Definition at line 279 of file led.c.
References first_led, InitLED(), led_evt, LED_IS_OFF, led_tmr, malloc, memset(), NutEnterCritical, NutExitCritical, NutThreadCreate(), NutTimerStart(), and sys_led().
LEDEventT* first_led = NULL |