10#ifndef M5_UNIT_ANADIG_UNIT_GP8413_HPP
11#define M5_UNIT_ANADIG_UNIT_GP8413_HPP
12#include <M5UnitComponent.hpp>
40 M5_UNIT_COMPONENT_HPP_BUILDER(
UnitGP8413, 0x59);
43 static constexpr uint16_t RESOLUTION{0x7FFF};
56 explicit UnitGP8413(
const uint8_t addr = DEFAULT_ADDRESS) : Component(addr)
58 auto ccfg = component_config();
59 ccfg.clock = 400 * 1000U;
60 component_config(ccfg);
66 virtual bool begin()
override;
87 return _range[m5::stl::to_underlying(channel)];
109 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
112 return (mv >= 0.0f) &&
writeVoltage(channel, voltage_to_raw(channel, (
float)mv));
115 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
118 return (mv >= 0.0f) &&
writeVoltage(gp8413::Channel::Zero, voltage_to_raw(gp8413::Channel::Zero, (
float)mv));
121 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
124 return (mv >= 0.0f) &&
writeVoltage(gp8413::Channel::One, voltage_to_raw(gp8413::Channel::One, (
float)mv));
132 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
136 voltage_to_raw(gp8413::Channel::One, (
float)mv1));
143 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
146 return (mv >= 0.0f) &&
writeBothVoltage(voltage_to_raw(gp8413::Channel::Zero, (
float)mv),
147 voltage_to_raw(gp8413::Channel::One, (
float)mv));
163 return writeVoltage(gp8413::Channel::Zero,
static_cast<uint16_t
>(raw & RESOLUTION));
168 return writeVoltage(gp8413::Channel::One,
static_cast<uint16_t
>(raw & RESOLUTION));
184 return writeBothVoltage(
static_cast<uint16_t
>(raw & RESOLUTION),
static_cast<uint16_t
>(raw & RESOLUTION));
202 uint16_t voltage_to_raw(
const gp8413::Channel channel,
const float mv);
203 bool write_voltage(
const uint8_t reg,
const uint8_t* buf,
const uint32_t len);
213constexpr uint8_t OUTPUT_RANGE_REG{0x01};
214constexpr uint8_t OUTPUT_CHANNEL0_REG{0x02};
215constexpr uint8_t OUTPUT_CHANNEL1_REG{0x04};
Digital-to-analog signal conversion unit.
Definition unit_GP8413.hpp:39
bool writeChannel1Voltage(const uint16_t raw)
Output the raw value to channel 1.
Definition unit_GP8413.hpp:166
bool storeBothVoltage()
Store the current output voltage to the chip.
Definition unit_GP8413.cpp:98
bool writeVoltage(const gp8413::Channel channel, const T mv)
Output the voltage.
Definition unit_GP8413.hpp:110
bool writeBothVoltage(const uint16_t raw)
Output the raw value to both channel.
Definition unit_GP8413.hpp:182
bool writeBothVoltage(const T mv)
Output the voltage to both channel.
Definition unit_GP8413.hpp:144
bool writeChannel1Voltage(const T mv)
Output the voltage(mV) to channel 1.
Definition unit_GP8413.hpp:122
config_t config()
Gets the configration.
Definition unit_GP8413.hpp:71
float maximumVoltage(const gp8413::Channel channel) const
Get the maximum voltage of the channel.
Definition unit_GP8413.cpp:51
bool writeChannel0Voltage(const uint16_t raw)
Output the raw value to channel 0.
Definition unit_GP8413.hpp:161
bool writeOutputRange(const gp8413::Output range0, const gp8413::Output range1)
Write the output range.
Definition unit_GP8413.cpp:61
gp8413::Output range(const gp8413::Channel channel) const
Gets the inner range.
Definition unit_GP8413.hpp:85
void config(const config_t &cfg)
Set the configration.
Definition unit_GP8413.hpp:76
bool writeChannel0Voltage(const T mv)
Output the voltage(mV) to channel 0.
Definition unit_GP8413.hpp:116
bool writeBothVoltage(const T mv0, const T mv1)
Output the voltage to both channel.
Definition unit_GP8413.hpp:133
Top level namespace of M5stack.
Settings for begin.
Definition unit_GP8413.hpp:49
gp8413::Output range0
Output range for channel 0.
Definition unit_GP8413.hpp:51
gp8413::Output range1
Output range for channel 1.
Definition unit_GP8413.hpp:53
Output
Definition unit_GP8413.hpp:23
Channel
Definition unit_GP8413.hpp:28