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 }
static gzp_tx_rx_trans_result_t gzp_tx_rx_transaction(const uint8_t *tx_packet, uint8_t tx_length, uint8_t *rx_dst, uint32_t *rx_length, uint8_t pipe) { gzp_tx_rx_trans_result_t retval; uint8_t fetch_packet[GZP_CMD_FETCH_RESP_PAYLOAD_LENGTH]; bool tx_packet_success; bool fetch_success; uint32_t local_rx_length = GZP_MAX_ACK_PAYLOAD_LENGTH; uint32_t temp_lifetime; nrf_gzp_flush_rx_fifo(pipe); retval = GZP_TX_RX_FAILED_TO_SEND; (void)nrf_gzll_disable(); while(nrf_gzll_is_enabled()) {} temp_lifetime = nrf_gzll_get_sync_lifetime(); (void)nrf_gzll_set_sync_lifetime(GZP_TX_RX_TRANS_DELAY * 3); // 3 = RXPERIOD * 2 + margin (void)nrf_gzll_enable(); tx_packet_success = gzp_tx_packet(tx_packet, tx_length, pipe); if(tx_packet_success) { retval = GZP_TX_RX_NO_RESPONSE; nrf_gzp_flush_rx_fifo(pipe); fetch_packet[0] = (uint8_t)GZP_CMD_FETCH_RESP; gzp_tick_sleep_rx_periods(GZP_TX_RX_TRANS_DELAY); tx_packet_success = gzp_tx_packet(fetch_packet, GZP_CMD_FETCH_RESP_PAYLOAD_LENGTH, pipe); if(tx_packet_success) { if(nrf_gzll_get_rx_fifo_packet_count(pipe)) { local_rx_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH; fetch_success = nrf_gzll_fetch_packet_from_rx_fifo(pipe, rx_dst, &local_rx_length); } else { fetch_success = false; } if(fetch_success) { retval = GZP_TX_RX_SUCCESS; } else { //print_string("GZP_TX_FETCH_FAILED\r\n"); } } else { //print_string("GZP_TX_FETCH_NO_ACK\r\n"); } } (void)nrf_gzll_disable(); while(nrf_gzll_is_enabled()) {} (void)nrf_gzll_set_sync_lifetime(temp_lifetime); (void)nrf_gzll_enable(); return retval; }
int main() { bool init_ok = false; uint32_t err_code; //lint -save -e514 Unusual use of a boolean expression (use of &= assignment). const app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_ENABLED, false, UART_BAUDRATE_BAUDRATE_Baud38400 }; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOW, err_code); (void)err_code; UNUSED_VARIABLE(bsp_init(BSP_INIT_BUTTONS,0,NULL)); printf("Desktop emulator example\n"); // 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. bool send_mouse_data_button_pressed; err_code = bsp_button_is_pressed(SEND_MOUSE_DATA_BUTTON_ID,&(send_mouse_data_button_pressed)); if( send_mouse_data_button_pressed) { read_mouse_and_send(); } else { //indicate mouse button not pressed } // If BUTTON_SEND_KEYBOARD_DATA button is pressed bool send_keyboard_data_button_pressed; err_code = bsp_button_is_pressed(SEND_KEYBOARD_DATA_BUTTON_ID,&(send_keyboard_data_button_pressed)); if(send_keyboard_data_button_pressed) { read_keyboard_and_send(); } else { //indicate keyboard button not pressed } error_report(); /* 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 }