예제 #1
0
/**
 * \brief Common initialiser for all buttons
 * \param port_base GPIO port's register offset
 * \param pin_mask Pin mask corresponding to the button's pin
 */
static void
config(uint32_t port_base, uint32_t pin_mask)
{
  GPIO_SOFTWARE_CONTROL(port_base, pin_mask);
  GPIO_SET_INPUT(port_base, pin_mask);
  GPIO_DETECT_EDGE(port_base, pin_mask);
  GPIO_TRIGGER_BOTH_EDGES(port_base, pin_mask);
  GPIO_ENABLE_INTERRUPT(port_base, pin_mask);
}
예제 #2
0
파일: spi-arch.c 프로젝트: johangas/thesis
/*---------------------------------------------------------------------------*/
void
felicia_spi_init(void)
{
  /* Initialize ring buffers for RX and TX data */
  ringbuf_init(&spi_rx_buf, rxbuf_data, sizeof(rxbuf_data));
  ringbuf_init(&spi_tx_buf, txbuf_data, sizeof(txbuf_data));

  /* Configre SSI interface and init TX FIFO */
  ssi_reconfigure(1);

  /* Set the mux correctly to connect the SSI pins to the correct GPIO pins */
  /* set input pin with ioc */
  REG(IOC_CLK_SSIIN_SSI0) = ioc_input_sel(SPI_CLK_PORT, SPI_CLK_PIN);
  REG(IOC_SSIFSSIN_SSI0) = ioc_input_sel(SPI_SEL_PORT, SPI_SEL_PIN);
  REG(IOC_SSIRXD_SSI0) = ioc_input_sel(SPI_MOSI_PORT, SPI_MOSI_PIN);
  /* set output pin */
  ioc_set_sel(SPI_MISO_PORT, SPI_MISO_PIN, IOC_PXX_SEL_SSI0_TXD);

  /* Set pins as input and MISo as output */
  GPIO_SET_INPUT(SPI_CLK_PORT_BASE, SPI_CLK_PIN_MASK);
  GPIO_SET_INPUT(SPI_MOSI_PORT_BASE, SPI_MOSI_PIN_MASK);
  GPIO_SET_INPUT(SPI_SEL_PORT_BASE, SPI_SEL_PIN_MASK); /* it seems that setting SEL as input is not necessary */
  GPIO_SET_OUTPUT(SPI_MISO_PORT_BASE, SPI_MISO_PIN_MASK);
  /* Put all the SSI gpios into peripheral mode */
  GPIO_PERIPHERAL_CONTROL(SPI_CLK_PORT_BASE, SPI_CLK_PIN_MASK);
  GPIO_PERIPHERAL_CONTROL(SPI_MOSI_PORT_BASE, SPI_MOSI_PIN_MASK);
  GPIO_PERIPHERAL_CONTROL(SPI_MISO_PORT_BASE, SPI_MISO_PIN_MASK);
  GPIO_PERIPHERAL_CONTROL(SPI_SEL_PORT_BASE, SPI_SEL_PIN_MASK); /* it seems that setting SEL: as peripheral controlled is not necessary */
  /* Disable any pull ups or the like */
  ioc_set_over(SPI_CLK_PORT, SPI_CLK_PIN, IOC_OVERRIDE_DIS);
  ioc_set_over(SPI_MOSI_PORT, SPI_MOSI_PIN, IOC_OVERRIDE_DIS);
  ioc_set_over(SPI_MISO_PORT, SPI_MISO_PIN, IOC_OVERRIDE_DIS);
  ioc_set_over(SPI_SEL_PORT, SPI_SEL_PIN, IOC_OVERRIDE_PDE); /* it seems that configuring pull-ups/downs on SEL is not necessary */

  /* Configure output INT pin (from Felicia to Host */
  GPIO_SET_OUTPUT(SPI_INT_PORT_BASE, SPI_INT_PIN_MASK);
  GPIO_CLR_PIN(SPI_INT_PORT_BASE, SPI_INT_PIN_MASK);

  /* Configure CS pin and detection for both edges on that pin */
  GPIO_SOFTWARE_CONTROL(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK);
  GPIO_SET_INPUT(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK);
  GPIO_DETECT_EDGE(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK);
  GPIO_TRIGGER_BOTH_EDGES(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK);
  GPIO_ENABLE_INTERRUPT(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK);
  ioc_set_over(SPI_CS_PORT, SPI_CS_PIN, IOC_OVERRIDE_PUE);
  /* Enable interrupt form CS pin */
  nvic_interrupt_enable(NVIC_INT_GPIO_PORT_B);
  gpio_register_callback(cs_isr, SPI_CS_PORT, SPI_CS_PIN);
}
예제 #3
0
/**
 * \brief Init function for the User button.
 * \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1
 *             or 0 respectively)
 *
 * \param value Depends on the value of the type argument
 * \return Depends on the value of the type argument
 */
static int
config_user(int type, int value)
{
  switch(type) {
  case SENSORS_HW_INIT:
    button_press_duration_exceeded = process_alloc_event();

    /* Software controlled */
    GPIO_SOFTWARE_CONTROL(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);

    /* Set pin to input */
    GPIO_SET_INPUT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);

    /* Enable edge detection */
    GPIO_DETECT_EDGE(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);

    /* Both Edges */
    GPIO_TRIGGER_BOTH_EDGES(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);

    ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE);

    gpio_register_callback(btn_callback, BUTTON_USER_PORT, BUTTON_USER_PIN);
    break;
  case SENSORS_ACTIVE:
    if(value) {
      GPIO_ENABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
      nvic_interrupt_enable(BUTTON_USER_VECTOR);
    } else {
      GPIO_DISABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
      nvic_interrupt_disable(BUTTON_USER_VECTOR);
    }
    return value;
  case BUTTON_SENSOR_CONFIG_TYPE_INTERVAL:
    press_duration = (clock_time_t)value;
    break;
  default:
    break;
  }

  return 1;
}