Add "hardware_defs" target to dump hardware defines from hal.h per target Fixed hal.h definitions for switches & ADC inputs Tools to generate hardware definitions from current hal.h generator: add support for EXTx and analog switches WiP Add generated header to hardware_defs target Add support for ADC input direction and index per GPIO port Incredible: it compiles Removed StdPeriph ADC driver Works on QX7 Works on TX16S (VBat missing) Switch driver using generated switches for stm32 targets Switch driver with generated switches for simu Use switch names from switch driver Fixed single conversion handling Fixed horus VBat reading Added switch name Fix warnings about bitfield offsets and GCC 4.4 This is caused by bitfields that cross type boundaries. In this particular case, it happens as the bitfield is not defined the same in `rtc_backup.cpp`. Switches has already been moved to generic driver Jitter measurement for each sample, not just for oversampled values Moved periph clock init to the ADC driver ADC & GPIOs. Add switchInit() to init pins Fix NV14 CMake Fix taranis target Fix NV14 (again) Model audio files: use new interface for switch index Fix X9-lite Fix simu headers Fix getSwitchName() Add support for ADC switches Fix switch warning YAML Test only switches which are defined Conversions tests for QX7 only on QX7 Fix X12S Fix function switch names Enable ADC periph clock before initialising channels NV14: offset inputs for the sticks & fix switches WiP: get rid of VSRCRAW and some more Simu shall use normal ADC driver fix x7 fix nv14 Fix 9x nav fix 212x64 fix xlite fix x9e fix simu lib fix unit tests fix x7 tests PWM stick values should be written directly into adcValues ... just like FlySky sticks. fix x12s fix nv14 Add some support for SPI ADC (only unit tests) Remove `jq` usage fix generate_yaml.py for newer libclang fix pot config fix stick names Some YAML generator improvements Max 16 Pots on COLORLCD Fix some source names Use 10 bits for switches to prevent overflow Removed horus constants for switches & ADC inputs Fix unit tests Fix curve edit Fix libsimulator Fix function switches (tpro) Refine ADC & analog API Moved hardware definitions scripts and templates into own dir cleanup API refine Fix unit tests Mixer: apply calibration only on required inputs Place ADC switches after all other ADC inputs Fix X12S Remove useless TR_POTS_VSRCRAW, TR_SW_VSRCRAW, and TR_VSRCRAW Cleanup redundant generated YAML parsers Fixes Boxer rebase Add boxer to generate-hw-defs.sh Obsolete LUA exports Add boxer ADC_DIRECTION Split generate_hw_defs.py into multiple files Some cleanup (+ LUA switches) Fix AXIS definitions Fixed translation strings declarations Some rebase fixes Remove some useless StdPeriph drivers fix: set pin mode to reset state on usart deinit fix: use canonical names for calibration data fix: ADC driver does not care about unconfigured inputs fix X12S ADC Add support for ADC conversion chaining Better X12S ADC implem Moved X12S ADC driver to HAL/LL Improve ADC driver separation Fixed taranis & nv14 Moved PWM gimbals to HAL/LL Removed useless TR_EXTRA_VSRCRAW Fixed include guards Small fixes Renamed control inputs Moved internal and external module pulse driver def to boards Move more things to the generic_stm32 board Remove STR_VMIXTRIMS Added analog labels Generate main control names Misuse labels / short labels for main controls Backward compatibility: sliders and legacy names New keys driver Let's get rid of StdPeriph headers in simu Add jinja2 to CI workflows Use `grep` instead of `sed` chore: add python jinja2 oto msys setup script Removed more static definitions and use dynamic ones instead Fixes X9E Fix x7 nav too 212 switch display Fix default sliders Removed NUM_STICKS 212 switch display working nicely Surface radio 'stick' replacements fix: switch, trim & rotary pin init Remove old key drivers Removed VKEYS Removed ETX_FOURCC Fixed SURFACE_NAME Removed TR_VSWITCHES & TR_TRIMS_SWITCHES Fix xpot switches Store calibrated analogs in physical order Use getSourceString in drawSource Implement missing YAML read/write Fix isSourceAvailableInInputs() Fix isSourceAvailable() Some surface fixes Fix CLI debug Ported colour UI of analog diagnostics to new ADC API Small fixes Better input mapping Minor tpro fixes Fix trims available Remove TX mode choice on surface radio Rename surface controls Channel order alignement Fix throttle warning Fix checkTrims() Fix pot config casting issue Fix IS_SWITCH_FS() Fixed input mapping Fix fswitch auto-switch Fixed storing / reading function switches in YAML Fix enableVBatBridge() / disableVBatBridge() Fix interesting mode conversion Fix sources issues Fix special funnction list Proper function switch handling 128 GUI improvements Fix compilation Boxer cosmetics 128 hardware screen cosmetic Fix TX12 switches More switches fixes Simplify CPU type handling Fix flash size Fixed page-up / page-down in libopenui
198 lines
5.7 KiB
C++
198 lines
5.7 KiB
C++
/*
|
|
* Copyright (C) EdgeTX
|
|
*
|
|
* Based on code named
|
|
* opentx - https://github.com/opentx/opentx
|
|
* th9x - http://code.google.com/p/th9x
|
|
* er9x - http://code.google.com/p/er9x
|
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
|
*
|
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#ifndef _KEYS_H_
|
|
#define _KEYS_H_
|
|
|
|
#include <inttypes.h>
|
|
#include "opentx_types.h"
|
|
#include "libopenui/src/libopenui_types.h"
|
|
|
|
#include "hal/key_driver.h"
|
|
|
|
constexpr event_t EVT_REFRESH = 0x1000;
|
|
constexpr event_t EVT_ENTRY = 0x1001;
|
|
constexpr event_t EVT_ENTRY_UP = 0x1002;
|
|
constexpr event_t EVT_ROTARY_LEFT = 0x1003;
|
|
constexpr event_t EVT_ROTARY_RIGHT = 0x1004;
|
|
|
|
#if defined(COLORLCD)
|
|
constexpr event_t _MSK_KEY_BREAK = 0x0200;
|
|
constexpr event_t _MSK_KEY_REPT = 0x0400;
|
|
constexpr event_t _MSK_KEY_FIRST = 0x0600;
|
|
constexpr event_t _MSK_KEY_LONG = 0x0800;
|
|
constexpr event_t _MSK_KEY_FLAGS = 0x0E00;
|
|
#else
|
|
constexpr event_t _MSK_KEY_BREAK = 0x0020;
|
|
constexpr event_t _MSK_KEY_REPT = 0x0040;
|
|
constexpr event_t _MSK_KEY_FIRST = 0x0060;
|
|
constexpr event_t _MSK_KEY_LONG = 0x0080;
|
|
constexpr event_t _MSK_KEY_FLAGS = 0x00E0;
|
|
#endif
|
|
|
|
#if defined(COLORLCD)
|
|
constexpr event_t _MSK_VIRTUAL_KEY = 0x2000;
|
|
|
|
constexpr event_t EVT_VIRTUAL_KEY(uint8_t key)
|
|
{
|
|
return (key | _MSK_VIRTUAL_KEY);
|
|
}
|
|
|
|
constexpr event_t EVT_VIRTUAL_KEY_MIN = EVT_VIRTUAL_KEY('m');
|
|
constexpr event_t EVT_VIRTUAL_KEY_MAX = EVT_VIRTUAL_KEY('M');
|
|
constexpr event_t EVT_VIRTUAL_KEY_PLUS = EVT_VIRTUAL_KEY('+');
|
|
constexpr event_t EVT_VIRTUAL_KEY_MINUS = EVT_VIRTUAL_KEY('-');
|
|
constexpr event_t EVT_VIRTUAL_KEY_FORWARD = EVT_VIRTUAL_KEY('F');
|
|
constexpr event_t EVT_VIRTUAL_KEY_BACKWARD = EVT_VIRTUAL_KEY('B');
|
|
constexpr event_t EVT_VIRTUAL_KEY_DEFAULT = EVT_VIRTUAL_KEY('0');
|
|
constexpr event_t EVT_VIRTUAL_KEY_UP = EVT_VIRTUAL_KEY('U');
|
|
constexpr event_t EVT_VIRTUAL_KEY_DOWN = EVT_VIRTUAL_KEY('D');
|
|
constexpr event_t EVT_VIRTUAL_KEY_LEFT = EVT_VIRTUAL_KEY('L');
|
|
constexpr event_t EVT_VIRTUAL_KEY_RIGHT = EVT_VIRTUAL_KEY('R');
|
|
constexpr event_t EVT_VIRTUAL_KEY_NEXT = EVT_VIRTUAL_KEY('N');
|
|
constexpr event_t EVT_VIRTUAL_KEY_PREVIOUS = EVT_VIRTUAL_KEY('P');
|
|
constexpr event_t EVT_VIRTUAL_KEY_SIGN = EVT_VIRTUAL_KEY(177);
|
|
|
|
constexpr bool IS_VIRTUAL_KEY_EVENT(event_t event)
|
|
{
|
|
return (event & 0xF000) == _MSK_VIRTUAL_KEY;
|
|
}
|
|
|
|
// Touch events for Lua widgets - assuming _MSK_KEY_* for PCBHORUS
|
|
constexpr event_t EVT_TOUCH = EVT_VIRTUAL_KEY('t');
|
|
constexpr event_t EVT_TOUCH_FIRST = EVT_TOUCH | _MSK_KEY_FIRST;
|
|
constexpr event_t EVT_TOUCH_BREAK = EVT_TOUCH | _MSK_KEY_BREAK;
|
|
constexpr event_t EVT_TOUCH_SLIDE = EVT_TOUCH | _MSK_KEY_LONG;
|
|
constexpr event_t EVT_TOUCH_TAP = EVT_TOUCH | _MSK_KEY_REPT;
|
|
|
|
constexpr bool IS_TOUCH_EVENT(event_t event)
|
|
{
|
|
return (event & ~_MSK_KEY_FLAGS) == EVT_TOUCH;
|
|
}
|
|
#endif
|
|
|
|
// normal order of events is: FIRST, LONG, REPEAT, REPEAT, ..., BREAK
|
|
#define EVT_KEY_MASK(e) ((e) & 0x1F)
|
|
|
|
constexpr event_t EVT_KEY_FIRST(uint8_t key)
|
|
{
|
|
return (key | _MSK_KEY_FIRST); // fired when key is pressed
|
|
}
|
|
|
|
constexpr event_t EVT_KEY_REPT(uint8_t key)
|
|
{
|
|
return (key | _MSK_KEY_REPT); // fired when key is held pressed long enough, fires multiple times with increasing speed
|
|
}
|
|
|
|
constexpr event_t EVT_KEY_LONG(uint8_t key)
|
|
{
|
|
return (key | _MSK_KEY_LONG); // fired when key is held pressed for a while
|
|
}
|
|
|
|
constexpr event_t EVT_KEY_BREAK(uint8_t key)
|
|
{
|
|
return (key | _MSK_KEY_BREAK); // fired when key is released (short or long), but only if the event was not killed
|
|
}
|
|
|
|
constexpr bool IS_KEY_EVENT(event_t event)
|
|
{
|
|
return (event & 0xF000) == 0; // fired when key is released (short or long), but only if the event was not killed
|
|
}
|
|
|
|
// constexpr bool IS_TRIM_EVENT(event_t event)
|
|
// {
|
|
// return (IS_KEY_EVENT(event) && EVT_KEY_MASK(event) >= TRM_BASE);
|
|
// }
|
|
|
|
inline bool IS_KEY_FIRST(event_t evt)
|
|
{
|
|
return (evt & _MSK_KEY_FLAGS) == _MSK_KEY_FIRST;
|
|
}
|
|
|
|
inline bool IS_KEY_REPT(event_t evt)
|
|
{
|
|
return (evt & _MSK_KEY_FLAGS) == _MSK_KEY_REPT;
|
|
}
|
|
|
|
inline bool IS_KEY_LONG(event_t evt)
|
|
{
|
|
return (evt & _MSK_KEY_FLAGS) == _MSK_KEY_LONG;
|
|
}
|
|
|
|
inline bool IS_KEY_BREAK(event_t evt)
|
|
{
|
|
return (evt & _MSK_KEY_FLAGS) == _MSK_KEY_BREAK;
|
|
}
|
|
|
|
inline bool IS_KEY_EVT(event_t evt, uint8_t key)
|
|
{
|
|
return (evt & _MSK_KEY_FLAGS) && (EVT_KEY_MASK(evt) == key);
|
|
}
|
|
|
|
inline bool IS_NEXT_EVENT(event_t evt)
|
|
{
|
|
return evt == EVT_KEY_FIRST(KEY_DOWN) || evt == EVT_KEY_REPT(KEY_DOWN) ||
|
|
evt == EVT_KEY_FIRST(KEY_MINUS) || evt == EVT_KEY_REPT(KEY_MINUS) ||
|
|
evt == EVT_ROTARY_RIGHT;
|
|
}
|
|
|
|
inline bool IS_PREVIOUS_EVENT(event_t evt)
|
|
{
|
|
return evt == EVT_KEY_FIRST(KEY_UP) || evt == EVT_KEY_REPT(KEY_UP) ||
|
|
evt == EVT_KEY_FIRST(KEY_PLUS) || evt == EVT_KEY_REPT(KEY_PLUS) ||
|
|
evt == EVT_ROTARY_LEFT;
|
|
}
|
|
|
|
void pushEvent(event_t evt);
|
|
event_t getEvent();
|
|
|
|
void pauseEvents(event_t event);
|
|
void killEvents(event_t event);
|
|
void killAllEvents();
|
|
bool waitKeysReleased();
|
|
bool isEvent();
|
|
bool keyDown();
|
|
|
|
event_t getTrimEvent();
|
|
void pauseTrimEvents(event_t event);
|
|
void killTrimEvents(event_t event);
|
|
|
|
uint8_t keysGetState(uint8_t key);
|
|
uint8_t keysGetTrimState(uint8_t trim);
|
|
|
|
bool keysPollingCycle();
|
|
bool rotaryEncoderPollingCycle();
|
|
|
|
#if defined(USE_TRIMS_AS_BUTTONS)
|
|
void setTrimsAsButtons(bool val);
|
|
bool getTrimsAsButtons();
|
|
#endif
|
|
|
|
struct InactivityData
|
|
{
|
|
uint16_t counter;
|
|
uint8_t sum;
|
|
};
|
|
|
|
extern InactivityData inactivity;
|
|
|
|
#endif // _KEYS_H_
|