mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 16:16:13 +01:00
Try to add pin map classes
This commit is contained in:
parent
8cbcf5df32
commit
06945bb114
38
EX-IOExpanderPinMaps.h
Normal file
38
EX-IOExpanderPinMaps.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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)
|
|
@ -28,31 +28,65 @@
|
||||||
|
|
||||||
#include "IO_GPIOBase.h"
|
#include "IO_GPIOBase.h"
|
||||||
#include "FSH.h"
|
#include "FSH.h"
|
||||||
|
#include "EX-IOExpanderPinMaps.h"
|
||||||
|
|
||||||
#if __has_include ("myPinMap.h")
|
// Include user defined pin maps in myEX-IOExpander if defined
|
||||||
#include "myPinMap.h"
|
#if __has_include ("myEX-IOExpander.h")
|
||||||
#else
|
#include "myEX-IOExpander.h"
|
||||||
#warning myPinMap.h not found. Using defaults from myPinMap.example.h
|
|
||||||
#include "myPinMap.example.h"
|
|
||||||
#endif
|
#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.
|
* IODevice subclass for EX-IOExpander.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class EXIOExpander : public IODevice {
|
class EXIOExpander : public IODevice {
|
||||||
public:
|
public:
|
||||||
static void create(VPIN vpin, int nPins, uint8_t 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);
|
if (checkNoOverlap(vpin, nPins, i2cAddress)) new EXIOExpander(vpin, nPins, i2cAddress, digitalPinMap, analoguePinMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Constructor
|
// Constructor
|
||||||
EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress) {
|
EXIOExpander(VPIN firstVpin, int nPins, uint8_t i2cAddress, EXIODigitalPinMap digitalPinMap, EXIOAnaloguePinMap analoguePinMap) {
|
||||||
_firstVpin = firstVpin;
|
_firstVpin = firstVpin;
|
||||||
_nPins = nPins;
|
_nPins = nPins;
|
||||||
_i2cAddress = i2cAddress;
|
_i2cAddress = i2cAddress;
|
||||||
|
_digitalPinMap = digitalPinMap;
|
||||||
|
_analoguePinMap = analoguePinMap;
|
||||||
addDevice(this);
|
addDevice(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +108,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t _i2cAddress;
|
uint8_t _i2cAddress;
|
||||||
|
EXIODigitalPinMap _digitalPinMap;
|
||||||
|
EXIOAnaloguePinMap _analoguePinMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
23
myEX-IOExpander.example.h
Normal file
23
myEX-IOExpander.example.h
Normal file
|
@ -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
|
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user