diff options
Diffstat (limited to 'bootloaders/diskloader')
-rw-r--r-- | bootloaders/diskloader/DiskLoader-Leonardo.hex | 115 | ||||
-rw-r--r-- | bootloaders/diskloader/Makefile | 105 | ||||
-rw-r--r-- | bootloaders/diskloader/src/DiskLoader.cpp | 239 | ||||
-rw-r--r-- | bootloaders/diskloader/src/Platform.h | 51 | ||||
-rw-r--r-- | bootloaders/diskloader/src/USBCore.cpp | 510 | ||||
-rw-r--r-- | bootloaders/diskloader/src/USBCore.h | 246 | ||||
-rw-r--r-- | bootloaders/diskloader/src/USBDesc.cpp | 87 | ||||
-rw-r--r-- | bootloaders/diskloader/src/USBDesc.h | 65 |
8 files changed, 0 insertions, 1418 deletions
diff --git a/bootloaders/diskloader/DiskLoader-Leonardo.hex b/bootloaders/diskloader/DiskLoader-Leonardo.hex deleted file mode 100644 index 0d0c167..0000000 --- a/bootloaders/diskloader/DiskLoader-Leonardo.hex +++ /dev/null @@ -1,115 +0,0 @@ -:1078000011241FBECFEFDAE0DEBFCDBFFFC04101C4
-:1078100042144505560455026403740300001E9586
-:1078200087020110030000C18081C106C0FF0A0069
-:107830000CA10185037508150026FF00954009017C
-:107840008102954009029102C0040309041A033021
-:1078500000300030003000300030003000300031A7
-:1078600000370030003100380341007200640075B9
-:107870000069006E006F0020004C0065006F006E14
-:10788000006100720064006F00200062006F006FF2
-:107890000074006C006F00610064006500720018E5
-:1078A00003410072006400750069006E006F0020E3
-:1078B000004C004C00430012010002020000404155
-:1078C0002334000001000203011201000200000045
-:1078D0004041233400000100020301090264000357
-:1078E00001008032080B00020202010009040000BE
-:1078F0000102020000052400100105240101010419
-:107900002402020524060001070581031000400936
-:10791000040100020A0000000705020240000007FF
-:107920000583024000000904020001030000000971
-:107930002101010001221E000705840340004000D0
-:1079400020918A0130918B012C5F3F4F30938B0146
-:1079500020938A01C901892F99278695982F803411
-:1079600018F08FE7891B982F990F921710F44798FA
-:107970000895479A08955D9A289A81E08093E000DF
-:107980001092E200EE27FF27099408950F931F93AA
-:10799000CF93DF93982FEB01042F10E088E760303E
-:1079A000780730F411E083E0FB0180935700E895FD
-:1079B000892F68E071E0402FF8D0112311F107B64C
-:1079C00000FCFDCF402F4695FE01A8E0B1E020E08D
-:1079D00031E009C08D919D910C0130935700E895DD
-:1079E000112432962F5F2417A8F385E0FE018093BF
-:1079F0005700E89507B600FCFDCF81E18093570062
-:107A0000E895DF91CF911F910F91089588E10FB60E
-:107A1000F89480936000109260000FBE5D9A289ADF
-:107A200047983F9A209A559A90E890936100109257
-:107A3000610081E885BF95BF9FD084E18093880174
-:107A400080E180938901E0E0F0E0859194918F5F7F
-:107A50009F4F19F081E080938F01EE24FF24BB2417
-:107A6000B39454EFC52E51E0D52E13D2082F8EE0DB
-:107A700098E7FC012491319602964491201711F069
-:107A80002223B9F7109291011092900182E068E0F0
-:107A900071E08BD0013479F4609108016058633053
-:107AA00028F0683111F064E001C063E0C62FD0E037
-:107AB000CF5DD7480EC0063571F480910801803340
-:107AC00011F011E022C080910A01C82FD0E0C25EFF
-:107AD000D74811E022C0053721F413E0CEE1D8E702
-:107AE0001CC0053539F4E0900801F0900901EE0C56
-:107AF000FF1C0AC0043631F482E0B701409109014D
-:107B000045DF02C0043721F010E0C5E2D8E705C028
-:107B100010910901E701E10EF11CBBD18097B1F48E
-:107B200083E068E871E041E050E059D0112329F08A
-:107B3000412F50E083E8BE0152D083E469E871E050
-:107B400041E050E04CD0013509F08FCFD092910147
-:107B5000C0929001B0928F01EE24FF2486CFFC01E9
-:107B6000289884E680938D0104C08091F100819370
-:107B700061506623D1F708951092910110929001FF
-:107B800010928E0110928F0181E08093D70080EADD
-:107B90008093D80082E189BD09B400FEFDCF80E961
-:107BA0008093D8001092E0000895FB018093E900D3
-:107BB00024E69BE611C08091E80085FFFCCF289861
-:107BC00020938D018091F10081938091E80085FDE3
-:107BD00002C09093E8004150442369F70895982F1C
-:107BE000FB01282F207287708093E90064E63AE356
-:107BF00017C08091E80085FFFCCF97FF02C08491F9
-:107C000001C080813196211180E05D9860938C01E4
-:107C10008093F1008091E80085FD02C03093E80078
-:107C2000415050408FEF4F3F580719F796FF03C060
-:107C30008AE38093E800089580919301813299F45A
-:107C40005D9884E680938C0120E030E003C0808161
-:107C50008093F100F901E050FF4F2F5F3F4F283034
-:107C60003105A9F714C0803261F48091E80082FFE9
-:107C7000FCCF80E091E067E072DF8BEF8093E8005B
-:107C800006C0823221F4809194018093070181E043
-:107C9000089520919501223289F1213081F480915B
-:107CA000980190919901089711F420939A0180917D
-:107CB0009A01882309F04FC0E9ECF8E74EC0223062
-:107CC00021F484E6EBEDF8E71CC0233009F041C055
-:107CD00080919401882319F4E9E4F8E73EC08230EA
-:107CE00019F4E7E6F8E739C0833019F4EDE4F8E772
-:107CF00034C0813071F5EFE9F8E72FC081E0EBE2A5
-:107D0000F8E790919801382F981708F4392F90913F
-:107D10008C0120E04EEF8091E8008570E1F38091C6
-:107D2000E80082FD12C02F5F84915D988093F1007E
-:107D3000822F8F7311F44093E800319694E6231755
-:107D400050F390938C0181E0089590938C0180E032
-:107D5000089580E00895E7EBF8E78491D2CF109280
-:107D6000E9008091E80083FF61C082E991E068E06A
-:107D7000F6DE82EF8093E8008091920187FF05C0D4
-:107D80008091E80080FFFCCF03C08EEF8093E80075
-:107D900080919301853051F48091E80080FFFCCF01
-:107DA0008091940180688093E30039C08930E1F4C8
-:107DB0008091940180938E01E7E2F8E791E031E051
-:107DC00026E39093E9003093EB0084918093EC00DC
-:107DD0002093ED009F5F3196953099F78EE7809361
-:107DE000EA001092EA001BC0883049F490918E019D
-:107DF0005D9884E680938C019093F10010C08823F5
-:107E000039F45D9884E680938C011092F10007C0EC
-:107E1000863011F43EDF01C00FDF882321F08EEFA2
-:107E20008093E800089581E28093EB0008958091AB
-:107E3000E1001092E100282F83FF0CC01092E900AE
-:107E400081E08093EB001092EC0082E38093ED00E0
-:107E500010928E0122FF1CC080918C01882331F08A
-:107E6000815080938C01882309F45D9A80918D0163
-:107E7000882331F0815080938D01882309F4289A5A
-:107E800080918F01882321F410929101109290012A
-:107E900008951F93CF93DF9312E0C0E9D1E05FDF35
-:107EA000C6DF1093E9008091E80085FF13C0289891
-:107EB00084E680938D019091F1008091E80085FD2A
-:107EC00003C08BE68093E800892F90E0DF91CF918B
-:107ED0001F91089580919001909191010197909345
-:107EE0009101809390018091900190919101892B53
-:0E7EF00009F441DDCE010197F1F722DDD0CF7C
-:087EFE0000E10000000000009B
-:040000030000780081
-:00000001FF
diff --git a/bootloaders/diskloader/Makefile b/bootloaders/diskloader/Makefile deleted file mode 100644 index 6ac3db3..0000000 --- a/bootloaders/diskloader/Makefile +++ /dev/null @@ -1,105 +0,0 @@ -############################################################################### -# Makefile for DiskLoader -############################################################################### - -## General Flags -PROJECT = DiskLoader -TARGET = DiskLoader.elf -CC = avr-gcc - -# BOARD2 -MCU = atmega32u4 -AVR_FREQ = 16000000L - -# Specify the Arduino model using the assigned PID. This is used by Descriptors.c
-# to set PID and product descriptor string
-# Arduino Leonardo PID
-ARDUINO_MODEL_PID = 0x0034
-# Arduino Micro PID
-#ARDUINO_MODEL_PID = 0x0035 - -# Change if your programmer is different -AVRDUDE_PROGRAMMER = avrispmkII -AVRDUDE_PORT = usb - -# program name should not be changed... -PROGRAM = DiskLoader - -AVRDUDE = avrdude -AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -p $(MCU) - -## Options common to compile, link and assembly rules -COMMON = -mmcu=$(MCU) - -override CFLAGS = -g -Wall -Os -mmcu=$(MCU) -DF_CPU=$(AVR_FREQ) -DARDUINO_MODEL_PID=$(ARDUINO_MODEL_PID) $(DEFS) -ffunction-sections -gdwarf-2 -fdata-sections -fno-split-wide-types - -## Assembly specific flags -ASMFLAGS = $(COMMON) -ASMFLAGS += $(CFLAGS) -ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2 - -## Linker flags -LDFLAGS = $(COMMON) -LDFLAGS += -Wl,-gc-sections,-Map=DiskLoader.map,--section-start=.text=0x7800,--relax -LDFLAGS += -nodefaultlibs -nostartfiles - - -## Intel Hex file production flags -HEX_EEPROM_FLAGS = -j .eeprom -HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load" -HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings - -## Objects explicitly added by the user -LINKONLYOBJECTS = - -MODULES := . -SRC_DIR := $(addprefix src/,$(MODULES)) -BUILD_DIR := $(addprefix build/,$(MODULES)) - -SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp)) -OBJ := $(patsubst src/%.cpp,build/%.o,$(SRC)) -DEP := $(OBJ:%.o=%.d) -INCLUDES := $(addprefix -I,$(SRC_DIR)) - -vpath %.cpp $(SRC_DIR) - -.PHONY: all checkdirs clean - -all: checkdirs $(TARGET) DiskLoader.hex DiskLoader.lss size - --include $(DEP) - -checkdirs: $(BUILD_DIR) - -$(BUILD_DIR): - @mkdir -p $@ - -clean: - @rm -rf build/ - @rm -f *.hex - @rm -f *.elf - @rm -f *.lss - @rm -f *.map - -define make-goal -$1/%.o: %.cpp - $(CC) $(INCLUDES) $(CFLAGS) -c $$< -MD -o $$@ -endef - -$(foreach bdir,$(BUILD_DIR),$(eval $(call make-goal,$(bdir)))) - -$(TARGET): $(OBJ) - $(CC) $(LDFLAGS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) $^ -o $@ - -%.hex: $(TARGET) - avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ - -%.lss: $(TARGET) - avr-objdump -h -S $< > $@ - -size: $(TARGET) - @echo -# @avr-size -C --mcu=${MCU} ${TARGET}.elf - -program: $(TARGET).hex - $(AVRDUDE) $(AVRDUDE_FLAGS) -B 5 -u -U flash:w:$(TARGET).hex
\ No newline at end of file diff --git a/bootloaders/diskloader/src/DiskLoader.cpp b/bootloaders/diskloader/src/DiskLoader.cpp deleted file mode 100644 index 6580618..0000000 --- a/bootloaders/diskloader/src/DiskLoader.cpp +++ /dev/null @@ -1,239 +0,0 @@ - - -#include "Platform.h" - -// This bootloader creates a composite Serial device -// -// The serial interface supports a STK500v1 protocol that is very similar to optiboot -// -// The bootloader will timeout and start the firmware after a few hundred milliseconds -// if a usb connection is not detected. -// -// The tweakier code is to keep the bootloader below 2k (no interrupt table, for example) - -extern "C" -void entrypoint(void) __attribute__ ((naked)) __attribute__ ((section (".vectors"))); -void entrypoint(void) -{ - asm volatile ( - "eor r1, r1\n" // Zero register - "out 0x3F, r1\n" // SREG - "ldi r28, 0xFF\n" - "ldi r29, 0x0A\n" - "out 0x3E, r29\n" // SPH - "out 0x3D, r28\n" // SPL - "rjmp main" // Stack is all set up, start the main code - ::); -} - -u8 _flashbuf[128]; -u8 _inSync; -u8 _ok; -extern volatile u8 _ejected; -extern volatile u16 _timeout; - -void Program(u8 ep, u16 page, u8 count) -{ - u8 write = page < 30*1024; // Don't write over firmware please - if (write) - boot_page_erase(page); - - Recv(ep,_flashbuf,count); // Read while page is erasing - - if (!write) - return; - - boot_spm_busy_wait(); // Wait until the memory is erased. - - count >>= 1; - u16* p = (u16*)page; - u16* b = (u16*)_flashbuf; - for (u8 i = 0; i < count; i++) - boot_page_fill(p++, b[i]); - - boot_page_write(page); - boot_spm_busy_wait(); - boot_rww_enable (); -} - - -int USBGetChar(); -#define getch USBGetChar - -#define HW_VER 0x02 -#define SW_MAJOR 0x01 -#define SW_MINOR 0x10 - -#define STK_OK 0x10 -#define STK_INSYNC 0x14 // ' ' -#define CRC_EOP 0x20 // 'SPACE' -#define STK_GET_SYNC 0x30 // '0' - -#define STK_GET_PARAMETER 0x41 // 'A' -#define STK_SET_DEVICE 0x42 // 'B' -#define STK_SET_DEVICE_EXT 0x45 // 'E' -#define STK_LOAD_ADDRESS 0x55 // 'U' -#define STK_UNIVERSAL 0x56 // 'V' -#define STK_PROG_PAGE 0x64 // 'd' -#define STK_READ_PAGE 0x74 // 't' -#define STK_READ_SIGN 0x75 // 'u' - -extern const u8 _readSize[] PROGMEM; -const u8 _readSize[] = -{ - STK_GET_PARAMETER, 1, - STK_SET_DEVICE, 20, - STK_SET_DEVICE_EXT, 5, - STK_UNIVERSAL, 4, - STK_LOAD_ADDRESS, 2, - STK_PROG_PAGE, 3, - STK_READ_PAGE, 3, - 0,0 -}; - -extern const u8 _consts[] PROGMEM; -const u8 _consts[] = -{ - SIGNATURE_0, - SIGNATURE_1, - SIGNATURE_2, - HW_VER, // Hardware version - SW_MAJOR, // Software major version - SW_MINOR, // Software minor version - 0x03, // Unknown but seems to be required by avr studio 3.56 - 0x00, // -}; - - -void USBInit(void); -int main(void) __attribute__ ((naked)); - -// STK500v1 main loop, very similar to optiboot in protocol and implementation -int main() -{ - wdt_disable(); - TXLED0; - RXLED0; - LED0; - BOARD_INIT(); - USBInit(); - - _inSync = STK_INSYNC; - _ok = STK_OK; - - if (pgm_read_word(0) != -1) - _ejected = 1; - - for(;;) - { - u8* packet = _flashbuf; - u16 address = 0; - for (;;) - { - u8 cmd = getch(); - - // Read packet contents - u8 len; - const u8* rs = _readSize; - for(;;) - { - u8 c = pgm_read_byte(rs++); - len = pgm_read_byte(rs++); - if (c == cmd || c == 0) - break; - } - _timeout = 0; - // Read params - Recv(CDC_RX,packet,len); - - // Send a response - u8 send = 0; - const u8* pgm = _consts+7; // 0 - if (STK_GET_PARAMETER == cmd) - { - u8 i = packet[0] - 0x80; - if (i > 2) - i = (i == 0x18) ? 3 : 4; // 0x80:HW_VER,0x81:SW_MAJOR,0x82:SW_MINOR,0x18:3 or 0 - pgm = _consts + i + 3; - send = 1; - } - - else if (STK_UNIVERSAL == cmd) - { - if (packet[0] == 0x30) - pgm = _consts + packet[2]; // read signature - send = 1; - } - - // Read signature bytes - else if (STK_READ_SIGN == cmd) - { - pgm = _consts; - send = 3; - } - - else if (STK_LOAD_ADDRESS == cmd) - { - address = *((u16*)packet); // word addresses - address += address; - } - - else if (STK_PROG_PAGE == cmd) - { - Program(CDC_RX,address,packet[1]); - } - - else if (STK_READ_PAGE == cmd) - { - send = packet[1]; - pgm = (const u8*)address; - address += send; // not sure of this is required - } - - // Check sync - if (getch() != ' ') - break; - Transfer(CDC_TX,&_inSync,1); - - // Send result - if (send) - Transfer(CDC_TX|TRANSFER_PGM,pgm,send); // All from pgm memory - - // Send ok - Transfer(CDC_TX|TRANSFER_RELEASE,&_ok,1); - - if (cmd == 'Q') - break; - } - _timeout = 500; // wait a moment before exiting the bootloader - may need to finish responding to 'Q' for example - _ejected = 1; - } -} - -// Nice breathing LED indicates we are in the firmware -u16 _pulse; -void LEDPulse() -{ - _pulse += 4; - u8 p = _pulse >> 9; - if (p > 63) - p = 127-p; - p += p; - if (((u8)_pulse) > p) - LED0; - else - LED1; -} - -void Reboot() -{ - TXLED0; // switch off the RX and TX LEDs before starting the user sketch - RXLED0; - UDCON = 1; // Detatch USB - UDIEN = 0; - asm volatile ( // Reset vector to run firmware - "clr r30\n" - "clr r31\n" - "ijmp\n" - ::); -} diff --git a/bootloaders/diskloader/src/Platform.h b/bootloaders/diskloader/src/Platform.h deleted file mode 100644 index 04c5b79..0000000 --- a/bootloaders/diskloader/src/Platform.h +++ /dev/null @@ -1,51 +0,0 @@ - -#include <inttypes.h> -#include <avr/io.h> -#include <avr/pgmspace.h> -#include <avr/boot.h> -#include <util/delay.h> -#include <avr/interrupt.h> -#include <avr/wdt.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned long u32; - - -#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) -#define DISABLE_JTAG() MCUCR = (1 << JTD) | (1 << IVCE) | (0 << PUD); MCUCR = (1 << JTD) | (0 << IVSEL) | (0 << IVCE) | (0 << PUD); - -#define USB_PID_LEONARDO 0x0034 -#define USB_PID_MICRO 0x0035 -#define USB_VID 0x2341 // arduino LLC vid -#define USB_PID ARDUINO_MODEL_PID // passed in by Makefile - 0x0034 for Leonardo, 0x0035 for MIcro - -#define USB_SERIAL_STRING '0','0','0','0','0','0','0','0','1','7','0','1' - -#define OEM_NAME 'l','e','o','n','a','r','d','o' // 8 chars -#define BOARD_INIT() DDRC |= (1<<7); DDRB |= (1<<0); DDRD |= (1<<5); CPU_PRESCALE(0); DISABLE_JTAG(); -#define LED0 PORTC &= ~(1<<7) -#define LED1 PORTC |= (1<<7) -#define TXLED0 PORTD |= (1<<5) -#define TXLED1 PORTD &= ~(1<<5) -#define RXLED0 PORTB |= (1<<0) -#define RXLED1 PORTB &= ~(1<<0) - -#define TRANSFER_PGM 0x80 -#define TRANSFER_RELEASE 0x40 -#define TRANSFER_ZERO 0x20 - -void Transfer(u8 ep, const u8* data, int len); -void Recv(u8 ep, u8* dst, u8 len); -void Program(u8 ep, u16 page, u8 count); - -#define CDC_ENABLED - -#include "USBCore.h" -#include "USBDesc.h" - - diff --git a/bootloaders/diskloader/src/USBCore.cpp b/bootloaders/diskloader/src/USBCore.cpp deleted file mode 100644 index 208121e..0000000 --- a/bootloaders/diskloader/src/USBCore.cpp +++ /dev/null @@ -1,510 +0,0 @@ - - -/* 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. -*/ - -#include "Platform.h" - -#define CDC_TX CDC_ENDPOINT_IN -#define CDC_RX CDC_ENDPOINT_OUT - -#define EP_TYPE_CONTROL 0x00 -#define EP_TYPE_BULK_IN 0x81 -#define EP_TYPE_BULK_OUT 0x80 -#define EP_TYPE_INTERRUPT_IN 0xC1 -#define EP_TYPE_INTERRUPT_OUT 0xC0 -#define EP_TYPE_ISOCHRONOUS_IN 0x41 -#define EP_TYPE_ISOCHRONOUS_OUT 0x40 - -/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */ -#define TX_RX_LED_PULSE_MS 100 -u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */ -u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */ - -void Reboot(); - -//================================================================== -//================================================================== - -typedef struct -{ - u32 dwDTERate; - u8 bCharFormat; - u8 bParityType; - u8 bDataBits; - u8 lineState; -} LineInfo; - -static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 }; - -//================================================================== -//================================================================== - -// 4 bytes of RAM -volatile u8 _usbConfiguration; -volatile u8 _ejected; -volatile u16 _timeout; - -static inline void WaitIN(void) -{ - while (!(UEINTX & (1<<TXINI))); -} - -static inline void ClearIN(void) -{ - UEINTX = ~(1<<TXINI); -} - -static inline void WaitOUT(void) -{ - while (!(UEINTX & (1<<RXOUTI))) - ; -} - -static inline u8 WaitForINOrOUT() -{ - while (!(UEINTX & ((1<<TXINI)|(1<<RXOUTI)))) - ; - return (UEINTX & (1<<RXOUTI)) == 0; -} - -static inline void ClearOUT(void) -{ - UEINTX = ~(1<<RXOUTI); -} - -static -void Send(volatile const u8* data, u8 count) -{ - TXLED1; // light the TX LED - TxLEDPulse = TX_RX_LED_PULSE_MS; - while (count--) - UEDATX = *data++; -} - -void Recv(volatile u8* data, u8 count) -{ - RXLED1; // light the RX LED - RxLEDPulse = TX_RX_LED_PULSE_MS; - while (count--) - *data++ = UEDATX; -} - -static inline u8 Recv8() -{ - RXLED1; // light the RX LED - RxLEDPulse = TX_RX_LED_PULSE_MS; - return UEDATX; -} - -static inline void Send8(u8 d) -{ - TXLED1; // light the TX LED - TxLEDPulse = TX_RX_LED_PULSE_MS; - UEDATX = d; -} - -static inline void SetEP(u8 ep) -{ - UENUM = ep; -} - -static inline u8 FifoByteCount() -{ - return UEBCLX; -} - -static inline u8 ReceivedSetupInt() -{ - return UEINTX & (1<<RXSTPI); -} - -static inline void ClearSetupInt() -{ - UEINTX = ~((1<<RXSTPI) | (1<<RXOUTI) | (1<<TXINI)); -} - -static inline void Stall() -{ - UECONX = (1<<STALLRQ) | (1<<EPEN); -} - -static inline u8 ReadWriteAllowed() -{ - return UEINTX & (1<<RWAL); -} - -static inline u8 Stalled() -{ - return UEINTX & (1<<STALLEDI); -} - -static inline u8 FifoFree() -{ - return UEINTX & (1<<FIFOCON); -} - -static inline void ReleaseRX() -{ - UEINTX = 0x6B; // FIFOCON=0 NAKINI=1 RWAL=1 NAKOUTI=0 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=1 -} - -static inline void ReleaseTX() -{ - UEINTX = 0x3A; // FIFOCON=0 NAKINI=0 RWAL=1 NAKOUTI=1 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=0 -} - -static inline u8 FrameNumber() -{ - return UDFNUML; -} - -//================================================================== -//================================================================== - -#define EP_SINGLE_64 0x32 // EP0 -#define EP_DOUBLE_64 0x36 // Other endpoints - -static void InitEP(u8 index, u8 type, u8 size) -{ - UENUM = index; - UECONX = 1; - UECFG0X = type; - UECFG1X = size; -} - -// API -void USBInit(void) -{ - _timeout = 0; - _usbConfiguration = 0; - _ejected = 0; - - UHWCON = 0x01; // power internal reg (don't need this?) - USBCON = (1<<USBE)|(1<<FRZCLK); // clock frozen, usb enabled - PLLCSR = 0x12; // Need 16 MHz xtal - while (!(PLLCSR & (1<<PLOCK))) // wait for lock pll - ; - USBCON = ((1<<USBE)|(1<<OTGPADE)); // start USB clock - UDCON = 0; // enable attach resistor -} - -u8 USBGetConfiguration(void) -{ - return _usbConfiguration; -} - -u8 HasData(u8 ep) -{ - SetEP(ep); - return ReadWriteAllowed(); // count in fifo -} - -int USBGetChar(); -void Recv(u8 ep, u8* dst, u8 len) -{ - SetEP(ep); - while (len--) - { - while (!ReadWriteAllowed()) - ; - *dst++ = Recv8(); - if (!ReadWriteAllowed()) // release empty buffer - ReleaseRX(); - } -} - -// Transmit a packet to endpoint -void Transfer(u8 ep, const u8* data, int len) -{ - u8 zero = ep & TRANSFER_ZERO; - SetEP(ep & 7); - while (len--) - { - while (!ReadWriteAllowed()) - ; // TODO Check for STALL etc - - u8 d = (ep & TRANSFER_PGM) ? pgm_read_byte(data) : data[0]; - data++; - if (zero) - d = 0; - Send8(d); - - if (!ReadWriteAllowed()) - ReleaseTX(); - } - if (ep & TRANSFER_RELEASE) - ReleaseTX(); -} - -extern const u8 _initEndpoints[] PROGMEM; -const u8 _initEndpoints[] = -{ - 0, - -#ifdef CDC_ENABLED - EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM - EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT - EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN -#endif - - EP_TYPE_INTERRUPT_IN, // HID_ENDPOINT_INT -}; - -static void InitEndpoints() -{ - for (u8 i = 1; i < sizeof(_initEndpoints); i++) - { - UENUM = i; - UECONX = 1; - UECFG0X = pgm_read_byte(_initEndpoints+i); - UECFG1X = EP_DOUBLE_64; - } - UERST = 0x7E; // And reset them - UERST = 0; -} - -typedef struct -{ - u8 bmRequestType; - u8 bRequest; - u8 wValueL; - u8 wValueH; - u16 wIndex; - u16 wLength; -} Setup; -Setup _setup; - -//bool USBHook(Setup& setup) -bool USBHook() -{ - Setup& setup = _setup; - u8 r = setup.bRequest; - - // CDC Requests - if (CDC_GET_LINE_CODING == r) - { - Send((const volatile u8*)&_usbLineInfo,7); - } - - else if (CDC_SET_LINE_CODING == r) - { - WaitOUT(); - Recv((volatile u8*)&_usbLineInfo,7); - ClearOUT(); - } - - else if (CDC_SET_CONTROL_LINE_STATE == r) - { - _usbLineInfo.lineState = setup.wValueL; - } - - return true; -} - -extern const u8 _rawHID[] PROGMEM; -#define LSB(_x) ((_x) & 0xFF) -#define MSB(_x) ((_x) >> 8) - -#define RAWHID_USAGE_PAGE 0xFFC0 -#define RAWHID_USAGE 0x0C00 -#define RAWHID_TX_SIZE 64 -#define RAWHID_RX_SIZE 64 - -const u8 _rawHID[] = -{ - // RAW HID - 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30 - 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), - - 0xA1, 0x01, // Collection 0x01 - 0x85, 0x03, // REPORT_ID (3) - 0x75, 0x08, // report size = 8 bits - 0x15, 0x00, // logical minimum = 0 - 0x26, 0xFF, 0x00, // logical maximum = 255 - - 0x95, 64, // report count TX - 0x09, 0x01, // usage - 0x81, 0x02, // Input (array) - - 0x95, 64, // report count RX - 0x09, 0x02, // usage - 0x91, 0x02, // Output (array) - 0xC0 // end collection -}; - -u8 _cdcComposite = 0; - -bool SendDescriptor() -{ - Setup& setup = _setup; - u8 desc_length = 0; - const u8* desc_addr = 0; - - u8 t = setup.wValueH; - if (0x22 == t) - { - desc_addr = _rawHID; - desc_length = sizeof(desc_length); - } else if (USB_DEVICE_DESCRIPTOR_TYPE == t) - { - if (setup.wLength == 8) - _cdcComposite = 1; - desc_addr = _cdcComposite ? (const u8*)&USB_DeviceDescriptorA : (const u8*)&USB_DeviceDescriptor; - } - else if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t) - { - desc_addr = (const u8*)&USB_ConfigDescriptor; - desc_length = sizeof(USB_ConfigDescriptor); - } - else if (USB_STRING_DESCRIPTOR_TYPE == t) - { - if (setup.wValueL == 0) - desc_addr = (const u8*)&STRING_LANGUAGE; - else if (setup.wValueL == IPRODUCT) - desc_addr = (const u8*)&STRING_IPRODUCT; - else if (setup.wValueL == ISERIAL) - desc_addr = (const u8*)&STRING_SERIAL; - else if (setup.wValueL == IMANUFACTURER) - desc_addr = (const u8*)&STRING_IMANUFACTURER; - else - return false; - } else - return false; - - if (desc_length == 0) - desc_length = pgm_read_byte(desc_addr); - if ((u8)setup.wLength < desc_length) // bit of a cheat limiting to 255 bytes TODO (saved 8 bytes) - desc_length = (u8)setup.wLength; - - // Send descriptor - // EP0 is 64 bytes long - // RWAL and FIFOCON don't work on EP0 - u8 n = 0; - do - { - if (!WaitForINOrOUT()) - return false; - Send8(pgm_read_byte(&desc_addr[n++])); - u8 clr = n & 0x3F; - if (!clr) - ClearIN(); // Fifo is full, release this packet - } while (n < desc_length); - return true; -} - -void USBSetupInterrupt() -{ - SetEP(0); - if (!ReceivedSetupInt()) - return; - - Setup& setup = _setup; // global saves ~30 bytes - Recv((u8*)&setup,8); - ClearSetupInt(); - - if (setup.bmRequestType & DEVICETOHOST) - WaitIN(); - else - ClearIN(); - - bool ok = true; - u8 r = setup.bRequest; - if (SET_ADDRESS == r) - { - WaitIN(); - UDADDR = setup.wValueL | (1<<ADDEN); - } - else if (SET_CONFIGURATION == r) - { - _usbConfiguration = setup.wValueL; - InitEndpoints(); - } - else if (GET_CONFIGURATION == r) - { - Send8(_usbConfiguration); - } - else if (GET_STATUS == r) - { - Send8(0); // All good as far as I know - } - else if (GET_DESCRIPTOR == r) - { - ok = SendDescriptor(); - } - else - { - ok = USBHook(); - } - - if (ok) - ClearIN(); - else - Stall(); -} - -void USBGeneralInterrupt() -{ - u8 udint = UDINT; - UDINT = 0; - - // End of Reset - if (udint & (1<<EORSTI)) - { - InitEP(0,EP_TYPE_CONTROL,EP_SINGLE_64); // init ep0 - _usbConfiguration = 0; // not configured yet - } - - // Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too - if (udint & (1<<SOFI)) - { - // check whether the one-shot period has elapsed. if so, turn off the LED - if (TxLEDPulse && !(--TxLEDPulse)) - TXLED0; - if (RxLEDPulse && !(--RxLEDPulse)) - RXLED0; - - if (!_ejected) - _timeout = 0; - } -} - -void LEDPulse(); -int USBGetChar() -{ - for(;;) - { - USBSetupInterrupt(); - USBGeneralInterrupt(); - - // Read a char - if (HasData(CDC_RX)) - { - u8 c = Recv8(); - if (!ReadWriteAllowed()) - ReleaseRX(); - return c; - } - - if (!--_timeout) { - Reboot(); // USB not connected, run firmware - } - - _delay_us(100); // stretch out the bootloader period to about 5 seconds after enumeration - LEDPulse(); - } - return -1; -} diff --git a/bootloaders/diskloader/src/USBCore.h b/bootloaders/diskloader/src/USBCore.h deleted file mode 100644 index 537c0ec..0000000 --- a/bootloaders/diskloader/src/USBCore.h +++ /dev/null @@ -1,246 +0,0 @@ - -// 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__ - -#define GET_STATUS 0 -#define CLEAR_FEATURE 1 -#define SET_FEATURE 3 -#define SET_ADDRESS 5 -#define GET_DESCRIPTOR 6 -#define GET_CONFIGURATION 8 -#define SET_CONFIGURATION 9 -#define GET_INTERFACE 10 -#define SET_INTERFACE 11 - -// bmRequestType -#define HOSTTODEVICE 0x00 -#define DEVICETOHOST 0x80 -#define STANDARD 0x00 -#define CLASS 0x20 -#define VENDOR 0x40 -#define DEVICE 0x00 -#define INTERFACE 0x01 -#define ENDPOINT 0x02 -#define OTHER 0x03 - -#define CDC_SET_LINE_CODING 0x20 -#define CDC_GET_LINE_CODING 0x21 -#define CDC_SET_CONTROL_LINE_STATE 0x22 - -// 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 - - -// 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 -{ - IADDescriptor iad; // Only needed on compound device - - // Control - InterfaceDescriptor cif; // - CDCCSInterfaceDescriptor header; - CDCCSInterfaceDescriptor callManagement; - CDCCSInterfaceDescriptor4 controlManagement; - CDCCSInterfaceDescriptor functionalDescriptor; - EndpointDescriptor cifin; - - // Data - InterfaceDescriptor dif; - EndpointDescriptor in; - EndpointDescriptor out; -} CDCDescriptor; - -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(100) } - -#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
\ No newline at end of file diff --git a/bootloaders/diskloader/src/USBDesc.cpp b/bootloaders/diskloader/src/USBDesc.cpp deleted file mode 100644 index ade072a..0000000 --- a/bootloaders/diskloader/src/USBDesc.cpp +++ /dev/null @@ -1,87 +0,0 @@ - - -/* 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. -*/ - -#include "Platform.h" - -//==================================================================================================== -//==================================================================================================== -// Actual device descriptors - -const u16 STRING_LANGUAGE[2] = { - (3<<8) | (2+2), - 0x0409 // English -}; - -const u16 STRING_SERIAL[13] = { - (3<<8) | (2+2*12), - USB_SERIAL_STRING -}; - -const u16 STRING_IPRODUCT[28] = { - (3<<8) | (2+2*27), -#if USB_PID == USB_PID_LEONARDO - 'A','r','d','u','i','n','o',' ','L','e','o','n','a','r','d','o',' ','b','o','o','t','l','o','a','d','e','r' -#elif USB_PID == USB_PID_MICRO - 'A','r','d','u','i','n','o',' ','M','i','c','r','o',' ','b','o','o','t','l','o','a','d','e','r',' ',' ',' ' -#endif -}; - -const u16 STRING_IMANUFACTURER[12] = { - (3<<8) | (2+2*11), - 'A','r','d','u','i','n','o',' ','L','L','C' -}; - - -//#ifdef CDC_ENABLED -DeviceDescriptor USB_DeviceDescriptorA = D_DEVICE(0X02,0X00,0X00,64,USB_VID,USB_PID,0x100,0,IPRODUCT,ISERIAL,1); -//#else -DeviceDescriptor USB_DeviceDescriptor = D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,0,IPRODUCT,ISERIAL,1); -//#endif - - -Config USB_ConfigDescriptor = -{ - D_CONFIG(sizeof(Config),INTERFACE_COUNT), - -#ifdef CDC_ENABLED - // CDC - { - 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 - D_CDCCS4(CDC_ABSTRACT_CONTROL_MANAGEMENT,2), // 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_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,0x40,0), - D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x40,0) - }, -#endif - // HID - { - D_INTERFACE(HID_INTERFACE,1,3,0,0), - D_HIDREPORT(30), - D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x40) - } -}; - diff --git a/bootloaders/diskloader/src/USBDesc.h b/bootloaders/diskloader/src/USBDesc.h deleted file mode 100644 index a970fa4..0000000 --- a/bootloaders/diskloader/src/USBDesc.h +++ /dev/null @@ -1,65 +0,0 @@ - - -/* 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. -*/ - - -#ifdef CDC_ENABLED - -#define CDC_ACM_INTERFACE 0 // CDC ACM -#define CDC_DATA_INTERFACE 1 // CDC Data -#define CDC_ENDPOINT_ACM 1 -#define CDC_ENDPOINT_OUT 2 -#define CDC_ENDPOINT_IN 3 - -#define HID_INTERFACE 2 // HID Interface -#define HID_ENDPOINT_INT 4 - -#define INTERFACE_COUNT 3 // 2 for cdc + 1 for hid - -#else - -#define HID_INTERFACE 2 // HID Interface -#define HID_ENDPOINT_INT 4 - -#define INTERFACE_COUNT 1 // 1 for hid - -#endif - -typedef struct -{ - ConfigDescriptor config; -#ifdef CDC_ENABLED - CDCDescriptor cdc; -#endif - HIDDescriptor hid; -} Config; - -extern Config USB_ConfigDescriptor PROGMEM; -extern DeviceDescriptor USB_DeviceDescriptor PROGMEM; -extern DeviceDescriptor USB_DeviceDescriptorA PROGMEM; - -extern const u16 STRING_LANGUAGE[2] PROGMEM; -extern const u16 STRING_IPRODUCT[28] PROGMEM; -extern const u16 STRING_IMANUFACTURER[12] PROGMEM; -extern const u16 STRING_SERIAL[13] PROGMEM; - -#define IMANUFACTURER 1 -#define IPRODUCT 2 -#define ISERIAL 3 - -#define CDC_TX CDC_ENDPOINT_IN -#define CDC_RX CDC_ENDPOINT_OUT
\ No newline at end of file |