feat: Flysky PL18 Support (#4105)

Co-authored-by: raphaelcoeffic <raphael.coeffic@frafos.com>
Co-authored-by: rotorman <risto.koiva@web.de>
Co-authored-by: Xy201207 <yaoxu@flysky.com>
Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
richardclli
2023-12-06 09:00:44 +10:00
committed by GitHub
co-authored by raphaelcoeffic rotorman Xy201207 Peter Feerick
parent 5153aaeea0
commit cc17046e7a
128 changed files with 9178 additions and 171 deletions
+12 -10
View File
@@ -22,17 +22,19 @@ option(DEBUG_USB_INTERRUPTS "Count individual USB interrupts" OFF)
option(DEBUG_TIMERS "Time critical parts of the code" OFF)
option(DEBUG_BLUETOOTH "Debug Bluetooth" OFF)
# option to select the default internal module
#set(DEFAULT_INTERNAL_MODULE NONE CACHE STRING "Default internal module")
set_property(CACHE DEFAULT_INTERNAL_MODULE PROPERTY STRINGS ${INTERNAL_MODULES})
if(INTERNAL_MODULES)
# option to select the default internal module
#set(DEFAULT_INTERNAL_MODULE NONE CACHE STRING "Default internal module")
set_property(CACHE DEFAULT_INTERNAL_MODULE PROPERTY STRINGS ${INTERNAL_MODULES})
# define variables for internal modules
foreach(module ${INTERNAL_MODULES})
set(INTERNAL_MODULE_${module} ON CACHE BOOL "Support for ${module} internal module")
if (INTERNAL_MODULE_${module})
message("-- Adding support for ${module} as internal module")
endif()
endforeach()
# define variables for internal modules
foreach(module ${INTERNAL_MODULES})
set(INTERNAL_MODULE_${module} ON CACHE BOOL "Support for ${module} internal module")
if (INTERNAL_MODULE_${module})
message("-- Adding support for ${module} as internal module")
endif()
endforeach()
endif()
if(INTERNAL_MODULE_PXX1)
add_definitions(-DHARDWARE_INTERNAL_MODULE)
@@ -69,8 +69,7 @@ if(DEBUG_SEGGER_RTT)
)
endif()
if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14 OR PCB STREQUAL PL18)
set(BOOTLOADER_SRC
${BOOTLOADER_SRC}
../../../../../gui/colorlcd/fonts.cpp
@@ -79,7 +78,6 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
../../../../../thirdparty/libopenui/src/bitmapbuffer.cpp
../../../../../thirdparty/libopenui/thirdparty/lz4/lz4.c
../../../../../targets/common/arm/stm32/dma2d.cpp
../../../../../targets/common/arm/stm32/diskio_sdio.cpp
../../../../../targets/common/arm/stm32/rtc_driver.cpp
../../../../../targets/common/arm/stm32/diskio_spi_flash.cpp
../../../../../targets/common/arm/stm32/spi_flash.cpp
@@ -90,12 +88,22 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
../../../../../targets/${TARGET_DIR}/haptic_driver.cpp
)
if(NOT PCB STREQUAL PL18)
set(BOOTLOADER_SRC ${BOOTLOADER_SRC}
../../../../../targets/common/arm/stm32/diskio_sdio.cpp
)
else()
set(BOOTLOADER_SRC ${BOOTLOADER_SRC}
../../../../../targets/pl18/key_driver.cpp
)
endif()
# Add LVGL sources
foreach(LVGL_FILE ${LVGL_SRC_FILES_MINIMAL})
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} ../../../../../${LVGL_FILE})
endforeach()
if(NOT PCB STREQUAL NV14)
if(NOT (PCB STREQUAL NV14 OR PCB STREQUAL PL18))
set(BOOTLOADER_SRC
${BOOTLOADER_SRC}
../../../../../targets/${TARGET_DIR}/led_driver.cpp
@@ -56,12 +56,17 @@
#define APP_START_ADDRESS (uint32_t)(FIRMWARE_ADDRESS + BOOTLOADER_SIZE)
#if defined(EEPROM)
#if defined(EEPROM) || defined(SPI_FLASH)
#define MAIN_MENU_LEN 3
#else
#define MAIN_MENU_LEN 2
#endif
#if defined(SPI_FLASH)
#include "spi_flash.h"
#define SEL_CLEAR_FLASH_STORAGE_MENU_LEN 2
#endif
typedef void (*voidFunction)(void);
#define jumpTo(addr) do { \
@@ -369,6 +374,10 @@ int bootloaderMain()
memoryType = MEM_EEPROM;
state = ST_DIR_CHECK;
break;
#elif defined(SPI_FLASH)
case 1:
state = ST_CLEAR_FLASH_CHECK;
break;
#endif
default:
if(vpos < bootloaderGetMenuItemCount(MAIN_MENU_LEN-1))
@@ -511,6 +520,35 @@ int bootloaderMain()
else if (memoryType == MEM_EEPROM && eepromWritten >= EEPROM_SIZE) {
state = ST_FLASH_DONE; // Backstop
}
#endif
#if defined(SPI_FLASH)
} else if (state == ST_CLEAR_FLASH_CHECK) {
bootloaderDrawScreen(state, vpos);
if (event == EVT_KEY_REPT(KEY_DOWN) || event == EVT_KEY_FIRST(KEY_DOWN)) {
if (vpos < SEL_CLEAR_FLASH_STORAGE_MENU_LEN - 1) { vpos++; }
continue;
}
if (event == EVT_KEY_REPT(KEY_UP) || event == EVT_KEY_FIRST(KEY_UP)) {
if (vpos > 0) { vpos--; }
continue;
}
if (event == EVT_KEY_LONG(KEY_ENTER) && vpos == 0)
{
state = ST_CLEAR_FLASH;
} else if (event == EVT_KEY_BREAK(KEY_EXIT) ||
(event == EVT_KEY_BREAK(KEY_ENTER) && vpos == 1) ) {
vpos = 0;
state = ST_START;
continue;
}
} else if (state == ST_CLEAR_FLASH) {
bootloaderDrawScreen(state, 0);
lcdRefresh();
if(event != EVT_KEY_BREAK(KEY_ENTER))
continue;
flashSpiEraseAll();
vpos = 0;
state = ST_START;
#endif
} else if (state == ST_RADIO_MENU) {
if(bootloaderRadioMenu(radioMenuItem, event))
@@ -565,6 +603,6 @@ int bootloaderMain()
return 0;
}
#if !defined(SIMU) && (defined(PCBHORUS) || defined(PCBNV14))
#if !defined(SIMU) && (defined(PCBHORUS) || defined(PCBFLYSKY))
void *__dso_handle = nullptr;
#endif
@@ -54,6 +54,10 @@ enum BootloaderState {
ST_FLASH_DONE,
ST_RESTORE_MENU,
ST_USB,
#if defined(SPI_FLASH)
ST_CLEAR_FLASH_CHECK,
ST_CLEAR_FLASH,
#endif
ST_RADIO_MENU,
ST_REBOOT,
};
@@ -30,6 +30,7 @@
#include "drivers/frftl.h"
static FrFTL _frftl;
static bool frftlInitDone = false;
static bool flashRead(uint32_t addr, uint8_t* buf, uint32_t len)
{
@@ -89,6 +90,7 @@ static DSTATUS spi_flash_initialize(BYTE lun)
if (!ftlInit(&_frftl, &_frftl_cb, flashSizeMB)) {
return STA_NOINIT;
}
frftlInitDone = true;
#endif
return 0;
@@ -102,7 +104,7 @@ static DSTATUS spi_flash_status (BYTE lun)
static DRESULT spi_flash_read(BYTE lun, BYTE * buff, DWORD sector, UINT count)
{
#if defined(USE_FLASH_FTL)
while(count) {
while(frftlInitDone && count) {
if(!ftlRead(&_frftl, sector, (uint8_t*)buff)) {
return RES_ERROR;
@@ -122,7 +124,7 @@ static DRESULT spi_flash_read(BYTE lun, BYTE * buff, DWORD sector, UINT count)
static DRESULT spi_flash_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
{
#if defined(USE_FLASH_FTL)
if (!ftlWrite(&_frftl, sector, count, (uint8_t*)buff)) {
if (frftlInitDone && !ftlWrite(&_frftl, sector, count, (uint8_t*)buff)) {
return RES_ERROR;
}
#else
@@ -166,7 +168,7 @@ static DRESULT spi_flash_ioctl(BYTE lun, BYTE ctrl, void *buff)
case CTRL_SYNC:
#if defined(USE_FLASH_FTL)
if (!ftlSync(&_frftl)) {
if (frftlInitDone && !ftlSync(&_frftl)) {
res = RES_ERROR;
}
#else
@@ -176,7 +178,7 @@ static DRESULT spi_flash_ioctl(BYTE lun, BYTE ctrl, void *buff)
case CTRL_TRIM:
#if defined(USE_FLASH_FTL)
if (!ftlTrim(&_frftl, *(DWORD*)buff, 1 + *((DWORD*)buff + 1) - *(DWORD*)buff)) {
if (frftlInitDone && !ftlTrim(&_frftl, *(DWORD*)buff, 1 + *((DWORD*)buff + 1) - *(DWORD*)buff)) {
res = RES_ERROR;
}
#endif
@@ -38,9 +38,11 @@ void pwrInit()
#endif
// Internal module power
#if defined(HARDWARE_INTERNAL_MODULE)
INTERNAL_MODULE_OFF();
GPIO_InitStructure.GPIO_Pin = INTMODULE_PWR_GPIO_PIN;
GPIO_Init(INTMODULE_PWR_GPIO, &GPIO_InitStructure);
#endif
// External module power
EXTERNAL_MODULE_PWR_OFF();
@@ -223,10 +223,19 @@ static bool flash_read_sfdp(SpiFlashDescriptor* desc)
return true;
}
void flashSpiSync()
{
uint8_t status;
do {
flash_do_cmd(FLASH_CMD_STATUS, 0, &status, 1);
} while (status & 0x01);
}
bool flashSpiInit(void)
{
stm32_spi_init(&_flash_spi);
delay_ms(1);
flashSpiSync();
if (!flash_read_id(&_flashDescriptor)) {
return false;
@@ -239,14 +248,6 @@ bool flashSpiInit(void)
return true;
}
void flashSpiSync()
{
uint8_t status;
do {
flash_do_cmd(FLASH_CMD_STATUS, 0, &status, 1);
} while (status & 0x01);
}
uint32_t flashSpiGetSize()
{
return (1UL << _flashDescriptor.log2Size);
@@ -26,9 +26,10 @@
#include "opentx.h"
#define ADC_COMMON ((ADC_Common_TypeDef *) ADC_BASE)
#define MAX_ADC_INPUTS 32
#define OVERSAMPLING 4
#define ADC_COMMON ((ADC_Common_TypeDef *)ADC_BASE)
#define OVERSAMPLING 4
#define SAMPLING_TIMEOUT_US 500
// Please note that we use the same prio for DMA TC and ADC IRQs
// to avoid issues with preemption between these 2
@@ -43,7 +44,7 @@ static volatile uint32_t _adc_inhibit_mask;
static uint16_t _adc_dma_buffer[MAX_ADC_INPUTS] __DMA;
// ADCs started
static uint8_t _adc_started_mask;
static volatile uint8_t _adc_started_mask;
static volatile uint8_t _adc_completed;
static const stm32_adc_t* _adc_ADCs;
@@ -532,8 +533,14 @@ void stm32_hal_adc_wait_completion(const stm32_adc_t* ADCs, uint8_t n_ADC,
(void)inputs;
(void)n_inputs;
auto timeout = timersGetUsTick();
while(!_adc_completed) {
// busy wait
if ((uint32_t)(timersGetUsTick() - timeout) >= SAMPLING_TIMEOUT_US) {
TRACE("ADC timeout");
_adc_started_mask = 0;
return;
}
}
}
@@ -572,8 +579,7 @@ static void _adc_chain_conversions(const stm32_adc_t* adc)
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);
adc_dma_clear_flags(adc->DMAx, adc->DMA_Stream);
uint16_t* dma_buffer = _adc_dma_buffer + adc->offset;
copy_adc_values(dma_buffer, adc, _adc_inputs);
@@ -24,6 +24,7 @@
#include "stm32_hal_ll.h"
#include "hal/adc_driver.h"
#define MAX_ADC_INPUTS 32
struct stm32_adc_input_t {
GPIO_TypeDef* GPIOx;
+3 -1
View File
@@ -49,7 +49,8 @@ void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
GPIO_PinAFConfig(USB_GPIO, USB_GPIO_PinSource_DM, USB_GPIO_AF);
GPIO_PinAFConfig(USB_GPIO, USB_GPIO_PinSource_DP, USB_GPIO_AF);
#if defined(USB_GPIO_PIN_VBUS)
/* Configure VBUS Pin */
GPIO_InitStructure.GPIO_Pin = USB_GPIO_PIN_VBUS;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
@@ -57,6 +58,7 @@ void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(USB_GPIO, &GPIO_InitStructure);
#endif
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;
@@ -29,6 +29,8 @@
#include "stm32f2xx.h"
#endif
#include "hal.h"
/* USB Core and PHY interface configuration.
Tip: To avoid modifying these defines each time you need to change the USB
configuration, you can declare the needed define in your toolchain
@@ -97,7 +99,9 @@
#endif
/****************** USB OTG MISC CONFIGURATION ********************************/
#if defined(USB_GPIO_PIN_VBUS)
#define VBUS_SENSING_ENABLED
#endif
/****************** USB OTG MODE CONFIGURATION ********************************/
//#define USE_HOST_MODE
@@ -57,6 +57,7 @@ void setSelectedUsbMode(int mode)
selectedUsbMode = usbMode(mode);
}
#if defined(USB_GPIO_PIN_VBUS)
int usbPlugged()
{
static uint8_t debouncedState = 0;
@@ -71,6 +72,7 @@ int usbPlugged()
return debouncedState;
}
#endif
USB_OTG_CORE_HANDLE USB_OTG_dev;