From 4186fdcdd4826949d028d79d5b14aa45cf10338b Mon Sep 17 00:00:00 2001 From: Rob French Date: Fri, 5 Feb 2021 22:59:31 -0600 Subject: [PATCH] Scary commit. I've taken baby steps toward passing rig status between the Raduino and the TeensyDSP using I2C. Compiles, but has not been tested. Need to create a branch. --- Raduino/Raduino.ino | 6 +- Raduino/RigState.h | 1 + Raduino/ubitx.h | 10 ++++ Raduino/ubitx_lcd_nextion.ino | 9 +++ Raduino/ubitx_ui.ino | 25 ++++++++ Schematics/IO_Board/IO_Board.sch | 8 ++- Schematics/IO_Board/IO_Board.sch-bak | 2 + Schematics/IO_Board/IO_Board_Wiring.sch | 16 ++++++ TeensyDSP/RigState.h | 76 +++++++++++++++++++++++++ TeensyDSP/TeensyDSP.h | 7 +++ TeensyDSP/TeensyDSP.ino | 39 +++++++++++-- 11 files changed, 191 insertions(+), 8 deletions(-) create mode 120000 Raduino/RigState.h create mode 100644 Schematics/IO_Board/IO_Board_Wiring.sch create mode 100644 TeensyDSP/RigState.h diff --git a/Raduino/Raduino.ino b/Raduino/Raduino.ino index c78da97..e24a4ee 100644 --- a/Raduino/Raduino.ino +++ b/Raduino/Raduino.ino @@ -1,4 +1,4 @@ - //Firmware Version +//Firmware Version //+ : This symbol identifies the firmware. // It was originally called 'CEC V1.072' but it is too long to waste the LCD window. // I do not want to make this Firmware users's uBITX messy with my callsign. @@ -122,7 +122,9 @@ char vfoActive = VFO_A; int8_t meter_reading = 0; // a -1 on meter makes it invisible unsigned long vfoA=7150000L, vfoB=14200000L, sideTone=800, usbCarrier, cwmCarrier; unsigned long vfoA_eeprom, vfoB_eeprom; //for protect eeprom life -unsigned long frequency, ritRxFrequency, ritTxFrequency; //frequency is the current frequency on the dial +unsigned long frequency; +unsigned long ritRxFrequency, ritTxFrequency; //frequency is the current frequency on the dial + unsigned int cwSpeed = 100; //this is actuall the dot period in milliseconds extern int32_t calibration; diff --git a/Raduino/RigState.h b/Raduino/RigState.h new file mode 120000 index 0000000..db176f3 --- /dev/null +++ b/Raduino/RigState.h @@ -0,0 +1 @@ +../TeensyDSP/RigState.h \ No newline at end of file diff --git a/Raduino/ubitx.h b/Raduino/ubitx.h index f60146e..bfdf125 100644 --- a/Raduino/ubitx.h +++ b/Raduino/ubitx.h @@ -19,6 +19,8 @@ #include //for Linux, On Linux it is case sensitive. +#include "RigState.h" + //============================================================================== // Compile Option //============================================================================== @@ -253,6 +255,12 @@ extern byte I2C_LCD_SECOND_ADDRESS; //only using Dual LCD Mode #define I2CMETER_CALCR 0x55 //Calculated SWR Meter #define I2CMETER_UNCALCR 0x54 //Uncalculated SWR Meter +// Raduino provides updated data to TeensyDSP +#define I2CMETER_RIGINF 0x50 + +// Raduino requests any CAT updates from TeensyDSP +#define I2CMETER_REQCAT 0x51 + //============================================================================== // for public, Variable, functions //============================================================================== @@ -332,4 +340,6 @@ extern void DisplayVersionInfo(const char* fwVersionInfo); //I2C Signal Meter, Version 1.097 extern int GetI2CSmeterValue(int valueType); //ubitx_ui.ino +extern void doRaduinoToTeensy(UBitxRigState* r); + #endif //end of if header define diff --git a/Raduino/ubitx_lcd_nextion.ino b/Raduino/ubitx_lcd_nextion.ino index 62667af..dd2b989 100644 --- a/Raduino/ubitx_lcd_nextion.ino +++ b/Raduino/ubitx_lcd_nextion.ino @@ -990,9 +990,18 @@ void SWS_Process(void) char checkCount = 0; char checkCountSMeter = 0; +UBitxRigState rigState; +UBitxRigState catState; + //execute interval : 0.25sec void idle_process() { + // KC4UPR 2021-02-05 added update process for Raduino-TeensyDSP coordination + // Note, need to not have to copy this every time... + rigState.vfo[0] = vfoA; + rigState.vfo[1] = vfoB; + doRaduinoToTeensy(&rigState); + //S-Meter Display if (((displayOption1 & 0x08) == 0x08 && (sdrModeOn == 0)) && (++checkCountSMeter > SMeterLatency)) { diff --git a/Raduino/ubitx_ui.ino b/Raduino/ubitx_ui.ino index 0aa7c30..d660042 100644 --- a/Raduino/ubitx_ui.ino +++ b/Raduino/ubitx_ui.ino @@ -18,6 +18,8 @@ const PROGMEM uint8_t meters_bitmap[] = { }; */ +#include "RigState.h" + //SWR GRAPH, DrawMeter and drawingMeter Logic function by VK2ETA #ifdef OPTION_SKINNYBARS //We want skninny bars with more text @@ -296,4 +298,27 @@ int GetI2CSmeterValue(int valueType) } } +//====================================================================== +void doRaduinoToTeensy(UBitxRigState* r) { + uint8_t* ptr = (uint8_t*)r; + + Wire.beginTransmission(I2CMETER_ADDR); + Wire.write(I2CMETER_RIGINF); + Wire.write(ptr, sizeof(UBitxRigState)); + Wire.endTransmission(); + + Wire.requestFrom(I2CMETER_ADDR, sizeof(UBitxRigState)); + + UBitxRigState tmp; + + int len = 0; + ptr = (uint8_t*)&tmp; + + while (Wire.available() > 0) { + uint8_t b = Wire.read(); + if (len < sizeof(UBitxRigState)) { + ptr[len++] = b; + } + } +} diff --git a/Schematics/IO_Board/IO_Board.sch b/Schematics/IO_Board/IO_Board.sch index 1dcf221..0624ea4 100644 --- a/Schematics/IO_Board/IO_Board.sch +++ b/Schematics/IO_Board/IO_Board.sch @@ -3,7 +3,7 @@ EELAYER 30 0 EELAYER END $Descr USLetter 11000 8500 encoding utf-8 -Sheet 1 1 +Sheet 1 2 Title "uBitx V5 I/O Board" Date "" Rev "" @@ -1102,4 +1102,10 @@ Text Notes 7750 3900 0 118 ~ 0 RX Audio Output Text Notes 10200 1800 2 50 Italic 0 Unused op-amp section +$Sheet +S 9400 4500 500 400 +U 607D96BA +F0 "I/O Board Wiring" 50 +F1 "IO_Board_Wiring.sch" 50 +$EndSheet $EndSCHEMATC diff --git a/Schematics/IO_Board/IO_Board.sch-bak b/Schematics/IO_Board/IO_Board.sch-bak index c68d4d9..1dcf221 100644 --- a/Schematics/IO_Board/IO_Board.sch-bak +++ b/Schematics/IO_Board/IO_Board.sch-bak @@ -1100,4 +1100,6 @@ Text Notes 4900 1550 0 59 Italic 0 Spare 2 (pin 31)\nS-Meter (pin 28)\nSupply Voltage (pin 21)\nREV PWR (pin 20)\nFWD PWR (pin 26)\nSpare 1 (pin 27) Text Notes 7750 3900 0 118 ~ 0 RX Audio Output +Text Notes 10200 1800 2 50 Italic 0 +Unused op-amp section $EndSCHEMATC diff --git a/Schematics/IO_Board/IO_Board_Wiring.sch b/Schematics/IO_Board/IO_Board_Wiring.sch new file mode 100644 index 0000000..95554eb --- /dev/null +++ b/Schematics/IO_Board/IO_Board_Wiring.sch @@ -0,0 +1,16 @@ +EESchema Schematic File Version 4 +EELAYER 30 0 +EELAYER END +$Descr A4 11693 8268 +encoding utf-8 +Sheet 2 2 +Title "" +Date "" +Rev "" +Comp "" +Comment1 "" +Comment2 "" +Comment3 "" +Comment4 "" +$EndDescr +$EndSCHEMATC diff --git a/TeensyDSP/RigState.h b/TeensyDSP/RigState.h new file mode 100644 index 0000000..97f8487 --- /dev/null +++ b/TeensyDSP/RigState.h @@ -0,0 +1,76 @@ +#ifndef __RigState_h__ +#define __RigState_h__ + +#define UBITX_VFOA_UPDATE 0x01 +#define UBITX_VFOB_UPDATE 0x02 +#define UBITX_RIT_UPDATE 0x04 +#define UBITX_XIT_UPDATE 0x08 +#define UBITX_FLAGS_UPDATE 0x10 + +#define UBITX_VFOB_FLAG 0x01 +#define UBITX_SPLIT_FLAG 0x02 +#define UBITX_RIT_FLAG 0x04 +#define UBITX_XIT_FLAG 0x08 +#define UBITX_CW_FLAG 0x10 +#define UBITX_USB_FLAG 0x20 +#define UBITX_TX_FLAG 0x40 + +struct UBitxRigState { + uint8_t header = 0; + uint32_t vfo[2]; + uint16_t rit; + uint16_t xit; + uint8_t flags = 0; +}; + +/* +class UBitxRig { + public: + inline int freqA() const { return state.vfo[0]; } + inline int freqB() const { return state.vfo[1]; } + inline int freqRIT() const { return state.rit; } + inline int freqXIT() const { return state.xit; } + + inline char vfo() const { return (state.flags & UBITX_VFOB_FLAG) == UBITX_VFOB_FLAG; } + inline char isSplit() const { return (state.flags & UBITX_SPLIT_FLAG) == UBITX_SPLIT_FLAG; } + inline char isRIT() const { return (state.flags & UBITX_RIT_FLAG) == UBITX_RIT_FLAG; } + inline char isXIT() const { return (state.flags & UBITX_XIT_FLAG) == UBITX_XIT_FLAG; } + inline char isCW() const { return (state.flags & UBITX_CW_FLAG) == UBITX_CW_FLAG; } + inline char isLSB() const { return (state.flags & UBITX_USB_FLAG) != UBITX_USB_FLAG; } + inline char isUSB() const { return (state.flags & UBITX_USB_FLAG) == UBITX_USB_FLAG; } + + char* packDelta() { + buflen = 0; + + // first byte: what fields have changed + buf[buflen++] = uint8_t(state.dirty); + + // next (if req'd): VFO A frequency + if (state.dirty & UBITX_VFOA_UPDATE) { + packInt(state.vfo[0]; + } + + // next (if req'd): VFO B frequency + if (state.dirty & UBITX_VFOB_UPDATE) { + packInt(state.vfo[0]; + } + + + private: + inline void packByte(uint8_t b) { buf[buflen++] = uint8_t(state.dirty); + + inline void packInt(int i) { + int tmp = i; + for (int j = 0; j < 32; j+=8) { + tmp = tmp >> j; + buf[buflen++] = uint8_t(tmp & 0x000000FF); + } + } + + UBitxRigState state; + uint8_t buf[sizeof(uint8_t) + sizeof(UBitxRigState)]; + int buflen = 0; +}; +*/ + +#endif diff --git a/TeensyDSP/TeensyDSP.h b/TeensyDSP/TeensyDSP.h index 744a39d..24d8e40 100644 --- a/TeensyDSP/TeensyDSP.h +++ b/TeensyDSP/TeensyDSP.h @@ -11,6 +11,7 @@ KD8CEC, Ian Lee #include "Debug.h" #include "DSP.h" #include "Nextion.h" +#include "RigState.h" #include "Sensors.h" #include "TR.h" @@ -63,3 +64,9 @@ extern int magnitudelimit_low; //SWR #define I2CMETER_CALCR 0x55 //Calculated SWR Meter #define I2CMETER_UNCALCR 0x54 //Uncalculated SWR Meter + +// Raduino provides updated data to TeensyDSP +#define I2CMETER_RIGINF 0x50 + +// Raduino requests any CAT updates from TeensyDSP +#define I2CMETER_REQCAT 0x51 diff --git a/TeensyDSP/TeensyDSP.ino b/TeensyDSP/TeensyDSP.ino index 833c3c0..86c8dd7 100644 --- a/TeensyDSP/TeensyDSP.ino +++ b/TeensyDSP/TeensyDSP.ino @@ -47,6 +47,11 @@ bool isTX = false; /**********************************************************************/ +UBitxRigState catState; +UBitxRigState rigState; + +/**********************************************************************/ + void responseConfig() { if (responseCommand == 2) @@ -371,16 +376,30 @@ void setup() Number of bytes received--not used in this procedure. */ void i2cReceiveEvent(size_t numBytes) -{ +{ int readCommand = 0; - while (Wire1.available() > 0) // for Last command - { + while (Wire1.available() > 0) { readCommand = Wire1.read(); - // KC4UPR: Note that this looks to be only reading the last command, i.e. - // if multiple commands have been queued up, only the last will get executed. + if (readCommand == I2CMETER_RIGINF) { + size_t len = 0; + uint8_t* ptr = (uint8_t*)&rigState; + while (Wire.available() > 0) { + uint8_t b = Wire.read(); + if (len < sizeof(UBitxRigState)) { + ptr[len++] = b; + } + } + } } +// while (Wire1.available() > 0) // for Last command +// { +// readCommand = Wire1.read(); +// // KC4UPR: Note that this looks to be only reading the last command, i.e. +// // if multiple commands have been queued up, only the last will get executed. +// } + if (0x50 <= readCommand && readCommand <= 0x59) { #ifdef DEBUG @@ -434,6 +453,16 @@ void i2cRequestEvent(void) #endif break; + case I2CMETER_RIGINF: + // Receive current rig state; transmit any CAT updates, if required. + Wire1.write(catState.header); // temporary - just writing a single, null byte + break; + + case I2CMETER_REQCAT: + // Provide latest CAT updates, if any. + + break; + default: break; }