Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of football_project by
Diff: io/MySerial.cpp
- Revision:
- 2:fe1566cdb6e7
- Parent:
- 1:0ba687d4196f
- Child:
- 4:17b8edf264c3
--- a/io/MySerial.cpp Mon Apr 13 12:23:44 2015 +0000
+++ b/io/MySerial.cpp Mon Apr 13 14:02:48 2015 +0000
@@ -23,13 +23,11 @@
using namespace moo;
-void my_serial_init( serial_t *obj, PinName tx, PinName rx, PinName rts, PinName cts );
-
MySerialBase::MySerialBase( PinName tx, PinName rx,
PinName rts, PinName cts ) : _my_serial(), _my_baud( 9600 )
{
-// my_serial_init( &_my_serial, tx, rx, rts, cts );
+ my_serial_init( &_my_serial, tx, rx, rts, cts, _my_baud );
serial_irq_handler( &_my_serial, _irq_handler, (uint32_t)this );
}
void MySerialBase::baud( int baudrate )
@@ -60,6 +58,66 @@
serial_irq_set( &_my_serial, (SerialIrq)type, 0 );
}
}
+void MySerialBase::my_serial_init( serial_t *obj, PinName tx, PinName rx, PinName rts, PinName cts, int baudrate )
+{
+ UARTName uart = UART_0;
+ obj->uart = (NRF_UART_Type *)uart;
+
+ // pin configurations --
+ NRF_GPIO->DIR |= (1 << tx); // TX_PIN_NUMBER
+ NRF_GPIO->DIR |= ((NC == rts) ? 0 : (1 << rts)); // RTS_PIN_NUMBER
+
+ NRF_GPIO->DIR &= ~(1 << rx); // RX_PIN_NUMBER
+ NRF_GPIO->DIR &= ~((NC == cts) ? 0 : (1 << cts)); // CTS_PIN_NUMBER
+
+ obj->uart->PSELRTS = ((NC == rts) ? 0xFFFFFFFF : rts); // RTS_PIN_NUMBER
+ obj->uart->PSELTXD = tx; // TX_PIN_NUMBER
+ obj->uart->PSELCTS = ((NC == cts) ? 0xFFFFFFFF : cts); // CTS_PIN_NUMBER
+ obj->uart->PSELRXD = rx; // RX_PIN_NUMBER
+
+ if( (NC != rts) || (NC != cts) )
+ {
+ obj->uart->CONFIG |= 0x01; // Enable HWFC
+
+ } else
+ {
+ obj->uart->CONFIG &= ~0x01; // Disable HWFC;
+ }
+
+ // set default baud rate and format
+ serial_baud ( obj, baudrate );
+ serial_format( obj, 8, ParityNone, 1 );
+
+ obj->uart->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
+ obj->uart->TASKS_STARTTX = 1;
+ obj->uart->TASKS_STARTRX = 1;
+ obj->uart->EVENTS_RXDRDY = 0;
+ // dummy write needed or TXDRDY trails write rather than leads write.
+ // pins are disconnected so nothing is physically transmitted on the wire
+ obj->uart->TXD = 0;
+
+ obj->index = 0;
+
+ // set rx/tx pins in PullUp mode
+ if (tx != NC) {
+ pin_mode(tx, PullUp);
+ }
+ if (rx != NC) {
+ pin_mode(rx, PullUp);
+ }
+
+ // Set CTS pin to PullDown mode if used.
+ if( cts != NC )
+ {
+ pin_mode( cts, PullDown );
+ }
+
+
+ if (uart == STDIO_UART) {
+ stdio_uart_inited = 1;
+ memcpy(&stdio_uart, obj, sizeof(serial_t));
+ }
+}
void MySerialBase::_irq_handler( uint32_t id, SerialIrq irq_type )
{
MySerialBase *handler = (MySerialBase*)id;
@@ -144,65 +202,4 @@
return len;
}
-void my_serial_init( serial_t *obj, PinName tx, PinName rx, PinName rts, PinName cts )
-{
- UARTName uart = UART_0;
- obj->uart = (NRF_UART_Type *)uart;
-
- // pin configurations --
- NRF_GPIO->DIR |= (1 << tx); // TX_PIN_NUMBER
- NRF_GPIO->DIR |= ((NC == rts) ? 0 : (1 << rts)); // RTS_PIN_NUMBER
-
- NRF_GPIO->DIR &= ~(1 << rx); // RX_PIN_NUMBER
- NRF_GPIO->DIR &= ~((NC == cts) ? 0 : (1 << cts)); // CTS_PIN_NUMBER
-
- obj->uart->PSELRTS = ((NC == rts) ? 0xFFFFFFFF : rts); // RTS_PIN_NUMBER
- obj->uart->PSELTXD = tx; // TX_PIN_NUMBER
- obj->uart->PSELCTS = ((NC == cts) ? 0xFFFFFFFF : cts); // CTS_PIN_NUMBER
- obj->uart->PSELRXD = rx; // RX_PIN_NUMBER
-
- // set default baud rate and format
- serial_baud ( obj, 9600 );
- serial_format( obj, 8, ParityNone, 1 );
-
- obj->uart->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
- obj->uart->TASKS_STARTTX = 1;
- obj->uart->TASKS_STARTRX = 1;
- obj->uart->EVENTS_RXDRDY = 0;
- // dummy write needed or TXDRDY trails write rather than leads write.
- // pins are disconnected so nothing is physically transmitted on the wire
- obj->uart->TXD = 0;
-
- obj->index = 0;
-
- // set rx/tx pins in PullUp mode
- if (tx != NC) {
- pin_mode(tx, PullUp);
- }
- if (rx != NC) {
- pin_mode(rx, PullUp);
- }
-
- // Set CTS pin to PullDown mode if used.
- if( cts != NC )
- {
- pin_mode( cts, PullDown );
- }
-
- if( (NC != rts) || (NC != cts) )
- {
- obj->uart->CONFIG |= 0x01; // Enable HWFC
-
- } else
- {
- obj->uart->CONFIG &= ~0x01; // Disable HWFC;
- }
-
-
- if (uart == STDIO_UART) {
- stdio_uart_inited = 1;
- memcpy(&stdio_uart, obj, sizeof(serial_t));
- }
-}
-
/* EOF */
