Ejemplo n.º 1
0
/**
 * \brief Configuration function for the button sensor for all buttons.
 *
 * \param type This function does nothing unless type == SENSORS_ACTIVE
 * \param c 0: disable the button, non-zero: enable
 * \param key: One of BOARD_KEY_LEFT, BOARD_KEY_RIGHT etc
 */
static void
config_buttons(int type, int c, uint32_t key)
{
  switch(type) {
  case SENSORS_HW_INIT:
    ti_lib_gpio_event_clear(1 << key);
    ti_lib_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
    ti_lib_gpio_dir_mode_set((1 << key), GPIO_DIR_MODE_IN);
    gpio_interrupt_register_handler(key, button_press_handler);
    break;
  case SENSORS_ACTIVE:
    if(c) {
      ti_lib_gpio_event_clear(1 << key);
      ti_lib_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
      ti_lib_gpio_dir_mode_set((1 << key), GPIO_DIR_MODE_IN);
      ti_lib_ioc_int_enable(key);
    } else {
      ti_lib_ioc_int_disable(key);
    }
    break;
  default:
    break;
  }
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*/
void
gpio_interrupt_register_handler(uint8_t ioid, gpio_interrupt_handler_t f)
{
  uint8_t interrupts_disabled = ti_lib_int_master_disable();

  /* Clear interrupts on specified pins */
  ti_lib_gpio_event_clear(1 << ioid);

  handlers[ioid] = f;

  /* Re-enable interrupts */
  if(!interrupts_disabled) {
    ti_lib_int_master_enable();
  }
}