PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

120 行
2.6KB

  1. #ifndef USBserial_h_
  2. #define USBserial_h_
  3. #include <inttypes.h>
  4. #include "keylayouts.h"
  5. #include "Print.h"
  6. #include "Stream.h"
  7. class usb_keyboard_class : public Print
  8. {
  9. public:
  10. void begin(void) { }
  11. void end(void) { }
  12. #if ARDUINO >= 100
  13. virtual size_t write(uint8_t);
  14. #else
  15. virtual void write(uint8_t);
  16. #endif
  17. using Print::write;
  18. void write_unicode(uint16_t unicode) { write_keycode(unicode_to_keycode(unicode)); }
  19. void set_modifier(uint16_t);
  20. void set_key1(uint8_t);
  21. void set_key2(uint8_t);
  22. void set_key3(uint8_t);
  23. void set_key4(uint8_t);
  24. void set_key5(uint8_t);
  25. void set_key6(uint8_t);
  26. void set_media(uint8_t);
  27. void send_now(void);
  28. void press(uint16_t n);
  29. void release(uint16_t n);
  30. void releaseAll(void);
  31. private:
  32. KEYCODE_TYPE unicode_to_keycode(uint16_t unicode);
  33. KEYCODE_TYPE deadkey_to_keycode(KEYCODE_TYPE keycode);
  34. uint8_t keycode_to_modifier(KEYCODE_TYPE keycode);
  35. uint8_t keycode_to_key(KEYCODE_TYPE keycode);
  36. void presskey(uint8_t key, uint8_t modifier);
  37. void releasekey(uint8_t key, uint8_t modifier);
  38. void write_keycode(KEYCODE_TYPE key);
  39. void write_key(KEYCODE_TYPE code);
  40. uint8_t utf8_state;
  41. uint16_t unicode_wchar;
  42. };
  43. extern usb_keyboard_class Keyboard;
  44. class usb_serial_class : public Stream
  45. {
  46. public:
  47. // standard Arduino functions
  48. void begin(long);
  49. void end();
  50. virtual int available();
  51. virtual int read();
  52. virtual int peek();
  53. virtual void flush();
  54. #if ARDUINO >= 100
  55. virtual size_t write(uint8_t);
  56. #else
  57. virtual void write(uint8_t);
  58. #endif
  59. using Print::write;
  60. operator bool();
  61. // Teensy extensions
  62. void send_now(void);
  63. uint32_t baud(void);
  64. uint8_t stopbits(void);
  65. uint8_t paritytype(void);
  66. uint8_t numbits(void);
  67. uint8_t dtr(void);
  68. uint8_t rts(void);
  69. private:
  70. uint8_t readnext(void);
  71. };
  72. extern usb_serial_class Serial;
  73. extern "C" {
  74. extern void media_claim(void);
  75. extern uint8_t media_read_sector(uint32_t lba, uint8_t *buffer);
  76. extern uint8_t media_write_sector(uint32_t lba, const uint8_t *buffer);
  77. extern void media_release(uint8_t read_only_mode);
  78. uint8_t media_lock(void);
  79. void media_unlock(void);
  80. }
  81. class usb_disk_class
  82. {
  83. public:
  84. inline void pause(void) {
  85. while (!media_lock()) /* wait */ ;
  86. }
  87. inline void resume(void) {
  88. media_unlock();
  89. }
  90. inline void claim(void) {
  91. media_claim();
  92. }
  93. inline uint8_t readSector(uint32_t addr, uint8_t *buffer) {
  94. return media_read_sector(addr, buffer);
  95. }
  96. inline uint8_t writeSector(uint32_t addr, const uint8_t *buffer) {
  97. return media_write_sector(addr, buffer);
  98. }
  99. inline void release(void) {
  100. media_release(0);
  101. }
  102. inline void releaseReadOnly(void) {
  103. media_release(1);
  104. }
  105. };
  106. extern usb_disk_class Disk;
  107. #endif