gblink.h 1.5 KB

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