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

213 lines
5.2 KiB
C
Raw Normal View History

2021-05-26 06:02:17 -04:00
#pragma once
//
// FILE: AD5144A.h
// AUTHOR: Rob Tillaart
2022-12-07 10:52:55 -05:00
// VERSION: 0.1.9
2021-05-26 06:02:17 -04:00
// PURPOSE: I2C digital PotentioMeter AD5144A
// DATE: 2021-04-30
// URL: https://github.com/RobTillaart/AD5144A
//
2022-03-15 06:36:35 -04:00
// Datasheet: REV-C 7/2019
2021-05-26 06:02:17 -04:00
2022-12-07 10:52:55 -05:00
2021-05-26 06:02:17 -04:00
#include "Arduino.h"
#include "Wire.h"
2022-12-07 10:52:55 -05:00
#define AD51XXA_VERSION (F("0.1.9"))
2021-05-26 06:02:17 -04:00
2021-12-11 09:52:48 -05:00
#define AD51XXA_OK 0
#define AD51XXA_ERROR 100
#define AD51XXA_INVALID_POT 101
#define AD51XXA_INVALID_VALUE 102
2021-05-26 06:02:17 -04:00
class AD51XX
{
public:
explicit AD51XX(const uint8_t address, TwoWire *wire = &Wire);
2022-12-07 10:52:55 -05:00
// default the reset function will be called in begin(),
2022-03-15 06:36:35 -04:00
// by setting doReset to false one can skip this explicitly.
2021-05-26 06:02:17 -04:00
#if defined (ESP8266) || defined(ESP32)
2022-06-21 03:14:39 -04:00
bool begin(int dataPin, int clockPin, bool doReset = true);
2021-05-26 06:02:17 -04:00
#endif
2022-03-15 06:36:35 -04:00
bool begin(bool doReset = true);
2021-05-26 06:02:17 -04:00
bool isConnected();
uint8_t reset();
2022-03-15 06:36:35 -04:00
// BASE functions
// rdac = 0..3 - zero based indexing...
2021-05-26 06:02:17 -04:00
uint8_t write(const uint8_t rdac, const uint8_t value);
2022-03-15 06:36:35 -04:00
// fast read from cache
2022-12-07 10:52:55 -05:00
uint8_t read(const uint8_t rdac);
// additional write functions
uint8_t writeAll(const uint8_t value); // set all channels to same value
uint8_t zeroAll();
uint8_t midScaleAll(); // _maxValue + 1)/2
uint8_t maxAll();
uint8_t zero(const uint8_t rdac);
uint8_t midScale(const uint8_t rdac); // _maxValue + 1)/2
uint8_t maxValue(const uint8_t rdac);
uint8_t mid(const uint8_t rdac) { return midScale(rdac); }; // will be obsolete 0.2.0
2021-05-26 06:02:17 -04:00
2022-03-15 06:36:35 -04:00
// EEPROM functions
// defines power up value; copies between RDAC and EEPROM
2021-05-26 06:02:17 -04:00
uint8_t storeEEPROM(const uint8_t rdac);
uint8_t storeEEPROM(const uint8_t rdac, const uint8_t value);
uint8_t recallEEPROM(const uint8_t rdac);
2022-03-15 06:36:35 -04:00
// page 27
2021-05-26 06:02:17 -04:00
uint8_t setTopScale(const uint8_t rdac);
uint8_t clrTopScale(const uint8_t rdac);
uint8_t setTopScaleAll();
uint8_t clrTopScaleAll();
uint8_t setBottomScale(const uint8_t rdac);
uint8_t clrBottomScale(const uint8_t rdac);
uint8_t setBottomScaleAll();
uint8_t clrBottomScaleAll();
2022-03-15 06:36:35 -04:00
// page 27-28
2021-05-26 06:02:17 -04:00
uint8_t setLinearMode(const uint8_t rdac);
uint8_t setPotentiometerMode(const uint8_t rdac);
2022-03-15 06:36:35 -04:00
// 0 = potentiometer, 1 = linear
2021-05-26 06:02:17 -04:00
uint8_t getOperationalMode(const uint8_t rdac);
uint8_t incrementLinear(const uint8_t rdac);
uint8_t incrementLinearAll();
uint8_t decrementLineair(const uint8_t rdac);
uint8_t decrementLineairAll();
uint8_t increment6dB(const uint8_t rdac);
uint8_t increment6dBAll();
uint8_t decrement6dB(const uint8_t rdac);
uint8_t decrement6dBAll();
2022-03-15 06:36:35 -04:00
// SYNC functions
// preload registers to change all channels synchronous
2021-05-26 06:02:17 -04:00
uint8_t preload(const uint8_t rdac, const uint8_t value);
uint8_t preloadAll(const uint8_t value);
2022-03-15 06:36:35 -04:00
// copy the preloads to the channels. The bit mask indicates which channels
// b00001101 would indicate channel 0, 2 and 3;
2022-12-07 10:52:55 -05:00
// sync can not have a default mask as one doesn't know which preloads
2022-04-26 05:45:40 -04:00
// are set and which not.
2021-05-26 06:02:17 -04:00
uint8_t sync(const uint8_t mask);
2022-03-15 06:36:35 -04:00
// MISC
2021-05-26 06:02:17 -04:00
uint8_t pmCount() { return _potCount; };
uint8_t maxValue() { return _maxValue; };
uint8_t shutDown();
2022-03-15 06:36:35 -04:00
// returns the value from internal registers.
2021-05-26 06:02:17 -04:00
uint8_t readBackINPUT(const uint8_t rdac) { return readBack(rdac, 0x00); };
uint8_t readBackEEPROM(const uint8_t rdac) { return readBack(rdac, 0x01); };
uint8_t readBackCONTROL(const uint8_t rdac) { return readBack(rdac, 0x02); };
uint8_t readBackRDAC(const uint8_t rdac) { return readBack(rdac, 0x03); };
2022-03-15 06:36:35 -04:00
// USE WITH CARE - READ DATASHEET
// write to control register
2021-10-17 05:16:21 -04:00
//
2022-03-15 06:36:35 -04:00
// value : 0 1
// bit 0 : FREEZE RDAC's normal operation
// bit 1 : EEPROM DISABLED normal operation
// bit 2 : normal operation LINEAR GAIN MODE
// bit 3 : normal operation BURST MODE
2021-10-17 05:16:21 -04:00
//
2021-05-26 06:02:17 -04:00
uint8_t writeControlRegister(uint8_t mask);
2022-03-15 06:36:35 -04:00
// TODO separate get set functions ?
// uint8_t writeControlRegisterBit(uint8_t mask);
2021-05-26 06:02:17 -04:00
protected:
2022-12-07 10:52:55 -05:00
uint8_t _potCount = 4; // unknown, default max
uint8_t _maxValue = 255; // unknown, default max
2022-03-15 06:36:35 -04:00
2021-05-26 06:02:17 -04:00
uint8_t send(const uint8_t cmd, const uint8_t value);
uint8_t readBack(const uint8_t rdac, const uint8_t mask);
uint8_t _address;
uint8_t _lastValue[4];
TwoWire* _wire;
};
2021-10-17 05:16:21 -04:00
//////////////////////////////////////////////////////////////
//
// DERIVED CLASSES
//
2021-05-26 06:02:17 -04:00
class AD5123 : public AD51XX
{
2021-12-11 09:52:48 -05:00
public:
2021-05-26 06:02:17 -04:00
AD5123(const uint8_t address, TwoWire *wire = &Wire);
};
2022-03-15 06:36:35 -04:00
2021-05-26 06:02:17 -04:00
class AD5124 : public AD51XX
{
2021-12-11 09:52:48 -05:00
public:
2021-05-26 06:02:17 -04:00
AD5124(const uint8_t address, TwoWire *wire = &Wire);
};
2022-03-15 06:36:35 -04:00
2021-05-26 06:02:17 -04:00
class AD5143 : public AD51XX
{
2021-12-11 09:52:48 -05:00
public:
2021-05-26 06:02:17 -04:00
AD5143(const uint8_t address, TwoWire *wire = &Wire);
};
2022-03-15 06:36:35 -04:00
2021-05-26 06:02:17 -04:00
class AD5144 : public AD51XX
{
public:
AD5144(const uint8_t address, TwoWire *wire = &Wire);
};
2022-03-15 06:36:35 -04:00
2021-05-26 06:02:17 -04:00
class AD5144A : public AD51XX
{
public:
AD5144A(const uint8_t address, TwoWire *wire = &Wire);
};
2022-03-15 06:36:35 -04:00
2021-05-26 06:02:17 -04:00
class AD5122A : public AD51XX
{
2021-12-11 09:52:48 -05:00
public:
2021-05-26 06:02:17 -04:00
AD5122A(const uint8_t address, TwoWire *wire = &Wire);
};
2022-03-15 06:36:35 -04:00
2021-05-26 06:02:17 -04:00
class AD5142A : public AD51XX
{
public:
AD5142A(const uint8_t address, TwoWire *wire = &Wire);
};
2022-03-15 06:36:35 -04:00
2021-05-26 06:02:17 -04:00
class AD5121 : public AD51XX
{
public:
AD5121(const uint8_t address, TwoWire *wire = &Wire);
};
2022-03-15 06:36:35 -04:00
2021-05-26 06:02:17 -04:00
class AD5141 : public AD51XX
{
public:
AD5141(const uint8_t address, TwoWire *wire = &Wire);
};
2022-12-07 10:52:55 -05:00
// -- END OF FILE --