int btns_addGpioteBtn(BTNS_Data *context, uint32_t pinNo, uint32_t channelNo, BTNS_ButtonEventHandler hndlr, void *hndlrData)
{
    //find an empty place
    BTNS_PrivData *p = context->priv;
    int i = 0;
    for (; i < p->configSize; ++i) {
        BTNS_Config *cfg = &(p->config[i]);
        if (BTNS_UnassignedChannel == cfg->btnChannelNo) {
            cfg->btnChannelNo = channelNo;
            cfg->btnGpio = pinNo;
            cfg->handler = hndlr;
            cfg->hndlrData = hndlrData;
            break;
        }
    }

    //has a free space been found?
    if (i == p->configSize)
        return -1;

    //button ports configured as input configured
    nrf_gpio_cfg_input(pinNo, NRF_GPIO_PIN_PULLUP);
    //gpiote events are triggered on both edges
    nrf_gpiote_event_config(channelNo, pinNo, NRF_GPIOTE_POLARITY_TOGGLE);
    //set appropriate inteset bits
    NRF_GPIOTE->INTENSET  |= GPIOTE_INTENSET_IN0_Set << (GPIOTE_INTENSET_IN0_Pos + channelNo);

    dbg_debugModule("Added ch: %d, gpio: %d\n", channelNo, pinNo);

    return 0;
}
示例#2
0
/** @brief Function for initializing the GPIO Tasks/Events peripheral.
*/
static void gpiote_init(void)
{
    // Configure GPIOTE channel 0 to generate event when MOTION_INTERRUPT_PIN_NUMBER goes from Low to High
    nrf_gpiote_event_config(0, MOTION_INTERRUPT_PIN_NUMBER, NRF_GPIOTE_POLARITY_LOTOHI);

    // Enable interrupt for NRF_GPIOTE->EVENTS_IN[0] event
    NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Msk;
}
示例#3
0
/** @brief Function for initializing the GPIO Tasks/Events peripheral.
*/
static void gpiote_init(void)
{
    // Configure port1 (pins 8-15) as outputs for showing duty cycle.
    nrf_gpio_range_cfg_output(LED_START, LED_STOP);

    nrf_gpio_cfg_input(INPUT_PIN_NUMBER, NRF_GPIO_PIN_NOPULL);

    // Enable interrupt on input 1 event.
    NRF_GPIOTE->INTENSET = (GPIOTE_INTENSET_IN1_Enabled << GPIOTE_INTENSET_IN1_Pos);

    // Configure GPIOTE channel 0 to generate event on input pin high-to-low transition.
    // Note that we can connect multiple GPIOTE events to a single input pin.
    nrf_gpiote_event_config(0, INPUT_PIN_NUMBER, NRF_GPIOTE_POLARITY_HITOLO);

    // Configure GPIOTE channel 1 to generate event on input pin low-to-high transition.
    // Note that we can connect multiple GPIOTE events to a single input pin.
    nrf_gpiote_event_config(1, INPUT_PIN_NUMBER, NRF_GPIOTE_POLARITY_LOTOHI);
}
示例#4
0
/** Initializes GPIO Tasks/Events peripheral.
*/
static void gpiote_init(void)
{
  *(uint32_t *)0x40000504 = 0xC007FFDF; // Workaround for PAN_028 rev1.1 anomaly 23 - System: Manual setup is required to enable use of peripherals

  // Configure GPIOTE channel 0 to generate event when MOTION_INTERRUPT_PIN_NUMBER goes from Low to High
  nrf_gpiote_event_config(0, MOTION_INTERRUPT_PIN_NUMBER, NRF_GPIOTE_POLARITY_LOTOHI);

  // Enable interrupt for NRF_GPIOTE->EVENTS_IN[0] event
  NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Msk;
}
static void uart_tx_last_byte(void)
{
    uart_peripheral_disconnect_flow();
    m_tx_state = UART_TX_LAST_BYTE_WAIT;

    //Configure event in case CTS is going low during this function execution
    nrf_gpiote_event_config(0, SER_PHY_UART_CTS, NRF_GPIOTE_POLARITY_TOGGLE);

    if (!nrf_gpio_pin_read(SER_PHY_UART_CTS)) //All pins are low --> last byte can be transmitted.
    {
        //Re-check state as it might have changed due to preemption of current interrupt.
        nrf_gpiote_unconfig(0);

        if (m_tx_state == UART_TX_LAST_BYTE_WAIT)
        {
            m_tx_state = UART_TX_COMPLETE;
            uart_tx_send();
        }
    }
}
static void uart_peripheral_disable(void)
{
    if ((m_tx_state == UART_IDLE || m_tx_state == UART_STALL) &&
        (m_rx_state == UART_IDLE))
    {
        NRF_UART0->TASKS_STOPTX = 1;
        NRF_UART0->TASKS_STOPRX = 1;
        NRF_UART0->PSELCTS      = UART_PIN_DISCONNECTED;
        NRF_UART0->PSELRTS      = UART_PIN_DISCONNECTED;
        NRF_UART0->ENABLE       = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);

        nrf_gpio_cfg_input(SER_PHY_UART_RTS, NRF_GPIO_PIN_NOPULL);

        nrf_gpiote_event_config(0, SER_PHY_UART_CTS, NRF_GPIOTE_POLARITY_TOGGLE);

        if (!nrf_gpio_pin_read(SER_PHY_UART_CTS))
        {
            NRF_GPIO->OUTSET = 1 << SER_PHY_UART_RTS;
            nrf_gpio_cfg_output(SER_PHY_UART_RTS);
            uart_peripheral_enable();
        }
    }
}
static void uart_txdrdy_handle(void)
{
    NRF_UART0->EVENTS_TXDRDY = 0;

    if (m_tx_state == UART_TX_SEND || m_tx_state == UART_IDLE)
    {
        if (m_tx_stream_index < (m_tx_stream_length - 1))
        {
            m_tx_state = UART_TX_SEND;
            uart_tx_send();
            //Keep same state.
        }
        else if (m_tx_stream_index == m_tx_stream_length)
        {
            m_tx_state = UART_IDLE;
            tx_complete_event_send();
        }
        else
        {
            uart_tx_last_byte();
        }
    }
    else if (m_tx_state == UART_TX_COMPLETE)
    {
        m_tx_state = UART_IDLE;

        if (m_rx_state == UART_IDLE)
        {
            nrf_delay_us(15);
            nrf_gpiote_event_config(0, SER_PHY_UART_CTS, NRF_GPIOTE_POLARITY_TOGGLE);

            if (nrf_gpio_pin_read(SER_PHY_UART_CTS))
            {
                uart_peripheral_disable();
            }
            else
            {
                uart_peripheral_connect_flow();
                m_cts_high_disconnect = true;
                nrf_gpiote_event_config(0, SER_PHY_UART_CTS, NRF_GPIOTE_POLARITY_TOGGLE);

                if (nrf_gpio_pin_read(SER_PHY_UART_CTS))
                {
                    //If second sample show CTS high it either
                    //1) happened BEFORE gpiote enable and uart should be disabled.
                    //(m_cts_high_disconnect == true).
                    //2) happened AFTER gpiote enable and an interrupt low->high has occured then
                    //uart should NOT be disabled as the ISR has disabled the UART.
                    //(m_cts_high_disconnect == false).
                    if (m_cts_high_disconnect == true)
                    {
                        m_cts_high_disconnect = false;
                        uart_peripheral_disable();
                    }
                }
            }
        }
        else
        {
            uart_peripheral_connect_flow();
        }

        tx_complete_event_send();
    }
    else if (m_tx_state == UART_STALL)
    {
        if (m_tx_stream_index == m_tx_stream_length)
        {
            tx_complete_event_send();
        }
        else
        {
            m_tx_pending = true;
        }
    }
    else
    {
        //Do nothing.
    }
}