GY-63_MS5611/libraries/DAC8551/DAC8551.h

127 lines
2.7 KiB
C
Raw Permalink Normal View History

2020-11-27 05:10:47 -05:00
#pragma once
2017-12-19 01:47:37 -05:00
//
// FILE: DAC8551.h
// AUTHOR: Rob Tillaart
2023-09-23 11:02:25 -04:00
// PURPOSE: Arduino library for DAC8551 SPI Digital Analog Convertor
2020-11-27 05:10:47 -05:00
// could work with DAC8550, not tested
2024-05-23 13:44:28 -04:00
// VERSION: 0.4.1
2017-12-19 01:47:37 -05:00
// HISTORY: See DAC8551.cpp
2020-11-27 05:10:47 -05:00
// URL: https://github.com/RobTillaart/DAC8551
2017-12-19 01:47:37 -05:00
//
2021-06-02 02:31:14 -04:00
#include "Arduino.h"
2021-01-29 06:31:58 -05:00
#include "SPI.h"
2024-05-23 13:44:28 -04:00
#define DAC8551_LIB_VERSION (F("0.4.1"))
2021-01-29 06:31:58 -05:00
#define DAC8551_POWERDOWN_NORMAL 0
#define DAC8551_POWERDOWN_1K 1
#define DAC8551_POWERDOWN_100K 2
#define DAC8551_POWERDOWN_HIGH_IMP 3
2017-12-19 01:47:37 -05:00
2023-12-02 04:36:26 -05:00
#ifndef __SPI_CLASS__
2024-05-23 13:44:28 -04:00
// MBED must be tested before RP2040
#if defined(ARDUINO_ARCH_MBED)
#define __SPI_CLASS__ SPIClass
#elif defined(ARDUINO_ARCH_RP2040)
2023-12-02 04:36:26 -05:00
#define __SPI_CLASS__ SPIClassRP2040
#else
#define __SPI_CLASS__ SPIClass
#endif
#endif
2017-12-19 01:47:37 -05:00
class DAC8551
{
public:
2023-12-02 04:36:26 -05:00
DAC8551(uint8_t select, __SPI_CLASS__ * spi = &SPI);
DAC8551(uint8_t select, uint8_t spiData, uint8_t spiClock);
2017-12-19 01:47:37 -05:00
2021-01-29 06:31:58 -05:00
void begin();
2017-12-19 01:47:37 -05:00
2021-01-29 06:31:58 -05:00
void setValue(uint16_t value);
2017-12-19 01:47:37 -05:00
uint16_t getValue();
2021-01-29 06:31:58 -05:00
void setPowerDown(uint8_t powerDownMode);
uint8_t getPowerDownMode();
2017-12-19 01:47:37 -05:00
2021-08-29 14:58:12 -04:00
// speed in Hz
void setSPIspeed(uint32_t speed);
uint32_t getSPIspeed() { return _SPIspeed; };
bool usesHWSPI() { return _hwSPI; };
2021-02-06 09:52:51 -05:00
protected:
2021-08-29 14:58:12 -04:00
uint8_t _dataOut = 255;
uint8_t _clock = 255;
uint8_t _select = 255;
bool _hwSPI = false;
uint16_t _value = 0;
uint8_t _register = 0;
uint32_t _SPIspeed = 16000000;
2021-01-29 06:31:58 -05:00
void updateDevice();
void swSPI_transfer(uint8_t value);
2021-08-29 14:58:12 -04:00
2023-12-02 04:36:26 -05:00
__SPI_CLASS__ * _mySPI;
SPISettings _spi_settings;
2017-12-19 01:47:37 -05:00
};
2021-02-06 09:52:51 -05:00
/////////////////////////////////////////////////////////
//
2024-01-20 07:12:45 -05:00
// DERIVED DAC8501, DAC8531, DAC8550
2023-09-23 11:02:25 -04:00
//
2021-02-06 09:52:51 -05:00
#define DAC8501_POWERDOWN_NORMAL 0
#define DAC8501_POWERDOWN_1K 1
#define DAC8501_POWERDOWN_100K 2
#define DAC8501_POWERDOWN_HIGH_IMP 3
class DAC8501 : public DAC8551
{
public:
2023-12-02 04:36:26 -05:00
DAC8501(uint8_t select, __SPI_CLASS__ * spi = &SPI);
DAC8501(uint8_t select, uint8_t spiData, uint8_t spiClock);
2021-02-06 09:52:51 -05:00
};
#define DAC8531_POWERDOWN_NORMAL 0
#define DAC8531_POWERDOWN_1K 1
#define DAC8531_POWERDOWN_100K 2
#define DAC8531_POWERDOWN_HIGH_IMP 3
class DAC8531 : public DAC8551
{
public:
2023-12-02 04:36:26 -05:00
DAC8531(uint8_t select, __SPI_CLASS__ * spi = &SPI);
DAC8531(uint8_t select, uint8_t spiData, uint8_t spiClock);
2021-02-06 09:52:51 -05:00
};
#define DAC8550_POWERDOWN_NORMAL 0
#define DAC8550_POWERDOWN_1K 1
#define DAC8550_POWERDOWN_100K 2
#define DAC8550_POWERDOWN_HIGH_IMP 3
class DAC8550 : public DAC8551
{
public:
2023-12-02 04:36:26 -05:00
DAC8550(uint8_t select, __SPI_CLASS__ * spi = &SPI);
DAC8550(uint8_t select, uint8_t spiData, uint8_t spiClock);
2021-02-06 09:52:51 -05:00
};
2023-12-02 04:36:26 -05:00
// -- END OF FILE --
2021-12-15 06:34:24 -05:00