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

124 lines
2.8 KiB
C
Raw Normal View History

2021-06-11 04:31:59 -04:00
#pragma once
//
// FILE: TCA9555.h
// AUTHOR: Rob Tillaart
2023-01-12 14:18:00 -05:00
// VERSION: 0.1.5
2021-06-11 04:31:59 -04:00
// PURPOSE: Arduino library for I2C TCA9555 16 channel port expander
// DATE: 2021-06-09
// URL: https://github.com/RobTillaart/TCA9555
#include "Arduino.h"
#include "Wire.h"
2023-01-12 14:18:00 -05:00
#define TCA9555_LIB_VERSION (F("0.1.5"))
2021-06-11 04:31:59 -04:00
2021-12-28 12:38:10 -05:00
#define TCA9555_OK 0x00
#define TCA9555_PIN_ERROR 0x81
#define TCA9555_I2C_ERROR 0x82
#define TCA9555_VALUE_ERROR 0x83
#define TCA9555_PORT_ERROR 0x84
2021-06-11 04:31:59 -04:00
2021-12-28 12:38:10 -05:00
#define TCA9555_INVALID_READ -100
2021-06-11 04:31:59 -04:00
2023-01-12 14:18:00 -05:00
#if !defined(TCA9555_PIN_NAMES)
#define TCA9555_PIN_NAMES
#define TCA_P00 0
#define TCA_P01 1
#define TCA_P02 2
#define TCA_P03 3
#define TCA_P04 4
#define TCA_P05 5
#define TCA_P06 6
#define TCA_P07 7
#define TCA_P10 8
#define TCA_P11 9
#define TCA_P12 10
#define TCA_P13 11
#define TCA_P14 12
#define TCA_P15 13
#define TCA_P16 14
#define TCA_P17 15
#endif
2021-06-11 04:31:59 -04:00
class TCA9555
{
public:
TCA9555(uint8_t address, TwoWire *wire = &Wire);
#if defined(ESP8266) || defined(ESP32)
bool begin(const uint8_t dataPin, const uint8_t clockPin);
#endif
bool begin();
bool isConnected();
2022-12-29 10:04:09 -05:00
uint8_t getAddress();
2021-06-11 04:31:59 -04:00
// 1 PIN INTERFACE
// pin = 0..15
// mode = INPUT, OUTPUT (INPUT_PULLUP is not supported)
// value = LOW, HIGH
bool pinMode(uint8_t pin, uint8_t mode);
bool digitalWrite(uint8_t pin, uint8_t value);
uint8_t digitalRead(uint8_t pin);
2022-11-26 07:08:45 -05:00
bool setPolarity(uint8_t pin, uint8_t value); // input pins only.
2021-06-11 04:31:59 -04:00
uint8_t getPolarity(uint8_t pin);
// 8 PIN INTERFACE
// port = 0..1
2021-12-28 12:38:10 -05:00
// mask = bit pattern
2021-06-11 04:31:59 -04:00
bool pinMode8(uint8_t port, uint8_t mask);
bool write8(uint8_t port, uint8_t mask);
int read8(uint8_t port);
bool setPolarity8(uint8_t port, uint8_t value);
uint8_t getPolarity8(uint8_t port);
// 16 PIN INTERFACE
// wraps 2x 8 PIN call.
// opportunistic implementation of functions
// needs error checking in between calls
2021-12-28 12:38:10 -05:00
// mask = bit pattern
2021-06-11 04:31:59 -04:00
bool pinMode16(uint16_t mask);
bool write16(uint16_t mask);
uint16_t read16();
bool setPolarity16(uint16_t mask);
uint8_t getPolarity16();
int lastError();
2023-01-12 14:18:00 -05:00
uint8_t getType();
2021-06-11 04:31:59 -04:00
protected:
bool writeRegister(uint8_t reg, uint8_t value);
uint8_t readRegister(uint8_t reg);
2022-11-26 07:08:45 -05:00
uint8_t _address;
TwoWire* _wire;
uint8_t _error;
2023-01-12 14:18:00 -05:00
uint8_t _type;
2021-06-11 04:31:59 -04:00
};
/////////////////////////////////////////////////////////////////////////////
//
2022-11-26 07:08:45 -05:00
// TCA9535 class which is just a wrapper (for now)
2021-12-28 12:38:10 -05:00
//
2021-06-11 04:31:59 -04:00
class TCA9535 : public TCA9555
{
2022-12-29 10:04:09 -05:00
public:
2021-06-11 04:31:59 -04:00
TCA9535(uint8_t address, TwoWire *wire = &Wire);
};
// -- END OF FILE --
2021-12-28 12:38:10 -05:00