Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup clock modules and add related user-defined literals #180

Merged
merged 12 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/guide/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using Uart = Uart0;
// connect both pins with a pullup on the Rx
Uart::connect<GpioOutputD1::Tx, GpioInputD0::Rx>(Gpio::InputType::PullUp);
// initialize to 115.2kBaud from the BSP clock configuration
Uart::initialize<Board::systemClock, 115200>();
Uart::initialize<Board::SystemClock, 115200_Bd>();

Uart::write('H'); // Ohai there
Uart::write('i');
Expand All @@ -59,7 +59,7 @@ modm::IODeviceWrapper<Uart> device;
modm::IOStream stream(device);

Uart::connect<GpioOutputD1::Tx>();
Uart::initialize<Board::systemClock, 115200>();
Uart::initialize<Board::SystemClock, 115200_Bd>();

// similar to std::ostream but without formatting features
stream << 42 << " is a nice number!" << modm::endl;
Expand Down
6 changes: 3 additions & 3 deletions docs/src/how-modm-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ for keeping code size in check on very resource constrained targets, like the AV

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

Expand Down Expand Up @@ -320,7 +320,7 @@ using GpioExpander = modm::Mcp23x17< Transport >;
GpioExpander expander;
// Connect and initialize the peripherals
SpiMaster1::connect<GpioA0::Sck, GpioA1::Mosi, GpioA2::Miso>();
SpiMaster1::initialize<Board::systemClock, 1MHz>();
SpiMaster1::initialize<Board::SystemClock, 1MHz>();
expander.initialize();
// Bind the expander pins to a simpler name
using Pin0 = GpioExpander::P0< expander >;
Expand Down
3 changes: 2 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,6 +14,7 @@
// Inspired by: http://arduino.cc/en/Tutorial/AnalogReadSerial

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

int
main()
Expand All @@ -23,7 +24,7 @@ main()
// Initialize the analog to digital converter
// With the AVR running at 16Mhz and a prescaler of 128 the
// ADC is running at 125kHz.
Adc::initialize<Board::systemClock, 125000>();
Adc::initialize<Board::SystemClock, 125_kHz>();
Adc::setReference(Adc::Reference::InternalVcc);

while (1)
Expand Down
3 changes: 2 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,6 +14,7 @@
// Inspired by: http://arduino.cc/en/Tutorial/ReadAnalogVoltage

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

int
main()
Expand All @@ -23,7 +24,7 @@ main()
// Initialize the analog to digital converter
// With the AVR running at 16Mhz and a prescaler of 128 the
// ADC is running at 125kHz.
Adc::initialize<Board::systemClock, 125000>();
Adc::initialize<Board::SystemClock, 125_kHz>();
Adc::setReference(Adc::Reference::InternalVcc);

while (1)
Expand Down
4 changes: 2 additions & 2 deletions examples/avr/1-wire/ds18b20/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
#include <modm/io/iostream.hpp>

using namespace modm::platform;
using namespace modm::literals;

using OneWirePin = GpioC2;
using OneWireMaster = BitBangOneWireMaster<OneWirePin>;

int
main()
{
using systemClock = SystemClock;
Uart0::connect<GpioD1::Txd, GpioD0::Rxd>();
Uart0::initialize<systemClock, 9600>();
Uart0::initialize<SystemClock, 9600_Bd>();

// Enable interrupts, this is needed for every buffered UART
enableInterrupts();
Expand Down
6 changes: 3 additions & 3 deletions examples/avr/adc/basic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
#include <modm/io/iostream.hpp>

using namespace modm::platform;
using systemClock = SystemClock;
using namespace modm::literals;

int
main()
{
// Create a new UART object and configure it to a baudrate of 115200
Uart0::connect<GpioOutputD1::Txd, GpioInputD0::Rxd>();
Uart0::initialize<systemClock, 115200>();
Uart0::initialize<SystemClock, 115200_Bd>();

// Enable interrupts, this is needed for every buffered UART
enableInterrupts();
Expand All @@ -36,7 +36,7 @@ main()
// Initialize the analog to digital converter
// With the AVR running at 14.7456Mhz and a prescaler of 128 the
// ADC is running at 115kHz.
Adc::initialize<systemClock, 115000>();
Adc::initialize<SystemClock, 115_kHz>();
Adc::setReference(Adc::Reference::InternalVcc);

// read the value of channel 0 (=> ADC0 => PA0) and wait until
Expand Down
6 changes: 3 additions & 3 deletions examples/avr/adc/oversample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <modm/processing/timer.hpp>

using namespace modm::platform;
using namespace modm::literals;

// Create a new UART object
using systemClock = SystemClock;

#include <modm/io/iostream.hpp>
// Create a IOStream for complex formatting tasks
Expand All @@ -38,12 +38,12 @@ int
main()
{
Uart0::connect<GpioOutputD1::Txd, GpioInputD0::Rxd>();
Uart0::initialize<systemClock, 115200>();
Uart0::initialize<SystemClock, 115200_Bd>();

// Initialize the analog to digital converter
// With the AVR running at 14.7456Mhz and a prescaler of 128 the
// ADC is running at 115kHz.
Adc::initialize<systemClock, 115000>();
Adc::initialize<SystemClock, 115_kHz>();
Adc::setReference(Adc::Reference::InternalVcc);
Adc::enableInterrupt();

Expand Down
6 changes: 3 additions & 3 deletions examples/avr/can/mcp2515/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <modm/driver/can/mcp2515.hpp>

using namespace modm::platform;
using systemClock = SystemClock;
using namespace modm::literals;

typedef GpioOutputB4 Cs;
typedef GpioInputB2 Int;
Expand Down Expand Up @@ -50,12 +50,12 @@ main()
// Initialize SPI interface and the other pins
// needed by the MCP2515
SPI::connect<Sclk::Sck, Mosi::Mosi, Miso::Miso>();
SPI::initialize<systemClock, 921600>();
SPI::initialize<SystemClock, 921.6_kHz>();
Cs::setOutput();
Int::setInput(Gpio::InputType::PullUp);

// Configure MCP2515 and set the filters
mcp2515.initialize<modm::clock::MHz8, modm::Can::Bitrate::kBps125>();
mcp2515.initialize<8_MHz, modm::Can::Bitrate::kBps125>();
mcp2515.setFilter(modm::accessor::asFlash(canFilter));

// Create a new message
Expand Down
8 changes: 4 additions & 4 deletions examples/avr/can/mcp2515_uart/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <modm/processing/timer.hpp>

using namespace modm::platform;
using systemClock = SystemClock;
using namespace modm::literals;

typedef GpioOutputB0 LedGreen;
typedef GpioOutputB1 LedRed;
Expand Down Expand Up @@ -69,7 +69,7 @@ main()
OCR2A = 230;

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

// Create a IOStream for complex formatting tasks
modm::IODeviceWrapper< Uart0, modm::IOBuffer::BlockIfFull > device;
Expand All @@ -83,12 +83,12 @@ main()
// Initialize SPI interface and the other pins
// needed by the MCP2515
SPI::connect<Sclk::BitBang, Mosi::BitBang, Miso::BitBang>();
SPI::initialize<systemClock, 1000000>();
SPI::initialize<SystemClock, 1_MHz>();
Cs::setOutput();
Int::setInput(Gpio::InputType::PullUp);

// Configure MCP2515 and set the filters
mcp2515.initialize<modm::clock::MHz8, modm::Can::Bitrate::kBps125>();
mcp2515.initialize<8_MHz, modm::Can::Bitrate::kBps125>();
mcp2515.setFilter(modm::accessor::asFlash(canFilter));

// Create a new message
Expand Down
4 changes: 2 additions & 2 deletions examples/avr/display/dogm128/benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "images/rca_logo_128x64.hpp"

using namespace modm::platform;
using namespace modm::literals;

using systemClock = SystemClock;

namespace led
{
Expand Down Expand Up @@ -64,7 +64,7 @@ setup()
led::B::setOutput();

lcd::SPI::connect<lcd::Sck::BitBang, lcd::Mosi::BitBang>();
lcd::SPI::initialize<systemClock, MHz2>();
lcd::SPI::initialize<SystemClock, 2_MHz>();

// timer initialization
// compare-match-interrupt every 1 ms at 14.7456 MHz
Expand Down
4 changes: 2 additions & 2 deletions examples/avr/display/dogm128/caged_ball/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <modm/architecture/interface/clock.hpp>

using namespace modm::platform;
using namespace modm::literals;

using systemClock = SystemClock;

namespace led
{
Expand Down Expand Up @@ -55,7 +55,7 @@ main()
led::B::setOutput();

lcd::SPI::connect<lcd::Scl::BitBang, lcd::Mosi::BitBang>();
lcd::SPI::initialize<systemClock, MHz2>();
lcd::SPI::initialize<SystemClock, 2_MHz>();

display.initialize();

Expand Down
4 changes: 2 additions & 2 deletions examples/avr/display/dogm128/draw/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <modm/architecture/interface/clock.hpp>

using namespace modm::platform;
using namespace modm::literals;

using systemClock = SystemClock;

namespace led
{
Expand Down Expand Up @@ -55,7 +55,7 @@ main()
led::B::setOutput();

lcd::SPI::connect<lcd::Scl::BitBang, lcd::Mosi::BitBang>();
lcd::SPI::initialize<systemClock, MHz2>();
lcd::SPI::initialize<SystemClock, 2_MHz>();

display.initialize();

Expand Down
4 changes: 2 additions & 2 deletions examples/avr/display/dogm128/image/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include "images/image_64x64_9.hpp"

using namespace modm::platform;
using namespace modm::literals;

using systemClock = SystemClock;

namespace led
{
Expand Down Expand Up @@ -211,7 +211,7 @@ main()
led::B::setOutput();

lcd::SPI::connect<lcd::Sck::BitBang, lcd::Mosi::BitBang>();
lcd::SPI::initialize<systemClock, MHz2>();
lcd::SPI::initialize<SystemClock, 2_MHz>();

display.initialize();

Expand Down
4 changes: 2 additions & 2 deletions examples/avr/display/dogm128/text/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <modm/architecture/interface/clock.hpp>

using namespace modm::platform;
using namespace modm::literals;

using systemClock = SystemClock;

// LCD Backlight
namespace led
Expand Down Expand Up @@ -57,7 +57,7 @@ main()
led::B::setOutput();

SPI::connect< lcd::Scl::BitBang, lcd::Mosi::BitBang, lcd::Miso::BitBang >();
SPI::initialize<systemClock, MHz2>();
SPI::initialize<SystemClock, 2_MHz>();

display.initialize();

Expand Down
8 changes: 4 additions & 4 deletions examples/avr/display/dogm128/touch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <modm/architecture/interface/clock.hpp>

using namespace modm::platform;
using systemClock = SystemClock;
using namespace modm::literals;

namespace touch
{
Expand Down Expand Up @@ -63,7 +63,7 @@ int
main()
{
Uart0::connect<GpioOutputD1::Txd, GpioInputD0::Rxd>();
Uart0::initialize<systemClock, 115200>();
Uart0::initialize<SystemClock, 115200_Bd>();

// Enable interrupts, this is needed for every buffered UART
enableInterrupts();
Expand All @@ -83,7 +83,7 @@ main()
led::B::setOutput();

lcd::SPI::connect<lcd::Scl::BitBang, lcd::Mosi::BitBang>();
lcd::SPI::initialize<systemClock, MHz2>();
lcd::SPI::initialize<SystemClock, 2_MHz>();

display.initialize();

Expand All @@ -96,7 +96,7 @@ main()

display.update();

Adc::initialize<systemClock, 115000>();
Adc::initialize<SystemClock, 115_kHz>();
Adc::setReference(Adc::Reference::Internal2V56);

touch::Bottom::setInput();
Expand Down
4 changes: 2 additions & 2 deletions examples/avr/display/dogm132/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <modm/ui/button_group.hpp>

using namespace modm::platform;
using systemClock = SystemClock;
using namespace modm::literals;

typedef GpioOutputD2 Cs;
typedef GpioOutputB6 Mosi;
Expand All @@ -40,7 +40,7 @@ main()
Backlight::set();

SPI::connect<Sck::BitBang, Mosi::BitBang>();
SPI::initialize<systemClock, 1000000>();
SPI::initialize<SystemClock, 1_MHz>();

display.initialize();
display.setFont(modm::font::Assertion);
Expand Down
4 changes: 2 additions & 2 deletions examples/avr/display/dogm163/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <modm/ui/display/font.hpp>

using namespace modm::platform;
using systemClock = SystemClock;
using namespace modm::literals;

// Graphic LCD
namespace lcd
Expand All @@ -37,7 +37,7 @@ int
main()
{
SPI::connect<lcd::Scl::BitBang, lcd::Mosi::BitBang, lcd::Miso::BitBang>();
SPI::initialize<systemClock, 1000000>();
SPI::initialize<SystemClock, 1_MHz>();
lcd::Cs::setOutput();
lcd::Rs::setOutput();

Expand Down
4 changes: 2 additions & 2 deletions examples/avr/display/siemens_s65/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <modm/ui/button_group.hpp>

using namespace modm::platform;
using namespace modm::literals;

using systemClock = SystemClock;

typedef GpioOutputA0 Mosi;
typedef GpioOutputA1 Sck;
Expand All @@ -34,7 +34,7 @@ int
main()
{
SPI::connect<Sck::BitBang, Mosi::BitBang>();
SPI::initialize<systemClock, 1000000>();
SPI::initialize<SystemClock, 1_MHz>();

Backlight::setOutput();
Backlight::set();
Expand Down
Loading