gblink.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef enum {
  13. /* Flipper drives the clock line */
  14. /* Unsupported at this time */
  15. GBLINK_INTERNAL_CLK,
  16. /* Game Boy drives the clock line */
  17. GBLINK_EXTERNAL_CLK,
  18. } gblink_clk_source;
  19. /* Currently unused */
  20. typedef enum {
  21. GBLINK_MODE_GBC,
  22. GBLINK_MODE_GBA,
  23. } gblink_mode;
  24. /* Should this just be a macro? */
  25. /* This pretty much only applies to GBC, OG GB is 8192 Hz only */
  26. /* This is only for TX */
  27. typedef enum {
  28. GBLINK_SPD_8192HZ,
  29. GBLINK_SPD_16384HZ,
  30. GBLINK_SPD_262144HZ,
  31. GBLINK_SPD_524288HZ,
  32. } gblink_speed;
  33. struct gblink_pins {
  34. const GpioPin *serin;
  35. const GpioPin *serout;
  36. const GpioPin *clk;
  37. const GpioPin *sd;
  38. };
  39. typedef enum {
  40. PINOUT_ORIGINAL,
  41. PINOUT_MALVEKE_EXT1,
  42. PINOUT_COUNT,
  43. } gblink_pinout;
  44. extern const struct gblink_pins common_pinouts[PINOUT_COUNT];
  45. struct gblink_def {
  46. struct gblink_pins *pins;
  47. gblink_clk_source source;
  48. gblink_mode mode;
  49. void (*callback)(void* cb_context, uint8_t in);
  50. void *cb_context;
  51. };
  52. void gblink_clk_source_set(void *handle, int clk_source);
  53. void gblink_speed_set(void *handle, gblink_speed speed);
  54. void gblink_timeout_set(void *handle, uint32_t us);
  55. void gblink_transfer(void *handle, uint8_t val);
  56. void gblink_nobyte_set(void *handle, uint8_t val);
  57. void gblink_int_enable(void *handle);
  58. void gblink_int_disable(void *handle);
  59. void *gblink_alloc(struct gblink_def *gblink_def);
  60. void gblink_free(void *handle);
  61. #ifdef __cplusplus
  62. {
  63. #endif
  64. #endif // __GBLINK_H__