mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-06-16 12:35:24 +02:00
Compare commits
No commits in common. "4f3b7068ca45fc751b9f4eea34637d8e646520cc" and "54f8aaf116f7f0476f9a19128f386cb283024a7f" have entirely different histories.
4f3b7068ca
...
54f8aaf116
101
IO_PCA9554.h
101
IO_PCA9554.h
@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* © 2025, Paul M. Antoine
|
|
||||||
* © 2021, Neil McKechnie. All rights reserved.
|
|
||||||
*
|
|
||||||
* This file is part of DCC-EX API
|
|
||||||
*
|
|
||||||
* This 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.
|
|
||||||
*
|
|
||||||
* It 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 CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef io_pca9554_h
|
|
||||||
#define io_pca9554_h
|
|
||||||
|
|
||||||
#include "IO_GPIOBase.h"
|
|
||||||
#include "FSH.h"
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/*
|
|
||||||
* IODevice subclass for PCA9554/TCA9554 8-bit I/O expander (NXP & Texas Instruments).
|
|
||||||
*/
|
|
||||||
|
|
||||||
class PCA9554 : public GPIOBase<uint8_t> {
|
|
||||||
public:
|
|
||||||
static void create(VPIN vpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1) {
|
|
||||||
if (checkNoOverlap(vpin, nPins, i2cAddress)) new PCA9554(vpin,nPins, i2cAddress, interruptPin);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
// Constructor
|
|
||||||
PCA9554(VPIN vpin, uint8_t nPins, I2CAddress I2CAddress, int interruptPin=-1)
|
|
||||||
: GPIOBase<uint8_t>((FSH *)F("PCA9554"), vpin, nPins, I2CAddress, interruptPin)
|
|
||||||
{
|
|
||||||
requestBlock.setRequestParams(_I2CAddress, inputBuffer, sizeof(inputBuffer),
|
|
||||||
outputBuffer, sizeof(outputBuffer));
|
|
||||||
outputBuffer[0] = REG_INPUT_P0;
|
|
||||||
}
|
|
||||||
void _writeGpioPort() override {
|
|
||||||
I2CManager.write(_I2CAddress, 2, REG_OUTPUT_P0, _portOutputState);
|
|
||||||
}
|
|
||||||
void _writePullups() override {
|
|
||||||
// Do nothing, pull-ups are always in place for input ports
|
|
||||||
// This function is here for HAL GPIOBase API compatibilitiy
|
|
||||||
|
|
||||||
}
|
|
||||||
void _writePortModes() override {
|
|
||||||
// Write 0 to REG_CONF_P0 & REG_CONF_P1 for in-use pins that are outputs, 1 for others.
|
|
||||||
// PCA9554 & TCA9554, Interrupt is always enabled for raising and falling edge
|
|
||||||
uint8_t temp = ~(_portMode & _portInUse);
|
|
||||||
I2CManager.write(_I2CAddress, 2, REG_CONF_P0, temp);
|
|
||||||
}
|
|
||||||
void _readGpioPort(bool immediate) override {
|
|
||||||
if (immediate) {
|
|
||||||
uint8_t buffer[1];
|
|
||||||
I2CManager.read(_I2CAddress, buffer, 1, 1, REG_INPUT_P0);
|
|
||||||
_portInputState = buffer[0];
|
|
||||||
} else {
|
|
||||||
// Queue new request
|
|
||||||
requestBlock.wait(); // Wait for preceding operation to complete
|
|
||||||
// Issue new request to read GPIO register
|
|
||||||
I2CManager.queueRequest(&requestBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// This function is invoked when an I/O operation on the requestBlock completes.
|
|
||||||
void _processCompletion(uint8_t status) override {
|
|
||||||
if (status == I2C_STATUS_OK)
|
|
||||||
_portInputState = inputBuffer[0];
|
|
||||||
else
|
|
||||||
_portInputState = 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _setupDevice() override {
|
|
||||||
// HAL API calls
|
|
||||||
_writePortModes();
|
|
||||||
_writePullups();
|
|
||||||
_writeGpioPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t inputBuffer[1];
|
|
||||||
uint8_t outputBuffer[1];
|
|
||||||
|
|
||||||
|
|
||||||
enum {
|
|
||||||
REG_INPUT_P0 = 0x00,
|
|
||||||
REG_OUTPUT_P0 = 0x01,
|
|
||||||
REG_POL_INV_P0 = 0x02,
|
|
||||||
REG_CONF_P0 = 0x03,
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
13
IO_PCF8574.h
13
IO_PCF8574.h
@ -1,5 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* © 2025 Herb Morton
|
|
||||||
* © 2022 Paul M Antoine
|
* © 2022 Paul M Antoine
|
||||||
* © 2021, Neil McKechnie. All rights reserved.
|
* © 2021, Neil McKechnie. All rights reserved.
|
||||||
*
|
*
|
||||||
@ -44,21 +43,15 @@
|
|||||||
|
|
||||||
class PCF8574 : public GPIOBase<uint8_t> {
|
class PCF8574 : public GPIOBase<uint8_t> {
|
||||||
public:
|
public:
|
||||||
static void create(VPIN firstVpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1, int initPortState=-1) {
|
static void create(VPIN firstVpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1) {
|
||||||
if (checkNoOverlap(firstVpin, nPins, i2cAddress)) new PCF8574(firstVpin, nPins, i2cAddress, interruptPin, initPortState);
|
if (checkNoOverlap(firstVpin, nPins, i2cAddress)) new PCF8574(firstVpin, nPins, i2cAddress, interruptPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PCF8574(VPIN firstVpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1, int initPortState=-1)
|
PCF8574(VPIN firstVpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1)
|
||||||
: GPIOBase<uint8_t>((FSH *)F("PCF8574"), firstVpin, nPins, i2cAddress, interruptPin)
|
: GPIOBase<uint8_t>((FSH *)F("PCF8574"), firstVpin, nPins, i2cAddress, interruptPin)
|
||||||
{
|
{
|
||||||
requestBlock.setReadParams(_I2CAddress, inputBuffer, 1);
|
requestBlock.setReadParams(_I2CAddress, inputBuffer, 1);
|
||||||
if (initPortState>=0) {
|
|
||||||
_portMode = 255; // set all pins to output mode
|
|
||||||
_portInUse = 255; // 8 ports in use
|
|
||||||
_portOutputState = initPortState; // initialize pins low-high 0-255
|
|
||||||
I2CManager.write(_I2CAddress, 1, initPortState);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The PCF8574 handles inputs by applying a weak pull-up when output is driven to '1'.
|
// The PCF8574 handles inputs by applying a weak pull-up when output is driven to '1'.
|
||||||
|
@ -146,13 +146,6 @@ void halSetup() {
|
|||||||
|
|
||||||
//PCF8574::create(200, 8, 0x23, 40);
|
//PCF8574::create(200, 8, 0x23, 40);
|
||||||
|
|
||||||
// Alternative form to initialize 8 pins as output
|
|
||||||
// INT pin -1, when INT is not used
|
|
||||||
|
|
||||||
//PCF8574::create(200, 8, 0x23, -1, 255); 8 pins High
|
|
||||||
//PCF8574::create(200, 8, 0x23, -1, 0); 8 pins Low
|
|
||||||
//PCF8574::create(200, 8, 0x23, -1, 0b11000010);
|
|
||||||
// pins listed sequentially from 7 to 0
|
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
// The following directive defines a PCF8575 16-port I2C GPIO Extender module.
|
// The following directive defines a PCF8575 16-port I2C GPIO Extender module.
|
||||||
|
@ -3,9 +3,7 @@
|
|||||||
|
|
||||||
#include "StringFormatter.h"
|
#include "StringFormatter.h"
|
||||||
|
|
||||||
#define VERSION "5.5.27"
|
#define VERSION "5.5.25"
|
||||||
// 5.5.27 - PCF8574 output pin initialization parameter
|
|
||||||
// 5.5.26 - PCA9554 and TCA9554/9534 I2C 8-bit GPIO expander drivers
|
|
||||||
// 5.2.25 - IO_Bitmap and assicated Exrail macros
|
// 5.2.25 - IO_Bitmap and assicated Exrail macros
|
||||||
// 5.5.24 - SensorCAM in I2C scan and automatically setClock
|
// 5.5.24 - SensorCAM in I2C scan and automatically setClock
|
||||||
// 5.5.23 - Reminder loop Idle packet optimization
|
// 5.5.23 - Reminder loop Idle packet optimization
|
||||||
|
Loading…
x
Reference in New Issue
Block a user