PS_Fgen_FW  4da88f4073c1cc65ea45c3a652a2751e495e50db
Firmware for an Power Supply and Function Generator build from an ATX power supply
Loading...
Searching...
No Matches
MCP23S08.h
Go to the documentation of this file.
1
8
9#ifndef MCP23S08_H_
10#define MCP23S08_H_
11
12#include <stdint.h>
13
14#define SELECT_MCP23S08 SPI_SELECT_IO_EXP
15#define DESELECT_MCP23S08 SPI_DESELECT_IO_EXP
16
17// register addresses
18#define MCP23S08_IODIR 0x00
19#define MCP23S08_IPOL 0x01
20#define MCP23S08_GPINTEN 0x02
21#define MCP23S08_DEFVAL 0x03
22#define MCP23S08_INTCON 0x04
23#define MCP23S08_IOCON 0x05
24#define MCP23S08_GPPU 0x06
25#define MCP23S08_INTF 0x07
26#define MCP23S08_INTCAP 0x08
27#define MCP23S08_GPIO 0x09
28#define MCP23S08_OLAT 0x0A
29
39
40class MCP23S08
41{
42 public:
43 // constructors
44 MCP23S08();
45 MCP23S08(uint8_t deviceAddr);
46
47 // call in setup
48 void begin();
49
50 // usage equivalent to the default IDE functions, see examples
51 bool digitalReadIO(uint8_t pin);
52 void digitalWriteIO(uint8_t pin, bool state);
53 void pinModeIO(uint8_t pin, MCP23S08_PinModes_t mode);
54
55 // advanced, write settings for all pins at once
56 void setOutputStates(uint8_t states);
57 void setPinModes(uint8_t modes);
58 void enablePullups(uint8_t enables);
59 void setInterruptOnChange(uint8_t mask);
60 void setInterruptOnChangeDefaultCompare(uint8_t mask);
61 void setInterruptControl(uint8_t mask);
62 void setINTPinPushPullActiveState(bool activeLow);
63
64 // advanced, get settings for all pin at once
65 uint8_t getInputStates();
66 uint8_t getOutputStates();
67 uint8_t getPinModes();
68 uint8_t getEnabledPullups();
73 uint8_t getInterruptOnChange();
84 uint8_t getInterruptControl();
89 uint8_t getInterruptFlags();
95 uint8_t getInterruptCaptures();
96
97 private:
98 // private variables
99 uint8_t deviceOpcode = 0x40;
100
101 // low level SPI communication
102 void writeRegister(uint8_t address, uint8_t data);
103 uint8_t readRegister(uint8_t address);
104};
105
106#endif /* MCP23S08_H_ */
enum MCP23S08_PinModes MCP23S08_PinModes_t
Enumeration with all MCP23S08 pin modes.
MCP23S08_PinModes
Enumeration with all MCP23S08 pin modes.
Definition MCP23S08.h:34
@ MCP23S08_PINMODE_INPUT
MCP23S08 pin is input.
Definition MCP23S08.h:36
@ MCP23S08_PINMODE_OUTPUT
MCP23S08 pin is output.
Definition MCP23S08.h:35
@ MCP23S08_PINMODE_INPUT_PULLUP
MCP23S08 pin is input with enabled pullup.
Definition MCP23S08.h:37
uint8_t getInterruptOnChange()
The GPINTEN register controls the interrupt-onchange feature for each pin.
Definition MCP23S08.cpp:157
uint8_t getInterruptOnChangeDefaultCompare()
The default comparison value is configured in the DEFVAL register.
Definition MCP23S08.cpp:162
uint8_t getInterruptFlags()
The INTF register reflects the interrupt condition on the port pins of any pin that is enabled for in...
Definition MCP23S08.cpp:172
uint8_t getInterruptControl()
The INTCON register controls how the associated pin value is compared for the interrupt-on-change fea...
Definition MCP23S08.cpp:167
uint8_t getInterruptCaptures()
The INTCAP register captures the GPIO port value at the time the interrupt occurred.
Definition MCP23S08.cpp:177