Skip to content

Commit 2d12faf

Browse files
committed
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 <Kris@KBEmbedded.com>
1 parent a982886 commit 2d12faf

File tree

3 files changed

+28
-65
lines changed

3 files changed

+28
-65
lines changed

pokemon_app.c

+1-30
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,6 @@
88
#include "views/select_pokemon.h"
99
#include "pokemon_char_encode.h"
1010

11-
12-
/* The MALVEKE board has an esp32 which is set to TX on the flipper's default
13-
* UART pins. If this pin shows signs of something connected, assume a MALVEKE
14-
* board is being used.
15-
*/
16-
static bool detect_malveke(void) {
17-
bool rc;
18-
19-
furi_hal_gpio_init(&gpio_usart_rx, GpioModeInput, GpioPullDown, GpioSpeedVeryHigh);
20-
//furi_hal_gpio_init(&gpio_swdio, GpioModeInput, GpioPullDown, GpioSpeedVeryHigh);
21-
/* Delay a tick to let the IO pin changes settle */
22-
furi_delay_tick(1);
23-
rc = furi_hal_gpio_read(&gpio_usart_rx);
24-
/* XXX: HACK: Need to clean this up later, but, newer MALVEKE boards use the
25-
* original pinout. Using a second pin to detect if there is a pullup to
26-
* determine if this is the board in use. In the future, it looks like the
27-
* GPIO module auto-detect support might be the better way here.
28-
*/
29-
if(furi_hal_gpio_read(&gpio_swdio)) rc = 0;
30-
furi_hal_gpio_init_simple(&gpio_usart_rx, GpioModeAnalog);
31-
//furi_hal_gpio_init_simple(&gpio_swdio, GpioModeAnalog);
32-
33-
return rc;
34-
}
35-
3611
PokemonFap* pokemon_alloc() {
3712
PokemonFap* pokemon_fap = (PokemonFap*)malloc(sizeof(PokemonFap));
3813

@@ -47,11 +22,7 @@ PokemonFap* pokemon_alloc() {
4722
ViewDispatcherTypeFullscreen);
4823

4924
// Set up defaults
50-
pokemon_fap->malveke_detected = detect_malveke();
51-
memcpy(
52-
&pokemon_fap->pins,
53-
&common_pinouts[pokemon_fap->malveke_detected],
54-
sizeof(struct gblink_pins));
25+
memcpy(&pokemon_fap->pins, &common_pinouts[PINOUT_ORIGINAL], sizeof(struct gblink_pins));
5526

5627
/* Set up gui modules used. It would be nice if these could be allocated and
5728
* freed as needed, however, the scene manager still requires pointers that

pokemon_app.h

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ struct pokemon_fap {
3737

3838
/* Pin definition to actual Game Link Cable interface */
3939
struct gblink_pins pins;
40-
int malveke_detected;
4140
};
4241

4342
typedef struct pokemon_fap PokemonFap;

scenes/pokemon_pins.c

+27-34
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
#include "../pokemon_app.h"
55
#include "pokemon_menu.h"
66

7-
struct named_pins {
8-
const char* text;
9-
const GpioPin* pin;
10-
};
11-
12-
/* XXX: These exist already in Flipper API */
13-
static const struct named_pins named_pins[] = {
14-
{"PA7", &gpio_ext_pa7},
15-
{"PA6", &gpio_ext_pa6},
16-
{"PA4", &gpio_ext_pa4},
17-
{"PB3", &gpio_ext_pb3},
18-
{"PB2", &gpio_ext_pb2},
19-
{"PC3", &gpio_ext_pc3},
20-
{"PC1", &gpio_ext_pc1},
21-
{"PC0", &gpio_ext_pc0},
22-
{},
23-
};
24-
7+
/* This is a bit of a hack to save some space and not have to refactor this scene.
8+
* We re-use the name and pin from the global gpio pin definition, but need to
9+
* skip the two debug pins in the row of header pins.
10+
*
11+
* This is hard-coded, not really portable, but saves a couple hundred bytes :D
12+
*
13+
* In the future, the right way to do this would be to build our own table of
14+
* non-debug pins from whatever the current platforms gpio pin definition is.
15+
*/
2516
#define NUM_PINS 8
17+
static const GpioPinRecord* named_pins[NUM_PINS] = {
18+
&gpio_pins[0],
19+
&gpio_pins[1],
20+
&gpio_pins[2],
21+
&gpio_pins[3],
22+
&gpio_pins[4],
23+
&gpio_pins[5],
24+
&gpio_pins[10],
25+
&gpio_pins[11]};
2626

2727
/* This must match gblink's enum order */
2828
static const char* named_groups[] = {
@@ -48,9 +48,9 @@ static struct itemlist_builder builder = {0};
4848
static void select_pins_rebuild_list(PokemonFap* pokemon_fap);
4949

5050
static void select_pins_set(PokemonFap* pokemon_fap) {
51-
pokemon_fap->pins.serin = named_pins[builder.serin_index].pin;
52-
pokemon_fap->pins.serout = named_pins[builder.serout_index].pin;
53-
pokemon_fap->pins.clk = named_pins[builder.clk_index].pin;
51+
pokemon_fap->pins.serin = named_pins[builder.serin_index]->pin;
52+
pokemon_fap->pins.serout = named_pins[builder.serout_index]->pin;
53+
pokemon_fap->pins.clk = named_pins[builder.clk_index]->pin;
5454
}
5555

5656
static void select_named_group_callback(VariableItem* item) {
@@ -67,7 +67,7 @@ static void select_pins_serin_callback(VariableItem* item) {
6767
uint8_t index = variable_item_get_current_value_index(item);
6868
PokemonFap* pokemon_fap = variable_item_get_context(item);
6969

70-
variable_item_set_current_value_text(item, named_pins[index].text);
70+
variable_item_set_current_value_text(item, named_pins[index]->name);
7171
builder.serin_index = index;
7272
select_pins_rebuild_list(pokemon_fap);
7373
variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 1);
@@ -77,7 +77,7 @@ static void select_pins_serout_callback(VariableItem* item) {
7777
uint8_t index = variable_item_get_current_value_index(item);
7878
PokemonFap* pokemon_fap = variable_item_get_context(item);
7979

80-
variable_item_set_current_value_text(item, named_pins[index].text);
80+
variable_item_set_current_value_text(item, named_pins[index]->name);
8181
builder.serout_index = index;
8282
select_pins_rebuild_list(pokemon_fap);
8383
variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 2);
@@ -87,7 +87,7 @@ static void select_pins_clk_callback(VariableItem* item) {
8787
uint8_t index = variable_item_get_current_value_index(item);
8888
PokemonFap* pokemon_fap = variable_item_get_context(item);
8989

90-
variable_item_set_current_value_text(item, named_pins[index].text);
90+
variable_item_set_current_value_text(item, named_pins[index]->name);
9191
builder.clk_index = index;
9292
select_pins_rebuild_list(pokemon_fap);
9393
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) {
117117
break;
118118
}
119119

120-
/* HACK: */
121-
pokemon_fap->malveke_detected = builder.named_index;
122-
123120
select_pins_set(pokemon_fap);
124121

125122
variable_item_list_reset(pokemon_fap->variable_item_list);
@@ -137,22 +134,18 @@ static void select_pins_rebuild_list(PokemonFap* pokemon_fap) {
137134
variable_item_set_current_value_text(builder.named, named_groups[builder.named_index]);
138135

139136
variable_item_set_current_value_index(builder.serin, (num == 1 ? 0 : builder.serin_index));
140-
variable_item_set_current_value_text(builder.serin, named_pins[builder.serin_index].text);
137+
variable_item_set_current_value_text(builder.serin, named_pins[builder.serin_index]->name);
141138

142139
variable_item_set_current_value_index(builder.serout, (num == 1 ? 0 : builder.serout_index));
143-
variable_item_set_current_value_text(builder.serout, named_pins[builder.serout_index].text);
140+
variable_item_set_current_value_text(builder.serout, named_pins[builder.serout_index]->name);
144141

145142
variable_item_set_current_value_index(builder.clk, (num == 1 ? 0 : builder.clk_index));
146-
variable_item_set_current_value_text(builder.clk, named_pins[builder.clk_index].text);
143+
variable_item_set_current_value_text(builder.clk, named_pins[builder.clk_index]->name);
147144
}
148145

149146
void select_pins_scene_on_enter(void* context) {
150147
PokemonFap* pokemon_fap = (PokemonFap*)context;
151148

152-
/* TODO: Figure out what defaults we should use for pins based on attached board! */
153-
/* HACK: */
154-
if(builder.named_index < 2) builder.named_index = pokemon_fap->malveke_detected;
155-
156149
select_pins_rebuild_list(pokemon_fap);
157150

158151
view_dispatcher_add_view(

0 commit comments

Comments
 (0)