diff --git a/arduino_fixes/1.5.6-r2/UARTClass.cpp b/arduino_fixes/1.5.6-r2/UARTClass.cpp deleted file mode 100644 index aa416cd7..00000000 --- a/arduino_fixes/1.5.6-r2/UARTClass.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include -#include -#include -#include "UARTClass.h" - -// Constructors //////////////////////////////////////////////////////////////// - -UARTClass::UARTClass( Uart* pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer ) -{ - _rx_buffer = pRx_buffer ; - - _pUart=pUart ; - _dwIrq=dwIrq ; - _dwId=dwId ; -} - -// Public Methods ////////////////////////////////////////////////////////////// - -void UARTClass::begin( const uint32_t dwBaudRate ) -{ - // Configure PMC - pmc_enable_periph_clk( _dwId ) ; - - // Disable PDC channel - _pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS ; - - // Reset and disable receiver and transmitter - _pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS ; - - // Configure mode - _pUart->UART_MR = UART_MR_PAR_NO | UART_MR_CHMODE_NORMAL ; - - // Configure baudrate (asynchronous, no oversampling) - _pUart->UART_BRGR = (SystemCoreClock / dwBaudRate) >> 4 ; - - // Configure interrupts - _pUart->UART_IDR = 0xFFFFFFFF; - _pUart->UART_IER = UART_IER_RXRDY | UART_IER_OVRE | UART_IER_FRAME; - - // Enable UART interrupt in NVIC - NVIC_EnableIRQ(_dwIrq); - - // Enable receiver and transmitter - _pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN ; -} - -void UARTClass::end( void ) -{ - // clear any received data - _rx_buffer->_iHead = _rx_buffer->_iTail ; - - // Disable UART interrupt in NVIC - NVIC_DisableIRQ( _dwIrq ) ; - - // Wait for any outstanding data to be sent - flush(); - - pmc_disable_periph_clk( _dwId ) ; -} - -int UARTClass::available( void ) -{ - return (uint32_t)(SERIAL_BUFFER_SIZE + _rx_buffer->_iHead - _rx_buffer->_iTail) % SERIAL_BUFFER_SIZE ; -} - -int UARTClass::peek( void ) -{ - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1 ; - - return _rx_buffer->_aucBuffer[_rx_buffer->_iTail] ; -} - -int UARTClass::read( void ) -{ - // if the head isn't ahead of the tail, we don't have any characters - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1 ; - - uint8_t uc = _rx_buffer->_aucBuffer[_rx_buffer->_iTail] ; - _rx_buffer->_iTail = (unsigned int)(_rx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE ; - return uc ; -} - -void UARTClass::flush( void ) -{ - // Wait for transmission to complete - while ((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) - ; -} - -size_t UARTClass::write( const uint8_t uc_data ) -{ - return write(uc_data, true); -} - -size_t UARTClass::write( const uint8_t uc_data, const bool wait ) -{ - // Check if the transmitter is ready - while ((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) { - if ( !wait ) return 0; - } - - // Send character - _pUart->UART_THR = uc_data; - return 1; -} - -void UARTClass::IrqHandler( void ) -{ - uint32_t status = _pUart->UART_SR; - - // Did we receive data ? - if ((status & UART_SR_RXRDY) == UART_SR_RXRDY) - _rx_buffer->store_char(_pUart->UART_RHR); - - // Acknowledge errors - if ((status & UART_SR_OVRE) == UART_SR_OVRE || - (status & UART_SR_FRAME) == UART_SR_FRAME) - { - // TODO: error reporting outside ISR - _pUart->UART_CR |= UART_CR_RSTSTA; - } -} - diff --git a/arduino_fixes/1.5.6-r2/UARTClass.h b/arduino_fixes/1.5.6-r2/UARTClass.h deleted file mode 100644 index dcc02d1e..00000000 --- a/arduino_fixes/1.5.6-r2/UARTClass.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _UART_CLASS_ -#define _UART_CLASS_ - -#include "HardwareSerial.h" -#include "RingBuffer.h" - -// Includes Atmel CMSIS -#include - -class UARTClass : public HardwareSerial -{ - protected: - RingBuffer *_rx_buffer ; - - protected: - Uart* _pUart ; - IRQn_Type _dwIrq ; - uint32_t _dwId ; - - public: - UARTClass( Uart* pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer ) ; - - void begin( const uint32_t dwBaudRate ) ; - void end( void ) ; - int available( void ) ; - int peek( void ) ; - int read( void ) ; - void flush( void ) ; - size_t write( const uint8_t c ) ; - size_t write( const uint8_t c, const bool wait ) ; - - void IrqHandler( void ) ; - -#if defined __GNUC__ /* GCC CS3 */ - using Print::write ; // pull in write(str) and write(buf, size) from Print -#elif defined __ICCARM__ /* IAR Ewarm 5.41+ */ -// virtual void write( const char *str ) ; -// virtual void write( const uint8_t *buffer, size_t size ) ; -#endif - - operator bool() { return true; }; // UART always active -}; - -#endif // _UART_CLASS_ diff --git a/arduino_fixes/1.5.6-r2/USARTClass.cpp b/arduino_fixes/1.5.6-r2/USARTClass.cpp deleted file mode 100644 index 76e34ce3..00000000 --- a/arduino_fixes/1.5.6-r2/USARTClass.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include -#include -#include -#include "USARTClass.h" - -// Constructors //////////////////////////////////////////////////////////////// - -USARTClass::USARTClass( Usart* pUsart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer ) -{ - _rx_buffer = pRx_buffer ; - - _pUsart=pUsart ; - _dwIrq=dwIrq ; - _dwId=dwId ; -} - -// Public Methods ////////////////////////////////////////////////////////////// - -void USARTClass::begin( const uint32_t dwBaudRate ) -{ - // Configure PMC - pmc_enable_periph_clk( _dwId ) ; - - // Disable PDC channel - _pUsart->US_PTCR = US_PTCR_RXTDIS | US_PTCR_TXTDIS ; - - // Reset and disable receiver and transmitter - _pUsart->US_CR = US_CR_RSTRX | US_CR_RSTTX | US_CR_RXDIS | US_CR_TXDIS ; - - // Configure mode - _pUsart->US_MR = 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; - - // Configure baudrate, asynchronous no oversampling - _pUsart->US_BRGR = (SystemCoreClock / dwBaudRate) / 16 ; - - // Configure interrupts - _pUsart->US_IDR = 0xFFFFFFFF; - _pUsart->US_IER = US_IER_RXRDY | US_IER_OVRE | US_IER_FRAME; - - // Enable UART interrupt in NVIC - NVIC_EnableIRQ( _dwIrq ) ; - - // Enable receiver and transmitter - _pUsart->US_CR = US_CR_RXEN | US_CR_TXEN ; -} - -void USARTClass::end( void ) -{ - // clear any received data - _rx_buffer->_iHead = _rx_buffer->_iTail ; - - // Disable UART interrupt in NVIC - NVIC_DisableIRQ( _dwIrq ) ; - - // Wait for any outstanding data to be sent - flush(); - - pmc_disable_periph_clk( _dwId ) ; -} - -int USARTClass::available( void ) -{ - return (uint32_t)(SERIAL_BUFFER_SIZE + _rx_buffer->_iHead - _rx_buffer->_iTail) % SERIAL_BUFFER_SIZE ; -} - -int USARTClass::peek( void ) -{ - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1 ; - - return _rx_buffer->_aucBuffer[_rx_buffer->_iTail] ; -} - -int USARTClass::read( void ) -{ - // if the head isn't ahead of the tail, we don't have any characters - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1 ; - - uint8_t uc = _rx_buffer->_aucBuffer[_rx_buffer->_iTail] ; - _rx_buffer->_iTail = (unsigned int)(_rx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE ; - return uc ; -} - -void USARTClass::flush( void ) -{ - // Wait for transmission to complete - while ((_pUsart->US_CSR & US_CSR_TXRDY) != US_CSR_TXRDY) - ; -} - -size_t USARTClass::write( const uint8_t uc_data ) -{ - return write(uc_data, true); -} - -size_t USARTClass::write( const uint8_t uc_data, const bool wait ) -{ - // Check if the transmitter is ready - while ((_pUsart->US_CSR & US_CSR_TXRDY) != US_CSR_TXRDY) { - if ( !wait ) return 0; - } - - // Send character - _pUsart->US_THR = uc_data ; - return 1; -} - -void USARTClass::IrqHandler( void ) -{ - uint32_t status = _pUsart->US_CSR; - - // Did we receive data ? - if ((status & US_CSR_RXRDY) == US_CSR_RXRDY) - _rx_buffer->store_char( _pUsart->US_RHR ) ; - - // Acknowledge errors - if ((status & US_CSR_OVRE) == US_CSR_OVRE || - (status & US_CSR_FRAME) == US_CSR_FRAME) - { - // TODO: error reporting outside ISR - _pUsart->US_CR |= US_CR_RSTSTA; - } -} - diff --git a/arduino_fixes/1.5.6-r2/USARTClass.h b/arduino_fixes/1.5.6-r2/USARTClass.h deleted file mode 100644 index 61248604..00000000 --- a/arduino_fixes/1.5.6-r2/USARTClass.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _USART_CLASS_ -#define _USART_CLASS_ - -#include "HardwareSerial.h" -#include "RingBuffer.h" - -// Includes Atmel CMSIS -#include - -class USARTClass : public HardwareSerial -{ - protected: - RingBuffer *_rx_buffer ; - - protected: - Usart* _pUsart ; - IRQn_Type _dwIrq ; - uint32_t _dwId ; - - public: - USARTClass( Usart* pUsart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer ) ; - - void begin( const uint32_t dwBaudRate ) ; - void end( void ) ; - int available( void ) ; - int peek( void ) ; - int read( void ) ; - void flush( void ) ; - size_t write( const uint8_t c ) ; - size_t write( const uint8_t c , const bool wait ) ; - - void IrqHandler( void ) ; - -#if defined __GNUC__ /* GCC CS3 */ - using Print::write ; // pull in write(str) and write(buf, size) from Print -#elif defined __ICCARM__ /* IAR Ewarm 5.41+ */ -// virtual void write( const char *str ) ; -// virtual void write( const uint8_t *buffer, size_t size ) ; -#endif - - operator bool() { return true; }; // USART always active -}; - -#endif // _USART_CLASS_ diff --git a/arduino_fixes/1.5.7-1.5.8/UARTClass.cpp b/arduino_fixes/1.5.7-1.5.8/UARTClass.cpp deleted file mode 100644 index aa416cd7..00000000 --- a/arduino_fixes/1.5.7-1.5.8/UARTClass.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include -#include -#include -#include "UARTClass.h" - -// Constructors //////////////////////////////////////////////////////////////// - -UARTClass::UARTClass( Uart* pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer ) -{ - _rx_buffer = pRx_buffer ; - - _pUart=pUart ; - _dwIrq=dwIrq ; - _dwId=dwId ; -} - -// Public Methods ////////////////////////////////////////////////////////////// - -void UARTClass::begin( const uint32_t dwBaudRate ) -{ - // Configure PMC - pmc_enable_periph_clk( _dwId ) ; - - // Disable PDC channel - _pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS ; - - // Reset and disable receiver and transmitter - _pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS ; - - // Configure mode - _pUart->UART_MR = UART_MR_PAR_NO | UART_MR_CHMODE_NORMAL ; - - // Configure baudrate (asynchronous, no oversampling) - _pUart->UART_BRGR = (SystemCoreClock / dwBaudRate) >> 4 ; - - // Configure interrupts - _pUart->UART_IDR = 0xFFFFFFFF; - _pUart->UART_IER = UART_IER_RXRDY | UART_IER_OVRE | UART_IER_FRAME; - - // Enable UART interrupt in NVIC - NVIC_EnableIRQ(_dwIrq); - - // Enable receiver and transmitter - _pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN ; -} - -void UARTClass::end( void ) -{ - // clear any received data - _rx_buffer->_iHead = _rx_buffer->_iTail ; - - // Disable UART interrupt in NVIC - NVIC_DisableIRQ( _dwIrq ) ; - - // Wait for any outstanding data to be sent - flush(); - - pmc_disable_periph_clk( _dwId ) ; -} - -int UARTClass::available( void ) -{ - return (uint32_t)(SERIAL_BUFFER_SIZE + _rx_buffer->_iHead - _rx_buffer->_iTail) % SERIAL_BUFFER_SIZE ; -} - -int UARTClass::peek( void ) -{ - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1 ; - - return _rx_buffer->_aucBuffer[_rx_buffer->_iTail] ; -} - -int UARTClass::read( void ) -{ - // if the head isn't ahead of the tail, we don't have any characters - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1 ; - - uint8_t uc = _rx_buffer->_aucBuffer[_rx_buffer->_iTail] ; - _rx_buffer->_iTail = (unsigned int)(_rx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE ; - return uc ; -} - -void UARTClass::flush( void ) -{ - // Wait for transmission to complete - while ((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) - ; -} - -size_t UARTClass::write( const uint8_t uc_data ) -{ - return write(uc_data, true); -} - -size_t UARTClass::write( const uint8_t uc_data, const bool wait ) -{ - // Check if the transmitter is ready - while ((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) { - if ( !wait ) return 0; - } - - // Send character - _pUart->UART_THR = uc_data; - return 1; -} - -void UARTClass::IrqHandler( void ) -{ - uint32_t status = _pUart->UART_SR; - - // Did we receive data ? - if ((status & UART_SR_RXRDY) == UART_SR_RXRDY) - _rx_buffer->store_char(_pUart->UART_RHR); - - // Acknowledge errors - if ((status & UART_SR_OVRE) == UART_SR_OVRE || - (status & UART_SR_FRAME) == UART_SR_FRAME) - { - // TODO: error reporting outside ISR - _pUart->UART_CR |= UART_CR_RSTSTA; - } -} - diff --git a/arduino_fixes/1.5.7-1.5.8/UARTClass.h b/arduino_fixes/1.5.7-1.5.8/UARTClass.h deleted file mode 100644 index dcc02d1e..00000000 --- a/arduino_fixes/1.5.7-1.5.8/UARTClass.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _UART_CLASS_ -#define _UART_CLASS_ - -#include "HardwareSerial.h" -#include "RingBuffer.h" - -// Includes Atmel CMSIS -#include - -class UARTClass : public HardwareSerial -{ - protected: - RingBuffer *_rx_buffer ; - - protected: - Uart* _pUart ; - IRQn_Type _dwIrq ; - uint32_t _dwId ; - - public: - UARTClass( Uart* pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer ) ; - - void begin( const uint32_t dwBaudRate ) ; - void end( void ) ; - int available( void ) ; - int peek( void ) ; - int read( void ) ; - void flush( void ) ; - size_t write( const uint8_t c ) ; - size_t write( const uint8_t c, const bool wait ) ; - - void IrqHandler( void ) ; - -#if defined __GNUC__ /* GCC CS3 */ - using Print::write ; // pull in write(str) and write(buf, size) from Print -#elif defined __ICCARM__ /* IAR Ewarm 5.41+ */ -// virtual void write( const char *str ) ; -// virtual void write( const uint8_t *buffer, size_t size ) ; -#endif - - operator bool() { return true; }; // UART always active -}; - -#endif // _UART_CLASS_ diff --git a/arduino_fixes/1.5.7-1.5.8/USARTClass.cpp b/arduino_fixes/1.5.7-1.5.8/USARTClass.cpp deleted file mode 100644 index 888b5cb1..00000000 --- a/arduino_fixes/1.5.7-1.5.8/USARTClass.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include -#include -#include -#include "USARTClass.h" - -// Constructors //////////////////////////////////////////////////////////////// - -USARTClass::USARTClass( Usart* pUsart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer ) -{ - _rx_buffer = pRx_buffer ; - - _pUsart=pUsart ; - _dwIrq=dwIrq ; - _dwId=dwId ; -} - -// Public Methods ////////////////////////////////////////////////////////////// - -void USARTClass::begin( const uint32_t dwBaudRate ) -{ - begin( dwBaudRate, SERIAL_8N1 ); -} - -void USARTClass::begin( const uint32_t dwBaudRate, const uint32_t config ) -{ - // Configure PMC - pmc_enable_periph_clk( _dwId ) ; - - // Disable PDC channel - _pUsart->US_PTCR = US_PTCR_RXTDIS | US_PTCR_TXTDIS ; - - // Reset and disable receiver and transmitter - _pUsart->US_CR = US_CR_RSTRX | US_CR_RSTTX | US_CR_RXDIS | US_CR_TXDIS ; - - // Configure mode - _pUsart->US_MR = config; - - - // Configure baudrate, asynchronous no oversampling - _pUsart->US_BRGR = (SystemCoreClock / dwBaudRate) / 16 ; - - // Configure interrupts - _pUsart->US_IDR = 0xFFFFFFFF; - _pUsart->US_IER = US_IER_RXRDY | US_IER_OVRE | US_IER_FRAME; - - // Enable UART interrupt in NVIC - NVIC_EnableIRQ( _dwIrq ) ; - - // Enable receiver and transmitter - _pUsart->US_CR = US_CR_RXEN | US_CR_TXEN ; -} - -void USARTClass::end( void ) -{ - // clear any received data - _rx_buffer->_iHead = _rx_buffer->_iTail ; - - // Disable UART interrupt in NVIC - NVIC_DisableIRQ( _dwIrq ) ; - - // Wait for any outstanding data to be sent - flush(); - - pmc_disable_periph_clk( _dwId ) ; -} - -int USARTClass::available( void ) -{ - return (uint32_t)(SERIAL_BUFFER_SIZE + _rx_buffer->_iHead - _rx_buffer->_iTail) % SERIAL_BUFFER_SIZE ; -} - -int USARTClass::peek( void ) -{ - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1 ; - - return _rx_buffer->_aucBuffer[_rx_buffer->_iTail] ; -} - -int USARTClass::read( void ) -{ - // if the head isn't ahead of the tail, we don't have any characters - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1 ; - - uint8_t uc = _rx_buffer->_aucBuffer[_rx_buffer->_iTail] ; - _rx_buffer->_iTail = (unsigned int)(_rx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE ; - return uc ; -} - -void USARTClass::flush( void ) -{ - // Wait for transmission to complete - while ((_pUsart->US_CSR & US_CSR_TXRDY) != US_CSR_TXRDY) - ; -} - -size_t USARTClass::write( const uint8_t uc_data ) -{ - return write(uc_data, true); -} - -size_t USARTClass::write( const uint8_t uc_data, const bool wait ) -{ - // Check if the transmitter is ready - while ((_pUsart->US_CSR & US_CSR_TXRDY) != US_CSR_TXRDY) { - if ( !wait ) return 0; - } - - // Send character - _pUsart->US_THR = uc_data ; - return 1; -} - -void USARTClass::IrqHandler( void ) -{ - uint32_t status = _pUsart->US_CSR; - - // Did we receive data ? - if ((status & US_CSR_RXRDY) == US_CSR_RXRDY) - _rx_buffer->store_char( _pUsart->US_RHR ) ; - - // Acknowledge errors - if ((status & US_CSR_OVRE) == US_CSR_OVRE || - (status & US_CSR_FRAME) == US_CSR_FRAME) - { - // TODO: error reporting outside ISR - _pUsart->US_CR |= US_CR_RSTSTA; - } -} - diff --git a/arduino_fixes/1.5.7-1.5.8/USARTClass.h b/arduino_fixes/1.5.7-1.5.8/USARTClass.h deleted file mode 100644 index ff99f7d9..00000000 --- a/arduino_fixes/1.5.7-1.5.8/USARTClass.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _USART_CLASS_ -#define _USART_CLASS_ - -#include "HardwareSerial.h" -#include "RingBuffer.h" - -// Includes Atmel CMSIS -#include - -// 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) - -class USARTClass : public HardwareSerial -{ - protected: - RingBuffer *_rx_buffer ; - - protected: - Usart* _pUsart ; - IRQn_Type _dwIrq ; - uint32_t _dwId ; - - public: - USARTClass( Usart* pUsart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer ) ; - - void begin( const uint32_t dwBaudRate ) ; - void begin( const uint32_t dwBaudRate , const uint32_t config ) ; - void end( void ) ; - int available( void ) ; - int peek( void ) ; - int read( void ) ; - void flush( void ) ; - size_t write( const uint8_t c ) ; - size_t write( const uint8_t c , const bool wait ) ; - - void IrqHandler( void ) ; - -#if defined __GNUC__ /* GCC CS3 */ - using Print::write ; // pull in write(str) and write(buf, size) from Print -#elif defined __ICCARM__ /* IAR Ewarm 5.41+ */ -// virtual void write( const char *str ) ; -// virtual void write( const uint8_t *buffer, size_t size ) ; -#endif - - operator bool() { return true; }; // USART always active -}; - -#endif // _USART_CLASS_ diff --git a/arduino_fixes/1.6.0/UARTClass.cpp b/arduino_fixes/1.6.0/UARTClass.cpp deleted file mode 100644 index f1d7c629..00000000 --- a/arduino_fixes/1.6.0/UARTClass.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include -#include -#include -#include "UARTClass.h" - -// Constructors //////////////////////////////////////////////////////////////// - -UARTClass::UARTClass( Uart *pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer *pRx_buffer, RingBuffer *pTx_buffer ) -{ - _rx_buffer = pRx_buffer; - _tx_buffer = pTx_buffer; - - _pUart=pUart; - _dwIrq=dwIrq; - _dwId=dwId; -} - -// Public Methods ////////////////////////////////////////////////////////////// - -void UARTClass::begin(const uint32_t dwBaudRate) -{ - begin(dwBaudRate, Mode_8N1); -} - -void UARTClass::begin(const uint32_t dwBaudRate, const UARTModes config) -{ - uint32_t modeReg = static_cast(config) & 0x00000E00; - init(dwBaudRate, modeReg | UART_MR_CHMODE_NORMAL); -} - -void UARTClass::init(const uint32_t dwBaudRate, const uint32_t modeReg) -{ - // Configure PMC - pmc_enable_periph_clk( _dwId ); - - // Disable PDC channel - _pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS; - - // Reset and disable receiver and transmitter - _pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS; - - // Configure mode - _pUart->UART_MR = modeReg; - - // Configure baudrate (asynchronous, no oversampling) - _pUart->UART_BRGR = (SystemCoreClock / dwBaudRate) >> 4; - - // Configure interrupts - _pUart->UART_IDR = 0xFFFFFFFF; - _pUart->UART_IER = UART_IER_RXRDY | UART_IER_OVRE | UART_IER_FRAME; - - // Enable UART interrupt in NVIC - NVIC_EnableIRQ(_dwIrq); - - // Make sure both ring buffers are initialized back to empty. - _rx_buffer->_iHead = _rx_buffer->_iTail = 0; - _tx_buffer->_iHead = _tx_buffer->_iTail = 0; - - // Enable receiver and transmitter - _pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN; -} - -void UARTClass::end( void ) -{ - // Clear any received data - _rx_buffer->_iHead = _rx_buffer->_iTail; - - // Wait for any outstanding data to be sent - flush(); - - // Disable UART interrupt in NVIC - NVIC_DisableIRQ( _dwIrq ); - - pmc_disable_periph_clk( _dwId ); -} - -void UARTClass::setInterruptPriority(uint32_t priority) -{ - NVIC_SetPriority(_dwIrq, priority & 0x0F); -} - -uint32_t UARTClass::getInterruptPriority() -{ - return NVIC_GetPriority(_dwIrq); -} - -int UARTClass::available( void ) -{ - return (uint32_t)(SERIAL_BUFFER_SIZE + _rx_buffer->_iHead - _rx_buffer->_iTail) % SERIAL_BUFFER_SIZE; -} - -int UARTClass::availableForWrite(void) -{ - int head = _tx_buffer->_iHead; - int tail = _tx_buffer->_iTail; - if (head >= tail) return SERIAL_BUFFER_SIZE - 1 - head + tail; - return tail - head - 1; -} - -int UARTClass::peek( void ) -{ - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1; - - return _rx_buffer->_aucBuffer[_rx_buffer->_iTail]; -} - -int UARTClass::read( void ) -{ - // if the head isn't ahead of the tail, we don't have any characters - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1; - - uint8_t uc = _rx_buffer->_aucBuffer[_rx_buffer->_iTail]; - _rx_buffer->_iTail = (unsigned int)(_rx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE; - return uc; -} - -void UARTClass::flush( void ) -{ - while (_tx_buffer->_iHead != _tx_buffer->_iTail); //wait for transmit data to be sent - // Wait for transmission to complete - while ((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) - ; -} - -size_t UARTClass::write( const uint8_t uc_data ) -{ - return write(uc_data, true); -} - -size_t UARTClass::write( const uint8_t uc_data, const bool wait ) -{ - // Is the hardware currently busy? - if (((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) | - (_tx_buffer->_iTail != _tx_buffer->_iHead)) - { - // return immediately if we're not supposed to wait or buffer, - // meaning that the buffering is most probably done by the calling code - if ( !wait ) return 0; - - // If busy we buffer - unsigned int l = (_tx_buffer->_iHead + 1) % SERIAL_BUFFER_SIZE; - while (_tx_buffer->_iTail == l) - ; // Spin locks if we're about to overwrite the buffer. This continues once the data is sent - - _tx_buffer->_aucBuffer[_tx_buffer->_iHead] = uc_data; - _tx_buffer->_iHead = l; - // Make sure TX interrupt is enabled - _pUart->UART_IER = UART_IER_TXRDY; - } - else - { - // Bypass buffering and send character directly - _pUart->UART_THR = uc_data; - } - return 1; -} - -void UARTClass::IrqHandler( void ) -{ - uint32_t status = _pUart->UART_SR; - - // Did we receive data? - if ((status & UART_SR_RXRDY) == UART_SR_RXRDY) - _rx_buffer->store_char(_pUart->UART_RHR); - - // Do we need to keep sending data? - if ((status & UART_SR_TXRDY) == UART_SR_TXRDY) - { - if (_tx_buffer->_iTail != _tx_buffer->_iHead) { - _pUart->UART_THR = _tx_buffer->_aucBuffer[_tx_buffer->_iTail]; - _tx_buffer->_iTail = (unsigned int)(_tx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE; - } - else - { - // Mask off transmit interrupt so we don't get it anymore - _pUart->UART_IDR = UART_IDR_TXRDY; - } - } - - // Acknowledge errors - if ((status & UART_SR_OVRE) == UART_SR_OVRE || (status & UART_SR_FRAME) == UART_SR_FRAME) - { - // TODO: error reporting outside ISR - _pUart->UART_CR |= UART_CR_RSTSTA; - } -} - diff --git a/arduino_fixes/1.6.0/UARTClass.h b/arduino_fixes/1.6.0/UARTClass.h deleted file mode 100644 index 313e174e..00000000 --- a/arduino_fixes/1.6.0/UARTClass.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _UART_CLASS_ -#define _UART_CLASS_ - -#include "HardwareSerial.h" -#include "RingBuffer.h" - -// Includes Atmel CMSIS -#include - -#define SERIAL_8N1 UARTClass::Mode_8N1 -#define SERIAL_8E1 UARTClass::Mode_8E1 -#define SERIAL_8O1 UARTClass::Mode_8O1 -#define SERIAL_8M1 UARTClass::Mode_8M1 -#define SERIAL_8S1 UARTClass::Mode_8S1 - - -class UARTClass : public HardwareSerial -{ - public: - enum UARTModes { - Mode_8N1 = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_NO, - Mode_8E1 = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_EVEN, - Mode_8O1 = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_ODD, - Mode_8M1 = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_MARK, - Mode_8S1 = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_SPACE, - }; - 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 UARTModes config); - void end(void); - int available(void); - int availableForWrite(void); - int peek(void); - int read(void); - void flush(void); - size_t write(const uint8_t c); - size_t write( const uint8_t c, const bool wait); - using Print::write; // pull in write(str) and write(buf, size) from Print - - void setInterruptPriority(uint32_t priority); - uint32_t getInterruptPriority(); - - 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_ diff --git a/arduino_fixes/1.6.3/UARTClass.cpp b/arduino_fixes/1.6.3/UARTClass.cpp deleted file mode 100644 index f1d7c629..00000000 --- a/arduino_fixes/1.6.3/UARTClass.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include -#include -#include -#include "UARTClass.h" - -// Constructors //////////////////////////////////////////////////////////////// - -UARTClass::UARTClass( Uart *pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer *pRx_buffer, RingBuffer *pTx_buffer ) -{ - _rx_buffer = pRx_buffer; - _tx_buffer = pTx_buffer; - - _pUart=pUart; - _dwIrq=dwIrq; - _dwId=dwId; -} - -// Public Methods ////////////////////////////////////////////////////////////// - -void UARTClass::begin(const uint32_t dwBaudRate) -{ - begin(dwBaudRate, Mode_8N1); -} - -void UARTClass::begin(const uint32_t dwBaudRate, const UARTModes config) -{ - uint32_t modeReg = static_cast(config) & 0x00000E00; - init(dwBaudRate, modeReg | UART_MR_CHMODE_NORMAL); -} - -void UARTClass::init(const uint32_t dwBaudRate, const uint32_t modeReg) -{ - // Configure PMC - pmc_enable_periph_clk( _dwId ); - - // Disable PDC channel - _pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS; - - // Reset and disable receiver and transmitter - _pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS; - - // Configure mode - _pUart->UART_MR = modeReg; - - // Configure baudrate (asynchronous, no oversampling) - _pUart->UART_BRGR = (SystemCoreClock / dwBaudRate) >> 4; - - // Configure interrupts - _pUart->UART_IDR = 0xFFFFFFFF; - _pUart->UART_IER = UART_IER_RXRDY | UART_IER_OVRE | UART_IER_FRAME; - - // Enable UART interrupt in NVIC - NVIC_EnableIRQ(_dwIrq); - - // Make sure both ring buffers are initialized back to empty. - _rx_buffer->_iHead = _rx_buffer->_iTail = 0; - _tx_buffer->_iHead = _tx_buffer->_iTail = 0; - - // Enable receiver and transmitter - _pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN; -} - -void UARTClass::end( void ) -{ - // Clear any received data - _rx_buffer->_iHead = _rx_buffer->_iTail; - - // Wait for any outstanding data to be sent - flush(); - - // Disable UART interrupt in NVIC - NVIC_DisableIRQ( _dwIrq ); - - pmc_disable_periph_clk( _dwId ); -} - -void UARTClass::setInterruptPriority(uint32_t priority) -{ - NVIC_SetPriority(_dwIrq, priority & 0x0F); -} - -uint32_t UARTClass::getInterruptPriority() -{ - return NVIC_GetPriority(_dwIrq); -} - -int UARTClass::available( void ) -{ - return (uint32_t)(SERIAL_BUFFER_SIZE + _rx_buffer->_iHead - _rx_buffer->_iTail) % SERIAL_BUFFER_SIZE; -} - -int UARTClass::availableForWrite(void) -{ - int head = _tx_buffer->_iHead; - int tail = _tx_buffer->_iTail; - if (head >= tail) return SERIAL_BUFFER_SIZE - 1 - head + tail; - return tail - head - 1; -} - -int UARTClass::peek( void ) -{ - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1; - - return _rx_buffer->_aucBuffer[_rx_buffer->_iTail]; -} - -int UARTClass::read( void ) -{ - // if the head isn't ahead of the tail, we don't have any characters - if ( _rx_buffer->_iHead == _rx_buffer->_iTail ) - return -1; - - uint8_t uc = _rx_buffer->_aucBuffer[_rx_buffer->_iTail]; - _rx_buffer->_iTail = (unsigned int)(_rx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE; - return uc; -} - -void UARTClass::flush( void ) -{ - while (_tx_buffer->_iHead != _tx_buffer->_iTail); //wait for transmit data to be sent - // Wait for transmission to complete - while ((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) - ; -} - -size_t UARTClass::write( const uint8_t uc_data ) -{ - return write(uc_data, true); -} - -size_t UARTClass::write( const uint8_t uc_data, const bool wait ) -{ - // Is the hardware currently busy? - if (((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) | - (_tx_buffer->_iTail != _tx_buffer->_iHead)) - { - // return immediately if we're not supposed to wait or buffer, - // meaning that the buffering is most probably done by the calling code - if ( !wait ) return 0; - - // If busy we buffer - unsigned int l = (_tx_buffer->_iHead + 1) % SERIAL_BUFFER_SIZE; - while (_tx_buffer->_iTail == l) - ; // Spin locks if we're about to overwrite the buffer. This continues once the data is sent - - _tx_buffer->_aucBuffer[_tx_buffer->_iHead] = uc_data; - _tx_buffer->_iHead = l; - // Make sure TX interrupt is enabled - _pUart->UART_IER = UART_IER_TXRDY; - } - else - { - // Bypass buffering and send character directly - _pUart->UART_THR = uc_data; - } - return 1; -} - -void UARTClass::IrqHandler( void ) -{ - uint32_t status = _pUart->UART_SR; - - // Did we receive data? - if ((status & UART_SR_RXRDY) == UART_SR_RXRDY) - _rx_buffer->store_char(_pUart->UART_RHR); - - // Do we need to keep sending data? - if ((status & UART_SR_TXRDY) == UART_SR_TXRDY) - { - if (_tx_buffer->_iTail != _tx_buffer->_iHead) { - _pUart->UART_THR = _tx_buffer->_aucBuffer[_tx_buffer->_iTail]; - _tx_buffer->_iTail = (unsigned int)(_tx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE; - } - else - { - // Mask off transmit interrupt so we don't get it anymore - _pUart->UART_IDR = UART_IDR_TXRDY; - } - } - - // Acknowledge errors - if ((status & UART_SR_OVRE) == UART_SR_OVRE || (status & UART_SR_FRAME) == UART_SR_FRAME) - { - // TODO: error reporting outside ISR - _pUart->UART_CR |= UART_CR_RSTSTA; - } -} - diff --git a/arduino_fixes/1.6.3/UARTClass.h b/arduino_fixes/1.6.3/UARTClass.h deleted file mode 100644 index c24228bf..00000000 --- a/arduino_fixes/1.6.3/UARTClass.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _UART_CLASS_ -#define _UART_CLASS_ - -#include "HardwareSerial.h" -#include "RingBuffer.h" - -// Includes Atmel CMSIS -#include - -#define SERIAL_8N1 UARTClass::Mode_8N1 -#define SERIAL_8E1 UARTClass::Mode_8E1 -#define SERIAL_8O1 UARTClass::Mode_8O1 -#define SERIAL_8M1 UARTClass::Mode_8M1 -#define SERIAL_8S1 UARTClass::Mode_8S1 - - -class UARTClass : public HardwareSerial -{ - public: - enum UARTModes { - Mode_8N1 = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_NO, - Mode_8E1 = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_EVEN, - Mode_8O1 = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_ODD, - Mode_8M1 = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_MARK, - Mode_8S1 = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_SPACE, - }; - 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 UARTModes config); - void end(void); - int available(void); - int availableForWrite(void); - int peek(void); - int read(void); - void flush(void); - size_t write(const uint8_t c); - size_t write(const uint8_t c, const bool wait); - using Print::write; // pull in write(str) and write(buf, size) from Print - - void setInterruptPriority(uint32_t priority); - uint32_t getInterruptPriority(); - - 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_ diff --git a/arduino_fixes/1_6_0.diff b/arduino_fixes/1_6_0.diff deleted file mode 100644 index 7ab4d958..00000000 --- a/arduino_fixes/1_6_0.diff +++ /dev/null @@ -1,32 +0,0 @@ ---- hardware/arduino/sam/cores/arduino/UARTClass.cpp 2015-02-08 21:23:24.000000000 +0100 -+++ UARTClass.cpp 2015-02-10 13:26:48.000000000 +0100 -@@ -144,10 +144,19 @@ - - size_t UARTClass::write( const uint8_t uc_data ) - { -+ return write(uc_data, true); -+} -+ -+size_t UARTClass::write( const uint8_t uc_data, const bool wait ) -+{ - // Is the hardware currently busy? - if (((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) | - (_tx_buffer->_iTail != _tx_buffer->_iHead)) - { -+ // return immediately if we're not supposed to wait or buffer, -+ // meaning that the buffering is most probably done by the calling code -+ if ( !wait ) return 0; -+ - // If busy we buffer - unsigned int l = (_tx_buffer->_iHead + 1) % SERIAL_BUFFER_SIZE; - while (_tx_buffer->_iTail == l) ---- hardware/arduino/sam/cores/arduino/UARTClass.h 2015-02-08 21:23:24.000000000 +0100 -+++ UARTClass.h 2015-02-10 13:26:43.000000000 +0100 -@@ -53,6 +53,7 @@ - int read(void); - void flush(void); - size_t write(const uint8_t c); -+ size_t write( const uint8_t c, const bool wait); - using Print::write; // pull in write(str) and write(buf, size) from Print - - void setInterruptPriority(uint32_t priority); diff --git a/arduino_fixes/1_6_3.diff b/arduino_fixes/1_6_3.diff deleted file mode 100644 index a8d08378..00000000 --- a/arduino_fixes/1_6_3.diff +++ /dev/null @@ -1,36 +0,0 @@ -diff -u -r hardware_orig/sam/1.6.3/cores/arduino/UARTClass.cpp hardware/sam/1.6.3/cores/arduino/UARTClass.cpp ---- hardware_orig/sam/1.6.3/cores/arduino/UARTClass.cpp 2015-03-27 11:53:25.000000000 +0200 -+++ hardware/sam/1.6.3/cores/arduino/UARTClass.cpp 2015-04-02 17:51:12.000000000 +0300 -@@ -144,10 +144,19 @@ - - size_t UARTClass::write( const uint8_t uc_data ) - { -+ return write(uc_data, true); -+} -+ -+size_t UARTClass::write( const uint8_t uc_data, const bool wait ) -+{ - // Is the hardware currently busy? - if (((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) | - (_tx_buffer->_iTail != _tx_buffer->_iHead)) - { -+ // return immediately if we're not supposed to wait or buffer, -+ // meaning that the buffering is most probably done by the calling code -+ if ( !wait ) return 0; -+ - // If busy we buffer - unsigned int l = (_tx_buffer->_iHead + 1) % SERIAL_BUFFER_SIZE; - while (_tx_buffer->_iTail == l) -Only in hardware/sam/1.6.3/cores/arduino: UARTClass.cpp.rej -diff -u -r hardware_orig/sam/1.6.3/cores/arduino/UARTClass.h hardware/sam/1.6.3/cores/arduino/UARTClass.h ---- hardware_orig/sam/1.6.3/cores/arduino/UARTClass.h 2015-03-27 11:53:25.000000000 +0200 -+++ hardware/sam/1.6.3/cores/arduino/UARTClass.h 2015-04-02 17:51:32.000000000 +0300 -@@ -53,6 +53,7 @@ - int read(void); - void flush(void); - size_t write(const uint8_t c); -+ size_t write(const uint8_t c, const bool wait); - using Print::write; // pull in write(str) and write(buf, size) from Print - - void setInterruptPriority(uint32_t priority); -Only in hardware/sam/1.6.3/cores/arduino: UARTClass.h.rej diff --git a/arduino_fixes/README.md b/arduino_fixes/README.md index 1e2341b0..65c0e622 100644 --- a/arduino_fixes/README.md +++ b/arduino_fixes/README.md @@ -4,56 +4,23 @@ Arduino fixes for the LinnStrument software In order to get better performance through the serial port, we had to improve the Arduino API for writing serial data. -This directory contains for files that need to be replaced in the -Arduino IDE. Note that there are different files for each IDE version: +We currently support Arduino IDE 1.6.5 with version 1.6.4 of the Arduino SAM boards. - * UARTClass.cpp - * UARTClass.h - -These are for 1.5.x only: - - * USARTClass.cpp - * USARTClass.h - -These need to be copied to the hardware/arduino/sam/cores/arduino/ directory. - -On MacOSX this is located inside the Arduino.app: - - Arduino.app/Contents/Resources/Java - -On the Terminal, this command should copy them all to the right location in -one go, make sure that the 'arduino_fixes' directory is your current directory -first: - -For 1.6.4: +Make sure to first install the required packages for the Arduino SAM Boards through +the Arduino IDE board manager from the Tools menu. - First install the required packages for the Arduino SAM Boards through the Arduino IDE board manager. - These packages will be located in your home directory, for instance on MacOSX: - $HOME/Library/Arduino15/packages/arduino/ +This readme's directory contains files that need to overwrite files in the Arduino IDE. - Now issue the following command: - cp -v 1.6.4/*ART* $HOME/Library/Arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/ - -For 1.6.3: - - First install the required packages for the Arduino SAM Boards through the Arduino IDE board manager. - These packages will be located in your home directory, for instance on MacOSX: - $HOME/Library/Arduino15/packages/arduino/ - - Now issue the following command: - cp -v 1.6.3/*ART* $HOME/Library/Arduino15/packages/arduino/hardware/sam/1.6.3/cores/arduino/ - -For 1.6.0: - - cp -v 1.6.0/*ART* /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/ - -For 1.5.7 and 1.5.8: + * UARTClass.cpp + * UARTClass.h - cp -v 1.5.7-1.5.8/*ART* /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/ +On MacOSX these need to be copied to this directory: +$HOME/Library/Arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/ -For 1.5.6-rc2: +Using the Terminal, the following command copies them all to the right location in one go. - cp -v 1.5.6-rc2/*ART* /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/ +Make sure that the 'arduino_fixes' directory is your current directory first: +cp -v 1.6.4/*ART* $HOME/Library/Arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/ If you don't want to use out improved serial write code, you can comment out the 'PATCHED_ARDUINO_SERIAL_WRITE' define in the linnstrument.ino file. This diff --git a/changelog.txt b/changelog.txt deleted file mode 100644 index b717f0e4..00000000 --- a/changelog.txt +++ /dev/null @@ -1,184 +0,0 @@ -v1.2.0: - - * Added support for configurable MIDI CC numbers for each split's CC Faders by holding down the - CC Faders cell in per-split settings. - * Added support for configuring LowRow CC numbers as well as a new Fader mode that is absolute and sticky. - * Added support for configuring Switch CC65 CC numbers by holding down the cell. - * Reworked custom Pitch Bend, Y-axis CC and Z-axis CC settings by removing them from row 5 and accessing them by - holding down the bottom-most cell. The value will now also be persisted when switching between other options. - * Changed split CC Faders to send out over the main channel only, instead of all the playing channels. - * Enabled playing notes on strummed split. - * Added open strings support for split strumming. - * Added support for automated octave switching similar to GeoSynth by pressing both octave down and up in the - switch/pedal assignments. - * New approach to pitch hold quantization so that it's more fine-grained and can be faster. It now also - exponentially corrects based on the movement speed instead of linearly, which feels more natural. - * Pitch hold quantization settings now behave consistently with the rest of the UI but being mutually - exclusive between medium and fast, and requiring two cells to be pressed for the slow setting. - * Improvements to low power mode to make it consume less, be more robust and slightly more responsive. - * Added detection for settings corruption that might occur when unplugging right at the moment when - LinnStrument is storing settings. A global reset will automatically be formed in this case with an - appropriate warning message. - * Support for User Firmware Mode, explained in user_firmware_mode.txt - * Support for Multidimensional Polyphonic Expression standard (MPE) in its current form (see http://bit.ly/mpe-spec) - * Made incoming MIDI messages on splits with ChannelPerRow mode active only highlight the exact cells that match - based on the channel information. - * Fixed bug where settings where not stored after doing a reset through the Global Settings Actions. - * Improved manufacturing test procedure. - -v1.1.2 - - * Removed delay on touch release so that accidental legato and note de-duplication aren't triggered anymore - * Allow MIDI CC 22 LED messages to turn a cell off explicitly by sending value 7 - -v1.1.1 - - * Fixed regressions in the calibration procedure from v1.1.0, please recalibrate after the v1.1.1 upgrade - * New approach to 'all settings' preset handling. Pressing an 'all settings' cell will now load the settings - that belong to it and holding down that cell for 2 seconds will store the current settings into that preset - cell. The current state of LinnStrument continues to exist outside of the 'all settings' presets, which have - now essentially become save locations. - * Audience messages can now be edited by keeping the corresponding cell pressed in Global Settings for - three seconds, sliding horizontally scrolls the text and sliding vertically loops through different - characters. The maximum message length is 30 characters and trailing spaces will be stripped. - * Note pad 4 in Global Pressure Sensitivity settings now toggles traditional aftertouch-like behavior where the - pressure only has an effect when a minimum amount of force has already been applied - * Made low-power mode at boot time persist across power cycles - * Added three different pitch quantize hold speeds, accessible through note pads 3 and 4 form the top in the - Per Split Pitch/X settings. When note pad 3 is active, quantize hold speed is medium; when note pad 4 is - also active, it's slow; when only note pad 4 is active, it's fast and when none are active, quantize hold is - turned off. - * Moved the hidden Reset On Release option from note pad 4 to note pad 5 in Per Split Pitch/X. - * Low-power mode can now be turned on/off through note pad 3 in the Global MIDI I/O settings (above MIDI Jacks) - * Fixed split select on preset and volume screen intervening with the actual settings. - * Made CC faders and Volume fader more reliable on very soft touches. - * Disabled control buttons except for switch 1 and switch 2 when notes are being played on the surface, this - prevents accidentally going into settings during a live performance - * When pressing down two fingers in the same column and sliding with a third finger on the same row as one of those - two pressed, the pitch sliding didn't work well. This is fixed. - * Reduced flickering during numeric parameter changes - * Improvements to changing numeric parameters through sliding - * Optimized the fonts that are used on the LinnStrument surface - * Quantize hold has been very slightly sped up - * Blink the middle root note when the octave is changed through switches while playing - * The performance display is always updated when octaves are changed through switches since some cells might fall - out of MIDI note range and be blank - * Fix for played note light getting stuck when switch octaves while cells are pressed - -v1.1.0 - - * Much reduced latency and jitter, making the LinnStrument wonderful for rapid runs and sharp attacks - * Improved velocity algorithm that measures actual velocity instead of instantaneous pressure - * Improved dynamic range and distribution in all three velocity sensitivity settings - * Added support for 4 presets of global and per-split settings, located at the right edge of the preset section - * Added support for poly pressure and channel pressure on the Y axis, to access it use the advanced CC configuration - and slide past number 127 - * Improved middle root note flashing so that it would always occur with the accent color even when disabled in - the note highlighting configuration - * Improved debouncing behavior to prevent occasional double note triggers at very low velocities - * Fix for poly pressure only being sent per-note in ChannelPerNote mode, other modes tied poly pressure to the - actual MIDI channel, meaning that for instance with ChannelPerRow it was impossible to have per-note poly pressure - on the same row - * Fixes to promo animation so that it would not start flickering after a while - * Added independent layers of lights, which are combined for the final display, allowing external light control - through MIDI to exist independently of the other lights - * Change foot pedal behavior to always be in hold mode for Sustain, CC65 and Arpeggiator, and always be in trigger - mode for Octave Up/Down and Alt Split - * Fixed octave/transpose display to update when the octave is changed through switches - * Removed flicker when moving the split point - -v1.0.9 - - * Added flashing the middle root note when exiting octave/transpose - * Prevent pitch bends where there are several touches for the same MIDI channel, this allows sliding over semi-tones - in One Channel mode without changing the pitch of other notes - * Add support for any bend range between 1-96 through the 5th option down in the Bend Range setting - * Fix for keeping notes highlighted in the arpeggiator when NotePerChannel is active and the same note is played - several times on different channels - * Regression fix for DIN MIDI output not working anymore - -v1.0.8 - - * Regression fix for scrolling audience messages not working anymore - -v1.0.7 - - * Noticeable playability improvements - * Reimplemented velocity and pressure sensitivity modes so that the low settings have more range and all the settings - have a smooth curve from 0 to 127 - * Low row now behaves exactly the same in slides as the main playing area, including quantization - * Allow CC faders to be 'played' with multiple fingers similar to the low row - * Performance optimizations and latency reduction - * Improved MIDI message output speed - * Fixed rare situation of switches being inadvertently pressed for a rectangular touch formations - -v1.0.6 - - * Tweaks to initial touch quantization so that immediate slides feel more natural - * Tweaks for sensor differences in November models - * Added indicator in global settings that lights red when the LinnStrument is not calibrated and green when the - calibration has been performed - * Added support for sending and retrieving the LinnStrument calibration and settings over serial so that the firmware - upgrade tool can restore everything after a firmware upgrade - -v1.0.5 - - * Slow pitch slides now don't have any jumps anymore that were due to the 1mm groove between the cells - * Improved the Notes Off feature, it now sends CC 120, as well as NoteOff for each note number and each channel, and - Sustain Off for each channel - * Changed 'focused cell' logic in One Channel mode, instead of doing pitch-slides and expression on the highest note, - it's now on the more recent one - * The global active split color is now displayed in split mode with the LED of the 'Split' switch - * Double-tapping the 'Split' switch now activates the other split, similar to selecting the split in - 'Per-Split Settings' - * Pedal and switch operations apart from Alt Split, can now act upon both splits when split mode is active by - pressing the cell above the Octave Dn setting - * Fix for foot switch assignments being reversed - * Fix for low-row bend not properly supporting multiple fingers for pitch-bend jumps anymore - * Fix for played cell lights sticking if identical notes are played on both splits - * Fix to reset operation so that calibration data is not lost - -v1.0.4 - - * Slides transition smoother from one cell to another, based on the pressure contribute of each cell - * Timbre/Y data changes are stabilized when sliding rapidly over the X axis - * Active note lights now stay lit when the same note value in a different position is pressed and released - * Added four additional Y calibration columns, these are needed to obtain precise and predictable timbre changes - everywhere - * Introduced easy-to-use one-click firmware updater tool - * Automatically activate calibration procedure after a firmware update - -v1.0.3 - - * added low-power mode for iOS bus-power use that is selected by holding down Octave/Transpose at startup - * added support for independent per-split pitch and light transposition - * increased octave transposition range to -5 and +5 - * made preset change slider less sensitive in the first three columns to make it easier to just go to previous/next - * fix for MIDI jacks selection not being persisted correctly across restarts - * dramatically improved detection of phantom touches, using a new algorithm that relies on calibration - * added advanced arbitrary CC support by using the 5th option down in the per-split Timbre/Y and Loudness/Z columns - -v1.0.2 - - * adding progressive smoothing to Y axis value for stability, low pressure has more smoothing - * relaxed restriction on left and right edge to allow full vibrato past the cell midpoints - * brought the main volume fader handling in-line with the CC faders, made sure that they're in sync for the sent - value of MIDI CC 7 - * added full control over the LinnStrument settings through MIDI NRPN messages, see midi.txt for details - * respond to CC 1-8 MIDI input to change the CC fader values for each split - * respond to Program Change MIDI input to change the preset values for each split - * added Windows driver for LinnStrument Programming Port, not signed though so there will be warning when installing - this driver - * regression fix where low row wouldn't be smoothly continuous anymore - -v1.0.1 - - * 20% pressure sensitivity increase, by normalizing to the top instead of to the middle - * allow for easier pitch slides without triggering new notes - * improved phantom touch detection to also function during slides - * changed default low row colors to yellow - * changed default arpeggiator speed to 16th notes - -v1.0.0 - - * Initial release \ No newline at end of file