-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdac_out.hpp
149 lines (129 loc) · 4.06 KB
/
dac_out.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#pragma once
//=========================================================================//
/*! @file
@brief RX62[1N]/RX63[1N]/RX24T(Version B)/RX24U 10 bits D/A 制御
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2019, 2024 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=========================================================================//
#include "common/device.hpp"
namespace device {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief D/A 制御クラス
@param[in] DAC D/A デバイス・クラス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <class DAC>
class dac_out {
public:
//-----------------------------------------------------------------//
/*!
@brief 出力タイプ
*/
//-----------------------------------------------------------------//
enum class output : uint8_t {
NONE, ///< 出力禁止
CH0, ///< チャネル0
CH1, ///< チャネル1
CH0_CH1 ///< チャネル0、1
};
//-----------------------------------------------------------------//
/*!
@brief コンストラクター
*/
//-----------------------------------------------------------------//
dac_out() noexcept { }
//-----------------------------------------------------------------//
/*!
@brief スタート
@param[in] otype 出力タイプ
@param[in] ampe アンプ許可の場合「true」 @n
互換性の為ある(機能しない)
@return 成功なら「true」
*/
//-----------------------------------------------------------------//
bool start(output otype, bool ampe) const noexcept
{
power_mgr::turn(DAC::PERIPHERAL);
if(otype == output::NONE) {
DAC::DACR.DAE = 0;
DAC::DACR = DAC::DACR.DAE.b(0) | DAC::DACR.DAOE0.b(0) | DAC::DACR.DAOE1.b(0);
power_mgr::turn(DAC::PERIPHERAL, false);
return true;
}
DAC::DADPR.DPSEL = 1; // 左詰め(下位6ビット無視)
DAC::DACR.DAE = 0;
bool ch0 = false;
bool ch1 = false;
switch(otype) {
case output::CH0:
ch0 = true;
break;
case output::CH1:
ch1 = true;
break;
case output::CH0_CH1:
ch0 = true;
ch1 = true;
break;
default:
power_mgr::turn(DAC::PERIPHERAL, false);
return false;
}
if(ch0) {
DAC::enable(DAC::ANALOG::DA0);
DAC::DACR.DAOE0 = 1;
}
if(ch1) {
DAC::enable(DAC::ANALOG::DA1);
DAC::DACR.DAOE1 = 1;
}
utils::delay::micro_second(3); // amp start setup time
return true;
}
//-----------------------------------------------------------------//
/*!
@brief 電圧出力0(16ビット値)
@param[in] value 値
*/
//-----------------------------------------------------------------//
void out0(uint16_t value) const noexcept
{
DAC::DADR0 = value;
}
//-----------------------------------------------------------------//
/*!
@brief 電圧出力0ポートアドレスの取得 @n
32 bits アクセスで、DA0/DA1 を同時に書き込み可能
@return 電圧出力0ポートアドレス
*/
//-----------------------------------------------------------------//
uint32_t get_out0_adr() const noexcept
{
return DAC::DARD0.address;
}
//-----------------------------------------------------------------//
/*!
@brief 電圧出力1(16ビット値)
@param[in] value 値
*/
//-----------------------------------------------------------------//
void out1(uint16_t value) const noexcept
{
DAC::DADR1 = value;
}
//-----------------------------------------------------------------//
/*!
@brief 電圧出力1ポートアドレスの取得
@return 電圧出力1ポートアドレス
*/
//-----------------------------------------------------------------//
uint32_t get_out1_adr() const noexcept
{
return DAC::DARD1.address;
}
};
}