[X9E/X7D] Rotary encoder navigation speed implemented (#3724)

This commit is contained in:
Bertrand Songis
2016-08-27 18:19:44 +02:00
committed by Andre Bernet
parent 3cb64d984a
commit 1d735f2bd3
114 changed files with 785 additions and 865 deletions
+2 -3
View File
@@ -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
}
+1 -3
View File
@@ -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
+21 -57
View File
@@ -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) {
+2
View File
@@ -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
+16 -53
View File
@@ -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
}