From d651b22379bd87e7996dd43434439c3be1c97261 Mon Sep 17 00:00:00 2001 From: Richard Li Date: Wed, 27 Mar 2024 15:01:08 +0800 Subject: [PATCH] Initial support of NB4+ --- fw.json | 1 + radio/src/datastructs.h | 8 +++- radio/src/targets/pl18/CMakeLists.txt | 5 +- radio/src/targets/pl18/hal.h | 16 +++++-- radio/src/targets/pl18/lcd_driver.cpp | 37 ++++++++++----- radio/src/targets/pl18/usb_descriptor.h | 20 ++++---- radio/util/hw_defs/legacy_names.py | 62 +++++++++++++++++++++++++ radio/util/hw_defs/pot_config.py | 7 +++ radio/util/hw_defs/switch_config.py | 10 ++++ tools/build-common.sh | 3 ++ 10 files changed, 142 insertions(+), 27 deletions(-) diff --git a/fw.json b/fw.json index 8300dc7cf..9eac988f3 100644 --- a/fw.json +++ b/fw.json @@ -6,6 +6,7 @@ ["Flysky NV14", "nv14-"], ["Flysky PL18", "pl18-"], ["Flysky PL18EV", "pl18ev-"], + ["Flysky NB4+", "nb4p-"], ["FrSky Horus X10", "x10-"], ["FrSky Horus X10 Express", "x10express-"], ["FrSky Horus X12s", "x12s-"], diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h index ef8fa03ea..2f54b69f3 100644 --- a/radio/src/datastructs.h +++ b/radio/src/datastructs.h @@ -73,7 +73,7 @@ static inline void check_struct() CHKSIZE(TimerData, 17); CHKSIZE(ModelHeader, 131); CHKSIZE(CustomScreenData, 1892); - #if defined(PCBNV14) + #if defined(PCBNV14) || defined(RADIO_NB4P) CHKTYPE(TopBarPersistentData, 704); #else CHKTYPE(TopBarPersistentData, 1048); @@ -107,7 +107,11 @@ static inline void check_struct() #elif defined(PCBNV14) CHKSIZE(ModelData, 26463); #elif defined(PCBPL18) - CHKSIZE(ModelData, 26845); + #if defined(RADIO_NB4P) + CHKSIZE(ModelData, 26499); + #else + CHKSIZE(ModelData, 26845); + #endif #elif defined(RADIO_T15) CHKSIZE(ModelData, 26834); #elif defined(PCBHORUS) diff --git a/radio/src/targets/pl18/CMakeLists.txt b/radio/src/targets/pl18/CMakeLists.txt index 860dcb250..43fbca566 100644 --- a/radio/src/targets/pl18/CMakeLists.txt +++ b/radio/src/targets/pl18/CMakeLists.txt @@ -40,7 +40,10 @@ add_definitions(-DSOFTWARE_VOLUME) add_definitions(-DSPI_FLASH) add_definitions(-DSTM32_SUPPORT_32BIT_TIMERS) -if(PCBREV STREQUAL PL18EV) +if(PCBREV STREQUAL NB4P) + set(FLAVOUR nb4p) + add_definitions(-DRADIO_NB4P) +elseif(PCBREV STREQUAL PL18EV) set(FLAVOUR pl18ev) add_definitions(-DRADIO_PL18EV) else() diff --git a/radio/src/targets/pl18/hal.h b/radio/src/targets/pl18/hal.h index fd34d0823..e0ad68d54 100644 --- a/radio/src/targets/pl18/hal.h +++ b/radio/src/targets/pl18/hal.h @@ -639,11 +639,17 @@ // SDRAM #define SDRAM_BANK1 -#define PORTRAIT_LCD false -#define LANDSCAPE_LCD true - -#define LCD_W 480 -#define LCD_H 320 +#if defined(RADIO_NB4P) + #define PORTRAIT_LCD true + #define LANDSCAPE_LCD false + #define LCD_W 320 + #define LCD_H 480 +#else + #define PORTRAIT_LCD false + #define LANDSCAPE_LCD true + #define LCD_W 480 + #define LCD_H 320 +#endif #define LCD_PHYS_W 320 #define LCD_PHYS_H 480 diff --git a/radio/src/targets/pl18/lcd_driver.cpp b/radio/src/targets/pl18/lcd_driver.cpp index 6b398fb3f..070bdb5f1 100644 --- a/radio/src/targets/pl18/lcd_driver.cpp +++ b/radio/src/targets/pl18/lcd_driver.cpp @@ -1150,18 +1150,33 @@ void LCD_ST7796S_Init(void) { lcdWriteData( 0x96 ); lcdWriteCommand( 0x36 ); - lcdWriteData( 0x28 ); + if (LCD_W != LCD_PHYS_W) { + lcdWriteData( 0x28 ); - lcdWriteCommand( 0x2A ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x01 ); - lcdWriteData( 0xDF ); - lcdWriteCommand( 0x2B ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x00 ); - lcdWriteData( 0x01 ); - lcdWriteData( 0x3F ); + lcdWriteCommand( 0x2A ); + lcdWriteData( 0x00 ); + lcdWriteData( 0x00 ); + lcdWriteData( 0x01 ); + lcdWriteData( 0xDF ); + lcdWriteCommand( 0x2B ); + lcdWriteData( 0x00 ); + lcdWriteData( 0x00 ); + lcdWriteData( 0x01 ); + lcdWriteData( 0x3F ); + } else { + lcdWriteData( 0x88 ); + + lcdWriteCommand( 0x2A ); + lcdWriteData( 0x00 ); + lcdWriteData( 0x00 ); + lcdWriteData( 0x01 ); + lcdWriteData( 0x3F ); + lcdWriteCommand( 0x2B ); + lcdWriteData( 0x00 ); + lcdWriteData( 0x00 ); + lcdWriteData( 0x01 ); + lcdWriteData( 0xDF ); + } lcdWriteCommand( 0x3A ); lcdWriteData( 0x66 ); diff --git a/radio/src/targets/pl18/usb_descriptor.h b/radio/src/targets/pl18/usb_descriptor.h index 27ec010c9..3e5c3293f 100644 --- a/radio/src/targets/pl18/usb_descriptor.h +++ b/radio/src/targets/pl18/usb_descriptor.h @@ -21,12 +21,16 @@ #pragma once -#if defined(RADIO_PL18EV) -#define USB_NAME "FlySky PL18EV" -#define USB_MANUFACTURER 'F', 'l', 'y', 'S', 'k', 'y', ' ', ' ' /* 8 bytes */ -#define USB_PRODUCT 'P', 'L', '1', '8', 'E', 'V', ' ', ' ' /* 8 Bytes */ -#else -#define USB_NAME "FlySky PL18" -#define USB_MANUFACTURER 'F', 'l', 'y', 'S', 'k', 'y', ' ', ' ' /* 8 bytes */ -#define USB_PRODUCT 'P', 'L', '1', '8', ' ', ' ', ' ', ' ' /* 8 Bytes */ +#if defined(RADIO_NB4P) + #define USB_NAME "FlySky NB4+" + #define USB_MANUFACTURER 'F', 'l', 'y', 'S', 'k', 'y', ' ', ' ' /* 8 bytes */ + #define USB_PRODUCT 'N', 'B', '4', '+', ' ', ' ', ' ', ' ' /* 8 Bytes */ +#elif defined(RADIO_PL18EV) + #define USB_NAME "FlySky PL18EV" + #define USB_MANUFACTURER 'F', 'l', 'y', 'S', 'k', 'y', ' ', ' ' /* 8 bytes */ + #define USB_PRODUCT 'P', 'L', '1', '8', 'E', 'V', ' ', ' ' /* 8 Bytes */ +#else + #define USB_NAME "FlySky PL18" + #define USB_MANUFACTURER 'F', 'l', 'y', 'S', 'k', 'y', ' ', ' ' /* 8 bytes */ + #define USB_PRODUCT 'P', 'L', '1', '8', ' ', ' ', ' ', ' ' /* 8 Bytes */ #endif diff --git a/radio/util/hw_defs/legacy_names.py b/radio/util/hw_defs/legacy_names.py index e41fcd1bc..2d2bcc874 100644 --- a/radio/util/hw_defs/legacy_names.py +++ b/radio/util/hw_defs/legacy_names.py @@ -679,6 +679,68 @@ LEGACY_NAMES = [ } } }, + { + "targets": { + "nb4p" + }, + "inputs": { + "LH": { + "yaml": "Rud", + "lua": "rud", + "description": "Rudder" + }, + "LV": { + "yaml": "Ele", + "lua": "ele", + "description": "Elevator" + }, + "RV": { + "yaml": "Thr", + "lua": "thr", + "description": "Throttle" + }, + "RH": { + "yaml": "Ail", + "lua": "ail", + "description": "Aileron" + }, + "P1": { + "yaml": "POT1", + "lua": "s1", + "label": "S1", + "short_label": "1", + "description": "Potentiometer 1" + }, + "P2": { + "yaml": "POT2", + "lua": "s2", + "label": "S2", + "short_label": "2", + "description": "Potentiometer 2" + }, + "P3": { + "yaml": "POT3", + "lua": "s3", + "label": "S3", + "short_label": "3", + "description": "Potentiometer 3" + }, + "SL1": { + "yaml": "LS", + "lua": "ls", + "label": "LS", + "short_label": "L", + "description": "Left slider" + }, + "SL2": { + "yaml": "RS", + "lua": "rs", + "label": "RS", + "short_label": "R", + "description": "Right slider" + }, + } + }, { "targets": {"v12", "v14"}, "inputs": { diff --git a/radio/util/hw_defs/pot_config.py b/radio/util/hw_defs/pot_config.py index 153beb93c..59aa1d263 100644 --- a/radio/util/hw_defs/pot_config.py +++ b/radio/util/hw_defs/pot_config.py @@ -39,6 +39,13 @@ POT_CONFIG = { "EXT3": {"default": "MULTIPOS"}, "EXT4": {"default": "MULTIPOS"} }, + "nb4p": { + "P1": {"default": "POT"}, + "P2": {"default": "POT"}, + "P3": {"default": "POT"}, + "SL1": {"default": "SLIDER"}, + "SL2": {"default": "SLIDER"} + }, "v12": { "P1": {"default": "POT_CENTER"}, "P2": {"default": "POT_CENTER"}, diff --git a/radio/util/hw_defs/switch_config.py b/radio/util/hw_defs/switch_config.py index 523cc69f8..5050d10b7 100644 --- a/radio/util/hw_defs/switch_config.py +++ b/radio/util/hw_defs/switch_config.py @@ -65,6 +65,16 @@ SWITCH_CONFIG = { "SI": { "default": "3POS" }, "SJ": { "default": "3POS" } }, + "nb4p": { + "SA": { "default": "2POS" }, + "SB": { "default": "3POS" }, + "SC": { "default": "2POS" }, + "SD": { "default": "3POS" }, + "SE": { "default": "3POS" }, + "SF": { "default": "2POS" }, + "SG": { "default": "3POS" }, + "SH": { "default": "TOGGLE" } + }, "lr3pro": { # left side "SA": {"default": "3POS", "display": [0, 0]}, diff --git a/tools/build-common.sh b/tools/build-common.sh index 6989b4f90..0aab3417f 100644 --- a/tools/build-common.sh +++ b/tools/build-common.sh @@ -143,6 +143,9 @@ get_target_build_options() { pl18ev) BUILD_OPTIONS+="-DPCB=PL18 -DPCBREV=PL18EV" ;; + nb4p) + BUILD_OPTIONS+="-DPCB=PL18 -DPCBREV=NB4P" + ;; *) echo "Unknown target: $target_name" return 1