-
Notifications
You must be signed in to change notification settings - Fork 156
[WIP] Support Radiolink AT9/AT10 stock module and protocol #709
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
Open
goebish
wants to merge
18
commits into
DeviationTX:master
Choose a base branch
from
goebish:protocol_radiolink
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3d8e12c
Add protocol for Radiolink CC2530 module
goebish 9a0bb18
Fix typo
goebish ce3ba61
Fix lint errors
goebish 168b6cd
Fix protocol.h
goebish b949390
Fix failsafe
goebish a6d98a5
Support modular build
goebish 9103899
Rename module
goebish cae7db2
Rename module
goebish db48e38
Rename RADIOLINK_Reset()
goebish ff9d393
Add RADIOLINK_Reset() with module detection
goebish 5cc75db
Fix lint
goebish ce40c9d
Fix byte order
goebish 8edb4ae
Add RADIOLINK_CC2530 module
goebish 435c0f2
Use msleep instead of Delay
goebish 6225c1d
Remove from modular build
goebish 94d7233
Remove module name
goebish d3f79b5
Add PROTOCMD_RESET
goebish 8f377ea
Fix lint
goebish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /* | ||
| This project is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| Deviation is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with Deviation. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "common.h" | ||
| #include "interface.h" | ||
| #include "mixer.h" | ||
| #include "config/model.h" | ||
| #include "config/tx.h" | ||
| #include "telemetry.h" | ||
| #include "protospi.h" | ||
|
|
||
| #ifdef PROTO_HAS_RADIOLINK_CC2530 | ||
|
|
||
| #define PACKET_SIZE 41 | ||
| #define PACKET_INTERVAL 4000 | ||
|
|
||
| static u8 packet[PACKET_SIZE]; | ||
|
|
||
| static u16 scale_channel(s32 chanval, s32 inMin, s32 inMax, u16 destMin, u16 destMax) | ||
| { | ||
| s32 range = (s32)destMax - (s32)destMin; | ||
| s32 chanrange = inMax - inMin; | ||
|
|
||
| if (chanval < inMin) | ||
| chanval = inMin; | ||
| else if (chanval > inMax) | ||
| chanval = inMax; | ||
| return (range * (chanval - inMin)) / chanrange + destMin; | ||
| } | ||
|
|
||
| static void send_packet() | ||
| { | ||
| u8 i = 0; | ||
| u8 chan; | ||
| u16 val; | ||
| packet[i++] = 0xaa; | ||
| packet[i++] = 0xaa; | ||
| packet[i++] = 0x29; | ||
| packet[i++] = 0x01; | ||
| // channels | ||
| for (chan = 0; chan < 10; chan++) { | ||
| // is 0-4000 for 100% endpoints ? can it be extended ? | ||
| val = scale_channel(Channels[chan], CHAN_MIN_VALUE, CHAN_MAX_VALUE, 4000, 0); | ||
| packet[i++] = val >> 8; | ||
| packet[i++] = val & 0xff; | ||
| } | ||
| // failsafe | ||
| for (chan = 0; chan < 8; chan++) { | ||
| // any way to disable failsafe on a channel ? (keep last received value) | ||
| val = scale_channel(Model.limits[chan].failsafe, -100, 100, 4000, 0); | ||
| packet[i++] = val >> 8; | ||
| packet[i++] = val & 0xff; | ||
| } | ||
| // checksum | ||
| packet[40] = packet[4]; | ||
| for (i = 5; i < PACKET_SIZE-1; i++) | ||
| packet[40] += packet[i]; | ||
|
|
||
| // send packet to Radiolink CC2530 module | ||
| PROTO_CS_LO(RADIOLINK_CC2530); | ||
| for (i = 0; i < PACKET_SIZE; i++) | ||
| packet[i] = PROTOSPI_xfer(packet[i]); | ||
| PROTO_CS_HI(RADIOLINK_CC2530); | ||
|
|
||
| // todo: packet[] now contains the module's response, with telemetry data | ||
| } | ||
|
|
||
| static u16 radiolink_cb() | ||
| { | ||
| send_packet(); | ||
| return PACKET_INTERVAL; | ||
| } | ||
|
|
||
| static void RADIOLINK_Initialize() | ||
| { | ||
| PROTO_CS_HI(RADIOLINK_CC2530); | ||
| PROTOSPI_pin_clear(RADIOLINK_CC2530_RESET_PIN); | ||
| msleep(100); | ||
| PROTOSPI_pin_set(RADIOLINK_CC2530_RESET_PIN); | ||
| } | ||
|
|
||
| static void RADIOLINK_Stop() | ||
| { | ||
| PROTO_CS_HI(RADIOLINK_CC2530); | ||
| PROTOSPI_pin_clear(RADIOLINK_CC2530_RESET_PIN); | ||
| } | ||
|
|
||
| static int RADIOLINK_Reset() | ||
| { | ||
| RADIOLINK_Initialize(); | ||
| send_packet(); | ||
| RADIOLINK_Stop(); | ||
| #ifdef EMULATOR | ||
| return 1; | ||
| #endif | ||
| return (packet[0] == 0x55) && (packet[1] == 0x55); | ||
| } | ||
|
|
||
| static void initialize() | ||
| { | ||
| CLOCK_StopTimer(); | ||
| RADIOLINK_Initialize(); | ||
| CLOCK_StartTimer(1000, radiolink_cb); | ||
| } | ||
|
|
||
| uintptr_t RADIOLINK_Cmds(enum ProtoCmds cmd) | ||
| { | ||
| switch (cmd) { | ||
| case PROTOCMD_INIT: initialize(); return 0; | ||
| case PROTOCMD_RESET: | ||
| case PROTOCMD_DEINIT: | ||
| CLOCK_StopTimer(); | ||
| return (RADIOLINK_Reset() ? 1 : -1); | ||
| case PROTOCMD_CHECK_AUTOBIND: return 1; | ||
| case PROTOCMD_BIND: initialize(); return 0; | ||
| case PROTOCMD_NUMCHAN: return 10; | ||
| case PROTOCMD_DEFAULT_NUMCHAN: return 10; | ||
| case PROTOCMD_CHANNELMAP: return AETRG; | ||
| case PROTOCMD_TELEMETRYSTATE: return PROTO_TELEM_UNSUPPORTED; | ||
| default: break; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ enum Radio { | |
| CC2500, | ||
| NRF24L01, | ||
| MULTIMOD, | ||
| RADIOLINK_CC2530, | ||
| R9M, | ||
| TX_MODULE_LAST, | ||
| }; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.