mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Changed HardwareSerial to call the C serial functions in wiring.h and wiring.c to save space.
This commit is contained in:
@ -15,14 +15,14 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Modified 23 November 2006 by David A. Mellis
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "Serial.h"
|
#include "wiring.h"
|
||||||
}
|
|
||||||
|
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
|
|
||||||
@ -30,44 +30,43 @@ extern "C" {
|
|||||||
|
|
||||||
HardwareSerial::HardwareSerial(uint8_t uart)
|
HardwareSerial::HardwareSerial(uint8_t uart)
|
||||||
{
|
{
|
||||||
if(uart == 0){
|
//if(uart == 0){
|
||||||
_uart = 0;
|
// _uart = 0;
|
||||||
}else{
|
//}else{
|
||||||
_uart = 1;
|
// _uart = 1;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public Methods //////////////////////////////////////////////////////////////
|
// Public Methods //////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void HardwareSerial::begin(long speed)
|
void HardwareSerial::begin(long speed)
|
||||||
{
|
{
|
||||||
uart_init(_uart, speed);
|
beginSerial(speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t HardwareSerial::available(void)
|
uint8_t HardwareSerial::available(void)
|
||||||
{
|
{
|
||||||
return uart_available(_uart);
|
return serialAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardwareSerial::read(void)
|
int HardwareSerial::read(void)
|
||||||
{
|
{
|
||||||
return uart_read(_uart);
|
return serialRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareSerial::print(char c)
|
void HardwareSerial::print(char c)
|
||||||
{
|
{
|
||||||
uart_write(_uart, &c, 1);
|
printByte(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareSerial::print(char c[])
|
void HardwareSerial::print(char c[])
|
||||||
{
|
{
|
||||||
uart_write(_uart, c, strlen(c));
|
printString(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareSerial::print(uint8_t b)
|
void HardwareSerial::print(uint8_t b)
|
||||||
{
|
{
|
||||||
char c = b;
|
printByte(b);
|
||||||
uart_write(_uart, &c, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareSerial::print(int n)
|
void HardwareSerial::print(int n)
|
||||||
@ -75,6 +74,11 @@ void HardwareSerial::print(int n)
|
|||||||
print((long) n);
|
print((long) n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HardwareSerial::print(unsigned int n)
|
||||||
|
{
|
||||||
|
print((unsigned long) n);
|
||||||
|
}
|
||||||
|
|
||||||
void HardwareSerial::print(long n)
|
void HardwareSerial::print(long n)
|
||||||
{
|
{
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
@ -113,7 +117,7 @@ void HardwareSerial::println(char c)
|
|||||||
|
|
||||||
void HardwareSerial::println(char c[])
|
void HardwareSerial::println(char c[])
|
||||||
{
|
{
|
||||||
uart_write(_uart, c, strlen(c));
|
print(c);
|
||||||
println();
|
println();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +129,8 @@ void HardwareSerial::println(uint8_t b)
|
|||||||
|
|
||||||
void HardwareSerial::println(int n)
|
void HardwareSerial::println(int n)
|
||||||
{
|
{
|
||||||
println((long) n);
|
print(n);
|
||||||
|
println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareSerial::println(long n)
|
void HardwareSerial::println(long n)
|
||||||
@ -150,19 +155,7 @@ void HardwareSerial::println(long n, int base)
|
|||||||
|
|
||||||
void HardwareSerial::printNumber(unsigned long n, uint8_t base)
|
void HardwareSerial::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
uint8_t buf[8 * sizeof(long)]; // Assumes 8-bit chars.
|
printIntegerInBase(n, base);
|
||||||
int i = 0;
|
|
||||||
if (n == 0) {
|
|
||||||
print('0');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (n > 0) {
|
|
||||||
buf[i++] = n % base;
|
|
||||||
n /= base;
|
|
||||||
}
|
|
||||||
for (i--; i >= 0; i--){
|
|
||||||
print((char)(buf[i] < 10 ? '0' + buf[i] : 'A' + buf[i] - 10));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preinstantiate Objects //////////////////////////////////////////////////////
|
// Preinstantiate Objects //////////////////////////////////////////////////////
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
class HardwareSerial
|
class HardwareSerial
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
uint8_t _uart;
|
//uint8_t _uart;
|
||||||
void printNumber(unsigned long, uint8_t);
|
void printNumber(unsigned long, uint8_t);
|
||||||
public:
|
public:
|
||||||
HardwareSerial(uint8_t);
|
HardwareSerial(uint8_t);
|
||||||
@ -42,6 +42,7 @@ class HardwareSerial
|
|||||||
void print(char[]);
|
void print(char[]);
|
||||||
void print(uint8_t);
|
void print(uint8_t);
|
||||||
void print(int);
|
void print(int);
|
||||||
|
void print(unsigned int);
|
||||||
void print(long);
|
void print(long);
|
||||||
void print(unsigned long);
|
void print(unsigned long);
|
||||||
void print(long, int);
|
void print(long, int);
|
||||||
|
@ -77,6 +77,7 @@ void printInteger(long n);
|
|||||||
void printHex(unsigned long n);
|
void printHex(unsigned long n);
|
||||||
void printOctal(unsigned long n);
|
void printOctal(unsigned long n);
|
||||||
void printBinary(unsigned long n);
|
void printBinary(unsigned long n);
|
||||||
|
void printIntegerInBase(unsigned long n, unsigned long base);
|
||||||
|
|
||||||
unsigned long millis(void);
|
unsigned long millis(void);
|
||||||
void delay(unsigned long);
|
void delay(unsigned long);
|
||||||
|
Reference in New Issue
Block a user