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
@@ -57,7 +57,7 @@ if (PCB STREQUAL X10)
|
||||
add_definitions(-DSOFTWARE_VOLUME)
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
targets/common/arm/stm32/stm32_hal_adc.cpp
|
||||
targets/common/arm/stm32/stm32_adc.cpp
|
||||
targets/common/arm/stm32/audio_dac_driver.cpp
|
||||
)
|
||||
if (NOT PCBREV STREQUAL TX16S)
|
||||
@@ -69,7 +69,6 @@ if (PCB STREQUAL X10)
|
||||
set(BITMAPS_TARGET x10_bitmaps)
|
||||
set(FONTS_TARGET x10_fonts)
|
||||
set(LCD_DRIVER lcd_driver.cpp)
|
||||
set(LUA_EXPORT lua_export_x10)
|
||||
if (PCBREV STREQUAL EXPRESS)
|
||||
set(FLAVOUR x10express)
|
||||
set(DEFAULT_INTERNAL_MODULE ISRM_PXX2 CACHE STRING "Default internal module")
|
||||
@@ -80,7 +79,6 @@ if (PCB STREQUAL X10)
|
||||
add_definitions(-DMANUFACTURER_FRSKY)
|
||||
elseif (PCBREV STREQUAL T16)
|
||||
set(FLAVOUR t16)
|
||||
set(LUA_EXPORT lua_export_t16)
|
||||
add_definitions(-DRADIO_T16)
|
||||
add_definitions(-DRADIO_FAMILY_T16)
|
||||
set(DEFAULT_INTERNAL_MODULE MULTIMODULE CACHE STRING "Default internal module")
|
||||
@@ -95,7 +93,6 @@ if (PCB STREQUAL X10)
|
||||
set(FLYSKY_GIMBAL ON)
|
||||
elseif (PCBREV STREQUAL TX16S)
|
||||
set(FLAVOUR tx16s)
|
||||
set(LUA_EXPORT lua_export_t16)
|
||||
add_definitions(-DRADIO_TX16S)
|
||||
add_definitions(-DRADIO_FAMILY_T16)
|
||||
set(DEFAULT_INTERNAL_MODULE MULTIMODULE CACHE STRING "Default internal module")
|
||||
@@ -113,7 +110,6 @@ if (PCB STREQUAL X10)
|
||||
set(FLYSKY_GIMBAL ON)
|
||||
elseif (PCBREV STREQUAL T18)
|
||||
set(FLAVOUR t18)
|
||||
set(LUA_EXPORT lua_export_t16)
|
||||
add_definitions(-DRADIO_T18)
|
||||
add_definitions(-DRADIO_FAMILY_T16)
|
||||
set(DEFAULT_INTERNAL_MODULE MULTIMODULE CACHE STRING "Default internal module")
|
||||
@@ -151,12 +147,10 @@ elseif (PCB STREQUAL X12S)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
audio_spi_driver.cpp
|
||||
x12s_adc_driver.cpp
|
||||
)
|
||||
set(BITMAPS_TARGET x12s_bitmaps)
|
||||
set(FONTS_TARGET x12s_fonts)
|
||||
set(LCD_DRIVER lcd_driver.cpp)
|
||||
set(LUA_EXPORT lua_export_x12s)
|
||||
add_definitions(-DMANUFACTURER_FRSKY)
|
||||
endif()
|
||||
|
||||
@@ -269,20 +263,15 @@ set(FIRMWARE_TARGET_SRC
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
hal/adc_driver.cpp
|
||||
boards/generic_stm32/module_ports.cpp
|
||||
boards/generic_stm32/aux_ports.cpp
|
||||
boards/generic_stm32/sport_update.cpp
|
||||
boards/generic_stm32/intmodule_heartbeat.cpp
|
||||
targets/common/arm/stm32/stm32_exti_driver.cpp
|
||||
targets/common/arm/stm32/mixer_scheduler_driver.cpp
|
||||
targets/common/arm/stm32/timers_driver.cpp
|
||||
targets/common/arm/stm32/extmodule_driver.cpp
|
||||
targets/common/arm/stm32/stm32_pulse_driver.cpp
|
||||
targets/common/arm/stm32/stm32_usart_driver.cpp
|
||||
targets/common/arm/stm32/rotary_encoder_driver.cpp
|
||||
targets/common/arm/stm32/pwr_driver.cpp
|
||||
targets/common/arm/stm32/heartbeat_driver.cpp
|
||||
targets/common/arm/stm32/trainer_driver.cpp
|
||||
targets/common/arm/stm32/ads79xx.cpp
|
||||
targets/common/arm/stm32/sdio_sd.c
|
||||
)
|
||||
|
||||
|
||||
@@ -19,12 +19,15 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/trainer_driver.h"
|
||||
#include "hal/switch_driver.h"
|
||||
#include "hal/rotary_encoder.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "boards/generic_stm32/module_ports.h"
|
||||
#include "boards/generic_stm32/intmodule_heartbeat.h"
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/trainer_driver.h"
|
||||
#include "boards/generic_stm32/analog_inputs.h"
|
||||
|
||||
#include "timers_driver.h"
|
||||
#include "dataconstants.h"
|
||||
@@ -35,18 +38,41 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(PCBX12S)
|
||||
#include "stm32_hal_adc.h"
|
||||
#define ADC_DRIVER stm32_hal_adc_driver
|
||||
#else
|
||||
#include "x12s_adc_driver.h"
|
||||
#define ADC_DRIVER x12s_adc_driver
|
||||
#if defined(PWM_STICKS)
|
||||
#include "sticks_pwm_driver.h"
|
||||
#endif
|
||||
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
#if defined(RADIO_FAMILY_T16) || defined(PCBNV14)
|
||||
#include "flysky_gimbal_driver.h"
|
||||
#endif
|
||||
|
||||
enum PowerReason {
|
||||
SHUTDOWN_REQUEST = 0xDEADBEEF,
|
||||
SOFTRESET_REQUEST = 0xCAFEDEAD,
|
||||
};
|
||||
|
||||
constexpr uint32_t POWER_REASON_SIGNATURE = 0x0178746F;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void SET_POWER_REASON(uint32_t value)
|
||||
{
|
||||
RTC->BKP0R = value;
|
||||
RTC->BKP1R = POWER_REASON_SIGNATURE;
|
||||
}
|
||||
|
||||
HardwareOptions hardwareOptions;
|
||||
bool boardBacklightOn = false;
|
||||
|
||||
@@ -75,7 +101,7 @@ void boardInit()
|
||||
AUDIO_RCC_AHB1Periph |
|
||||
KEYS_RCC_AHB1Periph |
|
||||
ADC_RCC_AHB1Periph |
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
#if defined(RADIO_FAMILY_T16)
|
||||
FLYSKY_HALL_RCC_AHB1Periph |
|
||||
#endif
|
||||
AUX_SERIAL_RCC_AHB1Periph |
|
||||
@@ -95,7 +121,7 @@ void boardInit()
|
||||
ADC_RCC_APB1Periph |
|
||||
TIMER_2MHz_RCC_APB1Periph |
|
||||
AUDIO_RCC_APB1Periph |
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
#if defined(RADIO_FAMILY_T16)
|
||||
FLYSKY_HALL_RCC_APB1Periph |
|
||||
#endif
|
||||
TELEMETRY_RCC_APB1Periph |
|
||||
@@ -148,23 +174,18 @@ void boardInit()
|
||||
audioInit();
|
||||
|
||||
keysInit();
|
||||
switchInit();
|
||||
rotaryEncoderInit();
|
||||
|
||||
#if NUM_PWMSTICKS > 0
|
||||
sticksPwmInit();
|
||||
delay_ms(20);
|
||||
if (pwm_interrupt_count < 32) {
|
||||
hardwareOptions.sticksPwmDisabled = true;
|
||||
}
|
||||
#if defined(PWM_STICKS)
|
||||
sticksPwmDetect();
|
||||
#endif
|
||||
|
||||
#if defined(RADIO_FAMILY_T16)
|
||||
flysky_gimbal_init();
|
||||
#endif
|
||||
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
globalData.flyskygimbals = flysky_gimbal_init();
|
||||
#else
|
||||
globalData.flyskygimbals = false;
|
||||
#endif
|
||||
|
||||
if (!adcInit(&ADC_DRIVER))
|
||||
if (!adcInit(&_adc_driver))
|
||||
TRACE("adcInit failed");
|
||||
|
||||
init2MhzTimer();
|
||||
@@ -197,8 +218,11 @@ void boardInit()
|
||||
}
|
||||
#endif
|
||||
|
||||
extern void rtcDisableBackupReg();
|
||||
|
||||
void boardOff()
|
||||
{
|
||||
ledOff();
|
||||
backlightEnable(0);
|
||||
|
||||
while (pwrPressed()) {
|
||||
@@ -222,11 +246,7 @@ void boardOff()
|
||||
// Shutdown the Haptic
|
||||
hapticDone();
|
||||
|
||||
#if defined(RTC_BACKUP_RAM)
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, DISABLE);
|
||||
PWR_BackupRegulatorCmd(DISABLE);
|
||||
#endif
|
||||
|
||||
rtcDisableBackupReg();
|
||||
RTC->BKP0R = SHUTDOWN_REQUEST;
|
||||
|
||||
pwrOff();
|
||||
|
||||
@@ -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
|
||||
|
||||
+238
-188
@@ -33,48 +33,48 @@
|
||||
// Keys
|
||||
#define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI | RCC_AHB1Periph_GPIOJ)
|
||||
#if defined(PCBX12S)
|
||||
#define KEYS_GPIO_REG_PGUP GPIOC->IDR
|
||||
#define KEYS_GPIO_PIN_PGUP GPIO_Pin_13 // PC.13
|
||||
#define KEYS_GPIO_REG_PGDN GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_PGDN GPIO_Pin_8 // PI.08
|
||||
#define KEYS_GPIO_REG_LEFT GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_LEFT GPIO_Pin_7 // PI.07
|
||||
#define KEYS_GPIO_REG_ENTER GPIOC->IDR
|
||||
#define KEYS_GPIO_PIN_ENTER GPIO_Pin_1 // PC.01
|
||||
#define KEYS_GPIO_REG_UP GPIOG->IDR
|
||||
#define KEYS_GPIO_PIN_UP GPIO_Pin_13 // PG.13
|
||||
#define KEYS_GPIO_REG_DOWN GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_DOWN GPIO_Pin_6 // PI.06
|
||||
#define KEYS_GPIO_REG_RIGHT GPIOC->IDR
|
||||
#define KEYS_GPIO_PIN_RIGHT GPIO_Pin_4 // PC.04
|
||||
#define KEYS_GPIO_REG_PGUP GPIOC
|
||||
#define KEYS_GPIO_PIN_PGUP LL_GPIO_PIN_13 // PC.13
|
||||
#define KEYS_GPIO_REG_PGDN GPIOI
|
||||
#define KEYS_GPIO_PIN_PGDN LL_GPIO_PIN_8 // PI.08
|
||||
#define KEYS_GPIO_REG_SYS GPIOI
|
||||
#define KEYS_GPIO_PIN_SYS LL_GPIO_PIN_7 // PI.07
|
||||
#define KEYS_GPIO_REG_ENTER GPIOC
|
||||
#define KEYS_GPIO_PIN_ENTER LL_GPIO_PIN_1 // PC.01
|
||||
#define KEYS_GPIO_REG_MDL GPIOG
|
||||
#define KEYS_GPIO_PIN_MDL LL_GPIO_PIN_13 // PG.13
|
||||
#define KEYS_GPIO_REG_EXIT GPIOI
|
||||
#define KEYS_GPIO_PIN_EXIT LL_GPIO_PIN_6 // PI.06
|
||||
#define KEYS_GPIO_REG_TELE GPIOC
|
||||
#define KEYS_GPIO_PIN_TELE LL_GPIO_PIN_4 // PC.04
|
||||
#elif defined(RADIO_TX16S)
|
||||
#define KEYS_GPIO_REG_ENTER GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_ENTER GPIO_Pin_8 // PI.08
|
||||
#define KEYS_GPIO_REG_PGUP GPIOC->IDR
|
||||
#define KEYS_GPIO_PIN_PGUP GPIO_Pin_13 // PC.13
|
||||
#define KEYS_GPIO_REG_PGDN GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_PGDN GPIO_Pin_11 // PI.11
|
||||
#define KEYS_GPIO_REG_UP GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_UP GPIO_Pin_6 // PI.06
|
||||
#define KEYS_GPIO_REG_DOWN GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_DOWN GPIO_Pin_4 // PI.04
|
||||
#define KEYS_GPIO_REG_LEFT GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_LEFT GPIO_Pin_7 // PI.07
|
||||
#define KEYS_GPIO_REG_RIGHT GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_RIGHT GPIO_Pin_5 // PI.05
|
||||
#define KEYS_GPIO_REG_ENTER GPIOI
|
||||
#define KEYS_GPIO_PIN_ENTER LL_GPIO_PIN_8 // PI.08
|
||||
#define KEYS_GPIO_REG_PGUP GPIOC
|
||||
#define KEYS_GPIO_PIN_PGUP LL_GPIO_PIN_13 // PC.13
|
||||
#define KEYS_GPIO_REG_PGDN GPIOI
|
||||
#define KEYS_GPIO_PIN_PGDN LL_GPIO_PIN_11 // PI.11
|
||||
#define KEYS_GPIO_REG_MDL GPIOI
|
||||
#define KEYS_GPIO_PIN_MDL LL_GPIO_PIN_6 // PI.06
|
||||
#define KEYS_GPIO_REG_EXIT GPIOI
|
||||
#define KEYS_GPIO_PIN_EXIT LL_GPIO_PIN_4 // PI.04
|
||||
#define KEYS_GPIO_REG_SYS GPIOI
|
||||
#define KEYS_GPIO_PIN_SYS LL_GPIO_PIN_7 // PI.07
|
||||
#define KEYS_GPIO_REG_TELE GPIOI
|
||||
#define KEYS_GPIO_PIN_TELE LL_GPIO_PIN_5 // PI.05
|
||||
#elif defined(PCBX10)
|
||||
#define KEYS_GPIO_REG_ENTER GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_ENTER GPIO_Pin_8 // PI.08
|
||||
#define KEYS_GPIO_REG_PGDN GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_PGDN GPIO_Pin_11 // PI.11
|
||||
#define KEYS_GPIO_REG_UP GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_UP GPIO_Pin_4 // PI.04
|
||||
#define KEYS_GPIO_REG_DOWN GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_DOWN GPIO_Pin_6 // PI.06
|
||||
#define KEYS_GPIO_REG_LEFT GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_LEFT GPIO_Pin_7 // PI.07
|
||||
#define KEYS_GPIO_REG_RIGHT GPIOI->IDR
|
||||
#define KEYS_GPIO_PIN_RIGHT GPIO_Pin_5 // PI.05
|
||||
#define KEYS_GPIO_REG_ENTER GPIOI
|
||||
#define KEYS_GPIO_PIN_ENTER LL_GPIO_PIN_8 // PI.08
|
||||
#define KEYS_GPIO_REG_PGDN GPIOI
|
||||
#define KEYS_GPIO_PIN_PGDN LL_GPIO_PIN_11 // PI.11
|
||||
#define KEYS_GPIO_REG_MDL GPIOI
|
||||
#define KEYS_GPIO_PIN_MDL LL_GPIO_PIN_4 // PI.04
|
||||
#define KEYS_GPIO_REG_EXIT GPIOI
|
||||
#define KEYS_GPIO_PIN_EXIT LL_GPIO_PIN_6 // PI.06
|
||||
#define KEYS_GPIO_REG_SYS GPIOI
|
||||
#define KEYS_GPIO_PIN_SYS LL_GPIO_PIN_7 // PI.07
|
||||
#define KEYS_GPIO_REG_TELE GPIOI
|
||||
#define KEYS_GPIO_PIN_TELE LL_GPIO_PIN_5 // PI.05
|
||||
#endif
|
||||
|
||||
// Rotary Encoder
|
||||
@@ -103,138 +103,146 @@
|
||||
// Switches
|
||||
#define STORAGE_SWITCH_A
|
||||
#define HARDWARE_SWITCH_A
|
||||
#define SWITCHES_GPIO_REG_A_H GPIOH->IDR
|
||||
#define SWITCHES_GPIO_PIN_A_H GPIO_Pin_9 // PH.09
|
||||
#define SWITCHES_GPIO_REG_A_L GPIOI->IDR
|
||||
#define SWITCHES_GPIO_PIN_A_L GPIO_Pin_15 // PI.15
|
||||
#define SWITCHES_GPIO_REG_A_H GPIOH
|
||||
#define SWITCHES_GPIO_PIN_A_H LL_GPIO_PIN_9 // PH.09
|
||||
#define SWITCHES_GPIO_REG_A_L GPIOI
|
||||
#define SWITCHES_GPIO_PIN_A_L LL_GPIO_PIN_15 // PI.15
|
||||
#define STORAGE_SWITCH_B
|
||||
#define HARDWARE_SWITCH_B
|
||||
#define SWITCHES_GPIO_REG_B_H GPIOH->IDR
|
||||
#define SWITCHES_GPIO_PIN_B_H GPIO_Pin_12 // PH.12
|
||||
#define SWITCHES_GPIO_REG_B_L GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_B_L GPIO_Pin_12 // PB.12
|
||||
#define SWITCHES_GPIO_REG_B_H GPIOH
|
||||
#define SWITCHES_GPIO_PIN_B_H LL_GPIO_PIN_12 // PH.12
|
||||
#define SWITCHES_GPIO_REG_B_L GPIOB
|
||||
#define SWITCHES_GPIO_PIN_B_L LL_GPIO_PIN_12 // PB.12
|
||||
#define STORAGE_SWITCH_C
|
||||
#define HARDWARE_SWITCH_C
|
||||
#define SWITCHES_GPIO_REG_C_H GPIOD->IDR
|
||||
#define SWITCHES_GPIO_PIN_C_H GPIO_Pin_11 // PD.11
|
||||
#define SWITCHES_GPIO_REG_C_L GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_C_L GPIO_Pin_15 // PB.15
|
||||
#define SWITCHES_GPIO_REG_C_H GPIOD
|
||||
#define SWITCHES_GPIO_PIN_C_H LL_GPIO_PIN_11 // PD.11
|
||||
#define SWITCHES_GPIO_REG_C_L GPIOB
|
||||
#define SWITCHES_GPIO_PIN_C_L LL_GPIO_PIN_15 // PB.15
|
||||
#define STORAGE_SWITCH_D
|
||||
#define HARDWARE_SWITCH_D
|
||||
#define SWITCHES_GPIO_REG_D_H GPIOJ->IDR
|
||||
#define SWITCHES_GPIO_PIN_D_H GPIO_Pin_7 // PJ.07
|
||||
#define SWITCHES_GPIO_REG_D_L GPIOG->IDR
|
||||
#define SWITCHES_GPIO_PIN_D_L GPIO_Pin_2 // PG.02
|
||||
#define SWITCHES_GPIO_REG_D_H GPIOJ
|
||||
#define SWITCHES_GPIO_PIN_D_H LL_GPIO_PIN_7 // PJ.07
|
||||
#define SWITCHES_GPIO_REG_D_L GPIOG
|
||||
#define SWITCHES_GPIO_PIN_D_L LL_GPIO_PIN_2 // PG.02
|
||||
#define STORAGE_SWITCH_E
|
||||
#define HARDWARE_SWITCH_E
|
||||
#define SWITCHES_GPIO_REG_E_H GPIOH->IDR
|
||||
#define SWITCHES_GPIO_PIN_E_H GPIO_Pin_4 // PH.04
|
||||
#define SWITCHES_GPIO_REG_E_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_E_L GPIO_Pin_3 // PE.03
|
||||
#define SWITCHES_GPIO_REG_E_H GPIOH
|
||||
#define SWITCHES_GPIO_PIN_E_H LL_GPIO_PIN_4 // PH.04
|
||||
#define SWITCHES_GPIO_REG_E_L GPIOE
|
||||
#define SWITCHES_GPIO_PIN_E_L LL_GPIO_PIN_3 // PE.03
|
||||
#define STORAGE_SWITCH_F
|
||||
#define HARDWARE_SWITCH_F
|
||||
#define SWITCHES_GPIO_REG_F GPIOH->IDR
|
||||
#define SWITCHES_GPIO_PIN_F GPIO_Pin_3 // PH.03
|
||||
#define SWITCHES_GPIO_REG_F GPIOH
|
||||
#define SWITCHES_GPIO_PIN_F LL_GPIO_PIN_3 // PH.03
|
||||
#define STORAGE_SWITCH_G
|
||||
#define HARDWARE_SWITCH_G
|
||||
#define SWITCHES_GPIO_REG_G_H GPIOG->IDR
|
||||
#define SWITCHES_GPIO_PIN_G_H GPIO_Pin_6 // PG.06
|
||||
#define SWITCHES_GPIO_REG_G_L GPIOG->IDR
|
||||
#define SWITCHES_GPIO_PIN_G_L GPIO_Pin_3 // PG.03
|
||||
#define SWITCHES_GPIO_REG_G_H GPIOG
|
||||
#define SWITCHES_GPIO_PIN_G_H LL_GPIO_PIN_6 // PG.06
|
||||
#define SWITCHES_GPIO_REG_G_L GPIOG
|
||||
#define SWITCHES_GPIO_PIN_G_L LL_GPIO_PIN_3 // PG.03
|
||||
#define STORAGE_SWITCH_H
|
||||
#define HARDWARE_SWITCH_H
|
||||
#define SWITCHES_GPIO_REG_H GPIOG->IDR
|
||||
#define SWITCHES_GPIO_PIN_H GPIO_Pin_7 // PG.07
|
||||
#define SWITCHES_GPIO_REG_H GPIOG
|
||||
#define SWITCHES_GPIO_PIN_H LL_GPIO_PIN_7 // PG.07
|
||||
|
||||
#if defined(PCBX12S)
|
||||
#define SWITCHES_F_INVERTED
|
||||
#elif defined(PCBX10)
|
||||
#define SWITCHES_B_INVERTED
|
||||
#define SWITCHES_D_INVERTED
|
||||
#define SWITCHES_E_INVERTED
|
||||
#endif
|
||||
|
||||
#if defined(PCBX10)
|
||||
// Gimbal switch left
|
||||
#define STORAGE_SWITCH_I
|
||||
#define HARDWARE_SWITCH_I
|
||||
#define SWITCHES_GPIO_REG_I GPIOH->IDR
|
||||
#define SWITCHES_GPIO_PIN_I GPIO_Pin_14 // PH.14
|
||||
#define SWITCHES_GPIO_REG_I GPIOH
|
||||
#define SWITCHES_GPIO_PIN_I LL_GPIO_PIN_14 // PH.14
|
||||
// Gimbal switch right
|
||||
#define STORAGE_SWITCH_J
|
||||
#define HARDWARE_SWITCH_J
|
||||
#define SWITCHES_GPIO_REG_J GPIOH->IDR
|
||||
#define SWITCHES_GPIO_PIN_J GPIO_Pin_15 // PH.15
|
||||
#define SWITCHES_GPIO_REG_J GPIOH
|
||||
#define SWITCHES_GPIO_PIN_J LL_GPIO_PIN_15 // PH.15
|
||||
#elif defined(PCBX12S)
|
||||
// Gimbal switch left
|
||||
#define STORAGE_SWITCH_I
|
||||
#define HARDWARE_SWITCH_I
|
||||
#define SWITCHES_GPIO_REG_I GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_I GPIO_Pin_1 // PB.01
|
||||
#define SWITCHES_GPIO_REG_I GPIOB
|
||||
#define SWITCHES_GPIO_PIN_I LL_GPIO_PIN_1 // PB.01
|
||||
// Gimbal switch right
|
||||
#define STORAGE_SWITCH_J
|
||||
#define HARDWARE_SWITCH_J
|
||||
#define SWITCHES_GPIO_REG_J GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_J GPIO_Pin_0 // PB.00
|
||||
#define SWITCHES_GPIO_REG_J GPIOB
|
||||
#define SWITCHES_GPIO_PIN_J LL_GPIO_PIN_0 // PB.00
|
||||
#endif
|
||||
|
||||
// Trims
|
||||
#if defined(PCBX12S)
|
||||
#define TRIMS_GPIO_REG_RHL GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_RHL GPIO_Pin_0 // PC.00
|
||||
#define TRIMS_GPIO_REG_RHR GPIOI->IDR
|
||||
#define TRIMS_GPIO_PIN_RHR GPIO_Pin_4 // PI.04
|
||||
#define TRIMS_GPIO_REG_RVD GPIOG->IDR
|
||||
#define TRIMS_GPIO_PIN_RVD GPIO_Pin_12 // PG.12
|
||||
#define TRIMS_GPIO_REG_RVU GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_RVU GPIO_Pin_14 // PJ.14
|
||||
#define TRIMS_GPIO_REG_LVD GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_LVD GPIO_Pin_13 // PJ.13
|
||||
#define TRIMS_GPIO_REG_LHL GPIOD->IDR
|
||||
#define TRIMS_GPIO_PIN_LHL GPIO_Pin_3 // PD.03
|
||||
#define TRIMS_GPIO_REG_LVU GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_LVU GPIO_Pin_12 // PJ.12
|
||||
#define TRIMS_GPIO_REG_LHR GPIOD->IDR
|
||||
#define TRIMS_GPIO_PIN_LHR GPIO_Pin_7 // PD.07
|
||||
#define TRIMS_GPIO_REG_RSD GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_RSD GPIO_Pin_8 // PJ.08
|
||||
#define TRIMS_GPIO_REG_RSU GPIOD->IDR
|
||||
#define TRIMS_GPIO_PIN_RSU GPIO_Pin_13 // PD.13
|
||||
#define TRIMS_GPIO_REG_LSD GPIOB->IDR
|
||||
#define TRIMS_GPIO_PIN_LSD GPIO_Pin_14 // PB.14
|
||||
#define TRIMS_GPIO_REG_LSU GPIOB->IDR
|
||||
#define TRIMS_GPIO_PIN_LSU GPIO_Pin_13 // PB.13
|
||||
#define TRIMS_GPIO_REG_RHL GPIOC
|
||||
#define TRIMS_GPIO_PIN_RHL LL_GPIO_PIN_0 // PC.00
|
||||
#define TRIMS_GPIO_REG_RHR GPIOI
|
||||
#define TRIMS_GPIO_PIN_RHR LL_GPIO_PIN_4 // PI.04
|
||||
#define TRIMS_GPIO_REG_RVD GPIOG
|
||||
#define TRIMS_GPIO_PIN_RVD LL_GPIO_PIN_12 // PG.12
|
||||
#define TRIMS_GPIO_REG_RVU GPIOJ
|
||||
#define TRIMS_GPIO_PIN_RVU LL_GPIO_PIN_14 // PJ.14
|
||||
#define TRIMS_GPIO_REG_LVD GPIOJ
|
||||
#define TRIMS_GPIO_PIN_LVD LL_GPIO_PIN_13 // PJ.13
|
||||
#define TRIMS_GPIO_REG_LHL GPIOD
|
||||
#define TRIMS_GPIO_PIN_LHL LL_GPIO_PIN_3 // PD.03
|
||||
#define TRIMS_GPIO_REG_LVU GPIOJ
|
||||
#define TRIMS_GPIO_PIN_LVU LL_GPIO_PIN_12 // PJ.12
|
||||
#define TRIMS_GPIO_REG_LHR GPIOD
|
||||
#define TRIMS_GPIO_PIN_LHR LL_GPIO_PIN_7 // PD.07
|
||||
#define TRIMS_GPIO_REG_RSD GPIOJ
|
||||
#define TRIMS_GPIO_PIN_RSD LL_GPIO_PIN_8 // PJ.08
|
||||
#define TRIMS_GPIO_REG_RSU GPIOD
|
||||
#define TRIMS_GPIO_PIN_RSU LL_GPIO_PIN_13 // PD.13
|
||||
#define TRIMS_GPIO_REG_LSD GPIOB
|
||||
#define TRIMS_GPIO_PIN_LSD LL_GPIO_PIN_14 // PB.14
|
||||
#define TRIMS_GPIO_REG_LSU GPIOB
|
||||
#define TRIMS_GPIO_PIN_LSU LL_GPIO_PIN_13 // PB.13
|
||||
#elif defined(PCBX10)
|
||||
#if defined(RADIO_TX16S)
|
||||
#define TRIMS_GPIO_REG_LHL GPIOA->IDR
|
||||
#define TRIMS_GPIO_PIN_LHL GPIO_Pin_6 // PA.06
|
||||
#define TRIMS_GPIO_REG_LHR GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_LHR GPIO_Pin_4 // PC.04
|
||||
#define TRIMS_GPIO_REG_LHL GPIOA
|
||||
#define TRIMS_GPIO_PIN_LHL LL_GPIO_PIN_6 // PA.06
|
||||
#define TRIMS_GPIO_REG_LHR GPIOC
|
||||
#define TRIMS_GPIO_PIN_LHR LL_GPIO_PIN_4 // PC.04
|
||||
#else
|
||||
#define TRIMS_GPIO_REG_LHL GPIOB->IDR
|
||||
#define TRIMS_GPIO_PIN_LHL GPIO_Pin_8 // PB.08
|
||||
#define TRIMS_GPIO_REG_LHR GPIOB->IDR
|
||||
#define TRIMS_GPIO_PIN_LHR GPIO_Pin_9 // PB.09
|
||||
#define TRIMS_GPIO_REG_LHL GPIOB
|
||||
#define TRIMS_GPIO_PIN_LHL LL_GPIO_PIN_8 // PB.08
|
||||
#define TRIMS_GPIO_REG_LHR GPIOB
|
||||
#define TRIMS_GPIO_PIN_LHR LL_GPIO_PIN_9 // PB.09
|
||||
#endif
|
||||
#define TRIMS_GPIO_REG_LVD GPIOG->IDR
|
||||
#define TRIMS_GPIO_PIN_LVD GPIO_Pin_12 // PG.12
|
||||
#define TRIMS_GPIO_REG_LVU GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_LVU GPIO_Pin_14 // PJ.14
|
||||
#define TRIMS_GPIO_REG_RVD GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_RVD GPIO_Pin_13 // PJ.13
|
||||
#define TRIMS_GPIO_REG_RHL GPIOD->IDR
|
||||
#define TRIMS_GPIO_PIN_RHL GPIO_Pin_3 // PD.03
|
||||
#define TRIMS_GPIO_REG_RVU GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_RVU GPIO_Pin_12 // PJ.12
|
||||
#define TRIMS_GPIO_REG_RHR GPIOD->IDR
|
||||
#define TRIMS_GPIO_PIN_RHR GPIO_Pin_7 // PD.07
|
||||
#define TRIMS_GPIO_REG_LVD GPIOG
|
||||
#define TRIMS_GPIO_PIN_LVD LL_GPIO_PIN_12 // PG.12
|
||||
#define TRIMS_GPIO_REG_LVU GPIOJ
|
||||
#define TRIMS_GPIO_PIN_LVU LL_GPIO_PIN_14 // PJ.14
|
||||
#define TRIMS_GPIO_REG_RVD GPIOJ
|
||||
#define TRIMS_GPIO_PIN_RVD LL_GPIO_PIN_13 // PJ.13
|
||||
#define TRIMS_GPIO_REG_RHL GPIOD
|
||||
#define TRIMS_GPIO_PIN_RHL LL_GPIO_PIN_3 // PD.03
|
||||
#define TRIMS_GPIO_REG_RVU GPIOJ
|
||||
#define TRIMS_GPIO_PIN_RVU LL_GPIO_PIN_12 // PJ.12
|
||||
#define TRIMS_GPIO_REG_RHR GPIOD
|
||||
#define TRIMS_GPIO_PIN_RHR LL_GPIO_PIN_7 // PD.07
|
||||
#if defined(RADIO_FAMILY_T16)
|
||||
#define TRIMS_GPIO_REG_LSU GPIOD->IDR
|
||||
#define TRIMS_GPIO_PIN_LSU GPIO_Pin_13 // PD.13
|
||||
#define TRIMS_GPIO_REG_LSD GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_LSD GPIO_Pin_8 // PJ.08
|
||||
#define TRIMS_GPIO_REG_LSU GPIOD
|
||||
#define TRIMS_GPIO_PIN_LSU LL_GPIO_PIN_13 // PD.13
|
||||
#define TRIMS_GPIO_REG_LSD GPIOJ
|
||||
#define TRIMS_GPIO_PIN_LSD LL_GPIO_PIN_8 // PJ.08
|
||||
#else
|
||||
#define TRIMS_GPIO_REG_LSU GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_LSU GPIO_Pin_8 // PJ.08
|
||||
#define TRIMS_GPIO_REG_LSD GPIOD->IDR
|
||||
#define TRIMS_GPIO_PIN_LSD GPIO_Pin_13 // PD.13
|
||||
#define TRIMS_GPIO_REG_LSU GPIOJ
|
||||
#define TRIMS_GPIO_PIN_LSU LL_GPIO_PIN_8 // PJ.08
|
||||
#define TRIMS_GPIO_REG_LSD GPIOD
|
||||
#define TRIMS_GPIO_PIN_LSD LL_GPIO_PIN_13 // PD.13
|
||||
#endif
|
||||
#define TRIMS_GPIO_REG_RSU GPIOB->IDR
|
||||
#define TRIMS_GPIO_PIN_RSU GPIO_Pin_14 // PB.14
|
||||
#define TRIMS_GPIO_REG_RSD GPIOB->IDR
|
||||
#define TRIMS_GPIO_PIN_RSD GPIO_Pin_13 // PB.13
|
||||
#define TRIMS_GPIO_REG_RSU GPIOB
|
||||
#define TRIMS_GPIO_PIN_RSU LL_GPIO_PIN_14 // PB.14
|
||||
#define TRIMS_GPIO_REG_RSD GPIOB
|
||||
#define TRIMS_GPIO_PIN_RSD LL_GPIO_PIN_13 // PB.13
|
||||
#endif
|
||||
|
||||
// Index of all keys
|
||||
@@ -269,88 +277,130 @@
|
||||
|
||||
// ADC
|
||||
#if defined(PCBX12S)
|
||||
#define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_DMA2)
|
||||
#define ADC_RCC_AHB1Periph (RCC_AHB1Periph_DMA2)
|
||||
#define ADC_RCC_APB1Periph 0
|
||||
#define ADC_RCC_APB2Periph (RCC_APB2Periph_SPI4 | RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC3)
|
||||
#define ADC_RCC_APB2Periph (RCC_APB2Periph_SPI4)
|
||||
#define ADC_SPI SPI4
|
||||
#define ADC_GPIO_AF GPIO_AF_SPI4
|
||||
#define ADC_SPI_GPIO GPIOE
|
||||
#define ADC_SPI_PIN_SCK GPIO_Pin_2 // PE.02
|
||||
#define ADC_SPI_PIN_CS GPIO_Pin_4 // PE.04
|
||||
#define ADC_SPI_PIN_MOSI GPIO_Pin_6 // PE.06
|
||||
#define ADC_SPI_PIN_MISO GPIO_Pin_5 // PE.05
|
||||
#define ADC_SPI_PinSource_SCK GPIO_PinSource2
|
||||
#define ADC_SPI_PinSource_MISO GPIO_PinSource5
|
||||
#define ADC_SPI_PinSource_MOSI GPIO_PinSource6
|
||||
#define ADC_GPIO_PIN_MOUSE1 GPIO_Pin_8 // PF.08 ADC3_IN6 J5 MOUSE_X
|
||||
#define ADC_GPIO_PIN_MOUSE2 GPIO_Pin_9 // PF.09 ADC3_IN7 J6 MOUSE_Y
|
||||
#define ADC_SPI_GPIO_AF LL_GPIO_AF_5
|
||||
#define ADC_SPI_GPIO_PIN_SCK LL_GPIO_PIN_2 // PE.02
|
||||
#define ADC_SPI_GPIO_PIN_CS LL_GPIO_PIN_4 // PE.04
|
||||
#define ADC_SPI_GPIO_PIN_MOSI LL_GPIO_PIN_6 // PE.06
|
||||
#define ADC_SPI_GPIO_PIN_MISO LL_GPIO_PIN_5 // PE.05
|
||||
|
||||
#define ADC_SPI_STICK_LH 0
|
||||
#define ADC_SPI_STICK_LV 1
|
||||
#define ADC_SPI_STICK_RV 2
|
||||
#define ADC_SPI_STICK_RH 3
|
||||
#define ADC_SPI_POT1 4
|
||||
#define ADC_SPI_POT2 5
|
||||
#define ADC_SPI_POT3 6
|
||||
#define ADC_SPI_SLIDER1 7
|
||||
#define ADC_SPI_SLIDER2 8
|
||||
#define ADC_SPI_BATT 9
|
||||
#define ADC_SPI_SLIDER3 11
|
||||
#define ADC_SPI_SLIDER4 10
|
||||
|
||||
#define ADC_MAIN ADC3
|
||||
#define ADC_GPIO_PIN_MOUSE1 LL_GPIO_PIN_8 // PF.08 ADC3_IN6 J5 MOUSE_X
|
||||
#define ADC_GPIO_PIN_MOUSE2 LL_GPIO_PIN_9 // PF.09 ADC3_IN7 J6 MOUSE_Y
|
||||
#define ADC_GPIO_MOUSE GPIOF
|
||||
#define ADC_CHANNEL_MOUSE1 6
|
||||
#define ADC_CHANNEL_MOUSE2 7
|
||||
#define ADC_GPIOF_PINS (ADC_GPIO_PIN_MOUSE1 | ADC_GPIO_PIN_MOUSE2)
|
||||
#define ADC_EXT ADC1
|
||||
#define ADC_EXT_SAMPTIME LL_ADC_SAMPLINGTIME_56CYCLES
|
||||
#define ADC_CHANNEL_RTC_BAT LL_ADC_CHANNEL_VBAT // ADC1_IN16
|
||||
#define ADC_EXT_CHANNELS { ADC_CHANNEL_RTC_BATT }
|
||||
#define ADC_DMA DMA2
|
||||
#define ADC_DMA_Stream DMA2_Stream0
|
||||
#define ADC_SAMPTIME 3
|
||||
#define ADC_VREF_PREC2 300
|
||||
#define ADC_DMA_CHANNEL LL_DMA_CHANNEL_2
|
||||
#define ADC_DMA_STREAM LL_DMA_STREAM_0
|
||||
#define ADC_DMA_STREAM_IRQ DMA2_Stream0_IRQn
|
||||
#define ADC_DMA_STREAM_IRQHandler DMA2_Stream0_IRQHandler
|
||||
#define ADC_SAMPTIME LL_ADC_SAMPLINGTIME_56CYCLES
|
||||
#define ADC_VREF_PREC2 600
|
||||
#elif defined(PCBX10)
|
||||
#define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_DMA2)
|
||||
#define ADC_RCC_AHB1Periph (RCC_AHB1Periph_DMA2)
|
||||
#define ADC_RCC_APB1Periph (RCC_APB1Periph_TIM5)
|
||||
#define ADC_RCC_APB2Periph (RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC3)
|
||||
#define ADC_GPIO_PIN_STICK_LH GPIO_Pin_0 // PA.00
|
||||
#define ADC_GPIO_PIN_STICK_LV GPIO_Pin_1 // PA.01
|
||||
#define ADC_GPIO_PIN_STICK_RH GPIO_Pin_2 // PA.02
|
||||
#define ADC_GPIO_PIN_STICK_RV GPIO_Pin_3 // PA.03
|
||||
#define ADC_GPIO_PIN_POT1 GPIO_Pin_0 // PC.00
|
||||
#define ADC_GPIO_PIN_POT2 GPIO_Pin_1 // PC.01
|
||||
#define ADC_GPIO_PIN_POT3 GPIO_Pin_2 // PC.02
|
||||
#define ADC_GPIO_PIN_SLIDER1 GPIO_Pin_6 // PF.06
|
||||
#define ADC_GPIO_PIN_SLIDER2 GPIO_Pin_3 // PC.03
|
||||
#define ADC_GPIO_PIN_BATT GPIO_Pin_7 // PF.07
|
||||
#define ADC_GPIO_PIN_EXT1 GPIO_Pin_8 // PF.08
|
||||
#define ADC_GPIO_PIN_EXT2 GPIO_Pin_9 // PF.09
|
||||
#define ADC_RCC_APB2Periph 0
|
||||
#define ADC_GPIO_PIN_STICK_LH LL_GPIO_PIN_0 // PA.00
|
||||
#define ADC_GPIO_PIN_STICK_LV LL_GPIO_PIN_1 // PA.01
|
||||
#define ADC_GPIO_PIN_STICK_RH LL_GPIO_PIN_2 // PA.02
|
||||
#define ADC_GPIO_PIN_STICK_RV LL_GPIO_PIN_3 // PA.03
|
||||
#define ADC_GPIO_PIN_POT1 LL_GPIO_PIN_0 // PC.00
|
||||
#define ADC_GPIO_PIN_POT2 LL_GPIO_PIN_1 // PC.01
|
||||
#define ADC_GPIO_PIN_POT3 LL_GPIO_PIN_2 // PC.02 //
|
||||
#define ADC_GPIO_PIN_SLIDER1 LL_GPIO_PIN_6 // PF.06
|
||||
#define ADC_GPIO_PIN_SLIDER2 LL_GPIO_PIN_3 // PC.03 //
|
||||
#define ADC_GPIO_PIN_BATT LL_GPIO_PIN_7 // PF.07
|
||||
#define ADC_GPIO_PIN_EXT1 LL_GPIO_PIN_8 // PF.08
|
||||
#define ADC_GPIO_PIN_EXT2 LL_GPIO_PIN_9 // PF.09
|
||||
#define ADC_GPIO_PIN_EXT3 ADC_GPIO_PIN_STICK_RH
|
||||
#define ADC_GPIO_PIN_EXT4 ADC_GPIO_PIN_STICK_RV
|
||||
#if !defined(RADIO_TX16S)
|
||||
#define PWM_STICKS
|
||||
#define PWM_TIMER TIM5
|
||||
#define PWM_GPIO GPIOA
|
||||
#define PWM_GPIO_AF GPIO_AF_TIM5
|
||||
#define PWM_IRQHandler TIM5_IRQHandler
|
||||
#define PWM_IRQn TIM5_IRQn
|
||||
#define PWM_GPIOA_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3)
|
||||
#define PWM_GPIOA_PINS (ADC_GPIO_PIN_STICK_LH | ADC_GPIO_PIN_STICK_LV | ADC_GPIO_PIN_STICK_RH | ADC_GPIO_PIN_STICK_RV)
|
||||
#endif
|
||||
#define ADC_GPIOA_PINS_FS (GPIO_Pin_2 | GPIO_Pin_3)
|
||||
#define ADC_GPIOA_PINS (STICKS_PWM_ENABLED() ? 0 : (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3))
|
||||
#define ADC_GPIOC_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3)
|
||||
#define ADC_GPIOF_PINS (GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9)
|
||||
#define ADC_CHANNEL_STICK_LH ADC_Channel_0 // ADC3_IN0
|
||||
#define ADC_CHANNEL_STICK_LV ADC_Channel_1 // ADC3_IN1
|
||||
#define ADC_CHANNEL_STICK_RH ADC_Channel_2 // ADC3_IN2
|
||||
#define ADC_CHANNEL_STICK_RV ADC_Channel_3 // ADC3_IN3
|
||||
#define ADC_CHANNEL_POT1 ADC_Channel_10 // ADC3_IN10
|
||||
#define ADC_CHANNEL_POT2 ADC_Channel_11 // ADC3_IN11
|
||||
#define ADC_CHANNEL_POT3 ADC_Channel_12 // ADC3_IN12
|
||||
#define ADC_CHANNEL_SLIDER1 ADC_Channel_4 // ADC3_IN4
|
||||
#define ADC_CHANNEL_SLIDER2 ADC_Channel_13 // ADC3_IN13
|
||||
#define ADC_CHANNEL_BATT ADC_Channel_5 // ADC3_IN5
|
||||
#define ADC_CHANNEL_EXT1 ADC_Channel_6 // ADC3_IN6
|
||||
#define ADC_CHANNEL_EXT2 ADC_Channel_7 // ADC3_IN7
|
||||
#define ADC_CHANNEL_EXT3 ADC_Channel_2 // ADC3_IN2: same as RH
|
||||
#define ADC_CHANNEL_EXT4 ADC_Channel_3 // ADC3_IN3: same as RV
|
||||
#define ADC_GPIOA_PINS_FS (LL_GPIO_PIN_2 | LL_GPIO_PIN_3)
|
||||
#define ADC_GPIOA_PINS (ADC_GPIO_PIN_STICK_LH | ADC_GPIO_PIN_STICK_LV | ADC_GPIO_PIN_STICK_RH | ADC_GPIO_PIN_STICK_RV)
|
||||
#define ADC_GPIOC_PINS (ADC_GPIO_PIN_POT1 | ADC_GPIO_PIN_POT2 | ADC_GPIO_PIN_POT3 | ADC_GPIO_PIN_SLIDER2)
|
||||
#define ADC_GPIOF_PINS (ADC_GPIO_PIN_SLIDER1 | ADC_GPIO_PIN_BATT | ADC_GPIO_PIN_EXT1 | ADC_GPIO_PIN_EXT2)
|
||||
#define ADC_CHANNEL_STICK_LH LL_ADC_CHANNEL_0 // ADC3_IN0
|
||||
#define ADC_CHANNEL_STICK_LV LL_ADC_CHANNEL_1 // ADC3_IN1
|
||||
#define ADC_CHANNEL_STICK_RH LL_ADC_CHANNEL_2 // ADC3_IN2
|
||||
#define ADC_CHANNEL_STICK_RV LL_ADC_CHANNEL_3 // ADC3_IN3
|
||||
#define ADC_CHANNEL_POT1 LL_ADC_CHANNEL_10 // ADC3_IN10
|
||||
#define ADC_CHANNEL_POT2 LL_ADC_CHANNEL_11 // ADC3_IN11
|
||||
#define ADC_CHANNEL_POT3 LL_ADC_CHANNEL_12 // ADC3_IN12
|
||||
#define ADC_CHANNEL_SLIDER1 LL_ADC_CHANNEL_4 // ADC3_IN4
|
||||
#define ADC_CHANNEL_SLIDER2 LL_ADC_CHANNEL_13 // ADC3_IN13
|
||||
#define ADC_CHANNEL_BATT LL_ADC_CHANNEL_5 // ADC3_IN5
|
||||
#define ADC_CHANNEL_EXT1 LL_ADC_CHANNEL_6 // ADC3_IN6
|
||||
#define ADC_CHANNEL_EXT2 LL_ADC_CHANNEL_7 // ADC3_IN7
|
||||
#define ADC_CHANNEL_EXT3 LL_ADC_CHANNEL_2 // ADC3_IN2: same as RH
|
||||
#define ADC_CHANNEL_EXT4 LL_ADC_CHANNEL_3 // ADC3_IN3: same as RV
|
||||
#define ADC_CHANNEL_RTC_BAT LL_ADC_CHANNEL_VBAT // ADC1_IN18
|
||||
#define ADC_MAIN ADC3
|
||||
#define ADC_EXT ADC1
|
||||
#define ADC_SAMPTIME 3
|
||||
#define ADC_EXT_CHANNELS { ADC_CHANNEL_RTC_BAT }
|
||||
#define ADC_EXT_SAMPTIME LL_ADC_SAMPLINGTIME_56CYCLES
|
||||
#define ADC_SAMPTIME LL_ADC_SAMPLINGTIME_56CYCLES
|
||||
#define ADC_DMA DMA2
|
||||
#define ADC_DMA_Channel DMA_Channel_2
|
||||
#define ADC_DMA_Stream DMA2_Stream0
|
||||
#define ADC_TRANSFER_COMPLETE() (ADC_DMA->LISR & DMA_LISR_TCIF0)
|
||||
#define ADC_DMA_TC_Flag DMA_FLAG_TCIF0
|
||||
#define ADC_DMA_CHANNEL LL_DMA_CHANNEL_2
|
||||
#define ADC_DMA_STREAM LL_DMA_STREAM_0
|
||||
#define ADC_DMA_STREAM_IRQ DMA2_Stream0_IRQn
|
||||
#define ADC_DMA_STREAM_IRQHandler DMA2_Stream0_IRQHandler
|
||||
|
||||
// VBat divider is /4 on F42x and F43x devices
|
||||
#if defined(RADIO_TX16S)
|
||||
#define ADC_VREF_PREC2 330
|
||||
#define ADC_VREF_PREC2 660
|
||||
#elif defined(RADIO_T16) || defined(RADIO_T18)
|
||||
#define ADC_VREF_PREC2 300
|
||||
#define ADC_VREF_PREC2 600
|
||||
#else
|
||||
#define ADC_VREF_PREC2 250
|
||||
#define ADC_VREF_PREC2 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(RADIO_T16)
|
||||
#define ADC_DIRECTION {1,-1,1,-1, 1,1,1, -1,1,1,1, -1,1 }
|
||||
#elif defined(RADIO_T18)
|
||||
#define ADC_DIRECTION {1,-1,1,-1, -1,1,-1, -1,1,1,1, -1,1 }
|
||||
#elif defined(RADIO_TX16S)
|
||||
#define ADC_DIRECTION {1,-1,1,-1, 1,1,1, -1,1,1,1, -1,1 }
|
||||
#elif defined(PCBX10)
|
||||
#define ADC_DIRECTION {1,-1,1,-1, -1,1,-1, 1,1,1,1, 1,-1 }
|
||||
#elif defined(PCBX12S)
|
||||
#define ADC_DIRECTION {1,-1,1,-1, -1,1,-1, 1,-1, -1,-1, 0,0,0}
|
||||
#else
|
||||
#error "Missing ADC_DIRECTION array"
|
||||
#endif
|
||||
|
||||
|
||||
// Power
|
||||
#if defined(RADIO_T18)
|
||||
#define PWR_RCC_AHB1Periph RCC_AHB1Periph_GPIOJ | RCC_AHB1Periph_GPIOB
|
||||
|
||||
@@ -1,223 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "opentx_types.h"
|
||||
#include "board.h"
|
||||
#include "keys.h"
|
||||
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
#if defined(KEYS_GPIO_REG_PGUP)
|
||||
if (~KEYS_GPIO_REG_PGUP & KEYS_GPIO_PIN_PGUP)
|
||||
result |= 1 << KEY_PGUP;
|
||||
#endif
|
||||
if (~KEYS_GPIO_REG_PGDN & KEYS_GPIO_PIN_PGDN)
|
||||
result |= 1 << KEY_PGDN;
|
||||
if (~KEYS_GPIO_REG_ENTER & KEYS_GPIO_PIN_ENTER)
|
||||
result |= 1 << KEY_ENTER;
|
||||
if (~KEYS_GPIO_REG_UP & KEYS_GPIO_PIN_UP)
|
||||
result |= 1 << KEY_MODEL;
|
||||
if (~KEYS_GPIO_REG_DOWN & KEYS_GPIO_PIN_DOWN)
|
||||
result |= 1 << KEY_EXIT;
|
||||
if (~KEYS_GPIO_REG_RIGHT & KEYS_GPIO_PIN_RIGHT)
|
||||
result |= 1 << KEY_TELEM;
|
||||
if (~KEYS_GPIO_REG_LEFT & KEYS_GPIO_PIN_LEFT)
|
||||
result |= 1 << KEY_RADIO;
|
||||
|
||||
// TRACE("readKeys(): %x", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t readTrims()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
if (~TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
|
||||
result |= 0x01;
|
||||
if (~TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
|
||||
result |= 0x02;
|
||||
if (~TRIMS_GPIO_REG_LVD & TRIMS_GPIO_PIN_LVD)
|
||||
result |= 0x04;
|
||||
if (~TRIMS_GPIO_REG_LVU & TRIMS_GPIO_PIN_LVU)
|
||||
result |= 0x08;
|
||||
if (~TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
|
||||
result |= 0x10;
|
||||
if (~TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
|
||||
result |= 0x20;
|
||||
if (~TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
|
||||
result |= 0x40;
|
||||
if (~TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
|
||||
result |= 0x80;
|
||||
if (~TRIMS_GPIO_REG_LSD & TRIMS_GPIO_PIN_LSD)
|
||||
result |= 0x100;
|
||||
if (~TRIMS_GPIO_REG_LSU & TRIMS_GPIO_PIN_LSU)
|
||||
result |= 0x200;
|
||||
if (~TRIMS_GPIO_REG_RSD & TRIMS_GPIO_PIN_RSD)
|
||||
result |= 0x400;
|
||||
if (~TRIMS_GPIO_REG_RSU & TRIMS_GPIO_PIN_RSU)
|
||||
result |= 0x800;
|
||||
// TRACE("readTrims(): result=0x%04x", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool trimDown(uint8_t idx)
|
||||
{
|
||||
return readTrims() & ((uint32_t)1 << idx);
|
||||
}
|
||||
|
||||
bool keyDown()
|
||||
{
|
||||
return readKeys() || readTrims();
|
||||
}
|
||||
|
||||
#define ADD_2POS_CASE(x) \
|
||||
case SW_S ## x ## 0: \
|
||||
xxx = SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
|
||||
break; \
|
||||
case SW_S ## x ## 2: \
|
||||
xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
|
||||
break
|
||||
#define ADD_INV_2POS_CASE(x) \
|
||||
case SW_S ## x ## 2: \
|
||||
xxx = SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
|
||||
break; \
|
||||
case SW_S ## x ## 0: \
|
||||
xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
|
||||
break
|
||||
#define ADD_3POS_CASE(x, i) \
|
||||
case SW_S ## x ## 0: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
|
||||
if (IS_3POS(i)) { \
|
||||
xxx = xxx && (~SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
} \
|
||||
break; \
|
||||
case SW_S ## x ## 1: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
break; \
|
||||
case SW_S ## x ## 2: \
|
||||
xxx = (~SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
|
||||
if (IS_3POS(i)) { \
|
||||
xxx = xxx && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
} \
|
||||
break
|
||||
#define ADD_INV_3POS_CASE(x, i) \
|
||||
case SW_S ## x ## 2: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
|
||||
if (IS_3POS(i)) { \
|
||||
xxx = xxx && (~SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
} \
|
||||
break; \
|
||||
case SW_S ## x ## 1: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
break; \
|
||||
case SW_S ## x ## 0: \
|
||||
xxx = (~SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
|
||||
if (IS_3POS(i)) { \
|
||||
xxx = xxx && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
} \
|
||||
break
|
||||
|
||||
#if !defined(BOOT)
|
||||
uint32_t switchState(uint8_t index)
|
||||
{
|
||||
uint32_t xxx = 0;
|
||||
|
||||
switch (index) {
|
||||
#if defined(PCBX12S)
|
||||
ADD_3POS_CASE(A, 0);
|
||||
ADD_3POS_CASE(B, 1);
|
||||
ADD_3POS_CASE(C, 2);
|
||||
ADD_3POS_CASE(D, 3);
|
||||
ADD_3POS_CASE(E, 4);
|
||||
ADD_INV_2POS_CASE(F);
|
||||
ADD_3POS_CASE(G, 6);
|
||||
ADD_2POS_CASE(H);
|
||||
ADD_2POS_CASE(I);
|
||||
ADD_2POS_CASE(J);
|
||||
#else
|
||||
ADD_3POS_CASE(A, 0);
|
||||
ADD_INV_3POS_CASE(B, 1);
|
||||
ADD_3POS_CASE(C, 2);
|
||||
ADD_INV_3POS_CASE(D, 3);
|
||||
ADD_INV_3POS_CASE(E, 4);
|
||||
ADD_2POS_CASE(F);
|
||||
ADD_3POS_CASE(G, 6);
|
||||
ADD_2POS_CASE(H);
|
||||
ADD_2POS_CASE(I);
|
||||
ADD_2POS_CASE(J);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// TRACE("switch %d => %d", index, xxx);
|
||||
return xxx;
|
||||
}
|
||||
#endif
|
||||
|
||||
void keysInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
|
||||
#if defined(KEYS_GPIOA_PINS)
|
||||
INIT_KEYS_PINS(GPIOA);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOB_PINS)
|
||||
INIT_KEYS_PINS(GPIOB);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOC_PINS)
|
||||
INIT_KEYS_PINS(GPIOC);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOD_PINS)
|
||||
INIT_KEYS_PINS(GPIOD);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOE_PINS)
|
||||
INIT_KEYS_PINS(GPIOE);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOG_PINS)
|
||||
INIT_KEYS_PINS(GPIOG);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOH_PINS)
|
||||
INIT_KEYS_PINS(GPIOH);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOI_PINS)
|
||||
INIT_KEYS_PINS(GPIOI);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOJ_PINS)
|
||||
INIT_KEYS_PINS(GPIOJ);
|
||||
#endif
|
||||
}
|
||||
@@ -24,6 +24,9 @@
|
||||
#include "lcd.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
#include "stm32f4xx_dma2d.h"
|
||||
#include "stm32f4xx_ltdc.h"
|
||||
|
||||
#if defined(RADIO_T18)
|
||||
#define HBP 43
|
||||
#define VBP 12
|
||||
|
||||
@@ -139,5 +139,3 @@ constexpr LcdFlags TABLE_BODY_FONT = FONT(STD);
|
||||
|
||||
constexpr int CJK_FIRST_LETTER_INDEX = 128 - 32 + 21;
|
||||
constexpr coord_t CHAR_SPACING = 0;
|
||||
|
||||
#define ROTARY_ENCODER_SPEED() rotencSpeed
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "stm32f4xx_fmc.h"
|
||||
|
||||
#define SDRAM_MEMORY_WIDTH FMC_SDMemory_Width_16b
|
||||
|
||||
@@ -463,4 +464,4 @@ void SDRAM_ReadBuffer(uint32_t* pBuffer, uint32_t uwReadAddress, uint32_t uwBuff
|
||||
write_pointer += 4;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_i2c_driver.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "tp_gt911.h"
|
||||
@@ -471,25 +472,13 @@ static void TOUCH_AF_ExtiConfig(void)
|
||||
NVIC_EnableIRQ(TOUCH_INT_EXTI_IRQn);
|
||||
}
|
||||
|
||||
static int gt911_enable_gpio_clock(GPIO_TypeDef *GPIOx)
|
||||
{
|
||||
if (GPIOx == GPIOF)
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
else if (GPIOx == GPIOH)
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
else
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void TOUCH_AF_GPIOConfig(void)
|
||||
{
|
||||
LL_GPIO_InitTypeDef gpioInit;
|
||||
LL_GPIO_StructInit(&gpioInit);
|
||||
|
||||
gt911_enable_gpio_clock(TOUCH_RST_GPIO);
|
||||
gt911_enable_gpio_clock(TOUCH_INT_GPIO);
|
||||
stm32_gpio_enable_clock(TOUCH_RST_GPIO);
|
||||
stm32_gpio_enable_clock(TOUCH_INT_GPIO);
|
||||
|
||||
gpioInit.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
gpioInit.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
||||
|
||||
@@ -1,281 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "x12s_adc_driver.h"
|
||||
|
||||
|
||||
#define ADC_CS_HIGH() (ADC_SPI_GPIO->BSRRL = ADC_SPI_PIN_CS)
|
||||
#define ADC_CS_LOW() (ADC_SPI_GPIO->BSRRH = ADC_SPI_PIN_CS)
|
||||
|
||||
#define SPI_STICK1 0
|
||||
#define SPI_STICK2 1
|
||||
#define SPI_STICK3 2
|
||||
#define SPI_STICK4 3
|
||||
#define SPI_S1 4
|
||||
#define SPI_6POS 5
|
||||
#define SPI_S2 6
|
||||
#define SPI_LS 7
|
||||
#define SPI_RS 8
|
||||
#define SPI_TX_VOLTAGE 9
|
||||
#define SPI_L2 10
|
||||
#define SPI_L1 11
|
||||
#define RESETCMD 0x4000
|
||||
#define MANUAL_MODE 0x1000 // manual mode channel 0
|
||||
|
||||
uint16_t SPIx_ReadWriteByte(uint16_t value)
|
||||
{
|
||||
while (SPI_I2S_GetFlagStatus(ADC_SPI, SPI_I2S_FLAG_TXE) == RESET);
|
||||
SPI_I2S_SendData(ADC_SPI, value);
|
||||
|
||||
while (SPI_I2S_GetFlagStatus(ADC_SPI, SPI_I2S_FLAG_RXNE) == RESET);
|
||||
return SPI_I2S_ReceiveData(ADC_SPI);
|
||||
}
|
||||
|
||||
static void ADS7952_Init()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
SPI_InitTypeDef SPI_InitStructure;
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_SPI_PIN_MISO | ADC_SPI_PIN_SCK | ADC_SPI_PIN_MOSI;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(ADC_SPI_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_SPI_PIN_CS;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(ADC_SPI_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_PinAFConfig(ADC_SPI_GPIO, ADC_SPI_PinSource_SCK, ADC_GPIO_AF);
|
||||
GPIO_PinAFConfig(ADC_SPI_GPIO, ADC_SPI_PinSource_MISO, ADC_GPIO_AF);
|
||||
GPIO_PinAFConfig(ADC_SPI_GPIO, ADC_SPI_PinSource_MOSI, ADC_GPIO_AF);
|
||||
|
||||
SPI_I2S_DeInit(ADC_SPI);
|
||||
|
||||
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
||||
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
|
||||
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
|
||||
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
|
||||
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
|
||||
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
|
||||
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
||||
SPI_InitStructure.SPI_CRCPolynomial = 7;
|
||||
SPI_Init(ADC_SPI, &SPI_InitStructure);
|
||||
SPI_Cmd(ADC_SPI, ENABLE);
|
||||
SPI_I2S_ITConfig(ADC_SPI, SPI_I2S_IT_TXE, DISABLE);
|
||||
SPI_I2S_ITConfig(ADC_SPI, SPI_I2S_IT_RXNE, DISABLE);
|
||||
|
||||
ADC_CS_HIGH();
|
||||
delay_01us(1);
|
||||
ADC_CS_LOW();
|
||||
SPIx_ReadWriteByte(RESETCMD);
|
||||
ADC_CS_HIGH();
|
||||
delay_01us(1);
|
||||
ADC_CS_LOW();
|
||||
SPIx_ReadWriteByte(MANUAL_MODE);
|
||||
ADC_CS_HIGH();
|
||||
}
|
||||
|
||||
static bool x12s_adc_init()
|
||||
{
|
||||
ADS7952_Init();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIO_PIN_MOUSE1 | ADC_GPIO_PIN_MOUSE2;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(ADC_GPIO_MOUSE, &GPIO_InitStructure);
|
||||
|
||||
ADC3->CR1 = ADC_CR1_SCAN;
|
||||
ADC3->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS;
|
||||
ADC3->SQR1 = (2 - 1) << 20;
|
||||
ADC3->SQR2 = 0;
|
||||
ADC3->SQR3 = (ADC_CHANNEL_MOUSE1 << 0) + (ADC_CHANNEL_MOUSE2 << 5);
|
||||
ADC3->SMPR1 = (ADC_SAMPTIME << 0) + (ADC_SAMPTIME << 3) + (ADC_SAMPTIME << 6) + (ADC_SAMPTIME << 9) + (ADC_SAMPTIME << 12) + (ADC_SAMPTIME << 15) + (ADC_SAMPTIME << 18) + (ADC_SAMPTIME << 21) + (ADC_SAMPTIME << 24);
|
||||
ADC3->SMPR2 = (ADC_SAMPTIME << 0) + (ADC_SAMPTIME << 3) + (ADC_SAMPTIME << 6) + (ADC_SAMPTIME << 9) + (ADC_SAMPTIME << 12) + (ADC_SAMPTIME << 15) + (ADC_SAMPTIME << 18) + (ADC_SAMPTIME << 21) + (ADC_SAMPTIME << 24) + (ADC_SAMPTIME << 27);
|
||||
ADC->CCR = 0;
|
||||
|
||||
// Enable the DMA channel here, DMA2 stream 1, channel 2
|
||||
ADC_DMA_Stream->CR = DMA_SxCR_PL | DMA_SxCR_CHSEL_1 | DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC;
|
||||
ADC_DMA_Stream->PAR = CONVERT_PTR_UINT(&ADC3->DR);
|
||||
ADC_DMA_Stream->M0AR = CONVERT_PTR_UINT(&adcValues[MOUSE1]);
|
||||
ADC_DMA_Stream->NDTR = 2;
|
||||
ADC_DMA_Stream->FCR = DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0;
|
||||
|
||||
ADC->CCR = ADC_CCR_VBATE; // Enable RTC coin cell sampling bridge
|
||||
|
||||
ADC1->CR1 = ADC_CR1_SCAN;
|
||||
ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS;
|
||||
ADC1->SQR1 = (1 - 1) << 20;
|
||||
ADC1->SQR2 = 0;
|
||||
ADC1->SQR3 = (ADC_Channel_Vbat << 0);
|
||||
ADC1->SMPR1 = (ADC_SAMPTIME << 0) + (ADC_SAMPTIME << 3) + (ADC_SAMPTIME << 6) + (ADC_SAMPTIME << 9) + (ADC_SAMPTIME << 12) + (ADC_SAMPTIME << 15) + (ADC_SAMPTIME << 18) + (ADC_SAMPTIME << 21) + (ADC_SAMPTIME << 24);
|
||||
ADC1->SMPR2 = (ADC_SAMPTIME << 0) + (ADC_SAMPTIME << 3) + (ADC_SAMPTIME << 6) + (ADC_SAMPTIME << 9) + (ADC_SAMPTIME << 12) + (ADC_SAMPTIME << 15) + (ADC_SAMPTIME << 18) + (ADC_SAMPTIME << 21) + (ADC_SAMPTIME << 24) + (ADC_SAMPTIME << 27);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const uint16_t adcCommands[MOUSE1+2] =
|
||||
{
|
||||
MANUAL_MODE | (SPI_STICK1 << 7),
|
||||
MANUAL_MODE | (SPI_STICK2 << 7),
|
||||
MANUAL_MODE | (SPI_STICK3 << 7),
|
||||
MANUAL_MODE | (SPI_STICK4 << 7),
|
||||
MANUAL_MODE | (SPI_S1 << 7),
|
||||
MANUAL_MODE | (SPI_6POS << 7),
|
||||
MANUAL_MODE | (SPI_S2 << 7),
|
||||
MANUAL_MODE | (SPI_L1 << 7),
|
||||
MANUAL_MODE | (SPI_L2 << 7),
|
||||
MANUAL_MODE | (SPI_LS << 7),
|
||||
MANUAL_MODE | (SPI_RS << 7),
|
||||
MANUAL_MODE | (SPI_TX_VOLTAGE << 7),
|
||||
MANUAL_MODE | (0 << 7), // small joystick left/right
|
||||
MANUAL_MODE | (0 << 7) // small joystick up/down
|
||||
};
|
||||
|
||||
void adcReadSPIDummy()
|
||||
{
|
||||
// A dummy command to get things started
|
||||
// (because the sampled data is lagging behind for two command cycles)
|
||||
ADC_CS_LOW();
|
||||
delay_01us(1);
|
||||
SPIx_ReadWriteByte(adcCommands[0]);
|
||||
ADC_CS_HIGH();
|
||||
delay_01us(1);
|
||||
}
|
||||
|
||||
uint32_t adcReadNextSPIChannel(uint8_t index)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
// This delay is to allow charging of ADC input capacitor
|
||||
// after the MUX changes from one channel to the other.
|
||||
// It was determined experimentally. Biggest problem seems to be
|
||||
// the cross-talk between A4:S1 and A5:MULTIPOS. Changing S1 for one extreme
|
||||
// to the other resulted in A5 change of:
|
||||
//
|
||||
// delay value A5 change Time needed for adcRead()
|
||||
// 1 16 0.154ms - 0.156ms
|
||||
// 38 5 0.197ms - 0.199ms
|
||||
// 62 0 0.225ms - 0.243ms
|
||||
delay_01us(40);
|
||||
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
ADC_CS_LOW();
|
||||
delay_01us(1);
|
||||
// command is changed to the next index for the last two readings
|
||||
// (because the sampled data is lagging behind for two command cycles)
|
||||
uint16_t val = (0x0fff & SPIx_ReadWriteByte(adcCommands[(i>1) ? index+1 : index]));
|
||||
#if defined(JITTER_MEASURE)
|
||||
if (JITTER_MEASURE_ACTIVE()) {
|
||||
rawJitter[index].measure(val);
|
||||
}
|
||||
#endif
|
||||
ADC_CS_HIGH();
|
||||
delay_01us(1);
|
||||
result += val;
|
||||
}
|
||||
|
||||
return result >> 2;
|
||||
}
|
||||
|
||||
void adcOnChipReadStart()
|
||||
{
|
||||
ADC_DMA_Stream->CR &= ~DMA_SxCR_EN; // Disable DMA
|
||||
ADC3->SR &= ~(uint32_t)(ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
|
||||
ADC_DMA->LIFCR = DMA_LIFCR_CTCIF0 | DMA_LIFCR_CHTIF0 | DMA_LIFCR_CTEIF0 | DMA_LIFCR_CDMEIF0 | DMA_LIFCR_CFEIF0; // Write ones to clear bits
|
||||
ADC_DMA_Stream->M0AR = CONVERT_PTR_UINT(&adcValues[MOUSE1]);
|
||||
ADC_DMA_Stream->NDTR = 2;
|
||||
ADC_DMA_Stream->CR |= DMA_SxCR_EN; // Enable DMA
|
||||
ADC3->CR2 |= (uint32_t)ADC_CR2_SWSTART;
|
||||
|
||||
ADC1->SR &= ~(uint32_t)(ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
|
||||
ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART;
|
||||
}
|
||||
|
||||
bool adcOnChipReadFinished()
|
||||
{
|
||||
return (ADC_DMA->LISR & DMA_LISR_TCIF0);
|
||||
}
|
||||
|
||||
// Re-declare adcRead()
|
||||
// (takes precedence over hal/adc_driver.cpp)
|
||||
bool adcRead()
|
||||
{
|
||||
uint16_t temp[NUM_ANALOGS-MOUSE1] = { 0 };
|
||||
uint8_t noInternalReads = 0;
|
||||
|
||||
adcOnChipReadStart();
|
||||
adcReadSPIDummy();
|
||||
adcReadSPIDummy();
|
||||
for (uint32_t index=0; index<MOUSE1; index++) {
|
||||
adcValues[index] = adcReadNextSPIChannel(index);
|
||||
if (noInternalReads < 4 && adcOnChipReadFinished()) {
|
||||
for (uint8_t x=0; x<NUM_ANALOGS-MOUSE1; x++) {
|
||||
uint16_t val = adcValues[MOUSE1+x];
|
||||
#if defined(JITTER_MEASURE)
|
||||
if (JITTER_MEASURE_ACTIVE()) {
|
||||
rawJitter[MOUSE1+x].measure(val);
|
||||
}
|
||||
#endif
|
||||
temp[x] += val;
|
||||
}
|
||||
if (++noInternalReads < 4) {
|
||||
adcOnChipReadStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(DEBUG)
|
||||
if (noInternalReads != 4) {
|
||||
TRACE("Internal ADC problem: reads: %d", noInternalReads);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (uint8_t x=0; x<NUM_ANALOGS-MOUSE1; x++) {
|
||||
adcValues[MOUSE1+x] = temp[x] >> 2;
|
||||
}
|
||||
|
||||
if (isVBatBridgeEnabled()) {
|
||||
rtcBatteryVoltage = ADC1->DR;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO: implement these based on stm32_hal_adc.cpp
|
||||
//static bool x12s_adc_init();
|
||||
//static bool x12s_adc_start_read();
|
||||
//static void x12s_adc_wait_completion();
|
||||
|
||||
const etx_hal_adc_driver_t x12s_adc_driver = {
|
||||
x12s_adc_init,
|
||||
nullptr,//x12s_adc_start_read,
|
||||
nullptr,//x12s_adc_wait_completion
|
||||
};
|
||||
Reference in New Issue
Block a user