gblink.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_CLK_INT,
  16. /* Game Boy drives the clock line */
  17. GBLINK_CLK_EXT,
  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 = 4096,
  29. GBLINK_SPD_16384HZ = 8192,
  30. GBLINK_SPD_262144HZ = 16384,
  31. GBLINK_SPD_524288HZ = 262144,
  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_pinouts;
  44. typedef enum {
  45. PIN_SERIN,
  46. PIN_SEROUT,
  47. PIN_CLK,
  48. PIN_SD,
  49. PIN_COUNT,
  50. } gblink_bus_pins;
  51. /*
  52. * NOTE:
  53. * This can be called at any time, it resets the current byte transfer information
  54. */
  55. void gblink_clk_source_set(void *handle, gblink_clk_source clk_source);
  56. void gblink_speed_set(void *handle, gblink_speed speed);
  57. void gblink_timeout_set(void *handle, uint32_t us);
  58. bool gblink_transfer(void *handle, uint8_t val);
  59. /* Can only be run after alloc, before start */
  60. int gblink_pin_set_default(void *handle, gblink_pinouts pinout);
  61. int gblink_pin_set(void *handle, gblink_bus_pins pin, const GpioPin *gpio);
  62. const GpioPin *gblink_pin_get(void *handle, gblink_bus_pins pin);
  63. int gblink_callback_set(void *handle, void (*callback)(void* cb_context, uint8_t in), void *cb_context);
  64. int gblink_mode_set(void *handle, gblink_mode mode);
  65. /*
  66. * This can be used for INT or EXT clock modes. After a call to
  67. * gblink_transfer this can be called at any time and will return only after
  68. * a full byte is transferred and it will return the byte that was last shifted
  69. * in from the link partner.
  70. */
  71. uint8_t gblink_transfer_tx_wait_complete(void *handle);
  72. void gblink_nobyte_set(void *handle, uint8_t val);
  73. void gblink_int_enable(void *handle);
  74. void gblink_int_disable(void *handle);
  75. /* Sets up some defaults */
  76. void *gblink_alloc(void);
  77. void gblink_free(void *handle);
  78. void gblink_start(void *handle);
  79. void gblink_stop(void *handle);
  80. // void gblink_blink_led_on_byte(handle, color?)
  81. // get blink?
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif // __GBLINK_H__