Keyboard firmwares for Atmel AVR and Cortex-M
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

USBSerial.cpp 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (c) 2010-2011 mbed.org, MIT License
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  4. * and associated documentation files (the "Software"), to deal in the Software without
  5. * restriction, including without limitation the rights to use, copy, modify, merge, publish,
  6. * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
  7. * Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or
  10. * substantial portions of the Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  13. * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  14. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  15. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. */
  18. #include "stdint.h"
  19. #include "USBSerial.h"
  20. int USBSerial::_putc(int c) {
  21. if (!terminal_connected)
  22. return 0;
  23. send((uint8_t *)&c, 1);
  24. return 1;
  25. }
  26. int USBSerial::_getc() {
  27. uint8_t c = 0;
  28. while (buf.isEmpty());
  29. buf.dequeue(&c);
  30. return c;
  31. }
  32. bool USBSerial::writeBlock(uint8_t * buf, uint16_t size) {
  33. if(size > MAX_PACKET_SIZE_EPBULK) {
  34. return false;
  35. }
  36. if(!send(buf, size)) {
  37. return false;
  38. }
  39. return true;
  40. }
  41. bool USBSerial::EPBULK_OUT_callback() {
  42. uint8_t c[65];
  43. uint32_t size = 0;
  44. //we read the packet received and put it on the circular buffer
  45. readEP(c, &size);
  46. for (uint32_t i = 0; i < size; i++) {
  47. buf.queue(c[i]);
  48. }
  49. //call a potential handler
  50. rx.call();
  51. return true;
  52. }
  53. uint8_t USBSerial::available() {
  54. return buf.available();
  55. }