forked from WereCatf/PCF8574_ESP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcf8574_esp.h
68 lines (56 loc) · 1.53 KB
/
pcf8574_esp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* PCF8574_ESP -- library for using the I2C-driven 8-pin GPIO-expander
ORIGINAL AUTHOR: Rob Tillaart
Library modified by WereCatf */
#ifndef _PCF8574_ESP_H
#define _PCF8574_ESP_H
#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#if defined (ARDUINO_AVR_DIGISPARK) || defined (ARDUINO_AVR_ATTINYX5)
#include <TinyWireM.h>
#else
#include <Wire.h>
#endif
#define PCF857x_OK 0x00
#define PCF857x_PIN_ERROR 0x81
#define PCF857x_I2C_ERROR 0x82
class PCF857x
{
public:
// Defaults to 8574, set is8575 to true if you have a 8575 instead.
#if defined (ARDUINO_AVR_DIGISPARK) || defined (ARDUINO_AVR_ATTINYX5)
PCF857x(uint8_t address, bool is8575 = false);
#else
PCF857x(uint8_t address, TwoWire *UseWire, bool is8575 = false);
#endif
void begin(uint16_t defaultValues=0xffff);
uint8_t read8();
uint16_t read16();
uint8_t read(uint8_t pin);
void write8(uint8_t value);
void write16(uint16_t value);
void write(uint8_t pin, uint8_t value);
void toggle(uint8_t pin);
void toggleAll();
void shiftRight(uint8_t n=1);
void shiftLeft(uint8_t n=1);
void rotateRight(uint8_t n=1);
void rotateLeft(uint8_t n=1);
void resetInterruptPin();
int lastError();
protected:
uint16_t _data;
uint16_t _pinModeMask;
bool _is8575;
private:
#if defined (ARDUINO_AVR_DIGISPARK) || defined (ARDUINO_AVR_ATTINYX5)
USI_TWI *_Wire;
#else
TwoWire *_Wire;
#endif
uint8_t _address;
int _error;
};
#endif