From 1bc4f66032da07117cbbef63551d34ad1c2cd38b Mon Sep 17 00:00:00 2001 From: IanSB Date: Thu, 20 Apr 2023 01:51:39 +0100 Subject: [PATCH] Add mono board detection --- src/cpld_yuv.c | 2 +- src/filesystem.c | 43 +++++++++++++++++++++--------------- src/osd.c | 56 ++++++++++++++++++++++++++++++++--------------- src/rgb_to_hdmi.c | 10 ++++++++- src/rgb_to_hdmi.h | 1 + 5 files changed, 74 insertions(+), 38 deletions(-) diff --git a/src/cpld_yuv.c b/src/cpld_yuv.c index 5bd881ca..19fe0901 100644 --- a/src/cpld_yuv.c +++ b/src/cpld_yuv.c @@ -1434,7 +1434,7 @@ cpld_t cpld_yuv_analog = { .nameBBCprefix = "BBC", .nameRGBprefix = "RGB", .nameYUVprefix = "YUV", - .default_profile = "Apple/Apple_II", + .default_profile = "Apple_/Apple_II_", .init = cpld_init_analog, .get_version = cpld_get_version, .calibrate = cpld_calibrate, diff --git a/src/filesystem.c b/src/filesystem.c index 3b34a70c..e98be354 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -510,6 +510,7 @@ unsigned int file_read_profile(char *profile_name, int saved_config_number, char char path[MAX_STRING_SIZE]; FIL file; unsigned int bytes_read = 0; + command_string[bytes_read] = 0; if (updatecmd) { write_profile_choice(profile_name, saved_config_number, (char*)cpld->name); } @@ -599,6 +600,7 @@ void scan_cpld_filenames(char cpld_filenames[MAX_CPLD_FILENAMES][MAX_FILENAME_WI if (strcmp(filetype, ".xsvf") == 0) { strncpy(cpld_filenames[*count], fno.fname, MAX_FILENAME_WIDTH); cpld_filenames[*count][strlen(fno.fname) - 5] = 0; + log_info("Found CPLD: %s", cpld_filenames[*count]); (*count)++; } } @@ -625,20 +627,21 @@ void scan_profiles(char *prefix, char manufacturer_names[MAX_PROFILES][MAX_PROFI if (res != FR_OK || fno.fname[0] == 0 || *mcount == MAX_PROFILES) break; if (fno.fattrib & AM_DIR && strcmp(fno.fname, PAXHEADER) != 0) { fno.fname[MAX_PROFILE_WIDTH - 1] = 0; - int duplicate = 0; - if (*mcount != 0) { - for (int k = 0; k < *mcount; k++) { - if (strcmp(fno.fname, manufacturer_names[k]) == 0) { - duplicate = 1; - break; + if (mono_board_detected() == 0 || (mono_board_detected() == 1 && fno.fname[strlen(fno.fname) - 1] == '_')) { + int duplicate = 0; + if (*mcount != 0) { + for (int k = 0; k < *mcount; k++) { + if (strcmp(fno.fname, manufacturer_names[k]) == 0) { + duplicate = 1; + break; + } } } - } - - if (duplicate == 0) { - strcpy(manufacturer_names[*mcount], fno.fname); - (*mcount)++; - } else { + if (duplicate == 0) { + strcpy(manufacturer_names[*mcount], fno.fname); + (*mcount)++; + } else { + } } } } @@ -655,18 +658,22 @@ void scan_profiles(char *prefix, char manufacturer_names[MAX_PROFILES][MAX_PROFI if (res != FR_OK || fno.fname[0] == 0 || *count == MAX_PROFILES) break; if (fno.fattrib & AM_DIR && strcmp(fno.fname, PAXHEADER) != 0) { fno.fname[MAX_PROFILE_WIDTH - 1] = 0; - sprintf(profile_names[*count], "%s%s/%s", prefix, manufacturer_names[i], fno.fname); - log_info("Found profile: %s", profile_names[*count]); - (*count)++; + if (mono_board_detected() == 0 || (mono_board_detected() == 1 && fno.fname[strlen(fno.fname) - 1] == '_')) { + sprintf(profile_names[*count], "%s%s/%s", prefix, manufacturer_names[i], fno.fname); + log_info("Found profile: %s", profile_names[*count]); + (*count)++; + } } else { if (fno.fname[0] != '.' && strlen(fno.fname) > 4 && strcmp(fno.fname, DEFAULTTXT_STRING) != 0) { char* filetype = fno.fname + strlen(fno.fname)-4; if (strcmp(filetype, ".txt") == 0) { fno.fname[MAX_PROFILE_WIDTH - 1] = 0; fno.fname[strlen(fno.fname) - 4] = 0; - sprintf(profile_names[*count], "%s%s/%s", prefix, manufacturer_names[i], fno.fname); - log_info("Found profile: %s", profile_names[*count]); - (*count)++; + if (mono_board_detected() == 0 || (mono_board_detected() == 1 && fno.fname[strlen(fno.fname) - 1] == '_')) { + sprintf(profile_names[*count], "%s%s/%s", prefix, manufacturer_names[i], fno.fname); + log_info("Found profile: %s", profile_names[*count]); + (*count)++; + } } } } diff --git a/src/osd.c b/src/osd.c index fdd001f9..5f07d320 100644 --- a/src/osd.c +++ b/src/osd.c @@ -1469,9 +1469,9 @@ void osd_display_interface(int line) { gpioreg = (volatile uint32_t *)(_get_peripheral_base() + 0x101000UL); char osdline[256]; sprintf(osdline, "Interface: %s", get_interface_name()); - osd_set(line, 0, osdline); + osd_set(line++, 0, osdline); sprintf(osdline, "Scaling: %s", scaling_names[get_parameter(F_SCALING)]); - osd_set(line + 1, 0, osdline); + osd_set(line++, 0, osdline); char profile_name[MAX_PROFILE_WIDTH]; char *position = strchr(profile_names[get_parameter(F_PROFILE)], '/'); if (position) { @@ -1479,30 +1479,40 @@ void osd_display_interface(int line) { } else { strcpy(profile_name, profile_names[get_parameter(F_PROFILE)] + cpld_prefix_length); } + sprintf(osdline, "Profile: %s", profile_name); + for (int j=0; j < strlen(osdline); j++) { + if (*(osdline+j) == '_') { + *(osdline+j) = ' '; + } + } + osd_set(line++, 0, osdline); if (has_sub_profiles[get_parameter(F_PROFILE)]) { - sprintf(osdline, "Profile: %s (%s)", profile_name, sub_profile_names[get_parameter(F_SUB_PROFILE)]); - } else { - sprintf(osdline, "Profile: %s", profile_name); + sprintf(osdline, "Sub-Profile: %s", sub_profile_names[get_parameter(F_SUB_PROFILE)]); + for (int j=0; j < strlen(osdline); j++) { + if (*(osdline+j) == '_') { + *(osdline+j) = ' '; + } + } + osd_set(line++, 0, osdline); } - osd_set(line + 2, 0, osdline); #ifdef USE_ARM_CAPTURE - osd_set(line + 3, 0, "Warning: ARM Capture Version"); + osd_set(line++, 0, "Warning: ARM Capture Version"); #else - osd_set(line + 3, 0, "GPU Capture Version"); + osd_set(line++, 0, "GPU Capture Version"); #endif - + line++; if (get_parameter(F_FRONTEND) != FRONTEND_SIMPLE) { - osd_set(line + 5, 0, "Use Auto Calibrate Video Sampling or"); - osd_set(line + 6, 0, "adjust sampling phase to fix noise"); + osd_set(line++, 0, "Use Auto Calibrate Video Sampling or"); + osd_set(line++, 0, "adjust sampling phase to fix noise"); } - + line++; if (core_clock == 250) { // either a Pi 1 or Pi 2 which can be auto overclocked if (disable_overclock) { - osd_set(line + 8, 0, "Set disable_overclock=0 in config.txt"); - osd_set(line + 9, 0, "to enable 9BPP & 12BPP on Pi 1 or Pi 2"); + osd_set(line++, 0, "Set disable_overclock=0 in config.txt"); + osd_set(line++, 0, "to enable 9BPP & 12BPP on Pi 1 or Pi 2"); } else { - osd_set(line + 8, 0, "Set disable_overclock=1 in config.txt"); - osd_set(line + 9, 0, "if you have lockups on Pi 1 or Pi 2"); + osd_set(line++, 0, "Set disable_overclock=1 in config.txt"); + osd_set(line++, 0, "if you have lockups on Pi 1 or Pi 2"); } } @@ -1864,6 +1874,9 @@ static void redraw_menu() { } else { strcpy(mp, name); } + if (mp[strlen(mp) - 1] == '_') { + mp[strlen(mp) - 1] = 0; + } for (int j=0; j < strlen(mp); j++) { if (*(mp+j) == '_') { *(mp+j) = ' '; @@ -1892,6 +1905,9 @@ static void redraw_menu() { } else { strcpy(mp, name); } + if (mp[strlen(mp) - 1] == '_') { + mp[strlen(mp) - 1] = 0; + } for (int j=0; j < strlen(mp); j++) { if (*(mp+j) == '_') { *(mp+j) = ' '; @@ -1922,6 +1938,10 @@ static void redraw_menu() { strcpy(mp, get_param_string((param_menu_item_t *)item)); } int param_len = strlen(mp); + if (mp[param_len - 1] == '_') { + mp[param_len - 1] = 0; + param_len--; + } for (int j=0; j < param_len; j++) { if (*mp == '_') { *mp = ' '; @@ -5386,7 +5406,7 @@ int osd_key(int key) { redraw_menu(); break; case I_PICKPRO: - log_info("Selected Profile = %s %s", item_name(item), favourite_names[favourites_count]); + log_info("Selected Profile = %s %s %d", item_name(item), favourite_names[favourites_count], first_time_press); if (strcmp(favourite_names[favourites_count], item_name(item)) == 0) { favourites_count = 0; strcpy(favourite_names[favourites_count], FAVOURITES_MENU_CLEAR); @@ -5420,7 +5440,6 @@ int osd_key(int key) { file_save_bin(FAVOURITES_PATH, config_buffer, bytes_written); } strcpy(favourite_names[favourites_count], FAVOURITES_MENU_CLEAR); - if (strncmp(current_cpld_prefix, item_name(item), cpld_prefix_length) != 0) { char msg[256]; if (first_time_press == 0) { @@ -5459,6 +5478,7 @@ int osd_key(int key) { break; } } + log_info("CPLD update failed"); sprintf(msg, "CPLD update failed"); } } else { diff --git a/src/rgb_to_hdmi.c b/src/rgb_to_hdmi.c index c63fba44..55aa3e83 100644 --- a/src/rgb_to_hdmi.c +++ b/src/rgb_to_hdmi.c @@ -230,6 +230,7 @@ static int cpuspeed = 1000; static int cpld_fail_state = CPLD_NORMAL; static int helper_flag = 0; static int simple_detected = 0; +static int mono_detected = 0; static int supports8bit = 0; static int newanalog = 0; static int force_genlock_range = 0; @@ -1607,6 +1608,10 @@ int any_DAC_detected() { return DAC_detected; } +int mono_board_detected() { + return mono_detected; +} + void set_vsync_psync(int state) { cpld->set_vsync_psync(state); } @@ -1728,6 +1733,7 @@ static void init_hardware() { // Configure the GPCLK pin as a GPCLK RPI_SetGpioPinFunction(GPCLK_PIN, FS_ALT5); + if (simple_detected) { log_info("Simple board detected"); } else { @@ -1744,8 +1750,10 @@ static void init_hardware() { } } - if (sp_clk_state == 0) { + + if (sp_clk_state == 0 && simple_detected == 0 && supports8bit) { log_info("Mono / lumacode board detected"); + mono_detected = 1; } else { log_info("Standard board detected"); } diff --git a/src/rgb_to_hdmi.h b/src/rgb_to_hdmi.h index afa7a6a9..054a2db1 100644 --- a/src/rgb_to_hdmi.h +++ b/src/rgb_to_hdmi.h @@ -44,6 +44,7 @@ void set_helper_flag(); int eight_bit_detected(); int new_DAC_detected(); int any_DAC_detected(); +int mono_board_detected(); int extra_flags(); int calibrate_sampling_clock(int profile_changed); void DPMS(int dpms_state);