gblink.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: BSD-2-Clause
  2. // Copyright (c) 2023 KBEmbedded
  3. #ifndef __GBLINK_H__
  4. #define __GBLINK_H__
  5. #pragma once
  6. #include <furi.h>
  7. #include <furi_hal.h>
  8. #include <stdint.h>
  9. typedef enum {
  10. /* Flipper drives the clock line */
  11. /* Unsupported at this time */
  12. GBLINK_INTERNAL_CLK,
  13. /* Game Boy drives the clock line */
  14. GBLINK_EXTERNAL_CLK,
  15. } gblink_clk_source;
  16. /* Currently unused */
  17. typedef enum {
  18. GBLINK_MODE_GBC,
  19. GBLINK_MODE_GBA,
  20. } gblink_mode;
  21. /* Should this just be a macro? */
  22. /* This pretty much only applies to GBC, OG GB is 8192 Hz only */
  23. /* This is only for TX */
  24. typedef enum {
  25. GBLINK_SPD_8192HZ,
  26. GBLINK_SPD_16384HZ,
  27. GBLINK_SPD_262144HZ,
  28. GBLINK_SPD_524288HZ,
  29. } gblink_speed;
  30. struct gblink_pins {
  31. const GpioPin *serin;
  32. const GpioPin *serout;
  33. const GpioPin *clk;
  34. const GpioPin *sd;
  35. };
  36. typedef enum {
  37. PINOUT_ORIGINAL,
  38. PINOUT_MALVEKE_EXT1,
  39. PINOUT_COUNT,
  40. } gblink_pinout;
  41. extern const struct gblink_pins common_pinouts[PINOUT_COUNT];
  42. struct gblink_def {
  43. struct gblink_pins *pins;
  44. gblink_clk_source source;
  45. gblink_mode mode;
  46. void (*callback)(void* cb_context, uint8_t in);
  47. void *cb_context;
  48. };
  49. void gblink_clk_source_set(void *handle, int clk_source);
  50. void gblink_speed_set(void *handle, gblink_speed speed);
  51. void gblink_timeout_set(void *handle, uint32_t us);
  52. void gblink_transfer(void *handle, uint8_t val);
  53. void gblink_nobyte_set(void *handle, uint8_t val);
  54. void gblink_int_enable(void *handle);
  55. void gblink_int_disable(void *handle);
  56. void *gblink_alloc(struct gblink_def *gblink_def);
  57. void gblink_free(void *handle);
  58. #endif // __GBLINK_H__