Add correct handling of sd card, add reset command, add ls command
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <reflow-controller/shell.h>
|
||||
#include <reflow-controller/pid-controller.h>
|
||||
#include <reflow-controller/digio.h>
|
||||
#include "fatfs/shimatta_sdio_driver/shimatta_sdio.h"
|
||||
#include <reflow-controller/temp-converter.h>
|
||||
#include <reflow-controller/rotary-encoder.h>
|
||||
#include <stm-periph/stm32-gpio-macros.h>
|
||||
@@ -60,6 +61,9 @@ static uint32_t rot;
|
||||
static volatile float pid_out;
|
||||
static volatile float current_temperature;
|
||||
|
||||
FATFS fs;
|
||||
FATFS *fs_ptr = &fs;
|
||||
|
||||
static inline void uart_gpio_config()
|
||||
{
|
||||
#ifdef DEBUGBUILD
|
||||
@@ -104,11 +108,32 @@ static inline void setup_sell_uart(struct stm_uart *uart)
|
||||
NVIC_EnableIRQ(DMA2_Stream7_IRQn);
|
||||
}
|
||||
|
||||
static bool mount_sd_card_if_avail(bool mounted)
|
||||
{
|
||||
FRESULT res;
|
||||
|
||||
if (sdio_check_inserted() && mounted) {
|
||||
memset(fs_ptr, 0, sizeof(FATFS));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sdio_check_inserted() && !mounted) {
|
||||
res = f_mount(fs_ptr, "0:/", 1);
|
||||
if (res == FR_OK) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return mounted;
|
||||
}
|
||||
|
||||
const char *oven_controller_hello_world = "Hello world :)\n";
|
||||
|
||||
int main()
|
||||
{
|
||||
FATFS fs;
|
||||
bool sd_card_mounted = false;
|
||||
FIL test_file;
|
||||
const char *uart_input;
|
||||
size_t uart_input_len;
|
||||
@@ -132,8 +157,10 @@ int main()
|
||||
setup_sell_uart(&shell_uart);
|
||||
|
||||
shell_handle = shell_init(write_shell_callback);
|
||||
shell_print_motd(shell_handle);
|
||||
|
||||
if (f_mount(&fs, "0:/", 1) == FR_OK) {
|
||||
if (f_mount(fs_ptr, "0:/", 1) == FR_OK) {
|
||||
sd_card_mounted = true;
|
||||
f_open(&test_file, "hello-world.txt", FA_OPEN_APPEND | FA_WRITE);
|
||||
f_write(&test_file, oven_controller_hello_world, strlen(oven_controller_hello_world), NULL);
|
||||
f_close(&test_file);
|
||||
@@ -143,6 +170,9 @@ int main()
|
||||
pid_zero(&pid);
|
||||
|
||||
while (1) {
|
||||
|
||||
sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted);
|
||||
|
||||
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
|
||||
|
||||
if (pt1000_value_status >= 0) {
|
||||
|
Reference in New Issue
Block a user