-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathadc_base.hpp
76 lines (66 loc) · 2.06 KB
/
adc_base.hpp
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
74
75
76
#pragma once
//=========================================================================//
/*! @file
@brief A/D 変換共通クラス
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2022 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=========================================================================//
#include <cstdint>
namespace device {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief A/D 変換共通クラス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
class adc_base {
public:
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief A/D 変換チャネルホルダーテンプレート
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <typename ANALOG>
struct channels_t {
uint16_t channels_;
//-------------------------------------------------------------//
/*!
@brief コンストラクター
*/
//-------------------------------------------------------------//
channels_t() noexcept : channels_(0) { }
//-------------------------------------------------------------//
/*!
@brief セット
@param[in] an アナログチャネル型
@param[in] on 不許可にする場合「false」
*/
//-------------------------------------------------------------//
void set(ANALOG an, bool on = true) noexcept
{
if(on) {
channels_ |= 1 << static_cast<uint8_t>(an);
} else {
channels_ &= ~(1 << static_cast<uint8_t>(an));
}
}
//-------------------------------------------------------------//
/*!
@brief 取得
@param[in] an アナログチャネル型
@return 状態
*/
//-------------------------------------------------------------//
bool get(ANALOG an) const noexcept
{
return (channels_ & (1 << static_cast<uint8_t>(an))) != 0;
}
bool operator() (ANALOG an) const noexcept
{
return get(an);
}
};
};
}