diff --git a/speeduino/board_avr2560.cpp b/speeduino/board_avr2560.cpp index f00471b0..3341782f 100644 --- a/speeduino/board_avr2560.cpp +++ b/speeduino/board_avr2560.cpp @@ -1,6 +1,7 @@ #include "globals.h" #if defined(CORE_AVR) #include "auxiliaries.h" +#include "comms_secondary.h" // Prescaler values for timers 1-3-4-5. Refer to www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg #define TIMER_PRESCALER_OFF ((0< Can0; @@ -20,6 +21,7 @@ void initBoard() *********************************************************************************************************** * General */ + pSecondarySerial = &Serial2; /* *********************************************************************************************************** diff --git a/speeduino/board_teensy35.h b/speeduino/board_teensy35.h index cca2b5c2..095d0e37 100644 --- a/speeduino/board_teensy35.h +++ b/speeduino/board_teensy35.h @@ -155,7 +155,10 @@ *********************************************************************************************************** * CAN / Second serial */ - #define USE_SERIAL3 // Secondary serial port to use + #define USE_SERIAL3 // Secondary serial port to use + #define secondarySerial_AVAILABLE + #define SECONDARY_SERIAL_T HardwareSerial + #include #if defined(__MK64FX512__) // use for Teensy 3.5 only extern FlexCAN_T4 Can0; diff --git a/speeduino/board_teensy41.cpp b/speeduino/board_teensy41.cpp index 270a2bcc..6a76e1d6 100644 --- a/speeduino/board_teensy41.cpp +++ b/speeduino/board_teensy41.cpp @@ -5,6 +5,7 @@ #include "idle.h" #include "scheduler.h" #include "timers.h" +#include "comms_secondary.h" FlexCAN_T4 Can0; FlexCAN_T4 Can1; @@ -22,6 +23,7 @@ void initBoard() *********************************************************************************************************** * General */ + pSecondarySerial = &Serial2; /* Idle + Boost + VVT use the PIT timer. THIS IS ALSO USED BY THE INTERVAL TIMER THAT CALLS THE 1MS LOW RES TIMER! diff --git a/speeduino/board_teensy41.h b/speeduino/board_teensy41.h index c7a4a537..93eb25e1 100644 --- a/speeduino/board_teensy41.h +++ b/speeduino/board_teensy41.h @@ -168,6 +168,9 @@ * CAN / Second serial */ #define USE_SERIAL3 + #define secondarySerial_AVAILABLE + #define SECONDARY_SERIAL_T HardwareSerial + #include extern FlexCAN_T4 Can0; extern FlexCAN_T4 Can1; diff --git a/speeduino/comms_secondary.cpp b/speeduino/comms_secondary.cpp index 981af561..fefc92d9 100644 --- a/speeduino/comms_secondary.cpp +++ b/speeduino/comms_secondary.cpp @@ -24,23 +24,10 @@ sendcancommand is called when a command is to be sent either to serial3 #include "comms_legacy.h" #include "logger.h" #include "page_crc.h" +#include BOARD_H uint8_t currentSecondaryCommand; - -#if ( defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ) - HardwareSerial &secondarySerial = Serial3; -#elif defined(CORE_STM32) - #ifndef HAVE_HWSERIAL2 //Hack to get the code to compile on BlackPills - #define Serial2 Serial1 - #endif - #if defined(STM32GENERIC) // STM32GENERIC core - SerialUART &secondarySerial = Serial2; - #else //libmaple core aka STM32DUINO - HardwareSerial &secondarySerial = Serial2; - #endif -#elif defined(CORE_TEENSY) - HardwareSerial &secondarySerial = Serial2; -#endif +SECONDARY_SERIAL_T* pSecondarySerial; void secondserial_Command(void) { diff --git a/speeduino/comms_secondary.h b/speeduino/comms_secondary.h index 2cb07a79..dc654ee5 100644 --- a/speeduino/comms_secondary.h +++ b/speeduino/comms_secondary.h @@ -10,23 +10,8 @@ #define SECONDARY_SERIAL_PROTO_MSDROID 3 #define SECONDARY_SERIAL_PROTO_REALDASH 4 -#if ( defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ) - #define secondarySerial_AVAILABLE - extern HardwareSerial &secondarySerial; -#elif defined(CORE_STM32) - #define secondarySerial_AVAILABLE - #ifndef HAVE_HWSERIAL2 //Hack to get the code to compile on BlackPills - #define Serial2 Serial1 - #endif - #if defined(STM32GENERIC) // STM32GENERIC core - extern SerialUART &secondarySerial; - #else //libmaple core aka STM32DUINO - extern HardwareSerial &secondarySerial; - #endif -#elif defined(CORE_TEENSY) - #define secondarySerial_AVAILABLE - extern HardwareSerial &secondarySerial; -#endif +extern SECONDARY_SERIAL_T *pSecondarySerial; +#define secondarySerial (*pSecondarySerial) void secondserial_Command(void);//This is the heart of the Command Line Interpreter. All that needed to be done was to make it human readable. void sendCancommand(uint8_t cmdtype , uint16_t canadddress, uint8_t candata1, uint8_t candata2, uint16_t sourcecanAddress); diff --git a/speeduino/init.cpp b/speeduino/init.cpp index add92449..ee99f881 100644 --- a/speeduino/init.cpp +++ b/speeduino/init.cpp @@ -117,10 +117,7 @@ void initialiseAll(void) #endif Serial.begin(115200); - BIT_SET(currentStatus.status4, BIT_STATUS4_ALLOW_LEGACY_COMMS); //Flag legacy comms as being allowed on startip - #if defined(secondarySerial_AVAILABLE) - if (configPage9.enable_secondarySerial == 1) { secondarySerial.begin(115200); } - #endif + BIT_SET(currentStatus.status4, BIT_STATUS4_ALLOW_LEGACY_COMMS); //Flag legacy comms as being allowed on startup //Repoint the 2D table structs to the config pages that were just loaded taeTable.valueSize = SIZE_BYTE; //Set this table to use byte values @@ -320,6 +317,11 @@ void initialiseAll(void) Can0.setTX(DEF); #endif + //Must come after setPinMapping() as secondary serial can be changed on a per board basis + #if defined(secondarySerial_AVAILABLE) + if (configPage9.enable_secondarySerial == 1) { secondarySerial.begin(115200); } + #endif + //End all coil charges to ensure no stray sparks on startup endCoil1Charge(); endCoil2Charge(); @@ -2333,9 +2335,21 @@ void setPinMapping(byte boardID) pinInjector3 = 12; //MISO pinInjector4 = 10; //CS for MC33810 1 pinInjector5 = 9; //CS for MC33810 2 + pinInjector6 = 9; //CS for MC33810 3 + //Dummy pins, without thes pin 0 (Serial1 RX) gets overwritten + pinCoil1 = 40; + pinCoil2 = 41; + /* + pinCoil3 = 55; + pinCoil4 = 55; + pinCoil5 = 55; + pinCoil6 = 55; + */ + pinTrigger = 19; //The CAS pin pinTrigger2 = 18; //The Cam Sensor pin + pinTrigger3 = 22; //Uses one of the protected spare digitial inputs. This must be set or Serial1 (Pin 0) gets broken pinFlex = A16; // Flex sensor pinMAP = A1; //MAP sensor pin pinBaro = A0; //Baro sensor pin @@ -2369,6 +2383,8 @@ void setPinMapping(byte boardID) pinCLT = A20; //CLS sensor pin pinO2 = A21; //O2 Sensor pin pinO2_2 = A18; //Spare 2 + + pSecondarySerial = &Serial1; //Header that is broken out on Dropbear boards is attached to Serial1 #endif #if defined(CORE_TEENSY41) diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index 0f41428d..4a39dffb 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -111,7 +111,7 @@ void loop(void) //if can or secondary serial interface is enabled then check for requests. if (configPage9.enable_secondarySerial == 1) //secondary serial interface enabled { - if ( ((mainLoopCount & 31) == 1) or (secondarySerial.available() > SERIAL_BUFFER_THRESHOLD) ) + if ( ((mainLoopCount & 31) == 1) || (secondarySerial.available() > SERIAL_BUFFER_THRESHOLD) ) { if (secondarySerial.available() > 0) { secondserial_Command(); } }