Skip to content

Commit

Permalink
[architecture] std::chrono compatible system_clock and high_resolutio…
Browse files Browse the repository at this point in the history
…n_clock
  • Loading branch information
salkinium committed Apr 3, 2020
1 parent 1ac1130 commit 778951a
Show file tree
Hide file tree
Showing 385 changed files with 2,263 additions and 2,312 deletions.
1 change: 0 additions & 1 deletion examples/arduino_uno/basic/analog_read_serial/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// Inspired by: http://arduino.cc/en/Tutorial/AnalogReadSerial

#include <modm/board.hpp>
using namespace modm::literals;

int
main()
Expand Down
4 changes: 2 additions & 2 deletions examples/arduino_uno/basic/blink/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ main()
while (true)
{
LedD13::set();
modm::delayMilliseconds(1000);
modm::delay(1s);
LedD13::reset();
modm::delayMilliseconds(1000);
modm::delay(1s);
}
}
1 change: 0 additions & 1 deletion examples/arduino_uno/basic/read_analog_voltage/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// Inspired by: http://arduino.cc/en/Tutorial/ReadAnalogVoltage

#include <modm/board.hpp>
using namespace modm::literals;

int
main()
Expand Down
9 changes: 5 additions & 4 deletions examples/avr/1-wire/ds18b20/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using namespace modm::platform;
using namespace modm::literals;
using namespace std::chrono_literals;

using OneWirePin = GpioC2;
using OneWireMaster = BitBangOneWireMaster<OneWirePin>;
Expand All @@ -35,14 +36,14 @@ main()
modm::IOStream output(device);

output << "Welcome" << modm::endl;
modm::delayMilliseconds(100);
modm::delay(100ms);

OneWireMaster::connect<OneWirePin::BitBang>();
OneWireMaster::initialize<SystemClock>();

if (!OneWireMaster::touchReset()) {
output << "No devices found!" << modm::endl;
modm::delayMilliseconds(100);
modm::delay(100ms);
while (true) {
// wait forever
}
Expand All @@ -58,7 +59,7 @@ main()
output << rom[i];
}
output << modm::ascii << modm::endl;
modm::delayMilliseconds(100);
modm::delay(100ms);
}
output << "finished!" << modm::endl;

Expand All @@ -74,7 +75,7 @@ main()
int16_t temperature = ds18b20.readTemperature();

output << "Temperature: " << temperature << modm::endl;
modm::delayMilliseconds(100);
modm::delay(100ms);

ds18b20.startConversion();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/avr/1-wire/ds18b20/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<library>
<options>
<option name="modm:target">atmega644-20au</option>
<option name="modm:platform:clock:f_cpu">14745600</option>
<option name="modm:platform:core:f_cpu">14745600</option>
<option name="modm:build:build.path">../../../../build/avr/1-wire/ds18b20</option>
</options>
<modules>
Expand Down
3 changes: 2 additions & 1 deletion examples/avr/adc/basic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using namespace modm::platform;
using namespace modm::literals;
using namespace std::chrono_literals;

int
main()
Expand Down Expand Up @@ -62,7 +63,7 @@ main()
// receiving the UART output on a PC. If you want to do further
// calculations with the results instead of sending it
// you do not need this.
modm::delayMilliseconds(300);
modm::delay(300ms);

// restart the conversion
Adc::setChannel(0);
Expand Down
2 changes: 1 addition & 1 deletion examples/avr/adc/basic/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<library>
<options>
<option name="modm:target">atmega644-20au</option>
<option name="modm:platform:clock:f_cpu">14745600</option>
<option name="modm:platform:core:f_cpu">14745600</option>
<option name="modm:build:build.path">../../../../build/avr/adc/basic</option>
</options>
<modules>
Expand Down
5 changes: 3 additions & 2 deletions examples/avr/adc/oversample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using namespace modm::platform;
using namespace modm::literals;
using namespace std::chrono_literals;

// Create a new UART object

Expand All @@ -32,7 +33,7 @@ typedef modm::AdcSampler< AdcInterrupt, 3, 32 > sensors;
// the results are up to 16 bit wide
sensors::DataType sensorData[3];

modm::ShortTimeout timeout(100);
modm::ShortTimeout timeout(100ms);

int
main()
Expand Down Expand Up @@ -67,7 +68,7 @@ main()

// start another readout
sensors::startReadout();
timeout.restart(200);
timeout.restart(200ms);
}
}
}
2 changes: 1 addition & 1 deletion examples/avr/adc/oversample/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<library>
<options>
<option name="modm:target">atmega644-20au</option>
<option name="modm:platform:clock:f_cpu">14745600</option>
<option name="modm:platform:core:f_cpu">14745600</option>
<option name="modm:build:build.path">../../../../build/avr/adc/oversample</option>
</options>
<modules>
Expand Down
3 changes: 2 additions & 1 deletion examples/avr/app_can2usb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <modm/debug/logger.hpp>

using namespace modm::platform;
using namespace std::chrono_literals;

// LED1 Status
typedef GpioOutputD7 LedStatus;
Expand Down Expand Up @@ -110,7 +111,7 @@ main()

while (true)
{
modm::delayMilliseconds(100);
modm::delay(100ms);
LedStatus::toggle();
LedRxHigh::toggle();
LedRxLow::toggle();
Expand Down
2 changes: 1 addition & 1 deletion examples/avr/app_can2usb/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<library>
<options>
<option name="modm:target">at90can128-16au</option>
<option name="modm:platform:clock:f_cpu">16000000</option>
<option name="modm:platform:core:f_cpu">16000000</option>
<option name="modm:build:build.path">../../../build/avr/app_can2usb</option>
</options>
<modules>
Expand Down
6 changes: 3 additions & 3 deletions examples/avr/assert/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ modm_abandon(const modm::AssertionInfo &info)
Leds::setOutput();
while (true) {
Leds::write(1);
modm::delayMilliseconds(20);
modm::delay(20ms);
Leds::write(0);
modm::delayMilliseconds(180);
modm::delay(180ms);
}
}

Expand Down Expand Up @@ -87,6 +87,6 @@ int main()
while (true)
{
LedD13::toggle();
modm::delayMilliseconds(500);
modm::delay(500ms);
}
}
1 change: 0 additions & 1 deletion examples/avr/block_device_mirror/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <stdlib.h>

using namespace modm::platform;
typedef modm::platform::SystemClock clock;

// Create a new UART object and configure it to a baudrate of 115200
Uart0 uart;
Expand Down
2 changes: 1 addition & 1 deletion examples/avr/block_device_mirror/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<library>
<options>
<option name="modm:target">atmega644-20au</option>
<option name="modm:platform:clock:f_cpu">14745600</option>
<option name="modm:platform:core:f_cpu">14745600</option>
<option name="modm:build:build.path">../../../build/avr/block_device_mirror</option>
<option name="modm:io:with_printf">True</option>
</options>
Expand Down
2 changes: 1 addition & 1 deletion examples/avr/can/mcp2515/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<library>
<options>
<option name="modm:target">atmega644-20au</option>
<option name="modm:platform:clock:f_cpu">14745600</option>
<option name="modm:platform:core:f_cpu">14745600</option>
<option name="modm:build:build.path">../../../../build/avr/can/mcp2515</option>
<option name="modm:io:with_printf">True</option>
</options>
Expand Down
19 changes: 3 additions & 16 deletions examples/avr/can/mcp2515_uart/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
// ----------------------------------------------------------------------------

#include <modm/platform.hpp>
#include <modm/architecture/interface/interrupt.hpp>

#include <modm/driver/can/mcp2515.hpp>
#include <modm/processing/timer.hpp>

using namespace modm::platform;
using namespace modm::literals;
using namespace std::chrono_literals;

typedef GpioOutputB0 LedGreen;
typedef GpioOutputB1 LedRed;
Expand Down Expand Up @@ -49,25 +48,13 @@ FLASH_STORAGE(uint8_t canFilter[]) =
MCP2515_FILTER_EXTENDED(0), // Mask 1
};

// timer interrupt routine
MODM_ISR(TIMER2_COMPA)
{
modm::Clock::increment();
}

int
main()
{
SystemClock::enable();
LedGreen::setOutput(modm::Gpio::High);
LedRed::setOutput(modm::Gpio::Low);

// timer initialization
// compare-match-interrupt every 1 ms at 14.7456 MHz
TCCR2A = (1 << WGM21);
TCCR2B = (1 << CS22);
TIMSK2 = (1 << OCIE2A);
OCR2A = 230;

Uart0::connect<GpioD1::Txd, GpioD0::Rxd>();
Uart0::initialize<SystemClock, 115200_Bd>();

Expand Down Expand Up @@ -99,7 +86,7 @@ main()

mcp2515.sendMessage(message);

modm::ShortPeriodicTimer timer(200);
modm::ShortPeriodicTimer timer(200ms);
while (true)
{
if (mcp2515.isMessageAvailable())
Expand Down
2 changes: 1 addition & 1 deletion examples/avr/can/mcp2515_uart/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<library>
<options>
<option name="modm:target">atmega644-20au</option>
<option name="modm:platform:clock:f_cpu">14745600</option>
<option name="modm:platform:core:f_cpu">14745600</option>
<option name="modm:build:build.path">../../../../build/avr/can/mcp2515_uart</option>
<option name="modm:io:with_printf">True</option>
</options>
Expand Down
32 changes: 11 additions & 21 deletions examples/avr/display/dogm128/benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using namespace modm::platform;
using namespace modm::literals;
using namespace std::chrono_literals;


namespace led
Expand All @@ -46,15 +47,11 @@ modm::DogM128< lcd::SPI, lcd::Cs, lcd::A0, lcd::Reset, true > display;

using namespace modm::glcd;

// timer interrupt routine
MODM_ISR(TIMER2_COMPA)
{
modm::Clock::increment();
}

void
setup()
{
SystemClock::enable();

led::R::set();
led::G::set();
led::B::reset();
Expand All @@ -66,13 +63,6 @@ setup()
lcd::SPI::connect<lcd::Sck::BitBang, lcd::Mosi::BitBang>();
lcd::SPI::initialize<SystemClock, 2_MHz>();

// timer initialization
// compare-match-interrupt every 1 ms at 14.7456 MHz
TCCR2A = (1 << WGM21);
TCCR2B = (1 << CS22);
TIMSK2 = (1 << OCIE2A);
OCR2A = 230;

// enable interrupts
enableInterrupts();

Expand All @@ -87,7 +77,7 @@ introScreen()
modm::accessor::asFlash(bitmap::rca_logo_128x64));
display.update();

modm::delayMilliseconds(2000);
modm::delay(2s);

display.clear();

Expand All @@ -108,28 +98,28 @@ introScreen()

display.update();

modm::delayMilliseconds(1000);
modm::delay(1s);
display.setCursor(Point(40, 55));

display << "5 ";
display.update();
modm::delayMilliseconds(1000);
modm::delay(1s);

display << "4 ";
display.update();
modm::delayMilliseconds(1000);
modm::delay(1s);

display << "3 ";
display.update();
modm::delayMilliseconds(1000);
modm::delay(1s);

display << "2 ";
display.update();
modm::delayMilliseconds(1000);
modm::delay(1s);

display << "1";
display.update();
modm::delayMilliseconds(1000);
modm::delay(1s);

display.clear();
}
Expand Down Expand Up @@ -164,7 +154,7 @@ main()

display.setFont(modm::font::FixedWidth5x8);

modm::ShortPeriodicTimer timer(1000);
modm::ShortPeriodicTimer timer(1s);
while (true)
{
uint8_t iter = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/avr/display/dogm128/benchmark/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<library>
<options>
<option name="modm:target">atmega644-20au</option>
<option name="modm:platform:clock:f_cpu">14745600</option>
<option name="modm:platform:core:f_cpu">14745600</option>
<option name="modm:build:build.path">../../../../../build/avr/display/dogm128/benchmark</option>
<option name="modm:build:scons:image.source">images</option>
</options>
Expand Down
3 changes: 2 additions & 1 deletion examples/avr/display/dogm128/caged_ball/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using namespace modm::platform;
using namespace modm::literals;
using namespace std::chrono_literals;


namespace led
Expand Down Expand Up @@ -82,6 +83,6 @@ main()
display.drawCircle(Point(x, y), radius);
display.update();

modm::delayMilliseconds(50);
modm::delay(50ms);
}
}
2 changes: 1 addition & 1 deletion examples/avr/display/dogm128/caged_ball/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<library>
<options>
<option name="modm:target">atmega644-20au</option>
<option name="modm:platform:clock:f_cpu">14745600</option>
<option name="modm:platform:core:f_cpu">14745600</option>
<option name="modm:build:build.path">../../../../../build/avr/display/dogm128/caged_ball</option>
</options>
<modules>
Expand Down
Loading

0 comments on commit 778951a

Please sign in to comment.