aa

Dependencies:   mbed MCP23017

Committer:
M_souta
Date:
Thu Jan 23 09:16:38 2020 +0000
Revision:
2:32d2cd7d744b
Parent:
1:5b0303768126
Child:
4:15547d07f8e5
lll

Who changed what in which revision?

UserRevisionLine numberNew contents of line
M_souta 0:db8d4af513c0 1 #ifndef MCP_H_
M_souta 0:db8d4af513c0 2 #define MCP_H_
M_souta 0:db8d4af513c0 3
M_souta 0:db8d4af513c0 4 #include "mbed.h"
M_souta 1:5b0303768126 5 #include "MCP23017.h"
M_souta 0:db8d4af513c0 6
M_souta 0:db8d4af513c0 7 #define SDA PB_7
M_souta 0:db8d4af513c0 8 #define SCL PB_6
M_souta 0:db8d4af513c0 9
M_souta 0:db8d4af513c0 10 #define MCP_ADDRESS 0x40
M_souta 0:db8d4af513c0 11
M_souta 2:32d2cd7d744b 12 #define GPA0 0
M_souta 2:32d2cd7d744b 13 #define GPA1 1
M_souta 2:32d2cd7d744b 14 #define GPA2 2
M_souta 2:32d2cd7d744b 15 #define GPA3 3
M_souta 2:32d2cd7d744b 16 #define GPA4 4
M_souta 2:32d2cd7d744b 17 #define GPA5 5
M_souta 2:32d2cd7d744b 18 #define GPA6 6
M_souta 2:32d2cd7d744b 19 #define GPA7 7
M_souta 2:32d2cd7d744b 20 #define GPB0 8
M_souta 2:32d2cd7d744b 21 #define GPB1 9
M_souta 2:32d2cd7d744b 22 #define GPB2 10
M_souta 2:32d2cd7d744b 23 #define GPB3 11
M_souta 2:32d2cd7d744b 24 #define GPB4 12
M_souta 2:32d2cd7d744b 25 #define GPB5 13
M_souta 2:32d2cd7d744b 26 #define GPB6 14
M_souta 2:32d2cd7d744b 27 #define GPB7 15
M_souta 0:db8d4af513c0 28
M_souta 0:db8d4af513c0 29 typedef enum {
M_souta 0:db8d4af513c0 30 OUTPUT,
M_souta 0:db8d4af513c0 31 INPUT,
M_souta 0:db8d4af513c0 32 INPUT_PULLUP,
M_souta 0:db8d4af513c0 33 }pin_mode;
M_souta 0:db8d4af513c0 34
M_souta 1:5b0303768126 35 typedef struct byte{
M_souta 1:5b0303768126 36 uint8_t port_A;
M_souta 1:5b0303768126 37 uint8_t port_B;
M_souta 1:5b0303768126 38 }byte;
M_souta 1:5b0303768126 39
M_souta 0:db8d4af513c0 40 typedef union {
M_souta 1:5b0303768126 41 byte port;
M_souta 0:db8d4af513c0 42 uint16_t all;
M_souta 1:5b0303768126 43 }mcp_data;
M_souta 0:db8d4af513c0 44
M_souta 0:db8d4af513c0 45 class MCP {
M_souta 0:db8d4af513c0 46 public:
M_souta 0:db8d4af513c0 47 /* MCP class constracter
M_souta 0:db8d4af513c0 48 / deffult Input
M_souta 0:db8d4af513c0 49 / */
M_souta 0:db8d4af513c0 50 MCP(PinName sda, PinName scl, uint8_t device_address);
M_souta 0:db8d4af513c0 51 // MCP pin define * pin number is 0 ~ 15
M_souta 1:5b0303768126 52 void PinMode(uint8_t pin, pin_mode mode);
M_souta 0:db8d4af513c0 53 // MCP DigitalWrite * pin number is 0 ~ 15
M_souta 0:db8d4af513c0 54 void Write(uint8_t pin, bool signal);
M_souta 0:db8d4af513c0 55 // MCP DigitalRead * pin number is 0 ~ 15
M_souta 1:5b0303768126 56 bool Read(uint8_t pin);
M_souta 0:db8d4af513c0 57 // MCP initialize
M_souta 0:db8d4af513c0 58 void Initialize(void);
M_souta 0:db8d4af513c0 59 // MCP register update and read new data
M_souta 0:db8d4af513c0 60 void Update(void);
M_souta 0:db8d4af513c0 61
M_souta 0:db8d4af513c0 62 private:
M_souta 0:db8d4af513c0 63 I2C i2c;
M_souta 1:5b0303768126 64 MCP23017 mcp;
M_souta 0:db8d4af513c0 65 char _read_opcode;
M_souta 0:db8d4af513c0 66 char _write_opcode;
M_souta 0:db8d4af513c0 67
M_souta 1:5b0303768126 68 mcp_data _iodir_data;
M_souta 1:5b0303768126 69 mcp_data _pull_data;
M_souta 1:5b0303768126 70 mcp_data _read_data;
M_souta 1:5b0303768126 71 mcp_data _write_data;
M_souta 0:db8d4af513c0 72
M_souta 0:db8d4af513c0 73 void _Write(uint8_t address, uint8_t data);
M_souta 1:5b0303768126 74 void _Read(uint8_t address, uint8_t data);
M_souta 2:32d2cd7d744b 75
M_souta 2:32d2cd7d744b 76 void I2Crestart(void);
M_souta 0:db8d4af513c0 77
M_souta 0:db8d4af513c0 78 };
M_souta 0:db8d4af513c0 79
M_souta 0:db8d4af513c0 80 #endif //I2C_H_