From 9246ea38b3b24f36e20a59e01a4a654f78fdb551 Mon Sep 17 00:00:00 2001 From: bkleiner Date: Fri, 23 Aug 2024 18:19:10 +0200 Subject: [PATCH] hdzero => displayport --- src/core/profile.c | 4 +- src/driver/osd/{hdzero.c => displayport.c} | 78 +++++++++++----------- src/driver/osd/displayport.h | 19 ++++++ src/driver/osd/hdzero.h | 19 ------ src/driver/osd/osd.c | 64 +++++++++--------- src/driver/osd/osd.h | 2 +- src/driver/serial.h | 2 +- src/driver/vtx/msp.c | 12 ++-- src/io/msp.c | 4 +- src/io/msp.h | 2 +- src/io/vtx.c | 4 +- 11 files changed, 105 insertions(+), 105 deletions(-) rename src/driver/osd/{hdzero.c => displayport.c} (65%) create mode 100644 src/driver/osd/displayport.h delete mode 100644 src/driver/osd/hdzero.h diff --git a/src/core/profile.c b/src/core/profile.c index 91b45699c..26c6c0127 100644 --- a/src/core/profile.c +++ b/src/core/profile.c @@ -173,8 +173,8 @@ const profile_t default_profile = { #else .smart_audio = SERIAL_PORT_INVALID, #endif -#ifdef HDZERO_USART - .hdzero = HDZERO_USART, +#ifdef DISPLAYPORT_USART + .hdzero = DISPLAYPORT_USART, #else .hdzero = SERIAL_PORT_INVALID, #endif diff --git a/src/driver/osd/hdzero.c b/src/driver/osd/displayport.c similarity index 65% rename from src/driver/osd/hdzero.c rename to src/driver/osd/displayport.c index ca4c6347a..0895af8ab 100644 --- a/src/driver/osd/hdzero.c +++ b/src/driver/osd/displayport.c @@ -1,4 +1,4 @@ -#include "driver/osd/hdzero.h" +#include "driver/osd/displayport.h" #include @@ -43,7 +43,7 @@ static ring_buffer_t rx_buffer = { .size = 512, }; -serial_port_t serial_hdzero = { +serial_port_t serial_displayport = { .rx_buffer = &rx_buffer, .tx_buffer = &tx_buffer, @@ -54,14 +54,14 @@ static const uint8_t msp_options[2] = {0, 1}; static volatile uint32_t last_heartbeat = 0; static bool is_detected = false; -static void hdzero_msp_send(msp_magic_t magic, uint8_t direction, uint16_t cmd, const uint8_t *data, uint16_t len) { +static void displayport_msp_send(msp_magic_t magic, uint8_t direction, uint16_t cmd, const uint8_t *data, uint16_t len) { if (cmd == MSP_FC_VARIANT) { // we got the first MSP_FC_VARIANT request, consider vtx detected is_detected = true; } if (magic == MSP2_MAGIC) { - if (serial_bytes_free(&serial_hdzero) < (len + MSP2_HEADER_LEN + 1)) { + if (serial_bytes_free(&serial_displayport) < (len + MSP2_HEADER_LEN + 1)) { return; } @@ -91,9 +91,9 @@ static void hdzero_msp_send(msp_magic_t magic, uint8_t direction, uint16_t cmd, buf[size++] = crc8_dvb_s2_data(crc, data, len); - serial_write_bytes(&serial_hdzero, buf, size); + serial_write_bytes(&serial_displayport, buf, size); } else if (len < 255) { - if (serial_bytes_free(&serial_hdzero) < (len + MSP_HEADER_LEN + 1)) { + if (serial_bytes_free(&serial_displayport) < (len + MSP_HEADER_LEN + 1)) { return; } @@ -115,21 +115,21 @@ static void hdzero_msp_send(msp_magic_t magic, uint8_t direction, uint16_t cmd, } buf[size++] = chksum; - serial_write_bytes(&serial_hdzero, buf, size); + serial_write_bytes(&serial_displayport, buf, size); } } static uint8_t msp_buffer[128]; -msp_t hdzero_msp = { +msp_t displayport_msp = { .buffer = msp_buffer, .buffer_size = 128, .buffer_offset = 0, - .send = hdzero_msp_send, + .send = displayport_msp_send, .device = MSP_DEVICE_VTX, }; -static bool hdzero_push_subcmd(displayport_subcmd_t subcmd, const uint8_t *data, const uint8_t len) { - if (serial_bytes_free(&serial_hdzero) < (MSP_HEADER_LEN + len + 2)) { +static bool displayport_push_subcmd(displayport_subcmd_t subcmd, const uint8_t *data, const uint8_t len) { + if (serial_bytes_free(&serial_displayport) < (MSP_HEADER_LEN + len + 2)) { return false; } @@ -152,10 +152,10 @@ static bool hdzero_push_subcmd(displayport_subcmd_t subcmd, const uint8_t *data, } buf[size++] = chksum; - return serial_write_bytes(&serial_hdzero, buf, size); + return serial_write_bytes(&serial_displayport, buf, size); } -static uint8_t hdzero_map_attr(uint8_t attr) { +static uint8_t displayport_map_attr(uint8_t attr) { uint8_t val = 0; if (attr & OSD_ATTR_INVERT) { val |= 0x1; @@ -169,7 +169,7 @@ static uint8_t hdzero_map_attr(uint8_t attr) { return val; } -void hdzero_init() { +void displayport_init() { serial_port_config_t config; config.port = profile.serial.hdzero; config.baudrate = 115200; @@ -179,21 +179,21 @@ void hdzero_init() { config.half_duplex = false; config.half_duplex_pp = false; - serial_init(&serial_hdzero, config); + serial_init(&serial_displayport, config); } -static void hdzero_wait_for_ready() { +static void displayport_wait_for_ready() { const uint32_t start = time_millis(); - while (!hdzero_is_ready()) { + while (!displayport_is_ready()) { if ((time_millis() - start) > 500) { return; } } } -void hdzero_intro() { - hdzero_wait_for_ready(); - hdzero_clear_async(); +void displayport_intro() { + displayport_wait_for_ready(); + displayport_clear_async(); uint8_t buffer[24]; for (uint8_t row = 0; row < 4; row++) { @@ -201,37 +201,37 @@ void hdzero_intro() { for (uint8_t i = 0; i < 24; i++) { buffer[i] = start + i; } - hdzero_wait_for_ready(); - hdzero_push_string(OSD_ATTR_TEXT, (HDZERO_COLS / 2) - 12, (HDZERO_ROWS / 2) - 2 + row, buffer, 24); + displayport_wait_for_ready(); + displayport_push_string(OSD_ATTR_TEXT, (DISPLAYPORT_COLS / 2) - 12, (DISPLAYPORT_ROWS / 2) - 2 + row, buffer, 24); } - hdzero_push_subcmd(SUBCMD_DRAW_SCREEN, NULL, 0); + displayport_push_subcmd(SUBCMD_DRAW_SCREEN, NULL, 0); } -uint8_t hdzero_clear_async() { - hdzero_push_subcmd(SUBCMD_SET_OPTIONS, msp_options, 2); - return hdzero_push_subcmd(SUBCMD_CLEAR_SCREEN, NULL, 0); +uint8_t displayport_clear_async() { + displayport_push_subcmd(SUBCMD_SET_OPTIONS, msp_options, 2); + return displayport_push_subcmd(SUBCMD_CLEAR_SCREEN, NULL, 0); } -bool hdzero_is_ready() { +bool displayport_is_ready() { while (true) { uint8_t data = 0; - if (!serial_read_bytes(&serial_hdzero, &data, 1)) { + if (!serial_read_bytes(&serial_displayport, &data, 1)) { break; } - msp_process_serial(&hdzero_msp, data); + msp_process_serial(&displayport_msp, data); } static bool was_detected = false; if (!was_detected && is_detected) { - hdzero_push_subcmd(SUBCMD_SET_OPTIONS, msp_options, 2); + displayport_push_subcmd(SUBCMD_SET_OPTIONS, msp_options, 2); was_detected = is_detected; return false; } if ((time_millis() - last_heartbeat) > 500) { - hdzero_push_subcmd(SUBCMD_HEARTBEAT, NULL, 0); + displayport_push_subcmd(SUBCMD_HEARTBEAT, NULL, 0); last_heartbeat = time_millis(); return false; } @@ -239,28 +239,28 @@ bool hdzero_is_ready() { return true; } -osd_system_t hdzero_check_system() { +osd_system_t displayport_check_system() { return OSD_SYS_HD; } -bool hdzero_push_string(uint8_t attr, uint8_t x, uint8_t y, const uint8_t *data, uint8_t size) { +bool displayport_push_string(uint8_t attr, uint8_t x, uint8_t y, const uint8_t *data, uint8_t size) { uint8_t buffer[size + 3]; buffer[0] = y; buffer[1] = x; - buffer[2] = hdzero_map_attr(attr); + buffer[2] = displayport_map_attr(attr); memcpy(buffer + 3, data, size); - return hdzero_push_subcmd(SUBCMD_WRITE_STRING, buffer, size + 3); + return displayport_push_subcmd(SUBCMD_WRITE_STRING, buffer, size + 3); } -bool hdzero_can_fit(uint8_t size) { - const uint32_t free = serial_bytes_free(&serial_hdzero); +bool displayport_can_fit(uint8_t size) { + const uint32_t free = serial_bytes_free(&serial_displayport); return free > (size + 10); } -bool hdzero_flush() { - return hdzero_push_subcmd(SUBCMD_DRAW_SCREEN, NULL, 0); +bool displayport_flush() { + return displayport_push_subcmd(SUBCMD_DRAW_SCREEN, NULL, 0); } #endif \ No newline at end of file diff --git a/src/driver/osd/displayport.h b/src/driver/osd/displayport.h new file mode 100644 index 000000000..4e40c83a6 --- /dev/null +++ b/src/driver/osd/displayport.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include "driver/osd/osd.h" + +#define DISPLAYPORT_ROWS 18 +#define DISPLAYPORT_COLS 50 + +void displayport_init(); +bool displayport_is_ready(); +void displayport_intro(); + +uint8_t displayport_clear_async(); +osd_system_t displayport_check_system(); + +bool displayport_can_fit(uint8_t size); +bool displayport_push_string(uint8_t attr, uint8_t x, uint8_t y, const uint8_t *data, uint8_t size); +bool displayport_flush(); \ No newline at end of file diff --git a/src/driver/osd/hdzero.h b/src/driver/osd/hdzero.h deleted file mode 100644 index 2deb22f37..000000000 --- a/src/driver/osd/hdzero.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include - -#include "driver/osd/osd.h" - -#define HDZERO_ROWS 18 -#define HDZERO_COLS 50 - -void hdzero_init(); -bool hdzero_is_ready(); -void hdzero_intro(); - -uint8_t hdzero_clear_async(); -osd_system_t hdzero_check_system(); - -bool hdzero_can_fit(uint8_t size); -bool hdzero_push_string(uint8_t attr, uint8_t x, uint8_t y, const uint8_t *data, uint8_t size); -bool hdzero_flush(); \ No newline at end of file diff --git a/src/driver/osd/osd.c b/src/driver/osd/osd.c index de21b1156..0655db3e7 100644 --- a/src/driver/osd/osd.c +++ b/src/driver/osd/osd.c @@ -3,34 +3,34 @@ #include #include "core/profile.h" -#include "driver/osd/hdzero.h" +#include "driver/osd/displayport.h" #include "driver/osd/max7456.h" #include "io/simulator.h" #include "util/util.h" -#define MAX_ROWS HDZERO_ROWS -#define MAX_COLS HDZERO_COLS +#define MAX_ROWS DISPLAYPORT_ROWS +#define MAX_COLS DISPLAYPORT_COLS -#define MAX_DISPLAY_SIZE (HDZERO_COLS * HDZERO_ROWS) +#define MAX_DISPLAY_SIZE (DISPLAYPORT_COLS * DISPLAYPORT_ROWS) static osd_segment_t osd_seg; static osd_device_t osd_device = OSD_DEVICE_NONE; static osd_char_t display[MAX_DISPLAY_SIZE]; -static bool display_row_dirty[HDZERO_ROWS]; +static bool display_row_dirty[DISPLAYPORT_ROWS]; static bool display_dirty = false; -static uint8_t cols = HDZERO_COLS; -static uint8_t rows = HDZERO_ROWS; +static uint8_t cols = DISPLAYPORT_COLS; +static uint8_t rows = DISPLAYPORT_ROWS; void osd_device_init() { #ifdef USE_DIGITAL_VTX if (profile.serial.hdzero != SERIAL_PORT_INVALID) { target_set_feature(FEATURE_OSD); - osd_device = OSD_DEVICE_HDZERO; - cols = HDZERO_COLS; - rows = HDZERO_ROWS; - hdzero_init(); + osd_device = OSD_DEVICE_DISPLAYPORT; + cols = DISPLAYPORT_COLS; + rows = DISPLAYPORT_ROWS; + displayport_init(); } #endif #ifdef USE_MAX7456 @@ -45,8 +45,8 @@ void osd_device_init() { { target_set_feature(FEATURE_OSD); osd_device = OSD_DEVICE_SIMULATOR; - cols = HDZERO_COLS; - rows = HDZERO_ROWS; + cols = DISPLAYPORT_COLS; + rows = DISPLAYPORT_ROWS; } #else { @@ -63,8 +63,8 @@ void osd_intro() { break; #endif #ifdef USE_DIGITAL_VTX - case OSD_DEVICE_HDZERO: - hdzero_intro(); + case OSD_DEVICE_DISPLAYPORT: + displayport_intro(); break; #endif #ifdef SIMULATOR @@ -104,8 +104,8 @@ uint8_t osd_clear_async() { break; #endif #ifdef USE_DIGITAL_VTX - case OSD_DEVICE_HDZERO: - if (!hdzero_clear_async()) { + case OSD_DEVICE_DISPLAYPORT: + if (!displayport_clear_async()) { return 0; } break; @@ -161,15 +161,15 @@ osd_system_t osd_check_system() { return max7456_check_system(); #endif #ifdef USE_DIGITAL_VTX - case OSD_DEVICE_HDZERO: - cols = HDZERO_COLS; - rows = HDZERO_ROWS; - return hdzero_check_system(); + case OSD_DEVICE_DISPLAYPORT: + cols = DISPLAYPORT_COLS; + rows = DISPLAYPORT_ROWS; + return displayport_check_system(); #endif #ifdef SIMULATOR case OSD_DEVICE_SIMULATOR: - cols = HDZERO_COLS; - rows = HDZERO_ROWS; + cols = DISPLAYPORT_COLS; + rows = DISPLAYPORT_ROWS; return simulator_osd_check_system(); #endif default: @@ -201,8 +201,8 @@ static bool osd_can_fit(uint8_t size) { return max7456_can_fit(size); #endif #ifdef USE_DIGITAL_VTX - case OSD_DEVICE_HDZERO: - return hdzero_can_fit(size); + case OSD_DEVICE_DISPLAYPORT: + return displayport_can_fit(size); #endif #ifdef SIMULATOR case OSD_DEVICE_SIMULATOR: @@ -224,8 +224,8 @@ static bool osd_push_string(uint8_t attr, uint8_t x, uint8_t y, const uint8_t *d return max7456_push_string(attr, x, y, data, size); #endif #ifdef USE_DIGITAL_VTX - case OSD_DEVICE_HDZERO: - return hdzero_push_string(attr, x, y, data, size); + case OSD_DEVICE_DISPLAYPORT: + return displayport_push_string(attr, x, y, data, size); #endif #ifdef SIMULATOR case OSD_DEVICE_SIMULATOR: @@ -243,8 +243,8 @@ static bool osd_flush() { return max7456_flush(); #endif #ifdef USE_DIGITAL_VTX - case OSD_DEVICE_HDZERO: - return hdzero_flush(); + case OSD_DEVICE_DISPLAYPORT: + return displayport_flush(); #endif #ifdef SIMULATOR case OSD_DEVICE_SIMULATOR: @@ -264,7 +264,7 @@ static bool osd_update_display() { continue; } - uint8_t string[HDZERO_COLS]; + uint8_t string[DISPLAYPORT_COLS]; uint8_t attr = 0; uint8_t start = cols; uint8_t size = 0; @@ -326,8 +326,8 @@ bool osd_is_ready() { return max7456_is_ready(); #endif #ifdef USE_DIGITAL_VTX - case OSD_DEVICE_HDZERO: - return hdzero_is_ready(); + case OSD_DEVICE_DISPLAYPORT: + return displayport_is_ready(); #endif #ifdef SIMULATOR case OSD_DEVICE_SIMULATOR: diff --git a/src/driver/osd/osd.h b/src/driver/osd/osd.h index 3e66c8049..cd6e771b6 100644 --- a/src/driver/osd/osd.h +++ b/src/driver/osd/osd.h @@ -31,7 +31,7 @@ typedef enum { typedef enum { OSD_DEVICE_NONE, OSD_DEVICE_MAX7456, - OSD_DEVICE_HDZERO, + OSD_DEVICE_DISPLAYPORT, OSD_DEVICE_SIMULATOR, } osd_device_t; diff --git a/src/driver/serial.h b/src/driver/serial.h index 24acf17e8..7710a283e 100644 --- a/src/driver/serial.h +++ b/src/driver/serial.h @@ -62,7 +62,7 @@ typedef struct { } usart_port_def_t; extern serial_port_t serial_rx; -extern serial_port_t serial_hdzero; +extern serial_port_t serial_displayport; extern serial_port_t serial_vtx; void serial_init(serial_port_t *serial, serial_port_config_t config); diff --git a/src/driver/vtx/msp.c b/src/driver/vtx/msp.c index 9f39e7d03..266d06348 100644 --- a/src/driver/vtx/msp.c +++ b/src/driver/vtx/msp.c @@ -5,7 +5,7 @@ #include "core/debug.h" #include "core/profile.h" -#include "driver/osd/hdzero.h" +#include "driver/osd/displayport.h" #include "driver/serial.h" #include "io/msp.h" #include "rx/unified_serial.h" @@ -58,7 +58,7 @@ static void serial_msp_send(msp_magic_t magic, uint8_t direction, uint16_t cmd, } } -extern msp_t hdzero_msp; +extern msp_t displayport_msp; extern msp_t crsf_msp; static uint8_t msp_rx_buffer[128]; @@ -71,9 +71,9 @@ static msp_t msp = { }; void serial_msp_vtx_init() { - if (serial_hdzero.config.port != SERIAL_PORT_INVALID) { + if (serial_displayport.config.port != SERIAL_PORT_INVALID) { // reuse existing msp for hdz - msp_vtx = &hdzero_msp; + msp_vtx = &displayport_msp; return; } @@ -104,8 +104,8 @@ void serial_msp_vtx_init() { } vtx_update_result_t serial_msp_vtx_update() { - if (serial_hdzero.config.port != SERIAL_PORT_INVALID) { - if (!hdzero_is_ready()) { + if (serial_displayport.config.port != SERIAL_PORT_INVALID) { + if (!displayport_is_ready()) { return VTX_WAIT; } return VTX_IDLE; diff --git a/src/io/msp.c b/src/io/msp.c index dc4d20098..5146fc614 100644 --- a/src/io/msp.c +++ b/src/io/msp.c @@ -317,8 +317,8 @@ static void msp_process_serial_cmd(msp_t *msp, msp_magic_t magic, uint16_t cmd, function = MSP_SERIAL_FUNCTION_SA; } } - if (i == serial_hdzero.config.port) { - function = MSP_SERIAL_FUNCTION_HDZERO; + if (i == serial_displayport.config.port) { + function = MSP_SERIAL_FUNCTION_DISPLAYPORT; } data[1 + i * 5 + 1] = (function >> 0) & 0xFF; diff --git a/src/io/msp.h b/src/io/msp.h index 11a6dd8e2..de3b46cc8 100644 --- a/src/io/msp.h +++ b/src/io/msp.h @@ -70,7 +70,7 @@ typedef enum { MSP_SERIAL_FUNCTION_RX = (1 << 0), MSP_SERIAL_FUNCTION_SA = (1 << 1), MSP_SERIAL_FUNCTION_TRAMP = (1 << 2), - MSP_SERIAL_FUNCTION_HDZERO = (1 << 3), + MSP_SERIAL_FUNCTION_DISPLAYPORT = (1 << 3), } msp_serial_function_t; typedef enum { diff --git a/src/io/vtx.c b/src/io/vtx.c index 5f3c31aaa..eafbfcbf7 100644 --- a/src/io/vtx.c +++ b/src/io/vtx.c @@ -147,7 +147,7 @@ static bool vtx_detect_protocol() { return true; } - if (serial_hdzero.config.port != SERIAL_PORT_INVALID) { + if (serial_displayport.config.port != SERIAL_PORT_INVALID) { vtx_settings.protocol = VTX_PROTOCOL_MSP_VTX; } @@ -326,7 +326,7 @@ void vtx_update() { } if (profile.serial.smart_audio == SERIAL_PORT_INVALID && - serial_hdzero.config.port == SERIAL_PORT_INVALID) { + serial_displayport.config.port == SERIAL_PORT_INVALID) { // no serial assigned to vtx or still in use by rx return; }