From 04c1401a9cae7de83624bc0f1ae619d04e71073e Mon Sep 17 00:00:00 2001 From: BlackMark Date: Fri, 26 Jul 2019 18:50:26 +0200 Subject: [PATCH] Finished example implementation using new library --- io/io | 2 +- io/io.cppproj | 174 +++++++++++++++++++++++++++++++++----------------- io/main.cpp | 123 +++++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+), 58 deletions(-) diff --git a/io/io b/io/io index 7396831..4683686 160000 --- a/io/io +++ b/io/io @@ -1 +1 @@ -Subproject commit 7396831828b4fe4d01c3078e8a8decf0cf2b8132 +Subproject commit 468368692e65ce85fd208a6caa05ccc053905f3f diff --git a/io/io.cppproj b/io/io.cppproj index a7853c1..ef7506e 100644 --- a/io/io.cppproj +++ b/io/io.cppproj @@ -59,72 +59,132 @@ + + + + + + + + + + + + - -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 - True - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - True - True - True - True - -Wextra -std=c++17 - libm - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - 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 + True + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + True + True + True + True + -Wextra -std=c++17 + + + libm + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + + + 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 - True - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - True - True - True - True - -Wextra -std=c++17 - libm - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - DEBUG - Optimize (-O1) - Default (-g2) - 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 + True + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + True + True + True + True + -Wextra -std=c++17 + + + libm + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + + + DEBUG + + + Optimize (-O1) + Default (-g2) + + + DEBUG + + + Optimize (-O1) + Default (-g2) + Default (-Wa,-g) + diff --git a/io/main.cpp b/io/main.cpp index 3595112..b9deeb1 100644 --- a/io/main.cpp +++ b/io/main.cpp @@ -2,7 +2,130 @@ #include "io/io.hpp" +void pinUsage1() +{ + using namespace io; + + Pin pin1; + Pin 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; + using pin2_t = Pin; + + 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 port1; + Port 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; + using port2_t = Port; + + 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(); +} + int main() { + pinUsage1(); + pinUsage2(); + + portUsage1(); + portUsage2(); + + using namespace io; + + Pin led; + led.dir(Dir::OUT); + + while (true) { + led = true; + _delay_ms(500); + + led = false; + _delay_ms(500); + } + return 0; }