#ifndef __FILE_H__
#define __FILE_H__

#ifdef __cplusplus
 extern "C" {
#endif

#include "stm32f4xx.h"
#include "ff.h"

#define FILE_IDX_CONFIG  (0)
#define FILE_IDX_MAIN    (1)
#define FILE_IDX_GAS1    (2)
#define FILE_IDX_GAS2    (3)
#define FILE_IDX_GAS3    (4)
#define FILE_IDX_GAS4    (5)
#define FILE_IDX_FW      (6)
#define FILE_IDX_MAX     (7)
#define FILE_IDX_OTHER   (0xFF01)
#define FILE_IDX_END     (0xFF02)

#define FILE_MASK_NULL   (0)
#define FILE_MASK_CONFIG (1 << FILE_IDX_CONFIG)
#define FILE_MASK_MAIN   (1 << FILE_IDX_MAIN  )
#define FILE_MASK_GAS1   (1 << FILE_IDX_GAS1  )
#define FILE_MASK_GAS2   (1 << FILE_IDX_GAS2  )
#define FILE_MASK_GAS3   (1 << FILE_IDX_GAS3  )
#define FILE_MASK_GAS4   (1 << FILE_IDX_GAS4  )
#define FILE_MASK_FW     (1 << FILE_IDX_FW    )

#define FILE_NAME_CONFIG "CONFIG.TXT"
#define FILE_NAME_MAIN   "MAIN_1~1.BIN"
#define FILE_NAME_GAS1   "GAS1_1~1.BIN"
#define FILE_NAME_GAS2   "GAS2_1~1.BIN"
#define FILE_NAME_GAS3   "GAS3_1~1.BIN"
#define FILE_NAME_GAS4   "GAS4_1~1.BIN"
#define FILE_NAME_FW     "LARK1FQ.BIN"

#define FILE_NAME_LEN  (13)
#define FILE_BUFF_SIZE (4 * 1024)

extern FATFS fs;
extern FIL f;
extern uint8_t file_buffer[FILE_BUFF_SIZE];
extern TCHAR file_name[FILE_IDX_MAX][FILE_NAME_LEN];

uint32_t file_init(void);
void file_secctor_erase(uint16_t sector);
void file_write_flash(uint32_t flash, uint8_t *buff, uint32_t len);

#ifdef __cplusplus
}
#endif

#endif /* __FILE_H__ */
