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

feat(pxx2): add support for SR10+ and R10+ #3249

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 112 additions & 48 deletions radio/src/gui/colorlcd/access_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ RxOptions::RxOptions(Window* parent, uint8_t moduleIdx, uint8_t rxIdx):
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
state = RO_ReadReceiverSettings;
auto& rxInfo = hwSettings.modules[moduleIdx].receivers[receiverIdx].information;
rxInfo.capabilities = 0xFFFFFFFF;
rxInfo.capabilities = 0xFB;//0xFFFFFFFF;
hwSettings.receiverSettings.outputsCount = 6;
for (int i=0; i<6; i++) {
hwSettings.receiverSettings.outputsMapping[i] = i;
Expand Down Expand Up @@ -710,24 +710,107 @@ void RxOptions::checkEvents()
#define CH_ENABLE_SPORT 4
#define CH_ENABLE_SBUS 5

#define CH_MAP_SBUS_IN (1 << 5) /* 0x20 */
#define CH_MAP_SPORT (1 << 6) /* 0x40 */
#define CH_MAP_SBUS_OUT (1 << 7) /* 0x80 */
#define CH_MAP_FBUS (CH_MAP_SPORT | CH_MAP_SBUS_OUT) /* 0xC0 */

static uint8_t getShiftedChannel(int8_t moduleIdx, int ch)
{
return g_model.moduleData[moduleIdx].channelsStart + ch;
}

static std::string getChannelText(int8_t moduleIdx, uint8_t pin, int val)
class OutputMappingChoice : public Choice
{
uint8_t ch = getShiftedChannel(moduleIdx, val);
uint8_t channelsMax = sentModuleChannels(moduleIdx) - 1;
if (val <= channelsMax) {
return std::string("CH") + std::to_string(ch + 1);
} else if (pin == CH_ENABLE_SPORT) {
return std::string("S.PORT");
} else if (pin == CH_ENABLE_SBUS) {
return std::string("SBUS");
protected:
uint32_t capabilities;
uint8_t ch_offset;
uint8_t channels;
uint8_t rx_pin;

int get_output_mapping()
{
auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return hwSettings.receiverSettings.outputsMapping[rx_pin];
}
return std::string();
}

void set_output_mapping(int val)
{
auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
hwSettings.receiverSettings.outputsMapping[rx_pin] = val;
}

std::string get_channel_text(int val)
{
if (val < channels) {
return std::string("CH") + std::to_string(ch_offset + val + 1);
}
return std::string();
}

public:
OutputMappingChoice(Window* parent, uint32_t capabilities,
uint8_t module, uint8_t channels, uint8_t output_pin) :
Choice(parent, rect_t{}, 0, channels - 1,
std::bind(&OutputMappingChoice::get_output_mapping, this),
std::bind(&OutputMappingChoice::set_output_mapping, this,
std::placeholders::_1), 0),
capabilities(capabilities),
ch_offset(getShiftedChannel(module, 0)),
channels(channels),
rx_pin(output_pin)
{
if (capabilities & (1 << RECEIVER_CAPABILITY_ENABLE_PWM_CH5_CH6)) {
if (CH_ENABLE_SPORT == output_pin) {
setTextHandler([=] (int val) {
if (val == channels) return std::string("S.PORT");
return get_channel_text(val);
});
setMax(channels);
return;
} else if (CH_ENABLE_SBUS == output_pin) {
setTextHandler([=] (int val) {
if (val == channels) return std::string("SBUS");
return get_channel_text(val);
});
setMax(channels);
return;
}
} else if (capabilities & (1 << RECEIVER_CAPABILITY_CONFIGURABLE_PORTS)) {
setTextHandler([=] (int val) {
switch(val) {
case CH_MAP_SBUS_IN:
return std::string("SBUS in"); // TODO: translation
case CH_MAP_SBUS_OUT:
return std::string("SBUS out");
case CH_MAP_SPORT:
return std::string("S.PORT");
case CH_MAP_FBUS:
return std::string("FBUS");
default:
return get_channel_text(val);
}
});
setAvailableHandler([=] (int val) {
switch(val) {
case CH_MAP_SBUS_IN:
return output_pin == 0;
case CH_MAP_SBUS_OUT:
case CH_MAP_SPORT:
case CH_MAP_FBUS:
return true;
default:
return val >= 0 && val < channels;
}
});
setMax(CH_MAP_FBUS);
return;
}

setTextHandler(std::bind(&OutputMappingChoice::get_channel_text, this,
std::placeholders::_1));
}
};

void RxOptions::update()
{
Expand Down Expand Up @@ -797,6 +880,21 @@ void RxOptions::update()
});
}

if (capabilities & (1 << RECEIVER_CAPABILITY_SBUS_24)) {
line = form->newLine(&grid);
new StaticText(line, rect_t{}, "SBUS-24");
new CheckBox(
line, rect_t{},
[]() {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return hwSettings.receiverSettings.sbus24ch;
},
[](int val) {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
hwSettings.receiverSettings.sbus24ch = val;
});
}

if (capabilities &
((1 << RECEIVER_CAPABILITY_FPORT) | (1 << RECEIVER_CAPABILITY_FPORT2))) {

Expand Down Expand Up @@ -834,42 +932,8 @@ void RxOptions::update()
std::string i_str = std::to_string(i+1);
new StaticText(line, rect_t{}, std::string(STR_PIN) + i_str);

uint8_t channelsMax = sentModuleChannels(moduleIdx) - 1;
uint8_t selectionMax = channelsMax;
if (capabilities & (1 << RECEIVER_CAPABILITY_ENABLE_PWM_CH5_CH6)
&& (CH_ENABLE_SPORT == i || CH_ENABLE_SBUS == i)) {
selectionMax++;
}

//uint8_t mapping = hwSettings.receiverSettings.outputsMapping[i];
// uint8_t channel = getShiftedChannel(moduleIdx, mapping);

// TODO
// auto r = grid.getFieldSlot(2, 1);
// if (r.h > BAR_HEIGHT) {
// r.y += (r.h - BAR_HEIGHT)/2;
// r.h = BAR_HEIGHT;
// }
// auto chBar = new OutputChannelBar(form, r, channel);

auto chDn = new Choice(
line, rect_t{}, 0, selectionMax,
[=]() {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return hwSettings.receiverSettings.outputsMapping[i];
},
[=](int val) {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
hwSettings.receiverSettings.outputsMapping[i] = val;
// if (val <= channelsMax) {
// chBar->setChannel(getShiftedChannel(moduleIdx, val));
// lv_obj_clear_flag(chBar->getLvObj(), LV_OBJ_FLAG_HIDDEN);
// } else {
// lv_obj_add_flag(chBar->getLvObj(), LV_OBJ_FLAG_HIDDEN);
// }
});
chDn->setTextHandler(
[=](int val) { return getChannelText(moduleIdx, i, val); });
uint8_t channels = sentModuleChannels(moduleIdx);
new OutputMappingChoice(line, capabilities, moduleIdx, channels, i);
}

line = form->newLine(&grid);
Expand Down
6 changes: 6 additions & 0 deletions radio/src/pulses/pxx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ void Pxx2Pulses::setupReceiverSettingsFrame(uint8_t module, int16_t* channels, u
uint8_t flag1 = 0;
if (reusableBuffer.hardwareAndSettings.receiverSettings.telemetryDisabled)
flag1 |= PXX2_RX_SETTINGS_FLAG1_TELEMETRY_DISABLED;
if (reusableBuffer.hardwareAndSettings.receiverSettings.sbus24ch)
flag1 |= PXX2_RX_SETTINGS_FLAG1_SBUS_24CH;
if (reusableBuffer.hardwareAndSettings.receiverSettings.pwmRate)
flag1 |= PXX2_RX_SETTINGS_FLAG1_FASTPWM;
if (reusableBuffer.hardwareAndSettings.receiverSettings.fport)
Expand All @@ -416,6 +418,10 @@ void Pxx2Pulses::setupReceiverSettingsFrame(uint8_t module, int16_t* channels, u
Pxx2Transport::addByte(flag1);
uint8_t outputsCount = min<uint8_t>(24, reusableBuffer.hardwareAndSettings.receiverSettings.outputsCount);
for (int i = 0; i < outputsCount; i++) {
// Replaces channel:
// (1 << 5) SBUS in (0x20)
// (1 << 6) S.PORT (0x40)
// (1 << 7) SBUS out (0x80)
Pxx2Transport::addByte(min<uint8_t>(23, reusableBuffer.hardwareAndSettings.receiverSettings.outputsMapping[i]));
}
}
Expand Down
4 changes: 4 additions & 0 deletions radio/src/pulses/pxx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

#define PXX2_RX_SETTINGS_FLAG1_TELEMETRY_DISABLED (1 << 7)
#define PXX2_RX_SETTINGS_FLAG1_READONLY (1 << 6)
#define PXX2_RX_SETTINGS_FLAG1_SBUS_24CH (1 << 5)
#define PXX2_RX_SETTINGS_FLAG1_FASTPWM (1 << 4)
#define PXX2_RX_SETTINGS_FLAG1_FPORT (1 << 3)
#define PXX2_RX_SETTINGS_FLAG1_TELEMETRY_25MW (1 << 2)
Expand Down Expand Up @@ -118,6 +119,8 @@ enum ReceiverCapabilities {
RECEIVER_CAPABILITY_ENABLE_PWM_CH5_CH6,
RECEIVER_CAPABILITY_FPORT2,
RECEIVER_CAPABILITY_RACING_MODE,
RECEIVER_CAPABILITY_CONFIGURABLE_PORTS,
RECEIVER_CAPABILITY_SBUS_24,
RECEIVER_CAPABILITY_COUNT
};

Expand Down Expand Up @@ -230,6 +233,7 @@ class ReceiverSettings {
uint8_t fport;
uint8_t enablePwmCh5Ch6;
uint8_t fport2;
uint8_t sbus24ch;
uint8_t outputsCount;
uint8_t outputsMapping[24];
};
Expand Down
3 changes: 3 additions & 0 deletions radio/src/telemetry/frsky_pxx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ static void processReceiverSettingsFrame(uint8_t module, const uint8_t * frame)
if (frame[4] & PXX2_RX_SETTINGS_FLAG1_FPORT2)
destination->fport2 = 1;

if (frame[4] & PXX2_RX_SETTINGS_FLAG1_SBUS_24CH)
destination->sbus24ch = 1;

uint8_t outputsCount = min<uint8_t>(16, frame[0] - 4);
destination->outputsCount = outputsCount;
for (uint8_t pin = 0; pin < outputsCount; pin++) {
Expand Down