Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MCP/MCP.h
- Committer:
- M_souta
- Date:
- 2020-01-20
- Revision:
- 0:db8d4af513c0
- Child:
- 1:5b0303768126
File content as of revision 0:db8d4af513c0:
#ifndef MCP_H_
#define MCP_H_
#include "mbed.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 {
OUTPUT,
INPUT,
INPUT_PULLUP,
}pin_mode;
typedef union {
uint8_t port_A, port_B;
uint16_t all;
}mcp_register;
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, uint8_t 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);
// MCP initialize
void Initialize(void);
// MCP register update and read new data
void Update(void);
// i2c error check
bool ErrorOccurred(void);
private:
I2C i2c;
char _read_opcode;
char _write_opcode;
uint16_t _pull_data;
uint16_t _read_data;
uint16_t _write_data;
void _Write(uint8_t address, uint8_t data);
void _Read(uint8_t address, uint8_t data);
};
#endif //I2C_H_