-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTODO
74 lines (55 loc) · 2.08 KB
/
TODO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Random thoughts and Todos...
tldr; see _attic/templatized_conf_idea.hh
You can convert an element of a const struct with static linkage (known at compile time) to a constexpr like this:
const SaiConf codec_sai_conf = { .periph_num = 1, ...};
constexpr auto pn = [=]() { return codec_sai_conf.periph_num; };
Clocks::SAIs<pn()>::enable();
However, you can't pass the const struct to a function (including a ctor).
-Consider more peripherals with a periph_num template parameter:
e.g: SAI<1>, SAI<2>
Small benefit is we can convert RCC_Control::PERIPH to be templated:
target::RCC_Control::PERIPH<periph_num>
target::RCC_Control::SAI<2>::set()
like this:
template<int periph_num>
class SaiPeriph {
SaiPeriph(const SaiConf &defs)
: defs_(defs)
{
target::RCC_Control::SAI<periph_num>::set();
}
Clocks::SAI<2>::enable() just directly calls target::RCC_Control::SAI<2>::set();
and we may not even need the Clocks wrapper anymore
But--- the conf/defs struct must be constexpr in order to say:
SaiPeriph<project_sai_conf.periph_num> sai {project_sai_conf};
...And clang doesn't allow constexpr structs to contain a pointer (...are there workarounds??)
But gcc does (and it's a bug, so we shouldn't rely on it)
--there may be a workaround for this, so it's not a deal-breaker
Or: we can have the periph_num outside the struct:
constexpr unsigned project_sai_periph_num = 2;
const SaiConfig project_sai_conf = { .sai=SAI2, .tx_block=SAI2_Block_A, ...};
Even if we had multiple SAIs in a project, it'd be like this:
SaiPeriph<main_sai_pn> sai_main {main_sai_conf};
SaiPeriph<aux_sai_pn> sai_aux {aux_sai_conf};
Or could we templatize the conf struct?
//sai_conf_struct:
template <unsigned periph_num>
struct SaiConf {
static inline const unsigned PeriphNum = periph_num;
SAI_TypeDef *SAIx;
...
};
//project sai_conf:
const SaiConf<1> project_sai_conf = {
.SAIx = SAI1;
};
template <typename ConfT>
struct SaiPeriph {
SaiPeriph(const ConfT &defs)
: defs_(defs)
{
target::RCC_Controls::SAI<ConfT::PeriphNum>::set();
}
const ConfT &defs_;
};
^^ This works, see _attic/templatized_conf_idea.hh