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
+91
-37
@@ -22,38 +22,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "opentx_types.h"
|
||||
|
||||
// TODO: move this to the targets
|
||||
#if NUM_PWMSTICKS > 0
|
||||
#define FIRST_ANALOG_ADC (STICKS_PWM_ENABLED() ? NUM_PWMSTICKS : 0)
|
||||
#define NUM_ANALOGS_ADC (STICKS_PWM_ENABLED() ? (NUM_ANALOGS - NUM_PWMSTICKS) : NUM_ANALOGS)
|
||||
#elif defined(PCBX9E)
|
||||
#define FIRST_ANALOG_ADC 0
|
||||
#define NUM_ANALOGS_ADC 11
|
||||
#define NUM_ANALOGS_ADC_EXT (NUM_ANALOGS - NUM_ANALOGS_ADC)
|
||||
#else
|
||||
#define FIRST_ANALOG_ADC_FS 4
|
||||
#if defined (RADIO_BOXER)
|
||||
#define NUM_ANALOGS_ADC_FS 5
|
||||
#else
|
||||
#define NUM_ANALOGS_ADC_FS 10
|
||||
#define NUM_ANALOGS_ADC_EXT 2
|
||||
#endif
|
||||
#define FIRST_ANALOG_ADC 0
|
||||
#define NUM_ANALOGS_ADC NUM_ANALOGS
|
||||
#endif
|
||||
// 12-bit values
|
||||
#define ADC_MAX_VALUE 4095
|
||||
|
||||
#define ADCMAXVALUE 4095
|
||||
#define ADC_INVERT_VALUE(v) (ADC_MAX_VALUE - (v))
|
||||
|
||||
// TODO: get rid of this special case
|
||||
#if defined(PCBX10) || defined(PCBX12S)
|
||||
extern uint16_t rtcBatteryVoltage;
|
||||
#endif
|
||||
// tune this value, bigger value - more filtering (range: 1-5) (see explanation below)
|
||||
#define JITTER_FILTER_STRENGTH 4
|
||||
// tune this value, bigger value - more filtering (range: 0-1) (see explanation below)
|
||||
#define ANALOG_SCALE 1
|
||||
#define JITTER_ALPHA (1<<JITTER_FILTER_STRENGTH)
|
||||
|
||||
enum {
|
||||
ADC_INPUT_MAIN=0, // gimbals / wheel + throttle
|
||||
ADC_INPUT_POT,
|
||||
ADC_INPUT_AXIS,
|
||||
ADC_INPUT_VBAT,
|
||||
ADC_INPUT_RTC_BAT,
|
||||
ADC_INPUT_ALL,
|
||||
};
|
||||
|
||||
// Air radios
|
||||
enum {
|
||||
ADC_MAIN_LH,
|
||||
ADC_MAIN_LV,
|
||||
ADC_MAIN_RV,
|
||||
ADC_MAIN_RH,
|
||||
};
|
||||
|
||||
// Surface radios
|
||||
enum {
|
||||
ADC_MAIN_ST,
|
||||
ADC_MAIN_TH,
|
||||
};
|
||||
|
||||
struct etx_hal_adc_input_t {
|
||||
const char* name;
|
||||
const char* label;
|
||||
const char* short_label;
|
||||
};
|
||||
|
||||
struct etx_hal_adc_inputs_t {
|
||||
uint8_t n_inputs;
|
||||
uint8_t offset;
|
||||
const etx_hal_adc_input_t* inputs;
|
||||
};
|
||||
|
||||
struct etx_hal_adc_driver_t {
|
||||
|
||||
const etx_hal_adc_inputs_t* inputs; // ADC_INPUT_ALL + 1;
|
||||
potconfig_t default_pots_cfg;
|
||||
|
||||
bool (*init)();
|
||||
bool (*start_conversion)();
|
||||
void (*wait_completion)();
|
||||
void (*wait_completion)();
|
||||
};
|
||||
|
||||
bool adcInit(const etx_hal_adc_driver_t* driver);
|
||||
@@ -63,22 +87,52 @@ bool adcRead();
|
||||
uint16_t getBatteryVoltage();
|
||||
uint16_t getRTCBatteryVoltage();
|
||||
uint16_t getAnalogValue(uint8_t index);
|
||||
void setAnalogValue(uint8_t index, uint16_t value);
|
||||
uint16_t* getAnalogValues();
|
||||
|
||||
#define JITTER_FILTER_STRENGTH 4 // tune this value, bigger value - more filtering (range: 1-5) (see explanation below)
|
||||
#define ANALOG_SCALE 1 // tune this value, bigger value - more filtering (range: 0-1) (see explanation below)
|
||||
#define JITTER_ALPHA (1<<JITTER_FILTER_STRENGTH)
|
||||
// Run calibration steps
|
||||
void adcCalibMinMax();
|
||||
void adcCalibSetMidPoint();
|
||||
void adcCalibSetMinMax();
|
||||
void adcCalibSetXPot();
|
||||
void adcCalibStore();
|
||||
|
||||
#if defined(JITTER_MEASURE)
|
||||
extern JitterMeter<uint16_t> rawJitter[NUM_ANALOGS];
|
||||
extern JitterMeter<uint16_t> avgJitter[NUM_ANALOGS];
|
||||
#if defined(PCBHORUS) || defined(PCBTARANIS)
|
||||
#define JITTER_MEASURE_ACTIVE() (menuHandlers[menuLevel] == menuRadioDiagAnalogs)
|
||||
#elif defined(CLI)
|
||||
#define JITTER_MEASURE_ACTIVE() (1)
|
||||
#else
|
||||
#define JITTER_MEASURE_ACTIVE() (0)
|
||||
#endif
|
||||
extern JitterMeter<uint16_t> rawJitter[MAX_ANALOG_INPUTS];
|
||||
extern JitterMeter<uint16_t> avgJitter[MAX_ANALOG_INPUTS];
|
||||
#endif
|
||||
|
||||
void getADC();
|
||||
uint16_t anaIn(uint8_t chan);
|
||||
uint32_t anaIn_diag(uint8_t chan);
|
||||
uint16_t getBatteryVoltage();
|
||||
|
||||
// Warning:
|
||||
// STM32 uses a 25K+25K voltage divider bridge to measure the battery voltage
|
||||
// Measuring VBAT puts considerable drain (22 µA) on the battery instead of
|
||||
// normal drain (~10 nA)
|
||||
void enableVBatBridge();
|
||||
void disableVBatBridge();
|
||||
bool isVBatBridgeEnabled();
|
||||
|
||||
potconfig_t adcGetDefaultPotsConfig();
|
||||
|
||||
uint8_t adcGetMaxInputs(uint8_t type);
|
||||
uint8_t adcGetInputOffset(uint8_t type);
|
||||
|
||||
uint16_t adcGetInputValue(uint8_t type, uint8_t idx);
|
||||
const char* adcGetInputName(uint8_t type, uint8_t idx);
|
||||
|
||||
const char* adcGetInputName(uint8_t idx);
|
||||
int adcGetInputIdx(const char* input, uint8_t len);
|
||||
|
||||
const char* adcGetInputLabel(uint8_t type, uint8_t idx);
|
||||
const char* adcGetInputShortLabel(uint8_t type, uint8_t idx);
|
||||
|
||||
// To be implemented by the target driver
|
||||
// int8_t adcGetVRTC();
|
||||
// int8_t adcGetVBAT();
|
||||
// const char* adcGetStickName(uint8_t idx);
|
||||
// const char* adcGetPotName(uint8_t idx);
|
||||
// uint8_t adcGetMaxSticks();
|
||||
// uint8_t adcGetMaxPots();
|
||||
|
||||
Reference in New Issue
Block a user