tone-generator/entry.hpp

79 lines
946 B
C++
Raw Normal View History

2024-08-19 22:43:24 +10:00
#pragma once
2024-08-25 13:55:43 +10:00
template <int P, bool v>
struct Checker {
static constexpr bool value = v;
};
2024-08-19 22:43:24 +10:00
namespace entry {
2024-08-25 13:55:43 +10:00
enum Type : uint8_t {
stop,
config,
set,
set_ts,
clear,
clear_ts,
};
2024-08-19 22:43:24 +10:00
struct Set {
uint8_t index;
uint16_t frequency;
};
struct Clear {
uint8_t index;
};
struct SetTS {
uint8_t index;
2024-08-25 13:55:43 +10:00
uint32_t ticks;
2024-08-19 22:43:24 +10:00
uint16_t frequency;
};
struct ClearTS {
uint8_t index;
2024-08-25 13:55:43 +10:00
uint32_t ticks;
2024-08-19 22:43:24 +10:00
};
2024-08-25 13:55:43 +10:00
struct Stop {
2024-08-19 22:43:24 +10:00
};
2024-08-25 13:55:43 +10:00
struct Config {
uint32_t us_per_tick;
float amplitude;
};
struct Generic {
Type type;
union {
Set set;
SetTS set_ts;
Clear clear;
ClearTS clear_ts;
Stop stop;
Config config;
};
};
inline size_t get_size(Type type) {
switch(type) {
case Type::set:
return 3;
case Type::clear:
return 1;
case Type::set_ts:
return 5;
case Type::clear_ts:
return 4;
case Type::config:
return 8;
case Type::stop:
default:
return 1;
}
}
2024-08-19 22:43:24 +10:00
};