#pragma once #include #include namespace esphome { namespace grub_boot_switch { #define WBVAL(x) ((x) & 0xFF), (((x) >> 8) & 0xFF) #define QBVAL(x) ((x) & 0xFF), (((x) >> 8) & 0xFF), (((x) >> 16) & 0xFF), (((x) >> 24) & 0xFF) constexpr uint8_t FAT_MEDIA_FIXED_DISK = 0xF8; constexpr uint8_t FAT_NAME_LEN = 8; constexpr uint8_t FAT_EXT_LEN = 3; enum FatFileAttributes : uint8_t { kFatAttr_ReadOnly = 0x01, kFatAttr_Hidden = 0x02, kFatAttr_System = 0x04, kFatAttr_VolumeLabel = 0x08, kFatAttr_Subdirectory = 0x10, kFatAttr_Archive = 0x20, kFatAttr_LongFileName = 0x0F, }; enum FatOrdinalFlags : uint8_t { kFat_LastLFN = 0x40, kFat_DeletedLFN = 0x80, }; struct FatDirEntry { char name[FAT_NAME_LEN]; char ext[FAT_EXT_LEN]; uint8_t attrs; uint8_t type; uint8_t ctime_ms; uint16_t ctime; uint16_t cdate; uint16_t adate; uint16_t ea_index; uint16_t mtime; uint16_t mdate; uint16_t start; uint32_t size; } __attribute__((packed)); uint8_t fat_write_lfn(const char *name, const FatDirEntry *direntry, uint8_t *output); uint8_t fat_write_dir(const FatDirEntry *direntry, uint8_t *output); uint16_t fat_date(uint16_t year, uint8_t month, uint8_t day); } // namespace grub_boot_switch } // namespace esphome