Skip to content

Commit

Permalink
Merge pull request #283 from solosky/develop
Browse files Browse the repository at this point in the history
2.11.2
  • Loading branch information
solosky authored Oct 13, 2024
2 parents 6890a72 + 40ace4c commit d616fc5
Show file tree
Hide file tree
Showing 31 changed files with 1,626 additions and 1,395 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ fw/.settings
fw/_build
fw/.idea

fw/application/.idea
fw/bootloader/.idea

fw/src/amiibo_private.c
fw/src/version.inc.h
fw/src/version.json
Expand Down
10 changes: 5 additions & 5 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
{
"name": "Pixl.js Debug",
"includePath": [
"${workspaceFolder}/src/**",
"${workspaceFolder}/../components/**",
"D:/dev/SDKs/nRF5_SDK_17.1.0_ddde560/**"
"${workspaceFolder}/fw/application/src/**",
"${workspaceFolder}/fw/components/**",
"${NRF52_SDK_ROOT}/**"
],
"forcedInclude": [
"${workspaceFolder}/config/sdk_config.h"
"${workspaceFolder}/fw/application/config/sdk_config.h"
],
"defines": [
"BOARD_PCA10056",
Expand All @@ -24,7 +24,7 @@
"DEBUG_NRF",
"M_USE_THREAD_BACKEND=0"
],
"compilerPath": "D:/dev/SDKs/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc.exe",
"compilerPath": "/usr/local/bin/arm-none-eabi-gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-arm"
Expand Down
32 changes: 27 additions & 5 deletions fw/application/src/amiibo_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,31 @@ ret_code_t amiibo_helper_rand_amiibo_uuid(ntag_t *ntag) {
return err_code;
}

ret_code_t amiibo_helper_set_amiibo_uuid(ntag_t *ntag, uint8_t *uuid) {
ret_code_t err_code;
ntag_t ntag_new;
ntag_t *ntag_current = ntag;

memcpy(&ntag_new, ntag_current, sizeof(ntag_t));

if (!is_valid_amiibo_ntag(ntag_current)) {
return NRF_ERROR_INVALID_DATA;
}

if (!amiibo_helper_is_key_loaded()) {
return NRF_ERROR_INVALID_DATA;
}

ntag_store_set_uuid(&ntag_new, uuid);

// sign new
err_code = amiibo_helper_sign_new_ntag(ntag_current, &ntag_new);
if (err_code == NRF_SUCCESS) {
memcpy(ntag, &ntag_new, sizeof(ntag_t));
}
return err_code;
}

ret_code_t amiibo_helper_generate_amiibo(uint32_t head, uint32_t tail, ntag_t *ntag) {
if (!amiibo_helper_is_key_loaded()) {
return NRF_ERROR_INVALID_DATA;
Expand Down Expand Up @@ -192,20 +217,18 @@ void amiibo_helper_try_load_amiibo_keys_from_vfs() {
}
}

uint32_t to_little_endian_int32(const uint8_t* data){
uint32_t to_little_endian_int32(const uint8_t *data) {
uint32_t val = 0;
val += data[0];
val <<= 8;
val += data[1];
val <<= 8;
val += data[2];
val <<=8;
val <<= 8;
val += data[3];
return val;
}



bool is_valid_amiibo_ntag(const ntag_t *ntag) {
uint32_t head = to_little_endian_int32(&ntag->data[84]);
uint32_t tail = to_little_endian_int32(&ntag->data[88]);
Expand All @@ -224,4 +247,3 @@ bool is_valid_amiibo_ntag(const ntag_t *ntag) {

return false;
}

6 changes: 3 additions & 3 deletions fw/application/src/amiidb/db_amiibo.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ const db_amiibo_t amiibo_list[] = {
{0x08090000, 0x04350402, "Big Man", "鬼福"},
{0x08060100, 0x041c0402, "Smallfry", "小鲑鱼"},
{0x08010000, 0x04360402, "Callie - Alterna", "小拟 - 幻界"},
{0x08020200, 0x04370402, "Marie - Alterna", "小萤 - 幻界"},
{0x08030100, 0x04380402, "Pearl - Side Order", "小姬 - 秩序篇"},
{0x08040100, 0x04390402, "Marina - Side Order", "饭田 - 秩序篇"},
{0x08020000, 0x04370402, "Marie - Alterna", "小萤 - 幻界"},
{0x08030000, 0x04380402, "Pearl - Side Order", "小姬 - 秩序篇"},
{0x08040000, 0x04390402, "Marina - Side Order", "饭田 - 秩序篇"},
{0x00240000, 0x038d0002, "Piranha Plant", "吞食花"},
{0x00c00000, 0x037b0002, "King K. Rool", "库鲁鲁王"},
{0x01810000, 0x037d0002, "Isabelle", "西施惠"},
Expand Down
6 changes: 3 additions & 3 deletions fw/application/src/amiidb/db_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ const db_link_t link_list[] = {
{12, 0x08070000, 0x04330402, "", "暂无简介", ""},
{12, 0x08060100, 0x041c0402, "", "暂无简介", ""},
{12, 0x08010000, 0x04360402, "", "暂无简介", ""},
{12, 0x08020200, 0x04370402, "", "暂无简介", ""},
{12, 0x08030100, 0x04380402, "", "暂无简介", ""},
{12, 0x08040100, 0x04390402, "", "暂无简介", ""},
{12, 0x08020000, 0x04370402, "", "暂无简介", ""},
{12, 0x08030000, 0x04380402, "", "暂无简介", ""},
{12, 0x08040000, 0x04390402, "", "暂无简介", ""},
{13, 0x21060000, 0x03601202, "", "暂无简介", ""},
{13, 0x210b0000, 0x03a50002, "", "暂无简介", ""},
{13, 0x21070000, 0x03611202, "", "暂无简介", ""},
Expand Down
13 changes: 13 additions & 0 deletions fw/application/src/app/amiibo/app_amiibo.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void app_amiibo_on_run(mini_app_inst_t *p_app_inst) {
p_app_handle->p_msg_box = mui_msg_box_create();
mui_msg_box_set_user_data(p_app_handle->p_msg_box, p_app_handle);

p_app_handle->p_toast_view = mui_toast_view_create();
mui_toast_view_set_user_data(p_app_handle->p_toast_view, p_app_handle);

p_app_handle->p_scene_dispatcher = mui_scene_dispatcher_create();

string_init(p_app_handle->current_file);
Expand All @@ -67,6 +70,12 @@ void app_amiibo_on_run(mini_app_inst_t *p_app_inst) {

mui_view_dispatcher_attach(p_app_handle->p_view_dispatcher, MUI_LAYER_FULLSCREEN);

p_app_handle->p_view_dispatcher_toast = mui_view_dispatcher_create();
mui_view_dispatcher_add_view(p_app_handle->p_view_dispatcher_toast, AMIIBO_VIEW_ID_TOAST,
mui_toast_view_get_view(p_app_handle->p_toast_view));
mui_view_dispatcher_attach(p_app_handle->p_view_dispatcher_toast, MUI_LAYER_TOAST);
mui_view_dispatcher_switch_to_view(p_app_handle->p_view_dispatcher_toast, AMIIBO_VIEW_ID_TOAST);

extern const ntag_t default_ntag215;
APP_ERROR_CHECK(ntag_emu_init(&default_ntag215));

Expand Down Expand Up @@ -133,6 +142,10 @@ void app_amiibo_on_kill(mini_app_inst_t *p_app_inst) {
mui_scene_dispatcher_free(p_app_handle->p_scene_dispatcher);
amiibo_detail_view_free(p_app_handle->p_amiibo_detail_view);

mui_view_dispatcher_detach(p_app_handle->p_view_dispatcher_toast, MUI_LAYER_TOAST);
mui_view_dispatcher_free(p_app_handle->p_view_dispatcher_toast);
mui_toast_view_free(p_app_handle->p_toast_view);

string_clear(p_app_handle->current_file);
string_clear(p_app_handle->current_folder);
string_array_clear(p_app_handle->amiibo_files);
Expand Down
8 changes: 5 additions & 3 deletions fw/application/src/app/amiibo/app_amiibo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
#include "mui_msg_box.h"
#include "mui_scene_dispatcher.h"
#include "mui_text_input.h"
#include "mui_toast_view.h"
#include "ntag_def.h"
#include "vfs.h"

#include "mlib_common.h"


typedef struct {
amiibo_detail_view_t *p_amiibo_detail_view;
mui_list_view_t *p_list_view;
mui_text_input_t *p_text_input;
mui_msg_box_t *p_msg_box;
mui_toast_view_t *p_toast_view;
mui_view_dispatcher_t *p_view_dispatcher;
mui_scene_dispatcher_t *p_scene_dispatcher;
mui_view_dispatcher_t *p_view_dispatcher_toast;
ntag_t ntag;

/** file browser*/
vfs_drive_t current_drive;
string_t current_folder;
Expand All @@ -39,6 +41,7 @@ typedef enum {
AMIIBO_VIEW_ID_DETAIL,
AMIIBO_VIEW_ID_INPUT,
AMIIBO_VIEW_ID_MSG_BOX,
AMIIBO_VIEW_ID_TOAST
} amiibo_view_id_t;

typedef struct {
Expand All @@ -50,7 +53,6 @@ typedef struct {
uint32_t current_scene_id;
} app_amiibo_cache_data_t;


extern mini_app_t app_amiibo_info;

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum amiibo_detail_menu_t {
AMIIBO_DETAIL_MENU_RAND_UID,
AMIIBO_DETAIL_MENU_AUTO_RAND_UID,
AMIIBO_DETAIL_MENU_READ_ONLY,
AMIIBO_DETAIL_MENU_SET_CUSTOM_UID,
AMIIBO_DETAIL_MENU_REMOVE_AMIIBO,
AMIIBO_DETAIL_MENU_BACK_AMIIBO_DETAIL,
AMIIBO_DETAIL_MENU_BACK_FILE_BROWSER,
Expand All @@ -33,7 +34,6 @@ static ret_code_t amiibo_scene_amiibo_detail_set_readonly(app_amiibo_t *app, boo
vfs_obj_t obj;
uint8_t meta_buf[VFS_MAX_META_LEN];


cwalk_append_segment(path, string_get_cstr(app->current_folder), string_get_cstr(app->current_file));

vfs_driver_t *p_vfs_driver = vfs_get_driver(VFS_DRIVE_EXT);
Expand Down Expand Up @@ -112,6 +112,60 @@ static void amiibo_scene_amiibo_detail_delete_tag_confirmed(mui_msg_box_event_t
}
}

static void amiibo_scene_amiibo_detail_menu_text_input_set_id_event_cb(mui_text_input_event_t event,
mui_text_input_t *p_text_input) {
app_amiibo_t *app = p_text_input->user_data;
const char *input_text = mui_text_input_get_input_text(p_text_input);
if (event == MUI_TEXT_INPUT_EVENT_CONFIRMED && strlen(input_text) > 0) {

int8_t uid[7];
ret_code_t err_code;
char path[VFS_MAX_PATH_LEN];

ntag_t *ntag = &app->ntag;

// read uid from input
if (sscanf(input_text, "%02x.%02x.%02x.%02x.%02x.%02x.%02x", uid, uid + 1, uid + 2, uid + 3, uid + 4, uid + 5,
uid + 6) != 7) {
mui_toast_view_show(app->p_toast_view, _T(INAVLID_ID));
return;
}

// same uid as current tag
uint8_t cur_uid[7];
ntag_store_get_uuid(ntag, cur_uid);
if (memcmp(cur_uid, uid, 7) == 0) {
mui_scene_dispatcher_previous_scene(app->p_scene_dispatcher);
return;
}

// set current ntag uid
err_code = amiibo_helper_set_amiibo_uuid(ntag, uid);
if (err_code != NRF_SUCCESS) {
mui_toast_view_show(app->p_toast_view, _T(FAILED));
return;
}

// set ntag emu to emulate new tag
ntag_emu_set_tag(&app->ntag);

// save to file
vfs_driver_t *p_driver = vfs_get_driver(app->current_drive);

cwalk_append_segment(path, string_get_cstr(app->current_folder), string_get_cstr(app->current_file));
int32_t res = p_driver->write_file_data(path, ntag->data, sizeof(ntag->data));

if (res < 0) {
mui_toast_view_show(app->p_toast_view, _T(FAILED));
return;
}

mui_scene_dispatcher_previous_scene(app->p_scene_dispatcher);
} else {
mui_scene_dispatcher_previous_scene(app->p_scene_dispatcher);
}
}

static void amiibo_scene_amiibo_detail_menu_on_selected(mui_list_view_event_t event, mui_list_view_t *p_list_view,
mui_list_item_t *p_item) {
app_amiibo_t *app = p_list_view->user_data;
Expand Down Expand Up @@ -168,6 +222,27 @@ static void amiibo_scene_amiibo_detail_menu_on_selected(mui_list_view_event_t ev
p_item, (p_settings->auto_gen_amiibo ? getLangString(_L_ON_F) : getLangString(_L_OFF_F)));
} break;

case AMIIBO_DETAIL_MENU_SET_CUSTOM_UID: {
char id_text[32];
uint8_t id[7];
ntag_t *ntag = &app->ntag;

if (!amiibo_helper_is_key_loaded()) {
amiibo_scene_amiibo_detail_no_key_msg(app);
return;
}

ntag_store_get_uuid(ntag, id);

sprintf(id_text, "%02x.%02x.%02x.%02x.%02x.%02x.%02x", id[0], id[1], id[2], id[3], id[4], id[5], id[6]);

mui_text_input_set_header(app->p_text_input, getLangString(_L_INPUT_ID));
mui_text_input_set_input_text(app->p_text_input, id_text);
mui_text_input_set_event_cb(app->p_text_input, amiibo_scene_amiibo_detail_menu_text_input_set_id_event_cb);

mui_view_dispatcher_switch_to_view(app->p_view_dispatcher, AMIIBO_VIEW_ID_INPUT);
} break;

case AMIIBO_DETAIL_MENU_READ_ONLY: {
ret_code_t err_code = amiibo_scene_amiibo_detail_set_readonly(app, !app->ntag.read_only);
if (err_code == NRF_SUCCESS) {
Expand Down Expand Up @@ -207,6 +282,9 @@ void amiibo_scene_amiibo_detail_menu_on_enter(void *user_data) {
(p_settings->auto_gen_amiibo ? getLangString(_L_ON_F) : getLangString(_L_OFF_F)),
(void *)AMIIBO_DETAIL_MENU_AUTO_RAND_UID);

mui_list_view_add_item(app->p_list_view, 0xe1c8, getLangString(_L_SET_CUSTOM_ID),
(void *)AMIIBO_DETAIL_MENU_SET_CUSTOM_UID);

mui_list_view_add_item_ext(app->p_list_view, 0xe007, getLangString(_L_READ_ONLY),
app->ntag.read_only ? getLangString(_L_ON_F) : getLangString(_L_OFF_F),
(void *)AMIIBO_DETAIL_MENU_READ_ONLY);
Expand Down
6 changes: 6 additions & 0 deletions fw/application/src/app/settings/scene/settings_scene_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum settings_main_menu_t {
SETTINGS_MAIN_MENU_SHOW_MEM_USAGE,
SETTINGS_MAIN_MENU_SLEEP_TIMEOUT,
SETTINGS_MAIN_MENU_ANIM_ENABLED,
SETTINGS_MAIN_MENU_GO_SLEEP,
SETTINGS_MAIN_MENU_DFU,
SETTINGS_MAIN_MENU_REBOOT,
SETTINGS_MAIN_MENU_RESET_DEFAULT,
Expand Down Expand Up @@ -84,6 +85,10 @@ static void settings_scene_main_list_view_on_selected(mui_list_view_event_t even
mui_scene_dispatcher_next_scene(app->p_scene_dispatcher, SETTINGS_SCENE_LANGUAGE);
break;

case SETTINGS_MAIN_MENU_GO_SLEEP:
go_sleep();
break;

case SETTINGS_MAIN_MENU_DFU:
enter_dfu();
break;
Expand Down Expand Up @@ -205,6 +210,7 @@ static void settings_scene_main_reload(void *user_data) {
mui_list_view_add_item_ext(app->p_list_view, 0xe1c9, _T(APP_SET_SLEEP_TIMEOUT), txt,
(void *)SETTINGS_MAIN_MENU_SLEEP_TIMEOUT);

mui_list_view_add_item(app->p_list_view, 0xe1c9, _T(APP_SET_GO_SLEEP), (void *)SETTINGS_MAIN_MENU_GO_SLEEP);
mui_list_view_add_item(app->p_list_view, 0xe1ca, _T(APP_SET_DFU), (void *)SETTINGS_MAIN_MENU_DFU);
mui_list_view_add_item(app->p_list_view, 0xe1cb, _T(APP_SET_REBOOT), (void *)SETTINGS_MAIN_MENU_REBOOT);
mui_list_view_add_item(app->p_list_view, 0xe1ce, _T(APP_SET_RESET_DEFAULT),
Expand Down
5 changes: 5 additions & 0 deletions fw/application/src/i18n/de_DE.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const char * const lang_de_DE[_L_COUNT] = {
[_L_BACK] = "Zurück",
[_L_ERR] = "Fehler",
[_L_ERR_CODE] = "Fehlercode",
[_L_FAILED] = "",
[_L_APP_AMIIBO] = "Amiibo Emulator",
[_L_APP_AMIIBOLINK] = "AmiiboLink",
[_L_APP_BLE] = "BLE Dateitransfer",
Expand All @@ -26,6 +27,7 @@ const char * const lang_de_DE[_L_COUNT] = {
[_L_APP_SET_HIBERNATE] = "Schnelles Aufwachen",
[_L_APP_SET_SLEEP_TIMEOUT] = "Standby nach",
[_L_APP_SET_LANGUAGE] = "Sprache",
[_L_APP_SET_GO_SLEEP] = "",
[_L_APP_SET_DFU] = "Firmw. Aktualisierung",
[_L_APP_SET_REBOOT] = "System Neustart",
[_L_APP_SET_RESET_DEFAULT] = "Standardeinstellungen",
Expand All @@ -45,6 +47,9 @@ const char * const lang_de_DE[_L_COUNT] = {
[_L_KNOW] = "Verstanden",
[_L_RANDOM_GENERATION] = "Zufällige UUID",
[_L_AUTO_RANDOM_GENERATION] = "Zufällige UUID (Automatisch)",
[_L_SET_CUSTOM_ID] = "",
[_L_INPUT_ID] = "",
[_L_INAVLID_ID] = "",
[_L_SHOW_QRCODE] = "QR Code",
[_L_READ_ONLY] = "",
[_L_DELETE_TAG] = "Tag löschen",
Expand Down
5 changes: 5 additions & 0 deletions fw/application/src/i18n/en_US.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const char * const lang_en_US[_L_COUNT] = {
[_L_BACK] = "Back",
[_L_ERR] = "Error",
[_L_ERR_CODE] = "Error Code",
[_L_FAILED] = "Failed",
[_L_APP_AMIIBO] = "Amiibo Emulator",
[_L_APP_AMIIBOLINK] = "AmiiboLink",
[_L_APP_BLE] = "BLE File Transfer",
Expand All @@ -26,6 +27,7 @@ const char * const lang_en_US[_L_COUNT] = {
[_L_APP_SET_HIBERNATE] = "Fast Wakeup",
[_L_APP_SET_SLEEP_TIMEOUT] = "Sleep Timeout",
[_L_APP_SET_LANGUAGE] = "Language",
[_L_APP_SET_GO_SLEEP] = "Go Sleep",
[_L_APP_SET_DFU] = "Firmware Update",
[_L_APP_SET_REBOOT] = "System Reboot",
[_L_APP_SET_RESET_DEFAULT] = "Reset Default Setting",
Expand All @@ -45,6 +47,9 @@ const char * const lang_en_US[_L_COUNT] = {
[_L_KNOW] = "Got it",
[_L_RANDOM_GENERATION] = "Rand. Tag",
[_L_AUTO_RANDOM_GENERATION] = "Auto Rand.",
[_L_SET_CUSTOM_ID] = "Set Custom ID",
[_L_INPUT_ID] = "Input ID",
[_L_INAVLID_ID] = "Invalid ID",
[_L_SHOW_QRCODE] = "Display QR Code",
[_L_READ_ONLY] = "Read-only",
[_L_DELETE_TAG] = "Delete Tag",
Expand Down
Loading

0 comments on commit d616fc5

Please sign in to comment.