qmk_firmware/tmk_core/protocol/vusb/main.c
Takeshi ISHII dbbab40981
Refactor rgblight_reconfig.h (#7773)
* Moved contents of rgblight_reconfig.h to rgblight_post_config.h.

In #3582, rgblight_reconfig.h had to be newly created. Now, the build system of qmk_firmware has a post_cofig feature, so that what was done in rgblight_reconfig.h can now be realized in rgblight_post_config.h.

**This commit does not change the build result.**

Testing script
```shell
  # build on master
  git checkout master
  echo master > /tmp/master_md5.txt

  # RGBLIGHT_ENABLE = no
  make HELIX=verbose helix/rev2:default:clean
  make HELIX=verbose helix/rev2:default
  md5 helix_rev2_default.hex >> /tmp/master_md5.txt

  # RGBLIGHT_ENABLE = yes, with animations
  make HELIX=verbose helix/rev2/back:default:clean
  make HELIX=verbose helix/rev2/back:default
  md5 helix_rev2_back_default.hex >> /tmp/master_md5.txt

  # RGBLIGHT_ENABLE = yes, without animations
  make HELIX=verbose,no_ani helix/rev2/back:default:clean
  make HELIX=verbose,no_ani helix/rev2/back:default
  md5 helix_rev2_back_default.hex >> /tmp/master_md5.txt

  # build on refactor_rgblight_reconfig.h
  git checkout refactor_rgblight_reconfig.h
  echo refactor_rgblight_reconfig.h > /tmp/branch_md5.txt

  # RGBLIGHT_ENABLE = no
  make HELIX=verbose helix/rev2:default:clean
  make HELIX=verbose helix/rev2:default
  md5 helix_rev2_default.hex >> /tmp/branch_md5.txt

  # RGBLIGHT_ENABLE = yes, with animations
  make HELIX=verbose helix/rev2/back:default:clean
  make HELIX=verbose helix/rev2/back:default
  md5 helix_rev2_back_default.hex >> /tmp/branch_md5.txt

  # RGBLIGHT_ENABLE = yes, without animations
  make HELIX=verbose,no_ani helix/rev2/back:default:clean
  make HELIX=verbose,no_ani helix/rev2/back:default
  md5 helix_rev2_back_default.hex >> /tmp/branch_md5.txt

  diff -u /tmp/master_md5.txt /tmp/branch_md5.txt
```

Test result:
```
--- /tmp/master_md5.txt 2020-01-03 15:42:22.000000000 +0900
+++ /tmp/branch_md5.txt 2020-01-03 15:42:42.000000000 +0900
@@ -1,4 +1,4 @@
-master
+refactor_rgblight_reconfig.h
 MD5 (helix_rev2_default.hex) = f360032edd522448366d471d8f4f8181
 MD5 (helix_rev2_back_default.hex) = 0c663acc6cccc44476b3b969ad22a48f
 MD5 (helix_rev2_back_default.hex) = e66b1195ff6d38e6e22c975b8ae42fd3
```

* Expressions that are too long are difficult to read, so wrap them.

* Edit the expression again

* remove `defined(RGBLIGHT_ANIMATIONS)` in `tmk_core/common/*/suspend.c`, `tmk_core/protocol/*/main.c`

move contents of rgblight_reconfig.h to rgblight.h.

The following changes were made to rgblight.h.

```diff
+#ifdef RGBLIGHT_USE_TIMER
 void rgblight_task(void);

 void rgblight_timer_init(void);
 void rgblight_timer_enable(void);
 void rgblight_timer_disable(void);
 void rgblight_timer_toggle(void);
+#else
+#define rgblight_task()
+#define rgblight_timer_init()
+#define rgblight_timer_enable()
+#define rgblight_timer_disable()
+#define rgblight_timer_toggle()
+#endif
```

The following changes were made to tmk_core/common/avr/suspend.c, tmk_core/common/chibios/suspend.c, tmk_core/protocol/chibios/main.c, tmk_core/protocol/lufa/lufa.c, tmk_core/protocol/vusb/main.c.

```diff
-#    ifdef RGBLIGHT_ANIMATIONS
     rgblight_timer_enable();
-#    endif
```
```diff
-#if defined(RGBLIGHT_ANIMATIONS) && defined(RGBLIGHT_ENABLE)
+#if defined(RGBLIGHT_ENABLE)
         rgblight_task();
 #endif
```

* remove 'defined(RGBLIGHT_ANIMATIONS)' in tmk_core/common/keyboard.c

Co-authored-by: Joel Challis <git@zvecr.com>
2020-03-10 01:46:03 -07:00

106 lines
2.9 KiB
C

/* Name: main.c
* Project: hid-mouse, a very simple HID example
* Author: Christian Starkjohann
* Creation Date: 2008-04-07
* Tabsize: 4
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
* This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
*/
#include <stdint.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include "usbdrv.h"
#include "oddebug.h"
#include "vusb.h"
#include "keyboard.h"
#include "host.h"
#include "timer.h"
#include "uart.h"
#include "debug.h"
#if defined(RGBLIGHT_ENABLE)
# include "rgblight.h"
#endif
#define UART_BAUD_RATE 115200
/* This is from main.c of USBaspLoader */
static void initForUsbConnectivity(void) {
uint8_t i = 0;
usbInit();
/* enforce USB re-enumerate: */
usbDeviceDisconnect(); /* do this while interrupts are disabled */
while (--i) { /* fake USB disconnect for > 250 ms */
wdt_reset();
_delay_ms(1);
}
usbDeviceConnect();
sei();
}
int main(void) {
bool suspended = false;
#if USB_COUNT_SOF
uint16_t last_timer = timer_read();
#endif
#ifdef CLKPR
// avoid unintentional changes of clock frequency in devices that have a
// clock prescaler
CLKPR = 0x80, CLKPR = 0;
#endif
#ifndef NO_UART
uart_init(UART_BAUD_RATE);
#endif
keyboard_setup();
host_set_driver(vusb_driver());
debug("initForUsbConnectivity()\n");
initForUsbConnectivity();
keyboard_init();
debug("main loop\n");
while (1) {
#if USB_COUNT_SOF
if (usbSofCount != 0) {
suspended = false;
usbSofCount = 0;
last_timer = timer_read();
} else {
// Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
if (timer_elapsed(last_timer) > 5) {
suspended = true;
/*
uart_putchar('S');
_delay_ms(1);
cli();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_bod_disable();
sei();
sleep_cpu();
sleep_disable();
_delay_ms(10);
uart_putchar('W');
*/
}
}
#endif
if (!suspended) {
usbPoll();
// TODO: configuration process is incosistent. it sometime fails.
// To prevent failing to configure NOT scan keyboard during configuration
if (usbConfiguration && usbInterruptIsReady()) {
keyboard_task();
}
vusb_transfer_keyboard();
}
}
}