diff --git a/PSE-firmware b/PSE-firmware index bf08fc6..8a099f5 160000 --- a/PSE-firmware +++ b/PSE-firmware @@ -1 +1 @@ -Subproject commit bf08fc69ff21c28482ade1eca086867e619b7fea +Subproject commit 8a099f5c215424ff34ceafaaa35615ec0fbeb685 diff --git a/fatfs.c b/fatfs.c index 9967001..107a894 100644 --- a/fatfs.c +++ b/fatfs.c @@ -1,5 +1,6 @@ #include "fatfs.h" +#include #include FRESULT f_open ( @@ -7,8 +8,21 @@ FRESULT f_open ( const TCHAR* path, /* Pointer to the file name */ BYTE mode /* Access mode and file open mode flags */ ){ - printf("file open try\n"); - return FR_NO_FILE; + FILE* f; + printf("mode %d\n", mode); + if(mode & FA_READ) + f = fopen(path, "r"); + else if(mode & FA_WRITE && mode & FA_OPEN_ALWAYS) + f = fopen(path, "w+"); + else + printf("Unimplemented mode"); + if(f == NULL){ + printf("errno %d\n",errno); + return FR_NO_FILE; + } + *fp = f; + + return FR_OK; } FRESULT f_read ( @@ -17,15 +31,15 @@ FRESULT f_read ( UINT btr, /* Number of bytes to read */ UINT* br /* Pointer to number of bytes read */ ){ - printf("file read try\n"); - return FR_NO_FILE; + *br = fread(buff, 1, btr, *fp); + return FR_OK; } FRESULT f_close ( FIL *fp /* Pointer to the file object to be closed */ ){ - printf("file close try\n"); - return FR_NO_FILE; + fclose(*fp); + return FR_OK; } FRESULT f_write ( @@ -34,6 +48,6 @@ FRESULT f_write ( UINT btw, /* Number of bytes to write */ UINT* bw /* Pointer to number of bytes written */ ){ - printf("file write try\n"); - return FR_NO_FILE; + *bw = fwrite(buff, 1, btw, *fp); + return FR_OK; } diff --git a/fatfs.h b/fatfs.h index 4113ab5..d5f391d 100644 --- a/fatfs.h +++ b/fatfs.h @@ -1,5 +1,6 @@ -typedef struct { -} FIL; +#include + +typedef FILE* FIL; typedef enum { FR_OK = 0, /* (0) Succeeded */ diff --git a/main.c b/main.c index e61d4bf..b73969a 100644 --- a/main.c +++ b/main.c @@ -32,6 +32,7 @@ TIM_HandleTypeDef htim5; pse_unit pse_units[PSE_UNITS_NUM]; pse_syringe pse_syringes[PSE_UNITS_NUM]; pse_home_display pse_home_displays[PSE_UNITS_NUM]; +pse_stepper_status pse_steppers_status[PSE_UNITS_NUM]; enum steppers_axis{PSE_X_STEPPER, PSE_Y_STEPPER, PSE_Z_STEPPER, PSE_E_STEPPER, PSE_STEPPER_NUM}; pse_stepper_conf pse_stepper_confs[PSE_STEPPER_NUM] = { @@ -120,7 +121,7 @@ int main(int argc, char** argv){ lv_label_set_text(cursor, "A"); lv_indev_set_cursor(my_indev, cursor); - load_units(pse_units, pse_syringes, pse_stepper_confs, pse_home_displays, PSE_UNITS_NUM, 0); + load_units(pse_units, pse_syringes, pse_stepper_confs, pse_steppers_status, pse_home_displays, PSE_UNITS_NUM, 0); Home_Screen_Gen(pse_units, PSE_UNITS_NUM, false); pthread_t tickThread; diff --git a/stm32f1xx_hal.c b/stm32f1xx_hal.c index af71b1d..6bbfdaa 100644 --- a/stm32f1xx_hal.c +++ b/stm32f1xx_hal.c @@ -47,7 +47,7 @@ static void* tim_handler(void* arg){ int backlog = nb_exec - exec_counter; if(backlog > 10) printf("timer simulation lagging behind (%d ticks)\n", backlog); - while(backlog > 0){ + while(backlog > 0 && htim->started){ HAL_TIM_PeriodElapsedCallback(htim); exec_counter++; backlog = nb_exec - exec_counter; diff --git a/stm32f1xx_hal.h b/stm32f1xx_hal.h index d3f367b..e0deb96 100644 --- a/stm32f1xx_hal.h +++ b/stm32f1xx_hal.h @@ -10,7 +10,7 @@ typedef struct { typedef struct{ uint16_t presc; uint16_t period; - uint8_t started; + volatile uint8_t started; } TIM_HandleTypeDef; typedef int HAL_StatusTypeDef;