mirror of https://github.com/ARMmbed/mbed-os.git
Serial, SerialBase, UARTSerial: Add explicit pinmap support
parent
3d2bebde0c
commit
bef6854a47
|
@ -73,6 +73,16 @@ public:
|
|||
*/
|
||||
Serial(PinName tx, PinName rx, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
|
||||
|
||||
/** Create a Serial port, connected to the specified transmit and receive pins
|
||||
*
|
||||
* @param explicit_pinmap reference to strucure which holds static pinmap.
|
||||
* @param name The name of the stream associated with this serial port (optional)
|
||||
* @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE or 9600)
|
||||
*
|
||||
* @note
|
||||
* Either tx or rx may be specified as NC (Not Connected) if unused
|
||||
*/
|
||||
Serial(const serial_pinmap_t &explicit_pinmap, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
|
||||
|
||||
/** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
|
||||
*
|
||||
|
@ -85,6 +95,16 @@ public:
|
|||
*/
|
||||
Serial(PinName tx, PinName rx, int baud);
|
||||
|
||||
/** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
|
||||
*
|
||||
* @param explicit_pinmap reference to strucure which holds static pinmap.
|
||||
* @param baud The baud rate of the serial port
|
||||
*
|
||||
* @note
|
||||
* Either tx or rx may be specified as NC (Not Connected) if unused
|
||||
*/
|
||||
Serial(const serial_pinmap_t &explicit_pinmap, int baud);
|
||||
|
||||
/* Stream gives us a FileHandle with non-functional poll()/readable()/writable. Pass through
|
||||
* the calls from the SerialBase instead for backwards compatibility. This problem is
|
||||
* part of why Stream and Serial should be deprecated.
|
||||
|
|
|
@ -200,6 +200,13 @@ public:
|
|||
* @param flow2 the second flow control pin (CTS for RTSCTS)
|
||||
*/
|
||||
void set_flow_control(Flow type, PinName flow1 = NC, PinName flow2 = NC);
|
||||
|
||||
/** Set the flow control type on the serial port
|
||||
*
|
||||
* @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
|
||||
* @param pinmap reference to strucure which holds static pinmap
|
||||
*/
|
||||
void set_flow_control(Flow type, const serial_fc_pinmap_t &explicit_pinmap);
|
||||
#endif
|
||||
|
||||
static void _irq_handler(uint32_t id, SerialIrq irq_type);
|
||||
|
@ -313,6 +320,7 @@ protected:
|
|||
#if !defined(DOXYGEN_ONLY)
|
||||
protected:
|
||||
SerialBase(PinName tx, PinName rx, int baud);
|
||||
SerialBase(const serial_pinmap_t &explicit_pinmap, int baud);
|
||||
virtual ~SerialBase();
|
||||
|
||||
int _base_getc();
|
||||
|
|
|
@ -58,6 +58,13 @@ public:
|
|||
* @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
|
||||
*/
|
||||
UARTSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
|
||||
|
||||
/** Create a UARTSerial port, connected to the specified transmit and receive pins, with a particular baud rate.
|
||||
* @param explicit_pinmap reference to strucure which holds static pinmap
|
||||
* @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
|
||||
*/
|
||||
UARTSerial(const serial_pinmap_t &explicit_pinmap, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
|
||||
|
||||
virtual ~UARTSerial();
|
||||
|
||||
/** Equivalent to POSIX poll(). Derived from FileHandle.
|
||||
|
|
|
@ -24,10 +24,18 @@ Serial::Serial(PinName tx, PinName rx, const char *name, int baud) : SerialBase(
|
|||
{
|
||||
}
|
||||
|
||||
Serial::Serial(const serial_pinmap_t &explicit_pinmap, const char *name, int baud) : SerialBase(explicit_pinmap, baud), Stream(name)
|
||||
{
|
||||
}
|
||||
|
||||
Serial::Serial(PinName tx, PinName rx, int baud): SerialBase(tx, rx, baud), Stream(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Serial::Serial(const serial_pinmap_t &explicit_pinmap, int baud): SerialBase(explicit_pinmap, baud), Stream(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
int Serial::_getc()
|
||||
{
|
||||
// Mutex is already held
|
||||
|
|
|
@ -40,6 +40,29 @@ SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
|
|||
_init();
|
||||
}
|
||||
|
||||
SerialBase::SerialBase(const serial_pinmap_t &explicit_pinmap, int baud) :
|
||||
#if DEVICE_SERIAL_ASYNCH
|
||||
_thunk_irq(this), _tx_usage(DMA_USAGE_NEVER),
|
||||
_rx_usage(DMA_USAGE_NEVER), _tx_callback(NULL),
|
||||
_rx_callback(NULL), _tx_asynch_set(false),
|
||||
_rx_asynch_set(false),
|
||||
#endif
|
||||
_serial(),
|
||||
_baud(baud),
|
||||
_tx_pin(explicit_pinmap.tx_pin),
|
||||
_rx_pin(explicit_pinmap.rx_pin)
|
||||
{
|
||||
// No lock needed in the constructor
|
||||
|
||||
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
|
||||
_irq[i] = NULL;
|
||||
}
|
||||
|
||||
serial_init_direct(&_serial, &explicit_pinmap);
|
||||
serial_baud(&_serial, _baud);
|
||||
serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this);
|
||||
}
|
||||
|
||||
void SerialBase::baud(int baudrate)
|
||||
{
|
||||
lock();
|
||||
|
@ -292,6 +315,14 @@ void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2)
|
|||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
void SerialBase::set_flow_control(Flow type, const serial_fc_pinmap_t &explicit_pinmap)
|
||||
{
|
||||
lock();
|
||||
FlowControl flow_type = (FlowControl)type;
|
||||
serial_set_flow_control_direct(&_serial, flow_type, &explicit_pinmap);
|
||||
unlock();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if DEVICE_SERIAL_ASYNCH
|
||||
|
|
|
@ -36,6 +36,19 @@ UARTSerial::UARTSerial(PinName tx, PinName rx, int baud) :
|
|||
enable_rx_irq();
|
||||
}
|
||||
|
||||
UARTSerial::UARTSerial(const serial_pinmap_t &explicit_pinmap, int baud) :
|
||||
SerialBase(explicit_pinmap, baud),
|
||||
_blocking(true),
|
||||
_tx_irq_enabled(false),
|
||||
_rx_irq_enabled(false),
|
||||
_tx_enabled(true),
|
||||
_rx_enabled(true),
|
||||
_dcd_irq(NULL)
|
||||
{
|
||||
/* Attatch IRQ routines to the serial device. */
|
||||
enable_rx_irq();
|
||||
}
|
||||
|
||||
UARTSerial::~UARTSerial()
|
||||
{
|
||||
delete _dcd_irq;
|
||||
|
|
Loading…
Reference in New Issue