SD card detection and filesystem mounting.

This commit is contained in:
Jared Boone 2015-11-10 15:24:42 -08:00
parent 9f6c495fef
commit 987ea3555d
4 changed files with 84 additions and 9 deletions

View file

@ -52,6 +52,8 @@
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
#include "sd_card.hpp"
#include <string.h>
class EventDispatcher {
@ -87,6 +89,7 @@ private:
ui::Context& context;
uint32_t encoder_last = 0;
bool is_running = true;
bool sd_card_present = false;
eventmask_t wait() {
return chEvtWaitAny(ALL_EVENTS);
@ -105,10 +108,6 @@ private:
handle_lcd_frame_sync();
}
if( events & EVT_MASK_SD_CARD_PRESENT ) {
handle_sd_card_detect();
}
if( events & EVT_MASK_SWITCHES ) {
handle_switches();
}
@ -130,7 +129,28 @@ private:
}
void handle_rtc_tick() {
const auto sd_card_present_now = sdc_lld_is_card_inserted(&SDCD1);
if( sd_card_present_now != sd_card_present ) {
sd_card_present = sd_card_present_now;
if( sd_card_present ) {
if( sdcConnect(&SDCD1) == CH_SUCCESS ) {
if( sd_card::filesystem::mount() == FR_OK ) {
SDCardStatusMessage message { true };
context.message_map().send(&message);
} else {
// TODO: Error, modal warning?
}
} else {
// TODO: Error, modal warning?
}
} else {
sdcDisconnect(&SDCD1);
SDCardStatusMessage message { false };
context.message_map().send(&message);
}
}
}
static ui::Widget* touch_widget(ui::Widget* const w, ui::TouchEvent event) {
@ -181,10 +201,6 @@ private:
painter.paint_widget_tree(top_widget);
}
void handle_sd_card_detect() {
}
void handle_switches() {
const auto switches_state = get_switches_state();
for(size_t i=0; i<switches_state.size(); i++) {