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

84 lines
1.9 KiB
C
Raw Normal View History

2020-11-27 05:10:47 -05:00
#pragma once
//
2020-11-27 05:10:47 -05:00
// FILE: DAC8552.h
// AUTHOR: Rob Tillaart
2020-11-27 05:10:47 -05:00
// PURPOSE: Arduino library for DAC8552 SPI Digital Analog Convertor
2021-12-15 06:48:53 -05:00
// VERSION: 0.2.3
// HISTORY: See DAC8552.cpp
2020-11-27 05:10:47 -05:00
// URL: https://github.com/RobTillaart/DAC8552
//
2021-06-02 02:54:12 -04:00
#include "Arduino.h"
2021-01-29 06:31:58 -05:00
#include "SPI.h"
2021-12-15 06:48:53 -05:00
#define DAC8552_LIB_VERSION (F("0.2.3"))
2021-01-29 06:31:58 -05:00
#define DAC8552_POWERDOWN_NORMAL 0
#define DAC8552_POWERDOWN_1K 1
#define DAC8552_POWERDOWN_100K 2
#define DAC8552_POWERDOWN_HIGH_IMP 3
class DAC8552
{
public:
2021-01-29 06:31:58 -05:00
DAC8552(uint8_t slaveSelect);
DAC8552(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect);
2021-01-29 06:31:58 -05:00
void begin();
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);
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);
2021-08-30 07:27:26 -04:00
// speed in Hz
void setSPIspeed(uint32_t speed);
uint32_t getSPIspeed() { return _SPIspeed; };
bool usesHWSPI() { return _hwSPI; };
// ESP32 specific
#if defined(ESP32)
void selectHSPI() { _useHSPI = true; };
void selectVSPI() { _useHSPI = false; };
bool usesHSPI() { return _useHSPI; };
bool usesVSPI() { return !_useHSPI; };
// to overrule ESP32 default hardware pins
void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select);
#endif
private:
2021-08-30 07:27:26 -04:00
uint8_t _dataOut = 255;
uint8_t _clock = 255;
uint8_t _select = 255;
bool _hwSPI = false;
uint16_t _value[2];
2021-01-29 06:31:58 -05:00
uint8_t _register[2];
2021-08-30 07:27:26 -04:00
uint32_t _SPIspeed = 16000000;
2021-01-29 06:31:58 -05:00
void updateDevice(uint8_t channel, bool directWrite);
void swSPI_transfer(uint8_t value);
2021-08-30 07:27:26 -04:00
SPIClass * mySPI;
SPISettings _spi_settings;
#if defined(ESP32)
bool _useHSPI = true;
#endif
};
2021-12-15 06:48:53 -05:00
2020-11-27 05:10:47 -05:00
// -- END OF FILE --
2021-12-15 06:48:53 -05:00