From 820a2813d1081aa531aaf044437a57466e5d839d Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 1 Feb 2020 22:15:49 +0100 Subject: [PATCH] Updated example to show virtual port usage --- io/io | 2 +- io/io.cppproj | 189 +++++++++++++++++++++++++++++++++----------------- io/main.cpp | 70 +++++++++++++++++++ 3 files changed, 196 insertions(+), 65 deletions(-) diff --git a/io/io b/io/io index 986ceef..a30b78f 160000 --- a/io/io +++ b/io/io @@ -1 +1 @@ -Subproject commit 986ceef65d1888e62ba759755def449915d3f9b9 +Subproject commit a30b78fb81acf3d6bc198848b44765a64f820b0b diff --git a/io/io.cppproj b/io/io.cppproj index 3a5560c..b278241 100644 --- a/io/io.cppproj +++ b/io/io.cppproj @@ -28,13 +28,14 @@ 0 0 - com.atmel.avrdbg.tool.jtagicemkii - 070000004699 + com.atmel.avrdbg.tool.stk500 + + 0x1E950F - 125000 + 0 ISP @@ -71,76 +72,136 @@ + + + + 125000 + + ISP + + com.atmel.avrdbg.tool.stk500 + + + STK500 + - -mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega328p" - True - True - True - True - False - True - True - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - True - True - True - True - -fno-threadsafe-statics -std=c11 - True - True - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - True - True - True - -fno-threadsafe-statics -Wextra -std=c++17 - libm - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - True - NDEBUG - Optimize for size (-Os) - NDEBUG - Optimize for size (-Os) - + -mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega328p" + True + True + True + True + False + True + True + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + True + True + True + True + -fno-threadsafe-statics -std=c11 + True + True + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + True + True + True + -fno-threadsafe-statics -Wextra -std=c++17 + + + libm + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + True + + + NDEBUG + + + Optimize for size (-Os) + + + NDEBUG + + + Optimize for size (-Os) + - -mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega328p" - True - True - True - True - False - True - True - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - True - True - True - True - -fno-threadsafe-statics -std=c11 - True - True - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - True - True - True - -fno-threadsafe-statics -Wextra -std=c++17 - libm - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - True - DEBUG - Optimize (-O1) - Maximum (-g3) - DEBUG - Optimize (-O1) - Default (-g2) - Default (-Wa,-g) - + -mmcu=atmega328p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega328p" + True + True + True + True + False + True + True + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + True + True + True + True + -fno-threadsafe-statics -std=c11 + True + True + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + True + True + True + -fno-threadsafe-statics -Wextra -std=c++17 + + + libm + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + True + + + DEBUG + + + Optimize (-O1) + Maximum (-g3) + + + DEBUG + + + Optimize (-O1) + Default (-g2) + Default (-Wa,-g) + diff --git a/io/main.cpp b/io/main.cpp index 997bded..a60306f 100644 --- a/io/main.cpp +++ b/io/main.cpp @@ -106,6 +106,73 @@ void portUsage2() port2_t::invert(); } +void virtualPortUsage1() +{ + using namespace io; + + VirtPort port1; + VirtPort 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; + using port2_t = VirtPort; + + 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 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(); @@ -114,6 +181,9 @@ int main() portUsage1(); portUsage2(); + virtualPortUsage1(); + virtualPortUsage2(); + using namespace io; Pin led;