示例#1
0
/** Initializes GPIO Tasks/Events peripheral.
*/
static void gpiote_init(void)
{
  NRF_GPIO->OUT = 0x00000000UL;
  NRF_GPIO->DIRSET = 0x0000FF00UL;
  NRF_GPIO->DIRCLR = 0x000000FFUL;

  /* Configuring Button 0 as input */
  nrf_gpio_cfg_input(BUTTON0, NRF_GPIO_PIN_NOPULL);

  /* Configuring Button 1 as input */
  /*lint -e{845} // A zero has been given as right argument to operator '|'" */
  nrf_gpio_cfg_input(BUTTON1, NRF_GPIO_PIN_NOPULL);

  /* Configuring Pin PWM_OUTPUT_PIN_NUMBER as output to be used for the PWM waveform */
  nrf_gpio_cfg_output(PWM_OUTPUT_PIN_NUMBER);
  
  *(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 toggle the PWM pin state */
  /* Note that we can only connect one GPIOTE task to an output pin */
  nrf_gpiote_task_config(0, PWM_OUTPUT_PIN_NUMBER, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
}
示例#2
0
文件: main.c 项目: pcbreflux/nordic
/**
 * @brief Function for application main entry.
 */
int main(void) {

    uint8_t pos=0;
    // setup
    // Configure LED-pin as outputs and clear.
    for (pos=0;pos<LEDPINS;pos++) {
    	nrf_gpio_cfg_output(led_pin[pos]);
    	nrf_gpio_pin_clear(led_pin[pos]);
    }

    // loop
    // Toggle LED.
    pos=0;
    while (true) {
        nrf_gpio_pin_toggle(led_pin[pos]);
        nrf_delay_ms(1000);
        pos++;
		if (pos>=LEDPINS) {
			pos=0;
		}
    }
}
示例#3
0
/**@brief Function for UART initialization.
 */
static uint32_t uart_init(app_uart_stream_comm_params_t * p_comm_params)
{
    if (p_comm_params->baud_rate > UART_BAUD_RATE_115200)
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    NVIC_DisableIRQ(UART0_IRQn);
    NVIC_ClearPendingIRQ(UART0_IRQn);
    NRF_UART0->INTENCLR = 0xFFFFFFFF;

    m_iterations_next_byte_max = m_iteration[p_comm_params->baud_rate];

    //Configure UART0 pins.
    nrf_gpio_cfg_output(p_comm_params->tx_pin_no);
    nrf_gpio_cfg_input(p_comm_params->rx_pin_no, NRF_GPIO_PIN_NOPULL);

    NRF_UART0->PSELTXD  = p_comm_params->tx_pin_no;
    NRF_UART0->PSELRXD  = p_comm_params->rx_pin_no;
    NRF_UART0->PSELCTS  = UART_PIN_DISCONNECTED;
    NRF_UART0->PSELRTS  = UART_PIN_DISCONNECTED;
    NRF_UART0->BAUDRATE = m_baud_rates[p_comm_params->baud_rate];
    NRF_UART0->CONFIG   = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Msk) |
                          (UART_CONFIG_HWFC_Disabled << UART_CONFIG_HWFC_Pos);

    //Clean out possible events from earlier operations
    NRF_UART0->EVENTS_RXDRDY = 0;
    NRF_UART0->EVENTS_TXDRDY = 0;
    NRF_UART0->EVENTS_ERROR  = 0;

    //Activate UART.
    NRF_UART0->ENABLE        = UART_ENABLE_ENABLE_Enabled;
    NRF_UART0->INTENSET      = 0;
    NRF_UART0->TASKS_STARTTX = 1;
    NRF_UART0->TASKS_STARTRX = 1;

    return NRF_SUCCESS;
}
示例#4
0
int main()
{
	//APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);
	nrf_gpio_cfg_output(LED_CONNECTED);
	APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
	timers_init();
	uart_init();
//	blink();
	nrf_gpio_pin_clear(LED_CONNECTED);

	BLEStart();
//	timers_start();
//	blink();


	while (1)
	{
		app_sched_execute();
		uint32_t err_code = sd_app_evt_wait();
		APP_ERROR_CHECK(err_code);
		//BlueIOADCStart();
	}
}
示例#5
0
文件: main.c 项目: AriZuu/blink-test
int main(int argc, char **argv)
{
// configure console pins

  nrf_gpio_cfg_output(TXPIN);
  nrf_gpio_cfg_input(RXPIN, NRF_GPIO_PIN_NOPULL);

  nrf_uart_txrx_pins_set(NRF_UART0, TXPIN, RXPIN);

// Start lf clock

  nrf_clock_lf_src_set(NRF_CLOCK_LFCLK_Xtal);
  nrf_clock_event_clear(NRF_CLOCK_EVENT_LFCLKSTARTED);

  nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART);
  while (!nrf_clock_event_check(NRF_CLOCK_EVENT_LFCLKSTARTED));
  nrf_clock_event_clear(NRF_CLOCK_EVENT_LFCLKSTARTED);

  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

  testStart();
  return 0;
}
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();
        }
    }
}
示例#7
0
static void pmRunSystem(bool enable)
{
  if (enable) {
    // Release the reset pin!
    nrf_gpio_pin_set(STM_NRST_PIN);

    //Activate UART TX pin
    nrf_gpio_cfg_output(UART_TX_PIN);
    nrf_gpio_pin_set(UART_TX_PIN);

    nrf_gpio_cfg_output(PM_EN1);
    nrf_gpio_cfg_output(PM_EN2);
    // Set 500mA current
    nrf_gpio_pin_set(PM_EN1);
    nrf_gpio_pin_clear(PM_EN2);
    // 980mA current
//    nrf_gpio_pin_clear(PM_EN1);
//    nrf_gpio_pin_set(PM_EN2);

    // Enable charging
    nrf_gpio_cfg_output(PM_CHG_EN);
    nrf_gpio_pin_clear(PM_CHG_EN);

    // Enable RF power amplifier
    nrf_gpio_cfg_output(RADIO_PAEN_PIN);
#ifdef DISABLE_PA
    nrf_gpio_pin_clear(RADIO_PAEN_PIN);
#else
    nrf_gpio_pin_set(RADIO_PAEN_PIN);
#endif

    // Sink battery divider
    nrf_gpio_cfg_output(PM_VBAT_SINK_PIN);
    nrf_gpio_pin_clear(PM_VBAT_SINK_PIN);

    pmStartAdc(adcVBAT);

  } else {
    //Disable UART
    nrf_gpio_cfg_input(UART_TX_PIN, NRF_GPIO_PIN_PULLDOWN);

    //Hold reset
    nrf_gpio_pin_clear(STM_NRST_PIN);
  }
}
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
{
	// disable INTs
    CRITICAL_REGION_ENTER();

    /* Light a LED on error or warning. */
    nrf_gpio_cfg_output(SER_CONN_ASSERT_LED_PIN);
    nrf_gpio_pin_set(SER_CONN_ASSERT_LED_PIN);

   	// m_p_error_file_name = p_file_name;
    // m_error_code = error_code;
    // m_error_line_num = line_num;

    /* Do not reset when warning. */
    if(SER_WARNING_CODE != error_code)
    {
        /* This call can be used for debug purposes during application development.
        * @note CAUTION: Activating code below will write the stack to flash on an error.
        * This function should NOT be used in a final product.
        * It is intended STRICTLY for development/debugging purposes.
        * The flash write will happen EVEN if the radio is active, thus interrupting any communication.
        * Use with care. Un-comment the line below to use. */

        /* ble_debug_assert_handler(error_code, line_num, p_file_name); */

#if 0
        /* Reset the chip. Should be used in the release version. */
        NVIC_SystemReset();
#else   /* Debug version. */
        /* To be able to see function parameters in a debugger. */
        uint32_t temp = 1;
        while(temp);
#endif
        CRITICAL_REGION_EXIT();

    }
}
示例#9
0
/**@brief Function for the output pin initialization.
 *
 * @details Initializes all output pins used by the application.
 */
static void pin_output_init(void)
{
    for(uint8_t i = 0; i < PIN_OUTPUT_OFFSET; i++){ 
    nrf_gpio_cfg_output((PIN_OUTPUT_START + i));
    nrf_gpio_pin_clear((PIN_OUTPUT_START + i));
    }

    nrf_gpio_cfg_output(LED_CONNECTED_PIN);
    nrf_gpio_cfg_output(LED_ADVERTISING_PIN);
    nrf_gpio_cfg_output(LED_MOTOR_TWI_WRITE_PIN);
    nrf_gpio_cfg_output(LED_RFID_TWI_READ_PIN);

    nrf_gpio_pin_set(LED_CONNECTED_PIN);
    nrf_gpio_pin_set(LED_ADVERTISING_PIN);
    nrf_gpio_pin_set(LED_MOTOR_TWI_WRITE_PIN);
    nrf_gpio_pin_set(LED_RFID_TWI_READ_PIN);

    nrf_gpio_cfg_output(PIEZO_BUZZER_PIN);
    nrf_gpio_pin_clear(PIEZO_BUZZER_PIN);
}
/**
 * @brief Initialize PPI to toggle GPIO pins on radio events.
 */
static void radio_event_gpio_toggle_init(void)
{
    nrf_gpio_cfg_output(PIN_DBG_RADIO_EVT_END);
    nrf_gpio_cfg_output(PIN_DBG_RADIO_EVT_DISABLED);
    nrf_gpio_cfg_output(PIN_DBG_RADIO_EVT_READY);
    nrf_gpio_cfg_output(PIN_DBG_RADIO_EVT_FRAMESTART);
    nrf_gpio_cfg_output(PIN_DBG_RADIO_EVT_EDEND);
    nrf_gpio_cfg_output(PIN_DBG_RADIO_EVT_PHYEND);

    nrf_gpiote_task_configure(0, PIN_DBG_RADIO_EVT_END, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
    nrf_gpiote_task_configure(1, PIN_DBG_RADIO_EVT_DISABLED, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
    nrf_gpiote_task_configure(2, PIN_DBG_RADIO_EVT_READY, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
    nrf_gpiote_task_configure(3, PIN_DBG_RADIO_EVT_FRAMESTART, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
    nrf_gpiote_task_configure(4, PIN_DBG_RADIO_EVT_EDEND, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
    nrf_gpiote_task_configure(5, PIN_DBG_RADIO_EVT_PHYEND, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);

    nrf_gpiote_task_enable(0);
    nrf_gpiote_task_enable(1);
    nrf_gpiote_task_enable(2);
    nrf_gpiote_task_enable(3);
    nrf_gpiote_task_enable(4);
    nrf_gpiote_task_enable(5);

    nrf_ppi_channel_endpoint_setup(NRF_PPI_CHANNEL0, (uint32_t) &NRF_RADIO->EVENTS_END,        nrf_gpiote_task_addr_get(NRF_GPIOTE_TASKS_OUT_0));
    nrf_ppi_channel_endpoint_setup(NRF_PPI_CHANNEL1, (uint32_t) &NRF_RADIO->EVENTS_DISABLED,   nrf_gpiote_task_addr_get(NRF_GPIOTE_TASKS_OUT_1));
    nrf_ppi_channel_endpoint_setup(NRF_PPI_CHANNEL2, (uint32_t) &NRF_RADIO->EVENTS_READY,      nrf_gpiote_task_addr_get(NRF_GPIOTE_TASKS_OUT_2));
    nrf_ppi_channel_endpoint_setup(NRF_PPI_CHANNEL3, (uint32_t) &NRF_RADIO->EVENTS_FRAMESTART, nrf_gpiote_task_addr_get(NRF_GPIOTE_TASKS_OUT_3));
    nrf_ppi_channel_endpoint_setup(NRF_PPI_CHANNEL4, (uint32_t) &NRF_RADIO->EVENTS_EDEND,      nrf_gpiote_task_addr_get(NRF_GPIOTE_TASKS_OUT_4));
    nrf_ppi_channel_endpoint_setup(NRF_PPI_CHANNEL5, (uint32_t) &NRF_RADIO->EVENTS_PHYEND,     nrf_gpiote_task_addr_get(NRF_GPIOTE_TASKS_OUT_5));

    nrf_ppi_channel_enable(NRF_PPI_CHANNEL0);
    nrf_ppi_channel_enable(NRF_PPI_CHANNEL1);
    nrf_ppi_channel_enable(NRF_PPI_CHANNEL2);
    nrf_ppi_channel_enable(NRF_PPI_CHANNEL3);
    nrf_ppi_channel_enable(NRF_PPI_CHANNEL4);
    nrf_ppi_channel_enable(NRF_PPI_CHANNEL5);
}
示例#11
0
/**@brief     Function for the LEDs initialization.
 */
static void leds_init(void)
{
    nrf_gpio_cfg_output(ADVERTISING_LED_PIN_NO);
    nrf_gpio_cfg_output(CONNECTED_LED_PIN_NO);
    nrf_gpio_cfg_output(ASSERT_LED_PIN_NO);
}
示例#12
0
/**@brief Function for initialization of LEDs.
 */
static void leds_init(void)
{
    nrf_gpio_cfg_output(UPDATE_IN_PROGRESS_LED);
    nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED);
}
示例#13
0
int main()
{
    static char address[5];

    sd_mbr_command(&startSdCmd);
    sd_softdevice_vector_table_base_set(BOOTLOADER_ADDRESS);

    // If the master boot switch has detected short or no click: boot the firmware
    if (((NRF_POWER->GPREGRET&0x86U) != 0x82U) &&
            ((NRF_POWER->GPREGRET&0x40U) != 0x40U) &&
            (*(uint32_t *)FW_ADDRESS != 0xFFFFFFFFU) ) {
        start_firmware();
    }

    if (NRF_POWER->GPREGRET&0x40U) {
        address[4] = 0xb1;
        memcpy(&address[0], (char*)&NRF_FICR->DEVICEADDR[0], 4);
        esbSetAddress(address);
    }

    NRF_POWER->GPREGRET &= ~(0x60U);

    // Enable the radio LNA
    nrf_gpio_cfg_output(RADIO_PAEN_PIN);
    nrf_gpio_pin_set(RADIO_PAEN_PIN);

    // Initialize timer module.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);

    ble_init();
    /*
      NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSTAT_SRC_Synth;

      NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
      while(!NRF_CLOCK->EVENTS_LFCLKSTARTED);
    */
    systickInit();
    buttonInit(buttonIdle);

#ifndef DEBUG_TIMESLOT
    //sd_ppi_channel_assign(0, &(NRF_TIMER1->EVENTS_COMPARE[0]), &(NRF_GPIOTE->TASKS_OUT[0]));
    //sd_ppi_channel_enable_set(PPI_CHEN_CH0_Msk);

    //NRF_PPI->CH[0].EEP = &(NRF_TIMER1->EVENTS_COMPARE[0]);
    //NRF_PPI->CH[0].TEP = &(NRF_GPIOTE->TASKS_OUT[0]);
    //NRF_PPI->CHENSET = 1;
#endif

    // Start (or continue) to blink  the LED at 0.5Hz
    //NRF_TIMER1->TASKS_STOP = 1;

    //NRF_TIMER1->MODE      = TIMER_MODE_MODE_Timer;
    //NRF_TIMER1->PRESCALER = 7;
    //NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos;
    //NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk; // | TIMER_SHORTS_COMPARE1_CLEAR_Msk;

    //NRF_TIMER1->TASKS_CLEAR = 1;

    NRF_TIMER1->CC[0] = 1*SEC; //0x1E84 ;
    NRF_TIMER1->CC[1] = 2*SEC;


    nrf_gpio_cfg_output(LED_PIN);

    nrf_gpiote_task_config(0,
                           LED_PIN,
                           NRF_GPIOTE_POLARITY_TOGGLE,
                           NRF_GPIOTE_INITIAL_VALUE_LOW);
    NRF_TIMER1->TASKS_START = 1;


    // Enable 500mA USB input and enable battery charging
    nrf_gpio_cfg_output(PM_EN1);
    nrf_gpio_pin_set(PM_EN1);
    nrf_gpio_cfg_output(PM_EN2);
    nrf_gpio_pin_clear(PM_EN2);
    nrf_gpio_cfg_output(PM_CHG_EN);
    nrf_gpio_pin_clear(PM_CHG_EN);


    // Power STM32, hold reset
    nrf_gpio_cfg_output(PM_VCCEN_PIN);
    nrf_gpio_pin_set(PM_VCCEN_PIN);
    nrf_gpio_cfg_output(STM_NRST_PIN);
    nrf_gpio_pin_clear(STM_NRST_PIN);

    // Set flow control and activate pull-down on RX data pin
    nrf_gpio_cfg_output(UART_TX_PIN);
    nrf_gpio_pin_set(UART_TX_PIN);
    nrf_gpio_cfg_output(UART_RTS_PIN);
    nrf_gpio_pin_set(UART_RTS_PIN);
    nrf_gpio_cfg_input(UART_RX_PIN, NRF_GPIO_PIN_PULLDOWN);


    nrf_gpio_pin_set(STM_NRST_PIN);

    //systickInit();
    //syslinkInit();
    //buttonInit();

//  nrf_gpio_cfg_input(BUTTON_PIN, NRF_GPIO_PIN_PULLUP);

    mainLoop();

    while(1);
}
示例#14
0
/** @brief Function initialization and configuration of RTC driver instance.
 */
static void gpio_config(void) {
    // Configure LED-pin as outputs and clear.
    nrf_gpio_cfg_output(led_pin1);
    nrf_gpio_pin_clear(led_pin1);
}
示例#15
0
uint32_t app_uart_init(const app_uart_comm_params_t * p_comm_params,
                       app_uart_buffers_t           * p_buffers,
                       app_uart_event_handler_t       event_handler,
                       app_irq_priority_t             irq_priority,
                       uint16_t                     * p_app_uart_uid)
{
    uint32_t err_code;

    m_current_state = UART_OFF;
    m_event_handler = event_handler;
    m_rx_byte       = BYTE_INVALID;


    // Configure RX and TX pins.
    nrf_gpio_pin_set(p_comm_params->tx_pin_no);
    nrf_gpio_cfg_output(p_comm_params->tx_pin_no);
    nrf_gpio_cfg_input(p_comm_params->rx_pin_no, NRF_GPIO_PIN_PULLUP);


    NRF_UART0->PSELTXD = p_comm_params->tx_pin_no;
    NRF_UART0->PSELRXD = p_comm_params->rx_pin_no;

    // Configure baud rate and parity.
    NRF_UART0->BAUDRATE = (p_comm_params->baud_rate << UART_BAUDRATE_BAUDRATE_Pos);

    if (p_comm_params->use_parity)
    {
        NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Included << UART_CONFIG_PARITY_Pos);
    }
    else
    {
        NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos);
    }

    if (p_comm_params->flow_control == APP_UART_FLOW_CONTROL_LOW_POWER)
    {
        if (!nrf_drv_gpiote_is_init())
        {
            err_code = nrf_drv_gpiote_init();
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
        }

        // Configure hardware flow control.
        nrf_drv_gpiote_out_config_t rts_config = GPIOTE_CONFIG_OUT_SIMPLE(true);
        err_code = nrf_drv_gpiote_out_init(p_comm_params->rts_pin_no, &rts_config);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }

        NRF_UART0->PSELCTS = UART_PIN_DISCONNECTED;
        NRF_UART0->PSELRTS = p_comm_params->rts_pin_no;
        NRF_UART0->CONFIG |= (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);

        // Setup the gpiote to handle pin events on cts-pin.
        // For the UART we want to detect both low->high and high->low transitions in order to
        // know when to activate/de-activate the TX/RX in the UART.
        // Configure pin.
        nrf_drv_gpiote_in_config_t cts_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
        err_code = nrf_drv_gpiote_in_init(p_comm_params->cts_pin_no, &cts_config, gpiote_uart_event_handler);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }

        nrf_drv_gpiote_in_event_enable(p_comm_params->cts_pin_no, true);

        // UART CTS pin is active when low.
        if (nrf_drv_gpiote_in_is_set(p_comm_params->cts_pin_no))
        {
            on_uart_event(ON_CTS_HIGH);
        }
        else
        {
            on_uart_event(ON_CTS_LOW);
        }
    }
    else if (p_comm_params->flow_control == APP_UART_FLOW_CONTROL_ENABLED)
    {
        uart_standard_flow_control_init(p_comm_params);
        m_current_state = UART_READY;
    }
    else
    {
        uart_no_flow_control_init();
        m_current_state = UART_READY;
    }
    if (*p_app_uart_uid == UART_INSTANCE_ID_INVALID)
    {
        *p_app_uart_uid = m_instance_counter++;
    }

    // Enable UART interrupt
    NRF_UART0->INTENCLR = 0xffffffffUL;
    NRF_UART0->INTENSET = (UART_INTENSET_RXDRDY_Set << UART_INTENSET_RXDRDY_Pos) |
                          (UART_INTENSET_TXDRDY_Set << UART_INTENSET_TXDRDY_Pos) |
                          (UART_INTENSET_ERROR_Set << UART_INTENSET_ERROR_Pos);

    NVIC_ClearPendingIRQ(UART_IRQ);
    NVIC_SetPriority(UART_IRQ, irq_priority);
    NVIC_EnableIRQ(UART_IRQ);

    return NRF_SUCCESS;
}
示例#16
0
static int uarte_instance_init(struct device *dev,
			       const struct uarte_init_config *config,
			       u8_t interrupts_active)
{
	int err;
	NRF_UARTE_Type *uarte = get_uarte_instance(dev);
	struct uarte_nrfx_data *data = get_dev_data(dev);

	nrf_gpio_pin_write(config->pseltxd, 1);
	nrf_gpio_cfg_output(config->pseltxd);

	nrf_gpio_cfg_input(config->pselrxd, NRF_GPIO_PIN_NOPULL);

	nrf_uarte_txrx_pins_set(uarte,
				config->pseltxd,
				config->pselrxd);

	if (config->hwfc == NRF_UARTE_HWFC_ENABLED) {
		nrf_gpio_pin_write(config->pselrts, 1);
		nrf_gpio_cfg_output(config->pselrts);

		nrf_gpio_cfg_input(config->pselcts, NRF_GPIO_PIN_NOPULL);

		nrf_uarte_hwfc_pins_set(uarte,
					config->pselrts,
					config->pselcts);
	}

	/* Configure flow control and parity checking */
	nrf_uarte_configure(uarte,
			    config->parity,
			    config->hwfc);

	err = baudrate_set(dev, config->baudrate);
	if (err) {
		return err;
	}

	/* Enable receiver and transmitter */
	nrf_uarte_enable(uarte);

	nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDRX);

	nrf_uarte_rx_buffer_set(uarte, &data->rx_data, 1);
	nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTRX);

#if UARTE_INTERRUPT_DRIVEN
	if (interrupts_active) {
		/* Set ENDTX event by requesting fake (zero-length) transfer.
		 * Pointer to RAM variable (data->tx_buffer) is set because
		 * otherwise such operation may result in HardFault or RAM
		 * corruption.
		 */
		nrf_uarte_tx_buffer_set(uarte, data->tx_buffer, 0);
		nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTTX);

		/* switch off transmitter to save an energy */
		nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPTX);
	}
#endif /* UARTE_INTERRUPT_DRIVEN */

	return 0;
}
示例#17
0
// Application main function.
int main(void)
{
    uint32_t err_code;

    // set up timers
    APP_TIMER_INIT(0, 4, 4, false);

    // initlialize BLE
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();

    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);

    // init GPIOTE
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);

    // init PPI
    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    // intialize UART
    uart_init();

    // prints to serial port
    printf("starting...\n");

    // Create the instance "PWM1" using TIMER1.
    APP_PWM_INSTANCE(PWM1,1);                   

    // RGB LED pins
    // (Common cathode)
    uint32_t pinR = 1;
    uint32_t pinG = 2;
    uint32_t pinB = 3;
   
    // 2-channel PWM, 200Hz
    app_pwm_config_t pwm1_cfg = 
      APP_PWM_DEFAULT_CONFIG_2CH(5000L, pinR, pinG);

    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM1);

    // Create the instance "PWM2" using TIMER2.
    APP_PWM_INSTANCE(PWM2,2);                   
 
    // 1-channel PWM, 200Hz
    app_pwm_config_t pwm2_cfg = 
      APP_PWM_DEFAULT_CONFIG_1CH(5000L, pinB);

    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&PWM2,&pwm2_cfg,pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM2);


    // Enter main loop.
    int dir = 1;
    int val = 0;

    // main loop:
    bool pwmEnabled = true;

    while(1) {

      // only if not paused 
      if (!pausePWM) {
        
        // enable disable as needed
        if(!enablePWM) {
          if(pwmEnabled) {
            app_pwm_disable(&PWM1);
            app_pwm_disable(&PWM2);

            // This is required becauase app_pwm_disable()
            // has a bug. 
            // See: 
            // https://devzone.nordicsemi.com/question/41179/how-to-stop-pwm-and-set-pin-to-clear/
            nrf_drv_gpiote_out_task_disable(pinR);
            nrf_gpio_cfg_output(pinR);
            nrf_gpio_pin_clear(pinR);
            nrf_drv_gpiote_out_task_disable(pinG);
            nrf_gpio_cfg_output(pinG);
            nrf_gpio_pin_clear(pinG);
            nrf_drv_gpiote_out_task_disable(pinB);
            nrf_gpio_cfg_output(pinB);
            nrf_gpio_pin_clear(pinB);

            pwmEnabled = false;
          }
        }
        else {
          if(!pwmEnabled) {

            // enable PWM 

            nrf_drv_gpiote_out_task_enable(pinR);
            nrf_drv_gpiote_out_task_enable(pinG);
            nrf_drv_gpiote_out_task_enable(pinB);

            app_pwm_enable(&PWM1);
            app_pwm_enable(&PWM2);
            pwmEnabled = true;
          }
        }

        if(pwmEnabled) {
          // Set the duty cycle - keep trying until PWM is ready
          while (app_pwm_channel_duty_set(&PWM1, 0, val) == NRF_ERROR_BUSY);
          while (app_pwm_channel_duty_set(&PWM1, 1, val) == NRF_ERROR_BUSY);
          while (app_pwm_channel_duty_set(&PWM2, 0, val) == NRF_ERROR_BUSY);
        }
        
        // change direction at edges
        if(val > 99) {
          dir = -1;
        }
        else if (val < 1){
          dir = 1;
        }
        // increment/decrement
        val += dir*5;
      }      
      // delay
      nrf_delay_ms(delay);
    }
}
示例#18
0
文件: led.c 项目: pfalcon/micropython
void led_init(void) {
    for (uint8_t i = 0; i < NUM_LEDS; i++) {
        LED_OFF((board_led_obj_t*)&board_led_obj[i]);
        nrf_gpio_cfg_output(board_led_obj[i].hw_pin);
    }
}
示例#19
0
uint32_t spi_master_open(const spi_master_hw_instance_t    spi_master_hw_instance,
                         spi_master_config_t const * const p_spi_master_config)
{
    #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE)

    /* Check against null */
    if (p_spi_master_config == NULL)
    {
        return NRF_ERROR_NULL;
    }

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

    switch (spi_master_hw_instance)
    {
    #ifdef SPI_MASTER_0_ENABLE
        case SPI_MASTER_0:
            spi_master_init_hw_instance(NRF_SPI0, SPI0_TWI0_IRQn, p_spi_instance, p_spi_master_config->SPI_DisableAllIRQ);
            break;
    #endif /* SPI_MASTER_0_ENABLE */

    #ifdef SPI_MASTER_1_ENABLE
        case SPI_MASTER_1:
            spi_master_init_hw_instance(NRF_SPI1, SPI1_TWI1_IRQn, p_spi_instance, p_spi_master_config->SPI_DisableAllIRQ);
            break;
    #endif /* SPI_MASTER_1_ENABLE */

        default:
            break;
    }

    //A Slave select must be set as high before setting it as output,
    //because during connect it to the pin it causes glitches.
    nrf_gpio_pin_set(p_spi_master_config->SPI_Pin_SS);
    nrf_gpio_cfg_output(p_spi_master_config->SPI_Pin_SS);
    nrf_gpio_pin_set(p_spi_master_config->SPI_Pin_SS);

    //Configure GPIO
    nrf_gpio_cfg_output(p_spi_master_config->SPI_Pin_SCK);
    nrf_gpio_cfg_output(p_spi_master_config->SPI_Pin_MOSI);
    nrf_gpio_cfg_input(p_spi_master_config->SPI_Pin_MISO, NRF_GPIO_PIN_NOPULL);
    p_spi_instance->pin_slave_select = p_spi_master_config->SPI_Pin_SS;

    /* Configure SPI hardware */
    p_spi_instance->p_nrf_spi->PSELSCK  = p_spi_master_config->SPI_Pin_SCK;
    p_spi_instance->p_nrf_spi->PSELMOSI = p_spi_master_config->SPI_Pin_MOSI;
    p_spi_instance->p_nrf_spi->PSELMISO = p_spi_master_config->SPI_Pin_MISO;

    p_spi_instance->p_nrf_spi->FREQUENCY = p_spi_master_config->SPI_Freq;

    p_spi_instance->p_nrf_spi->CONFIG =
        (uint32_t)(p_spi_master_config->SPI_CONFIG_CPHA << SPI_CONFIG_CPHA_Pos) |
        (p_spi_master_config->SPI_CONFIG_CPOL << SPI_CONFIG_CPOL_Pos) |
        (p_spi_master_config->SPI_CONFIG_ORDER << SPI_CONFIG_ORDER_Pos);

    /* Clear waiting interrupts and events */
    p_spi_instance->p_nrf_spi->EVENTS_READY = 0;

    APP_ERROR_CHECK(sd_nvic_ClearPendingIRQ(p_spi_instance->irq_type));
    APP_ERROR_CHECK(sd_nvic_SetPriority(p_spi_instance->irq_type, p_spi_master_config->SPI_PriorityIRQ));

    /* Clear event handler */
    p_spi_instance->callback_event_handler = NULL;

    /* Enable interrupt */
    p_spi_instance->p_nrf_spi->INTENSET = (SPI_INTENSET_READY_Set << SPI_INTENCLR_READY_Pos);
    APP_ERROR_CHECK(sd_nvic_EnableIRQ(p_spi_instance->irq_type));

    /* Enable SPI hardware */
    p_spi_instance->p_nrf_spi->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos);

    /* Change state to IDLE */
    p_spi_instance->state = SPI_MASTER_STATE_IDLE;

    return NRF_SUCCESS;
    #else
    return NRF_ERROR_NOT_SUPPORTED;
    #endif
}
示例#20
0
int main(void)
{
    bool init_status;
    int retValue;
	int i = defaultPerso.fall_detection_window;

    // initialize LEDs
    nrf_gpio_cfg_output(LED_RESETTING);
    nrf_gpio_cfg_output(LED_NO_FALL);
    nrf_gpio_cfg_output(LED_FALL_DETECTED);
		nrf_gpio_cfg_output(LED_OTHER);
		
		welcomeLEDs();

    // Initialize
    timers_init();
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
    sec_params_init();
    twi_master_init();
		
#ifdef TEST_ACTIVITY_LOG		
		testActivityLog();
#endif
		
		initActivityLog();
		initSnapshotBuffer();
		initCoefficients();

    // initialize values
    retValue = 0;

    init_status = mpu6050_init(MPU6050_DEVICE_ADDR);
    if ( false == init_status )
    {
        init_status = mpu6050_init(MPU6050_DEVICE_ADDR+1);
        if ( false == init_status )
        {   
            retValue = -1;
						errorLEDs();
					sd_nvic_SystemReset();
        }
    }
    if ( 0 == retValue )
    {    
      init_status = false;

			
			i = 0;
        while ( false == init_status )
        {
          if (i == 6) 
					{
						errorLEDs();
						sd_nvic_SystemReset();
					}
					
					init_status = accel_setup();
					i++;
					
				}
    }
		
		
    if (0 == retValue) {
			 
			char outbuf[20];
			
			// Start execution - write a log entry with zero steps to indicate startup
				
//				writeLogEntry(999);
        advertising_start();
				setup_wdt();
        timers_start(); // start sampliing
        
        while(1)
        {
					if (ReadSnapshots == 1)
					{

						FullSnapshotEntry* entry = (FullSnapshotEntry*)(SNAPSHOT_DATA_ADDRESS_START) ;
						
						SnapshotHeader *h;
						Sensor_Reading *r;

            sprintf (outbuf, "ID: %s                                   ", getPerso()->uname);    
						ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
                

                for(int i=0;i < getActivityLogSize(); i++)
                {
                  h = &entry->hdr;
									
									sprintf (outbuf, ": SNAPSHOT # %d  \n                           ",(i));
									ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 16);
									
									sprintf (outbuf, "Version: 2 \n");//
									ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 12);
									
									sprintf (outbuf, "t:%d n:%d last:%d",h->data.time, h->data.num_of_data_points, h->data.latest_data_point_index);
									ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
//									ptr++;
								
									r = entry->r;
										
									for (int j = 0; j < NUMBER_OF_ENTRIES; j++)
									{
										#define FLASH_READ_DELAY 40
										nrf_gpio_pin_set(LED_RESETTING); 
		
										sprintf (outbuf, "i: %d T: %04x           ",j,r[j].val.temp);
										ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
										
										nrf_delay_ms(FLASH_READ_DELAY);

										sprintf (outbuf, "A: x%04xy%04xz%04x",r[j].val.x_ac,r[j].val.y_ac,r[j].val.z_ac);
										ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
										
										nrf_delay_ms(FLASH_READ_DELAY);
								
										sprintf (outbuf, "G: x%04xy%04xz%04x",r[j].val.x_gy,r[j].val.y_gy,r[j].val.z_gy);
										ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
										
										nrf_delay_ms(FLASH_READ_DELAY);
										
										nrf_gpio_pin_clear(LED_RESETTING);
										
										nrf_delay_ms(FLASH_READ_DELAY);
										
										//ptr += sizeof(Sensor_Reading);
										

									}
									entry++;
                    
									
                    
                }  	
						
						
						ReadSnapshots = 0;
					}

					if (ReadSnapshotsPartial == 1)
					{
						
						PartialSnapTotal = ((PartialSnap1-('0'))*10)+(PartialSnap2-('0'));
						
						FullSnapshotEntry* entry = (FullSnapshotEntry*)(SNAPSHOT_DATA_ADDRESS_START+(((PartialSnapTotal*sizeof(FullSnapshotEntry)*10))/4)) ;
						
						SnapshotHeader *h;
						Sensor_Reading *r;

            sprintf (outbuf, "ID: %s                                   ", getPerso()->uname);    
						ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
                

                for(int i=0;i < 10; i++)
                {
                  h = &entry->hdr;
									
									sprintf (outbuf, ": SNAPSHOT # %d  \n                           ",(i+(PartialSnapTotal*10)));
									ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 16);
									
									sprintf (outbuf, "Version: 2 \n");//
									ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 12);
									
									sprintf (outbuf, "t:%d n:%d last:%d",h->data.time, h->data.num_of_data_points, h->data.latest_data_point_index);
									ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
//									ptr++;
								
									r = entry->r;
										
									for (int j = 0; j < NUMBER_OF_ENTRIES; j++)
									{
										#define FLASH_READ_DELAY 40
										nrf_gpio_pin_set(LED_RESETTING); 
		
										sprintf (outbuf, "i: %d T: %04x           ",j,r[j].val.temp);
										ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
										
										nrf_delay_ms(FLASH_READ_DELAY);

										sprintf (outbuf, "A: x%04xy%04xz%04x",r[j].val.x_ac,r[j].val.y_ac,r[j].val.z_ac);
										ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
										
										nrf_delay_ms(FLASH_READ_DELAY);
								
										sprintf (outbuf, "G: x%04xy%04xz%04x",r[j].val.x_gy,r[j].val.y_gy,r[j].val.z_gy);
										ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
										
										nrf_delay_ms(FLASH_READ_DELAY);
										
										nrf_gpio_pin_clear(LED_RESETTING);
										
										nrf_delay_ms(FLASH_READ_DELAY);
										
										//ptr += sizeof(Sensor_Reading);
										

									}
									entry++;
                    
									
                    
                }  	
						
						
						ReadSnapshotsPartial = 0;
					}
					
					if (ReadDataBuffer == 1)
					{
						LogEntry *addr;
 
			
						sprintf (outbuf, "ID: %s                                   ", getPerso()->uname);
							ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
							
						addr = (LogEntry *)(STEP_DATA_ADDRESS_START);
							for(int i=0;i < getActivityLogSize(); i++)
							{
								nrf_gpio_pin_set(LED_RESETTING); 
								nrf_delay_ms(20);
								nrf_gpio_pin_clear(LED_RESETTING);
								nrf_delay_ms(20);  
								
									
					//			sprintf ( outbuf, ": h:%d s:%d a:%04f                                   ",addr->item.hour, addr->item.sec, addr->item.activity_level);
								sprintf ( outbuf, "%d:%d - %03f                                   ",addr->item.hour, (addr->item.sec)/60, addr->item.activity_level);
									ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
									//nrf_delay_ms(1);
								addr++;
									
							}  
							ReadDataBuffer = 0;
					}

					if (ReadDataBufferPartial == 1)
					{
						LogEntry *addr;
 
			
						sprintf (outbuf, "ID: %s                                   ", getPerso()->uname);
							ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
						
						PartialCountTotal = ((PartialCount1-('0'))*10)+(PartialCount2-('0'));							
						
						addr = (LogEntry *)(STEP_DATA_ADDRESS_START+(2*(PartialCountTotal*1000)));

							for(int i=0;i < 1000; i++)
							{
								nrf_gpio_pin_set(LED_RESETTING); 
								nrf_delay_ms(20);
								nrf_gpio_pin_clear(LED_RESETTING);
								nrf_delay_ms(20);  
								
									
					//			sprintf ( outbuf, ": h:%d s:%d a:%04f                                   ",addr->item.hour, addr->item.sec, addr->item.activity_level);
								sprintf ( outbuf, "%d:%d - %03f                                   ",addr->item.hour, (addr->item.sec)/60, addr->item.activity_level);
									ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
									//nrf_delay_ms(1);
								addr++;
									
							}  
							ReadDataBufferPartial = 0;
					}
				 
					if (Dumper == 1)
					{
						
						sprintf (outbuf, "Log: %d                                   ",getActivityLogSize());
							ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);   

							Dumper = 0;
					}
					
					if (ReadBigSnapshot == 1)
					{	
						SnapshotHeader *h = getSnapshotHeader();
						
						sprintf (outbuf, "t:%d n:%d last:%d",h->data.time, h->data.num_of_data_points, h->data.latest_data_point_index);
						ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
						
						for (i = 0; i < NUMBER_OF_ENTRIES; i++) //i <= h->data.latest_data_point_index; i++)
						{      
							#define RAM_READ_DELAY 15
							
							sprintf (outbuf, "i: %d T: %04x           ",i,raw_data[i].val.temp);
							ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
							nrf_delay_ms(RAM_READ_DELAY);

							sprintf (outbuf, "A: x%04xy%04xz%04x",raw_data[i].val.x_ac,raw_data[i].val.y_ac,raw_data[i].val.z_ac);
							ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
							nrf_delay_ms(RAM_READ_DELAY);

							sprintf (outbuf, "G: x%04xy%04xz%04x",raw_data[i].val.x_gy,raw_data[i].val.y_gy,raw_data[i].val.z_gy);
							ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20);
							nrf_delay_ms(RAM_READ_DELAY);
							
							
						}
						
						ReadBigSnapshot = 0;
						
					}
												
					if (do_post_processing == true)
					{
						do_post_processing = false;
						
						if (emergencyCall == 1) 
							{
								makeTheCall();
								emergencyCall = 0;
							}
						
						post_comm_processing();
						
					}
				
        // Power Method 1
				//		nrf_gpio_pin_write(LED_OTHER,1);
           // power_manage();
				//		nrf_gpio_pin_write(LED_OTHER,0);
        }
    }
    return retValue;

		
}
示例#21
0
/*******************************************************************************
* Function Name  : SSD1306_Init
* Description    : Initialize display
*******************************************************************************/
void SSD1306_Init()
{
    nrf_gpio_cfg_output(D_CS);
    nrf_gpio_cfg_output(D_DC);
    nrf_gpio_cfg_output(D_RESET);

    nrf_gpio_cfg_output(SPI_CLK);
    nrf_gpio_cfg_output(SPI_MOSI);
    NRF_SPI0->PSELSCK = SPI_CLK;
    NRF_SPI0->PSELMOSI = SPI_MOSI;
    NRF_SPI0->FREQUENCY = (uint32_t) 0x80000000;//0x02000000
    NRF_SPI0->CONFIG =  (SPI_CONFIG_CPHA_Leading << SPI_CONFIG_CPHA_Pos) |
                        (SPI_CONFIG_CPOL_ActiveHigh << SPI_CONFIG_CPOL_Pos) |
                        (SPI_CONFIG_ORDER_MsbFirst << SPI_CONFIG_ORDER_Pos);
    NRF_SPI0->EVENTS_READY = 0U;
    NRF_SPI0->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos);

	RESET_H;
	nrf_delay_us(10000);
	RESET_L;
	nrf_delay_us(50000);
	RESET_H;

	// Init sequence for 128x64 OLED module
	SSD1306_Command(SSD1306_DISPLAYOFF);                    // 0xAE
	SSD1306_Command(SSD1306_SETDISPLAYCLOCKDIV);            // 0xD5
	SSD1306_Command(0x80);                                  // the suggested ratio 0x80
	SSD1306_Command(SSD1306_SETMULTIPLEX);                  // 0xA8
	SSD1306_Command(0x3F);
	SSD1306_Command(SSD1306_SETDISPLAYOFFSET);              // 0xD3
	SSD1306_Command(0x0);                                   // no offset
	SSD1306_Command(SSD1306_SETSTARTLINE | 0x0);            // line #0
	SSD1306_Command(SSD1306_CHARGEPUMP);                    // 0x8D
#if 0
	   SSD1306_Command(0x10); // SSD1306_EXTERNALVCC
#else
	   SSD1306_Command(0x14);
#endif

	SSD1306_Command(SSD1306_MEMORYMODE);                    // 0x20
	SSD1306_Command(0x00);                                  // 0x0 act like ks0108
	SSD1306_Command(SSD1306_SEGREMAP | 0x1);
	SSD1306_Command(SSD1306_COMSCANDEC);
	SSD1306_Command(SSD1306_SETCOMPINS);                    // 0xDA
	SSD1306_Command(0x12);
	SSD1306_Command(SSD1306_SETCONTRAST);                   // 0x81

#if 0
	SSD1306_Command(0x9F); // SSD1306_EXTERNALVCC)
#else
	SSD1306_Command(0xCF);
#endif

	SSD1306_Command(SSD1306_SETPRECHARGE);                  // 0xd9

#if 0
	SSD1306_Command(0x22); // SSD1306_EXTERNALVCC)
#else
	SSD1306_Command(0xF1);
#endif

	SSD1306_Command(SSD1306_SETVCOMDETECT);                 // 0xDB
	SSD1306_Command(0x40);
	SSD1306_Command(SSD1306_DISPLAYALLON_RESUME);           // 0xA4
	SSD1306_Command(SSD1306_NORMALDISPLAY);                 // 0xA6

	SSD1306_Command(SSD1306_DISPLAYON);						//--turn on oled panel

nrf_delay_us(100000);
	//SSD1306_ReDraw();

	//orient = LANDSCAPE;
	orient = PORTRAIT;
}
示例#22
0
/*JSON{
  "type" : "function",
  "name" : "show",
  "generate" : "jswrap_microbit_show",
  "params" : [
     ["image","JsVar","The image to show"]
  ]
}
Show an image on the in-built 5x5 LED screen.

Image can be:

* A number where each bit represents a pixel (so 25 bits)

*/
void jswrap_microbit_show(JsVar *image) {
  if (!jsvIsInt(image)) {
    jsError("Expecting a number, got %t\n", image);
    return;
  }
  uint32_t newState = jsvGetInteger(image);

  if ((newState!=0) && (microbitLEDState==0)) {
    // we want to display something but we don't have an interval
    jstExecuteFn(jswrap_microbit_display_callback, jshGetTimeFromMilliseconds(5));
    // and also set pins to outputs
    nrf_gpio_cfg_output(MB_LED_COL1);
    nrf_gpio_cfg_output(MB_LED_COL2);
    nrf_gpio_cfg_output(MB_LED_COL3);
    nrf_gpio_cfg_output(MB_LED_COL4);
    nrf_gpio_cfg_output(MB_LED_COL5);
    nrf_gpio_cfg_output(MB_LED_COL6);
    nrf_gpio_cfg_output(MB_LED_COL7);
    nrf_gpio_cfg_output(MB_LED_COL8);
    nrf_gpio_cfg_output(MB_LED_COL9);
    nrf_gpio_cfg_output(MB_LED_ROW1);
    nrf_gpio_cfg_output(MB_LED_ROW2);
    nrf_gpio_cfg_output(MB_LED_ROW3);
  } else  if ((newState==0) && (microbitLEDState!=0)) {
    jswrap_microbit_stopDisplay();
  }
  microbitLEDState = newState;
}
示例#23
0
文件: led.c 项目: tigerzhh/ADC_Test
void LED_Init(void)
{
  // Configure LED-pins as outputs
  nrf_gpio_cfg_output(LED_0);
  nrf_gpio_cfg_output(LED_1);
}
示例#24
0
文件: main.c 项目: Hom-Wang/SmartBLE
/*====================================================================================================*/
void GPIO_Config( void )
{
  nrf_gpio_range_cfg_output(1, 6);
  nrf_gpio_cfg_output(8);
}
示例#25
0
void pinMode(uint32_t pin, int mode) {
	if (mode == OUTPUT) {
		nrf_gpio_cfg_output(pin);
	}
}
示例#26
0
uint32_t* spi_master_init(SPIModuleNumber module_number, SPIMode mode, bool lsb_first)
{
    uint32_t config_mode;

    NRF_SPI_Type *spi_base_address = (SPI0 == module_number)? NRF_SPI0 : (NRF_SPI_Type *)NRF_SPI1;

    if(SPI0 == module_number)
    {
        /* Configure GPIO pins used for pselsck, pselmosi, pselmiso and pselss for SPI0 */
        nrf_gpio_cfg_output(SPI_PSELSCK0);
        nrf_gpio_cfg_output(SPI_PSELMOSI0);
        nrf_gpio_cfg_input(SPI_PSELMISO0, NRF_GPIO_PIN_NOPULL);
        nrf_gpio_cfg_output(SPI_PSELSS0);

        /* Configure pins, frequency and mode */
        spi_base_address->PSELSCK  = SPI_PSELSCK0;
        spi_base_address->PSELMOSI = SPI_PSELMOSI0;
        spi_base_address->PSELMISO = SPI_PSELMISO0;
        nrf_gpio_pin_set(SPI_PSELSS0); /* disable Set slave select (inactive high) */
    }
    else
    {
        /* Configure GPIO pins used for pselsck, pselmosi, pselmiso and pselss for SPI1*/
        nrf_gpio_cfg_output(SPI_PSELSCK1);
        nrf_gpio_cfg_output(SPI_PSELMOSI1);
        nrf_gpio_cfg_input(SPI_PSELMISO1, NRF_GPIO_PIN_NOPULL);
        nrf_gpio_cfg_output(SPI_PSELSS1);

        /* Configure pins, frequency and mode */
        spi_base_address->PSELSCK  = SPI_PSELSCK1;
        spi_base_address->PSELMOSI = SPI_PSELMOSI1;
        spi_base_address->PSELMISO = SPI_PSELMISO1;
        nrf_gpio_pin_set(SPI_PSELSS1);         /* disable Set slave select (inactive high) */
    }

    spi_base_address->FREQUENCY = (uint32_t) SPI_OPERATING_FREQUENCY;

    /*lint -e845 -save // A zero has been given as right argument to operator '!'" */
    /** @snippet [SPI Select mode] */
    switch (mode )
    {
       
        case SPI_MODE0:
            config_mode = (SPI_CONFIG_CPHA_Leading << SPI_CONFIG_CPHA_Pos) | (SPI_CONFIG_CPOL_ActiveHigh << SPI_CONFIG_CPOL_Pos);
            break;
        case SPI_MODE1:
            config_mode = (SPI_CONFIG_CPHA_Trailing << SPI_CONFIG_CPHA_Pos) | (SPI_CONFIG_CPOL_ActiveHigh << SPI_CONFIG_CPOL_Pos);
            break;
        case SPI_MODE2:
            config_mode = (SPI_CONFIG_CPHA_Leading << SPI_CONFIG_CPHA_Pos) | (SPI_CONFIG_CPOL_ActiveLow << SPI_CONFIG_CPOL_Pos);
            break;
        case SPI_MODE3:
            config_mode = (SPI_CONFIG_CPHA_Trailing << SPI_CONFIG_CPHA_Pos) | (SPI_CONFIG_CPOL_ActiveLow << SPI_CONFIG_CPOL_Pos);
            break;
        default:
            config_mode = 0;
            break;
    
    }
    /** @snippet [SPI Select mode] */
    /*lint -restore */

    /*lint -e845 -save // A zero has been given as right argument to operator '!'" */
    /** @snippet [SPI Select endianess] */
    if (lsb_first)
    {
        spi_base_address->CONFIG = (config_mode | (SPI_CONFIG_ORDER_LsbFirst << SPI_CONFIG_ORDER_Pos));
    }
    else
    {
        spi_base_address->CONFIG = (config_mode | (SPI_CONFIG_ORDER_MsbFirst << SPI_CONFIG_ORDER_Pos));
    }
    /** @snippet [SPI Select endianess] */
    /*lint -restore */

    spi_base_address->EVENTS_READY = 0U;

    /* Enable */
    spi_base_address->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos);

    return (uint32_t *)spi_base_address;
}
/**@brief Function for the LEDs initialization.
 *
 * @details Initializes all LEDs used by this application.
 */
static void leds_init(void)
{
    nrf_gpio_cfg_output(LED_RQ_PENDING);
    nrf_gpio_cfg_output(LED_CONNECTED);
}
示例#28
0
// Initialize IO
static void rino_init(void)
{
	nrf_gpio_pin_clear(NRF51_TO_RT5350_MAIL_IO);
	nrf_gpio_cfg_output(NRF51_TO_RT5350_MAIL_IO);
	nrf_gpio_pin_clear(NRF51_TO_RT5350_MAIL_IO);
}
示例#29
0
/**@brief Function for initialization of LEDs.
 */
static void leds_init(void)
{
    nrf_gpio_cfg_output(LED_0);
    nrf_gpio_cfg_output(LED_1);
}
示例#30
0
/**@brief Init the SPI and the CS pin.
 */
void spi_init(){
	sdcard_spi_addr = spi_master_init(SPI0, SPI_MODE0, 0);
	nrf_gpio_cfg_output(MMCSD_PIN_SELECT);
	nrf_gpio_pin_set(MMCSD_PIN_SELECT);
}