From 8cbcf5df32f9435825a4b4d135eeffafc603432a Mon Sep 17 00:00:00 2001 From: peteGSX Date: Thu, 8 Dec 2022 14:21:01 +1000 Subject: [PATCH 01/28] Basic shell of device driver started --- IO_EXIOExpander.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++ myPinMap.example.h | 28 ++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 IO_EXIOExpander.h create mode 100644 myPinMap.example.h diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h new file mode 100644 index 0000000..c979176 --- /dev/null +++ b/IO_EXIOExpander.h @@ -0,0 +1,79 @@ +/* + * © 2021, Peter Cole. All rights reserved. + * + * This file is part of EX-CommandStation + * + * 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 . +*/ + +/* +* The IO_EX-IOExpander.h device driver integrates with one or more EX-IOExpander devices. +* This device driver will configure the device and all I/O ports on startup, along with +* interacting with the device for all input/output duties. +*/ + +#ifndef IO_EX_IOEXPANDER_H +#define IO_EX_IOEXPANDER_H + +#include "IO_GPIOBase.h" +#include "FSH.h" + +#if __has_include ("myPinMap.h") + #include "myPinMap.h" +#else + #warning myPinMap.h not found. Using defaults from myPinMap.example.h + #include "myPinMap.example.h" +#endif + +///////////////////////////////////////////////////////////////////////////////////////////////////// +/* + * IODevice subclass for EX-IOExpander. + */ + +class EXIOExpander : public IODevice { +public: + static void create(VPIN vpin, int nPins, uint8_t i2cAddress) { + if (checkNoOverlap(vpin, nPins, i2cAddress)) new EXIOExpander(vpin, nPins, i2cAddress); + } + +private: + // Constructor + EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress) { + _firstVpin = firstVpin; + _nPins = nPins; + _i2cAddress = i2cAddress; + addDevice(this); + } + + void _begin() { + // Initialise EX-IOExander device + if (I2CManager.exists(_i2cAddress)) { +#ifdef DIAG_IO + _display(); +#endif + } else { + DIAG(F("EX-IOExpander device not found, I2C:%x"), _i2cAddress); + _deviceState = DEVSTATE_FAILED; + } + } + + void _display() override { + DIAG(F("EX-IOExpander I2C:x%x Configured on Vpins:%d-%d %S"), _i2cAddress, _firstVpin, _firstVpin+_nPins-1, + _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F("")); + } + + uint8_t _i2cAddress; +}; + +#endif \ No newline at end of file diff --git a/myPinMap.example.h b/myPinMap.example.h new file mode 100644 index 0000000..3afebc1 --- /dev/null +++ b/myPinMap.example.h @@ -0,0 +1,28 @@ +/* + * © 2022 Peter Cole. All rights reserved. + * + * This is the example configuration file for the EX-IOExpander pin map file. + * + * It is highly recommended to copy this to "myPinMap.h" and modify to suit your specific + * requirements. + * + * NOTE: Modifications to this file will be overwritten by future software updates. + */ +#ifndef MYPINMAP_H +#define MYPINMAP_H + +///////////////////////////////////////////////////////////////////////////////////// +// Define the number of I/O pins to be configured on the EX-IOExpander device +// +#define NUMBER_OF_DIGITAL_PINS 12 +#define NUMBER_OF_ANALOGUE_PINS 4 + +///////////////////////////////////////////////////////////////////////////////////// +// Define the pin map +// +// You must define the correct number of pins as per NUMBER_OF_PINS above +// +static uint8_t digitalPinMap[NUMBER_OF_DIGITAL_PINS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; +static uint8_t analoguePinMap[NUMBER_OF_ANALOGUE_PINS] = {A0, A1, A2, A3}; + +#endif \ No newline at end of file From 2d27cb052d499fa23454239c567670f88bb9c98c Mon Sep 17 00:00:00 2001 From: peteGSX Date: Fri, 9 Dec 2022 14:41:48 +1000 Subject: [PATCH 02/28] Add registers --- IO_EXIOExpander.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index c979176..67cbb3d 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -74,6 +74,15 @@ private: } uint8_t _i2cAddress; + + enum { + REG_EXIOINIT = 0x00, // Flag to initialise setup procedure + REG_EXIODPIN = 0x01, // Flag we're sending digital pin assignments + REG_EXIOAPIN = 0x02, // Flag we're sending analogue pin assignments + REG_EXIORDY = 0x03, // Flag we have completed setup procedure, also for EX-IO to ACK setup + REG_EXIODDIR = 0x04, // Flag we're sending digital pin direction configuration + REG_EXIODPUP = 0x05, // Flag we're sending digital pin pullup configuration + }; }; #endif \ No newline at end of file From 06945bb114fcfe009de039c0fa5ee4215d347873 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Sat, 10 Dec 2022 08:23:46 +1000 Subject: [PATCH 03/28] Try to add pin map classes --- EX-IOExpanderPinMaps.h | 38 +++++++++++++++++++++++++++ IO_EXIOExpander.h | 54 ++++++++++++++++++++++++++++++++------- myEX-IOExpander.example.h | 23 +++++++++++++++++ myPinMap.example.h | 28 -------------------- 4 files changed, 106 insertions(+), 37 deletions(-) create mode 100644 EX-IOExpanderPinMaps.h create mode 100644 myEX-IOExpander.example.h delete mode 100644 myPinMap.example.h diff --git a/EX-IOExpanderPinMaps.h b/EX-IOExpanderPinMaps.h new file mode 100644 index 0000000..b09dca3 --- /dev/null +++ b/EX-IOExpanderPinMaps.h @@ -0,0 +1,38 @@ +/* + * © 2022 Peter Cole + * + * This file is part of EX-CommandStation + * + * 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 . + */ + +/* +* This file defines default pin maps for the various architectures supported +* by default by EX-IOExpander. +* +* Custom user defined pinmaps should be defined in myEX-IOExpander.h. +* +* Any modifications to this file will be overwritten by future software updates. +*/ + +#define DEFAULT_NANO_DIGITAL_PINMAP new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) +#define DEFAULT_NANO_ANALOGUE_PINMAP new EXIOAnaloguePinMap(6,A0,A1,A2,A3,A6,A7) + +#define DEFAULT_UNO F("DEFAULT_UNO"), \ + new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) \ + new EXIOAnaloguePinMap(4,A0,A1,A2,A3) + +#define DEFAULT_MEGA F("DEFAULT_MEGA"), \ + new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) \ + new EXIOAnaloguePinMap(4,A0,A1,A2,A3) \ No newline at end of file diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index c979176..052ad72 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -28,31 +28,65 @@ #include "IO_GPIOBase.h" #include "FSH.h" +#include "EX-IOExpanderPinMaps.h" -#if __has_include ("myPinMap.h") - #include "myPinMap.h" -#else - #warning myPinMap.h not found. Using defaults from myPinMap.example.h - #include "myPinMap.example.h" +// Include user defined pin maps in myEX-IOExpander if defined +#if __has_include ("myEX-IOExpander.h") + #include "myEX-IOExpander.h" #endif +///////////////////////////////////////////////////////////////////////////////////////////////////// +/* + * EXIODigitalPinMap class for EX-IOExpander. + */ +class EXIODigitalPinMap { + public: + EXIODigitalPinMap(uint8_t numDigitalPins, uint8_t...); + EXIODigitalPinMap() = default; + + private: + EXIODigitalPinMap(uint8_t numDigitalPins, ...) { + _numDigitalPins = numDigitalPins; + uint8_t _digitalPinMap[_numDigitalPins]; + va_list _pinList; + va_start(_pinList, _numDigitalPins); + for (uint8_t pin = 0; pin < _numDigitalPins; pin++) { + _digitalPinMap[pin] = va_arg(_pinList, int); + } + va_end(_pinList); + } + + uint8_t _numDigitalPins; +}; + +///////////////////////////////////////////////////////////////////////////////////////////////////// +/* + * EXIOAnaloguePinMap class for EX-IOExpander. + */ +class EXIOAnaloguePinMap { + public: + EXIOAnaloguePinMap(uint8_t numAnaloguePins, ...); + EXIOAnaloguePinMap() = default; +}; + ///////////////////////////////////////////////////////////////////////////////////////////////////// /* * IODevice subclass for EX-IOExpander. */ - class EXIOExpander : public IODevice { public: - static void create(VPIN vpin, int nPins, uint8_t i2cAddress) { - if (checkNoOverlap(vpin, nPins, i2cAddress)) new EXIOExpander(vpin, nPins, i2cAddress); + static void create(VPIN vpin, int nPins, uint8_t i2cAddress, EXIODigitalPinMap digitalPinMap, EXIOAnaloguePinMap analoguePinMap) { + if (checkNoOverlap(vpin, nPins, i2cAddress)) new EXIOExpander(vpin, nPins, i2cAddress, digitalPinMap, analoguePinMap); } private: // Constructor - EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress) { + EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress, EXIODigitalPinMap digitalPinMap, EXIOAnaloguePinMap analoguePinMap) { _firstVpin = firstVpin; _nPins = nPins; _i2cAddress = i2cAddress; + _digitalPinMap = digitalPinMap; + _analoguePinMap = analoguePinMap; addDevice(this); } @@ -74,6 +108,8 @@ private: } uint8_t _i2cAddress; + EXIODigitalPinMap _digitalPinMap; + EXIOAnaloguePinMap _analoguePinMap; }; #endif \ No newline at end of file diff --git a/myEX-IOExpander.example.h b/myEX-IOExpander.example.h new file mode 100644 index 0000000..3402c92 --- /dev/null +++ b/myEX-IOExpander.example.h @@ -0,0 +1,23 @@ +/* + * © 2022 Peter Cole. All rights reserved. + * + * This is the example configuration file for a custom EX-IOExpander pin map file. + * + * It is highly recommended to copy this to "myEX-IOExpander.h" and modify to suit your specific + * requirements. + * + * If you are simply using a default definition for a defined microcontroller, then you don't + * need to use this file, and instead can use one of the existing definitions. + * + * Refer to https://dcc-ex.com for the full documentation. + * + * NOTE: Modifications to this file will be overwritten by future software updates. + */ +#ifndef MYEX_IOEXPANDER_H +#define MYEX_IOEXPANDER_H + +#define MY_CUSTOM_NANO F("MY_NANO_PINMAP"), \ + new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13) \ + new EXIOAnaloguePinMap(4,A0,A1,A2,A3) + +#endif \ No newline at end of file diff --git a/myPinMap.example.h b/myPinMap.example.h deleted file mode 100644 index 3afebc1..0000000 --- a/myPinMap.example.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * © 2022 Peter Cole. All rights reserved. - * - * This is the example configuration file for the EX-IOExpander pin map file. - * - * It is highly recommended to copy this to "myPinMap.h" and modify to suit your specific - * requirements. - * - * NOTE: Modifications to this file will be overwritten by future software updates. - */ -#ifndef MYPINMAP_H -#define MYPINMAP_H - -///////////////////////////////////////////////////////////////////////////////////// -// Define the number of I/O pins to be configured on the EX-IOExpander device -// -#define NUMBER_OF_DIGITAL_PINS 12 -#define NUMBER_OF_ANALOGUE_PINS 4 - -///////////////////////////////////////////////////////////////////////////////////// -// Define the pin map -// -// You must define the correct number of pins as per NUMBER_OF_PINS above -// -static uint8_t digitalPinMap[NUMBER_OF_DIGITAL_PINS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; -static uint8_t analoguePinMap[NUMBER_OF_ANALOGUE_PINS] = {A0, A1, A2, A3}; - -#endif \ No newline at end of file From 91049560094987a6c8df2456ac1c6905a66817fa Mon Sep 17 00:00:00 2001 From: peteGSX Date: Sat, 10 Dec 2022 08:28:20 +1000 Subject: [PATCH 04/28] Fix default pin maps --- EX-IOExpanderPinMaps.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/EX-IOExpanderPinMaps.h b/EX-IOExpanderPinMaps.h index b09dca3..b4fed55 100644 --- a/EX-IOExpanderPinMaps.h +++ b/EX-IOExpanderPinMaps.h @@ -29,10 +29,8 @@ #define DEFAULT_NANO_DIGITAL_PINMAP new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) #define DEFAULT_NANO_ANALOGUE_PINMAP new EXIOAnaloguePinMap(6,A0,A1,A2,A3,A6,A7) -#define DEFAULT_UNO F("DEFAULT_UNO"), \ - new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) \ - new EXIOAnaloguePinMap(4,A0,A1,A2,A3) +#define DEFAULT_UNO_DIGITAL_PINMAP new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) +#define DEFAULT_UNO_ANALOGUE_PINMAP new EXIOAnaloguePinMap(4,A0,A1,A2,A3) -#define DEFAULT_MEGA F("DEFAULT_MEGA"), \ - new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) \ - new EXIOAnaloguePinMap(4,A0,A1,A2,A3) \ No newline at end of file +#define DEFAULT_MEGA_DIGITAL_PINMAP new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) +#define DEFAULT_MEGA_ANALOGUE_PINMAP new EXIOAnaloguePinMap(4,A0,A1,A2,A3) From 7bc043319704670a3abacc030327504bdef586a0 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Sat, 10 Dec 2022 08:32:15 +1000 Subject: [PATCH 05/28] Add myHal.cpp example to driver --- IO_EXIOExpander.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 352711f..2157b79 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -21,6 +21,15 @@ * The IO_EX-IOExpander.h device driver integrates with one or more EX-IOExpander devices. * This device driver will configure the device and all I/O ports on startup, along with * interacting with the device for all input/output duties. +* +* To create EX-IOExpander devices, these are defined in myHal.cpp: +* +* #include "IO_EX-IOExpander.h" +* +* void halSetup() { +* // EXIOExpander::create(vpin, num_vpins, i2c_address, digital_pinmap, analogue_pinmap); +* EXIOExpander::create(800, 18, 0x90, DEFAULT_NANO_DIGITAL_PINMAP, DEFAULT_NANO_ANALOGUE_PINMAP); +} */ #ifndef IO_EX_IOEXPANDER_H From 1d5897d2d22973e50252e91065ec2479f608fbea Mon Sep 17 00:00:00 2001 From: peteGSX Date: Sat, 10 Dec 2022 19:14:32 +1000 Subject: [PATCH 06/28] A bit lost --- EX-IOExpanderPinMaps.h | 13 ++++++----- IO_EXIOExpander.h | 48 ++++----------------------------------- myEX-IOExpander.example.h | 5 ++-- 3 files changed, 14 insertions(+), 52 deletions(-) diff --git a/EX-IOExpanderPinMaps.h b/EX-IOExpanderPinMaps.h index b4fed55..46d03a9 100644 --- a/EX-IOExpanderPinMaps.h +++ b/EX-IOExpanderPinMaps.h @@ -26,11 +26,12 @@ * Any modifications to this file will be overwritten by future software updates. */ -#define DEFAULT_NANO_DIGITAL_PINMAP new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) -#define DEFAULT_NANO_ANALOGUE_PINMAP new EXIOAnaloguePinMap(6,A0,A1,A2,A3,A6,A7) +#define DEFAULT_NANO_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13 +#define DEFAULT_NANO_ANALOGUE_PINMAP A0,A1,A2,A3,A6,A7 -#define DEFAULT_UNO_DIGITAL_PINMAP new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) -#define DEFAULT_UNO_ANALOGUE_PINMAP new EXIOAnaloguePinMap(4,A0,A1,A2,A3) +#define DEFAULT_UNO_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13 +#define DEFAULT_UNO_ANALOGUE_PINMAP A0,A1,A2,A3 -#define DEFAULT_MEGA_DIGITAL_PINMAP new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A6,A7) -#define DEFAULT_MEGA_ANALOGUE_PINMAP new EXIOAnaloguePinMap(4,A0,A1,A2,A3) +#define DEFAULT_MEGA_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,28,29, \ + 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49 +#define DEFAULT_MEGA_ANALOGUE_PINMAP A0,A1,A2,A3,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15 diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 2157b79..0521ac7 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -27,8 +27,8 @@ * #include "IO_EX-IOExpander.h" * * void halSetup() { -* // EXIOExpander::create(vpin, num_vpins, i2c_address, digital_pinmap, analogue_pinmap); -* EXIOExpander::create(800, 18, 0x90, DEFAULT_NANO_DIGITAL_PINMAP, DEFAULT_NANO_ANALOGUE_PINMAP); +* // EXIOExpander::create(vpin, num_vpins, i2c_address); +* EXIOExpander::create(800, 18, 0x90); } */ @@ -44,58 +44,22 @@ #include "myEX-IOExpander.h" #endif -///////////////////////////////////////////////////////////////////////////////////////////////////// -/* - * EXIODigitalPinMap class for EX-IOExpander. - */ -class EXIODigitalPinMap { - public: - EXIODigitalPinMap(uint8_t numDigitalPins, uint8_t...); - EXIODigitalPinMap() = default; - - private: - EXIODigitalPinMap(uint8_t numDigitalPins, ...) { - _numDigitalPins = numDigitalPins; - uint8_t _digitalPinMap[_numDigitalPins]; - va_list _pinList; - va_start(_pinList, _numDigitalPins); - for (uint8_t pin = 0; pin < _numDigitalPins; pin++) { - _digitalPinMap[pin] = va_arg(_pinList, int); - } - va_end(_pinList); - } - - uint8_t _numDigitalPins; -}; - -///////////////////////////////////////////////////////////////////////////////////////////////////// -/* - * EXIOAnaloguePinMap class for EX-IOExpander. - */ -class EXIOAnaloguePinMap { - public: - EXIOAnaloguePinMap(uint8_t numAnaloguePins, ...); - EXIOAnaloguePinMap() = default; -}; - ///////////////////////////////////////////////////////////////////////////////////////////////////// /* * IODevice subclass for EX-IOExpander. */ class EXIOExpander : public IODevice { public: - static void create(VPIN vpin, int nPins, uint8_t i2cAddress, EXIODigitalPinMap digitalPinMap, EXIOAnaloguePinMap analoguePinMap) { - if (checkNoOverlap(vpin, nPins, i2cAddress)) new EXIOExpander(vpin, nPins, i2cAddress, digitalPinMap, analoguePinMap); + static void create(VPIN vpin, int nPins, uint8_t i2cAddress) { + if (checkNoOverlap(vpin, nPins, i2cAddress)) new EXIOExpander(vpin, nPins, i2cAddress); } private: // Constructor - EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress, EXIODigitalPinMap digitalPinMap, EXIOAnaloguePinMap analoguePinMap) { + EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress) { _firstVpin = firstVpin; _nPins = nPins; _i2cAddress = i2cAddress; - _digitalPinMap = digitalPinMap; - _analoguePinMap = analoguePinMap; addDevice(this); } @@ -117,8 +81,6 @@ private: } uint8_t _i2cAddress; - EXIODigitalPinMap _digitalPinMap; - EXIOAnaloguePinMap _analoguePinMap; enum { REG_EXIOINIT = 0x00, // Flag to initialise setup procedure diff --git a/myEX-IOExpander.example.h b/myEX-IOExpander.example.h index 3402c92..94e378e 100644 --- a/myEX-IOExpander.example.h +++ b/myEX-IOExpander.example.h @@ -16,8 +16,7 @@ #ifndef MYEX_IOEXPANDER_H #define MYEX_IOEXPANDER_H -#define MY_CUSTOM_NANO F("MY_NANO_PINMAP"), \ - new EXIODigitalPinMap(12,2,3,4,5,6,7,8,9,10,11,12,13) \ - new EXIOAnaloguePinMap(4,A0,A1,A2,A3) +#define MY_NANO_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13 +#define MY_NANO_ANALOGUE_PINMAP A0,A1,A2,A3 #endif \ No newline at end of file From cb9a8bb7a66a14fb67f707b9c1333936e7a9e438 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Sun, 11 Dec 2022 10:22:48 +1000 Subject: [PATCH 07/28] Getting somewhere --- EX-IOExpanderPins.h | 46 +++++++++++++++++++++++++++++++++++++++++++++ IO_EXIOExpander.h | 36 +++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 EX-IOExpanderPins.h diff --git a/EX-IOExpanderPins.h b/EX-IOExpanderPins.h new file mode 100644 index 0000000..fa32873 --- /dev/null +++ b/EX-IOExpanderPins.h @@ -0,0 +1,46 @@ +/* + * © 2022 Peter Cole + * + * This file is part of EX-CommandStation + * + * 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 . + */ + +/* +* This file defines default pin maps for the various architectures supported +* by default by EX-IOExpander. +* +* Custom user defined pinmaps should be defined in myEX-IOExpander.h. +* +* Any modifications to this file will be overwritten by future software updates. +*/ + +// #define DEFAULT_NANO_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13 +// #define DEFAULT_NANO_ANALOGUE_PINMAP A0,A1,A2,A3,A6,A7 + +#define EXIO_UNO_DIGITAL_PINS 12 +#define EXIO_UNO_ANALOGUE_PINS 4 + +#define EXIO_NANO_DIGITAL_PINS 12 +#define EXIO_NANO_ANALOGUE_PINS 6 + +#define EXIO_MEGA_DIGITAL_PINS 46 +#define EXIO_MEGA_ANALOGUE_PINS 16 + +// #define EXIO_UNO_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13 +// #define EXIO_UNO_ANALOGUE_PINMAP A0,A1,A2,A3 + +// #define DEFAULT_MEGA_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,28,29, \ +// 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49 +// #define DEFAULT_MEGA_ANALOGUE_PINMAP A0,A1,A2,A3,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15 diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 0521ac7..efd09cd 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -37,7 +37,7 @@ #include "IO_GPIOBase.h" #include "FSH.h" -#include "EX-IOExpanderPinMaps.h" +#include "EX-IOExpanderPins.h" // Include user defined pin maps in myEX-IOExpander if defined #if __has_include ("myEX-IOExpander.h") @@ -50,16 +50,18 @@ */ class EXIOExpander : public IODevice { public: - static void create(VPIN vpin, int nPins, uint8_t i2cAddress) { - if (checkNoOverlap(vpin, nPins, i2cAddress)) new EXIOExpander(vpin, nPins, i2cAddress); + static void create(VPIN vpin, int nPins, uint8_t i2cAddress, uint8_t numDigitalPins, uint8_t numAnaloguePins) { + if (checkNoOverlap(vpin, nPins, i2cAddress)) new EXIOExpander(vpin, nPins, i2cAddress, numDigitalPins, numAnaloguePins); } private: // Constructor - EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress) { + EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress, uint8_t numDigitalPins, uint8_t numAnaloguePins) { _firstVpin = firstVpin; _nPins = nPins; _i2cAddress = i2cAddress; + _numDigitalPins = numDigitalPins; + _numAnaloguePins = numAnaloguePins; addDevice(this); } @@ -69,18 +71,44 @@ private: #ifdef DIAG_IO _display(); #endif + _setupDevice(); } else { DIAG(F("EX-IOExpander device not found, I2C:%x"), _i2cAddress); _deviceState = DEVSTATE_FAILED; } } + void _setupDevice() { + // Send digital and analogue pin counts + I2CManager.write(_i2cAddress, 3, REG_EXIOINIT, _numDigitalPins, _numAnaloguePins); + // Enable digital ports + _digitalPinBytes = (_numDigitalPins + 7) / 8; + uint8_t enableDigitalPins[_digitalPinBytes]; + for (uint8_t pin = 0; pin < _numDigitalPins; pin++) { + int pinByte = ((pin + 7) / 8); + bitSet(enableDigitalPins[pinByte], (pin - (pinByte * 8))); + } + I2CManager.write(_i2cAddress, _digitalPinBytes + 1, REG_EXIODPIN, enableDigitalPins); + // Enable analogue ports + _analoguePinBytes = (_numAnaloguePins + 7) / 8; + uint8_t enableAnaloguePins[_analoguePinBytes]; + for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) { + int pinByte = ((pin + 7) / 8); + bitSet(enableAnaloguePins[pinByte], (pin - (pinByte * 8))); + } + I2CManager.write(_i2cAddress, _analoguePinBytes + 1, REG_EXIOAPIN, enableAnaloguePins); + } + void _display() override { DIAG(F("EX-IOExpander I2C:x%x Configured on Vpins:%d-%d %S"), _i2cAddress, _firstVpin, _firstVpin+_nPins-1, _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F("")); } uint8_t _i2cAddress; + uint8_t _numDigitalPins; + uint8_t _numAnaloguePins; + int _digitalPinBytes; + int _analoguePinBytes; enum { REG_EXIOINIT = 0x00, // Flag to initialise setup procedure From 9699a44081d8972776cd61ebf2b662d9c9dbf015 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Sun, 11 Dec 2022 10:25:29 +1000 Subject: [PATCH 08/28] Rename pin file --- EX-IOExpanderPinMaps.h | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 EX-IOExpanderPinMaps.h diff --git a/EX-IOExpanderPinMaps.h b/EX-IOExpanderPinMaps.h deleted file mode 100644 index 46d03a9..0000000 --- a/EX-IOExpanderPinMaps.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * © 2022 Peter Cole - * - * This file is part of EX-CommandStation - * - * 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 . - */ - -/* -* This file defines default pin maps for the various architectures supported -* by default by EX-IOExpander. -* -* Custom user defined pinmaps should be defined in myEX-IOExpander.h. -* -* Any modifications to this file will be overwritten by future software updates. -*/ - -#define DEFAULT_NANO_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13 -#define DEFAULT_NANO_ANALOGUE_PINMAP A0,A1,A2,A3,A6,A7 - -#define DEFAULT_UNO_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13 -#define DEFAULT_UNO_ANALOGUE_PINMAP A0,A1,A2,A3 - -#define DEFAULT_MEGA_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,28,29, \ - 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49 -#define DEFAULT_MEGA_ANALOGUE_PINMAP A0,A1,A2,A3,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15 From 785b515f9ec3c340604883fa3c30fd9331b955b5 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Sun, 11 Dec 2022 19:44:42 +1000 Subject: [PATCH 09/28] Bug fixes, update registers --- EX-IOExpanderPins.h | 14 +------------- IO_EXIOExpander.h | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/EX-IOExpanderPins.h b/EX-IOExpanderPins.h index fa32873..cbb726f 100644 --- a/EX-IOExpanderPins.h +++ b/EX-IOExpanderPins.h @@ -18,17 +18,12 @@ */ /* -* This file defines default pin maps for the various architectures supported +* This file defines default pin numbers for the various architectures supported * by default by EX-IOExpander. * -* Custom user defined pinmaps should be defined in myEX-IOExpander.h. -* * Any modifications to this file will be overwritten by future software updates. */ -// #define DEFAULT_NANO_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13 -// #define DEFAULT_NANO_ANALOGUE_PINMAP A0,A1,A2,A3,A6,A7 - #define EXIO_UNO_DIGITAL_PINS 12 #define EXIO_UNO_ANALOGUE_PINS 4 @@ -37,10 +32,3 @@ #define EXIO_MEGA_DIGITAL_PINS 46 #define EXIO_MEGA_ANALOGUE_PINS 16 - -// #define EXIO_UNO_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13 -// #define EXIO_UNO_ANALOGUE_PINMAP A0,A1,A2,A3 - -// #define DEFAULT_MEGA_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,28,29, \ -// 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49 -// #define DEFAULT_MEGA_ANALOGUE_PINMAP A0,A1,A2,A3,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15 diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index efd09cd..ca2bf10 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -84,19 +84,25 @@ private: // Enable digital ports _digitalPinBytes = (_numDigitalPins + 7) / 8; uint8_t enableDigitalPins[_digitalPinBytes]; - for (uint8_t pin = 0; pin < _numDigitalPins; pin++) { - int pinByte = ((pin + 7) / 8); - bitSet(enableDigitalPins[pinByte], (pin - (pinByte * 8))); + for (uint8_t byte = 0; byte < _digitalPinBytes; byte++) { + enableDigitalPins[byte] = 0; } - I2CManager.write(_i2cAddress, _digitalPinBytes + 1, REG_EXIODPIN, enableDigitalPins); + for (uint8_t pin = 0; pin < _numDigitalPins; pin++) { + int pinByte = pin / 8; + bitSet(enableDigitalPins[pinByte], pin - pinByte * 8); + } + I2CManager.write(_i2cAddress, _digitalPinBytes + 1, REG_EXIODPIN, *enableDigitalPins); // Enable analogue ports _analoguePinBytes = (_numAnaloguePins + 7) / 8; uint8_t enableAnaloguePins[_analoguePinBytes]; - for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) { - int pinByte = ((pin + 7) / 8); - bitSet(enableAnaloguePins[pinByte], (pin - (pinByte * 8))); + for (uint8_t byte = 0; byte < _analoguePinBytes; byte++) { + enableAnaloguePins[byte] = 0; } - I2CManager.write(_i2cAddress, _analoguePinBytes + 1, REG_EXIOAPIN, enableAnaloguePins); + for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) { + int pinByte = pin / 8; + bitSet(enableAnaloguePins[pinByte], pin - pinByte * 8); + } + I2CManager.write(_i2cAddress, _analoguePinBytes + 1, REG_EXIOAPIN, *enableAnaloguePins); } void _display() override { @@ -111,12 +117,12 @@ private: int _analoguePinBytes; enum { - REG_EXIOINIT = 0x00, // Flag to initialise setup procedure - REG_EXIODPIN = 0x01, // Flag we're sending digital pin assignments - REG_EXIOAPIN = 0x02, // Flag we're sending analogue pin assignments - REG_EXIORDY = 0x03, // Flag we have completed setup procedure, also for EX-IO to ACK setup - REG_EXIODDIR = 0x04, // Flag we're sending digital pin direction configuration - REG_EXIODPUP = 0x05, // Flag we're sending digital pin pullup configuration + REG_EXIOINIT = 0xE0, // Flag to initialise setup procedure + REG_EXIODPIN = 0xE1, // Flag we're sending digital pin assignments + REG_EXIOAPIN = 0xE2, // Flag we're sending analogue pin assignments + REG_EXIORDY = 0xE3, // Flag we have completed setup procedure, also for EX-IO to ACK setup + REG_EXIODDIR = 0xE4, // Flag we're sending digital pin direction configuration + REG_EXIODPUP = 0xE5, // Flag we're sending digital pin pullup configuration }; }; From 3862f7250dfcf4bee139ed5e511c90bcc27bf564 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Mon, 12 Dec 2022 19:54:20 +1000 Subject: [PATCH 10/28] Fix bugs, learn I2CManager --- IO_EXIOExpander.h | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index ca2bf10..1c2c570 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -35,7 +35,9 @@ #ifndef IO_EX_IOEXPANDER_H #define IO_EX_IOEXPANDER_H -#include "IO_GPIOBase.h" +#include "IODevice.h" +#include "I2CManager.h" +#include "DIAG.h" #include "FSH.h" #include "EX-IOExpanderPins.h" @@ -82,27 +84,29 @@ private: // Send digital and analogue pin counts I2CManager.write(_i2cAddress, 3, REG_EXIOINIT, _numDigitalPins, _numAnaloguePins); // Enable digital ports - _digitalPinBytes = (_numDigitalPins + 7) / 8; - uint8_t enableDigitalPins[_digitalPinBytes]; - for (uint8_t byte = 0; byte < _digitalPinBytes; byte++) { - enableDigitalPins[byte] = 0; + _digitalPinBytes = (_numDigitalPins + 7) / 8 + 1; + uint8_t _enableDigitalPins[_digitalPinBytes]; + _enableDigitalPins[0] = REG_EXIODPIN; + for (uint8_t byte = 1; byte < _digitalPinBytes; byte++) { + _enableDigitalPins[byte] = 0; } for (uint8_t pin = 0; pin < _numDigitalPins; pin++) { int pinByte = pin / 8; - bitSet(enableDigitalPins[pinByte], pin - pinByte * 8); + bitSet(_enableDigitalPins[pinByte + 1], pin - pinByte * 8); } - I2CManager.write(_i2cAddress, _digitalPinBytes + 1, REG_EXIODPIN, *enableDigitalPins); + I2CManager.write(_i2cAddress, _enableDigitalPins, _digitalPinBytes, &_i2crb); // Enable analogue ports - _analoguePinBytes = (_numAnaloguePins + 7) / 8; - uint8_t enableAnaloguePins[_analoguePinBytes]; - for (uint8_t byte = 0; byte < _analoguePinBytes; byte++) { - enableAnaloguePins[byte] = 0; + _analoguePinBytes = (_numAnaloguePins + 7) / 8 + 1; + uint8_t _enableAnaloguePins[_analoguePinBytes]; + _enableAnaloguePins[0] = REG_EXIOAPIN; + for (uint8_t byte = 1; byte < _analoguePinBytes; byte++) { + _enableAnaloguePins[byte] = 0; } for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) { int pinByte = pin / 8; - bitSet(enableAnaloguePins[pinByte], pin - pinByte * 8); + bitSet(_enableAnaloguePins[pinByte + 1], pin - pinByte * 8); } - I2CManager.write(_i2cAddress, _analoguePinBytes + 1, REG_EXIOAPIN, *enableAnaloguePins); + I2CManager.write(_i2cAddress, _enableAnaloguePins, _analoguePinBytes, &_i2crb); } void _display() override { @@ -115,6 +119,7 @@ private: uint8_t _numAnaloguePins; int _digitalPinBytes; int _analoguePinBytes; + I2CRB _i2crb; enum { REG_EXIOINIT = 0xE0, // Flag to initialise setup procedure From 8ecb408da7de74885d86bd6e2170e2a681dfaf97 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Tue, 13 Dec 2022 19:51:41 +1000 Subject: [PATCH 11/28] Update I2C address, fix bug setting analogue pins --- IO_EXIOExpander.h | 92 +++++++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 30 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 1c2c570..2331715 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -82,31 +82,58 @@ private: void _setupDevice() { // Send digital and analogue pin counts - I2CManager.write(_i2cAddress, 3, REG_EXIOINIT, _numDigitalPins, _numAnaloguePins); - // Enable digital ports - _digitalPinBytes = (_numDigitalPins + 7) / 8 + 1; - uint8_t _enableDigitalPins[_digitalPinBytes]; - _enableDigitalPins[0] = REG_EXIODPIN; - for (uint8_t byte = 1; byte < _digitalPinBytes; byte++) { - _enableDigitalPins[byte] = 0; + uint8_t _setupBuffer[3] = {EXIOINIT, _numDigitalPins, _numAnaloguePins}; + // I2CManager.write(_i2cAddress, 3, EXIOINIT, _numDigitalPins, _numAnaloguePins); + I2CManager.write(_i2cAddress, _setupBuffer, 3, &_i2crb); + _activity = EXIODPIN; + } + + void _loop(unsigned long currentMicros) override { + if (_i2crb.status == I2C_STATUS_PENDING) return; + if (_i2crb.status == I2C_STATUS_OK) { + switch(_activity) { + case EXIODPIN: + // Enable digital ports + _digitalPinBytes = (_numDigitalPins + 7) / 8 + 1; + // uint8_t _enableDigitalPins[_digitalPinBytes]; + // _enableDigitalPins[0] = EXIODPIN; + _digitalOutBuffer[0] = EXIODPIN; + for (uint8_t byte = 1; byte < _digitalPinBytes; byte++) { + // _enableDigitalPins[byte] = 0; + _digitalOutBuffer[byte] = 0; + } + for (uint8_t pin = 0; pin < _numDigitalPins; pin++) { + int pinByte = pin / 8; + // bitSet(_enableDigitalPins[pinByte + 1], pin - pinByte * 8); + bitSet(_digitalOutBuffer[pinByte + 1], pin - pinByte * 8); + } + // I2CManager.write(_i2cAddress, _enableDigitalPins, _digitalPinBytes, &_i2crb); + I2CManager.write(_i2cAddress, _digitalOutBuffer, _digitalPinBytes, &_i2crb); + _activity = EXIOAPIN; + break; + case EXIOAPIN: + // Enable analogue ports + _analoguePinBytes = (_numAnaloguePins + 7) / 8 + 1; + // uint8_t _enableAnaloguePins[_analoguePinBytes]; + // _enableAnaloguePins[0] = EXIOAPIN; + _analogueOutBuffer[0] = EXIOAPIN; + for (uint8_t byte = 1; byte < _analoguePinBytes; byte++) { + // _enableAnaloguePins[byte] = 0; + _analogueOutBuffer[byte] = 0; + } + for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) { + int pinByte = pin / 8; + // bitSet(_enableAnaloguePins[pinByte + 1], pin - pinByte * 8); + bitSet(_analogueOutBuffer[pinByte + 1], pin - pinByte * 8); + } + // I2CManager.write(_i2cAddress, _enableAnaloguePins, _analoguePinBytes, &_i2crb); + I2CManager.write(_i2cAddress, _analogueOutBuffer, _analoguePinBytes, &_i2crb); + _activity = EXIORDY; + break; + default: + break; + } } - for (uint8_t pin = 0; pin < _numDigitalPins; pin++) { - int pinByte = pin / 8; - bitSet(_enableDigitalPins[pinByte + 1], pin - pinByte * 8); - } - I2CManager.write(_i2cAddress, _enableDigitalPins, _digitalPinBytes, &_i2crb); - // Enable analogue ports - _analoguePinBytes = (_numAnaloguePins + 7) / 8 + 1; - uint8_t _enableAnaloguePins[_analoguePinBytes]; - _enableAnaloguePins[0] = REG_EXIOAPIN; - for (uint8_t byte = 1; byte < _analoguePinBytes; byte++) { - _enableAnaloguePins[byte] = 0; - } - for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) { - int pinByte = pin / 8; - bitSet(_enableAnaloguePins[pinByte + 1], pin - pinByte * 8); - } - I2CManager.write(_i2cAddress, _enableAnaloguePins, _analoguePinBytes, &_i2crb); } void _display() override { @@ -119,15 +146,20 @@ private: uint8_t _numAnaloguePins; int _digitalPinBytes; int _analoguePinBytes; + uint8_t _digitalOutBuffer[EXIO_NANO_DIGITAL_PINS + 1]; + uint8_t _digitalInBufer[EXIO_NANO_DIGITAL_PINS]; + uint8_t _analogueOutBuffer[EXIO_NANO_ANALOGUE_PINS + 1]; + uint8_t _analogueInBuffer[EXIO_NANO_ANALOGUE_PINS]; + uint8_t _activity; I2CRB _i2crb; enum { - REG_EXIOINIT = 0xE0, // Flag to initialise setup procedure - REG_EXIODPIN = 0xE1, // Flag we're sending digital pin assignments - REG_EXIOAPIN = 0xE2, // Flag we're sending analogue pin assignments - REG_EXIORDY = 0xE3, // Flag we have completed setup procedure, also for EX-IO to ACK setup - REG_EXIODDIR = 0xE4, // Flag we're sending digital pin direction configuration - REG_EXIODPUP = 0xE5, // Flag we're sending digital pin pullup configuration + EXIOINIT = 0xE0, // Flag to initialise setup procedure + EXIODPIN = 0xE1, // Flag we're sending digital pin assignments + EXIOAPIN = 0xE2, // Flag we're sending analogue pin assignments + EXIORDY = 0xE3, // Flag we have completed setup procedure, also for EX-IO to ACK setup + EXIODDIR = 0xE4, // Flag we're sending digital pin direction configuration + EXIODPUP = 0xE5, // Flag we're sending digital pin pullup configuration }; }; From 75f1a8f43a9187f0d09a7ad6daa3a265074c5428 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Wed, 14 Dec 2022 07:49:09 +1000 Subject: [PATCH 12/28] More bugs to fix --- IO_EXIOExpander.h | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 2331715..f3cbfbe 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -27,8 +27,8 @@ * #include "IO_EX-IOExpander.h" * * void halSetup() { -* // EXIOExpander::create(vpin, num_vpins, i2c_address); -* EXIOExpander::create(800, 18, 0x90); +* // EXIOExpander::create(vpin, num_vpins, i2c_address, digitalPinCount, analoguePinCount); +* EXIOExpander::create(800, 18, 0x90, 12, 6); } */ @@ -69,64 +69,56 @@ private: void _begin() { // Initialise EX-IOExander device + uint8_t _check = I2CManager.checkAddress(_i2cAddress); + DIAG(F("I2C status check: %d"), _check); if (I2CManager.exists(_i2cAddress)) { + _activity = EXIOINIT; #ifdef DIAG_IO _display(); #endif - _setupDevice(); } else { - DIAG(F("EX-IOExpander device not found, I2C:%x"), _i2cAddress); + DIAG(F("EX-IOExpander device not found, I2C:x%x"), _i2cAddress); _deviceState = DEVSTATE_FAILED; } } - void _setupDevice() { - // Send digital and analogue pin counts - uint8_t _setupBuffer[3] = {EXIOINIT, _numDigitalPins, _numAnaloguePins}; - // I2CManager.write(_i2cAddress, 3, EXIOINIT, _numDigitalPins, _numAnaloguePins); - I2CManager.write(_i2cAddress, _setupBuffer, 3, &_i2crb); - _activity = EXIODPIN; - } - void _loop(unsigned long currentMicros) override { if (_i2crb.status == I2C_STATUS_PENDING) return; if (_i2crb.status == I2C_STATUS_OK) { switch(_activity) { + case EXIOINIT: + // Send digital and analogue pin counts + _setupBuffer[0] = EXIOINIT; + _setupBuffer[1] = _numDigitalPins; + _setupBuffer[2] = _numAnaloguePins; + I2CManager.write(_i2cAddress, _setupBuffer, 3, &_i2crb); + _activity = EXIODPIN; + break; case EXIODPIN: // Enable digital ports _digitalPinBytes = (_numDigitalPins + 7) / 8 + 1; - // uint8_t _enableDigitalPins[_digitalPinBytes]; - // _enableDigitalPins[0] = EXIODPIN; _digitalOutBuffer[0] = EXIODPIN; for (uint8_t byte = 1; byte < _digitalPinBytes; byte++) { - // _enableDigitalPins[byte] = 0; _digitalOutBuffer[byte] = 0; } for (uint8_t pin = 0; pin < _numDigitalPins; pin++) { int pinByte = pin / 8; - // bitSet(_enableDigitalPins[pinByte + 1], pin - pinByte * 8); bitSet(_digitalOutBuffer[pinByte + 1], pin - pinByte * 8); } - // I2CManager.write(_i2cAddress, _enableDigitalPins, _digitalPinBytes, &_i2crb); I2CManager.write(_i2cAddress, _digitalOutBuffer, _digitalPinBytes, &_i2crb); _activity = EXIOAPIN; break; case EXIOAPIN: // Enable analogue ports _analoguePinBytes = (_numAnaloguePins + 7) / 8 + 1; - // uint8_t _enableAnaloguePins[_analoguePinBytes]; - // _enableAnaloguePins[0] = EXIOAPIN; _analogueOutBuffer[0] = EXIOAPIN; for (uint8_t byte = 1; byte < _analoguePinBytes; byte++) { - // _enableAnaloguePins[byte] = 0; _analogueOutBuffer[byte] = 0; } for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) { int pinByte = pin / 8; - // bitSet(_enableAnaloguePins[pinByte + 1], pin - pinByte * 8); bitSet(_analogueOutBuffer[pinByte + 1], pin - pinByte * 8); } - // I2CManager.write(_i2cAddress, _enableAnaloguePins, _analoguePinBytes, &_i2crb); I2CManager.write(_i2cAddress, _analogueOutBuffer, _analoguePinBytes, &_i2crb); _activity = EXIORDY; break; @@ -146,6 +138,7 @@ private: uint8_t _numAnaloguePins; int _digitalPinBytes; int _analoguePinBytes; + uint8_t _setupBuffer[3]; uint8_t _digitalOutBuffer[EXIO_NANO_DIGITAL_PINS + 1]; uint8_t _digitalInBufer[EXIO_NANO_DIGITAL_PINS]; uint8_t _analogueOutBuffer[EXIO_NANO_ANALOGUE_PINS + 1]; From 070daa37dc5bcc6fd5ba780c128623f34358fb15 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Thu, 15 Dec 2022 07:58:21 +1000 Subject: [PATCH 13/28] Move buffers to constructor --- IO_EXIOExpander.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index f3cbfbe..f936677 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -52,18 +52,22 @@ */ class EXIOExpander : public IODevice { public: - static void create(VPIN vpin, int nPins, uint8_t i2cAddress, uint8_t numDigitalPins, uint8_t numAnaloguePins) { + static void create(VPIN vpin, int nPins, uint8_t i2cAddress, byte numDigitalPins, byte numAnaloguePins) { if (checkNoOverlap(vpin, nPins, i2cAddress)) new EXIOExpander(vpin, nPins, i2cAddress, numDigitalPins, numAnaloguePins); } private: // Constructor - EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress, uint8_t numDigitalPins, uint8_t numAnaloguePins) { + EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress, byte numDigitalPins, byte numAnaloguePins) { _firstVpin = firstVpin; _nPins = nPins; _i2cAddress = i2cAddress; _numDigitalPins = numDigitalPins; _numAnaloguePins = numAnaloguePins; + _digitalOutBuffer = (byte *)calloc(_numDigitalPins + 1, 1); + _digitalInBuffer = (byte *)calloc(_numDigitalPins, 1); + _analogueOutBuffer = (byte *)calloc(_numAnaloguePins + 1, 1); + _analogueInBuffer = (byte *)calloc(_numAnaloguePins, 1); addDevice(this); } @@ -139,10 +143,10 @@ private: int _digitalPinBytes; int _analoguePinBytes; uint8_t _setupBuffer[3]; - uint8_t _digitalOutBuffer[EXIO_NANO_DIGITAL_PINS + 1]; - uint8_t _digitalInBufer[EXIO_NANO_DIGITAL_PINS]; - uint8_t _analogueOutBuffer[EXIO_NANO_ANALOGUE_PINS + 1]; - uint8_t _analogueInBuffer[EXIO_NANO_ANALOGUE_PINS]; + byte * _digitalOutBuffer = NULL; + byte * _digitalInBuffer = NULL; + byte * _analogueOutBuffer = NULL; + byte * _analogueInBuffer = NULL; uint8_t _activity; I2CRB _i2crb; From a480a5a3d29d1b7ed1bb93f2bdab568a537d038e Mon Sep 17 00:00:00 2001 From: peteGSX Date: Thu, 15 Dec 2022 15:10:53 +1000 Subject: [PATCH 14/28] Add comments, remove unnecessary functions --- IO_EXIOExpander.h | 55 ++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index f936677..fee4884 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -28,8 +28,16 @@ * * void halSetup() { * // EXIOExpander::create(vpin, num_vpins, i2c_address, digitalPinCount, analoguePinCount); -* EXIOExpander::create(800, 18, 0x90, 12, 6); -} +* EXIOExpander::create(800, 18, 0x65, EXIO_NANO_DIGITAL_PINS, EXIO_NANO_ANALOGUE_PINS); +* } +* +* Note when defining the number of digital and analogue pins, there is no way to sanity check +* this from the device driver, and it is up to the user to define the correct values here. +* +* Vpins are allocated to digital pins first, and then analogue pins, so digital pins will +* populate the first part of the specified vpin range, with the analogue pins populating the +* last part of the vpin range. +* Eg. for a default Nano, 800 - 811 are digital (D2 - D13), 812 to 817 are analogue (A0 - A3, A6/A7). */ #ifndef IO_EX_IOEXPANDER_H @@ -74,9 +82,8 @@ private: void _begin() { // Initialise EX-IOExander device uint8_t _check = I2CManager.checkAddress(_i2cAddress); - DIAG(F("I2C status check: %d"), _check); if (I2CManager.exists(_i2cAddress)) { - _activity = EXIOINIT; + _activity = EXIOINIT; // First thing to do is configure EX-IOExpander device #ifdef DIAG_IO _display(); #endif @@ -87,43 +94,15 @@ private: } void _loop(unsigned long currentMicros) override { - if (_i2crb.status == I2C_STATUS_PENDING) return; + if (_i2crb.status == I2C_STATUS_PENDING) return; // Do nothing if I2C isn't ready yet if (_i2crb.status == I2C_STATUS_OK) { switch(_activity) { case EXIOINIT: - // Send digital and analogue pin counts + // Send digital and analogue pin counts to configure EX-IOExpander _setupBuffer[0] = EXIOINIT; _setupBuffer[1] = _numDigitalPins; _setupBuffer[2] = _numAnaloguePins; I2CManager.write(_i2cAddress, _setupBuffer, 3, &_i2crb); - _activity = EXIODPIN; - break; - case EXIODPIN: - // Enable digital ports - _digitalPinBytes = (_numDigitalPins + 7) / 8 + 1; - _digitalOutBuffer[0] = EXIODPIN; - for (uint8_t byte = 1; byte < _digitalPinBytes; byte++) { - _digitalOutBuffer[byte] = 0; - } - for (uint8_t pin = 0; pin < _numDigitalPins; pin++) { - int pinByte = pin / 8; - bitSet(_digitalOutBuffer[pinByte + 1], pin - pinByte * 8); - } - I2CManager.write(_i2cAddress, _digitalOutBuffer, _digitalPinBytes, &_i2crb); - _activity = EXIOAPIN; - break; - case EXIOAPIN: - // Enable analogue ports - _analoguePinBytes = (_numAnaloguePins + 7) / 8 + 1; - _analogueOutBuffer[0] = EXIOAPIN; - for (uint8_t byte = 1; byte < _analoguePinBytes; byte++) { - _analogueOutBuffer[byte] = 0; - } - for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) { - int pinByte = pin / 8; - bitSet(_analogueOutBuffer[pinByte + 1], pin - pinByte * 8); - } - I2CManager.write(_i2cAddress, _analogueOutBuffer, _analoguePinBytes, &_i2crb); _activity = EXIORDY; break; default: @@ -152,11 +131,9 @@ private: enum { EXIOINIT = 0xE0, // Flag to initialise setup procedure - EXIODPIN = 0xE1, // Flag we're sending digital pin assignments - EXIOAPIN = 0xE2, // Flag we're sending analogue pin assignments - EXIORDY = 0xE3, // Flag we have completed setup procedure, also for EX-IO to ACK setup - EXIODDIR = 0xE4, // Flag we're sending digital pin direction configuration - EXIODPUP = 0xE5, // Flag we're sending digital pin pullup configuration + EXIORDY = 0xE1, // Flag we have completed setup procedure, also for EX-IO to ACK setup + EXIODDIR = 0xE2, // Flag we're sending digital pin direction configuration + EXIODPUP = 0xE3, // Flag we're sending digital pin pullup configuration }; }; From c8fea3a4a7b4e9e26bd0c81cec6fba5f0d76f14d Mon Sep 17 00:00:00 2001 From: peteGSX Date: Sun, 18 Dec 2022 09:43:11 +1000 Subject: [PATCH 15/28] Add version, analogue reads working --- IO_EXIOExpander.h | 30 ++++++++++++++++++++++++------ IO_EXIOExpander_version.h | 10 ++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 IO_EXIOExpander_version.h diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index fee4884..94bd589 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -48,6 +48,7 @@ #include "DIAG.h" #include "FSH.h" #include "EX-IOExpanderPins.h" +#include "IO_EXIOExpander_version.h" // Include user defined pin maps in myEX-IOExpander if defined #if __has_include ("myEX-IOExpander.h") @@ -60,13 +61,13 @@ */ class EXIOExpander : public IODevice { public: - static void create(VPIN vpin, int nPins, uint8_t i2cAddress, byte numDigitalPins, byte numAnaloguePins) { + static void create(VPIN vpin, int nPins, uint8_t i2cAddress, int numDigitalPins, int numAnaloguePins) { if (checkNoOverlap(vpin, nPins, i2cAddress)) new EXIOExpander(vpin, nPins, i2cAddress, numDigitalPins, numAnaloguePins); } private: // Constructor - EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress, byte numDigitalPins, byte numAnaloguePins) { + EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress, int numDigitalPins, int numAnaloguePins) { _firstVpin = firstVpin; _nPins = nPins; _i2cAddress = i2cAddress; @@ -74,8 +75,8 @@ private: _numAnaloguePins = numAnaloguePins; _digitalOutBuffer = (byte *)calloc(_numDigitalPins + 1, 1); _digitalInBuffer = (byte *)calloc(_numDigitalPins, 1); - _analogueOutBuffer = (byte *)calloc(_numAnaloguePins + 1, 1); - _analogueInBuffer = (byte *)calloc(_numAnaloguePins, 1); + _analogueValues = (uint16_t *)calloc(_numAnaloguePins, 1); + _currentAPin = _nPins - _numAnaloguePins; addDevice(this); } @@ -84,6 +85,7 @@ private: uint8_t _check = I2CManager.checkAddress(_i2cAddress); if (I2CManager.exists(_i2cAddress)) { _activity = EXIOINIT; // First thing to do is configure EX-IOExpander device + DIAG(F("EX-IOExpander x%x using driver version %S"), _i2cAddress, EXIO_VERSION); #ifdef DIAG_IO _display(); #endif @@ -105,10 +107,22 @@ private: I2CManager.write(_i2cAddress, _setupBuffer, 3, &_i2crb); _activity = EXIORDY; break; + case EXIORDY: + _analogueOutBuffer[0] = EXIORDAN; + _analogueOutBuffer[1] = _currentAPin - _numDigitalPins; + I2CManager.read(_i2cAddress, _analogueInBuffer, 2, _analogueOutBuffer, 2, &_i2crb); + _analogueValues[_currentAPin] = (_analogueInBuffer[1] << 8) + _analogueInBuffer[0]; + if (++_currentAPin >= _numDigitalPins + _numAnaloguePins) _currentAPin = _nPins - _numAnaloguePins; default: break; } } + // delayUntil(currentMicros + 2000000); // Delay 2 seconds while bug fixing/developing + } + + int _readAnalogue(VPIN vpin) override { + int pin = vpin - _firstVpin; + return _analogueValues[pin]; } void _display() override { @@ -124,8 +138,10 @@ private: uint8_t _setupBuffer[3]; byte * _digitalOutBuffer = NULL; byte * _digitalInBuffer = NULL; - byte * _analogueOutBuffer = NULL; - byte * _analogueInBuffer = NULL; + byte _analogueInBuffer[2]; + byte _analogueOutBuffer[2]; + uint16_t * _analogueValues = NULL; + uint8_t _currentAPin; // Current analogue pin to read uint8_t _activity; I2CRB _i2crb; @@ -134,6 +150,8 @@ private: EXIORDY = 0xE1, // Flag we have completed setup procedure, also for EX-IO to ACK setup EXIODDIR = 0xE2, // Flag we're sending digital pin direction configuration EXIODPUP = 0xE3, // Flag we're sending digital pin pullup configuration + EXIOOP = 0xE4, // Flag to say we're operating normally + EXIORDAN = 0xE5, // Flag to read an analogue input }; }; diff --git a/IO_EXIOExpander_version.h b/IO_EXIOExpander_version.h new file mode 100644 index 0000000..6d2e553 --- /dev/null +++ b/IO_EXIOExpander_version.h @@ -0,0 +1,10 @@ +#ifndef IO_EXIOEXPANDER_VERSION_H +#define IO_EXIOEXPANDER_VERSION_H + +#include "StringFormatter.h" + + +#define EXIO_VERSION "0.0.1alpha" +// 0.0.1 Initial version for alpha testing + +#endif \ No newline at end of file From 943494385f2a259a46f8d19e13abcdd8ba48a3d7 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Sun, 18 Dec 2022 18:59:16 +1000 Subject: [PATCH 16/28] Add digital write --- IO_EXIOExpander.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 94bd589..90dd06d 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -125,6 +125,14 @@ private: return _analogueValues[pin]; } + void _write(VPIN vpin, int value) override { + int pin = vpin - _firstVpin; + _digitalWriteBuffer[0] = EXIOWRD; + _digitalWriteBuffer[1] = pin; + _digitalWriteBuffer[2] = value; + I2CManager.write(_i2cAddress, _digitalWriteBuffer, 3, &_i2crb); + } + void _display() override { DIAG(F("EX-IOExpander I2C:x%x Configured on Vpins:%d-%d %S"), _i2cAddress, _firstVpin, _firstVpin+_nPins-1, _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F("")); @@ -140,6 +148,7 @@ private: byte * _digitalInBuffer = NULL; byte _analogueInBuffer[2]; byte _analogueOutBuffer[2]; + byte _digitalWriteBuffer[3]; uint16_t * _analogueValues = NULL; uint8_t _currentAPin; // Current analogue pin to read uint8_t _activity; @@ -152,6 +161,7 @@ private: EXIODPUP = 0xE3, // Flag we're sending digital pin pullup configuration EXIOOP = 0xE4, // Flag to say we're operating normally EXIORDAN = 0xE5, // Flag to read an analogue input + EXIOWRD = 0xE6, // Flag for digital write }; }; From 3973996344c7973dd66291d6cf5d3cd28990fb8c Mon Sep 17 00:00:00 2001 From: peteGSX Date: Mon, 19 Dec 2022 14:24:49 +1000 Subject: [PATCH 17/28] Digital pin config done, digital read in progress --- IO_EXIOExpander.h | 53 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 90dd06d..3641dfd 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -73,10 +73,11 @@ private: _i2cAddress = i2cAddress; _numDigitalPins = numDigitalPins; _numAnaloguePins = numAnaloguePins; - _digitalOutBuffer = (byte *)calloc(_numDigitalPins + 1, 1); - _digitalInBuffer = (byte *)calloc(_numDigitalPins, 1); + // _digitalOutBuffer = (byte *)calloc(_numDigitalPins + 1, 1); + // _digitalInBuffer = (byte *)calloc(_numDigitalPins, 1); _analogueValues = (uint16_t *)calloc(_numAnaloguePins, 1); _currentAPin = _nPins - _numAnaloguePins; + int _dPinArrayLen = (_numDigitalPins + 7) / 8; addDevice(this); } @@ -120,17 +121,40 @@ private: // delayUntil(currentMicros + 2000000); // Delay 2 seconds while bug fixing/developing } + bool _configure(VPIN vpin, ConfigTypeEnum configType, int paramCount, int params[]) override { + if (configType != CONFIGURE_INPUT) return false; + if (paramCount != 1) return false; + bool pullup = params[0]; + int pin = vpin - _firstVpin; + uint8_t mask = 1 << ((pin-_firstVpin) % 8); + DIAG(F("Configure vpin|pin %d|%d as input, pullup %d"), vpin, pin, pullup); + _digitalOutBuffer[0] = EXIODPUP; + _digitalOutBuffer[1] = pin; + _digitalOutBuffer[2] = pullup; + I2CManager.write(_i2cAddress, _digitalOutBuffer, 3, &_i2crb); + return true; + } + int _readAnalogue(VPIN vpin) override { int pin = vpin - _firstVpin; return _analogueValues[pin]; } + int _read(VPIN vpin) override { + int pin = vpin - _firstVpin; + _digitalOutBuffer[0] = EXIORDD; + _digitalOutBuffer[1] = pin; + _digitalOutBuffer[2] = 0x00; // Don't need to use this for reading + int _value = I2CManager.read(_i2cAddress, _digitalInBuffer, 1, _digitalOutBuffer, 3, &_i2crb); + return _value; + } + void _write(VPIN vpin, int value) override { int pin = vpin - _firstVpin; - _digitalWriteBuffer[0] = EXIOWRD; - _digitalWriteBuffer[1] = pin; - _digitalWriteBuffer[2] = value; - I2CManager.write(_i2cAddress, _digitalWriteBuffer, 3, &_i2crb); + _digitalOutBuffer[0] = EXIOWRD; + _digitalOutBuffer[1] = pin; + _digitalOutBuffer[2] = value; + I2CManager.write(_i2cAddress, _digitalOutBuffer, 3, &_i2crb); } void _display() override { @@ -144,11 +168,12 @@ private: int _digitalPinBytes; int _analoguePinBytes; uint8_t _setupBuffer[3]; - byte * _digitalOutBuffer = NULL; - byte * _digitalInBuffer = NULL; + // byte * _digitalOutBuffer = NULL; + // byte * _digitalInBuffer = NULL; byte _analogueInBuffer[2]; byte _analogueOutBuffer[2]; - byte _digitalWriteBuffer[3]; + byte _digitalOutBuffer[3]; + byte _digitalInBuffer[1]; uint16_t * _analogueValues = NULL; uint8_t _currentAPin; // Current analogue pin to read uint8_t _activity; @@ -157,11 +182,11 @@ private: enum { EXIOINIT = 0xE0, // Flag to initialise setup procedure EXIORDY = 0xE1, // Flag we have completed setup procedure, also for EX-IO to ACK setup - EXIODDIR = 0xE2, // Flag we're sending digital pin direction configuration - EXIODPUP = 0xE3, // Flag we're sending digital pin pullup configuration - EXIOOP = 0xE4, // Flag to say we're operating normally - EXIORDAN = 0xE5, // Flag to read an analogue input - EXIOWRD = 0xE6, // Flag for digital write + EXIODPUP = 0xE2, // Flag we're sending digital pin pullup configuration + EXIOOP = 0xE3, // Flag to say we're operating normally + EXIORDAN = 0xE4, // Flag to read an analogue input + EXIOWRD = 0xE5, // Flag for digital write + EXIORDD = 0xE6, // Flag to read digital input }; }; From 25b325034514f2b8939005899169e7773b716d4c Mon Sep 17 00:00:00 2001 From: peteGSX Date: Tue, 20 Dec 2022 07:08:42 +1000 Subject: [PATCH 18/28] Digital read working --- IO_EXIOExpander.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 3641dfd..692e309 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -145,8 +145,8 @@ private: _digitalOutBuffer[0] = EXIORDD; _digitalOutBuffer[1] = pin; _digitalOutBuffer[2] = 0x00; // Don't need to use this for reading - int _value = I2CManager.read(_i2cAddress, _digitalInBuffer, 1, _digitalOutBuffer, 3, &_i2crb); - return _value; + I2CManager.read(_i2cAddress, _digitalInBuffer, 1, _digitalOutBuffer, 3, &_i2crb); + return _digitalInBuffer[0]; } void _write(VPIN vpin, int value) override { From 2ad08029a4763e595db59ecef041094ec7e1aebc Mon Sep 17 00:00:00 2001 From: peteGSX Date: Tue, 20 Dec 2022 08:05:05 +1000 Subject: [PATCH 19/28] Remove excess DIAG output --- IO_EXIOExpander.h | 1 - 1 file changed, 1 deletion(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 692e309..591680d 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -127,7 +127,6 @@ private: bool pullup = params[0]; int pin = vpin - _firstVpin; uint8_t mask = 1 << ((pin-_firstVpin) % 8); - DIAG(F("Configure vpin|pin %d|%d as input, pullup %d"), vpin, pin, pullup); _digitalOutBuffer[0] = EXIODPUP; _digitalOutBuffer[1] = pin; _digitalOutBuffer[2] = pullup; From 5170147e3e3c5e395177f8a4208d93583ab24a5e Mon Sep 17 00:00:00 2001 From: peteGSX Date: Tue, 20 Dec 2022 19:41:32 +1000 Subject: [PATCH 20/28] Error checking pin config, code tidy --- IO_EXIOExpander.h | 46 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 591680d..067caf8 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -73,9 +73,6 @@ private: _i2cAddress = i2cAddress; _numDigitalPins = numDigitalPins; _numAnaloguePins = numAnaloguePins; - // _digitalOutBuffer = (byte *)calloc(_numDigitalPins + 1, 1); - // _digitalInBuffer = (byte *)calloc(_numDigitalPins, 1); - _analogueValues = (uint16_t *)calloc(_numAnaloguePins, 1); _currentAPin = _nPins - _numAnaloguePins; int _dPinArrayLen = (_numDigitalPins + 7) / 8; addDevice(this); @@ -87,6 +84,15 @@ private: if (I2CManager.exists(_i2cAddress)) { _activity = EXIOINIT; // First thing to do is configure EX-IOExpander device DIAG(F("EX-IOExpander x%x using driver version %S"), _i2cAddress, EXIO_VERSION); + _digitalOutBuffer[0] = EXIOINIT; + _digitalOutBuffer[1] = _numDigitalPins; + _digitalOutBuffer[2] = _numAnaloguePins; + I2CManager.read(_i2cAddress, _digitalInBuffer, 1, _digitalOutBuffer, 3, &_i2crb); + if (_digitalInBuffer[0] != EXIORDY) { + DIAG(F("ERROR configuring EX-IOExpander device, I2C:x%x"), _i2cAddress); + _deviceState = DEVSTATE_FAILED; + return; + } #ifdef DIAG_IO _display(); #endif @@ -96,31 +102,6 @@ private: } } - void _loop(unsigned long currentMicros) override { - if (_i2crb.status == I2C_STATUS_PENDING) return; // Do nothing if I2C isn't ready yet - if (_i2crb.status == I2C_STATUS_OK) { - switch(_activity) { - case EXIOINIT: - // Send digital and analogue pin counts to configure EX-IOExpander - _setupBuffer[0] = EXIOINIT; - _setupBuffer[1] = _numDigitalPins; - _setupBuffer[2] = _numAnaloguePins; - I2CManager.write(_i2cAddress, _setupBuffer, 3, &_i2crb); - _activity = EXIORDY; - break; - case EXIORDY: - _analogueOutBuffer[0] = EXIORDAN; - _analogueOutBuffer[1] = _currentAPin - _numDigitalPins; - I2CManager.read(_i2cAddress, _analogueInBuffer, 2, _analogueOutBuffer, 2, &_i2crb); - _analogueValues[_currentAPin] = (_analogueInBuffer[1] << 8) + _analogueInBuffer[0]; - if (++_currentAPin >= _numDigitalPins + _numAnaloguePins) _currentAPin = _nPins - _numAnaloguePins; - default: - break; - } - } - // delayUntil(currentMicros + 2000000); // Delay 2 seconds while bug fixing/developing - } - bool _configure(VPIN vpin, ConfigTypeEnum configType, int paramCount, int params[]) override { if (configType != CONFIGURE_INPUT) return false; if (paramCount != 1) return false; @@ -136,7 +117,10 @@ private: int _readAnalogue(VPIN vpin) override { int pin = vpin - _firstVpin; - return _analogueValues[pin]; + _analogueOutBuffer[0] = EXIORDAN; + _analogueOutBuffer[1] = _currentAPin - _numDigitalPins; + I2CManager.read(_i2cAddress, _analogueInBuffer, 2, _analogueOutBuffer, 2, &_i2crb); + return (_analogueInBuffer[1] << 8) + _analogueInBuffer[0]; } int _read(VPIN vpin) override { @@ -166,14 +150,10 @@ private: uint8_t _numAnaloguePins; int _digitalPinBytes; int _analoguePinBytes; - uint8_t _setupBuffer[3]; - // byte * _digitalOutBuffer = NULL; - // byte * _digitalInBuffer = NULL; byte _analogueInBuffer[2]; byte _analogueOutBuffer[2]; byte _digitalOutBuffer[3]; byte _digitalInBuffer[1]; - uint16_t * _analogueValues = NULL; uint8_t _currentAPin; // Current analogue pin to read uint8_t _activity; I2CRB _i2crb; From 1c7103c21ea3916ae75e4efbdca73d04d760ac77 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Wed, 21 Dec 2022 08:37:23 +1000 Subject: [PATCH 21/28] Analogue read bugfix --- IO_EXIOExpander.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 067caf8..fc5bc4b 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -73,7 +73,6 @@ private: _i2cAddress = i2cAddress; _numDigitalPins = numDigitalPins; _numAnaloguePins = numAnaloguePins; - _currentAPin = _nPins - _numAnaloguePins; int _dPinArrayLen = (_numDigitalPins + 7) / 8; addDevice(this); } @@ -83,7 +82,6 @@ private: uint8_t _check = I2CManager.checkAddress(_i2cAddress); if (I2CManager.exists(_i2cAddress)) { _activity = EXIOINIT; // First thing to do is configure EX-IOExpander device - DIAG(F("EX-IOExpander x%x using driver version %S"), _i2cAddress, EXIO_VERSION); _digitalOutBuffer[0] = EXIOINIT; _digitalOutBuffer[1] = _numDigitalPins; _digitalOutBuffer[2] = _numAnaloguePins; @@ -118,7 +116,7 @@ private: int _readAnalogue(VPIN vpin) override { int pin = vpin - _firstVpin; _analogueOutBuffer[0] = EXIORDAN; - _analogueOutBuffer[1] = _currentAPin - _numDigitalPins; + _analogueOutBuffer[1] = pin; I2CManager.read(_i2cAddress, _analogueInBuffer, 2, _analogueOutBuffer, 2, &_i2crb); return (_analogueInBuffer[1] << 8) + _analogueInBuffer[0]; } @@ -143,6 +141,10 @@ private: void _display() override { DIAG(F("EX-IOExpander I2C:x%x Configured on Vpins:%d-%d %S"), _i2cAddress, _firstVpin, _firstVpin+_nPins-1, _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F("")); + DIAG(F("EX-IOExpander x%x using driver version %S"), _i2cAddress, EXIO_VERSION); + DIAG(F("EX-IOExpander x%x: Digital Vpins %d-%d, Analogue Vpins %d-%d"), + _i2cAddress, _firstVpin, _firstVpin + _numDigitalPins - 1, _firstVpin + _numDigitalPins, + _firstVpin + _nPins - 1); } uint8_t _i2cAddress; @@ -154,7 +156,6 @@ private: byte _analogueOutBuffer[2]; byte _digitalOutBuffer[3]; byte _digitalInBuffer[1]; - uint8_t _currentAPin; // Current analogue pin to read uint8_t _activity; I2CRB _i2crb; From c44fb0ac44a5ffa90db7b3a45bce29afdd9fe21b Mon Sep 17 00:00:00 2001 From: peteGSX Date: Thu, 22 Dec 2022 07:22:04 +1000 Subject: [PATCH 22/28] Disable device driver version, add myHal example --- IO_EXIOExpander.h | 3 +-- IO_EXIOExpander_version.h | 10 ---------- myEX-IOExpander.example.h | 22 ---------------------- myHal.cpp_example.txt | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 34 deletions(-) delete mode 100644 IO_EXIOExpander_version.h delete mode 100644 myEX-IOExpander.example.h diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index fc5bc4b..6eb3492 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -48,7 +48,6 @@ #include "DIAG.h" #include "FSH.h" #include "EX-IOExpanderPins.h" -#include "IO_EXIOExpander_version.h" // Include user defined pin maps in myEX-IOExpander if defined #if __has_include ("myEX-IOExpander.h") @@ -141,7 +140,7 @@ private: void _display() override { DIAG(F("EX-IOExpander I2C:x%x Configured on Vpins:%d-%d %S"), _i2cAddress, _firstVpin, _firstVpin+_nPins-1, _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F("")); - DIAG(F("EX-IOExpander x%x using driver version %S"), _i2cAddress, EXIO_VERSION); + // DIAG(F("EX-IOExpander x%x using driver version %S"), _i2cAddress, EXIO_VERSION); DIAG(F("EX-IOExpander x%x: Digital Vpins %d-%d, Analogue Vpins %d-%d"), _i2cAddress, _firstVpin, _firstVpin + _numDigitalPins - 1, _firstVpin + _numDigitalPins, _firstVpin + _nPins - 1); diff --git a/IO_EXIOExpander_version.h b/IO_EXIOExpander_version.h deleted file mode 100644 index 6d2e553..0000000 --- a/IO_EXIOExpander_version.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef IO_EXIOEXPANDER_VERSION_H -#define IO_EXIOEXPANDER_VERSION_H - -#include "StringFormatter.h" - - -#define EXIO_VERSION "0.0.1alpha" -// 0.0.1 Initial version for alpha testing - -#endif \ No newline at end of file diff --git a/myEX-IOExpander.example.h b/myEX-IOExpander.example.h deleted file mode 100644 index 94e378e..0000000 --- a/myEX-IOExpander.example.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * © 2022 Peter Cole. All rights reserved. - * - * This is the example configuration file for a custom EX-IOExpander pin map file. - * - * It is highly recommended to copy this to "myEX-IOExpander.h" and modify to suit your specific - * requirements. - * - * If you are simply using a default definition for a defined microcontroller, then you don't - * need to use this file, and instead can use one of the existing definitions. - * - * Refer to https://dcc-ex.com for the full documentation. - * - * NOTE: Modifications to this file will be overwritten by future software updates. - */ -#ifndef MYEX_IOEXPANDER_H -#define MYEX_IOEXPANDER_H - -#define MY_NANO_DIGITAL_PINMAP 2,3,4,5,6,7,8,9,10,11,12,13 -#define MY_NANO_ANALOGUE_PINMAP A0,A1,A2,A3 - -#endif \ No newline at end of file diff --git a/myHal.cpp_example.txt b/myHal.cpp_example.txt index 32aa12e..3febc82 100644 --- a/myHal.cpp_example.txt +++ b/myHal.cpp_example.txt @@ -20,6 +20,8 @@ #include "IO_HCSR04.h" // Ultrasonic range sensor #include "IO_VL53L0X.h" // Laser time-of-flight sensor #include "IO_DFPlayer.h" // MP3 sound player +//#include "IO_EXTurntable.h" // Turntable-EX turntable controller +// #include "IO_EXIOExpander.h" // EX-IOExpander device driver //========================================================================== @@ -160,6 +162,39 @@ void halSetup() { // DFPlayer::create(10000, 10, Serial1); + //======================================================================= + // The following directive defines an EX-Turntable turntable instance. + //======================================================================= + // EXTurntable::create(VPIN, Number of VPINs, I2C Address) + // + // The parameters are: + // VPIN=600 + // Number of VPINs=1 (Note there is no reason to change this) + // I2C address=0x60 + // + // Note that the I2C address is defined in the EX-Turntable code, and 0x60 is the default. + + //EXTurntable::create(600, 1, 0x60); + + + //======================================================================= + // The following directive defines an EX-IOExpander instance. + //======================================================================= + // EXIOExpander::create(VPIN, Number of VPINs, I2C Address, Digital pin count, Analogue pin count) + // + // The parameters are: + // VPIN=an available Vpin + // Number of VPINs=Digital pin count + Analogue pin count (must match device in use as per documentation) + // I2C address=an available I2C address (default 0x65) + // + // Note that the I2C address is defined in the EX-IOExpander code, and 0x65 is the default. + // The first example is for an Arduino Nano with the default pin allocations. + // The second example is for an Arduino Uno using all pins as digital only. + + //EXIOExpander::create(800, 18, 0x65, EXIO_NANO_DIGITAL_PINS, EXIO_NANO_ANALOGUE_PINS); + //EXIOExpander::create(820, 16, 0x66, 16, 0); + + } #endif From 70845b49322b80bc532ee265c77a9cbbc18c9ea6 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Mon, 26 Dec 2022 06:44:15 +1000 Subject: [PATCH 23/28] Receive/display EXIO version --- IO_EXIOExpander.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 6eb3492..69c568d 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -84,12 +84,20 @@ private: _digitalOutBuffer[0] = EXIOINIT; _digitalOutBuffer[1] = _numDigitalPins; _digitalOutBuffer[2] = _numAnaloguePins; + // Send config, if EXIORDY returned, we're good, otherwise go offline I2CManager.read(_i2cAddress, _digitalInBuffer, 1, _digitalOutBuffer, 3, &_i2crb); if (_digitalInBuffer[0] != EXIORDY) { DIAG(F("ERROR configuring EX-IOExpander device, I2C:x%x"), _i2cAddress); _deviceState = DEVSTATE_FAILED; return; } + // Attempt to get version, if we don't get it, we don't care, don't go offline + // Using digital buffers in reverse to save RAM + _digitalInBuffer[0] = EXIOVER; + I2CManager.read(_i2cAddress, _digitalOutBuffer, 3, _digitalInBuffer, 1, &_i2crb); + _majorVer = _digitalOutBuffer[0]; + _minorVer = _digitalOutBuffer[1]; + _patchVer = _digitalOutBuffer[2]; #ifdef DIAG_IO _display(); #endif @@ -138,12 +146,10 @@ private: } void _display() override { - DIAG(F("EX-IOExpander I2C:x%x Configured on Vpins:%d-%d %S"), _i2cAddress, _firstVpin, _firstVpin+_nPins-1, - _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F("")); - // DIAG(F("EX-IOExpander x%x using driver version %S"), _i2cAddress, EXIO_VERSION); - DIAG(F("EX-IOExpander x%x: Digital Vpins %d-%d, Analogue Vpins %d-%d"), - _i2cAddress, _firstVpin, _firstVpin + _numDigitalPins - 1, _firstVpin + _numDigitalPins, - _firstVpin + _nPins - 1); + DIAG(F("EX-IOExpander I2C:x%x v%d.%d.%d: Digital Vpins %d-%d, Analogue Vpins %d-%d %S"), + _i2cAddress, _majorVer, _minorVer, _patchVer, _firstVpin, _firstVpin + _numDigitalPins - 1, + _firstVpin + _numDigitalPins, _firstVpin + _nPins - 1, + _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F("")); } uint8_t _i2cAddress; @@ -155,6 +161,9 @@ private: byte _analogueOutBuffer[2]; byte _digitalOutBuffer[3]; byte _digitalInBuffer[1]; + uint8_t _majorVer = 0; + uint8_t _minorVer = 0; + uint8_t _patchVer = 0; uint8_t _activity; I2CRB _i2crb; @@ -162,7 +171,7 @@ private: EXIOINIT = 0xE0, // Flag to initialise setup procedure EXIORDY = 0xE1, // Flag we have completed setup procedure, also for EX-IO to ACK setup EXIODPUP = 0xE2, // Flag we're sending digital pin pullup configuration - EXIOOP = 0xE3, // Flag to say we're operating normally + EXIOVER = 0xE3, // Flag to get version EXIORDAN = 0xE4, // Flag to read an analogue input EXIOWRD = 0xE5, // Flag for digital write EXIORDD = 0xE6, // Flag to read digital input From 71ce913712fff2877ca0756e0edc2c8feabc05b6 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Mon, 26 Dec 2022 07:36:12 +1000 Subject: [PATCH 24/28] Version bugfix --- IO_EXIOExpander.h | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 69c568d..cc3160c 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -92,12 +92,12 @@ private: return; } // Attempt to get version, if we don't get it, we don't care, don't go offline - // Using digital buffers in reverse to save RAM + // Using digital in buffer in reverse to save RAM _digitalInBuffer[0] = EXIOVER; - I2CManager.read(_i2cAddress, _digitalOutBuffer, 3, _digitalInBuffer, 1, &_i2crb); - _majorVer = _digitalOutBuffer[0]; - _minorVer = _digitalOutBuffer[1]; - _patchVer = _digitalOutBuffer[2]; + I2CManager.read(_i2cAddress, _versionBuffer, 3, _digitalInBuffer, 1, &_i2crb); + _majorVer = _versionBuffer[0]; + _minorVer = _versionBuffer[1]; + _patchVer = _versionBuffer[2]; #ifdef DIAG_IO _display(); #endif @@ -146,9 +146,18 @@ private: } void _display() override { - DIAG(F("EX-IOExpander I2C:x%x v%d.%d.%d: Digital Vpins %d-%d, Analogue Vpins %d-%d %S"), - _i2cAddress, _majorVer, _minorVer, _patchVer, _firstVpin, _firstVpin + _numDigitalPins - 1, - _firstVpin + _numDigitalPins, _firstVpin + _nPins - 1, + int _firstAnalogue, _lastAnalogue; + if (_numAnaloguePins == 0) { + _firstAnalogue = 0; + _lastAnalogue = 0; + } else { + _firstAnalogue = _firstVpin + _numDigitalPins; + _lastAnalogue = _firstVpin + _nPins - 1; + } + DIAG(F("EX-IOExpander I2C:x%x v%d.%d.%d: %d Digital Vpins %d-%d, %d Analogue Vpins %d-%d %S"), + _i2cAddress, _majorVer, _minorVer, _patchVer, + _numDigitalPins, _firstVpin, _firstVpin + _numDigitalPins - 1, + _numAnaloguePins, _firstAnalogue, _lastAnalogue, _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F("")); } @@ -161,6 +170,7 @@ private: byte _analogueOutBuffer[2]; byte _digitalOutBuffer[3]; byte _digitalInBuffer[1]; + uint8_t _versionBuffer[3]; uint8_t _majorVer = 0; uint8_t _minorVer = 0; uint8_t _patchVer = 0; From eea13969979ce7f1c8a8613c1fb0118bb283b04c Mon Sep 17 00:00:00 2001 From: peteGSX Date: Tue, 27 Dec 2022 10:10:44 +1000 Subject: [PATCH 25/28] Remove EX-IO pin macros --- EX-IOExpanderPins.h | 34 ---------------------------------- IO_EXIOExpander.h | 1 - 2 files changed, 35 deletions(-) delete mode 100644 EX-IOExpanderPins.h diff --git a/EX-IOExpanderPins.h b/EX-IOExpanderPins.h deleted file mode 100644 index cbb726f..0000000 --- a/EX-IOExpanderPins.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * © 2022 Peter Cole - * - * This file is part of EX-CommandStation - * - * 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 . - */ - -/* -* This file defines default pin numbers for the various architectures supported -* by default by EX-IOExpander. -* -* Any modifications to this file will be overwritten by future software updates. -*/ - -#define EXIO_UNO_DIGITAL_PINS 12 -#define EXIO_UNO_ANALOGUE_PINS 4 - -#define EXIO_NANO_DIGITAL_PINS 12 -#define EXIO_NANO_ANALOGUE_PINS 6 - -#define EXIO_MEGA_DIGITAL_PINS 46 -#define EXIO_MEGA_ANALOGUE_PINS 16 diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index cc3160c..58c6a1d 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -47,7 +47,6 @@ #include "I2CManager.h" #include "DIAG.h" #include "FSH.h" -#include "EX-IOExpanderPins.h" // Include user defined pin maps in myEX-IOExpander if defined #if __has_include ("myEX-IOExpander.h") From 8f32ae712f1f2342aa06f0f0e820b9a425fff7e6 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Tue, 27 Dec 2022 10:13:08 +1000 Subject: [PATCH 26/28] Fix myHal example --- myHal.cpp_example.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/myHal.cpp_example.txt b/myHal.cpp_example.txt index 3febc82..c56a03d 100644 --- a/myHal.cpp_example.txt +++ b/myHal.cpp_example.txt @@ -191,7 +191,7 @@ void halSetup() { // The first example is for an Arduino Nano with the default pin allocations. // The second example is for an Arduino Uno using all pins as digital only. - //EXIOExpander::create(800, 18, 0x65, EXIO_NANO_DIGITAL_PINS, EXIO_NANO_ANALOGUE_PINS); + //EXIOExpander::create(800, 18, 0x65, 12, 8); //EXIOExpander::create(820, 16, 0x66, 16, 0); From ffdf023de67d121005d291c1a144ae08c5324500 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Thu, 29 Dec 2022 05:10:37 +1000 Subject: [PATCH 27/28] Clean up --- IO_EXIOExpander.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 58c6a1d..ff6db8e 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -18,21 +18,23 @@ */ /* -* The IO_EX-IOExpander.h device driver integrates with one or more EX-IOExpander devices. -* This device driver will configure the device and all I/O ports on startup, along with +* The IO_EXIOExpander.h device driver integrates with one or more EX-IOExpander devices. +* This device driver will configure the device on startup, along with * interacting with the device for all input/output duties. * * To create EX-IOExpander devices, these are defined in myHal.cpp: * -* #include "IO_EX-IOExpander.h" +* #include "IO_EXIOExpander.h" * * void halSetup() { * // EXIOExpander::create(vpin, num_vpins, i2c_address, digitalPinCount, analoguePinCount); -* EXIOExpander::create(800, 18, 0x65, EXIO_NANO_DIGITAL_PINS, EXIO_NANO_ANALOGUE_PINS); +* EXIOExpander::create(800, 18, 0x65, 12, 8); * } * * Note when defining the number of digital and analogue pins, there is no way to sanity check * this from the device driver, and it is up to the user to define the correct values here. +* +* All pins available on the EX-IOExpander device must be accounted for. * * Vpins are allocated to digital pins first, and then analogue pins, so digital pins will * populate the first part of the specified vpin range, with the analogue pins populating the @@ -48,11 +50,6 @@ #include "DIAG.h" #include "FSH.h" -// Include user defined pin maps in myEX-IOExpander if defined -#if __has_include ("myEX-IOExpander.h") - #include "myEX-IOExpander.h" -#endif - ///////////////////////////////////////////////////////////////////////////////////////////////////// /* * IODevice subclass for EX-IOExpander. @@ -79,7 +76,6 @@ private: // Initialise EX-IOExander device uint8_t _check = I2CManager.checkAddress(_i2cAddress); if (I2CManager.exists(_i2cAddress)) { - _activity = EXIOINIT; // First thing to do is configure EX-IOExpander device _digitalOutBuffer[0] = EXIOINIT; _digitalOutBuffer[1] = _numDigitalPins; _digitalOutBuffer[2] = _numAnaloguePins; @@ -173,7 +169,6 @@ private: uint8_t _majorVer = 0; uint8_t _minorVer = 0; uint8_t _patchVer = 0; - uint8_t _activity; I2CRB _i2crb; enum { From 322cb3db54e88071a7230b2a6f3eda566eca3298 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Thu, 29 Dec 2022 08:44:08 +1000 Subject: [PATCH 28/28] Include driver in IODevice.h --- IODevice.h | 1 + IO_EXIOExpander.h | 4 +--- myHal.cpp_example.txt | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/IODevice.h b/IODevice.h index ce47267..942fb64 100644 --- a/IODevice.h +++ b/IODevice.h @@ -408,5 +408,6 @@ private: #include "IO_MCP23008.h" #include "IO_MCP23017.h" #include "IO_PCF8574.h" +#include "IO_EXIOExpander.h" #endif // iodevice_h diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index ff6db8e..151a319 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -23,8 +23,7 @@ * interacting with the device for all input/output duties. * * To create EX-IOExpander devices, these are defined in myHal.cpp: -* -* #include "IO_EXIOExpander.h" +* (Note the device driver is included by default) * * void halSetup() { * // EXIOExpander::create(vpin, num_vpins, i2c_address, digitalPinCount, analoguePinCount); @@ -45,7 +44,6 @@ #ifndef IO_EX_IOEXPANDER_H #define IO_EX_IOEXPANDER_H -#include "IODevice.h" #include "I2CManager.h" #include "DIAG.h" #include "FSH.h" diff --git a/myHal.cpp_example.txt b/myHal.cpp_example.txt index c56a03d..c95aaed 100644 --- a/myHal.cpp_example.txt +++ b/myHal.cpp_example.txt @@ -21,7 +21,6 @@ #include "IO_VL53L0X.h" // Laser time-of-flight sensor #include "IO_DFPlayer.h" // MP3 sound player //#include "IO_EXTurntable.h" // Turntable-EX turntable controller -// #include "IO_EXIOExpander.h" // EX-IOExpander device driver //==========================================================================