From 0bc2a81c0aab3c89b534415d6f07d07e392260ce Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 3 Jun 2017 20:47:37 +0200 Subject: o Adding support for reading IR codes. --- include/misc.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 include/misc.h (limited to 'include') diff --git a/include/misc.h b/include/misc.h new file mode 100644 index 0000000..aacba74 --- /dev/null +++ b/include/misc.h @@ -0,0 +1,61 @@ +#pragma once + +#include +#include +#include + +template +struct from_f_cpu_and_time_per_timer_tick { + template + using r = std::ratio; + + using f_cpu = r; + using seconds_per_cpu_tick = r<1, f_cpu::num>; + using seconds_per_timer_tick = SecondsPerTimerTick; + using timer_frequency = r; + +// static constexpr std::intmax_t prescaler = std::ratio_divive::value; + using prescaler_t = std::ratio_divide; + static_assert(prescaler_t::den == 1, "Could not represent the prescaler as an integer"); + static constexpr std::intmax_t prescaler = prescaler_t::num; + + // us_per_timer_tick = seconds_per_timer_tick * 1'000'000 + using us_per_timer_tick_t = typename std::ratio_multiply>::type; + + static constexpr uint16_t us_per_timer_tick = static_cast(us_per_timer_tick_t::num); + + template + __always_inline constexpr + static T to_us(unsigned int count) + { + return T(count * us_per_timer_tick); + } +}; + +using values = from_f_cpu_and_time_per_timer_tick<72'000'000, std::ratio_multiply, std::micro>>; + +//static_assert(values::timer_frequency::num == 200'000, "timer_frequency::num"); +static_assert(values::timer_frequency::den == 1, "timer_frequency::den"); +//static_assert(std::is_same< +// values::timer_frequency, +// std::ratio<200'000, 1>>::value, "Timer frequency is not 200kHz"); +static_assert(values::prescaler == 360, "Timer frequency is not 200kHz"); +static_assert(values::prescaler - 1 == RADIO_RX_TIMER_PRESCALER, "Bad prescaler from STM32CubeMX"); +static_assert(values::us_per_timer_tick == 5, "bad us_per_timer_tick"); + +static inline +void debug_pin(int count) { + for(int i = 0; i < count; i++) { + HAL_GPIO_WritePin(DEBUG_PIN_GPIO_Port, DEBUG_PIN_Pin, GPIO_PIN_SET); + __NOP(); + __NOP(); + __NOP(); + HAL_GPIO_WritePin(DEBUG_PIN_GPIO_Port, DEBUG_PIN_Pin, GPIO_PIN_RESET); + __NOP(); + __NOP(); + __NOP(); + } + __NOP(); + __NOP(); + __NOP(); +} -- cgit v1.2.3