I'm trying to combine hid keyboard with .../peripheral/uart example.
Only after the bluetooth connection is established between host (PC) & nrf DK, I want to continuously send data received from uart (connected to microcontroller) to host machine. This data needs to be sent in input report.
But if I merge the uart peripheral with hid keyboard, the bluetooth does not connect at all.
I have pasted the changes I have made to specific functions/ files. Can you check at your end?
void uart_error_handle(app_uart_evt_t * p_event)
{
if (p_event->evt_type == APP_UART_DATA_READY)
{
if(flag == 1)
{
while (app_uart_get(&cr) != NRF_SUCCESS){};
if (cr == '9')
{
bsp_board_led_invert(1);
nrf_delay_ms(500);
}
}
//while (app_uart_put('?') != NRF_SUCCESS);
}
/* else if (p_event->evt_type == APP_UART_TX_EMPTY)
{
while (app_uart_put('?') != NRF_SUCCESS);
}*/
else if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_communication);
}
else if (p_event->evt_type == APP_UART_FIFO_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_code);
}
}
static void uart_init(void)
{
uint32_t err_code;
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
0,/*RTS_PIN_NUMBER,*/
0,/*CTS_PIN_NUMBER,*/
UART_HWFC,
false,
NRF_UART_BAUDRATE_460800
};
APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
APP_ERROR_CHECK(err_code);
}
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
ret_code_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
NRF_LOG_INFO("Connected");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
APP_ERROR_CHECK(err_code);
flag = 1;
break;
case BLE_GAP_EVT_DISCONNECTED:
NRF_LOG_INFO("Disconnected");
// Dequeue all keys without transmission.
(void) buffer_dequeue(false);
m_conn_handle = BLE_CONN_HANDLE_INVALID;
// Reset m_caps_on variable. Upon reconnect, the HID host will re-send the Output report containing the Caps lock state.
// m_caps_on = false;
// disabling alert 3. signal - used for capslock ON
err_code = bsp_indication_set(BSP_INDICATE_ALERT_OFF);
APP_ERROR_CHECK(err_code);
flag = 0;
break; // BLE_GAP_EVT_DISCONNECTED
int main(void)
{
bool erase_bonds;
log_init();
// Data_Init();
timers_init();
buttons_leds_init(&erase_bonds);
power_management_init();
ble_stack_init();
scheduler_init();
gap_params_init();
gatt_init();
advertising_init();
services_init();
sensor_simulator_init();
conn_params_init();
buffer_init();
peer_manager_init();
NRF_LOG_INFO("HID Keyboard example started.");
timers_start();
advertising_start(erase_bonds);
uart_init();
for (;;)
{
idle_state_handle();
}
}
Rest things are just as is from ../peripheral/uart code.
I also made changes to sdkconfig.h