From d2fa44eec706f71cf894efb8a95698da281a2a88 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Thu, 24 Mar 2022 11:56:06 +0000 Subject: [PATCH 1/4] EXRAIL VIRTUAL_TURNOUT --- defines.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/defines.h b/defines.h index 19ebb4a..c24d6af 100644 --- a/defines.h +++ b/defines.h @@ -77,15 +77,8 @@ // This defines the speed at which the Arduino will communicate with the ESP8266 module. // Currently only devices which can communicate at 115200 are supported. // -// TODO: PMA remove! Need 9600bps for Sparkfun shield with old firmware! -#if defined(ARDUINO_ARCH_SAMD) -#define WIFI_SERIAL_LINK_SPEED 9600 -#else #define WIFI_SERIAL_LINK_SPEED 115200 -#endif -// TODO: PMA - figure out why enabling this causes the CS to crashe immediately after starting the motor driver -// on the SAMD platform - going to try to rebase to current TrackManager in case it's not my bug :-) #if __has_include ( "myAutomation.h") #if defined(BIG_RAM) || defined(DISABLE_EEPROM) #define EXRAIL_ACTIVE From 3c01bd9012003ef8f9e21b56cc8c282df18f32af Mon Sep 17 00:00:00 2001 From: Asbelos Date: Thu, 24 Mar 2022 13:56:01 +0000 Subject: [PATCH 2/4] Cleanup version.h --- version.h | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/version.h b/version.h index cb08ff3..8bfc201 100644 --- a/version.h +++ b/version.h @@ -24,29 +24,19 @@ // EXRAIL POWERON // 4.0.0 Major functional and non-functional changes. // Engine Driver "DriveAway" feature enhancement -// 'Discovered Server' multicast Dynamic Network Server (mDNS) displays available WiFi connections to a DCC++EX Command Station -// New EX-RAIL "Extended Railroad Automation Instruction Language" automation capability. -// EX-Rail Function commands for creating Automation, Route & Sequence Scripts -// EX-RAIL “ROSTER” Engines Id & Function key layout on Engine Driver or WiThrottle -// EX-RAIL DCC++EX Commands to Control EX-RAIL via JMRI Send pane and IDE Serial monitors -// New JMRI feature enhancements; -// Reads DCC++EX EEPROM & automatically uploades any Signals, DCC Turnouts, Servo Turnouts, Vpin Turnouts , & Output pane -// Turnout class revised to expand turnout capabilities, new commands added. -// Provides for multiple additional DCC++EX WiFi connections as accessory controllers or CS for a programming track when Motor Shields are added -// Supports Multiple Command Station connections and individual tracking of Send DCC++ Command panes and DCC++ Traffic Monitor panes -// New HAL added for I/O (digital and analogue inputs and outputs, servos etc) -// Automatically detects & connects to supported devices included in your config.h file -// Support for MCP23008, MCP23017 and PCF9584 I2C GPIO Extender modules. -// Support for PCA9685 PWM (servo) control modules. -// Support for analogue inputs on Arduino pins and on ADS111x I2C modules. -// Support for MP3 sound playback via DFPlayer module. -// Support for HC-SR04 Ultrasonic range sensor module. -// Support for VL53L0X Laser range sensor module (Time-Of-Flight). -// Added diagnostic command to show configured devices -// New Processor Support added -// Compiles on Nano Every and Teensy -// Native non-blocking I2C drivers for AVR and Nano architectures (fallback to blocking Wire library for other platforms). -// Can disable EEPROM code +// JMRI feature enhancement. Provides for multiple additional DCC++EX wifi +// connections as accessory controllers or CS for a programming track when +// motor shield is added +// New HAL added for I/O (digital and analogue inputs and outputs, servos etc). +// Support for MCP23008, MCP23017 and PCF9584 I2C GPIO Extender modules. +// Support for PCA9685 PWM (servo) control modules. +// Support for analogue inputs on Arduino pins and on ADS111x I2C modules. +// Support for MP3 sound playback via DFPlayer module. +// Support for HC-SR04 Ultrasonic range sensor module. +// Support for VL53L0X Laser range sensor module (Time-Of-Flight). +// Added diagnostic command to show configured devices +// Native non-blocking I2C drivers for AVR and Nano architectures (fallback +// to blocking Wire library for other platforms). // EEPROM layout change - deletes EEPROM contents on first start following upgrade. // Output class now allows ID > 255. // Configuration options to globally flip polarity of DCC Accessory states when driven from command and command. From a1a2c9ce5b3b7392e7215a01f5cba72bcb8f7bb3 Mon Sep 17 00:00:00 2001 From: Kcsmith0708 Date: Thu, 24 Mar 2022 11:34:11 -0400 Subject: [PATCH 3/4] Update version.h (#223) Rewrite & Updated the 4.0.0 Section --- version.h | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/version.h b/version.h index 8bfc201..cb08ff3 100644 --- a/version.h +++ b/version.h @@ -24,19 +24,29 @@ // EXRAIL POWERON // 4.0.0 Major functional and non-functional changes. // Engine Driver "DriveAway" feature enhancement -// JMRI feature enhancement. Provides for multiple additional DCC++EX wifi -// connections as accessory controllers or CS for a programming track when -// motor shield is added -// New HAL added for I/O (digital and analogue inputs and outputs, servos etc). -// Support for MCP23008, MCP23017 and PCF9584 I2C GPIO Extender modules. -// Support for PCA9685 PWM (servo) control modules. -// Support for analogue inputs on Arduino pins and on ADS111x I2C modules. -// Support for MP3 sound playback via DFPlayer module. -// Support for HC-SR04 Ultrasonic range sensor module. -// Support for VL53L0X Laser range sensor module (Time-Of-Flight). -// Added diagnostic command to show configured devices -// Native non-blocking I2C drivers for AVR and Nano architectures (fallback -// to blocking Wire library for other platforms). +// 'Discovered Server' multicast Dynamic Network Server (mDNS) displays available WiFi connections to a DCC++EX Command Station +// New EX-RAIL "Extended Railroad Automation Instruction Language" automation capability. +// EX-Rail Function commands for creating Automation, Route & Sequence Scripts +// EX-RAIL “ROSTER” Engines Id & Function key layout on Engine Driver or WiThrottle +// EX-RAIL DCC++EX Commands to Control EX-RAIL via JMRI Send pane and IDE Serial monitors +// New JMRI feature enhancements; +// Reads DCC++EX EEPROM & automatically uploades any Signals, DCC Turnouts, Servo Turnouts, Vpin Turnouts , & Output pane +// Turnout class revised to expand turnout capabilities, new commands added. +// Provides for multiple additional DCC++EX WiFi connections as accessory controllers or CS for a programming track when Motor Shields are added +// Supports Multiple Command Station connections and individual tracking of Send DCC++ Command panes and DCC++ Traffic Monitor panes +// New HAL added for I/O (digital and analogue inputs and outputs, servos etc) +// Automatically detects & connects to supported devices included in your config.h file +// Support for MCP23008, MCP23017 and PCF9584 I2C GPIO Extender modules. +// Support for PCA9685 PWM (servo) control modules. +// Support for analogue inputs on Arduino pins and on ADS111x I2C modules. +// Support for MP3 sound playback via DFPlayer module. +// Support for HC-SR04 Ultrasonic range sensor module. +// Support for VL53L0X Laser range sensor module (Time-Of-Flight). +// Added diagnostic command to show configured devices +// New Processor Support added +// Compiles on Nano Every and Teensy +// Native non-blocking I2C drivers for AVR and Nano architectures (fallback to blocking Wire library for other platforms). +// Can disable EEPROM code // EEPROM layout change - deletes EEPROM contents on first start following upgrade. // Output class now allows ID > 255. // Configuration options to globally flip polarity of DCC Accessory states when driven from command and command. From c2d7e7169a2bbc95db2d6d23262a77c360c6a3c5 Mon Sep 17 00:00:00 2001 From: pmantoine Date: Fri, 3 Jun 2022 17:04:32 +0800 Subject: [PATCH 4/4] Starting I2C Native Driver --- I2CManager_SAMD.h | 188 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 I2CManager_SAMD.h diff --git a/I2CManager_SAMD.h b/I2CManager_SAMD.h new file mode 100644 index 0000000..aeabd6c --- /dev/null +++ b/I2CManager_SAMD.h @@ -0,0 +1,188 @@ +/* + * © 2021, Neil McKechnie. All rights reserved. + * + * This file is part of CommandStation-EX + * + * 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 . + */ + +#ifndef I2CMANAGER_SAMD_H +#define I2CMANAGER_SAMD_H + +#include +#include "I2CManager.h" + +//#include +//#include + +#if defined(I2C_USE_INTERRUPTS) && defined(ARDUINO_SAMD_ZERO) +// PMA - IRQ handler, based on SERCOM3 being used for I2C, as per Arduino Zero & Sparkfun SAMD21 +// TODO: test +void SERCOM3_Handler() { + I2CManagerClass::handleInterrupt(); +} +#endif + +/*************************************************************************** + * Set I2C clock speed register. + ***************************************************************************/ +void I2CManagerClass::I2C_setClock(unsigned long i2cClockSpeed) { + unsigned long temp = ((F_CPU / i2cClockSpeed) - 16) / 2; + for (uint8_t preScaler = 0; preScaler<=3; preScaler++) { + if (temp <= 255) { + TWBR = temp; + TWSR = (TWSR & 0xfc) | preScaler; + return; + } else + temp /= 4; + } + // Set slowest speed ~= 500 bits/sec + TWBR = 255; + TWSR |= 0x03; +} + +/*************************************************************************** + * Initialise I2C registers. + ***************************************************************************/ +void I2CManagerClass::I2C_init() +{ + // PMA - broadly we do the following + initialise the clock + initialise the NVIC + software reset the I2C for the sercom + set master mode + do we need smart mode and quick command?? + configure interrupt handlers + enable interrupts + set default baud rate + set SDA/SCL pins as outputs and enable pullups +} + +/*************************************************************************** + * Initiate a start bit for transmission. + ***************************************************************************/ +void I2CManagerClass::I2C_sendStart() { + bytesToSend = currentRequest->writeLen; + bytesToReceive = currentRequest->readLen; + // We may have initiated a stop bit before this without waiting for it. + // Wait for stop bit to be sent before sending start. + while (TWCR & (1<writeBuffer + (txCount++)); + else + TWDR = currentRequest->writeBuffer[txCount++]; + bytesToSend--; + TWCR = (1< 0) { + currentRequest->readBuffer[rxCount++] = TWDR; + bytesToReceive--; + } + /* fallthrough */ + case TWI_MRX_ADR_ACK: // SLA+R has been sent and ACK received + if (bytesToReceive <= 1) { + TWCR = (1< 0) { + currentRequest->readBuffer[rxCount++] = TWDR; + bytesToReceive--; + } + TWCR = (1<i2cAddress << 1) | 1; // SLA+R + else + TWDR = (currentRequest->i2cAddress << 1) | 0; // SLA+W + TWCR = (1<