mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2026-09-21 12:29:35 +00:00
135 lines
2.8 KiB
C++
135 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
struct GPIO_TypeDef
|
|
{
|
|
uint32_t BSRR = 0;
|
|
uint32_t IDR = 0;
|
|
};
|
|
|
|
class __FlashStringHelper;
|
|
#define F(value) (reinterpret_cast<const __FlashStringHelper *>(value))
|
|
|
|
class Print
|
|
{
|
|
public:
|
|
size_t print(const __FlashStringHelper *value)
|
|
{
|
|
return append(reinterpret_cast<const char *>(value));
|
|
}
|
|
|
|
size_t print(const char *value) { return append(value); }
|
|
|
|
size_t print(char value)
|
|
{
|
|
buffer_.push_back(value);
|
|
return 1U;
|
|
}
|
|
|
|
template <typename T>
|
|
size_t print(T value)
|
|
{
|
|
return append(std::to_string(value).c_str());
|
|
}
|
|
|
|
size_t println()
|
|
{
|
|
buffer_.push_back('\n');
|
|
return 1U;
|
|
}
|
|
|
|
size_t write(uint8_t value)
|
|
{
|
|
buffer_.push_back(static_cast<char>(value));
|
|
return 1U;
|
|
}
|
|
|
|
const std::string &str() const { return buffer_; }
|
|
void clear() { buffer_.clear(); }
|
|
|
|
private:
|
|
size_t append(const char *value)
|
|
{
|
|
if (value == nullptr)
|
|
return 0U;
|
|
const size_t oldSize = buffer_.size();
|
|
buffer_ += value;
|
|
return buffer_.size() - oldSize;
|
|
}
|
|
|
|
std::string buffer_;
|
|
};
|
|
|
|
using IRQn_Type = int;
|
|
enum TimerFormat_t : uint8_t { TICK_FORMAT = 0, MICROSEC_FORMAT, HERTZ_FORMAT };
|
|
|
|
constexpr uint8_t LOW = 0;
|
|
constexpr uint8_t HIGH = 1;
|
|
constexpr uint8_t INPUT = 0;
|
|
constexpr uint8_t OUTPUT = 1;
|
|
|
|
class HardwareTimer
|
|
{
|
|
public:
|
|
void pause() {}
|
|
void resume() {}
|
|
void setOverflow(uint32_t value, TimerFormat_t format = TICK_FORMAT)
|
|
{
|
|
if (format == HERTZ_FORMAT && value != 0U)
|
|
{
|
|
prescale_ = 1U;
|
|
overflow_ = timerClockHz_ / value;
|
|
if (overflow_ == 0U) overflow_ = 1U;
|
|
}
|
|
else
|
|
{
|
|
overflow_ = value == 0U ? 1U : value;
|
|
}
|
|
}
|
|
uint32_t getOverflow(TimerFormat_t = TICK_FORMAT) { return overflow_; }
|
|
uint32_t getPrescaleFactor() { return prescale_; }
|
|
uint32_t getTimerClkFreq() { return timerClockHz_; }
|
|
void attachInterrupt(uint8_t, void (*)()) {}
|
|
|
|
uint32_t timerClockHz_ = 12000000U;
|
|
uint32_t prescale_ = 1U;
|
|
uint32_t overflow_ = 1U;
|
|
};
|
|
|
|
inline GPIO_TypeDef *digitalPinToPort(uint8_t)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
inline uint16_t digitalPinToBitMask(uint8_t)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
inline void pinMode(uint8_t, uint8_t) {}
|
|
inline void digitalWrite(uint8_t, uint8_t) {}
|
|
inline void NVIC_SetPriority(IRQn_Type, uint8_t) {}
|
|
inline void noInterrupts() {}
|
|
inline void interrupts() {}
|
|
|
|
struct ArduinoSerialStub
|
|
{
|
|
template <typename T> void print(const T&) {}
|
|
template <typename T> void println(const T&) {}
|
|
void println() {}
|
|
};
|
|
|
|
inline ArduinoSerialStub Serial;
|
|
|
|
inline uint32_t arduino_stub_micros = 0U;
|
|
|
|
inline unsigned long millis()
|
|
{
|
|
return arduino_stub_micros / 1000U;
|
|
}
|
|
|
|
inline unsigned long micros() { return arduino_stub_micros; }
|