int main() { uint8_t debug_led_output; // Setup port directions nrf_gpio_port_dir_set(BUTTONS, NRF_GPIO_PORT_DIR_INPUT); nrf_gpio_port_dir_set(LEDS, NRF_GPIO_PORT_DIR_OUTPUT); // Initialize Gazell init_ok = nrf_gzll_init(NRF_GZLL_MODE_DEVICE); // Attempt sending every packet up to 100 times init_ok &= nrf_gzll_set_max_tx_attempts(100); // Load data into TX queue data_payload[0] = nrf_gpio_port_read(BUTTONS); push_ok = nrf_gzll_add_packet_to_tx_fifo(PIPE_NUMBER, data_payload, TX_PAYLOAD_LENGTH); // Enable Gazell to start sending over the air enable_ok = nrf_gzll_enable(); while(1) { // Error handling debug_led_output = ((uint8_t)tx_success << 4) | ((uint8_t)pop_ok << 3) | ((uint8_t)push_ok << 2) | ((uint8_t)enable_ok << 1) | (uint8_t)init_ok; // If an error has occured if(debug_led_output != 0x1F) { nrf_gpio_port_write(LEDS,0xFF); nrf_delay_us(1000000); // 1 second delay nrf_gpio_port_write(LEDS, debug_led_output); nrf_delay_us(1000000); // 1 second delay nrf_gpio_port_write(LEDS,0xF0 + (uint32_t)nrf_gzll_get_error_code()); nrf_delay_us(1000000); // 1 second delay } // Optionally send the CPU to sleep while waiting for a callback. // __WFI(); } }
int main() { bool init_ok = false; //lint -save -e514 Unusual use of a boolean expression (use of &= assignment). // Configure input pins nrf_gpio_pin_dir_set(BUTTON_SEND_MOUSE_DATA, NRF_GPIO_PIN_DIR_INPUT); nrf_gpio_pin_dir_set(BUTTON_SEND_KEYBOARD_DATA, NRF_GPIO_PIN_DIR_INPUT); nrf_gpio_port_dir_set(LED_PORT, NRF_GPIO_PORT_DIR_OUTPUT); // Initialize and enable "mouse sensor" init_ok = mouse_sensor_init(MOUSE_SENSOR_SAMPLE_PERIOD_8_MS); mouse_sensor_enable(); // Initialize and enable Gazell init_ok &= nrf_gzll_init(NRF_GZLL_MODE_DEVICE); // Ensure Gazell parameters are configured. init_ok &= nrf_gzll_set_max_tx_attempts(150); init_ok &= nrf_gzll_set_device_channel_selection_policy(NRF_GZLLDE_DEVICE_CHANNEL_SELECTION_POLICY); init_ok &= nrf_gzll_set_timeslot_period(NRF_GZLLDE_RXPERIOD_DIV_2); init_ok &= nrf_gzll_set_sync_lifetime(0); // Asynchronous mode, more efficient for pairing. switch(gzp_get_pairing_status()) { case -2: host_id_received = false; system_addr_received = false; break; case -1: host_id_received = false; system_addr_received = true; break; default: host_id_received = true; system_addr_received = true; } gzp_init(); init_ok &= nrf_gzll_enable(); if(init_ok) { while(1) { // If BUTTON_SEND_MOUSE_DATA button is pressed. if(nrf_gpio_pin_read(BUTTON_SEND_MOUSE_DATA) == 0) { read_mouse_and_send(); } // If BUTTON_SEND_KEYBOARD_DATA button is pressed if(nrf_gpio_pin_read(BUTTON_SEND_KEYBOARD_DATA) == 0) { read_keyboard_and_send(); } /* CPU sleep. We will wake up from all enabled interrupts, which here are the internal Gazell interrupts and the "mouse sensor" internal timer interrupt. */ //__WFI(); } } else { /* The initialization failed. Use nrf_gzll_get_error_code() to investigate the cause. */ } //lint -restore }