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));
144 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, std::nullptr_t>::type =
nullptr>
147 return (mv >= 0.0f) &&
writeBothVoltage(voltage_to_raw(gp8413::Channel::Zero, (
float)mv),
148 voltage_to_raw(gp8413::Channel::One, (
float)mv));
163 template <typename T, typename std::enable_if<!std::is_same<uint16_t, T>::value && std::is_unsigned<T>::value,
164 std::nullptr_t>::type =
nullptr>
167 return writeVoltage(channel,
static_cast<uint16_t
>(raw & RESOLUTION));
170 template <typename T, typename std::enable_if<!std::is_same<uint16_t, T>::value && std::is_unsigned<T>::value,
171 std::nullptr_t>::type =
nullptr>
174 return writeVoltage(gp8413::Channel::Zero,
static_cast<uint16_t
>(raw & RESOLUTION));
177 template <typename T, typename std::enable_if<!std::is_same<uint16_t, T>::value && std::is_unsigned<T>::value,
178 std::nullptr_t>::type =
nullptr>
181 return writeVoltage(gp8413::Channel::One,
static_cast<uint16_t
>(raw & RESOLUTION));
191 template <typename T, typename std::enable_if<!std::is_same<uint16_t, T>::value && std::is_unsigned<T>::value,
192 std::nullptr_t>::type =
nullptr>
195 return writeBothVoltage(
static_cast<uint16_t
>(raw0 & RESOLUTION),
static_cast<uint16_t
>(raw1 & RESOLUTION));
203 template <typename T, typename std::enable_if<!std::is_same<uint16_t, T>::value && std::is_unsigned<T>::value,
204 std::nullptr_t>::type =
nullptr>
207 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);
224constexpr uint8_t OUTPUT_RANGE{0x01};
225constexpr uint8_t OUTPUT_CHANNEL_0{0x02};
226constexpr uint8_t OUTPUT_CHANNEL_1{0x04};
Digital-to-analog signal conversion unit.
Definition unit_GP8413.hpp:39
bool writeVoltage(const gp8413::Channel channel, const T mv)
Output the voltage.
Definition unit_GP8413.hpp:110
bool writeBothVoltage(const T mv)
Output the voltage to both channel.
Definition unit_GP8413.hpp:145
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:36
bool writeVoltage(const gp8413::Channel channel, const T raw)
Output the raw value.
Definition unit_GP8413.hpp:165
bool writeBothVoltage(const T raw0, const T raw1)
Output the raw value to both channel.
Definition unit_GP8413.hpp:193
bool writeOutputRange(const gp8413::Output range0, const gp8413::Output range1)
Write the output range.
Definition unit_GP8413.cpp:46
bool writeBothVoltage(const T raw)
Output the raw value to both channel.
Definition unit_GP8413.hpp:205
bool writeChannel0Voltage(const T raw)
Output the raw value to channel 0.
Definition unit_GP8413.hpp:172
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 writeChannel1Voltage(const T raw)
Output the raw value to channel 1.
Definition unit_GP8413.hpp:179
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