2020-11-27 05:10:47 -05:00
|
|
|
#pragma once
|
2017-12-19 05:44:03 -05:00
|
|
|
//
|
|
|
|
// FILE: DAC8554.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2020-11-27 05:10:47 -05:00
|
|
|
// PURPOSE: Arduino library for DAC8554 SPI Digital Analog Convertor
|
2024-01-20 07:43:39 -05:00
|
|
|
// VERSION: 0.4.0
|
2023-10-19 09:28:53 -04:00
|
|
|
// DATE: 2017-12-19
|
2020-11-27 05:10:47 -05:00
|
|
|
// URL: https://github.com/RobTillaart/DAC8554
|
2017-12-19 05:44:03 -05:00
|
|
|
//
|
|
|
|
|
2021-06-02 02:50:22 -04:00
|
|
|
#include "Arduino.h"
|
2020-11-27 05:10:47 -05:00
|
|
|
#include "SPI.h"
|
2017-12-19 05:44:03 -05:00
|
|
|
|
2024-01-20 07:43:39 -05:00
|
|
|
#define DAC8554_LIB_VERSION (F("0.4.0"))
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-12-15 08:57:49 -05:00
|
|
|
#define DAC8554_POWERDOWN_NORMAL 0x00
|
|
|
|
#define DAC8554_POWERDOWN_1K 0x40
|
|
|
|
#define DAC8554_POWERDOWN_100K 0x80
|
|
|
|
#define DAC8554_POWERDOWN_HIGH_IMP 0xC0
|
2017-12-19 05:44:03 -05:00
|
|
|
|
|
|
|
|
2023-12-02 04:49:47 -05:00
|
|
|
#ifndef __SPI_CLASS__
|
|
|
|
#if defined(ARDUINO_ARCH_RP2040)
|
|
|
|
#define __SPI_CLASS__ SPIClassRP2040
|
|
|
|
#else
|
|
|
|
#define __SPI_CLASS__ SPIClass
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2017-12-19 05:44:03 -05:00
|
|
|
class DAC8554
|
|
|
|
{
|
|
|
|
public:
|
2022-10-31 11:49:34 -04:00
|
|
|
// hardware SPI constructor
|
2023-12-02 04:49:47 -05:00
|
|
|
DAC8554(uint8_t select, __SPI_CLASS__ * spi = &SPI, uint8_t address = 0);
|
2022-10-31 11:49:34 -04:00
|
|
|
// software SPI constructor
|
2023-12-02 04:49:47 -05:00
|
|
|
DAC8554(uint8_t select, uint8_t spiData, uint8_t spiClock, uint8_t address = 0);
|
2017-12-19 05:44:03 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void begin();
|
2017-12-19 05:44:03 -05:00
|
|
|
|
2021-12-15 08:57:49 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void bufferValue(uint8_t channel, uint16_t value);
|
|
|
|
void setValue(uint8_t channel, uint16_t value);
|
|
|
|
uint16_t getValue(uint8_t channel);
|
2022-10-31 11:49:34 -04:00
|
|
|
// writes the value to the channel but does not affect buffered ones
|
2021-01-29 06:31:58 -05:00
|
|
|
void setSingleValue(uint8_t channel, uint16_t value);
|
2017-12-19 05:44:03 -05:00
|
|
|
|
2021-12-15 08:57:49 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void bufferPowerDown(uint8_t channel, uint8_t powerDownMode);
|
|
|
|
void setPowerDown(uint8_t channel, uint8_t powerDownMode);
|
|
|
|
uint8_t getPowerDownMode(uint8_t channel);
|
|
|
|
void setSinglePowerDown(uint8_t channel, uint8_t powerDownMode);
|
2017-12-19 05:44:03 -05:00
|
|
|
|
2021-12-15 08:57:49 -05:00
|
|
|
|
2022-10-31 11:49:34 -04:00
|
|
|
// write all buffers to all(up to 4) 8554's channel's
|
2021-01-29 06:31:58 -05:00
|
|
|
void broadcastBuffer();
|
2022-10-31 11:49:34 -04:00
|
|
|
// write value to all(up to 4) 8554's channel's
|
2021-01-29 06:31:58 -05:00
|
|
|
void broadcastValue(uint16_t value);
|
2022-10-31 11:49:34 -04:00
|
|
|
// write powerDownMode to all 8554's channel's
|
2021-01-29 06:31:58 -05:00
|
|
|
void broadcastPowerDown(uint8_t powerDownMode);
|
2017-12-19 05:44:03 -05:00
|
|
|
|
2021-12-15 08:57:49 -05:00
|
|
|
|
2021-08-30 08:09:24 -04:00
|
|
|
// speed in Hz
|
|
|
|
void setSPIspeed(uint32_t speed);
|
|
|
|
uint32_t getSPIspeed() { return _SPIspeed; };
|
|
|
|
bool usesHWSPI() { return _hwSPI; };
|
|
|
|
|
2021-12-15 08:57:49 -05:00
|
|
|
|
2023-12-02 04:49:47 -05:00
|
|
|
protected:
|
2021-08-30 08:09:24 -04:00
|
|
|
uint8_t _dataOut = 255;
|
|
|
|
uint8_t _clock = 255;
|
|
|
|
uint8_t _select = 255;
|
|
|
|
|
|
|
|
bool _hwSPI = false;
|
2023-12-02 04:49:47 -05:00
|
|
|
uint8_t _address = 0;
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2022-10-31 11:49:34 -04:00
|
|
|
uint16_t _value[4]; // holds last written / buffered value per channel
|
|
|
|
uint8_t _register[4]; // holds powerDownMode per channel
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-08-30 08:09:24 -04:00
|
|
|
uint32_t _SPIspeed = 16000000;
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void writeDevice(uint8_t configRegister, uint16_t value);
|
|
|
|
void swSPI_transfer(uint8_t value);
|
2021-08-30 08:09:24 -04:00
|
|
|
|
2021-12-15 08:57:49 -05:00
|
|
|
|
2023-12-02 04:49:47 -05:00
|
|
|
__SPI_CLASS__ * _mySPI;
|
2021-08-30 08:09:24 -04:00
|
|
|
SPISettings _spi_settings;
|
2023-12-02 04:49:47 -05:00
|
|
|
};
|
2021-08-30 08:09:24 -04:00
|
|
|
|
2023-12-02 04:49:47 -05:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// DERIVED DAC8534
|
|
|
|
//
|
|
|
|
|
|
|
|
#define DAC8534_POWERDOWN_NORMAL 0
|
|
|
|
#define DAC8534_POWERDOWN_1K 1
|
|
|
|
#define DAC8534_POWERDOWN_100K 2
|
|
|
|
#define DAC8534_POWERDOWN_HIGH_IMP 3
|
|
|
|
|
|
|
|
|
|
|
|
class DAC8534 : public DAC8554
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DAC8534(uint8_t select, __SPI_CLASS__ * spi = &SPI, uint8_t address = 0);
|
|
|
|
DAC8534(uint8_t select, uint8_t spiData, uint8_t spiClock, uint8_t address = 0);
|
2017-12-19 05:44:03 -05:00
|
|
|
};
|
|
|
|
|
2021-12-15 08:57:49 -05:00
|
|
|
|
2023-10-19 09:28:53 -04:00
|
|
|
// -- END OF FILE --
|
2021-12-15 08:57:49 -05:00
|
|
|
|