Skip to content

Commit f0d4534

Browse files
committed
[board] Implement modm_abandon for AVR boards
1 parent ae74049 commit f0d4534

File tree

17 files changed

+70
-131
lines changed

17 files changed

+70
-131
lines changed

examples/arduino_nano/printf/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ main()
2222
modm::PeriodicTimer heartbeat(1s);
2323

2424
// <option name="modm:io:with_long_long">yes</option>
25-
serialStream << 32ull << modm::endl;
25+
MODM_LOG_INFO << 32ull << modm::endl;
2626

2727
// <option name="modm:io:with_float">yes</option>
28-
serialStream << 32.0f << modm::endl;
28+
MODM_LOG_INFO << 32.0f << modm::endl;
2929

3030
// <option name="modm:io:with_printf">yes</option>
31-
serialStream.printf("hello %lu %03.3f\n", 32ul, 32.23451);
31+
MODM_LOG_INFO.printf("hello %lu %03.3f\n", 32ul, 32.23451);
3232

3333
uint8_t counter{0};
3434
while (true)
3535
{
3636
if (heartbeat.execute())
3737
{
38-
serialStream << counter++ << modm::endl;
38+
MODM_LOG_INFO << counter++ << modm::endl;
3939
Board::LedD13::toggle();
4040
}
4141
}

examples/arduino_uno/basic/analog_read_serial/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ main()
3131
// read the input on analog pin 0
3232
int sensorValue = Adc::readChannel(0);
3333
// print analog readout
34-
serialStream << sensorValue << modm::endl;
34+
MODM_LOG_INFO << sensorValue << modm::endl;
3535
}
3636
}

examples/arduino_uno/basic/digital_read_serial/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ main()
2929
// read the input pin
3030
bool buttonState = PushButton::read();
3131
// print button state
32-
serialStream << buttonState << modm::endl;
32+
MODM_LOG_INFO << buttonState << modm::endl;
3333
}
3434
}

examples/arduino_uno/basic/read_analog_voltage/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ main()
3333
// convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
3434
float voltage = sensorValue * (5.0 / 1023.0);
3535
// print voltage
36-
serialStream << voltage << "V" << modm::endl;
36+
MODM_LOG_INFO << voltage << "V" << modm::endl;
3737
}
3838
}

examples/avr/assert/main.cpp

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,13 @@
1414

1515
using modm::accessor::asFlash;
1616

17-
// Flash support on avr-gcc is so horribly broken.
18-
#define IFS(s) asFlash(PSTR(s))
19-
20-
extern "C" void
21-
modm_abandon(const modm::AssertionInfo &info)
22-
{
23-
serialStream << IFS("Assertion '") << asFlash(info.name) << '\'';
24-
if (info.context != uintptr_t(-1))
25-
serialStream << IFS(" @ ") << (void *)info.context << IFS(" (") << (uint32_t)info.context << IFS(")");
26-
#if MODM_ASSERTION_INFO_HAS_DESCRIPTION
27-
serialStream << IFS(" failed!\n ") << asFlash(info.description) << IFS("\nAbandoning...\n");
28-
#else
29-
serialStream << IFS(" failed!\nAbandoning...\n");
30-
#endif
31-
32-
Leds::setOutput();
33-
while (true) {
34-
Leds::write(1);
35-
modm::delay(20ms);
36-
Leds::write(0);
37-
modm::delay(180ms);
38-
}
39-
}
40-
41-
4217
static modm::Abandonment
4318
test_assertion_handler(const modm::AssertionInfo &info)
4419
{
45-
serialStream << IFS("#1: '") << asFlash(info.name) << IFS("'!") << modm::endl;
20+
MODM_LOG_INFO << IFSS("#1: '") << asFlash(info.name) << IFSS("'!") << modm::endl;
4621
// The strings are located in FLASH!!!
4722
if (strncmp_P("io.", info.name, 3) == 0) {
48-
serialStream << IFS("Ignoring assertion!") << modm::endl;
23+
MODM_LOG_INFO << IFSS("Ignoring assertion!") << modm::endl;
4924
return modm::Abandonment::Ignore;
5025
}
5126
return modm::Abandonment::DontCare;
@@ -55,15 +30,15 @@ MODM_ASSERTION_HANDLER(test_assertion_handler);
5530
static modm::Abandonment
5631
test_assertion_handler2(const modm::AssertionInfo &info)
5732
{
58-
serialStream << IFS("#2: '") << asFlash(info.name) << IFS("'!") << modm::endl;
33+
MODM_LOG_INFO << IFSS("#2: '") << asFlash(info.name) << IFSS("'!") << modm::endl;
5934
return modm::Abandonment::DontCare;
6035
}
6136
MODM_ASSERTION_HANDLER(test_assertion_handler2);
6237

6338
static modm::Abandonment
6439
test_assertion_handler3(const modm::AssertionInfo &info)
6540
{
66-
serialStream << IFS("#3: '") << asFlash(info.name) << IFS("'!") << modm::endl;
41+
MODM_LOG_INFO << IFSS("#3: '") << asFlash(info.name) << IFSS("'!") << modm::endl;
6742
return modm::Abandonment::DontCare;
6843
}
6944
MODM_ASSERTION_HANDLER(test_assertion_handler3);
@@ -74,7 +49,7 @@ int main()
7449
{
7550
Board::initialize();
7651
Leds::setOutput();
77-
serialStream << IFS("Starting test...\n");
52+
MODM_LOG_INFO << IFSS("Starting test...\n");
7853

7954
// only fails for debug builds, but is ignored anyways
8055
modm_assert_continue_fail(false, "io.tx",

examples/avr/ports/main.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ struct DebugGpioPort : public Port
1919
static void dumpShifts()
2020
{
2121
for (int ii=0; ii<7; ii++) {
22-
serialStream << char(ii+'A') << " {";
22+
MODM_LOG_INFO << char(ii+'A') << " {";
2323
for (int jj=0; jj<Port::width; jj++) {
2424
const auto p = Port::shift_masks[ii][jj];
25-
serialStream << " ";
26-
if (p >= 0) { serialStream << p; }
27-
else { serialStream << " "; }
28-
serialStream << " ";
29-
if (jj != Port::width - 1) { serialStream << ","; }
25+
MODM_LOG_INFO << " ";
26+
if (p >= 0) { MODM_LOG_INFO << p; }
27+
else { MODM_LOG_INFO << " "; }
28+
MODM_LOG_INFO << " ";
29+
if (jj != Port::width - 1) { MODM_LOG_INFO << ","; }
3030
}
31-
serialStream << "}" << modm::endl;
31+
MODM_LOG_INFO << "}" << modm::endl;
3232
}
3333
}
3434

3535
static void dumpMasks()
3636
{
3737
for (int ii=0; ii<7; ii++) {
38-
serialStream << char(ii+'A') << " " << modm::bin << Port::mask(ii) << modm::endl;
38+
MODM_LOG_INFO << char(ii+'A') << " " << modm::bin << Port::mask(ii) << modm::endl;
3939
}
40-
serialStream << modm::endl;
40+
MODM_LOG_INFO << modm::endl;
4141
for (int ii=0; ii<7; ii++) {
42-
serialStream << char(ii+'A') << " " << modm::bin << Port::inverted(ii) << modm::endl;
42+
MODM_LOG_INFO << char(ii+'A') << " " << modm::bin << Port::inverted(ii) << modm::endl;
4343
}
4444
}
4545
};
@@ -64,23 +64,23 @@ int main()
6464
static_assert(PinGroup3::number_of_ports == 1);
6565
static_assert(PinGroup4::number_of_ports == 1);
6666

67-
DebugGpioPort<PinGroup>::dumpMasks(); serialStream << modm::endl;
68-
DebugGpioPort<PinGroup2>::dumpMasks(); serialStream << modm::endl;
69-
DebugGpioPort<PinGroup3>::dumpMasks(); serialStream << modm::endl;
70-
DebugGpioPort<PinGroup4>::dumpMasks(); serialStream << modm::endl;
67+
DebugGpioPort<PinGroup>::dumpMasks(); MODM_LOG_INFO << modm::endl;
68+
DebugGpioPort<PinGroup2>::dumpMasks(); MODM_LOG_INFO << modm::endl;
69+
DebugGpioPort<PinGroup3>::dumpMasks(); MODM_LOG_INFO << modm::endl;
70+
DebugGpioPort<PinGroup4>::dumpMasks(); MODM_LOG_INFO << modm::endl;
7171

72-
DebugGpioPort<PinGroup>::dumpShifts(); serialStream << modm::endl;
73-
DebugGpioPort<PinGroup2>::dumpShifts(); serialStream << modm::endl;
72+
DebugGpioPort<PinGroup>::dumpShifts(); MODM_LOG_INFO << modm::endl;
73+
DebugGpioPort<PinGroup2>::dumpShifts(); MODM_LOG_INFO << modm::endl;
7474

75-
PinGroup2::setInput(); serialStream << modm::bin << PinGroup2::read() << modm::endl;
76-
PinGroup3::setInput(); serialStream << modm::bin << PinGroup3::read() << modm::endl;
77-
PinGroup4::setInput(); serialStream << modm::bin << PinGroup4::read() << modm::endl;
78-
serialStream << modm::endl;
75+
PinGroup2::setInput(); MODM_LOG_INFO << modm::bin << PinGroup2::read() << modm::endl;
76+
PinGroup3::setInput(); MODM_LOG_INFO << modm::bin << PinGroup3::read() << modm::endl;
77+
PinGroup4::setInput(); MODM_LOG_INFO << modm::bin << PinGroup4::read() << modm::endl;
78+
MODM_LOG_INFO << modm::endl;
7979

8080
PinGroup::setOutput(modm::Gpio::High); modm::delay(1s);
8181

8282
const auto fn_report = []() {
83-
serialStream << modm::bin << PinGroup::read() << modm::endl; modm::delay(200ms);
83+
MODM_LOG_INFO << modm::bin << PinGroup::read() << modm::endl; modm::delay(200ms);
8484
};
8585

8686
while (true)
@@ -91,14 +91,14 @@ int main()
9191
PinGroup::write(0b00111); fn_report();
9292
PinGroup::write(0b01111); fn_report();
9393
PinGroup::write(0b11111); fn_report();
94-
serialStream << modm::endl;
94+
MODM_LOG_INFO << modm::endl;
9595

9696
PinGroup::reset();
9797
Pin0::set(); fn_report();
9898
Pin1::set(); fn_report();
9999
Pin2::set(); fn_report();
100100
Pin3::set(); fn_report();
101-
serialStream << modm::endl;
101+
MODM_LOG_INFO << modm::endl;
102102

103103
// while (true);
104104
}

examples/avr/qmc5883l/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ main()
5454
<< modm::endl;
5555
} else
5656
{
57-
serialStream << "readDataBlocking(): Error: " << uint8_t(I2cMaster::getErrorState())
58-
<< modm::endl;
57+
MODM_LOG_INFO << "readDataBlocking(): Error: " << uint8_t(I2cMaster::getErrorState())
58+
<< modm::endl;
5959
}
6060
}
6161
}

src/modm/board/al_avreb_can/board.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#define MODM_AL_AVREB_CAN_HPP
1919

2020
#include <modm/platform.hpp>
21-
#include <modm/io/iostream.hpp>
21+
#include <modm/debug/logger.hpp>
22+
/// @ingroup modm_board_al_avreb_can
23+
#define MODM_BOARD_HAS_LOGGER
2224

2325
using namespace modm::platform;
2426

@@ -54,6 +56,5 @@ initialize()
5456
}
5557

5658
using namespace Board;
57-
extern modm::IOStream serialStream;
5859

5960
#endif // MODM_ARDUINO_UNO_HPP

src/modm/board/al_avreb_can/board_serial.cpp

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/modm/board/al_avreb_can/module.lb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def prepare(module, options):
2525

2626
module.depends(
2727
":architecture:clock",
28-
":io",
28+
":debug",
2929
":platform:clock",
3030
":platform:core",
3131
":platform:gpio",
@@ -34,6 +34,11 @@ def prepare(module, options):
3434

3535
def build(env):
3636
env.outbasepath = "modm/src/modm/board"
37+
env.substitutions = {
38+
"with_logger": True,
39+
"with_assert": env.has_module(":architecture:assert")
40+
}
41+
env.template("../board.cpp.in", "board.cpp")
3742
env.copy('.')
3843
env.collect(":build:default.avrdude.port", "usb");
3944
env.collect(":build:default.avrdude.programmer", "avrispmkII");

0 commit comments

Comments
 (0)