refact: ADC, switches and keys
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
This commit is contained in:
committed by
Malte Langermann
parent
b6dd3a0ef8
commit
2b100e0eb5
@@ -41,19 +41,11 @@
|
||||
|
||||
PACK(typedef struct {
|
||||
uint8_t pcbrev:2;
|
||||
uint8_t sticksPwmDisabled:1;
|
||||
uint8_t pxx2Enabled:1;
|
||||
}) HardwareOptions;
|
||||
|
||||
extern HardwareOptions hardwareOptions;
|
||||
|
||||
#if !defined(LUA_EXPORT_GENERATION)
|
||||
#include "stm32f4xx_sdio.h"
|
||||
#include "stm32f4xx_dma2d.h"
|
||||
#include "stm32f4xx_ltdc.h"
|
||||
#include "stm32f4xx_fmc.h"
|
||||
#endif
|
||||
|
||||
#define FLASHSIZE 0x200000
|
||||
#define BOOTLOADER_SIZE 0x20000
|
||||
#define FIRMWARE_ADDRESS 0x08000000
|
||||
@@ -178,255 +170,13 @@ void SDRAM_Init();
|
||||
#define IS_PXX1_INTERNAL_ENABLED() (true)
|
||||
#endif
|
||||
|
||||
// Keys driver
|
||||
enum EnumKeys
|
||||
{
|
||||
KEY_PGUP,
|
||||
KEY_PGDN,
|
||||
KEY_ENTER,
|
||||
KEY_MODEL,
|
||||
KEY_UP = KEY_MODEL,
|
||||
KEY_EXIT,
|
||||
KEY_DOWN = KEY_EXIT,
|
||||
KEY_TELEM,
|
||||
KEY_RIGHT = KEY_TELEM,
|
||||
KEY_RADIO,
|
||||
KEY_LEFT = KEY_RADIO,
|
||||
|
||||
TRM_BASE,
|
||||
TRM_LH_DWN = TRM_BASE,
|
||||
TRM_LH_UP,
|
||||
TRM_LV_DWN,
|
||||
TRM_LV_UP,
|
||||
TRM_RV_DWN,
|
||||
TRM_RV_UP,
|
||||
TRM_RH_DWN,
|
||||
TRM_RH_UP,
|
||||
TRM_LS_DWN,
|
||||
TRM_LS_UP,
|
||||
TRM_RS_DWN,
|
||||
TRM_RS_UP,
|
||||
TRM_LAST = TRM_RS_UP,
|
||||
|
||||
NUM_KEYS
|
||||
};
|
||||
|
||||
#define IS_SHIFT_KEY(index) (false)
|
||||
#define IS_SHIFT_PRESSED() (false)
|
||||
|
||||
enum EnumSwitches
|
||||
{
|
||||
SW_SA,
|
||||
SW_SB,
|
||||
SW_SC,
|
||||
SW_SD,
|
||||
SW_SE,
|
||||
SW_SF,
|
||||
SW_SG,
|
||||
SW_SH,
|
||||
SW_SI,
|
||||
SW_SJ,
|
||||
NUM_SWITCHES
|
||||
};
|
||||
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define IS_3POS(x) ((x) != SW_SF && (x) != SW_SH)
|
||||
|
||||
enum EnumSwitchesPositions
|
||||
{
|
||||
SW_SA0,
|
||||
SW_SA1,
|
||||
SW_SA2,
|
||||
SW_SB0,
|
||||
SW_SB1,
|
||||
SW_SB2,
|
||||
SW_SC0,
|
||||
SW_SC1,
|
||||
SW_SC2,
|
||||
SW_SD0,
|
||||
SW_SD1,
|
||||
SW_SD2,
|
||||
SW_SE0,
|
||||
SW_SE1,
|
||||
SW_SE2,
|
||||
SW_SF0,
|
||||
SW_SF1,
|
||||
SW_SF2,
|
||||
SW_SG0,
|
||||
SW_SG1,
|
||||
SW_SG2,
|
||||
SW_SH0,
|
||||
SW_SH1,
|
||||
SW_SH2,
|
||||
SW_SI0,
|
||||
SW_SI1,
|
||||
SW_SI2,
|
||||
SW_SJ0,
|
||||
SW_SJ1,
|
||||
SW_SJ2,
|
||||
NUM_SWITCHES_POSITIONS
|
||||
};
|
||||
|
||||
#define STORAGE_NUM_SWITCHES_POSITIONS (STORAGE_NUM_SWITCHES * 3)
|
||||
|
||||
#if !defined(NUM_FUNCTIONS_SWITCHES)
|
||||
#define NUM_FUNCTIONS_SWITCHES 0
|
||||
#endif
|
||||
|
||||
void keysInit();
|
||||
uint32_t switchState(uint8_t index);
|
||||
uint32_t readKeys();
|
||||
#define KEYS_PRESSED() (readKeys())
|
||||
#define DBLKEYS_PRESSED_RGT_LFT(in) ((in & ((1<<KEY_RIGHT) + (1<<KEY_LEFT))) == ((1<<KEY_RIGHT) + (1<<KEY_LEFT)))
|
||||
#define DBLKEYS_PRESSED_UP_DWN(in) ((in & ((1<<KEY_UP) + (1<<KEY_DOWN))) == ((1<<KEY_UP) + (1<<KEY_DOWN)))
|
||||
#define DBLKEYS_PRESSED_RGT_UP(in) ((in & ((1<<KEY_RIGHT) + (1<<KEY_UP))) == ((1<<KEY_RIGHT) + (1<<KEY_UP)))
|
||||
#define DBLKEYS_PRESSED_LFT_DWN(in) ((in & ((1<<KEY_LEFT) + (1<<KEY_DOWN))) == ((1<<KEY_LEFT) + (1<<KEY_DOWN)))
|
||||
|
||||
// Trims driver
|
||||
#define NUM_TRIMS 6
|
||||
#define NUM_TRIMS_KEYS (NUM_TRIMS * 2)
|
||||
uint32_t readTrims();
|
||||
#define TRIMS_PRESSED() (readTrims())
|
||||
|
||||
// Rotary encoder driver
|
||||
void rotaryEncoderInit();
|
||||
void rotaryEncoderCheck();
|
||||
|
||||
// ADC driver
|
||||
|
||||
#if defined(PCBX10)
|
||||
#define NUM_POTS 7
|
||||
#define STORAGE_NUM_POTS 7
|
||||
#else
|
||||
#define NUM_POTS 3
|
||||
#define STORAGE_NUM_POTS 5
|
||||
#endif
|
||||
|
||||
#define NUM_XPOTS NUM_POTS
|
||||
|
||||
#if defined(PCBX10)
|
||||
#define NUM_SLIDERS 2
|
||||
#if defined(RADIO_TX16S) || defined(RADIO_T18) || defined(RADIO_T16)
|
||||
#define NUM_PWMSTICKS 0
|
||||
#else
|
||||
#define NUM_PWMSTICKS 4
|
||||
#endif
|
||||
#else
|
||||
#define NUM_SLIDERS 4
|
||||
#define NUM_PWMSTICKS 0
|
||||
#endif
|
||||
|
||||
#define STORAGE_NUM_SLIDERS 4
|
||||
|
||||
|
||||
enum Analogs {
|
||||
STICK1,
|
||||
STICK2,
|
||||
STICK3,
|
||||
STICK4,
|
||||
POT_FIRST,
|
||||
POT1 = POT_FIRST,
|
||||
POT2,
|
||||
POT3,
|
||||
#if defined(PCBX10)
|
||||
EXT1,
|
||||
EXT2,
|
||||
EXT3,
|
||||
EXT4,
|
||||
#endif
|
||||
POT_LAST = POT_FIRST + NUM_POTS - 1,
|
||||
SLIDER_FIRST,
|
||||
SLIDER_FRONT_LEFT = SLIDER_FIRST,
|
||||
SLIDER_FRONT_RIGHT,
|
||||
#if defined(PCBX12S)
|
||||
SLIDER_REAR_LEFT,
|
||||
SLIDER_REAR_RIGHT,
|
||||
#endif
|
||||
SLIDER_LAST = SLIDER_FIRST + NUM_SLIDERS - 1,
|
||||
TX_VOLTAGE,
|
||||
#if defined(PCBX12S)
|
||||
MOUSE1, // after voltage because previous ones come from SPI on X12S
|
||||
MOUSE2,
|
||||
#endif
|
||||
NUM_ANALOGS
|
||||
};
|
||||
|
||||
#if defined(PCBX12S)
|
||||
#define EXT1 SLIDER_FRONT_LEFT
|
||||
#define EXT2 SLIDER_FRONT_RIGHT
|
||||
#endif
|
||||
|
||||
#define SLIDER1 SLIDER_FRONT_LEFT
|
||||
#define SLIDER2 SLIDER_FRONT_RIGHT
|
||||
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 14) + (SWITCH_3POS << 12) + (SWITCH_2POS << 10) + (SWITCH_3POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
|
||||
#if defined(RADIO_FAMILY_T16)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 4) + (POT_MULTIPOS_SWITCH << 2) + (POT_WITH_DETENT << 0)
|
||||
#else
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 4) + (POT_MULTIPOS_SWITCH << 2) + (POT_WITHOUT_DETENT << 0)
|
||||
#endif
|
||||
|
||||
#if defined(PCBX12S)
|
||||
#define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 3) + (SLIDER_WITH_DETENT << 2) + (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
|
||||
#else
|
||||
#define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
|
||||
#endif
|
||||
|
||||
#define HARDWARE_POT3
|
||||
#if !defined(PCBX12S) // ext are used by mouse on X12S
|
||||
#define HARDWARE_EXT1
|
||||
#define HARDWARE_EXT2
|
||||
#define HARDWARE_EXT3
|
||||
#define HARDWARE_EXT4
|
||||
#endif
|
||||
|
||||
enum CalibratedAnalogs {
|
||||
CALIBRATED_STICK1,
|
||||
CALIBRATED_STICK2,
|
||||
CALIBRATED_STICK3,
|
||||
CALIBRATED_STICK4,
|
||||
CALIBRATED_POT1,
|
||||
CALIBRATED_POT2,
|
||||
CALIBRATED_POT3,
|
||||
#if defined(PCBX12S)
|
||||
CALIBRATED_SLIDER_FRONT_LEFT,
|
||||
CALIBRATED_POT_EXT1 = CALIBRATED_SLIDER_FRONT_LEFT,
|
||||
CALIBRATED_SLIDER_FRONT_RIGHT,
|
||||
CALIBRATED_POT_EXT2 = CALIBRATED_SLIDER_FRONT_RIGHT,
|
||||
CALIBRATED_SLIDER_REAR_LEFT,
|
||||
CALIBRATED_SLIDER_REAR_RIGHT,
|
||||
#else
|
||||
CALIBRATED_POT_EXT1,
|
||||
CALIBRATED_POT_EXT2,
|
||||
CALIBRATED_POT_EXT3,
|
||||
CALIBRATED_POT_EXT4,
|
||||
CALIBRATED_SLIDER_REAR_LEFT,
|
||||
CALIBRATED_SLIDER_REAR_RIGHT,
|
||||
#endif
|
||||
CALIBRATED_MOUSE1,
|
||||
CALIBRATED_MOUSE2,
|
||||
NUM_CALIBRATED_ANALOGS
|
||||
};
|
||||
|
||||
#define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT_LAST)
|
||||
#define IS_SLIDER(x) ((x)>=SLIDER_FIRST && (x)<=SLIDER_LAST)
|
||||
extern uint16_t adcValues[NUM_ANALOGS];
|
||||
|
||||
#if defined(PCBX12S)
|
||||
#define NUM_MOUSE_ANALOGS 2
|
||||
#else
|
||||
#define NUM_MOUSE_ANALOGS 0
|
||||
#endif
|
||||
#define STORAGE_NUM_MOUSE_ANALOGS 2
|
||||
|
||||
#if NUM_PWMSTICKS > 0
|
||||
#define STICKS_PWM_ENABLED() (!hardwareOptions.sticksPwmDisabled)
|
||||
void sticksPwmInit();
|
||||
void sticksPwmRead(uint16_t * values);
|
||||
extern volatile uint32_t pwm_interrupt_count;
|
||||
#else
|
||||
#define STICKS_PWM_ENABLED() (false)
|
||||
#endif
|
||||
|
||||
// Battery driver
|
||||
#if defined(PCBX10)
|
||||
@@ -441,34 +191,8 @@ extern volatile uint32_t pwm_interrupt_count;
|
||||
#define BATTERY_MAX 115 // 11.5V
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
enum PowerReason {
|
||||
SHUTDOWN_REQUEST = 0xDEADBEEF,
|
||||
SOFTRESET_REQUEST = 0xCAFEDEAD,
|
||||
};
|
||||
|
||||
constexpr uint32_t POWER_REASON_SIGNATURE = 0x0178746F;
|
||||
|
||||
inline bool UNEXPECTED_SHUTDOWN()
|
||||
{
|
||||
#if defined(SIMU) || defined(NO_UNEXPECTED_SHUTDOWN)
|
||||
return false;
|
||||
#else
|
||||
if (WAS_RESET_BY_WATCHDOG())
|
||||
return true;
|
||||
else if (WAS_RESET_BY_SOFTWARE())
|
||||
return RTC->BKP0R != SOFTRESET_REQUEST;
|
||||
else
|
||||
return RTC->BKP1R == POWER_REASON_SIGNATURE && RTC->BKP0R != SHUTDOWN_REQUEST;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void SET_POWER_REASON(uint32_t value)
|
||||
{
|
||||
RTC->BKP0R = value;
|
||||
RTC->BKP1R = POWER_REASON_SIGNATURE;
|
||||
}
|
||||
#endif
|
||||
bool UNEXPECTED_SHUTDOWN();
|
||||
void SET_POWER_REASON(uint32_t value);
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
extern "C" {
|
||||
@@ -482,6 +206,7 @@ void pwrOn();
|
||||
void pwrOff();
|
||||
void pwrResetHandler();
|
||||
bool pwrPressed();
|
||||
bool pwrOffPressed();
|
||||
#if defined(PWR_EXTRA_SWITCH_GPIO)
|
||||
bool pwrForcePressed();
|
||||
#else
|
||||
@@ -630,8 +355,6 @@ void hapticDone();
|
||||
void hapticOff();
|
||||
void hapticOn(uint32_t pwmPercent);
|
||||
|
||||
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||
|
||||
// BT driver
|
||||
#define BT_TX_FIFO_SIZE 64
|
||||
#define BT_RX_FIFO_SIZE 256
|
||||
|
||||
Reference in New Issue
Block a user