This library provides simplified I2C access to a Microchip MCP23x17 GPIO expender device, including a general interface for any GPIO expender
AbstractGpioExpender.h
- Committer:
- Yann
- Date:
- 2015-01-09
- Revision:
- 0:ebd3a7cc9b92
- Child:
- 1:ec9e770173d5
File content as of revision 0:ebd3a7cc9b92:
#pragma once
#include <list>
#include <mbed.h>
#define GPA0 0
#define GPA1 1
#define GPA2 2
#define GPA3 3
#define GPA4 4
#define GPA5 5
#define GPA6 6
#define GPA7 7
#define GPB0 8
#define GPB1 9
#define GPB2 10
#define GPB3 11
#define GPB4 12
#define GPB5 13
#define GPB6 14
#define GPB7 15
#define GPIO_MAX GPB7
#define GPIO_MED GPB0
#define GPIO_SIZE 8
class AbstractGpioExpender {
public:
/** Interrupt modes
*/
enum InterruptModes {
OnChange = 0x00,
OnRising = 0x01,
OnFalling = 0x03
};
/** Reset the device
*/
virtual void reset() = 0;
/** Setup interrupt mechanism for all GPIO ports
* @param p_mirroring Set to 0x00 to disable INTA/B mirroring, 0x01 otherwise. Default: 0x00
* @param p_openDrain Set to 0x00 for active driver output, 0x01 for opn drain output. Default: 0x00
* @param p_polarity Set to 0x00 for interrupt active low, 0x01 otherwise. Default: 0x00
*/
virtual void setupInterrupts(const unsigned char p_mirroring = 0x00, const unsigned char p_openDrain = 0x00, const unsigned char p_polarity = 0x00) = 0;
/** Setup interrupt for a specific IO port
* @param p_gpioId The IO port identifier
* @param p_mode The interrupt mode
* @return 0 on success, negative value otherwise
*/
virtual int setupInterruptPin(const unsigned char p_gpioId, const InterruptModes p_mode = OnRising) = 0;
/** Get interrupt information and clear it
* @param p_gpioId The IO port identifier where the interrupt occured
* @param p_value The logic value on the pin port where the interrupt occured
* @return 0 on success, negative value otherwise
*/
virtual int getLastInterruptPin(unsigned char * p_gpioId, unsigned char * p_value) = 0;
/** Attach a function to call when a interrupt occurs on the GPIOA input ports
*/
virtual void setIntrACallback(void (* p_fptr)(void)) = 0;
/** Attach a function to call when a rising edge occurs on the input
*/
virtual void setIntrBCallback(void (* p_fptr)(void)) = 0;
virtual int read(const unsigned char p_gpioId, unsigned char * p_value) = 0;
virtual int write(const unsigned char p_gpioId, const unsigned char p_value) = 0;
virtual unsigned char createBus(const std::list<unsigned char> p_lines, const PinMode p_mode = PullNone) = 0;
virtual void deleteBus(const unsigned char p_busId) = 0;
virtual int busRead(const unsigned char p_busId) = 0;
virtual int busWrite(const unsigned char p_busId, const unsigned char p_value) = 0;
protected:
virtual bool writeRegister(const unsigned char p_registerId, const unsigned char p_value) = 0;
virtual bool readRegister(const unsigned char p_registerId, unsigned char * p_value) = 0;
}; // End of class AbstractGpioExpender
Yann Garcia