FrSkyA: FrSky ACCESS on the CC2500 (#1214)

* FrSky X: S.Port frames to the receiver stored at payload[i-start-2]

FrSkyX_seq_sport() (SPORT_SEND) stored the outgoing bytes at
payload[i-start+2], i.e. payload[4] to payload[11] for the 8 bytes of
an LBT packet: up to 4 bytes past each frame's 8-byte payload (into the
next frame's count and payload, past the array for frame 3). The
retransmits sent payload[i] and payload[i-start+2], bytes from beyond
the frame. All three now use payload[i-start-2] (0 to 7).

* FrSkyA: FrSky ACCESS on the CC2500

New protocol 112, subtypes 16ch, 8ch (FCC) and EU16ch, EU8ch (only the
region flag differs: ACCESS uses the same channels, hops and timing in
both). Reversed from the ISRM and RX6R firmwares and captures of an X9
Lite with an RX6R; same CC2500 PHY as Mike's UNI ACCESS.

- register (channel 0) and bind (channel 239) in the same bind
- 16 or 8 channels every 7 ms, D16 channel packing, extended limits
- failsafe: one channel per frame in its slot, as the ISRM
- telemetry: RSSI / RxBatt and the S.Port stream as D16, S.Port packets
  from the radio sent to the receiver (SportQueue(), split out of the
  serial input for FrSkyX/X2/R9)
- receiver settings and hardware info (PXX2 messages 5 and 6) between
  the receiver and a Lua script, MULTI telemetry type 18 ("Pipe") and
  serial frames of 2 to 7 extra bytes
- not on the atmega328p nor in the 64KB CC2500 release (size)

Tested with an RX6R (ACCESS 2.1.8) and an Archer Plus SR10+ (1.0.10,
3.0.3): bind, channels, failsafe (S.Bus output), telemetry, receiver
settings and the SR10+ stabilizer settings over S.Port.

Needs FrSkyX_seq_sport() fixed (#1203): its resends overflowed and
froze the hopping at the first S.Port packet.

* Lua: FrSky ACCESS RX, receiver options for FrSkyA

The receiver options page of an ACCESS module for a receiver bound
with FrSkyA: name and versions, fast PWM, telemetry and 25mW,
S.Port/F.Port/F.Port2, S.Bus 24, PWM on CH5/CH6, the channel or port
mode of each output. Rows follow the capabilities the receiver
reports. Uses the Multi Lua pipe (multiBuffer "Pipe").

* FrSkyA Lua: receiver IDs 81 to 85

Names for the newer ACCESS receivers (SR6BL15A, SR6Lite, R6Lite,
RS-Lite, R2SIM), so an R6Lite shows by name instead of "ID 83".

---------

Co-authored-by: Raphael Coeffic <1050031+raphaelcoeffic@users.noreply.github.com>
Co-authored-by: pascallanger <pascal_langer@yahoo.fr>
This commit is contained in:
authored and GitHub committed 2026-11-21 16:07:16 +01:00
1 parent 2a13543cdc
commit fc6814b705
13 files changed
+1153 -52

No files matched your search

+424
View File
@@ -0,0 +1,424 @@
local toolName = "TNS|FrSky ACCESS RX|TNE"
-- Receiver options of a FrSky ACCESS receiver bound to the MULTI FrSkyA
-- protocol, as the EdgeTX receiver options page of an ACCESS module.
--
-- EdgeTX/Multi bridge (multiBuffer "Pipe"):
-- Multi_Buffer[4] 1..7: message piece ready to send
-- Multi_Buffer[5..11] type, offset << 4 | length, up to 5 bytes
-- Multi_Buffer[14] length of the message from the module, 0 = none
-- Multi_Buffer[15..] type, length, data
-- Messages as EdgeTX's PXX2 ones. Type 5 = receiver settings:
-- flag0 receiver slot, 0x40 = write
-- flag1 0x80 telemetry off, 0x40 read only, 0x20 S.Bus 24, 0x10 fast PWM,
-- 0x08 F.Port, 0x04 telemetry 25 mW, 0x02 PWM on CH5/CH6, 0x01 F.Port2
-- then one byte per output: the channel (0 = CH1), or on receivers with a
-- configurable telemetry port (SR10+, R10+, SR12+, R12+) 0x40 S.Port,
-- 0x80 S.Bus out, 0xC0 F.Bus, 0xA0 S.Bus in (output 1 only); with PWM on
-- CH5/CH6 (capability 0x04), outputs 5 / 6 = last channel + 1: S.Port / S.Bus
-- out (as EdgeTX)
-- Type 6 = hardware info: request = receiver index; answer = index, model ID,
-- hw version (2 bytes), sw version (2 bytes), variant, capabilities
-- (0x01 F.Port, 0x02 telemetry 25 mW, 0x04 PWM on CH5/CH6, 0x08 F.Port2,
-- 0x10 racing mode, 0x20 S.Bus 24)
local PROTO_FRSKYA = 112
local TX_READY = 4
local TX_PAYLOAD = 5
local TX_MAX_PAYLOAD = 7
local RX_READY = 14
local RX_PAYLOAD = 15
local RX_MAX_PAYLOAD = 32
local TYPE_RX_SETTINGS = 5
local TYPE_HW_INFO = 6
local SLOT = 0
local RETRY = 200 -- 2 s, in 10 ms ticks
local WRITE_WAIT = 250 -- the receiver restarts after a write
local colorLcd = type(lcd.RGB) == "function"
local settings = nil -- { flag1 = n, outputs = { ch, ... } }
local hwInfo = nil -- { name = "RX6R 2.1.8", id = n, caps = n }
local channels = 16 -- the module's channel count
local lines = {}
local sel = 1
local top = 1
local edit = false
local blink = 0
local moduleOk = false
local queue = {}
local state = "idle" -- idle, info, reading, writing
local status = ""
local deadline = 0
local tries = 0
local function limit(v, mn, mx)
if v < mn then return mn end
if v > mx then return mx end
return v
end
local function bit(v, b)
return math.floor(v / b) % 2
end
local function setBit(v, b, on)
if bit(v, b) == 1 then v = v - b end
if on then v = v + b end
return v
end
local function screenLines()
if colorLcd then return limit(math.floor(((LCD_H or 272) - 46) / 20), 8, 12) end
return 6
end
local function drawTitle(title)
if colorLcd and lcd.drawFilledRectangle then
lcd.drawFilledRectangle(0, 0, LCD_W, 30, COLOR_THEME_SECONDARY1)
lcd.drawText(3, 5, title, COLOR_THEME_PRIMARY2)
elseif lcd.drawScreenTitle then
lcd.drawScreenTitle(title, 0, 0)
else
lcd.drawText(0, 0, title, INVERS)
end
end
local function findModule()
for i = 0, 1 do
local m = model.getModule(i)
if m and m["Type"] == 6 and m["protocol"] == PROTO_FRSKYA then
channels = limit(m["channelsCount"] or 16, 1, 24)
return true
end
end
return false
end
local function initBuffer()
multiBuffer(0, string.byte("P"))
if multiBuffer(0) ~= string.byte("P") then
error("Not enough memory!")
return
end
multiBuffer(1, string.byte("i"))
multiBuffer(2, string.byte("p"))
multiBuffer(3, string.byte("e"))
multiBuffer(TX_READY, 0)
multiBuffer(RX_READY, 0)
end
local function release()
for i = 0, RX_PAYLOAD + RX_MAX_PAYLOAD - 1 do
multiBuffer(i, 0)
end
end
-- A message in pieces of up to 5 bytes: type, offset << 4 | length, data
local function queueMessage(msgType, data)
local len = #data
local pos = 0
repeat
local piece = { msgType, pos * 16 + len }
for i = pos + 1, math.min(pos + 5, len) do
piece[#piece + 1] = data[i]
end
queue[#queue + 1] = piece
pos = pos + 5
until pos >= len
end
local function sendQueue()
if #queue == 0 or multiBuffer(TX_READY) ~= 0 then return end
local piece = table.remove(queue, 1)
for i = 1, TX_MAX_PAYLOAD do
multiBuffer(TX_PAYLOAD + i - 1, piece[i] or 0)
end
multiBuffer(TX_READY, #piece)
end
-- 2.4 GHz ACCESS receiver model IDs; TD / TW (TANDEM / TWIN) and R9 (900 MHz)
-- receivers are left out
local rxNames = {
[1]="X8R", [2]="RX8R", [3]="RX8R Pro", [4]="RX6R", [5]="RX4R", [6]="G-RX8", [7]="G-RX6",
[8]="X6R", [9]="X4R", [10]="X4RSB", [11]="XSR", [12]="XSR M", [13]="RXSR", [14]="S6R",
[15]="S8R", [16]="XM", [17]="XM+", [18]="XMR", [28]="Archer X", [64]="Archer Plus SR10+",
[65]="Archer Plus R10+", [66]="Archer Plus GR8", [67]="Archer Plus R8",
[68]="Archer Plus SR8", [69]="Archer Plus GR6", [70]="Archer Plus R6",
[71]="R6M(ESC DC)", [72]="Archer Plus RS", [73]="Rs Mini", [74]="R6FB", [75]="GR6FB",
[76]="Archer Plus SR12+", [77]="Archer Plus R12+", [78]="R6 Mini E", [79]="SR6 Mini",
[80]="SR6 Mini E", [81]="SR6BL15A", [82]="SR6Lite", [83]="R6Lite", [84]="RS-Lite",
[85]="R2SIM" }
-- Version bytes: major, minor << 4 | revision; shown with major + 1 as EdgeTX
local function versionText(major, b)
if major == 0xFF then return "---" end
return (major + 1) .. "." .. math.floor(b / 16) .. "." .. (b % 16)
end
local function readInfo()
queue = {}
queueMessage(TYPE_HW_INFO, { SLOT })
state = "info"
status = "Reading..."
tries = 1
deadline = getTime() + RETRY
end
local function readSettings()
queue = {}
queueMessage(TYPE_RX_SETTINGS, { SLOT })
state = "reading"
status = "Reading..."
tries = 1
deadline = getTime() + RETRY
end
local function writeSettings()
if not settings then return end
local data = { 0x40 + SLOT, settings.flag1 }
for i = 1, #settings.outputs do
data[#data + 1] = settings.outputs[i]
end
queue = {}
queueMessage(TYPE_RX_SETTINGS, data)
state = "writing"
status = "Writing..."
edit = false
deadline = getTime() + WRITE_WAIT
end
local function pollRx()
local len = multiBuffer(RX_READY)
if not len or len == 0 then return end
local p = {}
for i = 1, math.min(len, RX_MAX_PAYLOAD) do
p[i] = multiBuffer(RX_PAYLOAD + i - 1)
end
multiBuffer(RX_READY, 0)
if len < 3 or p[2] + 2 > len then return end
if p[1] == TYPE_HW_INFO and state == "info" and p[2] >= 7 then
local caps = 0
for i = p[2] + 2, 10, -1 do caps = caps * 256 + p[i] end
hwInfo = { name = (rxNames[p[4]] or ("ID " .. p[4])) .. " " .. versionText(p[7], p[8]), id = p[4], caps = caps }
readSettings()
return
end
if p[1] ~= TYPE_RX_SETTINGS or len < 4 or state ~= "reading" then return end
settings = { flag1 = p[4], outputs = {} }
for i = 5, p[2] + 2 do
settings.outputs[#settings.outputs + 1] = p[i]
end
state = "idle"
status = bit(settings.flag1, 0x40) == 1 and "Read only" or ""
end
local function timers()
if state == "idle" or getTime() < deadline then return end
if state == "writing" then
readSettings() -- read back what the receiver kept
elseif tries < 5 then
queue = {}
queueMessage(state == "info" and TYPE_HW_INFO or TYPE_RX_SETTINGS, { SLOT })
tries = tries + 1
deadline = getTime() + RETRY
else
state = "idle"
status = "No answer"
end
end
local portModes = { "S.Port", "F.Port", "F.Port2" }
local function portMode()
if bit(settings.flag1, 0x01) == 1 then return 3 end
if bit(settings.flag1, 0x08) == 1 then return 2 end
return 1
end
-- Rows as EdgeTX's receiver options: the optional ones by capability
local function hasCap(b)
return hwInfo == nil or bit(hwInfo.caps, b) == 1
end
local function rebuildLines()
lines = { { hwInfo and hwInfo.name or "Read", "action", readInfo } }
lines[#lines + 1] = { "Fast PWM", "flag", 0x10 }
lines[#lines + 1] = { "Telemetry", "flag", 0x80, true }
if hasCap(0x02) then lines[#lines + 1] = { "Telem 25mW", "flag", 0x04 } end
if hasCap(0x01) or hasCap(0x08) then lines[#lines + 1] = { "Port", "port" } end
if hasCap(0x20) then lines[#lines + 1] = { "S.Bus 24", "flag", 0x20 } end
if hasCap(0x04) then lines[#lines + 1] = { "PWM CH5/CH6", "flag", 0x02 } end
if settings then
for i = 1, #settings.outputs do
lines[#lines + 1] = { "Output " .. i, "output", i }
end
end
lines[#lines + 1] = { "Write", "action", writeSettings }
sel = limit(sel, 1, #lines)
end
-- Output pin modes (EdgeTX pxx2.h CH_MAP_*, RECEIVER_OPTION_D_TELE_PORT)
local CH_MAP_SPORT, CH_MAP_SBUS_OUT, CH_MAP_SBUS_IN, CH_MAP_FBUS = 0x40, 0x80, 0xA0, 0xC0
local telePortIds = { [64] = true, [65] = true, [76] = true, [77] = true }
local function hasTelePort()
return hwInfo ~= nil and telePortIds[hwInfo.id] == true
end
-- The values output i can take, in order, and their names
local function outputChoices(i)
local list = {}
for ch = 0, channels - 1 do list[#list + 1] = ch end
if hasTelePort() then
list[#list + 1] = CH_MAP_SPORT
list[#list + 1] = CH_MAP_SBUS_OUT
list[#list + 1] = CH_MAP_FBUS
if i == 1 then list[#list + 1] = CH_MAP_SBUS_IN end
elseif hwInfo and bit(hwInfo.caps, 0x04) == 1 and (i == 5 or i == 6) then
list[#list + 1] = channels
end
return list
end
local function outputName(i, v)
if v < channels then return "CH" .. (v + 1) end
if hasTelePort() then
if v == CH_MAP_SPORT then return "S.Port" end
if v == CH_MAP_SBUS_OUT then return "S.Bus out" end
if v == CH_MAP_FBUS then return "F.Bus" end
if v == CH_MAP_SBUS_IN and i == 1 then return "S.Bus in" end
elseif v == channels and (i == 5 or i == 6) then
return i == 5 and "S.Port" or "S.Bus out"
end
if v < 24 then return "CH" .. (v + 1) end
return string.format("0x%02X", v)
end
local function lineValue(line)
if line[2] == "action" then return ">" end
if not settings then return "--" end
if line[2] == "flag" then
local on = bit(settings.flag1, line[3]) == 1
if line[4] then on = not on end
return on and "On" or "Off"
end
if line[2] == "port" then return portModes[portMode()] end
if line[2] == "output" then return outputName(line[3], settings.outputs[line[3]]) end
return ""
end
local function changeValue(dir)
local line = lines[sel]
if not line or not settings then return end
if line[2] == "flag" then
local on = dir > 0
if line[4] then on = not on end
settings.flag1 = setBit(settings.flag1, line[3], on)
elseif line[2] == "port" then
local modes = { 1 }
if hasCap(0x01) then modes[#modes + 1] = 2 end
if hasCap(0x08) then modes[#modes + 1] = 3 end
local pos = 1
for i = 1, #modes do
if modes[i] == portMode() then pos = i end
end
local m = modes[limit(pos + dir, 1, #modes)]
settings.flag1 = setBit(settings.flag1, 0x08, m == 2)
settings.flag1 = setBit(settings.flag1, 0x01, m == 3)
elseif line[2] == "output" then
local i = line[3]
local list = outputChoices(i)
local pos = nil
for k = 1, #list do
if list[k] == settings.outputs[i] then pos = k end
end
if pos == nil then pos = dir > 0 and 0 or #list + 1 end -- not offered here: first / last
settings.outputs[i] = list[limit(pos + dir, 1, #list)]
end
end
local function handleEvent(event)
local nextEvent = edit and EVT_VIRTUAL_INC or EVT_VIRTUAL_NEXT
local prevEvent = edit and EVT_VIRTUAL_DEC or EVT_VIRTUAL_PREV
if event == nextEvent then
if edit then changeValue(1) else sel = limit(sel + 1, 1, #lines) end
elseif event == prevEvent then
if edit then changeValue(-1) else sel = limit(sel - 1, 1, #lines) end
elseif event == EVT_VIRTUAL_ENTER then
local line = lines[sel]
if line and line[2] == "action" then
if state == "idle" then line[3]() end
elseif line and settings then
edit = not edit
end
end
local count = screenLines()
if sel < top then top = sel end
if sel >= top + count then top = sel - count + 1 end
end
local function draw()
lcd.clear()
drawTitle("FrSky ACCESS RX")
local font = colorLcd and 0 or SMLSIZE
local x = 2
local y = colorLcd and 34 or 9
local dy = colorLcd and 20 or 8
local valueX = colorLcd and 150 or 70
if not moduleOk then
lcd.drawText(x, y + dy, "Select Multi FrSkyA", font + BLINK)
return
end
if status ~= "" then
lcd.drawText(LCD_W - 2, colorLcd and 5 or 0, status, (colorLcd and COLOR_THEME_PRIMARY2 or SMLSIZE + INVERS) + RIGHT)
end
for i = top, math.min(#lines, top + screenLines() - 1) do
local attr = font
if i == sel then
attr = attr + INVERS
if edit then
blink = (blink + 1) % 30
if blink > 15 then attr = font end
end
end
local yy = y + (i - top) * dy
lcd.drawText(x, yy, lines[i][1], attr)
lcd.drawText(valueX, yy, lineValue(lines[i]), attr)
end
end
local function init()
moduleOk = type(multiBuffer) == "function" and findModule()
rebuildLines()
if moduleOk then
initBuffer()
readInfo()
end
end
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT and not edit then
if moduleOk then release() end
return 2
elseif event == EVT_VIRTUAL_EXIT then
edit = false
end
if moduleOk then
local had = settings
local hadInfo = hwInfo
pollRx()
timers()
sendQueue()
if settings ~= had or hwInfo ~= hadInfo then rebuildLines() end
handleEvent(event)
end
draw()
return 0
end
return { init = init, run = run }
+4
View File
@@ -202,6 +202,10 @@
62,1,XK,X420,1,FMode,TakeOf,Emerg,3D_6G,Pict,Video,Flip,Light
62,2,XK,Cars,0,FMode,TakeOf,Emerg,3D_6G,Pict,Video,Flip,Light
109,0,MoFly,Std,0,FMode,Rate,BFlip,LRoll,RRoll,Invert
112,0,FrSkyA,16ch,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
112,1,FrSkyA,8ch,0,CH5,CH6,CH7,CH8
112,2,FrSkyA,EU16ch,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
112,3,FrSkyA,EU8ch,0,CH5,CH6,CH7,CH8
99,0,XK2,X4,0,Rate,Mode,Hover,Light,Stunt
99,1,XK2,P10,0,Rate,Mode,Hover,Light,Stunt
8,0,YD717,Std,1,Flip,Light,Pict,Video,HLess
+6
View File
@@ -40,6 +40,12 @@ Script to set the channels function (switch, servo, pwm, ppm, sbus) on a [LOLI R
[![MultiLOLIconfig](https://img.youtube.com/vi/e698pQxfv-A/0.jpg)](https://www.youtube.com/watch?v=e698pQxfv-A)
## FrSky ACCESS RX
Receiver options of a FrSky ACCESS receiver bound with the [FrskyA protocol](https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/blob/master/Protocols_Details.md#frskya---112), as the receiver options page of an ACCESS module: receiver name and versions, fast PWM, telemetry on/off and 25mW, S.Port/F.Port/F.Port2, S.Bus 24, PWM on CH5/CH6 and the channel of each output, or its port mode (S.Port, S.Bus out/in, F.Bus) on the receivers that have it (SR10+, R10+, SR12+, R12+). The options shown depend on the capabilities the receiver reports.
Needs a radio firmware with the Multi Lua pipe (multiBuffer "Pipe"). Located on the radio SD card under \SCRIPTS\TOOLS.
## Futaba S.BUS2 sensors
Sets up the S.BUS2 sensors of a Futaba receiver bound with the [Futaba protocol](https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/blob/master/Protocols_Details.md#futaba---21) (T-FHSS sub protocols). S.BUS2 sensors don't tell their type on the bus: the radio shows each slot with data as a raw sensor "S1", "S2"... and this tool turns it into a typed sensor that the radio decodes: temperature (SBS-01T, SBS-01TE), RPM (SBS-01RM), voltage (SBS-01V, 2 slots) and current (SBS-01C, 3 slots: current, voltage, capacity). A preset sets up an ESCape32 ESC (its telemetry ID 1 to 4).
+578
View File
@@ -0,0 +1,578 @@
/*
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.
Multiprotocol 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 Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/
/*
FrSky ACCESS 2.4 GHz, from the ISRM-N 2.1.9 and RX6R 2.1.0 firmwares and
captures of an X9 Lite ISRM with an RX6R 2.1.8.
CC2500: 125 kbps 2-FSK, 69.8 kHz deviation, sync D391 sent twice (TX), the
receiver's replies on 89CB, variable length, CRC. Channel n at 2403.97 MHz
+ n x 300 kHz (CHANNR, 299.93 kHz steps as Mike's UNI ACCESS). Every 7 ms
a 33-byte frame on the next hop, the receiver's 18-byte reply 3.97 ms
after its sync word on the same channel.
Frame bytes (after the length byte, packet[n+1]):
0..2 TX id (id low, id high, third byte)
3..4 hop state: index | skip << 6 (index of the channel it is sent on)
5 RX number, bits 6..7: 0x40 16 channels, 0x00 8 channels
6 0x20 | slot: a failsafe value in that slot (channel n in frame n
of every 1024); bits 6..7 region, 1 FCC, 0 EU (ISRM 0x239; the
channels, hops and timing are the same in both, the RX6R ignores it)
7 race mode switch (0)
8..19 8 channel slots, 12 bits each, D16 packing; slot k = ch k or k+8
20..30 S.Port downlink: seq/ack, count | receiver slot << 4, 0xFE, 8 bytes
31..32 CRC (D16) of bytes 2..30, big endian
Bytes 3 .. 3+n-1 XOR key = (id * 0xD7) ^ 0x83, n = key & 7 (3 at least).
Reply: id (3 bytes), RSSI | 0x80 or RX voltage XOR (id * 0xD7) ^ 0x74,
seq/ack, count, 0xFE, up to 8 bytes of the S.Port stream (as D16) or
zeros, CRC over bytes 2..15 with byte 3 before its XOR.
Bind (one bind does both steps):
- register on channel 0: 03 01 01 00 <sub>, sub 0 until a receiver in
register mode answers with its name, then subs 1..5 with its name, our
registration ID (the module ID in hex) and UID 0
- bind on channel 239: 03 01 02 00 00 + registration ID + UID (0..7 in
turn) until a registered receiver answers with its name, then sub 1 with
the name, slot 0, TX id and RX number, subs 2..5 to confirm
Without an answer to the register frames for FRSKYA_REG_TRY frames, the
module tries bind for as long (the receiver may be registered already).
RX6R: register mode = bind button held at power-up until the LEDs
alternate; it listens for bind after every plain power-up.
*/
#if defined(FRSKYA_CC2500_INO)
#include "iface_cc2500.h"
#define FRSKYA_PERIOD 7000
#define FRSKYA_TX_US 3900 // TX start to RX on: the frame is 2.9 ms on air, the reply starts ~4.2 ms
#define FRSKYA_RX_US 2800 // RX on to reading the reply (it ends at ~6.1 ms)
#define FRSKYA_LEN 33
#define FRSKYA_REPLY_LEN 18
#define FRSKYA_REG_CH 47 // hopping_frequency[47] = 0
#define FRSKYA_BIND_CH 48 // hopping_frequency[48] = 239
#define FRSKYA_REG_TRY 300 // frames (2.1 s)
enum {
FRSKYA_REGISTER = 0,
FRSKYA_BIND,
FRSKYA_DATA,
};
static uint8_t FrSkyA_mode, FrSkyA_sub, FrSkyA_tries, FrSkyA_uid, FrSkyA_phase;
static uint16_t FrSkyA_count;
static uint8_t FrSkyA_name[8], FrSkyA_regid[8];
static uint8_t FrSkyA_chan_start;
// Subtypes: 16ch, 8ch (FCC), EU16ch, EU 8ch (EU): bit 0 = 8 channels
#define FRSKYA_8CH (sub_protocol & 1)
#define FRSKYA_REGION (sub_protocol >= A_EU16 ? 0x00 : 0x40) // byte 6 bits 6..7
#ifdef FAILSAFE_ENABLE
static bool FrSkyA_fs_valid;
static uint16_t FrSkyA_fs_count;
#endif
// Lua pipe (EdgeTX multiBuffer "Pipe", MULTI telemetry type 18), messages as
// EdgeTX's PXX2 ones: type 5 = receiver settings (flag0: slot, 0x40 write;
// flag1; one channel byte per output), type 6 = hardware info (request: the
// receiver index; answer: index, model ID, hw and sw versions, variant,
// capabilities). In: type, offset << 4 | length, up to 5 bytes per MULTI
// frame (8 bytes are S.Port). Out: type, length, data.
// On air (ISRM 0x11af0 / 0xe23c / 0x115d8): downlink stream 5 in place of
// the S.Port data, byte 21 slot << 4 | count, 22 type, 23 offset << 4 |
// length, up to 7 bytes; the receiver answers the same way, up to 8 bytes.
#define FRSKYA_MSG_MAX 15
static uint8_t FrSkyA_req[FRSKYA_MSG_MAX];
static uint8_t FrSkyA_cfg_buf[FRSKYA_MSG_MAX], FrSkyA_cfg_len, FrSkyA_cfg_pos, FrSkyA_cfg_type;
static uint8_t FrSkyA_rep[FRSKYA_MSG_MAX];
uint8_t FrSkyA_lua_out[2 + FRSKYA_MSG_MAX], FrSkyA_lua_out_len;
void FrSkyA_lua_in(const uint8_t *d, uint8_t len)
{
if(len < 2)
return;
uint8_t pos = d[1] >> 4, total = d[1] & 0x0F, n = len - 2;
if(total == 0 || pos >= total)
return;
if(pos + n > total)
n = total - pos;
memcpy(&FrSkyA_req[pos], &d[2], n);
if(pos + n < total)
return; // more to come
if(d[0] == 6)
{// Hardware info: the receiver index (ISRM 0x11660)
FrSkyA_cfg_buf[0] = FrSkyA_req[0];
FrSkyA_cfg_len = 1;
}
else if(d[0] != 5)
return;
else if(FrSkyA_req[0] & 0x40)
{// Write: flag0, flag1, outputs
memcpy(FrSkyA_cfg_buf, FrSkyA_req, total);
FrSkyA_cfg_len = total;
}
else
{// Read: flag0 and a flag1 byte, as the ISRM sends it
FrSkyA_cfg_buf[0] = FrSkyA_req[0] & 0x0F;
FrSkyA_cfg_buf[1] = 0;
FrSkyA_cfg_len = 2;
}
FrSkyA_cfg_type = d[0];
FrSkyA_cfg_pos = 0;
}
// The receiver's answer (reply frame bytes 5..15 at d): settings carry
// offset << 4 | length, hardware info only an offset (RX6R 0x11eec, one
// frame: index, model, hw and sw versions, variant, capabilities)
static void __attribute__((unused)) FrSkyA_stream_reply(const uint8_t *d)
{
uint8_t n = (d[0] & 0x0F);
if(n == 0)
return;
n--; // the count includes the header
if(n > 8) n = 8;
uint8_t pos, total;
if(d[1] == 6)
{
pos = d[2];
total = pos + n;
if(pos || total > FRSKYA_MSG_MAX)
return;
}
else
{
pos = d[2] >> 4;
total = d[2] & 0x0F;
if(total == 0 || pos >= total)
return;
}
if(pos + n > total)
n = total - pos;
memcpy(&FrSkyA_rep[pos], &d[3], n);
if(pos + n < total)
return;
FrSkyA_lua_out[0] = d[1];
FrSkyA_lua_out[1] = total;
memcpy(&FrSkyA_lua_out[2], FrSkyA_rep, total);
FrSkyA_lua_out_len = total + 2;
}
const PROGMEM uint8_t FRSKYA_cc2500_conf[]= {
/*02_IOCFG0*/ 0x06 ,
/*00_IOCFG2*/ 0x06 ,
/*17_MCSM1*/ 0x0C ,
/*18_MCSM0*/ 0x18 ,
/*06_PKTLEN*/ 0x26 ,
/*07_PKTCTRL1*/ 0x04 , // status appended, no address check
/*08_PKTCTRL0*/ 0x05 , // variable length, CRC
/*3E_PATABLE*/ 0xff ,
/*0B_FSCTRL1*/ 0x08 ,
/*0C_FSCTRL0*/ 0x00 ,
/*0D_FREQ2*/ 0x5C , // 2403.970 MHz
/*0E_FREQ1*/ 0x75 ,
/*0F_FREQ0*/ 0xDC ,
/*10_MDMCFG4*/ 0x6C , // 271 kHz, 125 kbps
/*11_MDMCFG3*/ 0x3B ,
/*12_MDMCFG2*/ 0x03 , // 2-FSK, 30/32 sync
/*13_MDMCFG1*/ 0x23 , // 4 preamble bytes
/*14_MDMCFG0*/ 0x7A , // 299.93 kHz
/*15_DEVIATN*/ 0x53 }; // 69.8 kHz
static uint16_t __attribute__((unused)) FrSkyA_id()
{
return rx_tx_addr[3] | (rx_tx_addr[2] << 8);
}
static uint8_t __attribute__((unused)) FrSkyA_key(uint8_t x)
{
return (uint8_t)(rx_tx_addr[3] * 0xD7) ^ x;
}
static void __attribute__((unused)) FrSkyA_crc()
{// Frame bytes 2..30
uint16_t lcrc = FrSkyX_crc(&packet[3], FRSKYA_LEN - 4);
packet[FRSKYA_LEN - 1] = lcrc >> 8;
packet[FRSKYA_LEN] = lcrc;
}
static void __attribute__((unused)) FrSkyA_setup_frame(uint8_t type)
{
memset(packet, 0, FRSKYA_LEN + 1);
packet[0] = FRSKYA_LEN;
packet[1] = 0x03;
packet[2] = 0x01;
packet[3] = type; // 1 register, 2 bind
packet[5] = FrSkyA_sub;
if(type == 1)
{
if(FrSkyA_sub)
{
memcpy(&packet[6], FrSkyA_name, 8);
memcpy(&packet[14], FrSkyA_regid, 8);
packet[22] = 0; // UID
}
}
else
{
if(FrSkyA_sub == 0)
{
memcpy(&packet[6], FrSkyA_regid, 8);
packet[14] = FrSkyA_uid;
FrSkyA_uid = (FrSkyA_uid + 1) & 7;
}
else
{
memcpy(&packet[6], FrSkyA_name, 8);
// packet[14..15]: receiver slot 0
packet[16] = rx_tx_addr[3];
packet[17] = rx_tx_addr[2];
packet[18] = rx_tx_addr[1];
packet[19] = RX_num & 0x3F;
packet[20] = 0x01;
if(FrSkyA_sub >= 2)
packet[6] = 0xFF;
}
}
FrSkyA_crc();
}
// Slot chan & 7: channel chan, or the failsafe value of fs_chan
static uint16_t __attribute__((unused)) FrSkyA_slot_value(uint8_t chan, uint8_t fs_slot, uint8_t fs_chan)
{
#ifdef FAILSAFE_ENABLE
if((chan & 0x07) == fs_slot)
return FrSkyX_scaleForPXX_FS(fs_chan);
#else
(void)fs_slot; (void)fs_chan;
#endif
return FrSkyX_scaleForPXX(chan);
}
static void __attribute__((unused)) FrSkyA_data_frame()
{
packet[0] = FRSKYA_LEN;
packet[1] = rx_tx_addr[3];
packet[2] = rx_tx_addr[2];
packet[3] = rx_tx_addr[1];
packet[4] = (FrSkyX_chanskip << 6) | hopping_frequency_no;
packet[5] = FrSkyX_chanskip >> 2;
packet[6] = (RX_num & 0x3F) | (FRSKYA_8CH ? 0x00 : 0x40);
packet[7] = FRSKYA_REGION; // no failsafe value in this frame
packet[8] = 0; // race mode off
//Failsafe (ISRM 0x9854): frame n of every 1024 carries channel n's value in
//slot n & 7 (PXX scale, +2048 for ch 9-16, 0 = no pulses, 2047 = hold, as
//D16), byte 6 = 0x20 | slot. Once the radio has sent values (failsafe mode
//"receiver": none, the receiver keeps its own)
uint8_t fs_slot = 0xFF, fs_chan = 0;
#ifdef FAILSAFE_ENABLE
if(IS_FAILSAFE_VALUES_on)
{
FrSkyA_fs_valid = true;
FrSkyA_fs_count = 0x3FF; // new values: from ch 1 in the next frames
FAILSAFE_VALUES_off;
}
FrSkyA_fs_count = (FrSkyA_fs_count + 1) & 0x3FF;
if(FrSkyA_fs_valid && FrSkyA_fs_count < (FRSKYA_8CH ? 8 : 16))
{
fs_chan = FrSkyA_fs_count;
fs_slot = fs_chan & 0x07;
packet[7] = FRSKYA_REGION | 0x20 | fs_slot;
}
#endif
//Channels, 8 slots: ch k or k+8 in turn (16 channels), ch k (8)
uint8_t chan = FrSkyA_chan_start;
for(uint8_t i = 9; i < 9 + 12; i += 3)
{
uint16_t ch1 = FrSkyA_slot_value(chan++, fs_slot, fs_chan);
uint16_t ch2 = FrSkyA_slot_value(chan++, fs_slot, fs_chan);
packet[i] = ch1;
packet[i+1] = ((ch1 >> 8) & 0x0F) | (ch2 << 4);
packet[i+2] = ch2 >> 4;
}
if(FRSKYA_8CH)
FrSkyA_chan_start = 0;
else
FrSkyA_chan_start ^= 0x08;
//S.Port downlink: frame bytes 20 (seq), 21 (count, slot 0), 22 (type), 23..30
FrSkyX_seq_sport(21, 30); // data at packet[23..30]
memmove(&packet[24], &packet[23], 8);
packet[23] = 0xFE; // sequenced S.Port
if(FrSkyA_cfg_len && packet[22] == 0)
{// Receiver settings in place of the S.Port data (none in this frame)
uint8_t n = FrSkyA_cfg_len - FrSkyA_cfg_pos;
if(n > 7) n = 7;
packet[22] = ((FrSkyA_cfg_buf[0] & 0x03) << 4) | (n + 1);
packet[23] = FrSkyA_cfg_type;
packet[24] = FrSkyA_cfg_type == 6 ? FrSkyA_cfg_pos : (FrSkyA_cfg_pos << 4) | FrSkyA_cfg_len; // ISRM 0x10630: offset only
memset(&packet[25], 0, 7);
memcpy(&packet[25], &FrSkyA_cfg_buf[FrSkyA_cfg_pos], n);
FrSkyA_cfg_pos += n;
if(FrSkyA_cfg_pos >= FrSkyA_cfg_len)
FrSkyA_cfg_len = 0;
}
//XOR from frame byte 3
uint8_t key = FrSkyA_key(0x83);
uint8_t n = key & 7;
if(n < 3) n = 3;
for(uint8_t i = 0; i < n; i++)
packet[4 + i] ^= key;
FrSkyA_crc();
}
static void __attribute__((unused)) FrSkyA_set_sync(uint16_t sync)
{
CC2500_WriteReg(CC2500_04_SYNC1, sync >> 8);
CC2500_WriteReg(CC2500_05_SYNC0, sync);
}
// A reply in packet_in: 1 length byte, 18 bytes, 2 status bytes
static bool __attribute__((unused)) FrSkyA_read_reply()
{
uint8_t len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST);
if((len & 0x80) || (len & 0x7F) < FRSKYA_REPLY_LEN + 3)
return false; // overflow or nothing complete
CC2500_ReadData(packet_in, FRSKYA_REPLY_LEN + 3);
return packet_in[0] == FRSKYA_REPLY_LEN && (packet_in[FRSKYA_REPLY_LEN + 2] & 0x80); // CC2500 CRC
}
static bool __attribute__((unused)) FrSkyA_setup_reply_ok(uint8_t type)
{// Same CRC as the TX frames (bytes 2..15)
if(packet_in[1] != 0x03 || packet_in[2] != 0x01 || packet_in[3] != type || packet_in[5] != FrSkyA_sub)
return false;
uint16_t lcrc = FrSkyX_crc(&packet_in[3], FRSKYA_REPLY_LEN - 4);
return packet_in[17] == (lcrc >> 8) && packet_in[18] == (lcrc & 0xFF);
}
static void __attribute__((unused)) FrSkyA_register_reply()
{
if(!FrSkyA_setup_reply_ok(1))
return;
if(FrSkyA_sub == 0)
memcpy(FrSkyA_name, &packet_in[6], 8);
debugln("A reg %d", FrSkyA_sub);
FrSkyA_sub++;
FrSkyA_tries = 0;
if(FrSkyA_sub > 5)
{// Registered: on to bind
FrSkyA_mode = FRSKYA_BIND;
FrSkyA_sub = 0;
FrSkyA_count = 0;
}
}
static void __attribute__((unused)) FrSkyA_bind_reply()
{
if(!FrSkyA_setup_reply_ok(2))
return;
if(FrSkyA_sub == 0)
memcpy(FrSkyA_name, &packet_in[6], 8);
debugln("A bind %d", FrSkyA_sub);
FrSkyA_sub++;
FrSkyA_tries = 0;
if(FrSkyA_sub > 5)
{
BIND_DONE;
FrSkyA_mode = FRSKYA_DATA;
FrSkyX_telem_init();
}
}
#if defined TELEMETRY
static void __attribute__((unused)) FrSkyA_telemetry()
{
if(packet_in[1] != rx_tx_addr[3] || packet_in[2] != rx_tx_addr[2] || packet_in[3] != rx_tx_addr[1])
return;
uint8_t b3 = packet_in[4] ^ FrSkyA_key(0x74);
// CRC over frame bytes 2..15, byte 3 before its XOR
uint8_t tmp[FRSKYA_REPLY_LEN - 4];
memcpy(tmp, &packet_in[3], FRSKYA_REPLY_LEN - 4);
tmp[1] = b3;
uint16_t lcrc = FrSkyX_crc(tmp, FRSKYA_REPLY_LEN - 4);
if(packet_in[17] != (lcrc >> 8) || packet_in[18] != (lcrc & 0xFF))
return;
if(packet_in[7] == 5 || packet_in[7] == 6)
FrSkyA_stream_reply(&packet_in[6]);
// As a D16 telemetry frame for frsky_process_telemetry(): length, id,
// id, byte, RSSI | 0x80 or voltage, seq, count, data, CRC (D16, of
// bytes 3..15), RSSI, LQI. The ACCESS reply carries the same sequenced
// S.Port byte stream as D16 (7E, stuffed), up to 8 bytes after the
// stream type; bytes past the count are left over from older replies
uint8_t d[20];
uint8_t count = packet_in[7] == 0xFE ? packet_in[6] & 0x0F : 0;
if(count > 8)
count = 8;
d[0] = 17;
d[1] = packet_in[1];
d[2] = packet_in[2];
d[3] = packet_in[3];
d[4] = b3;
d[5] = packet_in[5];
d[6] = count;
memset(&d[7], 0, 9);
memcpy(&d[7], &packet_in[8], count);
lcrc = FrSkyX_crc(&d[3], 13);
d[16] = lcrc >> 8;
d[17] = lcrc;
d[18] = packet_in[19];
d[19] = packet_in[20];
if(frsky_process_telemetry(d, 20))
{
pps_counter++;
if(TX_LQI == 0)
TX_LQI++;
}
}
#endif
uint16_t FRSKYA_callback()
{
#ifdef MULTI_EU
if(sub_protocol < A_EU16)
return FRSKYA_PERIOD; // FCC subtypes: nothing sent in the EU builds
#endif
switch(FrSkyA_phase)
{
case 0:
{// TX
#ifdef MULTI_SYNC
telemetry_set_input_sync(FRSKYA_PERIOD);
#endif
CC2500_SetFreqOffset();
CC2500_SetPower();
uint8_t ch;
if(FrSkyA_mode != FRSKYA_DATA && IS_BIND_DONE)
{// Bind ended by the radio
FrSkyA_mode = FRSKYA_DATA;
FrSkyX_telem_init();
}
if(FrSkyA_mode == FRSKYA_DATA)
{
ch = hopping_frequency_no;
FrSkyA_data_frame();
}
else
{
if(++FrSkyA_count >= FRSKYA_REG_TRY && FrSkyA_sub == 0)
{// Nobody answers: try the other step
FrSkyA_count = 0;
FrSkyA_mode = FrSkyA_mode == FRSKYA_REGISTER ? FRSKYA_BIND : FRSKYA_REGISTER;
}
ch = FrSkyA_mode == FRSKYA_REGISTER ? FRSKYA_REG_CH : FRSKYA_BIND_CH;
FrSkyA_setup_frame(FrSkyA_mode == FRSKYA_REGISTER ? 1 : 2);
}
FrSkyX_set_start(ch);
FrSkyA_set_sync(0xD391);
CC2500_SetTxRxMode(TX_EN);
CC2500_Strobe(CC2500_SFTX);
CC2500_WriteData(packet, FRSKYA_LEN + 1);
FrSkyA_phase = 1;
return FRSKYA_TX_US;
}
case 1:
// RX for the reply, same channel
CC2500_Strobe(CC2500_SIDLE);
FrSkyA_set_sync(0x89CB);
CC2500_SetTxRxMode(RX_EN);
CC2500_Strobe(CC2500_SFRX);
CC2500_Strobe(CC2500_SRX);
FrSkyA_phase = 2;
return FRSKYA_RX_US;
default:
{// The reply, then the next hop
bool got = FrSkyA_read_reply();
CC2500_Strobe(CC2500_SIDLE);
if(FrSkyA_mode == FRSKYA_REGISTER)
{
if(got) FrSkyA_register_reply();
}
else if(FrSkyA_mode == FRSKYA_BIND)
{
if(got) FrSkyA_bind_reply();
}
else
{
#if defined TELEMETRY
if(got)
FrSkyA_telemetry();
if(millis() - pps_timer >= 700)
{// 100 frames
pps_timer = millis();
TX_LQI = pps_counter;
pps_counter = 0;
}
if(TX_LQI == 0)
FrSkyX_telem_init();
else
telemetry_link = 1;
#endif
hopping_frequency_no = (hopping_frequency_no + FrSkyX_chanskip) % 47;
}
if(FrSkyA_mode != FRSKYA_DATA && FrSkyA_sub && ++FrSkyA_tries > 10)
{// Lost the receiver in the middle of a step: start over
FrSkyA_sub = 0;
FrSkyA_tries = 0;
}
FrSkyA_phase = 0;
return FRSKYA_PERIOD - FRSKYA_TX_US - FRSKYA_RX_US;
}
}
}
void FRSKYA_init()
{
set_rx_tx_addr(MProtocol_id_master);
FrSkyFormat = 0; // FCC hop table
FrSkyX2_init_hop(); // the ACCESS table, [47] = 0
hopping_frequency[FRSKYA_BIND_CH] = 239;
// Registration ID: the module ID in hex
for(uint8_t i = 0; i < 8; i++)
{
uint8_t v = (MProtocol_id_master >> (28 - 4 * i)) & 0x0F;
FrSkyA_regid[i] = v < 10 ? '0' + v : 'A' + v - 10;
}
FrSkyX_chanskip = 0;
while(!FrSkyX_chanskip)
FrSkyX_chanskip = random(0xfefefefe) % 47;
hopping_frequency_no = 0;
FrSkyA_chan_start = 0;
FRSKY_init_cc2500(FRSKYA_cc2500_conf);
// Frequency offset compensation only once a carrier is there (10 dB over
// the noise): left running on noise before the reply, it drifts and 15 %
// of the replies were missed. Without it, 15 % fail the CRC (the RX6R is
// on 300 kHz steps, the CC2500 on 299.93 kHz).
CC2500_WriteReg(CC2500_19_FOCCFG, 0x36);
CC2500_WriteReg(CC2500_1C_AGCCTRL1, 0x68);
for(uint8_t c = 0; c <= FRSKYA_BIND_CH; c++)
{// Calibrate the hops, register and bind channels
CC2500_Strobe(CC2500_SIDLE);
CC2500_WriteReg(CC2500_0A_CHANNR, hopping_frequency[c]);
CC2500_Strobe(CC2500_SCAL);
delayMicroseconds(900);
calData[c] = CC2500_ReadReg(CC2500_25_FSCAL1);
}
CC2500_WriteReg(CC2500_18_MCSM0, 0x08); // no calibration: calData
FrSkyA_mode = IS_BIND_IN_PROGRESS ? FRSKYA_REGISTER : FRSKYA_DATA;
FrSkyA_sub = FrSkyA_tries = FrSkyA_uid = 0;
FrSkyA_count = 0;
FrSkyA_phase = 0;
memcpy(FrSkyA_name, "RX ", 8);
FrSkyX_telem_init();
FrSkyA_cfg_len = FrSkyA_lua_out_len = 0;
#ifdef FAILSAFE_ENABLE
FrSkyA_fs_valid = false;
FrSkyA_fs_count = 0;
#endif
}
#endif
+1
View File
@@ -105,3 +105,4 @@
107,WPL
108,Ares
109,MoFly
112,FrskyA,16ch,8ch,EU16ch,EU8ch
+6
View File
@@ -31,6 +31,7 @@ const char STR_BAYANG[] ="Bayang";
const char STR_FRSKYL[] ="FrSky L";
const char STR_FRSKYX[] ="FrSky X";
const char STR_FRSKYX2[] ="FrSkyX2";
const char STR_FRSKYA[] ="FrSkyA";
const char STR_ESKY[] ="ESky";
const char STR_MT99XX[] ="MT99XX";
const char STR_MT99XX2[] ="MT99XX2";
@@ -127,8 +128,10 @@ const char STR_SUBTYPE_HUBSAN[] = "\x04""H107""H301""H501";
const char STR_SUBTYPE_FRSKYD[] = "\x06""D8\0 ""Cloned";
#ifndef MULTI_EU
const char STR_SUBTYPE_FRSKYX[] = "\x07""D16\0 ""D16 8ch""LBT(EU)""LBT 8ch""Cloned\0""Clo 8ch";
const char STR_SUBTYPE_FRSKYA[] = "\x06""16ch\0 ""8ch\0 ""EU16ch""EU 8ch";
#else
const char STR_SUBTYPE_FRSKYX[] = "\x07""--->\0 ""--->\0 ""LBT(EU)""LBT 8ch""Cloned\0""Clo 8ch";
const char STR_SUBTYPE_FRSKYA[] = "\x06""--->\0 ""--->\0 ""EU16ch""EU 8ch";
#endif
const char STR_SUBTYPE_HISKY[] = "\x05""Std\0 ""HK310";
const char STR_SUBTYPE_V2X2[] = "\x06""Std\0 ""JXD506""MR101\0";
@@ -341,6 +344,9 @@ const mm_protocol_definition multi_protocols[] = {
{PROTO_FRSKYX, STR_FRSKYX, STR_SUBTYPE_FRSKYX, 6, OPTION_RFTUNE, 1, 0, SW_CC2500, FRSKYX_init, FRSKYX_callback },
{PROTO_FRSKYX2, STR_FRSKYX2, STR_SUBTYPE_FRSKYX, 6, OPTION_RFTUNE, 1, 0, SW_CC2500, FRSKYX_init, FRSKYX_callback },
#endif
#if defined(FRSKYA_CC2500_INO)
{PROTO_FRSKYA, STR_FRSKYA, STR_SUBTYPE_FRSKYA, 4, OPTION_RFTUNE, 1, 0, SW_CC2500, FRSKYA_init, FRSKYA_callback },
#endif
//OpenTX 2.3.x issue: DO NOT CHANGE ORDER above
#if defined(FRSKYL_CC2500_INO)
{PROTO_FRSKYL, STR_FRSKYL, STR_SUBTYPE_FRSKYL, 2, OPTION_RFTUNE, 0, 0, SW_CC2500, FRSKYL_init, FRSKYL_callback },
+8
View File
@@ -137,6 +137,7 @@ enum PROTOCOLS
PROTO_WPL = 107, // =>NRF24L01
PROTO_ARES = 108, // =>CC2500
PROTO_MOFLY = 109, // =>CC2500 & NRF24L01
PROTO_FRSKYA = 112, // =>CC2500
PROTO_NANORF = 126, // =>NRF24L01
PROTO_TEST = 127, // =>CC2500
@@ -283,6 +284,13 @@ enum FRSKYD
FRSKYD = 0,
DCLONE = 1,
};
enum FRSKYA
{
A_16 = 0,
A_8 = 1,
A_EU16 = 2,
A_EU8 = 3,
};
enum FRSKYX
{
CH_16 = 0,
+59 -46
View File
@@ -693,6 +693,55 @@ void setup()
// Main
// Protocol scheduler
#ifdef SPORT_SEND
// One S.Port packet from the radio (physical ID, primId, data ID, value; no
// CRC) into the stuffed downlink stream (FrSky X, X2, ACCESS, R9)
void SportQueue(const uint8_t *b)
{
#define BYTE_STUFF 0x7D
#define STUFF_MASK 0x20
//debug("SPort_in: ");
boolean sport_valid=false;
for(uint8_t i=1;i<8;i++)
if(b[i]!=0) sport_valid=true; //Check that the payload is not full of 0
if((b[0]&0x1F) > 0x1B) //Check 1st byte validity
sport_valid=false;
if(sport_valid)
{
SportData[SportTail]=0x7E;
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
SportData[SportTail]=b[0]&0x1F;
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
for(uint8_t i=1;i<8;i++)
{
if( (b[i]==BYTE_STUFF) || (b[i]==0x7E) )
{//stuff
SportData[SportTail]=BYTE_STUFF;
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
SportData[SportTail]=b[i]^STUFF_MASK;
}
else
SportData[SportTail]=b[i];
//debug("%02X ",SportData[SportTail]);
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
}
uint8_t used = SportTail;
if ( SportHead > SportTail )
used += MAX_SPORT_BUFFER - SportHead ;
else
used -= SportHead ;
if ( used >= MAX_SPORT_BUFFER-(MAX_SPORT_BUFFER>>2) )
{
DATA_BUFFER_LOW_on;
//Send Multi Status ASAP to inform the TX
SEND_MULTI_STATUS_on;
Update_Telem();
debugln("Low buf=%d,h=%d,t=%d",used,SportHead,SportTail);
}
}
}
#endif
void loop()
{
uint16_t next_callback, diff;
@@ -769,7 +818,7 @@ void loop()
void End_Bind()
{
//Request protocol to terminate bind
if(protocol==PROTO_FRSKYD || protocol==PROTO_FRSKYL || protocol==PROTO_FRSKYX || protocol==PROTO_FRSKYX2 || protocol==PROTO_FRSKYV || protocol==PROTO_FRSKY_R9
if(protocol==PROTO_FRSKYD || protocol==PROTO_FRSKYL || protocol==PROTO_FRSKYX || protocol==PROTO_FRSKYX2 || protocol==PROTO_FRSKYA || protocol==PROTO_FRSKYV || protocol==PROTO_FRSKY_R9
|| protocol==PROTO_DSM_RX || protocol==PROTO_AFHDS2A_RX || protocol==PROTO_FRSKY_RX || protocol==PROTO_BAYANG_RX
|| protocol==PROTO_AFHDS2A || protocol==PROTO_BUGS || protocol==PROTO_BUGSMINI || protocol==PROTO_HOTT || protocol==PROTO_ASSAN)
BIND_DONE;
@@ -1529,50 +1578,8 @@ void update_serial_data()
}
#endif
#ifdef SPORT_SEND
if((protocol==PROTO_FRSKYX || protocol==PROTO_FRSKYX2 || protocol==PROTO_FRSKY_R9) && rx_len==27+8)
{//Protocol waiting for 8 bytes
#define BYTE_STUFF 0x7D
#define STUFF_MASK 0x20
//debug("SPort_in: ");
boolean sport_valid=false;
for(uint8_t i=28;i<28+7;i++)
if(rx_ok_buff[i]!=0) sport_valid=true; //Check that the payload is not full of 0
if((rx_ok_buff[27]&0x1F) > 0x1B) //Check 1st byte validity
sport_valid=false;
if(sport_valid)
{
SportData[SportTail]=0x7E;
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
SportData[SportTail]=rx_ok_buff[27]&0x1F;
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
for(uint8_t i=28;i<28+7;i++)
{
if( (rx_ok_buff[i]==BYTE_STUFF) || (rx_ok_buff[i]==0x7E) )
{//stuff
SportData[SportTail]=BYTE_STUFF;
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
SportData[SportTail]=rx_ok_buff[i]^STUFF_MASK;
}
else
SportData[SportTail]=rx_ok_buff[i];
//debug("%02X ",SportData[SportTail]);
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
}
uint8_t used = SportTail;
if ( SportHead > SportTail )
used += MAX_SPORT_BUFFER - SportHead ;
else
used -= SportHead ;
if ( used >= MAX_SPORT_BUFFER-(MAX_SPORT_BUFFER>>2) )
{
DATA_BUFFER_LOW_on;
//Send Multi Status ASAP to inform the TX
SEND_MULTI_STATUS_on;
Update_Telem();
debugln("Low buf=%d,h=%d,t=%d",used,SportHead,SportTail);
}
}
}
if((protocol==PROTO_FRSKYX || protocol==PROTO_FRSKYX2 || protocol==PROTO_FRSKYA || protocol==PROTO_FRSKY_R9) && rx_len==27+8)
SportQueue((const uint8_t *)&rx_ok_buff[27]); //Protocol waiting for 8 bytes
#endif //SPORT_SEND
#ifdef HOTT_FW_TELEMETRY
if(protocol==PROTO_HOTT && rx_len==27+1)
@@ -1595,6 +1602,12 @@ void update_serial_data()
CONFIG_SerialRX=true;
}
#endif
#if defined(FRSKYA_CC2500_INO)
if(protocol==PROTO_FRSKYA && rx_len>27+1 && rx_len<27+8)
{//Lua/multiBuffer message (8 bytes = S.Port)
FrSkyA_lua_in((const uint8_t *)&rx_ok_buff[27], rx_len-27);
}
#endif
#ifdef RLINK_HUB_TELEMETRY
if(protocol==PROTO_RLINK && sub_protocol==RLINK_DUMBORC_P
&& rx_len>27 && rx_len<=27+sizeof(RLINK_SerialRX_val))
@@ -1856,7 +1869,7 @@ void PPM_Telemetry_serial_init()
)
initTXSerial( SPEED_9600 ) ;
#ifndef TELEMETRY_FRSKYX_TO_FRSKYD
if(protocol==PROTO_FRSKYX || protocol==PROTO_FRSKYX2)
if(protocol==PROTO_FRSKYX || protocol==PROTO_FRSKYX2 || protocol==PROTO_FRSKYA)
initTXSerial( SPEED_57600 ) ;
#endif
if(protocol==PROTO_DSM)
+18 -6
View File
@@ -38,11 +38,13 @@ uint8_t RetrySequence ;
// Store for out of sequence packet
uint8_t FrSkyX_RX_ValidSeq ;
// Payload: up to 6 bytes from a D16 receiver, 8 from an ACCESS one
#define FRSKYX_RX_PAYLOAD_MAX 8
struct t_FrSkyX_RX_Frame
{
boolean valid;
uint8_t count;
uint8_t payload[6];
uint8_t payload[FRSKYX_RX_PAYLOAD_MAX];
} ;
// Store for FrskyX telemetry
@@ -404,7 +406,7 @@ bool frsky_process_telemetry(uint8_t *buffer,uint8_t len)
#endif
#if defined SPORT_TELEMETRY && (defined FRSKYX_CC2500_INO || defined FRSKYR9_SX1276_INO)
if (protocol==PROTO_FRSKYX||protocol==PROTO_FRSKYX2)
if (protocol==PROTO_FRSKYX||protocol==PROTO_FRSKYX2||protocol==PROTO_FRSKYA)
{
/*Telemetry frames(RF) SPORT info
15 bytes payload
@@ -438,7 +440,7 @@ bool frsky_process_telemetry(uint8_t *buffer,uint8_t len)
return true;
#endif
}
if (protocol==PROTO_FRSKYX||protocol==PROTO_FRSKYX2||protocol==PROTO_FRSKY_R9)
if (protocol==PROTO_FRSKYX||protocol==PROTO_FRSKYX2||protocol==PROTO_FRSKYA||protocol==PROTO_FRSKY_R9)
{
telemetry_lost=0;
@@ -466,7 +468,7 @@ bool frsky_process_telemetry(uint8_t *buffer,uint8_t len)
// buffer[7-12] payload
p = &FrSkyX_RX_Frames[packet_seq] ;
count = buffer[6]; // Payload length
if ( count <= 6 )
if ( count <= FRSKYX_RX_PAYLOAD_MAX )
{//Store payload
p->count = count ;
for ( uint8_t i = 0 ; i < count ; i++ )
@@ -497,7 +499,7 @@ bool frsky_process_telemetry(uint8_t *buffer,uint8_t len)
{//Received next sequence -> save it
q = &FrSkyX_RX_Frames[packet_seq] ;
count = buffer[6]; // Payload length
if ( count <= 6 )
if ( count <= FRSKYX_RX_PAYLOAD_MAX )
{//Store payload
q->count = count ;
for ( uint8_t i = 0 ; i < count ; i++ )
@@ -932,9 +934,19 @@ void TelemetryUpdate()
return;
}
#endif
#if defined(FRSKYA_CC2500_INO)
if(protocol == PROTO_FRSKYA && FrSkyA_lua_out_len)
{// Receiver message for the Lua script (multiBuffer "Pipe")
multi_send_header(MULTI_TELEMETRY_RLINK, FrSkyA_lua_out_len);
for (uint8_t i = 0; i < FrSkyA_lua_out_len; i++)
Serial_write(FrSkyA_lua_out[i]);
FrSkyA_lua_out_len = 0;
return;
}
#endif
#endif
#if defined SPORT_TELEMETRY
if ((protocol==PROTO_FRSKYX || protocol==PROTO_FRSKYX2||protocol==PROTO_FRSKY_R9) && telemetry_link
if ((protocol==PROTO_FRSKYX || protocol==PROTO_FRSKYX2||protocol==PROTO_FRSKYA||protocol==PROTO_FRSKY_R9) && telemetry_link
#ifdef TELEMETRY_FRSKYX_TO_FRSKYD
&& mode_select==MODE_SERIAL
#endif
+7
View File
@@ -289,6 +289,7 @@
#undef FRSKYL_CC2500_INO
#undef FRSKYV_CC2500_INO
#if not defined(CC2500_INSTALLED)
#undef FRSKYA_CC2500_INO
#undef FRSKYX_CC2500_INO
#undef FRSKY_RX_CC2500_INO
#endif
@@ -380,6 +381,7 @@
#endif
#if not defined(STM32_BOARD)
#undef SX1276_INSTALLED
#undef FRSKYA_CC2500_INO //STM32 only: doesn't fit the atmega328p with the other CC2500 protocols
#endif
#if not defined(SX1276_INSTALLED) || defined MULTI_EU
#undef FRSKYR9_SX1276_INO
@@ -471,6 +473,11 @@
#undef YUXIANG_NRF24L01_INO
#endif
//FrSky ACCESS uses the FrSky X routines and telemetry
#if defined(FRSKYA_CC2500_INO)
#define FRSKYX_CC2500_INO
#endif
//OpenTX 2.3.x issue
#if defined (FRSKYD_CC2500_INO) || defined(FRSKYV_CC2500_INO) || defined(FRSKYX_CC2500_INO)
#define FRSKYX_CC2500_INO
+1
View File
@@ -214,6 +214,7 @@
#define FRSKYD_CC2500_INO
#define FRSKYV_CC2500_INO
#define FRSKYX_CC2500_INO //Include FRSKYX2 protocol
#define FRSKYA_CC2500_INO //FrSky ACCESS, needs FRSKYX_CC2500_INO
#define FRSKY_RX_CC2500_INO
#define FUTABA_CC2500_INO
#define HITEC_CC2500_INO
+40
View File
@@ -92,6 +92,7 @@ CFlie|AIR|38|CFlie||||||||NRF24L01|
[Flysky AFHDS2A](Protocols_Details.md#FLYSKY-AFHDS2A---28)||28|PWM_IBUS|PPM_IBUS|PWM_SBUS|PPM_SBUS|Gyro_Off|Gyro_On|Gyro_On_Rev||A7105|
[Flysky AFHDS2A RX](Protocols_Details.md#FLYSKY-AFHDS2A-RX---56)||56|Multi|CPPM|||||||A7105|
[FQ777](Protocols_Details.md#FQ777---23)||23|124|XBM37|||||||NRF24L01|SSV7241
[FrskyA](Protocols_Details.md#FRSKYA---112)||112|16ch|8ch|EU16ch|EU8ch|||||CC2500|
[FrskyD](Protocols_Details.md#FRSKYD---3)||3|D8|Cloned|||||||CC2500|
[FrskyL](Protocols_Details.md#FRSKYL---67)||67|LR12|LR12 6CH|||||||CC2500|
[FrskyR9](Protocols_Details.md#FRSKYR9---65)||65|FrskyR9|R9_915|R9_868||||||SX1276|
@@ -955,6 +956,45 @@ Use the identifier learnt from another FrSky radio when binding with the FrSkyRX
## FRSKYX2 - *64*
Same as [FrskyX](Protocols_Details.md#FRSKYX---15) but for D16 v2.1.0 FCC/LBT.
## FRSKYA - *112*
Models: FrSky ACCESS 2.4GHz receivers, tested with the RX6R (ACCESS firmware 2.1.8) and the Archer Plus SR10+ (1.0.10 and 3.0.3). Protocol also known as ACCESS.
Not supported: TANDEM and TWIN receivers, race mode, 24 channels, more than one receiver per model, receiver firmware updates.
Extended limits and failsafe supported
Telemetry enabled for A1 (RxBatt), RSSI, TX_RSSI, TX_LQI and the S.Port sensors, as FrskyX. S.Port packets from the radio are sent to the receiver (for example the Archer Plus stabilizer settings), this needs a radio firmware able to send them to a FrskyA module.
The receiver options (outputs, telemetry, F.Port/S.Bus...) are set with the [FrSky ACCESS RX script](https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/Lua_scripts#frsky-access-rx).
Option for this protocol corresponds to fine frequency tuning, as FrskyX. Check the [Frequency Tuning page](/docs/Frequency_Tuning.md) to determine it.
Bind: a receiver is registered to the module, then bound, both during the same bind:
- put the receiver in register mode (RX6R: hold its bind button while powering it until the LEDs alternate; Archer Plus: see its manual) and start the bind on the radio
- once the receiver has registered, power cycle it normally while the module is still in bind: it binds and the link starts
If no receiver answers the registration within 2 seconds, the module looks for an already registered receiver to bind, and both steps alternate until the end of the bind. The RX number of the model is sent to the receiver at bind (Model Match).
### Sub_protocol 16ch - *0*
FCC, 16 channels. A frame every 7ms carries channels 1-8 and 9-16 in turn.
CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12|CH13|CH14|CH15|CH16
---|---|---|---|---|---|---|---|---|----|----|----|----|----|----|----
CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12|CH13|CH14|CH15|CH16
### Sub_protocol 8ch - *1*
FCC, 8 channels every 7ms.
CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8
---|---|---|---|---|---|---|---
CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8
### Sub_protocol EU16ch - *2*
Same as 16ch for the EU region. ACCESS uses the same frequencies, hopping and timing in both regions, only the region sent to the receiver changes.
### Sub_protocol EU8ch - *3*
Same as 8ch for the EU region.
## FRSKY_RX - *55*
### Sub_protocol Multi - *0*
@@ -6,6 +6,7 @@ exitcode=0;
# CC2500-only 64Kb FCC builds
printf "\e[33;1mBuilding mm-stm-cc2500-64-aetr-v$MULTI_VERSION.bin\e[0m\n";
opt_disable SCANNER_CC2500_INO;
opt_disable FRSKYA_CC2500_INO;
opt_disable ENABLE_PPM;
opt_disable A7105_INSTALLED;
opt_disable CYRF6936_INSTALLED;