#FL-303 fix for some spi bugs, test app for sd-nfc interconnection (#247)

* sd-nfc test app

* do not hold spi in disable mode

* disable pullups in nfc chip
This commit is contained in:
DrZlo13
2020-11-18 16:01:25 +03:00
committed by GitHub
parent 9bbc8fafe5
commit 27ae2a8fa9
5 changed files with 225 additions and 16 deletions

View File

@@ -38,6 +38,7 @@ void app_gpio_test(void* p);
void app_ibutton(void* p);
void cli_task(void* p);
void music_player(void* p);
void sdnfc(void* p);
void floopper_bloopper(void* p);
const FlipperStartupApp FLIPPER_STARTUP[] = {
@@ -185,7 +186,14 @@ const FlipperStartupApp FLIPPER_STARTUP[] = {
#endif
#ifdef APP_FLOOPPER_BLOOPPER
{.app = floopper_bloopper, .name = "Floopper Bloopper", .libs = {1, FURI_LIB{"gui_task"}}},
{.app = floopper_bloopper,
.name = "Floopper Bloopper",
.libs = {1, FURI_LIB{"gui_task"}},
.icon = A_Games_14},
#endif
#ifdef APP_SDNFC
{.app = sdnfc, .name = "sdnfc", .libs = {1, FURI_LIB{"gui_task"}}, .icon = A_Plugins_14},
#endif
};
@@ -265,7 +273,13 @@ const FlipperStartupApp FLIPPER_PLUGINS[] = {
#endif
#ifdef BUILD_FLOOPPER_BLOOPPER
{.app = floopper_bloopper, .name = "Floopper Bloopper", .libs = {1, FURI_LIB{"gui_task"}}},
{.app = floopper_bloopper,
.name = "Floopper Bloopper",
.libs = {1, FURI_LIB{"gui_task"}},
.icon = A_Games_14},
#endif
#ifdef BUILD_SDNFC
{.app = sdnfc, .name = "sdnfc", .libs = {1, FURI_LIB{"gui_task"}}, .icon = A_Plugins_14},
#endif
};

View File

@@ -279,9 +279,19 @@ endif
BUILD_IBUTTON ?= 0
ifeq ($(BUILD_IBUTTON), 1)
CFLAGS += -DBUILD_IBUTTON
CPP_SOURCES += $(wildcard $(APP_DIR)/ibutton/ibutton.cpp)
CPP_SOURCES += $(APP_DIR)/ibutton/ibutton.cpp
endif
APP_SDNFC ?= 0
ifeq ($(APP_SDNFC), 1)
CFLAGS += -DAPP_SDNFC
BUILD_SDNFC = 1
endif
BUILD_SDNFC ?= 0
ifeq ($(BUILD_SDNFC), 1)
CFLAGS += -DBUILD_SDNFC
CPP_SOURCES += $(APP_DIR)/sdnfc/sdnfc.cpp
endif
# device drivers
APP_GUI ?= 0

View File

@@ -0,0 +1,164 @@
#include "app-template.h"
extern "C" {
#include <rfal_analogConfig.h>
#include <rfal_rf.h>
#include <rfal_nfc.h>
#include <rfal_nfca.h>
#include <st25r3916.h>
#include <st25r3916_irq.h>
}
#include "fatfs/ff.h"
#include "stm32_adafruit_sd.h"
// event enumeration type
typedef uint8_t event_t;
// app state class
class AppSdNFCState {
public:
// state data
const char* name;
// state initializer
AppSdNFCState() {
name = "sd nfc test";
}
};
// app events class
class AppSdNFCEvent {
public:
// events enum
static const event_t EventTypeTick = 0;
static const event_t EventTypeKey = 1;
// payload
union {
InputEvent input;
} value;
// event type
event_t type;
};
// our app derived from base AppTemplate class
// with template variables <state, events>
class AppSdNFC : public AppTemplate<AppSdNFCState, AppSdNFCEvent> {
public:
GpioPin* red_led_record;
GpioPin* green_led_record;
void run();
void render(CanvasApi* canvas);
void set_error(const char* text);
void set_text(const char* text);
void light_red();
void light_green();
void blink_red();
void blink_green();
};
FATFS sd_fat_fs;
char sd_path[6] = "";
// start app
void AppSdNFC::run() {
// create pin
GpioPin red_led = led_gpio[0];
GpioPin green_led = led_gpio[1];
// TODO open record
red_led_record = &red_led;
green_led_record = &green_led;
// configure pin
gpio_init(red_led_record, GpioModeOutputOpenDrain);
gpio_init(green_led_record, GpioModeOutputOpenDrain);
uint8_t rfal_result = rfalNfcInitialize();
if(rfal_result) {
set_text("rfal init fail");
blink_red();
}
uint8_t bsp_result = BSP_SD_Init();
if(bsp_result) {
set_error("sd init fail");
}
FRESULT result;
result = f_mount(&sd_fat_fs, sd_path, 1);
if(result) {
set_error("sd mount fail");
}
light_green();
set_text("all good");
AppSdNFCEvent event;
while(1) {
if(get_event(&event, 1000)) {
if(event.type == AppSdNFCEvent::EventTypeKey) {
// press events
if(event.value.input.state && event.value.input.input == InputBack) {
exit();
}
}
}
// signal to force gui update
update_gui();
};
}
// render app
void AppSdNFC::render(CanvasApi* canvas) {
canvas->set_color(canvas, ColorBlack);
canvas->set_font(canvas, FontPrimary);
canvas->draw_str(canvas, 2, 12, state.name);
}
void AppSdNFC::set_error(const char* text) {
light_red();
set_text(text);
update_gui();
while(1)
;
}
void AppSdNFC::set_text(const char* text) {
acquire_state();
state.name = text;
release_state();
}
void AppSdNFC::light_red() {
gpio_write(red_led_record, false);
}
void AppSdNFC::light_green() {
gpio_write(green_led_record, false);
}
void AppSdNFC::blink_red() {
gpio_write(red_led_record, false);
delay(500);
gpio_write(red_led_record, true);
delay(500);
}
void AppSdNFC::blink_green() {
gpio_write(green_led_record, false);
delay(500);
gpio_write(green_led_record, true);
delay(500);
}
// app enter function
extern "C" void sdnfc(void* p) {
AppSdNFC* app = new AppSdNFC();
app->run();
}