Silence unused-variable warning (#2872)
[ExpressLRS.git] / src / lib / DAC / DAC.cpp
blobf23911b77e20371db737137293d4e056ee8e46c3
2 #include "DAC.h"
4 #if defined(POWER_OUTPUT_DAC)
5 #include "helpers.h"
6 #include "logging.h"
7 #include <Wire.h>
9 #ifndef DAC_REF_VCC
10 #define DAC_REF_VCC 3300
11 #endif
13 void DAC::init()
15 DBGLN("Init DAC Driver");
17 // I2C initialization is the responsibility of the caller
18 // e.g. Wire.begin(GPIO_PIN_SDA, GPIO_PIN_SCL);
20 m_state = UNKNOWN;
23 void DAC::standby()
25 if (m_state != STANDBY)
27 Wire.beginTransmission(POWER_OUTPUT_DAC);
28 Wire.write(0x00);
29 Wire.write(0x00);
30 Wire.endTransmission();
31 m_state = STANDBY;
35 void DAC::resume()
37 if (m_state != RUNNING)
39 DAC::setVoltageRegDirect(m_currVoltageRegVal);
43 void DAC::setVoltageRegDirect(uint8_t voltReg)
45 m_currVoltageRegVal = voltReg;
46 uint8_t RegH = ((voltReg & 0b11110000) >> 4) + (0b0000 << 4);
47 uint8_t RegL = (voltReg & 0b00001111) << 4;
49 Wire.beginTransmission(POWER_OUTPUT_DAC);
50 Wire.write(RegH);
51 Wire.write(RegL);
52 Wire.endTransmission();
55 void DAC::setPower(uint32_t milliVolts)
57 uint8_t ScaledVolts = map(milliVolts, 0, DAC_REF_VCC, 0, 255);
58 setVoltageRegDirect(ScaledVolts);
59 DBGLN("DAC::setPower(%umV)", milliVolts);
62 DAC TxDAC;
64 #endif // defined(POWER_OUTPUT_DAC)