Skip to content

Commit ca222ce

Browse files
giulcioffifacchinm
authored andcommitted
Port USB to API
Move CDC and MSC classes to own files. Fix all u8/u32 entries to stantard types.
1 parent 41794fa commit ca222ce

File tree

10 files changed

+357
-589
lines changed

10 files changed

+357
-589
lines changed

cores/arduino/CDC.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
/* Copyright (c) 2011, Peter Barrett
42
**
53
** Permission to use, copy, modify, and/or distribute this software for
@@ -16,25 +14,31 @@
1614
** SOFTWARE.
1715
*/
1816

19-
#include "USBAPI.h"
17+
#define RINGBUFFER_FORCE_SMALL_SIZE
18+
2019
#include <avr/wdt.h>
2120
#include <util/atomic.h>
21+
#include <avr/pgmspace.h>
22+
#include "CDC.h"
23+
#include "api/USBAPI.h"
24+
#include "USBCore.h"
25+
#include "api/Common.h"
2226

2327
#if defined(USBCON)
2428

2529
typedef struct
2630
{
27-
u32 dwDTERate;
28-
u8 bCharFormat;
29-
u8 bParityType;
30-
u8 bDataBits;
31-
u8 lineState;
31+
uint32_t dwDTERate;
32+
uint8_t bCharFormat;
33+
uint8_t bParityType;
34+
uint8_t bDataBits;
35+
uint8_t lineState;
3236
} LineInfo;
3337

3438
static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
3539
static volatile int32_t breakValue = -1;
3640

37-
static u8 wdtcsr_save;
41+
static uint8_t wdtcsr_save;
3842

3943
#define WEAK __attribute__ ((weak))
4044

@@ -62,16 +66,16 @@ bool isLUFAbootloader()
6266
return pgm_read_word(FLASHEND - 1) == NEW_LUFA_SIGNATURE;
6367
}
6468

65-
int CDC_GetInterface(u8* interfaceNum)
69+
int CDC_GetInterface(uint8_t* interfaceNum)
6670
{
6771
interfaceNum[0] += 2; // uses 2
6872
return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface));
6973
}
7074

7175
bool CDC_Setup(USBSetup& setup)
7276
{
73-
u8 r = setup.bRequest;
74-
u8 requestType = setup.bmRequestType;
77+
uint8_t r = setup.bRequest;
78+
uint8_t requestType = setup.bmRequestType;
7579

7680
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
7781
{

cores/arduino/CDC.h

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#ifndef __CDC_H__
2+
#define __CDC_H__
3+
4+
#include "Arduino.h"
5+
#include "api/Stream.h"
6+
#include "api/USBAPI.h"
7+
8+
#if defined (USBCON)
9+
10+
//================================================================================
11+
//================================================================================
12+
// Serial over CDC (Serial1 is the physical port)
13+
14+
#define RINGBUFFER_FORCE_SMALL_SIZE
15+
#include "api/RingBuffer.h"
16+
17+
#ifndef SERIAL_BUFFER_SIZE
18+
#if ((RAMEND - RAMSTART) < 1023)
19+
#define SERIAL_BUFFER_SIZE 16
20+
#else
21+
#define SERIAL_BUFFER_SIZE 64
22+
#endif
23+
#endif
24+
#if (SERIAL_BUFFER_SIZE > 256)
25+
#error Please lower the CDC Buffer size
26+
#endif
27+
28+
class Serial_ : public Stream
29+
{
30+
private:
31+
int peek_buffer;
32+
public:
33+
Serial_() { peek_buffer = -1; };
34+
void begin(unsigned long);
35+
void begin(unsigned long, uint8_t);
36+
void end(void);
37+
38+
virtual int available(void);
39+
virtual int peek(void);
40+
virtual int read(void);
41+
virtual int availableForWrite(void);
42+
virtual void flush(void);
43+
virtual size_t write(uint8_t);
44+
virtual size_t write(const uint8_t*, size_t);
45+
using Print::write; // pull in write(str) and write(buf, size) from Print
46+
operator bool();
47+
48+
//RingBuffer _rx_buffer(SERIAL_BUFFER_SIZE);
49+
50+
// This method allows processing "SEND_BREAK" requests sent by
51+
// the USB host. Those requests indicate that the host wants to
52+
// send a BREAK signal and are accompanied by a single uint16_t
53+
// value, specifying the duration of the break. The value 0
54+
// means to end any current break, while the value 0xffff means
55+
// to start an indefinite break.
56+
// readBreak() will return the value of the most recent break
57+
// request, but will return it at most once, returning -1 when
58+
// readBreak() is called again (until another break request is
59+
// received, which is again returned once).
60+
// This also mean that if two break requests are received
61+
// without readBreak() being called in between, the value of the
62+
// first request is lost.
63+
// Note that the value returned is a long, so it can return
64+
// 0-0xffff as well as -1.
65+
int32_t readBreak();
66+
67+
// These return the settings specified by the USB host for the
68+
// serial port. These aren't really used, but are offered here
69+
// in case a sketch wants to act on these settings.
70+
uint32_t baud();
71+
uint8_t stopbits();
72+
uint8_t paritytype();
73+
uint8_t numbits();
74+
bool dtr();
75+
bool rts();
76+
enum {
77+
ONE_STOP_BIT = 0,
78+
ONE_AND_HALF_STOP_BIT = 1,
79+
TWO_STOP_BITS = 2,
80+
};
81+
enum {
82+
NO_PARITY = 0,
83+
ODD_PARITY = 1,
84+
EVEN_PARITY = 2,
85+
MARK_PARITY = 3,
86+
SPACE_PARITY = 4,
87+
};
88+
89+
};
90+
extern Serial_ Serial;
91+
92+
#define HAVE_CDCSERIAL
93+
94+
//================================================================================
95+
//================================================================================
96+
// CSC 'Driver'
97+
98+
int CDC_GetInterface(uint8_t* interfaceNum);
99+
int CDC_GetDescriptor(int i);
100+
bool CDC_Setup(USBSetup& setup);
101+
102+
#endif
103+
104+
#endif

cores/arduino/MSC.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#if defined (USBCON)
2+
3+
#ifndef __MSC_H__
4+
#define __MSC_H__
5+
6+
#include "api/USBAPI.h"
7+
8+
//================================================================================
9+
//================================================================================
10+
// MSC 'Driver'
11+
12+
int MSC_GetInterface(uint8_t* interfaceNum);
13+
int MSC_GetDescriptor(int i);
14+
bool MSC_Setup(USBSetup& setup);
15+
bool MSC_Data(uint8_t rx,uint8_t tx);
16+
17+
#endif
18+
19+
#endif

cores/arduino/PluggableUSB.cpp

Lines changed: 0 additions & 115 deletions
This file was deleted.

cores/arduino/PluggableUSB.h

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)