Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: basic H7 support #5228

Merged
merged 7 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions radio/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ include(hal/CMakeLists.txt)
add_subdirectory(bitmaps)
add_subdirectory(fonts)

if(CPU_TYPE STREQUAL STM32H7)
include(targets/common/arm/stm32/h7/CMakeLists.txt)
endif()

if(CPU_TYPE STREQUAL STM32F4)
include(targets/common/arm/stm32/f4/CMakeLists.txt)
endif()
Expand Down
11 changes: 11 additions & 0 deletions radio/src/boards/generic_stm32/module_ports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,15 @@ static const stm32_pulse_timer_t trainerModuleTimer = {

static void _set_sport_input(uint8_t enable)
{
#if defined(TELEMETRY_DIR_GPIO)
if (TELEMETRY_SET_INPUT) {
gpio_write(TELEMETRY_DIR_GPIO, enable);
} else {
gpio_write(TELEMETRY_DIR_GPIO, !enable);
}
#else
(void)enable;
#endif
}

#if defined(TELEMETRY_TX_REV_GPIO) && defined(TELEMETRY_RX_REV_GPIO)
Expand All @@ -283,6 +287,7 @@ static void _sport_init_inverter()
}
#endif

#if defined(TELEMETRY_USART)
static const stm32_usart_t sportUSART = {
.USARTx = TELEMETRY_USART,
.txGPIO = TELEMETRY_TX_GPIO,
Expand All @@ -307,10 +312,13 @@ extern "C" void TELEMETRY_DMA_TX_IRQHandler(void)

DEFINE_STM32_SERIAL_PORT(SportModule, sportUSART, TELEMETRY_FIFO_SIZE, 0);

#if defined(TELEMETRY_DIR_GPIO)
static void _sport_direction_init()
{
gpio_init(TELEMETRY_DIR_GPIO, GPIO_OUT, GPIO_PIN_SPEED_MEDIUM);
}
#endif
#endif

#if defined(TELEMETRY_TIMER)
static const stm32_softserial_rx_port sportSoftRX = {
Expand Down Expand Up @@ -551,7 +559,10 @@ uint32_t __pxx1_get_inverter_comp() { return 1; }

void boardInitModulePorts()
{
#if defined(TELEMETRY_USART) && defined(TELEMETRY_DIR_GPIO)
_sport_direction_init();
#endif

#if defined(SPORT_UPDATE_PWR_GPIO)
sportUpdateInit();
#endif
Expand Down
4 changes: 2 additions & 2 deletions radio/src/dataconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define LABELS_LENGTH 100 // Maximum length of the label string
#define LABEL_LENGTH 16

#if defined(PCBHORUS) || defined(PCBNV14) || defined(PCBPL18)
#if defined(PCBHORUS) || defined(PCBNV14) || defined(PCBPL18) || defined(STM32H747xx)
#define MAX_MODELS 60
#define MAX_OUTPUT_CHANNELS 32 // number of real output channels CH1-CH32
#define MAX_FLIGHT_MODES 9
Expand Down Expand Up @@ -97,7 +97,7 @@ enum CurveType {
#define MIN_POINTS_PER_CURVE 3
#define MAX_POINTS_PER_CURVE 17

#if defined(PCBHORUS) || defined(PCBNV14) || defined(PCBPL18)
#if defined(COLORLCD)
#define LEN_MODEL_NAME 15
#define LEN_TIMER_NAME 8
#define LEN_FLIGHT_MODE_NAME 10
Expand Down
10 changes: 5 additions & 5 deletions radio/src/gui/colorlcd/layouts/layout_factory_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ class Layout: public LayoutBase
}

bool hasTopbar() const {
return getOptionValue(LAYOUT_OPTION_TOPBAR)->boolValue;
return ((uint8_t*)(&getOptionValue(LAYOUT_OPTION_TOPBAR)->boolValue))[0];
}

bool hasFlightMode() const {
return getOptionValue(LAYOUT_OPTION_FM)->boolValue;
return ((uint8_t*)(&getOptionValue(LAYOUT_OPTION_FM)->boolValue))[0];
}

bool hasSliders() const {
return getOptionValue(LAYOUT_OPTION_SLIDERS)->boolValue;
return ((uint8_t*)(&getOptionValue(LAYOUT_OPTION_SLIDERS)->boolValue))[0];
}

bool hasTrims() const {
return getOptionValue(LAYOUT_OPTION_TRIMS)->boolValue;
return ((uint8_t*)(&getOptionValue(LAYOUT_OPTION_TRIMS)->boolValue))[0];
}

bool isMirrored() const {
return getOptionValue(LAYOUT_OPTION_MIRRORED)->boolValue;
return ((uint8_t*)(&getOptionValue(LAYOUT_OPTION_MIRRORED)->boolValue))[0];
}

// Set decoration visibility
Expand Down
46 changes: 22 additions & 24 deletions radio/src/gui/colorlcd/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static lv_disp_drv_t* refr_disp = nullptr;
static void flushLcd(lv_disp_drv_t* disp_drv, const lv_area_t* area,
lv_color_t* color_p)
{
#if (!defined(LCD_VERTICAL_INVERT) || defined(RADIO_F16)) && !defined(BOOT)
#if (!defined(LCD_VERTICAL_INVERT) || defined(RADIO_F16)) && !defined(BOOT)
#if defined(RADIO_F16)
if (hardwareOptions.pcbrev > 0)
#endif
Expand Down Expand Up @@ -102,31 +102,29 @@ static void flushLcd(lv_disp_drv_t* disp_drv, const lv_area_t* area,

#if (!defined(LCD_VERTICAL_INVERT) || defined(RADIO_F16)) && !defined(BOOT)
#if defined(RADIO_F16)
if (hardwareOptions.pcbrev > 0)
if (hardwareOptions.pcbrev > 0)
#endif
{
uint16_t* src = (uint16_t*)color_p;
uint16_t* dst = nullptr;
if ((uint16_t*)color_p == LCD_FIRST_FRAME_BUFFER)
dst = LCD_SECOND_FRAME_BUFFER;
else
dst = LCD_FIRST_FRAME_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;

const lv_area_t& refr_area = disp->inv_areas[i];

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);
{
uint16_t* src = (uint16_t*)color_p;
uint16_t* dst = nullptr;
if ((uint16_t*)color_p == LCD_FIRST_FRAME_BUFFER)
dst = LCD_SECOND_FRAME_BUFFER;
else
dst = LCD_FIRST_FRAME_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;

const lv_area_t& refr_area = disp->inv_areas[i];

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);
}
}
DMAWait(); // wait for the last DMACopyBitmap to be completed before
// sending completion message
}
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions radio/src/gui/colorlcd/radio_sdmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ void RadioSdManagerPage::fileAction(const char* path, const char* name,
audioQueue.playFile(fullpath, 0, ID_PLAY_FROM_SD_MANAGER);
});
}
#if defined(HARDWARE_INTERNAL_MODULE) || defined(HARDWARE_EXTERNAL_MODULE)
#if defined(MULTIMODULE) && !defined(DISABLE_MULTI_UPDATE)
if (!strcasecmp(ext, MULTI_FIRMWARE_EXT)) {
MultiFirmwareInformation information;
Expand Down Expand Up @@ -409,6 +410,7 @@ void RadioSdManagerPage::fileAction(const char* path, const char* name,
#endif // _NYI_
}
}
#endif
#if defined(LUA)
else if (isExtensionMatching(ext, SCRIPTS_EXT)) {
menu->addLine(STR_EXECUTE_FILE, [=]() {
Expand Down
4 changes: 4 additions & 0 deletions radio/src/gui/colorlcd/radio_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class DateTimeWindow : public Window
}
};

#if defined(AUDIO)
static SetupLineDef soundPageSetupLines[] = {
{
// Beeps mode
Expand Down Expand Up @@ -252,6 +253,7 @@ static SetupLineDef soundPageSetupLines[] = {
}
},
};
#endif

#if defined(VARIO)
static SetupLineDef varioPageSetupLines[] = {
Expand Down Expand Up @@ -926,7 +928,9 @@ void RadioSetupPage::build(Window* window)

// Sub-pages
w = new SetupButtonGroup(window, {0, y, LCD_W - padding * 2, 0}, nullptr, BTN_COLS, PAD_TINY, {
#if defined(AUDIO)
{STR_SOUND_LABEL, []() { new SubPage(ICON_RADIO_SETUP, STR_RADIO_SETUP, STR_SOUND_LABEL, soundPageSetupLines, DIM(soundPageSetupLines)); }},
#endif
#if defined(VARIO)
{STR_VARIO, []() { new SubPage(ICON_RADIO_SETUP, STR_RADIO_SETUP, STR_VARIO, varioPageSetupLines, DIM(varioPageSetupLines)); }},
#endif
Expand Down
4 changes: 3 additions & 1 deletion radio/src/gui/colorlcd/widgets/radio_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ class DateTimeWidget : public TopBarWidget
void update() override
{
// get color from options
dateTime->setColor(persistentData->options[0].value.unsignedValue);
uint32_t color;
memcpy(&color, &persistentData->options[0].value.unsignedValue, sizeof(color));
dateTime->setColor(color);
}

HeaderDateTime* dateTime = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/widgets/widgets_container_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ class WidgetsContainerImpl : public WidgetsContainer

protected:
PersistentData* persistentData;
Widget* widgets[N] = {};
Widget* widgets[N] = {nullptr};
};
2 changes: 1 addition & 1 deletion radio/src/hal/adc_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ int adcGetInputIdx(const char* input, uint8_t len)
if (!strncmp(_hal_adc_inputs[type].inputs[i].name, input, len))
return idx;
}
} while(++type < ADC_INPUT_ALL);
} while (++type < ADC_INPUT_ALL);

return -1;
}
Expand Down
5 changes: 5 additions & 0 deletions radio/src/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,15 @@
#else //SIMU
#define LV_USE_GPU_STM32_DMA2D 1
#endif

#if LV_USE_GPU_STM32_DMA2D
/*Must be defined to include path of CMSIS header of target processor
e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
#ifdef STM32H7
#define LV_GPU_DMA2D_CMSIS_INCLUDE "stm32h7xx.h"
#else
#define LV_GPU_DMA2D_CMSIS_INCLUDE "stm32f4xx.h"
#endif
// #if !defined(DMA2D_NLR_PL_Pos)
// #define DMA2D_NLR_PL_Pos 16
// #endif
Expand Down
3 changes: 3 additions & 0 deletions radio/src/opentx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ void checkValidMCU(void)
#define TARGET_IDCODE 0x419
#elif defined(STM32F413xx)
#define TARGET_IDCODE 0x463
#elif defined(STM32H750xx) || defined(STM32H747xx)
#define TARGET_IDCODE 0x450
#else
// Ensure new radio get registered :)
#warning "Target MCU code undefined"
#define TARGET_IDCODE 0x0
#endif

Expand Down
9 changes: 7 additions & 2 deletions radio/src/pulses/crossfire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ static void _crsf_extmodule_frame_received()
// FreeRTOS methods from ISR with prio 0
static void _soft_irq_trigger(void*)
{
#ifndef STM32H7
EXTI->SWIER = TELEMETRY_RX_FRAME_EXTI_LINE;
#else
EXTI->SWIER1 = TELEMETRY_RX_FRAME_EXTI_LINE;
#endif
}
#endif

Expand Down Expand Up @@ -358,9 +362,10 @@ static void crossfireDeInit(void* ctx)
{
auto mod_st = (etx_module_state_t*)ctx;

memset(&crossfireModuleStatus[modulePortGetModule(mod_st)], 0, sizeof(crossfireModuleStatus[modulePortGetModule(mod_st)]));
memset(&crossfireModuleStatus[modulePortGetModule(mod_st)], 0,
sizeof(CrossfireModuleStatus));

#if !defined(SIMU)
#if !defined(SIMU) && defined(HARDWARE_EXTERNAL_MODULE)
if (mod_st && (modulePortGetModule(mod_st) == EXTERNAL_MODULE)) {
auto drv = modulePortGetSerialDrv(mod_st->rx);
auto ctx = modulePortGetCtx(mod_st->rx);
Expand Down
12 changes: 8 additions & 4 deletions radio/src/storage/yaml/yaml_bits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include <limits.h> /* CHAR_BIT */

#define _IS_ALIGNED(addr) (((intptr_t)addr & 0x3) == 0)

#define BIT_MASK(__TYPE__, __ONE_COUNT__) \
((__TYPE__) (-((__ONE_COUNT__) != 0))) \
& (((__TYPE__) -1) >> ((sizeof(__TYPE__) * CHAR_BIT) - (__ONE_COUNT__)))
Expand Down Expand Up @@ -107,10 +109,12 @@ bool yaml_is_zero(uint8_t* data, uint32_t bitoffs, uint32_t bits)
return !yaml_get_bits(data, bitoffs, bits);
}

while (bits >= 32) {
if (*(uint32_t*)data) return false;
data += 4;
bits -= 32;
if(_IS_ALIGNED(data)) {
while (bits >= 32) {
if (*(uint32_t*)data) return false;
data += 4;
bits -= 32;
}
}

while (bits >= 8) {
Expand Down
26 changes: 15 additions & 11 deletions radio/src/storage/yaml/yaml_datastructs_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,11 @@ void r_zov_color(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len)
{
data += bitoffs >> 3UL;
auto p_val = reinterpret_cast<ZoneOptionValue*>(data);

ZoneOptionValue zov;
if (strncmp(val, "COLIDX", 6) == 0) {
val += 6; val_len -= 6;
p_val->unsignedValue = COLOR2FLAGS(yaml_str2uint(val, val_len));
zov.unsignedValue = COLOR2FLAGS(yaml_str2uint(val, val_len));
} else {
if (val_len < sizeof("0xFFFFFF")-1
|| val[0] != '0'
Expand All @@ -556,28 +556,32 @@ void r_zov_color(void* user, uint8_t* data, uint32_t bitoffs,
val += 2; val_len -= 2;

auto rgb24 = yaml_hex2uint(val, val_len);
p_val->unsignedValue =
RGB2FLAGS((rgb24 & 0xFF0000) >> 16, (rgb24 & 0xFF00) >> 8, rgb24 & 0xFF);
zov.unsignedValue = RGB2FLAGS((rgb24 & 0xFF0000) >> 16,
(rgb24 & 0xFF00) >> 8, rgb24 & 0xFF);
}

memcpy(data, &zov, sizeof(ZoneOptionValue));
}

bool w_zov_color(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
data += bitoffs >> 3UL;
auto p_val = (reinterpret_cast<ZoneOptionValue*>(data))->unsignedValue;

if (p_val & RGB_FLAG) {
p_val = COLOR_VAL(p_val);
uint32_t color = (uint32_t)GET_RED(p_val) << 16 |
(uint32_t)GET_GREEN(p_val) << 8 |
(uint32_t)GET_BLUE(p_val);
ZoneOptionValue zov;
memcpy(&zov, data, sizeof(ZoneOptionValue));

uint32_t val = zov.unsignedValue;
if (val & RGB_FLAG) {
val = COLOR_VAL(val);
uint32_t color = (uint32_t)GET_RED(val) << 16 |
(uint32_t)GET_GREEN(val) << 8 | (uint32_t)GET_BLUE(val);

if (!wf(opaque, "0x", 2)) return false;
return wf(opaque, yaml_rgb2hex(color), 3 * 2);
} else {
if (!wf(opaque, "COLIDX", 6)) return false;
const char* str = yaml_unsigned2str(COLOR_VAL(p_val));
const char* str = yaml_unsigned2str(COLOR_VAL(val));
return wf(opaque, str, strlen(str));
}
}
Expand Down
1 change: 0 additions & 1 deletion radio/src/targets/common/arm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ endif()
if(HAPTIC)
add_definitions(-DHAPTIC)
set(SRC ${SRC} haptic.cpp)
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} haptic_driver.cpp)
endif()

# Protocols supported
Expand Down
4 changes: 4 additions & 0 deletions radio/src/targets/common/arm/stm32/abnormal_reboot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ void _init_reboot_cause()
_dbg_csr = LL_RCC_ReadReg(CSR);
#endif

#ifdef STM32H7
if (LL_RCC_IsActiveFlag_IWDG1RST()) {
#else
if (LL_RCC_IsActiveFlag_IWDGRST()) {
#endif
_reboot_cause = ARC_Watchdog;
} else if (LL_RCC_IsActiveFlag_SFTRST()) {
_reboot_cause = ARC_Software;
Expand Down
Loading