Browse Source

FIX - Keyboard LEDS

The main issue was I used a setup structure on the stack which turned into garbage.  Earlier I thought the data was copied, but it was not...

Found that fixing this resolved the earlier issue where I needed to defer the update.  So removed the defered code, plus use member variable for the one byte output instead of static variable.
main
Kurt Eckhardt 7 years ago
parent
commit
d3e21b04c0
2 changed files with 2 additions and 24 deletions
  1. +0
    -2
      USBHost_t36.h
  2. +2
    -22
      keyboard.cpp

+ 0
- 2
USBHost_t36.h View File

uint8_t keyOEM; uint8_t keyOEM;
uint8_t prev_report[8]; uint8_t prev_report[8];
KBDLeds_t leds_ = {0}; KBDLeds_t leds_ = {0};
bool update_leds_ = false;
bool processing_new_data_ = false;
Pipe_t mypipes[2] __attribute__ ((aligned(32))); Pipe_t mypipes[2] __attribute__ ((aligned(32)));
Transfer_t mytransfers[4] __attribute__ ((aligned(32))); Transfer_t mytransfers[4] __attribute__ ((aligned(32)));
strbuf_t mystring_bufs[1]; strbuf_t mystring_bufs[1];

+ 2
- 22
keyboard.cpp View File



void KeyboardController::new_data(const Transfer_t *transfer) void KeyboardController::new_data(const Transfer_t *transfer)
{ {
processing_new_data_ = true;
println("KeyboardController Callback (member)"); println("KeyboardController Callback (member)");
print(" KB Data: "); print(" KB Data: ");
print_hexbytes(transfer->buffer, 8); print_hexbytes(transfer->buffer, 8);
} }
memcpy(prev_report, report, 8); memcpy(prev_report, report, 8);
queue_Data_Transfer(datapipe, report, 8, this); queue_Data_Transfer(datapipe, report, 8, this);
processing_new_data_ = false;

// See if we have any outstanding leds to update
if (update_leds_) {
updateLEDS();
}
} }




} }


void KeyboardController::updateLEDS() { void KeyboardController::updateLEDS() {
println("KBD: Update LEDS", leds_.byte, HEX);
if (processing_new_data_) {
println(" Update defered");
update_leds_ = true;
return; // defer until later
}

// Now lets tell keyboard new state. // Now lets tell keyboard new state.
static uint8_t keyboard_keys_report[1] = {0};
setup_t keys_setup;
keyboard_keys_report[0] = leds_.byte;
queue_Data_Transfer(datapipe, report, 8, this);
mk_setup(keys_setup, 0x21, 9, 0x200, 0, sizeof(keyboard_keys_report)); // hopefully this sets leds
queue_Control_Transfer(device, &keys_setup, keyboard_keys_report, this);

update_leds_ = false;
mk_setup(setup, 0x21, 9, 0x200, 0, sizeof(leds_.byte)); // hopefully this sets leds
queue_Control_Transfer(device, &setup, &leds_.byte, this);
} }





Loading…
Cancel
Save