modify to nucleo stm32F411
Dependencies: RingBuffer
Dependents: MX_control Program_BEAR_Protocol SwitchMode BEAR_Motion ... more
Fork of iSerial by
Diff: iSerial.cpp
- Revision:
- 4:b38ef9675d39
- Parent:
- 3:d5353b68105f
- Child:
- 5:d83fc550ccbc
--- a/iSerial.cpp Sat Sep 01 12:28:28 2012 +0000 +++ b/iSerial.cpp Mon Sep 03 09:15:34 2012 +0000 @@ -4,11 +4,27 @@ // 2009.11.13 ... Originally written by Y.Kuroda for Renesas H83664 // 2012.08.31 ... Code convert for mbed in C++ // +#include <stdarg.h> #include "mbed.h" #include "RingBuffer.h" #include "iSerial.h" + +#if defined(TARGET_LPC1768) + +// UART1 = p9, p10 + + #define UART_IRQn UART2_IRQn + +#elif defined(TARGET_LPC11U24) + + #define UART_IRQn UART_IRQn + +#endif + + + /* * Interrupt Function */ @@ -33,19 +49,13 @@ NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn); } -/* - * void sci_init(void) - * - *@|[gú»ÖDDDD·×ÄÌI/OÌÝèðsÁÄ¢éD - * - *@@øFȵ - *@@ßèlFȵ - * - */ iSerial::iSerial(PinName _tx, PinName _rx, const char *_name, int _txbufsize, int _rxbufsize) : Serial(_tx, _rx, _name), - txbuf(RingBuffer(_txbufsize)), - rxbuf(RingBuffer(_rxbufsize)) + txbufsize(_txbufsize), + rxbufsize(_rxbufsize), + txbuf(RingBuffer(txbufsize)), + rxbuf(RingBuffer(rxbufsize)), + str(new char [txbufsize]) { __disable_irq(); @@ -59,20 +69,17 @@ NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn); } -/* - * VAüÍɶª é©Ç¤©`FbN - * ÔlF obt@É é¶ - */ +iSerial::~iSerial() +{ + delete [] str; +} + int iSerial::readable(void) { return rxbuf.check(); } -/* - * VA©çê¶üÍ - * --- ¶üÍðÒ - */ int iSerial::getc(void) { @@ -84,10 +91,6 @@ return c; } - -/* - *@VAÖê¶oÍ - */ void iSerial::putc(short ch) { @@ -101,14 +104,6 @@ } } -/* - *@VAÖ¶ñðoÍ - *@@FêñÌÅå¶ÍLINESIZE - *@@F¶ñÌIíèÉÍk¶ªKvD - * - *@@øF¶ñÖÌ|C^ - *@@ÔlFo͵½¶ - */ short int iSerial::putstr(const char* s) { @@ -120,13 +115,6 @@ return i; } -/*@short int sci_puts(char* s) - *@VAÖ¶ñðêsoÍ - *@@FÅãÉüsR[hðé¼Ísci_putstrƯ¶ - * - *@@øF¶ñÖÌ|C^ - *@@ÔlFo͵½¶ - */ short int iSerial::puts(const char* s) { @@ -136,3 +124,17 @@ return n; } +char* +iSerial::printf(const char* format, ...) +{ + va_list arg; + va_start(arg,format); + vsprintf(str, format, arg); + va_end(arg); + putstr(str); + return str; +} + + + +