void pioInit(PioState *pioState, Task client) { MessagePioChanged *m = malloc(sizeof(MessagePioChanged)); uint16 pio_get = PioGet(); uint16 pskey_wakeup = 0xFFFF; pioState->task.handler = pioHandler; pioState->client = client; PsFullRetrieve(PSKEY_PIO_WAKEUP_STATE, &pskey_wakeup, sizeof(pskey_wakeup)); pskey_wakeup = ~pskey_wakeup; pioState->pio_states.store_held = Unknown; pioState->pio_states.double_press = Unknown; pioState->pio_states.store_count = 0; pioState->pio_states.store_bits = 0; pioState->pio_states.timed_id = 0; pioState->pio_states.pskey_wakeup = pskey_wakeup; pioState->pio_states.pio_raw_bits = ~(pio_get^pskey_wakeup) & (0); (void) MessagePioTask(&pioState->task); PioDebounce((1UL<<0), 2, 20); m->state = pio_get & ((1UL<<0)); m->time = 0; MessageSend(&pioState->task, MESSAGE_PIO_CHANGED, m); }
/**************************************************************************** DESCRIPTION Initialises the Button Module parameters */ void ButtonsInit ( ButtonsTaskData *pButtonsTask ) { #ifdef ENABLE_CAPSENSE uint8 i; bool success; #endif pButtonsTask->task.handler = ButtonsMessageHandler; /*connect the underlying PIO task to this task*/ MessagePioTask(&pButtonsTask->task); /*connect the underlying Charger task to this task*/ MessageChargerTask(&pButtonsTask->task); #ifdef ENABLE_CAPSENSE /* set the update rate, currently a fast update rate to detect short touches */ success = CapsenseConfigure(CAPSENSE_SET_CINT_UPDATE_DIVIDER, 0); /* set an initial trigger level for the cap sensors, this level will depend upon hardware and tests will need to be carried out to determine what a particular implementation requires */ for (i = 0; success && (i < BM_CAP_SENSORS); i++) success = CapsenseConfigurePad(i, CAPSENSE_SET_TRIGGER_LEVEL, BM_CAP_SENSOR_LOW_SENSITIVITY); B_DEBUG(("B: capsense %s\n", success ? "OK" : "FAIL: check CONFIG_CAP_SENSE_PRELOAD")) ; /* initialise task handler for capsense events after a short delay due to spurious events generated from the firmware during this time */ MessageSendLater(&pButtonsTask->task,B_MESSAGE_CAPSENSE_ENABLE,0,CAPSENSE_INIT_INTERVAL); #endif }
/**************************************************************************** DESCRIPTION Initialises the Button Module parameters */ void ButtonsInit ( ButtonsTaskData *pButtonsTask ) { pButtonsTask->task.handler = ButtonsMessageHandler; /*connect the underlying PIO task to this task*/ MessagePioTask(&pButtonsTask->task); /*connect the underlying Charger task to this task*/ MessageChargerTask(&pButtonsTask->task); }
void InitPioTask() { /* Set up task 1 handler */ pioApp.task.handler = PioTaskHandler; pioApp.new_heater_state = Heater0; MessagePioTask(&pioApp.task); PioSetDir(0x03, 0x03); PioSet(0x03, 0); MessageSend( &pioApp.task, NewHeaterState, 0); }
int main(void) { /* Set app_handler() function to handle app's messages */ app.task.handler = app_handler; /* Set app task to receive PIO messages */ MessagePioTask(&app.task); /* Setup PIO interrupt messages */ PioDebounce32(BUTTON_A | BUTTON_B, /* PIO pins we are interested in */ 2, 20); /* 2 reads and 20ms between them */ MessageLoop(); return 0; }