10#ifndef M5_UNIT_ANADIG_UNIT_GP8413_HPP
11#define M5_UNIT_ANADIG_UNIT_GP8413_HPP
12#include <M5UnitComponent.hpp>
48 M5_UNIT_COMPONENT_HPP_BUILDER(
UnitGP8413, 0x59);
51 static constexpr uint16_t RESOLUTION{0x7FFF};
64 explicit UnitGP8413(
const uint8_t addr = DEFAULT_ADDRESS) : Component(addr)
66 auto ccfg = component_config();
67 ccfg.clock = 400 * 1000U;
68 component_config(ccfg);
74 virtual bool begin()
override;
95 return _range[m5::stl::to_underlying(channel)];
117 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
120 return (mv >= 0.0f) &&
writeVoltage(channel, voltage_to_raw(channel,
static_cast<float>(mv)));
123 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
126 return (mv >= 0.0f) &&
127 writeVoltage(gp8413::Channel::Zero, voltage_to_raw(gp8413::Channel::Zero,
static_cast<float>(mv)));
130 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
133 return (mv >= 0.0f) &&
134 writeVoltage(gp8413::Channel::One, voltage_to_raw(gp8413::Channel::One,
static_cast<float>(mv)));
142 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
145 return writeBothVoltage(voltage_to_raw(gp8413::Channel::Zero,
static_cast<float>(mv0)),
146 voltage_to_raw(gp8413::Channel::One,
static_cast<float>(mv1)));
153 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
156 return (mv >= 0.0f) &&
writeBothVoltage(voltage_to_raw(gp8413::Channel::Zero,
static_cast<float>(mv)),
157 voltage_to_raw(gp8413::Channel::One,
static_cast<float>(mv)));
173 return writeVoltage(gp8413::Channel::Zero,
static_cast<uint16_t
>(raw & RESOLUTION));
178 return writeVoltage(gp8413::Channel::One,
static_cast<uint16_t
>(raw & RESOLUTION));
194 return writeBothVoltage(
static_cast<uint16_t
>(raw & RESOLUTION),
static_cast<uint16_t
>(raw & RESOLUTION));
212 uint16_t voltage_to_raw(
const gp8413::Channel channel,
const float mv);
213 bool write_voltage(
const uint8_t reg,
const uint8_t* buf,
const uint32_t len);
223constexpr uint8_t OUTPUT_RANGE_REG{0x01};
224constexpr uint8_t OUTPUT_CHANNEL0_REG{0x02};
225constexpr uint8_t OUTPUT_CHANNEL1_REG{0x04};
Digital-to-analog signal conversion unit.
Definition unit_GP8413.hpp:47
bool writeChannel1Voltage(const uint16_t raw)
Output the raw value to channel 1.
Definition unit_GP8413.hpp:176
bool storeBothVoltage()
Store the current output voltage to the chip.
Definition unit_GP8413.cpp:99
bool writeVoltage(const gp8413::Channel channel, const T mv)
Output the voltage.
Definition unit_GP8413.hpp:118
bool writeBothVoltage(const uint16_t raw)
Output the raw value to both channel.
Definition unit_GP8413.hpp:192
bool writeBothVoltage(const T mv)
Output the voltage to both channel.
Definition unit_GP8413.hpp:154
bool writeChannel1Voltage(const T mv)
Output the voltage(mV) to channel 1.
Definition unit_GP8413.hpp:131
config_t config()
Gets the configuration.
Definition unit_GP8413.hpp:79
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:171
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:93
void config(const config_t &cfg)
Set the configuration.
Definition unit_GP8413.hpp:84
bool writeChannel0Voltage(const T mv)
Output the voltage(mV) to channel 0.
Definition unit_GP8413.hpp:124
bool writeBothVoltage(const T mv0, const T mv1)
Output the voltage to both channel.
Definition unit_GP8413.hpp:143
Top level namespace of M5Stack.
Settings for begin.
Definition unit_GP8413.hpp:57
gp8413::Output range0
Output range for channel 0.
Definition unit_GP8413.hpp:59
gp8413::Output range1
Output range for channel 1.
Definition unit_GP8413.hpp:61
Output
Output voltage range.
Definition unit_GP8413.hpp:27
Channel
Output channel.
Definition unit_GP8413.hpp:36