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
@@ -301,7 +301,7 @@ set(SRC
|
||||
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
keys_driver.cpp
|
||||
# keys_driver.cpp
|
||||
diskio.cpp
|
||||
# telemetry_driver.cpp
|
||||
)
|
||||
|
||||
@@ -41,6 +41,10 @@ set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/stm32_serial_driver.cpp
|
||||
../common/arm/stm32/stm32_softserial_driver.cpp
|
||||
../common/arm/stm32/module_timer_driver.cpp
|
||||
../common/arm/stm32/stm32_switch_driver.cpp
|
||||
../common/arm/stm32/stm32_adc.cpp
|
||||
../common/arm/stm32/stm32_gpio_driver.cpp
|
||||
../common/arm/stm32/mixer_scheduler_driver.cpp
|
||||
)
|
||||
|
||||
if(IMU)
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* 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 "ads79xx.h"
|
||||
#include "delays_driver.h"
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#define RESETCMD 0x4000
|
||||
#define MANUAL_MODE 0x1000 // manual mode channel 0
|
||||
#define MANUAL_MODE_CHANNEL(x) (MANUAL_MODE | ((x) << 7))
|
||||
|
||||
static uint16_t ads79xx_rw(SPI_TypeDef* SPIx, uint16_t value)
|
||||
{
|
||||
while (!LL_SPI_IsActiveFlag_TXE(SPIx));
|
||||
LL_SPI_TransmitData16(SPIx, value);
|
||||
|
||||
while (!LL_SPI_IsActiveFlag_RXNE(SPIx));
|
||||
return LL_SPI_ReceiveData16(SPIx);
|
||||
}
|
||||
|
||||
void ads79xx_init(const stm32_spi_adc_t* adc)
|
||||
{
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = adc->GPIO_Pins;
|
||||
pinInit.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
pinInit.Alternate = adc->GPIO_AF;
|
||||
LL_GPIO_Init(adc->GPIOx, &pinInit);
|
||||
|
||||
pinInit.Pin = adc->GPIO_CS;
|
||||
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
pinInit.Alternate = LL_GPIO_AF_0;
|
||||
LL_GPIO_Init(adc->GPIOx, &pinInit);
|
||||
|
||||
auto SPIx = adc->SPIx;
|
||||
LL_SPI_DeInit(SPIx);
|
||||
|
||||
LL_SPI_InitTypeDef spiInit;
|
||||
LL_SPI_StructInit(&spiInit);
|
||||
|
||||
spiInit.TransferDirection = LL_SPI_FULL_DUPLEX;
|
||||
spiInit.Mode = LL_SPI_MODE_MASTER;
|
||||
spiInit.DataWidth = LL_SPI_DATAWIDTH_16BIT;
|
||||
spiInit.NSS = LL_SPI_NSS_SOFT;
|
||||
spiInit.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8;
|
||||
LL_SPI_Init(SPIx, &spiInit);
|
||||
|
||||
LL_SPI_Enable(SPIx);
|
||||
|
||||
LL_SPI_DisableIT_TXE(SPIx);
|
||||
LL_SPI_DisableIT_RXNE(SPIx);
|
||||
|
||||
_SPI_ADC_CS_HIGH(adc);
|
||||
delay_01us(1);
|
||||
_SPI_ADC_CS_LOW(adc);
|
||||
ads79xx_rw(SPIx, RESETCMD);
|
||||
_SPI_ADC_CS_HIGH(adc);
|
||||
delay_01us(1);
|
||||
_SPI_ADC_CS_LOW(adc);
|
||||
ads79xx_rw(SPIx, MANUAL_MODE);
|
||||
_SPI_ADC_CS_HIGH(adc);
|
||||
}
|
||||
|
||||
static void ads79xx_dummy_read(const stm32_spi_adc_t* adc, uint16_t start_channel)
|
||||
{
|
||||
// A dummy command to get things started
|
||||
// (because the sampled data is lagging behind for two command cycles)
|
||||
_SPI_ADC_CS_LOW(adc);
|
||||
delay_01us(1);
|
||||
ads79xx_rw(adc->SPIx, MANUAL_MODE_CHANNEL(start_channel));
|
||||
_SPI_ADC_CS_HIGH(adc);
|
||||
delay_01us(1);
|
||||
}
|
||||
|
||||
static uint32_t ads79xx_read_next_channel(const stm32_spi_adc_t* adc,
|
||||
uint8_t index,
|
||||
const stm32_adc_input_t* inputs,
|
||||
const uint8_t* chan, uint8_t nconv)
|
||||
{
|
||||
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++) {
|
||||
_SPI_ADC_CS_LOW(adc);
|
||||
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)
|
||||
uint8_t chan_idx = (i > 1 ? index + 1 : index) % nconv;
|
||||
|
||||
auto input_idx = chan[chan_idx];
|
||||
auto spi_chan = inputs[input_idx].ADC_Channel;
|
||||
|
||||
uint16_t val = (0x0fff & ads79xx_rw(adc->SPIx, MANUAL_MODE_CHANNEL(spi_chan)));
|
||||
|
||||
#if defined(JITTER_MEASURE)
|
||||
if (JITTER_MEASURE_ACTIVE()) {
|
||||
rawJitter[index].measure(val);
|
||||
}
|
||||
#endif
|
||||
|
||||
_SPI_ADC_CS_HIGH(adc);
|
||||
delay_01us(1);
|
||||
result += val;
|
||||
}
|
||||
|
||||
return result >> 2;
|
||||
}
|
||||
|
||||
bool ads79xx_adc_start_read(const stm32_spi_adc_t* adc, const stm32_adc_input_t* inputs)
|
||||
{
|
||||
auto start_channel = inputs[adc->channels[0]].ADC_Channel;
|
||||
ads79xx_dummy_read(adc, start_channel);
|
||||
ads79xx_dummy_read(adc, start_channel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ads79xx_adc_wait_completion(const stm32_spi_adc_t* adc, const stm32_adc_input_t* inputs)
|
||||
{
|
||||
auto spi_channels = adc->n_channels;
|
||||
auto chans = adc->channels;
|
||||
|
||||
// Fetch buffer from generic ADC driver
|
||||
auto adcValues = getAnalogValues();
|
||||
|
||||
// At this point, the first conversion has been started
|
||||
// in ads79xx_adc_start_read()
|
||||
|
||||
// for each SPI channel
|
||||
for (uint32_t i = 0; i < spi_channels; i++) {
|
||||
|
||||
// read SPI channel
|
||||
auto input_channel = chans[i];
|
||||
auto adc_value = ads79xx_read_next_channel(adc, i, inputs, chans, spi_channels);
|
||||
|
||||
if (inputs[input_channel].inverted)
|
||||
adcValues[input_channel] = ADC_INVERT_VALUE(adc_value);
|
||||
else
|
||||
adcValues[input_channel] = adc_value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 "stm32_spi_adc.h"
|
||||
#include "stm32_adc.h"
|
||||
|
||||
void ads79xx_init(const stm32_spi_adc_t* adc);
|
||||
bool ads79xx_adc_start_read(const stm32_spi_adc_t* adc, const stm32_adc_input_t* inputs);
|
||||
void ads79xx_adc_wait_completion(const stm32_spi_adc_t* adc, const stm32_adc_input_t* inputs);
|
||||
|
||||
@@ -25,16 +25,7 @@
|
||||
#include <inttypes.h>
|
||||
#include "cpu_id.h"
|
||||
|
||||
#if defined(LUA_EXPORT_GENERATION)
|
||||
// no includes
|
||||
#else
|
||||
|
||||
#if __clang__
|
||||
// clang is very picky about the use of "register"
|
||||
// Tell clang to ignore the warnings for the following files
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-register"
|
||||
#endif
|
||||
#if !defined(SIMU) && !defined(BACKUP)
|
||||
|
||||
#if defined(STM32F4)
|
||||
#include "stm32f4xx.h"
|
||||
@@ -43,7 +34,6 @@
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_exti.h"
|
||||
#include "stm32f4xx_tim.h"
|
||||
#include "stm32f4xx_adc.h"
|
||||
#include "stm32f4xx_spi.h"
|
||||
#include "stm32f4xx_pwr.h"
|
||||
#include "stm32f4xx_dma.h"
|
||||
@@ -57,7 +47,6 @@
|
||||
#include "stm32f2xx_gpio.h"
|
||||
#include "stm32f2xx_exti.h"
|
||||
#include "stm32f2xx_tim.h"
|
||||
#include "stm32f2xx_adc.h"
|
||||
#include "stm32f2xx_spi.h"
|
||||
#include "stm32f2xx_pwr.h"
|
||||
#include "stm32f2xx_dma.h"
|
||||
@@ -67,11 +56,6 @@
|
||||
#include "dwt.h" // the old ST library that we use does not define DWT register for STM32F2xx
|
||||
#endif
|
||||
|
||||
#if __clang__
|
||||
// Restore warnings about registers
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#include "usb_driver.h"
|
||||
@@ -80,25 +64,6 @@
|
||||
#include "../simu/simpgmspace.h"
|
||||
#endif
|
||||
|
||||
uint16_t getBatteryVoltage();
|
||||
|
||||
// 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)
|
||||
static inline void enableVBatBridge()
|
||||
{
|
||||
ADC->CCR |= ADC_CCR_VBATE;
|
||||
}
|
||||
|
||||
static inline void disableVBatBridge()
|
||||
{
|
||||
ADC->CCR &= ~ADC_CCR_VBATE;
|
||||
}
|
||||
|
||||
static inline bool isVBatBridgeEnabled()
|
||||
{
|
||||
return ADC->CCR & ADC_CCR_VBATE;
|
||||
}
|
||||
|
||||
// Delays driver
|
||||
#define SYSTEM_TICKS_1MS ((CPU_FREQ + 500) / 1000)
|
||||
#define SYSTEM_TICKS_1US ((CPU_FREQ + 500000) / 1000000)
|
||||
@@ -110,10 +75,10 @@ extern "C" {
|
||||
|
||||
static inline uint32_t ticksNow()
|
||||
{
|
||||
#if defined(SIMU)
|
||||
return 0;
|
||||
#else
|
||||
#if !defined(SIMU) && !defined(BACKUP)
|
||||
return DWT->CYCCNT;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -123,35 +88,4 @@ static inline uint32_t ticksNow()
|
||||
|
||||
#include "delays_driver.h"
|
||||
|
||||
#define INIT_KEYS_PINS(GPIO) \
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_ ## GPIO ## _PINS; \
|
||||
GPIO_Init(GPIO, &GPIO_InitStructure)
|
||||
|
||||
#define SET_KEYS_PINS_HIGH(GPIO) \
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_ ## GPIO ## _PINS; \
|
||||
GPIO_Init(GPIO, &GPIO_InitStructure); \
|
||||
GPIO_SetBits(GPIO, KEYS_ ## GPIO ## _PINS)
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
typedef int32_t rotenc_t;
|
||||
extern volatile rotenc_t rotencValue;
|
||||
#define IS_ROTARY_ENCODER_NAVIGATION_ENABLE() true
|
||||
#define ROTARY_ENCODER_NAVIGATION_VALUE rotencValue
|
||||
#define ROTENC_LOWSPEED 1
|
||||
#define ROTENC_MIDSPEED 5
|
||||
#define ROTENC_HIGHSPEED 50
|
||||
#define ROTENC_DELAY_MIDSPEED 32
|
||||
#define ROTENC_DELAY_HIGHSPEED 16
|
||||
#elif (defined(RADIO_T8) || defined(RADIO_COMMANDO8)) && defined(__cplusplus)
|
||||
constexpr uint8_t rotencSpeed = 1;
|
||||
#endif
|
||||
|
||||
#define ROTARY_ENCODER_GRANULARITY (2)
|
||||
|
||||
#if defined(PWR_BUTTON_PRESS)
|
||||
#define pwrOffPressed() pwrPressed()
|
||||
#else
|
||||
#define pwrOffPressed() (!pwrPressed())
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,7 +22,7 @@ set(BOOTLOADER_SRC
|
||||
../../../../../${FATFS_DIR}/ffunicode.c
|
||||
../../../../../targets/${TARGET_DIR}/${LCD_DRIVER}
|
||||
../../../../../targets/${TARGET_DIR}/backlight_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/keys_driver.cpp
|
||||
#../../../../../targets/${TARGET_DIR}/keys_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/diskio.cpp
|
||||
../../../../../targets/${TARGET_DIR}/board.cpp
|
||||
../pwr_driver.cpp
|
||||
@@ -37,6 +37,7 @@ set(BOOTLOADER_SRC
|
||||
../stm32_exti_driver.cpp
|
||||
../stm32_serial_driver.cpp
|
||||
../stm32_usart_driver.cpp
|
||||
../stm32_gpio_driver.cpp
|
||||
init.c
|
||||
boot.cpp
|
||||
bin_files.cpp
|
||||
@@ -72,9 +73,9 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
|
||||
../../../../../fonts/lvgl/lv_font_roboto_bl_16.c
|
||||
../../../../../thirdparty/libopenui/src/bitmapbuffer.cpp
|
||||
../../../../../thirdparty/libopenui/thirdparty/lz4/lz4.c
|
||||
../../../../../targets/${TARGET_DIR}/sdram_driver.c
|
||||
../../../../../targets/common/arm/stm32/sdio_sd.c
|
||||
../../../../../targets/common/arm/stm32/rtc_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/sdram_driver.c
|
||||
../../../../../targets/${TARGET_DIR}/haptic_driver.cpp
|
||||
)
|
||||
|
||||
@@ -83,11 +84,18 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} ../../../../../${LVGL_FILE})
|
||||
endforeach()
|
||||
|
||||
if(NOT PCB STREQUAL NV14)
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../targets/${TARGET_DIR}/led_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
if(USB_CHARGER)
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../targets/${TARGET_DIR}/usb_charger_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/led_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
#include "bluetooth_driver.h"
|
||||
#include "stm32_serial_driver.h"
|
||||
@@ -29,9 +31,13 @@
|
||||
#include "bin_files.h"
|
||||
#include "dataconstants.h"
|
||||
#include "lcd.h"
|
||||
#include "keys.h"
|
||||
// #include "keys.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "watchdog_driver.h"
|
||||
|
||||
#include "hal/rotary_encoder.h"
|
||||
|
||||
#if defined(DEBUG_SEGGER_RTT)
|
||||
#include "thirdparty/Segger_RTT/RTT/SEGGER_RTT.h"
|
||||
#endif
|
||||
@@ -67,9 +73,10 @@ const uint8_t bootloaderVersion[] __attribute__ ((section(".version"), used)) =
|
||||
{'B', 'O', 'O', 'T', '1', '0'};
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG) && !defined(SIMU)
|
||||
#define SOFTRESET_REQUEST 0xCAFEDEAD
|
||||
|
||||
volatile tmr10ms_t g_tmr10ms;
|
||||
#endif
|
||||
volatile uint8_t tenms = 1;
|
||||
|
||||
uint32_t firmwareSize;
|
||||
uint32_t firmwareAddress = FIRMWARE_ADDRESS;
|
||||
@@ -80,7 +87,6 @@ uint32_t eepromAddress = 0;
|
||||
uint32_t eepromWritten = 0;
|
||||
#endif
|
||||
|
||||
volatile uint8_t tenms = 1;
|
||||
FlashCheckRes valid;
|
||||
MemoryType memoryType;
|
||||
uint32_t unlocked = 0;
|
||||
@@ -88,26 +94,18 @@ uint32_t unlocked = 0;
|
||||
void interrupt10ms()
|
||||
{
|
||||
tenms |= 1u; // 10 mS has passed
|
||||
|
||||
#if defined(DEBUG)
|
||||
g_tmr10ms++;
|
||||
#endif
|
||||
|
||||
uint8_t index = 0;
|
||||
uint32_t in = readKeys();
|
||||
|
||||
for (int i = 0; i < TRM_BASE; i++) {
|
||||
keys[index++].input(in & (1 << i));
|
||||
}
|
||||
keysPollingCycle();
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
static rotenc_t rePreviousValue;
|
||||
|
||||
rotenc_t reNewValue = (rotencValue / ROTARY_ENCODER_GRANULARITY);
|
||||
rotenc_t reNewValue = rotaryEncoderGetValue();
|
||||
int8_t scrollRE = reNewValue - rePreviousValue;
|
||||
if (scrollRE) {
|
||||
rePreviousValue = reNewValue;
|
||||
pushEvent(scrollRE < 0 ? EVT_KEY_FIRST(KEY_UP) : EVT_KEY_FIRST(KEY_DOWN));
|
||||
pushEvent(scrollRE < 0 ? EVT_ROTARY_LEFT : EVT_ROTARY_RIGHT);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -265,7 +263,7 @@ void bootloaderInitApp()
|
||||
|
||||
#if (defined(RADIO_T8) || defined(RADIO_COMMANDO8)) && !defined(RADIOMASTER_RELEASE)
|
||||
// Bind button not pressed
|
||||
if ((~KEYS_GPIO_REG_BIND & KEYS_GPIO_PIN_BIND) == false) {
|
||||
if ((~(KEYS_GPIO_REG_BIND->IDR) & KEYS_GPIO_PIN_BIND) == false) {
|
||||
#else
|
||||
// LHR & RHL trims not pressed simultanously
|
||||
if (readTrims() != BOOTLOADER_KEYS) {
|
||||
@@ -374,11 +372,11 @@ int bootloaderMain()
|
||||
|
||||
bootloaderDrawScreen(state, vpos);
|
||||
|
||||
if (event == EVT_KEY_FIRST(KEY_DOWN)) {
|
||||
if (IS_NEXT_EVENT(event)) {
|
||||
if (vpos < bootloaderGetMenuItemCount(MAIN_MENU_LEN) - 1) { vpos++; }
|
||||
continue;
|
||||
}
|
||||
else if (event == EVT_KEY_FIRST(KEY_UP)) {
|
||||
else if (IS_PREVIOUS_EVENT(event)) {
|
||||
if (vpos > 0) { vpos--; }
|
||||
continue;
|
||||
}
|
||||
@@ -435,7 +433,7 @@ int bootloaderMain()
|
||||
limit = nameCount;
|
||||
}
|
||||
|
||||
if (event == EVT_KEY_REPT(KEY_DOWN) || event == EVT_KEY_FIRST(KEY_DOWN)) {
|
||||
if (IS_NEXT_EVENT(event)) {
|
||||
if (vpos < limit - 1) {
|
||||
vpos += 1;
|
||||
}
|
||||
@@ -446,7 +444,7 @@ int bootloaderMain()
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event == EVT_KEY_REPT(KEY_UP) || event == EVT_KEY_FIRST(KEY_UP)) {
|
||||
else if (IS_PREVIOUS_EVENT(event)) {
|
||||
if (vpos > 0) {
|
||||
vpos -= 1;
|
||||
}
|
||||
|
||||
@@ -1,69 +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 "extmodule_driver.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "board.h"
|
||||
#include "timers_driver.h"
|
||||
|
||||
static stm32_pulse_dma_tc_cb_t _ext_timer_DMA_TC_Callback;
|
||||
|
||||
const stm32_pulse_timer_t extmoduleTimer = {
|
||||
.GPIOx = EXTMODULE_TX_GPIO,
|
||||
.GPIO_Pin = EXTMODULE_TX_GPIO_PIN,
|
||||
.GPIO_Alternate = EXTMODULE_TIMER_TX_GPIO_AF,
|
||||
.TIMx = EXTMODULE_TIMER,
|
||||
.TIM_Freq = EXTMODULE_TIMER_FREQ,
|
||||
.TIM_Channel = EXTMODULE_TIMER_Channel,
|
||||
.TIM_IRQn = EXTMODULE_TIMER_IRQn,
|
||||
.DMAx = EXTMODULE_TIMER_DMA,
|
||||
.DMA_Stream = EXTMODULE_TIMER_DMA_STREAM_LL,
|
||||
.DMA_Channel = EXTMODULE_TIMER_DMA_CHANNEL,
|
||||
.DMA_IRQn = EXTMODULE_TIMER_DMA_STREAM_IRQn,
|
||||
.DMA_TC_CallbackPtr = &_ext_timer_DMA_TC_Callback,
|
||||
};
|
||||
|
||||
// Make sure the timer channel is supported
|
||||
static_assert(__STM32_PULSE_IS_TIMER_CHANNEL_SUPPORTED(EXTMODULE_TIMER_Channel),
|
||||
"Unsupported timer channel");
|
||||
|
||||
// Make sure the DMA channel is supported
|
||||
static_assert(__STM32_PULSE_IS_DMA_STREAM_SUPPORTED(EXTMODULE_TIMER_DMA_STREAM_LL),
|
||||
"Unsupported DMA stream");
|
||||
|
||||
#if !defined(EXTMODULE_TIMER_DMA_IRQHandler)
|
||||
#error "Missing EXTMODULE_TIMER_DMA_IRQHandler definition"
|
||||
#endif
|
||||
|
||||
extern "C" void EXTMODULE_TIMER_DMA_IRQHandler()
|
||||
{
|
||||
stm32_pulse_dma_tc_isr(&extmoduleTimer);
|
||||
}
|
||||
|
||||
#if !defined(EXTMODULE_TIMER_IRQHandler)
|
||||
#error "Missing EXTMODULE_TIMER_IRQHandler definition"
|
||||
#endif
|
||||
|
||||
extern "C" void EXTMODULE_TIMER_IRQHandler()
|
||||
{
|
||||
stm32_pulse_tim_update_isr(&extmoduleTimer);
|
||||
}
|
||||
@@ -15,6 +15,7 @@ if(NOT NATIVE_BUILD)
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_ll_usart.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_ll_rcc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_ll_exti.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_ll_adc.c
|
||||
# HAL drivers
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_hal.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_hal_pwr.c
|
||||
@@ -50,11 +51,8 @@ add_library(stm32_stdperiph OBJECT EXCLUDE_FROM_ALL
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_gpio.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_dbgmcu.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_rcc.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_syscfg.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_spi.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_dma.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_pwr.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_adc.c
|
||||
)
|
||||
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32_stdperiph>)
|
||||
|
||||
@@ -8,12 +8,15 @@ if(NOT NATIVE_BUILD)
|
||||
include_directories(${STM32CUBE_DIR}/Inc)
|
||||
|
||||
add_library(stm32cube_ll OBJECT EXCLUDE_FROM_ALL
|
||||
# LL drivers
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_gpio.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_tim.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_dma.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_usart.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_rcc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_exti.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_adc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_spi.c
|
||||
# HAL drivers
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_pwr.c
|
||||
@@ -49,11 +52,8 @@ set(STM32_STDPERIPH_SRC
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_gpio.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_dbgmcu.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_rcc.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_syscfg.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_spi.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_dma.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_pwr.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_adc.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_flash.c
|
||||
)
|
||||
|
||||
@@ -66,6 +66,10 @@ if(CPU_TYPE_FULL STREQUAL STM32F429xI)
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_dma2d.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_sdio.c
|
||||
)
|
||||
elseif (CPU_TYPE_FULL STREQUAL STM32F413xG)
|
||||
set(STM32_STDPERIPH_SRC ${STM32_STDPERIPH_SRC}
|
||||
targets/${TARGET_DIR}/startup_stm32f413vgtx.s
|
||||
)
|
||||
else()
|
||||
set(STM32_STDPERIPH_SRC ${STM32_STDPERIPH_SRC}
|
||||
targets/${TARGET_DIR}/startup_stm32f40_41xxx.s
|
||||
|
||||
@@ -151,16 +151,27 @@
|
||||
/******************************************************************************/
|
||||
|
||||
/************************* PLL Parameters *************************************/
|
||||
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
|
||||
#define PLL_M 12
|
||||
#define PLL_N 336
|
||||
#if defined(STM32F413xx)
|
||||
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
|
||||
#define PLL_M 12
|
||||
#define PLL_N 200
|
||||
|
||||
/* SYSCLK = PLL_VCO / PLL_P */
|
||||
#define PLL_P 2
|
||||
/* SYSCLK = PLL_VCO / PLL_P */
|
||||
#define PLL_P 2
|
||||
|
||||
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
|
||||
#define PLL_Q 7
|
||||
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
|
||||
#define PLL_Q 2
|
||||
#else
|
||||
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
|
||||
#define PLL_M 12
|
||||
#define PLL_N 336
|
||||
|
||||
/* SYSCLK = PLL_VCO / PLL_P */
|
||||
#define PLL_P 2
|
||||
|
||||
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
|
||||
#define PLL_Q 7
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
@@ -178,8 +189,11 @@
|
||||
/** @addtogroup STM32F4xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(STM32F413xx)
|
||||
uint32_t SystemCoreClock = 100000000;
|
||||
#else
|
||||
uint32_t SystemCoreClock = 168000000;
|
||||
#endif
|
||||
|
||||
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
__I uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "watchdog_driver.h"
|
||||
|
||||
void waitFlashIdle()
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "flysky_gimbal_driver.h"
|
||||
#include "stm32_serial_driver.h"
|
||||
#include "delays_driver.h"
|
||||
#include "hal/adc_driver.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "crc.h"
|
||||
@@ -46,20 +47,8 @@ DEFINE_STM32_SERIAL_PORT(FSGimbal, fsUSART, HALLSTICK_BUFF_SIZE, 0);
|
||||
|
||||
static STRUCT_HALL HallProtocol = { 0 };
|
||||
|
||||
signed short hall_raw_values[FLYSKY_HALL_CHANNEL_COUNT];
|
||||
unsigned short hall_adc_values[FLYSKY_HALL_CHANNEL_COUNT];
|
||||
|
||||
static void* _fs_usart_ctx = nullptr;
|
||||
|
||||
uint16_t get_flysky_hall_adc_value(uint8_t ch)
|
||||
{
|
||||
if (ch >= FLYSKY_HALL_CHANNEL_COUNT) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 2 * FLYSKY_OFFSET_VALUE - hall_adc_values[ch];
|
||||
}
|
||||
|
||||
static int _fs_get_byte(uint8_t* data)
|
||||
{
|
||||
return STM32SerialDriver.getByte(_fs_usart_ctx, data);
|
||||
@@ -130,33 +119,31 @@ static volatile bool _fs_gimbal_detected;
|
||||
|
||||
static void flysky_gimbal_loop()
|
||||
{
|
||||
uint8_t byte;
|
||||
uint8_t byte;
|
||||
|
||||
while(_fs_get_byte(&byte))
|
||||
{
|
||||
HallProtocol.index++;
|
||||
while (_fs_get_byte(&byte)) {
|
||||
HallProtocol.index++;
|
||||
|
||||
_fs_parse(&HallProtocol, byte);
|
||||
if ( HallProtocol.msg_OK )
|
||||
{
|
||||
HallProtocol.msg_OK = 0;
|
||||
HallProtocol.stickState = HallProtocol.data[HallProtocol.length - 1];
|
||||
_fs_parse(&HallProtocol, byte);
|
||||
if (HallProtocol.msg_OK) {
|
||||
HallProtocol.msg_OK = 0;
|
||||
HallProtocol.stickState = HallProtocol.data[HallProtocol.length - 1];
|
||||
|
||||
switch ( HallProtocol.hallID.hall_Id.receiverID )
|
||||
{
|
||||
case TRANSFER_DIR_TXMCU:
|
||||
if(HallProtocol.hallID.hall_Id.packetID == FLYSKY_HALL_RESP_TYPE_VALUES) {
|
||||
memcpy(hall_raw_values, HallProtocol.data, sizeof(hall_raw_values));
|
||||
for ( uint8_t channel = 0; channel < 4; channel++ )
|
||||
{
|
||||
hall_adc_values[channel] = FLYSKY_OFFSET_VALUE + hall_raw_values[channel];
|
||||
}
|
||||
}
|
||||
break;
|
||||
switch (HallProtocol.hallID.hall_Id.receiverID) {
|
||||
case TRANSFER_DIR_TXMCU:
|
||||
if (HallProtocol.hallID.hall_Id.packetID ==
|
||||
FLYSKY_HALL_RESP_TYPE_VALUES) {
|
||||
int16_t* p_values = (int16_t*)HallProtocol.data;
|
||||
uint16_t* adcValues = getAnalogValues();
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
adcValues[i] = FLYSKY_OFFSET_VALUE - p_values[i];
|
||||
}
|
||||
_fs_gimbal_detected = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
_fs_gimbal_detected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void flysky_gimbal_deinit()
|
||||
|
||||
@@ -19,12 +19,11 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "mixer_scheduler.h"
|
||||
|
||||
#if !defined(SIMU)
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#include "FreeRTOSConfig.h"
|
||||
#include "hal.h"
|
||||
|
||||
// Start scheduler with default period
|
||||
void mixerSchedulerStart()
|
||||
@@ -81,5 +80,3 @@ extern "C" void MIXER_SCHEDULER_TIMER_IRQHandler(void)
|
||||
// trigger mixer start
|
||||
mixerSchedulerISRTrigger();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "watchdog_driver.h"
|
||||
|
||||
void pwrInit()
|
||||
{
|
||||
@@ -107,9 +108,22 @@ bool pwrForcePressed()
|
||||
bool pwrPressed()
|
||||
{
|
||||
#if defined(PWR_EXTRA_SWITCH_GPIO)
|
||||
return (GPIO_ReadInputDataBit(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET || GPIO_ReadInputDataBit(PWR_EXTRA_SWITCH_GPIO, PWR_EXTRA_SWITCH_GPIO_PIN) == Bit_RESET);
|
||||
return (GPIO_ReadInputDataBit(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN) ==
|
||||
Bit_RESET ||
|
||||
GPIO_ReadInputDataBit(PWR_EXTRA_SWITCH_GPIO,
|
||||
PWR_EXTRA_SWITCH_GPIO_PIN) == Bit_RESET);
|
||||
#else
|
||||
return GPIO_ReadInputDataBit(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET;
|
||||
return GPIO_ReadInputDataBit(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN) ==
|
||||
Bit_RESET;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool pwrOffPressed()
|
||||
{
|
||||
#if defined(PWR_BUTTON_PRESS)
|
||||
return pwrPressed();
|
||||
#else
|
||||
return !pwrPressed();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,13 @@
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_exti_driver.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "board.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "hal/key_driver.h"
|
||||
#include "hal/rotary_encoder.h"
|
||||
|
||||
#include "board_common.h"
|
||||
|
||||
#if !defined(BOOT)
|
||||
@@ -43,6 +47,16 @@ volatile uint32_t rotencDt = 0;
|
||||
(g_eeGeneral.rotEncMode == ROTARY_ENCODER_MODE_INVERT_BOTH ? -2 : 2);
|
||||
#endif
|
||||
|
||||
rotenc_t rotaryEncoderGetValue()
|
||||
{
|
||||
return rotencValue / ROTARY_ENCODER_GRANULARITY;
|
||||
}
|
||||
|
||||
rotenc_t rotaryEncoderGetRawValue()
|
||||
{
|
||||
return rotencValue;
|
||||
}
|
||||
|
||||
void rotaryEncoderCheck()
|
||||
{
|
||||
static uint8_t state = 0;
|
||||
@@ -131,6 +145,15 @@ void rotaryEncoderStartDelay()
|
||||
|
||||
void rotaryEncoderInit()
|
||||
{
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
pinInit.Pull = LL_GPIO_PULL_UP;
|
||||
pinInit.Pin = ROTARY_ENCODER_GPIO_PIN_A | ROTARY_ENCODER_GPIO_PIN_B;
|
||||
|
||||
stm32_gpio_enable_clock(ROTARY_ENCODER_GPIO);
|
||||
LL_GPIO_Init(ROTARY_ENCODER_GPIO, &pinInit);
|
||||
|
||||
ROTARY_ENCODER_TIMER->ARR = 99; // 100uS
|
||||
ROTARY_ENCODER_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1; // 1uS
|
||||
ROTARY_ENCODER_TIMER->CCER = 0;
|
||||
|
||||
@@ -91,8 +91,17 @@ void rtcInit()
|
||||
rtcGetTime(&utm);
|
||||
g_rtcTime = gmktime(&utm);
|
||||
#endif
|
||||
|
||||
#if defined(RTC_BACKUP_RAM) && !defined(BOOT)
|
||||
__HAL_RCC_BKPSRAM_CLK_ENABLE();
|
||||
HAL_PWREx_EnableBkUpReg();
|
||||
#endif
|
||||
}
|
||||
|
||||
void rtcDisableBackupReg()
|
||||
{
|
||||
#if defined(RTC_BACKUP_RAM)
|
||||
__HAL_RCC_BKPSRAM_CLK_DISABLE();
|
||||
HAL_PWREx_DisableBkUpReg();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@
|
||||
#include "sdio_sd.h"
|
||||
#include "debug.h"
|
||||
|
||||
#if defined(STM32F4)
|
||||
#include "stm32f4xx_sdio.h"
|
||||
#elif defined(STM32F2)
|
||||
#include "stm32f2xx_sdio.h"
|
||||
#endif
|
||||
|
||||
#define SDIO_STATIC_FLAGS ((uint32_t)0x000005FF)
|
||||
#define SDIO_CMD0TIMEOUT ((uint32_t)0x00010000)
|
||||
|
||||
|
||||
@@ -19,25 +19,24 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "hal/adc_driver.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "delays_driver.h"
|
||||
|
||||
volatile uint32_t pwm_interrupt_count = 0;
|
||||
volatile uint16_t timer_capture_values[NUM_PWMSTICKS];
|
||||
#include "hal.h"
|
||||
#include "dataconstants.h"
|
||||
|
||||
void sticksPwmInit()
|
||||
static volatile uint32_t pwm_interrupt_count;
|
||||
|
||||
static void sticksPwmInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = PWM_GPIOA_PINS;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(PWM_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_PinAFConfig(PWM_GPIO, GPIO_PinSource0, PWM_GPIO_AF);
|
||||
GPIO_PinAFConfig(PWM_GPIO, GPIO_PinSource1, PWM_GPIO_AF);
|
||||
GPIO_PinAFConfig(PWM_GPIO, GPIO_PinSource2, PWM_GPIO_AF);
|
||||
GPIO_PinAFConfig(PWM_GPIO, GPIO_PinSource3, PWM_GPIO_AF);
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
pinInit.Pin = PWM_GPIOA_PINS;
|
||||
pinInit.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
pinInit.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
pinInit.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
pinInit.Pull = LL_GPIO_PULL_UP;
|
||||
LL_GPIO_Init(PWM_GPIO, &pinInit);
|
||||
|
||||
PWM_TIMER->CR1 &= ~TIM_CR1_CEN; // Stop timer
|
||||
PWM_TIMER->PSC = 80;
|
||||
@@ -45,14 +44,39 @@ void sticksPwmInit()
|
||||
PWM_TIMER->CCMR1 = TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0;
|
||||
PWM_TIMER->CCMR2 = TIM_CCMR2_CC3S_0 | TIM_CCMR2_CC4S_0;
|
||||
PWM_TIMER->CCER = TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E;
|
||||
PWM_TIMER->DIER |= TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4;
|
||||
PWM_TIMER->DIER |= TIM_DIER_CC1IE | TIM_DIER_CC2IE | TIM_DIER_CC3IE | TIM_DIER_CC4IE;
|
||||
PWM_TIMER->CR1 = TIM_CR1_CEN; // Start timer
|
||||
|
||||
NVIC_EnableIRQ(PWM_IRQn);
|
||||
NVIC_SetPriority(PWM_IRQn, 10);
|
||||
}
|
||||
|
||||
inline uint32_t TIM_GetCapture_Stick(uint8_t n)
|
||||
static void sticksPwmDeInit()
|
||||
{
|
||||
NVIC_DisableIRQ(PWM_IRQn);
|
||||
PWM_TIMER->CR1 &= ~TIM_CR1_CEN; // Stop timer
|
||||
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = PWM_GPIOA_PINS;
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
LL_GPIO_Init(PWM_GPIO, &pinInit);
|
||||
}
|
||||
|
||||
bool sticksPwmDetect()
|
||||
{
|
||||
pwm_interrupt_count = 0;
|
||||
sticksPwmInit();
|
||||
delay_ms(20);
|
||||
if (pwm_interrupt_count < 32) {
|
||||
sticksPwmDeInit();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline uint32_t TIM_GetCapture_Stick(uint8_t n)
|
||||
{
|
||||
switch (n) {
|
||||
case 0:
|
||||
@@ -68,22 +92,22 @@ inline uint32_t TIM_GetCapture_Stick(uint8_t n)
|
||||
}
|
||||
}
|
||||
|
||||
inline void TIM_SetPolarityRising(uint8_t n)
|
||||
static inline void TIM_SetPolarityRising(uint8_t n)
|
||||
{
|
||||
PWM_TIMER->CCER &= ~(TIM_CCER_CC1P << (n * 4));
|
||||
}
|
||||
|
||||
inline void TIM_SetPolarityFalling(uint8_t n)
|
||||
static inline void TIM_SetPolarityFalling(uint8_t n)
|
||||
{
|
||||
PWM_TIMER->CCER |= (TIM_CCER_CC1P << (n * 4));
|
||||
}
|
||||
|
||||
inline void TIM_ClearITPendingBit(uint8_t n)
|
||||
static inline void TIM_ClearITPendingBit(uint8_t n)
|
||||
{
|
||||
PWM_TIMER->SR = ~(TIM_IT_CC1 << n);
|
||||
PWM_TIMER->SR = ~(TIM_SR_CC1IF << n);
|
||||
}
|
||||
|
||||
inline uint32_t diff_with_16bits_overflow(uint32_t a, uint32_t b)
|
||||
static inline uint32_t diff_with_16bits_overflow(uint32_t a, uint32_t b)
|
||||
{
|
||||
if (b > a)
|
||||
return b - a;
|
||||
@@ -91,19 +115,45 @@ inline uint32_t diff_with_16bits_overflow(uint32_t a, uint32_t b)
|
||||
return b + 0xffff - a;
|
||||
}
|
||||
|
||||
#if !defined(STICK_PWM_CHANNEL_0)
|
||||
#define STICK_PWM_CHANNEL_0 0
|
||||
#endif
|
||||
|
||||
#if !defined(STICK_PWM_CHANNEL_1)
|
||||
#define STICK_PWM_CHANNEL_1 1
|
||||
#endif
|
||||
|
||||
#if !defined(STICK_PWM_CHANNEL_2)
|
||||
#define STICK_PWM_CHANNEL_2 2
|
||||
#endif
|
||||
|
||||
#if !defined(STICK_PWM_CHANNEL_3)
|
||||
#define STICK_PWM_CHANNEL_3 3
|
||||
#endif
|
||||
|
||||
static const uint8_t _channel_map[] = {
|
||||
STICK_PWM_CHANNEL_0,
|
||||
STICK_PWM_CHANNEL_1,
|
||||
STICK_PWM_CHANNEL_2,
|
||||
STICK_PWM_CHANNEL_3,
|
||||
};
|
||||
|
||||
extern "C" void PWM_IRQHandler(void)
|
||||
{
|
||||
static uint8_t timer_capture_states[NUM_PWMSTICKS];
|
||||
static uint32_t timer_capture_rising_time[NUM_PWMSTICKS];
|
||||
static uint8_t timer_capture_states[MAX_STICKS];
|
||||
static uint32_t timer_capture_rising_time[MAX_STICKS];
|
||||
|
||||
for (uint8_t i=0; i<NUM_PWMSTICKS; i++) {
|
||||
if (PWM_TIMER->SR & (TIM_DIER_CC1IE << i)) {
|
||||
auto adcValues = getAnalogValues();
|
||||
|
||||
for (uint8_t i=0; i<MAX_STICKS; i++) {
|
||||
if (PWM_TIMER->SR & (TIM_SR_CC1IF << i)) {
|
||||
uint32_t capture = TIM_GetCapture_Stick(i);
|
||||
pwm_interrupt_count++; // overflow may happen but we only use this to detect PWM / ADC on radio startup
|
||||
// overflow may happen but we only use this to detect PWM / ADC on radio startup
|
||||
pwm_interrupt_count++;
|
||||
if (timer_capture_states[i] != 0) {
|
||||
uint32_t value = diff_with_16bits_overflow(timer_capture_rising_time[i], capture);
|
||||
if (value < 10000) {
|
||||
timer_capture_values[i] = (uint16_t) value;
|
||||
adcValues[_channel_map[i]] = (uint16_t) value;
|
||||
}
|
||||
TIM_SetPolarityRising(i);
|
||||
timer_capture_states[i] = 0;
|
||||
@@ -117,21 +167,3 @@ extern "C" void PWM_IRQHandler(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(STICK_CHANNEL_CHANGE)
|
||||
void sticksPwmRead(uint16_t * values)
|
||||
{
|
||||
values[0] = timer_capture_values[STICK_PWM_CHANNEL_0];
|
||||
values[1] = timer_capture_values[STICK_PWM_CHANNEL_1];
|
||||
values[2] = timer_capture_values[STICK_PWM_CHANNEL_2];
|
||||
values[3] = timer_capture_values[STICK_PWM_CHANNEL_3];
|
||||
}
|
||||
#else
|
||||
void sticksPwmRead(uint16_t * values)
|
||||
{
|
||||
values[0] = timer_capture_values[0];
|
||||
values[1] = timer_capture_values[1];
|
||||
values[2] = timer_capture_values[3];
|
||||
values[3] = timer_capture_values[2];
|
||||
}
|
||||
#endif
|
||||
|
||||
+2
-4
@@ -21,7 +21,5 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stm32_pulse_driver.h"
|
||||
|
||||
// used in module_ports.cpp
|
||||
extern const stm32_pulse_timer_t intmoduleTimer;
|
||||
// returns 'true' if PWM sticks have been detected
|
||||
bool sticksPwmDetect();
|
||||
@@ -0,0 +1,582 @@
|
||||
/*
|
||||
* 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 "stm32_adc.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define ADC_COMMON ((ADC_Common_TypeDef *) ADC_BASE)
|
||||
#define MAX_ADC_INPUTS 32
|
||||
#define OVERSAMPLING 4
|
||||
|
||||
// Please note that we use the same prio for DMA TC and ADC IRQs
|
||||
// to avoid issues with preemption between these 2
|
||||
#define ADC_IRQ_PRIO configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
|
||||
|
||||
// Max 32 inputs supported
|
||||
static uint32_t _adc_input_mask;
|
||||
static volatile uint32_t _adc_inhibit_mask;
|
||||
|
||||
// DMA buffers
|
||||
static uint16_t _adc_dma_buffer[MAX_ADC_INPUTS] __DMA;
|
||||
|
||||
// ADCs started
|
||||
static uint8_t _adc_started_mask;
|
||||
static volatile uint8_t _adc_completed;
|
||||
|
||||
static const stm32_adc_t* _adc_ADCs;
|
||||
static uint8_t _adc_n_ADC;
|
||||
static const stm32_adc_input_t* _adc_inputs;
|
||||
static uint8_t _adc_n_inputs;
|
||||
|
||||
// Need for oversampling and decimation
|
||||
static uint8_t _adc_run;
|
||||
static uint8_t _adc_oversampling_disabled;
|
||||
static uint16_t _adc_oversampling[MAX_ADC_INPUTS];
|
||||
|
||||
// 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()
|
||||
{
|
||||
if (adcGetMaxInputs(ADC_INPUT_RTC_BAT) < 1) return;
|
||||
|
||||
// Set internal measurement path for vbat sensor
|
||||
LL_ADC_SetCommonPathInternalCh(ADC_COMMON, LL_ADC_PATH_INTERNAL_VBAT);
|
||||
|
||||
auto channel = adcGetInputOffset(ADC_INPUT_RTC_BAT);
|
||||
_adc_inhibit_mask &= ~(1 << channel);
|
||||
}
|
||||
|
||||
void disableVBatBridge()
|
||||
{
|
||||
if (adcGetMaxInputs(ADC_INPUT_RTC_BAT) < 1) return;
|
||||
|
||||
auto channel = adcGetInputOffset(ADC_INPUT_RTC_BAT);
|
||||
_adc_inhibit_mask |= (1 << channel);
|
||||
|
||||
// Set internal measurement path to none
|
||||
LL_ADC_SetCommonPathInternalCh(ADC_COMMON, LL_ADC_PATH_INTERNAL_NONE);
|
||||
}
|
||||
|
||||
bool isVBatBridgeEnabled()
|
||||
{
|
||||
// && !(_adc_inhibit_mask & (1 << channel));
|
||||
return LL_ADC_GetCommonPathInternalCh(ADC_COMMON) == LL_ADC_PATH_INTERNAL_VBAT;
|
||||
}
|
||||
|
||||
static void adc_enable_clock(ADC_TypeDef* ADCx)
|
||||
{
|
||||
uint32_t adc_idx = (((uint32_t) ADCx) - ADC1_BASE) / 0x100UL;
|
||||
uint32_t adc_msk = RCC_APB2ENR_ADC1EN << adc_idx;
|
||||
LL_APB2_GRP1_EnableClock(adc_msk);
|
||||
}
|
||||
|
||||
static bool adc_disable_dma(DMA_TypeDef* DMAx, uint32_t stream);
|
||||
static void adc_dma_clear_flags(DMA_TypeDef* DMAx, uint32_t stream);
|
||||
|
||||
static void adc_init_pins(const stm32_adc_gpio_t* GPIOs, uint8_t n_GPIO)
|
||||
{
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Mode = LL_GPIO_MODE_ANALOG;
|
||||
pinInit.Pull = LL_GPIO_PULL_NO;
|
||||
|
||||
const stm32_adc_gpio_t* gpio = GPIOs;
|
||||
while (n_GPIO > 0) {
|
||||
|
||||
pinInit.Pin = 0;
|
||||
|
||||
for (uint8_t pin_idx = 0; pin_idx < gpio->n_pins; pin_idx++) {
|
||||
|
||||
uint32_t pin = gpio->pins[pin_idx];
|
||||
uint32_t mode = LL_GPIO_GetPinMode(gpio->GPIOx, pin);
|
||||
|
||||
// Output or AF: pin is probably used somewhere else
|
||||
if (mode != LL_GPIO_MODE_INPUT && mode != LL_GPIO_MODE_ANALOG) continue;
|
||||
|
||||
pinInit.Pin |= pin;
|
||||
}
|
||||
|
||||
stm32_gpio_enable_clock(gpio->GPIOx);
|
||||
LL_GPIO_Init(gpio->GPIOx, &pinInit);
|
||||
gpio++; n_GPIO--;
|
||||
}
|
||||
}
|
||||
|
||||
static const uint32_t _seq_length_lookup[] = {
|
||||
LL_ADC_REG_SEQ_SCAN_DISABLE,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS,
|
||||
};
|
||||
|
||||
static void adc_setup_scan_mode(ADC_TypeDef* ADCx, uint8_t nconv)
|
||||
{
|
||||
// ADC must be disabled for the functions used here
|
||||
LL_ADC_Disable(ADCx);
|
||||
|
||||
LL_ADC_InitTypeDef adcInit;
|
||||
LL_ADC_StructInit(&adcInit);
|
||||
|
||||
if (nconv > 1) {
|
||||
adcInit.SequencersScanMode = LL_ADC_SEQ_SCAN_ENABLE;
|
||||
} else {
|
||||
adcInit.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE;
|
||||
}
|
||||
|
||||
adcInit.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
|
||||
LL_ADC_Init(ADCx, &adcInit);
|
||||
|
||||
LL_ADC_REG_InitTypeDef adcRegInit;
|
||||
LL_ADC_REG_StructInit(&adcRegInit);
|
||||
|
||||
adcRegInit.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
|
||||
adcRegInit.ContinuousMode = LL_ADC_REG_CONV_SINGLE;
|
||||
|
||||
if (nconv > 1) {
|
||||
adcRegInit.SequencerLength = _seq_length_lookup[nconv - 1];
|
||||
adcRegInit.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED;
|
||||
}
|
||||
|
||||
LL_ADC_REG_Init(ADCx, &adcRegInit);
|
||||
|
||||
// Enable ADC
|
||||
// TODO: check ADC_CR2_DDS (normally only for circular DMA
|
||||
// but the old was using it (no clue why)
|
||||
LL_ADC_Enable(ADCx);
|
||||
}
|
||||
|
||||
static const uint32_t _rank_lookup[] = {
|
||||
LL_ADC_REG_RANK_1,
|
||||
LL_ADC_REG_RANK_2,
|
||||
LL_ADC_REG_RANK_3,
|
||||
LL_ADC_REG_RANK_4,
|
||||
LL_ADC_REG_RANK_5,
|
||||
LL_ADC_REG_RANK_6,
|
||||
LL_ADC_REG_RANK_7,
|
||||
LL_ADC_REG_RANK_8,
|
||||
LL_ADC_REG_RANK_9,
|
||||
LL_ADC_REG_RANK_10,
|
||||
LL_ADC_REG_RANK_11,
|
||||
LL_ADC_REG_RANK_12,
|
||||
LL_ADC_REG_RANK_13,
|
||||
LL_ADC_REG_RANK_14,
|
||||
LL_ADC_REG_RANK_15,
|
||||
LL_ADC_REG_RANK_16,
|
||||
};
|
||||
|
||||
static uint8_t adc_init_channels(const stm32_adc_t* adc,
|
||||
const stm32_adc_input_t* inputs,
|
||||
const uint8_t* chan,
|
||||
uint8_t nconv)
|
||||
{
|
||||
if (!chan || !nconv) return 0;
|
||||
|
||||
uint8_t rank = 0;
|
||||
uint32_t channel_mask = 0;
|
||||
|
||||
while (nconv > 0) {
|
||||
|
||||
uint8_t input_idx = *chan;
|
||||
const stm32_adc_input_t* input = &inputs[input_idx];
|
||||
|
||||
// internal channel don't have a GPIO + pin defined
|
||||
uint32_t mask = (1 << (ADC_CHANNEL_ID_MASK & input->ADC_Channel));
|
||||
if (!__LL_ADC_IS_CHANNEL_INTERNAL(input->ADC_Channel)) {
|
||||
uint32_t mode = LL_GPIO_GetPinMode(input->GPIOx, input->GPIO_Pin);
|
||||
if (mode != LL_GPIO_MODE_ANALOG) {
|
||||
// skip channel
|
||||
nconv--; chan++;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// Internal channels are inhibited until explicitely enabled
|
||||
_adc_inhibit_mask |= mask;
|
||||
}
|
||||
|
||||
// channel is already used, probably a secondary input
|
||||
// using the same ADC channel
|
||||
if (channel_mask & mask) {
|
||||
nconv--; chan++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// update mask for used channels
|
||||
channel_mask |= mask;
|
||||
|
||||
// update mask for valid inputs
|
||||
_adc_input_mask |= (1 << input_idx);
|
||||
|
||||
LL_ADC_REG_SetSequencerRanks(adc->ADCx, _rank_lookup[rank],
|
||||
input->ADC_Channel);
|
||||
|
||||
LL_ADC_SetChannelSamplingTime(adc->ADCx, input->ADC_Channel,
|
||||
adc->sample_time);
|
||||
|
||||
|
||||
nconv--;
|
||||
rank++;
|
||||
chan++;
|
||||
}
|
||||
|
||||
return rank;
|
||||
}
|
||||
|
||||
static bool adc_init_dma_stream(ADC_TypeDef* adc, DMA_TypeDef* DMAx,
|
||||
uint32_t stream, uint32_t channel,
|
||||
uint16_t* dest, uint8_t nconv)
|
||||
{
|
||||
// Disable DMA before continuing (see ref. manual "Stream configuration procedure")
|
||||
if (!adc_disable_dma(DMAx, stream))
|
||||
return false;
|
||||
|
||||
// Clear Interrupt flags
|
||||
adc_dma_clear_flags(DMAx, stream);
|
||||
|
||||
// setup DMA request
|
||||
LL_DMA_ConfigAddresses(DMAx, stream, CONVERT_PTR_UINT(&adc->DR),
|
||||
CONVERT_PTR_UINT(dest),
|
||||
LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
|
||||
LL_DMA_SetDataLength(DMAx, stream, nconv);
|
||||
LL_DMA_SetChannelSelection(DMAx, stream, channel);
|
||||
|
||||
// Very high priority, 1 byte transfers, increment memory
|
||||
LL_DMA_ConfigTransfer(DMAx, stream,
|
||||
LL_DMA_PRIORITY_VERYHIGH | LL_DMA_MDATAALIGN_HALFWORD |
|
||||
LL_DMA_PDATAALIGN_HALFWORD | LL_DMA_MEMORY_INCREMENT |
|
||||
LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
|
||||
|
||||
// disable direct mode, half full FIFO
|
||||
LL_DMA_EnableFifoMode(DMAx, stream);
|
||||
LL_DMA_SetFIFOThreshold(DMAx, stream, LL_DMA_FIFOTHRESHOLD_1_2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool stm32_hal_adc_init(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
const stm32_adc_input_t* inputs,
|
||||
const stm32_adc_gpio_t* ADC_GPIOs, uint8_t n_GPIO)
|
||||
{
|
||||
_adc_input_mask = 0;
|
||||
_adc_inhibit_mask = 0;
|
||||
_adc_oversampling_disabled = 0;
|
||||
|
||||
adc_init_pins(ADC_GPIOs, n_GPIO);
|
||||
|
||||
// Init common to all ADCs
|
||||
LL_ADC_CommonInitTypeDef commonInit;
|
||||
LL_ADC_CommonStructInit(&commonInit);
|
||||
|
||||
commonInit.CommonClock = LL_ADC_CLOCK_SYNC_PCLK_DIV2;
|
||||
LL_ADC_CommonInit(ADC_COMMON, &commonInit);
|
||||
|
||||
_adc_input_mask = 0;
|
||||
// uint16_t* dma_buffer = _adc_dma_buffer;
|
||||
const stm32_adc_t* adc = ADCs;
|
||||
while (n_ADC > 0) {
|
||||
|
||||
uint8_t nconv = adc->n_channels;
|
||||
if (nconv > 0) {
|
||||
|
||||
// enable periph clock
|
||||
adc_enable_clock(adc->ADCx);
|
||||
|
||||
// configure each channel
|
||||
const uint8_t* chan = adc->channels;
|
||||
nconv = adc_init_channels(adc, inputs, chan, nconv);
|
||||
adc_setup_scan_mode(adc->ADCx, nconv);
|
||||
|
||||
if (nconv > 1) {
|
||||
if (adc->DMAx) {
|
||||
uint16_t* dma_buffer = _adc_dma_buffer + adc->offset;
|
||||
if (!adc_init_dma_stream(adc->ADCx, adc->DMAx, adc->DMA_Stream,
|
||||
adc->DMA_Channel, dma_buffer, nconv))
|
||||
return false;
|
||||
|
||||
NVIC_SetPriority(adc->DMA_Stream_IRQn, ADC_IRQ_PRIO);
|
||||
NVIC_EnableIRQ(adc->DMA_Stream_IRQn);
|
||||
} else {
|
||||
// multiple channels on the same ADC
|
||||
// without a DMA is NOT supported
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// single conversion
|
||||
NVIC_SetPriority(ADC_IRQn, ADC_IRQ_PRIO);
|
||||
NVIC_EnableIRQ(ADC_IRQn);
|
||||
}
|
||||
}
|
||||
|
||||
// move to next ADC definition
|
||||
adc++; n_ADC--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define DMA_Stream0_IT_MASK (uint32_t)(DMA_LISR_FEIF0 | DMA_LISR_DMEIF0 | \
|
||||
DMA_LISR_TEIF0 | DMA_LISR_HTIF0 | \
|
||||
DMA_LISR_TCIF0)
|
||||
|
||||
#define DMA_Stream4_IT_MASK (uint32_t)(DMA_HISR_FEIF4 | DMA_HISR_DMEIF4 | \
|
||||
DMA_HISR_TEIF4 | DMA_HISR_HTIF4 | \
|
||||
DMA_HISR_TCIF4)
|
||||
|
||||
static void adc_dma_clear_flags(DMA_TypeDef* DMAx, uint32_t stream)
|
||||
{
|
||||
// no other choice, sorry for that...
|
||||
if (stream == LL_DMA_STREAM_4) {
|
||||
/* Reset interrupt pending bits for DMA2 Stream4 */
|
||||
WRITE_REG(DMAx->HIFCR, DMA_Stream4_IT_MASK);
|
||||
|
||||
} else if (stream == LL_DMA_STREAM_0) {
|
||||
/* Reset interrupt pending bits for DMA2 Stream0 */
|
||||
WRITE_REG(DMAx->LIFCR, DMA_Stream0_IT_MASK);
|
||||
}
|
||||
}
|
||||
|
||||
static inline DMA_Stream_TypeDef* _dma_get_stream(DMA_TypeDef *DMAx, uint32_t Stream)
|
||||
{
|
||||
return ((DMA_Stream_TypeDef*)((uint32_t)((uint32_t)DMAx + STREAM_OFFSET_TAB[Stream])));
|
||||
}
|
||||
|
||||
static void adc_start_dma_conversion(ADC_TypeDef* ADCx, DMA_TypeDef* DMAx, uint32_t stream)
|
||||
{
|
||||
// Clear Interrupt flags
|
||||
adc_dma_clear_flags(DMAx, stream);
|
||||
|
||||
// Clear ADC status register & disable ADC IRQ
|
||||
CLEAR_BIT(ADCx->SR, ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
|
||||
CLEAR_BIT(ADCx->CR1, ADC_CR1_EOCIE);
|
||||
|
||||
// Enable DMA
|
||||
auto dma_stream = _dma_get_stream(DMAx, stream);
|
||||
SET_BIT(dma_stream->CR, DMA_SxCR_TCIE | DMA_SxCR_TEIE | DMA_SxCR_DMEIE);
|
||||
SET_BIT(dma_stream->CR, DMA_SxCR_EN);
|
||||
|
||||
// Trigger ADC start
|
||||
SET_BIT(ADCx->CR2, ADC_CR2_SWSTART);
|
||||
}
|
||||
|
||||
static bool adc_disable_dma(DMA_TypeDef* DMAx, uint32_t stream)
|
||||
{
|
||||
LL_DMA_DisableStream(DMAx, stream);
|
||||
|
||||
// wait until DMA EN bit gets cleared by hardware
|
||||
uint16_t timeout = 1000;
|
||||
while (LL_DMA_IsEnabledStream(DMAx, stream)) {
|
||||
if (--timeout == 0) {
|
||||
// Timeout. Failed to disable DMA
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void adc_start_normal_conversion(ADC_TypeDef* ADCx)
|
||||
{
|
||||
// clear status flags
|
||||
CLEAR_BIT(ADCx->SR, ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
|
||||
|
||||
// enble ADC IRQ
|
||||
SET_BIT(ADCx->CR1, ADC_CR1_EOCIE);
|
||||
|
||||
// and start!
|
||||
SET_BIT(ADCx->CR2, ADC_CR2_SWSTART);
|
||||
}
|
||||
|
||||
static void adc_start_read(const stm32_adc_t* ADCs, uint8_t n_ADC)
|
||||
{
|
||||
// Start all ADCs in parallel
|
||||
|
||||
uint8_t adc_mask = 1;
|
||||
_adc_started_mask = 0;
|
||||
|
||||
const stm32_adc_t* adc = ADCs;
|
||||
while (n_ADC > 0) {
|
||||
|
||||
// if the ADC has no active channels,
|
||||
// it has not been enabled at all
|
||||
auto ADCx = adc->ADCx;
|
||||
if (!LL_ADC_IsEnabled(ADCx)) {
|
||||
adc++; n_ADC--; adc_mask <<= 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// more than one channel enabled on this ADC
|
||||
if (LL_ADC_GetSequencersScanMode(ADCx) == LL_ADC_SEQ_SCAN_ENABLE) {
|
||||
|
||||
// Disable DMA before continuing (see ref. manual "Stream configuration procedure")
|
||||
auto DMAx = adc->DMAx;
|
||||
auto stream = adc->DMA_Stream;
|
||||
if (DMAx && adc_disable_dma(DMAx, stream)) {
|
||||
_adc_started_mask |= adc_mask;
|
||||
adc_start_dma_conversion(ADCx, DMAx, stream);
|
||||
}
|
||||
|
||||
} else {
|
||||
// only one channel
|
||||
_adc_started_mask |= adc_mask;
|
||||
adc_start_normal_conversion(ADCx);
|
||||
}
|
||||
|
||||
// move to next ADC
|
||||
adc++; n_ADC--; adc_mask <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool stm32_hal_adc_start_read(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
const stm32_adc_input_t* inputs, uint8_t n_inputs)
|
||||
{
|
||||
_adc_completed = 0;
|
||||
_adc_run = 0;
|
||||
|
||||
_adc_ADCs = ADCs;
|
||||
_adc_n_ADC = n_ADC;
|
||||
_adc_inputs = inputs;
|
||||
_adc_n_inputs = n_inputs;
|
||||
|
||||
memclear(_adc_oversampling, sizeof(_adc_oversampling));
|
||||
adc_start_read(_adc_ADCs, _adc_n_ADC);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void copy_adc_values(uint16_t* src, const stm32_adc_t* adc,
|
||||
const stm32_adc_input_t* inputs)
|
||||
{
|
||||
for (uint8_t i=0; i < adc->n_channels; i++) {
|
||||
uint8_t channel = adc->channels[i];
|
||||
|
||||
// if input disabled, skip
|
||||
if (~_adc_input_mask & (1 << channel)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip sampled but inhibited channels
|
||||
if (_adc_inhibit_mask & (1 << channel)) {
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: move inversion to the generic ADC driver?
|
||||
if (inputs[channel].inverted)
|
||||
_adc_oversampling[channel] += ADC_INVERT_VALUE(*src);
|
||||
else
|
||||
_adc_oversampling[channel] += *src;
|
||||
|
||||
#if defined(JITTER_MEASURE)
|
||||
if (JITTER_MEASURE_ACTIVE()) {
|
||||
rawJitter[channel].measure(dst[channel]);
|
||||
}
|
||||
#endif
|
||||
|
||||
src++;
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_hal_adc_wait_completion(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
const stm32_adc_input_t* inputs, uint8_t n_inputs)
|
||||
{
|
||||
(void)ADCs;
|
||||
(void)n_ADC;
|
||||
(void)inputs;
|
||||
(void)n_inputs;
|
||||
|
||||
while(!_adc_completed) {
|
||||
// busy wait
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_hal_adc_disable_oversampling()
|
||||
{
|
||||
_adc_oversampling_disabled = 1;
|
||||
}
|
||||
|
||||
static void _adc_mark_completed(const stm32_adc_t* adc)
|
||||
{
|
||||
uint8_t adc_idx = (adc - _adc_ADCs);
|
||||
_adc_started_mask &= ~(1 << adc_idx);
|
||||
}
|
||||
|
||||
static void _adc_chain_conversions(const stm32_adc_t* adc)
|
||||
{
|
||||
_adc_mark_completed(adc);
|
||||
if (_adc_started_mask != 0) return;
|
||||
|
||||
if (!_adc_oversampling_disabled && (++_adc_run < OVERSAMPLING)) {
|
||||
adc_start_read(_adc_ADCs, _adc_n_ADC);
|
||||
return;
|
||||
}
|
||||
|
||||
auto adcValues = getAnalogValues();
|
||||
for (uint8_t i = 0; i < _adc_n_inputs; i++) {
|
||||
if (~_adc_input_mask & (1 << i)) continue;
|
||||
if (_adc_inhibit_mask & (1 << i)) continue;
|
||||
adcValues[i] = _adc_oversampling[i] / OVERSAMPLING;
|
||||
}
|
||||
|
||||
// we're done!
|
||||
_adc_completed = 1;
|
||||
}
|
||||
|
||||
void stm32_hal_adc_dma_isr(const stm32_adc_t* adc)
|
||||
{
|
||||
// Disable IRQ
|
||||
auto dma_stream = _dma_get_stream(adc->DMAx, adc->DMA_Stream);
|
||||
CLEAR_BIT(dma_stream->CR, DMA_SxCR_TCIE | DMA_SxCR_TEIE | DMA_SxCR_DMEIE);
|
||||
|
||||
uint16_t* dma_buffer = _adc_dma_buffer + adc->offset;
|
||||
copy_adc_values(dma_buffer, adc, _adc_inputs);
|
||||
|
||||
_adc_chain_conversions(adc);
|
||||
}
|
||||
|
||||
void stm32_hal_adc_isr(const stm32_adc_t* adc)
|
||||
{
|
||||
// check if this ADC triggered the IRQ
|
||||
auto ADCx = adc->ADCx;
|
||||
if (!LL_ADC_IsActiveFlag_EOCS(ADCx) || !LL_ADC_IsEnabledIT_EOCS(ADCx))
|
||||
return;
|
||||
|
||||
// Disable end-of-conversion IRQ
|
||||
CLEAR_BIT(ADCx->CR1, ADC_CR1_EOCIE);
|
||||
|
||||
uint16_t* dma_buffer = _adc_dma_buffer + adc->offset;
|
||||
*dma_buffer = adc->ADCx->DR;
|
||||
copy_adc_values(dma_buffer, adc, _adc_inputs);
|
||||
|
||||
_adc_chain_conversions(adc);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "hal/adc_driver.h"
|
||||
|
||||
|
||||
struct stm32_adc_input_t {
|
||||
const char* name;
|
||||
GPIO_TypeDef* GPIOx;
|
||||
uint32_t GPIO_Pin;
|
||||
uint32_t ADC_Channel;
|
||||
uint8_t inverted;
|
||||
};
|
||||
|
||||
struct stm32_adc_t {
|
||||
ADC_TypeDef* ADCx;
|
||||
DMA_TypeDef* DMAx;
|
||||
uint32_t DMA_Channel;
|
||||
uint32_t DMA_Stream;
|
||||
IRQn_Type DMA_Stream_IRQn;
|
||||
const uint8_t* channels;
|
||||
uint8_t offset;
|
||||
uint8_t n_channels;
|
||||
uint8_t sample_time;
|
||||
};
|
||||
|
||||
struct stm32_adc_gpio_t {
|
||||
GPIO_TypeDef* GPIOx;
|
||||
const uint32_t* pins;
|
||||
uint8_t n_pins;
|
||||
};
|
||||
|
||||
|
||||
bool stm32_hal_adc_init(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
const stm32_adc_input_t* inputs,
|
||||
const stm32_adc_gpio_t* ADC_GPIOs, uint8_t n_GPIO);
|
||||
|
||||
bool stm32_hal_adc_start_read(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
const stm32_adc_input_t* inputs, uint8_t n_inputs);
|
||||
|
||||
void stm32_hal_adc_wait_completion(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
const stm32_adc_input_t* inputs, uint8_t n_inputs);
|
||||
|
||||
void stm32_hal_adc_disable_oversampling();
|
||||
|
||||
void stm32_hal_adc_dma_isr(const stm32_adc_t* adc);
|
||||
void stm32_hal_adc_isr(const stm32_adc_t* adc);
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(STM32F4)
|
||||
#include "CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
|
||||
#elif defined(STM32F2)
|
||||
|
||||
// Workaround to prevent the other CMSIS header to be included
|
||||
// and fix some missing items in the old one
|
||||
#include "thirdparty/CMSIS/Include/cmsis_compiler.h"
|
||||
#define __CORE_CM3_H_GENERIC
|
||||
|
||||
#include "CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 "stm32_gpio_driver.h"
|
||||
|
||||
void stm32_gpio_enable_clock(GPIO_TypeDef *GPIOx)
|
||||
{
|
||||
uint32_t reg_idx = (((uint32_t) GPIOx) - GPIOA_BASE) / 0x0400UL;
|
||||
uint32_t reg_msk = RCC_AHB1ENR_GPIOAEN << reg_idx;
|
||||
LL_AHB1_GRP1_EnableClock(reg_msk);
|
||||
}
|
||||
|
||||
+2
-4
@@ -21,8 +21,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#include "stm32_pulse_driver.h"
|
||||
|
||||
extern const stm32_pulse_timer_t extmoduleTimer;
|
||||
void stm32_gpio_enable_clock(GPIO_TypeDef *GPIOx);
|
||||
@@ -1,474 +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 "hal/adc_driver.h"
|
||||
#include "stm32_hal_adc.h"
|
||||
|
||||
static bool adc_disable_dma(DMA_Stream_TypeDef * dma_stream);
|
||||
static void adc_dma_clear_flags(DMA_Stream_TypeDef * dma_stream);
|
||||
|
||||
static void adc_init_pins()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
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;
|
||||
|
||||
#if defined(ADC_GPIOA_PINS)
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
if (globalData.flyskygimbals)
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIOA_PINS_FS;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIOA_PINS;
|
||||
}
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(ADC_GPIOB_PINS)
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIOB_PINS;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(ADC_GPIOC_PINS)
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIOC_PINS;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(ADC_GPIOF_PINS)
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIOF_PINS;
|
||||
GPIO_Init(GPIOF, &GPIO_InitStructure);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void adc_setup_scan_mode(ADC_TypeDef* ADCx, uint8_t nconv)
|
||||
{
|
||||
ADC_InitTypeDef ADC_InitStructure;
|
||||
ADC_StructInit(&ADC_InitStructure);
|
||||
|
||||
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
|
||||
ADC_InitStructure.ADC_ScanConvMode = ENABLE; // Sets ADC_CR1_SCAN
|
||||
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // Clears ADC_CR2_CONT
|
||||
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; // Software trigger
|
||||
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||
ADC_InitStructure.ADC_NbrOfConversion = nconv; // Channel count
|
||||
|
||||
ADC_Init(ADCx, &ADC_InitStructure);
|
||||
|
||||
// enable ADC_MAIN
|
||||
ADC_Cmd(ADCx, ENABLE); // ADC_CR2_ADON
|
||||
// enable DMA for ADC
|
||||
ADC_DMACmd(ADCx, ENABLE); // ADC_CR2_DMA
|
||||
ADC_DMARequestAfterLastTransferCmd(ADCx, ENABLE); // ADC_CR2_DDS
|
||||
}
|
||||
|
||||
static const stm32_hal_adc_channel ADC_MAIN_channels[] = {
|
||||
{ADC_CHANNEL_STICK_LH, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_STICK_LV, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_STICK_RV, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_STICK_RH, ADC_SAMPTIME},
|
||||
#if defined(PCBX10)
|
||||
{ ADC_CHANNEL_POT1, ADC_SAMPTIME },
|
||||
{ ADC_CHANNEL_POT2, ADC_SAMPTIME },
|
||||
{ ADC_CHANNEL_POT3, ADC_SAMPTIME },
|
||||
{ ADC_CHANNEL_EXT1, ADC_SAMPTIME },
|
||||
{ ADC_CHANNEL_EXT2, ADC_SAMPTIME },
|
||||
{ ADC_CHANNEL_EXT3, ADC_SAMPTIME },
|
||||
{ ADC_CHANNEL_EXT4, ADC_SAMPTIME },
|
||||
{ ADC_CHANNEL_SLIDER1, ADC_SAMPTIME },
|
||||
{ ADC_CHANNEL_SLIDER2, ADC_SAMPTIME },
|
||||
{ ADC_CHANNEL_BATT, ADC_SAMPTIME }
|
||||
#else
|
||||
#if defined(RADIO_T8) || defined(RADIO_TLITE) || defined(RADIO_COMMANDO8) || defined(RADIO_LR3PRO)
|
||||
// fake channels to fill unused POT1/POT2
|
||||
{0, 0},
|
||||
{0, 0},
|
||||
#elif defined(PCBX7) || defined(PCBXLITE)
|
||||
{ADC_CHANNEL_POT1, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_POT2, ADC_SAMPTIME},
|
||||
#if defined(RADIO_BOXER)
|
||||
{ADC_CHANNEL_POT3, ADC_SAMPTIME},
|
||||
#endif
|
||||
#elif defined(PCBX9LITE)
|
||||
{ADC_CHANNEL_POT1, ADC_SAMPTIME},
|
||||
#elif defined(PCBX9E)
|
||||
{ADC_CHANNEL_POT2, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_POT3, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_POT4, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SLIDER3, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SLIDER4, ADC_SAMPTIME},
|
||||
#elif defined(PCBX9D) || defined(PCBX9DP)
|
||||
{ADC_CHANNEL_POT1, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_POT2, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_POT3, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SLIDER1, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SLIDER2, ADC_SAMPTIME},
|
||||
#elif defined(PCBNV14)
|
||||
{ADC_CHANNEL_POT1, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_POT2, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SWA, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SWC, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SWE, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SWF, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SWG, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SWH, ADC_SAMPTIME},
|
||||
#endif
|
||||
{ADC_CHANNEL_BATT, ADC_SAMPTIME},
|
||||
{ADC_Channel_Vbat, ADC_SAMPTIME}
|
||||
#endif
|
||||
};
|
||||
|
||||
static const stm32_hal_adc_channel* ADC_MAIN_get_channels()
|
||||
{
|
||||
#if (NUM_PWMSTICKS > 0)
|
||||
if (STICKS_PWM_ENABLED())
|
||||
return ADC_MAIN_channels + 4;
|
||||
#endif
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
if (globalData.flyskygimbals)
|
||||
{
|
||||
return ADC_MAIN_channels + FIRST_ANALOG_ADC_FS;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
return ADC_MAIN_channels + FIRST_ANALOG_ADC;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADC_MAIN_get_nconv()
|
||||
{
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
if (globalData.flyskygimbals)
|
||||
{
|
||||
return NUM_ANALOGS_ADC_FS;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
return NUM_ANALOGS_ADC; // based on STICKS_PWM_ENABLED()
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ADC_EXT)
|
||||
#if defined(PCBX9E)
|
||||
|
||||
static const stm32_hal_adc_channel ADC_EXT_channels[] = {
|
||||
{ADC_CHANNEL_POT1, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SLIDER1, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SLIDER2, ADC_SAMPTIME}
|
||||
};
|
||||
|
||||
static uint8_t ADC_EXT_get_nconv() { return NUM_ANALOGS_ADC_EXT; }
|
||||
|
||||
#elif defined(PCBX10)
|
||||
|
||||
static const stm32_hal_adc_channel ADC_EXT_channels[] = {
|
||||
{ ADC_Channel_Vbat, ADC_SAMPTIME }
|
||||
};
|
||||
|
||||
static uint8_t ADC_EXT_get_nconv() { return 1; }
|
||||
|
||||
#elif defined(PCBNV14)
|
||||
|
||||
static const stm32_hal_adc_channel ADC_EXT_channels[] = {
|
||||
{ADC_CHANNEL_SWB, ADC_SAMPTIME},
|
||||
{ADC_CHANNEL_SWD, ADC_SAMPTIME},
|
||||
};
|
||||
|
||||
static uint8_t ADC_EXT_get_nconv() { return NUM_ANALOGS_ADC_EXT; }
|
||||
|
||||
#endif
|
||||
|
||||
static const stm32_hal_adc_channel* ADC_EXT_get_channels()
|
||||
{
|
||||
return ADC_EXT_channels;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static uint16_t* ADC_MAIN_get_dma_buffer()
|
||||
{
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
if (globalData.flyskygimbals)
|
||||
{
|
||||
return &adcValues[FIRST_ANALOG_ADC_FS];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
return &adcValues[FIRST_ANALOG_ADC];
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ADC_EXT) && defined(ADC_EXT_DMA_Stream)
|
||||
static uint16_t* ADC_EXT_get_dma_buffer()
|
||||
{
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
if (globalData.flyskygimbals)
|
||||
{
|
||||
return adcValues + NUM_ANALOGS_ADC_FS + FIRST_ANALOG_ADC_FS;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
return adcValues + NUM_ANALOGS_ADC + FIRST_ANALOG_ADC;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static const stm32_hal_adc ADC_hal_def[] = {
|
||||
{
|
||||
ADC_MAIN,
|
||||
ADC_DMA_Stream, ADC_DMA_Channel, ADC_MAIN_get_dma_buffer,
|
||||
ADC_MAIN_get_nconv, ADC_MAIN_get_channels
|
||||
},
|
||||
#if defined(ADC_EXT)
|
||||
{
|
||||
ADC_EXT,
|
||||
#if defined(ADC_EXT_DMA_Stream)
|
||||
ADC_EXT_DMA_Stream, ADC_EXT_DMA_Channel, ADC_EXT_get_dma_buffer,
|
||||
#else
|
||||
nullptr, 0, nullptr,
|
||||
#endif
|
||||
ADC_EXT_get_nconv, ADC_EXT_get_channels
|
||||
},
|
||||
#endif
|
||||
// required to detect end of ADC definitions
|
||||
{ nullptr, nullptr, 0, nullptr, nullptr, nullptr },
|
||||
};
|
||||
|
||||
static void adc_init_channels(ADC_TypeDef* adc, const stm32_hal_adc_channel* chan,
|
||||
uint8_t nconv)
|
||||
{
|
||||
if (!chan || !nconv) return;
|
||||
|
||||
uint8_t rank = 1;
|
||||
while (nconv > 0) {
|
||||
ADC_RegularChannelConfig(adc, chan->adc_channel, rank, chan->sample_time);
|
||||
nconv--; rank++; chan++;
|
||||
}
|
||||
}
|
||||
|
||||
static bool adc_init_dma_stream(ADC_TypeDef* adc, DMA_Stream_TypeDef * dma_stream,
|
||||
uint32_t dma_channel, uint16_t* dest, uint8_t nconv)
|
||||
{
|
||||
// Disable DMA before continuing (see ref. manual "Stream configuration procedure")
|
||||
if (!adc_disable_dma(dma_stream))
|
||||
return false;
|
||||
|
||||
// Clear Interrupt flags
|
||||
adc_dma_clear_flags(dma_stream);
|
||||
|
||||
// setup DMA request
|
||||
dma_stream->PAR = CONVERT_PTR_UINT(&adc->DR);
|
||||
dma_stream->M0AR = CONVERT_PTR_UINT(dest);
|
||||
dma_stream->NDTR = nconv;
|
||||
// Very high priority, 1 byte transfers, increment memory
|
||||
dma_stream->CR = DMA_SxCR_PL | dma_channel | DMA_SxCR_MSIZE_0 |
|
||||
DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC;
|
||||
// disable direct mode, half full FIFO
|
||||
dma_stream->FCR = DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool stm32_hal_adc_init()
|
||||
{
|
||||
adc_init_pins();
|
||||
|
||||
// Init common to all ADCs
|
||||
ADC_CommonInitTypeDef ADC_CommonInitStruct;
|
||||
ADC_CommonStructInit(&ADC_CommonInitStruct);
|
||||
ADC_CommonInitStruct.ADC_Mode = ADC_Mode_Independent;
|
||||
ADC_CommonInitStruct.ADC_Prescaler = ADC_Prescaler_Div2;
|
||||
ADC_CommonInit(&ADC_CommonInitStruct);
|
||||
|
||||
const stm32_hal_adc* adc_def = ADC_hal_def;
|
||||
while (adc_def->adc) {
|
||||
uint8_t nconv = 0;
|
||||
if (adc_def->get_nconv) {
|
||||
nconv = adc_def->get_nconv();
|
||||
if (nconv > 0) {
|
||||
adc_setup_scan_mode(adc_def->adc, nconv);
|
||||
|
||||
// configure each channel
|
||||
if (adc_def->get_channels) {
|
||||
const stm32_hal_adc_channel* chan = adc_def->get_channels();
|
||||
adc_init_channels(adc_def->adc, chan, nconv);
|
||||
}
|
||||
|
||||
if (adc_def->dma_stream && adc_def->get_dma_buffer) {
|
||||
uint16_t* dma_buffer = adc_def->get_dma_buffer();
|
||||
if (!adc_init_dma_stream(adc_def->adc, adc_def->dma_stream,
|
||||
adc_def->dma_channel, dma_buffer, nconv))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// move to next ADC definition
|
||||
adc_def++;
|
||||
}
|
||||
|
||||
//TODO: move VBat & PWM sticks somewhere else.
|
||||
|
||||
// Enable vbat sensor
|
||||
ADC_VBATCmd(ENABLE);
|
||||
|
||||
#if NUM_PWMSTICKS > 0
|
||||
if (STICKS_PWM_ENABLED()) {
|
||||
sticksPwmInit();
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
#define DMA_Stream0_IT_MASK (uint32_t)(DMA_LISR_FEIF0 | DMA_LISR_DMEIF0 | \
|
||||
DMA_LISR_TEIF0 | DMA_LISR_HTIF0 | \
|
||||
DMA_LISR_TCIF0)
|
||||
|
||||
#define DMA_Stream4_IT_MASK (uint32_t)(DMA_HISR_FEIF4 | DMA_HISR_DMEIF4 | \
|
||||
DMA_HISR_TEIF4 | DMA_HISR_HTIF4 | \
|
||||
DMA_HISR_TCIF4)
|
||||
|
||||
static void adc_dma_clear_flags(DMA_Stream_TypeDef * dma_stream)
|
||||
{
|
||||
// no other choice, sorry for that...
|
||||
if (dma_stream == DMA2_Stream4) {
|
||||
/* Reset interrupt pending bits for DMA2 Stream4 */
|
||||
DMA2->HIFCR = DMA_Stream4_IT_MASK;
|
||||
|
||||
} else if (dma_stream == DMA2_Stream0) {
|
||||
/* Reset interrupt pending bits for DMA2 Stream0 */
|
||||
DMA2->LIFCR = DMA_Stream0_IT_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
static bool adc_start_dma_conversion(ADC_TypeDef* ADCx,
|
||||
DMA_Stream_TypeDef * dma_stream)
|
||||
{
|
||||
// Disable DMA before continuing (see ref. manual "Stream configuration procedure")
|
||||
if (!adc_disable_dma(dma_stream))
|
||||
return false;
|
||||
|
||||
// Clear Interrupt flags
|
||||
adc_dma_clear_flags(dma_stream);
|
||||
|
||||
// Clear ADC status register
|
||||
ADCx->SR &= ~(uint32_t)(ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
|
||||
|
||||
// Enable DMA
|
||||
dma_stream->CR |= DMA_SxCR_EN;
|
||||
|
||||
// Trigger ADC start
|
||||
ADCx->CR2 |= (uint32_t)ADC_CR2_SWSTART;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool adc_disable_dma(DMA_Stream_TypeDef* dma_stream)
|
||||
{
|
||||
dma_stream->CR &= ~(uint32_t)DMA_SxCR_EN;
|
||||
|
||||
// wait until DMA EN bit gets cleared by hardware
|
||||
uint16_t uiTimeout = 1000;
|
||||
while (dma_stream->CR & (uint32_t)DMA_SxCR_EN) {
|
||||
if (--uiTimeout == 0) {
|
||||
// Timeout. Failed to disable DMA
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void adc_start_single_conversion(ADC_TypeDef* ADCx)
|
||||
{
|
||||
ADCx->SR &= ~(uint32_t)(ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
|
||||
ADCx->CR2 |= (uint32_t)ADC_CR2_SWSTART;
|
||||
}
|
||||
|
||||
static bool stm32_hal_adc_start_read()
|
||||
{
|
||||
const stm32_hal_adc* adc_def = ADC_hal_def;
|
||||
while (adc_def->adc) {
|
||||
uint8_t nconv = 0;
|
||||
if (adc_def->get_nconv) {
|
||||
nconv = adc_def->get_nconv();
|
||||
if (nconv > 0) {
|
||||
if (adc_def->dma_stream && adc_def->get_dma_buffer) {
|
||||
if (!adc_start_dma_conversion(adc_def->adc, adc_def->dma_stream))
|
||||
return false;
|
||||
} else if (nconv == 1) {
|
||||
adc_start_single_conversion(adc_def->adc);
|
||||
}
|
||||
}
|
||||
}
|
||||
// move to next ADC definition
|
||||
adc_def++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void stm32_hal_adc_wait_completion()
|
||||
{
|
||||
//TODO:
|
||||
// - iterate through ADCs
|
||||
// - replace with IRQ trigger (both)
|
||||
// - move RTC batt reading somewhere else
|
||||
|
||||
#if defined(ADC_EXT) && defined(ADC_EXT_DMA_Stream)
|
||||
// Wait for all ADCs to complete
|
||||
for (unsigned int i=0; i<10000; i++) {
|
||||
if (DMA_GetFlagStatus(ADC_DMA_Stream, ADC_DMA_TC_Flag) != RESET &&
|
||||
DMA_GetFlagStatus(ADC_EXT_DMA_Stream, ADC_EXT_TC_Flag) != RESET) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//TODO: move into completion IRQ trigger
|
||||
adc_disable_dma(ADC_DMA_Stream);
|
||||
adc_disable_dma(ADC_EXT_DMA_Stream);
|
||||
#else
|
||||
// Wait only for the main ADC, and hope others are done as well
|
||||
for (unsigned int i = 0; i < 10000; i++) {
|
||||
if (DMA_GetFlagStatus(ADC_DMA_Stream, ADC_DMA_TC_Flag) != RESET) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//TODO: move into completion IRQ trigger
|
||||
adc_disable_dma(ADC_DMA_Stream);
|
||||
|
||||
#if defined(ADC_EXT) && !defined(ADC_EXT_DMA_Stream)
|
||||
if (isVBatBridgeEnabled()) {
|
||||
rtcBatteryVoltage = ADC_EXT->DR;
|
||||
disableVBatBridge();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
const etx_hal_adc_driver_t stm32_hal_adc_driver = {
|
||||
stm32_hal_adc_init,
|
||||
stm32_hal_adc_start_read,
|
||||
stm32_hal_adc_wait_completion
|
||||
};
|
||||
@@ -21,33 +21,36 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stm32_cmsis.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#define USE_FULL_LL_DRIVER
|
||||
#if defined(STM32F4)
|
||||
#include "CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_tim.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.h"
|
||||
#elif defined(STM32F2)
|
||||
#endif
|
||||
|
||||
// Workaround to prevent the other CMSIS header to be included
|
||||
// and fix some missing items in the old one
|
||||
#include "thirdparty/CMSIS/Include/cmsis_compiler.h"
|
||||
#define __CORE_CM3_H_GENERIC
|
||||
#define USE_FULL_LL_DRIVER
|
||||
#if defined(STM32F4)
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_tim.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_adc.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_spi.h"
|
||||
#elif defined(STM32F2)
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_bus.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_gpio.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_tim.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_dma.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_usart.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_exti.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_system.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_rcc.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_adc.h"
|
||||
#endif
|
||||
|
||||
#include "CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_bus.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_gpio.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_tim.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_dma.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_usart.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_exti.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_system.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_rcc.h"
|
||||
#endif
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
+12
-19
@@ -21,25 +21,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
struct stm32_hal_adc_channel {
|
||||
const uint8_t adc_channel;
|
||||
const uint8_t sample_time;
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
struct stm32_spi_adc_t {
|
||||
SPI_TypeDef* SPIx;
|
||||
GPIO_TypeDef* GPIOx;
|
||||
uint32_t GPIO_Pins;
|
||||
uint32_t GPIO_AF;
|
||||
uint32_t GPIO_CS;
|
||||
const uint8_t* channels;
|
||||
uint8_t n_channels;
|
||||
};
|
||||
|
||||
typedef const stm32_hal_adc_channel* (*stm32_hal_adc_get_channels)();
|
||||
typedef uint8_t (*stm32_hal_adc_get_nconv)();
|
||||
typedef uint16_t* (*stm32_hal_adc_get_dma_buffer)();
|
||||
#define _SPI_ADC_CS_HIGH(adc) LL_GPIO_SetOutputPin(adc->GPIOx, adc->GPIO_CS)
|
||||
#define _SPI_ADC_CS_LOW(adc) LL_GPIO_ResetOutputPin(adc->GPIOx, adc->GPIO_CS)
|
||||
|
||||
struct stm32_hal_adc {
|
||||
ADC_TypeDef* adc;
|
||||
|
||||
DMA_Stream_TypeDef* dma_stream;
|
||||
uint32_t dma_channel;
|
||||
const stm32_hal_adc_get_dma_buffer get_dma_buffer;
|
||||
|
||||
const stm32_hal_adc_get_nconv get_nconv;
|
||||
const stm32_hal_adc_get_channels get_channels;
|
||||
};
|
||||
|
||||
// Driver to be passed to adcInit()
|
||||
extern const etx_hal_adc_driver_t stm32_hal_adc_driver;
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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 "stm32_switch_driver.h"
|
||||
#include "hal/adc_driver.h"
|
||||
|
||||
bool stm32_switch_get_state(const stm32_switch_t* sw, SwitchHwPos pos)
|
||||
{
|
||||
switch (sw->type) {
|
||||
case SWITCH_HW_2POS:
|
||||
switch (pos) {
|
||||
case SWITCH_HW_UP:
|
||||
if (sw->flags & SWITCH_HW_INVERTED)
|
||||
return !LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
|
||||
else
|
||||
return LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
|
||||
|
||||
case SWITCH_HW_DOWN:
|
||||
if (sw->flags & SWITCH_HW_INVERTED)
|
||||
return LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
|
||||
else
|
||||
return !LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case SWITCH_HW_3POS: {
|
||||
auto hi = LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
|
||||
auto lo = LL_GPIO_IsInputPinSet(sw->GPIOx_low, sw->Pin_low);
|
||||
|
||||
switch (pos) {
|
||||
case SWITCH_HW_UP:
|
||||
if (sw->flags & SWITCH_HW_INVERTED)
|
||||
return !hi && lo;
|
||||
else
|
||||
return hi && !lo;
|
||||
|
||||
case SWITCH_HW_DOWN:
|
||||
if (sw->flags & SWITCH_HW_INVERTED)
|
||||
return hi && !lo;
|
||||
else
|
||||
return !hi && lo;
|
||||
|
||||
case SWITCH_HW_MID:
|
||||
return hi && lo;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
} break;
|
||||
|
||||
case SWITCH_HW_ADC: {
|
||||
uint16_t value = getAnalogValue(sw->Pin_high);
|
||||
switch (pos) {
|
||||
case SWITCH_HW_UP:
|
||||
return value < 1024;
|
||||
case SWITCH_HW_DOWN:
|
||||
return value > 3 * 1024;
|
||||
case SWITCH_HW_MID:
|
||||
return (value >= 1024) && (value <= 3 * 1024);
|
||||
}
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SwitchHwPos stm32_switch_get_position(const stm32_switch_t* sw)
|
||||
{
|
||||
bool inv = sw->flags & SWITCH_HW_INVERTED;
|
||||
SwitchHwPos ret = SWITCH_HW_UP;
|
||||
|
||||
switch (sw->type) {
|
||||
case SWITCH_HW_2POS:
|
||||
if (!LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high))
|
||||
ret = SWITCH_HW_DOWN;
|
||||
break;
|
||||
|
||||
case SWITCH_HW_3POS: {
|
||||
auto hi = LL_GPIO_IsInputPinSet(sw->GPIOx_high, sw->Pin_high);
|
||||
auto lo = LL_GPIO_IsInputPinSet(sw->GPIOx_low, sw->Pin_low);
|
||||
|
||||
if (hi && lo)
|
||||
ret = SWITCH_HW_MID;
|
||||
else if (!hi && lo)
|
||||
ret = SWITCH_HW_DOWN;
|
||||
} break;
|
||||
|
||||
case SWITCH_HW_ADC: {
|
||||
uint16_t value = getAnalogValue(sw->Pin_high);
|
||||
if (value > 3 * 1024)
|
||||
ret = SWITCH_HW_DOWN;
|
||||
else if (value >= 1024)
|
||||
ret = SWITCH_HW_MID;
|
||||
} break;
|
||||
}
|
||||
|
||||
if (inv) {
|
||||
return ret == SWITCH_HW_UP ? SWITCH_HW_DOWN
|
||||
: ret == SWITCH_HW_DOWN ? SWITCH_HW_UP
|
||||
: ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "hal/switch_driver.h"
|
||||
|
||||
struct stm32_switch_t
|
||||
{
|
||||
const char* name;
|
||||
GPIO_TypeDef* GPIOx_high;
|
||||
uint32_t Pin_high;
|
||||
|
||||
GPIO_TypeDef* GPIOx_low;
|
||||
uint32_t Pin_low;
|
||||
|
||||
SwitchHwType type;
|
||||
uint8_t flags;
|
||||
};
|
||||
|
||||
#define SWITCH_HW_DEF_3POS(x, flags) \
|
||||
{ \
|
||||
SWITCHES_GPIO_REG_##x##_H, SWITCHES_GPIO_PIN_##x##_H, \
|
||||
SWITCHES_GPIO_REG_##x##_L, SWITCHES_GPIO_PIN_##x##_L, \
|
||||
SWITCH_HW_3POS, (flags) \
|
||||
}
|
||||
|
||||
#define SWITCH_HW_DEF_2POS(x, flags) \
|
||||
{ \
|
||||
SWITCHES_GPIO_REG_##x, SWITCHES_GPIO_PIN_##x, \
|
||||
nullptr, 0, SWITCH_HW_2POS, (flags) \
|
||||
}
|
||||
|
||||
SwitchHwPos stm32_switch_get_position(const stm32_switch_t* sw);
|
||||
bool stm32_switch_get_state(const stm32_switch_t* sw, SwitchHwPos pos);
|
||||
@@ -318,9 +318,7 @@ void stm32_usart_deinit(const stm32_usart_t* usart)
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
pinInit.Pin = usart->GPIO_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
pinInit.Pull = LL_GPIO_PULL_NO;
|
||||
pinInit.Alternate = LL_GPIO_AF_0;
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
LL_GPIO_Init(usart->GPIOx, &pinInit);
|
||||
LL_GPIO_ResetOutputPin(usart->GPIOx, pinInit.Pin);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "watchdog_driver.h"
|
||||
|
||||
static volatile uint32_t msTickCount; // Used to get 1 kHz counter
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
#if defined(SIMU)
|
||||
|
||||
uint16_t getTmr2MHz();
|
||||
|
||||
#define watchdogSuspend(timeout)
|
||||
#else
|
||||
|
||||
#else // SIMU
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
@@ -34,7 +34,7 @@ void init2MhzTimer();
|
||||
void init1msTimer();
|
||||
void stop1msTimer();
|
||||
|
||||
static inline uint16_t getTmr2MHz() { return TIMER_2MHz_TIMER->CNT; }
|
||||
#define getTmr2MHz() TIMER_2MHz_TIMER->CNT
|
||||
|
||||
void watchdogSuspend(uint32_t timeout);
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ extern "C" {
|
||||
|
||||
#include "board.h"
|
||||
#include "debug.h"
|
||||
#include "debounce.h"
|
||||
|
||||
static bool usbDriverStarted = false;
|
||||
#if defined(BOOT)
|
||||
@@ -60,8 +59,17 @@ void setSelectedUsbMode(int mode)
|
||||
|
||||
int usbPlugged()
|
||||
{
|
||||
static PinDebounce debounce;
|
||||
return debounce.debounce(USB_GPIO, USB_GPIO_PIN_VBUS);
|
||||
static uint8_t debouncedState = 0;
|
||||
static uint8_t lastState = 0;
|
||||
|
||||
uint8_t state = GPIO_ReadInputDataBit(USB_GPIO, USB_GPIO_PIN_VBUS);
|
||||
|
||||
if (state == lastState)
|
||||
debouncedState = state;
|
||||
else
|
||||
lastState = state;
|
||||
|
||||
return debouncedState;
|
||||
}
|
||||
|
||||
USB_OTG_CORE_HANDLE USB_OTG_dev;
|
||||
|
||||
@@ -22,22 +22,33 @@
|
||||
#pragma once
|
||||
|
||||
#define WDG_DURATION 500 /*ms*/
|
||||
|
||||
void watchdogInit(unsigned int duration);
|
||||
|
||||
#if defined(SIMU)
|
||||
#define WAS_RESET_BY_WATCHDOG() (false)
|
||||
#define WAS_RESET_BY_SOFTWARE() (false)
|
||||
#define WAS_RESET_BY_WATCHDOG_OR_SOFTWARE() (false)
|
||||
|
||||
#define WAS_RESET_BY_WATCHDOG() (false)
|
||||
#define WAS_RESET_BY_SOFTWARE() (false)
|
||||
#define WAS_RESET_BY_WATCHDOG_OR_SOFTWARE() (false)
|
||||
#define WDG_ENABLE(x)
|
||||
#define WDG_RESET()
|
||||
|
||||
#else // SIMU
|
||||
|
||||
#if defined(WATCHDOG)
|
||||
#define WDG_ENABLE(x) watchdogInit(x)
|
||||
#define WDG_RESET() IWDG->KR = 0xAAAA
|
||||
#else
|
||||
#define WDG_ENABLE(x)
|
||||
#define WDG_RESET()
|
||||
#else
|
||||
#if defined(WATCHDOG)
|
||||
#define WDG_ENABLE(x) watchdogInit(x)
|
||||
#define WDG_RESET() IWDG->KR = 0xAAAA
|
||||
#else
|
||||
#define WDG_ENABLE(x)
|
||||
#define WDG_RESET()
|
||||
#endif
|
||||
#define WAS_RESET_BY_WATCHDOG() (RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF))
|
||||
#define WAS_RESET_BY_SOFTWARE() (RCC->CSR & RCC_CSR_SFTRSTF)
|
||||
#define WAS_RESET_BY_WATCHDOG_OR_SOFTWARE() (RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF | RCC_CSR_SFTRSTF))
|
||||
#endif
|
||||
|
||||
#define WAS_RESET_BY_WATCHDOG() \
|
||||
(RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF))
|
||||
|
||||
#define WAS_RESET_BY_SOFTWARE() (RCC->CSR & RCC_CSR_SFTRSTF)
|
||||
|
||||
#define WAS_RESET_BY_WATCHDOG_OR_SOFTWARE() \
|
||||
(RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF | RCC_CSR_SFTRSTF))
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
};
|
||||
@@ -26,11 +26,6 @@ else()
|
||||
set(LINKER_SCRIPT targets/nv14/stm32f4_flash.ld)
|
||||
endif()
|
||||
|
||||
if(YAML_STORAGE)
|
||||
set(STORAGE_CONVERT RAW)
|
||||
set(STORAGE_FORMAT YAML)
|
||||
endif()
|
||||
|
||||
set(RTC_BACKUP_RAM YES)
|
||||
set(PPM_LIMITS_SYMETRICAL YES)
|
||||
# for size report script
|
||||
@@ -44,7 +39,7 @@ set_property(CACHE PCB_RF_BAUD PROPERTY STRINGS ${RF_BAUD_RATE})
|
||||
|
||||
set(FLAVOUR nv14)
|
||||
add_definitions(-DPCBNV14 -DPCBFLYSKY -DAFHDS2_BAUDRATE=${PCB_RF_BAUD})
|
||||
add_definitions(-DBATTERY_CHARGE)
|
||||
add_definitions(-DBATTERY_CHARGE -DUSE_TRIMS_AS_BUTTONS)
|
||||
|
||||
# defines existing internal modules
|
||||
set(INTERNAL_MODULES AFHDS2A;AFHDS3 CACHE STRING "Internal modules")
|
||||
@@ -53,7 +48,6 @@ set(DEFAULT_INTERNAL_MODULE FLYSKY CACHE STRING "Default internal module")
|
||||
set(BITMAPS_TARGET nv14_bitmaps)
|
||||
set(FONTS_TARGET x12_fonts)
|
||||
set(LCD_DRIVER lcd_driver.cpp)
|
||||
set(LUA_EXPORT lua_export_nv14)
|
||||
set(TOUCH_DRIVER touch_driver.cpp)
|
||||
set(HARDWARE_TOUCH YES)
|
||||
|
||||
@@ -146,12 +140,8 @@ 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
|
||||
targets/common/arm/stm32/stm32_hal_adc.cpp
|
||||
targets/common/arm/stm32/stm32_adc.cpp
|
||||
targets/common/arm/stm32/timers_driver.cpp
|
||||
targets/common/arm/stm32/mixer_scheduler_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/trainer_driver.cpp
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "board.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "lcd_driver.h"
|
||||
|
||||
void backlightLowInit( void )
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
#include "opentx.h"
|
||||
#include "battery_driver.h"
|
||||
|
||||
#define __BATTERY_DRIVER_C__
|
||||
|
||||
|
||||
@@ -18,22 +18,30 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_adc.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "boards/generic_stm32/module_ports.h"
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/trainer_driver.h"
|
||||
#include "hal/switch_driver.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "sdcard.h"
|
||||
#include "touch.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "stm32_hal_adc.h"
|
||||
#include "flysky_gimbal_driver.h"
|
||||
#include "timers_driver.h"
|
||||
|
||||
#include "lcd_driver.h"
|
||||
#include "lcd_driver.h"
|
||||
#include "battery_driver.h"
|
||||
#include "touch_driver.h"
|
||||
#include "watchdog_driver.h"
|
||||
|
||||
#include "bitmapbuffer.h"
|
||||
#include "colors.h"
|
||||
|
||||
@@ -48,6 +56,36 @@ extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
// common ADC driver
|
||||
extern const etx_hal_adc_driver_t _adc_driver;
|
||||
|
||||
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;
|
||||
|
||||
void watchdogInit(unsigned int duration)
|
||||
@@ -148,6 +186,18 @@ void boardBootloaderInit()
|
||||
hardwareOptions.pcbrev = boardGetPcbRev();
|
||||
}
|
||||
|
||||
static void monitorInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = VBUS_MONITOR_PIN;
|
||||
GPIO_Init(GPIOJ, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
void boardInit()
|
||||
{
|
||||
#if defined(SEMIHOSTING)
|
||||
@@ -183,7 +233,7 @@ void boardInit()
|
||||
|
||||
init_trainer();
|
||||
battery_charge_init();
|
||||
globalData.flyskygimbals = flysky_gimbal_init();
|
||||
flysky_gimbal_init();
|
||||
init2MhzTimer();
|
||||
init1msTimer();
|
||||
TouchInit();
|
||||
@@ -227,12 +277,13 @@ void boardInit()
|
||||
}
|
||||
|
||||
keysInit();
|
||||
switchInit();
|
||||
audioInit();
|
||||
// we need to initialize g_FATFS_Obj here, because it is in .ram section (because of DMA access)
|
||||
// and this section is un-initialized
|
||||
memset(&g_FATFS_Obj, 0, sizeof(g_FATFS_Obj));
|
||||
monitorInit();
|
||||
adcInit(&stm32_hal_adc_driver);
|
||||
adcInit(&_adc_driver);
|
||||
hapticInit();
|
||||
|
||||
|
||||
@@ -252,6 +303,8 @@ void boardInit()
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void rtcDisableBackupReg();
|
||||
|
||||
void boardOff()
|
||||
{
|
||||
lcdOff();
|
||||
@@ -265,10 +318,7 @@ void boardOff()
|
||||
// Shutdown the Haptic
|
||||
hapticDone();
|
||||
|
||||
#if defined(RTC_BACKUP_RAM)
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, DISABLE);
|
||||
PWR_BackupRegulatorCmd(DISABLE);
|
||||
#endif
|
||||
rtcDisableBackupReg();
|
||||
|
||||
if (usbPlugged())
|
||||
{
|
||||
|
||||
@@ -24,22 +24,11 @@
|
||||
|
||||
#include "definitions.h"
|
||||
#include "opentx_constants.h"
|
||||
|
||||
#include "board_common.h"
|
||||
#include "hal.h"
|
||||
#include "hal/serial_port.h"
|
||||
|
||||
#if !defined(LUA_EXPORT_GENERATION)
|
||||
#include "stm32f4xx_sdio.h"
|
||||
#include "stm32f4xx_dma2d.h"
|
||||
#include "stm32f4xx_ltdc.h"
|
||||
#include "stm32f4xx_fmc.h"
|
||||
#endif
|
||||
|
||||
#include "touch_driver.h"
|
||||
#include "lcd_driver.h"
|
||||
#include "battery_driver.h"
|
||||
#include "watchdog_driver.h"
|
||||
|
||||
#define FLASHSIZE 0x200000
|
||||
#define BOOTLOADER_SIZE 0x20000
|
||||
#define FIRMWARE_ADDRESS 0x08000000
|
||||
@@ -150,191 +139,18 @@ extern HardwareOptions hardwareOptions;
|
||||
#define IS_UART_MODULE(port) (port == INTERNAL_MODULE)
|
||||
#define IS_PXX2_INTERNAL_ENABLED() (false)
|
||||
|
||||
// Keys driver
|
||||
enum EnumKeys
|
||||
{
|
||||
KEY_ENTER,
|
||||
KEY_EXIT,
|
||||
KEY_PGUP,
|
||||
KEY_PGDN,
|
||||
KEY_UP,
|
||||
KEY_DOWN,
|
||||
KEY_LEFT,
|
||||
KEY_RIGHT,
|
||||
KEY_MODEL,
|
||||
KEY_RADIO,
|
||||
KEY_TELEM,
|
||||
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_LAST = TRM_LS_UP,
|
||||
|
||||
NUM_KEYS
|
||||
};
|
||||
|
||||
#define IS_SHIFT_KEY(index) (false)
|
||||
#define IS_SHIFT_PRESSED() (false)
|
||||
enum VirtualKeys {
|
||||
VKEY_MIN,
|
||||
VKEY_MAX,
|
||||
VKEY_INC,
|
||||
VKEY_DEC,
|
||||
VKEY_INC_LARGE,
|
||||
VKEY_DEC_LARGE,
|
||||
VKEY_DEFAULT,
|
||||
};
|
||||
|
||||
enum LUATouchEvent {
|
||||
TOUCH_DOWN = 1,
|
||||
TOUCH_UP,
|
||||
TOUCH_SLIDE_UP,
|
||||
TOUCH_SLIDE_DOWN,
|
||||
TOUCH_SLIDE_LEFT,
|
||||
TOUCH_SLIDE_RIGHT,
|
||||
};
|
||||
|
||||
enum EnumSwitches
|
||||
{
|
||||
SW_SA,
|
||||
SW_SB,
|
||||
SW_SC,
|
||||
SW_SD,
|
||||
SW_SE,
|
||||
SW_SF,
|
||||
SW_SG,
|
||||
SW_SH,
|
||||
NUM_SWITCHES
|
||||
};
|
||||
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 14) + (SWITCH_3POS << 12) + (SWITCH_3POS << 10) + (SWITCH_TOGGLE << 8) + (SWITCH_2POS << 6) + (SWITCH_TOGGLE << 4) + (SWITCH_3POS << 2) + (SWITCH_2POS << 0);
|
||||
|
||||
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,
|
||||
NUM_SWITCHES_POSITIONS
|
||||
};
|
||||
|
||||
#define STORAGE_NUM_SWITCHES_POSITIONS (STORAGE_NUM_SWITCHES * 3)
|
||||
|
||||
#if !defined(NUM_FUNCTIONS_SWITCHES)
|
||||
#define NUM_FUNCTIONS_SWITCHES 0
|
||||
#endif
|
||||
|
||||
void monitorInit();
|
||||
void keysInit();
|
||||
uint8_t keyState(uint8_t index);
|
||||
uint32_t switchState(uint8_t index);
|
||||
uint32_t readKeys();
|
||||
uint32_t readTrims();
|
||||
void setTrimsAsButtons(bool);
|
||||
bool getTrimsAsButtons();
|
||||
#define TRIMS_EMULATE_BUTTONS
|
||||
#define NUM_TRIMS NUM_STICKS
|
||||
#define NUM_TRIMS_KEYS (NUM_TRIMS * 2)
|
||||
#define TRIMS_PRESSED() (readTrims())
|
||||
#define KEYS_PRESSED() (readKeys())
|
||||
#define DBLKEYS_PRESSED_RGT_LFT(in) (false)
|
||||
#define DBLKEYS_PRESSED_UP_DWN(in) (false)
|
||||
#define DBLKEYS_PRESSED_RGT_UP(in) (false)
|
||||
#define DBLKEYS_PRESSED_LFT_DWN(in) (false)
|
||||
|
||||
// ADC driver
|
||||
#define NUM_POTS 2
|
||||
#define NUM_XPOTS 0 // NUM_POTS
|
||||
#define NUM_SLIDERS 0
|
||||
#define NUM_PWMSTICKS 0
|
||||
#define NUM_MOUSE_ANALOGS 0
|
||||
#define STORAGE_NUM_POTS 5
|
||||
#define STORAGE_NUM_SLIDERS 0
|
||||
#define STORAGE_NUM_MOUSE_ANALOGS 0
|
||||
|
||||
enum Analogs {
|
||||
STICK1,
|
||||
STICK2,
|
||||
STICK3,
|
||||
STICK4,
|
||||
POT_FIRST,
|
||||
POT1 = POT_FIRST,
|
||||
POT2,
|
||||
POT_LAST = POT2,
|
||||
SWITCH_FIRST,
|
||||
SWA = SWITCH_FIRST,
|
||||
SWB,
|
||||
SWC,
|
||||
SWD,
|
||||
SWE,
|
||||
SWF,
|
||||
SWG,
|
||||
SWH,
|
||||
SUB_ANALOG_POS = SWH,
|
||||
SWITCH_END = SWH,
|
||||
TX_VOLTAGE,
|
||||
TX_VBAT,
|
||||
NUM_ANALOGS
|
||||
};
|
||||
|
||||
#define SLIDER_FIRST 0
|
||||
#define SLIDER_LAST -1
|
||||
|
||||
#define DEFAULT_STICK_DEADZONE 2
|
||||
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITHOUT_DETENT << 2) // 2 pots without detent
|
||||
|
||||
enum CalibratedAnalogs {
|
||||
CALIBRATED_STICK1,
|
||||
CALIBRATED_STICK2,
|
||||
CALIBRATED_STICK3,
|
||||
CALIBRATED_STICK4,
|
||||
CALIBRATED_POT1,
|
||||
CALIBRATED_POT2,
|
||||
CALIBRATED_SWA,
|
||||
CALIBRATED_SWB,
|
||||
CALIBRATED_SWC,
|
||||
CALIBRATED_SWD,
|
||||
CALIBRATED_SWE,
|
||||
CALIBRATED_SWF,
|
||||
CALIBRATED_SWG,
|
||||
CALIBRATED_SWH,
|
||||
NUM_CALIBRATED_ANALOGS
|
||||
};
|
||||
|
||||
#define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT_LAST)
|
||||
#define IS_SLIDER(x) (false)
|
||||
|
||||
extern uint16_t adcValues[NUM_ANALOGS];
|
||||
|
||||
// 2 pots without detent
|
||||
#define DEFAULT_POTS_CONFIG \
|
||||
(POT_WITHOUT_DETENT << 0) + \
|
||||
(POT_WITHOUT_DETENT << 2)
|
||||
|
||||
#define BATTERY_WARN 36 // 3.6V
|
||||
#define BATTERY_MIN 35 // 3.5V
|
||||
@@ -348,35 +164,8 @@ enum EnumPowerupState
|
||||
BOARD_REBOOT = 0xC00010FF,
|
||||
};
|
||||
|
||||
|
||||
#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" {
|
||||
@@ -395,6 +184,7 @@ void pwrSoftReboot();
|
||||
void pwrOff();
|
||||
void pwrResetHandler();
|
||||
bool pwrPressed();
|
||||
bool pwrOffPressed();
|
||||
#if defined(PWR_EXTRA_SWITCH_GPIO)
|
||||
bool pwrForcePressed();
|
||||
#else
|
||||
|
||||
@@ -49,27 +49,29 @@
|
||||
|
||||
|
||||
// Trims
|
||||
#define TRIMS_GPIO_REG_RHL GPIOD->IDR
|
||||
#define TRIMS_GPIO_PIN_RHL GPIO_Pin_7 // PD.07
|
||||
#define TRIMS_GPIO_REG_RHR GPIOG->IDR
|
||||
#define TRIMS_GPIO_PIN_RHR GPIO_Pin_10 // PG.10
|
||||
#define TRIMS_GPIO_REG_RVD GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_RVD GPIO_Pin_0 // PJ.00
|
||||
#define TRIMS_GPIO_REG_RVU GPIOB->IDR
|
||||
#define TRIMS_GPIO_PIN_RVU GPIO_Pin_15 // PB.15
|
||||
#define TRIMS_GPIO_REG_RPRESS GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_RPRESS GPIO_Pin_13 // PC.13
|
||||
#define TRIMS_GPIO_REG_RHL GPIOD
|
||||
#define TRIMS_GPIO_PIN_RHL LL_GPIO_PIN_7 // PD.07
|
||||
#define TRIMS_GPIO_REG_RHR GPIOG
|
||||
#define TRIMS_GPIO_PIN_RHR LL_GPIO_PIN_10 // PG.10
|
||||
#define TRIMS_GPIO_REG_RVD GPIOJ
|
||||
#define TRIMS_GPIO_PIN_RVD LL_GPIO_PIN_0 // PJ.00
|
||||
#define TRIMS_GPIO_REG_RVU GPIOB
|
||||
#define TRIMS_GPIO_PIN_RVU LL_GPIO_PIN_15 // PB.15
|
||||
|
||||
#define TRIMS_GPIO_REG_LHL GPIOH->IDR
|
||||
#define TRIMS_GPIO_PIN_LHL GPIO_Pin_2 // PH.02
|
||||
#define TRIMS_GPIO_REG_LHR GPIOG->IDR
|
||||
#define TRIMS_GPIO_PIN_LHR GPIO_Pin_2 // PG.02
|
||||
#define TRIMS_GPIO_REG_LVU GPIOH->IDR
|
||||
#define TRIMS_GPIO_PIN_LVU GPIO_Pin_7 // PH.07
|
||||
#define TRIMS_GPIO_REG_LVD GPIOJ->IDR
|
||||
#define TRIMS_GPIO_PIN_LVD GPIO_Pin_12 // PJ.12
|
||||
#define TRIMS_GPIO_REG_LPRESS GPIOG->IDR
|
||||
#define TRIMS_GPIO_PIN_LPRESS GPIO_Pin_11 // PG.11
|
||||
#define KEYS_GPIO_REG_ENTER GPIOC
|
||||
#define KEYS_GPIO_PIN_ENTER LL_GPIO_PIN_13 // PC.13
|
||||
|
||||
#define TRIMS_GPIO_REG_LHL GPIOH
|
||||
#define TRIMS_GPIO_PIN_LHL LL_GPIO_PIN_2 // PH.02
|
||||
#define TRIMS_GPIO_REG_LHR GPIOG
|
||||
#define TRIMS_GPIO_PIN_LHR LL_GPIO_PIN_2 // PG.02
|
||||
#define TRIMS_GPIO_REG_LVU GPIOH
|
||||
#define TRIMS_GPIO_PIN_LVU LL_GPIO_PIN_7 // PH.07
|
||||
#define TRIMS_GPIO_REG_LVD GPIOJ
|
||||
#define TRIMS_GPIO_PIN_LVD LL_GPIO_PIN_12 // PJ.12
|
||||
|
||||
#define KEYS_GPIO_REG_EXIT GPIOG
|
||||
#define KEYS_GPIO_PIN_EXIT LL_GPIO_PIN_11 // PG.11
|
||||
|
||||
// Monitor pin
|
||||
#define MONITOR_RCC_AHB1Periph (RCC_AHB1Periph_GPIOJ)
|
||||
@@ -104,62 +106,78 @@
|
||||
#define KEYS_GPIOJ_PINS (GPIO_Pin_0 | GPIO_Pin_12)
|
||||
|
||||
// ADC
|
||||
#define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_DMA2)
|
||||
#define ADC_RCC_APB2Periph (RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC3)
|
||||
// FLYSKY_HALL_STICKS
|
||||
#define ADC_GPIO_PIN_STICK_LH 0
|
||||
#define ADC_GPIO_PIN_STICK_LV 0
|
||||
#define ADC_GPIO_PIN_STICK_RH 0
|
||||
#define ADC_GPIO_PIN_STICK_RV 0
|
||||
#define ADC_RCC_AHB1Periph (RCC_AHB1Periph_DMA2)
|
||||
#define ADC_RCC_APB2Periph 0
|
||||
|
||||
#define ADC_GPIO_PIN_POT1 GPIO_Pin_6 // PA.06 VRA
|
||||
#define ADC_GPIO_PIN_POT2 GPIO_Pin_4 // PC.04 VRB
|
||||
#define ADC_GPIO_PIN_SWA GPIO_Pin_1 // PB.01
|
||||
#define ADC_GPIO_PIN_SWB GPIO_Pin_8 // PF.08
|
||||
#define ADC_GPIO_PIN_SWC GPIO_Pin_0 // PB.00
|
||||
#define ADC_GPIO_PIN_SWD GPIO_Pin_10 // PF.10
|
||||
#define ADC_GPIO_PIN_SWE GPIO_Pin_2 // PC.02
|
||||
#define ADC_GPIO_PIN_SWF GPIO_Pin_7 // PA.07
|
||||
#define ADC_GPIO_PIN_SWG GPIO_Pin_0 // PC.00
|
||||
#define ADC_GPIO_PIN_SWH GPIO_Pin_1 // PC.01
|
||||
#define ADC_GPIO_PIN_BATT GPIO_Pin_5 // PC.05
|
||||
#define ADC_GPIO_PIN_STICK_LH
|
||||
#define ADC_GPIO_PIN_STICK_LV
|
||||
#define ADC_GPIO_PIN_STICK_RV
|
||||
#define ADC_GPIO_PIN_STICK_RH
|
||||
|
||||
#define ADC_GPIO_PIN_POT1 LL_GPIO_PIN_6 // PA.06 VRA
|
||||
#define ADC_GPIO_PIN_POT2 LL_GPIO_PIN_4 // PC.04 VRB
|
||||
#define ADC_GPIO_PIN_SWA LL_GPIO_PIN_1 // PB.01
|
||||
#define ADC_GPIO_PIN_SWB LL_GPIO_PIN_8 // PF.08
|
||||
#define ADC_GPIO_PIN_SWC LL_GPIO_PIN_0 // PB.00
|
||||
#define ADC_GPIO_PIN_SWD LL_GPIO_PIN_10 // PF.10
|
||||
#define ADC_GPIO_PIN_SWE LL_GPIO_PIN_0 // PC.00
|
||||
#define ADC_GPIO_PIN_SWF LL_GPIO_PIN_1 // PC.01
|
||||
#define ADC_GPIO_PIN_SWG LL_GPIO_PIN_2 // PC.02
|
||||
#define ADC_GPIO_PIN_SWH LL_GPIO_PIN_7 // PA.07
|
||||
|
||||
#define ADC_GPIO_PIN_BATT LL_GPIO_PIN_5 // PC.05
|
||||
|
||||
// FLYSKY_HALL_STICKS
|
||||
#define ADC_GPIOA_PINS_FS (GPIO_Pin_6 | GPIO_Pin_7)
|
||||
#define ADC_GPIOA_PINS ADC_GPIOA_PINS_FS
|
||||
#define ADC_GPIOB_PINS (GPIO_Pin_0 | GPIO_Pin_1)
|
||||
// #define ADC_GPIOA_PINS_FS (GPIO_Pin_6 | GPIO_Pin_7)
|
||||
#define ADC_GPIOA_PINS (ADC_GPIO_PIN_POT1 | ADC_GPIO_PIN_SWH)
|
||||
#define ADC_GPIOB_PINS (ADC_GPIO_PIN_SWA | ADC_GPIO_PIN_SWC)
|
||||
#define ADC_GPIOC_PINS \
|
||||
(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_4 | GPIO_Pin_5)
|
||||
#define ADC_GPIOF_PINS (GPIO_Pin_8 | GPIO_Pin_10)
|
||||
(ADC_GPIO_PIN_POT2 | ADC_GPIO_PIN_SWE | ADC_GPIO_PIN_SWF | ADC_GPIO_PIN_SWG | ADC_GPIO_PIN_BATT)
|
||||
#define ADC_GPIOF_PINS (ADC_GPIO_PIN_SWB | ADC_GPIO_PIN_SWD)
|
||||
|
||||
#define ADC_CHANNEL_STICK_LH 0
|
||||
#define ADC_CHANNEL_STICK_LV 0
|
||||
#define ADC_CHANNEL_STICK_RH 0
|
||||
#define ADC_CHANNEL_STICK_RV 0
|
||||
#define ADC_CHANNEL_STICK_LH
|
||||
#define ADC_CHANNEL_STICK_LV
|
||||
#define ADC_CHANNEL_STICK_RV
|
||||
#define ADC_CHANNEL_STICK_RH
|
||||
|
||||
#define ADC_CHANNEL_POT1 ADC_Channel_6 // ADC12_IN6 -> ADC1_IN6
|
||||
#define ADC_CHANNEL_POT2 ADC_Channel_14 // ADC12_IN14 -> ADC1_IN14
|
||||
#define ADC_CHANNEL_SWA ADC_Channel_9 // ADC12_IN9 -> ADC1_IN9
|
||||
#define ADC_CHANNEL_SWB ADC_Channel_6 // ADC3_IN6 -> ADC3_IN6
|
||||
#define ADC_CHANNEL_SWC ADC_Channel_8 // ADC12_IN8 -> ADC1_IN8
|
||||
#define ADC_CHANNEL_SWD ADC_Channel_8 // ADC3_IN8 -> ADC3_IN8
|
||||
#define ADC_CHANNEL_SWE ADC_Channel_10 // ADC123_IN10-> ADC1_IN10
|
||||
#define ADC_CHANNEL_SWF ADC_Channel_11 // ADC123_IN11-> ADC1_IN11
|
||||
#define ADC_CHANNEL_SWG ADC_Channel_7 // ADC12_IN7 -> ADC1_IN7
|
||||
#define ADC_CHANNEL_SWH ADC_Channel_12 // ADC123_IN12-> ADC1_IN12
|
||||
#define ADC_CHANNEL_POT1 LL_ADC_CHANNEL_6 // ADC12_IN6 -> ADC1_IN6
|
||||
#define ADC_CHANNEL_POT2 LL_ADC_CHANNEL_14 // ADC12_IN14 -> ADC1_IN14
|
||||
#define ADC_CHANNEL_SWA LL_ADC_CHANNEL_9 // ADC12_IN9 -> ADC1_IN9
|
||||
#define ADC_CHANNEL_SWB LL_ADC_CHANNEL_6 // ADC3_IN6 -> ADC3_IN6
|
||||
#define ADC_CHANNEL_SWC LL_ADC_CHANNEL_8 // ADC12_IN8 -> ADC1_IN8
|
||||
#define ADC_CHANNEL_SWD LL_ADC_CHANNEL_8 // ADC3_IN8 -> ADC3_IN8
|
||||
#define ADC_CHANNEL_SWE LL_ADC_CHANNEL_10 // ADC123_IN10-> ADC1_IN10
|
||||
#define ADC_CHANNEL_SWF LL_ADC_CHANNEL_11 // ADC123_IN11-> ADC1_IN11
|
||||
#define ADC_CHANNEL_SWG LL_ADC_CHANNEL_12 // ADC123_IN12-> ADC1_IN12
|
||||
#define ADC_CHANNEL_SWH LL_ADC_CHANNEL_7 // ADC12_IN7 -> ADC1_IN7
|
||||
|
||||
#define ADC_CHANNEL_BATT LL_ADC_CHANNEL_15 // ADC12_IN15 -> ADC1_IN15
|
||||
#define ADC_CHANNEL_RTC_BAT LL_ADC_CHANNEL_VBAT // ADC1_IN18
|
||||
|
||||
#define ADC_CHANNEL_BATT ADC_Channel_15 // ADC12_IN15 -> ADC1_IN15
|
||||
#define ADC_MAIN ADC1
|
||||
#define ADC_EXT ADC3
|
||||
#define ADC_SAMPTIME 2
|
||||
#define ADC_EXT_CHANNELS { ADC_CHANNEL_SWB, ADC_CHANNEL_SWD }
|
||||
#define ADC_SAMPTIME LL_ADC_SAMPLINGTIME_28CYCLES
|
||||
#define ADC_DMA DMA2
|
||||
#define ADC_DMA_Channel DMA_Channel_0
|
||||
#define ADC_DMA_Stream DMA2_Stream4
|
||||
#define ADC_DMA_TC_Flag DMA_FLAG_TCIF4
|
||||
#define ADC_DMA_CHANNEL LL_DMA_CHANNEL_0
|
||||
#define ADC_DMA_STREAM LL_DMA_STREAM_4
|
||||
#define ADC_DMA_STREAM_IRQ DMA2_Stream4_IRQn
|
||||
#define ADC_DMA_STREAM_IRQHandler DMA2_Stream4_IRQHandler
|
||||
|
||||
#define ADC_EXT_DMA_Channel DMA_Channel_2
|
||||
#define ADC_EXT_DMA_Stream DMA2_Stream0
|
||||
#define ADC_EXT_TC_Flag DMA_FLAG_TCIF0
|
||||
#define ADC_EXT_DMA DMA2
|
||||
#define ADC_EXT_DMA_CHANNEL LL_DMA_CHANNEL_2
|
||||
#define ADC_EXT_DMA_STREAM LL_DMA_STREAM_0
|
||||
#define ADC_EXT_DMA_STREAM_IRQ DMA2_Stream0_IRQn
|
||||
#define ADC_EXT_DMA_STREAM_IRQHandler DMA2_Stream0_IRQHandler
|
||||
#define ADC_EXT_SAMPTIME LL_ADC_SAMPLINGTIME_28CYCLES
|
||||
#define ADC_VREF_PREC2 660
|
||||
|
||||
#define ADC_DIRECTION \
|
||||
{ 0 /*STICK1*/, 0 /*STICK2*/, 0 /*STICK3*/, 0 /*STICK4*/, \
|
||||
-1 /*POT1*/, 0 /*POT2*/, 0 /*SWA*/, 0 /*SWB*/, 0 /*SWC*/, \
|
||||
0 /*SWD*/, 0 /*SWE*/, -1 /*SWF*/, -1 /*SWG*/, 0 /*SWH*/, \
|
||||
0 /*TX_VOLTAGE*/, 0 /*TX_VBAT*/ \
|
||||
}
|
||||
|
||||
// Power
|
||||
#define PWR_RCC_AHB1Periph RCC_AHB1Periph_GPIOI
|
||||
|
||||
@@ -1,171 +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"
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
|
||||
#if defined(LUA)
|
||||
#include "lua/lua_api.h"
|
||||
#endif
|
||||
|
||||
bool trimsAsButtons = false;
|
||||
|
||||
void setTrimsAsButtons(bool val) { trimsAsButtons = val; }
|
||||
|
||||
bool getTrimsAsButtons()
|
||||
{
|
||||
bool lua = false;
|
||||
#if defined(LUA)
|
||||
lua = isLuaStandaloneRunning();
|
||||
#endif
|
||||
return (trimsAsButtons || lua);
|
||||
}
|
||||
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
#ifndef BOOT
|
||||
if (getTrimsAsButtons()) {
|
||||
#endif
|
||||
if (TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
|
||||
result |= 1 << KEY_RADIO;
|
||||
if (TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
|
||||
result |= 1 << KEY_MODEL;
|
||||
if (TRIMS_GPIO_REG_LVD & TRIMS_GPIO_PIN_LVD)
|
||||
result |= 1 << KEY_TELEM;
|
||||
if (TRIMS_GPIO_REG_LVU & TRIMS_GPIO_PIN_LVU)
|
||||
result |= 1 << KEY_PGUP;
|
||||
if (TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
|
||||
result |= 1 << KEY_DOWN;
|
||||
if (TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
|
||||
result |= 1 << KEY_UP;
|
||||
if (TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
|
||||
result |= 1 << KEY_LEFT;
|
||||
if (TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
|
||||
result |= 1 << KEY_RIGHT;
|
||||
#ifndef BOOT
|
||||
}
|
||||
#endif
|
||||
|
||||
// Enter and Exit are always supported
|
||||
if (TRIMS_GPIO_REG_RPRESS & TRIMS_GPIO_PIN_RPRESS)
|
||||
result |= 1 << KEY_ENTER;
|
||||
if (TRIMS_GPIO_REG_LPRESS & TRIMS_GPIO_PIN_LPRESS)
|
||||
result |= 1 << KEY_EXIT;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t readTrims()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
if(getTrimsAsButtons()) return result;
|
||||
if (TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
|
||||
result |= 1 << (TRM_LH_DWN - TRM_BASE);
|
||||
if (TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
|
||||
result |= 1 << (TRM_LH_UP - TRM_BASE);
|
||||
if (TRIMS_GPIO_REG_LVD & TRIMS_GPIO_PIN_LVD)
|
||||
result |= 1 << (TRM_LV_DWN - TRM_BASE);
|
||||
if (TRIMS_GPIO_REG_LVU & TRIMS_GPIO_PIN_LVU)
|
||||
result |= 1 << (TRM_LV_UP - TRM_BASE);
|
||||
if (TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
|
||||
result |= 1 << (TRM_RV_DWN - TRM_BASE);
|
||||
if (TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
|
||||
result |= 1 << (TRM_RV_UP - TRM_BASE);
|
||||
if (TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
|
||||
result |= 1 << (TRM_RH_DWN - TRM_BASE);
|
||||
if (TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
|
||||
result |= 1 << (TRM_RH_UP - TRM_BASE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool trimDown(uint8_t idx)
|
||||
{
|
||||
return readTrims() & (1 << idx);
|
||||
}
|
||||
|
||||
bool keyDown()
|
||||
{
|
||||
return readKeys() || readTrims();
|
||||
}
|
||||
|
||||
#if !defined(BOOT)
|
||||
uint32_t switchState(uint8_t index)
|
||||
{
|
||||
uint16_t value = getAnalogValue(SWITCH_FIRST + index / 3);
|
||||
uint8_t position;
|
||||
|
||||
if (value < 1024)
|
||||
position = 0;
|
||||
else if (value > 3 * 1024)
|
||||
position = 2;
|
||||
else
|
||||
position = 1;
|
||||
|
||||
return position == (index % 3);
|
||||
}
|
||||
#endif
|
||||
|
||||
void monitorInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = VBUS_MONITOR_PIN;
|
||||
GPIO_Init(GPIOJ, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
void keysInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOB_PINS;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOC_PINS;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOD_PINS;
|
||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOG_PINS;
|
||||
GPIO_Init(GPIOG, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOH_PINS;
|
||||
GPIO_Init(GPIOH, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOJ_PINS;
|
||||
GPIO_Init(GPIOJ, &GPIO_InitStructure);
|
||||
setTrimsAsButtons(false);
|
||||
}
|
||||
@@ -21,7 +21,13 @@
|
||||
|
||||
#include "opentx_types.h"
|
||||
#include "libopenui_config.h"
|
||||
|
||||
#include "lcd.h"
|
||||
#include "lcd_driver.h"
|
||||
|
||||
// StdPeriph
|
||||
#include "stm32f4xx_ltdc.h"
|
||||
#include "stm32f4xx_dma2d.h"
|
||||
|
||||
static volatile uint8_t _frame_addr_reloaded = 0;
|
||||
|
||||
|
||||
@@ -138,6 +138,3 @@ constexpr LcdFlags TABLE_BODY_FONT = FONT(STD);
|
||||
|
||||
constexpr int CJK_FIRST_LETTER_INDEX = 128 - 32 + 21;
|
||||
constexpr coord_t CHAR_SPACING = 0;
|
||||
|
||||
// Disable rotary encoder, as the NV14 does not have one
|
||||
#define ROTARY_ENCODER_SPEED() 0
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "stm32f4xx_fmc.h"
|
||||
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_1 ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_2 ((uint16_t)0x0001)
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "hal.h"
|
||||
|
||||
#include "stm32_i2c_driver.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
|
||||
#include "timers_driver.h"
|
||||
#include "delays_driver.h"
|
||||
#include "touch_driver.h"
|
||||
@@ -128,21 +130,11 @@ void I2C_FreeBus()
|
||||
// __HAL_RCC_I2C1_RELEASE_RESET();
|
||||
// }
|
||||
|
||||
static int _enable_gpio_clock(GPIO_TypeDef *GPIOx)
|
||||
{
|
||||
if (GPIOx == GPIOB)
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
else
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void I2C_Init()
|
||||
{
|
||||
stm32_i2c_deinit(TOUCH_I2C_BUS);
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
stm32_gpio_enable_clock(TOUCH_GPIO);
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
@@ -155,8 +147,8 @@ void I2C_Init()
|
||||
LL_GPIO_InitTypeDef gpioInit;
|
||||
LL_GPIO_StructInit(&gpioInit);
|
||||
|
||||
_enable_gpio_clock(TOUCH_RST_GPIO);
|
||||
_enable_gpio_clock(TOUCH_INT_GPIO);
|
||||
stm32_gpio_enable_clock(TOUCH_RST_GPIO);
|
||||
stm32_gpio_enable_clock(TOUCH_INT_GPIO);
|
||||
|
||||
gpioInit.Pin = TOUCH_RST_GPIO_PIN;
|
||||
gpioInit.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
|
||||
@@ -11,6 +11,8 @@ set(SIMU_DRIVERS
|
||||
simufatfs.cpp
|
||||
simudisk.cpp
|
||||
simulcd.cpp
|
||||
switch_driver.cpp
|
||||
adc_driver.cpp
|
||||
module_drivers.cpp
|
||||
led_driver.cpp
|
||||
backlight_driver.cpp
|
||||
@@ -18,6 +20,19 @@ set(SIMU_DRIVERS
|
||||
bt_driver.cpp
|
||||
)
|
||||
|
||||
set(HW_DESC_JSON ${FLAVOUR}.json)
|
||||
AddHardwareDefTarget(${HW_DESC_JSON})
|
||||
AddHWGenTarget(${HW_DESC_JSON} simu_keys simu_keys.inc)
|
||||
AddHWGenTarget(${HW_DESC_JSON} simu_switches simu_switches.inc)
|
||||
AddHWGenTarget(${HW_DESC_JSON} hal_adc_inputs hal_adc_inputs.inc)
|
||||
|
||||
set(SIMU_DRIVERS ${SIMU_DRIVERS}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simu_keys.inc
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simu_switches.inc
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hal_adc_inputs.inc
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${HW_DESC_JSON}
|
||||
)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
if(SDL2_FOUND)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
@@ -156,7 +171,6 @@ endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
|
||||
|
||||
use_cxx11() # ensure gnu++11 in CXX_FLAGS with CMake < 3.1
|
||||
|
||||
if(FOX_FOUND)
|
||||
add_executable(simu WIN32
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 "hal/adc_driver.h"
|
||||
#include "definitions.h"
|
||||
|
||||
#include "myeeprom.h"
|
||||
#include "translations.h"
|
||||
|
||||
#include "hal_adc_inputs.inc"
|
||||
#include "board.h"
|
||||
|
||||
void enableVBatBridge(){}
|
||||
void disableVBatBridge(){}
|
||||
bool isVBatBridgeEnabled(){ return false; }
|
||||
|
||||
extern uint16_t simu_get_analog(uint8_t idx);
|
||||
|
||||
static bool simu_start_conversion()
|
||||
{
|
||||
int max_input = adcGetInputOffset(ADC_INPUT_VBAT);
|
||||
for (int i = 0; i < max_input; i++) {
|
||||
setAnalogValue(i, simu_get_analog(i));
|
||||
}
|
||||
|
||||
// set VBAT / RTC_BAT
|
||||
if (adcGetMaxInputs(ADC_INPUT_VBAT) > 0) {
|
||||
uint32_t vbat = (BATTERY_MAX + BATTERY_MIN) / 2;
|
||||
vbat = (vbat * BATTERY_DIVIDER) / 100;
|
||||
setAnalogValue(adcGetInputOffset(ADC_INPUT_VBAT), vbat * 2);
|
||||
}
|
||||
|
||||
if (adcGetMaxInputs(ADC_INPUT_RTC_BAT) > 0) {
|
||||
uint32_t rtc_bat = (300 * (2048 >> ANALOG_SCALE)) / ADC_VREF_PREC2;
|
||||
setAnalogValue(adcGetInputOffset(ADC_INPUT_RTC_BAT), rtc_bat * 2);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
extern const etx_hal_adc_driver_t simu_adc_driver;
|
||||
|
||||
const etx_hal_adc_driver_t simu_adc_driver = {
|
||||
.inputs = _hal_inputs,
|
||||
.default_pots_cfg = _pot_default_config,
|
||||
.init = nullptr,
|
||||
.start_conversion = simu_start_conversion,
|
||||
.wait_completion = nullptr,
|
||||
};
|
||||
@@ -28,3 +28,4 @@ void ledBlue() {}
|
||||
void ledOff() {}
|
||||
void fsLedOn(uint8_t) {}
|
||||
void fsLedOff(uint8_t) {}
|
||||
bool getFSLedState(uint8_t) { return false;}
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
#include "opentxsimulator.h"
|
||||
#include "opentx.h"
|
||||
#include "simulcd.h"
|
||||
#include "switches.h"
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/rotary_encoder.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QElapsedTimer>
|
||||
@@ -34,7 +38,7 @@
|
||||
|
||||
#define ETXS_DBG qDebug() << "(" << simuTimerMicros() << "us)"
|
||||
|
||||
int16_t g_anas[Analogs::NUM_ANALOGS];
|
||||
int16_t g_anas[MAX_ANALOG_INPUTS];
|
||||
QVector<QIODevice *> OpenTxSimulator::tracebackDevices;
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
@@ -44,14 +48,9 @@ QVector<QIODevice *> OpenTxSimulator::tracebackDevices;
|
||||
#define TAP_TIME 25
|
||||
#endif
|
||||
|
||||
uint16_t anaIn(uint8_t chan)
|
||||
uint16_t simu_get_analog(uint8_t idx)
|
||||
{
|
||||
return g_anas[chan];
|
||||
}
|
||||
|
||||
uint16_t getAnalogValue(uint8_t index)
|
||||
{
|
||||
return anaIn(index);
|
||||
return g_anas[idx];
|
||||
}
|
||||
|
||||
void firmwareTraceCb(const char * text)
|
||||
@@ -123,9 +122,10 @@ void OpenTxSimulator::init()
|
||||
QMutexLocker lckr(&m_mtxSimuMain);
|
||||
memset(g_anas, 0, sizeof(g_anas));
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
g_anas[TX_RTC_VOLTAGE] = 800; // 2,34V
|
||||
#endif
|
||||
if (adcGetMaxInputs(ADC_INPUT_RTC_BAT) > 0) {
|
||||
auto idx = adcGetInputOffset(ADC_INPUT_RTC_BAT);
|
||||
setAnalogValue(idx, 800);
|
||||
}
|
||||
|
||||
simuInit();
|
||||
}
|
||||
@@ -221,9 +221,7 @@ void OpenTxSimulator::setTrimSwitch(uint8_t trim, bool state)
|
||||
|
||||
void OpenTxSimulator::setTrim(unsigned int idx, int value)
|
||||
{
|
||||
unsigned i = idx;
|
||||
if (i < 4) // swap axes
|
||||
i = modn12x3[4 * getStickMode() + idx];
|
||||
unsigned i = inputMappingConvertMode(idx);
|
||||
uint8_t phase = getTrimFlightMode(getFlightMode(), i);
|
||||
setTrimValue(phase, i, value);
|
||||
}
|
||||
@@ -245,13 +243,14 @@ void OpenTxSimulator::setInputValue(int type, uint8_t index, int16_t value)
|
||||
setAnalogValue(index, value);
|
||||
break;
|
||||
case INPUT_SRC_KNOB :
|
||||
setAnalogValue(index + NUM_STICKS, value);
|
||||
break;
|
||||
case INPUT_SRC_SLIDER :
|
||||
setAnalogValue(index + NUM_STICKS + NUM_POTS, value);
|
||||
setAnalogValue(index + adcGetInputOffset(ADC_INPUT_POT), value);
|
||||
break;
|
||||
case INPUT_SRC_TXVIN :
|
||||
setAnalogValue(Analogs::TX_VOLTAGE, voltageToAdc(value));
|
||||
if (adcGetMaxInputs(ADC_INPUT_VBAT) > 0) {
|
||||
auto idx = adcGetInputOffset(ADC_INPUT_VBAT);
|
||||
setAnalogValue(idx, voltageToAdc(value));
|
||||
}
|
||||
break;
|
||||
case INPUT_SRC_SWITCH :
|
||||
setSwitch(index, (int8_t)value);
|
||||
@@ -274,6 +273,7 @@ void OpenTxSimulator::setInputValue(int type, uint8_t index, int16_t value)
|
||||
}
|
||||
}
|
||||
|
||||
extern volatile rotenc_t rotencValue;
|
||||
extern volatile uint32_t rotencDt;
|
||||
|
||||
void OpenTxSimulator::rotaryEncoderEvent(int steps)
|
||||
@@ -282,7 +282,7 @@ void OpenTxSimulator::rotaryEncoderEvent(int steps)
|
||||
static uint32_t last_tick = 0;
|
||||
if (steps != 0) {
|
||||
if (g_eeGeneral.rotEncMode >= ROTARY_ENCODER_MODE_INVERT_BOTH) steps *= -1;
|
||||
ROTARY_ENCODER_NAVIGATION_VALUE += steps * ROTARY_ENCODER_GRANULARITY;
|
||||
rotencValue += steps * ROTARY_ENCODER_GRANULARITY;
|
||||
// TODO: set rotencDt
|
||||
uint32_t now = RTOS_GET_MS();
|
||||
uint32_t dt = now - last_tick;
|
||||
@@ -548,7 +548,6 @@ void OpenTxSimulator::checkOutputsChanged()
|
||||
qint32 tmpVal;
|
||||
uint8_t i, idx;
|
||||
const uint8_t phase = getFlightMode(); // opentx.cpp
|
||||
const uint8_t mode = getStickMode();
|
||||
|
||||
for (i=0; i < chansDim; i++) {
|
||||
if (lastOutputs.chans[i] != channelOutputs[i] || m_resetOutputsData) {
|
||||
@@ -564,7 +563,7 @@ void OpenTxSimulator::checkOutputsChanged()
|
||||
}
|
||||
|
||||
for (i=0; i < MAX_LOGICAL_SWITCHES; i++) {
|
||||
tmpVal = (qint32)GET_SWITCH_BOOL(SWSRC_SW1+i);
|
||||
tmpVal = (qint32)GET_SWITCH_BOOL(SWSRC_FIRST_LOGICAL_SWITCH+i);
|
||||
if (lastOutputs.vsw[i] != (bool)tmpVal || m_resetOutputsData) {
|
||||
emit virtualSwValueChange(i, tmpVal);
|
||||
emit outputValueChange(OUTPUT_SRC_VIRTUAL_SW, i, tmpVal);
|
||||
@@ -573,11 +572,7 @@ void OpenTxSimulator::checkOutputsChanged()
|
||||
}
|
||||
|
||||
for (i=0; i < Board::TRIM_AXIS_COUNT; i++) {
|
||||
if (i < 4) // swap axes
|
||||
idx = modn12x3[4 * mode + i];
|
||||
else
|
||||
idx = i;
|
||||
|
||||
idx = inputMappingConvertMode(i);
|
||||
tmpVal = getTrimValue(getTrimFlightMode(phase, idx), idx);
|
||||
if (lastOutputs.trims[i] != tmpVal || m_resetOutputsData) {
|
||||
emit trimValueChange(i, tmpVal);
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include "opentx.h"
|
||||
#include "simulcd.h"
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/rotary_encoder.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
@@ -45,16 +48,20 @@ char * main_thread_error = nullptr;
|
||||
bool simu_shutdown = false;
|
||||
bool simu_running = false;
|
||||
|
||||
uint32_t telemetryErrors = 0;
|
||||
|
||||
typedef int32_t rotenc_t;
|
||||
volatile rotenc_t rotencValue = 0;
|
||||
volatile uint32_t rotencDt = 0;
|
||||
|
||||
rotenc_t rotaryEncoderGetValue()
|
||||
{
|
||||
return rotencValue / ROTARY_ENCODER_GRANULARITY;
|
||||
}
|
||||
|
||||
rotenc_t rotaryEncoderGetRawValue() { return rotencValue; }
|
||||
|
||||
// TODO: remove all STM32 defs
|
||||
GPIO_TypeDef gpioa, gpiob, gpioc, gpiod, gpioe, gpiof, gpiog, gpioh, gpioi, gpioj;
|
||||
ADC_Common_TypeDef adc;
|
||||
RTC_TypeDef rtc;
|
||||
|
||||
extern const etx_hal_adc_driver_t simu_adc_driver;
|
||||
|
||||
void lcdCopy(void * dest, void * src);
|
||||
|
||||
@@ -114,9 +121,12 @@ void simuInit()
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
rotencValue = 0;
|
||||
#endif
|
||||
|
||||
// Init ADC driver callback
|
||||
adcInit(&simu_adc_driver);
|
||||
}
|
||||
|
||||
bool keysStates[NUM_KEYS] = { false };
|
||||
bool keysStates[MAX_KEYS] = { false };
|
||||
void simuSetKey(uint8_t key, bool state)
|
||||
{
|
||||
// TRACE("simuSetKey(%d, %d)", key, state);
|
||||
@@ -124,7 +134,7 @@ void simuSetKey(uint8_t key, bool state)
|
||||
keysStates[key] = state;
|
||||
}
|
||||
|
||||
bool trimsStates[NUM_TRIMS_KEYS] = { false };
|
||||
bool trimsStates[MAX_TRIMS * 2] = { false };
|
||||
void simuSetTrim(uint8_t trim, bool state)
|
||||
{
|
||||
// TRACE("simuSetTrim(%d, %d)", trim, state);
|
||||
@@ -132,14 +142,6 @@ void simuSetTrim(uint8_t trim, bool state)
|
||||
trimsStates[trim] = state;
|
||||
}
|
||||
|
||||
int8_t switchesStates[NUM_SWITCHES] = { -1 };
|
||||
void simuSetSwitch(uint8_t swtch, int8_t state)
|
||||
{
|
||||
// TRACE("simuSetSwitch(%d, %d)", swtch, state);
|
||||
assert(swtch < DIM(switchesStates));
|
||||
switchesStates[swtch] = state;
|
||||
}
|
||||
|
||||
#if defined(SIMU_BOOTLOADER)
|
||||
int bootloaderMain();
|
||||
static void* bootloaderThread(void*)
|
||||
@@ -206,9 +208,9 @@ void simuStart(bool tests, const char * sdPath, const char * settingsPath)
|
||||
try {
|
||||
#endif
|
||||
|
||||
// Init LCD call backs
|
||||
// Init LCD callbacks
|
||||
lcdInit();
|
||||
|
||||
|
||||
#if !defined(SIMU_BOOTLOADER)
|
||||
simuMain();
|
||||
#else
|
||||
@@ -421,86 +423,28 @@ void lcdSetRefVolt(uint8_t val)
|
||||
}
|
||||
#endif
|
||||
|
||||
void telemetryPortInit(uint8_t baudrate)
|
||||
{
|
||||
}
|
||||
|
||||
void telemetryPortInit()
|
||||
{
|
||||
}
|
||||
|
||||
void sportUpdatePowerOn()
|
||||
{
|
||||
}
|
||||
|
||||
void sportUpdatePowerOff()
|
||||
{
|
||||
}
|
||||
|
||||
void sportUpdatePowerInit()
|
||||
{
|
||||
}
|
||||
|
||||
void telemetryPortSetDirectionInput()
|
||||
{
|
||||
}
|
||||
|
||||
void telemetryPortSetDirectionOutput()
|
||||
{
|
||||
}
|
||||
|
||||
void rxPdcUsart( void (*pChProcess)(uint8_t x) )
|
||||
{
|
||||
}
|
||||
|
||||
void telemetryPortInit(uint32_t baudrate, uint8_t mode)
|
||||
{
|
||||
}
|
||||
|
||||
bool sportGetByte(uint8_t * byte)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void telemetryClearFifo()
|
||||
{
|
||||
}
|
||||
|
||||
void telemetryPortInvertedInit(uint32_t baudrate)
|
||||
{
|
||||
}
|
||||
|
||||
void sportSendByte(uint8_t byte)
|
||||
{
|
||||
}
|
||||
|
||||
void sportSendBuffer(const uint8_t * buffer, uint32_t count)
|
||||
{
|
||||
}
|
||||
|
||||
void check_telemetry_exti()
|
||||
{
|
||||
}
|
||||
|
||||
void boardInit()
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t pwrCheck() { return simu_shutdown ? e_power_off : e_power_on; }
|
||||
|
||||
bool pwrPressed() { return false; }
|
||||
bool pwrOffPressed()
|
||||
{
|
||||
#if defined(PWR_BUTTON_PRESS)
|
||||
return pwrPressed();
|
||||
#else
|
||||
return !pwrPressed();
|
||||
#endif
|
||||
}
|
||||
|
||||
void pwrInit() {}
|
||||
void pwrOn() {}
|
||||
void pwrOff() {}
|
||||
|
||||
bool keyDown()
|
||||
{
|
||||
return readKeys();
|
||||
}
|
||||
|
||||
bool trimDown(uint8_t idx)
|
||||
{
|
||||
return readTrims() & (1 << idx);
|
||||
}
|
||||
bool UNEXPECTED_SHUTDOWN() { return false; }
|
||||
void SET_POWER_REASON(uint32_t value) {}
|
||||
|
||||
#if defined(TRIMS_EMULATE_BUTTONS)
|
||||
bool trimsAsButtons = false;
|
||||
@@ -521,7 +465,7 @@ uint32_t readKeys()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
for (int i = 0; i < NUM_KEYS; i++) {
|
||||
for (int i = 0; i < MAX_KEYS; i++) {
|
||||
if (keysStates[i]) {
|
||||
// TRACE("key pressed %d", i);
|
||||
result |= 1 << i;
|
||||
@@ -535,7 +479,7 @@ uint32_t readTrims()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
for (int i=0; i<NUM_TRIMS_KEYS; i++) {
|
||||
for (int i = 0; i < MAX_TRIMS; i++) {
|
||||
if (trimsStates[i]) {
|
||||
// TRACE("trim pressed %d", i);
|
||||
result |= 1 << i;
|
||||
@@ -543,27 +487,13 @@ uint32_t readTrims()
|
||||
}
|
||||
|
||||
#if defined(PCBXLITE)
|
||||
if (IS_SHIFT_PRESSED())
|
||||
if (keysStates[KEY_SHIFT])
|
||||
result = ((result & 0x03) << 6) | ((result & 0x0c) << 2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t switchState(uint8_t index)
|
||||
{
|
||||
div_t qr = div(index, 3);
|
||||
int state = switchesStates[qr.quot];
|
||||
switch (qr.rem) {
|
||||
case 0:
|
||||
return state < 0;
|
||||
case 2:
|
||||
return state > 0;
|
||||
default:
|
||||
return state == 0;
|
||||
}
|
||||
}
|
||||
|
||||
int usbPlugged() { return false; }
|
||||
int getSelectedUsbMode() { return USB_JOYSTICK_MODE; }
|
||||
void setSelectedUsbMode(int mode) {}
|
||||
@@ -599,16 +529,6 @@ void serialPrintf(const char * format, ...) { }
|
||||
void serialCrlf() { }
|
||||
void serialPutc(char c) { }
|
||||
|
||||
uint16_t getBatteryVoltage()
|
||||
{
|
||||
return (g_eeGeneral.vBatWarn * 10) + 50; // 0.5 volt above alerm (value is PREC1)
|
||||
}
|
||||
|
||||
uint16_t getRTCBatteryVoltage()
|
||||
{
|
||||
return 300;
|
||||
}
|
||||
|
||||
void boardOff()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -22,176 +22,20 @@
|
||||
#ifndef _SIMPGMSPACE_H_
|
||||
#define _SIMPGMSPACE_H_
|
||||
|
||||
#ifndef __GNUC__
|
||||
#include <windows.h>
|
||||
#include <intrin.h>
|
||||
#define sleep(x) Sleep(x)
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _tcsnicmp
|
||||
#define chdir _chdir
|
||||
#define getcwd _getcwd
|
||||
inline int __builtin_clz(unsigned x)
|
||||
{
|
||||
return (int)__lzcnt(x);
|
||||
}
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define sleep(x) usleep(1000*x)
|
||||
#endif
|
||||
|
||||
#ifdef SIMU_EXCEPTIONS
|
||||
extern char * main_thread_error;
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#if defined(_MSC_VER) || !defined(__GNUC__)
|
||||
#define write_backtrace(output)
|
||||
#else
|
||||
#include <execinfo.h>
|
||||
inline void write_backtrace(char *output)
|
||||
{
|
||||
void *buf[16];
|
||||
char **s;
|
||||
int n = backtrace(buf, 16);
|
||||
s = backtrace_symbols(buf, n);
|
||||
if (s) {
|
||||
for (int i=0; i<n; ++i) {
|
||||
sprintf(output+strlen(output), "%02i: %s\n", i, s[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void sig(int sgn)
|
||||
{
|
||||
main_thread_error = (char *)malloc(2048);
|
||||
sprintf(main_thread_error,"Signal %d caught\n", sgn);
|
||||
write_backtrace(main_thread_error);
|
||||
throw std::exception();
|
||||
}
|
||||
#define assert(x) do { if (!(x)) { main_thread_error = (char *)malloc(2048); sprintf(main_thread_error, "Assert failed, %s:%d: %s\n", __FILE__, __LINE__, #x); write_backtrace(main_thread_error); throw std::exception(); } } while(0)
|
||||
#else
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
#define __REV
|
||||
|
||||
extern GPIO_TypeDef gpioa, gpiob, gpioc, gpiod, gpioe, gpiof, gpiog, gpioh, gpioi, gpioj;
|
||||
extern TIM_TypeDef tim1, tim2, tim3, tim4, tim5, tim6, tim7, tim8, tim9, tim10;
|
||||
extern USART_TypeDef Usart0, Usart1, Usart2, Usart3, Usart4;
|
||||
extern RCC_TypeDef rcc;
|
||||
extern DMA_Stream_TypeDef dma1_stream0, dma1_stream1, dma1_stream2, dma1_stream3, dma1_stream4, dma1_stream5, dma1_stream6, dma1_stream7, dma2_stream1, dma2_stream2, dma2_stream5, dma2_stream6, dma2_stream7;
|
||||
extern DMA_TypeDef dma2;
|
||||
extern SysTick_Type systick;
|
||||
extern ADC_Common_TypeDef adc;
|
||||
extern RTC_TypeDef rtc;
|
||||
#undef SysTick
|
||||
#define SysTick (&systick)
|
||||
#undef GPIOA
|
||||
#undef GPIOB
|
||||
#undef GPIOC
|
||||
#undef GPIOD
|
||||
#undef GPIOE
|
||||
#undef GPIOF
|
||||
#undef GPIOG
|
||||
#undef GPIOH
|
||||
#undef GPIOI
|
||||
#undef GPIOJ
|
||||
#define GPIOA (&gpioa)
|
||||
#define GPIOB (&gpiob)
|
||||
#define GPIOC (&gpioc)
|
||||
#define GPIOD (&gpiod)
|
||||
#define GPIOE (&gpioe)
|
||||
#define GPIOF (&gpiof)
|
||||
#define GPIOG (&gpiog)
|
||||
#define GPIOH (&gpioh)
|
||||
#define GPIOI (&gpioi)
|
||||
#define GPIOJ (&gpioj)
|
||||
#undef TIM1
|
||||
#undef TIM2
|
||||
#undef TIM3
|
||||
#undef TIM4
|
||||
#undef TIM5
|
||||
#undef TIM6
|
||||
#undef TIM7
|
||||
#undef TIM8
|
||||
#undef TIM9
|
||||
#undef TIM10
|
||||
#define TIM1 (&tim1)
|
||||
#define TIM2 (&tim2)
|
||||
#define TIM3 (&tim3)
|
||||
#define TIM4 (&tim4)
|
||||
#define TIM5 (&tim4)
|
||||
#define TIM6 (&tim4)
|
||||
#define TIM7 (&tim4)
|
||||
#define TIM8 (&tim8)
|
||||
#define TIM9 (&tim9)
|
||||
#define TIM10 (&tim10)
|
||||
#undef USART0
|
||||
#undef USART1
|
||||
#undef USART2
|
||||
#undef USART3
|
||||
#define USART0 (&Usart0)
|
||||
#define USART1 (&Usart1)
|
||||
#define USART2 (&Usart2)
|
||||
#define USART3 (&Usart3)
|
||||
#undef RCC
|
||||
#define RCC (&rcc)
|
||||
#undef DMA1_Stream0
|
||||
#undef DMA1_Stream1
|
||||
#undef DMA1_Stream2
|
||||
#undef DMA1_Stream3
|
||||
#undef DMA1_Stream4
|
||||
#undef DMA1_Stream5
|
||||
#undef DMA1_Stream7
|
||||
#undef DMA2_Stream1
|
||||
#undef DMA2_Stream2
|
||||
#undef DMA2_Stream5
|
||||
#undef DMA2_Stream6
|
||||
#undef DMA2_Stream7
|
||||
#define DMA1_Stream0 (&dma1_stream0)
|
||||
#define DMA1_Stream1 (&dma1_stream1)
|
||||
#define DMA1_Stream2 (&dma1_stream2)
|
||||
#define DMA1_Stream3 (&dma1_stream3)
|
||||
#define DMA1_Stream4 (&dma1_stream4)
|
||||
#define DMA1_Stream5 (&dma1_stream5)
|
||||
#define DMA1_Stream7 (&dma1_stream7)
|
||||
#define DMA2_Stream1 (&dma2_stream1)
|
||||
#define DMA2_Stream2 (&dma2_stream2)
|
||||
#define DMA2_Stream5 (&dma2_stream5)
|
||||
#define DMA2_Stream6 (&dma2_stream6)
|
||||
#define DMA2_Stream7 (&dma2_stream7)
|
||||
#undef DMA2
|
||||
#define DMA2 (&dma2)
|
||||
#undef ADC
|
||||
#define ADC (&adc)
|
||||
#undef RTC
|
||||
#define RTC (&rtc)
|
||||
// #undef min
|
||||
// #undef max
|
||||
|
||||
extern uint8_t * eeprom;
|
||||
extern void startPdcUsartReceive() ;
|
||||
extern uint32_t txPdcUsart( uint8_t *buffer, uint32_t size );
|
||||
extern uint32_t txPdcPending();
|
||||
extern void rxPdcUsart( void (*pChProcess)(uint8_t x) );
|
||||
|
||||
#define ISR(x, ...) void x()
|
||||
|
||||
#if !defined(_MSC_VER) && defined(__GNUC__)
|
||||
#define asm(...)
|
||||
#endif
|
||||
|
||||
extern uint32_t Master_frequency;
|
||||
#define NVIC_EnableIRQ(x)
|
||||
#define NVIC_DisableIRQ(x)
|
||||
#define NVIC_SetPriority(...)
|
||||
#define NVIC_SystemReset() exit(0)
|
||||
#define __disable_irq()
|
||||
#define __enable_irq()
|
||||
|
||||
@@ -200,7 +44,6 @@ extern char * main_thread_error;
|
||||
|
||||
#define OPENTX_START_DEFAULT_ARGS simu_start_mode
|
||||
|
||||
inline void getADC() { }
|
||||
|
||||
uint64_t simuTimerMicros(void);
|
||||
uint8_t simuSleep(uint32_t ms); // returns true if thread shutdown requested
|
||||
@@ -228,21 +71,6 @@ void stopEepromThread();
|
||||
|
||||
void simuMain();
|
||||
|
||||
#define UART_Stop(...)
|
||||
#define UART3_Stop(...)
|
||||
#define USART_GetITStatus(...) 0
|
||||
#define USART_ClearFlag(...)
|
||||
|
||||
#define TIM_DeInit(...)
|
||||
#define TIM_SetCompare2(...)
|
||||
#define TIM_ClearFlag(...)
|
||||
#define TIM_Cmd(...)
|
||||
#define TIM_ITConfig(...)
|
||||
#define GPIO_SetBits(GPIOx, pin) GPIOx->BSRRL |= pin
|
||||
#define GPIO_ResetBits(GPIOx, pin) GPIOx->BSRRL &= ~pin
|
||||
#define GPIO_ReadInputDataBit(GPIOx, pin) (GPIOx->BSRRL & pin)
|
||||
#define RCC_AHB1PeriphClockCmd(...)
|
||||
#define RCC_APB2PeriphClockCmd(...)
|
||||
|
||||
// inline void delay_01us(uint32_t dummy) { }
|
||||
|
||||
|
||||
@@ -289,9 +289,12 @@ void DMACopyAlphaMask(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
}
|
||||
}
|
||||
|
||||
#define DMA2D_ARGB4444 ((uint32_t)0x00000004)
|
||||
|
||||
void DMABitmapConvert(uint16_t *dest, const uint8_t *src, uint16_t w,
|
||||
uint16_t h, uint32_t format)
|
||||
{
|
||||
|
||||
if (format == DMA2D_ARGB4444) {
|
||||
for (int row = 0; row < h; ++row) {
|
||||
for (int col = 0; col < w; ++col) {
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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 "hal/switch_driver.h"
|
||||
#include "definitions.h"
|
||||
#include "myeeprom.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
struct hw_switch_def {
|
||||
const char* name;
|
||||
SwitchHwType type;
|
||||
};
|
||||
|
||||
#include "simu_switches.inc"
|
||||
|
||||
int8_t switchesStates[n_total_switches] = { -1 };
|
||||
|
||||
void simuSetSwitch(uint8_t swtch, int8_t state)
|
||||
{
|
||||
assert(swtch < n_total_switches);
|
||||
switchesStates[swtch] = state;
|
||||
}
|
||||
|
||||
swconfig_t switchGetDefaultConfig()
|
||||
{
|
||||
return _switch_default_config;
|
||||
}
|
||||
|
||||
switch_display_pos_t switchGetDisplayPosition(uint8_t idx)
|
||||
{
|
||||
if (idx >= DIM(_switch_display))
|
||||
return {0, 0};
|
||||
|
||||
return _switch_display[idx];
|
||||
}
|
||||
|
||||
uint8_t switchGetMaxSwitches()
|
||||
{
|
||||
return n_switches;
|
||||
}
|
||||
|
||||
uint8_t getSwitchCount()
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < switchGetMaxSwitches(); ++i) {
|
||||
if (SWITCH_EXISTS(i)) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
uint8_t switchGetMaxRow(uint8_t col)
|
||||
{
|
||||
uint8_t lastrow = 0;
|
||||
for (int i = 0; i < switchGetMaxSwitches(); ++i) {
|
||||
if (SWITCH_EXISTS(i)) {
|
||||
auto switch_display = switchGetDisplayPosition(i);
|
||||
if (switch_display.col == col)
|
||||
lastrow = switch_display.row > lastrow ? switch_display.row : lastrow;
|
||||
}
|
||||
}
|
||||
return lastrow;
|
||||
}
|
||||
|
||||
uint8_t switchGetMaxFctSwitches()
|
||||
{
|
||||
return n_fct_switches;
|
||||
}
|
||||
|
||||
const char* switchGetName(uint8_t idx)
|
||||
{
|
||||
assert(idx < n_total_switches);
|
||||
return _hw_switch_defs[idx].name;
|
||||
}
|
||||
|
||||
SwitchHwType switchGetHwType(uint8_t idx)
|
||||
{
|
||||
assert(idx < n_total_switches);
|
||||
return _hw_switch_defs[idx].type;
|
||||
}
|
||||
|
||||
uint32_t switchState(uint8_t pos)
|
||||
{
|
||||
assert(pos < n_total_switches * 3);
|
||||
|
||||
div_t qr = div(pos, 3);
|
||||
int state = switchesStates[qr.quot];
|
||||
switch (qr.rem) {
|
||||
case SWITCH_HW_UP:
|
||||
return state < 0;
|
||||
case SWITCH_HW_DOWN:
|
||||
return state > 0;
|
||||
default:
|
||||
return state == 0;
|
||||
}
|
||||
}
|
||||
|
||||
SwitchHwPos switchGetPosition(uint8_t idx)
|
||||
{
|
||||
assert(idx < n_total_switches);
|
||||
|
||||
if (switchesStates[idx] < 0)
|
||||
return SWITCH_HW_UP;
|
||||
else if (switchesStates[idx] == 0)
|
||||
return SWITCH_HW_MID;
|
||||
else
|
||||
return SWITCH_HW_DOWN;
|
||||
}
|
||||
@@ -18,12 +18,8 @@ if(PCB STREQUAL X9E)
|
||||
set(DEFAULT_INTERNAL_MODULE XJT_PXX1 CACHE STRING "Default internal module")
|
||||
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
|
||||
set(STICKS "STANDARD" CACHE STRING "Sticks type (STANDARD/HORUS)")
|
||||
set(CPU_TYPE STM32F4)
|
||||
set(CPU_TYPE_FULL STM32F407xE) # for size report
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f4_flash.ld)
|
||||
add_definitions(-DSTM32F40_41xxx -DSTM32F407xx)
|
||||
set(CPU_TYPE_FULL STM32F407xE)
|
||||
set(HAPTIC YES)
|
||||
set(LUA_EXPORT lua_export_x9e)
|
||||
set(FLAVOUR x9e)
|
||||
add_definitions(-DPCBX9E -DPCBX9)
|
||||
add_definitions(-DEEPROM_VARIANT=0x8000)
|
||||
@@ -49,7 +45,6 @@ if(PCB STREQUAL X9E)
|
||||
add_definitions(-DMANUFACTURER_FRSKY)
|
||||
elseif(PCB STREQUAL X9D+)
|
||||
set(HAPTIC YES)
|
||||
set(LUA_EXPORT lua_export_x9d)
|
||||
add_definitions(-DPCBX9DP -DPCBX9)
|
||||
add_definitions(-DEEPROM_VARIANT=0)
|
||||
set(GUI_DIR 212x64)
|
||||
@@ -66,13 +61,9 @@ elseif(PCB STREQUAL X9D+)
|
||||
if (${PCBREV} STREQUAL 2019)
|
||||
set(DEFAULT_INTERNAL_MODULE ISRM_PXX2 CACHE STRING "Default internal module")
|
||||
set(FLAVOUR x9d+2019)
|
||||
set(LUA_EXPORT lua_export_x9d+2019)
|
||||
set(CPU_TYPE STM32F4)
|
||||
set(CPU_TYPE_FULL STM32F407xE) # for size report
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f4_flash.ld)
|
||||
set(CPU_TYPE_FULL STM32F407xE)
|
||||
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
|
||||
add_definitions(-DRADIO_X9DP2019)
|
||||
add_definitions(-DSTM32F40_41xxx -DSTM32F407xx)
|
||||
add_definitions(-DSOFTWARE_VOLUME -DPWR_BUTTON_${PWR_BUTTON} -DHARDWARE_POWER_MANAGEMENT_UNIT)
|
||||
set(STATUS_LEDS YES)
|
||||
set(PXX2 ON)
|
||||
@@ -83,22 +74,15 @@ elseif(PCB STREQUAL X9D+)
|
||||
else()
|
||||
set(DEFAULT_INTERNAL_MODULE XJT_PXX1 CACHE STRING "Default internal module")
|
||||
set(FLAVOUR x9d+)
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
set(AUX_SERIAL ON)
|
||||
set(STATUS_LEDS NO)
|
||||
endif()
|
||||
elseif(PCB STREQUAL X9D)
|
||||
set(DEFAULT_INTERNAL_MODULE XJT_PXX1 CACHE STRING "Default internal module")
|
||||
set(FLAVOUR x9d)
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
option(HAPTIC "Haptic support" ON) # While the X9D doesn't have haptic OOTB, it can be added
|
||||
set(LUA_EXPORT lua_export_x9d)
|
||||
add_definitions(-DPCBX9D -DPCBX9)
|
||||
add_definitions(-DEEPROM_VARIANT=0)
|
||||
set(GUI_DIR 212x64)
|
||||
@@ -129,11 +113,7 @@ elseif(PCB STREQUAL X7)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(FLAVOUR t12)
|
||||
set(NAVIGATION_TYPE 9x)
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(LUA_EXPORT lua_export_t12)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
add_definitions(-DRADIO_T12)
|
||||
add_definitions(-DRADIO_FAMILY_JUMPER_T12)
|
||||
add_definitions(-DEEPROM_VARIANT=0x4001)
|
||||
@@ -143,12 +123,8 @@ elseif(PCB STREQUAL X7)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(FLAVOUR tpro)
|
||||
set(NAVIGATION_TYPE x7)
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(ROTARY_ENCODER YES)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(LUA_EXPORT lua_export_tpro)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
add_definitions(-DFUNCTION_SWITCHES)
|
||||
add_definitions(-DRADIO_TPRO)
|
||||
add_definitions(-DEEPROM_VARIANT=0x4005)
|
||||
@@ -159,11 +135,7 @@ elseif(PCB STREQUAL X7)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(FLAVOUR tlite)
|
||||
set(NAVIGATION_TYPE 9x)
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(LUA_EXPORT lua_export_tlite)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
add_definitions(-DRADIO_TLITE)
|
||||
add_definitions(-DRADIO_FAMILY_JUMPER_T12)
|
||||
add_definitions(-DEEPROM_VARIANT=0x4003)
|
||||
@@ -174,12 +146,7 @@ elseif(PCB STREQUAL X7)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(FLAVOUR tlitef4)
|
||||
set(NAVIGATION_TYPE 9x)
|
||||
set(CPU_TYPE STM32F4)
|
||||
set(CPU_TYPE_FULL STM32F407xE) # for size report
|
||||
add_definitions(-DSTM32F407xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f4_flash.ld)
|
||||
add_definitions(-DSTM32F40_41xxx -DSTM32F407xx)
|
||||
set(LUA_EXPORT lua_export_tlite)
|
||||
add_definitions(-DRADIO_TLITE)
|
||||
add_definitions(-DRADIO_FAMILY_JUMPER_T12)
|
||||
add_definitions(-DEEPROM_VARIANT=0x4003)
|
||||
@@ -190,11 +157,7 @@ elseif(PCB STREQUAL X7)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(FLAVOUR lr3pro)
|
||||
set(NAVIGATION_TYPE 9x)
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(LUA_EXPORT lua_export_lr3pro)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
add_definitions(-DRADIO_LR3PRO)
|
||||
add_definitions(-DRADIO_FAMILY_JUMPER_T12)
|
||||
add_definitions(-DMANUFACTURER_BETAFPV)
|
||||
@@ -204,12 +167,8 @@ elseif(PCB STREQUAL X7)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(FLAVOUR tx12)
|
||||
set(NAVIGATION_TYPE x7)
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
set(ROTARY_ENCODER YES)
|
||||
set(LUA_EXPORT lua_export_tx12)
|
||||
set(BLUETOOTH NO)
|
||||
set(USB_CHARGER YES)
|
||||
add_definitions(-DRADIO_TX12)
|
||||
@@ -220,13 +179,8 @@ elseif(PCB STREQUAL X7)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(FLAVOUR tx12mk2)
|
||||
set(NAVIGATION_TYPE x7)
|
||||
set(CPU_TYPE STM32F4)
|
||||
set(CPU_TYPE_FULL STM32F407xE) # for size report
|
||||
add_definitions(-DSTM32F407xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f4_flash.ld)
|
||||
add_definitions(-DSTM32F40_41xxx -DSTM32F407xx)
|
||||
set(CPU_TYPE_FULL STM32F407xE)
|
||||
set(ROTARY_ENCODER YES)
|
||||
set(LUA_EXPORT lua_export_tx12mk2)
|
||||
set(USB_CHARGER YES)
|
||||
if (NOT BLUETOOTH)
|
||||
set(AUX_SERIAL ON)
|
||||
@@ -241,13 +195,8 @@ elseif(PCB STREQUAL X7)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(FLAVOUR boxer)
|
||||
set(NAVIGATION_TYPE x7)
|
||||
set(CPU_TYPE STM32F4)
|
||||
set(CPU_TYPE_FULL STM32F407xE) # for size report
|
||||
add_definitions(-DSTM32F407xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f4_flash.ld)
|
||||
add_definitions(-DSTM32F40_41xxx -DSTM32F407xx)
|
||||
set(CPU_TYPE_FULL STM32F407xE)
|
||||
set(ROTARY_ENCODER YES)
|
||||
set(LUA_EXPORT lua_export_boxer)
|
||||
set(USB_CHARGER YES)
|
||||
add_definitions(-DRADIO_BOXER)
|
||||
add_definitions(-DMANUFACTURER_RADIOMASTER)
|
||||
@@ -262,13 +211,8 @@ elseif(PCB STREQUAL X7)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(FLAVOUR zorro)
|
||||
set(NAVIGATION_TYPE x7)
|
||||
set(CPU_TYPE STM32F4)
|
||||
set(CPU_TYPE_FULL STM32F407xE) # for size report
|
||||
add_definitions(-DSTM32F407xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f4_flash.ld)
|
||||
add_definitions(-DSTM32F40_41xxx -DSTM32F407xx)
|
||||
set(CPU_TYPE_FULL STM32F407xE)
|
||||
set(ROTARY_ENCODER YES)
|
||||
set(LUA_EXPORT lua_export_zorro)
|
||||
set(BLUETOOTH NO)
|
||||
set(USB_CHARGER YES)
|
||||
set(AUX_SERIAL ON)
|
||||
@@ -283,12 +227,8 @@ elseif(PCB STREQUAL X7)
|
||||
set(HARDWARE_EXTERNAL_MODULE NO)
|
||||
set(FLAVOUR t8)
|
||||
set(NAVIGATION_TYPE x7)
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
set(ROTARY_ENCODER NO)
|
||||
set(LUA_EXPORT lua_export_t8)
|
||||
set(BLUETOOTH NO)
|
||||
if(RADIOMASTER_RELEASE)
|
||||
set(BIND_KEY YES)
|
||||
@@ -302,17 +242,11 @@ elseif(PCB STREQUAL X7)
|
||||
set(HARDWARE_EXTERNAL_MODULE YES)
|
||||
set(FLAVOUR commando8)
|
||||
set(NAVIGATION_TYPE x7)
|
||||
set(CPU_TYPE STM32F4)
|
||||
set(CPU_TYPE_FULL STM32F407xE) # for size report
|
||||
add_definitions(-DSTM32F407xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f4_flash.ld)
|
||||
add_definitions(-DSTM32F407xx -DSTM32F40_41xxx)
|
||||
set(CPU_TYPE_FULL STM32F407xE)
|
||||
set(ROTARY_ENCODER NO)
|
||||
set(LUA_EXPORT lua_export_commando8)
|
||||
set(BLUETOOTH NO)
|
||||
set(USE_RTC_CLOCK NO)
|
||||
add_definitions(-DRADIO_COMMANDO8)
|
||||
add_definitions(-DSTICKS_PWM)
|
||||
add_definitions(-DMUTUALLY_EXCLUSIVE_MODULES)
|
||||
add_definitions(-DMANUFACTURER_IFLIGHT)
|
||||
elseif(PCBREV STREQUAL ACCESS)
|
||||
@@ -320,15 +254,11 @@ elseif(PCB STREQUAL X7)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(FLAVOUR x7access)
|
||||
set(NAVIGATION_TYPE x7)
|
||||
set(CPU_TYPE STM32F4)
|
||||
set(CPU_TYPE_FULL STM32F407xE) # for size report
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f4_flash.ld)
|
||||
set(LUA_EXPORT lua_export_x7access)
|
||||
set(CPU_TYPE_FULL STM32F407xE)
|
||||
add_definitions(-DRADIO_X7ACCESS)
|
||||
add_definitions(-DEEPROM_VARIANT=0x4000)
|
||||
add_definitions(-DPCBREV=${PCBREV})
|
||||
add_definitions(-DPCBX7ACCESS)
|
||||
add_definitions(-DSTM32F40_41xxx -DSTM32F407xx)
|
||||
add_definitions(-DHARDWARE_POWER_MANAGEMENT_UNIT)
|
||||
set(PXX2 ON)
|
||||
set(PXX_FREQUENCY "HIGH")
|
||||
@@ -339,11 +269,7 @@ elseif(PCB STREQUAL X7)
|
||||
set(DEFAULT_INTERNAL_MODULE XJT_PXX1 CACHE STRING "Default internal module")
|
||||
set(FLAVOUR x7)
|
||||
set(NAVIGATION_TYPE x7)
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(LUA_EXPORT lua_export_x7)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
add_definitions(-DRADIO_X7)
|
||||
add_definitions(-DEEPROM_VARIANT=0x4000)
|
||||
set(BLUETOOTH YES)
|
||||
@@ -364,12 +290,8 @@ elseif(PCB STREQUAL X9LITE)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(PXX_FREQUENCY "HIGH")
|
||||
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
set(HAPTIC YES)
|
||||
set(LUA_EXPORT lua_export_x9lite)
|
||||
set(FLAVOUR x9lite)
|
||||
add_definitions(-DBOARD_NAME="x9lite")
|
||||
add_definitions(-DPCBX9LITE -DPCBX9 -DSOFTWARE_VOLUME -DHARDWARE_POWER_MANAGEMENT_UNIT)
|
||||
@@ -391,12 +313,8 @@ elseif(PCB STREQUAL X9LITES)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(PXX_FREQUENCY "HIGH")
|
||||
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
set(HAPTIC YES)
|
||||
set(LUA_EXPORT lua_export_x9lites)
|
||||
set(FLAVOUR x9lites)
|
||||
add_definitions(-DBOARD_NAME="x9lites")
|
||||
add_definitions(-DPCBX9LITES -DPCBX9LITE -DPCBX9 -DSOFTWARE_VOLUME -DHARDWARE_POWER_MANAGEMENT_UNIT)
|
||||
@@ -420,13 +338,10 @@ elseif(PCB STREQUAL XLITE)
|
||||
set(PXX_FREQUENCY "HIGH" CACHE STRING "PXX frequency (LOW / HIGH)") # always use HIGH except on some prototype boards
|
||||
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
set(HAPTIC YES)
|
||||
set(LUA_EXPORT lua_export_xlite)
|
||||
set(FLAVOUR xlite)
|
||||
add_definitions(-DPCBXLITE -DSOFTWARE_VOLUME -DSTICKS_PWM)
|
||||
add_definitions(-DPCBXLITE -DSOFTWARE_VOLUME)
|
||||
add_definitions(-DEEPROM_VARIANT=0x2000)
|
||||
add_definitions(-DPWR_BUTTON_${PWR_BUTTON})
|
||||
set(PXX2 ON)
|
||||
@@ -445,14 +360,10 @@ elseif(PCB STREQUAL XLITES)
|
||||
set(INTERNAL_MODULE_SERIAL YES)
|
||||
set(PXX_FREQUENCY "HIGH")
|
||||
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
set(CPU_TYPE_FULL STM32F205xE)
|
||||
set(HAPTIC YES)
|
||||
set(LUA_EXPORT lua_export_xlites)
|
||||
set(FLAVOUR xlites)
|
||||
add_definitions(-DPCBXLITES -DPCBXLITE -DSOFTWARE_VOLUME -DSTICKS_PWM -DHARDWARE_POWER_MANAGEMENT_UNIT)
|
||||
add_definitions(-DPCBXLITES -DPCBXLITE -DSOFTWARE_VOLUME -DHARDWARE_POWER_MANAGEMENT_UNIT)
|
||||
add_definitions(-DEEPROM_VARIANT=0x1000)
|
||||
add_definitions(-DPWR_BUTTON_${PWR_BUTTON})
|
||||
set(GUI_DIR 128x64)
|
||||
@@ -469,6 +380,24 @@ elseif(PCB STREQUAL XLITES)
|
||||
add_definitions(-DMANUFACTURER_FRSKY)
|
||||
endif()
|
||||
|
||||
if(CPU_TYPE_FULL STREQUAL STM32F205xE)
|
||||
set(CPU_TYPE STM32F2)
|
||||
add_definitions(-DSTM32F205xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
|
||||
elseif (CPU_TYPE_FULL STREQUAL STM32F407xE)
|
||||
set(CPU_TYPE STM32F4)
|
||||
add_definitions(-DSTM32F407xx)
|
||||
add_definitions(-DSTM32F40_41xxx -DSTM32F407xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f4_flash.ld)
|
||||
elseif (CPU_TYPE_FULL STREQUAL STM32F413xG)
|
||||
set(CPU_TYPE STM32F4)
|
||||
add_definitions(-DSTM32F413xx)
|
||||
add_definitions(-DSTM32F40_41xxx -DSTM32F413xx)
|
||||
set(LINKER_SCRIPT targets/taranis/stm32f413_flash.ld)
|
||||
else()
|
||||
message( FATAL_ERROR "Unknown CPU_TYPE_FULL" )
|
||||
endif()
|
||||
|
||||
if(NOT PCB STREQUAL PCBXLITE)
|
||||
add_definitions(-DHARDWARE_TRAINER_JACK)
|
||||
endif()
|
||||
@@ -497,17 +426,6 @@ else()
|
||||
# defines existing internal modules
|
||||
set(INTERNAL_MODULES PXX1)
|
||||
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
intmodule_pulses_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(HARDWARE_EXTERNAL_MODULE)
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
targets/common/arm/stm32/extmodule_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(ROTARY_ENCODER)
|
||||
@@ -609,13 +527,7 @@ set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
hal/adc_driver.cpp
|
||||
targets/common/arm/loadboot.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_hal_adc.cpp
|
||||
targets/common/arm/stm32/heartbeat_driver.cpp
|
||||
targets/common/arm/stm32/mixer_scheduler_driver.cpp
|
||||
targets/common/arm/stm32/timers_driver.cpp
|
||||
targets/common/arm/stm32/audio_dac_driver.cpp
|
||||
targets/common/arm/stm32/pwr_driver.cpp
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
bool setBindProtocolSelection()
|
||||
{
|
||||
int16_t xPos = calibratedAnalogs[CONVERT_MODE(0)];
|
||||
int16_t yPos = calibratedAnalogs[CONVERT_MODE(1)];
|
||||
int16_t xPos = calibratedAnalogs[ADC_MAIN_LH];
|
||||
int16_t yPos = calibratedAnalogs[ADC_MAIN_LV];
|
||||
|
||||
// Center: D8
|
||||
if (abs(xPos < 50 && abs(yPos) < 50)) {
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/switch_driver.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "boards/generic_stm32/module_ports.h"
|
||||
#include "boards/generic_stm32/intmodule_heartbeat.h"
|
||||
@@ -28,7 +31,6 @@
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/module_port.h"
|
||||
#include "stm32_hal_adc.h"
|
||||
|
||||
#include "../common/arm/stm32/timers_driver.h"
|
||||
|
||||
@@ -45,6 +47,10 @@
|
||||
#include "bluetooth_driver.h"
|
||||
#endif
|
||||
|
||||
#if defined(PWM_STICKS)
|
||||
#include "sticks_pwm_driver.h"
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -54,12 +60,19 @@ extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
#include "flysky_gimbal_driver.h"
|
||||
#if !defined(BOOT)
|
||||
bool UNEXPECTED_SHUTDOWN()
|
||||
{
|
||||
return WAS_RESET_BY_WATCHDOG()
|
||||
|| g_eeGeneral.unexpectedShutdown;
|
||||
}
|
||||
#endif
|
||||
|
||||
HardwareOptions hardwareOptions;
|
||||
|
||||
// adc_driver.cpp
|
||||
extern const etx_hal_adc_driver_t _adc_driver;
|
||||
|
||||
void watchdogInit(unsigned int duration)
|
||||
{
|
||||
IWDG->KR = 0x5555; // Unlock registers
|
||||
@@ -72,7 +85,7 @@ void watchdogInit(unsigned int duration)
|
||||
|
||||
#if !defined(BOOT)
|
||||
|
||||
#if defined(RADIO_TPRO)
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#include "storage/storage.h"
|
||||
#endif
|
||||
|
||||
@@ -85,9 +98,6 @@ void boardInit()
|
||||
AUDIO_RCC_AHB1Periph |
|
||||
BACKLIGHT_RCC_AHB1Periph |
|
||||
ADC_RCC_AHB1Periph |
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
FLYSKY_HALL_RCC_AHB1Periph |
|
||||
#endif
|
||||
SD_RCC_AHB1Periph |
|
||||
HAPTIC_RCC_AHB1Periph |
|
||||
INTMODULE_RCC_AHB1Periph |
|
||||
@@ -104,9 +114,6 @@ void boardInit()
|
||||
LCD_RCC_APB1Periph |
|
||||
AUDIO_RCC_APB1Periph |
|
||||
ADC_RCC_APB1Periph |
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
FLYSKY_HALL_RCC_APB1Periph |
|
||||
#endif
|
||||
BACKLIGHT_RCC_APB1Periph |
|
||||
HAPTIC_RCC_APB1Periph |
|
||||
INTERRUPT_xMS_RCC_APB1Periph |
|
||||
@@ -161,9 +168,7 @@ void boardInit()
|
||||
|
||||
#if defined(STATUS_LEDS)
|
||||
ledInit();
|
||||
#if defined(RADIO_T8) || defined(RADIO_COMMANDO8) || defined(RADIO_TLITE) || \
|
||||
defined(RADIO_TPRO) || defined(RADIO_TX12) || defined(RADIO_TX12MK2) || \
|
||||
defined(RADIO_ZORRO) || defined(RADIO_BOXER)
|
||||
#if defined(MANUFACTURER_RADIOMASTER) || defined(MANUFACTURER_JUMPER) || defined(RADIO_COMMANDO8)
|
||||
ledBlue();
|
||||
#else
|
||||
ledGreen();
|
||||
@@ -171,7 +176,7 @@ void boardInit()
|
||||
#endif
|
||||
|
||||
// Support for FS Led to indicate battery charge level
|
||||
#if defined(RADIO_TPRO)
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
// This is needed to prevent radio from starting when usb is plugged to charge
|
||||
usbInit();
|
||||
// prime debounce state...
|
||||
@@ -179,7 +184,7 @@ void boardInit()
|
||||
|
||||
if (usbPlugged()) {
|
||||
delaysInit();
|
||||
adcInit(&stm32_hal_adc_driver);
|
||||
adcInit(&_adc_driver);
|
||||
getADC();
|
||||
pwrOn(); // required to get bat adc reads
|
||||
storageReadRadioSettings(false); // Needed for bat calibration
|
||||
@@ -208,6 +213,7 @@ void boardInit()
|
||||
#endif
|
||||
|
||||
keysInit();
|
||||
switchInit();
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
rotaryEncoderInit();
|
||||
@@ -215,22 +221,13 @@ void boardInit()
|
||||
|
||||
delaysInit();
|
||||
|
||||
#if NUM_PWMSTICKS > 0
|
||||
sticksPwmInit();
|
||||
delay_ms(20);
|
||||
if (pwm_interrupt_count < 32) {
|
||||
hardwareOptions.sticksPwmDisabled = true;
|
||||
}
|
||||
#if defined(PWM_STICKS)
|
||||
sticksPwmDetect();
|
||||
#endif
|
||||
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
globalData.flyskygimbals = flysky_gimbal_init();
|
||||
#else
|
||||
globalData.flyskygimbals = false;
|
||||
#endif
|
||||
if (!adcInit(&_adc_driver))
|
||||
TRACE("adcInit failed");
|
||||
|
||||
if (!adcInit(&stm32_hal_adc_driver))
|
||||
TRACE("adcInit failed");
|
||||
lcdInit(); // delaysInit() must be called before
|
||||
audioInit();
|
||||
init2MhzTimer();
|
||||
|
||||
@@ -41,7 +41,11 @@ void rotaryEncoderInit();
|
||||
void rotaryEncoderCheck();
|
||||
#endif
|
||||
|
||||
#define FLASHSIZE 0x80000
|
||||
#if defined(STM32F413xx)
|
||||
#define FLASHSIZE 0x100000 // 1M
|
||||
#else
|
||||
#define FLASHSIZE 0x80000 // 512k
|
||||
#endif
|
||||
#define BOOTLOADER_SIZE 0x8000
|
||||
#define FIRMWARE_ADDRESS 0x08000000
|
||||
|
||||
@@ -133,491 +137,47 @@ uint32_t isBootloaderStart(const uint8_t * buffer);
|
||||
#define TRAINER_CONNECTED() true
|
||||
#endif
|
||||
|
||||
void check_telemetry_exti();
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
|
||||
// Keys driver
|
||||
enum EnumKeys
|
||||
{
|
||||
#if defined(KEYS_GPIO_REG_SHIFT)
|
||||
KEY_SHIFT,
|
||||
#endif
|
||||
#define NUM_FUNCTIONS_SWITCHES 6
|
||||
|
||||
#if defined(KEYS_GPIO_REG_MENU)
|
||||
KEY_MENU,
|
||||
#endif
|
||||
#define DEFAULT_FS_CONFIG \
|
||||
(SWITCH_2POS << 10) + (SWITCH_2POS << 8) + (SWITCH_2POS << 6) + \
|
||||
(SWITCH_2POS << 4) + (SWITCH_2POS << 2) + (SWITCH_2POS << 0)
|
||||
|
||||
KEY_EXIT,
|
||||
KEY_ENTER,
|
||||
#define DEFAULT_FS_GROUPS \
|
||||
(1 << 10) + (1 << 8) + (1 << 6) + (1 << 4) + (1 << 2) + \
|
||||
(1 << 0) // Set all FS to group 1 to act like a 6pos
|
||||
|
||||
#if defined(KEYS_GPIO_REG_DOWN)
|
||||
KEY_DOWN,
|
||||
KEY_UP,
|
||||
#endif
|
||||
#define DEFAULT_FS_STARTUP_CONFIG \
|
||||
((FS_START_PREVIOUS << 10) + (FS_START_PREVIOUS << 8) + \
|
||||
(FS_START_PREVIOUS << 6) + (FS_START_PREVIOUS << 4) + \
|
||||
(FS_START_PREVIOUS << 2) + \
|
||||
(FS_START_PREVIOUS << 0)) // keep last state by default
|
||||
|
||||
#if defined(KEYS_GPIO_REG_RIGHT)
|
||||
KEY_RIGHT,
|
||||
KEY_LEFT,
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_REG_PAGE)
|
||||
KEY_PAGE,
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_REG_PAGEUP)
|
||||
KEY_PAGEUP,
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_REG_PAGEDN)
|
||||
KEY_PAGEDN,
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_REG_SYS)
|
||||
KEY_SYS,
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_REG_MDL)
|
||||
KEY_MODEL,
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_REG_TELE)
|
||||
KEY_TELE,
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_REG_PLUS)
|
||||
KEY_PLUS,
|
||||
KEY_MINUS,
|
||||
#endif
|
||||
|
||||
KEY_COUNT,
|
||||
KEY_MAX = KEY_COUNT - 1,
|
||||
|
||||
#if defined(KEYS_GPIO_REG_BIND)
|
||||
KEY_BIND,
|
||||
#endif
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
KEY_PLUS,
|
||||
KEY_MINUS,
|
||||
#endif
|
||||
|
||||
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_LAST = TRM_RH_UP,
|
||||
|
||||
NUM_KEYS
|
||||
};
|
||||
|
||||
#if defined(PCBX9E) && !defined(SIMU)
|
||||
#define KEY_UP KEY_MINUS
|
||||
#define KEY_DOWN KEY_PLUS
|
||||
#define KEY_RIGHT KEY_PLUS
|
||||
#define KEY_LEFT KEY_MINUS
|
||||
#elif defined(NAVIGATION_XLITE)
|
||||
#define KEY_PLUS KEY_RIGHT
|
||||
#define KEY_MINUS KEY_LEFT
|
||||
#elif defined(NAVIGATION_9X)
|
||||
#define KEY_MENU KEY_ENTER
|
||||
#define KEY_MINUS KEY_DOWN
|
||||
#define KEY_PLUS KEY_UP
|
||||
#else
|
||||
#define KEY_UP KEY_PLUS
|
||||
#define KEY_DOWN KEY_MINUS
|
||||
#define KEY_RIGHT KEY_MINUS
|
||||
#define KEY_LEFT KEY_PLUS
|
||||
|
||||
#define NUM_FUNCTIONS_SWITCHES 0
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_SHIFT)
|
||||
#define IS_SHIFT_KEY(index) (index == KEY_SHIFT)
|
||||
#if defined(SIMU)
|
||||
#define IS_SHIFT_PRESSED() (readKeys() & (1 << KEY_SHIFT))
|
||||
#else
|
||||
#define IS_SHIFT_PRESSED() (~KEYS_GPIO_REG_SHIFT & KEYS_GPIO_PIN_SHIFT)
|
||||
#endif
|
||||
#else
|
||||
#define IS_SHIFT_KEY(index) (false)
|
||||
#define IS_SHIFT_PRESSED() (false)
|
||||
#endif
|
||||
|
||||
enum EnumSwitches
|
||||
{
|
||||
SW_SA,
|
||||
SW_SB,
|
||||
SW_SC,
|
||||
SW_SD,
|
||||
SW_SE,
|
||||
SW_SF,
|
||||
SW_SG,
|
||||
SW_SH,
|
||||
SW_SI,
|
||||
SW_SJ,
|
||||
SW_SK,
|
||||
SW_SL,
|
||||
SW_SM,
|
||||
SW_SO,
|
||||
SW_SP,
|
||||
SW_SQ,
|
||||
SW_SR,
|
||||
};
|
||||
#if defined(RADIO_TX12) || defined(RADIO_TX12MK2)
|
||||
#define IS_3POS(x) ((x) != SW_SA && (x) != SW_SD)
|
||||
#elif defined(RADIO_BOXER) || defined(RADIO_ZORRO)
|
||||
#define IS_3POS(x) ((x) == SW_SB || (x) == SW_SC)
|
||||
#else
|
||||
#define IS_3POS(x) ((x) != SW_SF && (x) != SW_SH)
|
||||
#endif
|
||||
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,
|
||||
#if defined(HARDWARE_SWITCH_E)
|
||||
SW_SE0,
|
||||
SW_SE1,
|
||||
SW_SE2,
|
||||
#endif
|
||||
#if defined(HARDWARE_SWITCH_F)
|
||||
SW_SF0,
|
||||
SW_SF1,
|
||||
SW_SF2,
|
||||
#endif
|
||||
#if defined(HARDWARE_SWITCH_G)
|
||||
SW_SG0,
|
||||
SW_SG1,
|
||||
SW_SG2,
|
||||
#endif
|
||||
#if defined(HARDWARE_SWITCH_H)
|
||||
SW_SH0,
|
||||
SW_SH1,
|
||||
SW_SH2,
|
||||
#endif
|
||||
#if defined(RADIO_X9DP2019)
|
||||
SW_SI0,
|
||||
SW_SI1,
|
||||
SW_SI2,
|
||||
#endif
|
||||
#if defined(PCBX7ACCESS)
|
||||
SW_SI0,
|
||||
SW_SI1,
|
||||
SW_SI2,
|
||||
#elif defined(PCBX7) && !defined(RADIO_ZORRO)
|
||||
SW_SI0,
|
||||
SW_SI1,
|
||||
SW_SI2,
|
||||
SW_SJ0,
|
||||
SW_SJ1,
|
||||
SW_SJ2,
|
||||
#endif
|
||||
#if defined(PCBX9E)
|
||||
SW_SI0,
|
||||
SW_SI1,
|
||||
SW_SI2,
|
||||
SW_SJ0,
|
||||
SW_SJ1,
|
||||
SW_SJ2,
|
||||
SW_SK0,
|
||||
SW_SK1,
|
||||
SW_SK2,
|
||||
SW_SL0,
|
||||
SW_SL1,
|
||||
SW_SL2,
|
||||
SW_SM0,
|
||||
SW_SM1,
|
||||
SW_SM2,
|
||||
SW_SN0,
|
||||
SW_SN1,
|
||||
SW_SN2,
|
||||
SW_SO0,
|
||||
SW_SO1,
|
||||
SW_SO2,
|
||||
SW_SP0,
|
||||
SW_SP1,
|
||||
SW_SP2,
|
||||
SW_SQ0,
|
||||
SW_SQ1,
|
||||
SW_SQ2,
|
||||
SW_SR0,
|
||||
SW_SR1,
|
||||
SW_SR2,
|
||||
#endif
|
||||
NUM_SWITCHES_POSITIONS
|
||||
};
|
||||
|
||||
#if defined(PCBXLITES)
|
||||
#define NUM_SWITCHES 6
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 10) + (SWITCH_TOGGLE << 8) + (SWITCH_2POS << 6) + (SWITCH_2POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 2) + (POT_WITHOUT_DETENT << 0)
|
||||
#elif defined(PCBXLITE)
|
||||
#define NUM_SWITCHES 4
|
||||
#define STORAGE_NUM_SWITCHES 6
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_2POS << 6) + (SWITCH_2POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 2) + (POT_WITHOUT_DETENT << 0)
|
||||
#elif defined(RADIO_TLITE) || defined(RADIO_LR3PRO)
|
||||
#define NUM_SWITCHES 4
|
||||
#define STORAGE_NUM_SWITCHES 8
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_2POS << 6) + (SWITCH_2POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
|
||||
#define DEFAULT_POTS_CONFIG (0)
|
||||
#elif defined(RADIO_TPRO)
|
||||
#define NUM_SWITCHES 10
|
||||
#define NUM_FUNCTIONS_SWITCHES 6
|
||||
#define NUM_REGULAR_SWITCHES (NUM_SWITCHES - NUM_FUNCTIONS_SWITCHES)
|
||||
#define STORAGE_NUM_SWITCHES 10
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 6) + (SWITCH_TOGGLE << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
|
||||
#define DEFAULT_FS_CONFIG (SWITCH_2POS << 10) + (SWITCH_2POS << 8) + (SWITCH_2POS << 6) + (SWITCH_2POS << 4) + (SWITCH_2POS << 2) + (SWITCH_2POS << 0)
|
||||
#define DEFAULT_FS_GROUPS (1 << 10) + (1 << 8) + (1 << 6) + (1 << 4) + (1 << 2) + (1 << 0) // Set all FS to group 1 to act like a 6pos
|
||||
#define DEFAULT_FS_STARTUP_CONFIG ((FS_START_PREVIOUS << 10) + (FS_START_PREVIOUS << 8) + (FS_START_PREVIOUS << 6) + (FS_START_PREVIOUS << 4) + (FS_START_PREVIOUS << 2) + (FS_START_PREVIOUS << 0)) // keep last state by default
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
|
||||
#elif defined(RADIO_FAMILY_JUMPER_T12)
|
||||
#define NUM_SWITCHES 8
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_2POS << 10) + (SWITCH_2POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITHOUT_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
|
||||
#elif defined(RADIO_TX12)
|
||||
#define NUM_SWITCHES 8
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_3POS << 10) + (SWITCH_3POS << 8) + (SWITCH_TOGGLE << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_TOGGLE << 0)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2);
|
||||
#elif defined(RADIO_TX12MK2)
|
||||
#define NUM_SWITCHES 6
|
||||
#define STORAGE_NUM_SWITCHES 8
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_3POS << 10) + (SWITCH_3POS << 8) + (SWITCH_TOGGLE << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_TOGGLE << 0)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2);
|
||||
#elif defined(RADIO_BOXER)
|
||||
#define NUM_SWITCHES 6
|
||||
#define STORAGE_NUM_SWITCHES 8
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 10) + (SWITCH_2POS << 8) + (SWITCH_2POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_2POS << 0)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2) + (POT_MULTIPOS_SWITCH << 4);
|
||||
#elif defined(RADIO_ZORRO)
|
||||
#define NUM_SWITCHES 8
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 14) + (SWITCH_TOGGLE << 12) + (SWITCH_2POS << 10) + (SWITCH_2POS << 8) + (SWITCH_TOGGLE << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_TOGGLE << 0)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITHOUT_DETENT << 2);
|
||||
#elif defined(RADIO_T8) || defined(RADIO_COMMANDO8)
|
||||
#define NUM_SWITCHES 4
|
||||
#define STORAGE_NUM_SWITCHES 8
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_2POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_2POS << 0);
|
||||
#define DEFAULT_POTS_CONFIG (0)
|
||||
#elif defined(PCBX7ACCESS)
|
||||
#define NUM_SWITCHES 7
|
||||
#define STORAGE_NUM_SWITCHES 8
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 10) + (SWITCH_2POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
|
||||
#elif defined(PCBX7)
|
||||
#define NUM_SWITCHES 8
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 10) + (SWITCH_2POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
|
||||
#elif defined(PCBX9LITES)
|
||||
#define NUM_SWITCHES 7
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 12) + (SWITCH_TOGGLE << 10) + (SWITCH_TOGGLE << 8) + (SWITCH_2POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0); // S1 = pot with detent
|
||||
#elif defined(PCBX9LITE)
|
||||
#define NUM_SWITCHES 5
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 8) + (SWITCH_2POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0); // S1 = pot with detent
|
||||
#elif defined(PCBX9E)
|
||||
#define NUM_SWITCHES 18 // yes, it's perfect like that !
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#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)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
|
||||
#define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 3) + (SLIDER_WITH_DETENT << 2) + (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
|
||||
#elif defined(RADIO_X9DP2019)
|
||||
#define NUM_SWITCHES 9
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 16) + (SWITCH_TOGGLE << 14) + (SWITCH_3POS << 12) + (SWITCH_2POS << 10) + (SWITCH_3POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
|
||||
#define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
|
||||
#elif defined(PCBX9D) || defined(PCBX9DP)
|
||||
#define NUM_SWITCHES 8
|
||||
#define STORAGE_NUM_SWITCHES 9
|
||||
#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)
|
||||
#define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
|
||||
#define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
|
||||
#endif
|
||||
|
||||
#if !defined(NUM_FUNCTIONS_SWITCHES)
|
||||
#define NUM_FUNCTIONS_SWITCHES 0
|
||||
#endif
|
||||
|
||||
#define STORAGE_NUM_SWITCHES_POSITIONS (STORAGE_NUM_SWITCHES * 3)
|
||||
|
||||
void keysInit();
|
||||
uint32_t switchState(uint8_t index);
|
||||
uint32_t readKeys();
|
||||
uint32_t readTrims();
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
extern uint8_t fsPreviousState;
|
||||
void evalFunctionSwitches();
|
||||
void setFSStartupPosition();
|
||||
void fsLedOff(uint8_t);
|
||||
void fsLedOn(uint8_t);
|
||||
uint8_t getFSLogicalState(uint8_t index);
|
||||
uint8_t getFSPhysicalState(uint8_t index);
|
||||
#endif
|
||||
|
||||
#define TRIMS_PRESSED() (readTrims())
|
||||
#define KEYS_PRESSED() (readKeys())
|
||||
|
||||
// ADC driver
|
||||
enum Analogs {
|
||||
STICK1,
|
||||
STICK2,
|
||||
STICK3,
|
||||
STICK4,
|
||||
POT_FIRST,
|
||||
POT1 = POT_FIRST,
|
||||
#if defined(PCBX9LITE)
|
||||
POT_LAST = POT1,
|
||||
#elif defined(RADIO_BOXER)
|
||||
POT2,
|
||||
POT3,
|
||||
POT_LAST = POT3,
|
||||
#elif defined(PCBXLITE) || defined(PCBX7)
|
||||
POT2,
|
||||
POT_LAST = POT2,
|
||||
#elif defined(PCBX9E)
|
||||
POT2,
|
||||
POT3,
|
||||
POT4,
|
||||
POT_LAST = POT4,
|
||||
SLIDER1,
|
||||
SLIDER2,
|
||||
SLIDER3,
|
||||
SLIDER4,
|
||||
#else
|
||||
POT2,
|
||||
POT3,
|
||||
POT_LAST = POT3,
|
||||
SLIDER1,
|
||||
SLIDER2,
|
||||
#endif
|
||||
TX_VOLTAGE,
|
||||
TX_RTC_VOLTAGE,
|
||||
NUM_ANALOGS
|
||||
};
|
||||
|
||||
#define HAS_TX_RTC_VOLTAGE
|
||||
|
||||
#if defined(PCBX9LITE)
|
||||
#define NUM_POTS 1
|
||||
#define NUM_SLIDERS 0
|
||||
#define STORAGE_NUM_POTS 1
|
||||
#define STORAGE_NUM_SLIDERS 0
|
||||
#elif defined(RADIO_T8) || defined(RADIO_TLITE) || defined(RADIO_COMMANDO8) || defined(RADIO_LR3PRO)
|
||||
#define NUM_POTS 0
|
||||
#define NUM_SLIDERS 0
|
||||
#define STORAGE_NUM_POTS 2
|
||||
#define STORAGE_NUM_SLIDERS 0
|
||||
#elif defined(RADIO_BOXER)
|
||||
#define NUM_POTS 3 // S1 + S2 + 6POS
|
||||
#define NUM_SLIDERS 0
|
||||
#define STORAGE_NUM_POTS 3
|
||||
#define STORAGE_NUM_SLIDERS 0
|
||||
#elif defined(PCBXLITE) || defined(PCBX7)
|
||||
#define NUM_POTS 2
|
||||
#define NUM_SLIDERS 0
|
||||
#define STORAGE_NUM_POTS 2
|
||||
#define STORAGE_NUM_SLIDERS 0
|
||||
#elif defined(PCBX9E)
|
||||
#define NUM_POTS 4
|
||||
#define NUM_SLIDERS 4
|
||||
#define STORAGE_NUM_POTS 4
|
||||
#define STORAGE_NUM_SLIDERS 4
|
||||
#elif defined(PCBX9DP)
|
||||
#define NUM_POTS 3
|
||||
#define NUM_SLIDERS 2
|
||||
#define STORAGE_NUM_POTS 3
|
||||
#define STORAGE_NUM_SLIDERS 2
|
||||
#else
|
||||
#define NUM_POTS 3 // TODO X9D has only 2 pots
|
||||
#define NUM_SLIDERS 2
|
||||
#define STORAGE_NUM_POTS 3
|
||||
#define STORAGE_NUM_SLIDERS 2
|
||||
#endif
|
||||
|
||||
#define NUM_XPOTS STORAGE_NUM_POTS
|
||||
#define NUM_TRIMS 4
|
||||
#define NUM_MOUSE_ANALOGS 0
|
||||
#define STORAGE_NUM_MOUSE_ANALOGS 0
|
||||
|
||||
#if defined(PCBXLITE)
|
||||
#define NUM_TRIMS_KEYS 4
|
||||
#else
|
||||
#define NUM_TRIMS_KEYS (NUM_TRIMS * 2)
|
||||
#endif
|
||||
|
||||
#if defined(STICKS_PWM)
|
||||
#define NUM_PWMSTICKS 4
|
||||
#define STICKS_PWM_ENABLED() (!hardwareOptions.sticksPwmDisabled)
|
||||
void sticksPwmInit();
|
||||
void sticksPwmRead(uint16_t * values);
|
||||
extern volatile uint32_t pwm_interrupt_count; // TODO => reusable buffer (boot section)
|
||||
#else
|
||||
#define STICKS_PWM_ENABLED() false
|
||||
bool getFSLedState(uint8_t index);
|
||||
#endif
|
||||
|
||||
PACK(typedef struct {
|
||||
uint8_t pcbrev:2;
|
||||
uint8_t sticksPwmDisabled:1;
|
||||
uint8_t pxx2Enabled:1;
|
||||
}) HardwareOptions;
|
||||
|
||||
extern HardwareOptions hardwareOptions;
|
||||
|
||||
#if !defined(PXX2)
|
||||
#define IS_PXX2_INTERNAL_ENABLED() (false)
|
||||
#define IS_PXX1_INTERNAL_ENABLED() (true)
|
||||
#elif !defined(PXX1) || defined(PCBXLITES) || defined(PCBX9LITE)
|
||||
#define IS_PXX2_INTERNAL_ENABLED() (true)
|
||||
#define IS_PXX1_INTERNAL_ENABLED() (false)
|
||||
#elif defined(INTERNAL_MODULE_PXX1)
|
||||
#define IS_PXX2_INTERNAL_ENABLED() (false)
|
||||
#define IS_PXX1_INTERNAL_ENABLED() (true)
|
||||
#else
|
||||
// TODO #define PXX2_PROBE
|
||||
// TODO #define IS_PXX2_INTERNAL_ENABLED() (hardwareOptions.pxx2Enabled)
|
||||
#define IS_PXX2_INTERNAL_ENABLED() (true)
|
||||
#define IS_PXX1_INTERNAL_ENABLED() (true)
|
||||
#endif
|
||||
|
||||
enum CalibratedAnalogs {
|
||||
CALIBRATED_STICK1,
|
||||
CALIBRATED_STICK2,
|
||||
CALIBRATED_STICK3,
|
||||
CALIBRATED_STICK4,
|
||||
CALIBRATED_POT_FIRST,
|
||||
CALIBRATED_POT_LAST = CALIBRATED_POT_FIRST + NUM_POTS - 1,
|
||||
CALIBRATED_SLIDER_FIRST,
|
||||
CALIBRATED_SLIDER_LAST = CALIBRATED_SLIDER_FIRST + NUM_SLIDERS - 1,
|
||||
NUM_CALIBRATED_ANALOGS
|
||||
};
|
||||
|
||||
#if defined(PCBX9D)
|
||||
#define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT2) // POT3 is only defined in software
|
||||
#else
|
||||
#define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT_LAST)
|
||||
#endif
|
||||
|
||||
#define IS_SLIDER(x) ((x)>POT_LAST && (x)<TX_VOLTAGE)
|
||||
|
||||
extern uint16_t adcValues[NUM_ANALOGS];
|
||||
|
||||
// Battery driver
|
||||
#if defined(PCBX9E)
|
||||
// NI-MH 9.6V
|
||||
@@ -668,6 +228,7 @@ uint32_t pwrCheck();
|
||||
void pwrOn();
|
||||
void pwrOff();
|
||||
bool pwrPressed();
|
||||
bool pwrOffPressed();
|
||||
#if defined(PWR_BUTTON_PRESS)
|
||||
#define STARTUP_ANIMATION
|
||||
uint32_t pwrPressedDuration();
|
||||
@@ -675,11 +236,7 @@ uint32_t pwrPressedDuration();
|
||||
void pwrResetHandler();
|
||||
#define pwrForcePressed() false
|
||||
|
||||
#if defined(SIMU)
|
||||
#define UNEXPECTED_SHUTDOWN() false
|
||||
#else
|
||||
#define UNEXPECTED_SHUTDOWN() (WAS_RESET_BY_WATCHDOG() || g_eeGeneral.unexpectedShutdown)
|
||||
#endif
|
||||
bool UNEXPECTED_SHUTDOWN();
|
||||
|
||||
// Backlight driver
|
||||
#define BACKLIGHT_DISABLE() backlightDisable()
|
||||
@@ -747,19 +304,6 @@ uint8_t isBacklightEnabled();
|
||||
// Debug driver
|
||||
void debugPutc(const char c);
|
||||
|
||||
// Telemetry driver
|
||||
// void telemetryPortInit(uint32_t baudrate, uint8_t mode);
|
||||
// void telemetryPortSetDirectionInput();
|
||||
// void telemetryPortSetDirectionOutput();
|
||||
// void sportSendByte(uint8_t byte);
|
||||
// void sportSendByteLoop(uint8_t byte);
|
||||
// void sportStopSendByteLoop();
|
||||
// void sportSendBuffer(const uint8_t * buffer, uint32_t count);
|
||||
// bool sportGetByte(uint8_t * byte);
|
||||
// void telemetryClearFifo();
|
||||
// extern uint32_t telemetryErrors;
|
||||
|
||||
|
||||
// Audio driver
|
||||
void audioInit() ;
|
||||
void audioEnd() ;
|
||||
@@ -825,10 +369,6 @@ void ledOff();
|
||||
void ledRed();
|
||||
void ledGreen();
|
||||
void ledBlue();
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
void fsLedOff(uint8_t);
|
||||
void fsLedOn(uint8_t);
|
||||
#endif
|
||||
|
||||
// LCD driver
|
||||
#if defined(PCBX9D) || defined(PCBX9DP) || defined(PCBX9E)
|
||||
@@ -898,8 +438,6 @@ void setTopBatteryState(int state, uint8_t blinking);
|
||||
void setTopBatteryValue(uint32_t volts);
|
||||
#endif
|
||||
|
||||
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||
|
||||
#if defined(CROSSFIRE)
|
||||
#define TELEMETRY_FIFO_SIZE 128
|
||||
#else
|
||||
|
||||
@@ -22,27 +22,14 @@
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_i2c_driver.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
#include "hal/eeprom_driver.h"
|
||||
|
||||
static int enable_wp_clock(GPIO_TypeDef *GPIOx)
|
||||
{
|
||||
if (GPIOx == GPIOB)
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
else if (GPIOx == GPIOD)
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
else if (GPIOx == GPIOF)
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
else
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void init_wp_pin()
|
||||
{
|
||||
enable_wp_clock(EEPROM_WP_GPIO);
|
||||
stm32_gpio_enable_clock(EEPROM_WP_GPIO);
|
||||
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
+760
-710
File diff suppressed because it is too large
Load Diff
@@ -1,73 +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 "intmodule_pulses_driver.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "board.h"
|
||||
#include "timers_driver.h"
|
||||
|
||||
#if defined(INTMODULE_TIMER)
|
||||
|
||||
static stm32_pulse_dma_tc_cb_t _int_timer_DMA_TC_Callback;
|
||||
|
||||
const stm32_pulse_timer_t intmoduleTimer = {
|
||||
.GPIOx = INTMODULE_TX_GPIO,
|
||||
.GPIO_Pin = INTMODULE_TX_GPIO_PIN,
|
||||
.GPIO_Alternate = INTMODULE_TX_GPIO_AF,
|
||||
.TIMx = INTMODULE_TIMER,
|
||||
.TIM_Freq = INTMODULE_TIMER_FREQ,
|
||||
.TIM_Channel = INTMODULE_TIMER_Channel,
|
||||
.TIM_IRQn = INTMODULE_TIMER_IRQn,
|
||||
.DMAx = INTMODULE_TIMER_DMA,
|
||||
.DMA_Stream = INTMODULE_TIMER_DMA_STREAM,
|
||||
.DMA_Channel = INTMODULE_TIMER_DMA_CHANNEL,
|
||||
.DMA_IRQn = INTMODULE_TIMER_DMA_STREAM_IRQn,
|
||||
.DMA_TC_CallbackPtr = &_int_timer_DMA_TC_Callback,
|
||||
};
|
||||
|
||||
// Make sure the timer channel is supported
|
||||
static_assert(__STM32_PULSE_IS_TIMER_CHANNEL_SUPPORTED(INTMODULE_TIMER_Channel),
|
||||
"Unsupported timer channel");
|
||||
|
||||
// Make sure the DMA channel is supported
|
||||
static_assert(__STM32_PULSE_IS_DMA_STREAM_SUPPORTED(INTMODULE_TIMER_DMA_STREAM),
|
||||
"Unsupported DMA stream");
|
||||
|
||||
#if !defined(INTMODULE_TIMER_DMA_IRQHandler)
|
||||
#error "Missing INTMODULE_TIMER_DMA_IRQHandler definition"
|
||||
#endif
|
||||
|
||||
extern "C" void INTMODULE_TIMER_DMA_IRQHandler()
|
||||
{
|
||||
stm32_pulse_dma_tc_isr(&intmoduleTimer);
|
||||
}
|
||||
|
||||
#if !defined(INTMODULE_TIMER_IRQHandler)
|
||||
#error "Missing INTMODULE_TIMER_IRQHandler definition"
|
||||
#endif
|
||||
|
||||
extern "C" void INTMODULE_TIMER_IRQHandler()
|
||||
{
|
||||
stm32_pulse_tim_update_isr(&intmoduleTimer);
|
||||
}
|
||||
|
||||
#endif // INTMODULE_TIMER
|
||||
@@ -1,333 +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 "board.h"
|
||||
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
if (~KEYS_GPIO_REG_ENTER & KEYS_GPIO_PIN_ENTER)
|
||||
result |= 1 << KEY_ENTER;
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_MENU)
|
||||
if (~KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU)
|
||||
result |= 1 << KEY_MENU;
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_PAGE)
|
||||
if (~KEYS_GPIO_REG_PAGE & KEYS_GPIO_PIN_PAGE)
|
||||
result |= 1 << KEY_PAGE;
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_PAGEUP)
|
||||
if (~KEYS_GPIO_REG_PAGEUP & KEYS_GPIO_PIN_PAGEUP)
|
||||
result |= 1 << KEY_PAGEUP;
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_PAGEDN)
|
||||
if (~KEYS_GPIO_REG_PAGEDN & KEYS_GPIO_PIN_PAGEDN)
|
||||
result |= 1 << KEY_PAGEDN;
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_SYS)
|
||||
if (~KEYS_GPIO_REG_SYS & KEYS_GPIO_PIN_SYS)
|
||||
result |= 1 << KEY_SYS;
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_MDL)
|
||||
if (~KEYS_GPIO_REG_MDL & KEYS_GPIO_PIN_MDL)
|
||||
result |= 1 << KEY_MODEL;
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_TELE)
|
||||
if (~KEYS_GPIO_REG_TELE & KEYS_GPIO_PIN_TELE)
|
||||
result |= 1 << KEY_TELE;
|
||||
#endif
|
||||
|
||||
if (~KEYS_GPIO_REG_EXIT & KEYS_GPIO_PIN_EXIT)
|
||||
result |= 1 << KEY_EXIT;
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_PLUS)
|
||||
if (~KEYS_GPIO_REG_PLUS & KEYS_GPIO_PIN_PLUS)
|
||||
result |= 1 << KEY_PLUS;
|
||||
if (~KEYS_GPIO_REG_MINUS & KEYS_GPIO_PIN_MINUS)
|
||||
result |= 1 << KEY_MINUS;
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_LEFT)
|
||||
if (~KEYS_GPIO_REG_LEFT & KEYS_GPIO_PIN_LEFT)
|
||||
result |= 1 << KEY_LEFT;
|
||||
if (~KEYS_GPIO_REG_RIGHT & KEYS_GPIO_PIN_RIGHT)
|
||||
result |= 1 << KEY_RIGHT;
|
||||
if (~KEYS_GPIO_REG_UP & KEYS_GPIO_PIN_UP)
|
||||
result |= 1 << KEY_UP;
|
||||
if (~KEYS_GPIO_REG_DOWN & KEYS_GPIO_PIN_DOWN)
|
||||
result |= 1 << KEY_DOWN;
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_SHIFT)
|
||||
if (~KEYS_GPIO_REG_SHIFT & KEYS_GPIO_PIN_SHIFT)
|
||||
result |= 1 << KEY_SHIFT;
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIO_PIN_BIND)
|
||||
if (~KEYS_GPIO_REG_BIND & KEYS_GPIO_PIN_BIND)
|
||||
result |= 1 << KEY_BIND;
|
||||
#endif
|
||||
// if (result != 0) TRACE("readKeys(): result=0x%02x", 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 defined(PCBXLITE)
|
||||
if (IS_SHIFT_PRESSED())
|
||||
result = ((result & 0x03) << 6) | ((result & 0x0c) << 2);
|
||||
#else
|
||||
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;
|
||||
#endif
|
||||
|
||||
// TRACE("readTrims(): result=0x%02x", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool trimDown(uint8_t idx)
|
||||
{
|
||||
return readTrims() & (1 << idx);
|
||||
}
|
||||
|
||||
bool keyDown()
|
||||
{
|
||||
return readKeys() || readTrims();
|
||||
}
|
||||
|
||||
#if defined(PCBX9E)
|
||||
#define ADD_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
|
||||
#else
|
||||
#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
|
||||
#endif
|
||||
|
||||
#define ADD_3POS_CASE(x, i) \
|
||||
case SW_S ## x ## 0: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
|
||||
if (IS_CONFIG_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_CONFIG_3POS(i)) { \
|
||||
xxx = xxx && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
} \
|
||||
break
|
||||
|
||||
#if !defined(BOOT)
|
||||
#include "opentx.h"
|
||||
|
||||
uint32_t switchState(uint8_t index)
|
||||
{
|
||||
uint32_t xxx = 0;
|
||||
|
||||
switch (index) {
|
||||
|
||||
#if defined(RADIO_TX12) || defined(RADIO_TX12MK2) || defined(RADIO_BOXER) || defined(RADIO_ZORRO) || defined(RADIO_T8) || defined(RADIO_COMMANDO8)
|
||||
ADD_2POS_CASE(A);
|
||||
ADD_3POS_CASE(B, 1);
|
||||
ADD_3POS_CASE(C, 2);
|
||||
#elif defined(RADIO_TLITE) || defined(RADIO_TPRO) || defined(RADIO_LR3PRO)
|
||||
ADD_3POS_CASE(A, 0);
|
||||
ADD_3POS_CASE(B, 1);
|
||||
ADD_2POS_CASE(C);
|
||||
ADD_2POS_CASE(D);
|
||||
#else
|
||||
ADD_3POS_CASE(A, 0);
|
||||
ADD_3POS_CASE(B, 1);
|
||||
ADD_3POS_CASE(C, 2);
|
||||
#endif
|
||||
#if defined(PCBX9LITES)
|
||||
ADD_2POS_CASE(D);
|
||||
ADD_2POS_CASE(E);
|
||||
ADD_2POS_CASE(F);
|
||||
ADD_2POS_CASE(G);
|
||||
#elif defined(PCBX9LITE)
|
||||
ADD_2POS_CASE(D);
|
||||
ADD_2POS_CASE(E);
|
||||
#elif defined(PCBXLITES)
|
||||
ADD_3POS_CASE(D, 3);
|
||||
ADD_2POS_CASE(E);
|
||||
ADD_2POS_CASE(F);
|
||||
// no SWG and SWH on XLITES
|
||||
#elif defined(PCBXLITE)
|
||||
ADD_3POS_CASE(D, 3);
|
||||
// no SWE, SWF, SWG and SWH on XLITE
|
||||
#elif defined(PCBX7ACCESS)
|
||||
ADD_3POS_CASE(D, 3);
|
||||
ADD_2POS_CASE(F);
|
||||
ADD_2POS_CASE(H);
|
||||
ADD_2POS_CASE(I);
|
||||
// no SWJ on XLITE
|
||||
#elif defined(RADIO_ZORRO)
|
||||
ADD_2POS_CASE(D);
|
||||
ADD_2POS_CASE(E);
|
||||
ADD_2POS_CASE(F);
|
||||
ADD_2POS_CASE(G);
|
||||
ADD_2POS_CASE(H);
|
||||
#elif defined(RADIO_TX12MK2)
|
||||
ADD_2POS_CASE(D);
|
||||
ADD_3POS_CASE(E, 4);
|
||||
ADD_3POS_CASE(F, 5);
|
||||
#elif defined(RADIO_BOXER)
|
||||
ADD_2POS_CASE(D);
|
||||
ADD_2POS_CASE(E);
|
||||
ADD_2POS_CASE(F);
|
||||
#elif defined(RADIO_TX12) || defined(RADIO_ZORRO)
|
||||
ADD_2POS_CASE(D);
|
||||
ADD_3POS_CASE(E, 4);
|
||||
ADD_3POS_CASE(F, 5);
|
||||
ADD_2POS_CASE(I);
|
||||
ADD_2POS_CASE(J);
|
||||
#elif defined(RADIO_T8) || defined(RADIO_COMMANDO8)
|
||||
ADD_2POS_CASE(D);
|
||||
#elif defined(RADIO_TLITE) || defined(RADIO_LR3PRO)
|
||||
// Only 4 switches
|
||||
#elif defined(RADIO_TPRO)
|
||||
ADD_2POS_CASE(E);
|
||||
ADD_2POS_CASE(F);
|
||||
ADD_2POS_CASE(G);
|
||||
ADD_2POS_CASE(H);
|
||||
ADD_2POS_CASE(I);
|
||||
ADD_2POS_CASE(J);
|
||||
#elif defined(PCBX7)
|
||||
ADD_3POS_CASE(D, 3);
|
||||
#if defined(RADIO_T12)
|
||||
ADD_2POS_CASE(G);
|
||||
#else
|
||||
ADD_2POS_CASE(F);
|
||||
#endif
|
||||
ADD_2POS_CASE(H);
|
||||
ADD_2POS_CASE(I);
|
||||
ADD_2POS_CASE(J);
|
||||
#else
|
||||
ADD_3POS_CASE(D, 3);
|
||||
ADD_3POS_CASE(E, 4);
|
||||
ADD_2POS_CASE(F);
|
||||
ADD_3POS_CASE(G, 6);
|
||||
ADD_2POS_CASE(H);
|
||||
#endif
|
||||
|
||||
#if defined(RADIO_X9DP2019)
|
||||
ADD_2POS_CASE(I);
|
||||
#endif
|
||||
|
||||
#if defined(PCBX9E)
|
||||
ADD_3POS_CASE(I, 8);
|
||||
ADD_3POS_CASE(J, 9);
|
||||
ADD_3POS_CASE(K, 10);
|
||||
ADD_3POS_CASE(L, 11);
|
||||
ADD_3POS_CASE(M, 12);
|
||||
ADD_3POS_CASE(N, 13);
|
||||
ADD_3POS_CASE(O, 14);
|
||||
ADD_3POS_CASE(P, 15);
|
||||
ADD_3POS_CASE(Q, 16);
|
||||
ADD_3POS_CASE(R, 17);
|
||||
#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_GPIOF_PINS)
|
||||
INIT_KEYS_PINS(GPIOF);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOG_PINS)
|
||||
INIT_KEYS_PINS(GPIOG);
|
||||
#endif
|
||||
}
|
||||
@@ -56,7 +56,9 @@ void ledInit()
|
||||
}
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
constexpr uint32_t fsLeds[] = {FSLED_GPIO_PIN_1, FSLED_GPIO_PIN_2, FSLED_GPIO_PIN_3, FSLED_GPIO_PIN_4, FSLED_GPIO_PIN_5, FSLED_GPIO_PIN_6};
|
||||
constexpr uint32_t fsLeds[] = {FSLED_GPIO_PIN_1, FSLED_GPIO_PIN_2,
|
||||
FSLED_GPIO_PIN_3, FSLED_GPIO_PIN_4,
|
||||
FSLED_GPIO_PIN_5, FSLED_GPIO_PIN_6};
|
||||
|
||||
void fsLedOff(uint8_t index)
|
||||
{
|
||||
@@ -67,6 +69,11 @@ void fsLedOn(uint8_t index)
|
||||
{
|
||||
GPIO_FSLED_GPIO_ON(FSLED_GPIO, fsLeds[index]);
|
||||
}
|
||||
|
||||
bool getFSLedState(uint8_t index)
|
||||
{
|
||||
return (FSLED_GPIO->ODR & fsLeds[index]);
|
||||
}
|
||||
#endif
|
||||
|
||||
void ledOff()
|
||||
|
||||
@@ -0,0 +1,575 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file startup_stm32f413xx.s
|
||||
* @author MCD Application Team
|
||||
* @brief STM32F413xx Devices vector table for GCC based toolchains.
|
||||
* This module performs:
|
||||
* - Set the initial SP
|
||||
* - Set the initial PC == Reset_Handler,
|
||||
* - Set the vector table entries with the exceptions ISR address
|
||||
* - Branches to main in the C library (which eventually
|
||||
* calls main()).
|
||||
* After Reset the Cortex-M4 processor is in Thread mode,
|
||||
* priority is Privileged, and the Stack is set to Main.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.fpu softvfp
|
||||
.thumb
|
||||
|
||||
.global g_pfnVectors
|
||||
.global Default_Handler
|
||||
|
||||
/* start address for the initialization values of the .data section.
|
||||
defined in linker script */
|
||||
.word _sidata
|
||||
/* start address for the .data section. defined in linker script */
|
||||
.word _sdata
|
||||
/* end address for the .data section. defined in linker script */
|
||||
.word _edata
|
||||
/* start address for the .bss section. defined in linker script */
|
||||
.word _sbss
|
||||
/* end address for the .bss section. defined in linker script */
|
||||
.word _ebss
|
||||
/* stack used for SystemInit_ExtMemCtl; always internal RAM used */
|
||||
|
||||
/**
|
||||
* @brief This is the code that gets called when the processor first
|
||||
* starts execution following a reset event. Only the absolutely
|
||||
* necessary set is performed, after which the application
|
||||
* supplied main() routine is called.
|
||||
* @param None
|
||||
* @retval : None
|
||||
*/
|
||||
|
||||
.section .text.Reset_Handler
|
||||
.weak Reset_Handler
|
||||
.type Reset_Handler, %function
|
||||
Reset_Handler:
|
||||
bl pwrResetHandler /*jump to WDT reset handler where soft power control pin is turned on as soon as possible */
|
||||
|
||||
/* Copy the data segment initializers from flash to SRAM */
|
||||
ldr r0, =_sdata
|
||||
ldr r1, =_edata
|
||||
ldr r2, =_sidata
|
||||
movs r3, #0
|
||||
b LoopCopyDataInit
|
||||
|
||||
CopyDataInit:
|
||||
ldr r4, [r2, r3]
|
||||
str r4, [r0, r3]
|
||||
adds r3, r3, #4
|
||||
|
||||
LoopCopyDataInit:
|
||||
adds r4, r0, r3
|
||||
cmp r4, r1
|
||||
bcc CopyDataInit
|
||||
|
||||
/* Zero fill the bss segment. */
|
||||
ldr r2, =_sbss
|
||||
ldr r4, =_ebss
|
||||
movs r3, #0
|
||||
b LoopFillZerobss
|
||||
|
||||
FillZerobss:
|
||||
str r3, [r2]
|
||||
adds r2, r2, #4
|
||||
|
||||
LoopFillZerobss:
|
||||
cmp r2, r4
|
||||
bcc FillZerobss
|
||||
|
||||
/*Paint Main Stack */
|
||||
ldr r2, = _main_stack_start
|
||||
PaintMainStack:
|
||||
movs r3, #0x55555555
|
||||
str r3, [r2], #4
|
||||
LoopPaintMainStack:
|
||||
ldr r3, = _estack
|
||||
cmp r2, r3
|
||||
bcc PaintMainStack
|
||||
|
||||
/* Call the clock system initialization function.*/
|
||||
bl SystemInit
|
||||
/* Call static constructors */
|
||||
bl __libc_init_array
|
||||
/* Call the application's entry point.*/
|
||||
bl main
|
||||
bx lr
|
||||
.size Reset_Handler, .-Reset_Handler
|
||||
|
||||
/**
|
||||
* @brief This is the code that gets called when the processor receives an
|
||||
* unexpected interrupt. This simply enters an infinite loop, preserving
|
||||
* the system state for examination by a debugger.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
.section .text.Default_Handler,"ax",%progbits
|
||||
Default_Handler:
|
||||
Infinite_Loop:
|
||||
b Infinite_Loop
|
||||
.size Default_Handler, .-Default_Handler
|
||||
/******************************************************************************
|
||||
*
|
||||
* The minimal vector table for a Cortex M3. Note that the proper constructs
|
||||
* must be placed on this to ensure that it ends up at physical address
|
||||
* 0x0000.0000.
|
||||
*
|
||||
*******************************************************************************/
|
||||
.section .isr_vector,"a",%progbits
|
||||
.type g_pfnVectors, %object
|
||||
.size g_pfnVectors, .-g_pfnVectors
|
||||
|
||||
g_pfnVectors:
|
||||
.word _estack
|
||||
.word Reset_Handler
|
||||
.word NMI_Handler
|
||||
.word HardFault_Handler
|
||||
.word MemManage_Handler
|
||||
.word BusFault_Handler
|
||||
.word UsageFault_Handler
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word SVC_Handler
|
||||
.word DebugMon_Handler
|
||||
.word 0
|
||||
.word PendSV_Handler
|
||||
.word SysTick_Handler
|
||||
|
||||
/* External Interrupts */
|
||||
.word WWDG_IRQHandler /* Window WatchDog */
|
||||
.word PVD_IRQHandler /* PVD through EXTI Line detection */
|
||||
.word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */
|
||||
.word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */
|
||||
.word FLASH_IRQHandler /* FLASH */
|
||||
.word RCC_IRQHandler /* RCC */
|
||||
.word EXTI0_IRQHandler /* EXTI Line0 */
|
||||
.word EXTI1_IRQHandler /* EXTI Line1 */
|
||||
.word EXTI2_IRQHandler /* EXTI Line2 */
|
||||
.word EXTI3_IRQHandler /* EXTI Line3 */
|
||||
.word EXTI4_IRQHandler /* EXTI Line4 */
|
||||
.word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */
|
||||
.word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */
|
||||
.word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */
|
||||
.word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */
|
||||
.word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */
|
||||
.word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */
|
||||
.word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */
|
||||
.word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */
|
||||
.word CAN1_TX_IRQHandler /* CAN1 TX */
|
||||
.word CAN1_RX0_IRQHandler /* CAN1 RX0 */
|
||||
.word CAN1_RX1_IRQHandler /* CAN1 RX1 */
|
||||
.word CAN1_SCE_IRQHandler /* CAN1 SCE */
|
||||
.word EXTI9_5_IRQHandler /* External Line[9:5]s */
|
||||
.word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */
|
||||
.word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */
|
||||
.word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */
|
||||
.word TIM1_CC_IRQHandler /* TIM1 Capture Compare */
|
||||
.word TIM2_IRQHandler /* TIM2 */
|
||||
.word TIM3_IRQHandler /* TIM3 */
|
||||
.word TIM4_IRQHandler /* TIM4 */
|
||||
.word I2C1_EV_IRQHandler /* I2C1 Event */
|
||||
.word I2C1_ER_IRQHandler /* I2C1 Error */
|
||||
.word I2C2_EV_IRQHandler /* I2C2 Event */
|
||||
.word I2C2_ER_IRQHandler /* I2C2 Error */
|
||||
.word SPI1_IRQHandler /* SPI1 */
|
||||
.word SPI2_IRQHandler /* SPI2 */
|
||||
.word USART1_IRQHandler /* USART1 */
|
||||
.word USART2_IRQHandler /* USART2 */
|
||||
.word USART3_IRQHandler /* USART3 */
|
||||
.word EXTI15_10_IRQHandler /* External Line[15:10]s */
|
||||
.word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */
|
||||
.word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */
|
||||
.word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */
|
||||
.word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */
|
||||
.word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */
|
||||
.word TIM8_CC_IRQHandler /* TIM8 Capture Compare */
|
||||
.word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */
|
||||
.word FSMC_IRQHandler /* FSMC */
|
||||
.word SDIO_IRQHandler /* SDIO */
|
||||
.word TIM5_IRQHandler /* TIM5 */
|
||||
.word SPI3_IRQHandler /* SPI3 */
|
||||
.word UART4_IRQHandler /* UART4 */
|
||||
.word UART5_IRQHandler /* UART5 */
|
||||
.word TIM6_DAC_IRQHandler /* TIM6, DAC1 and DAC2 */
|
||||
.word TIM7_IRQHandler /* TIM7 */
|
||||
.word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */
|
||||
.word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */
|
||||
.word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */
|
||||
.word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */
|
||||
.word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */
|
||||
.word DFSDM1_FLT0_IRQHandler /* DFSDM1 Filter0 */
|
||||
.word DFSDM1_FLT1_IRQHandler /* DFSDM1 Filter1 */
|
||||
.word CAN2_TX_IRQHandler /* CAN2 TX */
|
||||
.word CAN2_RX0_IRQHandler /* CAN2 RX0 */
|
||||
.word CAN2_RX1_IRQHandler /* CAN2 RX1 */
|
||||
.word CAN2_SCE_IRQHandler /* CAN2 SCE */
|
||||
.word OTG_FS_IRQHandler /* USB OTG FS */
|
||||
.word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */
|
||||
.word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */
|
||||
.word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */
|
||||
.word USART6_IRQHandler /* USART6 */
|
||||
.word I2C3_EV_IRQHandler /* I2C3 event */
|
||||
.word I2C3_ER_IRQHandler /* I2C3 error */
|
||||
.word CAN3_TX_IRQHandler /* CAN3 TX */
|
||||
.word CAN3_RX0_IRQHandler /* CAN3 RX0 */
|
||||
.word CAN3_RX1_IRQHandler /* CAN3 RX1 */
|
||||
.word CAN3_SCE_IRQHandler /* CAN3 SCE */
|
||||
.word 0 /* Reserved */
|
||||
.word 0 /* Reserved */
|
||||
.word RNG_IRQHandler /* RNG */
|
||||
.word FPU_IRQHandler /* FPU */
|
||||
.word UART7_IRQHandler /* UART7 */
|
||||
.word UART8_IRQHandler /* UART8 */
|
||||
.word SPI4_IRQHandler /* SPI4 */
|
||||
.word SPI5_IRQHandler /* SPI5 */
|
||||
.word 0 /* Reserved */
|
||||
.word SAI1_IRQHandler /* SAI1 */
|
||||
.word UART9_IRQHandler /* UART9 */
|
||||
.word UART10_IRQHandler /* UART10 */
|
||||
.word 0 /* Reserved */
|
||||
.word 0 /* Reserved */
|
||||
.word QUADSPI_IRQHandler /* QuadSPI */
|
||||
.word 0 /* Reserved */
|
||||
.word 0 /* Reserved */
|
||||
.word FMPI2C1_EV_IRQHandler /* FMPI2C1 Event */
|
||||
.word FMPI2C1_ER_IRQHandler /* FMPI2C1 Error */
|
||||
.word LPTIM1_IRQHandler /* LPTIM1 */
|
||||
.word DFSDM2_FLT0_IRQHandler /* DFSDM2 Filter0 */
|
||||
.word DFSDM2_FLT1_IRQHandler /* DFSDM2 Filter1 */
|
||||
.word DFSDM2_FLT2_IRQHandler /* DFSDM2 Filter2 */
|
||||
.word DFSDM2_FLT3_IRQHandler /* DFSDM2 Filter3 */
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Provide weak aliases for each Exception handler to the Default_Handler.
|
||||
* As they are weak aliases, any function with the same name will override
|
||||
* this definition.
|
||||
*
|
||||
*******************************************************************************/
|
||||
.weak NMI_Handler
|
||||
.thumb_set NMI_Handler,Default_Handler
|
||||
|
||||
.weak HardFault_Handler
|
||||
.thumb_set HardFault_Handler,Default_Handler
|
||||
|
||||
.weak MemManage_Handler
|
||||
.thumb_set MemManage_Handler,Default_Handler
|
||||
|
||||
.weak BusFault_Handler
|
||||
.thumb_set BusFault_Handler,Default_Handler
|
||||
|
||||
.weak UsageFault_Handler
|
||||
.thumb_set UsageFault_Handler,Default_Handler
|
||||
|
||||
.weak SVC_Handler
|
||||
.thumb_set SVC_Handler,Default_Handler
|
||||
|
||||
.weak DebugMon_Handler
|
||||
.thumb_set DebugMon_Handler,Default_Handler
|
||||
|
||||
.weak PendSV_Handler
|
||||
.thumb_set PendSV_Handler,Default_Handler
|
||||
|
||||
.weak SysTick_Handler
|
||||
.thumb_set SysTick_Handler,Default_Handler
|
||||
|
||||
.weak WWDG_IRQHandler
|
||||
.thumb_set WWDG_IRQHandler,Default_Handler
|
||||
|
||||
.weak PVD_IRQHandler
|
||||
.thumb_set PVD_IRQHandler,Default_Handler
|
||||
|
||||
.weak TAMP_STAMP_IRQHandler
|
||||
.thumb_set TAMP_STAMP_IRQHandler,Default_Handler
|
||||
|
||||
.weak RTC_WKUP_IRQHandler
|
||||
.thumb_set RTC_WKUP_IRQHandler,Default_Handler
|
||||
|
||||
.weak FLASH_IRQHandler
|
||||
.thumb_set FLASH_IRQHandler,Default_Handler
|
||||
|
||||
.weak RCC_IRQHandler
|
||||
.thumb_set RCC_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI0_IRQHandler
|
||||
.thumb_set EXTI0_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI1_IRQHandler
|
||||
.thumb_set EXTI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI2_IRQHandler
|
||||
.thumb_set EXTI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI3_IRQHandler
|
||||
.thumb_set EXTI3_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI4_IRQHandler
|
||||
.thumb_set EXTI4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Stream0_IRQHandler
|
||||
.thumb_set DMA1_Stream0_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Stream1_IRQHandler
|
||||
.thumb_set DMA1_Stream1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Stream2_IRQHandler
|
||||
.thumb_set DMA1_Stream2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Stream3_IRQHandler
|
||||
.thumb_set DMA1_Stream3_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Stream4_IRQHandler
|
||||
.thumb_set DMA1_Stream4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Stream5_IRQHandler
|
||||
.thumb_set DMA1_Stream5_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Stream6_IRQHandler
|
||||
.thumb_set DMA1_Stream6_IRQHandler,Default_Handler
|
||||
|
||||
.weak ADC_IRQHandler
|
||||
.thumb_set ADC_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_TX_IRQHandler
|
||||
.thumb_set CAN1_TX_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_RX0_IRQHandler
|
||||
.thumb_set CAN1_RX0_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_RX1_IRQHandler
|
||||
.thumb_set CAN1_RX1_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_SCE_IRQHandler
|
||||
.thumb_set CAN1_SCE_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI9_5_IRQHandler
|
||||
.thumb_set EXTI9_5_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_BRK_TIM9_IRQHandler
|
||||
.thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_UP_TIM10_IRQHandler
|
||||
.thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_TRG_COM_TIM11_IRQHandler
|
||||
.thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_CC_IRQHandler
|
||||
.thumb_set TIM1_CC_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM2_IRQHandler
|
||||
.thumb_set TIM2_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM3_IRQHandler
|
||||
.thumb_set TIM3_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM4_IRQHandler
|
||||
.thumb_set TIM4_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C1_EV_IRQHandler
|
||||
.thumb_set I2C1_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C1_ER_IRQHandler
|
||||
.thumb_set I2C1_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C2_EV_IRQHandler
|
||||
.thumb_set I2C2_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C2_ER_IRQHandler
|
||||
.thumb_set I2C2_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI1_IRQHandler
|
||||
.thumb_set SPI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI2_IRQHandler
|
||||
.thumb_set SPI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART1_IRQHandler
|
||||
.thumb_set USART1_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART2_IRQHandler
|
||||
.thumb_set USART2_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART3_IRQHandler
|
||||
.thumb_set USART3_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI15_10_IRQHandler
|
||||
.thumb_set EXTI15_10_IRQHandler,Default_Handler
|
||||
|
||||
.weak RTC_Alarm_IRQHandler
|
||||
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
|
||||
|
||||
.weak OTG_FS_WKUP_IRQHandler
|
||||
.thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM8_BRK_TIM12_IRQHandler
|
||||
.thumb_set TIM8_BRK_TIM12_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM8_UP_TIM13_IRQHandler
|
||||
.thumb_set TIM8_UP_TIM13_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM8_TRG_COM_TIM14_IRQHandler
|
||||
.thumb_set TIM8_TRG_COM_TIM14_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM8_CC_IRQHandler
|
||||
.thumb_set TIM8_CC_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Stream7_IRQHandler
|
||||
.thumb_set DMA1_Stream7_IRQHandler,Default_Handler
|
||||
|
||||
.weak FSMC_IRQHandler
|
||||
.thumb_set FSMC_IRQHandler,Default_Handler
|
||||
|
||||
.weak SDIO_IRQHandler
|
||||
.thumb_set SDIO_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM5_IRQHandler
|
||||
.thumb_set TIM5_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI3_IRQHandler
|
||||
.thumb_set SPI3_IRQHandler,Default_Handler
|
||||
|
||||
.weak UART4_IRQHandler
|
||||
.thumb_set UART4_IRQHandler,Default_Handler
|
||||
|
||||
.weak UART5_IRQHandler
|
||||
.thumb_set UART5_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM6_DAC_IRQHandler
|
||||
.thumb_set TIM6_DAC_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM7_IRQHandler
|
||||
.thumb_set TIM7_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Stream0_IRQHandler
|
||||
.thumb_set DMA2_Stream0_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Stream1_IRQHandler
|
||||
.thumb_set DMA2_Stream1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Stream2_IRQHandler
|
||||
.thumb_set DMA2_Stream2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Stream3_IRQHandler
|
||||
.thumb_set DMA2_Stream3_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Stream4_IRQHandler
|
||||
.thumb_set DMA2_Stream4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DFSDM1_FLT0_IRQHandler
|
||||
.thumb_set DFSDM1_FLT0_IRQHandler,Default_Handler
|
||||
|
||||
.weak DFSDM1_FLT1_IRQHandler
|
||||
.thumb_set DFSDM1_FLT1_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_TX_IRQHandler
|
||||
.thumb_set CAN2_TX_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_RX0_IRQHandler
|
||||
.thumb_set CAN2_RX0_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_RX1_IRQHandler
|
||||
.thumb_set CAN2_RX1_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_SCE_IRQHandler
|
||||
.thumb_set CAN2_SCE_IRQHandler,Default_Handler
|
||||
|
||||
.weak OTG_FS_IRQHandler
|
||||
.thumb_set OTG_FS_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Stream5_IRQHandler
|
||||
.thumb_set DMA2_Stream5_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Stream6_IRQHandler
|
||||
.thumb_set DMA2_Stream6_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Stream7_IRQHandler
|
||||
.thumb_set DMA2_Stream7_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART6_IRQHandler
|
||||
.thumb_set USART6_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C3_EV_IRQHandler
|
||||
.thumb_set I2C3_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C3_ER_IRQHandler
|
||||
.thumb_set I2C3_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN3_TX_IRQHandler
|
||||
.thumb_set CAN3_TX_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN3_RX0_IRQHandler
|
||||
.thumb_set CAN3_RX0_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN3_RX1_IRQHandler
|
||||
.thumb_set CAN3_RX1_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN3_SCE_IRQHandler
|
||||
.thumb_set CAN3_SCE_IRQHandler,Default_Handler
|
||||
|
||||
.weak RNG_IRQHandler
|
||||
.thumb_set RNG_IRQHandler,Default_Handler
|
||||
|
||||
.weak FPU_IRQHandler
|
||||
.thumb_set FPU_IRQHandler,Default_Handler
|
||||
|
||||
.weak UART7_IRQHandler
|
||||
.thumb_set UART7_IRQHandler,Default_Handler
|
||||
|
||||
.weak UART8_IRQHandler
|
||||
.thumb_set UART8_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI4_IRQHandler
|
||||
.thumb_set SPI4_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI5_IRQHandler
|
||||
.thumb_set SPI5_IRQHandler,Default_Handler
|
||||
|
||||
.weak SAI1_IRQHandler
|
||||
.thumb_set SAI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak UART9_IRQHandler
|
||||
.thumb_set UART9_IRQHandler,Default_Handler
|
||||
|
||||
.weak UART10_IRQHandler
|
||||
.thumb_set UART10_IRQHandler,Default_Handler
|
||||
|
||||
.weak QUADSPI_IRQHandler
|
||||
.thumb_set QUADSPI_IRQHandler,Default_Handler
|
||||
|
||||
.weak FMPI2C1_EV_IRQHandler
|
||||
.thumb_set FMPI2C1_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak FMPI2C1_ER_IRQHandler
|
||||
.thumb_set FMPI2C1_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak LPTIM1_IRQHandler
|
||||
.thumb_set LPTIM1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DFSDM2_FLT0_IRQHandler
|
||||
.thumb_set DFSDM2_FLT0_IRQHandler,Default_Handler
|
||||
|
||||
.weak DFSDM2_FLT1_IRQHandler
|
||||
.thumb_set DFSDM2_FLT1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DFSDM2_FLT2_IRQHandler
|
||||
.thumb_set DFSDM2_FLT2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DFSDM2_FLT3_IRQHandler
|
||||
.thumb_set DFSDM2_FLT3_IRQHandler,Default_Handler
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
**
|
||||
** @file : LinkerScript.ld
|
||||
**
|
||||
** @brief : Linker script for STM32F413VGTx Device from STM32F4 series
|
||||
** 1024Kbytes FLASH
|
||||
** 320Kbytes RAM
|
||||
**
|
||||
** Set heap size, stack size and stack location according
|
||||
** to application requirements.
|
||||
**
|
||||
** Set memory bank area and size if external memory is used
|
||||
**
|
||||
** Target : STMicroelectronics STM32
|
||||
**
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
|
||||
_heap_end = 0x20050000; /* end of 320K SRAM */
|
||||
|
||||
_Min_Heap_Size = 0 ; /* required amount of heap */
|
||||
_Min_Stack_Size = 0x400 ; /* required amount of stack */
|
||||
|
||||
_Main_Stack_Size = 1024; /* required amount of stack for interrupt stack (Main stack) */
|
||||
|
||||
/* Main stack end */
|
||||
_main_stack_start = _estack - _Main_Stack_Size;
|
||||
|
||||
/* Memories definition */
|
||||
MEMORY
|
||||
{
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K
|
||||
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
|
||||
}
|
||||
|
||||
/* Sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The program code and other data into "FLASH" Rom type memory */
|
||||
.text :
|
||||
{
|
||||
FILL(0xFFFF)
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
|
||||
KEEP(*(.bootloader)) /* Bootloader code */
|
||||
|
||||
. = 0x8000; /* Set the start of the main program */
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
KEEP(*(.fwversiondata))
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
*(.data.__global_locale)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >FLASH
|
||||
|
||||
.ARM.extab : {
|
||||
. = ALIGN(4);
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.ARM : {
|
||||
. = ALIGN(4);
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.init_array :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.fini_array :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
KEEP (*(.fini_array*))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
/* Used by the startup to initialize data */
|
||||
_sidata = LOADADDR(.data);
|
||||
|
||||
/* Initialized data sections into "RAM" Ram type memory */
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sdata = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
*(.RamFunc) /* .RamFunc sections */
|
||||
*(.RamFunc*) /* .RamFunc* sections */
|
||||
|
||||
. = ALIGN(4);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
|
||||
} >RAM AT> FLASH
|
||||
|
||||
/* Uninitialized data section into "RAM" Ram type memory */
|
||||
. = ALIGN(4);
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss section */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
__bss_start__ = _sbss;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
__bss_end__ = _ebss;
|
||||
} >RAM
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
|
||||
._user_heap_stack :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE ( end = . );
|
||||
PROVIDE ( _end = . );
|
||||
. = . + _Min_Heap_Size;
|
||||
. = . + _Min_Stack_Size;
|
||||
. = ALIGN(8);
|
||||
} >RAM
|
||||
|
||||
/* Remove information from the compiler libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
}
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
Reference in New Issue
Block a user