Skip to content

Commit db9fa6b

Browse files
committed
pokemon_app: detect if MALVEKE present
If so, switch pin configuration to be compatible with that.
1 parent a9f399b commit db9fa6b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

pokemon_app.c

+20
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,20 @@ static void trade_block_free(TradeBlock* trade) {
21362136
free(trade);
21372137
}
21382138

2139+
/* The MALVEKE board has an esp32 which is set to TX on the flipper's default
2140+
* UART pins. If this pin shows signs of something connected, assume a MALVEKE
2141+
* board is being used.
2142+
*/
2143+
static bool detect_malveke(void) {
2144+
bool rc;
2145+
2146+
furi_hal_gpio_init(&gpio_usart_rx, GpioModeInput, GpioPullDown, GpioSpeedVeryHigh);
2147+
rc = furi_hal_gpio_read(&gpio_usart_rx);
2148+
furi_hal_gpio_init_simple(&gpio_usart_rx, GpioModeAnalog);
2149+
2150+
return rc;
2151+
}
2152+
21392153
PokemonFap* pokemon_alloc() {
21402154
PokemonFap* pokemon_fap = (PokemonFap*)malloc(sizeof(PokemonFap));
21412155

@@ -2157,6 +2171,11 @@ PokemonFap* pokemon_alloc() {
21572171
// Set up defaults
21582172
pokemon_fap->curr_pokemon = 0;
21592173
pokemon_fap->curr_stats = 0;
2174+
pokemon_fap->malveke_detected = detect_malveke();
2175+
memcpy(
2176+
&pokemon_fap->pins,
2177+
&common_pinouts[pokemon_fap->malveke_detected],
2178+
sizeof(struct gblink_pins));
21602179

21612180
// Set up trade party struct
21622181
pokemon_fap->trade_block = trade_block_alloc();
@@ -2189,6 +2208,7 @@ PokemonFap* pokemon_alloc() {
21892208
pokemon_fap->trade = trade_alloc(
21902209
pokemon_fap->trade_block,
21912210
pokemon_fap->pokemon_table,
2211+
&pokemon_fap->pins,
21922212
pokemon_fap->view_dispatcher,
21932213
AppViewTrade);
21942214

pokemon_app.h

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <gui/modules/submenu.h>
1111
#include <gui/modules/text_input.h>
1212
#include <gui/modules/variable_item_list.h>
13+
#include <gblink.h>
1314

1415
#include "pokemon_data.h"
1516

@@ -75,6 +76,10 @@ struct pokemon_fap {
7576
*/
7677
TradeBlock* trade_block;
7778

79+
/* Pin definition to actual Game Link Cable interface */
80+
struct gblink_pins pins;
81+
int malveke_detected;
82+
7883
/* The currently selected pokemon */
7984
int curr_pokemon;
8085

0 commit comments

Comments
 (0)