whiskers 0.2.0
RP2350 BadUSB Tool
Loading...
Searching...
No Matches
shared.h
Go to the documentation of this file.
1/* Copyright (c) 2026 Zane A. Maple
2 Licensed under the MIT license. See LICENSE in the main repository for more information. */
3
4/* Includes standard struct definitions to be used across hardware implementations */
5
15
16#ifndef W_HAL_SHARED_H
17#define W_HAL_SHARED_H
18
19#include <stdint.h>
20#include <stddef.h>
21#include <stdbool.h>
22
23#define CODE_VERSION "0.2.0"
24
25/* Note: these are not set in stone and will be expanded upon more than likely as time goes on */
26
31typedef uint8_t HAL_ERROR;
32#define HAL_OKAY 0
37#define HAL_FS_DISK_ERR 1
42#define HAL_FS_INT_ERR 2
47#define HAL_FS_NOT_READY 3
52#define HAL_FS_NO_FILE 4
57#define HAL_FS_NO_PATH 5
62#define HAL_FS_INVALID_NAME 6
67#define HAL_FS_ACCESS_DENY 7
72#define HAL_FS_ALRDY_EXISTS 8
77#define HAL_FS_INVALID_OBJ 9
82#define HAL_FS_NOT_ENABLED 10
87#define HAL_FS_NO_FS 11
92#define HAL_FS_MKFS_ABORTED 12
97#define HAL_FS_TIMEOUT 13
102#define HAL_FS_LOCKED 14
107#define HAL_FS_NOT_ENOUGH_M 15
112#define HAL_FS_TOO_MANY_OPN 16
117#define HAL_FS_INVALID_PARM 17
122#define HAL_FS_WRITE_PROT 18
127#define HAL_FS_INVALID_DRIV 19
132#define HAL_FS_DOUBLE_OPEN 20
137#define HAL_FS_UNKNOWN_ERR 21
142
143#define HAL_FLASH_OUT_OF_BOUNDS 22
148#define HAL_FLASH_BAD_INTEGRITY 23
153#define HAL_USB_CANNOT_INITIALIZE 24
158/* File system settings */
159
160#define HAL_FS_MAX_OPEN_FILES 16
168#define HAL_FS_MAX_OPEN_DIRS 4
174#define HAL_SD_USE_HW_CD false
181
196typedef struct hal_file
197{
198 /* Basic metadata */
199 char *filename;
200 size_t fsize;
201 uint8_t fattrs;
202 uint16_t fdate;
203 uint16_t ftime;
204
205 /* Internal pointer based on underlying implementation, points to actual internal file object */
208
209 /* If any of the file functions fail, this is where the err is set */
211} _FILE;
212
227typedef struct hal_dir
228{
229 uint8_t dattrs;
230 uint16_t fdate;
231 uint16_t ftime;
232
233 /* Internal pointer based on underlying implementation, points to actual internal dir object */
236
237 /* If any of the file functions fail, this is where the err is set */
239} _DIR;
240
249
250/* Mainly used as an pointer holder for internal sd/fatfs code */
251typedef struct disk_info
252{
258 bool (*_internal_read_fp)(uint32_t, uint32_t, void*);
259 bool (*_internal_write_fp)(uint32_t, uint32_t, uint8_t*);
262
263
264 /* Errno for all disk operations */
266
267} _DISK_INFO;
268
274const char * HAL_ERROR_to_str(HAL_ERROR errno);
275
276#endif
uint8_t HAL_ERROR
This type represents a HAL_* error. See the defines in the file to read up on them.
Definition shared.h:31
const char * HAL_ERROR_to_str(HAL_ERROR errno)
Turns provided errno into a string for logging/debugging.
Definition shared.c:6
Struct to hold disk information.
Definition shared.h:252
uint32_t _internal_blocksize
Definition shared.h:260
bool is_externally_writable
Definition shared.h:254
bool(* _internal_write_fp)(uint32_t, uint32_t, uint8_t *)
Definition shared.h:259
void * _internal_fsp
Definition shared.h:257
void * _internal_sdp
Definition shared.h:256
HAL_ERROR errno
Definition shared.h:265
uint32_t _internal_sectorcount
Definition shared.h:261
bool disk_mounted
Definition shared.h:253
bool(* _internal_read_fp)(uint32_t, uint32_t, void *)
Definition shared.h:258
Directory struct used in directory operations.
Definition shared.h:228
HAL_ERROR errno
Definition shared.h:238
bool _internal_has_dir
Definition shared.h:235
uint16_t fdate
Definition shared.h:230
void * _internal_dp
Definition shared.h:234
uint16_t ftime
Definition shared.h:231
uint8_t dattrs
Definition shared.h:229
File struct to be used in file operations.
Definition shared.h:197
void * _internal_fp
Definition shared.h:206
char * filename
Definition shared.h:199
uint8_t fattrs
Definition shared.h:201
uint16_t ftime
Definition shared.h:203
HAL_ERROR errno
Definition shared.h:210
uint16_t fdate
Definition shared.h:202
bool _internal_has_file
Definition shared.h:207
size_t fsize
Definition shared.h:200