mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-05-02 21:00:45 +00:00
SD card detection and filesystem mounting.
This commit is contained in:
parent
9f6c495fef
commit
987ea3555d
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
constexpr auto EVT_MASK_RTC_TICK = EVENT_MASK(0);
|
constexpr auto EVT_MASK_RTC_TICK = EVENT_MASK(0);
|
||||||
constexpr auto EVT_MASK_LCD_FRAME_SYNC = EVENT_MASK(1);
|
constexpr auto EVT_MASK_LCD_FRAME_SYNC = EVENT_MASK(1);
|
||||||
constexpr auto EVT_MASK_SD_CARD_PRESENT = EVENT_MASK(2);
|
|
||||||
constexpr auto EVT_MASK_SWITCHES = EVENT_MASK(3);
|
constexpr auto EVT_MASK_SWITCHES = EVENT_MASK(3);
|
||||||
constexpr auto EVT_MASK_ENCODER = EVENT_MASK(4);
|
constexpr auto EVT_MASK_ENCODER = EVENT_MASK(4);
|
||||||
constexpr auto EVT_MASK_TOUCH = EVENT_MASK(5);
|
constexpr auto EVT_MASK_TOUCH = EVENT_MASK(5);
|
||||||
|
@ -52,6 +52,8 @@
|
|||||||
#include "lpc43xx_cpp.hpp"
|
#include "lpc43xx_cpp.hpp"
|
||||||
using namespace lpc43xx;
|
using namespace lpc43xx;
|
||||||
|
|
||||||
|
#include "sd_card.hpp"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
class EventDispatcher {
|
class EventDispatcher {
|
||||||
@ -87,6 +89,7 @@ private:
|
|||||||
ui::Context& context;
|
ui::Context& context;
|
||||||
uint32_t encoder_last = 0;
|
uint32_t encoder_last = 0;
|
||||||
bool is_running = true;
|
bool is_running = true;
|
||||||
|
bool sd_card_present = false;
|
||||||
|
|
||||||
eventmask_t wait() {
|
eventmask_t wait() {
|
||||||
return chEvtWaitAny(ALL_EVENTS);
|
return chEvtWaitAny(ALL_EVENTS);
|
||||||
@ -105,10 +108,6 @@ private:
|
|||||||
handle_lcd_frame_sync();
|
handle_lcd_frame_sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( events & EVT_MASK_SD_CARD_PRESENT ) {
|
|
||||||
handle_sd_card_detect();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( events & EVT_MASK_SWITCHES ) {
|
if( events & EVT_MASK_SWITCHES ) {
|
||||||
handle_switches();
|
handle_switches();
|
||||||
}
|
}
|
||||||
@ -130,7 +129,28 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handle_rtc_tick() {
|
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) {
|
static ui::Widget* touch_widget(ui::Widget* const w, ui::TouchEvent event) {
|
||||||
@ -181,10 +201,6 @@ private:
|
|||||||
painter.paint_widget_tree(top_widget);
|
painter.paint_widget_tree(top_widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_sd_card_detect() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_switches() {
|
void handle_switches() {
|
||||||
const auto switches_state = get_switches_state();
|
const auto switches_state = get_switches_state();
|
||||||
for(size_t i=0; i<switches_state.size(); i++) {
|
for(size_t i=0; i<switches_state.size(); i++) {
|
||||||
|
47
firmware/application/sd_card.hpp
Normal file
47
firmware/application/sd_card.hpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SD_CARD_H__
|
||||||
|
#define __SD_CARD_H__
|
||||||
|
|
||||||
|
#include "ff.h"
|
||||||
|
|
||||||
|
namespace sd_card {
|
||||||
|
namespace filesystem {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
FATFS fs;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
FRESULT mount() {
|
||||||
|
return f_mount(&fs, "", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
FRESULT unmount() {
|
||||||
|
return f_mount(NULL, "", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace filesystem */
|
||||||
|
} /* namespace sd_card */
|
||||||
|
|
||||||
|
#endif/*__SD_CARD_H__*/
|
@ -46,6 +46,7 @@ public:
|
|||||||
TPMSPacket = 6,
|
TPMSPacket = 6,
|
||||||
Shutdown = 8,
|
Shutdown = 8,
|
||||||
AISPacket = 7,
|
AISPacket = 7,
|
||||||
|
SDCardStatus = 10,
|
||||||
MAX
|
MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -245,6 +246,18 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SDCardStatusMessage : public Message {
|
||||||
|
public:
|
||||||
|
constexpr SDCardStatusMessage(
|
||||||
|
bool is_mounted
|
||||||
|
) : Message { ID::SDCardStatus },
|
||||||
|
is_mounted { is_mounted }
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool is_mounted;
|
||||||
|
};
|
||||||
|
|
||||||
class MessageHandlerMap {
|
class MessageHandlerMap {
|
||||||
public:
|
public:
|
||||||
using MessageHandler = std::function<void(Message* const p)>;
|
using MessageHandler = std::function<void(Message* const p)>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user