|
| | ESP32DAC (uint8_t channel_id=0, float init_voltage=0.0f, float reference_voltage=3.3f) |
| |
| ErrorCode | Write (float voltage) override |
| | 输出 DAC 电压
|
| |
| | DAC ()=default |
| | 默认构造函数
|
| |
Definition at line 20 of file esp_dac.hpp.
◆ ESP32DAC()
| LibXR::ESP32DAC::ESP32DAC |
( |
uint8_t | channel_id = 0, |
|
|
float | init_voltage = 0.0f, |
|
|
float | reference_voltage = 3.3f ) |
|
inlineexplicit |
Definition at line 23 of file esp_dac.hpp.
25 : channel_id_(channel_id), reference_voltage_(reference_voltage)
26 {
27#if SOC_DAC_SUPPORTED
28 if ((channel_id_ >= SOC_DAC_CHAN_NUM) || (reference_voltage_ <= 0.0f))
29 {
30 return;
31 }
32
33 ready_ = true;
34 dac_ll_power_on(ToChannel(channel_id_));
35 dac_ll_rtc_sync_by_adc(false);
36 (void)gpio_config_as_analog(
37 static_cast<gpio_num_t>(dac_periph_signal.dac_channel_io_num[channel_id_]));
38 (void)
Write(init_voltage);
39#else
40 (void)init_voltage;
41#endif
42 }
ErrorCode Write(float voltage) override
输出 DAC 电压
◆ Write()
| ErrorCode LibXR::ESP32DAC::Write |
( |
float | voltage | ) |
|
|
inlineoverridevirtual |
输出 DAC 电压
Outputs the DAC voltage
- Parameters
-
| voltage | 需要输出的模拟电压值 |
| voltage | The analog voltage value to be output |
- Returns
- 错误码 ErrorCode
该方法为纯虚函数,子类必须实现此方法以提供具体的 DAC 输出功能。 This is a pure virtual function. Subclasses must implement this method to provide specific DAC output functionality.
Implements LibXR::DAC.
Definition at line 45 of file esp_dac.hpp.
46 {
47#if SOC_DAC_SUPPORTED
48 if (!ready_)
49 {
51 }
52
53 if (voltage < 0.0f)
54 {
55 voltage = 0.0f;
56 }
57 else if (voltage > reference_voltage_)
58 {
59 voltage = reference_voltage_;
60 }
61
62 constexpr uint32_t kMaxCode = (1U << SOC_DAC_RESOLUTION) - 1U;
63 const float scale = static_cast<float>(kMaxCode) / reference_voltage_;
64 uint32_t code = static_cast<uint32_t>((voltage * scale) + 0.5f);
65 if (code > kMaxCode)
66 {
67 code = kMaxCode;
68 }
69
70 dac_ll_update_output_value(ToChannel(channel_id_), static_cast<uint8_t>(code));
72#else
73 (void)voltage;
75#endif
76 }
@ NOT_SUPPORT
不支持 | Not supported
@ OK
操作成功 | Operation successful
◆ channel_id_
| uint8_t LibXR::ESP32DAC::channel_id_ |
|
private |
◆ ready_
| bool LibXR::ESP32DAC::ready_ = false |
|
private |
◆ reference_voltage_
| float LibXR::ESP32DAC::reference_voltage_ |
|
private |
The documentation for this class was generated from the following file: