[X9E/X7D] Rotary encoder navigation speed implemented (#3724)
This commit is contained in:
committed by
Andre Bernet
parent
3cb64d984a
commit
1d735f2bd3
@@ -40,7 +40,7 @@ void rotencPoll()
|
||||
{
|
||||
#if defined(TELEMETREZ)
|
||||
if (TrotCount != LastTrotCount) {
|
||||
g_rotenc[0] = LastTrotCount = TrotCount ;
|
||||
rotencValue[0] = LastTrotCount = TrotCount ;
|
||||
}
|
||||
#else
|
||||
// Rotary Encoder polling
|
||||
@@ -64,10 +64,10 @@ void rotencPoll()
|
||||
x <<= 1 ;
|
||||
x ^= rotary & 0x80 ;
|
||||
if ( x ) {
|
||||
g_rotenc[0] -= 1 ;
|
||||
rotencValue[0] -= 1 ;
|
||||
}
|
||||
else {
|
||||
g_rotenc[0] += 1 ;
|
||||
rotencValue[0] += 1 ;
|
||||
}
|
||||
RotPosition = rotary ;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ set(LUA_EXPORT lua_export_horus)
|
||||
set(FLAVOUR horus)
|
||||
set(RAMBACKUP YES)
|
||||
|
||||
add_definitions(-DPCBHORUS -DPCBREV=${PCBREV} -DCOLORLCD -DSTM32F429_439xx -DSDRAM -DPPM_PIN_UART -DPPM_PIN_TIMER)
|
||||
add_definitions(-DPCBHORUS -DPCBREV=${PCBREV} -DSTM32F429_439xx -DSDRAM -DCOLORLCD -DPPM_PIN_UART -DPPM_PIN_TIMER)
|
||||
add_definitions(-DEEPROM_VARIANT=0 -DAUDIO -DVOICE -DRTCLOCK)
|
||||
|
||||
include_directories(${RADIO_SRC_DIRECTORY}/fonts/480x272 gui/${GUI_DIR} gui/${GUI_DIR}/layouts)
|
||||
|
||||
@@ -255,11 +255,7 @@ uint32_t readTrims(void);
|
||||
#define DBLKEYS_PRESSED_LFT_DWN(in) ((in & (KEYS_GPIO_PIN_LEFT + KEYS_GPIO_PIN_DOWN)) == (KEYS_GPIO_PIN_LEFT + KEYS_GPIO_PIN_DOWN))
|
||||
|
||||
// Rotary encoder driver
|
||||
extern int32_t rotencValue;
|
||||
extern uint32_t rotencSpeed;
|
||||
#define ROTENC_LOWSPEED 1
|
||||
#define ROTENC_MIDSPEED 5
|
||||
#define ROTENC_HIGHSPEED 50
|
||||
#define ROTARY_ENCODER_NAVIGATION
|
||||
void checkRotaryEncoder(void);
|
||||
|
||||
// WDT driver
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint32_t rotencPosition;
|
||||
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
@@ -89,22 +91,15 @@ uint8_t keyDown()
|
||||
return readKeys();
|
||||
}
|
||||
|
||||
int32_t rotencValue;
|
||||
uint32_t rotencPosition;
|
||||
uint32_t rotencSpeed = ROTENC_LOWSPEED;
|
||||
|
||||
#define ROTENC_DELAY_MIDSPEED 4
|
||||
#define ROTENC_DELAY_HIGHSPEED 2
|
||||
|
||||
void checkRotaryEncoder()
|
||||
{
|
||||
register uint32_t newpos = ROTARY_ENCODER_POSITION();
|
||||
if (newpos != rotencPosition) {
|
||||
if ((rotencPosition & 0x01) ^ ((newpos & 0x02) >> 1)) {
|
||||
--rotencValue;
|
||||
--rotencValue[0];
|
||||
}
|
||||
else {
|
||||
++rotencValue;
|
||||
++rotencValue[0];
|
||||
}
|
||||
rotencPosition = newpos;
|
||||
}
|
||||
@@ -121,28 +116,6 @@ void readKeysAndTrims()
|
||||
keys[index++].input(in & (1 << i));
|
||||
}
|
||||
|
||||
static rotenc_t rePreviousValue;
|
||||
rotenc_t reNewValue = (rotencValue / 2);
|
||||
int8_t scrollRE = reNewValue - rePreviousValue;
|
||||
static uint32_t lastTick = 0;
|
||||
if (scrollRE) {
|
||||
rePreviousValue = reNewValue;
|
||||
if (scrollRE < 0) {
|
||||
putEvent(EVT_ROTARY_LEFT);
|
||||
}
|
||||
else {
|
||||
putEvent(EVT_ROTARY_RIGHT);
|
||||
}
|
||||
uint32_t delay = get_tmr10ms() - lastTick;
|
||||
lastTick = get_tmr10ms();
|
||||
if (delay < ROTENC_DELAY_HIGHSPEED)
|
||||
rotencSpeed = ROTENC_HIGHSPEED;
|
||||
else if (delay < ROTENC_DELAY_MIDSPEED)
|
||||
rotencSpeed = ROTENC_MIDSPEED;
|
||||
else
|
||||
rotencSpeed = ROTENC_LOWSPEED;
|
||||
}
|
||||
|
||||
in = readTrims();
|
||||
for (i = 1; i <= 1 << (TRM_LAST-TRM_BASE); i <<= 1) {
|
||||
keys[index++].input(in & i);
|
||||
|
||||
@@ -98,11 +98,9 @@ void OpenTxSimulator::start(QByteArray & ee, bool tests)
|
||||
|
||||
void OpenTxSimulator::start(const char * filename, bool tests)
|
||||
{
|
||||
#if ROTARY_ENCODERS > 0
|
||||
g_rotenc[0] = 0;
|
||||
#endif
|
||||
#if ROTARY_ENCODERS > 1
|
||||
g_rotenc[1] = 0;
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
for (int i=0; i<DIM(rotencValue); i++)
|
||||
rotencValue[i] = 0;
|
||||
#endif
|
||||
|
||||
StartEepromThread(filename);
|
||||
@@ -157,20 +155,8 @@ void OpenTxSimulator::getTrims(Trims & trims)
|
||||
|
||||
void OpenTxSimulator::wheelEvent(int steps)
|
||||
{
|
||||
#if defined(PCBHORUS) || defined(PCBFLAMENCO)
|
||||
if (steps > 0)
|
||||
rotencValue -= 2;
|
||||
else
|
||||
rotencValue += 2;
|
||||
#elif defined(PCBX9E)
|
||||
if (steps == 255)
|
||||
rotencValue -= 2;
|
||||
else
|
||||
rotencValue += 2;
|
||||
#elif defined(PCBSKY9X) && ROTARY_ENCODERS > 0
|
||||
g_rotenc[0] += steps*4;
|
||||
#elif defined(PCBGRUVIN9X)
|
||||
g_rotenc[0] += steps;
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
ROTARY_ENCODER_NAVIGATION_VALUE += steps * ROTARY_ENCODER_GRANULARITY;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ void simuSetKey(uint8_t key, bool state)
|
||||
KEY_CASE(BTN_REa, PIOB->PIO_PDSR, 0x40)
|
||||
#elif defined(PCBGRUVIN9X) || defined(PCBMEGA2560)
|
||||
KEY_CASE(BTN_REa, pind, 0x20)
|
||||
#elif defined(ROTARY_ENCODER_NAVIGATION)
|
||||
#elif defined(PCB9X) && defined(ROTARY_ENCODER_NAVIGATION)
|
||||
KEY_CASE(BTN_REa, RotEncoder, 0x20)
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ else()
|
||||
set(FLAVOUR sky9x)
|
||||
option(PCBREV "PCB Revision" REVC)
|
||||
set(TARGET_SRC ${TARGET_SRC} coproc_driver.cpp rotenc_driver.cpp rtc_driver.cpp)
|
||||
add_definitions(-DROTARY_ENCODERS=1)
|
||||
set(BOOTLOADER bootflash4.lbm)
|
||||
if(PCBREV STREQUAL REVA)
|
||||
add_definitions(-DDREVA)
|
||||
|
||||
@@ -35,6 +35,18 @@ extern uint16_t ResetReason;
|
||||
void boardInit(void);
|
||||
#define boardOff() pwrOff()
|
||||
|
||||
// Rotary Encoder driver
|
||||
void rotencInit();
|
||||
void rotencEnd();
|
||||
|
||||
#if !defined(REVX) && !defined(AR9X)
|
||||
#define ROTARY_ENCODERS 1
|
||||
#define ROTARY_ENCODER_NAVIGATION
|
||||
#define REA_DOWN() (!(PIOB->PIO_PDSR & 0x40))
|
||||
#else
|
||||
#define REA_DOWN() (0)
|
||||
#endif
|
||||
|
||||
// Keys driver
|
||||
#define NUM_SWITCHES 7
|
||||
enum EnumKeys
|
||||
@@ -58,13 +70,10 @@ enum EnumKeys
|
||||
TRM_RH_UP,
|
||||
TRM_LAST = TRM_RH_UP,
|
||||
|
||||
#if ROTARY_ENCODERS > 0 || defined(ROTARY_ENCODER_NAVIGATION)
|
||||
#if defined(ROTARY_ENCODERS)
|
||||
BTN_REa,
|
||||
#endif
|
||||
#if ROTARY_ENCODERS > 0
|
||||
BTN_REb,
|
||||
#endif
|
||||
|
||||
|
||||
NUM_KEYS
|
||||
};
|
||||
|
||||
@@ -359,16 +368,6 @@ void eepromBlockErase(uint32_t address);
|
||||
void eepromStartRead(uint8_t * buffer, size_t address, size_t size);
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size);
|
||||
|
||||
// Rotary Encoder driver
|
||||
void rotencInit();
|
||||
void rotencEnd();
|
||||
|
||||
#if ROTARY_ENCODERS > 0
|
||||
#define REA_DOWN() (!(PIOB->PIO_PDSR & 0x40))
|
||||
#else
|
||||
#define REA_DOWN() (0)
|
||||
#endif
|
||||
|
||||
// Debug driver
|
||||
void debugPutc(const char c);
|
||||
|
||||
|
||||
@@ -93,13 +93,12 @@ void interrupt5ms()
|
||||
HAPTIC_HEARTBEAT();
|
||||
#endif
|
||||
|
||||
if ( ++pre_scale >= 2 ) {
|
||||
if (++pre_scale >= 2) {
|
||||
pre_scale = 0 ;
|
||||
per10ms();
|
||||
}
|
||||
|
||||
#if defined(PCBX9E) || defined(PCBX7D)
|
||||
// TODO define ROTARY_ENCODER
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
checkRotaryEncoder();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -316,9 +316,7 @@ uint32_t readTrims(void);
|
||||
|
||||
#if defined(PCBX9E) || defined(PCBX7D)
|
||||
// Rotary Encoder driver
|
||||
extern int32_t rotencValue;
|
||||
void rotencInit(void);
|
||||
void rotencEnd(void);
|
||||
#define ROTARY_ENCODER_NAVIGATION
|
||||
void checkRotaryEncoder(void);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -18,45 +18,32 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "board.h"
|
||||
#include "lcd.h"
|
||||
#include "storage/eeprom_rlc.h"
|
||||
#include "pwr.h"
|
||||
#include "keys.h"
|
||||
#include "sdcard.h"
|
||||
#include "FatFs/ff.h"
|
||||
#include "FatFs/diskio.h"
|
||||
#include "translations/en.h"
|
||||
#include "opentx.h"
|
||||
#include "stamp.h"
|
||||
#include "strhelpers.h"
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
#define BOOTLOADER_TITLE " Taranis BootLoader - " VERSION
|
||||
#if defined(PCBX9E)
|
||||
#define BOOT_KEY_UP KEY_MINUS
|
||||
#define BOOT_KEY_DOWN KEY_PLUS
|
||||
#else
|
||||
#define BOOT_KEY_UP KEY_PLUS
|
||||
#define BOOT_KEY_DOWN KEY_MINUS
|
||||
#endif
|
||||
#define BOOT_KEY_LEFT KEY_MENU
|
||||
#define BOOT_KEY_RIGHT KEY_PAGE
|
||||
#define BOOT_KEY_MENU KEY_ENTER
|
||||
#define BOOT_KEY_EXIT KEY_EXIT
|
||||
#define DISPLAY_CHAR_WIDTH 35
|
||||
#elif defined(PCBSKY9X)
|
||||
#define BOOTLOADER_TITLE "Sky9x Boot Loader - " VERSION
|
||||
#define BOOTLOADER_TITLE " Taranis BootLoader - " VERSION
|
||||
#if defined(PCBX9E)
|
||||
#define BOOT_KEY_UP KEY_MINUS
|
||||
#define BOOT_KEY_DOWN KEY_PLUS
|
||||
#else
|
||||
#define BOOT_KEY_UP KEY_PLUS
|
||||
#define BOOT_KEY_DOWN KEY_MINUS
|
||||
#endif
|
||||
#define BOOT_KEY_LEFT KEY_MENU
|
||||
#define BOOT_KEY_RIGHT KEY_PAGE
|
||||
#define BOOT_KEY_MENU KEY_ENTER
|
||||
#define BOOT_KEY_EXIT KEY_EXIT
|
||||
#define DISPLAY_CHAR_WIDTH 35
|
||||
|
||||
const uint8_t bootloaderVersion[] __attribute__ ((section(".version"), used)) =
|
||||
{
|
||||
'B', 'O', 'O', 'T', '1', '0'
|
||||
};
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
volatile rotenc_t rotencValue[1] = {0};
|
||||
#endif
|
||||
|
||||
// states
|
||||
enum BootLoaderStates {
|
||||
ST_START,
|
||||
@@ -100,13 +87,8 @@ FILINFO Finfo;
|
||||
|
||||
TCHAR Filenames[20][50];
|
||||
uint32_t FileSize[20];
|
||||
uint32_t FnStartIndex;
|
||||
uint32_t Valid;
|
||||
|
||||
uint32_t FlashSize;
|
||||
|
||||
uint32_t LockBits;
|
||||
|
||||
uint32_t Block_buffer[1024];
|
||||
UINT BlockCount;
|
||||
|
||||
@@ -114,21 +96,6 @@ uint32_t memoryType;
|
||||
|
||||
uint32_t unlocked = 0;
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
extern int32_t EblockAddress;
|
||||
#endif
|
||||
|
||||
extern uint32_t EepromBlocked;
|
||||
|
||||
void init_spi(void);
|
||||
void writeBlock(void);
|
||||
void usbPluggedIn();
|
||||
|
||||
#if defined(PCBX9E)
|
||||
typedef int32_t rotenc_t;
|
||||
extern rotenc_t rotencValue;
|
||||
#endif
|
||||
|
||||
void interrupt10ms(void)
|
||||
{
|
||||
Tenms |= 1; // 10 mS has passed
|
||||
@@ -141,10 +108,10 @@ void interrupt10ms(void)
|
||||
++index;
|
||||
}
|
||||
|
||||
#if defined(PCBX9E)
|
||||
#if defined(PCBX9E) || defined(PCBX7D)
|
||||
checkRotaryEncoder();
|
||||
static rotenc_t rePreviousValue;
|
||||
rotenc_t reNewValue = (rotencValue / 2);
|
||||
rotenc_t reNewValue = (rotencValue[0] / 2);
|
||||
int8_t scrollRE = reNewValue - rePreviousValue;
|
||||
if (scrollRE) {
|
||||
rePreviousValue = reNewValue;
|
||||
@@ -278,7 +245,7 @@ uint32_t isValidBufferStart(const void * buffer)
|
||||
return isEepromStart(buffer);
|
||||
}
|
||||
|
||||
int menuFlashFile(uint32_t index, uint8_t event)
|
||||
int menuFlashFile(uint32_t index, event_t event)
|
||||
{
|
||||
FRESULT fr;
|
||||
|
||||
@@ -401,7 +368,7 @@ int main()
|
||||
lcdDrawTextAlignedLeft(0, BOOTLOADER_TITLE);
|
||||
lcdInvertLine(0);
|
||||
|
||||
uint8_t event = getEvent();
|
||||
event_t event = getEvent();
|
||||
|
||||
if (state != ST_USB) {
|
||||
if (usbPlugged()) {
|
||||
@@ -450,9 +417,6 @@ int main()
|
||||
}
|
||||
state = ST_START;
|
||||
}
|
||||
#if defined(PCBSKY9X)
|
||||
usbMassStorage();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (state == ST_FLASH_MENU || state == ST_RESTORE_MENU) {
|
||||
|
||||
@@ -58,10 +58,12 @@
|
||||
#define ENC_GPIO GPIOD
|
||||
#define ENC_GPIO_PIN_A GPIO_Pin_12 // PD.12
|
||||
#define ENC_GPIO_PIN_B GPIO_Pin_13 // PD.13
|
||||
#define ROTARY_ENCODER_POSITION() (ENC_GPIO->IDR >> 12) & 0x03
|
||||
#elif defined(PCBX7D)
|
||||
#define ENC_GPIO GPIOE
|
||||
#define ENC_GPIO_PIN_A GPIO_Pin_9 // PE.09
|
||||
#define ENC_GPIO_PIN_B GPIO_Pin_11 // PE.11
|
||||
#define ROTARY_ENCODER_POSITION() (((ENC_GPIO->IDR >> 10) & 0x02) + ((ENC_GPIO->IDR >> 9) & 0x01))
|
||||
#endif
|
||||
|
||||
// This is for SIMU: reuse rotary encoder pins to map UP and DOWN keyboard keys
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
uint32_t rotencPosition;
|
||||
#endif
|
||||
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
@@ -33,7 +37,7 @@ uint32_t readKeys()
|
||||
if (~KEYS_GPIO_REG_EXIT & KEYS_GPIO_PIN_EXIT)
|
||||
result |= 1 << KEY_EXIT;
|
||||
|
||||
#if (!defined(PCBX9E) && !defined(PCBX7D)) || defined(SIMU)
|
||||
#if !defined(PCBX9E) && !defined(PCBX7D)
|
||||
if (~KEYS_GPIO_REG_PLUS & KEYS_GPIO_PIN_PLUS)
|
||||
result |= 1 << KEY_PLUS;
|
||||
if (~KEYS_GPIO_REG_MINUS & KEYS_GPIO_PIN_MINUS)
|
||||
@@ -81,29 +85,18 @@ uint8_t keyDown()
|
||||
return readKeys();
|
||||
}
|
||||
|
||||
#if defined(PCBX9E) || defined(PCBX7D)
|
||||
uint32_t Rotary_position;
|
||||
rotenc_t rotencValue;
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
void checkRotaryEncoder()
|
||||
{
|
||||
register uint32_t dummy = ENC_GPIO->IDR; // Read Rotary encoder
|
||||
|
||||
// TODO quick & dirty!
|
||||
#if defined(PCBX9E)
|
||||
dummy >>= 12;
|
||||
dummy &= 0x03;
|
||||
#else
|
||||
dummy = ((dummy >> 11) & 0x01) + ((dummy >> 8) & 0x02);
|
||||
#endif
|
||||
if (dummy != (Rotary_position & 0x03)) {
|
||||
if ((Rotary_position & 0x01) ^ ((dummy & 0x02) >> 1)) {
|
||||
--rotencValue;
|
||||
register uint32_t newpos = ROTARY_ENCODER_POSITION();
|
||||
if (newpos != rotencPosition) {
|
||||
if ((rotencPosition & 0x01) ^ ((newpos & 0x02) >> 1)) {
|
||||
--rotencValue[0];
|
||||
}
|
||||
else {
|
||||
++rotencValue;
|
||||
++rotencValue[0];
|
||||
}
|
||||
Rotary_position &= ~0x03 ;
|
||||
Rotary_position |= dummy ;
|
||||
rotencPosition = newpos;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -117,40 +110,6 @@ void readKeysAndTrims()
|
||||
keys[index++].input(in & i);
|
||||
}
|
||||
|
||||
#if (defined(PCBX9E) || defined(PCBX7D)) && !defined(SIMU)
|
||||
#define X9E_RE_TIMEOUT 5
|
||||
static rotenc_t rePreviousValue;
|
||||
rotenc_t reNewValue = (rotencValue / 2);
|
||||
static int timeout = X9E_RE_TIMEOUT;
|
||||
static int lastkey = 0;
|
||||
int8_t scrollRE = reNewValue - rePreviousValue;
|
||||
if (scrollRE) {
|
||||
rePreviousValue = reNewValue;
|
||||
timeout = X9E_RE_TIMEOUT;
|
||||
if (scrollRE < 0) {
|
||||
if (lastkey != KEY_MINUS) {
|
||||
putEvent(EVT_KEY_BREAK(lastkey));
|
||||
}
|
||||
putEvent(EVT_KEY_FIRST(KEY_MINUS));
|
||||
lastkey = KEY_MINUS;
|
||||
}
|
||||
else {
|
||||
if (lastkey != KEY_PLUS) {
|
||||
putEvent(EVT_KEY_BREAK(lastkey));
|
||||
}
|
||||
putEvent(EVT_KEY_FIRST(KEY_PLUS));
|
||||
lastkey = KEY_PLUS;
|
||||
}
|
||||
}
|
||||
else if (timeout > 0) {
|
||||
timeout--;
|
||||
}
|
||||
else if (lastkey && timeout == 0) {
|
||||
putEvent(EVT_KEY_BREAK(lastkey));
|
||||
lastkey = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
in = readTrims();
|
||||
for (uint8_t i = 1; i != uint8_t(1 << 8); i <<= 1) {
|
||||
keys[index++].input(in & i);
|
||||
@@ -289,4 +248,8 @@ void keysInit()
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOG_PINS;
|
||||
GPIO_Init(GPIOG, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
rotencPosition = ROTARY_ENCODER_POSITION();
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user