mirror of https://github.com/noisymime/Arduino.git
got rid of u8, u16, u32 typedefs in Diskloader
done to bring types in line with others in Arduino core
This commit is contained in:
parent
f403b001a2
commit
e3b89d178d
|
@ -26,15 +26,15 @@ void entrypoint(void)
|
||||||
::);
|
::);
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 _flashbuf[128];
|
uint8_t _flashbuf[128];
|
||||||
u8 _inSync;
|
uint8_t _inSync;
|
||||||
u8 _ok;
|
uint8_t _ok;
|
||||||
extern volatile u8 _ejected;
|
extern volatile uint8_t _ejected;
|
||||||
extern volatile u16 _timeout;
|
extern volatile uint16_t _timeout;
|
||||||
|
|
||||||
void Program(u8 ep, u16 page, u8 count)
|
void Program(uint8_t ep, uint16_t page, uint8_t count)
|
||||||
{
|
{
|
||||||
u8 write = page < 30*1024; // Don't write over firmware please
|
uint8_t write = page < 30*1024; // Don't write over firmware please
|
||||||
if (write)
|
if (write)
|
||||||
boot_page_erase(page);
|
boot_page_erase(page);
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ void Program(u8 ep, u16 page, u8 count)
|
||||||
boot_spm_busy_wait(); // Wait until the memory is erased.
|
boot_spm_busy_wait(); // Wait until the memory is erased.
|
||||||
|
|
||||||
count >>= 1;
|
count >>= 1;
|
||||||
u16* p = (u16*)page;
|
uint16_t* p = (uint16_t*)page;
|
||||||
u16* b = (u16*)_flashbuf;
|
uint16_t* b = (uint16_t*)_flashbuf;
|
||||||
for (u8 i = 0; i < count; i++)
|
for (uint8_t i = 0; i < count; i++)
|
||||||
boot_page_fill(p++, b[i]);
|
boot_page_fill(p++, b[i]);
|
||||||
|
|
||||||
boot_page_write(page);
|
boot_page_write(page);
|
||||||
|
@ -78,8 +78,8 @@ int USBGetChar();
|
||||||
#define STK_READ_PAGE 0x74 // 't'
|
#define STK_READ_PAGE 0x74 // 't'
|
||||||
#define STK_READ_SIGN 0x75 // 'u'
|
#define STK_READ_SIGN 0x75 // 'u'
|
||||||
|
|
||||||
extern const u8 _readSize[] PROGMEM;
|
extern const uint8_t _readSize[] PROGMEM;
|
||||||
const u8 _readSize[] =
|
const uint8_t _readSize[] =
|
||||||
{
|
{
|
||||||
STK_GET_PARAMETER, 1,
|
STK_GET_PARAMETER, 1,
|
||||||
STK_SET_DEVICE, 20,
|
STK_SET_DEVICE, 20,
|
||||||
|
@ -91,8 +91,8 @@ const u8 _readSize[] =
|
||||||
0,0
|
0,0
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const u8 _consts[] PROGMEM;
|
extern const uint8_t _consts[] PROGMEM;
|
||||||
const u8 _consts[] =
|
const uint8_t _consts[] =
|
||||||
{
|
{
|
||||||
SIGNATURE_0,
|
SIGNATURE_0,
|
||||||
SIGNATURE_1,
|
SIGNATURE_1,
|
||||||
|
@ -131,18 +131,18 @@ int main()
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
u8* packet = _flashbuf;
|
uint8_t* packet = _flashbuf;
|
||||||
u16 address = 0;
|
uint16_t address = 0;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
u8 cmd = getch();
|
uint8_t cmd = getch();
|
||||||
|
|
||||||
// Read packet contents
|
// Read packet contents
|
||||||
u8 len;
|
uint8_t len;
|
||||||
const u8* rs = _readSize;
|
const uint8_t* rs = _readSize;
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
u8 c = pgm_read_byte(rs++);
|
uint8_t c = pgm_read_byte(rs++);
|
||||||
len = pgm_read_byte(rs++);
|
len = pgm_read_byte(rs++);
|
||||||
if (c == cmd || c == 0)
|
if (c == cmd || c == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -152,11 +152,11 @@ int main()
|
||||||
Recv(CDC_RX,packet,len);
|
Recv(CDC_RX,packet,len);
|
||||||
|
|
||||||
// Send a response
|
// Send a response
|
||||||
u8 send = 0;
|
uint8_t send = 0;
|
||||||
const u8* pgm = _consts+7; // 0
|
const uint8_t* pgm = _consts+7; // 0
|
||||||
if (STK_GET_PARAMETER == cmd)
|
if (STK_GET_PARAMETER == cmd)
|
||||||
{
|
{
|
||||||
u8 i = packet[0] - 0x80;
|
uint8_t i = packet[0] - 0x80;
|
||||||
if (i > 2)
|
if (i > 2)
|
||||||
i = (i == 0x18) ? 3 : 4; // 0x80:HW_VER,0x81:SW_MAJOR,0x82:SW_MINOR,0x18:3 or 0
|
i = (i == 0x18) ? 3 : 4; // 0x80:HW_VER,0x81:SW_MAJOR,0x82:SW_MINOR,0x18:3 or 0
|
||||||
pgm = _consts + i + 3;
|
pgm = _consts + i + 3;
|
||||||
|
@ -179,7 +179,7 @@ int main()
|
||||||
|
|
||||||
else if (STK_LOAD_ADDRESS == cmd)
|
else if (STK_LOAD_ADDRESS == cmd)
|
||||||
{
|
{
|
||||||
address = *((u16*)packet); // word addresses
|
address = *((uint16_t*)packet); // word addresses
|
||||||
address += address;
|
address += address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ int main()
|
||||||
else if (STK_READ_PAGE == cmd)
|
else if (STK_READ_PAGE == cmd)
|
||||||
{
|
{
|
||||||
send = packet[1];
|
send = packet[1];
|
||||||
pgm = (const u8*)address;
|
pgm = (const uint8_t*)address;
|
||||||
address += send; // not sure of this is required
|
address += send; // not sure of this is required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,15 +216,15 @@ int main()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nice breathing LED indicates we are in the firmware
|
// Nice breathing LED indicates we are in the firmware
|
||||||
u16 _pulse;
|
uint16_t _pulse;
|
||||||
void LEDPulse()
|
void LEDPulse()
|
||||||
{
|
{
|
||||||
_pulse += 4;
|
_pulse += 4;
|
||||||
u8 p = _pulse >> 9;
|
uint8_t p = _pulse >> 9;
|
||||||
if (p > 63)
|
if (p > 63)
|
||||||
p = 127-p;
|
p = 127-p;
|
||||||
p += p;
|
p += p;
|
||||||
if (((u8)_pulse) > p)
|
if (((uint8_t)_pulse) > p)
|
||||||
L_LED_OFF();
|
L_LED_OFF();
|
||||||
else
|
else
|
||||||
L_LED_ON();
|
L_LED_ON();
|
||||||
|
@ -234,7 +234,7 @@ void StartSketch()
|
||||||
{
|
{
|
||||||
TX_LED_OFF(); // switch off the RX and TX LEDs before starting the user sketch
|
TX_LED_OFF(); // switch off the RX and TX LEDs before starting the user sketch
|
||||||
RX_LED_OFF();
|
RX_LED_OFF();
|
||||||
UDCON = 1; // Detatch USB
|
UDCON = 1; // Detach USB
|
||||||
UDIEN = 0;
|
UDIEN = 0;
|
||||||
asm volatile ( // Reset vector to run firmware
|
asm volatile ( // Reset vector to run firmware
|
||||||
"clr r30\n"
|
"clr r30\n"
|
||||||
|
@ -245,7 +245,7 @@ void StartSketch()
|
||||||
|
|
||||||
void Reset()
|
void Reset()
|
||||||
{
|
{
|
||||||
wdt_enable(WDTO_15MS);
|
wdt_enable(WDTO_15MS); // reset the microcontroller to reinitialize all IO and other registers
|
||||||
for (;;)
|
for (;;)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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 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 DISABLE_JTAG() MCUCR = (1 << JTD) | (1 << IVCE) | (0 << PUD); MCUCR = (1 << JTD) | (0 << IVSEL) | (0 << IVCE) | (0 << PUD);
|
||||||
|
|
||||||
|
@ -39,9 +34,9 @@ typedef unsigned long u32;
|
||||||
#define TRANSFER_RELEASE 0x40
|
#define TRANSFER_RELEASE 0x40
|
||||||
#define TRANSFER_ZERO 0x20
|
#define TRANSFER_ZERO 0x20
|
||||||
|
|
||||||
void Transfer(u8 ep, const u8* data, int len);
|
void Transfer(uint8_t ep, const uint8_t* data, int len);
|
||||||
void Recv(u8 ep, u8* dst, u8 len);
|
void Recv(uint8_t ep, uint8_t* dst, uint8_t len);
|
||||||
void Program(u8 ep, u16 page, u8 count);
|
void Program(uint8_t ep, uint16_t page, uint8_t count);
|
||||||
|
|
||||||
/* HID is not fully-supported in the bootloader - can be enabled
|
/* HID is not fully-supported in the bootloader - can be enabled
|
||||||
for testing, but note the descriptor report and other parts are
|
for testing, but note the descriptor report and other parts are
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
|
|
||||||
/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
|
/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
|
||||||
#define TX_RX_LED_PULSE_MS 100
|
#define TX_RX_LED_PULSE_MS 100
|
||||||
u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
|
uint8_t TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
|
||||||
u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
|
uint8_t RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
|
@ -41,11 +41,11 @@ void Reset();
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u32 dwDTERate;
|
uint32_t dwDTERate;
|
||||||
u8 bCharFormat;
|
uint8_t bCharFormat;
|
||||||
u8 bParityType;
|
uint8_t bParityType;
|
||||||
u8 bDataBits;
|
uint8_t bDataBits;
|
||||||
u8 lineState;
|
uint8_t lineState;
|
||||||
} LineInfo;
|
} LineInfo;
|
||||||
|
|
||||||
static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
|
static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
@ -54,9 +54,9 @@ static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
|
||||||
//==================================================================
|
//==================================================================
|
||||||
|
|
||||||
// 4 bytes of RAM
|
// 4 bytes of RAM
|
||||||
volatile u8 _usbConfiguration;
|
volatile uint8_t _usbConfiguration;
|
||||||
volatile u8 _ejected;
|
volatile uint8_t _ejected;
|
||||||
volatile u16 _timeout;
|
volatile uint16_t _timeout;
|
||||||
|
|
||||||
static inline void WaitIN(void)
|
static inline void WaitIN(void)
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,7 @@ static inline void WaitOUT(void)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u8 WaitForINOrOUT()
|
static inline uint8_t WaitForINOrOUT()
|
||||||
{
|
{
|
||||||
while (!(UEINTX & ((1<<TXINI)|(1<<RXOUTI))))
|
while (!(UEINTX & ((1<<TXINI)|(1<<RXOUTI))))
|
||||||
;
|
;
|
||||||
|
@ -87,7 +87,7 @@ static inline void ClearOUT(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void Send(volatile const u8* data, u8 count)
|
void Send(volatile const uint8_t* data, uint8_t count)
|
||||||
{
|
{
|
||||||
TX_LED_ON(); // light the TX LED
|
TX_LED_ON(); // light the TX LED
|
||||||
TxLEDPulse = TX_RX_LED_PULSE_MS;
|
TxLEDPulse = TX_RX_LED_PULSE_MS;
|
||||||
|
@ -95,7 +95,7 @@ void Send(volatile const u8* data, u8 count)
|
||||||
UEDATX = *data++;
|
UEDATX = *data++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Recv(volatile u8* data, u8 count)
|
void Recv(volatile uint8_t* data, uint8_t count)
|
||||||
{
|
{
|
||||||
RX_LED_ON(); // light the RX LED
|
RX_LED_ON(); // light the RX LED
|
||||||
RxLEDPulse = TX_RX_LED_PULSE_MS;
|
RxLEDPulse = TX_RX_LED_PULSE_MS;
|
||||||
|
@ -103,31 +103,31 @@ void Recv(volatile u8* data, u8 count)
|
||||||
*data++ = UEDATX;
|
*data++ = UEDATX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u8 Recv8()
|
static inline uint8_t Recv8()
|
||||||
{
|
{
|
||||||
RX_LED_ON(); // light the RX LED
|
RX_LED_ON(); // light the RX LED
|
||||||
RxLEDPulse = TX_RX_LED_PULSE_MS;
|
RxLEDPulse = TX_RX_LED_PULSE_MS;
|
||||||
return UEDATX;
|
return UEDATX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Send8(u8 d)
|
static inline void Send8(uint8_t d)
|
||||||
{
|
{
|
||||||
TX_LED_ON(); // light the TX LED
|
TX_LED_ON(); // light the TX LED
|
||||||
TxLEDPulse = TX_RX_LED_PULSE_MS;
|
TxLEDPulse = TX_RX_LED_PULSE_MS;
|
||||||
UEDATX = d;
|
UEDATX = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void SetEP(u8 ep)
|
static inline void SetEP(uint8_t ep)
|
||||||
{
|
{
|
||||||
UENUM = ep;
|
UENUM = ep;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u8 FifoByteCount()
|
static inline uint8_t FifoByteCount()
|
||||||
{
|
{
|
||||||
return UEBCLX;
|
return UEBCLX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u8 ReceivedSetupInt()
|
static inline uint8_t ReceivedSetupInt()
|
||||||
{
|
{
|
||||||
return UEINTX & (1<<RXSTPI);
|
return UEINTX & (1<<RXSTPI);
|
||||||
}
|
}
|
||||||
|
@ -142,17 +142,17 @@ static inline void Stall()
|
||||||
UECONX = (1<<STALLRQ) | (1<<EPEN);
|
UECONX = (1<<STALLRQ) | (1<<EPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u8 ReadWriteAllowed()
|
static inline uint8_t ReadWriteAllowed()
|
||||||
{
|
{
|
||||||
return UEINTX & (1<<RWAL);
|
return UEINTX & (1<<RWAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u8 Stalled()
|
static inline uint8_t Stalled()
|
||||||
{
|
{
|
||||||
return UEINTX & (1<<STALLEDI);
|
return UEINTX & (1<<STALLEDI);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u8 FifoFree()
|
static inline uint8_t FifoFree()
|
||||||
{
|
{
|
||||||
return UEINTX & (1<<FIFOCON);
|
return UEINTX & (1<<FIFOCON);
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ static inline void ReleaseTX()
|
||||||
UEINTX = 0x3A; // FIFOCON=0 NAKINI=0 RWAL=1 NAKOUTI=1 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=0
|
UEINTX = 0x3A; // FIFOCON=0 NAKINI=0 RWAL=1 NAKOUTI=1 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=0
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u8 FrameNumber()
|
static inline uint8_t FrameNumber()
|
||||||
{
|
{
|
||||||
return UDFNUML;
|
return UDFNUML;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ static inline u8 FrameNumber()
|
||||||
#define EP_SINGLE_64 0x32 // EP0
|
#define EP_SINGLE_64 0x32 // EP0
|
||||||
#define EP_DOUBLE_64 0x36 // Other endpoints
|
#define EP_DOUBLE_64 0x36 // Other endpoints
|
||||||
|
|
||||||
static void InitEP(u8 index, u8 type, u8 size)
|
static void InitEP(uint8_t index, uint8_t type, uint8_t size)
|
||||||
{
|
{
|
||||||
UENUM = index;
|
UENUM = index;
|
||||||
UECONX = 1;
|
UECONX = 1;
|
||||||
|
@ -202,19 +202,19 @@ void USBInit(void)
|
||||||
UDCON = 0; // enable attach resistor
|
UDCON = 0; // enable attach resistor
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 USBGetConfiguration(void)
|
uint8_t USBGetConfiguration(void)
|
||||||
{
|
{
|
||||||
return _usbConfiguration;
|
return _usbConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 HasData(u8 ep)
|
uint8_t HasData(uint8_t ep)
|
||||||
{
|
{
|
||||||
SetEP(ep);
|
SetEP(ep);
|
||||||
return ReadWriteAllowed(); // count in fifo
|
return ReadWriteAllowed(); // count in fifo
|
||||||
}
|
}
|
||||||
|
|
||||||
int USBGetChar();
|
int USBGetChar();
|
||||||
void Recv(u8 ep, u8* dst, u8 len)
|
void Recv(uint8_t ep, uint8_t* dst, uint8_t len)
|
||||||
{
|
{
|
||||||
SetEP(ep);
|
SetEP(ep);
|
||||||
while (len--)
|
while (len--)
|
||||||
|
@ -228,16 +228,16 @@ void Recv(u8 ep, u8* dst, u8 len)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transmit a packet to endpoint
|
// Transmit a packet to endpoint
|
||||||
void Transfer(u8 ep, const u8* data, int len)
|
void Transfer(uint8_t ep, const uint8_t* data, int len)
|
||||||
{
|
{
|
||||||
u8 zero = ep & TRANSFER_ZERO;
|
uint8_t zero = ep & TRANSFER_ZERO;
|
||||||
SetEP(ep & 7);
|
SetEP(ep & 7);
|
||||||
while (len--)
|
while (len--)
|
||||||
{
|
{
|
||||||
while (!ReadWriteAllowed())
|
while (!ReadWriteAllowed())
|
||||||
; // TODO Check for STALL etc
|
; // TODO Check for STALL etc
|
||||||
|
|
||||||
u8 d = (ep & TRANSFER_PGM) ? pgm_read_byte(data) : data[0];
|
uint8_t d = (ep & TRANSFER_PGM) ? pgm_read_byte(data) : data[0];
|
||||||
data++;
|
data++;
|
||||||
if (zero)
|
if (zero)
|
||||||
d = 0;
|
d = 0;
|
||||||
|
@ -250,8 +250,8 @@ void Transfer(u8 ep, const u8* data, int len)
|
||||||
ReleaseTX();
|
ReleaseTX();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const u8 _initEndpoints[] PROGMEM;
|
extern const uint8_t _initEndpoints[] PROGMEM;
|
||||||
const u8 _initEndpoints[] =
|
const uint8_t _initEndpoints[] =
|
||||||
{
|
{
|
||||||
0,
|
0,
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ const u8 _initEndpoints[] =
|
||||||
|
|
||||||
static void InitEndpoints()
|
static void InitEndpoints()
|
||||||
{
|
{
|
||||||
for (u8 i = 1; i < sizeof(_initEndpoints); i++)
|
for (uint8_t i = 1; i < sizeof(_initEndpoints); i++)
|
||||||
{
|
{
|
||||||
UENUM = i;
|
UENUM = i;
|
||||||
UECONX = 1;
|
UECONX = 1;
|
||||||
|
@ -279,12 +279,12 @@ static void InitEndpoints()
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u8 bmRequestType;
|
uint8_t bmRequestType;
|
||||||
u8 bRequest;
|
uint8_t bRequest;
|
||||||
u8 wValueL;
|
uint8_t wValueL;
|
||||||
u8 wValueH;
|
uint8_t wValueH;
|
||||||
u16 wIndex;
|
uint16_t wIndex;
|
||||||
u16 wLength;
|
uint16_t wLength;
|
||||||
} Setup;
|
} Setup;
|
||||||
Setup _setup;
|
Setup _setup;
|
||||||
|
|
||||||
|
@ -292,18 +292,18 @@ Setup _setup;
|
||||||
bool USBHook()
|
bool USBHook()
|
||||||
{
|
{
|
||||||
Setup& setup = _setup;
|
Setup& setup = _setup;
|
||||||
u8 r = setup.bRequest;
|
uint8_t r = setup.bRequest;
|
||||||
|
|
||||||
// CDC Requests
|
// CDC Requests
|
||||||
if (CDC_GET_LINE_CODING == r)
|
if (CDC_GET_LINE_CODING == r)
|
||||||
{
|
{
|
||||||
Send((const volatile u8*)&_usbLineInfo,7);
|
Send((const volatile uint8_t*)&_usbLineInfo,7);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (CDC_SET_LINE_CODING == r)
|
else if (CDC_SET_LINE_CODING == r)
|
||||||
{
|
{
|
||||||
WaitOUT();
|
WaitOUT();
|
||||||
Recv((volatile u8*)&_usbLineInfo,7);
|
Recv((volatile uint8_t*)&_usbLineInfo,7);
|
||||||
ClearOUT();
|
ClearOUT();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ bool USBHook()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const u8 _rawHID[] PROGMEM;
|
extern const uint8_t _rawHID[] PROGMEM;
|
||||||
#define LSB(_x) ((_x) & 0xFF)
|
#define LSB(_x) ((_x) & 0xFF)
|
||||||
#define MSB(_x) ((_x) >> 8)
|
#define MSB(_x) ((_x) >> 8)
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ extern const u8 _rawHID[] PROGMEM;
|
||||||
#define RAWHID_TX_SIZE 64
|
#define RAWHID_TX_SIZE 64
|
||||||
#define RAWHID_RX_SIZE 64
|
#define RAWHID_RX_SIZE 64
|
||||||
|
|
||||||
const u8 _rawHID[] =
|
const uint8_t _rawHID[] =
|
||||||
{
|
{
|
||||||
// RAW HID
|
// RAW HID
|
||||||
0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30
|
0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30
|
||||||
|
@ -346,15 +346,15 @@ const u8 _rawHID[] =
|
||||||
0xC0 // end collection
|
0xC0 // end collection
|
||||||
};
|
};
|
||||||
|
|
||||||
u8 _cdcComposite = 0;
|
uint8_t _cdcComposite = 0;
|
||||||
|
|
||||||
bool SendDescriptor()
|
bool SendDescriptor()
|
||||||
{
|
{
|
||||||
Setup& setup = _setup;
|
Setup& setup = _setup;
|
||||||
u16 desc_length = 0;
|
uint16_t desc_length = 0;
|
||||||
const u8* desc_addr = 0;
|
const uint8_t* desc_addr = 0;
|
||||||
|
|
||||||
u8 t = setup.wValueH;
|
uint8_t t = setup.wValueH;
|
||||||
if (0x22 == t)
|
if (0x22 == t)
|
||||||
{
|
{
|
||||||
#ifdef HID_ENABLED
|
#ifdef HID_ENABLED
|
||||||
|
@ -363,23 +363,23 @@ bool SendDescriptor()
|
||||||
#endif
|
#endif
|
||||||
} else if (USB_DEVICE_DESCRIPTOR_TYPE == t)
|
} else if (USB_DEVICE_DESCRIPTOR_TYPE == t)
|
||||||
{
|
{
|
||||||
desc_addr = (const u8*)&USB_DeviceDescriptor;
|
desc_addr = (const uint8_t*)&USB_DeviceDescriptor;
|
||||||
}
|
}
|
||||||
else if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
|
else if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
|
||||||
{
|
{
|
||||||
desc_addr = (const u8*)&USB_ConfigDescriptor;
|
desc_addr = (const uint8_t*)&USB_ConfigDescriptor;
|
||||||
desc_length = sizeof(USB_ConfigDescriptor);
|
desc_length = sizeof(USB_ConfigDescriptor);
|
||||||
}
|
}
|
||||||
else if (USB_STRING_DESCRIPTOR_TYPE == t)
|
else if (USB_STRING_DESCRIPTOR_TYPE == t)
|
||||||
{
|
{
|
||||||
if (setup.wValueL == 0)
|
if (setup.wValueL == 0)
|
||||||
desc_addr = (const u8*)&STRING_LANGUAGE;
|
desc_addr = (const uint8_t*)&STRING_LANGUAGE;
|
||||||
else if (setup.wValueL == IPRODUCT)
|
else if (setup.wValueL == IPRODUCT)
|
||||||
desc_addr = (const u8*)&STRING_IPRODUCT;
|
desc_addr = (const uint8_t*)&STRING_IPRODUCT;
|
||||||
else if (setup.wValueL == ISERIAL)
|
else if (setup.wValueL == ISERIAL)
|
||||||
desc_addr = (const u8*)&STRING_SERIAL;
|
desc_addr = (const uint8_t*)&STRING_SERIAL;
|
||||||
else if (setup.wValueL == IMANUFACTURER)
|
else if (setup.wValueL == IMANUFACTURER)
|
||||||
desc_addr = (const u8*)&STRING_IMANUFACTURER;
|
desc_addr = (const uint8_t*)&STRING_IMANUFACTURER;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
} else
|
} else
|
||||||
|
@ -393,13 +393,13 @@ bool SendDescriptor()
|
||||||
// Send descriptor
|
// Send descriptor
|
||||||
// EP0 is 64 bytes long
|
// EP0 is 64 bytes long
|
||||||
// RWAL and FIFOCON don't work on EP0
|
// RWAL and FIFOCON don't work on EP0
|
||||||
u16 n = 0;
|
uint16_t n = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!WaitForINOrOUT())
|
if (!WaitForINOrOUT())
|
||||||
return false;
|
return false;
|
||||||
Send8(pgm_read_byte(&desc_addr[n++]));
|
Send8(pgm_read_byte(&desc_addr[n++]));
|
||||||
u8 clr = n & 0x3F;
|
uint8_t clr = n & 0x3F;
|
||||||
if (!clr)
|
if (!clr)
|
||||||
ClearIN(); // Fifo is full, release this packet
|
ClearIN(); // Fifo is full, release this packet
|
||||||
} while (n < desc_length);
|
} while (n < desc_length);
|
||||||
|
@ -413,7 +413,7 @@ void USBSetupInterrupt()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Setup& setup = _setup; // global saves ~30 bytes
|
Setup& setup = _setup; // global saves ~30 bytes
|
||||||
Recv((u8*)&setup,8);
|
Recv((uint8_t*)&setup,8);
|
||||||
ClearSetupInt();
|
ClearSetupInt();
|
||||||
|
|
||||||
if (setup.bmRequestType & DEVICETOHOST)
|
if (setup.bmRequestType & DEVICETOHOST)
|
||||||
|
@ -422,7 +422,7 @@ void USBSetupInterrupt()
|
||||||
ClearIN();
|
ClearIN();
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
u8 r = setup.bRequest;
|
uint8_t r = setup.bRequest;
|
||||||
if (SET_ADDRESS == r)
|
if (SET_ADDRESS == r)
|
||||||
{
|
{
|
||||||
WaitIN();
|
WaitIN();
|
||||||
|
@ -458,7 +458,7 @@ void USBSetupInterrupt()
|
||||||
|
|
||||||
void USBGeneralInterrupt()
|
void USBGeneralInterrupt()
|
||||||
{
|
{
|
||||||
u8 udint = UDINT;
|
uint8_t udint = UDINT;
|
||||||
UDINT = 0;
|
UDINT = 0;
|
||||||
|
|
||||||
// End of Reset
|
// End of Reset
|
||||||
|
@ -493,7 +493,7 @@ int USBGetChar()
|
||||||
// Read a char
|
// Read a char
|
||||||
if (HasData(CDC_RX))
|
if (HasData(CDC_RX))
|
||||||
{
|
{
|
||||||
u8 c = Recv8();
|
uint8_t c = Recv8();
|
||||||
if (!ReadWriteAllowed())
|
if (!ReadWriteAllowed())
|
||||||
ReleaseRX();
|
ReleaseRX();
|
||||||
return c;
|
return c;
|
||||||
|
|
|
@ -97,32 +97,32 @@
|
||||||
|
|
||||||
// Device
|
// Device
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u8 len; // 18
|
uint8_t len; // 18
|
||||||
u8 dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE
|
uint8_t dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE
|
||||||
u16 usbVersion; // 0x200
|
uint16_t usbVersion; // 0x200
|
||||||
u8 deviceClass;
|
uint8_t deviceClass;
|
||||||
u8 deviceSubClass;
|
uint8_t deviceSubClass;
|
||||||
u8 deviceProtocol;
|
uint8_t deviceProtocol;
|
||||||
u8 packetSize0; // Packet 0
|
uint8_t packetSize0; // Packet 0
|
||||||
u16 idVendor;
|
uint16_t idVendor;
|
||||||
u16 idProduct;
|
uint16_t idProduct;
|
||||||
u16 deviceVersion; // 0x100
|
uint16_t deviceVersion; // 0x100
|
||||||
u8 iManufacturer;
|
uint8_t iManufacturer;
|
||||||
u8 iProduct;
|
uint8_t iProduct;
|
||||||
u8 iSerialNumber;
|
uint8_t iSerialNumber;
|
||||||
u8 bNumConfigurations;
|
uint8_t bNumConfigurations;
|
||||||
} DeviceDescriptor;
|
} DeviceDescriptor;
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u8 len; // 9
|
uint8_t len; // 9
|
||||||
u8 dtype; // 2
|
uint8_t dtype; // 2
|
||||||
u16 clen; // total length
|
uint16_t clen; // total length
|
||||||
u8 numInterfaces;
|
uint8_t numInterfaces;
|
||||||
u8 config;
|
uint8_t config;
|
||||||
u8 iconfig;
|
uint8_t iconfig;
|
||||||
u8 attributes;
|
uint8_t attributes;
|
||||||
u8 maxPower;
|
uint8_t maxPower;
|
||||||
} ConfigDescriptor;
|
} ConfigDescriptor;
|
||||||
|
|
||||||
// String
|
// String
|
||||||
|
@ -130,58 +130,58 @@ typedef struct {
|
||||||
// Interface
|
// Interface
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u8 len; // 9
|
uint8_t len; // 9
|
||||||
u8 dtype; // 4
|
uint8_t dtype; // 4
|
||||||
u8 number;
|
uint8_t number;
|
||||||
u8 alternate;
|
uint8_t alternate;
|
||||||
u8 numEndpoints;
|
uint8_t numEndpoints;
|
||||||
u8 interfaceClass;
|
uint8_t interfaceClass;
|
||||||
u8 interfaceSubClass;
|
uint8_t interfaceSubClass;
|
||||||
u8 protocol;
|
uint8_t protocol;
|
||||||
u8 iInterface;
|
uint8_t iInterface;
|
||||||
} InterfaceDescriptor;
|
} InterfaceDescriptor;
|
||||||
|
|
||||||
// Endpoint
|
// Endpoint
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u8 len; // 7
|
uint8_t len; // 7
|
||||||
u8 dtype; // 5
|
uint8_t dtype; // 5
|
||||||
u8 addr;
|
uint8_t addr;
|
||||||
u8 attr;
|
uint8_t attr;
|
||||||
u16 packetSize;
|
uint16_t packetSize;
|
||||||
u8 interval;
|
uint8_t interval;
|
||||||
} EndpointDescriptor;
|
} EndpointDescriptor;
|
||||||
|
|
||||||
// Interface Association Descriptor
|
// Interface Association Descriptor
|
||||||
// Used to bind 2 interfaces together in CDC compostite device
|
// Used to bind 2 interfaces together in CDC compostite device
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u8 len; // 8
|
uint8_t len; // 8
|
||||||
u8 dtype; // 11
|
uint8_t dtype; // 11
|
||||||
u8 firstInterface;
|
uint8_t firstInterface;
|
||||||
u8 interfaceCount;
|
uint8_t interfaceCount;
|
||||||
u8 functionClass;
|
uint8_t functionClass;
|
||||||
u8 funtionSubClass;
|
uint8_t funtionSubClass;
|
||||||
u8 functionProtocol;
|
uint8_t functionProtocol;
|
||||||
u8 iInterface;
|
uint8_t iInterface;
|
||||||
} IADDescriptor;
|
} IADDescriptor;
|
||||||
|
|
||||||
// CDC CS interface descriptor
|
// CDC CS interface descriptor
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u8 len; // 5
|
uint8_t len; // 5
|
||||||
u8 dtype; // 0x24
|
uint8_t dtype; // 0x24
|
||||||
u8 subtype;
|
uint8_t subtype;
|
||||||
u8 d0;
|
uint8_t d0;
|
||||||
u8 d1;
|
uint8_t d1;
|
||||||
} CDCCSInterfaceDescriptor;
|
} CDCCSInterfaceDescriptor;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u8 len; // 4
|
uint8_t len; // 4
|
||||||
u8 dtype; // 0x24
|
uint8_t dtype; // 0x24
|
||||||
u8 subtype;
|
uint8_t subtype;
|
||||||
u8 d0;
|
uint8_t d0;
|
||||||
} CDCCSInterfaceDescriptor4;
|
} CDCCSInterfaceDescriptor4;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -204,15 +204,15 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u8 len; // 9
|
uint8_t len; // 9
|
||||||
u8 dtype; // 0x21
|
uint8_t dtype; // 0x21
|
||||||
u8 addr;
|
uint8_t addr;
|
||||||
u8 versionL; // 0x101
|
uint8_t versionL; // 0x101
|
||||||
u8 versionH; // 0x101
|
uint8_t versionH; // 0x101
|
||||||
u8 country;
|
uint8_t country;
|
||||||
u8 desctype; // 0x22 report
|
uint8_t desctype; // 0x22 report
|
||||||
u8 descLenL;
|
uint8_t descLenL;
|
||||||
u8 descLenH;
|
uint8_t descLenH;
|
||||||
} HIDDescDescriptor;
|
} HIDDescDescriptor;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
|
@ -22,17 +22,17 @@
|
||||||
//====================================================================================================
|
//====================================================================================================
|
||||||
// Actual device descriptors
|
// Actual device descriptors
|
||||||
|
|
||||||
const u16 STRING_LANGUAGE[2] = {
|
const uint16_t STRING_LANGUAGE[2] = {
|
||||||
(3<<8) | (2+2),
|
(3<<8) | (2+2),
|
||||||
0x0409 // English
|
0x0409 // English
|
||||||
};
|
};
|
||||||
|
|
||||||
const u16 STRING_SERIAL[13] = {
|
const uint16_t STRING_SERIAL[13] = {
|
||||||
(3<<8) | (2+2*12),
|
(3<<8) | (2+2*12),
|
||||||
USB_SERIAL_STRING
|
USB_SERIAL_STRING
|
||||||
};
|
};
|
||||||
|
|
||||||
const u16 STRING_IPRODUCT[28] = {
|
const uint16_t STRING_IPRODUCT[28] = {
|
||||||
(3<<8) | (2+2*27),
|
(3<<8) | (2+2*27),
|
||||||
#if USB_PID == USB_PID_LEONARDO
|
#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'
|
'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'
|
||||||
|
@ -41,7 +41,7 @@ const u16 STRING_IPRODUCT[28] = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
const u16 STRING_IMANUFACTURER[12] = {
|
const uint16_t STRING_IMANUFACTURER[12] = {
|
||||||
(3<<8) | (2+2*11),
|
(3<<8) | (2+2*11),
|
||||||
'A','r','d','u','i','n','o',' ','L','L','C'
|
'A','r','d','u','i','n','o',' ','L','L','C'
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,10 +47,10 @@ extern Config USB_ConfigDescriptor PROGMEM;
|
||||||
extern DeviceDescriptor USB_DeviceDescriptor PROGMEM;
|
extern DeviceDescriptor USB_DeviceDescriptor PROGMEM;
|
||||||
extern DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
|
extern DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
|
||||||
|
|
||||||
extern const u16 STRING_LANGUAGE[2] PROGMEM;
|
extern const uint16_t STRING_LANGUAGE[2] PROGMEM;
|
||||||
extern const u16 STRING_IPRODUCT[28] PROGMEM;
|
extern const uint16_t STRING_IPRODUCT[28] PROGMEM;
|
||||||
extern const u16 STRING_IMANUFACTURER[12] PROGMEM;
|
extern const uint16_t STRING_IMANUFACTURER[12] PROGMEM;
|
||||||
extern const u16 STRING_SERIAL[13] PROGMEM;
|
extern const uint16_t STRING_SERIAL[13] PROGMEM;
|
||||||
|
|
||||||
#define IMANUFACTURER 1
|
#define IMANUFACTURER 1
|
||||||
#define IPRODUCT 2
|
#define IPRODUCT 2
|
||||||
|
|
Loading…
Reference in New Issue