#include "ble_app_gzll_device.h" #include <stdint.h> #include "nordic_common.h" #include "app_error.h" #include "nrf_gzll.h" #include "nrf_gzll_error.h" #include "ble_app_gzll_ui.h" #include "bsp.h" #include "nrf_gzll.h" #include "nrf_gzp.h" #include "nrf_gzllde_params.h" #include "nrf_delay.h" #define MAX_TX_ATTEMPTS 100 /< Maximum number of Transmit attempts.*/ #define DUMMY_PACKET 0x80 /< First payload./ #define NB_TX_WITH_SAME_PAYLOAD 3 /**< Number of times each packet is sent (this avoid changing the payload too quickly and allows to have a visible LED pattern on the receiver side)./ #define PAYLOAD_SIZE 8 /< Size of the payload to send over Gazell.*/ #define PIPE_TO_HOST 0 /< Pipe number. */
static uint8_t m_gzll_packet[PAYLOAD_SIZE]; unsigned char buff[32] = {0x08,0x02,0x00 ,0x20 ,0xDD ,0x00 ,0x00 ,0xE0 ,0x8C ,0x3E ,0x00 ,0x0C ,0x36 ,0x3F ,0x00 ,0x80 ,0x0A ,0xBF ,0x00 ,0x98 ,0xB5 ,0x3E ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x74 ,0x8F ,0x02 ,0x00 ,0x28}; static bool system_addr_received = false; ///< System address receivedfrom Host.
/**@brief Function for starting Gazell functionality. */ void gzll_app_start(void) { // GAZELLE_ERROR_CODE_CHECK(nrf_gzll_init(NRF_GZLL_MODE_DEVICE)); // GAZELLE_ERROR_CODE_CHECK(nrf_gzll_set_max_tx_attempts(MAX_TX_ATTEMPTS)); // GAZELLE_ERROR_CODE_CHECK(nrf_gzll_enable());
// // Add a packet to the TX FIFO to start the data transfer. // // Next packets to send will be added. // m_gzll_packet[0] = DUMMY_PACKET; // GAZELLE_ERROR_CODE_CHECK(nrf_gzll_add_packet_to_tx_fifo(PIPE_TO_HOST, // m_gzll_packet, // PAYLOAD_SIZE));
unsigned char ch_table[] = {3, 23, 40, 61, 75};
bool init_ok = false;
uint32_t err_code;
init_ok = true;
// 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(10); // 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.
init_ok &= nrf_gzll_set_max_tx_attempts(20);
init_ok &= nrf_gzll_set_device_channel_selection_policy(NRF_GZLLDE_DEVICE_CHANNEL_SELECTION_POLICY);
init_ok &= nrf_gzll_set_timeslot_period(540);
init_ok &=nrf_gzll_set_timeslots_per_channel(2);
init_ok &= nrf_gzll_set_timeslots_per_channel_when_device_out_of_sync(2);
init_ok &= nrf_gzll_set_sync_lifetime(0);
init_ok &= nrf_gzll_set_datarate(NRF_GZLL_DATARATE_2MBIT);
init_ok &= nrf_gzll_set_channel_table(ch_table, sizeof(ch_table));
gzp_init();
init_ok &= nrf_gzll_enable();
while(!system_addr_received)
{
system_addr_received = gzp_address_req_send();
nrf_delay_ms(10);
}
nrf_gzp_disable_gzll();
init_ok &= nrf_gzll_set_max_tx_attempts(3);
init_ok &= nrf_gzll_set_device_channel_selection_policy(NRF_GZLL_DEVICE_CHANNEL_SELECTION_POLICY_USE_CURRENT);
init_ok &= nrf_gzll_set_timeslot_period(750);
init_ok &= nrf_gzll_set_sync_lifetime(100);
nrf_gzll_set_tx_power(NRF_GZLL_TX_POWER_4_DBM);
nrf_gzll_enable();
uint32_t result;
if(init_ok)
{
while(1)
{
buff[4]+=1;
buff[5]+=1;
while(!nrf_gzll_ok_to_add_packet_to_tx_fifo(NRFR_MOUSE_EP))
{}
// Add mouse packet to the mouse pipe's TX FIFO.
nrf_gzll_add_packet_to_tx_fifo(NRFR_MOUSE_EP, buff, 32);
}
}
}