git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10515 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
Giovanni Di Sirio 2017-08-31 14:17:35 +00:00
parent 424f886068
commit a093ad6f13
2 changed files with 8 additions and 9 deletions

View File

@ -32,6 +32,7 @@
#define PORTAB_LINE_LED1 LINE_LED_GREEN #define PORTAB_LINE_LED1 LINE_LED_GREEN
#define PORTAB_LINE_LED2 LINE_LED_RED #define PORTAB_LINE_LED2 LINE_LED_RED
#define PORTAB_LINE_BUTTON LINE_JOY_CENTER #define PORTAB_LINE_BUTTON LINE_JOY_CENTER
#define PORTAB_BUTTON_PRESSED PAL_HIGH
/*===========================================================================*/ /*===========================================================================*/
/* Module pre-compile time settings. */ /* Module pre-compile time settings. */

View File

@ -31,28 +31,26 @@ static THD_FUNCTION(Thread1, arg) {
(void)arg; (void)arg;
chRegSetThreadName("blinker"); chRegSetThreadName("blinker");
while (true) { while (true) {
systime_t time = palReadLine(PORTAB_LINE_BUTTON) == PAL_LOW ? 500 : 250; systime_t time = palReadLine(PORTAB_LINE_BUTTON) == PORTAB_BUTTON_PRESSED ? 250 : 500;
palClearLine(PORTAB_LINE_LED2); palToggleLine(PORTAB_LINE_LED2);
chThdSleepMilliseconds(time);
palSetLine(PORTAB_LINE_LED2);
chThdSleepMilliseconds(time); chThdSleepMilliseconds(time);
} }
} }
#endif #endif
event_source_t button_pressed_event; static event_source_t button_pressed_event;
event_source_t button_released_event; static event_source_t button_released_event;
static void button_cb(void *arg) { static void button_cb(void *arg) {
(void)arg; (void)arg;
chSysLockFromISR(); chSysLockFromISR();
if (palReadLine(PORTAB_LINE_BUTTON) == PAL_LOW) { if (palReadLine(PORTAB_LINE_BUTTON) == PORTAB_BUTTON_PRESSED) {
chEvtBroadcastI(&button_released_event); chEvtBroadcastI(&button_pressed_event);
} }
else { else {
chEvtBroadcastI(&button_pressed_event); chEvtBroadcastI(&button_released_event);
} }
chSysUnlockFromISR(); chSysUnlockFromISR();
} }