Skip to content

Commit

Permalink
Merge branch 'master' into backpack-version
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/MSP/msp.h
#	lib/MSP/msptypes.h
  • Loading branch information
pkendall64 committed Feb 12, 2023
2 parents 330c7e3 + 0021275 commit 09d2dad
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 29 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
targets: ${{ steps.set-targets.outputs.targets }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- id: set-targets
run: echo "::set-output name=targets::[$(grep -r "\[env:" targets | sed 's/.*://' | sed s/.$// | egrep "UART" | tr '\n' ',' | sed 's/,$/"\n/' | sed 's/,/","/'g | sed 's/^/"/')]"
run: echo "targets=[$(grep -r "\[env:" targets | sed 's/.*://' | sed s/.$// | egrep "UART" | tr '\n' ',' | sed 's/,$/"\n/' | sed 's/,/","/'g | sed 's/^/"/')]" >> $GITHUB_OUTPUT

build:
needs: targets
Expand All @@ -21,16 +21,18 @@ jobs:
steps:

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
uses: rlespinasse/github-slug-action@v4

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.target }}
Expand All @@ -42,7 +44,7 @@ jobs:
pip install wheel
- name: Cache PlatformIO
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.platformio
key: ${{ runner.os }}-platformio
Expand All @@ -56,7 +58,7 @@ jobs:
mv .pio/build ~/artifacts/
- name: Store Artifacts
uses: actions/upload-artifact@v2-preview
uses: actions/upload-artifact@v3
with:
name: ExpressLRS-Backpack-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.run_number }}
path: ~/artifacts/**/*.bin
Expand Down
6 changes: 5 additions & 1 deletion lib/MSP/msp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#include <Arduino.h>

#define MSP_PORT_INBUF_SIZE 32
// TODO: MSP_PORT_INBUF_SIZE should be changed to
// dynamically allocate array length based on the payload size
// Hardcoding payload size to 64 bytes for now, to allow enough space
// for custom OSD text.
#define MSP_PORT_INBUF_SIZE 64

#define CHECK_PACKET_PARSING() \
if (packet->readError) {\
Expand Down
1 change: 1 addition & 0 deletions lib/MSP/msptypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define MSP_ELRS_SET_RX_WIFI_MODE 0x0E
#define MSP_ELRS_SET_RX_LOAN_MODE 0x0F
#define MSP_ELRS_GET_BACKPACK_VERSION 0x10
#define MSP_ELRS_SET_OSD 0x00B6

// CRSF encapsulated msp defines
#define ENCAPSULATED_MSP_PAYLOAD_SIZE 4
Expand Down
44 changes: 39 additions & 5 deletions src/Tx_main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include <Arduino.h>
#include <espnow.h>
#include <ESP8266WiFi.h>

#if defined(PLATFORM_ESP8266)
#include <espnow.h>
#include <ESP8266WiFi.h>
#elif defined(PLATFORM_ESP32)
#include <esp_now.h>
#include <esp_wifi.h>
#include <WiFi.h>
#endif

#include "msp.h"
#include "msptypes.h"
Expand Down Expand Up @@ -54,6 +61,13 @@ void sendMSPViaEspnow(mspPacket_t *packet);

/////////////////////////////////////

#if defined(PLATFORM_ESP32)
// This seems to need to be global, as per this page,
// otherwise we get errors about invalid peer:
// https://rntlab.com/question/espnow-peer-interface-is-invalid/
esp_now_peer_info_t peerInfo;
#endif

void RebootIntoWifi()
{
DBGLN("Rebooting into wifi update mode...");
Expand All @@ -76,7 +90,11 @@ void ProcessMSPPacketFromPeer(mspPacket_t *packet)
}

// espnow on-receive callback
#if defined(PLATFORM_ESP8266)
void OnDataRecv(uint8_t * mac_addr, uint8_t *data, uint8_t data_len)
#elif defined(PLATFORM_ESP32)
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *data, int data_len)
#endif
{
DBGLN("ESP NOW DATA:");
for(int i = 0; i < data_len; i++)
Expand Down Expand Up @@ -217,7 +235,11 @@ void SetSoftMACAddress()
WiFi.disconnect();

// Soft-set the MAC address to the passphrase UID for binding
wifi_set_macaddr(STATION_IF, broadcastAddress);
#if defined(PLATFORM_ESP8266)
wifi_set_macaddr(STATION_IF, broadcastAddress);
#elif defined(PLATFORM_ESP32)
esp_wifi_set_mac(WIFI_IF_STA, broadcastAddress);
#endif
}

#if defined(PLATFORM_ESP8266)
Expand Down Expand Up @@ -276,8 +298,20 @@ void setup()
rebootTime = millis();
}

esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
#if defined(PLATFORM_ESP8266)
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
#elif defined(PLATFORM_ESP32)
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK)
{
DBGLN("ESP-NOW failed to add peer");
return;
}
#endif

esp_now_register_recv_cb(OnDataRecv);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Vrx_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ void ProcessMSPPacket(mspPacket_t *packet)
vrxModule.SetRecordingState(state, delay);
}
break;
case MSP_ELRS_SET_OSD:
vrxModule.SetOSD(packet);
break;
default:
DBGLN("Unknown command from ESPNOW");
break;
Expand Down
1 change: 0 additions & 1 deletion src/fusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "module_base.h"
#include <Arduino.h>

#undef VRX_BOOT_DELAY
#define VRX_BOOT_DELAY 1000

#define VRX_UART_BAUD 500000 // fusion uses 500k baud between the ESP8266 and the STM32
Expand Down
2 changes: 2 additions & 0 deletions src/hdzero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ HDZero::GetChannelIndex()
if (receivedResponse)
{
packet = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte();
}

Expand Down Expand Up @@ -74,6 +75,7 @@ HDZero::GetRecordingState()
if (receivedResponse)
{
packet = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE;
}

Expand Down
1 change: 0 additions & 1 deletion src/hdzero.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "module_base.h"
#include <Arduino.h>

#undef VRX_BOOT_DELAY
#define VRX_BOOT_DELAY 7000

#define VRX_RESPONSE_TIMEOUT 500
Expand Down
6 changes: 5 additions & 1 deletion src/module_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
void
ModuleBase::Init()
{
delay(VRX_BOOT_DELAY);
}

void
Expand All @@ -16,6 +15,11 @@ ModuleBase::SetRecordingState(uint8_t recordingState, uint16_t delay)
{
}

void
ModuleBase::SetOSD(mspPacket_t *packet)
{
}

void
ModuleBase::Loop(uint32_t now)
{
Expand Down
4 changes: 2 additions & 2 deletions src/module_base.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include <Arduino.h>

#define VRX_BOOT_DELAY 0
#include "msp.h"

class ModuleBase
{
public:
void Init();
void SendIndexCmd(uint8_t index);
void SetRecordingState(uint8_t recordingState, uint16_t delay);
void SetOSD(mspPacket_t *packet);
void Loop(uint32_t now);
};
9 changes: 5 additions & 4 deletions src/rapidfire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Rapidfire::Init()
{
ModuleBase::Init();

delay(VRX_BOOT_DELAY);
EnableSPIMode(); // https://github.com/ExpressLRS/ExpressLRS/pull/1489 & https://github.com/ExpressLRS/Backpack/pull/65

pinMode(PIN_MOSI, INPUT);
Expand Down Expand Up @@ -44,7 +45,7 @@ void
Rapidfire::SendBuzzerCmd()
{
DBGLN("Beep!");

uint8_t cmd[4];
cmd[0] = RF_API_BEEP_CMD; // 'S'
cmd[1] = RF_API_DIR_GRTHAN; // '>'
Expand All @@ -59,7 +60,7 @@ Rapidfire::SendBuzzerCmd()

void
Rapidfire::SendIndexCmd(uint8_t index)
{
{
uint8_t newBand = index / 8 + 1;
uint8_t newChannel = index % 8;

Expand Down Expand Up @@ -194,7 +195,7 @@ Rapidfire::SendSPI(uint8_t* buf, uint8_t bufLen)
digitalWrite(PIN_CLK, HIGH);
delayMicroseconds(periodMicroSec / 2);

bufByte <<= 1;
bufByte <<= 1;
}
}
DBGLN("");
Expand All @@ -203,7 +204,7 @@ Rapidfire::SendSPI(uint8_t* buf, uint8_t bufLen)
digitalWrite(PIN_CLK, LOW);
digitalWrite(PIN_CS, HIGH);
delay(100);

pinMode(PIN_MOSI, INPUT);
pinMode(PIN_CLK, INPUT);
pinMode(PIN_CS, INPUT);
Expand Down
1 change: 0 additions & 1 deletion src/rapidfire.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "module_base.h"
#include <Arduino.h>

#undef VRX_BOOT_DELAY
#define VRX_BOOT_DELAY 2000

#define BIT_BANG_FREQ 1000
Expand Down
17 changes: 13 additions & 4 deletions src/skyzone_msp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SkyzoneMSP::Init()

void
SkyzoneMSP::SendIndexCmd(uint8_t index)
{
{
uint8_t retries = 3;
while (GetChannelIndex() != index && retries > 0)
{
Expand All @@ -40,6 +40,7 @@ SkyzoneMSP::GetChannelIndex()
if (receivedResponse)
{
packet = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte();
}

Expand All @@ -49,7 +50,7 @@ SkyzoneMSP::GetChannelIndex()

void
SkyzoneMSP::SetChannelIndex(uint8_t index)
{
{
MSP msp;
mspPacket_t packet;
packet.reset();
Expand All @@ -75,6 +76,7 @@ SkyzoneMSP::GetRecordingState()
if (receivedResponse)
{
packet = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE;
}

Expand All @@ -86,7 +88,7 @@ void
SkyzoneMSP::SetRecordingState(uint8_t recordingState, uint16_t delay)
{
DBGLN("SetRecordingState = %d delay = %d", recordingState, delay);

m_recordingState = recordingState;
m_delay = delay * 1000; // delay is in seconds, convert to milliseconds
m_delayStartMillis = millis();
Expand All @@ -101,7 +103,7 @@ void
SkyzoneMSP::SendRecordingState()
{
DBGLN("SendRecordingState = %d delay = %d", m_recordingState, m_delay);

MSP msp;
mspPacket_t packet;
packet.reset();
Expand All @@ -114,6 +116,13 @@ SkyzoneMSP::SendRecordingState()
msp.sendPacket(&packet, m_port);
}

void
SkyzoneMSP::SetOSD(mspPacket_t *packet)
{
MSP msp;
msp.sendPacket(packet, m_port);
}

void
SkyzoneMSP::Loop(uint32_t now)
{
Expand Down
2 changes: 1 addition & 1 deletion src/skyzone_msp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "module_base.h"
#include <Arduino.h>

#undef VRX_BOOT_DELAY
#define VRX_BOOT_DELAY 2000

#define VRX_RESPONSE_TIMEOUT 500
Expand All @@ -26,6 +25,7 @@ class SkyzoneMSP : public ModuleBase
void SetChannelIndex(uint8_t index);
uint8_t GetRecordingState();
void SetRecordingState(uint8_t recordingState, uint16_t delay);
void SetOSD(mspPacket_t *packet);
void Loop(uint32_t now);

private:
Expand Down
12 changes: 12 additions & 0 deletions targets/debug.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ build_flags =

[env:DEBUG_TX_Backpack_via_WIFI]
extends = env:DEBUG_TX_Backpack_via_UART

[env:DEBUG_ESP32_TX_Backpack_via_UART]
extends = env_common_esp32, tx_backpack_common
build_flags =
${env_common_esp32.build_flags}
${tx_backpack_common.build_flags}
-D PIN_BUTTON=0
-D PIN_LED=4
lib_ignore = STM32UPDATE

[env:DEBUG_ESP32_TX_Backpack_via_WIFI]
extends = env:DEBUG_ESP32_TX_Backpack_via_UART

0 comments on commit 09d2dad

Please sign in to comment.