21 #include <util/atomic.h> 34 static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
35 static volatile int32_t breakValue = -1;
37 bool _updatedLUFAbootloader =
false;
39 #define WEAK __attribute__ ((weak)) 60 int CDC_GetInterface(
u8* interfaceNum)
63 return USB_SendControl(TRANSFER_PGM,&_cdcInterface,
sizeof(_cdcInterface));
66 bool CDC_Setup(USBSetup&
setup)
68 u8 r = setup.bRequest;
69 u8 requestType = setup.bmRequestType;
75 USB_SendControl(0,(
void*)&_usbLineInfo,7);
84 breakValue = ((uint16_t)setup.wValueH << 8) | setup.wValueL;
89 USB_RecvControl((
void*)&_usbLineInfo,7);
94 _usbLineInfo.lineState = setup.wValueL;
109 #if MAGIC_KEY_POS != (RAMEND-1) 112 if (_updatedLUFAbootloader) {
114 magic_key_pos = (RAMEND-1);
119 if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
121 #if MAGIC_KEY_POS != (RAMEND-1) 124 if (magic_key_pos != (RAMEND-1)) {
125 *(uint16_t *)(RAMEND-1) = *(uint16_t *)magic_key_pos;
130 wdt_enable(WDTO_120MS);
141 #if MAGIC_KEY_POS != (RAMEND-1) 143 if (magic_key_pos != (RAMEND-1)) {
144 *(uint16_t *)magic_key_pos = *(uint16_t *)(RAMEND-1);
149 *(uint16_t *)magic_key_pos = 0x0000;
159 void Serial_::begin(
unsigned long )
164 void Serial_::begin(
unsigned long ,
byte )
169 void Serial_::end(
void)
173 int Serial_::available(
void)
175 if (peek_buffer >= 0) {
176 return 1 + USB_Available(
CDC_RX);
178 return USB_Available(
CDC_RX);
181 int Serial_::peek(
void)
184 peek_buffer = USB_Recv(
CDC_RX);
188 int Serial_::read(
void)
190 if (peek_buffer >= 0) {
198 int Serial_::availableForWrite(
void)
200 return USB_SendSpace(
CDC_TX);
203 void Serial_::flush(
void)
208 size_t Serial_::write(uint8_t
c)
213 size_t Serial_::write(
const uint8_t *
buffer,
size_t size)
224 if (_usbLineInfo.lineState > 0) {
225 int r = USB_Send(
CDC_TX,buffer,size);
244 Serial_::operator bool() {
246 if (_usbLineInfo.lineState > 0)
252 unsigned long Serial_::baud() {
255 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
256 baudrate = _usbLineInfo.dwDTERate;
261 uint8_t Serial_::stopbits() {
262 return _usbLineInfo.bCharFormat;
265 uint8_t Serial_::paritytype() {
266 return _usbLineInfo.bParityType;
269 uint8_t Serial_::numbits() {
270 return _usbLineInfo.bDataBits;
273 bool Serial_::dtr() {
274 return _usbLineInfo.lineState & 0x1;
277 bool Serial_::rts() {
278 return _usbLineInfo.lineState & 0x2;
285 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
#define CDC_CALL_MANAGEMENT
#define CDC_GET_LINE_CODING
#define D_CDCCS4(_subtype, _d0)
#define CDC_ABSTRACT_CONTROL_MANAGEMENT
#define USB_ENDPOINT_TYPE_BULK
#define CDC_DATA_INTERFACE_CLASS
#define CDC_ACM_INTERFACE
#define D_ENDPOINT(_addr, _attr, _packetSize, _interval)
#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE
#define CDC_SET_LINE_CODING
#define CDC_ABSTRACT_CONTROL_MODEL
void delay(unsigned long)
#define CDC_COMMUNICATION_INTERFACE_CLASS
#define CDC_DATA_INTERFACE
#define D_CDCCS(_subtype, _d0, _d1)
#define REQUEST_DEVICETOHOST_CLASS_INTERFACE
#define CDC_SET_CONTROL_LINE_STATE
GLdouble GLdouble GLdouble r
#define USB_ENDPOINT_TYPE_INTERRUPT
#define D_IAD(_firstInterface, _count, _class, _subClass, _protocol)
#define USB_ENDPOINT_OUT(addr)
#define D_INTERFACE(_n, _numEndpoints, _class, _subClass, _protocol)
#define USB_ENDPOINT_IN(addr)