This commit is contained in:
hathach committed 2018-08-24 00:31:42 +07:00
1 parent f91c42b3ec
commit 043aa57f43
3 files changed
+4 -100

No files matched your search

-49
View File
@@ -224,7 +224,6 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
return write(str);
}
#if 1
size_t Print::printFloat(double number, uint8_t digits)
{
char buf[256];
@@ -238,54 +237,6 @@ size_t Print::printFloat(double number, uint8_t digits)
return s;
}
#else
size_t Print::printFloat(double number, uint8_t digits)
{
size_t n = 0;
if (isnan(number)) return print("nan");
if (isinf(number)) return print("inf");
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
// Handle negative numbers
if (number < 0.0)
{
n += print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
n += print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
n += print(".");
}
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
n += print(toPrint);
remainder -= toPrint;
}
return n;
}
#endif
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
+2 -51
View File
@@ -80,7 +80,6 @@ void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
uint32_t nrfBaudRate;
#if defined(NRF52) || defined(NRF52_SERIES)
if (baudrate <= 1200) {
nrfBaudRate = UARTE_BAUDRATE_BAUDRATE_Baud1200;
} else if (baudrate <= 2400) {
@@ -114,41 +113,6 @@ void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
} else {
nrfBaudRate = UARTE_BAUDRATE_BAUDRATE_Baud1M;
}
#else
if (baudrate <= 1200) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud1200;
} else if (baudrate <= 2400) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud2400;
} else if (baudrate <= 4800) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud4800;
} else if (baudrate <= 9600) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud9600;
} else if (baudrate <= 14400) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud14400;
} else if (baudrate <= 19200) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud19200;
} else if (baudrate <= 28800) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud28800;
} else if (baudrate <= 38400) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud38400;
} else if (baudrate <= 57600) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud57600;
} else if (baudrate <= 76800) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud76800;
} else if (baudrate <= 115200) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud115200;
} else if (baudrate <= 230400) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud230400;
} else if (baudrate <= 250000) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud250000;
} else if (baudrate <= 460800) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud460800;
} else if (baudrate <= 921600) {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud921600;
} else {
nrfBaudRate = UART_BAUDRATE_BAUDRATE_Baud1M;
}
#endif
nrfUart->BAUDRATE = nrfBaudRate;
@@ -235,11 +199,8 @@ size_t Uart::write(const uint8_t data)
return 1;
}
#if defined(NRF52) || defined(NRF52_SERIES)
#define NRF_UART0_IRQn UARTE0_UART0_IRQn
#elif defined(NRF51)
#define NRF_UART0_IRQn UART0_IRQn
#endif
#define NRF_UART0_IRQn UARTE0_UART0_IRQn
#if defined(PIN_SERIAL_CTS) && defined(PIN_SERIAL_RTS)
Uart Serial( NRF_UART0, NRF_UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX, PIN_SERIAL_CTS, PIN_SERIAL_RTS );
@@ -247,7 +208,6 @@ size_t Uart::write(const uint8_t data)
Uart Serial( NRF_UART0, NRF_UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX );
#endif
#if defined(NRF52) || defined(NRF52_SERIES)
extern "C"
{
void UARTE0_UART0_IRQHandler()
@@ -255,12 +215,3 @@ extern "C"
Serial.IrqHandler();
}
}
#elif defined(NRF51)
extern "C"
{
void UART0_IRQHandler()
{
Serial.IrqHandler();
}
}
#endif
+2
View File
@@ -39,5 +39,7 @@ void initVariant()
pinMode(PIN_LED2, OUTPUT);
ledOff(PIN_LED2);
// USB init TODO may have trouble with ISR when SD is enabled
}