Browse Source

add PortMCP23S17::beginProtocol()

tags/v0.6.0
wolfv6 7 years ago
parent
commit
fbf4eda206
4 changed files with 15 additions and 9 deletions
  1. 2
    1
      src/PortInterface.h
  2. 10
    7
      src/PortMCP23S17.cpp
  3. 1
    0
      src/PortMCP23S17.h
  4. 2
    1
      src/Scanner_IOE.cpp

+ 2
- 1
src/PortInterface.h View File

class PortInterface class PortInterface
{ {
public: public:
virtual void begin(const uint8_t strobeOn)=0;
virtual void beginProtocol()=0; //SPI or I2C bus
virtual void begin(const uint8_t strobeOn)=0; //configure GPIO pins
virtual void write(const uint8_t strobePin, const bool pinLogicLevel)=0; virtual void write(const uint8_t strobePin, const bool pinLogicLevel)=0;
virtual uint8_t read()=0; virtual uint8_t read()=0;
}; };

+ 10
- 7
src/PortMCP23S17.cpp View File



/* begin() is called from Scanner_IOE::begin(). /* begin() is called from Scanner_IOE::begin().
Initiates SPI bus and configures I/O pins for read and write. Initiates SPI bus and configures I/O pins for read and write.
strobeOn is logic level of strobe on, HIGH or LOW


MCP23S17 SPI interface is 10 MHz max. MCP23S17 SPI interface is 10 MHz max.
The electrical limitation to bus speed is bus capacitance and the length of the wires involved. The electrical limitation to bus speed is bus capacitance and the length of the wires involved.
Longer wires require lower clock speeds. Longer wires require lower clock speeds.

begin() is called from Scanner_IOE::begin() twice, once each for refPortWrite and refPortRead.
The first 4 lines only need to be called once, but seem to work OK if called a second time.
*/ */
void PortMCP23S17::begin(const uint8_t strobeOn)
void PortMCP23S17::beginProtocol()
{ {
uint8_t pullUp; //bits, GPPU 0=pull-up disabled, 1=pull-up enabled

pinMode(SS, OUTPUT); //configure controller's Slave Select pin to output pinMode(SS, OUTPUT); //configure controller's Slave Select pin to output
digitalWrite(SS, HIGH); //disable Slave Select digitalWrite(SS, HIGH); //disable Slave Select
SPI.begin(); SPI.begin();
SPI.beginTransaction(SPISettings (5000000, MSBFIRST, SPI_MODE0)); //control SPI bus, 5 MHz SPI.beginTransaction(SPISettings (5000000, MSBFIRST, SPI_MODE0)); //control SPI bus, 5 MHz
//SPI.endTransaction() not called to release SPI bus because keyboard only has one SPI device //SPI.endTransaction() not called to release SPI bus because keyboard only has one SPI device
}

/* begin() is called from Scanner_IOE::begin().
strobeOn is logic level of strobe on, HIGH or LOW
configure IODIR and GPPU.
*/
void PortMCP23S17::begin(const uint8_t strobeOn)
{
uint8_t pullUp; //bits, GPPU 0=pull-up disabled, 1=pull-up enabled


if (strobeOn == LOW) //if active low, use internal pull-up resistors if (strobeOn == LOW) //if active low, use internal pull-up resistors
{ {

+ 1
- 0
src/PortMCP23S17.h View File

uint8_t transfer(const uint8_t command, const uint8_t registerAddr, const uint8_t data); uint8_t transfer(const uint8_t command, const uint8_t registerAddr, const uint8_t data);
public: public:
PortMCP23S17(PortIOE& port, const uint8_t readPins) : port(port), readPins(readPins) {} PortMCP23S17(PortIOE& port, const uint8_t readPins) : port(port), readPins(readPins) {}
void beginProtocol();
void begin(const uint8_t strobeOn); void begin(const uint8_t strobeOn);
virtual void write(const uint8_t pin, const bool logicLevel); virtual void write(const uint8_t pin, const bool logicLevel);
virtual uint8_t read(); virtual uint8_t read();

+ 2
- 1
src/Scanner_IOE.cpp View File

*/ */
void Scanner_IOE::begin() void Scanner_IOE::begin()
{ {
refPortRead.begin(strobeOn);
refPortWrite.beginProtocol();
refPortWrite.begin(strobeOn); refPortWrite.begin(strobeOn);
refPortRead.begin(strobeOn);
} }


/* scan() is called on every iteration of sketch loop(). /* scan() is called on every iteration of sketch loop().