GY-63_MS5611/libraries/MCP23017_RT/MCP23017.h

108 lines
2.5 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: MCP23017.h
// AUTHOR: Rob Tillaart
2024-01-05 04:59:57 -05:00
// VERSION: 0.6.1
2021-01-29 06:31:58 -05:00
// PURPOSE: Arduino library for I2C MCP23017 16 channel port expander
// DATE: 2019-10-12
// URL: https://github.com/RobTillaart/MCP23017_RT
2023-09-23 10:25:55 -04:00
//
2023-02-04 05:37:40 -05:00
// WARNING: please read REV D note in readme.md.
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
#include "Wire.h"
2024-01-05 04:59:57 -05:00
#define MCP23017_LIB_VERSION (F("0.6.1"))
2021-01-29 06:31:58 -05:00
2021-12-21 11:12:20 -05:00
#define MCP23017_OK 0x00
#define MCP23017_PIN_ERROR 0x81
#define MCP23017_I2C_ERROR 0x82
#define MCP23017_VALUE_ERROR 0x83
#define MCP23017_PORT_ERROR 0x84
2021-01-29 06:31:58 -05:00
2021-12-21 11:12:20 -05:00
#define MCP23017_INVALID_READ -100
2021-06-06 13:58:43 -04:00
2021-01-29 06:31:58 -05:00
class MCP23017
{
public:
2022-01-09 14:53:12 -05:00
MCP23017(uint8_t address, TwoWire *wire = &Wire);
2021-06-06 13:58:43 -04:00
2023-09-23 10:25:55 -04:00
bool begin();
bool isConnected();
2023-12-10 08:29:27 -05:00
uint8_t getAddress();
2021-06-06 13:58:43 -04:00
2023-09-23 10:25:55 -04:00
// single pin interface
// mode = INPUT, OUTPUT or INPUT_PULLUP (==INPUT)
2023-12-24 08:31:28 -05:00
bool pinMode1(uint8_t pin, uint8_t mode);
bool write1(uint8_t pin, uint8_t value);
uint8_t read1(uint8_t pin);
2021-01-29 06:31:58 -05:00
2023-09-23 10:25:55 -04:00
bool setPolarity(uint8_t pin, bool reversed);
bool getPolarity(uint8_t pin, bool &reversed);
bool setPullup(uint8_t pin, bool pullup);
bool getPullup(uint8_t pin, bool &pullup);
2021-09-17 04:30:51 -04:00
2021-06-06 13:58:43 -04:00
2023-09-23 10:25:55 -04:00
// 8 pins interface
// port = 0..1
// value = bit pattern
bool pinMode8(uint8_t port, uint8_t value);
bool write8(uint8_t port, uint8_t value);
int read8(uint8_t port);
2021-01-29 06:31:58 -05:00
2023-09-23 10:25:55 -04:00
bool setPolarity8(uint8_t port, uint8_t mask);
bool getPolarity8(uint8_t port, uint8_t &mask);
bool setPullup8(uint8_t port, uint8_t mask);
bool getPullup8(uint8_t port, uint8_t &mask);
2021-09-17 04:30:51 -04:00
2022-11-17 10:46:22 -05:00
// 16 pins interface
// value = bit pattern
2022-01-09 14:53:12 -05:00
bool pinMode16(uint16_t value);
bool write16(uint16_t value);
uint16_t read16();
bool setPolarity16(uint16_t mask);
bool getPolarity16(uint16_t &mask);
bool setPullup16(uint16_t mask);
bool getPullup16(uint16_t &mask);
2022-11-17 10:46:22 -05:00
int lastError();
2021-09-17 04:30:51 -04:00
2023-12-10 08:29:27 -05:00
protected:
2023-09-23 10:25:55 -04:00
bool writeReg(uint8_t reg, uint8_t value);
uint8_t readReg(uint8_t reg);
2021-01-29 06:31:58 -05:00
2022-01-09 14:53:12 -05:00
uint8_t _address;
2021-01-29 06:31:58 -05:00
TwoWire* _wire;
uint8_t _error;
};
2021-12-21 11:12:20 -05:00
2023-12-10 08:29:27 -05:00
/*
TODO
- can it protect the user
- can we detect REV D chips (over I2C)
class MCP23017_REVD : public MCP23017
{
public:
MCP23017_REVD(uint8_t address, TwoWire *wire = &Wire);
- GPA7 and GPB7 should be set to output in constructor
- GPA7 and GPB7 output mode may not change in any call
- GPA7 and GPB7 should return last written value for read.
- which functions are affected? setMode pullups etc.
};
*/
2023-09-23 10:25:55 -04:00
// -- END OF FILE --
2021-12-21 11:12:20 -05:00