From 39485dd95405d0a0cb682a4fcc8fe0cc4ede5cfc Mon Sep 17 00:00:00 2001 From: Peppe21 <14368925+Peppe21@users.noreply.github.com> Date: Tue, 3 Jan 2023 20:53:08 +0100 Subject: [PATCH] New config 0_9_X_WT901 : IMU Connected on the MPU9250 Slot using SerialPIO --- Firmware/LowLevel/lib/JY901_SERIAL/JY901.cpp | 4 ++++ Firmware/LowLevel/lib/JY901_SERIAL/JY901.h | 10 +++++++++- Firmware/LowLevel/platformio.ini | 9 +++++++++ Firmware/LowLevel/src/imu/WT901_SERIAL/imu.cpp | 7 +++++++ Firmware/LowLevel/src/pins.h | 14 ++++++++------ 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Firmware/LowLevel/lib/JY901_SERIAL/JY901.cpp b/Firmware/LowLevel/lib/JY901_SERIAL/JY901.cpp index 4c70945d..3175e9fe 100644 --- a/Firmware/LowLevel/lib/JY901_SERIAL/JY901.cpp +++ b/Firmware/LowLevel/lib/JY901_SERIAL/JY901.cpp @@ -1,7 +1,11 @@ #include "JY901.h" #include "string.h" +#ifdef WT901_INSTEAD_OF_SOUND CJY901 ::CJY901(HardwareSerial *serial) +#elif WT901 +CJY901 ::CJY901(SerialPIO *serial) +#endif { this->serial = serial; } diff --git a/Firmware/LowLevel/lib/JY901_SERIAL/JY901.h b/Firmware/LowLevel/lib/JY901_SERIAL/JY901.h index 5a036d68..094c0e55 100644 --- a/Firmware/LowLevel/lib/JY901_SERIAL/JY901.h +++ b/Firmware/LowLevel/lib/JY901_SERIAL/JY901.h @@ -141,7 +141,11 @@ class CJY901 struct SLonLat stcLonLat; struct SGPSV stcGPSV; - CJY901 (HardwareSerial *serial); + #ifdef WT901_INSTEAD_OF_SOUND + CJY901 (HardwareSerial *serial); + #elif WT901 + CJY901 (SerialPIO *serial); + #endif void begin(int baudrate = 9600); // Call as often as possible to fetch data from serial @@ -150,7 +154,11 @@ class CJY901 private: + #ifdef WT901_INSTEAD_OF_SOUND HardwareSerial *serial; + #elif WT901 + SerialPIO *serial; + #endif unsigned char ucRxBuffer[250]; unsigned char ucRxCnt = 0; diff --git a/Firmware/LowLevel/platformio.ini b/Firmware/LowLevel/platformio.ini index d8efac24..0eaa13cd 100644 --- a/Firmware/LowLevel/platformio.ini +++ b/Firmware/LowLevel/platformio.ini @@ -77,3 +77,12 @@ lib_deps = ${env.lib_deps} JY901_SERIAL build_flags = ${env.build_flags} -DWT901_INSTEAD_OF_SOUND -DHW_0_9_X + +[env:0_9_X_WT901] +lib_ignore = JY901_I2C +build_src_filter = ${env.build_src_filter} + + +lib_deps = ${env.lib_deps} + JY901_SERIAL + powerbroker2/DFPlayerMini_Fast@^1.2.4 +build_flags = + ${env.build_flags} -DWT901 -DHW_0_9_X -DENABLE_SOUND_MODULE \ No newline at end of file diff --git a/Firmware/LowLevel/src/imu/WT901_SERIAL/imu.cpp b/Firmware/LowLevel/src/imu/WT901_SERIAL/imu.cpp index 33e88773..7127e081 100644 --- a/Firmware/LowLevel/src/imu/WT901_SERIAL/imu.cpp +++ b/Firmware/LowLevel/src/imu/WT901_SERIAL/imu.cpp @@ -2,12 +2,19 @@ #include "pins.h" #include +#ifdef WT901_INSTEAD_OF_SOUND CJY901 IMU(&Serial2); +#elif WT901 +SerialPIO imuSerial(PIN_WT901_TX, PIN_WT901_RX, 250); // set hardware pin +CJY901 IMU(&imuSerial); +#endif bool init_imu() { + #ifdef WT901_INSTEAD_OF_SOUND Serial2.setRX(PIN_WT901_RX); // set hardware pin Serial2.setTX(PIN_WT901_TX); + #endif IMU.begin(); diff --git a/Firmware/LowLevel/src/pins.h b/Firmware/LowLevel/src/pins.h index 3db7b638..e7f717c9 100644 --- a/Firmware/LowLevel/src/pins.h +++ b/Firmware/LowLevel/src/pins.h @@ -32,13 +32,15 @@ #define PIN_SOUND_RX 9 #endif -//This is used as a hack to use WT901 on older mainboards. #ifdef WT901_INSTEAD_OF_SOUND -#ifdef ENABLE_SOUND_MODULE -#error you can not enable sound and have wt901 on sound port at the same time. -#endif -#define PIN_WT901_TX 8 -#define PIN_WT901_RX 9 + #ifdef ENABLE_SOUND_MODULE + #error you can not enable sound and have wt901 on sound port at the same time. + #endif + #define PIN_WT901_TX 8 + #define PIN_WT901_RX 9 +#elif WT901 //This is to use WT901 on MPU9250 Slot via Serial. + #define PIN_WT901_TX 17 + #define PIN_WT901_RX 16 #endif #elif HW_0_10_X