using | modm::frequency_t = uint32_t |
|
using | modm::baudrate_t = uint32_t |
|
using | modm::bitrate_t = uint32_t |
|
using | modm::percent_t = float |
|
using | modm::seconds_t = std::chrono::seconds |
|
using | modm::milliseconds_t = std::chrono::milliseconds |
|
using | modm::microseconds_t = std::chrono::microseconds |
|
template<typename T > |
constexpr frequency_t | modm::Hz (T value) |
|
template<typename T > |
constexpr frequency_t | modm::kHz (T value) |
|
template<typename T > |
constexpr frequency_t | modm::MHz (T value) |
|
template<typename T > |
constexpr baudrate_t | modm::Bd (T value) |
|
template<typename T > |
constexpr baudrate_t | modm::kBd (T value) |
|
template<typename T > |
constexpr baudrate_t | modm::MBd (T value) |
|
template<typename T > |
constexpr bitrate_t | modm::bps (T value) |
|
template<typename T > |
constexpr bitrate_t | modm::kbps (T value) |
|
template<typename T > |
constexpr bitrate_t | modm::Mbps (T value) |
|
template<typename T > |
constexpr percent_t | modm::pct (T value) |
|
constexpr | modm::literals::operator""_Hz (T value) |
|
constexpr | modm::literals::operator""_kHz (T value) |
|
constexpr | modm::literals::operator""_MHz (T value) |
|
constexpr | modm::literals::operator""_Bd (T value) |
|
constexpr | modm::literals::operator""_kBd (T value) |
|
constexpr | modm::literals::operator""_MBd (T value) |
|
constexpr | modm::literals::operator""_bps (T value) |
|
constexpr | modm::literals::operator""_kbps (T value) |
|
constexpr | modm::literals::operator""_Mbps (T value) |
|
constexpr | modm::literals::operator""_pct (T value) |
|
lbuild module: modm:math:units
modm uses a couple of common SI units for configuration of peripherals:
frequency_t
in Hertz: Hz
, kHz
and MHz
.
baudrate_t
in Baud: Bd
, kBd
, MBd
.
bitrate_t
in bit/s, bps
.
These are integral units, so 1 Hz/Bd/bps cannot be split further, and are cast directly to uint32_t
type, so they can be used as a non-type template argument.
Conversion can be done via constexpr functions from any numerical type:
modm::Hz(T value)
, modm::kHz(T value)
, modm::MHz(T value)
.
modm::Bd(T value)
, modm::kBd(T value)
, modm::MBd(T value)
.
modm::bps(T value)
, modm::kbps(T value)
, modm::Mbps(T value)
.
In addition, user-defined literals are provided in the modm::literals
namespace:
using namespace modm::literals;
frequency_t frequency = modm::Mhz(10.5);
frequency = 10.5_MHz;
baudrate_t baudrate = 115.2_kBd;
baudrate = modm::kBd(115.2);
bitrate_t bitrate = modm::kbps(125);
bitrate = 125_kbps;
frequency = 4295_MHz;
Percentages
Percentages are stored as normalized floating point numbers and can be converted using these convenience constructors:
using namespace modm::literals;
percent_t tolerance = modm::pct(10);
tolerance = 10_pct;
tolerance = 0.1f;
Time
Simplified types allow passing std::chrono::duration
values as template parameters:
seconds_t duration = 10s;
milliseconds_t duration = 10ms;
microseconds_t duration = 10us;
auto count = duration.count();
template< milliseconds_t period >
void setPeriod()
{
auto seconds = 1000.0 / period.count();
}