Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter for SPI clock frequency to begin_SPI() functions #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Adafruit_MCP23XXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ bool Adafruit_MCP23XXX::begin_I2C(uint8_t i2c_addr, TwoWire *wire) {
@param cs_pin Pin to use for SPI chip select
@param theSPI Pointer to SPI instance
@param _hw_addr Hardware address (pins A2, A1, A0)
@param freq SPI clock frequency to use in Hz. Defaults to 1MHz
@return true if initialization successful, otherwise false.
*/
/**************************************************************************/
bool Adafruit_MCP23XXX::begin_SPI(uint8_t cs_pin, SPIClass *theSPI,
uint8_t _hw_addr) {
uint8_t _hw_addr, uint32_t freq) {
this->hw_addr = _hw_addr;
spi_dev = new Adafruit_SPIDevice(cs_pin, 1000000, SPI_BITORDER_MSBFIRST,
spi_dev = new Adafruit_SPIDevice(cs_pin, freq, SPI_BITORDER_MSBFIRST,
SPI_MODE0, theSPI);
return spi_dev->begin();
}
Expand All @@ -60,14 +61,15 @@ bool Adafruit_MCP23XXX::begin_SPI(uint8_t cs_pin, SPIClass *theSPI,
@param miso_pin Pin to use for SPI MISO
@param mosi_pin Pin to use for SPI MOSI
@param _hw_addr Hardware address (pins A2, A1, A0)
@param freq SPI clock frequency to use in Hz. Defaults to 1MHz
@return true if initialization successful, otherwise false.
*/
/**************************************************************************/
bool Adafruit_MCP23XXX::begin_SPI(int8_t cs_pin, int8_t sck_pin,
int8_t miso_pin, int8_t mosi_pin,
uint8_t _hw_addr) {
uint8_t _hw_addr, uint32_t freq) {
this->hw_addr = _hw_addr;
spi_dev = new Adafruit_SPIDevice(cs_pin, sck_pin, miso_pin, mosi_pin);
spi_dev = new Adafruit_SPIDevice(cs_pin, sck_pin, miso_pin, mosi_pin, freq);
return spi_dev->begin();
}

Expand Down
5 changes: 3 additions & 2 deletions src/Adafruit_MCP23XXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ class Adafruit_MCP23XXX {
// init
bool begin_I2C(uint8_t i2c_addr = MCP23XXX_ADDR, TwoWire *wire = &Wire);
bool begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI,
uint8_t _hw_addr = 0x00);
uint8_t _hw_addr = 0x00, uint32_t freq = 1000000);
bool begin_SPI(int8_t cs_pin, int8_t sck_pin, int8_t miso_pin,
int8_t mosi_pin, uint8_t _hw_addr = 0x00);
int8_t mosi_pin, uint8_t _hw_addr = 0x00,
uint32_t freq = 1000000);

// main Arduino API methods
void pinMode(uint8_t pin, uint8_t mode);
Expand Down
Loading