Kaleidoscope
BootKeyboard.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014-2015 NicoHood
3 See the readme for credit to other people.
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11 
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14 
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23 
24 // Include guard
25 #pragma once
26 
27 #include <Arduino.h>
28 #include "PluggableUSB.h"
29 #include "HID.h"
30 #include "HID-Settings.h"
31 #include "HIDTables.h"
32 #include "HIDAliases.h"
33 
34 typedef union {
35  // Low level key report: up to 6 keys and shift, ctrl etc at once
36  struct {
37  uint8_t modifiers;
38  uint8_t reserved;
39  uint8_t keycodes[6];
40  };
41  uint8_t keys[8];
43 
44 
45 class BootKeyboard_ : public PluggableUSBModule {
46  public:
47  BootKeyboard_(void);
48  size_t press(uint8_t);
49  void begin(void);
50  void end(void);
51  size_t release(uint8_t);
52  void releaseAll(void);
53 
54  int sendReport(void);
55 
56 
57 
58  uint8_t getLeds(void);
59  uint8_t getProtocol(void);
60  void wakeupHost(void);
61 
62  void setFeatureReport(void* report, int length) {
63  if (length > 0) {
64  featureReport = (uint8_t*)report;
65  featureLength = length;
66 
67  // Disable feature report by default
69  }
70  }
71 
73  if (featureLength < 0) {
74  return featureLength & ~0x8000;
75  }
76  return 0;
77  }
78 
79  void enableFeatureReport(void) {
80  featureLength &= ~0x8000;
81  }
82 
83  void disableFeatureReport(void) {
84  featureLength |= 0x8000;
85  }
86 
87 
88  protected:
90 
91  // Implementation of the PUSBListNode
92  int getInterface(uint8_t* interfaceCount);
93  int getDescriptor(USBSetup& setup);
94  bool setup(USBSetup& setup);
95 
96  uint8_t epType[1];
97  uint8_t protocol;
98  uint8_t idle;
99 
100  uint8_t leds;
101 
102  uint8_t* featureReport;
104 };
106 
107 
Definition: BootKeyboard.h:34
int availableFeatureReport(void)
Definition: BootKeyboard.h:72
int getDescriptor(USBSetup &setup)
Definition: BootKeyboard.cpp:90
void end(void)
Definition: BootKeyboard.cpp:121
int featureLength
Definition: BootKeyboard.h:103
BootKeyboard_ BootKeyboard
Definition: BootKeyboard.cpp:307
uint8_t reserved
Definition: BootKeyboard.h:38
void disableFeatureReport(void)
Definition: BootKeyboard.h:83
int getInterface(uint8_t *interfaceCount)
Definition: BootKeyboard.cpp:80
int sendReport(void)
Definition: BootKeyboard.cpp:210
uint8_t getLeds(void)
Definition: BootKeyboard.cpp:202
BootKeyboard_(void)
Definition: BootKeyboard.cpp:75
uint8_t protocol
Definition: BootKeyboard.h:97
void setFeatureReport(void *report, int length)
Definition: BootKeyboard.h:62
size_t press(uint8_t)
Definition: BootKeyboard.cpp:225
uint8_t modifiers
Definition: BootKeyboard.h:37
Definition: BootKeyboard.h:45
void enableFeatureReport(void)
Definition: BootKeyboard.h:79
void wakeupHost(void)
Definition: BootKeyboard.cpp:214
HID_BootKeyboardReport_Data_t _keyReport
Definition: BootKeyboard.h:89
size_t release(uint8_t)
Definition: BootKeyboard.cpp:262
uint8_t getProtocol(void)
Definition: BootKeyboard.cpp:206
uint8_t leds
Definition: BootKeyboard.h:100
uint8_t epType[1]
Definition: BootKeyboard.h:96
void releaseAll(void)
Definition: BootKeyboard.cpp:303
uint8_t * featureReport
Definition: BootKeyboard.h:102
bool setup(USBSetup &setup)
Definition: BootKeyboard.cpp:128
void begin(void)
Definition: BootKeyboard.cpp:112
uint8_t idle
Definition: BootKeyboard.h:98