36 #define LSB(_x) ((_x) & 0xFF) 37 #define MSB(_x) ((_x) >> 8) 39 #define RAWHID_USAGE_PAGE 0xFFC0 40 #define RAWHID_USAGE 0x0C00 41 #define RAWHID_TX_SIZE 64 42 #define RAWHID_RX_SIZE 64 44 extern const u8 _hidReportDescriptor[] PROGMEM;
45 const u8 _hidReportDescriptor[] = {
107 #ifdef RAWHID_ENABLED 109 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE),
110 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
129 extern const HIDDescriptor _hidInterface PROGMEM;
130 const HIDDescriptor _hidInterface =
133 D_HIDREPORT(
sizeof(_hidReportDescriptor)),
141 u8 _hid_protocol = 1;
144 #define WEAK __attribute__ ((weak)) 146 int WEAK HID_GetInterface(
u8* interfaceNum)
148 interfaceNum[0] += 1;
149 return USB_SendControl(TRANSFER_PGM,&_hidInterface,
sizeof(_hidInterface));
152 int WEAK HID_GetDescriptor(
int )
154 return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,
sizeof(_hidReportDescriptor));
157 void WEAK HID_SendReport(
u8 id,
const void*
data,
int len)
159 USB_Send(HID_TX, &
id, 1);
160 USB_Send(HID_TX | TRANSFER_RELEASE,data,len);
163 bool WEAK HID_Setup(Setup&
setup)
165 u8 r = setup.bRequest;
166 u8 requestType = setup.bmRequestType;
169 if (HID_GET_REPORT == r)
174 if (HID_GET_PROTOCOL == r)
183 if (HID_SET_PROTOCOL == r)
185 _hid_protocol = setup.wValueL;
189 if (HID_SET_IDLE == r)
191 _hid_idle = setup.wValueL;
202 Mouse_::Mouse_(
void) : _buttons(0)
206 void Mouse_::begin(
void)
210 void Mouse_::end(
void)
214 void Mouse_::click(uint8_t
b)
222 void Mouse_::move(
signed char x,
signed char y,
signed char wheel)
229 HID_SendReport(1,m,4);
232 void Mouse_::buttons(uint8_t
b)
241 void Mouse_::press(uint8_t b)
243 buttons(_buttons | b);
246 void Mouse_::release(uint8_t b)
248 buttons(_buttons & ~b);
251 bool Mouse_::isPressed(uint8_t b)
253 if ((b & _buttons) > 0)
262 Keyboard_::Keyboard_(
void)
266 void Keyboard_::begin(
void)
270 void Keyboard_::end(
void)
274 void Keyboard_::sendReport(KeyReport* keys)
276 HID_SendReport(2,keys,
sizeof(KeyReport));
280 const uint8_t _asciimap[128] PROGMEM;
283 const uint8_t _asciimap[128] =
416 uint8_t USBPutChar(uint8_t
c);
422 size_t Keyboard_::press(uint8_t k)
427 }
else if (k >= 128) {
428 _keyReport.modifiers |= (1<<(k-128));
431 k = pgm_read_byte(_asciimap + k);
437 _keyReport.modifiers |= 0x02;
444 if (_keyReport.keys[0] != k && _keyReport.keys[1] != k &&
445 _keyReport.keys[2] != k && _keyReport.keys[3] != k &&
446 _keyReport.keys[4] != k && _keyReport.keys[5] != k) {
448 for (i=0; i<6; i++) {
449 if (_keyReport.keys[i] == 0x00) {
450 _keyReport.keys[i] = k;
459 sendReport(&_keyReport);
466 size_t Keyboard_::release(uint8_t k)
471 }
else if (k >= 128) {
472 _keyReport.modifiers &= ~(1<<(k-128));
475 k = pgm_read_byte(_asciimap + k);
480 _keyReport.modifiers &= ~(0x02);
487 for (i=0; i<6; i++) {
488 if (0 != k && _keyReport.keys[i] == k) {
489 _keyReport.keys[i] = 0x00;
493 sendReport(&_keyReport);
497 void Keyboard_::releaseAll(
void)
499 _keyReport.keys[0] = 0;
500 _keyReport.keys[1] = 0;
501 _keyReport.keys[2] = 0;
502 _keyReport.keys[3] = 0;
503 _keyReport.keys[4] = 0;
504 _keyReport.keys[5] = 0;
505 _keyReport.modifiers = 0;
506 sendReport(&_keyReport);
509 size_t Keyboard_::write(uint8_t
c)
511 uint8_t
p = press(c);
GLint GLint GLint GLint GLint GLint y
void setWriteError(int err=1)
#define D_ENDPOINT(_addr, _attr, _packetSize, _interval)
GLint GLint GLint GLint GLint x
#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
#define REQUEST_DEVICETOHOST_CLASS_INTERFACE
GLdouble GLdouble GLdouble r
#define USB_ENDPOINT_TYPE_INTERRUPT
GLdouble GLdouble GLdouble b
const T & move(const T &t)
#define D_INTERFACE(_n, _numEndpoints, _class, _subClass, _protocol)
#define USB_ENDPOINT_IN(addr)