33,90 → 33,28 |
#include <twi/twi.h> |
#include <useful/bits.h> |
|
#include <assert.h> |
#include <stdint.h> |
#include <stdlib.h> |
|
/****************************************************************************** |
* Private macros. |
******************************************************************************/ |
|
/**************************************************************************//** |
* \def MCP23008__ADDRESS |
* \brief MCP23008 address on TWI bus. |
* This value is given by the datasheet. |
******************************************************************************/ |
#define MCP23008__ADDRESS 0x20 |
|
/**************************************************************************//** |
* \def MCP23008__REG_IODIR |
* \brief I/O direction register. |
******************************************************************************/ |
#define MCP23008__REG_IODIR 0x00 |
|
/**************************************************************************//** |
* \def MCP23008__REG_IPOL |
* \brief Input polarity register. |
******************************************************************************/ |
#define MCP23008__REG_IPOL 0x01 |
|
/**************************************************************************//** |
* \def MCP23008__REG_GPINTEN |
* \brief Interrupt on change control register. |
******************************************************************************/ |
#define MCP23008__REG_GPINTEN 0x02 |
|
/**************************************************************************//** |
* \def MCP23008__REG_DEFVAL |
* \brief Default compare register for interrupt on change. |
******************************************************************************/ |
#define MCP23008__REG_DEFVAL 0x03 |
|
/**************************************************************************//** |
* \def MCP23008__REG_INTCON |
* \brief Interrupt control register. |
******************************************************************************/ |
#define MCP23008__REG_INTCON 0x04 |
|
/**************************************************************************//** |
* \def MCP23008__REG_IOCON |
* \brief Configuration register. |
******************************************************************************/ |
#define MCP23008__REG_IOCON 0x05 |
|
/**************************************************************************//** |
* \def MCP23008__REG_GPPU |
* \brief Pull-up resistor configuration register. |
******************************************************************************/ |
#define MCP23008__REG_GPPU 0x06 |
|
/**************************************************************************//** |
* \def MCP23008__REG_INTF |
* \brief Interrupt flag register. |
******************************************************************************/ |
#define MCP23008__REG_INTF 0x07 |
|
/**************************************************************************//** |
* \def MCP23008__REG_INTCAP |
* \brief Interrupt capture register. |
******************************************************************************/ |
#define MCP23008__REG_INTCAP 0x08 |
|
/**************************************************************************//** |
* \def MCP23008__REG_GPIO |
* \brief Port register. |
******************************************************************************/ |
#define MCP23008__REG_GPIO 0x09 |
|
/**************************************************************************//** |
* \def MCP23008__REG_OLAT |
* \brief Output latch register. |
******************************************************************************/ |
#define MCP23008__REG_OLAT 0x0A |
|
/**************************************************************************//** |
* \def MCP23008__CLOCK_RATE |
* \brief MCP23008 frequency in Hertz. |
* On ATmega, can be 100 kHz or 400 Khz. |
******************************************************************************/ |
#define MCP23008__CLOCK_RATE 400000 |
|
/****************************************************************************** |
124,11 → 62,7 |
******************************************************************************/ |
|
/**************************************************************************//** |
* \fn static uint8_t mcp23008__read_register(uint8_t address) |
* |
* \brief Read MCP23008 register value. |
* |
* \param address Address of the register to read value. |
******************************************************************************/ |
static |
uint8_t |
138,12 → 72,7 |
); |
|
/**************************************************************************//** |
* \fn static void mcp23008__write_register(uint8_t address, uint8_t value) |
* |
* \brief Write MCP23008 register value. |
* |
* \param address Address of the register to write value. |
* \param value Value to write. |
******************************************************************************/ |
static |
void |
198,14 → 127,7 |
} |
|
/**************************************************************************//** |
* \fn void mcp23008__configure pin( |
* mcp23008__gpio_t pin, |
* mcp23008__direction_t direction) |
* |
* \brief Configure pin direction. |
* |
* \param pin Pin to configure. |
* \param direction Pin direction. |
******************************************************************************/ |
void |
mcp23008__configure_pin |
229,11 → 151,7 |
} |
|
/**************************************************************************//** |
* \fn void mcp23008__configure_port(mcp23008__direction_t direction) |
* |
* \brief Configure port direction. |
* |
* \param direction Port direction. |
******************************************************************************/ |
void |
mcp23008__configure_port |
244,13 → 162,7 |
} |
|
/**************************************************************************//** |
* \fn mcp23008__level_t mcp23008__get_pin_level(mcp23008__gpio_t pin) |
* |
* \brief Get pin level. |
* |
* \param pin Pin to get level. |
* |
* \return Pin level. |
******************************************************************************/ |
mcp23008__level_t |
mcp23008__get_pin_level |
265,14 → 177,7 |
} |
|
/**************************************************************************//** |
* \fn void mcp23008__set_pin_level( |
* mcp23008__gpio_t pin, |
* mcp23008__level_t level) |
* |
* \brief Set pin level. |
* |
* \param pin Pin to set level. |
* \param level Level to set. |
******************************************************************************/ |
void |
mcp23008__set_pin_level |
295,11 → 200,7 |
} |
|
/**************************************************************************//** |
* \fn uin8_t mcp23008__get_port_value(void) |
* |
* \brief Get port value. |
* |
* \return Port value. |
******************************************************************************/ |
uint8_t |
mcp23008__get_port_value |
312,11 → 213,7 |
} |
|
/**************************************************************************//** |
* \fn void mcp23008__set_port_value(uint8_t value) |
* |
* \brief Set port value. |
* |
* \param value Value to set. |
******************************************************************************/ |
void |
mcp23008__set_port_value |
331,11 → 228,7 |
******************************************************************************/ |
|
/**************************************************************************//** |
* \fn static uint8_t mcp23008__read_register(uint8_t address) |
* |
* \brief Read MCP23008 register value. |
* |
* \param address Address of the register to read value. |
******************************************************************************/ |
static |
uint8_t |
359,12 → 252,7 |
} |
|
/**************************************************************************//** |
* \fn static void mcp23008__write_register(uint8_t address, uint8_t value) |
* |
* \brief Write MCP23008 register value. |
* |
* \param address Address of the register to write value. |
* \param value Value to write. |
******************************************************************************/ |
static |
void |