Skip to content

Commit

Permalink
pokemon_app: detect if MALVEKE present
Browse files Browse the repository at this point in the history
If so, switch pin configuration to be compatible with that.
  • Loading branch information
kbembedded committed Dec 17, 2023
1 parent a9f399b commit db9fa6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pokemon_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,20 @@ static void trade_block_free(TradeBlock* trade) {
free(trade);
}

/* 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);
rc = furi_hal_gpio_read(&gpio_usart_rx);
furi_hal_gpio_init_simple(&gpio_usart_rx, GpioModeAnalog);

return rc;
}

PokemonFap* pokemon_alloc() {
PokemonFap* pokemon_fap = (PokemonFap*)malloc(sizeof(PokemonFap));

Expand All @@ -2157,6 +2171,11 @@ PokemonFap* pokemon_alloc() {
// Set up defaults
pokemon_fap->curr_pokemon = 0;
pokemon_fap->curr_stats = 0;
pokemon_fap->malveke_detected = detect_malveke();
memcpy(
&pokemon_fap->pins,
&common_pinouts[pokemon_fap->malveke_detected],
sizeof(struct gblink_pins));

// Set up trade party struct
pokemon_fap->trade_block = trade_block_alloc();
Expand Down Expand Up @@ -2189,6 +2208,7 @@ PokemonFap* pokemon_alloc() {
pokemon_fap->trade = trade_alloc(
pokemon_fap->trade_block,
pokemon_fap->pokemon_table,
&pokemon_fap->pins,
pokemon_fap->view_dispatcher,
AppViewTrade);

Expand Down
5 changes: 5 additions & 0 deletions pokemon_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <gui/modules/submenu.h>
#include <gui/modules/text_input.h>
#include <gui/modules/variable_item_list.h>
#include <gblink.h>

#include "pokemon_data.h"

Expand Down Expand Up @@ -75,6 +76,10 @@ struct pokemon_fap {
*/
TradeBlock* trade_block;

/* Pin definition to actual Game Link Cable interface */
struct gblink_pins pins;
int malveke_detected;

/* The currently selected pokemon */
int curr_pokemon;

Expand Down

0 comments on commit db9fa6b

Please sign in to comment.