toshi mura
/
NRP2020_main
gjyrjyykkudt
MCP/MCP.h
- Committer:
- M_souta
- Date:
- 2020-01-21
- Revision:
- 1:5b0303768126
- Parent:
- 0:db8d4af513c0
- Child:
- 2:32d2cd7d744b
File content as of revision 1:5b0303768126:
#ifndef MCP_H_ #define MCP_H_ #include "mbed.h" #include "MCP23017.h" #define SDA PB_7 #define SCL PB_6 #define MCP_ADDRESS 0x40 typedef enum { a0 = 0, a1 = 1, a2 = 2, a3 = 3, a4 = 4, a5 = 5, a6 = 6, a7 = 7, b0 = 8, b1 = 9, b2 = 10, b3 = 11, b4 = 12, b5 = 13, b6 = 14, b7 = 15, }pin_name; typedef enum { OUTPUT, INPUT, INPUT_PULLUP, }pin_mode; typedef struct byte{ uint8_t port_A; uint8_t port_B; }byte; typedef union { byte port; uint16_t all; }mcp_data; class MCP { public: /* MCP class constracter / deffult Input / */ MCP(PinName sda, PinName scl, uint8_t device_address); // MCP pin define * pin number is 0 ~ 15 void PinMode(uint8_t pin, pin_mode mode); // MCP DigitalWrite * pin number is 0 ~ 15 void Write(uint8_t pin, bool signal); // MCP DigitalRead * pin number is 0 ~ 15 bool Read(uint8_t pin); // MCP initialize void Initialize(void); // MCP register update and read new data void Update(void); // i2c error check bool ErrorOccurred(void); private: I2C i2c; MCP23017 mcp; char _read_opcode; char _write_opcode; mcp_data _iodir_data; mcp_data _pull_data; mcp_data _read_data; mcp_data _write_data; void _Write(uint8_t address, uint8_t data); void _Read(uint8_t address, uint8_t data); }; #endif //I2C_H_