led_controller.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /*
  2. Copyright 2016 flabbergast <s3+flabbergast@sdfeu.org>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /*
  15. * LED controller code
  16. * WF uses IS31FL3731C matrix LED driver from ISSI
  17. * datasheet: http://www.issi.com/WW/pdf/31FL3731C.pdf
  18. */
  19. #include "ch.h"
  20. #include "hal.h"
  21. #include "print.h"
  22. #include "led.h"
  23. #include "led_controller.h"
  24. #include "suspend.h"
  25. #include "usb_main.h"
  26. /* Infinity60 LED MAP
  27. - digits mean "row" and "col", i.e. 45 means C4-5 in the IS31 datasheet, matrix A
  28. 11 12 13 14 15 16 17 18 21 22 23 24 25 26 27*
  29. 28 31 32 33 34 35 36 37 38 41 42 43 44 45
  30. 46 47 48 51 52 53 54 55 56 57 58 61 62
  31. 63 64 65 66 67 68 71 72 73 74 75 76 77*
  32. 78 81 82 83 84 85 86 87
  33. *Unused in Alphabet Layout
  34. */
  35. /*
  36. each page has 0xB4 bytes
  37. 0 - 0x11: LED control (on/off):
  38. order: CA1, CB1, CA2, CB2, .... (CA - matrix A, CB - matrix B)
  39. CAn controls Cn-8 .. Cn-1 (LSbit)
  40. 0x12 - 0x23: blink control (like "LED control")
  41. 0x24 - 0xB3: PWM control: byte per LED, 0xFF max on
  42. order same as above (CA 1st row (8bytes), CB 1st row (8bytes), ...)
  43. */
  44. /* Which LED should be used for CAPS LOCK indicator
  45. * The usual Caps Lock position is C4-6, so the address is
  46. * 0x24 + (4-1)*0x10 + (8-1) = 0x59 */
  47. #if !defined(CAPS_LOCK_LED_ADDRESS)
  48. #define CAPS_LOCK_LED_ADDRESS 46
  49. #endif
  50. #if !defined(NUM_LOCK_LED_ADDRESS)
  51. #define NUM_LOCK_LED_ADDRESS 85
  52. #endif
  53. /* Which LED should breathe during sleep */
  54. #if !defined(BREATHE_LED_ADDRESS)
  55. #define BREATHE_LED_ADDRESS CAPS_LOCK_LED_ADDRESS
  56. #endif
  57. /* =================
  58. * ChibiOS I2C setup
  59. * ================= */
  60. static const I2CConfig i2ccfg = {
  61. 400000 // clock speed (Hz); 400kHz max for IS31
  62. };
  63. /* ==============
  64. * variables
  65. * ============== */
  66. // internal communication buffers
  67. uint8_t tx[2] __attribute__((aligned(2)));
  68. uint8_t rx[1] __attribute__((aligned(2)));
  69. // buffer for sending the whole page at once (used also as a temp buffer)
  70. uint8_t full_page[0xB4+1] = {0};
  71. // LED mask (which LEDs are present, selected by bits)
  72. // See page comment above, control alternates CA matrix/CB matrix
  73. // IC60 pcb uses only CA matrix.
  74. // Each byte is a control pin for 8 leds ordered 8-1
  75. const uint8_t all_on_leds_mask[0x12] = {
  76. 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF,
  77. 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7F, 0x00, 0x00, 0x00
  78. };
  79. // array to hold brightness pwm steps
  80. const uint8_t pwm_levels[5] = {
  81. 0x00, 0x16, 0x4E, 0xA1, 0xFF
  82. };
  83. // array to write to pwm register
  84. uint8_t pwm_register_array[9] = {0};
  85. /* ============================
  86. * communication functions
  87. * ============================ */
  88. msg_t is31_select_page(uint8_t page) {
  89. tx[0] = IS31_COMMANDREGISTER;
  90. tx[1] = page;
  91. return i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, tx, 2, NULL, 0, US2ST(IS31_TIMEOUT));
  92. }
  93. msg_t is31_write_data(uint8_t page, uint8_t *buffer, uint8_t size) {
  94. is31_select_page(page);
  95. return i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, buffer, size, NULL, 0, US2ST(IS31_TIMEOUT));
  96. }
  97. msg_t is31_write_register(uint8_t page, uint8_t reg, uint8_t data) {
  98. is31_select_page(page);
  99. tx[0] = reg;
  100. tx[1] = data;
  101. return i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, tx, 2, NULL, 0, US2ST(IS31_TIMEOUT));
  102. }
  103. msg_t is31_read_register(uint8_t page, uint8_t reg, uint8_t *result) {
  104. is31_select_page(page);
  105. tx[0] = reg;
  106. return i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, tx, 1, result, 1, US2ST(IS31_TIMEOUT));
  107. }
  108. /* ========================
  109. * initialise the IS31 chip
  110. * ======================== */
  111. void is31_init(void) {
  112. // just to be sure that it's all zeroes
  113. __builtin_memset(full_page,0,0xB4+1);
  114. // zero function page, all registers (assuming full_page is all zeroes)
  115. is31_write_data(IS31_FUNCTIONREG, full_page, 0xD + 1);
  116. // disable hardware shutdown
  117. palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL);
  118. palSetPad(GPIOB, 16);
  119. chThdSleepMilliseconds(10);
  120. // software shutdown
  121. is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, 0);
  122. chThdSleepMilliseconds(10);
  123. // software shutdown disable (i.e. turn stuff on)
  124. is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON);
  125. chThdSleepMilliseconds(10);
  126. // zero all LED registers on all 8 pages
  127. uint8_t i;
  128. for(i=0; i<8; i++) {
  129. is31_write_data(i, full_page, 0xB4 + 1);
  130. chThdSleepMilliseconds(1);
  131. }
  132. }
  133. /* ==================
  134. * LED control thread
  135. * ================== */
  136. #define LED_MAILBOX_NUM_MSGS 5
  137. static msg_t led_mailbox_queue[LED_MAILBOX_NUM_MSGS];
  138. mailbox_t led_mailbox;
  139. static THD_WORKING_AREA(waLEDthread, 256);
  140. static THD_FUNCTION(LEDthread, arg) {
  141. (void)arg;
  142. chRegSetThreadName("LEDthread");
  143. uint8_t i, page;
  144. uint8_t control_register_word[2] = {0};
  145. uint8_t led_control_reg[0x13] = {0};//led control register start address + 0x12 bytes
  146. //persistent status variables
  147. uint8_t backlight_status, led_step_status, layer_status;
  148. //mailbox variables
  149. uint8_t temp, msg_type, msg_led;
  150. msg_t msg;
  151. /* //control register variables
  152. uint8_t page, save_page, save_breath1, save_breath2;
  153. msg_t msg, retval;
  154. */
  155. // initialize persistent variables
  156. backlight_status = 0;
  157. led_step_status = 4; //full brightness
  158. layer_status = 0;
  159. while(true) {
  160. // wait for a message (asynchronous)
  161. // (messages are queued (up to LED_MAILBOX_NUM_MSGS) if they can't
  162. // be processed right away)
  163. chMBFetch(&led_mailbox, &msg, TIME_INFINITE);
  164. msg_type = (msg >> 8) & 0xFF; //first byte is msg type
  165. msg_led = (msg) & 0xFF; //second byte is action information
  166. xprintf("--------------------\n");
  167. xprintf("mailbox fetch\nmsg: %X\n", msg);
  168. xprintf("type: %X - led: %X\n", msg_type, msg_led); //test if msg_type is 1 or 2 bytes after mask
  169. switch (msg_type){
  170. case KEY_LIGHT:
  171. //TODO: lighting key led on keypress
  172. break;
  173. //turn on/off/toggle single led, msg_led = row/col of led
  174. case OFF_LED:
  175. xprintf("OFF_LED\n");
  176. set_led_bit(7, control_register_word, msg_led, 0);
  177. is31_write_data (7, control_register_word, 0x02);
  178. if (layer_status > 0) {//check current led page to prevent double blink
  179. is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7);
  180. }
  181. layer_status = 7;
  182. break;
  183. case ON_LED:
  184. xprintf("ON_LED\n");
  185. set_led_bit(7, control_register_word, msg_led, 1);
  186. is31_write_data (7, control_register_word, 0x02);
  187. if (layer_status > 7) {
  188. is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7);
  189. }
  190. layer_status = 7;
  191. break;
  192. case TOGGLE_LED:
  193. xprintf("TOGGLE_LED\n");
  194. set_led_bit(7, control_register_word, msg_led, 2);
  195. is31_write_data (7, control_register_word, 0x02);
  196. if (layer_status > 7) {
  197. is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7);
  198. }
  199. layer_status = 7;
  200. break;
  201. case TOGGLE_ALL:
  202. xprintf("TOGGLE_ALL\n");
  203. //msg_led = unused, TODO: consider using msg_led to toggle layer display
  204. is31_read_register(0, 0x00, &temp);//if first byte is on, then toggle frame 1 off
  205. led_control_reg[0] = 0;
  206. if (temp==0) {
  207. xprintf("all leds on");
  208. __builtin_memcpy(led_control_reg+1, all_on_leds_mask, 0x12);
  209. } else {
  210. xprintf("all leds off");
  211. __builtin_memset(led_control_reg+1, 0, 0x12);
  212. }
  213. is31_write_data(0, led_control_reg, 0x13);
  214. if (layer_status > 0) {
  215. is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0);
  216. }
  217. layer_status=0;
  218. //TODO: Double blink when all on
  219. break;
  220. case TOGGLE_BACKLIGHT:
  221. //msg_led = unused
  222. //TODO: consider Frame 0 as on/off layer and toggle led control register here
  223. //TODO: need to test tracking of active layer with layer_state from qmk
  224. xprintf("TOGGLE_BACKLIGHT\n");
  225. backlight_status ^= 1;
  226. is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp);
  227. layer_status = temp;
  228. page = backlight_status == 0 ? 0 : layer_status;
  229. is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, page);
  230. break;
  231. case TOGGLE_LAYER_LEDS://show layer indicator or full map of layer keys.
  232. //TODO: change so user can flag which they want, indiv or full map in fn_actions
  233. //msg_led = layer to toggle on
  234. xprintf("TOGGLE_LAYER_LEDS\n");
  235. is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp);
  236. if(temp == msg_led) {
  237. is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7);
  238. layer_status = 7;
  239. } else {
  240. is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led);
  241. layer_status = msg_led;
  242. }
  243. break;
  244. case TOGGLE_NUM_LOCK:
  245. //msg_led = 0 or 1, off/on
  246. //TODO: confirm toggling works and doesn't get out of sync
  247. set_lock_leds(USB_LED_NUM_LOCK, msg_led);
  248. break;
  249. case TOGGLE_CAPS_LOCK:
  250. //msg_led = 0 or 1, off/on
  251. //TODO: confirm toggling works and doesn't get out of sync
  252. set_lock_leds(USB_LED_CAPS_LOCK, msg_led);
  253. break;
  254. case MODE_BREATH:
  255. break;
  256. case STEP_BRIGHTNESS:
  257. //TEST: Step brightness code
  258. //pwm_levels[] bounds checking, loop through array
  259. //TODO: find a cleaner way to walk through this logic
  260. if (msg_led == 0 && led_step_status == 0) {
  261. led_step_status = 4;
  262. } else {
  263. led_step_status--;
  264. }
  265. if (msg_led == 1 && led_step_status == 4) {
  266. led_step_status = 0;
  267. } else {
  268. led_step_status++;
  269. }
  270. //TODO: this seems a messy way to populate the pwm register
  271. //mimic whitefox init which uses memcpy
  272. //populate the 9 byte rows to be written to each pin, first byte is register (pin) address
  273. for(i=1; i<9; i++) {
  274. pwm_register_array[i]=pwm_levels[led_step_status];
  275. }
  276. for(i=0; i<8; i++) {
  277. pwm_register_array[0] = 0x24 + (i * 0x10);//first byte of 9 bytes must be register address
  278. is31_write_data(0, pwm_register_array, 9);//first page controls pwm in all pages (init Display Option register)
  279. }
  280. break;
  281. /* case LED_MSG_SLEEP_LED_ON:
  282. // save current settings
  283. is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &save_page);
  284. is31_read_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL1, &save_breath1);
  285. is31_read_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, &save_breath2);
  286. // use pages 7 and 8 for (hardware) breathing (assuming they're empty)
  287. is31_write_register(6, BREATHE_LED_ADDRESS, 0xFF);
  288. is31_write_register(7, BREATHE_LED_ADDRESS, 0x00);
  289. is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL1, (6<<4)|6);
  290. is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, IS31_REG_BREATHCTRL2_ENABLE|3);
  291. retval = MSG_TIMEOUT;
  292. temp = 6;
  293. while(retval == MSG_TIMEOUT) {
  294. // switch to the other page
  295. is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, temp);
  296. temp = (temp == 6 ? 7 : 6);
  297. // the times should be sufficiently long for IS31 to finish switching pages
  298. retval = chMBFetch(&led_mailbox, &msg, MS2ST(temp == 6 ? 4000 : 6000));
  299. }
  300. // received a message (should be a wakeup), so restore previous state
  301. chThdSleepMilliseconds(3000); // need to wait until the page change finishes
  302. // note: any other messages are queued
  303. is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL1, save_breath1);
  304. is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, save_breath2);
  305. is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, save_page);
  306. break;
  307. case LED_MSG_SLEEP_LED_OFF:
  308. // should not get here; wakeup should be received in the branch above break;
  309. break;
  310. */
  311. }
  312. xprintf("--------------------\n");
  313. }
  314. }
  315. /* ==============================
  316. * led processing functions
  317. * ============================== */
  318. void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action) {
  319. //returns 2 bytes led control register address and byte mask to write
  320. uint8_t control_reg_addr, column_bit, column_byte, temp;
  321. //first byte is led control register address 0x00
  322. //msg_led tens column is pin#, ones column is bit position in 8-bit mask
  323. chThdSleepMilliseconds(10);
  324. xprintf("led_addr: %d ", led_addr);
  325. control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-register is every other byte
  326. column_bit = 1<<(led_addr % 10 - 1);
  327. is31_read_register(page,control_reg_addr,&temp);//need to maintain status of leds in this row (1 byte)
  328. chThdSleepMilliseconds(10);
  329. xprintf("col_bit: %X ", column_bit);
  330. column_byte = temp;
  331. chThdSleepMilliseconds(10);
  332. xprintf("action: %X ", action);
  333. switch(action) {
  334. case 0:
  335. xprintf("off-");
  336. chThdSleepMilliseconds(10);
  337. column_byte &= ~column_bit;
  338. break;
  339. case 1:
  340. xprintf("on-");
  341. chThdSleepMilliseconds(10);
  342. column_byte |= column_bit;
  343. break;
  344. case 2:
  345. xprintf("toggle-");
  346. chThdSleepMilliseconds(10);
  347. column_byte ^= column_bit;
  348. break;
  349. }
  350. led_control_reg[0] = control_reg_addr;
  351. led_control_reg[1] = column_byte;
  352. chThdSleepMilliseconds(10);
  353. xprintf("set_bit row: %X set_bit col: %X\n", led_control_reg[0], led_control_reg[1]);
  354. }
  355. void set_lock_leds(uint8_t lock_type, uint8_t led_on) {
  356. uint8_t page, led_addr;
  357. uint8_t led_control_write[2] = {0};
  358. //TODO: consolidate control register to top level array vs. three scattered around
  359. switch(lock_type) {
  360. case USB_LED_NUM_LOCK:
  361. led_addr = NUM_LOCK_LED_ADDRESS;
  362. break;
  363. case USB_LED_CAPS_LOCK:
  364. led_addr = CAPS_LOCK_LED_ADDRESS;
  365. break;
  366. #ifdef SCROLL_LOCK_LED_ADDRESS
  367. case USB_LED_SCROLL_LOCK:
  368. led_addr = SCROLL_LOCK_LED_ADDRESS;
  369. break;
  370. #endif
  371. #ifdef COMPOSE_LED_ADDRESS
  372. case USB_LED_COMPOSE:
  373. led_addr = COMPOSE_LED_ADDRESS;
  374. break;
  375. #endif
  376. #ifdef SCROLL_LOCK_LED_ADDRESS
  377. case USB_LED_KANA:
  378. led_addr = KANA_LED_ADDRESS;
  379. break;
  380. #endif
  381. }
  382. for(page=0; page<8; page++) { //set in led_controller.h
  383. //TODO: check if frame2 (or frame1, first byte all on), and ignore if true
  384. //also if BACKLIGHT_OFF_LOCK_LED_OFF set
  385. set_led_bit(page,led_control_write,led_addr,led_on);
  386. xprintf("lock_led row: %X lock_led col%X\n", led_control_write[0], led_control_write[1]);
  387. is31_write_data(page, led_control_write, 0x02);
  388. chThdSleepMilliseconds(10);
  389. }
  390. }
  391. void write_led_page (uint8_t page, const uint8_t *led_array, uint8_t led_count) {
  392. uint8_t i;
  393. uint8_t row, col;
  394. uint8_t led_control_register[0x13] = {0};//led control register start address + 0x12 bytes
  395. for(i=0;i<led_count;i++){
  396. row = ((led_array[i] / 10) % 10 - 1 ) * 2 + 1;//includes 1 byte shift for led register 0x00 address
  397. col = led_array[i] % 10 - 1;
  398. led_control_register[row] |= 1<<(col);
  399. }
  400. is31_write_data(page, led_control_register, 0x13);
  401. }
  402. /* =====================
  403. * hook into user keymap
  404. * ===================== */
  405. void led_controller_init(void) {
  406. uint8_t i;
  407. /* initialise I2C */
  408. /* I2C pins */
  409. palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATIVE_2); // PTB0/I2C0/SCL
  410. palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATIVE_2); // PTB1/I2C0/SDA
  411. /* start I2C */
  412. i2cStart(&I2CD1, &i2ccfg);
  413. // try high drive (from kiibohd)
  414. I2CD1.i2c->C2 |= I2Cx_C2_HDRS;
  415. // try glitch fixing (from kiibohd)
  416. I2CD1.i2c->FLT = 4;
  417. chThdSleepMilliseconds(10);
  418. /* initialise IS31 chip */
  419. is31_init();
  420. //set Display Option Register so all pwm intensity is controlled from Frame 1
  421. is31_write_register(IS31_FUNCTIONREG, IS31_REG_DISPLAYOPT, IS31_REG_DISPLAYOPT_INTENSITY_SAME);
  422. /* set full pwm on Frame 1 */
  423. for(i=1; i<9; i++) {
  424. pwm_register_array[i]=0xFF;
  425. }
  426. for(i=0; i<8; i++) {
  427. pwm_register_array[0] = 0x24 + (i * 0x10);//first byte of 9 bytes must be register address
  428. is31_write_data(0, pwm_register_array, 9);
  429. chThdSleepMilliseconds(5);
  430. }
  431. //set all led bits on for Frame 2 LEDS_ALL
  432. //TODO: set all off in init
  433. full_page[0] = 0;
  434. __builtin_memset(full_page+1, 0, 0x12);
  435. is31_write_data(1, full_page, 1+0x12);
  436. /* enable breathing when the displayed page changes */
  437. // Fade-in Fade-out, time = 26ms * 2^N, N=3
  438. is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL1, (3<<4)|3);
  439. is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, IS31_REG_BREATHCTRL2_ENABLE|3);
  440. // clean up the lock LEDs
  441. set_lock_leds(USB_LED_NUM_LOCK, 0);
  442. set_lock_leds(USB_LED_CAPS_LOCK, 0);
  443. /* more time consuming LED processing should be offloaded into
  444. * a thread, with asynchronous messaging. */
  445. chMBObjectInit(&led_mailbox, led_mailbox_queue, LED_MAILBOX_NUM_MSGS);
  446. chThdCreateStatic(waLEDthread, sizeof(waLEDthread), LOWPRIO, LEDthread, NULL);
  447. }
  448. //TODO: Don't know equivalent QMK hooks for these
  449. //
  450. //void hook_usb_suspend_entry(void) {
  451. //#ifdef SLEEP_LED_ENABLE
  452. // chSysLockFromISR();
  453. // chMBPostI(&led_mailbox, LED_MSG_SLEEP_LED_ON);
  454. // chSysUnlockFromISR();
  455. //#endif /* SLEEP_LED_ENABLE */
  456. //}
  457. //
  458. //void hook_usb_suspend_loop(void) {
  459. // chThdSleepMilliseconds(100);
  460. // /* Remote wakeup */
  461. // if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) {
  462. // send_remote_wakeup(&USB_DRIVER);
  463. // }
  464. //}
  465. //
  466. //void hook_usb_wakeup(void) {
  467. //#ifdef SLEEP_LED_ENABLE
  468. // chSysLockFromISR();
  469. // chMBPostI(&led_mailbox, LED_MSG_SLEEP_LED_OFF);
  470. // chSysUnlockFromISR();
  471. //#endif /* SLEEP_LED_ENABLE */
  472. //}
  473. //*/