A simple static library for controlling an MCP23S17 port expander over SPI. More...
#include <stdint.h>Go to the source code of this file.
Functions | |
| int | mcp23s17_open (int bus, int chip_select) |
| uint8_t | mcp23s17_read_reg (uint8_t reg, uint8_t hw_addr, int fd) |
| void | mcp23s17_write_reg (uint8_t data, uint8_t reg, uint8_t hw_addr, int fd) |
| uint8_t | mcp23s17_read_bit (uint8_t bit_num, uint8_t reg, uint8_t hw_addr, int fd) |
| void | mcp23s17_write_bit (uint8_t data, uint8_t bit_num, uint8_t reg, uint8_t hw_addr, int fd) |
| int | mcp23s17_enable_interrupts () |
| int | mcp23s17_disable_interrupts () |
| int | mcp23s17_wait_for_interrupt (int timeout) |
A simple static library for controlling an MCP23S17 port expander over SPI.
Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/21952b.pdf
Copyright (C) 2013 Thomas Preston thomas.preston@openlx.org.uk
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
| int mcp23s17_disable_interrupts | ( | ) |
Disables interrupts and exports to the GPIO connection from the mcp23s17.
| int mcp23s17_enable_interrupts | ( | ) |
Enables interrupts and exports to the GPIO connection from the mcp23s17.
| int mcp23s17_open | ( | int | bus, |
| int | chip_select | ||
| ) |
Returns a file descriptor for the SPI device through which the MCP23S17 port expander can be accessed.
| bus | The SPI bus. |
| chip_select | The SPI chip select. |
| uint8_t mcp23s17_read_bit | ( | uint8_t | bit_num, |
| uint8_t | reg, | ||
| uint8_t | hw_addr, | ||
| int | fd | ||
| ) |
Reads a single bit from the register specified. Must also specify which hardware address and file descriptor to use.
| bit_num | The bit number to read. |
| reg | The register to read from (example: IODIRA, GPIOA). |
| hw_addr | The hardware address of the MCP23S17. |
| fd | The file descriptor returned from <mcp23s17_open>"()". |
| uint8_t mcp23s17_read_reg | ( | uint8_t | reg, |
| uint8_t | hw_addr, | ||
| int | fd | ||
| ) |
Returns the 8 bit value from the register specified. Must also specify which hardware address and file descriptor to use.
| reg | The register to read from (example: IODIRA, GPIOA). |
| hw_addr | The hardware address of the MCP23S17. |
| fd | The file descriptor returned from <mcp23s17_open>"()". |
| int mcp23s17_wait_for_interrupt | ( | int | timeout | ) |
Waits for an interrupt from the mcp23s17 or until timeout is reached.
| timeout | Maximum ms to wait for input, -1 for forever |
| void mcp23s17_write_bit | ( | uint8_t | data, |
| uint8_t | bit_num, | ||
| uint8_t | reg, | ||
| uint8_t | hw_addr, | ||
| int | fd | ||
| ) |
Writes a single bit to the register specified. Must also specify which hardware address and file descriptor to use.
| data | The data to write. |
| bit_num | The bit number to write to. |
| reg | The register to write to (example: IODIRA, GPIOA). |
| hw_addr | The hardware address of the MCP23S17. |
| fd | The file descriptor returned from <mcp23s17_open>"()". |
| void mcp23s17_write_reg | ( | uint8_t | data, |
| uint8_t | reg, | ||
| uint8_t | hw_addr, | ||
| int | fd | ||
| ) |
Writes an 8 bit value to the register specified. Must also specify which hardware address and file descriptor to use.
| data | The data byte to be written. |
| reg | The register to write to (example: IODIRA, GPIOA). |
| hw_addr | The hardware address of the MCP23S17. |
| fd | The file descriptor returned from <mcp23s17_open>"()". |
1.8.1.2