COSA
An Object-Oriented Platform for Arduino Programming
|
#include <MCP23008.hh>
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 |
Driver for the MCP23008 8-bit I/O Expander with I2C Interface and Interrupt.
Definition at line 50 of file MCP23008.hh.
|
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.
|
protected |
Configuration Register Bits, pp. 15.
Enumerator | |
---|---|
INTPOL | |
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.
|
inline |
Construct connection to MCP23008 8-bit I/O Expander with given sub-address. All pins are input on reset. Interrupt disabled.
[in] | subaddr | sub-address (0..7, default 0). |
Definition at line 65 of file MCP23008.hh.
bool MCP23008::begin | ( | ) |
Initiate device driver. Return true if initiated otherwise false.
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.
[in] | iodir | data direction mask. |
Definition at line 47 of file MCP23008.cpp.
|
inline |
Set given pin as input. Return true if set otherwise false.
[in] | pin | number (0..7). |
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.
[in] | pin | number (0..7). |
[in] | mode | interrupt. |
Definition at line 69 of file MCP23008.cpp.
|
inline |
Set given pin as output. Return true if set otherwise false.
[in] | pin | number (0..7). |
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.
[in] | gppu | pullup resistor mask. |
Definition at line 58 of file MCP23008.cpp.
|
inline |
Set given pin pullup. Return true if set otherwise false.
[in] | pin | number (0..7). |
Definition at line 113 of file MCP23008.hh.
uint8_t MCP23008::read | ( | ) |
Read pins and return current 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.
[in,out] | buf | pointer to buffer for data. |
[in] | size | number of bytes to read. |
Definition at line 124 of file MCP23008.cpp.
|
inline |
Read given pin and return true is set otherwise false.
[in] | pin | number (0..7). |
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.
[in] | value. |
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.
[in] | buf | pointer to data to write to port. |
[in] | size | of buffer. |
Definition at line 150 of file MCP23008.cpp.
|
inline |
Write set given output pin if value is non-zero, otherwise clear. Return true if successful otherwise false.
[in] | pin | number (0..7). |
[in] | value. |
Definition at line 157 of file MCP23008.hh.
|
protected |
Default Compare Register, 0 = rising, 1 = falling.
Definition at line 240 of file MCP23008.hh.
|
protected |
Interrupt on Change Control Register, 0 = disable, 1 = enable.
Definition at line 237 of file MCP23008.hh.
|
protected |
Pullup Register, 0 = disable, 1 = pullup enable, default disable.
Definition at line 246 of file MCP23008.hh.
|
protected |
Interrupt Control Register, 0 = change/toggle, 1 = compare.
Definition at line 243 of file MCP23008.hh.
|
protected |
Data Direction Register, 0 = output, 1 = input, default all input.
Definition at line 234 of file MCP23008.hh.
|
protected |
Output Register values.
Definition at line 249 of file MCP23008.hh.
|
protected |
Current Register.
Definition at line 252 of file MCP23008.hh.
|
staticprotected |
Pin number mask.
Definition at line 206 of file MCP23008.hh.
|
staticprotected |
Sub-address mask.
Definition at line 203 of file MCP23008.hh.