Skip to content

Commit f5599ce

Browse files
committed
[peripheral] Add Baudrate user-defined literal
1 parent 7af2e23 commit f5599ce

File tree

91 files changed

+161
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+161
-80
lines changed

docs/src/guide/cookbook.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using Uart = Uart0;
3535
// connect both pins with a pullup on the Rx
3636
Uart::connect<GpioOutputD1::Tx, GpioInputD0::Rx>(Gpio::InputType::PullUp);
3737
// initialize to 115.2kBaud from the BSP clock configuration
38-
Uart::initialize<Board::systemClock, 115200>();
38+
Uart::initialize<Board::systemClock, 115200_Bd>();
3939
4040
Uart::write('H'); // Ohai there
4141
Uart::write('i');
@@ -59,7 +59,7 @@ modm::IODeviceWrapper<Uart> device;
5959
modm::IOStream stream(device);
6060

6161
Uart::connect<GpioOutputD1::Tx>();
62-
Uart::initialize<Board::systemClock, 115200>();
62+
Uart::initialize<Board::systemClock, 115200_Bd>();
6363

6464
// similar to std::ostream but without formatting features
6565
stream << 42 << " is a nice number!" << modm::endl;

docs/src/how-modm-works.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ for keeping code size in check on very resource constrained targets, like the AV
259259

260260
```cpp
261261
Uart4::connect<GpioA0::Tx, GpioA1::Rx>(Gpio::InputType::PullUp); // pull-up in RX pin
262-
Uart4::initialize<Board::systemClock, 115'200>(); // Within 1% default tolerance
263-
Uart4::initialize<Board::systemClock, 115'200, Tolerance::Exact>();
262+
Uart4::initialize<Board::systemClock, 115'200_Bd>(); // Within 1% default tolerance
263+
Uart4::initialize<Board::systemClock, 115'200_Bd> Tolerance::Exact>();
264264
// error: The closest available baudrate exceeds the tolerance of the requested baudrate!
265265
```
266266

examples/arduino_uno/basic/analog_read_serial/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// Inspired by: http://arduino.cc/en/Tutorial/AnalogReadSerial
1515

1616
#include <modm/board.hpp>
17+
using namespace modm::literals;
1718

1819
int
1920
main()

examples/arduino_uno/basic/read_analog_voltage/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// Inspired by: http://arduino.cc/en/Tutorial/ReadAnalogVoltage
1515

1616
#include <modm/board.hpp>
17+
using namespace modm::literals;
1718

1819
int
1920
main()

examples/avr/1-wire/ds18b20/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <modm/io/iostream.hpp>
1717

1818
using namespace modm::platform;
19+
using namespace modm::literals;
1920

2021
using OneWirePin = GpioC2;
2122
using OneWireMaster = BitBangOneWireMaster<OneWirePin>;
@@ -25,7 +26,7 @@ main()
2526
{
2627
using systemClock = SystemClock;
2728
Uart0::connect<GpioD1::Txd, GpioD0::Rxd>();
28-
Uart0::initialize<systemClock, 9600>();
29+
Uart0::initialize<systemClock, 9600_Bd>();
2930

3031
// Enable interrupts, this is needed for every buffered UART
3132
enableInterrupts();

examples/avr/adc/basic/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
#include <modm/io/iostream.hpp>
1616

1717
using namespace modm::platform;
18+
using namespace modm::literals;
1819
using systemClock = SystemClock;
1920

2021
int
2122
main()
2223
{
2324
// Create a new UART object and configure it to a baudrate of 115200
2425
Uart0::connect<GpioOutputD1::Txd, GpioInputD0::Rxd>();
25-
Uart0::initialize<systemClock, 115200>();
26+
Uart0::initialize<systemClock, 115200_Bd>();
2627

2728
// Enable interrupts, this is needed for every buffered UART
2829
enableInterrupts();

examples/avr/adc/oversample/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <modm/processing/timer.hpp>
1515

1616
using namespace modm::platform;
17+
using namespace modm::literals;
1718

1819
// Create a new UART object
1920
using systemClock = SystemClock;
@@ -38,7 +39,7 @@ int
3839
main()
3940
{
4041
Uart0::connect<GpioOutputD1::Txd, GpioInputD0::Rxd>();
41-
Uart0::initialize<systemClock, 115200>();
42+
Uart0::initialize<systemClock, 115200_Bd>();
4243

4344
// Initialize the analog to digital converter
4445
// With the AVR running at 14.7456Mhz and a prescaler of 128 the

examples/avr/can/mcp2515_uart/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ main()
7070
OCR2A = 230;
7171

7272
Uart0::connect<GpioD1::Txd, GpioD0::Rxd>();
73-
Uart0::initialize<systemClock, 115200>();
73+
Uart0::initialize<systemClock, 115200_Bd>();
7474

7575
// Create a IOStream for complex formatting tasks
7676
modm::IODeviceWrapper< Uart0, modm::IOBuffer::BlockIfFull > device;

examples/avr/display/dogm128/touch/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int
6464
main()
6565
{
6666
Uart0::connect<GpioOutputD1::Txd, GpioInputD0::Rxd>();
67-
Uart0::initialize<systemClock, 115200>();
67+
Uart0::initialize<systemClock, 115200_Bd>();
6868

6969
// Enable interrupts, this is needed for every buffered UART
7070
enableInterrupts();

examples/avr/display/dogm132/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <modm/ui/button_group.hpp>
1717

1818
using namespace modm::platform;
19+
using namespace modm::literals;
1920
using systemClock = SystemClock;
2021

2122
typedef GpioOutputD2 Cs;

examples/avr/display/dogm163/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <modm/ui/display/font.hpp>
1717

1818
using namespace modm::platform;
19+
using namespace modm::literals;
1920
using systemClock = SystemClock;
2021

2122
// Graphic LCD

examples/avr/display/siemens_s65/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <modm/ui/button_group.hpp>
1717

1818
using namespace modm::platform;
19+
using namespace modm::literals;
1920

2021
using systemClock = SystemClock;
2122

examples/avr/logger/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <modm/debug/logger.hpp>
1616

1717
using namespace modm::platform;
18+
using namespace modm::literals;
1819
using systemClock = SystemClock;
1920

2021
// Create a new UART object and configure it to a baudrate of 115200
@@ -34,7 +35,7 @@ int
3435
main()
3536
{
3637
Uart0::connect<GpioD1::Txd, GpioD0::Rxd>();
37-
Uart0::initialize<systemClock, 115200>();
38+
Uart0::initialize<systemClock, 115200_Bd>();
3839

3940
// Enable interrupts, this is needed for every buffered UART
4041
enableInterrupts();

examples/avr/pwm/pca9685/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <modm/driver/pwm/pca9685.hpp>
1515

1616
using namespace modm::platform;
17+
using namespace modm::literals;
1718
using systemClock = SystemClock;
1819

1920
int

examples/avr/sab/slave/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <modm/communication/sab/slave.hpp>
2222

2323
using namespace modm::platform;
24+
using namespace modm::literals;
2425
using systemClock = SystemClock;
2526

2627
// ----------------------------------------------------------------------------

examples/avr/uart/basic/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313

1414
#include <modm/platform.hpp>
1515

16+
using namespace modm::literals;
1617
using namespace modm::platform;
1718
using systemClock = SystemClock;
1819

1920
int
2021
main()
2122
{
2223
Uart0::connect<GpioOutputD1::Txd, GpioInputD0::Rxd>();
23-
Uart0::initialize<systemClock, 115200>();
24+
Uart0::initialize<systemClock, 115200_Bd>();
2425

2526
// Enable interrupts, this is needed for every buffered UART
2627
enableInterrupts();

examples/avr/uart/extended/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <modm/platform.hpp>
1515
#include <modm/io/iostream.hpp>
16+
using namespace modm::literals;
1617

1718
using namespace modm::platform;
1819
using systemClock = SystemClock;
@@ -21,7 +22,7 @@ int
2122
main()
2223
{
2324
Uart0::connect<GpioOutputD1::Txd, GpioInputD0::Rxd>();
24-
Uart0::initialize<systemClock, 115200>();
25+
Uart0::initialize<systemClock, 115200_Bd>();
2526

2627
// Enable interrupts, this is needed for every buffered UART
2728
enableInterrupts();

examples/avr/xpcc/receiver/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int
8787
main()
8888
{
8989
Uart0::connect<GpioOutputD1::Txd, GpioInputD0::Rxd>();
90-
Uart0::initialize<systemClock, 115200>();
90+
Uart0::initialize<systemClock, 115200_Bd>();
9191

9292
// Initialize SPI interface and the other pins
9393
// needed by the MCP2515

examples/avr/xpcc/sender/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int
8787
main()
8888
{
8989
Uart0::connect<GpioOutputD1::Txd, GpioInputD0::Rxd>();
90-
Uart0::initialize<systemClock, 115200>();
90+
Uart0::initialize<systemClock, 115200_Bd>();
9191

9292
// Initialize SPI interface and the other pins
9393
// needed by the MCP2515

examples/generic/i2c_multiplex/i2c_multiplex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <modm/architecture/interface/i2c_device.hpp>
1414
#include <modm/architecture/interface/i2c_multiplexer.hpp>
1515
#include <modm/driver/gpio/pca9548a.hpp>
16+
using namespace modm::literals;
1617

1718
using MyI2cMaster = modm::platform::I2cMaster1;
1819
using Mpx = modm::Pca9548a<MyI2cMaster>;
@@ -108,7 +109,7 @@ main()
108109

109110
#ifndef MODM_BOARD_HAS_LOGGER
110111
LoggerUsart::connect<LoggerUsartTx::Tx, LoggerUsartRx::Rx>();
111-
LoggerUsart::initialize<Board::systemClock, modm::Uart::Baudrate::B115200>(12);
112+
LoggerUsart::initialize<Board::systemClock, 115200_Bd>(12);
112113
#endif
113114

114115
modm::platform::I2cMaster1::connect<modm::platform::GpioB7::Sda, modm::platform::GpioB6::Scl>();

examples/generic/ros/can_bridge/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <can_msgs/Frame.h>
1515
#include <ros/node_handle.h>
1616
#include <modm/communication/ros.hpp>
17+
using namespace modm::literals;
1718

1819
namespace modm {
1920
namespace can {
@@ -95,7 +96,7 @@ main()
9596

9697
// Reinit onboard UART to 1 Mbps
9798
// Do not use it for logging because this will destroy ROS serial messages.
98-
RosSerialUart::initialize<Board::systemClock, modm::Uart::Baudrate::kBps250>(12);
99+
RosSerialUart::initialize<Board::systemClock, 250_kBd>(12);
99100

100101
CanFilter::setStartFilterBankForCan2(14);
101102

examples/generic/ros/environment/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <ros/node_handle.h>
3232
#include <modm/communication/ros.hpp>
33+
using namespace modm::literals;
3334

3435
#undef MODM_LOG_LEVEL
3536
#define MODM_LOG_LEVEL modm::log::DISABLED
@@ -62,7 +63,7 @@ main()
6263

6364
// Reinit onboard UART to 1 Mbps
6465
// Do not use it for logging because this will destroy ROS serial messages.
65-
Board::stlink::Uart::initialize<Board::systemClock, modm::Uart::Baudrate::MBps1>(12);
66+
Board::stlink::Uart::initialize<Board::systemClock, 1_MBd>(12);
6667

6768
MyI2cMaster::connect<Board::D14::Sda, Board::D15::Scl>();
6869
MyI2cMaster::initialize<Board::systemClock, MyI2cMaster::Baudrate::Standard>();

examples/generic/ros/sub_pub/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <ros/node_handle.h>
2525
#include <modm/communication/ros.hpp>
26+
using namespace modm::literals;
2627

2728
#undef MODM_LOG_LEVEL
2829
#define MODM_LOG_LEVEL modm::log::DISABLED
@@ -74,7 +75,7 @@ main()
7475

7576
// Reinit onboard UART to 1 Mbps
7677
// Do not use it for logging because this will destroy ROS serial messages.
77-
Board::stlink::Uart::initialize<Board::systemClock, modm::Uart::Baudrate::MBps1>(12);
78+
Board::stlink::Uart::initialize<Board::systemClock, 1_MBd>(12);
7879

7980
Board::LedGreen::set();
8081

examples/nucleo_f401re/distance_vl53l0/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// ----------------------------------------------------------------------------
1313

1414
#include <modm/board.hpp>
15+
using namespace modm::literals;
1516

1617
#include <modm/processing/protothread.hpp>
1718
#include <modm/driver/position/vl53l0.hpp>

examples/nucleo_f429zi/pat9125el/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// ----------------------------------------------------------------------------
1111

1212
#include <modm/board.hpp>
13+
using namespace modm::literals;
1314

1415
#include <modm/processing/timer.hpp>
1516
#include <modm/processing/protothread.hpp>

examples/nucleo_f429zi/spi_flash/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include <modm/board.hpp>
12+
using namespace modm::literals;
1213

1314
#include <modm/driver/storage/block_device_spiflash.hpp>
1415

examples/nucleo_l432kc/gyroscope/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <modm/driver/inertial/l3gd20.hpp>
1717
#include <modm/processing.hpp>
1818
#include <modm/math/filter.hpp>
19+
using namespace modm::literals;
1920

2021
// Example for L3gd20 gyroscope connected to SPI USART interface
2122

examples/nucleo_l432kc/uart_spi/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// ----------------------------------------------------------------------------
1313

1414
#include <modm/board.hpp>
15+
using namespace modm::literals;
1516

1617

1718
int

examples/stm32f072_discovery/can/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <modm/board.hpp>
1515
#include <modm/processing/timer.hpp>
1616
#include <modm/debug/logger.hpp>
17+
using namespace modm::literals;
1718

1819
/**
1920
* Example of CAN Hardware on STM32 F0 Discovery Board.
@@ -75,7 +76,7 @@ main()
7576

7677
// Initialize Usart
7778
Usart1::connect<GpioOutputA9::Tx>();
78-
Usart1::initialize<Board::systemClock, 115200>();
79+
Usart1::initialize<Board::systemClock, 115200_Bd>();
7980

8081
MODM_LOG_INFO << "CAN Test Program" << modm::endl;
8182

examples/stm32f072_discovery/hard_fault/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <modm/board.hpp>
1313
#include <modm/debug/logger.hpp>
14+
using namespace modm::literals;
1415

1516
// ----------------------------------------------------------------------------
1617
// Set the log level
@@ -34,7 +35,7 @@ main()
3435

3536
// initialize Uart for MODM_LOG
3637
Usart1::connect<GpioOutputA9::Tx>();
37-
Usart1::initialize<Board::systemClock, 115200>();
38+
Usart1::initialize<Board::systemClock, 115200_Bd>();
3839

3940
MODM_LOG_INFO << "Causing a Hardfault now!" << modm::endl;
4041

examples/stm32f072_discovery/tmp102/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// ----------------------------------------------------------------------------
1212

1313
#include <modm/board.hpp>
14+
using namespace modm::literals;
1415

1516
#include <modm/processing/timer.hpp>
1617
#include <modm/processing/protothread.hpp>
@@ -108,7 +109,7 @@ main()
108109
Board::initialize();
109110

110111
Usart1::connect<GpioA9::Tx>();
111-
Usart1::initialize<Board::systemClock, 115'200>();
112+
Usart1::initialize<Board::systemClock, 115'200_Bd>();
112113

113114
MyI2cMaster::connect<GpioB7::Sda, GpioB8::Scl>();
114115
MyI2cMaster::initialize<Board::systemClock, 400_kHz>();

examples/stm32f072_discovery/uart/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// ----------------------------------------------------------------------------
1515

1616
#include <modm/board.hpp>
17+
using namespace modm::literals;
1718

1819
// ----------------------------------------------------------------------------
1920
/**
@@ -30,7 +31,7 @@ main()
3031

3132
// Enable USART 1
3233
Usart1::connect<GpioOutputA9::Tx>();
33-
Usart1::initialize<Board::systemClock, 9600>();
34+
Usart1::initialize<Board::systemClock, 9600_Bd>();
3435

3536
while (1)
3637
{

0 commit comments

Comments
 (0)