From 2d12faf562a26e51629d742189febff245a847f4 Mon Sep 17 00:00:00 2001 From: Kris Bahnsen Date: Sat, 3 Feb 2024 20:56:43 -0800 Subject: [PATCH] pokemon_data: remove MALVEKE check Default pinout to Original, MALVEKE can be manually set, newer MALVEKE boards are transitioning to the Original pinout, so as time goes on there will be fewer and fewer MALVEKE pinned boards. Also save some codespace by re-using the in-firmware pin names Signed-off-by: Kris Bahnsen --- pokemon_app.c | 31 +--------------------- pokemon_app.h | 1 - scenes/pokemon_pins.c | 61 +++++++++++++++++++------------------------ 3 files changed, 28 insertions(+), 65 deletions(-) diff --git a/pokemon_app.c b/pokemon_app.c index b63bed5ebaa..200d892cabd 100644 --- a/pokemon_app.c +++ b/pokemon_app.c @@ -8,31 +8,6 @@ #include "views/select_pokemon.h" #include "pokemon_char_encode.h" - -/* The MALVEKE board has an esp32 which is set to TX on the flipper's default - * UART pins. If this pin shows signs of something connected, assume a MALVEKE - * board is being used. - */ -static bool detect_malveke(void) { - bool rc; - - furi_hal_gpio_init(&gpio_usart_rx, GpioModeInput, GpioPullDown, GpioSpeedVeryHigh); - //furi_hal_gpio_init(&gpio_swdio, GpioModeInput, GpioPullDown, GpioSpeedVeryHigh); - /* Delay a tick to let the IO pin changes settle */ - furi_delay_tick(1); - rc = furi_hal_gpio_read(&gpio_usart_rx); - /* XXX: HACK: Need to clean this up later, but, newer MALVEKE boards use the - * original pinout. Using a second pin to detect if there is a pullup to - * determine if this is the board in use. In the future, it looks like the - * GPIO module auto-detect support might be the better way here. - */ - if(furi_hal_gpio_read(&gpio_swdio)) rc = 0; - furi_hal_gpio_init_simple(&gpio_usart_rx, GpioModeAnalog); - //furi_hal_gpio_init_simple(&gpio_swdio, GpioModeAnalog); - - return rc; -} - PokemonFap* pokemon_alloc() { PokemonFap* pokemon_fap = (PokemonFap*)malloc(sizeof(PokemonFap)); @@ -47,11 +22,7 @@ PokemonFap* pokemon_alloc() { ViewDispatcherTypeFullscreen); // Set up defaults - pokemon_fap->malveke_detected = detect_malveke(); - memcpy( - &pokemon_fap->pins, - &common_pinouts[pokemon_fap->malveke_detected], - sizeof(struct gblink_pins)); + memcpy(&pokemon_fap->pins, &common_pinouts[PINOUT_ORIGINAL], sizeof(struct gblink_pins)); /* Set up gui modules used. It would be nice if these could be allocated and * freed as needed, however, the scene manager still requires pointers that diff --git a/pokemon_app.h b/pokemon_app.h index cc6973b04d8..e29d92b5ae0 100644 --- a/pokemon_app.h +++ b/pokemon_app.h @@ -37,7 +37,6 @@ struct pokemon_fap { /* Pin definition to actual Game Link Cable interface */ struct gblink_pins pins; - int malveke_detected; }; typedef struct pokemon_fap PokemonFap; diff --git a/scenes/pokemon_pins.c b/scenes/pokemon_pins.c index 92ebe777b09..835f551f65d 100644 --- a/scenes/pokemon_pins.c +++ b/scenes/pokemon_pins.c @@ -4,25 +4,25 @@ #include "../pokemon_app.h" #include "pokemon_menu.h" -struct named_pins { - const char* text; - const GpioPin* pin; -}; - -/* XXX: These exist already in Flipper API */ -static const struct named_pins named_pins[] = { - {"PA7", &gpio_ext_pa7}, - {"PA6", &gpio_ext_pa6}, - {"PA4", &gpio_ext_pa4}, - {"PB3", &gpio_ext_pb3}, - {"PB2", &gpio_ext_pb2}, - {"PC3", &gpio_ext_pc3}, - {"PC1", &gpio_ext_pc1}, - {"PC0", &gpio_ext_pc0}, - {}, -}; - +/* This is a bit of a hack to save some space and not have to refactor this scene. + * We re-use the name and pin from the global gpio pin definition, but need to + * skip the two debug pins in the row of header pins. + * + * This is hard-coded, not really portable, but saves a couple hundred bytes :D + * + * In the future, the right way to do this would be to build our own table of + * non-debug pins from whatever the current platforms gpio pin definition is. + */ #define NUM_PINS 8 +static const GpioPinRecord* named_pins[NUM_PINS] = { + &gpio_pins[0], + &gpio_pins[1], + &gpio_pins[2], + &gpio_pins[3], + &gpio_pins[4], + &gpio_pins[5], + &gpio_pins[10], + &gpio_pins[11]}; /* This must match gblink's enum order */ static const char* named_groups[] = { @@ -48,9 +48,9 @@ static struct itemlist_builder builder = {0}; static void select_pins_rebuild_list(PokemonFap* pokemon_fap); static void select_pins_set(PokemonFap* pokemon_fap) { - pokemon_fap->pins.serin = named_pins[builder.serin_index].pin; - pokemon_fap->pins.serout = named_pins[builder.serout_index].pin; - pokemon_fap->pins.clk = named_pins[builder.clk_index].pin; + pokemon_fap->pins.serin = named_pins[builder.serin_index]->pin; + pokemon_fap->pins.serout = named_pins[builder.serout_index]->pin; + pokemon_fap->pins.clk = named_pins[builder.clk_index]->pin; } static void select_named_group_callback(VariableItem* item) { @@ -67,7 +67,7 @@ static void select_pins_serin_callback(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); PokemonFap* pokemon_fap = variable_item_get_context(item); - variable_item_set_current_value_text(item, named_pins[index].text); + variable_item_set_current_value_text(item, named_pins[index]->name); builder.serin_index = index; select_pins_rebuild_list(pokemon_fap); variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 1); @@ -77,7 +77,7 @@ static void select_pins_serout_callback(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); PokemonFap* pokemon_fap = variable_item_get_context(item); - variable_item_set_current_value_text(item, named_pins[index].text); + variable_item_set_current_value_text(item, named_pins[index]->name); builder.serout_index = index; select_pins_rebuild_list(pokemon_fap); variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 2); @@ -87,7 +87,7 @@ static void select_pins_clk_callback(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); PokemonFap* pokemon_fap = variable_item_get_context(item); - variable_item_set_current_value_text(item, named_pins[index].text); + variable_item_set_current_value_text(item, named_pins[index]->name); builder.clk_index = index; select_pins_rebuild_list(pokemon_fap); variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 3); @@ -117,9 +117,6 @@ static void select_pins_rebuild_list(PokemonFap* pokemon_fap) { break; } - /* HACK: */ - pokemon_fap->malveke_detected = builder.named_index; - select_pins_set(pokemon_fap); variable_item_list_reset(pokemon_fap->variable_item_list); @@ -137,22 +134,18 @@ static void select_pins_rebuild_list(PokemonFap* pokemon_fap) { variable_item_set_current_value_text(builder.named, named_groups[builder.named_index]); variable_item_set_current_value_index(builder.serin, (num == 1 ? 0 : builder.serin_index)); - variable_item_set_current_value_text(builder.serin, named_pins[builder.serin_index].text); + variable_item_set_current_value_text(builder.serin, named_pins[builder.serin_index]->name); variable_item_set_current_value_index(builder.serout, (num == 1 ? 0 : builder.serout_index)); - variable_item_set_current_value_text(builder.serout, named_pins[builder.serout_index].text); + variable_item_set_current_value_text(builder.serout, named_pins[builder.serout_index]->name); variable_item_set_current_value_index(builder.clk, (num == 1 ? 0 : builder.clk_index)); - variable_item_set_current_value_text(builder.clk, named_pins[builder.clk_index].text); + variable_item_set_current_value_text(builder.clk, named_pins[builder.clk_index]->name); } void select_pins_scene_on_enter(void* context) { PokemonFap* pokemon_fap = (PokemonFap*)context; - /* TODO: Figure out what defaults we should use for pins based on attached board! */ - /* HACK: */ - if(builder.named_index < 2) builder.named_index = pokemon_fap->malveke_detected; - select_pins_rebuild_list(pokemon_fap); view_dispatcher_add_view(