diff --git a/I2CManager.cpp b/I2CManager.cpp index 6d5db41..aad6418 100644 --- a/I2CManager.cpp +++ b/I2CManager.cpp @@ -72,18 +72,23 @@ static const FSH * guessI2CDeviceType(uint8_t address) { void I2CManagerClass::begin(void) { if (!_beginCompleted) { _beginCompleted = true; + + // Check for short-circuit or floating lines (no pull-up) on I2C before enabling I2C + const FSH *message = F("WARNING: Possible short-circuit or inadequate pullup on I2C %S line"); + pinMode(SDA, INPUT); + if (!digitalRead(SDA)) + DIAG(message, F("SDA")); + pinMode(SCL, INPUT); + if (!digitalRead(SCL)) + DIAG(message, F("SCL")); + + // Now initialise I2C _initialise(); #if defined(I2C_USE_WIRE) DIAG(F("I2CManager: Using Wire library")); #endif - // Check for short-circuits on I2C - if (!digitalRead(SDA)) - DIAG(F("WARNING: Possible short-circuit on I2C SDA line")); - if (!digitalRead(SCL)) - DIAG(F("WARNING: Possible short-circuit on I2C SCL line")); - // Probe and list devices. Use standard mode // (clock speed 100kHz) for best device compatibility. _setClock(100000); diff --git a/IO_HALDisplay.h b/IO_HALDisplay.h index 5ef9efc..f2ca3af 100644 --- a/IO_HALDisplay.h +++ b/IO_HALDisplay.h @@ -82,10 +82,10 @@ private: public: // Static function to handle "HALDisplay::create(...)" calls. static void create(I2CAddress i2cAddress, int width, int height) { - /* if (checkNoOverlap(i2cAddress)) */ new HALDisplay(0, i2cAddress, width, height); + if (checkNoOverlap(0, 0, i2cAddress)) new HALDisplay(0, i2cAddress, width, height); } static void create(uint8_t displayNo, I2CAddress i2cAddress, int width, int height) { - /* if (checkNoOverlap(i2cAddress)) */ new HALDisplay(displayNo, i2cAddress, width, height); + if (checkNoOverlap(0, 0, i2cAddress)) new HALDisplay(displayNo, i2cAddress, width, height); } protected: diff --git a/config.example.h b/config.example.h index b253ab3..2a8a11a 100644 --- a/config.example.h +++ b/config.example.h @@ -125,10 +125,10 @@ The configuration file for DCC-EX Command Station // define LCD_DRIVER for I2C address 0x27, 16 cols, 2 rows // #define LCD_DRIVER 0x27,16,2 -//OR define OLED_DRIVER width,height in pixels (address auto detected) +//OR define OLED_DRIVER width,height[,address] in pixels (address auto detected if not supplied) // 128x32 or 128x64 I2C SSD1306-based devices are supported. // Use 132,64 for a SH1106-based I2C device with a 128x64 display. -// #define OLED_DRIVER 128,32 +// #define OLED_DRIVER 128,32,0x3c // Define scroll mode as 0, 1 or 2 // * #define SCROLLMODE 0 is scroll continuous (fill screen if poss), diff --git a/myHal.cpp_example.txt b/myHal.cpp_example.txt index b9e68b7..d93ea5c 100644 --- a/myHal.cpp_example.txt +++ b/myHal.cpp_example.txt @@ -17,9 +17,11 @@ // Include devices you need. #include "IODevice.h" -#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_HALDisplay.h" // Auxiliary display devices (LCD/OLED) +//#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_TouchKeypad.h // Touch keypad with 16 keys //#include "IO_EXTurntable.h" // Turntable-EX turntable controller //#include "IO_EXFastClock.h" // FastClock driver @@ -31,6 +33,61 @@ void halSetup() { + //======================================================================= + // The following directives define auxiliary display devices. + // These can be defined in addition to the system display (display + // number 0) that is defined in config.h. + // A write to a line which is beyond the length of the screen will overwrite + // the bottom line, unless the line number is 255 in which case the + // screen contents will scroll up before the text is written to the + // bottom line. + //======================================================================= + // + // Create a 128x32 OLED display device as display number 1 + // (line 0 is written by EX-RAIL 'SCREEN(1, 0, "text")'). + + //HALDisplay::create(1, 0x3d, 128, 32); + + // Create a 20x4 LCD display device as display number 2 + // (line 0 is written by EX-RAIL 'SCREEN(2, 0, "text")'). + + // HALDisplay(2, 0x27, 20, 4); + + + //======================================================================= + // User Add-ins + //======================================================================= + // User add-ins can be created when you want to do something that + // can't be done in EX-RAIL but does not merit a HAL driver. The + // user add-in is a C++ function that is executed periodically by the + // HAL subsystem. + + // Example: The function will be executed once per second and will display, + // on screen #3, the first eight entries (assuming an 8-line display) + // from the loco speed table. + + // Put the following block of code in myHal.cpp OUTSIDE of the + // halSetup() function: + // + // void updateLocoScreen() { + // for (int i=0; i<8; i++) { + // if (DCC::speedTable[i].loco > 0) { + // int speed = DCC::speedTable[i].speedCode; + // char direction = (speed & 0x80) ? 'R' : 'F'; + // speed = speed & 0x7f; + // if (speed > 0) speed = speed - 1; + // SCREEN(3, i, F("Loco:%4d %3d %c"), DCC::speedTable[i].loco, + // speed, direction); + // } + // } + // } + // + // Put the following line INSIDE the halSetup() function: + // + // UserAddin::create(updateLocoScreen, 1000); + // + + //======================================================================= // The following directive defines a PCA9685 PWM Servo driver module. //======================================================================= @@ -176,6 +233,21 @@ void halSetup() { // DFPlayer::create(10000, 10, Serial1); + //======================================================================= + // 16-pad capacitative touch key pad based on TP229 IC. + //======================================================================= + // Parameters below: + // 11000 = first VPIN allocated + // 16 = number of VPINs allocated + // 25 = local GPIO pin number for clock signal + // 24 = local GPIO pin number for data signal + // + // Pressing the key pads numbered 1-16 cause each of the nominated digital VPINs + // (11000-11015 in this case) to be activated. + + // TouchKeypad::create(11000, 16, 25, 24); + + //======================================================================= // The following directive defines an EX-Turntable turntable instance. //=======================================================================