wii_ec_udraw.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //! udraw support is NOT written - this is just notes about the init function
  2. #include <stdint.h>
  3. #include <furi.h> // Core API
  4. #include "wii_anal.h"
  5. #include "wii_ec.h"
  6. #include "bc_logging.h"
  7. #include "i2c_workaround.h" //! temporary workaround for a bug in furi i2c [see header]
  8. // ** If you want to see what this source code looks like with all the MACROs expanded
  9. // ** grep -v '#include ' wii_ec_udraw.c | gcc -E -o /dev/stdout -xc -
  10. #include "wii_ec_macros.h"
  11. //+============================================================================ ========================================
  12. // https://github.com/madhephaestus/WiiChuck/blob/master/src/Drawsome.cpp#L3
  13. // Gratuitously stolen ... never tested (don't own one) - just bought one on ebay <shrug>
  14. // although it seems like the UK version is a "uDraw" and MIGHT contain a different chipset :/
  15. //
  16. // read 6 bytes starting from 0x20
  17. // read 6 bytes starting from 0x28
  18. // read 6 bytes starting from 0x30
  19. // read 6 bytes starting from 0x38
  20. // read 6 bytes starting from 0x00 (#1)
  21. // read 6 bytes starting from 0x00 (#2)
  22. // write 1 byte [0x01] to 0xFB
  23. // read 6 bytes starting from 0x00 (#3)
  24. // read 6 bytes starting from 0x00 (#4)
  25. //
  26. bool udraw_init(wiiEC_t* const pec) {
  27. ENTER;
  28. bool rv = true;
  29. (void)pec;
  30. /*
  31. //! this is the Drawsome code, NOT the uDraw code !!
  32. static const uint8_t reg[9] = {0x20, 0x28, 0x30, 0x38, 0x00, 0x00, 0xFB, 0x00, 0x00}; // 0..8
  33. const uint8_t* p = reg;
  34. uint8_t buf[6] = {0};
  35. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 0
  36. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 1
  37. furi_delay_ms(100);
  38. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 2
  39. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 3
  40. furi_delay_ms(100);
  41. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 4
  42. furi_delay_ms(100);
  43. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 5
  44. furi_delay_ms(100);
  45. buf[0] = *p++;
  46. buf[1] = 0x01;
  47. if (!furi_hal_i2c_tx(bus,addr, buf,2, timeout)) goto fail ; // 6
  48. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 7
  49. furi_delay_ms(100);
  50. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 8
  51. furi_delay_ms(100);
  52. TRACE("%s : OK #%d", __func__, (p-reg));
  53. goto done;
  54. fail:
  55. ERROR("%s : fail #%d", __func__, (p -reg) -1);
  56. rv = false;
  57. done:
  58. */
  59. LEAVE;
  60. return rv;
  61. }
  62. //+============================================================================ ========================================
  63. bool udraw_key(const eventMsg_t* const msg, state_t* const state) {
  64. (void)state;
  65. bool run = true;
  66. switch(msg->input.type) {
  67. case InputTypeShort: //# <! After InputTypeRelease within INPUT_LONG_PRESS interval
  68. switch(msg->input.key) {
  69. case InputKeyUp: //# <U [ SHORT-UP ]
  70. case InputKeyDown: //# <D [ SHORT-DOWN ]
  71. case InputKeyLeft: //# <L [ SHORT-LEFT ]
  72. case InputKeyRight: //# <R [ SHORT-RIGHT ]
  73. case InputKeyOk: //# <O [ SHORT-OK ]
  74. case InputKeyBack: //# <B [ SHORT-BACK ]
  75. default:
  76. break; //# <?
  77. }
  78. break;
  79. case InputTypeLong: //# >! After INPUT_LONG_PRESS interval, asynch to InputTypeRelease
  80. switch(msg->input.key) {
  81. case InputKeyUp: //# >U [ LONG-UP ]
  82. case InputKeyDown: //# >D [ LONG-DOWN ]
  83. case InputKeyLeft: //# >L [ LONG-LEFT ]
  84. case InputKeyRight: //# >R [ LONG-RIGHT ]
  85. case InputKeyOk: //# >O [ LONG-OK ]
  86. case InputKeyBack: //# >B [ LONG-BACK ]
  87. default:
  88. break; //# >?
  89. }
  90. break;
  91. case InputTypePress: //# +! After debounce
  92. switch(msg->input.key) {
  93. case InputKeyUp: //# +U [ SHORT-UP ]
  94. case InputKeyDown: //# +D [ SHORT-DOWN ]
  95. case InputKeyLeft: //# +L [ SHORT-LEFT ]
  96. case InputKeyRight: //# +R [ SHORT-RIGHT ]
  97. case InputKeyOk: //# +O [ SHORT-OK ]
  98. case InputKeyBack: //# +B [ SHORT-BACK ]
  99. default:
  100. break; //# +?
  101. }
  102. break;
  103. case InputTypeRepeat: //# *! With INPUT_REPEATE_PRESS period after InputTypeLong event
  104. switch(msg->input.key) {
  105. case InputKeyUp: //# *U [ REPEAT-UP ]
  106. case InputKeyDown: //# *D [ REPEAT-DOWN ]
  107. case InputKeyLeft: //# *L [ REPEAT-LEFT ]
  108. case InputKeyRight: //# *R [ REPEAT-RIGHT ]
  109. case InputKeyOk: //# *O [ REPEAT-OK ]
  110. case InputKeyBack: //# *B [ REPEAT-BACK ]
  111. default:
  112. break; //# *?
  113. }
  114. break;
  115. case InputTypeRelease: //# -! After debounce
  116. switch(msg->input.key) {
  117. case InputKeyUp: //# -U [ RELEASE-UP ]
  118. case InputKeyDown: //# -D [ RELEASE-DOWN ]
  119. case InputKeyLeft: //# -L [ RELEASE-LEFT ]
  120. case InputKeyRight: //# -R [ RELEASE-RIGHT ]
  121. case InputKeyOk: //# -O [ RELEASE-OK ]
  122. case InputKeyBack: //# -B [ RELEASE-BACK ]
  123. default:
  124. break; //# -?
  125. }
  126. break;
  127. default:
  128. return true;
  129. }
  130. return run;
  131. }