mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
sam: USART modes now fails if used on UART
This commit is contained in:
parent
0dbd35a70e
commit
5e97168fbc
@ -37,10 +37,15 @@ UARTClass::UARTClass( Uart *pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer *p
|
||||
|
||||
void UARTClass::begin( const uint32_t dwBaudRate )
|
||||
{
|
||||
begin( dwBaudRate, UART_MR_PAR_NO | UART_MR_CHMODE_NORMAL );
|
||||
begin(dwBaudRate, Mode_8N1);
|
||||
}
|
||||
|
||||
void UARTClass::begin( const uint32_t dwBaudRate, const uint32_t config )
|
||||
void UARTClass::begin(const uint32_t dwBaudRate, const UARTModes config)
|
||||
{
|
||||
init(dwBaudRate, static_cast<uint32_t>(config));
|
||||
}
|
||||
|
||||
void UARTClass::init(const uint32_t dwBaudRate, const uint32_t config)
|
||||
{
|
||||
// Configure PMC
|
||||
pmc_enable_periph_clk( _dwId );
|
||||
@ -52,7 +57,7 @@ void UARTClass::begin( const uint32_t dwBaudRate, const uint32_t config )
|
||||
_pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS;
|
||||
|
||||
// Configure mode
|
||||
_pUart->UART_MR = config;
|
||||
_pUart->UART_MR = config | US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHMODE_NORMAL;
|
||||
|
||||
// Configure baudrate (asynchronous, no oversampling)
|
||||
_pUart->UART_BRGR = (SystemCoreClock / dwBaudRate) >> 4;
|
||||
|
@ -25,22 +25,28 @@
|
||||
// Includes Atmel CMSIS
|
||||
#include <chip.h>
|
||||
|
||||
#define SERIAL_8N1 UARTClass::Mode_8N1
|
||||
#define SERIAL_8N2 UARTClass::Mode_8N2
|
||||
#define SERIAL_8E1 UARTClass::Mode_8E1
|
||||
#define SERIAL_8E2 UARTClass::Mode_8E2
|
||||
#define SERIAL_8O1 UARTClass::Mode_8O1
|
||||
#define SERIAL_8O2 UARTClass::Mode_8O2
|
||||
|
||||
class UARTClass : public HardwareSerial
|
||||
{
|
||||
protected:
|
||||
RingBuffer *_rx_buffer;
|
||||
RingBuffer *_tx_buffer;
|
||||
|
||||
protected:
|
||||
Uart* _pUart;
|
||||
IRQn_Type _dwIrq;
|
||||
uint32_t _dwId;
|
||||
|
||||
public:
|
||||
enum UARTModes {
|
||||
Mode_8N1 = US_MR_CHRL_8_BIT | US_MR_PAR_NO | US_MR_NBSTOP_1_BIT,
|
||||
Mode_8N2 = US_MR_CHRL_8_BIT | US_MR_PAR_NO | US_MR_NBSTOP_2_BIT,
|
||||
Mode_8E1 = US_MR_CHRL_8_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_1_BIT,
|
||||
Mode_8E2 = US_MR_CHRL_8_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_2_BIT,
|
||||
Mode_8O1 = US_MR_CHRL_8_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_1_BIT,
|
||||
Mode_8O2 = US_MR_CHRL_8_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_2_BIT,
|
||||
};
|
||||
UARTClass(Uart* pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer, RingBuffer* pTx_buffer);
|
||||
|
||||
void begin(const uint32_t dwBaudRate);
|
||||
void begin(const uint32_t dwBaudRate, const uint32_t config);
|
||||
void begin(const uint32_t dwBaudRate, const UARTModes config);
|
||||
void end(void);
|
||||
int available(void);
|
||||
int availableForWrite(void);
|
||||
@ -56,6 +62,17 @@ class UARTClass : public HardwareSerial
|
||||
void IrqHandler(void);
|
||||
|
||||
operator bool() { return true; }; // UART always active
|
||||
|
||||
protected:
|
||||
void init(const uint32_t dwBaudRate, const uint32_t config);
|
||||
|
||||
RingBuffer *_rx_buffer;
|
||||
RingBuffer *_tx_buffer;
|
||||
|
||||
Uart* _pUart;
|
||||
IRQn_Type _dwIrq;
|
||||
uint32_t _dwId;
|
||||
|
||||
};
|
||||
|
||||
#endif // _UART_CLASS_
|
||||
|
@ -32,8 +32,8 @@ USARTClass::USARTClass( Usart* pUsart, IRQn_Type dwIrq, uint32_t dwId, RingBuffe
|
||||
|
||||
// Public Methods //////////////////////////////////////////////////////////////
|
||||
|
||||
void USARTClass::begin( const uint32_t dwBaudRate, const uint32_t config )
|
||||
void USARTClass::begin( const uint32_t dwBaudRate, const USARTModes config )
|
||||
{
|
||||
UARTClass::begin(dwBaudRate, config);
|
||||
UARTClass::init(dwBaudRate, static_cast<uint32_t>(config));
|
||||
}
|
||||
|
||||
|
@ -26,35 +26,24 @@
|
||||
#include <chip.h>
|
||||
|
||||
// Define config for Serial.begin(baud, config);
|
||||
#define SERIAL_5N1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_5_BIT | US_MR_PAR_NO | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_6N1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_6_BIT | US_MR_PAR_NO | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_7N1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_7_BIT | US_MR_PAR_NO | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_8N1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_8_BIT | US_MR_PAR_NO | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
|
||||
#define SERIAL_5N2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_5_BIT | US_MR_PAR_NO | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_6N2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_6_BIT | US_MR_PAR_NO | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_7N2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_7_BIT | US_MR_PAR_NO | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_8N2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_8_BIT | US_MR_PAR_NO | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
|
||||
#define SERIAL_5E1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_5_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_6E1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_6_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_7E1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_7_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_8E1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_8_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
|
||||
#define SERIAL_5E2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_5_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_6E2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_6_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_7E2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_7_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_8E2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_8_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
|
||||
#define SERIAL_5O1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_5_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_6O1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_6_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_7O1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_7_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_8O1 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_8_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL)
|
||||
|
||||
#define SERIAL_5O2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_5_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_6O2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_6_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_7O2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_7_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_8O2 (US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_8_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL)
|
||||
#define SERIAL_5N1 USARTClass::Mode_5N1
|
||||
#define SERIAL_6N1 USARTClass::Mode_6N1
|
||||
#define SERIAL_7N1 USARTClass::Mode_7N1
|
||||
#define SERIAL_5N2 USARTClass::Mode_5N2
|
||||
#define SERIAL_6N2 USARTClass::Mode_6N2
|
||||
#define SERIAL_7N2 USARTClass::Mode_7N2
|
||||
#define SERIAL_5E1 USARTClass::Mode_5E1
|
||||
#define SERIAL_6E1 USARTClass::Mode_6E1
|
||||
#define SERIAL_7E1 USARTClass::Mode_7E1
|
||||
#define SERIAL_5E2 USARTClass::Mode_5E2
|
||||
#define SERIAL_6E2 USARTClass::Mode_6E2
|
||||
#define SERIAL_7E2 USARTClass::Mode_7E2
|
||||
#define SERIAL_5O1 USARTClass::Mode_5O1
|
||||
#define SERIAL_6O1 USARTClass::Mode_6O1
|
||||
#define SERIAL_7O1 USARTClass::Mode_7O1
|
||||
#define SERIAL_5O2 USARTClass::Mode_5O2
|
||||
#define SERIAL_6O2 USARTClass::Mode_6O2
|
||||
#define SERIAL_7O2 USARTClass::Mode_7O2
|
||||
|
||||
class USARTClass : public UARTClass
|
||||
{
|
||||
@ -62,9 +51,31 @@ class USARTClass : public UARTClass
|
||||
Usart* _pUsart;
|
||||
|
||||
public:
|
||||
// 8 bit modes are inherited from UARTClass
|
||||
enum USARTModes {
|
||||
Mode_5N1 = US_MR_CHRL_5_BIT | US_MR_PAR_NO | US_MR_NBSTOP_1_BIT,
|
||||
Mode_6N1 = US_MR_CHRL_6_BIT | US_MR_PAR_NO | US_MR_NBSTOP_1_BIT,
|
||||
Mode_7N1 = US_MR_CHRL_7_BIT | US_MR_PAR_NO | US_MR_NBSTOP_1_BIT,
|
||||
Mode_5N2 = US_MR_CHRL_5_BIT | US_MR_PAR_NO | US_MR_NBSTOP_2_BIT,
|
||||
Mode_6N2 = US_MR_CHRL_6_BIT | US_MR_PAR_NO | US_MR_NBSTOP_2_BIT,
|
||||
Mode_7N2 = US_MR_CHRL_7_BIT | US_MR_PAR_NO | US_MR_NBSTOP_2_BIT,
|
||||
Mode_5E1 = US_MR_CHRL_5_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_1_BIT,
|
||||
Mode_6E1 = US_MR_CHRL_6_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_1_BIT,
|
||||
Mode_7E1 = US_MR_CHRL_7_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_1_BIT,
|
||||
Mode_5E2 = US_MR_CHRL_5_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_2_BIT,
|
||||
Mode_6E2 = US_MR_CHRL_6_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_2_BIT,
|
||||
Mode_7E2 = US_MR_CHRL_7_BIT | US_MR_PAR_EVEN | US_MR_NBSTOP_2_BIT,
|
||||
Mode_5O1 = US_MR_CHRL_5_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_1_BIT,
|
||||
Mode_6O1 = US_MR_CHRL_6_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_1_BIT,
|
||||
Mode_7O1 = US_MR_CHRL_7_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_1_BIT,
|
||||
Mode_5O2 = US_MR_CHRL_5_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_2_BIT,
|
||||
Mode_6O2 = US_MR_CHRL_6_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_2_BIT,
|
||||
Mode_7O2 = US_MR_CHRL_7_BIT | US_MR_PAR_ODD | US_MR_NBSTOP_2_BIT,
|
||||
};
|
||||
|
||||
USARTClass( Usart* pUsart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer, RingBuffer* pTx_buffer );
|
||||
|
||||
void begin( const uint32_t dwBaudRate , const uint32_t config );
|
||||
void begin( const uint32_t dwBaudRate , const USARTModes config );
|
||||
using UARTClass::begin; // Needed only for polymorphic methods
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user