flasher.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @file flasher.h
  3. * @brief High-level functions for flashing the VGM firmware.
  4. */
  5. #pragma once
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. /**
  9. * @brief Enumeration of possible flasher event types.
  10. */
  11. typedef enum {
  12. FlasherEventTypeProgress, /**< Operation progress has been reported. */
  13. FlasherEventTypeSuccess, /**< Operation has finished successfully. */
  14. FlasherEventTypeError, /**< Operation has finished with an error. */
  15. } FlasherEventType;
  16. /**
  17. * @brief Enumeration of possible flasher errors.
  18. */
  19. typedef enum {
  20. FlasherErrorBadFile, /**< File error: wrong format, I/O problem, etc.*/
  21. FlasherErrorDisconnect, /**< Connection error: Module disconnected, frozen, etc. */
  22. FlasherErrorUnknown, /**< An error that does not fit to any of the above categories. */
  23. } FlasherError;
  24. /**
  25. * @brief Flasher event structure.
  26. *
  27. * Events of FlasherEventTypeSuccess type do not carry additional data.
  28. */
  29. typedef struct {
  30. FlasherEventType type; /**< Type of the event that has occurred. */
  31. union {
  32. uint8_t progress; /**< Progress value (0-100). */
  33. FlasherError error; /**< Error value. */
  34. };
  35. } FlasherEvent;
  36. /**
  37. * @brief Flasher event callback type.
  38. *
  39. * @param[in] event Description of the event that has occurred.
  40. * @param[in,out] context Pointer to a user-specified object.
  41. */
  42. typedef void (*FlasherCallback)(FlasherEvent event, void* context);
  43. /**
  44. * @brief Initialise the flasher.
  45. *
  46. * Calling this function will initialise the GPIO, set up the debug
  47. * connection, halt the module's CPU, etc.
  48. *
  49. * @returns true on success, false on failure.
  50. */
  51. bool flasher_init(void);
  52. /**
  53. * @brief Disable the flasher.
  54. *
  55. * Calling this function will disable all activated hardware and
  56. * reset the module.
  57. */
  58. void flasher_deinit(void);
  59. /**
  60. * @brief Set callback for flasher events.
  61. *
  62. * The callback MUST be set before calling flasher_start().
  63. *
  64. * @param[in] callback pointer to the function used to receive events.
  65. * @param[in] context pointer to a user-specified object (will be passed to the callback function).
  66. */
  67. void flasher_set_callback(FlasherCallback callback, void* context);
  68. /**
  69. * @brief Start the flashing process.
  70. *
  71. * The only way to get the return value is via the event callback.
  72. *
  73. * @param[in] file_path pointer to a zero-terminated string containing the full firmware file path.
  74. */
  75. void flasher_start(const char* file_path);