FrSkyA and T-FHSS smaller: the 5-in-1 AIR builds fit again (#1217)

* FrSkyA: smaller (no memmove, one setup reply handler)

The 5-in-1 AIR firmwares (T18, T-Lite) were still too large after #1216.
- The S.Port data moved by one byte with a loop: memmove alone pulled
  200 bytes of libc in.
- Register and bind replies through one handler, the mode giving the
  frame type and the channel.
-312 bytes.

* Futaba: T-FHSS smaller in AIR builds, bind power via CC2500_SetPower()

- AIR builds: the Surface key layout, register table and telemetry rate
  limit left out (Surface and SR aren't there since #1216).
- The bind (link) at the normal power through CC2500_SetPower() with
  the bind flag cleared for the call, instead of a copy of it.
-200 bytes in AIR builds.

---------

Co-authored-by: Raphael Coeffic <1050031+raphaelcoeffic@users.noreply.github.com>
This commit is contained in:
Raphael CoefficandRaphael Coeffic authored and GitHub committed 2026-11-21 16:59:10 +01:00
1 parent eea0a0f3c2
commit aa916c2852
2 files changed
+36 -54

No files matched your search

+17 -33
View File
@@ -305,7 +305,8 @@ static void __attribute__((unused)) FrSkyA_data_frame()
FrSkyA_chan_start ^= 0x08; FrSkyA_chan_start ^= 0x08;
//S.Port downlink: frame bytes 20 (seq), 21 (count, slot 0), 22 (type), 23..30 //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] FrSkyX_seq_sport(21, 30); // data at packet[23..30]
memmove(&packet[24], &packet[23], 8); for(uint8_t i = 31; i > 23; i--) // data to packet[24..31] (no memmove: +200 bytes of libc)
packet[i] = packet[i - 1];
packet[23] = 0xFE; // sequenced S.Port packet[23] = 0xFE; // sequenced S.Port
if(FrSkyA_cfg_len && packet[22] == 0) if(FrSkyA_cfg_len && packet[22] == 0)
{// Receiver settings in place of the S.Port data (none in this frame) {// Receiver settings in place of the S.Port data (none in this frame)
@@ -353,37 +354,24 @@ static bool __attribute__((unused)) FrSkyA_setup_reply_ok(uint8_t type)
return packet_in[17] == (lcrc >> 8) && packet_in[18] == (lcrc & 0xFF); return packet_in[17] == (lcrc >> 8) && packet_in[18] == (lcrc & 0xFF);
} }
static void __attribute__((unused)) FrSkyA_register_reply() // Register (type 1) or bind (type 2) reply: the next sub, then the next step
static void __attribute__((unused)) FrSkyA_setup_reply(uint8_t type)
{ {
if(!FrSkyA_setup_reply_ok(1)) if(!FrSkyA_setup_reply_ok(type))
return; return;
if(FrSkyA_sub == 0) if(FrSkyA_sub == 0)
memcpy(FrSkyA_name, &packet_in[6], 8); memcpy(FrSkyA_name, &packet_in[6], 8);
debugln("A reg %d", FrSkyA_sub); debugln("A %d %d", type, FrSkyA_sub);
FrSkyA_sub++;
FrSkyA_tries = 0; FrSkyA_tries = 0;
if(FrSkyA_sub > 5) if(++FrSkyA_sub > 5)
{// Registered: on to bind {
FrSkyA_mode = FRSKYA_BIND;
FrSkyA_sub = 0; FrSkyA_sub = 0;
FrSkyA_count = 0; FrSkyA_count = 0;
} if(++FrSkyA_mode == FRSKYA_DATA)
} {// Bound
BIND_DONE;
static void __attribute__((unused)) FrSkyA_bind_reply() FrSkyX_telem_init();
{ }
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();
} }
} }
@@ -469,8 +457,8 @@ uint16_t FRSKYA_callback()
FrSkyA_count = 0; FrSkyA_count = 0;
FrSkyA_mode = FrSkyA_mode == FRSKYA_REGISTER ? FRSKYA_BIND : FRSKYA_REGISTER; FrSkyA_mode = FrSkyA_mode == FRSKYA_REGISTER ? FRSKYA_BIND : FRSKYA_REGISTER;
} }
ch = FrSkyA_mode == FRSKYA_REGISTER ? FRSKYA_REG_CH : FRSKYA_BIND_CH; ch = FRSKYA_REG_CH + FrSkyA_mode; // FRSKYA_BIND_CH in bind
FrSkyA_setup_frame(FrSkyA_mode == FRSKYA_REGISTER ? 1 : 2); FrSkyA_setup_frame(FrSkyA_mode + 1);
} }
FrSkyX_set_start(ch); FrSkyX_set_start(ch);
FrSkyA_set_sync(0xD391); FrSkyA_set_sync(0xD391);
@@ -493,13 +481,9 @@ uint16_t FRSKYA_callback()
{// The reply, then the next hop {// The reply, then the next hop
bool got = FrSkyA_read_reply(); bool got = FrSkyA_read_reply();
CC2500_Strobe(CC2500_SIDLE); CC2500_Strobe(CC2500_SIDLE);
if(FrSkyA_mode == FRSKYA_REGISTER) if(FrSkyA_mode != FRSKYA_DATA)
{ {
if(got) FrSkyA_register_reply(); if(got) FrSkyA_setup_reply(FrSkyA_mode + 1);
}
else if(FrSkyA_mode == FRSKYA_BIND)
{
if(got) FrSkyA_bind_reply();
} }
else else
{ {
+19 -21
View File
@@ -154,6 +154,7 @@ static uint8_t __attribute__((unused)) TFHSS_key(uint8_t i, uint8_t n, const uin
{ {
if(i == 0) if(i == 0)
return 0; return 0;
#ifndef MULTI_AIR
if(sub_protocol != TFHSS_AIR) if(sub_protocol != TFHSS_AIR)
{ {
if(i == 1 || i == 6) return 0; if(i == 1 || i == 6) return 0;
@@ -161,6 +162,9 @@ static uint8_t __attribute__((unused)) TFHSS_key(uint8_t i, uint8_t n, const uin
if(i == 7) return n; if(i == 7) return n;
return b[i - 8]; return b[i - 8];
} }
#else
(void)b;
#endif
uint8_t m = (i - 1) % 6; uint8_t m = (i - 1) % 6;
return m < 4 ? a[m] : m == 4 ? 0 : n; return m < 4 ? a[m] : m == 4 ? 0 : n;
} }
@@ -204,23 +208,11 @@ static bool __attribute__((unused)) TFHSS_unkey(const uint8_t *in, uint8_t len,
// Plus binds 33 dB down from its normal power, the T6K links at full power // Plus binds 33 dB down from its normal power, the T6K links at full power
static void __attribute__((unused)) TFHSS_SetPower() static void __attribute__((unused)) TFHSS_SetPower()
{ {
if(!TFHSS_list_mode) bool binding = IS_BIND_IN_PROGRESS;
{ BIND_DONE; // CC2500_SetPower(): the normal power
CC2500_SetPower(); CC2500_SetPower();
return; if(binding)
} BIND_IN_PROGRESS;
uint8_t power = CC2500_HIGH_POWER;
#ifdef CC2500_ENABLE_LOW_POWER
if(!IS_POWER_FLAG_on)
power = CC2500_LOW_POWER;
#endif
if(IS_RANGE_FLAG_on)
power = CC2500_RANGE_POWER;
if(prev_power != power)
{
CC2500_WriteReg(CC2500_3E_PATABLE, power);
prev_power = power;
}
} }
static uint8_t __attribute__((unused)) TFHSS_channel(uint8_t pos) static uint8_t __attribute__((unused)) TFHSS_channel(uint8_t pos)
@@ -272,9 +264,11 @@ static bool __attribute__((unused)) TFHSS_rx_read(uint8_t len)
static void __attribute__((unused)) TFHSS_telemetry(uint8_t first, const uint8_t *slots, uint8_t n, uint8_t lq, uint8_t rssi, uint8_t lqi) static void __attribute__((unused)) TFHSS_telemetry(uint8_t first, const uint8_t *slots, uint8_t n, uint8_t lq, uint8_t rssi, uint8_t lqi)
{ {
#ifdef FUTABA_FW_TELEMETRY #ifdef FUTABA_FW_TELEMETRY
if(sub_protocol != TFHSS_AIR && ++TFHSS_replies < TFHSS_TELEM_EVERY) #ifndef MULTI_AIR
return; if(sub_protocol != TFHSS_AIR && ++TFHSS_replies < TFHSS_TELEM_EVERY)
TFHSS_replies = 0; return;
TFHSS_replies = 0;
#endif
// The link frame: slot 0 half 0 = the receiver's voltage (0.1 V) // The link frame: slot 0 half 0 = the receiver's voltage (0.1 V)
if(first == 0 && !(slots[0] & 0x04)) if(first == 0 && !(slots[0] & 0x04))
v_lipo1 = (uint16_t)slots[1] * 255 / 132; v_lipo1 = (uint16_t)slots[1] * 255 / 132;
@@ -667,7 +661,11 @@ static void __attribute__((unused)) TFHSS_init()
hopping_frequency_no = 0; hopping_frequency_no = 0;
TFHSS_ch = TFHSS_channel(0); TFHSS_ch = TFHSS_channel(0);
const uint8_t *regs = sub_protocol == TFHSS_AIR ? TFHSS_AIR_init_values : TFHSS_init_values; #ifdef MULTI_AIR
const uint8_t *regs = TFHSS_AIR_init_values;
#else
const uint8_t *regs = sub_protocol == TFHSS_AIR ? TFHSS_AIR_init_values : TFHSS_init_values;
#endif
CC2500_Strobe(CC2500_SIDLE); CC2500_Strobe(CC2500_SIDLE);
for(uint8_t i = 0; i < 0x27; i++) for(uint8_t i = 0; i < 0x27; i++)
CC2500_WriteReg(i, pgm_read_byte_near(&regs[i])); CC2500_WriteReg(i, pgm_read_byte_near(&regs[i]));