ttt ko
/
NRP2020_main_1_29
aa
Diff: MCP/MCP.h
- Revision:
- 1:5b0303768126
- Parent:
- 0:db8d4af513c0
- Child:
- 2:32d2cd7d744b
diff -r db8d4af513c0 -r 5b0303768126 MCP/MCP.h --- a/MCP/MCP.h Mon Jan 20 08:46:24 2020 +0000 +++ b/MCP/MCP.h Tue Jan 21 11:10:33 2020 +0000 @@ -2,35 +2,34 @@ #define MCP_H_ #include "mbed.h" +#include "MCP23017.h" #define SDA PB_7 #define SCL PB_6 #define MCP_ADDRESS 0x40 -// MCP register address -#define IODIRA 0x00 -#define IODIRB 0x01 -#define IPOLA 0x02 -#define IPOLB 0x03 -#define GPINTENA 0x04 -#define GPINTENB 0x05 -#define DEFVALA 0x06 -#define DEFVALB 0x07 -#define INTCONA 0x08 -#define INTCONB 0x09 -#define IOCONA 0x0A -#define IOCONB 0x0B -#define GPPUA 0x0C -#define GPPUB 0x0D -#define INTFA 0x0E -#define INTFB 0x0F -#define INTCAPA 0x10 -#define INTCAPB 0x11 -#define GPIOA 0x12 -#define GPIOB 0x13 -#define OLATA 0x14 -#define OLATB 0x15 + + +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, @@ -38,10 +37,15 @@ INPUT_PULLUP, }pin_mode; +typedef struct byte{ + uint8_t port_A; + uint8_t port_B; +}byte; + typedef union { - uint8_t port_A, port_B; + byte port; uint16_t all; -}mcp_register; +}mcp_data; class MCP { public: @@ -50,11 +54,11 @@ / */ MCP(PinName sda, PinName scl, uint8_t device_address); // MCP pin define * pin number is 0 ~ 15 - void PinMode(uint8_t pin, uint8_t mode); + 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, bool signal); + bool Read(uint8_t pin); // MCP initialize void Initialize(void); // MCP register update and read new data @@ -64,15 +68,17 @@ private: I2C i2c; + MCP23017 mcp; char _read_opcode; char _write_opcode; - uint16_t _pull_data; - uint16_t _read_data; - uint16_t _write_data; + 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); + void _Read(uint8_t address, uint8_t data); };