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); }
void debug_init(hci_dbg_event_handler_t evt_callback) { //Configure all LED as outputs. nrf_gpio_range_cfg_output(LED_START, LED_STOP); nrf_gpio_cfg_output(PIO_SLIP_EVT_PKT_TX); nrf_gpio_cfg_output(PIO_SLIP_EVT_ACK_TX); nrf_gpio_cfg_output(PIO_SLIP_EVT_PKT_TXED); nrf_gpio_cfg_output(PIO_SLIP_EVT_ACK_TXED); nrf_gpio_cfg_output(PIO_SLIP_EVT_PKT_RXED); nrf_gpio_cfg_output(PIO_SLIP_EVT_ACK_RXED); nrf_gpio_cfg_output(PIO_TIMER_EVT_TIMEOUT); nrf_gpio_cfg_output(PIO_HCI_RETX); nrf_gpio_cfg_output(PIO_MAIN_BUSY); nrf_gpio_cfg_output(PIO_TX_REQ); m_hci_dbg_event_handler = evt_callback; if (evt_callback) { m_hci_dbg_event_handler = evt_callback; } else { m_hci_dbg_event_handler = default_hci_event_handler; } }
uint32_t sdm_rx_init(void) { #if defined(TRACE_UART) app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_DISABLED, false, UART_BAUDRATE_BAUDRATE_Baud38400 }; uint32_t err_code; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOW, err_code); APP_ERROR_CHECK(err_code); #endif // TRACE_UART #if defined(TRACE_GPIO) // Configure pins LED_0 and LED_1 as outputs. nrf_gpio_range_cfg_output(SDM_GPIO_START, SDM_GPIO_STOP); // Reset the pins if they already are in a high state. nrf_gpio_pin_clear(SDM_GPIO_0); nrf_gpio_pin_clear(SDM_GPIO_1); nrf_gpio_pin_clear(SDM_GPIO_2); #endif // TRACE_GPIO return NRF_SUCCESS; }
int main(void) { /* Silence the compiler */ (void) g_sd_assert_pc; (void) g_evt; uart_init(); char start_msg[128]; sprintf(&start_msg[0], "\n| %s |---------------------------------------------------\r\n\n", __TIME__); uart_putstring((uint8_t*) &start_msg[0]); nrf_gpio_range_cfg_output(0, 30); for(int i = LED_START; i <= LED_STOP; ++i) nrf_gpio_pin_set(i); uint32_t error_code = sd_softdevice_enable((uint32_t)NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, sd_assert_cb); APP_ERROR_CHECK(error_code); error_code = sd_nvic_EnableIRQ(SD_EVT_IRQn); APP_ERROR_CHECK(error_code); ble_setup(); /* Enable a generic SD advertiser to display concurrent operation */ nrf_adv_conn_init(); while (true) { sd_app_evt_wait(); } }
/**@brief Function for initializing the client handling. */ void client_handling_init(void) { uint32_t err_code; uint32_t i; ble_uuid128_t base_uuid = MULTILINK_PERIPHERAL_BASE_UUID; err_code = sd_ble_uuid_vs_add(&base_uuid, &m_base_uuid_type); APP_ERROR_CHECK(err_code); nrf_gpio_range_cfg_output(8, 15); for (i = 0; i < MAX_CLIENTS; i++) { m_client[i].state = IDLE; } m_client_count = 0; db_discovery_init(); // Register with discovery module for the discovery of the service. ble_uuid_t uuid; uuid.type = m_base_uuid_type; uuid.uuid = MULTILINK_PERIPHERAL_SERVICE_UUID; err_code = ble_db_discovery_register(&uuid, db_discovery_evt_handler); APP_ERROR_CHECK(err_code); }
static void init_leds(void) { #ifdef DEBUG_LEDS nrf_gpio_range_cfg_output(21, 24); NRF_GPIO->OUT = (1 << 22) | (1 << 21) | (1 << 24); #endif }
/**@brief Function for application main entry. Does not return. */ int main(void) { bool is_test_success; // Configure all LEDs as outputs. nrf_gpio_range_cfg_output(LED_START, LED_STOP); // Set LED_0 high to indicate that the application is running. nrf_gpio_pin_set(LED_0); for (;;) { is_test_success = test_spi_tx_rx(); if (!is_test_success) { // Set LED2 high to indicate that error has occurred. nrf_gpio_pin_set(LED_2); for (;;) { // No implementation needed. } } nrf_gpio_pin_toggle(LED_1); nrf_delay_ms(DELAY_MS); } }
/** * main() function * @return 0. int return type required by ANSI/ISO standard. */ int main(void) { /* Start 16 MHz crystal oscillator */ NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1; /* Wait for the external oscillator to start up */ while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { } // Set Port 1 as output nrf_gpio_range_cfg_output(8, 15); // Set radio configuration parameters radio_configure(); nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, 0x55); while(true) { // Set payload pointer NRF_RADIO->PACKETPTR = (uint32_t)packet; NRF_RADIO->EVENTS_READY = 0U; // Enable radio and wait for ready NRF_RADIO->TASKS_RXEN = 1U; while(NRF_RADIO->EVENTS_READY == 0U) { } NRF_RADIO->EVENTS_END = 0U; // Start listening and wait for address received event NRF_RADIO->TASKS_START = 1U; // Wait for end of packet while(NRF_RADIO->EVENTS_END == 0U) { } // Write received data to port 1 on CRC match if (NRF_RADIO->CRCSTATUS == 1U) { nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, packet[0]); } NRF_RADIO->EVENTS_DISABLED = 0U; // Disable radio NRF_RADIO->TASKS_DISABLE = 1U; while(NRF_RADIO->EVENTS_DISABLED == 0U) { } } }
/*====================================================================================================*/ void GPIO_Config( void ) { nrf_gpio_range_cfg_output(LED_R, LED_B); LEDR_Set(); LEDG_Set(); LEDB_Set(); }
/** Configure pins 0-7 as inputs and 8-15 as outputs. * */ static void init(void) { // Port0 (0-7 as inputs) nrf_gpio_range_cfg_input(0, 7, NRF_GPIO_PIN_NOPULL); // Port1 (8-15 as outputs) nrf_gpio_range_cfg_output(8, 15); }
/** * @brief Function for application main entry. * @return 0. int return type required by ANSI/ISO standard. */ int main(void) { const uint8_t *key_packet; uint8_t key_packet_size; #ifdef USE_UART simple_uart_config(0, SIMPLE_UART_TXD_PIN_NUMBER, 0, SIMPLE_UART_RXD_PIN_NUMBER, false); // Hardware flow control not used in this example. #else // Configure pins 24-30 for LEDs. Note that pin 31 is not connected. nrf_gpio_range_cfg_output(24, 30); #endif // Enable pulldowns on row port, see matrix_row_port. nrf_gpio_range_cfg_input(16, 23, NRF_GPIO_PIN_PULLDOWN); // Column pin configuration, see matrix_column_port. nrf_gpio_range_cfg_output(0, 15); if (cherry8x16_init(matrix_row_port, matrix_column_port, CHERRY8x16_DEFAULT_KEY_LOOKUP_MATRIX) != CHERRY8x16_OK) { #ifdef USE_UART simple_uart_putstring((const uint8_t *)"Init failed."); #else nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT3, 0x55); #endif while (true) { // Do nothing. } } while(true) { if (cherry8x16_new_packet(&key_packet, &key_packet_size)) { #ifdef USE_UART // Send the whole key packet over UART. uart_puthidstring((char*)&key_packet[KEY_PACKET_KEY_INDEX]); #else // Show modifier key state using the LEDs. Note LED's use GPIO pins from 8 to 15. nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT3, key_packet[KEY_PACKET_MODIFIER_KEY_INDEX]); #endif } nrf_delay_ms(25); } }
/** @brief Function for configuring pins 0-7 as inputs and 8-15 as outputs. * */ static void init(void) { // Port0 (0-7 as inputs) nrf_gpio_range_cfg_input(BUTTON_START, BUTTON_STOP, BUTTON_PULL); // Port1 (8-15 as outputs) nrf_gpio_range_cfg_output(LED_START, LED_STOP); }
/** * 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); }
/** * @brief Function for application main entry. */ int main(void) { // Start 16 MHz crystal oscillator. NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1; // Wait for the external oscillator to start up. while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { // Do nothing. } // Set Port 0 as input. nrf_gpio_range_cfg_input(BUTTON_START, BUTTON_STOP, BUTTON_PULL); // Set Port 1 as output. nrf_gpio_range_cfg_output(LED_START, LED_STOP); // Set radio configuration parameters. radio_configure(); // Set payload pointer. NRF_RADIO->PACKETPTR = (uint32_t)packet; while (true) { // Read Data to send, button signals are default high, and low when pressed. packet[0] = ~(nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0)); // Write GPIO to payload byte 0. NRF_RADIO->EVENTS_READY = 0U; NRF_RADIO->TASKS_TXEN = 1; // Enable radio and wait for ready. while (NRF_RADIO->EVENTS_READY == 0U) { // Do nothing. } // Start transmission. NRF_RADIO->TASKS_START = 1U; NRF_RADIO->EVENTS_END = 0U; while (NRF_RADIO->EVENTS_END == 0U) // Wait for end of the transmission packet. { // Do nothing. } // Write sent data to port 1. nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, packet[0]); NRF_RADIO->EVENTS_DISABLED = 0U; NRF_RADIO->TASKS_DISABLE = 1U; // Disable the radio. while (NRF_RADIO->EVENTS_DISABLED == 0U) { // Do nothing. } } }
/*====================================================================================================*/ void NRF51_GPIO_Config( void ) { nrf_gpio_range_cfg_output(LED_1, LED_4); nrf_gpio_range_cfg_input(KEY_1, KEY_4, NRF_GPIO_PIN_PULLUP); LED1_Set(); LED2_Set(); LED3_Set(); LED4_Set(); }
int main(void){ nrf_gpio_range_cfg_output(18, 19); while(1){ nrf_gpio_port_write(2, 8); nrf_delay_ms(500); nrf_gpio_port_write(2, 4); nrf_delay_ms(500); } }
void init(void) { /* Start 16 MHz crystal oscillator */ NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1; /* Wait for the external oscillator to start up */ while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { } nrf_gpio_range_cfg_output(LED_START, LED_STOP); // Set radio configuration parameters radio_configure(); }
/**@brief Function for application main entry. Does not return. */ int main(void) { // Configure all LED as outputs. nrf_gpio_range_cfg_output(LED_START, LED_STOP); const uint32_t err_code = spi_slave_example_init(); APP_ERROR_CHECK(err_code); // Set LED0 high to indicate that the application is running. nrf_gpio_pin_set(LED_0); // Enter application main processing loop. for (;;) { // No implementation needed. } }
/** @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); }
/** * @brief Initialize GPIO pins, for LEDs and debugging */ void gpio_init(void) { #ifdef BOARD_PCA10028 nrf_gpio_cfg_output(LED_1); nrf_gpio_cfg_output(LED_2); #ifdef BUTTONS nrf_gpio_cfg_input(BUTTON_1, NRF_GPIO_PIN_PULLUP); nrf_gpio_cfg_input(BUTTON_2, NRF_GPIO_PIN_PULLUP); nrf_gpio_cfg_input(BUTTON_3, NRF_GPIO_PIN_PULLUP); nrf_gpio_cfg_input(BUTTON_4, NRF_GPIO_PIN_PULLUP); #endif #endif #ifdef BOARD_PCA10031 nrf_gpio_cfg_output(LED_RGB_RED); nrf_gpio_cfg_output(LED_RGB_GREEN); nrf_gpio_cfg_output(LED_RGB_BLUE); nrf_gpio_pin_set(LED_RGB_RED); nrf_gpio_pin_set(LED_RGB_GREEN); nrf_gpio_pin_set(LED_RGB_BLUE); #endif #ifdef BOARD_PCA10000 nrf_gpio_cfg_output(LED_RGB_RED); nrf_gpio_cfg_output(LED_RGB_GREEN); nrf_gpio_cfg_output(LED_RGB_BLUE); nrf_gpio_pin_set(LED_RGB_RED); nrf_gpio_pin_set(LED_RGB_GREEN); nrf_gpio_pin_set(LED_RGB_BLUE); #endif #ifdef BOARD_PCA10001 nrf_gpio_range_cfg_output(0, 32); #endif led_config(1, 0); led_config(2, 0); }
/** * main function * @return 0. int return type required by ANSI/ISO standard. */ int main(void) { // Configure pins 8-15 (port1) for LEDs as outputs nrf_gpio_range_cfg_output(8, 15); nrf_gpio_port_set(NRF_GPIO_PORT_SELECT_PORT1, 0XFF); NRF_RNG->TASKS_START = 1; // start RNG while (true) { // Clear the VALRDY EVENT and clear gpio8 - 15 (port1) NRF_RNG->EVENTS_VALRDY = 0; // Wait until the value ready event is generated while ( NRF_RNG->EVENTS_VALRDY == 0){} // Set output according to the random value nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, (uint8_t)NRF_RNG->VALUE); nrf_delay_ms(100); } }
/** @brief Function for main application entry. */ int main(void) { // Configure pins 8-15 (port 1) for LEDs as outputs. nrf_gpio_range_cfg_output(LED_START, LED_STOP); nrf_gpio_port_set(NRF_GPIO_PORT_SELECT_PORT1, 0XFF); NRF_RNG->TASKS_START = 1; // start the RNG peripheral. while (true) { // Clear the VALRDY EVENT. NRF_RNG->EVENTS_VALRDY = 0; // Wait until the value ready event is generated. while (NRF_RNG->EVENTS_VALRDY == 0) { // Do nothing. } // Set output according to the random value. nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, (uint8_t)NRF_RNG->VALUE); nrf_delay_ms(100); } }
/** * @brief Initialize GPIO pins, for LEDs and debugging */ void gpio_init(void) { #ifdef BOARD_PCA10028 nrf_gpio_cfg_output(LED_2); #else nrf_gpio_cfg_output(LED_0); #endif nrf_gpio_cfg_output(LED_1); #ifdef BOARD_PCA10000 nrf_gpio_cfg_output(LED_RGB_BLUE); nrf_gpio_pin_set(LED_RGB_RED); nrf_gpio_pin_set(LED_RGB_GREEN); nrf_gpio_pin_set(LED_RGB_BLUE); #endif #ifdef BOARD_PCA10001 nrf_gpio_range_cfg_output(0, 32); #endif led_config(1, 0); led_config(2, 0); }
/** * @brief Function for application main entry. */ int main(void) { nrf_gpio_range_cfg_output(LED_0, LED_1); nrf_gpio_pin_set(LED_0); NRF_CLOCK->TASKS_HFCLKSTART = 1; while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { } NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; // Workaround for PAN item 11, nRF51822-PAN v2.0.pdf. Not needed on second revision chips. NRF_POWER->TASKS_CONSTLAT = 1; NRF_GPIOTE->CONFIG[0] = GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos | GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos | LED_1 << GPIOTE_CONFIG_PSEL_Pos | GPIOTE_CONFIG_OUTINIT_Low << GPIOTE_CONFIG_OUTINIT_Pos; NRF_TIMER1->PRESCALER = 0; // Adjust the output frequency by adjusting the CC. // Due to PAN item 33, you can't have this at 1 for first revision chips, and will hence be limited to 4 MHz. NRF_TIMER1->CC[0] = 1; NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos; NRF_TIMER1->TASKS_START = 1; NRF_PPI->CH[0].EEP = (uint32_t) &NRF_TIMER1->EVENTS_COMPARE[0]; NRF_PPI->CH[0].TEP = (uint32_t) &NRF_GPIOTE->TASKS_OUT[0]; NRF_PPI->CHENSET = PPI_CHENSET_CH0_Enabled << PPI_CHENSET_CH0_Pos; while (true) { } }
/*====================================================================================================*/ void GPIO_Config( void ) { nrf_gpio_range_cfg_output(0, 7); // Pin 00-07 - output nrf_gpio_range_cfg_output(LED_0, LED_1); // Pin 18-19 - output nrf_gpio_cfg_input(KEY, NRF_GPIO_PIN_PULLUP); // Pin 20 - input }
/**@brief Function for application main entry. Does not return. */ int main(void) { // ANT event message buffer. static ant_evt_t ant_event; // Configure LEDs as outputs. nrf_gpio_range_cfg_output(BSP_LED_0, BSP_LED_1); // Set LED_0 and LED_1 high to indicate that the application is running. LEDS_ON(BSP_LED_0_MASK); LEDS_ON(BSP_LED_1_MASK); // Enable SoftDevice. uint32_t err_code; err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, softdevice_assert_callback); APP_ERROR_CHECK(err_code); // Set application IRQ to lowest priority. err_code = sd_nvic_SetPriority(SD_EVT_IRQn, NRF_APP_PRIORITY_LOW); APP_ERROR_CHECK(err_code); // Enable application IRQ (triggered from protocol). err_code = sd_nvic_EnableIRQ(SD_EVT_IRQn); APP_ERROR_CHECK(err_code); err_code = ant_stack_static_config(); APP_ERROR_CHECK(err_code); // Setup Channel_0 as a TX Master Only. ant_channel_setup(); // Set LED_0 and LED_1 low to indicate that stack is enabled. LEDS_OFF(BSP_LED_0_MASK); LEDS_OFF(BSP_LED_1_MASK); button_init(); // Main loop. for (;;) { // Put CPU in sleep if possible. err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); // Extract and process all pending ANT events as long as there are any left. do { // Fetch the event. err_code = sd_ant_event_get(&ant_event.channel, &ant_event.event, ant_event.evt_buffer); if (err_code == NRF_SUCCESS) { switch(ant_event.channel) { case ANT_RELAY_MASTER_CHANNEL: { ant_process_relay_master(&ant_event); break; } case ANT_RELAY_SLAVE_CHANNEL: { ant_process_relay_slave(&ant_event); break; } case ANT_MOBILE_CHANNEL: { ant_process_mobile(&ant_event); break; } default: { break; } } } } while (err_code == NRF_SUCCESS); } }
/*====================================================================================================*/ void GPIO_Config( void ) { nrf_gpio_range_cfg_output(1, 6); nrf_gpio_cfg_output(8); }
/*====================================================================================================*/ void GPIO_Config( void ) { nrf_gpio_range_cfg_output(LED_1, LED_4); nrf_gpio_range_cfg_input(KEY_1, KEY_4, NRF_GPIO_PIN_PULLUP); }
/*====================================================================================================*/ void GPIO_Config( void ) { nrf_gpio_range_cfg_output(LED_1, LED_4); }
/** * @brief Function for application main entry. */ int main(void) { // Configure pins 8-15 (Port1) as outputs nrf_gpio_range_cfg_output(8, 15); nrf_gpio_port_clear(NRF_GPIO_PORT_SELECT_PORT1, 0XFF); // Configure motion interrupt pin nrf_gpio_cfg_input(MOTION_INTERRUPT_PIN_NUMBER, NRF_GPIO_PIN_PULLDOWN); gpiote_init(); if (adns2080_init() != ADNS2080_OK) { // ADNS2080 init failed, set rightmost LED on. nrf_gpio_pin_write(15, 1); while (true) { // Do nothing. } } // By default, ADNS2080 motion interrupt output is active low, edge sensitive; make it active high. if (adns2080_motion_interrupt_set(ADNS2080_MOTION_OUTPUT_POLARITY_HIGH, ADNS2080_MOTION_OUTPUT_SENSITIVITY_LEVEL) != ADNS2080_OK) { nrf_gpio_pin_write(14, 1); while (true) { // Do nothing. } } // Read out movement to clear ADNS2080 interrupt flags. if (adns2080_is_motion_detected()) { int16_t dummy; adns2080_movement_read(&dummy, &dummy); } // Enable GPIOTE interrupt in Nested Vector Interrupt Controller. NVIC_EnableIRQ(GPIOTE_IRQn); // Enable global interrupts. __enable_irq(); while(true) { if (motion_interrupt_detected) { // Toggle pin 12 to indicate that we've detected motion interrupt. nrf_gpio_pin_toggle(12); motion_interrupt_detected = false; // On our Nordic reference design PCB, the chip orientation is not the same as in the ADNS2080 // datasheet diagram, so X and Y axis are reversed. This is corrected by passing the pointer // parameters in reversed order. */ adns2080_movement_read(&m_delta_y, &m_delta_x); // If movement delta_x is above the threshold, the LEDs light up accordingly. When the mouse is moved // to the left, LEDs 1 through 4 are lit and when the mouse is moved right, LEDs 5 through 8 are lit. if (m_delta_x > MOUSE_MOVEMENT_THRESHOLD) { nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, 0xF0); } else if (m_delta_x < (-MOUSE_MOVEMENT_THRESHOLD)) { nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, 0x0F); } else { nrf_gpio_port_clear(NRF_GPIO_PORT_SELECT_PORT1, 0xFF); } } } }