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
Add TBS SmartAudio support #1283
Conversation
Required for SmartAudio Support with single wire connection and without external pull-up. Tested with F3 only. F1 and F4 has untested mods, and Softserial haven’t been touched.
#include "drivers/vtx_smartaudio.h" | ||
#include "io/serial.h" | ||
#include "fc/runtime_config.h" | ||
#include "config/config_master.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drivers should not call upwards, so should not include any of:
io/serial.h
fc/runtime_config.h
config/config_master.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I can live without fc/runtime_config.h and config/config_master.h.
io/serial.h is included for
- To find out a port assigned to the smartaudio.
- To open a uart port for printf() debugging.
2 will eventually go away, but where should I put 1? main.c?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing that calls smartAudioInit
should open the port and pass it in as a parameter to the smartAudioInit
function. So yes, main.c
. [We might elect to change that in future, but for the moment that is the correct place.]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
Thanks for the suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm beginning to think about moving this to io since it never touches raw I/O directly, or separating it into a driver that handles up to transport layer (framing + retransmission) and a module in io that handles the vtx control protocol. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right - none of this code should be in the driver, I should have spotted that.
So I'd move all code into the IO layer. However the comments about reducing interdependencies still apply - I would still make the changes suggested above.
|
||
void smartAudioProcess(uint32_t now) | ||
{ | ||
bool armedState = ARMING_FLAG(ARMED) ? true : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Driver should not have knowledge of arming. Instead just don't call this function if armed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
void taskVtxControl(uint32_t currentTime) | ||
{ | ||
#ifdef VTX_SMARTAUDIO | ||
smartAudioProcess(currentTime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only call this function if armed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
I've had a bit of time to look at the code overall. Not much time, so this is only a fairly cursory review, but I have the following comments:
|
Also can you put a link to the SMARTAUDIO spec in this PR. |
I believe we need a state machine based receive framer to handle variable length frame from unreliable input channel.
This needs some explanation.
I understand.
Yeap. They will eventually be all gone. |
@jflyper , you explanations make sense. Can you add some comments in the code to explain this? Otherwise, at some future date, someone might decide to "optimise" the code and remove the queue and state machine. |
Finishing #1352 first, so the smartaudio can be controlled through osd menu. |
@jflyper , see my comments on the CMS code. |
@@ -0,0 +1 @@ | |||
extern CMS_Menu cmsx_menuVtxSmartAudio; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have missed this one. Shouldn't this be in cms
directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the smartaudio, corresponding CMS contents reside in io/vtx_smartaudio.c.
I first thought it would be nice to keep them together with objects and functions the are related with. However, I'm not so sure now, thinking about the possible consolidation of vtx related APIs, associated codes, operational model and of course, UIs. There is also a couple of new FC controllable vtx that we are expecting to join this game. So, my plan is to keep it as is for 3.1, and restructure it as a part of the vtx system reorganization later (3.2 or 3.3).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense.
So, we have a problem in how to enable smartaudio support for all boards that potentially need it. I was going to enable I am facing a similar problem with I2C configuration, in which common.h defines
Other targets will retain Any thoughts? EDIT |
I tried to run this branch on the brainfpv fork: I am able to get the menus on the OSD, and I see it tries to send packets at different baud rates, but it never receives a reply from the Unify (race edition, should be smartaudio v2.0) I have the smartaudio pin wired to uart1, and the serial mask is set up correctly (to 2048), and the configurator built with the related pull request for this feature sees it correctly as peripherals/smartaudio. The spec also says the unify baud rate could vary to +/- 5%, which for the nominal 4800, could mean anything between ~4500 to ~5100, and so I tried to increase the 'scanned' range min/max to those numbers, but still no response (the OSD does show it attempting the larger range). Is there anything I could be missing? |
@stellarhopper SERIAL_BIDIR turns on half-duplex, and IOCFG_AF_OD. It looks like SmartAudio doesn't like this, so I added SERIAL_BIDIR_PP option to set push-pull on half-duplex.
|
@stellarhopper awesome. I'm in the process of updating it. Just push your changes to github and I will cherry pick your commit :). Edit: found the branch on your repo, will take the changes from there :) |
@jflyper Great work!I want to know how to connect TBS SmartAudio to my F4 FC ? |
I tried it, it works great ! I have an OmibusF3 with TBS HV 5G8 Race Edition. |
@jflyper So I ran into what could possibly be a smartaudio related bug. somehow I got into a mode where the unify would only power on in pitmode, and I'd have to take it out of pit mode manually on every boot, either by holding the button, or through the VTX menu if I was using PIR. I was able to get it back out of this mode (always boot in pitmode) by holding the button while powering on, and then cycling through the 'menu' and finally saving (all on the vtx/button). But I certainly didn't enable this mode myself by powering up while holding the button. So is there any way certain smartaudio commands could've been sent to put the vtx into this mode? (I haven't looked at the smartaudio spec to see if such a setting is even exposed..). |
@stellarhopper In terms of CMS for SmartAudio, yes, you can enable/disable the PIT mode: It would be grateful if you do some experiments regarding the interaction of buttons and the RACE/FREESTYLE selection. |
@jflyper yes, I've been doing experiments to try and trigger this again.. Is that correct? It might be easier to understand the terminology if the OPMODE selection was instead I'm not sure how generic the menus are, but if they are Unify specific, then it might be worth making this change. |
Yes. You are correct. I first named it PIT and FREE, but thought "PIT mode" is just a state or momentary mode, and whole operational scheme should called differently, thus the "RACE" operational model.
I didn't know the CLEANSWITCH stuff. Any pointers?
I'm some what trying to make the concept of "operational model" generic :) |
For cleanswitch, grep for it in: http://www.team-blacksheep.com/tbs-unify-pro-5g8-manual.pdf I did just confirm that RACE == cleanswitch on, and FREE == cleanswitch off. Unfortunately this doesn't seem to be documented in the manual at all, and I only know because TBS support guided me on how to do this.. I think the biggest point of confusion is probably caused by the 'RACE' wording, because that is also a model of the Unify, and people are assuming that is what it stands for, and enabling it :) |
In the least, I think there should be some safeguard against turning on both RACE and POR together.. (that is how I first hit the issue and feared that the unify had gotten fried or something, as it was transmitting nothing on any of the usual channels). Because this will always make it come up at the out of band freq at low power on every boot, and really I don't see a use case for this.. Someone made another suggestion, that the RACE/FREE selection could be made in a different 'screen' or submenu on the OSD, which will then have some space to describe both modes in some detail so users aren't completely caught off guard. |
@stellarhopper I see your points. For 3.1, I think I'm going to add an explanation of the status line to the wiki page for the smartaudio. For the cleanswitch, I think it is a by-product of the pit mode... |
This is the rebased version of #1275 (onto development branch).
It now works with the new OSD code on OMNIBUS (F3) target.
UART is now configurable with cli serial command; use mask value 1024.
Works with the new OSD code; full band/chan control, limited power control (25 & 200mW).
EDIT
Discussion (issue) thread is at #1029