feat: add support for RadioMaster TX16S MK3 (#7017)

Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
Co-authored-by: 3djc <3djc@gh.com>
Co-authored-by: Peter Feerick <5500713+pfeerick@users.noreply.github.com>
This commit is contained in:
3djc
2026-01-25 14:08:05 +10:00
committed by GitHub
co-authored by philmoz 3djc Peter Feerick
parent 5394e84871
commit be496b66b6
86 changed files with 2789 additions and 60 deletions
+1 -1
View File
@@ -184,7 +184,7 @@ extern "C" void DMA1_Stream4_IRQHandler(void)
if (stm32_dma_check_ht_flag(I2S_DMA, I2S_DMA_Stream)) {
audio_update_dma_buffer(0);
}
if (stm32_dma_check_tc_flag(I2S_DMA, I2S_DMA_Stream)) {
audio_update_dma_buffer(1);
}
@@ -29,6 +29,12 @@
#include "globals.h"
typedef void (*lcdSpiInitFucPtr)(void);
typedef unsigned int LcdReadIDFucPtr( void );
extern lcdSpiInitFucPtr lcdOffFunction;
extern lcdSpiInitFucPtr lcdOnFunction;
static const stm32_pulse_timer_t _bl_timer = {
.GPIO = (gpio_t)BACKLIGHT_GPIO,
.GPIO_Alternate = BACKLIGHT_GPIO_AF,
@@ -51,7 +57,7 @@ void backlightLowInit()
void backlightInit()
{
stm32_pulse_init(&_bl_timer, 1000000);
stm32_pulse_init(&_bl_timer, 100000);
stm32_pulse_config_output(&_bl_timer, true, LL_TIM_OCMODE_PWM1, 100);
LL_TIM_SetAutoReload(_bl_timer.TIMx, 100);
LL_TIM_EnableCounter(_bl_timer.TIMx);
+1 -1
View File
@@ -202,7 +202,7 @@ static SwitchHwPos _get_switch_pos(uint8_t idx)
}
else if (!def->Pin_low) {
// 2POS switch
if ((state & def->Pin_high) == 0) {
if ((state & def->Pin_high) != 0) {
pos = SWITCH_HW_DOWN;
}
} else {
+275
View File
@@ -0,0 +1,275 @@
/*
* 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_hal_ll.h"
#include "stm32_hal.h"
#include "edgetx_types.h"
#include "dma2d.h"
#include "hal.h"
#include "delays_driver.h"
#include "debug.h"
#include "lcd.h"
#include "lcd_driver_800.h"
#include "board.h"
#include "hal/gpio.h"
#include "stm32_gpio.h"
#include "stm32_qspi.h"
uint8_t TouchControllerType = 0; // 0: other; 1: CST836U
static const uint16_t lcd_phys_w = LCD_PHYS_W;
static const uint16_t lcd_phys_h = LCD_PHYS_H;
static LTDC_HandleTypeDef hltdc;
static void* initialFrameBuffer = nullptr;
static volatile uint8_t _frame_addr_reloaded = 0;
static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer,
const rect_t &copy_area)
{
(void)disp_drv;
(void)copy_area;
// given the data cache size, this is probably
// faster than cleaning by address
SCB_CleanDCache();
LTDC_Layer1->CFBAR = (uint32_t)buffer;
// reload shadow registers on vertical blank
_frame_addr_reloaded = 0;
LTDC->SRCR = LTDC_SRCR_VBR;
__HAL_LTDC_ENABLE_IT(&hltdc, LTDC_IT_LI);
// wait for reload
// TODO: replace through some smarter mechanism without busy wait
while(_frame_addr_reloaded == 0);
}
lcdSpiInitFucPtr lcdInitFunction;
lcdSpiInitFucPtr lcdOffFunction;
lcdSpiInitFucPtr lcdOnFunction;
uint32_t lcdPixelClock;
volatile uint8_t LCD_ReadBuffer[24] = { 0, 0 };
static void LCD_AF_GPIOConfig(void)
{
const gpio_t _lcd_af_gpios[] = {
GPIO_PIN(GPIOI, 12), GPIO_PIN(GPIOI, 13), GPIO_PIN(GPIOI, 14),
GPIO_PIN(GPIOJ, 1), GPIO_PIN(GPIOJ, 2), GPIO_PIN(GPIOJ, 3),
GPIO_PIN(GPIOJ, 4), GPIO_PIN(GPIOJ, 5), GPIO_PIN(GPIOJ, 6),
GPIO_PIN(GPIOJ, 9), GPIO_PIN(GPIOJ, 10), GPIO_PIN(GPIOJ, 11),
GPIO_PIN(GPIOJ, 14), GPIO_PIN(GPIOJ, 15),
GPIO_PIN(GPIOK, 0), GPIO_PIN(GPIOK, 1), GPIO_PIN(GPIOK, 2),
GPIO_PIN(GPIOK, 3), GPIO_PIN(GPIOK, 4), GPIO_PIN(GPIOK, 5),
GPIO_PIN(GPIOK, 6), GPIO_PIN(GPIOK, 7),
};
for (unsigned i = 0; i < sizeof(_lcd_af_gpios) / sizeof(_lcd_af_gpios[0]); i++) {
gpio_init_af(_lcd_af_gpios[i], GPIO_AF14, GPIO_SPEED_FREQ_LOW);
}
}
static void lcdSpiConfig(void)
{
LL_GPIO_InitTypeDef GPIO_InitStructure;
LL_GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.Pin = LCD_RESET_GPIO_PIN;
GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStructure.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(LCD_RESET_GPIO, &GPIO_InitStructure);
}
void lcdDelay() {
delay_01us(1);
}
static void lcdReset() {
LCD_NRST_HIGH();
delay_ms(1);
LCD_NRST_LOW(); // RESET();
delay_ms(10);
LCD_NRST_HIGH();
delay_ms(100);
}
void LCD_Init_LTDC() {
hltdc.Instance = LTDC;
/* Configure PLLSAI prescalers for LCD */
/* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
/* PLLSAI_VCO Output = PLLSAI_VCO Input * lcdPixelclock * 16 = XX Mhz */
/* PLLLCDCLK = PLLSAI_VCO Output/PLL_LTDC = PLLSAI_VCO/4 = YY Mhz */
/* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = YY/4 = lcdPixelClock Mhz */
// uint32_t clock = (lcdPixelClock*16) / 1000000; // clock*16 in MHz
// RCC_PeriphCLKInitTypeDef clkConfig;
// clkConfig.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
// clkConfig.PLLI2S
// clkConfig.PLLSAI.PLLSAIN = clock;
// clkConfig.PLLSAI.PLLSAIR = 4;
// clkConfig.PLLSAIDivQ = 6;
// clkConfig.PLLSAIDivR = RCC_PLLSAIDIVR_4;
// HAL_RCCEx_PeriphCLKConfig(&clkConfig);
/* LTDC Configuration *********************************************************/
/* Polarity configuration */
/* Initialize the horizontal synchronization polarity as active low */
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
/* Initialize the vertical synchronization polarity as active low */
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
/* Initialize the data enable polarity as active low */
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
/* Initialize the pixel clock polarity as input pixel clock */
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IIPC;
/* Configure R,G,B component values for LCD background color */
hltdc.Init.Backcolor.Red = 0;
hltdc.Init.Backcolor.Green = 0;
hltdc.Init.Backcolor.Blue = 0;
/* Configure horizontal synchronization width */
hltdc.Init.HorizontalSync = HSW-1;
/* Configure vertical synchronization height */
hltdc.Init.VerticalSync = VSH-1;
/* Configure accumulated horizontal back porch */
hltdc.Init.AccumulatedHBP = HSW+HBP-1;
/* Configure accumulated vertical back porch */
hltdc.Init.AccumulatedVBP = VSH+VBP-1;
/* Configure accumulated active width */
hltdc.Init.AccumulatedActiveW = lcd_phys_w + HBP+HSW-1;
/* Configure accumulated active height */
hltdc.Init.AccumulatedActiveH = lcd_phys_h + VBP+VSH-1;
/* Configure total width */
hltdc.Init.TotalWidth = lcd_phys_w + HBP + HFP + HSW -1;
/* Configure total height */
hltdc.Init.TotalHeigh = lcd_phys_h + VBP + VFP+VSH-1;
HAL_LTDC_Init(&hltdc);
// Configure IRQ (line)
NVIC_SetPriority(LTDC_IRQn, LTDC_IRQ_PRIO);
NVIC_EnableIRQ(LTDC_IRQn);
// Trigger on last line
HAL_LTDC_ProgramLineEvent(&hltdc, lcd_phys_h);
__HAL_LTDC_ENABLE_IT(&hltdc, LTDC_IT_LI);
}
void LCD_LayerInit() {
auto& layer = hltdc.LayerCfg[0];
/* Windowing configuration */
layer.WindowX0 = 0;
layer.WindowX1 = lcd_phys_w;
layer.WindowY0 = 0;
layer.WindowY1 = lcd_phys_h;
/* Pixel Format configuration*/
layer.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
/* Alpha constant (255 totally opaque) */
layer.Alpha = 255;
/* Default Color configuration (configure A,R,G,B component values) */
layer.Backcolor.Blue = 0;
layer.Backcolor.Green = 0;
layer.Backcolor.Red = 0;
layer.Alpha0 = 0;
/* Configure blending factors */
layer.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
layer.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
layer.ImageWidth = lcd_phys_w;
layer.ImageHeight = lcd_phys_h;
/* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */
layer.FBStartAdress = (intptr_t)initialFrameBuffer;
/* Initialize LTDC layer 1 */
HAL_LTDC_ConfigLayer(&hltdc, &hltdc.LayerCfg[0], 0);
/* dithering activation */
HAL_LTDC_EnableDither(&hltdc);
}
extern "C"
void lcdSetInitalFrameBuffer(void* fbAddress)
{
initialFrameBuffer = fbAddress;
}
const char* boardLcdType = "";
extern "C"
void lcdInit(void)
{
#if defined(LCD_SPI_CONFLICTS_WITH_QSPI)
stm32_qspi_nor_deinit();
#endif
/* Configure the LCD SPI+RESET pins */
lcdSpiConfig();
/* Reset the LCD --------------------------------------------------------*/
lcdReset();
/* Configure the LCD Control pins */
LCD_AF_GPIOConfig();
/* Send LCD initialization commands */
TRACE("LCD INIT (default): ST7365");
boardLcdType = "ST7365 (Default)";
__HAL_RCC_LTDC_CLK_ENABLE();
LCD_Init_LTDC();
LCD_LayerInit();
// Enable LCD display
__HAL_LTDC_ENABLE(&hltdc);
lcdSetFlushCb(startLcdRefresh);
#if defined(LCD_SPI_CONFLICTS_WITH_QSPI)
stm32_qspi_nor_init();
stm32_qspi_nor_memory_mapped();
#endif
}
extern "C" void LTDC_IRQHandler(void)
{
__HAL_LTDC_CLEAR_FLAG(&hltdc, LTDC_FLAG_LI);
__HAL_LTDC_DISABLE_IT(&hltdc, LTDC_IT_LI);
_frame_addr_reloaded = 1;
}
+46
View File
@@ -0,0 +1,46 @@
/*
* 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 "bsp_io.h"
#define HBP ( 16 )
#define VBP ( 8 )
#define HSW ( 4 )
#define VSH ( 4 )
#define HFP ( 16 )
#define VFP ( 8 )
typedef void (*lcdSpiInitFucPtr)(void);
typedef unsigned int LcdReadIDFucPtr( void );
extern lcdSpiInitFucPtr lcdInitFunction;
extern lcdSpiInitFucPtr lcdOffFunction;
extern lcdSpiInitFucPtr lcdOnFunction;
#define SET_IO_INPUT( PORT, PIN ) LL_GPIO_SetPinMode( PORT, PIN, LL_GPIO_MODE_INPUT )
#define SET_IO_OUTPUT( PORT, PIN ) LL_GPIO_SetPinMode( PORT, PIN, LL_GPIO_MODE_OUTPUT )
#define LCD_NRST_HIGH() LL_GPIO_SetOutputPin(LCD_RESET_GPIO, LCD_RESET_GPIO_PIN)
#define LCD_NRST_LOW() LL_GPIO_ResetOutputPin(LCD_RESET_GPIO, LCD_RESET_GPIO_PIN)
@@ -0,0 +1,51 @@
/*
* 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 "edgetx.h"
#include "luminosity_sensor.h"
#include "hal/adc_driver.h"
static uint32_t luxEMA = 0;
static bool luxInitialized = false;
bool getPeriodicLuxSensorValue()
{
if (adcGetMaxInputs(ADC_INPUT_LUX) < 1) return false;
uint16_t newValue = anaIn(adcGetInputOffset(ADC_INPUT_LUX));
if (!luxInitialized) {
// Initialize EMA with first reading
luxEMA = (uint32_t)newValue << 8; // Scale up for precision
luxInitialized = true;
} else {
// EMA formula with alpha = 26/256 ≈ 0.102
int32_t diff = ((int32_t)newValue << 8) - (int32_t)luxEMA;
luxEMA = luxEMA + ((diff * 26) >> 8);
}
return true;
}
uint16_t getLuxSensorValue()
{
return luxEMA >> 8; // Scale back down
}
@@ -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 <stdint.h>
#include "edgetx_types.h"
#pragma once
bool getPeriodicLuxSensorValue();
uint16_t getLuxSensorValue();
@@ -96,6 +96,9 @@ extern "C" void SDRAM_GPIOConfig(void)
/* GPIOG configuration */
gpio_init_af(GPIO_PIN(GPIOG, 0), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
gpio_init_af(GPIO_PIN(GPIOG, 1), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
#if defined(SDRAM_32M)
gpio_init_af(GPIO_PIN(GPIOG, 2), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
#endif
gpio_init_af(GPIO_PIN(GPIOG, 4), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
gpio_init_af(GPIO_PIN(GPIOG, 5), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
gpio_init_af(GPIO_PIN(GPIOG, 8), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
@@ -194,8 +197,13 @@ extern "C" void SDRAM_Init(void)
/* FMC SDRAM control configuration */
FMC_SDRAMInitStructure.SDBank = FMC_SDRAM_BANK2;
#if defined(SDRAM_32M)
FMC_SDRAMInitStructure.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9;
FMC_SDRAMInitStructure.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13;
#else
FMC_SDRAMInitStructure.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
FMC_SDRAMInitStructure.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
#endif
FMC_SDRAMInitStructure.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
FMC_SDRAMInitStructure.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
FMC_SDRAMInitStructure.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
+5 -1
View File
@@ -94,7 +94,11 @@ BOOTSTRAP void SystemClock_Config(void)
LL_RCC_PLL3_SetN(4);
LL_RCC_PLL3_SetP(2);
LL_RCC_PLL3_SetQ(2);
#if defined(RADIO_TX16SMK3)
LL_RCC_PLL3_SetR(8); // 24 MHz
#else
LL_RCC_PLL3_SetR(18);
#endif
LL_RCC_PLL3_Enable();
while (LL_RCC_PLL3_IsReady() != 1) {
}
@@ -105,7 +109,7 @@ BOOTSTRAP void SystemClock_Config(void)
LL_AHB2_GRP1_PERIPH_D2SRAM3);
/* Set periph clock sources */
LL_RCC_SetSPIClockSource(LL_RCC_SPI123_CLKSOURCE_PLL1Q);
LL_RCC_SetSPIClockSource(LL_RCC_SPI123_CLKSOURCE_PLL1Q);
LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLL1Q);
LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_CLKP);
}