Made pullup setting mandatory in order to avoid errors and refactored some code

This commit is contained in:
BlackMark 2016-02-25 22:20:24 +01:00
parent e2e45becc0
commit 6b44b1868c
4 changed files with 65 additions and 75 deletions

View File

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

View File

@ -93,7 +93,7 @@ uint8_t InOut::getPin( Pin enmPin )
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void InOut::setPinDirection( Pin enmPin, Dir enmDir, bool bPullup /* = true */ ) void InOut::setPinDirection( Pin enmPin, Dir enmDir, bool bPullup )
{ {
if( enmPin == Pin::P_NONE ) if( enmPin == Pin::P_NONE )
{ {
@ -106,13 +106,9 @@ void InOut::setPinDirection( Pin enmPin, Dir enmDir, bool bPullup /* = true */ )
setPinDirection( vpui8PortDir, ui8Pin, enmDir ); setPinDirection( vpui8PortDir, ui8Pin, enmDir );
if( enmDir == Dir::D_IN && bPullup ) if( enmDir == Dir::D_IN )
{ {
writePin( vpui8PortOut, ui8Pin, true ); writePin( vpui8PortOut, ui8Pin, bPullup );
}
else if( enmDir == Dir::D_IN && !bPullup )
{
writePin( vpui8PortOut, ui8Pin, false );
} }
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright (c) by BlackMark 2015-2016 * Copyright (c) by BlackMark 2015-2016
* Date 05/01/2016 * Date 25/02/2016
* Version 2.3 * Version 2.4
*/ */
#ifndef INOUT_H #ifndef INOUT_H
@ -120,7 +120,7 @@ public:
static volatile uint8_t* getPort( Pin enmPin, Type enmType ); static volatile uint8_t* getPort( Pin enmPin, Type enmType );
static uint8_t getPin( Pin enmPin ); static uint8_t getPin( Pin enmPin );
static void setPinDirection( Pin enmPin, Dir enmDir, bool bPullup = true ); static void setPinDirection( Pin enmPin, Dir enmDir, bool bPullup );
static bool readPin( Pin enmPin ); static bool readPin( Pin enmPin );
static void writePin( Pin enmPin, bool bValue ); static void writePin( Pin enmPin, bool bValue );
@ -202,7 +202,7 @@ public:
void setPin( InOut::Pin enmPin ); void setPin( InOut::Pin enmPin );
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
inline void setDirection( InOut::Dir enmDir, bool bPullup = true ) inline void setDirection( InOut::Dir enmDir, bool bPullup )
{ {
if( !m_vpui8Dir || !m_vpui8Output ) if( !m_vpui8Dir || !m_vpui8Output )
{ {
@ -211,13 +211,9 @@ public:
InOut::setPinDirection( m_vpui8Dir, m_ui8Pin, enmDir ); InOut::setPinDirection( m_vpui8Dir, m_ui8Pin, enmDir );
if( enmDir == InOut::Dir::D_IN && bPullup ) if( enmDir == InOut::Dir::D_IN )
{ {
InOut::writePin( m_vpui8Output, m_ui8Pin, true ); InOut::writePin( m_vpui8Output, m_ui8Pin, bPullup );
}
else if( enmDir == InOut::Dir::D_IN && !bPullup )
{
InOut::writePin( m_vpui8Output, m_ui8Pin, false );
} }
} }
@ -261,7 +257,7 @@ public:
void setPort( InOut::Pin enmPortPin ); void setPort( InOut::Pin enmPortPin );
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
inline void setDirection( InOut::Dir enmDir, bool bPullup = true ) inline void setDirection( InOut::Dir enmDir, bool bPullup )
{ {
if( !m_vpui8Dir || !m_vpui8Output ) if( !m_vpui8Dir || !m_vpui8Output )
{ {
@ -270,13 +266,9 @@ public:
InOut::setPortDirection( m_vpui8Dir, enmDir ); InOut::setPortDirection( m_vpui8Dir, enmDir );
if( enmDir == InOut::Dir::D_IN && bPullup ) if( enmDir == InOut::Dir::D_IN )
{ {
InOut::writePort( m_vpui8Output, 0xFF ); InOut::writePort( m_vpui8Output, ( ( bPullup ) ? ( 0xFF ) : ( 0x00 ) ) );
}
else if( enmDir == InOut::Dir::D_IN && !bPullup )
{
InOut::writePort( m_vpui8Output, 0x00 );
} }
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright (c) by BlackMark 2015-2016 * Copyright (c) by BlackMark 2015-2016
* Date 02/01/2016 * Date 25/02/2016
* Version 1.2 * Version 1.3
*/ */
#include "Clock.h" #include "Clock.h"
@ -9,40 +9,42 @@
int main() int main()
{ {
InOutPin cPinRed( InOut::Pin::P_B5 ); InOutPin cLED( InOut::Pin::P_D7 );
InOutPin cPinGreen( InOut::Pin::P_B4 );
InOutPin cPinBlue( InOut::Pin::P_B3 );
cPinRed.setDirection( InOut::Dir::D_OUT ); cLED.setDirection( InOut::Dir::D_OUT, false );
cPinGreen.setDirection( InOut::Dir::D_OUT );
cPinBlue.setDirection( InOut::Dir::D_OUT );
cPinRed.write( false ); cLED.write( false );
cPinGreen.write( false );
cPinBlue.write( false );
while( true ) while( true )
{ {
cPinRed.write( true ); for( uint8_t i = 0; i < 3; ++i )
_delay_ms( 1000 ); {
cPinRed.write( false ); cLED.write( true );
_delay_ms( 100 );
cLED.write( false );
_delay_ms( 100 );
}
cPinGreen.write( true ); _delay_ms( 300 );
_delay_ms( 1000 );
cPinGreen.write( false );
cPinBlue.write( true ); for( uint8_t i = 0; i < 3; ++i )
_delay_ms( 1000 ); {
cPinBlue.write( false ); cLED.write( true );
_delay_ms( 300 );
cLED.write( false );
_delay_ms( 300 );
}
cPinRed.write( true ); _delay_ms( 100 );
cPinGreen.write( true );
cPinBlue.write( true ); for( uint8_t i = 0; i < 3; ++i )
_delay_ms( 5000 ); {
cLED.write( true );
_delay_ms( 100 );
cLED.write( false );
_delay_ms( 100 );
}
cPinRed.write( false );
cPinGreen.write( false );
cPinBlue.write( false );
_delay_ms( 1000 ); _delay_ms( 1000 );
} }