mirror of
https://github.com/arabine/open-story-teller.git
synced 2025-12-07 09:19:57 +01:00
New: HMI thread (user inputs and LCD manager)
This commit is contained in:
parent
5104f9a6c0
commit
05eda44df7
3 changed files with 146 additions and 4 deletions
|
|
@ -1,7 +1,10 @@
|
||||||
|
#include <stdbool.h>
|
||||||
#include <ff.h>
|
#include <ff.h>
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "ost_hal.h"
|
#include "ost_hal.h"
|
||||||
|
|
||||||
|
#include "filesystem.h"
|
||||||
|
|
||||||
// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
|
// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
|
||||||
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
|
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
|
||||||
#define SD_FAT_TYPE 2
|
#define SD_FAT_TYPE 2
|
||||||
|
|
@ -65,3 +68,86 @@ void filesystem_mount()
|
||||||
|
|
||||||
scan_files("");
|
scan_files("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ouvre le fichier d'index d'histoires
|
||||||
|
// Le format est le suivant :
|
||||||
|
// - Fichier texte, avec fin de ligne \n
|
||||||
|
// - Une ligne par histoire
|
||||||
|
// - la ligne contient le nom du répertoire au format UUIDv4 (36 caractères ASCII avec 4 tirets '-')
|
||||||
|
|
||||||
|
// Exemple: d0ad13e4-06de-4e00-877c-d922fdd37d13
|
||||||
|
|
||||||
|
int is_multiple_of_37(int nombre)
|
||||||
|
{
|
||||||
|
int plusGrandMultiple = (nombre / 37) * 37;
|
||||||
|
return (nombre - plusGrandMultiple) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Loop in all directories
|
||||||
|
void disk_start()
|
||||||
|
{
|
||||||
|
// default is current directory
|
||||||
|
const char* dpath = ".";
|
||||||
|
if (argc) dpath = args;
|
||||||
|
|
||||||
|
DIR dir;
|
||||||
|
if ( FR_OK != f_opendir(&dir, dpath) )
|
||||||
|
{
|
||||||
|
printf("cannot access '%s': No such file or directory\r\n", dpath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILINFO fno;
|
||||||
|
while( (f_readdir(&dir, &fno) == FR_OK) && (fno.fname[0] != 0) )
|
||||||
|
{
|
||||||
|
if ( fno.fname[0] != '.' ) // ignore . and .. entry
|
||||||
|
{
|
||||||
|
if ( fno.fattrib & AM_DIR )
|
||||||
|
{
|
||||||
|
// directory
|
||||||
|
printf("/%s\r\n", fno.fname);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
printf("%-40s", fno.fname);
|
||||||
|
if (fno.fsize < 1024)
|
||||||
|
{
|
||||||
|
printf("%lu B\r\n", fno.fsize);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
printf("%lu KB\r\n", fno.fsize / 1024);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f_closedir(&dir);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool filesystem_read_index_file(ost_context_t *ctx)
|
||||||
|
{
|
||||||
|
FILINFO fno;
|
||||||
|
FRESULT fr = f_stat("index.ost", &fno);
|
||||||
|
|
||||||
|
ctx->number_of_stories = 0;
|
||||||
|
ctx->current_story = 0;
|
||||||
|
|
||||||
|
if (fr == FR_OK)
|
||||||
|
{
|
||||||
|
bool valid_file = false;
|
||||||
|
int size = fno.fsize;
|
||||||
|
// une ligne = 36 octets (UUID) + 1 octet (\n) = 37
|
||||||
|
// Déjà, la taille doit être multiple de 37
|
||||||
|
if (is_multiple_of_37(size) && (size > 0))
|
||||||
|
{
|
||||||
|
valid_file = true;
|
||||||
|
ctx->number_of_stories = size / 37;
|
||||||
|
debug_printf("SUCCESS: found %d stories\r\n", ctx->number_of_stories);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debug_printf("ERROR: index.ost not found\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,15 @@
|
||||||
#ifndef FILESYSTEM_H
|
#ifndef FILESYSTEM_H
|
||||||
#define FILESYSTEM_H
|
#define FILESYSTEM_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t number_of_stories;
|
||||||
|
uint32_t current_story;
|
||||||
|
} ost_context_t;
|
||||||
|
|
||||||
|
bool filesystem_read_index_file(ost_context_t *ctx);
|
||||||
void filesystem_mount();
|
void filesystem_mount();
|
||||||
|
|
||||||
#endif // FILESYSTEM_H
|
#endif // FILESYSTEM_H
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,50 @@ void ost_hal_panic()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================================================================================
|
||||||
|
// GLOBAL STORY VARIABLES
|
||||||
|
// ===========================================================================================================
|
||||||
|
static ost_context_t OstContext;
|
||||||
|
|
||||||
|
// ===========================================================================================================
|
||||||
|
// HMI TASK (user interface, buttons manager, LCD)
|
||||||
|
// ===========================================================================================================
|
||||||
|
static qor_tcb_t HmiTcb;
|
||||||
|
static uint32_t HmiStack[4096];
|
||||||
|
|
||||||
|
static qor_mbox_t HmiMailBox;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t ev;
|
||||||
|
} ost_hmi_event_t;
|
||||||
|
|
||||||
|
static ost_hmi_event_t HmiEvent;
|
||||||
|
|
||||||
|
ost_hmi_event_t HmiQueue[10];
|
||||||
|
|
||||||
|
void HmiTask(void *args)
|
||||||
|
{
|
||||||
|
qor_mbox_init(&HmiMailBox, (void **)&HmiQueue, 10);
|
||||||
|
|
||||||
|
ost_hmi_event_t *e = NULL;
|
||||||
|
|
||||||
|
filesystem_read_index_file(&OstContext);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t res = qor_mbox_wait(&HmiMailBox, (void **)&e, 1000);
|
||||||
|
|
||||||
|
if (res == QOR_MBOX_OK)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debug_printf("H"); // pour le debug only
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================================================================================================
|
// ===========================================================================================================
|
||||||
// VIRTUAL MACHINE TASK
|
// VIRTUAL MACHINE TASK
|
||||||
// ===========================================================================================================
|
// ===========================================================================================================
|
||||||
|
|
@ -39,13 +83,14 @@ static uint8_t m_rom_data[16 * 1024];
|
||||||
static uint8_t m_ram_data[16 * 1024];
|
static uint8_t m_ram_data[16 * 1024];
|
||||||
static chip32_ctx_t m_chip32_ctx;
|
static chip32_ctx_t m_chip32_ctx;
|
||||||
|
|
||||||
|
// Index file parameter, reference an index in the file
|
||||||
|
|
||||||
uint8_t vm_syscall(chip32_ctx_t *ctx, uint8_t signum)
|
uint8_t vm_syscall(chip32_ctx_t *ctx, uint8_t signum)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void VmTask(void *args)
|
void VmTask(void *args)
|
||||||
{
|
{
|
||||||
|
|
||||||
// VM Initialize
|
// VM Initialize
|
||||||
m_chip32_ctx.stack_size = 512;
|
m_chip32_ctx.stack_size = 512;
|
||||||
|
|
||||||
|
|
@ -61,6 +106,8 @@ void VmTask(void *args)
|
||||||
|
|
||||||
chip32_initialize(&m_chip32_ctx);
|
chip32_initialize(&m_chip32_ctx);
|
||||||
|
|
||||||
|
qor_mbox_init(&VmMailBox, (void **)&VmQueue, 10);
|
||||||
|
|
||||||
chip32_result_t run_result;
|
chip32_result_t run_result;
|
||||||
ost_vm_event_t *e = NULL;
|
ost_vm_event_t *e = NULL;
|
||||||
|
|
||||||
|
|
@ -82,7 +129,7 @@ void VmTask(void *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================================================================
|
// ===========================================================================================================
|
||||||
// FILE SYSTEM TASK
|
// AUDIO TASK
|
||||||
// ===========================================================================================================
|
// ===========================================================================================================
|
||||||
static qor_tcb_t AudioTcb;
|
static qor_tcb_t AudioTcb;
|
||||||
static uint32_t AudioStack[4096];
|
static uint32_t AudioStack[4096];
|
||||||
|
|
@ -123,8 +170,7 @@ void show_duration(uint32_t millisecondes)
|
||||||
|
|
||||||
void AudioTask(void *args)
|
void AudioTask(void *args)
|
||||||
{
|
{
|
||||||
picture_show("example.bmp");
|
// picture_show("example.bmp");
|
||||||
// ost_audio_play("out2.wav");
|
|
||||||
|
|
||||||
wake_up.ev = 34;
|
wake_up.ev = 34;
|
||||||
|
|
||||||
|
|
@ -205,6 +251,7 @@ int main()
|
||||||
qor_init(125000000UL);
|
qor_init(125000000UL);
|
||||||
|
|
||||||
// 5. Initialize the tasks
|
// 5. Initialize the tasks
|
||||||
|
qor_create_thread(&HmiTcb, HmiTask, HmiStack, sizeof(HmiStack) / sizeof(HmiStack[0]), 1, "HmiTask"); // less priority is the HMI (user inputs and LCD)
|
||||||
qor_create_thread(&VmTcb, VmTask, VmStack, sizeof(VmStack) / sizeof(VmStack[0]), 2, "VmTask");
|
qor_create_thread(&VmTcb, VmTask, VmStack, sizeof(VmStack) / sizeof(VmStack[0]), 2, "VmTask");
|
||||||
qor_create_thread(&AudioTcb, AudioTask, AudioStack, sizeof(AudioStack) / sizeof(AudioStack[0]), 3, "AudioTask"); ///< High priority for audio
|
qor_create_thread(&AudioTcb, AudioTask, AudioStack, sizeof(AudioStack) / sizeof(AudioStack[0]), 3, "AudioTask"); ///< High priority for audio
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue