コード例 #1
0
ファイル: main.c プロジェクト: tkadom/TWBLE
void test_app_init(void)
{
    nrf_gpio_cfg_output(LED_0);
    nrf_gpio_cfg_output(LED_1);

#ifdef BOARD_PCA10000
    nrf_gpio_pin_clear(LED_RGB_RED);
    nrf_gpio_pin_clear(LED_RGB_GREEN);
    nrf_gpio_pin_clear(LED_RGB_BLUE);
#endif

#ifdef BOARD_PCA10031
    nrf_gpio_pin_clear(LED_RGB_RED);
    nrf_gpio_pin_clear(LED_RGB_GREEN);
    nrf_gpio_pin_clear(LED_RGB_BLUE);
#endif

#ifdef BOARD_PCA10001
    nrf_gpio_range_cfg_output(0, 32);
    nrf_gpio_cfg_input(BUTTON_0, BUTTON_PULL);
    nrf_gpio_cfg_input(BUTTON_1, BUTTON_PULL);
    gpiote_init();
#endif

#ifdef BOARD_PCA10031
    nrf_gpio_range_cfg_output(0, 32);
    nrf_gpio_cfg_input(BUTTON_0, BUTTON_PULL);
    nrf_gpio_cfg_input(BUTTON_1, BUTTON_PULL);
    gpiote_init();
#endif

    led_config(1, 0);
    led_config(2, 0);
}
コード例 #2
0
ファイル: uart_nrf.c プロジェクト: jiunting/nrf51MasterL2CAP
}

void set_rx_handler (void (*handler) (uint8_t * ptr) ){
	rx_handler = handler;
}

void uart_init(){
	/* Make rx_handler NULL, configure it with set_rx_handler */
	rx_handler = NULL;

	/* Configure TX and RX pins from board.h */
	nrf_gpio_cfg_output(TX_PIN_NUMBER);
	nrf_gpio_cfg_input(RX_PIN_NUMBER, NRF_GPIO_PIN_NOPULL);
	NRF_UART0->PSELTXD = TX_PIN_NUMBER;
	NRF_UART0->PSELRXD = RX_PIN_NUMBER;

	/* Configure CTS and RTS pins if HWFC is true in board.h */
	if(HWFC){
		nrf_gpio_cfg_output(RTS_PIN_NUMBER);
		nrf_gpio_cfg_input(CTS_PIN_NUMBER, NRF_GPIO_PIN_NOPULL);
		NRF_UART0->PSELRTS = RTS_PIN_NUMBER;
		NRF_UART0->PSELCTS = CTS_PIN_NUMBER;
		NRF_UART0->CONFIG = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
	}

	/* Configure other UART parameters, BAUD rate is defined in uart_nrf.h	*/
	NRF_UART0->BAUDRATE = (UART_BAUDRATE << UART_BAUDRATE_BAUDRATE_Pos);
	NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
	NRF_UART0->EVENTS_RXDRDY = 0;

	// Enable UART RX interrupt only
	NRF_UART0->INTENSET = (UART_INTENSET_RXDRDY_Set << UART_INTENSET_RXDRDY_Pos);

	NVIC_SetPriority(UART0_IRQn, 4);
コード例 #3
0
ファイル: switch.c プロジェクト: cody82/car_nrf51
SwitchPosition Switch()
{
    SwitchPosition result;

	//nrf_gpio_cfg_output(SWITCH_PIN1);
	//nrf_gpio_pin_clear(SWITCH_PIN1);

    nrf_gpio_cfg_input(SWITCH_PIN2, NRF_GPIO_PIN_PULLUP);

    nrf_delay_us(10);

    if(nrf_gpio_pin_read(SWITCH_PIN2) == 0)
    {
        result = SwitchESB;
    }
    else
    {
        result = SwitchBLE;
    }

    //nrf_gpio_cfg_input(SWITCH_PIN1, NRF_GPIO_PIN_NOPULL);
    nrf_gpio_cfg_input(SWITCH_PIN2, NRF_GPIO_PIN_NOPULL);

    return result;
}
コード例 #4
0
ファイル: nrfx_i2s.c プロジェクト: turon/openthread
static void configure_pins(nrfx_i2s_config_t const * p_config)
{
    uint32_t mck_pin, sdout_pin, sdin_pin;

    // Configure pins used by the peripheral:

    // - SCK and LRCK (required) - depending on the mode of operation these
    //   pins are configured as outputs (in Master mode) or inputs (in Slave
    //   mode).
    if (p_config->mode == NRF_I2S_MODE_MASTER)
    {
        nrf_gpio_cfg_output(p_config->sck_pin);
        nrf_gpio_cfg_output(p_config->lrck_pin);
    }
    else
    {
        nrf_gpio_cfg_input(p_config->sck_pin,  NRF_GPIO_PIN_NOPULL);
        nrf_gpio_cfg_input(p_config->lrck_pin, NRF_GPIO_PIN_NOPULL);
    }

    // - MCK (optional) - always output,
    if (p_config->mck_pin != NRFX_I2S_PIN_NOT_USED)
    {
        mck_pin = p_config->mck_pin;
        nrf_gpio_cfg_output(mck_pin);
    }
    else
    {
        mck_pin = NRF_I2S_PIN_NOT_CONNECTED;
    }

    // - SDOUT (optional) - always output,
    if (p_config->sdout_pin != NRFX_I2S_PIN_NOT_USED)
    {
        sdout_pin = p_config->sdout_pin;
        nrf_gpio_cfg_output(sdout_pin);
    }
    else
    {
        sdout_pin = NRF_I2S_PIN_NOT_CONNECTED;
    }

    // - SDIN (optional) - always input.
    if (p_config->sdin_pin != NRFX_I2S_PIN_NOT_USED)
    {
        sdin_pin = p_config->sdin_pin;
        nrf_gpio_cfg_input(sdin_pin, NRF_GPIO_PIN_NOPULL);
    }
    else
    {
        sdin_pin = NRF_I2S_PIN_NOT_CONNECTED;
    }

    nrf_i2s_pins_set(NRF_I2S,
                     p_config->sck_pin,
                     p_config->lrck_pin,
                     mck_pin,
                     sdout_pin,
                     sdin_pin);
}
コード例 #5
0
void uartreader_init(uartreader_init_t * init)
{
    NRF_UART0->BAUDRATE = init->baudrate << UART_BAUDRATE_BAUDRATE_Pos;

    nrf_gpio_cfg_input(init->rxd_pin_no, NRF_GPIO_PIN_NOPULL);
    nrf_gpio_cfg_output(init->txd_pin_no);

    NRF_UART0->PSELTXD = init->txd_pin_no; 
    NRF_UART0->PSELRXD = init->rxd_pin_no; 

    if (init->hwfc)
    {
        nrf_gpio_cfg_input(init->cts_pin_no, NRF_GPIO_PIN_NOPULL);
        nrf_gpio_cfg_output(init->rts_pin_no);

        NRF_UART0->PSELCTS = init->cts_pin_no;
        NRF_UART0->PSELRTS = init->rts_pin_no;

        NRF_UART0->CONFIG = UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos;
    }
    else
    {
        NRF_UART0->CONFIG = UART_CONFIG_HWFC_Disabled << UART_CONFIG_HWFC_Pos;
    }

    m_evt_handler = init->evt_handler;
    m_buffer_index = 0;

    NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos;
    NVIC_EnableIRQ(UART0_IRQn);

    NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos;
    NRF_UART0->TASKS_STARTRX = 1;
}
コード例 #6
0
ファイル: intermcu_spi.c プロジェクト: qodome/Firmware
static void roni_init(void)
{
	nrf_gpio_cfg_input(RT5350_TO_NRF51_MAIL_IO, NRF_GPIO_PIN_PULLDOWN);
	// To avoid IO collision, configure RINO as input and wait
	// until RT5350 signal us
	nrf_gpio_cfg_input(NRF51_TO_RT5350_MAIL_IO, NRF_GPIO_PIN_PULLDOWN);
}
コード例 #7
0
ファイル: n5sk_button.c プロジェクト: RobinLin/Espruino
void n5_io_button_init(void)
{
    nrf_gpio_cfg_input(BUTTON_A, BUTTON_PULL);
    nrf_gpio_cfg_input(BUTTON_B, BUTTON_PULL);
    nrf_gpio_cfg_input(BUTTON_C, BUTTON_PULL);
    nrf_gpio_cfg_input(BUTTON_D, BUTTON_PULL);
}
コード例 #8
0
ファイル: et_battery.c プロジェクト: liuyuanbin/ET-smart-band
//================USB charing detect==================================
uint8_t USB_detect(void)
{ 
   //nrf_gpio_cfg_input(USB_DETECT_PIN, NRF_GPIO_PIN_PULLUP);
  //nrf_gpio_cfg_input(USB_DETECT_PIN, NRF_GPIO_PIN_NOPULL);
  //nrf_delay_100us(1);
   if(nrf_gpio_pin_read(USB_DETECT_PIN)==1)
   {
    //nrf_gpio_cfg_input(USB_DETECT_PIN, NRF_GPIO_PIN_PULLDOWN);
    if(chargeing_init==DISABLE_CHARGING_PIN_INIT)
    {
      //nrf_gpio_cfg_input(CHARGE_PIN, NRF_GPIO_PIN_NOPULL);
      nrf_gpio_cfg_input(CHARGE_PIN, NRF_GPIO_PIN_PULLUP);
      chargeing_init=ENABLE_CHARGING_PIN_INIT;
    }
   	return 1;
   }
   else
   {
    if(chargeing_init==ENABLE_CHARGING_PIN_INIT)
    {
      nrf_gpio_cfg_input(CHARGE_PIN, NRF_GPIO_PIN_PULLDOWN);
      chargeing_init=DISABLE_CHARGING_PIN_INIT;
    }  
   //nrf_gpio_cfg_input(USB_DETECT_PIN, NRF_GPIO_PIN_PULLDOWN);
   return 0;
   }
}
コード例 #9
0
ファイル: nrfx_uart.c プロジェクト: abtink/openthread
static void apply_config(nrfx_uart_t        const * p_instance,
                         nrfx_uart_config_t const * p_config)
{
    if (p_config->pseltxd != NRF_UART_PSEL_DISCONNECTED)
    {
        nrf_gpio_pin_set(p_config->pseltxd);
        nrf_gpio_cfg_output(p_config->pseltxd);
    }
    if (p_config->pselrxd != NRF_UART_PSEL_DISCONNECTED)
    {
        nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_NOPULL);
    }

    nrf_uart_baudrate_set(p_instance->p_reg, p_config->baudrate);
    nrf_uart_configure(p_instance->p_reg, p_config->parity, p_config->hwfc);
    nrf_uart_txrx_pins_set(p_instance->p_reg, p_config->pseltxd, p_config->pselrxd);
    if (p_config->hwfc == NRF_UART_HWFC_ENABLED)
    {
        if (p_config->pselcts != NRF_UART_PSEL_DISCONNECTED)
        {
            nrf_gpio_cfg_input(p_config->pselcts, NRF_GPIO_PIN_NOPULL);
        }
        if (p_config->pselrts != NRF_UART_PSEL_DISCONNECTED)
        {
            nrf_gpio_pin_set(p_config->pselrts);
            nrf_gpio_cfg_output(p_config->pselrts);
        }
        nrf_uart_hwfc_pins_set(p_instance->p_reg, p_config->pselrts, p_config->pselcts);
    }
}
コード例 #10
0
ファイル: nrf_drv_qdec.c プロジェクト: BlueSkyGjj/nRF52
ret_code_t nrf_drv_qdec_init(const nrf_drv_qdec_config_t * p_config,
                             qdec_event_handler_t event_handler)
{
    if (m_state != NRF_DRV_STATE_UNINITIALIZED)
    {
        return NRF_ERROR_INVALID_STATE; // qdec_event_handler has been already registered
    }

    if (p_config == NULL)
    {
        p_config = &m_default_config;
    }

    if (event_handler)
    {
        m_qdec_event_handler = event_handler;
    }
    else
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    nrf_qdec_sampleper_set(p_config->sampleper);
    nrf_gpio_cfg_input(p_config->pselled,NRF_GPIO_PIN_NOPULL);
    nrf_gpio_cfg_input(p_config->psela, NRF_GPIO_PIN_NOPULL);
    nrf_gpio_cfg_input(p_config->pselb, NRF_GPIO_PIN_NOPULL);
    nrf_qdec_pio_assign( p_config->psela, p_config->pselb, p_config->pselled);
    nrf_qdec_ledpre_set(p_config->ledpre);
    nrf_qdec_ledpol_set(p_config->ledpol);
    nrf_qdec_shorts_enable(NRF_QDEC_SHORT_REPORTRDY_READCLRACC_MASK);

    if (p_config->dbfen)
    {
        nrf_qdec_dbfen_enable();
    }
    else
    {
        nrf_qdec_dbfen_disable();
    }

    uint32_t int_mask = NRF_QDEC_INT_ACCOF_MASK;

    if (p_config->reportper != NRF_QDEC_REPORTPER_DISABLED)
    {
        nrf_qdec_reportper_set(p_config->reportper);
        int_mask |= NRF_QDEC_INT_REPORTRDY_MASK;
    }

    if (p_config->sample_inten)
    {
        int_mask |= NRF_QDEC_INT_SAMPLERDY_MASK;
    }

    nrf_qdec_int_enable(int_mask);
    nrf_drv_common_irq_enable(QDEC_IRQn, p_config->interrupt_priority);

    m_state = NRF_DRV_STATE_INITIALIZED;

    return NRF_SUCCESS;
}
コード例 #11
0
void simple_uart_config(uint8_t rts_pin_number,
                        uint8_t txd_pin_number,
                        uint8_t cts_pin_number,
                        uint8_t rxd_pin_number,
                        bool    hwfc)
{
/** @snippet [Configure UART RX and TX pin] */
    nrf_gpio_cfg_output(txd_pin_number);
    nrf_gpio_cfg_input(rxd_pin_number, NRF_GPIO_PIN_NOPULL);

    NRF_UART0->PSELTXD = txd_pin_number;
    NRF_UART0->PSELRXD = rxd_pin_number;
/** @snippet [Configure UART RX and TX pin] */
    if (hwfc)
    {
        nrf_gpio_cfg_output(rts_pin_number);
        nrf_gpio_cfg_input(cts_pin_number, NRF_GPIO_PIN_NOPULL);
        NRF_UART0->PSELCTS = cts_pin_number;
        NRF_UART0->PSELRTS = rts_pin_number;
        NRF_UART0->CONFIG  = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
    }

    NRF_UART0->BAUDRATE      = (UART_BAUDRATE_BAUDRATE_Baud38400 << UART_BAUDRATE_BAUDRATE_Pos);
    NRF_UART0->ENABLE        = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
    NRF_UART0->TASKS_STARTTX = 1;
    NRF_UART0->TASKS_STARTRX = 1;
    NRF_UART0->EVENTS_RXDRDY = 0;
}
コード例 #12
0
ファイル: n5sk_button.c プロジェクト: RobinLin/Espruino
void n5_io_switch_init(void)
{
    nrf_gpio_cfg_input(SWITCH_1, SWITCH_PULL);
    nrf_gpio_cfg_input(SWITCH_2, SWITCH_PULL);
    nrf_gpio_cfg_input(SWITCH_3, SWITCH_PULL);
    nrf_gpio_cfg_input(SWITCH_4, SWITCH_PULL);
    nrf_gpio_cfg_input(SWITCH_5, SWITCH_PULL);
}
コード例 #13
0
ファイル: uart.c プロジェクト: nodish/openthread
otError otPlatUartEnable(void)
{
    otError error = OT_ERROR_NONE;

    otEXPECT_ACTION(sUartEnabled == false, error = OT_ERROR_ALREADY);

    // Set up TX and RX pins.
    nrf_gpio_pin_set(UART_PIN_TX);
    nrf_gpio_cfg_output(UART_PIN_TX);
    nrf_gpio_cfg_input(UART_PIN_RX, NRF_GPIO_PIN_NOPULL);
    nrf_uart_txrx_pins_set(UART_INSTANCE, UART_PIN_TX, UART_PIN_RX);

#if (UART_HWFC == NRF_UART_HWFC_ENABLED)
    // Set up CTS and RTS pins.
    nrf_gpio_cfg_input(UART_PIN_CTS, NRF_GPIO_PIN_NOPULL);
    nrf_gpio_pin_set(UART_PIN_RTS);
    nrf_gpio_cfg_output(UART_PIN_RTS);
    nrf_uart_hwfc_pins_set(UART_INSTANCE, UART_PIN_RTS, UART_PIN_CTS);
#endif

    // Configure baudrate.
    nrf_uart_baudrate_set(UART_INSTANCE, UART_BAUDRATE);

    // Configure parity and hardware flow control.
    nrf_uart_configure(UART_INSTANCE, UART_PARITY, UART_HWFC);

    // Clear UART specific events.
    nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_TXDRDY);
    nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_ERROR);
    nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_RXDRDY);

    // Enable interrupts for TX.
    nrf_uart_int_enable(UART_INSTANCE, NRF_UART_INT_MASK_TXDRDY);

    // Enable interrupts for RX.
    nrf_uart_int_enable(UART_INSTANCE, NRF_UART_INT_MASK_RXDRDY | NRF_UART_INT_MASK_ERROR);

    // Configure NVIC to handle UART interrupts.
    NVIC_SetPriority(UART_IRQN, UART_IRQ_PRIORITY);
    NVIC_ClearPendingIRQ(UART_IRQN);
    NVIC_EnableIRQ(UART_IRQN);

    // Start HFCLK
    nrf_drv_clock_hfclk_request(NULL);

    while (!nrf_drv_clock_hfclk_is_running())
    {
    }

    // Enable UART instance, and start RX on it.
    nrf_uart_enable(UART_INSTANCE);
    nrf_uart_task_trigger(UART_INSTANCE, NRF_UART_TASK_STARTRX);

    sUartEnabled = true;

exit:
    return error;
}
コード例 #14
0
/**
 * Configures LEDs and buttons from boards.h as outputs and inputs. 
 */
static void gpio_init(void)
{
    nrf_gpio_cfg_input(WATCHDOG_RELOAD_BUTTON, NRF_GPIO_PIN_NOPULL);
    nrf_gpio_cfg_input(SOFTWARE_RESET_BUTTON, NRF_GPIO_PIN_NOPULL);
    nrf_gpio_cfg_input(SYSTEM_OFF_BUTTON, NRF_GPIO_PIN_NOPULL);	
    nrf_gpio_cfg_sense_input(WAKEUP_BUTTON, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
    
    nrf_gpio_range_cfg_output(LED_0, LED_7);
}
コード例 #15
0
void uart_init_lowPower(void)
{
//  NRF_GPIO->DIRSET = RX_PIN_MASK|TX_PIN_MASK|CTS_PIN_MASK|RTS_PIN_MASK;
  nrf_gpio_cfg_input(RX_PIN_NUMBER, NRF_GPIO_PIN_PULLDOWN);
  nrf_gpio_cfg_input(TX_PIN_NUMBER, NRF_GPIO_PIN_PULLDOWN);
  nrf_gpio_cfg_input(CTS_PIN_NUMBER, NRF_GPIO_PIN_PULLDOWN);
  nrf_gpio_cfg_input(RTS_PIN_NUMBER, NRF_GPIO_PIN_PULLDOWN);

}
コード例 #16
0
ファイル: jshardware.c プロジェクト: cyrusmaintea/Espruino
// Set the pin state
void jshPinSetState(Pin pin, JshPinState state) {
  /* Make sure we kill software PWM if we set the pin state
   * after we've started it */
  if (BITFIELD_GET(jshPinSoftPWM, pin)) {
    BITFIELD_SET(jshPinSoftPWM, pin, 0);
    jstPinPWM(0,0,pin);
  }

  uint32_t ipin = (uint32_t)pinInfo[pin].pin;
  switch (state) {
    case JSHPINSTATE_UNDEFINED :
      nrf_gpio_cfg_default(ipin);
      break;
    case JSHPINSTATE_GPIO_OUT :
      nrf_gpio_cfg_output(ipin);
      break;
    case JSHPINSTATE_GPIO_OUT_OPENDRAIN :
      NRF_GPIO->PIN_CNF[ipin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
                              | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
                              | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
                              | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
                              | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
      break;
    case JSHPINSTATE_GPIO_IN :
      nrf_gpio_cfg_input(ipin, NRF_GPIO_PIN_NOPULL);
      break;
    case JSHPINSTATE_GPIO_IN_PULLUP :
      nrf_gpio_cfg_input(ipin, NRF_GPIO_PIN_PULLUP);
      break;
    case JSHPINSTATE_GPIO_IN_PULLDOWN :
      nrf_gpio_cfg_input(ipin, NRF_GPIO_PIN_PULLDOWN);
      break;
    /*case JSHPINSTATE_ADC_IN :
      break;
    case JSHPINSTATE_AF_OUT :
      break;
    case JSHPINSTATE_AF_OUT_OPENDRAIN :
      break;
    case JSHPINSTATE_USART_IN :
      break;
    case JSHPINSTATE_USART_OUT :
      break;
    case JSHPINSTATE_DAC_OUT :
      break;*/
    case JSHPINSTATE_I2C :
      NRF_GPIO->PIN_CNF[ipin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
                              | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
                              | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
                              | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
                              | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
      // may need to be set to GPIO_PIN_CNF_DIR_Output as well depending on I2C state?
      break;
    default : assert(0);
      break;
  }
}
コード例 #17
0
void uartDeinit()
{
  NRF_UART0->TASKS_STOPRX = 1;
  NRF_UART0->TASKS_STOPTX = 1;
  NRF_UART0->ENABLE = 0;

  nrf_gpio_cfg_input(UART_TX_PIN, NRF_GPIO_PIN_NOPULL);
  nrf_gpio_cfg_input(UART_RTS_PIN, NRF_GPIO_PIN_NOPULL);

  isInit = false;
}
コード例 #18
0
ファイル: main.c プロジェクト: CorBiNO/Atomwear
void sensor_init()
{
	nrf_gpio_cfg_input(4, NRF_GPIO_PIN_PULLDOWN);
	nrf_gpio_cfg_input(5, NRF_GPIO_PIN_PULLDOWN);
	nrf_gpio_cfg_input(6, NRF_GPIO_PIN_PULLDOWN);
	
	MMA845x_Init();
	bmp180_init_interface();
	bmi055_init();
	ak8963_init();
}
コード例 #19
0
ファイル: main.c プロジェクト: IOIOI/nRF51
/**@brief Initializes the battery board switches as inputs.
 */
void switch_init(void)
{
#if defined(BSP_SWITCH_0) && defined(BSP_SWITCH_1) && defined(BSP_SWITCH_2) && \
    defined(BSP_SWITCH_3) && defined(BSP_SWITCH_4) // Only initialize switches on boards which have switches defined
    nrf_gpio_cfg_input(BSP_SWITCH_0, SWITCH_PULL);
    nrf_gpio_cfg_input(BSP_SWITCH_1, SWITCH_PULL);
    nrf_gpio_cfg_input(BSP_SWITCH_2, SWITCH_PULL);
    nrf_gpio_cfg_input(BSP_SWITCH_3, SWITCH_PULL);
    nrf_gpio_cfg_input(BSP_SWITCH_4, SWITCH_PULL);
#endif
}
コード例 #20
0
ファイル: uart.c プロジェクト: meriac/openbeacon-ng
void uart_init(void)
{
	g_uart_buffer_count = 0;
	g_uart_buffer_head = g_uart_buffer_tail = 0;

#ifdef  CONFIG_UART_RXD_PIN
	nrf_gpio_cfg_input(CONFIG_UART_RXD_PIN, NRF_GPIO_PIN_NOPULL);
	NRF_UART0->PSELRXD = CONFIG_UART_RXD_PIN;
#endif/*CONFIG_UART_RXD_PIN*/

#ifdef  CONFIG_UART_TXD_PIN
	nrf_gpio_cfg_output(CONFIG_UART_TXD_PIN);
	NRF_UART0->PSELTXD = CONFIG_UART_TXD_PIN;
#endif/*CONFIG_UART_TXD_PIN*/

	/* Optionally enable UART flow control */
#if defined(CONFIG_UART_RTS_PIN) || defined(CONFIG_UART_CTS_PIN)

	/* Clear-To-Send */
	nrf_gpio_cfg_input(CONFIG_UART_CTS_PIN, NRF_GPIO_PIN_NOPULL);
	NRF_UART0->PSELCTS = CONFIG_UART_CTS_PIN;

	/* Ready-To-Send */
	nrf_gpio_cfg_output(CONFIG_UART_RTS_PIN);
	NRF_UART0->PSELRTS = CONFIG_UART_RTS_PIN;

	/* enable hardware flow control */
	NRF_UART0->CONFIG = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
#endif/* flow control */

	/* set baud rate */
	NRF_UART0->BAUDRATE = (CONFIG_UART_BAUDRATE << UART_BAUDRATE_BAUDRATE_Pos);

	/* enable UART IRQ */
#ifdef  IRQ_PRIORITY_UART0
	NVIC_SetPriority(UART0_IRQn, IRQ_PRIORITY_UART0);
#endif
	NVIC_EnableIRQ(UART0_IRQn);
	NRF_UART0->INTENSET =
		(UART_INTENSET_TXDRDY_Enabled << UART_INTENSET_TXDRDY_Pos);

	/* start UART */
#ifdef  CONFIG_UART_RXD_PIN
	NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
	NRF_UART0->TASKS_STARTRX = 1;
	NRF_UART0->EVENTS_RXDRDY = 0;
#else
	NRF_UART0->ENABLE = CONFIG_UART_FORCE_POWERED ? (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos) : 0;
#endif/*CONFIG_UART_RXD_PIN*/
}
コード例 #21
0
ファイル: jshardware.c プロジェクト: RepRapThailand/Espruino
// Set the pin state
void jshPinSetState(Pin pin, JshPinState state) {
  uint32_t ipin = (uint32_t)pinInfo[pin].pin;
  switch (state) {
    case JSHPINSTATE_UNDEFINED :
      nrf_gpio_cfg_default(ipin);
      break;
    case JSHPINSTATE_GPIO_OUT :
      nrf_gpio_cfg_output(ipin);
      break;
    case JSHPINSTATE_GPIO_OUT_OPENDRAIN :
      NRF_GPIO->PIN_CNF[ipin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
                              | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
                              | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
                              | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
                              | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
      break;
    case JSHPINSTATE_GPIO_IN :
      nrf_gpio_cfg_input(ipin, NRF_GPIO_PIN_NOPULL);
      break;
    case JSHPINSTATE_GPIO_IN_PULLUP :
      nrf_gpio_cfg_input(ipin, NRF_GPIO_PIN_PULLUP);
      break;
    case JSHPINSTATE_GPIO_IN_PULLDOWN :
      nrf_gpio_cfg_input(ipin, NRF_GPIO_PIN_PULLDOWN);
      break;
    /*case JSHPINSTATE_ADC_IN :
      break;
    case JSHPINSTATE_AF_OUT :
      break;
    case JSHPINSTATE_AF_OUT_OPENDRAIN :
      break;
    case JSHPINSTATE_USART_IN :
      break;
    case JSHPINSTATE_USART_OUT :
      break;
    case JSHPINSTATE_DAC_OUT :
      break;*/
    case JSHPINSTATE_I2C :
      NRF_GPIO->PIN_CNF[ipin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
                              | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
                              | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
                              | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
                              | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
      // may need to be set to GPIO_PIN_CNF_DIR_Output as well depending on I2C state?
      break;
    default : assert(0);
      break;
  }
}
コード例 #22
0
ファイル: pm.c プロジェクト: CEDAROAD/crazyflie2-nrf-firmware
void pmInit()
{
  state = pmSysOff; //When NRF starts, the system is OFF
  targetState = state;

  /* PM-side IOs */
  nrf_gpio_cfg_output(PM_VCCEN_PIN);
  nrf_gpio_pin_clear(PM_VCCEN_PIN);

  nrf_gpio_cfg_input(PM_PGOOD_PIN, NRF_GPIO_PIN_PULLUP);
  //NRF_GPIO->PIN_CNF[PM_PGOOD_PIN] |= (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos);

  nrf_gpio_cfg_input(PM_CHG_PIN, NRF_GPIO_PIN_PULLUP);

}
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;
}
コード例 #24
0
bool keyboard_init(void)
{
		input_scan_vector = 0;
    if (row_pin_array == 0 || column_pin_array == 0){
		return false;	//return if pins have not been define
    }else{
		for (uint_fast8_t i = KEYBOARD_NUM_OF_COLUMNS; i--;){
			nrf_gpio_cfg_output((uint32_t)column_pin_array[i]);
			NRF_GPIO->PIN_CNF[(uint32_t)column_pin_array[i]] |= 0x400;	//Set pin to be "Disconnected 0 and standard 1"
			nrf_gpio_pin_clear((uint32_t)column_pin_array[i]);	//Set pin to low
		}
		for (uint_fast8_t i = KEYBOARD_NUM_OF_ROWS; i--;){
			nrf_gpio_cfg_input((uint32_t)row_pin_array[i],NRF_GPIO_PIN_PULLDOWN);
			input_scan_vector |= (1U << row_pin_array[i]);	//Prepare the magic number
		}
        if (((NRF_GPIO->IN)&input_scan_vector) != 0){	//Detect if any input pin is high
            return false;	//If inputs are not all low while output are, there must be something wrong
        }else{
			transmitted_keys_num = 0;	//Clear the arrays
			currently_pressed_keys_num = 0;
            for (uint_fast8_t i = MAX_NUM_OF_PRESSED_KEYS; i--;){
				transmitted_keys[i] = 0;
                currently_pressed_keys[i] = 0;
            }
        }
        matrix_lookup = default_matrix_lookup;
    }
    return true;
}
コード例 #25
0
void spi_master_close(const spi_master_hw_instance_t spi_master_hw_instance)
{
    #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE)

    volatile spi_master_instance_t * p_spi_instance = spi_master_get_instance(
        spi_master_hw_instance);
    APP_ERROR_CHECK_BOOL(p_spi_instance != NULL);

    /* Disable interrupt */
    APP_ERROR_CHECK(sd_nvic_ClearPendingIRQ(p_spi_instance->irq_type));
    APP_ERROR_CHECK(sd_nvic_DisableIRQ(p_spi_instance->irq_type));

    p_spi_instance->p_nrf_spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);

    /* Set Slave Select pin as input with pull-up. */
    nrf_gpio_pin_set(p_spi_instance->pin_slave_select);
    nrf_gpio_cfg_input(p_spi_instance->pin_slave_select, NRF_GPIO_PIN_PULLUP);
    p_spi_instance->pin_slave_select = (uint8_t)0xFF;

    /* Disconnect pins from SPI hardware */
    p_spi_instance->p_nrf_spi->PSELSCK  = (uint32_t)SPI_PIN_DISCONNECTED;
    p_spi_instance->p_nrf_spi->PSELMOSI = (uint32_t)SPI_PIN_DISCONNECTED;
    p_spi_instance->p_nrf_spi->PSELMISO = (uint32_t)SPI_PIN_DISCONNECTED;

    /* Reset to default values */
    spi_master_init_hw_instance(NULL, (IRQn_Type)0, p_spi_instance, false);
    #else
    return;
    #endif
}
コード例 #26
0
ファイル: main.c プロジェクト: sloboste/eecs473-fitness-watch
int main(void)
{
    nrf_gpio_cfg_output(PIN_LED_0);
    nrf_gpio_cfg_output(PIN_LED_1);
    nrf_gpio_cfg_input(PIN_BUTTON_0, GPIO_PIN_CNF_PULL_Pullup);

    nrf_gpio_pin_clear(PIN_LED_0);
    nrf_gpio_pin_clear(PIN_LED_1);

    lfclk_request();

    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS,
                   APP_TIMER_OP_QUEUE_SIZE, app_timer_evt_schedule);

    APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); 

    create_timers();

    timer_start(0);
    timer_start(1);
    
    while (1) {
        app_sched_execute();
        __WFI();
    }
}
コード例 #27
0
ファイル: uart.c プロジェクト: mrhexiaoheng/ble-3g
void UART_init(void)
{
	FIFO_Init(&tx_fifo, tx_buf_gs, TX_BUFFER_MAX_SIZE);
	FIFO_Init(&rx_fifo, rx_buf_gs, RX_BUFFER_MAX_SIZE);

	/** @snippet [Configure UART RX and TX pin] */
    nrf_gpio_cfg_output(TX_PIN_NUM);
    nrf_gpio_cfg_input(RX_PIN_NUM, NRF_GPIO_PIN_NOPULL);
    NRF_UART0->PSELTXD = TX_PIN_NUM;
    NRF_UART0->PSELRXD = RX_PIN_NUM;

    NRF_UART0->BAUDRATE      = (UART_BAUDRATE_BAUDRATE_Baud38400 << UART_BAUDRATE_BAUDRATE_Pos);
    
    NRF_UART0->EVENTS_RXDRDY = 0;
	NRF_UART0->EVENTS_TXDRDY = 0;
	NRF_UART0->TASKS_STARTTX = 1;
    NRF_UART0->TASKS_STARTRX = 1;
		
	NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos;
	NRF_UART0->INTENSET |= UART_INTENSET_TXDRDY_Enabled << UART_INTENSET_TXDRDY_Pos;

	// enable interrupt;
	NVIC_SetPriority(UART0_IRQn, APP_IRQ_PRIORITY_LOW);
	NVIC_EnableIRQ(UART0_IRQn);

	NRF_UART0->ENABLE        = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
}
コード例 #28
0
void photodiodes_init() {
  nrf_gpio_cfg_output(PD_CLOCK_PIN);
  nrf_gpio_cfg_output(PD_MOSI_PIN);
  nrf_gpio_cfg_input(PD_MISO_PIN, 1);
  nrf_gpio_cfg_output(PD_CS_PIN_A);
  nrf_gpio_cfg_output(PD_CS_PIN_B);
}
コード例 #29
0
uint32_t ser_phy_open(ser_phy_events_handler_t events_handler)
{
    uint32_t err_code = NRF_SUCCESS;

    if (events_handler == NULL)
    {
        return NRF_ERROR_NULL;
    }

    //Check if function was not called before
    if (m_ser_phy_event_handler != NULL)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    //Configure UART and register handler
    //uart_evt_handler is used to handle events produced by low-level uart driver
    APP_UART_INIT(&comm_params, ser_phy_uart_evt_callback, UART_IRQ_PRIORITY, err_code);

    //Pull down Rx pin until another side gets up to avoid receiving false bytes due to glitches
    //on Rx line
    nrf_gpio_cfg_input(comm_params.rx_pin_no, NRF_GPIO_PIN_PULLDOWN);

    m_ser_phy_event_handler = events_handler;

    //If intialization did not go alright return error
    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    return err_code;
}
コード例 #30
0
ファイル: main.c プロジェクト: tkadom/TWBLE
int main(void)
{

    LEDS_CONFIGURE(LEDS_MASK);
    LEDS_OFF(LEDS_MASK);
    nrf_gpio_cfg_output(WAVE_ON_PIN_NUMBER); // on this pin 2Hz wave will be generated

#ifdef BSP_BUTTON_0
    // configure pull-up on first button
    nrf_gpio_cfg_input(BSP_BUTTON_0, NRF_GPIO_PIN_PULLUP);
#endif

    APP_GPIOTE_INIT(1);

    uart_config();

    lpcomp_init();

    printf("\n\rLPCOMP driver usage example\r\n");

    while (true)
    {
        print_statistics();
        LEDS_ON(BSP_LED_1_MASK);
        NRF_GPIO->OUTCLR = (1 << WAVE_ON_PIN_NUMBER);
        nrf_delay_ms(100); // generate 100 ms pulse on selected pin
        print_statistics();
        LEDS_OFF(BSP_LED_1_MASK);
        NRF_GPIO->OUTSET = (1 << WAVE_ON_PIN_NUMBER);
        nrf_delay_ms(400);
    }
}