libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::MAX11300Driver< Transport, num_devices > Class Template Reference

Device Driver for the MAX11300 20 port ADC/DAC/GPIO device. More...

Detailed Description

template<typename Transport, size_t num_devices>
class daisy::MAX11300Driver< Transport, num_devices >

Device Driver for the MAX11300 20 port ADC/DAC/GPIO device.

Author
sam.braam
Date
Oct. 2021

This is a highly opinionated driver implementation for the MAX11300 DAC/ADC/GPIO device.

This implemetation has been designed for use in the context of Eurorack modular systems. There are a number of features the MAX11300 offers which are not exposed, as well as a number of configuration decisions that were made in order to simplify usage and improve ergonomics, even at the cost of flexibility.

#include <max11300.h>

Classes

struct  Config
 

Public Member Functions

 MAX11300Driver ()
 
 ~MAX11300Driver ()
 
MAX11300Types::Result Init (Config config, MAX11300Types::DmaBuffer *dma_buffer)
 
MAX11300Types::Result ConfigurePinAsDigitalRead (size_t device_index, MAX11300Types::Pin pin, float threshold_voltage)
 
MAX11300Types::Result ConfigurePinAsDigitalWrite (size_t device_index, MAX11300Types::Pin pin, float output_voltage)
 
MAX11300Types::Result ConfigurePinAsAnalogRead (size_t device_index, MAX11300Types::Pin pin, MAX11300Types::AdcVoltageRange range)
 
MAX11300Types::Result ConfigurePinAsAnalogWrite (size_t device_index, MAX11300Types::Pin pin, MAX11300Types::DacVoltageRange range)
 
MAX11300Types::Result DisablePin (size_t device_index, Pin pin)
 
uint16_t ReadAnalogPinRaw (size_t device_index, MAX11300Types::Pin pin) const
 
float ReadAnalogPinVolts (size_t device_index, MAX11300Types::Pin pin) const
 
void WriteAnalogPinRaw (size_t device_index, MAX11300Types::Pin pin, uint16_t raw_value)
 
void WriteAnalogPinVolts (size_t device_index, MAX11300Types::Pin pin, float voltage)
 
bool ReadDigitalPin (size_t device_index, MAX11300Types::Pin pin) const
 
void WriteDigitalPin (size_t device_index, MAX11300Types::Pin pin, bool value)
 
MAX11300Types::Result Start (MAX11300Types::UpdateCompleteCallbackFunctionPtr complete_callback=nullptr, void *complete_callback_context=nullptr)
 
void Stop ()
 

Static Public Member Functions

static uint16_t VoltsTo12BitUint (float volts, MAX11300Types::DacVoltageRange range)
 
static float TwelveBitUintToVolts (uint16_t value, MAX11300Types::AdcVoltageRange range)
 

Constructor & Destructor Documentation

◆ MAX11300Driver()

template<typename Transport , size_t num_devices>
daisy::MAX11300Driver< Transport, num_devices >::MAX11300Driver ( )
inline

◆ ~MAX11300Driver()

template<typename Transport , size_t num_devices>
daisy::MAX11300Driver< Transport, num_devices >::~MAX11300Driver ( )
inline

Member Function Documentation

◆ ConfigurePinAsAnalogRead()

template<typename Transport , size_t num_devices>
MAX11300Types::Result daisy::MAX11300Driver< Transport, num_devices >::ConfigurePinAsAnalogRead ( size_t  device_index,
MAX11300Types::Pin  pin,
MAX11300Types::AdcVoltageRange  range 
)
inline

◆ ConfigurePinAsAnalogWrite()

template<typename Transport , size_t num_devices>
MAX11300Types::Result daisy::MAX11300Driver< Transport, num_devices >::ConfigurePinAsAnalogWrite ( size_t  device_index,
MAX11300Types::Pin  pin,
MAX11300Types::DacVoltageRange  range 
)
inline

◆ ConfigurePinAsDigitalRead()

template<typename Transport , size_t num_devices>
MAX11300Types::Result daisy::MAX11300Driver< Transport, num_devices >::ConfigurePinAsDigitalRead ( size_t  device_index,
MAX11300Types::Pin  pin,
float  threshold_voltage 
)
inline

◆ ConfigurePinAsDigitalWrite()

template<typename Transport , size_t num_devices>
MAX11300Types::Result daisy::MAX11300Driver< Transport, num_devices >::ConfigurePinAsDigitalWrite ( size_t  device_index,
MAX11300Types::Pin  pin,
float  output_voltage 
)
inline

◆ DisablePin()

template<typename Transport , size_t num_devices>
MAX11300Types::Result daisy::MAX11300Driver< Transport, num_devices >::DisablePin ( size_t  device_index,
Pin  pin 
)
inline

◆ Init()

template<typename Transport , size_t num_devices>
MAX11300Types::Result daisy::MAX11300Driver< Transport, num_devices >::Init ( Config  config,
MAX11300Types::DmaBuffer dma_buffer 
)
inline

Initialize the MAX11300

This method verifies SPI connectivity, configures the chip to operate within the scope of this implementation, and intitalizes all pins by default to High-Z mode.

Parameters
config- The MAX11300 configuration
dma_buffera buffer in DMA-accessible memory. Allocate it like this: MAX11300DmaBuffer DMA_BUFFER_MEM_SECTION myBuffer;

◆ ReadAnalogPinRaw()

template<typename Transport , size_t num_devices>
uint16_t daisy::MAX11300Driver< Transport, num_devices >::ReadAnalogPinRaw ( size_t  device_index,
MAX11300Types::Pin  pin 
) const
inline

Read the raw 12 bit (0-4095) value of a given ANALOG_IN (ADC) pin.

*note this read is local, call MAX11300::Start() to sync with the MAX11300

Parameters
pin- The pin of which to read the value
Returns
- The raw, 12 bit value of the given ANALOG_IN (ADC) pin.

◆ ReadAnalogPinVolts()

template<typename Transport , size_t num_devices>
float daisy::MAX11300Driver< Transport, num_devices >::ReadAnalogPinVolts ( size_t  device_index,
MAX11300Types::Pin  pin 
) const
inline

Read the value of a given ADC pin in volts.

*note this read is local, call MAX11300::Start() to sync with the MAX11300

Parameters
pin- The pin of which to read the voltage
Returns
- The value of the given ANALOG_IN (ADC) pin in volts

◆ ReadDigitalPin()

template<typename Transport , size_t num_devices>
bool daisy::MAX11300Driver< Transport, num_devices >::ReadDigitalPin ( size_t  device_index,
MAX11300Types::Pin  pin 
) const
inline

Read the state of a GPI pin

*note this read is local, call MAX11300::Start() to sync with the MAX11300

Parameters
pin- The pin of which to read the value
Returns
- The boolean state of the pin

◆ Start()

template<typename Transport , size_t num_devices>
MAX11300Types::Result daisy::MAX11300Driver< Transport, num_devices >::Start ( MAX11300Types::UpdateCompleteCallbackFunctionPtr  complete_callback = nullptr,
void complete_callback_context = nullptr 
)
inline

Starts to update and synchronize the MAX11300 - This method does the following:

  • Write all current ANALOG_OUT (DAC) values to all MAX11300s
  • Read all current ANALOG_IN (ADC) values to memory
  • Write all GPO states to all MAX11300s
  • Read all GPI states to memory
  • call the provided callback function when complete (from an interrupt)
  • repeat

The driver can be stopped by calling Stop().

See also
Stop()
Parameters
complete_callbackAn optional callback function that's called after each successful update Keep this callback function simple and fast, it's called from an interrupt.
complete_callback_contextAn optional context pointer provided to the complete_callback

◆ Stop()

template<typename Transport , size_t num_devices>
void daisy::MAX11300Driver< Transport, num_devices >::Stop ( )
inline

Call this to stop the auto updating, but complete the current update.

◆ TwelveBitUintToVolts()

template<typename Transport , size_t num_devices>
static float daisy::MAX11300Driver< Transport, num_devices >::TwelveBitUintToVolts ( uint16_t  value,
MAX11300Types::AdcVoltageRange  range 
)
inlinestatic

A utility funtion for converting the first 12 bits (0-4095) of an unsigned 16 bit integer value, to a voltage (float) value. The voltage value is scaled and bound to the given voltage range.

Parameters
valuethe 12 bit value to convert
rangethe MAX11300Types::AdcVoltageRange to constrain to
Returns
the value as a float voltage constrained to the given voltage range

◆ VoltsTo12BitUint()

template<typename Transport , size_t num_devices>
static uint16_t daisy::MAX11300Driver< Transport, num_devices >::VoltsTo12BitUint ( float  volts,
MAX11300Types::DacVoltageRange  range 
)
inlinestatic

A utility funtion for converting a voltage (float) value, bound to a given voltage range, to the first 12 bits (0-4095) of an unsigned 16 bit integer value.

Parameters
voltsthe voltage to convert
rangethe MAX11300Types::DacVoltageRange to constrain to
Returns
the voltage as 12 bit unsigned integer

◆ WriteAnalogPinRaw()

template<typename Transport , size_t num_devices>
void daisy::MAX11300Driver< Transport, num_devices >::WriteAnalogPinRaw ( size_t  device_index,
MAX11300Types::Pin  pin,
uint16_t  raw_value 
)
inline

Write a raw 12 bit (0-4095) value to a given ANALOG_OUT (DAC) pin

*note this write is local, call MAX11300::Start() to sync with the MAX11300

Parameters
pin- The pin of which to write the value
raw_value- the 12-bit code to write to the given Pin

◆ WriteAnalogPinVolts()

template<typename Transport , size_t num_devices>
void daisy::MAX11300Driver< Transport, num_devices >::WriteAnalogPinVolts ( size_t  device_index,
MAX11300Types::Pin  pin,
float  voltage 
)
inline

Write a voltage value, within the bounds of the configured volatge range, to a given ANALOG_OUT (DAC) pin.

*note this write is local, call MAX11300::Start() to sync with the MAX11300

Parameters
pin- The pin of which to write the voltage
voltage- Target voltage

◆ WriteDigitalPin()

template<typename Transport , size_t num_devices>
void daisy::MAX11300Driver< Transport, num_devices >::WriteDigitalPin ( size_t  device_index,
MAX11300Types::Pin  pin,
bool  value 
)
inline

Write a digital state to the given GPO pin

*note this write is local, call MAX11300::Start() to sync with the MAX11300

Parameters
pin- The pin of which to write the value
value- the boolean state to write

The documentation for this class was generated from the following file: