2017-08-22 09:30:33 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HARDWARE_SERIAL_H_
|
|
|
|
#define HARDWARE_SERIAL_H_
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <Stream.h>
|
|
|
|
|
|
|
|
extern "C" {
|
2017-10-24 17:28:33 -05:00
|
|
|
#include <lpc17xx_uart.h>
|
|
|
|
#include "lpc17xx_pinsel.h"
|
2017-08-22 09:30:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class HardwareSerial : public Stream {
|
|
|
|
private:
|
2017-10-24 17:28:33 -05:00
|
|
|
LPC_UART_TypeDef *UARTx;
|
|
|
|
|
|
|
|
uint32_t Status;
|
|
|
|
uint8_t RxBuffer[RX_BUFFER_SIZE];
|
|
|
|
uint32_t RxQueueWritePos;
|
|
|
|
uint32_t RxQueueReadPos;
|
|
|
|
#if TX_BUFFER_SIZE > 0
|
|
|
|
uint8_t TxBuffer[TX_BUFFER_SIZE];
|
|
|
|
uint32_t TxQueueWritePos;
|
|
|
|
uint32_t TxQueueReadPos;
|
|
|
|
#endif
|
2017-08-22 09:30:33 -05:00
|
|
|
|
|
|
|
public:
|
2017-10-24 17:28:33 -05:00
|
|
|
HardwareSerial(LPC_UART_TypeDef *UARTx)
|
|
|
|
: UARTx(UARTx)
|
|
|
|
, RxQueueWritePos(0)
|
|
|
|
, RxQueueReadPos(0)
|
|
|
|
#if TX_BUFFER_SIZE > 0
|
|
|
|
, TxQueueWritePos(0)
|
|
|
|
, TxQueueReadPos(0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
}
|
2017-08-22 09:30:33 -05:00
|
|
|
|
|
|
|
void begin(uint32_t baudrate);
|
2017-10-24 17:28:33 -05:00
|
|
|
int peek();
|
2017-08-22 09:30:33 -05:00
|
|
|
int read();
|
|
|
|
size_t write(uint8_t send);
|
2017-10-24 17:28:33 -05:00
|
|
|
#if TX_BUFFER_SIZE > 0
|
|
|
|
void flushTX();
|
|
|
|
#endif
|
2017-08-22 09:30:33 -05:00
|
|
|
int available();
|
|
|
|
void flush();
|
|
|
|
void printf(const char *format, ...);
|
|
|
|
|
2017-09-27 04:57:33 -05:00
|
|
|
operator bool() { return true; }
|
|
|
|
|
2017-10-24 17:28:33 -05:00
|
|
|
void IRQHandler();
|
|
|
|
|
2017-09-27 04:57:33 -05:00
|
|
|
void print(const char value[]) { printf("%s" , value); }
|
|
|
|
void print(char value, int = 0) { printf("%c" , value); }
|
|
|
|
void print(unsigned char value, int = 0) { printf("%u" , value); }
|
|
|
|
void print(int value, int = 0) { printf("%d" , value); }
|
|
|
|
void print(unsigned int value, int = 0) { printf("%u" , value); }
|
|
|
|
void print(long value, int = 0) { printf("%ld" , value); }
|
|
|
|
void print(unsigned long value, int = 0) { printf("%lu" , value); }
|
|
|
|
|
|
|
|
void print(float value, int round = 6) { printf("%f" , value); }
|
|
|
|
void print(double value, int round = 6) { printf("%f" , value ); }
|
|
|
|
|
|
|
|
void println(const char value[]) { printf("%s\n" , value); }
|
|
|
|
void println(char value, int = 0) { printf("%c\n" , value); }
|
|
|
|
void println(unsigned char value, int = 0) { printf("%u\r\n" , value); }
|
|
|
|
void println(int value, int = 0) { printf("%d\n" , value); }
|
|
|
|
void println(unsigned int value, int = 0) { printf("%u\n" , value); }
|
|
|
|
void println(long value, int = 0) { printf("%ld\n" , value); }
|
|
|
|
void println(unsigned long value, int = 0) { printf("%lu\n" , value); }
|
|
|
|
void println(float value, int round = 6) { printf("%f\n" , value ); }
|
|
|
|
void println(double value, int round = 6) { printf("%f\n" , value ); }
|
|
|
|
void println(void) { print('\n'); }
|
2017-08-22 09:30:33 -05:00
|
|
|
|
|
|
|
};
|
2017-09-27 04:57:33 -05:00
|
|
|
|
2017-10-24 17:28:33 -05:00
|
|
|
extern HardwareSerial Serial;
|
|
|
|
extern HardwareSerial Serial1;
|
|
|
|
extern HardwareSerial Serial2;
|
2017-08-22 09:30:33 -05:00
|
|
|
extern HardwareSerial Serial3;
|
|
|
|
|
2017-09-27 04:57:33 -05:00
|
|
|
#endif // MARLIN_SRC_HAL_HAL_SERIAL_H_
|