feat(v12): support for HelloRadioSky V12 (#7114)

Co-authored-by: Peter Feerick <5500713+pfeerick@users.noreply.github.com>
Co-authored-by: radiosky <839034809@qq.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
richardclli
2026-08-05 14:57:46 +10:00
committed by GitHub
co-authored by Peter Feerick radiosky Claude Sonnet 5
parent 256dc98917
commit 866ee0a92e
93 changed files with 4582 additions and 406 deletions
@@ -58,6 +58,16 @@ static const stm32_i2c_hw_def_t _i2c2 = {
};
#endif
#if defined(I2C_B4)
static const stm32_i2c_hw_def_t _i2c4 = {
.I2Cx = I2C_B4,
.SCL_GPIO = (gpio_t)I2C_B4_SCL_GPIO,
.SDA_GPIO = (gpio_t)I2C_B4_SDA_GPIO,
.GPIO_AF = I2C_B4_GPIO_AF,
.set_pwr = nullptr,
};
#endif
int i2c_init(etx_i2c_bus_t bus)
{
#if defined(I2C_B1)
@@ -72,6 +82,12 @@ int i2c_init(etx_i2c_bus_t bus)
}
#endif
#if defined(I2C_B4)
if (bus == I2C_Bus_4) {
return stm32_i2c_init(I2C_Bus_4, I2C_B4_CLK_RATE, &_i2c4);
}
#endif
return -1;
}
@@ -89,6 +105,12 @@ int i2c_deinit(etx_i2c_bus_t bus)
}
#endif
#if defined(I2C_B4)
if (bus == I2C_Bus_4) {
return stm32_i2c_deinit(I2C_Bus_4);
}
#endif
return -1;
}
+4 -1
View File
@@ -48,7 +48,10 @@
static uint8_t _last_adc_state = 0;
static volatile uint8_t _six_pos_state = 0;
void sixPosUpdateFromAdc()
// Called whenever the sticky 6POS position changes. Boards that need to
// map position to a switch-expander state (e.g. FUNCTION_SWITCHES) can
// override this to react to position changes without polling adcValues[].
__attribute__((weak)) void sixPosUpdateFromAdc()
{
uint16_t* values = getAnalogValues();
uint16_t adcValue = values[SIXPOS_SWITCH_INDEX];
@@ -0,0 +1,94 @@
/*
* 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);
}
uint8_t lastDutyCycle = 0;
void backlightEnable(uint8_t dutyCycle)
{
stm32_pulse_set_cmp_val(&_bl_timer, dutyCycle);
// TODO: removed until QSPI & LCD SPI are split
// if(!dutyCycle) {
// //experimental to turn off LCD when no backlight
// // if(lcdOffFunction) lcdOffFunction();
// }
// else if(!lastDutyCycle) {
// // if(lcdOnFunction) lcdOnFunction();
// // else lcdInit();
// }
// lastDutyCycle = dutyCycle;
}
void lcdOff() {
backlightEnable(0);
}
void lcdOn(){
// if(lcdOnFunction) lcdOnFunction();
// else lcdInit();
backlightEnable(BACKLIGHT_LEVEL_MAX);
}
bool boardBacklightOn;
bool isBacklightEnabled()
{
return boardBacklightOn;
}
+419
View File
@@ -0,0 +1,419 @@
/*
* 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 "boards/generic_stm32/rgb_leds.h"
#include "stm32_switch_driver.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 "flysky_gimbal_driver.h"
#include "timers_driver.h"
#include "bitmapbuffer.h"
#include "colors.h"
// #include "touch_driver.h"
#include <string.h>
// common ADC driver
extern const etx_hal_adc_driver_t _adc_driver;
#if defined(SIXPOS_SWITCH_INDEX)
#if defined(FUNCTION_SWITCHES)
extern const stm32_switch_t* boardGetSwitchDef(uint8_t idx);
extern SwitchHwPos stm32_switch_get_position(const stm32_switch_t* sw);
extern uint8_t isSwitch3Pos(uint8_t idx);
struct _adckey_switches_expander {
uint8_t state;
};
// Bitmask of all 6 function switch bits
#define FS_ALL_BITS 0x3F
// For each 6POS position (0=none, 1-6=SW1-SW6): bit of the active switch,
// inverted so active switch pin reads low (DOWN) like real PCA95xx hardware.
// position 0 (none): all bits set = all UP
// position N: all bits set except SW_N's bit = SW_N is DOWN
static uint8_t _pos_to_state(uint8_t pos)
{
if (pos == 0) return FS_ALL_BITS;
uint8_t active_bit = (1 << (pos - 1));
return FS_ALL_BITS & ~active_bit;
}
static _adckey_switches_expander _adckey_switches = { FS_ALL_BITS };
// Called whenever the sticky 6POS position changes. Boards that need to
// map position to a switch-expander state (e.g. FUNCTION_SWITCHES) can
// override this to react to position changes without polling adcValues[].
void sixPosUpdateFromAdc()
{
uint16_t* values = getAnalogValues();
uint16_t adcValue = values[SIXPOS_SWITCH_INDEX];
uint8_t current = 0;
if (adcValue > 3800) current = 1;
else if (adcValue > 3100) current = 2;
else if (adcValue > 2300) current = 3;
else if (adcValue > 1500) current = 4;
else if (adcValue > 1000) current = 5;
else if (adcValue > 400) current = 6;
static uint8_t lastSeen = 0;
static uint8_t debounce = 0;
static uint8_t sixPosState = 0;
if (current != lastSeen) {
lastSeen = current;
debounce = 2; // require this many more stable samples before committing
} else if (debounce > 0) {
if (--debounce == 0) {
// Switch state always reflects the true debounced position
_adckey_switches.state = _pos_to_state(current);
if (current != 0) {
// Indicator value stays sticky on the last active position
sixPosState = current;
}
}
}
values[SIXPOS_SWITCH_INDEX] = sixPosState ? (4096 / 5) * (7 - sixPosState) : 0;
}
static SwitchHwPos _get_switch_pos(uint8_t idx)
{
SwitchHwPos pos = SWITCH_HW_UP;
const stm32_switch_t* def = boardGetSwitchDef(idx);
uint8_t state = _adckey_switches.state;
if (def->isCustomSwitch) {
if ((state & def->Pin_high) == 0) {
return SWITCH_HW_DOWN;
} else {
return SWITCH_HW_UP;
}
}
else if (!def->Pin_low) {
// 2POS switch
if ((state & def->Pin_high) != 0) {
pos = SWITCH_HW_DOWN;
}
} else {
bool hi = state & def->Pin_high;
bool lo = state & def->Pin_low;
if(!isSwitch3Pos(idx))
{
// Switch not declared as 3POS installed in a 3POS HW
if (!(hi && lo)) {
pos = SWITCH_HW_DOWN;
}
} else if (hi && lo) {
pos = SWITCH_HW_MID;
} else if (!hi && lo) {
pos = SWITCH_HW_DOWN;
}
}
return pos;
}
static SwitchHwPos _get_fs_switch_pos(uint8_t idx)
{
const stm32_switch_t* def = boardGetSwitchDef(idx);
uint8_t state = _adckey_switches.state;
if ((state & def->Pin_high) == 0) {
return SWITCH_HW_DOWN;
} else {
return SWITCH_HW_UP;
}
}
bool boardIsCustomSwitch(uint8_t idx);
SwitchHwPos boardSwitchGetPosition(uint8_t idx)
{
if (boardIsCustomSwitch(idx)) {
return _get_fs_switch_pos(idx);
} else if (boardGetSwitchDef(idx)->GPIOx_high != nullptr) {
return stm32_switch_get_position(boardGetSwitchDef(idx));
} else {
return _get_switch_pos(idx);
}
}
#endif
#endif
static void led_strip_off()
{
rgbLedClearAll();
rgbLedColorApply();
}
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 INTMODULE_ANTSEL_EXT()
{
gpio_set(INTMODULE_ANTSEL_GPIO);
}
void INTMODULE_ANTSEL_INT()
{
gpio_clear(INTMODULE_ANTSEL_GPIO);
}
void boardBLEarlyInit()
{
timersInit();
usbChargerInit();
}
void boardBLPreJump()
{
ExtFLASH_Init();
SDRAM_Init();
// Stop 1ms timer
MS_TIMER->CR1 &= ~TIM_CR1_CEN;
}
void boardBLInit()
{
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 USBCharger(uint32_t usbchgstatus)
{
// USB Charger init code can be added here if needed
static uint32_t usbchgmode=0;
if(usbchgstatus>10){
rgbLedClearAll();
rgbLedColorApply();
return;
}
switch (++usbchgmode) {
case 1:
rgbSetLedColor(0, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
break;
case 2:
rgbSetLedColor(1, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
break;
case 3:
rgbSetLedColor(2, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
break;
case 4:
rgbSetLedColor(3, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
break;
case 5:
rgbSetLedColor(4, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
break;
case 6:
rgbSetLedColor(5, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
break;
case 7:
usbchgmode=0;
rgbLedClearAll();
break;
default:
break;
}
rgbLedColorApply();
}
void boardInit()
{
// enable interrupts
__enable_irq();
ledInit();
boardInitModulePorts();
pwrInit();
delaysInit();
timersInit();
usbChargerInit();
gpio_set(LED_BLUE_GPIO);
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);
usbInit();
rgbLedInit();
led_strip_off();
#if !defined(DEBUG_SEGGER_RTT)
static uint32_t usbchgstatus=0;
// This is needed to prevent radio from starting when usb is plugged to charge
if (usbPlugged()) {
while (usbPlugged() && !pwrPressed()) {//charging loop
delay_ms(500);
USBCharger(usbchgstatus);
if (IS_UCHARGER_ACTIVE()) {
/* code */
ledRed();
usbchgstatus=0;
}
else{
ledGreen();
usbchgstatus++;
}
}
if (!pwrPressed()) {
pwrOff();
// Wait power to drain
while (true) {
}
}
}
#endif
rgbLedInit();
led_strip_off();
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();
#if !defined(BOOT)
rgbLedClearAll();
while (pwrPressed()) {
WDG_RESET();
}
if (IS_UCHARGER_ACTIVE()||usbPlugged())
{
while (pwrPressed()) {
WDG_RESET();
}
// RTC->BKP0R = SOFTRESET_REQUEST;
NVIC_SystemReset();
}
#endif
// RTC->BKP0R = SHUTDOWN_REQUEST;
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) {
}
}
+272
View File
@@ -0,0 +1,272 @@
/*
* 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 0x800000
#define FLASH_PAGESIZE 256
#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 INTMODULE_ANTSEL_EXT();
void INTMODULE_ANTSEL_INT();
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() (gpio_read(INTMODULE_PWR_GPIO) ? 1 : 0)
#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 100 // kOhms
#define VBAT_DIV_R2 56 // kOhms
#define VBAT_MOSFET_DROP 10 // * 10mV
// #define BATTERY_DIVIDER 1211 // = 2047 * 165k / (165k + 680k) * 10 / 3.3V
#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 1
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
#define IS_UCHARGER_ACTIVE() !gpio_read(UCHARGER_GPIO) ? 1 : 0
#define IS_UCHARGER_CHARGE_END_ACTIVE() gpio_read(UCHARGER_CHARGE_END_GPIO) ? 0 : 1
#define ENABLE_UCHARGER() bsp_output_set(BSP_CHARGE_EN);
#define DISABLE_UCHARGER() bsp_output_clear(BSP_CHARGE_EN)
// Audio driver
class stm32_spi_t;
struct AudioConfig_t
{
stm32_spi_t* spi;
void (*setMuteHigh)();
void (*setMuteLow)();
void (*setResetHigh)();
void (*setResetLow)();
};
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,423 @@
/*
* 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 "lcd_driver.h"
#include "stm32_gpio.h"
#include "stm32_spi.h"
#include "delays_driver.h"
#include "hal/gpio.h"
#include "lcd.h"
#include "hal.h"
#include "board.h"
#define LCD_NRST_HIGH() gpio_set(LCD_NRST)
#define LCD_NRST_LOW() gpio_clear(LCD_NRST)
#define LCD_COMMAND_MODE() gpio_clear(LCD_SPI_RS)
#define LCD_DATA_MODE() gpio_set(LCD_SPI_RS)
#define CASET 0x2A
#define RASET 0x2B
#define RAMWR 0x2C
static const stm32_spi_t lcdSpi = {
.SPIx = LCD_SPI,
.SCK = LCD_SPI_CLK,
.MISO = LCD_SPI_MISO,
.MOSI = LCD_SPI_MOSI,
.CS = LCD_SPI_CS,
.DMA = LCD_SPI_DMA,
.txDMA_PeriphRequest = LCD_SPI_TX_DMA,
.rxDMA_PeriphRequest = LCD_SPI_RX_DMA,
.txDMA_Stream = LCD_SPI_TX_DMA_STREAM,
.rxDMA_Stream = LCD_SPI_RX_DMA_STREAM,
};
static void* initialFrameBuffer = nullptr;
static void write_start_end(uint8_t cmd, uint16_t start, uint16_t end)
{
// big endian format
uint8_t buf[4] = {
(uint8_t)(start >> 8),
(uint8_t)(start & 0xFF),
(uint8_t)(end >> 8),
(uint8_t)(end & 0xFF),
};
stm32_spi_select(&lcdSpi);
LCD_COMMAND_MODE();
stm32_spi_transfer_byte(&lcdSpi, cmd);
LCD_DATA_MODE();
stm32_spi_transfer_bytes(&lcdSpi, (uint8_t *)buf, nullptr, sizeof(buf));
stm32_spi_unselect(&lcdSpi);
}
static inline void set_column_addr(uint16_t xs, uint16_t xe)
{
write_start_end(CASET, xs, xe);
}
static inline void set_row_addr(uint16_t ys, uint16_t ye)
{
write_start_end(RASET, ys, ye);
}
static void memory_write(const uint16_t* data, uint32_t length)
{
stm32_spi_select(&lcdSpi);
LCD_COMMAND_MODE();
stm32_spi_transfer_byte(&lcdSpi, RAMWR);
LCD_DATA_MODE();
stm32_spi_set_data_width(&lcdSpi, LL_SPI_DATAWIDTH_16BIT);
SCB_CleanDCache_by_Addr((void *)data, length * sizeof(uint16_t));
stm32_spi_dma_transmit_words(&lcdSpi, data, length);
stm32_spi_unselect(&lcdSpi);
stm32_spi_set_data_width(&lcdSpi, LL_SPI_DATAWIDTH_8BIT);
}
static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer,
const rect_t &copy_area)
{
(void)disp_drv;
// TODO: replace through some smarter mechanism without busy wait
while (!gpio_read(LCD_FMARK));
coord_t x1 = copy_area.x;
coord_t x2 = x1 + copy_area.w - 1;
set_column_addr(x1, x2);
coord_t y1 = copy_area.y;
coord_t y2 = y1 + copy_area.h - 1;
set_row_addr(y1, y2);
memory_write(buffer, copy_area.w * copy_area.h);
lcdFlushed();
}
lcdSpiInitFucPtr lcdInitFunction;
lcdSpiInitFucPtr lcdOffFunction;
lcdSpiInitFucPtr lcdOnFunction;
uint32_t lcdPixelClock;
static void lcdSpiConfig(void)
{
stm32_spi_init(&lcdSpi, LL_SPI_DATAWIDTH_8BIT);
stm32_spi_set_max_baudrate(&lcdSpi, LCD_SPI_BAUD);
gpio_init(LCD_FMARK, GPIO_IN, GPIO_PIN_SPEED_HIGH);
gpio_init(LCD_NRST, GPIO_OUT, GPIO_PIN_SPEED_HIGH);
gpio_init(LCD_SPI_RS, GPIO_OUT, GPIO_PIN_SPEED_HIGH);
}
void lcdDelay() {
delay_01us(1);
}
static void lcdReset() {
LCD_NRST_HIGH();
delay_ms(1);
LCD_NRST_LOW(); // RESET();
delay_ms(100);
LCD_NRST_HIGH();
delay_ms(120);
}
static void lcdWriteCommand(uint8_t cmd)
{
LCD_COMMAND_MODE();
stm32_spi_select(&lcdSpi);
stm32_spi_transfer_byte(&lcdSpi, cmd);
stm32_spi_unselect(&lcdSpi);
}
// static void lcdWriteReg(uint8_t reg, uint8_t data)
// {
// LCD_COMMAND_MODE();
// stm32_spi_select(&lcdSpi);
// stm32_spi_transfer_byte(&lcdSpi, reg);
// LCD_DATA_MODE();
// stm32_spi_transfer_byte(&lcdSpi, data);
// stm32_spi_unselect(&lcdSpi);
// }
static void lcdWriteData(uint8_t data)
{
LCD_DATA_MODE();
stm32_spi_select(&lcdSpi);
stm32_spi_transfer_byte(&lcdSpi, data);
stm32_spi_unselect(&lcdSpi);
}
// static uint8_t lcdReadReg(uint8_t reg)
// {
// uint8_t data = 0;
// LCD_COMMAND_MODE();
// stm32_spi_select(&lcdSpi);
// stm32_spi_transfer_byte(&lcdSpi, reg);
// LCD_DATA_MODE();
// data = stm32_spi_transfer_byte(&lcdSpi, 0xFF);
// stm32_spi_unselect(&lcdSpi);
// return data;
// }
extern "C" void lcdSetInitalFrameBuffer(void *fbAddress)
{
initialFrameBuffer = fbAddress;
}
static void lcdSetOn(void) { lcdWriteCommand(0x29); }
static void lcdSetOff(void) { lcdWriteCommand(0x28); }
extern "C" void lcdInit()
{
// Configure the LCD SPI + RESET pins
lcdSpiConfig();
stm32_spi_unselect(&lcdSpi);
// hard reset
lcdReset();
// Init command start
lcdWriteCommand( 0xFE );
lcdWriteCommand( 0xEF );
// Display orientation
lcdWriteCommand( 0x36 );
lcdWriteData( 0x60 );
// Color mode
lcdWriteCommand( 0x3A );
lcdWriteData( 0x05 ); // 16-bit color
// Display control
lcdWriteCommand( 0x86 );
lcdWriteData( 0x98 );
lcdWriteCommand( 0x89 );
lcdWriteData( 0x33 );
lcdWriteCommand( 0x8B );
lcdWriteData( 0x80 );
lcdWriteCommand( 0x8D );
lcdWriteData( 0x33 );
lcdWriteCommand( 0x3A );
lcdWriteData( 0x05 );
lcdWriteCommand( 0x8E );
lcdWriteData( 0x0F );
lcdWriteCommand( 0xEC );
lcdWriteData( 0x33 );
lcdWriteData( 0x07 );
lcdWriteData( 0x00 );
lcdWriteCommand( 0xED );
lcdWriteData( 0x18 );
lcdWriteData( 0x08 );
lcdWriteCommand( 0xE8 );
lcdWriteData( 0x12 );
lcdWriteData( 0x00 );
// Init command ends
lcdWriteCommand( 0xFF );
lcdWriteCommand( 0x62 );
// Display control
lcdWriteCommand( 0x99 );
lcdWriteData( 0x3E );
lcdWriteCommand( 0x9D );
lcdWriteData( 0x4B );
lcdWriteCommand( 0x98 );
lcdWriteData( 0x3E );
lcdWriteCommand( 0x9C );
lcdWriteData( 0x4B );
lcdWriteCommand( 0xC3 );
lcdWriteData( 0x39 );
lcdWriteCommand( 0xC4 );
lcdWriteData( 0x29 );
lcdWriteCommand( 0xC9 );
lcdWriteData( 0x09 );
// Gamma Control
lcdWriteCommand( 0xF0 );
lcdWriteData( 0x0B );
lcdWriteData( 0x0C );
lcdWriteData( 0x07 );
lcdWriteData( 0x07 );
lcdWriteData( 0x05 );
lcdWriteData( 0x22 );
lcdWriteCommand( 0xF1);
lcdWriteData( 0x42 );
lcdWriteData( 0x78 );
lcdWriteData( 0x56 );
lcdWriteData( 0x1E );
lcdWriteData( 0x1A );
lcdWriteData( 0x95 );
lcdWriteCommand( 0xF2 );
lcdWriteData( 0x0B );
lcdWriteData( 0x0C );
lcdWriteData( 0x07 );
lcdWriteData( 0x07 );
lcdWriteData( 0x05 );
lcdWriteData( 0x44 );
lcdWriteCommand( 0xF3 );
lcdWriteData( 0x56 );
lcdWriteData( 0x92 );
lcdWriteData( 0x30 );
lcdWriteData( 0x31 );
lcdWriteData( 0x35 );
lcdWriteData( 0x7F );
// Display orientation
lcdWriteCommand( 0x36 );
//lcdWriteData( 0xA0 );
lcdWriteData( 0x60 );
// Display size
lcdWriteCommand( 0x2A );
lcdWriteData( 0x00 );
lcdWriteData( 0x00 );
lcdWriteData( 0x01 );
lcdWriteData( 0x40 );
lcdWriteCommand( 0x2B );
lcdWriteData( 0x00 );
lcdWriteData( 0x00 );
lcdWriteData( 0x00 );
lcdWriteData( 0xF0 );
// Invert color
lcdWriteCommand( 0x21 );
// Tear on
lcdWriteCommand( 0x35 );
// Exit sleep
lcdWriteCommand( 0x11 );
/*
lcdWriteCommand(0x11);
delay_ms(120);
lcdWriteCommand(0xB2);
lcdWriteData(0x0C);
lcdWriteData(0x0C);
lcdWriteData(0x00);
lcdWriteData(0x33);
lcdWriteData(0x33);
lcdWriteCommand(0x35);
lcdWriteData(0x00);
lcdWriteCommand(0x36);
lcdWriteData(0x60);
lcdWriteCommand(0x3A);
lcdWriteData(0x05);
lcdWriteCommand(0xB7);
lcdWriteData(0x35);
lcdWriteCommand(0xBB);
lcdWriteData(0x34);
lcdWriteCommand(0xC0);
lcdWriteData(0x2C);
lcdWriteCommand(0xC2);
lcdWriteData( 0x01);
lcdWriteCommand(0xC3);
lcdWriteData(0x13);//4.5V
lcdWriteCommand(0xC4);
lcdWriteData(0x20);
lcdWriteCommand(0xC6);
lcdWriteData(0x0F);
lcdWriteCommand(0xD0);
lcdWriteData(0xA4);
lcdWriteData(0xA1);
lcdWriteCommand(0xD6);
lcdWriteData(0xA1);
lcdWriteCommand(0xE0);
lcdWriteData(0xD0);
lcdWriteData(0x0A);
lcdWriteData(0x10);
lcdWriteData(0x0C);
lcdWriteData(0x0C);
lcdWriteData(0x18);
lcdWriteData(0x35);
lcdWriteData(0x43);
lcdWriteData(0x4D);
lcdWriteData(0x39);
lcdWriteData(0x13);
lcdWriteData(0x13);
lcdWriteData(0x2D);
lcdWriteData(0x34);
lcdWriteCommand(0xE1);
lcdWriteData(0xD0);
lcdWriteData(0x05);
lcdWriteData(0x0B);
lcdWriteData(0x06);
lcdWriteData(0x05);
lcdWriteData(0x02);
lcdWriteData(0x35);
lcdWriteData(0x43);
lcdWriteData(0x4D);
lcdWriteData(0x16);
lcdWriteData(0x15);
lcdWriteData(0x15);
lcdWriteData(0x2E);
lcdWriteData(0x32);
lcdWriteCommand(0x21);
lcdWriteCommand(0x29);
lcdWriteCommand(0x2C); */
lcdSetOn();
// Init LCD RAM
memory_write((const uint16_t*)initialFrameBuffer, LCD_W * LCD_H);
lcdOnFunction = lcdSetOn;
lcdOffFunction = lcdSetOff;
lcdSetFlushCb(startLcdRefresh);
}
@@ -0,0 +1,77 @@
/*
* 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__
#define HBP ( 24 ) // TODO use names from FlySky
#define VBP ( 10 )
#define HSW ( 4 )
#define VSH ( 2 )
#define HFP ( 140 - HBP )
#define VFP ( 22 - VBP )
#define LCD_ST7796S_ID ( 0x7796 )
#define LCD_ILI9481_ID ( 0x9481 )
#define LCD_ILI9486_ID ( 0x9486 )
#define LCD_ILI9488_ID ( 0x9488 )
#define LCD_HX8357D_ID ( 0x99 )
#define LCD_DELAY() LCD_Delay()
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_NRST_GPIO, LCD_NRST_GPIO_PIN)
//#define LCD_NRST_LOW() LL_GPIO_ResetOutputPin(LCD_NRST_GPIO, LCD_NRST_GPIO_PIN)
//#define LCD_CS_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_CS_GPIO, LCD_SPI_CS_GPIO_PIN)
//#define LCD_CS_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_CS_GPIO, LCD_SPI_CS_GPIO_PIN)
#define LCD_SCK_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_SCK_GPIO_PIN)
#define LCD_SCK_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_SCK_GPIO_PIN)
#define LCD_MOSI_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN)
#define LCD_MOSI_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN)
#define LCD_MOSI_AS_INPUT() SET_IO_INPUT( LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN )
#define LCD_MOSI_AS_OUTPUT() SET_IO_OUTPUT( LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN )
#define LCD_READ_DATA_PIN() LL_GPIO_IsInputPinSet(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN)
#define HORIZONTAL_SYNC_WIDTH ( 4 )
#define HORIZONTAL_BACK_PORCH ( 24 )
#define HORIZONTAL_FRONT_PORCH ( 140 - HORIZONTAL_BACK_PORCH )
#define VERTICAL_SYNC_HEIGHT ( 2 )
#define VERTICAL_BACK_PORCH ( 10 )
#define VERTICAL_FRONT_PORCH ( 22 - VERTICAL_BACK_PORCH )
#endif
@@ -0,0 +1,252 @@
/*
* 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 -----------------------------------------------------*/
/*
*/
/* 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);//BL1
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);//RAS
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);//BA0
gpio_init_af(GPIO_PIN(GPIOG, 5), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);//BA1
gpio_init_af(GPIO_PIN(GPIOG, 8), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);//CLK
gpio_init_af(GPIO_PIN(GPIOG, 15), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);//NCAS
gpio_init_af(GPIO_PIN(GPIOH, 2), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);//CLKE0 PH2
gpio_init_af(GPIO_PIN(GPIOH, 3), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);//NE0 PH3
gpio_init_af(GPIO_PIN(GPIOH, 5), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);//NWE PH5 V14P OK
}
extern "C" void SDRAM_InitSequence(void)
{
FMC_SDRAM_CommandTypeDef FMC_SDRAMCommandStructure;
uint32_t tmpr = 0;
uint32_t timeout = SDRAM_TIMEOUT;
/* Step 3 --------------------------------------------------------------------*/
/* Configure a clock configuration enable command */
FMC_SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_CLK_ENABLE;
FMC_SDRAMCommandStructure.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1;
FMC_SDRAMCommandStructure.AutoRefreshNumber = 1;
FMC_SDRAMCommandStructure.ModeRegisterDefinition = 0;
/* Wait until the SDRAM controller is ready */
// while((__FMC_SDRAM_GET_FLAG(FMC_Bank5_6_R, FMC_SDRAM_FLAG_BUSY) != 0) &&
// (timeout > 0))
// {
// timeout--;
// }
/* 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_BANK1;
FMC_SDRAMCommandStructure.AutoRefreshNumber = 1;
FMC_SDRAMCommandStructure.ModeRegisterDefinition = 0;
/* Wait until the SDRAM controller is ready */
// timeout = SDRAM_TIMEOUT;
// while((__FMC_SDRAM_GET_FLAG(FMC_Bank5_6_R, FMC_SDRAM_FLAG_BUSY) != 0) && (timeout > 0))
// {
// timeout--;
// }
/* Send the command */
FMC_SDRAM_SendCommand(FMC_Bank5_6_R, &FMC_SDRAMCommandStructure, 10);
// delay_ms(1);
/* Step 6 --------------------------------------------------------------------*/
/* Configure a Auto-Refresh command */
FMC_SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
FMC_SDRAMCommandStructure.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1;
FMC_SDRAMCommandStructure.AutoRefreshNumber = 8;
FMC_SDRAMCommandStructure.ModeRegisterDefinition = 0;
/* Wait until the SDRAM controller is ready */
// timeout = SDRAM_TIMEOUT;
// while((__FMC_SDRAM_GET_FLAG(FMC_Bank5_6_R, FMC_SDRAM_FLAG_BUSY) != 0) &&
// (timeout > 0))
// {
// timeout--;
// }
/* Send the command */
FMC_SDRAM_SendCommand(FMC_Bank5_6_R, &FMC_SDRAMCommandStructure, 10);
// delay_ms(1);
/* 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_BANK1;
FMC_SDRAMCommandStructure.AutoRefreshNumber = 1;
FMC_SDRAMCommandStructure.ModeRegisterDefinition = tmpr;
/* Wait until the SDRAM controller is ready */
// timeout = SDRAM_TIMEOUT;
// while((__FMC_SDRAM_GET_FLAG(FMC_Bank5_6_R, FMC_SDRAM_FLAG_BUSY) != 0) && (timeout > 0))
// {
// timeout--;
// }
/* Send the command */
FMC_SDRAM_SendCommand(FMC_Bank5_6_R, &FMC_SDRAMCommandStructure, 10);
// delay_ms(1);
/* 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, 1855);
/* Wait until the SDRAM controller is ready */
// timeout = SDRAM_TIMEOUT;
// while((__FMC_SDRAM_GET_FLAG(FMC_Bank5_6_R, FMC_SDRAM_FLAG_BUSY) != 0) && (timeout > 0))
// {
// timeout--;
// }
// delay_ms(1);
}
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 */
/* Timing configuration for 80 Mhz of SD clock */
FMC_SDRAMTimingInitStructure.LoadToActiveDelay = 2;
FMC_SDRAMTimingInitStructure.ExitSelfRefreshDelay = 7;
FMC_SDRAMTimingInitStructure.SelfRefreshTime = 4;
FMC_SDRAMTimingInitStructure.RowCycleDelay = 7;
FMC_SDRAMTimingInitStructure.WriteRecoveryTime = 3;
FMC_SDRAMTimingInitStructure.RPDelay = 2;
FMC_SDRAMTimingInitStructure.RCDDelay = 2;
/* FMC SDRAM control configuration */
FMC_SDRAMInitStructure.SDBank = FMC_SDRAM_BANK1;
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_2;
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_BANK1);
__FMC_ENABLE();
/* FMC SDRAM device initialization sequence */
SDRAM_InitSequence();
}
@@ -0,0 +1,116 @@
/*
* 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);
LL_RCC_PLL1_SetM(1);
LL_RCC_PLL1_SetN(100);
LL_RCC_PLL1_SetP(2);
LL_RCC_PLL1_SetQ(4);
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_PLL2Q_Enable();
LL_RCC_PLL2R_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(1);
LL_RCC_PLL2_SetN(120);
LL_RCC_PLL2_SetP(12);
LL_RCC_PLL2_SetQ(2);
LL_RCC_PLL2_SetR(4);
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);
LL_RCC_PLL3_SetM(1);
LL_RCC_PLL3_SetN(120);
LL_RCC_PLL3_SetP(5);
LL_RCC_PLL3_SetQ(20);
LL_RCC_PLL3_SetR(80);
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_SetFMCClockSource(LL_RCC_FMC_CLKSOURCE_HCLK);
LL_RCC_SetSPIClockSource(LL_RCC_SPI123_CLKSOURCE_PLL3P);
LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLL3Q);
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,291 @@
/*
* 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 "touch_driver.h"
#include "stm32_hal.h"
#include "stm32_hal_ll.h"
#include "stm32_exti_driver.h"
#include "stm32_gpio.h"
#include "stm32_gpio_driver.h"
#include "stm32_i2c_driver.h"
#include "timers_driver.h"
#include "debug.h"
#include "delays_driver.h"
#include "hal.h"
#include "hal/gpio.h"
#include "hal/i2c_driver.h"
#include "rtos.h"
volatile static bool touchEventOccured;
#define TOUCH_CST836U_I2C_ADDRESS (0x15)
static tc_handle_TypeDef tc_handle = {0, 0};
tmr10ms_t downTime = 0;
tmr10ms_t tapTime = 0;
short tapCount = 0;
#define TAP_TIME 250 // ms
static TouchState internalTouchState = {};
static void _cst836u_exti_isr(void) {
touchEventOccured = true;
}
static void TouchAFExtiConfig(void)
{
TRACE("TOUCH_AF_EXTI_CONFIG");
gpio_init_int(TOUCH_INT_GPIO, GPIO_IN_PU, GPIO_FALLING, _cst836u_exti_isr);
}
void initTouchI2C(void)
{
TRACE("CST836U I2C Init");
if (i2c_init(TOUCH_I2C_BUS) < 0) {
TRACE("CST836U ERROR: i2c_init failed");
return;
}
}
#define I2C_TIMEOUT_MAX 5 // 5 ms
bool touch_i2c_read(uint8_t addr, uint8_t reg, uint8_t* data, uint8_t len)
{
if (stm32_i2c_master_tx(TOUCH_I2C_BUS, addr, &reg, 1, 3) < 0) return false;
delay_us(5);
if (stm32_i2c_master_rx(TOUCH_I2C_BUS, addr, data, len, I2C_TIMEOUT_MAX) < 0)
return false;
return true;
}
static uint8_t TS_IO_Read(uint8_t addr, uint8_t reg)
{
uint8_t result;
uint8_t tryCount = 3;
while (!touch_i2c_read(addr, reg, &result, 1)) {
if (--tryCount == 0) break;
initTouchI2C();
}
return result;
}
static uint16_t TS_IO_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t* buffer,
uint16_t length)
{
uint8_t tryCount = 3;
while (!touch_i2c_read(addr, reg, buffer, length)) {
if (--tryCount == 0) break;
initTouchI2C();
}
return 1;
}
static void touch_cst836u_debug_info(void)
{
#if defined(DEBUG)
TRACE("cst836u: fw ver 0x%02X %02X",
TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_FW_VERSION_H_REG),
TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_FW_VERSION_L_REG));
TRACE("cst836u: module version 0x%02X",
TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_MODULE_VERSION_REG));
TRACE("cst836u: project name 0x%02X",
TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_PROJECT_NAME_REG));
TRACE("cst836u: chip type 0x%02X 0x%02X",
TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_CHIP_TYPE_H_REG),
TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_CHIP_TYPE_L_REG));
#endif
}
/**
* @brief Get the touch screen X and Y positions values
* Manage multi touch thanks to touch Index global
* variable 'tc_handle.currActiveTouchIdx'.
* @param DeviceAddr: Device address on communication Bus.
* @param X: Pointer to X position value
* @param Y: Pointer to Y position value
* @retval None.
*/
static void cst836u_TS_GetXY(uint16_t* X, uint16_t* Y, uint32_t* event)
{
uint8_t regAddress = 0;
uint8_t dataxy[4];
if (tc_handle.currActiveTouchIdx < tc_handle.currActiveTouchNb) {
switch (tc_handle.currActiveTouchIdx) {
case 0:
regAddress = CST836U_TOUCH1_XH_REG;
break;
case 1:
regAddress = CST836U_TOUCH2_XH_REG;
break;
default:
break;
}
/* Read X and Y positions */
TS_IO_ReadMultiple(TOUCH_CST836U_I2C_ADDRESS, regAddress, dataxy,
sizeof(dataxy));
/* Send back ready X position to caller */
*X = ((dataxy[0] & CST836U_MSB_MASK) << 8) | dataxy[1];
/* Send back ready Y position to caller */
*Y = ((dataxy[2] & CST836U_MSB_MASK) << 8) | dataxy[3];
*event = (dataxy[0] & CST836U_TOUCH_EVT_FLAG_MASK) >>
CST836U_TOUCH_EVT_FLAG_SHIFT;
/*
uint32_t weight;
uint32_t area;
*/
tc_handle.currActiveTouchIdx++;
}
}
/**
* @brief Return if there is touches detected or not.
* Try to detect new touches and forget the old ones (reset internal
* global variables).
* @param DeviceAddr: Device address on communication Bus.
* @retval : Number of active touches detected (can be 0, 1 or 2).
*/
static uint8_t cst836u_TS_DetectTouch()
{
volatile uint8_t nbTouch = 0;
/* Read register CST836U_TOUCH_NUM_REG to check number of touches detection */
nbTouch = TS_IO_Read(TOUCH_CST836U_I2C_ADDRESS, CST836U_TOUCH_NUM_REG);
if (nbTouch > CST836U_MAX_DETECTABLE_TOUCH) {
/* If invalid number of touch detected, set it to zero */
nbTouch = 0;
}
tc_handle.currActiveTouchNb = nbTouch;
tc_handle.currActiveTouchIdx = 0;
return (nbTouch);
}
void TouchReset()
{
gpio_clear(TOUCH_RST_GPIO);
delay_ms(10);
gpio_set(TOUCH_RST_GPIO);
delay_ms(300);
}
void touchPanelInit(void)
{
gpio_init(TOUCH_RST_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
initTouchI2C();
TouchReset();
TouchAFExtiConfig();
touch_cst836u_debug_info();
}
void handleTouch()
{
unsigned short touchX;
unsigned short touchY;
uint32_t tEvent = 0;
cst836u_TS_GetXY(&touchX, &touchY, &tEvent);
if (tEvent == CST836U_TOUCH_EVT_FLAG_CONTACT) {
int dx = touchX - internalTouchState.x;
int dy = touchY - internalTouchState.y;
internalTouchState.x = touchX;
internalTouchState.y = touchY;
if (internalTouchState.event == TE_NONE ||
internalTouchState.event == TE_UP ||
internalTouchState.event == TE_SLIDE_END) {
internalTouchState.startX = internalTouchState.x;
internalTouchState.startY = internalTouchState.y;
internalTouchState.event = TE_DOWN;
} else if (internalTouchState.event == TE_DOWN) {
if (dx >= SLIDE_RANGE || dx <= -SLIDE_RANGE || dy >= SLIDE_RANGE ||
dy <= -SLIDE_RANGE) {
internalTouchState.event = TE_SLIDE;
internalTouchState.deltaX = (short)dx;
internalTouchState.deltaY = (short)dy;
} else {
internalTouchState.event = TE_DOWN;
internalTouchState.deltaX = 0;
internalTouchState.deltaY = 0;
}
} else if (internalTouchState.event == TE_SLIDE) {
internalTouchState.event = TE_SLIDE; // no change
internalTouchState.deltaX = (short)dx;
internalTouchState.deltaY = (short)dy;
}
}
}
bool touchPanelEventOccured() { return touchEventOccured; }
TouchState touchPanelRead()
{
if (!touchEventOccured) return internalTouchState;
touchEventOccured = false;
tmr10ms_t now = timersGetMsTick();
internalTouchState.tapCount = 0;
if (cst836u_TS_DetectTouch()) {
handleTouch();
if (internalTouchState.event == TE_DOWN && downTime == 0) {
downTime = now;
}
} else {
if (internalTouchState.event == TE_DOWN) {
internalTouchState.event = TE_UP;
if (now - downTime <= TAP_TIME) {
if (now - tapTime > TAP_TIME) {
tapCount = 1;
} else {
tapCount++;
}
internalTouchState.tapCount = tapCount;
tapTime = now;
} else {
internalTouchState.tapCount = 0; // not a tap
}
downTime = 0;
} else {
tapCount = 0;
internalTouchState.tapCount = 0;
internalTouchState.event = TE_SLIDE_END;
}
}
TouchState ret = internalTouchState;
internalTouchState.deltaX = 0;
internalTouchState.deltaY = 0;
if (internalTouchState.event == TE_UP ||
internalTouchState.event == TE_SLIDE_END)
internalTouchState.event = TE_NONE;
return ret;
}
TouchState getInternalTouchState() { return internalTouchState; }
@@ -0,0 +1,110 @@
/*
* 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.
*/
/*
Copyright 2016 fishpepper <AT> gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
author: fishpepper <AT> gmail.com
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <touch.h>
/* Set Multi-touch as non supported */
#ifndef TS_MULTI_TOUCH_SUPPORTED
#define TS_MULTI_TOUCH_SUPPORTED 0
#endif
/* Set Auto-calibration as non supported */
#ifndef TS_AUTO_CALIBRATION_SUPPORTED
#define TS_AUTO_CALIBRATION_SUPPORTED 0
#endif
/* Macros --------------------------------------------------------------------*/
/** @typedef ft6x06_handle_TypeDef
* ft6x06 Handle definition.
*/
typedef struct {
/* field holding the current number of simultaneous active touches */
uint8_t currActiveTouchNb;
/* field holding the touch index currently managed */
uint8_t currActiveTouchIdx;
} tc_handle_TypeDef;
/* clang-format off */
#define CST836U_WORK_MODE_REG 0x00
#define CST836U_PROXIMITY_ID_REG 0x01
#define CST836U_TOUCH_NUM_REG 0x02
#define CST836U_TOUCH1_XH_REG 0x03
#define CST836U_TOUCH1_XL_REG 0x04
#define CST836U_TOUCH1_YH_REG 0x05
#define CST836U_TOUCH1_YL_REG 0x06
#define CST836U_TOUCH2_XH_REG 0x09
#define CST836U_TOUCH2_XL_REG 0x0A
#define CST836U_TOUCH2_YH_REG 0x0B
#define CST836U_TOUCH2_YL_REG 0x0C
#define CST836U_FW_VERSION_L_REG 0xA6
#define CST836U_FW_VERSION_H_REG 0xA7
#define CST836U_MODULE_VERSION_REG 0xA8
#define CST836U_PROJECT_NAME_REG 0xA9
#define CST836U_CHIP_TYPE_L_REG 0xAA
#define CST836U_CHIP_TYPE_H_REG 0xAB
#define CST836U_CHECKSUM_L_REG 0xAC
#define CST836U_CHECKSUM_H_REG 0xAD
#define CST836U_PROX_STATE_REG 0xB0
#define CST836U_GES_STATE_REG 0xD0
#define CST836U_GES_ID_REG_REG 0xD3
#define CST836U_MAX_DETECTABLE_TOUCH 2
#define CST836U_MSB_MASK 0x0F
#define CST836U_TOUCH_EVT_FLAG_SHIFT 6
#define CST836U_TOUCH_EVT_FLAG_MASK (3 << CST836U_TOUCH_EVT_FLAG_SHIFT)
#define CST836U_TOUCH_EVT_FLAG_CONTACT 0x02
/* clang-format on */
extern void touchPanelInit(void);
extern void TouchDriver(void);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,52 @@
/*
* 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 "board.h"
#include "hal/usb_driver.h"
void usbChargerInit()
{
gpio_init(UCHARGER_GPIO, GPIO_IN_PU, GPIO_PIN_SPEED_LOW);
#if defined(UCHARGER_PW)
gpio_init(UCHARGER_PW, GPIO_OUT, GPIO_PIN_SPEED_LOW);
gpio_set(UCHARGER_PW);
//gpio_clear(UCHARGER_PW); 0=DISABLE 1=ENABLE
#endif
#if defined(UCHARGER_EN)
gpio_init(UCHARGER_EN, GPIO_OUT, GPIO_PIN_SPEED_LOW);
//gpio_set(UCHARGER_EN);
gpio_clear(UCHARGER_EN); //cherge EN 0=ENANLE 1=DISABLE
#endif
#if defined(USB_GPIO_SEL)
gpio_init(USB_GPIO_SEL, GPIO_OUT, GPIO_PIN_SPEED_LOW);
gpio_set(USB_GPIO_SEL);
//gpio_clear(USB_GPIO_SEL); // USB HUB SELECT 0->H7 MCU 1->CHARGE MCU
#endif
}
bool usbChargerLed()
{
return (!gpio_read(UCHARGER_GPIO) && usbPlugged());
}
+203 -168
View File
@@ -5,21 +5,21 @@
"name": "MAIN",
"adc": "ADC1",
"dma": "DMA2",
"dma_channel": "LL_DMA_CHANNEL_0",
"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_28CYCLES"
"sample_time": "LL_ADC_SAMPLINGTIME_8CYCLES_5"
},
{
"name": "EXT",
"adc": "ADC3",
"dma": "DMA2",
"dma_channel": "LL_DMA_CHANNEL_2",
"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_56CYCLES"
"sample_time": "LL_ADC_SAMPLINGTIME_8CYCLES_5"
}
],
"inputs": [
@@ -29,7 +29,7 @@
"adc": "MAIN",
"gpio": "GPIOA",
"pin": "LL_GPIO_PIN_2",
"channel": "LL_ADC_CHANNEL_2"
"channel": "LL_ADC_CHANNEL_14"
},
{
"name": "LV",
@@ -37,8 +37,7 @@
"adc": "MAIN",
"gpio": "GPIOA",
"pin": "LL_GPIO_PIN_3",
"channel": "LL_ADC_CHANNEL_3",
"inverted": true
"channel": "LL_ADC_CHANNEL_15"
},
{
"name": "RV",
@@ -46,7 +45,8 @@
"adc": "MAIN",
"gpio": "GPIOA",
"pin": "LL_GPIO_PIN_0",
"channel": "LL_ADC_CHANNEL_0"
"channel": "LL_ADC_CHANNEL_17",
"inverted": true
},
{
"name": "RH",
@@ -54,17 +54,16 @@
"adc": "MAIN",
"gpio": "GPIOA",
"pin": "LL_GPIO_PIN_1",
"channel": "LL_ADC_CHANNEL_1",
"channel": "LL_ADC_CHANNEL_16",
"inverted": true
},
{
"name": "P1",
"type": "FLEX",
"adc": "MAIN",
"gpio": "GPIOB",
"pin": "LL_GPIO_PIN_0",
"channel": "LL_ADC_CHANNEL_8",
"inverted": true,
"gpio": "GPIOC",
"pin": "LL_GPIO_PIN_1",
"channel": "LL_ADC_CHANNEL_11",
"label": "S1",
"short_label": "1",
"default": "POT_CENTER"
@@ -73,64 +72,36 @@
"name": "P2",
"type": "FLEX",
"adc": "MAIN",
"gpio": "GPIOA",
"pin": "LL_GPIO_PIN_6",
"channel": "LL_ADC_CHANNEL_6",
"inverted": true,
"gpio": "GPIOC",
"pin": "LL_GPIO_PIN_0",
"channel": "LL_ADC_CHANNEL_10",
"label": "S2",
"short_label": "2",
"default": "POT_CENTER"
},
{
"name": "P3",
"type": "FLEX",
"adc": "EXT",
"name": "RAW1",
"type": "RAW",
"adc": "MAIN",
"gpio": "GPIOC",
"pin": "LL_GPIO_PIN_2",
"channel": "LL_ADC_CHANNEL_12",
"label": "S3",
"short_label": "3",
"default": "MULTIPOS"
"pin": "LL_GPIO_PIN_5",
"channel": "LL_ADC_CHANNEL_8"
},
{
"name": "VBAT",
"type": "VBAT",
"adc": "MAIN",
"gpio": "GPIOC",
"pin": "LL_GPIO_PIN_3",
"channel": "LL_ADC_CHANNEL_13"
},
{
"name": "RTC_BAT",
"type": "RTC_BAT",
"adc": "MAIN",
"adc": "EXT",
"gpio": null,
"pin": null,
"channel": "LL_ADC_CHANNEL_VBAT"
},
{
"name": "SWB",
"type": "SWITCH",
"adc": "MAIN",
"gpio": "GPIOA",
"pin": "LL_GPIO_PIN_5",
"channel": "LL_ADC_CHANNEL_5"
},
{
"name": "SWC",
"type": "SWITCH",
"adc": "MAIN",
"gpio": "GPIOC",
"pin": "LL_GPIO_PIN_0",
"channel": "LL_ADC_CHANNEL_10"
},
{
"name": "SWE",
"type": "SWITCH",
"adc": "MAIN",
"gpio": "GPIOA",
"pin": "LL_GPIO_PIN_7",
"channel": "LL_ADC_CHANNEL_7"
},
{
"name": "SWF",
"type": "SWITCH",
"adc": "MAIN",
"gpio": "GPIOC",
"pin": "LL_GPIO_PIN_5",
"channel": "LL_ADC_CHANNEL_15"
}
]
},
@@ -140,39 +111,33 @@
"type": "2POS",
"flags": 0,
"inverted": false,
"default": "3POS",
"display": [
0,
0
],
"gpio": "GPIOC",
"pin": "LL_GPIO_PIN_13",
"default": "2POS",
"gpio": "GPIOH",
"pin": "LL_GPIO_PIN_8",
"is_cfs": false
},
{
"name": "SB",
"type": "ADC",
"type": "3POS",
"flags": 0,
"inverted": false,
"inverted": true,
"default": "3POS",
"display": [
0,
1
],
"adc_input": "SWB",
"gpio_high": "GPIOD",
"pin_high": "LL_GPIO_PIN_11",
"gpio_low": "GPIOH",
"pin_low": "LL_GPIO_PIN_7",
"is_cfs": false
},
{
"name": "SC",
"type": "ADC",
"type": "3POS",
"flags": 0,
"inverted": false,
"inverted": true,
"default": "3POS",
"display": [
1,
0
],
"adc_input": "SWC",
"gpio_high": "GPIOG",
"pin_high": "LL_GPIO_PIN_3",
"gpio_low": "GPIOD",
"pin_low": "LL_GPIO_PIN_4",
"is_cfs": false
},
{
@@ -180,70 +145,98 @@
"type": "2POS",
"flags": 0,
"inverted": false,
"default": "3POS",
"display": [
1,
1
],
"gpio": "GPIOE",
"pin": "LL_GPIO_PIN_8",
"default": "TOGGLE",
"gpio": "GPIOI",
"pin": "LL_GPIO_PIN_3",
"is_cfs": false
},
{
"name": "SE",
"type": "ADC",
"name": "SW1",
"type": "2POS",
"flags": 0,
"inverted": false,
"default": "2POS",
"display": [
0,
2
],
"adc_input": "SWE",
"is_cfs": false
"gpio": null,
"pin": "PCA95XX_P0",
"is_cfs": true,
"cfs_idx": 0
},
{
"name": "SF",
"type": "ADC",
"name": "SW2",
"type": "2POS",
"flags": 0,
"inverted": false,
"default": "TOGGLE",
"display": [
1,
2
],
"adc_input": "SWF",
"is_cfs": false
"default": "2POS",
"gpio": null,
"pin": "PCA95XX_P1",
"is_cfs": true,
"cfs_idx": 1
},
{
"name": "SW3",
"type": "2POS",
"flags": 0,
"inverted": false,
"default": "2POS",
"gpio": null,
"pin": "PCA95XX_P2",
"is_cfs": true,
"cfs_idx": 2
},
{
"name": "SW4",
"type": "2POS",
"flags": 0,
"inverted": false,
"default": "2POS",
"gpio": null,
"pin": "PCA95XX_P3",
"is_cfs": true,
"cfs_idx": 3
},
{
"name": "SW5",
"type": "2POS",
"flags": 0,
"inverted": false,
"default": "2POS",
"gpio": null,
"pin": "PCA95XX_P4",
"is_cfs": true,
"cfs_idx": 4
},
{
"name": "SW6",
"type": "2POS",
"flags": 0,
"inverted": false,
"default": "2POS",
"gpio": null,
"pin": "PCA95XX_P5",
"is_cfs": true,
"cfs_idx": 5
}
],
"keys": [
{
"gpio": "GPIOE",
"pin": "LL_GPIO_PIN_1",
"active_low": true,
"key": "KEY_EXIT",
"name": "EXIT",
"label": "EXIT"
},
{
"gpio": "GPIOD",
"pin": "LL_GPIO_PIN_11",
"gpio": "GPIOI",
"pin": "LL_GPIO_PIN_8",
"active_low": true,
"key": "KEY_ENTER",
"name": "ENTER",
"label": "Enter"
},
{
"gpio": "GPIOD",
"pin": "LL_GPIO_PIN_3",
"gpio": "GPIOI",
"pin": "LL_GPIO_PIN_10",
"active_low": true,
"key": "KEY_PAGEUP",
"name": "PAGEUP",
"label": "PAGE<"
},
{
"gpio": "GPIOD",
"pin": "LL_GPIO_PIN_7",
"gpio": "GPIOI",
"pin": "LL_GPIO_PIN_11",
"active_low": true,
"key": "KEY_PAGEDN",
"name": "PAGEDN",
@@ -251,40 +244,48 @@
},
{
"gpio": "GPIOE",
"pin": "LL_GPIO_PIN_11",
"pin": "LL_GPIO_PIN_5",
"active_low": true,
"key": "KEY_MODEL",
"name": "MDL",
"label": "MDL"
},
{
"gpio": "GPIOD",
"pin": "LL_GPIO_PIN_2",
"gpio": "GPIOK",
"pin": "LL_GPIO_PIN_5",
"active_low": true,
"key": "KEY_TELE",
"name": "TELE",
"label": "TELE"
"key": "KEY_EXIT",
"name": "EXIT",
"label": "EXIT"
},
{
"gpio": "GPIOB",
"pin": "LL_GPIO_PIN_4",
"gpio": "GPIOJ",
"pin": "LL_GPIO_PIN_3",
"active_low": true,
"key": "KEY_SYS",
"name": "SYS",
"label": "SYS"
},
{
"gpio": "GPIOK",
"pin": "LL_GPIO_PIN_4",
"active_low": true,
"key": "KEY_TELE",
"name": "TELE",
"label": "TELE"
}
],
"trims": [
{
"name": "T1",
"dec": {
"gpio": "GPIOD",
"pin": "LL_GPIO_PIN_15",
"gpio": "GPIOB",
"pin": "LL_GPIO_PIN_2",
"active_low": true
},
"inc": {
"gpio": "GPIOC",
"pin": "LL_GPIO_PIN_1",
"gpio": "GPIOJ",
"pin": "LL_GPIO_PIN_4",
"active_low": true
},
"active_low": true
@@ -292,13 +293,13 @@
{
"name": "T2",
"dec": {
"gpio": "GPIOE",
"pin": "LL_GPIO_PIN_6",
"gpio": "GPIOJ",
"pin": "LL_GPIO_PIN_2",
"active_low": true
},
"inc": {
"gpio": "GPIOE",
"pin": "LL_GPIO_PIN_5",
"gpio": "GPIOI",
"pin": "LL_GPIO_PIN_15",
"active_low": true
},
"active_low": true
@@ -307,12 +308,12 @@
"name": "T3",
"dec": {
"gpio": "GPIOC",
"pin": "LL_GPIO_PIN_3",
"pin": "LL_GPIO_PIN_13",
"active_low": true
},
"inc": {
"gpio": "GPIOD",
"pin": "LL_GPIO_PIN_0",
"gpio": "GPIOC",
"pin": "LL_GPIO_PIN_2",
"active_low": true
},
"active_low": true
@@ -320,12 +321,12 @@
{
"name": "T4",
"dec": {
"gpio": "GPIOE",
"pin": "LL_GPIO_PIN_3",
"gpio": "GPIOB",
"pin": "LL_GPIO_PIN_6",
"active_low": true
},
"inc": {
"gpio": "GPIOE",
"gpio": "GPIOB",
"pin": "LL_GPIO_PIN_4",
"active_low": true
},
@@ -333,45 +334,53 @@
}
],
"display": {
"lcd_w": 128,
"lcd_h": 64,
"lcd_phys_w": 128,
"lcd_phys_h": 64,
"lcd_depth": 1,
"lcd_vertical_invert": true
"lcd_w": 320,
"lcd_h": 240,
"lcd_phys_w": 320,
"lcd_phys_h": 240,
"lcd_depth": 16
},
"backlight": {
"backlight_bdtr": "TIM_BDTR_MOE"
"backlight_gpio": "GPIO_PIN(GPIOI, 2)",
"backlight_timer": "TIM8",
"backlight_timer_channel": "LL_TIM_CHANNEL_CH4",
"backlight_gpio_af": "GPIO_AF3",
"backlight_timer_freq": "(PERI1_FREQUENCY * TIMER_MULT_APB1)"
},
"leds": {
"led_strip_length": 6,
"led_strip_length": 7,
"bling_led_strip_start": 6,
"bling_led_strip_length": 1,
"cfs_led_strip_start": 0,
"cfs_led_strip_length": 6,
"cfs_leds_per_switch": 1,
"led_strip_gpio": "GPIO_PIN(GPIOA, 10)",
"led_strip_gpio_af": "LL_GPIO_AF_1",
"led_strip_timer": "TIM1",
"led_strip_timer_freq": "(PERI2_FREQUENCY * TIMER_MULT_APB2)",
"led_strip_timer_freq": "(PERI1_FREQUENCY * TIMER_MULT_APB1)",
"led_strip_timer_channel": "LL_TIM_CHANNEL_CH3",
"led_strip_timer_dma": "DMA2",
"led_strip_timer_dma_channel": "LL_DMA_CHANNEL_6",
"led_strip_timer_dma_stream": "LL_DMA_STREAM_5",
"led_strip_timer_dma_irqn": "DMA2_Stream5_IRQn",
"led_strip_timer_dma_irqhandler": "DMA2_Stream5_IRQHandler",
"led_strip_timer_dma": "DMA1",
"led_strip_timer_dma_channel": "LL_DMAMUX1_REQ_TIM1_UP",
"led_strip_timer_dma_stream": "LL_DMA_STREAM_0",
"led_strip_timer_dma_irqn": "DMA1_Stream0_IRQn",
"led_strip_timer_dma_irqhandler": "DMA1_Stream0_IRQHandler",
"led_strip_refresh_period": 50,
"status_leds": true,
"led_red_gpio": "GPIO_PIN(GPIOE, 13)",
"led_green_gpio": "GPIO_PIN(GPIOE, 14)",
"led_blue_gpio": "GPIO_PIN(GPIOE, 2)"
"led_red_gpio": "GPIO_PIN(GPIOI, 12)",
"led_green_gpio": "GPIO_PIN(GPIOI, 13)",
"led_blue_gpio": "GPIO_PIN(GPIOI, 14)"
},
"hardware": {
"has_ext_module_support": true,
"has_int_module_support": true,
"sport_max_baudrate": 400000,
"cpu": "STM32F407xG",
"cpu_type": "STM32F4"
"cpu": "STM32H750xB",
"cpu_type": "STM32H7"
},
"timers": {
"cpu_freq": 168000000,
"peri1_frequency": 42000000,
"peri2_frequency": 84000000,
"cpu_freq": 400000000,
"peri1_frequency": 100000000,
"peri2_frequency": 100000000,
"timer_mult_apb1": 2,
"timer_mult_apb2": 2,
"ms_timer": "TIM14",
@@ -382,14 +391,40 @@
"mixer_scheduler_timer_irqn": "TIM8_BRK_TIM12_IRQn",
"mixer_scheduler_timer_irqhandler": "TIM8_BRK_TIM12_IRQHandler"
},
"rotenc": {
"rotary_encoder_gpio_a": "GPIOE",
"rotary_encoder_gpio_pin_a": "LL_GPIO_PIN_3",
"rotary_encoder_gpio_b": "GPIOE",
"rotary_encoder_gpio_pin_b": "LL_GPIO_PIN_4",
"rotary_encoder_inverted": true,
"rotary_encoder_position": "(((ROTARY_ENCODER_GPIO_A->IDR >> 3) & 0x01)|((ROTARY_ENCODER_GPIO_B->IDR >> 3) & 0x02))",
"rotary_encoder_exti_line1": "LL_EXTI_LINE_3",
"rotary_encoder_exti_line2": "LL_EXTI_LINE_4",
"exti": [
{
"irq": "EXTI3_IRQ",
"priority": 5
},
{
"irq": "EXTI4_IRQ",
"priority": 5
}
],
"rotary_encoder_exti_port_a": "LL_SYSCFG_EXTI_PORTE",
"rotary_encoder_exti_port_b": "LL_SYSCFG_EXTI_PORTE",
"rotary_encoder_exti_sys_line1": "LL_SYSCFG_EXTI_LINE3",
"rotary_encoder_exti_sys_line2": "LL_SYSCFG_EXTI_LINE4",
"rotary_encoder_timer": "TIM17",
"rotary_encoder_timer_irqn": "TIM17_IRQn",
"rotary_encoder_timer_irqhandler": "TIM17_IRQHandler"
},
"haptic": {
"haptic_pwm": true,
"haptic_gpio": "GPIO_PIN(GPIOB, 3)",
"haptic_gpio_af": "GPIO_AF1",
"haptic_timer": "TIM2",
"haptic_timer_freq": "(PERI1_FREQUENCY * TIMER_MULT_APB1)",
"haptic_counter_register": "HAPTIC_TIMER->CCR2",
"haptic_ccmr1": "TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2",
"haptic_ccer": "TIM_CCER_CC2E"
"haptic_gpio": "GPIO_PIN(GPIOE, 6)",
"haptic_gpio_timer": "TIM15",
"haptic_gpio_af": "GPIO_AF4",
"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"
}
}