Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diversity 2.4GHz (SX1280) Rx... aka Medley #1555

Merged
merged 25 commits into from Jun 6, 2022
Merged

Diversity 2.4GHz (SX1280) Rx... aka Medley #1555

merged 25 commits into from Jun 6, 2022

Conversation

JyeSmith
Copy link
Member

@JyeSmith JyeSmith commented May 1, 2022

This PR not only adds sx1280 diversity radios, but also has a LOT of other changes to the sx1280 lib I found a long the way. Hopefully Ill remember them all and describe below.

Diversity

Each radio can be called individually or together with the enum SX1280_Radio_Number_t. Multiple radios can and/or together to group SPI transactions. The idea is to make life easier if this is ever expanded to 3-4 radios.

typedef enum
{
    SX1280_Radio_1 = 1 << 0,
    SX1280_Radio_2 = 1 << 1,
    SX1280_Radio_All = 0xFF,
} SX1280_Radio_Number_t;

When a packet is received it is processes as normal. If successful then all radio irqStatus are cleared. Subsequent interrupts for the same packet will then not be processed since that radio returns a blank GetIrqStatus().

If a packets is processed and fails e.g. bad sync word or crc, then only that radios irqStatus is cleared. Subsequent interrupts for the same OTA packet will then be processed as normal as its irqStatus has not been cleared.

Below is an trace of radio #1 failing HW CRC, then radio #2 having a successful packet processed.

image

Successful packet track is done by the variable gotPacketThisInterval. Ideally instance->RXnbISR() would return true/false but I couldn't figure out how to do this. Happy for someone to make a commit here and I will test it. This has been done.

This PR supersedes #1304

Other Changes

New target category of 'ELRS' to move away from 'DIY'. These targets can of course be DIYed by users, but the majority of users will have commercial hardware and this naming will look more professional in Lua. We should consider this for all new targets going into V3.

The FLRC CRC reg was accidentally being set to 0, resulting in no HW CRC check. This has been fixed.

image

Added SX12XX_RX_SYNCWORD_ERROR to rx_status. SX1280 packets will no longer be processed if the failed status is returned in irqStatus.

SPI transactions have been reordered to minimise latency. Packet stats are only retrieved after a successfully being processed and RC data sent to the FC. ClearIrqStatus is also now done after RC data is processed and sent.

WaitOnBusy() has been changed to replace NOP with micros(). Micros() takes for ever to called and adding it after digitalRead means it may not need to be called at all. If it does need to be called then there is no need to waste time with a NOP, but instead waste time called micros(). There is a HUGE benefit here is reducing the delay and jitter in the first NSS call after an interrupt. Compare the above trace to the below. The delay between NSS going low and transaction beginning is gone.

image

Timing between the rx interrupt, and NSS going high after packet processing, is now a consistent 49us. Before there was some jitter.

image

src/html/hardware.html Outdated Show resolved Hide resolved
src/lib/SX1280Driver/SX1280_hal.cpp Outdated Show resolved Hide resolved
@pkendall64
Copy link
Collaborator

My changes are only niceties. I have tested the branch on regular hardware i.e. not tested the dual RX at all.

@JyeSmith
Copy link
Member Author

JyeSmith commented Jun 2, 2022

Added power_rxen_2 and power_txen_2 plus some logic to only send TLM on the radio with the last successful packet received.

image

@JyeSmith
Copy link
Member Author

JyeSmith commented Jun 5, 2022

@pkendall64 I have rebased after Frank was merged and added some new generic targets. Another once over might be required.

@JyeSmith
Copy link
Member Author

JyeSmith commented Jun 5, 2022

This schematic is a reference for anyone looking to build the Generic 2400 Diversity.json or Generic 2400 Diversity and VTx.json targets.

Schematic_EpressLRS Diversity VTx Receiver_2022-07-12

Busy 2 is crapping out on freq changes
- updated busy to only wait for the required radio
- fix radio.begin to use SX1280_MODE_STDBY_RC
- fix TXnb to set non unused radio to FS mode.
- FLRC CRC fixed
- BusyDelay timeout now based on measured busy periods
- dioISR added for both radios
- SX12XX_RX_SYNCWORD_ERROR checking added
The var name of currFreq is incorrect and causes confusion.  This is actually the register value.
This removes the delay seen in NSS going low and the SPI transfer beginning.
@JyeSmith JyeSmith merged commit 2a3fbd7 into master Jun 6, 2022
@JyeSmith JyeSmith deleted the dual-sx1280-rx branch June 6, 2022 23:40
bkleiner pushed a commit to bkleiner/ExpressLRS that referenced this pull request Jun 12, 2022
* sx1280 lib optimisations and minor dual radio additions

* more dual radio additions

Busy 2 is crapping out on freq changes

* fixes

- updated busy to only wait for the required radio
- fix radio.begin to use SX1280_MODE_STDBY_RC
- fix TXnb to set non unused radio to FS mode.

* remove unnecessary RXnb in HandleFHSS()

* Lots of additions.  Check the description...

- FLRC CRC fixed
- BusyDelay timeout now based on measured busy periods
- dioISR added for both radios
- SX12XX_RX_SYNCWORD_ERROR checking added

* change SX1280_Radio_Number_t to be mask based

* fix freq reg write

The var name of currFreq is incorrect and causes confusion.  This is actually the register value.

* replace NOP() with micro() in WaitOnBusy()

This removes the delay seen in NSS going low and the SPI transfer beginning.

* fix 900 targets

* add comment about removing SX1280Driver::SetMode() guard

* adds target 'ELRS 2.4 Medley'

* remove var gotPacketThisInterval

* add back the SX1280Hal::reset() delay

* fix GPIO_PIN_RST toggling

* add missing ICACHE_RAM_ATTR

* spelling

* adds setNss()

* adds power_rxen_2 and power_txen_2

* add missing defines

* fix defines and add pins after rebase

* remove diversity 8285 target

* add generic diversity and diversity+vtx targets

* clean up old target

* add missing pin config

* minor optimisation

Co-authored-by: Jye <JyeSmith@users.noreply.github.com>
@Martivip
Copy link

Hi @brandonrc any progress with Atto Duo target ?

@JyeSmith JyeSmith mentioned this pull request Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants