Added Led Out Report, CDC Linestate, Magic Bootkey
You can now read the led states of the keyboard, the dtr line of the cdc and the bootkey got fixed to the new hoodloader 2.0.1
This commit is contained in:
parent
36a8af03df
commit
0b7cb6eaf5
6 changed files with 443 additions and 45 deletions
104
CDC.cpp
104
CDC.cpp
|
|
@ -1,19 +1,19 @@
|
|||
|
||||
|
||||
/* Copyright (c) 2011, Peter Barrett
|
||||
**
|
||||
** Permission to use, copy, modify, and/or distribute this software for
|
||||
** any purpose with or without fee is hereby granted, provided that the
|
||||
** above copyright notice and this permission notice appear in all copies.
|
||||
**
|
||||
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
|
||||
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
|
||||
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
** SOFTWARE.
|
||||
/* Copyright (c) 2011, Peter Barrett
|
||||
**
|
||||
** Permission to use, copy, modify, and/or distribute this software for
|
||||
** any purpose with or without fee is hereby granted, provided that the
|
||||
** above copyright notice and this permission notice appear in all copies.
|
||||
**
|
||||
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
|
||||
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
|
||||
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
** SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
|
@ -61,28 +61,34 @@ static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
|
|||
extern const CDCDescriptor _cdcInterface PROGMEM;
|
||||
const CDCDescriptor _cdcInterface =
|
||||
{
|
||||
D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1),
|
||||
D_IAD(0, 2, CDC_COMMUNICATION_INTERFACE_CLASS, CDC_ABSTRACT_CONTROL_MODEL, 1),
|
||||
|
||||
// CDC communication interface
|
||||
D_INTERFACE(CDC_ACM_INTERFACE,1,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0),
|
||||
D_CDCCS(CDC_HEADER,0x10,0x01), // Header (1.10 bcd)
|
||||
D_CDCCS(CDC_CALL_MANAGEMENT,1,1), // Device handles call management (not)
|
||||
D_CDCCS4(CDC_ABSTRACT_CONTROL_MANAGEMENT,6), // SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported
|
||||
D_CDCCS(CDC_UNION,CDC_ACM_INTERFACE,CDC_DATA_INTERFACE), // Communication interface is master, data interface is slave 0
|
||||
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_ACM),USB_ENDPOINT_TYPE_INTERRUPT,0x10,0x40),
|
||||
D_INTERFACE(CDC_ACM_INTERFACE, 1, CDC_COMMUNICATION_INTERFACE_CLASS, CDC_ABSTRACT_CONTROL_MODEL, 0),
|
||||
D_CDCCS(CDC_HEADER, 0x10, 0x01), // Header (1.10 bcd)
|
||||
D_CDCCS(CDC_CALL_MANAGEMENT, 1, 1), // Device handles call management (not)
|
||||
D_CDCCS4(CDC_ABSTRACT_CONTROL_MANAGEMENT, 6), // SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported
|
||||
D_CDCCS(CDC_UNION, CDC_ACM_INTERFACE, CDC_DATA_INTERFACE), // Communication interface is master, data interface is slave 0
|
||||
D_ENDPOINT(USB_ENDPOINT_IN(CDC_ENDPOINT_ACM), USB_ENDPOINT_TYPE_INTERRUPT, 0x10, 0x40),
|
||||
|
||||
// CDC data interface
|
||||
D_INTERFACE(CDC_DATA_INTERFACE,2,CDC_DATA_INTERFACE_CLASS,0,0),
|
||||
D_INTERFACE(CDC_DATA_INTERFACE, 2, CDC_DATA_INTERFACE_CLASS, 0, 0),
|
||||
// edit by NicoHood
|
||||
D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,USB_EP_SIZE,0),
|
||||
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,USB_EP_SIZE,0)
|
||||
D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT), USB_ENDPOINT_TYPE_BULK, USB_EP_SIZE, 0),
|
||||
D_ENDPOINT(USB_ENDPOINT_IN(CDC_ENDPOINT_IN), USB_ENDPOINT_TYPE_BULK, USB_EP_SIZE, 0)
|
||||
};
|
||||
|
||||
int WEAK CDC_GetInterface(u8* interfaceNum)
|
||||
{
|
||||
interfaceNum[0] += 2; // uses 2
|
||||
return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface));
|
||||
return USB_SendControl(TRANSFER_PGM, &_cdcInterface, sizeof(_cdcInterface));
|
||||
}
|
||||
// edit by NicoHood
|
||||
// ensure the address isnt used anywhere else by adding a compiler flag in the makefile lf flag
|
||||
// -Wl,--section-start=.blkey=0x280
|
||||
//TODO where to put that flag? use different position: 0x100 maybe?
|
||||
// someone has to add the compiler flag to fix this bug: https://github.com/arduino/Arduino/issues/2474
|
||||
//volatile uint8_t MagicBootKey __attribute__((section(".blkey")));
|
||||
|
||||
bool WEAK CDC_Setup(Setup& setup)
|
||||
{
|
||||
|
|
@ -93,7 +99,7 @@ bool WEAK CDC_Setup(Setup& setup)
|
|||
{
|
||||
if (CDC_GET_LINE_CODING == r)
|
||||
{
|
||||
USB_SendControl(0,(void*)&_usbLineInfo,7);
|
||||
USB_SendControl(0, (void*)&_usbLineInfo, 7);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -102,7 +108,7 @@ bool WEAK CDC_Setup(Setup& setup)
|
|||
{
|
||||
if (CDC_SET_LINE_CODING == r)
|
||||
{
|
||||
USB_RecvControl((void*)&_usbLineInfo,7);
|
||||
USB_RecvControl((void*)&_usbLineInfo, 7);
|
||||
}
|
||||
|
||||
if (CDC_SET_CONTROL_LINE_STATE == r)
|
||||
|
|
@ -120,8 +126,26 @@ bool WEAK CDC_Setup(Setup& setup)
|
|||
// We check DTR state to determine if host port is open (bit 0 of lineState).
|
||||
if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
|
||||
{
|
||||
// edit by NicoHood
|
||||
// change ram pointer to fit the 16u2's ram size and only use a 8bit value
|
||||
#if defined(__AVR_ATmega32U4__)
|
||||
*(uint16_t *)0x0800 = 0x7777;
|
||||
wdt_enable(WDTO_120MS);
|
||||
#else
|
||||
// workaround for this issue:
|
||||
// https://github.com/arduino/Arduino/issues/2474
|
||||
// I didnt change this for the 32u4 to simply not touch their code
|
||||
cli();
|
||||
|
||||
//MagicBootKey = 0x77;
|
||||
*(uint8_t *)0x0280 = 0x77;
|
||||
|
||||
wdt_enable(WDTO_120MS);
|
||||
|
||||
// wait for reset
|
||||
for (;;);
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -130,9 +154,18 @@ bool WEAK CDC_Setup(Setup& setup)
|
|||
// To avoid spurious resets we set the watchdog to 250ms and eventually
|
||||
// cancel if DTR goes back high.
|
||||
|
||||
// edit by NicoHood
|
||||
#if defined(__AVR_ATmega32U4__)
|
||||
wdt_disable();
|
||||
wdt_reset();
|
||||
*(uint16_t *)0x0800 = 0x0;
|
||||
#else
|
||||
// not used because of the workaround above
|
||||
//wdt_disable();
|
||||
//wdt_reset();
|
||||
//MagicBootKey = 0x0;
|
||||
//*(uint8_t *)0x0280 = 0x00;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
@ -155,6 +188,12 @@ void Serial_::end(void)
|
|||
{
|
||||
}
|
||||
|
||||
// edit by NicoHood
|
||||
uint8_t Serial_::lineState(void)
|
||||
{
|
||||
return _usbLineInfo.lineState;
|
||||
}
|
||||
|
||||
int Serial_::available(void)
|
||||
{
|
||||
if (peek_buffer >= 0) {
|
||||
|
|
@ -192,20 +231,21 @@ size_t Serial_::write(uint8_t c)
|
|||
|
||||
size_t Serial_::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
/* only try to send bytes if the high-level CDC connection itself
|
||||
/* only try to send bytes if the high-level CDC connection itself
|
||||
is open (not just the pipe) - the OS should set lineState when the port
|
||||
is opened and clear lineState when the port is closed.
|
||||
bytes sent before the user opens the connection or after
|
||||
the connection is closed are lost - just like with a UART. */
|
||||
|
||||
|
||||
// TODO - ZE - check behavior on different OSes and test what happens if an
|
||||
// open connection isn't broken cleanly (cable is yanked out, host dies
|
||||
// or locks up, or host virtual serial port hangs)
|
||||
if (_usbLineInfo.lineState > 0) {
|
||||
int r = USB_Send(CDC_TX,buffer,size);
|
||||
int r = USB_Send(CDC_TX, buffer, size);
|
||||
if (r > 0) {
|
||||
return r;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -223,7 +263,7 @@ size_t Serial_::write(const uint8_t *buffer, size_t size)
|
|||
// where the port is configured (lineState != 0) but not quite opened.
|
||||
Serial_::operator bool() {
|
||||
bool result = false;
|
||||
if (_usbLineInfo.lineState > 0)
|
||||
if (_usbLineInfo.lineState > 0)
|
||||
result = true;
|
||||
delay(10);
|
||||
return result;
|
||||
|
|
|
|||
41
HID.cpp
41
HID.cpp
|
|
@ -48,6 +48,11 @@ THE SOFTWARE.
|
|||
//================================================================================
|
||||
// HID report descriptor
|
||||
|
||||
#if defined USBCON && defined(HID_KEYBOARD_ENABLED) && defined(HID_KEYBOARD_LEDS_ENABLED)
|
||||
// extern accessible led out report
|
||||
uint8_t hid_keyboard_leds = 0;
|
||||
#endif
|
||||
|
||||
extern const u8 _hidReportDescriptor[] PROGMEM;
|
||||
const u8 _hidReportDescriptor[] = {
|
||||
#ifdef HID_MOUSE_ENABLED
|
||||
|
|
@ -114,17 +119,19 @@ const u8 _hidReportDescriptor[] = {
|
|||
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
|
||||
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
|
||||
0x81, 0x00, // INPUT (Data,Ary,Abs)
|
||||
#ifdef HID_KEYBOARD_LEDS_ENABLED
|
||||
// LEDs for num lock etc
|
||||
//0x05, 0x08, /* USAGE_PAGE (LEDs) */
|
||||
//0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */
|
||||
//0x29, 0x05, /* USAGE_MAXIMUM (Kana) */
|
||||
//0x95, 0x05, /* REPORT_COUNT (5) */
|
||||
//0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
//0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
|
||||
0x05, 0x08, /* USAGE_PAGE (LEDs) */
|
||||
0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */
|
||||
0x29, 0x05, /* USAGE_MAXIMUM (Kana) */
|
||||
0x95, 0x05, /* REPORT_COUNT (5) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
|
||||
// Reserved 3 bits
|
||||
//0x95, 0x01, /* REPORT_COUNT (1) */
|
||||
//0x75, 0x03, /* REPORT_SIZE (3) */
|
||||
//0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */
|
||||
0x75, 0x03, /* REPORT_SIZE (3) */
|
||||
0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */
|
||||
#endif
|
||||
// end
|
||||
0xc0, // END_COLLECTION
|
||||
#endif
|
||||
|
|
@ -302,6 +309,22 @@ bool WEAK HID_Setup(Setup& setup)
|
|||
_hid_idle = setup.wValueL;
|
||||
return true;
|
||||
}
|
||||
|
||||
// edit by NicoHood
|
||||
#if defined USBCON && defined(HID_KEYBOARD_ENABLED) && defined(HID_KEYBOARD_LEDS_ENABLED)
|
||||
if (HID_SET_REPORT == r)
|
||||
{
|
||||
if (setup.wLength == 2)
|
||||
{
|
||||
uint8_t data[2];
|
||||
if (2 == USB_RecvControl(data, 2))
|
||||
{
|
||||
// write led out report data
|
||||
hid_keyboard_leds=data[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
21
USBAPI.h
21
USBAPI.h
|
|
@ -61,6 +61,8 @@ typedef unsigned long u32;
|
|||
// by default only Mouse + Keyboard are activated
|
||||
#define HID_MOUSE_ENABLED
|
||||
#define HID_KEYBOARD_ENABLED
|
||||
//#define HID_KEYBOARD_LEDS_ENABLED
|
||||
|
||||
//#define HID_RAWHID_ENABLED
|
||||
//#define HID_MEDIA_ENABLED
|
||||
//#define HID_SYSTEM_ENABLED
|
||||
|
|
@ -76,6 +78,15 @@ typedef unsigned long u32;
|
|||
|
||||
#ifdef HID_KEYBOARD_ENABLED
|
||||
#define HID_KEYBOARD_SIZE (65-18) //18 for missing led out report = 47
|
||||
|
||||
#if defined USBCON && defined(HID_KEYBOARD_ENABLED) && defined(HID_KEYBOARD_LEDS_ENABLED)
|
||||
// extern accessible led out report
|
||||
extern uint8_t hid_keyboard_leds;
|
||||
|
||||
#define LED_NUM_LOCK 0x01
|
||||
#define LED_CAPS_LOCK 0x02
|
||||
#define LED_SCROLL_LOCK 0x04
|
||||
#endif
|
||||
#else
|
||||
#define HID_KEYBOARD_SIZE 0
|
||||
#endif
|
||||
|
|
@ -181,6 +192,9 @@ public:
|
|||
void begin(unsigned long, uint8_t);
|
||||
void end(void);
|
||||
|
||||
// edit by NicoHood
|
||||
uint8_t lineState(void);
|
||||
|
||||
virtual int available(void);
|
||||
virtual int peek(void);
|
||||
virtual int read(void);
|
||||
|
|
@ -369,6 +383,7 @@ extern Mouse_ Mouse;
|
|||
|
||||
//Keyboard fixed/added missing Keys
|
||||
#define KEY_PRINT 0xCE
|
||||
#define KEY_NUM_LOCK 0xDB
|
||||
#define KEY_SCROLL_LOCK 0xCF
|
||||
#define KEY_PAUSE 0xD0
|
||||
|
||||
|
|
@ -619,6 +634,12 @@ public:
|
|||
releaseAll();
|
||||
}
|
||||
|
||||
#if defined(HID_KEYBOARD_LEDS_ENABLED)
|
||||
inline uint8_t getLEDs(void){
|
||||
return hid_keyboard_leds;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline size_t write(uint8_t c){
|
||||
uint8_t p = press(c); // Keydown
|
||||
release(c); // Keyup
|
||||
|
|
|
|||
|
|
@ -104,7 +104,8 @@ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
|
|||
// edit by NicoHood
|
||||
// warning from USBlyzer: IAD is used. Should be EFh (Miscellaneous Device Class).
|
||||
// Lufa also use these values, so i will use them at least for the u2 boards. Someone should fix this for the u4 series if needed.
|
||||
#if defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__)
|
||||
// You have to use this descriptor if you have CDC AND HID at the same time. Otherwise they are quite different.
|
||||
#if defined(HID_ENABLED) && (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__))
|
||||
|
||||
// DEVICE DESCRIPTOR
|
||||
const DeviceDescriptor USB_DeviceDescriptor =
|
||||
|
|
@ -742,7 +743,7 @@ void USBDevice_::attach()
|
|||
#ifdef PINDIV
|
||||
PLLCSR = (1 << PINDIV) | (1 << PLLE);
|
||||
#else
|
||||
// added from paul, no idea for what board this is used for
|
||||
// added from paul brook, no idea for what board this is used for
|
||||
PLLCSR = (1 << PLLP0) | (1 << PLLE);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
307
USBCore.h
Normal file
307
USBCore.h
Normal file
|
|
@ -0,0 +1,307 @@
|
|||
|
||||
// Copyright (c) 2010, Peter Barrett
|
||||
/*
|
||||
** Permission to use, copy, modify, and/or distribute this software for
|
||||
** any purpose with or without fee is hereby granted, provided that the
|
||||
** above copyright notice and this permission notice appear in all copies.
|
||||
**
|
||||
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
|
||||
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
|
||||
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
** SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __USBCORE_H__
|
||||
#define __USBCORE_H__
|
||||
|
||||
// Standard requests
|
||||
#define GET_STATUS 0
|
||||
#define CLEAR_FEATURE 1
|
||||
#define SET_FEATURE 3
|
||||
#define SET_ADDRESS 5
|
||||
#define GET_DESCRIPTOR 6
|
||||
#define SET_DESCRIPTOR 7
|
||||
#define GET_CONFIGURATION 8
|
||||
#define SET_CONFIGURATION 9
|
||||
#define GET_INTERFACE 10
|
||||
#define SET_INTERFACE 11
|
||||
|
||||
|
||||
// bmRequestType
|
||||
#define REQUEST_HOSTTODEVICE 0x00
|
||||
#define REQUEST_DEVICETOHOST 0x80
|
||||
#define REQUEST_DIRECTION 0x80
|
||||
|
||||
#define REQUEST_STANDARD 0x00
|
||||
#define REQUEST_CLASS 0x20
|
||||
#define REQUEST_VENDOR 0x40
|
||||
#define REQUEST_TYPE 0x60
|
||||
|
||||
#define REQUEST_DEVICE 0x00
|
||||
#define REQUEST_INTERFACE 0x01
|
||||
#define REQUEST_ENDPOINT 0x02
|
||||
#define REQUEST_OTHER 0x03
|
||||
#define REQUEST_RECIPIENT 0x03
|
||||
|
||||
#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE)
|
||||
#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE)
|
||||
|
||||
// Class requests
|
||||
|
||||
#define CDC_SET_LINE_CODING 0x20
|
||||
#define CDC_GET_LINE_CODING 0x21
|
||||
#define CDC_SET_CONTROL_LINE_STATE 0x22
|
||||
|
||||
// edit by NicoHood
|
||||
#define CDC_CONTROL_LINE_OUT_DTR (1 << 0)
|
||||
#define CDC_CONTROL_LINE_OUT_RTS (1 << 1)
|
||||
|
||||
#define MSC_RESET 0xFF
|
||||
#define MSC_GET_MAX_LUN 0xFE
|
||||
|
||||
#define HID_GET_REPORT 0x01
|
||||
#define HID_GET_IDLE 0x02
|
||||
#define HID_GET_PROTOCOL 0x03
|
||||
#define HID_SET_REPORT 0x09
|
||||
#define HID_SET_IDLE 0x0A
|
||||
#define HID_SET_PROTOCOL 0x0B
|
||||
|
||||
// Descriptors
|
||||
|
||||
#define USB_DEVICE_DESC_SIZE 18
|
||||
#define USB_CONFIGUARTION_DESC_SIZE 9
|
||||
#define USB_INTERFACE_DESC_SIZE 9
|
||||
#define USB_ENDPOINT_DESC_SIZE 7
|
||||
|
||||
#define USB_DEVICE_DESCRIPTOR_TYPE 1
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
|
||||
#define USB_STRING_DESCRIPTOR_TYPE 3
|
||||
#define USB_INTERFACE_DESCRIPTOR_TYPE 4
|
||||
#define USB_ENDPOINT_DESCRIPTOR_TYPE 5
|
||||
|
||||
#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
|
||||
#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
|
||||
#define USB_DEVICE_CLASS_STORAGE 0x08
|
||||
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
|
||||
|
||||
#define USB_CONFIG_POWERED_MASK 0x40
|
||||
#define USB_CONFIG_BUS_POWERED 0x80
|
||||
#define USB_CONFIG_SELF_POWERED 0xC0
|
||||
#define USB_CONFIG_REMOTE_WAKEUP 0x20
|
||||
|
||||
// bMaxPower in Configuration Descriptor
|
||||
#define USB_CONFIG_POWER_MA(mA) ((mA)/2)
|
||||
|
||||
// bEndpointAddress in Endpoint Descriptor
|
||||
#define USB_ENDPOINT_DIRECTION_MASK 0x80
|
||||
#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
|
||||
#define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
|
||||
|
||||
#define USB_ENDPOINT_TYPE_MASK 0x03
|
||||
#define USB_ENDPOINT_TYPE_CONTROL 0x00
|
||||
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
|
||||
#define USB_ENDPOINT_TYPE_BULK 0x02
|
||||
#define USB_ENDPOINT_TYPE_INTERRUPT 0x03
|
||||
|
||||
#define TOBYTES(x) ((x) & 0xFF),(((x) >> 8) & 0xFF)
|
||||
|
||||
#define CDC_V1_10 0x0110
|
||||
#define CDC_COMMUNICATION_INTERFACE_CLASS 0x02
|
||||
|
||||
#define CDC_CALL_MANAGEMENT 0x01
|
||||
#define CDC_ABSTRACT_CONTROL_MODEL 0x02
|
||||
#define CDC_HEADER 0x00
|
||||
#define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02
|
||||
#define CDC_UNION 0x06
|
||||
#define CDC_CS_INTERFACE 0x24
|
||||
#define CDC_CS_ENDPOINT 0x25
|
||||
#define CDC_DATA_INTERFACE_CLASS 0x0A
|
||||
|
||||
#define MSC_SUBCLASS_SCSI 0x06
|
||||
#define MSC_PROTOCOL_BULK_ONLY 0x50
|
||||
|
||||
#define HID_HID_DESCRIPTOR_TYPE 0x21
|
||||
#define HID_REPORT_DESCRIPTOR_TYPE 0x22
|
||||
#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23
|
||||
|
||||
|
||||
// Device
|
||||
typedef struct {
|
||||
u8 len; // 18
|
||||
u8 dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE
|
||||
u16 usbVersion; // 0x200
|
||||
u8 deviceClass;
|
||||
u8 deviceSubClass;
|
||||
u8 deviceProtocol;
|
||||
u8 packetSize0; // Packet 0
|
||||
u16 idVendor;
|
||||
u16 idProduct;
|
||||
u16 deviceVersion; // 0x100
|
||||
u8 iManufacturer;
|
||||
u8 iProduct;
|
||||
u8 iSerialNumber;
|
||||
u8 bNumConfigurations;
|
||||
} DeviceDescriptor;
|
||||
|
||||
// Config
|
||||
typedef struct {
|
||||
u8 len; // 9
|
||||
u8 dtype; // 2
|
||||
u16 clen; // total length
|
||||
u8 numInterfaces;
|
||||
u8 config;
|
||||
u8 iconfig;
|
||||
u8 attributes;
|
||||
u8 maxPower;
|
||||
} ConfigDescriptor;
|
||||
|
||||
// String
|
||||
|
||||
// Interface
|
||||
typedef struct
|
||||
{
|
||||
u8 len; // 9
|
||||
u8 dtype; // 4
|
||||
u8 number;
|
||||
u8 alternate;
|
||||
u8 numEndpoints;
|
||||
u8 interfaceClass;
|
||||
u8 interfaceSubClass;
|
||||
u8 protocol;
|
||||
u8 iInterface;
|
||||
} InterfaceDescriptor;
|
||||
|
||||
// Endpoint
|
||||
typedef struct
|
||||
{
|
||||
u8 len; // 7
|
||||
u8 dtype; // 5
|
||||
u8 addr;
|
||||
u8 attr;
|
||||
u16 packetSize;
|
||||
u8 interval;
|
||||
} EndpointDescriptor;
|
||||
|
||||
// Interface Association Descriptor
|
||||
// Used to bind 2 interfaces together in CDC compostite device
|
||||
typedef struct
|
||||
{
|
||||
u8 len; // 8
|
||||
u8 dtype; // 11
|
||||
u8 firstInterface;
|
||||
u8 interfaceCount;
|
||||
u8 functionClass;
|
||||
u8 funtionSubClass;
|
||||
u8 functionProtocol;
|
||||
u8 iInterface;
|
||||
} IADDescriptor;
|
||||
|
||||
// CDC CS interface descriptor
|
||||
typedef struct
|
||||
{
|
||||
u8 len; // 5
|
||||
u8 dtype; // 0x24
|
||||
u8 subtype;
|
||||
u8 d0;
|
||||
u8 d1;
|
||||
} CDCCSInterfaceDescriptor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 len; // 4
|
||||
u8 dtype; // 0x24
|
||||
u8 subtype;
|
||||
u8 d0;
|
||||
} CDCCSInterfaceDescriptor4;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 len;
|
||||
u8 dtype; // 0x24
|
||||
u8 subtype; // 1
|
||||
u8 bmCapabilities;
|
||||
u8 bDataInterface;
|
||||
} CMFunctionalDescriptor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 len;
|
||||
u8 dtype; // 0x24
|
||||
u8 subtype; // 1
|
||||
u8 bmCapabilities;
|
||||
} ACMFunctionalDescriptor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// IAD
|
||||
IADDescriptor iad; // Only needed on compound device
|
||||
|
||||
// Control
|
||||
InterfaceDescriptor cif; //
|
||||
CDCCSInterfaceDescriptor header;
|
||||
CMFunctionalDescriptor callManagement; // Call Management
|
||||
ACMFunctionalDescriptor controlManagement; // ACM
|
||||
CDCCSInterfaceDescriptor functionalDescriptor; // CDC_UNION
|
||||
EndpointDescriptor cifin;
|
||||
|
||||
// Data
|
||||
InterfaceDescriptor dif;
|
||||
EndpointDescriptor in;
|
||||
EndpointDescriptor out;
|
||||
} CDCDescriptor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
InterfaceDescriptor msc;
|
||||
EndpointDescriptor in;
|
||||
EndpointDescriptor out;
|
||||
} MSCDescriptor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 len; // 9
|
||||
u8 dtype; // 0x21
|
||||
u8 addr;
|
||||
u8 versionL; // 0x101
|
||||
u8 versionH; // 0x101
|
||||
u8 country;
|
||||
u8 desctype; // 0x22 report
|
||||
u8 descLenL;
|
||||
u8 descLenH;
|
||||
} HIDDescDescriptor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
InterfaceDescriptor hid;
|
||||
HIDDescDescriptor desc;
|
||||
EndpointDescriptor in;
|
||||
} HIDDescriptor;
|
||||
|
||||
|
||||
#define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \
|
||||
{ 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
|
||||
|
||||
#define D_CONFIG(_totalLength,_interfaces) \
|
||||
{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(500) }
|
||||
|
||||
#define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \
|
||||
{ 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 }
|
||||
|
||||
#define D_ENDPOINT(_addr,_attr,_packetSize, _interval) \
|
||||
{ 7, 5, _addr,_attr,_packetSize, _interval }
|
||||
|
||||
#define D_IAD(_firstInterface, _count, _class, _subClass, _protocol) \
|
||||
{ 8, 11, _firstInterface, _count, _class, _subClass, _protocol, 0 }
|
||||
|
||||
#define D_HIDREPORT(_descriptorLength) \
|
||||
{ 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 }
|
||||
|
||||
#define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 }
|
||||
#define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 }
|
||||
|
||||
|
||||
#endif
|
||||
10
keywords.txt
10
keywords.txt
|
|
@ -48,8 +48,9 @@ Gamepad KEYWORD3
|
|||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
#General
|
||||
SERIAL_HID_BAUD LITERAL1
|
||||
#CDC
|
||||
CDC_CONTROL_LINE_OUT_DTR LITERAL1
|
||||
CDC_CONTROL_LINE_OUT_TRS LITERAL1
|
||||
|
||||
#Mouse
|
||||
|
||||
|
|
@ -61,6 +62,10 @@ MOUSE_NEXT LITERAL1
|
|||
|
||||
#Keyboard
|
||||
|
||||
LED_NUM_LOCK LITERAL1
|
||||
LED_CAPS_LOCK LITERAL1
|
||||
LED_SCROLL_LOCK LITERAL1
|
||||
|
||||
KEY_LEFT_CTRL LITERAL1
|
||||
KEY_LEFT_SHIFT LITERAL1
|
||||
KEY_LEFT_ALT LITERAL1
|
||||
|
|
@ -102,6 +107,7 @@ KEY_F11 LITERAL1
|
|||
KEY_F12 LITERAL1
|
||||
|
||||
KEY_PRINT LITERAL1
|
||||
KEY_NUM_LOCK LITERAL1
|
||||
KEY_SCROLL_LOCK LITERAL1
|
||||
KEY_PAUSE LITERAL1
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue