Skip to content

Instantly share code, notes, and snippets.

Created June 6, 2012 07:26
Show Gist options
  • Select an option

  • Save anonymous/2880420 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/2880420 to your computer and use it in GitHub Desktop.
main.c
#include <stdio.h>
#include "ch.h"
#include "hal.h"
#include "test.h"
#include "shell.h"
#include "evtimer.h"
#include "chprintf.h"
#include "glcd.h"
#include "touchpad.h"
#define BKGRD Black
Thread *thread2_p = NULL;
static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg) {
(void)arg;
chRegSetThreadName("blinker");
while (TRUE) {
palTogglePad(GPIOD, GPIOD_LED1);
chThdSleepMilliseconds(200);
}
return 0;
}
static WORKING_AREA(waThread2, 1024);
static msg_t Thread2(void *arg) {
(void)arg;
chRegSetThreadName("touchpad");
while(TRUE) {
chEvtWaitAny((eventmask_t)1);
palTogglePad(GPIOD, GPIOD_LED3);
}
}
static void touchIRQ(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
chSysLockFromIsr();
chEvtSignalFlagsI(thread2_p, (eventmask_t)1);
chSysUnlockFromIsr()
}
int main(void) {
static const EXTConfig extcfg = {
{
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOC, touchIRQ},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL}
}
};
halInit();
chSysInit();
lcdInit();
tpInit();
tpCalibrate();
lcdClear(BKGRD);
lcdSetOrientation(landscape);
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
thread2_p = chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);
extStart(&EXTD1, &extcfg);
while (TRUE) {
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment