avr_compat.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. /*
  3. * AVR Compatibility Layer for PC compilation
  4. * Provides AVR types, macros, and functions for x86/x64 hosts
  5. */
  6. /* Prevent AVR-specific headers from being included */
  7. #define _AVR_PGMSPACE_H_ 1
  8. #define _AVR_IO_H_ 1
  9. #define _AVR_WDT_H_ 1
  10. #define _AVR_SLEEP_H_ 1
  11. #include <stdio.h>
  12. #include <stdint.h>
  13. #include <string.h>
  14. #include <time.h>
  15. #include <math.h>
  16. /* AVR type definitions - on PC, these are already correct */
  17. /* No need to redefine built-in types */
  18. /* PROGMEM/Flash support - on PC everything is in RAM */
  19. #define PROGMEM
  20. #define __flash
  21. #define PSTR(s) (s)
  22. #define strcpy_P strcpy
  23. #define strcat_P strcat
  24. /* xprintf functions are implemented in gpx_wrapper.c and nmea_wrapper.c */
  25. /* FatFS types stub */
  26. typedef struct {
  27. FILE *fp;
  28. char filename[256];
  29. } FIL;
  30. typedef uint32_t DWORD;
  31. typedef unsigned int UINT;
  32. /* FatFS function stubs */
  33. #define FA_WRITE 0x02
  34. #define FA_OPEN_ALWAYS 0x10
  35. static inline unsigned char f_open(FIL *file, const char *path, unsigned char mode) {
  36. (void)mode;
  37. file->fp = fopen(path, "w");
  38. if (file->fp) {
  39. strncpy(file->filename, path, sizeof(file->filename) - 1);
  40. return 0;
  41. }
  42. return 1;
  43. }
  44. static inline unsigned char f_write(FIL *file, const void *buf, unsigned int len, unsigned int *written) {
  45. if (!file->fp) return 1;
  46. *written = fwrite(buf, 1, len, file->fp);
  47. return (*written == len) ? 0 : 1;
  48. }
  49. static inline unsigned char f_close(FIL *file) {
  50. if (file->fp) {
  51. fclose(file->fp);
  52. file->fp = NULL;
  53. return 0;
  54. }
  55. return 1;
  56. }
  57. /* Math functions */
  58. #ifndef M_PI
  59. #define M_PI 3.14159265358979323846
  60. #endif
  61. /* AVR interrupt stubs */
  62. #define cli()
  63. #define sei()
  64. /* System structure - simplified for PC testing */
  65. struct config_s {
  66. unsigned char skip_points;
  67. unsigned char auto_pause_dist;
  68. };
  69. struct system_s {
  70. struct config_s conf;
  71. unsigned long int distance;
  72. unsigned long int elevation_gain;
  73. unsigned long int elevation_loss;
  74. time_t time_start;
  75. time_t current_pause_start;
  76. time_t pause_time;
  77. unsigned tracking_paused:1;
  78. unsigned tracking_auto_paused:1;
  79. };
  80. struct location_s {
  81. float lon;
  82. float lat;
  83. float alt;
  84. time_t time;
  85. };
  86. extern volatile struct system_s System;
  87. extern struct location_s location;
  88. extern time_t utc;
  89. /* Settings flags */
  90. #define CONFFLAG_DISABLE_FILTERS 0x01
  91. extern unsigned char config_flags;
  92. static inline unsigned char get_flag(unsigned char flag) {
  93. return (config_flags & flag) ? 1 : 0;
  94. }
  95. /* Time functions */
  96. char *get_iso_time(time_t time, unsigned char local);
  97. void iso_time_to_filename(char *time);