Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

usb_extra.c 830B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <avr/interrupt.h>
  2. #include "usb_extra.h"
  3. int8_t usb_extra_send(uint8_t report_id, uint8_t bits)
  4. {
  5. uint8_t intr_state, timeout;
  6. if (!usb_configured()) return -1;
  7. intr_state = SREG;
  8. cli();
  9. UENUM = EXTRA_ENDPOINT;
  10. timeout = UDFNUML + 50;
  11. while (1) {
  12. // are we ready to transmit?
  13. if (UEINTX & (1<<RWAL)) break;
  14. SREG = intr_state;
  15. // has the USB gone offline?
  16. if (!usb_configured()) return -1;
  17. // have we waited too long?
  18. if (UDFNUML == timeout) return -1;
  19. // get ready to try checking again
  20. intr_state = SREG;
  21. cli();
  22. UENUM = EXTRA_ENDPOINT;
  23. }
  24. UEDATX = report_id;
  25. UEDATX = bits;
  26. UEINTX = 0x3A;
  27. SREG = intr_state;
  28. return 0;
  29. }
  30. int8_t usb_extra_audio_send(uint8_t bits)
  31. {
  32. return usb_extra_send(1, bits);
  33. }
  34. int8_t usb_extra_system_send(uint8_t bits)
  35. {
  36. return usb_extra_send(2, bits);
  37. }