Compare commits

...

24 Commits

Author SHA1 Message Date
314e1d20ab Updated compiler settings 2020-02-01 22:44:01 +01:00
b8ea05597f Changed toolchain to gcc v9 2020-02-01 22:38:15 +01:00
52d964d8e7 Updated submodule 2020-02-01 22:29:05 +01:00
820a2813d1 Updated example to show virtual port usage 2020-02-01 22:15:49 +01:00
afbb1d0423 Updated submodule and added MIT license file 2020-02-01 15:28:41 +01:00
f7753a0cf9 Updated project and submodule 2019-08-15 17:38:49 +02:00
f6613f662a Updated submodule 2019-08-10 13:59:00 +02:00
ac7a909c20 Fixed submodule url 2019-08-02 19:35:59 +02:00
69bca8c08f Updated submodule 2019-07-28 14:01:48 +02:00
5c0f29e452 Updated project file 2019-07-26 18:57:56 +02:00
d1da327558 Fixed outdated submodule path 2019-07-26 18:54:22 +02:00
04c1401a9c Finished example implementation using new library 2019-07-26 18:50:26 +02:00
e95f936321 Added clock config 2019-07-26 14:07:20 +02:00
9519f3a444 Included new library 2019-07-26 14:02:12 +02:00
b3c111dc89 Added io submodule 2019-07-26 13:56:52 +02:00
171aa72b2e Removed old example 2019-07-26 13:55:35 +02:00
a5761ab5db Added clang-format and removed submodule 2019-07-26 13:48:54 +02:00
fb6003eaa3 Adapted example to new shortened function names 2018-04-26 16:03:45 +02:00
08b69f70d7 Adapted example to new interface 2018-04-26 15:24:10 +02:00
b438aac91d Exported library to submodule branch and adapted example 2018-04-26 13:45:23 +02:00
79741c300b Merged changes from submodule branch 2016-10-29 16:47:56 +02:00
103e8698bf Changed Atmel Studio project files 2016-05-24 20:38:32 +02:00
9e1a0d8a2e Removed trailing newlines 2016-05-24 20:13:39 +02:00
065f21440c Renamed project to lowercase 2016-05-24 19:40:08 +02:00
14 changed files with 334 additions and 628 deletions

13
.clang-format Normal file
View File

@ -0,0 +1,13 @@
---
BasedOnStyle: LLVM
ColumnLimit: 120
IndentWidth: 4
TabWidth: 4
UseTab: ForIndentation
AlignEscapedNewlines: DontAlign
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: true
...

1
.gitattributes vendored
View File

@ -2,6 +2,7 @@
*.hpp eol=lf
*.c eol=lf
*.cpp eol=lf
.git* eol=lf
*.vcxproj* eol=crlf
*.cppproj eol=crlf
*.sln eol=crlf

11
.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
.vs
Release
Debug
*.componentinfo.xml
*.elf
*.o
*.hex
*.srec
*.eeprom
*.lss
*.map

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "io/io"]
path = io/io
url = git@git.blackmark.me:avr/io.git

View File

@ -1,14 +0,0 @@
/*
* Copyright (c) by BlackMark 2015
* Date 24/11/2015
* Version 1.1
*/
#ifndef CLOCK_H
#define CLOCK_H
#define F_CPU 20000000
#include <util/delay.h>
#endif

View File

@ -1,221 +0,0 @@
#include "InOut.h"
//////////////////////////////////////////////////////////////////////////
volatile uint8_t* InOut::getPort( Pin enmPin, Type enmType )
{
volatile uint8_t *vpui8Port = nullptr;
if( enmPin == Pin::P_NONE )
{
return vpui8Port;
}
uint8_t ui8Port = ( static_cast<uint16_t>( enmPin ) >> 4 ) & 0x0F;
switch( ui8Port )
{
case 0:
{
if( enmType == Type::T_PIN )
{
vpui8Port = PORT_PINA;
}
else if( enmType == Type::T_DDR )
{
vpui8Port = PORT_DDRA;
}
else if( enmType == Type::T_PORT )
{
vpui8Port = PORT_PORTA;
}
break;
}
case 1:
{
if( enmType == Type::T_PIN )
{
vpui8Port = PORT_PINB;
}
else if( enmType == Type::T_DDR )
{
vpui8Port = PORT_DDRB;
}
else if( enmType == Type::T_PORT )
{
vpui8Port = PORT_PORTB;
}
break;
}
case 2:
{
if( enmType == Type::T_PIN )
{
vpui8Port = PORT_PINC;
}
else if( enmType == Type::T_DDR )
{
vpui8Port = PORT_DDRC;
}
else if( enmType == Type::T_PORT )
{
vpui8Port = PORT_PORTC;
}
break;
}
case 3:
{
if( enmType == Type::T_PIN )
{
vpui8Port = PORT_PIND;
}
else if( enmType == Type::T_DDR )
{
vpui8Port = PORT_DDRD;
}
else if( enmType == Type::T_PORT )
{
vpui8Port = PORT_PORTD;
}
break;
}
}
return vpui8Port;
}
//////////////////////////////////////////////////////////////////////////
uint8_t InOut::getPin( Pin enmPin )
{
return static_cast<uint16_t>( enmPin ) & 0x0F;
}
//////////////////////////////////////////////////////////////////////////
void InOut::setPinDirection( Pin enmPin, Dir enmDir, bool bPullup )
{
if( enmPin == Pin::P_NONE )
{
return;
}
volatile uint8_t *vpui8PortDir = getPort( enmPin, Type::T_DDR );
volatile uint8_t *vpui8PortOut = getPort( enmPin, Type::T_PORT );
uint8_t ui8Pin = getPin( enmPin );
setPinDirection( vpui8PortDir, ui8Pin, enmDir );
if( enmDir == Dir::D_IN )
{
writePin( vpui8PortOut, ui8Pin, bPullup );
}
}
//////////////////////////////////////////////////////////////////////////
bool InOut::readPin( Pin enmPin )
{
if( enmPin == Pin::P_NONE )
{
return false;
}
volatile uint8_t *vpui8Port = getPort( enmPin, Type::T_PIN );
uint8_t ui8Pin = getPin( enmPin );
return readPin( vpui8Port, ui8Pin );
}
//////////////////////////////////////////////////////////////////////////
void InOut::writePin( Pin enmPin, bool bValue )
{
if( enmPin == Pin::P_NONE )
{
return;
}
volatile uint8_t *vpui8Port = getPort( enmPin, Type::T_PORT );
uint8_t ui8Pin = getPin( enmPin );
writePin( vpui8Port, ui8Pin, bValue );
}
//////////////////////////////////////////////////////////////////////////
uint8_t InOut::readPort( Pin enmPortPin )
{
if( enmPortPin == Pin::P_NONE )
{
return 0;
}
volatile uint8_t *vpui8Port = getPort( enmPortPin, Type::T_PIN );
return readPort( vpui8Port );
}
//////////////////////////////////////////////////////////////////////////
void InOut::writePort( Pin enmPortPin, uint8_t ui8Value )
{
if( enmPortPin == Pin::P_NONE )
{
return;
}
volatile uint8_t *vpui8Port = getPort( enmPortPin, Type::T_PORT );
writePort( vpui8Port, ui8Value );
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
InOutPin::InOutPin()
{
setPin( InOut::Pin::P_NONE );
}
//////////////////////////////////////////////////////////////////////////
InOutPin::InOutPin( InOut::Pin enmPin )
{
setPin( enmPin );
}
//////////////////////////////////////////////////////////////////////////
InOutPin::~InOutPin()
{}
//////////////////////////////////////////////////////////////////////////
void InOutPin::setPin( InOut::Pin enmPin )
{
m_vpui8Input = InOut::getPort( enmPin, InOut::Type::T_PIN );
m_vpui8Dir = InOut::getPort( enmPin, InOut::Type::T_DDR );
m_vpui8Output = InOut::getPort( enmPin, InOut::Type::T_PORT );
m_ui8Pin = InOut::getPin( enmPin );
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
InOutPort::InOutPort()
{
setPort( InOut::Pin::P_NONE );
}
//////////////////////////////////////////////////////////////////////////
InOutPort::InOutPort( InOut::Pin enmPin )
{
setPort( enmPin );
}
//////////////////////////////////////////////////////////////////////////
InOutPort::~InOutPort()
{}
//////////////////////////////////////////////////////////////////////////
void InOutPort::setPort( InOut::Pin enmPortPin )
{
m_vpui8Input = InOut::getPort( enmPortPin, InOut::Type::T_PIN );
m_vpui8Dir = InOut::getPort( enmPortPin, InOut::Type::T_DDR );
m_vpui8Output = InOut::getPort( enmPortPin, InOut::Type::T_PORT );
}

View File

@ -1,298 +0,0 @@
/*
* Copyright (c) by BlackMark 2015-2016
* Date 25/02/2016
* Version 2.4
*/
#ifndef INOUT_H
#define INOUT_H
#include <stdint.h>
#include <avr/io.h>
#define AVR_DIP40 defined (__AVR_ATmega32A__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega1284P__)
#define AVR_DIP28 defined (__AVR_ATmega8__) || defined (__AVR_ATmega168A__) || defined (__AVR_ATmega328P__)
#define AVR_DIP8 defined (__AVR_ATtiny13A__)
#if AVR_DIP40
#define PORT_PINA &PINA
#define PORT_DDRA &DDRA
#define PORT_PORTA &PORTA
#else
#define PORT_PINA nullptr
#define PORT_DDRA nullptr
#define PORT_PORTA nullptr
#endif
#if AVR_DIP40 || AVR_DIP28 || AVR_DIP8
#define PORT_PINB &PINB
#define PORT_DDRB &DDRB
#define PORT_PORTB &PORTB
#else
#define PORT_PINB nullptr
#define PORT_DDRB nullptr
#define PORT_PORTB nullptr
#endif
#if AVR_DIP40 || AVR_DIP28
#define PORT_PINC &PINC
#define PORT_DDRC &DDRC
#define PORT_PORTC &PORTC
#else
#define PORT_PINC nullptr
#define PORT_DDRC nullptr
#define PORT_PORTC nullptr
#endif
#if AVR_DIP40 || AVR_DIP28
#define PORT_PIND &PIND
#define PORT_DDRD &DDRD
#define PORT_PORTD &PORTD
#else
#define PORT_PIND nullptr
#define PORT_DDRD nullptr
#define PORT_PORTD nullptr
#endif
class InOut
{
public:
enum class Pin
{
P_NONE = -1,
#if AVR_DIP40
P_A0 = 0x00,
P_A1 = 0x01,
P_A2 = 0x02,
P_A3 = 0x03,
P_A4 = 0x04,
P_A5 = 0x05,
P_A6 = 0x06,
P_A7 = 0x07,
#endif
#if AVR_DIP40 || AVR_DIP28 || AVR_DIP8
P_B0 = 0x10,
P_B1 = 0x11,
P_B2 = 0x12,
P_B3 = 0x13,
P_B4 = 0x14,
P_B5 = 0x15,
#endif
#if AVR_DIP40 || AVR_DIP28
P_B6 = 0x16,
P_B7 = 0x17,
P_C0 = 0x20,
P_C1 = 0x21,
P_C2 = 0x22,
P_C3 = 0x23,
P_C4 = 0x24,
P_C5 = 0x25,
P_C6 = 0x26,
#endif
#if AVR_DIP40
P_C7 = 0x27,
#endif
#if AVR_DIP40 || AVR_DIP28
P_D0 = 0x30,
P_D1 = 0x31,
P_D2 = 0x32,
P_D3 = 0x33,
P_D4 = 0x34,
P_D5 = 0x35,
P_D6 = 0x36,
P_D7 = 0x37,
#endif
};
enum class Dir
{
D_IN = 0,
D_OUT = 1
};
enum class Type
{
T_PIN = 0,
T_DDR = 1,
T_PORT = 2
};
static volatile uint8_t* getPort( Pin enmPin, Type enmType );
static uint8_t getPin( Pin enmPin );
static void setPinDirection( Pin enmPin, Dir enmDir, bool bPullup );
static bool readPin( Pin enmPin );
static void writePin( Pin enmPin, bool bValue );
static uint8_t readPort( Pin enmPortPin );
static void writePort( Pin enmPortPin, uint8_t ui8Value );
//////////////////////////////////////////////////////////////////////////
static inline void setPinDirection( volatile uint8_t *vpui8Port, uint8_t ui8Pin, Dir enmDir )
{
if( enmDir == Dir::D_OUT )
{
*vpui8Port |= ( 1 << ui8Pin );
}
else
{
*vpui8Port &= ~( 1 << ui8Pin );
}
}
//////////////////////////////////////////////////////////////////////////
static inline bool readPin( volatile uint8_t *vpui8Port, uint8_t ui8Pin )
{
if( ( ( *vpui8Port ) >> ui8Pin ) & 1 )
{
return true;
}
return false;
}
//////////////////////////////////////////////////////////////////////////
static inline void writePin( volatile uint8_t *vpui8Port, uint8_t ui8Pin, bool bValue )
{
if( bValue )
{
*vpui8Port |= ( 1 << ui8Pin );
}
else
{
*vpui8Port &= ~( 1 << ui8Pin );
}
}
//////////////////////////////////////////////////////////////////////////
static inline void setPortDirection( volatile uint8_t *vpui8Port, Dir enmDir )
{
*vpui8Port = ( ( enmDir == InOut::Dir::D_OUT ) ? ( 0xFF ) : ( 0x00 ) );
}
//////////////////////////////////////////////////////////////////////////
static inline uint8_t readPort( volatile uint8_t *vpui8Port )
{
return *vpui8Port;
}
//////////////////////////////////////////////////////////////////////////
static inline void writePort( volatile uint8_t *vpui8Port, uint8_t ui8Value )
{
*vpui8Port = ui8Value;
}
};
//////////////////////////////////////////////////////////////////////////
class InOutPin
{
private:
volatile uint8_t *m_vpui8Input;
volatile uint8_t *m_vpui8Dir;
volatile uint8_t *m_vpui8Output;
uint8_t m_ui8Pin;
public:
InOutPin();
InOutPin( InOut::Pin enmPin );
~InOutPin();
void setPin( InOut::Pin enmPin );
//////////////////////////////////////////////////////////////////////////
inline void setDirection( InOut::Dir enmDir, bool bPullup )
{
if( !m_vpui8Dir || !m_vpui8Output )
{
return;
}
InOut::setPinDirection( m_vpui8Dir, m_ui8Pin, enmDir );
if( enmDir == InOut::Dir::D_IN )
{
InOut::writePin( m_vpui8Output, m_ui8Pin, bPullup );
}
}
//////////////////////////////////////////////////////////////////////////
inline bool read()
{
if( !m_vpui8Input )
{
return false;
}
return InOut::readPin( m_vpui8Input, m_ui8Pin );
}
//////////////////////////////////////////////////////////////////////////
inline void write( bool bValue )
{
if( !m_vpui8Output )
{
return;
}
InOut::writePin( m_vpui8Output, m_ui8Pin, bValue );
}
};
//////////////////////////////////////////////////////////////////////////
class InOutPort
{
private:
volatile uint8_t *m_vpui8Input;
volatile uint8_t *m_vpui8Dir;
volatile uint8_t *m_vpui8Output;
public:
InOutPort();
InOutPort( InOut::Pin enmPortPin );
~InOutPort();
void setPort( InOut::Pin enmPortPin );
//////////////////////////////////////////////////////////////////////////
inline void setDirection( InOut::Dir enmDir, bool bPullup )
{
if( !m_vpui8Dir || !m_vpui8Output )
{
return;
}
InOut::setPortDirection( m_vpui8Dir, enmDir );
if( enmDir == InOut::Dir::D_IN )
{
InOut::writePort( m_vpui8Output, ( ( bPullup ) ? ( 0xFF ) : ( 0x00 ) ) );
}
}
//////////////////////////////////////////////////////////////////////////
inline uint8_t read()
{
if( !m_vpui8Input )
{
return 0;
}
return InOut::readPort( m_vpui8Input );
}
//////////////////////////////////////////////////////////////////////////
inline void write( uint8_t ui8Value )
{
if( !m_vpui8Output )
{
return;
}
InOut::writePort( m_vpui8Output, ui8Value );
}
};
#endif

View File

@ -1,52 +0,0 @@
/*
* Copyright (c) by BlackMark 2015-2016
* Date 25/02/2016
* Version 1.3
*/
#include "Clock.h"
#include "InOut.h"
int main()
{
InOutPin cLED( InOut::Pin::P_D7 );
cLED.setDirection( InOut::Dir::D_OUT, false );
cLED.write( false );
while( true )
{
for( uint8_t i = 0; i < 3; ++i )
{
cLED.write( true );
_delay_ms( 100 );
cLED.write( false );
_delay_ms( 100 );
}
_delay_ms( 300 );
for( uint8_t i = 0; i < 3; ++i )
{
cLED.write( true );
_delay_ms( 300 );
cLED.write( false );
_delay_ms( 300 );
}
_delay_ms( 100 );
for( uint8_t i = 0; i < 3; ++i )
{
cLED.write( true );
_delay_ms( 100 );
cLED.write( false );
_delay_ms( 100 );
}
_delay_ms( 1000 );
}
return 0;
}

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 BlackMark
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Atmel Studio Solution File, Format Version 11.00
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "InOut", "InOut\InOut.cppproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "io", "io\io.cppproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

4
io/clock.hpp Normal file
View File

@ -0,0 +1,4 @@
#pragma once
#define F_CPU 16000000
#include <util/delay.h>

1
io/io Submodule

@ -0,0 +1 @@
Subproject commit 80de36ee7ee3e6b0842d5eaee81d54062cb496b2

View File

@ -12,10 +12,10 @@
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
<OutputFileExtension>.elf</OutputFileExtension>
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
<AssemblyName>InOut</AssemblyName>
<Name>InOut</Name>
<RootNamespace>InOut</RootNamespace>
<ToolchainFlavour>Native</ToolchainFlavour>
<AssemblyName>io</AssemblyName>
<Name>io</Name>
<RootNamespace>io</RootNamespace>
<ToolchainFlavour>avr-g++-9.1.0</ToolchainFlavour>
<KeepTimersRunning>true</KeepTimersRunning>
<OverrideVtor>false</OverrideVtor>
<CacheFlash>true</CacheFlash>
@ -25,23 +25,53 @@
<preserveEEPROM>true</preserveEEPROM>
<OverrideVtorValue>exception_table</OverrideVtorValue>
<BootSegment>2</BootSegment>
<ResetRule>0</ResetRule>
<eraseonlaunchrule>0</eraseonlaunchrule>
<EraseKey />
<avrtool>com.atmel.avrdbg.tool.stk500</avrtool>
<avrtoolserialnumber>
</avrtoolserialnumber>
<avrdeviceexpectedsignature>0x1E950F</avrdeviceexpectedsignature>
<com_atmel_avrdbg_tool_jtagicemkii>
<ToolOptions>
<InterfaceProperties>
<IspClock>0</IspClock>
</InterfaceProperties>
<InterfaceName>ISP</InterfaceName>
</ToolOptions>
<ToolType>com.atmel.avrdbg.tool.jtagicemkii</ToolType>
<ToolNumber>070000004699</ToolNumber>
<ToolName>JTAGICE mkII</ToolName>
</com_atmel_avrdbg_tool_jtagicemkii>
<avrtoolinterface>ISP</avrtoolinterface>
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
<AAFDebugger>
<AAFDebugFiles>
<DebugFile>
<path>\Debug\io.lss</path>
<AAFSetting>
<Label>Lss Files</Label>
<Extention>.lss</Extention>
<Regex>^\s*(?&lt;address&gt;[a-f0-9]*):\s*.*$</Regex>
<DebugEnabled>true</DebugEnabled>
<RegexGroups>address</RegexGroups>
<DebuggerExpression>$pc</DebuggerExpression>
</AAFSetting>
</DebugFile>
</AAFDebugFiles>
</AAFDebugger>
<AsfFrameworkConfig>
<framework-data xmlns="">
<options />
<configurations />
<files />
<documentation help="" />
<offline-documentation help="" />
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.29.0" />
</dependencies>
</framework-data>
<options />
<configurations />
<files />
<documentation help="" />
<offline-documentation help="" />
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.46.0" />
</dependencies>
</framework-data>
</AsfFrameworkConfig>
<avrtool>
</avrtool>
<avrtoolserialnumber />
<avrdeviceexpectedsignature>0x1E9705</avrdeviceexpectedsignature>
<com_atmel_avrdbg_tool_stk500>
<ToolOptions>
<InterfaceProperties>
@ -54,14 +84,11 @@
</ToolNumber>
<ToolName>STK500</ToolName>
</com_atmel_avrdbg_tool_stk500>
<avrtoolinterface>ISP</avrtoolinterface>
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings>
<AvrGccCpp>
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\gcc\dev\atmega328p"</avrgcc.common.Device>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega328p"</avrgcc.common.Device>
<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>
@ -76,13 +103,15 @@
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\include</Value>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\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>
<avrgcc.compiler.warnings.ExtraWarnings>True</avrgcc.compiler.warnings.ExtraWarnings>
<avrgcc.compiler.warnings.Pedantic>True</avrgcc.compiler.warnings.Pedantic>
<avrgcc.compiler.miscellaneous.OtherFlags>-fno-threadsafe-statics -std=c11</avrgcc.compiler.miscellaneous.OtherFlags>
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcccpp.compiler.symbols.DefSymbols>
@ -92,29 +121,31 @@
</avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\include</Value>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\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.compiler.miscellaneous.OtherFlags>-fno-threadsafe-statics -Wextra -std=c++17</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.3.300\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>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings>
<AvrGccCpp>
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\gcc\dev\atmega328p"</avrgcc.common.Device>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega328p"</avrgcc.common.Device>
<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>
@ -129,14 +160,16 @@
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\include</Value>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\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.optimization.DebugLevel>Maximum (-g3)</avrgcc.compiler.optimization.DebugLevel>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.compiler.warnings.ExtraWarnings>True</avrgcc.compiler.warnings.ExtraWarnings>
<avrgcc.compiler.warnings.Pedantic>True</avrgcc.compiler.warnings.Pedantic>
<avrgcc.compiler.miscellaneous.OtherFlags>-fno-threadsafe-statics -std=c11</avrgcc.compiler.miscellaneous.OtherFlags>
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcccpp.compiler.symbols.DefSymbols>
@ -146,39 +179,42 @@
</avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.0.91\include</Value>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\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.optimization.DebugLevel>Maximum (-g3)</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.compiler.miscellaneous.OtherFlags>-fno-threadsafe-statics -Wextra -std=c++17</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.3.300\include</Value>
</ListValues>
</avrgcccpp.assembler.general.IncludePaths>
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
</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>
<ItemGroup>
<Compile Include="Clock.h">
<Compile Include="clock.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="InOut.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="InOut.h">
<Compile Include="io\io.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="main.cpp">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="io" />
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>

201
io/main.cpp Normal file
View File

@ -0,0 +1,201 @@
#include "clock.hpp"
#include "io/io.hpp"
void pinUsage1()
{
using namespace io;
Pin<P::B0> pin1;
Pin<P::B5> pin2;
pin1.dir(Dir::IN);
pin1.pullup(false);
pin2.dir(Dir::OUT);
pin2.write(false);
pin2 = pin1;
if (pin1) {
pin1.dir(Dir::OUT);
pin1 = true;
} else {
pin1.dir(Dir::OUT);
pin2 = false;
}
pin2.toggle();
}
void pinUsage2()
{
using namespace io;
using pin1_t = Pin<P::B0>;
using pin2_t = Pin<P::B5>;
pin1_t::dir(Dir::IN);
pin1_t::pullup(false);
pin2_t::dir(Dir::OUT);
pin2_t::write(false);
pin2_t::write(pin1_t::read());
if (pin1_t::read()) {
pin1_t::dir(Dir::OUT);
pin1_t::write(true);
} else {
pin1_t::dir(Dir::OUT);
pin2_t::write(false);
}
pin2_t::toggle();
}
void portUsage1()
{
using namespace io;
Port<Bus::D> port1;
Port<Bus::B> port2;
port1.dir(Dir::IN);
port1.pullup(false);
port2.dir(Dir::OUT);
port2.write(0x00);
port2 = port1;
if (port1) {
port1.dir(Dir::OUT);
port1 = 0b10101010;
} else {
port1.dir(Dir::OUT);
port1 = 0b01010101;
}
port2.invert();
}
void portUsage2()
{
using namespace io;
using port1_t = Port<Bus::D>;
using port2_t = Port<Bus::B>;
port1_t::dir(Dir::IN);
port1_t::pullup(false);
port2_t::dir(Dir::OUT);
port2_t::write(0x00);
port2_t::write(port1_t::read());
if (port1_t::read()) {
port1_t::dir(Dir::OUT);
port1_t::write(0b10101010);
} else {
port1_t::dir(Dir::OUT);
port1_t::write(0b01010101);
}
port2_t::invert();
}
void virtualPortUsage1()
{
using namespace io;
VirtPort<P::B0, P::B1, P::B3, P::B4> port1;
VirtPort<P::C5, P::C4, P::C3, P::C2, P::C1, P::C0, P::D0, P::D1> port2;
port1.dir(Dir::IN);
port1.pullup(false);
port2.dir(Dir::OUT);
port2.write(0x00);
port2 = port1;
if (port1) {
port1.dir(Dir::OUT);
port1 = 0b10101010;
} else {
port1.dir(Dir::OUT);
port1 = 0b01010101;
}
port2.invert();
}
void virtualPortUsage2()
{
using namespace io;
using port1_t = VirtPort<P::B0, P::B1, P::B3, P::B4>;
using port2_t = VirtPort<P::C5, P::C4, P::C3, P::C2, P::C1, P::C0, P::D0, P::D1>;
port1_t::dir(Dir::IN);
port1_t::pullup(false);
port2_t::dir(Dir::OUT);
port2_t::write(0x00);
port2_t::write(port1_t::read());
if (port1_t::read()) {
port1_t::dir(Dir::OUT);
port1_t::write(0b10101010);
} else {
port1_t::dir(Dir::OUT);
port1_t::write(0b01010101);
}
port2_t::invert();
}
void outputByte(uint8_t value)
{
using namespace io;
Pin<P::B5> led;
led.dir(Dir::OUT);
for (uint16_t i = 0; i < value; ++i) {
led = true;
_delay_ms(250);
led = false;
_delay_ms(250);
}
}
int main()
{
pinUsage1();
pinUsage2();
portUsage1();
portUsage2();
virtualPortUsage1();
virtualPortUsage2();
using namespace io;
Pin<P::B5> led;
led.dir(Dir::OUT);
while (true) {
led = true;
_delay_ms(500);
led = false;
_delay_ms(500);
}
return 0;
}