Cleanup clock modules and add related user-defined literals #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This refactors the
:platform:clock
and related modules to remove legacy code and simplify module partitioning and generalize Baudrate and Frequency specification with user-defined literals.Structural changes (breaking):
:platform:clock.cortex
->:platform:systick
: Movedmodm_clock.cpp
to:platform:cortex-m
modulemodm::platform::ClockControl
for STM32 to:platform:rcc
module.modm:platform:clock
now is a module that contains common code.Refactorings (breaking):
modm::platform::ClockControl
->modm::platform::Rcc
for consistency.modm::cortex::SysTickTimer
->modm::platform::SysTickTimer
for consistency.ClockControl::setFlashLatency(Hz, mV)
->ClockControl::setFlashLatency<Hz, mV>()
: Allows latency table lookup in constexpr at compile-time.Rcc::updateCoreFrequency<Hz>()
: Sets the internal frequency values for delay functions.User-defined literals (breaking) added to the
modm::literals
namespace:_Hz
,_kHz
and_MHz
literals. Removed and replaced usage ofmodm::clock::Frequency
enum._Bd
,_kBd
and_MBd
literals. Removed and replaced usage ofmodm::Uart::Baudrate
enum._bps
, _kbpsand
_Mbps` literals. Not used yet.All literals are simply casting to a dimensionless
uint32_t
of integer units (no fractional units possible) to be lightweight and backwards compatible with modm.The limitation here is that since baudrates and frequencies are passed around as template arguments, the C++ limitations regarding template argument types applies, specifically
float
cannot be passed, as well as custom types cannot be used (Like a type-safefrequency_t
type).Todo:
Check if clock tree can at least be partially generated, requires data from modm-devices.No, this is difficult, see Add clock trees and query interface modm-devices#17. To be added later.Check if using aNo, this would break a lot ofenum class frequency_t : uint32_t {};
is an option for providing strongly-typed template arguments. Unfortunatelyenum class
operators are severely restricted (no implicit conversion obviously).::initialize<>()
code without any benefits.Bd
as Baudrate symbol, however, I personally find_Baud
,_kBaud
and_MBaud
more intuitive. Well, Bd is a SI unit, so that settles it.bit/s
as bitrate symbol, however_bits
looks wrong, so_bps
was chosen. This is fine, other libraries use this convention too (Bytes/s is Bps then).@rleh @chris-durand