feat(radio): Senduwing H17 support (#7764)
Co-authored-by: 3djc <3djc@gh.com> Co-authored-by: Risto <rotorman@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,476 @@
|
||||
{
|
||||
"adc_inputs": {
|
||||
"adcs": [
|
||||
{
|
||||
"name": "MAIN",
|
||||
"adc": "ADC1",
|
||||
"dma": "DMA2",
|
||||
"dma_channel": "LL_DMAMUX1_REQ_ADC1",
|
||||
"dma_stream": "LL_DMA_STREAM_4",
|
||||
"dma_stream_irq": "DMA2_Stream4_IRQn",
|
||||
"dma_stream_irq_handler": "DMA2_Stream4_IRQHandler",
|
||||
"sample_time": "LL_ADC_SAMPLINGTIME_8CYCLES_5"
|
||||
},
|
||||
{
|
||||
"name": "EXT",
|
||||
"adc": "ADC3",
|
||||
"dma": "DMA2",
|
||||
"dma_channel": "LL_DMAMUX1_REQ_ADC3",
|
||||
"dma_stream": "LL_DMA_STREAM_0",
|
||||
"dma_stream_irq": "DMA2_Stream0_IRQn",
|
||||
"dma_stream_irq_handler": "DMA2_Stream0_IRQHandler",
|
||||
"sample_time": "LL_ADC_SAMPLINGTIME_8CYCLES_5"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"name": "LH",
|
||||
"type": "STICK",
|
||||
"adc": "MAIN",
|
||||
"gpio": "GPIOA",
|
||||
"pin": "LL_GPIO_PIN_6",
|
||||
"channel": "LL_ADC_CHANNEL_3",
|
||||
"inverted": true
|
||||
},
|
||||
{
|
||||
"name": "LV",
|
||||
"type": "STICK",
|
||||
"adc": "MAIN",
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_3",
|
||||
"channel": "LL_ADC_CHANNEL_13",
|
||||
"inverted": true
|
||||
},
|
||||
{
|
||||
"name": "RV",
|
||||
"type": "STICK",
|
||||
"adc": "MAIN",
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_4",
|
||||
"channel": "LL_ADC_CHANNEL_4"
|
||||
},
|
||||
{
|
||||
"name": "RH",
|
||||
"type": "STICK",
|
||||
"adc": "MAIN",
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_5",
|
||||
"channel": "LL_ADC_CHANNEL_8",
|
||||
"inverted": true
|
||||
},
|
||||
{
|
||||
"name": "P1",
|
||||
"type": "FLEX",
|
||||
"adc": "MAIN",
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_1",
|
||||
"channel": "LL_ADC_CHANNEL_11",
|
||||
"label": "S1",
|
||||
"short_label": "1",
|
||||
"default": "POT"
|
||||
},
|
||||
{
|
||||
"name": "SL1",
|
||||
"type": "FLEX",
|
||||
"adc": "EXT",
|
||||
"gpio": "GPIOH",
|
||||
"pin": "LL_GPIO_PIN_2",
|
||||
"channel": "LL_ADC_CHANNEL_13",
|
||||
"label": "S2",
|
||||
"short_label": "2",
|
||||
"default": "POT"
|
||||
},
|
||||
{
|
||||
"name": "SL2",
|
||||
"type": "FLEX",
|
||||
"adc": "MAIN",
|
||||
"gpio": "GPIOA",
|
||||
"pin": "LL_GPIO_PIN_7",
|
||||
"channel": "LL_ADC_CHANNEL_7",
|
||||
"label": "S3",
|
||||
"short_label": "3",
|
||||
"default": "POT"
|
||||
},
|
||||
{
|
||||
"name": "P3",
|
||||
"type": "FLEX",
|
||||
"adc": "MAIN",
|
||||
"gpio": "GPIOB",
|
||||
"pin": "LL_GPIO_PIN_1",
|
||||
"channel": "LL_ADC_CHANNEL_5",
|
||||
"label": "S4",
|
||||
"short_label": "4",
|
||||
"default": "POT"
|
||||
},
|
||||
{
|
||||
"name": "P2",
|
||||
"type": "FLEX",
|
||||
"adc": "MAIN",
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_2",
|
||||
"channel": "LL_ADC_CHANNEL_12",
|
||||
"default": "MULTIPOS",
|
||||
"label": "6POS",
|
||||
"short_label": "6"
|
||||
},
|
||||
{
|
||||
"name": "EXT1",
|
||||
"type": "FLEX",
|
||||
"adc": "MAIN",
|
||||
"gpio": "GPIOA",
|
||||
"pin": "LL_GPIO_PIN_1",
|
||||
"channel": "LL_ADC_CHANNEL_17",
|
||||
"default": "NONE",
|
||||
"label": "EXT1",
|
||||
"short_label": "E1"
|
||||
},
|
||||
{
|
||||
"name": "EXT2",
|
||||
"type": "FLEX",
|
||||
"adc": "MAIN",
|
||||
"gpio": "GPIOA",
|
||||
"pin": "LL_GPIO_PIN_0",
|
||||
"channel": "LL_ADC_CHANNEL_16",
|
||||
"default": "NONE",
|
||||
"label": "EXT2",
|
||||
"short_label": "E2"
|
||||
},
|
||||
{
|
||||
"name": "VBAT",
|
||||
"type": "VBAT",
|
||||
"adc": "EXT",
|
||||
"gpio": "GPIOH",
|
||||
"pin": "LL_GPIO_PIN_3",
|
||||
"channel": "LL_ADC_CHANNEL_14"
|
||||
},
|
||||
{
|
||||
"name": "RTC_BAT",
|
||||
"type": "RTC_BAT",
|
||||
"adc": "EXT",
|
||||
"gpio": null,
|
||||
"pin": null,
|
||||
"channel": "LL_ADC_CHANNEL_VBAT"
|
||||
}
|
||||
]
|
||||
},
|
||||
"switches": [
|
||||
{
|
||||
"name": "SA",
|
||||
"type": "3POS",
|
||||
"flags": 0,
|
||||
"inverted": true,
|
||||
"default": "2POS",
|
||||
"display": null,
|
||||
"gpio_high": "GPIOB",
|
||||
"pin_high": "LL_GPIO_PIN_0",
|
||||
"gpio_low": "GPIOE",
|
||||
"pin_low": "LL_GPIO_PIN_4",
|
||||
"is_cfs": false
|
||||
},
|
||||
{
|
||||
"name": "SB",
|
||||
"type": "3POS",
|
||||
"flags": 0,
|
||||
"inverted": false,
|
||||
"default": "3POS",
|
||||
"display": null,
|
||||
"gpio_high": "GPIOD",
|
||||
"pin_high": "LL_GPIO_PIN_5",
|
||||
"gpio_low": "GPIOJ",
|
||||
"pin_low": "LL_GPIO_PIN_7",
|
||||
"is_cfs": false
|
||||
},
|
||||
{
|
||||
"name": "SC",
|
||||
"type": "3POS",
|
||||
"flags": 0,
|
||||
"inverted": false,
|
||||
"default": "3POS",
|
||||
"display": null,
|
||||
"gpio_high": "GPIOD",
|
||||
"pin_high": "LL_GPIO_PIN_3",
|
||||
"gpio_low": "GPIOJ",
|
||||
"pin_low": "LL_GPIO_PIN_0",
|
||||
"is_cfs": false
|
||||
},
|
||||
{
|
||||
"name": "SD",
|
||||
"type": "3POS",
|
||||
"flags": 0,
|
||||
"inverted": true,
|
||||
"default": "2POS",
|
||||
"display": null,
|
||||
"gpio_high": "GPIOD",
|
||||
"pin_high": "LL_GPIO_PIN_11",
|
||||
"gpio_low": "GPIOH",
|
||||
"pin_low": "LL_GPIO_PIN_15",
|
||||
"is_cfs": false
|
||||
},
|
||||
{
|
||||
"name": "SE",
|
||||
"type": "3POS",
|
||||
"flags": 0,
|
||||
"inverted": false,
|
||||
"default": "3POS",
|
||||
"display": null,
|
||||
"gpio_high": "GPIOE",
|
||||
"pin_high": "LL_GPIO_PIN_6",
|
||||
"gpio_low": "GPIOE",
|
||||
"pin_low": "LL_GPIO_PIN_5",
|
||||
"is_cfs": false
|
||||
},
|
||||
{
|
||||
"name": "SF",
|
||||
"type": "2POS",
|
||||
"flags": 0,
|
||||
"inverted": false,
|
||||
"default": "2POS",
|
||||
"display": null,
|
||||
"gpio": "GPIOB",
|
||||
"pin": "LL_GPIO_PIN_8",
|
||||
"is_cfs": false
|
||||
},
|
||||
{
|
||||
"name": "SG",
|
||||
"type": "2POS",
|
||||
"flags": 0,
|
||||
"inverted": false,
|
||||
"default": "TOGGLE",
|
||||
"display": null,
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_6",
|
||||
"is_cfs": false
|
||||
},
|
||||
{
|
||||
"name": "SH",
|
||||
"type": "2POS",
|
||||
"flags": 0,
|
||||
"inverted": false,
|
||||
"default": "TOGGLE",
|
||||
"display": null,
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_8",
|
||||
"is_cfs": false
|
||||
},
|
||||
{
|
||||
"name": "SI",
|
||||
"type": "2POS",
|
||||
"flags": 0,
|
||||
"inverted": false,
|
||||
"default": "2POS",
|
||||
"display": null,
|
||||
"gpio": "GPIOH",
|
||||
"pin": "LL_GPIO_PIN_14",
|
||||
"is_cfs": false
|
||||
},
|
||||
{
|
||||
"name": "SJ",
|
||||
"type": "2POS",
|
||||
"flags": 0,
|
||||
"inverted": false,
|
||||
"default": "2POS",
|
||||
"display": null,
|
||||
"gpio": "GPIOH",
|
||||
"pin": "LL_GPIO_PIN_13",
|
||||
"is_cfs": false
|
||||
}
|
||||
],
|
||||
"keys": [
|
||||
{
|
||||
"gpio": "GPIOG",
|
||||
"pin": "LL_GPIO_PIN_3",
|
||||
"active_low": true,
|
||||
"key": "KEY_EXIT",
|
||||
"name": "EXIT",
|
||||
"label": "RTN"
|
||||
},
|
||||
{
|
||||
"gpio": "GPIOG",
|
||||
"pin": "LL_GPIO_PIN_12",
|
||||
"active_low": true,
|
||||
"key": "KEY_ENTER",
|
||||
"name": "ENTER",
|
||||
"label": "Enter"
|
||||
},
|
||||
{
|
||||
"gpio": "GPIOG",
|
||||
"pin": "LL_GPIO_PIN_7",
|
||||
"active_low": true,
|
||||
"key": "KEY_PAGEUP",
|
||||
"name": "PAGEUP",
|
||||
"label": "PAGE<"
|
||||
},
|
||||
{
|
||||
"gpio": "GPIOA",
|
||||
"pin": "LL_GPIO_PIN_8",
|
||||
"active_low": true,
|
||||
"key": "KEY_PAGEDN",
|
||||
"name": "PAGEDN",
|
||||
"label": "PAGE>"
|
||||
},
|
||||
{
|
||||
"gpio": "GPIOE",
|
||||
"pin": "LL_GPIO_PIN_3",
|
||||
"active_low": true,
|
||||
"key": "KEY_MODEL",
|
||||
"name": "MDL",
|
||||
"label": "MDL"
|
||||
},
|
||||
{
|
||||
"gpio": "GPIOI",
|
||||
"pin": "LL_GPIO_PIN_15",
|
||||
"active_low": true,
|
||||
"key": "KEY_TELE",
|
||||
"name": "TELE",
|
||||
"label": "TELE"
|
||||
},
|
||||
{
|
||||
"gpio": "GPIOB",
|
||||
"pin": "LL_GPIO_PIN_2",
|
||||
"active_low": true,
|
||||
"key": "KEY_SYS",
|
||||
"name": "SYS",
|
||||
"label": "SYS"
|
||||
}
|
||||
],
|
||||
"trims": [
|
||||
{
|
||||
"name": "T1",
|
||||
"dec": {
|
||||
"gpio": "GPIOG",
|
||||
"pin": "LL_GPIO_PIN_2",
|
||||
"active_low": true
|
||||
},
|
||||
"inc": {
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_9",
|
||||
"active_low": true
|
||||
},
|
||||
"active_low": true
|
||||
},
|
||||
{
|
||||
"name": "T2",
|
||||
"dec": {
|
||||
"gpio": "GPIOB",
|
||||
"pin": "LL_GPIO_PIN_12",
|
||||
"active_low": true
|
||||
},
|
||||
"inc": {
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_10",
|
||||
"active_low": true
|
||||
},
|
||||
"active_low": true
|
||||
},
|
||||
{
|
||||
"name": "T3",
|
||||
"dec": {
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_12",
|
||||
"active_low": true
|
||||
},
|
||||
"inc": {
|
||||
"gpio": "GPIOC",
|
||||
"pin": "LL_GPIO_PIN_11",
|
||||
"active_low": true
|
||||
},
|
||||
"active_low": true
|
||||
},
|
||||
{
|
||||
"name": "T4",
|
||||
"dec": {
|
||||
"gpio": "GPIOD",
|
||||
"pin": "LL_GPIO_PIN_2",
|
||||
"active_low": true
|
||||
},
|
||||
"inc": {
|
||||
"gpio": "GPIOI",
|
||||
"pin": "LL_GPIO_PIN_9",
|
||||
"active_low": true
|
||||
},
|
||||
"active_low": true
|
||||
}
|
||||
],
|
||||
"display": {
|
||||
"lcd_w": 480,
|
||||
"lcd_h": 272,
|
||||
"lcd_phys_w": 480,
|
||||
"lcd_phys_h": 272,
|
||||
"lcd_depth": 16,
|
||||
"oled_screen": false,
|
||||
"lcd_vertical_invert": true,
|
||||
"ltdc_irq_prio": 4,
|
||||
"dma_screen_irq_prio": 6
|
||||
},
|
||||
"backlight": {
|
||||
"backlight_gpio": "GPIO_PIN(GPIOA, 10)",
|
||||
"backlight_timer": "TIM1",
|
||||
"backlight_timer_channel": "LL_TIM_CHANNEL_CH3",
|
||||
"backlight_gpio_af": "GPIO_AF1",
|
||||
"backlight_timer_freq": "(PERI2_FREQUENCY * TIMER_MULT_APB2)"
|
||||
},
|
||||
"haptic": {
|
||||
"haptic_pwm": true,
|
||||
"haptic_gpio": "GPIO_PIN(GPIOC, 7)",
|
||||
"haptic_gpio_timer": "TIM3",
|
||||
"haptic_gpio_af": "GPIO_AF2",
|
||||
"haptic_timer_output_enable": "TIM_CCER_CC2E | TIM_CCER_CC2NE",
|
||||
"haptic_timer_mode": "TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2PE",
|
||||
"haptic_timer_compare_value": "HAPTIC_GPIO_TIMER->CCR2"
|
||||
},
|
||||
"leds": {
|
||||
"status_leds": true,
|
||||
"gpio_led_gpio_on": "gpio_set",
|
||||
"gpio_led_gpio_off": "gpio_clear",
|
||||
"led_red_gpio": "GPIO_PIN(GPIOI, 8)",
|
||||
"led_green_gpio": "GPIO_PIN(GPIOI, 11)",
|
||||
"led_blue_gpio": "GPIO_PIN(GPIOI, 10)"
|
||||
},
|
||||
"timers": {
|
||||
"cpu_freq": 480000000,
|
||||
"peri1_frequency": 120000000,
|
||||
"peri2_frequency": 120000000,
|
||||
"timer_mult_apb1": 2,
|
||||
"timer_mult_apb2": 2,
|
||||
"ms_timer": "TIM14",
|
||||
"ms_timer_irqn": "TIM8_TRG_COM_TIM14_IRQn",
|
||||
"ms_timer_irqhandler": "TIM8_TRG_COM_TIM14_IRQHandler",
|
||||
"mixer_scheduler_timer": "TIM12",
|
||||
"mixer_scheduler_timer_freq": "(PERI1_FREQUENCY * TIMER_MULT_APB1)",
|
||||
"mixer_scheduler_timer_irqn": "TIM8_BRK_TIM12_IRQn",
|
||||
"mixer_scheduler_timer_irqhandler": "TIM8_BRK_TIM12_IRQHandler"
|
||||
},
|
||||
"rotenc": {
|
||||
"rotary_encoder_inverted": true,
|
||||
"rotary_encoder_gpio_a": "GPIOI",
|
||||
"rotary_encoder_gpio_pin_a": "LL_GPIO_PIN_7",
|
||||
"rotary_encoder_gpio_b": "GPIOJ",
|
||||
"rotary_encoder_gpio_pin_b": "LL_GPIO_PIN_8",
|
||||
"rotary_encoder_position": "(((ROTARY_ENCODER_GPIO_A->IDR >> 7) & 0x01)|((ROTARY_ENCODER_GPIO_B->IDR >> 7) & 0x02))",
|
||||
"rotary_encoder_exti_line1": "LL_EXTI_LINE_7",
|
||||
"rotary_encoder_exti_line2": "LL_EXTI_LINE_8",
|
||||
"exti": [
|
||||
{ "irq": "EXTI9_5_IRQ", "priority": 5 }
|
||||
],
|
||||
"rotary_encoder_exti_port_a": "LL_SYSCFG_EXTI_PORTI",
|
||||
"rotary_encoder_exti_port_b": "LL_SYSCFG_EXTI_PORTJ",
|
||||
"rotary_encoder_exti_sys_line1": "LL_SYSCFG_EXTI_LINE7",
|
||||
"rotary_encoder_exti_sys_line2": "LL_SYSCFG_EXTI_LINE8",
|
||||
"rotary_encoder_timer": "TIM17",
|
||||
"rotary_encoder_timer_irqn": "TIM17_IRQn",
|
||||
"rotary_encoder_timer_irqhandler": "TIM17_IRQHandler"
|
||||
},
|
||||
"key_lock_combo": [
|
||||
"KEY_SYS",
|
||||
"KEY_MODEL"
|
||||
],
|
||||
"hardware": {
|
||||
"has_audio_mute": true,
|
||||
"has_ext_module_support": true,
|
||||
"has_int_module_support": true,
|
||||
"sport_max_baudrate": 400000,
|
||||
"surface": false,
|
||||
"cpu": "STM32H750xB",
|
||||
"cpu_type": "STM32H7"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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/gpio.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_timer.h"
|
||||
#include "stm32_pulse_driver.h"
|
||||
|
||||
#include "edgetx_types.h"
|
||||
#include "board.h"
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
static const stm32_pulse_timer_t _bl_timer = {
|
||||
.GPIO = (gpio_t)BACKLIGHT_GPIO,
|
||||
.GPIO_Alternate = BACKLIGHT_GPIO_AF,
|
||||
.TIMx = BACKLIGHT_TIMER,
|
||||
.TIM_Freq = BACKLIGHT_TIMER_FREQ,
|
||||
.TIM_Channel = BACKLIGHT_TIMER_CHANNEL,
|
||||
.TIM_IRQn = (IRQn_Type)-1,
|
||||
.DMAx = nullptr,
|
||||
.DMA_Stream = 0,
|
||||
.DMA_Channel = 0,
|
||||
.DMA_IRQn = (IRQn_Type)-1,
|
||||
.DMA_TC_CallbackPtr = nullptr,
|
||||
};
|
||||
|
||||
void backlightLowInit()
|
||||
{
|
||||
gpio_init(BACKLIGHT_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
gpio_clear(BACKLIGHT_GPIO);
|
||||
}
|
||||
|
||||
void backlightInit()
|
||||
{
|
||||
stm32_pulse_init(&_bl_timer, 10000);
|
||||
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);
|
||||
}
|
||||
|
||||
void backlightEnable(uint8_t dutyCycle)
|
||||
{
|
||||
stm32_pulse_set_cmp_val(&_bl_timer, dutyCycle);
|
||||
}
|
||||
|
||||
void lcdOff() {
|
||||
backlightEnable(0);
|
||||
}
|
||||
|
||||
void lcdOn(){
|
||||
backlightEnable(BACKLIGHT_LEVEL_MAX);
|
||||
}
|
||||
|
||||
bool boardBacklightOn;
|
||||
|
||||
bool isBacklightEnabled()
|
||||
{
|
||||
return boardBacklightOn;
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* 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.h"
|
||||
#include "stm32_i2c_driver.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_spi.h"
|
||||
|
||||
#include "flash_driver.h"
|
||||
#include "extflash_driver.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "boards/generic_stm32/module_ports.h"
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/flash_driver.h"
|
||||
#include "hal/trainer_driver.h"
|
||||
#include "hal/rotary_encoder.h"
|
||||
#include "hal/switch_driver.h"
|
||||
#include "hal/abnormal_reboot.h"
|
||||
#include "hal/watchdog_driver.h"
|
||||
#include "hal/usb_driver.h"
|
||||
#include "hal/gpio.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "sdcard.h"
|
||||
#include "debug.h"
|
||||
#include "keys.h"
|
||||
#include "gyro.h"
|
||||
|
||||
#include "flysky_gimbal_driver.h"
|
||||
#include "timers_driver.h"
|
||||
|
||||
#include "touch_driver.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// common ADC driver
|
||||
extern const etx_hal_adc_driver_t _adc_driver;
|
||||
|
||||
void INTERNAL_MODULE_ON()
|
||||
{
|
||||
gpio_set(INTMODULE_PWR_GPIO);
|
||||
}
|
||||
|
||||
void INTERNAL_MODULE_OFF()
|
||||
{
|
||||
gpio_clear(INTMODULE_PWR_GPIO);
|
||||
}
|
||||
|
||||
void EXTERNAL_MODULE_ON()
|
||||
{
|
||||
gpio_set(EXTMODULE_PWR_GPIO);
|
||||
}
|
||||
|
||||
void EXTERNAL_MODULE_OFF()
|
||||
{
|
||||
gpio_clear(EXTMODULE_PWR_GPIO);
|
||||
}
|
||||
|
||||
void boardBLEarlyInit()
|
||||
{
|
||||
timersInit();
|
||||
#if defined(USB_CHARGER)
|
||||
usbChargerInit();
|
||||
#endif
|
||||
}
|
||||
|
||||
void boardBLPreJump()
|
||||
{
|
||||
ExtFLASH_Init();
|
||||
SDRAM_Init();
|
||||
|
||||
// Stop 1ms timer
|
||||
MS_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
void boardBLInit()
|
||||
{
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
rotaryEncoderInit();
|
||||
#endif
|
||||
|
||||
ExtFLASH_Init();
|
||||
SDRAM_Init();
|
||||
|
||||
// register external FLASH for DFU
|
||||
usbRegisterDFUMedia((void*)extflash_dfu_media);
|
||||
|
||||
// register internal & external FLASH for UF2
|
||||
flashRegisterDriver(FLASH_BANK1_BASE, BOOTLOADER_SIZE, &stm32_flash_driver);
|
||||
flashRegisterDriver(QSPI_BASE, 8 * 1024 * 1024, &extflash_driver);
|
||||
}
|
||||
|
||||
void boardInit()
|
||||
{
|
||||
// enable interrupts
|
||||
__enable_irq();
|
||||
|
||||
ledInit();
|
||||
boardInitModulePorts();
|
||||
|
||||
pwrInit();
|
||||
delaysInit();
|
||||
timersInit();
|
||||
|
||||
#if !defined(POWER_LED_BLUE)
|
||||
ledBlue();
|
||||
#else
|
||||
ledGreen();
|
||||
#endif
|
||||
|
||||
ExtFLASH_InitRuntime();
|
||||
|
||||
// register internal & external FLASH for UF2
|
||||
flashRegisterDriver(FLASH_BANK1_BASE, BOOTLOADER_SIZE, &stm32_flash_driver);
|
||||
flashRegisterDriver(QSPI_BASE, QSPI_FLASH_SIZE, &extflash_driver);
|
||||
|
||||
#if defined(FLYSKY_GIMBAL)
|
||||
auto inittime = flysky_gimbal_init();
|
||||
if (inittime)
|
||||
TRACE("Serial gimbal detected in %d ms", inittime);
|
||||
else
|
||||
TRACE("No serial gimbal detected");
|
||||
#endif
|
||||
|
||||
usbInit();
|
||||
|
||||
#if !defined(DEBUG_SEGGER_RTT)
|
||||
// This is needed to prevent radio from starting when usb is plugged to charge
|
||||
if (!UNEXPECTED_SHUTDOWN() && usbPlugged()) {
|
||||
while (usbPlugged() && !pwrPressed()) {
|
||||
delay_ms(1000);
|
||||
}
|
||||
if (!pwrPressed()) {
|
||||
pwrOff();
|
||||
// Wait power to drain
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
keysInit();
|
||||
switchInit();
|
||||
rotaryEncoderInit();
|
||||
touchPanelInit();
|
||||
audioInit();
|
||||
adcInit(&_adc_driver);
|
||||
hapticInit();
|
||||
|
||||
rtcInit(); // RTC must be initialized before rambackupRestore() is called
|
||||
}
|
||||
|
||||
extern void rtcDisableBackupReg();
|
||||
|
||||
void boardOff()
|
||||
{
|
||||
lcdOff();
|
||||
|
||||
while (pwrPressed()) {
|
||||
WDG_RESET();
|
||||
}
|
||||
|
||||
SysTick->CTRL = 0; // turn off systick
|
||||
|
||||
// Shutdown the Haptic
|
||||
hapticDone();
|
||||
|
||||
rtcDisableBackupReg();
|
||||
|
||||
pwrOff();
|
||||
|
||||
// We reach here only in forced power situations, such as hw-debugging with external power
|
||||
// Enter STM32 stop mode / deep-sleep
|
||||
// Code snippet from ST Nucleo PWR_EnterStopMode example
|
||||
#define PDMode 0x00000000U
|
||||
#if defined(PWR_CR1_MRUDS) && defined(PWR_CR1_LPUDS) && defined(PWR_CR1_FPDS)
|
||||
MODIFY_REG(PWR->CR1, (PWR_CR1_PDDS | PWR_CR1_LPDS | PWR_CR1_FPDS | PWR_CR1_LPUDS | PWR_CR1_MRUDS), PDMode);
|
||||
#elif defined(PWR_CR_MRLVDS) && defined(PWR_CR_LPLVDS) && defined(PWR_CR_FPDS)
|
||||
MODIFY_REG(PWR->CR1, (PWR_CR1_PDDS | PWR_CR1_LPDS | PWR_CR1_FPDS | PWR_CR1_LPLVDS | PWR_CR1_MRLVDS), PDMode);
|
||||
#else
|
||||
// MODIFY_REG(PWR->CR1, (PWR_CR1_P_PDDS| PWR_CR1_LPDS), PDMode);
|
||||
#endif /* PWR_CR_MRUDS && PWR_CR_LPUDS && PWR_CR_FPDS */
|
||||
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
||||
|
||||
// To avoid HardFault at return address, end in an endless loop
|
||||
while (1) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
#include "definitions.h"
|
||||
#include "edgetx_constants.h"
|
||||
|
||||
#include "board_common.h"
|
||||
#include "hal.h"
|
||||
#include "hal/serial_port.h"
|
||||
#include "hal/watchdog_driver.h"
|
||||
|
||||
#define FLASHSIZE 0x1000000
|
||||
#define BOOTLOADER_SIZE 0x10000
|
||||
#define BOOTLOADER_ADDRESS 0x08000000
|
||||
#define FIRMWARE_ADDRESS 0x90000000
|
||||
#define FIRMWARE_LEN(fsize) (fsize)
|
||||
#define FIRMWARE_MAX_LEN FLASHSIZE
|
||||
#define APP_START_ADDRESS (uint32_t)(FIRMWARE_ADDRESS)
|
||||
|
||||
#define BOOTLOADER_KEYS 0x42
|
||||
|
||||
#define MB *1024*1024
|
||||
#define LUA_MEM_EXTRA_MAX (2 MB) // max allowed memory usage for Lua bitmaps (in bytes)
|
||||
#define LUA_MEM_MAX (6 MB) // max allowed memory usage for complete Lua (in bytes), 0 means unlimited
|
||||
|
||||
extern uint16_t sessionTimer;
|
||||
|
||||
#define SLAVE_MODE() (g_model.trainerData.mode == TRAINER_MODE_SLAVE)
|
||||
|
||||
// Board driver
|
||||
void boardInit();
|
||||
void boardOff();
|
||||
|
||||
// CPU Unique ID
|
||||
#define LEN_CPU_UID (3*8+2)
|
||||
void getCPUUniqueID(char * s);
|
||||
|
||||
// Flash Write driver
|
||||
#define FLASH_PAGESIZE 256
|
||||
void unlockFlash();
|
||||
void lockFlash();
|
||||
void flashWrite(uint32_t * address, const uint32_t * buffer);
|
||||
uint32_t isFirmwareStart(const uint8_t * buffer);
|
||||
uint32_t isBootloaderStart(const uint8_t * buffer);
|
||||
|
||||
// SDRAM driver
|
||||
extern "C" void SDRAM_Init();
|
||||
|
||||
// Pulses driver
|
||||
#if !defined(SIMU)
|
||||
|
||||
void INTERNAL_MODULE_ON();
|
||||
void INTERNAL_MODULE_OFF();
|
||||
void EXTERNAL_MODULE_ON();
|
||||
void EXTERNAL_MODULE_OFF();
|
||||
#define EXTERNAL_MODULE_PWR_OFF EXTERNAL_MODULE_OFF
|
||||
#define BLUETOOTH_MODULE_ON() gpio_clear(BLUETOOTH_ON_GPIO)
|
||||
#define BLUETOOTH_MODULE_OFF() gpio_set(BLUETOOTH_ON_GPIO)
|
||||
#define IS_INTERNAL_MODULE_ON() (false)
|
||||
#define IS_EXTERNAL_MODULE_ON() (gpio_read(EXTMODULE_PWR_GPIO) ? 1 : 0)
|
||||
|
||||
#else
|
||||
|
||||
#define INTERNAL_MODULE_OFF()
|
||||
#define INTERNAL_MODULE_ON()
|
||||
#define EXTERNAL_MODULE_ON()
|
||||
#define EXTERNAL_MODULE_OFF()
|
||||
#define BLUETOOTH_MODULE_ON()
|
||||
#define BLUETOOTH_MODULE_OFF()
|
||||
#define IS_INTERNAL_MODULE_ON() (false)
|
||||
#define IS_EXTERNAL_MODULE_ON() (false)
|
||||
|
||||
#endif // defined(SIMU)
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#define NUM_FUNCTIONS_SWITCHES 6
|
||||
#define NUM_FUNCTIONS_GROUPS 3
|
||||
#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
|
||||
|
||||
#else
|
||||
#define NUM_FUNCTIONS_SWITCHES 0
|
||||
#endif
|
||||
|
||||
#define NUM_TRIMS 8
|
||||
#define DEFAULT_STICK_DEADZONE 2
|
||||
|
||||
#define BATTERY_WARN 74 // 7.4V
|
||||
#define BATTERY_MIN 70 // 6.8V
|
||||
#define BATTERY_MAX 86 // 8.6V
|
||||
|
||||
// --- MOSFET ---- R1 --- MCU
|
||||
// |__ R2 --- GND
|
||||
//
|
||||
#define VBAT_DIV_R1 120 // kOhms
|
||||
#define VBAT_DIV_R2 39 // kOhms
|
||||
#define VBAT_MOSFET_DROP 0 // * 10mV
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Power driver
|
||||
#define SOFT_PWR_CTRL
|
||||
#define POWER_ON_DELAY 10 // 1s
|
||||
void pwrInit();
|
||||
void extModuleInit();
|
||||
uint32_t pwrCheck();
|
||||
uint32_t lowPowerCheck();
|
||||
|
||||
void pwrOn();
|
||||
void pwrSoftReboot();
|
||||
void pwrOff();
|
||||
void pwrResetHandler();
|
||||
bool pwrPressed();
|
||||
bool pwrOffPressed();
|
||||
#if defined(PWR_EXTRA_SWITCH_GPIO)
|
||||
bool pwrForcePressed();
|
||||
#else
|
||||
#define pwrForcePressed() false
|
||||
#endif
|
||||
uint32_t pwrPressedDuration();;
|
||||
|
||||
const etx_serial_port_t* auxSerialGetPort(int port_nr);
|
||||
#define AUX_SERIAL_POWER_ON()
|
||||
#define AUX_SERIAL_POWER_OFF()
|
||||
|
||||
// LED driver
|
||||
void ledInit();
|
||||
void ledOff();
|
||||
void ledRed();
|
||||
void ledBlue();
|
||||
void ledGreen();
|
||||
|
||||
// LCD driver
|
||||
void lcdSetInitalFrameBuffer(void* fbAddress);
|
||||
void lcdInit();
|
||||
void lcdCopy(void * dest, void * src);
|
||||
|
||||
void lcdOff();
|
||||
void lcdOn();
|
||||
|
||||
#define lcdRefreshWait(...)
|
||||
|
||||
// Backlight driver
|
||||
#define BACKLIGHT_LEVEL_MAX 100
|
||||
#define BACKLIGHT_FORCED_ON BACKLIGHT_LEVEL_MAX + 1
|
||||
#define BACKLIGHT_LEVEL_MIN 35
|
||||
|
||||
extern bool boardBacklightOn;
|
||||
void backlightLowInit( void );
|
||||
void backlightInit();
|
||||
void backlightEnable(uint8_t dutyCycle);
|
||||
void backlightFullOn();
|
||||
bool isBacklightEnabled();
|
||||
|
||||
#define BACKLIGHT_ENABLE() \
|
||||
{ \
|
||||
boardBacklightOn = true; \
|
||||
backlightEnable(BACKLIGHT_LEVEL_MAX - currentBacklightBright); \
|
||||
}
|
||||
|
||||
#define BACKLIGHT_DISABLE() \
|
||||
{ \
|
||||
boardBacklightOn = false; \
|
||||
backlightEnable(((g_eeGeneral.blOffBright == BACKLIGHT_LEVEL_MIN) && \
|
||||
(g_eeGeneral.backlightMode != e_backlight_mode_off)) \
|
||||
? 0 \
|
||||
: g_eeGeneral.blOffBright); \
|
||||
}
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Audio driver
|
||||
void audioInit();
|
||||
void audioConsumeCurrentBuffer();
|
||||
|
||||
#define audioDisableIrq() // interrupts must stay enabled on Horus
|
||||
#define audioEnableIrq() // interrupts must stay enabled on Horus
|
||||
#define setSampleRate(freq)
|
||||
void setScaledVolume(uint8_t volume);
|
||||
void setVolume(uint8_t volume);
|
||||
int32_t getVolume();
|
||||
#define VOLUME_LEVEL_MAX 23
|
||||
#define VOLUME_LEVEL_DEF 12
|
||||
|
||||
// Telemetry driver
|
||||
#define INTMODULE_FIFO_SIZE 512
|
||||
#define TELEMETRY_FIFO_SIZE 512
|
||||
|
||||
// Haptic driver
|
||||
void hapticInit();
|
||||
void hapticDone();
|
||||
void hapticOff();
|
||||
void hapticOn(uint32_t pwmPercent);
|
||||
|
||||
// Second serial port driver
|
||||
//#define AUX_SERIAL
|
||||
#define DEBUG_BAUDRATE 115200
|
||||
#define LUA_DEFAULT_BAUDRATE 115200
|
||||
|
||||
extern uint8_t currentTrainerMode;
|
||||
void checkTrainerSettings();
|
||||
|
||||
// Touch panel driver
|
||||
bool touchPanelEventOccured();
|
||||
struct TouchState touchPanelRead();
|
||||
struct TouchState getInternalTouchState();
|
||||
|
||||
// USB Charger
|
||||
#if defined(USB_CHARGER)
|
||||
void usbChargerInit();
|
||||
bool usbChargerLed();
|
||||
#endif
|
||||
|
||||
#endif // _BOARD_H_
|
||||
@@ -0,0 +1,154 @@
|
||||
#include "extflash_driver.h"
|
||||
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_qspi.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#define QSPI_NOR_PAGE_SIZE 256
|
||||
|
||||
int32_t ExtFLASH_Init()
|
||||
{
|
||||
if (stm32_qspi_nor_init() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return stm32_qspi_nor_memory_mapped();
|
||||
}
|
||||
|
||||
void ExtFLASH_InitRuntime() { stm32_qspi_no_init_runtime(); }
|
||||
|
||||
//
|
||||
// ETX HAL flash interface
|
||||
//
|
||||
|
||||
static uint32_t extflash_get_size_kb()
|
||||
{
|
||||
return QSPI_FLASH_SIZE / 1024;
|
||||
}
|
||||
|
||||
static uint32_t extflash_get_sector(uint32_t address)
|
||||
{
|
||||
address -= QSPI_BASE;
|
||||
return address / (64 * 1024);
|
||||
}
|
||||
|
||||
static uint32_t extflash_get_sector_size(uint32_t sector)
|
||||
{
|
||||
(void)sector;
|
||||
return (64 * 1024);
|
||||
}
|
||||
|
||||
static int extflash_erase_sector(uint32_t address)
|
||||
{
|
||||
address -= QSPI_BASE;
|
||||
return stm32_qspi_nor_erase_sector(address);
|
||||
}
|
||||
|
||||
static int extflash_program(uint32_t address, void* data, uint32_t len)
|
||||
{
|
||||
address -= QSPI_BASE;
|
||||
|
||||
int ret = 0;
|
||||
while (len > 0) {
|
||||
uint32_t size = (len > QSPI_NOR_PAGE_SIZE) ? QSPI_NOR_PAGE_SIZE : len;
|
||||
ret = stm32_qspi_nor_program(address, data, size);
|
||||
if (ret != 0) break;
|
||||
len -= size;
|
||||
address += size;
|
||||
data = (uint8_t*)data + size;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int extflash_read(uint32_t address, void* data, uint32_t len)
|
||||
{
|
||||
address -= QSPI_BASE;
|
||||
return stm32_qspi_nor_read(address, data, len);
|
||||
}
|
||||
|
||||
const etx_flash_driver_t extflash_driver = {
|
||||
.get_size_kb = extflash_get_size_kb,
|
||||
.get_sector = extflash_get_sector,
|
||||
.get_sector_size = extflash_get_sector_size,
|
||||
.erase_sector = extflash_erase_sector,
|
||||
.program = extflash_program,
|
||||
.read = extflash_read,
|
||||
};
|
||||
|
||||
#if defined(BOOT)
|
||||
//
|
||||
// USB DFU interface
|
||||
//
|
||||
#include "usbd_dfu.h"
|
||||
|
||||
#define MEDIA_DESC_STR "@External Flash /0x90000000/128*064Kg"
|
||||
|
||||
static uint16_t extflash_dfu_init()
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
static uint16_t extflash_dfu_deinit()
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
static uint16_t extflash_dfu_erase(uint32_t address)
|
||||
{
|
||||
if (extflash_erase_sector(address) < 0) {
|
||||
return USBD_FAIL;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
static uint16_t extflash_dfu_write(uint8_t* src, uint8_t* dest, uint32_t len)
|
||||
{
|
||||
if (extflash_program((intptr_t)dest, (void*)src, len) < 0) {
|
||||
return USBD_FAIL;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
static uint8_t* extflash_dfu_read(uint8_t* src, uint8_t* dest, uint32_t len)
|
||||
{
|
||||
if (extflash_read((intptr_t)src, (void*)dest, len) < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
static uint16_t extflash_dfu_get_status(uint32_t address, uint8_t cmd, uint8_t *buffer)
|
||||
{
|
||||
switch (cmd) {
|
||||
case DFU_MEDIA_PROGRAM:
|
||||
buffer[1] = 1;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
break;
|
||||
|
||||
case DFU_MEDIA_ERASE:
|
||||
default:
|
||||
buffer[1] = 20;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
const USBD_DFU_MediaTypeDef _extflash_dfu_media = {
|
||||
.pStrDesc = (uint8_t*)MEDIA_DESC_STR,
|
||||
.Init = extflash_dfu_init,
|
||||
.DeInit = extflash_dfu_deinit,
|
||||
.Erase = extflash_dfu_erase,
|
||||
.Write = extflash_dfu_write,
|
||||
.Read = extflash_dfu_read,
|
||||
.GetStatus = extflash_dfu_get_status,
|
||||
};
|
||||
|
||||
const void* extflash_dfu_media = &_extflash_dfu_media;
|
||||
|
||||
#endif // BOOT
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* 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 "hal/flash_driver.h"
|
||||
|
||||
extern const etx_flash_driver_t extflash_driver;
|
||||
extern const void* extflash_dfu_media;
|
||||
|
||||
// init external FLASH hardware
|
||||
int32_t ExtFLASH_Init();
|
||||
|
||||
// init only runtime structures
|
||||
void ExtFLASH_InitRuntime();
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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/gpio.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_timer.h"
|
||||
#include "stm32_pulse_driver.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#define HAPTIC_TIMER_FREQ 200000000
|
||||
|
||||
static const stm32_pulse_timer_t _haptic_timer = {
|
||||
.GPIO = (gpio_t)HAPTIC_GPIO,
|
||||
.GPIO_Alternate = HAPTIC_GPIO_AF,
|
||||
.TIMx = HAPTIC_GPIO_TIMER,
|
||||
.TIM_Freq = HAPTIC_TIMER_FREQ,
|
||||
.TIM_Channel = LL_TIM_CHANNEL_CH2,
|
||||
.TIM_IRQn = (IRQn_Type)-1,
|
||||
.DMAx = nullptr,
|
||||
.DMA_Stream = 0,
|
||||
.DMA_Channel = 0,
|
||||
.DMA_IRQn = (IRQn_Type)-1,
|
||||
.DMA_TC_CallbackPtr = nullptr,
|
||||
};
|
||||
|
||||
void hapticInit(void)
|
||||
{
|
||||
stm32_pulse_init(&_haptic_timer, 10000);
|
||||
stm32_pulse_config_output(&_haptic_timer, true, LL_TIM_OCMODE_PWM1, 0);
|
||||
LL_TIM_SetAutoReload(_haptic_timer.TIMx, 100);
|
||||
LL_TIM_EnableCounter(_haptic_timer.TIMx);
|
||||
}
|
||||
|
||||
void hapticOn(uint32_t pwmPercent)
|
||||
{
|
||||
if (pwmPercent > 100) pwmPercent = 100;
|
||||
stm32_pulse_set_cmp_val(&_haptic_timer, pwmPercent);
|
||||
}
|
||||
|
||||
void hapticOff(void) { hapticOn(0); }
|
||||
void hapticDone(void) { hapticOff(); }
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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/key_driver.h"
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "stm32_i2c_driver.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "delays_driver.h"
|
||||
#include "keys.h"
|
||||
|
||||
#include "stm32_keys.inc"
|
||||
#include "debug.h"
|
||||
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
* 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.h"
|
||||
#include "board.h"
|
||||
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
#include "hal/gpio.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_qspi.h"
|
||||
|
||||
uint8_t TouchControllerType = 0; // 0: other; 1: CST836U
|
||||
static volatile uint16_t lcd_phys_w = LCD_PHYS_W;
|
||||
static volatile uint16_t lcd_phys_h = LCD_PHYS_H;
|
||||
|
||||
static LTDC_HandleTypeDef hltdc;
|
||||
static void* initialFrameBuffer = nullptr;
|
||||
|
||||
static volatile uint8_t _frame_addr_reloaded = 0;
|
||||
|
||||
#if defined(LCD_VERTICAL_INVERT)
|
||||
// The H17 panel is mounted upside-down, exactly like the tx16s/horus panel.
|
||||
// LTDC cannot rotate, so we software-rotate every refreshed area 180 into a
|
||||
// dedicated back buffer and swap it in on the last flush of a frame. Mirrors
|
||||
// radio/src/targets/horus/lcd_driver.cpp.
|
||||
typedef uint16_t pixel_t;
|
||||
static pixel_t _LCD_BUF_1[DISPLAY_BUFFER_SIZE] __SDRAM;
|
||||
static pixel_t _LCD_BUF_2[DISPLAY_BUFFER_SIZE] __SDRAM;
|
||||
|
||||
static pixel_t _line_buffer[LCD_W];
|
||||
|
||||
static uint16_t* _front_buffer = _LCD_BUF_1;
|
||||
static uint16_t* _back_buffer = _LCD_BUF_2;
|
||||
|
||||
// Copy 2 pixels at once to speed up a little
|
||||
static void _copy_rotate_180(uint16_t* dst, uint16_t* src, const rect_t& copy_area)
|
||||
{
|
||||
coord_t x1 = LCD_W - copy_area.w - copy_area.x;
|
||||
coord_t y1 = LCD_H - copy_area.h - copy_area.y;
|
||||
|
||||
src += copy_area.w - 2;
|
||||
dst += (y1 + copy_area.h - 1) * LCD_W + x1;
|
||||
|
||||
for (auto line = 0; line < copy_area.h; line++) {
|
||||
|
||||
// invert line into _line_buffer first (SRAM)
|
||||
auto px_dst = _line_buffer;
|
||||
|
||||
auto line_end = px_dst + (copy_area.w & ~1);
|
||||
while (px_dst != line_end) {
|
||||
uint32_t* px2_src = (uint32_t*)src;
|
||||
|
||||
*((uint32_t*)px_dst) = ((*px2_src & 0xFFFF0000) >> 16) | ((*px2_src & 0xFFFF) << 16);
|
||||
|
||||
src -= 2;
|
||||
px_dst += 2;
|
||||
}
|
||||
|
||||
if (copy_area.w & 1) {
|
||||
*px_dst = *(src+1);
|
||||
src--;
|
||||
}
|
||||
|
||||
// ... and DMA back into SDRAM
|
||||
DMACopyBitmap(dst, copy_area.w, 1, 0, 0,
|
||||
_line_buffer, copy_area.w, 1, 0, 0,
|
||||
copy_area.w, 1);
|
||||
|
||||
src += copy_area.w * 2;
|
||||
dst -= LCD_W;
|
||||
}
|
||||
}
|
||||
|
||||
static void _rotate_area_180(lv_area_t& area)
|
||||
{
|
||||
lv_coord_t tmp_coord;
|
||||
tmp_coord = area.y2;
|
||||
area.y2 = LCD_H - area.y1 - 1;
|
||||
area.y1 = LCD_H - tmp_coord - 1;
|
||||
tmp_coord = area.x2;
|
||||
area.x2 = LCD_W - area.x1 - 1;
|
||||
area.x1 = LCD_W - tmp_coord - 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void _update_frame_buffer_addr(uint16_t* buffer)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer,
|
||||
const rect_t ©_area)
|
||||
{
|
||||
#if defined(LCD_VERTICAL_INVERT)
|
||||
_copy_rotate_180(_back_buffer, buffer, copy_area);
|
||||
|
||||
if (lv_disp_flush_is_last(disp_drv)) {
|
||||
|
||||
// swap back/front
|
||||
if (_front_buffer == _LCD_BUF_1) {
|
||||
_front_buffer = _LCD_BUF_2;
|
||||
_back_buffer = _LCD_BUF_1;
|
||||
} else {
|
||||
_front_buffer = _LCD_BUF_1;
|
||||
_back_buffer = _LCD_BUF_2;
|
||||
}
|
||||
|
||||
// Trigger async refresh
|
||||
_update_frame_buffer_addr(_front_buffer);
|
||||
|
||||
// Copy refreshed & rotated areas into new back buffer
|
||||
uint16_t* src = _front_buffer;
|
||||
uint16_t* dst = _back_buffer;
|
||||
|
||||
lv_disp_t* disp = _lv_refr_get_disp_refreshing();
|
||||
for(int i = 0; i < disp->inv_p; i++) {
|
||||
if(disp->inv_area_joined[i]) continue;
|
||||
|
||||
lv_area_t refr_area;
|
||||
lv_area_copy(&refr_area, &disp->inv_areas[i]);
|
||||
|
||||
_rotate_area_180(refr_area);
|
||||
|
||||
auto area_w = refr_area.x2 - refr_area.x1 + 1;
|
||||
auto area_h = refr_area.y2 - refr_area.y1 + 1;
|
||||
|
||||
DMACopyBitmap(dst, LCD_W, LCD_H, refr_area.x1, refr_area.y1,
|
||||
src, LCD_W, LCD_H, refr_area.x1, refr_area.y1,
|
||||
area_w, area_h);
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void)disp_drv;
|
||||
(void)copy_area;
|
||||
|
||||
_update_frame_buffer_addr(buffer);
|
||||
#endif
|
||||
|
||||
// Since #7483 the shared LVGL flush path (gui/colorlcd/lcd.cpp) no longer
|
||||
// signals completion after invoking the flush callback; the driver must call
|
||||
// lcdFlushed() itself, otherwise LVGL's flush stays pending forever and the
|
||||
// UI freezes on the first frame (e.g. stuck on the boot logo).
|
||||
lcdFlushed();
|
||||
}
|
||||
|
||||
// LTDC RGB666 data + sync lines (all on AF14). Layout matches the tx15/rm-h750
|
||||
// panel wiring: PI12-14 (HSYNC/VSYNC/CLK), PJ1-6 (R2-R7), PJ9-11 + PK0-2
|
||||
// (G2-G7), PJ14-15 + PK3-6 (B2-B7), PK7 (DE).
|
||||
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),
|
||||
};
|
||||
|
||||
static void LCD_AF_GPIOConfig(void)
|
||||
{
|
||||
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 lcdResetConfig(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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/* LTDC pixel clock is driven from PLL3R (see system_clock.c) */
|
||||
|
||||
/* 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.
|
||||
tx16s/horus drives this panel with IPC (non-inverted); jumper-h750 used
|
||||
IIPC for a different panel. */
|
||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
||||
|
||||
/* 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 */
|
||||
#if defined(LCD_VERTICAL_INVERT)
|
||||
layer.FBStartAdress = (intptr_t)_LCD_BUF_1;
|
||||
#else
|
||||
layer.FBStartAdress = (intptr_t)initialFrameBuffer;
|
||||
#endif
|
||||
|
||||
/* 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_VERTICAL_INVERT)
|
||||
// Clear buffers first
|
||||
memset(_LCD_BUF_1, 0, sizeof(_LCD_BUF_1));
|
||||
memset(_LCD_BUF_2, 0, sizeof(_LCD_BUF_2));
|
||||
#endif
|
||||
|
||||
/* Configure the LCD reset pin */
|
||||
lcdResetConfig();
|
||||
|
||||
/* Reset the LCD --------------------------------------------------------*/
|
||||
lcdReset();
|
||||
|
||||
/* Configure the LTDC RGB control pins */
|
||||
LCD_AF_GPIOConfig();
|
||||
|
||||
TRACE("LCD INIT: parallel RGB (LTDC)");
|
||||
boardLcdType = "RGB (LTDC)";
|
||||
|
||||
__HAL_RCC_LTDC_CLK_ENABLE();
|
||||
|
||||
LCD_Init_LTDC();
|
||||
LCD_LayerInit();
|
||||
|
||||
// Enable LCD display
|
||||
__HAL_LTDC_ENABLE(&hltdc);
|
||||
|
||||
lcdSetFlushCb(startLcdRefresh);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __LCD_DRIVER_H__
|
||||
#define __LCD_DRIVER_H__
|
||||
|
||||
// H17 uses a parallel RGB (LTDC) panel with no MCU-side SPI configuration bus.
|
||||
// Only the LTDC data/sync lines and the panel reset line (LCD_RESET_GPIO) are
|
||||
// wired, so the SPI bit-bang init/read path used by the RadioMaster boards is
|
||||
// intentionally absent here.
|
||||
|
||||
// Timings taken from the horus/tx16s driver, which drives this same panel.
|
||||
// Values are in this board's raw-porch convention (lcd_driver.cpp subtracts 1
|
||||
// and accumulates), and reproduce the exact LTDC register values horus programs:
|
||||
// HSync=2 AccHBP=42 AccActiveW=522 TotalWidth=525
|
||||
// VSync=10 AccVBP=12 AccActiveH=284 TotalHeigh=286
|
||||
#define HBP ( 40 )
|
||||
#define VBP ( 2 )
|
||||
|
||||
#define HSW ( 3 )
|
||||
#define VSH ( 11 )
|
||||
|
||||
#define HFP ( 3 )
|
||||
#define VFP ( 2 )
|
||||
|
||||
#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)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* 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/gpio.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#define SDRAM_MEMORY_WIDTH FMC_SDRAM_MEM_BUS_WIDTH_16
|
||||
|
||||
#define SDRAM_CAS_LATENCY FMC_SDRAM_CAS_LATENCY_3
|
||||
|
||||
#define SDCLOCK_PERIOD FMC_SDRAM_CLOCK_PERIOD_2
|
||||
|
||||
#define SDRAM_TIMEOUT ((uint32_t)0xFFFF)
|
||||
|
||||
#define SDRAM_READBURST FMC_SDRAM_RBURST_DISABLE
|
||||
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_1 ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_2 ((uint16_t)0x0001)
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_4 ((uint16_t)0x0002)
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_8 ((uint16_t)0x0004)
|
||||
#define SDRAM_MODEREG_BURST_FULL_PAGE ((uint16_t)0x0007)
|
||||
#define SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_BURST_TYPE_INTERLEAVED ((uint16_t)0x0008)
|
||||
#define SDRAM_MODEREG_CAS_LATENCY_1 ((uint16_t)0x0010)
|
||||
#define SDRAM_MODEREG_CAS_LATENCY_2 ((uint16_t)0x0020)
|
||||
#define SDRAM_MODEREG_CAS_LATENCY_3 ((uint16_t)0x0030)
|
||||
#define SDRAM_MODEREG_OPERATING_MODE_STANDARD ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_WRITEBURST_MODE_PROGRAMMED ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_WRITEBURST_MODE_SINGLE ((uint16_t)0x0200)
|
||||
|
||||
#define GPIO_AF_FMC GPIO_AF12
|
||||
|
||||
extern "C" void SDRAM_GPIOConfig(void)
|
||||
{
|
||||
/*-- GPIOs Configuration -----------------------------------------------------*/
|
||||
/*
|
||||
*/
|
||||
|
||||
/* GPIOC configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOC, 0), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH); // FMC_SDNWE (RAM_WE)
|
||||
|
||||
/* GPIOD configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 0), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 1), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 8), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 9), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 10), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 14), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 15), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
|
||||
/* GPIOE configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 0), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 1), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 7), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 8), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 9), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 10), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 11), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 12), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 13), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 14), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 15), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
|
||||
/* GPIOF configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 0), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 1), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 2), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 3), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 4), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 5), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 11), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 12), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 13), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 14), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 15), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
|
||||
/* 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);
|
||||
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);
|
||||
gpio_init_af(GPIO_PIN(GPIOG, 15), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
|
||||
// NB: PH5 is USB_VBUS on this board, NOT FMC_SDNWE (write-enable is on PC0).
|
||||
// Only PH6 (FMC_SDNE1 / RAM_CS) and PH7 (FMC_SDCKE1 / RAM_CKE) are FMC here.
|
||||
gpio_init_af(GPIO_PIN(GPIOH, 6), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOH, 7), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
|
||||
}
|
||||
|
||||
extern "C" void SDRAM_InitSequence(void)
|
||||
{
|
||||
FMC_SDRAM_CommandTypeDef FMC_SDRAMCommandStructure;
|
||||
uint32_t tmpr = 0;
|
||||
|
||||
/* Step 3 --------------------------------------------------------------------*/
|
||||
/* Configure a clock configuration enable command */
|
||||
FMC_SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_CLK_ENABLE;
|
||||
FMC_SDRAMCommandStructure.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
|
||||
FMC_SDRAMCommandStructure.AutoRefreshNumber = 1;
|
||||
FMC_SDRAMCommandStructure.ModeRegisterDefinition = 0;
|
||||
/* Send the command */
|
||||
FMC_SDRAM_SendCommand(FMC_Bank5_6_R, &FMC_SDRAMCommandStructure, 10);
|
||||
|
||||
/* Step 4 --------------------------------------------------------------------*/
|
||||
/* Insert 1 ms delay */
|
||||
delay_ms(100);
|
||||
|
||||
/* Step 5 --------------------------------------------------------------------*/
|
||||
/* Configure a PALL (precharge all) command */
|
||||
FMC_SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_PALL;
|
||||
FMC_SDRAMCommandStructure.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
|
||||
FMC_SDRAMCommandStructure.AutoRefreshNumber = 1;
|
||||
FMC_SDRAMCommandStructure.ModeRegisterDefinition = 0;
|
||||
/* Send the command */
|
||||
FMC_SDRAM_SendCommand(FMC_Bank5_6_R, &FMC_SDRAMCommandStructure, 10);
|
||||
|
||||
/* Step 6 --------------------------------------------------------------------*/
|
||||
/* Configure a Auto-Refresh command */
|
||||
FMC_SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
|
||||
FMC_SDRAMCommandStructure.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
|
||||
FMC_SDRAMCommandStructure.AutoRefreshNumber = 8;
|
||||
FMC_SDRAMCommandStructure.ModeRegisterDefinition = 0;
|
||||
/* Send the command */
|
||||
FMC_SDRAM_SendCommand(FMC_Bank5_6_R, &FMC_SDRAMCommandStructure, 10);
|
||||
|
||||
/* Step 7 --------------------------------------------------------------------*/
|
||||
/* Program the external memory mode register */
|
||||
tmpr = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 |
|
||||
SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL |
|
||||
SDRAM_MODEREG_CAS_LATENCY_3 |
|
||||
SDRAM_MODEREG_OPERATING_MODE_STANDARD |
|
||||
SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
|
||||
|
||||
/* Configure a load Mode register command*/
|
||||
FMC_SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_LOAD_MODE;
|
||||
FMC_SDRAMCommandStructure.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
|
||||
FMC_SDRAMCommandStructure.AutoRefreshNumber = 1;
|
||||
FMC_SDRAMCommandStructure.ModeRegisterDefinition = tmpr;
|
||||
/* Send the command */
|
||||
FMC_SDRAM_SendCommand(FMC_Bank5_6_R, &FMC_SDRAMCommandStructure, 10);
|
||||
|
||||
/* Step 8 --------------------------------------------------------------------*/
|
||||
/* Set the refresh rate counter */
|
||||
/* (15.62 us x Freq) - 20 */
|
||||
/* Set the device refresh counter */
|
||||
FMC_SDRAM_SetAutoRefreshNumber(FMC_Bank5_6_R, 15);
|
||||
FMC_SDRAM_ProgramRefreshRate(FMC_Bank5_6_R, 2479);
|
||||
}
|
||||
|
||||
extern "C" void SDRAM_Init(void)
|
||||
{
|
||||
//delay funcion needed
|
||||
delaysInit();
|
||||
|
||||
/* GPIO configuration for FMC SDRAM bank */
|
||||
SDRAM_GPIOConfig();
|
||||
|
||||
/* Enable FMC clock */
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_FMC);
|
||||
|
||||
/* FMC Configuration ---------------------------------------------------------*/
|
||||
FMC_SDRAM_InitTypeDef FMC_SDRAMInitStructure;
|
||||
FMC_SDRAM_TimingTypeDef FMC_SDRAMTimingInitStructure;
|
||||
|
||||
/* FMC SDRAM Bank configuration */
|
||||
FMC_SDRAMTimingInitStructure.LoadToActiveDelay = 3; // tMRD
|
||||
FMC_SDRAMTimingInitStructure.ExitSelfRefreshDelay = 11; // tXSR = 70ns
|
||||
FMC_SDRAMTimingInitStructure.SelfRefreshTime = 7; // tRAS = 42ns
|
||||
FMC_SDRAMTimingInitStructure.RowCycleDelay = 10; // tRC = 60ns
|
||||
FMC_SDRAMTimingInitStructure.WriteRecoveryTime = 2; // tWR
|
||||
FMC_SDRAMTimingInitStructure.RPDelay = 3; // tRP = 18ns
|
||||
FMC_SDRAMTimingInitStructure.RCDDelay = 3; // tRCD = 18ns
|
||||
|
||||
/* FMC SDRAM control configuration */
|
||||
FMC_SDRAMInitStructure.SDBank = FMC_SDRAM_BANK2;
|
||||
FMC_SDRAMInitStructure.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
||||
FMC_SDRAMInitStructure.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
||||
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;
|
||||
FMC_SDRAMInitStructure.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
||||
FMC_SDRAMInitStructure.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_3;
|
||||
FMC_SDRAMInitStructure.ReadBurst = FMC_SDRAM_RBURST_ENABLE;
|
||||
FMC_SDRAMInitStructure.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;
|
||||
|
||||
/* FMC SDRAM bank initialization */
|
||||
FMC_SDRAM_Init(FMC_Bank5_6_R, &FMC_SDRAMInitStructure);
|
||||
FMC_SDRAM_Timing_Init(FMC_Bank5_6_R, &FMC_SDRAMTimingInitStructure, FMC_SDRAM_BANK2);
|
||||
|
||||
__FMC_ENABLE();
|
||||
|
||||
/* FMC SDRAM device initialization sequence */
|
||||
SDRAM_InitSequence();
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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 "stm32h7xx_ll_pwr.h"
|
||||
#include "stm32h7xx_ll_rcc.h"
|
||||
#include "stm32h7xx_ll_system.h"
|
||||
#include "stm32h7xx_ll_bus.h"
|
||||
|
||||
#define BOOTSTRAP __attribute__((section(".bootstrap")))
|
||||
|
||||
BOOTSTRAP void SystemClock_Config(void)
|
||||
{
|
||||
/* Power Configuration */
|
||||
LL_PWR_ConfigSupply(LL_PWR_LDO_SUPPLY);
|
||||
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
|
||||
while (LL_PWR_IsActiveFlag_VOS() == 0){
|
||||
}
|
||||
|
||||
/* Enable HSE oscillator */
|
||||
LL_RCC_HSE_Enable();
|
||||
while (LL_RCC_HSE_IsReady() != 1) {
|
||||
}
|
||||
|
||||
/* Set FLASH latency */
|
||||
LL_FLASH_SetLatency(LL_FLASH_LATENCY_5);
|
||||
|
||||
/* Main PLL configuration and activation */
|
||||
LL_RCC_PLL_SetSource(LL_RCC_PLLSOURCE_HSE);
|
||||
LL_RCC_PLL1P_Enable();
|
||||
LL_RCC_PLL1Q_Enable();
|
||||
LL_RCC_PLL1R_Enable();
|
||||
LL_RCC_PLL1FRACN_Disable();
|
||||
LL_RCC_PLL1_SetVCOInputRange(LL_RCC_PLLINPUTRANGE_2_4);
|
||||
LL_RCC_PLL1_SetVCOOutputRange(LL_RCC_PLLVCORANGE_WIDE);
|
||||
// HSE = 48 MHz. M=12 -> 4 MHz PFD input (matches RANGE_2_4). VCO = 4*240 =
|
||||
// 960 MHz. Outputs unchanged from the previous (out-of-range M=3/N=60) config:
|
||||
// P=2 -> 480 MHz sysclk, Q=20 -> 48 MHz (USB/SPI), R=2 -> 480 MHz.
|
||||
LL_RCC_PLL1_SetM(12);
|
||||
LL_RCC_PLL1_SetN(240);
|
||||
LL_RCC_PLL1_SetP(2);
|
||||
LL_RCC_PLL1_SetQ(20);
|
||||
LL_RCC_PLL1_SetR(2);
|
||||
LL_RCC_PLL1_Enable();
|
||||
while (LL_RCC_PLL1_IsReady() != 1) {
|
||||
}
|
||||
|
||||
/* Set Sys & AHB & APB1 & APB2 & APB4 prescaler */
|
||||
LL_RCC_SetSysPrescaler(LL_RCC_SYSCLK_DIV_1);
|
||||
LL_RCC_SetAHBPrescaler(LL_RCC_AHB_DIV_2);
|
||||
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
|
||||
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_2);
|
||||
LL_RCC_SetAPB4Prescaler(LL_RCC_APB4_DIV_2);
|
||||
|
||||
/* Set PLL1 as System Clock Source */
|
||||
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1);
|
||||
while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL1) {
|
||||
}
|
||||
|
||||
/* Config & activate PLL2 */
|
||||
LL_RCC_PLL2P_Enable();
|
||||
LL_RCC_PLL2FRACN_Disable();
|
||||
LL_RCC_PLL2_SetVCOInputRange(LL_RCC_PLLINPUTRANGE_2_4);
|
||||
LL_RCC_PLL2_SetVCOOutputRange(LL_RCC_PLLVCORANGE_WIDE);
|
||||
LL_RCC_PLL2_SetM(24);
|
||||
LL_RCC_PLL2_SetN(96);
|
||||
LL_RCC_PLL2_SetP(17); // 11.294 MHz
|
||||
LL_RCC_PLL2_Enable();
|
||||
while (LL_RCC_PLL2_IsReady() != 1) {
|
||||
}
|
||||
|
||||
/* Config & activate PLL3 */
|
||||
LL_RCC_PLL3P_Enable();
|
||||
LL_RCC_PLL3Q_Enable();
|
||||
LL_RCC_PLL3R_Enable();
|
||||
LL_RCC_PLL3FRACN_Disable();
|
||||
LL_RCC_PLL3_SetVCOInputRange(LL_RCC_PLLINPUTRANGE_2_4);
|
||||
LL_RCC_PLL3_SetVCOOutputRange(LL_RCC_PLLVCORANGE_WIDE);
|
||||
// HSE = 48 MHz. Previous M=1 gave a 48 MHz PFD input (3x over the 16 MHz PLL
|
||||
// input max) so PLL3 could not lock -> no LTDC pixel clock. M=12 -> 4 MHz
|
||||
// input (matches RANGE_2_4). VCO = 4*48 = 192 MHz, identical to before:
|
||||
// P=2 -> 96 MHz, Q=2 -> 96 MHz, R=18 -> ~10.67 MHz LTDC pixel clock.
|
||||
LL_RCC_PLL3_SetM(12);
|
||||
LL_RCC_PLL3_SetN(48);
|
||||
LL_RCC_PLL3_SetP(2);
|
||||
LL_RCC_PLL3_SetQ(2);
|
||||
LL_RCC_PLL3_SetR(18);
|
||||
LL_RCC_PLL3_Enable();
|
||||
while (LL_RCC_PLL3_IsReady() != 1) {
|
||||
}
|
||||
|
||||
/* Enable SRAM1, SRAM2 & SRAM3 */
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_D2SRAM1 |
|
||||
LL_AHB2_GRP1_PERIPH_D2SRAM2 |
|
||||
LL_AHB2_GRP1_PERIPH_D2SRAM3);
|
||||
|
||||
/* Set periph clock sources */
|
||||
LL_RCC_SetSPIClockSource(LL_RCC_SPI123_CLKSOURCE_PLL1Q);
|
||||
LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLL1Q);
|
||||
LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_CLKP);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
void SystemClock_Config();
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 "touch.h"
|
||||
|
||||
extern void touchPanelDeInit();
|
||||
extern bool touchPanelInit();
|
||||
|
||||
struct TouchState touchPanelRead();
|
||||
bool touchPanelEventOccured();
|
||||
struct TouchState getInternalTouchState();
|
||||
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
* 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/gpio.h"
|
||||
#include "hal/i2c_driver.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_i2c_driver.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "stm32_exti_driver.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "timers_driver.h"
|
||||
#include "tp_gt911.h"
|
||||
#include "delays_driver.h"
|
||||
|
||||
#include "os/sleep.h"
|
||||
#include "edgetx_types.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TP_GT911_ID "911"
|
||||
|
||||
|
||||
bool touchGT911Flag = false;
|
||||
volatile static bool touchEventOccured = false;
|
||||
struct TouchData touchData;
|
||||
uint16_t touchGT911fwver = 0;
|
||||
uint32_t touchGT911hiccups = 0;
|
||||
|
||||
static tmr10ms_t downTime = 0;
|
||||
static tmr10ms_t tapTime = 0;
|
||||
static short tapCount = 0;
|
||||
|
||||
static TouchState internalTouchState = {};
|
||||
|
||||
static void _gt911_exti_isr(void)
|
||||
{
|
||||
touchEventOccured = true;
|
||||
}
|
||||
|
||||
void I2C_Init_Radio(void)
|
||||
{
|
||||
TRACE("GT911 I2C Init");
|
||||
|
||||
if (i2c_init(TOUCH_I2C_BUS) < 0) {
|
||||
TRACE("GT911 ERROR: i2c_init failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool I2C_GT911_WriteRegister(uint16_t reg, uint8_t *buf, uint8_t len)
|
||||
{
|
||||
uint8_t uAddrAndBuf[258];
|
||||
uAddrAndBuf[0] = (uint8_t)((reg & 0xFF00) >> 8);
|
||||
uAddrAndBuf[1] = (uint8_t)(reg & 0x00FF);
|
||||
|
||||
if (len > 0) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
uAddrAndBuf[i + 2] = buf[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (stm32_i2c_master_tx(TOUCH_I2C_BUS, GT911_I2C_ADDR, uAddrAndBuf, len + 2,
|
||||
100) < 0) {
|
||||
TRACE("I2C B1 ERROR: WriteRegister failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool I2C_GT911_ReadRegister(uint16_t reg, uint8_t *buf, uint8_t len)
|
||||
{
|
||||
uint8_t uRegAddr[2];
|
||||
uRegAddr[0] = (uint8_t)((reg & 0xFF00) >> 8);
|
||||
uRegAddr[1] = (uint8_t)(reg & 0x00FF);
|
||||
|
||||
if (stm32_i2c_master_tx(TOUCH_I2C_BUS, GT911_I2C_ADDR, uRegAddr, 2, 10) < 0) {
|
||||
TRACE("I2C B1 ERROR: ReadRegister write reg address failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stm32_i2c_master_rx(TOUCH_I2C_BUS, GT911_I2C_ADDR, buf, len, 100) < 0) {
|
||||
TRACE("I2C B1 ERROR: ReadRegister read reg address failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void touchPanelDeInit(void)
|
||||
{
|
||||
gpio_int_disable(TOUCH_INT_GPIO);
|
||||
touchGT911Flag = false;
|
||||
}
|
||||
|
||||
uint8_t tp_gt911_cfgVer = GT911_CFG_NUMBER;
|
||||
|
||||
bool touchPanelInit(void)
|
||||
{
|
||||
uint8_t tmp[4] = {0};
|
||||
|
||||
if (touchGT911Flag) {
|
||||
gpio_init_int(TOUCH_INT_GPIO, GPIO_IN_PU, GPIO_RISING, _gt911_exti_isr);
|
||||
return true;
|
||||
} else {
|
||||
TRACE("Touchpanel init start ...");
|
||||
|
||||
gpio_init(TOUCH_RST_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
gpio_init(TOUCH_INT_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
I2C_Init_Radio();
|
||||
|
||||
gpio_clear(TOUCH_RST_GPIO);
|
||||
gpio_set(TOUCH_INT_GPIO);
|
||||
delay_us(200);
|
||||
|
||||
gpio_set(TOUCH_RST_GPIO);
|
||||
delay_ms(6);
|
||||
|
||||
gpio_clear(TOUCH_INT_GPIO);
|
||||
delay_ms(55);
|
||||
|
||||
gpio_init(TOUCH_INT_GPIO, GPIO_IN_PU, GPIO_PIN_SPEED_LOW);
|
||||
|
||||
delay_ms(50);
|
||||
|
||||
TRACE("Reading Touch registry");
|
||||
if (!I2C_GT911_ReadRegister(GT911_PRODUCT_ID_REG, tmp, 4)) {
|
||||
TRACE("GT911 ERROR: Product ID read failed");
|
||||
}
|
||||
|
||||
if (strcmp((char *)tmp, TP_GT911_ID) == 0) {
|
||||
TRACE("GT911 chip detected");
|
||||
tmp[0] = 0X02;
|
||||
if (!I2C_GT911_WriteRegister(GT911_COMMAND_REG, tmp, 1)) {
|
||||
TRACE("GT911 ERROR: write to control register failed");
|
||||
}
|
||||
if (!I2C_GT911_ReadRegister(GT911_CONFIG_REG, tmp, 1)) {
|
||||
TRACE("GT911 ERROR: configuration register read failed");
|
||||
}
|
||||
|
||||
TRACE("Chip config Ver:%x", tmp[0]);
|
||||
if ((tp_gt911_cfgVer == 0) || (tmp[0] < tp_gt911_cfgVer)) { // Config ver
|
||||
TRACE("Sending new config %d", GT911_CFG_NUMBER);
|
||||
if (!I2C_GT911_ReadRegister(GT911_CONFIG_REG, tmp, 1)) {
|
||||
TRACE("GT911 ERROR: configuration register read failed");
|
||||
}
|
||||
tp_gt911_cfgVer = tmp[0];
|
||||
}
|
||||
|
||||
if (!I2C_GT911_ReadRegister(GT911_FIRMWARE_VERSION_REG, tmp, 2)) {
|
||||
TRACE("GT911 ERROR: reading firmware version failed");
|
||||
} else {
|
||||
touchGT911fwver = (tmp[1] << 8) + tmp[0];
|
||||
TRACE("GT911 FW version: %u", touchGT911fwver);
|
||||
}
|
||||
|
||||
delay_ms(10);
|
||||
tmp[0] = 0X00;
|
||||
if (!I2C_GT911_WriteRegister(GT911_COMMAND_REG, tmp, 1)) { // end reset
|
||||
TRACE("GT911 ERROR: write to command register failed");
|
||||
}
|
||||
touchGT911Flag = true;
|
||||
|
||||
gpio_init_int(TOUCH_INT_GPIO, GPIO_IN_PU, GPIO_RISING, _gt911_exti_isr);
|
||||
|
||||
return true;
|
||||
}
|
||||
TRACE("GT911 chip NOT FOUND");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool I2C_ReInit(void)
|
||||
{
|
||||
TRACE("I2C B1 ReInit");
|
||||
touchPanelDeInit();
|
||||
if (stm32_i2c_deinit(TOUCH_I2C_BUS) < 0)
|
||||
TRACE("I2C B1 ReInit - I2C DeInit failed");
|
||||
|
||||
// If DeInit fails, try to re-init anyway
|
||||
if (!touchPanelInit()) {
|
||||
TRACE("I2C B1 ReInit - touchPanelInit failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(SIMU) || defined(SEMIHOSTING) || defined(DEBUG)
|
||||
static const char *event2str(uint8_t ev)
|
||||
{
|
||||
switch (ev) {
|
||||
case TE_NONE:
|
||||
return "NONE";
|
||||
case TE_UP:
|
||||
return "UP";
|
||||
case TE_DOWN:
|
||||
return "DOWN";
|
||||
case TE_SLIDE_END:
|
||||
return "SLIDE_END";
|
||||
case TE_SLIDE:
|
||||
return "SLIDE";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
struct TouchState touchPanelRead()
|
||||
{
|
||||
uint8_t state = 0;
|
||||
|
||||
if (!touchEventOccured) return internalTouchState;
|
||||
|
||||
touchEventOccured = false;
|
||||
|
||||
uint32_t startReadStatus = timersGetMsTick();
|
||||
do {
|
||||
if (!I2C_GT911_ReadRegister(GT911_READ_XY_REG, &state, 1)) {
|
||||
touchGT911hiccups++;
|
||||
TRACE("GT911 I2C read XY error");
|
||||
if (!I2C_ReInit()) TRACE("I2C B1 ReInit failed");
|
||||
return internalTouchState;
|
||||
}
|
||||
|
||||
if (state & 0x80u) {
|
||||
// ready
|
||||
break;
|
||||
}
|
||||
sleep_ms(1);
|
||||
} while (timersGetMsTick() - startReadStatus < GT911_TIMEOUT);
|
||||
|
||||
internalTouchState.deltaX = 0;
|
||||
internalTouchState.deltaY = 0;
|
||||
TRACE("touch state = 0x%x", state);
|
||||
if (state & 0x80u) {
|
||||
uint8_t pointsCount = (state & 0x0Fu);
|
||||
uint32_t now = timersGetMsTick();
|
||||
internalTouchState.tapCount = 0;
|
||||
|
||||
if (pointsCount > 0 && pointsCount <= GT911_MAX_TP) {
|
||||
if (!I2C_GT911_ReadRegister(GT911_READ_XY_REG + 1, touchData.data,
|
||||
pointsCount * sizeof(TouchPoint))) {
|
||||
touchGT911hiccups++;
|
||||
TRACE("GT911 I2C data read error");
|
||||
if (!I2C_ReInit()) TRACE("I2C B1 ReInit failed");
|
||||
return internalTouchState;
|
||||
}
|
||||
|
||||
#if defined(LCD_VERTICAL_INVERT)
|
||||
// Panel (and thus the GT911) is mounted upside-down, matching the 180
|
||||
// display rotation in lcd_driver.cpp. Flip the reported coordinates so
|
||||
// touches line up with what is drawn.
|
||||
for (uint8_t i = 0; i < pointsCount; i++) {
|
||||
touchData.points[i].x = LCD_W - 1 - touchData.points[i].x;
|
||||
touchData.points[i].y = LCD_H - 1 - touchData.points[i].y;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (internalTouchState.event == TE_NONE ||
|
||||
internalTouchState.event == TE_UP ||
|
||||
internalTouchState.event == TE_SLIDE_END) {
|
||||
internalTouchState.event = TE_DOWN;
|
||||
internalTouchState.startX = internalTouchState.x =
|
||||
touchData.points[0].x;
|
||||
internalTouchState.startY = internalTouchState.y =
|
||||
touchData.points[0].y;
|
||||
downTime = now;
|
||||
} else {
|
||||
internalTouchState.deltaX =
|
||||
touchData.points[0].x - internalTouchState.x;
|
||||
internalTouchState.deltaY =
|
||||
touchData.points[0].y - internalTouchState.y;
|
||||
if (internalTouchState.event == TE_SLIDE ||
|
||||
abs(internalTouchState.deltaX) >= SLIDE_RANGE ||
|
||||
abs(internalTouchState.deltaY) >= SLIDE_RANGE) {
|
||||
internalTouchState.event = TE_SLIDE;
|
||||
internalTouchState.x = touchData.points[0].x;
|
||||
internalTouchState.y = touchData.points[0].y;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (internalTouchState.event == TE_SLIDE) {
|
||||
internalTouchState.event = TE_SLIDE_END;
|
||||
} else if (internalTouchState.event == TE_DOWN) {
|
||||
internalTouchState.event = TE_UP;
|
||||
if (now - downTime <= GT911_TAP_TIME) {
|
||||
if (now - tapTime > GT911_TAP_TIME)
|
||||
tapCount = 1;
|
||||
else
|
||||
tapCount++;
|
||||
internalTouchState.tapCount = tapCount;
|
||||
tapTime = now;
|
||||
}
|
||||
} else {
|
||||
internalTouchState.event = TE_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t zero = 0;
|
||||
if (!I2C_GT911_WriteRegister(GT911_READ_XY_REG, &zero, 1)) {
|
||||
TRACE("GT911 ERROR: clearing XY register failed");
|
||||
}
|
||||
|
||||
TRACE("touch event = %s", event2str(internalTouchState.event));
|
||||
return internalTouchState;
|
||||
}
|
||||
|
||||
bool touchPanelEventOccured()
|
||||
{
|
||||
return touchEventOccured;
|
||||
}
|
||||
|
||||
TouchState getInternalTouchState()
|
||||
{
|
||||
return internalTouchState;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 "touch.h"
|
||||
#include "definitions.h"
|
||||
|
||||
#define HAS_TOUCH_PANEL() (touchGT911Flag == true)
|
||||
|
||||
extern bool touchGT911Flag;
|
||||
extern uint16_t touchGT911fwver;
|
||||
extern uint32_t touchGT911hiccups;
|
||||
|
||||
extern void touchPanelDeInit();
|
||||
extern bool touchPanelInit();
|
||||
|
||||
struct TouchState touchPanelRead();
|
||||
bool touchPanelEventOccured();
|
||||
struct TouchState getInternalTouchState();
|
||||
|
||||
#define GT911_TIMEOUT 3 // 3ms
|
||||
#define GT911_TAP_TIME 250 // 250 ms
|
||||
|
||||
#define GT911_MAX_TP 5
|
||||
|
||||
#define GT911_CFG_NUMBER 0x6D
|
||||
|
||||
//I2C
|
||||
#define GT911_I2C_ADDR 0x14
|
||||
|
||||
//#define GT_CMD_WR 0x28
|
||||
//#define GT_CMD_RD 0x29
|
||||
//#define I2C_TIMEOUT_MAX 1000
|
||||
|
||||
#define GT911_COMMAND_REG 0x8040
|
||||
#define GT911_CONFIG_REG 0x8047
|
||||
#define GT911_COORDINATE_REG 0x804D
|
||||
#define GT911_CONFIG_CHECKSUM_REG 0x80FF
|
||||
|
||||
#define GT911_PRODUCT_ID_REG 0x8140
|
||||
#define GT911_FIRMWARE_VERSION_REG 0x8144
|
||||
#define GT911_VENDOR_ID_REG 0x814A
|
||||
#define GT911_READ_XY_REG 0x814E
|
||||
#define GT911_TP1_REG 0x8150
|
||||
#define GT911_TP2_REG 0x8158
|
||||
#define GT911_TP3_REG 0x8160
|
||||
#define GT911_TP4_REG 0x8168
|
||||
#define GT911_TP5_REG 0x8170
|
||||
|
||||
PACK(typedef struct {
|
||||
uint8_t track;
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
uint16_t size;
|
||||
uint8_t reserved;
|
||||
}) TouchPoint;
|
||||
|
||||
PACK(struct TouchData {
|
||||
union
|
||||
{
|
||||
TouchPoint points[GT911_MAX_TP];
|
||||
uint8_t data[GT911_MAX_TP * sizeof(TouchPoint)];
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user