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

Allow both version of rotary encoder boards #8564

Merged
merged 3 commits into from Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions radio/src/opentx.h
Expand Up @@ -571,11 +571,7 @@ bool setTrimValue(uint8_t phase, uint8_t idx, int trim);

#if defined(PCBSKY9X)
#define ROTARY_ENCODER_GRANULARITY (2 << g_eeGeneral.rotarySteps)
#elif defined(RADIO_FAMILY_T16) && !defined(RADIO_T18)
#define ROTARY_ENCODER_GRANULARITY (1)
#elif defined(RADIO_TX12)
#define ROTARY_ENCODER_GRANULARITY (1)
#elif defined(RADIO_FAMILY_TBS)
#elif defined(RADIO_FAMILY_TBS)
#define ROTARY_ENCODER_GRANULARITY (1)
#else
#define ROTARY_ENCODER_GRANULARITY (2)
Expand Down
37 changes: 21 additions & 16 deletions radio/src/targets/common/arm/stm32/rotary_encoder_driver.cpp
Expand Up @@ -73,24 +73,29 @@ void rotaryEncoderCheck()
{
#if (defined(RADIO_FAMILY_T16) && !defined(RADIO_T18)) || defined(RADIO_TX12)
static uint8_t state = 0;
uint8_t pins = ROTARY_ENCODER_POSITION();

if (pins != (state & 0x03) && !(readKeys() & (1 << KEY_ENTER))) {
if ((pins & 0x01) ^ ((pins & 0x02) >> 1)) {
if ((state & 0x03) == 3)
++rotencValue;
else
--rotencValue;
uint32_t pins;

pins = ROTARY_ENCODER_POSITION();

if (pins != (state & 0x03)) {
if ((pins ^ (state & 0x03)) == 0x03) {
if (pins == 3) {
rotencValue += 2;
}
else {
rotencValue -= 2;
}
}
else
{
if ((state & 0x03) == 3)
--rotencValue;
else if ((state & 0x03) == 0)
++rotencValue;
else {
if ((state & 0x01) ^ ((pins & 0x02) >> 1)) {
rotencValue -= 1;
}
else {
rotencValue += 1;
}
}
state &= ~0x03 ;
state |= pins ;
state &= ~0x03;
state |= pins;
#else
uint8_t newPosition = ROTARY_ENCODER_POSITION();
if (newPosition != rotencPosition && !(readKeys() & (1 << KEY_ENTER))) {
Expand Down