fc10ef2e10
GD32F470ZGT6 based project with full peripheral support: - SDRAM (W9825G6KH) via EXMC - LCD NT35510 (480x800) via EXMC NOR/PSRAM - Flash (W25Q64) via SPI - UART (USART0) debug console - LED indicators - CMSIS-DAP debug interface - CMake + ARM GCC toolchain build system
51 lines
956 B
C++
51 lines
956 B
C++
#ifndef __TIMER_DRIVER_H__
|
|
#define __TIMER_DRIVER_H__
|
|
|
|
#include <cstdint>
|
|
#include "bus_core.h"
|
|
|
|
enum class TimerPort : uint8_t {
|
|
_0 = 0,
|
|
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13,
|
|
MAX
|
|
};
|
|
|
|
enum class TimerMode : uint8_t {
|
|
BASIC = 0,
|
|
PWM,
|
|
INPUT_CAPTURE,
|
|
ONE_PULSE,
|
|
};
|
|
|
|
struct TimerConfig {
|
|
uint32_t prescaler = 0;
|
|
uint32_t period = 0;
|
|
bool use_interrupt = false;
|
|
TimerMode mode = TimerMode::BASIC;
|
|
};
|
|
|
|
class TimerBus {
|
|
public:
|
|
explicit TimerBus(TimerPort port);
|
|
~TimerBus();
|
|
|
|
TimerBus(const TimerBus &) = delete;
|
|
TimerBus &operator=(const TimerBus &) = delete;
|
|
|
|
RetCode init(const TimerConfig &config);
|
|
RetCode deinit();
|
|
RetCode start();
|
|
RetCode stop();
|
|
RetCode set_period(uint32_t period);
|
|
uint32_t get_counter() const;
|
|
|
|
private:
|
|
TimerPort port_;
|
|
TimerConfig config_;
|
|
bool initialized_ = false;
|
|
};
|
|
|
|
void timer_irq_handler(TimerPort port);
|
|
|
|
#endif
|