Hello,
I'm trying to add a rotary encoder support to the HID keyboard example on SDK17.0 with some custom hardware utilizing the NRF52840. It works well to send the requested characters per click-turn, but at some point it inevitably fails with Error 19, as if I were trying to send too many consecutive characters. It's a bit hard to tell, but it could be when I attempt to turn the encoder too fast? I have a really aggressive low-pass filter on there right now, and I've confirmed on the oscilloscope that I'm not getting any double-edges.
I have each encoder pin set up with a low-power GPIOTE event, each pointing to the same handler.
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false); in_config.sense = NRF_GPIOTE_POLARITY_HITOLO; err_code = nrf_drv_gpiote_in_init(enc_pins[0], &in_config, encoder_handler); APP_ERROR_CHECK(err_code); nrf_drv_gpiote_in_event_enable(enc_pins[0], true); err_code = nrf_drv_gpiote_in_init(enc_pins[1], &in_config, encoder_handler); APP_ERROR_CHECK(err_code); nrf_drv_gpiote_in_event_enable(enc_pins[1], true);
And the handler. The error occurs on the first APP_ERROR_CHECK, line 18
void encoder_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action){
ret_code_t err_code;
//NRF_LOG_INFO("Enc handler");
uint8_t data[] = {0, 0, 0, 0, 0, 0, 0, 0};
if(nrf_gpio_pin_read(enc_pins[0]) != nrf_gpio_pin_read(enc_pins[1])){
if(pin == enc_pins[1]){
data[0] = enc_mods[1];
data[2] = enc_keys[1];
} else{
data[0] = enc_mods[0];
data[2] = enc_keys[0];
}
if(!m_in_boot_mode){
err_code = ble_hids_inp_rep_send(&m_hids, INPUT_REPORT_KEYS_INDEX, INPUT_REPORT_KEYS_MAX_LEN, data, m_conn_handle);
APP_ERROR_CHECK(err_code);
data[0] = 0;
data[2] = 0;
err_code = ble_hids_inp_rep_send(&m_hids, INPUT_REPORT_KEYS_INDEX, INPUT_REPORT_KEYS_MAX_LEN, data, m_conn_handle);
} else{
err_code = ble_hids_boot_kb_inp_rep_send(&m_hids, INPUT_REPORT_KEYS_MAX_LEN, data, m_conn_handle);
APP_ERROR_CHECK(err_code);
data[0] = 0;
data[2] = 0;
err_code = ble_hids_boot_kb_inp_rep_send(&m_hids, INPUT_REPORT_KEYS_MAX_LEN, data, m_conn_handle);
}
APP_ERROR_CHECK(err_code);
}
}
Any help is appreciated!
