wii_ec_udraw.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. {
  28. ENTER;
  29. bool rv = true;
  30. (void)pec;
  31. /*
  32. //! this is the Drawsome code, NOT the uDraw code !!
  33. static const uint8_t reg[9] = {0x20, 0x28, 0x30, 0x38, 0x00, 0x00, 0xFB, 0x00, 0x00}; // 0..8
  34. const uint8_t* p = reg;
  35. uint8_t buf[6] = {0};
  36. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 0
  37. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 1
  38. furi_delay_ms(100);
  39. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 2
  40. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 3
  41. furi_delay_ms(100);
  42. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 4
  43. furi_delay_ms(100);
  44. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 5
  45. furi_delay_ms(100);
  46. buf[0] = *p++;
  47. buf[1] = 0x01;
  48. if (!furi_hal_i2c_tx(bus,addr, buf,2, timeout)) goto fail ; // 6
  49. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 7
  50. furi_delay_ms(100);
  51. if (!furi_hal_i2c_trxd(bus,addr, p++,1, buf,sizeof(buf), timeout,300)) goto fail ; // 8
  52. furi_delay_ms(100);
  53. TRACE("%s : OK #%d", __func__, (p-reg));
  54. goto done;
  55. fail:
  56. ERROR("%s : fail #%d", __func__, (p -reg) -1);
  57. rv = false;
  58. done:
  59. */
  60. LEAVE;
  61. return rv;
  62. }
  63. //+============================================================================ ========================================
  64. bool udraw_key (const eventMsg_t* const msg, state_t* const state)
  65. {
  66. (void)state;
  67. bool run = true;
  68. switch (msg->input.type) {
  69. case InputTypeShort: //# <! After InputTypeRelease within INPUT_LONG_PRESS interval
  70. switch (msg->input.key) {
  71. case InputKeyUp: //# <U [ SHORT-UP ]
  72. case InputKeyDown: //# <D [ SHORT-DOWN ]
  73. case InputKeyLeft: //# <L [ SHORT-LEFT ]
  74. case InputKeyRight: //# <R [ SHORT-RIGHT ]
  75. case InputKeyOk: //# <O [ SHORT-OK ]
  76. case InputKeyBack: //# <B [ SHORT-BACK ]
  77. default: break ; //# <?
  78. }
  79. break;
  80. case InputTypeLong: //# >! After INPUT_LONG_PRESS interval, asynch to InputTypeRelease
  81. switch (msg->input.key) {
  82. case InputKeyUp: //# >U [ LONG-UP ]
  83. case InputKeyDown: //# >D [ LONG-DOWN ]
  84. case InputKeyLeft: //# >L [ LONG-LEFT ]
  85. case InputKeyRight: //# >R [ LONG-RIGHT ]
  86. case InputKeyOk: //# >O [ LONG-OK ]
  87. case InputKeyBack: //# >B [ LONG-BACK ]
  88. default: 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: break ; //# +?
  100. }
  101. break;
  102. case InputTypeRepeat: //# *! With INPUT_REPEATE_PRESS period after InputTypeLong event
  103. switch (msg->input.key) {
  104. case InputKeyUp: //# *U [ REPEAT-UP ]
  105. case InputKeyDown: //# *D [ REPEAT-DOWN ]
  106. case InputKeyLeft: //# *L [ REPEAT-LEFT ]
  107. case InputKeyRight: //# *R [ REPEAT-RIGHT ]
  108. case InputKeyOk: //# *O [ REPEAT-OK ]
  109. case InputKeyBack: //# *B [ REPEAT-BACK ]
  110. default: break ; //# *?
  111. }
  112. break;
  113. case InputTypeRelease: //# -! After debounce
  114. switch (msg->input.key) {
  115. case InputKeyUp: //# -U [ RELEASE-UP ]
  116. case InputKeyDown: //# -D [ RELEASE-DOWN ]
  117. case InputKeyLeft: //# -L [ RELEASE-LEFT ]
  118. case InputKeyRight: //# -R [ RELEASE-RIGHT ]
  119. case InputKeyOk: //# -O [ RELEASE-OK ]
  120. case InputKeyBack: //# -B [ RELEASE-BACK ]
  121. default: break ; //# -?
  122. }
  123. break;
  124. default: return true ;
  125. }
  126. return run;
  127. }