Replaced class variables with defines

This commit is contained in:
BlackMark 2016-05-19 22:13:06 +02:00
parent 6ac7d71530
commit 11ba283d0e
5 changed files with 178 additions and 154 deletions

View File

@ -7,7 +7,7 @@
#ifndef CLOCK_H
#define CLOCK_H
#define F_CPU 16000000
#define F_CPU 8000000
#include <util/delay.h>

View File

@ -30,11 +30,11 @@ void USART0::setRXState( bool bEnable )
{
if( bEnable )
{
*m_vui8pUCSRB |= ( 1 << m_ui8RXEN );
*m_vui8pUCSRB |= ( 1 << RXEN_D );
}
else
{
*m_vui8pUCSRB &= ~( 1 << m_ui8RXEN );
*m_vui8pUCSRB &= ~( 1 << RXEN_D );
}
}
@ -43,11 +43,11 @@ void USART0::setTXState( bool bEnable )
{
if( bEnable )
{
*m_vui8pUCSRB |= ( 1 << m_ui8TXEN );
*m_vui8pUCSRB |= ( 1 << TXEN_D );
}
else
{
*m_vui8pUCSRB &= ~( 1 << m_ui8TXEN );
*m_vui8pUCSRB &= ~( 1 << TXEN_D );
}
}
@ -80,28 +80,28 @@ void USART0::setDataBits( uint8_t ui8DataBits )
if( bZeroBit )
{
ui8UCSRC |= ( 1 << m_ui8UCSZ0 );
ui8UCSRC |= ( 1 << UCSZ0_D );
}
else
{
ui8UCSRC &= ~( 1 << m_ui8UCSZ0 );
ui8UCSRC &= ~( 1 << UCSZ0_D );
}
if( bOneBit )
{
ui8UCSRC |= ( 1 << m_ui8UCSZ1 );
ui8UCSRC |= ( 1 << UCSZ1_D );
}
else
{
ui8UCSRC &= ~( 1 << m_ui8UCSZ1 );
ui8UCSRC &= ~( 1 << UCSZ1_D );
}
*m_vui8pUCSRB &= ~( 1 << m_ui8UCSZ2 );
*m_vui8pUCSRB &= ~( 1 << UCSZ2_D );
}
else
{
ui8UCSRC |= ( 1 << m_ui8UCSZ1 ) | ( 1 << m_ui8UCSZ0 );
*m_vui8pUCSRB |= ( 1 << m_ui8UCSZ2 );
ui8UCSRC |= ( 1 << UCSZ1_D ) | ( 1 << UCSZ0_D );
*m_vui8pUCSRB |= ( 1 << UCSZ2_D );
}
setUCSRC( ui8UCSRC );
@ -114,16 +114,16 @@ void USART0::setParity( Parity enmParity )
if( enmParity == Parity::DISABLED )
{
ui8UCSRC &= ~( ( 1 << m_ui8UPM1 ) | ( 1 << m_ui8UPM0 ) );
ui8UCSRC &= ~( ( 1 << UPM1_D ) | ( 1 << UPM0_D ) );
}
else if( enmParity == Parity::ODD )
{
ui8UCSRC |= ( ( 1 << m_ui8UPM1 ) | ( 1 << m_ui8UPM0 ) );
ui8UCSRC |= ( ( 1 << UPM1_D ) | ( 1 << UPM0_D ) );
}
else if( enmParity == Parity::EVEN )
{
ui8UCSRC &= ~( ( 1 << m_ui8UPM0 ) );
ui8UCSRC |= ( ( 1 << m_ui8UPM1 ) );
ui8UCSRC &= ~( ( 1 << UPM0_D ) );
ui8UCSRC |= ( ( 1 << UPM1_D ) );
}
setUCSRC( ui8UCSRC );
@ -136,11 +136,11 @@ void USART0::setStopBits( StopBit enmStopBits )
if( enmStopBits == StopBit::ONE )
{
ui8UCSRC &= ~( 1 << m_ui8USBS );
ui8UCSRC &= ~( 1 << USBS_D );
}
else if( enmStopBits == StopBit::TWO )
{
ui8UCSRC |= ( 1 << m_ui8USBS );
ui8UCSRC |= ( 1 << USBS_D );
}
setUCSRC( ui8UCSRC );
@ -154,25 +154,25 @@ void USART0::setMode( Mode enmMode )
#ifdef USART_SPI
if( enmMode == Mode::ASYNCHRONOUS )
{
ui8UCSRC &= ~( ( 1 << m_ui8UMSEL1 ) | ( 1 << m_ui8UMSEL0 ) );
ui8UCSRC &= ~( ( 1 << UMSEL1_D ) | ( 1 << UMSEL0_D ) );
}
else if( enmMode == Mode::SYNCHRONOUS )
{
ui8UCSRC &= ~( 1 << m_ui8UMSEL1 );
ui8UCSRC |= ( 1 << m_ui8UMSEL0 );
ui8UCSRC &= ~( 1 << UMSEL1_D );
ui8UCSRC |= ( 1 << UMSEL0_D );
}
else if( enmMode == Mode::MASTERSPI )
{
ui8UCSRC |= ( ( 1 << m_ui8UMSEL1 ) | ( 1 << m_ui8UMSEL0 ) );
ui8UCSRC |= ( ( 1 << UMSEL1_D ) | ( 1 << UMSEL0_D ) );
}
#else
if( enmMode == Mode::ASYNCHRONOUS )
{
ui8UCSRC &= ~( 1 << m_ui8UMSEL );
ui8UCSRC &= ~( 1 << UMSEL_D );
}
else if( enmMode == Mode::SYNCHRONOUS )
{
ui8UCSRC |= ( 1 << m_ui8UMSEL );
ui8UCSRC |= ( 1 << UMSEL_D );
}
#endif
@ -193,17 +193,6 @@ USART0::USART0( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, St
m_vui8pUBRRH = &UBRRH;
m_vui8pUBRRL = &UBRRL;
m_vui8pUDR = &UDR;
m_ui8RXEN = RXEN;
m_ui8TXEN = TXEN;
m_ui8UCSZ0 = UCSZ0;
m_ui8UCSZ1 = UCSZ1;
m_ui8UCSZ2 = UCSZ2;
m_ui8UPM0 = UPM0;
m_ui8UPM1 = UPM1;
m_ui8USBS = USBS;
m_ui8RXC = RXC;
m_ui8UDRE = UDRE;
#endif
#ifndef USART_SHAREDIO
@ -213,24 +202,6 @@ USART0::USART0( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, St
m_vui8pUBRRH = &UBRR0H;
m_vui8pUBRRL = &UBRR0L;
m_vui8pUDR = &UDR0;
m_ui8RXEN = RXEN0;
m_ui8TXEN = TXEN0;
m_ui8UCSZ0 = UCSZ00;
m_ui8UCSZ1 = UCSZ01;
m_ui8UCSZ2 = UCSZ02;
m_ui8UPM0 = UPM00;
m_ui8UPM1 = UPM01;
m_ui8USBS = USBS0;
m_ui8RXC = RXC0;
m_ui8UDRE = UDRE0;
#endif
#ifdef USART_SPI
m_ui8UMSEL0 = UMSEL00;
m_ui8UMSEL1 = UMSEL01;
#else
m_ui8UMSEL = UMSEL;
#endif
init( ui32BaudRate, ui8DataBits, enmParity, enmStopBits, enmMode );
@ -263,7 +234,7 @@ bool USART0::receiveByte( unsigned char &chData, uint32_t ui32DelayMS )
do
{
if( ( *m_vui8pUCSRA & ( 1 << m_ui8RXC ) ) )
if( ( *m_vui8pUCSRA & ( 1 << RXC_D ) ) )
{
chData = *m_vui8pUDR;
return true;
@ -276,7 +247,7 @@ bool USART0::receiveByte( unsigned char &chData, uint32_t ui32DelayMS )
//////////////////////////////////////////////////////////////////////////
unsigned char USART0::receiveByte()
{
while( !( *m_vui8pUCSRA & ( 1 << m_ui8RXC ) ) );
while( !( *m_vui8pUCSRA & ( 1 << RXC_D ) ) );
return *m_vui8pUDR;
}
@ -431,7 +402,7 @@ void USART0::receive( long double &ldReceived )
//////////////////////////////////////////////////////////////////////////
void USART0::transmitByte( unsigned char byteData )
{
while( !( *m_vui8pUCSRA & ( 1 << m_ui8UDRE ) ) );
while( !( *m_vui8pUCSRA & ( 1 << UDRE_D ) ) );
*m_vui8pUDR = byteData;
}
@ -563,19 +534,6 @@ USART1::USART1( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, St
m_vui8pUBRRL = &UBRR1L;
m_vui8pUDR = &UDR1;
m_ui8RXEN = RXEN1;
m_ui8TXEN = TXEN1;
m_ui8UCSZ0 = UCSZ10;
m_ui8UCSZ1 = UCSZ11;
m_ui8UCSZ2 = UCSZ12;
m_ui8UPM0 = UPM10;
m_ui8UPM1 = UPM11;
m_ui8USBS = USBS1;
m_ui8RXC = RXC1;
m_ui8UDRE = UDRE1;
m_ui8UMSEL0 = UMSEL10;
m_ui8UMSEL1 = UMSEL11;
init( ui32BaudRate, ui8DataBits, enmParity, enmStopBits, enmMode );
}

View File

@ -36,7 +36,7 @@
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.31.0" />
</dependencies>
</framework-data>
</framework-data>
</AsfFrameworkConfig>
<avrtool>com.atmel.avrdbg.tool.stk500</avrtool>
<avrtoolserialnumber />
@ -60,6 +60,7 @@
<ToolchainSettings>
<AvrGccCpp>
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p"</avrgcc.common.Device>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
@ -67,25 +68,49 @@
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.directories.IncludePaths><ListValues><Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value></ListValues></avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>NDEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcccpp.compiler.directories.IncludePaths><ListValues><Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value></ListValues></avrgcccpp.compiler.directories.IncludePaths>
<avrgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>NDEBUG</Value>
</ListValues>
</avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value>
</ListValues>
</avrgcccpp.compiler.directories.IncludePaths>
<avrgcccpp.compiler.optimization.level>Optimize for size (-Os)</avrgcccpp.compiler.optimization.level>
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
<avrgcccpp.compiler.warnings.Pedantic>True</avrgcccpp.compiler.warnings.Pedantic>
<avrgcccpp.compiler.miscellaneous.OtherFlags>-Wextra -std=c++11</avrgcccpp.compiler.miscellaneous.OtherFlags>
<avrgcccpp.linker.libraries.Libraries><ListValues><Value>libm</Value></ListValues></avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.general.IncludePaths><ListValues><Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value></ListValues></avrgcccpp.assembler.general.IncludePaths>
<avrgcc.compiler.symbols.DefSymbols><ListValues><Value>NDEBUG</Value></ListValues></avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
<avrgcccpp.compiler.symbols.DefSymbols><ListValues><Value>NDEBUG</Value></ListValues></avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.optimization.level>Optimize for size (-Os)</avrgcccpp.compiler.optimization.level>
</AvrGccCpp>
<avrgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value>
</ListValues>
</avrgcccpp.assembler.general.IncludePaths>
</AvrGccCpp>
</ToolchainSettings>
<PreBuildEvent>echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i &gt; "$(MSBuildProjectDirectory)\avrdude.bat"</PreBuildEvent>
</PropertyGroup>
@ -93,6 +118,7 @@
<ToolchainSettings>
<AvrGccCpp>
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p"</avrgcc.common.Device>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
@ -100,28 +126,52 @@
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.directories.IncludePaths><ListValues><Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value></ListValues></avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcccpp.compiler.directories.IncludePaths><ListValues><Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value></ListValues></avrgcccpp.compiler.directories.IncludePaths>
<avrgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value>
</ListValues>
</avrgcccpp.compiler.directories.IncludePaths>
<avrgcccpp.compiler.optimization.level>Optimize (-O1)</avrgcccpp.compiler.optimization.level>
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
<avrgcccpp.compiler.warnings.Pedantic>True</avrgcccpp.compiler.warnings.Pedantic>
<avrgcccpp.compiler.miscellaneous.OtherFlags>-Wextra -std=c++11</avrgcccpp.compiler.miscellaneous.OtherFlags>
<avrgcccpp.linker.libraries.Libraries><ListValues><Value>libm</Value></ListValues></avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.general.IncludePaths><ListValues><Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value></ListValues></avrgcccpp.assembler.general.IncludePaths>
<avrgcc.compiler.symbols.DefSymbols><ListValues><Value>DEBUG</Value></ListValues></avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
<avrgcccpp.compiler.symbols.DefSymbols><ListValues><Value>DEBUG</Value></ListValues></avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.optimization.level>Optimize (-O1)</avrgcccpp.compiler.optimization.level>
<avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>
<avrgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include</Value>
</ListValues>
</avrgcccpp.assembler.general.IncludePaths>
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
</AvrGccCpp>
</AvrGccCpp>
</ToolchainSettings>
<PreBuildEvent>echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i &gt; "$(MSBuildProjectDirectory)\avrdude.bat"</PreBuildEvent>
</PropertyGroup>

View File

@ -26,6 +26,37 @@
#define SECOND_USART
#endif
#ifdef USART_SHAREDIO
#define RXEN_D RXEN
#define TXEN_D TXEN
#define UCSZ0_D UCSZ0
#define UCSZ1_D UCSZ1
#define UCSZ2_D UCSZ2
#define UPM0_D UPM0
#define UPM1_D UPM1
#define USBS_D USBS
#define RXC_D RXC
#define UDRE_D UDRE
#else
#define RXEN_D RXEN0
#define TXEN_D TXEN0
#define UCSZ0_D UCSZ00
#define UCSZ1_D UCSZ01
#define UCSZ2_D UCSZ02
#define UPM0_D UPM00
#define UPM1_D UPM01
#define USBS_D USBS0
#define RXC_D RXC0
#define UDRE_D UDRE0
#endif
#ifdef USART_SPI
#define UMSEL0_D UMSEL00
#define UMSEL1_D UMSEL01
#else
#define UMSEL_D UMSEL
#endif
class USART0
{
public:
@ -59,24 +90,6 @@ protected:
volatile uint8_t *m_vui8pUBRRL;
volatile uint8_t *m_vui8pUDR;
uint8_t m_ui8RXEN;
uint8_t m_ui8TXEN;
uint8_t m_ui8UCSZ0;
uint8_t m_ui8UCSZ1;
uint8_t m_ui8UCSZ2;
uint8_t m_ui8UPM0;
uint8_t m_ui8UPM1;
uint8_t m_ui8USBS;
uint8_t m_ui8RXC;
uint8_t m_ui8UDRE;
#ifdef USART_SPI
uint8_t m_ui8UMSEL0;
uint8_t m_ui8UMSEL1;
#else
uint8_t m_ui8UMSEL;
#endif
private:
uint8_t readUCSRC();
void setUCSRC( uint8_t ui8UCSRC );

View File

@ -28,6 +28,9 @@ int main()
cUSART << "sizeof( float ) = " << sizeof( float ) << "\r\n";
cUSART << "sizeof( double ) = " << sizeof( double ) << "\r\n";
cUSART << "sizeof( long double ) = " << sizeof( long double ) << "\r\n\r\n";
cUSART << "sizeof( void* ) = " << sizeof( void* ) << "\r\n";
cUSART << "sizeof( unsigned char* ) = " << sizeof( unsigned char* ) << "\r\n";
cUSART << "sizeof( unsigned int* ) = " << sizeof( unsigned int* ) << "\r\n\r\n";
while( true )
{