-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Modification of ArduinoCore-avr to use API #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8ac2905
41794fa
ca222ce
a6006d1
dd6c2c9
40c3734
e908c9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#ifndef __CDC_H__ | ||
#define __CDC_H__ | ||
|
||
#include "Arduino.h" | ||
#include "api/Stream.h" | ||
#include "api/USBAPI.h" | ||
|
||
#if defined (USBCON) | ||
|
||
//================================================================================ | ||
//================================================================================ | ||
// Serial over CDC (Serial1 is the physical port) | ||
|
||
#define RINGBUFFER_FORCE_SMALL_SIZE | ||
#include "api/RingBuffer.h" | ||
|
||
#ifndef SERIAL_BUFFER_SIZE | ||
#if ((RAMEND - RAMSTART) < 1023) | ||
#define SERIAL_BUFFER_SIZE 16 | ||
#else | ||
#define SERIAL_BUFFER_SIZE 64 | ||
#endif | ||
#endif | ||
#if (SERIAL_BUFFER_SIZE > 256) | ||
#error Please lower the CDC Buffer size | ||
#endif | ||
|
||
class Serial_ : public Stream | ||
{ | ||
private: | ||
int peek_buffer; | ||
public: | ||
Serial_() { peek_buffer = -1; }; | ||
void begin(unsigned long); | ||
void begin(unsigned long, uint8_t); | ||
void end(void); | ||
|
||
virtual int available(void); | ||
virtual int peek(void); | ||
virtual int read(void); | ||
virtual int availableForWrite(void); | ||
virtual void flush(void); | ||
virtual size_t write(uint8_t); | ||
virtual size_t write(const uint8_t*, size_t); | ||
using Print::write; // pull in write(str) and write(buf, size) from Print | ||
operator bool(); | ||
|
||
//RingBuffer _rx_buffer(SERIAL_BUFFER_SIZE); | ||
|
||
// This method allows processing "SEND_BREAK" requests sent by | ||
// the USB host. Those requests indicate that the host wants to | ||
// send a BREAK signal and are accompanied by a single uint16_t | ||
// value, specifying the duration of the break. The value 0 | ||
// means to end any current break, while the value 0xffff means | ||
// to start an indefinite break. | ||
// readBreak() will return the value of the most recent break | ||
// request, but will return it at most once, returning -1 when | ||
// readBreak() is called again (until another break request is | ||
// received, which is again returned once). | ||
// This also mean that if two break requests are received | ||
// without readBreak() being called in between, the value of the | ||
// first request is lost. | ||
// Note that the value returned is a long, so it can return | ||
// 0-0xffff as well as -1. | ||
int32_t readBreak(); | ||
|
||
// These return the settings specified by the USB host for the | ||
// serial port. These aren't really used, but are offered here | ||
// in case a sketch wants to act on these settings. | ||
uint32_t baud(); | ||
uint8_t stopbits(); | ||
uint8_t paritytype(); | ||
uint8_t numbits(); | ||
bool dtr(); | ||
bool rts(); | ||
enum { | ||
ONE_STOP_BIT = 0, | ||
ONE_AND_HALF_STOP_BIT = 1, | ||
TWO_STOP_BITS = 2, | ||
}; | ||
enum { | ||
NO_PARITY = 0, | ||
ODD_PARITY = 1, | ||
EVEN_PARITY = 2, | ||
MARK_PARITY = 3, | ||
SPACE_PARITY = 4, | ||
}; | ||
|
||
}; | ||
extern Serial_ Serial; | ||
|
||
#define HAVE_CDCSERIAL | ||
|
||
//================================================================================ | ||
//================================================================================ | ||
// CSC 'Driver' | ||
|
||
int CDC_GetInterface(uint8_t* interfaceNum); | ||
int CDC_GetDescriptor(int i); | ||
bool CDC_Setup(USBSetup& setup); | ||
|
||
#endif | ||
|
||
#endif |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#if defined (USBCON) | ||
|
||
#ifndef __MSC_H__ | ||
#define __MSC_H__ | ||
|
||
#include "api/USBAPI.h" | ||
|
||
//================================================================================ | ||
//================================================================================ | ||
// MSC 'Driver' | ||
|
||
int MSC_GetInterface(uint8_t* interfaceNum); | ||
int MSC_GetDescriptor(int i); | ||
bool MSC_Setup(USBSetup& setup); | ||
bool MSC_Data(uint8_t rx,uint8_t tx); | ||
|
||
#endif | ||
|
||
#endif |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
HardwareSerial.h - Hardware serial library for Wiring | ||
UART.h - Hardware serial library for Wiring | ||
Copyright (c) 2006 Nicholas Zambetti. All right reserved. | ||
This library is free software; you can redistribute it and/or | ||
|
@@ -21,12 +21,16 @@ | |
Modified 3 December 2013 by Matthijs Kooijman | ||
*/ | ||
|
||
#ifndef HardwareSerial_h | ||
#define HardwareSerial_h | ||
#ifndef _UART_H_ | ||
#define _UART_H_ | ||
|
||
#include "Arduino.h" | ||
#include <inttypes.h> | ||
#include "api/HardwareSerial.h" | ||
|
||
#include "Stream.h" | ||
#if ARDUINO_API_VERSION > 10000 | ||
using namespace arduino; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment to explain why this |
||
#endif | ||
|
||
// Define constants and variables for buffering incoming serial data. We're | ||
// using a ring buffer (I think), in which head is the index of the location | ||
|
@@ -65,6 +69,31 @@ typedef uint8_t rx_buffer_index_t; | |
#endif | ||
|
||
// Define config for Serial.begin(baud, config); | ||
#undef SERIAL_5N1 | ||
#undef SERIAL_6N1 | ||
#undef SERIAL_7N1 | ||
#undef SERIAL_8N1 | ||
#undef SERIAL_5N2 | ||
#undef SERIAL_6N2 | ||
#undef SERIAL_7N2 | ||
#undef SERIAL_8N2 | ||
#undef SERIAL_5E1 | ||
#undef SERIAL_6E1 | ||
#undef SERIAL_7E1 | ||
#undef SERIAL_8E1 | ||
#undef SERIAL_5E2 | ||
#undef SERIAL_6E2 | ||
#undef SERIAL_7E2 | ||
#undef SERIAL_8E2 | ||
#undef SERIAL_5O1 | ||
#undef SERIAL_6O1 | ||
#undef SERIAL_7O1 | ||
#undef SERIAL_8O1 | ||
#undef SERIAL_5O2 | ||
#undef SERIAL_6O2 | ||
#undef SERIAL_7O2 | ||
#undef SERIAL_8O2 | ||
|
||
#define SERIAL_5N1 0x00 | ||
#define SERIAL_6N1 0x02 | ||
#define SERIAL_7N1 0x04 | ||
|
@@ -90,7 +119,7 @@ typedef uint8_t rx_buffer_index_t; | |
#define SERIAL_7O2 0x3C | ||
#define SERIAL_8O2 0x3E | ||
|
||
class HardwareSerial : public Stream | ||
class UartClass : public HardwareSerial | ||
{ | ||
protected: | ||
volatile uint8_t * const _ubrrh; | ||
|
@@ -114,12 +143,12 @@ class HardwareSerial : public Stream | |
unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE]; | ||
|
||
public: | ||
inline HardwareSerial( | ||
inline UartClass( | ||
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, | ||
volatile uint8_t *ucsra, volatile uint8_t *ucsrb, | ||
volatile uint8_t *ucsrc, volatile uint8_t *udr); | ||
void begin(unsigned long baud) { begin(baud, SERIAL_8N1); } | ||
void begin(unsigned long, uint8_t); | ||
void begin(unsigned long, uint16_t); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above, it's not clear why this was changed to a |
||
void end(); | ||
virtual int available(void); | ||
virtual int peek(void); | ||
|
@@ -140,22 +169,20 @@ class HardwareSerial : public Stream | |
}; | ||
|
||
#if defined(UBRRH) || defined(UBRR0H) | ||
extern HardwareSerial Serial; | ||
extern UartClass Serial; | ||
#define HAVE_HWSERIAL0 | ||
#endif | ||
#if defined(UBRR1H) | ||
extern HardwareSerial Serial1; | ||
extern UartClass Serial1; | ||
#define HAVE_HWSERIAL1 | ||
#endif | ||
#if defined(UBRR2H) | ||
extern HardwareSerial Serial2; | ||
extern UartClass Serial2; | ||
#define HAVE_HWSERIAL2 | ||
#endif | ||
#if defined(UBRR3H) | ||
extern HardwareSerial Serial3; | ||
extern UartClass Serial3; | ||
#define HAVE_HWSERIAL3 | ||
#endif | ||
|
||
extern void serialEventRun(void) __attribute__((weak)); | ||
|
||
#endif |
This file was deleted.
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
config
is later assigned to a*_ucsrc
which is declared as auint8_t
in UART.h. Was this change intentional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is due to https://github.com/arduino/ArduinoCore-API/blob/master/api/HardwareSerial.h#L91 , so the signature must be
uint16_t
.Said that, I'll push a commit to fix this by casting the assignment
*_ucsrc = (uint8_t)config;
(since we are assured that config fits an uint8_t)