Controll MCP23S17 as GPIO
Diff: ExioMcp23s17.h
- Revision:
- 0:54f1f00eb42f
- Child:
- 1:2315f8a0be58
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ExioMcp23s17.h Sun Oct 30 12:22:48 2016 +0000 @@ -0,0 +1,46 @@ +/* + * ExioMcp23s17.h + * Rapper Class for MCP23S17 + * + * https://developer.mbed.org/users/stjo2809/code/MCP23S17/ + * + * 割込み処理は未実装 + * + * Created: 2016.10.30 + * + */ + +#ifndef _EXIOMCP23S17_H_ +#define _EXIOMCP23S17_H_ + +#include "mbed.h" +#include "MCP23S17.h" + +typedef enum { ExioPortA, ExioPortB } ExioPort; + +class ExioMcp23s17 : public MCP23S17 { +public: + ExioMcp23s17(int hardwareaddress, SPI& spi, PinName nCs, PinName nReset) : + MCP23S17(hardwareaddress, spi, nCs, nReset) {} + + ExioMcp23s17(int hardwareaddress, SPI& spi, PinName nCs) : + MCP23S17(hardwareaddress, spi, nCs) {} + + char ioDirection(ExioPort port) { return read(IODIRA_ADDR | port); } + void ioDirection(ExioPort port, char data) { write(IODIRA_ADDR | port, data); } + + char ioPolarity(ExioPort port) { return read(IPOLA_ADDR | port); } + void ioPolarity(ExioPort port, char data) { write(IPOLA_ADDR | port, data); } + + char ioPullup(ExioPort port) { return read(GPPUA_ADDR | port); } + void ioPullup(ExioPort port, char data) { write(GPPUA_ADDR | port, data); } + + char readPort(ExioPort port) { return read(GPIOA_ADDR | port); } + void writePort(ExioPort port, char data) { write(GPIOA_ADDR | port, data); } + +protected: + void write(char reg_address, char data) { MCP23S17::write(reg_address, data); } + char read(char reg_address) { return MCP23S17::read(reg_address); } +}; + +#endif //_EXIOMCP23S17_H_ \ No newline at end of file