hal.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * TamaLIB - A hardware agnostic Tamagotchi P1 emulation library
  3. *
  4. * Copyright (C) 2021 Jean-Christophe Rona <jc@rona.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef _HAL_H_
  21. #define _HAL_H_
  22. #include "../hal_types.h"
  23. #ifndef NULL
  24. #define NULL 0
  25. #endif
  26. typedef enum {
  27. LOG_ERROR = 0x1,
  28. LOG_INFO = (0x1 << 1),
  29. LOG_MEMORY = (0x1 << 2),
  30. LOG_CPU = (0x1 << 3),
  31. } log_level_t;
  32. /* The Hardware Abstraction Layer
  33. * NOTE: This structure acts as an abstraction layer between TamaLIB and the OS/SDK.
  34. * All pointers MUST be implemented, but some implementations can be left empty.
  35. */
  36. typedef struct {
  37. /* Memory allocation functions
  38. * NOTE: Needed only if breakpoints support is required.
  39. */
  40. void* (*malloc)(u32_t size);
  41. void (*free)(void* ptr);
  42. /* What to do if the CPU has halted
  43. */
  44. void (*halt)(void);
  45. /* Log related function
  46. * NOTE: Needed only if log messages are required.
  47. */
  48. bool_t (*is_log_enabled)(log_level_t level);
  49. void (*log)(log_level_t level, char* buff, ...);
  50. /* Clock related functions
  51. * NOTE: Timestamps granularity is configured with tamalib_init(), an accuracy
  52. * of ~30 us (1/32768) is required for a cycle accurate emulation.
  53. */
  54. void (*sleep_until)(timestamp_t ts);
  55. timestamp_t (*get_timestamp)(void);
  56. /* Screen related functions
  57. * NOTE: In case of direct hardware access to pixels, the set_XXXX() functions
  58. * (called for each pixel/icon update) can directly drive them, otherwise they
  59. * should just store the data in a buffer and let update_screen() do the actual
  60. * rendering (at 30 fps).
  61. */
  62. void (*update_screen)(void);
  63. void (*set_lcd_matrix)(u8_t x, u8_t y, bool_t val);
  64. void (*set_lcd_icon)(u8_t icon, bool_t val);
  65. /* Sound related functions
  66. * NOTE: set_frequency() changes the output frequency of the sound, while
  67. * play_frequency() decides whether the sound should be heard or not.
  68. */
  69. void (*set_frequency)(u32_t freq);
  70. void (*play_frequency)(bool_t en);
  71. /* Event handler from the main app (if any)
  72. * NOTE: This function usually handles button related events, states loading/saving ...
  73. */
  74. int (*handler)(void);
  75. } hal_t;
  76. extern hal_t* g_hal;
  77. #endif /* _HAL_H_ */