M5Unit-ANADIG 0.4.1 git rev:a449179
Loading...
Searching...
No Matches
m5::unit::UnitGP8413 Class Reference

Digital-to-analog signal conversion unit. More...

#include <unit_GP8413.hpp>

Inheritance diagram for m5::unit::UnitGP8413:

Classes

struct  config_t
 Settings for begin. More...
 

Public Member Functions

 UnitGP8413 (const uint8_t addr=DEFAULT_ADDRESS)
 Constructor.
 
virtual bool begin () override
 Initialize the unit and apply config_t (output ranges)
 
Settings for begin
config_t config ()
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
Settings
gp8413::Output range (const gp8413::Channel channel) const
 Gets the output range set for the channel.
 
float maximumVoltage (const gp8413::Channel channel) const
 Gets the maximum voltage of the channel.
 
bool writeOutputRange (const gp8413::Output range0, const gp8413::Output range1)
 Write the output range.
 
Output the voltage
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool writeVoltage (const gp8413::Channel channel, const T mv)
 Output the voltage.
 
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool writeChannel0Voltage (const T mv)
 Output the voltage to channel 0.
 
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool writeChannel1Voltage (const T mv)
 Output the voltage to channel 1.
 
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool writeBothVoltage (const T mv0, const T mv1)
 Output the voltage to both channels.
 
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool writeBothVoltage (const T mv)
 Output the voltage to both channels.
 
Output the raw value
bool writeVoltage (const gp8413::Channel channel, const uint16_t raw)
 Output the raw value.
 
bool writeChannel0Voltage (const uint16_t raw)
 Output the raw value to channel 0.
 
bool writeChannel1Voltage (const uint16_t raw)
 Output the raw value to channel 1.
 
bool writeBothVoltage (const uint16_t raw0, const uint16_t raw1)
 Output the raw value to both channels.
 
bool writeBothVoltage (const uint16_t raw)
 Output the raw value to both channels.
 
Store output voltage
Note
The GP8413 supports storing voltage data in the chip to ensure that the voltage output state remains in the corresponding state after power-down or start-up.
bool storeBothVoltage ()
 Store the current output voltage to the chip.
 

Static Public Attributes

static constexpr uint16_t RESOLUTION {0x7FFF}
 Maximum raw output value (15 bits)
 

Protected Member Functions

uint16_t voltage_to_raw (const gp8413::Channel channel, const float mv) const
 
bool write_voltage (const uint8_t reg, const uint8_t *buf, const uint32_t len)
 

Detailed Description

Digital-to-analog signal conversion unit.

Constructor & Destructor Documentation

◆ UnitGP8413()

m5::unit::UnitGP8413::UnitGP8413 ( const uint8_t addr = DEFAULT_ADDRESS)
inlineexplicit

Constructor.

Parameters
addrI2C address

Member Function Documentation

◆ begin()

bool m5::unit::UnitGP8413::begin ( )
overridevirtual

Initialize the unit and apply config_t (output ranges)

Returns
True if successful

◆ maximumVoltage()

float m5::unit::UnitGP8413::maximumVoltage ( const gp8413::Channel channel) const

Gets the maximum voltage of the channel.

Parameters
channelTarget channel
Returns
Maximum voltage (mV) of the current output range

◆ range()

gp8413::Output m5::unit::UnitGP8413::range ( const gp8413::Channel channel) const
inline

Gets the output range set for the channel.

Parameters
channelTarget channel
Returns
Output range

◆ storeBothVoltage()

bool m5::unit::UnitGP8413::storeBothVoltage ( )

Store the current output voltage to the chip.

The stored voltage is output when the chip is powered on (until the output is written again). The store sequence cannot be generated by the I2C controller, so the I2C bus is released and the sequence is bit-banged on the SDA/SCL pins, then the bus is restored. Supported buses: Arduino TwoWire (including the LP I2C Wire1, e.g. NessoN1 Hat port), m5::I2C_Class (M5.Ex_I2C etc.), M5HAL software I2C, ESP-IDF native I2C drivers, and via a hub (PaHub etc.) connected to one of these

Returns
True if successful. False if the chip does not acknowledge the store sequence (e.g. not connected)
Warning
Not supported on the ESP-IDF native I2C drivers when the pins are not routed through the GPIO matrix (LP I2C) (returns false)
Other devices on the same bus cannot be accessed during the store (about 10 ms). Blocked until complete
Note that the output range is not stored
Note
The chip has no read command, so the stored value can only be checked by power-cycling the unit and measuring the output

◆ writeBothVoltage() [1/4]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitGP8413::writeBothVoltage ( const T mv)
inline

Output the voltage to both channels.

Parameters
mvOutput voltage(mV) to both channels
Returns
True if successful
Note
Negative values return false. Values exceeding the output range are clamped

◆ writeBothVoltage() [2/4]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitGP8413::writeBothVoltage ( const T mv0,
const T mv1 )
inline

Output the voltage to both channels.

Parameters
mv0Output voltage(mV) to channel 0
mv1Output voltage(mV) to channel 1
Returns
True if successful
Note
Negative values return false. Values exceeding the output range are clamped

◆ writeBothVoltage() [3/4]

bool m5::unit::UnitGP8413::writeBothVoltage ( const uint16_t raw)
inline

Output the raw value to both channels.

Parameters
rawOutput raw value to both channels (masked with RESOLUTION)
Returns
True if successful

◆ writeBothVoltage() [4/4]

bool m5::unit::UnitGP8413::writeBothVoltage ( const uint16_t raw0,
const uint16_t raw1 )

Output the raw value to both channels.

Parameters
raw0Output raw value to channel 0 (masked with RESOLUTION)
raw1Output raw value to channel 1 (masked with RESOLUTION)
Returns
True if successful

◆ writeChannel0Voltage() [1/2]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitGP8413::writeChannel0Voltage ( const T mv)
inline

Output the voltage to channel 0.

Parameters
mvOutput voltage(mV)
Returns
True if successful
Note
Negative values return false. Values exceeding the output range are clamped

◆ writeChannel0Voltage() [2/2]

bool m5::unit::UnitGP8413::writeChannel0Voltage ( const uint16_t raw)
inline

Output the raw value to channel 0.

Parameters
rawOutput raw value (masked with RESOLUTION)
Returns
True if successful

◆ writeChannel1Voltage() [1/2]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitGP8413::writeChannel1Voltage ( const T mv)
inline

Output the voltage to channel 1.

Parameters
mvOutput voltage(mV)
Returns
True if successful
Note
Negative values return false. Values exceeding the output range are clamped

◆ writeChannel1Voltage() [2/2]

bool m5::unit::UnitGP8413::writeChannel1Voltage ( const uint16_t raw)
inline

Output the raw value to channel 1.

Parameters
rawOutput raw value (masked with RESOLUTION)
Returns
True if successful

◆ writeOutputRange()

bool m5::unit::UnitGP8413::writeOutputRange ( const gp8413::Output range0,
const gp8413::Output range1 )

Write the output range.

Parameters
range0Output range to channel 0
range1Output range to channel 1
Returns
True if successful

◆ writeVoltage() [1/2]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitGP8413::writeVoltage ( const gp8413::Channel channel,
const T mv )
inline

Output the voltage.

Parameters
channelChannel to output
mvOutput voltage(mV)
Returns
True if successful
Note
Negative values return false. Values exceeding the output range are clamped

◆ writeVoltage() [2/2]

bool m5::unit::UnitGP8413::writeVoltage ( const gp8413::Channel channel,
const uint16_t raw )

Output the raw value.

Parameters
channelChannel to output
rawOutput raw value (masked with RESOLUTION)
Returns
True if successful