2015-11-20 01:59:09 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
2016-02-04 04:27:53 -05:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-11-20 01:59:09 -05:00
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_loadmodule.hpp"
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
|
|
|
|
#include "ff.h"
|
2016-02-04 04:27:53 -05:00
|
|
|
#include "event_m0.hpp"
|
2015-11-20 01:59:09 -05:00
|
|
|
#include "hackrf_gpio.hpp"
|
|
|
|
#include "portapack.hpp"
|
2016-01-05 14:17:55 -05:00
|
|
|
#include "portapack_shared_memory.hpp"
|
2015-11-20 01:59:09 -05:00
|
|
|
#include "hackrf_hal.hpp"
|
2016-02-04 04:27:53 -05:00
|
|
|
#include "string_format.hpp"
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2016-04-28 08:59:14 -04:00
|
|
|
#include "ui_rds.hpp"
|
|
|
|
#include "ui_xylos.hpp"
|
|
|
|
#include "ui_lcr.hpp"
|
2016-05-09 14:42:20 -04:00
|
|
|
#include "analog_audio_app.hpp"
|
|
|
|
#include "ui_soundboard.hpp"
|
2016-04-28 08:59:14 -04:00
|
|
|
#include "ui_debug.hpp"
|
2016-05-09 14:42:20 -04:00
|
|
|
#include "ui_audiotx.hpp"
|
2016-04-28 08:59:14 -04:00
|
|
|
|
2015-11-20 01:59:09 -05:00
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-02-06 17:19:28 -05:00
|
|
|
using namespace portapack;
|
2015-11-20 01:59:09 -05:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void LoadModuleView::focus() {
|
|
|
|
button_ok.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadModuleView::paint(Painter& painter) {
|
2016-01-05 05:47:46 -05:00
|
|
|
(void)painter;
|
2015-11-20 01:59:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadModuleView::on_hide() {
|
2016-02-04 04:27:53 -05:00
|
|
|
EventDispatcher::message_map().unregister_handler(Message::ID::ReadyForSwitch);
|
|
|
|
EventDispatcher::message_map().unregister_handler(Message::ID::ModuleID);
|
2015-11-20 01:59:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadModuleView::on_show() {
|
2016-02-06 17:19:28 -05:00
|
|
|
char md5_signature[16];
|
|
|
|
uint8_t c;
|
2016-01-05 14:17:55 -05:00
|
|
|
|
2016-02-06 17:19:28 -05:00
|
|
|
memcpy(md5_signature, (const void *)(0x10087FF0), 16);
|
|
|
|
for (c=0; c<16; c++) {
|
|
|
|
if (md5_signature[c] != _hash[c]) break;
|
|
|
|
}
|
2016-04-28 08:59:14 -04:00
|
|
|
//text_info.set(to_string_hex(*((unsigned int*)0x10087FF0), 8));
|
|
|
|
|
2016-02-06 17:19:28 -05:00
|
|
|
if (c == 16) {
|
|
|
|
text_info.set("Module already loaded :)");
|
|
|
|
_mod_loaded = true;
|
|
|
|
} else {
|
|
|
|
text_info.set("Loading module");
|
|
|
|
loadmodule();
|
|
|
|
}
|
2016-01-05 14:17:55 -05:00
|
|
|
}
|
|
|
|
|
2016-02-04 04:27:53 -05:00
|
|
|
int LoadModuleView::load_image() {
|
|
|
|
const char magic[6] = {'P', 'P', 'M', ' ', 0x02, 0x00};
|
|
|
|
UINT bw;
|
|
|
|
uint8_t i;
|
|
|
|
uint32_t cnt;
|
|
|
|
char md5sum[16];
|
|
|
|
FILINFO modinfo;
|
|
|
|
FIL modfile;
|
|
|
|
DIR rootdir;
|
|
|
|
FRESULT res;
|
|
|
|
|
|
|
|
// Scan SD card root directory for files with the right MD5 fingerprint at the right location
|
|
|
|
if (f_opendir(&rootdir, "/") == FR_OK) {
|
|
|
|
for (;;) {
|
|
|
|
res = f_readdir(&rootdir, &modinfo);
|
|
|
|
if (res != FR_OK || modinfo.fname[0] == 0) break; // Reached last file, abort
|
|
|
|
// Only care about files with .bin extension
|
|
|
|
if ((!(modinfo.fattrib & AM_DIR)) && (modinfo.fname[9] == 'B') && (modinfo.fname[10] == 'I') && (modinfo.fname[11] == 'N')) {
|
|
|
|
res = f_open(&modfile, modinfo.fname, FA_OPEN_EXISTING | FA_READ);
|
|
|
|
if (res != FR_OK) return 0;
|
|
|
|
// Magic bytes and version check
|
|
|
|
f_read(&modfile, &md5sum, 6, &bw);
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
if (md5sum[i] != magic[i]) break;
|
|
|
|
if (i == 6) {
|
|
|
|
f_lseek(&modfile, 26);
|
|
|
|
f_read(&modfile, &md5sum, 16, &bw);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
if (md5sum[i] != _hash[i]) break;
|
|
|
|
// f_read can't read more than 512 bytes at a time ?
|
|
|
|
if (i == 16) {
|
|
|
|
f_lseek(&modfile, 512);
|
|
|
|
for (cnt = 0; cnt < 64; cnt++) {
|
|
|
|
if (f_read(&modfile, reinterpret_cast<void*>(portapack::memory::map::m4_code.base() + (cnt * 512)), 512, &bw)) return 0;
|
|
|
|
}
|
|
|
|
f_close(&modfile);
|
|
|
|
f_closedir(&rootdir);
|
|
|
|
LPC_RGU->RESET_CTRL[0] = (1 << 13);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f_close(&modfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f_closedir(&rootdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-05 14:17:55 -05:00
|
|
|
void LoadModuleView::loadmodule() {
|
2016-02-04 04:27:53 -05:00
|
|
|
//message_map.unregister_handler(Message::ID::ReadyForSwitch);
|
|
|
|
|
2016-02-06 17:19:28 -05:00
|
|
|
m4_switch(_hash);
|
|
|
|
|
|
|
|
/*EventDispatcher::message_map().register_handler(Message::ID::ReadyForSwitch,
|
2015-11-20 01:59:09 -05:00
|
|
|
[this](Message* const p) {
|
2016-02-06 17:19:28 -05:00
|
|
|
(void)p;*/
|
2016-02-04 04:27:53 -05:00
|
|
|
if (load_image()) {
|
|
|
|
text_infob.set("Module loaded :)");
|
2015-11-20 01:59:09 -05:00
|
|
|
_mod_loaded = true;
|
|
|
|
} else {
|
|
|
|
text_info.set("Module not found :(");
|
|
|
|
_mod_loaded = false;
|
|
|
|
}
|
2016-02-06 17:19:28 -05:00
|
|
|
// }
|
|
|
|
//);
|
2015-11-20 01:59:09 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadModuleView::LoadModuleView(
|
|
|
|
NavigationView& nav,
|
|
|
|
const char * hash,
|
2016-05-09 14:42:20 -04:00
|
|
|
uint8_t ViewID,
|
|
|
|
bool loadplz
|
2015-11-20 01:59:09 -05:00
|
|
|
)
|
|
|
|
{
|
2016-05-09 14:42:20 -04:00
|
|
|
if (loadplz == false) nav.pop(); // Useless, remove !
|
|
|
|
|
2015-11-20 01:59:09 -05:00
|
|
|
add_children({ {
|
|
|
|
&text_info,
|
2016-02-04 04:27:53 -05:00
|
|
|
&text_infob,
|
2015-11-20 01:59:09 -05:00
|
|
|
&button_ok
|
|
|
|
} });
|
|
|
|
|
|
|
|
_hash = hash;
|
|
|
|
|
2016-04-28 08:59:14 -04:00
|
|
|
button_ok.on_select = [this, &nav, ViewID](Button&){
|
|
|
|
if (_mod_loaded == true) {
|
2016-05-09 14:42:20 -04:00
|
|
|
if (ViewID == 0) nav.push<AudioTXView>(); //nav.push<RDSView>();
|
2016-04-28 08:59:14 -04:00
|
|
|
if (ViewID == 1) nav.push<XylosView>();
|
|
|
|
if (ViewID == 2) nav.push<LCRView>();
|
2016-05-09 14:42:20 -04:00
|
|
|
if (ViewID == 3) nav.push<SoundBoardView>();
|
|
|
|
if (ViewID == 10) nav.push<AnalogAudioView>();
|
2016-04-28 08:59:14 -04:00
|
|
|
} else {
|
|
|
|
nav.pop();
|
|
|
|
}
|
2015-11-20 01:59:09 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|