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

79 lines
1.7 KiB
C
Raw Normal View History

2022-01-10 06:51:36 -05:00
#pragma once
//
// FILE: MCP23008.h
// AUTHOR: Rob Tillaart
2024-03-05 05:26:47 -05:00
// VERSION: 0.3.2
2023-02-04 08:40:35 -05:00
// PURPOSE: Arduino library for I2C MCP23008 8 channel port expander
2022-01-10 06:51:36 -05:00
// DATE: 2022-01-10
// URL: https://github.com/RobTillaart/MCP23008
#include "Arduino.h"
#include "Wire.h"
2024-03-05 05:26:47 -05:00
#define MCP23008_LIB_VERSION (F("0.3.2"))
2022-01-10 06:51:36 -05:00
#define MCP23008_OK 0x00
#define MCP23008_PIN_ERROR 0x81
#define MCP23008_I2C_ERROR 0x82
#define MCP23008_VALUE_ERROR 0x83
#define MCP23008_PORT_ERROR 0x84
#define MCP23008_INVALID_READ -100
class MCP23008
{
public:
MCP23008(uint8_t address, TwoWire *wire = &Wire);
2024-03-05 05:26:47 -05:00
bool begin(bool pullup = true);
2022-01-10 06:51:36 -05:00
bool isConnected();
2023-12-10 08:28:53 -05:00
uint8_t getAddress();
2022-01-10 06:51:36 -05:00
2022-11-17 10:12:58 -05:00
// single pin interface
// mode = INPUT, OUTPUT or INPUT_PULLUP (== INPUT)
2023-12-24 08:12:39 -05:00
bool pinMode1(uint8_t pin, uint8_t mode);
bool write1(uint8_t pin, uint8_t value);
uint8_t read1(uint8_t pin);
2022-01-10 06:51:36 -05: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);
2022-11-17 10:12:58 -05:00
// 8 pins interface
// value = bit pattern
2022-01-10 06:51:36 -05:00
bool pinMode8(uint8_t value);
bool write8(uint8_t value);
int read8();
bool setPolarity8(uint8_t mask);
bool getPolarity8(uint8_t &mask);
bool setPullup8(uint8_t mask);
bool getPullup8(uint8_t &mask);
int lastError();
2023-12-10 08:28:53 -05:00
// DEBUG functions
2023-07-19 07:24:56 -04:00
uint8_t getPinMode8();
2022-01-10 06:51:36 -05:00
private:
bool writeReg(uint8_t reg, uint8_t value);
uint8_t readReg(uint8_t reg);
uint8_t _address;
TwoWire* _wire;
uint8_t _error;
};
2023-02-04 08:40:35 -05:00
// -- END OF FILE --
2022-01-10 06:51:36 -05:00