Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <HID.h>
- #if !defined(_USING_HID)
- #error "Using legacy HID core (non pluggable)"
- #endif
- static const u8 _hidReportDescriptor[] PROGMEM = {
- /* Gamepad with buttons and X/Y only */ \
- 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \
- 0x09, 0x04, /* USAGE (Joystick) */ \
- 0xa1, 0x01, /* COLLECTION
- (Application) */ \
- 0x85, 0x01, /* REPORT_ID */ \
- /* 32 Buttons */ \
- 0x05, 0x09, /* USAGE_PAGE (Button) */ \
- 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ \
- 0x29, 0x20, /* USAGE_MAXIMUM (Button 32) */ \
- 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
- 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \
- 0x75, 0x01, /* REPORT_SIZE (1) */ \
- 0x95, 0x20, /* REPORT_COUNT (32) */ \
- 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \
- 0xc0 /* END_COLLECTION */
- };
- struct ControlPadReport
- {
- uint32_t buttons;
- };
- class ControlPad
- {
- private:
- ControlPadReport _report;
- HID_ *_hid;
- public:
- ControlPad(HID_ *hid)
- {
- _hid = hid;
- static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor));
- _hid->AppendDescriptor(&node);
- }
- void begin(void)
- {
- releaseAll();
- write();
- }
- void end(void)
- {
- releaseAll();
- write();
- }
- inline void press(uint8_t b)
- {
- bitSet(_report.buttons, b);
- }
- inline void release(uint8_t b)
- {
- bitClear(_report.buttons, b);
- }
- inline void releaseAll()
- {
- memset(&_report, 0, sizeof(ControlPadReport));
- }
- void write()
- {
- _hid->SendReport(1,&_report,sizeof(ControlPadReport));
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement