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
#define CLOCK_H
#define F_CPU 16000000
#define F_CPU 20000000
#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 )
{
@ -106,13 +106,9 @@ void InOut::setPinDirection( Pin enmPin, Dir enmDir, bool bPullup /* = true */ )
setPinDirection( vpui8PortDir, ui8Pin, enmDir );
if( enmDir == Dir::D_IN && bPullup )
if( enmDir == Dir::D_IN )
{
writePin( vpui8PortOut, ui8Pin, true );
}
else if( enmDir == Dir::D_IN && !bPullup )
{
writePin( vpui8PortOut, ui8Pin, false );
writePin( vpui8PortOut, ui8Pin, bPullup );
}
}

View File

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

View File

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