COSA
An Object-Oriented Platform for Arduino Programming
MCP23008 Class Reference

#include <MCP23008.hh>

Inheritance diagram for MCP23008:
Inheritance graph
Collaboration diagram for MCP23008:
Collaboration graph

Public Types

enum  InterruptMode { DISABLE = 0, ON_CHANGE = 1, ON_FALLING = 2, ON_RISING = 3 }
 

Public Member Functions

 MCP23008 (uint8_t subaddr=0)
 
bool begin ()
 
bool data_direction (uint8_t iodir)
 
bool pullup (uint8_t gppu)
 
bool input_pin (uint8_t pin)
 
bool pullup_pin (uint8_t pin)
 
bool interrupt_pin (uint8_t pin, InterruptMode mode)
 
bool output_pin (uint8_t pin)
 
bool read_pin (uint8_t pin)
 
bool write_pin (uint8_t pin, uint8_t value)
 
uint8_t read ()
 
bool read (void *buf, size_t size)
 
bool write (uint8_t value)
 
bool write (void *buf, size_t size)
 

Protected Types

enum  {
  IODIR = 0x00, IPOL = 0x01, GPINTEN = 0x02, DEFVAL = 0x03,
  INTCON = 0x04, IOCON = 0x05, GPPU = 0x06, INTF = 0x07,
  INTCAP = 0x08, GPIO = 0x09, OLAT = 0x0a, REG_MAX = 0x0b
}
 
enum  {
  INTPOL = 1, ODR = 2, HAEN = 3, DISSLW = 4,
  SEQOP = 5
}
 

Protected Attributes

uint8_t m_iodir
 
uint8_t m_gpinten
 
uint8_t m_defval
 
uint8_t m_intcon
 
uint8_t m_gppu
 
uint8_t m_olat
 
uint8_t m_reg
 

Static Protected Attributes

static const uint8_t SUBADDR_MASK = 0x07
 
static const uint8_t PIN_MASK = 0x07
 

Private Member Functions

bool is_async () const
 
void sync_request ()
 
void async_request ()
 
virtual void on_completion (uint8_t type, int count)
 

Private Attributes

uint8_t m_addr
 
bool m_async
 

Detailed Description

Driver for the MCP23008 8-bit I/O Expander with I2C Interface and Interrupt.

Circuit

+------------+
(SCL)---------------1-|SCL VCC|-18--------------(VCC)
(SDA)---------------2-|SDA GP7|-17---------------(P7)
(A2)----[ ]---------3-|A2 GP6|-16---------------(P6)
(A1)----[ ]---------4-|A1 GP5|-15---------------(P5)
(A0)----[ ]---------5-|A0 GP4|-14---------------(P4)
(RST)---------------6-|RESET/ GP3|-13---------------(P3)
7-|NC GP2|-12---------------(P2)
(EXT)---------------8-|INT GP1|-11---------------(P1)
(GND)---------------9-|GND GP0|-10---------------(P0)
+------------+

References

  1. Microchip Technology Inc., Device Documentation, DS21919E, 2007. http://ww1.microchip.com/downloads/en/DeviceDoc/21919e.pdf

Definition at line 50 of file MCP23008.hh.

Member Enumeration Documentation

anonymous enum
protected

Register Addresses, table 1-2, pp. 6.

Enumerator
IODIR 

I/O Direction Register.

IPOL 

Input Polarity Register.

GPINTEN 

Interrupt on Change Control Register.

DEFVAL 

Default Compare Register.

INTCON 

Interrupt Control Register.

IOCON 

Configuration Register.

GPPU 

Pull-up Resistor Configuration.

INTF 

Interrupt Flag Register.

INTCAP 

Interrupt Capture Register.

GPIO 

Port Register.

OLAT 

Output Latch Register.

REG_MAX 

Number of Registers.

Definition at line 209 of file MCP23008.hh.

anonymous enum
protected

Configuration Register Bits, pp. 15.

Enumerator
INTPOL 

Polarity of Interrupt Pin.

ODR 

Open-drain Output enable.

HAEN 

Hardware Address Enable (SPI).

DISSLW 

Slew Rate disable.

SEQOP 

Sequence Operation mode disable.

Definition at line 225 of file MCP23008.hh.

Interrupt Pin modes

Enumerator
DISABLE 

Interrupt disabled.

ON_CHANGE 

Interrupt on change (toggle).

ON_FALLING 

Interrupt on falling (high to low).

ON_RISING 

Interrupt on rising (low to high).

Definition at line 53 of file MCP23008.hh.

Constructor & Destructor Documentation

MCP23008::MCP23008 ( uint8_t  subaddr = 0)
inline

Construct connection to MCP23008 8-bit I/O Expander with given sub-address. All pins are input on reset. Interrupt disabled.

Parameters
[in]subaddrsub-address (0..7, default 0).

Definition at line 65 of file MCP23008.hh.

Member Function Documentation

bool MCP23008::begin ( )

Initiate device driver. Return true if initiated otherwise false.

Returns
bool.

Definition at line 24 of file MCP23008.cpp.

bool MCP23008::data_direction ( uint8_t  iodir)

Set data direction for port pin P0..P7; 0 for output, 1 for input. Return true if set otherwise false.

Parameters
[in]iodirdata direction mask.
Returns
bool.

Definition at line 47 of file MCP23008.cpp.

bool MCP23008::input_pin ( uint8_t  pin)
inline

Set given pin as input. Return true if set otherwise false.

Parameters
[in]pinnumber (0..7).
Returns
bool.

Definition at line 102 of file MCP23008.hh.

bool MCP23008::interrupt_pin ( uint8_t  pin,
InterruptMode  mode 
)

Set interrupt mode for given pin. Return true if set otherwise false.

Parameters
[in]pinnumber (0..7).
[in]modeinterrupt.
Returns
bool.

Definition at line 69 of file MCP23008.cpp.

bool MCP23008::output_pin ( uint8_t  pin)
inline

Set given pin as output. Return true if set otherwise false.

Parameters
[in]pinnumber (0..7).
Returns
bool.

Definition at line 133 of file MCP23008.hh.

bool MCP23008::pullup ( uint8_t  gppu)

Set pullup mode for port pin P0..P7; 0 for normal, 1 for pullup resistor. Return true if set otherwise false.

Parameters
[in]gppupullup resistor mask.
Returns
bool.

Definition at line 58 of file MCP23008.cpp.

bool MCP23008::pullup_pin ( uint8_t  pin)
inline

Set given pin pullup. Return true if set otherwise false.

Parameters
[in]pinnumber (0..7).
Returns
bool.

Definition at line 113 of file MCP23008.hh.

uint8_t MCP23008::read ( )

Read pins and return current values.

Returns
input pin values.

Definition at line 110 of file MCP23008.cpp.

bool MCP23008::read ( void *  buf,
size_t  size 
)

Read pins value into given buffer with given size. Return true if successful otherwise false.

Parameters
[in,out]bufpointer to buffer for data.
[in]sizenumber of bytes to read.
Returns
bool.

Definition at line 124 of file MCP23008.cpp.

bool MCP23008::read_pin ( uint8_t  pin)
inline

Read given pin and return true is set otherwise false.

Parameters
[in]pinnumber (0..7).
Returns
bool.

Definition at line 144 of file MCP23008.hh.

bool MCP23008::write ( uint8_t  value)

Write given value to the output pins. Return true if successful otherwise false.

Parameters
[in]value.
Returns
bool.

Definition at line 139 of file MCP23008.cpp.

bool MCP23008::write ( void *  buf,
size_t  size 
)

Write given values to the output pins. Allow sequence of updates to output pins in a single write. Return true if successful otherwise false.

Parameters
[in]bufpointer to data to write to port.
[in]sizeof buffer.
Returns
bool.

Definition at line 150 of file MCP23008.cpp.

bool MCP23008::write_pin ( uint8_t  pin,
uint8_t  value 
)
inline

Write set given output pin if value is non-zero, otherwise clear. Return true if successful otherwise false.

Parameters
[in]pinnumber (0..7).
[in]value.
Returns
bool.

Definition at line 157 of file MCP23008.hh.

Member Data Documentation

uint8_t MCP23008::m_defval
protected

Default Compare Register, 0 = rising, 1 = falling.

Definition at line 240 of file MCP23008.hh.

uint8_t MCP23008::m_gpinten
protected

Interrupt on Change Control Register, 0 = disable, 1 = enable.

Definition at line 237 of file MCP23008.hh.

uint8_t MCP23008::m_gppu
protected

Pullup Register, 0 = disable, 1 = pullup enable, default disable.

Definition at line 246 of file MCP23008.hh.

uint8_t MCP23008::m_intcon
protected

Interrupt Control Register, 0 = change/toggle, 1 = compare.

Definition at line 243 of file MCP23008.hh.

uint8_t MCP23008::m_iodir
protected

Data Direction Register, 0 = output, 1 = input, default all input.

Definition at line 234 of file MCP23008.hh.

uint8_t MCP23008::m_olat
protected

Output Register values.

Definition at line 249 of file MCP23008.hh.

uint8_t MCP23008::m_reg
protected

Current Register.

Definition at line 252 of file MCP23008.hh.

const uint8_t MCP23008::PIN_MASK = 0x07
staticprotected

Pin number mask.

Definition at line 206 of file MCP23008.hh.

const uint8_t MCP23008::SUBADDR_MASK = 0x07
staticprotected

Sub-address mask.

Definition at line 203 of file MCP23008.hh.


The documentation for this class was generated from the following files: