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);
69 explicit UnitGP8413(
const uint8_t addr = DEFAULT_ADDRESS) : Component(addr)
71 auto ccfg = component_config();
72 ccfg.clock = 400 * 1000U;
73 component_config(ccfg);
83 virtual bool begin()
override;
108 return _range[m5::stl::to_underlying(channel)];
134 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
137 return (mv >= 0.0f) &&
writeVoltage(channel, voltage_to_raw(channel,
static_cast<float>(mv)));
145 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
148 return (mv >= 0.0f) &&
149 writeVoltage(gp8413::Channel::Zero, voltage_to_raw(gp8413::Channel::Zero,
static_cast<float>(mv)));
157 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
160 return (mv >= 0.0f) &&
161 writeVoltage(gp8413::Channel::One, voltage_to_raw(gp8413::Channel::One,
static_cast<float>(mv)));
170 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
173 return (mv0 >= 0.0f) && (mv1 >= 0.0f) &&
174 writeBothVoltage(voltage_to_raw(gp8413::Channel::Zero,
static_cast<float>(mv0)),
175 voltage_to_raw(gp8413::Channel::One,
static_cast<float>(mv1)));
183 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
186 return (mv >= 0.0f) &&
writeBothVoltage(voltage_to_raw(gp8413::Channel::Zero,
static_cast<float>(mv)),
187 voltage_to_raw(gp8413::Channel::One,
static_cast<float>(mv)));
260 uint16_t voltage_to_raw(
const gp8413::Channel channel,
const float mv)
const;
261 bool write_voltage(
const uint8_t reg,
const uint8_t* buf,
const uint32_t len);
271constexpr uint8_t OUTPUT_RANGE_REG{0x01};
272constexpr uint8_t OUTPUT_CHANNEL0_REG{0x02};
273constexpr 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:214
bool storeBothVoltage()
Store the current output voltage to the chip.
Definition unit_GP8413.cpp:220
bool writeVoltage(const gp8413::Channel channel, const T mv)
Output the voltage.
Definition unit_GP8413.hpp:135
bool writeBothVoltage(const uint16_t raw)
Output the raw value to both channels.
Definition unit_GP8413.hpp:230
static constexpr uint16_t RESOLUTION
Maximum raw output value (15 bits)
Definition unit_GP8413.hpp:52
bool writeBothVoltage(const T mv)
Output the voltage to both channels.
Definition unit_GP8413.hpp:184
bool writeChannel1Voltage(const T mv)
Output the voltage to channel 1.
Definition unit_GP8413.hpp:158
config_t config()
Gets the configuration.
Definition unit_GP8413.hpp:88
virtual bool begin() override
Initialize the unit and apply config_t (output ranges)
Definition unit_GP8413.cpp:174
float maximumVoltage(const gp8413::Channel channel) const
Gets the maximum voltage of the channel.
Definition unit_GP8413.cpp:169
bool writeChannel0Voltage(const uint16_t raw)
Output the raw value to channel 0.
Definition unit_GP8413.hpp:205
bool writeOutputRange(const gp8413::Output range0, const gp8413::Output range1)
Write the output range.
Definition unit_GP8413.cpp:179
UnitGP8413(const uint8_t addr=DEFAULT_ADDRESS)
Constructor.
Definition unit_GP8413.hpp:69
gp8413::Output range(const gp8413::Channel channel) const
Gets the output range set for the channel.
Definition unit_GP8413.hpp:106
void config(const config_t &cfg)
Set the configuration.
Definition unit_GP8413.hpp:93
bool writeChannel0Voltage(const T mv)
Output the voltage to channel 0.
Definition unit_GP8413.hpp:146
bool writeBothVoltage(const T mv0, const T mv1)
Output the voltage to both channels.
Definition unit_GP8413.hpp:171
Top level namespace of M5Stack.
Settings for begin.
Definition unit_GP8413.hpp:58
gp8413::Output range0
Output range for channel 0.
Definition unit_GP8413.hpp:60
gp8413::Output range1
Output range for channel 1.
Definition unit_GP8413.hpp:62
Output
Output voltage range.
Definition unit_GP8413.hpp:27
Channel
Output channel.
Definition unit_GP8413.hpp:36