]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
clang-format changes
authorskullY <skullydazed@gmail.com>
Fri, 30 Aug 2019 18:19:03 +0000 (11:19 -0700)
committerskullydazed <skullydazed@users.noreply.github.com>
Fri, 30 Aug 2019 22:01:52 +0000 (15:01 -0700)
502 files changed:
drivers/arm/i2c_master.c
drivers/arm/i2c_master.h
drivers/avr/analog.c
drivers/avr/analog.h
drivers/avr/apa102.c [changed mode: 0755->0644]
drivers/avr/apa102.h [changed mode: 0755->0644]
drivers/avr/glcdfont.c
drivers/avr/hd44780.c
drivers/avr/hd44780.h
drivers/avr/i2c_master.c [changed mode: 0755->0644]
drivers/avr/i2c_master.h [changed mode: 0755->0644]
drivers/avr/i2c_slave.c [changed mode: 0755->0644]
drivers/avr/i2c_slave.h [changed mode: 0755->0644]
drivers/avr/pro_micro.h
drivers/avr/ssd1306.c
drivers/avr/ssd1306.h
drivers/avr/ws2812.c
drivers/avr/ws2812.h
drivers/boards/GENERIC_STM32_F303XC/board.c
drivers/boards/GENERIC_STM32_F303XC/board.h
drivers/boards/IC_TEENSY_3_1/board.c
drivers/boards/IC_TEENSY_3_1/board.h
drivers/gpio/pca9555.c
drivers/haptic/DRV2605L.c
drivers/haptic/DRV2605L.h
drivers/haptic/haptic.c
drivers/haptic/haptic.h
drivers/haptic/solenoid.c
drivers/haptic/solenoid.h
drivers/issi/is31fl3218.c
drivers/issi/is31fl3218.h
drivers/issi/is31fl3731-simple.c
drivers/issi/is31fl3731-simple.h
drivers/issi/is31fl3731.c
drivers/issi/is31fl3731.h
drivers/issi/is31fl3733.c
drivers/issi/is31fl3733.h
drivers/issi/is31fl3736.c
drivers/issi/is31fl3736.h
drivers/issi/is31fl3737.c
drivers/issi/is31fl3737.h
drivers/oled/glcdfont.c
drivers/oled/oled_driver.c
drivers/oled/oled_driver.h
drivers/qwiic/micro_oled.c
drivers/qwiic/micro_oled.h
drivers/qwiic/qwiic.c
drivers/qwiic/qwiic.h
drivers/qwiic/util/font5x7.h
drivers/qwiic/util/font8x16.h
drivers/ugfx/gdisp/is31fl3731c/board_is31fl3731c_template.h
drivers/ugfx/gdisp/is31fl3731c/gdisp_is31fl3731c.c
drivers/ugfx/gdisp/is31fl3731c/gdisp_lld_config.h
drivers/ugfx/gdisp/st7565/board_st7565_template.h
drivers/ugfx/gdisp/st7565/gdisp_lld_ST7565.c
drivers/ugfx/gdisp/st7565/gdisp_lld_config.h
drivers/ugfx/gdisp/st7565/st7565.h
quantum/api.c
quantum/api.h
quantum/api/api_sysex.c
quantum/api/api_sysex.h
quantum/audio/audio.c
quantum/audio/audio.h
quantum/audio/audio_arm.c
quantum/audio/audio_pwm.c
quantum/audio/luts.c
quantum/audio/luts.h
quantum/audio/muse.c
quantum/audio/musical_notes.h
quantum/audio/song_list.h
quantum/audio/voices.c
quantum/audio/voices.h
quantum/audio/wave.h
quantum/color.c
quantum/color.h
quantum/config_common.h
quantum/debounce/eager_pk.c
quantum/debounce/eager_pr.c
quantum/debounce/sym_g.c
quantum/dynamic_keymap.c
quantum/dynamic_keymap.h
quantum/dynamic_macro.h
quantum/encoder.c
quantum/fauxclicky.c
quantum/fauxclicky.h
quantum/keycode_config.c
quantum/keycode_config.h
quantum/keymap.h
quantum/keymap_common.c
quantum/keymap_extras/keymap_belgian.h
quantum/keymap_extras/keymap_bepo.h
quantum/keymap_extras/keymap_br_abnt2.h
quantum/keymap_extras/keymap_canadian_multilingual.h
quantum/keymap_extras/keymap_colemak.h
quantum/keymap_extras/keymap_dvorak.h
quantum/keymap_extras/keymap_dvp.h
quantum/keymap_extras/keymap_fr_ch.h
quantum/keymap_extras/keymap_french.h
quantum/keymap_extras/keymap_french_osx.h
quantum/keymap_extras/keymap_german.h
quantum/keymap_extras/keymap_german_ch.h
quantum/keymap_extras/keymap_german_osx.h
quantum/keymap_extras/keymap_hungarian.h
quantum/keymap_extras/keymap_italian.h
quantum/keymap_extras/keymap_jp.h
quantum/keymap_extras/keymap_nordic.h
quantum/keymap_extras/keymap_norman.h
quantum/keymap_extras/keymap_norwegian.h
quantum/keymap_extras/keymap_plover.h
quantum/keymap_extras/keymap_plover_dvorak.h
quantum/keymap_extras/keymap_slovenian.h
quantum/keymap_extras/keymap_spanish.h
quantum/keymap_extras/keymap_steno.h
quantum/keymap_extras/keymap_swedish.h
quantum/keymap_extras/keymap_uk.h
quantum/keymap_extras/keymap_workman.h
quantum/keymap_extras/sendstring_belgian.h
quantum/keymap_extras/sendstring_bepo.h
quantum/keymap_extras/sendstring_colemak.h
quantum/keymap_extras/sendstring_dvorak.h
quantum/keymap_extras/sendstring_french.h
quantum/keymap_extras/sendstring_german.h
quantum/keymap_extras/sendstring_jis.h
quantum/keymap_extras/sendstring_norman.h
quantum/keymap_extras/sendstring_spanish.h
quantum/keymap_extras/sendstring_uk.h
quantum/keymap_extras/sendstring_workman.h
quantum/led_matrix.c
quantum/led_matrix_drivers.c
quantum/led_tables.c
quantum/ledmatrix.h
quantum/matrix.c
quantum/pincontrol.h
quantum/pointing_device.c
quantum/pointing_device.h
quantum/process_keycode/process_audio.c
quantum/process_keycode/process_auto_shift.c
quantum/process_keycode/process_auto_shift.h
quantum/process_keycode/process_clicky.c
quantum/process_keycode/process_combo.c
quantum/process_keycode/process_combo.h
quantum/process_keycode/process_key_lock.c
quantum/process_keycode/process_key_lock.h
quantum/process_keycode/process_leader.c
quantum/process_keycode/process_leader.h
quantum/process_keycode/process_midi.c
quantum/process_keycode/process_midi.h
quantum/process_keycode/process_music.c
quantum/process_keycode/process_music.h
quantum/process_keycode/process_printer.c
quantum/process_keycode/process_printer_bb.c
quantum/process_keycode/process_space_cadet.c
quantum/process_keycode/process_steno.c
quantum/process_keycode/process_steno.h
quantum/process_keycode/process_tap_dance.c
quantum/process_keycode/process_tap_dance.h
quantum/process_keycode/process_terminal.c
quantum/process_keycode/process_terminal.h
quantum/process_keycode/process_ucis.c
quantum/process_keycode/process_ucis.h
quantum/process_keycode/process_unicode.c
quantum/process_keycode/process_unicode_common.c
quantum/process_keycode/process_unicode_common.h
quantum/process_keycode/process_unicodemap.c
quantum/process_keycode/process_unicodemap.h
quantum/quantum.c
quantum/quantum.h
quantum/quantum_keycodes.h
quantum/rgb.h
quantum/rgb_matrix.c
quantum/rgb_matrix.h
quantum/rgb_matrix_animations/alpha_mods_anim.h
quantum/rgb_matrix_animations/breathing_anim.h
quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h
quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h
quantum/rgb_matrix_animations/colorband_sat_anim.h
quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h
quantum/rgb_matrix_animations/colorband_spiral_val_anim.h
quantum/rgb_matrix_animations/colorband_val_anim.h
quantum/rgb_matrix_animations/cycle_all_anim.h
quantum/rgb_matrix_animations/cycle_left_right_anim.h
quantum/rgb_matrix_animations/cycle_out_in_anim.h
quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h
quantum/rgb_matrix_animations/cycle_pinwheel_anim.h
quantum/rgb_matrix_animations/cycle_spiral_anim.h
quantum/rgb_matrix_animations/cycle_up_down_anim.h
quantum/rgb_matrix_animations/digital_rain_anim.h
quantum/rgb_matrix_animations/dual_beacon_anim.h
quantum/rgb_matrix_animations/gradient_up_down_anim.h
quantum/rgb_matrix_animations/jellybean_raindrops_anim.h
quantum/rgb_matrix_animations/rainbow_beacon_anim.h
quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h
quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h
quantum/rgb_matrix_animations/raindrops_anim.h
quantum/rgb_matrix_animations/solid_color_anim.h
quantum/rgb_matrix_animations/solid_reactive_anim.h
quantum/rgb_matrix_animations/solid_reactive_cross.h
quantum/rgb_matrix_animations/solid_reactive_nexus.h
quantum/rgb_matrix_animations/solid_reactive_simple_anim.h
quantum/rgb_matrix_animations/solid_reactive_wide.h
quantum/rgb_matrix_animations/solid_splash_anim.h
quantum/rgb_matrix_animations/splash_anim.h
quantum/rgb_matrix_animations/typing_heatmap_anim.h
quantum/rgb_matrix_drivers.c
quantum/rgb_matrix_runners/effect_runner_dx_dy.h
quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h
quantum/rgb_matrix_runners/effect_runner_i.h
quantum/rgb_matrix_runners/effect_runner_reactive.h
quantum/rgb_matrix_runners/effect_runner_reactive_splash.h
quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h
quantum/rgb_matrix_types.h
quantum/rgblight.c
quantum/rgblight.h
quantum/rgblight_breathe_table.h
quantum/rgblight_list.h
quantum/rgblight_modes.h
quantum/rgblight_post_config.h
quantum/rgblight_reconfig.h
quantum/send_string_keycodes.h
quantum/serial_link/protocol/byte_stuffer.c
quantum/serial_link/protocol/frame_router.c
quantum/serial_link/protocol/frame_validator.c
quantum/serial_link/protocol/transport.c
quantum/serial_link/protocol/transport.h
quantum/serial_link/protocol/triple_buffered_object.c
quantum/serial_link/protocol/triple_buffered_object.h
quantum/serial_link/system/serial_link.c
quantum/serial_link/system/serial_link.h
quantum/serial_link/tests/byte_stuffer_tests.cpp
quantum/serial_link/tests/frame_router_tests.cpp
quantum/serial_link/tests/frame_validator_tests.cpp
quantum/serial_link/tests/transport_tests.cpp
quantum/serial_link/tests/triple_buffered_object_tests.cpp
quantum/split_common/matrix.c
quantum/split_common/post_config.h
quantum/split_common/serial.c
quantum/split_common/serial.h
quantum/split_common/split_util.c
quantum/split_common/split_util.h
quantum/split_common/transport.c
quantum/stm32/chconf.h
quantum/stm32/halconf.h
quantum/stm32/mcuconf.h
quantum/template/avr/config.h
quantum/template/base/keymaps/default/keymap.c
quantum/template/base/template.h
quantum/template/ps2avrgb/config.h
quantum/template/ps2avrgb/template.c
quantum/template/ps2avrgb/usbconfig.h
quantum/variable_trace.c
quantum/variable_trace.h
quantum/velocikey.c
quantum/velocikey.h
quantum/visualizer/common_gfxconf.h
quantum/visualizer/default_animations.c
quantum/visualizer/lcd_backlight.c
quantum/visualizer/lcd_backlight.h
quantum/visualizer/lcd_backlight_keyframes.c
quantum/visualizer/lcd_keyframes.c
quantum/visualizer/lcd_keyframes.h
quantum/visualizer/led_backlight_keyframes.c
quantum/visualizer/led_backlight_keyframes.h
quantum/visualizer/resources/lcd_logo.c
quantum/visualizer/resources/resources.h
quantum/visualizer/visualizer.c
quantum/visualizer/visualizer.h
tests/basic/keymap.c
tests/basic/test_keypress.cpp
tests/basic/test_macro.cpp
tests/test_common/keyboard_report_util.cpp
tests/test_common/matrix.c
tests/test_common/test_driver.cpp
tests/test_common/test_fixture.cpp
tmk_core/common/action.c
tmk_core/common/action.h
tmk_core/common/action_code.h
tmk_core/common/action_layer.c
tmk_core/common/action_layer.h
tmk_core/common/action_macro.c
tmk_core/common/action_macro.h
tmk_core/common/action_tapping.c
tmk_core/common/action_tapping.h
tmk_core/common/action_util.c
tmk_core/common/action_util.h
tmk_core/common/arm_atsam/bootloader.c
tmk_core/common/arm_atsam/eeprom.c
tmk_core/common/arm_atsam/printf.c
tmk_core/common/arm_atsam/printf.h
tmk_core/common/arm_atsam/suspend.c
tmk_core/common/arm_atsam/timer.c
tmk_core/common/avr/bootloader.c
tmk_core/common/avr/sleep_led.c
tmk_core/common/avr/suspend.c
tmk_core/common/avr/suspend_avr.h
tmk_core/common/avr/timer.c
tmk_core/common/avr/timer_avr.h
tmk_core/common/avr/xprintf.h
tmk_core/common/backlight.c
tmk_core/common/backlight.h
tmk_core/common/bootloader.h
tmk_core/common/bootmagic.c
tmk_core/common/bootmagic.h
tmk_core/common/chibios/bootloader.c
tmk_core/common/chibios/eeprom_stm32.c [changed mode: 0755->0644]
tmk_core/common/chibios/eeprom_stm32.h [changed mode: 0755->0644]
tmk_core/common/chibios/eeprom_teensy.c
tmk_core/common/chibios/flash_stm32.c [changed mode: 0755->0644]
tmk_core/common/chibios/flash_stm32.h [changed mode: 0755->0644]
tmk_core/common/chibios/printf.c
tmk_core/common/chibios/printf.h
tmk_core/common/chibios/sleep_led.c
tmk_core/common/chibios/suspend.c
tmk_core/common/chibios/timer.c
tmk_core/common/command.c
tmk_core/common/command.h
tmk_core/common/debug.c
tmk_core/common/debug.h
tmk_core/common/eeconfig.c
tmk_core/common/eeconfig.h
tmk_core/common/eeprom.h
tmk_core/common/host.c
tmk_core/common/host.h
tmk_core/common/host_driver.h
tmk_core/common/keyboard.c
tmk_core/common/keyboard.h
tmk_core/common/keycode.h
tmk_core/common/led.h
tmk_core/common/magic.c
tmk_core/common/matrix.h
tmk_core/common/mbed/bootloader.c
tmk_core/common/mbed/suspend.c
tmk_core/common/mbed/timer.c
tmk_core/common/mbed/xprintf.cpp
tmk_core/common/mbed/xprintf.h
tmk_core/common/mousekey.c
tmk_core/common/mousekey.h
tmk_core/common/nodebug.h
tmk_core/common/print.c
tmk_core/common/print.h
tmk_core/common/progmem.h
tmk_core/common/raw_hid.h
tmk_core/common/report.c
tmk_core/common/report.h
tmk_core/common/sendchar.h
tmk_core/common/sendchar_null.c
tmk_core/common/sendchar_uart.c
tmk_core/common/sleep_led.h
tmk_core/common/suspend.h
tmk_core/common/test/eeprom.c
tmk_core/common/test/suspend.c
tmk_core/common/test/timer.c
tmk_core/common/timer.h
tmk_core/common/uart.c
tmk_core/common/uart.h
tmk_core/common/util.c
tmk_core/common/util.h
tmk_core/common/wait.h
tmk_core/protocol/adb.c
tmk_core/protocol/adb.h
tmk_core/protocol/arm_atsam/adc.c
tmk_core/protocol/arm_atsam/adc.h
tmk_core/protocol/arm_atsam/arm_atsam_protocol.h
tmk_core/protocol/arm_atsam/clks.c
tmk_core/protocol/arm_atsam/clks.h
tmk_core/protocol/arm_atsam/d51_util.c
tmk_core/protocol/arm_atsam/d51_util.h
tmk_core/protocol/arm_atsam/i2c_master.c
tmk_core/protocol/arm_atsam/i2c_master.h
tmk_core/protocol/arm_atsam/issi3733_driver.h
tmk_core/protocol/arm_atsam/led_matrix.c
tmk_core/protocol/arm_atsam/led_matrix.h
tmk_core/protocol/arm_atsam/led_matrix_programs.c
tmk_core/protocol/arm_atsam/main_arm_atsam.c
tmk_core/protocol/arm_atsam/main_arm_atsam.h
tmk_core/protocol/arm_atsam/md_bootloader.h
tmk_core/protocol/arm_atsam/spi.c
tmk_core/protocol/arm_atsam/spi.h
tmk_core/protocol/arm_atsam/startup.c
tmk_core/protocol/arm_atsam/usb/compiler.h
tmk_core/protocol/arm_atsam/usb/conf_usb.h
tmk_core/protocol/arm_atsam/usb/main_usb.c
tmk_core/protocol/arm_atsam/usb/status_codes.h
tmk_core/protocol/arm_atsam/usb/udc.c
tmk_core/protocol/arm_atsam/usb/udc.h
tmk_core/protocol/arm_atsam/usb/udc_desc.h
tmk_core/protocol/arm_atsam/usb/udd.h
tmk_core/protocol/arm_atsam/usb/udi.h
tmk_core/protocol/arm_atsam/usb/udi_cdc.c
tmk_core/protocol/arm_atsam/usb/udi_cdc.h
tmk_core/protocol/arm_atsam/usb/udi_cdc_conf.h
tmk_core/protocol/arm_atsam/usb/udi_device_conf.h
tmk_core/protocol/arm_atsam/usb/udi_device_epsize.h
tmk_core/protocol/arm_atsam/usb/udi_hid.c
tmk_core/protocol/arm_atsam/usb/udi_hid.h
tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h
tmk_core/protocol/arm_atsam/usb/udi_hid_kbd_conf.h
tmk_core/protocol/arm_atsam/usb/udi_hid_kbd_desc.c
tmk_core/protocol/arm_atsam/usb/ui.c
tmk_core/protocol/arm_atsam/usb/ui.h
tmk_core/protocol/arm_atsam/usb/usb.c
tmk_core/protocol/arm_atsam/usb/usb.h
tmk_core/protocol/arm_atsam/usb/usb2422.c
tmk_core/protocol/arm_atsam/usb/usb2422.h
tmk_core/protocol/arm_atsam/usb/usb_atmel.h
tmk_core/protocol/arm_atsam/usb/usb_device_udd.c
tmk_core/protocol/arm_atsam/usb/usb_main.h
tmk_core/protocol/arm_atsam/usb/usb_protocol.h
tmk_core/protocol/arm_atsam/usb/usb_protocol_cdc.h
tmk_core/protocol/arm_atsam/usb/usb_protocol_hid.h
tmk_core/protocol/arm_atsam/usb/usb_util.c
tmk_core/protocol/arm_atsam/usb/usb_util.h
tmk_core/protocol/arm_atsam/wait_api.h
tmk_core/protocol/bluefruit/bluefruit.c
tmk_core/protocol/bluefruit/bluefruit.h
tmk_core/protocol/bluefruit/main.c
tmk_core/protocol/chibios/lufa_utils/LUFA/Drivers/USB/USB.h
tmk_core/protocol/chibios/main.c
tmk_core/protocol/chibios/usb_driver.c
tmk_core/protocol/chibios/usb_driver.h
tmk_core/protocol/chibios/usb_main.c
tmk_core/protocol/chibios/usb_main.h
tmk_core/protocol/ibm4704.c
tmk_core/protocol/ibm4704.h
tmk_core/protocol/iwrap/iwrap.c
tmk_core/protocol/iwrap/iwrap.h
tmk_core/protocol/iwrap/main.c
tmk_core/protocol/iwrap/suart.h
tmk_core/protocol/iwrap/wd.h
tmk_core/protocol/lufa/adafruit_ble.cpp
tmk_core/protocol/lufa/adafruit_ble.h
tmk_core/protocol/lufa/bluetooth.c
tmk_core/protocol/lufa/bluetooth.h
tmk_core/protocol/lufa/lufa.c
tmk_core/protocol/lufa/lufa.h
tmk_core/protocol/lufa/outputselect.c
tmk_core/protocol/lufa/outputselect.h
tmk_core/protocol/m0110.c
tmk_core/protocol/m0110.h
tmk_core/protocol/mbed/HIDKeyboard.cpp
tmk_core/protocol/mbed/HIDKeyboard.h
tmk_core/protocol/mbed/mbed_driver.cpp
tmk_core/protocol/midi/Config/LUFAConfig.h [changed mode: 0755->0644]
tmk_core/protocol/midi/bytequeue/bytequeue.c [changed mode: 0755->0644]
tmk_core/protocol/midi/bytequeue/bytequeue.h [changed mode: 0755->0644]
tmk_core/protocol/midi/bytequeue/interrupt_setting.c [changed mode: 0755->0644]
tmk_core/protocol/midi/bytequeue/interrupt_setting.h [changed mode: 0755->0644]
tmk_core/protocol/midi/midi.c [changed mode: 0755->0644]
tmk_core/protocol/midi/midi.h [changed mode: 0755->0644]
tmk_core/protocol/midi/midi_device.c [changed mode: 0755->0644]
tmk_core/protocol/midi/midi_device.h [changed mode: 0755->0644]
tmk_core/protocol/midi/midi_function_types.h [changed mode: 0755->0644]
tmk_core/protocol/midi/qmk_midi.c
tmk_core/protocol/midi/qmk_midi.h
tmk_core/protocol/midi/sysex_tools.c [changed mode: 0755->0644]
tmk_core/protocol/midi/sysex_tools.h [changed mode: 0755->0644]
tmk_core/protocol/news.c
tmk_core/protocol/news.h
tmk_core/protocol/next_kbd.c
tmk_core/protocol/next_kbd.h
tmk_core/protocol/pjrc/main.c
tmk_core/protocol/pjrc/pjrc.c
tmk_core/protocol/pjrc/pjrc.h
tmk_core/protocol/pjrc/usb.c
tmk_core/protocol/pjrc/usb.h
tmk_core/protocol/pjrc/usb_debug.c
tmk_core/protocol/pjrc/usb_debug.h
tmk_core/protocol/pjrc/usb_extra.c
tmk_core/protocol/pjrc/usb_extra.h
tmk_core/protocol/pjrc/usb_keyboard.c
tmk_core/protocol/pjrc/usb_keyboard.h
tmk_core/protocol/pjrc/usb_mouse.c
tmk_core/protocol/pjrc/usb_mouse.h
tmk_core/protocol/ps2.h
tmk_core/protocol/ps2_busywait.c
tmk_core/protocol/ps2_interrupt.c
tmk_core/protocol/ps2_io.h
tmk_core/protocol/ps2_io_avr.c
tmk_core/protocol/ps2_io_mbed.c
tmk_core/protocol/ps2_mouse.c
tmk_core/protocol/ps2_mouse.h
tmk_core/protocol/ps2_usart.c
tmk_core/protocol/serial.h
tmk_core/protocol/serial_mouse.h
tmk_core/protocol/serial_mouse_microsoft.c
tmk_core/protocol/serial_mouse_mousesystems.c
tmk_core/protocol/serial_soft.c
tmk_core/protocol/serial_uart.c
tmk_core/protocol/usb_descriptor.c
tmk_core/protocol/usb_descriptor.h
tmk_core/protocol/vusb/main.c
tmk_core/protocol/vusb/sendchar_usart.c
tmk_core/protocol/vusb/usbdrv/oddebug.c
tmk_core/protocol/vusb/usbdrv/oddebug.h
tmk_core/protocol/vusb/usbdrv/usbconfig-prototype.h
tmk_core/protocol/vusb/usbdrv/usbdrv.c
tmk_core/protocol/vusb/usbdrv/usbdrv.h
tmk_core/protocol/vusb/vusb.c
tmk_core/protocol/vusb/vusb.h
tmk_core/protocol/xt.h
tmk_core/protocol/xt_interrupt.c
tmk_core/ring_buffer.h

index cba5a1c679f3fa07f65ce3022d9db3714013b6df..18068d3a6dcd992254d0b57ee0086d8ed3473621 100644 (file)
@@ -34,98 +34,83 @@ static uint8_t i2c_address;
 
 static const I2CConfig i2cconfig = {
 #ifdef USE_I2CV1
-  I2C1_OPMODE,
-  I2C1_CLOCK_SPEED,
-  I2C1_DUTY_CYCLE,
+    I2C1_OPMODE,
+    I2C1_CLOCK_SPEED,
+    I2C1_DUTY_CYCLE,
 #else
-  STM32_TIMINGR_PRESC(I2C1_TIMINGR_PRESC) |
-  STM32_TIMINGR_SCLDEL(I2C1_TIMINGR_SCLDEL) | STM32_TIMINGR_SDADEL(I2C1_TIMINGR_SDADEL) |
-  STM32_TIMINGR_SCLH(I2C1_TIMINGR_SCLH)  | STM32_TIMINGR_SCLL(I2C1_TIMINGR_SCLL),
-  0,
-  0
+    STM32_TIMINGR_PRESC(I2C1_TIMINGR_PRESC) | STM32_TIMINGR_SCLDEL(I2C1_TIMINGR_SCLDEL) | STM32_TIMINGR_SDADEL(I2C1_TIMINGR_SDADEL) | STM32_TIMINGR_SCLH(I2C1_TIMINGR_SCLH) | STM32_TIMINGR_SCLL(I2C1_TIMINGR_SCLL), 0, 0
 #endif
 };
 
 static i2c_status_t chibios_to_qmk(const msg_t* status) {
-  switch (*status) {
-    case I2C_NO_ERROR:
-      return I2C_STATUS_SUCCESS;
-    case I2C_TIMEOUT:
-      return I2C_STATUS_TIMEOUT;
-    // I2C_BUS_ERROR, I2C_ARBITRATION_LOST, I2C_ACK_FAILURE, I2C_OVERRUN, I2C_PEC_ERROR, I2C_SMB_ALERT
-    default:
-      return I2C_STATUS_ERROR;
-  }
+    switch (*status) {
+        case I2C_NO_ERROR:
+            return I2C_STATUS_SUCCESS;
+        case I2C_TIMEOUT:
+            return I2C_STATUS_TIMEOUT;
+        // I2C_BUS_ERROR, I2C_ARBITRATION_LOST, I2C_ACK_FAILURE, I2C_OVERRUN, I2C_PEC_ERROR, I2C_SMB_ALERT
+        default:
+            return I2C_STATUS_ERROR;
+    }
 }
 
-__attribute__ ((weak))
-void i2c_init(void)
-{
-  // Try releasing special pins for a short time
-  palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT);
-  palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT);
+__attribute__((weak)) void i2c_init(void) {
+    // Try releasing special pins for a short time
+    palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT);
+    palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT);
 
-  chThdSleepMilliseconds(10);
+    chThdSleepMilliseconds(10);
 
 #ifdef USE_I2CV1
-  palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
-  palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
+    palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
+    palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
 #else
-  palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
-  palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
+    palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
+    palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
 #endif
 
-  //i2cInit(); //This is invoked by halInit() so no need to redo it.
+    // i2cInit(); //This is invoked by halInit() so no need to redo it.
 }
 
-i2c_status_t i2c_start(uint8_t address)
-{
-  i2c_address = address;
-  i2cStart(&I2C_DRIVER, &i2cconfig);
-  return I2C_STATUS_SUCCESS;
+i2c_status_t i2c_start(uint8_t address) {
+    i2c_address = address;
+    i2cStart(&I2C_DRIVER, &i2cconfig);
+    return I2C_STATUS_SUCCESS;
 }
 
-i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout)
-{
-  i2c_address = address;
-  i2cStart(&I2C_DRIVER, &i2cconfig);
-  msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, 0, 0, MS2ST(timeout));
-  return chibios_to_qmk(&status);
+i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout) {
+    i2c_address = address;
+    i2cStart(&I2C_DRIVER, &i2cconfig);
+    msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, 0, 0, MS2ST(timeout));
+    return chibios_to_qmk(&status);
 }
 
-i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout)
-{
-  i2c_address = address;
-  i2cStart(&I2C_DRIVER, &i2cconfig);
-  msg_t status = i2cMasterReceiveTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, MS2ST(timeout));
-  return chibios_to_qmk(&status);
+i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout) {
+    i2c_address = address;
+    i2cStart(&I2C_DRIVER, &i2cconfig);
+    msg_t status = i2cMasterReceiveTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, MS2ST(timeout));
+    return chibios_to_qmk(&status);
 }
 
-i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout)
-{
-  i2c_address = devaddr;
-  i2cStart(&I2C_DRIVER, &i2cconfig);
+i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
+    i2c_address = devaddr;
+    i2cStart(&I2C_DRIVER, &i2cconfig);
 
-  uint8_t complete_packet[length + 1];
-  for(uint8_t i = 0; i < length; i++)
-  {
-    complete_packet[i+1] = data[i];
-  }
-  complete_packet[0] = regaddr;
+    uint8_t complete_packet[length + 1];
+    for (uint8_t i = 0; i < length; i++) {
+        complete_packet[i + 1] = data[i];
+    }
+    complete_packet[0] = regaddr;
 
-  msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), complete_packet, length + 1, 0, 0, MS2ST(timeout));
-  return chibios_to_qmk(&status);
+    msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), complete_packet, length + 1, 0, 0, MS2ST(timeout));
+    return chibios_to_qmk(&status);
 }
 
-i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)
-{
-  i2c_address = devaddr;
-  i2cStart(&I2C_DRIVER, &i2cconfig);
-  msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), &regaddr, 1, data, length, MS2ST(timeout));
-  return chibios_to_qmk(&status);
+i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
+    i2c_address = devaddr;
+    i2cStart(&I2C_DRIVER, &i2cconfig);
+    msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), &regaddr, 1, data, length, MS2ST(timeout));
+    return chibios_to_qmk(&status);
 }
 
-void i2c_stop(void)
-{
-  i2cStop(&I2C_DRIVER);
-}
+void i2c_stop(void) { i2cStop(&I2C_DRIVER); }
index c8afa31e28d67e76cbe1a8700c5c684de8281544..b40fa0a9102614bdbb739d8f608915acec71d315 100644 (file)
 #include "ch.h"
 #include <hal.h>
 
-
 #if defined(STM32F1XX) || defined(STM32F1xx) || defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32L0xx) || defined(STM32L1xx)
-    #define USE_I2CV1
+#    define USE_I2CV1
 #endif
 
 #ifdef I2C1_BANK
-    #define I2C1_SCL_BANK I2C1_BANK
-    #define I2C1_SDA_BANK I2C1_BANK
+#    define I2C1_SCL_BANK I2C1_BANK
+#    define I2C1_SDA_BANK I2C1_BANK
 #endif
 
 #ifndef I2C1_SCL_BANK
-    #define I2C1_SCL_BANK GPIOB
+#    define I2C1_SCL_BANK GPIOB
 #endif
 
 #ifndef I2C1_SDA_BANK
-    #define I2C1_SDA_BANK GPIOB
+#    define I2C1_SDA_BANK GPIOB
 #endif
 
 #ifndef I2C1_SCL
-    #define I2C1_SCL 6
+#    define I2C1_SCL 6
 #endif
 #ifndef I2C1_SDA
-    #define I2C1_SDA 7
+#    define I2C1_SDA 7
 #endif
 
 #ifdef USE_I2CV1
-    #ifndef I2C1_OPMODE
-        #define I2C1_OPMODE OPMODE_I2C
-    #endif
-    #ifndef I2C1_CLOCK_SPEED
-        #define I2C1_CLOCK_SPEED 100000 /* 400000 */
-    #endif
-    #ifndef I2C1_DUTY_CYCLE
-        #define I2C1_DUTY_CYCLE STD_DUTY_CYCLE /* FAST_DUTY_CYCLE_2 */
-    #endif
+#    ifndef I2C1_OPMODE
+#        define I2C1_OPMODE OPMODE_I2C
+#    endif
+#    ifndef I2C1_CLOCK_SPEED
+#        define I2C1_CLOCK_SPEED 100000 /* 400000 */
+#    endif
+#    ifndef I2C1_DUTY_CYCLE
+#        define I2C1_DUTY_CYCLE STD_DUTY_CYCLE /* FAST_DUTY_CYCLE_2 */
+#    endif
 #else
-    // The default PAL alternate modes are used to signal that the pins are used for I2C
-    #ifndef I2C1_SCL_PAL_MODE
-        #define I2C1_SCL_PAL_MODE 4
-    #endif
-    #ifndef I2C1_SDA_PAL_MODE
-        #define I2C1_SDA_PAL_MODE 4
-    #endif
+// The default PAL alternate modes are used to signal that the pins are used for I2C
+#    ifndef I2C1_SCL_PAL_MODE
+#        define I2C1_SCL_PAL_MODE 4
+#    endif
+#    ifndef I2C1_SDA_PAL_MODE
+#        define I2C1_SDA_PAL_MODE 4
+#    endif
 
-    // The default timing values below configures the I2C clock to 400khz assuming a 72Mhz clock
-    // For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html
-    #ifndef I2C1_TIMINGR_PRESC
-        #define I2C1_TIMINGR_PRESC 15U
-    #endif
-    #ifndef I2C1_TIMINGR_SCLDEL
-        #define I2C1_TIMINGR_SCLDEL 4U
-    #endif
-    #ifndef I2C1_TIMINGR_SDADEL
-        #define I2C1_TIMINGR_SDADEL 2U
-    #endif
-    #ifndef I2C1_TIMINGR_SCLH
-        #define I2C1_TIMINGR_SCLH 15U
-    #endif
-    #ifndef I2C1_TIMINGR_SCLL
-        #define I2C1_TIMINGR_SCLL 21U
-    #endif
+// The default timing values below configures the I2C clock to 400khz assuming a 72Mhz clock
+// For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html
+#    ifndef I2C1_TIMINGR_PRESC
+#        define I2C1_TIMINGR_PRESC 15U
+#    endif
+#    ifndef I2C1_TIMINGR_SCLDEL
+#        define I2C1_TIMINGR_SCLDEL 4U
+#    endif
+#    ifndef I2C1_TIMINGR_SDADEL
+#        define I2C1_TIMINGR_SDADEL 2U
+#    endif
+#    ifndef I2C1_TIMINGR_SCLH
+#        define I2C1_TIMINGR_SCLH 15U
+#    endif
+#    ifndef I2C1_TIMINGR_SCLL
+#        define I2C1_TIMINGR_SCLL 21U
+#    endif
 #endif
 
 #ifndef I2C_DRIVER
-  #define I2C_DRIVER I2CD1
+#    define I2C_DRIVER I2CD1
 #endif
 
 typedef int16_t i2c_status_t;
 
 #define I2C_STATUS_SUCCESS (0)
-#define I2C_STATUS_ERROR   (-1)
+#define I2C_STATUS_ERROR (-1)
 #define I2C_STATUS_TIMEOUT (-2)
 
-void i2c_init(void);
+void         i2c_init(void);
 i2c_status_t i2c_start(uint8_t address);
 i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout);
 i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
-i2c_status_t i2c_transmit_receive(uint8_t address, uint8_t * tx_body, uint16_t tx_length, uint8_t * rx_body, uint16_t rx_length);
+i2c_status_t i2c_transmit_receive(uint8_t address, uint8_t* tx_body, uint16_t tx_length, uint8_t* rx_body, uint16_t rx_length);
 i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
 i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
-void i2c_stop(void);
+void         i2c_stop(void);
index 1ec38df75df6080d70e00a622d67300c6c06b801..1a8da4261dfe3286c9dd7fc4378a0869f0b45ecf 100644 (file)
 #include <stdint.h>
 #include "analog.h"
 
+static uint8_t aref = (1 << REFS0);  // default to AREF = Vcc
 
-static uint8_t aref = (1<<REFS0); // default to AREF = Vcc
-
-
-void analogReference(uint8_t mode)
-{
-       aref = mode & 0xC0;
-}
-
+void analogReference(uint8_t mode) { aref = mode & 0xC0; }
 
 // Arduino compatible pin input
-int16_t analogRead(uint8_t pin)
-{
+int16_t analogRead(uint8_t pin) {
 #if defined(__AVR_ATmega32U4__)
-       static const uint8_t PROGMEM pin_to_mux[] = {
-               0x00, 0x01, 0x04, 0x05, 0x06, 0x07,
-               0x25, 0x24, 0x23, 0x22, 0x21, 0x20};
-       if (pin >= 12) return 0;
-       return adc_read(pgm_read_byte(pin_to_mux + pin));
+    static const uint8_t PROGMEM pin_to_mux[] = {0x00, 0x01, 0x04, 0x05, 0x06, 0x07, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20};
+    if (pin >= 12) return 0;
+    return adc_read(pgm_read_byte(pin_to_mux + pin));
 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
-       if (pin >= 8) return 0;
-       return adc_read(pin);
+    if (pin >= 8) return 0;
+    return adc_read(pin);
 #else
-       return 0;
+    return 0;
 #endif
 }
 
 // Mux input
-int16_t adc_read(uint8_t mux)
-{
+int16_t adc_read(uint8_t mux) {
 #if defined(__AVR_AT90USB162__)
-       return 0;
+    return 0;
 #else
-       uint8_t low;
-
-       ADCSRA = (1<<ADEN) | ADC_PRESCALER;             // enable ADC
-       ADCSRB = (1<<ADHSM) | (mux & 0x20);             // high speed mode
-       ADMUX = aref | (mux & 0x1F);                    // configure mux input
-       ADCSRA = (1<<ADEN) | ADC_PRESCALER | (1<<ADSC); // start the conversion
-       while (ADCSRA & (1<<ADSC)) ;                    // wait for result
-       low = ADCL;                                     // must read LSB first
-       return (ADCH << 8) | low;                       // must read MSB only once!
+    uint8_t low;
+
+    ADCSRA = (1 << ADEN) | ADC_PRESCALER;                // enable ADC
+    ADCSRB = (1 << ADHSM) | (mux & 0x20);                // high speed mode
+    ADMUX  = aref | (mux & 0x1F);                        // configure mux input
+    ADCSRA = (1 << ADEN) | ADC_PRESCALER | (1 << ADSC);  // start the conversion
+    while (ADCSRA & (1 << ADSC))
+        ;                      // wait for result
+    low = ADCL;                // must read LSB first
+    return (ADCH << 8) | low;  // must read MSB only once!
 #endif
 }
-
-
index 8d93de7dc27f983e1d55620bf3ead95858586aa4..32452a1ec210c14a4daa9b6b865dfe4714480ef2 100644 (file)
 
 #include <stdint.h>
 
-void analogReference(uint8_t mode);
+void    analogReference(uint8_t mode);
 int16_t analogRead(uint8_t pin);
 int16_t adc_read(uint8_t mux);
 
-#define ADC_REF_POWER     (1<<REFS0)
-#define ADC_REF_INTERNAL  ((1<<REFS1) | (1<<REFS0))
-#define ADC_REF_EXTERNAL  (0)
+#define ADC_REF_POWER (1 << REFS0)
+#define ADC_REF_INTERNAL ((1 << REFS1) | (1 << REFS0))
+#define ADC_REF_EXTERNAL (0)
 
 // These prescaler values are for high speed mode, ADHSM = 1
 #if F_CPU == 16000000L
-#define ADC_PRESCALER ((1<<ADPS2) | (1<<ADPS1))
+#    define ADC_PRESCALER ((1 << ADPS2) | (1 << ADPS1))
 #elif F_CPU == 8000000L
-#define ADC_PRESCALER ((1<<ADPS2) | (1<<ADPS0))
+#    define ADC_PRESCALER ((1 << ADPS2) | (1 << ADPS0))
 #elif F_CPU == 4000000L
-#define ADC_PRESCALER ((1<<ADPS2))
+#    define ADC_PRESCALER ((1 << ADPS2))
 #elif F_CPU == 2000000L
-#define ADC_PRESCALER ((1<<ADPS1) | (1<<ADPS0))
+#    define ADC_PRESCALER ((1 << ADPS1) | (1 << ADPS0))
 #elif F_CPU == 1000000L
-#define ADC_PRESCALER ((1<<ADPS1))
+#    define ADC_PRESCALER ((1 << ADPS1))
 #else
-#define ADC_PRESCALER ((1<<ADPS0))
+#    define ADC_PRESCALER ((1 << ADPS0))
 #endif
 
 // some avr-libc versions do not properly define ADHSM
 #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
-#if !defined(ADHSM)
-#define ADHSM (7)
-#endif
+#    if !defined(ADHSM)
+#        define ADHSM (7)
+#    endif
 #endif
 
 #endif
old mode 100755 (executable)
new mode 100644 (file)
index 55a0d57..f4d97a1
@@ -1,24 +1,24 @@
 /*
-* APA102 lib V1.0a
-*
-* Controls APA102 RGB-LEDs
-* Author: Mikkel (Duckle29 on github)
-*
-* Dec 22th, 2017  v1.0a Initial Version
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+ * APA102 lib V1.0a
+ *
+ * Controls APA102 RGB-LEDs
+ * Author: Mikkel (Duckle29 on github)
+ *
+ * Dec 22th, 2017  v1.0a Initial Version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 
 #include "apa102.h"
 #include <avr/interrupt.h>
 #include "debug.h"
 
 // Setleds for standard RGB
-void inline apa102_setleds(LED_TYPE *ledarray, uint16_t leds){
-  apa102_setleds_pin(ledarray,leds, _BV(RGB_DI_PIN & 0xF), _BV(RGB_CLK_PIN & 0xF));
-}
+void inline apa102_setleds(LED_TYPE *ledarray, uint16_t leds) { apa102_setleds_pin(ledarray, leds, _BV(RGB_DI_PIN & 0xF), _BV(RGB_CLK_PIN & 0xF)); }
 
-void static inline apa102_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask_DI, uint8_t pinmask_CLK){
-  pinMode(RGB_DI_PIN, PinDirectionOutput);
-  pinMode(RGB_CLK_PIN, PinDirectionOutput);
+void static inline apa102_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask_DI, uint8_t pinmask_CLK) {
+    pinMode(RGB_DI_PIN, PinDirectionOutput);
+    pinMode(RGB_CLK_PIN, PinDirectionOutput);
 
-  apa102_send_array((uint8_t*)ledarray,leds)
+    apa102_send_array((uint8_t *)ledarray, leds)
 }
 
-void apa102_send_array(uint8_t *data, uint16_t leds){ // Data is struct of 3 bytes. RGB - leds is number of leds in data
-  apa102_start_frame();
-  while(leds--){
-    apa102_send_frame(0xFF000000 | (data->b << 16) | (data->g << 8) | data->r);
-    data++;
-  }
-  apa102_end_frame(leds);
+void apa102_send_array(uint8_t *data, uint16_t leds) {  // Data is struct of 3 bytes. RGB - leds is number of leds in data
+    apa102_start_frame();
+    while (leds--) {
+        apa102_send_frame(0xFF000000 | (data->b << 16) | (data->g << 8) | data->r);
+        data++;
+    }
+    apa102_end_frame(leds);
 }
 
-void apa102_send_frame(uint32_t frame){
-  for(uint32_t i=0xFF; i>0;){
-    apa102_send_byte(frame & i);
-    i = i << 8;
-  }
+void apa102_send_frame(uint32_t frame) {
+    for (uint32_t i = 0xFF; i > 0;) {
+        apa102_send_byte(frame & i);
+        i = i << 8;
+    }
 }
 
-void apa102_start_frame(){
-  apa102_send_frame(0);
-}
+void apa102_start_frame() { apa102_send_frame(0); }
 
-void apa102_end_frame(uint16_t leds)
-{
-  // This function has been taken from: https://github.com/pololu/apa102-arduino/blob/master/APA102.h
-  // and adapted. The code is MIT licensed. I think thats compatible?
+void apa102_end_frame(uint16_t leds) {
+    // This function has been taken from: https://github.com/pololu/apa102-arduino/blob/master/APA102.h
+    // and adapted. The code is MIT licensed. I think thats compatible?
 
-  // We need to send some more bytes to ensure that all the LEDs in the
-  // chain see their new color and start displaying it.
-  //
-  // The data stream seen by the last LED in the chain will be delayed by
-  // (count - 1) clock edges, because each LED before it inverts the clock
-  // line and delays the data by one clock edge.  Therefore, to make sure
-  // the last LED actually receives the data we wrote, the number of extra
-  // edges we send at the end of the frame must be at least (count - 1).
-  // For the APA102C, that is sufficient.
-  //
-  // The SK9822 only updates after it sees 32 zero bits followed by one more
-  // rising edge.  To avoid having the update time depend on the color of
-  // the last LED, we send a dummy 0xFF byte.  (Unfortunately, this means
-  // that partial updates of the beginning of an LED strip are not possible;
-  // the LED after the last one you are trying to update will be black.)
-  // After that, to ensure that the last LED in the chain sees 32 zero bits
-  // and a rising edge, we need to send at least 65 + (count - 1) edges.  It
-  // is sufficent and simpler to just send (5 + count/16) bytes of zeros.
-  //
-  // We are ignoring the specification for the end frame in the APA102/SK9822
-  // datasheets because it does not actually ensure that all the LEDs will
-  // start displaying their new colors right away.
+    // We need to send some more bytes to ensure that all the LEDs in the
+    // chain see their new color and start displaying it.
+    //
+    // The data stream seen by the last LED in the chain will be delayed by
+    // (count - 1) clock edges, because each LED before it inverts the clock
+    // line and delays the data by one clock edge.  Therefore, to make sure
+    // the last LED actually receives the data we wrote, the number of extra
+    // edges we send at the end of the frame must be at least (count - 1).
+    // For the APA102C, that is sufficient.
+    //
+    // The SK9822 only updates after it sees 32 zero bits followed by one more
+    // rising edge.  To avoid having the update time depend on the color of
+    // the last LED, we send a dummy 0xFF byte.  (Unfortunately, this means
+    // that partial updates of the beginning of an LED strip are not possible;
+    // the LED after the last one you are trying to update will be black.)
+    // After that, to ensure that the last LED in the chain sees 32 zero bits
+    // and a rising edge, we need to send at least 65 + (count - 1) edges.  It
+    // is sufficent and simpler to just send (5 + count/16) bytes of zeros.
+    //
+    // We are ignoring the specification for the end frame in the APA102/SK9822
+    // datasheets because it does not actually ensure that all the LEDs will
+    // start displaying their new colors right away.
 
-  apa102_send_byte(0xFF);
-  for (uint16_t i = 0; i < 5 + leds / 16; i++){
-    apa102_send_byte(0);
-  }
+    apa102_send_byte(0xFF);
+    for (uint16_t i = 0; i < 5 + leds / 16; i++) {
+        apa102_send_byte(0);
+    }
 }
 
-void apa102_send_byte(uint8_t byte){
-  uint8_t i;
-  for (i = 0; i < 8; i++){
+void apa102_send_byte(uint8_t byte) {
+    uint8_t i;
+    for (i = 0; i < 8; i++) {
     digitalWrite(RGB_DI_PIN, !!(byte & (1 << (7-i)));
     digitalWrite(RGB_CLK_PIN, PinLevelHigh);
-  }
+    }
 }
old mode 100755 (executable)
new mode 100644 (file)
index 5d852e0..d4c1e18
@@ -27,7 +27,6 @@
 
 #include "color.h"
 
-
 /* User Interface
  *
  * Input:
@@ -41,6 +40,6 @@
  *         - Wait 50�s to reset the LEDs
  */
 
-void apa102_setleds     (LED_TYPE *ledarray, uint16_t number_of_leds);
-void apa102_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask);
+void apa102_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
+void apa102_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask);
 void apa102_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
index 6f88bd23a781d6376abbd2815dea9dcbc2508ae9..2c332ea6db41919a8538e7fa7137989b398ad3bd 100644 (file)
 #define FONT5X7_H
 
 #ifdef __AVR__
- #include <avr/io.h>
- #include <avr/pgmspace.h>
+#    include <avr/io.h>
+#    include <avr/pgmspace.h>
 #elif defined(ESP8266)
- #include <pgmspace.h>
+#    include <pgmspace.h>
 #else
- #define PROGMEM
+#    define PROGMEM
 #endif
 
 // Standard ASCII 5x7 font
 
 static const unsigned char font[] PROGMEM = {
-       0x00, 0x00, 0x00, 0x00, 0x00,
-       0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
-       0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
-       0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
-       0x18, 0x3C, 0x7E, 0x3C, 0x18,
-       0x1C, 0x57, 0x7D, 0x57, 0x1C,
-       0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
-       0x00, 0x18, 0x3C, 0x18, 0x00,
-       0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
-       0x00, 0x18, 0x24, 0x18, 0x00,
-       0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
-       0x30, 0x48, 0x3A, 0x06, 0x0E,
-       0x26, 0x29, 0x79, 0x29, 0x26,
-       0x40, 0x7F, 0x05, 0x05, 0x07,
-       0x40, 0x7F, 0x05, 0x25, 0x3F,
-       0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
-       0x7F, 0x3E, 0x1C, 0x1C, 0x08,
-       0x08, 0x1C, 0x1C, 0x3E, 0x7F,
-       0x14, 0x22, 0x7F, 0x22, 0x14,
-       0x5F, 0x5F, 0x00, 0x5F, 0x5F,
-       0x06, 0x09, 0x7F, 0x01, 0x7F,
-       0x00, 0x66, 0x89, 0x95, 0x6A,
-       0x60, 0x60, 0x60, 0x60, 0x60,
-       0x94, 0xA2, 0xFF, 0xA2, 0x94,
-       0x08, 0x04, 0x7E, 0x04, 0x08,
-       0x10, 0x20, 0x7E, 0x20, 0x10,
-       0x08, 0x08, 0x2A, 0x1C, 0x08,
-       0x08, 0x1C, 0x2A, 0x08, 0x08,
-       0x1E, 0x10, 0x10, 0x10, 0x10,
-       0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
-       0x30, 0x38, 0x3E, 0x38, 0x30,
-       0x06, 0x0E, 0x3E, 0x0E, 0x06,
-       0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x5F, 0x00, 0x00,
-       0x00, 0x07, 0x00, 0x07, 0x00,
-       0x14, 0x7F, 0x14, 0x7F, 0x14,
-       0x24, 0x2A, 0x7F, 0x2A, 0x12,
-       0x23, 0x13, 0x08, 0x64, 0x62,
-       0x36, 0x49, 0x56, 0x20, 0x50,
-       0x00, 0x08, 0x07, 0x03, 0x00,
-       0x00, 0x1C, 0x22, 0x41, 0x00,
-       0x00, 0x41, 0x22, 0x1C, 0x00,
-       0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
-       0x08, 0x08, 0x3E, 0x08, 0x08,
-       0x00, 0x80, 0x70, 0x30, 0x00,
-       0x08, 0x08, 0x08, 0x08, 0x08,
-       0x00, 0x00, 0x60, 0x60, 0x00,
-       0x20, 0x10, 0x08, 0x04, 0x02,
-       0x3E, 0x51, 0x49, 0x45, 0x3E,
-       0x00, 0x42, 0x7F, 0x40, 0x00,
-       0x72, 0x49, 0x49, 0x49, 0x46,
-       0x21, 0x41, 0x49, 0x4D, 0x33,
-       0x18, 0x14, 0x12, 0x7F, 0x10,
-       0x27, 0x45, 0x45, 0x45, 0x39,
-       0x3C, 0x4A, 0x49, 0x49, 0x31,
-       0x41, 0x21, 0x11, 0x09, 0x07,
-       0x36, 0x49, 0x49, 0x49, 0x36,
-       0x46, 0x49, 0x49, 0x29, 0x1E,
-       0x00, 0x00, 0x14, 0x00, 0x00,
-       0x00, 0x40, 0x34, 0x00, 0x00,
-       0x00, 0x08, 0x14, 0x22, 0x41,
-       0x14, 0x14, 0x14, 0x14, 0x14,
-       0x00, 0x41, 0x22, 0x14, 0x08,
-       0x02, 0x01, 0x59, 0x09, 0x06,
-       0x3E, 0x41, 0x5D, 0x59, 0x4E,
-       0x7C, 0x12, 0x11, 0x12, 0x7C,
-       0x7F, 0x49, 0x49, 0x49, 0x36,
-       0x3E, 0x41, 0x41, 0x41, 0x22,
-       0x7F, 0x41, 0x41, 0x41, 0x3E,
-       0x7F, 0x49, 0x49, 0x49, 0x41,
-       0x7F, 0x09, 0x09, 0x09, 0x01,
-       0x3E, 0x41, 0x41, 0x51, 0x73,
-       0x7F, 0x08, 0x08, 0x08, 0x7F,
-       0x00, 0x41, 0x7F, 0x41, 0x00,
-       0x20, 0x40, 0x41, 0x3F, 0x01,
-       0x7F, 0x08, 0x14, 0x22, 0x41,
-       0x7F, 0x40, 0x40, 0x40, 0x40,
-       0x7F, 0x02, 0x1C, 0x02, 0x7F,
-       0x7F, 0x04, 0x08, 0x10, 0x7F,
-       0x3E, 0x41, 0x41, 0x41, 0x3E,
-       0x7F, 0x09, 0x09, 0x09, 0x06,
-       0x3E, 0x41, 0x51, 0x21, 0x5E,
-       0x7F, 0x09, 0x19, 0x29, 0x46,
-       0x26, 0x49, 0x49, 0x49, 0x32,
-       0x03, 0x01, 0x7F, 0x01, 0x03,
-       0x3F, 0x40, 0x40, 0x40, 0x3F,
-       0x1F, 0x20, 0x40, 0x20, 0x1F,
-       0x3F, 0x40, 0x38, 0x40, 0x3F,
-       0x63, 0x14, 0x08, 0x14, 0x63,
-       0x03, 0x04, 0x78, 0x04, 0x03,
-       0x61, 0x59, 0x49, 0x4D, 0x43,
-       0x00, 0x7F, 0x41, 0x41, 0x41,
-       0x02, 0x04, 0x08, 0x10, 0x20,
-       0x00, 0x41, 0x41, 0x41, 0x7F,
-       0x04, 0x02, 0x01, 0x02, 0x04,
-       0x40, 0x40, 0x40, 0x40, 0x40,
-       0x00, 0x03, 0x07, 0x08, 0x00,
-       0x20, 0x54, 0x54, 0x78, 0x40,
-       0x7F, 0x28, 0x44, 0x44, 0x38,
-       0x38, 0x44, 0x44, 0x44, 0x28,
-       0x38, 0x44, 0x44, 0x28, 0x7F,
-       0x38, 0x54, 0x54, 0x54, 0x18,
-       0x00, 0x08, 0x7E, 0x09, 0x02,
-       0x18, 0xA4, 0xA4, 0x9C, 0x78,
-       0x7F, 0x08, 0x04, 0x04, 0x78,
-       0x00, 0x44, 0x7D, 0x40, 0x00,
-       0x20, 0x40, 0x40, 0x3D, 0x00,
-       0x7F, 0x10, 0x28, 0x44, 0x00,
-       0x00, 0x41, 0x7F, 0x40, 0x00,
-       0x7C, 0x04, 0x78, 0x04, 0x78,
-       0x7C, 0x08, 0x04, 0x04, 0x78,
-       0x38, 0x44, 0x44, 0x44, 0x38,
-       0xFC, 0x18, 0x24, 0x24, 0x18,
-       0x18, 0x24, 0x24, 0x18, 0xFC,
-       0x7C, 0x08, 0x04, 0x04, 0x08,
-       0x48, 0x54, 0x54, 0x54, 0x24,
-       0x04, 0x04, 0x3F, 0x44, 0x24,
-       0x3C, 0x40, 0x40, 0x20, 0x7C,
-       0x1C, 0x20, 0x40, 0x20, 0x1C,
-       0x3C, 0x40, 0x30, 0x40, 0x3C,
-       0x44, 0x28, 0x10, 0x28, 0x44,
-       0x4C, 0x90, 0x90, 0x90, 0x7C,
-       0x44, 0x64, 0x54, 0x4C, 0x44,
-       0x00, 0x08, 0x36, 0x41, 0x00,
-       0x00, 0x00, 0x77, 0x00, 0x00,
-       0x00, 0x41, 0x36, 0x08, 0x00,
-       0x02, 0x01, 0x02, 0x04, 0x02,
-       0x3C, 0x26, 0x23, 0x26, 0x3C,
-       0x1E, 0xA1, 0xA1, 0x61, 0x12,
-       0x3A, 0x40, 0x40, 0x20, 0x7A,
-       0x38, 0x54, 0x54, 0x55, 0x59,
-       0x21, 0x55, 0x55, 0x79, 0x41,
-       0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
-       0x21, 0x55, 0x54, 0x78, 0x40,
-       0x20, 0x54, 0x55, 0x79, 0x40,
-       0x0C, 0x1E, 0x52, 0x72, 0x12,
-       0x39, 0x55, 0x55, 0x55, 0x59,
-       0x39, 0x54, 0x54, 0x54, 0x59,
-       0x39, 0x55, 0x54, 0x54, 0x58,
-       0x00, 0x00, 0x45, 0x7C, 0x41,
-       0x00, 0x02, 0x45, 0x7D, 0x42,
-       0x00, 0x01, 0x45, 0x7C, 0x40,
-       0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
-       0xF0, 0x28, 0x25, 0x28, 0xF0,
-       0x7C, 0x54, 0x55, 0x45, 0x00,
-       0x20, 0x54, 0x54, 0x7C, 0x54,
-       0x7C, 0x0A, 0x09, 0x7F, 0x49,
-       0x32, 0x49, 0x49, 0x49, 0x32,
-       0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
-       0x32, 0x4A, 0x48, 0x48, 0x30,
-       0x3A, 0x41, 0x41, 0x21, 0x7A,
-       0x3A, 0x42, 0x40, 0x20, 0x78,
-       0x00, 0x9D, 0xA0, 0xA0, 0x7D,
-       0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
-       0x3D, 0x40, 0x40, 0x40, 0x3D,
-       0x3C, 0x24, 0xFF, 0x24, 0x24,
-       0x48, 0x7E, 0x49, 0x43, 0x66,
-       0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
-       0xFF, 0x09, 0x29, 0xF6, 0x20,
-       0xC0, 0x88, 0x7E, 0x09, 0x03,
-       0x20, 0x54, 0x54, 0x79, 0x41,
-       0x00, 0x00, 0x44, 0x7D, 0x41,
-       0x30, 0x48, 0x48, 0x4A, 0x32,
-       0x38, 0x40, 0x40, 0x22, 0x7A,
-       0x00, 0x7A, 0x0A, 0x0A, 0x72,
-       0x7D, 0x0D, 0x19, 0x31, 0x7D,
-       0x26, 0x29, 0x29, 0x2F, 0x28,
-       0x26, 0x29, 0x29, 0x29, 0x26,
-       0x30, 0x48, 0x4D, 0x40, 0x20,
-       0x38, 0x08, 0x08, 0x08, 0x08,
-       0x08, 0x08, 0x08, 0x08, 0x38,
-       0x2F, 0x10, 0xC8, 0xAC, 0xBA,
-       0x2F, 0x10, 0x28, 0x34, 0xFA,
-       0x00, 0x00, 0x7B, 0x00, 0x00,
-       0x08, 0x14, 0x2A, 0x14, 0x22,
-       0x22, 0x14, 0x2A, 0x14, 0x08,
-       0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
-       0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
-       0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
-       0x00, 0x00, 0x00, 0xFF, 0x00,
-       0x10, 0x10, 0x10, 0xFF, 0x00,
-       0x14, 0x14, 0x14, 0xFF, 0x00,
-       0x10, 0x10, 0xFF, 0x00, 0xFF,
-       0x10, 0x10, 0xF0, 0x10, 0xF0,
-       0x14, 0x14, 0x14, 0xFC, 0x00,
-       0x14, 0x14, 0xF7, 0x00, 0xFF,
-       0x00, 0x00, 0xFF, 0x00, 0xFF,
-       0x14, 0x14, 0xF4, 0x04, 0xFC,
-       0x14, 0x14, 0x17, 0x10, 0x1F,
-       0x10, 0x10, 0x1F, 0x10, 0x1F,
-       0x14, 0x14, 0x14, 0x1F, 0x00,
-       0x10, 0x10, 0x10, 0xF0, 0x00,
-       0x00, 0x00, 0x00, 0x1F, 0x10,
-       0x10, 0x10, 0x10, 0x1F, 0x10,
-       0x10, 0x10, 0x10, 0xF0, 0x10,
-       0x00, 0x00, 0x00, 0xFF, 0x10,
-       0x10, 0x10, 0x10, 0x10, 0x10,
-       0x10, 0x10, 0x10, 0xFF, 0x10,
-       0x00, 0x00, 0x00, 0xFF, 0x14,
-       0x00, 0x00, 0xFF, 0x00, 0xFF,
-       0x00, 0x00, 0x1F, 0x10, 0x17,
-       0x00, 0x00, 0xFC, 0x04, 0xF4,
-       0x14, 0x14, 0x17, 0x10, 0x17,
-       0x14, 0x14, 0xF4, 0x04, 0xF4,
-       0x00, 0x00, 0xFF, 0x00, 0xF7,
-       0x14, 0x14, 0x14, 0x14, 0x14,
-       0x14, 0x14, 0xF7, 0x00, 0xF7,
-       0x14, 0x14, 0x14, 0x17, 0x14,
-       0x10, 0x10, 0x1F, 0x10, 0x1F,
-       0x14, 0x14, 0x14, 0xF4, 0x14,
-       0x10, 0x10, 0xF0, 0x10, 0xF0,
-       0x00, 0x00, 0x1F, 0x10, 0x1F,
-       0x00, 0x00, 0x00, 0x1F, 0x14,
-       0x00, 0x00, 0x00, 0xFC, 0x14,
-       0x00, 0x00, 0xF0, 0x10, 0xF0,
-       0x10, 0x10, 0xFF, 0x10, 0xFF,
-       0x14, 0x14, 0x14, 0xFF, 0x14,
-       0x10, 0x10, 0x10, 0x1F, 0x00,
-       0x00, 0x00, 0x00, 0xF0, 0x10,
-       0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-       0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
-       0xFF, 0xFF, 0xFF, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0xFF, 0xFF,
-       0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
-       0x38, 0x44, 0x44, 0x38, 0x44,
-       0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
-       0x7E, 0x02, 0x02, 0x06, 0x06,
-       0x02, 0x7E, 0x02, 0x7E, 0x02,
-       0x63, 0x55, 0x49, 0x41, 0x63,
-       0x38, 0x44, 0x44, 0x3C, 0x04,
-       0x40, 0x7E, 0x20, 0x1E, 0x20,
-       0x06, 0x02, 0x7E, 0x02, 0x02,
-       0x99, 0xA5, 0xE7, 0xA5, 0x99,
-       0x1C, 0x2A, 0x49, 0x2A, 0x1C,
-       0x4C, 0x72, 0x01, 0x72, 0x4C,
-       0x30, 0x4A, 0x4D, 0x4D, 0x30,
-       0x30, 0x48, 0x78, 0x48, 0x30,
-       0xBC, 0x62, 0x5A, 0x46, 0x3D,
-       0x3E, 0x49, 0x49, 0x49, 0x00,
-       0x7E, 0x01, 0x01, 0x01, 0x7E,
-       0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
-       0x44, 0x44, 0x5F, 0x44, 0x44,
-       0x40, 0x51, 0x4A, 0x44, 0x40,
-       0x40, 0x44, 0x4A, 0x51, 0x40,
-       0x00, 0x00, 0xFF, 0x01, 0x03,
-       0xE0, 0x80, 0xFF, 0x00, 0x00,
-       0x08, 0x08, 0x6B, 0x6B, 0x08,
-       0x36, 0x12, 0x36, 0x24, 0x36,
-       0x06, 0x0F, 0x09, 0x0F, 0x06,
-       0x00, 0x00, 0x18, 0x18, 0x00,
-       0x00, 0x00, 0x10, 0x10, 0x00,
-       0x30, 0x40, 0xFF, 0x01, 0x01,
-       0x00, 0x1F, 0x01, 0x01, 0x1E,
-       0x00, 0x19, 0x1D, 0x17, 0x12,
-       0x00, 0x3C, 0x3C, 0x3C, 0x3C,
-       0x00, 0x00, 0x00, 0x00, 0x00  // #255 NBSP
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, 0x18, 0x3C, 0x18, 0x00, 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, 0x18, 0x24, 0x18, 0x00, 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x26, 0x29, 0x79, 0x29, 0x26, 0x40, 0x7F, 0x05, 0x05, 0x07, 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, 0x66, 0x89, 0x95, 0x6A, 0x60, 0x60, 0x60, 0x60, 0x60, 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x08, 0x04, 0x7E, 0x04, 0x08, 0x10, 0x20, 0x7E, 0x20, 0x10, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x1E, 0x10, 0x10, 0x10, 0x10, 0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
+    0x30, 0x38, 0x3E, 0x38, 0x30, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x23, 0x13, 0x08, 0x64, 0x62, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x80, 0x70, 0x30, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x60, 0x60, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x72, 0x49, 0x49, 0x49, 0x46, 0x21, 0x41, 0x49, 0x4D, 0x33, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x27, 0x45, 0x45, 0x45, 0x39, 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x41, 0x21, 0x11, 0x09, 0x07, 0x36, 0x49, 0x49, 0x49, 0x36, 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x40, 0x34, 0x00, 0x00,
+    0x00, 0x08, 0x14, 0x22, 0x41, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x41, 0x22, 0x14, 0x08, 0x02, 0x01, 0x59, 0x09, 0x06, 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x3E, 0x41, 0x41, 0x51, 0x73, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x26, 0x49, 0x49, 0x49, 0x32, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x63, 0x14, 0x08, 0x14, 0x63, 0x03, 0x04, 0x78, 0x04, 0x03,
+    0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x04, 0x02, 0x01, 0x02, 0x04, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x03, 0x07, 0x08, 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x38, 0x44, 0x44, 0x44, 0x28, 0x38, 0x44, 0x44, 0x28, 0x7F, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x08, 0x7E, 0x09, 0x02, 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x20, 0x40, 0x40, 0x3D, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x7C, 0x04, 0x78, 0x04, 0x78, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x38, 0x44, 0x44, 0x44, 0x38, 0xFC, 0x18, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x48, 0x54, 0x54, 0x54, 0x24, 0x04, 0x04, 0x3F, 0x44, 0x24, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x3C, 0x40, 0x30, 0x40, 0x3C,
+    0x44, 0x28, 0x10, 0x28, 0x44, 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 0x02, 0x01, 0x02, 0x04, 0x02, 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x1E, 0xA1, 0xA1, 0x61, 0x12, 0x3A, 0x40, 0x40, 0x20, 0x7A, 0x38, 0x54, 0x54, 0x55, 0x59, 0x21, 0x55, 0x55, 0x79, 0x41, 0x22, 0x54, 0x54, 0x78, 0x42,                                                                                                                                                                                                                                                                                                              // a-umlaut
+    0x21, 0x55, 0x54, 0x78, 0x40, 0x20, 0x54, 0x55, 0x79, 0x40, 0x0C, 0x1E, 0x52, 0x72, 0x12, 0x39, 0x55, 0x55, 0x55, 0x59, 0x39, 0x54, 0x54, 0x54, 0x59, 0x39, 0x55, 0x54, 0x54, 0x58, 0x00, 0x00, 0x45, 0x7C, 0x41, 0x00, 0x02, 0x45, 0x7D, 0x42, 0x00, 0x01, 0x45, 0x7C, 0x40, 0x7D, 0x12, 0x11, 0x12, 0x7D,                                                                                                                                                                                                                                                                                                                                                                                                        // A-umlaut
+    0xF0, 0x28, 0x25, 0x28, 0xF0, 0x7C, 0x54, 0x55, 0x45, 0x00, 0x20, 0x54, 0x54, 0x7C, 0x54, 0x7C, 0x0A, 0x09, 0x7F, 0x49, 0x32, 0x49, 0x49, 0x49, 0x32, 0x3A, 0x44, 0x44, 0x44, 0x3A,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                // o-umlaut
+    0x32, 0x4A, 0x48, 0x48, 0x30, 0x3A, 0x41, 0x41, 0x21, 0x7A, 0x3A, 0x42, 0x40, 0x20, 0x78, 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 0x3D, 0x42, 0x42, 0x42, 0x3D,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              // O-umlaut
+    0x3D, 0x40, 0x40, 0x40, 0x3D, 0x3C, 0x24, 0xFF, 0x24, 0x24, 0x48, 0x7E, 0x49, 0x43, 0x66, 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 0xFF, 0x09, 0x29, 0xF6, 0x20, 0xC0, 0x88, 0x7E, 0x09, 0x03, 0x20, 0x54, 0x54, 0x79, 0x41, 0x00, 0x00, 0x44, 0x7D, 0x41, 0x30, 0x48, 0x48, 0x4A, 0x32, 0x38, 0x40, 0x40, 0x22, 0x7A, 0x00, 0x7A, 0x0A, 0x0A, 0x72, 0x7D, 0x0D, 0x19, 0x31, 0x7D, 0x26, 0x29, 0x29, 0x2F, 0x28, 0x26, 0x29, 0x29, 0x29, 0x26, 0x30, 0x48, 0x4D, 0x40, 0x20, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 0x2F, 0x10, 0x28, 0x34, 0xFA, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x08, 0x14, 0x2A, 0x14, 0x22, 0x22, 0x14, 0x2A, 0x14, 0x08, 0x55, 0x00, 0x55, 0x00, 0x55,  // #176 (25% block) missing in old code
+    0xAA, 0x55, 0xAA, 0x55, 0xAA,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // 50% block
+    0xFF, 0x55, 0xFF, 0x55, 0xFF,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // 75% block
+    0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x10, 0x10, 0xFF, 0x00, 0x14, 0x14, 0x14, 0xFF, 0x00, 0x10, 0x10, 0xFF, 0x00, 0xFF, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x14, 0x14, 0x14, 0xFC, 0x00, 0x14, 0x14, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x14, 0x14, 0xF4, 0x04, 0xFC, 0x14, 0x14, 0x17, 0x10, 0x1F, 0x10, 0x10, 0x1F, 0x10, 0x1F, 0x14, 0x14, 0x14, 0x1F, 0x00, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x14, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x1F, 0x10, 0x17, 0x00, 0x00, 0xFC, 0x04, 0xF4, 0x14, 0x14, 0x17, 0x10, 0x17, 0x14, 0x14, 0xF4, 0x04, 0xF4, 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0xF7, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x17, 0x14, 0x10, 0x10, 0x1F, 0x10, 0x1F,
+    0x14, 0x14, 0x14, 0xF4, 0x14, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00, 0x1F, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x14, 0x00, 0x00, 0x00, 0xFC, 0x14, 0x00, 0x00, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0xFF, 0x10, 0xFF, 0x14, 0x14, 0x14, 0xFF, 0x14, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x38, 0x44, 0x44, 0x38, 0x44, 0xFC, 0x4A, 0x4A, 0x4A, 0x34,                                                                                                                                                                                                                                                                                                                                                                                                       // sharp-s or beta
+    0x7E, 0x02, 0x02, 0x06, 0x06, 0x02, 0x7E, 0x02, 0x7E, 0x02, 0x63, 0x55, 0x49, 0x41, 0x63, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x40, 0x7E, 0x20, 0x1E, 0x20, 0x06, 0x02, 0x7E, 0x02, 0x02, 0x99, 0xA5, 0xE7, 0xA5, 0x99, 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 0x4C, 0x72, 0x01, 0x72, 0x4C, 0x30, 0x4A, 0x4D, 0x4D, 0x30, 0x30, 0x48, 0x78, 0x48, 0x30, 0xBC, 0x62, 0x5A, 0x46, 0x3D, 0x3E, 0x49, 0x49, 0x49, 0x00, 0x7E, 0x01, 0x01, 0x01, 0x7E, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x44, 0x44, 0x5F, 0x44, 0x44, 0x40, 0x51, 0x4A, 0x44, 0x40, 0x40, 0x44, 0x4A, 0x51, 0x40, 0x00, 0x00, 0xFF, 0x01, 0x03, 0xE0, 0x80, 0xFF, 0x00, 0x00, 0x08, 0x08, 0x6B, 0x6B, 0x08, 0x36, 0x12, 0x36, 0x24, 0x36, 0x06, 0x0F, 0x09, 0x0F, 0x06, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x30, 0x40, 0xFF, 0x01, 0x01, 0x00, 0x1F, 0x01, 0x01, 0x1E, 0x00, 0x19, 0x1D, 0x17, 0x12, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00  // #255 NBSP
 };
-#endif // FONT5X7_H
+#endif  // FONT5X7_H
index 51414d8f914359072cf07707f49553d562241be2..f71069dece74c94bb9daa333d75fb5b00a3fadd3 100644 (file)
@@ -3,7 +3,7 @@
  Author:    Peter Fleury <pfleury@gmx.ch>  http://tinyurl.com/peterfleury
  License:   GNU General Public License Version 3
  File:     $Id: lcd.c,v 1.15.2.2 2015/01/17 12:16:05 peter Exp $
- Software:  AVR-GCC 3.3 
+ Software:  AVR-GCC 3.3
  Target:    any AVR device, memory mapped mode only for AT90S4414/8515/Mega
 
  DESCRIPTION
        changed lcd_init(), added additional constants for lcd_command(),
        added 4-bit I/O mode, improved and optimized code.
 
-       Library can be operated in memory mapped mode (LCD_IO_MODE=0) or in 
+       Library can be operated in memory mapped mode (LCD_IO_MODE=0) or in
        4-bit IO port mode (LCD_IO_MODE=1). 8-bit IO port mode not supported.
-       
+
        Memory mapped mode compatible with Kanda STK200, but supports also
        generation of R/W signal through A8 address line.
 
  USAGE
        See the C include lcd.h file for a description of each function
-       
+
 *****************************************************************************/
 #include <inttypes.h>
 #include <avr/io.h>
 #include <util/delay.h>
 #include "hd44780.h"
 
-/* 
-** constants/macros 
+/*
+** constants/macros
 */
-#define DDR(x) (*(&x - 1))      /* address of data direction register of port x */
+#define DDR(x) (*(&x - 1)) /* address of data direction register of port x */
 #if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
-    /* on ATmega64/128 PINF is on port 0x00 and not 0x60 */
-    #define PIN(x) ( &PORTF==&(x) ? _SFR_IO8(0x00) : (*(&x - 2)) )
+/* on ATmega64/128 PINF is on port 0x00 and not 0x60 */
+#    define PIN(x) (&PORTF == &(x) ? _SFR_IO8(0x00) : (*(&x - 2)))
 #else
-       #define PIN(x) (*(&x - 2))    /* address of input register of port x          */
+#    define PIN(x) (*(&x - 2)) /* address of input register of port x          */
 #endif
 
-
 #if LCD_IO_MODE
-#define lcd_e_delay()   _delay_us(LCD_DELAY_ENABLE_PULSE)
-#define lcd_e_high()    LCD_E_PORT  |=  _BV(LCD_E_PIN);
-#define lcd_e_low()     LCD_E_PORT  &= ~_BV(LCD_E_PIN);
-#define lcd_e_toggle()  toggle_e()
-#define lcd_rw_high()   LCD_RW_PORT |=  _BV(LCD_RW_PIN)
-#define lcd_rw_low()    LCD_RW_PORT &= ~_BV(LCD_RW_PIN)
-#define lcd_rs_high()   LCD_RS_PORT |=  _BV(LCD_RS_PIN)
-#define lcd_rs_low()    LCD_RS_PORT &= ~_BV(LCD_RS_PIN)
+#    define lcd_e_delay() _delay_us(LCD_DELAY_ENABLE_PULSE)
+#    define lcd_e_high() LCD_E_PORT |= _BV(LCD_E_PIN);
+#    define lcd_e_low() LCD_E_PORT &= ~_BV(LCD_E_PIN);
+#    define lcd_e_toggle() toggle_e()
+#    define lcd_rw_high() LCD_RW_PORT |= _BV(LCD_RW_PIN)
+#    define lcd_rw_low() LCD_RW_PORT &= ~_BV(LCD_RW_PIN)
+#    define lcd_rs_high() LCD_RS_PORT |= _BV(LCD_RS_PIN)
+#    define lcd_rs_low() LCD_RS_PORT &= ~_BV(LCD_RS_PIN)
 #endif
 
 #if LCD_IO_MODE
-#if LCD_LINES==1
-#define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_4BIT_1LINE 
+#    if LCD_LINES == 1
+#        define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_1LINE
+#    else
+#        define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_2LINES
+#    endif
 #else
-#define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_4BIT_2LINES 
-#endif
-#else
-#if LCD_LINES==1
-#define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_8BIT_1LINE
-#else
-#define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_8BIT_2LINES
-#endif
+#    if LCD_LINES == 1
+#        define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_1LINE
+#    else
+#        define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_2LINES
+#    endif
 #endif
 
 #if LCD_CONTROLLER_KS0073
-#if LCD_LINES==4
+#    if LCD_LINES == 4
 
-#define KS0073_EXTENDED_FUNCTION_REGISTER_ON  0x2C   /* |0|010|1100 4-bit mode, extension-bit RE = 1 */
-#define KS0073_EXTENDED_FUNCTION_REGISTER_OFF 0x28   /* |0|010|1000 4-bit mode, extension-bit RE = 0 */
-#define KS0073_4LINES_MODE                    0x09   /* |0|000|1001 4 lines mode */
+#        define KS0073_EXTENDED_FUNCTION_REGISTER_ON 0x2C  /* |0|010|1100 4-bit mode, extension-bit RE = 1 */
+#        define KS0073_EXTENDED_FUNCTION_REGISTER_OFF 0x28 /* |0|010|1000 4-bit mode, extension-bit RE = 0 */
+#        define KS0073_4LINES_MODE 0x09                    /* |0|000|1001 4 lines mode */
 
-#endif
+#    endif
 #endif
 
-/* 
-** function prototypes 
+/*
+** function prototypes
 */
 #if LCD_IO_MODE
 static void toggle_e(void);
@@ -87,93 +86,83 @@ static void toggle_e(void);
 ** local functions
 */
 
-
-/************************************************************************* 
+/*************************************************************************
 delay for a minimum of <us> microseconds
 the number of loops is calculated at compile-time from MCU clock frequency
 *************************************************************************/
-#define delay(us)  _delay_us(us) 
-
+#define delay(us) _delay_us(us)
 
 #if LCD_IO_MODE
 /* toggle Enable Pin to initiate write */
-static void toggle_e(void)
-{
+static void toggle_e(void) {
     lcd_e_high();
     lcd_e_delay();
     lcd_e_low();
 }
 #endif
 
-
 /*************************************************************************
 Low-level function to write byte to LCD controller
 Input:    data   byte to write to LCD
-          rs     1: write data    
+          rs     1: write data
                  0: write instruction
 Returns:  none
 *************************************************************************/
 #if LCD_IO_MODE
-static void lcd_write(uint8_t data,uint8_t rs) 
-{
-    unsigned char dataBits ;
-
+static void lcd_write(uint8_t data, uint8_t rs) {
+    unsigned char dataBits;
 
-    if (rs) {        /* write data        (RS=1, RW=0) */
-       lcd_rs_high();
-    } else {         /* write instruction (RS=0, RW=0) */
-       lcd_rs_low();
+    if (rs) { /* write data        (RS=1, RW=0) */
+        lcd_rs_high();
+    } else { /* write instruction (RS=0, RW=0) */
+        lcd_rs_low();
     }
-    lcd_rw_low();    /* RW=0  write mode      */
+    lcd_rw_low(); /* RW=0  write mode      */
 
-    if ( ( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT )
-      && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) )
-    {
+    if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) {
         /* configure data pins as output */
         DDR(LCD_DATA0_PORT) |= 0x0F;
 
         /* output high nibble first */
-        dataBits = LCD_DATA0_PORT & 0xF0;
-        LCD_DATA0_PORT = dataBits |((data>>4)&0x0F);
+        dataBits       = LCD_DATA0_PORT & 0xF0;
+        LCD_DATA0_PORT = dataBits | ((data >> 4) & 0x0F);
         lcd_e_toggle();
 
         /* output low nibble */
-        LCD_DATA0_PORT = dataBits | (data&0x0F);
+        LCD_DATA0_PORT = dataBits | (data & 0x0F);
         lcd_e_toggle();
 
         /* all data pins high (inactive) */
         LCD_DATA0_PORT = dataBits | 0x0F;
-    }
-    else
-    {
+    } else {
         /* configure data pins as output */
         DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN);
         DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN);
         DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN);
         DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN);
-        
+
         /* output high nibble first */
         LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN);
         LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN);
         LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN);
         LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);
-       if(data & 0x80) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
-       if(data & 0x40) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
-       if(data & 0x20) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
-       if(data & 0x10) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);   
+        if (data & 0x80) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
+        if (data & 0x40) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
+        if (data & 0x20) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
+        if (data & 0x10) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
         lcd_e_toggle();
-        
+
         /* output low nibble */
         LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN);
         LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN);
         LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN);
         LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);
-       if(data & 0x08) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
-       if(data & 0x04) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
-       if(data & 0x02) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
-       if(data & 0x01) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
-        lcd_e_toggle();        
-        
+        if (data & 0x08) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
+        if (data & 0x04) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
+        if (data & 0x02) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
+        if (data & 0x01) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
+        lcd_e_toggle();
+
         /* all data pins high (inactive) */
         LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
         LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
@@ -182,85 +171,81 @@ static void lcd_write(uint8_t data,uint8_t rs)
     }
 }
 #else
-#define lcd_write(d,rs) if (rs) *(volatile uint8_t*)(LCD_IO_DATA) = d; else *(volatile uint8_t*)(LCD_IO_FUNCTION) = d;
+#    define lcd_write(d, rs)                        \
+        if (rs)                                     \
+            *(volatile uint8_t *)(LCD_IO_DATA) = d; \
+        else                                        \
+            *(volatile uint8_t *)(LCD_IO_FUNCTION) = d;
 /* rs==0 -> write instruction to LCD_IO_FUNCTION */
 /* rs==1 -> write data to LCD_IO_DATA */
 #endif
 
-
 /*************************************************************************
 Low-level function to read byte from LCD controller
-Input:    rs     1: read data    
+Input:    rs     1: read data
                  0: read busy flag / address counter
 Returns:  byte read from LCD controller
 *************************************************************************/
 #if LCD_IO_MODE
-static uint8_t lcd_read(uint8_t rs) 
-{
+static uint8_t lcd_read(uint8_t rs) {
     uint8_t data;
-    
-    
+
     if (rs)
-        lcd_rs_high();                       /* RS=1: read data      */
+        lcd_rs_high(); /* RS=1: read data      */
     else
-        lcd_rs_low();                        /* RS=0: read busy flag */
-    lcd_rw_high();                           /* RW=1  read mode      */
-    
-    if ( ( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT )
-      && ( LCD_DATA0_PIN == 0 )&& (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) )
-    {
-        DDR(LCD_DATA0_PORT) &= 0xF0;         /* configure data pins as input */
-        
+        lcd_rs_low(); /* RS=0: read busy flag */
+    lcd_rw_high();    /* RW=1  read mode      */
+
+    if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) {
+        DDR(LCD_DATA0_PORT) &= 0xF0; /* configure data pins as input */
+
         lcd_e_high();
-        lcd_e_delay();        
-        data = PIN(LCD_DATA0_PORT) << 4;     /* read high nibble first */
+        lcd_e_delay();
+        data = PIN(LCD_DATA0_PORT) << 4; /* read high nibble first */
         lcd_e_low();
-        
-        lcd_e_delay();                       /* Enable 500ns low       */
-        
+
+        lcd_e_delay(); /* Enable 500ns low       */
+
         lcd_e_high();
         lcd_e_delay();
-        data |= PIN(LCD_DATA0_PORT)&0x0F;    /* read low nibble        */
+        data |= PIN(LCD_DATA0_PORT) & 0x0F; /* read low nibble        */
         lcd_e_low();
-    }
-    else
-    {
+    } else {
         /* configure data pins as input */
         DDR(LCD_DATA0_PORT) &= ~_BV(LCD_DATA0_PIN);
         DDR(LCD_DATA1_PORT) &= ~_BV(LCD_DATA1_PIN);
         DDR(LCD_DATA2_PORT) &= ~_BV(LCD_DATA2_PIN);
         DDR(LCD_DATA3_PORT) &= ~_BV(LCD_DATA3_PIN);
-                
+
         /* read high nibble first */
         lcd_e_high();
-        lcd_e_delay();        
+        lcd_e_delay();
         data = 0;
-        if ( PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN) ) data |= 0x10;
-        if ( PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN) ) data |= 0x20;
-        if ( PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN) ) data |= 0x40;
-        if ( PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN) ) data |= 0x80;
+        if (PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN)) data |= 0x10;
+        if (PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN)) data |= 0x20;
+        if (PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN)) data |= 0x40;
+        if (PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN)) data |= 0x80;
         lcd_e_low();
 
-        lcd_e_delay();                       /* Enable 500ns low       */
-    
-        /* read low nibble */    
+        lcd_e_delay(); /* Enable 500ns low       */
+
+        /* read low nibble */
         lcd_e_high();
         lcd_e_delay();
-        if ( PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN) ) data |= 0x01;
-        if ( PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN) ) data |= 0x02;
-        if ( PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN) ) data |= 0x04;
-        if ( PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN) ) data |= 0x08;        
+        if (PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN)) data |= 0x01;
+        if (PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN)) data |= 0x02;
+        if (PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN)) data |= 0x04;
+        if (PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN)) data |= 0x08;
         lcd_e_low();
     }
     return data;
 }
 #else
-#define lcd_read(rs) (rs) ? *(volatile uint8_t*)(LCD_IO_DATA+LCD_IO_READ) : *(volatile uint8_t*)(LCD_IO_FUNCTION+LCD_IO_READ)
+#    define lcd_read(rs) (rs) ? *(volatile uint8_t *)(LCD_IO_DATA + LCD_IO_READ) : *(volatile uint8_t *)(LCD_IO_FUNCTION + LCD_IO_READ)
 /* rs==0 -> read instruction from LCD_IO_FUNCTION */
 /* rs==1 -> read data from LCD_IO_DATA */
 #endif
 
-
 /*************************************************************************
 loops while lcd is busy, returns address counter
 *************************************************************************/
@@ -268,65 +253,62 @@ static uint8_t lcd_waitbusy(void)
 
 {
     register uint8_t c;
-    
+
     /* wait until busy flag is cleared */
-    while ( (c=lcd_read(0)) & (1<<LCD_BUSY)) {}
-    
+    while ((c = lcd_read(0)) & (1 << LCD_BUSY)) {
+    }
+
     /* the address counter is updated 4us after the busy flag is cleared */
     delay(LCD_DELAY_BUSY_FLAG);
 
     /* now read the address counter */
     return (lcd_read(0));  // return address counter
-    
-}/* lcd_waitbusy */
 
+} /* lcd_waitbusy */
 
 /*************************************************************************
-Move cursor to the start of next line or to the first line if the cursor 
+Move cursor to the start of next line or to the first line if the cursor
 is already on the last line.
 *************************************************************************/
-static inline void lcd_newline(uint8_t pos)
-{
+static inline void lcd_newline(uint8_t pos) {
     register uint8_t addressCounter;
 
-
-#if LCD_LINES==1
+#if LCD_LINES == 1
     addressCounter = 0;
 #endif
-#if LCD_LINES==2
-    if ( pos < (LCD_START_LINE2) )
+#if LCD_LINES == 2
+    if (pos < (LCD_START_LINE2))
         addressCounter = LCD_START_LINE2;
     else
         addressCounter = LCD_START_LINE1;
 #endif
-#if LCD_LINES==4
-#if KS0073_4LINES_MODE
-    if ( pos < LCD_START_LINE2 )
+#if LCD_LINES == 4
+#    if KS0073_4LINES_MODE
+    if (pos < LCD_START_LINE2)
         addressCounter = LCD_START_LINE2;
-    else if ( (pos >= LCD_START_LINE2) && (pos < LCD_START_LINE3) )
+    else if ((pos >= LCD_START_LINE2) && (pos < LCD_START_LINE3))
         addressCounter = LCD_START_LINE3;
-    else if ( (pos >= LCD_START_LINE3) && (pos < LCD_START_LINE4) )
+    else if ((pos >= LCD_START_LINE3) && (pos < LCD_START_LINE4))
         addressCounter = LCD_START_LINE4;
-    else 
+    else
         addressCounter = LCD_START_LINE1;
-#else
-    if ( pos < LCD_START_LINE3 )
+#    else
+    if (pos < LCD_START_LINE3)
         addressCounter = LCD_START_LINE2;
-    else if ( (pos >= LCD_START_LINE2) && (pos < LCD_START_LINE4) )
+    else if ((pos >= LCD_START_LINE2) && (pos < LCD_START_LINE4))
         addressCounter = LCD_START_LINE3;
-    else if ( (pos >= LCD_START_LINE3) && (pos < LCD_START_LINE2) )
+    else if ((pos >= LCD_START_LINE3) && (pos < LCD_START_LINE2))
         addressCounter = LCD_START_LINE4;
-    else 
+    else
         addressCounter = LCD_START_LINE1;
+#    endif
 #endif
-#endif
-    lcd_command((1<<LCD_DDRAM)+addressCounter);
-
-}/* lcd_newline */
+    lcd_command((1 << LCD_DDRAM) + addressCounter);
 
+} /* lcd_newline */
 
 /*
-** PUBLIC FUNCTIONS 
+** PUBLIC FUNCTIONS
 */
 
 /*************************************************************************
@@ -334,132 +316,107 @@ Send LCD controller instruction command
 Input:   instruction to send to LCD controller, see HD44780 data sheet
 Returns: none
 *************************************************************************/
-void lcd_command(uint8_t cmd)
-{
+void lcd_command(uint8_t cmd) {
     lcd_waitbusy();
-    lcd_write(cmd,0);
+    lcd_write(cmd, 0);
 }
 
-
 /*************************************************************************
-Send data byte to LCD controller 
+Send data byte to LCD controller
 Input:   data to send to LCD controller, see HD44780 data sheet
 Returns: none
 *************************************************************************/
-void lcd_data(uint8_t data)
-{
+void lcd_data(uint8_t data) {
     lcd_waitbusy();
-    lcd_write(data,1);
+    lcd_write(data, 1);
 }
 
-
-
 /*************************************************************************
 Set cursor to specified position
 Input:    x  horizontal position  (0: left most position)
           y  vertical position    (0: first line)
 Returns:  none
 *************************************************************************/
-void lcd_gotoxy(uint8_t x, uint8_t y)
-{
-#if LCD_LINES==1
-    lcd_command((1<<LCD_DDRAM)+LCD_START_LINE1+x);
+void lcd_gotoxy(uint8_t x, uint8_t y) {
+#if LCD_LINES == 1
+    lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
 #endif
-#if LCD_LINES==2
-    if ( y==0 ) 
-        lcd_command((1<<LCD_DDRAM)+LCD_START_LINE1+x);
+#if LCD_LINES == 2
+    if (y == 0)
+        lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
     else
-        lcd_command((1<<LCD_DDRAM)+LCD_START_LINE2+x);
+        lcd_command((1 << LCD_DDRAM) + LCD_START_LINE2 + x);
 #endif
-#if LCD_LINES==4
-    if ( y==0 )
-        lcd_command((1<<LCD_DDRAM)+LCD_START_LINE1+x);
-    else if ( y==1)
-        lcd_command((1<<LCD_DDRAM)+LCD_START_LINE2+x);
-    else if ( y==2)
-        lcd_command((1<<LCD_DDRAM)+LCD_START_LINE3+x);
+#if LCD_LINES == 4
+    if (y == 0)
+        lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
+    else if (y == 1)
+        lcd_command((1 << LCD_DDRAM) + LCD_START_LINE2 + x);
+    else if (y == 2)
+        lcd_command((1 << LCD_DDRAM) + LCD_START_LINE3 + x);
     else /* y==3 */
-        lcd_command((1<<LCD_DDRAM)+LCD_START_LINE4+x);
+        lcd_command((1 << LCD_DDRAM) + LCD_START_LINE4 + x);
 #endif
 
-}/* lcd_gotoxy */
-
+} /* lcd_gotoxy */
 
 /*************************************************************************
 *************************************************************************/
-int lcd_getxy(void)
-{
-    return lcd_waitbusy();
-}
-
+int lcd_getxy(void) { return lcd_waitbusy(); }
 
 /*************************************************************************
 Clear display and set cursor to home position
 *************************************************************************/
-void lcd_clrscr(void)
-{
-    lcd_command(1<<LCD_CLR);
-}
-
+void lcd_clrscr(void) { lcd_command(1 << LCD_CLR); }
 
 /*************************************************************************
 Set cursor to home position
 *************************************************************************/
-void lcd_home(void)
-{
-    lcd_command(1<<LCD_HOME);
-}
-
+void lcd_home(void) { lcd_command(1 << LCD_HOME); }
 
 /*************************************************************************
-Display character at current cursor position 
-Input:    character to be displayed                                       
+Display character at current cursor position
+Input:    character to be displayed
 Returns:  none
 *************************************************************************/
-void lcd_putc(char c)
-{
+void lcd_putc(char c) {
     uint8_t pos;
 
-
-    pos = lcd_waitbusy();   // read busy-flag and address counter
-    if (c=='\n')
-    {
+    pos = lcd_waitbusy();  // read busy-flag and address counter
+    if (c == '\n') {
         lcd_newline(pos);
-    }
-    else
-    {
-#if LCD_WRAP_LINES==1
-#if LCD_LINES==1
-        if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
-            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
+    } else {
+#if LCD_WRAP_LINES == 1
+#    if LCD_LINES == 1
+        if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) {
+            lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0);
         }
-#elif LCD_LINES==2
-        if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
-            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE2,0);    
-        }else if ( pos == LCD_START_LINE2+LCD_DISP_LENGTH ){
-            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
+#    elif LCD_LINES == 2
+        if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) {
+            lcd_write((1 << LCD_DDRAM) + LCD_START_LINE2, 0);
+        } else if (pos == LCD_START_LINE2 + LCD_DISP_LENGTH) {
+            lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0);
         }
-#elif LCD_LINES==4
-        if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
-            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE2,0);    
-        }else if ( pos == LCD_START_LINE2+LCD_DISP_LENGTH ) {
-            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE3,0);
-        }else if ( pos == LCD_START_LINE3+LCD_DISP_LENGTH ) {
-            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE4,0);
-        }else if ( pos == LCD_START_LINE4+LCD_DISP_LENGTH ) {
-            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
+#    elif LCD_LINES == 4
+        if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) {
+            lcd_write((1 << LCD_DDRAM) + LCD_START_LINE2, 0);
+        } else if (pos == LCD_START_LINE2 + LCD_DISP_LENGTH) {
+            lcd_write((1 << LCD_DDRAM) + LCD_START_LINE3, 0);
+        } else if (pos == LCD_START_LINE3 + LCD_DISP_LENGTH) {
+            lcd_write((1 << LCD_DDRAM) + LCD_START_LINE4, 0);
+        } else if (pos == LCD_START_LINE4 + LCD_DISP_LENGTH) {
+            lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0);
         }
-#endif
+#    endif
         lcd_waitbusy();
 #endif
         lcd_write(c, 1);
     }
 
-}/* lcd_putc */
-
+} /* lcd_putc */
 
 /*************************************************************************
-Display string without auto linefeed 
+Display string without auto linefeed
 Input:    string to be displayed
 Returns:  none
 *************************************************************************/
@@ -468,16 +425,15 @@ void lcd_puts(const char *s)
 {
     register char c;
 
-    while ( (c = *s++) ) {
+    while ((c = *s++)) {
         lcd_putc(c);
     }
 
-}/* lcd_puts */
-
+} /* lcd_puts */
 
 /*************************************************************************
-Display string from program memory without auto linefeed 
-Input:     string from program memory be be displayed                                        
+Display string from program memory without auto linefeed
+Input:     string from program memory be be displayed
 Returns:   none
 *************************************************************************/
 void lcd_puts_p(const char *progmem_s)
@@ -485,108 +441,96 @@ void lcd_puts_p(const char *progmem_s)
 {
     register char c;
 
-    while ( (c = pgm_read_byte(progmem_s++)) ) {
+    while ((c = pgm_read_byte(progmem_s++))) {
         lcd_putc(c);
     }
 
-}/* lcd_puts_p */
-
+} /* lcd_puts_p */
 
 /*************************************************************************
-Initialize display and select type of cursor 
+Initialize display and select type of cursor
 Input:    dispAttr LCD_DISP_OFF            display off
                    LCD_DISP_ON             display on, cursor off
                    LCD_DISP_ON_CURSOR      display on, cursor on
                    LCD_DISP_CURSOR_BLINK   display on, cursor on flashing
 Returns:  none
 *************************************************************************/
-void lcd_init(uint8_t dispAttr)
-{
+void lcd_init(uint8_t dispAttr) {
 #if LCD_IO_MODE
     /*
      *  Initialize LCD to 4 bit I/O mode
      */
-     
-    if ( ( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT )
-      && ( &LCD_RS_PORT == &LCD_DATA0_PORT) && ( &LCD_RW_PORT == &LCD_DATA0_PORT) && (&LCD_E_PORT == &LCD_DATA0_PORT)
-      && (LCD_DATA0_PIN == 0 ) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) 
-      && (LCD_RS_PIN == 4 ) && (LCD_RW_PIN == 5) && (LCD_E_PIN == 6 ) )
-    {
+
+    if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (&LCD_RS_PORT == &LCD_DATA0_PORT) && (&LCD_RW_PORT == &LCD_DATA0_PORT) && (&LCD_E_PORT == &LCD_DATA0_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) && (LCD_RS_PIN == 4) && (LCD_RW_PIN == 5) && (LCD_E_PIN == 6)) {
         /* configure all port bits as output (all LCD lines on same port) */
         DDR(LCD_DATA0_PORT) |= 0x7F;
-    }
-    else if ( ( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT )
-           && (LCD_DATA0_PIN == 0 ) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) )
-    {
+    } else if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) {
         /* configure all port bits as output (all LCD data lines on same port, but control lines on different ports) */
         DDR(LCD_DATA0_PORT) |= 0x0F;
-        DDR(LCD_RS_PORT)    |= _BV(LCD_RS_PIN);
-        DDR(LCD_RW_PORT)    |= _BV(LCD_RW_PIN);
-        DDR(LCD_E_PORT)     |= _BV(LCD_E_PIN);
-    }
-    else
-    {
+        DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN);
+        DDR(LCD_RW_PORT) |= _BV(LCD_RW_PIN);
+        DDR(LCD_E_PORT) |= _BV(LCD_E_PIN);
+    } else {
         /* configure all port bits as output (LCD data and control lines on different ports */
-        DDR(LCD_RS_PORT)    |= _BV(LCD_RS_PIN);
-        DDR(LCD_RW_PORT)    |= _BV(LCD_RW_PIN);
-        DDR(LCD_E_PORT)     |= _BV(LCD_E_PIN);
+        DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN);
+        DDR(LCD_RW_PORT) |= _BV(LCD_RW_PIN);
+        DDR(LCD_E_PORT) |= _BV(LCD_E_PIN);
         DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN);
         DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN);
         DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN);
         DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN);
     }
-    delay(LCD_DELAY_BOOTUP);             /* wait 16ms or more after power-on       */
-    
+    delay(LCD_DELAY_BOOTUP); /* wait 16ms or more after power-on       */
+
     /* initial write to lcd is 8bit */
-    LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);    // LCD_FUNCTION>>4;
-    LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);    // LCD_FUNCTION_8BIT>>4;
+    LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);  // LCD_FUNCTION>>4;
+    LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);  // LCD_FUNCTION_8BIT>>4;
+    lcd_e_toggle();
+    delay(LCD_DELAY_INIT); /* delay, busy flag can't be checked here */
+
+    /* repeat last command */
     lcd_e_toggle();
-    delay(LCD_DELAY_INIT);               /* delay, busy flag can't be checked here */
-   
-    /* repeat last command */ 
-    lcd_e_toggle();      
-    delay(LCD_DELAY_INIT_REP);           /* delay, busy flag can't be checked here */
-    
+    delay(LCD_DELAY_INIT_REP); /* delay, busy flag can't be checked here */
+
     /* repeat last command a third time */
-    lcd_e_toggle();      
-    delay(LCD_DELAY_INIT_REP);           /* delay, busy flag can't be checked here */
+    lcd_e_toggle();
+    delay(LCD_DELAY_INIT_REP); /* delay, busy flag can't be checked here */
 
     /* now configure for 4bit mode */
-    LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);   // LCD_FUNCTION_4BIT_1LINE>>4
+    LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);  // LCD_FUNCTION_4BIT_1LINE>>4
     lcd_e_toggle();
-    delay(LCD_DELAY_INIT_4BIT);          /* some displays need this additional delay */
-    
-    /* from now the LCD only accepts 4 bit I/O, we can use lcd_command() */    
+    delay(LCD_DELAY_INIT_4BIT); /* some displays need this additional delay */
+
+    /* from now the LCD only accepts 4 bit I/O, we can use lcd_command() */
 #else
     /*
      * Initialize LCD to 8 bit memory mapped mode
      */
-    
-    /* enable external SRAM (memory mapped lcd) and one wait state */        
+
+    /* enable external SRAM (memory mapped lcd) and one wait state */
     MCUCR = _BV(SRE) | _BV(SRW);
 
     /* reset LCD */
-    delay(LCD_DELAY_BOOTUP);                    /* wait 16ms after power-on     */
-    lcd_write(LCD_FUNCTION_8BIT_1LINE,0);   /* function set: 8bit interface */                   
-    delay(LCD_DELAY_INIT);                      /* wait 5ms                     */
-    lcd_write(LCD_FUNCTION_8BIT_1LINE,0);   /* function set: 8bit interface */                 
-    delay(LCD_DELAY_INIT_REP);                  /* wait 64us                    */
-    lcd_write(LCD_FUNCTION_8BIT_1LINE,0);   /* function set: 8bit interface */                
-    delay(LCD_DELAY_INIT_REP);                  /* wait 64us                    */
+    delay(LCD_DELAY_BOOTUP);               /* wait 16ms after power-on     */
+    lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */
+    delay(LCD_DELAY_INIT);                 /* wait 5ms                     */
+    lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */
+    delay(LCD_DELAY_INIT_REP);             /* wait 64us                    */
+    lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */
+    delay(LCD_DELAY_INIT_REP);             /* wait 64us                    */
 #endif
 
 #if KS0073_4LINES_MODE
     /* Display with KS0073 controller requires special commands for enabling 4 line mode */
-       lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_ON);
-       lcd_command(KS0073_4LINES_MODE);
-       lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_OFF);
+    lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_ON);
+    lcd_command(KS0073_4LINES_MODE);
+    lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_OFF);
 #else
-    lcd_command(LCD_FUNCTION_DEFAULT);      /* function set: display lines  */
+    lcd_command(LCD_FUNCTION_DEFAULT);     /* function set: display lines  */
 #endif
-    lcd_command(LCD_DISP_OFF);              /* display off                  */
-    lcd_clrscr();                           /* display clear                */ 
-    lcd_command(LCD_MODE_DEFAULT);          /* set entry mode               */
-    lcd_command(dispAttr);                  /* display/cursor control       */
-
-}/* lcd_init */
+    lcd_command(LCD_DISP_OFF);     /* display off                  */
+    lcd_clrscr();                  /* display clear                */
+    lcd_command(LCD_MODE_DEFAULT); /* set entry mode               */
+    lcd_command(dispAttr);         /* display/cursor control       */
 
+} /* lcd_init */
index 7421c8131f8d0ce4dc0c27322082f6175adfcdf0..e60817e9898d7b66ce09628ccaeac4f6ce6a0a47 100644 (file)
@@ -6,7 +6,7 @@
  License:   GNU General Public License Version 3
  File:     $Id: lcd.h,v 1.14.2.4 2015/01/20 17:16:07 peter Exp $
  Software:  AVR-GCC 4.x
- Hardware:  any AVR device, memory mapped mode only for AVR with 
+ Hardware:  any AVR device, memory mapped mode only for AVR with
             memory mapped interface (AT90S8515/ATmega8515/ATmega128)
 ***************************************************************************/
 
  Collection of libraries for AVR-GCC
  @author Peter Fleury pfleury@gmx.ch http://tinyurl.com/peterfleury
  @copyright (C) 2015 Peter Fleury, GNU General Public License Version 3
+
  @file
  @defgroup pfleury_lcd LCD library <lcd.h>
  @code #include <lcd.h> @endcode
+
  @brief Basic routines for interfacing a HD44780U-based character LCD display
 
- LCD character displays can be found in many devices, like espresso machines, laser printers. 
- The Hitachi HD44780 controller and its compatible controllers like Samsung KS0066U have become an industry standard for these types of displays. 
+ LCD character displays can be found in many devices, like espresso machines, laser printers.
+ The Hitachi HD44780 controller and its compatible controllers like Samsung KS0066U have become an industry standard for these types of displays.
+
  This library allows easy interfacing with a HD44780 compatible display and can be
- operated in memory mapped mode (LCD_IO_MODE defined as 0 in the include file lcd.h.) or in 
+ operated in memory mapped mode (LCD_IO_MODE defined as 0 in the include file lcd.h.) or in
  4-bit IO port mode (LCD_IO_MODE defined as 1). 8-bit IO port mode is not supported.
 
  Memory mapped mode is compatible with old Kanda STK200 starter kit, but also supports
  generation of R/W signal through A8 address line.
 
  @see The chapter <a href=" http://homepage.hispeed.ch/peterfleury/avr-lcd44780.html" target="_blank">Interfacing a HD44780 Based LCD to an AVR</a>
-      on my home page, which shows example circuits how to connect an LCD to an AVR controller. 
+      on my home page, which shows example circuits how to connect an LCD to an AVR controller.
 
  @author Peter Fleury pfleury@gmx.ch http://tinyurl.com/peterfleury
+
  @version   2.0
+
  @copyright (C) 2015 Peter Fleury, GNU General Public License Version 3
-  
+
 */
 
 #include <inttypes.h>
 #include <avr/pgmspace.h>
 
 #if (__GNUC__ * 100 + __GNUC_MINOR__) < 405
-#error "This library requires AVR-GCC 4.5 or later, update to newer AVR-GCC compiler !"
+#    error "This library requires AVR-GCC 4.5 or later, update to newer AVR-GCC compiler !"
 #endif
 
-
 /**@{*/
 
 /*
- * LCD and target specific definitions below can be defined in a separate include file with name lcd_definitions.h instead modifying this file 
+ * LCD and target specific definitions below can be defined in a separate include file with name lcd_definitions.h instead modifying this file
  * by adding -D_LCD_DEFINITIONS_FILE to the CDEFS section in the Makefile
  * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
  */
 #ifdef _LCD_DEFINITIONS_FILE
-#include "lcd_definitions.h"
+#    include "lcd_definitions.h"
 #endif
 
-
 /**
  * @name  Definition for LCD controller type
  * Use 0 for HD44780 controller, change to 1 for displays with KS0073 controller.
  */
-#ifndef LCD_CONTROLLER_KS0073 
-#define LCD_CONTROLLER_KS0073 0  /**< Use 0 for HD44780 controller, 1 for KS0073 controller */
+#ifndef LCD_CONTROLLER_KS0073
+#    define LCD_CONTROLLER_KS0073 0 /**< Use 0 for HD44780 controller, 1 for KS0073 controller */
 #endif
 
-/** 
- * @name  Definitions for Display Size 
+/**
+ * @name  Definitions for Display Size
  * Change these definitions to adapt setting to your display
  *
- * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by 
+ * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by
  * adding -D_LCD_DEFINITIONS_FILE to the CDEFS section in the Makefile.
  * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
  *
  */
 #ifndef LCD_LINES
-#define LCD_LINES           2     /**< number of visible lines of the display */
+#    define LCD_LINES 2 /**< number of visible lines of the display */
 #endif
 #ifndef LCD_DISP_LENGTH
-#define LCD_DISP_LENGTH    16     /**< visibles characters per line of the display */
+#    define LCD_DISP_LENGTH 16 /**< visibles characters per line of the display */
 #endif
 #ifndef LCD_LINE_LENGTH
-#define LCD_LINE_LENGTH  0x40     /**< internal line length of the display    */
+#    define LCD_LINE_LENGTH 0x40 /**< internal line length of the display    */
 #endif
 #ifndef LCD_START_LINE1
-#define LCD_START_LINE1  0x00     /**< DDRAM address of first char of line 1 */
+#    define LCD_START_LINE1 0x00 /**< DDRAM address of first char of line 1 */
 #endif
 #ifndef LCD_START_LINE2
-#define LCD_START_LINE2  0x40     /**< DDRAM address of first char of line 2 */
+#    define LCD_START_LINE2 0x40 /**< DDRAM address of first char of line 2 */
 #endif
 #ifndef LCD_START_LINE3
-#define LCD_START_LINE3  0x14     /**< DDRAM address of first char of line 3 */
+#    define LCD_START_LINE3 0x14 /**< DDRAM address of first char of line 3 */
 #endif
 #ifndef LCD_START_LINE4
-#define LCD_START_LINE4  0x54     /**< DDRAM address of first char of line 4 */
+#    define LCD_START_LINE4 0x54 /**< DDRAM address of first char of line 4 */
 #endif
 #ifndef LCD_WRAP_LINES
-#define LCD_WRAP_LINES      0     /**< 0: no wrap, 1: wrap at end of visibile line */
+#    define LCD_WRAP_LINES 0 /**< 0: no wrap, 1: wrap at end of visibile line */
 #endif
 
-
 /**
  * @name Definitions for 4-bit IO mode
  *
- * The four LCD data lines and the three control lines RS, RW, E can be on the 
- * same port or on different ports. 
+ * The four LCD data lines and the three control lines RS, RW, E can be on the
+ * same port or on different ports.
  * Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on
- * different ports. 
+ * different ports.
  *
  * Normally the four data lines should be mapped to bit 0..3 on one port, but it
  * is possible to connect these data lines in different order or even on different
  * ports by adapting the LCD_DATAx_PORT and LCD_DATAx_PIN definitions.
  *
- * Adjust these definitions to your target.\n 
- * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by 
+ * Adjust these definitions to your target.\n
+ * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by
  * adding \b -D_LCD_DEFINITIONS_FILE to the \b CDEFS section in the Makefile.
  * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
- *  
+ *
  */
-#define LCD_IO_MODE      1            /**< 0: memory mapped mode, 1: IO port mode */
+#define LCD_IO_MODE 1 /**< 0: memory mapped mode, 1: IO port mode */
 
 #if LCD_IO_MODE
 
-#ifndef LCD_PORT
-#define LCD_PORT         PORTA        /**< port for the LCD lines   */
-#endif
-#ifndef LCD_DATA0_PORT
-#define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */
-#endif
-#ifndef LCD_DATA1_PORT
-#define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */
-#endif
-#ifndef LCD_DATA2_PORT
-#define LCD_DATA2_PORT   LCD_PORT     /**< port for 4bit data bit 2 */
-#endif
-#ifndef LCD_DATA3_PORT
-#define LCD_DATA3_PORT   LCD_PORT     /**< port for 4bit data bit 3 */
-#endif
-#ifndef LCD_DATA0_PIN
-#define LCD_DATA0_PIN    4            /**< pin for 4bit data bit 0  */
-#endif
-#ifndef LCD_DATA1_PIN
-#define LCD_DATA1_PIN    5            /**< pin for 4bit data bit 1  */
-#endif
-#ifndef LCD_DATA2_PIN
-#define LCD_DATA2_PIN    6            /**< pin for 4bit data bit 2  */
-#endif
-#ifndef LCD_DATA3_PIN
-#define LCD_DATA3_PIN    7            /**< pin for 4bit data bit 3  */
-#endif
-#ifndef LCD_RS_PORT
-#define LCD_RS_PORT      LCD_PORT     /**< port for RS line         */
-#endif
-#ifndef LCD_RS_PIN
-#define LCD_RS_PIN       3            /**< pin  for RS line         */
-#endif
-#ifndef LCD_RW_PORT
-#define LCD_RW_PORT      LCD_PORT     /**< port for RW line         */
-#endif
-#ifndef LCD_RW_PIN
-#define LCD_RW_PIN       2            /**< pin  for RW line         */
-#endif
-#ifndef LCD_E_PORT
-#define LCD_E_PORT       LCD_PORT     /**< port for Enable line     */
-#endif
-#ifndef LCD_E_PIN
-#define LCD_E_PIN        1            /**< pin  for Enable line     */
-#endif
-
-#elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || defined(__AVR_ATmega64__) || \
-      defined(__AVR_ATmega8515__)|| defined(__AVR_ATmega103__) || defined(__AVR_ATmega128__) || \
-      defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__)
+#    ifndef LCD_PORT
+#        define LCD_PORT PORTA /**< port for the LCD lines   */
+#    endif
+#    ifndef LCD_DATA0_PORT
+#        define LCD_DATA0_PORT LCD_PORT /**< port for 4bit data bit 0 */
+#    endif
+#    ifndef LCD_DATA1_PORT
+#        define LCD_DATA1_PORT LCD_PORT /**< port for 4bit data bit 1 */
+#    endif
+#    ifndef LCD_DATA2_PORT
+#        define LCD_DATA2_PORT LCD_PORT /**< port for 4bit data bit 2 */
+#    endif
+#    ifndef LCD_DATA3_PORT
+#        define LCD_DATA3_PORT LCD_PORT /**< port for 4bit data bit 3 */
+#    endif
+#    ifndef LCD_DATA0_PIN
+#        define LCD_DATA0_PIN 4 /**< pin for 4bit data bit 0  */
+#    endif
+#    ifndef LCD_DATA1_PIN
+#        define LCD_DATA1_PIN 5 /**< pin for 4bit data bit 1  */
+#    endif
+#    ifndef LCD_DATA2_PIN
+#        define LCD_DATA2_PIN 6 /**< pin for 4bit data bit 2  */
+#    endif
+#    ifndef LCD_DATA3_PIN
+#        define LCD_DATA3_PIN 7 /**< pin for 4bit data bit 3  */
+#    endif
+#    ifndef LCD_RS_PORT
+#        define LCD_RS_PORT LCD_PORT /**< port for RS line         */
+#    endif
+#    ifndef LCD_RS_PIN
+#        define LCD_RS_PIN 3 /**< pin  for RS line         */
+#    endif
+#    ifndef LCD_RW_PORT
+#        define LCD_RW_PORT LCD_PORT /**< port for RW line         */
+#    endif
+#    ifndef LCD_RW_PIN
+#        define LCD_RW_PIN 2 /**< pin  for RW line         */
+#    endif
+#    ifndef LCD_E_PORT
+#        define LCD_E_PORT LCD_PORT /**< port for Enable line     */
+#    endif
+#    ifndef LCD_E_PIN
+#        define LCD_E_PIN 1 /**< pin  for Enable line     */
+#    endif
+
+#elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || defined(__AVR_ATmega64__) || defined(__AVR_ATmega8515__) || defined(__AVR_ATmega103__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__)
 /*
  * memory mapped mode is only supported when the device has an external data memory interface
  */
-#define LCD_IO_DATA      0xC000    /* A15=E=1, A14=RS=1                 */
-#define LCD_IO_FUNCTION  0x8000    /* A15=E=1, A14=RS=0                 */
-#define LCD_IO_READ      0x0100    /* A8 =R/W=1 (R/W: 1=Read, 0=Write   */
+#    define LCD_IO_DATA 0xC000     /* A15=E=1, A14=RS=1                 */
+#    define LCD_IO_FUNCTION 0x8000 /* A15=E=1, A14=RS=0                 */
+#    define LCD_IO_READ 0x0100     /* A8 =R/W=1 (R/W: 1=Read, 0=Write   */
 
 #else
-#error "external data memory interface not available for this device, use 4-bit IO port mode"
+#    error "external data memory interface not available for this device, use 4-bit IO port mode"
 
 #endif
 
-
 /**
  * @name Definitions of delays
  * Used to calculate delay timers.
  * Adapt the F_CPU define in the Makefile to the clock frequency in Hz of your target
  *
- * These delay times can be adjusted, if some displays require different delays.\n 
- * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by 
+ * These delay times can be adjusted, if some displays require different delays.\n
+ * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by
  * adding \b -D_LCD_DEFINITIONS_FILE to the \b CDEFS section in the Makefile.
  * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
  */
 #ifndef LCD_DELAY_BOOTUP
-#define LCD_DELAY_BOOTUP   16000      /**< delay in micro seconds after power-on  */
+#    define LCD_DELAY_BOOTUP 16000 /**< delay in micro seconds after power-on  */
 #endif
 #ifndef LCD_DELAY_INIT
-#define LCD_DELAY_INIT      5000      /**< delay in micro seconds after initialization command sent  */
+#    define LCD_DELAY_INIT 5000 /**< delay in micro seconds after initialization command sent  */
 #endif
 #ifndef LCD_DELAY_INIT_REP
-#define LCD_DELAY_INIT_REP    64      /**< delay in micro seconds after initialization command repeated */
+#    define LCD_DELAY_INIT_REP 64 /**< delay in micro seconds after initialization command repeated */
 #endif
 #ifndef LCD_DELAY_INIT_4BIT
-#define LCD_DELAY_INIT_4BIT   64      /**< delay in micro seconds after setting 4-bit mode */ 
+#    define LCD_DELAY_INIT_4BIT 64 /**< delay in micro seconds after setting 4-bit mode */
 #endif
 #ifndef LCD_DELAY_BUSY_FLAG
-#define LCD_DELAY_BUSY_FLAG    4      /**< time in micro seconds the address counter is updated after busy flag is cleared */
+#    define LCD_DELAY_BUSY_FLAG 4 /**< time in micro seconds the address counter is updated after busy flag is cleared */
 #endif
 #ifndef LCD_DELAY_ENABLE_PULSE
-#define LCD_DELAY_ENABLE_PULSE 1      /**< enable signal pulse width in micro seconds */
+#    define LCD_DELAY_ENABLE_PULSE 1 /**< enable signal pulse width in micro seconds */
 #endif
 
-
 /**
  * @name Definitions for LCD command instructions
- * The constants define the various LCD controller instructions which can be passed to the 
+ * The constants define the various LCD controller instructions which can be passed to the
  * function lcd_command(), see HD44780 data sheet for a complete description.
  */
 
 /* instruction register bit positions, see HD44780U data sheet */
-#define LCD_CLR               0      /* DB0: clear display                  */
-#define LCD_HOME              1      /* DB1: return to home position        */
-#define LCD_ENTRY_MODE        2      /* DB2: set entry mode                 */
-#define LCD_ENTRY_INC         1      /*   DB1: 1=increment, 0=decrement     */
-#define LCD_ENTRY_SHIFT       0      /*   DB2: 1=display shift on           */
-#define LCD_ON                3      /* DB3: turn lcd/cursor on             */
-#define LCD_ON_DISPLAY        2      /*   DB2: turn display on              */
-#define LCD_ON_CURSOR         1      /*   DB1: turn cursor on               */
-#define LCD_ON_BLINK          0      /*     DB0: blinking cursor ?          */
-#define LCD_MOVE              4      /* DB4: move cursor/display            */
-#define LCD_MOVE_DISP         3      /*   DB3: move display (0-> cursor) ?  */
-#define LCD_MOVE_RIGHT        2      /*   DB2: move right (0-> left) ?      */
-#define LCD_FUNCTION          5      /* DB5: function set                   */
-#define LCD_FUNCTION_8BIT     4      /*   DB4: set 8BIT mode (0->4BIT mode) */
-#define LCD_FUNCTION_2LINES   3      /*   DB3: two lines (0->one line)      */
-#define LCD_FUNCTION_10DOTS   2      /*   DB2: 5x10 font (0->5x7 font)      */
-#define LCD_CGRAM             6      /* DB6: set CG RAM address             */
-#define LCD_DDRAM             7      /* DB7: set DD RAM address             */
-#define LCD_BUSY              7      /* DB7: LCD is busy                    */
+#define LCD_CLR 0             /* DB0: clear display                  */
+#define LCD_HOME 1            /* DB1: return to home position        */
+#define LCD_ENTRY_MODE 2      /* DB2: set entry mode                 */
+#define LCD_ENTRY_INC       /*   DB1: 1=increment, 0=decrement     */
+#define LCD_ENTRY_SHIFT 0     /*   DB2: 1=display shift on           */
+#define LCD_ON 3              /* DB3: turn lcd/cursor on             */
+#define LCD_ON_DISPLAY 2      /*   DB2: turn display on              */
+#define LCD_ON_CURSOR       /*   DB1: turn cursor on               */
+#define LCD_ON_BLINK 0        /*     DB0: blinking cursor ?          */
+#define LCD_MOVE 4            /* DB4: move cursor/display            */
+#define LCD_MOVE_DISP       /*   DB3: move display (0-> cursor) ?  */
+#define LCD_MOVE_RIGHT 2      /*   DB2: move right (0-> left) ?      */
+#define LCD_FUNCTION 5        /* DB5: function set                   */
+#define LCD_FUNCTION_8BIT 4   /*   DB4: set 8BIT mode (0->4BIT mode) */
+#define LCD_FUNCTION_2LINES 3 /*   DB3: two lines (0->one line)      */
+#define LCD_FUNCTION_10DOTS 2 /*   DB2: 5x10 font (0->5x7 font)      */
+#define LCD_CGRAM 6           /* DB6: set CG RAM address             */
+#define LCD_DDRAM 7           /* DB7: set DD RAM address             */
+#define LCD_BUSY 7            /* DB7: LCD is busy                    */
 
 /* set entry mode: display shift on/off, dec/inc cursor move direction */
-#define LCD_ENTRY_DEC            0x04   /* display shift off, dec cursor move dir */
-#define LCD_ENTRY_DEC_SHIFT      0x05   /* display shift on,  dec cursor move dir */
-#define LCD_ENTRY_INC_           0x06   /* display shift off, inc cursor move dir */
-#define LCD_ENTRY_INC_SHIFT      0x07   /* display shift on,  inc cursor move dir */
+#define LCD_ENTRY_DEC 0x04       /* display shift off, dec cursor move dir */
+#define LCD_ENTRY_DEC_SHIFT 0x05 /* display shift on,  dec cursor move dir */
+#define LCD_ENTRY_INC_ 0x06      /* display shift off, inc cursor move dir */
+#define LCD_ENTRY_INC_SHIFT 0x07 /* display shift on,  inc cursor move dir */
 
 /* display on/off, cursor on/off, blinking char at cursor position */
-#define LCD_DISP_OFF             0x08   /* display off                            */
-#define LCD_DISP_ON              0x0C   /* display on, cursor off                 */
-#define LCD_DISP_ON_BLINK        0x0D   /* display on, cursor off, blink char     */
-#define LCD_DISP_ON_CURSOR       0x0E   /* display on, cursor on                  */
-#define LCD_DISP_ON_CURSOR_BLINK 0x0F   /* display on, cursor on, blink char      */
+#define LCD_DISP_OFF 0x08             /* display off                            */
+#define LCD_DISP_ON 0x0C              /* display on, cursor off                 */
+#define LCD_DISP_ON_BLINK 0x0D        /* display on, cursor off, blink char     */
+#define LCD_DISP_ON_CURSOR 0x0E       /* display on, cursor on                  */
+#define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char      */
 
 /* move cursor/shift display */
-#define LCD_MOVE_CURSOR_LEFT     0x10   /* move cursor left  (decrement)          */
-#define LCD_MOVE_CURSOR_RIGHT    0x14   /* move cursor right (increment)          */
-#define LCD_MOVE_DISP_LEFT       0x18   /* shift display left                     */
-#define LCD_MOVE_DISP_RIGHT      0x1C   /* shift display right                    */
+#define LCD_MOVE_CURSOR_LEFT 0x10  /* move cursor left  (decrement)          */
+#define LCD_MOVE_CURSOR_RIGHT 0x14 /* move cursor right (increment)          */
+#define LCD_MOVE_DISP_LEFT 0x18    /* shift display left                     */
+#define LCD_MOVE_DISP_RIGHT 0x1C   /* shift display right                    */
 
 /* function set: set interface data length and number of display lines */
-#define LCD_FUNCTION_4BIT_1LINE  0x20   /* 4-bit interface, single line, 5x7 dots */
-#define LCD_FUNCTION_4BIT_2LINES 0x28   /* 4-bit interface, dual line,   5x7 dots */
-#define LCD_FUNCTION_8BIT_1LINE  0x30   /* 8-bit interface, single line, 5x7 dots */
-#define LCD_FUNCTION_8BIT_2LINES 0x38   /* 8-bit interface, dual line,   5x7 dots */
+#define LCD_FUNCTION_4BIT_1LINE 0x20  /* 4-bit interface, single line, 5x7 dots */
+#define LCD_FUNCTION_4BIT_2LINES 0x28 /* 4-bit interface, dual line,   5x7 dots */
+#define LCD_FUNCTION_8BIT_1LINE 0x30  /* 8-bit interface, single line, 5x7 dots */
+#define LCD_FUNCTION_8BIT_2LINES 0x38 /* 8-bit interface, dual line,   5x7 dots */
 
+#define LCD_MODE_DEFAULT ((1 << LCD_ENTRY_MODE) | (1 << LCD_ENTRY_INC))
 
-#define LCD_MODE_DEFAULT     ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC) )
-
-
-
-/** 
+/**
  *  @name Functions
  */
 
-
 /**
  @brief    Initialize display and select type of cursor
  @param    dispAttr \b LCD_DISP_OFF display off\n
                     \b LCD_DISP_ON display on, cursor off\n
                     \b LCD_DISP_ON_CURSOR display on, cursor on\n
-                    \b LCD_DISP_ON_CURSOR_BLINK display on, cursor on flashing             
+                    \b LCD_DISP_ON_CURSOR_BLINK display on, cursor on flashing
  @return  none
 */
 extern void lcd_init(uint8_t dispAttr);
 
-
 /**
  @brief    Clear display and set cursor to home position
  @return   none
 */
 extern void lcd_clrscr(void);
 
-
 /**
  @brief    Set cursor to home position
  @return   none
 */
 extern void lcd_home(void);
 
-
 /**
  @brief    Set cursor to specified position
+
  @param    x horizontal position\n (0: left most position)
  @param    y vertical position\n   (0: first line)
  @return   none
 */
 extern void lcd_gotoxy(uint8_t x, uint8_t y);
 
-
 /**
  @brief    Display character at current cursor position
- @param    c character to be displayed                                       
+ @param    c character to be displayed
  @return   none
 */
 extern void lcd_putc(char c);
 
-
 /**
  @brief    Display string without auto linefeed
- @param    s string to be displayed                                        
+ @param    s string to be displayed
  @return   none
 */
 extern void lcd_puts(const char *s);
 
-
 /**
  @brief    Display string from program memory without auto linefeed
- @param    progmem_s string from program memory be be displayed                                        
+ @param    progmem_s string from program memory be be displayed
  @return   none
  @see      lcd_puts_P
 */
 extern void lcd_puts_p(const char *progmem_s);
 
-
 /**
  @brief    Send LCD controller instruction command
  @param    cmd instruction to send to LCD controller, see HD44780 data sheet
@@ -349,23 +331,20 @@ extern void lcd_puts_p(const char *progmem_s);
 */
 extern void lcd_command(uint8_t cmd);
 
-
 /**
- @brief    Send data byte to LCD controller 
+ @brief    Send data byte to LCD controller
+
  Similar to lcd_putc(), but without interpreting LF
  @param    data byte to send to LCD controller, see HD44780 data sheet
  @return   none
 */
 extern void lcd_data(uint8_t data);
 
-
 /**
  @brief macros for automatically storing string constant in program memory
 */
-#define lcd_puts_P(__s)         lcd_puts_p(PSTR(__s))
+#define lcd_puts_P(__s) lcd_puts_p(PSTR(__s))
 
 /**@}*/
 
-#endif //LCD_H
-
+#endif  // LCD_H
old mode 100755 (executable)
new mode 100644 (file)
index 0acc246..5292443
 #include "wait.h"
 
 #ifndef F_SCL
-#  define F_SCL 400000UL  // SCL frequency
+#    define F_SCL 400000UL  // SCL frequency
 #endif
 #define Prescaler 1
 #define TWBR_val ((((F_CPU / F_SCL) / Prescaler) - 16) / 2)
 
 void i2c_init(void) {
-  TWSR = 0; /* no prescaler */
-  TWBR = (uint8_t)TWBR_val;
+    TWSR = 0; /* no prescaler */
+    TWBR = (uint8_t)TWBR_val;
 
-  #ifdef __AVR_ATmega32A__
-  // set pull-up resistors on I2C bus pins
-  PORTC |= 0b11;
+#ifdef __AVR_ATmega32A__
+    // set pull-up resistors on I2C bus pins
+    PORTC |= 0b11;
 
-  // enable TWI (two-wire interface)
-  TWCR |= (1 << TWEN);
+    // enable TWI (two-wire interface)
+    TWCR |= (1 << TWEN);
 
-  // enable TWI interrupt and slave address ACK
-  TWCR |= (1 << TWIE);
-  TWCR |= (1 << TWEA);
-  #endif
+    // enable TWI interrupt and slave address ACK
+    TWCR |= (1 << TWIE);
+    TWCR |= (1 << TWEA);
+#endif
 }
 
 i2c_status_t i2c_start(uint8_t address, uint16_t timeout) {
-  // reset TWI control register
-  TWCR = 0;
-  // transmit START condition
-  TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
-
-  uint16_t timeout_timer = timer_read();
-  while (!(TWCR & (1 << TWINT))) {
-    if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
-      return I2C_STATUS_TIMEOUT;
-    }
-  }
-
-  // check if the start condition was successfully transmitted
-  if (((TW_STATUS & 0xF8) != TW_START) && ((TW_STATUS & 0xF8) != TW_REP_START)) {
-    return I2C_STATUS_ERROR;
-  }
-
-  // load slave address into data register
-  TWDR = address;
-  // start transmission of address
-  TWCR = (1 << TWINT) | (1 << TWEN);
-
-  timeout_timer = timer_read();
-  while (!(TWCR & (1 << TWINT))) {
-    if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
-      return I2C_STATUS_TIMEOUT;
-    }
-  }
-
-  // check if the device has acknowledged the READ / WRITE mode
-  uint8_t twst = TW_STATUS & 0xF8;
-  if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
-    return I2C_STATUS_ERROR;
-  }
-
-  return I2C_STATUS_SUCCESS;
+    // reset TWI control register
+    TWCR = 0;
+    // transmit START condition
+    TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
+
+    uint16_t timeout_timer = timer_read();
+    while (!(TWCR & (1 << TWINT))) {
+        if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
+            return I2C_STATUS_TIMEOUT;
+        }
+    }
+
+    // check if the start condition was successfully transmitted
+    if (((TW_STATUS & 0xF8) != TW_START) && ((TW_STATUS & 0xF8) != TW_REP_START)) {
+        return I2C_STATUS_ERROR;
+    }
+
+    // load slave address into data register
+    TWDR = address;
+    // start transmission of address
+    TWCR = (1 << TWINT) | (1 << TWEN);
+
+    timeout_timer = timer_read();
+    while (!(TWCR & (1 << TWINT))) {
+        if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
+            return I2C_STATUS_TIMEOUT;
+        }
+    }
+
+    // check if the device has acknowledged the READ / WRITE mode
+    uint8_t twst = TW_STATUS & 0xF8;
+    if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
+        return I2C_STATUS_ERROR;
+    }
+
+    return I2C_STATUS_SUCCESS;
 }
 
 i2c_status_t i2c_write(uint8_t data, uint16_t timeout) {
-  // load data into data register
-  TWDR = data;
-  // start transmission of data
-  TWCR = (1 << TWINT) | (1 << TWEN);
-
-  uint16_t timeout_timer = timer_read();
-  while (!(TWCR & (1 << TWINT))) {
-    if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
-      return I2C_STATUS_TIMEOUT;
+    // load data into data register
+    TWDR = data;
+    // start transmission of data
+    TWCR = (1 << TWINT) | (1 << TWEN);
+
+    uint16_t timeout_timer = timer_read();
+    while (!(TWCR & (1 << TWINT))) {
+        if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
+            return I2C_STATUS_TIMEOUT;
+        }
     }
-  }
 
-  if ((TW_STATUS & 0xF8) != TW_MT_DATA_ACK) {
-    return I2C_STATUS_ERROR;
-  }
+    if ((TW_STATUS & 0xF8) != TW_MT_DATA_ACK) {
+        return I2C_STATUS_ERROR;
+    }
 
-  return I2C_STATUS_SUCCESS;
+    return I2C_STATUS_SUCCESS;
 }
 
 int16_t i2c_read_ack(uint16_t timeout) {
-  // start TWI module and acknowledge data after reception
-  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
-
-  uint16_t timeout_timer = timer_read();
-  while (!(TWCR & (1 << TWINT))) {
-    if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
-      return I2C_STATUS_TIMEOUT;
+    // start TWI module and acknowledge data after reception
+    TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
+
+    uint16_t timeout_timer = timer_read();
+    while (!(TWCR & (1 << TWINT))) {
+        if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
+            return I2C_STATUS_TIMEOUT;
+        }
     }
-  }
 
-  // return received data from TWDR
-  return TWDR;
+    // return received data from TWDR
+    return TWDR;
 }
 
 int16_t i2c_read_nack(uint16_t timeout) {
-  // start receiving without acknowledging reception
-  TWCR = (1 << TWINT) | (1 << TWEN);
-
-  uint16_t timeout_timer = timer_read();
-  while (!(TWCR & (1 << TWINT))) {
-    if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
-      return I2C_STATUS_TIMEOUT;
+    // start receiving without acknowledging reception
+    TWCR = (1 << TWINT) | (1 << TWEN);
+
+    uint16_t timeout_timer = timer_read();
+    while (!(TWCR & (1 << TWINT))) {
+        if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
+            return I2C_STATUS_TIMEOUT;
+        }
     }
-  }
 
-  // return received data from TWDR
-  return TWDR;
+    // return received data from TWDR
+    return TWDR;
 }
 
 i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout) {
-  i2c_status_t status = i2c_start(address | I2C_WRITE, timeout);
+    i2c_status_t status = i2c_start(address | I2C_WRITE, timeout);
 
-  for (uint16_t i = 0; i < length && status >= 0; i++) {
-    status = i2c_write(data[i], timeout);
-  }
+    for (uint16_t i = 0; i < length && status >= 0; i++) {
+        status = i2c_write(data[i], timeout);
+    }
 
-  i2c_stop();
+    i2c_stop();
 
-  return status;
+    return status;
 }
 
 i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout) {
-  i2c_status_t status = i2c_start(address | I2C_READ, timeout);
+    i2c_status_t status = i2c_start(address | I2C_READ, timeout);
 
-  for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
-    status = i2c_read_ack(timeout);
-    if (status >= 0) {
-      data[i] = status;
+    for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
+        status = i2c_read_ack(timeout);
+        if (status >= 0) {
+            data[i] = status;
+        }
     }
-  }
 
-  if (status >= 0) {
-    status = i2c_read_nack(timeout);
     if (status >= 0) {
-      data[(length - 1)] = status;
+        status = i2c_read_nack(timeout);
+        if (status >= 0) {
+            data[(length - 1)] = status;
+        }
     }
-  }
 
-  i2c_stop();
+    i2c_stop();
 
-  return (status < 0) ? status : I2C_STATUS_SUCCESS;
+    return (status < 0) ? status : I2C_STATUS_SUCCESS;
 }
 
 i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
-  i2c_status_t status = i2c_start(devaddr | 0x00, timeout);
-  if (status >= 0) {
-    status = i2c_write(regaddr, timeout);
+    i2c_status_t status = i2c_start(devaddr | 0x00, timeout);
+    if (status >= 0) {
+        status = i2c_write(regaddr, timeout);
 
-    for (uint16_t i = 0; i < length && status >= 0; i++) {
-      status = i2c_write(data[i], timeout);
+        for (uint16_t i = 0; i < length && status >= 0; i++) {
+            status = i2c_write(data[i], timeout);
+        }
     }
-  }
 
-  i2c_stop();
+    i2c_stop();
 
-  return status;
+    return status;
 }
 
 i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
-  i2c_status_t status = i2c_start(devaddr, timeout);
-  if (status < 0) {
-    goto error;
-  }
+    i2c_status_t status = i2c_start(devaddr, timeout);
+    if (status < 0) {
+        goto error;
+    }
 
-  status = i2c_write(regaddr, timeout);
-  if (status < 0) {
-    goto error;
-  }
+    status = i2c_write(regaddr, timeout);
+    if (status < 0) {
+        goto error;
+    }
 
-  status = i2c_start(devaddr | 0x01, timeout);
+    status = i2c_start(devaddr | 0x01, timeout);
 
-  for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
-    status = i2c_read_ack(timeout);
-    if (status >= 0) {
-      data[i] = status;
+    for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
+        status = i2c_read_ack(timeout);
+        if (status >= 0) {
+            data[i] = status;
+        }
     }
-  }
 
-  if (status >= 0) {
-    status = i2c_read_nack(timeout);
     if (status >= 0) {
-      data[(length - 1)] = status;
+        status = i2c_read_nack(timeout);
+        if (status >= 0) {
+            data[(length - 1)] = status;
+        }
     }
-  }
 
 error:
-  i2c_stop();
+    i2c_stop();
 
-  return (status < 0) ? status : I2C_STATUS_SUCCESS;
+    return (status < 0) ? status : I2C_STATUS_SUCCESS;
 }
 
 void i2c_stop(void) {
-  // transmit STOP condition
-  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
+    // transmit STOP condition
+    TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
 }
old mode 100755 (executable)
new mode 100644 (file)
index d681424..0a3b6c5
 typedef int16_t i2c_status_t;
 
 #define I2C_STATUS_SUCCESS (0)
-#define I2C_STATUS_ERROR   (-1)
+#define I2C_STATUS_ERROR (-1)
 #define I2C_STATUS_TIMEOUT (-2)
 
 #define I2C_TIMEOUT_IMMEDIATE (0)
 #define I2C_TIMEOUT_INFINITE (0xFFFF)
 
-void i2c_init(void);
+void         i2c_init(void);
 i2c_status_t i2c_start(uint8_t address, uint16_t timeout);
 i2c_status_t i2c_write(uint8_t data, uint16_t timeout);
-int16_t i2c_read_ack(uint16_t timeout);
-int16_t i2c_read_nack(uint16_t timeout);
+int16_t      i2c_read_ack(uint16_t timeout);
+int16_t      i2c_read_nack(uint16_t timeout);
 i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout);
 i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
 i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
 i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
-void i2c_stop(void);
+void         i2c_stop(void);
 
-#endif // I2C_MASTER_H
+#endif  // I2C_MASTER_H
old mode 100755 (executable)
new mode 100644 (file)
index 4958a0f..3fb684f
 volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT];
 
 static volatile uint8_t buffer_address;
-static volatile bool slave_has_register_set = false;
+static volatile bool    slave_has_register_set = false;
 
-void i2c_slave_init(uint8_t address){
+void i2c_slave_init(uint8_t address) {
     // load address into TWI address register
     TWAR = address;
     // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt
     TWCR = (1 << TWIE) | (1 << TWEA) | (1 << TWINT) | (1 << TWEN);
 }
 
-void i2c_slave_stop(void){
+void i2c_slave_stop(void) {
     // clear acknowledge and enable bits
     TWCR &= ~((1 << TWEA) | (1 << TWEN));
 }
 
-ISR(TWI_vect){
+ISR(TWI_vect) {
     uint8_t ack = 1;
 
-    switch(TW_STATUS){
+    switch (TW_STATUS) {
         case TW_SR_SLA_ACK:
             // The device is now a slave receiver
             slave_has_register_set = false;
@@ -53,14 +53,14 @@ ISR(TWI_vect){
         case TW_SR_DATA_ACK:
             // This device is a slave receiver and has received data
             // First byte is the location then the bytes will be writen in buffer with auto-incriment
-            if(!slave_has_register_set){
+            if (!slave_has_register_set) {
                 buffer_address = TWDR;
 
                 if (buffer_address >= I2C_SLAVE_REG_COUNT) {  // address out of bounds dont ack
-                  ack            = 0;
-                  buffer_address = 0;
+                    ack            = 0;
+                    buffer_address = 0;
                 }
-                slave_has_register_set = true; // address has been receaved now fill in buffer
+                slave_has_register_set = true;  // address has been receaved now fill in buffer
             } else {
                 i2c_slave_reg[buffer_address] = TWDR;
                 buffer_address++;
old mode 100755 (executable)
new mode 100644 (file)
index 2f4589e..5ed0b11
@@ -30,4 +30,4 @@ extern volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT];
 void i2c_slave_init(uint8_t address);
 void i2c_slave_stop(void);
 
-#endif // I2C_SLAVE_H
+#endif  // I2C_SLAVE_H
index f9e7ed75d9d5b6e878d4b279d5f23a5771329412..762a99a058aa868098a83669b104d46a0faecf48 100644 (file)
 #undef OCR2_6
 #undef OCR2_7
 
-#define NUM_DIGITAL_PINS  30
+#define NUM_DIGITAL_PINS 30
 #define NUM_ANALOG_INPUTS 12
 
-#define TX_RX_LED_INIT  DDRD |= (1<<5), DDRB |= (1<<0)
-#define TXLED0          PORTD |= (1<<5)
-#define TXLED1          PORTD &= ~(1<<5)
-#define RXLED0          PORTB |= (1<<0)
-#define RXLED1          PORTB &= ~(1<<0)
+#define TX_RX_LED_INIT DDRD |= (1 << 5), DDRB |= (1 << 0)
+#define TXLED0 PORTD |= (1 << 5)
+#define TXLED1 PORTD &= ~(1 << 5)
+#define RXLED0 PORTB |= (1 << 0)
+#define RXLED1 PORTB &= ~(1 << 0)
 
 static const uint8_t SDA = 2;
 static const uint8_t SCL = 3;
@@ -111,27 +111,27 @@ static const uint8_t SCK  = 15;
 
 // Mapping of analog pins as digital I/O
 // A6-A11 share with digital pins
-static const uint8_t ADC0 = 18;
-static const uint8_t ADC1 = 19;
-static const uint8_t ADC2 = 20;
-static const uint8_t ADC3 = 21;
-static const uint8_t ADC4 = 22;
-static const uint8_t ADC5 = 23;
-static const uint8_t ADC6 = 24;   // D4
-static const uint8_t ADC7 = 25;   // D6
-static const uint8_t ADC8 = 26;   // D8
-static const uint8_t ADC9 = 27;   // D9
+static const uint8_t ADC0  = 18;
+static const uint8_t ADC1  = 19;
+static const uint8_t ADC2  = 20;
+static const uint8_t ADC3  = 21;
+static const uint8_t ADC4  = 22;
+static const uint8_t ADC5  = 23;
+static const uint8_t ADC6  = 24;  // D4
+static const uint8_t ADC7  = 25;  // D6
+static const uint8_t ADC8  = 26;  // D8
+static const uint8_t ADC9  = 27;  // D9
 static const uint8_t ADC10 = 28;  // D10
 static const uint8_t ADC11 = 29;  // D12
 
-#define digitalPinToPCICR(p)    ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0))
+#define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0))
 #define digitalPinToPCICRbit(p) 0
-#define digitalPinToPCMSK(p)    ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0))
-#define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4))))))
+#define digitalPinToPCMSK(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0))
+#define digitalPinToPCMSKbit(p) (((p) >= 8 && (p) <= 11) ? (p)-4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4))))))
 
 //  __AVR_ATmega32U4__ has an unusual mapping of pins to channels
 extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
-#define analogPinToChannel(P)  ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
+#define analogPinToChannel(P) (pgm_read_byte(analog_pin_to_channel_PGM + (P)))
 
 #define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
 
@@ -182,159 +182,121 @@ extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
 // appropriate addresses for various functions (e.g. reading
 // and writing)
 const uint16_t PROGMEM port_to_mode_PGM[] = {
-    NOT_A_PORT,
-    NOT_A_PORT,
-    (uint16_t) &DDRB,
-    (uint16_t) &DDRC,
-    (uint16_t) &DDRD,
-    (uint16_t) &DDRE,
-    (uint16_t) &DDRF,
+    NOT_A_PORT, NOT_A_PORT, (uint16_t)&DDRB, (uint16_t)&DDRC, (uint16_t)&DDRD, (uint16_t)&DDRE, (uint16_t)&DDRF,
 };
 
 const uint16_t PROGMEM port_to_output_PGM[] = {
-    NOT_A_PORT,
-    NOT_A_PORT,
-    (uint16_t) &PORTB,
-    (uint16_t) &PORTC,
-    (uint16_t) &PORTD,
-    (uint16_t) &PORTE,
-    (uint16_t) &PORTF,
+    NOT_A_PORT, NOT_A_PORT, (uint16_t)&PORTB, (uint16_t)&PORTC, (uint16_t)&PORTD, (uint16_t)&PORTE, (uint16_t)&PORTF,
 };
 
 const uint16_t PROGMEM port_to_input_PGM[] = {
-    NOT_A_PORT,
-    NOT_A_PORT,
-    (uint16_t) &PINB,
-    (uint16_t) &PINC,
-    (uint16_t) &PIND,
-    (uint16_t) &PINE,
-    (uint16_t) &PINF,
+    NOT_A_PORT, NOT_A_PORT, (uint16_t)&PINB, (uint16_t)&PINC, (uint16_t)&PIND, (uint16_t)&PINE, (uint16_t)&PINF,
 };
 
 const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
-    PD, // D0 - PD2
-    PD, // D1 - PD3
-    PD, // D2 - PD1
-    PD, // D3 - PD0
-    PD, // D4 - PD4
-    PC, // D5 - PC6
-    PD, // D6 - PD7
-    PE, // D7 - PE6
-
-    PB, // D8 - PB4
-    PB, // D9 - PB5
-    PB, // D10 - PB6
-    PB, // D11 - PB7
-    PD, // D12 - PD6
-    PC, // D13 - PC7
-
-    PB, // D14 - MISO - PB3
-    PB, // D15 - SCK - PB1
-    PB, // D16 - MOSI - PB2
-    PB, // D17 - SS - PB0
-
-    PF, // D18 - A0 - PF7
-    PF, // D19 - A1 - PF6
-    PF, // D20 - A2 - PF5
-    PF, // D21 - A3 - PF4
-    PF, // D22 - A4 - PF1
-    PF, // D23 - A5 - PF0
-
-    PD, // D24 - PD5
-    PD, // D25 / D6 - A7 - PD7
-    PB, // D26 / D8 - A8 - PB4
-    PB, // D27 / D9 - A9 - PB5
-    PB, // D28 / D10 - A10 - PB6
-    PD, // D29 / D12 - A11 - PD6
+    PD,  // D0 - PD2
+    PD,  // D1 - PD3
+    PD,  // D2 - PD1
+    PD,  // D3 - PD0
+    PD,  // D4 - PD4
+    PC,  // D5 - PC6
+    PD,  // D6 - PD7
+    PE,  // D7 - PE6
+
+    PB,  // D8 - PB4
+    PB,  // D9 - PB5
+    PB,  // D10 - PB6
+    PB,  // D11 - PB7
+    PD,  // D12 - PD6
+    PC,  // D13 - PC7
+
+    PB,  // D14 - MISO - PB3
+    PB,  // D15 - SCK - PB1
+    PB,  // D16 - MOSI - PB2
+    PB,  // D17 - SS - PB0
+
+    PF,  // D18 - A0 - PF7
+    PF,  // D19 - A1 - PF6
+    PF,  // D20 - A2 - PF5
+    PF,  // D21 - A3 - PF4
+    PF,  // D22 - A4 - PF1
+    PF,  // D23 - A5 - PF0
+
+    PD,  // D24 - PD5
+    PD,  // D25 / D6 - A7 - PD7
+    PB,  // D26 / D8 - A8 - PB4
+    PB,  // D27 / D9 - A9 - PB5
+    PB,  // D28 / D10 - A10 - PB6
+    PD,  // D29 / D12 - A11 - PD6
 };
 
 const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
-    _BV(2), // D0 - PD2
-    _BV(3), // D1 - PD3
-    _BV(1), // D2 - PD1
-    _BV(0), // D3 - PD0
-    _BV(4), // D4 - PD4
-    _BV(6), // D5 - PC6
-    _BV(7), // D6 - PD7
-    _BV(6), // D7 - PE6
-
-    _BV(4), // D8 - PB4
-    _BV(5), // D9 - PB5
-    _BV(6), // D10 - PB6
-    _BV(7), // D11 - PB7
-    _BV(6), // D12 - PD6
-    _BV(7), // D13 - PC7
-
-    _BV(3), // D14 - MISO - PB3
-    _BV(1), // D15 - SCK - PB1
-    _BV(2), // D16 - MOSI - PB2
-    _BV(0), // D17 - SS - PB0
-
-    _BV(7), // D18 - A0 - PF7
-    _BV(6), // D19 - A1 - PF6
-    _BV(5), // D20 - A2 - PF5
-    _BV(4), // D21 - A3 - PF4
-    _BV(1), // D22 - A4 - PF1
-    _BV(0), // D23 - A5 - PF0
-
-    _BV(5), // D24 - PD5
-    _BV(7), // D25 / D6 - A7 - PD7
-    _BV(4), // D26 / D8 - A8 - PB4
-    _BV(5), // D27 / D9 - A9 - PB5
-    _BV(6), // D28 / D10 - A10 - PB6
-    _BV(6), // D29 / D12 - A11 - PD6
+    _BV(2),  // D0 - PD2
+    _BV(3),  // D1 - PD3
+    _BV(1),  // D2 - PD1
+    _BV(0),  // D3 - PD0
+    _BV(4),  // D4 - PD4
+    _BV(6),  // D5 - PC6
+    _BV(7),  // D6 - PD7
+    _BV(6),  // D7 - PE6
+
+    _BV(4),  // D8 - PB4
+    _BV(5),  // D9 - PB5
+    _BV(6),  // D10 - PB6
+    _BV(7),  // D11 - PB7
+    _BV(6),  // D12 - PD6
+    _BV(7),  // D13 - PC7
+
+    _BV(3),  // D14 - MISO - PB3
+    _BV(1),  // D15 - SCK - PB1
+    _BV(2),  // D16 - MOSI - PB2
+    _BV(0),  // D17 - SS - PB0
+
+    _BV(7),  // D18 - A0 - PF7
+    _BV(6),  // D19 - A1 - PF6
+    _BV(5),  // D20 - A2 - PF5
+    _BV(4),  // D21 - A3 - PF4
+    _BV(1),  // D22 - A4 - PF1
+    _BV(0),  // D23 - A5 - PF0
+
+    _BV(5),  // D24 - PD5
+    _BV(7),  // D25 / D6 - A7 - PD7
+    _BV(4),  // D26 / D8 - A8 - PB4
+    _BV(5),  // D27 / D9 - A9 - PB5
+    _BV(6),  // D28 / D10 - A10 - PB6
+    _BV(6),  // D29 / D12 - A11 - PD6
 };
 
 const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    TIMER0B,        /* 3 */
-    NOT_ON_TIMER,
-    TIMER3A,        /* 5 */
-    TIMER4D,        /* 6 */
+    NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, TIMER0B, /* 3 */
+    NOT_ON_TIMER, TIMER3A,                             /* 5 */
+    TIMER4D,                                           /* 6 */
     NOT_ON_TIMER,
 
-    NOT_ON_TIMER,
-    TIMER1A,        /* 9 */
-    TIMER1B,        /* 10 */
-    TIMER0A,        /* 11 */
+    NOT_ON_TIMER, TIMER1A, /* 9 */
+    TIMER1B,               /* 10 */
+    TIMER0A,               /* 11 */
 
-    NOT_ON_TIMER,
-    TIMER4A,        /* 13 */
+    NOT_ON_TIMER, TIMER4A, /* 13 */
 
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
+    NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER,
 
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
-    NOT_ON_TIMER,
+    NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER,
 };
 
 const uint8_t PROGMEM analog_pin_to_channel_PGM[] = {
-    7,  // A0               PF7                 ADC7
-    6,  // A1               PF6                 ADC6
-    5,  // A2               PF5                 ADC5
-    4,  // A3               PF4                 ADC4
-    1,  // A4               PF1                 ADC1
-    0,  // A5               PF0                 ADC0
-    8,  // A6       D4      PD4                 ADC8
-    10, // A7       D6      PD7                 ADC10
-    11, // A8       D8      PB4                 ADC11
-    12, // A9       D9      PB5                 ADC12
-    13, // A10      D10     PB6                 ADC13
-    9   // A11      D12     PD6                 ADC9
+    7,   // A0               PF7                 ADC7
+    6,   // A1               PF6                 ADC6
+    5,   // A2               PF5                 ADC5
+    4,   // A3               PF4                 ADC4
+    1,   // A4               PF1                 ADC1
+    0,   // A5               PF0                 ADC0
+    8,   // A6       D4      PD4                 ADC8
+    10,  // A7       D6      PD7                 ADC10
+    11,  // A8       D8      PB4                 ADC11
+    12,  // A9       D9      PB5                 ADC12
+    13,  // A10      D10     PB6                 ADC13
+    9    // A11      D12     PD6                 ADC9
 };
 
 #endif /* ARDUINO_MAIN */
@@ -354,9 +316,9 @@ const uint8_t PROGMEM analog_pin_to_channel_PGM[] = {
 //
 // SERIAL_PORT_HARDWARE_OPEN  Hardware serial ports which are open for use.  Their RX & TX
 //                            pins are NOT connected to anything by default.
-#define SERIAL_PORT_MONITOR        Serial
-#define SERIAL_PORT_USBVIRTUAL     Serial
-#define SERIAL_PORT_HARDWARE       Serial1
-#define SERIAL_PORT_HARDWARE_OPEN  Serial1
+#define SERIAL_PORT_MONITOR Serial
+#define SERIAL_PORT_USBVIRTUAL Serial
+#define SERIAL_PORT_HARDWARE Serial1
+#define SERIAL_PORT_HARDWARE_OPEN Serial1
 
 #endif /* Pins_Arduino_h */
index bb8938bba3a5e1d7f61745ad1e0cd5e16f5e9cfc..61d7a99531133deb4cb6aaa0931c85652cdf9f9b 100644 (file)
 #ifdef SSD1306OLED
 
-#include "ssd1306.h"
-#include "i2c.h"
-#include <string.h>
-#include "print.h"
-#include "glcdfont.c"
-#ifdef ADAFRUIT_BLE_ENABLE
-#include "adafruit_ble.h"
-#endif
-#ifdef PROTOCOL_LUFA
-#include "lufa.h"
-#endif
-#include "sendchar.h"
-#include "timer.h"
+#    include "ssd1306.h"
+#    include "i2c.h"
+#    include <string.h>
+#    include "print.h"
+#    include "glcdfont.c"
+#    ifdef ADAFRUIT_BLE_ENABLE
+#        include "adafruit_ble.h"
+#    endif
+#    ifdef PROTOCOL_LUFA
+#        include "lufa.h"
+#    endif
+#    include "sendchar.h"
+#    include "timer.h"
 
 // Set this to 1 to help diagnose early startup problems
 // when testing power-on with ble.  Turn it off otherwise,
 // as the latency of printing most of the debug info messes
 // with the matrix scan, causing keys to drop.
-#define DEBUG_TO_SCREEN 0
+#    define DEBUG_TO_SCREEN 0
 
-//static uint16_t last_battery_update;
-//static uint32_t vbat;
+// static uint16_t last_battery_update;
+// static uint32_t vbat;
 //#define BatteryUpdateInterval 10000 /* milliseconds */
-#define ScreenOffInterval 300000 /* milliseconds */
-#if DEBUG_TO_SCREEN
+#    define ScreenOffInterval 300000 /* milliseconds */
+#    if DEBUG_TO_SCREEN
 static uint8_t displaying;
-#endif
+#    endif
 static uint16_t last_flush;
 
 // Write command sequence.
 // Returns true on success.
 static inline bool _send_cmd1(uint8_t cmd) {
-  bool res = false;
+    bool res = false;
 
-  if (i2c_start_write(SSD1306_ADDRESS)) {
-    xprintf("failed to start write to %d\n", SSD1306_ADDRESS);
-    goto done;
-  }
+    if (i2c_start_write(SSD1306_ADDRESS)) {
+        xprintf("failed to start write to %d\n", SSD1306_ADDRESS);
+        goto done;
+    }
 
-  if (i2c_master_write(0x0 /* command byte follows */)) {
-    print("failed to write control byte\n");
+    if (i2c_master_write(0x0 /* command byte follows */)) {
+        print("failed to write control byte\n");
 
-    goto done;
-  }
+        goto done;
+    }
 
-  if (i2c_master_write(cmd)) {
-    xprintf("failed to write command %d\n", cmd);
-    goto done;
-  }
-  res = true;
+    if (i2c_master_write(cmd)) {
+        xprintf("failed to write command %d\n", cmd);
+        goto done;
+    }
+    res = true;
 done:
-  i2c_master_stop();
-  return res;
+    i2c_master_stop();
+    return res;
 }
 
 // Write 2-byte command sequence.
 // Returns true on success
 static inline bool _send_cmd2(uint8_t cmd, uint8_t opr) {
-  if (!_send_cmd1(cmd)) {
-    return false;
-  }
-  return _send_cmd1(opr);
+    if (!_send_cmd1(cmd)) {
+        return false;
+    }
+    return _send_cmd1(opr);
 }
 
 // Write 3-byte command sequence.
 // Returns true on success
 static inline bool _send_cmd3(uint8_t cmd, uint8_t opr1, uint8_t opr2) {
-  if (!_send_cmd1(cmd)) {
-    return false;
-  }
-  if (!_send_cmd1(opr1)) {
-    return false;
-  }
-  return _send_cmd1(opr2);
+    if (!_send_cmd1(cmd)) {
+        return false;
+    }
+    if (!_send_cmd1(opr1)) {
+        return false;
+    }
+    return _send_cmd1(opr2);
 }
 
-#define send_cmd1(c) if (!_send_cmd1(c)) {goto done;}
-#define send_cmd2(c,o) if (!_send_cmd2(c,o)) {goto done;}
-#define send_cmd3(c,o1,o2) if (!_send_cmd3(c,o1,o2)) {goto done;}
+#    define send_cmd1(c)      \
+        if (!_send_cmd1(c)) { \
+            goto done;        \
+        }
+#    define send_cmd2(c, o)      \
+        if (!_send_cmd2(c, o)) { \
+            goto done;           \
+        }
+#    define send_cmd3(c, o1, o2)      \
+        if (!_send_cmd3(c, o1, o2)) { \
+            goto done;                \
+        }
 
 static void clear_display(void) {
-  matrix_clear(&display);
-
-  // Clear all of the display bits (there can be random noise
-  // in the RAM on startup)
-  send_cmd3(PageAddr, 0, (DisplayHeight / 8) - 1);
-  send_cmd3(ColumnAddr, 0, DisplayWidth - 1);
-
-  if (i2c_start_write(SSD1306_ADDRESS)) {
-    goto done;
-  }
-  if (i2c_master_write(0x40)) {
-    // Data mode
-    goto done;
-  }
-  for (uint8_t row = 0; row < MatrixRows; ++row) {
-    for (uint8_t col = 0; col < DisplayWidth; ++col) {
-      i2c_master_write(0);
+    matrix_clear(&display);
+
+    // Clear all of the display bits (there can be random noise
+    // in the RAM on startup)
+    send_cmd3(PageAddr, 0, (DisplayHeight / 8) - 1);
+    send_cmd3(ColumnAddr, 0, DisplayWidth - 1);
+
+    if (i2c_start_write(SSD1306_ADDRESS)) {
+        goto done;
+    }
+    if (i2c_master_write(0x40)) {
+        // Data mode
+        goto done;
+    }
+    for (uint8_t row = 0; row < MatrixRows; ++row) {
+        for (uint8_t col = 0; col < DisplayWidth; ++col) {
+            i2c_master_write(0);
+        }
     }
-  }
 
-  display.dirty = false;
+    display.dirty = false;
 
 done:
-  i2c_master_stop();
+    i2c_master_stop();
 }
 
-#if DEBUG_TO_SCREEN
-#undef sendchar
+#    if DEBUG_TO_SCREEN
+#        undef sendchar
 static int8_t capture_sendchar(uint8_t c) {
-  sendchar(c);
-  iota_gfx_write_char(c);
+    sendchar(c);
+    iota_gfx_write_char(c);
 
-  if (!displaying) {
-    iota_gfx_flush();
-  }
-  return 0;
+    if (!displaying) {
+        iota_gfx_flush();
+    }
+    return 0;
 }
-#endif
+#    endif
 
 bool iota_gfx_init(void) {
-  bool success = false;
+    bool success = false;
 
-  send_cmd1(DisplayOff);
-  send_cmd2(SetDisplayClockDiv, 0x80);
-  send_cmd2(SetMultiPlex, DisplayHeight - 1);
+    send_cmd1(DisplayOff);
+    send_cmd2(SetDisplayClockDiv, 0x80);
+    send_cmd2(SetMultiPlex, DisplayHeight - 1);
 
-  send_cmd2(SetDisplayOffset, 0);
+    send_cmd2(SetDisplayOffset, 0);
 
+    send_cmd1(SetStartLine | 0x0);
+    send_cmd2(SetChargePump, 0x14 /* Enable */);
+    send_cmd2(SetMemoryMode, 0 /* horizontal addressing */);
 
-  send_cmd1(SetStartLine | 0x0);
-  send_cmd2(SetChargePump, 0x14 /* Enable */);
-  send_cmd2(SetMemoryMode, 0 /* horizontal addressing */);
+#    ifdef OLED_ROTATE180
+    // the following Flip the display orientation 180 degrees
+    send_cmd1(SegRemap);
+    send_cmd1(ComScanInc);
+#    endif
+#    ifndef OLED_ROTATE180
+    // Flips the display orientation 0 degrees
+    send_cmd1(SegRemap | 0x1);
+    send_cmd1(ComScanDec);
+#    endif
 
-#ifdef OLED_ROTATE180
-// the following Flip the display orientation 180 degrees
-  send_cmd1(SegRemap);
-  send_cmd1(ComScanInc);
-#endif
-#ifndef OLED_ROTATE180
-// Flips the display orientation 0 degrees
-  send_cmd1(SegRemap | 0x1);
-  send_cmd1(ComScanDec);
-#endif
-  
-  send_cmd2(SetComPins, 0x2);
-  send_cmd2(SetContrast, 0x8f);
-  send_cmd2(SetPreCharge, 0xf1);
-  send_cmd2(SetVComDetect, 0x40);
-  send_cmd1(DisplayAllOnResume);
-  send_cmd1(NormalDisplay);
-  send_cmd1(DeActivateScroll);
-  send_cmd1(DisplayOn);
+    send_cmd2(SetComPins, 0x2);
+    send_cmd2(SetContrast, 0x8f);
+    send_cmd2(SetPreCharge, 0xf1);
+    send_cmd2(SetVComDetect, 0x40);
+    send_cmd1(DisplayAllOnResume);
+    send_cmd1(NormalDisplay);
+    send_cmd1(DeActivateScroll);
+    send_cmd1(DisplayOn);
 
-  send_cmd2(SetContrast, 0); // Dim
+    send_cmd2(SetContrast, 0);  // Dim
 
-  clear_display();
+    clear_display();
 
-  success = true;
+    success = true;
 
-  iota_gfx_flush();
+    iota_gfx_flush();
 
-#if DEBUG_TO_SCREEN
-  print_set_sendchar(capture_sendchar);
-#endif
+#    if DEBUG_TO_SCREEN
+    print_set_sendchar(capture_sendchar);
+#    endif
 
 done:
-  return success;
+    return success;
 }
 
 bool iota_gfx_off(void) {
-  bool success = false;
+    bool success = false;
 
-  send_cmd1(DisplayOff);
-  success = true;
+    send_cmd1(DisplayOff);
+    success = true;
 
 done:
-  return success;
-} 
+    return success;
+}
 
 bool iota_gfx_on(void) {
-  bool success = false;
+    bool success = false;
 
-  send_cmd1(DisplayOn);
-  success = true;
+    send_cmd1(DisplayOn);
+    success = true;
 
 done:
-  return success;
+    return success;
 }
 
 void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c) {
-  *matrix->cursor = c;
-  ++matrix->cursor;
-
-  if (matrix->cursor - &matrix->display[0][0] == sizeof(matrix->display)) {
-    // We went off the end; scroll the display upwards by one line
-    memmove(&matrix->display[0], &matrix->display[1],
-            MatrixCols * (MatrixRows - 1));
-    matrix->cursor = &matrix->display[MatrixRows - 1][0];
-    memset(matrix->cursor, ' ', MatrixCols);
-  }
+    *matrix->cursor = c;
+    ++matrix->cursor;
+
+    if (matrix->cursor - &matrix->display[0][0] == sizeof(matrix->display)) {
+        // We went off the end; scroll the display upwards by one line
+        memmove(&matrix->display[0], &matrix->display[1], MatrixCols * (MatrixRows - 1));
+        matrix->cursor = &matrix->display[MatrixRows - 1][0];
+        memset(matrix->cursor, ' ', MatrixCols);
+    }
 }
 
 void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c) {
-  matrix->dirty = true;
+    matrix->dirty = true;
 
-  if (c == '\n') {
-    // Clear to end of line from the cursor and then move to the
-    // start of the next line
-    uint8_t cursor_col = (matrix->cursor - &matrix->display[0][0]) % MatrixCols;
+    if (c == '\n') {
+        // Clear to end of line from the cursor and then move to the
+        // start of the next line
+        uint8_t cursor_col = (matrix->cursor - &matrix->display[0][0]) % MatrixCols;
 
-    while (cursor_col++ < MatrixCols) {
-      matrix_write_char_inner(matrix, ' ');
+        while (cursor_col++ < MatrixCols) {
+            matrix_write_char_inner(matrix, ' ');
+        }
+        return;
     }
-    return;
-  }
 
-  matrix_write_char_inner(matrix, c);
+    matrix_write_char_inner(matrix, c);
 }
 
-void iota_gfx_write_char(uint8_t c) {
-  matrix_write_char(&display, c);
-}
+void iota_gfx_write_char(uint8_t c) { matrix_write_char(&display, c); }
 
 void matrix_write(struct CharacterMatrix *matrix, const char *data) {
-  const char *end = data + strlen(data);
-  while (data < end) {
-    matrix_write_char(matrix, *data);
-    ++data;
-  }
+    const char *end = data + strlen(data);
+    while (data < end) {
+        matrix_write_char(matrix, *data);
+        ++data;
+    }
 }
 
-void iota_gfx_write(const char *data) {
-  matrix_write(&display, data);
-}
+void iota_gfx_write(const char *data) { matrix_write(&display, data); }
 
 void matrix_write_P(struct CharacterMatrix *matrix, const char *data) {
-  while (true) {
-    uint8_t c = pgm_read_byte(data);
-    if (c == 0) {
-      return;
+    while (true) {
+        uint8_t c = pgm_read_byte(data);
+        if (c == 0) {
+            return;
+        }
+        matrix_write_char(matrix, c);
+        ++data;
     }
-    matrix_write_char(matrix, c);
-    ++data;
-  }
 }
 
-void iota_gfx_write_P(const char *data) {
-  matrix_write_P(&display, data);
-}
+void iota_gfx_write_P(const char *data) { matrix_write_P(&display, data); }
 
 void matrix_clear(struct CharacterMatrix *matrix) {
-  memset(matrix->display, ' ', sizeof(matrix->display));
-  matrix->cursor = &matrix->display[0][0];
-  matrix->dirty = true;
+    memset(matrix->display, ' ', sizeof(matrix->display));
+    matrix->cursor = &matrix->display[0][0];
+    matrix->dirty  = true;
 }
 
-void iota_gfx_clear_screen(void) {
-  matrix_clear(&display);
-}
+void iota_gfx_clear_screen(void) { matrix_clear(&display); }
 
 void matrix_render(struct CharacterMatrix *matrix) {
-  last_flush = timer_read();
-  iota_gfx_on();
-#if DEBUG_TO_SCREEN
-  ++displaying;
-#endif
+    last_flush = timer_read();
+    iota_gfx_on();
+#    if DEBUG_TO_SCREEN
+    ++displaying;
+#    endif
+
+    // Move to the home position
+    send_cmd3(PageAddr, 0, MatrixRows - 1);
+    send_cmd3(ColumnAddr, 0, (MatrixCols * FontWidth) - 1);
+
+    if (i2c_start_write(SSD1306_ADDRESS)) {
+        goto done;
+    }
+    if (i2c_master_write(0x40)) {
+        // Data mode
+        goto done;
+    }
+
+    for (uint8_t row = 0; row < MatrixRows; ++row) {
+        for (uint8_t col = 0; col < MatrixCols; ++col) {
+            const uint8_t *glyph = font + (matrix->display[row][col] * (FontWidth - 1));
+
+            for (uint8_t glyphCol = 0; glyphCol < FontWidth - 1; ++glyphCol) {
+                uint8_t colBits = pgm_read_byte(glyph + glyphCol);
+                i2c_master_write(colBits);
+            }
 
-  // Move to the home position
-  send_cmd3(PageAddr, 0, MatrixRows - 1);
-  send_cmd3(ColumnAddr, 0, (MatrixCols * FontWidth) - 1);
-
-  if (i2c_start_write(SSD1306_ADDRESS)) {
-    goto done;
-  }
-  if (i2c_master_write(0x40)) {
-    // Data mode
-    goto done;
-  }
-
-  for (uint8_t row = 0; row < MatrixRows; ++row) {
-    for (uint8_t col = 0; col < MatrixCols; ++col) {
-      const uint8_t *glyph = font + (matrix->display[row][col] * (FontWidth - 1));
-
-      for (uint8_t glyphCol = 0; glyphCol < FontWidth - 1; ++glyphCol) {
-        uint8_t colBits = pgm_read_byte(glyph + glyphCol);
-        i2c_master_write(colBits);
-      }
-
-      // 1 column of space between chars (it's not included in the glyph)
-      i2c_master_write(0);
+            // 1 column of space between chars (it's not included in the glyph)
+            i2c_master_write(0);
+        }
     }
-  }
 
-  matrix->dirty = false;
+    matrix->dirty = false;
 
 done:
-  i2c_master_stop();
-#if DEBUG_TO_SCREEN
-  --displaying;
-#endif
+    i2c_master_stop();
+#    if DEBUG_TO_SCREEN
+    --displaying;
+#    endif
 }
 
-void iota_gfx_flush(void) {
-  matrix_render(&display);
-}
+void iota_gfx_flush(void) { matrix_render(&display); }
 
-__attribute__ ((weak))
-void iota_gfx_task_user(void) {
-}
+__attribute__((weak)) void iota_gfx_task_user(void) {}
 
 void iota_gfx_task(void) {
-  iota_gfx_task_user();
+    iota_gfx_task_user();
 
-  if (display.dirty) {
-    iota_gfx_flush();
-  }
+    if (display.dirty) {
+        iota_gfx_flush();
+    }
 
-  if (timer_elapsed(last_flush) > ScreenOffInterval) {
-    iota_gfx_off();
-  }
+    if (timer_elapsed(last_flush) > ScreenOffInterval) {
+        iota_gfx_off();
+    }
 }
 #endif
index df6a75359febc12d07f305e5ef8255c982088d71..825b0d7d5b6722dc3fc143089c378783e09238b7 100644 (file)
@@ -7,49 +7,49 @@
 #include "config.h"
 
 enum ssd1306_cmds {
-  DisplayOff = 0xAE,
-  DisplayOn = 0xAF,
-
-  SetContrast = 0x81,
-  DisplayAllOnResume = 0xA4,
-
-  DisplayAllOn = 0xA5,
-  NormalDisplay = 0xA6,
-  InvertDisplay = 0xA7,
-  SetDisplayOffset = 0xD3,
-  SetComPins = 0xda,
-  SetVComDetect = 0xdb,
-  SetDisplayClockDiv = 0xD5,
-  SetPreCharge = 0xd9,
-  SetMultiPlex = 0xa8,
-  SetLowColumn = 0x00,
-  SetHighColumn = 0x10,
-  SetStartLine = 0x40,
-
-  SetMemoryMode = 0x20,
-  ColumnAddr = 0x21,
-  PageAddr = 0x22,
-
-  ComScanInc = 0xc0,
-  ComScanDec = 0xc8,
-  SegRemap = 0xa0,
-  SetChargePump = 0x8d,
-  ExternalVcc = 0x01,
-  SwitchCapVcc = 0x02,
-
-  ActivateScroll = 0x2f,
-  DeActivateScroll = 0x2e,
-  SetVerticalScrollArea = 0xa3,
-  RightHorizontalScroll = 0x26,
-  LeftHorizontalScroll = 0x27,
-  VerticalAndRightHorizontalScroll = 0x29,
-  VerticalAndLeftHorizontalScroll = 0x2a,
+    DisplayOff = 0xAE,
+    DisplayOn  = 0xAF,
+
+    SetContrast        = 0x81,
+    DisplayAllOnResume = 0xA4,
+
+    DisplayAllOn       = 0xA5,
+    NormalDisplay      = 0xA6,
+    InvertDisplay      = 0xA7,
+    SetDisplayOffset   = 0xD3,
+    SetComPins         = 0xda,
+    SetVComDetect      = 0xdb,
+    SetDisplayClockDiv = 0xD5,
+    SetPreCharge       = 0xd9,
+    SetMultiPlex       = 0xa8,
+    SetLowColumn       = 0x00,
+    SetHighColumn      = 0x10,
+    SetStartLine       = 0x40,
+
+    SetMemoryMode = 0x20,
+    ColumnAddr    = 0x21,
+    PageAddr      = 0x22,
+
+    ComScanInc    = 0xc0,
+    ComScanDec    = 0xc8,
+    SegRemap      = 0xa0,
+    SetChargePump = 0x8d,
+    ExternalVcc   = 0x01,
+    SwitchCapVcc  = 0x02,
+
+    ActivateScroll                   = 0x2f,
+    DeActivateScroll                 = 0x2e,
+    SetVerticalScrollArea            = 0xa3,
+    RightHorizontalScroll            = 0x26,
+    LeftHorizontalScroll             = 0x27,
+    VerticalAndRightHorizontalScroll = 0x29,
+    VerticalAndLeftHorizontalScroll  = 0x2a,
 };
 
 // Controls the SSD1306 128x32 OLED display via i2c
 
 #ifndef SSD1306_ADDRESS
-#define SSD1306_ADDRESS 0x3C
+#    define SSD1306_ADDRESS 0x3C
 #endif
 
 #define DisplayHeight 32
@@ -62,9 +62,9 @@ enum ssd1306_cmds {
 #define MatrixCols (DisplayWidth / FontWidth)
 
 struct CharacterMatrix {
-  uint8_t display[MatrixRows][MatrixCols];
-  uint8_t *cursor;
-  bool dirty;
+    uint8_t  display[MatrixRows][MatrixCols];
+    uint8_t *cursor;
+    bool     dirty;
 };
 
 struct CharacterMatrix display;
@@ -88,6 +88,4 @@ void matrix_write(struct CharacterMatrix *matrix, const char *data);
 void matrix_write_P(struct CharacterMatrix *matrix, const char *data);
 void matrix_render(struct CharacterMatrix *matrix);
 
-
-
 #endif
index 7c3cb5174df0a86af17a4fb2a70b856c06bc344b..0a02c6f7fd85fa5b2ee65a9462cda941fd106e5f 100644 (file)
@@ -1,25 +1,25 @@
 /*
-* light weight WS2812 lib V2.0b
-*
-* Controls WS2811/WS2812/WS2812B RGB-LEDs
-* Author: Tim (cpldcpu@gmail.com)
-*
-* Jan 18th, 2014  v2.0b Initial Version
-* Nov 29th, 2015  v2.3  Added SK6812RGBW support
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+ * light weight WS2812 lib V2.0b
+ *
+ * Controls WS2811/WS2812/WS2812B RGB-LEDs
+ * Author: Tim (cpldcpu@gmail.com)
+ *
+ * Jan 18th, 2014  v2.0b Initial Version
+ * Nov 29th, 2015  v2.3  Added SK6812RGBW support
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 
 #include "ws2812.h"
 #include <avr/interrupt.h>
 #if !defined(LED_ARRAY) && defined(RGB_MATRIX_ENABLE)
 // LED color buffer
 LED_TYPE led[DRIVER_LED_TOTAL];
-  #define LED_ARRAY led
+#    define LED_ARRAY led
 #endif
 
 #ifdef RGBW_BB_TWI
 
 // Port for the I2C
-#define I2C_DDR DDRD
-#define I2C_PIN PIND
-#define I2C_PORT PORTD
+#    define I2C_DDR DDRD
+#    define I2C_PIN PIND
+#    define I2C_PORT PORTD
 
 // Pins to be used in the bit banging
-#define I2C_CLK 0
-#define I2C_DAT 1
-
-#define I2C_DATA_HI()\
-I2C_DDR &= ~ (1 << I2C_DAT);\
-I2C_PORT |= (1 << I2C_DAT);
-#define I2C_DATA_LO()\
-I2C_DDR |= (1 << I2C_DAT);\
-I2C_PORT &= ~ (1 << I2C_DAT);
-
-#define I2C_CLOCK_HI()\
-I2C_DDR &= ~ (1 << I2C_CLK);\
-I2C_PORT |= (1 << I2C_CLK);
-#define I2C_CLOCK_LO()\
-I2C_DDR |= (1 << I2C_CLK);\
-I2C_PORT &= ~ (1 << I2C_CLK);
-
-#define I2C_DELAY 1
-
-void I2C_WriteBit(unsigned char c)
-{
-    if (c > 0)
-    {
+#    define I2C_CLK 0
+#    define I2C_DAT 1
+
+#    define I2C_DATA_HI()           \
+        I2C_DDR &= ~(1 << I2C_DAT); \
+        I2C_PORT |= (1 << I2C_DAT);
+#    define I2C_DATA_LO()          \
+        I2C_DDR |= (1 << I2C_DAT); \
+        I2C_PORT &= ~(1 << I2C_DAT);
+
+#    define I2C_CLOCK_HI()          \
+        I2C_DDR &= ~(1 << I2C_CLK); \
+        I2C_PORT |= (1 << I2C_CLK);
+#    define I2C_CLOCK_LO()         \
+        I2C_DDR |= (1 << I2C_CLK); \
+        I2C_PORT &= ~(1 << I2C_CLK);
+
+#    define I2C_DELAY 1
+
+void I2C_WriteBit(unsigned char c) {
+    if (c > 0) {
         I2C_DATA_HI();
-    }
-    else
-    {
+    } else {
         I2C_DATA_LO();
     }
 
@@ -77,8 +73,7 @@ void I2C_WriteBit(unsigned char c)
     I2C_CLOCK_LO();
     _delay_us(I2C_DELAY);
 
-    if (c > 0)
-    {
+    if (c > 0) {
         I2C_DATA_LO();
     }
 
@@ -87,9 +82,8 @@ void I2C_WriteBit(unsigned char c)
 
 // Inits bitbanging port, must be called before using the functions below
 //
-void I2C_Init(void)
-{
-    I2C_PORT &= ~ ((1 << I2C_DAT) | (1 << I2C_CLK));
+void I2C_Init(void) {
+    I2C_PORT &= ~((1 << I2C_DAT) | (1 << I2C_CLK));
 
     I2C_CLOCK_HI();
     I2C_DATA_HI();
@@ -99,10 +93,9 @@ void I2C_Init(void)
 
 // Send a START Condition
 //
-void I2C_Start(void)
-{
+void I2C_Start(void) {
     // set both to high at the same time
-    I2C_DDR &= ~ ((1 << I2C_DAT) | (1 << I2C_CLK));
+    I2C_DDR &= ~((1 << I2C_DAT) | (1 << I2C_CLK));
     _delay_us(I2C_DELAY);
 
     I2C_DATA_LO();
@@ -114,8 +107,7 @@ void I2C_Start(void)
 
 // Send a STOP Condition
 //
-void I2C_Stop(void)
-{
+void I2C_Stop(void) {
     I2C_CLOCK_HI();
     _delay_us(I2C_DELAY);
 
@@ -125,106 +117,91 @@ void I2C_Stop(void)
 
 // write a byte to the I2C slave device
 //
-unsigned char I2C_Write(unsigned char c)
-{
-    for (char i = 0; i < 8; i++)
-    {
+unsigned char I2C_Write(unsigned char c) {
+    for (char i = 0; i < 8; i++) {
         I2C_WriteBit(c & 128);
 
         c <<= 1;
     }
 
-
     I2C_WriteBit(0);
     _delay_us(I2C_DELAY);
     _delay_us(I2C_DELAY);
 
     // _delay_us(I2C_DELAY);
-    //return I2C_ReadBit();
+    // return I2C_ReadBit();
     return 0;
 }
 
-
 #endif
 
 #ifdef RGB_MATRIX_ENABLE
 // Set an led in the buffer to a color
-void inline ws2812_setled(int i, uint8_t r, uint8_t g, uint8_t b)
-{
+void inline ws2812_setled(int i, uint8_t r, uint8_t g, uint8_t b) {
     led[i].r = r;
     led[i].g = g;
     led[i].b = b;
 }
 
-void ws2812_setled_all  (uint8_t r, uint8_t g, uint8_t b)
-{
-  for (int i = 0; i < sizeof(led)/sizeof(led[0]); i++) {
-    led[i].r = r;
-    led[i].g = g;
-    led[i].b = b;
-  }
+void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b) {
+    for (int i = 0; i < sizeof(led) / sizeof(led[0]); i++) {
+        led[i].r = r;
+        led[i].g = g;
+        led[i].b = b;
+    }
 }
 #endif
 
 // Setleds for standard RGB
-void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds)
-{
-   // ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin));
-   ws2812_setleds_pin(ledarray,leds, _BV(RGB_DI_PIN & 0xF));
+void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
+    // ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin));
+    ws2812_setleds_pin(ledarray, leds, _BV(RGB_DI_PIN & 0xF));
 }
 
-void inline ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask)
-{
-  // ws2812_DDRREG |= pinmask; // Enable DDR
-  // new universal format (DDR)
-  _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= pinmask;
+void inline ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask) {
+    // ws2812_DDRREG |= pinmask; // Enable DDR
+    // new universal format (DDR)
+    _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= pinmask;
 
-  ws2812_sendarray_mask((uint8_t*)ledarray,leds+leds+leds,pinmask);
-  _delay_us(50);
+    ws2812_sendarray_mask((uint8_t *)ledarray, leds + leds + leds, pinmask);
+    _delay_us(50);
 }
 
 // Setleds for SK6812RGBW
-void inline ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds)
-{
-
-  #ifdef RGBW_BB_TWI
+void inline ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) {
+#ifdef RGBW_BB_TWI
     uint8_t sreg_prev, twcr_prev;
-    sreg_prev=SREG;
-    twcr_prev=TWCR;
+    sreg_prev = SREG;
+    twcr_prev = TWCR;
     cli();
-    TWCR &= ~(1<<TWEN);
+    TWCR &= ~(1 << TWEN);
     I2C_Init();
     I2C_Start();
     I2C_Write(0x84);
-    uint16_t datlen = leds<<2;
-    uint8_t curbyte;
-    uint8_t * data = (uint8_t*)ledarray;
+    uint16_t datlen = leds << 2;
+    uint8_t  curbyte;
+    uint8_t *data = (uint8_t *)ledarray;
     while (datlen--) {
-      curbyte=*data++;
-      I2C_Write(curbyte);
+        curbyte = *data++;
+        I2C_Write(curbyte);
     }
     I2C_Stop();
-    SREG=sreg_prev;
-    TWCR=twcr_prev;
-  #endif
-
-
-  // ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR
-  // new universal format (DDR)
-  _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF);
+    SREG = sreg_prev;
+    TWCR = twcr_prev;
+#endif
 
-  ws2812_sendarray_mask((uint8_t*)ledarray,leds<<2,_BV(RGB_DI_PIN & 0xF));
+    // ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR
+    // new universal format (DDR)
+    _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF);
 
+    ws2812_sendarray_mask((uint8_t *)ledarray, leds << 2, _BV(RGB_DI_PIN & 0xF));
 
-  #ifndef RGBW_BB_TWI
+#ifndef RGBW_BB_TWI
     _delay_us(80);
-  #endif
+#endif
 }
 
-void ws2812_sendarray(uint8_t *data,uint16_t datlen)
-{
-  ws2812_sendarray_mask(data,datlen,_BV(RGB_DI_PIN & 0xF));
-}
+void ws2812_sendarray(uint8_t *data, uint16_t datlen) { ws2812_sendarray_mask(data, datlen, _BV(RGB_DI_PIN & 0xF)); }
 
 /*
   This routine writes an array of bytes with RGB values to the Dataout pin
@@ -232,136 +209,133 @@ void ws2812_sendarray(uint8_t *data,uint16_t datlen)
 */
 
 // Timing in ns
-#define w_zeropulse   350
-#define w_onepulse    900
+#define w_zeropulse 350
+#define w_onepulse 900
 #define w_totalperiod 1250
 
 // Fixed cycles used by the inner loop
-#define w_fixedlow    2
-#define w_fixedhigh   4
-#define w_fixedtotal  8
+#define w_fixedlow 2
+#define w_fixedhigh 4
+#define w_fixedtotal 8
 
 // Insert NOPs to match the timing, if possible
-#define w_zerocycles    (((F_CPU/1000)*w_zeropulse          )/1000000)
-#define w_onecycles     (((F_CPU/1000)*w_onepulse    +500000)/1000000)
-#define w_totalcycles   (((F_CPU/1000)*w_totalperiod +500000)/1000000)
+#define w_zerocycles (((F_CPU / 1000) * w_zeropulse) / 1000000)
+#define w_onecycles (((F_CPU / 1000) * w_onepulse + 500000) / 1000000)
+#define w_totalcycles (((F_CPU / 1000) * w_totalperiod + 500000) / 1000000)
 
 // w1 - nops between rising edge and falling edge - low
-#define w1 (w_zerocycles-w_fixedlow)
+#define w1 (w_zerocycles - w_fixedlow)
 // w2   nops between fe low and fe high
-#define w2 (w_onecycles-w_fixedhigh-w1)
+#define w2 (w_onecycles - w_fixedhigh - w1)
 // w3   nops to complete loop
-#define w3 (w_totalcycles-w_fixedtotal-w1-w2)
+#define w3 (w_totalcycles - w_fixedtotal - w1 - w2)
 
-#if w1>0
-  #define w1_nops w1
+#if w1 > 0
+#    define w1_nops w1
 #else
-  #define w1_nops  0
+#    define w1_nops 0
 #endif
 
 // The only critical timing parameter is the minimum pulse length of the "0"
 // Warn or throw error if this timing can not be met with current F_CPU settings.
-#define w_lowtime ((w1_nops+w_fixedlow)*1000000)/(F_CPU/1000)
-#if w_lowtime>550
-   #error "Light_ws2812: Sorry, the clock speed is too low. Did you set F_CPU correctly?"
-#elif w_lowtime>450
-   #warning "Light_ws2812: The timing is critical and may only work on WS2812B, not on WS2812(S)."
-   #warning "Please consider a higher clockspeed, if possible"
+#define w_lowtime ((w1_nops + w_fixedlow) * 1000000) / (F_CPU / 1000)
+#if w_lowtime > 550
+#    error "Light_ws2812: Sorry, the clock speed is too low. Did you set F_CPU correctly?"
+#elif w_lowtime > 450
+#    warning "Light_ws2812: The timing is critical and may only work on WS2812B, not on WS2812(S)."
+#    warning "Please consider a higher clockspeed, if possible"
 #endif
 
-#if w2>0
-#define w2_nops w2
+#if w2 > 0
+#    define w2_nops w2
 #else
-#define w2_nops  0
+#    define w2_nops 0
 #endif
 
-#if w3>0
-#define w3_nops w3
+#if w3 > 0
+#    define w3_nops w3
 #else
-#define w3_nops  0
+#    define w3_nops 0
 #endif
 
-#define w_nop1  "nop      \n\t"
-#define w_nop2  "rjmp .+0 \n\t"
-#define w_nop4  w_nop2 w_nop2
-#define w_nop8  w_nop4 w_nop4
+#define w_nop1 "nop      \n\t"
+#define w_nop2 "rjmp .+0 \n\t"
+#define w_nop4 w_nop2 w_nop2
+#define w_nop8 w_nop4 w_nop4
 #define w_nop16 w_nop8 w_nop8
 
-void inline ws2812_sendarray_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi)
-{
-  uint8_t curbyte,ctr,masklo;
-  uint8_t sreg_prev;
-
-  // masklo  =~maskhi&ws2812_PORTREG;
-  // maskhi |=        ws2812_PORTREG;
-  masklo  =~maskhi&_SFR_IO8((RGB_DI_PIN >> 4) + 2);
-  maskhi |=        _SFR_IO8((RGB_DI_PIN >> 4) + 2);
-  sreg_prev=SREG;
-  cli();
-
-  while (datlen--) {
-    curbyte=(*data++);
-
-    asm volatile(
-    "       ldi   %0,8  \n\t"
-    "loop%=:            \n\t"
-    "       out   %2,%3 \n\t"    //  '1' [01] '0' [01] - re
-#if (w1_nops&1)
-w_nop1
+void inline ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t maskhi) {
+    uint8_t curbyte, ctr, masklo;
+    uint8_t sreg_prev;
+
+    // masklo  =~maskhi&ws2812_PORTREG;
+    // maskhi |=        ws2812_PORTREG;
+    masklo = ~maskhi & _SFR_IO8((RGB_DI_PIN >> 4) + 2);
+    maskhi |= _SFR_IO8((RGB_DI_PIN >> 4) + 2);
+    sreg_prev = SREG;
+    cli();
+
+    while (datlen--) {
+        curbyte = (*data++);
+
+        asm volatile("       ldi   %0,8  \n\t"
+                     "loop%=:            \n\t"
+                     "       out   %2,%3 \n\t"  //  '1' [01] '0' [01] - re
+#if (w1_nops & 1)
+                     w_nop1
 #endif
-#if (w1_nops&2)
-w_nop2
+#if (w1_nops & 2)
+                         w_nop2
 #endif
-#if (w1_nops&4)
-w_nop4
+#if (w1_nops & 4)
+                             w_nop4
 #endif
-#if (w1_nops&8)
-w_nop8
+#if (w1_nops & 8)
+                                 w_nop8
 #endif
-#if (w1_nops&16)
-w_nop16
+#if (w1_nops & 16)
+                                     w_nop16
 #endif
-    "       sbrs  %1,7  \n\t"    //  '1' [03] '0' [02]
-    "       out   %2,%4 \n\t"    //  '1' [--] '0' [03] - fe-low
-    "       lsl   %1    \n\t"    //  '1' [04] '0' [04]
-#if (w2_nops&1)
-  w_nop1
+                     "       sbrs  %1,7  \n\t"  //  '1' [03] '0' [02]
+                     "       out   %2,%4 \n\t"  //  '1' [--] '0' [03] - fe-low
+                     "       lsl   %1    \n\t"  //  '1' [04] '0' [04]
+#if (w2_nops & 1)
+                     w_nop1
 #endif
-#if (w2_nops&2)
-  w_nop2
+#if (w2_nops & 2)
+                         w_nop2
 #endif
-#if (w2_nops&4)
-  w_nop4
+#if (w2_nops & 4)
+                             w_nop4
 #endif
-#if (w2_nops&8)
-  w_nop8
+#if (w2_nops & 8)
+                                 w_nop8
 #endif
-#if (w2_nops&16)
-  w_nop16
+#if (w2_nops & 16)
+                                     w_nop16
 #endif
-    "       out   %2,%4 \n\t"    //  '1' [+1] '0' [+1] - fe-high
-#if (w3_nops&1)
-w_nop1
+                     "       out   %2,%4 \n\t"  //  '1' [+1] '0' [+1] - fe-high
+#if (w3_nops & 1)
+                     w_nop1
 #endif
-#if (w3_nops&2)
-w_nop2
+#if (w3_nops & 2)
+                         w_nop2
 #endif
-#if (w3_nops&4)
-w_nop4
+#if (w3_nops & 4)
+                             w_nop4
 #endif
-#if (w3_nops&8)
-w_nop8
+#if (w3_nops & 8)
+                                 w_nop8
 #endif
-#if (w3_nops&16)
-w_nop16
+#if (w3_nops & 16)
+                                     w_nop16
 #endif
 
-    "       dec   %0    \n\t"    //  '1' [+2] '0' [+2]
-    "       brne  loop%=\n\t"    //  '1' [+3] '0' [+4]
-    :  "=&d" (ctr)
-    :  "r" (curbyte), "I" (_SFR_IO_ADDR(_SFR_IO8((RGB_DI_PIN >> 4) + 2))), "r" (maskhi), "r" (masklo)
-    );
-  }
+                     "       dec   %0    \n\t"  //  '1' [+2] '0' [+2]
+                     "       brne  loop%=\n\t"  //  '1' [+3] '0' [+4]
+                     : "=&d"(ctr)
+                     : "r"(curbyte), "I"(_SFR_IO_ADDR(_SFR_IO8((RGB_DI_PIN >> 4) + 2))), "r"(maskhi), "r"(masklo));
+    }
 
-  SREG=sreg_prev;
+    SREG = sreg_prev;
 }
index 95f540b1849bf93de4ebd674f54d8d30a13fa5dc..a9dd897185358e4613862f30f2856963e52fd173 100644 (file)
  *         - Wait 50�s to reset the LEDs
  */
 #ifdef RGB_MATRIX_ENABLE
-void ws2812_setled      (int index, uint8_t r, uint8_t g, uint8_t b);
-void ws2812_setled_all  (uint8_t r, uint8_t g, uint8_t b);
+void ws2812_setled(int index, uint8_t r, uint8_t g, uint8_t b);
+void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b);
 #endif
 
-void ws2812_setleds     (LED_TYPE *ledarray, uint16_t number_of_leds);
-void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask);
+void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
+void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask);
 void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
 
 /*
@@ -58,18 +58,17 @@ void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
  * The length is the number of bytes to send - three per LED.
  */
 
-void ws2812_sendarray     (uint8_t *array,uint16_t length);
-void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask);
-
+void ws2812_sendarray(uint8_t *array, uint16_t length);
+void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask);
 
 /*
  * Internal defines
  */
 #ifndef CONCAT
-#define CONCAT(a, b)            a ## b
+#    define CONCAT(a, b) a##b
 #endif
 #ifndef CONCAT_EXP
-#define CONCAT_EXP(a, b)   CONCAT(a, b)
+#    define CONCAT_EXP(a, b) CONCAT(a, b)
 #endif
 
 #endif /* LIGHT_WS2812_H_ */
index 4331155df4b6e436053089433e8308b7bbdcd285..60c191d9b1d253387dfa39f6226567378f725ca6 100644 (file)
  *          This variable is used by the HAL when initializing the PAL driver.
  */
 const PALConfig pal_default_config = {
-#if STM32_HAS_GPIOA
-  {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR,
-   VAL_GPIOA_ODR,   VAL_GPIOA_AFRL,   VAL_GPIOA_AFRH},
-#endif
-#if STM32_HAS_GPIOB
-  {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR,
-   VAL_GPIOB_ODR,   VAL_GPIOB_AFRL,   VAL_GPIOB_AFRH},
-#endif
-#if STM32_HAS_GPIOC
-  {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR,
-   VAL_GPIOC_ODR,   VAL_GPIOC_AFRL,   VAL_GPIOC_AFRH},
-#endif
-#if STM32_HAS_GPIOD
-  {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR,
-   VAL_GPIOD_ODR,   VAL_GPIOD_AFRL,   VAL_GPIOD_AFRH},
-#endif
-#if STM32_HAS_GPIOE
-  {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR,
-   VAL_GPIOE_ODR,   VAL_GPIOE_AFRL,   VAL_GPIOE_AFRH},
-#endif
-#if STM32_HAS_GPIOF
-  {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR,
-   VAL_GPIOF_ODR,   VAL_GPIOF_AFRL,   VAL_GPIOF_AFRH},
-#endif
-#if STM32_HAS_GPIOG
-  {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR,
-   VAL_GPIOG_ODR,   VAL_GPIOG_AFRL,   VAL_GPIOG_AFRH},
-#endif
-#if STM32_HAS_GPIOH
-  {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR,
-   VAL_GPIOH_ODR,   VAL_GPIOH_AFRL,   VAL_GPIOH_AFRH},
-#endif
-#if STM32_HAS_GPIOI
-  {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR,
-   VAL_GPIOI_ODR,   VAL_GPIOI_AFRL,   VAL_GPIOI_AFRH}
-#endif
+#    if STM32_HAS_GPIOA
+    {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR, VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH},
+#    endif
+#    if STM32_HAS_GPIOB
+    {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR, VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH},
+#    endif
+#    if STM32_HAS_GPIOC
+    {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR, VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH},
+#    endif
+#    if STM32_HAS_GPIOD
+    {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR, VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH},
+#    endif
+#    if STM32_HAS_GPIOE
+    {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR, VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH},
+#    endif
+#    if STM32_HAS_GPIOF
+    {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR, VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH},
+#    endif
+#    if STM32_HAS_GPIOG
+    {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR, VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH},
+#    endif
+#    if STM32_HAS_GPIOH
+    {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR, VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH},
+#    endif
+#    if STM32_HAS_GPIOI
+    {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR, VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH}
+#    endif
 };
 #endif
 
@@ -70,8 +61,8 @@ void enter_bootloader_mode_if_requested(void);
  *          and before any other initialization.
  */
 void __early_init(void) {
-  enter_bootloader_mode_if_requested();
-  stm32_clock_init();
+    enter_bootloader_mode_if_requested();
+    stm32_clock_init();
 }
 
 #if HAL_USE_SDC || defined(__DOXYGEN__)
@@ -79,20 +70,18 @@ void __early_init(void) {
  * @brief   SDC card detection.
  */
 bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
-
-  (void)sdcp;
-  /* TODO: Fill the implementation.*/
-  return true;
+    (void)sdcp;
+    /* TODO: Fill the implementation.*/
+    return true;
 }
 
 /**
  * @brief   SDC card write protection detection.
  */
 bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
-
-  (void)sdcp;
-  /* TODO: Fill the implementation.*/
-  return false;
+    (void)sdcp;
+    /* TODO: Fill the implementation.*/
+    return false;
 }
 #endif /* HAL_USE_SDC */
 
@@ -101,20 +90,18 @@ bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
  * @brief   MMC_SPI card detection.
  */
 bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
-
-  (void)mmcp;
-  /* TODO: Fill the implementation.*/
-  return true;
+    (void)mmcp;
+    /* TODO: Fill the implementation.*/
+    return true;
 }
 
 /**
  * @brief   MMC_SPI card write protection detection.
  */
 bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
-
-  (void)mmcp;
-  /* TODO: Fill the implementation.*/
-  return false;
+    (void)mmcp;
+    /* TODO: Fill the implementation.*/
+    return false;
 }
 #endif
 
@@ -122,5 +109,4 @@ bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
  * @brief   Board-specific initialization code.
  * @todo    Add your board-specific code, if any.
  */
-void boardInit(void) {
-}
+void boardInit(void) {}
index 11120dfd74637dd95443ed79e1e95c0510e36b87..3579c82770ecd3b17b5545ba5e658c9640e860aa 100644 (file)
  * Board identifier.
  */
 #define BOARD_GENERIC_STM32_F303XC
-#define BOARD_NAME                  "STM32_F303"
+#define BOARD_NAME "STM32_F303"
 
 /*
  * Board oscillators-related settings.
  * NOTE: LSE not fitted.
  */
 #if !defined(STM32_LSECLK)
-#define STM32_LSECLK                0U
+#    define STM32_LSECLK 0U
 #endif
 
-#define STM32_LSEDRV                (3U << 3U)
+#define STM32_LSEDRV (3U << 3U)
 
 #if !defined(STM32_HSECLK)
-#define STM32_HSECLK                8000000U
+#    define STM32_HSECLK 8000000U
 #endif
 
 // #define STM32_HSE_BYPASS
 /*
  * IO pins assignments.
  */
-#define GPIOA_PIN0       0U
-#define GPIOA_PIN1       1U
-#define GPIOA_PIN2       2U
-#define GPIOA_PIN3       3U
-#define GPIOA_PIN4       4U
-#define GPIOA_PIN5       5U
-#define GPIOA_PIN6       6U
-#define GPIOA_PIN7       7U
-#define GPIOA_PIN8       8U
-#define GPIOA_PIN9       9U
-#define GPIOA_PIN10      10U
-#define GPIOA_USB_DM     11U
-#define GPIOA_USB_DP     12U
-#define GPIOA_SWDIO      13U
-#define GPIOA_SWCLK      14U
-#define GPIOA_PIN15      15U
-
-#define GPIOB_PIN0       0U
-#define GPIOB_PIN1       1U
-#define GPIOB_PIN2       2U
-#define GPIOB_PIN3       3U
-#define GPIOB_PIN4       4U
-#define GPIOB_PIN5       5U
-#define GPIOB_PIN6       6U
-#define GPIOB_PIN7       7U
-#define GPIOB_PIN8       8U
-#define GPIOB_PIN9       9U
-#define GPIOB_PIN10      10U
-#define GPIOB_PIN11      11U
-#define GPIOB_PIN12      12U
-#define GPIOB_PIN13      13U
-#define GPIOB_PIN14      14U
-#define GPIOB_PIN15      15U
-
-#define GPIOC_PIN0       0U
-#define GPIOC_PIN1       1U
-#define GPIOC_PIN2       2U
-#define GPIOC_PIN3       3U
-#define GPIOC_PIN4       4U
-#define GPIOC_PIN5       5U
-#define GPIOC_PIN6       6U
-#define GPIOC_PIN7       7U
-#define GPIOC_PIN8       8U
-#define GPIOC_PIN9       9U
-#define GPIOC_PIN10      10U
-#define GPIOC_PIN11      11U
-#define GPIOC_PIN12      12U
-#define GPIOC_PIN13      13U
-#define GPIOC_PIN14      14U
-#define GPIOC_PIN15      15U
-
-#define GPIOD_PIN0       0U
-#define GPIOD_PIN1       1U
-#define GPIOD_PIN2       2U
-#define GPIOD_PIN3       3U
-#define GPIOD_PIN4       4U
-#define GPIOD_PIN5       5U
-#define GPIOD_PIN6       6U
-#define GPIOD_PIN7       7U
-#define GPIOD_PIN8       8U
-#define GPIOD_PIN9       9U
-#define GPIOD_PIN10      10U
-#define GPIOD_PIN11      11U
-#define GPIOD_PIN12      12U
-#define GPIOD_PIN13      13U
-#define GPIOD_PIN14      14U
-#define GPIOD_PIN15      15U
-
-#define GPIOE_PIN0       0U
-#define GPIOE_PIN1       1U
-#define GPIOE_PIN2       2U
-#define GPIOE_PIN3       3U
-#define GPIOE_PIN4       4U
-#define GPIOE_PIN5       5U
-#define GPIOE_PIN6       6U
-#define GPIOE_PIN7       7U
-#define GPIOE_PIN8       8U
-#define GPIOE_PIN9       9U
-#define GPIOE_PIN10      10U
-#define GPIOE_PIN11      11U
-#define GPIOE_PIN12      12U
-#define GPIOE_PIN13      13U
-#define GPIOE_PIN14      14U
-#define GPIOE_PIN15      15U
-
-#define GPIOF_I2C2_SDA   0U
-#define GPIOF_I2C2_SCL   1U
-#define GPIOF_PIN2       2U
-#define GPIOF_PIN3       3U
-#define GPIOF_PIN4       4U
-#define GPIOF_PIN5       5U
-#define GPIOF_PIN6       6U
-#define GPIOF_PIN7       7U
-#define GPIOF_PIN8       8U
-#define GPIOF_PIN9       9U
-#define GPIOF_PIN10      10U
-#define GPIOF_PIN11      11U
-#define GPIOF_PIN12      12U
-#define GPIOF_PIN13      13U
-#define GPIOF_PIN14      14U
-#define GPIOF_PIN15      15U
-
-#define GPIOG_PIN0       0U
-#define GPIOG_PIN1       1U
-#define GPIOG_PIN2       2U
-#define GPIOG_PIN3       3U
-#define GPIOG_PIN4       4U
-#define GPIOG_PIN5       5U
-#define GPIOG_PIN6       6U
-#define GPIOG_PIN7       7U
-#define GPIOG_PIN8       8U
-#define GPIOG_PIN9       9U
-#define GPIOG_PIN10      10U
-#define GPIOG_PIN11      11U
-#define GPIOG_PIN12      12U
-#define GPIOG_PIN13      13U
-#define GPIOG_PIN14      14U
-#define GPIOG_PIN15      15U
-
-#define GPIOH_PIN0       0U
-#define GPIOH_PIN1       1U
-#define GPIOH_PIN2       2U
-#define GPIOH_PIN3       3U
-#define GPIOH_PIN4       4U
-#define GPIOH_PIN5       5U
-#define GPIOH_PIN6       6U
-#define GPIOH_PIN7       7U
-#define GPIOH_PIN8       8U
-#define GPIOH_PIN9       9U
-#define GPIOH_PIN10      10U
-#define GPIOH_PIN11      11U
-#define GPIOH_PIN12      12U
-#define GPIOH_PIN13      13U
-#define GPIOH_PIN14      14U
-#define GPIOH_PIN15      15U
+#define GPIOA_PIN0 0U
+#define GPIOA_PIN1 1U
+#define GPIOA_PIN2 2U
+#define GPIOA_PIN3 3U
+#define GPIOA_PIN4 4U
+#define GPIOA_PIN5 5U
+#define GPIOA_PIN6 6U
+#define GPIOA_PIN7 7U
+#define GPIOA_PIN8 8U
+#define GPIOA_PIN9 9U
+#define GPIOA_PIN10 10U
+#define GPIOA_USB_DM 11U
+#define GPIOA_USB_DP 12U
+#define GPIOA_SWDIO 13U
+#define GPIOA_SWCLK 14U
+#define GPIOA_PIN15 15U
+
+#define GPIOB_PIN0 0U
+#define GPIOB_PIN1 1U
+#define GPIOB_PIN2 2U
+#define GPIOB_PIN3 3U
+#define GPIOB_PIN4 4U
+#define GPIOB_PIN5 5U
+#define GPIOB_PIN6 6U
+#define GPIOB_PIN7 7U
+#define GPIOB_PIN8 8U
+#define GPIOB_PIN9 9U
+#define GPIOB_PIN10 10U
+#define GPIOB_PIN11 11U
+#define GPIOB_PIN12 12U
+#define GPIOB_PIN13 13U
+#define GPIOB_PIN14 14U
+#define GPIOB_PIN15 15U
+
+#define GPIOC_PIN0 0U
+#define GPIOC_PIN1 1U
+#define GPIOC_PIN2 2U
+#define GPIOC_PIN3 3U
+#define GPIOC_PIN4 4U
+#define GPIOC_PIN5 5U
+#define GPIOC_PIN6 6U
+#define GPIOC_PIN7 7U
+#define GPIOC_PIN8 8U
+#define GPIOC_PIN9 9U
+#define GPIOC_PIN10 10U
+#define GPIOC_PIN11 11U
+#define GPIOC_PIN12 12U
+#define GPIOC_PIN13 13U
+#define GPIOC_PIN14 14U
+#define GPIOC_PIN15 15U
+
+#define GPIOD_PIN0 0U
+#define GPIOD_PIN1 1U
+#define GPIOD_PIN2 2U
+#define GPIOD_PIN3 3U
+#define GPIOD_PIN4 4U
+#define GPIOD_PIN5 5U
+#define GPIOD_PIN6 6U
+#define GPIOD_PIN7 7U
+#define GPIOD_PIN8 8U
+#define GPIOD_PIN9 9U
+#define GPIOD_PIN10 10U
+#define GPIOD_PIN11 11U
+#define GPIOD_PIN12 12U
+#define GPIOD_PIN13 13U
+#define GPIOD_PIN14 14U
+#define GPIOD_PIN15 15U
+
+#define GPIOE_PIN0 0U
+#define GPIOE_PIN1 1U
+#define GPIOE_PIN2 2U
+#define GPIOE_PIN3 3U
+#define GPIOE_PIN4 4U
+#define GPIOE_PIN5 5U
+#define GPIOE_PIN6 6U
+#define GPIOE_PIN7 7U
+#define GPIOE_PIN8 8U
+#define GPIOE_PIN9 9U
+#define GPIOE_PIN10 10U
+#define GPIOE_PIN11 11U
+#define GPIOE_PIN12 12U
+#define GPIOE_PIN13 13U
+#define GPIOE_PIN14 14U
+#define GPIOE_PIN15 15U
+
+#define GPIOF_I2C2_SDA 0U
+#define GPIOF_I2C2_SCL 1U
+#define GPIOF_PIN2 2U
+#define GPIOF_PIN3 3U
+#define GPIOF_PIN4 4U
+#define GPIOF_PIN5 5U
+#define GPIOF_PIN6 6U
+#define GPIOF_PIN7 7U
+#define GPIOF_PIN8 8U
+#define GPIOF_PIN9 9U
+#define GPIOF_PIN10 10U
+#define GPIOF_PIN11 11U
+#define GPIOF_PIN12 12U
+#define GPIOF_PIN13 13U
+#define GPIOF_PIN14 14U
+#define GPIOF_PIN15 15U
+
+#define GPIOG_PIN0 0U
+#define GPIOG_PIN1 1U
+#define GPIOG_PIN2 2U
+#define GPIOG_PIN3 3U
+#define GPIOG_PIN4 4U
+#define GPIOG_PIN5 5U
+#define GPIOG_PIN6 6U
+#define GPIOG_PIN7 7U
+#define GPIOG_PIN8 8U
+#define GPIOG_PIN9 9U
+#define GPIOG_PIN10 10U
+#define GPIOG_PIN11 11U
+#define GPIOG_PIN12 12U
+#define GPIOG_PIN13 13U
+#define GPIOG_PIN14 14U
+#define GPIOG_PIN15 15U
+
+#define GPIOH_PIN0 0U
+#define GPIOH_PIN1 1U
+#define GPIOH_PIN2 2U
+#define GPIOH_PIN3 3U
+#define GPIOH_PIN4 4U
+#define GPIOH_PIN5 5U
+#define GPIOH_PIN6 6U
+#define GPIOH_PIN7 7U
+#define GPIOH_PIN8 8U
+#define GPIOH_PIN9 9U
+#define GPIOH_PIN10 10U
+#define GPIOH_PIN11 11U
+#define GPIOH_PIN12 12U
+#define GPIOH_PIN13 13U
+#define GPIOH_PIN14 14U
+#define GPIOH_PIN15 15U
 
 /*
  * IO lines assignments.
  */
-#define LINE_L3GD20_SDI             PAL_LINE(GPIOA, 7U)
-#define LINE_USB_DM                 PAL_LINE(GPIOA, 11U)
-#define LINE_USB_DP                 PAL_LINE(GPIOA, 12U)
-#define LINE_SWDIO                  PAL_LINE(GPIOA, 13U)
-#define LINE_SWCLK                  PAL_LINE(GPIOA, 14U)
-
-#define LINE_PIN6               PAL_LINE(GPIOF, 0U)
-#define LINE_PIN7               PAL_LINE(GPIOF, 1U)
+#define LINE_L3GD20_SDI PAL_LINE(GPIOA, 7U)
+#define LINE_USB_DM PAL_LINE(GPIOA, 11U)
+#define LINE_USB_DP PAL_LINE(GPIOA, 12U)
+#define LINE_SWDIO PAL_LINE(GPIOA, 13U)
+#define LINE_SWCLK PAL_LINE(GPIOA, 14U)
 
-#define LINE_CAPS_LOCK               PAL_LINE(GPIOB, 7U)
+#define LINE_PIN6 PAL_LINE(GPIOF, 0U)
+#define LINE_PIN7 PAL_LINE(GPIOF, 1U)
 
+#define LINE_CAPS_LOCK PAL_LINE(GPIOB, 7U)
 
 /*
  * I/O ports initial setup, this configuration is established soon after reset
  * in the initialization code.
  * Please refer to the STM32 Reference Manual for details.
  */
-#define PIN_MODE_INPUT(n)           (0U << ((n) * 2U))
-#define PIN_MODE_OUTPUT(n)          (1U << ((n) * 2U))
-#define PIN_MODE_ALTERNATE(n)       (2U << ((n) * 2U))
-#define PIN_MODE_ANALOG(n)          (3U << ((n) * 2U))
-#define PIN_ODR_LOW(n)              (0U << (n))
-#define PIN_ODR_HIGH(n)             (1U << (n))
-#define PIN_OTYPE_PUSHPULL(n)       (0U << (n))
-#define PIN_OTYPE_OPENDRAIN(n)      (1U << (n))
-#define PIN_OSPEED_VERYLOW(n)       (0U << ((n) * 2U))
-#define PIN_OSPEED_LOW(n)           (1U << ((n) * 2U))
-#define PIN_OSPEED_MEDIUM(n)        (2U << ((n) * 2U))
-#define PIN_OSPEED_HIGH(n)          (3U << ((n) * 2U))
-#define PIN_PUPDR_FLOATING(n)       (0U << ((n) * 2U))
-#define PIN_PUPDR_PULLUP(n)         (1U << ((n) * 2U))
-#define PIN_PUPDR_PULLDOWN(n)       (2U << ((n) * 2U))
-#define PIN_AFIO_AF(n, v)           ((v) << (((n) % 8U) * 4U))
+#define PIN_MODE_INPUT(n) (0U << ((n)*2U))
+#define PIN_MODE_OUTPUT(n) (1U << ((n)*2U))
+#define PIN_MODE_ALTERNATE(n) (2U << ((n)*2U))
+#define PIN_MODE_ANALOG(n) (3U << ((n)*2U))
+#define PIN_ODR_LOW(n) (0U << (n))
+#define PIN_ODR_HIGH(n) (1U << (n))
+#define PIN_OTYPE_PUSHPULL(n) (0U << (n))
+#define PIN_OTYPE_OPENDRAIN(n) (1U << (n))
+#define PIN_OSPEED_VERYLOW(n) (0U << ((n)*2U))
+#define PIN_OSPEED_LOW(n) (1U << ((n)*2U))
+#define PIN_OSPEED_MEDIUM(n) (2U << ((n)*2U))
+#define PIN_OSPEED_HIGH(n) (3U << ((n)*2U))
+#define PIN_PUPDR_FLOATING(n) (0U << ((n)*2U))
+#define PIN_PUPDR_PULLUP(n) (1U << ((n)*2U))
+#define PIN_PUPDR_PULLDOWN(n) (2U << ((n)*2U))
+#define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U))
 
 /*
  * GPIOA setup:
  * PA14 - SWCLK                     (alternate 0).
  * PA15 - ROW4
  */
-#define VAL_GPIOA_MODER             (PIN_MODE_INPUT(GPIOA_PIN0) |         \
-                                     PIN_MODE_ALTERNATE(GPIOA_PIN1) |           \
-                                     PIN_MODE_INPUT(GPIOA_PIN2) |           \
-                                     PIN_MODE_INPUT(GPIOA_PIN3) |           \
-                                     PIN_MODE_INPUT(GPIOA_PIN4) |           \
-                                     PIN_MODE_INPUT(GPIOA_PIN5) |   \
-                                     PIN_MODE_INPUT(GPIOA_PIN6) |  \
-                                     PIN_MODE_INPUT(GPIOA_PIN7) |  \
-                                     PIN_MODE_INPUT(GPIOA_PIN8) |           \
-                                     PIN_MODE_INPUT(GPIOA_PIN9) |           \
-                                     PIN_MODE_INPUT(GPIOA_PIN10) |          \
-                                     PIN_MODE_ALTERNATE(GPIOA_USB_DM) |     \
-                                     PIN_MODE_ALTERNATE(GPIOA_USB_DP) |     \
-                                     PIN_MODE_ALTERNATE(GPIOA_SWDIO) |      \
-                                     PIN_MODE_ALTERNATE(GPIOA_SWCLK) |      \
-                                     PIN_MODE_INPUT(GPIOA_PIN15))
-#define VAL_GPIOA_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOA_PIN0) |     \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN1) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN2) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN3) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN4) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN5) |   \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN6) |  \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN7) |  \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN8) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN9) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN10) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_USB_DM) |     \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_USB_DP) |     \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_SWDIO) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_SWCLK) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN15))
-#define VAL_GPIOA_OSPEEDR           (PIN_OSPEED_VERYLOW(GPIOA_PIN0) |     \
-                                     PIN_OSPEED_HIGH(GPIOA_PIN1) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOA_PIN2) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOA_PIN3) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOA_PIN4) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOA_PIN5) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOA_PIN6) |     \
-                                     PIN_OSPEED_VERYLOW(GPIOA_PIN7) |     \
-                                     PIN_OSPEED_VERYLOW(GPIOA_PIN8) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOA_PIN9) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOA_PIN10) |      \
-                                     PIN_OSPEED_HIGH(GPIOA_USB_DM) |        \
-                                     PIN_OSPEED_VERYLOW(GPIOA_USB_DP) |     \
-                                     PIN_OSPEED_HIGH(GPIOA_SWDIO) |         \
-                                     PIN_OSPEED_HIGH(GPIOA_SWCLK) |         \
-                                     PIN_OSPEED_VERYLOW(GPIOA_PIN15))
-#define VAL_GPIOA_PUPDR             (PIN_PUPDR_FLOATING(GPIOA_PIN0) |     \
-                                     PIN_PUPDR_FLOATING(GPIOA_PIN1) |         \
-                                     PIN_PUPDR_PULLUP(GPIOA_PIN2) |         \
-                                     PIN_PUPDR_PULLUP(GPIOA_PIN3) |         \
-                                     PIN_PUPDR_PULLUP(GPIOA_PIN4) |         \
-                                     PIN_PUPDR_PULLUP(GPIOA_PIN5) |   \
-                                     PIN_PUPDR_PULLUP(GPIOA_PIN6) |    \
-                                     PIN_PUPDR_FLOATING(GPIOA_PIN7) |  \
-                                     PIN_PUPDR_PULLUP(GPIOA_PIN8) |         \
-                                     PIN_PUPDR_PULLUP(GPIOA_PIN9) |         \
-                                     PIN_PUPDR_PULLUP(GPIOA_PIN10) |        \
-                                     PIN_PUPDR_FLOATING(GPIOA_USB_DM) |     \
-                                     PIN_PUPDR_FLOATING(GPIOA_USB_DP) |     \
-                                     PIN_PUPDR_PULLUP(GPIOA_SWDIO) |        \
-                                     PIN_PUPDR_PULLDOWN(GPIOA_SWCLK) |      \
-                                     PIN_PUPDR_PULLUP(GPIOA_PIN15))
-#define VAL_GPIOA_ODR               (PIN_ODR_HIGH(GPIOA_PIN0) |           \
-                                     PIN_ODR_HIGH(GPIOA_PIN1) |             \
-                                     PIN_ODR_HIGH(GPIOA_PIN2) |             \
-                                     PIN_ODR_HIGH(GPIOA_PIN3) |             \
-                                     PIN_ODR_HIGH(GPIOA_PIN4) |             \
-                                     PIN_ODR_HIGH(GPIOA_PIN5) |         \
-                                     PIN_ODR_HIGH(GPIOA_PIN6) |        \
-                                     PIN_ODR_HIGH(GPIOA_PIN7) |        \
-                                     PIN_ODR_HIGH(GPIOA_PIN8) |             \
-                                     PIN_ODR_HIGH(GPIOA_PIN9) |             \
-                                     PIN_ODR_HIGH(GPIOA_PIN10) |            \
-                                     PIN_ODR_HIGH(GPIOA_USB_DM) |           \
-                                     PIN_ODR_HIGH(GPIOA_USB_DP) |           \
-                                     PIN_ODR_HIGH(GPIOA_SWDIO) |            \
-                                     PIN_ODR_HIGH(GPIOA_SWCLK) |            \
-                                     PIN_ODR_HIGH(GPIOA_PIN15))
-#define VAL_GPIOA_AFRL              (PIN_AFIO_AF(GPIOA_PIN0, 0) |         \
-                                     PIN_AFIO_AF(GPIOA_PIN1, 1) |           \
-                                     PIN_AFIO_AF(GPIOA_PIN2, 0) |           \
-                                     PIN_AFIO_AF(GPIOA_PIN3, 0) |           \
-                                     PIN_AFIO_AF(GPIOA_PIN4, 0) |           \
-                                     PIN_AFIO_AF(GPIOA_PIN5, 5) |       \
-                                     PIN_AFIO_AF(GPIOA_PIN6, 5) |      \
-                                     PIN_AFIO_AF(GPIOA_PIN7, 5))
-#define VAL_GPIOA_AFRH              (PIN_AFIO_AF(GPIOA_PIN8, 0) |           \
-                                     PIN_AFIO_AF(GPIOA_PIN9, 0) |           \
-                                     PIN_AFIO_AF(GPIOA_PIN10, 0) |          \
-                                     PIN_AFIO_AF(GPIOA_USB_DM, 14) |        \
-                                     PIN_AFIO_AF(GPIOA_USB_DP, 14) |        \
-                                     PIN_AFIO_AF(GPIOA_SWDIO, 0) |          \
-                                     PIN_AFIO_AF(GPIOA_SWCLK, 0) |          \
-                                     PIN_AFIO_AF(GPIOA_PIN15, 0))
+#define VAL_GPIOA_MODER (PIN_MODE_INPUT(GPIOA_PIN0) | PIN_MODE_ALTERNATE(GPIOA_PIN1) | PIN_MODE_INPUT(GPIOA_PIN2) | PIN_MODE_INPUT(GPIOA_PIN3) | PIN_MODE_INPUT(GPIOA_PIN4) | PIN_MODE_INPUT(GPIOA_PIN5) | PIN_MODE_INPUT(GPIOA_PIN6) | PIN_MODE_INPUT(GPIOA_PIN7) | PIN_MODE_INPUT(GPIOA_PIN8) | PIN_MODE_INPUT(GPIOA_PIN9) | PIN_MODE_INPUT(GPIOA_PIN10) | PIN_MODE_ALTERNATE(GPIOA_USB_DM) | PIN_MODE_ALTERNATE(GPIOA_USB_DP) | PIN_MODE_ALTERNATE(GPIOA_SWDIO) | PIN_MODE_ALTERNATE(GPIOA_SWCLK) | PIN_MODE_INPUT(GPIOA_PIN15))
+#define VAL_GPIOA_OTYPER (PIN_OTYPE_PUSHPULL(GPIOA_PIN0) | PIN_OTYPE_PUSHPULL(GPIOA_PIN1) | PIN_OTYPE_PUSHPULL(GPIOA_PIN2) | PIN_OTYPE_PUSHPULL(GPIOA_PIN3) | PIN_OTYPE_PUSHPULL(GPIOA_PIN4) | PIN_OTYPE_PUSHPULL(GPIOA_PIN5) | PIN_OTYPE_PUSHPULL(GPIOA_PIN6) | PIN_OTYPE_PUSHPULL(GPIOA_PIN7) | PIN_OTYPE_PUSHPULL(GPIOA_PIN8) | PIN_OTYPE_PUSHPULL(GPIOA_PIN9) | PIN_OTYPE_PUSHPULL(GPIOA_PIN10) | PIN_OTYPE_PUSHPULL(GPIOA_USB_DM) | PIN_OTYPE_PUSHPULL(GPIOA_USB_DP) | PIN_OTYPE_PUSHPULL(GPIOA_SWDIO) | PIN_OTYPE_PUSHPULL(GPIOA_SWCLK) | PIN_OTYPE_PUSHPULL(GPIOA_PIN15))
+#define VAL_GPIOA_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOA_PIN0) | PIN_OSPEED_HIGH(GPIOA_PIN1) | PIN_OSPEED_VERYLOW(GPIOA_PIN2) | PIN_OSPEED_VERYLOW(GPIOA_PIN3) | PIN_OSPEED_VERYLOW(GPIOA_PIN4) | PIN_OSPEED_VERYLOW(GPIOA_PIN5) | PIN_OSPEED_VERYLOW(GPIOA_PIN6) | PIN_OSPEED_VERYLOW(GPIOA_PIN7) | PIN_OSPEED_VERYLOW(GPIOA_PIN8) | PIN_OSPEED_VERYLOW(GPIOA_PIN9) | PIN_OSPEED_VERYLOW(GPIOA_PIN10) | PIN_OSPEED_HIGH(GPIOA_USB_DM) | PIN_OSPEED_VERYLOW(GPIOA_USB_DP) | PIN_OSPEED_HIGH(GPIOA_SWDIO) | PIN_OSPEED_HIGH(GPIOA_SWCLK) | PIN_OSPEED_VERYLOW(GPIOA_PIN15))
+#define VAL_GPIOA_PUPDR (PIN_PUPDR_FLOATING(GPIOA_PIN0) | PIN_PUPDR_FLOATING(GPIOA_PIN1) | PIN_PUPDR_PULLUP(GPIOA_PIN2) | PIN_PUPDR_PULLUP(GPIOA_PIN3) | PIN_PUPDR_PULLUP(GPIOA_PIN4) | PIN_PUPDR_PULLUP(GPIOA_PIN5) | PIN_PUPDR_PULLUP(GPIOA_PIN6) | PIN_PUPDR_FLOATING(GPIOA_PIN7) | PIN_PUPDR_PULLUP(GPIOA_PIN8) | PIN_PUPDR_PULLUP(GPIOA_PIN9) | PIN_PUPDR_PULLUP(GPIOA_PIN10) | PIN_PUPDR_FLOATING(GPIOA_USB_DM) | PIN_PUPDR_FLOATING(GPIOA_USB_DP) | PIN_PUPDR_PULLUP(GPIOA_SWDIO) | PIN_PUPDR_PULLDOWN(GPIOA_SWCLK) | PIN_PUPDR_PULLUP(GPIOA_PIN15))
+#define VAL_GPIOA_ODR (PIN_ODR_HIGH(GPIOA_PIN0) | PIN_ODR_HIGH(GPIOA_PIN1) | PIN_ODR_HIGH(GPIOA_PIN2) | PIN_ODR_HIGH(GPIOA_PIN3) | PIN_ODR_HIGH(GPIOA_PIN4) | PIN_ODR_HIGH(GPIOA_PIN5) | PIN_ODR_HIGH(GPIOA_PIN6) | PIN_ODR_HIGH(GPIOA_PIN7) | PIN_ODR_HIGH(GPIOA_PIN8) | PIN_ODR_HIGH(GPIOA_PIN9) | PIN_ODR_HIGH(GPIOA_PIN10) | PIN_ODR_HIGH(GPIOA_USB_DM) | PIN_ODR_HIGH(GPIOA_USB_DP) | PIN_ODR_HIGH(GPIOA_SWDIO) | PIN_ODR_HIGH(GPIOA_SWCLK) | PIN_ODR_HIGH(GPIOA_PIN15))
+#define VAL_GPIOA_AFRL (PIN_AFIO_AF(GPIOA_PIN0, 0) | PIN_AFIO_AF(GPIOA_PIN1, 1) | PIN_AFIO_AF(GPIOA_PIN2, 0) | PIN_AFIO_AF(GPIOA_PIN3, 0) | PIN_AFIO_AF(GPIOA_PIN4, 0) | PIN_AFIO_AF(GPIOA_PIN5, 5) | PIN_AFIO_AF(GPIOA_PIN6, 5) | PIN_AFIO_AF(GPIOA_PIN7, 5))
+#define VAL_GPIOA_AFRH (PIN_AFIO_AF(GPIOA_PIN8, 0) | PIN_AFIO_AF(GPIOA_PIN9, 0) | PIN_AFIO_AF(GPIOA_PIN10, 0) | PIN_AFIO_AF(GPIOA_USB_DM, 14) | PIN_AFIO_AF(GPIOA_USB_DP, 14) | PIN_AFIO_AF(GPIOA_SWDIO, 0) | PIN_AFIO_AF(GPIOA_SWCLK, 0) | PIN_AFIO_AF(GPIOA_PIN15, 0))
 
 /*
  * GPIOB setup:
  * PB14 - PIN14                     (input pullup).
  * PB15 - PIN15                     (input pullup).
  */
-#define VAL_GPIOB_MODER             (PIN_MODE_INPUT(GPIOB_PIN0) |           \
-                                     PIN_MODE_INPUT(GPIOB_PIN1) |           \
-                                     PIN_MODE_INPUT(GPIOB_PIN2) |           \
-                                     PIN_MODE_ALTERNATE(GPIOB_PIN3) |        \
-                                     PIN_MODE_INPUT(GPIOB_PIN4) |           \
-                                     PIN_MODE_INPUT(GPIOB_PIN5) |           \
-                                     PIN_MODE_ALTERNATE(GPIOB_PIN6) |   \
-                                     PIN_MODE_OUTPUT(GPIOB_PIN7) |   \
-                                     PIN_MODE_INPUT(GPIOB_PIN8) |           \
-                                     PIN_MODE_INPUT(GPIOB_PIN9) |           \
-                                     PIN_MODE_INPUT(GPIOB_PIN10) |          \
-                                     PIN_MODE_INPUT(GPIOB_PIN11) |          \
-                                     PIN_MODE_INPUT(GPIOB_PIN12) |          \
-                                     PIN_MODE_INPUT(GPIOB_PIN13) |          \
-                                     PIN_MODE_INPUT(GPIOB_PIN14) |          \
-                                     PIN_MODE_INPUT(GPIOB_PIN15))
-#define VAL_GPIOB_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOB_PIN0) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN1) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN2) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN3) |        \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN4) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN5) |       \
-                                     PIN_OTYPE_OPENDRAIN(GPIOB_PIN6) |  \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN7) |  \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN8) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN9) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN10) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN11) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN12) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN13) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN14) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN15))
-#define VAL_GPIOB_OSPEEDR           (PIN_OSPEED_VERYLOW(GPIOB_PIN0) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN1) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN2) |       \
-                                     PIN_OSPEED_HIGH(GPIOB_PIN3) |           \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN4) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN5) |       \
-                                     PIN_OSPEED_HIGH(GPIOB_PIN6) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN7) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN8) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN9) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN10) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN11) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN12) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN13) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN14) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOB_PIN15))
-#define VAL_GPIOB_PUPDR             (PIN_PUPDR_PULLUP(GPIOB_PIN0) |         \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN1) |         \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN2) |         \
-                                     PIN_PUPDR_FLOATING(GPIOB_PIN3) |        \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN4) |         \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN5) |         \
-                                     PIN_PUPDR_FLOATING(GPIOB_PIN6) |   \
-                                     PIN_PUPDR_PULLDOWN(GPIOB_PIN7) |   \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN8) |         \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN9) |         \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN10) |        \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN11) |        \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN12) |        \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN13) |        \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN14) |        \
-                                     PIN_PUPDR_PULLUP(GPIOB_PIN15))
-#define VAL_GPIOB_ODR               (PIN_ODR_HIGH(GPIOB_PIN0) |             \
-                                     PIN_ODR_HIGH(GPIOB_PIN1) |             \
-                                     PIN_ODR_HIGH(GPIOB_PIN2) |             \
-                                     PIN_ODR_HIGH(GPIOB_PIN3) |              \
-                                     PIN_ODR_HIGH(GPIOB_PIN4) |             \
-                                     PIN_ODR_HIGH(GPIOB_PIN5) |             \
-                                     PIN_ODR_HIGH(GPIOB_PIN6) |         \
-                                     PIN_ODR_LOW(GPIOB_PIN7) |         \
-                                     PIN_ODR_HIGH(GPIOB_PIN8) |             \
-                                     PIN_ODR_HIGH(GPIOB_PIN9) |             \
-                                     PIN_ODR_HIGH(GPIOB_PIN10) |            \
-                                     PIN_ODR_HIGH(GPIOB_PIN11) |            \
-                                     PIN_ODR_HIGH(GPIOB_PIN12) |            \
-                                     PIN_ODR_HIGH(GPIOB_PIN13) |            \
-                                     PIN_ODR_HIGH(GPIOB_PIN14) |            \
-                                     PIN_ODR_HIGH(GPIOB_PIN15))
-#define VAL_GPIOB_AFRL              (PIN_AFIO_AF(GPIOB_PIN0, 0) |           \
-                                     PIN_AFIO_AF(GPIOB_PIN1, 0) |           \
-                                     PIN_AFIO_AF(GPIOB_PIN2, 0) |           \
-                                     PIN_AFIO_AF(GPIOB_PIN3, 0) |            \
-                                     PIN_AFIO_AF(GPIOB_PIN4, 0) |           \
-                                     PIN_AFIO_AF(GPIOB_PIN5, 0) |           \
-                                     PIN_AFIO_AF(GPIOB_PIN6, 4) |       \
-                                     PIN_AFIO_AF(GPIOB_PIN7, 0))
-#define VAL_GPIOB_AFRH              (PIN_AFIO_AF(GPIOB_PIN8, 0) |           \
-                                     PIN_AFIO_AF(GPIOB_PIN9, 0) |           \
-                                     PIN_AFIO_AF(GPIOB_PIN10, 0) |          \
-                                     PIN_AFIO_AF(GPIOB_PIN11, 0) |          \
-                                     PIN_AFIO_AF(GPIOB_PIN12, 0) |          \
-                                     PIN_AFIO_AF(GPIOB_PIN13, 0) |          \
-                                     PIN_AFIO_AF(GPIOB_PIN14, 0) |          \
-                                     PIN_AFIO_AF(GPIOB_PIN15, 0))
+#define VAL_GPIOB_MODER (PIN_MODE_INPUT(GPIOB_PIN0) | PIN_MODE_INPUT(GPIOB_PIN1) | PIN_MODE_INPUT(GPIOB_PIN2) | PIN_MODE_ALTERNATE(GPIOB_PIN3) | PIN_MODE_INPUT(GPIOB_PIN4) | PIN_MODE_INPUT(GPIOB_PIN5) | PIN_MODE_ALTERNATE(GPIOB_PIN6) | PIN_MODE_OUTPUT(GPIOB_PIN7) | PIN_MODE_INPUT(GPIOB_PIN8) | PIN_MODE_INPUT(GPIOB_PIN9) | PIN_MODE_INPUT(GPIOB_PIN10) | PIN_MODE_INPUT(GPIOB_PIN11) | PIN_MODE_INPUT(GPIOB_PIN12) | PIN_MODE_INPUT(GPIOB_PIN13) | PIN_MODE_INPUT(GPIOB_PIN14) | PIN_MODE_INPUT(GPIOB_PIN15))
+#define VAL_GPIOB_OTYPER (PIN_OTYPE_PUSHPULL(GPIOB_PIN0) | PIN_OTYPE_PUSHPULL(GPIOB_PIN1) | PIN_OTYPE_PUSHPULL(GPIOB_PIN2) | PIN_OTYPE_PUSHPULL(GPIOB_PIN3) | PIN_OTYPE_PUSHPULL(GPIOB_PIN4) | PIN_OTYPE_PUSHPULL(GPIOB_PIN5) | PIN_OTYPE_OPENDRAIN(GPIOB_PIN6) | PIN_OTYPE_PUSHPULL(GPIOB_PIN7) | PIN_OTYPE_PUSHPULL(GPIOB_PIN8) | PIN_OTYPE_PUSHPULL(GPIOB_PIN9) | PIN_OTYPE_PUSHPULL(GPIOB_PIN10) | PIN_OTYPE_PUSHPULL(GPIOB_PIN11) | PIN_OTYPE_PUSHPULL(GPIOB_PIN12) | PIN_OTYPE_PUSHPULL(GPIOB_PIN13) | PIN_OTYPE_PUSHPULL(GPIOB_PIN14) | PIN_OTYPE_PUSHPULL(GPIOB_PIN15))
+#define VAL_GPIOB_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOB_PIN0) | PIN_OSPEED_VERYLOW(GPIOB_PIN1) | PIN_OSPEED_VERYLOW(GPIOB_PIN2) | PIN_OSPEED_HIGH(GPIOB_PIN3) | PIN_OSPEED_VERYLOW(GPIOB_PIN4) | PIN_OSPEED_VERYLOW(GPIOB_PIN5) | PIN_OSPEED_HIGH(GPIOB_PIN6) | PIN_OSPEED_VERYLOW(GPIOB_PIN7) | PIN_OSPEED_VERYLOW(GPIOB_PIN8) | PIN_OSPEED_VERYLOW(GPIOB_PIN9) | PIN_OSPEED_VERYLOW(GPIOB_PIN10) | PIN_OSPEED_VERYLOW(GPIOB_PIN11) | PIN_OSPEED_VERYLOW(GPIOB_PIN12) | PIN_OSPEED_VERYLOW(GPIOB_PIN13) | PIN_OSPEED_VERYLOW(GPIOB_PIN14) | PIN_OSPEED_VERYLOW(GPIOB_PIN15))
+#define VAL_GPIOB_PUPDR (PIN_PUPDR_PULLUP(GPIOB_PIN0) | PIN_PUPDR_PULLUP(GPIOB_PIN1) | PIN_PUPDR_PULLUP(GPIOB_PIN2) | PIN_PUPDR_FLOATING(GPIOB_PIN3) | PIN_PUPDR_PULLUP(GPIOB_PIN4) | PIN_PUPDR_PULLUP(GPIOB_PIN5) | PIN_PUPDR_FLOATING(GPIOB_PIN6) | PIN_PUPDR_PULLDOWN(GPIOB_PIN7) | PIN_PUPDR_PULLUP(GPIOB_PIN8) | PIN_PUPDR_PULLUP(GPIOB_PIN9) | PIN_PUPDR_PULLUP(GPIOB_PIN10) | PIN_PUPDR_PULLUP(GPIOB_PIN11) | PIN_PUPDR_PULLUP(GPIOB_PIN12) | PIN_PUPDR_PULLUP(GPIOB_PIN13) | PIN_PUPDR_PULLUP(GPIOB_PIN14) | PIN_PUPDR_PULLUP(GPIOB_PIN15))
+#define VAL_GPIOB_ODR (PIN_ODR_HIGH(GPIOB_PIN0) | PIN_ODR_HIGH(GPIOB_PIN1) | PIN_ODR_HIGH(GPIOB_PIN2) | PIN_ODR_HIGH(GPIOB_PIN3) | PIN_ODR_HIGH(GPIOB_PIN4) | PIN_ODR_HIGH(GPIOB_PIN5) | PIN_ODR_HIGH(GPIOB_PIN6) | PIN_ODR_LOW(GPIOB_PIN7) | PIN_ODR_HIGH(GPIOB_PIN8) | PIN_ODR_HIGH(GPIOB_PIN9) | PIN_ODR_HIGH(GPIOB_PIN10) | PIN_ODR_HIGH(GPIOB_PIN11) | PIN_ODR_HIGH(GPIOB_PIN12) | PIN_ODR_HIGH(GPIOB_PIN13) | PIN_ODR_HIGH(GPIOB_PIN14) | PIN_ODR_HIGH(GPIOB_PIN15))
+#define VAL_GPIOB_AFRL (PIN_AFIO_AF(GPIOB_PIN0, 0) | PIN_AFIO_AF(GPIOB_PIN1, 0) | PIN_AFIO_AF(GPIOB_PIN2, 0) | PIN_AFIO_AF(GPIOB_PIN3, 0) | PIN_AFIO_AF(GPIOB_PIN4, 0) | PIN_AFIO_AF(GPIOB_PIN5, 0) | PIN_AFIO_AF(GPIOB_PIN6, 4) | PIN_AFIO_AF(GPIOB_PIN7, 0))
+#define VAL_GPIOB_AFRH (PIN_AFIO_AF(GPIOB_PIN8, 0) | PIN_AFIO_AF(GPIOB_PIN9, 0) | PIN_AFIO_AF(GPIOB_PIN10, 0) | PIN_AFIO_AF(GPIOB_PIN11, 0) | PIN_AFIO_AF(GPIOB_PIN12, 0) | PIN_AFIO_AF(GPIOB_PIN13, 0) | PIN_AFIO_AF(GPIOB_PIN14, 0) | PIN_AFIO_AF(GPIOB_PIN15, 0))
 
 /*
  * GPIOC setup:
  * PC14 - PIN14                  (input floating).
  * PC15 - PIN15                 (input floating).
  */
-#define VAL_GPIOC_MODER             (PIN_MODE_INPUT(GPIOC_PIN0) |           \
-                                     PIN_MODE_INPUT(GPIOC_PIN1) |           \
-                                     PIN_MODE_INPUT(GPIOC_PIN2) |           \
-                                     PIN_MODE_INPUT(GPIOC_PIN3) |           \
-                                     PIN_MODE_INPUT(GPIOC_PIN4) |           \
-                                     PIN_MODE_INPUT(GPIOC_PIN5) |           \
-                                     PIN_MODE_INPUT(GPIOC_PIN6) |           \
-                                     PIN_MODE_INPUT(GPIOC_PIN7) |           \
-                                     PIN_MODE_INPUT(GPIOC_PIN8) |           \
-                                     PIN_MODE_INPUT(GPIOC_PIN9) |           \
-                                     PIN_MODE_INPUT(GPIOC_PIN10) |          \
-                                     PIN_MODE_INPUT(GPIOC_PIN11) |          \
-                                     PIN_MODE_INPUT(GPIOC_PIN12) |          \
-                                     PIN_MODE_INPUT(GPIOC_PIN13) |          \
-                                     PIN_MODE_INPUT(GPIOC_PIN14) |       \
-                                     PIN_MODE_INPUT(GPIOC_PIN15))
-#define VAL_GPIOC_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOC_PIN0) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN1) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN2) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN3) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN4) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN5) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN6) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN7) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN8) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN9) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN10) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN11) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN12) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN13) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN14) |   \
-                                     PIN_OTYPE_PUSHPULL(GPIOC_PIN15))
-#define VAL_GPIOC_OSPEEDR           (PIN_OSPEED_VERYLOW(GPIOC_PIN0) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN1) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN2) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN3) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN4) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN5) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN6) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN7) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN8) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN9) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN10) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN11) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN12) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOC_PIN13) |      \
-                                     PIN_OSPEED_HIGH(GPIOC_PIN14) |      \
-                                     PIN_OSPEED_HIGH(GPIOC_PIN15))
-#define VAL_GPIOC_PUPDR             (PIN_PUPDR_PULLUP(GPIOC_PIN0) |         \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN1) |         \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN2) |         \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN3) |         \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN4) |         \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN5) |         \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN6) |         \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN7) |         \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN8) |         \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN9) |         \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN10) |        \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN11) |        \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN12) |        \
-                                     PIN_PUPDR_PULLUP(GPIOC_PIN13) |        \
-                                     PIN_PUPDR_FLOATING(GPIOC_PIN14) |   \
-                                     PIN_PUPDR_FLOATING(GPIOC_PIN15))
-#define VAL_GPIOC_ODR               (PIN_ODR_HIGH(GPIOC_PIN0) |             \
-                                     PIN_ODR_HIGH(GPIOC_PIN1) |             \
-                                     PIN_ODR_HIGH(GPIOC_PIN2) |             \
-                                     PIN_ODR_HIGH(GPIOC_PIN3) |             \
-                                     PIN_ODR_HIGH(GPIOC_PIN4) |             \
-                                     PIN_ODR_HIGH(GPIOC_PIN5) |             \
-                                     PIN_ODR_HIGH(GPIOC_PIN6) |             \
-                                     PIN_ODR_HIGH(GPIOC_PIN7) |             \
-                                     PIN_ODR_HIGH(GPIOC_PIN8) |             \
-                                     PIN_ODR_HIGH(GPIOC_PIN9) |             \
-                                     PIN_ODR_HIGH(GPIOC_PIN10) |            \
-                                     PIN_ODR_HIGH(GPIOC_PIN11) |            \
-                                     PIN_ODR_HIGH(GPIOC_PIN12) |            \
-                                     PIN_ODR_HIGH(GPIOC_PIN13) |            \
-                                     PIN_ODR_HIGH(GPIOC_PIN14) |         \
-                                     PIN_ODR_HIGH(GPIOC_PIN15))
-#define VAL_GPIOC_AFRL              (PIN_AFIO_AF(GPIOC_PIN0, 0) |           \
-                                     PIN_AFIO_AF(GPIOC_PIN1, 0) |           \
-                                     PIN_AFIO_AF(GPIOC_PIN2, 0) |           \
-                                     PIN_AFIO_AF(GPIOC_PIN3, 0) |           \
-                                     PIN_AFIO_AF(GPIOC_PIN4, 0) |           \
-                                     PIN_AFIO_AF(GPIOC_PIN5, 0) |           \
-                                     PIN_AFIO_AF(GPIOC_PIN6, 0) |           \
-                                     PIN_AFIO_AF(GPIOC_PIN7, 0))
-#define VAL_GPIOC_AFRH              (PIN_AFIO_AF(GPIOC_PIN8, 0) |           \
-                                     PIN_AFIO_AF(GPIOC_PIN9, 0) |           \
-                                     PIN_AFIO_AF(GPIOC_PIN10, 0) |          \
-                                     PIN_AFIO_AF(GPIOC_PIN11, 0) |          \
-                                     PIN_AFIO_AF(GPIOC_PIN12, 0) |          \
-                                     PIN_AFIO_AF(GPIOC_PIN13, 0) |          \
-                                     PIN_AFIO_AF(GPIOC_PIN14, 0) |       \
-                                     PIN_AFIO_AF(GPIOC_PIN15, 0))
+#define VAL_GPIOC_MODER (PIN_MODE_INPUT(GPIOC_PIN0) | PIN_MODE_INPUT(GPIOC_PIN1) | PIN_MODE_INPUT(GPIOC_PIN2) | PIN_MODE_INPUT(GPIOC_PIN3) | PIN_MODE_INPUT(GPIOC_PIN4) | PIN_MODE_INPUT(GPIOC_PIN5) | PIN_MODE_INPUT(GPIOC_PIN6) | PIN_MODE_INPUT(GPIOC_PIN7) | PIN_MODE_INPUT(GPIOC_PIN8) | PIN_MODE_INPUT(GPIOC_PIN9) | PIN_MODE_INPUT(GPIOC_PIN10) | PIN_MODE_INPUT(GPIOC_PIN11) | PIN_MODE_INPUT(GPIOC_PIN12) | PIN_MODE_INPUT(GPIOC_PIN13) | PIN_MODE_INPUT(GPIOC_PIN14) | PIN_MODE_INPUT(GPIOC_PIN15))
+#define VAL_GPIOC_OTYPER (PIN_OTYPE_PUSHPULL(GPIOC_PIN0) | PIN_OTYPE_PUSHPULL(GPIOC_PIN1) | PIN_OTYPE_PUSHPULL(GPIOC_PIN2) | PIN_OTYPE_PUSHPULL(GPIOC_PIN3) | PIN_OTYPE_PUSHPULL(GPIOC_PIN4) | PIN_OTYPE_PUSHPULL(GPIOC_PIN5) | PIN_OTYPE_PUSHPULL(GPIOC_PIN6) | PIN_OTYPE_PUSHPULL(GPIOC_PIN7) | PIN_OTYPE_PUSHPULL(GPIOC_PIN8) | PIN_OTYPE_PUSHPULL(GPIOC_PIN9) | PIN_OTYPE_PUSHPULL(GPIOC_PIN10) | PIN_OTYPE_PUSHPULL(GPIOC_PIN11) | PIN_OTYPE_PUSHPULL(GPIOC_PIN12) | PIN_OTYPE_PUSHPULL(GPIOC_PIN13) | PIN_OTYPE_PUSHPULL(GPIOC_PIN14) | PIN_OTYPE_PUSHPULL(GPIOC_PIN15))
+#define VAL_GPIOC_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOC_PIN0) | PIN_OSPEED_VERYLOW(GPIOC_PIN1) | PIN_OSPEED_VERYLOW(GPIOC_PIN2) | PIN_OSPEED_VERYLOW(GPIOC_PIN3) | PIN_OSPEED_VERYLOW(GPIOC_PIN4) | PIN_OSPEED_VERYLOW(GPIOC_PIN5) | PIN_OSPEED_VERYLOW(GPIOC_PIN6) | PIN_OSPEED_VERYLOW(GPIOC_PIN7) | PIN_OSPEED_VERYLOW(GPIOC_PIN8) | PIN_OSPEED_VERYLOW(GPIOC_PIN9) | PIN_OSPEED_VERYLOW(GPIOC_PIN10) | PIN_OSPEED_VERYLOW(GPIOC_PIN11) | PIN_OSPEED_VERYLOW(GPIOC_PIN12) | PIN_OSPEED_VERYLOW(GPIOC_PIN13) | PIN_OSPEED_HIGH(GPIOC_PIN14) | PIN_OSPEED_HIGH(GPIOC_PIN15))
+#define VAL_GPIOC_PUPDR (PIN_PUPDR_PULLUP(GPIOC_PIN0) | PIN_PUPDR_PULLUP(GPIOC_PIN1) | PIN_PUPDR_PULLUP(GPIOC_PIN2) | PIN_PUPDR_PULLUP(GPIOC_PIN3) | PIN_PUPDR_PULLUP(GPIOC_PIN4) | PIN_PUPDR_PULLUP(GPIOC_PIN5) | PIN_PUPDR_PULLUP(GPIOC_PIN6) | PIN_PUPDR_PULLUP(GPIOC_PIN7) | PIN_PUPDR_PULLUP(GPIOC_PIN8) | PIN_PUPDR_PULLUP(GPIOC_PIN9) | PIN_PUPDR_PULLUP(GPIOC_PIN10) | PIN_PUPDR_PULLUP(GPIOC_PIN11) | PIN_PUPDR_PULLUP(GPIOC_PIN12) | PIN_PUPDR_PULLUP(GPIOC_PIN13) | PIN_PUPDR_FLOATING(GPIOC_PIN14) | PIN_PUPDR_FLOATING(GPIOC_PIN15))
+#define VAL_GPIOC_ODR (PIN_ODR_HIGH(GPIOC_PIN0) | PIN_ODR_HIGH(GPIOC_PIN1) | PIN_ODR_HIGH(GPIOC_PIN2) | PIN_ODR_HIGH(GPIOC_PIN3) | PIN_ODR_HIGH(GPIOC_PIN4) | PIN_ODR_HIGH(GPIOC_PIN5) | PIN_ODR_HIGH(GPIOC_PIN6) | PIN_ODR_HIGH(GPIOC_PIN7) | PIN_ODR_HIGH(GPIOC_PIN8) | PIN_ODR_HIGH(GPIOC_PIN9) | PIN_ODR_HIGH(GPIOC_PIN10) | PIN_ODR_HIGH(GPIOC_PIN11) | PIN_ODR_HIGH(GPIOC_PIN12) | PIN_ODR_HIGH(GPIOC_PIN13) | PIN_ODR_HIGH(GPIOC_PIN14) | PIN_ODR_HIGH(GPIOC_PIN15))
+#define VAL_GPIOC_AFRL (PIN_AFIO_AF(GPIOC_PIN0, 0) | PIN_AFIO_AF(GPIOC_PIN1, 0) | PIN_AFIO_AF(GPIOC_PIN2, 0) | PIN_AFIO_AF(GPIOC_PIN3, 0) | PIN_AFIO_AF(GPIOC_PIN4, 0) | PIN_AFIO_AF(GPIOC_PIN5, 0) | PIN_AFIO_AF(GPIOC_PIN6, 0) | PIN_AFIO_AF(GPIOC_PIN7, 0))
+#define VAL_GPIOC_AFRH (PIN_AFIO_AF(GPIOC_PIN8, 0) | PIN_AFIO_AF(GPIOC_PIN9, 0) | PIN_AFIO_AF(GPIOC_PIN10, 0) | PIN_AFIO_AF(GPIOC_PIN11, 0) | PIN_AFIO_AF(GPIOC_PIN12, 0) | PIN_AFIO_AF(GPIOC_PIN13, 0) | PIN_AFIO_AF(GPIOC_PIN14, 0) | PIN_AFIO_AF(GPIOC_PIN15, 0))
 
 /*
  * GPIOD setup:
  * PD14 - PIN14                     (input pullup).
  * PD15 - PIN15                     (input pullup).
  */
-#define VAL_GPIOD_MODER             (PIN_MODE_INPUT(GPIOD_PIN0) |           \
-                                     PIN_MODE_INPUT(GPIOD_PIN1) |           \
-                                     PIN_MODE_INPUT(GPIOD_PIN2) |           \
-                                     PIN_MODE_INPUT(GPIOD_PIN3) |           \
-                                     PIN_MODE_INPUT(GPIOD_PIN4) |           \
-                                     PIN_MODE_INPUT(GPIOD_PIN5) |           \
-                                     PIN_MODE_INPUT(GPIOD_PIN6) |           \
-                                     PIN_MODE_INPUT(GPIOD_PIN7) |           \
-                                     PIN_MODE_INPUT(GPIOD_PIN8) |           \
-                                     PIN_MODE_INPUT(GPIOD_PIN9) |           \
-                                     PIN_MODE_INPUT(GPIOD_PIN10) |          \
-                                     PIN_MODE_INPUT(GPIOD_PIN11) |          \
-                                     PIN_MODE_INPUT(GPIOD_PIN12) |          \
-                                     PIN_MODE_INPUT(GPIOD_PIN13) |          \
-                                     PIN_MODE_INPUT(GPIOD_PIN14) |          \
-                                     PIN_MODE_INPUT(GPIOD_PIN15))
-#define VAL_GPIOD_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOD_PIN0) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN1) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN2) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN3) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN4) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN5) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN6) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN7) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN8) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN9) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN10) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN11) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN12) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN13) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN14) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOD_PIN15))
-#define VAL_GPIOD_OSPEEDR           (PIN_OSPEED_VERYLOW(GPIOD_PIN0) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN1) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN2) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN3) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN4) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN5) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN6) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN7) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN8) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN9) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN10) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN11) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN12) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN13) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN14) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOD_PIN15))
-#define VAL_GPIOD_PUPDR             (PIN_PUPDR_PULLUP(GPIOD_PIN0) |         \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN1) |         \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN2) |         \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN3) |         \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN4) |         \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN5) |         \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN6) |         \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN7) |         \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN8) |         \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN9) |         \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN10) |        \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN11) |        \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN12) |        \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN13) |        \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN14) |        \
-                                     PIN_PUPDR_PULLUP(GPIOD_PIN15))
-#define VAL_GPIOD_ODR               (PIN_ODR_HIGH(GPIOD_PIN0) |             \
-                                     PIN_ODR_HIGH(GPIOD_PIN1) |             \
-                                     PIN_ODR_HIGH(GPIOD_PIN2) |             \
-                                     PIN_ODR_HIGH(GPIOD_PIN3) |             \
-                                     PIN_ODR_HIGH(GPIOD_PIN4) |             \
-                                     PIN_ODR_HIGH(GPIOD_PIN5) |             \
-                                     PIN_ODR_HIGH(GPIOD_PIN6) |             \
-                                     PIN_ODR_HIGH(GPIOD_PIN7) |             \
-                                     PIN_ODR_HIGH(GPIOD_PIN8) |             \
-                                     PIN_ODR_HIGH(GPIOD_PIN9) |             \
-                                     PIN_ODR_HIGH(GPIOD_PIN10) |            \
-                                     PIN_ODR_HIGH(GPIOD_PIN11) |            \
-                                     PIN_ODR_HIGH(GPIOD_PIN12) |            \
-                                     PIN_ODR_HIGH(GPIOD_PIN13) |            \
-                                     PIN_ODR_HIGH(GPIOD_PIN14) |            \
-                                     PIN_ODR_HIGH(GPIOD_PIN15))
-#define VAL_GPIOD_AFRL              (PIN_AFIO_AF(GPIOD_PIN0, 0) |           \
-                                     PIN_AFIO_AF(GPIOD_PIN1, 0) |           \
-                                     PIN_AFIO_AF(GPIOD_PIN2, 0) |           \
-                                     PIN_AFIO_AF(GPIOD_PIN3, 0) |           \
-                                     PIN_AFIO_AF(GPIOD_PIN4, 0) |           \
-                                     PIN_AFIO_AF(GPIOD_PIN5, 0) |           \
-                                     PIN_AFIO_AF(GPIOD_PIN6, 0) |           \
-                                     PIN_AFIO_AF(GPIOD_PIN7, 0))
-#define VAL_GPIOD_AFRH              (PIN_AFIO_AF(GPIOD_PIN8, 0) |           \
-                                     PIN_AFIO_AF(GPIOD_PIN9, 0) |           \
-                                     PIN_AFIO_AF(GPIOD_PIN10, 0) |          \
-                                     PIN_AFIO_AF(GPIOD_PIN11, 0) |          \
-                                     PIN_AFIO_AF(GPIOD_PIN12, 0) |          \
-                                     PIN_AFIO_AF(GPIOD_PIN13, 0) |          \
-                                     PIN_AFIO_AF(GPIOD_PIN14, 0) |          \
-                                     PIN_AFIO_AF(GPIOD_PIN15, 0))
+#define VAL_GPIOD_MODER (PIN_MODE_INPUT(GPIOD_PIN0) | PIN_MODE_INPUT(GPIOD_PIN1) | PIN_MODE_INPUT(GPIOD_PIN2) | PIN_MODE_INPUT(GPIOD_PIN3) | PIN_MODE_INPUT(GPIOD_PIN4) | PIN_MODE_INPUT(GPIOD_PIN5) | PIN_MODE_INPUT(GPIOD_PIN6) | PIN_MODE_INPUT(GPIOD_PIN7) | PIN_MODE_INPUT(GPIOD_PIN8) | PIN_MODE_INPUT(GPIOD_PIN9) | PIN_MODE_INPUT(GPIOD_PIN10) | PIN_MODE_INPUT(GPIOD_PIN11) | PIN_MODE_INPUT(GPIOD_PIN12) | PIN_MODE_INPUT(GPIOD_PIN13) | PIN_MODE_INPUT(GPIOD_PIN14) | PIN_MODE_INPUT(GPIOD_PIN15))
+#define VAL_GPIOD_OTYPER (PIN_OTYPE_PUSHPULL(GPIOD_PIN0) | PIN_OTYPE_PUSHPULL(GPIOD_PIN1) | PIN_OTYPE_PUSHPULL(GPIOD_PIN2) | PIN_OTYPE_PUSHPULL(GPIOD_PIN3) | PIN_OTYPE_PUSHPULL(GPIOD_PIN4) | PIN_OTYPE_PUSHPULL(GPIOD_PIN5) | PIN_OTYPE_PUSHPULL(GPIOD_PIN6) | PIN_OTYPE_PUSHPULL(GPIOD_PIN7) | PIN_OTYPE_PUSHPULL(GPIOD_PIN8) | PIN_OTYPE_PUSHPULL(GPIOD_PIN9) | PIN_OTYPE_PUSHPULL(GPIOD_PIN10) | PIN_OTYPE_PUSHPULL(GPIOD_PIN11) | PIN_OTYPE_PUSHPULL(GPIOD_PIN12) | PIN_OTYPE_PUSHPULL(GPIOD_PIN13) | PIN_OTYPE_PUSHPULL(GPIOD_PIN14) | PIN_OTYPE_PUSHPULL(GPIOD_PIN15))
+#define VAL_GPIOD_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOD_PIN0) | PIN_OSPEED_VERYLOW(GPIOD_PIN1) | PIN_OSPEED_VERYLOW(GPIOD_PIN2) | PIN_OSPEED_VERYLOW(GPIOD_PIN3) | PIN_OSPEED_VERYLOW(GPIOD_PIN4) | PIN_OSPEED_VERYLOW(GPIOD_PIN5) | PIN_OSPEED_VERYLOW(GPIOD_PIN6) | PIN_OSPEED_VERYLOW(GPIOD_PIN7) | PIN_OSPEED_VERYLOW(GPIOD_PIN8) | PIN_OSPEED_VERYLOW(GPIOD_PIN9) | PIN_OSPEED_VERYLOW(GPIOD_PIN10) | PIN_OSPEED_VERYLOW(GPIOD_PIN11) | PIN_OSPEED_VERYLOW(GPIOD_PIN12) | PIN_OSPEED_VERYLOW(GPIOD_PIN13) | PIN_OSPEED_VERYLOW(GPIOD_PIN14) | PIN_OSPEED_VERYLOW(GPIOD_PIN15))
+#define VAL_GPIOD_PUPDR (PIN_PUPDR_PULLUP(GPIOD_PIN0) | PIN_PUPDR_PULLUP(GPIOD_PIN1) | PIN_PUPDR_PULLUP(GPIOD_PIN2) | PIN_PUPDR_PULLUP(GPIOD_PIN3) | PIN_PUPDR_PULLUP(GPIOD_PIN4) | PIN_PUPDR_PULLUP(GPIOD_PIN5) | PIN_PUPDR_PULLUP(GPIOD_PIN6) | PIN_PUPDR_PULLUP(GPIOD_PIN7) | PIN_PUPDR_PULLUP(GPIOD_PIN8) | PIN_PUPDR_PULLUP(GPIOD_PIN9) | PIN_PUPDR_PULLUP(GPIOD_PIN10) | PIN_PUPDR_PULLUP(GPIOD_PIN11) | PIN_PUPDR_PULLUP(GPIOD_PIN12) | PIN_PUPDR_PULLUP(GPIOD_PIN13) | PIN_PUPDR_PULLUP(GPIOD_PIN14) | PIN_PUPDR_PULLUP(GPIOD_PIN15))
+#define VAL_GPIOD_ODR (PIN_ODR_HIGH(GPIOD_PIN0) | PIN_ODR_HIGH(GPIOD_PIN1) | PIN_ODR_HIGH(GPIOD_PIN2) | PIN_ODR_HIGH(GPIOD_PIN3) | PIN_ODR_HIGH(GPIOD_PIN4) | PIN_ODR_HIGH(GPIOD_PIN5) | PIN_ODR_HIGH(GPIOD_PIN6) | PIN_ODR_HIGH(GPIOD_PIN7) | PIN_ODR_HIGH(GPIOD_PIN8) | PIN_ODR_HIGH(GPIOD_PIN9) | PIN_ODR_HIGH(GPIOD_PIN10) | PIN_ODR_HIGH(GPIOD_PIN11) | PIN_ODR_HIGH(GPIOD_PIN12) | PIN_ODR_HIGH(GPIOD_PIN13) | PIN_ODR_HIGH(GPIOD_PIN14) | PIN_ODR_HIGH(GPIOD_PIN15))
+#define VAL_GPIOD_AFRL (PIN_AFIO_AF(GPIOD_PIN0, 0) | PIN_AFIO_AF(GPIOD_PIN1, 0) | PIN_AFIO_AF(GPIOD_PIN2, 0) | PIN_AFIO_AF(GPIOD_PIN3, 0) | PIN_AFIO_AF(GPIOD_PIN4, 0) | PIN_AFIO_AF(GPIOD_PIN5, 0) | PIN_AFIO_AF(GPIOD_PIN6, 0) | PIN_AFIO_AF(GPIOD_PIN7, 0))
+#define VAL_GPIOD_AFRH (PIN_AFIO_AF(GPIOD_PIN8, 0) | PIN_AFIO_AF(GPIOD_PIN9, 0) | PIN_AFIO_AF(GPIOD_PIN10, 0) | PIN_AFIO_AF(GPIOD_PIN11, 0) | PIN_AFIO_AF(GPIOD_PIN12, 0) | PIN_AFIO_AF(GPIOD_PIN13, 0) | PIN_AFIO_AF(GPIOD_PIN14, 0) | PIN_AFIO_AF(GPIOD_PIN15, 0))
 
 /*
  * GPIOE setup:
  * PE14 - PIN14               (output pushpull maximum).
  * PE15 - PIN15                (output pushpull maximum).
  */
-#define VAL_GPIOE_MODER             (PIN_MODE_INPUT(GPIOE_PIN0) |    \
-                                     PIN_MODE_INPUT(GPIOE_PIN1) |    \
-                                     PIN_MODE_INPUT(GPIOE_PIN2) |\
-                                     PIN_MODE_OUTPUT(GPIOE_PIN3) |       \
-                                     PIN_MODE_INPUT(GPIOE_PIN4) |\
-                                     PIN_MODE_INPUT(GPIOE_PIN5) |\
-                                     PIN_MODE_INPUT(GPIOE_PIN6) |           \
-                                     PIN_MODE_INPUT(GPIOE_PIN7) |           \
-                                     PIN_MODE_OUTPUT(GPIOE_PIN8) |     \
-                                     PIN_MODE_OUTPUT(GPIOE_PIN9) |      \
-                                     PIN_MODE_OUTPUT(GPIOE_PIN10) |   \
-                                     PIN_MODE_OUTPUT(GPIOE_PIN11) |    \
-                                     PIN_MODE_OUTPUT(GPIOE_PIN12) |     \
-                                     PIN_MODE_OUTPUT(GPIOE_PIN13) |     \
-                                     PIN_MODE_OUTPUT(GPIOE_PIN14) |   \
-                                     PIN_MODE_OUTPUT(GPIOE_PIN15))
-#define VAL_GPIOE_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOE_PIN0) |\
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN1) |\
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN2) |\
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN3) |    \
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN4) |\
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN5) |\
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN6) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN7) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN8) |  \
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN9) |   \
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN10) |\
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN11) | \
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN12) |  \
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN13) |  \
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN14) |\
-                                     PIN_OTYPE_PUSHPULL(GPIOE_PIN15))
-#define VAL_GPIOE_OSPEEDR           (PIN_OSPEED_VERYLOW(GPIOE_PIN0) |\
-                                     PIN_OSPEED_VERYLOW(GPIOE_PIN1) |\
-                                     PIN_OSPEED_VERYLOW(GPIOE_PIN2) |\
-                                     PIN_OSPEED_HIGH(GPIOE_PIN3) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOE_PIN4) |\
-                                     PIN_OSPEED_VERYLOW(GPIOE_PIN5) |\
-                                     PIN_OSPEED_VERYLOW(GPIOE_PIN6) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOE_PIN7) |       \
-                                     PIN_OSPEED_HIGH(GPIOE_PIN8) |     \
-                                     PIN_OSPEED_HIGH(GPIOE_PIN9) |      \
-                                     PIN_OSPEED_HIGH(GPIOE_PIN10) |   \
-                                     PIN_OSPEED_HIGH(GPIOE_PIN11) |    \
-                                     PIN_OSPEED_HIGH(GPIOE_PIN12) |     \
-                                     PIN_OSPEED_HIGH(GPIOE_PIN13) |     \
-                                     PIN_OSPEED_HIGH(GPIOE_PIN14) |   \
-                                     PIN_OSPEED_HIGH(GPIOE_PIN15))
-#define VAL_GPIOE_PUPDR             (PIN_PUPDR_PULLUP(GPIOE_PIN0) |  \
-                                     PIN_PUPDR_PULLUP(GPIOE_PIN1) |  \
-                                     PIN_PUPDR_PULLUP(GPIOE_PIN2) |\
-                                     PIN_PUPDR_FLOATING(GPIOE_PIN3) |    \
-                                     PIN_PUPDR_PULLUP(GPIOE_PIN4) |\
-                                     PIN_PUPDR_PULLUP(GPIOE_PIN5) |\
-                                     PIN_PUPDR_PULLUP(GPIOE_PIN6) |         \
-                                     PIN_PUPDR_PULLUP(GPIOE_PIN7) |         \
-                                     PIN_PUPDR_PULLUP(GPIOE_PIN8) |    \
-                                     PIN_PUPDR_PULLUP(GPIOE_PIN9) |     \
-                                     PIN_PUPDR_PULLUP(GPIOE_PIN10) |  \
-                                     PIN_PUPDR_FLOATING(GPIOE_PIN11) | \
-                                     PIN_PUPDR_PULLUP(GPIOE_PIN12) |    \
-                                     PIN_PUPDR_FLOATING(GPIOE_PIN13) |  \
-                                     PIN_PUPDR_FLOATING(GPIOE_PIN14) |\
-                                     PIN_PUPDR_FLOATING(GPIOE_PIN15))
-#define VAL_GPIOE_ODR               (PIN_ODR_HIGH(GPIOE_PIN0) |      \
-                                     PIN_ODR_HIGH(GPIOE_PIN1) |      \
-                                     PIN_ODR_HIGH(GPIOE_PIN2) |  \
-                                     PIN_ODR_HIGH(GPIOE_PIN3) |          \
-                                     PIN_ODR_HIGH(GPIOE_PIN4) |  \
-                                     PIN_ODR_HIGH(GPIOE_PIN5) |  \
-                                     PIN_ODR_HIGH(GPIOE_PIN6) |             \
-                                     PIN_ODR_HIGH(GPIOE_PIN7) |             \
-                                     PIN_ODR_LOW(GPIOE_PIN8) |         \
-                                     PIN_ODR_LOW(GPIOE_PIN9) |          \
-                                     PIN_ODR_LOW(GPIOE_PIN10) |       \
-                                     PIN_ODR_LOW(GPIOE_PIN11) |        \
-                                     PIN_ODR_LOW(GPIOE_PIN12) |         \
-                                     PIN_ODR_LOW(GPIOE_PIN13) |         \
-                                     PIN_ODR_LOW(GPIOE_PIN14) |       \
-                                     PIN_ODR_LOW(GPIOE_PIN15))
-#define VAL_GPIOE_AFRL              (PIN_AFIO_AF(GPIOE_PIN0, 0) |    \
-                                     PIN_AFIO_AF(GPIOE_PIN1, 0) |    \
-                                     PIN_AFIO_AF(GPIOE_PIN2, 0) |\
-                                     PIN_AFIO_AF(GPIOE_PIN3, 0) |        \
-                                     PIN_AFIO_AF(GPIOE_PIN4, 0) |\
-                                     PIN_AFIO_AF(GPIOE_PIN5, 0) |\
-                                     PIN_AFIO_AF(GPIOE_PIN6, 0) |           \
-                                     PIN_AFIO_AF(GPIOE_PIN7, 0))
-#define VAL_GPIOE_AFRH              (PIN_AFIO_AF(GPIOE_PIN8, 0) |      \
-                                     PIN_AFIO_AF(GPIOE_PIN9, 0) |       \
-                                     PIN_AFIO_AF(GPIOE_PIN10, 0) |    \
-                                     PIN_AFIO_AF(GPIOE_PIN11, 0) |     \
-                                     PIN_AFIO_AF(GPIOE_PIN12, 0) |      \
-                                     PIN_AFIO_AF(GPIOE_PIN13, 0) |      \
-                                     PIN_AFIO_AF(GPIOE_PIN14, 0) |    \
-                                     PIN_AFIO_AF(GPIOE_PIN15, 0))
+#define VAL_GPIOE_MODER (PIN_MODE_INPUT(GPIOE_PIN0) | PIN_MODE_INPUT(GPIOE_PIN1) | PIN_MODE_INPUT(GPIOE_PIN2) | PIN_MODE_OUTPUT(GPIOE_PIN3) | PIN_MODE_INPUT(GPIOE_PIN4) | PIN_MODE_INPUT(GPIOE_PIN5) | PIN_MODE_INPUT(GPIOE_PIN6) | PIN_MODE_INPUT(GPIOE_PIN7) | PIN_MODE_OUTPUT(GPIOE_PIN8) | PIN_MODE_OUTPUT(GPIOE_PIN9) | PIN_MODE_OUTPUT(GPIOE_PIN10) | PIN_MODE_OUTPUT(GPIOE_PIN11) | PIN_MODE_OUTPUT(GPIOE_PIN12) | PIN_MODE_OUTPUT(GPIOE_PIN13) | PIN_MODE_OUTPUT(GPIOE_PIN14) | PIN_MODE_OUTPUT(GPIOE_PIN15))
+#define VAL_GPIOE_OTYPER (PIN_OTYPE_PUSHPULL(GPIOE_PIN0) | PIN_OTYPE_PUSHPULL(GPIOE_PIN1) | PIN_OTYPE_PUSHPULL(GPIOE_PIN2) | PIN_OTYPE_PUSHPULL(GPIOE_PIN3) | PIN_OTYPE_PUSHPULL(GPIOE_PIN4) | PIN_OTYPE_PUSHPULL(GPIOE_PIN5) | PIN_OTYPE_PUSHPULL(GPIOE_PIN6) | PIN_OTYPE_PUSHPULL(GPIOE_PIN7) | PIN_OTYPE_PUSHPULL(GPIOE_PIN8) | PIN_OTYPE_PUSHPULL(GPIOE_PIN9) | PIN_OTYPE_PUSHPULL(GPIOE_PIN10) | PIN_OTYPE_PUSHPULL(GPIOE_PIN11) | PIN_OTYPE_PUSHPULL(GPIOE_PIN12) | PIN_OTYPE_PUSHPULL(GPIOE_PIN13) | PIN_OTYPE_PUSHPULL(GPIOE_PIN14) | PIN_OTYPE_PUSHPULL(GPIOE_PIN15))
+#define VAL_GPIOE_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOE_PIN0) | PIN_OSPEED_VERYLOW(GPIOE_PIN1) | PIN_OSPEED_VERYLOW(GPIOE_PIN2) | PIN_OSPEED_HIGH(GPIOE_PIN3) | PIN_OSPEED_VERYLOW(GPIOE_PIN4) | PIN_OSPEED_VERYLOW(GPIOE_PIN5) | PIN_OSPEED_VERYLOW(GPIOE_PIN6) | PIN_OSPEED_VERYLOW(GPIOE_PIN7) | PIN_OSPEED_HIGH(GPIOE_PIN8) | PIN_OSPEED_HIGH(GPIOE_PIN9) | PIN_OSPEED_HIGH(GPIOE_PIN10) | PIN_OSPEED_HIGH(GPIOE_PIN11) | PIN_OSPEED_HIGH(GPIOE_PIN12) | PIN_OSPEED_HIGH(GPIOE_PIN13) | PIN_OSPEED_HIGH(GPIOE_PIN14) | PIN_OSPEED_HIGH(GPIOE_PIN15))
+#define VAL_GPIOE_PUPDR (PIN_PUPDR_PULLUP(GPIOE_PIN0) | PIN_PUPDR_PULLUP(GPIOE_PIN1) | PIN_PUPDR_PULLUP(GPIOE_PIN2) | PIN_PUPDR_FLOATING(GPIOE_PIN3) | PIN_PUPDR_PULLUP(GPIOE_PIN4) | PIN_PUPDR_PULLUP(GPIOE_PIN5) | PIN_PUPDR_PULLUP(GPIOE_PIN6) | PIN_PUPDR_PULLUP(GPIOE_PIN7) | PIN_PUPDR_PULLUP(GPIOE_PIN8) | PIN_PUPDR_PULLUP(GPIOE_PIN9) | PIN_PUPDR_PULLUP(GPIOE_PIN10) | PIN_PUPDR_FLOATING(GPIOE_PIN11) | PIN_PUPDR_PULLUP(GPIOE_PIN12) | PIN_PUPDR_FLOATING(GPIOE_PIN13) | PIN_PUPDR_FLOATING(GPIOE_PIN14) | PIN_PUPDR_FLOATING(GPIOE_PIN15))
+#define VAL_GPIOE_ODR (PIN_ODR_HIGH(GPIOE_PIN0) | PIN_ODR_HIGH(GPIOE_PIN1) | PIN_ODR_HIGH(GPIOE_PIN2) | PIN_ODR_HIGH(GPIOE_PIN3) | PIN_ODR_HIGH(GPIOE_PIN4) | PIN_ODR_HIGH(GPIOE_PIN5) | PIN_ODR_HIGH(GPIOE_PIN6) | PIN_ODR_HIGH(GPIOE_PIN7) | PIN_ODR_LOW(GPIOE_PIN8) | PIN_ODR_LOW(GPIOE_PIN9) | PIN_ODR_LOW(GPIOE_PIN10) | PIN_ODR_LOW(GPIOE_PIN11) | PIN_ODR_LOW(GPIOE_PIN12) | PIN_ODR_LOW(GPIOE_PIN13) | PIN_ODR_LOW(GPIOE_PIN14) | PIN_ODR_LOW(GPIOE_PIN15))
+#define VAL_GPIOE_AFRL (PIN_AFIO_AF(GPIOE_PIN0, 0) | PIN_AFIO_AF(GPIOE_PIN1, 0) | PIN_AFIO_AF(GPIOE_PIN2, 0) | PIN_AFIO_AF(GPIOE_PIN3, 0) | PIN_AFIO_AF(GPIOE_PIN4, 0) | PIN_AFIO_AF(GPIOE_PIN5, 0) | PIN_AFIO_AF(GPIOE_PIN6, 0) | PIN_AFIO_AF(GPIOE_PIN7, 0))
+#define VAL_GPIOE_AFRH (PIN_AFIO_AF(GPIOE_PIN8, 0) | PIN_AFIO_AF(GPIOE_PIN9, 0) | PIN_AFIO_AF(GPIOE_PIN10, 0) | PIN_AFIO_AF(GPIOE_PIN11, 0) | PIN_AFIO_AF(GPIOE_PIN12, 0) | PIN_AFIO_AF(GPIOE_PIN13, 0) | PIN_AFIO_AF(GPIOE_PIN14, 0) | PIN_AFIO_AF(GPIOE_PIN15, 0))
 
 /*
  * GPIOF setup:
  * PF14 - PIN14                     (input pullup).
  * PF15 - PIN15                     (input pullup).
  */
-#define VAL_GPIOF_MODER             (PIN_MODE_INPUT(GPIOF_I2C2_SDA) |         \
-                                     PIN_MODE_INPUT(GPIOF_I2C2_SCL) |        \
-                                     PIN_MODE_INPUT(GPIOF_PIN2) |           \
-                                     PIN_MODE_INPUT(GPIOF_PIN3) |           \
-                                     PIN_MODE_INPUT(GPIOF_PIN4) |           \
-                                     PIN_MODE_INPUT(GPIOF_PIN5) |           \
-                                     PIN_MODE_INPUT(GPIOF_PIN6) |           \
-                                     PIN_MODE_INPUT(GPIOF_PIN7) |           \
-                                     PIN_MODE_INPUT(GPIOF_PIN8) |           \
-                                     PIN_MODE_INPUT(GPIOF_PIN9) |           \
-                                     PIN_MODE_INPUT(GPIOF_PIN10) |          \
-                                     PIN_MODE_INPUT(GPIOF_PIN11) |          \
-                                     PIN_MODE_INPUT(GPIOF_PIN12) |          \
-                                     PIN_MODE_INPUT(GPIOF_PIN13) |          \
-                                     PIN_MODE_INPUT(GPIOF_PIN14) |          \
-                                     PIN_MODE_INPUT(GPIOF_PIN15))
-#define VAL_GPIOF_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOF_I2C2_SDA) |     \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_I2C2_SCL) |    \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN2) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN3) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN4) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN5) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN6) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN7) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN8) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN9) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN10) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN11) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN12) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN13) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN14) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOF_PIN15))
-#define VAL_GPIOF_OSPEEDR           (PIN_OSPEED_HIGH(GPIOF_I2C2_SDA) |        \
-                                     PIN_OSPEED_HIGH(GPIOF_I2C2_SCL) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN2) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN3) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN4) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN5) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN6) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN7) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN8) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN9) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN10) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN11) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN12) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN13) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN14) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOF_PIN15))
-#define VAL_GPIOF_PUPDR             (PIN_PUPDR_FLOATING(GPIOF_I2C2_SDA) |     \
-                                     PIN_PUPDR_FLOATING(GPIOF_I2C2_SCL) |    \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN2) |         \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN3) |         \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN4) |         \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN5) |         \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN6) |         \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN7) |         \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN8) |         \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN9) |         \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN10) |        \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN11) |        \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN12) |        \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN13) |        \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN14) |        \
-                                     PIN_PUPDR_PULLUP(GPIOF_PIN15))
-#define VAL_GPIOF_ODR               (PIN_ODR_HIGH(GPIOF_I2C2_SDA) |           \
-                                     PIN_ODR_HIGH(GPIOF_I2C2_SCL) |          \
-                                     PIN_ODR_HIGH(GPIOF_PIN2) |             \
-                                     PIN_ODR_HIGH(GPIOF_PIN3) |             \
-                                     PIN_ODR_HIGH(GPIOF_PIN4) |             \
-                                     PIN_ODR_HIGH(GPIOF_PIN5) |             \
-                                     PIN_ODR_HIGH(GPIOF_PIN6) |             \
-                                     PIN_ODR_HIGH(GPIOF_PIN7) |             \
-                                     PIN_ODR_HIGH(GPIOF_PIN8) |             \
-                                     PIN_ODR_HIGH(GPIOF_PIN9) |             \
-                                     PIN_ODR_HIGH(GPIOF_PIN10) |            \
-                                     PIN_ODR_HIGH(GPIOF_PIN11) |            \
-                                     PIN_ODR_HIGH(GPIOF_PIN12) |            \
-                                     PIN_ODR_HIGH(GPIOF_PIN13) |            \
-                                     PIN_ODR_HIGH(GPIOF_PIN14) |            \
-                                     PIN_ODR_HIGH(GPIOF_PIN15))
-#define VAL_GPIOF_AFRL              (PIN_AFIO_AF(GPIOF_I2C2_SDA, 0) |         \
-                                     PIN_AFIO_AF(GPIOF_I2C2_SCL, 0) |        \
-                                     PIN_AFIO_AF(GPIOF_PIN2, 0) |           \
-                                     PIN_AFIO_AF(GPIOF_PIN3, 0) |           \
-                                     PIN_AFIO_AF(GPIOF_PIN4, 0) |           \
-                                     PIN_AFIO_AF(GPIOF_PIN5, 0) |           \
-                                     PIN_AFIO_AF(GPIOF_PIN6, 0) |           \
-                                     PIN_AFIO_AF(GPIOF_PIN7, 0))
-#define VAL_GPIOF_AFRH              (PIN_AFIO_AF(GPIOF_PIN8, 0) |           \
-                                     PIN_AFIO_AF(GPIOF_PIN9, 0) |           \
-                                     PIN_AFIO_AF(GPIOF_PIN10, 0) |          \
-                                     PIN_AFIO_AF(GPIOF_PIN11, 0) |          \
-                                     PIN_AFIO_AF(GPIOF_PIN12, 0) |          \
-                                     PIN_AFIO_AF(GPIOF_PIN13, 0) |          \
-                                     PIN_AFIO_AF(GPIOF_PIN14, 0) |          \
-                                     PIN_AFIO_AF(GPIOF_PIN15, 0))
+#define VAL_GPIOF_MODER (PIN_MODE_INPUT(GPIOF_I2C2_SDA) | PIN_MODE_INPUT(GPIOF_I2C2_SCL) | PIN_MODE_INPUT(GPIOF_PIN2) | PIN_MODE_INPUT(GPIOF_PIN3) | PIN_MODE_INPUT(GPIOF_PIN4) | PIN_MODE_INPUT(GPIOF_PIN5) | PIN_MODE_INPUT(GPIOF_PIN6) | PIN_MODE_INPUT(GPIOF_PIN7) | PIN_MODE_INPUT(GPIOF_PIN8) | PIN_MODE_INPUT(GPIOF_PIN9) | PIN_MODE_INPUT(GPIOF_PIN10) | PIN_MODE_INPUT(GPIOF_PIN11) | PIN_MODE_INPUT(GPIOF_PIN12) | PIN_MODE_INPUT(GPIOF_PIN13) | PIN_MODE_INPUT(GPIOF_PIN14) | PIN_MODE_INPUT(GPIOF_PIN15))
+#define VAL_GPIOF_OTYPER (PIN_OTYPE_PUSHPULL(GPIOF_I2C2_SDA) | PIN_OTYPE_PUSHPULL(GPIOF_I2C2_SCL) | PIN_OTYPE_PUSHPULL(GPIOF_PIN2) | PIN_OTYPE_PUSHPULL(GPIOF_PIN3) | PIN_OTYPE_PUSHPULL(GPIOF_PIN4) | PIN_OTYPE_PUSHPULL(GPIOF_PIN5) | PIN_OTYPE_PUSHPULL(GPIOF_PIN6) | PIN_OTYPE_PUSHPULL(GPIOF_PIN7) | PIN_OTYPE_PUSHPULL(GPIOF_PIN8) | PIN_OTYPE_PUSHPULL(GPIOF_PIN9) | PIN_OTYPE_PUSHPULL(GPIOF_PIN10) | PIN_OTYPE_PUSHPULL(GPIOF_PIN11) | PIN_OTYPE_PUSHPULL(GPIOF_PIN12) | PIN_OTYPE_PUSHPULL(GPIOF_PIN13) | PIN_OTYPE_PUSHPULL(GPIOF_PIN14) | PIN_OTYPE_PUSHPULL(GPIOF_PIN15))
+#define VAL_GPIOF_OSPEEDR (PIN_OSPEED_HIGH(GPIOF_I2C2_SDA) | PIN_OSPEED_HIGH(GPIOF_I2C2_SCL) | PIN_OSPEED_VERYLOW(GPIOF_PIN2) | PIN_OSPEED_VERYLOW(GPIOF_PIN3) | PIN_OSPEED_VERYLOW(GPIOF_PIN4) | PIN_OSPEED_VERYLOW(GPIOF_PIN5) | PIN_OSPEED_VERYLOW(GPIOF_PIN6) | PIN_OSPEED_VERYLOW(GPIOF_PIN7) | PIN_OSPEED_VERYLOW(GPIOF_PIN8) | PIN_OSPEED_VERYLOW(GPIOF_PIN9) | PIN_OSPEED_VERYLOW(GPIOF_PIN10) | PIN_OSPEED_VERYLOW(GPIOF_PIN11) | PIN_OSPEED_VERYLOW(GPIOF_PIN12) | PIN_OSPEED_VERYLOW(GPIOF_PIN13) | PIN_OSPEED_VERYLOW(GPIOF_PIN14) | PIN_OSPEED_VERYLOW(GPIOF_PIN15))
+#define VAL_GPIOF_PUPDR (PIN_PUPDR_FLOATING(GPIOF_I2C2_SDA) | PIN_PUPDR_FLOATING(GPIOF_I2C2_SCL) | PIN_PUPDR_PULLUP(GPIOF_PIN2) | PIN_PUPDR_PULLUP(GPIOF_PIN3) | PIN_PUPDR_PULLUP(GPIOF_PIN4) | PIN_PUPDR_PULLUP(GPIOF_PIN5) | PIN_PUPDR_PULLUP(GPIOF_PIN6) | PIN_PUPDR_PULLUP(GPIOF_PIN7) | PIN_PUPDR_PULLUP(GPIOF_PIN8) | PIN_PUPDR_PULLUP(GPIOF_PIN9) | PIN_PUPDR_PULLUP(GPIOF_PIN10) | PIN_PUPDR_PULLUP(GPIOF_PIN11) | PIN_PUPDR_PULLUP(GPIOF_PIN12) | PIN_PUPDR_PULLUP(GPIOF_PIN13) | PIN_PUPDR_PULLUP(GPIOF_PIN14) | PIN_PUPDR_PULLUP(GPIOF_PIN15))
+#define VAL_GPIOF_ODR (PIN_ODR_HIGH(GPIOF_I2C2_SDA) | PIN_ODR_HIGH(GPIOF_I2C2_SCL) | PIN_ODR_HIGH(GPIOF_PIN2) | PIN_ODR_HIGH(GPIOF_PIN3) | PIN_ODR_HIGH(GPIOF_PIN4) | PIN_ODR_HIGH(GPIOF_PIN5) | PIN_ODR_HIGH(GPIOF_PIN6) | PIN_ODR_HIGH(GPIOF_PIN7) | PIN_ODR_HIGH(GPIOF_PIN8) | PIN_ODR_HIGH(GPIOF_PIN9) | PIN_ODR_HIGH(GPIOF_PIN10) | PIN_ODR_HIGH(GPIOF_PIN11) | PIN_ODR_HIGH(GPIOF_PIN12) | PIN_ODR_HIGH(GPIOF_PIN13) | PIN_ODR_HIGH(GPIOF_PIN14) | PIN_ODR_HIGH(GPIOF_PIN15))
+#define VAL_GPIOF_AFRL (PIN_AFIO_AF(GPIOF_I2C2_SDA, 0) | PIN_AFIO_AF(GPIOF_I2C2_SCL, 0) | PIN_AFIO_AF(GPIOF_PIN2, 0) | PIN_AFIO_AF(GPIOF_PIN3, 0) | PIN_AFIO_AF(GPIOF_PIN4, 0) | PIN_AFIO_AF(GPIOF_PIN5, 0) | PIN_AFIO_AF(GPIOF_PIN6, 0) | PIN_AFIO_AF(GPIOF_PIN7, 0))
+#define VAL_GPIOF_AFRH (PIN_AFIO_AF(GPIOF_PIN8, 0) | PIN_AFIO_AF(GPIOF_PIN9, 0) | PIN_AFIO_AF(GPIOF_PIN10, 0) | PIN_AFIO_AF(GPIOF_PIN11, 0) | PIN_AFIO_AF(GPIOF_PIN12, 0) | PIN_AFIO_AF(GPIOF_PIN13, 0) | PIN_AFIO_AF(GPIOF_PIN14, 0) | PIN_AFIO_AF(GPIOF_PIN15, 0))
 
 /*
  * GPIOG setup:
  * PG14 - PIN14                     (input pullup).
  * PG15 - PIN15                     (input pullup).
  */
-#define VAL_GPIOG_MODER             (PIN_MODE_INPUT(GPIOG_PIN0) |           \
-                                     PIN_MODE_INPUT(GPIOG_PIN1) |           \
-                                     PIN_MODE_INPUT(GPIOG_PIN2) |           \
-                                     PIN_MODE_INPUT(GPIOG_PIN3) |           \
-                                     PIN_MODE_INPUT(GPIOG_PIN4) |           \
-                                     PIN_MODE_INPUT(GPIOG_PIN5) |           \
-                                     PIN_MODE_INPUT(GPIOG_PIN6) |           \
-                                     PIN_MODE_INPUT(GPIOG_PIN7) |           \
-                                     PIN_MODE_INPUT(GPIOG_PIN8) |           \
-                                     PIN_MODE_INPUT(GPIOG_PIN9) |           \
-                                     PIN_MODE_INPUT(GPIOG_PIN10) |          \
-                                     PIN_MODE_INPUT(GPIOG_PIN11) |          \
-                                     PIN_MODE_INPUT(GPIOG_PIN12) |          \
-                                     PIN_MODE_INPUT(GPIOG_PIN13) |          \
-                                     PIN_MODE_INPUT(GPIOG_PIN14) |          \
-                                     PIN_MODE_INPUT(GPIOG_PIN15))
-#define VAL_GPIOG_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOG_PIN0) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN1) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN2) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN3) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN4) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN5) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN6) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN7) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN8) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN9) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN10) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN11) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN12) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN13) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN14) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOG_PIN15))
-#define VAL_GPIOG_OSPEEDR           (PIN_OSPEED_VERYLOW(GPIOG_PIN0) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN1) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN2) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN3) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN4) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN5) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN6) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN7) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN8) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN9) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN10) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN11) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN12) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN13) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN14) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOG_PIN15))
-#define VAL_GPIOG_PUPDR             (PIN_PUPDR_PULLUP(GPIOG_PIN0) |         \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN1) |         \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN2) |         \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN3) |         \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN4) |         \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN5) |         \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN6) |         \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN7) |         \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN8) |         \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN9) |         \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN10) |        \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN11) |        \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN12) |        \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN13) |        \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN14) |        \
-                                     PIN_PUPDR_PULLUP(GPIOG_PIN15))
-#define VAL_GPIOG_ODR               (PIN_ODR_HIGH(GPIOG_PIN0) |             \
-                                     PIN_ODR_HIGH(GPIOG_PIN1) |             \
-                                     PIN_ODR_HIGH(GPIOG_PIN2) |             \
-                                     PIN_ODR_HIGH(GPIOG_PIN3) |             \
-                                     PIN_ODR_HIGH(GPIOG_PIN4) |             \
-                                     PIN_ODR_HIGH(GPIOG_PIN5) |             \
-                                     PIN_ODR_HIGH(GPIOG_PIN6) |             \
-                                     PIN_ODR_HIGH(GPIOG_PIN7) |             \
-                                     PIN_ODR_HIGH(GPIOG_PIN8) |             \
-                                     PIN_ODR_HIGH(GPIOG_PIN9) |             \
-                                     PIN_ODR_HIGH(GPIOG_PIN10) |            \
-                                     PIN_ODR_HIGH(GPIOG_PIN11) |            \
-                                     PIN_ODR_HIGH(GPIOG_PIN12) |            \
-                                     PIN_ODR_HIGH(GPIOG_PIN13) |            \
-                                     PIN_ODR_HIGH(GPIOG_PIN14) |            \
-                                     PIN_ODR_HIGH(GPIOG_PIN15))
-#define VAL_GPIOG_AFRL              (PIN_AFIO_AF(GPIOG_PIN0, 0) |           \
-                                     PIN_AFIO_AF(GPIOG_PIN1, 0) |           \
-                                     PIN_AFIO_AF(GPIOG_PIN2, 0) |           \
-                                     PIN_AFIO_AF(GPIOG_PIN3, 0) |           \
-                                     PIN_AFIO_AF(GPIOG_PIN4, 0) |           \
-                                     PIN_AFIO_AF(GPIOG_PIN5, 0) |           \
-                                     PIN_AFIO_AF(GPIOG_PIN6, 0) |           \
-                                     PIN_AFIO_AF(GPIOG_PIN7, 0))
-#define VAL_GPIOG_AFRH              (PIN_AFIO_AF(GPIOG_PIN8, 0) |           \
-                                     PIN_AFIO_AF(GPIOG_PIN9, 0) |           \
-                                     PIN_AFIO_AF(GPIOG_PIN10, 0) |          \
-                                     PIN_AFIO_AF(GPIOG_PIN11, 0) |          \
-                                     PIN_AFIO_AF(GPIOG_PIN12, 0) |          \
-                                     PIN_AFIO_AF(GPIOG_PIN13, 0) |          \
-                                     PIN_AFIO_AF(GPIOG_PIN14, 0) |          \
-                                     PIN_AFIO_AF(GPIOG_PIN15, 0))
+#define VAL_GPIOG_MODER (PIN_MODE_INPUT(GPIOG_PIN0) | PIN_MODE_INPUT(GPIOG_PIN1) | PIN_MODE_INPUT(GPIOG_PIN2) | PIN_MODE_INPUT(GPIOG_PIN3) | PIN_MODE_INPUT(GPIOG_PIN4) | PIN_MODE_INPUT(GPIOG_PIN5) | PIN_MODE_INPUT(GPIOG_PIN6) | PIN_MODE_INPUT(GPIOG_PIN7) | PIN_MODE_INPUT(GPIOG_PIN8) | PIN_MODE_INPUT(GPIOG_PIN9) | PIN_MODE_INPUT(GPIOG_PIN10) | PIN_MODE_INPUT(GPIOG_PIN11) | PIN_MODE_INPUT(GPIOG_PIN12) | PIN_MODE_INPUT(GPIOG_PIN13) | PIN_MODE_INPUT(GPIOG_PIN14) | PIN_MODE_INPUT(GPIOG_PIN15))
+#define VAL_GPIOG_OTYPER (PIN_OTYPE_PUSHPULL(GPIOG_PIN0) | PIN_OTYPE_PUSHPULL(GPIOG_PIN1) | PIN_OTYPE_PUSHPULL(GPIOG_PIN2) | PIN_OTYPE_PUSHPULL(GPIOG_PIN3) | PIN_OTYPE_PUSHPULL(GPIOG_PIN4) | PIN_OTYPE_PUSHPULL(GPIOG_PIN5) | PIN_OTYPE_PUSHPULL(GPIOG_PIN6) | PIN_OTYPE_PUSHPULL(GPIOG_PIN7) | PIN_OTYPE_PUSHPULL(GPIOG_PIN8) | PIN_OTYPE_PUSHPULL(GPIOG_PIN9) | PIN_OTYPE_PUSHPULL(GPIOG_PIN10) | PIN_OTYPE_PUSHPULL(GPIOG_PIN11) | PIN_OTYPE_PUSHPULL(GPIOG_PIN12) | PIN_OTYPE_PUSHPULL(GPIOG_PIN13) | PIN_OTYPE_PUSHPULL(GPIOG_PIN14) | PIN_OTYPE_PUSHPULL(GPIOG_PIN15))
+#define VAL_GPIOG_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOG_PIN0) | PIN_OSPEED_VERYLOW(GPIOG_PIN1) | PIN_OSPEED_VERYLOW(GPIOG_PIN2) | PIN_OSPEED_VERYLOW(GPIOG_PIN3) | PIN_OSPEED_VERYLOW(GPIOG_PIN4) | PIN_OSPEED_VERYLOW(GPIOG_PIN5) | PIN_OSPEED_VERYLOW(GPIOG_PIN6) | PIN_OSPEED_VERYLOW(GPIOG_PIN7) | PIN_OSPEED_VERYLOW(GPIOG_PIN8) | PIN_OSPEED_VERYLOW(GPIOG_PIN9) | PIN_OSPEED_VERYLOW(GPIOG_PIN10) | PIN_OSPEED_VERYLOW(GPIOG_PIN11) | PIN_OSPEED_VERYLOW(GPIOG_PIN12) | PIN_OSPEED_VERYLOW(GPIOG_PIN13) | PIN_OSPEED_VERYLOW(GPIOG_PIN14) | PIN_OSPEED_VERYLOW(GPIOG_PIN15))
+#define VAL_GPIOG_PUPDR (PIN_PUPDR_PULLUP(GPIOG_PIN0) | PIN_PUPDR_PULLUP(GPIOG_PIN1) | PIN_PUPDR_PULLUP(GPIOG_PIN2) | PIN_PUPDR_PULLUP(GPIOG_PIN3) | PIN_PUPDR_PULLUP(GPIOG_PIN4) | PIN_PUPDR_PULLUP(GPIOG_PIN5) | PIN_PUPDR_PULLUP(GPIOG_PIN6) | PIN_PUPDR_PULLUP(GPIOG_PIN7) | PIN_PUPDR_PULLUP(GPIOG_PIN8) | PIN_PUPDR_PULLUP(GPIOG_PIN9) | PIN_PUPDR_PULLUP(GPIOG_PIN10) | PIN_PUPDR_PULLUP(GPIOG_PIN11) | PIN_PUPDR_PULLUP(GPIOG_PIN12) | PIN_PUPDR_PULLUP(GPIOG_PIN13) | PIN_PUPDR_PULLUP(GPIOG_PIN14) | PIN_PUPDR_PULLUP(GPIOG_PIN15))
+#define VAL_GPIOG_ODR (PIN_ODR_HIGH(GPIOG_PIN0) | PIN_ODR_HIGH(GPIOG_PIN1) | PIN_ODR_HIGH(GPIOG_PIN2) | PIN_ODR_HIGH(GPIOG_PIN3) | PIN_ODR_HIGH(GPIOG_PIN4) | PIN_ODR_HIGH(GPIOG_PIN5) | PIN_ODR_HIGH(GPIOG_PIN6) | PIN_ODR_HIGH(GPIOG_PIN7) | PIN_ODR_HIGH(GPIOG_PIN8) | PIN_ODR_HIGH(GPIOG_PIN9) | PIN_ODR_HIGH(GPIOG_PIN10) | PIN_ODR_HIGH(GPIOG_PIN11) | PIN_ODR_HIGH(GPIOG_PIN12) | PIN_ODR_HIGH(GPIOG_PIN13) | PIN_ODR_HIGH(GPIOG_PIN14) | PIN_ODR_HIGH(GPIOG_PIN15))
+#define VAL_GPIOG_AFRL (PIN_AFIO_AF(GPIOG_PIN0, 0) | PIN_AFIO_AF(GPIOG_PIN1, 0) | PIN_AFIO_AF(GPIOG_PIN2, 0) | PIN_AFIO_AF(GPIOG_PIN3, 0) | PIN_AFIO_AF(GPIOG_PIN4, 0) | PIN_AFIO_AF(GPIOG_PIN5, 0) | PIN_AFIO_AF(GPIOG_PIN6, 0) | PIN_AFIO_AF(GPIOG_PIN7, 0))
+#define VAL_GPIOG_AFRH (PIN_AFIO_AF(GPIOG_PIN8, 0) | PIN_AFIO_AF(GPIOG_PIN9, 0) | PIN_AFIO_AF(GPIOG_PIN10, 0) | PIN_AFIO_AF(GPIOG_PIN11, 0) | PIN_AFIO_AF(GPIOG_PIN12, 0) | PIN_AFIO_AF(GPIOG_PIN13, 0) | PIN_AFIO_AF(GPIOG_PIN14, 0) | PIN_AFIO_AF(GPIOG_PIN15, 0))
 
 /*
  * GPIOH setup:
  * PH14 - PIN14                     (input pullup).
  * PH15 - PIN15                     (input pullup).
  */
-#define VAL_GPIOH_MODER             (PIN_MODE_INPUT(GPIOH_PIN0) |           \
-                                     PIN_MODE_INPUT(GPIOH_PIN1) |           \
-                                     PIN_MODE_INPUT(GPIOH_PIN2) |           \
-                                     PIN_MODE_INPUT(GPIOH_PIN3) |           \
-                                     PIN_MODE_INPUT(GPIOH_PIN4) |           \
-                                     PIN_MODE_INPUT(GPIOH_PIN5) |           \
-                                     PIN_MODE_INPUT(GPIOH_PIN6) |           \
-                                     PIN_MODE_INPUT(GPIOH_PIN7) |           \
-                                     PIN_MODE_INPUT(GPIOH_PIN8) |           \
-                                     PIN_MODE_INPUT(GPIOH_PIN9) |           \
-                                     PIN_MODE_INPUT(GPIOH_PIN10) |          \
-                                     PIN_MODE_INPUT(GPIOH_PIN11) |          \
-                                     PIN_MODE_INPUT(GPIOH_PIN12) |          \
-                                     PIN_MODE_INPUT(GPIOH_PIN13) |          \
-                                     PIN_MODE_INPUT(GPIOH_PIN14) |          \
-                                     PIN_MODE_INPUT(GPIOH_PIN15))
-#define VAL_GPIOH_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOH_PIN0) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN1) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN2) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN3) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN4) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN5) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN6) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN7) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN8) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN9) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN10) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN11) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN12) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN13) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN14) |      \
-                                     PIN_OTYPE_PUSHPULL(GPIOH_PIN15))
-#define VAL_GPIOH_OSPEEDR           (PIN_OSPEED_VERYLOW(GPIOH_PIN0) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN1) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN2) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN3) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN4) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN5) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN6) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN7) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN8) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN9) |       \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN10) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN11) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN12) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN13) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN14) |      \
-                                     PIN_OSPEED_VERYLOW(GPIOH_PIN15))
-#define VAL_GPIOH_PUPDR             (PIN_PUPDR_PULLUP(GPIOH_PIN0) |         \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN1) |         \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN2) |         \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN3) |         \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN4) |         \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN5) |         \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN6) |         \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN7) |         \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN8) |         \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN9) |         \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN10) |        \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN11) |        \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN12) |        \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN13) |        \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN14) |        \
-                                     PIN_PUPDR_PULLUP(GPIOH_PIN15))
-#define VAL_GPIOH_ODR               (PIN_ODR_HIGH(GPIOH_PIN0) |             \
-                                     PIN_ODR_HIGH(GPIOH_PIN1) |             \
-                                     PIN_ODR_HIGH(GPIOH_PIN2) |             \
-                                     PIN_ODR_HIGH(GPIOH_PIN3) |             \
-                                     PIN_ODR_HIGH(GPIOH_PIN4) |             \
-                                     PIN_ODR_HIGH(GPIOH_PIN5) |             \
-                                     PIN_ODR_HIGH(GPIOH_PIN6) |             \
-                                     PIN_ODR_HIGH(GPIOH_PIN7) |             \
-                                     PIN_ODR_HIGH(GPIOH_PIN8) |             \
-                                     PIN_ODR_HIGH(GPIOH_PIN9) |             \
-                                     PIN_ODR_HIGH(GPIOH_PIN10) |            \
-                                     PIN_ODR_HIGH(GPIOH_PIN11) |            \
-                                     PIN_ODR_HIGH(GPIOH_PIN12) |            \
-                                     PIN_ODR_HIGH(GPIOH_PIN13) |            \
-                                     PIN_ODR_HIGH(GPIOH_PIN14) |            \
-                                     PIN_ODR_HIGH(GPIOH_PIN15))
-#define VAL_GPIOH_AFRL              (PIN_AFIO_AF(GPIOH_PIN0, 0) |           \
-                                     PIN_AFIO_AF(GPIOH_PIN1, 0) |           \
-                                     PIN_AFIO_AF(GPIOH_PIN2, 0) |           \
-                                     PIN_AFIO_AF(GPIOH_PIN3, 0) |           \
-                                     PIN_AFIO_AF(GPIOH_PIN4, 0) |           \
-                                     PIN_AFIO_AF(GPIOH_PIN5, 0) |           \
-                                     PIN_AFIO_AF(GPIOH_PIN6, 0) |           \
-                                     PIN_AFIO_AF(GPIOH_PIN7, 0))
-#define VAL_GPIOH_AFRH              (PIN_AFIO_AF(GPIOH_PIN8, 0) |           \
-                                     PIN_AFIO_AF(GPIOH_PIN9, 0) |           \
-                                     PIN_AFIO_AF(GPIOH_PIN10, 0) |          \
-                                     PIN_AFIO_AF(GPIOH_PIN11, 0) |          \
-                                     PIN_AFIO_AF(GPIOH_PIN12, 0) |          \
-                                     PIN_AFIO_AF(GPIOH_PIN13, 0) |          \
-                                     PIN_AFIO_AF(GPIOH_PIN14, 0) |          \
-                                     PIN_AFIO_AF(GPIOH_PIN15, 0))
-
+#define VAL_GPIOH_MODER (PIN_MODE_INPUT(GPIOH_PIN0) | PIN_MODE_INPUT(GPIOH_PIN1) | PIN_MODE_INPUT(GPIOH_PIN2) | PIN_MODE_INPUT(GPIOH_PIN3) | PIN_MODE_INPUT(GPIOH_PIN4) | PIN_MODE_INPUT(GPIOH_PIN5) | PIN_MODE_INPUT(GPIOH_PIN6) | PIN_MODE_INPUT(GPIOH_PIN7) | PIN_MODE_INPUT(GPIOH_PIN8) | PIN_MODE_INPUT(GPIOH_PIN9) | PIN_MODE_INPUT(GPIOH_PIN10) | PIN_MODE_INPUT(GPIOH_PIN11) | PIN_MODE_INPUT(GPIOH_PIN12) | PIN_MODE_INPUT(GPIOH_PIN13) | PIN_MODE_INPUT(GPIOH_PIN14) | PIN_MODE_INPUT(GPIOH_PIN15))
+#define VAL_GPIOH_OTYPER (PIN_OTYPE_PUSHPULL(GPIOH_PIN0) | PIN_OTYPE_PUSHPULL(GPIOH_PIN1) | PIN_OTYPE_PUSHPULL(GPIOH_PIN2) | PIN_OTYPE_PUSHPULL(GPIOH_PIN3) | PIN_OTYPE_PUSHPULL(GPIOH_PIN4) | PIN_OTYPE_PUSHPULL(GPIOH_PIN5) | PIN_OTYPE_PUSHPULL(GPIOH_PIN6) | PIN_OTYPE_PUSHPULL(GPIOH_PIN7) | PIN_OTYPE_PUSHPULL(GPIOH_PIN8) | PIN_OTYPE_PUSHPULL(GPIOH_PIN9) | PIN_OTYPE_PUSHPULL(GPIOH_PIN10) | PIN_OTYPE_PUSHPULL(GPIOH_PIN11) | PIN_OTYPE_PUSHPULL(GPIOH_PIN12) | PIN_OTYPE_PUSHPULL(GPIOH_PIN13) | PIN_OTYPE_PUSHPULL(GPIOH_PIN14) | PIN_OTYPE_PUSHPULL(GPIOH_PIN15))
+#define VAL_GPIOH_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOH_PIN0) | PIN_OSPEED_VERYLOW(GPIOH_PIN1) | PIN_OSPEED_VERYLOW(GPIOH_PIN2) | PIN_OSPEED_VERYLOW(GPIOH_PIN3) | PIN_OSPEED_VERYLOW(GPIOH_PIN4) | PIN_OSPEED_VERYLOW(GPIOH_PIN5) | PIN_OSPEED_VERYLOW(GPIOH_PIN6) | PIN_OSPEED_VERYLOW(GPIOH_PIN7) | PIN_OSPEED_VERYLOW(GPIOH_PIN8) | PIN_OSPEED_VERYLOW(GPIOH_PIN9) | PIN_OSPEED_VERYLOW(GPIOH_PIN10) | PIN_OSPEED_VERYLOW(GPIOH_PIN11) | PIN_OSPEED_VERYLOW(GPIOH_PIN12) | PIN_OSPEED_VERYLOW(GPIOH_PIN13) | PIN_OSPEED_VERYLOW(GPIOH_PIN14) | PIN_OSPEED_VERYLOW(GPIOH_PIN15))
+#define VAL_GPIOH_PUPDR (PIN_PUPDR_PULLUP(GPIOH_PIN0) | PIN_PUPDR_PULLUP(GPIOH_PIN1) | PIN_PUPDR_PULLUP(GPIOH_PIN2) | PIN_PUPDR_PULLUP(GPIOH_PIN3) | PIN_PUPDR_PULLUP(GPIOH_PIN4) | PIN_PUPDR_PULLUP(GPIOH_PIN5) | PIN_PUPDR_PULLUP(GPIOH_PIN6) | PIN_PUPDR_PULLUP(GPIOH_PIN7) | PIN_PUPDR_PULLUP(GPIOH_PIN8) | PIN_PUPDR_PULLUP(GPIOH_PIN9) | PIN_PUPDR_PULLUP(GPIOH_PIN10) | PIN_PUPDR_PULLUP(GPIOH_PIN11) | PIN_PUPDR_PULLUP(GPIOH_PIN12) | PIN_PUPDR_PULLUP(GPIOH_PIN13) | PIN_PUPDR_PULLUP(GPIOH_PIN14) | PIN_PUPDR_PULLUP(GPIOH_PIN15))
+#define VAL_GPIOH_ODR (PIN_ODR_HIGH(GPIOH_PIN0) | PIN_ODR_HIGH(GPIOH_PIN1) | PIN_ODR_HIGH(GPIOH_PIN2) | PIN_ODR_HIGH(GPIOH_PIN3) | PIN_ODR_HIGH(GPIOH_PIN4) | PIN_ODR_HIGH(GPIOH_PIN5) | PIN_ODR_HIGH(GPIOH_PIN6) | PIN_ODR_HIGH(GPIOH_PIN7) | PIN_ODR_HIGH(GPIOH_PIN8) | PIN_ODR_HIGH(GPIOH_PIN9) | PIN_ODR_HIGH(GPIOH_PIN10) | PIN_ODR_HIGH(GPIOH_PIN11) | PIN_ODR_HIGH(GPIOH_PIN12) | PIN_ODR_HIGH(GPIOH_PIN13) | PIN_ODR_HIGH(GPIOH_PIN14) | PIN_ODR_HIGH(GPIOH_PIN15))
+#define VAL_GPIOH_AFRL (PIN_AFIO_AF(GPIOH_PIN0, 0) | PIN_AFIO_AF(GPIOH_PIN1, 0) | PIN_AFIO_AF(GPIOH_PIN2, 0) | PIN_AFIO_AF(GPIOH_PIN3, 0) | PIN_AFIO_AF(GPIOH_PIN4, 0) | PIN_AFIO_AF(GPIOH_PIN5, 0) | PIN_AFIO_AF(GPIOH_PIN6, 0) | PIN_AFIO_AF(GPIOH_PIN7, 0))
+#define VAL_GPIOH_AFRH (PIN_AFIO_AF(GPIOH_PIN8, 0) | PIN_AFIO_AF(GPIOH_PIN9, 0) | PIN_AFIO_AF(GPIOH_PIN10, 0) | PIN_AFIO_AF(GPIOH_PIN11, 0) | PIN_AFIO_AF(GPIOH_PIN12, 0) | PIN_AFIO_AF(GPIOH_PIN13, 0) | PIN_AFIO_AF(GPIOH_PIN14, 0) | PIN_AFIO_AF(GPIOH_PIN15, 0))
 
 /*
  * USB bus activation macro, required by the USB driver.
  * USB bus de-activation macro, required by the USB driver.
  */
 // #define usb_lld_disconnect_bus(usbp)
-#define usb_lld_disconnect_bus(usbp) (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_OUTPUT_PUSHPULL)); palClearPad(GPIOA, GPIOA_USB_DP)
+#define usb_lld_disconnect_bus(usbp)                                \
+    (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_OUTPUT_PUSHPULL)); \
+    palClearPad(GPIOA, GPIOA_USB_DP)
 // #define usb_lld_disconnect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOA, 12)
 
 #if !defined(_FROM_ASM_)
-#ifdef __cplusplus
+#    ifdef __cplusplus
 extern "C" {
-#endif
-  void boardInit(void);
-#ifdef __cplusplus
+#    endif
+void boardInit(void);
+#    ifdef __cplusplus
 }
-#endif
+#    endif
 #endif /* _FROM_ASM_ */
 
 #endif /* _BOARD_H_ */
index 1e952883d87d5c59c4353616f54e94504eef1336..63e3f64929da987b0c6b5e8e3565c80bbfbee105 100644 (file)
  * @details Digital I/O ports static configuration as defined in @p board.h.
  *          This variable is used by the HAL when initializing the PAL driver.
  */
-const PALConfig pal_default_config =
-{
-    .ports = {
+const PALConfig pal_default_config = {
+    .ports =
         {
-            /*
-             * PORTA setup.
-             *
-             * PTA4  - PIN33
-             * PTA5  - PIN24
-             * PTA12 - PIN3
-             * PTA13 - PIN4
-             *
-             * PTA18/19 crystal
-             * PTA0/3 SWD
-             */
-            .port = IOPORT1,
-            .pads = {
-                PAL_MODE_ALTERNATIVE_7,     PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_ALTERNATIVE_7,     PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_INPUT_ANALOG,      PAL_MODE_INPUT_ANALOG,      PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
+            {
+                /*
+                 * PORTA setup.
+                 *
+                 * PTA4  - PIN33
+                 * PTA5  - PIN24
+                 * PTA12 - PIN3
+                 * PTA13 - PIN4
+                 *
+                 * PTA18/19 crystal
+                 * PTA0/3 SWD
+                 */
+                .port = IOPORT1,
+                .pads =
+                    {
+                        PAL_MODE_ALTERNATIVE_7, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_ALTERNATIVE_7, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_INPUT_ANALOG, PAL_MODE_INPUT_ANALOG, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED,
+                    },
             },
-        },
-        {
-            /*
-             * PORTB setup.
-             *
-             * PTB0  - PIN16
-             * PTB1  - PIN17
-             * PTB2  - PIN19
-             * PTB3  - PIN18
-             * PTB16 - PIN0 - UART0_TX
-             * PTB17 - PIN1 - UART0_RX
-             * PTB18 - PIN32
-             * PTB19 - PIN25
-             */
-            .port = IOPORT2,
-            .pads = {
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_ALTERNATIVE_3,     PAL_MODE_ALTERNATIVE_3,
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
+            {
+                /*
+                 * PORTB setup.
+                 *
+                 * PTB0  - PIN16
+                 * PTB1  - PIN17
+                 * PTB2  - PIN19
+                 * PTB3  - PIN18
+                 * PTB16 - PIN0 - UART0_TX
+                 * PTB17 - PIN1 - UART0_RX
+                 * PTB18 - PIN32
+                 * PTB19 - PIN25
+                 */
+                .port = IOPORT2,
+                .pads =
+                    {
+                        PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_ALTERNATIVE_3, PAL_MODE_ALTERNATIVE_3, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED,
+                    },
             },
-        },
-        {
-            /*
-             * PORTC setup.
-             *
-             * PTC0  - PIN15
-             * PTC1  - PIN22
-             * PTC2  - PIN23
-             * PTC3  - PIN9
-             * PTC4  - PIN10
-             * PTC5  - PIN13
-             * PTC6  - PIN11
-             * PTC7  - PIN12
-             * PTC8  - PIN28
-             * PTC9  - PIN27
-             * PTC10 - PIN29
-             * PTC11 - PIN30
-             */
-            .port = IOPORT3,
-            .pads = {
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
+            {
+                /*
+                 * PORTC setup.
+                 *
+                 * PTC0  - PIN15
+                 * PTC1  - PIN22
+                 * PTC2  - PIN23
+                 * PTC3  - PIN9
+                 * PTC4  - PIN10
+                 * PTC5  - PIN13
+                 * PTC6  - PIN11
+                 * PTC7  - PIN12
+                 * PTC8  - PIN28
+                 * PTC9  - PIN27
+                 * PTC10 - PIN29
+                 * PTC11 - PIN30
+                 */
+                .port = IOPORT3,
+                .pads =
+                    {
+                        PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED,
+                    },
             },
-        },
-        {
-            /*
-             * PORTD setup.
-             *
-             * PTD0  - PIN2
-             * PTD1  - PIN14
-             * PTD2  - PIN7
-             * PTD3  - PIN8
-             * PTD4  - PIN6
-             * PTD5  - PIN20
-             * PTD6  - PIN21
-             * PTD7  - PIN5
-             */
-            .port = IOPORT4,
-            .pads = {
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
+            {
+                /*
+                 * PORTD setup.
+                 *
+                 * PTD0  - PIN2
+                 * PTD1  - PIN14
+                 * PTD2  - PIN7
+                 * PTD3  - PIN8
+                 * PTD4  - PIN6
+                 * PTD5  - PIN20
+                 * PTD6  - PIN21
+                 * PTD7  - PIN5
+                 */
+                .port = IOPORT4,
+                .pads =
+                    {
+                        PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED,
+                    },
             },
-        },
-        {
-            /*
-             * PORTE setup.
-             *
-             * PTE0  - PIN31
-             * PTE1  - PIN26
-             */
-            .port = IOPORT5,
-            .pads = {
-                PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_OUTPUT_PUSHPULL,   PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
-                PAL_MODE_UNCONNECTED,       PAL_MODE_UNCONNECTED,
+            {
+                /*
+                 * PORTE setup.
+                 *
+                 * PTE0  - PIN31
+                 * PTE1  - PIN26
+                 */
+                .port = IOPORT5,
+                .pads =
+                    {
+                        PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED,
+                    },
             },
         },
-    },
 };
 #endif
 
 // NOTE: This value comes from kiibohd/controller and is the location of a value
 // which needs to be checked before disabling the watchdog (which happens in
 // k20x_clock_init)
-#define WDOG_TMROUTL            *(volatile uint16_t *)0x40052012
+#define WDOG_TMROUTL *(volatile uint16_t *)0x40052012
 
 /**
  * @brief   Early initialization code.
@@ -176,16 +131,16 @@ const PALConfig pal_default_config =
  *          and before any other initialization.
  */
 void __early_init(void) {
-  // This is a dirty hack and should only be used as a temporary fix until this
-  // is upstreamed.
-  while (WDOG_TMROUTL < 2); // Must wait for WDOG timer if already running, before jumping
+    // This is a dirty hack and should only be used as a temporary fix until this
+    // is upstreamed.
+    while (WDOG_TMROUTL < 2)
+        ;  // Must wait for WDOG timer if already running, before jumping
 
-  k20x_clock_init();
+    k20x_clock_init();
 }
 
 /**
  * @brief   Board-specific initialization code.
  * @todo    Add your board-specific code, if any.
  */
-void boardInit(void) {
-}
+void boardInit(void) {}
index 8853395efe84b62961ef159484c24480d4d558af..c8259ab0c7bf390ffd4e183cd06cb91e956619f5 100644 (file)
  * Board identifier.
  */
 #define BOARD_PJRC_TEENSY_3_1
-#define BOARD_NAME                  "PJRC Teensy 3.1"
+#define BOARD_NAME "PJRC Teensy 3.1"
 
 /* External 16 MHz crystal */
-#define KINETIS_XTAL_FREQUENCY      16000000UL
+#define KINETIS_XTAL_FREQUENCY 16000000UL
 
 /* Use internal capacitors for the crystal */
-#define KINETIS_BOARD_OSCILLATOR_SETTING OSC_CR_SC8P|OSC_CR_SC2P
+#define KINETIS_BOARD_OSCILLATOR_SETTING OSC_CR_SC8P | OSC_CR_SC2P
 
 /*
  * MCU type
 /*
  * IO pins assignments.
  */
-#define PORTA_PIN0                  0
-#define PORTA_PIN1                  1
-#define PORTA_PIN2                  2
-#define PORTA_PIN3                  3
-#define TEENSY_PIN33                4
-#define TEENSY_PIN24                5
-#define PORTA_PIN6                  6
-#define PORTA_PIN7                  7
-#define PORTA_PIN8                  8
-#define PORTA_PIN9                  9
-#define PORTA_PIN10                 10
-#define PORTA_PIN11                 11
-#define TEENSY_PIN3                 12
-#define TEENSY_PIN4                 13
-#define PORTA_PIN14                 14
-#define PORTA_PIN15                 15
-#define PORTA_PIN16                 16
-#define PORTA_PIN17                 17
-#define PORTA_PIN18                 18
-#define PORTA_PIN19                 19
-#define PORTA_PIN20                 20
-#define PORTA_PIN21                 21
-#define PORTA_PIN22                 22
-#define PORTA_PIN23                 23
-#define PORTA_PIN24                 24
-#define PORTA_PIN25                 25
-#define PORTA_PIN26                 26
-#define PORTA_PIN27                 27
-#define PORTA_PIN28                 28
-#define PORTA_PIN29                 29
-#define PORTA_PIN30                 30
-#define PORTA_PIN31                 31
+#define PORTA_PIN0 0
+#define PORTA_PIN1 1
+#define PORTA_PIN2 2
+#define PORTA_PIN3 3
+#define TEENSY_PIN33 4
+#define TEENSY_PIN24 5
+#define PORTA_PIN6 6
+#define PORTA_PIN7 7
+#define PORTA_PIN8 8
+#define PORTA_PIN9 9
+#define PORTA_PIN10 10
+#define PORTA_PIN11 11
+#define TEENSY_PIN3 12
+#define TEENSY_PIN4 13
+#define PORTA_PIN14 14
+#define PORTA_PIN15 15
+#define PORTA_PIN16 16
+#define PORTA_PIN17 17
+#define PORTA_PIN18 18
+#define PORTA_PIN19 19
+#define PORTA_PIN20 20
+#define PORTA_PIN21 21
+#define PORTA_PIN22 22
+#define PORTA_PIN23 23
+#define PORTA_PIN24 24
+#define PORTA_PIN25 25
+#define PORTA_PIN26 26
+#define PORTA_PIN27 27
+#define PORTA_PIN28 28
+#define PORTA_PIN29 29
+#define PORTA_PIN30 30
+#define PORTA_PIN31 31
 
-#define TEENSY_PIN3_IOPORT  IOPORT1
-#define TEENSY_PIN4_IOPORT  IOPORT1
+#define TEENSY_PIN3_IOPORT IOPORT1
+#define TEENSY_PIN4_IOPORT IOPORT1
 #define TEENSY_PIN24_IOPORT IOPORT1
 #define TEENSY_PIN33_IOPORT IOPORT1
 
-#define TEENSY_PIN16                0
-#define TEENSY_PIN17                1
-#define TEENSY_PIN19                2
-#define TEENSY_PIN18                3
-#define PORTB_PIN4                  4
-#define PORTB_PIN5                  5
-#define PORTB_PIN6                  6
-#define PORTB_PIN7                  7
-#define PORTB_PIN8                  8
-#define PORTB_PIN9                  9
-#define PORTB_PIN10                 10
-#define PORTB_PIN11                 11
-#define PORTB_PIN12                 12
-#define PORTB_PIN13                 13
-#define PORTB_PIN14                 14
-#define PORTB_PIN15                 15
-#define TEENSY_PIN0                 16
-#define TEENSY_PIN1                 17
-#define TEENSY_PIN32                18
-#define TEENSY_PIN25                19
-#define PORTB_PIN20                 20
-#define PORTB_PIN21                 21
-#define PORTB_PIN22                 22
-#define PORTB_PIN23                 23
-#define PORTB_PIN24                 24
-#define PORTB_PIN25                 25
-#define PORTB_PIN26                 26
-#define PORTB_PIN27                 27
-#define PORTB_PIN28                 28
-#define PORTB_PIN29                 29
-#define PORTB_PIN30                 30
-#define PORTB_PIN31                 31
+#define TEENSY_PIN16 0
+#define TEENSY_PIN17 1
+#define TEENSY_PIN19 2
+#define TEENSY_PIN18 3
+#define PORTB_PIN4 4
+#define PORTB_PIN5 5
+#define PORTB_PIN6 6
+#define PORTB_PIN7 7
+#define PORTB_PIN8 8
+#define PORTB_PIN9 9
+#define PORTB_PIN10 10
+#define PORTB_PIN11 11
+#define PORTB_PIN12 12
+#define PORTB_PIN13 13
+#define PORTB_PIN14 14
+#define PORTB_PIN15 15
+#define TEENSY_PIN0 16
+#define TEENSY_PIN1 17
+#define TEENSY_PIN32 18
+#define TEENSY_PIN25 19
+#define PORTB_PIN20 20
+#define PORTB_PIN21 21
+#define PORTB_PIN22 22
+#define PORTB_PIN23 23
+#define PORTB_PIN24 24
+#define PORTB_PIN25 25
+#define PORTB_PIN26 26
+#define PORTB_PIN27 27
+#define PORTB_PIN28 28
+#define PORTB_PIN29 29
+#define PORTB_PIN30 30
+#define PORTB_PIN31 31
 
-#define TEENSY_PIN0_IOPORT  IOPORT2
-#define TEENSY_PIN1_IOPORT  IOPORT2
+#define TEENSY_PIN0_IOPORT IOPORT2
+#define TEENSY_PIN1_IOPORT IOPORT2
 #define TEENSY_PIN16_IOPORT IOPORT2
 #define TEENSY_PIN17_IOPORT IOPORT2
 #define TEENSY_PIN18_IOPORT IOPORT2
 #define TEENSY_PIN25_IOPORT IOPORT2
 #define TEENSY_PIN32_IOPORT IOPORT2
 
-#define TEENSY_PIN15                0
-#define TEENSY_PIN22                1
-#define TEENSY_PIN23                2
-#define TEENSY_PIN9                 3
-#define TEENSY_PIN10                4
-#define TEENSY_PIN13                5
-#define TEENSY_PIN11                6
-#define TEENSY_PIN12                7
-#define TEENSY_PIN28                8
-#define TEENSY_PIN27                9
-#define TEENSY_PIN29                10
-#define TEENSY_PIN30                11
-#define PORTC_PIN12                 12
-#define PORTC_PIN13                 13
-#define PORTC_PIN14                 14
-#define PORTC_PIN15                 15
-#define PORTC_PIN16                 16
-#define PORTC_PIN17                 17
-#define PORTC_PIN18                 18
-#define PORTC_PIN19                 19
-#define PORTC_PIN20                 20
-#define PORTC_PIN21                 21
-#define PORTC_PIN22                 22
-#define PORTC_PIN23                 23
-#define PORTC_PIN24                 24
-#define PORTC_PIN25                 25
-#define PORTC_PIN26                 26
-#define PORTC_PIN27                 27
-#define PORTC_PIN28                 28
-#define PORTC_PIN29                 29
-#define PORTC_PIN30                 30
-#define PORTC_PIN31                 31
+#define TEENSY_PIN15 0
+#define TEENSY_PIN22 1
+#define TEENSY_PIN23 2
+#define TEENSY_PIN9 3
+#define TEENSY_PIN10 4
+#define TEENSY_PIN13 5
+#define TEENSY_PIN11 6
+#define TEENSY_PIN12 7
+#define TEENSY_PIN28 8
+#define TEENSY_PIN27 9
+#define TEENSY_PIN29 10
+#define TEENSY_PIN30 11
+#define PORTC_PIN12 12
+#define PORTC_PIN13 13
+#define PORTC_PIN14 14
+#define PORTC_PIN15 15
+#define PORTC_PIN16 16
+#define PORTC_PIN17 17
+#define PORTC_PIN18 18
+#define PORTC_PIN19 19
+#define PORTC_PIN20 20
+#define PORTC_PIN21 21
+#define PORTC_PIN22 22
+#define PORTC_PIN23 23
+#define PORTC_PIN24 24
+#define PORTC_PIN25 25
+#define PORTC_PIN26 26
+#define PORTC_PIN27 27
+#define PORTC_PIN28 28
+#define PORTC_PIN29 29
+#define PORTC_PIN30 30
+#define PORTC_PIN31 31
 
-#define TEENSY_PIN9_IOPORT  IOPORT3
+#define TEENSY_PIN9_IOPORT IOPORT3
 #define TEENSY_PIN10_IOPORT IOPORT3
 #define TEENSY_PIN11_IOPORT IOPORT3
 #define TEENSY_PIN12_IOPORT IOPORT3
 #define TEENSY_PIN29_IOPORT IOPORT3
 #define TEENSY_PIN30_IOPORT IOPORT3
 
-#define TEENSY_PIN2                 0
-#define TEENSY_PIN14                1
-#define TEENSY_PIN7                 2
-#define TEENSY_PIN8                 3
-#define TEENSY_PIN6                 4
-#define TEENSY_PIN20                5
-#define TEENSY_PIN21                6
-#define TEENSY_PIN5                 7
-#define PORTD_PIN8                  8
-#define PORTD_PIN9                  9
-#define PORTD_PIN10                 10
-#define PORTD_PIN11                 11
-#define PORTD_PIN12                 12
-#define PORTD_PIN13                 13
-#define PORTD_PIN14                 14
-#define PORTD_PIN15                 15
-#define PORTD_PIN16                 16
-#define PORTD_PIN17                 17
-#define PORTD_PIN18                 18
-#define PORTD_PIN19                 19
-#define PORTD_PIN20                 20
-#define PORTD_PIN21                 21
-#define PORTD_PIN22                 22
-#define PORTD_PIN23                 23
-#define PORTD_PIN24                 24
-#define PORTD_PIN25                 25
-#define PORTD_PIN26                 26
-#define PORTD_PIN27                 27
-#define PORTD_PIN28                 28
-#define PORTD_PIN29                 29
-#define PORTD_PIN30                 30
-#define PORTD_PIN31                 31
+#define TEENSY_PIN2 0
+#define TEENSY_PIN14 1
+#define TEENSY_PIN7 2
+#define TEENSY_PIN8 3
+#define TEENSY_PIN6 4
+#define TEENSY_PIN20 5
+#define TEENSY_PIN21 6
+#define TEENSY_PIN5 7
+#define PORTD_PIN8 8
+#define PORTD_PIN9 9
+#define PORTD_PIN10 10
+#define PORTD_PIN11 11
+#define PORTD_PIN12 12
+#define PORTD_PIN13 13
+#define PORTD_PIN14 14
+#define PORTD_PIN15 15
+#define PORTD_PIN16 16
+#define PORTD_PIN17 17
+#define PORTD_PIN18 18
+#define PORTD_PIN19 19
+#define PORTD_PIN20 20
+#define PORTD_PIN21 21
+#define PORTD_PIN22 22
+#define PORTD_PIN23 23
+#define PORTD_PIN24 24
+#define PORTD_PIN25 25
+#define PORTD_PIN26 26
+#define PORTD_PIN27 27
+#define PORTD_PIN28 28
+#define PORTD_PIN29 29
+#define PORTD_PIN30 30
+#define PORTD_PIN31 31
 
-#define TEENSY_PIN2_IOPORT  IOPORT4
-#define TEENSY_PIN5_IOPORT  IOPORT4
-#define TEENSY_PIN6_IOPORT  IOPORT4
-#define TEENSY_PIN7_IOPORT  IOPORT4
-#define TEENSY_PIN8_IOPORT  IOPORT4
+#define TEENSY_PIN2_IOPORT IOPORT4
+#define TEENSY_PIN5_IOPORT IOPORT4
+#define TEENSY_PIN6_IOPORT IOPORT4
+#define TEENSY_PIN7_IOPORT IOPORT4
+#define TEENSY_PIN8_IOPORT IOPORT4
 #define TEENSY_PIN14_IOPORT IOPORT4
 #define TEENSY_PIN20_IOPORT IOPORT4
 #define TEENSY_PIN21_IOPORT IOPORT4
 
-#define TEENSY_PIN31                0
-#define TEENSY_PIN26                1
-#define PORTE_PIN2                  2
-#define PORTE_PIN3                  3
-#define PORTE_PIN4                  4
-#define PORTE_PIN5                  5
-#define PORTE_PIN6                  6
-#define PORTE_PIN7                  7
-#define PORTE_PIN8                  8
-#define PORTE_PIN9                  9
-#define PORTE_PIN10                 10
-#define PORTE_PIN11                 11
-#define PORTE_PIN12                 12
-#define PORTE_PIN13                 13
-#define PORTE_PIN14                 14
-#define PORTE_PIN15                 15
-#define PORTE_PIN16                 16
-#define PORTE_PIN17                 17
-#define PORTE_PIN18                 18
-#define PORTE_PIN19                 19
-#define PORTE_PIN20                 20
-#define PORTE_PIN21                 21
-#define PORTE_PIN22                 22
-#define PORTE_PIN23                 23
-#define PORTE_PIN24                 24
-#define PORTE_PIN25                 25
-#define PORTE_PIN26                 26
-#define PORTE_PIN27                 27
-#define PORTE_PIN28                 28
-#define PORTE_PIN29                 29
-#define PORTE_PIN30                 30
-#define PORTE_PIN31                 31
+#define TEENSY_PIN31 0
+#define TEENSY_PIN26 1
+#define PORTE_PIN2 2
+#define PORTE_PIN3 3
+#define PORTE_PIN4 4
+#define PORTE_PIN5 5
+#define PORTE_PIN6 6
+#define PORTE_PIN7 7
+#define PORTE_PIN8 8
+#define PORTE_PIN9 9
+#define PORTE_PIN10 10
+#define PORTE_PIN11 11
+#define PORTE_PIN12 12
+#define PORTE_PIN13 13
+#define PORTE_PIN14 14
+#define PORTE_PIN15 15
+#define PORTE_PIN16 16
+#define PORTE_PIN17 17
+#define PORTE_PIN18 18
+#define PORTE_PIN19 19
+#define PORTE_PIN20 20
+#define PORTE_PIN21 21
+#define PORTE_PIN22 22
+#define PORTE_PIN23 23
+#define PORTE_PIN24 24
+#define PORTE_PIN25 25
+#define PORTE_PIN26 26
+#define PORTE_PIN27 27
+#define PORTE_PIN28 28
+#define PORTE_PIN29 29
+#define PORTE_PIN30 30
+#define PORTE_PIN31 31
 
 #define TEENSY_PIN26_IOPORT IOPORT5
 #define TEENSY_PIN31_IOPORT IOPORT5
 
-#define LINE_PIN1           PAL_LINE(TEENSY_PIN1_IOPORT, TEENSY_PIN1)
-#define LINE_PIN2           PAL_LINE(TEENSY_PIN2_IOPORT, TEENSY_PIN2)
-#define LINE_PIN3           PAL_LINE(TEENSY_PIN3_IOPORT, TEENSY_PIN3)
-#define LINE_PIN4           PAL_LINE(TEENSY_PIN4_IOPORT, TEENSY_PIN4)
-#define LINE_PIN5           PAL_LINE(TEENSY_PIN5_IOPORT, TEENSY_PIN5)
-#define LINE_PIN6           PAL_LINE(TEENSY_PIN6_IOPORT, TEENSY_PIN6)
-#define LINE_PIN7           PAL_LINE(TEENSY_PIN7_IOPORT, TEENSY_PIN7)
-#define LINE_PIN8           PAL_LINE(TEENSY_PIN8_IOPORT, TEENSY_PIN8)
-#define LINE_PIN9           PAL_LINE(TEENSY_PIN9_IOPORT, TEENSY_PIN9)
-#define LINE_PIN10          PAL_LINE(TEENSY_PIN10_IOPORT, TEENSY_PIN10)
-#define LINE_PIN11          PAL_LINE(TEENSY_PIN11_IOPORT, TEENSY_PIN11)
-#define LINE_PIN12          PAL_LINE(TEENSY_PIN12_IOPORT, TEENSY_PIN12)
-#define LINE_PIN13          PAL_LINE(TEENSY_PIN13_IOPORT, TEENSY_PIN13)
-#define LINE_PIN14          PAL_LINE(TEENSY_PIN14_IOPORT, TEENSY_PIN14)
-#define LINE_PIN15          PAL_LINE(TEENSY_PIN15_IOPORT, TEENSY_PIN15)
-#define LINE_PIN16          PAL_LINE(TEENSY_PIN16_IOPORT, TEENSY_PIN16)
-#define LINE_PIN17          PAL_LINE(TEENSY_PIN17_IOPORT, TEENSY_PIN17)
-#define LINE_PIN18          PAL_LINE(TEENSY_PIN18_IOPORT, TEENSY_PIN18)
-#define LINE_PIN19          PAL_LINE(TEENSY_PIN19_IOPORT, TEENSY_PIN19)
-#define LINE_PIN20          PAL_LINE(TEENSY_PIN20_IOPORT, TEENSY_PIN20)
-#define LINE_PIN21          PAL_LINE(TEENSY_PIN21_IOPORT, TEENSY_PIN21)
-#define LINE_PIN22          PAL_LINE(TEENSY_PIN22_IOPORT, TEENSY_PIN22)
-#define LINE_PIN23          PAL_LINE(TEENSY_PIN23_IOPORT, TEENSY_PIN23)
-#define LINE_PIN24          PAL_LINE(TEENSY_PIN24_IOPORT, TEENSY_PIN24)
-#define LINE_PIN25          PAL_LINE(TEENSY_PIN25_IOPORT, TEENSY_PIN25)
-#define LINE_PIN25          PAL_LINE(TEENSY_PIN25_IOPORT, TEENSY_PIN25)
-#define LINE_PIN26          PAL_LINE(TEENSY_PIN26_IOPORT, TEENSY_PIN26)
-#define LINE_PIN27          PAL_LINE(TEENSY_PIN27_IOPORT, TEENSY_PIN27)
-#define LINE_PIN28          PAL_LINE(TEENSY_PIN28_IOPORT, TEENSY_PIN28)
-#define LINE_PIN29          PAL_LINE(TEENSY_PIN29_IOPORT, TEENSY_PIN29)
-#define LINE_PIN30          PAL_LINE(TEENSY_PIN30_IOPORT, TEENSY_PIN30)
-#define LINE_PIN31          PAL_LINE(TEENSY_PIN31_IOPORT, TEENSY_PIN31)
-#define LINE_PIN32          PAL_LINE(TEENSY_PIN32_IOPORT, TEENSY_PIN32)
-#define LINE_PIN33          PAL_LINE(TEENSY_PIN33_IOPORT, TEENSY_PIN33)
+#define LINE_PIN1 PAL_LINE(TEENSY_PIN1_IOPORT, TEENSY_PIN1)
+#define LINE_PIN2 PAL_LINE(TEENSY_PIN2_IOPORT, TEENSY_PIN2)
+#define LINE_PIN3 PAL_LINE(TEENSY_PIN3_IOPORT, TEENSY_PIN3)
+#define LINE_PIN4 PAL_LINE(TEENSY_PIN4_IOPORT, TEENSY_PIN4)
+#define LINE_PIN5 PAL_LINE(TEENSY_PIN5_IOPORT, TEENSY_PIN5)
+#define LINE_PIN6 PAL_LINE(TEENSY_PIN6_IOPORT, TEENSY_PIN6)
+#define LINE_PIN7 PAL_LINE(TEENSY_PIN7_IOPORT, TEENSY_PIN7)
+#define LINE_PIN8 PAL_LINE(TEENSY_PIN8_IOPORT, TEENSY_PIN8)
+#define LINE_PIN9 PAL_LINE(TEENSY_PIN9_IOPORT, TEENSY_PIN9)
+#define LINE_PIN10 PAL_LINE(TEENSY_PIN10_IOPORT, TEENSY_PIN10)
+#define LINE_PIN11 PAL_LINE(TEENSY_PIN11_IOPORT, TEENSY_PIN11)
+#define LINE_PIN12 PAL_LINE(TEENSY_PIN12_IOPORT, TEENSY_PIN12)
+#define LINE_PIN13 PAL_LINE(TEENSY_PIN13_IOPORT, TEENSY_PIN13)
+#define LINE_PIN14 PAL_LINE(TEENSY_PIN14_IOPORT, TEENSY_PIN14)
+#define LINE_PIN15 PAL_LINE(TEENSY_PIN15_IOPORT, TEENSY_PIN15)
+#define LINE_PIN16 PAL_LINE(TEENSY_PIN16_IOPORT, TEENSY_PIN16)
+#define LINE_PIN17 PAL_LINE(TEENSY_PIN17_IOPORT, TEENSY_PIN17)
+#define LINE_PIN18 PAL_LINE(TEENSY_PIN18_IOPORT, TEENSY_PIN18)
+#define LINE_PIN19 PAL_LINE(TEENSY_PIN19_IOPORT, TEENSY_PIN19)
+#define LINE_PIN20 PAL_LINE(TEENSY_PIN20_IOPORT, TEENSY_PIN20)
+#define LINE_PIN21 PAL_LINE(TEENSY_PIN21_IOPORT, TEENSY_PIN21)
+#define LINE_PIN22 PAL_LINE(TEENSY_PIN22_IOPORT, TEENSY_PIN22)
+#define LINE_PIN23 PAL_LINE(TEENSY_PIN23_IOPORT, TEENSY_PIN23)
+#define LINE_PIN24 PAL_LINE(TEENSY_PIN24_IOPORT, TEENSY_PIN24)
+#define LINE_PIN25 PAL_LINE(TEENSY_PIN25_IOPORT, TEENSY_PIN25)
+#define LINE_PIN25 PAL_LINE(TEENSY_PIN25_IOPORT, TEENSY_PIN25)
+#define LINE_PIN26 PAL_LINE(TEENSY_PIN26_IOPORT, TEENSY_PIN26)
+#define LINE_PIN27 PAL_LINE(TEENSY_PIN27_IOPORT, TEENSY_PIN27)
+#define LINE_PIN28 PAL_LINE(TEENSY_PIN28_IOPORT, TEENSY_PIN28)
+#define LINE_PIN29 PAL_LINE(TEENSY_PIN29_IOPORT, TEENSY_PIN29)
+#define LINE_PIN30 PAL_LINE(TEENSY_PIN30_IOPORT, TEENSY_PIN30)
+#define LINE_PIN31 PAL_LINE(TEENSY_PIN31_IOPORT, TEENSY_PIN31)
+#define LINE_PIN32 PAL_LINE(TEENSY_PIN32_IOPORT, TEENSY_PIN32)
+#define LINE_PIN33 PAL_LINE(TEENSY_PIN33_IOPORT, TEENSY_PIN33)
 
-#define LINE_LED            LINE_PIN13
+#define LINE_LED LINE_PIN13
 
 #if !defined(_FROM_ASM_)
-#ifdef __cplusplus
+#    ifdef __cplusplus
 extern "C" {
-#endif
-  void boardInit(void);
-#ifdef __cplusplus
+#    endif
+void boardInit(void);
+#    ifdef __cplusplus
 }
-#endif
+#    endif
 #endif /* _FROM_ASM_ */
 
 #endif /* _BOARD_H_ */
index b0e542d8deffcc8afd9b644d828e3d7464b3b9d4..496bbca04e5f4de011bac52c1fe3e2fbf2241be0 100644 (file)
 #define TIMEOUT 100
 
 enum {
-  CMD_INPUT_0 = 0,
-  CMD_INPUT_1,
-  CMD_OUTPUT_0,
-  CMD_OUTPUT_1,
-  CMD_INVERSION_0,
-  CMD_INVERSION_1,
-  CMD_CONFIG_0,
-  CMD_CONFIG_1,
+    CMD_INPUT_0 = 0,
+    CMD_INPUT_1,
+    CMD_OUTPUT_0,
+    CMD_OUTPUT_1,
+    CMD_INVERSION_0,
+    CMD_INVERSION_1,
+    CMD_CONFIG_0,
+    CMD_CONFIG_1,
 };
 
 void pca9555_init(uint8_t slave_addr) {
-  static uint8_t s_init = 0;
-  if (!s_init) {
-    i2c_init();
+    static uint8_t s_init = 0;
+    if (!s_init) {
+        i2c_init();
 
-    s_init = 1;
-  }
+        s_init = 1;
+    }
 
-  // TODO: could check device connected
-  // i2c_start(SLAVE_TO_ADDR(slave) | I2C_WRITE);
-  // i2c_stop();
+    // TODO: could check device connected
+    // i2c_start(SLAVE_TO_ADDR(slave) | I2C_WRITE);
+    // i2c_stop();
 }
 
 void pca9555_set_config(uint8_t slave_addr, uint8_t port, uint8_t conf) {
-  uint8_t addr = SLAVE_TO_ADDR(slave_addr);
-  uint8_t cmd  = port ? CMD_CONFIG_1 : CMD_CONFIG_0;
+    uint8_t addr = SLAVE_TO_ADDR(slave_addr);
+    uint8_t cmd  = port ? CMD_CONFIG_1 : CMD_CONFIG_0;
 
-  i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
-  if (ret != I2C_STATUS_SUCCESS) {
-    print("pca9555_set_config::FAILED\n");
-  }
+    i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
+    if (ret != I2C_STATUS_SUCCESS) {
+        print("pca9555_set_config::FAILED\n");
+    }
 }
 
 void pca9555_set_output(uint8_t slave_addr, uint8_t port, uint8_t conf) {
-  uint8_t addr = SLAVE_TO_ADDR(slave_addr);
-  uint8_t cmd  = port ? CMD_OUTPUT_1 : CMD_OUTPUT_0;
+    uint8_t addr = SLAVE_TO_ADDR(slave_addr);
+    uint8_t cmd  = port ? CMD_OUTPUT_1 : CMD_OUTPUT_0;
 
-  i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
-  if (ret != I2C_STATUS_SUCCESS) {
-    print("pca9555_set_output::FAILED\n");
-  }
+    i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
+    if (ret != I2C_STATUS_SUCCESS) {
+        print("pca9555_set_output::FAILED\n");
+    }
 }
 
 uint8_t pca9555_readPins(uint8_t slave_addr, uint8_t port) {
-  uint8_t addr = SLAVE_TO_ADDR(slave_addr);
-  uint8_t cmd  = port ? CMD_INPUT_1 : CMD_INPUT_0;
+    uint8_t addr = SLAVE_TO_ADDR(slave_addr);
+    uint8_t cmd  = port ? CMD_INPUT_1 : CMD_INPUT_0;
 
-  uint8_t      data = 0;
-  i2c_status_t ret  = i2c_readReg(addr, cmd, &data, sizeof(data), TIMEOUT);
-  if (ret != I2C_STATUS_SUCCESS) {
-    print("pca9555_readPins::FAILED\n");
-  }
-  return data;
+    uint8_t      data = 0;
+    i2c_status_t ret  = i2c_readReg(addr, cmd, &data, sizeof(data), TIMEOUT);
+    if (ret != I2C_STATUS_SUCCESS) {
+        print("pca9555_readPins::FAILED\n");
+    }
+    return data;
 }
index 215e6be3e7cbd2b779e1e11770e52fe6807ca634..f74c965253750c9fff23b47f1ccd9076bbc6b8d4 100644 (file)
 #include <stdio.h>
 #include <math.h>
 
-
 uint8_t DRV2605L_transfer_buffer[2];
 uint8_t DRV2605L_tx_register[0];
 uint8_t DRV2605L_read_buffer[0];
 uint8_t DRV2605L_read_register;
 
-
 void DRV_write(uint8_t drv_register, uint8_t settings) {
-  DRV2605L_transfer_buffer[0] = drv_register;
-  DRV2605L_transfer_buffer[1] = settings;
-  i2c_transmit(DRV2605L_BASE_ADDRESS << 1, DRV2605L_transfer_buffer, 2, 100);
+    DRV2605L_transfer_buffer[0] = drv_register;
+    DRV2605L_transfer_buffer[1] = settings;
+    i2c_transmit(DRV2605L_BASE_ADDRESS << 1, DRV2605L_transfer_buffer, 2, 100);
 }
 
 uint8_t DRV_read(uint8_t regaddress) {
 #ifdef __AVR__
-  i2c_readReg(DRV2605L_BASE_ADDRESS << 1,
-    regaddress, DRV2605L_read_buffer, 1, 100);
-  DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
+    i2c_readReg(DRV2605L_BASE_ADDRESS << 1, regaddress, DRV2605L_read_buffer, 1, 100);
+    DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
 #else
-  DRV2605L_tx_register[0] = regaddress;
-  if (MSG_OK != i2c_transmit_receive(DRV2605L_BASE_ADDRESS << 1,
-    DRV2605L_tx_register, 1,
-    DRV2605L_read_buffer, 1
-)){
-    printf("err reading reg \n");
-  }
-  DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
+    DRV2605L_tx_register[0] = regaddress;
+    if (MSG_OK != i2c_transmit_receive(DRV2605L_BASE_ADDRESS << 1, DRV2605L_tx_register, 1, DRV2605L_read_buffer, 1)) {
+        printf("err reading reg \n");
+    }
+    DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
 #endif
-return DRV2605L_read_register;
+    return DRV2605L_read_register;
 }
 
-void DRV_init(void)
-{
-  i2c_init();
-  /* 0x07 sets DRV2605 into calibration mode */
-  DRV_write(DRV_MODE,0x07); 
+void DRV_init(void) {
+    i2c_init();
+    /* 0x07 sets DRV2605 into calibration mode */
+    DRV_write(DRV_MODE, 0x07);
+
+    //  DRV_write(DRV_FEEDBACK_CTRL,0xB6);
 
-//  DRV_write(DRV_FEEDBACK_CTRL,0xB6);
-    
-  #if FB_ERM_LRA == 0
+#if FB_ERM_LRA == 0
     /* ERM settings */
-  DRV_write(DRV_RATED_VOLT, (RATED_VOLTAGE/21.33)*1000);
-  #if ERM_OPEN_LOOP == 0
-  DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (((V_PEAK*(DRIVE_TIME+BLANKING_TIME+IDISS_TIME))/0.02133)/(DRIVE_TIME-0.0003))); 
-  #elif ERM_OPEN_LOOP == 1
-  DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK/0.02196));
-  #endif
-  #elif FB_ERM_LRA == 1
-  DRV_write(DRV_RATED_VOLT, ((V_RMS * sqrt(1 - ((4 * ((150+(SAMPLE_TIME*50))*0.000001)) + 0.0003)* F_LRA)/0.02071)));
-  #if LRA_OPEN_LOOP == 0
-    DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, ((V_PEAK/sqrt(1-(F_LRA*0.0008))/0.02133)));
-  #elif LRA_OPEN_LOOP == 1
-    DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK/0.02196));
-  #endif
-  #endif
-      
-  DRVREG_FBR FB_SET;
-    FB_SET.Bits.ERM_LRA = FB_ERM_LRA;
+    DRV_write(DRV_RATED_VOLT, (RATED_VOLTAGE / 21.33) * 1000);
+#    if ERM_OPEN_LOOP == 0
+    DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (((V_PEAK * (DRIVE_TIME + BLANKING_TIME + IDISS_TIME)) / 0.02133) / (DRIVE_TIME - 0.0003)));
+#    elif ERM_OPEN_LOOP == 1
+    DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK / 0.02196));
+#    endif
+#elif FB_ERM_LRA == 1
+    DRV_write(DRV_RATED_VOLT, ((V_RMS * sqrt(1 - ((4 * ((150 + (SAMPLE_TIME * 50)) * 0.000001)) + 0.0003) * F_LRA) / 0.02071)));
+#    if LRA_OPEN_LOOP == 0
+    DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, ((V_PEAK / sqrt(1 - (F_LRA * 0.0008)) / 0.02133)));
+#    elif LRA_OPEN_LOOP == 1
+    DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK / 0.02196));
+#    endif
+#endif
+
+    DRVREG_FBR FB_SET;
+    FB_SET.Bits.ERM_LRA      = FB_ERM_LRA;
     FB_SET.Bits.BRAKE_FACTOR = FB_BRAKEFACTOR;
-    FB_SET.Bits.LOOP_GAIN =FB_LOOPGAIN;
-    FB_SET.Bits.BEMF_GAIN = 0; /* auto-calibration populates this field*/
-    DRV_write(DRV_FEEDBACK_CTRL, (uint8_t) FB_SET.Byte);
-  DRVREG_CTRL1 C1_SET;
-    C1_SET.Bits.C1_DRIVE_TIME = DRIVE_TIME;
-    C1_SET.Bits.C1_AC_COUPLE = AC_COUPLE;
+    FB_SET.Bits.LOOP_GAIN    = FB_LOOPGAIN;
+    FB_SET.Bits.BEMF_GAIN    = 0; /* auto-calibration populates this field*/
+    DRV_write(DRV_FEEDBACK_CTRL, (uint8_t)FB_SET.Byte);
+    DRVREG_CTRL1 C1_SET;
+    C1_SET.Bits.C1_DRIVE_TIME    = DRIVE_TIME;
+    C1_SET.Bits.C1_AC_COUPLE     = AC_COUPLE;
     C1_SET.Bits.C1_STARTUP_BOOST = STARTUP_BOOST;
-    DRV_write(DRV_CTRL_1, (uint8_t) C1_SET.Byte);
-  DRVREG_CTRL2 C2_SET;
-    C2_SET.Bits.C2_BIDIR_INPUT = BIDIR_INPUT;
-    C2_SET.Bits.C2_BRAKE_STAB = BRAKE_STAB;
-    C2_SET.Bits.C2_SAMPLE_TIME = SAMPLE_TIME;
+    DRV_write(DRV_CTRL_1, (uint8_t)C1_SET.Byte);
+    DRVREG_CTRL2 C2_SET;
+    C2_SET.Bits.C2_BIDIR_INPUT   = BIDIR_INPUT;
+    C2_SET.Bits.C2_BRAKE_STAB    = BRAKE_STAB;
+    C2_SET.Bits.C2_SAMPLE_TIME   = SAMPLE_TIME;
     C2_SET.Bits.C2_BLANKING_TIME = BLANKING_TIME;
-    C2_SET.Bits.C2_IDISS_TIME = IDISS_TIME;
-    DRV_write(DRV_CTRL_2, (uint8_t) C2_SET.Byte);
-  DRVREG_CTRL3 C3_SET;
-    C3_SET.Bits.C3_LRA_OPEN_LOOP = LRA_OPEN_LOOP;
-    C3_SET.Bits.C3_N_PWM_ANALOG = N_PWM_ANALOG;
-    C3_SET.Bits.C3_LRA_DRIVE_MODE = LRA_DRIVE_MODE;
+    C2_SET.Bits.C2_IDISS_TIME    = IDISS_TIME;
+    DRV_write(DRV_CTRL_2, (uint8_t)C2_SET.Byte);
+    DRVREG_CTRL3 C3_SET;
+    C3_SET.Bits.C3_LRA_OPEN_LOOP   = LRA_OPEN_LOOP;
+    C3_SET.Bits.C3_N_PWM_ANALOG    = N_PWM_ANALOG;
+    C3_SET.Bits.C3_LRA_DRIVE_MODE  = LRA_DRIVE_MODE;
     C3_SET.Bits.C3_DATA_FORMAT_RTO = DATA_FORMAT_RTO;
     C3_SET.Bits.C3_SUPPLY_COMP_DIS = SUPPLY_COMP_DIS;
-    C3_SET.Bits.C3_ERM_OPEN_LOOP = ERM_OPEN_LOOP;
-    C3_SET.Bits.C3_NG_THRESH = NG_THRESH;
-    DRV_write(DRV_CTRL_3, (uint8_t) C3_SET.Byte);
-  DRVREG_CTRL4 C4_SET;
-    C4_SET.Bits.C4_ZC_DET_TIME = ZC_DET_TIME;
+    C3_SET.Bits.C3_ERM_OPEN_LOOP   = ERM_OPEN_LOOP;
+    C3_SET.Bits.C3_NG_THRESH       = NG_THRESH;
+    DRV_write(DRV_CTRL_3, (uint8_t)C3_SET.Byte);
+    DRVREG_CTRL4 C4_SET;
+    C4_SET.Bits.C4_ZC_DET_TIME   = ZC_DET_TIME;
     C4_SET.Bits.C4_AUTO_CAL_TIME = AUTO_CAL_TIME;
-    DRV_write(DRV_CTRL_4, (uint8_t) C4_SET.Byte);
-  DRV_write(DRV_LIB_SELECTION,LIB_SELECTION);
+    DRV_write(DRV_CTRL_4, (uint8_t)C4_SET.Byte);
+    DRV_write(DRV_LIB_SELECTION, LIB_SELECTION);
 
-  DRV_write(DRV_GO, 0x01);
+    DRV_write(DRV_GO, 0x01);
 
-  /* 0x00 sets DRV2605 out of standby and to use internal trigger
-   * 0x01 sets DRV2605 out of standby and to use external trigger */
-  DRV_write(DRV_MODE,0x00); 
+    /* 0x00 sets DRV2605 out of standby and to use internal trigger
+     * 0x01 sets DRV2605 out of standby and to use external trigger */
+    DRV_write(DRV_MODE, 0x00);
 
-//Play greeting sequence
-  DRV_write(DRV_GO, 0x00);
-  DRV_write(DRV_WAVEFORM_SEQ_1, DRV_GREETING);
-  DRV_write(DRV_GO, 0x01);
+    // Play greeting sequence
+    DRV_write(DRV_GO, 0x00);
+    DRV_write(DRV_WAVEFORM_SEQ_1, DRV_GREETING);
+    DRV_write(DRV_GO, 0x01);
 }
 
-void DRV_pulse(uint8_t sequence)
-{
-  DRV_write(DRV_GO, 0x00);
-  DRV_write(DRV_WAVEFORM_SEQ_1, sequence);
-  DRV_write(DRV_GO, 0x01);
+void DRV_pulse(uint8_t sequence) {
+    DRV_write(DRV_GO, 0x00);
+    DRV_write(DRV_WAVEFORM_SEQ_1, sequence);
+    DRV_write(DRV_GO, 0x01);
 }
\ No newline at end of file
index 836e9cbcd281fda1fd50b8cb1bbcf702be9ca490..f550b859f7c94008f83c6ea99b3447da2b97b6f1 100644 (file)
 
  * Feedback Control Settings */
 #ifndef FB_ERM_LRA
-#define FB_ERM_LRA 1 /* For ERM:0 or LRA:1*/
+#    define FB_ERM_LRA 1 /* For ERM:0 or LRA:1*/
 #endif
 #ifndef FB_BRAKEFACTOR
-#define FB_BRAKEFACTOR 3 /* For 1x:0, 2x:1, 3x:2, 4x:3, 6x:4, 8x:5, 16x:6, Disable Braking:7 */
+#    define FB_BRAKEFACTOR 3 /* For 1x:0, 2x:1, 3x:2, 4x:3, 6x:4, 8x:5, 16x:6, Disable Braking:7 */
 #endif
 #ifndef FB_LOOPGAIN
-#define FB_LOOPGAIN 1 /* For  Low:0, Medium:1, High:2, Very High:3 */
+#    define FB_LOOPGAIN 1 /* For  Low:0, Medium:1, High:2, Very High:3 */
 #endif
 
 /* LRA specific settings */
 #if FB_ERM_LRA == 1
-#ifndef V_RMS
-#define V_RMS 2.0
-#endif
-#ifndef V_PEAK
-#define V_PEAK 2.1
-#endif
-#ifndef F_LRA
-#define F_LRA 205
-#endif
-#ifndef RATED_VOLTAGE
-#define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */
-#endif
+#    ifndef V_RMS
+#        define V_RMS 2.0
+#    endif
+#    ifndef V_PEAK
+#        define V_PEAK 2.1
+#    endif
+#    ifndef F_LRA
+#        define F_LRA 205
+#    endif
+#    ifndef RATED_VOLTAGE
+#        define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */
+#    endif
 #endif
 
 #ifndef RATED_VOLTAGE
-#define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */
+#    define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */
 #endif
 #ifndef V_PEAK
-#define V_PEAK 2.8
+#    define V_PEAK 2.8
 #endif
 
 /* Library Selection */
 #ifndef LIB_SELECTION
-#if FB_ERM_LRA == 1
-#define LIB_SELECTION 6 /* For Empty:0' TS2200 library A to D:1-5, LRA Library: 6 */
-#else
-#define LIB_SELECTION 1
-#endif
+#    if FB_ERM_LRA == 1
+#        define LIB_SELECTION 6 /* For Empty:0' TS2200 library A to D:1-5, LRA Library: 6 */
+#    else
+#        define LIB_SELECTION 1
+#    endif
 #endif
 
 #ifndef DRV_GREETING
-#define DRV_GREETING alert_750ms
+#    define DRV_GREETING alert_750ms
 #endif
 #ifndef DRV_MODE_DEFAULT
-#define DRV_MODE_DEFAULT strong_click1
+#    define DRV_MODE_DEFAULT strong_click1
 #endif
 
 /* Control 1 register settings */
 #ifndef DRIVE_TIME
-#define DRIVE_TIME 25
+#    define DRIVE_TIME 25
 #endif
 #ifndef AC_COUPLE
-#define AC_COUPLE 0
+#    define AC_COUPLE 0
 #endif
 #ifndef STARTUP_BOOST
-#define STARTUP_BOOST 1
+#    define STARTUP_BOOST 1
 #endif
 
 /* Control 2 Settings */
 #ifndef BIDIR_INPUT
-#define BIDIR_INPUT 1
+#    define BIDIR_INPUT 1
 #endif
 #ifndef BRAKE_STAB
-#define BRAKE_STAB 1 /* Loopgain is reduced when braking is almost complete to improve stability */
+#    define BRAKE_STAB 1 /* Loopgain is reduced when braking is almost complete to improve stability */
 #endif
-#ifndef SAMPLE_TIME 
-#define SAMPLE_TIME 3
+#ifndef SAMPLE_TIME
+#    define SAMPLE_TIME 3
 #endif
 #ifndef BLANKING_TIME
-#define BLANKING_TIME 1
+#    define BLANKING_TIME 1
 #endif
 #ifndef IDISS_TIME
-#define IDISS_TIME 1
+#    define IDISS_TIME 1
 #endif
 
 /* Control 3 settings */
 #ifndef NG_THRESH
-#define NG_THRESH 2
+#    define NG_THRESH 2
 #endif
 #ifndef ERM_OPEN_LOOP
-#define ERM_OPEN_LOOP 1
+#    define ERM_OPEN_LOOP 1
 #endif
 #ifndef SUPPLY_COMP_DIS
-#define SUPPLY_COMP_DIS 0
+#    define SUPPLY_COMP_DIS 0
 #endif
 #ifndef DATA_FORMAT_RTO
-#define DATA_FORMAT_RTO 0
+#    define DATA_FORMAT_RTO 0
 #endif
 #ifndef LRA_DRIVE_MODE
-#define LRA_DRIVE_MODE 0
+#    define LRA_DRIVE_MODE 0
 #endif
 #ifndef N_PWM_ANALOG
-#define N_PWM_ANALOG 0
+#    define N_PWM_ANALOG 0
 #endif
 #ifndef LRA_OPEN_LOOP
-#define LRA_OPEN_LOOP 0
+#    define LRA_OPEN_LOOP 0
 #endif
 
 /* Control 4 settings */
 #ifndef ZC_DET_TIME
-#define ZC_DET_TIME 0
+#    define ZC_DET_TIME 0
 #endif
 #ifndef AUTO_CAL_TIME
-#define AUTO_CAL_TIME 3
+#    define AUTO_CAL_TIME 3
 #endif
 
 /* register defines -------------------------------------------------------- */
-#define DRV2605L_BASE_ADDRESS       0x5A               /* DRV2605L Base address */
-#define DRV_STATUS                  0x00
-#define DRV_MODE                    0x01
-#define DRV_RTP_INPUT               0x02
-#define DRV_LIB_SELECTION           0x03
-#define DRV_WAVEFORM_SEQ_1          0x04
-#define DRV_WAVEFORM_SEQ_2          0x05
-#define DRV_WAVEFORM_SEQ_3          0x06
-#define DRV_WAVEFORM_SEQ_4          0x07
-#define DRV_WAVEFORM_SEQ_5          0x08
-#define DRV_WAVEFORM_SEQ_6          0x09
-#define DRV_WAVEFORM_SEQ_7          0x0A
-#define DRV_WAVEFORM_SEQ_8          0x0B
-#define DRV_GO                      0x0C
-#define DRV_OVERDRIVE_TIME_OFFSET   0x0D
-#define DRV_SUSTAIN_TIME_OFFSET_P   0x0E
-#define DRV_SUSTAIN_TIME_OFFSET_N   0x0F
-#define DRV_BRAKE_TIME_OFFSET       0x10
-#define DRV_AUDIO_2_VIBE_CTRL       0x11
-#define DRV_AUDIO_2_VIBE_MIN_IN     0x12
-#define DRV_AUDIO_2_VIBE_MAX_IN     0x13
-#define DRV_AUDIO_2_VIBE_MIN_OUTDRV    0x14
-#define DRV_AUDIO_2_VIBE_MAX_OUTDRV    0x15
-#define DRV_RATED_VOLT              0x16
-#define DRV_OVERDRIVE_CLAMP_VOLT    0x17
-#define DRV_AUTO_CALIB_COMP_RESULT  0x18 
-#define DRV_AUTO_CALIB_BEMF_RESULT  0x19
-#define DRV_FEEDBACK_CTRL           0x1A
-#define DRV_CTRL_1                  0x1B
-#define DRV_CTRL_2                  0x1C
-#define DRV_CTRL_3                  0x1D
-#define DRV_CTRL_4                  0x1E
-#define DRV_CTRL_5                  0x1F
-#define DRV_OPEN_LOOP_PERIOD        0x20
-#define DRV_VBAT_VOLT_MONITOR       0x21
-#define DRV_LRA_RESONANCE_PERIOD    0x22
+#define DRV2605L_BASE_ADDRESS 0x5A /* DRV2605L Base address */
+#define DRV_STATUS 0x00
+#define DRV_MODE 0x01
+#define DRV_RTP_INPUT 0x02
+#define DRV_LIB_SELECTION 0x03
+#define DRV_WAVEFORM_SEQ_1 0x04
+#define DRV_WAVEFORM_SEQ_2 0x05
+#define DRV_WAVEFORM_SEQ_3 0x06
+#define DRV_WAVEFORM_SEQ_4 0x07
+#define DRV_WAVEFORM_SEQ_5 0x08
+#define DRV_WAVEFORM_SEQ_6 0x09
+#define DRV_WAVEFORM_SEQ_7 0x0A
+#define DRV_WAVEFORM_SEQ_8 0x0B
+#define DRV_GO 0x0C
+#define DRV_OVERDRIVE_TIME_OFFSET 0x0D
+#define DRV_SUSTAIN_TIME_OFFSET_P 0x0E
+#define DRV_SUSTAIN_TIME_OFFSET_N 0x0F
+#define DRV_BRAKE_TIME_OFFSET 0x10
+#define DRV_AUDIO_2_VIBE_CTRL 0x11
+#define DRV_AUDIO_2_VIBE_MIN_IN 0x12
+#define DRV_AUDIO_2_VIBE_MAX_IN 0x13
+#define DRV_AUDIO_2_VIBE_MIN_OUTDRV 0x14
+#define DRV_AUDIO_2_VIBE_MAX_OUTDRV 0x15
+#define DRV_RATED_VOLT 0x16
+#define DRV_OVERDRIVE_CLAMP_VOLT 0x17
+#define DRV_AUTO_CALIB_COMP_RESULT 0x18
+#define DRV_AUTO_CALIB_BEMF_RESULT 0x19
+#define DRV_FEEDBACK_CTRL 0x1A
+#define DRV_CTRL_1 0x1B
+#define DRV_CTRL_2 0x1C
+#define DRV_CTRL_3 0x1D
+#define DRV_CTRL_4 0x1E
+#define DRV_CTRL_5 0x1F
+#define DRV_OPEN_LOOP_PERIOD 0x20
+#define DRV_VBAT_VOLT_MONITOR 0x21
+#define DRV_LRA_RESONANCE_PERIOD 0x22
 
-void DRV_init(void);
-void DRV_write(const uint8_t drv_register, const uint8_t settings);
+void    DRV_init(void);
+void    DRV_write(const uint8_t drv_register, const uint8_t settings);
 uint8_t DRV_read(const uint8_t regaddress);
-void DRV_pulse(const uint8_t sequence);
+void    DRV_pulse(const uint8_t sequence);
 
-typedef enum DRV_EFFECT{
-  clear_sequence      = 0,
-  strong_click                     = 1,
-  strong_click_60              = 2,
-  strong_click_30              = 3,
-  sharp_click              = 4,
-  sharp_click_60      = 5,
-  sharp_click_30      = 6,
-  soft_bump           = 7,
-  soft_bump_60        = 8,
-  soft_bump_30        = 9,
-  dbl_click           = 10,
-  dbl_click_60        = 11,
-  trp_click           = 12,
-  soft_fuzz           = 13,
-  strong_buzz         = 14,
-  alert_750ms         = 15,
-  alert_1000ms        = 16,
-  strong_click1       = 17,
-  strong_click2_80    = 18,
-  strong_click3_60    = 19,
-  strong_click4_30    = 20,
-  medium_click1       = 21,
-  medium_click2_80    = 22,
-  medium_click3_60    = 23,
-  sharp_tick1         = 24,
-  sharp_tick2_80      = 25,
-  sharp_tick3_60      = 26,
-  sh_dblclick_str     = 27,
-  sh_dblclick_str_80  = 28,
-  sh_dblclick_str_60  = 29,
-  sh_dblclick_str_30  = 30,
-  sh_dblclick_med     = 31,
-  sh_dblclick_med_80  = 32,
-  sh_dblclick_med_60  = 33,
-  sh_dblsharp_tick    = 34,
-  sh_dblsharp_tick_80 = 35,
-  sh_dblsharp_tick_60 = 36,
-  lg_dblclick_str     = 37,
-  lg_dblclick_str_80  = 38,
-  lg_dblclick_str_60  = 39,
-  lg_dblclick_str_30  = 40,
-  lg_dblclick_med     = 41,
-  lg_dblclick_med_80  = 42,
-  lg_dblclick_med_60  = 43,
-  lg_dblsharp_tick    = 44,
-  lg_dblsharp_tick_80 = 45,
-  lg_dblsharp_tick_60 = 46,
-  buzz                                         = 47,
-  buzz_80                              = 48,
-  buzz_60                              = 49,
-  buzz_40                              = 50,
-  buzz_20                              = 51,
-  pulsing_strong      = 52,
-  pulsing_strong_80   = 53,
-  pulsing_medium      = 54,
-  pulsing_medium_80   = 55,
-  pulsing_sharp       = 56,
-  pulsing_sharp_80    = 57,
-  transition_click             = 58,
-  transition_click_80 = 59,
-  transition_click_60  = 60,
-  transition_click_40  = 61,
-  transition_click_20  = 62,
-  transition_click_10  = 63,
-  transition_hum      = 64,
-  transition_hum_80   = 65,
-  transition_hum_60   = 66,
-  transition_hum_40   = 67,
-  transition_hum_20   = 68,
-  transition_hum_10   = 69,
-  transition_rampdown_long_smooth1  = 70,
-  transition_rampdown_long_smooth2  = 71,
-  transition_rampdown_med_smooth1   = 72,
-  transition_rampdown_med_smooth2   = 73,
-  transition_rampdown_short_smooth1 = 74,
-  transition_rampdown_short_smooth2 = 75,
-  transition_rampdown_long_sharp1   = 76,
-  transition_rampdown_long_sharp2   = 77,
-  transition_rampdown_med_sharp1    = 78,
-  transition_rampdown_med_sharp2    = 79,
-  transition_rampdown_short_sharp1  = 80,
-  transition_rampdown_short_sharp2  = 81,
-  transition_rampup_long_smooth1    = 82,
-  transition_rampup_long_smooth2    = 83,
-  transition_rampup_med_smooth1     = 84,
-  transition_rampup_med_smooth2     = 85,
-  transition_rampup_short_smooth1   = 86,
-  transition_rampup_short_smooth2   = 87,
-  transition_rampup_long_sharp1     = 88,
-  transition_rampup_long_sharp2     = 89,
-  transition_rampup_med_sharp1      = 90,
-  transition_rampup_med_sharp2      = 91,
-  transition_rampup_short_sharp1    = 92,
-  transition_rampup_short_sharp2    = 93,
-  transition_rampdown_long_smooth1_50  = 94,
-  transition_rampdown_long_smooth2_50  = 95,
-  transition_rampdown_med_smooth1_50   = 96,
-  transition_rampdown_med_smooth2_50   = 97,
-  transition_rampdown_short_smooth1_50 = 98,
-  transition_rampdown_short_smooth2_50 = 99,
-  transition_rampdown_long_sharp1_50   = 100,
-  transition_rampdown_long_sharp2_50   = 101,
-  transition_rampdown_med_sharp1_50    = 102,
-  transition_rampdown_med_sharp2_50    = 103,
-  transition_rampdown_short_sharp1_50  = 104,
-  transition_rampdown_short_sharp2_50  = 105,
-  transition_rampup_long_smooth1_50    = 106,
-  transition_rampup_long_smooth2_50    = 107,
-  transition_rampup_med_smooth1_50     = 108,
-  transition_rampup_med_smooth2_50     = 109,
-  transition_rampup_short_smooth1_50   = 110,
-  transition_rampup_short_smooth2_50   = 111,
-  transition_rampup_long_sharp1_50     = 112,
-  transition_rampup_long_sharp2_50     = 113,
-  transition_rampup_med_sharp1_50      = 114,
-  transition_rampup_med_sharp2_50      = 115,
-  transition_rampup_short_sharp1_50    = 116,
-  transition_rampup_short_sharp2_50    = 117,
-  long_buzz_for_programmatic_stopping  = 118,
-  smooth_hum1_50 = 119,
-  smooth_hum2_40 = 120,
-  smooth_hum3_30 = 121,
-  smooth_hum4_20 = 122,
-  smooth_hum5_10 = 123,
-  drv_effect_max = 124,
+typedef enum DRV_EFFECT {
+    clear_sequence                       = 0,
+    strong_click                         = 1,
+    strong_click_60                      = 2,
+    strong_click_30                      = 3,
+    sharp_click                          = 4,
+    sharp_click_60                       = 5,
+    sharp_click_30                       = 6,
+    soft_bump                            = 7,
+    soft_bump_60                         = 8,
+    soft_bump_30                         = 9,
+    dbl_click                            = 10,
+    dbl_click_60                         = 11,
+    trp_click                            = 12,
+    soft_fuzz                            = 13,
+    strong_buzz                          = 14,
+    alert_750ms                          = 15,
+    alert_1000ms                         = 16,
+    strong_click1                        = 17,
+    strong_click2_80                     = 18,
+    strong_click3_60                     = 19,
+    strong_click4_30                     = 20,
+    medium_click1                        = 21,
+    medium_click2_80                     = 22,
+    medium_click3_60                     = 23,
+    sharp_tick1                          = 24,
+    sharp_tick2_80                       = 25,
+    sharp_tick3_60                       = 26,
+    sh_dblclick_str                      = 27,
+    sh_dblclick_str_80                   = 28,
+    sh_dblclick_str_60                   = 29,
+    sh_dblclick_str_30                   = 30,
+    sh_dblclick_med                      = 31,
+    sh_dblclick_med_80                   = 32,
+    sh_dblclick_med_60                   = 33,
+    sh_dblsharp_tick                     = 34,
+    sh_dblsharp_tick_80                  = 35,
+    sh_dblsharp_tick_60                  = 36,
+    lg_dblclick_str                      = 37,
+    lg_dblclick_str_80                   = 38,
+    lg_dblclick_str_60                   = 39,
+    lg_dblclick_str_30                   = 40,
+    lg_dblclick_med                      = 41,
+    lg_dblclick_med_80                   = 42,
+    lg_dblclick_med_60                   = 43,
+    lg_dblsharp_tick                     = 44,
+    lg_dblsharp_tick_80                  = 45,
+    lg_dblsharp_tick_60                  = 46,
+    buzz                                 = 47,
+    buzz_80                              = 48,
+    buzz_60                              = 49,
+    buzz_40                              = 50,
+    buzz_20                              = 51,
+    pulsing_strong                       = 52,
+    pulsing_strong_80                    = 53,
+    pulsing_medium                       = 54,
+    pulsing_medium_80                    = 55,
+    pulsing_sharp                        = 56,
+    pulsing_sharp_80                     = 57,
+    transition_click                     = 58,
+    transition_click_80                  = 59,
+    transition_click_60                  = 60,
+    transition_click_40                  = 61,
+    transition_click_20                  = 62,
+    transition_click_10                  = 63,
+    transition_hum                       = 64,
+    transition_hum_80                    = 65,
+    transition_hum_60                    = 66,
+    transition_hum_40                    = 67,
+    transition_hum_20                    = 68,
+    transition_hum_10                    = 69,
+    transition_rampdown_long_smooth1     = 70,
+    transition_rampdown_long_smooth2     = 71,
+    transition_rampdown_med_smooth1      = 72,
+    transition_rampdown_med_smooth2      = 73,
+    transition_rampdown_short_smooth1    = 74,
+    transition_rampdown_short_smooth2    = 75,
+    transition_rampdown_long_sharp1      = 76,
+    transition_rampdown_long_sharp2      = 77,
+    transition_rampdown_med_sharp1       = 78,
+    transition_rampdown_med_sharp2       = 79,
+    transition_rampdown_short_sharp1     = 80,
+    transition_rampdown_short_sharp2     = 81,
+    transition_rampup_long_smooth1       = 82,
+    transition_rampup_long_smooth2       = 83,
+    transition_rampup_med_smooth1        = 84,
+    transition_rampup_med_smooth2        = 85,
+    transition_rampup_short_smooth1      = 86,
+    transition_rampup_short_smooth2      = 87,
+    transition_rampup_long_sharp1        = 88,
+    transition_rampup_long_sharp2        = 89,
+    transition_rampup_med_sharp1         = 90,
+    transition_rampup_med_sharp2         = 91,
+    transition_rampup_short_sharp1       = 92,
+    transition_rampup_short_sharp2       = 93,
+    transition_rampdown_long_smooth1_50  = 94,
+    transition_rampdown_long_smooth2_50  = 95,
+    transition_rampdown_med_smooth1_50   = 96,
+    transition_rampdown_med_smooth2_50   = 97,
+    transition_rampdown_short_smooth1_50 = 98,
+    transition_rampdown_short_smooth2_50 = 99,
+    transition_rampdown_long_sharp1_50   = 100,
+    transition_rampdown_long_sharp2_50   = 101,
+    transition_rampdown_med_sharp1_50    = 102,
+    transition_rampdown_med_sharp2_50    = 103,
+    transition_rampdown_short_sharp1_50  = 104,
+    transition_rampdown_short_sharp2_50  = 105,
+    transition_rampup_long_smooth1_50    = 106,
+    transition_rampup_long_smooth2_50    = 107,
+    transition_rampup_med_smooth1_50     = 108,
+    transition_rampup_med_smooth2_50     = 109,
+    transition_rampup_short_smooth1_50   = 110,
+    transition_rampup_short_smooth2_50   = 111,
+    transition_rampup_long_sharp1_50     = 112,
+    transition_rampup_long_sharp2_50     = 113,
+    transition_rampup_med_sharp1_50      = 114,
+    transition_rampup_med_sharp2_50      = 115,
+    transition_rampup_short_sharp1_50    = 116,
+    transition_rampup_short_sharp2_50    = 117,
+    long_buzz_for_programmatic_stopping  = 118,
+    smooth_hum1_50                       = 119,
+    smooth_hum2_40                       = 120,
+    smooth_hum3_30                       = 121,
+    smooth_hum4_20                       = 122,
+    smooth_hum5_10                       = 123,
+    drv_effect_max                       = 124,
 } DRV_EFFECT;
 
 /* Register bit array unions */
 
 typedef union DRVREG_STATUS { /* register 0x00 */
-  uint8_t Byte;
-  struct {
-    uint8_t OC_DETECT   :1; /* set to 1 when overcurrent event is detected */
-    uint8_t OVER_TEMP   :1; /* set to 1 when device exceeds temp threshold */
-    uint8_t FB_STS      :1; /* set to 1 when feedback controller has timed out */
-    /* auto-calibration routine and diagnostic result
-     * result  |  auto-calibation  |      diagnostic       |
-     *   0     |      passed       | actuator func normal  |
-     *   1     |      failed       | actuator func fault*  |
-     * * actuator is not present or is shorted, timing out, or giving out–of-range back-EMF */
-    uint8_t DIAG_RESULT :1;
-    uint8_t             :1;
-    uint8_t DEVICE_ID   :3; /* Device IDs 3: DRV2605  4: DRV2604  5: DRV2604L  6: DRV2605L */
-  } Bits;
+    uint8_t Byte;
+    struct {
+        uint8_t OC_DETECT : 1; /* set to 1 when overcurrent event is detected */
+        uint8_t OVER_TEMP : 1; /* set to 1 when device exceeds temp threshold */
+        uint8_t FB_STS : 1;    /* set to 1 when feedback controller has timed out */
+        /* auto-calibration routine and diagnostic result
+         * result  |  auto-calibation  |      diagnostic       |
+         *   0     |      passed       | actuator func normal  |
+         *   1     |      failed       | actuator func fault*  |
+         * * actuator is not present or is shorted, timing out, or giving out–of-range back-EMF */
+        uint8_t DIAG_RESULT : 1;
+        uint8_t : 1;
+        uint8_t DEVICE_ID : 3; /* Device IDs 3: DRV2605  4: DRV2604  5: DRV2604L  6: DRV2605L */
+    } Bits;
 } DRVREG_STATUS;
 
 typedef union DRVREG_MODE { /* register 0x01 */
-  uint8_t Byte;
-  struct {
-    uint8_t MODE        :3; /* Mode setting */
-    uint8_t             :3;
-    uint8_t STANDBY     :1; /* 0:standby 1:ready */
-  } Bits;
+    uint8_t Byte;
+    struct {
+        uint8_t MODE : 3; /* Mode setting */
+        uint8_t : 3;
+        uint8_t STANDBY : 1; /* 0:standby 1:ready */
+    } Bits;
 } DRVREG_MODE;
 
 typedef union DRVREG_WAIT {
-  uint8_t Byte;
-  struct {
-    uint8_t WAIT_MODE   :1; /* Set to 1 to interpret as wait for next 7 bits x10ms */
-    uint8_t WAIT_TIME   :7;
-  } Bits;
+    uint8_t Byte;
+    struct {
+        uint8_t WAIT_MODE : 1; /* Set to 1 to interpret as wait for next 7 bits x10ms */
+        uint8_t WAIT_TIME : 7;
+    } Bits;
 } DRVREG_WAIT;
 
-typedef union DRVREG_FBR{ /* register 0x1A */
-  uint8_t Byte;
-  struct {
-    uint8_t BEMF_GAIN    :2;
-    uint8_t LOOP_GAIN    :2;
-    uint8_t BRAKE_FACTOR :3;
-    uint8_t ERM_LRA      :1;
-  } Bits;
+typedef union DRVREG_FBR { /* register 0x1A */
+    uint8_t Byte;
+    struct {
+        uint8_t BEMF_GAIN : 2;
+        uint8_t LOOP_GAIN : 2;
+        uint8_t BRAKE_FACTOR : 3;
+        uint8_t ERM_LRA : 1;
+    } Bits;
 } DRVREG_FBR;
 
-typedef union DRVREG_CTRL1{ /* register 0x1B */
-  uint8_t Byte;
-  struct {
-    uint8_t C1_DRIVE_TIME    :5;
-    uint8_t C1_AC_COUPLE     :1;
-    uint8_t                  :1;
-    uint8_t C1_STARTUP_BOOST :1;
-  } Bits;
+typedef union DRVREG_CTRL1 { /* register 0x1B */
+    uint8_t Byte;
+    struct {
+        uint8_t C1_DRIVE_TIME : 5;
+        uint8_t C1_AC_COUPLE : 1;
+        uint8_t : 1;
+        uint8_t C1_STARTUP_BOOST : 1;
+    } Bits;
 } DRVREG_CTRL1;
 
-typedef union DRVREG_CTRL2{ /* register 0x1C */
-  uint8_t Byte;
-  struct {
-    uint8_t C2_IDISS_TIME    :2;
-    uint8_t C2_BLANKING_TIME :2;
-    uint8_t C2_SAMPLE_TIME   :2;
-    uint8_t C2_BRAKE_STAB    :1;
-    uint8_t C2_BIDIR_INPUT   :1;
-  } Bits;
+typedef union DRVREG_CTRL2 { /* register 0x1C */
+    uint8_t Byte;
+    struct {
+        uint8_t C2_IDISS_TIME : 2;
+        uint8_t C2_BLANKING_TIME : 2;
+        uint8_t C2_SAMPLE_TIME : 2;
+        uint8_t C2_BRAKE_STAB : 1;
+        uint8_t C2_BIDIR_INPUT : 1;
+    } Bits;
 } DRVREG_CTRL2;
 
-typedef union DRVREG_CTRL3{ /* register 0x1D */
-  uint8_t Byte;
-  struct {
-    uint8_t C3_LRA_OPEN_LOOP   :1;
-    uint8_t C3_N_PWM_ANALOG    :1;
-    uint8_t C3_LRA_DRIVE_MODE  :1;
-    uint8_t C3_DATA_FORMAT_RTO :1;
-    uint8_t C3_SUPPLY_COMP_DIS :1;
-    uint8_t C3_ERM_OPEN_LOOP   :1;
-    uint8_t C3_NG_THRESH       :2;
-  } Bits;
+typedef union DRVREG_CTRL3 { /* register 0x1D */
+    uint8_t Byte;
+    struct {
+        uint8_t C3_LRA_OPEN_LOOP : 1;
+        uint8_t C3_N_PWM_ANALOG : 1;
+        uint8_t C3_LRA_DRIVE_MODE : 1;
+        uint8_t C3_DATA_FORMAT_RTO : 1;
+        uint8_t C3_SUPPLY_COMP_DIS : 1;
+        uint8_t C3_ERM_OPEN_LOOP : 1;
+        uint8_t C3_NG_THRESH : 2;
+    } Bits;
 } DRVREG_CTRL3;
 
-typedef union DRVREG_CTRL4{ /* register 0x1E */
-  uint8_t Byte;
-  struct {
-    uint8_t C4_OTP_PROGRAM     :1;
-    uint8_t                    :1;
-    uint8_t C4_OTP_STATUS      :1;
-    uint8_t                    :1;
-    uint8_t C4_AUTO_CAL_TIME   :2;
-    uint8_t C4_ZC_DET_TIME     :2;
-  } Bits;
+typedef union DRVREG_CTRL4 { /* register 0x1E */
+    uint8_t Byte;
+    struct {
+        uint8_t C4_OTP_PROGRAM : 1;
+        uint8_t : 1;
+        uint8_t C4_OTP_STATUS : 1;
+        uint8_t : 1;
+        uint8_t C4_AUTO_CAL_TIME : 2;
+        uint8_t C4_ZC_DET_TIME : 2;
+    } Bits;
 } DRVREG_CTRL4;
 
-typedef union DRVREG_CTRL5{ /* register 0x1F */
-  uint8_t Byte;
-  struct {
-    uint8_t C5_IDISS_TIME         :2;
-    uint8_t C5_BLANKING_TIME      :2;
-    uint8_t C5_PLAYBACK_INTERVAL  :1;
-    uint8_t C5_LRA_AUTO_OPEN_LOOP :1;
-    uint8_t C5_AUTO_OL_CNT        :2;
-  } Bits;
+typedef union DRVREG_CTRL5 { /* register 0x1F */
+    uint8_t Byte;
+    struct {
+        uint8_t C5_IDISS_TIME : 2;
+        uint8_t C5_BLANKING_TIME : 2;
+        uint8_t C5_PLAYBACK_INTERVAL : 1;
+        uint8_t C5_LRA_AUTO_OPEN_LOOP : 1;
+        uint8_t C5_AUTO_OL_CNT : 2;
+    } Bits;
 } DRVREG_CTRL5;
\ No newline at end of file
index a94f05565c228c8c373ad8cea4f093226e3eeea5..ded6d8a44a0416de83747e6f30ce933920866564 100644 (file)
 #include "progmem.h"
 #include "debug.h"
 #ifdef DRV2605L
-#include "DRV2605L.h"
+#    include "DRV2605L.h"
 #endif
 #ifdef SOLENOID_ENABLE
-#include "solenoid.h"
+#    include "solenoid.h"
 #endif
 
 haptic_config_t haptic_config;
 
 void haptic_init(void) {
-  debug_enable = 1; //Debug is ON!
-  if (!eeconfig_is_enabled()) {
-       eeconfig_init();
-  }
-  haptic_config.raw = eeconfig_read_haptic();
-  if (haptic_config.mode < 1){
-  haptic_config.mode = 1;
-  }
-  if (!haptic_config.mode){
-  dprintf("No haptic config found in eeprom, setting default configs\n");
-  haptic_reset();
-  }
-  #ifdef SOLENOID_ENABLE
+    debug_enable = 1;  // Debug is ON!
+    if (!eeconfig_is_enabled()) {
+        eeconfig_init();
+    }
+    haptic_config.raw = eeconfig_read_haptic();
+    if (haptic_config.mode < 1) {
+        haptic_config.mode = 1;
+    }
+    if (!haptic_config.mode) {
+        dprintf("No haptic config found in eeprom, setting default configs\n");
+        haptic_reset();
+    }
+#ifdef SOLENOID_ENABLE
     solenoid_setup();
     dprintf("Solenoid driver initialized\n");
-  #endif
-  #ifdef DRV2605L
+#endif
+#ifdef DRV2605L
     DRV_init();
     dprintf("DRV2605 driver initialized\n");
-  #endif
-  eeconfig_debug_haptic();
+#endif
+    eeconfig_debug_haptic();
 }
 
 void haptic_task(void) {
-  #ifdef SOLENOID_ENABLE
-  solenoid_check();
-  #endif
+#ifdef SOLENOID_ENABLE
+    solenoid_check();
+#endif
 }
 
 void eeconfig_debug_haptic(void) {
-  dprintf("haptic_config eprom\n");
-  dprintf("haptic_config.enable = %d\n", haptic_config.enable);
-  dprintf("haptic_config.mode = %d\n", haptic_config.mode);
+    dprintf("haptic_config eprom\n");
+    dprintf("haptic_config.enable = %d\n", haptic_config.enable);
+    dprintf("haptic_config.mode = %d\n", haptic_config.mode);
 }
 
 void haptic_enable(void) {
-  haptic_config.enable = 1;
-  xprintf("haptic_config.enable = %u\n", haptic_config.enable);
-  eeconfig_update_haptic(haptic_config.raw);
+    haptic_config.enable = 1;
+    xprintf("haptic_config.enable = %u\n", haptic_config.enable);
+    eeconfig_update_haptic(haptic_config.raw);
 }
 
 void haptic_disable(void) {
-  haptic_config.enable = 0;
-  xprintf("haptic_config.enable = %u\n", haptic_config.enable);
-  eeconfig_update_haptic(haptic_config.raw);
+    haptic_config.enable = 0;
+    xprintf("haptic_config.enable = %u\n", haptic_config.enable);
+    eeconfig_update_haptic(haptic_config.raw);
 }
 
 void haptic_toggle(void) {
-if (haptic_config.enable) {
-  haptic_disable();
-  } else {
-  haptic_enable();
-  }
-  eeconfig_update_haptic(haptic_config.raw);
+    if (haptic_config.enable) {
+        haptic_disable();
+    } else {
+        haptic_enable();
+    }
+    eeconfig_update_haptic(haptic_config.raw);
 }
 
-void haptic_feedback_toggle(void){
- haptic_config.feedback++;
-  if (haptic_config.feedback >= HAPTIC_FEEDBACK_MAX)
-  haptic_config.feedback = KEY_PRESS;
-  xprintf("haptic_config.feedback = %u\n", !haptic_config.feedback);
-  eeconfig_update_haptic(haptic_config.raw);
+void haptic_feedback_toggle(void) {
+    haptic_config.feedback++;
+    if (haptic_config.feedback >= HAPTIC_FEEDBACK_MAX) haptic_config.feedback = KEY_PRESS;
+    xprintf("haptic_config.feedback = %u\n", !haptic_config.feedback);
+    eeconfig_update_haptic(haptic_config.raw);
 }
 
 void haptic_buzz_toggle(void) {
-  bool buzz_stat = !haptic_config.buzz;
-  haptic_config.buzz = buzz_stat;
-  haptic_set_buzz(buzz_stat);
+    bool buzz_stat     = !haptic_config.buzz;
+    haptic_config.buzz = buzz_stat;
+    haptic_set_buzz(buzz_stat);
 }
 
 void haptic_mode_increase(void) {
-  uint8_t mode = haptic_config.mode + 1;
-  #ifdef DRV2605L
-  if (haptic_config.mode >= drv_effect_max) {
-    mode = 1;
-  }
-  #endif
+    uint8_t mode = haptic_config.mode + 1;
+#ifdef DRV2605L
+    if (haptic_config.mode >= drv_effect_max) {
+        mode = 1;
+    }
+#endif
     haptic_set_mode(mode);
 }
 
 void haptic_mode_decrease(void) {
-  uint8_t mode = haptic_config.mode -1;
-  #ifdef DRV2605L
-  if (haptic_config.mode < 1) {
-    mode = (drv_effect_max - 1);
-  }
-  #endif
-  haptic_set_mode(mode);
+    uint8_t mode = haptic_config.mode - 1;
+#ifdef DRV2605L
+    if (haptic_config.mode < 1) {
+        mode = (drv_effect_max - 1);
+    }
+#endif
+    haptic_set_mode(mode);
 }
 
 void haptic_dwell_increase(void) {
-  uint8_t dwell = haptic_config.dwell + 1;
-  #ifdef SOLENOID_ENABLE
-  if (haptic_config.dwell >= SOLENOID_MAX_DWELL) {
-    dwell = 1;
-  }
-  solenoid_set_dwell(dwell);
-  #endif
-  haptic_set_dwell(dwell);
+    uint8_t dwell = haptic_config.dwell + 1;
+#ifdef SOLENOID_ENABLE
+    if (haptic_config.dwell >= SOLENOID_MAX_DWELL) {
+        dwell = 1;
+    }
+    solenoid_set_dwell(dwell);
+#endif
+    haptic_set_dwell(dwell);
 }
 
 void haptic_dwell_decrease(void) {
-  uint8_t dwell = haptic_config.dwell -1;
-  #ifdef SOLENOID_ENABLE
-  if (haptic_config.dwell < SOLENOID_MIN_DWELL) {
-    dwell = SOLENOID_MAX_DWELL;
-  }
-  solenoid_set_dwell(dwell);
-  #endif
-  haptic_set_dwell(dwell);
-}
-
-void haptic_reset(void){
-  haptic_config.enable = true;
-  uint8_t feedback = HAPTIC_FEEDBACK_DEFAULT;
-  haptic_config.feedback = feedback;
-  #ifdef DRV2605L
-    uint8_t mode = HAPTIC_MODE_DEFAULT;
+    uint8_t dwell = haptic_config.dwell - 1;
+#ifdef SOLENOID_ENABLE
+    if (haptic_config.dwell < SOLENOID_MIN_DWELL) {
+        dwell = SOLENOID_MAX_DWELL;
+    }
+    solenoid_set_dwell(dwell);
+#endif
+    haptic_set_dwell(dwell);
+}
+
+void haptic_reset(void) {
+    haptic_config.enable   = true;
+    uint8_t feedback       = HAPTIC_FEEDBACK_DEFAULT;
+    haptic_config.feedback = feedback;
+#ifdef DRV2605L
+    uint8_t mode       = HAPTIC_MODE_DEFAULT;
     haptic_config.mode = mode;
-  #endif
-  #ifdef SOLENOID_ENABLE
-    uint8_t dwell = SOLENOID_DEFAULT_DWELL;
+#endif
+#ifdef SOLENOID_ENABLE
+    uint8_t dwell       = SOLENOID_DEFAULT_DWELL;
     haptic_config.dwell = dwell;
-  #endif
-  eeconfig_update_haptic(haptic_config.raw);
-  xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
-  xprintf("haptic_config.mode = %u\n", haptic_config.mode);
+#endif
+    eeconfig_update_haptic(haptic_config.raw);
+    xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
+    xprintf("haptic_config.mode = %u\n", haptic_config.mode);
 }
 
 void haptic_set_feedback(uint8_t feedback) {
-  haptic_config.feedback = feedback;
-  eeconfig_update_haptic(haptic_config.raw);
-  xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
+    haptic_config.feedback = feedback;
+    eeconfig_update_haptic(haptic_config.raw);
+    xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
 }
 
 void haptic_set_mode(uint8_t mode) {
-  haptic_config.mode = mode;
-  eeconfig_update_haptic(haptic_config.raw);
-  xprintf("haptic_config.mode = %u\n", haptic_config.mode);
+    haptic_config.mode = mode;
+    eeconfig_update_haptic(haptic_config.raw);
+    xprintf("haptic_config.mode = %u\n", haptic_config.mode);
 }
 
 void haptic_set_buzz(uint8_t buzz) {
-  haptic_config.buzz = buzz;
-  eeconfig_update_haptic(haptic_config.raw);
-  xprintf("haptic_config.buzz = %u\n", haptic_config.buzz);
+    haptic_config.buzz = buzz;
+    eeconfig_update_haptic(haptic_config.raw);
+    xprintf("haptic_config.buzz = %u\n", haptic_config.buzz);
 }
 
 void haptic_set_dwell(uint8_t dwell) {
-  haptic_config.dwell = dwell;
-  eeconfig_update_haptic(haptic_config.raw);
-  xprintf("haptic_config.dwell = %u\n", haptic_config.dwell);
+    haptic_config.dwell = dwell;
+    eeconfig_update_haptic(haptic_config.raw);
+    xprintf("haptic_config.dwell = %u\n", haptic_config.dwell);
 }
 
 uint8_t haptic_get_mode(void) {
-  if (!haptic_config.enable){
-    return false;
-  }
-  return haptic_config.mode;
+    if (!haptic_config.enable) {
+        return false;
+    }
+    return haptic_config.mode;
 }
 
 uint8_t haptic_get_feedback(void) {
-  if (!haptic_config.enable){
-    return false;
-  }
-  return haptic_config.feedback;
+    if (!haptic_config.enable) {
+        return false;
+    }
+    return haptic_config.feedback;
 }
 
 uint8_t haptic_get_dwell(void) {
-  if (!haptic_config.enable){
-    return false;
-  }
-  return haptic_config.dwell;
+    if (!haptic_config.enable) {
+        return false;
+    }
+    return haptic_config.dwell;
 }
 
 void haptic_play(void) {
-  #ifdef DRV2605L
-  uint8_t play_eff = 0;
-  play_eff = haptic_config.mode;
-  DRV_pulse(play_eff);
-  #endif
-  #ifdef SOLENOID_ENABLE
-  solenoid_fire();
-  #endif
+#ifdef DRV2605L
+    uint8_t play_eff = 0;
+    play_eff         = haptic_config.mode;
+    DRV_pulse(play_eff);
+#endif
+#ifdef SOLENOID_ENABLE
+    solenoid_fire();
+#endif
 }
 
 bool process_haptic(uint16_t keycode, keyrecord_t *record) {
-    if (keycode == HPT_ON && record->event.pressed) { haptic_enable(); }
-    if (keycode == HPT_OFF && record->event.pressed) { haptic_disable(); }
-    if (keycode == HPT_TOG && record->event.pressed) { haptic_toggle(); }
-    if (keycode == HPT_RST && record->event.pressed) { haptic_reset(); }
-    if (keycode == HPT_FBK && record->event.pressed) { haptic_feedback_toggle(); }
-    if (keycode == HPT_BUZ && record->event.pressed) { haptic_buzz_toggle(); }
-    if (keycode == HPT_MODI && record->event.pressed) { haptic_mode_increase(); }
-    if (keycode == HPT_MODD && record->event.pressed) { haptic_mode_decrease(); }
-    if (keycode == HPT_DWLI && record->event.pressed) { haptic_dwell_increase(); }
-    if (keycode == HPT_DWLD && record->event.pressed) { haptic_dwell_decrease(); }
-  if (haptic_config.enable) {
-    if ( record->event.pressed ) {
-       // keypress
-      if (haptic_config.feedback < 2) {
-      haptic_play();
-      }
-    } else {
-    //keyrelease
-      if (haptic_config.feedback > 0) {
-      haptic_play();
-      } 
+    if (keycode == HPT_ON && record->event.pressed) {
+        haptic_enable();
     }
-  }
-  return true;
+    if (keycode == HPT_OFF && record->event.pressed) {
+        haptic_disable();
+    }
+    if (keycode == HPT_TOG && record->event.pressed) {
+        haptic_toggle();
+    }
+    if (keycode == HPT_RST && record->event.pressed) {
+        haptic_reset();
+    }
+    if (keycode == HPT_FBK && record->event.pressed) {
+        haptic_feedback_toggle();
+    }
+    if (keycode == HPT_BUZ && record->event.pressed) {
+        haptic_buzz_toggle();
+    }
+    if (keycode == HPT_MODI && record->event.pressed) {
+        haptic_mode_increase();
+    }
+    if (keycode == HPT_MODD && record->event.pressed) {
+        haptic_mode_decrease();
+    }
+    if (keycode == HPT_DWLI && record->event.pressed) {
+        haptic_dwell_increase();
+    }
+    if (keycode == HPT_DWLD && record->event.pressed) {
+        haptic_dwell_decrease();
+    }
+    if (haptic_config.enable) {
+        if (record->event.pressed) {
+            // keypress
+            if (haptic_config.feedback < 2) {
+                haptic_play();
+            }
+        } else {
+            // keyrelease
+            if (haptic_config.feedback > 0) {
+                haptic_play();
+            }
+        }
+    }
+    return true;
 }
 
 void haptic_shutdown(void) {
-  #ifdef SOLENOID_ENABLE
-  solenoid_shutdown();
-  #endif
-
+#ifdef SOLENOID_ENABLE
+    solenoid_shutdown();
+#endif
 }
index d39dc5c3b9d6442bb0e8987dd7869f07d0291ffb..8135d0d43985fddbda7fd89a10f66f09f9fb6837 100644 (file)
 #include <stdbool.h>
 #include "quantum.h"
 #ifdef DRV2605L
-#include "DRV2605L.h"
+#    include "DRV2605L.h"
 #endif
 
-
 #ifndef HAPTIC_FEEDBACK_DEFAULT
-#define HAPTIC_FEEDBACK_DEFAULT 0
+#    define HAPTIC_FEEDBACK_DEFAULT 0
 #endif
 #ifndef HAPTIC_MODE_DEFAULT
-#define HAPTIC_MODE_DEFAULT DRV_MODE_DEFAULT
+#    define HAPTIC_MODE_DEFAULT DRV_MODE_DEFAULT
 #endif
 
 /* EEPROM config settings */
 typedef union {
-  uint32_t raw;
-  struct {
-    bool     enable    :1;
-    uint8_t  feedback  :2;
-    uint8_t  mode      :7;
-    bool     buzz      :1;
-    uint8_t  dwell     :7;
-    uint16_t reserved  :16; 
-  };
+    uint32_t raw;
+    struct {
+        bool     enable : 1;
+        uint8_t  feedback : 2;
+        uint8_t  mode : 7;
+        bool     buzz : 1;
+        uint8_t  dwell : 7;
+        uint16_t reserved : 16;
+    };
 } haptic_config_t;
 
-typedef enum HAPTIC_FEEDBACK{
-  KEY_PRESS,
-  KEY_PRESS_RELEASE,
-  KEY_RELEASE,
-  HAPTIC_FEEDBACK_MAX,
+typedef enum HAPTIC_FEEDBACK {
+    KEY_PRESS,
+    KEY_PRESS_RELEASE,
+    KEY_RELEASE,
+    HAPTIC_FEEDBACK_MAX,
 } HAPTIC_FEEDBACK;
 
-bool process_haptic(uint16_t keycode, keyrecord_t *record);
-void haptic_init(void);
-void haptic_task(void);
-void eeconfig_debug_haptic(void);
-void haptic_enable(void);
-void haptic_disable(void);
-void haptic_toggle(void);
-void haptic_feedback_toggle(void);
-void haptic_mode_increase(void);
-void haptic_mode_decrease(void);
-void haptic_mode(uint8_t mode);
-void haptic_reset(void);
-void haptic_set_feedback(uint8_t feedback);
-void haptic_set_mode(uint8_t mode);
-void haptic_set_dwell(uint8_t dwell);
-void haptic_set_buzz(uint8_t buzz);
-void haptic_buzz_toggle(void);
+bool    process_haptic(uint16_t keycode, keyrecord_t *record);
+void    haptic_init(void);
+void    haptic_task(void);
+void    eeconfig_debug_haptic(void);
+void    haptic_enable(void);
+void    haptic_disable(void);
+void    haptic_toggle(void);
+void    haptic_feedback_toggle(void);
+void    haptic_mode_increase(void);
+void    haptic_mode_decrease(void);
+void    haptic_mode(uint8_t mode);
+void    haptic_reset(void);
+void    haptic_set_feedback(uint8_t feedback);
+void    haptic_set_mode(uint8_t mode);
+void    haptic_set_dwell(uint8_t dwell);
+void    haptic_set_buzz(uint8_t buzz);
+void    haptic_buzz_toggle(void);
 uint8_t haptic_get_mode(void);
 uint8_t haptic_get_feedback(void);
-void haptic_dwell_increase(void);
-void haptic_dwell_decrease(void);
+void    haptic_dwell_increase(void);
+void    haptic_dwell_decrease(void);
 
 void haptic_play(void);
 void haptic_shutdown(void);
-
-
-
-
-
index 2d39dbc1794c97945dd6054d9dc7049720856037..d645c379ae9704dbc22c5d60d7c14d74c80e9bca 100644 (file)
 #include "solenoid.h"
 #include "haptic.h"
 
-bool solenoid_on = false;
-bool solenoid_buzzing = false;
-uint16_t solenoid_start = 0;
-uint8_t solenoid_dwell = SOLENOID_DEFAULT_DWELL;
+bool     solenoid_on      = false;
+bool     solenoid_buzzing = false;
+uint16_t solenoid_start   = 0;
+uint8_t  solenoid_dwell   = SOLENOID_DEFAULT_DWELL;
 
 extern haptic_config_t haptic_config;
 
+void solenoid_buzz_on(void) { haptic_set_buzz(1); }
 
-void solenoid_buzz_on(void) {
-  haptic_set_buzz(1);
-}
-
-void solenoid_buzz_off(void) {
-  haptic_set_buzz(0);
-}
-
-void solenoid_set_buzz(int buzz) {
-  haptic_set_buzz(buzz);
-}
+void solenoid_buzz_off(void) { haptic_set_buzz(0); }
 
+void solenoid_set_buzz(int buzz) { haptic_set_buzz(buzz); }
 
 void solenoid_dwell_minus(uint8_t solenoid_dwell) {
-  if (solenoid_dwell > 0) solenoid_dwell--;
+    if (solenoid_dwell > 0) solenoid_dwell--;
 }
 
 void solenoid_dwell_plus(uint8_t solenoid_dwell) {
-  if (solenoid_dwell < SOLENOID_MAX_DWELL) solenoid_dwell++;
+    if (solenoid_dwell < SOLENOID_MAX_DWELL) solenoid_dwell++;
 }
 
-void solenoid_set_dwell(uint8_t dwell) {
-  solenoid_dwell = dwell;
-}
+void solenoid_set_dwell(uint8_t dwell) { solenoid_dwell = dwell; }
 
 void solenoid_stop(void) {
-  writePinLow(SOLENOID_PIN);
-  solenoid_on = false;
-  solenoid_buzzing = false;
+    writePinLow(SOLENOID_PIN);
+    solenoid_on      = false;
+    solenoid_buzzing = false;
 }
 
 void solenoid_fire(void) {
-  if (!haptic_config.buzz && solenoid_on) return;
-  if (haptic_config.buzz && solenoid_buzzing) return;
+    if (!haptic_config.buzz && solenoid_on) return;
+    if (haptic_config.buzz && solenoid_buzzing) return;
 
-  solenoid_on = true;
-  solenoid_buzzing = true;
-  solenoid_start = timer_read();
-  writePinHigh(SOLENOID_PIN);
+    solenoid_on      = true;
+    solenoid_buzzing = true;
+    solenoid_start   = timer_read();
+    writePinHigh(SOLENOID_PIN);
 }
 
 void solenoid_check(void) {
-  uint16_t elapsed = 0;
-
-  if (!solenoid_on) return;
+    uint16_t elapsed = 0;
 
-  elapsed = timer_elapsed(solenoid_start);
+    if (!solenoid_on) return;
 
-  //Check if it's time to finish this solenoid click cycle
-  if (elapsed > solenoid_dwell) {
-    solenoid_stop();
-    return;
-  }
+    elapsed = timer_elapsed(solenoid_start);
 
-  //Check whether to buzz the solenoid on and off
-  if (haptic_config.buzz) {
-    if (elapsed / SOLENOID_MIN_DWELL % 2 == 0){
-      if (!solenoid_buzzing) {
-        solenoid_buzzing = true;
-        writePinHigh(SOLENOID_PIN);
-      }
+    // Check if it's time to finish this solenoid click cycle
+    if (elapsed > solenoid_dwell) {
+        solenoid_stop();
+        return;
     }
-    else {
-      if (solenoid_buzzing) {
-        solenoid_buzzing = false;
-        writePinLow(SOLENOID_PIN);
-      }
+
+    // Check whether to buzz the solenoid on and off
+    if (haptic_config.buzz) {
+        if (elapsed / SOLENOID_MIN_DWELL % 2 == 0) {
+            if (!solenoid_buzzing) {
+                solenoid_buzzing = true;
+                writePinHigh(SOLENOID_PIN);
+            }
+        } else {
+            if (solenoid_buzzing) {
+                solenoid_buzzing = false;
+                writePinLow(SOLENOID_PIN);
+            }
+        }
     }
-  }
 }
 
 void solenoid_setup(void) {
-  setPinOutput(SOLENOID_PIN);
-  solenoid_fire();
+    setPinOutput(SOLENOID_PIN);
+    solenoid_fire();
 }
 
-void solenoid_shutdown(void) {
-  writePinLow(SOLENOID_PIN);
-
-}
+void solenoid_shutdown(void) { writePinLow(SOLENOID_PIN); }
index a08f62a11ee06efe861fe73c3583a50c0a358081..53dc626e33f89545ee11a1c9b493d36f7d1db0b3 100644 (file)
 #pragma once
 
 #ifndef SOLENOID_DEFAULT_DWELL
-#define SOLENOID_DEFAULT_DWELL 12
+#    define SOLENOID_DEFAULT_DWELL 12
 #endif
 
 #ifndef SOLENOID_MAX_DWELL
-#define SOLENOID_MAX_DWELL 100
+#    define SOLENOID_MAX_DWELL 100
 #endif
 
 #ifndef SOLENOID_MIN_DWELL
-#define SOLENOID_MIN_DWELL 4
+#    define SOLENOID_MIN_DWELL 4
 #endif
 
 #ifndef SOLENOID_ACTIVE
-#define SOLENOID_ACTIVE false
+#    define SOLENOID_ACTIVE false
 #endif
 
 #ifndef SOLENOID_PIN
-#define SOLENOID_PIN F6
+#    define SOLENOID_PIN F6
 #endif
 
 void solenoid_buzz_on(void);
index db44f725644ff411de180a37d68dbd32a8ffaa75..d43863ac4beeec055e15ce7a1a331cf1b54b3a67 100644 (file)
@@ -35,68 +35,62 @@ uint8_t g_twi_transfer_buffer[20];
 // IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
 // If used as RGB LED driver, LEDs are assigned RGB,RGB,RGB,RGB,RGB,RGB
 uint8_t g_pwm_buffer[18];
-bool g_pwm_buffer_update_required = false;
+bool    g_pwm_buffer_update_required = false;
 
-void IS31FL3218_write_register( uint8_t reg, uint8_t data )
-{
-       g_twi_transfer_buffer[0] = reg;
-       g_twi_transfer_buffer[1] = data;
-       i2c_transmit( ISSI_ADDRESS, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
+void IS31FL3218_write_register(uint8_t reg, uint8_t data) {
+    g_twi_transfer_buffer[0] = reg;
+    g_twi_transfer_buffer[1] = data;
+    i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
 }
 
-void IS31FL3218_write_pwm_buffer( uint8_t *pwm_buffer )
-{
-       g_twi_transfer_buffer[0] = ISSI_REG_PWM;
-       for ( int i=0; i<18; i++ ) {
-               g_twi_transfer_buffer[1+i] = pwm_buffer[i];
-       }
-       
-       i2c_transmit( ISSI_ADDRESS, g_twi_transfer_buffer, 19, ISSI_TIMEOUT);
+void IS31FL3218_write_pwm_buffer(uint8_t *pwm_buffer) {
+    g_twi_transfer_buffer[0] = ISSI_REG_PWM;
+    for (int i = 0; i < 18; i++) {
+        g_twi_transfer_buffer[1 + i] = pwm_buffer[i];
+    }
+
+    i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 19, ISSI_TIMEOUT);
 }
 
-void IS31FL3218_init(void)
-{
-       // In case we ever want to reinitialize (?)
-       IS31FL3218_write_register( ISSI_REG_RESET, 0x00 );
-       
-       // Turn off software shutdown
-       IS31FL3218_write_register( ISSI_REG_SHUTDOWN, 0x01 );
-
-       // Set all PWM values to zero
-       for ( uint8_t i = 0; i < 18; i++ ) {
-               IS31FL3218_write_register( ISSI_REG_PWM+i, 0x00 );
-       }
-       
-       // Enable all channels
-       for ( uint8_t i = 0; i < 3; i++ ) {
-               IS31FL3218_write_register( ISSI_REG_CONTROL+i, 0b00111111 );
-       }
-       
-       // Load PWM registers and LED Control register data
-       IS31FL3218_write_register( ISSI_REG_UPDATE, 0x01 );
+void IS31FL3218_init(void) {
+    // In case we ever want to reinitialize (?)
+    IS31FL3218_write_register(ISSI_REG_RESET, 0x00);
+
+    // Turn off software shutdown
+    IS31FL3218_write_register(ISSI_REG_SHUTDOWN, 0x01);
+
+    // Set all PWM values to zero
+    for (uint8_t i = 0; i < 18; i++) {
+        IS31FL3218_write_register(ISSI_REG_PWM + i, 0x00);
+    }
+
+    // Enable all channels
+    for (uint8_t i = 0; i < 3; i++) {
+        IS31FL3218_write_register(ISSI_REG_CONTROL + i, 0b00111111);
+    }
+
+    // Load PWM registers and LED Control register data
+    IS31FL3218_write_register(ISSI_REG_UPDATE, 0x01);
 }
 
-void IS31FL3218_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
-{
-       g_pwm_buffer[index * 3 + 0] = red;
-       g_pwm_buffer[index * 3 + 1] = green;
-       g_pwm_buffer[index * 3 + 2] = blue;
-       g_pwm_buffer_update_required = true;
+void IS31FL3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+    g_pwm_buffer[index * 3 + 0]  = red;
+    g_pwm_buffer[index * 3 + 1]  = green;
+    g_pwm_buffer[index * 3 + 2]  = blue;
+    g_pwm_buffer_update_required = true;
 }
 
-void IS31FL3218_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
-{
-       for ( int i = 0; i < 6; i++ ) {
-               IS31FL3218_set_color( i, red, green, blue );
-       }
+void IS31FL3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+    for (int i = 0; i < 6; i++) {
+        IS31FL3218_set_color(i, red, green, blue);
+    }
 }
 
-void IS31FL3218_update_pwm_buffers(void)
-{
-       if ( g_pwm_buffer_update_required ) {
-               IS31FL3218_write_pwm_buffer( g_pwm_buffer );
-               // Load PWM registers and LED Control register data
-               IS31FL3218_write_register( ISSI_REG_UPDATE, 0x01 );
-       }
-       g_pwm_buffer_update_required = false;
+void IS31FL3218_update_pwm_buffers(void) {
+    if (g_pwm_buffer_update_required) {
+        IS31FL3218_write_pwm_buffer(g_pwm_buffer);
+        // Load PWM registers and LED Control register data
+        IS31FL3218_write_register(ISSI_REG_UPDATE, 0x01);
+    }
+    g_pwm_buffer_update_required = false;
 }
index 2d24e514638eb6e33878ba6cdeecd24725938951..a70cc1e79380e12d03a82a8a442641d18eef47c9 100644 (file)
@@ -19,6 +19,6 @@
 #include <stdbool.h>
 
 void IS31FL3218_init(void);
-void IS31FL3218_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
-void IS31FL3218_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
+void IS31FL3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
 void IS31FL3218_update_pwm_buffers(void);
index a7faa9c38c0bf73e395afc3a8cb01efe0a455d25..fad4676defd4aa42ccd72a1bb10e64968304685a 100644 (file)
  */
 
 #ifdef __AVR__
-#include <avr/interrupt.h>
-#include <avr/io.h>
-#include <util/delay.h>
+#    include <avr/interrupt.h>
+#    include <avr/io.h>
+#    include <util/delay.h>
 #else
-#include "wait.h"
+#    include "wait.h"
 #endif
 
 #include <stdint.h>
@@ -41,7 +41,7 @@
 // 0b1110110 AD <-> SDA
 #define ISSI_ADDR_DEFAULT 0x74
 
-#define ISSI_REG_CONFIG  0x00
+#define ISSI_REG_CONFIG 0x00
 #define ISSI_REG_CONFIG_PICTUREMODE 0x00
 #define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08
 #define ISSI_REG_CONFIG_AUDIOPLAYMODE 0x18
 #define ISSI_CONF_AUTOFRAMEMODE 0x04
 #define ISSI_CONF_AUDIOMODE 0x08
 
-#define ISSI_REG_PICTUREFRAME  0x01
+#define ISSI_REG_PICTUREFRAME 0x01
 
 #define ISSI_REG_SHUTDOWN 0x0A
 #define ISSI_REG_AUDIOSYNC 0x06
 
 #define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_BANK_FUNCTIONREG 0x0B    // helpfully called 'page nine'
+#define ISSI_BANK_FUNCTIONREG 0x0B  // helpfully called 'page nine'
 
 #ifndef ISSI_TIMEOUT
-  #define ISSI_TIMEOUT 100
+#    define ISSI_TIMEOUT 100
 #endif
 
 #ifndef ISSI_PERSISTENCE
-  #define ISSI_PERSISTENCE 0
+#    define ISSI_PERSISTENCE 0
 #endif
 
 // Transfer buffer for TWITransmitData()
@@ -75,17 +75,17 @@ uint8_t g_twi_transfer_buffer[20];
 // buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's
 // probably not worth the extra complexity.
 uint8_t g_pwm_buffer[LED_DRIVER_COUNT][144];
-bool g_pwm_buffer_update_required = false;
+bool    g_pwm_buffer_update_required = false;
 
 /* There's probably a better way to init this... */
 #if LED_DRIVER_COUNT == 1
-    uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}};
+uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}};
 #elif LED_DRIVER_COUNT == 2
-    uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}};
+uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}};
 #elif LED_DRIVER_COUNT == 3
-    uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}};
+uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}};
 #elif LED_DRIVER_COUNT == 4
-    uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}, {0}};
+uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}, {0}};
 #endif
 bool g_led_control_registers_update_required = false;
 
@@ -103,20 +103,19 @@ bool g_led_control_registers_update_required = false;
 // 0x0E - R17,G15,G14,G13,G12,G11,G10,G09
 // 0x10 - R16,R15,R14,R13,R12,R11,R10,R09
 
-
 void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
     g_twi_transfer_buffer[0] = reg;
     g_twi_transfer_buffer[1] = data;
 
-    #if ISSI_PERSISTENCE > 0
-        for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
-            if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) {
-              break;
-            }
+#if ISSI_PERSISTENCE > 0
+    for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+        if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) {
+            break;
         }
-    #else
-        i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-    #endif
+    }
+#else
+    i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
+#endif
 }
 
 void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
@@ -136,14 +135,13 @@ void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
             g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
         }
 
-    #if ISSI_PERSISTENCE > 0
-      for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
-        if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0)
-          break;
-      }
-    #else
-      i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
-    #endif
+#if ISSI_PERSISTENCE > 0
+        for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+            if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
+        }
+#else
+        i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
+#endif
     }
 }
 
@@ -196,7 +194,6 @@ void IS31FL3731_init(uint8_t addr) {
     // most usage after initialization is just writing PWM buffers in bank 0
     // as there's not much point in double-buffering
     IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
-
 }
 
 void IS31FL3731_set_value(int index, uint8_t value) {
@@ -205,7 +202,7 @@ void IS31FL3731_set_value(int index, uint8_t value) {
 
         // Subtract 0x24 to get the second index of g_pwm_buffer
         g_pwm_buffer[led.driver][led.v - 0x24] = value;
-        g_pwm_buffer_update_required = true;
+        g_pwm_buffer_update_required           = true;
     }
 }
 
@@ -216,10 +213,10 @@ void IS31FL3731_set_value_all(uint8_t value) {
 }
 
 void IS31FL3731_set_led_control_register(uint8_t index, bool value) {
-  is31_led led = g_is31_leds[index];
+    is31_led led = g_is31_leds[index];
 
-  uint8_t control_register = (led.v - 0x24) / 8;
-  uint8_t bit_value = (led.v - 0x24) % 8;
+    uint8_t control_register = (led.v - 0x24) / 8;
+    uint8_t bit_value        = (led.v - 0x24) % 8;
 
     if (value) {
         g_led_control_registers[led.driver][control_register] |= (1 << bit_value);
@@ -239,7 +236,7 @@ void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
 
 void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index) {
     if (g_led_control_registers_update_required) {
-        for (int i=0; i<18; i++) {
+        for (int i = 0; i < 18; i++) {
             IS31FL3731_write_register(addr, i, g_led_control_registers[index][i]);
         }
     }
index dbe49828179183f3d1ceac78cfb95df6cb14ae88..a223c351e885beb1aee464648f864d8fe129b93a 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #ifndef IS31FL3731_DRIVER_H
 #define IS31FL3731_DRIVER_H
 
-
 typedef struct is31_led {
-  uint8_t driver:2;
-  uint8_t v;
+    uint8_t driver : 2;
+    uint8_t v;
 } __attribute__((packed)) is31_led;
 
 extern const is31_led g_is31_leds[LED_DRIVER_LED_COUNT];
@@ -44,16 +42,16 @@ void IS31FL3731_set_led_control_register(uint8_t index, bool value);
 void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index);
 void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
 
-#define C1_1  0x24
-#define C1_2  0x25
-#define C1_3  0x26
-#define C1_4  0x27
-#define C1_5  0x28
-#define C1_6  0x29
-#define C1_7  0x2A
-#define C1_8  0x2B
+#define C1_1 0x24
+#define C1_2 0x25
+#define C1_3 0x26
+#define C1_4 0x27
+#define C1_5 0x28
+#define C1_6 0x29
+#define C1_7 0x2A
+#define C1_8 0x2B
 
-#define C1_9  0x2C
+#define C1_9 0x2C
 #define C1_10 0x2D
 #define C1_11 0x2E
 #define C1_12 0x2F
@@ -62,16 +60,16 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
 #define C1_15 0x32
 #define C1_16 0x33
 
-#define C2_1  0x34
-#define C2_2  0x35
-#define C2_3  0x36
-#define C2_4  0x37
-#define C2_5  0x38
-#define C2_6  0x39
-#define C2_7  0x3A
-#define C2_8  0x3B
+#define C2_1 0x34
+#define C2_2 0x35
+#define C2_3 0x36
+#define C2_4 0x37
+#define C2_5 0x38
+#define C2_6 0x39
+#define C2_7 0x3A
+#define C2_8 0x3B
 
-#define C2_9  0x3C
+#define C2_9 0x3C
 #define C2_10 0x3D
 #define C2_11 0x3E
 #define C2_12 0x3F
@@ -80,16 +78,16 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
 #define C2_15 0x42
 #define C2_16 0x43
 
-#define C3_1  0x44
-#define C3_2  0x45
-#define C3_3  0x46
-#define C3_4  0x47
-#define C3_5  0x48
-#define C3_6  0x49
-#define C3_7  0x4A
-#define C3_8  0x4B
+#define C3_1 0x44
+#define C3_2 0x45
+#define C3_3 0x46
+#define C3_4 0x47
+#define C3_5 0x48
+#define C3_6 0x49
+#define C3_7 0x4A
+#define C3_8 0x4B
 
-#define C3_9  0x4C
+#define C3_9 0x4C
 #define C3_10 0x4D
 #define C3_11 0x4E
 #define C3_12 0x4F
@@ -98,16 +96,16 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
 #define C3_15 0x52
 #define C3_16 0x53
 
-#define C4_1  0x54
-#define C4_2  0x55
-#define C4_3  0x56
-#define C4_4  0x57
-#define C4_5  0x58
-#define C4_6  0x59
-#define C4_7  0x5A
-#define C4_8  0x5B
+#define C4_1 0x54
+#define C4_2 0x55
+#define C4_3 0x56
+#define C4_4 0x57
+#define C4_5 0x58
+#define C4_6 0x59
+#define C4_7 0x5A
+#define C4_8 0x5B
 
-#define C4_9  0x5C
+#define C4_9 0x5C
 #define C4_10 0x5D
 #define C4_11 0x5E
 #define C4_12 0x5F
@@ -116,16 +114,16 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
 #define C4_15 0x62
 #define C4_16 0x63
 
-#define C5_1  0x64
-#define C5_2  0x65
-#define C5_3  0x66
-#define C5_4  0x67
-#define C5_5  0x68
-#define C5_6  0x69
-#define C5_7  0x6A
-#define C5_8  0x6B
+#define C5_1 0x64
+#define C5_2 0x65
+#define C5_3 0x66
+#define C5_4 0x67
+#define C5_5 0x68
+#define C5_6 0x69
+#define C5_7 0x6A
+#define C5_8 0x6B
 
-#define C5_9  0x6C
+#define C5_9 0x6C
 #define C5_10 0x6D
 #define C5_11 0x6E
 #define C5_12 0x6F
@@ -134,16 +132,16 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
 #define C5_15 0x72
 #define C5_16 0x73
 
-#define C6_1  0x74
-#define C6_2  0x75
-#define C6_3  0x76
-#define C6_4  0x77
-#define C6_5  0x78
-#define C6_6  0x79
-#define C6_7  0x7A
-#define C6_8  0x7B
+#define C6_1 0x74
+#define C6_2 0x75
+#define C6_3 0x76
+#define C6_4 0x77
+#define C6_5 0x78
+#define C6_6 0x79
+#define C6_7 0x7A
+#define C6_8 0x7B
 
-#define C6_9  0x7C
+#define C6_9 0x7C
 #define C6_10 0x7D
 #define C6_11 0x7E
 #define C6_12 0x7F
@@ -152,16 +150,16 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
 #define C6_15 0x82
 #define C6_16 0x83
 
-#define C7_1  0x84
-#define C7_2  0x85
-#define C7_3  0x86
-#define C7_4  0x87
-#define C7_5  0x88
-#define C7_6  0x89
-#define C7_7  0x8A
-#define C7_8  0x8B
+#define C7_1 0x84
+#define C7_2 0x85
+#define C7_3 0x86
+#define C7_4 0x87
+#define C7_5 0x88
+#define C7_6 0x89
+#define C7_7 0x8A
+#define C7_8 0x8B
 
-#define C7_9  0x8C
+#define C7_9 0x8C
 #define C7_10 0x8D
 #define C7_11 0x8E
 #define C7_12 0x8F
@@ -170,16 +168,16 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
 #define C7_15 0x92
 #define C7_16 0x93
 
-#define C8_1  0x94
-#define C8_2  0x95
-#define C8_3  0x96
-#define C8_4  0x97
-#define C8_5  0x98
-#define C8_6  0x99
-#define C8_7  0x9A
-#define C8_8  0x9B
+#define C8_1 0x94
+#define C8_2 0x95
+#define C8_3 0x96
+#define C8_4 0x97
+#define C8_5 0x98
+#define C8_6 0x99
+#define C8_7 0x9A
+#define C8_8 0x9B
 
-#define C8_9  0x9C
+#define C8_9 0x9C
 #define C8_10 0x9D
 #define C8_11 0x9E
 #define C8_12 0x9F
@@ -188,16 +186,16 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
 #define C8_15 0xA2
 #define C8_16 0xA3
 
-#define C9_1  0xA4
-#define C9_2  0xA5
-#define C9_3  0xA6
-#define C9_4  0xA7
-#define C9_5  0xA8
-#define C9_6  0xA9
-#define C9_7  0xAA
-#define C9_8  0xAB
+#define C9_1 0xA4
+#define C9_2 0xA5
+#define C9_3 0xA6
+#define C9_4 0xA7
+#define C9_5 0xA8
+#define C9_6 0xA9
+#define C9_7 0xAA
+#define C9_8 0xAB
 
-#define C9_9  0xAC
+#define C9_9 0xAC
 #define C9_10 0xAD
 #define C9_11 0xAE
 #define C9_12 0xAF
@@ -206,5 +204,4 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
 #define C9_15 0xB2
 #define C9_16 0xB3
 
-
-#endif // IS31FL3731_DRIVER_H
+#endif  // IS31FL3731_DRIVER_H
index 30c7dd0530c0b8bea98eee86d1cf94560ea020ee..0b6f3e985de1530dd5880c9ac61851065f167f30 100644 (file)
  */
 
 #ifdef __AVR__
-#include <avr/interrupt.h>
-#include <avr/io.h>
-#include <util/delay.h>
+#    include <avr/interrupt.h>
+#    include <avr/io.h>
+#    include <util/delay.h>
 #else
-#include "wait.h"
+#    include "wait.h"
 #endif
 
 #include "is31fl3731.h"
@@ -37,7 +37,7 @@
 // 0b1110110 AD <-> SDA
 #define ISSI_ADDR_DEFAULT 0x74
 
-#define ISSI_REG_CONFIG  0x00
+#define ISSI_REG_CONFIG 0x00
 #define ISSI_REG_CONFIG_PICTUREMODE 0x00
 #define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08
 #define ISSI_REG_CONFIG_AUDIOPLAYMODE 0x18
 #define ISSI_CONF_AUTOFRAMEMODE 0x04
 #define ISSI_CONF_AUDIOMODE 0x08
 
-#define ISSI_REG_PICTUREFRAME  0x01
+#define ISSI_REG_PICTUREFRAME 0x01
 
 #define ISSI_REG_SHUTDOWN 0x0A
 #define ISSI_REG_AUDIOSYNC 0x06
 
 #define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_BANK_FUNCTIONREG 0x0B    // helpfully called 'page nine'
+#define ISSI_BANK_FUNCTIONREG 0x0B  // helpfully called 'page nine'
 
 #ifndef ISSI_TIMEOUT
-  #define ISSI_TIMEOUT 100
+#    define ISSI_TIMEOUT 100
 #endif
 
 #ifndef ISSI_PERSISTENCE
-  #define ISSI_PERSISTENCE 0
+#    define ISSI_PERSISTENCE 0
 #endif
 
 // Transfer buffer for TWITransmitData()
@@ -71,10 +71,10 @@ uint8_t g_twi_transfer_buffer[20];
 // buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's
 // probably not worth the extra complexity.
 uint8_t g_pwm_buffer[DRIVER_COUNT][144];
-bool g_pwm_buffer_update_required[DRIVER_COUNT] = { false };
+bool    g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
 
-uint8_t g_led_control_registers[DRIVER_COUNT][18] = { { 0 }, { 0 } };
-bool g_led_control_registers_update_required[DRIVER_COUNT] = { false };
+uint8_t g_led_control_registers[DRIVER_COUNT][18]             = {{0}, {0}};
+bool    g_led_control_registers_update_required[DRIVER_COUNT] = {false};
 
 // This is the bit pattern in the LED control registers
 // (for matrix A, add one to register for matrix B)
@@ -90,179 +90,159 @@ bool g_led_control_registers_update_required[DRIVER_COUNT] = { false };
 // 0x0E - R17,G15,G14,G13,G12,G11,G10,G09
 // 0x10 - R16,R15,R14,R13,R12,R11,R10,R09
 
-
-void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data )
-{
+void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
     g_twi_transfer_buffer[0] = reg;
     g_twi_transfer_buffer[1] = data;
 
-  #if ISSI_PERSISTENCE > 0
+#if ISSI_PERSISTENCE > 0
     for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
-      if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0)
-        break;
+        if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
     }
-  #else
+#else
     i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-  #endif
+#endif
 }
 
-void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer )
-{
+void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
     // assumes bank is already selected
 
     // transmit PWM registers in 9 transfers of 16 bytes
     // g_twi_transfer_buffer[] is 20 bytes
 
     // iterate over the pwm_buffer contents at 16 byte intervals
-    for ( int i = 0; i < 144; i += 16 ) {
+    for (int i = 0; i < 144; i += 16) {
         // set the first register, e.g. 0x24, 0x34, 0x44, etc.
         g_twi_transfer_buffer[0] = 0x24 + i;
         // copy the data from i to i+15
         // device will auto-increment register for data after the first byte
         // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer
-        for ( int j = 0; j < 16; j++ ) {
+        for (int j = 0; j < 16; j++) {
             g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
         }
 
-    #if ISSI_PERSISTENCE > 0
-      for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
-        if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0)
-          break;
-      }
-    #else
-      i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
-    #endif
+#if ISSI_PERSISTENCE > 0
+        for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+            if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
+        }
+#else
+        i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
+#endif
     }
 }
 
-void IS31FL3731_init( uint8_t addr )
-{
+void IS31FL3731_init(uint8_t addr) {
     // In order to avoid the LEDs being driven with garbage data
     // in the LED driver's PWM registers, first enable software shutdown,
     // then set up the mode and other settings, clear the PWM registers,
     // then disable software shutdown.
 
     // select "function register" bank
-    IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG );
+    IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG);
 
     // enable software shutdown
-    IS31FL3731_write_register( addr, ISSI_REG_SHUTDOWN, 0x00 );
-    // this delay was copied from other drivers, might not be needed
-    #ifdef __AVR__
-    _delay_ms( 10 );
-    #else
+    IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00);
+// this delay was copied from other drivers, might not be needed
+#ifdef __AVR__
+    _delay_ms(10);
+#else
     wait_ms(10);
-    #endif
+#endif
 
     // picture mode
-    IS31FL3731_write_register( addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE );
+    IS31FL3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE);
     // display frame 0
-    IS31FL3731_write_register( addr, ISSI_REG_PICTUREFRAME, 0x00 );
+    IS31FL3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00);
     // audio sync off
-    IS31FL3731_write_register( addr, ISSI_REG_AUDIOSYNC, 0x00 );
+    IS31FL3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00);
 
     // select bank 0
-    IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, 0 );
+    IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
 
     // turn off all LEDs in the LED control register
-    for ( int i = 0x00; i <= 0x11; i++ )
-    {
-        IS31FL3731_write_register( addr, i, 0x00 );
+    for (int i = 0x00; i <= 0x11; i++) {
+        IS31FL3731_write_register(addr, i, 0x00);
     }
 
     // turn off all LEDs in the blink control register (not really needed)
-    for ( int i = 0x12; i <= 0x23; i++ )
-    {
-        IS31FL3731_write_register( addr, i, 0x00 );
+    for (int i = 0x12; i <= 0x23; i++) {
+        IS31FL3731_write_register(addr, i, 0x00);
     }
 
     // set PWM on all LEDs to 0
-    for ( int i = 0x24; i <= 0xB3; i++ )
-    {
-        IS31FL3731_write_register( addr, i, 0x00 );
+    for (int i = 0x24; i <= 0xB3; i++) {
+        IS31FL3731_write_register(addr, i, 0x00);
     }
 
     // select "function register" bank
-    IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG );
+    IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG);
 
     // disable software shutdown
-    IS31FL3731_write_register( addr, ISSI_REG_SHUTDOWN, 0x01 );
+    IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01);
 
     // select bank 0 and leave it selected.
     // most usage after initialization is just writing PWM buffers in bank 0
     // as there's not much point in double-buffering
-    IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, 0 );
-
+    IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
 }
 
-void IS31FL3731_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
-{
-    if ( index >= 0 && index < DRIVER_LED_TOTAL ) {
+void IS31FL3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+    if (index >= 0 && index < DRIVER_LED_TOTAL) {
         is31_led led = g_is31_leds[index];
 
         // Subtract 0x24 to get the second index of g_pwm_buffer
-        g_pwm_buffer[led.driver][led.r - 0x24] = red;
-        g_pwm_buffer[led.driver][led.g - 0x24] = green;
-        g_pwm_buffer[led.driver][led.b - 0x24] = blue;
+        g_pwm_buffer[led.driver][led.r - 0x24]   = red;
+        g_pwm_buffer[led.driver][led.g - 0x24]   = green;
+        g_pwm_buffer[led.driver][led.b - 0x24]   = blue;
         g_pwm_buffer_update_required[led.driver] = true;
     }
 }
 
-void IS31FL3731_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
-{
-    for ( int i = 0; i < DRIVER_LED_TOTAL; i++ )
-    {
-        IS31FL3731_set_color( i, red, green, blue );
+void IS31FL3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+    for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+        IS31FL3731_set_color(i, red, green, blue);
     }
 }
 
-void IS31FL3731_set_led_control_register( uint8_t index, bool red, bool green, bool blue )
-{
+void IS31FL3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
     is31_led led = g_is31_leds[index];
 
     uint8_t control_register_r = (led.r - 0x24) / 8;
     uint8_t control_register_g = (led.g - 0x24) / 8;
     uint8_t control_register_b = (led.b - 0x24) / 8;
-    uint8_t bit_r = (led.r - 0x24) % 8;
-    uint8_t bit_g = (led.g - 0x24) % 8;
-    uint8_t bit_b = (led.b - 0x24) % 8;
+    uint8_t bit_r              = (led.r - 0x24) % 8;
+    uint8_t bit_g              = (led.g - 0x24) % 8;
+    uint8_t bit_b              = (led.b - 0x24) % 8;
 
-    if ( red ) {
+    if (red) {
         g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
     } else {
         g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
     }
-    if ( green ) {
+    if (green) {
         g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
     } else {
         g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
     }
-    if ( blue ) {
+    if (blue) {
         g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
     } else {
         g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
     }
 
     g_led_control_registers_update_required[led.driver] = true;
-
 }
 
-void IS31FL3731_update_pwm_buffers( uint8_t addr, uint8_t index )
-{
-    if ( g_pwm_buffer_update_required[index] )
-    {
-        IS31FL3731_write_pwm_buffer( addr, g_pwm_buffer[index] );
+void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
+    if (g_pwm_buffer_update_required[index]) {
+        IS31FL3731_write_pwm_buffer(addr, g_pwm_buffer[index]);
     }
     g_pwm_buffer_update_required[index] = false;
 }
 
-void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index )
-{
-    if ( g_led_control_registers_update_required[index] )
-    {
-        for ( int i=0; i<18; i++ )
-        {
-            IS31FL3731_write_register( addr, i, g_led_control_registers[index][i] );
+void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index) {
+    if (g_led_control_registers_update_required[index]) {
+        for (int i = 0; i < 18; i++) {
+            IS31FL3731_write_register(addr, i, g_led_control_registers[index][i]);
         }
     }
 }
index 968638f86af8460c7fc87f08cb148b5e6035fc32..6a7a45d8fff01f3795d54a4a4429485eb9e7aa92 100644 (file)
@@ -15,7 +15,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #ifndef IS31FL3731_DRIVER_H
 #define IS31FL3731_DRIVER_H
 
 #include <stdbool.h>
 
 typedef struct is31_led {
-  uint8_t driver:2;
-  uint8_t r;
-  uint8_t g;
-  uint8_t b;
+    uint8_t driver : 2;
+    uint8_t r;
+    uint8_t g;
+    uint8_t b;
 } __attribute__((packed)) is31_led;
 
 extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
 
-void IS31FL3731_init( uint8_t addr );
-void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data );
-void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer );
+void IS31FL3731_init(uint8_t addr);
+void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
 
-void IS31FL3731_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
-void IS31FL3731_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
+void IS31FL3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
 
-void IS31FL3731_set_led_control_register( uint8_t index, bool red, bool green, bool blue );
+void IS31FL3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
 
 // This should not be called from an interrupt
 // (eg. from a timer interrupt).
 // Call this while idle (in between matrix scans).
 // If the buffer is dirty, it will update the driver with the buffer.
-void IS31FL3731_update_pwm_buffers( uint8_t addr, uint8_t index  );
-void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index );
-
-#define C1_1  0x24
-#define C1_2  0x25
-#define C1_3  0x26
-#define C1_4  0x27
-#define C1_5  0x28
-#define C1_6  0x29
-#define C1_7  0x2A
-#define C1_8  0x2B
-
-#define C1_9  0x2C
+void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index);
+void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
+
+#define C1_1 0x24
+#define C1_2 0x25
+#define C1_3 0x26
+#define C1_4 0x27
+#define C1_5 0x28
+#define C1_6 0x29
+#define C1_7 0x2A
+#define C1_8 0x2B
+
+#define C1_9 0x2C
 #define C1_10 0x2D
 #define C1_11 0x2E
 #define C1_12 0x2F
@@ -65,16 +64,16 @@ void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index );
 #define C1_15 0x32
 #define C1_16 0x33
 
-#define C2_1  0x34
-#define C2_2  0x35
-#define C2_3  0x36
-#define C2_4  0x37
-#define C2_5  0x38
-#define C2_6  0x39
-#define C2_7  0x3A
-#define C2_8  0x3B
+#define C2_1 0x34
+#define C2_2 0x35
+#define C2_3 0x36
+#define C2_4 0x37
+#define C2_5 0x38
+#define C2_6 0x39
+#define C2_7 0x3A
+#define C2_8 0x3B
 
-#define C2_9  0x3C
+#define C2_9 0x3C
 #define C2_10 0x3D
 #define C2_11 0x3E
 #define C2_12 0x3F
@@ -83,16 +82,16 @@ void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index );
 #define C2_15 0x42
 #define C2_16 0x43
 
-#define C3_1  0x44
-#define C3_2  0x45
-#define C3_3  0x46
-#define C3_4  0x47
-#define C3_5  0x48
-#define C3_6  0x49
-#define C3_7  0x4A
-#define C3_8  0x4B
+#define C3_1 0x44
+#define C3_2 0x45
+#define C3_3 0x46
+#define C3_4 0x47
+#define C3_5 0x48
+#define C3_6 0x49
+#define C3_7 0x4A
+#define C3_8 0x4B
 
-#define C3_9  0x4C
+#define C3_9 0x4C
 #define C3_10 0x4D
 #define C3_11 0x4E
 #define C3_12 0x4F
@@ -101,16 +100,16 @@ void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index );
 #define C3_15 0x52
 #define C3_16 0x53
 
-#define C4_1  0x54
-#define C4_2  0x55
-#define C4_3  0x56
-#define C4_4  0x57
-#define C4_5  0x58
-#define C4_6  0x59
-#define C4_7  0x5A
-#define C4_8  0x5B
+#define C4_1 0x54
+#define C4_2 0x55
+#define C4_3 0x56
+#define C4_4 0x57
+#define C4_5 0x58
+#define C4_6 0x59
+#define C4_7 0x5A
+#define C4_8 0x5B
 
-#define C4_9  0x5C
+#define C4_9 0x5C
 #define C4_10 0x5D
 #define C4_11 0x5E
 #define C4_12 0x5F
@@ -119,16 +118,16 @@ void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index );
 #define C4_15 0x62
 #define C4_16 0x63
 
-#define C5_1  0x64
-#define C5_2  0x65
-#define C5_3  0x66
-#define C5_4  0x67
-#define C5_5  0x68
-#define C5_6  0x69
-#define C5_7  0x6A
-#define C5_8  0x6B
+#define C5_1 0x64
+#define C5_2 0x65
+#define C5_3 0x66
+#define C5_4 0x67
+#define C5_5 0x68
+#define C5_6 0x69
+#define C5_7 0x6A
+#define C5_8 0x6B
 
-#define C5_9  0x6C
+#define C5_9 0x6C
 #define C5_10 0x6D
 #define C5_11 0x6E
 #define C5_12 0x6F
@@ -137,16 +136,16 @@ void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index );
 #define C5_15 0x72
 #define C5_16 0x73
 
-#define C6_1  0x74
-#define C6_2  0x75
-#define C6_3  0x76
-#define C6_4  0x77
-#define C6_5  0x78
-#define C6_6  0x79
-#define C6_7  0x7A
-#define C6_8  0x7B
+#define C6_1 0x74
+#define C6_2 0x75
+#define C6_3 0x76
+#define C6_4 0x77
+#define C6_5 0x78
+#define C6_6 0x79
+#define C6_7 0x7A
+#define C6_8 0x7B
 
-#define C6_9  0x7C
+#define C6_9 0x7C
 #define C6_10 0x7D
 #define C6_11 0x7E
 #define C6_12 0x7F
@@ -155,16 +154,16 @@ void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index );
 #define C6_15 0x82
 #define C6_16 0x83
 
-#define C7_1  0x84
-#define C7_2  0x85
-#define C7_3  0x86
-#define C7_4  0x87
-#define C7_5  0x88
-#define C7_6  0x89
-#define C7_7  0x8A
-#define C7_8  0x8B
+#define C7_1 0x84
+#define C7_2 0x85
+#define C7_3 0x86
+#define C7_4 0x87
+#define C7_5 0x88
+#define C7_6 0x89
+#define C7_7 0x8A
+#define C7_8 0x8B
 
-#define C7_9  0x8C
+#define C7_9 0x8C
 #define C7_10 0x8D
 #define C7_11 0x8E
 #define C7_12 0x8F
@@ -173,16 +172,16 @@ void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index );
 #define C7_15 0x92
 #define C7_16 0x93
 
-#define C8_1  0x94
-#define C8_2  0x95
-#define C8_3  0x96
-#define C8_4  0x97
-#define C8_5  0x98
-#define C8_6  0x99
-#define C8_7  0x9A
-#define C8_8  0x9B
+#define C8_1 0x94
+#define C8_2 0x95
+#define C8_3 0x96
+#define C8_4 0x97
+#define C8_5 0x98
+#define C8_6 0x99
+#define C8_7 0x9A
+#define C8_8 0x9B
 
-#define C8_9  0x9C
+#define C8_9 0x9C
 #define C8_10 0x9D
 #define C8_11 0x9E
 #define C8_12 0x9F
@@ -191,16 +190,16 @@ void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index );
 #define C8_15 0xA2
 #define C8_16 0xA3
 
-#define C9_1  0xA4
-#define C9_2  0xA5
-#define C9_3  0xA6
-#define C9_4  0xA7
-#define C9_5  0xA8
-#define C9_6  0xA9
-#define C9_7  0xAA
-#define C9_8  0xAB
+#define C9_1 0xA4
+#define C9_2 0xA5
+#define C9_3 0xA6
+#define C9_4 0xA7
+#define C9_5 0xA8
+#define C9_6 0xA9
+#define C9_7 0xAA
+#define C9_8 0xAB
 
-#define C9_9  0xAC
+#define C9_9 0xAC
 #define C9_10 0xAD
 #define C9_11 0xAE
 #define C9_12 0xAF
@@ -209,6 +208,4 @@ void IS31FL3731_update_led_control_registers( uint8_t addr, uint8_t index );
 #define C9_15 0xB2
 #define C9_16 0xB3
 
-
-
-#endif // IS31FL3731_DRIVER_H
+#endif  // IS31FL3731_DRIVER_H
index aa247f4e8a2a1de9816cc45452fa586f8f57639d..968f072de8768f15728cd6eaa5b800b808b4a5e7 100644 (file)
  */
 
 #ifdef __AVR__
-#include <avr/interrupt.h>
-#include <avr/io.h>
-#include <util/delay.h>
+#    include <avr/interrupt.h>
+#    include <avr/io.h>
+#    include <util/delay.h>
 #else
-#include "wait.h"
+#    include "wait.h"
 #endif
 
 #include "is31fl3733.h"
 #define ISSI_INTERRUPTMASKREGISTER 0xF0
 #define ISSI_INTERRUPTSTATUSREGISTER 0xF1
 
-#define ISSI_PAGE_LEDCONTROL 0x00 //PG0
-#define ISSI_PAGE_PWM 0x01        //PG1
-#define ISSI_PAGE_AUTOBREATH 0x02 //PG2
-#define ISSI_PAGE_FUNCTION 0x03   //PG3
+#define ISSI_PAGE_LEDCONTROL 0x00  // PG0
+#define ISSI_PAGE_PWM 0x01         // PG1
+#define ISSI_PAGE_AUTOBREATH 0x02  // PG2
+#define ISSI_PAGE_FUNCTION 0x03    // PG3
 
-#define ISSI_REG_CONFIGURATION 0x00 //PG3
-#define ISSI_REG_GLOBALCURRENT 0x01 //PG3
-#define ISSI_REG_RESET 0x11// PG3
-#define ISSI_REG_SWPULLUP 0x0F //PG3
-#define ISSI_REG_CSPULLUP 0x10 //PG3
+#define ISSI_REG_CONFIGURATION 0x00  // PG3
+#define ISSI_REG_GLOBALCURRENT 0x01  // PG3
+#define ISSI_REG_RESET 0x11          // PG3
+#define ISSI_REG_SWPULLUP 0x0F       // PG3
+#define ISSI_REG_CSPULLUP 0x10       // PG3
 
 #ifndef ISSI_TIMEOUT
-  #define ISSI_TIMEOUT 100
+#    define ISSI_TIMEOUT 100
 #endif
 
 #ifndef ISSI_PERSISTENCE
-  #define ISSI_PERSISTENCE 0
+#    define ISSI_PERSISTENCE 0
 #endif
 
 // Transfer buffer for TWITransmitData()
@@ -75,56 +75,51 @@ uint8_t g_twi_transfer_buffer[20];
 // buffers and the transfers in IS31FL3733_write_pwm_buffer() but it's
 // probably not worth the extra complexity.
 uint8_t g_pwm_buffer[DRIVER_COUNT][192];
-bool g_pwm_buffer_update_required[DRIVER_COUNT] = { false };
+bool    g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
 
-uint8_t g_led_control_registers[DRIVER_COUNT][24] = { { 0 }, { 0 } };
-bool g_led_control_registers_update_required[DRIVER_COUNT] = { false };
+uint8_t g_led_control_registers[DRIVER_COUNT][24]             = {{0}, {0}};
+bool    g_led_control_registers_update_required[DRIVER_COUNT] = {false};
 
-void IS31FL3733_write_register( uint8_t addr, uint8_t reg, uint8_t data )
-{
+void IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
     g_twi_transfer_buffer[0] = reg;
     g_twi_transfer_buffer[1] = data;
 
-  #if ISSI_PERSISTENCE > 0
+#if ISSI_PERSISTENCE > 0
     for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
-      if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0)
-        break;
+        if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
     }
-  #else
+#else
     i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-  #endif
+#endif
 }
 
-void IS31FL3733_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer )
-{
+void IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
     // assumes PG1 is already selected
 
     // transmit PWM registers in 12 transfers of 16 bytes
     // g_twi_transfer_buffer[] is 20 bytes
 
     // iterate over the pwm_buffer contents at 16 byte intervals
-    for ( int i = 0; i < 192; i += 16 ) {
+    for (int i = 0; i < 192; i += 16) {
         g_twi_transfer_buffer[0] = i;
         // copy the data from i to i+15
         // device will auto-increment register for data after the first byte
         // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
-        for ( int j = 0; j < 16; j++ ) {
+        for (int j = 0; j < 16; j++) {
             g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
         }
 
-    #if ISSI_PERSISTENCE > 0
-      for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
-        if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0)
-          break;
-      }
-    #else
-      i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
-    #endif
+#if ISSI_PERSISTENCE > 0
+        for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+            if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
+        }
+#else
+        i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
+#endif
     }
 }
 
-void IS31FL3733_init( uint8_t addr, uint8_t sync)
-{
+void IS31FL3733_init(uint8_t addr, uint8_t sync) {
     // In order to avoid the LEDs being driven with garbage data
     // in the LED driver's PWM registers, shutdown is enabled last.
     // Set up the mode and other settings, clear the PWM registers,
@@ -132,120 +127,108 @@ void IS31FL3733_init( uint8_t addr, uint8_t sync)
     // Sync is passed so set it according to the datasheet.
 
     // Unlock the command register.
-    IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
+    IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
 
     // Select PG0
-    IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL );
+    IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
     // Turn off all LEDs.
-    for ( int i = 0x00; i <= 0x17; i++ )
-    {
-        IS31FL3733_write_register( addr, i, 0x00 );
+    for (int i = 0x00; i <= 0x17; i++) {
+        IS31FL3733_write_register(addr, i, 0x00);
     }
 
     // Unlock the command register.
-    IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
+    IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
 
     // Select PG1
-    IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM );
+    IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
     // Set PWM on all LEDs to 0
     // No need to setup Breath registers to PWM as that is the default.
-    for ( int i = 0x00; i <= 0xBF; i++ )
-    {
-        IS31FL3733_write_register( addr, i, 0x00 );
+    for (int i = 0x00; i <= 0xBF; i++) {
+        IS31FL3733_write_register(addr, i, 0x00);
     }
 
     // Unlock the command register.
-    IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
+    IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
 
     // Select PG3
-    IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION );
+    IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
     // Set global current to maximum.
-    IS31FL3733_write_register( addr, ISSI_REG_GLOBALCURRENT, 0xFF );
+    IS31FL3733_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
     // Disable software shutdown.
-    IS31FL3733_write_register( addr, ISSI_REG_CONFIGURATION, (sync << 6) | 0x01 );
+    IS31FL3733_write_register(addr, ISSI_REG_CONFIGURATION, (sync << 6) | 0x01);
 
-    // Wait 10ms to ensure the device has woken up.
-    #ifdef __AVR__
-    _delay_ms( 10 );
-    #else
+// Wait 10ms to ensure the device has woken up.
+#ifdef __AVR__
+    _delay_ms(10);
+#else
     wait_ms(10);
-    #endif
+#endif
 }
 
-void IS31FL3733_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
-{
-    if ( index >= 0 && index < DRIVER_LED_TOTAL ) {
+void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+    if (index >= 0 && index < DRIVER_LED_TOTAL) {
         is31_led led = g_is31_leds[index];
 
-        g_pwm_buffer[led.driver][led.r] = red;
-        g_pwm_buffer[led.driver][led.g] = green;
-        g_pwm_buffer[led.driver][led.b] = blue;
+        g_pwm_buffer[led.driver][led.r]          = red;
+        g_pwm_buffer[led.driver][led.g]          = green;
+        g_pwm_buffer[led.driver][led.b]          = blue;
         g_pwm_buffer_update_required[led.driver] = true;
     }
 }
 
-void IS31FL3733_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
-{
-    for ( int i = 0; i < DRIVER_LED_TOTAL; i++ )
-    {
-        IS31FL3733_set_color( i, red, green, blue );
+void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+    for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+        IS31FL3733_set_color(i, red, green, blue);
     }
 }
 
-void IS31FL3733_set_led_control_register( uint8_t index, bool red, bool green, bool blue )
-{
+void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
     is31_led led = g_is31_leds[index];
 
-  uint8_t control_register_r = led.r / 8;
-  uint8_t control_register_g = led.g / 8;
-  uint8_t control_register_b = led.b / 8;
-  uint8_t bit_r = led.r % 8;
-  uint8_t bit_g = led.g % 8;
-  uint8_t bit_b = led.b % 8;
+    uint8_t control_register_r = led.r / 8;
+    uint8_t control_register_g = led.g / 8;
+    uint8_t control_register_b = led.b / 8;
+    uint8_t bit_r              = led.r % 8;
+    uint8_t bit_g              = led.g % 8;
+    uint8_t bit_b              = led.b % 8;
 
-    if ( red ) {
+    if (red) {
         g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
     } else {
         g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
     }
-    if ( green ) {
+    if (green) {
         g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
     } else {
         g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
     }
-    if ( blue ) {
+    if (blue) {
         g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
     } else {
         g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
     }
 
     g_led_control_registers_update_required[led.driver] = true;
-
 }
 
-void IS31FL3733_update_pwm_buffers( uint8_t addr, uint8_t index )
-{
-    if ( g_pwm_buffer_update_required[index] )
-    {
+void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
+    if (g_pwm_buffer_update_required[index]) {
         // Firstly we need to unlock the command register and select PG1
-        IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
-        IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM );
+        IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+        IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
 
-        IS31FL3733_write_pwm_buffer( addr, g_pwm_buffer[index] );
+        IS31FL3733_write_pwm_buffer(addr, g_pwm_buffer[index]);
     }
     g_pwm_buffer_update_required[index] = false;
 }
 
-void IS31FL3733_update_led_control_registers( uint8_t addr, uint8_t index )
-{
-    if ( g_led_control_registers_update_required[index] )
-    {
+void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index) {
+    if (g_led_control_registers_update_required[index]) {
         // Firstly we need to unlock the command register and select PG0
-        IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
-        IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL );
-        for ( int i=0; i<24; i++ )
-        {
-            IS31FL3733_write_register(addr, i, g_led_control_registers[index][i] );
+        IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+        IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+        for (int i = 0; i < 24; i++) {
+            IS31FL3733_write_register(addr, i, g_led_control_registers[index][i]);
         }
     }
     g_led_control_registers_update_required[index] = false;
index e117b2546009ad7d15d2869846bddbd946b71b26..5b3283e035f63120134320e23db5eb0072947c5c 100644 (file)
@@ -16,7 +16,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #ifndef IS31FL3733_DRIVER_H
 #define IS31FL3733_DRIVER_H
 
 #include <stdbool.h>
 
 typedef struct is31_led {
-  uint8_t driver:2;
-  uint8_t r;
-  uint8_t g;
-  uint8_t b;
+    uint8_t driver : 2;
+    uint8_t r;
+    uint8_t g;
+    uint8_t b;
 } __attribute__((packed)) is31_led;
 
 extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
 
-void IS31FL3733_init( uint8_t addr, uint8_t sync );
-void IS31FL3733_write_register( uint8_t addr, uint8_t reg, uint8_t data );
-void IS31FL3733_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer );
+void IS31FL3733_init(uint8_t addr, uint8_t sync);
+void IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
 
-void IS31FL3733_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
-void IS31FL3733_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
+void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
 
-void IS31FL3733_set_led_control_register( uint8_t index, bool red, bool green, bool blue );
+void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
 
 // This should not be called from an interrupt
 // (eg. from a timer interrupt).
 // Call this while idle (in between matrix scans).
 // If the buffer is dirty, it will update the driver with the buffer.
-void IS31FL3733_update_pwm_buffers( uint8_t addr, uint8_t index );
-void IS31FL3733_update_led_control_registers( uint8_t addr, uint8_t index );
-
-#define A_1  0x00
-#define A_2  0x01
-#define A_3  0x02
-#define A_4  0x03
-#define A_5  0x04
-#define A_6  0x05
-#define A_7  0x06
-#define A_8  0x07
-#define A_9  0x08
-#define A_10  0x09
-#define A_11  0x0A
-#define A_12  0x0B
-#define A_13  0x0C
-#define A_14  0x0D
-#define A_15  0x0E
-#define A_16  0x0F
-
-#define B_1  0x10
-#define B_2  0x11
-#define B_3  0x12
-#define B_4  0x13
-#define B_5  0x14
-#define B_6  0x15
-#define B_7  0x16
-#define B_8  0x17
-#define B_9  0x18
-#define B_10  0x19
-#define B_11  0x1A
-#define B_12  0x1B
-#define B_13  0x1C
-#define B_14  0x1D
-#define B_15  0x1E
-#define B_16  0x1F
-
-#define C_1  0x20
-#define C_2  0x21
-#define C_3  0x22
-#define C_4  0x23
-#define C_5  0x24
-#define C_6  0x25
-#define C_7  0x26
-#define C_8  0x27
-#define C_9  0x28
-#define C_10  0x29
-#define C_11  0x2A
-#define C_12  0x2B
-#define C_13  0x2C
-#define C_14  0x2D
-#define C_15  0x2E
-#define C_16  0x2F
-
-#define D_1  0x30
-#define D_2  0x31
-#define D_3  0x32
-#define D_4  0x33
-#define D_5  0x34
-#define D_6  0x35
-#define D_7  0x36
-#define D_8  0x37
-#define D_9  0x38
-#define D_10  0x39
-#define D_11  0x3A
-#define D_12  0x3B
-#define D_13  0x3C
-#define D_14  0x3D
-#define D_15  0x3E
-#define D_16  0x3F
-
-#define E_1  0x40
-#define E_2  0x41
-#define E_3  0x42
-#define E_4  0x43
-#define E_5  0x44
-#define E_6  0x45
-#define E_7  0x46
-#define E_8  0x47
-#define E_9  0x48
-#define E_10  0x49
-#define E_11  0x4A
-#define E_12  0x4B
-#define E_13  0x4C
-#define E_14  0x4D
-#define E_15  0x4E
-#define E_16  0x4F
-
-#define F_1  0x50
-#define F_2  0x51
-#define F_3  0x52
-#define F_4  0x53
-#define F_5  0x54
-#define F_6  0x55
-#define F_7  0x56
-#define F_8  0x57
-#define F_9  0x58
-#define F_10  0x59
-#define F_11  0x5A
-#define F_12  0x5B
-#define F_13  0x5C
-#define F_14  0x5D
-#define F_15  0x5E
-#define F_16  0x5F
-
-#define G_1  0x60
-#define G_2  0x61
-#define G_3  0x62
-#define G_4  0x63
-#define G_5  0x64
-#define G_6  0x65
-#define G_7  0x66
-#define G_8  0x67
-#define G_9  0x68
-#define G_10  0x69
-#define G_11  0x6A
-#define G_12  0x6B
-#define G_13  0x6C
-#define G_14  0x6D
-#define G_15  0x6E
-#define G_16  0x6F
-
-#define H_1  0x70
-#define H_2  0x71
-#define H_3  0x72
-#define H_4  0x73
-#define H_5  0x74
-#define H_6  0x75
-#define H_7  0x76
-#define H_8  0x77
-#define H_9  0x78
-#define H_10  0x79
-#define H_11  0x7A
-#define H_12  0x7B
-#define H_13  0x7C
-#define H_14  0x7D
-#define H_15  0x7E
-#define H_16  0x7F
-
-#define I_1  0x80
-#define I_2  0x81
-#define I_3  0x82
-#define I_4  0x83
-#define I_5  0x84
-#define I_6  0x85
-#define I_7  0x86
-#define I_8  0x87
-#define I_9  0x88
-#define I_10  0x89
-#define I_11  0x8A
-#define I_12  0x8B
-#define I_13  0x8C
-#define I_14  0x8D
-#define I_15  0x8E
-#define I_16  0x8F
-
-#define J_1  0x90
-#define J_2  0x91
-#define J_3  0x92
-#define J_4  0x93
-#define J_5  0x94
-#define J_6  0x95
-#define J_7  0x96
-#define J_8  0x97
-#define J_9  0x98
-#define J_10  0x99
-#define J_11  0x9A
-#define J_12  0x9B
-#define J_13  0x9C
-#define J_14  0x9D
-#define J_15  0x9E
-#define J_16  0x9F
-
-#define K_1  0xA0
-#define K_2  0xA1
-#define K_3  0xA2
-#define K_4  0xA3
-#define K_5  0xA4
-#define K_6  0xA5
-#define K_7  0xA6
-#define K_8  0xA7
-#define K_9  0xA8
-#define K_10  0xA9
-#define K_11  0xAA
-#define K_12  0xAB
-#define K_13  0xAC
-#define K_14  0xAD
-#define K_15  0xAE
-#define K_16  0xAF
-
-#define L_1  0xB0
-#define L_2  0xB1
-#define L_3  0xB2
-#define L_4  0xB3
-#define L_5  0xB4
-#define L_6  0xB5
-#define L_7  0xB6
-#define L_8  0xB7
-#define L_9  0xB8
-#define L_10  0xB9
-#define L_11  0xBA
-#define L_12  0xBB
-#define L_13  0xBC
-#define L_14  0xBD
-#define L_15  0xBE
-#define L_16  0xBF
-
-#endif // IS31FL3733_DRIVER_H
+void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index);
+void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index);
+
+#define A_1 0x00
+#define A_2 0x01
+#define A_3 0x02
+#define A_4 0x03
+#define A_5 0x04
+#define A_6 0x05
+#define A_7 0x06
+#define A_8 0x07
+#define A_9 0x08
+#define A_10 0x09
+#define A_11 0x0A
+#define A_12 0x0B
+#define A_13 0x0C
+#define A_14 0x0D
+#define A_15 0x0E
+#define A_16 0x0F
+
+#define B_1 0x10
+#define B_2 0x11
+#define B_3 0x12
+#define B_4 0x13
+#define B_5 0x14
+#define B_6 0x15
+#define B_7 0x16
+#define B_8 0x17
+#define B_9 0x18
+#define B_10 0x19
+#define B_11 0x1A
+#define B_12 0x1B
+#define B_13 0x1C
+#define B_14 0x1D
+#define B_15 0x1E
+#define B_16 0x1F
+
+#define C_1 0x20
+#define C_2 0x21
+#define C_3 0x22
+#define C_4 0x23
+#define C_5 0x24
+#define C_6 0x25
+#define C_7 0x26
+#define C_8 0x27
+#define C_9 0x28
+#define C_10 0x29
+#define C_11 0x2A
+#define C_12 0x2B
+#define C_13 0x2C
+#define C_14 0x2D
+#define C_15 0x2E
+#define C_16 0x2F
+
+#define D_1 0x30
+#define D_2 0x31
+#define D_3 0x32
+#define D_4 0x33
+#define D_5 0x34
+#define D_6 0x35
+#define D_7 0x36
+#define D_8 0x37
+#define D_9 0x38
+#define D_10 0x39
+#define D_11 0x3A
+#define D_12 0x3B
+#define D_13 0x3C
+#define D_14 0x3D
+#define D_15 0x3E
+#define D_16 0x3F
+
+#define E_1 0x40
+#define E_2 0x41
+#define E_3 0x42
+#define E_4 0x43
+#define E_5 0x44
+#define E_6 0x45
+#define E_7 0x46
+#define E_8 0x47
+#define E_9 0x48
+#define E_10 0x49
+#define E_11 0x4A
+#define E_12 0x4B
+#define E_13 0x4C
+#define E_14 0x4D
+#define E_15 0x4E
+#define E_16 0x4F
+
+#define F_1 0x50
+#define F_2 0x51
+#define F_3 0x52
+#define F_4 0x53
+#define F_5 0x54
+#define F_6 0x55
+#define F_7 0x56
+#define F_8 0x57
+#define F_9 0x58
+#define F_10 0x59
+#define F_11 0x5A
+#define F_12 0x5B
+#define F_13 0x5C
+#define F_14 0x5D
+#define F_15 0x5E
+#define F_16 0x5F
+
+#define G_1 0x60
+#define G_2 0x61
+#define G_3 0x62
+#define G_4 0x63
+#define G_5 0x64
+#define G_6 0x65
+#define G_7 0x66
+#define G_8 0x67
+#define G_9 0x68
+#define G_10 0x69
+#define G_11 0x6A
+#define G_12 0x6B
+#define G_13 0x6C
+#define G_14 0x6D
+#define G_15 0x6E
+#define G_16 0x6F
+
+#define H_1 0x70
+#define H_2 0x71
+#define H_3 0x72
+#define H_4 0x73
+#define H_5 0x74
+#define H_6 0x75
+#define H_7 0x76
+#define H_8 0x77
+#define H_9 0x78
+#define H_10 0x79
+#define H_11 0x7A
+#define H_12 0x7B
+#define H_13 0x7C
+#define H_14 0x7D
+#define H_15 0x7E
+#define H_16 0x7F
+
+#define I_1 0x80
+#define I_2 0x81
+#define I_3 0x82
+#define I_4 0x83
+#define I_5 0x84
+#define I_6 0x85
+#define I_7 0x86
+#define I_8 0x87
+#define I_9 0x88
+#define I_10 0x89
+#define I_11 0x8A
+#define I_12 0x8B
+#define I_13 0x8C
+#define I_14 0x8D
+#define I_15 0x8E
+#define I_16 0x8F
+
+#define J_1 0x90
+#define J_2 0x91
+#define J_3 0x92
+#define J_4 0x93
+#define J_5 0x94
+#define J_6 0x95
+#define J_7 0x96
+#define J_8 0x97
+#define J_9 0x98
+#define J_10 0x99
+#define J_11 0x9A
+#define J_12 0x9B
+#define J_13 0x9C
+#define J_14 0x9D
+#define J_15 0x9E
+#define J_16 0x9F
+
+#define K_1 0xA0
+#define K_2 0xA1
+#define K_3 0xA2
+#define K_4 0xA3
+#define K_5 0xA4
+#define K_6 0xA5
+#define K_7 0xA6
+#define K_8 0xA7
+#define K_9 0xA8
+#define K_10 0xA9
+#define K_11 0xAA
+#define K_12 0xAB
+#define K_13 0xAC
+#define K_14 0xAD
+#define K_15 0xAE
+#define K_16 0xAF
+
+#define L_1 0xB0
+#define L_2 0xB1
+#define L_3 0xB2
+#define L_4 0xB3
+#define L_5 0xB4
+#define L_6 0xB5
+#define L_7 0xB6
+#define L_8 0xB7
+#define L_9 0xB8
+#define L_10 0xB9
+#define L_11 0xBA
+#define L_12 0xBB
+#define L_13 0xBC
+#define L_14 0xBD
+#define L_15 0xBE
+#define L_16 0xBF
+
+#endif  // IS31FL3733_DRIVER_H
index c5d43109719880714f4373aa9a83b432547997ec..754292425ec8d57ff670f7b9e45a7e3e12fc8b6f 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #ifdef __AVR__
-#include <avr/interrupt.h>
-#include <avr/io.h>
-#include <util/delay.h>
+#    include <avr/interrupt.h>
+#    include <avr/io.h>
+#    include <util/delay.h>
 #else
-#include "wait.h"
+#    include "wait.h"
 #endif
 
 #include "is31fl3736.h"
@@ -28,8 +27,6 @@
 #include "i2c_master.h"
 #include "progmem.h"
 
-
-
 // This is a 7-bit address, that gets left-shifted and bit 0
 // set to 0 for write, 1 for read (as per I2C protocol)
 // The address will vary depending on your wiring:
 #define ISSI_INTERRUPTMASKREGISTER 0xF0
 #define ISSI_INTERRUPTSTATUSREGISTER 0xF1
 
-#define ISSI_PAGE_LEDCONTROL 0x00 //PG0
-#define ISSI_PAGE_PWM 0x01        //PG1
-#define ISSI_PAGE_AUTOBREATH 0x02 //PG2
-#define ISSI_PAGE_FUNCTION 0x03   //PG3
+#define ISSI_PAGE_LEDCONTROL 0x00  // PG0
+#define ISSI_PAGE_PWM 0x01         // PG1
+#define ISSI_PAGE_AUTOBREATH 0x02  // PG2
+#define ISSI_PAGE_FUNCTION 0x03    // PG3
 
-#define ISSI_REG_CONFIGURATION 0x00 //PG3
-#define ISSI_REG_GLOBALCURRENT 0x01 //PG3
-#define ISSI_REG_RESET 0x11// PG3
-#define ISSI_REG_SWPULLUP 0x0F //PG3
-#define ISSI_REG_CSPULLUP 0x10 //PG3
+#define ISSI_REG_CONFIGURATION 0x00  // PG3
+#define ISSI_REG_GLOBALCURRENT 0x01  // PG3
+#define ISSI_REG_RESET 0x11          // PG3
+#define ISSI_REG_SWPULLUP 0x0F       // PG3
+#define ISSI_REG_CSPULLUP 0x10       // PG3
 
 #ifndef ISSI_TIMEOUT
-  #define ISSI_TIMEOUT 100
+#    define ISSI_TIMEOUT 100
 #endif
 
 #ifndef ISSI_PERSISTENCE
-  #define ISSI_PERSISTENCE 0
+#    define ISSI_PERSISTENCE 0
 #endif
 
 // Transfer buffer for TWITransmitData()
@@ -76,124 +73,113 @@ uint8_t g_twi_transfer_buffer[20];
 // buffers and the transfers in IS31FL3736_write_pwm_buffer() but it's
 // probably not worth the extra complexity.
 uint8_t g_pwm_buffer[DRIVER_COUNT][192];
-bool g_pwm_buffer_update_required = false;
+bool    g_pwm_buffer_update_required = false;
 
-uint8_t g_led_control_registers[DRIVER_COUNT][24] = { { 0 }, { 0 } };
-bool g_led_control_registers_update_required = false;
+uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}};
+bool    g_led_control_registers_update_required   = false;
 
-void IS31FL3736_write_register( uint8_t addr, uint8_t reg, uint8_t data )
-{
+void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
     g_twi_transfer_buffer[0] = reg;
     g_twi_transfer_buffer[1] = data;
 
-  #if ISSI_PERSISTENCE > 0
+#if ISSI_PERSISTENCE > 0
     for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
-      if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0)
-        break;
+        if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
     }
-  #else
+#else
     i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-  #endif
+#endif
 }
 
-void IS31FL3736_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer )
-{
+void IS31FL3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
     // assumes PG1 is already selected
 
     // transmit PWM registers in 12 transfers of 16 bytes
     // g_twi_transfer_buffer[] is 20 bytes
 
     // iterate over the pwm_buffer contents at 16 byte intervals
-    for ( int i = 0; i < 192; i += 16 ) {
+    for (int i = 0; i < 192; i += 16) {
         g_twi_transfer_buffer[0] = i;
         // copy the data from i to i+15
         // device will auto-increment register for data after the first byte
         // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
-        for ( int j = 0; j < 16; j++ ) {
+        for (int j = 0; j < 16; j++) {
             g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
         }
 
-    #if ISSI_PERSISTENCE > 0
-      for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
-        if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0)
-          break;
-      }
-    #else
-      i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
-    #endif
+#if ISSI_PERSISTENCE > 0
+        for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+            if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
+        }
+#else
+        i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
+#endif
     }
 }
 
-void IS31FL3736_init( uint8_t addr )
-{
+void IS31FL3736_init(uint8_t addr) {
     // In order to avoid the LEDs being driven with garbage data
     // in the LED driver's PWM registers, shutdown is enabled last.
     // Set up the mode and other settings, clear the PWM registers,
     // then disable software shutdown.
 
     // Unlock the command register.
-    IS31FL3736_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
+    IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
 
     // Select PG0
-    IS31FL3736_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL );
+    IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
     // Turn off all LEDs.
-    for ( int i = 0x00; i <= 0x17; i++ )
-    {
-        IS31FL3736_write_register( addr, i, 0x00 );
+    for (int i = 0x00; i <= 0x17; i++) {
+        IS31FL3736_write_register(addr, i, 0x00);
     }
 
     // Unlock the command register.
-    IS31FL3736_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
+    IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
 
     // Select PG1
-    IS31FL3736_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM );
+    IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
     // Set PWM on all LEDs to 0
     // No need to setup Breath registers to PWM as that is the default.
-    for ( int i = 0x00; i <= 0xBF; i++ )
-    {
-        IS31FL3736_write_register( addr, i, 0x00 );
+    for (int i = 0x00; i <= 0xBF; i++) {
+        IS31FL3736_write_register(addr, i, 0x00);
     }
 
     // Unlock the command register.
-    IS31FL3736_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
+    IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
 
     // Select PG3
-    IS31FL3736_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION );
+    IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
     // Set global current to maximum.
-    IS31FL3736_write_register( addr, ISSI_REG_GLOBALCURRENT, 0xFF );
+    IS31FL3736_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
     // Disable software shutdown.
-    IS31FL3736_write_register( addr, ISSI_REG_CONFIGURATION, 0x01 );
+    IS31FL3736_write_register(addr, ISSI_REG_CONFIGURATION, 0x01);
 
-    // Wait 10ms to ensure the device has woken up.
-    #ifdef __AVR__
-    _delay_ms( 10 );
-    #else
+// Wait 10ms to ensure the device has woken up.
+#ifdef __AVR__
+    _delay_ms(10);
+#else
     wait_ms(10);
-    #endif
+#endif
 }
 
-void IS31FL3736_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
-{
-    if ( index >= 0 && index < DRIVER_LED_TOTAL ) {
+void IS31FL3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+    if (index >= 0 && index < DRIVER_LED_TOTAL) {
         is31_led led = g_is31_leds[index];
 
         g_pwm_buffer[led.driver][led.r] = red;
         g_pwm_buffer[led.driver][led.g] = green;
         g_pwm_buffer[led.driver][led.b] = blue;
-        g_pwm_buffer_update_required = true;
+        g_pwm_buffer_update_required    = true;
     }
 }
 
-void IS31FL3736_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
-{
-    for ( int i = 0; i < DRIVER_LED_TOTAL; i++ )
-    {
-        IS31FL3736_set_color( i, red, green, blue );
+void IS31FL3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+    for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+        IS31FL3736_set_color(i, red, green, blue);
     }
 }
 
-void IS31FL3736_set_led_control_register( uint8_t index, bool red, bool green, bool blue )
-{
+void IS31FL3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
     is31_led led = g_is31_leds[index];
 
     // IS31FL3733
@@ -209,64 +195,59 @@ void IS31FL3736_set_led_control_register( uint8_t index, bool red, bool green, b
     // A1-A4=0x00 A5-A8=0x01
     // So, the same math applies.
 
-       uint8_t control_register_r = led.r / 8;
-       uint8_t control_register_g = led.g / 8;
-       uint8_t control_register_b = led.b / 8;
+    uint8_t control_register_r = led.r / 8;
+    uint8_t control_register_g = led.g / 8;
+    uint8_t control_register_b = led.b / 8;
 
-       uint8_t bit_r = led.r % 8;
-       uint8_t bit_g = led.g % 8;
-       uint8_t bit_b = led.b % 8;
+    uint8_t bit_r = led.r % 8;
+    uint8_t bit_g = led.g % 8;
+    uint8_t bit_b = led.b % 8;
 
-    if ( red ) {
+    if (red) {
         g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
     } else {
         g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
     }
-    if ( green ) {
+    if (green) {
         g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
     } else {
         g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
     }
-    if ( blue ) {
+    if (blue) {
         g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
     } else {
         g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
     }
 
     g_led_control_registers_update_required = true;
-
 }
 
-void IS31FL3736_mono_set_brightness( int index, uint8_t value )
-{
-    if ( index >= 0 && index < 96 ) {
-       // Index in range 0..95 -> A1..A8, B1..B8, etc.
-       // Map index 0..95 to registers 0x00..0xBE (interleaved)
-       uint8_t pwm_register = index * 2;
+void IS31FL3736_mono_set_brightness(int index, uint8_t value) {
+    if (index >= 0 && index < 96) {
+        // Index in range 0..95 -> A1..A8, B1..B8, etc.
+        // Map index 0..95 to registers 0x00..0xBE (interleaved)
+        uint8_t pwm_register          = index * 2;
         g_pwm_buffer[0][pwm_register] = value;
-        g_pwm_buffer_update_required = true;
+        g_pwm_buffer_update_required  = true;
     }
 }
 
-void IS31FL3736_mono_set_brightness_all( uint8_t value )
-{
-    for ( int i = 0; i < 96; i++ )
-    {
-       IS31FL3736_mono_set_brightness( i, value );
+void IS31FL3736_mono_set_brightness_all(uint8_t value) {
+    for (int i = 0; i < 96; i++) {
+        IS31FL3736_mono_set_brightness(i, value);
     }
 }
 
-void IS31FL3736_mono_set_led_control_register( uint8_t index, bool enabled )
-{
-       // Index in range 0..95 -> A1..A8, B1..B8, etc.
+void IS31FL3736_mono_set_led_control_register(uint8_t index, bool enabled) {
+    // Index in range 0..95 -> A1..A8, B1..B8, etc.
 
-       // Map index 0..95 to registers 0x00..0xBE (interleaved)
-       uint8_t pwm_register = index * 2;
-       // Map register 0x00..0xBE (interleaved) into control register and bit
-       uint8_t control_register = pwm_register / 8;
-       uint8_t bit = pwm_register % 8;
+    // Map index 0..95 to registers 0x00..0xBE (interleaved)
+    uint8_t pwm_register = index * 2;
+    // Map register 0x00..0xBE (interleaved) into control register and bit
+    uint8_t control_register = pwm_register / 8;
+    uint8_t bit              = pwm_register % 8;
 
-    if ( enabled ) {
+    if (enabled) {
         g_led_control_registers[0][control_register] |= (1 << bit);
     } else {
         g_led_control_registers[0][control_register] &= ~(1 << bit);
@@ -275,32 +256,26 @@ void IS31FL3736_mono_set_led_control_register( uint8_t index, bool enabled )
     g_led_control_registers_update_required = true;
 }
 
-void IS31FL3736_update_pwm_buffers( uint8_t addr1, uint8_t addr2 )
-{
-    if ( g_pwm_buffer_update_required )
-    {
+void IS31FL3736_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
+    if (g_pwm_buffer_update_required) {
         // Firstly we need to unlock the command register and select PG1
-        IS31FL3736_write_register( addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
-        IS31FL3736_write_register( addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM );
+        IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+        IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
 
-        IS31FL3736_write_pwm_buffer( addr1, g_pwm_buffer[0] );
-        //IS31FL3736_write_pwm_buffer( addr2, g_pwm_buffer[1] );
+        IS31FL3736_write_pwm_buffer(addr1, g_pwm_buffer[0]);
+        // IS31FL3736_write_pwm_buffer( addr2, g_pwm_buffer[1] );
     }
     g_pwm_buffer_update_required = false;
 }
 
-void IS31FL3736_update_led_control_registers( uint8_t addr1, uint8_t addr2 )
-{
-    if ( g_led_control_registers_update_required )
-    {
+void IS31FL3736_update_led_control_registers(uint8_t addr1, uint8_t addr2) {
+    if (g_led_control_registers_update_required) {
         // Firstly we need to unlock the command register and select PG0
-        IS31FL3736_write_register( addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
-        IS31FL3736_write_register( addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL );
-        for ( int i=0; i<24; i++ )
-        {
-            IS31FL3736_write_register(addr1, i, g_led_control_registers[0][i] );
-            //IS31FL3736_write_register(addr2, i, g_led_control_registers[1][i] );
+        IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+        IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+        for (int i = 0; i < 24; i++) {
+            IS31FL3736_write_register(addr1, i, g_led_control_registers[0][i]);
+            // IS31FL3736_write_register(addr2, i, g_led_control_registers[1][i] );
         }
     }
 }
-
index cff50fd0d8863c5837f19d90bb3b9261403e28ee..e48e31c27917c59368b351643330e507027b7d9b 100644 (file)
 #include <stdint.h>
 #include <stdbool.h>
 
-
 // Simple interface option.
 // If these aren't defined, just define them to make it compile
 
-
 #ifndef DRIVER_COUNT
-#define DRIVER_COUNT 2
+#    define DRIVER_COUNT 2
 #endif
 
 #ifndef DRIVER_LED_TOTAL
-#define DRIVER_LED_TOTAL 96
+#    define DRIVER_LED_TOTAL 96
 #endif
 
-
 typedef struct is31_led {
-  uint8_t driver:2;
-  uint8_t r;
-  uint8_t g;
-  uint8_t b;
+    uint8_t driver : 2;
+    uint8_t r;
+    uint8_t g;
+    uint8_t b;
 } __attribute__((packed)) is31_led;
 
 extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
 
-void IS31FL3736_init( uint8_t addr );
-void IS31FL3736_write_register( uint8_t addr, uint8_t reg, uint8_t data );
-void IS31FL3736_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer );
+void IS31FL3736_init(uint8_t addr);
+void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void IS31FL3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
 
-void IS31FL3736_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
-void IS31FL3736_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
+void IS31FL3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
 
-void IS31FL3736_set_led_control_register( uint8_t index, bool red, bool green, bool blue );
+void IS31FL3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
 
-void IS31FL3736_mono_set_brightness( int index, uint8_t value );
-void IS31FL3736_mono_set_brightness_all( uint8_t value );
-void IS31FL3736_mono_set_led_control_register( uint8_t index, bool enabled );
+void IS31FL3736_mono_set_brightness(int index, uint8_t value);
+void IS31FL3736_mono_set_brightness_all(uint8_t value);
+void IS31FL3736_mono_set_led_control_register(uint8_t index, bool enabled);
 
 // This should not be called from an interrupt
 // (eg. from a timer interrupt).
 // Call this while idle (in between matrix scans).
 // If the buffer is dirty, it will update the driver with the buffer.
-void IS31FL3736_update_pwm_buffers( uint8_t addr1, uint8_t addr2 );
-void IS31FL3736_update_led_control_registers( uint8_t addr1, uint8_t addr2 );
-
-#define A_1  0x00
-#define A_2  0x02
-#define A_3  0x04
-#define A_4  0x06
-#define A_5  0x08
-#define A_6  0x0A
-#define A_7  0x0C
-#define A_8  0x0E
-
-#define B_1  0x10
-#define B_2  0x12
-#define B_3  0x14
-#define B_4  0x16
-#define B_5  0x18
-#define B_6  0x1A
-#define B_7  0x1C
-#define B_8  0x1E
-
-#define C_1  0x20
-#define C_2  0x22
-#define C_3  0x24
-#define C_4  0x26
-#define C_5  0x28
-#define C_6  0x2A
-#define C_7  0x2C
-#define C_8  0x2E
-
-#define D_1  0x30
-#define D_2  0x32
-#define D_3  0x34
-#define D_4  0x36
-#define D_5  0x38
-#define D_6  0x3A
-#define D_7  0x3C
-#define D_8  0x3E
-
-#define E_1  0x40
-#define E_2  0x42
-#define E_3  0x44
-#define E_4  0x46
-#define E_5  0x48
-#define E_6  0x4A
-#define E_7  0x4C
-#define E_8  0x4E
-
-#define F_1  0x50
-#define F_2  0x52
-#define F_3  0x54
-#define F_4  0x56
-#define F_5  0x58
-#define F_6  0x5A
-#define F_7  0x5C
-#define F_8  0x5E
-
-#define G_1  0x60
-#define G_2  0x62
-#define G_3  0x64
-#define G_4  0x66
-#define G_5  0x68
-#define G_6  0x6A
-#define G_7  0x6C
-#define G_8  0x6E
-
-#define H_1  0x70
-#define H_2  0x72
-#define H_3  0x74
-#define H_4  0x76
-#define H_5  0x78
-#define H_6  0x7A
-#define H_7  0x7C
-#define H_8  0x7E
-
-#define I_1  0x80
-#define I_2  0x82
-#define I_3  0x84
-#define I_4  0x86
-#define I_5  0x88
-#define I_6  0x8A
-#define I_7  0x8C
-#define I_8  0x8E
-
-#define J_1  0x90
-#define J_2  0x92
-#define J_3  0x94
-#define J_4  0x96
-#define J_5  0x98
-#define J_6  0x9A
-#define J_7  0x9C
-#define J_8  0x9E
-
-#define K_1  0xA0
-#define K_2  0xA2
-#define K_3  0xA4
-#define K_4  0xA6
-#define K_5  0xA8
-#define K_6  0xAA
-#define K_7  0xAC
-#define K_8  0xAE
-
-#define L_1  0xB0
-#define L_2  0xB2
-#define L_3  0xB4
-#define L_4  0xB6
-#define L_5  0xB8
-#define L_6  0xBA
-#define L_7  0xBC
-#define L_8  0xBE
-
+void IS31FL3736_update_pwm_buffers(uint8_t addr1, uint8_t addr2);
+void IS31FL3736_update_led_control_registers(uint8_t addr1, uint8_t addr2);
+
+#define A_1 0x00
+#define A_2 0x02
+#define A_3 0x04
+#define A_4 0x06
+#define A_5 0x08
+#define A_6 0x0A
+#define A_7 0x0C
+#define A_8 0x0E
+
+#define B_1 0x10
+#define B_2 0x12
+#define B_3 0x14
+#define B_4 0x16
+#define B_5 0x18
+#define B_6 0x1A
+#define B_7 0x1C
+#define B_8 0x1E
+
+#define C_1 0x20
+#define C_2 0x22
+#define C_3 0x24
+#define C_4 0x26
+#define C_5 0x28
+#define C_6 0x2A
+#define C_7 0x2C
+#define C_8 0x2E
+
+#define D_1 0x30
+#define D_2 0x32
+#define D_3 0x34
+#define D_4 0x36
+#define D_5 0x38
+#define D_6 0x3A
+#define D_7 0x3C
+#define D_8 0x3E
+
+#define E_1 0x40
+#define E_2 0x42
+#define E_3 0x44
+#define E_4 0x46
+#define E_5 0x48
+#define E_6 0x4A
+#define E_7 0x4C
+#define E_8 0x4E
+
+#define F_1 0x50
+#define F_2 0x52
+#define F_3 0x54
+#define F_4 0x56
+#define F_5 0x58
+#define F_6 0x5A
+#define F_7 0x5C
+#define F_8 0x5E
+
+#define G_1 0x60
+#define G_2 0x62
+#define G_3 0x64
+#define G_4 0x66
+#define G_5 0x68
+#define G_6 0x6A
+#define G_7 0x6C
+#define G_8 0x6E
+
+#define H_1 0x70
+#define H_2 0x72
+#define H_3 0x74
+#define H_4 0x76
+#define H_5 0x78
+#define H_6 0x7A
+#define H_7 0x7C
+#define H_8 0x7E
+
+#define I_1 0x80
+#define I_2 0x82
+#define I_3 0x84
+#define I_4 0x86
+#define I_5 0x88
+#define I_6 0x8A
+#define I_7 0x8C
+#define I_8 0x8E
+
+#define J_1 0x90
+#define J_2 0x92
+#define J_3 0x94
+#define J_4 0x96
+#define J_5 0x98
+#define J_6 0x9A
+#define J_7 0x9C
+#define J_8 0x9E
+
+#define K_1 0xA0
+#define K_2 0xA2
+#define K_3 0xA4
+#define K_4 0xA6
+#define K_5 0xA8
+#define K_6 0xAA
+#define K_7 0xAC
+#define K_8 0xAE
+
+#define L_1 0xB0
+#define L_2 0xB2
+#define L_3 0xB4
+#define L_4 0xB6
+#define L_5 0xB8
+#define L_6 0xBA
+#define L_7 0xBC
+#define L_8 0xBE
index 6491049274b5cf0515750ee841fba4cff4906489..4cc46272e24142ecd19bf92712d88a7945e76550 100644 (file)
  */
 
 #ifdef __AVR__
-#include <avr/interrupt.h>
-#include <avr/io.h>
-#include <util/delay.h>
+#    include <avr/interrupt.h>
+#    include <avr/io.h>
+#    include <util/delay.h>
 #else
-#include "wait.h"
+#    include "wait.h"
 #endif
 
 #include <string.h>
 #define ISSI_INTERRUPTMASKREGISTER 0xF0
 #define ISSI_INTERRUPTSTATUSREGISTER 0xF1
 
-#define ISSI_PAGE_LEDCONTROL 0x00 //PG0
-#define ISSI_PAGE_PWM 0x01        //PG1
-#define ISSI_PAGE_AUTOBREATH 0x02 //PG2
-#define ISSI_PAGE_FUNCTION 0x03   //PG3
+#define ISSI_PAGE_LEDCONTROL 0x00  // PG0
+#define ISSI_PAGE_PWM 0x01         // PG1
+#define ISSI_PAGE_AUTOBREATH 0x02  // PG2
+#define ISSI_PAGE_FUNCTION 0x03    // PG3
 
-#define ISSI_REG_CONFIGURATION 0x00 //PG3
-#define ISSI_REG_GLOBALCURRENT 0x01 //PG3
-#define ISSI_REG_RESET 0x11// PG3
-#define ISSI_REG_SWPULLUP 0x0F //PG3
-#define ISSI_REG_CSPULLUP 0x10 //PG3
+#define ISSI_REG_CONFIGURATION 0x00  // PG3
+#define ISSI_REG_GLOBALCURRENT 0x01  // PG3
+#define ISSI_REG_RESET 0x11          // PG3
+#define ISSI_REG_SWPULLUP 0x0F       // PG3
+#define ISSI_REG_CSPULLUP 0x10       // PG3
 
 #ifndef ISSI_TIMEOUT
-  #define ISSI_TIMEOUT 100
+#    define ISSI_TIMEOUT 100
 #endif
 
 #ifndef ISSI_PERSISTENCE
-  #define ISSI_PERSISTENCE 0
+#    define ISSI_PERSISTENCE 0
 #endif
 
 // Transfer buffer for TWITransmitData()
@@ -75,178 +75,161 @@ uint8_t g_twi_transfer_buffer[20];
 // buffers and the transfers in IS31FL3737_write_pwm_buffer() but it's
 // probably not worth the extra complexity.
 uint8_t g_pwm_buffer[DRIVER_COUNT][192];
-bool g_pwm_buffer_update_required = false;
+bool    g_pwm_buffer_update_required = false;
 
-uint8_t g_led_control_registers[DRIVER_COUNT][24] = { { 0 } };
-bool g_led_control_registers_update_required = false;
+uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}};
+bool    g_led_control_registers_update_required   = false;
 
-void IS31FL3737_write_register( uint8_t addr, uint8_t reg, uint8_t data )
-{
+void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
     g_twi_transfer_buffer[0] = reg;
     g_twi_transfer_buffer[1] = data;
 
-  #if ISSI_PERSISTENCE > 0
+#if ISSI_PERSISTENCE > 0
     for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
-      if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0)
-        break;
+        if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
     }
-  #else
+#else
     i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-  #endif
+#endif
 }
 
-void IS31FL3737_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer )
-{
+void IS31FL3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
     // assumes PG1 is already selected
 
     // transmit PWM registers in 12 transfers of 16 bytes
     // g_twi_transfer_buffer[] is 20 bytes
 
     // iterate over the pwm_buffer contents at 16 byte intervals
-    for ( int i = 0; i < 192; i += 16 ) {
+    for (int i = 0; i < 192; i += 16) {
         g_twi_transfer_buffer[0] = i;
         // copy the data from i to i+15
         // device will auto-increment register for data after the first byte
         // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
-        for ( int j = 0; j < 16; j++ ) {
+        for (int j = 0; j < 16; j++) {
             g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
         }
 
-    #if ISSI_PERSISTENCE > 0
-      for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
-        if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0)
-          break;
-      }
-    #else
-      i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
-    #endif
+#if ISSI_PERSISTENCE > 0
+        for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+            if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
+        }
+#else
+        i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
+#endif
     }
 }
 
-void IS31FL3737_init( uint8_t addr )
-{
+void IS31FL3737_init(uint8_t addr) {
     // In order to avoid the LEDs being driven with garbage data
     // in the LED driver's PWM registers, shutdown is enabled last.
     // Set up the mode and other settings, clear the PWM registers,
     // then disable software shutdown.
 
     // Unlock the command register.
-    IS31FL3737_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
+    IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
 
     // Select PG0
-    IS31FL3737_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL );
+    IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
     // Turn off all LEDs.
-    for ( int i = 0x00; i <= 0x17; i++ )
-    {
-        IS31FL3737_write_register( addr, i, 0x00 );
+    for (int i = 0x00; i <= 0x17; i++) {
+        IS31FL3737_write_register(addr, i, 0x00);
     }
 
     // Unlock the command register.
-    IS31FL3737_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
+    IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
 
     // Select PG1
-    IS31FL3737_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM );
+    IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
     // Set PWM on all LEDs to 0
     // No need to setup Breath registers to PWM as that is the default.
-    for ( int i = 0x00; i <= 0xBF; i++ )
-    {
-        IS31FL3737_write_register( addr, i, 0x00 );
+    for (int i = 0x00; i <= 0xBF; i++) {
+        IS31FL3737_write_register(addr, i, 0x00);
     }
 
     // Unlock the command register.
-    IS31FL3737_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
+    IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
 
     // Select PG3
-    IS31FL3737_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION );
+    IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
     // Set global current to maximum.
-    IS31FL3737_write_register( addr, ISSI_REG_GLOBALCURRENT, 0xFF );
+    IS31FL3737_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
     // Disable software shutdown.
-    IS31FL3737_write_register( addr, ISSI_REG_CONFIGURATION, 0x01 );
+    IS31FL3737_write_register(addr, ISSI_REG_CONFIGURATION, 0x01);
 
-    // Wait 10ms to ensure the device has woken up.
-    #ifdef __AVR__
-    _delay_ms( 10 );
-    #else
+// Wait 10ms to ensure the device has woken up.
+#ifdef __AVR__
+    _delay_ms(10);
+#else
     wait_ms(10);
-    #endif
+#endif
 }
 
-void IS31FL3737_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
-{
-    if ( index >= 0 && index < DRIVER_LED_TOTAL ) {
+void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+    if (index >= 0 && index < DRIVER_LED_TOTAL) {
         is31_led led = g_is31_leds[index];
 
         g_pwm_buffer[led.driver][led.r] = red;
         g_pwm_buffer[led.driver][led.g] = green;
         g_pwm_buffer[led.driver][led.b] = blue;
-        g_pwm_buffer_update_required = true;
+        g_pwm_buffer_update_required    = true;
     }
 }
 
-void IS31FL3737_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
-{
-    for ( int i = 0; i < DRIVER_LED_TOTAL; i++ )
-    {
-        IS31FL3737_set_color( i, red, green, blue );
+void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+    for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+        IS31FL3737_set_color(i, red, green, blue);
     }
 }
 
-void IS31FL3737_set_led_control_register( uint8_t index, bool red, bool green, bool blue )
-{
+void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
     is31_led led = g_is31_leds[index];
 
-  uint8_t control_register_r = led.r / 8;
-  uint8_t control_register_g = led.g / 8;
-  uint8_t control_register_b = led.b / 8;
-  uint8_t bit_r = led.r % 8;
-  uint8_t bit_g = led.g % 8;
-  uint8_t bit_b = led.b % 8;
+    uint8_t control_register_r = led.r / 8;
+    uint8_t control_register_g = led.g / 8;
+    uint8_t control_register_b = led.b / 8;
+    uint8_t bit_r              = led.r % 8;
+    uint8_t bit_g              = led.g % 8;
+    uint8_t bit_b              = led.b % 8;
 
-    if ( red ) {
+    if (red) {
         g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
     } else {
         g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
     }
-    if ( green ) {
+    if (green) {
         g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
     } else {
         g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
     }
-    if ( blue ) {
+    if (blue) {
         g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
     } else {
         g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
     }
 
     g_led_control_registers_update_required = true;
-
 }
 
-void IS31FL3737_update_pwm_buffers( uint8_t addr1, uint8_t addr2 )
-{
-    if ( g_pwm_buffer_update_required )
-    {
+void IS31FL3737_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
+    if (g_pwm_buffer_update_required) {
         // Firstly we need to unlock the command register and select PG1
-        IS31FL3737_write_register( addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
-        IS31FL3737_write_register( addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM );
+        IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+        IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
 
-        IS31FL3737_write_pwm_buffer( addr1, g_pwm_buffer[0] );
-        //IS31FL3737_write_pwm_buffer( addr2, g_pwm_buffer[1] );
+        IS31FL3737_write_pwm_buffer(addr1, g_pwm_buffer[0]);
+        // IS31FL3737_write_pwm_buffer( addr2, g_pwm_buffer[1] );
     }
     g_pwm_buffer_update_required = false;
 }
 
-void IS31FL3737_update_led_control_registers( uint8_t addr1, uint8_t addr2 )
-{
-    if ( g_led_control_registers_update_required )
-    {
+void IS31FL3737_update_led_control_registers(uint8_t addr1, uint8_t addr2) {
+    if (g_led_control_registers_update_required) {
         // Firstly we need to unlock the command register and select PG0
-        IS31FL3737_write_register( addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
-        IS31FL3737_write_register( addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL );
-        for ( int i=0; i<24; i++ )
-        {
-            IS31FL3737_write_register(addr1, i, g_led_control_registers[0][i] );
-            //IS31FL3737_write_register(addr2, i, g_led_control_registers[1][i] );
+        IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+        IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+        for (int i = 0; i < 24; i++) {
+            IS31FL3737_write_register(addr1, i, g_led_control_registers[0][i]);
+            // IS31FL3737_write_register(addr2, i, g_led_control_registers[1][i] );
         }
     }
 }
index 69c4b9b538f8e9cc7dc13165276021d97f60753c..2c2fb19641371bbf136bff21ad3267e13e88f24c 100644 (file)
@@ -16,7 +16,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #ifndef IS31FL3737_DRIVER_H
 #define IS31FL3737_DRIVER_H
 
 #include <stdbool.h>
 
 typedef struct is31_led {
-  uint8_t driver:2;
-  uint8_t r;
-  uint8_t g;
-  uint8_t b;
+    uint8_t driver : 2;
+    uint8_t r;
+    uint8_t g;
+    uint8_t b;
 } __attribute__((packed)) is31_led;
 
 extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
 
-void IS31FL3737_init( uint8_t addr );
-void IS31FL3737_write_register( uint8_t addr, uint8_t reg, uint8_t data );
-void IS31FL3737_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer );
+void IS31FL3737_init(uint8_t addr);
+void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void IS31FL3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
 
-void IS31FL3737_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
-void IS31FL3737_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
+void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
 
-void IS31FL3737_set_led_control_register( uint8_t index, bool red, bool green, bool blue );
+void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
 
 // This should not be called from an interrupt
 // (eg. from a timer interrupt).
 // Call this while idle (in between matrix scans).
 // If the buffer is dirty, it will update the driver with the buffer.
-void IS31FL3737_update_pwm_buffers( uint8_t addr1, uint8_t addr2 );
-void IS31FL3737_update_led_control_registers( uint8_t addr1, uint8_t addr2 );
-
-#define A_1   0x00
-#define A_2   0x01
-#define A_3   0x02
-#define A_4   0x03
-#define A_5   0x04
-#define A_6   0x05
-#define A_7   0x08
-#define A_8   0x09
-#define A_9   0x0A
-#define A_10  0x0B
-#define A_11  0x0C
-#define A_12  0x0D
-
-#define B_1   0x10
-#define B_2   0x11
-#define B_3   0x12
-#define B_4   0x13
-#define B_5   0x14
-#define B_6   0x15
-#define B_7   0x18
-#define B_8   0x19
-#define B_9   0x1A
-#define B_10  0x1B
-#define B_11  0x1C
-#define B_12  0x1D
-
-#define C_1   0x20
-#define C_2   0x21
-#define C_3   0x22
-#define C_4   0x23
-#define C_5   0x24
-#define C_6   0x25
-#define C_7   0x28
-#define C_8   0x29
-#define C_9   0x2A
-#define C_10  0x2B
-#define C_11  0x2C
-#define C_12  0x2D
-
-#define D_1   0x30
-#define D_2   0x31
-#define D_3   0x32
-#define D_4   0x33
-#define D_5   0x34
-#define D_6   0x35
-#define D_7   0x38
-#define D_8   0x39
-#define D_9   0x3A
-#define D_10  0x3B
-#define D_11  0x3C
-#define D_12  0x3D
-
-#define E_1   0x40
-#define E_2   0x41
-#define E_3   0x42
-#define E_4   0x43
-#define E_5   0x44
-#define E_6   0x45
-#define E_7   0x48
-#define E_8   0x49
-#define E_9   0x4A
-#define E_10  0x4B
-#define E_11  0x4C
-#define E_12  0x4D
-
-#define F_1   0x50
-#define F_2   0x51
-#define F_3   0x52
-#define F_4   0x53
-#define F_5   0x54
-#define F_6   0x55
-#define F_7   0x58
-#define F_8   0x59
-#define F_9   0x5A
-#define F_10  0x5B
-#define F_11  0x5C
-#define F_12  0x5D
-
-#define G_1   0x60
-#define G_2   0x61
-#define G_3   0x62
-#define G_4   0x63
-#define G_5   0x64
-#define G_6   0x65
-#define G_7   0x68
-#define G_8   0x69
-#define G_9   0x6A
-#define G_10  0x6B
-#define G_11  0x6C
-#define G_12  0x6D
-
-#define H_1   0x70
-#define H_2   0x71
-#define H_3   0x72
-#define H_4   0x73
-#define H_5   0x74
-#define H_6   0x75
-#define H_7   0x78
-#define H_8   0x79
-#define H_9   0x7A
-#define H_10  0x7B
-#define H_11  0x7C
-#define H_12  0x7D
-
-#define I_1   0x80
-#define I_2   0x81
-#define I_3   0x82
-#define I_4   0x83
-#define I_5   0x84
-#define I_6   0x85
-#define I_7   0x88
-#define I_8   0x89
-#define I_9   0x8A
-#define I_10  0x8B
-#define I_11  0x8C
-#define I_12  0x8D
-
-#define J_1   0x90
-#define J_2   0x91
-#define J_3   0x92
-#define J_4   0x93
-#define J_5   0x94
-#define J_6   0x95
-#define J_7   0x98
-#define J_8   0x99
-#define J_9   0x9A
-#define J_10  0x9B
-#define J_11  0x9C
-#define J_12  0x9D
-
-#define K_1   0xA0
-#define K_2   0xA1
-#define K_3   0xA2
-#define K_4   0xA3
-#define K_5   0xA4
-#define K_6   0xA5
-#define K_7   0xA8
-#define K_8   0xA9
-#define K_9   0xAA
-#define K_10  0xAB
-#define K_11  0xAC
-#define K_12  0xAD
-
-#define L_1   0xB0
-#define L_2   0xB1
-#define L_3   0xB2
-#define L_4   0xB3
-#define L_5   0xB4
-#define L_6   0xB5
-#define L_7   0xB8
-#define L_8   0xB9
-#define L_9   0xBA
-#define L_10  0xBB
-#define L_11  0xBC
-#define L_12  0xBD
-
-#endif // IS31FL3737_DRIVER_H
+void IS31FL3737_update_pwm_buffers(uint8_t addr1, uint8_t addr2);
+void IS31FL3737_update_led_control_registers(uint8_t addr1, uint8_t addr2);
+
+#define A_1 0x00
+#define A_2 0x01
+#define A_3 0x02
+#define A_4 0x03
+#define A_5 0x04
+#define A_6 0x05
+#define A_7 0x08
+#define A_8 0x09
+#define A_9 0x0A
+#define A_10 0x0B
+#define A_11 0x0C
+#define A_12 0x0D
+
+#define B_1 0x10
+#define B_2 0x11
+#define B_3 0x12
+#define B_4 0x13
+#define B_5 0x14
+#define B_6 0x15
+#define B_7 0x18
+#define B_8 0x19
+#define B_9 0x1A
+#define B_10 0x1B
+#define B_11 0x1C
+#define B_12 0x1D
+
+#define C_1 0x20
+#define C_2 0x21
+#define C_3 0x22
+#define C_4 0x23
+#define C_5 0x24
+#define C_6 0x25
+#define C_7 0x28
+#define C_8 0x29
+#define C_9 0x2A
+#define C_10 0x2B
+#define C_11 0x2C
+#define C_12 0x2D
+
+#define D_1 0x30
+#define D_2 0x31
+#define D_3 0x32
+#define D_4 0x33
+#define D_5 0x34
+#define D_6 0x35
+#define D_7 0x38
+#define D_8 0x39
+#define D_9 0x3A
+#define D_10 0x3B
+#define D_11 0x3C
+#define D_12 0x3D
+
+#define E_1 0x40
+#define E_2 0x41
+#define E_3 0x42
+#define E_4 0x43
+#define E_5 0x44
+#define E_6 0x45
+#define E_7 0x48
+#define E_8 0x49
+#define E_9 0x4A
+#define E_10 0x4B
+#define E_11 0x4C
+#define E_12 0x4D
+
+#define F_1 0x50
+#define F_2 0x51
+#define F_3 0x52
+#define F_4 0x53
+#define F_5 0x54
+#define F_6 0x55
+#define F_7 0x58
+#define F_8 0x59
+#define F_9 0x5A
+#define F_10 0x5B
+#define F_11 0x5C
+#define F_12 0x5D
+
+#define G_1 0x60
+#define G_2 0x61
+#define G_3 0x62
+#define G_4 0x63
+#define G_5 0x64
+#define G_6 0x65
+#define G_7 0x68
+#define G_8 0x69
+#define G_9 0x6A
+#define G_10 0x6B
+#define G_11 0x6C
+#define G_12 0x6D
+
+#define H_1 0x70
+#define H_2 0x71
+#define H_3 0x72
+#define H_4 0x73
+#define H_5 0x74
+#define H_6 0x75
+#define H_7 0x78
+#define H_8 0x79
+#define H_9 0x7A
+#define H_10 0x7B
+#define H_11 0x7C
+#define H_12 0x7D
+
+#define I_1 0x80
+#define I_2 0x81
+#define I_3 0x82
+#define I_4 0x83
+#define I_5 0x84
+#define I_6 0x85
+#define I_7 0x88
+#define I_8 0x89
+#define I_9 0x8A
+#define I_10 0x8B
+#define I_11 0x8C
+#define I_12 0x8D
+
+#define J_1 0x90
+#define J_2 0x91
+#define J_3 0x92
+#define J_4 0x93
+#define J_5 0x94
+#define J_6 0x95
+#define J_7 0x98
+#define J_8 0x99
+#define J_9 0x9A
+#define J_10 0x9B
+#define J_11 0x9C
+#define J_12 0x9D
+
+#define K_1 0xA0
+#define K_2 0xA1
+#define K_3 0xA2
+#define K_4 0xA3
+#define K_5 0xA4
+#define K_6 0xA5
+#define K_7 0xA8
+#define K_8 0xA9
+#define K_9 0xAA
+#define K_10 0xAB
+#define K_11 0xAC
+#define K_12 0xAD
+
+#define L_1 0xB0
+#define L_2 0xB1
+#define L_3 0xB2
+#define L_4 0xB3
+#define L_5 0xB4
+#define L_6 0xB5
+#define L_7 0xB8
+#define L_8 0xB9
+#define L_9 0xBA
+#define L_10 0xBB
+#define L_11 0xBC
+#define L_12 0xBD
+
+#endif  // IS31FL3737_DRIVER_H
index 8b969057e531b37798d3d094885cf7f384d21307..95c5d2ebf417cb562b4d328fa21fbdbb5a52bc0a 100644 (file)
 #pragma once
 
 #ifdef __AVR__
- #include <avr/io.h>
- #include <avr/pgmspace.h>
+#    include <avr/io.h>
+#    include <avr/pgmspace.h>
 #elif defined(ESP8266)
- #include <pgmspace.h>
+#    include <pgmspace.h>
 #else
- #define PROGMEM
+#    define PROGMEM
 #endif
 
 // Helidox 8x6 font with QMK Firmware Logo
 // Online editor: http://teripom.x0.com/
 
 static const unsigned char font[] PROGMEM = {
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00,
-  0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00,
-  0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00,
-  0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x00,
-  0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00,
-  0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00,
-  0x00, 0x18, 0x3C, 0x18, 0x00, 0x00,
-  0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00,
-  0x00, 0x18, 0x24, 0x18, 0x00, 0x00,
-  0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00,
-  0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00,
-  0x26, 0x29, 0x79, 0x29, 0x26, 0x00,
-  0x40, 0x7F, 0x05, 0x05, 0x07, 0x00,
-  0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00,
-  0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x00,
-  0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00,
-  0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00,
-  0x14, 0x22, 0x7F, 0x22, 0x14, 0x00,
-  0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00,
-  0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00,
-  0x00, 0x66, 0x89, 0x95, 0x6A, 0x00,
-  0x60, 0x60, 0x60, 0x60, 0x60, 0x00,
-  0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00,
-  0x08, 0x04, 0x7E, 0x04, 0x08, 0x00,
-  0x10, 0x20, 0x7E, 0x20, 0x10, 0x00,
-  0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00,
-  0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00,
-  0x1E, 0x10, 0x10, 0x10, 0x10, 0x00,
-  0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00,
-  0x30, 0x38, 0x3E, 0x38, 0x30, 0x00,
-  0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x5F, 0x00, 0x00, 0x00,
-  0x00, 0x07, 0x00, 0x07, 0x00, 0x00,
-  0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00,
-  0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00,
-  0x23, 0x13, 0x08, 0x64, 0x62, 0x00,
-  0x36, 0x49, 0x56, 0x20, 0x50, 0x00,
-  0x00, 0x08, 0x07, 0x03, 0x00, 0x00,
-  0x00, 0x1C, 0x22, 0x41, 0x00, 0x00,
-  0x00, 0x41, 0x22, 0x1C, 0x00, 0x00,
-  0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00,
-  0x08, 0x08, 0x3E, 0x08, 0x08, 0x00,
-  0x00, 0x80, 0x70, 0x30, 0x00, 0x00,
-  0x08, 0x08, 0x08, 0x08, 0x08, 0x00,
-  0x00, 0x00, 0x60, 0x60, 0x00, 0x00,
-  0x20, 0x10, 0x08, 0x04, 0x02, 0x00,
-  0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00,
-  0x00, 0x42, 0x7F, 0x40, 0x00, 0x00,
-  0x72, 0x49, 0x49, 0x49, 0x46, 0x00,
-  0x21, 0x41, 0x49, 0x4D, 0x33, 0x00,
-  0x18, 0x14, 0x12, 0x7F, 0x10, 0x00,
-  0x27, 0x45, 0x45, 0x45, 0x39, 0x00,
-  0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00,
-  0x41, 0x21, 0x11, 0x09, 0x07, 0x00,
-  0x36, 0x49, 0x49, 0x49, 0x36, 0x00,
-  0x46, 0x49, 0x49, 0x29, 0x1E, 0x00,
-  0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
-  0x00, 0x40, 0x34, 0x00, 0x00, 0x00,
-  0x00, 0x08, 0x14, 0x22, 0x41, 0x00,
-  0x14, 0x14, 0x14, 0x14, 0x14, 0x00,
-  0x00, 0x41, 0x22, 0x14, 0x08, 0x00,
-  0x02, 0x01, 0x59, 0x09, 0x06, 0x00,
-  0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00,
-  0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00,
-  0x7F, 0x49, 0x49, 0x49, 0x36, 0x00,
-  0x3E, 0x41, 0x41, 0x41, 0x22, 0x00,
-  0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00,
-  0x7F, 0x49, 0x49, 0x49, 0x41, 0x00,
-  0x7F, 0x09, 0x09, 0x09, 0x01, 0x00,
-  0x3E, 0x41, 0x41, 0x51, 0x73, 0x00,
-  0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00,
-  0x00, 0x41, 0x7F, 0x41, 0x00, 0x00,
-  0x20, 0x40, 0x41, 0x3F, 0x01, 0x00,
-  0x7F, 0x08, 0x14, 0x22, 0x41, 0x00,
-  0x7F, 0x40, 0x40, 0x40, 0x40, 0x00,
-  0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00,
-  0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00,
-  0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00,
-  0x7F, 0x09, 0x09, 0x09, 0x06, 0x00,
-  0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00,
-  0x7F, 0x09, 0x19, 0x29, 0x46, 0x00,
-  0x26, 0x49, 0x49, 0x49, 0x32, 0x00,
-  0x03, 0x01, 0x7F, 0x01, 0x03, 0x00,
-  0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00,
-  0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00,
-  0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00,
-  0x63, 0x14, 0x08, 0x14, 0x63, 0x00,
-  0x03, 0x04, 0x78, 0x04, 0x03, 0x00,
-  0x61, 0x59, 0x49, 0x4D, 0x43, 0x00,
-  0x00, 0x7F, 0x41, 0x41, 0x41, 0x00,
-  0x02, 0x04, 0x08, 0x10, 0x20, 0x00,
-  0x00, 0x41, 0x41, 0x41, 0x7F, 0x00,
-  0x04, 0x02, 0x01, 0x02, 0x04, 0x00,
-  0x40, 0x40, 0x40, 0x40, 0x40, 0x00,
-  0x00, 0x03, 0x07, 0x08, 0x00, 0x00,
-  0x20, 0x54, 0x54, 0x78, 0x40, 0x00,
-  0x7F, 0x28, 0x44, 0x44, 0x38, 0x00,
-  0x38, 0x44, 0x44, 0x44, 0x28, 0x00,
-  0x38, 0x44, 0x44, 0x28, 0x7F, 0x00,
-  0x38, 0x54, 0x54, 0x54, 0x18, 0x00,
-  0x00, 0x08, 0x7E, 0x09, 0x02, 0x00,
-  0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x00,
-  0x7F, 0x08, 0x04, 0x04, 0x78, 0x00,
-  0x00, 0x44, 0x7D, 0x40, 0x00, 0x00,
-  0x20, 0x40, 0x40, 0x3D, 0x00, 0x00,
-  0x7F, 0x10, 0x28, 0x44, 0x00, 0x00,
-  0x00, 0x41, 0x7F, 0x40, 0x00, 0x00,
-  0x7C, 0x04, 0x78, 0x04, 0x78, 0x00,
-  0x7C, 0x08, 0x04, 0x04, 0x78, 0x00,
-  0x38, 0x44, 0x44, 0x44, 0x38, 0x00,
-  0xFC, 0x18, 0x24, 0x24, 0x18, 0x00,
-  0x18, 0x24, 0x24, 0x18, 0xFC, 0x00,
-  0x7C, 0x08, 0x04, 0x04, 0x08, 0x00,
-  0x48, 0x54, 0x54, 0x54, 0x24, 0x00,
-  0x04, 0x04, 0x3F, 0x44, 0x24, 0x00,
-  0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00,
-  0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00,
-  0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00,
-  0x44, 0x28, 0x10, 0x28, 0x44, 0x00,
-  0x4C, 0x90, 0x90, 0x90, 0x7C, 0x00,
-  0x44, 0x64, 0x54, 0x4C, 0x44, 0x00,
-  0x00, 0x08, 0x36, 0x41, 0x00, 0x00,
-  0x00, 0x00, 0x77, 0x00, 0x00, 0x00,
-  0x00, 0x41, 0x36, 0x08, 0x00, 0x00,
-  0x02, 0x01, 0x02, 0x04, 0x02, 0x00,
-  0x3C, 0x26, 0x23, 0x26, 0x3C, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x40, 0x40, 0x40, 0xF0, 0xF8, 0xF8,
-  0xFF, 0x38, 0xFF, 0xF8, 0xF8, 0x3F,
-  0xF8, 0xF8, 0xFF, 0x38, 0xFF, 0xF8,
-  0xF8, 0xF0, 0x40, 0x40, 0x40, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
-  0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00,
-  0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00,
-  0x80, 0xC0, 0xC0, 0x00, 0xC0, 0xC0,
-  0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0,
-  0xC0, 0xC0, 0xC0, 0x00, 0xC0, 0xC0,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0xC0, 0xF0, 0xF8, 0xFC, 0x3E,
-  0x1E, 0x06, 0x01, 0x00, 0x00, 0x00,
-  0x7F, 0x41, 0x41, 0x41, 0x7F, 0x00,
-  0x7F, 0x41, 0x41, 0x41, 0x7F, 0x00,
-  0x00, 0x80, 0xC0, 0xE0, 0x7E, 0x5B,
-  0x4F, 0x5B, 0xFE, 0xC0, 0x00, 0x00,
-  0xC0, 0x00, 0xDC, 0xD7, 0xDE, 0xDE,
-  0xDE, 0xD7, 0xDC, 0x00, 0xC0, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x49, 0x49, 0x49, 0xFF, 0xFF, 0xFF,
-  0xFF, 0xE0, 0xDF, 0xBF, 0xBF, 0x00,
-  0xBF, 0xBF, 0xDF, 0xE0, 0xFF, 0xFF,
-  0xFF, 0xFF, 0x49, 0x49, 0x49, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F,
-  0x60, 0x60, 0xE0, 0xBF, 0x1F, 0x00,
-  0x7F, 0x7F, 0x07, 0x1E, 0x38, 0x1E,
-  0x07, 0x7F, 0x7F, 0x00, 0x7F, 0x7F,
-  0x0E, 0x1F, 0x3B, 0x71, 0x60, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F,
-  0x0C, 0x0C, 0x0C, 0x00, 0x7E, 0x7E,
-  0x00, 0x7F, 0x7E, 0x03, 0x03, 0x00,
-  0x7F, 0x7E, 0x03, 0x03, 0x7E, 0x7E,
-  0x03, 0x03, 0x7F, 0x7E, 0x00, 0x0F,
-  0x3E, 0x70, 0x3C, 0x06, 0x3C, 0x70,
-  0x3E, 0x0F, 0x00, 0x32, 0x7B, 0x49,
-  0x49, 0x3F, 0x7E, 0x00, 0x7F, 0x7E,
-  0x03, 0x03, 0x00, 0x1E, 0x3F, 0x69,
-  0x69, 0x6F, 0x26, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x3C,
-  0x78, 0x70, 0x60, 0x00, 0x00, 0x00,
-  0x7F, 0x41, 0x41, 0x41, 0x7F, 0x00,
-  0x7F, 0x41, 0x41, 0x41, 0x7F, 0x00,
-  0x30, 0x7B, 0x7F, 0x78, 0x30, 0x20,
-  0x20, 0x30, 0x78, 0x7F, 0x3B, 0x00,
-  0x03, 0x00, 0x0F, 0x7F, 0x0F, 0x0F,
-  0x0F, 0x7F, 0x0F, 0x00, 0x03, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x01, 0x01, 0x01, 0x07, 0x0F, 0x0F,
-  0x7F, 0x0F, 0x7F, 0x0F, 0x0F, 0x7E,
-  0x0F, 0x0F, 0x7F, 0x0F, 0x7F, 0x0F,
-  0x0F, 0x07, 0x01, 0x01, 0x01, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x01, 0x01, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00, 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x00, 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00, 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, 0x00, 0x18, 0x3C, 0x18, 0x00, 0x00, 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, 0x00, 0x18, 0x24, 0x18, 0x00, 0x00, 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00, 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00, 0x26, 0x29, 0x79, 0x29, 0x26, 0x00, 0x40, 0x7F, 0x05, 0x05, 0x07, 0x00, 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00, 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x00, 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00, 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00, 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00, 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, 0x00, 0x66, 0x89, 0x95, 0x6A, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00, 0x08, 0x04, 0x7E, 0x04, 0x08, 0x00,
+    0x10, 0x20, 0x7E, 0x20, 0x10, 0x00, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, 0x1E, 0x10, 0x10, 0x10, 0x10, 0x00, 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00, 0x30, 0x38, 0x3E, 0x38, 0x30, 0x00, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x80, 0x70, 0x30, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00,
+    0x72, 0x49, 0x49, 0x49, 0x46, 0x00, 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00, 0x41, 0x21, 0x11, 0x09, 0x07, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x02, 0x01, 0x59, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00,
+    0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x03, 0x07, 0x08, 0x00, 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x00, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00, 0x38, 0x44, 0x44, 0x44, 0x28, 0x00,
+    0x38, 0x44, 0x44, 0x28, 0x7F, 0x00, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x00, 0x08, 0x7E, 0x09, 0x02, 0x00, 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00, 0x20, 0x40, 0x40, 0x3D, 0x00, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00, 0x7C, 0x04, 0x78, 0x04, 0x78, 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0xFC, 0x18, 0x24, 0x24, 0x18, 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00, 0x48, 0x54, 0x54, 0x54, 0x24, 0x00, 0x04, 0x04, 0x3F, 0x44, 0x24, 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00,
+    0x00, 0x41, 0x36, 0x08, 0x00, 0x00, 0x02, 0x01, 0x02, 0x04, 0x02, 0x00, 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0xF0, 0xF8, 0xF8, 0xFF, 0x38, 0xFF, 0xF8, 0xF8, 0x3F, 0xF8, 0xF8, 0xFF, 0x38, 0xFF, 0xF8, 0xF8, 0xF0, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xF8, 0xFC, 0x3E,
+    0x1E, 0x06, 0x01, 0x00, 0x00, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x7F, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x7F, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0x7E, 0x5B, 0x4F, 0x5B, 0xFE, 0xC0, 0x00, 0x00, 0xC0, 0x00, 0xDC, 0xD7, 0xDE, 0xDE, 0xDE, 0xD7, 0xDC, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x49, 0x49, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0xDF, 0xBF, 0xBF, 0x00, 0xBF, 0xBF, 0xDF, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x49, 0x49, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x60, 0x60, 0xE0, 0xBF, 0x1F, 0x00, 0x7F, 0x7F, 0x07, 0x1E, 0x38, 0x1E, 0x07, 0x7F, 0x7F, 0x00, 0x7F, 0x7F, 0x0E, 0x1F, 0x3B, 0x71, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x0C, 0x0C, 0x0C, 0x00, 0x7E, 0x7E, 0x00, 0x7F, 0x7E, 0x03, 0x03, 0x00, 0x7F, 0x7E, 0x03, 0x03, 0x7E, 0x7E, 0x03, 0x03, 0x7F, 0x7E, 0x00, 0x0F,
+    0x3E, 0x70, 0x3C, 0x06, 0x3C, 0x70, 0x3E, 0x0F, 0x00, 0x32, 0x7B, 0x49, 0x49, 0x3F, 0x7E, 0x00, 0x7F, 0x7E, 0x03, 0x03, 0x00, 0x1E, 0x3F, 0x69, 0x69, 0x6F, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x3C, 0x78, 0x70, 0x60, 0x00, 0x00, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x7F, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x7F, 0x00, 0x30, 0x7B, 0x7F, 0x78, 0x30, 0x20, 0x20, 0x30, 0x78, 0x7F, 0x3B, 0x00, 0x03, 0x00, 0x0F, 0x7F, 0x0F, 0x0F, 0x0F, 0x7F, 0x0F, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x07, 0x0F, 0x0F, 0x7F, 0x0F, 0x7F, 0x0F, 0x0F, 0x7E, 0x0F, 0x0F, 0x7F, 0x0F, 0x7F, 0x0F, 0x0F, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 };
index 3dad72addb57acd67fefdd2e483ce511b05d8490..1a1b7299bba10402144502109dd48387cc68ca79 100644 (file)
@@ -23,64 +23,64 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <string.h>
 
 #if defined(__AVR__)
-  #include <avr/io.h>
-  #include <avr/pgmspace.h>
+#    include <avr/io.h>
+#    include <avr/pgmspace.h>
 #elif defined(ESP8266)
-  #include <pgmspace.h>
-#else // defined(ESP8266)
-  #define PROGMEM
-  #define memcpy_P(des, src, len) memcpy(des, src, len)
-#endif // defined(__AVR__)
+#    include <pgmspace.h>
+#else  // defined(ESP8266)
+#    define PROGMEM
+#    define memcpy_P(des, src, len) memcpy(des, src, len)
+#endif  // defined(__AVR__)
 
 // Used commands from spec sheet: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf
 // for SH1106: https://www.velleman.eu/downloads/29/infosheets/sh1106_datasheet.pdf
 
 // Fundamental Commands
-#define CONTRAST                0x81
-#define DISPLAY_ALL_ON          0xA5
-#define DISPLAY_ALL_ON_RESUME   0xA4
-#define NORMAL_DISPLAY          0xA6
-#define DISPLAY_ON              0xAF
-#define DISPLAY_OFF             0xAE
-#define NOP                     0xE3
+#define CONTRAST 0x81
+#define DISPLAY_ALL_ON 0xA5
+#define DISPLAY_ALL_ON_RESUME 0xA4
+#define NORMAL_DISPLAY 0xA6
+#define DISPLAY_ON 0xAF
+#define DISPLAY_OFF 0xAE
+#define NOP 0xE3
 
 // Scrolling Commands
-#define ACTIVATE_SCROLL         0x2F
-#define DEACTIVATE_SCROLL       0x2E
-#define SCROLL_RIGHT            0x26
-#define SCROLL_LEFT             0x27
-#define SCROLL_RIGHT_UP         0x29
-#define SCROLL_LEFT_UP          0x2A
+#define ACTIVATE_SCROLL 0x2F
+#define DEACTIVATE_SCROLL 0x2E
+#define SCROLL_RIGHT 0x26
+#define SCROLL_LEFT 0x27
+#define SCROLL_RIGHT_UP 0x29
+#define SCROLL_LEFT_UP 0x2A
 
 // Addressing Setting Commands
-#define MEMORY_MODE             0x20
-#define COLUMN_ADDR             0x21
-#define PAGE_ADDR               0x22
-#define PAM_SETCOLUMN_LSB       0x00
-#define PAM_SETCOLUMN_MSB       0x10
-#define PAM_PAGE_ADDR           0xB0 // 0xb0 -- 0xb7
+#define MEMORY_MODE 0x20
+#define COLUMN_ADDR 0x21
+#define PAGE_ADDR 0x22
+#define PAM_SETCOLUMN_LSB 0x00
+#define PAM_SETCOLUMN_MSB 0x10
+#define PAM_PAGE_ADDR 0xB0  // 0xb0 -- 0xb7
 
 // Hardware Configuration Commands
-#define DISPLAY_START_LINE      0x40
-#define SEGMENT_REMAP           0xA0
-#define SEGMENT_REMAP_INV       0xA1
-#define MULTIPLEX_RATIO         0xA8
-#define COM_SCAN_INC            0xC0
-#define COM_SCAN_DEC            0xC8
-#define DISPLAY_OFFSET          0xD3
-#define COM_PINS                0xDA
-#define COM_PINS_SEQ            0x02
-#define COM_PINS_ALT            0x12
-#define COM_PINS_SEQ_LR         0x22
-#define COM_PINS_ALT_LR         0x32
+#define DISPLAY_START_LINE 0x40
+#define SEGMENT_REMAP 0xA0
+#define SEGMENT_REMAP_INV 0xA1
+#define MULTIPLEX_RATIO 0xA8
+#define COM_SCAN_INC 0xC0
+#define COM_SCAN_DEC 0xC8
+#define DISPLAY_OFFSET 0xD3
+#define COM_PINS 0xDA
+#define COM_PINS_SEQ 0x02
+#define COM_PINS_ALT 0x12
+#define COM_PINS_SEQ_LR 0x22
+#define COM_PINS_ALT_LR 0x32
 
 // Timing & Driving Commands
-#define DISPLAY_CLOCK           0xD5
-#define PRE_CHARGE_PERIOD       0xD9
-#define VCOM_DETECT             0xDB
+#define DISPLAY_CLOCK 0xD5
+#define PRE_CHARGE_PERIOD 0xD9
+#define VCOM_DETECT 0xDB
 
 // Charge Pump Commands
-#define CHARGE_PUMP             0x8D
+#define CHARGE_PUMP 0x8D
 
 // Misc defines
 #define OLED_TIMEOUT 60000
@@ -91,12 +91,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define I2C_CMD 0x00
 #define I2C_DATA 0x40
 #if defined(__AVR__)
-  // already defined on ARM
-  #define I2C_TIMEOUT 100
-  #define I2C_TRANSMIT_P(data) i2c_transmit_P((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), I2C_TIMEOUT)
-#else // defined(__AVR__)
-  #define I2C_TRANSMIT_P(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), I2C_TIMEOUT)
-#endif // defined(__AVR__)
+// already defined on ARM
+#    define I2C_TIMEOUT 100
+#    define I2C_TRANSMIT_P(data) i2c_transmit_P((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), I2C_TIMEOUT)
+#else  // defined(__AVR__)
+#    define I2C_TRANSMIT_P(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), I2C_TIMEOUT)
+#endif  // defined(__AVR__)
 #define I2C_TRANSMIT(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), I2C_TIMEOUT)
 #define I2C_WRITE_REG(mode, data, size) i2c_writeReg((OLED_DISPLAY_ADDRESS << 1), mode, data, size, I2C_TIMEOUT)
 
@@ -106,19 +106,19 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 // this is so we don't end up with rounding errors with
 // parts of the display unusable or don't get cleared correctly
 // and also allows for drawing & inverting
-uint8_t          oled_buffer[OLED_MATRIX_SIZE];
-uint8_t*         oled_cursor;
-OLED_BLOCK_TYPE  oled_dirty = 0;
-bool             oled_initialized = false;
-bool             oled_active = false;
-bool             oled_scrolling = false;
-uint8_t          oled_rotation = 0;
-uint8_t          oled_rotation_width = 0;
+uint8_t         oled_buffer[OLED_MATRIX_SIZE];
+uint8_t *       oled_cursor;
+OLED_BLOCK_TYPE oled_dirty          = 0;
+bool            oled_initialized    = false;
+bool            oled_active         = false;
+bool            oled_scrolling      = false;
+uint8_t         oled_rotation       = 0;
+uint8_t         oled_rotation_width = 0;
 #if OLED_TIMEOUT > 0
-  uint32_t         oled_timeout;
+uint32_t oled_timeout;
 #endif
 #if OLED_SCROLL_TIMEOUT > 0
-  uint32_t         oled_scroll_timeout;
+uint32_t oled_scroll_timeout;
 #endif
 
 // Internal variables to reduce math instructions
@@ -126,468 +126,445 @@ uint8_t          oled_rotation_width = 0;
 #if defined(__AVR__)
 // identical to i2c_transmit, but for PROGMEM since all initialization is in PROGMEM arrays currently
 // probably should move this into i2c_master...
-static i2c_status_t i2c_transmit_P(uint8_t address, const uint8_tdata, uint16_t length, uint16_t timeout) {
-  i2c_status_t status = i2c_start(address | I2C_WRITE, timeout);
+static i2c_status_t i2c_transmit_P(uint8_t address, const uint8_t *data, uint16_t length, uint16_t timeout) {
+    i2c_status_t status = i2c_start(address | I2C_WRITE, timeout);
 
-  for (uint16_t i = 0; i < length && status >= 0; i++) {
-    status = i2c_write(pgm_read_byte((const char*)data++), timeout);
-    if (status) break;
-  }
+    for (uint16_t i = 0; i < length && status >= 0; i++) {
+        status = i2c_write(pgm_read_byte((const char *)data++), timeout);
+        if (status) break;
+    }
 
-  i2c_stop();
+    i2c_stop();
 
-  return status;
+    return status;
 }
 #endif
 
 // Flips the rendering bits for a character at the current cursor position
-static void InvertCharacter(uint8_t *cursor)
-{
-  const uint8_t *end = cursor + OLED_FONT_WIDTH;
-  while (cursor < end) {
-    *cursor = ~(*cursor);
-    cursor++;
-  }
+static void InvertCharacter(uint8_t *cursor) {
+    const uint8_t *end = cursor + OLED_FONT_WIDTH;
+    while (cursor < end) {
+        *cursor = ~(*cursor);
+        cursor++;
+    }
 }
 
 bool oled_init(uint8_t rotation) {
-  oled_rotation = oled_init_user(rotation);
-  if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
-    oled_rotation_width = OLED_DISPLAY_WIDTH;
-  } else {
-    oled_rotation_width = OLED_DISPLAY_HEIGHT;
-  }
-  i2c_init();
-
-  static const uint8_t PROGMEM display_setup1[] = {
-    I2C_CMD,
-    DISPLAY_OFF,
-    DISPLAY_CLOCK, 0x80,
-    MULTIPLEX_RATIO, OLED_DISPLAY_HEIGHT - 1,
-    DISPLAY_OFFSET, 0x00,
-    DISPLAY_START_LINE | 0x00,
-    CHARGE_PUMP, 0x14,
+    oled_rotation = oled_init_user(rotation);
+    if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
+        oled_rotation_width = OLED_DISPLAY_WIDTH;
+    } else {
+        oled_rotation_width = OLED_DISPLAY_HEIGHT;
+    }
+    i2c_init();
+
+    static const uint8_t PROGMEM display_setup1[] = {
+        I2C_CMD,
+        DISPLAY_OFF,
+        DISPLAY_CLOCK,
+        0x80,
+        MULTIPLEX_RATIO,
+        OLED_DISPLAY_HEIGHT - 1,
+        DISPLAY_OFFSET,
+        0x00,
+        DISPLAY_START_LINE | 0x00,
+        CHARGE_PUMP,
+        0x14,
 #if (OLED_IC != OLED_IC_SH1106)
-    // MEMORY_MODE is unsupported on SH1106 (Page Addressing only)
-    MEMORY_MODE, 0x00, // Horizontal addressing mode
+        // MEMORY_MODE is unsupported on SH1106 (Page Addressing only)
+        MEMORY_MODE,
+        0x00,  // Horizontal addressing mode
 #endif
-  };
-  if (I2C_TRANSMIT_P(display_setup1) != I2C_STATUS_SUCCESS) {
-    print("oled_init cmd set 1 failed\n");
-    return false;
-  }
-
-  if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_180)) {
-    static const uint8_t PROGMEM display_normal[] = {
-      I2C_CMD,
-      SEGMENT_REMAP_INV,
-      COM_SCAN_DEC };
-    if (I2C_TRANSMIT_P(display_normal) != I2C_STATUS_SUCCESS) {
-      print("oled_init cmd normal rotation failed\n");
-      return false;
-    }
-  } else {
-    static const uint8_t PROGMEM display_flipped[] = {
-      I2C_CMD,
-      SEGMENT_REMAP,
-      COM_SCAN_INC };
-    if (I2C_TRANSMIT_P(display_flipped) != I2C_STATUS_SUCCESS) {
-      print("display_flipped failed\n");
-      return false;
-    }
-  }
-
-  static const uint8_t PROGMEM display_setup2[] = {
-    I2C_CMD,
-    COM_PINS, OLED_COM_PINS,
-    CONTRAST, 0x8F,
-    PRE_CHARGE_PERIOD, 0xF1,
-    VCOM_DETECT, 0x40,
-    DISPLAY_ALL_ON_RESUME,
-    NORMAL_DISPLAY,
-    DEACTIVATE_SCROLL,
-    DISPLAY_ON };
-  if (I2C_TRANSMIT_P(display_setup2) != I2C_STATUS_SUCCESS) {
-    print("display_setup2 failed\n");
-    return false;
-  }
+    };
+    if (I2C_TRANSMIT_P(display_setup1) != I2C_STATUS_SUCCESS) {
+        print("oled_init cmd set 1 failed\n");
+        return false;
+    }
+
+    if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_180)) {
+        static const uint8_t PROGMEM display_normal[] = {I2C_CMD, SEGMENT_REMAP_INV, COM_SCAN_DEC};
+        if (I2C_TRANSMIT_P(display_normal) != I2C_STATUS_SUCCESS) {
+            print("oled_init cmd normal rotation failed\n");
+            return false;
+        }
+    } else {
+        static const uint8_t PROGMEM display_flipped[] = {I2C_CMD, SEGMENT_REMAP, COM_SCAN_INC};
+        if (I2C_TRANSMIT_P(display_flipped) != I2C_STATUS_SUCCESS) {
+            print("display_flipped failed\n");
+            return false;
+        }
+    }
+
+    static const uint8_t PROGMEM display_setup2[] = {I2C_CMD, COM_PINS, OLED_COM_PINS, CONTRAST, 0x8F, PRE_CHARGE_PERIOD, 0xF1, VCOM_DETECT, 0x40, DISPLAY_ALL_ON_RESUME, NORMAL_DISPLAY, DEACTIVATE_SCROLL, DISPLAY_ON};
+    if (I2C_TRANSMIT_P(display_setup2) != I2C_STATUS_SUCCESS) {
+        print("display_setup2 failed\n");
+        return false;
+    }
 
 #if OLED_TIMEOUT > 0
-  oled_timeout = timer_read32() + OLED_TIMEOUT;
+    oled_timeout = timer_read32() + OLED_TIMEOUT;
 #endif
 #if OLED_SCROLL_TIMEOUT > 0
-  oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
+    oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
 #endif
 
-  oled_clear();
-  oled_initialized = true;
-  oled_active = true;
-  oled_scrolling = false;
-  return true;
+    oled_clear();
+    oled_initialized = true;
+    oled_active      = true;
+    oled_scrolling   = false;
+    return true;
 }
 
-__attribute__((weak))
-oled_rotation_t oled_init_user(oled_rotation_t rotation) {
-  return rotation;
-}
+__attribute__((weak)) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return rotation; }
 
 void oled_clear(void) {
-  memset(oled_buffer, 0, sizeof(oled_buffer));
-  oled_cursor = &oled_buffer[0];
-  oled_dirty = -1; // -1 will be max value as long as display_dirty is unsigned type
+    memset(oled_buffer, 0, sizeof(oled_buffer));
+    oled_cursor = &oled_buffer[0];
+    oled_dirty  = -1;  // -1 will be max value as long as display_dirty is unsigned type
 }
 
-static void calc_bounds(uint8_t update_start, uint8_t* cmd_array)
-{
-  // Calculate commands to set memory addressing bounds.
-  uint8_t start_page = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_WIDTH;
-  uint8_t start_column = OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_WIDTH;
+static void calc_bounds(uint8_t update_start, uint8_t *cmd_array) {
+    // Calculate commands to set memory addressing bounds.
+    uint8_t start_page   = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_WIDTH;
+    uint8_t start_column = OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_WIDTH;
 #if (OLED_IC == OLED_IC_SH1106)
-  // Commands for Page Addressing Mode. Sets starting page and column; has no end bound.
-  // Column value must be split into high and low nybble and sent as two commands.
-  cmd_array[0] = PAM_PAGE_ADDR | start_page;
-  cmd_array[1] = PAM_SETCOLUMN_LSB | ((OLED_COLUMN_OFFSET + start_column) & 0x0f);
-  cmd_array[2] = PAM_SETCOLUMN_MSB | ((OLED_COLUMN_OFFSET + start_column) >> 4 & 0x0f);
-  cmd_array[3] = NOP;
-  cmd_array[4] = NOP;
-  cmd_array[5] = NOP;
+    // Commands for Page Addressing Mode. Sets starting page and column; has no end bound.
+    // Column value must be split into high and low nybble and sent as two commands.
+    cmd_array[0] = PAM_PAGE_ADDR | start_page;
+    cmd_array[1] = PAM_SETCOLUMN_LSB | ((OLED_COLUMN_OFFSET + start_column) & 0x0f);
+    cmd_array[2] = PAM_SETCOLUMN_MSB | ((OLED_COLUMN_OFFSET + start_column) >> 4 & 0x0f);
+    cmd_array[3] = NOP;
+    cmd_array[4] = NOP;
+    cmd_array[5] = NOP;
 #else
-  // Commands for use in Horizontal Addressing mode.
-  cmd_array[1] = start_column;
-  cmd_array[4] = start_page;
-  cmd_array[2] = (OLED_BLOCK_SIZE + OLED_DISPLAY_WIDTH - 1) % OLED_DISPLAY_WIDTH + cmd_array[1];
-  cmd_array[5] = (OLED_BLOCK_SIZE + OLED_DISPLAY_WIDTH - 1) / OLED_DISPLAY_WIDTH - 1;
+    // Commands for use in Horizontal Addressing mode.
+    cmd_array[1] = start_column;
+    cmd_array[4] = start_page;
+    cmd_array[2] = (OLED_BLOCK_SIZE + OLED_DISPLAY_WIDTH - 1) % OLED_DISPLAY_WIDTH + cmd_array[1];
+    cmd_array[5] = (OLED_BLOCK_SIZE + OLED_DISPLAY_WIDTH - 1) / OLED_DISPLAY_WIDTH - 1;
 #endif
 }
 
-static void calc_bounds_90(uint8_t update_start, uint8_t* cmd_array)
-{
-  cmd_array[1] = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_HEIGHT * 8;
-  cmd_array[4] = OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_HEIGHT;
-  cmd_array[2] = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) / OLED_DISPLAY_HEIGHT * 8 - 1 + cmd_array[1];;
-  cmd_array[5] = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) % OLED_DISPLAY_HEIGHT / 8;
+static void calc_bounds_90(uint8_t update_start, uint8_t *cmd_array) {
+    cmd_array[1] = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_HEIGHT * 8;
+    cmd_array[4] = OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_HEIGHT;
+    cmd_array[2] = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) / OLED_DISPLAY_HEIGHT * 8 - 1 + cmd_array[1];
+    ;
+    cmd_array[5] = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) % OLED_DISPLAY_HEIGHT / 8;
 }
 
-uint8_t crot(uint8_t a, int8_t n)
-{
-  const uint8_t mask = 0x7;
-  n &= mask;
-  return a << n | a >> (-n & mask);
+uint8_t crot(uint8_t a, int8_t n) {
+    const uint8_t mask = 0x7;
+    n &= mask;
+    return a << n | a >> (-n & mask);
 }
 
-static void rotate_90(const uint8_t* src, uint8_t* dest)
-{
-  for (uint8_t i = 0, shift = 7; i < 8; ++i, --shift) {
-    uint8_t selector = (1 << i);
-    for (uint8_t j = 0; j < 8; ++j) {
-      dest[i] |= crot(src[j] & selector, shift - (int8_t)j);
+static void rotate_90(const uint8_t *src, uint8_t *dest) {
+    for (uint8_t i = 0, shift = 7; i < 8; ++i, --shift) {
+        uint8_t selector = (1 << i);
+        for (uint8_t j = 0; j < 8; ++j) {
+            dest[i] |= crot(src[j] & selector, shift - (int8_t)j);
+        }
     }
-  }
 }
 
 void oled_render(void) {
-  // Do we have work to do?
-  if (!oled_dirty || oled_scrolling) {
-    return;
-  }
-
-  // Find first dirty block
-  uint8_t update_start = 0;
-  while (!(oled_dirty & (1 << update_start))) { ++update_start; }
-
-  // Set column & page position
-  static uint8_t display_start[] = {
-    I2C_CMD,
-    COLUMN_ADDR, 0, OLED_DISPLAY_WIDTH - 1,
-    PAGE_ADDR, 0, OLED_DISPLAY_HEIGHT / 8 - 1 };
-  if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
-    calc_bounds(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start
-  } else {
-    calc_bounds_90(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start
-  }
-
-  // Send column & page position
-  if (I2C_TRANSMIT(display_start) != I2C_STATUS_SUCCESS) {
-    print("oled_render offset command failed\n");
-    return;
-  }
-
-  if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
-    // Send render data chunk as is
-    if (I2C_WRITE_REG(I2C_DATA, &oled_buffer[OLED_BLOCK_SIZE * update_start], OLED_BLOCK_SIZE) != I2C_STATUS_SUCCESS) {
-      print("oled_render data failed\n");
-      return;
-    }
-  } else {
-    // Rotate the render chunks
-    const static uint8_t source_map[] = OLED_SOURCE_MAP;
-    const static uint8_t target_map[] = OLED_TARGET_MAP;
-
-    static uint8_t temp_buffer[OLED_BLOCK_SIZE];
-    memset(temp_buffer, 0, sizeof(temp_buffer));
-    for(uint8_t i = 0; i < sizeof(source_map); ++i) {
-      rotate_90(&oled_buffer[OLED_BLOCK_SIZE * update_start + source_map[i]], &temp_buffer[target_map[i]]);
-    }
-
-    // Send render data chunk after rotating
-    if (I2C_WRITE_REG(I2C_DATA, &temp_buffer[0], OLED_BLOCK_SIZE) != I2C_STATUS_SUCCESS) {
-      print("oled_render90 data failed\n");
-      return;
-    }
-  }
-
-  // Turn on display if it is off
-  oled_on();
-
-  // Clear dirty flag
-  oled_dirty &= ~(1 << update_start);
+    // Do we have work to do?
+    if (!oled_dirty || oled_scrolling) {
+        return;
+    }
+
+    // Find first dirty block
+    uint8_t update_start = 0;
+    while (!(oled_dirty & (1 << update_start))) {
+        ++update_start;
+    }
+
+    // Set column & page position
+    static uint8_t display_start[] = {I2C_CMD, COLUMN_ADDR, 0, OLED_DISPLAY_WIDTH - 1, PAGE_ADDR, 0, OLED_DISPLAY_HEIGHT / 8 - 1};
+    if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
+        calc_bounds(update_start, &display_start[1]);  // Offset from I2C_CMD byte at the start
+    } else {
+        calc_bounds_90(update_start, &display_start[1]);  // Offset from I2C_CMD byte at the start
+    }
+
+    // Send column & page position
+    if (I2C_TRANSMIT(display_start) != I2C_STATUS_SUCCESS) {
+        print("oled_render offset command failed\n");
+        return;
+    }
+
+    if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
+        // Send render data chunk as is
+        if (I2C_WRITE_REG(I2C_DATA, &oled_buffer[OLED_BLOCK_SIZE * update_start], OLED_BLOCK_SIZE) != I2C_STATUS_SUCCESS) {
+            print("oled_render data failed\n");
+            return;
+        }
+    } else {
+        // Rotate the render chunks
+        const static uint8_t source_map[] = OLED_SOURCE_MAP;
+        const static uint8_t target_map[] = OLED_TARGET_MAP;
+
+        static uint8_t temp_buffer[OLED_BLOCK_SIZE];
+        memset(temp_buffer, 0, sizeof(temp_buffer));
+        for (uint8_t i = 0; i < sizeof(source_map); ++i) {
+            rotate_90(&oled_buffer[OLED_BLOCK_SIZE * update_start + source_map[i]], &temp_buffer[target_map[i]]);
+        }
+
+        // Send render data chunk after rotating
+        if (I2C_WRITE_REG(I2C_DATA, &temp_buffer[0], OLED_BLOCK_SIZE) != I2C_STATUS_SUCCESS) {
+            print("oled_render90 data failed\n");
+            return;
+        }
+    }
+
+    // Turn on display if it is off
+    oled_on();
+
+    // Clear dirty flag
+    oled_dirty &= ~(1 << update_start);
 }
 
 void oled_set_cursor(uint8_t col, uint8_t line) {
-  uint16_t index = line * oled_rotation_width + col * OLED_FONT_WIDTH;
+    uint16_t index = line * oled_rotation_width + col * OLED_FONT_WIDTH;
 
-  // Out of bounds?
-  if (index >= OLED_MATRIX_SIZE) {
-    index = 0;
-  }
+    // Out of bounds?
+    if (index >= OLED_MATRIX_SIZE) {
+        index = 0;
+    }
 
-  oled_cursor = &oled_buffer[index];
+    oled_cursor = &oled_buffer[index];
 }
 
 void oled_advance_page(bool clearPageRemainder) {
-  uint16_t index = oled_cursor - &oled_buffer[0];
-  uint8_t remaining = oled_rotation_width - (index % oled_rotation_width);
-
-  if (clearPageRemainder) {
-    // Remaining Char count
-    remaining = remaining / OLED_FONT_WIDTH;
-
-    // Write empty character until next line
-    while (remaining--)
-      oled_write_char(' ', false);
-  } else {
-    // Next page index out of bounds?
-    if (index + remaining >= OLED_MATRIX_SIZE) {
-      index = 0;
-      remaining = 0;
+    uint16_t index     = oled_cursor - &oled_buffer[0];
+    uint8_t  remaining = oled_rotation_width - (index % oled_rotation_width);
+
+    if (clearPageRemainder) {
+        // Remaining Char count
+        remaining = remaining / OLED_FONT_WIDTH;
+
+        // Write empty character until next line
+        while (remaining--) oled_write_char(' ', false);
+    } else {
+        // Next page index out of bounds?
+        if (index + remaining >= OLED_MATRIX_SIZE) {
+            index     = 0;
+            remaining = 0;
+        }
+
+        oled_cursor = &oled_buffer[index + remaining];
     }
-
-    oled_cursor = &oled_buffer[index + remaining];
-  }
 }
 
 void oled_advance_char(void) {
-  uint16_t nextIndex = oled_cursor - &oled_buffer[0] + OLED_FONT_WIDTH;
-  uint8_t remainingSpace = oled_rotation_width - (nextIndex % oled_rotation_width);
+    uint16_t nextIndex      = oled_cursor - &oled_buffer[0] + OLED_FONT_WIDTH;
+    uint8_t  remainingSpace = oled_rotation_width - (nextIndex % oled_rotation_width);
 
-  // Do we have enough space on the current line for the next character
-  if (remainingSpace < OLED_FONT_WIDTH) {
-    nextIndex += remainingSpace;
-  }
+    // Do we have enough space on the current line for the next character
+    if (remainingSpace < OLED_FONT_WIDTH) {
+        nextIndex += remainingSpace;
+    }
 
-  // Did we go out of bounds
-  if (nextIndex >= OLED_MATRIX_SIZE) {
-    nextIndex = 0;
-  }
+    // Did we go out of bounds
+    if (nextIndex >= OLED_MATRIX_SIZE) {
+        nextIndex = 0;
+    }
 
-  // Update cursor position
-  oled_cursor = &oled_buffer[nextIndex];
+    // Update cursor position
+    oled_cursor = &oled_buffer[nextIndex];
 }
 
 // Main handler that writes character data to the display buffer
 void oled_write_char(const char data, bool invert) {
-  // Advance to the next line if newline
-  if (data == '\n') {
-    // Old source wrote ' ' until end of line...
-    oled_advance_page(true);
-    return;
-  }
-
-  if (data == '\r') {
-    oled_advance_page(false);
-    return;
-  }
-
-  // copy the current render buffer to check for dirty after
-  static uint8_t oled_temp_buffer[OLED_FONT_WIDTH];
-  memcpy(&oled_temp_buffer, oled_cursor, OLED_FONT_WIDTH);
-
-  // set the reder buffer data
-  uint8_t cast_data = (uint8_t)data; // font based on unsigned type for index
-  if (cast_data < OLED_FONT_START || cast_data > OLED_FONT_END) {
-    memset(oled_cursor, 0x00, OLED_FONT_WIDTH);
-  } else {
-    const uint8_t *glyph = &font[(cast_data - OLED_FONT_START) * OLED_FONT_WIDTH];
-    memcpy_P(oled_cursor, glyph, OLED_FONT_WIDTH);
-  }
-
-  // Invert if needed
-  if (invert) {
-    InvertCharacter(oled_cursor);
-  }
-
-  // Dirty check
-  if (memcmp(&oled_temp_buffer, oled_cursor, OLED_FONT_WIDTH)) {
-    uint16_t index = oled_cursor - &oled_buffer[0];
-    oled_dirty |= (1 << (index / OLED_BLOCK_SIZE));
-    // Edgecase check if the written data spans the 2 chunks
-    oled_dirty |= (1 << ((index + OLED_FONT_WIDTH) / OLED_BLOCK_SIZE));
-  }
-
-  // Finally move to the next char
-  oled_advance_char();
+    // Advance to the next line if newline
+    if (data == '\n') {
+        // Old source wrote ' ' until end of line...
+        oled_advance_page(true);
+        return;
+    }
+
+    if (data == '\r') {
+        oled_advance_page(false);
+        return;
+    }
+
+    // copy the current render buffer to check for dirty after
+    static uint8_t oled_temp_buffer[OLED_FONT_WIDTH];
+    memcpy(&oled_temp_buffer, oled_cursor, OLED_FONT_WIDTH);
+
+    // set the reder buffer data
+    uint8_t cast_data = (uint8_t)data;  // font based on unsigned type for index
+    if (cast_data < OLED_FONT_START || cast_data > OLED_FONT_END) {
+        memset(oled_cursor, 0x00, OLED_FONT_WIDTH);
+    } else {
+        const uint8_t *glyph = &font[(cast_data - OLED_FONT_START) * OLED_FONT_WIDTH];
+        memcpy_P(oled_cursor, glyph, OLED_FONT_WIDTH);
+    }
+
+    // Invert if needed
+    if (invert) {
+        InvertCharacter(oled_cursor);
+    }
+
+    // Dirty check
+    if (memcmp(&oled_temp_buffer, oled_cursor, OLED_FONT_WIDTH)) {
+        uint16_t index = oled_cursor - &oled_buffer[0];
+        oled_dirty |= (1 << (index / OLED_BLOCK_SIZE));
+        // Edgecase check if the written data spans the 2 chunks
+        oled_dirty |= (1 << ((index + OLED_FONT_WIDTH) / OLED_BLOCK_SIZE));
+    }
+
+    // Finally move to the next char
+    oled_advance_char();
 }
 
 void oled_write(const char *data, bool invert) {
-  const char *end = data + strlen(data);
-  while (data < end) {
-    oled_write_char(*data, invert);
-    data++;
-  }
+    const char *end = data + strlen(data);
+    while (data < end) {
+        oled_write_char(*data, invert);
+        data++;
+    }
 }
 
 void oled_write_ln(const char *data, bool invert) {
-  oled_write(data, invert);
-  oled_advance_page(true);
+    oled_write(data, invert);
+    oled_advance_page(true);
 }
 
 #if defined(__AVR__)
 void oled_write_P(const char *data, bool invert) {
-  uint8_t c = pgm_read_byte(data);
-  while (c != 0) {
-    oled_write_char(c, invert);
-    c = pgm_read_byte(++data);
-  }
+    uint8_t c = pgm_read_byte(data);
+    while (c != 0) {
+        oled_write_char(c, invert);
+        c = pgm_read_byte(++data);
+    }
 }
 
 void oled_write_ln_P(const char *data, bool invert) {
-  oled_write_P(data, invert);
-  oled_advance_page(true);
+    oled_write_P(data, invert);
+    oled_advance_page(true);
 }
-#endif // defined(__AVR__)
+#endif  // defined(__AVR__)
 
 bool oled_on(void) {
 #if OLED_TIMEOUT > 0
-  oled_timeout = timer_read32() + OLED_TIMEOUT;
+    oled_timeout = timer_read32() + OLED_TIMEOUT;
 #endif
 
-  static const uint8_t PROGMEM display_on[] = { I2C_CMD, DISPLAY_ON };
-  if (!oled_active) {
-    if (I2C_TRANSMIT_P(display_on) != I2C_STATUS_SUCCESS) {
-      print("oled_on cmd failed\n");
-      return oled_active;
+    static const uint8_t PROGMEM display_on[] = {I2C_CMD, DISPLAY_ON};
+    if (!oled_active) {
+        if (I2C_TRANSMIT_P(display_on) != I2C_STATUS_SUCCESS) {
+            print("oled_on cmd failed\n");
+            return oled_active;
+        }
+        oled_active = true;
     }
-    oled_active = true;
-  }
-  return oled_active;
+    return oled_active;
 }
 
 bool oled_off(void) {
-  static const uint8_t PROGMEM display_off[] = { I2C_CMD, DISPLAY_OFF };
-  if (oled_active) {
-    if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) {
-      print("oled_off cmd failed\n");
-      return oled_active;
-    }
-    oled_active = false;
-  }
-  return !oled_active;
+    static const uint8_t PROGMEM display_off[] = {I2C_CMD, DISPLAY_OFF};
+    if (oled_active) {
+        if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) {
+            print("oled_off cmd failed\n");
+            return oled_active;
+        }
+        oled_active = false;
+    }
+    return !oled_active;
 }
 
 bool oled_scroll_right(void) {
-  // Dont enable scrolling if we need to update the display
-  // This prevents scrolling of bad data from starting the scroll too early after init
-  if (!oled_dirty && !oled_scrolling) {
-    static const uint8_t PROGMEM display_scroll_right[] = {
-      I2C_CMD, SCROLL_RIGHT, 0x00, 0x00, 0x00, 0x0F, 0x00, 0xFF, ACTIVATE_SCROLL };
-    if (I2C_TRANSMIT_P(display_scroll_right) != I2C_STATUS_SUCCESS) {
-      print("oled_scroll_right cmd failed\n");
-      return oled_scrolling;
-    }
-    oled_scrolling = true;
-  }
-  return oled_scrolling;
+    // Dont enable scrolling if we need to update the display
+    // This prevents scrolling of bad data from starting the scroll too early after init
+    if (!oled_dirty && !oled_scrolling) {
+        static const uint8_t PROGMEM display_scroll_right[] = {I2C_CMD, SCROLL_RIGHT, 0x00, 0x00, 0x00, 0x0F, 0x00, 0xFF, ACTIVATE_SCROLL};
+        if (I2C_TRANSMIT_P(display_scroll_right) != I2C_STATUS_SUCCESS) {
+            print("oled_scroll_right cmd failed\n");
+            return oled_scrolling;
+        }
+        oled_scrolling = true;
+    }
+    return oled_scrolling;
 }
 
 bool oled_scroll_left(void) {
-  // Dont enable scrolling if we need to update the display
-  // This prevents scrolling of bad data from starting the scroll too early after init
-  if (!oled_dirty && !oled_scrolling) {
-    static const uint8_t PROGMEM display_scroll_left[] = {
-      I2C_CMD, SCROLL_LEFT, 0x00, 0x00, 0x00, 0x0F, 0x00, 0xFF, ACTIVATE_SCROLL };
-    if (I2C_TRANSMIT_P(display_scroll_left) != I2C_STATUS_SUCCESS) {
-      print("oled_scroll_left cmd failed\n");
-      return oled_scrolling;
-    }
-    oled_scrolling = true;
-  }
-  return oled_scrolling;
+    // Dont enable scrolling if we need to update the display
+    // This prevents scrolling of bad data from starting the scroll too early after init
+    if (!oled_dirty && !oled_scrolling) {
+        static const uint8_t PROGMEM display_scroll_left[] = {I2C_CMD, SCROLL_LEFT, 0x00, 0x00, 0x00, 0x0F, 0x00, 0xFF, ACTIVATE_SCROLL};
+        if (I2C_TRANSMIT_P(display_scroll_left) != I2C_STATUS_SUCCESS) {
+            print("oled_scroll_left cmd failed\n");
+            return oled_scrolling;
+        }
+        oled_scrolling = true;
+    }
+    return oled_scrolling;
 }
 
 bool oled_scroll_off(void) {
-  if (oled_scrolling) {
-    static const uint8_t PROGMEM display_scroll_off[] = { I2C_CMD, DEACTIVATE_SCROLL };
-    if (I2C_TRANSMIT_P(display_scroll_off) != I2C_STATUS_SUCCESS) {
-      print("oled_scroll_off cmd failed\n");
-      return oled_scrolling;
-    }
-    oled_scrolling = false;
-    oled_dirty = -1;
-  }
-  return !oled_scrolling;
+    if (oled_scrolling) {
+        static const uint8_t PROGMEM display_scroll_off[] = {I2C_CMD, DEACTIVATE_SCROLL};
+        if (I2C_TRANSMIT_P(display_scroll_off) != I2C_STATUS_SUCCESS) {
+            print("oled_scroll_off cmd failed\n");
+            return oled_scrolling;
+        }
+        oled_scrolling = false;
+        oled_dirty     = -1;
+    }
+    return !oled_scrolling;
 }
 
 uint8_t oled_max_chars(void) {
-  if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
-    return OLED_DISPLAY_WIDTH / OLED_FONT_WIDTH;
-  }
-  return OLED_DISPLAY_HEIGHT / OLED_FONT_WIDTH;
+    if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
+        return OLED_DISPLAY_WIDTH / OLED_FONT_WIDTH;
+    }
+    return OLED_DISPLAY_HEIGHT / OLED_FONT_WIDTH;
 }
 
 uint8_t oled_max_lines(void) {
-  if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
-    return OLED_DISPLAY_HEIGHT / OLED_FONT_HEIGHT;
-  }
-  return OLED_DISPLAY_WIDTH / OLED_FONT_HEIGHT;
+    if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
+        return OLED_DISPLAY_HEIGHT / OLED_FONT_HEIGHT;
+    }
+    return OLED_DISPLAY_WIDTH / OLED_FONT_HEIGHT;
 }
 
 void oled_task(void) {
-  if (!oled_initialized) {
-    return;
-  }
+    if (!oled_initialized) {
+        return;
+    }
 
-  oled_set_cursor(0, 0);
+    oled_set_cursor(0, 0);
 
-  oled_task_user();
+    oled_task_user();
 
 #if OLED_SCROLL_TIMEOUT > 0
-  if (oled_dirty && oled_scrolling) {
-    oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
-    oled_scroll_off();
-  }
+    if (oled_dirty && oled_scrolling) {
+        oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
+        oled_scroll_off();
+    }
 #endif
 
-  // Smart render system, no need to check for dirty
-  oled_render();
+    // Smart render system, no need to check for dirty
+    oled_render();
 
-  // Display timeout check
+    // Display timeout check
 #if OLED_TIMEOUT > 0
-  if (oled_active && timer_expired32(timer_read32(), oled_timeout)) {
-    oled_off();
-  }
+    if (oled_active && timer_expired32(timer_read32(), oled_timeout)) {
+        oled_off();
+    }
 #endif
 
 #if OLED_SCROLL_TIMEOUT > 0
-  if (!oled_scrolling && timer_expired32(timer_read32(), oled_scroll_timeout)) {
-#ifdef OLED_SCROLL_TIMEOUT_RIGHT
-    oled_scroll_right();
-#else
-    oled_scroll_left();
-#endif
-  }
+    if (!oled_scrolling && timer_expired32(timer_read32(), oled_scroll_timeout)) {
+#    ifdef OLED_SCROLL_TIMEOUT_RIGHT
+        oled_scroll_right();
+#    else
+        oled_scroll_left();
+#    endif
+    }
 #endif
 }
 
-__attribute__((weak))
-void oled_task_user(void) {
-}
+__attribute__((weak)) void oled_task_user(void) {}
index 4f6254c98cea0646434795e30b50d382b4bbf89b..ac8a1c7651d34021665a5e6a64d0ce76ccdfc782 100644 (file)
@@ -21,129 +21,133 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // an enumeration of the chips this driver supports
 #define OLED_IC_SSD1306 0
-#define OLED_IC_SH1106  1
+#define OLED_IC_SH1106 1
 
 #if defined(OLED_DISPLAY_CUSTOM)
-  // Expected user to implement the necessary defines
+// Expected user to implement the necessary defines
 #elif defined(OLED_DISPLAY_128X64)
-  // Double height 128x64
-#ifndef OLED_DISPLAY_WIDTH
-  #define OLED_DISPLAY_WIDTH 128
-#endif
-#ifndef OLED_DISPLAY_HEIGHT
-  #define OLED_DISPLAY_HEIGHT 64
-#endif
-#ifndef OLED_MATRIX_SIZE
-  #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 1024 (compile time mathed)
-#endif
-#ifndef OLED_BLOCK_TYPE
-  #define OLED_BLOCK_TYPE uint16_t
-#endif
-#ifndef OLED_BLOCK_COUNT
-  #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 32 (compile time mathed)
-#endif
-#ifndef OLED_BLOCK_SIZE
-  #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed)
-#endif
-#ifndef OLED_COM_PINS
-  #define OLED_COM_PINS COM_PINS_ALT
-#endif
-
-  // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays
-  // The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode
-#ifndef OLED_SOURCE_MAP
-  #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
-#endif
-#ifndef OLED_TARGET_MAP
-  #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 }
-#endif
-  // If OLED_BLOCK_TYPE is uint32_t, these tables would look like:
-  // #define OLED_SOURCE_MAP { 32, 40, 48, 56 }
-  // #define OLED_TARGET_MAP { 24, 16, 8, 0 }
-  // If OLED_BLOCK_TYPE is uint16_t, these tables would look like:
-  // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
-  // #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 }
-  // If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
-  // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 }
-  // #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 }
-#else // defined(OLED_DISPLAY_128X64)
-  // Default 128x32
-#ifndef OLED_DISPLAY_WIDTH
-  #define OLED_DISPLAY_WIDTH 128
-#endif
-#ifndef OLED_DISPLAY_HEIGHT
-  #define OLED_DISPLAY_HEIGHT 32
-#endif
-#ifndef OLED_MATRIX_SIZE
-  #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 512 (compile time mathed)
-#endif
-#ifndef OLED_BLOCK_TYPE
-  #define OLED_BLOCK_TYPE uint16_t // Type to use for segmenting the oled display for smart rendering, use unsigned types only
-#endif
-#ifndef OLED_BLOCK_COUNT
-  #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 16 (compile time mathed)
-#endif
-#ifndef OLED_BLOCK_SIZE
-  #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed)
-#endif
-#ifndef OLED_COM_PINS
-  #define OLED_COM_PINS COM_PINS_SEQ
-#endif
-
-  // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays
-  // The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode
-#ifndef OLED_SOURCE_MAP
-  #define OLED_SOURCE_MAP { 0, 8, 16, 24 }
-#endif
-#ifndef OLED_TARGET_MAP
-  #define OLED_TARGET_MAP { 24, 16, 8, 0 }
-#endif
-  // If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
-  // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
-  // #define OLED_TARGET_MAP { 48, 32, 16, 0, 56, 40, 24, 8 }
-#endif // defined(OLED_DISPLAY_CUSTOM)
+// Double height 128x64
+#    ifndef OLED_DISPLAY_WIDTH
+#        define OLED_DISPLAY_WIDTH 128
+#    endif
+#    ifndef OLED_DISPLAY_HEIGHT
+#        define OLED_DISPLAY_HEIGHT 64
+#    endif
+#    ifndef OLED_MATRIX_SIZE
+#        define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH)  // 1024 (compile time mathed)
+#    endif
+#    ifndef OLED_BLOCK_TYPE
+#        define OLED_BLOCK_TYPE uint16_t
+#    endif
+#    ifndef OLED_BLOCK_COUNT
+#        define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8)  // 32 (compile time mathed)
+#    endif
+#    ifndef OLED_BLOCK_SIZE
+#        define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT)  // 32 (compile time mathed)
+#    endif
+#    ifndef OLED_COM_PINS
+#        define OLED_COM_PINS COM_PINS_ALT
+#    endif
+
+// For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays
+// The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode
+#    ifndef OLED_SOURCE_MAP
+#        define OLED_SOURCE_MAP \
+            { 0, 8, 16, 24, 32, 40, 48, 56 }
+#    endif
+#    ifndef OLED_TARGET_MAP
+#        define OLED_TARGET_MAP \
+            { 56, 48, 40, 32, 24, 16, 8, 0 }
+#    endif
+// If OLED_BLOCK_TYPE is uint32_t, these tables would look like:
+// #define OLED_SOURCE_MAP { 32, 40, 48, 56 }
+// #define OLED_TARGET_MAP { 24, 16, 8, 0 }
+// If OLED_BLOCK_TYPE is uint16_t, these tables would look like:
+// #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
+// #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 }
+// If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
+// #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 }
+// #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 }
+#else  // defined(OLED_DISPLAY_128X64)
+// Default 128x32
+#    ifndef OLED_DISPLAY_WIDTH
+#        define OLED_DISPLAY_WIDTH 128
+#    endif
+#    ifndef OLED_DISPLAY_HEIGHT
+#        define OLED_DISPLAY_HEIGHT 32
+#    endif
+#    ifndef OLED_MATRIX_SIZE
+#        define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH)  // 512 (compile time mathed)
+#    endif
+#    ifndef OLED_BLOCK_TYPE
+#        define OLED_BLOCK_TYPE uint16_t  // Type to use for segmenting the oled display for smart rendering, use unsigned types only
+#    endif
+#    ifndef OLED_BLOCK_COUNT
+#        define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8)  // 16 (compile time mathed)
+#    endif
+#    ifndef OLED_BLOCK_SIZE
+#        define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT)  // 32 (compile time mathed)
+#    endif
+#    ifndef OLED_COM_PINS
+#        define OLED_COM_PINS COM_PINS_SEQ
+#    endif
+
+// For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays
+// The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode
+#    ifndef OLED_SOURCE_MAP
+#        define OLED_SOURCE_MAP \
+            { 0, 8, 16, 24 }
+#    endif
+#    ifndef OLED_TARGET_MAP
+#        define OLED_TARGET_MAP \
+            { 24, 16, 8, 0 }
+#    endif
+// If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
+// #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
+// #define OLED_TARGET_MAP { 48, 32, 16, 0, 56, 40, 24, 8 }
+#endif  // defined(OLED_DISPLAY_CUSTOM)
 
 #if !defined(OLED_IC)
-  #define OLED_IC OLED_IC_SSD1306
+#    define OLED_IC OLED_IC_SSD1306
 #endif
 
 // the column address corresponding to the first column in the display hardware
 #if !defined(OLED_COLUMN_OFFSET)
-  #define OLED_COLUMN_OFFSET 0
+#    define OLED_COLUMN_OFFSET 0
 #endif
 
 // Address to use for the i2c oled communication
 #if !defined(OLED_DISPLAY_ADDRESS)
-  #define OLED_DISPLAY_ADDRESS 0x3C
+#    define OLED_DISPLAY_ADDRESS 0x3C
 #endif
 
 // Custom font file to use
 #if !defined(OLED_FONT_H)
-  #define OLED_FONT_H "glcdfont.c"
+#    define OLED_FONT_H "glcdfont.c"
 #endif
 // unsigned char value of the first character in the font file
 #if !defined(OLED_FONT_START)
-  #define OLED_FONT_START 0
+#    define OLED_FONT_START 0
 #endif
 // unsigned char value of the last character in the font file
 #if !defined(OLED_FONT_END)
-  #define OLED_FONT_END 224
+#    define OLED_FONT_END 224
 #endif
 // Font render width
 #if !defined(OLED_FONT_WIDTH)
-  #define OLED_FONT_WIDTH 6
+#    define OLED_FONT_WIDTH 6
 #endif
 // Font render height
 #if !defined(OLED_FONT_HEIGHT)
-  #define OLED_FONT_HEIGHT 8
+#    define OLED_FONT_HEIGHT 8
 #endif
 
 #if !defined(OLED_TIMEOUT)
-  #if defined(OLED_DISABLE_TIMEOUT)
-    #define OLED_TIMEOUT 0
-  #else
-    #define OLED_TIMEOUT 60000
-  #endif
+#    if defined(OLED_DISABLE_TIMEOUT)
+#        define OLED_TIMEOUT 0
+#    else
+#        define OLED_TIMEOUT 60000
+#    endif
 #endif
 
 // OLED Rotation enum values are flags
@@ -151,7 +155,7 @@ typedef enum {
     OLED_ROTATION_0   = 0,
     OLED_ROTATION_90  = 1,
     OLED_ROTATION_180 = 2,
-    OLED_ROTATION_270 = 3, // OLED_ROTATION_90 | OLED_ROTATION_180
+    OLED_ROTATION_270 = 3,  // OLED_ROTATION_90 | OLED_ROTATION_180
 } oled_rotation_t;
 
 // Initialize the oled display, rotating the rendered output based on the define passed in.
@@ -208,15 +212,15 @@ void oled_write_P(const char *data, bool invert);
 // Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
 void oled_write_ln_P(const char *data, bool invert);
 #else
-  // Writes a string to the buffer at current cursor position
-  // Advances the cursor while writing, inverts the pixels if true
-  #define oled_write_P(data, invert) oled_write(data, invert)
-
-  // Writes a string to the buffer at current cursor position
-  // Advances the cursor while writing, inverts the pixels if true
-  // Advances the cursor to the next page, wiring ' ' to the remainder of the current page
-  #define oled_write_ln_P(data, invert) oled_write(data, invert)
-#endif // defined(__AVR__)
+// Writes a string to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+#    define oled_write_P(data, invert) oled_write(data, invert)
+
+// Writes a string to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
+#    define oled_write_ln_P(data, invert) oled_write(data, invert)
+#endif  // defined(__AVR__)
 
 // Can be used to manually turn on the screen if it is off
 // Returns true if the screen was on or turns on
index 092dd551e386857f12b0efa6649dc00ad4a4e69f..597810f339c27c2d19bfcd3f2a535f1b629b7c39 100644 (file)
 #include "string.h"
 
 #define TOTALFONTS 2
-const unsigned char * fonts_pointer[]= { font5x7, font8x16 };
+const unsigned char* fonts_pointer[] = {font5x7, font8x16};
 
-uint8_t foreColor,drawMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY;
+uint8_t  foreColor, drawMode, fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY;
 uint16_t fontMapWidth;
 
 #define _BV(x) (1 << (x))
-#define swap(a, b) { uint8_t t = a; a = b; b = t; }
+#define swap(a, b)     \
+    {                  \
+        uint8_t t = a; \
+        a         = b; \
+        b         = t; \
+    }
 
-uint8_t micro_oled_transfer_buffer[20];
-static uint8_t micro_oled_screen_current[LCDWIDTH*LCDWIDTH/8] = { 0 };
+uint8_t        micro_oled_transfer_buffer[20];
+static uint8_t micro_oled_screen_current[LCDWIDTH * LCDWIDTH / 8] = {0};
 
 /* LCD Memory organised in 64 horizontal pixel and 6 rows of byte
    B  B .............B  -----
@@ -64,628 +69,399 @@ static uint8_t micro_oled_screen_current[LCDWIDTH*LCDWIDTH/8] = { 0 };
   */
 
 #if LCDWIDTH == 64
-  #if LCDWIDTH == 48
+#    if LCDWIDTH == 48
 static uint8_t micro_oled_screen_buffer[] = {
-// QMK Logo - generated at http://www.majer.ch/lcd/adf_bitmap.php
-//64x48 image
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00,
-0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00,
-0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60,
-0xF8, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0xFF, 0xFF,
-0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0xFF, 0xFF, 0xFF,
-0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFE,
-0xFE, 0xF8, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x8C, 0x8C, 0x8C, 0x8C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
-0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
-0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x8C, 0x8C, 0x8C, 0x8C,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x31, 0x31, 0x31, 0x31, 0xFF, 0xFF,
-0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF8, 0xF1, 0xE3, 0xE7, 0xCF,
-0xCF, 0xCF, 0xCF, 0x00, 0x00, 0xCF, 0xCF, 0xCF, 0xC7, 0xE7,
-0xE3, 0xF1, 0xF8, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-0x31, 0x31, 0x31, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06,
-0x06, 0x06, 0x1F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF,
-0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-0xFF, 0x7F, 0x7F, 0x1F, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00,
-0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00,
-0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00
-};
-  #endif
+    // QMK Logo - generated at http://www.majer.ch/lcd/adf_bitmap.php
+    // 64x48 image
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0xF8, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xF8, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x8C, 0x8C, 0x8C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x8C, 0x8C, 0x8C, 0x8C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x31, 0x31, 0x31, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF8, 0xF1, 0xE3, 0xE7, 0xCF, 0xCF, 0xCF, 0xCF, 0x00, 0x00, 0xCF, 0xCF, 0xCF, 0xC7, 0xE7, 0xE3, 0xF1, 0xF8, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x31, 0x31, 0x31, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x1F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+#    endif
 #elif LCDWIDTH == 128
-  #if LCDHEIGHT == 32
-     static uint8_t micro_oled_screen_buffer[LCDWIDTH*LCDWIDTH/8] = {
-//128x32 qmk image
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xFC, 0xFC, 0xE0, 0xFC, 0xFC,
-0xE0, 0xF0, 0xFC, 0xE0, 0xE0, 0xFC, 0xE0, 0xE0, 0xFC, 0xFC,
-0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0xF0, 0x10, 0x10, 0x30, 0xE0, 0x00, 0x00,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00,
-0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x80,
-0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00,
-0x80, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
-0x80, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xB2, 0xB2, 0xFF,
-0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x03, 0xFF, 0xFF, 0xFF, 0x03,
-0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x03, 0xFF, 0xFF, 0xFF,
-0xFF, 0xB7, 0xB2, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x1F, 0x02, 0x02, 0x03, 0x01, 0x00, 0x06, 0x1F, 0x10,
-0x10, 0x10, 0x1F, 0x06, 0x00, 0x03, 0x1E, 0x18, 0x0F, 0x01,
-0x0F, 0x18, 0x1E, 0x01, 0x00, 0x0F, 0x1F, 0x12, 0x02, 0x12,
-0x13, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x0E, 0x1F, 0x12,
-0x02, 0x12, 0x13, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x1F,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x48, 0x4D, 0x4D, 0xFF, 0xFF, 0xFF,
-0xFF, 0xFF, 0xFE, 0xF8, 0xF9, 0xF3, 0xF3, 0xC0, 0x80, 0xF3,
-0xF3, 0xF3, 0xF9, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xED,
-0x4D, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0xFE, 0x20, 0x10, 0x10, 0xE0, 0xC0, 0x00, 0x70, 0xC0,
-0x00, 0x80, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x0C,
-0x04, 0x04, 0x04, 0x04, 0x1C, 0xF0, 0x00, 0x00, 0xFC, 0x0C,
-0x38, 0xE0, 0x00, 0x00, 0xC0, 0x38, 0x0C, 0xFC, 0x00, 0x00,
-0xFC, 0xFC, 0x60, 0x90, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x3F,
-0x3F, 0x07, 0x3F, 0x3F, 0x07, 0x0F, 0x3F, 0x07, 0x07, 0x3F,
-0x07, 0x07, 0x3F, 0x3F, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
-0x06, 0x04, 0x04, 0x07, 0x01, 0x00, 0x00, 0x13, 0x1E, 0x03,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x04, 0x04,
-0x04, 0x04, 0x07, 0x0D, 0x08, 0x00, 0x07, 0x00, 0x00, 0x01,
-0x07, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x07, 0x07,
-0x00, 0x01, 0x03, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00
-    };
-  #elif LCDHEIGHT == 64
-    static uint8_t micro_oled_screen_buffer[LCDWIDTH*LCDWIDTH/8] = {
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0,
-0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00,
-0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0xC0, 0xC0, 0xC0, 0xC0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFE, 0xFF,
-0x7F, 0x7E, 0xFE, 0xFF, 0xFF, 0xFE, 0xFE, 0x7F, 0x7F, 0xFE,
-0xFE, 0xFF, 0xFF, 0xFE, 0x7E, 0x7F, 0xFF, 0xFE, 0xFE, 0xFC,
-0xFC, 0xF8, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x88, 0x88, 0x88, 0xDD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
-0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
-0xFF, 0xFF, 0xFF, 0xDD, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x99, 0x99, 0x99, 0x99, 0xFF, 0xFF, 0xFF, 0xFF,
-0xFF, 0xFF, 0xFE, 0xF8, 0xF0, 0xF3, 0xF3, 0xE7, 0xE7, 0x00,
-0x00, 0xE7, 0xE7, 0xF3, 0xF3, 0xF0, 0xF8, 0xFE, 0xFF, 0xFF,
-0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0x99, 0x99, 0x99, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x1F, 0x3F,
-0x3F, 0x3F, 0xFF, 0xFF, 0x3F, 0x3F, 0xFF, 0xFF, 0x3F, 0x3F,
-0xFF, 0xFF, 0x3F, 0x3F, 0xFF, 0xFF, 0x3F, 0x3F, 0xFF, 0xFF,
-0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x01, 0x01, 0x01, 0x01, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x03, 0x01, 0x00,
-0x80, 0x03, 0x03, 0x00, 0x00, 0x01, 0x03, 0x00, 0x80, 0x01,
-0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0xFF, 0x11, 0x11, 0x11, 0x0E, 0x00, 0x70,
-0x88, 0x04, 0x04, 0x04, 0xF8, 0x00, 0x00, 0x3C, 0xE0, 0xC0,
-0x38, 0x1C, 0xE0, 0x80, 0x70, 0x0C, 0x00, 0xF8, 0xAC, 0x24,
-0x24, 0x3C, 0x30, 0x00, 0x00, 0xFC, 0x0C, 0x04, 0x00, 0xF8,
-0xAC, 0x24, 0x24, 0x2C, 0x30, 0x00, 0x70, 0xDC, 0x04, 0x04,
-0x88, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
-0x8C, 0x04, 0x04, 0xF8, 0x00, 0x04, 0x3C, 0xE0, 0x80, 0xF0,
-0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x83, 0x01, 0x01,
-0x01, 0x81, 0xFE, 0x3C, 0x00, 0x00, 0xFF, 0x03, 0x0E, 0x70,
-0xC0, 0xE0, 0x38, 0x06, 0x03, 0xFF, 0x00, 0x00, 0xFF, 0x18,
-0x38, 0x66, 0xC3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
-0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
-0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
-0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01,
-0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x03,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
-0x01, 0x01, 0x01, 0x01, 0x03, 0x02, 0x00, 0x01, 0x00, 0x00,
-0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01,
-0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-    };
-//TODO: generate bitmap of QMK logo here
-  #endif
+#    if LCDHEIGHT == 32
+static uint8_t micro_oled_screen_buffer[LCDWIDTH * LCDWIDTH / 8] = {
+    // 128x32 qmk image
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xFC, 0xFC, 0xE0, 0xFC, 0xFC, 0xE0, 0xF0, 0xFC, 0xE0, 0xE0, 0xFC, 0xE0, 0xE0, 0xFC, 0xFC, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, 0x10, 0x30, 0xE0, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xB2, 0xB2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x03, 0xFF, 0xFF, 0xFF, 0x03, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xB7, 0xB2, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x02, 0x02, 0x03, 0x01, 0x00, 0x06, 0x1F, 0x10, 0x10, 0x10, 0x1F, 0x06, 0x00, 0x03, 0x1E, 0x18, 0x0F, 0x01, 0x0F, 0x18, 0x1E, 0x01, 0x00, 0x0F, 0x1F, 0x12, 0x02, 0x12, 0x13, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x0E, 0x1F, 0x12, 0x02, 0x12, 0x13, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x4D, 0x4D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xF9, 0xF3, 0xF3, 0xC0, 0x80, 0xF3, 0xF3, 0xF3, 0xF9, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xED, 0x4D, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x20, 0x10, 0x10, 0xE0, 0xC0, 0x00, 0x70, 0xC0, 0x00, 0x80, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x1C, 0xF0, 0x00, 0x00, 0xFC, 0x0C, 0x38, 0xE0, 0x00, 0x00, 0xC0, 0x38, 0x0C, 0xFC, 0x00, 0x00, 0xFC, 0xFC, 0x60, 0x90, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x3F, 0x3F, 0x07, 0x3F, 0x3F, 0x07, 0x0F, 0x3F, 0x07, 0x07, 0x3F, 0x07, 0x07, 0x3F, 0x3F, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, 0x04, 0x04, 0x07, 0x01, 0x00, 0x00, 0x13, 0x1E, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x04, 0x04, 0x04, 0x04, 0x07, 0x0D, 0x08, 0x00, 0x07, 0x00, 0x00, 0x01, 0x07, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x07, 0x07, 0x00, 0x01, 0x03, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+#    elif LCDHEIGHT == 64
+static uint8_t micro_oled_screen_buffer[LCDWIDTH * LCDWIDTH / 8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFE, 0xFF, 0x7F, 0x7E, 0xFE, 0xFF, 0xFF, 0xFE, 0xFE, 0x7F, 0x7F, 0xFE, 0xFE, 0xFF, 0xFF, 0xFE, 0x7E, 0x7F, 0xFF, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0xDD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDD, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x99, 0x99, 0x99, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xF0, 0xF3, 0xF3, 0xE7, 0xE7, 0x00, 0x00, 0xE7, 0xE7, 0xF3, 0xF3, 0xF0, 0xF8, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0x99, 0x99, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x1F, 0x3F, 0x3F, 0x3F, 0xFF, 0xFF, 0x3F, 0x3F, 0xFF, 0xFF, 0x3F, 0x3F, 0xFF, 0xFF, 0x3F, 0x3F, 0xFF, 0xFF, 0x3F, 0x3F, 0xFF, 0xFF, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x03, 0x01, 0x00, 0x80, 0x03, 0x03, 0x00, 0x00, 0x01, 0x03, 0x00, 0x80, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x11, 0x11, 0x11, 0x0E, 0x00, 0x70, 0x88, 0x04, 0x04, 0x04, 0xF8, 0x00, 0x00, 0x3C, 0xE0, 0xC0, 0x38, 0x1C, 0xE0, 0x80, 0x70, 0x0C, 0x00, 0xF8, 0xAC, 0x24, 0x24, 0x3C, 0x30, 0x00, 0x00, 0xFC, 0x0C, 0x04, 0x00, 0xF8, 0xAC, 0x24, 0x24, 0x2C, 0x30, 0x00, 0x70, 0xDC, 0x04, 0x04, 0x88, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x8C, 0x04, 0x04, 0xF8, 0x00, 0x04, 0x3C, 0xE0, 0x80, 0xF0, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x83, 0x01, 0x01, 0x01, 0x81, 0xFE, 0x3C, 0x00, 0x00, 0xFF, 0x03, 0x0E, 0x70, 0xC0, 0xE0, 0x38, 0x06, 0x03, 0xFF, 0x00, 0x00, 0xFF, 0x18, 0x38, 0x66, 0xC3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+// TODO: generate bitmap of QMK logo here
+#    endif
 #else
-//catchall for custom screen szies
-    static uint8_t micro_oled_screen_buffer[LCDWIDTH*LCDWIDTH/8] = {0};
+// catchall for custom screen szies
+static uint8_t micro_oled_screen_buffer[LCDWIDTH * LCDWIDTH / 8] = {0};
 #endif
 
-
-
 void micro_oled_init(void) {
-  i2c_init();
-  i2c_start(I2C_ADDRESS_SA0_1);
+    i2c_init();
+    i2c_start(I2C_ADDRESS_SA0_1);
 
-  // Display Init sequence for 64x48 OLED module
-  send_command(DISPLAYOFF);      // 0xAE
+    // Display Init sequence for 64x48 OLED module
+    send_command(DISPLAYOFF);  // 0xAE
 
-  send_command(SETDISPLAYCLOCKDIV);  // 0xD5
-  send_command(0x80);          // the suggested ratio 0x80
+    send_command(SETDISPLAYCLOCKDIV);  // 0xD5
+    send_command(0x80);                // the suggested ratio 0x80
 
-  send_command(SETMULTIPLEX);      // 0xA8
-  send_command(LCDHEIGHT - 1);
+    send_command(SETMULTIPLEX);  // 0xA8
+    send_command(LCDHEIGHT - 1);
 
-  send_command(SETDISPLAYOFFSET);    // 0xD3
-  send_command(0x00);         // no offset
+    send_command(SETDISPLAYOFFSET);  // 0xD3
+    send_command(0x00);              // no offset
 
-  send_command(SETSTARTLINE | 0x00);  // line #0
+    send_command(SETSTARTLINE | 0x00);  // line #0
 
-  send_command(CHARGEPUMP);      // enable charge pump
-  send_command(0x14);
+    send_command(CHARGEPUMP);  // enable charge pump
+    send_command(0x14);
 
-  send_command(NORMALDISPLAY);     // 0xA6
-  send_command(DISPLAYALLONRESUME);  // 0xA4
+    send_command(NORMALDISPLAY);       // 0xA6
+    send_command(DISPLAYALLONRESUME);  // 0xA4
 
-//display at regular orientation
-  send_command(SEGREMAP | 0x1);
-  send_command(COMSCANDEC);
+    // display at regular orientation
+    send_command(SEGREMAP | 0x1);
+    send_command(COMSCANDEC);
 
-//rotate display 180
+// rotate display 180
 #ifdef micro_oled_rotate_180
-  send_command(SEGREMAP);
-  send_command(COMSCANINC);
+    send_command(SEGREMAP);
+    send_command(COMSCANINC);
 #endif
 
-  send_command(MEMORYMODE);
-  send_command(0x10);
+    send_command(MEMORYMODE);
+    send_command(0x10);
 
-  send_command(SETCOMPINS);      // 0xDA
-if (LCDHEIGHT > 32) {
-  send_command(0x12);
-} else {
-  send_command(0x02);
-}
-  send_command(SETCONTRAST);     // 0x81
-  send_command(0x8F);
+    send_command(SETCOMPINS);  // 0xDA
+    if (LCDHEIGHT > 32) {
+        send_command(0x12);
+    } else {
+        send_command(0x02);
+    }
+    send_command(SETCONTRAST);  // 0x81
+    send_command(0x8F);
 
-  send_command(SETPRECHARGE);      // 0xd9
-  send_command(0xF1);
+    send_command(SETPRECHARGE);  // 0xd9
+    send_command(0xF1);
 
-  send_command(SETVCOMDESELECT);     // 0xDB
-  send_command(0x40);
+    send_command(SETVCOMDESELECT);  // 0xDB
+    send_command(0x40);
 
-  send_command(DISPLAYON);       //--turn on oled panel
-  clear_screen();           // Erase hardware memory inside the OLED controller to avoid random data in memory.
-  send_buffer();
+    send_command(DISPLAYON);  //--turn on oled panel
+    clear_screen();           // Erase hardware memory inside the OLED controller to avoid random data in memory.
+    send_buffer();
 }
 
 void send_command(uint8_t command) {
-  micro_oled_transfer_buffer[0] = I2C_COMMAND;
-  micro_oled_transfer_buffer[1] = command;
-  i2c_transmit(I2C_ADDRESS_SA0_1 << 1, micro_oled_transfer_buffer, 2, 100);
+    micro_oled_transfer_buffer[0] = I2C_COMMAND;
+    micro_oled_transfer_buffer[1] = command;
+    i2c_transmit(I2C_ADDRESS_SA0_1 << 1, micro_oled_transfer_buffer, 2, 100);
 }
 
 void send_data(uint8_t data) {
-  micro_oled_transfer_buffer[0] = I2C_DATA;
-  micro_oled_transfer_buffer[1] = data;
-  i2c_transmit(I2C_ADDRESS_SA0_1 << 1, micro_oled_transfer_buffer, 2, 100);
+    micro_oled_transfer_buffer[0] = I2C_DATA;
+    micro_oled_transfer_buffer[1] = data;
+    i2c_transmit(I2C_ADDRESS_SA0_1 << 1, micro_oled_transfer_buffer, 2, 100);
 }
 
 /** \brief Set SSD1306 page address.
     Send page address command and address to the SSD1306 OLED controller.
 */
 void set_page_address(uint8_t address) {
-  address = (0xB0 | address);
-  send_command(address);
+    address = (0xB0 | address);
+    send_command(address);
 }
 
 /** \brief Set SSD1306 column address.
     Send column address command and address to the SSD1306 OLED controller.
 */
 void set_column_address(uint8_t address) {
-  send_command( ( 0x10 | (address >> 4) ) + ((128 - LCDWIDTH) >> 8) );
-  send_command( 0x0F & address );
+    send_command((0x10 | (address >> 4)) + ((128 - LCDWIDTH) >> 8));
+    send_command(0x0F & address);
 }
 
 /** \brief Clear SSD1306's memory.
     To clear GDRAM inside the LCD controller.
 */
 void clear_screen(void) {
-  for (int i=0;i<8; i++) {
-    set_page_address(i);
-    set_column_address(0);
-    for (int j=0; j<0x80; j++) {
-      send_data(0);
+    for (int i = 0; i < 8; i++) {
+        set_page_address(i);
+        set_column_address(0);
+        for (int j = 0; j < 0x80; j++) {
+            send_data(0);
+        }
     }
-  }
 }
 
 /** \brief Clear SSD1306's memory.
     To clear GDRAM inside the LCD controller.
 */
 void clear_buffer(void) {
-//384
-  memset(micro_oled_screen_buffer, 0, LCDWIDTH*LCDWIDTH/8);
+    // 384
+    memset(micro_oled_screen_buffer, 0, LCDWIDTH * LCDWIDTH / 8);
 }
 
 /** \brief Invert display.
     The PIXEL_ON color of the display will turn to PIXEL_OFF and the PIXEL_OFF will turn to PIXEL_ON.
 */
 void invert_screen(bool invert) {
-  if (invert) {
-    send_command(INVERTDISPLAY);
-  } else {
-    send_command(NORMALDISPLAY);
-  }
+    if (invert) {
+        send_command(INVERTDISPLAY);
+    } else {
+        send_command(NORMALDISPLAY);
+    }
 }
 
 /** \brief Set contrast.
     OLED contract value from 0 to 255. Note: Contrast level is not very obvious.
 */
 void set_contrast(uint8_t contrast) {
-  send_command(SETCONTRAST);     // 0x81
-  send_command(contrast);
+    send_command(SETCONTRAST);  // 0x81
+    send_command(contrast);
 }
 
 /** \brief Transfer display buffer.
   Sends the updated buffer to the controller - the current status is checked before to save i2c exectution time
 */
 void send_buffer(void) {
-  uint8_t i, j;
-
-  uint8_t page_addr = 0xFF;
-  for (i = 0; i < LCDHEIGHT/8; i++) {
-    uint8_t col_addr = 0xFF;
-    for (j = 0; j < LCDWIDTH; j++) {
-      if (micro_oled_screen_buffer[i*LCDWIDTH+j] != micro_oled_screen_current[i*LCDWIDTH+j]) {
-        if (page_addr != i) {
-          set_page_address(i);
+    uint8_t i, j;
+
+    uint8_t page_addr = 0xFF;
+    for (i = 0; i < LCDHEIGHT / 8; i++) {
+        uint8_t col_addr = 0xFF;
+        for (j = 0; j < LCDWIDTH; j++) {
+            if (micro_oled_screen_buffer[i * LCDWIDTH + j] != micro_oled_screen_current[i * LCDWIDTH + j]) {
+                if (page_addr != i) {
+                    set_page_address(i);
+                }
+                if (col_addr != j) {
+                    set_column_address(j);
+                }
+                send_data(micro_oled_screen_buffer[i * LCDWIDTH + j]);
+                micro_oled_screen_current[i * LCDWIDTH + j] = micro_oled_screen_buffer[i * LCDWIDTH + j];
+                col_addr                                    = j + 1;
+            }
         }
-        if (col_addr != j) {
-          set_column_address(j);
-        }
-        send_data(micro_oled_screen_buffer[i*LCDWIDTH+j]);
-        micro_oled_screen_current[i*LCDWIDTH+j] = micro_oled_screen_buffer[i*LCDWIDTH+j];
-        col_addr = j + 1;
-      }
     }
-  }
 }
 
 /** \brief Draw pixel with color and mode.
   Draw color pixel in the screen buffer's x,y position with NORM or XOR draw mode.
 */
 void draw_pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode) {
-  if ((x<0) ||  (x>=LCDWIDTH) || (y<0) || (y>=LCDHEIGHT))
-    return;
-
-  if (mode == XOR) {
-    if (color == PIXEL_ON)
-      micro_oled_screen_buffer[x + (y/8)*LCDWIDTH] ^= _BV((y%8));
-  } else {
-    if (color == PIXEL_ON)
-      micro_oled_screen_buffer[x + (y/8)*LCDWIDTH] |= _BV((y%8));
-    else
-      micro_oled_screen_buffer[x + (y/8)*LCDWIDTH] &= ~_BV((y%8));
-  }
+    if ((x < 0) || (x >= LCDWIDTH) || (y < 0) || (y >= LCDHEIGHT)) return;
+
+    if (mode == XOR) {
+        if (color == PIXEL_ON) micro_oled_screen_buffer[x + (y / 8) * LCDWIDTH] ^= _BV((y % 8));
+    } else {
+        if (color == PIXEL_ON)
+            micro_oled_screen_buffer[x + (y / 8) * LCDWIDTH] |= _BV((y % 8));
+        else
+            micro_oled_screen_buffer[x + (y / 8) * LCDWIDTH] &= ~_BV((y % 8));
+    }
 }
 
 /** \brief Draw line with color and mode.
 Draw line using color and mode from x0,y0 to x1,y1 of the screen buffer.
 */
 void draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode) {
-  uint8_t steep = abs(y1 - y0) > abs(x1 - x0);
-  if (steep) {
-    swap(x0, y0);
-    swap(x1, y1);
-  }
-
-  if (x0 > x1) {
-    swap(x0, x1);
-    swap(y0, y1);
-  }
-
-  uint8_t dx, dy;
-  dx = x1 - x0;
-  dy = abs(y1 - y0);
-
-  int8_t err = dx / 2;
-  int8_t ystep;
-
-  if (y0 < y1) {
-    ystep = 1;
-  } else {
-    ystep = -1;}
-
-  for (; x0<x1; x0++) {
+    uint8_t steep = abs(y1 - y0) > abs(x1 - x0);
     if (steep) {
-      draw_pixel(y0, x0, color, mode);
+        swap(x0, y0);
+        swap(x1, y1);
+    }
+
+    if (x0 > x1) {
+        swap(x0, x1);
+        swap(y0, y1);
+    }
+
+    uint8_t dx, dy;
+    dx = x1 - x0;
+    dy = abs(y1 - y0);
+
+    int8_t err = dx / 2;
+    int8_t ystep;
+
+    if (y0 < y1) {
+        ystep = 1;
     } else {
-      draw_pixel(x0, y0, color, mode);
+        ystep = -1;
     }
-    err -= dy;
-    if (err < 0) {
-      y0 += ystep;
-      err += dx;
+
+    for (; x0 < x1; x0++) {
+        if (steep) {
+            draw_pixel(y0, x0, color, mode);
+        } else {
+            draw_pixel(x0, y0, color, mode);
+        }
+        err -= dy;
+        if (err < 0) {
+            y0 += ystep;
+            err += dx;
+        }
     }
-  }
 }
 
 /** \brief Draw horizontal line with color and mode.
 Draw horizontal line using color and mode from x,y to x+width,y of the screen buffer.
 */
-void draw_line_hori(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode) {
-  draw_line(x,y,x+width,y,color,mode);
-}
+void draw_line_hori(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode) { draw_line(x, y, x + width, y, color, mode); }
 
 /** \brief Draw vertical line.
 Draw vertical line using current fore color and current draw mode from x,y to x,y+height of the screen buffer.
 */
-void draw_line_vert(uint8_t x, uint8_t y, uint8_t height, bool color, uint8_t mode) {
-  draw_line(x,y,x,y+height,color,mode);
-}
+void draw_line_vert(uint8_t x, uint8_t y, uint8_t height, bool color, uint8_t mode) { draw_line(x, y, x, y + height, color, mode); }
 
 /** \brief Draw rectangle with color and mode.
 Draw rectangle using color and mode from x,y to x+width,y+height of the screen buffer.
 */
 void draw_rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode) {
-  uint8_t tempHeight;
+    uint8_t tempHeight;
 
-  draw_line_hori(x,y, width, color, mode);
-  draw_line_hori(x,y+height-1, width, color, mode);
+    draw_line_hori(x, y, width, color, mode);
+    draw_line_hori(x, y + height - 1, width, color, mode);
 
-  tempHeight=height-2;
+    tempHeight = height - 2;
 
-  // skip drawing vertical lines to avoid overlapping of pixel that will
-  // affect XOR plot if no pixel in between horizontal lines
-  if (tempHeight<1) return;
+    // skip drawing vertical lines to avoid overlapping of pixel that will
+    // affect XOR plot if no pixel in between horizontal lines
+    if (tempHeight < 1) return;
 
-  draw_line_vert(x,y+1, tempHeight, color, mode);
-  draw_line_vert(x+width-1, y+1, tempHeight, color, mode);
+    draw_line_vert(x, y + 1, tempHeight, color, mode);
+    draw_line_vert(x + width - 1, y + 1, tempHeight, color, mode);
 }
 
 /** \brief Draw rectangle with color and mode.
 Draw rectangle using color and mode from x,y to x+width,y+height of the screen buffer.
 */
 void draw_rect_soft(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode) {
-  uint8_t tempHeight;
+    uint8_t tempHeight;
 
-  draw_line_hori(x+1,y, width-2, color, mode);
-  draw_line_hori(x+1,y+height-1, width-2, color, mode);
+    draw_line_hori(x + 1, y, width - 2, color, mode);
+    draw_line_hori(x + 1, y + height - 1, width - 2, color, mode);
 
-  tempHeight=height-2;
+    tempHeight = height - 2;
 
-  // skip drawing vertical lines to avoid overlapping of pixel that will
-  // affect XOR plot if no pixel in between horizontal lines
-  if (tempHeight<1) return;
+    // skip drawing vertical lines to avoid overlapping of pixel that will
+    // affect XOR plot if no pixel in between horizontal lines
+    if (tempHeight < 1) return;
 
-  draw_line_vert(x,y+1, tempHeight, color, mode);
-  draw_line_vert(x+width-1, y+1, tempHeight, color, mode);
+    draw_line_vert(x, y + 1, tempHeight, color, mode);
+    draw_line_vert(x + width - 1, y + 1, tempHeight, color, mode);
 }
 
 /** \brief Draw filled rectangle with color and mode.
 Draw filled rectangle using color and mode from x,y to x+width,y+height of the screen buffer.
 */
 void draw_rect_filled(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode) {
-  // TODO - need to optimise the memory map draw so that this function will not call pixel one by one
-  for (int i=x; i<x+width;i++) {
-    draw_line_vert(i,y, height, color, mode);
-  }
+    // TODO - need to optimise the memory map draw so that this function will not call pixel one by one
+    for (int i = x; i < x + width; i++) {
+        draw_line_vert(i, y, height, color, mode);
+    }
 }
 
 /** \brief Draw filled rectangle with color and mode.
 Draw filled rectangle using color and mode from x,y to x+width,y+height of the screen buffer.
 */
 void draw_rect_filled_soft(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode) {
-  // TODO - need to optimise the memory map draw so that this function will not call pixel one by one
-  for (int i=x; i<x+width;i++) {
-    if (i == x || i == (x + width - 1))
-      draw_line_vert(i, y+1, height-2, color, mode);
-    else
-      draw_line_vert(i, y, height, color, mode);
-  }
+    // TODO - need to optimise the memory map draw so that this function will not call pixel one by one
+    for (int i = x; i < x + width; i++) {
+        if (i == x || i == (x + width - 1))
+            draw_line_vert(i, y + 1, height - 2, color, mode);
+        else
+            draw_line_vert(i, y, height, color, mode);
+    }
 }
 
 /** \brief Draw character with color and mode.
   Draw character c using color and draw mode at x,y.
 */
 void draw_char(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode, uint8_t font) {
-  // TODO - New routine to take font of any height, at the moment limited to font height in multiple of 8 pixels
-
-  uint8_t rowsToDraw,row, tempC;
-  uint8_t i,j,temp;
-  uint16_t charPerBitmapRow,charColPositionOnBitmap,charRowPositionOnBitmap,charBitmapStartPosition;
-
-  if ((font>=TOTALFONTS) || (font<0))
-    return;
-
-  uint8_t fontType = font;
-  uint8_t fontWidth = pgm_read_byte(fonts_pointer[fontType]+0);
-  uint8_t fontHeight = pgm_read_byte(fonts_pointer[fontType]+1);
-  uint8_t fontStartChar = pgm_read_byte(fonts_pointer[fontType]+2);
-  uint8_t fontTotalChar = pgm_read_byte(fonts_pointer[fontType]+3);
-  uint16_t fontMapWidth = (pgm_read_byte(fonts_pointer[fontType]+4)*100)+pgm_read_byte(fonts_pointer[fontType]+5); // two bytes values into integer 16
-
-  if ((c<fontStartChar) || (c>(fontStartChar+fontTotalChar-1)))   // no bitmap for the required c
-    return;
-
-  tempC=c-fontStartChar;
-
-  // each row (in datasheet is call page) is 8 bits high, 16 bit high character will have 2 rows to be drawn
-  rowsToDraw=fontHeight/8;  // 8 is LCD's page size, see SSD1306 datasheet
-  if (rowsToDraw<=1) rowsToDraw=1;
-
-  // the following draw function can draw anywhere on the screen, but SLOW pixel by pixel draw
-  if (rowsToDraw==1) {
-    for  (i=0;i<fontWidth+1;i++) {
-      if (i==fontWidth) // this is done in a weird way because for 5x7 font, there is no margin, this code add a margin after col 5
-      temp=0;
-      else
-      temp=pgm_read_byte(fonts_pointer[fontType]+FONTHEADERSIZE+(tempC*fontWidth)+i);
-
-      for (j=0;j<8;j++) {     // 8 is the LCD's page height (see datasheet for explanation)
-        if (temp & 0x1) {
-          draw_pixel(x+i, y+j, color,mode);
+    // TODO - New routine to take font of any height, at the moment limited to font height in multiple of 8 pixels
+
+    uint8_t  rowsToDraw, row, tempC;
+    uint8_t  i, j, temp;
+    uint16_t charPerBitmapRow, charColPositionOnBitmap, charRowPositionOnBitmap, charBitmapStartPosition;
+
+    if ((font >= TOTALFONTS) || (font < 0)) return;
+
+    uint8_t  fontType      = font;
+    uint8_t  fontWidth     = pgm_read_byte(fonts_pointer[fontType] + 0);
+    uint8_t  fontHeight    = pgm_read_byte(fonts_pointer[fontType] + 1);
+    uint8_t  fontStartChar = pgm_read_byte(fonts_pointer[fontType] + 2);
+    uint8_t  fontTotalChar = pgm_read_byte(fonts_pointer[fontType] + 3);
+    uint16_t fontMapWidth  = (pgm_read_byte(fonts_pointer[fontType] + 4) * 100) + pgm_read_byte(fonts_pointer[fontType] + 5);  // two bytes values into integer 16
+
+    if ((c < fontStartChar) || (c > (fontStartChar + fontTotalChar - 1)))  // no bitmap for the required c
+        return;
+
+    tempC = c - fontStartChar;
+
+    // each row (in datasheet is call page) is 8 bits high, 16 bit high character will have 2 rows to be drawn
+    rowsToDraw = fontHeight / 8;  // 8 is LCD's page size, see SSD1306 datasheet
+    if (rowsToDraw <= 1) rowsToDraw = 1;
+
+    // the following draw function can draw anywhere on the screen, but SLOW pixel by pixel draw
+    if (rowsToDraw == 1) {
+        for (i = 0; i < fontWidth + 1; i++) {
+            if (i == fontWidth)  // this is done in a weird way because for 5x7 font, there is no margin, this code add a margin after col 5
+                temp = 0;
+            else
+                temp = pgm_read_byte(fonts_pointer[fontType] + FONTHEADERSIZE + (tempC * fontWidth) + i);
+
+            for (j = 0; j < 8; j++) {  // 8 is the LCD's page height (see datasheet for explanation)
+                if (temp & 0x1) {
+                    draw_pixel(x + i, y + j, color, mode);
+                } else {
+                    draw_pixel(x + i, y + j, !color, mode);
+                }
+
+                temp >>= 1;
+            }
         }
-        else {
-          draw_pixel(x+i, y+j, !color,mode);
-        }
-
-        temp >>=1;
-      }
+        return;
     }
-    return;
-  }
-
-  // font height over 8 bit
-  // take character "0" ASCII 48 as example
-  charPerBitmapRow = fontMapWidth/fontWidth;  // 256/8 =32 char per row
-  charColPositionOnBitmap = tempC % charPerBitmapRow;  // =16
-  charRowPositionOnBitmap = (int)(tempC/charPerBitmapRow); // =1
-  charBitmapStartPosition = (charRowPositionOnBitmap * fontMapWidth * (fontHeight/8)) + (charColPositionOnBitmap * fontWidth) ;
-
-  // each row on LCD is 8 bit height (see datasheet for explanation)
-  for(row=0;row<rowsToDraw;row++) {
-    for (i=0; i<fontWidth;i++) {
-      temp=pgm_read_byte(fonts_pointer[fontType]+FONTHEADERSIZE+(charBitmapStartPosition+i+(row*fontMapWidth)));
-      for (j=0;j<8;j++) {     // 8 is the LCD's page height (see datasheet for explanation)
-        if (temp & 0x1) {
-          draw_pixel(x+i,y+j+(row*8), color, mode);
-        }
-        else {
-          draw_pixel(x+i,y+j+(row*8), !color, mode);
+
+    // font height over 8 bit
+    // take character "0" ASCII 48 as example
+    charPerBitmapRow        = fontMapWidth / fontWidth;         // 256/8 =32 char per row
+    charColPositionOnBitmap = tempC % charPerBitmapRow;         // =16
+    charRowPositionOnBitmap = (int)(tempC / charPerBitmapRow);  // =1
+    charBitmapStartPosition = (charRowPositionOnBitmap * fontMapWidth * (fontHeight / 8)) + (charColPositionOnBitmap * fontWidth);
+
+    // each row on LCD is 8 bit height (see datasheet for explanation)
+    for (row = 0; row < rowsToDraw; row++) {
+        for (i = 0; i < fontWidth; i++) {
+            temp = pgm_read_byte(fonts_pointer[fontType] + FONTHEADERSIZE + (charBitmapStartPosition + i + (row * fontMapWidth)));
+            for (j = 0; j < 8; j++) {  // 8 is the LCD's page height (see datasheet for explanation)
+                if (temp & 0x1) {
+                    draw_pixel(x + i, y + j + (row * 8), color, mode);
+                } else {
+                    draw_pixel(x + i, y + j + (row * 8), !color, mode);
+                }
+                temp >>= 1;
+            }
         }
-        temp >>=1;
-      }
     }
-  }
-
 }
 
-void draw_string(uint8_t x, uint8_t y, char * string, uint8_t color, uint8_t mode, uint8_t font) {
-
-  if ((font>=TOTALFONTS) || (font<0))
-    return;
+void draw_string(uint8_t x, uint8_t y, char* string, uint8_t color, uint8_t mode, uint8_t font) {
+    if ((font >= TOTALFONTS) || (font < 0)) return;
 
-  uint8_t fontType = font;
-  uint8_t fontWidth = pgm_read_byte(fonts_pointer[fontType]+0);
-
-  uint8_t cur_x = x;
-  for (int i = 0; i < strlen(string); i++) {
-    draw_char(cur_x, y, string[i], color, mode, font);
-    cur_x += fontWidth + 1;
-  }
+    uint8_t fontType  = font;
+    uint8_t fontWidth = pgm_read_byte(fonts_pointer[fontType] + 0);
 
+    uint8_t cur_x = x;
+    for (int i = 0; i < strlen(string); i++) {
+        draw_char(cur_x, y, string[i], color, mode, font);
+        cur_x += fontWidth + 1;
+    }
 }
index 5d6a1029ed7a958d8786b771dca87ca1614d1d92..814143df11fee5d443971cea30aecc5845e71092 100644 (file)
@@ -49,86 +49,86 @@ void draw_rect_soft(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t
 void draw_rect_filled(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode);
 void draw_rect_filled_soft(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode);
 void draw_char(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode, uint8_t font);
-void draw_string(uint8_t x, uint8_t y, char * string, uint8_t color, uint8_t mode, uint8_t font);
+void draw_string(uint8_t x, uint8_t y, char* string, uint8_t color, uint8_t mode, uint8_t font);
 
 #define I2C_ADDRESS_SA0_0 0b0111100
 #ifndef I2C_ADDRESS_SA0_1
-#define I2C_ADDRESS_SA0_1 0b0111101
+#    define I2C_ADDRESS_SA0_1 0b0111101
 #endif
 #define I2C_COMMAND 0x00
 #define I2C_DATA 0x40
 #define PIXEL_OFF 0
-#define PIXEL_ON  1
+#define PIXEL_ON 1
 
 #ifndef LCDWIDTH
-#define LCDWIDTH      64
+#    define LCDWIDTH 64
 #endif
 #ifndef LCDWIDTH
-#define LCDHEIGHT     48
+#    define LCDHEIGHT 48
 #endif
-#define FONTHEADERSIZE    6
+#define FONTHEADERSIZE 6
 
-#define NORM        0
-#define XOR         1
+#define NORM 0
+#define XOR 1
 
-#define PAGE        0
-#define ALL         1
+#define PAGE 0
+#define ALL 1
 
-#define WIDGETSTYLE0      0
-#define WIDGETSTYLE1      1
-#define WIDGETSTYLE2      2
+#define WIDGETSTYLE0 0
+#define WIDGETSTYLE1 1
+#define WIDGETSTYLE2 2
 
-#define SETCONTRAST     0x81
-#define DISPLAYALLONRESUME  0xA4
-#define DISPLAYALLON    0xA5
-#define NORMALDISPLAY     0xA6
-#define INVERTDISPLAY     0xA7
-#define DISPLAYOFF      0xAE
-#define DISPLAYON       0xAF
-#define SETDISPLAYOFFSET  0xD3
-#define SETCOMPINS      0xDA
-#define SETVCOMDESELECT   0xDB
-#define SETDISPLAYCLOCKDIV  0xD5
-#define SETPRECHARGE    0xD9
-#define SETMULTIPLEX    0xA8
-#define SETLOWCOLUMN    0x00
-#define SETHIGHCOLUMN     0x10
-#define SETSTARTLINE    0x40
-#define MEMORYMODE      0x20
-#define COMSCANINC      0xC0
-#define COMSCANDEC      0xC8
-#define SEGREMAP      0xA0
-#define CHARGEPUMP      0x8D
-#define EXTERNALVCC     0x01
-#define SWITCHCAPVCC    0x02
+#define SETCONTRAST 0x81
+#define DISPLAYALLONRESUME 0xA4
+#define DISPLAYALLON 0xA5
+#define NORMALDISPLAY 0xA6
+#define INVERTDISPLAY 0xA7
+#define DISPLAYOFF 0xAE
+#define DISPLAYON 0xAF
+#define SETDISPLAYOFFSET 0xD3
+#define SETCOMPINS 0xDA
+#define SETVCOMDESELECT 0xDB
+#define SETDISPLAYCLOCKDIV 0xD5
+#define SETPRECHARGE 0xD9
+#define SETMULTIPLEX 0xA8
+#define SETLOWCOLUMN 0x00
+#define SETHIGHCOLUMN 0x10
+#define SETSTARTLINE 0x40
+#define MEMORYMODE 0x20
+#define COMSCANINC 0xC0
+#define COMSCANDEC 0xC8
+#define SEGREMAP 0xA0
+#define CHARGEPUMP 0x8D
+#define EXTERNALVCC 0x01
+#define SWITCHCAPVCC 0x02
 
 // Scroll
-#define ACTIVATESCROLL          0x2F
-#define DEACTIVATESCROLL        0x2E
-#define SETVERTICALSCROLLAREA       0xA3
-#define RIGHTHORIZONTALSCROLL       0x26
-#define LEFT_HORIZONTALSCROLL       0x27
+#define ACTIVATESCROLL 0x2F
+#define DEACTIVATESCROLL 0x2E
+#define SETVERTICALSCROLLAREA 0xA3
+#define RIGHTHORIZONTALSCROLL 0x26
+#define LEFT_HORIZONTALSCROLL 0x27
 #define VERTICALRIGHTHORIZONTALSCROLL 0x29
-#define VERTICALLEFTHORIZONTALSCROLL  0x2A
+#define VERTICALLEFTHORIZONTALSCROLL 0x2A
 
 typedef enum CMD {
-  CMD_CLEAR,      //0
-  CMD_INVERT,     //1
-  CMD_CONTRAST,   //2
-  CMD_DISPLAY,    //3
-  CMD_SETCURSOR,    //4
-  CMD_PIXEL,      //5
-  CMD_LINE,     //6
-  CMD_LINEH,      //7
-  CMD_LINEV,      //8
-  CMD_RECT,     //9
-  CMD_RECTFILL,   //10
-  CMD_CIRCLE,     //11
-  CMD_CIRCLEFILL,   //12
-  CMD_DRAWCHAR,   //13
-  CMD_DRAWBITMAP,   //14
-  CMD_GETLCDWIDTH,  //15
-  CMD_GETLCDHEIGHT, //16
-  CMD_SETCOLOR,   //17
-  CMD_SETDRAWMODE   //18
+    CMD_CLEAR,         // 0
+    CMD_INVERT,        // 1
+    CMD_CONTRAST,      // 2
+    CMD_DISPLAY,       // 3
+    CMD_SETCURSOR,     // 4
+    CMD_PIXEL,         // 5
+    CMD_LINE,          // 6
+    CMD_LINEH,         // 7
+    CMD_LINEV,         // 8
+    CMD_RECT,          // 9
+    CMD_RECTFILL,      // 10
+    CMD_CIRCLE,        // 11
+    CMD_CIRCLEFILL,    // 12
+    CMD_DRAWCHAR,      // 13
+    CMD_DRAWBITMAP,    // 14
+    CMD_GETLCDWIDTH,   // 15
+    CMD_GETLCDHEIGHT,  // 16
+    CMD_SETCOLOR,      // 17
+    CMD_SETDRAWMODE    // 18
 } commCommand_t;
\ No newline at end of file
index 9047919927e1e9c8c13a7af57bb5e8e100bb0bb0..316d6539cbe2232f2217a77ecfec7f43c947be2f 100644 (file)
 #include "qwiic.h"
 
 void qwiic_init(void) {
-  #ifdef QWIIC_JOYSTIIC_ENABLE
+#ifdef QWIIC_JOYSTIIC_ENABLE
     joystiic_init();
-  #endif
-  #ifdef QWIIC_MICRO_OLED_ENABLE
+#endif
+#ifdef QWIIC_MICRO_OLED_ENABLE
     micro_oled_init();
-  #endif
+#endif
 }
 
 void qwiic_task(void) {
-  #ifdef QWIIC_JOYSTIIC_ENABLE
+#ifdef QWIIC_JOYSTIIC_ENABLE
     joystiic_task();
-  #endif
+#endif
 }
index 160fb28dfde4aba09e1d011e8672b02dd221bfc1..8c3d1c8d632b0f4d9b417ea447765b2a5d39db4d 100644 (file)
 #include "i2c_master.h"
 
 #ifdef QWIIC_JOYSTIIC_ENABLE
-  #include "joystiic.h"
+#    include "joystiic.h"
 #endif
 #ifdef QWIIC_MICRO_OLED_ENABLE
-  #include "micro_oled.h"
+#    include "micro_oled.h"
 #endif
 
 void qwiic_init(void);
index 0bad206b7c7712f0d95607b7681d6de7d819924a..a641945aaed43af60ff9e9522288144bc4b1ce49 100644 (file)
@@ -29,260 +29,11 @@ https://github.com/emil01/SparkFun_Micro_OLED_Arduino_Library/
 // Standard ASCII 5x7 font
 static const unsigned char font5x7[] PROGMEM = {
     // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256)
-    5,8,0,255,12,75,
-    0x00, 0x00, 0x00, 0x00, 0x00,
-    0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
-    0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
-    0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
-    0x18, 0x3C, 0x7E, 0x3C, 0x18,
-    0x1C, 0x57, 0x7D, 0x57, 0x1C,
-    0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
-    0x00, 0x18, 0x3C, 0x18, 0x00,
-    0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
-    0x00, 0x18, 0x24, 0x18, 0x00,
-    0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
-    0x30, 0x48, 0x3A, 0x06, 0x0E,
-    0x26, 0x29, 0x79, 0x29, 0x26,
-    0x40, 0x7F, 0x05, 0x05, 0x07,
-    0x40, 0x7F, 0x05, 0x25, 0x3F,
-    0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
-    0x7F, 0x3E, 0x1C, 0x1C, 0x08,
-    0x08, 0x1C, 0x1C, 0x3E, 0x7F,
-    0x14, 0x22, 0x7F, 0x22, 0x14,
-    0x5F, 0x5F, 0x00, 0x5F, 0x5F,
-    0x06, 0x09, 0x7F, 0x01, 0x7F,
-    0x00, 0x66, 0x89, 0x95, 0x6A,
-    0x60, 0x60, 0x60, 0x60, 0x60,
-    0x94, 0xA2, 0xFF, 0xA2, 0x94,
-    0x08, 0x04, 0x7E, 0x04, 0x08,
-    0x10, 0x20, 0x7E, 0x20, 0x10,
-    0x08, 0x08, 0x2A, 0x1C, 0x08,
-    0x08, 0x1C, 0x2A, 0x08, 0x08,
-    0x1E, 0x10, 0x10, 0x10, 0x10,
-    0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
-    0x30, 0x38, 0x3E, 0x38, 0x30,
-    0x06, 0x0E, 0x3E, 0x0E, 0x06,
-    0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x5F, 0x00, 0x00,
-    0x00, 0x07, 0x00, 0x07, 0x00,
-    0x14, 0x7F, 0x14, 0x7F, 0x14,
-    0x24, 0x2A, 0x7F, 0x2A, 0x12,
-    0x23, 0x13, 0x08, 0x64, 0x62,
-    0x36, 0x49, 0x56, 0x20, 0x50,
-    0x00, 0x08, 0x07, 0x03, 0x00,
-    0x00, 0x1C, 0x22, 0x41, 0x00,
-    0x00, 0x41, 0x22, 0x1C, 0x00,
-    0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
-    0x08, 0x08, 0x3E, 0x08, 0x08,
-    0x00, 0x80, 0x70, 0x30, 0x00,
-    0x08, 0x08, 0x08, 0x08, 0x08,
-    0x00, 0x00, 0x60, 0x60, 0x00,
-    0x20, 0x10, 0x08, 0x04, 0x02,
-    0x3E, 0x51, 0x49, 0x45, 0x3E,
-    0x00, 0x42, 0x7F, 0x40, 0x00,
-    0x72, 0x49, 0x49, 0x49, 0x46,
-    0x21, 0x41, 0x49, 0x4D, 0x33,
-    0x18, 0x14, 0x12, 0x7F, 0x10,
-    0x27, 0x45, 0x45, 0x45, 0x39,
-    0x3C, 0x4A, 0x49, 0x49, 0x31,
-    0x41, 0x21, 0x11, 0x09, 0x07,
-    0x36, 0x49, 0x49, 0x49, 0x36,
-    0x46, 0x49, 0x49, 0x29, 0x1E,
-    0x00, 0x00, 0x14, 0x00, 0x00,
-    0x00, 0x40, 0x34, 0x00, 0x00,
-    0x00, 0x08, 0x14, 0x22, 0x41,
-    0x14, 0x14, 0x14, 0x14, 0x14,
-    0x00, 0x41, 0x22, 0x14, 0x08,
-    0x02, 0x01, 0x59, 0x09, 0x06,
-    0x3E, 0x41, 0x5D, 0x59, 0x4E,
-    0x7C, 0x12, 0x11, 0x12, 0x7C,
-    0x7F, 0x49, 0x49, 0x49, 0x36,
-    0x3E, 0x41, 0x41, 0x41, 0x22,
-    0x7F, 0x41, 0x41, 0x41, 0x3E,
-    0x7F, 0x49, 0x49, 0x49, 0x41,
-    0x7F, 0x09, 0x09, 0x09, 0x01,
-    0x3E, 0x41, 0x41, 0x51, 0x73,
-    0x7F, 0x08, 0x08, 0x08, 0x7F,
-    0x00, 0x41, 0x7F, 0x41, 0x00,
-    0x20, 0x40, 0x41, 0x3F, 0x01,
-    0x7F, 0x08, 0x14, 0x22, 0x41,
-    0x7F, 0x40, 0x40, 0x40, 0x40,
-    0x7F, 0x02, 0x1C, 0x02, 0x7F,
-    0x7F, 0x04, 0x08, 0x10, 0x7F,
-    0x3E, 0x41, 0x41, 0x41, 0x3E,
-    0x7F, 0x09, 0x09, 0x09, 0x06,
-    0x3E, 0x41, 0x51, 0x21, 0x5E,
-    0x7F, 0x09, 0x19, 0x29, 0x46,
-    0x26, 0x49, 0x49, 0x49, 0x32,
-    0x03, 0x01, 0x7F, 0x01, 0x03,
-    0x3F, 0x40, 0x40, 0x40, 0x3F,
-    0x1F, 0x20, 0x40, 0x20, 0x1F,
-    0x3F, 0x40, 0x38, 0x40, 0x3F,
-    0x63, 0x14, 0x08, 0x14, 0x63,
-    0x03, 0x04, 0x78, 0x04, 0x03,
-    0x61, 0x59, 0x49, 0x4D, 0x43,
-    0x00, 0x7F, 0x41, 0x41, 0x41,
-    0x02, 0x04, 0x08, 0x10, 0x20,
-    0x00, 0x41, 0x41, 0x41, 0x7F,
-    0x04, 0x02, 0x01, 0x02, 0x04,
-    0x40, 0x40, 0x40, 0x40, 0x40,
-    0x00, 0x03, 0x07, 0x08, 0x00,
-    0x20, 0x54, 0x54, 0x78, 0x40,
-    0x7F, 0x28, 0x44, 0x44, 0x38,
-    0x38, 0x44, 0x44, 0x44, 0x28,
-    0x38, 0x44, 0x44, 0x28, 0x7F,
-    0x38, 0x54, 0x54, 0x54, 0x18,
-    0x00, 0x08, 0x7E, 0x09, 0x02,
-    0x18, 0xA4, 0xA4, 0x9C, 0x78,
-    0x7F, 0x08, 0x04, 0x04, 0x78,
-    0x00, 0x44, 0x7D, 0x40, 0x00,
-    0x20, 0x40, 0x40, 0x3D, 0x00,
-    0x7F, 0x10, 0x28, 0x44, 0x00,
-    0x00, 0x41, 0x7F, 0x40, 0x00,
-    0x7C, 0x04, 0x78, 0x04, 0x78,
-    0x7C, 0x08, 0x04, 0x04, 0x78,
-    0x38, 0x44, 0x44, 0x44, 0x38,
-    0xFC, 0x18, 0x24, 0x24, 0x18,
-    0x18, 0x24, 0x24, 0x18, 0xFC,
-    0x7C, 0x08, 0x04, 0x04, 0x08,
-    0x48, 0x54, 0x54, 0x54, 0x24,
-    0x04, 0x04, 0x3F, 0x44, 0x24,
-    0x3C, 0x40, 0x40, 0x20, 0x7C,
-    0x1C, 0x20, 0x40, 0x20, 0x1C,
-    0x3C, 0x40, 0x30, 0x40, 0x3C,
-    0x44, 0x28, 0x10, 0x28, 0x44,
-    0x4C, 0x90, 0x90, 0x90, 0x7C,
-    0x44, 0x64, 0x54, 0x4C, 0x44,
-    0x00, 0x08, 0x36, 0x41, 0x00,
-    0x00, 0x00, 0x77, 0x00, 0x00,
-    0x00, 0x41, 0x36, 0x08, 0x00,
-    0x02, 0x01, 0x02, 0x04, 0x02,
-    0x3C, 0x26, 0x23, 0x26, 0x3C,
-    0x1E, 0xA1, 0xA1, 0x61, 0x12,
-    0x3A, 0x40, 0x40, 0x20, 0x7A,
-    0x38, 0x54, 0x54, 0x55, 0x59,
-    0x21, 0x55, 0x55, 0x79, 0x41,
-    0x21, 0x54, 0x54, 0x78, 0x41,
-    0x21, 0x55, 0x54, 0x78, 0x40,
-    0x20, 0x54, 0x55, 0x79, 0x40,
-    0x0C, 0x1E, 0x52, 0x72, 0x12,
-    0x39, 0x55, 0x55, 0x55, 0x59,
-    0x39, 0x54, 0x54, 0x54, 0x59,
-    0x39, 0x55, 0x54, 0x54, 0x58,
-    0x00, 0x00, 0x45, 0x7C, 0x41,
-    0x00, 0x02, 0x45, 0x7D, 0x42,
-    0x00, 0x01, 0x45, 0x7C, 0x40,
-    0xF0, 0x29, 0x24, 0x29, 0xF0,
-    0xF0, 0x28, 0x25, 0x28, 0xF0,
-    0x7C, 0x54, 0x55, 0x45, 0x00,
-    0x20, 0x54, 0x54, 0x7C, 0x54,
-    0x7C, 0x0A, 0x09, 0x7F, 0x49,
-    0x32, 0x49, 0x49, 0x49, 0x32,
-    0x32, 0x48, 0x48, 0x48, 0x32,
-    0x32, 0x4A, 0x48, 0x48, 0x30,
-    0x3A, 0x41, 0x41, 0x21, 0x7A,
-    0x3A, 0x42, 0x40, 0x20, 0x78,
-    0x00, 0x9D, 0xA0, 0xA0, 0x7D,
-    0x39, 0x44, 0x44, 0x44, 0x39,
-    0x3D, 0x40, 0x40, 0x40, 0x3D,
-    0x3C, 0x24, 0xFF, 0x24, 0x24,
-    0x48, 0x7E, 0x49, 0x43, 0x66,
-    0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
-    0xFF, 0x09, 0x29, 0xF6, 0x20,
-    0xC0, 0x88, 0x7E, 0x09, 0x03,
-    0x20, 0x54, 0x54, 0x79, 0x41,
-    0x00, 0x00, 0x44, 0x7D, 0x41,
-    0x30, 0x48, 0x48, 0x4A, 0x32,
-    0x38, 0x40, 0x40, 0x22, 0x7A,
-    0x00, 0x7A, 0x0A, 0x0A, 0x72,
-    0x7D, 0x0D, 0x19, 0x31, 0x7D,
-    0x26, 0x29, 0x29, 0x2F, 0x28,
-    0x26, 0x29, 0x29, 0x29, 0x26,
-    0x30, 0x48, 0x4D, 0x40, 0x20,
-    0x38, 0x08, 0x08, 0x08, 0x08,
-    0x08, 0x08, 0x08, 0x08, 0x38,
-    0x2F, 0x10, 0xC8, 0xAC, 0xBA,
-    0x2F, 0x10, 0x28, 0x34, 0xFA,
-    0x00, 0x00, 0x7B, 0x00, 0x00,
-    0x08, 0x14, 0x2A, 0x14, 0x22,
-    0x22, 0x14, 0x2A, 0x14, 0x08,
-    0xAA, 0x00, 0x55, 0x00, 0xAA,
-    0xAA, 0x55, 0xAA, 0x55, 0xAA,
-    0x00, 0x00, 0x00, 0xFF, 0x00,
-    0x10, 0x10, 0x10, 0xFF, 0x00,
-    0x14, 0x14, 0x14, 0xFF, 0x00,
-    0x10, 0x10, 0xFF, 0x00, 0xFF,
-    0x10, 0x10, 0xF0, 0x10, 0xF0,
-    0x14, 0x14, 0x14, 0xFC, 0x00,
-    0x14, 0x14, 0xF7, 0x00, 0xFF,
-    0x00, 0x00, 0xFF, 0x00, 0xFF,
-    0x14, 0x14, 0xF4, 0x04, 0xFC,
-    0x14, 0x14, 0x17, 0x10, 0x1F,
-    0x10, 0x10, 0x1F, 0x10, 0x1F,
-    0x14, 0x14, 0x14, 0x1F, 0x00,
-    0x10, 0x10, 0x10, 0xF0, 0x00,
-    0x00, 0x00, 0x00, 0x1F, 0x10,
-    0x10, 0x10, 0x10, 0x1F, 0x10,
-    0x10, 0x10, 0x10, 0xF0, 0x10,
-    0x00, 0x00, 0x00, 0xFF, 0x10,
-    0x10, 0x10, 0x10, 0x10, 0x10,
-    0x10, 0x10, 0x10, 0xFF, 0x10,
-    0x00, 0x00, 0x00, 0xFF, 0x14,
-    0x00, 0x00, 0xFF, 0x00, 0xFF,
-    0x00, 0x00, 0x1F, 0x10, 0x17,
-    0x00, 0x00, 0xFC, 0x04, 0xF4,
-    0x14, 0x14, 0x17, 0x10, 0x17,
-    0x14, 0x14, 0xF4, 0x04, 0xF4,
-    0x00, 0x00, 0xFF, 0x00, 0xF7,
-    0x14, 0x14, 0x14, 0x14, 0x14,
-    0x14, 0x14, 0xF7, 0x00, 0xF7,
-    0x14, 0x14, 0x14, 0x17, 0x14,
-    0x10, 0x10, 0x1F, 0x10, 0x1F,
-    0x14, 0x14, 0x14, 0xF4, 0x14,
-    0x10, 0x10, 0xF0, 0x10, 0xF0,
-    0x00, 0x00, 0x1F, 0x10, 0x1F,
-    0x00, 0x00, 0x00, 0x1F, 0x14,
-    0x00, 0x00, 0x00, 0xFC, 0x14,
-    0x00, 0x00, 0xF0, 0x10, 0xF0,
-    0x10, 0x10, 0xFF, 0x10, 0xFF,
-    0x14, 0x14, 0x14, 0xFF, 0x14,
-    0x10, 0x10, 0x10, 0x1F, 0x00,
-    0x00, 0x00, 0x00, 0xF0, 0x10,
-    0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-    0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
-    0xFF, 0xFF, 0xFF, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0xFF, 0xFF,
-    0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
-    0x38, 0x44, 0x44, 0x38, 0x44,
-    0x7C, 0x2A, 0x2A, 0x3E, 0x14,
-    0x7E, 0x02, 0x02, 0x06, 0x06,
-    0x02, 0x7E, 0x02, 0x7E, 0x02,
-    0x63, 0x55, 0x49, 0x41, 0x63,
-    0x38, 0x44, 0x44, 0x3C, 0x04,
-    0x40, 0x7E, 0x20, 0x1E, 0x20,
-    0x06, 0x02, 0x7E, 0x02, 0x02,
-    0x99, 0xA5, 0xE7, 0xA5, 0x99,
-    0x1C, 0x2A, 0x49, 0x2A, 0x1C,
-    0x4C, 0x72, 0x01, 0x72, 0x4C,
-    0x30, 0x4A, 0x4D, 0x4D, 0x30,
-    0x30, 0x48, 0x78, 0x48, 0x30,
-    0xBC, 0x62, 0x5A, 0x46, 0x3D,
-    0x3E, 0x49, 0x49, 0x49, 0x00,
-    0x7E, 0x01, 0x01, 0x01, 0x7E,
-    0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
-    0x44, 0x44, 0x5F, 0x44, 0x44,
-    0x40, 0x51, 0x4A, 0x44, 0x40,
-    0x40, 0x44, 0x4A, 0x51, 0x40,
-    0x00, 0x00, 0xFF, 0x01, 0x03,
-    0xE0, 0x80, 0xFF, 0x00, 0x00,
-    0x08, 0x08, 0x6B, 0x6B, 0x08,
-    0x36, 0x12, 0x36, 0x24, 0x36,
-    0x06, 0x0F, 0x09, 0x0F, 0x06,
-    0x00, 0x00, 0x18, 0x18, 0x00,
-    0x00, 0x00, 0x10, 0x10, 0x00,
-    0x30, 0x40, 0xFF, 0x01, 0x01,
-    0x00, 0x1F, 0x01, 0x01, 0x1E,
-    0x00, 0x19, 0x1D, 0x17, 0x12,
-    0x00, 0x3C, 0x3C, 0x3C, 0x3C,
-    0x00, 0x00, 0x00, 0x00, 0x00
-};
+    5,    8,    0,    255,  12,   75,   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, 0x18, 0x3C, 0x18, 0x00, 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, 0x18, 0x24, 0x18, 0x00, 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x26, 0x29, 0x79, 0x29, 0x26, 0x40, 0x7F, 0x05, 0x05, 0x07, 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, 0x66, 0x89, 0x95, 0x6A, 0x60, 0x60, 0x60, 0x60, 0x60, 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x08, 0x04, 0x7E, 0x04, 0x08, 0x10, 0x20, 0x7E, 0x20, 0x10, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x1E, 0x10, 0x10, 0x10, 0x10, 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x30, 0x38, 0x3E, 0x38, 0x30,
+    0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x23, 0x13, 0x08, 0x64, 0x62, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x80, 0x70, 0x30, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x60, 0x60, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x72, 0x49, 0x49, 0x49, 0x46, 0x21, 0x41, 0x49, 0x4D, 0x33, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x27, 0x45, 0x45, 0x45, 0x39, 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x41, 0x21, 0x11, 0x09, 0x07, 0x36, 0x49, 0x49, 0x49, 0x36, 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x40, 0x34, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x41, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x41, 0x22, 0x14, 0x08, 0x02,
+    0x01, 0x59, 0x09, 0x06, 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x3E, 0x41, 0x41, 0x51, 0x73, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x26, 0x49, 0x49, 0x49, 0x32, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x63, 0x14, 0x08, 0x14, 0x63, 0x03, 0x04, 0x78, 0x04, 0x03, 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x04, 0x02, 0x01, 0x02, 0x04, 0x40, 0x40,
+    0x40, 0x40, 0x40, 0x00, 0x03, 0x07, 0x08, 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x38, 0x44, 0x44, 0x44, 0x28, 0x38, 0x44, 0x44, 0x28, 0x7F, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x08, 0x7E, 0x09, 0x02, 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x20, 0x40, 0x40, 0x3D, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x7C, 0x04, 0x78, 0x04, 0x78, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x38, 0x44, 0x44, 0x44, 0x38, 0xFC, 0x18, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x48, 0x54, 0x54, 0x54, 0x24, 0x04, 0x04, 0x3F, 0x44, 0x24, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x44, 0x28, 0x10, 0x28, 0x44, 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 0x02, 0x01, 0x02, 0x04, 0x02, 0x3C, 0x26, 0x23,
+    0x26, 0x3C, 0x1E, 0xA1, 0xA1, 0x61, 0x12, 0x3A, 0x40, 0x40, 0x20, 0x7A, 0x38, 0x54, 0x54, 0x55, 0x59, 0x21, 0x55, 0x55, 0x79, 0x41, 0x21, 0x54, 0x54, 0x78, 0x41, 0x21, 0x55, 0x54, 0x78, 0x40, 0x20, 0x54, 0x55, 0x79, 0x40, 0x0C, 0x1E, 0x52, 0x72, 0x12, 0x39, 0x55, 0x55, 0x55, 0x59, 0x39, 0x54, 0x54, 0x54, 0x59, 0x39, 0x55, 0x54, 0x54, 0x58, 0x00, 0x00, 0x45, 0x7C, 0x41, 0x00, 0x02, 0x45, 0x7D, 0x42, 0x00, 0x01, 0x45, 0x7C, 0x40, 0xF0, 0x29, 0x24, 0x29, 0xF0, 0xF0, 0x28, 0x25, 0x28, 0xF0, 0x7C, 0x54, 0x55, 0x45, 0x00, 0x20, 0x54, 0x54, 0x7C, 0x54, 0x7C, 0x0A, 0x09, 0x7F, 0x49, 0x32, 0x49, 0x49, 0x49, 0x32, 0x32, 0x48, 0x48, 0x48, 0x32, 0x32, 0x4A, 0x48, 0x48, 0x30, 0x3A, 0x41, 0x41, 0x21, 0x7A, 0x3A, 0x42, 0x40, 0x20, 0x78, 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 0x39, 0x44, 0x44, 0x44, 0x39, 0x3D, 0x40, 0x40, 0x40, 0x3D, 0x3C, 0x24, 0xFF, 0x24, 0x24, 0x48, 0x7E, 0x49, 0x43, 0x66, 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 0xFF, 0x09, 0x29, 0xF6, 0x20, 0xC0, 0x88, 0x7E, 0x09,
+    0x03, 0x20, 0x54, 0x54, 0x79, 0x41, 0x00, 0x00, 0x44, 0x7D, 0x41, 0x30, 0x48, 0x48, 0x4A, 0x32, 0x38, 0x40, 0x40, 0x22, 0x7A, 0x00, 0x7A, 0x0A, 0x0A, 0x72, 0x7D, 0x0D, 0x19, 0x31, 0x7D, 0x26, 0x29, 0x29, 0x2F, 0x28, 0x26, 0x29, 0x29, 0x29, 0x26, 0x30, 0x48, 0x4D, 0x40, 0x20, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 0x2F, 0x10, 0x28, 0x34, 0xFA, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x08, 0x14, 0x2A, 0x14, 0x22, 0x22, 0x14, 0x2A, 0x14, 0x08, 0xAA, 0x00, 0x55, 0x00, 0xAA, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x10, 0x10, 0xFF, 0x00, 0x14, 0x14, 0x14, 0xFF, 0x00, 0x10, 0x10, 0xFF, 0x00, 0xFF, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x14, 0x14, 0x14, 0xFC, 0x00, 0x14, 0x14, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x14, 0x14, 0xF4, 0x04, 0xFC, 0x14, 0x14, 0x17, 0x10, 0x1F, 0x10, 0x10, 0x1F, 0x10, 0x1F, 0x14, 0x14, 0x14, 0x1F, 0x00, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10,
+    0x10, 0x10, 0x10, 0x1F, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x14, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x1F, 0x10, 0x17, 0x00, 0x00, 0xFC, 0x04, 0xF4, 0x14, 0x14, 0x17, 0x10, 0x17, 0x14, 0x14, 0xF4, 0x04, 0xF4, 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0xF7, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x17, 0x14, 0x10, 0x10, 0x1F, 0x10, 0x1F, 0x14, 0x14, 0x14, 0xF4, 0x14, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00, 0x1F, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x14, 0x00, 0x00, 0x00, 0xFC, 0x14, 0x00, 0x00, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0xFF, 0x10, 0xFF, 0x14, 0x14, 0x14, 0xFF, 0x14, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x38, 0x44, 0x44, 0x38, 0x44, 0x7C,
+    0x2A, 0x2A, 0x3E, 0x14, 0x7E, 0x02, 0x02, 0x06, 0x06, 0x02, 0x7E, 0x02, 0x7E, 0x02, 0x63, 0x55, 0x49, 0x41, 0x63, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x40, 0x7E, 0x20, 0x1E, 0x20, 0x06, 0x02, 0x7E, 0x02, 0x02, 0x99, 0xA5, 0xE7, 0xA5, 0x99, 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 0x4C, 0x72, 0x01, 0x72, 0x4C, 0x30, 0x4A, 0x4D, 0x4D, 0x30, 0x30, 0x48, 0x78, 0x48, 0x30, 0xBC, 0x62, 0x5A, 0x46, 0x3D, 0x3E, 0x49, 0x49, 0x49, 0x00, 0x7E, 0x01, 0x01, 0x01, 0x7E, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x44, 0x44, 0x5F, 0x44, 0x44, 0x40, 0x51, 0x4A, 0x44, 0x40, 0x40, 0x44, 0x4A, 0x51, 0x40, 0x00, 0x00, 0xFF, 0x01, 0x03, 0xE0, 0x80, 0xFF, 0x00, 0x00, 0x08, 0x08, 0x6B, 0x6B, 0x08, 0x36, 0x12, 0x36, 0x24, 0x36, 0x06, 0x0F, 0x09, 0x0F, 0x06, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x30, 0x40, 0xFF, 0x01, 0x01, 0x00, 0x1F, 0x01, 0x01, 0x1E, 0x00, 0x19, 0x1D, 0x17, 0x12, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00};
index c070e4ec8ca1dc9bc5271fe02ac9332d95b7a73b..4d3c23786620dc48c5e5bb1e54395f8bfd62cdad 100644 (file)
@@ -27,101 +27,13 @@ https://github.com/emil01/SparkFun_Micro_OLED_Arduino_Library/
 
 static const unsigned char font8x16[] PROGMEM = {
     // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256)
-    8,16,32,96,2,56,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xBE, 0x90, 0xD0, 0xBE, 0x90, 0x00,
-    0x00, 0x1C, 0x62, 0xFF, 0xC2, 0x80, 0x00, 0x00, 0x0C, 0x12, 0x92, 0x4C, 0xB0, 0x88, 0x06, 0x00,
-    0x80, 0x7C, 0x62, 0xB2, 0x1C, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0xE0, 0x18, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x18, 0xE0, 0x00, 0x00,
-    0x00, 0x24, 0x18, 0x7E, 0x18, 0x24, 0x00, 0x00, 0x80, 0x80, 0x80, 0xF0, 0x80, 0x80, 0x80, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x06, 0x00, 0x00,
-    0xF8, 0x04, 0xC2, 0x32, 0x0C, 0xF8, 0x00, 0x00, 0x00, 0x04, 0x04, 0xFE, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x02, 0x82, 0x42, 0x22, 0x1C, 0x00, 0x00, 0x00, 0x02, 0x22, 0x22, 0x22, 0xDC, 0x00, 0x00,
-    0xC0, 0xA0, 0x98, 0x84, 0xFE, 0x80, 0x80, 0x00, 0x00, 0x1E, 0x12, 0x12, 0x22, 0xC2, 0x00, 0x00,
-    0xF8, 0x44, 0x22, 0x22, 0x22, 0xC0, 0x00, 0x00, 0x00, 0x02, 0x02, 0xC2, 0x32, 0x0A, 0x06, 0x00,
-    0x00, 0x8C, 0x52, 0x22, 0x52, 0x8C, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x26, 0xF8, 0x00, 0x00,
-    0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00,
-    0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00,
-    0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, 0x02, 0x82, 0x42, 0x22, 0x1C, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
-    0x00, 0x04, 0x04, 0x0F, 0x04, 0x03, 0x00, 0x00, 0x04, 0x02, 0x01, 0x03, 0x04, 0x04, 0x03, 0x00,
-    0x03, 0x04, 0x04, 0x04, 0x05, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x03, 0x06, 0x08, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x06, 0x03, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x01, 0x03, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x04, 0x04, 0x07, 0x04, 0x04, 0x00, 0x00,
-    0x00, 0x07, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00,
-    0x01, 0x02, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x03, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00,
-    0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x04, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
-    0x04, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0xF8, 0x04, 0x72, 0x8A, 0xFA, 0x84, 0x78, 0x00, 0x00, 0xC0, 0x38, 0x06, 0x38, 0xC0, 0x00, 0x00,
-    0x00, 0xFE, 0x22, 0x22, 0x22, 0xDC, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00,
-    0xFE, 0x02, 0x02, 0x02, 0x04, 0xF8, 0x00, 0x00, 0x00, 0xFE, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00,
-    0x00, 0xFE, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x22, 0xE2, 0x00, 0x00,
-    0xFE, 0x20, 0x20, 0x20, 0x20, 0xFE, 0x00, 0x00, 0x00, 0x02, 0x02, 0xFE, 0x02, 0x02, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x02, 0x02, 0xFE, 0x00, 0x00, 0xFE, 0x40, 0xB0, 0x08, 0x04, 0x02, 0x00, 0x00,
-    0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x0C, 0x70, 0x80, 0x70, 0x0C, 0xFE, 0x00,
-    0xFE, 0x0C, 0x30, 0xC0, 0x00, 0xFE, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x04, 0xF8, 0x00, 0x00,
-    0xFE, 0x42, 0x42, 0x42, 0x22, 0x1C, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x04, 0xF8, 0x00, 0x00,
-    0x00, 0xFE, 0x42, 0x42, 0xA2, 0x1C, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x42, 0x42, 0x80, 0x00, 0x00,
-    0x02, 0x02, 0x02, 0xFE, 0x02, 0x02, 0x02, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00,
-    0x06, 0x38, 0xC0, 0x00, 0xC0, 0x38, 0x06, 0x00, 0x3E, 0xC0, 0xF0, 0x0E, 0xF0, 0xC0, 0x3E, 0x00,
-    0x00, 0x06, 0x98, 0x60, 0x98, 0x06, 0x00, 0x00, 0x00, 0x06, 0x18, 0xE0, 0x18, 0x06, 0x00, 0x00,
-    0x02, 0x02, 0xC2, 0x32, 0x0A, 0x06, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x02, 0x02, 0x02, 0x02, 0x00,
-    0x00, 0x06, 0x18, 0x60, 0x80, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00,
-    0x40, 0x30, 0x0C, 0x0C, 0x30, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x01, 0x02, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x06, 0x01, 0x01, 0x01, 0x01, 0x01, 0x06, 0x00,
-    0x00, 0x07, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00,
-    0x07, 0x04, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00,
-    0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x04, 0x07, 0x00, 0x00,
-    0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x04, 0x07, 0x04, 0x04, 0x00, 0x00,
-    0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00,
-    0x00, 0x07, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07, 0x00,
-    0x07, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00,
-    0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0C, 0x12, 0x11, 0x10, 0x00,
-    0x00, 0x07, 0x00, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00,
-    0x00, 0x00, 0x01, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
-    0x00, 0x06, 0x01, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00,
-    0x06, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x10, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x00, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
-    0x00, 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00,
-    0x00, 0xFE, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00,
-    0x00, 0xE0, 0x10, 0x10, 0x10, 0xFE, 0x00, 0x00, 0x00, 0xE0, 0x90, 0x90, 0x90, 0xE0, 0x00, 0x00,
-    0x00, 0x20, 0xFC, 0x22, 0x22, 0x22, 0x02, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00,
-    0x00, 0xFE, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x10, 0x10, 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x10, 0x10, 0x10, 0xF2, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x80, 0x40, 0x20, 0x10, 0x00, 0x00,
-    0x00, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x20, 0x10, 0xF0, 0x20, 0x10, 0xF0, 0x00,
-    0x00, 0xF0, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xE0, 0x00, 0x00,
-    0x00, 0xF0, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00,
-    0x00, 0xF0, 0x20, 0x10, 0x10, 0x70, 0x00, 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x20, 0x00, 0x00,
-    0x00, 0x20, 0x20, 0xFC, 0x20, 0x20, 0x20, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00,
-    0x00, 0x70, 0x80, 0x00, 0x80, 0x70, 0x00, 0x00, 0xF0, 0x00, 0xC0, 0x30, 0xC0, 0x00, 0xF0, 0x00,
-    0x00, 0x30, 0xC0, 0xC0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0xC0, 0x00, 0x80, 0x70, 0x00, 0x00,
-    0x00, 0x10, 0x10, 0x90, 0x50, 0x30, 0x00, 0x00, 0x00, 0x80, 0x80, 0x7E, 0x02, 0x02, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x7E, 0x80, 0x80, 0x00, 0x00,
-    0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x02, 0x07, 0x00, 0x00,
-    0x00, 0x07, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00,
-    0x00, 0x03, 0x04, 0x04, 0x02, 0x07, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00,
-    0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x24, 0x24, 0x22, 0x1F, 0x00, 0x00,
-    0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x00, 0x00, 0x00,
-    0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x00, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00,
-    0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00,
-    0x00, 0x3F, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x02, 0x3F, 0x00, 0x00,
-    0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x00, 0x00, 0x03, 0x04, 0x04, 0x02, 0x07, 0x00, 0x00,
-    0x00, 0x00, 0x03, 0x04, 0x03, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x00, 0x01, 0x06, 0x01, 0x00,
-    0x00, 0x06, 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x20, 0x20, 0x31, 0x0E, 0x03, 0x00, 0x00, 0x00,
-    0x00, 0x06, 0x05, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00,
-    0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
+    8,    16,   32,   96,   2,    56,   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xBE, 0x90, 0xD0, 0xBE, 0x90, 0x00, 0x00, 0x1C, 0x62, 0xFF, 0xC2, 0x80, 0x00, 0x00, 0x0C, 0x12, 0x92, 0x4C, 0xB0, 0x88, 0x06, 0x00, 0x80, 0x7C, 0x62, 0xB2, 0x1C, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x18, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x18, 0xE0, 0x00, 0x00, 0x00, 0x24, 0x18, 0x7E, 0x18, 0x24, 0x00, 0x00, 0x80, 0x80, 0x80, 0xF0, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x06, 0x00, 0x00, 0xF8, 0x04, 0xC2, 0x32, 0x0C, 0xF8, 0x00, 0x00, 0x00, 0x04, 0x04, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x82, 0x42, 0x22,
+    0x1C, 0x00, 0x00, 0x00, 0x02, 0x22, 0x22, 0x22, 0xDC, 0x00, 0x00, 0xC0, 0xA0, 0x98, 0x84, 0xFE, 0x80, 0x80, 0x00, 0x00, 0x1E, 0x12, 0x12, 0x22, 0xC2, 0x00, 0x00, 0xF8, 0x44, 0x22, 0x22, 0x22, 0xC0, 0x00, 0x00, 0x00, 0x02, 0x02, 0xC2, 0x32, 0x0A, 0x06, 0x00, 0x00, 0x8C, 0x52, 0x22, 0x52, 0x8C, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x26, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, 0x02, 0x82, 0x42, 0x22, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x0F, 0x04, 0x03, 0x00, 0x00, 0x04, 0x02, 0x01, 0x03, 0x04, 0x04, 0x03, 0x00,
+    0x03, 0x04, 0x04, 0x04, 0x05, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x08, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x04, 0x04, 0x07, 0x04, 0x04, 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x04, 0x04,
+    0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x04, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x04, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x04, 0x72, 0x8A, 0xFA, 0x84, 0x78, 0x00, 0x00, 0xC0, 0x38, 0x06, 0x38, 0xC0, 0x00, 0x00, 0x00, 0xFE, 0x22, 0x22, 0x22, 0xDC, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0xFE, 0x02, 0x02, 0x02, 0x04, 0xF8, 0x00, 0x00, 0x00, 0xFE, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0xFE, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x22, 0xE2, 0x00, 0x00, 0xFE, 0x20, 0x20, 0x20, 0x20, 0xFE, 0x00, 0x00, 0x00, 0x02, 0x02, 0xFE, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0xFE, 0x00, 0x00, 0xFE, 0x40, 0xB0, 0x08, 0x04, 0x02, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0xFE, 0x0C, 0x70, 0x80, 0x70, 0x0C, 0xFE, 0x00, 0xFE, 0x0C, 0x30, 0xC0, 0x00, 0xFE, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x04, 0xF8, 0x00, 0x00, 0xFE, 0x42, 0x42, 0x42, 0x22, 0x1C, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x04, 0xF8, 0x00, 0x00, 0x00, 0xFE, 0x42, 0x42, 0xA2, 0x1C, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x42, 0x42, 0x80, 0x00, 0x00, 0x02, 0x02, 0x02, 0xFE, 0x02, 0x02, 0x02, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x06, 0x38, 0xC0, 0x00, 0xC0, 0x38, 0x06, 0x00, 0x3E, 0xC0, 0xF0, 0x0E, 0xF0, 0xC0, 0x3E, 0x00, 0x00, 0x06, 0x98, 0x60, 0x98, 0x06, 0x00, 0x00, 0x00, 0x06, 0x18, 0xE0, 0x18, 0x06, 0x00, 0x00, 0x02, 0x02, 0xC2, 0x32, 0x0A, 0x06, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x06, 0x18, 0x60, 0x80, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00, 0x40, 0x30, 0x0C, 0x0C, 0x30, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+    0x02, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x06, 0x01, 0x01, 0x01, 0x01, 0x01, 0x06, 0x00, 0x00, 0x07, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x07, 0x04, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x04, 0x07, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x04, 0x07, 0x04, 0x04, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0C, 0x12, 0x11, 0x10, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,
+    0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x01, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x06, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x00, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0xFE, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xFE, 0x00, 0x00, 0x00, 0xE0, 0x90, 0x90, 0x90, 0xE0, 0x00, 0x00, 0x00, 0x20, 0xFC, 0x22, 0x22, 0x22, 0x02,
+    0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0xFE, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x10, 0x10, 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0xF2, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x80, 0x40, 0x20, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x20, 0x10, 0xF0, 0x20, 0x10, 0xF0, 0x00, 0x00, 0xF0, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x00, 0xF0, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0x20, 0x10, 0x10, 0x70, 0x00, 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x20, 0x00, 0x00, 0x00, 0x20, 0x20, 0xFC, 0x20, 0x20, 0x20, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x70, 0x80, 0x00, 0x80, 0x70, 0x00, 0x00, 0xF0, 0x00, 0xC0, 0x30, 0xC0, 0x00, 0xF0, 0x00, 0x00, 0x30, 0xC0, 0xC0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0xC0, 0x00, 0x80, 0x70, 0x00, 0x00, 0x00, 0x10,
+    0x10, 0x90, 0x50, 0x30, 0x00, 0x00, 0x00, 0x80, 0x80, 0x7E, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x7E, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x02, 0x07, 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x02, 0x07, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x24, 0x24, 0x22, 0x1F, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x00, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00,
+    0x00, 0x07, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x3F, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x02, 0x3F, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x00, 0x00, 0x03, 0x04, 0x04, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x03, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x00, 0x01, 0x06, 0x01, 0x00, 0x00, 0x06, 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x20, 0x20, 0x31, 0x0E, 0x03, 0x00, 0x00, 0x00, 0x00, 0x06, 0x05, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
index f248cc25baf64ce7080a84ac39265754f2b2c927..0755ddf6c4fe6ac1713a2a85665506bd0ad5728b 100644 (file)
@@ -19,54 +19,53 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define _GDISP_LLD_BOARD_H
 
 static const I2CConfig i2ccfg = {
-  400000 // clock speed (Hz); 400kHz max for IS31
+    400000  // clock speed (Hz); 400kHz max for IS31
 };
 
 static const uint8_t led_mask[] = {
-       0xFF, 0x00, /* C1-1 -> C1-16 */
-       0xFF, 0x00, /* C2-1 -> C2-16 */
-       0xFF, 0x00, /* C3-1 -> C3-16 */
-       0xFF, 0x00, /* C4-1 -> C4-16 */
-       0x3F, 0x00, /* C5-1 -> C5-16 */
-       0x00, 0x00, /* C6-1 -> C6-16 */
-       0x00, 0x00, /* C7-1 -> C7-16 */
-       0x00, 0x00, /* C8-1 -> C8-16 */
-       0x00, 0x00, /* C9-1 -> C9-16 */
+    0xFF, 0x00, /* C1-1 -> C1-16 */
+    0xFF, 0x00, /* C2-1 -> C2-16 */
+    0xFF, 0x00, /* C3-1 -> C3-16 */
+    0xFF, 0x00, /* C4-1 -> C4-16 */
+    0x3F, 0x00, /* C5-1 -> C5-16 */
+    0x00, 0x00, /* C6-1 -> C6-16 */
+    0x00, 0x00, /* C7-1 -> C7-16 */
+    0x00, 0x00, /* C8-1 -> C8-16 */
+    0x00, 0x00, /* C9-1 -> C9-16 */
 };
 
 // The address of the LED
-#define LA(c, r) (c + r * 16 )
+#define LA(c, r) (c + r * 16)
 // Need to be an address that is not mapped, but inside the range of the controller matrix
 #define NA LA(8, 8)
 
 // The numbers in the comments are the led numbers DXX on the PCB
 // The mapping is taken from the schematic of left hand side
 static const uint8_t led_mapping[GDISP_SCREEN_HEIGHT][GDISP_SCREEN_WIDTH] = {
-//   45        44        43        42        41        40        39
-   LA(1, 1), LA(1, 0), LA(0, 4), LA(0, 3), LA(0, 2), LA(0, 1), LA(0, 0)},
-//   52        51        50        49        48        47        46
-   { LA(2, 3), LA(2, 2), LA(2, 1), LA(2, 0), LA(1, 4), LA(1, 3), LA(1, 2) },
-//   58        57        56        55        54        53        N/A
-   { LA(3, 4), LA(3, 3), LA(3, 2), LA(3, 1), LA(3, 0), LA(2, 4), NA },
-//   67        66        65        64        63        62        61
-   { LA(5, 3), LA(5, 2), LA(5, 1), LA(5, 0), LA(4, 4), LA(4, 3), LA(4, 2) },
-//   76        75        74        73        72        60        59
-   { LA(7, 3), LA(7, 2), LA(7, 1), LA(7, 0), LA(6, 3), LA(4, 1), LA(4, 0) },
-//   N/A       N/A       N/A       N/A       N/A       N/A       68
-   { NA,       NA,       NA,       NA,       NA,       NA,       LA(5, 4) },
-//   N/A       N/A       N/A       N/A       71        70        69
-   { NA,       NA,       NA,       NA,       LA(6, 2), LA(6, 1), LA(6, 0) },
+    //   45        44        43        42        41        40        39
+    {LA(1, 1), LA(1, 0), LA(0, 4), LA(0, 3), LA(0, 2), LA(0, 1), LA(0, 0)},
+    //   52        51        50        49        48        47        46
+    {LA(2, 3), LA(2, 2), LA(2, 1), LA(2, 0), LA(1, 4), LA(1, 3), LA(1, 2)},
+    //   58        57        56        55        54        53        N/A
+    {LA(3, 4), LA(3, 3), LA(3, 2), LA(3, 1), LA(3, 0), LA(2, 4), NA},
+    //   67        66        65        64        63        62        61
+    {LA(5, 3), LA(5, 2), LA(5, 1), LA(5, 0), LA(4, 4), LA(4, 3), LA(4, 2)},
+    //   76        75        74        73        72        60        59
+    {LA(7, 3), LA(7, 2), LA(7, 1), LA(7, 0), LA(6, 3), LA(4, 1), LA(4, 0)},
+    //   N/A       N/A       N/A       N/A       N/A       N/A       68
+    {NA, NA, NA, NA, NA, NA, LA(5, 4)},
+    //   N/A       N/A       N/A       N/A       71        70        69
+    {NA, NA, NA, NA, LA(6, 2), LA(6, 1), LA(6, 0)},
 };
 
-
-#define IS31_ADDR_DEFAULT 0x74 // AD connected to GND
+#define IS31_ADDR_DEFAULT 0x74  // AD connected to GND
 #define IS31_TIMEOUT 5000
 
-static GFXINLINE void init_board(GDisplay *g) {
-    (void) g;
+static GFXINLINE void init_board(GDisplayg) {
+    (void)g;
     /* I2C pins */
-    palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATIVE_2); // PTB0/I2C0/SCL
-    palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATIVE_2); // PTB1/I2C0/SDA
+    palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATIVE_2);  // PTB0/I2C0/SCL
+    palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATIVE_2);  // PTB1/I2C0/SDA
     palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL);
     palClearPad(GPIOB, 16);
     /* start I2C */
@@ -77,34 +76,30 @@ static GFXINLINE void init_board(GDisplay *g) {
     I2CD1.i2c->FLT = 4;
 }
 
-static GFXINLINE void post_init_board(GDisplay *g) {
-       (void) g;
-}
+static GFXINLINE void post_init_board(GDisplay* g) { (void)g; }
 
 static GFXINLINE const uint8_t* get_led_mask(GDisplay* g) {
-    (void) g;
+    (void)g;
     return led_mask;
 }
 
-static GFXINLINE uint8_t get_led_address(GDisplay* g, uint16_t x, uint16_t y)
-{
-    (void) g;
+static GFXINLINE uint8_t get_led_address(GDisplay* g, uint16_t x, uint16_t y) {
+    (void)g;
     return led_mapping[y][x];
 }
 
 static GFXINLINE void set_hardware_shutdown(GDisplay* g, bool shutdown) {
-    (void) g;
-    if(!shutdown) {
+    (void)g;
+    if (!shutdown) {
         palSetPad(GPIOB, 16);
-    }
-    else {
+    } else {
         palClearPad(GPIOB, 16);
     }
 }
 
-static GFXINLINE void write_data(GDisplay *g, uint8_t* data, uint16_t length) {
-       (void) g;
-       i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, data, length, 0, 0, US2ST(IS31_TIMEOUT));
+static GFXINLINE void write_data(GDisplayg, uint8_t* data, uint16_t length) {
+    (void)g;
+    i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, data, length, 0, 0, US2ST(IS31_TIMEOUT));
 }
 
 #endif /* _GDISP_LLD_BOARD_H */
index 917adadb844947574c574e8cef510d0c21213e97..71882440222122e404a03f781e8801936f81c396 100644 (file)
@@ -19,15 +19,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #if GFX_USE_GDISP
 
-#define GDISP_DRIVER_VMT          GDISPVMT_IS31FL3731C_QMK
-#define GDISP_SCREEN_HEIGHT       LED_HEIGHT
-#define GDISP_SCREEN_WIDTH        LED_WIDTH
+#    define GDISP_DRIVER_VMT GDISPVMT_IS31FL3731C_QMK
+#    define GDISP_SCREEN_HEIGHT LED_HEIGHT
+#    define GDISP_SCREEN_WIDTH LED_WIDTH
 
-#include "gdisp_lld_config.h"
-#include "src/gdisp/gdisp_driver.h"
-
-#include "board_is31fl3731c.h"
+#    include "gdisp_lld_config.h"
+#    include "src/gdisp/gdisp_driver.h"
 
+#    include "board_is31fl3731c.h"
 
 // Can't include led_tables from here
 extern const uint8_t CIE1931_CURVE[];
@@ -36,96 +35,96 @@ extern const uint8_t CIE1931_CURVE[];
 /* Driver local definitions.                                                 */
 /*===========================================================================*/
 
-#ifndef GDISP_INITIAL_CONTRAST
-    #define GDISP_INITIAL_CONTRAST    0
-#endif
-#ifndef GDISP_INITIAL_BACKLIGHT
-    #define GDISP_INITIAL_BACKLIGHT   0
-#endif
+#    ifndef GDISP_INITIAL_CONTRAST
+#        define GDISP_INITIAL_CONTRAST 0
+#    endif
+#    ifndef GDISP_INITIAL_BACKLIGHT
+#        define GDISP_INITIAL_BACKLIGHT 0
+#    endif
 
-#define GDISP_FLG_NEEDFLUSH           (GDISP_FLG_DRIVER<<0)
+#    define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER << 0)
 
-#define IS31_ADDR_DEFAULT 0x74
+#    define IS31_ADDR_DEFAULT 0x74
 
-#define IS31_REG_CONFIG   0x00
+#    define IS31_REG_CONFIG 0x00
 // bits in reg
-#define IS31_REG_CONFIG_PICTUREMODE   0x00
-#define IS31_REG_CONFIG_AUTOPLAYMODE  0x08
-#define IS31_REG_CONFIG_AUDIOPLAYMODE 0x18
+#    define IS31_REG_CONFIG_PICTUREMODE 0x00
+#    define IS31_REG_CONFIG_AUTOPLAYMODE 0x08
+#    define IS31_REG_CONFIG_AUDIOPLAYMODE 0x18
 // D2:D0 bits are starting frame for autoplay mode
 
-#define IS31_REG_PICTDISP 0x01 // D2:D0 frame select for picture mode
+#    define IS31_REG_PICTDISP 0x01  // D2:D0 frame select for picture mode
 
-#define IS31_REG_AUTOPLAYCTRL1 0x02
+#    define IS31_REG_AUTOPLAYCTRL1 0x02
 // D6:D4 number of loops (000=infty)
 // D2:D0 number of frames to be used
 
-#define IS31_REG_AUTOPLAYCTRL2 0x03 // D5:D0 delay time (*11ms)
+#    define IS31_REG_AUTOPLAYCTRL2 0x03  // D5:D0 delay time (*11ms)
 
-#define IS31_REG_DISPLAYOPT 0x05
-#define IS31_REG_DISPLAYOPT_INTENSITY_SAME 0x20 // same intensity for all frames
-#define IS31_REG_DISPLAYOPT_BLINK_ENABLE 0x8
+#    define IS31_REG_DISPLAYOPT 0x05
+#    define IS31_REG_DISPLAYOPT_INTENSITY_SAME 0x20  // same intensity for all frames
+#    define IS31_REG_DISPLAYOPT_BLINK_ENABLE 0x8
 // D2:D0 bits blink period time (*0.27s)
 
-#define IS31_REG_AUDIOSYNC 0x06
-#define IS31_REG_AUDIOSYNC_ENABLE 0x1
+#    define IS31_REG_AUDIOSYNC 0x06
+#    define IS31_REG_AUDIOSYNC_ENABLE 0x1
 
-#define IS31_REG_FRAMESTATE 0x07
+#    define IS31_REG_FRAMESTATE 0x07
 
-#define IS31_REG_BREATHCTRL1 0x08
+#    define IS31_REG_BREATHCTRL1 0x08
 // D6:D4 fade out time (26ms*2^i)
 // D2:D0 fade in time (26ms*2^i)
 
-#define IS31_REG_BREATHCTRL2 0x09
-#define IS31_REG_BREATHCTRL2_ENABLE 0x10
+#    define IS31_REG_BREATHCTRL2 0x09
+#    define IS31_REG_BREATHCTRL2_ENABLE 0x10
 // D2:D0 extinguish time (3.5ms*2^i)
 
-#define IS31_REG_SHUTDOWN 0x0A
-#define IS31_REG_SHUTDOWN_OFF 0x0
-#define IS31_REG_SHUTDOWN_ON 0x1
+#    define IS31_REG_SHUTDOWN 0x0A
+#    define IS31_REG_SHUTDOWN_OFF 0x0
+#    define IS31_REG_SHUTDOWN_ON 0x1
 
-#define IS31_REG_AGCCTRL 0x0B
-#define IS31_REG_ADCRATE 0x0C
+#    define IS31_REG_AGCCTRL 0x0B
+#    define IS31_REG_ADCRATE 0x0C
 
-#define IS31_COMMANDREGISTER 0xFD
-#define IS31_FUNCTIONREG 0x0B    // helpfully called 'page nine'
-#define IS31_FUNCTIONREG_SIZE 0xD
+#    define IS31_COMMANDREGISTER 0xFD
+#    define IS31_FUNCTIONREG 0x0B  // helpfully called 'page nine'
+#    define IS31_FUNCTIONREG_SIZE 0xD
 
-#define IS31_FRAME_SIZE 0xB4
+#    define IS31_FRAME_SIZE 0xB4
 
-#define IS31_PWM_REG 0x24
-#define IS31_PWM_SIZE 0x90
+#    define IS31_PWM_REG 0x24
+#    define IS31_PWM_SIZE 0x90
 
-#define IS31_LED_MASK_SIZE 0x12
+#    define IS31_LED_MASK_SIZE 0x12
 
-#define IS31
+#    define IS31
 
 /*===========================================================================*/
 /* Driver local functions.                                                   */
 /*===========================================================================*/
 
-typedef struct{
+typedef struct {
     uint8_t write_buffer_offset;
     uint8_t write_buffer[IS31_FRAME_SIZE];
     uint8_t frame_buffer[GDISP_SCREEN_HEIGHT * GDISP_SCREEN_WIDTH];
     uint8_t page;
-}__attribute__((__packed__)) PrivData;
+} __attribute__((__packed__)) PrivData;
 
 // Some common routines and macros
-#define PRIV(g)                         ((PrivData*)g->priv)
+#    define PRIV(g) ((PrivData *)g->priv)
 
 /*===========================================================================*/
 /* Driver exported functions.                                                */
 /*===========================================================================*/
 
-static GFXINLINE void write_page(GDisplayg, uint8_t page) {
+static GFXINLINE void write_page(GDisplay *g, uint8_t page) {
     uint8_t tx[2] __attribute__((aligned(2)));
     tx[0] = IS31_COMMANDREGISTER;
     tx[1] = page;
     write_data(g, tx, 2);
 }
 
-static GFXINLINE void write_register(GDisplayg, uint8_t page, uint8_t reg, uint8_t data) {
+static GFXINLINE void write_register(GDisplay *g, uint8_t page, uint8_t reg, uint8_t data) {
     uint8_t tx[2] __attribute__((aligned(2)));
     tx[0] = reg;
     tx[1] = data;
@@ -136,7 +135,7 @@ static GFXINLINE void write_register(GDisplay* g, uint8_t page, uint8_t reg, uin
 static GFXINLINE void write_ram(GDisplay *g, uint8_t page, uint16_t offset, uint16_t length) {
     PRIV(g)->write_buffer_offset = offset;
     write_page(g, page);
-    write_data(g, (uint8_t*)PRIV(g), length + 1);
+    write_data(g, (uint8_t *)PRIV(g), length + 1);
 }
 
 LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
@@ -160,10 +159,9 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
     write_ram(g, IS31_FUNCTIONREG, 0, IS31_FUNCTIONREG_SIZE);
     gfxSleepMilliseconds(10);
 
-
     // zero all LED registers on all 8 pages, and enable the mask
     __builtin_memcpy(PRIV(g)->write_buffer, get_led_mask(g), IS31_LED_MASK_SIZE);
-    for(uint8_t i=0; i<8; i++) {
+    for (uint8_t i = 0; i < 8; i++) {
         write_ram(g, i, 0, IS31_FRAME_SIZE);
         gfxSleepMilliseconds(1);
     }
@@ -176,133 +174,129 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
     post_init_board(g);
 
     /* Initialise the GDISP structure */
-    g->g.Width = GDISP_SCREEN_WIDTH;
-    g->g.Height = GDISP_SCREEN_HEIGHT;
+    g->g.Width       = GDISP_SCREEN_WIDTH;
+    g->g.Height      = GDISP_SCREEN_HEIGHT;
     g->g.Orientation = GDISP_ROTATE_0;
-    g->g.Powermode = powerOff;
-    g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
-    g->g.Contrast = GDISP_INITIAL_CONTRAST;
+    g->g.Powermode   = powerOff;
+    g->g.Backlight   = GDISP_INITIAL_BACKLIGHT;
+    g->g.Contrast    = GDISP_INITIAL_CONTRAST;
     return TRUE;
 }
 
-#if GDISP_HARDWARE_FLUSH
-    LLDSPEC void gdisp_lld_flush(GDisplay *g) {
-        // Don't flush if we don't need it.
-        if (!(g->flags & GDISP_FLG_NEEDFLUSH))
-            return;
-
-        PRIV(g)->page++;
-        PRIV(g)->page %= 2;
-        // TODO: some smarter algorithm for this
-        // We should run only one physical page at a time
-        // This way we don't need to send so much data, and
-        // we could use slightly less memory
-        uint8_t* src = PRIV(g)->frame_buffer;
-        for (int y=0;y<GDISP_SCREEN_HEIGHT;y++) {
-            for (int x=0;x<GDISP_SCREEN_WIDTH;x++) {
-                uint8_t val = (uint16_t)*src * g->g.Backlight / 100;
-                PRIV(g)->write_buffer[get_led_address(g, x, y)]=CIE1931_CURVE[val];
-                ++src;
-            }
+#    if GDISP_HARDWARE_FLUSH
+LLDSPEC void gdisp_lld_flush(GDisplay *g) {
+    // Don't flush if we don't need it.
+    if (!(g->flags & GDISP_FLG_NEEDFLUSH)) return;
+
+    PRIV(g)->page++;
+    PRIV(g)->page %= 2;
+    // TODO: some smarter algorithm for this
+    // We should run only one physical page at a time
+    // This way we don't need to send so much data, and
+    // we could use slightly less memory
+    uint8_t *src = PRIV(g)->frame_buffer;
+    for (int y = 0; y < GDISP_SCREEN_HEIGHT; y++) {
+        for (int x = 0; x < GDISP_SCREEN_WIDTH; x++) {
+            uint8_t val                                     = (uint16_t)*src * g->g.Backlight / 100;
+            PRIV(g)->write_buffer[get_led_address(g, x, y)] = CIE1931_CURVE[val];
+            ++src;
         }
-        write_ram(g, PRIV(g)->page, IS31_PWM_REG, IS31_PWM_SIZE);
-        gfxSleepMilliseconds(1);
-        write_register(g, IS31_FUNCTIONREG, IS31_REG_PICTDISP, PRIV(g)->page);
-
-        g->flags &= ~GDISP_FLG_NEEDFLUSH;
     }
-#endif
+    write_ram(g, PRIV(g)->page, IS31_PWM_REG, IS31_PWM_SIZE);
+    gfxSleepMilliseconds(1);
+    write_register(g, IS31_FUNCTIONREG, IS31_REG_PICTDISP, PRIV(g)->page);
 
-#if GDISP_HARDWARE_DRAWPIXEL
-    LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
-        coord_t        x, y;
+    g->flags &= ~GDISP_FLG_NEEDFLUSH;
+}
+#    endif
 
-        switch(g->g.Orientation) {
+#    if GDISP_HARDWARE_DRAWPIXEL
+LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
+    coord_t x, y;
+
+    switch (g->g.Orientation) {
         default:
         case GDISP_ROTATE_0:
             x = g->p.x;
             y = g->p.y;
             break;
         case GDISP_ROTATE_180:
-            x = GDISP_SCREEN_WIDTH-1 - g->p.x;
+            x = GDISP_SCREEN_WIDTH - 1 - g->p.x;
             y = g->p.y;
             break;
-        }
-        PRIV(g)->frame_buffer[y * GDISP_SCREEN_WIDTH + x] = gdispColor2Native(g->p.color);
-        g->flags |= GDISP_FLG_NEEDFLUSH;
     }
-#endif
+    PRIV(g)->frame_buffer[y * GDISP_SCREEN_WIDTH + x] = gdispColor2Native(g->p.color);
+    g->flags |= GDISP_FLG_NEEDFLUSH;
+}
+#    endif
 
-#if GDISP_HARDWARE_PIXELREAD
-    LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
-        coord_t        x, y;
+#    if GDISP_HARDWARE_PIXELREAD
+LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
+    coord_t x, y;
 
-        switch(g->g.Orientation) {
+    switch (g->g.Orientation) {
         default:
         case GDISP_ROTATE_0:
             x = g->p.x;
             y = g->p.y;
             break;
         case GDISP_ROTATE_180:
-            x = GDISP_SCREEN_WIDTH-1 - g->p.x;
+            x = GDISP_SCREEN_WIDTH - 1 - g->p.x;
             y = g->p.y;
             break;
-        }
-        return gdispNative2Color(PRIV(g)->frame_buffer[y * GDISP_SCREEN_WIDTH + x]);
     }
-#endif
+    return gdispNative2Color(PRIV(g)->frame_buffer[y * GDISP_SCREEN_WIDTH + x]);
+}
+#    endif
 
-#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
-    LLDSPEC void gdisp_lld_control(GDisplay *g) {
-        switch(g->p.x) {
+#    if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+LLDSPEC void gdisp_lld_control(GDisplay *g) {
+    switch (g->p.x) {
         case GDISP_CONTROL_POWER:
-            if (g->g.Powermode == (powermode_t)g->p.ptr)
-                return;
-            switch((powermode_t)g->p.ptr) {
-            case powerOff:
-            case powerSleep:
-            case powerDeepSleep:
-                write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF);
-                break;
-            case powerOn:
-                write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON);
-                break;
-            default:
-                return;
+            if (g->g.Powermode == (powermode_t)g->p.ptr) return;
+            switch ((powermode_t)g->p.ptr) {
+                case powerOff:
+                case powerSleep:
+                case powerDeepSleep:
+                    write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF);
+                    break;
+                case powerOn:
+                    write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON);
+                    break;
+                default:
+                    return;
             }
             g->g.Powermode = (powermode_t)g->p.ptr;
             return;
 
         case GDISP_CONTROL_ORIENTATION:
-            if (g->g.Orientation == (orientation_t)g->p.ptr)
-                return;
-            switch((orientation_t)g->p.ptr) {
-            /* Rotation is handled by the drawing routines */
-            case GDISP_ROTATE_0:
-            case GDISP_ROTATE_180:
-                g->g.Height = GDISP_SCREEN_HEIGHT;
-                g->g.Width = GDISP_SCREEN_WIDTH;
-                break;
-            case GDISP_ROTATE_90:
-            case GDISP_ROTATE_270:
-                g->g.Height = GDISP_SCREEN_WIDTH;
-                g->g.Width = GDISP_SCREEN_HEIGHT;
-                break;
-            default:
-                return;
+            if (g->g.Orientation == (orientation_t)g->p.ptr) return;
+            switch ((orientation_t)g->p.ptr) {
+                /* Rotation is handled by the drawing routines */
+                case GDISP_ROTATE_0:
+                case GDISP_ROTATE_180:
+                    g->g.Height = GDISP_SCREEN_HEIGHT;
+                    g->g.Width  = GDISP_SCREEN_WIDTH;
+                    break;
+                case GDISP_ROTATE_90:
+                case GDISP_ROTATE_270:
+                    g->g.Height = GDISP_SCREEN_WIDTH;
+                    g->g.Width  = GDISP_SCREEN_HEIGHT;
+                    break;
+                default:
+                    return;
             }
             g->g.Orientation = (orientation_t)g->p.ptr;
             return;
 
         case GDISP_CONTROL_BACKLIGHT:
-            if (g->g.Backlight == (unsigned)g->p.ptr)
-                return;
-            unsigned val = (unsigned)g->p.ptr;
+            if (g->g.Backlight == (unsigned)g->p.ptr) return;
+            unsigned val   = (unsigned)g->p.ptr;
             g->g.Backlight = val > 100 ? 100 : val;
             g->flags |= GDISP_FLG_NEEDFLUSH;
             return;
-        }
     }
-#endif // GDISP_NEED_CONTROL
+}
+#    endif  // GDISP_NEED_CONTROL
 
-#endif // GFX_USE_GDISP
+#endif  // GFX_USE_GDISP
index 588d688cf6d8d70024d8c1d6c5fdb843dd4c70c8..1b9fadba16acddf795d0f03125befc539164d099 100644 (file)
@@ -24,13 +24,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /* Driver hardware support.                                                  */
 /*===========================================================================*/
 
-#define GDISP_HARDWARE_FLUSH            TRUE        // This controller requires flushing
-#define GDISP_HARDWARE_DRAWPIXEL        TRUE
-#define GDISP_HARDWARE_PIXELREAD        TRUE
-#define GDISP_HARDWARE_CONTROL          TRUE
+#    define GDISP_HARDWARE_FLUSH TRUE  // This controller requires flushing
+#    define GDISP_HARDWARE_DRAWPIXEL TRUE
+#    define GDISP_HARDWARE_PIXELREAD TRUE
+#    define GDISP_HARDWARE_CONTROL TRUE
 
-#define GDISP_LLD_PIXELFORMAT           GDISP_PIXELFORMAT_GRAY256
+#    define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_GRAY256
 
-#endif    /* GFX_USE_GDISP */
+#endif /* GFX_USE_GDISP */
 
-#endif    /* _GDISP_LLD_CONFIG_H */
+#endif /* _GDISP_LLD_CONFIG_H */
index 9ab636c95d0651fb1576389816f1570126d22f38..194f8ea24d649edda4634d6b5220671e2d4746c4 100644 (file)
@@ -8,10 +8,10 @@
 #ifndef _GDISP_LLD_BOARD_H
 #define _GDISP_LLD_BOARD_H
 
-#define ST7565_LCD_BIAS         ST7565_LCD_BIAS_9 // actually 6
-#define ST7565_ADC              ST7565_ADC_NORMAL
-#define ST7565_COM_SCAN         ST7565_COM_SCAN_DEC
-#define ST7565_PAGE_ORDER       0,1,2,3
+#define ST7565_LCD_BIAS ST7565_LCD_BIAS_9  // actually 6
+#define ST7565_ADC ST7565_ADC_NORMAL
+#define ST7565_COM_SCAN ST7565_COM_SCAN_DEC
+#define ST7565_PAGE_ORDER 0, 1, 2, 3
 /*
  * Custom page order for several LCD boards, e.g. HEM12864-99
  * #define ST7565_PAGE_ORDER       4,5,6,7,0,1,2,3
 #define ST7565_SLCK_PIN 5
 #define ST7565_SS_PIN 4
 
-#define palSetPadModeRaw(portname, bits) \
-    ST7565_PORT->PCR[ST7565_##portname##_PIN] = bits
+#define palSetPadModeRaw(portname, bits) ST7565_PORT->PCR[ST7565_##portname##_PIN] = bits
 
-#define palSetPadModeNamed(portname, portmode) \
-    palSetPadMode(ST7565_GPIOPORT, ST7565_##portname##_PIN, portmode)
+#define palSetPadModeNamed(portname, portmode) palSetPadMode(ST7565_GPIOPORT, ST7565_##portname##_PIN, portmode)
 
 #define ST7565_SPI_MODE PORTx_PCRn_DSE | PORTx_PCRn_MUX(2)
 // DSPI Clock and Transfer Attributes
 // MSB First
 // CLK Low by default
 static const SPIConfig spi1config = {
-   // Operation complete callback or @p NULL.
-  .end_cb = NULL,
-   //The chip select line port - when not using pcs.
-  .ssport = ST7565_GPIOPORT,
-   // brief The chip select line pad number - when not using pcs.
-  .sspad=ST7565_SS_PIN,
-   // SPI initialization data.
-  .tar0 =
-    SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes
-    | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns
-    | SPIx_CTARn_DT(0) // Delay After Transfer Scaler (no minimum)= 27.78ns
-    | SPIx_CTARn_CSSCK(0) // PCS to SCK Delay Scaler (min 20 ns) = 27.78ns
-    | SPIx_CTARn_PBR(0) // Baud Rate Prescaler = 2
-    | SPIx_CTARn_BR(0) // Baud rate (min 50ns) = 55.56ns
+    // Operation complete callback or @p NULL.
+    .end_cb = NULL,
+    // The chip select line port - when not using pcs.
+    .ssport = ST7565_GPIOPORT,
+    // brief The chip select line pad number - when not using pcs.
+    .sspad = ST7565_SS_PIN,
+    // SPI initialization data.
+    .tar0 = SPIx_CTARn_FMSZ(7)     // Frame size = 8 bytes
+            | SPIx_CTARn_ASC(1)    // After SCK Delay Scaler (min 50 ns) = 55.56ns
+            | SPIx_CTARn_DT(0)     // Delay After Transfer Scaler (no minimum)= 27.78ns
+            | SPIx_CTARn_CSSCK(0)  // PCS to SCK Delay Scaler (min 20 ns) = 27.78ns
+            | SPIx_CTARn_PBR(0)    // Baud Rate Prescaler = 2
+            | SPIx_CTARn_BR(0)     // Baud rate (min 50ns) = 55.56ns
 };
 
 static GFXINLINE void acquire_bus(GDisplay *g) {
-    (void) g;
+    (void)g;
     // Only the LCD is using the SPI bus, so no need to acquire
     // spiAcquireBus(&SPID1);
     spiSelect(&SPID1);
 }
 
 static GFXINLINE void release_bus(GDisplay *g) {
-    (void) g;
+    (void)g;
     // Only the LCD is using the SPI bus, so no need to release
-    //spiReleaseBus(&SPID1);
+    // spiReleaseBus(&SPID1);
     spiUnselect(&SPID1);
 }
 
 static GFXINLINE void init_board(GDisplay *g) {
-    (void) g;
+    (void)g;
     palSetPadModeNamed(A0, PAL_MODE_OUTPUT_PUSHPULL);
     palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN);
     palSetPadModeNamed(RST, PAL_MODE_OUTPUT_PUSHPULL);
@@ -82,31 +79,23 @@ static GFXINLINE void init_board(GDisplay *g) {
     release_bus(g);
 }
 
-static GFXINLINE void post_init_board(GDisplay *g) {
-    (void) g;
-}
+static GFXINLINE void post_init_board(GDisplay *g) { (void)g; }
 
 static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) {
-    (void) g;
+    (void)g;
     if (state) {
         palClearPad(ST7565_GPIOPORT, ST7565_RST_PIN);
-    }
-    else {
+    } else {
         palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN);
     }
 }
 
-static GFXINLINE void enter_data_mode(GDisplay *g) {
-    palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN);
-}
-
-static GFXINLINE void enter_cmd_mode(GDisplay *g) {
-    palClearPad(ST7565_GPIOPORT, ST7565_A0_PIN);
-}
+static GFXINLINE void enter_data_mode(GDisplay *g) { palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN); }
 
+static GFXINLINE void enter_cmd_mode(GDisplay *g) { palClearPad(ST7565_GPIOPORT, ST7565_A0_PIN); }
 
-static GFXINLINE void write_data(GDisplay *g, uint8_tdata, uint16_t length) {
-    (void) g;
+static GFXINLINE void write_data(GDisplay *g, uint8_t *data, uint16_t length) {
+    (void)g;
     spiSend(&SPID1, length, data);
 }
 
index c38194b0696a41b7dc00a6ace829cd0844272221..fde320981b3239767a8cfabc5e18c662c197c5cb 100644 (file)
@@ -9,82 +9,89 @@
 
 #if GFX_USE_GDISP
 
-#define GDISP_DRIVER_VMT            GDISPVMT_ST7565_QMK
-#include "gdisp_lld_config.h"
-#include "src/gdisp/gdisp_driver.h"
+#    define GDISP_DRIVER_VMT GDISPVMT_ST7565_QMK
+#    include "gdisp_lld_config.h"
+#    include "src/gdisp/gdisp_driver.h"
 
-#include "board_st7565.h"
+#    include "board_st7565.h"
 
 /*===========================================================================*/
 /* Driver local definitions.                                                 */
 /*===========================================================================*/
 
-#ifndef GDISP_SCREEN_HEIGHT
-#define GDISP_SCREEN_HEIGHT         LCD_HEIGHT
-#endif
-#ifndef GDISP_SCREEN_WIDTH
-#define GDISP_SCREEN_WIDTH          LCD_WIDTH
-#endif
-#ifndef GDISP_INITIAL_CONTRAST
-#define GDISP_INITIAL_CONTRAST      35
-#endif
-#ifndef GDISP_INITIAL_BACKLIGHT
-#define GDISP_INITIAL_BACKLIGHT     100
-#endif
+#    ifndef GDISP_SCREEN_HEIGHT
+#        define GDISP_SCREEN_HEIGHT LCD_HEIGHT
+#    endif
+#    ifndef GDISP_SCREEN_WIDTH
+#        define GDISP_SCREEN_WIDTH LCD_WIDTH
+#    endif
+#    ifndef GDISP_INITIAL_CONTRAST
+#        define GDISP_INITIAL_CONTRAST 35
+#    endif
+#    ifndef GDISP_INITIAL_BACKLIGHT
+#        define GDISP_INITIAL_BACKLIGHT 100
+#    endif
 
-#define GDISP_FLG_NEEDFLUSH         (GDISP_FLG_DRIVER<<0)
+#    define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER << 0)
 
-#include "st7565.h"
+#    include "st7565.h"
 
 /*===========================================================================*/
 /* Driver config defaults for backward compatibility.                        */
 /*===========================================================================*/
-#ifndef ST7565_LCD_BIAS
-#define ST7565_LCD_BIAS         ST7565_LCD_BIAS_7
-#endif
-#ifndef ST7565_ADC
-#define ST7565_ADC              ST7565_ADC_NORMAL
-#endif
-#ifndef ST7565_COM_SCAN
-#define ST7565_COM_SCAN         ST7565_COM_SCAN_INC
-#endif
-#ifndef ST7565_PAGE_ORDER
-#define ST7565_PAGE_ORDER       0,1,2,3
-#endif
+#    ifndef ST7565_LCD_BIAS
+#        define ST7565_LCD_BIAS ST7565_LCD_BIAS_7
+#    endif
+#    ifndef ST7565_ADC
+#        define ST7565_ADC ST7565_ADC_NORMAL
+#    endif
+#    ifndef ST7565_COM_SCAN
+#        define ST7565_COM_SCAN ST7565_COM_SCAN_INC
+#    endif
+#    ifndef ST7565_PAGE_ORDER
+#        define ST7565_PAGE_ORDER 0, 1, 2, 3
+#    endif
 
 /*===========================================================================*/
 /* Driver local functions.                                                   */
 /*===========================================================================*/
 
-typedef struct{
-    bool_t buffer2;
+typedef struct {
+    bool_t  buffer2;
     uint8_t data_pos;
     uint8_t data[16];
     uint8_t ram[GDISP_SCREEN_HEIGHT * GDISP_SCREEN_WIDTH / 8];
-}PrivData;
+} PrivData;
 
 // Some common routines and macros
-#define PRIV(g)                         ((PrivData*)g->priv)
-#define RAM(g)                          (PRIV(g)->ram)
+#    define PRIV(g) ((PrivData *)g->priv)
+#    define RAM(g) (PRIV(g)->ram)
 
-static GFXINLINE void write_cmd(GDisplay* g, uint8_t cmd) {
-    PRIV(g)->data[PRIV(g)->data_pos++] = cmd;
-}
+static GFXINLINE void write_cmd(GDisplay *g, uint8_t cmd) { PRIV(g)->data[PRIV(g)->data_pos++] = cmd; }
 
-static GFXINLINE void flush_cmd(GDisplayg) {
+static GFXINLINE void flush_cmd(GDisplay *g) {
     write_data(g, PRIV(g)->data, PRIV(g)->data_pos);
     PRIV(g)->data_pos = 0;
 }
 
-#define write_cmd2(g, cmd1, cmd2)        { write_cmd(g, cmd1); write_cmd(g, cmd2); }
-#define write_cmd3(g, cmd1, cmd2, cmd3)  { write_cmd(g, cmd1); write_cmd(g, cmd2); write_cmd(g, cmd3); }
+#    define write_cmd2(g, cmd1, cmd2) \
+        {                             \
+            write_cmd(g, cmd1);       \
+            write_cmd(g, cmd2);       \
+        }
+#    define write_cmd3(g, cmd1, cmd2, cmd3) \
+        {                                   \
+            write_cmd(g, cmd1);             \
+            write_cmd(g, cmd2);             \
+            write_cmd(g, cmd3);             \
+        }
 
 // Some common routines and macros
-#define delay(us)           gfxSleepMicroseconds(us)
-#define delay_ms(ms)        gfxSleepMilliseconds(ms)
+#    define delay(us) gfxSleepMicroseconds(us)
+#    define delay_ms(ms) gfxSleepMilliseconds(ms)
 
-#define xyaddr(x, y)        ((x) + ((y)>>3)*GDISP_SCREEN_WIDTH)
-#define xybit(y)            (1<<((y)&7))
+#    define xyaddr(x, y) ((x) + ((y) >> 3) * GDISP_SCREEN_WIDTH)
+#    define xybit(y) (1 << ((y)&7))
 
 /*===========================================================================*/
 /* Driver exported functions.                                                */
@@ -99,8 +106,8 @@ static GFXINLINE void flush_cmd(GDisplay* g) {
 
 LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
     // The private area is the display surface.
-    g->priv = gfxAlloc(sizeof(PrivData));
-    PRIV(g)->buffer2 = false;
+    g->priv           = gfxAlloc(sizeof(PrivData));
+    PRIV(g)->buffer2  = false;
     PRIV(g)->data_pos = 0;
 
     // Initialise the board interface
@@ -139,22 +146,21 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
     release_bus(g);
 
     /* Initialise the GDISP structure */
-    g->g.Width = GDISP_SCREEN_WIDTH;
-    g->g.Height = GDISP_SCREEN_HEIGHT;
+    g->g.Width       = GDISP_SCREEN_WIDTH;
+    g->g.Height      = GDISP_SCREEN_HEIGHT;
     g->g.Orientation = GDISP_ROTATE_0;
-    g->g.Powermode = powerOff;
-    g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
-    g->g.Contrast = GDISP_INITIAL_CONTRAST;
+    g->g.Powermode   = powerOff;
+    g->g.Backlight   = GDISP_INITIAL_BACKLIGHT;
+    g->g.Contrast    = GDISP_INITIAL_CONTRAST;
     return TRUE;
 }
 
-#if GDISP_HARDWARE_FLUSH
+#    if GDISP_HARDWARE_FLUSH
 LLDSPEC void gdisp_lld_flush(GDisplay *g) {
-    unsigned    p;
+    unsigned p;
 
     // Don't flush if we don't need it.
-    if (!(g->flags & GDISP_FLG_NEEDFLUSH))
-        return;
+    if (!(g->flags & GDISP_FLG_NEEDFLUSH)) return;
 
     acquire_bus(g);
     enter_cmd_mode(g);
@@ -166,7 +172,7 @@ LLDSPEC void gdisp_lld_flush(GDisplay *g) {
         write_cmd(g, ST7565_RMW);
         flush_cmd(g);
         enter_data_mode(g);
-        write_data(g, RAM(g) + (p*GDISP_SCREEN_WIDTH), GDISP_SCREEN_WIDTH);
+        write_data(g, RAM(g) + (p * GDISP_SCREEN_WIDTH), GDISP_SCREEN_WIDTH);
         enter_cmd_mode(g);
     }
     unsigned line = (PRIV(g)->buffer2 ? 32 : 0);
@@ -177,30 +183,30 @@ LLDSPEC void gdisp_lld_flush(GDisplay *g) {
 
     g->flags &= ~GDISP_FLG_NEEDFLUSH;
 }
-#endif
+#    endif
 
-#if GDISP_HARDWARE_DRAWPIXEL
+#    if GDISP_HARDWARE_DRAWPIXEL
 LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
-    coord_t        x, y;
-
-    switch(g->g.Orientation) {
-    default:
-    case GDISP_ROTATE_0:
-        x = g->p.x;
-        y = g->p.y;
-        break;
-    case GDISP_ROTATE_90:
-        x = g->p.y;
-        y = GDISP_SCREEN_HEIGHT-1 - g->p.x;
-        break;
-    case GDISP_ROTATE_180:
-        x = GDISP_SCREEN_WIDTH-1 - g->p.x;
-        y = GDISP_SCREEN_HEIGHT-1 - g->p.y;
-        break;
-    case GDISP_ROTATE_270:
-        x = GDISP_SCREEN_HEIGHT-1 - g->p.y;
-        y = g->p.x;
-        break;
+    coord_t x, y;
+
+    switch (g->g.Orientation) {
+        default:
+        case GDISP_ROTATE_0:
+            x = g->p.x;
+            y = g->p.y;
+            break;
+        case GDISP_ROTATE_90:
+            x = g->p.y;
+            y = GDISP_SCREEN_HEIGHT - 1 - g->p.x;
+            break;
+        case GDISP_ROTATE_180:
+            x = GDISP_SCREEN_WIDTH - 1 - g->p.x;
+            y = GDISP_SCREEN_HEIGHT - 1 - g->p.y;
+            break;
+        case GDISP_ROTATE_270:
+            x = GDISP_SCREEN_HEIGHT - 1 - g->p.y;
+            y = g->p.x;
+            break;
     }
     if (gdispColor2Native(g->p.color) != Black)
         RAM(g)[xyaddr(x, y)] |= xybit(y);
@@ -208,53 +214,52 @@ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
         RAM(g)[xyaddr(x, y)] &= ~xybit(y);
     g->flags |= GDISP_FLG_NEEDFLUSH;
 }
-#endif
+#    endif
 
-#if GDISP_HARDWARE_PIXELREAD
+#    if GDISP_HARDWARE_PIXELREAD
 LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
-    coord_t        x, y;
-
-    switch(g->g.Orientation) {
-    default:
-    case GDISP_ROTATE_0:
-        x = g->p.x;
-        y = g->p.y;
-        break;
-    case GDISP_ROTATE_90:
-        x = g->p.y;
-        y = GDISP_SCREEN_HEIGHT-1 - g->p.x;
-        break;
-    case GDISP_ROTATE_180:
-        x = GDISP_SCREEN_WIDTH-1 - g->p.x;
-        y = GDISP_SCREEN_HEIGHT-1 - g->p.y;
-        break;
-    case GDISP_ROTATE_270:
-        x = GDISP_SCREEN_HEIGHT-1 - g->p.y;
-        y = g->p.x;
-        break;
+    coord_t x, y;
+
+    switch (g->g.Orientation) {
+        default:
+        case GDISP_ROTATE_0:
+            x = g->p.x;
+            y = g->p.y;
+            break;
+        case GDISP_ROTATE_90:
+            x = g->p.y;
+            y = GDISP_SCREEN_HEIGHT - 1 - g->p.x;
+            break;
+        case GDISP_ROTATE_180:
+            x = GDISP_SCREEN_WIDTH - 1 - g->p.x;
+            y = GDISP_SCREEN_HEIGHT - 1 - g->p.y;
+            break;
+        case GDISP_ROTATE_270:
+            x = GDISP_SCREEN_HEIGHT - 1 - g->p.y;
+            y = g->p.x;
+            break;
     }
     return (RAM(g)[xyaddr(x, y)] & xybit(y)) ? White : Black;
 }
-#endif
+#    endif
 
 LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
-    uint8_t* buffer = (uint8_t*)g->p.ptr;
-    int linelength = g->p.cx;
+    uint8_t *buffer     = (uint8_t *)g->p.ptr;
+    int      linelength = g->p.cx;
     for (int i = 0; i < g->p.cy; i++) {
-        unsigned dstx = g->p.x;
-        unsigned dsty = g->p.y + i;
-        unsigned srcx = g->p.x1;
-        unsigned srcy = g->p.y1 + i;
+        unsigned dstx   = g->p.x;
+        unsigned dsty   = g->p.y + i;
+        unsigned srcx   = g->p.x1;
+        unsigned srcy   = g->p.y1 + i;
         unsigned srcbit = srcy * g->p.x2 + srcx;
-        for(int j=0; j < linelength; j++) {
-            uint8_t src = buffer[srcbit / 8];
-            uint8_t bit = 7-(srcbit % 8);
-            uint8_t bitset = (src >> bit) & 1;
-            uint8_t* dst = &(RAM(g)[xyaddr(dstx, dsty)]);
+        for (int j = 0; j < linelength; j++) {
+            uint8_t  src    = buffer[srcbit / 8];
+            uint8_t  bit    = 7 - (srcbit % 8);
+            uint8_t  bitset = (src >> bit) & 1;
+            uint8_t *dst    = &(RAM(g)[xyaddr(dstx, dsty)]);
             if (bitset) {
                 *dst |= xybit(dsty);
-            }
-            else {
+            } else {
                 *dst &= ~xybit(dsty);
             }
             dstx++;
@@ -264,66 +269,64 @@ LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
     g->flags |= GDISP_FLG_NEEDFLUSH;
 }
 
-#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+#    if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
 LLDSPEC void gdisp_lld_control(GDisplay *g) {
-    switch(g->p.x) {
-    case GDISP_CONTROL_POWER:
-        if (g->g.Powermode == (powermode_t)g->p.ptr)
-            return;
-        switch((powermode_t)g->p.ptr) {
-        case powerOff:
-        case powerSleep:
-        case powerDeepSleep:
-            acquire_bus(g);
-            enter_cmd_mode(g);
-            write_cmd(g, ST7565_DISPLAY_OFF);
-            flush_cmd(g);
-            release_bus(g);
-            break;
-        case powerOn:
-            acquire_bus(g);
-            enter_cmd_mode(g);
-            write_cmd(g, ST7565_DISPLAY_ON);
-            flush_cmd(g);
-            release_bus(g);
-            break;
-        default:
+    switch (g->p.x) {
+        case GDISP_CONTROL_POWER:
+            if (g->g.Powermode == (powermode_t)g->p.ptr) return;
+            switch ((powermode_t)g->p.ptr) {
+                case powerOff:
+                case powerSleep:
+                case powerDeepSleep:
+                    acquire_bus(g);
+                    enter_cmd_mode(g);
+                    write_cmd(g, ST7565_DISPLAY_OFF);
+                    flush_cmd(g);
+                    release_bus(g);
+                    break;
+                case powerOn:
+                    acquire_bus(g);
+                    enter_cmd_mode(g);
+                    write_cmd(g, ST7565_DISPLAY_ON);
+                    flush_cmd(g);
+                    release_bus(g);
+                    break;
+                default:
+                    return;
+            }
+            g->g.Powermode = (powermode_t)g->p.ptr;
             return;
-        }
-        g->g.Powermode = (powermode_t)g->p.ptr;
-        return;
 
         case GDISP_CONTROL_ORIENTATION:
-            if (g->g.Orientation == (orientation_t)g->p.ptr)
-                return;
-            switch((orientation_t)g->p.ptr) {
-            /* Rotation is handled by the drawing routines */
-            case GDISP_ROTATE_0:
-            case GDISP_ROTATE_180:
-                g->g.Height = GDISP_SCREEN_HEIGHT;
-                g->g.Width = GDISP_SCREEN_WIDTH;
-                break;
-            case GDISP_ROTATE_90:
-            case GDISP_ROTATE_270:
-                g->g.Height = GDISP_SCREEN_WIDTH;
-                g->g.Width = GDISP_SCREEN_HEIGHT;
-                break;
-            default:
-                return;
+            if (g->g.Orientation == (orientation_t)g->p.ptr) return;
+            switch ((orientation_t)g->p.ptr) {
+                /* Rotation is handled by the drawing routines */
+                case GDISP_ROTATE_0:
+                case GDISP_ROTATE_180:
+                    g->g.Height = GDISP_SCREEN_HEIGHT;
+                    g->g.Width  = GDISP_SCREEN_WIDTH;
+                    break;
+                case GDISP_ROTATE_90:
+                case GDISP_ROTATE_270:
+                    g->g.Height = GDISP_SCREEN_WIDTH;
+                    g->g.Width  = GDISP_SCREEN_HEIGHT;
+                    break;
+                default:
+                    return;
             }
             g->g.Orientation = (orientation_t)g->p.ptr;
             return;
 
-            case GDISP_CONTROL_CONTRAST:
-                g->g.Contrast = (unsigned)g->p.ptr & 63;
-                acquire_bus(g);
-                enter_cmd_mode(g);
-                write_cmd2(g, ST7565_CONTRAST, g->g.Contrast);
-                flush_cmd(g);
-                release_bus(g);
-                return;
+        case GDISP_CONTROL_CONTRAST:
+            g->g.Contrast = (unsigned)g->p.ptr & 63;
+            acquire_bus(g);
+            enter_cmd_mode(g);
+            write_cmd2(g, ST7565_CONTRAST, g->g.Contrast);
+            flush_cmd(g);
+            release_bus(g);
+            return;
     }
 }
-#endif // GDISP_NEED_CONTROL
+#    endif  // GDISP_NEED_CONTROL
 
-#endif // GFX_USE_GDISP
+#endif  // GFX_USE_GDISP
index 4446bd38bcb642e8e3c3d1bb47e0c0835c3525a5..9ab5daac1c2c3c718e0118007f2a3ba4ba5119af 100644 (file)
 /* Driver hardware support.                                                  */
 /*===========================================================================*/
 
-#define GDISP_HARDWARE_FLUSH            TRUE        // This controller requires flushing
-#define GDISP_HARDWARE_DRAWPIXEL        TRUE
-#define GDISP_HARDWARE_PIXELREAD        TRUE
-#define GDISP_HARDWARE_CONTROL          TRUE
-#define GDISP_HARDWARE_BITFILLS         TRUE
+#    define GDISP_HARDWARE_FLUSH TRUE  // This controller requires flushing
+#    define GDISP_HARDWARE_DRAWPIXEL TRUE
+#    define GDISP_HARDWARE_PIXELREAD TRUE
+#    define GDISP_HARDWARE_CONTROL TRUE
+#    define GDISP_HARDWARE_BITFILLS TRUE
 
-#define GDISP_LLD_PIXELFORMAT           GDISP_PIXELFORMAT_MONO
+#    define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_MONO
 
-#endif    /* GFX_USE_GDISP */
+#endif /* GFX_USE_GDISP */
 
-#endif    /* _GDISP_LLD_CONFIG_H */
+#endif /* _GDISP_LLD_CONFIG_H */
index 24924ff05042940757d385d456c985b56fba741c..3c77a88569aa6518c25ed1703c224dde6533b1c5 100644 (file)
@@ -8,32 +8,32 @@
 #ifndef _ST7565_H
 #define _ST7565_H
 
-#define ST7565_CONTRAST             0x81
-#define ST7565_ALLON_NORMAL         0xA4
-#define ST7565_ALLON                0xA5
-#define ST7565_POSITIVE_DISPLAY     0xA6
-#define ST7565_INVERT_DISPLAY       0xA7
-#define ST7565_DISPLAY_OFF          0xAE
-#define ST7565_DISPLAY_ON           0xAF
+#define ST7565_CONTRAST 0x81
+#define ST7565_ALLON_NORMAL 0xA4
+#define ST7565_ALLON 0xA5
+#define ST7565_POSITIVE_DISPLAY 0xA6
+#define ST7565_INVERT_DISPLAY 0xA7
+#define ST7565_DISPLAY_OFF 0xAE
+#define ST7565_DISPLAY_ON 0xAF
 
-#define ST7565_LCD_BIAS_7           0xA3
-#define ST7565_LCD_BIAS_9           0xA2
+#define ST7565_LCD_BIAS_7 0xA3
+#define ST7565_LCD_BIAS_9 0xA2
 
-#define ST7565_ADC_NORMAL           0xA0
-#define ST7565_ADC_REVERSE          0xA1
+#define ST7565_ADC_NORMAL 0xA0
+#define ST7565_ADC_REVERSE 0xA1
 
-#define ST7565_COM_SCAN_INC         0xC0
-#define ST7565_COM_SCAN_DEC         0xC8
+#define ST7565_COM_SCAN_INC 0xC0
+#define ST7565_COM_SCAN_DEC 0xC8
 
-#define ST7565_START_LINE           0x40
-#define ST7565_PAGE                 0xB0
-#define ST7565_COLUMN_MSB           0x10
-#define ST7565_COLUMN_LSB           0x00
-#define ST7565_RMW                  0xE0
+#define ST7565_START_LINE 0x40
+#define ST7565_PAGE 0xB0
+#define ST7565_COLUMN_MSB 0x10
+#define ST7565_COLUMN_LSB 0x00
+#define ST7565_RMW 0xE0
 
-#define ST7565_RESISTOR_RATIO       0x20
-#define ST7565_POWER_CONTROL        0x28
+#define ST7565_RESISTOR_RATIO 0x20
+#define ST7565_POWER_CONTROL 0x28
 
-#define ST7565_RESET                0xE2
+#define ST7565_RESET 0xE2
 
 #endif /* _ST7565_H */
index 233f99636de4a9dd16cee230602f463003c688c8..16857445895fa256c937b29a33a9bedd68f5aa21 100644 (file)
 #include "api.h"
 #include "quantum.h"
 
-void dword_to_bytes(uint32_t dword, uint8_t * bytes) {
+void dword_to_bytes(uint32_t dword, uint8_t* bytes) {
     bytes[0] = (dword >> 24) & 0xFF;
-    bytes[1] = (dword >> 16) & 0xFF; 
-    bytes[2] = (dword >> 8) & 0xFF; 
-    bytes[3] = (dword >> 0) & 0xFF; 
+    bytes[1] = (dword >> 16) & 0xFF;
+    bytes[2] = (dword >> 8) & 0xFF;
+    bytes[3] = (dword >> 0) & 0xFF;
 }
 
-uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index) {
-    return ((uint32_t)bytes[index + 0] << 24) | ((uint32_t)bytes[index + 1] << 16) | ((uint32_t)bytes[index + 2] << 8) | (uint32_t)bytes[index + 3];
-}
+uint32_t bytes_to_dword(uint8_t* bytes, uint8_t index) { return ((uint32_t)bytes[index + 0] << 24) | ((uint32_t)bytes[index + 1] << 16) | ((uint32_t)bytes[index + 2] << 8) | (uint32_t)bytes[index + 3]; }
 
-__attribute__ ((weak))
-bool process_api_quantum(uint8_t length, uint8_t * data) {
-    return process_api_keyboard(length, data);
-}
+__attribute__((weak)) bool process_api_quantum(uint8_t length, uint8_t* data) { return process_api_keyboard(length, data); }
 
-__attribute__ ((weak))
-bool process_api_keyboard(uint8_t length, uint8_t * data) {
-    return process_api_user(length, data);
-}
+__attribute__((weak)) bool process_api_keyboard(uint8_t length, uint8_t* data) { return process_api_user(length, data); }
 
-__attribute__ ((weak))
-bool process_api_user(uint8_t length, uint8_t * data) {
-    return true;
-}
+__attribute__((weak)) bool process_api_user(uint8_t length, uint8_t* data) { return true; }
 
-void process_api(uint16_t length, uint8_t * data) {
+void process_api(uint16_t length, uint8_t* data) {
     // SEND_STRING("\nRX: ");
     // for (uint8_t i = 0; i < length; i++) {
     //     send_byte(data[i]);
     //     SEND_STRING(" ");
     // }
-    if (!process_api_quantum(length, data))
-        return;
+    if (!process_api_quantum(length, data)) return;
 
     switch (data[0]) {
         case MT_SET_DATA:
@@ -65,10 +53,10 @@ void process_api(uint16_t length, uint8_t * data) {
                     break;
                 }
                 case DT_RGBLIGHT: {
-                    #ifdef RGBLIGHT_ENABLE
-                        uint32_t rgblight = bytes_to_dword(data, 2);
-                        eeconfig_update_rgblight(rgblight);
-                    #endif
+#ifdef RGBLIGHT_ENABLE
+                    uint32_t rgblight = bytes_to_dword(data, 2);
+                    eeconfig_update_rgblight(rgblight);
+#endif
                     break;
                 }
             }
@@ -79,12 +67,12 @@ void process_api(uint16_t length, uint8_t * data) {
                     break;
                 }
                 case DT_DEBUG: {
-                    uint8_t debug_bytes[1] = { eeprom_read_byte(EECONFIG_DEBUG) };
+                    uint8_t debug_bytes[1] = {eeprom_read_byte(EECONFIG_DEBUG)};
                     MT_GET_DATA_ACK(DT_DEBUG, debug_bytes, 1);
                     break;
                 }
                 case DT_DEFAULT_LAYER: {
-                    uint8_t default_bytes[1] = { eeprom_read_byte(EECONFIG_DEFAULT_LAYER) };
+                    uint8_t default_bytes[1] = {eeprom_read_byte(EECONFIG_DEFAULT_LAYER)};
                     MT_GET_DATA_ACK(DT_DEFAULT_LAYER, default_bytes, 1);
                     break;
                 }
@@ -95,35 +83,35 @@ void process_api(uint16_t length, uint8_t * data) {
                     break;
                 }
                 case DT_AUDIO: {
-                    #ifdef AUDIO_ENABLE
-                        uint8_t audio_bytes[1] = { eeprom_read_byte(EECONFIG_AUDIO) };
-                        MT_GET_DATA_ACK(DT_AUDIO, audio_bytes, 1);
-                    #else
-                        MT_GET_DATA_ACK(DT_AUDIO, NULL, 0);
-                    #endif
+#ifdef AUDIO_ENABLE
+                    uint8_t audio_bytes[1] = {eeprom_read_byte(EECONFIG_AUDIO)};
+                    MT_GET_DATA_ACK(DT_AUDIO, audio_bytes, 1);
+#else
+                    MT_GET_DATA_ACK(DT_AUDIO, NULL, 0);
+#endif
                     break;
                 }
                 case DT_BACKLIGHT: {
-                    #ifdef BACKLIGHT_ENABLE
-                        uint8_t backlight_bytes[1] = { eeprom_read_byte(EECONFIG_BACKLIGHT) };
-                        MT_GET_DATA_ACK(DT_BACKLIGHT, backlight_bytes, 1);
-                    #else
-                        MT_GET_DATA_ACK(DT_BACKLIGHT, NULL, 0);
-                    #endif
+#ifdef BACKLIGHT_ENABLE
+                    uint8_t backlight_bytes[1] = {eeprom_read_byte(EECONFIG_BACKLIGHT)};
+                    MT_GET_DATA_ACK(DT_BACKLIGHT, backlight_bytes, 1);
+#else
+                    MT_GET_DATA_ACK(DT_BACKLIGHT, NULL, 0);
+#endif
                     break;
                 }
                 case DT_RGBLIGHT: {
-                    #ifdef RGBLIGHT_ENABLE
-                        uint8_t rgblight_bytes[4];
-                        dword_to_bytes(eeconfig_read_rgblight(), rgblight_bytes);
-                        MT_GET_DATA_ACK(DT_RGBLIGHT, rgblight_bytes, 4);
-                    #else
-                        MT_GET_DATA_ACK(DT_RGBLIGHT, NULL, 0);
-                    #endif
+#ifdef RGBLIGHT_ENABLE
+                    uint8_t rgblight_bytes[4];
+                    dword_to_bytes(eeconfig_read_rgblight(), rgblight_bytes);
+                    MT_GET_DATA_ACK(DT_RGBLIGHT, rgblight_bytes, 4);
+#else
+                    MT_GET_DATA_ACK(DT_RGBLIGHT, NULL, 0);
+#endif
                     break;
                 }
                 case DT_KEYMAP_OPTIONS: {
-                    uint8_t keymap_bytes[1] = { eeconfig_read_keymap() };
+                    uint8_t keymap_bytes[1] = {eeconfig_read_keymap()};
                     MT_GET_DATA_ACK(DT_KEYMAP_OPTIONS, keymap_bytes, 1);
                     break;
                 }
@@ -172,24 +160,23 @@ void process_api(uint16_t length, uint8_t * data) {
             break;
         case MT_TYPE_ERROR:
             break;
-        default: ; // command not recognised
+        default: // command not recognised
             SEND_BYTES(MT_TYPE_ERROR, DT_NONE, data, length);
             break;
 
-        // #ifdef RGBLIGHT_ENABLE
-        // case 0x27: ; // RGB LED functions
-        //     switch (*data++) {
-        //         case 0x00: ; // Update HSV
-        //             rgblight_sethsv((data[0] << 8 | data[1]) % 360, data[2], data[3]);
-        //             break;
-        //         case 0x01: ; // Update RGB
-        //             break;
-        //         case 0x02: ; // Update mode
-        //             rgblight_mode(data[0]);
-        //             break;
-        //     }
-        //     break;
-        // #endif
+            // #ifdef RGBLIGHT_ENABLE
+            // case 0x27: ; // RGB LED functions
+            //     switch (*data++) {
+            //         case 0x00: ; // Update HSV
+            //             rgblight_sethsv((data[0] << 8 | data[1]) % 360, data[2], data[3]);
+            //             break;
+            //         case 0x01: ; // Update RGB
+            //             break;
+            //         case 0x02: ; // Update mode
+            //             rgblight_mode(data[0]);
+            //             break;
+            //     }
+            //     break;
+            // #endif
     }
-
 }
index fc016391bcf38052ffce72004c01b90272a4bc00..90a4de833931bc356616643529967c46bdcdaea5 100644 (file)
 #define _API_H_
 
 #ifdef __AVR__
-#include "lufa.h"
+#    include "lufa.h"
 #endif
 
 enum MESSAGE_TYPE {
-    MT_GET_DATA =      0x10, // Get data from keyboard
-    MT_GET_DATA_ACK =  0x11, // returned data to process (ACK)
-    MT_SET_DATA =      0x20, // Set data on keyboard
-    MT_SET_DATA_ACK =  0x21, // returned data to confirm (ACK)
-    MT_SEND_DATA =     0x30, // Sending data/action from keyboard
-    MT_SEND_DATA_ACK = 0x31, // returned data/action confirmation (ACK)
-    MT_EXE_ACTION =    0x40, // executing actions on keyboard
-    MT_EXE_ACTION_ACK =0x41, // return confirmation/value (ACK)
-    MT_TYPE_ERROR =    0x80 // type not recognised (ACK)
+    MT_GET_DATA       = 0x10,  // Get data from keyboard
+    MT_GET_DATA_ACK   = 0x11,  // returned data to process (ACK)
+    MT_SET_DATA       = 0x20,  // Set data on keyboard
+    MT_SET_DATA_ACK   = 0x21,  // returned data to confirm (ACK)
+    MT_SEND_DATA      = 0x30,  // Sending data/action from keyboard
+    MT_SEND_DATA_ACK  = 0x31,  // returned data/action confirmation (ACK)
+    MT_EXE_ACTION     = 0x40,  // executing actions on keyboard
+    MT_EXE_ACTION_ACK = 0x41,  // return confirmation/value (ACK)
+    MT_TYPE_ERROR     = 0x80   // type not recognised (ACK)
 };
 
-enum DATA_TYPE {
-    DT_NONE = 0x00,
-    DT_HANDSHAKE,
-    DT_DEFAULT_LAYER,
-    DT_CURRENT_LAYER,
-    DT_KEYMAP_OPTIONS,
-    DT_BACKLIGHT,
-    DT_RGBLIGHT,
-    DT_UNICODE,
-    DT_DEBUG,
-    DT_AUDIO,
-    DT_QUANTUM_ACTION,
-    DT_KEYBOARD_ACTION,
-    DT_USER_ACTION,
-    DT_KEYMAP_SIZE,
-    DT_KEYMAP
-};
+enum DATA_TYPE { DT_NONE = 0x00, DT_HANDSHAKE, DT_DEFAULT_LAYER, DT_CURRENT_LAYER, DT_KEYMAP_OPTIONS, DT_BACKLIGHT, DT_RGBLIGHT, DT_UNICODE, DT_DEBUG, DT_AUDIO, DT_QUANTUM_ACTION, DT_KEYBOARD_ACTION, DT_USER_ACTION, DT_KEYMAP_SIZE, DT_KEYMAP };
 
-void dword_to_bytes(uint32_t dword, uint8_t * bytes);
-uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index);
+void     dword_to_bytes(uint32_t dword, uint8_t* bytes);
+uint32_t bytes_to_dword(uint8_t* bytes, uint8_t index);
 
 #define MT_GET_DATA(data_type, data, length) SEND_BYTES(MT_GET_DATA, data_type, data, length)
 #define MT_GET_DATA_ACK(data_type, data, length) SEND_BYTES(MT_GET_DATA_ACK, data_type, data, length)
@@ -63,15 +47,12 @@ uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index);
 #define MT_EXE_ACTION(data_type, data, length) SEND_BYTES(MT_EXE_ACTION, data_type, data, length)
 #define MT_EXE_ACTION_ACK(data_type, data, length) SEND_BYTES(MT_EXE_ACTION_ACK, data_type, data, length)
 
-void process_api(uint16_t length, uint8_t * data);
+void process_api(uint16_t length, uint8_t* data);
 
-__attribute__ ((weak))
-bool process_api_quantum(uint8_t length, uint8_t * data);
+__attribute__((weak)) bool process_api_quantum(uint8_t length, uint8_t* data);
 
-__attribute__ ((weak))
-bool process_api_keyboard(uint8_t length, uint8_t * data);
+__attribute__((weak)) bool process_api_keyboard(uint8_t length, uint8_t* data);
 
-__attribute__ ((weak))
-bool process_api_user(uint8_t length, uint8_t * data);
+__attribute__((weak)) bool process_api_user(uint8_t length, uint8_t* data);
 
 #endif
index 89c66a2a20d026f3d064b68c16f78d39315829c4..07c90cf804bc7dbedc9b742bffdcdc77a4b782c3 100644 (file)
@@ -18,7 +18,7 @@
 #include "print.h"
 #include "qmk_midi.h"
 
-void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint16_t length) {
+void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t* bytes, uint16_t length) {
     // SEND_STRING("\nTX: ");
     // for (uint8_t i = 0; i < length; i++) {
     //     send_byte(bytes[i]);
@@ -29,7 +29,6 @@ void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes,
         return;
     }
 
-
     // The buffer size required is calculated as the following
     // API_SYSEX_MAX_SIZE is the maximum length
     // In addition to that we have a two byte message header consisting of the message_type and data_type
@@ -37,14 +36,14 @@ void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes,
     // We just add one extra byte in case it's not divisible by 7
     // Then we have an unencoded header consisting of 4 bytes
     // Plus a one byte terminator
-    const unsigned message_header = 2;
+    const unsigned message_header    = 2;
     const unsigned unencoded_message = API_SYSEX_MAX_SIZE + message_header;
     const unsigned encoding_overhead = unencoded_message / 7 + 1;
-    const unsigned encoded_size = unencoded_message + encoding_overhead;
-    const unsigned unencoded_header = 4;
-    const unsigned terminator = 1;
-    const unsigned buffer_size = encoded_size + unencoded_header + terminator;
-    uint8_t buffer[encoded_size + unencoded_header + terminator];
+    const unsigned encoded_size      = unencoded_message + encoding_overhead;
+    const unsigned unencoded_header  = 4;
+    const unsigned terminator        = 1;
+    const unsigned buffer_size       = encoded_size + unencoded_header + terminator;
+    uint8_t        buffer[encoded_size + unencoded_header + terminator];
     // The unencoded header
     buffer[0] = 0xF0;
     buffer[1] = 0x00;
@@ -53,16 +52,16 @@ void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes,
 
     // We copy the message to the end of the array, this way we can do an inplace encoding, using the same
     // buffer for both input and output
-    const unsigned message_size = length + message_header;
-    uint8_t* unencoded_start = buffer + buffer_size - message_size;
-    uint8_t* ptr = unencoded_start;
-    *(ptr++) = message_type;
-    *(ptr++) = data_type;
+    const unsigned message_size    = length + message_header;
+    uint8_t*       unencoded_start = buffer + buffer_size - message_size;
+    uint8_t*       ptr             = unencoded_start;
+    *(ptr++)                       = message_type;
+    *(ptr++)                       = data_type;
     memcpy(ptr, bytes, length);
 
     unsigned encoded_length = sysex_encode(buffer + unencoded_header, unencoded_start, message_size);
-    unsigned final_size = unencoded_header + encoded_length + terminator;
-    buffer[final_size - 1] = 0xF7;
+    unsigned final_size     = unencoded_header + encoded_length + terminator;
+    buffer[final_size - 1]  = 0xF7;
     midi_send_array(&midi_device, final_size, buffer);
 
     // SEND_STRING("\nTD: ");
index a23f00f5724eb5ae9521a96a94f390577507ed1e..58b8cbb663c8a5bb3db0a5d73afb3a3e1891c8b5 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "api.h"
 
-void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint16_t length);
+void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t* bytes, uint16_t length);
 
 #define SEND_BYTES(mt, dt, b, l) send_bytes_sysex(mt, dt, b, l)
 
index 3da164c736ef44611ab77f7de713e199b927141f..781378788c63eeac4e9b3e45390f97836bc85e07 100644 (file)
@@ -18,9 +18,9 @@
 #include <string.h>
 //#include <math.h>
 #if defined(__AVR__)
-  #include <avr/pgmspace.h>
-  #include <avr/interrupt.h>
-  #include <avr/io.h>
+#    include <avr/pgmspace.h>
+#    include <avr/interrupt.h>
+#    include <avr/io.h>
 #endif
 #include "print.h"
 #include "audio.h"
 // Timer Abstractions
 // -----------------------------------------------------------------------------
 
-//Currently we support timers 1 and 3 used at the sime time, channels A-C,
-//pins PB5, PB6, PB7, PC4, PC5, and PC6
+// Currently we support timers 1 and 3 used at the sime time, channels A-C,
+// pins PB5, PB6, PB7, PC4, PC5, and PC6
 #if defined(C6_AUDIO)
-    #define CPIN_AUDIO
-    #define CPIN_SET_DIRECTION DDRC |= _BV(PORTC6);
-    #define INIT_AUDIO_COUNTER_3 TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
-    #define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3A)
-    #define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3A)
-    #define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3A1);
-    #define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0));
-    #define TIMER_3_PERIOD     ICR3
-    #define TIMER_3_DUTY_CYCLE OCR3A
-    #define TIMER3_AUDIO_vect TIMER3_COMPA_vect
+#    define CPIN_AUDIO
+#    define CPIN_SET_DIRECTION DDRC |= _BV(PORTC6);
+#    define INIT_AUDIO_COUNTER_3 TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
+#    define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3A)
+#    define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3A)
+#    define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3A1);
+#    define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0));
+#    define TIMER_3_PERIOD ICR3
+#    define TIMER_3_DUTY_CYCLE OCR3A
+#    define TIMER3_AUDIO_vect TIMER3_COMPA_vect
 #endif
 #if defined(C5_AUDIO)
-    #define CPIN_AUDIO
-    #define CPIN_SET_DIRECTION DDRC |= _BV(PORTC5);
-    #define INIT_AUDIO_COUNTER_3 TCCR3A = (0 << COM3B1) | (0 << COM3B0) | (1 << WGM31) | (0 << WGM30);
-    #define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3B)
-    #define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3B)
-    #define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3B1);
-    #define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3B1) | _BV(COM3B0));
-    #define TIMER_3_PERIOD     ICR3
-    #define TIMER_3_DUTY_CYCLE OCR3B
-    #define TIMER3_AUDIO_vect TIMER3_COMPB_vect
+#    define CPIN_AUDIO
+#    define CPIN_SET_DIRECTION DDRC |= _BV(PORTC5);
+#    define INIT_AUDIO_COUNTER_3 TCCR3A = (0 << COM3B1) | (0 << COM3B0) | (1 << WGM31) | (0 << WGM30);
+#    define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3B)
+#    define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3B)
+#    define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3B1);
+#    define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3B1) | _BV(COM3B0));
+#    define TIMER_3_PERIOD ICR3
+#    define TIMER_3_DUTY_CYCLE OCR3B
+#    define TIMER3_AUDIO_vect TIMER3_COMPB_vect
 #endif
 #if defined(C4_AUDIO)
-    #define CPIN_AUDIO
-    #define CPIN_SET_DIRECTION DDRC |= _BV(PORTC4);
-    #define INIT_AUDIO_COUNTER_3 TCCR3A = (0 << COM3C1) | (0 << COM3C0) | (1 << WGM31) | (0 << WGM30);
-    #define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3C)
-    #define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3C)
-    #define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3C1);
-    #define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3C1) | _BV(COM3C0));
-    #define TIMER_3_PERIOD     ICR3
-    #define TIMER_3_DUTY_CYCLE OCR3C
-    #define TIMER3_AUDIO_vect TIMER3_COMPC_vect
+#    define CPIN_AUDIO
+#    define CPIN_SET_DIRECTION DDRC |= _BV(PORTC4);
+#    define INIT_AUDIO_COUNTER_3 TCCR3A = (0 << COM3C1) | (0 << COM3C0) | (1 << WGM31) | (0 << WGM30);
+#    define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3C)
+#    define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3C)
+#    define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3C1);
+#    define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3C1) | _BV(COM3C0));
+#    define TIMER_3_PERIOD ICR3
+#    define TIMER_3_DUTY_CYCLE OCR3C
+#    define TIMER3_AUDIO_vect TIMER3_COMPC_vect
 #endif
 
 #if defined(B5_AUDIO)
-    #define BPIN_AUDIO
-    #define BPIN_SET_DIRECTION DDRB |= _BV(PORTB5);
-    #define INIT_AUDIO_COUNTER_1 TCCR1A = (0 << COM1A1) | (0 << COM1A0) | (1 << WGM11) | (0 << WGM10);
-    #define ENABLE_AUDIO_COUNTER_1_ISR TIMSK1 |= _BV(OCIE1A)
-    #define DISABLE_AUDIO_COUNTER_1_ISR TIMSK1 &= ~_BV(OCIE1A)
-    #define ENABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A |= _BV(COM1A1);
-    #define DISABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A &= ~(_BV(COM1A1) | _BV(COM1A0));
-    #define TIMER_1_PERIOD     ICR1
-    #define TIMER_1_DUTY_CYCLE OCR1A
-    #define TIMER1_AUDIO_vect TIMER1_COMPA_vect
+#    define BPIN_AUDIO
+#    define BPIN_SET_DIRECTION DDRB |= _BV(PORTB5);
+#    define INIT_AUDIO_COUNTER_1 TCCR1A = (0 << COM1A1) | (0 << COM1A0) | (1 << WGM11) | (0 << WGM10);
+#    define ENABLE_AUDIO_COUNTER_1_ISR TIMSK1 |= _BV(OCIE1A)
+#    define DISABLE_AUDIO_COUNTER_1_ISR TIMSK1 &= ~_BV(OCIE1A)
+#    define ENABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A |= _BV(COM1A1);
+#    define DISABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A &= ~(_BV(COM1A1) | _BV(COM1A0));
+#    define TIMER_1_PERIOD ICR1
+#    define TIMER_1_DUTY_CYCLE OCR1A
+#    define TIMER1_AUDIO_vect TIMER1_COMPA_vect
 #endif
 #if defined(B6_AUDIO)
-    #define BPIN_AUDIO
-    #define BPIN_SET_DIRECTION DDRB |= _BV(PORTB6);
-    #define INIT_AUDIO_COUNTER_1 TCCR1A = (0 << COM1B1) | (0 << COM1B0) | (1 << WGM11) | (0 << WGM10);
-    #define ENABLE_AUDIO_COUNTER_1_ISR TIMSK1 |= _BV(OCIE1B)
-    #define DISABLE_AUDIO_COUNTER_1_ISR TIMSK1 &= ~_BV(OCIE1B)
-    #define ENABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A |= _BV(COM1B1);
-    #define DISABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A &= ~(_BV(COM1B1) | _BV(COM1B0));
-    #define TIMER_1_PERIOD     ICR1
-    #define TIMER_1_DUTY_CYCLE OCR1B
-    #define TIMER1_AUDIO_vect TIMER1_COMPB_vect
+#    define BPIN_AUDIO
+#    define BPIN_SET_DIRECTION DDRB |= _BV(PORTB6);
+#    define INIT_AUDIO_COUNTER_1 TCCR1A = (0 << COM1B1) | (0 << COM1B0) | (1 << WGM11) | (0 << WGM10);
+#    define ENABLE_AUDIO_COUNTER_1_ISR TIMSK1 |= _BV(OCIE1B)
+#    define DISABLE_AUDIO_COUNTER_1_ISR TIMSK1 &= ~_BV(OCIE1B)
+#    define ENABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A |= _BV(COM1B1);
+#    define DISABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A &= ~(_BV(COM1B1) | _BV(COM1B0));
+#    define TIMER_1_PERIOD ICR1
+#    define TIMER_1_DUTY_CYCLE OCR1B
+#    define TIMER1_AUDIO_vect TIMER1_COMPB_vect
 #endif
 #if defined(B7_AUDIO)
-    #define BPIN_AUDIO
-    #define BPIN_SET_DIRECTION DDRB |= _BV(PORTB7);
-    #define INIT_AUDIO_COUNTER_1 TCCR1A = (0 << COM1C1) | (0 << COM1C0) | (1 << WGM11) | (0 << WGM10);
-    #define ENABLE_AUDIO_COUNTER_1_ISR TIMSK1 |= _BV(OCIE1C)
-    #define DISABLE_AUDIO_COUNTER_1_ISR TIMSK1 &= ~_BV(OCIE1C)
-    #define ENABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A |= _BV(COM1C1);
-    #define DISABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A &= ~(_BV(COM1C1) | _BV(COM1C0));
-    #define TIMER_1_PERIOD     ICR1
-    #define TIMER_1_DUTY_CYCLE OCR1C
-    #define TIMER1_AUDIO_vect TIMER1_COMPC_vect
+#    define BPIN_AUDIO
+#    define BPIN_SET_DIRECTION DDRB |= _BV(PORTB7);
+#    define INIT_AUDIO_COUNTER_1 TCCR1A = (0 << COM1C1) | (0 << COM1C0) | (1 << WGM11) | (0 << WGM10);
+#    define ENABLE_AUDIO_COUNTER_1_ISR TIMSK1 |= _BV(OCIE1C)
+#    define DISABLE_AUDIO_COUNTER_1_ISR TIMSK1 &= ~_BV(OCIE1C)
+#    define ENABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A |= _BV(COM1C1);
+#    define DISABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A &= ~(_BV(COM1C1) | _BV(COM1C0));
+#    define TIMER_1_PERIOD ICR1
+#    define TIMER_1_DUTY_CYCLE OCR1C
+#    define TIMER1_AUDIO_vect TIMER1_COMPC_vect
 #endif
 // -----------------------------------------------------------------------------
 
-
-int voices = 0;
-int voice_place = 0;
-float frequency = 0;
+int   voices        = 0;
+int   voice_place   = 0;
+float frequency     = 0;
 float frequency_alt = 0;
-int volume = 0;
-long position = 0;
+int   volume        = 0;
+long  position      = 0;
 
 float frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0};
-int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
-bool sliding = false;
+int   volumes[8]     = {0, 0, 0, 0, 0, 0, 0, 0};
+bool  sliding        = false;
 
 float place = 0;
 
-uint8_t * sample;
+uint8_t* sample;
 uint16_t sample_length = 0;
 
-bool     playing_notes = false;
-bool     playing_note = false;
+bool     playing_notes  = false;
+bool     playing_note   = false;
 float    note_frequency = 0;
-float    note_length = 0;
-uint8_t  note_tempo = TEMPO_DEFAULT;
-float    note_timbre = TIMBRE_DEFAULT;
-uint16_t note_position = 0;
-float (* notes_pointer)[][2];
+float    note_length    = 0;
+uint8_t  note_tempo     = TEMPO_DEFAULT;
+float    note_timbre    = TIMBRE_DEFAULT;
+uint16_t note_position  = 0;
+float (*notes_pointer)[][2];
 uint16_t notes_count;
 bool     notes_repeat;
 bool     note_resting = false;
 
 uint16_t current_note = 0;
-uint8_t rest_counter = 0;
+uint8_t  rest_counter = 0;
 
 #ifdef VIBRATO_ENABLE
-float vibrato_counter = 0;
+float vibrato_counter  = 0;
 float vibrato_strength = .5;
-float vibrato_rate = 0.125;
+float vibrato_rate     = 0.125;
 #endif
 
 float polyphony_rate = 0;
@@ -157,73 +156,69 @@ static bool audio_initialized = false;
 audio_config_t audio_config;
 
 uint16_t envelope_index = 0;
-bool glissando = true;
+bool     glissando      = true;
 
 #ifndef STARTUP_SONG
-    #define STARTUP_SONG SONG(STARTUP_SOUND)
+#    define STARTUP_SONG SONG(STARTUP_SOUND)
 #endif
 #ifndef AUDIO_ON_SONG
-    #define AUDIO_ON_SONG SONG(AUDIO_ON_SOUND)
+#    define AUDIO_ON_SONG SONG(AUDIO_ON_SOUND)
 #endif
 #ifndef AUDIO_OFF_SONG
-    #define AUDIO_OFF_SONG SONG(AUDIO_OFF_SOUND)
+#    define AUDIO_OFF_SONG SONG(AUDIO_OFF_SOUND)
 #endif
-float startup_song[][2] = STARTUP_SONG;
-float audio_on_song[][2] = AUDIO_ON_SONG;
+float startup_song[][2]   = STARTUP_SONG;
+float audio_on_song[][2]  = AUDIO_ON_SONG;
 float audio_off_song[][2] = AUDIO_OFF_SONG;
 
-void audio_init()
-{
-
+void audio_init() {
     // Check EEPROM
-    if (!eeconfig_is_enabled())
-    {
+    if (!eeconfig_is_enabled()) {
         eeconfig_init();
     }
     audio_config.raw = eeconfig_read_audio();
 
     if (!audio_initialized) {
+// Set audio ports as output
+#ifdef CPIN_AUDIO
+        CPIN_SET_DIRECTION
+        DISABLE_AUDIO_COUNTER_3_ISR;
+#endif
+#ifdef BPIN_AUDIO
+        BPIN_SET_DIRECTION
+        DISABLE_AUDIO_COUNTER_1_ISR;
+#endif
 
-        // Set audio ports as output
-        #ifdef CPIN_AUDIO
-          CPIN_SET_DIRECTION
-          DISABLE_AUDIO_COUNTER_3_ISR;
-        #endif
-        #ifdef BPIN_AUDIO
-          BPIN_SET_DIRECTION
-          DISABLE_AUDIO_COUNTER_1_ISR;
-        #endif
-
-        // TCCR3A / TCCR3B: Timer/Counter #3 Control Registers TCCR3A/TCCR3B, TCCR1A/TCCR1B
-        // Compare Output Mode (COM3An and COM1An) = 0b00 = Normal port operation
-        //   OC3A -- PC6
-        //   OC3B -- PC5
-        //   OC3C -- PC4
-        //   OC1A -- PB5
-        //   OC1B -- PB6
-        //   OC1C -- PB7
-
-        // Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14. Period = ICR3, Duty Cycle OCR3A)
-        //   OCR3A - PC6
-        //   OCR3B - PC5
-        //   OCR3C - PC4
-        //   OCR1A - PB5
-        //   OCR1B - PB6
-        //   OCR1C - PB7
-
-        // Clock Select (CS3n) = 0b010 = Clock / 8
-        #ifdef CPIN_AUDIO
-            INIT_AUDIO_COUNTER_3
-            TCCR3B = (1 << WGM33)  | (1 << WGM32)  | (0 << CS32)  | (1 << CS31) | (0 << CS30);
-            TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (440 * CPU_PRESCALER));
-            TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre);
-        #endif
-        #ifdef BPIN_AUDIO
-            INIT_AUDIO_COUNTER_1
-            TCCR1B = (1 << WGM13)  | (1 << WGM12)  | (0 << CS12)  | (1 << CS11) | (0 << CS10);
-            TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (440 * CPU_PRESCALER));
-            TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre);
-        #endif
+// TCCR3A / TCCR3B: Timer/Counter #3 Control Registers TCCR3A/TCCR3B, TCCR1A/TCCR1B
+// Compare Output Mode (COM3An and COM1An) = 0b00 = Normal port operation
+//   OC3A -- PC6
+//   OC3B -- PC5
+//   OC3C -- PC4
+//   OC1A -- PB5
+//   OC1B -- PB6
+//   OC1C -- PB7
+
+// Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14. Period = ICR3, Duty Cycle OCR3A)
+//   OCR3A - PC6
+//   OCR3B - PC5
+//   OCR3C - PC4
+//   OCR1A - PB5
+//   OCR1B - PB6
+//   OCR1C - PB7
+
+// Clock Select (CS3n) = 0b010 = Clock / 8
+#ifdef CPIN_AUDIO
+        INIT_AUDIO_COUNTER_3
+        TCCR3B             = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30);
+        TIMER_3_PERIOD     = (uint16_t)(((float)F_CPU) / (440 * CPU_PRESCALER));
+        TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre);
+#endif
+#ifdef BPIN_AUDIO
+        INIT_AUDIO_COUNTER_1
+        TCCR1B             = (1 << WGM13) | (1 << WGM12) | (0 << CS12) | (1 << CS11) | (0 << CS10);
+        TIMER_1_PERIOD     = (uint16_t)(((float)F_CPU) / (440 * CPU_PRESCALER));
+        TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre);
+#endif
 
         audio_initialized = true;
     }
@@ -231,11 +226,9 @@ void audio_init()
     if (audio_config.enable) {
         PLAY_SONG(startup_song);
     }
-
 }
 
-void stop_all_notes()
-{
+void stop_all_notes() {
     dprintf("audio stop all notes");
 
     if (!audio_initialized) {
@@ -243,31 +236,29 @@ void stop_all_notes()
     }
     voices = 0;
 
-    #ifdef CPIN_AUDIO
-        DISABLE_AUDIO_COUNTER_3_ISR;
-        DISABLE_AUDIO_COUNTER_3_OUTPUT;
-    #endif
+#ifdef CPIN_AUDIO
+    DISABLE_AUDIO_COUNTER_3_ISR;
+    DISABLE_AUDIO_COUNTER_3_OUTPUT;
+#endif
 
-    #ifdef BPIN_AUDIO
-        DISABLE_AUDIO_COUNTER_1_ISR;
-        DISABLE_AUDIO_COUNTER_1_OUTPUT;
-    #endif
+#ifdef BPIN_AUDIO
+    DISABLE_AUDIO_COUNTER_1_ISR;
+    DISABLE_AUDIO_COUNTER_1_OUTPUT;
+#endif
 
     playing_notes = false;
-    playing_note = false;
-    frequency = 0;
+    playing_note  = false;
+    frequency     = 0;
     frequency_alt = 0;
-    volume = 0;
+    volume        = 0;
 
-    for (uint8_t i = 0; i < 8; i++)
-    {
+    for (uint8_t i = 0; i < 8; i++) {
         frequencies[i] = 0;
-        volumes[i] = 0;
+        volumes[i]     = 0;
     }
 }
 
-void stop_note(float freq)
-{
+void stop_note(float freq) {
     dprintf("audio stop note freq=%d", (int)freq);
 
     if (playing_note) {
@@ -277,133 +268,129 @@ void stop_note(float freq)
         for (int i = 7; i >= 0; i--) {
             if (frequencies[i] == freq) {
                 frequencies[i] = 0;
-                volumes[i] = 0;
+                volumes[i]     = 0;
                 for (int j = i; (j < 7); j++) {
-                    frequencies[j] = frequencies[j+1];
-                    frequencies[j+1] = 0;
-                    volumes[j] = volumes[j+1];
-                    volumes[j+1] = 0;
+                    frequencies[j]     = frequencies[j + 1];
+                    frequencies[j + 1] = 0;
+                    volumes[j]         = volumes[j + 1];
+                    volumes[j + 1]     = 0;
                 }
                 break;
             }
         }
         voices--;
-        if (voices < 0)
-            voices = 0;
+        if (voices < 0) voices = 0;
         if (voice_place >= voices) {
             voice_place = 0;
         }
         if (voices == 0) {
-            #ifdef CPIN_AUDIO
-                DISABLE_AUDIO_COUNTER_3_ISR;
-                DISABLE_AUDIO_COUNTER_3_OUTPUT;
-            #endif
-            #ifdef BPIN_AUDIO
-                DISABLE_AUDIO_COUNTER_1_ISR;
-                DISABLE_AUDIO_COUNTER_1_OUTPUT;
-            #endif
-            frequency = 0;
+#ifdef CPIN_AUDIO
+            DISABLE_AUDIO_COUNTER_3_ISR;
+            DISABLE_AUDIO_COUNTER_3_OUTPUT;
+#endif
+#ifdef BPIN_AUDIO
+            DISABLE_AUDIO_COUNTER_1_ISR;
+            DISABLE_AUDIO_COUNTER_1_OUTPUT;
+#endif
+            frequency     = 0;
             frequency_alt = 0;
-            volume = 0;
-            playing_note = false;
+            volume        = 0;
+            playing_note  = false;
         }
     }
 }
 
 #ifdef VIBRATO_ENABLE
 
-float mod(float a, int b)
-{
+float mod(float a, int b) {
     float r = fmod(a, b);
     return r < 0 ? r + b : r;
 }
 
 float vibrato(float average_freq) {
-    #ifdef VIBRATO_STRENGTH_ENABLE
-        float vibrated_freq = average_freq * pow(vibrato_lut[(int)vibrato_counter], vibrato_strength);
-    #else
-        float vibrated_freq = average_freq * vibrato_lut[(int)vibrato_counter];
-    #endif
-    vibrato_counter = mod((vibrato_counter + vibrato_rate * (1.0 + 440.0/average_freq)), VIBRATO_LUT_LENGTH);
+#    ifdef VIBRATO_STRENGTH_ENABLE
+    float vibrated_freq = average_freq * pow(vibrato_lut[(int)vibrato_counter], vibrato_strength);
+#    else
+    float vibrated_freq = average_freq * vibrato_lut[(int)vibrato_counter];
+#    endif
+    vibrato_counter = mod((vibrato_counter + vibrato_rate * (1.0 + 440.0 / average_freq)), VIBRATO_LUT_LENGTH);
     return vibrated_freq;
 }
 
 #endif
 
 #ifdef CPIN_AUDIO
-ISR(TIMER3_AUDIO_vect)
-{
+ISR(TIMER3_AUDIO_vect) {
     float freq;
 
     if (playing_note) {
         if (voices > 0) {
-
-            #ifdef BPIN_AUDIO
+#    ifdef BPIN_AUDIO
             float freq_alt = 0;
-                if (voices > 1) {
-                    if (polyphony_rate == 0) {
-                        if (glissando) {
-                            if (frequency_alt != 0 && frequency_alt < frequencies[voices - 2] && frequency_alt < frequencies[voices - 2] * pow(2, -440/frequencies[voices - 2]/12/2)) {
-                                frequency_alt = frequency_alt * pow(2, 440/frequency_alt/12/2);
-                            } else if (frequency_alt != 0 && frequency_alt > frequencies[voices - 2] && frequency_alt > frequencies[voices - 2] * pow(2, 440/frequencies[voices - 2]/12/2)) {
-                                frequency_alt = frequency_alt * pow(2, -440/frequency_alt/12/2);
-                            } else {
-                                frequency_alt = frequencies[voices - 2];
-                            }
+            if (voices > 1) {
+                if (polyphony_rate == 0) {
+                    if (glissando) {
+                        if (frequency_alt != 0 && frequency_alt < frequencies[voices - 2] && frequency_alt < frequencies[voices - 2] * pow(2, -440 / frequencies[voices - 2] / 12 / 2)) {
+                            frequency_alt = frequency_alt * pow(2, 440 / frequency_alt / 12 / 2);
+                        } else if (frequency_alt != 0 && frequency_alt > frequencies[voices - 2] && frequency_alt > frequencies[voices - 2] * pow(2, 440 / frequencies[voices - 2] / 12 / 2)) {
+                            frequency_alt = frequency_alt * pow(2, -440 / frequency_alt / 12 / 2);
                         } else {
                             frequency_alt = frequencies[voices - 2];
                         }
-
-                        #ifdef VIBRATO_ENABLE
-                            if (vibrato_strength > 0) {
-                                freq_alt = vibrato(frequency_alt);
-                            } else {
-                                freq_alt = frequency_alt;
-                            }
-                        #else
-                            freq_alt = frequency_alt;
-                        #endif
+                    } else {
+                        frequency_alt = frequencies[voices - 2];
                     }
 
-                    if (envelope_index < 65535) {
-                        envelope_index++;
+#        ifdef VIBRATO_ENABLE
+                    if (vibrato_strength > 0) {
+                        freq_alt = vibrato(frequency_alt);
+                    } else {
+                        freq_alt = frequency_alt;
                     }
+#        else
+                    freq_alt = frequency_alt;
+#        endif
+                }
 
-                    freq_alt = voice_envelope(freq_alt);
+                if (envelope_index < 65535) {
+                    envelope_index++;
+                }
 
-                    if (freq_alt < 30.517578125) {
-                        freq_alt = 30.52;
-                    }
+                freq_alt = voice_envelope(freq_alt);
 
-                    TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (freq_alt * CPU_PRESCALER));
-                    TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq_alt * CPU_PRESCALER)) * note_timbre);
+                if (freq_alt < 30.517578125) {
+                    freq_alt = 30.52;
                 }
-            #endif
+
+                TIMER_1_PERIOD     = (uint16_t)(((float)F_CPU) / (freq_alt * CPU_PRESCALER));
+                TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq_alt * CPU_PRESCALER)) * note_timbre);
+            }
+#    endif
 
             if (polyphony_rate > 0) {
                 if (voices > 1) {
                     voice_place %= voices;
                     if (place++ > (frequencies[voice_place] / polyphony_rate / CPU_PRESCALER)) {
                         voice_place = (voice_place + 1) % voices;
-                        place = 0.0;
+                        place       = 0.0;
                     }
                 }
 
-                #ifdef VIBRATO_ENABLE
-                    if (vibrato_strength > 0) {
-                        freq = vibrato(frequencies[voice_place]);
-                    } else {
-                        freq = frequencies[voice_place];
-                    }
-                #else
+#    ifdef VIBRATO_ENABLE
+                if (vibrato_strength > 0) {
+                    freq = vibrato(frequencies[voice_place]);
+                } else {
                     freq = frequencies[voice_place];
-                #endif
+                }
+#    else
+                freq = frequencies[voice_place];
+#    endif
             } else {
                 if (glissando) {
-                    if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
-                        frequency = frequency * pow(2, 440/frequency/12/2);
-                    } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
-                        frequency = frequency * pow(2, -440/frequency/12/2);
+                    if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440 / frequencies[voices - 1] / 12 / 2)) {
+                        frequency = frequency * pow(2, 440 / frequency / 12 / 2);
+                    } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440 / frequencies[voices - 1] / 12 / 2)) {
+                        frequency = frequency * pow(2, -440 / frequency / 12 / 2);
                     } else {
                         frequency = frequencies[voices - 1];
                     }
@@ -411,15 +398,15 @@ ISR(TIMER3_AUDIO_vect)
                     frequency = frequencies[voices - 1];
                 }
 
-                #ifdef VIBRATO_ENABLE
-                    if (vibrato_strength > 0) {
-                        freq = vibrato(frequency);
-                    } else {
-                        freq = frequency;
-                    }
-                #else
+#    ifdef VIBRATO_ENABLE
+                if (vibrato_strength > 0) {
+                    freq = vibrato(frequency);
+                } else {
                     freq = frequency;
-                #endif
+                }
+#    else
+                freq = frequency;
+#    endif
             }
 
             if (envelope_index < 65535) {
@@ -432,32 +419,32 @@ ISR(TIMER3_AUDIO_vect)
                 freq = 30.52;
             }
 
-            TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
+            TIMER_3_PERIOD     = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
             TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
         }
     }
 
     if (playing_notes) {
         if (note_frequency > 0) {
-            #ifdef VIBRATO_ENABLE
-                if (vibrato_strength > 0) {
-                    freq = vibrato(note_frequency);
-                } else {
-                    freq = note_frequency;
-                }
-            #else
-                    freq = note_frequency;
-            #endif
+#    ifdef VIBRATO_ENABLE
+            if (vibrato_strength > 0) {
+                freq = vibrato(note_frequency);
+            } else {
+                freq = note_frequency;
+            }
+#    else
+            freq = note_frequency;
+#    endif
 
             if (envelope_index < 65535) {
                 envelope_index++;
             }
             freq = voice_envelope(freq);
 
-            TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
+            TIMER_3_PERIOD     = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
             TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
         } else {
-            TIMER_3_PERIOD = 0;
+            TIMER_3_PERIOD     = 0;
             TIMER_3_DUTY_CYCLE = 0;
         }
 
@@ -489,16 +476,16 @@ ISR(TIMER3_AUDIO_vect)
                 current_note--;
                 if ((*notes_pointer)[current_note][0] == (*notes_pointer)[current_note + 1][0]) {
                     note_frequency = 0;
-                    note_length = 1;
+                    note_length    = 1;
                 } else {
                     note_frequency = (*notes_pointer)[current_note][0];
-                    note_length = 1;
+                    note_length    = 1;
                 }
             } else {
-                note_resting = false;
+                note_resting   = false;
                 envelope_index = 0;
                 note_frequency = (*notes_pointer)[current_note][0];
-                note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+                note_length    = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
             }
 
             note_position = 0;
@@ -507,15 +494,14 @@ ISR(TIMER3_AUDIO_vect)
 
     if (!audio_config.enable) {
         playing_notes = false;
-        playing_note = false;
+        playing_note  = false;
     }
 }
 #endif
 
 #ifdef BPIN_AUDIO
-ISR(TIMER1_AUDIO_vect)
-{
-    #if defined(BPIN_AUDIO) && !defined(CPIN_AUDIO)
+ISR(TIMER1_AUDIO_vect) {
+#    if defined(BPIN_AUDIO) && !defined(CPIN_AUDIO)
     float freq = 0;
 
     if (playing_note) {
@@ -525,25 +511,25 @@ ISR(TIMER1_AUDIO_vect)
                     voice_place %= voices;
                     if (place++ > (frequencies[voice_place] / polyphony_rate / CPU_PRESCALER)) {
                         voice_place = (voice_place + 1) % voices;
-                        place = 0.0;
+                        place       = 0.0;
                     }
                 }
 
-                #ifdef VIBRATO_ENABLE
-                    if (vibrato_strength > 0) {
-                        freq = vibrato(frequencies[voice_place]);
-                    } else {
-                        freq = frequencies[voice_place];
-                    }
-                #else
+#        ifdef VIBRATO_ENABLE
+                if (vibrato_strength > 0) {
+                    freq = vibrato(frequencies[voice_place]);
+                } else {
                     freq = frequencies[voice_place];
-                #endif
+                }
+#        else
+                freq = frequencies[voice_place];
+#        endif
             } else {
                 if (glissando) {
-                    if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
-                        frequency = frequency * pow(2, 440/frequency/12/2);
-                    } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
-                        frequency = frequency * pow(2, -440/frequency/12/2);
+                    if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440 / frequencies[voices - 1] / 12 / 2)) {
+                        frequency = frequency * pow(2, 440 / frequency / 12 / 2);
+                    } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440 / frequencies[voices - 1] / 12 / 2)) {
+                        frequency = frequency * pow(2, -440 / frequency / 12 / 2);
                     } else {
                         frequency = frequencies[voices - 1];
                     }
@@ -551,15 +537,15 @@ ISR(TIMER1_AUDIO_vect)
                     frequency = frequencies[voices - 1];
                 }
 
-                #ifdef VIBRATO_ENABLE
-                    if (vibrato_strength > 0) {
-                        freq = vibrato(frequency);
-                    } else {
-                        freq = frequency;
-                    }
-                #else
+#        ifdef VIBRATO_ENABLE
+                if (vibrato_strength > 0) {
+                    freq = vibrato(frequency);
+                } else {
                     freq = frequency;
-                #endif
+                }
+#        else
+                freq = frequency;
+#        endif
             }
 
             if (envelope_index < 65535) {
@@ -572,32 +558,32 @@ ISR(TIMER1_AUDIO_vect)
                 freq = 30.52;
             }
 
-            TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
+            TIMER_1_PERIOD     = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
             TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
         }
     }
 
     if (playing_notes) {
         if (note_frequency > 0) {
-            #ifdef VIBRATO_ENABLE
-                if (vibrato_strength > 0) {
-                    freq = vibrato(note_frequency);
-                } else {
-                    freq = note_frequency;
-                }
-            #else
-                    freq = note_frequency;
-            #endif
+#        ifdef VIBRATO_ENABLE
+            if (vibrato_strength > 0) {
+                freq = vibrato(note_frequency);
+            } else {
+                freq = note_frequency;
+            }
+#        else
+            freq = note_frequency;
+#        endif
 
             if (envelope_index < 65535) {
                 envelope_index++;
             }
             freq = voice_envelope(freq);
 
-            TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
+            TIMER_1_PERIOD     = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
             TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
         } else {
-            TIMER_1_PERIOD = 0;
+            TIMER_1_PERIOD     = 0;
             TIMER_1_DUTY_CYCLE = 0;
         }
 
@@ -629,16 +615,16 @@ ISR(TIMER1_AUDIO_vect)
                 current_note--;
                 if ((*notes_pointer)[current_note][0] == (*notes_pointer)[current_note + 1][0]) {
                     note_frequency = 0;
-                    note_length = 1;
+                    note_length    = 1;
                 } else {
                     note_frequency = (*notes_pointer)[current_note][0];
-                    note_length = 1;
+                    note_length    = 1;
                 }
             } else {
-                note_resting = false;
+                note_resting   = false;
                 envelope_index = 0;
                 note_frequency = (*notes_pointer)[current_note][0];
-                note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+                note_length    = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
             }
 
             note_position = 0;
@@ -647,14 +633,13 @@ ISR(TIMER1_AUDIO_vect)
 
     if (!audio_config.enable) {
         playing_notes = false;
-        playing_note = false;
+        playing_note  = false;
     }
-#endif
+#    endif
 }
 #endif
 
 void play_note(float freq, int vol) {
-
     dprintf("audio play note freq=%d vol=%d", (int)freq, vol);
 
     if (!audio_initialized) {
@@ -662,16 +647,15 @@ void play_note(float freq, int vol) {
     }
 
     if (audio_config.enable && voices < 8) {
-        #ifdef CPIN_AUDIO
-            DISABLE_AUDIO_COUNTER_3_ISR;
-        #endif
-        #ifdef BPIN_AUDIO
-            DISABLE_AUDIO_COUNTER_1_ISR;
-        #endif
+#ifdef CPIN_AUDIO
+        DISABLE_AUDIO_COUNTER_3_ISR;
+#endif
+#ifdef BPIN_AUDIO
+        DISABLE_AUDIO_COUNTER_1_ISR;
+#endif
 
         // Cancel notes if notes are playing
-        if (playing_notes)
-            stop_all_notes();
+        if (playing_notes) stop_all_notes();
 
         playing_note = true;
 
@@ -679,90 +663,78 @@ void play_note(float freq, int vol) {
 
         if (freq > 0) {
             frequencies[voices] = freq;
-            volumes[voices] = vol;
+            volumes[voices]     = vol;
             voices++;
         }
 
-        #ifdef CPIN_AUDIO
-            ENABLE_AUDIO_COUNTER_3_ISR;
-            ENABLE_AUDIO_COUNTER_3_OUTPUT;
-        #endif
-        #ifdef BPIN_AUDIO
-            #ifdef CPIN_AUDIO
-            if (voices > 1) {
-                ENABLE_AUDIO_COUNTER_1_ISR;
-                ENABLE_AUDIO_COUNTER_1_OUTPUT;
-            }
-            #else
+#ifdef CPIN_AUDIO
+        ENABLE_AUDIO_COUNTER_3_ISR;
+        ENABLE_AUDIO_COUNTER_3_OUTPUT;
+#endif
+#ifdef BPIN_AUDIO
+#    ifdef CPIN_AUDIO
+        if (voices > 1) {
             ENABLE_AUDIO_COUNTER_1_ISR;
             ENABLE_AUDIO_COUNTER_1_OUTPUT;
-            #endif
-        #endif
+        }
+#    else
+        ENABLE_AUDIO_COUNTER_1_ISR;
+        ENABLE_AUDIO_COUNTER_1_OUTPUT;
+#    endif
+#endif
     }
-
 }
 
-void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat)
-{
-
+void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat) {
     if (!audio_initialized) {
         audio_init();
     }
 
     if (audio_config.enable) {
-
-        #ifdef CPIN_AUDIO
-            DISABLE_AUDIO_COUNTER_3_ISR;
-        #endif
-        #ifdef BPIN_AUDIO
-            DISABLE_AUDIO_COUNTER_1_ISR;
-        #endif
+#ifdef CPIN_AUDIO
+        DISABLE_AUDIO_COUNTER_3_ISR;
+#endif
+#ifdef BPIN_AUDIO
+        DISABLE_AUDIO_COUNTER_1_ISR;
+#endif
 
         // Cancel note if a note is playing
-        if (playing_note)
-            stop_all_notes();
+        if (playing_note) stop_all_notes();
 
         playing_notes = true;
 
         notes_pointer = np;
-        notes_count = n_count;
-        notes_repeat = n_repeat;
+        notes_count   = n_count;
+        notes_repeat  = n_repeat;
 
-        place = 0;
+        place        = 0;
         current_note = 0;
 
         note_frequency = (*notes_pointer)[current_note][0];
-        note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
-        note_position = 0;
+        note_length    = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+        note_position  = 0;
 
-
-        #ifdef CPIN_AUDIO
-            ENABLE_AUDIO_COUNTER_3_ISR;
-            ENABLE_AUDIO_COUNTER_3_OUTPUT;
-        #endif
-        #ifdef BPIN_AUDIO
-            #ifndef CPIN_AUDIO
-            ENABLE_AUDIO_COUNTER_1_ISR;
-            ENABLE_AUDIO_COUNTER_1_OUTPUT;
-            #endif
-        #endif
+#ifdef CPIN_AUDIO
+        ENABLE_AUDIO_COUNTER_3_ISR;
+        ENABLE_AUDIO_COUNTER_3_OUTPUT;
+#endif
+#ifdef BPIN_AUDIO
+#    ifndef CPIN_AUDIO
+        ENABLE_AUDIO_COUNTER_1_ISR;
+        ENABLE_AUDIO_COUNTER_1_OUTPUT;
+#    endif
+#endif
     }
-
 }
 
-bool is_playing_notes(void) {
-    return playing_notes;
-}
+bool is_playing_notes(void) { return playing_notes; }
 
-bool is_audio_on(void) {
-    return (audio_config.enable != 0);
-}
+bool is_audio_on(void) { return (audio_config.enable != 0); }
 
 void audio_toggle(void) {
     audio_config.enable ^= 1;
     eeconfig_update_audio(audio_config.raw);
-    if (audio_config.enable)
-        audio_on_user();
+    if (audio_config.enable) audio_on_user();
 }
 
 void audio_on(void) {
@@ -784,73 +756,45 @@ void audio_off(void) {
 
 // Vibrato rate functions
 
-void set_vibrato_rate(float rate) {
-    vibrato_rate = rate;
-}
+void set_vibrato_rate(float rate) { vibrato_rate = rate; }
 
-void increase_vibrato_rate(float change) {
-    vibrato_rate *= change;
-}
+void increase_vibrato_rate(float change) { vibrato_rate *= change; }
 
-void decrease_vibrato_rate(float change) {
-    vibrato_rate /= change;
-}
+void decrease_vibrato_rate(float change) { vibrato_rate /= change; }
 
-#ifdef VIBRATO_STRENGTH_ENABLE
+#    ifdef VIBRATO_STRENGTH_ENABLE
 
-void set_vibrato_strength(float strength) {
-    vibrato_strength = strength;
-}
+void set_vibrato_strength(float strength) { vibrato_strength = strength; }
 
-void increase_vibrato_strength(float change) {
-    vibrato_strength *= change;
-}
+void increase_vibrato_strength(float change) { vibrato_strength *= change; }
 
-void decrease_vibrato_strength(float change) {
-    vibrato_strength /= change;
-}
+void decrease_vibrato_strength(float change) { vibrato_strength /= change; }
 
-#endif  /* VIBRATO_STRENGTH_ENABLE */
+#    endif /* VIBRATO_STRENGTH_ENABLE */
 
 #endif /* VIBRATO_ENABLE */
 
 // Polyphony functions
 
-void set_polyphony_rate(float rate) {
-    polyphony_rate = rate;
-}
+void set_polyphony_rate(float rate) { polyphony_rate = rate; }
 
-void enable_polyphony() {
-    polyphony_rate = 5;
-}
+void enable_polyphony() { polyphony_rate = 5; }
 
-void disable_polyphony() {
-    polyphony_rate = 0;
-}
+void disable_polyphony() { polyphony_rate = 0; }
 
-void increase_polyphony_rate(float change) {
-    polyphony_rate *= change;
-}
+void increase_polyphony_rate(float change) { polyphony_rate *= change; }
 
-void decrease_polyphony_rate(float change) {
-    polyphony_rate /= change;
-}
+void decrease_polyphony_rate(float change) { polyphony_rate /= change; }
 
 // Timbre function
 
-void set_timbre(float timbre) {
-    note_timbre = timbre;
-}
+void set_timbre(float timbre) { note_timbre = timbre; }
 
 // Tempo functions
 
-void set_tempo(uint8_t tempo) {
-    note_tempo = tempo;
-}
+void set_tempo(uint8_t tempo) { note_tempo = tempo; }
 
-void decrease_tempo(uint8_t tempo_change) {
-    note_tempo += tempo_change;
-}
+void decrease_tempo(uint8_t tempo_change) { note_tempo += tempo_change; }
 
 void increase_tempo(uint8_t tempo_change) {
     if (note_tempo - tempo_change < 10) {
index 8136c5b258fad6d6260d0437d2643f9fcbf87736..2bcc27b4a19adecd6ecec01f822928833895c0a1 100644 (file)
@@ -19,7 +19,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #if defined(__AVR__)
-  #include <avr/io.h>
+#    include <avr/io.h>
 #endif
 #include "wait.h"
 #include "musical_notes.h"
@@ -39,9 +39,9 @@
 typedef union {
     uint8_t raw;
     struct {
-        bool    enable :1;
-        bool    clicky_enable :1;
-        uint8_t level  :6;
+        bool    enable : 1;
+        bool    clicky_enable : 1;
+        uint8_t level 6;
     };
 } audio_config_t;
 
@@ -58,13 +58,13 @@ void set_vibrato_rate(float rate);
 void increase_vibrato_rate(float change);
 void decrease_vibrato_rate(float change);
 
-#ifdef VIBRATO_STRENGTH_ENABLE
+#    ifdef VIBRATO_STRENGTH_ENABLE
 
 void set_vibrato_strength(float strength);
 void increase_vibrato_strength(float change);
 void decrease_vibrato_strength(float change);
 
-#endif
+#    endif
 
 #endif
 
@@ -85,25 +85,23 @@ void decrease_tempo(uint8_t tempo_change);
 void audio_init(void);
 
 #ifdef PWM_AUDIO
-void play_sample(uint8_t * s, uint16_t l, bool r);
+void play_sample(uint8_t* s, uint16_t l, bool r);
 #endif
 void play_note(float freq, int vol);
 void stop_note(float freq);
 void stop_all_notes(void);
 void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat);
 
-#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
-                           0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
-                           0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
-                           0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
-                           0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
+#define SCALE \
+    (int8_t[]) { 0 + (12 * 0), 2 + (12 * 0), 4 + (12 * 0), 5 + (12 * 0), 7 + (12 * 0), 9 + (12 * 0), 11 + (12 * 0), 0 + (12 * 1), 2 + (12 * 1), 4 + (12 * 1), 5 + (12 * 1), 7 + (12 * 1), 9 + (12 * 1), 11 + (12 * 1), 0 + (12 * 2), 2 + (12 * 2), 4 + (12 * 2), 5 + (12 * 2), 7 + (12 * 2), 9 + (12 * 2), 11 + (12 * 2), 0 + (12 * 3), 2 + (12 * 3), 4 + (12 * 3), 5 + (12 * 3), 7 + (12 * 3), 9 + (12 * 3), 11 + (12 * 3), 0 + (12 * 4), 2 + (12 * 4), 4 + (12 * 4), 5 + (12 * 4), 7 + (12 * 4), 9 + (12 * 4), 11 + (12 * 4), }
 
 // These macros are used to allow play_notes to play an array of indeterminate
 // length. This works around the limitation of C's sizeof operation on pointers.
 // The global float array for the song must be used here.
 #define NOTE_ARRAY_SIZE(x) ((int16_t)(sizeof(x) / (sizeof(x[0]))))
-#define PLAY_NOTE_ARRAY(note_array, note_repeat, deprecated_arg) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat)); \
-       _Pragma ("message \"'PLAY_NOTE_ARRAY' macro is deprecated\"")
+#define PLAY_NOTE_ARRAY(note_array, note_repeat, deprecated_arg)           \
+    play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat)); \
+    _Pragma("message \"'PLAY_NOTE_ARRAY' macro is deprecated\"")
 #define PLAY_SONG(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), false)
 #define PLAY_LOOP(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), true)
 
index de0cd15c5825199ed5b08d36bb5495ab5cecbf2e..87d625301fbf2c33aab2228cb4b5e2d763bd5e6f 100644 (file)
 
 // -----------------------------------------------------------------------------
 
-int voices = 0;
-int voice_place = 0;
-float frequency = 0;
+int   voices        = 0;
+int   voice_place   = 0;
+float frequency     = 0;
 float frequency_alt = 0;
-int volume = 0;
-long position = 0;
+int   volume        = 0;
+long  position      = 0;
 
 float frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0};
-int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
-bool sliding = false;
+int   volumes[8]     = {0, 0, 0, 0, 0, 0, 0, 0};
+bool  sliding        = false;
 
 float place = 0;
 
-uint8_t * sample;
+uint8_t *sample;
 uint16_t sample_length = 0;
 
-bool     playing_notes = false;
-bool     playing_note = false;
+bool     playing_notes  = false;
+bool     playing_note   = false;
 float    note_frequency = 0;
-float    note_length = 0;
-uint8_t  note_tempo = TEMPO_DEFAULT;
-float    note_timbre = TIMBRE_DEFAULT;
-uint16_t note_position = 0;
-float (* notes_pointer)[][2];
+float    note_length    = 0;
+uint8_t  note_tempo     = TEMPO_DEFAULT;
+float    note_timbre    = TIMBRE_DEFAULT;
+uint16_t note_position  = 0;
+float (*notes_pointer)[][2];
 uint16_t notes_count;
 bool     notes_repeat;
 bool     note_resting = false;
 
 uint16_t current_note = 0;
-uint8_t rest_counter = 0;
+uint8_t  rest_counter = 0;
 
 #ifdef VIBRATO_ENABLE
-float vibrato_counter = 0;
+float vibrato_counter  = 0;
 float vibrato_strength = .5;
-float vibrato_rate = 0.125;
+float vibrato_rate     = 0.125;
 #endif
 
 float polyphony_rate = 0;
@@ -70,10 +70,10 @@ static bool audio_initialized = false;
 audio_config_t audio_config;
 
 uint16_t envelope_index = 0;
-bool glissando = true;
+bool     glissando      = true;
 
 #ifndef STARTUP_SONG
-    #define STARTUP_SONG SONG(STARTUP_SOUND)
+#    define STARTUP_SONG SONG(STARTUP_SOUND)
 #endif
 float startup_song[][2] = STARTUP_SONG;
 
@@ -81,27 +81,32 @@ static void gpt_cb8(GPTDriver *gptp);
 
 #define DAC_BUFFER_SIZE 100
 #ifndef DAC_SAMPLE_MAX
-#define DAC_SAMPLE_MAX  65535U
+#    define DAC_SAMPLE_MAX 65535U
 #endif
 
-#define START_CHANNEL_1() gptStart(&GPTD6, &gpt6cfg1); \
+#define START_CHANNEL_1()        \
+    gptStart(&GPTD6, &gpt6cfg1); \
     gptStartContinuous(&GPTD6, 2U)
-#define START_CHANNEL_2() gptStart(&GPTD7, &gpt7cfg1); \
+#define START_CHANNEL_2()        \
+    gptStart(&GPTD7, &gpt7cfg1); \
     gptStartContinuous(&GPTD7, 2U)
 #define STOP_CHANNEL_1() gptStopTimer(&GPTD6)
 #define STOP_CHANNEL_2() gptStopTimer(&GPTD7)
-#define RESTART_CHANNEL_1() STOP_CHANNEL_1(); \
+#define RESTART_CHANNEL_1() \
+    STOP_CHANNEL_1();       \
     START_CHANNEL_1()
-#define RESTART_CHANNEL_2() STOP_CHANNEL_2(); \
+#define RESTART_CHANNEL_2() \
+    STOP_CHANNEL_2();       \
     START_CHANNEL_2()
-#define UPDATE_CHANNEL_1_FREQ(freq) gpt6cfg1.frequency = freq * DAC_BUFFER_SIZE; \
+#define UPDATE_CHANNEL_1_FREQ(freq)              \
+    gpt6cfg1.frequency = freq * DAC_BUFFER_SIZE; \
     RESTART_CHANNEL_1()
-#define UPDATE_CHANNEL_2_FREQ(freq) gpt7cfg1.frequency = freq * DAC_BUFFER_SIZE; \
+#define UPDATE_CHANNEL_2_FREQ(freq)              \
+    gpt7cfg1.frequency = freq * DAC_BUFFER_SIZE; \
     RESTART_CHANNEL_2()
 #define GET_CHANNEL_1_FREQ (uint16_t)(gpt6cfg1.frequency * DAC_BUFFER_SIZE)
 #define GET_CHANNEL_2_FREQ (uint16_t)(gpt7cfg1.frequency * DAC_BUFFER_SIZE)
 
-
 /*
  * GPT6 configuration.
  */
@@ -112,27 +117,20 @@ static void gpt_cb8(GPTDriver *gptp);
 //   .dier         = 0U
 // };
 
-GPTConfig gpt6cfg1 = {
-  .frequency    = 440U*DAC_BUFFER_SIZE,
-  .callback     = NULL,
-  .cr2          = TIM_CR2_MMS_1,    /* MMS = 010 = TRGO on Update Event.    */
-  .dier         = 0U
-};
+GPTConfig gpt6cfg1 = {.frequency = 440U * DAC_BUFFER_SIZE,
+                      .callback  = NULL,
+                      .cr2       = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event.    */
+                      .dier      = 0U};
 
-GPTConfig gpt7cfg1 = {
-  .frequency    = 440U*DAC_BUFFER_SIZE,
-  .callback     = NULL,
-  .cr2          = TIM_CR2_MMS_1,    /* MMS = 010 = TRGO on Update Event.    */
-  .dier         = 0U
-};
-
-GPTConfig gpt8cfg1 = {
-  .frequency    = 10,
-  .callback     = gpt_cb8,
-  .cr2          = TIM_CR2_MMS_1,    /* MMS = 010 = TRGO on Update Event.    */
-  .dier         = 0U
-};
+GPTConfig gpt7cfg1 = {.frequency = 440U * DAC_BUFFER_SIZE,
+                      .callback  = NULL,
+                      .cr2       = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event.    */
+                      .dier      = 0U};
 
+GPTConfig gpt8cfg1 = {.frequency = 10,
+                      .callback  = gpt_cb8,
+                      .cr2       = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event.    */
+                      .dier      = 0U};
 
 /*
  * DAC test buffer (sine wave).
@@ -205,122 +203,101 @@ GPTConfig gpt8cfg1 = {
 
 // squarewave
 static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = {
-  // First half is max, second half is 0
-  [0                 ... DAC_BUFFER_SIZE/2-1] = DAC_SAMPLE_MAX,
-  [DAC_BUFFER_SIZE/2 ... DAC_BUFFER_SIZE  -1] = 0,
+    // First half is max, second half is 0
+    [0 ... DAC_BUFFER_SIZE / 2 - 1]               = DAC_SAMPLE_MAX,
+    [DAC_BUFFER_SIZE / 2 ... DAC_BUFFER_SIZE - 1] = 0,
 };
 
 // squarewave
 static const dacsample_t dac_buffer_2[DAC_BUFFER_SIZE] = {
-  // opposite of dac_buffer above
-  [0                 ... DAC_BUFFER_SIZE/2-1] = 0,
-  [DAC_BUFFER_SIZE/2 ... DAC_BUFFER_SIZE  -1] = DAC_SAMPLE_MAX,
+    // opposite of dac_buffer above
+    [0 ... DAC_BUFFER_SIZE / 2 - 1]               = 0,
+    [DAC_BUFFER_SIZE / 2 ... DAC_BUFFER_SIZE - 1] = DAC_SAMPLE_MAX,
 };
 
 /*
  * DAC streaming callback.
  */
-size_t nx = 0, ny = 0, nz = 0;
+size_t      nx = 0, ny = 0, nz = 0;
 static void end_cb1(DACDriver *dacp, dacsample_t *buffer, size_t n) {
+    (void)dacp;
 
-  (void)dacp;
-
-  nz++;
-  if (dac_buffer == buffer) {
-    nx += n;
-  }
-  else {
-    ny += n;
-  }
+    nz++;
+    if (dac_buffer == buffer) {
+        nx += n;
+    } else {
+        ny += n;
+    }
 
-  if ((nz % 1000) == 0) {
-    // palTogglePad(GPIOD, GPIOD_LED3);
-  }
+    if ((nz % 1000) == 0) {
+        // palTogglePad(GPIOD, GPIOD_LED3);
+    }
 }
 
 /*
  * DAC error callback.
  */
 static void error_cb1(DACDriver *dacp, dacerror_t err) {
+    (void)dacp;
+    (void)err;
 
-  (void)dacp;
-  (void)err;
-
-  chSysHalt("DAC failure");
+    chSysHalt("DAC failure");
 }
 
-static const DACConfig dac1cfg1 = {
-  .init         = DAC_SAMPLE_MAX,
-  .datamode     = DAC_DHRM_12BIT_RIGHT
-};
+static const DACConfig dac1cfg1 = {.init = DAC_SAMPLE_MAX, .datamode = DAC_DHRM_12BIT_RIGHT};
 
-static const DACConversionGroup dacgrpcfg1 = {
-  .num_channels = 1U,
-  .end_cb       = end_cb1,
-  .error_cb     = error_cb1,
-  .trigger      = DAC_TRG(0)
-};
+static const DACConversionGroup dacgrpcfg1 = {.num_channels = 1U, .end_cb = end_cb1, .error_cb = error_cb1, .trigger = DAC_TRG(0)};
 
-static const DACConfig dac1cfg2 = {
-  .init         = DAC_SAMPLE_MAX,
-  .datamode     = DAC_DHRM_12BIT_RIGHT
-};
+static const DACConfig dac1cfg2 = {.init = DAC_SAMPLE_MAX, .datamode = DAC_DHRM_12BIT_RIGHT};
 
-static const DACConversionGroup dacgrpcfg2 = {
-  .num_channels = 1U,
-  .end_cb       = end_cb1,
-  .error_cb     = error_cb1,
-  .trigger      = DAC_TRG(0)
-};
+static const DACConversionGroup dacgrpcfg2 = {.num_channels = 1U, .end_cb = end_cb1, .error_cb = error_cb1, .trigger = DAC_TRG(0)};
 
 void audio_init() {
+    if (audio_initialized) {
+        return;
+    }
 
-  if (audio_initialized) {
-    return;
-  }
-
-  // Check EEPROM
-  #if defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
+// Check EEPROM
+#if defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
     if (!eeconfig_is_enabled()) {
-      eeconfig_init();
+        eeconfig_init();
     }
     audio_config.raw = eeconfig_read_audio();
-#else // ARM EEPROM
-    audio_config.enable = true;
-  #ifdef AUDIO_CLICKY_ON
+#else  // ARM EEPROM
+    audio_config.enable        = true;
+#    ifdef AUDIO_CLICKY_ON
     audio_config.clicky_enable = true;
-  #endif
-#endif // ARM EEPROM
-
-  /*
-   * Starting DAC1 driver, setting up the output pin as analog as suggested
-   * by the Reference Manual.
-   */
-  palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
-  palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
-  dacStart(&DACD1, &dac1cfg1);
-  dacStart(&DACD2, &dac1cfg2);
-
-  /*
-   * Starting GPT6/7 driver, it is used for triggering the DAC.
-   */
-  START_CHANNEL_1();
-  START_CHANNEL_2();
-
-  /*
-   * Starting a continuous conversion.
-   */
-  dacStartConversion(&DACD1, &dacgrpcfg1, (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE);
-  dacStartConversion(&DACD2, &dacgrpcfg2, (dacsample_t *)dac_buffer_2, DAC_BUFFER_SIZE);
-
-  audio_initialized = true;
-
-  if (audio_config.enable) {
-    PLAY_SONG(startup_song);
-  } else {
-    stop_all_notes();
-  }
-
+#    endif
+#endif  // ARM EEPROM
+
+    /*
+     * Starting DAC1 driver, setting up the output pin as analog as suggested
+     * by the Reference Manual.
+     */
+    palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
+    palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
+    dacStart(&DACD1, &dac1cfg1);
+    dacStart(&DACD2, &dac1cfg2);
+
+    /*
+     * Starting GPT6/7 driver, it is used for triggering the DAC.
+     */
+    START_CHANNEL_1();
+    START_CHANNEL_2();
+
+    /*
+     * Starting a continuous conversion.
+     */
+    dacStartConversion(&DACD1, &dacgrpcfg1, (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE);
+    dacStartConversion(&DACD2, &dacgrpcfg2, (dacsample_t *)dac_buffer_2, DAC_BUFFER_SIZE);
+
+    audio_initialized = true;
+
+    if (audio_config.enable) {
+        PLAY_SONG(startup_song);
+    } else {
+        stop_all_notes();
+    }
 }
 
 void stop_all_notes() {
@@ -336,437 +313,396 @@ void stop_all_notes() {
     gptStopTimer(&GPTD8);
 
     playing_notes = false;
-    playing_note = false;
-    frequency = 0;
+    playing_note  = false;
+    frequency     = 0;
     frequency_alt = 0;
-    volume = 0;
+    volume        = 0;
 
-    for (uint8_t i = 0; i < 8; i++)
-    {
+    for (uint8_t i = 0; i < 8; i++) {
         frequencies[i] = 0;
-        volumes[i] = 0;
+        volumes[i]     = 0;
     }
 }
 
 void stop_note(float freq) {
-  dprintf("audio stop note freq=%d", (int)freq);
+    dprintf("audio stop note freq=%d", (int)freq);
 
-  if (playing_note) {
-    if (!audio_initialized) {
-      audio_init();
-    }
-    for (int i = 7; i >= 0; i--) {
-      if (frequencies[i] == freq) {
-        frequencies[i] = 0;
-        volumes[i] = 0;
-        for (int j = i; (j < 7); j++) {
-          frequencies[j] = frequencies[j+1];
-          frequencies[j+1] = 0;
-          volumes[j] = volumes[j+1];
-          volumes[j+1] = 0;
+    if (playing_note) {
+        if (!audio_initialized) {
+            audio_init();
+        }
+        for (int i = 7; i >= 0; i--) {
+            if (frequencies[i] == freq) {
+                frequencies[i] = 0;
+                volumes[i]     = 0;
+                for (int j = i; (j < 7); j++) {
+                    frequencies[j]     = frequencies[j + 1];
+                    frequencies[j + 1] = 0;
+                    volumes[j]         = volumes[j + 1];
+                    volumes[j + 1]     = 0;
+                }
+                break;
+            }
+        }
+        voices--;
+        if (voices < 0) {
+            voices = 0;
+        }
+        if (voice_place >= voices) {
+            voice_place = 0;
+        }
+        if (voices == 0) {
+            STOP_CHANNEL_1();
+            STOP_CHANNEL_2();
+            gptStopTimer(&GPTD8);
+            frequency     = 0;
+            frequency_alt = 0;
+            volume        = 0;
+            playing_note  = false;
         }
-        break;
-      }
-    }
-    voices--;
-    if (voices < 0) {
-      voices = 0;
-    }
-    if (voice_place >= voices) {
-      voice_place = 0;
-    }
-    if (voices == 0) {
-      STOP_CHANNEL_1();
-      STOP_CHANNEL_2();
-      gptStopTimer(&GPTD8);
-      frequency = 0;
-      frequency_alt = 0;
-      volume = 0;
-      playing_note = false;
     }
-  }
 }
 
 #ifdef VIBRATO_ENABLE
 
 float mod(float a, int b) {
-  float r = fmod(a, b);
-  return r < 0 ? r + b : r;
+    float r = fmod(a, b);
+    return r < 0 ? r + b : r;
 }
 
 float vibrato(float average_freq) {
-  #ifdef VIBRATO_STRENGTH_ENABLE
+#    ifdef VIBRATO_STRENGTH_ENABLE
     float vibrated_freq = average_freq * pow(vibrato_lut[(int)vibrato_counter], vibrato_strength);
-  #else
+#    else
     float vibrated_freq = average_freq * vibrato_lut[(int)vibrato_counter];
-  #endif
-  vibrato_counter = mod((vibrato_counter + vibrato_rate * (1.0 + 440.0/average_freq)), VIBRATO_LUT_LENGTH);
-  return vibrated_freq;
+#    endif
+    vibrato_counter = mod((vibrato_counter + vibrato_rate * (1.0 + 440.0 / average_freq)), VIBRATO_LUT_LENGTH);
+    return vibrated_freq;
 }
 
 #endif
 
 static void gpt_cb8(GPTDriver *gptp) {
-  float freq;
-
-  if (playing_note) {
-    if (voices > 0) {
-
-      float freq_alt = 0;
-      if (voices > 1) {
-        if (polyphony_rate == 0) {
-          if (glissando) {
-            if (frequency_alt != 0 && frequency_alt < frequencies[voices - 2] && frequency_alt < frequencies[voices - 2] * pow(2, -440/frequencies[voices - 2]/12/2)) {
-              frequency_alt = frequency_alt * pow(2, 440/frequency_alt/12/2);
-            } else if (frequency_alt != 0 && frequency_alt > frequencies[voices - 2] && frequency_alt > frequencies[voices - 2] * pow(2, 440/frequencies[voices - 2]/12/2)) {
-              frequency_alt = frequency_alt * pow(2, -440/frequency_alt/12/2);
-            } else {
-              frequency_alt = frequencies[voices - 2];
-            }
-          } else {
-            frequency_alt = frequencies[voices - 2];
-          }
+    float freq;
 
-          #ifdef VIBRATO_ENABLE
-            if (vibrato_strength > 0) {
-              freq_alt = vibrato(frequency_alt);
-            } else {
-              freq_alt = frequency_alt;
-            }
-          #else
-            freq_alt = frequency_alt;
-          #endif
-        }
+    if (playing_note) {
+        if (voices > 0) {
+            float freq_alt = 0;
+            if (voices > 1) {
+                if (polyphony_rate == 0) {
+                    if (glissando) {
+                        if (frequency_alt != 0 && frequency_alt < frequencies[voices - 2] && frequency_alt < frequencies[voices - 2] * pow(2, -440 / frequencies[voices - 2] / 12 / 2)) {
+                            frequency_alt = frequency_alt * pow(2, 440 / frequency_alt / 12 / 2);
+                        } else if (frequency_alt != 0 && frequency_alt > frequencies[voices - 2] && frequency_alt > frequencies[voices - 2] * pow(2, 440 / frequencies[voices - 2] / 12 / 2)) {
+                            frequency_alt = frequency_alt * pow(2, -440 / frequency_alt / 12 / 2);
+                        } else {
+                            frequency_alt = frequencies[voices - 2];
+                        }
+                    } else {
+                        frequency_alt = frequencies[voices - 2];
+                    }
 
-        if (envelope_index < 65535) {
-          envelope_index++;
-        }
+#ifdef VIBRATO_ENABLE
+                    if (vibrato_strength > 0) {
+                        freq_alt = vibrato(frequency_alt);
+                    } else {
+                        freq_alt = frequency_alt;
+                    }
+#else
+                    freq_alt = frequency_alt;
+#endif
+                }
 
-        freq_alt = voice_envelope(freq_alt);
+                if (envelope_index < 65535) {
+                    envelope_index++;
+                }
 
-        if (freq_alt < 30.517578125) {
-          freq_alt = 30.52;
-        }
+                freq_alt = voice_envelope(freq_alt);
 
-        if (GET_CHANNEL_2_FREQ != (uint16_t)freq_alt) {
-          UPDATE_CHANNEL_2_FREQ(freq_alt);
-        } else {
-          RESTART_CHANNEL_2();
-        }
-        //note_timbre;
-      }
-
-      if (polyphony_rate > 0) {
-        if (voices > 1) {
-          voice_place %= voices;
-          if (place++ > (frequencies[voice_place] / polyphony_rate)) {
-            voice_place = (voice_place + 1) % voices;
-            place = 0.0;
-          }
-        }
+                if (freq_alt < 30.517578125) {
+                    freq_alt = 30.52;
+                }
 
-        #ifdef VIBRATO_ENABLE
-          if (vibrato_strength > 0) {
-              freq = vibrato(frequencies[voice_place]);
-          } else {
-              freq = frequencies[voice_place];
-          }
-        #else
-          freq = frequencies[voice_place];
-        #endif
-      } else {
-        if (glissando) {
-          if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
-            frequency = frequency * pow(2, 440/frequency/12/2);
-          } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
-            frequency = frequency * pow(2, -440/frequency/12/2);
-          } else {
-            frequency = frequencies[voices - 1];
-          }
-        } else {
-          frequency = frequencies[voices - 1];
-        }
+                if (GET_CHANNEL_2_FREQ != (uint16_t)freq_alt) {
+                    UPDATE_CHANNEL_2_FREQ(freq_alt);
+                } else {
+                    RESTART_CHANNEL_2();
+                }
+                // note_timbre;
+            }
 
-        #ifdef VIBRATO_ENABLE
-          if (vibrato_strength > 0) {
-            freq = vibrato(frequency);
-          } else {
-            freq = frequency;
-          }
-        #else
-          freq = frequency;
-        #endif
-      }
+            if (polyphony_rate > 0) {
+                if (voices > 1) {
+                    voice_place %= voices;
+                    if (place++ > (frequencies[voice_place] / polyphony_rate)) {
+                        voice_place = (voice_place + 1) % voices;
+                        place       = 0.0;
+                    }
+                }
 
-      if (envelope_index < 65535) {
-        envelope_index++;
-      }
+#ifdef VIBRATO_ENABLE
+                if (vibrato_strength > 0) {
+                    freq = vibrato(frequencies[voice_place]);
+                } else {
+                    freq = frequencies[voice_place];
+                }
+#else
+                freq = frequencies[voice_place];
+#endif
+            } else {
+                if (glissando) {
+                    if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440 / frequencies[voices - 1] / 12 / 2)) {
+                        frequency = frequency * pow(2, 440 / frequency / 12 / 2);
+                    } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440 / frequencies[voices - 1] / 12 / 2)) {
+                        frequency = frequency * pow(2, -440 / frequency / 12 / 2);
+                    } else {
+                        frequency = frequencies[voices - 1];
+                    }
+                } else {
+                    frequency = frequencies[voices - 1];
+                }
 
-      freq = voice_envelope(freq);
+#ifdef VIBRATO_ENABLE
+                if (vibrato_strength > 0) {
+                    freq = vibrato(frequency);
+                } else {
+                    freq = frequency;
+                }
+#else
+                freq = frequency;
+#endif
+            }
 
-      if (freq < 30.517578125) {
-        freq = 30.52;
-      }
+            if (envelope_index < 65535) {
+                envelope_index++;
+            }
 
+            freq = voice_envelope(freq);
 
-      if (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
-        UPDATE_CHANNEL_1_FREQ(freq);
-      } else {
-        RESTART_CHANNEL_1();
-      }
-      //note_timbre;
-    }
-  }
+            if (freq < 30.517578125) {
+                freq = 30.52;
+            }
 
-  if (playing_notes) {
-    if (note_frequency > 0) {
-      #ifdef VIBRATO_ENABLE
-        if (vibrato_strength > 0) {
-          freq = vibrato(note_frequency);
-        } else {
-          freq = note_frequency;
+            if (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
+                UPDATE_CHANNEL_1_FREQ(freq);
+            } else {
+                RESTART_CHANNEL_1();
+            }
+            // note_timbre;
         }
-      #else
-        freq = note_frequency;
-      #endif
-
-      if (envelope_index < 65535) {
-        envelope_index++;
-      }
-      freq = voice_envelope(freq);
-
-
-      if (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
-        UPDATE_CHANNEL_1_FREQ(freq);
-        UPDATE_CHANNEL_2_FREQ(freq);
-      }
-      //note_timbre;
-    } else {
-        // gptStopTimer(&GPTD6);
-        // gptStopTimer(&GPTD7);
     }
 
-    note_position++;
-    bool end_of_note = false;
-    if (GET_CHANNEL_1_FREQ > 0) {
-      if (!note_resting)
-        end_of_note = (note_position >= (note_length*8 - 1));
-      else
-        end_of_note = (note_position >= (note_length*8));
-    } else {
-      end_of_note = (note_position >= (note_length*8));
-    }
+    if (playing_notes) {
+        if (note_frequency > 0) {
+#ifdef VIBRATO_ENABLE
+            if (vibrato_strength > 0) {
+                freq = vibrato(note_frequency);
+            } else {
+                freq = note_frequency;
+            }
+#else
+            freq = note_frequency;
+#endif
 
-    if (end_of_note) {
-      current_note++;
-      if (current_note >= notes_count) {
-        if (notes_repeat) {
-          current_note = 0;
+            if (envelope_index < 65535) {
+                envelope_index++;
+            }
+            freq = voice_envelope(freq);
+
+            if (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
+                UPDATE_CHANNEL_1_FREQ(freq);
+                UPDATE_CHANNEL_2_FREQ(freq);
+            }
+            // note_timbre;
         } else {
-          STOP_CHANNEL_1();
-          STOP_CHANNEL_2();
-          // gptStopTimer(&GPTD8);
-          playing_notes = false;
-          return;
+            // gptStopTimer(&GPTD6);
+            // gptStopTimer(&GPTD7);
         }
-      }
-      if (!note_resting) {
-        note_resting = true;
-        current_note--;
-        if ((*notes_pointer)[current_note][0] == (*notes_pointer)[current_note + 1][0]) {
-          note_frequency = 0;
-          note_length = 1;
+
+        note_position++;
+        bool end_of_note = false;
+        if (GET_CHANNEL_1_FREQ > 0) {
+            if (!note_resting)
+                end_of_note = (note_position >= (note_length * 8 - 1));
+            else
+                end_of_note = (note_position >= (note_length * 8));
         } else {
-          note_frequency = (*notes_pointer)[current_note][0];
-          note_length = 1;
+            end_of_note = (note_position >= (note_length * 8));
         }
-      } else {
-        note_resting = false;
-        envelope_index = 0;
-        note_frequency = (*notes_pointer)[current_note][0];
-        note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
-      }
 
-      note_position = 0;
+        if (end_of_note) {
+            current_note++;
+            if (current_note >= notes_count) {
+                if (notes_repeat) {
+                    current_note = 0;
+                } else {
+                    STOP_CHANNEL_1();
+                    STOP_CHANNEL_2();
+                    // gptStopTimer(&GPTD8);
+                    playing_notes = false;
+                    return;
+                }
+            }
+            if (!note_resting) {
+                note_resting = true;
+                current_note--;
+                if ((*notes_pointer)[current_note][0] == (*notes_pointer)[current_note + 1][0]) {
+                    note_frequency = 0;
+                    note_length    = 1;
+                } else {
+                    note_frequency = (*notes_pointer)[current_note][0];
+                    note_length    = 1;
+                }
+            } else {
+                note_resting   = false;
+                envelope_index = 0;
+                note_frequency = (*notes_pointer)[current_note][0];
+                note_length    = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+            }
+
+            note_position = 0;
+        }
     }
-  }
 
-  if (!audio_config.enable) {
-    playing_notes = false;
-    playing_note = false;
-  }
+    if (!audio_config.enable) {
+        playing_notes = false;
+        playing_note  = false;
+    }
 }
 
 void play_note(float freq, int vol) {
+    dprintf("audio play note freq=%d vol=%d", (int)freq, vol);
 
-  dprintf("audio play note freq=%d vol=%d", (int)freq, vol);
-
-  if (!audio_initialized) {
-      audio_init();
-  }
-
-  if (audio_config.enable && voices < 8) {
-
-     // Cancel notes if notes are playing
-    if (playing_notes) {
-      stop_all_notes();
+    if (!audio_initialized) {
+        audio_init();
     }
 
-    playing_note = true;
+    if (audio_config.enable && voices < 8) {
+        // Cancel notes if notes are playing
+        if (playing_notes) {
+            stop_all_notes();
+        }
 
-    envelope_index = 0;
+        playing_note = true;
 
-    if (freq > 0) {
-      frequencies[voices] = freq;
-      volumes[voices] = vol;
-      voices++;
-    }
+        envelope_index = 0;
 
-    gptStart(&GPTD8, &gpt8cfg1);
-    gptStartContinuous(&GPTD8, 2U);
-    RESTART_CHANNEL_1();
-    RESTART_CHANNEL_2();
-  }
+        if (freq > 0) {
+            frequencies[voices] = freq;
+            volumes[voices]     = vol;
+            voices++;
+        }
 
+        gptStart(&GPTD8, &gpt8cfg1);
+        gptStartContinuous(&GPTD8, 2U);
+        RESTART_CHANNEL_1();
+        RESTART_CHANNEL_2();
+    }
 }
 
 void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat) {
-
-  if (!audio_initialized) {
-    audio_init();
-  }
-
-  if (audio_config.enable) {
-
-    // Cancel note if a note is playing
-    if (playing_note) {
-      stop_all_notes();
+    if (!audio_initialized) {
+        audio_init();
     }
 
-    playing_notes = true;
+    if (audio_config.enable) {
+        // Cancel note if a note is playing
+        if (playing_note) {
+            stop_all_notes();
+        }
 
-    notes_pointer = np;
-    notes_count = n_count;
-    notes_repeat = n_repeat;
+        playing_notes = true;
 
-    place = 0;
-    current_note = 0;
+        notes_pointer = np;
+        notes_count   = n_count;
+        notes_repeat  = n_repeat;
 
-    note_frequency = (*notes_pointer)[current_note][0];
-    note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
-    note_position = 0;
+        place        = 0;
+        current_note = 0;
 
-    gptStart(&GPTD8, &gpt8cfg1);
-    gptStartContinuous(&GPTD8, 2U);
-    RESTART_CHANNEL_1();
-    RESTART_CHANNEL_2();
-  }
-}
+        note_frequency = (*notes_pointer)[current_note][0];
+        note_length    = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+        note_position  = 0;
 
-bool is_playing_notes(void) {
-  return playing_notes;
+        gptStart(&GPTD8, &gpt8cfg1);
+        gptStartContinuous(&GPTD8, 2U);
+        RESTART_CHANNEL_1();
+        RESTART_CHANNEL_2();
+    }
 }
 
-bool is_audio_on(void) {
-  return (audio_config.enable != 0);
-}
+bool is_playing_notes(void) { return playing_notes; }
+
+bool is_audio_on(void) { return (audio_config.enable != 0); }
 
 void audio_toggle(void) {
-  audio_config.enable ^= 1;
-  eeconfig_update_audio(audio_config.raw);
-  if (audio_config.enable) {
-    audio_on_user();
-  }
+    audio_config.enable ^= 1;
+    eeconfig_update_audio(audio_config.raw);
+    if (audio_config.enable) {
+        audio_on_user();
+    }
 }
 
 void audio_on(void) {
-  audio_config.enable = 1;
-  eeconfig_update_audio(audio_config.raw);
-  audio_on_user();
+    audio_config.enable = 1;
+    eeconfig_update_audio(audio_config.raw);
+    audio_on_user();
 }
 
 void audio_off(void) {
-  stop_all_notes();
-  audio_config.enable = 0;
-  eeconfig_update_audio(audio_config.raw);
+    stop_all_notes();
+    audio_config.enable = 0;
+    eeconfig_update_audio(audio_config.raw);
 }
 
 #ifdef VIBRATO_ENABLE
 
 // Vibrato rate functions
 
-void set_vibrato_rate(float rate) {
-  vibrato_rate = rate;
-}
+void set_vibrato_rate(float rate) { vibrato_rate = rate; }
 
-void increase_vibrato_rate(float change) {
-  vibrato_rate *= change;
-}
+void increase_vibrato_rate(float change) { vibrato_rate *= change; }
 
-void decrease_vibrato_rate(float change) {
-  vibrato_rate /= change;
-}
+void decrease_vibrato_rate(float change) { vibrato_rate /= change; }
 
-#ifdef VIBRATO_STRENGTH_ENABLE
+#    ifdef VIBRATO_STRENGTH_ENABLE
 
-void set_vibrato_strength(float strength) {
-  vibrato_strength = strength;
-}
+void set_vibrato_strength(float strength) { vibrato_strength = strength; }
 
-void increase_vibrato_strength(float change) {
-  vibrato_strength *= change;
-}
+void increase_vibrato_strength(float change) { vibrato_strength *= change; }
 
-void decrease_vibrato_strength(float change) {
-  vibrato_strength /= change;
-}
+void decrease_vibrato_strength(float change) { vibrato_strength /= change; }
 
-#endif  /* VIBRATO_STRENGTH_ENABLE */
+#    endif /* VIBRATO_STRENGTH_ENABLE */
 
 #endif /* VIBRATO_ENABLE */
 
 // Polyphony functions
 
-void set_polyphony_rate(float rate) {
-  polyphony_rate = rate;
-}
+void set_polyphony_rate(float rate) { polyphony_rate = rate; }
 
-void enable_polyphony() {
-  polyphony_rate = 5;
-}
+void enable_polyphony() { polyphony_rate = 5; }
 
-void disable_polyphony() {
-  polyphony_rate = 0;
-}
+void disable_polyphony() { polyphony_rate = 0; }
 
-void increase_polyphony_rate(float change) {
-  polyphony_rate *= change;
-}
+void increase_polyphony_rate(float change) { polyphony_rate *= change; }
 
-void decrease_polyphony_rate(float change) {
-  polyphony_rate /= change;
-}
+void decrease_polyphony_rate(float change) { polyphony_rate /= change; }
 
 // Timbre function
 
-void set_timbre(float timbre) {
-  note_timbre = timbre;
-}
+void set_timbre(float timbre) { note_timbre = timbre; }
 
 // Tempo functions
 
-void set_tempo(uint8_t tempo) {
-  note_tempo = tempo;
-}
+void set_tempo(uint8_t tempo) { note_tempo = tempo; }
 
-void decrease_tempo(uint8_t tempo_change) {
-  note_tempo += tempo_change;
-}
+void decrease_tempo(uint8_t tempo_change) { note_tempo += tempo_change; }
 
 void increase_tempo(uint8_t tempo_change) {
-  if (note_tempo - tempo_change < 10) {
-    note_tempo = 10;
-  } else {
-    note_tempo -= tempo_change;
-  }
+    if (note_tempo - tempo_change < 10) {
+        note_tempo = 10;
+    } else {
+        note_tempo -= tempo_change;
+    }
 }
index ed67136099a8889b13bc9e56974842da8bfe552e..545aef6dd7a81ebbd793f8857f3b9cb5e3fd13f7 100644 (file)
@@ -29,7 +29,6 @@
 
 #define CPU_PRESCALER 8
 
-
 // Timer Abstractions
 
 // TIMSK3 - Timer/Counter #3 Interrupt Mask Register
 #define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3A)
 #define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3A)
 
-
 // TCCR3A: Timer/Counter #3 Control Register
 // Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6
 #define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3A1);
 #define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0));
 
-
 #define NOTE_PERIOD ICR3
 #define NOTE_DUTY_CYCLE OCR3A
 
-
 #ifdef PWM_AUDIO
-    #include "wave.h"
-    #define SAMPLE_DIVIDER 39
-    #define SAMPLE_RATE (2000000.0/SAMPLE_DIVIDER/2048)
-    // Resistor value of 1/ (2 * PI * 10nF * (2000000 hertz / SAMPLE_DIVIDER / 10)) for 10nF cap
-
-    float places[8] = {0, 0, 0, 0, 0, 0, 0, 0};
-    uint16_t place_int = 0;
-    bool repeat = true;
+#    include "wave.h"
+#    define SAMPLE_DIVIDER 39
+#    define SAMPLE_RATE (2000000.0 / SAMPLE_DIVIDER / 2048)
+// Resistor value of 1/ (2 * PI * 10nF * (2000000 hertz / SAMPLE_DIVIDER / 10)) for 10nF cap
+
+float    places[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+uint16_t place_int = 0;
+bool     repeat    = true;
 #endif
 
 void delay_us(int count) {
-  while(count--) {
-    _delay_us(1);
-  }
+    while (count--) {
+        _delay_us(1);
+    }
 }
 
-int voices = 0;
-int voice_place = 0;
-float frequency = 0;
-int volume = 0;
-long position = 0;
+int   voices      = 0;
+int   voice_place = 0;
+float frequency   = 0;
+int   volume      = 0;
+long  position    = 0;
 
 float frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0};
-int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
-bool sliding = false;
+int   volumes[8]     = {0, 0, 0, 0, 0, 0, 0, 0};
+bool  sliding        = false;
 
 float place = 0;
 
-uint8_t * sample;
+uint8_t* sample;
 uint16_t sample_length = 0;
 // float freq = 0;
 
-bool     playing_notes = false;
-bool     playing_note = false;
+bool     playing_notes  = false;
+bool     playing_note   = false;
 float    note_frequency = 0;
-float    note_length = 0;
-uint8_t  note_tempo = TEMPO_DEFAULT;
-float    note_timbre = TIMBRE_DEFAULT;
-uint16_t note_position = 0;
-float (* notes_pointer)[][2];
+float    note_length    = 0;
+uint8_t  note_tempo     = TEMPO_DEFAULT;
+float    note_timbre    = TIMBRE_DEFAULT;
+uint16_t note_position  = 0;
+float (*notes_pointer)[][2];
 uint16_t notes_count;
 bool     notes_repeat;
 float    notes_rest;
 bool     note_resting = false;
 
 uint16_t current_note = 0;
-uint8_t rest_counter = 0;
+uint8_t  rest_counter = 0;
 
 #ifdef VIBRATO_ENABLE
-float vibrato_counter = 0;
+float vibrato_counter  = 0;
 float vibrato_strength = .5;
-float vibrato_rate = 0.125;
+float vibrato_rate     = 0.125;
 #endif
 
 float polyphony_rate = 0;
@@ -112,50 +108,49 @@ audio_config_t audio_config;
 uint16_t envelope_index = 0;
 
 void audio_init() {
-
     // Check EEPROM
-    if (!eeconfig_is_enabled())
-    {
+    if (!eeconfig_is_enabled()) {
         eeconfig_init();
     }
     audio_config.raw = eeconfig_read_audio();
 
-    #ifdef PWM_AUDIO
+#ifdef PWM_AUDIO
 
-        PLLFRQ = _BV(PDIV2);
-        PLLCSR = _BV(PLLE);
-        while(!(PLLCSR & _BV(PLOCK)));
-        PLLFRQ |= _BV(PLLTM0); /* PCK 48MHz */
+    PLLFRQ = _BV(PDIV2);
+    PLLCSR = _BV(PLLE);
+    while (!(PLLCSR & _BV(PLOCK)))
+        ;
+    PLLFRQ |= _BV(PLLTM0); /* PCK 48MHz */
 
-        /* Init a fast PWM on Timer4 */
-        TCCR4A = _BV(COM4A0) | _BV(PWM4A); /* Clear OC4A on Compare Match */
-        TCCR4B = _BV(CS40); /* No prescaling => f = PCK/256 = 187500Hz */
-        OCR4A = 0;
+    /* Init a fast PWM on Timer4 */
+    TCCR4A = _BV(COM4A0) | _BV(PWM4A); /* Clear OC4A on Compare Match */
+    TCCR4B = _BV(CS40);                /* No prescaling => f = PCK/256 = 187500Hz */
+    OCR4A  = 0;
 
-        /* Enable the OC4A output */
-        DDRC |= _BV(PORTC6);
+    /* Enable the OC4A output */
+    DDRC |= _BV(PORTC6);
 
-        DISABLE_AUDIO_COUNTER_3_ISR; // Turn off 3A interputs
+    DISABLE_AUDIO_COUNTER_3_ISR;  // Turn off 3A interputs
 
-        TCCR3A = 0x0; // Options not needed
-        TCCR3B = _BV(CS31) | _BV(CS30) | _BV(WGM32); // 64th prescaling and CTC
-        OCR3A = SAMPLE_DIVIDER - 1; // Correct count/compare, related to sample playback
+    TCCR3A = 0x0;                                 // Options not needed
+    TCCR3B = _BV(CS31) | _BV(CS30) | _BV(WGM32);  // 64th prescaling and CTC
+    OCR3A  = SAMPLE_DIVIDER - 1;                  // Correct count/compare, related to sample playback
 
-    #else
+#else
 
-       // Set port PC6 (OC3A and /OC4A) as output
-        DDRC |= _BV(PORTC6);
+    // Set port PC6 (OC3A and /OC4A) as output
+    DDRC |= _BV(PORTC6);
 
-        DISABLE_AUDIO_COUNTER_3_ISR;
+    DISABLE_AUDIO_COUNTER_3_ISR;
 
-               // TCCR3A / TCCR3B: Timer/Counter #3 Control Registers
-               // Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6
-               // Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14 (Period = ICR3, Duty Cycle = OCR3A)
-               // Clock Select (CS3n) = 0b010 = Clock / 8
-        TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
-        TCCR3B = (1 << WGM33)  | (1 << WGM32)  | (0 << CS32)  | (1 << CS31) | (0 << CS30);
+    // TCCR3A / TCCR3B: Timer/Counter #3 Control Registers
+    // Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6
+    // Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14 (Period = ICR3, Duty Cycle = OCR3A)
+    // Clock Select (CS3n) = 0b010 = Clock / 8
+    TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
+    TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30);
 
-    #endif
+#endif
 
     audio_initialized = true;
 }
@@ -165,62 +160,59 @@ void stop_all_notes() {
         audio_init();
     }
     voices = 0;
-    #ifdef PWM_AUDIO
-           DISABLE_AUDIO_COUNTER_3_ISR;
-    #else
-        DISABLE_AUDIO_COUNTER_3_ISR;
-        DISABLE_AUDIO_COUNTER_3_OUTPUT;
-    #endif
+#ifdef PWM_AUDIO
+    DISABLE_AUDIO_COUNTER_3_ISR;
+#else
+    DISABLE_AUDIO_COUNTER_3_ISR;
+    DISABLE_AUDIO_COUNTER_3_OUTPUT;
+#endif
 
     playing_notes = false;
-    playing_note = false;
-    frequency = 0;
-    volume = 0;
+    playing_note  = false;
+    frequency     = 0;
+    volume        = 0;
 
-    for (uint8_t i = 0; i < 8; i++)
-    {
+    for (uint8_t i = 0; i < 8; i++) {
         frequencies[i] = 0;
-        volumes[i] = 0;
+        volumes[i]     = 0;
     }
 }
 
-void stop_note(float freq)
-{
+void stop_note(float freq) {
     if (playing_note) {
         if (!audio_initialized) {
             audio_init();
         }
-        #ifdef PWM_AUDIO
-            freq = freq / SAMPLE_RATE;
-        #endif
+#ifdef PWM_AUDIO
+        freq = freq / SAMPLE_RATE;
+#endif
         for (int i = 7; i >= 0; i--) {
             if (frequencies[i] == freq) {
                 frequencies[i] = 0;
-                volumes[i] = 0;
+                volumes[i]     = 0;
                 for (int j = i; (j < 7); j++) {
-                    frequencies[j] = frequencies[j+1];
-                    frequencies[j+1] = 0;
-                    volumes[j] = volumes[j+1];
-                    volumes[j+1] = 0;
+                    frequencies[j]     = frequencies[j + 1];
+                    frequencies[j + 1] = 0;
+                    volumes[j]         = volumes[j + 1];
+                    volumes[j + 1]     = 0;
                 }
                 break;
             }
         }
         voices--;
-        if (voices < 0)
-            voices = 0;
+        if (voices < 0) voices = 0;
         if (voice_place >= voices) {
             voice_place = 0;
         }
         if (voices == 0) {
-            #ifdef PWM_AUDIO
-                DISABLE_AUDIO_COUNTER_3_ISR;
-            #else
-                DISABLE_AUDIO_COUNTER_3_ISR;
-                DISABLE_AUDIO_COUNTER_3_OUTPUT;
-            #endif
-            frequency = 0;
-            volume = 0;
+#ifdef PWM_AUDIO
+            DISABLE_AUDIO_COUNTER_3_ISR;
+#else
+            DISABLE_AUDIO_COUNTER_3_ISR;
+            DISABLE_AUDIO_COUNTER_3_OUTPUT;
+#endif
+            frequency    = 0;
+            volume       = 0;
             playing_note = false;
         }
     }
@@ -228,126 +220,120 @@ void stop_note(float freq)
 
 #ifdef VIBRATO_ENABLE
 
-float mod(float a, int b)
-{
+float mod(float a, int b) {
     float r = fmod(a, b);
     return r < 0 ? r + b : r;
 }
 
 float vibrato(float average_freq) {
-    #ifdef VIBRATO_STRENGTH_ENABLE
-        float vibrated_freq = average_freq * pow(vibrato_lut[(int)vibrato_counter], vibrato_strength);
-    #else
-        float vibrated_freq = average_freq * vibrato_lut[(int)vibrato_counter];
-    #endif
-    vibrato_counter = mod((vibrato_counter + vibrato_rate * (1.0 + 440.0/average_freq)), VIBRATO_LUT_LENGTH);
+#    ifdef VIBRATO_STRENGTH_ENABLE
+    float vibrated_freq = average_freq * pow(vibrato_lut[(int)vibrato_counter], vibrato_strength);
+#    else
+    float vibrated_freq = average_freq * vibrato_lut[(int)vibrato_counter];
+#    endif
+    vibrato_counter = mod((vibrato_counter + vibrato_rate * (1.0 + 440.0 / average_freq)), VIBRATO_LUT_LENGTH);
     return vibrated_freq;
 }
 
 #endif
 
-ISR(TIMER3_COMPA_vect)
-{
+ISR(TIMER3_COMPA_vect) {
     if (playing_note) {
-        #ifdef PWM_AUDIO
-            if (voices == 1) {
+#ifdef PWM_AUDIO
+        if (voices == 1) {
+            // SINE
+            OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 2;
+
+            // SQUARE
+            // if (((int)place) >= 1024){
+            //     OCR4A = 0xFF >> 2;
+            // } else {
+            //     OCR4A = 0x00;
+            // }
+
+            // SAWTOOTH
+            // OCR4A = (int)place / 4;
+
+            // TRIANGLE
+            // if (((int)place) >= 1024) {
+            //     OCR4A = (int)place / 2;
+            // } else {
+            //     OCR4A = 2048 - (int)place / 2;
+            // }
+
+            place += frequency;
+
+            if (place >= SINE_LENGTH) place -= SINE_LENGTH;
+
+        } else {
+            int sum = 0;
+            for (int i = 0; i < voices; i++) {
                 // SINE
-                OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 2;
+                sum += pgm_read_byte(&sinewave[(uint16_t)places[i]]) >> 2;
 
                 // SQUARE
-                // if (((int)place) >= 1024){
-                //     OCR4A = 0xFF >> 2;
+                // if (((int)places[i]) >= 1024){
+                //     sum += 0xFF >> 2;
                 // } else {
-                //     OCR4A = 0x00;
+                //     sum += 0x00;
                 // }
 
-                // SAWTOOTH
-                // OCR4A = (int)place / 4;
-
-                // TRIANGLE
-                // if (((int)place) >= 1024) {
-                //     OCR4A = (int)place / 2;
-                // } else {
-                //     OCR4A = 2048 - (int)place / 2;
-                // }
+                places[i] += frequencies[i];
 
-                place += frequency;
-
-                if (place >= SINE_LENGTH)
-                    place -= SINE_LENGTH;
-
-            } else {
-                int sum = 0;
-                for (int i = 0; i < voices; i++) {
-                    // SINE
-                    sum += pgm_read_byte(&sinewave[(uint16_t)places[i]]) >> 2;
-
-                    // SQUARE
-                    // if (((int)places[i]) >= 1024){
-                    //     sum += 0xFF >> 2;
-                    // } else {
-                    //     sum += 0x00;
-                    // }
-
-                    places[i] += frequencies[i];
-
-                    if (places[i] >= SINE_LENGTH)
-                        places[i] -= SINE_LENGTH;
-                }
-                OCR4A = sum;
+                if (places[i] >= SINE_LENGTH) places[i] -= SINE_LENGTH;
             }
-        #else
-            if (voices > 0) {
-                float freq;
-                if (polyphony_rate > 0) {
-                    if (voices > 1) {
-                        voice_place %= voices;
-                        if (place++ > (frequencies[voice_place] / polyphony_rate / CPU_PRESCALER)) {
-                            voice_place = (voice_place + 1) % voices;
-                            place = 0.0;
-                        }
-                    }
-                    #ifdef VIBRATO_ENABLE
-                    if (vibrato_strength > 0) {
-                        freq = vibrato(frequencies[voice_place]);
-                    } else {
-                    #else
-                    {
-                    #endif
-                        freq = frequencies[voice_place];
+            OCR4A = sum;
+        }
+#else
+        if (voices > 0) {
+            float freq;
+            if (polyphony_rate > 0) {
+                if (voices > 1) {
+                    voice_place %= voices;
+                    if (place++ > (frequencies[voice_place] / polyphony_rate / CPU_PRESCALER)) {
+                        voice_place = (voice_place + 1) % voices;
+                        place       = 0.0;
                     }
+                }
+#    ifdef VIBRATO_ENABLE
+                if (vibrato_strength > 0) {
+                    freq = vibrato(frequencies[voice_place]);
                 } else {
-                    if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
-                        frequency = frequency * pow(2, 440/frequency/12/2);
-                    } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
-                        frequency = frequency * pow(2, -440/frequency/12/2);
-                    } else {
-                        frequency = frequencies[voices - 1];
-                    }
-
-
-                    #ifdef VIBRATO_ENABLE
-                    if (vibrato_strength > 0) {
-                        freq = vibrato(frequency);
-                    } else {
-                    #else
-                    {
-                    #endif
-                        freq = frequency;
-                    }
+#    else
+                {
+#    endif
+                    freq = frequencies[voice_place];
+                }
+            } else {
+                if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440 / frequencies[voices - 1] / 12 / 2)) {
+                    frequency = frequency * pow(2, 440 / frequency / 12 / 2);
+                } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440 / frequencies[voices - 1] / 12 / 2)) {
+                    frequency = frequency * pow(2, -440 / frequency / 12 / 2);
+                } else {
+                    frequency = frequencies[voices - 1];
                 }
 
-                if (envelope_index < 65535) {
-                    envelope_index++;
+#    ifdef VIBRATO_ENABLE
+                if (vibrato_strength > 0) {
+                    freq = vibrato(frequency);
+                } else {
+#    else
+                {
+#    endif
+                    freq = frequency;
                 }
-                freq = voice_envelope(freq);
+            }
 
-                if (freq < 30.517578125)
-                    freq = 30.52;
-                NOTE_PERIOD = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
-                NOTE_DUTY_CYCLE = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
+            if (envelope_index < 65535) {
+                envelope_index++;
             }
-        #endif
+            freq = voice_envelope(freq);
+
+            if (freq < 30.517578125) freq = 30.52;
+            NOTE_PERIOD     = (int)(((double)F_CPU) / (freq * CPU_PRESCALER));                  // Set max to the period
+            NOTE_DUTY_CYCLE = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);  // Set compare to half the period
+        }
+#endif
     }
 
     // SAMPLE
@@ -361,41 +347,38 @@ ISR(TIMER3_COMPA_vect)
     //     else
     //         DISABLE_AUDIO_COUNTER_3_ISR;
 
-
     if (playing_notes) {
-        #ifdef PWM_AUDIO
-            OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 0;
-
-            place += note_frequency;
-            if (place >= SINE_LENGTH)
-                place -= SINE_LENGTH;
-        #else
-            if (note_frequency > 0) {
-                float freq;
-
-                #ifdef VIBRATO_ENABLE
-                if (vibrato_strength > 0) {
-                    freq = vibrato(note_frequency);
-                } else {
-                #else
-                {
-                #endif
-                    freq = note_frequency;
-                }
+#ifdef PWM_AUDIO
+        OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 0;
 
-                if (envelope_index < 65535) {
-                    envelope_index++;
-                }
-                freq = voice_envelope(freq);
+        place += note_frequency;
+        if (place >= SINE_LENGTH) place -= SINE_LENGTH;
+#else
+        if (note_frequency > 0) {
+            float freq;
 
-                NOTE_PERIOD = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
-                NOTE_DUTY_CYCLE = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
+#    ifdef VIBRATO_ENABLE
+            if (vibrato_strength > 0) {
+                freq = vibrato(note_frequency);
             } else {
-                NOTE_PERIOD = 0;
-                NOTE_DUTY_CYCLE = 0;
+#    else
+            {
+#    endif
+                freq = note_frequency;
             }
-        #endif
 
+            if (envelope_index < 65535) {
+                envelope_index++;
+            }
+            freq = voice_envelope(freq);
+
+            NOTE_PERIOD     = (int)(((double)F_CPU) / (freq * CPU_PRESCALER));                  // Set max to the period
+            NOTE_DUTY_CYCLE = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);  // Set compare to half the period
+        } else {
+            NOTE_PERIOD     = 0;
+            NOTE_DUTY_CYCLE = 0;
+        }
+#endif
 
         note_position++;
         bool end_of_note = false;
@@ -409,126 +392,116 @@ ISR(TIMER3_COMPA_vect)
                 if (notes_repeat) {
                     current_note = 0;
                 } else {
-                    #ifdef PWM_AUDIO
-                        DISABLE_AUDIO_COUNTER_3_ISR;
-                    #else
-                        DISABLE_AUDIO_COUNTER_3_ISR;
-                        DISABLE_AUDIO_COUNTER_3_OUTPUT;
-                    #endif
+#ifdef PWM_AUDIO
+                    DISABLE_AUDIO_COUNTER_3_ISR;
+#else
+                    DISABLE_AUDIO_COUNTER_3_ISR;
+                    DISABLE_AUDIO_COUNTER_3_OUTPUT;
+#endif
                     playing_notes = false;
                     return;
                 }
             }
             if (!note_resting && (notes_rest > 0)) {
-                note_resting = true;
+                note_resting   = true;
                 note_frequency = 0;
-                note_length = notes_rest;
+                note_length    = notes_rest;
                 current_note--;
             } else {
                 note_resting = false;
-                #ifdef PWM_AUDIO
-                    note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
-                    note_length = (*notes_pointer)[current_note][1] * (((float)note_tempo) / 100);
-                #else
-                    envelope_index = 0;
-                    note_frequency = (*notes_pointer)[current_note][0];
-                    note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
-                #endif
+#ifdef PWM_AUDIO
+                note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
+                note_length    = (*notes_pointer)[current_note][1] * (((float)note_tempo) / 100);
+#else
+                envelope_index = 0;
+                note_frequency = (*notes_pointer)[current_note][0];
+                note_length    = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+#endif
             }
             note_position = 0;
         }
-
     }
 
     if (!audio_config.enable) {
         playing_notes = false;
-        playing_note = false;
+        playing_note  = false;
     }
 }
 
 void play_note(float freq, int vol) {
-
     if (!audio_initialized) {
         audio_init();
     }
 
-       if (audio_config.enable && voices < 8) {
-           DISABLE_AUDIO_COUNTER_3_ISR;
-
-           // Cancel notes if notes are playing
-           if (playing_notes)
-               stop_all_notes();
+    if (audio_config.enable && voices < 8) {
+        DISABLE_AUDIO_COUNTER_3_ISR;
 
-           playing_note = true;
+        // Cancel notes if notes are playing
+        if (playing_notes) stop_all_notes();
 
-           envelope_index = 0;
+        playing_note = true;
 
-           #ifdef PWM_AUDIO
-               freq = freq / SAMPLE_RATE;
-           #endif
-           if (freq > 0) {
-               frequencies[voices] = freq;
-               volumes[voices] = vol;
-               voices++;
-           }
+        envelope_index = 0;
 
-           #ifdef PWM_AUDIO
-               ENABLE_AUDIO_COUNTER_3_ISR;
-           #else
-               ENABLE_AUDIO_COUNTER_3_ISR;
-               ENABLE_AUDIO_COUNTER_3_OUTPUT;
-           #endif
-       }
+#ifdef PWM_AUDIO
+        freq = freq / SAMPLE_RATE;
+#endif
+        if (freq > 0) {
+            frequencies[voices] = freq;
+            volumes[voices]     = vol;
+            voices++;
+        }
 
+#ifdef PWM_AUDIO
+        ENABLE_AUDIO_COUNTER_3_ISR;
+#else
+        ENABLE_AUDIO_COUNTER_3_ISR;
+        ENABLE_AUDIO_COUNTER_3_OUTPUT;
+#endif
+    }
 }
 
-void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
-{
-
+void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest) {
     if (!audio_initialized) {
         audio_init();
     }
 
-       if (audio_config.enable) {
-
-           DISABLE_AUDIO_COUNTER_3_ISR;
-
-               // Cancel note if a note is playing
-           if (playing_note)
-               stop_all_notes();
-
-           playing_notes = true;
+    if (audio_config.enable) {
+        DISABLE_AUDIO_COUNTER_3_ISR;
 
-           notes_pointer = np;
-           notes_count = n_count;
-           notes_repeat = n_repeat;
-           notes_rest = n_rest;
+        // Cancel note if a note is playing
+        if (playing_note) stop_all_notes();
 
-           place = 0;
-           current_note = 0;
+        playing_notes = true;
 
-           #ifdef PWM_AUDIO
-               note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
-               note_length = (*notes_pointer)[current_note][1] * (((float)note_tempo) / 100);
-           #else
-               note_frequency = (*notes_pointer)[current_note][0];
-               note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
-           #endif
-           note_position = 0;
+        notes_pointer = np;
+        notes_count   = n_count;
+        notes_repeat  = n_repeat;
+        notes_rest    = n_rest;
 
+        place        = 0;
+        current_note = 0;
 
-           #ifdef PWM_AUDIO
-               ENABLE_AUDIO_COUNTER_3_ISR;
-           #else
-               ENABLE_AUDIO_COUNTER_3_ISR;
-               ENABLE_AUDIO_COUNTER_3_OUTPUT;
-           #endif
-       }
+#ifdef PWM_AUDIO
+        note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
+        note_length    = (*notes_pointer)[current_note][1] * (((float)note_tempo) / 100);
+#else
+        note_frequency = (*notes_pointer)[current_note][0];
+        note_length    = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+#endif
+        note_position = 0;
 
+#ifdef PWM_AUDIO
+        ENABLE_AUDIO_COUNTER_3_ISR;
+#else
+        ENABLE_AUDIO_COUNTER_3_ISR;
+        ENABLE_AUDIO_COUNTER_3_OUTPUT;
+#endif
+    }
 }
 
 #ifdef PWM_AUDIO
-void play_sample(uint8_t * s, uint16_t l, bool r) {
+void play_sample(uint8_t* s, uint16_t l, bool r) {
     if (!audio_initialized) {
         audio_init();
     }
@@ -536,17 +509,16 @@ void play_sample(uint8_t * s, uint16_t l, bool r) {
     if (audio_config.enable) {
         DISABLE_AUDIO_COUNTER_3_ISR;
         stop_all_notes();
-        place_int = 0;
-        sample = s;
+        place_int     = 0;
+        sample        = s;
         sample_length = l;
-        repeat = r;
+        repeat        = r;
 
         ENABLE_AUDIO_COUNTER_3_ISR;
     }
 }
 #endif
 
-
 void audio_toggle(void) {
     audio_config.enable ^= 1;
     eeconfig_update_audio(audio_config.raw);
@@ -566,73 +538,45 @@ void audio_off(void) {
 
 // Vibrato rate functions
 
-void set_vibrato_rate(float rate) {
-    vibrato_rate = rate;
-}
+void set_vibrato_rate(float rate) { vibrato_rate = rate; }
 
-void increase_vibrato_rate(float change) {
-    vibrato_rate *= change;
-}
+void increase_vibrato_rate(float change) { vibrato_rate *= change; }
 
-void decrease_vibrato_rate(float change) {
-    vibrato_rate /= change;
-}
+void decrease_vibrato_rate(float change) { vibrato_rate /= change; }
 
-#ifdef VIBRATO_STRENGTH_ENABLE
+#    ifdef VIBRATO_STRENGTH_ENABLE
 
-void set_vibrato_strength(float strength) {
-    vibrato_strength = strength;
-}
+void set_vibrato_strength(float strength) { vibrato_strength = strength; }
 
-void increase_vibrato_strength(float change) {
-    vibrato_strength *= change;
-}
+void increase_vibrato_strength(float change) { vibrato_strength *= change; }
 
-void decrease_vibrato_strength(float change) {
-    vibrato_strength /= change;
-}
+void decrease_vibrato_strength(float change) { vibrato_strength /= change; }
 
-#endif  /* VIBRATO_STRENGTH_ENABLE */
+#    endif /* VIBRATO_STRENGTH_ENABLE */
 
 #endif /* VIBRATO_ENABLE */
 
 // Polyphony functions
 
-void set_polyphony_rate(float rate) {
-    polyphony_rate = rate;
-}
+void set_polyphony_rate(float rate) { polyphony_rate = rate; }
 
-void enable_polyphony() {
-    polyphony_rate = 5;
-}
+void enable_polyphony() { polyphony_rate = 5; }
 
-void disable_polyphony() {
-    polyphony_rate = 0;
-}
+void disable_polyphony() { polyphony_rate = 0; }
 
-void increase_polyphony_rate(float change) {
-    polyphony_rate *= change;
-}
+void increase_polyphony_rate(float change) { polyphony_rate *= change; }
 
-void decrease_polyphony_rate(float change) {
-    polyphony_rate /= change;
-}
+void decrease_polyphony_rate(float change) { polyphony_rate /= change; }
 
 // Timbre function
 
-void set_timbre(float timbre) {
-    note_timbre = timbre;
-}
+void set_timbre(float timbre) { note_timbre = timbre; }
 
 // Tempo functions
 
-void set_tempo(uint8_t tempo) {
-    note_tempo = tempo;
-}
+void set_tempo(uint8_t tempo) { note_tempo = tempo; }
 
-void decrease_tempo(uint8_t tempo_change) {
-    note_tempo += tempo_change;
-}
+void decrease_tempo(uint8_t tempo_change) { note_tempo += tempo_change; }
 
 void increase_tempo(uint8_t tempo_change) {
     if (note_tempo - tempo_change < 10) {
@@ -642,17 +586,10 @@ void increase_tempo(uint8_t tempo_change) {
     }
 }
 
-
 //------------------------------------------------------------------------------
 // Override these functions in your keymap file to play different tunes on
 // startup and bootloader jump
-__attribute__ ((weak))
-void play_startup_tone()
-{
-}
+__attribute__((weak)) void play_startup_tone() {}
 
-__attribute__ ((weak))
-void play_goodbye_tone()
-{
-}
+__attribute__((weak)) void play_goodbye_tone() {}
 //------------------------------------------------------------------------------
index 4404aff4340948321166a60d1e66704f07e063a7..e8f77a0f331ed85c7a8b8d4aeced90388f8cf004 100644 (file)
 
 #include "luts.h"
 
-const float vibrato_lut[VIBRATO_LUT_LENGTH] =
-{
-       1.0022336811487,
-       1.0042529943610,
-       1.0058584256028,
-       1.0068905285205,
-       1.0072464122237,
-       1.0068905285205,
-       1.0058584256028,
-       1.0042529943610,
-       1.0022336811487,
-       1.0000000000000,
-       0.9977712970630,
-       0.9957650169978,
-       0.9941756956510,
-       0.9931566259436,
-       0.9928057204913,
-       0.9931566259436,
-       0.9941756956510,
-       0.9957650169978,
-       0.9977712970630,
-       1.0000000000000,
+const float vibrato_lut[VIBRATO_LUT_LENGTH] = {
+    1.0022336811487, 1.0042529943610, 1.0058584256028, 1.0068905285205, 1.0072464122237, 1.0068905285205, 1.0058584256028, 1.0042529943610, 1.0022336811487, 1.0000000000000, 0.9977712970630, 0.9957650169978, 0.9941756956510, 0.9931566259436, 0.9928057204913, 0.9931566259436, 0.9941756956510, 0.9957650169978, 0.9977712970630, 1.0000000000000,
 };
 
-const uint16_t frequency_lut[FREQUENCY_LUT_LENGTH] =
-{
-       0x8E0B,
-       0x8C02,
-       0x8A00,
-       0x8805,
-       0x8612,
-       0x8426,
-       0x8241,
-       0x8063,
-       0x7E8C,
-       0x7CBB,
-       0x7AF2,
-       0x792E,
-       0x7772,
-       0x75BB,
-       0x740B,
-       0x7261,
-       0x70BD,
-       0x6F20,
-       0x6D88,
-       0x6BF6,
-       0x6A69,
-       0x68E3,
-       0x6762,
-       0x65E6,
-       0x6470,
-       0x6300,
-       0x6194,
-       0x602E,
-       0x5ECD,
-       0x5D71,
-       0x5C1A,
-       0x5AC8,
-       0x597B,
-       0x5833,
-       0x56EF,
-       0x55B0,
-       0x5475,
-       0x533F,
-       0x520E,
-       0x50E1,
-       0x4FB8,
-       0x4E93,
-       0x4D73,
-       0x4C57,
-       0x4B3E,
-       0x4A2A,
-       0x491A,
-       0x480E,
-       0x4705,
-       0x4601,
-       0x4500,
-       0x4402,
-       0x4309,
-       0x4213,
-       0x4120,
-       0x4031,
-       0x3F46,
-       0x3E5D,
-       0x3D79,
-       0x3C97,
-       0x3BB9,
-       0x3ADD,
-       0x3A05,
-       0x3930,
-       0x385E,
-       0x3790,
-       0x36C4,
-       0x35FB,
-       0x3534,
-       0x3471,
-       0x33B1,
-       0x32F3,
-       0x3238,
-       0x3180,
-       0x30CA,
-       0x3017,
-       0x2F66,
-       0x2EB8,
-       0x2E0D,
-       0x2D64,
-       0x2CBD,
-       0x2C19,
-       0x2B77,
-       0x2AD8,
-       0x2A3A,
-       0x299F,
-       0x2907,
-       0x2870,
-       0x27DC,
-       0x2749,
-       0x26B9,
-       0x262B,
-       0x259F,
-       0x2515,
-       0x248D,
-       0x2407,
-       0x2382,
-       0x2300,
-       0x2280,
-       0x2201,
-       0x2184,
-       0x2109,
-       0x2090,
-       0x2018,
-       0x1FA3,
-       0x1F2E,
-       0x1EBC,
-       0x1E4B,
-       0x1DDC,
-       0x1D6E,
-       0x1D02,
-       0x1C98,
-       0x1C2F,
-       0x1BC8,
-       0x1B62,
-       0x1AFD,
-       0x1A9A,
-       0x1A38,
-       0x19D8,
-       0x1979,
-       0x191C,
-       0x18C0,
-       0x1865,
-       0x180B,
-       0x17B3,
-       0x175C,
-       0x1706,
-       0x16B2,
-       0x165E,
-       0x160C,
-       0x15BB,
-       0x156C,
-       0x151D,
-       0x14CF,
-       0x1483,
-       0x1438,
-       0x13EE,
-       0x13A4,
-       0x135C,
-       0x1315,
-       0x12CF,
-       0x128A,
-       0x1246,
-       0x1203,
-       0x11C1,
-       0x1180,
-       0x1140,
-       0x1100,
-       0x10C2,
-       0x1084,
-       0x1048,
-       0x100C,
-       0xFD1,
-       0xF97,
-       0xF5E,
-       0xF25,
-       0xEEE,
-       0xEB7,
-       0xE81,
-       0xE4C,
-       0xE17,
-       0xDE4,
-       0xDB1,
-       0xD7E,
-       0xD4D,
-       0xD1C,
-       0xCEC,
-       0xCBC,
-       0xC8E,
-       0xC60,
-       0xC32,
-       0xC05,
-       0xBD9,
-       0xBAE,
-       0xB83,
-       0xB59,
-       0xB2F,
-       0xB06,
-       0xADD,
-       0xAB6,
-       0xA8E,
-       0xA67,
-       0xA41,
-       0xA1C,
-       0x9F7,
-       0x9D2,
-       0x9AE,
-       0x98A,
-       0x967,
-       0x945,
-       0x923,
-       0x901,
-       0x8E0,
-       0x8C0,
-       0x8A0,
-       0x880,
-       0x861,
-       0x842,
-       0x824,
-       0x806,
-       0x7E8,
-       0x7CB,
-       0x7AF,
-       0x792,
-       0x777,
-       0x75B,
-       0x740,
-       0x726,
-       0x70B,
-       0x6F2,
-       0x6D8,
-       0x6BF,
-       0x6A6,
-       0x68E,
-       0x676,
-       0x65E,
-       0x647,
-       0x630,
-       0x619,
-       0x602,
-       0x5EC,
-       0x5D7,
-       0x5C1,
-       0x5AC,
-       0x597,
-       0x583,
-       0x56E,
-       0x55B,
-       0x547,
-       0x533,
-       0x520,
-       0x50E,
-       0x4FB,
-       0x4E9,
-       0x4D7,
-       0x4C5,
-       0x4B3,
-       0x4A2,
-       0x491,
-       0x480,
-       0x470,
-       0x460,
-       0x450,
-       0x440,
-       0x430,
-       0x421,
-       0x412,
-       0x403,
-       0x3F4,
-       0x3E5,
-       0x3D7,
-       0x3C9,
-       0x3BB,
-       0x3AD,
-       0x3A0,
-       0x393,
-       0x385,
-       0x379,
-       0x36C,
-       0x35F,
-       0x353,
-       0x347,
-       0x33B,
-       0x32F,
-       0x323,
-       0x318,
-       0x30C,
-       0x301,
-       0x2F6,
-       0x2EB,
-       0x2E0,
-       0x2D6,
-       0x2CB,
-       0x2C1,
-       0x2B7,
-       0x2AD,
-       0x2A3,
-       0x299,
-       0x290,
-       0x287,
-       0x27D,
-       0x274,
-       0x26B,
-       0x262,
-       0x259,
-       0x251,
-       0x248,
-       0x240,
-       0x238,
-       0x230,
-       0x228,
-       0x220,
-       0x218,
-       0x210,
-       0x209,
-       0x201,
-       0x1FA,
-       0x1F2,
-       0x1EB,
-       0x1E4,
-       0x1DD,
-       0x1D6,
-       0x1D0,
-       0x1C9,
-       0x1C2,
-       0x1BC,
-       0x1B6,
-       0x1AF,
-       0x1A9,
-       0x1A3,
-       0x19D,
-       0x197,
-       0x191,
-       0x18C,
-       0x186,
-       0x180,
-       0x17B,
-       0x175,
-       0x170,
-       0x16B,
-       0x165,
-       0x160,
-       0x15B,
-       0x156,
-       0x151,
-       0x14C,
-       0x148,
-       0x143,
-       0x13E,
-       0x13A,
-       0x135,
-       0x131,
-       0x12C,
-       0x128,
-       0x124,
-       0x120,
-       0x11C,
-       0x118,
-       0x114,
-       0x110,
-       0x10C,
-       0x108,
-       0x104,
-       0x100,
-       0xFD,
-       0xF9,
-       0xF5,
-       0xF2,
-       0xEE,
+const uint16_t frequency_lut[FREQUENCY_LUT_LENGTH] = {
+    0x8E0B, 0x8C02, 0x8A00, 0x8805, 0x8612, 0x8426, 0x8241, 0x8063, 0x7E8C, 0x7CBB, 0x7AF2, 0x792E, 0x7772, 0x75BB, 0x740B, 0x7261, 0x70BD, 0x6F20, 0x6D88, 0x6BF6, 0x6A69, 0x68E3, 0x6762, 0x65E6, 0x6470, 0x6300, 0x6194, 0x602E, 0x5ECD, 0x5D71, 0x5C1A, 0x5AC8, 0x597B, 0x5833, 0x56EF, 0x55B0, 0x5475, 0x533F, 0x520E, 0x50E1, 0x4FB8, 0x4E93, 0x4D73, 0x4C57, 0x4B3E, 0x4A2A, 0x491A, 0x480E, 0x4705, 0x4601, 0x4500, 0x4402, 0x4309, 0x4213, 0x4120, 0x4031, 0x3F46, 0x3E5D, 0x3D79, 0x3C97, 0x3BB9, 0x3ADD, 0x3A05, 0x3930, 0x385E, 0x3790, 0x36C4, 0x35FB, 0x3534, 0x3471, 0x33B1, 0x32F3, 0x3238, 0x3180, 0x30CA, 0x3017, 0x2F66, 0x2EB8, 0x2E0D, 0x2D64, 0x2CBD, 0x2C19, 0x2B77, 0x2AD8, 0x2A3A, 0x299F, 0x2907, 0x2870, 0x27DC, 0x2749, 0x26B9, 0x262B, 0x259F, 0x2515, 0x248D, 0x2407, 0x2382, 0x2300, 0x2280, 0x2201, 0x2184, 0x2109, 0x2090, 0x2018, 0x1FA3, 0x1F2E, 0x1EBC, 0x1E4B, 0x1DDC, 0x1D6E, 0x1D02, 0x1C98, 0x1C2F, 0x1BC8, 0x1B62, 0x1AFD, 0x1A9A,
+    0x1A38, 0x19D8, 0x1979, 0x191C, 0x18C0, 0x1865, 0x180B, 0x17B3, 0x175C, 0x1706, 0x16B2, 0x165E, 0x160C, 0x15BB, 0x156C, 0x151D, 0x14CF, 0x1483, 0x1438, 0x13EE, 0x13A4, 0x135C, 0x1315, 0x12CF, 0x128A, 0x1246, 0x1203, 0x11C1, 0x1180, 0x1140, 0x1100, 0x10C2, 0x1084, 0x1048, 0x100C, 0xFD1,  0xF97,  0xF5E,  0xF25,  0xEEE,  0xEB7,  0xE81,  0xE4C,  0xE17,  0xDE4,  0xDB1,  0xD7E,  0xD4D,  0xD1C,  0xCEC,  0xCBC,  0xC8E,  0xC60,  0xC32,  0xC05,  0xBD9,  0xBAE,  0xB83,  0xB59,  0xB2F,  0xB06,  0xADD,  0xAB6,  0xA8E,  0xA67,  0xA41,  0xA1C,  0x9F7,  0x9D2,  0x9AE,  0x98A,  0x967,  0x945,  0x923,  0x901,  0x8E0,  0x8C0,  0x8A0,  0x880,  0x861,  0x842,  0x824,  0x806,  0x7E8,  0x7CB,  0x7AF,  0x792,  0x777,  0x75B,  0x740,  0x726,  0x70B,  0x6F2,  0x6D8,  0x6BF,  0x6A6,  0x68E,  0x676,  0x65E,  0x647,  0x630,  0x619,  0x602,  0x5EC,  0x5D7,  0x5C1,  0x5AC,  0x597,  0x583,  0x56E,  0x55B,  0x547,  0x533,  0x520,  0x50E,  0x4FB,  0x4E9,
+    0x4D7,  0x4C5,  0x4B3,  0x4A2,  0x491,  0x480,  0x470,  0x460,  0x450,  0x440,  0x430,  0x421,  0x412,  0x403,  0x3F4,  0x3E5,  0x3D7,  0x3C9,  0x3BB,  0x3AD,  0x3A0,  0x393,  0x385,  0x379,  0x36C,  0x35F,  0x353,  0x347,  0x33B,  0x32F,  0x323,  0x318,  0x30C,  0x301,  0x2F6,  0x2EB,  0x2E0,  0x2D6,  0x2CB,  0x2C1,  0x2B7,  0x2AD,  0x2A3,  0x299,  0x290,  0x287,  0x27D,  0x274,  0x26B,  0x262,  0x259,  0x251,  0x248,  0x240,  0x238,  0x230,  0x228,  0x220,  0x218,  0x210,  0x209,  0x201,  0x1FA,  0x1F2,  0x1EB,  0x1E4,  0x1DD,  0x1D6,  0x1D0,  0x1C9,  0x1C2,  0x1BC,  0x1B6,  0x1AF,  0x1A9,  0x1A3,  0x19D,  0x197,  0x191,  0x18C,  0x186,  0x180,  0x17B,  0x175,  0x170,  0x16B,  0x165,  0x160,  0x15B,  0x156,  0x151,  0x14C,  0x148,  0x143,  0x13E,  0x13A,  0x135,  0x131,  0x12C,  0x128,  0x124,  0x120,  0x11C,  0x118,  0x114,  0x110,  0x10C,  0x108,  0x104,  0x100,  0xFD,   0xF9,   0xF5,   0xF2,   0xEE,
 };
-
index a377a6c8709db5284424c88f6d18c8882ca73393..117d74cd00f6bc3cbf480fc7e5d3c27d2cfbe33a 100644 (file)
  */
 
 #if defined(__AVR__)
-    #include <avr/io.h>
-    #include <avr/interrupt.h>
-    #include <avr/pgmspace.h>
+#    include <avr/io.h>
+#    include <avr/interrupt.h>
+#    include <avr/pgmspace.h>
 #else
-    #include "ch.h"
-    #include "hal.h"
+#    include "ch.h"
+#    include "hal.h"
 #endif
 
 #ifndef LUTS_H
-#define LUTS_H
+#    define LUTS_H
 
-#define VIBRATO_LUT_LENGTH 20
+#    define VIBRATO_LUT_LENGTH 20
 
-#define FREQUENCY_LUT_LENGTH 349
+#    define FREQUENCY_LUT_LENGTH 349
 
-extern const float vibrato_lut[VIBRATO_LUT_LENGTH];
+extern const float    vibrato_lut[VIBRATO_LUT_LENGTH];
 extern const uint16_t frequency_lut[FREQUENCY_LUT_LENGTH];
 
 #endif /* LUTS_H */
index f3cb592d81e4f30fe192f19943af994f5bfeaf4f..01b95671fdcac1bba4593ae7bf4acd1b863c18d4 100644 (file)
 #include "muse.h"
 
-enum {
-  MUSE_OFF,
-  MUSE_ON,
-  MUSE_C_1_2,
-  MUSE_C1,
-  MUSE_C2,
-  MUSE_C4,
-  MUSE_C8,
-  MUSE_C3,
-  MUSE_C6,
-  MUSE_B1,
-  MUSE_B2,
-  MUSE_B3,
-  MUSE_B4,
-  MUSE_B5,
-  MUSE_B6,
-  MUSE_B7,
-  MUSE_B8,
-  MUSE_B9,
-  MUSE_B10,
-  MUSE_B11,
-  MUSE_B12,
-  MUSE_B13,
-  MUSE_B14,
-  MUSE_B15,
-  MUSE_B16,
-  MUSE_B17,
-  MUSE_B18,
-  MUSE_B19,
-  MUSE_B20,
-  MUSE_B21,
-  MUSE_B22,
-  MUSE_B23,
-  MUSE_B24,
-  MUSE_B25,
-  MUSE_B26,
-  MUSE_B27,
-  MUSE_B28,
-  MUSE_B29,
-  MUSE_B30,
-  MUSE_B31
-};
+enum { MUSE_OFF, MUSE_ON, MUSE_C_1_2, MUSE_C1, MUSE_C2, MUSE_C4, MUSE_C8, MUSE_C3, MUSE_C6, MUSE_B1, MUSE_B2, MUSE_B3, MUSE_B4, MUSE_B5, MUSE_B6, MUSE_B7, MUSE_B8, MUSE_B9, MUSE_B10, MUSE_B11, MUSE_B12, MUSE_B13, MUSE_B14, MUSE_B15, MUSE_B16, MUSE_B17, MUSE_B18, MUSE_B19, MUSE_B20, MUSE_B21, MUSE_B22, MUSE_B23, MUSE_B24, MUSE_B25, MUSE_B26, MUSE_B27, MUSE_B28, MUSE_B29, MUSE_B30, MUSE_B31 };
 
-bool number_of_ones_to_bool[16] = {
-  1, 0, 0, 1, 0, 1, 1, 0,
-  0, 1, 1, 0, 1, 0, 0, 1
-};
+bool number_of_ones_to_bool[16] = {1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1};
 
-uint8_t muse_interval[4] = {MUSE_B7,  MUSE_B19, MUSE_B3,  MUSE_B28};
+uint8_t muse_interval[4] = {MUSE_B7, MUSE_B19, MUSE_B3, MUSE_B28};
 uint8_t muse_theme[4]    = {MUSE_B8, MUSE_B23, MUSE_B18, MUSE_B17};
 
-bool muse_timer_1bit = 0;
-uint8_t muse_timer_2bit = 0;
-uint8_t muse_timer_2bit_counter = 0;
-uint8_t muse_timer_4bit = 0;
-uint32_t muse_timer_31bit = 0;
+bool     muse_timer_1bit         = 0;
+uint8_t  muse_timer_2bit         = 0;
+uint8_t  muse_timer_2bit_counter = 0;
+uint8_t  muse_timer_4bit         = 0;
+uint32_t muse_timer_31bit        = 0;
 
 bool bit_for_value(uint8_t value) {
-  switch (value) {
-    case MUSE_OFF:
-      return 0;
-    case MUSE_ON:
-      return 1;
-    case MUSE_C_1_2:
-      return muse_timer_1bit;
-    case MUSE_C1:
-      return (muse_timer_4bit & 1);
-    case MUSE_C2:
-      return (muse_timer_4bit & 2);
-    case MUSE_C4:
-      return (muse_timer_4bit & 4);
-    case MUSE_C8:
-      return (muse_timer_4bit & 8);
-    case MUSE_C3:
-      return (muse_timer_2bit & 1);
-    case MUSE_C6:
-      return (muse_timer_2bit & 2);
-    default:
-      return muse_timer_31bit & (1UL << (value - MUSE_B1));
-  }
+    switch (value) {
+        case MUSE_OFF:
+            return 0;
+        case MUSE_ON:
+            return 1;
+        case MUSE_C_1_2:
+            return muse_timer_1bit;
+        case MUSE_C1:
+            return (muse_timer_4bit & 1);
+        case MUSE_C2:
+            return (muse_timer_4bit & 2);
+        case MUSE_C4:
+            return (muse_timer_4bit & 4);
+        case MUSE_C8:
+            return (muse_timer_4bit & 8);
+        case MUSE_C3:
+            return (muse_timer_2bit & 1);
+        case MUSE_C6:
+            return (muse_timer_2bit & 2);
+        default:
+            return muse_timer_31bit & (1UL << (value - MUSE_B1));
+    }
 }
 
 uint8_t muse_clock_pulse(void) {
-
-  bool top = number_of_ones_to_bool[
-    bit_for_value(muse_theme[0]) +
-    (bit_for_value(muse_theme[1]) << 1) +
-    (bit_for_value(muse_theme[2]) << 2) +
-    (bit_for_value(muse_theme[3]) << 3)
-  ];
-
-  if (muse_timer_1bit == 0) {
-    if (muse_timer_2bit_counter == 0) {
-      muse_timer_2bit = (muse_timer_2bit + 1) % 4;
+    bool top = number_of_ones_to_bool[bit_for_value(muse_theme[0]) + (bit_for_value(muse_theme[1]) << 1) + (bit_for_value(muse_theme[2]) << 2) + (bit_for_value(muse_theme[3]) << 3)];
+
+    if (muse_timer_1bit == 0) {
+        if (muse_timer_2bit_counter == 0) {
+            muse_timer_2bit = (muse_timer_2bit + 1) % 4;
+        }
+        muse_timer_2bit_counter = (muse_timer_2bit_counter + 1) % 3;
+        muse_timer_4bit         = (muse_timer_4bit + 1) % 16;
+        muse_timer_31bit        = (muse_timer_31bit << 1) + top;
     }
-    muse_timer_2bit_counter = (muse_timer_2bit_counter + 1) % 3;
-    muse_timer_4bit = (muse_timer_4bit + 1) % 16;
-    muse_timer_31bit = (muse_timer_31bit << 1) + top;
-  }
-
-  muse_timer_1bit = (muse_timer_1bit + 1) % 2;
 
-  return
-    bit_for_value(muse_interval[0]) +
-    (bit_for_value(muse_interval[1]) << 1) +
-    (bit_for_value(muse_interval[2]) << 2) +
-    (bit_for_value(muse_interval[3]) << 3);
+    muse_timer_1bit = (muse_timer_1bit + 1) % 2;
 
+    return bit_for_value(muse_interval[0]) + (bit_for_value(muse_interval[1]) << 1) + (bit_for_value(muse_interval[2]) << 2) + (bit_for_value(muse_interval[3]) << 3);
 }
index cd54af38d22ffd3530d7b6e2eb7605a03fa1eaa8..9742e19c434c4f1c5a2c154e2d5e50505c714d7e 100644 (file)
 // Tempo Placeholder
 #define TEMPO_DEFAULT 100
 
-
-#define SONG(notes...) { notes }
-
+#define SONG(notes...) \
+    { notes }
 
 // Note Types
-#define MUSICAL_NOTE(note, duration)   {(NOTE##note), duration}
-#define BREVE_NOTE(note)               MUSICAL_NOTE(note, 128)
-#define WHOLE_NOTE(note)               MUSICAL_NOTE(note, 64)
-#define HALF_NOTE(note)                MUSICAL_NOTE(note, 32)
-#define QUARTER_NOTE(note)             MUSICAL_NOTE(note, 16)
-#define EIGHTH_NOTE(note)              MUSICAL_NOTE(note,  8)
-#define SIXTEENTH_NOTE(note)           MUSICAL_NOTE(note,  4)
-
-#define BREVE_DOT_NOTE(note)           MUSICAL_NOTE(note, 128+64)
-#define WHOLE_DOT_NOTE(note)           MUSICAL_NOTE(note, 64+32)
-#define HALF_DOT_NOTE(note)            MUSICAL_NOTE(note, 32+16)
-#define QUARTER_DOT_NOTE(note)         MUSICAL_NOTE(note, 16+8)
-#define EIGHTH_DOT_NOTE(note)          MUSICAL_NOTE(note,  8+4)
-#define SIXTEENTH_DOT_NOTE(note)       MUSICAL_NOTE(note,  4+2)
+#define MUSICAL_NOTE(note, duration) \
+    { (NOTE##note), duration }
+#define BREVE_NOTE(note) MUSICAL_NOTE(note, 128)
+#define WHOLE_NOTE(note) MUSICAL_NOTE(note, 64)
+#define HALF_NOTE(note) MUSICAL_NOTE(note, 32)
+#define QUARTER_NOTE(note) MUSICAL_NOTE(note, 16)
+#define EIGHTH_NOTE(note) MUSICAL_NOTE(note, 8)
+#define SIXTEENTH_NOTE(note) MUSICAL_NOTE(note, 4)
+
+#define BREVE_DOT_NOTE(note) MUSICAL_NOTE(note, 128 + 64)
+#define WHOLE_DOT_NOTE(note) MUSICAL_NOTE(note, 64 + 32)
+#define HALF_DOT_NOTE(note) MUSICAL_NOTE(note, 32 + 16)
+#define QUARTER_DOT_NOTE(note) MUSICAL_NOTE(note, 16 + 8)
+#define EIGHTH_DOT_NOTE(note) MUSICAL_NOTE(note, 8 + 4)
+#define SIXTEENTH_DOT_NOTE(note) MUSICAL_NOTE(note, 4 + 2)
 
 // Note Type Shortcuts
-#define M__NOTE(note, duration)        MUSICAL_NOTE(note, duration)
-#define B__NOTE(n)                     BREVE_NOTE(n)
-#define W__NOTE(n)                     WHOLE_NOTE(n)
-#define H__NOTE(n)                     HALF_NOTE(n)
-#define Q__NOTE(n)                     QUARTER_NOTE(n)
-#define E__NOTE(n)                     EIGHTH_NOTE(n)
-#define S__NOTE(n)                     SIXTEENTH_NOTE(n)
-#define BD_NOTE(n)                     BREVE_DOT_NOTE(n)
-#define WD_NOTE(n)                     WHOLE_DOT_NOTE(n)
-#define HD_NOTE(n)                     HALF_DOT_NOTE(n)
-#define QD_NOTE(n)                     QUARTER_DOT_NOTE(n)
-#define ED_NOTE(n)                     EIGHTH_DOT_NOTE(n)
-#define SD_NOTE(n)                     SIXTEENTH_DOT_NOTE(n)
+#define M__NOTE(note, duration) MUSICAL_NOTE(note, duration)
+#define B__NOTE(n) BREVE_NOTE(n)
+#define W__NOTE(n) WHOLE_NOTE(n)
+#define H__NOTE(n) HALF_NOTE(n)
+#define Q__NOTE(n) QUARTER_NOTE(n)
+#define E__NOTE(n) EIGHTH_NOTE(n)
+#define S__NOTE(n) SIXTEENTH_NOTE(n)
+#define BD_NOTE(n) BREVE_DOT_NOTE(n)
+#define WD_NOTE(n) WHOLE_DOT_NOTE(n)
+#define HD_NOTE(n) HALF_DOT_NOTE(n)
+#define QD_NOTE(n) QUARTER_DOT_NOTE(n)
+#define ED_NOTE(n) EIGHTH_DOT_NOTE(n)
+#define SD_NOTE(n) SIXTEENTH_DOT_NOTE(n)
 
 // Note Timbre
 // Changes how the notes sound
-#define TIMBRE_12       0.125f
-#define TIMBRE_25       0.250f
-#define TIMBRE_50       0.500f
-#define TIMBRE_75       0.750f
-#define TIMBRE_DEFAULT  TIMBRE_50
+#define TIMBRE_12 0.125f
+#define TIMBRE_25 0.250f
+#define TIMBRE_50 0.500f
+#define TIMBRE_75 0.750f
+#define TIMBRE_DEFAULT TIMBRE_50
 
 // Notes - # = Octave
 
 #ifdef __arm__
-#define NOTE_REST         1.00f
+#    define NOTE_REST 1.00f
 #else
-#define NOTE_REST         0.00f
+#    define NOTE_REST 0.00f
 #endif
 
 /* These notes are currently bugged
 #define NOTE_AS1         58.27f
 */
 
-#define NOTE_B1          61.74f
-#define NOTE_C2          65.41f
-#define NOTE_CS2         69.30f
-#define NOTE_D2          73.42f
-#define NOTE_DS2         77.78f
-#define NOTE_E2          82.41f
-#define NOTE_F2          87.31f
-#define NOTE_FS2         92.50f
-#define NOTE_G2          98.00f
-#define NOTE_GS2        103.83f
-#define NOTE_A2         110.00f
-#define NOTE_AS2        116.54f
-#define NOTE_B2         123.47f
-#define NOTE_C3         130.81f
-#define NOTE_CS3        138.59f
-#define NOTE_D3         146.83f
-#define NOTE_DS3        155.56f
-#define NOTE_E3         164.81f
-#define NOTE_F3         174.61f
-#define NOTE_FS3        185.00f
-#define NOTE_G3         196.00f
-#define NOTE_GS3        207.65f
-#define NOTE_A3         220.00f
-#define NOTE_AS3        233.08f
-#define NOTE_B3         246.94f
-#define NOTE_C4         261.63f
-#define NOTE_CS4        277.18f
-#define NOTE_D4         293.66f
-#define NOTE_DS4        311.13f
-#define NOTE_E4         329.63f
-#define NOTE_F4         349.23f
-#define NOTE_FS4        369.99f
-#define NOTE_G4         392.00f
-#define NOTE_GS4        415.30f
-#define NOTE_A4         440.00f
-#define NOTE_AS4        466.16f
-#define NOTE_B4         493.88f
-#define NOTE_C5         523.25f
-#define NOTE_CS5        554.37f
-#define NOTE_D5         587.33f
-#define NOTE_DS5        622.25f
-#define NOTE_E5         659.26f
-#define NOTE_F5         698.46f
-#define NOTE_FS5        739.99f
-#define NOTE_G5         783.99f
-#define NOTE_GS5        830.61f
-#define NOTE_A5         880.00f
-#define NOTE_AS5        932.33f
-#define NOTE_B5         987.77f
-#define NOTE_C6        1046.50f
-#define NOTE_CS6       1108.73f
-#define NOTE_D6        1174.66f
-#define NOTE_DS6       1244.51f
-#define NOTE_E6        1318.51f
-#define NOTE_F6        1396.91f
-#define NOTE_FS6       1479.98f
-#define NOTE_G6        1567.98f
-#define NOTE_GS6       1661.22f
-#define NOTE_A6        1760.00f
-#define NOTE_AS6       1864.66f
-#define NOTE_B6        1975.53f
-#define NOTE_C7        2093.00f
-#define NOTE_CS7       2217.46f
-#define NOTE_D7        2349.32f
-#define NOTE_DS7       2489.02f
-#define NOTE_E7        2637.02f
-#define NOTE_F7        2793.83f
-#define NOTE_FS7       2959.96f
-#define NOTE_G7        3135.96f
-#define NOTE_GS7       3322.44f
-#define NOTE_A7        3520.00f
-#define NOTE_AS7       3729.31f
-#define NOTE_B7        3951.07f
-#define NOTE_C8        4186.01f
-#define NOTE_CS8       4434.92f
-#define NOTE_D8        4698.64f
-#define NOTE_DS8       4978.03f
-#define NOTE_E8        5274.04f
-#define NOTE_F8        5587.65f
-#define NOTE_FS8       5919.91f
-#define NOTE_G8        6271.93f
-#define NOTE_GS8       6644.88f
-#define NOTE_A8        7040.00f
-#define NOTE_AS8       7458.62f
-#define NOTE_B8        7902.13f
+#define NOTE_B1 61.74f
+#define NOTE_C2 65.41f
+#define NOTE_CS2 69.30f
+#define NOTE_D2 73.42f
+#define NOTE_DS2 77.78f
+#define NOTE_E2 82.41f
+#define NOTE_F2 87.31f
+#define NOTE_FS2 92.50f
+#define NOTE_G2 98.00f
+#define NOTE_GS2 103.83f
+#define NOTE_A2 110.00f
+#define NOTE_AS2 116.54f
+#define NOTE_B2 123.47f
+#define NOTE_C3 130.81f
+#define NOTE_CS3 138.59f
+#define NOTE_D3 146.83f
+#define NOTE_DS3 155.56f
+#define NOTE_E3 164.81f
+#define NOTE_F3 174.61f
+#define NOTE_FS3 185.00f
+#define NOTE_G3 196.00f
+#define NOTE_GS3 207.65f
+#define NOTE_A3 220.00f
+#define NOTE_AS3 233.08f
+#define NOTE_B3 246.94f
+#define NOTE_C4 261.63f
+#define NOTE_CS4 277.18f
+#define NOTE_D4 293.66f
+#define NOTE_DS4 311.13f
+#define NOTE_E4 329.63f
+#define NOTE_F4 349.23f
+#define NOTE_FS4 369.99f
+#define NOTE_G4 392.00f
+#define NOTE_GS4 415.30f
+#define NOTE_A4 440.00f
+#define NOTE_AS4 466.16f
+#define NOTE_B4 493.88f
+#define NOTE_C5 523.25f
+#define NOTE_CS5 554.37f
+#define NOTE_D5 587.33f
+#define NOTE_DS5 622.25f
+#define NOTE_E5 659.26f
+#define NOTE_F5 698.46f
+#define NOTE_FS5 739.99f
+#define NOTE_G5 783.99f
+#define NOTE_GS5 830.61f
+#define NOTE_A5 880.00f
+#define NOTE_AS5 932.33f
+#define NOTE_B5 987.77f
+#define NOTE_C6 1046.50f
+#define NOTE_CS6 1108.73f
+#define NOTE_D6 1174.66f
+#define NOTE_DS6 1244.51f
+#define NOTE_E6 1318.51f
+#define NOTE_F6 1396.91f
+#define NOTE_FS6 1479.98f
+#define NOTE_G6 1567.98f
+#define NOTE_GS6 1661.22f
+#define NOTE_A6 1760.00f
+#define NOTE_AS6 1864.66f
+#define NOTE_B6 1975.53f
+#define NOTE_C7 2093.00f
+#define NOTE_CS7 2217.46f
+#define NOTE_D7 2349.32f
+#define NOTE_DS7 2489.02f
+#define NOTE_E7 2637.02f
+#define NOTE_F7 2793.83f
+#define NOTE_FS7 2959.96f
+#define NOTE_G7 3135.96f
+#define NOTE_GS7 3322.44f
+#define NOTE_A7 3520.00f
+#define NOTE_AS7 3729.31f
+#define NOTE_B7 3951.07f
+#define NOTE_C8 4186.01f
+#define NOTE_CS8 4434.92f
+#define NOTE_D8 4698.64f
+#define NOTE_DS8 4978.03f
+#define NOTE_E8 5274.04f
+#define NOTE_F8 5587.65f
+#define NOTE_FS8 5919.91f
+#define NOTE_G8 6271.93f
+#define NOTE_GS8 6644.88f
+#define NOTE_A8 7040.00f
+#define NOTE_AS8 7458.62f
+#define NOTE_B8 7902.13f
 
 // Flat Aliases
 #define NOTE_DF0 NOTE_CS0
 #define NOTE_AF8 NOTE_GS8
 #define NOTE_BF8 NOTE_AS8
 
-
 #endif
index 33dbcfcb1dc852aa9d6117f3bcd0990f6a610db7..3d0e0e51ed8e461082256ce300dc375e538ac444 100644 (file)
  * Author: Friedrich Schiller
  + License: Public Domain
  */
-#define ODE_TO_JOY                                          \
-    Q__NOTE(_E4), Q__NOTE(_E4), Q__NOTE(_F4), Q__NOTE(_G4), \
-    Q__NOTE(_G4), Q__NOTE(_F4), Q__NOTE(_E4), Q__NOTE(_D4), \
-    Q__NOTE(_C4), Q__NOTE(_C4), Q__NOTE(_D4), Q__NOTE(_E4), \
-    QD_NOTE(_E4), E__NOTE(_D4), H__NOTE(_D4),
+#define ODE_TO_JOY Q__NOTE(_E4), Q__NOTE(_E4), Q__NOTE(_F4), Q__NOTE(_G4), Q__NOTE(_G4), Q__NOTE(_F4), Q__NOTE(_E4), Q__NOTE(_D4), Q__NOTE(_C4), Q__NOTE(_C4), Q__NOTE(_D4), Q__NOTE(_E4), QD_NOTE(_E4), E__NOTE(_D4), H__NOTE(_D4),
 
 /* Rock-a-bye Baby
  * Author: Unknown
  + License: Public Domain
  */
-#define ROCK_A_BYE_BABY                            \
-    QD_NOTE(_B4), E__NOTE(_D4), Q__NOTE(_B5),      \
-    H__NOTE(_A5), Q__NOTE(_G5),                    \
-    QD_NOTE(_B4), E__NOTE(_D5), Q__NOTE(_G5),      \
-    H__NOTE(_FS5),
+#define ROCK_A_BYE_BABY QD_NOTE(_B4), E__NOTE(_D4), Q__NOTE(_B5), H__NOTE(_A5), Q__NOTE(_G5), QD_NOTE(_B4), E__NOTE(_D5), Q__NOTE(_G5), H__NOTE(_FS5),
 
-
-#define CLUEBOARD_SOUND \
-    HD_NOTE(_C3), HD_NOTE(_D3), HD_NOTE(_E3), HD_NOTE(_F3), HD_NOTE(_G3), HD_NOTE(_A4), HD_NOTE(_B4), HD_NOTE(_C4)
+#define CLUEBOARD_SOUND HD_NOTE(_C3), HD_NOTE(_D3), HD_NOTE(_E3), HD_NOTE(_F3), HD_NOTE(_G3), HD_NOTE(_A4), HD_NOTE(_B4), HD_NOTE(_C4)
 /*
     HD_NOTE(_G3), HD_NOTE(_E3), HD_NOTE(_C3), \
     Q__NOTE(_E3), Q__NOTE(_C3), Q__NOTE(_G3), \
     Q__NOTE(_F3)
 */
 
-#define STARTUP_SOUND  \
-    E__NOTE(_E6),     \
-    E__NOTE(_A6),     \
-    ED_NOTE(_E7),
-
-#define GOODBYE_SOUND \
-    E__NOTE(_E7),     \
-    E__NOTE(_A6),     \
-    ED_NOTE(_E6),
-
-#define PLANCK_SOUND  \
-    ED_NOTE(_E7 ),     \
-    E__NOTE(_CS7),     \
-    E__NOTE(_E6 ),     \
-    E__NOTE(_A6 ),     \
-    M__NOTE(_CS7, 20),
-
-#define PREONIC_SOUND \
-    M__NOTE(_B5, 20),  \
-    E__NOTE(_B6),      \
-    M__NOTE(_DS6, 20), \
-    E__NOTE(_B6),
-
-#define QWERTY_SOUND \
-    E__NOTE(_GS6 ),  \
-    E__NOTE(_A6  ),  \
-    S__NOTE(_REST),  \
-    Q__NOTE(_E7  ),
-
-#define COLEMAK_SOUND \
-    E__NOTE(_GS6 ),   \
-    E__NOTE(_A6  ),   \
-    S__NOTE(_REST),   \
-    ED_NOTE(_E7  ),   \
-    S__NOTE(_REST),   \
-    ED_NOTE(_GS7 ),
-
-#define DVORAK_SOUND \
-    E__NOTE(_GS6 ),  \
-    E__NOTE(_A6  ),  \
-    S__NOTE(_REST),  \
-    E__NOTE(_E7  ),  \
-    S__NOTE(_REST),  \
-    E__NOTE(_FS7 ),  \
-    S__NOTE(_REST),  \
-    E__NOTE(_E7  ),
-
-#define WORKMAN_SOUND \
-    E__NOTE(_GS6 ), \
-    E__NOTE(_A6  ), \
-    S__NOTE(_REST), \
-    E__NOTE(_GS6 ), \
-    E__NOTE(_A6  ), \
-    S__NOTE(_REST), \
-    ED_NOTE(_FS7  ), \
-    S__NOTE(_REST), \
-    ED_NOTE(_A7 ),
-
-#define PLOVER_SOUND \
-    E__NOTE(_GS6 ),  \
-    E__NOTE(_A6  ),  \
-    S__NOTE(_REST),  \
-    ED_NOTE(_E7  ),  \
-    S__NOTE(_REST),  \
-    ED_NOTE(_A7  ),
-
-#define PLOVER_GOODBYE_SOUND \
-    E__NOTE(_GS6 ),  \
-    E__NOTE(_A6  ),  \
-    S__NOTE(_REST),  \
-    ED_NOTE(_A7  ),  \
-    S__NOTE(_REST),  \
-    ED_NOTE(_E7  ),
-
-#define MUSIC_ON_SOUND \
-    E__NOTE(_A5 ),        \
-    E__NOTE(_B5 ),        \
-    E__NOTE(_CS6),        \
-    E__NOTE(_D6 ),        \
-    E__NOTE(_E6 ),        \
-    E__NOTE(_FS6),        \
-    E__NOTE(_GS6),        \
-    E__NOTE(_A6 ),
-
-#define AUDIO_ON_SOUND \
-    E__NOTE(_A5 ),        \
-    E__NOTE(_A6 ),
-
-#define AUDIO_OFF_SOUND \
-    E__NOTE(_A6 ),        \
-    E__NOTE(_A5 ),
+#define STARTUP_SOUND E__NOTE(_E6), E__NOTE(_A6), ED_NOTE(_E7),
+
+#define GOODBYE_SOUND E__NOTE(_E7), E__NOTE(_A6), ED_NOTE(_E6),
+
+#define PLANCK_SOUND ED_NOTE(_E7), E__NOTE(_CS7), E__NOTE(_E6), E__NOTE(_A6), M__NOTE(_CS7, 20),
+
+#define PREONIC_SOUND M__NOTE(_B5, 20), E__NOTE(_B6), M__NOTE(_DS6, 20), E__NOTE(_B6),
+
+#define QWERTY_SOUND E__NOTE(_GS6), E__NOTE(_A6), S__NOTE(_REST), Q__NOTE(_E7),
+
+#define COLEMAK_SOUND E__NOTE(_GS6), E__NOTE(_A6), S__NOTE(_REST), ED_NOTE(_E7), S__NOTE(_REST), ED_NOTE(_GS7),
+
+#define DVORAK_SOUND E__NOTE(_GS6), E__NOTE(_A6), S__NOTE(_REST), E__NOTE(_E7), S__NOTE(_REST), E__NOTE(_FS7), S__NOTE(_REST), E__NOTE(_E7),
+
+#define WORKMAN_SOUND E__NOTE(_GS6), E__NOTE(_A6), S__NOTE(_REST), E__NOTE(_GS6), E__NOTE(_A6), S__NOTE(_REST), ED_NOTE(_FS7), S__NOTE(_REST), ED_NOTE(_A7),
+
+#define PLOVER_SOUND E__NOTE(_GS6), E__NOTE(_A6), S__NOTE(_REST), ED_NOTE(_E7), S__NOTE(_REST), ED_NOTE(_A7),
+
+#define PLOVER_GOODBYE_SOUND E__NOTE(_GS6), E__NOTE(_A6), S__NOTE(_REST), ED_NOTE(_A7), S__NOTE(_REST), ED_NOTE(_E7),
+
+#define MUSIC_ON_SOUND E__NOTE(_A5), E__NOTE(_B5), E__NOTE(_CS6), E__NOTE(_D6), E__NOTE(_E6), E__NOTE(_FS6), E__NOTE(_GS6), E__NOTE(_A6),
+
+#define AUDIO_ON_SOUND E__NOTE(_A5), E__NOTE(_A6),
+
+#define AUDIO_OFF_SOUND E__NOTE(_A6), E__NOTE(_A5),
 
 #define MUSIC_SCALE_SOUND MUSIC_ON_SOUND
 
-#define MUSIC_OFF_SOUND \
-    E__NOTE(_A6 ),        \
-    E__NOTE(_GS6 ),        \
-    E__NOTE(_FS6),        \
-    E__NOTE(_E6 ),        \
-    E__NOTE(_D6 ),        \
-    E__NOTE(_CS6),        \
-    E__NOTE(_B5),        \
-    E__NOTE(_A5 ),
-
-#define VOICE_CHANGE_SOUND \
-    Q__NOTE(_A5 ),        \
-    Q__NOTE(_CS6),        \
-    Q__NOTE(_E6 ),        \
-    Q__NOTE(_A6 ),
-
-#define CHROMATIC_SOUND \
-    Q__NOTE(_A5 ),        \
-    Q__NOTE(_AS5 ),        \
-    Q__NOTE(_B5),        \
-    Q__NOTE(_C6 ),        \
-    Q__NOTE(_CS6 ),
-
-#define MAJOR_SOUND \
-    Q__NOTE(_A5 ),        \
-    Q__NOTE(_B5 ),        \
-    Q__NOTE(_CS6),        \
-    Q__NOTE(_D6 ),        \
-    Q__NOTE(_E6 ),
-
-#define MINOR_SOUND \
-    Q__NOTE(_A5 ),        \
-    Q__NOTE(_B5 ),        \
-    Q__NOTE(_C6 ),        \
-    Q__NOTE(_D6 ),        \
-    Q__NOTE(_E6 ),
-
-#define GUITAR_SOUND \
-    Q__NOTE(_E5 ),        \
-    Q__NOTE(_A5),        \
-    Q__NOTE(_D6 ),        \
-    Q__NOTE(_G6 ),
-
-#define VIOLIN_SOUND \
-    Q__NOTE(_G5 ),        \
-    Q__NOTE(_D6),        \
-    Q__NOTE(_A6 ),        \
-    Q__NOTE(_E7 ),
-
-#define CAPS_LOCK_ON_SOUND \
-    E__NOTE(_A3),          \
-    E__NOTE(_B3),
-
-#define CAPS_LOCK_OFF_SOUND \
-    E__NOTE(_B3),           \
-    E__NOTE(_A3),
-
-#define SCROLL_LOCK_ON_SOUND \
-    E__NOTE(_D4),            \
-    E__NOTE(_E4),
-
-#define SCROLL_LOCK_OFF_SOUND \
-    E__NOTE(_E4),             \
-    E__NOTE(_D4),
-
-#define NUM_LOCK_ON_SOUND \
-    E__NOTE(_D5),         \
-    E__NOTE(_E5),
-
-#define NUM_LOCK_OFF_SOUND \
-    E__NOTE(_E5),          \
-    E__NOTE(_D5),
-
-#define AG_NORM_SOUND \
-    E__NOTE(_A5),      \
-    E__NOTE(_A5),
-
-#define AG_SWAP_SOUND \
-    SD_NOTE(_B5),      \
-    SD_NOTE(_A5),      \
-    SD_NOTE(_B5),      \
-    SD_NOTE(_A5),
-
-#define UNICODE_WINDOWS \
-    E__NOTE(_B5),       \
-    S__NOTE(_E6),
-
-#define UNICODE_LINUX \
-    E__NOTE(_E6),     \
-    S__NOTE(_B5),
-
-
-#define TERMINAL_SOUND \
-    E__NOTE(_C5 )
+#define MUSIC_OFF_SOUND E__NOTE(_A6), E__NOTE(_GS6), E__NOTE(_FS6), E__NOTE(_E6), E__NOTE(_D6), E__NOTE(_CS6), E__NOTE(_B5), E__NOTE(_A5),
+
+#define VOICE_CHANGE_SOUND Q__NOTE(_A5), Q__NOTE(_CS6), Q__NOTE(_E6), Q__NOTE(_A6),
+
+#define CHROMATIC_SOUND Q__NOTE(_A5), Q__NOTE(_AS5), Q__NOTE(_B5), Q__NOTE(_C6), Q__NOTE(_CS6),
+
+#define MAJOR_SOUND Q__NOTE(_A5), Q__NOTE(_B5), Q__NOTE(_CS6), Q__NOTE(_D6), Q__NOTE(_E6),
+
+#define MINOR_SOUND Q__NOTE(_A5), Q__NOTE(_B5), Q__NOTE(_C6), Q__NOTE(_D6), Q__NOTE(_E6),
+
+#define GUITAR_SOUND Q__NOTE(_E5), Q__NOTE(_A5), Q__NOTE(_D6), Q__NOTE(_G6),
 
+#define VIOLIN_SOUND Q__NOTE(_G5), Q__NOTE(_D6), Q__NOTE(_A6), Q__NOTE(_E7),
+
+#define CAPS_LOCK_ON_SOUND E__NOTE(_A3), E__NOTE(_B3),
+
+#define CAPS_LOCK_OFF_SOUND E__NOTE(_B3), E__NOTE(_A3),
+
+#define SCROLL_LOCK_ON_SOUND E__NOTE(_D4), E__NOTE(_E4),
+
+#define SCROLL_LOCK_OFF_SOUND E__NOTE(_E4), E__NOTE(_D4),
+
+#define NUM_LOCK_ON_SOUND E__NOTE(_D5), E__NOTE(_E5),
+
+#define NUM_LOCK_OFF_SOUND E__NOTE(_E5), E__NOTE(_D5),
+
+#define AG_NORM_SOUND E__NOTE(_A5), E__NOTE(_A5),
+
+#define AG_SWAP_SOUND SD_NOTE(_B5), SD_NOTE(_A5), SD_NOTE(_B5), SD_NOTE(_A5),
+
+#define UNICODE_WINDOWS E__NOTE(_B5), S__NOTE(_E6),
+
+#define UNICODE_LINUX E__NOTE(_E6), S__NOTE(_B5),
+
+#define TERMINAL_SOUND E__NOTE(_C5)
 
 /* Title:            La Campanella
  * Author/Composer:  Frank Lizst
  + License:          Public Domain
  */
-#define CAMPANELLA \
-  Q__NOTE(_DS4), E__NOTE(_DS4), E__NOTE(_DS5), Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_DS5), E__NOTE(_DS5), \
-  E__NOTE(_DS6), Q__NOTE(_CS5), E__NOTE(_CS5), E__NOTE(_DS6), Q__NOTE(_B4), E__NOTE(_B4), E__NOTE(_DS6), \
-  Q__NOTE(_B4), E__NOTE(_B4), E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), Q__NOTE(_GS4), \
-  E__NOTE(_GS4), E__NOTE(_DS6), Q__NOTE(_G4), E__NOTE(_G4), E__NOTE(_DS6), Q__NOTE(_GS4), E__NOTE(_GS4), \
-  E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), Q__NOTE(_DS4), E__NOTE(_DS4), E__NOTE(_DS6), \
-  Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_E5), E__NOTE(_E5), E__NOTE(_DS6), Q__NOTE(_DS5), \
-  E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_CS5), E__NOTE(_CS5), E__NOTE(_DS6), Q__NOTE(_B4), E__NOTE(_B4), \
-  E__NOTE(_DS6), Q__NOTE(_B4), E__NOTE(_B4), E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), \
-  Q__NOTE(_GS4), E__NOTE(_GS4), E__NOTE(_DS6), Q__NOTE(_G4), E__NOTE(_G4), E__NOTE(_DS6), Q__NOTE(_GS4), \
-  E__NOTE(_GS4), E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), Q__NOTE(_DS4), E__NOTE(_DS4), \
-  E__NOTE(_DS5), Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_DS6), E__NOTE(_DS6), E__NOTE(_DS7), \
-  Q__NOTE(_DS6), E__NOTE(_DS6), E__NOTE(_DS7), Q__NOTE(_CS6), E__NOTE(_CS6), E__NOTE(_DS7), Q__NOTE(_B5), \
-  E__NOTE(_B5), E__NOTE(_DS7), Q__NOTE(_B5), E__NOTE(_B5), E__NOTE(_DS7), Q__NOTE(_AS5), E__NOTE(_AS5), \
-  E__NOTE(_DS7), Q__NOTE(_GS5), E__NOTE(_GS5), E__NOTE(_DS7), Q__NOTE(_G5), E__NOTE(_G5), E__NOTE(_DS7), \
-  Q__NOTE(_GS5), E__NOTE(_GS5), E__NOTE(_DS7), Q__NOTE(_AS5), E__NOTE(_AS5), E__NOTE(_DS7), Q__NOTE(_DS5), \
-  E__NOTE(_DS5), E__NOTE(_DS7), W__NOTE(_DS6), W__NOTE(_GS5),
-
-
-
+#define CAMPANELLA                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 \
+    Q__NOTE(_DS4), E__NOTE(_DS4), E__NOTE(_DS5), Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_CS5), E__NOTE(_CS5), E__NOTE(_DS6), Q__NOTE(_B4), E__NOTE(_B4), E__NOTE(_DS6), Q__NOTE(_B4), E__NOTE(_B4), E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), Q__NOTE(_GS4), E__NOTE(_GS4), E__NOTE(_DS6), Q__NOTE(_G4), E__NOTE(_G4), E__NOTE(_DS6), Q__NOTE(_GS4), E__NOTE(_GS4), E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), Q__NOTE(_DS4), E__NOTE(_DS4), E__NOTE(_DS6), Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_E5), E__NOTE(_E5), E__NOTE(_DS6), Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_CS5), E__NOTE(_CS5), E__NOTE(_DS6), Q__NOTE(_B4), E__NOTE(_B4), E__NOTE(_DS6), Q__NOTE(_B4), E__NOTE(_B4), E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), Q__NOTE(_GS4), E__NOTE(_GS4), E__NOTE(_DS6), Q__NOTE(_G4), E__NOTE(_G4), E__NOTE(_DS6), Q__NOTE(_GS4), E__NOTE(_GS4), E__NOTE(_DS6), Q__NOTE(_AS4), \
+        E__NOTE(_AS4), E__NOTE(_DS6), Q__NOTE(_DS4), E__NOTE(_DS4), E__NOTE(_DS5), Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_DS6), E__NOTE(_DS6), E__NOTE(_DS7), Q__NOTE(_DS6), E__NOTE(_DS6), E__NOTE(_DS7), Q__NOTE(_CS6), E__NOTE(_CS6), E__NOTE(_DS7), Q__NOTE(_B5), E__NOTE(_B5), E__NOTE(_DS7), Q__NOTE(_B5), E__NOTE(_B5), E__NOTE(_DS7), Q__NOTE(_AS5), E__NOTE(_AS5), E__NOTE(_DS7), Q__NOTE(_GS5), E__NOTE(_GS5), E__NOTE(_DS7), Q__NOTE(_G5), E__NOTE(_G5), E__NOTE(_DS7), Q__NOTE(_GS5), E__NOTE(_GS5), E__NOTE(_DS7), Q__NOTE(_AS5), E__NOTE(_AS5), E__NOTE(_DS7), Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS7), W__NOTE(_DS6), W__NOTE(_GS5),
 
 /* Title:            Fantaisie-Impromptu
  * Author/Composer:  Chopin
  * License:          Public Domain
-*/
-#define FANTASIE_IMPROMPTU \
-  E__NOTE(_GS4), E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_REST), E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), \
-  E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_GS4), E__NOTE(_A4), \
-  E__NOTE(_GS4), E__NOTE(_REST), E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_DS5), \
-  E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_A4), E__NOTE(_CS5), E__NOTE(_DS5), \
-  E__NOTE(_FS5), E__NOTE(_A5), E__NOTE(_CS6), E__NOTE(_DS6), E__NOTE(_B6), E__NOTE(_A6), E__NOTE(_GS6), E__NOTE(_FS6), \
-  E__NOTE(_E6), E__NOTE(_DS6), E__NOTE(_FS6), E__NOTE(_CS6), E__NOTE(_C5), E__NOTE(_DS6), E__NOTE(_A5), E__NOTE(_GS5), \
-  E__NOTE(_FS5), E__NOTE(_A5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_FS5), E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_DS5), \
-  E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_B4), E__NOTE(_A4), E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_A4), E__NOTE(_GS4), \
-  E__NOTE(_REST), E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_DS5), E__NOTE(_CS5), \
-  E__NOTE(_C5), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_GS4), E__NOTE(_AS4), E__NOTE(_GS4), E__NOTE(_REST), \
-  E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_C5), \
-  E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_DS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_REST), E__NOTE(_DS5), \
-  E__NOTE(_B5), E__NOTE(_AS5), E__NOTE(_GS5), E__NOTE(_REST), E__NOTE(_E6), E__NOTE(_DS6), E__NOTE(_CS6), E__NOTE(_B5), \
-  E__NOTE(_AS5), E__NOTE(_GS5), E__NOTE(_REST), E__NOTE(_AS5), WD_NOTE(_GS5),
-
+ */
+#define FANTASIE_IMPROMPTU                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   \
+    E__NOTE(_GS4), E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_REST), E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_GS4), E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_REST), E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_A4), E__NOTE(_CS5), E__NOTE(_DS5), E__NOTE(_FS5), E__NOTE(_A5), E__NOTE(_CS6), E__NOTE(_DS6), E__NOTE(_B6), E__NOTE(_A6), E__NOTE(_GS6), E__NOTE(_FS6), E__NOTE(_E6), E__NOTE(_DS6), E__NOTE(_FS6), E__NOTE(_CS6), E__NOTE(_C5), E__NOTE(_DS6), E__NOTE(_A5), E__NOTE(_GS5), E__NOTE(_FS5), E__NOTE(_A5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_FS5), E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_DS5), E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_B4), E__NOTE(_A4), E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_REST), E__NOTE(_GS4), \
+        E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_GS4), E__NOTE(_AS4), E__NOTE(_GS4), E__NOTE(_REST), E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_DS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_REST), E__NOTE(_DS5), E__NOTE(_B5), E__NOTE(_AS5), E__NOTE(_GS5), E__NOTE(_REST), E__NOTE(_E6), E__NOTE(_DS6), E__NOTE(_CS6), E__NOTE(_B5), E__NOTE(_AS5), E__NOTE(_GS5), E__NOTE(_REST), E__NOTE(_AS5), WD_NOTE(_GS5),
 
 /* Title:            Nocturne Op. 9 No. 1 in B flat minor
  * Author/Composer:  Chopin
    License:          Public Domain
 */
-#define NOCTURNE_OP_9_NO_1 \
-  H__NOTE(_BF5), H__NOTE(_C6), H__NOTE(_DF6), H__NOTE(_A5), H__NOTE(_BF5), H__NOTE(_GF5), W__NOTE(_F5), W__NOTE(_F5), W__NOTE(_F5), \
-  W__NOTE(_F5), H__NOTE(_GF5), H__NOTE(_F5), H__NOTE(_EF5), H__NOTE(_C5), B__NOTE(_DF5), W__NOTE(_BF4), Q__NOTE(_BF5), \
-  Q__NOTE(_C6), Q__NOTE(_DF6), Q__NOTE(_A5), Q__NOTE(_BF5), Q__NOTE(_A5), Q__NOTE(_GS5), Q__NOTE(_A5), Q__NOTE(_C6), \
-  Q__NOTE(_BF5), Q__NOTE(_GF5), Q__NOTE(_F5), Q__NOTE(_GF5), Q__NOTE(_E5), Q__NOTE(_F5), Q__NOTE(_BF5), Q__NOTE(_A5), \
-  Q__NOTE(_AF5), Q__NOTE(_G5), Q__NOTE(_GF5), Q__NOTE(_F5), Q__NOTE(_E5), Q__NOTE(_EF5), Q__NOTE(_D5), Q__NOTE(_DF5), \
-  Q__NOTE(_C5), Q__NOTE(_DF5), Q__NOTE(_C5), Q__NOTE(_B4), Q__NOTE(_C5), Q__NOTE(_F5), Q__NOTE(_E5), Q__NOTE(_EF5), \
-  B__NOTE(_DF5), W__NOTE(_BF4), W__NOTE(_BF5), W__NOTE(_BF5), W__NOTE(_BF5), BD_NOTE(_AF5), W__NOTE(_DF5), H__NOTE(_BF4), \
-  H__NOTE(_C5), H__NOTE(_DF5), H__NOTE(_GF5), H__NOTE(_GF5), BD_NOTE(_F5), W__NOTE(_EF5), H__NOTE(_F5), H__NOTE(_EF5), \
-  H__NOTE(_DF5), H__NOTE(_A4), B__NOTE(_AF4), W__NOTE(_DF5), W__NOTE(_EF5), H__NOTE(_F5), H__NOTE(_EF5), H__NOTE(_DF5), \
-  H__NOTE(_EF5), BD_NOTE(_F5),
-
+#define NOCTURNE_OP_9_NO_1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       \
+    H__NOTE(_BF5), H__NOTE(_C6), H__NOTE(_DF6), H__NOTE(_A5), H__NOTE(_BF5), H__NOTE(_GF5), W__NOTE(_F5), W__NOTE(_F5), W__NOTE(_F5), W__NOTE(_F5), H__NOTE(_GF5), H__NOTE(_F5), H__NOTE(_EF5), H__NOTE(_C5), B__NOTE(_DF5), W__NOTE(_BF4), Q__NOTE(_BF5), Q__NOTE(_C6), Q__NOTE(_DF6), Q__NOTE(_A5), Q__NOTE(_BF5), Q__NOTE(_A5), Q__NOTE(_GS5), Q__NOTE(_A5), Q__NOTE(_C6), Q__NOTE(_BF5), Q__NOTE(_GF5), Q__NOTE(_F5), Q__NOTE(_GF5), Q__NOTE(_E5), Q__NOTE(_F5), Q__NOTE(_BF5), Q__NOTE(_A5), Q__NOTE(_AF5), Q__NOTE(_G5), Q__NOTE(_GF5), Q__NOTE(_F5), Q__NOTE(_E5), Q__NOTE(_EF5), Q__NOTE(_D5), Q__NOTE(_DF5), Q__NOTE(_C5), Q__NOTE(_DF5), Q__NOTE(_C5), Q__NOTE(_B4), Q__NOTE(_C5), Q__NOTE(_F5), Q__NOTE(_E5), Q__NOTE(_EF5), B__NOTE(_DF5), W__NOTE(_BF4), W__NOTE(_BF5), W__NOTE(_BF5), W__NOTE(_BF5), BD_NOTE(_AF5), W__NOTE(_DF5), H__NOTE(_BF4), H__NOTE(_C5), H__NOTE(_DF5), H__NOTE(_GF5), H__NOTE(_GF5), BD_NOTE(_F5), W__NOTE(_EF5), H__NOTE(_F5), H__NOTE(_EF5), H__NOTE(_DF5), H__NOTE(_A4), B__NOTE(_AF4), \
+        W__NOTE(_DF5), W__NOTE(_EF5), H__NOTE(_F5), H__NOTE(_EF5), H__NOTE(_DF5), H__NOTE(_EF5), BD_NOTE(_F5),
 
 /* Removed sounds
  +   This list is here solely for compatibility, so that removed songs don't just break things
index 94147ccb660e8a72f50459263065515a9676fb0c..53a65e4e37ed55ac5760b390a772449765bb6e9a 100644 (file)
 
 // these are imported from audio.c
 extern uint16_t envelope_index;
-extern float note_timbre;
-extern float polyphony_rate;
-extern bool glissando;
+extern float    note_timbre;
+extern float    polyphony_rate;
+extern bool     glissando;
 
 voice_type voice = default_voice;
 
-void set_voice(voice_type v) {
-    voice = v;
-}
+void set_voice(voice_type v) { voice = v; }
 
-void voice_iterate() {
-    voice = (voice + 1) % number_of_voices;
-}
+void voice_iterate() { voice = (voice + 1) % number_of_voices; }
 
-void voice_deiterate() {
-    voice = (voice - 1 + number_of_voices) % number_of_voices;
-}
+void voice_deiterate() { voice = (voice - 1 + number_of_voices) % number_of_voices; }
 
 float voice_envelope(float frequency) {
     // envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz
-    __attribute__ ((unused))
-    uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency));
+    __attribute__((unused)) uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency));
 
     switch (voice) {
         case default_voice:
-            glissando = false;
-            note_timbre = TIMBRE_50;
+            glissando      = false;
+            note_timbre    = TIMBRE_50;
             polyphony_rate = 0;
-               break;
+            break;
 
-    #ifdef AUDIO_VOICES
+#ifdef AUDIO_VOICES
 
         case something:
-            glissando = false;
+            glissando      = false;
             polyphony_rate = 0;
             switch (compensated_index) {
                 case 0 ... 9:
@@ -74,25 +67,23 @@ float voice_envelope(float frequency) {
             break;
 
         case drums:
-            glissando = false;
+            glissando      = false;
             polyphony_rate = 0;
-                // switch (compensated_index) {
-                //     case 0 ... 10:
-                //         note_timbre = 0.5;
-                //         break;
-                //     case 11 ... 20:
-                //         note_timbre = 0.5 * (21 - compensated_index) / 10;
-                //         break;
-                //     default:
-                //         note_timbre = 0;
-                //         break;
-                // }
-                // frequency = (rand() % (int)(frequency * 1.2 - frequency)) + (frequency * 0.8);
+            // switch (compensated_index) {
+            //     case 0 ... 10:
+            //         note_timbre = 0.5;
+            //         break;
+            //     case 11 ... 20:
+            //         note_timbre = 0.5 * (21 - compensated_index) / 10;
+            //         break;
+            //     default:
+            //         note_timbre = 0;
+            //         break;
+            // }
+            // frequency = (rand() % (int)(frequency * 1.2 - frequency)) + (frequency * 0.8);
 
             if (frequency < 80.0) {
-
             } else if (frequency < 160.0) {
-
                 // Bass drum: 60 - 100 Hz
                 frequency = (rand() % (int)(40)) + 60;
                 switch (envelope_index) {
@@ -108,8 +99,6 @@ float voice_envelope(float frequency) {
                 }
 
             } else if (frequency < 320.0) {
-
-
                 // Snare drum: 1 - 2 KHz
                 frequency = (rand() % (int)(1000)) + 1000;
                 switch (envelope_index) {
@@ -125,7 +114,6 @@ float voice_envelope(float frequency) {
                 }
 
             } else if (frequency < 640.0) {
-
                 // Closed Hi-hat: 3 - 5 KHz
                 frequency = (rand() % (int)(2000)) + 3000;
                 switch (envelope_index) {
@@ -141,7 +129,6 @@ float voice_envelope(float frequency) {
                 }
 
             } else if (frequency < 1280.0) {
-
                 // Open Hi-hat: 3 - 5 KHz
                 frequency = (rand() % (int)(2000)) + 3000;
                 switch (envelope_index) {
@@ -155,141 +142,138 @@ float voice_envelope(float frequency) {
                         note_timbre = 0;
                         break;
                 }
-
             }
             break;
         case butts_fader:
-            glissando = true;
+            glissando      = true;
             polyphony_rate = 0;
             switch (compensated_index) {
                 case 0 ... 9:
-                    frequency = frequency / 4;
+                    frequency   = frequency / 4;
                     note_timbre = TIMBRE_12;
-                       break;
+                    break;
 
                 case 10 ... 19:
-                    frequency = frequency / 2;
+                    frequency   = frequency / 2;
                     note_timbre = TIMBRE_12;
-                       break;
+                    break;
 
                 case 20 ... 200:
-                    note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125;
-                       break;
+                    note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2) * .125;
+                    break;
 
                 default:
                     note_timbre = 0;
-                       break;
+                    break;
             }
-           break;
-
-        // case octave_crunch:
-        //     polyphony_rate = 0;
-        //     switch (compensated_index) {
-        //         case 0 ... 9:
-        //         case 20 ... 24:
-        //         case 30 ... 32:
-        //             frequency = frequency / 2;
-        //             note_timbre = TIMBRE_12;
-        //         break;
-
-        //         case 10 ... 19:
-        //         case 25 ... 29:
-        //         case 33 ... 35:
-        //             frequency = frequency * 2;
-        //             note_timbre = TIMBRE_12;
-              //          break;
+            break;
 
-        //         default:
-        //             note_timbre = TIMBRE_12;
-        //             break;
-        //     }
-              //  break;
+            // case octave_crunch:
+            //     polyphony_rate = 0;
+            //     switch (compensated_index) {
+            //         case 0 ... 9:
+            //         case 20 ... 24:
+            //         case 30 ... 32:
+            //             frequency = frequency / 2;
+            //             note_timbre = TIMBRE_12;
+            //         break;
+
+            //         case 10 ... 19:
+            //         case 25 ... 29:
+            //         case 33 ... 35:
+            //             frequency = frequency * 2;
+            //             note_timbre = TIMBRE_12;
+            //          break;
+
+            //         default:
+            //             note_timbre = TIMBRE_12;
+            //                 break;
+            //     }
+            //  break;
 
         case duty_osc:
             // This slows the loop down a substantial amount, so higher notes may freeze
-            glissando = true;
+            glissando      = true;
             polyphony_rate = 0;
             switch (compensated_index) {
                 default:
-                    #define OCS_SPEED 10
-                    #define OCS_AMP   .25
+#    define OCS_SPEED 10
+#    define OCS_AMP .25
                     // sine wave is slow
                     // note_timbre = (sin((float)compensated_index/10000*OCS_SPEED) * OCS_AMP / 2) + .5;
                     // triangle wave is a bit faster
-                    note_timbre = (float)abs((compensated_index*OCS_SPEED % 3000) - 1500) * ( OCS_AMP / 1500 ) + (1 - OCS_AMP) / 2;
-                       break;
+                    note_timbre = (float)abs((compensated_index * OCS_SPEED % 3000) - 1500) * (OCS_AMP / 1500) + (1 - OCS_AMP) / 2;
+                    break;
             }
-               break;
+            break;
 
         case duty_octave_down:
-            glissando = true;
+            glissando      = true;
             polyphony_rate = 0;
-            note_timbre = (envelope_index % 2) * .125 + .375 * 2;
-            if ((envelope_index % 4) == 0)
-                note_timbre = 0.5;
-            if ((envelope_index % 8) == 0)
-                note_timbre = 0;
+            note_timbre    = (envelope_index % 2) * .125 + .375 * 2;
+            if ((envelope_index % 4) == 0) note_timbre = 0.5;
+            if ((envelope_index % 8) == 0) note_timbre = 0;
             break;
         case delayed_vibrato:
-            glissando = true;
+            glissando      = true;
             polyphony_rate = 0;
-            note_timbre = TIMBRE_50;
-            #define VOICE_VIBRATO_DELAY 150
-            #define VOICE_VIBRATO_SPEED 50
+            note_timbre    = TIMBRE_50;
+#    define VOICE_VIBRATO_DELAY 150
+#    define VOICE_VIBRATO_SPEED 50
             switch (compensated_index) {
                 case 0 ... VOICE_VIBRATO_DELAY:
                     break;
                 default:
-                    frequency = frequency * vibrato_lut[(int)fmod((((float)compensated_index - (VOICE_VIBRATO_DELAY + 1))/1000*VOICE_VIBRATO_SPEED), VIBRATO_LUT_LENGTH)];
+                    frequency = frequency * vibrato_lut[(int)fmod((((float)compensated_index - (VOICE_VIBRATO_DELAY + 1)) / 1000 * VOICE_VIBRATO_SPEED), VIBRATO_LUT_LENGTH)];
                     break;
             }
             break;
-        // case delayed_vibrato_octave:
-        //     polyphony_rate = 0;
-        //     if ((envelope_index % 2) == 1) {
-        //         note_timbre = 0.55;
-        //     } else {
-        //         note_timbre = 0.45;
-        //     }
-        //     #define VOICE_VIBRATO_DELAY 150
-        //     #define VOICE_VIBRATO_SPEED 50
-        //     switch (compensated_index) {
-        //         case 0 ... VOICE_VIBRATO_DELAY:
-        //             break;
-        //         default:
-        //             frequency = frequency * VIBRATO_LUT[(int)fmod((((float)compensated_index - (VOICE_VIBRATO_DELAY + 1))/1000*VOICE_VIBRATO_SPEED), VIBRATO_LUT_LENGTH)];
-        //             break;
-        //     }
-        //     break;
-        // case duty_fifth_down:
-        //     note_timbre = 0.5;
-        //     if ((envelope_index % 3) == 0)
-        //         note_timbre = 0.75;
-        //     break;
-        // case duty_fourth_down:
-        //     note_timbre = 0.0;
-        //     if ((envelope_index % 12) == 0)
-        //         note_timbre = 0.75;
-        //     if (((envelope_index % 12) % 4) != 1)
-        //         note_timbre = 0.75;
-        //     break;
-        // case duty_third_down:
-        //     note_timbre = 0.5;
-        //     if ((envelope_index % 5) == 0)
-        //         note_timbre = 0.75;
-        //     break;
-        // case duty_fifth_third_down:
-        //     note_timbre = 0.5;
-        //     if ((envelope_index % 5) == 0)
-        //         note_timbre = 0.75;
-        //     if ((envelope_index % 3) == 0)
-        //         note_timbre = 0.25;
-        //     break;
-
-    #endif
-
-               default:
-                       break;
+            // case delayed_vibrato_octave:
+            //     polyphony_rate = 0;
+            //     if ((envelope_index % 2) == 1) {
+            //         note_timbre = 0.55;
+            //     } else {
+            //         note_timbre = 0.45;
+            //     }
+            //     #define VOICE_VIBRATO_DELAY 150
+            //     #define VOICE_VIBRATO_SPEED 50
+            //     switch (compensated_index) {
+            //         case 0 ... VOICE_VIBRATO_DELAY:
+            //             break;
+            //         default:
+            //             frequency = frequency * VIBRATO_LUT[(int)fmod((((float)compensated_index - (VOICE_VIBRATO_DELAY + 1))/1000*VOICE_VIBRATO_SPEED), VIBRATO_LUT_LENGTH)];
+            //             break;
+            //     }
+            //     break;
+            // case duty_fifth_down:
+            //     note_timbre = 0.5;
+            //     if ((envelope_index % 3) == 0)
+            //         note_timbre = 0.75;
+            //     break;
+            // case duty_fourth_down:
+            //     note_timbre = 0.0;
+            //     if ((envelope_index % 12) == 0)
+            //         note_timbre = 0.75;
+            //     if (((envelope_index % 12) % 4) != 1)
+            //         note_timbre = 0.75;
+            //     break;
+            // case duty_third_down:
+            //     note_timbre = 0.5;
+            //     if ((envelope_index % 5) == 0)
+            //         note_timbre = 0.75;
+            //     break;
+            // case duty_fifth_third_down:
+            //     note_timbre = 0.5;
+            //     if ((envelope_index % 5) == 0)
+            //         note_timbre = 0.75;
+            //     if ((envelope_index % 3) == 0)
+            //         note_timbre = 0.25;
+            //     break;
+
+#endif
+
+        default:
+            break;
     }
 
     return frequency;
index 1cf33095a436a95beeb4530ab9d27619f6a2b1c1..0c45b0720e8c90276e5613e44cfa8d93a89ebc95 100644 (file)
 #include <stdint.h>
 #include <stdbool.h>
 #if defined(__AVR__)
-    #include <avr/io.h>
+#    include <avr/io.h>
 #endif
 #include "wait.h"
 #include "luts.h"
 
 #ifndef VOICES_H
-#define VOICES_H
+#    define VOICES_H
 
 float voice_envelope(float frequency);
 
 typedef enum {
     default_voice,
-    #ifdef AUDIO_VOICES
+#    ifdef AUDIO_VOICES
     something,
     drums,
     butts_fader,
@@ -36,13 +36,13 @@ typedef enum {
     duty_osc,
     duty_octave_down,
     delayed_vibrato,
-    // delayed_vibrato_octave,
-    // duty_fifth_down,
-    // duty_fourth_down,
-    // duty_third_down,
-    // duty_fifth_third_down,
-    #endif
-    number_of_voices // important that this is last
+// delayed_vibrato_octave,
+// duty_fifth_down,
+// duty_fourth_down,
+// duty_third_down,
+// duty_fifth_third_down,
+#    endif
+    number_of_voices  // important that this is last
 } voice_type;
 
 void set_voice(voice_type v);
index f15615dd1ba8974cf2ccd5e0c5bf65b8e21a65b8..48210a944e813457b773d7593e687c5fb10ee2ac 100644 (file)
 
 #define SINE_LENGTH 2048
 
-const uint8_t sinewave[] PROGMEM= //2048 values
-{
-0x80,0x80,0x80,0x81,0x81,0x81,0x82,0x82,
-0x83,0x83,0x83,0x84,0x84,0x85,0x85,0x85,
-0x86,0x86,0x87,0x87,0x87,0x88,0x88,0x88,
-0x89,0x89,0x8a,0x8a,0x8a,0x8b,0x8b,0x8c,
-0x8c,0x8c,0x8d,0x8d,0x8e,0x8e,0x8e,0x8f,
-0x8f,0x8f,0x90,0x90,0x91,0x91,0x91,0x92,
-0x92,0x93,0x93,0x93,0x94,0x94,0x95,0x95,
-0x95,0x96,0x96,0x96,0x97,0x97,0x98,0x98,
-0x98,0x99,0x99,0x9a,0x9a,0x9a,0x9b,0x9b,
-0x9b,0x9c,0x9c,0x9d,0x9d,0x9d,0x9e,0x9e,
-0x9e,0x9f,0x9f,0xa0,0xa0,0xa0,0xa1,0xa1,
-0xa2,0xa2,0xa2,0xa3,0xa3,0xa3,0xa4,0xa4,
-0xa5,0xa5,0xa5,0xa6,0xa6,0xa6,0xa7,0xa7,
-0xa7,0xa8,0xa8,0xa9,0xa9,0xa9,0xaa,0xaa,
-0xaa,0xab,0xab,0xac,0xac,0xac,0xad,0xad,
-0xad,0xae,0xae,0xae,0xaf,0xaf,0xb0,0xb0,
-0xb0,0xb1,0xb1,0xb1,0xb2,0xb2,0xb2,0xb3,
-0xb3,0xb4,0xb4,0xb4,0xb5,0xb5,0xb5,0xb6,
-0xb6,0xb6,0xb7,0xb7,0xb7,0xb8,0xb8,0xb8,
-0xb9,0xb9,0xba,0xba,0xba,0xbb,0xbb,0xbb,
-0xbc,0xbc,0xbc,0xbd,0xbd,0xbd,0xbe,0xbe,
-0xbe,0xbf,0xbf,0xbf,0xc0,0xc0,0xc0,0xc1,
-0xc1,0xc1,0xc2,0xc2,0xc2,0xc3,0xc3,0xc3,
-0xc4,0xc4,0xc4,0xc5,0xc5,0xc5,0xc6,0xc6,
-0xc6,0xc7,0xc7,0xc7,0xc8,0xc8,0xc8,0xc9,
-0xc9,0xc9,0xca,0xca,0xca,0xcb,0xcb,0xcb,
-0xcb,0xcc,0xcc,0xcc,0xcd,0xcd,0xcd,0xce,
-0xce,0xce,0xcf,0xcf,0xcf,0xcf,0xd0,0xd0,
-0xd0,0xd1,0xd1,0xd1,0xd2,0xd2,0xd2,0xd2,
-0xd3,0xd3,0xd3,0xd4,0xd4,0xd4,0xd5,0xd5,
-0xd5,0xd5,0xd6,0xd6,0xd6,0xd7,0xd7,0xd7,
-0xd7,0xd8,0xd8,0xd8,0xd9,0xd9,0xd9,0xd9,
-0xda,0xda,0xda,0xda,0xdb,0xdb,0xdb,0xdc,
-0xdc,0xdc,0xdc,0xdd,0xdd,0xdd,0xdd,0xde,
-0xde,0xde,0xde,0xdf,0xdf,0xdf,0xe0,0xe0,
-0xe0,0xe0,0xe1,0xe1,0xe1,0xe1,0xe2,0xe2,
-0xe2,0xe2,0xe3,0xe3,0xe3,0xe3,0xe4,0xe4,
-0xe4,0xe4,0xe4,0xe5,0xe5,0xe5,0xe5,0xe6,
-0xe6,0xe6,0xe6,0xe7,0xe7,0xe7,0xe7,0xe8,
-0xe8,0xe8,0xe8,0xe8,0xe9,0xe9,0xe9,0xe9,
-0xea,0xea,0xea,0xea,0xea,0xeb,0xeb,0xeb,
-0xeb,0xeb,0xec,0xec,0xec,0xec,0xec,0xed,
-0xed,0xed,0xed,0xed,0xee,0xee,0xee,0xee,
-0xee,0xef,0xef,0xef,0xef,0xef,0xf0,0xf0,
-0xf0,0xf0,0xf0,0xf0,0xf1,0xf1,0xf1,0xf1,
-0xf1,0xf2,0xf2,0xf2,0xf2,0xf2,0xf2,0xf3,
-0xf3,0xf3,0xf3,0xf3,0xf3,0xf4,0xf4,0xf4,
-0xf4,0xf4,0xf4,0xf5,0xf5,0xf5,0xf5,0xf5,
-0xf5,0xf5,0xf6,0xf6,0xf6,0xf6,0xf6,0xf6,
-0xf6,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,
-0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,
-0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,
-0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,
-0xfa,0xfa,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,
-0xfb,0xfb,0xfb,0xfb,0xfc,0xfc,0xfc,0xfc,
-0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,
-0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,
-0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfe,0xfe,
-0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,
-0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,
-0xfe,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,
-0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,
-0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,
-0xfe,0xfe,0xfe,0xfd,0xfd,0xfd,0xfd,0xfd,
-0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,
-0xfd,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,
-0xfc,0xfc,0xfc,0xfc,0xfc,0xfb,0xfb,0xfb,
-0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfa,
-0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,
-0xfa,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,
-0xf9,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,
-0xf8,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,
-0xf6,0xf6,0xf6,0xf6,0xf6,0xf6,0xf6,0xf5,
-0xf5,0xf5,0xf5,0xf5,0xf5,0xf5,0xf4,0xf4,
-0xf4,0xf4,0xf4,0xf4,0xf3,0xf3,0xf3,0xf3,
-0xf3,0xf3,0xf2,0xf2,0xf2,0xf2,0xf2,0xf2,
-0xf1,0xf1,0xf1,0xf1,0xf1,0xf0,0xf0,0xf0,
-0xf0,0xf0,0xf0,0xef,0xef,0xef,0xef,0xef,
-0xee,0xee,0xee,0xee,0xee,0xed,0xed,0xed,
-0xed,0xed,0xec,0xec,0xec,0xec,0xec,0xeb,
-0xeb,0xeb,0xeb,0xeb,0xea,0xea,0xea,0xea,
-0xea,0xe9,0xe9,0xe9,0xe9,0xe8,0xe8,0xe8,
-0xe8,0xe8,0xe7,0xe7,0xe7,0xe7,0xe6,0xe6,
-0xe6,0xe6,0xe5,0xe5,0xe5,0xe5,0xe4,0xe4,
-0xe4,0xe4,0xe4,0xe3,0xe3,0xe3,0xe3,0xe2,
-0xe2,0xe2,0xe2,0xe1,0xe1,0xe1,0xe1,0xe0,
-0xe0,0xe0,0xe0,0xdf,0xdf,0xdf,0xde,0xde,
-0xde,0xde,0xdd,0xdd,0xdd,0xdd,0xdc,0xdc,
-0xdc,0xdc,0xdb,0xdb,0xdb,0xda,0xda,0xda,
-0xda,0xd9,0xd9,0xd9,0xd9,0xd8,0xd8,0xd8,
-0xd7,0xd7,0xd7,0xd7,0xd6,0xd6,0xd6,0xd5,
-0xd5,0xd5,0xd5,0xd4,0xd4,0xd4,0xd3,0xd3,
-0xd3,0xd2,0xd2,0xd2,0xd2,0xd1,0xd1,0xd1,
-0xd0,0xd0,0xd0,0xcf,0xcf,0xcf,0xcf,0xce,
-0xce,0xce,0xcd,0xcd,0xcd,0xcc,0xcc,0xcc,
-0xcb,0xcb,0xcb,0xcb,0xca,0xca,0xca,0xc9,
-0xc9,0xc9,0xc8,0xc8,0xc8,0xc7,0xc7,0xc7,
-0xc6,0xc6,0xc6,0xc5,0xc5,0xc5,0xc4,0xc4,
-0xc4,0xc3,0xc3,0xc3,0xc2,0xc2,0xc2,0xc1,
-0xc1,0xc1,0xc0,0xc0,0xc0,0xbf,0xbf,0xbf,
-0xbe,0xbe,0xbe,0xbd,0xbd,0xbd,0xbc,0xbc,
-0xbc,0xbb,0xbb,0xbb,0xba,0xba,0xba,0xb9,
-0xb9,0xb8,0xb8,0xb8,0xb7,0xb7,0xb7,0xb6,
-0xb6,0xb6,0xb5,0xb5,0xb5,0xb4,0xb4,0xb4,
-0xb3,0xb3,0xb2,0xb2,0xb2,0xb1,0xb1,0xb1,
-0xb0,0xb0,0xb0,0xaf,0xaf,0xae,0xae,0xae,
-0xad,0xad,0xad,0xac,0xac,0xac,0xab,0xab,
-0xaa,0xaa,0xaa,0xa9,0xa9,0xa9,0xa8,0xa8,
-0xa7,0xa7,0xa7,0xa6,0xa6,0xa6,0xa5,0xa5,
-0xa5,0xa4,0xa4,0xa3,0xa3,0xa3,0xa2,0xa2,
-0xa2,0xa1,0xa1,0xa0,0xa0,0xa0,0x9f,0x9f,
-0x9e,0x9e,0x9e,0x9d,0x9d,0x9d,0x9c,0x9c,
-0x9b,0x9b,0x9b,0x9a,0x9a,0x9a,0x99,0x99,
-0x98,0x98,0x98,0x97,0x97,0x96,0x96,0x96,
-0x95,0x95,0x95,0x94,0x94,0x93,0x93,0x93,
-0x92,0x92,0x91,0x91,0x91,0x90,0x90,0x8f,
-0x8f,0x8f,0x8e,0x8e,0x8e,0x8d,0x8d,0x8c,
-0x8c,0x8c,0x8b,0x8b,0x8a,0x8a,0x8a,0x89,
-0x89,0x88,0x88,0x88,0x87,0x87,0x87,0x86,
-0x86,0x85,0x85,0x85,0x84,0x84,0x83,0x83,
-0x83,0x82,0x82,0x81,0x81,0x81,0x80,0x80,
-0x80,0x7f,0x7f,0x7e,0x7e,0x7e,0x7d,0x7d,
-0x7c,0x7c,0x7c,0x7b,0x7b,0x7a,0x7a,0x7a,
-0x79,0x79,0x78,0x78,0x78,0x77,0x77,0x77,
-0x76,0x76,0x75,0x75,0x75,0x74,0x74,0x73,
-0x73,0x73,0x72,0x72,0x71,0x71,0x71,0x70,
-0x70,0x70,0x6f,0x6f,0x6e,0x6e,0x6e,0x6d,
-0x6d,0x6c,0x6c,0x6c,0x6b,0x6b,0x6a,0x6a,
-0x6a,0x69,0x69,0x69,0x68,0x68,0x67,0x67,
-0x67,0x66,0x66,0x65,0x65,0x65,0x64,0x64,
-0x64,0x63,0x63,0x62,0x62,0x62,0x61,0x61,
-0x61,0x60,0x60,0x5f,0x5f,0x5f,0x5e,0x5e,
-0x5d,0x5d,0x5d,0x5c,0x5c,0x5c,0x5b,0x5b,
-0x5a,0x5a,0x5a,0x59,0x59,0x59,0x58,0x58,
-0x58,0x57,0x57,0x56,0x56,0x56,0x55,0x55,
-0x55,0x54,0x54,0x53,0x53,0x53,0x52,0x52,
-0x52,0x51,0x51,0x51,0x50,0x50,0x4f,0x4f,
-0x4f,0x4e,0x4e,0x4e,0x4d,0x4d,0x4d,0x4c,
-0x4c,0x4b,0x4b,0x4b,0x4a,0x4a,0x4a,0x49,
-0x49,0x49,0x48,0x48,0x48,0x47,0x47,0x47,
-0x46,0x46,0x45,0x45,0x45,0x44,0x44,0x44,
-0x43,0x43,0x43,0x42,0x42,0x42,0x41,0x41,
-0x41,0x40,0x40,0x40,0x3f,0x3f,0x3f,0x3e,
-0x3e,0x3e,0x3d,0x3d,0x3d,0x3c,0x3c,0x3c,
-0x3b,0x3b,0x3b,0x3a,0x3a,0x3a,0x39,0x39,
-0x39,0x38,0x38,0x38,0x37,0x37,0x37,0x36,
-0x36,0x36,0x35,0x35,0x35,0x34,0x34,0x34,
-0x34,0x33,0x33,0x33,0x32,0x32,0x32,0x31,
-0x31,0x31,0x30,0x30,0x30,0x30,0x2f,0x2f,
-0x2f,0x2e,0x2e,0x2e,0x2d,0x2d,0x2d,0x2d,
-0x2c,0x2c,0x2c,0x2b,0x2b,0x2b,0x2a,0x2a,
-0x2a,0x2a,0x29,0x29,0x29,0x28,0x28,0x28,
-0x28,0x27,0x27,0x27,0x26,0x26,0x26,0x26,
-0x25,0x25,0x25,0x25,0x24,0x24,0x24,0x23,
-0x23,0x23,0x23,0x22,0x22,0x22,0x22,0x21,
-0x21,0x21,0x21,0x20,0x20,0x20,0x1f,0x1f,
-0x1f,0x1f,0x1e,0x1e,0x1e,0x1e,0x1d,0x1d,
-0x1d,0x1d,0x1c,0x1c,0x1c,0x1c,0x1b,0x1b,
-0x1b,0x1b,0x1b,0x1a,0x1a,0x1a,0x1a,0x19,
-0x19,0x19,0x19,0x18,0x18,0x18,0x18,0x17,
-0x17,0x17,0x17,0x17,0x16,0x16,0x16,0x16,
-0x15,0x15,0x15,0x15,0x15,0x14,0x14,0x14,
-0x14,0x14,0x13,0x13,0x13,0x13,0x13,0x12,
-0x12,0x12,0x12,0x12,0x11,0x11,0x11,0x11,
-0x11,0x10,0x10,0x10,0x10,0x10,0xf,0xf,
-0xf,0xf,0xf,0xf,0xe,0xe,0xe,0xe,
-0xe,0xd,0xd,0xd,0xd,0xd,0xd,0xc,
-0xc,0xc,0xc,0xc,0xc,0xb,0xb,0xb,
-0xb,0xb,0xb,0xa,0xa,0xa,0xa,0xa,
-0xa,0xa,0x9,0x9,0x9,0x9,0x9,0x9,
-0x9,0x8,0x8,0x8,0x8,0x8,0x8,0x8,
-0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x7,
-0x6,0x6,0x6,0x6,0x6,0x6,0x6,0x6,
-0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,
-0x5,0x5,0x4,0x4,0x4,0x4,0x4,0x4,
-0x4,0x4,0x4,0x4,0x3,0x3,0x3,0x3,
-0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,
-0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,
-0x2,0x2,0x2,0x2,0x2,0x2,0x1,0x1,
-0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,
-0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,
-0x1,0x1,0x1,0x1,0x0,0x0,0x0,0x0,
-0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
-0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
-0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
-0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
-0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
-0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
-0x0,0x0,0x0,0x0,0x0,0x1,0x1,0x1,
-0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,
-0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,
-0x1,0x1,0x1,0x2,0x2,0x2,0x2,0x2,
-0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,
-0x2,0x3,0x3,0x3,0x3,0x3,0x3,0x3,
-0x3,0x3,0x3,0x3,0x3,0x4,0x4,0x4,
-0x4,0x4,0x4,0x4,0x4,0x4,0x4,0x5,
-0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,
-0x5,0x6,0x6,0x6,0x6,0x6,0x6,0x6,
-0x6,0x7,0x7,0x7,0x7,0x7,0x7,0x7,
-0x7,0x8,0x8,0x8,0x8,0x8,0x8,0x8,
-0x9,0x9,0x9,0x9,0x9,0x9,0x9,0xa,
-0xa,0xa,0xa,0xa,0xa,0xa,0xb,0xb,
-0xb,0xb,0xb,0xb,0xc,0xc,0xc,0xc,
-0xc,0xc,0xd,0xd,0xd,0xd,0xd,0xd,
-0xe,0xe,0xe,0xe,0xe,0xf,0xf,0xf,
-0xf,0xf,0xf,0x10,0x10,0x10,0x10,0x10,
-0x11,0x11,0x11,0x11,0x11,0x12,0x12,0x12,
-0x12,0x12,0x13,0x13,0x13,0x13,0x13,0x14,
-0x14,0x14,0x14,0x14,0x15,0x15,0x15,0x15,
-0x15,0x16,0x16,0x16,0x16,0x17,0x17,0x17,
-0x17,0x17,0x18,0x18,0x18,0x18,0x19,0x19,
-0x19,0x19,0x1a,0x1a,0x1a,0x1a,0x1b,0x1b,
-0x1b,0x1b,0x1b,0x1c,0x1c,0x1c,0x1c,0x1d,
-0x1d,0x1d,0x1d,0x1e,0x1e,0x1e,0x1e,0x1f,
-0x1f,0x1f,0x1f,0x20,0x20,0x20,0x21,0x21,
-0x21,0x21,0x22,0x22,0x22,0x22,0x23,0x23,
-0x23,0x23,0x24,0x24,0x24,0x25,0x25,0x25,
-0x25,0x26,0x26,0x26,0x26,0x27,0x27,0x27,
-0x28,0x28,0x28,0x28,0x29,0x29,0x29,0x2a,
-0x2a,0x2a,0x2a,0x2b,0x2b,0x2b,0x2c,0x2c,
-0x2c,0x2d,0x2d,0x2d,0x2d,0x2e,0x2e,0x2e,
-0x2f,0x2f,0x2f,0x30,0x30,0x30,0x30,0x31,
-0x31,0x31,0x32,0x32,0x32,0x33,0x33,0x33,
-0x34,0x34,0x34,0x34,0x35,0x35,0x35,0x36,
-0x36,0x36,0x37,0x37,0x37,0x38,0x38,0x38,
-0x39,0x39,0x39,0x3a,0x3a,0x3a,0x3b,0x3b,
-0x3b,0x3c,0x3c,0x3c,0x3d,0x3d,0x3d,0x3e,
-0x3e,0x3e,0x3f,0x3f,0x3f,0x40,0x40,0x40,
-0x41,0x41,0x41,0x42,0x42,0x42,0x43,0x43,
-0x43,0x44,0x44,0x44,0x45,0x45,0x45,0x46,
-0x46,0x47,0x47,0x47,0x48,0x48,0x48,0x49,
-0x49,0x49,0x4a,0x4a,0x4a,0x4b,0x4b,0x4b,
-0x4c,0x4c,0x4d,0x4d,0x4d,0x4e,0x4e,0x4e,
-0x4f,0x4f,0x4f,0x50,0x50,0x51,0x51,0x51,
-0x52,0x52,0x52,0x53,0x53,0x53,0x54,0x54,
-0x55,0x55,0x55,0x56,0x56,0x56,0x57,0x57,
-0x58,0x58,0x58,0x59,0x59,0x59,0x5a,0x5a,
-0x5a,0x5b,0x5b,0x5c,0x5c,0x5c,0x5d,0x5d,
-0x5d,0x5e,0x5e,0x5f,0x5f,0x5f,0x60,0x60,
-0x61,0x61,0x61,0x62,0x62,0x62,0x63,0x63,
-0x64,0x64,0x64,0x65,0x65,0x65,0x66,0x66,
-0x67,0x67,0x67,0x68,0x68,0x69,0x69,0x69,
-0x6a,0x6a,0x6a,0x6b,0x6b,0x6c,0x6c,0x6c,
-0x6d,0x6d,0x6e,0x6e,0x6e,0x6f,0x6f,0x70,
-0x70,0x70,0x71,0x71,0x71,0x72,0x72,0x73,
-0x73,0x73,0x74,0x74,0x75,0x75,0x75,0x76,
-0x76,0x77,0x77,0x77,0x78,0x78,0x78,0x79,
-0x79,0x7a,0x7a,0x7a,0x7b,0x7b,0x7c,0x7c,
-0x7c,0x7d,0x7d,0x7e,0x7e,0x7e,0x7f,0x7f
-};
+const uint8_t sinewave[] PROGMEM =  // 2048 values
+    {0x80, 0x80, 0x80, 0x81, 0x81, 0x81, 0x82, 0x82, 0x83, 0x83, 0x83, 0x84, 0x84, 0x85, 0x85, 0x85, 0x86, 0x86, 0x87, 0x87, 0x87, 0x88, 0x88, 0x88, 0x89, 0x89, 0x8a, 0x8a, 0x8a, 0x8b, 0x8b, 0x8c, 0x8c, 0x8c, 0x8d, 0x8d, 0x8e, 0x8e, 0x8e, 0x8f, 0x8f, 0x8f, 0x90, 0x90, 0x91, 0x91, 0x91, 0x92, 0x92, 0x93, 0x93, 0x93, 0x94, 0x94, 0x95, 0x95, 0x95, 0x96, 0x96, 0x96, 0x97, 0x97, 0x98, 0x98, 0x98, 0x99, 0x99, 0x9a, 0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c, 0x9d, 0x9d, 0x9d, 0x9e, 0x9e, 0x9e, 0x9f, 0x9f, 0xa0, 0xa0, 0xa0, 0xa1, 0xa1, 0xa2, 0xa2, 0xa2, 0xa3, 0xa3, 0xa3, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5, 0xa6, 0xa6, 0xa6, 0xa7, 0xa7, 0xa7, 0xa8, 0xa8, 0xa9, 0xa9, 0xa9, 0xaa, 0xaa, 0xaa, 0xab, 0xab, 0xac, 0xac, 0xac, 0xad, 0xad, 0xad, 0xae, 0xae, 0xae, 0xaf, 0xaf, 0xb0, 0xb0, 0xb0, 0xb1, 0xb1, 0xb1, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb4, 0xb5, 0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xbb,
+     0xbb, 0xbb, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf, 0xc0, 0xc0, 0xc0, 0xc1, 0xc1, 0xc1, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc5, 0xc5, 0xc5, 0xc6, 0xc6, 0xc6, 0xc7, 0xc7, 0xc7, 0xc8, 0xc8, 0xc8, 0xc9, 0xc9, 0xc9, 0xca, 0xca, 0xca, 0xcb, 0xcb, 0xcb, 0xcb, 0xcc, 0xcc, 0xcc, 0xcd, 0xcd, 0xcd, 0xce, 0xce, 0xce, 0xcf, 0xcf, 0xcf, 0xcf, 0xd0, 0xd0, 0xd0, 0xd1, 0xd1, 0xd1, 0xd2, 0xd2, 0xd2, 0xd2, 0xd3, 0xd3, 0xd3, 0xd4, 0xd4, 0xd4, 0xd5, 0xd5, 0xd5, 0xd5, 0xd6, 0xd6, 0xd6, 0xd7, 0xd7, 0xd7, 0xd7, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9, 0xd9, 0xd9, 0xda, 0xda, 0xda, 0xda, 0xdb, 0xdb, 0xdb, 0xdc, 0xdc, 0xdc, 0xdc, 0xdd, 0xdd, 0xdd, 0xdd, 0xde, 0xde, 0xde, 0xde, 0xdf, 0xdf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe1, 0xe1, 0xe1, 0xe1, 0xe2, 0xe2, 0xe2, 0xe2, 0xe3, 0xe3, 0xe3, 0xe3, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe5, 0xe5, 0xe5, 0xe5, 0xe6, 0xe6, 0xe6, 0xe6, 0xe7, 0xe7, 0xe7, 0xe7, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8,
+     0xe9, 0xe9, 0xe9, 0xe9, 0xea, 0xea, 0xea, 0xea, 0xea, 0xeb, 0xeb, 0xeb, 0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec, 0xec, 0xed, 0xed, 0xed, 0xed, 0xed, 0xee, 0xee, 0xee, 0xee, 0xee, 0xef, 0xef, 0xef, 0xef, 0xef, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
+     0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+     0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xef, 0xef, 0xef, 0xef, 0xef, 0xee, 0xee, 0xee, 0xee, 0xee, 0xed, 0xed, 0xed, 0xed, 0xed, 0xec, 0xec, 0xec, 0xec, 0xec, 0xeb, 0xeb, 0xeb, 0xeb, 0xeb, 0xea, 0xea, 0xea, 0xea, 0xea, 0xe9, 0xe9, 0xe9, 0xe9, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe7, 0xe7, 0xe7, 0xe7, 0xe6, 0xe6, 0xe6, 0xe6, 0xe5, 0xe5, 0xe5, 0xe5, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe3, 0xe3, 0xe3, 0xe3, 0xe2, 0xe2, 0xe2, 0xe2, 0xe1, 0xe1, 0xe1, 0xe1, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xdf, 0xdf, 0xde, 0xde, 0xde, 0xde, 0xdd, 0xdd, 0xdd, 0xdd, 0xdc, 0xdc, 0xdc, 0xdc, 0xdb, 0xdb, 0xdb, 0xda, 0xda, 0xda, 0xda, 0xd9, 0xd9, 0xd9, 0xd9, 0xd8, 0xd8, 0xd8, 0xd7, 0xd7, 0xd7, 0xd7, 0xd6, 0xd6, 0xd6, 0xd5, 0xd5, 0xd5, 0xd5, 0xd4, 0xd4, 0xd4,
+     0xd3, 0xd3, 0xd3, 0xd2, 0xd2, 0xd2, 0xd2, 0xd1, 0xd1, 0xd1, 0xd0, 0xd0, 0xd0, 0xcf, 0xcf, 0xcf, 0xcf, 0xce, 0xce, 0xce, 0xcd, 0xcd, 0xcd, 0xcc, 0xcc, 0xcc, 0xcb, 0xcb, 0xcb, 0xcb, 0xca, 0xca, 0xca, 0xc9, 0xc9, 0xc9, 0xc8, 0xc8, 0xc8, 0xc7, 0xc7, 0xc7, 0xc6, 0xc6, 0xc6, 0xc5, 0xc5, 0xc5, 0xc4, 0xc4, 0xc4, 0xc3, 0xc3, 0xc3, 0xc2, 0xc2, 0xc2, 0xc1, 0xc1, 0xc1, 0xc0, 0xc0, 0xc0, 0xbf, 0xbf, 0xbf, 0xbe, 0xbe, 0xbe, 0xbd, 0xbd, 0xbd, 0xbc, 0xbc, 0xbc, 0xbb, 0xbb, 0xbb, 0xba, 0xba, 0xba, 0xb9, 0xb9, 0xb8, 0xb8, 0xb8, 0xb7, 0xb7, 0xb7, 0xb6, 0xb6, 0xb6, 0xb5, 0xb5, 0xb5, 0xb4, 0xb4, 0xb4, 0xb3, 0xb3, 0xb2, 0xb2, 0xb2, 0xb1, 0xb1, 0xb1, 0xb0, 0xb0, 0xb0, 0xaf, 0xaf, 0xae, 0xae, 0xae, 0xad, 0xad, 0xad, 0xac, 0xac, 0xac, 0xab, 0xab, 0xaa, 0xaa, 0xaa, 0xa9, 0xa9, 0xa9, 0xa8, 0xa8, 0xa7, 0xa7, 0xa7, 0xa6, 0xa6, 0xa6, 0xa5, 0xa5, 0xa5, 0xa4, 0xa4, 0xa3, 0xa3, 0xa3, 0xa2, 0xa2, 0xa2, 0xa1, 0xa1, 0xa0, 0xa0, 0xa0, 0x9f, 0x9f, 0x9e, 0x9e, 0x9e, 0x9d,
+     0x9d, 0x9d, 0x9c, 0x9c, 0x9b, 0x9b, 0x9b, 0x9a, 0x9a, 0x9a, 0x99, 0x99, 0x98, 0x98, 0x98, 0x97, 0x97, 0x96, 0x96, 0x96, 0x95, 0x95, 0x95, 0x94, 0x94, 0x93, 0x93, 0x93, 0x92, 0x92, 0x91, 0x91, 0x91, 0x90, 0x90, 0x8f, 0x8f, 0x8f, 0x8e, 0x8e, 0x8e, 0x8d, 0x8d, 0x8c, 0x8c, 0x8c, 0x8b, 0x8b, 0x8a, 0x8a, 0x8a, 0x89, 0x89, 0x88, 0x88, 0x88, 0x87, 0x87, 0x87, 0x86, 0x86, 0x85, 0x85, 0x85, 0x84, 0x84, 0x83, 0x83, 0x83, 0x82, 0x82, 0x81, 0x81, 0x81, 0x80, 0x80, 0x80, 0x7f, 0x7f, 0x7e, 0x7e, 0x7e, 0x7d, 0x7d, 0x7c, 0x7c, 0x7c, 0x7b, 0x7b, 0x7a, 0x7a, 0x7a, 0x79, 0x79, 0x78, 0x78, 0x78, 0x77, 0x77, 0x77, 0x76, 0x76, 0x75, 0x75, 0x75, 0x74, 0x74, 0x73, 0x73, 0x73, 0x72, 0x72, 0x71, 0x71, 0x71, 0x70, 0x70, 0x70, 0x6f, 0x6f, 0x6e, 0x6e, 0x6e, 0x6d, 0x6d, 0x6c, 0x6c, 0x6c, 0x6b, 0x6b, 0x6a, 0x6a, 0x6a, 0x69, 0x69, 0x69, 0x68, 0x68, 0x67, 0x67, 0x67, 0x66, 0x66, 0x65, 0x65, 0x65, 0x64, 0x64, 0x64, 0x63, 0x63, 0x62, 0x62, 0x62, 0x61, 0x61, 0x61, 0x60,
+     0x60, 0x5f, 0x5f, 0x5f, 0x5e, 0x5e, 0x5d, 0x5d, 0x5d, 0x5c, 0x5c, 0x5c, 0x5b, 0x5b, 0x5a, 0x5a, 0x5a, 0x59, 0x59, 0x59, 0x58, 0x58, 0x58, 0x57, 0x57, 0x56, 0x56, 0x56, 0x55, 0x55, 0x55, 0x54, 0x54, 0x53, 0x53, 0x53, 0x52, 0x52, 0x52, 0x51, 0x51, 0x51, 0x50, 0x50, 0x4f, 0x4f, 0x4f, 0x4e, 0x4e, 0x4e, 0x4d, 0x4d, 0x4d, 0x4c, 0x4c, 0x4b, 0x4b, 0x4b, 0x4a, 0x4a, 0x4a, 0x49, 0x49, 0x49, 0x48, 0x48, 0x48, 0x47, 0x47, 0x47, 0x46, 0x46, 0x45, 0x45, 0x45, 0x44, 0x44, 0x44, 0x43, 0x43, 0x43, 0x42, 0x42, 0x42, 0x41, 0x41, 0x41, 0x40, 0x40, 0x40, 0x3f, 0x3f, 0x3f, 0x3e, 0x3e, 0x3e, 0x3d, 0x3d, 0x3d, 0x3c, 0x3c, 0x3c, 0x3b, 0x3b, 0x3b, 0x3a, 0x3a, 0x3a, 0x39, 0x39, 0x39, 0x38, 0x38, 0x38, 0x37, 0x37, 0x37, 0x36, 0x36, 0x36, 0x35, 0x35, 0x35, 0x34, 0x34, 0x34, 0x34, 0x33, 0x33, 0x33, 0x32, 0x32, 0x32, 0x31, 0x31, 0x31, 0x30, 0x30, 0x30, 0x30, 0x2f, 0x2f, 0x2f, 0x2e, 0x2e, 0x2e, 0x2d, 0x2d, 0x2d, 0x2d, 0x2c, 0x2c, 0x2c, 0x2b, 0x2b, 0x2b, 0x2a, 0x2a,
+     0x2a, 0x2a, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x27, 0x27, 0x27, 0x26, 0x26, 0x26, 0x26, 0x25, 0x25, 0x25, 0x25, 0x24, 0x24, 0x24, 0x23, 0x23, 0x23, 0x23, 0x22, 0x22, 0x22, 0x22, 0x21, 0x21, 0x21, 0x21, 0x20, 0x20, 0x20, 0x1f, 0x1f, 0x1f, 0x1f, 0x1e, 0x1e, 0x1e, 0x1e, 0x1d, 0x1d, 0x1d, 0x1d, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1a, 0x1a, 0x1a, 0x1a, 0x19, 0x19, 0x19, 0x19, 0x18, 0x18, 0x18, 0x18, 0x17, 0x17, 0x17, 0x17, 0x17, 0x16, 0x16, 0x16, 0x16, 0x15, 0x15, 0x15, 0x15, 0x15, 0x14, 0x14, 0x14, 0x14, 0x14, 0x13, 0x13, 0x13, 0x13, 0x13, 0x12, 0x12, 0x12, 0x12, 0x12, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10, 0x10, 0x10, 0x10, 0x10, 0xf,  0xf,  0xf,  0xf,  0xf,  0xf,  0xe,  0xe,  0xe,  0xe,  0xe,  0xd,  0xd,  0xd,  0xd,  0xd,  0xd,  0xc,  0xc,  0xc,  0xc,  0xc,  0xc,  0xb,  0xb,  0xb,  0xb,  0xb,  0xb,  0xa,  0xa,  0xa,  0xa,  0xa,  0xa,  0xa,  0x9,  0x9,  0x9,  0x9,  0x9,  0x9,  0x9,  0x8,  0x8,  0x8,  0x8,  0x8,
+     0x8,  0x8,  0x7,  0x7,  0x7,  0x7,  0x7,  0x7,  0x7,  0x7,  0x6,  0x6,  0x6,  0x6,  0x6,  0x6,  0x6,  0x6,  0x5,  0x5,  0x5,  0x5,  0x5,  0x5,  0x5,  0x5,  0x5,  0x5,  0x4,  0x4,  0x4,  0x4,  0x4,  0x4,  0x4,  0x4,  0x4,  0x4,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,
+     0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x1,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x2,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x3,  0x4,  0x4,  0x4,  0x4,  0x4,  0x4,  0x4,  0x4,  0x4,  0x4,  0x5,  0x5,  0x5,  0x5,  0x5,  0x5,  0x5,  0x5,  0x5,  0x5,  0x6,  0x6,  0x6,  0x6,  0x6,  0x6,  0x6,  0x6,  0x7,  0x7,  0x7,  0x7,  0x7,  0x7,  0x7,  0x7,  0x8,  0x8,  0x8,  0x8,  0x8,  0x8,  0x8,  0x9,  0x9,  0x9,  0x9,  0x9,  0x9,  0x9,  0xa,  0xa,  0xa,  0xa,  0xa,  0xa,  0xa,  0xb,  0xb,  0xb,  0xb,  0xb,  0xb,  0xc,  0xc,  0xc,  0xc,  0xc,  0xc,  0xd,  0xd,  0xd,  0xd,  0xd,  0xd,  0xe,  0xe,  0xe,  0xe,  0xe,  0xf,  0xf,  0xf,  0xf,  0xf,  0xf,  0x10, 0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11, 0x11, 0x12, 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17, 0x17,
+     0x18, 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x19, 0x1a, 0x1a, 0x1a, 0x1a, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1c, 0x1c, 0x1c, 0x1c, 0x1d, 0x1d, 0x1d, 0x1d, 0x1e, 0x1e, 0x1e, 0x1e, 0x1f, 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x20, 0x21, 0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x22, 0x23, 0x23, 0x23, 0x23, 0x24, 0x24, 0x24, 0x25, 0x25, 0x25, 0x25, 0x26, 0x26, 0x26, 0x26, 0x27, 0x27, 0x27, 0x28, 0x28, 0x28, 0x28, 0x29, 0x29, 0x29, 0x2a, 0x2a, 0x2a, 0x2a, 0x2b, 0x2b, 0x2b, 0x2c, 0x2c, 0x2c, 0x2d, 0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f, 0x2f, 0x30, 0x30, 0x30, 0x30, 0x31, 0x31, 0x31, 0x32, 0x32, 0x32, 0x33, 0x33, 0x33, 0x34, 0x34, 0x34, 0x34, 0x35, 0x35, 0x35, 0x36, 0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x38, 0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3a, 0x3b, 0x3b, 0x3b, 0x3c, 0x3c, 0x3c, 0x3d, 0x3d, 0x3d, 0x3e, 0x3e, 0x3e, 0x3f, 0x3f, 0x3f, 0x40, 0x40, 0x40, 0x41, 0x41, 0x41, 0x42, 0x42, 0x42, 0x43, 0x43, 0x43, 0x44, 0x44, 0x44, 0x45, 0x45, 0x45, 0x46,
+     0x46, 0x47, 0x47, 0x47, 0x48, 0x48, 0x48, 0x49, 0x49, 0x49, 0x4a, 0x4a, 0x4a, 0x4b, 0x4b, 0x4b, 0x4c, 0x4c, 0x4d, 0x4d, 0x4d, 0x4e, 0x4e, 0x4e, 0x4f, 0x4f, 0x4f, 0x50, 0x50, 0x51, 0x51, 0x51, 0x52, 0x52, 0x52, 0x53, 0x53, 0x53, 0x54, 0x54, 0x55, 0x55, 0x55, 0x56, 0x56, 0x56, 0x57, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59, 0x59, 0x5a, 0x5a, 0x5a, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c, 0x5d, 0x5d, 0x5d, 0x5e, 0x5e, 0x5f, 0x5f, 0x5f, 0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62, 0x63, 0x63, 0x64, 0x64, 0x64, 0x65, 0x65, 0x65, 0x66, 0x66, 0x67, 0x67, 0x67, 0x68, 0x68, 0x69, 0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6b, 0x6b, 0x6c, 0x6c, 0x6c, 0x6d, 0x6d, 0x6e, 0x6e, 0x6e, 0x6f, 0x6f, 0x70, 0x70, 0x70, 0x71, 0x71, 0x71, 0x72, 0x72, 0x73, 0x73, 0x73, 0x74, 0x74, 0x75, 0x75, 0x75, 0x76, 0x76, 0x77, 0x77, 0x77, 0x78, 0x78, 0x78, 0x79, 0x79, 0x7a, 0x7a, 0x7a, 0x7b, 0x7b, 0x7c, 0x7c, 0x7c, 0x7d, 0x7d, 0x7e, 0x7e, 0x7e, 0x7f, 0x7f};
index a309da379a41cbefbb1e077a71fa8b1347e69bbd..847129736d521695153d6ab6a721f6510bdd0077 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #include "color.h"
 #include "led_tables.h"
 #include "progmem.h"
 
-RGB hsv_to_rgb( HSV hsv )
-{
-       RGB rgb;
-       uint8_t region, remainder, p, q, t;
-       uint16_t h, s, v;
+RGB hsv_to_rgb(HSV hsv) {
+    RGB      rgb;
+    uint8_t  region, remainder, p, q, t;
+    uint16_t h, s, v;
 
-       if ( hsv.s == 0 )
-       {
+    if (hsv.s == 0) {
 #ifdef USE_CIE1931_CURVE
-               rgb.r = rgb.g = rgb.b = pgm_read_byte( &CIE1931_CURVE[hsv.v] );
+        rgb.r = rgb.g = rgb.b = pgm_read_byte(&CIE1931_CURVE[hsv.v]);
 #else
-               rgb.r = hsv.v;
-               rgb.g = hsv.v;
-               rgb.b = hsv.v;
+        rgb.r = hsv.v;
+        rgb.g = hsv.v;
+        rgb.b = hsv.v;
 #endif
-               return rgb;
-       }
+        return rgb;
+    }
 
-       h = hsv.h;
-       s = hsv.s;
-       v = hsv.v;
+    h = hsv.h;
+    s = hsv.s;
+    v = hsv.v;
 
-       region = h * 6 / 255;
-       remainder = (h * 2 - region * 85) * 3;
+    region    = h * 6 / 255;
+    remainder = (h * 2 - region * 85) * 3;
 
-       p = (v * (255 - s)) >> 8;
-       q = (v * (255 - ((s * remainder) >> 8))) >> 8;
-       t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;
+    p = (v * (255 - s)) >> 8;
+    q = (v * (255 - ((s * remainder) >> 8))) >> 8;
+    t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;
 
-       switch ( region )
-       {
-               case 6:
-               case 0:
-                       rgb.r = v;
-                       rgb.g = t;
-                       rgb.b = p;
-                       break;
-               case 1:
-                       rgb.r = q;
-                       rgb.g = v;
-                       rgb.b = p;
-                       break;
-               case 2:
-                       rgb.r = p;
-                       rgb.g = v;
-                       rgb.b = t;
-                       break;
-               case 3:
-                       rgb.r = p;
-                       rgb.g = q;
-                       rgb.b = v;
-                       break;
-               case 4:
-                       rgb.r = t;
-                       rgb.g = p;
-                       rgb.b = v;
-                       break;
-               default:
-                       rgb.r = v;
-                       rgb.g = p;
-                       rgb.b = q;
-                       break;
-       }
+    switch (region) {
+        case 6:
+        case 0:
+            rgb.r = v;
+            rgb.g = t;
+            rgb.b = p;
+            break;
+        case 1:
+            rgb.r = q;
+            rgb.g = v;
+            rgb.b = p;
+            break;
+        case 2:
+            rgb.r = p;
+            rgb.g = v;
+            rgb.b = t;
+            break;
+        case 3:
+            rgb.r = p;
+            rgb.g = q;
+            rgb.b = v;
+            break;
+        case 4:
+            rgb.r = t;
+            rgb.g = p;
+            rgb.b = v;
+            break;
+        default:
+            rgb.r = v;
+            rgb.g = p;
+            rgb.b = q;
+            break;
+    }
 
 #ifdef USE_CIE1931_CURVE
-       rgb.r = pgm_read_byte( &CIE1931_CURVE[rgb.r] );
-       rgb.g = pgm_read_byte( &CIE1931_CURVE[rgb.g] );
-       rgb.b = pgm_read_byte( &CIE1931_CURVE[rgb.b] );
+    rgb.r = pgm_read_byte(&CIE1931_CURVE[rgb.r]);
+    rgb.g = pgm_read_byte(&CIE1931_CURVE[rgb.g]);
+    rgb.b = pgm_read_byte(&CIE1931_CURVE[rgb.b]);
 #endif
 
-       return rgb;
+    return rgb;
 }
-
index 22bb083519ca1346af96536c6da6f43ac82e3b28..67816466286330a5f32ad32e5caf8b76c3b55c5e 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #ifndef COLOR_H
 #define COLOR_H
 
 #include <stdint.h>
 #include <stdbool.h>
 
-
 #if defined(__GNUC__)
-#define PACKED __attribute__ ((__packed__))
+#    define PACKED __attribute__((__packed__))
 #else
-#define PACKED
+#    define PACKED
 #endif
 
 #if defined(_MSC_VER)
-#pragma pack( push, 1 )
+#    pragma pack(push, 1)
 #endif
 
 #ifdef RGBW
-  #define LED_TYPE cRGBW
+#    define LED_TYPE cRGBW
 #else
-  #define LED_TYPE RGB
+#    define LED_TYPE RGB
 #endif
 
 // WS2812 specific layout
-typedef struct PACKED
-{
-       uint8_t g;
-       uint8_t r;
-       uint8_t b;
+typedef struct PACKED {
+    uint8_t g;
+    uint8_t r;
+    uint8_t b;
 } cRGB;
 
 typedef cRGB RGB;
 
 // WS2812 specific layout
-typedef struct PACKED
-{
-       uint8_t g;
-       uint8_t r;
-       uint8_t b;
-       uint8_t w;
+typedef struct PACKED {
+    uint8_t g;
+    uint8_t r;
+    uint8_t b;
+    uint8_t w;
 } cRGBW;
 
-typedef struct PACKED
-{
-       uint8_t h;
-       uint8_t s;
-       uint8_t v;
+typedef struct PACKED {
+    uint8_t h;
+    uint8_t s;
+    uint8_t v;
 } HSV;
 
 #if defined(_MSC_VER)
-#pragma pack( pop )
+#    pragma pack(pop)
 #endif
 
 RGB hsv_to_rgb(HSV hsv);
 
-#endif // COLOR_H
+#endif  // COLOR_H
index ae72701da1d087ecce7b04fb0781fda748b6d71a..fb9f1fd00a66ab24ea1a9cd96304f73669defc81 100644 (file)
 #pragma once
 
 /* diode directions */
-#define COL2ROW       0
-#define ROW2COL       1
+#define COL2ROW 0
+#define ROW2COL 1
 #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
 
 // useful for direct pin mapping
 #define NO_PIN (~0)
 
 #ifdef __AVR__
-    #ifndef __ASSEMBLER__
-      #include <avr/io.h>
-    #endif
-    #define PORT_SHIFTER 4 // this may be 4 for all AVR chips
+#    ifndef __ASSEMBLER__
+#        include <avr/io.h>
+#    endif
+#    define PORT_SHIFTER 4  // this may be 4 for all AVR chips
 
-    // If you want to add more to this list, reference the PINx definitions in these header
-    // files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr
+// If you want to add more to this list, reference the PINx definitions in these header
+// files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr
 
-    #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__)
-        #define ADDRESS_BASE 0x00
-        #define PINB_ADDRESS 0x3
-        #define PINC_ADDRESS 0x6
-        #define PIND_ADDRESS 0x9
-        #define PINE_ADDRESS 0xC
-        #define PINF_ADDRESS 0xF
-    #elif defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__)
-        #define ADDRESS_BASE 0x00
-        #define PINB_ADDRESS 0x3
-        #define PINC_ADDRESS 0x6
-        #define PIND_ADDRESS 0x9
-    #elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__)
-        #define ADDRESS_BASE 0x00
-        #define PINA_ADDRESS 0x0
-        #define PINB_ADDRESS 0x3
-        #define PINC_ADDRESS 0x6
-        #define PIND_ADDRESS 0x9
-        #define PINE_ADDRESS 0xC
-        #define PINF_ADDRESS 0xF
-    #elif defined(__AVR_ATmega32A__)
-        #define ADDRESS_BASE 0x10
-        #define PIND_ADDRESS 0x0
-        #define PINC_ADDRESS 0x3
-        #define PINB_ADDRESS 0x6
-        #define PINA_ADDRESS 0x9
-    #elif defined(__AVR_ATmega328P__)
-        #define ADDRESS_BASE 0x00
-        #define PINB_ADDRESS 0x3
-        #define PINC_ADDRESS 0x6
-        #define PIND_ADDRESS 0x9
-    #else
-        #error "Pins are not defined"
-    #endif
+#    if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__)
+#        define ADDRESS_BASE 0x00
+#        define PINB_ADDRESS 0x3
+#        define PINC_ADDRESS 0x6
+#        define PIND_ADDRESS 0x9
+#        define PINE_ADDRESS 0xC
+#        define PINF_ADDRESS 0xF
+#    elif defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__)
+#        define ADDRESS_BASE 0x00
+#        define PINB_ADDRESS 0x3
+#        define PINC_ADDRESS 0x6
+#        define PIND_ADDRESS 0x9
+#    elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__)
+#        define ADDRESS_BASE 0x00
+#        define PINA_ADDRESS 0x0
+#        define PINB_ADDRESS 0x3
+#        define PINC_ADDRESS 0x6
+#        define PIND_ADDRESS 0x9
+#        define PINE_ADDRESS 0xC
+#        define PINF_ADDRESS 0xF
+#    elif defined(__AVR_ATmega32A__)
+#        define ADDRESS_BASE 0x10
+#        define PIND_ADDRESS 0x0
+#        define PINC_ADDRESS 0x3
+#        define PINB_ADDRESS 0x6
+#        define PINA_ADDRESS 0x9
+#    elif defined(__AVR_ATmega328P__)
+#        define ADDRESS_BASE 0x00
+#        define PINB_ADDRESS 0x3
+#        define PINC_ADDRESS 0x6
+#        define PIND_ADDRESS 0x9
+#    else
+#        error "Pins are not defined"
+#    endif
 
-    /* I/O pins */
-    #define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin)
+/* I/O pins */
+#    define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin)
 
-    #ifdef PORTA
-        #define A0 PINDEF(A, 0)
-        #define A1 PINDEF(A, 1)
-        #define A2 PINDEF(A, 2)
-        #define A3 PINDEF(A, 3)
-        #define A4 PINDEF(A, 4)
-        #define A5 PINDEF(A, 5)
-        #define A6 PINDEF(A, 6)
-        #define A7 PINDEF(A, 7)
-    #endif
-    #ifdef PORTB
-        #define B0 PINDEF(B, 0)
-        #define B1 PINDEF(B, 1)
-        #define B2 PINDEF(B, 2)
-        #define B3 PINDEF(B, 3)
-        #define B4 PINDEF(B, 4)
-        #define B5 PINDEF(B, 5)
-        #define B6 PINDEF(B, 6)
-        #define B7 PINDEF(B, 7)
-    #endif
-    #ifdef PORTC
-        #define C0 PINDEF(C, 0)
-        #define C1 PINDEF(C, 1)
-        #define C2 PINDEF(C, 2)
-        #define C3 PINDEF(C, 3)
-        #define C4 PINDEF(C, 4)
-        #define C5 PINDEF(C, 5)
-        #define C6 PINDEF(C, 6)
-        #define C7 PINDEF(C, 7)
-    #endif
-    #ifdef PORTD
-        #define D0 PINDEF(D, 0)
-        #define D1 PINDEF(D, 1)
-        #define D2 PINDEF(D, 2)
-        #define D3 PINDEF(D, 3)
-        #define D4 PINDEF(D, 4)
-        #define D5 PINDEF(D, 5)
-        #define D6 PINDEF(D, 6)
-        #define D7 PINDEF(D, 7)
-    #endif
-    #ifdef PORTE
-        #define E0 PINDEF(E, 0)
-        #define E1 PINDEF(E, 1)
-        #define E2 PINDEF(E, 2)
-        #define E3 PINDEF(E, 3)
-        #define E4 PINDEF(E, 4)
-        #define E5 PINDEF(E, 5)
-        #define E6 PINDEF(E, 6)
-        #define E7 PINDEF(E, 7)
-    #endif
-    #ifdef PORTF
-        #define F0 PINDEF(F, 0)
-        #define F1 PINDEF(F, 1)
-        #define F2 PINDEF(F, 2)
-        #define F3 PINDEF(F, 3)
-        #define F4 PINDEF(F, 4)
-        #define F5 PINDEF(F, 5)
-        #define F6 PINDEF(F, 6)
-        #define F7 PINDEF(F, 7)
-    #endif
+#    ifdef PORTA
+#        define A0 PINDEF(A, 0)
+#        define A1 PINDEF(A, 1)
+#        define A2 PINDEF(A, 2)
+#        define A3 PINDEF(A, 3)
+#        define A4 PINDEF(A, 4)
+#        define A5 PINDEF(A, 5)
+#        define A6 PINDEF(A, 6)
+#        define A7 PINDEF(A, 7)
+#    endif
+#    ifdef PORTB
+#        define B0 PINDEF(B, 0)
+#        define B1 PINDEF(B, 1)
+#        define B2 PINDEF(B, 2)
+#        define B3 PINDEF(B, 3)
+#        define B4 PINDEF(B, 4)
+#        define B5 PINDEF(B, 5)
+#        define B6 PINDEF(B, 6)
+#        define B7 PINDEF(B, 7)
+#    endif
+#    ifdef PORTC
+#        define C0 PINDEF(C, 0)
+#        define C1 PINDEF(C, 1)
+#        define C2 PINDEF(C, 2)
+#        define C3 PINDEF(C, 3)
+#        define C4 PINDEF(C, 4)
+#        define C5 PINDEF(C, 5)
+#        define C6 PINDEF(C, 6)
+#        define C7 PINDEF(C, 7)
+#    endif
+#    ifdef PORTD
+#        define D0 PINDEF(D, 0)
+#        define D1 PINDEF(D, 1)
+#        define D2 PINDEF(D, 2)
+#        define D3 PINDEF(D, 3)
+#        define D4 PINDEF(D, 4)
+#        define D5 PINDEF(D, 5)
+#        define D6 PINDEF(D, 6)
+#        define D7 PINDEF(D, 7)
+#    endif
+#    ifdef PORTE
+#        define E0 PINDEF(E, 0)
+#        define E1 PINDEF(E, 1)
+#        define E2 PINDEF(E, 2)
+#        define E3 PINDEF(E, 3)
+#        define E4 PINDEF(E, 4)
+#        define E5 PINDEF(E, 5)
+#        define E6 PINDEF(E, 6)
+#        define E7 PINDEF(E, 7)
+#    endif
+#    ifdef PORTF
+#        define F0 PINDEF(F, 0)
+#        define F1 PINDEF(F, 1)
+#        define F2 PINDEF(F, 2)
+#        define F3 PINDEF(F, 3)
+#        define F4 PINDEF(F, 4)
+#        define F5 PINDEF(F, 5)
+#        define F6 PINDEF(F, 6)
+#        define F7 PINDEF(F, 7)
+#    endif
 
-  #ifndef __ASSEMBLER__
-    #define _PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset)
-    // Port X Input Pins Address
-    #define PINx_ADDRESS(p)  _PIN_ADDRESS(p, 0)
-    // Port X Data Direction Register,  0:input 1:output
-    #define DDRx_ADDRESS(p)  _PIN_ADDRESS(p, 1)
-    // Port X Data Register
-    #define PORTx_ADDRESS(p) _PIN_ADDRESS(p, 2)
-  #endif
+#    ifndef __ASSEMBLER__
+#        define _PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset)
+// Port X Input Pins Address
+#        define PINx_ADDRESS(p) _PIN_ADDRESS(p, 0)
+// Port X Data Direction Register,  0:input 1:output
+#        define DDRx_ADDRESS(p) _PIN_ADDRESS(p, 1)
+// Port X Data Register
+#        define PORTx_ADDRESS(p) _PIN_ADDRESS(p, 2)
+#    endif
 
 #elif defined(PROTOCOL_CHIBIOS)
-  // Defines mapping for Proton C replacement
-  #ifdef CONVERT_TO_PROTON_C
-    // Left side (front)
-    #define D3 PAL_LINE(GPIOA, 9)
-    #define D2 PAL_LINE(GPIOA, 10)
-    //      GND
-    //      GND
-    #define D1 PAL_LINE(GPIOB, 7)
-    #define D0 PAL_LINE(GPIOB, 6)
-    #define D4 PAL_LINE(GPIOB, 5)
-    #define C6 PAL_LINE(GPIOB, 4)
-    #define D7 PAL_LINE(GPIOB, 3)
-    #define E6 PAL_LINE(GPIOB, 2)
-    #define B4 PAL_LINE(GPIOB, 1)
-    #define B5 PAL_LINE(GPIOB, 0)
+// Defines mapping for Proton C replacement
+#    ifdef CONVERT_TO_PROTON_C
+// Left side (front)
+#        define D3 PAL_LINE(GPIOA, 9)
+#        define D2 PAL_LINE(GPIOA, 10)
+//      GND
+//      GND
+#        define D1 PAL_LINE(GPIOB, 7)
+#        define D0 PAL_LINE(GPIOB, 6)
+#        define D4 PAL_LINE(GPIOB, 5)
+#        define C6 PAL_LINE(GPIOB, 4)
+#        define D7 PAL_LINE(GPIOB, 3)
+#        define E6 PAL_LINE(GPIOB, 2)
+#        define B4 PAL_LINE(GPIOB, 1)
+#        define B5 PAL_LINE(GPIOB, 0)
 
-    // Right side (front)
-    //      RAW
-    //      GND
-    //      RESET
-    //      VCC
-    #define F4 PAL_LINE(GPIOA, 2)
-    #define F5 PAL_LINE(GPIOA, 1)
-    #define F6 PAL_LINE(GPIOA, 0)
-    #define F7 PAL_LINE(GPIOB, 8)
-    #define B1 PAL_LINE(GPIOB, 13)
-    #define B3 PAL_LINE(GPIOB, 14)
-    #define B2 PAL_LINE(GPIOB, 15)
-    #define B6 PAL_LINE(GPIOB, 9)
+// Right side (front)
+//      RAW
+//      GND
+//      RESET
+//      VCC
+#        define F4 PAL_LINE(GPIOA, 2)
+#        define F5 PAL_LINE(GPIOA, 1)
+#        define F6 PAL_LINE(GPIOA, 0)
+#        define F7 PAL_LINE(GPIOB, 8)
+#        define B1 PAL_LINE(GPIOB, 13)
+#        define B3 PAL_LINE(GPIOB, 14)
+#        define B2 PAL_LINE(GPIOB, 15)
+#        define B6 PAL_LINE(GPIOB, 9)
 
-    // LEDs (only D5/C13 uses an actual LED)
-    #ifdef CONVERT_TO_PROTON_C_RXLED
-      #define D5 PAL_LINE(GPIOC, 13)
-      #define B0 PAL_LINE(GPIOC, 13)
-    #else
-      #define D5 PAL_LINE(GPIOC, 13)
-      #define B0 PAL_LINE(GPIOC, 14)
-    #endif
-  #else
-    #define A0  PAL_LINE(GPIOA, 0)
-    #define A1  PAL_LINE(GPIOA, 1)
-    #define A2  PAL_LINE(GPIOA, 2)
-    #define A3  PAL_LINE(GPIOA, 3)
-    #define A4  PAL_LINE(GPIOA, 4)
-    #define A5  PAL_LINE(GPIOA, 5)
-    #define A6  PAL_LINE(GPIOA, 6)
-    #define A7  PAL_LINE(GPIOA, 7)
-    #define A8  PAL_LINE(GPIOA, 8)
-    #define A9  PAL_LINE(GPIOA, 9)
-    #define A10 PAL_LINE(GPIOA, 10)
-    #define A11 PAL_LINE(GPIOA, 11)
-    #define A12 PAL_LINE(GPIOA, 12)
-    #define A13 PAL_LINE(GPIOA, 13)
-    #define A14 PAL_LINE(GPIOA, 14)
-    #define A15 PAL_LINE(GPIOA, 15)
-    #define B0  PAL_LINE(GPIOB, 0)
-    #define B1  PAL_LINE(GPIOB, 1)
-    #define B2  PAL_LINE(GPIOB, 2)
-    #define B3  PAL_LINE(GPIOB, 3)
-    #define B4  PAL_LINE(GPIOB, 4)
-    #define B5  PAL_LINE(GPIOB, 5)
-    #define B6  PAL_LINE(GPIOB, 6)
-    #define B7  PAL_LINE(GPIOB, 7)
-    #define B8  PAL_LINE(GPIOB, 8)
-    #define B9  PAL_LINE(GPIOB, 9)
-    #define B10 PAL_LINE(GPIOB, 10)
-    #define B11 PAL_LINE(GPIOB, 11)
-    #define B12 PAL_LINE(GPIOB, 12)
-    #define B13 PAL_LINE(GPIOB, 13)
-    #define B14 PAL_LINE(GPIOB, 14)
-    #define B15 PAL_LINE(GPIOB, 15)
-    #define B16 PAL_LINE(GPIOB, 16)
-    #define B17 PAL_LINE(GPIOB, 17)
-    #define C0  PAL_LINE(GPIOC, 0)
-    #define C1  PAL_LINE(GPIOC, 1)
-    #define C2  PAL_LINE(GPIOC, 2)
-    #define C3  PAL_LINE(GPIOC, 3)
-    #define C4  PAL_LINE(GPIOC, 4)
-    #define C5  PAL_LINE(GPIOC, 5)
-    #define C6  PAL_LINE(GPIOC, 6)
-    #define C7  PAL_LINE(GPIOC, 7)
-    #define C8  PAL_LINE(GPIOC, 8)
-    #define C9  PAL_LINE(GPIOC, 9)
-    #define C10 PAL_LINE(GPIOC, 10)
-    #define C11 PAL_LINE(GPIOC, 11)
-    #define C12 PAL_LINE(GPIOC, 12)
-    #define C13 PAL_LINE(GPIOC, 13)
-    #define C14 PAL_LINE(GPIOC, 14)
-    #define C15 PAL_LINE(GPIOC, 15)
-    #define D0  PAL_LINE(GPIOD, 0)
-    #define D1  PAL_LINE(GPIOD, 1)
-    #define D2  PAL_LINE(GPIOD, 2)
-    #define D3  PAL_LINE(GPIOD, 3)
-    #define D4  PAL_LINE(GPIOD, 4)
-    #define D5  PAL_LINE(GPIOD, 5)
-    #define D6  PAL_LINE(GPIOD, 6)
-    #define D7  PAL_LINE(GPIOD, 7)
-    #define D8  PAL_LINE(GPIOD, 8)
-    #define D9  PAL_LINE(GPIOD, 9)
-    #define D10 PAL_LINE(GPIOD, 10)
-    #define D11 PAL_LINE(GPIOD, 11)
-    #define D12 PAL_LINE(GPIOD, 12)
-    #define D13 PAL_LINE(GPIOD, 13)
-    #define D14 PAL_LINE(GPIOD, 14)
-    #define D15 PAL_LINE(GPIOD, 15)
-    #define E0  PAL_LINE(GPIOE, 0)
-    #define E1  PAL_LINE(GPIOE, 1)
-    #define E2  PAL_LINE(GPIOE, 2)
-    #define E3  PAL_LINE(GPIOE, 3)
-    #define E4  PAL_LINE(GPIOE, 4)
-    #define E5  PAL_LINE(GPIOE, 5)
-    #define E6  PAL_LINE(GPIOE, 6)
-    #define E7  PAL_LINE(GPIOE, 7)
-    #define E8  PAL_LINE(GPIOE, 8)
-    #define E9  PAL_LINE(GPIOE, 9)
-    #define E10 PAL_LINE(GPIOE, 10)
-    #define E11 PAL_LINE(GPIOE, 11)
-    #define E12 PAL_LINE(GPIOE, 12)
-    #define E13 PAL_LINE(GPIOE, 13)
-    #define E14 PAL_LINE(GPIOE, 14)
-    #define E15 PAL_LINE(GPIOE, 15)
-    #define F0  PAL_LINE(GPIOF, 0)
-    #define F1  PAL_LINE(GPIOF, 1)
-    #define F2  PAL_LINE(GPIOF, 2)
-    #define F3  PAL_LINE(GPIOF, 3)
-    #define F4  PAL_LINE(GPIOF, 4)
-    #define F5  PAL_LINE(GPIOF, 5)
-    #define F6  PAL_LINE(GPIOF, 6)
-    #define F7  PAL_LINE(GPIOF, 7)
-    #define F8  PAL_LINE(GPIOF, 8)
-    #define F9  PAL_LINE(GPIOF, 9)
-    #define F10 PAL_LINE(GPIOF, 10)
-    #define F11 PAL_LINE(GPIOF, 11)
-    #define F12 PAL_LINE(GPIOF, 12)
-    #define F13 PAL_LINE(GPIOF, 13)
-    #define F14 PAL_LINE(GPIOF, 14)
-    #define F15 PAL_LINE(GPIOF, 15)
-  #endif
+// LEDs (only D5/C13 uses an actual LED)
+#        ifdef CONVERT_TO_PROTON_C_RXLED
+#            define D5 PAL_LINE(GPIOC, 13)
+#            define B0 PAL_LINE(GPIOC, 13)
+#        else
+#            define D5 PAL_LINE(GPIOC, 13)
+#            define B0 PAL_LINE(GPIOC, 14)
+#        endif
+#    else
+#        define A0 PAL_LINE(GPIOA, 0)
+#        define A1 PAL_LINE(GPIOA, 1)
+#        define A2 PAL_LINE(GPIOA, 2)
+#        define A3 PAL_LINE(GPIOA, 3)
+#        define A4 PAL_LINE(GPIOA, 4)
+#        define A5 PAL_LINE(GPIOA, 5)
+#        define A6 PAL_LINE(GPIOA, 6)
+#        define A7 PAL_LINE(GPIOA, 7)
+#        define A8 PAL_LINE(GPIOA, 8)
+#        define A9 PAL_LINE(GPIOA, 9)
+#        define A10 PAL_LINE(GPIOA, 10)
+#        define A11 PAL_LINE(GPIOA, 11)
+#        define A12 PAL_LINE(GPIOA, 12)
+#        define A13 PAL_LINE(GPIOA, 13)
+#        define A14 PAL_LINE(GPIOA, 14)
+#        define A15 PAL_LINE(GPIOA, 15)
+#        define B0 PAL_LINE(GPIOB, 0)
+#        define B1 PAL_LINE(GPIOB, 1)
+#        define B2 PAL_LINE(GPIOB, 2)
+#        define B3 PAL_LINE(GPIOB, 3)
+#        define B4 PAL_LINE(GPIOB, 4)
+#        define B5 PAL_LINE(GPIOB, 5)
+#        define B6 PAL_LINE(GPIOB, 6)
+#        define B7 PAL_LINE(GPIOB, 7)
+#        define B8 PAL_LINE(GPIOB, 8)
+#        define B9 PAL_LINE(GPIOB, 9)
+#        define B10 PAL_LINE(GPIOB, 10)
+#        define B11 PAL_LINE(GPIOB, 11)
+#        define B12 PAL_LINE(GPIOB, 12)
+#        define B13 PAL_LINE(GPIOB, 13)
+#        define B14 PAL_LINE(GPIOB, 14)
+#        define B15 PAL_LINE(GPIOB, 15)
+#        define B16 PAL_LINE(GPIOB, 16)
+#        define B17 PAL_LINE(GPIOB, 17)
+#        define C0 PAL_LINE(GPIOC, 0)
+#        define C1 PAL_LINE(GPIOC, 1)
+#        define C2 PAL_LINE(GPIOC, 2)
+#        define C3 PAL_LINE(GPIOC, 3)
+#        define C4 PAL_LINE(GPIOC, 4)
+#        define C5 PAL_LINE(GPIOC, 5)
+#        define C6 PAL_LINE(GPIOC, 6)
+#        define C7 PAL_LINE(GPIOC, 7)
+#        define C8 PAL_LINE(GPIOC, 8)
+#        define C9 PAL_LINE(GPIOC, 9)
+#        define C10 PAL_LINE(GPIOC, 10)
+#        define C11 PAL_LINE(GPIOC, 11)
+#        define C12 PAL_LINE(GPIOC, 12)
+#        define C13 PAL_LINE(GPIOC, 13)
+#        define C14 PAL_LINE(GPIOC, 14)
+#        define C15 PAL_LINE(GPIOC, 15)
+#        define D0 PAL_LINE(GPIOD, 0)
+#        define D1 PAL_LINE(GPIOD, 1)
+#        define D2 PAL_LINE(GPIOD, 2)
+#        define D3 PAL_LINE(GPIOD, 3)
+#        define D4 PAL_LINE(GPIOD, 4)
+#        define D5 PAL_LINE(GPIOD, 5)
+#        define D6 PAL_LINE(GPIOD, 6)
+#        define D7 PAL_LINE(GPIOD, 7)
+#        define D8 PAL_LINE(GPIOD, 8)
+#        define D9 PAL_LINE(GPIOD, 9)
+#        define D10 PAL_LINE(GPIOD, 10)
+#        define D11 PAL_LINE(GPIOD, 11)
+#        define D12 PAL_LINE(GPIOD, 12)
+#        define D13 PAL_LINE(GPIOD, 13)
+#        define D14 PAL_LINE(GPIOD, 14)
+#        define D15 PAL_LINE(GPIOD, 15)
+#        define E0 PAL_LINE(GPIOE, 0)
+#        define E1 PAL_LINE(GPIOE, 1)
+#        define E2 PAL_LINE(GPIOE, 2)
+#        define E3 PAL_LINE(GPIOE, 3)
+#        define E4 PAL_LINE(GPIOE, 4)
+#        define E5 PAL_LINE(GPIOE, 5)
+#        define E6 PAL_LINE(GPIOE, 6)
+#        define E7 PAL_LINE(GPIOE, 7)
+#        define E8 PAL_LINE(GPIOE, 8)
+#        define E9 PAL_LINE(GPIOE, 9)
+#        define E10 PAL_LINE(GPIOE, 10)
+#        define E11 PAL_LINE(GPIOE, 11)
+#        define E12 PAL_LINE(GPIOE, 12)
+#        define E13 PAL_LINE(GPIOE, 13)
+#        define E14 PAL_LINE(GPIOE, 14)
+#        define E15 PAL_LINE(GPIOE, 15)
+#        define F0 PAL_LINE(GPIOF, 0)
+#        define F1 PAL_LINE(GPIOF, 1)
+#        define F2 PAL_LINE(GPIOF, 2)
+#        define F3 PAL_LINE(GPIOF, 3)
+#        define F4 PAL_LINE(GPIOF, 4)
+#        define F5 PAL_LINE(GPIOF, 5)
+#        define F6 PAL_LINE(GPIOF, 6)
+#        define F7 PAL_LINE(GPIOF, 7)
+#        define F8 PAL_LINE(GPIOF, 8)
+#        define F9 PAL_LINE(GPIOF, 9)
+#        define F10 PAL_LINE(GPIOF, 10)
+#        define F11 PAL_LINE(GPIOF, 11)
+#        define F12 PAL_LINE(GPIOF, 12)
+#        define F13 PAL_LINE(GPIOF, 13)
+#        define F14 PAL_LINE(GPIOF, 14)
+#        define F15 PAL_LINE(GPIOF, 15)
+#    endif
 #endif
 
 /* USART configuration */
 #ifdef BLUETOOTH_ENABLE
-#   ifdef __AVR_ATmega32U4__
-#      define SERIAL_UART_BAUD 9600
-#      define SERIAL_UART_DATA UDR1
-#      define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
-#      define SERIAL_UART_RXD_VECT USART1_RX_vect
-#      define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
-#      define SERIAL_UART_INIT() do { \
-            /* baud rate */ \
-            UBRR1L = SERIAL_UART_UBRR; \
-            /* baud rate */ \
-            UBRR1H = SERIAL_UART_UBRR >> 8; \
-            /* enable TX */ \
-            UCSR1B = _BV(TXEN1); \
-            /* 8-bit data */ \
-            UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
-            sei(); \
-        } while(0)
-#   else
-#       error "USART configuration is needed."
-#   endif
+#    ifdef __AVR_ATmega32U4__
+#        define SERIAL_UART_BAUD 9600
+#        define SERIAL_UART_DATA UDR1
+#        define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
+#        define SERIAL_UART_RXD_VECT USART1_RX_vect
+#        define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
+#        define SERIAL_UART_INIT()                  \
+            do {                                    \
+                /* baud rate */                     \
+                UBRR1L = SERIAL_UART_UBRR;          \
+                /* baud rate */                     \
+                UBRR1H = SERIAL_UART_UBRR >> 8;     \
+                /* enable TX */                     \
+                UCSR1B = _BV(TXEN1);                \
+                /* 8-bit data */                    \
+                UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
+                sei();                              \
+            } while (0)
+#    else
+#        error "USART configuration is needed."
+#    endif
 #endif
 
 #define API_SYSEX_MAX_SIZE 32
index c07be18f8d1e09a5a8dde08e07c2b5644101d334..76b978d059e826c9970f09297c10bb603fb5186f 100644 (file)
@@ -24,15 +24,15 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred.
 #include <stdlib.h>
 
 #ifndef DEBOUNCE
-#  define DEBOUNCE 5
+#    define DEBOUNCE 5
 #endif
 
 #if (MATRIX_COLS <= 8)
-#  define ROW_SHIFTER ((uint8_t)1)
+#    define ROW_SHIFTER ((uint8_t)1)
 #elif (MATRIX_COLS <= 16)
-#  define ROW_SHIFTER ((uint16_t)1)
+#    define ROW_SHIFTER ((uint16_t)1)
 #elif (MATRIX_COLS <= 32)
-#  define ROW_SHIFTER ((uint32_t)1)
+#    define ROW_SHIFTER ((uint32_t)1)
 #endif
 
 #define debounce_counter_t uint8_t
@@ -49,66 +49,66 @@ void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t n
 
 // we use num_rows rather than MATRIX_ROWS to support split keyboards
 void debounce_init(uint8_t num_rows) {
-  debounce_counters = (debounce_counter_t *)malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t));
-  int i             = 0;
-  for (uint8_t r = 0; r < num_rows; r++) {
-    for (uint8_t c = 0; c < MATRIX_COLS; c++) {
-      debounce_counters[i++] = DEBOUNCE_ELAPSED;
+    debounce_counters = (debounce_counter_t *)malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t));
+    int i             = 0;
+    for (uint8_t r = 0; r < num_rows; r++) {
+        for (uint8_t c = 0; c < MATRIX_COLS; c++) {
+            debounce_counters[i++] = DEBOUNCE_ELAPSED;
+        }
     }
-  }
 }
 
 void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
-  uint8_t current_time = timer_read() % MAX_DEBOUNCE;
-  if (counters_need_update) {
-    update_debounce_counters(num_rows, current_time);
-  }
+    uint8_t current_time = timer_read() % MAX_DEBOUNCE;
+    if (counters_need_update) {
+        update_debounce_counters(num_rows, current_time);
+    }
 
-  if (changed || matrix_need_update) {
-    transfer_matrix_values(raw, cooked, num_rows, current_time);
-  }
+    if (changed || matrix_need_update) {
+        transfer_matrix_values(raw, cooked, num_rows, current_time);
+    }
 }
 
 // If the current time is > debounce counter, set the counter to enable input.
 void update_debounce_counters(uint8_t num_rows, uint8_t current_time) {
-  counters_need_update                 = false;
-  debounce_counter_t *debounce_pointer = debounce_counters;
-  for (uint8_t row = 0; row < num_rows; row++) {
-    for (uint8_t col = 0; col < MATRIX_COLS; col++) {
-      if (*debounce_pointer != DEBOUNCE_ELAPSED) {
-        if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) {
-          *debounce_pointer = DEBOUNCE_ELAPSED;
-        } else {
-          counters_need_update = true;
+    counters_need_update                 = false;
+    debounce_counter_t *debounce_pointer = debounce_counters;
+    for (uint8_t row = 0; row < num_rows; row++) {
+        for (uint8_t col = 0; col < MATRIX_COLS; col++) {
+            if (*debounce_pointer != DEBOUNCE_ELAPSED) {
+                if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) {
+                    *debounce_pointer = DEBOUNCE_ELAPSED;
+                } else {
+                    counters_need_update = true;
+                }
+            }
+            debounce_pointer++;
         }
-      }
-      debounce_pointer++;
     }
-  }
 }
 
 // upload from raw_matrix to final matrix;
 void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) {
-  matrix_need_update = false;
-  debounce_counter_t *debounce_pointer = debounce_counters;
-  for (uint8_t row = 0; row < num_rows; row++) {
-    matrix_row_t delta        = raw[row] ^ cooked[row];
-    matrix_row_t existing_row = cooked[row];
-    for (uint8_t col = 0; col < MATRIX_COLS; col++) {
-      matrix_row_t col_mask = (ROW_SHIFTER << col);
-      if (delta & col_mask) {
-        if (*debounce_pointer == DEBOUNCE_ELAPSED) {
-          *debounce_pointer    = current_time;
-          counters_need_update = true;
-          existing_row ^= col_mask;  // flip the bit.
-        } else {
-          matrix_need_update = true;
+    matrix_need_update                   = false;
+    debounce_counter_t *debounce_pointer = debounce_counters;
+    for (uint8_t row = 0; row < num_rows; row++) {
+        matrix_row_t delta        = raw[row] ^ cooked[row];
+        matrix_row_t existing_row = cooked[row];
+        for (uint8_t col = 0; col < MATRIX_COLS; col++) {
+            matrix_row_t col_mask = (ROW_SHIFTER << col);
+            if (delta & col_mask) {
+                if (*debounce_pointer == DEBOUNCE_ELAPSED) {
+                    *debounce_pointer    = current_time;
+                    counters_need_update = true;
+                    existing_row ^= col_mask;  // flip the bit.
+                } else {
+                    matrix_need_update = true;
+                }
+            }
+            debounce_pointer++;
         }
-      }
-      debounce_pointer++;
+        cooked[row] = existing_row;
     }
-    cooked[row] = existing_row;
-  }
 }
 
 bool debounce_active(void) { return true; }
index 8dbfa3fcfa9b5b317c324dc3fb4f4edbf09f158b..173ad15ee92b1582d103283ed308e07cf0ff52ce 100644 (file)
@@ -24,11 +24,11 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred.
 #include <stdlib.h>
 
 #ifndef DEBOUNCE
-#  define DEBOUNCE 5
+#    define DEBOUNCE 5
 #endif
 
 #define debounce_counter_t uint8_t
-static bool                matrix_need_update;
+static bool matrix_need_update;
 
 static debounce_counter_t *debounce_counters;
 static bool                counters_need_update;
@@ -41,60 +41,60 @@ void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t n
 
 // we use num_rows rather than MATRIX_ROWS to support split keyboards
 void debounce_init(uint8_t num_rows) {
-  debounce_counters = (debounce_counter_t *)malloc(num_rows * sizeof(debounce_counter_t));
-  for (uint8_t r = 0; r < num_rows; r++) {
-    debounce_counters[r] = DEBOUNCE_ELAPSED;
-  }
+    debounce_counters = (debounce_counter_t *)malloc(num_rows * sizeof(debounce_counter_t));
+    for (uint8_t r = 0; r < num_rows; r++) {
+        debounce_counters[r] = DEBOUNCE_ELAPSED;
+    }
 }
 
 void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
-  uint8_t current_time = timer_read() % MAX_DEBOUNCE;
-  bool needed_update = counters_need_update;
-  if (counters_need_update) {
-    update_debounce_counters(num_rows, current_time);
-  }
+    uint8_t current_time  = timer_read() % MAX_DEBOUNCE;
+    bool    needed_update = counters_need_update;
+    if (counters_need_update) {
+        update_debounce_counters(num_rows, current_time);
+    }
 
-  if (changed || (needed_update && !counters_need_update) || matrix_need_update) {
-    transfer_matrix_values(raw, cooked, num_rows, current_time);
-  }
+    if (changed || (needed_update && !counters_need_update) || matrix_need_update) {
+        transfer_matrix_values(raw, cooked, num_rows, current_time);
+    }
 }
 
 // If the current time is > debounce counter, set the counter to enable input.
 void update_debounce_counters(uint8_t num_rows, uint8_t current_time) {
-  counters_need_update                 = false;
-  debounce_counter_t *debounce_pointer = debounce_counters;
-  for (uint8_t row = 0; row < num_rows; row++) {
-    if (*debounce_pointer != DEBOUNCE_ELAPSED) {
-      if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) {
-        *debounce_pointer = DEBOUNCE_ELAPSED;
-      } else {
-        counters_need_update = true;
-      }
+    counters_need_update                 = false;
+    debounce_counter_t *debounce_pointer = debounce_counters;
+    for (uint8_t row = 0; row < num_rows; row++) {
+        if (*debounce_pointer != DEBOUNCE_ELAPSED) {
+            if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) {
+                *debounce_pointer = DEBOUNCE_ELAPSED;
+            } else {
+                counters_need_update = true;
+            }
+        }
+        debounce_pointer++;
     }
-    debounce_pointer++;
-  }
 }
 
 // upload from raw_matrix to final matrix;
 void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) {
-  matrix_need_update = false;
-  debounce_counter_t *debounce_pointer = debounce_counters;
-  for (uint8_t row = 0; row < num_rows; row++) {
-    matrix_row_t existing_row = cooked[row];
-    matrix_row_t raw_row      = raw[row];
+    matrix_need_update                   = false;
+    debounce_counter_t *debounce_pointer = debounce_counters;
+    for (uint8_t row = 0; row < num_rows; row++) {
+        matrix_row_t existing_row = cooked[row];
+        matrix_row_t raw_row      = raw[row];
 
-    // determine new value basd on debounce pointer + raw value
-    if (existing_row != raw_row) {
-      if (*debounce_pointer == DEBOUNCE_ELAPSED) {
-        *debounce_pointer    = current_time;
-        cooked[row]          = raw_row;
-        counters_need_update = true;
-      } else {
-        matrix_need_update = true;
-      }
+        // determine new value basd on debounce pointer + raw value
+        if (existing_row != raw_row) {
+            if (*debounce_pointer == DEBOUNCE_ELAPSED) {
+                *debounce_pointer    = current_time;
+                cooked[row]          = raw_row;
+                counters_need_update = true;
+            } else {
+                matrix_need_update = true;
+            }
+        }
+        debounce_pointer++;
     }
-    debounce_pointer++;
-  }
 }
 
 bool debounce_active(void) { return true; }
index c8ab34e1a0cafd2a4969d1887aa308134c6ab7dd..3ed9055d2a9076bcecd8735293d9ed87c79e2c69 100644 (file)
@@ -20,38 +20,33 @@ When no state changes have occured for DEBOUNCE milliseconds, we push the state.
 #include "timer.h"
 #include "quantum.h"
 #ifndef DEBOUNCE
-  #define DEBOUNCE 5
+#    define DEBOUNCE 5
 #endif
 
-void debounce_init(uint8_t num_rows) {}
+void        debounce_init(uint8_t num_rows) {}
 static bool debouncing = false;
 
 #if DEBOUNCE > 0
 static uint16_t debouncing_time;
-void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed)
-{
-  if (changed) {
-    debouncing = true;
-    debouncing_time = timer_read();
-  }
+void            debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
+    if (changed) {
+        debouncing      = true;
+        debouncing_time = timer_read();
+    }
 
-  if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
-    for (int i = 0; i < num_rows; i++) {
-      cooked[i] = raw[i];
+    if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
+        for (int i = 0; i < num_rows; i++) {
+            cooked[i] = raw[i];
+        }
+        debouncing = false;
     }
-    debouncing = false;
-  }
 }
-#else //no debouncing.
-void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed)
-{
-  for (int i = 0; i < num_rows; i++) {
-    cooked[i] = raw[i];
-  }
+#else  // no debouncing.
+void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
+    for (int i = 0; i < num_rows; i++) {
+        cooked[i] = raw[i];
+    }
 }
 #endif
 
-bool debounce_active(void) {
-  return debouncing;
-}
-
+bool debounce_active(void) { return debouncing; }
index 38400e36f10d39444f09b1dce259b249b0957f45..ca056f630e3af08b5079ee56be4b17abb7f36583 100644 (file)
  */
 
 #include "config.h"
-#include "keymap.h" // to get keymaps[][][]
+#include "keymap.h"  // to get keymaps[][][]
 #include "tmk_core/common/eeprom.h"
-#include "progmem.h" // to read default from flash
-#include "quantum.h" // for send_string()
+#include "progmem.h"  // to read default from flash
+#include "quantum.h"  // for send_string()
 #include "dynamic_keymap.h"
 
 #ifdef DYNAMIC_KEYMAP_ENABLE
 
-#ifndef DYNAMIC_KEYMAP_EEPROM_ADDR
-#error DYNAMIC_KEYMAP_EEPROM_ADDR not defined
-#endif
+#    ifndef DYNAMIC_KEYMAP_EEPROM_ADDR
+#        error DYNAMIC_KEYMAP_EEPROM_ADDR not defined
+#    endif
 
-#ifndef DYNAMIC_KEYMAP_LAYER_COUNT
-#error DYNAMIC_KEYMAP_LAYER_COUNT not defined
-#endif
+#    ifndef DYNAMIC_KEYMAP_LAYER_COUNT
+#        error DYNAMIC_KEYMAP_LAYER_COUNT not defined
+#    endif
 
-#ifndef DYNAMIC_KEYMAP_MACRO_COUNT
-#error DYNAMIC_KEYMAP_MACRO_COUNT not defined
-#endif
+#    ifndef DYNAMIC_KEYMAP_MACRO_COUNT
+#        error DYNAMIC_KEYMAP_MACRO_COUNT not defined
+#    endif
 
-#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
-#error DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR not defined
-#endif
+#    ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
+#        error DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR not defined
+#    endif
 
-#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE
-#error DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE not defined
-#endif
+#    ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE
+#        error DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE not defined
+#    endif
 
-uint8_t dynamic_keymap_get_layer_count(void)
-{
-       return DYNAMIC_KEYMAP_LAYER_COUNT;
-}
+uint8_t dynamic_keymap_get_layer_count(void) { return DYNAMIC_KEYMAP_LAYER_COUNT; }
 
-void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column)
-{
-       // TODO: optimize this with some left shifts
-       return ((void*)DYNAMIC_KEYMAP_EEPROM_ADDR) + ( layer * MATRIX_ROWS * MATRIX_COLS * 2 ) +
-               ( row * MATRIX_COLS * 2 ) + ( column * 2 );
+void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column) {
+    // TODO: optimize this with some left shifts
+    return ((void *)DYNAMIC_KEYMAP_EEPROM_ADDR) + (layer * MATRIX_ROWS * MATRIX_COLS * 2) + (row * MATRIX_COLS * 2) + (column * 2);
 }
 
-uint16_t dynamic_keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t column)
-{
-       void *address = dynamic_keymap_key_to_eeprom_address(layer, row, column);
-       // Big endian, so we can read/write EEPROM directly from host if we want
-       uint16_t keycode = eeprom_read_byte(address) << 8;
-       keycode |= eeprom_read_byte(address + 1);
-       return keycode;
+uint16_t dynamic_keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t column) {
+    void *address = dynamic_keymap_key_to_eeprom_address(layer, row, column);
+    // Big endian, so we can read/write EEPROM directly from host if we want
+    uint16_t keycode = eeprom_read_byte(address) << 8;
+    keycode |= eeprom_read_byte(address + 1);
+    return keycode;
 }
 
-void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode)
-{
-       void *address = dynamic_keymap_key_to_eeprom_address(layer, row, column);
-       // Big endian, so we can read/write EEPROM directly from host if we want
-       eeprom_update_byte(address, (uint8_t)(keycode >> 8));
-       eeprom_update_byte(address+1, (uint8_t)(keycode & 0xFF));
+void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode) {
+    void *address = dynamic_keymap_key_to_eeprom_address(layer, row, column);
+    // Big endian, so we can read/write EEPROM directly from host if we want
+    eeprom_update_byte(address, (uint8_t)(keycode >> 8));
+    eeprom_update_byte(address + 1, (uint8_t)(keycode & 0xFF));
 }
 
-void dynamic_keymap_reset(void)
-{
-       // Reset the keymaps in EEPROM to what is in flash.
-       // All keyboards using dynamic keymaps should define a layout
-       // for the same number of layers as DYNAMIC_KEYMAP_LAYER_COUNT.
-       for ( int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++ )      {
-               for ( int row = 0; row < MATRIX_ROWS; row++ ) {
-                       for ( int column = 0; column < MATRIX_COLS; column++ )  {
-                               dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column]));
-                       }
-               }
-       }
+void dynamic_keymap_reset(void) {
+    // Reset the keymaps in EEPROM to what is in flash.
+    // All keyboards using dynamic keymaps should define a layout
+    // for the same number of layers as DYNAMIC_KEYMAP_LAYER_COUNT.
+    for (int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) {
+        for (int row = 0; row < MATRIX_ROWS; row++) {
+            for (int column = 0; column < MATRIX_COLS; column++) {
+                dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column]));
+            }
+        }
+    }
 }
 
-void dynamic_keymap_get_buffer( uint16_t offset, uint16_t size, uint8_t *data )
-{
-       uint16_t dynamic_keymap_eeprom_size = DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2;
-       void *source = (void*)(DYNAMIC_KEYMAP_EEPROM_ADDR+offset);
-       uint8_t *target = data;
-       for ( uint16_t i = 0; i < size; i++ ) {
-               if ( offset + i < dynamic_keymap_eeprom_size ) {
-                       *target = eeprom_read_byte(source);
-               } else {
-                       *target = 0x00;
-               }
-               source++;
-               target++;
-       }
+void dynamic_keymap_get_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
+    uint16_t dynamic_keymap_eeprom_size = DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2;
+    void *   source                     = (void *)(DYNAMIC_KEYMAP_EEPROM_ADDR + offset);
+    uint8_t *target                     = data;
+    for (uint16_t i = 0; i < size; i++) {
+        if (offset + i < dynamic_keymap_eeprom_size) {
+            *target = eeprom_read_byte(source);
+        } else {
+            *target = 0x00;
+        }
+        source++;
+        target++;
+    }
 }
 
-void dynamic_keymap_set_buffer( uint16_t offset, uint16_t size, uint8_t *data )
-{
-       uint16_t dynamic_keymap_eeprom_size = DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2;
-       void *target = (void*)(DYNAMIC_KEYMAP_EEPROM_ADDR+offset);
-       uint8_t *source = data;
-       for ( uint16_t i = 0; i < size; i++ ) {
-               if ( offset + i < dynamic_keymap_eeprom_size ) {
-                       eeprom_update_byte(target, *source);
-               }
-               source++;
-               target++;
-       }
+void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
+    uint16_t dynamic_keymap_eeprom_size = DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2;
+    void *   target                     = (void *)(DYNAMIC_KEYMAP_EEPROM_ADDR + offset);
+    uint8_t *source                     = data;
+    for (uint16_t i = 0; i < size; i++) {
+        if (offset + i < dynamic_keymap_eeprom_size) {
+            eeprom_update_byte(target, *source);
+        }
+        source++;
+        target++;
+    }
 }
 
 // This overrides the one in quantum/keymap_common.c
-uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
-{
-       if ( layer < DYNAMIC_KEYMAP_LAYER_COUNT &&
-                       key.row < MATRIX_ROWS &&
-                       key.col < MATRIX_COLS ) {
-               return dynamic_keymap_get_keycode(layer, key.row, key.col);
-       } else {
-               return KC_NO;
-       }
-}
-
-
-
-uint8_t dynamic_keymap_macro_get_count(void)
-{
-       return DYNAMIC_KEYMAP_MACRO_COUNT;
-}
-
-uint16_t dynamic_keymap_macro_get_buffer_size(void)
-{
-       return DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE;
+uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
+    if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
+        return dynamic_keymap_get_keycode(layer, key.row, key.col);
+    } else {
+        return KC_NO;
+    }
 }
 
-void dynamic_keymap_macro_get_buffer( uint16_t offset, uint16_t size, uint8_t *data )
-{
-       void *source = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR+offset);
-       uint8_t *target = data;
-       for ( uint16_t i = 0; i < size; i++ ) {
-               if ( offset + i < DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE ) {
-                       *target = eeprom_read_byte(source);
-               } else {
-                       *target = 0x00;
-               }
-               source++;
-               target++;
-       }
+uint8_t dynamic_keymap_macro_get_count(void) { return DYNAMIC_KEYMAP_MACRO_COUNT; }
+
+uint16_t dynamic_keymap_macro_get_buffer_size(void) { return DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE; }
+
+void dynamic_keymap_macro_get_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
+    void *   source = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + offset);
+    uint8_t *target = data;
+    for (uint16_t i = 0; i < size; i++) {
+        if (offset + i < DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE) {
+            *target = eeprom_read_byte(source);
+        } else {
+            *target = 0x00;
+        }
+        source++;
+        target++;
+    }
 }
 
-void dynamic_keymap_macro_set_buffer( uint16_t offset, uint16_t size, uint8_t *data )
-{
-       void *target = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR+offset);
-       uint8_t *source = data;
-       for ( uint16_t i = 0; i < size; i++ ) {
-               if ( offset + i < DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE ) {
-                       eeprom_update_byte(target, *source);
-               }
-               source++;
-               target++;
-       }
+void dynamic_keymap_macro_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
+    void *   target = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + offset);
+    uint8_t *source = data;
+    for (uint16_t i = 0; i < size; i++) {
+        if (offset + i < DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE) {
+            eeprom_update_byte(target, *source);
+        }
+        source++;
+        target++;
+    }
 }
 
-void dynamic_keymap_macro_reset(void)
-{
-       void *p = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR);
-       void *end = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR+DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE);
-       while ( p != end ) {
-               eeprom_update_byte(p, 0);
-               ++p;
-       }
+void dynamic_keymap_macro_reset(void) {
+    void *p   = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR);
+    void *end = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE);
+    while (p != end) {
+        eeprom_update_byte(p, 0);
+        ++p;
+    }
 }
 
-void dynamic_keymap_macro_send( uint8_t id )
-{
-       if ( id >= DYNAMIC_KEYMAP_MACRO_COUNT ) {
-               return;
-       }
-
-       // Check the last byte of the buffer.
-       // If it's not zero, then we are in the middle
-       // of buffer writing, possibly an aborted buffer
-       // write. So do nothing.
-       void *p = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR+DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE-1);
-       if ( eeprom_read_byte(p) != 0 ) {
-               return;
-       }
-
-       // Skip N null characters
-       // p will then point to the Nth macro
-       p = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR);
-       void *end = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR+DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE);
-       while ( id > 0 ) {
-               // If we are past the end of the buffer, then the buffer
-               // contents are garbage, i.e. there were not DYNAMIC_KEYMAP_MACRO_COUNT
-               // nulls in the buffer.
-               if ( p == end ) {
-                       return;
-               }
-               if ( eeprom_read_byte(p) == 0 ) {
-                       --id;
-               }
-               ++p;
-       }
-
-       // Send the macro string one or two chars at a time
-       // by making temporary 1 or 2 char strings
-       char data[3] = { 0, 0, 0 };
-       // We already checked there was a null at the end of
-       // the buffer, so this cannot go past the end
-       while ( 1 ) {
-               data[0] = eeprom_read_byte(p++);
-               data[1] = 0;
-               // Stop at the null terminator of this macro string
-               if ( data[0] == 0 ) {
-                       break;
-               }
-               // If the char is magic (tap, down, up),
-               // add the next char (key to use) and send a 2 char string.
-               if ( data[0] == SS_TAP_CODE || data[0] == SS_DOWN_CODE || data[0] == SS_UP_CODE ) {
-                       data[1] = eeprom_read_byte(p++);
-                       if ( data[1] == 0 ) {
-                               break;
-                       }
-               }
-               send_string(data);
-       }
+void dynamic_keymap_macro_send(uint8_t id) {
+    if (id >= DYNAMIC_KEYMAP_MACRO_COUNT) {
+        return;
+    }
+
+    // Check the last byte of the buffer.
+    // If it's not zero, then we are in the middle
+    // of buffer writing, possibly an aborted buffer
+    // write. So do nothing.
+    void *p = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE - 1);
+    if (eeprom_read_byte(p) != 0) {
+        return;
+    }
+
+    // Skip N null characters
+    // p will then point to the Nth macro
+    p         = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR);
+    void *end = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE);
+    while (id > 0) {
+        // If we are past the end of the buffer, then the buffer
+        // contents are garbage, i.e. there were not DYNAMIC_KEYMAP_MACRO_COUNT
+        // nulls in the buffer.
+        if (p == end) {
+            return;
+        }
+        if (eeprom_read_byte(p) == 0) {
+            --id;
+        }
+        ++p;
+    }
+
+    // Send the macro string one or two chars at a time
+    // by making temporary 1 or 2 char strings
+    char data[3] = {0, 0, 0};
+    // We already checked there was a null at the end of
+    // the buffer, so this cannot go past the end
+    while (1) {
+        data[0] = eeprom_read_byte(p++);
+        data[1] = 0;
+        // Stop at the null terminator of this macro string
+        if (data[0] == 0) {
+            break;
+        }
+        // If the char is magic (tap, down, up),
+        // add the next char (key to use) and send a 2 char string.
+        if (data[0] == SS_TAP_CODE || data[0] == SS_DOWN_CODE || data[0] == SS_UP_CODE) {
+            data[1] = eeprom_read_byte(p++);
+            if (data[1] == 0) {
+                break;
+            }
+        }
+        send_string(data);
+    }
 }
 
-#endif // DYNAMIC_KEYMAP_ENABLE
-
+#endif  // DYNAMIC_KEYMAP_ENABLE
index 63653f6cb71880bec187177ab6f2ada0345113f4..55676172b6e54e83b1a147571f55db39a45b9f75 100644 (file)
 #include <stdint.h>
 #include <stdbool.h>
 
-uint8_t dynamic_keymap_get_layer_count(void);
-void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column);
+uint8_t  dynamic_keymap_get_layer_count(void);
+void *   dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column);
 uint16_t dynamic_keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t column);
-void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode);
-void dynamic_keymap_reset(void);
+void     dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode);
+void     dynamic_keymap_reset(void);
 // These get/set the keycodes as stored in the EEPROM buffer
 // Data is big-endian 16-bit values (the keycodes)
 // Order is by layer/row/column
@@ -31,14 +31,12 @@ void dynamic_keymap_reset(void);
 // This is only really useful for host applications that want to get a whole keymap fast,
 // by reading 14 keycodes (28 bytes) at a time, reducing the number of raw HID transfers by
 // a factor of 14.
-void dynamic_keymap_get_buffer( uint16_t offset, uint16_t size, uint8_t *data );
-void dynamic_keymap_set_buffer( uint16_t offset, uint16_t size, uint8_t *data );
+void dynamic_keymap_get_buffer(uint16_t offset, uint16_t size, uint8_t *data);
+void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data);
 
 // This overrides the one in quantum/keymap_common.c
 // uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
 
-
-
 // Note regarding dynamic_keymap_macro_set_buffer():
 // The last byte of the buffer is used as a valid flag,
 // so macro sending is disabled during writing a new buffer,
@@ -53,11 +51,10 @@ void dynamic_keymap_set_buffer( uint16_t offset, uint16_t size, uint8_t *data );
 // and it not being null means the buffer can be considered in an
 // invalid state.
 
-uint8_t dynamic_keymap_macro_get_count(void);
+uint8_t  dynamic_keymap_macro_get_count(void);
 uint16_t dynamic_keymap_macro_get_buffer_size(void);
-void dynamic_keymap_macro_get_buffer( uint16_t offset, uint16_t size, uint8_t *data );
-void dynamic_keymap_macro_set_buffer( uint16_t offset, uint16_t size, uint8_t *data );
-void dynamic_keymap_macro_reset(void);
-
-void dynamic_keymap_macro_send( uint8_t id );
+void     dynamic_keymap_macro_get_buffer(uint16_t offset, uint16_t size, uint8_t *data);
+void     dynamic_keymap_macro_set_buffer(uint16_t offset, uint16_t size, uint8_t *data);
+void     dynamic_keymap_macro_reset(void);
 
+void dynamic_keymap_macro_send(uint8_t id);
index 07cba19f604c9913f558d430c6fabfe7f3ae81ed..c7632c004b1c7aa79e16d334c6acf2e1e1e7d223 100644 (file)
@@ -30,7 +30,7 @@
  * there have been reports of it being too much in some users' cases,
  * so 128 is considered a safe default.
  */
-#define DYNAMIC_MACRO_SIZE 128
+#    define DYNAMIC_MACRO_SIZE 128
 #endif
 
 /* DYNAMIC_MACRO_RANGE must be set as the last element of user's
@@ -46,8 +46,7 @@ enum dynamic_macro_keycodes {
 };
 
 /* Blink the LEDs to notify the user about some event. */
-void dynamic_macro_led_blink(void)
-{
+void dynamic_macro_led_blink(void) {
 #ifdef BACKLIGHT_ENABLE
     backlight_toggle();
     wait_ms(100);
@@ -59,10 +58,8 @@ void dynamic_macro_led_blink(void)
  * need a `direction` variable accessible at the call site.
  */
 #define DYNAMIC_MACRO_CURRENT_SLOT() (direction > 0 ? 1 : 2)
-#define DYNAMIC_MACRO_CURRENT_LENGTH(BEGIN, POINTER) \
-    ((int)(direction * ((POINTER) - (BEGIN))))
-#define DYNAMIC_MACRO_CURRENT_CAPACITY(BEGIN, END2) \
-    ((int)(direction * ((END2) - (BEGIN)) + 1))
+#define DYNAMIC_MACRO_CURRENT_LENGTH(BEGIN, POINTER) ((int)(direction * ((POINTER) - (BEGIN))))
+#define DYNAMIC_MACRO_CURRENT_CAPACITY(BEGIN, END2) ((int)(direction * ((END2) - (BEGIN)) + 1))
 
 /**
  * Start recording of the dynamic macro.
@@ -70,9 +67,7 @@ void dynamic_macro_led_blink(void)
  * @param[out] macro_pointer The new macro buffer iterator.
  * @param[in]  macro_buffer  The macro buffer used to initialize macro_pointer.
  */
-void dynamic_macro_record_start(
-    keyrecord_t **macro_pointer, keyrecord_t *macro_buffer)
-{
+void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer) {
     dprintln("dynamic macro recording: started");
 
     dynamic_macro_led_blink();
@@ -89,9 +84,7 @@ void dynamic_macro_record_start(
  * @param macro_end[in]    The element after the last macro buffer element.
  * @param direction[in]    Either +1 or -1, which way to iterate the buffer.
  */
-void dynamic_macro_play(
-    keyrecord_t *macro_buffer, keyrecord_t *macro_end, int8_t direction)
-{
+void dynamic_macro_play(keyrecord_t *macro_buffer, keyrecord_t *macro_end, int8_t direction) {
     dprintf("dynamic macro: slot %d playback\n", DYNAMIC_MACRO_CURRENT_SLOT());
 
     uint32_t saved_layer_state = layer_state;
@@ -118,13 +111,7 @@ void dynamic_macro_play(
  * @param direction[in]  Either +1 or -1, which way to iterate the buffer.
  * @param record[in]     The current keypress.
  */
-void dynamic_macro_record_key(
-    keyrecord_t *macro_buffer,
-    keyrecord_t **macro_pointer,
-    keyrecord_t *macro2_end,
-    int8_t direction,
-    keyrecord_t *record)
-{
+void dynamic_macro_record_key(keyrecord_t *macro_buffer, keyrecord_t **macro_pointer, keyrecord_t *macro2_end, int8_t direction, keyrecord_t *record) {
     /* If we've just started recording, ignore all the key releases. */
     if (!record->event.pressed && *macro_pointer == macro_buffer) {
         dprintln("dynamic macro: ignoring a leading key-up event");
@@ -141,38 +128,25 @@ void dynamic_macro_record_key(
         dynamic_macro_led_blink();
     }
 
-    dprintf(
-        "dynamic macro: slot %d length: %d/%d\n",
-        DYNAMIC_MACRO_CURRENT_SLOT(),
-        DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, *macro_pointer),
-        DYNAMIC_MACRO_CURRENT_CAPACITY(macro_buffer, macro2_end));
+    dprintf("dynamic macro: slot %d length: %d/%d\n", DYNAMIC_MACRO_CURRENT_SLOT(), DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, *macro_pointer), DYNAMIC_MACRO_CURRENT_CAPACITY(macro_buffer, macro2_end));
 }
 
 /**
  * End recording of the dynamic macro. Essentially just update the
  * pointer to the end of the macro.
  */
-void dynamic_macro_record_end(
-    keyrecord_t *macro_buffer,
-    keyrecord_t *macro_pointer,
-    int8_t direction,
-    keyrecord_t **macro_end)
-{
+void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_pointer, int8_t direction, keyrecord_t **macro_end) {
     dynamic_macro_led_blink();
 
     /* Do not save the keys being held when stopping the recording,
      * i.e. the keys used to access the layer DYN_REC_STOP is on.
      */
-    while (macro_pointer != macro_buffer &&
-           (macro_pointer - direction)->event.pressed) {
+    while (macro_pointer != macro_buffer && (macro_pointer - direction)->event.pressed) {
         dprintln("dynamic macro: trimming a trailing key-down event");
         macro_pointer -= direction;
     }
 
-    dprintf(
-        "dynamic macro: slot %d saved, length: %d\n",
-        DYNAMIC_MACRO_CURRENT_SLOT(),
-        DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, macro_pointer));
+    dprintf("dynamic macro: slot %d saved, length: %d\n", DYNAMIC_MACRO_CURRENT_SLOT(), DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, macro_pointer));
 
     *macro_end = macro_pointer;
 }
@@ -187,8 +161,7 @@ void dynamic_macro_record_end(
  *       <...THE REST OF THE FUNCTION...>
  *   }
  */
-bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record)
-{
+bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
     /* Both macros use the same buffer but read/write on different
      * ends of it.
      *
@@ -239,57 +212,57 @@ bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record)
         /* No macro recording in progress. */
         if (!record->event.pressed) {
             switch (keycode) {
-            case DYN_REC_START1:
-                dynamic_macro_record_start(&macro_pointer, macro_buffer);
-                macro_id = 1;
-                return false;
-            case DYN_REC_START2:
-                dynamic_macro_record_start(&macro_pointer, r_macro_buffer);
-                macro_id = 2;
-                return false;
-            case DYN_MACRO_PLAY1:
-                dynamic_macro_play(macro_buffer, macro_end, +1);
-                return false;
-            case DYN_MACRO_PLAY2:
-                dynamic_macro_play(r_macro_buffer, r_macro_end, -1);
-                return false;
+                case DYN_REC_START1:
+                    dynamic_macro_record_start(&macro_pointer, macro_buffer);
+                    macro_id = 1;
+                    return false;
+                case DYN_REC_START2:
+                    dynamic_macro_record_start(&macro_pointer, r_macro_buffer);
+                    macro_id = 2;
+                    return false;
+                case DYN_MACRO_PLAY1:
+                    dynamic_macro_play(macro_buffer, macro_end, +1);
+                    return false;
+                case DYN_MACRO_PLAY2:
+                    dynamic_macro_play(r_macro_buffer, r_macro_end, -1);
+                    return false;
             }
         }
     } else {
         /* A macro is being recorded right now. */
         switch (keycode) {
-        case DYN_REC_STOP:
-            /* Stop the macro recording. */
-            if (record->event.pressed) { /* Ignore the initial release
-                                          * just after the recoding
-                                          * starts. */
+            case DYN_REC_STOP:
+                /* Stop the macro recording. */
+                if (record->event.pressed) { /* Ignore the initial release
+                                              * just after the recoding
+                                              * starts. */
+                    switch (macro_id) {
+                        case 1:
+                            dynamic_macro_record_end(macro_buffer, macro_pointer, +1, &macro_end);
+                            break;
+                        case 2:
+                            dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end);
+                            break;
+                    }
+                    macro_id = 0;
+                }
+                return false;
+            case DYN_MACRO_PLAY1:
+            case DYN_MACRO_PLAY2:
+                dprintln("dynamic macro: ignoring macro play key while recording");
+                return false;
+            default:
+                /* Store the key in the macro buffer and process it normally. */
                 switch (macro_id) {
-                case 1:
-                    dynamic_macro_record_end(macro_buffer, macro_pointer, +1, &macro_end);
-                    break;
-                case 2:
-                    dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end);
-                    break;
+                    case 1:
+                        dynamic_macro_record_key(macro_buffer, &macro_pointer, r_macro_end, +1, record);
+                        break;
+                    case 2:
+                        dynamic_macro_record_key(r_macro_buffer, &macro_pointer, macro_end, -1, record);
+                        break;
                 }
-                macro_id = 0;
-            }
-            return false;
-        case DYN_MACRO_PLAY1:
-        case DYN_MACRO_PLAY2:
-            dprintln("dynamic macro: ignoring macro play key while recording");
-            return false;
-        default:
-            /* Store the key in the macro buffer and process it normally. */
-            switch (macro_id) {
-            case 1:
-                dynamic_macro_record_key(macro_buffer, &macro_pointer, r_macro_end, +1, record);
-                break;
-            case 2:
-                dynamic_macro_record_key(r_macro_buffer, &macro_pointer, macro_end, -1, record);
+                return true;
                 break;
-            }
-            return true;
-            break;
         }
     }
 
index 10d8cf7da0f8b551231601501d9b9bf3bb48fda5..b3b1cd9f2b7fe3a267f07c46848d5307501cae5d 100644 (file)
 
 #include "encoder.h"
 #ifdef SPLIT_KEYBOARD
-  #include "split_util.h"
+#    include "split_util.h"
 #endif
 
 // for memcpy
 #include <string.h>
 
-
 #ifndef ENCODER_RESOLUTION
-  #define ENCODER_RESOLUTION 4
+#    define ENCODER_RESOLUTION 4
 #endif
 
 #if !defined(ENCODERS_PAD_A) || !defined(ENCODERS_PAD_B)
-  #error "No encoder pads defined by ENCODERS_PAD_A and ENCODERS_PAD_B"
+#    error "No encoder pads defined by ENCODERS_PAD_A and ENCODERS_PAD_B"
 #endif
 
-
-#define NUMBER_OF_ENCODERS (sizeof(encoders_pad_a)/sizeof(pin_t))
+#define NUMBER_OF_ENCODERS (sizeof(encoders_pad_a) / sizeof(pin_t))
 static pin_t encoders_pad_a[] = ENCODERS_PAD_A;
 static pin_t encoders_pad_b[] = ENCODERS_PAD_B;
 
-static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 };
+static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
 
 static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0};
 
@@ -48,64 +46,58 @@ static int8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0};
 static int8_t encoder_value[NUMBER_OF_ENCODERS] = {0};
 #endif
 
-__attribute__ ((weak))
-void encoder_update_user(int8_t index, bool clockwise) { }
+__attribute__((weak)) void encoder_update_user(int8_t index, bool clockwise) {}
 
-__attribute__ ((weak))
-void encoder_update_kb(int8_t index, bool clockwise) {
-  encoder_update_user(index, clockwise);
-}
+__attribute__((weak)) void encoder_update_kb(int8_t index, bool clockwise) { encoder_update_user(index, clockwise); }
 
 void encoder_init(void) {
 #if defined(SPLIT_KEYBOARD) && defined(ENCODERS_PAD_A_RIGHT) && defined(ENCODERS_PAD_B_RIGHT)
-  if (!isLeftHand) {
-    const pin_t encoders_pad_a_right[] = ENCODERS_PAD_A_RIGHT;
-    const pin_t encoders_pad_b_right[] = ENCODERS_PAD_B_RIGHT;
-    for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) {
-      encoders_pad_a[i] = encoders_pad_a_right[i];
-      encoders_pad_b[i] = encoders_pad_b_right[i];
+    if (!isLeftHand) {
+        const pin_t encoders_pad_a_right[] = ENCODERS_PAD_A_RIGHT;
+        const pin_t encoders_pad_b_right[] = ENCODERS_PAD_B_RIGHT;
+        for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) {
+            encoders_pad_a[i] = encoders_pad_a_right[i];
+            encoders_pad_b[i] = encoders_pad_b_right[i];
+        }
     }
-  }
 #endif
 
-  for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
-    setPinInputHigh(encoders_pad_a[i]);
-    setPinInputHigh(encoders_pad_b[i]);
+    for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
+        setPinInputHigh(encoders_pad_a[i]);
+        setPinInputHigh(encoders_pad_b[i]);
 
-    encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
-  }
+        encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
+    }
 }
 
 void encoder_read(void) {
-  for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
-    encoder_state[i] <<= 2;
-    encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
-    encoder_value[i] += encoder_LUT[encoder_state[i] & 0xF];
-    if (encoder_value[i] >= ENCODER_RESOLUTION) {
-        encoder_update_kb(i, false);
+    for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
+        encoder_state[i] <<= 2;
+        encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
+        encoder_value[i] += encoder_LUT[encoder_state[i] & 0xF];
+        if (encoder_value[i] >= ENCODER_RESOLUTION) {
+            encoder_update_kb(i, false);
+        }
+        if (encoder_value[i] <= -ENCODER_RESOLUTION) {  // direction is arbitrary here, but this clockwise
+            encoder_update_kb(i, true);
+        }
+        encoder_value[i] %= ENCODER_RESOLUTION;
     }
-    if (encoder_value[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
-        encoder_update_kb(i, true);
-    }
-    encoder_value[i] %= ENCODER_RESOLUTION;
-  }
 }
 
 #ifdef SPLIT_KEYBOARD
-void encoder_state_raw(uint8_t* slave_state) {
-  memcpy(slave_state, encoder_state, sizeof(encoder_state));
-}
+void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, encoder_state, sizeof(encoder_state)); }
 
 void encoder_update_raw(uint8_t* slave_state) {
-  for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
-    encoder_value[NUMBER_OF_ENCODERS + i] += encoder_LUT[slave_state[i] & 0xF];
-    if (encoder_value[NUMBER_OF_ENCODERS + i] >= ENCODER_RESOLUTION) {
-        encoder_update_kb(NUMBER_OF_ENCODERS + i, false);
-    }
-    if (encoder_value[NUMBER_OF_ENCODERS + i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
-        encoder_update_kb(NUMBER_OF_ENCODERS + i, true);
+    for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
+        encoder_value[NUMBER_OF_ENCODERS + i] += encoder_LUT[slave_state[i] & 0xF];
+        if (encoder_value[NUMBER_OF_ENCODERS + i] >= ENCODER_RESOLUTION) {
+            encoder_update_kb(NUMBER_OF_ENCODERS + i, false);
+        }
+        if (encoder_value[NUMBER_OF_ENCODERS + i] <= -ENCODER_RESOLUTION) {  // direction is arbitrary here, but this clockwise
+            encoder_update_kb(NUMBER_OF_ENCODERS + i, true);
+        }
+        encoder_value[NUMBER_OF_ENCODERS + i] %= ENCODER_RESOLUTION;
     }
-    encoder_value[NUMBER_OF_ENCODERS + i] %= ENCODER_RESOLUTION;
-  }
 }
 #endif
index c3341ca3326bbf948de997028bd2cbaf81f7a5aa..a57e2ed0755f24d7c9edc8118d5497afdf0c234c 100644 (file)
@@ -20,23 +20,21 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdbool.h>
 #include <musical_notes.h>
 
-bool fauxclicky_enabled = true;
-uint16_t note_start = 0;
-bool note_playing = false;
-uint16_t note_period = 0;
+bool     fauxclicky_enabled = true;
+uint16_t note_start         = 0;
+bool     note_playing       = false;
+uint16_t note_period        = 0;
 
-void fauxclicky_init()
-{
+void fauxclicky_init() {
     // Set port PC6 (OC3A and /OC4A) as output
     DDRC |= _BV(PORTC6);
 
     // TCCR3A / TCCR3B: Timer/Counter #3 Control Registers
     TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
-    TCCR3B = (1 << WGM33)  | (1 << WGM32)  | (0 << CS32)  | (1 << CS31) | (0 << CS30);
+    TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30);
 }
 
-void fauxclicky_stop()
-{
+void fauxclicky_stop() {
     FAUXCLICKY_DISABLE_OUTPUT;
     note_playing = false;
 }
@@ -45,10 +43,10 @@ void fauxclicky_play(float note[]) {
     if (!fauxclicky_enabled) return;
     if (note_playing) fauxclicky_stop();
     FAUXCLICKY_TIMER_PERIOD = (uint16_t)(((float)F_CPU) / (note[0] * (float)FAUXCLICKY_CPU_PRESCALER));
-    FAUXCLICKY_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (note[0] * (float)FAUXCLICKY_CPU_PRESCALER)) / (float)2);
-    note_playing = true;
-    note_period = (note[1] / (float)16) * ((float)60 / (float)FAUXCLICKY_TEMPO) * 1000;
-    note_start = timer_read();
+    FAUXCLICKY_DUTY_CYCLE   = (uint16_t)((((float)F_CPU) / (note[0] * (float)FAUXCLICKY_CPU_PRESCALER)) / (float)2);
+    note_playing            = true;
+    note_period             = (note[1] / (float)16) * ((float)60 / (float)FAUXCLICKY_TEMPO) * 1000;
+    note_start              = timer_read();
     FAUXCLICKY_ENABLE_OUTPUT;
 }
 
index 1a8e188dd5304428b9987ecc9f475f00b90ac5ae..5c056918a73aeeaf6151738caf0f5f91e84bc335 100644 (file)
@@ -14,18 +14,15 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef AUDIO_ENABLE
-#error "AUDIO_ENABLE and FAUXCLICKY_ENABLE cannot be both enabled"
+#    error "AUDIO_ENABLE and FAUXCLICKY_ENABLE cannot be both enabled"
 #endif
 
 #include "musical_notes.h"
 #include "stdbool.h"
 
-__attribute__ ((weak))
-float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_D4, 0.25);
-__attribute__ ((weak))
-float fauxclicky_released_note[2] = MUSICAL_NOTE(_C4, 0.125);
-__attribute__ ((weak))
-float fauxclicky_beep_note[2] = MUSICAL_NOTE(_C4, 0.25);
+__attribute__((weak)) float fauxclicky_pressed_note[2]  = MUSICAL_NOTE(_D4, 0.25);
+__attribute__((weak)) float fauxclicky_released_note[2] = MUSICAL_NOTE(_C4, 0.125);
+__attribute__((weak)) float fauxclicky_beep_note[2]     = MUSICAL_NOTE(_C4, 0.25);
 
 bool fauxclicky_enabled;
 
@@ -34,7 +31,7 @@ bool fauxclicky_enabled;
 //
 
 #ifndef FAUXCLICKY_TEMPO
-#define FAUXCLICKY_TEMPO TEMPO_DEFAULT
+#    define FAUXCLICKY_TEMPO TEMPO_DEFAULT
 #endif
 
 // beep on press
@@ -50,42 +47,44 @@ bool fauxclicky_enabled;
 #define FAUXCLICKY_ON fauxclicky_enabled = true
 
 // disable
-#define FAUXCLICKY_OFF do { \
-    fauxclicky_enabled = false; \
-    fauxclicky_stop(); \
-} while (0)
+#define FAUXCLICKY_OFF              \
+    do {                            \
+        fauxclicky_enabled = false; \
+        fauxclicky_stop();          \
+    } while (0)
 
 // toggle
-#define FAUXCLICKY_TOGGLE do { \
-    if (fauxclicky_enabled) { \
-        FAUXCLICKY_OFF; \
-    } else { \
-        FAUXCLICKY_ON; \
-    } \
-} while (0)
+#define FAUXCLICKY_TOGGLE         \
+    do {                          \
+        if (fauxclicky_enabled) { \
+            FAUXCLICKY_OFF;       \
+        } else {                  \
+            FAUXCLICKY_ON;        \
+        }                         \
+    } while (0)
 
 //
 // pin configuration
 //
 
 #ifndef FAUXCLICKY_CPU_PRESCALER
-#define FAUXCLICKY_CPU_PRESCALER 8
+#    define FAUXCLICKY_CPU_PRESCALER 8
 #endif
 
 #ifndef FAUXCLICKY_ENABLE_OUTPUT
-#define FAUXCLICKY_ENABLE_OUTPUT TCCR3A |= _BV(COM3A1)
+#    define FAUXCLICKY_ENABLE_OUTPUT TCCR3A |= _BV(COM3A1)
 #endif
 
 #ifndef FAUXCLICKY_DISABLE_OUTPUT
-#define FAUXCLICKY_DISABLE_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0))
+#    define FAUXCLICKY_DISABLE_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0))
 #endif
 
 #ifndef FAUXCLICKY_TIMER_PERIOD
-#define FAUXCLICKY_TIMER_PERIOD ICR3
+#    define FAUXCLICKY_TIMER_PERIOD ICR3
 #endif
 
 #ifndef FAUXCLICKY_DUTY_CYCLE
-#define FAUXCLICKY_DUTY_CYCLE OCR3A
+#    define FAUXCLICKY_DUTY_CYCLE OCR3A
 #endif
 
 //
@@ -96,4 +95,3 @@ void fauxclicky_init(void);
 void fauxclicky_stop(void);
 void fauxclicky_play(float note[2]);
 void fauxclicky_check(void);
-
index bfd40d045c0542b966dd3c21248a236677aa937f..f340905eab83fdd3b3cc443aede12307a585f43d 100644 (file)
@@ -24,7 +24,6 @@ extern keymap_config_t keymap_config;
  * and will return the corrected keycode, when appropriate.
  */
 uint16_t keycode_config(uint16_t keycode) {
-
     switch (keycode) {
         case KC_CAPSLOCK:
         case KC_LOCKING_CAPS:
@@ -56,7 +55,7 @@ uint16_t keycode_config(uint16_t keycode) {
                 return KC_LALT;
             }
             if (keymap_config.swap_lctl_lgui) {
-              return KC_LCTRL;
+                return KC_LCTRL;
             }
             if (keymap_config.no_gui) {
                 return KC_NO;
@@ -83,7 +82,7 @@ uint16_t keycode_config(uint16_t keycode) {
                 return KC_RALT;
             }
             if (keymap_config.swap_rctl_rgui) {
-              return KC_RCTL;
+                return KC_RCTL;
             }
             if (keymap_config.no_gui) {
                 return KC_NO;
@@ -140,22 +139,22 @@ uint8_t mod_config(uint8_t mod) {
         }
     }
     if (keymap_config.swap_lctl_lgui) {
-      if ((mod & MOD_RGUI) == MOD_LGUI) {
-        mod &= ~MOD_LGUI;
-        mod |= MOD_LCTL;
-      } else if ((mod & MOD_RCTL) == MOD_LCTL) {
-        mod &= ~MOD_LCTL;
-        mod |= MOD_LGUI;
-      }
+        if ((mod & MOD_RGUI) == MOD_LGUI) {
+            mod &= ~MOD_LGUI;
+            mod |= MOD_LCTL;
+        } else if ((mod & MOD_RCTL) == MOD_LCTL) {
+            mod &= ~MOD_LCTL;
+            mod |= MOD_LGUI;
+        }
     }
     if (keymap_config.swap_rctl_rgui) {
-      if ((mod & MOD_RGUI) == MOD_RGUI) {
-        mod &= ~MOD_RGUI;
-        mod |= MOD_RCTL;
-      } else if ((mod & MOD_RCTL) == MOD_RCTL) {
-        mod &= ~MOD_RCTL;
-        mod |= MOD_RGUI;
-      }
+        if ((mod & MOD_RGUI) == MOD_RGUI) {
+            mod &= ~MOD_RGUI;
+            mod |= MOD_RCTL;
+        } else if ((mod & MOD_RCTL) == MOD_RCTL) {
+            mod &= ~MOD_RCTL;
+            mod |= MOD_RGUI;
+        }
     }
     if (keymap_config.no_gui) {
         mod &= ~MOD_LGUI;
index 7b01fcea456ecf3dea87af91a183fcb98309bdb8..aa75ba2c132fa6ab944d7f9569ffb6b3cac277e0 100644 (file)
 #include "action_code.h"
 
 #ifndef KEYCODE_CONFIG_H
-#define KEYCODE_CONFIG_H
+#    define KEYCODE_CONFIG_H
 
 uint16_t keycode_config(uint16_t keycode);
-uint8_t mod_config(uint8_t mod);
+uint8_t  mod_config(uint8_t mod);
 
 /* NOTE: Not portable. Bit field order depends on implementation */
 typedef union {
     uint16_t raw;
     struct {
-        bool swap_control_capslock:1;
-        bool capslock_to_control:1;
-        bool swap_lalt_lgui:1;
-        bool swap_ralt_rgui:1;
-        bool no_gui:1;
-        bool swap_grave_esc:1;
-        bool swap_backslash_backspace:1;
-        bool nkro:1;
-        bool swap_lctl_lgui:1;
-        bool swap_rctl_rgui:1;
+        bool swap_control_capslock : 1;
+        bool capslock_to_control : 1;
+        bool swap_lalt_lgui : 1;
+        bool swap_ralt_rgui : 1;
+        bool no_gui : 1;
+        bool swap_grave_esc : 1;
+        bool swap_backslash_backspace : 1;
+        bool nkro : 1;
+        bool swap_lctl_lgui : 1;
+        bool swap_rctl_rgui : 1;
     };
 } keymap_config_t;
 
index bfcb2f7cd517d861c032951f351da510c399c8f5..34a9c8f8c652ad155e19236ed039dcdc189c5d19 100644 (file)
@@ -22,10 +22,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdbool.h>
 #include "action.h"
 #if defined(__AVR__)
-#include <avr/pgmspace.h>
+#    include <avr/pgmspace.h>
 #elif defined PROTOCOL_CHIBIOS
-//We need to ensure that chibios is include before redefining reset
-#include "ch.h"
+// We need to ensure that chibios is include before redefining reset
+#    include "ch.h"
 #endif
 #include "keycode.h"
 #include "action_macro.h"
@@ -38,7 +38,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 // ChibiOS uses RESET in its FlagStatus enumeration
 // Therefore define it as QK_RESET here, to avoid name collision
 #if defined(PROTOCOL_CHIBIOS)
-#define RESET QK_RESET
+#    define RESET QK_RESET
 #endif
 
 #include "quantum_keycodes.h"
@@ -47,10 +47,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
 
 // translates function id to action
-uint16_t keymap_function_id_to_action( uint16_t function_id );
+uint16_t keymap_function_id_to_action(uint16_t function_id);
 
 extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
 extern const uint16_t fn_actions[];
 
-
 #endif
index eef739a14a023676841d378945ad529cb18e13e9..9af9510081e27df4960888635dfda542e9dff0dd 100644 (file)
@@ -20,8 +20,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "keycode.h"
 #include "action_layer.h"
 #if defined(__AVR__)
-#include <util/delay.h>
-#include <stdio.h>
+#    include <util/delay.h>
+#    include <stdio.h>
 #endif
 #include "action.h"
 #include "action_macro.h"
@@ -30,7 +30,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "quantum.h"
 
 #ifdef MIDI_ENABLE
-       #include "process_midi.h"
+#    include "process_midi.h"
 #endif
 
 extern keymap_config_t keymap_config;
@@ -38,8 +38,7 @@ extern keymap_config_t keymap_config;
 #include <inttypes.h>
 
 /* converts key to action */
-action_t action_for_key(uint8_t layer, keypos_t key)
-{
+action_t action_for_key(uint8_t layer, keypos_t key) {
     // 16bit keycodes - important
     uint16_t keycode = keymap_key_to_keycode(layer, key);
 
@@ -47,7 +46,7 @@ action_t action_for_key(uint8_t layer, keypos_t key)
     keycode = keycode_config(keycode);
 
     action_t action;
-    uint8_t action_layer, when, mod;
+    uint8_t  action_layer, when, mod;
 
     switch (keycode) {
         case KC_FN0 ... KC_FN31:
@@ -69,18 +68,18 @@ action_t action_for_key(uint8_t layer, keypos_t key)
         case KC_TRNS:
             action.code = ACTION_TRANSPARENT;
             break;
-        case QK_MODS ... QK_MODS_MAX: ;
+        case QK_MODS ... QK_MODS_MAX:;
             // Has a modifier
             // Split it up
-            action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
+            action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF);  // adds modifier to key
             break;
-        case QK_FUNCTION ... QK_FUNCTION_MAX: ;
+        case QK_FUNCTION ... QK_FUNCTION_MAX:;
             // Is a shortcut for function action_layer, pull last 12bits
             // This means we have 4,096 FN macros at our disposal
-            action.code = keymap_function_id_to_action( (int)keycode & 0xFFF );
+            action.code = keymap_function_id_to_action((int)keycode & 0xFFF);
             break;
         case QK_MACRO ... QK_MACRO_MAX:
-            if (keycode & 0x800) // tap macros have upper bit set
+            if (keycode & 0x800)  // tap macros have upper bit set
                 action.code = ACTION_MACRO_TAP(keycode & 0xFF);
             else
                 action.code = ACTION_MACRO(keycode & 0xFF);
@@ -88,50 +87,50 @@ action_t action_for_key(uint8_t layer, keypos_t key)
         case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
             action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
             break;
-        case QK_TO ... QK_TO_MAX: ;
+        case QK_TO ... QK_TO_MAX:;
             // Layer set "GOTO"
-            when = (keycode >> 0x4) & 0x3;
+            when         = (keycode >> 0x4) & 0x3;
             action_layer = keycode & 0xF;
-            action.code = ACTION_LAYER_SET(action_layer, when);
+            action.code  = ACTION_LAYER_SET(action_layer, when);
             break;
-        case QK_MOMENTARY ... QK_MOMENTARY_MAX: ;
+        case QK_MOMENTARY ... QK_MOMENTARY_MAX:;
             // Momentary action_layer
             action_layer = keycode & 0xFF;
-            action.code = ACTION_LAYER_MOMENTARY(action_layer);
+            action.code  = ACTION_LAYER_MOMENTARY(action_layer);
             break;
-        case QK_DEF_LAYER ... QK_DEF_LAYER_MAX: ;
+        case QK_DEF_LAYER ... QK_DEF_LAYER_MAX:;
             // Set default action_layer
             action_layer = keycode & 0xFF;
-            action.code = ACTION_DEFAULT_LAYER_SET(action_layer);
+            action.code  = ACTION_DEFAULT_LAYER_SET(action_layer);
             break;
-        case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX: ;
+        case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:;
             // Set toggle
             action_layer = keycode & 0xFF;
-            action.code = ACTION_LAYER_TOGGLE(action_layer);
+            action.code  = ACTION_LAYER_TOGGLE(action_layer);
             break;
-        case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX: ;
+        case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:;
             // OSL(action_layer) - One-shot action_layer
             action_layer = keycode & 0xFF;
-            action.code = ACTION_LAYER_ONESHOT(action_layer);
+            action.code  = ACTION_LAYER_ONESHOT(action_layer);
             break;
-        case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX: ;
+        case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:;
             // OSM(mod) - One-shot mod
-            mod = mod_config(keycode & 0xFF);
+            mod         = mod_config(keycode & 0xFF);
             action.code = ACTION_MODS_ONESHOT(mod);
             break;
         case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
             action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF);
             break;
         case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
-            mod = mod_config(keycode & 0xF);
+            mod          = mod_config(keycode & 0xF);
             action_layer = (keycode >> 4) & 0xF;
-            action.code = ACTION_LAYER_MODS(action_layer, mod);
+            action.code  = ACTION_LAYER_MODS(action_layer, mod);
             break;
         case QK_MOD_TAP ... QK_MOD_TAP_MAX:
-            mod = mod_config((keycode >> 0x8) & 0x1F);
+            mod         = mod_config((keycode >> 0x8) & 0x1F);
             action.code = ACTION_MODS_TAP_KEY(mod, keycode & 0xFF);
             break;
-    #ifdef BACKLIGHT_ENABLE
+#ifdef BACKLIGHT_ENABLE
         case BL_ON:
             action.code = ACTION_BACKLIGHT_ON();
             break;
@@ -150,12 +149,12 @@ action_t action_for_key(uint8_t layer, keypos_t key)
         case BL_STEP:
             action.code = ACTION_BACKLIGHT_STEP();
             break;
-    #endif
-    #ifdef SWAP_HANDS_ENABLE
+#endif
+#ifdef SWAP_HANDS_ENABLE
         case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
             action.code = ACTION(ACT_SWAP_HANDS, keycode & 0xff);
             break;
-    #endif
+#endif
 
         default:
             action.code = ACTION_NO;
@@ -164,42 +163,30 @@ action_t action_for_key(uint8_t layer, keypos_t key)
     return action;
 }
 
-__attribute__ ((weak))
-const uint16_t PROGMEM fn_actions[] = {
+__attribute__((weak)) const uint16_t PROGMEM fn_actions[] = {
 
 };
 
 /* Macro */
-__attribute__ ((weak))
-const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
-{
-    return MACRO_NONE;
-}
+__attribute__((weak)) const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { return MACRO_NONE; }
 
 /* Function */
-__attribute__ ((weak))
-void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
-{
-}
+__attribute__((weak)) void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {}
 
 // translates key to keycode
-__attribute__ ((weak))
-uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
-{
+__attribute__((weak)) uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
     // Read entire word (16bits)
     return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]);
 }
 
 // translates function id to action
-__attribute__ ((weak))
-uint16_t keymap_function_id_to_action( uint16_t function_id )
-{
-    // The compiler sees the empty (weak) fn_actions and generates a warning
-    // This function should not be called in that case, so the warning is too strict
-    // If this function is called however, the keymap should have overridden fn_actions, and then the compile
-    // is comparing against the wrong array
-    #pragma GCC diagnostic push
-    #pragma GCC diagnostic ignored "-Warray-bounds"
-       return pgm_read_word(&fn_actions[function_id]);
-    #pragma GCC diagnostic pop
+__attribute__((weak)) uint16_t keymap_function_id_to_action(uint16_t function_id) {
+// The compiler sees the empty (weak) fn_actions and generates a warning
+// This function should not be called in that case, so the warning is too strict
+// If this function is called however, the keymap should have overridden fn_actions, and then the compile
+// is comparing against the wrong array
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
+    return pgm_read_word(&fn_actions[function_id]);
+#pragma GCC diagnostic pop
 }
index ab89fbabfe62f1d3a31041aa9e1dccbe601949a3..55a0d892c52a9bc241cb0ba7d8532a7a30b40c2a 100644 (file)
 
 // Normal characters
 // Line 1
-#define BE_SUP2        KC_GRV
-#define BE_AMP KC_1
-#define BE_EACU        KC_2
-#define BE_QUOT        KC_3
-#define BE_APOS        KC_4
-#define BE_LPRN        KC_5
-#define BE_PARA        KC_6
-#define BE_EGRV        KC_7
-#define BE_EXLM        KC_8
-#define BE_CCED        KC_9
-#define BE_AGRV        KC_0
-#define BE_RPRN        KC_MINS
-#define BE_MINS        KC_EQL
+#define BE_SUP2 KC_GRV
+#define BE_AMP KC_1
+#define BE_EACU KC_2
+#define BE_QUOT KC_3
+#define BE_APOS KC_4
+#define BE_LPRN KC_5
+#define BE_PARA KC_6
+#define BE_EGRV KC_7
+#define BE_EXLM KC_8
+#define BE_CCED KC_9
+#define BE_AGRV KC_0
+#define BE_RPRN KC_MINS
+#define BE_MINS KC_EQL
 
 // Line 2
-#define BE_A    KC_Q
-#define BE_Z     KC_W
-#define        BE_CIRC KC_LBRC
-#define BE_DLR KC_RBRC
+#define BE_A KC_Q
+#define BE_Z KC_W
+#define BE_CIRC KC_LBRC
+#define BE_DLR KC_RBRC
 
 // Line 3
-#define BE_Q     KC_A
-#define BE_M     KC_SCLN
-#define BE_UGRV        KC_QUOT
-#define BE_MU  KC_NUHS
+#define BE_Q KC_A
+#define BE_M KC_SCLN
+#define BE_UGRV KC_QUOT
+#define BE_MU KC_NUHS
 
 // Line 4
-#define BE_LESS        KC_NUBS
-#define BE_W     KC_Z
-#define BE_COMM        KC_M
-#define BE_SCLN        KC_COMM
-#define BE_COLN        KC_DOT
-#define BE_EQL KC_SLSH
+#define BE_LESS KC_NUBS
+#define BE_W KC_Z
+#define BE_COMM KC_M
+#define BE_SCLN KC_COMM
+#define BE_COLN KC_DOT
+#define BE_EQL KC_SLSH
 
 // Shifted characters
 // Line 1
 #define BE_SUP3 KC_TILD
-#define BE_1   LSFT(KC_1)
-#define BE_2     LSFT(KC_2)
-#define BE_3     LSFT(KC_3)
-#define BE_4     LSFT(KC_4)
-#define BE_5     LSFT(KC_5)
-#define BE_6     LSFT(KC_6)
-#define BE_7     LSFT(KC_7)
-#define BE_8     LSFT(KC_8)
-#define BE_9     LSFT(KC_9)
-#define BE_0     LSFT(KC_0)
-#define BE_OVRR        KC_UNDS
+#define BE_1 LSFT(KC_1)
+#define BE_2 LSFT(KC_2)
+#define BE_3 LSFT(KC_3)
+#define BE_4 LSFT(KC_4)
+#define BE_5 LSFT(KC_5)
+#define BE_6 LSFT(KC_6)
+#define BE_7 LSFT(KC_7)
+#define BE_8 LSFT(KC_8)
+#define BE_9 LSFT(KC_9)
+#define BE_0 LSFT(KC_0)
+#define BE_OVRR KC_UNDS
 #define BE_UNDS KC_PLUS
 
 // Line 2
-#define BE_UMLT        LSFT(BE_CIRC)
-#define BE_PND LSFT(BE_DLR)
+#define BE_UMLT LSFT(BE_CIRC)
+#define BE_PND LSFT(BE_DLR)
 
 // Line 3
-#define        BE_PERC LSFT(BE_UGRV)
+#define BE_PERC LSFT(BE_UGRV)
 
 // Line 4
-#define BE_GRTR        LSFT(BE_LESS)
-#define BE_QUES        LSFT(BE_COMM)
-#define BE_DOT LSFT(BE_SCLN)
-#define BE_SLSH        LSFT(BE_COLN)
-#define BE_PLUS        LSFT(BE_EQL)
+#define BE_GRTR LSFT(BE_LESS)
+#define BE_QUES LSFT(BE_COMM)
+#define BE_DOT LSFT(BE_SCLN)
+#define BE_SLSH LSFT(BE_COLN)
+#define BE_PLUS LSFT(BE_EQL)
 
 // Alt Gr-ed characters
 // Line 1
 #define BE_PIPE ALGR(KC_1)
-#define BE_AT    ALGR(KC_2)
-#define BE_HASH        ALGR(KC_3)
+#define BE_AT ALGR(KC_2)
+#define BE_HASH ALGR(KC_3)
 #define BE_LCBR ALGR(KC_9)
-#define BE_RCBR        ALGR(KC_0)
+#define BE_RCBR ALGR(KC_0)
 
 // Line 2
-#define BE_EURO        ALGR(KC_E)
+#define BE_EURO ALGR(KC_E)
 #define BE_LSBR ALGR(BE_CIRC)
 #define BE_RSBR ALGR(BE_DLR)
 
 // Line 3
 #define BE_ACUT ALGR(BE_UGRV)
-#define BE_GRV ALGR(BE_MU)
+#define BE_GRV ALGR(BE_MU)
 
 // Line 4
 #define BE_BSLS ALGR(BE_LESS)
index 8d7b36ca3d1349f85d5dca32418b5ab829fe59bf..718baaa6838f8ac85b726ebb3a1b528657d980bc 100644 (file)
 
 // Normal characters
 // First row (on usual keyboards)
-#define BP_DOLLAR           KC_GRAVE            // $
-#define BP_DLR              BP_DOLLAR
-#define BP_DOUBLE_QUOTE     KC_1                // "
-#define BP_DQOT             BP_DOUBLE_QUOTE
-#define BP_LEFT_GUILLEMET   KC_2                // «
-#define BP_LGIL             BP_LEFT_GUILLEMET
-#define BP_RIGHT_GUILLEMET  KC_3                // »
-#define BP_RGIL             BP_RIGHT_GUILLEMET
-#define BP_LEFT_PAREN       KC_4                // (
-#define BP_LPRN             BP_LEFT_PAREN
-#define BP_RIGHT_PAREN      KC_5                // )
-#define BP_RPRN             BP_RIGHT_PAREN
-#define BP_AT               KC_6                // @
-#define BP_PLUS             KC_7                // +
-#define BP_MINUS            KC_8                // -
-#define BP_MINS             BP_MINUS
-#define BP_SLASH            KC_9                // /
-#define BP_SLSH             BP_SLASH
-#define BP_ASTERISK         KC_0                // *
-#define BP_ASTR             BP_ASTERISK
-#define BP_EQUAL            KC_MINUS            // =
-#define BP_EQL              BP_EQUAL
-#define BP_PERCENT          KC_EQUAL            // %
-#define BP_PERC             BP_PERCENT
+#define BP_DOLLAR KC_GRAVE  // $
+#define BP_DLR BP_DOLLAR
+#define BP_DOUBLE_QUOTE KC_1  // "
+#define BP_DQOT BP_DOUBLE_QUOTE
+#define BP_LEFT_GUILLEMET KC_2  // «
+#define BP_LGIL BP_LEFT_GUILLEMET
+#define BP_RIGHT_GUILLEMET KC_3  // »
+#define BP_RGIL BP_RIGHT_GUILLEMET
+#define BP_LEFT_PAREN KC_4  // (
+#define BP_LPRN BP_LEFT_PAREN
+#define BP_RIGHT_PAREN KC_5  // )
+#define BP_RPRN BP_RIGHT_PAREN
+#define BP_AT KC_6     // @
+#define BP_PLUS KC_7   // +
+#define BP_MINUS KC_8  // -
+#define BP_MINS BP_MINUS
+#define BP_SLASH KC_9  // /
+#define BP_SLSH BP_SLASH
+#define BP_ASTERISK KC_0  // *
+#define BP_ASTR BP_ASTERISK
+#define BP_EQUAL KC_MINUS  // =
+#define BP_EQL BP_EQUAL
+#define BP_PERCENT KC_EQUAL  // %
+#define BP_PERC BP_PERCENT
 
 // Second row
-#define BP_B                KC_Q
-#define BP_E_ACUTE          KC_W        // é
-#define BP_ECUT             BP_E_ACUTE
-#define BP_P                KC_E
-#define BP_O                KC_R
-#define BP_E_GRAVE          KC_T        // è
-#define BP_EGRV             BP_E_GRAVE
-#define BP_DEAD_CIRCUMFLEX  KC_Y        // dead ^
-#define BP_DCRC             BP_DEAD_CIRCUMFLEX
-#define BP_V                KC_U
-#define BP_D                KC_I
-#define BP_L                KC_O
-#define BP_J                KC_P
-#define BP_Z                KC_LBRACKET
-#define BP_W                KC_RBRACKET
+#define BP_B KC_Q
+#define BP_E_ACUTE KC_W  // é
+#define BP_ECUT BP_E_ACUTE
+#define BP_P KC_E
+#define BP_O KC_R
+#define BP_E_GRAVE KC_T  // è
+#define BP_EGRV BP_E_GRAVE
+#define BP_DEAD_CIRCUMFLEX KC_Y  // dead ^
+#define BP_DCRC BP_DEAD_CIRCUMFLEX
+#define BP_V KC_U
+#define BP_D KC_I
+#define BP_L KC_O
+#define BP_J KC_P
+#define BP_Z KC_LBRACKET
+#define BP_W KC_RBRACKET
 
 // Third row
-#define BP_A            KC_A
-#define BP_U            KC_S
-#define BP_I            KC_D
-#define BP_E            KC_F
-#define BP_COMMA        KC_G        // ,
-#define BP_COMM         BP_COMMA
-#define BP_C            KC_H
-#define BP_T            KC_J
-#define BP_S            KC_K
-#define BP_R            KC_L
-#define BP_N            KC_SCOLON
-#define BP_M            KC_QUOTE
-#define BP_C_CEDILLA    KC_BSLASH   // ç
-#define BP_CCED         BP_C_CEDILLA
+#define BP_A KC_A
+#define BP_U KC_S
+#define BP_I KC_D
+#define BP_E KC_F
+#define BP_COMMA KC_G  // ,
+#define BP_COMM BP_COMMA
+#define BP_C KC_H
+#define BP_T KC_J
+#define BP_S KC_K
+#define BP_R KC_L
+#define BP_N KC_SCOLON
+#define BP_M KC_QUOTE
+#define BP_C_CEDILLA KC_BSLASH  // ç
+#define BP_CCED BP_C_CEDILLA
 
 // Fourth row
-#define BP_E_CIRCUMFLEX     KC_NONUS_BSLASH // ê
-#define BP_ECRC             BP_E_CIRCUMFLEX
-#define BP_A_GRAVE          KC_Z            // à
-#define BP_AGRV             BP_A_GRAVE
-#define BP_Y                KC_X
-#define BP_X                KC_C
-#define BP_DOT              KC_V            // .
-#define BP_K                KC_B
-#define BP_APOSTROPHE       KC_N
-#define BP_APOS             BP_APOSTROPHE   // '
-#define BP_Q                KC_M
-#define BP_G                KC_COMMA
-#define BP_H                KC_DOT
-#define BP_F                KC_SLASH
+#define BP_E_CIRCUMFLEX KC_NONUS_BSLASH  // ê
+#define BP_ECRC BP_E_CIRCUMFLEX
+#define BP_A_GRAVE KC_Z  // à
+#define BP_AGRV BP_A_GRAVE
+#define BP_Y KC_X
+#define BP_X KC_C
+#define BP_DOT KC_V  // .
+#define BP_K KC_B
+#define BP_APOSTROPHE KC_N
+#define BP_APOS BP_APOSTROPHE  // '
+#define BP_Q KC_M
+#define BP_G KC_COMMA
+#define BP_H KC_DOT
+#define BP_F KC_SLASH
 
 // Shifted characters
 // First row
-#define BP_HASH     LSFT(BP_DOLLAR)     // #
-#define BP_1        LSFT(KC_1)
-#define BP_2        LSFT(KC_2)
-#define BP_3        LSFT(KC_3)
-#define BP_4        LSFT(KC_4)
-#define BP_5        LSFT(KC_5)
-#define BP_6        LSFT(KC_6)
-#define BP_7        LSFT(KC_7)
-#define BP_8        LSFT(KC_8)
-#define BP_9        LSFT(KC_9)
-#define BP_0        LSFT(KC_0)
-#define BP_DEGREE   LSFT(BP_EQUAL)      // °
-#define BP_DEGR     BP_DEGREE
-#define BP_GRAVE    LSFT(BP_PERCENT)    // `
-#define BP_GRV      BP_GRAVE
+#define BP_HASH LSFT(BP_DOLLAR)  // #
+#define BP_1 LSFT(KC_1)
+#define BP_2 LSFT(KC_2)
+#define BP_3 LSFT(KC_3)
+#define BP_4 LSFT(KC_4)
+#define BP_5 LSFT(KC_5)
+#define BP_6 LSFT(KC_6)
+#define BP_7 LSFT(KC_7)
+#define BP_8 LSFT(KC_8)
+#define BP_9 LSFT(KC_9)
+#define BP_0 LSFT(KC_0)
+#define BP_DEGREE LSFT(BP_EQUAL)  // °
+#define BP_DEGR BP_DEGREE
+#define BP_GRAVE LSFT(BP_PERCENT)  // `
+#define BP_GRV BP_GRAVE
 
 // Second row
-#define BP_EXCLAIM  LSFT(BP_DEAD_CIRCUMFLEX)    // !
-#define BP_EXLM     BP_EXCLAIM
+#define BP_EXCLAIM LSFT(BP_DEAD_CIRCUMFLEX)  // !
+#define BP_EXLM BP_EXCLAIM
 
 // Third row
-#define BP_SCOLON   LSFT(BP_COMMA)  // ;
-#define BP_SCLN     BP_SCOLON
+#define BP_SCOLON LSFT(BP_COMMA)  // ;
+#define BP_SCLN BP_SCOLON
 
 // Fourth row
-#define BP_COLON    LSFT(BP_DOT)    // :
-#define BP_COLN     BP_COLON
+#define BP_COLON LSFT(BP_DOT)  // :
+#define BP_COLN BP_COLON
 #define BP_QUESTION LSFT(BP_APOS)  // ?
-#define BP_QEST     BP_QUESTION
+#define BP_QEST BP_QUESTION
 
 // Space bar
-#define BP_NON_BREAKING_SPACE   LSFT(KC_SPACE)
-#define BP_NBSP                 BP_NON_BREAKING_SPACE
+#define BP_NON_BREAKING_SPACE LSFT(KC_SPACE)
+#define BP_NBSP BP_NON_BREAKING_SPACE
 
 // AltGr-ed characters
 // First row
-#define BP_EN_DASH          ALGR(BP_DOLLAR)     // –
-#define BP_NDSH             BP_EN_DASH
-#define BP_EM_DASH          ALGR(KC_1)          // —
-#define BP_MDSH             BP_EM_DASH
-#define BP_LESS             ALGR(KC_2)          // <
-#define BP_GREATER          ALGR(KC_3)          // >
-#define BP_GRTR             BP_GREATER
-#define BP_LBRACKET         ALGR(KC_4)          // [
-#define BP_LBRC             BP_LBRACKET
-#define BP_RBRACKET         ALGR(KC_5)          // ]
-#define BP_RBRC             BP_RBRACKET
-#define BP_CIRCUMFLEX       ALGR(KC_6)          // ^
-#define BP_CIRC             BP_CIRCUMFLEX
-#define BP_PLUS_MINUS       ALGR(KC_7)          // ±
-#define BP_PSMS             BP_PLUS_MINUS
-#define BP_MATH_MINUS       ALGR(KC_8)          // −
-#define BP_MMNS             BP_MATH_MINUS
-#define BP_OBELUS           ALGR(KC_9)          // ÷
-#define BP_OBEL             BP_OBELUS
+#define BP_EN_DASH ALGR(BP_DOLLAR)  // –
+#define BP_NDSH BP_EN_DASH
+#define BP_EM_DASH ALGR(KC_1)  // —
+#define BP_MDSH BP_EM_DASH
+#define BP_LESS ALGR(KC_2)     // <
+#define BP_GREATER ALGR(KC_3)  // >
+#define BP_GRTR BP_GREATER
+#define BP_LBRACKET ALGR(KC_4)  // [
+#define BP_LBRC BP_LBRACKET
+#define BP_RBRACKET ALGR(KC_5)  // ]
+#define BP_RBRC BP_RBRACKET
+#define BP_CIRCUMFLEX ALGR(KC_6)  // ^
+#define BP_CIRC BP_CIRCUMFLEX
+#define BP_PLUS_MINUS ALGR(KC_7)  // ±
+#define BP_PSMS BP_PLUS_MINUS
+#define BP_MATH_MINUS ALGR(KC_8)  // −
+#define BP_MMNS BP_MATH_MINUS
+#define BP_OBELUS ALGR(KC_9)  // ÷
+#define BP_OBEL BP_OBELUS
 // more conventional name of the symbol
-#define BP_DIVISION_SIGN    BP_OBELUS
-#define BP_DVSN             BP_DIVISION_SIGN
-#define BP_TIMES            ALGR(KC_0)          // ×
-#define BP_TIMS             BP_TIMES
-#define BP_DIFFERENT        ALGR(BP_EQUAL)      // ≠
-#define BP_DIFF             BP_DIFFERENT
-#define BP_PERMILLE         ALGR(BP_PERCENT)    // ‰
-#define BP_PMIL             BP_PERMILLE
+#define BP_DIVISION_SIGN BP_OBELUS
+#define BP_DVSN BP_DIVISION_SIGN
+#define BP_TIMES ALGR(KC_0)  // ×
+#define BP_TIMS BP_TIMES
+#define BP_DIFFERENT ALGR(BP_EQUAL)  // ≠
+#define BP_DIFF BP_DIFFERENT
+#define BP_PERMILLE ALGR(BP_PERCENT)  // ‰
+#define BP_PMIL BP_PERMILLE
 
 // Second row
-#define BP_PIPE                 ALGR(BP_B)          // |
-#define BP_DEAD_ACUTE           ALGR(BP_E_ACUTE)    // dead ´
-#define BP_DACT                 BP_DEAD_ACUTE
-#define BP_AMPERSAND            ALGR(BP_P)          // &
-#define BP_AMPR                 BP_AMPERSAND
-#define BP_OE_LIGATURE          ALGR(BP_O)          // œ
-#define BP_OE                   BP_OE_LIGATURE
-#define BP_DEAD_GRAVE           ALGR(BP_E_GRAVE)    // `
-#define BP_DGRV                 BP_DEAD_GRAVE
-#define BP_INVERTED_EXCLAIM     ALGR(BP_DEAD_CIRCUMFLEX)    // ¡
-#define BP_IXLM                 BP_INVERTED_EXCLAIM
-#define BP_DEAD_CARON           ALGR(BP_V)          // dead ˇ
-#define BP_DCAR                 BP_DEAD_CARON
-#define BP_ETH                  ALGR(BP_D)          // ð
-#define BP_DEAD_SLASH           ALGR(BP_L)          // dead /
-#define BP_DSLH                 BP_DEAD_SLASH
-#define BP_IJ_LIGATURE          ALGR(BP_J)          // ij
-#define BP_IJ                   BP_IJ_LIGATURE
-#define BP_SCHWA                ALGR(BP_Z)          // ə
-#define BP_SCWA                 BP_SCHWA
-#define BP_DEAD_BREVE           ALGR(BP_W)          // dead ˘
-#define BP_DBRV                 BP_DEAD_BREVE
+#define BP_PIPE ALGR(BP_B)              // |
+#define BP_DEAD_ACUTE ALGR(BP_E_ACUTE)  // dead ´
+#define BP_DACT BP_DEAD_ACUTE
+#define BP_AMPERSAND ALGR(BP_P)  // &
+#define BP_AMPR BP_AMPERSAND
+#define BP_OE_LIGATURE ALGR(BP_O)  // œ
+#define BP_OE BP_OE_LIGATURE
+#define BP_DEAD_GRAVE ALGR(BP_E_GRAVE)  // `
+#define BP_DGRV BP_DEAD_GRAVE
+#define BP_INVERTED_EXCLAIM ALGR(BP_DEAD_CIRCUMFLEX)  // ¡
+#define BP_IXLM BP_INVERTED_EXCLAIM
+#define BP_DEAD_CARON ALGR(BP_V)  // dead ˇ
+#define BP_DCAR BP_DEAD_CARON
+#define BP_ETH ALGR(BP_D)         // ð
+#define BP_DEAD_SLASH ALGR(BP_L)  // dead /
+#define BP_DSLH BP_DEAD_SLASH
+#define BP_IJ_LIGATURE ALGR(BP_J)  // ij
+#define BP_IJ BP_IJ_LIGATURE
+#define BP_SCHWA ALGR(BP_Z)  // ə
+#define BP_SCWA BP_SCHWA
+#define BP_DEAD_BREVE ALGR(BP_W)  // dead ˘
+#define BP_DBRV BP_DEAD_BREVE
 
 // Third row
-#define BP_AE_LIGATURE              ALGR(BP_A)          // æ
-#define BP_AE                       BP_AE_LIGATURE
-#define BP_U_GRAVE                  ALGR(BP_U)          // ù
-#define BP_UGRV                     BP_U_GRAVE
-#define BP_DEAD_TREMA               ALGR(BP_I)          // dead ¨ (trema/umlaut/diaresis)
-#define BP_DTRM                     BP_DEAD_TREMA
-#define BP_EURO                     ALGR(BP_E)          // €
-#define BP_TYPOGRAPHICAL_APOSTROPHE ALGR(BP_COMMA)      // ’
-#define BP_TAPO                     BP_TYPOGRAPHICAL_APOSTROPHE
-#define BP_COPYRIGHT                ALGR(BP_C)          // ©
-#define BP_CPRT                     BP_COPYRIGHT
-#define BP_THORN                    ALGR(BP_T)          // þ
-#define BP_THRN                     BP_THORN
-#define BP_SHARP_S                  ALGR(BP_S)          // ß
-#define BP_SRPS                     BP_SHARP_S
-#define BP_REGISTERED_TRADEMARK     ALGR(BP_R)          // ®
-#define BP_RTM                      BP_REGISTERED_TRADEMARK
-#define BP_DEAD_TILDE               ALGR(BP_N)          // dead ~
-#define BP_DTLD                     BP_DEAD_TILDE
-#define BP_DEAD_MACRON              ALGR(BP_M)          // dead ¯
-#define BP_DMCR                     BP_DEAD_MACRON
-#define BP_DEAD_CEDILLA             ALGR(BP_C_CEDILLA)  // dead ¸
-#define BP_DCED                     BP_DEAD_CEDILLA
+#define BP_AE_LIGATURE ALGR(BP_A)  // æ
+#define BP_AE BP_AE_LIGATURE
+#define BP_U_GRAVE ALGR(BP_U)  // ù
+#define BP_UGRV BP_U_GRAVE
+#define BP_DEAD_TREMA ALGR(BP_I)  // dead ¨ (trema/umlaut/diaresis)
+#define BP_DTRM BP_DEAD_TREMA
+#define BP_EURO ALGR(BP_E)                          // €
+#define BP_TYPOGRAPHICAL_APOSTROPHE ALGR(BP_COMMA)  // ’
+#define BP_TAPO BP_TYPOGRAPHICAL_APOSTROPHE
+#define BP_COPYRIGHT ALGR(BP_C)  // ©
+#define BP_CPRT BP_COPYRIGHT
+#define BP_THORN ALGR(BP_T)  // þ
+#define BP_THRN BP_THORN
+#define BP_SHARP_S ALGR(BP_S)  // ß
+#define BP_SRPS BP_SHARP_S
+#define BP_REGISTERED_TRADEMARK ALGR(BP_R)  // ®
+#define BP_RTM BP_REGISTERED_TRADEMARK
+#define BP_DEAD_TILDE ALGR(BP_N)  // dead ~
+#define BP_DTLD BP_DEAD_TILDE
+#define BP_DEAD_MACRON ALGR(BP_M)  // dead ¯
+#define BP_DMCR BP_DEAD_MACRON
+#define BP_DEAD_CEDILLA ALGR(BP_C_CEDILLA)  // dead ¸
+#define BP_DCED BP_DEAD_CEDILLA
 
 // Fourth row
-#define BP_NONUS_SLASH          ALGR(BP_E_CIRCUMFLEX)   // / on non-us backslash key (102nd key, ê in bépo)
-#define BP_NUSL                 BP_NONUS_SLASH
-#define BP_BACKSLASH            ALGR(BP_A_GRAVE)        /* \ */
-#define BP_BSLS                 BP_BACKSLASH
-#define BP_LEFT_CURLY_BRACE     ALGR(BP_Y)              // {
-#define BP_LCBR                 BP_LEFT_CURLY_BRACE
-#define BP_RIGHT_CURLY_BRACE    ALGR(BP_X)              // }
-#define BP_RCBR                 BP_RIGHT_CURLY_BRACE
-#define BP_ELLIPSIS             ALGR(BP_DOT)            // …
-#define BP_ELPS                 BP_ELLIPSIS
-#define BP_TILDE                ALGR(BP_K)              // ~
-#define BP_TILD                 BP_TILDE
-#define BP_INVERTED_QUESTION    ALGR(BP_QUESTION)       // ¿
-#define BP_IQST                 BP_INVERTED_QUESTION
-#define BP_DEAD_RING            ALGR(BP_Q)              // dead °
-#define BP_DRNG                 BP_DEAD_RING
-#define BP_DEAD_GREEK           ALGR(BP_G)              // dead Greek key (following key will make a Greek letter)
-#define BP_DGRK                 BP_DEAD_GREEK
-#define BP_DAGGER               ALGR(BP_H)              // †
-#define BP_DAGR                 BP_DAGGER
-#define BP_DEAD_OGONEK          ALGR(BP_F)              // dead ˛
-#define BP_DOGO                 BP_DEAD_OGONEK
+#define BP_NONUS_SLASH ALGR(BP_E_CIRCUMFLEX)  // / on non-us backslash key (102nd key, ê in bépo)
+#define BP_NUSL BP_NONUS_SLASH
+#define BP_BACKSLASH ALGR(BP_A_GRAVE) /* \ */
+#define BP_BSLS BP_BACKSLASH
+#define BP_LEFT_CURLY_BRACE ALGR(BP_Y)  // {
+#define BP_LCBR BP_LEFT_CURLY_BRACE
+#define BP_RIGHT_CURLY_BRACE ALGR(BP_X)  // }
+#define BP_RCBR BP_RIGHT_CURLY_BRACE
+#define BP_ELLIPSIS ALGR(BP_DOT)  // …
+#define BP_ELPS BP_ELLIPSIS
+#define BP_TILDE ALGR(BP_K)  // ~
+#define BP_TILD BP_TILDE
+#define BP_INVERTED_QUESTION ALGR(BP_QUESTION)  // ¿
+#define BP_IQST BP_INVERTED_QUESTION
+#define BP_DEAD_RING ALGR(BP_Q)  // dead °
+#define BP_DRNG BP_DEAD_RING
+#define BP_DEAD_GREEK ALGR(BP_G)  // dead Greek key (following key will make a Greek letter)
+#define BP_DGRK BP_DEAD_GREEK
+#define BP_DAGGER ALGR(BP_H)  // †
+#define BP_DAGR BP_DAGGER
+#define BP_DEAD_OGONEK ALGR(BP_F)  // dead ˛
+#define BP_DOGO BP_DEAD_OGONEK
 
 // Space bar
-#define BP_UNDERSCORE   ALGR(KC_SPACE)      // _
-#define BP_UNDS         BP_UNDERSCORE
+#define BP_UNDERSCORE ALGR(KC_SPACE)  // _
+#define BP_UNDS BP_UNDERSCORE
 
 // AltGr-Shifted characters (different from capitalised AltGr-ed characters)
 // First row
-#define BP_PARAGRAPH            ALGR(BP_HASH)       // ¶
-#define BP_PARG                 BP_PARAGRAPH
-#define BP_LOW_DOUBLE_QUOTE     ALGR(BP_1)          // „
-#define BP_LWQT                 BP_LOW_DOUBLE_QUOTE
-#define BP_LEFT_DOUBLE_QUOTE    ALGR(BP_2)          // “
-#define BP_LDQT                 BP_LEFT_DOUBLE_QUOTE
-#define BP_RIGHT_DOUBLE_QUOTE   ALGR(BP_3)          // ”
-#define BP_RDQT                 BP_RIGHT_DOUBLE_QUOTE
-#define BP_LESS_OR_EQUAL        ALGR(BP_4)          // ≤
-#define BP_LEQL                 BP_LESS_OR_EQUAL
-#define BP_GREATER_OR_EQUAL     ALGR(BP_5)          // ≥
-#define BP_GEQL                 BP_GREATER_OR_EQUAL
+#define BP_PARAGRAPH ALGR(BP_HASH)  // ¶
+#define BP_PARG BP_PARAGRAPH
+#define BP_LOW_DOUBLE_QUOTE ALGR(BP_1)  // „
+#define BP_LWQT BP_LOW_DOUBLE_QUOTE
+#define BP_LEFT_DOUBLE_QUOTE ALGR(BP_2)  // “
+#define BP_LDQT BP_LEFT_DOUBLE_QUOTE
+#define BP_RIGHT_DOUBLE_QUOTE ALGR(BP_3)  // ”
+#define BP_RDQT BP_RIGHT_DOUBLE_QUOTE
+#define BP_LESS_OR_EQUAL ALGR(BP_4)  // ≤
+#define BP_LEQL BP_LESS_OR_EQUAL
+#define BP_GREATER_OR_EQUAL ALGR(BP_5)  // ≥
+#define BP_GEQL BP_GREATER_OR_EQUAL
 // nothing on ALGR(BP_6)
-#define BP_NEGATION             ALGR(BP_7)          // ¬
-#define BP_NEGT                 BP_NEGATION
-#define BP_ONE_QUARTER          ALGR(BP_8)          // ¼
-#define BP_1QRT                 BP_ONE_QUARTER
-#define BP_ONE_HALF             ALGR(BP_9)          // ½
-#define BP_1HLF                 BP_ONE_HALF
-#define BP_THREE_QUARTERS       ALGR(BP_0)          // ¾
-#define BP_3QRT                 BP_THREE_QUARTERS
-#define BP_MINUTES              ALGR(BP_DEGREE)     // ′
-#define BP_MNUT                 BP_MINUTES
-#define BP_SECONDS              ALGR(BP_GRAVE)      // ″
-#define BP_SCND                 BP_SECONDS
+#define BP_NEGATION ALGR(BP_7)  // ¬
+#define BP_NEGT BP_NEGATION
+#define BP_ONE_QUARTER ALGR(BP_8)  // ¼
+#define BP_1QRT BP_ONE_QUARTER
+#define BP_ONE_HALF ALGR(BP_9)  // ½
+#define BP_1HLF BP_ONE_HALF
+#define BP_THREE_QUARTERS ALGR(BP_0)  // ¾
+#define BP_3QRT BP_THREE_QUARTERS
+#define BP_MINUTES ALGR(BP_DEGREE)  // ′
+#define BP_MNUT BP_MINUTES
+#define BP_SECONDS ALGR(BP_GRAVE)  // ″
+#define BP_SCND BP_SECONDS
 
 // Second row
-#define BP_BROKEN_PIPE          LSFT(BP_PIPE)           // ¦
-#define BP_BPIP                 BP_BROKEN_PIPE
-#define BP_DEAD_DOUBLE_ACUTE    LSFT(BP_DEAD_ACUTE)     // ˝
-#define BP_DDCT                 BP_DEAD_DOUBLE_ACUTE
-#define BP_SECTION              ALGR(LSFT(BP_P))        // §
-#define BP_SECT                 BP_SECTION
+#define BP_BROKEN_PIPE LSFT(BP_PIPE)  // ¦
+#define BP_BPIP BP_BROKEN_PIPE
+#define BP_DEAD_DOUBLE_ACUTE LSFT(BP_DEAD_ACUTE)  // ˝
+#define BP_DDCT BP_DEAD_DOUBLE_ACUTE
+#define BP_SECTION ALGR(LSFT(BP_P))  // §
+#define BP_SECT BP_SECTION
 // LSFT(BP_DEAD_GRAVE) is actually the same character as LSFT(BP_PERCENT)
-#define BP_GRAVE_BIS            LSFT(BP_DEAD_GRAVE)     // `
-#define BP_GRVB                 BP_GRAVE_BIS
+#define BP_GRAVE_BIS LSFT(BP_DEAD_GRAVE)  // `
+#define BP_GRVB BP_GRAVE_BIS
 
 // Third row
-#define BP_DEAD_DOT_ABOVE       LSFT(BP_DEAD_TREMA)     // dead ˙
-#define BP_DDTA                 BP_DEAD_DOT_ABOVE
-#define BP_DEAD_CURRENCY        LSFT(BP_EURO)           // dead ¤ (next key will generate a currency code like ¥ or £)
-#define BP_DCUR                 BP_DEAD_CURRENCY
-#define BP_DEAD_HORN            LSFT(ALGR(BP_COMMA))    // dead ̛
-#define BP_DHRN                 BP_DEAD_HORN
-#define BP_LONG_S               LSFT(ALGR(BP_C))        // ſ
-#define BP_LNGS                 BP_LONG_S
-#define BP_TRADEMARK            LSFT(BP_REGISTERED_TRADEMARK)   // ™
-#define BP_TM                   BP_TRADEMARK
-#define BP_ORDINAL_INDICATOR_O  LSFT(ALGR(BP_M))        // º
-#define BP_ORDO                 BP_ORDINAL_INDICATOR_O
-#define BP_DEAD_COMMA           LSFT(BP_DEAD_CEDILLA)   // dead ˛
-#define BP_DCOM                 BP_DEAD_COMMA
+#define BP_DEAD_DOT_ABOVE LSFT(BP_DEAD_TREMA)  // dead ˙
+#define BP_DDTA BP_DEAD_DOT_ABOVE
+#define BP_DEAD_CURRENCY LSFT(BP_EURO)  // dead ¤ (next key will generate a currency code like ¥ or £)
+#define BP_DCUR BP_DEAD_CURRENCY
+#define BP_DEAD_HORN LSFT(ALGR(BP_COMMA))  // dead ̛
+#define BP_DHRN BP_DEAD_HORN
+#define BP_LONG_S LSFT(ALGR(BP_C))  // ſ
+#define BP_LNGS BP_LONG_S
+#define BP_TRADEMARK LSFT(BP_REGISTERED_TRADEMARK)  // ™
+#define BP_TM BP_TRADEMARK
+#define BP_ORDINAL_INDICATOR_O LSFT(ALGR(BP_M))  // º
+#define BP_ORDO BP_ORDINAL_INDICATOR_O
+#define BP_DEAD_COMMA LSFT(BP_DEAD_CEDILLA)  // dead ˛
+#define BP_DCOM BP_DEAD_COMMA
 
 // Fourth row
-#define BP_LEFT_QUOTE           LSFT(ALGR(BP_Y))        // ‘
-#define BP_LQOT                 BP_LEFT_QUOTE
-#define BP_RIGHT_QUOTE          LSFT(ALGR(BP_X))        // ’
-#define BP_RQOT                 BP_RIGHT_QUOTE
-#define BP_INTERPUNCT           LSFT(ALGR(BP_DOT))      // ·
-#define BP_IPCT                 BP_INTERPUNCT
-#define BP_DEAD_HOOK_ABOVE      LSFT(ALGR(BP_QUESTION)) // dead ̉
-#define BP_DHKA                 BP_DEAD_HOOK_ABOVE
-#define BP_DEAD_UNDERDOT        LSFT(BP_DEAD_RING)      // dead ̣
-#define BP_DUDT                 BP_DEAD_UNDERDOT
-#define BP_DOUBLE_DAGGER        LSFT(BP_DAGGER)         // ‡
-#define BP_DDGR                 BP_DOUBLE_DAGGER
-#define BP_ORDINAL_INDICATOR_A  LSFT(ALGR(BP_F))        // ª
-#define BP_ORDA                 BP_ORDINAL_INDICATOR_A
+#define BP_LEFT_QUOTE LSFT(ALGR(BP_Y))  // ‘
+#define BP_LQOT BP_LEFT_QUOTE
+#define BP_RIGHT_QUOTE LSFT(ALGR(BP_X))  // ’
+#define BP_RQOT BP_RIGHT_QUOTE
+#define BP_INTERPUNCT LSFT(ALGR(BP_DOT))  // ·
+#define BP_IPCT BP_INTERPUNCT
+#define BP_DEAD_HOOK_ABOVE LSFT(ALGR(BP_QUESTION))  // dead ̉
+#define BP_DHKA BP_DEAD_HOOK_ABOVE
+#define BP_DEAD_UNDERDOT LSFT(BP_DEAD_RING)  // dead ̣
+#define BP_DUDT BP_DEAD_UNDERDOT
+#define BP_DOUBLE_DAGGER LSFT(BP_DAGGER)  // ‡
+#define BP_DDGR BP_DOUBLE_DAGGER
+#define BP_ORDINAL_INDICATOR_A LSFT(ALGR(BP_F))  // ª
+#define BP_ORDA BP_ORDINAL_INDICATOR_A
 
 // Space bar
-#define BP_NARROW_NON_BREAKING_SPACE    ALGR(BP_NON_BREAKING_SPACE)
-#define BP_NNBS                         BP_NARROW_NON_BREAKING_SPACE
+#define BP_NARROW_NON_BREAKING_SPACE ALGR(BP_NON_BREAKING_SPACE)
+#define BP_NNBS BP_NARROW_NON_BREAKING_SPACE
 
 #endif
index 63b917d8fc65ce161637db8932d8b95bc83b348b..eecd6f2b0b22f9164332cdcfa6c0461c3a7f864f 100644 (file)
 
 /* Scan codes for the Brazilian ABNT2 keyboard layout */
 
-#define BR_CCDL KC_SCLN      //  Ç   same scancode as ;: on US layout
-#define BR_SCLN KC_SLSH      //  ;:  same scancode as /? on US layout
-#define BR_QUOT KC_GRV       //  '"  same scancode as `~ on US layout
-#define BR_TILD KC_QUOT      //  ~^  dead keys, same scancode as '" on US layout
-#define BR_ACUT KC_LBRC      //  ´`  dead keys, same scancode as [{ on US layout
-#define BR_LBRC KC_RBRC      //  [{  same scancode as ]} on US layout
-#define BR_RBRC KC_BSLS      //  ]}  same scancode as \| on US layout
-#define BR_BSLS KC_NUBS      //  \|  uses the non-US hash scancode (#~, sometimes §±)
-#define BR_SLSH KC_INT1      //  /?  uses the INTL1 scancode
+#define BR_CCDL KC_SCLN  //  Ç   same scancode as ;: on US layout
+#define BR_SCLN KC_SLSH  //  ;:  same scancode as /? on US layout
+#define BR_QUOT KC_GRV   //  '"  same scancode as `~ on US layout
+#define BR_TILD KC_QUOT  //  ~^  dead keys, same scancode as '" on US layout
+#define BR_ACUT KC_LBRC  //  ´`  dead keys, same scancode as [{ on US layout
+#define BR_LBRC KC_RBRC  //  [{  same scancode as ]} on US layout
+#define BR_RBRC KC_BSLS  //  ]}  same scancode as \| on US layout
+#define BR_BSLS KC_NUBS  //  \|  uses the non-US hash scancode (#~, sometimes §±)
+#define BR_SLSH KC_INT1  //  /?  uses the INTL1 scancode
 
-#define BR_COLN LSFT(BR_SCLN)   // shifted :
-#define BR_DQT  LSFT(BR_QUOT)   // shifted "
-#define BR_CIRC LSFT(BR_TILD)   // shifted ^ (dead key)
-#define BR_GRAV LSFT(BR_ACUT)   // shifted ` (dead key)
-#define BR_LCBR LSFT(BR_LBRC)   // shifted {
-#define BR_RCBR LSFT(BR_RBRC)   // shifted }
-#define BR_PIPE LSFT(BR_BSLS)   // shifted |
-#define BR_QUES LSFT(BR_SLSH)   // shifted ?
-#define BR_TRMA LSFT(KC_6)      // shifted ¨ (dead key - trema accent)
+#define BR_COLN LSFT(BR_SCLN)  // shifted :
+#define BR_DQT LSFT(BR_QUOT)   // shifted "
+#define BR_CIRC LSFT(BR_TILD)  // shifted ^ (dead key)
+#define BR_GRAV LSFT(BR_ACUT)  // shifted ` (dead key)
+#define BR_LCBR LSFT(BR_LBRC)  // shifted {
+#define BR_RCBR LSFT(BR_RBRC)  // shifted }
+#define BR_PIPE LSFT(BR_BSLS)  // shifted |
+#define BR_QUES LSFT(BR_SLSH)  // shifted ?
+#define BR_TRMA LSFT(KC_6)     // shifted ¨ (dead key - trema accent)
 
 // On the ABNT2 the keypad comma and the keypad dot scancodes are switched
 // (presumably because in Brazil comma is used as the decimal separator)
 #define BR_KPDT KC_KP_COMMA  //  keypad .
 #define BR_KPCM KC_KP_DOT    //  keypad ,
 
-#define BR_1UP    LALT(KC_1)      // 1 superscript                    ¹   alt+1
-#define BR_2UP    LALT(KC_2)      // 2 superscript                    ²   alt+2
-#define BR_3UP    LALT(KC_3)      // 3 superscript                    ³   alt+3
-#define BR_PND    LALT(KC_4)      // Pound sign                       £   alt+4
-#define BR_CENT   LALT(KC_5)      // Cent sign                        ¢   alt+5
-#define BR_NOT    LALT(KC_6)      // Not sign                         ¬   alt+6
-#define BR_SECT   LALT(KC_EQL)    // Section sign                     §   alt+=
-#define BR_FORD   LALT(BR_LBRC)   // Feminine Ordinal Sign            ª   alt+[
-#define BR_MORD   LALT(BR_RBRC)   // Masculine Ordinal Sign           º   alt+]
-#define BR_DGRE   LALT(BR_SLSH)   // Degree sign                      °   alt+/
+#define BR_1UP LALT(KC_1)      // 1 superscript                    ¹   alt+1
+#define BR_2UP LALT(KC_2)      // 2 superscript                    ²   alt+2
+#define BR_3UP LALT(KC_3)      // 3 superscript                    ³   alt+3
+#define BR_PND LALT(KC_4)      // Pound sign                       £   alt+4
+#define BR_CENT LALT(KC_5)     // Cent sign                        ¢   alt+5
+#define BR_NOT LALT(KC_6)      // Not sign                         ¬   alt+6
+#define BR_SECT LALT(KC_EQL)   // Section sign                     §   alt+=
+#define BR_FORD LALT(BR_LBRC)  // Feminine Ordinal Sign            ª   alt+[
+#define BR_MORD LALT(BR_RBRC)  // Masculine Ordinal Sign           º   alt+]
+#define BR_DGRE LALT(BR_SLSH)  // Degree sign                      °   alt+/
 
-#define BR_EURO   LALT(KC_E)      // Euro sign                        €   alt+e
-#define BR_NDTD   LALT(BR_TILD)   // Non-dead key tilde               ~   alt+~
-#define BR_NDAC   LALT(BR_ACUT)   // Non-dead key acute accent        ´   alt+´
-#define BR_NDGV   LALT(BR_QUOT)   // Non-dead key grave accent        `   alt+'
-#define BR_NDCR   LALT(BR_CIRC)   // Non-dead key circumflex accent   ^   alt+^ (alt+shift+~)
-#define BR_NDTR   LALT(BR_TRMA)   // Non-dead key trema accent        ¨   alt+¨ (alt+shift+6)
+#define BR_EURO LALT(KC_E)     // Euro sign                        €   alt+e
+#define BR_NDTD LALT(BR_TILD)  // Non-dead key tilde               ~   alt+~
+#define BR_NDAC LALT(BR_ACUT)  // Non-dead key acute accent        ´   alt+´
+#define BR_NDGV LALT(BR_QUOT)  // Non-dead key grave accent        `   alt+'
+#define BR_NDCR LALT(BR_CIRC)  // Non-dead key circumflex accent   ^   alt+^ (alt+shift+~)
+#define BR_NDTR LALT(BR_TRMA)  // Non-dead key trema accent        ¨   alt+¨ (alt+shift+6)
 
 // For 101-key keyboard layouts, the ABNT2 layout allows
 // the slash and question mark to be typed using alt+q and alt+w.
 // The shortcuts are provided here for completeness' sake,
 // but it's recommended to use BR_SLSH and BR_QUES instead
-#define BR_ASLS   LALT(KC_Q)
-#define BR_AQST   LALT(KC_W)
+#define BR_ASLS LALT(KC_Q)
+#define BR_AQST LALT(KC_W)
 
 #endif
index 2b5b95d6fab91be57bd761916f4a63b38d7ac42e..4fc174e7352a830db0709fcac3f5ab3ff1101aa9 100644 (file)
 #include "keymap.h"
 
 #ifndef GR2A
-#define GR2A(kc)    RCTL(kc)
+#    define GR2A(kc) RCTL(kc)
 #endif
 
 // Normal characters
 // First row
-#define CSA_SLASH   KC_GRV      // /
-#define CSA_SLSH    CSA_SLASH
+#define CSA_SLASH KC_GRV  // /
+#define CSA_SLSH CSA_SLASH
 
 // Second row
-#define CSA_DEAD_CIRCUMFLEX     KC_LBRACKET         // dead ^
-#define CSA_DCRC                CSA_DEAD_CIRCUMFLEX
-#define CSA_C_CEDILLA           KC_RBRACKET         // Ç
-#define CSA_CCED                CSA_C_CEDILLA
+#define CSA_DEAD_CIRCUMFLEX KC_LBRACKET  // dead ^
+#define CSA_DCRC CSA_DEAD_CIRCUMFLEX
+#define CSA_C_CEDILLA KC_RBRACKET  // Ç
+#define CSA_CCED CSA_C_CEDILLA
 
 // Third row
-#define CSA_E_GRAVE     KC_QUOT     // è
-#define CSA_EGRV        CSA_E_GRAVE
-#define CSA_A_GRAVE     KC_BSLASH   // à
-#define CSA_AGRV        CSA_A_GRAVE
+#define CSA_E_GRAVE KC_QUOT  // è
+#define CSA_EGRV CSA_E_GRAVE
+#define CSA_A_GRAVE KC_BSLASH  // à
+#define CSA_AGRV CSA_A_GRAVE
 
 // Fourth row
-#define CSA_U_GRAVE     KC_NONUS_BSLASH     // ù
-#define CSA_UGRV        CSA_U_GRAVE
-#define CSA_E_ACUTE     KC_SLSH             // é
-#define CSA_ECUT        CSA_E_ACUTE
+#define CSA_U_GRAVE KC_NONUS_BSLASH  // ù
+#define CSA_UGRV CSA_U_GRAVE
+#define CSA_E_ACUTE KC_SLSH  // é
+#define CSA_ECUT CSA_E_ACUTE
 
 // Shifted characters
 // First row
-#define CSA_BACKSLASH   LSFT(CSA_SLASH) /* \ */
-#define CSA_BSLS        CSA_BACKSLASH
-#define CSA_QUESTION    LSFT(KC_6)      // ?
-#define CSA_QEST        CSA_QUESTION
+#define CSA_BACKSLASH LSFT(CSA_SLASH) /* \ */
+#define CSA_BSLS CSA_BACKSLASH
+#define CSA_QUESTION LSFT(KC_6)  // ?
+#define CSA_QEST CSA_QUESTION
 
 // Second row
-#define CSA_DEAD_TREMA  LSFT(CSA_DEAD_CIRCUMFLEX)    // dead trema/umlaut/diaresis for ä ë ï ö ü
-#define CSA_DTRM        CSA_DEAD_TREMA
+#define CSA_DEAD_TREMA LSFT(CSA_DEAD_CIRCUMFLEX)  // dead trema/umlaut/diaresis for ä ë ï ö ü
+#define CSA_DTRM CSA_DEAD_TREMA
 
 // Third row
 // all same as US-QWERTY, or capitalised character of the non-shifted key
 
 // Fourth row
-#define CSA_APOSTROPHE      LSFT(KC_COMMA)  // '
-#define CSA_APOS            CSA_APOSTROPHE
-#define CSA_DOUBLE_QUOTE    LSFT(KC_DOT)    // "
-#define CSA_DQOT            CSA_DOUBLE_QUOTE
+#define CSA_APOSTROPHE LSFT(KC_COMMA)  // '
+#define CSA_APOS CSA_APOSTROPHE
+#define CSA_DOUBLE_QUOTE LSFT(KC_DOT)  // "
+#define CSA_DQOT CSA_DOUBLE_QUOTE
 
 // Alt Gr-ed characters
 // First row
-#define CSA_PIPE                ALGR(CSA_SLASH)         // |
-#define CSA_CURRENCY            ALGR(KC_4)              // ¤
-#define CSA_CURR                CSA_CURRENCY
-#define CSA_LEFT_CURLY_BRACE    ALGR(KC_7)              // {
-#define CSA_LCBR                CSA_LEFT_CURLY_BRACE
-#define CSA_RIGHT_CURLY_BRACE   ALGR(KC_8)              // }
-#define CSA_RCBR                CSA_RIGHT_CURLY_BRACE
-#define CSA_LBRACKET            ALGR(KC_9)              // [
-#define CSA_LBRC                CSA_LBRACKET
-#define CSA_RBRACKET            ALGR(KC_0)              // ]
-#define CSA_RBRC                CSA_RBRACKET
-#define CSA_NEGATION            ALGR(KC_EQUAL)          // ¬
-#define CSA_NEGT                CSA_NEGATION
+#define CSA_PIPE ALGR(CSA_SLASH)  // |
+#define CSA_CURRENCY ALGR(KC_4)   // ¤
+#define CSA_CURR CSA_CURRENCY
+#define CSA_LEFT_CURLY_BRACE ALGR(KC_7)  // {
+#define CSA_LCBR CSA_LEFT_CURLY_BRACE
+#define CSA_RIGHT_CURLY_BRACE ALGR(KC_8)  // }
+#define CSA_RCBR CSA_RIGHT_CURLY_BRACE
+#define CSA_LBRACKET ALGR(KC_9)  // [
+#define CSA_LBRC CSA_LBRACKET
+#define CSA_RBRACKET ALGR(KC_0)  // ]
+#define CSA_RBRC CSA_RBRACKET
+#define CSA_NEGATION ALGR(KC_EQUAL)  // ¬
+#define CSA_NEGT CSA_NEGATION
 
 // Second row
 // euro symbol not available on Linux? (X.org)
-#define CSA_EURO        ALGR(KC_E)                  // €
-#define CSA_DEAD_GRAVE  ALGR(CSA_DEAD_CIRCUMFLEX)
-#define CSA_DGRV        CSA_DEAD_GRAVE              // dead `
-#define CSA_DEAD_TILDE  ALGR(CSA_C_CEDILLA)         // ~
-#define CSA_DTLD        CSA_DEAD_TILDE
+#define CSA_EURO ALGR(KC_E)  // €
+#define CSA_DEAD_GRAVE ALGR(CSA_DEAD_CIRCUMFLEX)
+#define CSA_DGRV CSA_DEAD_GRAVE             // dead `
+#define CSA_DEAD_TILDE ALGR(CSA_C_CEDILLA)  // ~
+#define CSA_DTLD CSA_DEAD_TILDE
 
 // Third row
-#define CSA_DEGREE  ALGR(KC_SCOLON)     // °
-#define CSA_DEGR    CSA_DEGREE
+#define CSA_DEGREE ALGR(KC_SCOLON)  // °
+#define CSA_DEGR CSA_DEGREE
 
 // Fourth row
-#define CSA_LEFT_GUILLEMET      ALGR(KC_Z)          // «
-#define CSA_LGIL                CSA_LEFT_GUILLEMET
-#define CSA_RIGHT_GUILLEMET     ALGR(KC_X)          // »
-#define CSA_RGIL                CSA_RIGHT_GUILLEMET
-#define CSA_LESS                ALGR(KC_COMMA)      // <
-#define CSA_GREATER             ALGR(KC_DOT)        // >
-#define CSA_GRTR                CSA_GREATER
+#define CSA_LEFT_GUILLEMET ALGR(KC_Z)  // «
+#define CSA_LGIL CSA_LEFT_GUILLEMET
+#define CSA_RIGHT_GUILLEMET ALGR(KC_X)  // »
+#define CSA_RGIL CSA_RIGHT_GUILLEMET
+#define CSA_LESS ALGR(KC_COMMA)   // <
+#define CSA_GREATER ALGR(KC_DOT)  // >
+#define CSA_GRTR CSA_GREATER
 
 // Space bar
-#define CSA_NON_BREAKING_SPACE  ALGR(KC_SPACE)
-#define CSA_NBSP                CSA_NON_BREAKING_SPACE
+#define CSA_NON_BREAKING_SPACE ALGR(KC_SPACE)
+#define CSA_NBSP CSA_NON_BREAKING_SPACE
 
 // GR2A-ed characters
 // First row
-#define CSA_SUPERSCRIPT_ONE     GR2A(KC_1)  // ¹
-#define CSA_SUP1                CSA_SUPERSCRIPT_ONE
-#define CSA_SUPERSCRIPT_TWO     GR2A(KC_2)  // ²
-#define CSA_SUP2                CSA_SUPERSCRIPT_TWO
-#define CSA_SUPERSCRIPT_THREE   GR2A(KC_3)  // ³
-#define CSA_SUP3                CSA_SUPERSCRIPT_THREE
-#define CSA_ONE_QUARTER         GR2A(KC_4)  // ¼
-#define CSA_1QRT                CSA_ONE_QUARTER
-#define CSA_ONE_HALF            GR2A(KC_5)  // ½
-#define CSA_1HLF                CSA_ONE_HALF
-#define CSA_THREE_QUARTERS      GR2A(KC_6)  // ¾
-#define CSA_3QRT                CSA_THREE_QUARTERS
+#define CSA_SUPERSCRIPT_ONE GR2A(KC_1)  // ¹
+#define CSA_SUP1 CSA_SUPERSCRIPT_ONE
+#define CSA_SUPERSCRIPT_TWO GR2A(KC_2)  // ²
+#define CSA_SUP2 CSA_SUPERSCRIPT_TWO
+#define CSA_SUPERSCRIPT_THREE GR2A(KC_3)  // ³
+#define CSA_SUP3 CSA_SUPERSCRIPT_THREE
+#define CSA_ONE_QUARTER GR2A(KC_4)  // ¼
+#define CSA_1QRT CSA_ONE_QUARTER
+#define CSA_ONE_HALF GR2A(KC_5)  // ½
+#define CSA_1HLF CSA_ONE_HALF
+#define CSA_THREE_QUARTERS GR2A(KC_6)  // ¾
+#define CSA_3QRT CSA_THREE_QUARTERS
 // nothing on 7-0 and -
-#define CSA_DEAD_CEDILLA        GR2A(KC_EQUAL)  // dead ¸
-#define CSA_DCED                CSA_DEAD_CEDILLA
+#define CSA_DEAD_CEDILLA GR2A(KC_EQUAL)  // dead ¸
+#define CSA_DCED CSA_DEAD_CEDILLA
 
 // Second row
-#define CSA_OMEGA           GR2A(KC_Q)  // ω
-#define CSA_OMEG            CSA_OMEGA
-#define CSA_L_STROKE        GR2A(KC_W)  // ł
-#define CSA_LSTK            CSA_L_STROKE
-#define CSA_OE_LIGATURE     GR2A(KC_E)  // œ
-#define CSA_OE              CSA_OE_LIGATURE
-#define CSA_PARAGRAPH       GR2A(KC_R)  // ¶
-#define CSA_PARG            CSA_PARAGRAPH
-#define CSA_T_STROKE        GR2A(KC_T)  // ŧ
-#define CSA_LEFT_ARROW      GR2A(KC_Y)  // ←
-#define CSA_LARW            CSA_LEFT_ARROW
-#define CSA_DOWN_ARROW      GR2A(KC_U)  // ↓
-#define CSA_DARW            CSA_DOWN_ARROW
-#define CSA_RIGHT_ARROW     GR2A(KC_I)  // →
-#define CSA_RARW            CSA_RIGHT_ARROW
-#define CSA_O_STROKE        GR2A(KC_O)  // ø
-#define CSA_OSTK            CSA_O_STROKE
-#define CSA_THORN           GR2A(KC_P)  // þ
-#define CSA_THRN            CSA_THORN
+#define CSA_OMEGA GR2A(KC_Q)  // ω
+#define CSA_OMEG CSA_OMEGA
+#define CSA_L_STROKE GR2A(KC_W)  // ł
+#define CSA_LSTK CSA_L_STROKE
+#define CSA_OE_LIGATURE GR2A(KC_E)  // œ
+#define CSA_OE CSA_OE_LIGATURE
+#define CSA_PARAGRAPH GR2A(KC_R)  // ¶
+#define CSA_PARG CSA_PARAGRAPH
+#define CSA_T_STROKE GR2A(KC_T)    // ŧ
+#define CSA_LEFT_ARROW GR2A(KC_Y)  // ←
+#define CSA_LARW CSA_LEFT_ARROW
+#define CSA_DOWN_ARROW GR2A(KC_U)  // ↓
+#define CSA_DARW CSA_DOWN_ARROW
+#define CSA_RIGHT_ARROW GR2A(KC_I)  // →
+#define CSA_RARW CSA_RIGHT_ARROW
+#define CSA_O_STROKE GR2A(KC_O)  // ø
+#define CSA_OSTK CSA_O_STROKE
+#define CSA_THORN GR2A(KC_P)  // þ
+#define CSA_THRN CSA_THORN
 // nothing on ^
-#define CSA_TILDE           GR2A(CSA_C_CEDILLA)  // dead ~
-#define CSA_TILD            CSA_TILDE
+#define CSA_TILDE GR2A(CSA_C_CEDILLA)  // dead ~
+#define CSA_TILD CSA_TILDE
 
 // Third row
-#define CSA_AE_LIGATURE     GR2A(KC_A)      // æ
-#define CSA_AE              CSA_AE_LIGATURE
-#define CSA_SHARP_S         GR2A(KC_S)      // ß
-#define CSA_SRPS            CSA_SHARP_S
-#define CSA_ETH             GR2A(KC_D)      // ð
+#define CSA_AE_LIGATURE GR2A(KC_A)  // æ
+#define CSA_AE CSA_AE_LIGATURE
+#define CSA_SHARP_S GR2A(KC_S)  // ß
+#define CSA_SRPS CSA_SHARP_S
+#define CSA_ETH GR2A(KC_D)  // ð
 // nothing on F
-#define CSA_ENG             GR2A(KC_G)      // ŋ
-#define CSA_H_SRTOKE        GR2A(KC_H)      // ħ
-#define CSA_HSTK            CSA_H_SRTOKE
-#define CSA_IJ_LIGATURE     GR2A(KC_J)      // ij
-#define CSA_IJ              CSA_IJ_LIGATURE
-#define CSA_KRA             GR2A(KC_K)      // ĸ
-#define CSA_L_FLOWN_DOT     GR2A(KC_L)      // ŀ
-#define CSA_LFLD            CSA_L_FLOWN_DOT
-#define CSA_DEAD_ACUTE      GR2A(KC_SCLN)   // dead acute accent
-#define CSA_DACT            CSA_DEAD_ACUTE
+#define CSA_ENG GR2A(KC_G)       // ŋ
+#define CSA_H_SRTOKE GR2A(KC_H)  // ħ
+#define CSA_HSTK CSA_H_SRTOKE
+#define CSA_IJ_LIGATURE GR2A(KC_J)  // ij
+#define CSA_IJ CSA_IJ_LIGATURE
+#define CSA_KRA GR2A(KC_K)          // ĸ
+#define CSA_L_FLOWN_DOT GR2A(KC_L)  // ŀ
+#define CSA_LFLD CSA_L_FLOWN_DOT
+#define CSA_DEAD_ACUTE GR2A(KC_SCLN)  // dead acute accent
+#define CSA_DACT CSA_DEAD_ACUTE
 // nothing on È & À
 
 // Fourth row
-#define CSA_CENT                GR2A(KC_C)  // ¢
-#define CSA_LEFT_DOUBLE_QUOTE   GR2A(KC_V)  // “
-#define CSA_LDQT                CSA_LEFT_DOUBLE_QUOTE
-#define CSA_RIGHT_DOUBLE_QUOTE  GR2A(KC_B)  // ”
-#define CSA_RDQT                CSA_RIGHT_DOUBLE_QUOTE
-#define CSA_N_APOSTROPHE        GR2A(KC_N)  // ʼn (deprecated unicode codepoint)
-#define CSA_NAPO                CSA_N_APOSTROPHE
-#define CSA_MU                  GR2A(KC_M)  // μ
-#define CSA_HORIZONTAL_BAR      GR2A(KC_COMMA)  // ―
-#define CSA_HZBR                CSA_HORIZONTAL_BAR
-#define CSA_DEAD_DOT_ABOVE      GR2A(KC_DOT)    // dead ˙
-#define CSA_DDTA                CSA_DEAD_DOT_ABOVE
+#define CSA_CENT GR2A(KC_C)               // ¢
+#define CSA_LEFT_DOUBLE_QUOTE GR2A(KC_V)  // “
+#define CSA_LDQT CSA_LEFT_DOUBLE_QUOTE
+#define CSA_RIGHT_DOUBLE_QUOTE GR2A(KC_B)  // ”
+#define CSA_RDQT CSA_RIGHT_DOUBLE_QUOTE
+#define CSA_N_APOSTROPHE GR2A(KC_N)  // ʼn (deprecated unicode codepoint)
+#define CSA_NAPO CSA_N_APOSTROPHE
+#define CSA_MU GR2A(KC_M)                  // μ
+#define CSA_HORIZONTAL_BAR GR2A(KC_COMMA)  // ―
+#define CSA_HZBR CSA_HORIZONTAL_BAR
+#define CSA_DEAD_DOT_ABOVE GR2A(KC_DOT)  // dead ˙
+#define CSA_DDTA CSA_DEAD_DOT_ABOVE
 
 // GR2A-shifted characters (different from capitalised GR2A-ed characters)
 // First row
-#define CSA_SOFT_HYPHEN         GR2A(LSFT(CSA_SLASH))   // soft-hyphen, appears as a hyphen in wrapped word
-#define CSA_SHYP                CSA_SOFT_HYPHEN
-#define CSA_INVERTED_EXCLAIM    GR2A(KC_EXCLAIM)    // ¡
-#define CSA_IXLM                CSA_INVERTED_EXCLAIM
+#define CSA_SOFT_HYPHEN GR2A(LSFT(CSA_SLASH))  // soft-hyphen, appears as a hyphen in wrapped word
+#define CSA_SHYP CSA_SOFT_HYPHEN
+#define CSA_INVERTED_EXCLAIM GR2A(KC_EXCLAIM)  // ¡
+#define CSA_IXLM CSA_INVERTED_EXCLAIM
 // nothing on 2
-#define CSA_POUND               GR2A(LSFT(KC_3))    // £
-#define CSA_GBP                 CSA_POUND_SIGN
+#define CSA_POUND GR2A(LSFT(KC_3))  // £
+#define CSA_GBP CSA_POUND_SIGN
 // already on ALGR(KC_E)
-#define CSA_EURO_BIS            GR2A(LSFT(KC_4))    // €
-#define CSA_EURB                CSA_EURO_BIS
-#define CSA_THREE_EIGHTHS       GR2A(LSFT(KC_5))    // ⅜
-#define CSA_3ON8                CSA_THREE_EIGHTHS
-#define CSA_FIVE_EIGHTHS        GR2A(LSFT(KC_6))    // ⅝
-#define CSA_5ON8                CSA_FIVE_EIGHTHS
-#define CSA_SEVEN_EIGHTHS       GR2A(LSFT(KC_7))    // ⅞
-#define CSA_7ON8                CSA_SEVEN_EIGHTHS
-#define CSA_TRADEMARK           GR2A(LSFT(KC_8))    // ™
-#define CSA_TM                  CSA_TRADEMARK
-#define CSA_PLUS_MINUS          GR2A(LSFT(KC_9))    // ±
-#define CSA_PSMS                CSA_PLUS_MINUS
+#define CSA_EURO_BIS GR2A(LSFT(KC_4))  // €
+#define CSA_EURB CSA_EURO_BIS
+#define CSA_THREE_EIGHTHS GR2A(LSFT(KC_5))  // ⅜
+#define CSA_3ON8 CSA_THREE_EIGHTHS
+#define CSA_FIVE_EIGHTHS GR2A(LSFT(KC_6))  // ⅝
+#define CSA_5ON8 CSA_FIVE_EIGHTHS
+#define CSA_SEVEN_EIGHTHS GR2A(LSFT(KC_7))  // ⅞
+#define CSA_7ON8 CSA_SEVEN_EIGHTHS
+#define CSA_TRADEMARK GR2A(LSFT(KC_8))  // ™
+#define CSA_TM CSA_TRADEMARK
+#define CSA_PLUS_MINUS GR2A(LSFT(KC_9))  // ±
+#define CSA_PSMS CSA_PLUS_MINUS
 // nothing on 0
-#define CSA_INVERTED_QUESTION   GR2A(LSFT(KC_MINUS))    // ¿
-#define CSA_IQST                CSA_INVERTED_QUESTION
-#define CSA_DEAD_OGONEK         GR2A(LSFT(KC_EQUAL))    // dead ˛
-#define CSA_DOGO                CSA_DEAD_OGONEK
+#define CSA_INVERTED_QUESTION GR2A(LSFT(KC_MINUS))  // ¿
+#define CSA_IQST CSA_INVERTED_QUESTION
+#define CSA_DEAD_OGONEK GR2A(LSFT(KC_EQUAL))  // dead ˛
+#define CSA_DOGO CSA_DEAD_OGONEK
 
 // Second row
-#define CSA_REGISTERED_TRADEMARK    GR2A(LSFT(KC_R))        // ®
-#define CSA_RTM                     CSA_REGISTERED_TRADEMARK
-#define CSA_YEN                     GR2A(LSFT(KC_Y))        // ¥
-#define CSA_YUAN                    CSA_YEN
-#define CSA_UP_ARROW                LSFT(CSA_DOWN_ARROW)    // ↑
-#define CSA_DOTLESS_I               GR2A(LSFT(KC_I))        // ı
-#define CSA_DLSI                    CSA_DOTLESS_I
-#define CSA_DEAD_RING               GR2A(LSFT(CSA_DCRC))    // dead °
-#define CSA_DRNG                    CSA_DEAD_RING
-#define CSA_DEAD_MACRON             GR2A(LSFT(CSA_C_CEDILLA))   // dead ¯
-#define CSA_DMCR                    CSA_DEAD_MACRON
+#define CSA_REGISTERED_TRADEMARK GR2A(LSFT(KC_R))  // ®
+#define CSA_RTM CSA_REGISTERED_TRADEMARK
+#define CSA_YEN GR2A(LSFT(KC_Y))  // ¥
+#define CSA_YUAN CSA_YEN
+#define CSA_UP_ARROW LSFT(CSA_DOWN_ARROW)  // ↑
+#define CSA_DOTLESS_I GR2A(LSFT(KC_I))     // ı
+#define CSA_DLSI CSA_DOTLESS_I
+#define CSA_DEAD_RING GR2A(LSFT(CSA_DCRC))  // dead °
+#define CSA_DRNG CSA_DEAD_RING
+#define CSA_DEAD_MACRON GR2A(LSFT(CSA_C_CEDILLA))  // dead ¯
+#define CSA_DMCR CSA_DEAD_MACRON
 
 // Third row
-#define CSA_SECTION                 GR2A(LSFT(KC_S))        // §
-#define CSA_SECT                    CSA_SECTION
-#define CSA_ORDINAL_INDICATOR_A     GR2A(LSFT(KC_F))        // ª
-#define CSA_ORDA                    CSA_ORDINAL_INDICATOR_A
-#define CSA_DEAD_DOUBLE_ACUTE       LSFT(CSA_DEAD_ACUTE)    // ˝
-#define CSA_DDCT                    CSA_DEAD_DOUBLE_ACUTE
-#define CSA_DEAD_CARON              GR2A(LSFT(CSA_E_GRAVE)) // dead ˇ
-#define CSA_DCAR                    CSA_DEAD_CARON
-#define CSA_DEAD_BREVE              GR2A(LSFT(CSA_A_GRAVE)) // dead ˘
-#define CSA_DBRV                    CSA_DEAD_BREVE
+#define CSA_SECTION GR2A(LSFT(KC_S))  // §
+#define CSA_SECT CSA_SECTION
+#define CSA_ORDINAL_INDICATOR_A GR2A(LSFT(KC_F))  // ª
+#define CSA_ORDA CSA_ORDINAL_INDICATOR_A
+#define CSA_DEAD_DOUBLE_ACUTE LSFT(CSA_DEAD_ACUTE)  // ˝
+#define CSA_DDCT CSA_DEAD_DOUBLE_ACUTE
+#define CSA_DEAD_CARON GR2A(LSFT(CSA_E_GRAVE))  // dead ˇ
+#define CSA_DCAR CSA_DEAD_CARON
+#define CSA_DEAD_BREVE GR2A(LSFT(CSA_A_GRAVE))  // dead ˘
+#define CSA_DBRV CSA_DEAD_BREVE
 
 // Fourth row
-#define CSA_BROKEN_PIPE         GR2A(LSFT(CSA_U_GRAVE)) // ¦
-#define CSA_BPIP                CSA_BROKEN_PIPE
-#define CSA_COPYRIGHT           GR2A(LSFT(KC_C))        // ©
-#define CSA_CPRT                CSA_COPYRIGHT
-#define CSA_LEFT_QUOTE          GR2A(LSFT(KC_V))        // ‘
-#define CSA_LQOT                CSA_LEFT_QUOTE
-#define CSA_RIGHT_QUOTE         GR2A(LSFT(KC_B))        // ’
-#define CSA_RQOT                CSA_RIGHT_QUOTE
-#define CSA_EIGHTH_NOTE         GR2A(LSFT(KC_N))        // ♪
-#define CSA_8NOT                CSA_EIGHTH_NOTE
-#define CSA_ORDINAL_INDICATOR_O GR2A(LSFT(KC_M))        // º
-#define CSA_ORDO                CSA_ORDINAL_INDICATOR_O
-#define CSA_TIMES               GR2A(LSFT(KC_COMMA))    // ×
-#define CSA_TIMS                CSA_TIMES
-#define CSA_OBELUS              GR2A(LSFT(KC_DOT))      // ÷
-#define CSA_OBEL                CSA_OBELUS
+#define CSA_BROKEN_PIPE GR2A(LSFT(CSA_U_GRAVE))  // ¦
+#define CSA_BPIP CSA_BROKEN_PIPE
+#define CSA_COPYRIGHT GR2A(LSFT(KC_C))  // ©
+#define CSA_CPRT CSA_COPYRIGHT
+#define CSA_LEFT_QUOTE GR2A(LSFT(KC_V))  // ‘
+#define CSA_LQOT CSA_LEFT_QUOTE
+#define CSA_RIGHT_QUOTE GR2A(LSFT(KC_B))  // ’
+#define CSA_RQOT CSA_RIGHT_QUOTE
+#define CSA_EIGHTH_NOTE GR2A(LSFT(KC_N))  // ♪
+#define CSA_8NOT CSA_EIGHTH_NOTE
+#define CSA_ORDINAL_INDICATOR_O GR2A(LSFT(KC_M))  // º
+#define CSA_ORDO CSA_ORDINAL_INDICATOR_O
+#define CSA_TIMES GR2A(LSFT(KC_COMMA))  // ×
+#define CSA_TIMS CSA_TIMES
+#define CSA_OBELUS GR2A(LSFT(KC_DOT))  // ÷
+#define CSA_OBEL CSA_OBELUS
 // more conventional name of the symbol
-#define CSA_DIVISION_SIGN       CSA_OBELUS
-#define CSA_DVSN                CSA_DIVISION_SIGN
+#define CSA_DIVISION_SIGN CSA_OBELUS
+#define CSA_DVSN CSA_DIVISION_SIGN
 // TODO GR2A(LSFT(CSA_E_ACUTE))
 
 #endif
index 2d3f9c06a52ff993a50f925574a801179481967d..166deeea423b14d8cb3a3eabae1341f1e94ee7be 100644 (file)
 
 #include "keymap.h"
 // For software implementation of colemak
-#define CM_Q    KC_Q
-#define CM_W    KC_W
-#define CM_F    KC_E
-#define CM_P    KC_R
-#define CM_G    KC_T
-#define CM_J    KC_Y
-#define CM_L    KC_U
-#define CM_U    KC_I
-#define CM_Y    KC_O
+#define CM_Q KC_Q
+#define CM_W KC_W
+#define CM_F KC_E
+#define CM_P KC_R
+#define CM_G KC_T
+#define CM_J KC_Y
+#define CM_L KC_U
+#define CM_U KC_I
+#define CM_Y KC_O
 #define CM_SCLN KC_P
 
-#define CM_A    KC_A
-#define CM_R    KC_S
-#define CM_S    KC_D
-#define CM_T    KC_F
-#define CM_D    KC_G
-#define CM_H    KC_H
-#define CM_N    KC_J
-#define CM_E    KC_K
-#define CM_I    KC_L
-#define CM_O    KC_SCLN
+#define CM_A KC_A
+#define CM_R KC_S
+#define CM_S KC_D
+#define CM_T KC_F
+#define CM_D KC_G
+#define CM_H KC_H
+#define CM_N KC_J
+#define CM_E KC_K
+#define CM_I KC_L
+#define CM_O KC_SCLN
 #define CM_COLN LSFT(CM_SCLN)
 
-#define CM_Z    KC_Z
-#define CM_X    KC_X
-#define CM_C    KC_C
-#define CM_V    KC_V
-#define CM_B    KC_B
-#define CM_K    KC_N
-#define CM_M    KC_M
+#define CM_Z KC_Z
+#define CM_X KC_X
+#define CM_C KC_C
+#define CM_V KC_V
+#define CM_B KC_B
+#define CM_K KC_N
+#define CM_M KC_M
 #define CM_COMM KC_COMM
-#define CM_DOT  KC_DOT
+#define CM_DOT KC_DOT
 #define CM_SLSH KC_SLSH
 
 // Make it easy to support these in macros
 // TODO: change macro implementation so these aren't needed
-#define KC_CM_Q    CM_Q
-#define KC_CM_W    CM_W
-#define KC_CM_F    CM_F
-#define KC_CM_P    CM_P
-#define KC_CM_G    CM_G
-#define KC_CM_J    CM_J
-#define KC_CM_L    CM_L
-#define KC_CM_U    CM_U
-#define KC_CM_Y    CM_Y
+#define KC_CM_Q CM_Q
+#define KC_CM_W CM_W
+#define KC_CM_F CM_F
+#define KC_CM_P CM_P
+#define KC_CM_G CM_G
+#define KC_CM_J CM_J
+#define KC_CM_L CM_L
+#define KC_CM_U CM_U
+#define KC_CM_Y CM_Y
 #define KC_CM_SCLN CM_SCLN
 
-#define KC_CM_A    CM_A
-#define KC_CM_R    CM_R
-#define KC_CM_S    CM_S
-#define KC_CM_T    CM_T
-#define KC_CM_D    CM_D
-#define KC_CM_H    CM_H
-#define KC_CM_N    CM_N
-#define KC_CM_E    CM_E
-#define KC_CM_I    CM_I
-#define KC_CM_O    CM_O
+#define KC_CM_A CM_A
+#define KC_CM_R CM_R
+#define KC_CM_S CM_S
+#define KC_CM_T CM_T
+#define KC_CM_D CM_D
+#define KC_CM_H CM_H
+#define KC_CM_N CM_N
+#define KC_CM_E CM_E
+#define KC_CM_I CM_I
+#define KC_CM_O CM_O
 
-#define KC_CM_Z    CM_Z
-#define KC_CM_X    CM_X
-#define KC_CM_C    CM_C
-#define KC_CM_V    CM_V
-#define KC_CM_B    CM_B
-#define KC_CM_K    CM_K
-#define KC_CM_M    CM_M
+#define KC_CM_Z CM_Z
+#define KC_CM_X CM_X
+#define KC_CM_C CM_C
+#define KC_CM_V CM_V
+#define KC_CM_B CM_B
+#define KC_CM_K CM_K
+#define KC_CM_M CM_M
 #define KC_CM_COMM CM_COMM
-#define KC_CM_DOT  CM_DOT
+#define KC_CM_DOT CM_DOT
 #define KC_CM_SLSH CM_SLSH
 
 #endif
index b1d5604baff766c97790ec9f0387614857694e9d..11f13d6dcd462d446c33af2895ba3a3aed80e57e 100644 (file)
 #include "keymap.h"
 
 // Normal characters
-#define DV_GRV KC_GRV
-#define DV_1   KC_1
-#define DV_2   KC_2
-#define DV_3   KC_3
-#define DV_4   KC_4
-#define DV_5   KC_5
-#define DV_6   KC_6
-#define DV_7   KC_7
-#define DV_8   KC_8
-#define DV_9   KC_9
-#define DV_0   KC_0
-#define DV_LBRC        KC_MINS
-#define DV_RBRC        KC_EQL
+#define DV_GRV KC_GRV
+#define DV_1 KC_1
+#define DV_2 KC_2
+#define DV_3 KC_3
+#define DV_4 KC_4
+#define DV_5 KC_5
+#define DV_6 KC_6
+#define DV_7 KC_7
+#define DV_8 KC_8
+#define DV_9 KC_9
+#define DV_0 KC_0
+#define DV_LBRC KC_MINS
+#define DV_RBRC KC_EQL
 
-#define DV_QUOT        KC_Q
-#define DV_COMM        KC_W
-#define DV_DOT KC_E
-#define DV_P   KC_R
-#define DV_Y   KC_T
-#define        DV_F    KC_Y
-#define DV_G   KC_U
-#define DV_C   KC_I
-#define        DV_R    KC_O
-#define DV_L   KC_P
-#define DV_SLSH        KC_LBRC
-#define DV_EQL KC_RBRC
-#define DV_BSLS        KC_BSLS
+#define DV_QUOT KC_Q
+#define DV_COMM KC_W
+#define DV_DOT KC_E
+#define DV_P KC_R
+#define DV_Y KC_T
+#define DV_F KC_Y
+#define DV_G KC_U
+#define DV_C KC_I
+#define DV_R KC_O
+#define DV_L KC_P
+#define DV_SLSH KC_LBRC
+#define DV_EQL KC_RBRC
+#define DV_BSLS KC_BSLS
 
-#define DV_A   KC_A
-#define DV_O   KC_S
-#define DV_E   KC_D
-#define DV_U   KC_F
-#define DV_I   KC_G
-#define DV_D   KC_H
-#define DV_H   KC_J
-#define DV_T   KC_K
-#define DV_N   KC_L
-#define DV_S   KC_SCLN
-#define DV_MINS        KC_QUOT
+#define DV_A KC_A
+#define DV_O KC_S
+#define DV_E KC_D
+#define DV_U KC_F
+#define DV_I KC_G
+#define DV_D KC_H
+#define DV_H KC_J
+#define DV_T KC_K
+#define DV_N KC_L
+#define DV_S KC_SCLN
+#define DV_MINS KC_QUOT
 
-#define DV_SCLN        KC_Z
-#define DV_Q   KC_X
-#define DV_J   KC_C
-#define DV_K   KC_V
-#define DV_X   KC_B
-#define DV_B   KC_N
-#define DV_M   KC_M
-#define DV_W   KC_COMM
-#define DV_V   KC_DOT
-#define DV_Z   KC_SLSH
+#define DV_SCLN KC_Z
+#define DV_Q KC_X
+#define DV_J KC_C
+#define DV_K KC_V
+#define DV_X KC_B
+#define DV_B KC_N
+#define DV_M KC_M
+#define DV_W KC_COMM
+#define DV_V KC_DOT
+#define DV_Z KC_SLSH
 
 // Shifted characters
-#define DV_TILD        LSFT(DV_GRV)
-#define DV_EXLM        LSFT(DV_1)
-#define DV_AT  LSFT(DV_2)
-#define DV_HASH        LSFT(DV_3)
-#define DV_DLR LSFT(DV_4)
-#define DV_PERC        LSFT(DV_5)
-#define DV_CIRC        LSFT(DV_6)
-#define DV_AMPR        LSFT(DV_7)
-#define DV_ASTR        LSFT(DV_8)
-#define DV_LPRN        LSFT(DV_9)
-#define DV_RPRN        LSFT(DV_0)
-#define DV_LCBR        LSFT(DV_LBRC)
-#define DV_RCBR        LSFT(DV_RBRC)
+#define DV_TILD LSFT(DV_GRV)
+#define DV_EXLM LSFT(DV_1)
+#define DV_AT LSFT(DV_2)
+#define DV_HASH LSFT(DV_3)
+#define DV_DLR LSFT(DV_4)
+#define DV_PERC LSFT(DV_5)
+#define DV_CIRC LSFT(DV_6)
+#define DV_AMPR LSFT(DV_7)
+#define DV_ASTR LSFT(DV_8)
+#define DV_LPRN LSFT(DV_9)
+#define DV_RPRN LSFT(DV_0)
+#define DV_LCBR LSFT(DV_LBRC)
+#define DV_RCBR LSFT(DV_RBRC)
 
-#define DV_DQUO        LSFT(DV_QUOT)
-#define DV_LABK        LSFT(DV_COMM)
-#define DV_RABK        LSFT(DV_DOT)
+#define DV_DQUO LSFT(DV_QUOT)
+#define DV_LABK LSFT(DV_COMM)
+#define DV_RABK LSFT(DV_DOT)
 
-#define DV_QUES        LSFT(DV_SLSH)
-#define DV_PLUS        LSFT(DV_EQL)
-#define DV_PIPE        LSFT(DV_BSLS)
+#define DV_QUES LSFT(DV_SLSH)
+#define DV_PLUS LSFT(DV_EQL)
+#define DV_PIPE LSFT(DV_BSLS)
 
-#define DV_UNDS        LSFT(DV_MINS)
+#define DV_UNDS LSFT(DV_MINS)
 
-#define DV_COLN        LSFT(DV_SCLN)
+#define DV_COLN LSFT(DV_SCLN)
 
 #endif
index 50e2d1f461e08fd0e5541ed907d9d55326093f3c..4b60a67d4db0c087ef47beb5d2d86c5ae0e85f0d 100644 (file)
 #include "keymap.h"
 
 // Normal characters
-#define DP_DLR KC_GRV
-#define DP_AMPR        KC_1
-#define DP_LBRC        KC_2
-#define DP_LCBR        KC_3
-#define DP_RCBR        KC_4
-#define DP_LPRN        KC_5
-#define DP_EQL KC_6
-#define DP_ASTR        KC_7
-#define DP_RPRN        KC_8
-#define DP_PLUS        KC_9
-#define DP_RBRC        KC_0
-#define DP_EXLM        KC_MINS
-#define DP_HASH        KC_EQL
+#define DP_DLR KC_GRV
+#define DP_AMPR KC_1
+#define DP_LBRC KC_2
+#define DP_LCBR KC_3
+#define DP_RCBR KC_4
+#define DP_LPRN KC_5
+#define DP_EQL KC_6
+#define DP_ASTR KC_7
+#define DP_RPRN KC_8
+#define DP_PLUS KC_9
+#define DP_RBRC KC_0
+#define DP_EXLM KC_MINS
+#define DP_HASH KC_EQL
 
-#define DP_SCLN        KC_Q
-#define DP_COMM        KC_W
-#define DP_DOT KC_E
-#define DP_P   KC_R
-#define DP_Y   KC_T
-#define DP_F   KC_Y
-#define DP_G   KC_U
-#define DP_C   KC_I
-#define DP_R   KC_O
-#define DP_L   KC_P
-#define DP_SLSH        KC_LBRC
-#define DP_AT  KC_RBRC
-#define DP_BSLS        KC_BSLS
+#define DP_SCLN KC_Q
+#define DP_COMM KC_W
+#define DP_DOT KC_E
+#define DP_P KC_R
+#define DP_Y KC_T
+#define DP_F KC_Y
+#define DP_G KC_U
+#define DP_C KC_I
+#define DP_R KC_O
+#define DP_L KC_P
+#define DP_SLSH KC_LBRC
+#define DP_AT KC_RBRC
+#define DP_BSLS KC_BSLS
 
-#define DP_A   KC_A
-#define DP_O   KC_S
-#define DP_E   KC_D
-#define DP_U   KC_F
-#define DP_I   KC_G
-#define DP_D   KC_H
-#define DP_H   KC_J
-#define DP_T   KC_K
-#define DP_N   KC_L
-#define DP_S   KC_SCLN
-#define DP_MINS        KC_QUOT
+#define DP_A KC_A
+#define DP_O KC_S
+#define DP_E KC_D
+#define DP_U KC_F
+#define DP_I KC_G
+#define DP_D KC_H
+#define DP_H KC_J
+#define DP_T KC_K
+#define DP_N KC_L
+#define DP_S KC_SCLN
+#define DP_MINS KC_QUOT
 
-#define DP_QUOT        KC_Z
-#define DP_Q   KC_X
-#define DP_J   KC_C
-#define DP_K   KC_V
-#define DP_X   KC_B
-#define DP_B   KC_N
-#define DP_M   KC_M
-#define DP_W   KC_COMM
-#define DP_V   KC_DOT
-#define DP_Z   KC_SLSH
+#define DP_QUOT KC_Z
+#define DP_Q KC_X
+#define DP_J KC_C
+#define DP_K KC_V
+#define DP_X KC_B
+#define DP_B KC_N
+#define DP_M KC_M
+#define DP_W KC_COMM
+#define DP_V KC_DOT
+#define DP_Z KC_SLSH
 
 // Shifted characters
-#define DP_TILD        LSFT(DP_DLR)
-#define DP_PERC        LSFT(DP_AMPR)
-#define DP_7   LSFT(DP_LBRC)
-#define DP_5   LSFT(DP_LCBR)
-#define DP_3   LSFT(DP_RCBR)
-#define DP_1   LSFT(DP_LPRN)
-#define DP_9   LSFT(DP_EQL)
-#define DP_0   LSFT(DP_ASTR)
-#define DP_2   LSFT(DP_RPRN)
-#define DP_4   LSFT(DP_PLUS)
-#define DP_6   LSFT(DP_RBRC)
-#define DP_8   LSFT(DP_EXLM)
-#define DP_GRV LSFT(DP_HASH)
+#define DP_TILD LSFT(DP_DLR)
+#define DP_PERC LSFT(DP_AMPR)
+#define DP_7 LSFT(DP_LBRC)
+#define DP_5 LSFT(DP_LCBR)
+#define DP_3 LSFT(DP_RCBR)
+#define DP_1 LSFT(DP_LPRN)
+#define DP_9 LSFT(DP_EQL)
+#define DP_0 LSFT(DP_ASTR)
+#define DP_2 LSFT(DP_RPRN)
+#define DP_4 LSFT(DP_PLUS)
+#define DP_6 LSFT(DP_RBRC)
+#define DP_8 LSFT(DP_EXLM)
+#define DP_GRV LSFT(DP_HASH)
 
-#define DP_COLN        LSFT(DP_SCLN)
-#define DP_LABK        LSFT(DP_COMM)
-#define DP_RABK        LSFT(DP_DOT)
-#define DP_QUES        LSFT(DP_SLSH)
-#define DP_CIRC        LSFT(DP_AT)
-#define DP_PIPE        LSFT(DP_BSLS)
-#define DP_UNDS        LSFT(DP_MINS)
-#define DP_DQUO        LSFT(DP_QUOT)
+#define DP_COLN LSFT(DP_SCLN)
+#define DP_LABK LSFT(DP_COMM)
+#define DP_RABK LSFT(DP_DOT)
+#define DP_QUES LSFT(DP_SLSH)
+#define DP_CIRC LSFT(DP_AT)
+#define DP_PIPE LSFT(DP_BSLS)
+#define DP_UNDS LSFT(DP_MINS)
+#define DP_DQUO LSFT(DP_QUOT)
 
 #endif
index 69f9547bb9cf2afc76edbaf2916ccb73957c0c92..8da5ae6aa50b8dec0eb3f9bb9b69f7d6be346494 100644 (file)
 #define FR_CH_UE KC_LBRC
 #define FR_CH_OE KC_SCLN
 
-#define FR_CH_CIRC KC_EQL // accent circumflex ^ and grave ` and ~
-#define FR_CH_LESS KC_NUBS // < and > and backslash
-#define FR_CH_MINS KC_SLSH // - and _
-#define FR_CH_DLR KC_BSLS // $, £ and }
-#define FR_CH_PARA KC_GRV // § and ring °
-#define FR_CH_DIAE KC_RBRC // accent ¨
+#define FR_CH_CIRC KC_EQL   // accent circumflex ^ and grave ` and ~
+#define FR_CH_LESS KC_NUBS  // < and > and backslash
+#define FR_CH_MINS KC_SLSH  // - and _
+#define FR_CH_DLR KC_BSLS   // $, £ and }
+#define FR_CH_PARA KC_GRV   // § and ring °
+#define FR_CH_DIAE KC_RBRC  // accent ¨
 
 // shifted characters
-#define FR_CH_RING LSFT(KC_GRV) // °
-#define FR_CH_EXLM LSFT(KC_RBRC) // !
-#define FR_CH_PLUS LSFT(KC_1) // +
-#define FR_CH_DQOT LSFT(KC_2) // "
-#define FR_CH_ASTR LSFT(KC_3) // *
-#define FR_CH_PERC LSFT(KC_5) // %
-#define FR_CH_AMPR LSFT(KC_6) // &
-#define FR_CH_SLSH LSFT(KC_7) // /
-#define FR_CH_LPRN LSFT(KC_8) // (
-#define FR_CH_RPRN LSFT(KC_9) // )
-#define FR_CH_EQL  LSFT(KC_0) // =
-#define FR_CH_QST  LSFT(FR_CH_QUOT) // ?
-#define FR_CH_MORE LSFT(FR_CH_LESS) // >
-#define FR_CH_COLN LSFT(KC_DOT) // :
-#define FR_CH_SCLN LSFT(KC_COMM) // ;
-#define FR_CH_UNDS LSFT(FR_CH_MINS) // _
-#define FR_CH_CCED LSFT(KC_4) // ç
-#define FR_CH_GRV  LSFT(FR_CH_CIRC) // accent grave `
+#define FR_CH_RING LSFT(KC_GRV)      // °
+#define FR_CH_EXLM LSFT(KC_RBRC)     // !
+#define FR_CH_PLUS LSFT(KC_1)        // +
+#define FR_CH_DQOT LSFT(KC_2)        // "
+#define FR_CH_ASTR LSFT(KC_3)        // *
+#define FR_CH_PERC LSFT(KC_5)        // %
+#define FR_CH_AMPR LSFT(KC_6)        // &
+#define FR_CH_SLSH LSFT(KC_7)        // /
+#define FR_CH_LPRN LSFT(KC_8)        // (
+#define FR_CH_RPRN LSFT(KC_9)        // )
+#define FR_CH_EQL LSFT(KC_0)         // =
+#define FR_CH_QST LSFT(FR_CH_QUOT)   // ?
+#define FR_CH_MORE LSFT(FR_CH_LESS)  // >
+#define FR_CH_COLN LSFT(KC_DOT)      // :
+#define FR_CH_SCLN LSFT(KC_COMM)     // ;
+#define FR_CH_UNDS LSFT(FR_CH_MINS)  // _
+#define FR_CH_CCED LSFT(KC_4)        // ç
+#define FR_CH_GRV LSFT(FR_CH_CIRC)   // accent grave `
 
 // Alt Gr-ed characters
-#define FR_CH_LCBR ALGR(KC_QUOT) // {
-#define FR_CH_LBRC ALGR(KC_LBRC) // [
-#define FR_CH_RBRC ALGR(KC_9) // ]
-#define FR_CH_RCBR ALGR(KC_0) // }
-#define FR_CH_BSLS ALGR(FR_CH_LESS) // backslash
-#define FR_CH_AT   ALGR(KC_2) // @
-#define FR_CH_EURO ALGR(KC_E) // €
-#define FR_CH_TILD ALGR(FR_CH_CIRC) // ~
-#define FR_CH_PIPE ALGR(KC_1) // |
-#define FR_CH_HASH ALGR(KC_3) // #
-#define FR_CH_ACUT ALGR(FR_CH_QUOT) // accent acute ´
+#define FR_CH_LCBR ALGR(KC_QUOT)     // {
+#define FR_CH_LBRC ALGR(KC_LBRC)     // [
+#define FR_CH_RBRC ALGR(KC_9)        // ]
+#define FR_CH_RCBR ALGR(KC_0)        // }
+#define FR_CH_BSLS ALGR(FR_CH_LESS)  // backslash
+#define FR_CH_AT ALGR(KC_2)          // @
+#define FR_CH_EURO ALGR(KC_E)        // €
+#define FR_CH_TILD ALGR(FR_CH_CIRC)  // ~
+#define FR_CH_PIPE ALGR(KC_1)        // |
+#define FR_CH_HASH ALGR(KC_3)        // #
+#define FR_CH_ACUT ALGR(FR_CH_QUOT)  // accent acute ´
 
 #endif
index bef7754707c74fdf68184b4c3d6f93098b836728..2d6881e20eadb8769cf73243e5b5915775ac858b 100644 (file)
 #include "keymap.h"
 
 // Normal characters
-#define FR_SUP2        KC_GRV
-#define FR_AMP KC_1
-#define FR_EACU        KC_2
-#define FR_QUOT        KC_3
-#define FR_APOS        KC_4
-#define FR_LPRN        KC_5
-#define FR_MINS        KC_6
-#define FR_EGRV        KC_7
-#define FR_UNDS        KC_8
-#define FR_CCED        KC_9
-#define FR_AGRV        KC_0
-#define FR_RPRN        KC_MINS
-#define FR_EQL KC_EQL
+#define FR_SUP2 KC_GRV
+#define FR_AMP KC_1
+#define FR_EACU KC_2
+#define FR_QUOT KC_3
+#define FR_APOS KC_4
+#define FR_LPRN KC_5
+#define FR_MINS KC_6
+#define FR_EGRV KC_7
+#define FR_UNDS KC_8
+#define FR_CCED KC_9
+#define FR_AGRV KC_0
+#define FR_RPRN KC_MINS
+#define FR_EQL KC_EQL
 
-#define FR_A   KC_Q
-#define FR_Z   KC_W
-#define        FR_CIRC KC_LBRC
-#define FR_DLR KC_RBRC
+#define FR_A KC_Q
+#define FR_Z KC_W
+#define FR_CIRC KC_LBRC
+#define FR_DLR KC_RBRC
 
-#define FR_Q   KC_A
-#define FR_M   KC_SCLN
-#define FR_UGRV        KC_QUOT
-#define FR_ASTR        KC_NUHS
+#define FR_Q KC_A
+#define FR_M KC_SCLN
+#define FR_UGRV KC_QUOT
+#define FR_ASTR KC_NUHS
 
-#define FR_LESS        KC_NUBS
-#define FR_W   KC_Z
-#define FR_COMM        KC_M
-#define FR_SCLN        KC_COMM
-#define FR_COLN        KC_DOT
-#define FR_EXLM        KC_SLSH
+#define FR_LESS KC_NUBS
+#define FR_W KC_Z
+#define FR_COMM KC_M
+#define FR_SCLN KC_COMM
+#define FR_COLN KC_DOT
+#define FR_EXLM KC_SLSH
 
 // Shifted characters
-#define FR_1   LSFT(KC_1)
-#define FR_2   LSFT(KC_2)
-#define FR_3   LSFT(KC_3)
-#define FR_4   LSFT(KC_4)
-#define FR_5   LSFT(KC_5)
-#define FR_6   LSFT(KC_6)
-#define FR_7   LSFT(KC_7)
-#define FR_8   LSFT(KC_8)
-#define FR_9   LSFT(KC_9)
-#define FR_0   LSFT(KC_0)
-#define FR_OVRR        LSFT(FR_RPRN)
+#define FR_1 LSFT(KC_1)
+#define FR_2 LSFT(KC_2)
+#define FR_3 LSFT(KC_3)
+#define FR_4 LSFT(KC_4)
+#define FR_5 LSFT(KC_5)
+#define FR_6 LSFT(KC_6)
+#define FR_7 LSFT(KC_7)
+#define FR_8 LSFT(KC_8)
+#define FR_9 LSFT(KC_9)
+#define FR_0 LSFT(KC_0)
+#define FR_OVRR LSFT(FR_RPRN)
 #define FR_PLUS LSFT(FR_EQL)
 
-#define FR_UMLT        LSFT(FR_CIRC)
-#define FR_PND LSFT(FR_DLR)
-#define        FR_PERC LSFT(FR_UGRV)
-#define FR_MU  LSFT(FR_ASTR)
+#define FR_UMLT LSFT(FR_CIRC)
+#define FR_PND LSFT(FR_DLR)
+#define FR_PERC LSFT(FR_UGRV)
+#define FR_MU LSFT(FR_ASTR)
 
-#define FR_GRTR        LSFT(FR_LESS)
-#define FR_QUES        LSFT(FR_COMM)
-#define FR_DOT LSFT(FR_SCLN)
-#define FR_SLSH        LSFT(FR_COLN)
-#define FR_SECT        LSFT(FR_EXLM)
+#define FR_GRTR LSFT(FR_LESS)
+#define FR_QUES LSFT(FR_COMM)
+#define FR_DOT LSFT(FR_SCLN)
+#define FR_SLSH LSFT(FR_COLN)
+#define FR_SECT LSFT(FR_EXLM)
 
 // Alt Gr-ed characters
-#define FR_TILD        ALGR(KC_2)
-#define FR_HASH        ALGR(KC_3)
+#define FR_TILD ALGR(KC_2)
+#define FR_HASH ALGR(KC_3)
 #define FR_LCBR ALGR(KC_4)
-#define FR_LBRC        ALGR(KC_5)
+#define FR_LBRC ALGR(KC_5)
 #define FR_PIPE ALGR(KC_6)
-#define FR_GRV         ALGR(KC_7)
-#define FR_BSLS        ALGR(KC_8)
-#define FR_CCIRC       ALGR(KC_9)
-#define FR_AT  ALGR(KC_0)
-#define FR_RBRC        ALGR(FR_RPRN)
+#define FR_GRV ALGR(KC_7)
+#define FR_BSLS ALGR(KC_8)
+#define FR_CCIRC ALGR(KC_9)
+#define FR_AT ALGR(KC_0)
+#define FR_RBRC ALGR(FR_RPRN)
 #define FR_RCBR ALGR(FR_EQL)
 
-#define FR_EURO        ALGR(KC_E)
-#define FR_BULT        ALGR(FR_DLR)
+#define FR_EURO ALGR(KC_E)
+#define FR_BULT ALGR(FR_DLR)
 
 #endif
index ecade3fe98bb4023cbad2cc6fae6b26e03494557..3a231874a4261f47e4de8326542c91c07b5dbb56 100644 (file)
 #include "keymap.h"
 
 // Normal characters
-#define FR_AT  KC_GRV
-#define FR_AMP KC_1
-#define FR_EACU        KC_2
-#define FR_QUOT        KC_3
-#define FR_APOS        KC_4
-#define FR_LPRN        KC_5
-#define FR_SECT        KC_6
-#define FR_EGRV        KC_7
-#define FR_EXLM        KC_8
-#define FR_CCED        KC_9
-#define FR_AGRV        KC_0
-#define FR_RPRN        KC_MINS
-#define FR_MINS        KC_EQL
+#define FR_AT KC_GRV
+#define FR_AMP KC_1
+#define FR_EACU KC_2
+#define FR_QUOT KC_3
+#define FR_APOS KC_4
+#define FR_LPRN KC_5
+#define FR_SECT KC_6
+#define FR_EGRV KC_7
+#define FR_EXLM KC_8
+#define FR_CCED KC_9
+#define FR_AGRV KC_0
+#define FR_RPRN KC_MINS
+#define FR_MINS KC_EQL
 
-#define FR_A   KC_Q
-#define FR_Z   KC_W
-#define FR_CIRC        KC_LBRC
-#define FR_DLR KC_RBRC
+#define FR_A KC_Q
+#define FR_Z KC_W
+#define FR_CIRC KC_LBRC
+#define FR_DLR KC_RBRC
 
-#define FR_Q   KC_A
-#define FR_M   KC_SCLN
-#define FR_UGRV        KC_QUOT
-#define FR_GRV KC_NUHS
+#define FR_Q KC_A
+#define FR_M KC_SCLN
+#define FR_UGRV KC_QUOT
+#define FR_GRV KC_NUHS
 
-#define FR_LESS        KC_NUBS
-#define FR_W   KC_Z
-#define FR_COMM        KC_M
-#define FR_SCLN        KC_COMM
-#define FR_COLN        KC_DOT
-#define FR_EQL KC_SLSH
+#define FR_LESS KC_NUBS
+#define FR_W KC_Z
+#define FR_COMM KC_M
+#define FR_SCLN KC_COMM
+#define FR_COLN KC_DOT
+#define FR_EQL KC_SLSH
 
 // Shifted characters
-#define FR_HASH        LSFT(KC_GRV)
-#define FR_1   LSFT(KC_1)
-#define FR_2   LSFT(KC_2)
-#define FR_3   LSFT(KC_3)
-#define FR_4   LSFT(KC_4)
-#define FR_5   LSFT(KC_5)
-#define FR_6   LSFT(KC_6)
-#define FR_7   LSFT(KC_7)
-#define FR_8   LSFT(KC_8)
-#define FR_9   LSFT(KC_9)
-#define FR_0   LSFT(KC_0)
-#define FR_UNDS        LSFT(FR_MINS)
+#define FR_HASH LSFT(KC_GRV)
+#define FR_1 LSFT(KC_1)
+#define FR_2 LSFT(KC_2)
+#define FR_3 LSFT(KC_3)
+#define FR_4 LSFT(KC_4)
+#define FR_5 LSFT(KC_5)
+#define FR_6 LSFT(KC_6)
+#define FR_7 LSFT(KC_7)
+#define FR_8 LSFT(KC_8)
+#define FR_9 LSFT(KC_9)
+#define FR_0 LSFT(KC_0)
+#define FR_UNDS LSFT(FR_MINS)
 
-#define FR_UMLT        LSFT(FR_CIRC)
-#define FR_ASTR        LSFT(FR_DLR)
+#define FR_UMLT LSFT(FR_CIRC)
+#define FR_ASTR LSFT(FR_DLR)
 
-#define FR_PERC        LSFT(FR_UGRV)
-#define FR_PND LSFT(FR_GRV)
+#define FR_PERC LSFT(FR_UGRV)
+#define FR_PND LSFT(FR_GRV)
 
-#define FR_GRTR        LSFT(FR_LESS)
-#define FR_QUES        LSFT(FR_COMM)
-#define FR_DOT LSFT(FR_SCLN)
-#define FR_SLSH        LSFT(FR_COLN)
-#define FR_PLUS        LSFT(FR_EQL)
+#define FR_GRTR LSFT(FR_LESS)
+#define FR_QUES LSFT(FR_COMM)
+#define FR_DOT LSFT(FR_SCLN)
+#define FR_SLSH LSFT(FR_COLN)
+#define FR_PLUS LSFT(FR_EQL)
 
 // Alted characters
-#define FR_LCBR        LALT(KC_5)
-#define FR_RCBR        LALT(FR_RPRN)
-#define FR_EURO        LALT(KC_E)
-#define FR_BULT        LALT(FR_DLR)
-#define FR_TILD        LALT(KC_N)
+#define FR_LCBR LALT(KC_5)
+#define FR_RCBR LALT(FR_RPRN)
+#define FR_EURO LALT(KC_E)
+#define FR_BULT LALT(FR_DLR)
+#define FR_TILD LALT(KC_N)
 
 // Shift+Alt-ed characters
-#define FR_LBRC        LSFT(LALT(KC_5))
-#define FR_RBRC        LSFT(LALT(FR_RPRN))
-#define FR_PIPE        LSFT(LALT(KC_L))
-#define FR_BSLS        LSFT(LALT(FR_COLN))
+#define FR_LBRC LSFT(LALT(KC_5))
+#define FR_RBRC LSFT(LALT(FR_RPRN))
+#define FR_PIPE LSFT(LALT(KC_L))
+#define FR_BSLS LSFT(LALT(FR_COLN))
 
 #endif
index 0ba3570df75d980e0a4bd177620ad9efa35230f8..b41b11d6aee84a51b222814a7b6876e8046e218b 100644 (file)
 #define DE_UE KC_LBRC
 #define DE_OE KC_SCLN
 
-#define DE_CIRC KC_GRAVE // accent circumflex ^ and ring °
-#define DE_ACUT KC_EQL // accent acute ´ and grave `
-#define DE_PLUS KC_RBRC // + and * and ~
-#define DE_HASH KC_BSLS // # and '
-#define DE_LESS KC_NUBS // < and > and |
-#define DE_MINS KC_SLSH // - and _
+#define DE_CIRC KC_GRAVE  // accent circumflex ^ and ring °
+#define DE_ACUT KC_EQL    // accent acute ´ and grave `
+#define DE_PLUS KC_RBRC   // + and * and ~
+#define DE_HASH KC_BSLS   // # and '
+#define DE_LESS KC_NUBS   // < and > and |
+#define DE_MINS KC_SLSH   // - and _
 
 // shifted characters
-#define DE_RING LSFT(DE_CIRC) // °
-#define DE_EXLM LSFT(KC_1) // !
-#define DE_DQOT LSFT(KC_2) // "
-#define DE_PARA LSFT(KC_3) // §
-#define DE_DLR  LSFT(KC_4) // $
-#define DE_PERC LSFT(KC_5) // %
-#define DE_AMPR LSFT(KC_6) // &
-#define DE_SLSH LSFT(KC_7) // /
-#define DE_LPRN LSFT(KC_8) // (
-#define DE_RPRN LSFT(KC_9) // )
-#define DE_EQL  LSFT(KC_0) // =
-#define DE_QST  LSFT(DE_SS) // ?
-#define DE_GRV  LSFT(DE_ACUT) // `
-#define DE_ASTR LSFT(DE_PLUS) // *
-#define DE_QUOT LSFT(DE_HASH) // '
-#define DE_MORE LSFT(DE_LESS) // >
-#define DE_COLN LSFT(KC_DOT) // :
-#define DE_SCLN LSFT(KC_COMM) // ;
-#define DE_UNDS LSFT(DE_MINS) // _
+#define DE_RING LSFT(DE_CIRC)  // °
+#define DE_EXLM LSFT(KC_1)     // !
+#define DE_DQOT LSFT(KC_2)     // "
+#define DE_PARA LSFT(KC_3)     // §
+#define DE_DLR LSFT(KC_4)      // $
+#define DE_PERC LSFT(KC_5)     // %
+#define DE_AMPR LSFT(KC_6)     // &
+#define DE_SLSH LSFT(KC_7)     // /
+#define DE_LPRN LSFT(KC_8)     // (
+#define DE_RPRN LSFT(KC_9)     // )
+#define DE_EQL LSFT(KC_0)      // =
+#define DE_QST LSFT(DE_SS)     // ?
+#define DE_GRV LSFT(DE_ACUT)   // `
+#define DE_ASTR LSFT(DE_PLUS)  // *
+#define DE_QUOT LSFT(DE_HASH)  // '
+#define DE_MORE LSFT(DE_LESS)  // >
+#define DE_COLN LSFT(KC_DOT)   // :
+#define DE_SCLN LSFT(KC_COMM)  // ;
+#define DE_UNDS LSFT(DE_MINS)  // _
 
 // Alt Gr-ed characters
-#define DE_SQ2 ALGR(KC_2) // ²
-#define DE_SQ3 ALGR(KC_3) // ³
-#define DE_LCBR ALGR(KC_7) // {
-#define DE_LBRC ALGR(KC_8) // [
-#define DE_RBRC ALGR(KC_9) // ]
-#define DE_RCBR ALGR(KC_0) // }
-#define DE_BSLS ALGR(DE_SS) // backslash
-#define DE_AT  ALGR(KC_Q) // @
-#define DE_EURO ALGR(KC_E) // €
-#define DE_TILD ALGR(DE_PLUS) // ~
-#define DE_PIPE ALGR(DE_LESS) // |
+#define DE_SQ2 ALGR(KC_2)      // ²
+#define DE_SQ3 ALGR(KC_3)      // ³
+#define DE_LCBR ALGR(KC_7)     // {
+#define DE_LBRC ALGR(KC_8)     // [
+#define DE_RBRC ALGR(KC_9)     // ]
+#define DE_RCBR ALGR(KC_0)     // }
+#define DE_BSLS ALGR(DE_SS)    // backslash
+#define DE_AT ALGR(KC_Q)       // @
+#define DE_EURO ALGR(KC_E)     // €
+#define DE_TILD ALGR(DE_PLUS)  // ~
+#define DE_PIPE ALGR(DE_LESS)  // |
 
 #endif
index bd1ef89a19c0710cb084c85bce7b60f93c89a541..19b3627587d61ea41871a2dbd26417614e057df1 100644 (file)
@@ -31,7 +31,7 @@
 #define CH_G KC_G
 #ifdef CH_H
 // The ChibiOS ch.h file defines this...
-#undef CH_H
+#    undef CH_H
 #endif
 #define CH_H KC_H
 #define CH_I KC_I
 #define CH_DOT KC_DOT
 #define CH_COMM KC_COMM
 
-#define CH_QUOT KC_MINS // ' ? ´
+#define CH_QUOT KC_MINS  // ' ? ´
 #define CH_AE KC_QUOT
 #define CH_UE KC_LBRC
 #define CH_OE KC_SCLN
 
-#define CH_PARA KC_GRAVE // secction sign § and °
-#define CH_CARR KC_EQL // carret ^ ` ~
-#define CH_DIER KC_RBRC // dieresis ¨ ! ]
-#define CH_DLR KC_BSLS // $ £ }
-#define CH_LESS KC_NUBS // < and > and backslash
-#define CH_MINS KC_SLSH // - and _
+#define CH_PARA KC_GRAVE  // secction sign § and °
+#define CH_CARR KC_EQL    // carret ^ ` ~
+#define CH_DIER KC_RBRC   // dieresis ¨ ! ]
+#define CH_DLR KC_BSLS    // $ £ }
+#define CH_LESS KC_NUBS   // < and > and backslash
+#define CH_MINS KC_SLSH   // - and _
 
 // shifted characters
-#define CH_RING LSFT(CH_PARA) // °
-#define CH_PLUS LSFT(KC_1) // +
-#define CH_DQOT LSFT(KC_2) // "
-#define CH_PAST LSFT(KC_3) // *
-#define CH_CELA  LSFT(KC_4) // ç
-#define CH_PERC LSFT(KC_5) // %
-#define CH_AMPR LSFT(KC_6) // &
-#define CH_SLSH LSFT(KC_7) // /
-#define CH_LPRN LSFT(KC_8) // (
-#define CH_RPRN LSFT(KC_9) // )
-#define CH_EQL  LSFT(KC_0) // =
-#define CH_QST  LSFT(CH_QUOT) // ?
-#define CH_GRV  LSFT(CH_CARR) // `
-#define CH_EXLM LSFT(CH_DIER) // !
-#define CH_POND LSFT(CH_DLR) // £
-#define CH_MORE LSFT(CH_LESS) // >
-#define CH_COLN LSFT(KC_DOT) // :
-#define CH_SCLN LSFT(KC_COMM) // ;
-#define CH_UNDS LSFT(CH_MINS) // _
+#define CH_RING LSFT(CH_PARA)  // °
+#define CH_PLUS LSFT(KC_1)     // +
+#define CH_DQOT LSFT(KC_2)     // "
+#define CH_PAST LSFT(KC_3)     // *
+#define CH_CELA LSFT(KC_4)     // ç
+#define CH_PERC LSFT(KC_5)     // %
+#define CH_AMPR LSFT(KC_6)     // &
+#define CH_SLSH LSFT(KC_7)     // /
+#define CH_LPRN LSFT(KC_8)     // (
+#define CH_RPRN LSFT(KC_9)     // )
+#define CH_EQL LSFT(KC_0)      // =
+#define CH_QST LSFT(CH_QUOT)   // ?
+#define CH_GRV LSFT(CH_CARR)   // `
+#define CH_EXLM LSFT(CH_DIER)  // !
+#define CH_POND LSFT(CH_DLR)   // £
+#define CH_MORE LSFT(CH_LESS)  // >
+#define CH_COLN LSFT(KC_DOT)   // :
+#define CH_SCLN LSFT(KC_COMM)  // ;
+#define CH_UNDS LSFT(CH_MINS)  // _
 
 // Alt Gr-ed characters
-#define CH_BRBR ALGR(KC_1) // ¦ brocken bar
-#define CH_AT ALGR(KC_2) // @
-#define CH_HASH ALGR(KC_3) // #
-#define CH_NOTL ALGR(KC_6) // ¬ negative logic
-#define CH_PIPE ALGR(KC_7) // |
-#define CH_CENT ALGR(KC_8) // ¢ cent
-#define CH_ACUT ALGR(CH_QUOT) // ´
-#define CH_TILD ALGR(CH_CARR) // ~
-#define CH_EURO ALGR(KC_E) // €
-#define CH_LBRC ALGR(CH_UE) // [
-#define CH_RBRC ALGR(CH_DIER) // ]
-#define CH_LCBR ALGR(CH_AE) // {
-#define CH_RCBR ALGR(CH_DLR) // }
-#define CH_BSLS ALGR(CH_LESS) // backslash
+#define CH_BRBR ALGR(KC_1)     // ¦ brocken bar
+#define CH_AT ALGR(KC_2)       // @
+#define CH_HASH ALGR(KC_3)     // #
+#define CH_NOTL ALGR(KC_6)     // ¬ negative logic
+#define CH_PIPE ALGR(KC_7)     // |
+#define CH_CENT ALGR(KC_8)     // ¢ cent
+#define CH_ACUT ALGR(CH_QUOT)  // ´
+#define CH_TILD ALGR(CH_CARR)  // ~
+#define CH_EURO ALGR(KC_E)     // €
+#define CH_LBRC ALGR(CH_UE)    // [
+#define CH_RBRC ALGR(CH_DIER)  // ]
+#define CH_LCBR ALGR(CH_AE)    // {
+#define CH_RCBR ALGR(CH_DLR)   // }
+#define CH_BSLS ALGR(CH_LESS)  // backslash
 
 #endif
index 798bb75798ec43e7e7ce7224e4cc2755ed17f9c5..29dee07ee03b5352f1ddcc6b91a22949fbf9cb0a 100644 (file)
 #define DE_OSX_UE KC_LBRC
 #define DE_OSX_OE KC_SCLN
 
-#define DE_OSX_CIRC KC_NUBS // accent circumflex ^ and ring °
-#define DE_OSX_ACUT KC_EQL // accent acute ´ and grave `
-#define DE_OSX_PLUS KC_RBRC // + and * and ~
-#define DE_OSX_HASH KC_BSLS // # and '
-#define DE_OSX_LESS KC_GRV // < and > and |
-#define DE_OSX_MINS KC_SLSH // - and _
+#define DE_OSX_CIRC KC_NUBS  // accent circumflex ^ and ring °
+#define DE_OSX_ACUT KC_EQL   // accent acute ´ and grave `
+#define DE_OSX_PLUS KC_RBRC  // + and * and ~
+#define DE_OSX_HASH KC_BSLS  // # and '
+#define DE_OSX_LESS KC_GRV   // < and > and |
+#define DE_OSX_MINS KC_SLSH  // - and _
 
 // shifted characters
-#define DE_OSX_RING LSFT(DE_OSX_CIRC) // °
-#define DE_OSX_EXLM LSFT(KC_1) // !
-#define DE_OSX_DQOT LSFT(KC_2) // "
-#define DE_OSX_PARA LSFT(KC_3) // §
-#define DE_OSX_DLR  LSFT(KC_4) // $
-#define DE_OSX_PERC LSFT(KC_5) // %
-#define DE_OSX_AMPR LSFT(KC_6) // &
-#define DE_OSX_SLSH LSFT(KC_7) // /
-#define DE_OSX_LPRN LSFT(KC_8) // (
-#define DE_OSX_RPRN LSFT(KC_9) // )
-#define DE_OSX_EQL  LSFT(KC_0) // =
-#define DE_OSX_QST  LSFT(DE_OSX_SS) // ?
-#define DE_OSX_GRV  LSFT(DE_OSX_ACUT) // `
-#define DE_OSX_ASTR LSFT(DE_OSX_PLUS) // *
-#define DE_OSX_QUOT LSFT(DE_OSX_HASH) // '
-#define DE_OSX_MORE LSFT(DE_OSX_LESS) // >
-#define DE_OSX_COLN LSFT(KC_DOT) // :
-#define DE_OSX_SCLN LSFT(KC_COMM) // ;
-#define DE_OSX_UNDS LSFT(DE_OSX_MINS) // _
+#define DE_OSX_RING LSFT(DE_OSX_CIRC)  // °
+#define DE_OSX_EXLM LSFT(KC_1)         // !
+#define DE_OSX_DQOT LSFT(KC_2)         // "
+#define DE_OSX_PARA LSFT(KC_3)         // §
+#define DE_OSX_DLR LSFT(KC_4)          // $
+#define DE_OSX_PERC LSFT(KC_5)         // %
+#define DE_OSX_AMPR LSFT(KC_6)         // &
+#define DE_OSX_SLSH LSFT(KC_7)         // /
+#define DE_OSX_LPRN LSFT(KC_8)         // (
+#define DE_OSX_RPRN LSFT(KC_9)         // )
+#define DE_OSX_EQL LSFT(KC_0)          // =
+#define DE_OSX_QST LSFT(DE_OSX_SS)     // ?
+#define DE_OSX_GRV LSFT(DE_OSX_ACUT)   // `
+#define DE_OSX_ASTR LSFT(DE_OSX_PLUS)  // *
+#define DE_OSX_QUOT LSFT(DE_OSX_HASH)  // '
+#define DE_OSX_MORE LSFT(DE_OSX_LESS)  // >
+#define DE_OSX_COLN LSFT(KC_DOT)       // :
+#define DE_OSX_SCLN LSFT(KC_COMM)      // ;
+#define DE_OSX_UNDS LSFT(DE_OSX_MINS)  // _
 
 // Alt-ed characters
 //#define DE_OSX_SQ2 LALT(KC_2) // ²
 //#define DE_OSX_SQ3 LALT(KC_3) // ³
-#define DE_OSX_LCBR LALT(KC_8) // {
-#define DE_OSX_LBRC LALT(KC_5) // [
-#define DE_OSX_RBRC LALT(KC_6) // ]
-#define DE_OSX_RCBR LALT(KC_9) // }
-#define DE_OSX_BSLS LALT(LSFT(KC_7)) // backslash
-#define DE_OSX_AT  LALT(DE_OSX_L) // @
-#define DE_OSX_EURO LALT(KC_E) // €
-#define DE_OSX_TILD LALT(DE_OSX_N) // ~
-#define DE_OSX_PIPE LALT(DE_OSX_7) // |
+#define DE_OSX_LCBR LALT(KC_8)        // {
+#define DE_OSX_LBRC LALT(KC_5)        // [
+#define DE_OSX_RBRC LALT(KC_6)        // ]
+#define DE_OSX_RCBR LALT(KC_9)        // }
+#define DE_OSX_BSLS LALT(LSFT(KC_7))  // backslash
+#define DE_OSX_AT LALT(DE_OSX_L)      // @
+#define DE_OSX_EURO LALT(KC_E)        // €
+#define DE_OSX_TILD LALT(DE_OSX_N)    // ~
+#define DE_OSX_PIPE LALT(DE_OSX_7)    // |
 
 #endif
index ff43535f38e958e65b9685f44f479d665c6083fe..e92d1a3b181c763f741efd2e21ab44c087a76645 100644 (file)
 #define HU_AA KC_QUOT
 #define HU_UEE KC_NUHS
 
-#define HU_MINS KC_SLSH // - 
+#define HU_MINS KC_SLSH  // -
 
 #define HU_DOT KC_DOT
 #define HU_COMM KC_COMM
 
 // shifted characters
 // num row
-#define HU_PARA LSFT(HU_0) // §
-#define HU_QUOT LSFT(HU_1) // '
-#define HU_DQOT LSFT(HU_2) // "
-#define HU_PLUS LSFT(HU_3) // + 
-#define HU_EXLM LSFT(HU_4) // !
-#define HU_PERC LSFT(HU_5) // %
-#define HU_SLSH LSFT(HU_6) // /
-#define HU_EQL LSFT(HU_7) // =
-#define HU_LPRN LSFT(HU_8) // (
-#define HU_RPRN LSFT(HU_9) // )
+#define HU_PARA LSFT(HU_0)  // §
+#define HU_QUOT LSFT(HU_1)  // '
+#define HU_DQOT LSFT(HU_2)  // "
+#define HU_PLUS LSFT(HU_3)  // +
+#define HU_EXLM LSFT(HU_4)  // !
+#define HU_PERC LSFT(HU_5)  // %
+#define HU_SLSH LSFT(HU_6)  // /
+#define HU_EQL LSFT(HU_7)   // =
+#define HU_LPRN LSFT(HU_8)  // (
+#define HU_RPRN LSFT(HU_9)  // )
 
 // í,y row
-#define HU_II  KC_NUBS
-#define HU_QST  LSFT(HU_COMM) // ?
-#define HU_COLN LSFT(HU_DOT) // :
-#define HU_UNDS LSFT(HU_MINS) // _
+#define HU_II KC_NUBS
+#define HU_QST LSFT(HU_COMM)   // ?
+#define HU_COLN LSFT(HU_DOT)   // :
+#define HU_UNDS LSFT(HU_MINS)  // _
 
 // Alt Gr'd characters
 // num row
-#define HU_TILD ALGR(HU_1) // ~
+#define HU_TILD ALGR(HU_1)  // ~
 //#define HU_?? ALGR(HU_2) // ˇ (proper name?)
-#define HU_CIRC ALGR(HU_3) // ^
-#define HU_BRV ALGR(HU_4) // ˘
-#define HU_RING ALGR(HU_5) // °
+#define HU_CIRC ALGR(HU_3)  // ^
+#define HU_BRV ALGR(HU_4)   // ˘
+#define HU_RING ALGR(HU_5)  // °
 //#define HU_?? ALGR(HU_6) // ˛ (proper name?)
-#define HU_GRV ALGR(HU_7) // `
+#define HU_GRV ALGR(HU_7)  // `
 //#define HU_?? ALGR(HU_8) // ˙ (proper name?)
-#define HU_ACUT ALGR(HU_9) // ´ 
+#define HU_ACUT ALGR(HU_9)  // ´
 
 // q row
-#define HU_BSLS ALGR(HU_Q) // \ backslash 
-#define HU_PIPE ALGR(HU_W) // |
-#define HU_DIV ALGR(HU_OEE) // ÷
-#define HU_CRSS ALGR(HU_UU) // ×
-#define HU_EURO ALGR(HU_U) // €
+#define HU_BSLS ALGR(HU_Q)   // \ backslash
+#define HU_PIPE ALGR(HU_W)   // |
+#define HU_DIV ALGR(HU_OEE)  // ÷
+#define HU_CRSS ALGR(HU_UU)  // ×
+#define HU_EURO ALGR(HU_U)   // €
 
 // a row
-#define HU_LBRC ALGR(HU_F) // [
-#define HU_RBRC ALGR(HU_G) // ]
-#define HU_DLR  ALGR(HU_EE) // $
-#define HU_SS ALGR(HU_AA) // ß
+#define HU_LBRC ALGR(HU_F)  // [
+#define HU_RBRC ALGR(HU_G)  // ]
+#define HU_DLR ALGR(HU_EE)  // $
+#define HU_SS ALGR(HU_AA)   // ß
 
 // í,y row
-#define HU_LESS ALGR(KC_NUBS) // < 
-#define HU_MORE ALGR(HU_Y) // >
-#define HU_HASH ALGR(HU_X) // # 
-#define HU_AMPR ALGR(HU_C) // &
-#define HU_AT  ALGR(HU_V) // @
-#define HU_LCBR ALGR(HU_B)// {
-#define HU_RCBR ALGR(HU_N) // }
-#define HU_SCLN ALGR(HU_COMM) // ;
-#define HU_ASTR ALGR(HU_MINS) // *
+#define HU_LESS ALGR(KC_NUBS)  // <
+#define HU_MORE ALGR(HU_Y)     // >
+#define HU_HASH ALGR(HU_X)     // #
+#define HU_AMPR ALGR(HU_C)     // &
+#define HU_AT ALGR(HU_V)       // @
+#define HU_LCBR ALGR(HU_B)     // {
+#define HU_RCBR ALGR(HU_N)     // }
+#define HU_SCLN ALGR(HU_COMM)  // ;
+#define HU_ASTR ALGR(HU_MINS)  // *
 
 #endif
index fe0f5eb847be9022f1f0d209044d391d6a3afdba..544ae94086903220acd22c3abd94712583797470 100644 (file)
 
 #define IT_APOS KC_MINS  // ', ?,  ,
 
-
-
-#define IT_BKSL KC_GRAVE // backslash \, |
-
+#define IT_BKSL KC_GRAVE  // backslash \, |
 
 #define IT_ACUT  // accent acute ´ and grave `
 
-#define IT_LESS KC_NUBS // < and > and |
-#define IT_MINS KC_SLSH // - and _
+#define IT_LESS KC_NUBS  // < and > and |
+#define IT_MINS KC_SLSH  // - and _
 
 // shifted characters
-#define IT_PIPE LSFT(IT_BKSL) // °
-#define IT_EXLM LSFT(KC_1) // !
-#define IT_DQOT LSFT(KC_2) // "
-#define IT_STRL LSFT(KC_3) // £
-#define IT_DLR  LSFT(KC_4) // $
-#define IT_PERC LSFT(KC_5) // %
-#define IT_AMPR LSFT(KC_6) // &
-#define IT_SLSH LSFT(KC_7) // /
-#define IT_LPRN LSFT(KC_8) // (
-#define IT_RPRN LSFT(KC_9) // )
-#define IT_EQL  LSFT(KC_0) // =
-#define IT_QST  LSFT(IT_APOS) // ?
-#define IT_CRC  LSFT(IT_IACC) // ^
-#define IT_ASTR LSFT(IT_PLUS) // *
-#define IT_MORE LSFT(IT_LESS) // >
-#define IT_COLN LSFT(IT_DOT) // :
-#define IT_SCLN LSFT(IT_COMM) // ;
-#define IT_UNDS LSFT(IT_MINS) // _
+#define IT_PIPE LSFT(IT_BKSL)  // °
+#define IT_EXLM LSFT(KC_1)     // !
+#define IT_DQOT LSFT(KC_2)     // "
+#define IT_STRL LSFT(KC_3)     // £
+#define IT_DLR LSFT(KC_4)      // $
+#define IT_PERC LSFT(KC_5)     // %
+#define IT_AMPR LSFT(KC_6)     // &
+#define IT_SLSH LSFT(KC_7)     // /
+#define IT_LPRN LSFT(KC_8)     // (
+#define IT_RPRN LSFT(KC_9)     // )
+#define IT_EQL LSFT(KC_0)      // =
+#define IT_QST LSFT(IT_APOS)   // ?
+#define IT_CRC LSFT(IT_IACC)   // ^
+#define IT_ASTR LSFT(IT_PLUS)  // *
+#define IT_MORE LSFT(IT_LESS)  // >
+#define IT_COLN LSFT(IT_DOT)   // :
+#define IT_SCLN LSFT(IT_COMM)  // ;
+#define IT_UNDS LSFT(IT_MINS)  // _
 
 // Alt Gr-ed characters
-#define IT_LCBR ALGR(KC_7) // {
-#define IT_LBRC ALGR(IT_EACC) // [
-#define IT_RBRC ALGR(IT_PLUS) // ]
-#define IT_RCBR ALGR(KC_0) // }
-#define IT_AT   ALGR(IT_OACC)  // @
-#define IT_EURO ALGR(KC_E)             // €
-#define IT_PIPE LSFT(IT_BKSL)  // |
-#define        IT_SHRP ALGR(IT_AACC)   // #
-
-#define        IT_X_PLUS       X_RBRACKET      // #
+#define IT_LCBR ALGR(KC_7)     // {
+#define IT_LBRC ALGR(IT_EACC)  // [
+#define IT_RBRC ALGR(IT_PLUS)  // ]
+#define IT_RCBR ALGR(KC_0)     // }
+#define IT_AT ALGR(IT_OACC)    // @
+#define IT_EURO ALGR(KC_E)     // €
+#define IT_PIPE LSFT(IT_BKSL)  // |
+#define IT_SHRP ALGR(IT_AACC)  // #
+
+#define IT_X_PLUS X_RBRACKET  // #
 
 #endif
index b0235f1120ee1a5b1dbd1840089bb387d8d0ea1c..01586d5674f82cd628673064017120d609b73e05 100644 (file)
  * note: This website is written in Japanese.
  */
 
-
 #ifndef KEYMAP_JP_H
 #define KEYMAP_JP_H
 
-
 #include "keymap.h"
 
+#define JP_ZHTG KC_GRV   // hankaku/zenkaku|kanzi
+#define JP_YEN KC_INT3   // yen, |
+#define JP_CIRC KC_EQL   // ^, ~
+#define JP_AT KC_LBRC    // @, `
+#define JP_LBRC KC_RBRC  // [, {
+#define JP_COLN KC_QUOT  // :, *
+#define JP_RBRC KC_NUHS  // ], }
+#define JP_BSLS KC_INT1  // \, _
+#define JP_MHEN KC_INT5  // muhenkan
+#define JP_HENK KC_INT4  // henkan
+#define JP_KANA KC_INT2  // katakana/hiragana|ro-mazi
 
-#define JP_ZHTG KC_GRV  // hankaku/zenkaku|kanzi
-#define JP_YEN  KC_INT3 // yen, |
-#define JP_CIRC KC_EQL  // ^, ~
-#define JP_AT   KC_LBRC // @, `
-#define JP_LBRC KC_RBRC // [, {
-#define JP_COLN KC_QUOT // :, *
-#define JP_RBRC KC_NUHS // ], }
-#define JP_BSLS KC_INT1 // \, _
-#define JP_MHEN KC_INT5 // muhenkan
-#define JP_HENK KC_INT4 // henkan
-#define JP_KANA KC_INT2 // katakana/hiragana|ro-mazi
-
-#define JP_MKANA KC_LANG1 //kana on MacOSX
-#define JP_MEISU KC_LANG2 //eisu on MacOSX
-
-
-//Aliases for shifted symbols
-#define JP_DQT  LSFT(KC_2)    // "
-#define JP_AMPR LSFT(KC_6)    // &
-#define JP_QUOT LSFT(KC_7)    // '
-#define JP_LPRN LSFT(KC_8)    // (
-#define JP_RPRN LSFT(KC_9)    // )
-#define JP_EQL  LSFT(KC_MINS) // =
-#define JP_TILD LSFT(JP_CIRC) // ~
-#define JP_PIPE LSFT(JP_YEN)  // |
-#define JP_GRV  LSFT(JP_AT)   // `
-#define JP_LCBR LSFT(JP_LBRC) // {
-#define JP_PLUS LSFT(KC_SCLN) // +
-#define JP_ASTR LSFT(JP_COLN) // *
-#define JP_RCBR LSFT(JP_RBRC) // }
-#define JP_UNDS LSFT(JP_BSLS) // _
+#define JP_MKANA KC_LANG1  // kana on MacOSX
+#define JP_MEISU KC_LANG2  // eisu on MacOSX
 
+// Aliases for shifted symbols
+#define JP_DQT LSFT(KC_2)      // "
+#define JP_AMPR LSFT(KC_6)     // &
+#define JP_QUOT LSFT(KC_7)     // '
+#define JP_LPRN LSFT(KC_8)     // (
+#define JP_RPRN LSFT(KC_9)     // )
+#define JP_EQL LSFT(KC_MINS)   // =
+#define JP_TILD LSFT(JP_CIRC)  // ~
+#define JP_PIPE LSFT(JP_YEN)   // |
+#define JP_GRV LSFT(JP_AT)     // `
+#define JP_LCBR LSFT(JP_LBRC)  // {
+#define JP_PLUS LSFT(KC_SCLN)  // +
+#define JP_ASTR LSFT(JP_COLN)  // *
+#define JP_RCBR LSFT(JP_RBRC)  // }
+#define JP_UNDS LSFT(JP_BSLS)  // _
 
 // These symbols are correspond to US101-layout.
-#define JP_MINS KC_MINS // -
-#define JP_SCLN KC_SCLN // ;
-#define JP_COMM KC_COMM // ,
-#define JP_DOT  KC_DOT  // .
-#define JP_SLSH KC_SLSH // /
+#define JP_MINS KC_MINS  // -
+#define JP_SCLN KC_SCLN  // ;
+#define JP_COMM KC_COMM  // ,
+#define JP_DOT KC_DOT    // .
+#define JP_SLSH KC_SLSH  // /
 // shifted
-#define JP_EXLM KC_EXLM // !
-#define JP_HASH KC_HASH // #
-#define JP_DLR  KC_DLR  // $
-#define JP_PERC KC_PERC // %
-#define JP_LT   KC_LT   // <
-#define JP_GT   KC_GT   // >
-#define JP_QUES KC_QUES // ?
-
+#define JP_EXLM KC_EXLM  // !
+#define JP_HASH KC_HASH  // #
+#define JP_DLR KC_DLR    // $
+#define JP_PERC KC_PERC  // %
+#define JP_LT KC_LT      // <
+#define JP_GT KC_GT      // >
+#define JP_QUES KC_QUES  // ?
 
 #endif
index 551a4212b26ec680774649cf8b09bfdc86d27d06..8d2f76f2732252f2b1919aee9cd5e536bfce4c1b 100644 (file)
 #include "keymap.h"
 
 // Normal characters
-#define NO_HALF        KC_GRV
-#define NO_PLUS        KC_MINS
-#define NO_ACUT        KC_EQL
+#define NO_HALF KC_GRV
+#define NO_PLUS KC_MINS
+#define NO_ACUT KC_EQL
 
-#define NO_AM  KC_LBRC
-#define NO_QUOT        KC_RBRC // this is the "umlaut" char on Nordic keyboards, Apple layout
-#define NO_AE  KC_SCLN
-#define NO_OSLH        KC_QUOT
-#define        NO_APOS KC_NUHS
+#define NO_AM KC_LBRC
+#define NO_QUOT KC_RBRC  // this is the "umlaut" char on Nordic keyboards, Apple layout
+#define NO_AE KC_SCLN
+#define NO_OSLH KC_QUOT
+#define NO_APOS KC_NUHS
 
-#define NO_LESS        KC_NUBS
+#define NO_LESS KC_NUBS
 #define NO_MINS KC_SLSH
 
 // Shifted characters
 #define NO_SECT LSFT(NO_HALF)
-#define NO_QUO2        LSFT(KC_2)
+#define NO_QUO2 LSFT(KC_2)
 #define NO_BULT LSFT(KC_4)
-#define NO_AMPR        LSFT(KC_6)
+#define NO_AMPR LSFT(KC_6)
 #define NO_SLSH LSFT(KC_7)
-#define NO_LPRN        LSFT(KC_8)
-#define NO_RPRN        LSFT(KC_9)
-#define NO_EQL LSFT(KC_0)
-#define NO_QUES        LSFT(NO_PLUS)
-#define NO_GRV LSFT(NO_ACUT)
+#define NO_LPRN LSFT(KC_8)
+#define NO_RPRN LSFT(KC_9)
+#define NO_EQL LSFT(KC_0)
+#define NO_QUES LSFT(NO_PLUS)
+#define NO_GRV LSFT(NO_ACUT)
 
 #define NO_CIRC LSFT(NO_QUOT)
 
-#define NO_GRTR        LSFT(NO_LESS)
+#define NO_GRTR LSFT(NO_LESS)
 #define NO_SCLN LSFT(KC_COMM)
 #define NO_COLN LSFT(KC_DOT)
 #define NO_UNDS LSFT(NO_MINS)
 
 // Alt Gr-ed characters
-#define NO_AT  ALGR(KC_2)
-#define NO_PND ALGR(KC_3)
-#define NO_DLR ALGR(KC_4)
+#define NO_AT ALGR(KC_2)
+#define NO_PND ALGR(KC_3)
+#define NO_DLR ALGR(KC_4)
 #define NO_LCBR ALGR(KC_7)
 #define NO_LBRC ALGR(KC_8)
 #define NO_RBRC ALGR(KC_9)
-#define NO_RCBR        ALGR(KC_0)
+#define NO_RCBR ALGR(KC_0)
 #define NO_PIPE ALGR(KC_NUBS)
 
 #define NO_EURO ALGR(KC_E)
 #define NO_TILD ALGR(NO_QUOT)
 
 #define NO_BSLS ALGR(KC_MINS)
-#define NO_MU  ALGR(KC_M)
+#define NO_MU ALGR(KC_M)
 
 #endif
index 995b1b8a02fda3dab00e5a5967f055e14dfabdd4..e0f246f8238c7df9c11b2a54a5182ea7abd08d4f 100644 (file)
 
 #include "keymap.h"
 // For software implementation of norman
-#define NM_Q    KC_Q
-#define NM_W    KC_W
-#define NM_D    KC_E
-#define NM_F    KC_R
-#define NM_K    KC_T
-#define NM_J    KC_Y
-#define NM_U    KC_U
-#define NM_R    KC_I
-#define NM_L    KC_O
+#define NM_Q KC_Q
+#define NM_W KC_W
+#define NM_D KC_E
+#define NM_F KC_R
+#define NM_K KC_T
+#define NM_J KC_Y
+#define NM_U KC_U
+#define NM_R KC_I
+#define NM_L KC_O
 #define NM_SCLN KC_P
 #define NM_COLN LSFT(NM_SCLN)
 
-#define NM_A    KC_A
-#define NM_S    KC_S
-#define NM_E    KC_D
-#define NM_T    KC_F
-#define NM_G    KC_G
-#define NM_Y    KC_H
-#define NM_N    KC_J
-#define NM_I    KC_K
-#define NM_O    KC_L
-#define NM_H    KC_SCLN
+#define NM_A KC_A
+#define NM_S KC_S
+#define NM_E KC_D
+#define NM_T KC_F
+#define NM_G KC_G
+#define NM_Y KC_H
+#define NM_N KC_J
+#define NM_I KC_K
+#define NM_O KC_L
+#define NM_H KC_SCLN
 
-#define NM_Z    KC_Z
-#define NM_X    KC_X
-#define NM_C    KC_C
-#define NM_V    KC_V
-#define NM_B    KC_B
-#define NM_P    KC_N
-#define NM_M    KC_M
+#define NM_Z KC_Z
+#define NM_X KC_X
+#define NM_C KC_C
+#define NM_V KC_V
+#define NM_B KC_B
+#define NM_P KC_N
+#define NM_M KC_M
 #define NM_COMM KC_COMM
-#define NM_DOT  KC_DOT
+#define NM_DOT KC_DOT
 #define NM_SLSH KC_SLSH
-
index b7128973aacdd60b64db9b56dcad1315e61a96d5..eb3b0b040e1a449a09b4ade76c7886f5e620aff2 100644 (file)
 
 // Norwegian redifinitions from the nordic keyset
 #undef NO_ACUT
-#define NO_ACUT        ALGR(NO_BSLS)  // ´
+#define NO_ACUT ALGR(NO_BSLS)  // ´
 #undef NO_AE
-#define NO_AE  KC_QUOT  // æ
+#define NO_AE KC_QUOT  // æ
 #undef NO_BSLS
 #define NO_BSLS KC_EQL  // '\'
 #undef NO_CIRC
 #define NO_CIRC LSFT(KC_RBRC)  // ^
 #undef NO_GRV
-#define NO_GRV LSFT(NO_BSLS)  //
+#define NO_GRV LSFT(NO_BSLS)  //
 #undef NO_OSLH
-#define NO_OSLH        KC_SCLN  // ø
+#define NO_OSLH KC_SCLN  // ø
 #undef NO_PIPE
 #define NO_PIPE KC_GRV  // |
 
 // Additional norwegian keys not defined in the nordic keyset
-#define NO_AA  KC_LBRC  // å
+#define NO_AA KC_LBRC          // å
 #define NO_ASTR LSFT(KC_BSLS)  // *
 
 // Norwegian unique MAC characters
-#define NO_ACUT_MAC KC_EQL  // =
-#define NO_APOS_MAC KC_NUBS  // '
-#define NO_AT_MAC   KC_BSLS  // @
-#define NO_BSLS_MAC ALGR(LSFT(KC_7)) // '\'
-#define NO_DLR_MAC  LSFT(KC_4) // $
-#define NO_GRV_MAC ALGR(NO_BSLS) // `
-#define NO_GRTR_MAC LSFT(KC_GRV)  // >
+#define NO_ACUT_MAC KC_EQL            // =
+#define NO_APOS_MAC KC_NUBS           // '
+#define NO_AT_MAC KC_BSLS             // @
+#define NO_BSLS_MAC ALGR(LSFT(KC_7))  // '\'
+#define NO_DLR_MAC LSFT(KC_4)         // $
+#define NO_GRV_MAC ALGR(NO_BSLS)      // `
+#define NO_GRTR_MAC LSFT(KC_GRV)      // >
 #define NO_LCBR_MAC ALGR(LSFT(KC_8))  // }
-#define NO_LESS_MAC KC_GRV  // >
-#define NO_PIPE_MAC ALGR(KC_7)  // |
+#define NO_LESS_MAC KC_GRV            // >
+#define NO_PIPE_MAC ALGR(KC_7)        // |
 #define NO_RCBR_MAC ALGR(LSFT(KC_9))  // }
 
 #endif
index de6d8c53f3fa1de893b034b4d238a531e5adefb6..3bfcb7ad9063e48380eceecaad50ddd685b2646f 100644 (file)
 
 #include "keymap.h"
 
-#define PV_NUM  KC_1
-#define PV_LS   KC_Q
-#define PV_LT   KC_W
-#define PV_LP   KC_E
-#define PV_LH   KC_R
-#define PV_LK   KC_S
-#define PV_LW   KC_D
-#define PV_LR   KC_F
+#define PV_NUM KC_1
+#define PV_LS KC_Q
+#define PV_LT KC_W
+#define PV_LP KC_E
+#define PV_LH KC_R
+#define PV_LK KC_S
+#define PV_LW KC_D
+#define PV_LR KC_F
 
 #define PV_STAR KC_Y
-#define PV_RF   KC_U
-#define PV_RP   KC_I
-#define PV_RL   KC_O
-#define PV_RT   KC_P
-#define PV_RD   KC_LBRC
-#define PV_RR   KC_J
-#define PV_RB   KC_K
-#define PV_RG   KC_L
-#define PV_RS   KC_SCLN
-#define PV_RZ   KC_QUOT
+#define PV_RF KC_U
+#define PV_RP KC_I
+#define PV_RL KC_O
+#define PV_RT KC_P
+#define PV_RD KC_LBRC
+#define PV_RR KC_J
+#define PV_RB KC_K
+#define PV_RG KC_L
+#define PV_RS KC_SCLN
+#define PV_RZ KC_QUOT
 
-#define PV_A    KC_C
-#define PV_O    KC_V
-#define PV_E    KC_N
-#define PV_U    KC_M
+#define PV_A KC_C
+#define PV_O KC_V
+#define PV_E KC_N
+#define PV_U KC_M
 
 #endif
index 83bb1e8b8783d0964d5ec1418c2bdb7b5637fffa..d40ff5c6bb554968ca0c3c67349268ce47168c02 100644 (file)
 
 #include "keymap_dvorak.h"
 
-#define PD_NUM  DV_1
-#define PD_LS   DV_Q
-#define PD_LT   DV_W
-#define PD_LP   DV_E
-#define PD_LH   DV_R
-#define PD_LK   DV_S
-#define PD_LW   DV_D
-#define PD_LR   DV_F
+#define PD_NUM DV_1
+#define PD_LS DV_Q
+#define PD_LT DV_W
+#define PD_LP DV_E
+#define PD_LH DV_R
+#define PD_LK DV_S
+#define PD_LW DV_D
+#define PD_LR DV_F
 
 #define PD_STAR DV_Y
-#define PD_RF   DV_U
-#define PD_RP   DV_I
-#define PD_RL   DV_O
-#define PD_RT   DV_P
-#define PD_RD   DV_LBRC
-#define PD_RR   DV_J
-#define PD_RB   DV_K
-#define PD_RG   DV_L
-#define PD_RS   DV_SCLN
-#define PD_RZ   DV_QUOT
+#define PD_RF DV_U
+#define PD_RP DV_I
+#define PD_RL DV_O
+#define PD_RT DV_P
+#define PD_RD DV_LBRC
+#define PD_RR DV_J
+#define PD_RB DV_K
+#define PD_RG DV_L
+#define PD_RS DV_SCLN
+#define PD_RZ DV_QUOT
 
-#define PD_A    DV_C
-#define PD_O    DV_V
-#define PD_E    DV_N
-#define PD_U    DV_M
+#define PD_A DV_C
+#define PD_O DV_V
+#define PD_E DV_N
+#define PD_U DV_M
 
 #endif
index 892283e7029a1fd78300c63b63c92a0c8b3438a9..7a8b7bec3701b4d630513f92e362ecac294468c1 100644 (file)
 
 #include "keymap.h"
 
-//Swapped Z and Y
+// Swapped Z and Y
 #define SI_Z KC_Y
 #define SI_Y KC_Z
 
-//Special characters
+// Special characters
 #define SI_CV KC_SCLN
 #define SI_SV KC_LBRC
 #define SI_ZV KC_BSLS
 #define SI_DOT KC_DOT
 #define SI_COMM KC_COMM
 
-#define SI_PLUS KC_EQL // + and * and ~
-#define SI_QOT KC_MINS // Single quote
-#define SI_MINS KC_SLSH // - and _
+#define SI_PLUS KC_EQL   // + and * and ~
+#define SI_QOT KC_MINS   // Single quote
+#define SI_MINS KC_SLSH  // - and _
 
 // shifted characters
-#define SI_EXLM LSFT(KC_1) // !
-#define SI_DQOT LSFT(KC_2) // "
-#define SI_HASH LSFT(KC_3) // #
-#define SI_DLR  LSFT(KC_4) // $
-#define SI_PERC LSFT(KC_5) // %
-#define SI_AMPR LSFT(KC_6) // &
-#define SI_SLSH LSFT(KC_7) // /
-#define SI_LPRN LSFT(KC_8) // (
-#define SI_RPRN LSFT(KC_9) // )
-#define SI_EQL  LSFT(KC_0) // =
-#define SI_QST  LSFT(SI_QOT) // ?
-#define SI_ASTR LSFT(SI_PLUS) // *
-#define SI_COLN LSFT(KC_DOT) // :
-#define SI_SCLN LSFT(KC_COMM) // ;
-#define SI_UNDS LSFT(SI_MINS) // _
+#define SI_EXLM LSFT(KC_1)     // !
+#define SI_DQOT LSFT(KC_2)     // "
+#define SI_HASH LSFT(KC_3)     // #
+#define SI_DLR LSFT(KC_4)      // $
+#define SI_PERC LSFT(KC_5)     // %
+#define SI_AMPR LSFT(KC_6)     // &
+#define SI_SLSH LSFT(KC_7)     // /
+#define SI_LPRN LSFT(KC_8)     // (
+#define SI_RPRN LSFT(KC_9)     // )
+#define SI_EQL LSFT(KC_0)      // =
+#define SI_QST LSFT(SI_QOT)    // ?
+#define SI_ASTR LSFT(SI_PLUS)  // *
+#define SI_COLN LSFT(KC_DOT)   // :
+#define SI_SCLN LSFT(KC_COMM)  // ;
+#define SI_UNDS LSFT(SI_MINS)  // _
 
 // Alt Gr-ed characters
-#define SI_CIRC ALGR(KC_3) // ^
-#define SI_DEG ALGR(KC_5) // °
-#define SI_GRV ALGR(KC_7) // `
-#define SI_ACCU ALGR(KC_9) // ´
-#define SI_LCBR ALGR(KC_B) // {
-#define SI_RCBR ALGR(KC_N) // }
-#define SI_LBRC ALGR(KC_F) // [
-#define SI_RBRC ALGR(KC_G) // ]
-#define SI_BSLS ALGR(KC_Q) // backslash
-#define SI_AT  ALGR(KC_V) // @
-#define SI_EURO ALGR(KC_E) // €
-#define SI_TILD ALGR(KC_1) // ~
-#define SI_PIPE ALGR(KC_W) // |
+#define SI_CIRC ALGR(KC_3)  // ^
+#define SI_DEG ALGR(KC_5)   // °
+#define SI_GRV ALGR(KC_7)   // `
+#define SI_ACCU ALGR(KC_9)  // ´
+#define SI_LCBR ALGR(KC_B)  // {
+#define SI_RCBR ALGR(KC_N)  // }
+#define SI_LBRC ALGR(KC_F)  // [
+#define SI_RBRC ALGR(KC_G)  // ]
+#define SI_BSLS ALGR(KC_Q)  // backslash
+#define SI_AT ALGR(KC_V)    // @
+#define SI_EURO ALGR(KC_E)  // €
+#define SI_TILD ALGR(KC_1)  // ~
+#define SI_PIPE ALGR(KC_W)  // |
 
 #endif
index 1f183327f9e171d58be7160813e5087afca24586..19a3c5284bea63a5dfd15b14d47115edf6109a26 100644 (file)
 
 // Normal characters
 #define ES_OVRR KC_GRV
-#define ES_APOS        KC_MINS
-#define ES_IEXL        KC_EQL
+#define ES_APOS KC_MINS
+#define ES_IEXL KC_EQL
 
-#define ES_GRV KC_LBRC
-#define ES_PLUS        KC_RBRC
+#define ES_GRV KC_LBRC
+#define ES_PLUS KC_RBRC
 
-#define ES_NTIL        KC_SCLN
-#define ES_ACUT        KC_QUOT
-#define ES_CCED        KC_NUHS
+#define ES_NTIL KC_SCLN
+#define ES_ACUT KC_QUOT
+#define ES_CCED KC_NUHS
 
-#define ES_LESS        KC_NUBS
-#define ES_MINS        KC_SLSH
+#define ES_LESS KC_NUBS
+#define ES_MINS KC_SLSH
 
 // Shifted characters
-#define ES_ASML        LSFT(ES_OVRR)
-#define ES_QUOT        LSFT(KC_2)
-#define ES_OVDT        LSFT(KC_3)
-#define ES_AMPR        LSFT(KC_6)
+#define ES_ASML LSFT(ES_OVRR)
+#define ES_QUOT LSFT(KC_2)
+#define ES_OVDT LSFT(KC_3)
+#define ES_AMPR LSFT(KC_6)
 #define ES_SLSH LSFT(KC_7)
 #define ES_LPRN LSFT(KC_8)
 #define ES_RPRN LSFT(KC_9)
-#define ES_EQL LSFT(KC_0)
-#define ES_QUES        LSFT(ES_APOS)
-#define ES_IQUE        LSFT(ES_IEXL)
+#define ES_EQL LSFT(KC_0)
+#define ES_QUES LSFT(ES_APOS)
+#define ES_IQUE LSFT(ES_IEXL)
 
-#define ES_CIRC        LSFT(ES_GRV)
-#define ES_ASTR        LSFT(ES_PLUS)
+#define ES_CIRC LSFT(ES_GRV)
+#define ES_ASTR LSFT(ES_PLUS)
 
-#define ES_UMLT        LSFT(ES_GRV)
+#define ES_UMLT LSFT(ES_GRV)
 
-#define ES_GRTR        LSFT(ES_LESS)
-#define ES_SCLN        LSFT(KC_COMM)
-#define ES_COLN        LSFT(KC_DOT)
-#define ES_UNDS        LSFT(ES_MINS)
+#define ES_GRTR LSFT(ES_LESS)
+#define ES_SCLN LSFT(KC_COMM)
+#define ES_COLN LSFT(KC_DOT)
+#define ES_UNDS LSFT(ES_MINS)
 
 // Alt Gr-ed characters
-#define ES_BSLS        ALGR(ES_OVRR)
-#define ES_PIPE        ALGR(KC_1)
-#define ES_AT  ALGR(KC_2)
-#define ES_HASH        ALGR(KC_3)
-#define ES_TILD        ALGR(ES_NTIL)
-#define ES_EURO        ALGR(KC_5)
-#define ES_NOT ALGR(KC_6)
+#define ES_BSLS ALGR(ES_OVRR)
+#define ES_PIPE ALGR(KC_1)
+#define ES_AT ALGR(KC_2)
+#define ES_HASH ALGR(KC_3)
+#define ES_TILD ALGR(ES_NTIL)
+#define ES_EURO ALGR(KC_5)
+#define ES_NOT ALGR(KC_6)
 
-#define ES_LBRC        ALGR(ES_GRV)
+#define ES_LBRC ALGR(ES_GRV)
 #define ES_RBRC ALGR(ES_PLUS)
 
-#define ES_LCBR        ALGR(ES_ACUT)
-#define ES_RCBR        ALGR(ES_CCED)
+#define ES_LCBR ALGR(ES_ACUT)
+#define ES_RCBR ALGR(ES_CCED)
 
 #endif
index 4ce91cc1352012a22fb9452815beb0a1fd6599f3..31dcbf7064907f623f1a00d06f3268a8fa1a6d8e 100644 (file)
 // errors, this must be <= 42 total entries in order to
 // support the GeminiPR protocol.
 enum steno_keycodes {
-  STN__MIN = QK_STENO,
-  STN_FN  = STN__MIN,
-  STN_NUM,
-  STN_N1 = STN_NUM,
-  STN_N2,
-  STN_N3,
-  STN_N4,
-  STN_N5,
-  STN_N6,
-  STN_SL,
-  STN_S1 = STN_SL,
-  STN_S2,
-  STN_TL,
-  STN_KL,
-  STN_PL,
-  STN_WL,
-  STN_HL,
-  STN_RL,
-  STN_A,
-  STN_O,
-  STN_STR,
-  STN_ST1 = STN_STR,
-  STN_ST2,
-  STN_RES1,
-  STN_RE1 = STN_RES1,
-  STN_RES2,
-  STN_RE2 = STN_RES2,
-  STN_PWR,
-  STN_ST3,
-  STN_ST4,
-  STN_E,
-  STN_U,
-  STN_FR,
-  STN_RR,
-  STN_PR,
-  STN_BR,
-  STN_LR,
-  STN_GR,
-  STN_TR,
-  STN_SR,
-  STN_DR,
-  STN_N7,
-  STN_N8,
-  STN_N9,
-  STN_NA,
-  STN_NB,
-  STN_NC,
-  STN_ZR,
-  STN__MAX = STN_ZR, // must be less than QK_STENO_BOLT
+    STN__MIN = QK_STENO,
+    STN_FN   = STN__MIN,
+    STN_NUM,
+    STN_N1 = STN_NUM,
+    STN_N2,
+    STN_N3,
+    STN_N4,
+    STN_N5,
+    STN_N6,
+    STN_SL,
+    STN_S1 = STN_SL,
+    STN_S2,
+    STN_TL,
+    STN_KL,
+    STN_PL,
+    STN_WL,
+    STN_HL,
+    STN_RL,
+    STN_A,
+    STN_O,
+    STN_STR,
+    STN_ST1 = STN_STR,
+    STN_ST2,
+    STN_RES1,
+    STN_RE1 = STN_RES1,
+    STN_RES2,
+    STN_RE2 = STN_RES2,
+    STN_PWR,
+    STN_ST3,
+    STN_ST4,
+    STN_E,
+    STN_U,
+    STN_FR,
+    STN_RR,
+    STN_PR,
+    STN_BR,
+    STN_LR,
+    STN_GR,
+    STN_TR,
+    STN_SR,
+    STN_DR,
+    STN_N7,
+    STN_N8,
+    STN_N9,
+    STN_NA,
+    STN_NB,
+    STN_NC,
+    STN_ZR,
+    STN__MAX = STN_ZR,  // must be less than QK_STENO_BOLT
 };
 
 #endif
index 436e81a37a62a42364bea88cd5cd4981414e6535..96fd0c5c658f4c931ea9901d0b39ab0c221f360c 100644 (file)
 #include "keymap.h"
 
 // Normal characters
-#define SE_HALF        KC_GRV
-#define SE_PLUS        KC_MINS
-#define SE_ACUT        KC_EQL
+#define SE_HALF KC_GRV
+#define SE_PLUS KC_MINS
+#define SE_ACUT KC_EQL
 
-#define SE_AM  KC_LBRC
-#define SE_QUOT        KC_RBRC // this is the "umlaut" char on Nordic keyboards, Apple layout
-#define SE_AE   KC_QUOT  // ä
+#define SE_AM KC_LBRC
+#define SE_QUOT KC_RBRC  // this is the "umlaut" char on Nordic keyboards, Apple layout
+#define SE_AE KC_QUOT    // ä
 #define SE_OSLH KC_SCLN  // ö
-#define        SE_APOS KC_NUHS
+#define SE_APOS KC_NUHS
 
-#define SE_LESS        KC_NUBS
+#define SE_LESS KC_NUBS
 #define SE_MINS KC_SLSH
 
 // Shifted characters
 #define SE_SECT LSFT(SE_HALF)
-#define SE_QUO2        LSFT(KC_2)
+#define SE_QUO2 LSFT(KC_2)
 #define SE_BULT LSFT(KC_4)
-#define SE_AMPR        LSFT(KC_6)
+#define SE_AMPR LSFT(KC_6)
 #define SE_SLSH LSFT(KC_7)
-#define SE_LPRN        LSFT(KC_8)
-#define SE_RPRN        LSFT(KC_9)
-#define SE_EQL LSFT(KC_0)
-#define SE_QUES        LSFT(SE_PLUS)
-#define SE_GRV LSFT(SE_ACUT)
+#define SE_LPRN LSFT(KC_8)
+#define SE_RPRN LSFT(KC_9)
+#define SE_EQL LSFT(KC_0)
+#define SE_QUES LSFT(SE_PLUS)
+#define SE_GRV LSFT(SE_ACUT)
 
 #define SE_CIRC LSFT(KC_RBRC)  // ^
 
-#define SE_GRTR        LSFT(SE_LESS)
+#define SE_GRTR LSFT(SE_LESS)
 #define SE_SCLN LSFT(KC_COMM)
 #define SE_COLN LSFT(KC_DOT)
 #define SE_UNDS LSFT(SE_MINS)
 
 // Alt Gr-ed characters
-#define SE_AT  ALGR(KC_2)
-#define SE_PND ALGR(KC_3)
-#define SE_DLR ALGR(KC_4)
+#define SE_AT ALGR(KC_2)
+#define SE_PND ALGR(KC_3)
+#define SE_DLR ALGR(KC_4)
 #define SE_LCBR ALGR(KC_7)
 #define SE_LBRC ALGR(KC_8)
 #define SE_RBRC ALGR(KC_9)
-#define SE_RCBR        ALGR(KC_0)
+#define SE_RCBR ALGR(KC_0)
 #define SE_PIPE ALGR(KC_NUBS)
 
 #define SE_EURO ALGR(KC_E)
 #define SE_TILD ALGR(SE_QUOT)
 
 #define SE_BSLS ALGR(KC_MINS)
-#define SE_MU  ALGR(KC_M)
+#define SE_MU ALGR(KC_M)
 
-#define SE_AA   KC_LBRC  // å
+#define SE_AA KC_LBRC          // å
 #define SE_ASTR LSFT(KC_BSLS)  // *
 
 // Norwegian unique MAC characters (not vetted for Swedish)
-#define SE_ACUT_MAC KC_EQL  // =
-#define SE_APOS_MAC KC_NUBS  // '
-#define SE_AT_MAC   KC_BSLS  // @
-#define SE_BSLS_MAC ALGR(LSFT(KC_7)) // '\'
-#define SE_DLR_MAC  ALGR(KC_4) // $
-#define SE_GRV_MAC ALGR(SE_BSLS) // `
-#define SE_GRTR_MAC LSFT(KC_GRV)  // >
+#define SE_ACUT_MAC KC_EQL            // =
+#define SE_APOS_MAC KC_NUBS           // '
+#define SE_AT_MAC KC_BSLS             // @
+#define SE_BSLS_MAC ALGR(LSFT(KC_7))  // '\'
+#define SE_DLR_MAC ALGR(KC_4)         // $
+#define SE_GRV_MAC ALGR(SE_BSLS)      // `
+#define SE_GRTR_MAC LSFT(KC_GRV)      // >
 #define SE_LCBR_MAC ALGR(LSFT(KC_8))  // {
-#define SE_LESS_MAC KC_GRV  // <
-#define SE_PIPE_MAC ALGR(KC_7)  // |
+#define SE_LESS_MAC KC_GRV            // <
+#define SE_PIPE_MAC ALGR(KC_7)        // |
 #define SE_RCBR_MAC ALGR(LSFT(KC_9))  // }
 
 #endif
index cc3d0039e28c6932f015bfddd15a6eb459590593..d4329e547d49262cd16c7c6fcce403dd08104d90 100644 (file)
 
 // Normal characters
 #define UK_HASH KC_NUHS
-#define UK_BSLS        KC_NUBS
+#define UK_BSLS KC_NUBS
 
 // Shifted characters
-#define UK_NOT LSFT(KC_GRV)
-#define UK_DQUO        LSFT(KC_2)
-#define UK_PND LSFT(KC_3)
-#define UK_AT  LSFT(KC_QUOT)
-#define UK_TILD        LSFT(KC_NUHS)
-#define UK_PIPE        LSFT(KC_NUBS)
+#define UK_NOT LSFT(KC_GRV)
+#define UK_DQUO LSFT(KC_2)
+#define UK_PND LSFT(KC_3)
+#define UK_AT LSFT(KC_QUOT)
+#define UK_TILD LSFT(KC_NUHS)
+#define UK_PIPE LSFT(KC_NUBS)
 
 // Alt Gr-ed characters
-#define UK_BRKP        ALGR(KC_GRV)
-#define UK_EURO        ALGR(KC_4)
-#define UK_EACT        ALGR(KC_E)
-#define UK_UACT        ALGR(KC_U)
+#define UK_BRKP ALGR(KC_GRV)
+#define UK_EURO ALGR(KC_4)
+#define UK_EACT ALGR(KC_E)
+#define UK_UACT ALGR(KC_U)
 #define UK_IACT ALGR(KC_I)
 #define UK_OACT ALGR(KC_O)
 #define UK_AACT ALGR(KC_A)
index 97927bf50a7968f1af0570d17cd8e91ad1454bfc..e608164d0326d63d924d2f598bcfb50ee11e567d 100644 (file)
 
 #include "keymap.h"
 // For software implementation of workman
-#define WK_Q    KC_Q
-#define WK_D    KC_W
-#define WK_R    KC_E
-#define WK_W    KC_R
-#define WK_B    KC_T
-#define WK_J    KC_Y
-#define WK_F    KC_U
-#define WK_U    KC_I
-#define WK_P    KC_O
+#define WK_Q KC_Q
+#define WK_D KC_W
+#define WK_R KC_E
+#define WK_W KC_R
+#define WK_B KC_T
+#define WK_J KC_Y
+#define WK_F KC_U
+#define WK_U KC_I
+#define WK_P KC_O
 #define WK_SCLN KC_P
 
-#define WK_A    KC_A
-#define WK_S    KC_S
-#define WK_H    KC_D
-#define WK_T    KC_F
-#define WK_G    KC_G
-#define WK_Y    KC_H
-#define WK_N    KC_J
-#define WK_E    KC_K
-#define WK_O    KC_L
-#define WK_I    KC_SCLN
+#define WK_A KC_A
+#define WK_S KC_S
+#define WK_H KC_D
+#define WK_T KC_F
+#define WK_G KC_G
+#define WK_Y KC_H
+#define WK_N KC_J
+#define WK_E KC_K
+#define WK_O KC_L
+#define WK_I KC_SCLN
 
-#define WK_Z    KC_Z
-#define WK_X    KC_X
-#define WK_M    KC_C
-#define WK_C    KC_V
-#define WK_V    KC_B
-#define WK_K    KC_N
-#define WK_L    KC_M
+#define WK_Z KC_Z
+#define WK_X KC_X
+#define WK_M KC_C
+#define WK_C KC_V
+#define WK_V KC_B
+#define WK_K KC_N
+#define WK_L KC_M
 
 // Make it easy to support these in macros
 // TODO: change macro implementation so these aren't needed
-#define KC_WK_Q    WK_Q
-#define KC_WK_D    WK_D
-#define KC_WK_R    WK_R
-#define KC_WK_W    WK_W
-#define KC_WK_B    WK_B
-#define KC_WK_J    WK_J
-#define KC_WK_F    WK_F
-#define KC_WK_U    WK_U
-#define KC_WK_P    WK_P
+#define KC_WK_Q WK_Q
+#define KC_WK_D WK_D
+#define KC_WK_R WK_R
+#define KC_WK_W WK_W
+#define KC_WK_B WK_B
+#define KC_WK_J WK_J
+#define KC_WK_F WK_F
+#define KC_WK_U WK_U
+#define KC_WK_P WK_P
 #define KC_WK_SCLN WK_SCLN
 
-#define KC_WK_A    WK_A
-#define KC_WK_S    WK_S
-#define KC_WK_H    WK_H
-#define KC_WK_T    WK_T
-#define KC_WK_G    WK_G
-#define KC_WK_Y    WK_Y
-#define KC_WK_N    WK_N
-#define KC_WK_E    WK_E
-#define KC_WK_O    WK_O
-#define KC_WK_I    WK_I
+#define KC_WK_A WK_A
+#define KC_WK_S WK_S
+#define KC_WK_H WK_H
+#define KC_WK_T WK_T
+#define KC_WK_G WK_G
+#define KC_WK_Y WK_Y
+#define KC_WK_N WK_N
+#define KC_WK_E WK_E
+#define KC_WK_O WK_O
+#define KC_WK_I WK_I
 
-#define KC_WK_Z    WK_Z
-#define KC_WK_X    WK_X
-#define KC_WK_M    WK_M
-#define KC_WK_C    WK_C
-#define KC_WK_V    WK_V
-#define KC_WK_K    WK_K
-#define KC_WK_L    WK_L
+#define KC_WK_Z WK_Z
+#define KC_WK_X WK_X
+#define KC_WK_M WK_M
+#define KC_WK_C WK_C
+#define KC_WK_V WK_V
+#define KC_WK_K WK_K
+#define KC_WK_L WK_L
 
 #endif
index f07d852722ad89586215b9f6c415b91221a32f25..d12c1890907e84da3e22618f35d9bdf6adcfb42e 100644 (file)
 
 #include "keymap_belgian.h"
 
-const bool ascii_to_shift_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 0, 0, 0, 0, 1, 0, 0,
-    0, 0, 1, 1, 0, 0, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 0, 0, 0, 0, 1, 1,
-    0, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 0, 0, 0, 0, 1,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0
-};
+                                              0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-const bool ascii_to_altgr_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_altgr_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 0, 0, 1, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    1, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 0,
-    1, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 0
-};
+                                              0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0};
 
 const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    KC_SPC,  BE_EXLM, BE_QUOT, BE_QUOT, BE_DLR,  BE_UGRV, BE_AMP,  BE_APOS,
+    KC_SPC, BE_EXLM, BE_QUOT, BE_QUOT, BE_DLR, BE_UGRV, BE_AMP, BE_APOS,
     // (     )        *        +        ,        -        .        /
-    BE_LPRN, BE_RPRN, BE_DLR,  BE_EQL,  BE_COMM, BE_MINS, BE_SCLN, BE_COLN,
+    BE_LPRN, BE_RPRN, BE_DLR, BE_EQL, BE_COMM, BE_MINS, BE_SCLN, BE_COLN,
     // 0     1        2        3        4        5        6        7
-    BE_AGRV, BE_AMP,  BE_EACU, BE_QUOT, BE_APOS, BE_LPRN, BE_PARA, BE_EGRV,
+    BE_AGRV, BE_AMP, BE_EACU, BE_QUOT, BE_APOS, BE_LPRN, BE_PARA, BE_EGRV,
     // 8     9        :        ;        <        =        >        ?
-    BE_EXLM, BE_CCED, BE_COLN, BE_SCLN, BE_LESS, BE_EQL,  BE_LESS, BE_COMM,
+    BE_EXLM, BE_CCED, BE_COLN, BE_SCLN, BE_LESS, BE_EQL, BE_LESS, BE_COMM,
     // @     A        B        C        D        E        F        G
-    BE_EACU, BE_A,    KC_B,    KC_C,    KC_D,    KC_E,    KC_F,    KC_G,
+    BE_EACU, BE_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
     // H     I        J        K        L        M        N        O
-    KC_H,    KC_I,    KC_J,    KC_K,    KC_L,    BE_M,    KC_N,    KC_O,
+    KC_H, KC_I, KC_J, KC_K, KC_L, BE_M, KC_N, KC_O,
     // P     Q        R        S        T        U        V        W
-    KC_P,    BE_Q,    KC_R,    KC_S,    KC_T,    KC_U,    KC_V,    BE_W,
+    KC_P, BE_Q, KC_R, KC_S, KC_T, KC_U, KC_V, BE_W,
     // X     Y        Z        [        \        ]        ^        _
-    KC_X,    KC_Y,    BE_Z,    BE_CIRC, BE_LESS, BE_DLR,  BE_PARA, BE_MINS,
+    KC_X, KC_Y, BE_Z, BE_CIRC, BE_LESS, BE_DLR, BE_PARA, BE_MINS,
     // `     a        b        c        d        e        f        g
-    BE_MU,   BE_A,    KC_B,    KC_C,    KC_D,    KC_E,    KC_F,    KC_G,
+    BE_MU, BE_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
     // h     i        j        k        l        m        n        o
-    KC_H,    KC_I,    KC_J,    KC_K,    KC_L,    BE_M,    KC_N,    KC_O,
+    KC_H, KC_I, KC_J, KC_K, KC_L, BE_M, KC_N, KC_O,
     // p     q        r        s        t        u        v        w
-    KC_P,    BE_Q,    KC_R,    KC_S,    KC_T,    KC_U,    KC_V,    BE_W,
+    KC_P, BE_Q, KC_R, KC_S, KC_T, KC_U, KC_V, BE_W,
     // x     y        z        {        |        }        ~        DEL
-    KC_X,    KC_Y,    BE_Z,    BE_CCED, BE_AMP,  BE_AGRV, BE_EQL,  KC_DEL
-};
+    KC_X, KC_Y, BE_Z, BE_CCED, BE_AMP, BE_AGRV, BE_EQL, KC_DEL};
index 565c55b9553eb17af268078e579ebe6e28295b6d..bad3c3f0c1cfee5150501f5cc8c5d9e2c104cf4c 100644 (file)
 
 #include "keymap_bepo.h"
 
-const bool ascii_to_shift_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 1, 0, 1, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 0, 0, 0, 1,
-    0, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 0, 0, 0, 0, 0,
-    1, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0
-};
+                                              0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-const bool ascii_to_altgr_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_altgr_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 0, 0, 0, 0, 0, 1, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 1, 0, 1, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 1,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 0
-};
+                                              0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0};
 
 const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    KC_SPC,  BP_DCRC, BP_DQOT, BP_DLR,  BP_DLR,  BP_PERC, BP_P,    BP_APOS,
+    KC_SPC, BP_DCRC, BP_DQOT, BP_DLR, BP_DLR, BP_PERC, BP_P, BP_APOS,
     // (     )        *        +        ,        -        .        /
-    BP_LPRN, BP_RPRN, BP_ASTR, BP_PLUS, BP_COMM, BP_MINS, BP_DOT,  BP_SLSH,
+    BP_LPRN, BP_RPRN, BP_ASTR, BP_PLUS, BP_COMM, BP_MINS, BP_DOT, BP_SLSH,
     // 0     1        2        3        4        5        6        7
-    BP_ASTR, BP_DQOT, BP_LGIL, BP_RGIL, BP_LPRN, BP_RPRN, BP_AT,   BP_PLUS,
+    BP_ASTR, BP_DQOT, BP_LGIL, BP_RGIL, BP_LPRN, BP_RPRN, BP_AT, BP_PLUS,
     // 8     9        :        ;        <        =        >        ?
-    BP_MINS, BP_SLSH, BP_DOT,  BP_COMM, BP_LGIL, BP_EQL,  BP_RGIL, BP_APOS,
+    BP_MINS, BP_SLSH, BP_DOT, BP_COMM, BP_LGIL, BP_EQL, BP_RGIL, BP_APOS,
     // @     A        B        C        D        E        F        G
-    BP_AT,   BP_A,    BP_B,    BP_C,    BP_D,    BP_E,    BP_F,    BP_G,
+    BP_AT, BP_A, BP_B, BP_C, BP_D, BP_E, BP_F, BP_G,
     // H     I        J        K        L        M        N        O
-    BP_H,    BP_I,    BP_J,    BP_K,    BP_L,    BP_M,    BP_N,    BP_O,
+    BP_H, BP_I, BP_J, BP_K, BP_L, BP_M, BP_N, BP_O,
     // P     Q        R        S        T        U        V        W
-    BP_P,    BP_Q,    BP_R,    BP_S,    BP_T,    BP_U,    BP_V,    BP_W,
+    BP_P, BP_Q, BP_R, BP_S, BP_T, BP_U, BP_V, BP_W,
     // X     Y        Z        [        \        ]        ^        _
-    BP_X,    BP_Y,    BP_Z,    BP_LPRN, BP_AGRV, BP_RPRN, BP_AT,   KC_SPC,
+    BP_X, BP_Y, BP_Z, BP_LPRN, BP_AGRV, BP_RPRN, BP_AT, KC_SPC,
     // `     a        b        c        d        e        f        g
-    BP_PERC, BP_A,    BP_B,    BP_C,    BP_D,    BP_E,    BP_F,    BP_G,
+    BP_PERC, BP_A, BP_B, BP_C, BP_D, BP_E, BP_F, BP_G,
     // h     i        j        k        l        m        n        o
-    BP_H,    BP_I,    BP_J,    BP_K,    BP_L,    BP_M,    BP_N,    BP_O,
+    BP_H, BP_I, BP_J, BP_K, BP_L, BP_M, BP_N, BP_O,
     // p     q        r        s        t        u        v        w
-    BP_P,    BP_Q,    BP_R,    BP_S,    BP_T,    BP_U,    BP_V,    BP_W,
+    BP_P, BP_Q, BP_R, BP_S, BP_T, BP_U, BP_V, BP_W,
     // x     y        z        {        |        }        ~        DEL
-    BP_X,    BP_Y,    BP_Z,    BP_Y,    BP_B,    BP_X,    BP_K,    KC_DEL
-};
+    BP_X, BP_Y, BP_Z, BP_Y, BP_B, BP_X, BP_K, KC_DEL};
index 331f6c2223c67b1bfefc0c8f8a1bcce8283664af..1c02b3b86a472fdc1c112be45ca2184f92c5b075 100644 (file)
@@ -24,34 +24,33 @@ const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    KC_SPC,  KC_1,    KC_QUOT, KC_3,    KC_4,    KC_5,    KC_7,    KC_QUOT,
+    KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
     // (     )        *        +        ,        -        .        /
-    KC_9,    KC_0,    KC_8,    KC_EQL,  KC_COMM, KC_MINS, KC_DOT,  KC_SLSH,
+    KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
     // 0     1        2        3        4        5        6        7
-    KC_0,    KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,
+    KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
     // 8     9        :        ;        <        =        >        ?
-    KC_8,    KC_9,    CM_SCLN, CM_SCLN, KC_COMM, KC_EQL,  KC_DOT,  KC_SLSH,
+    KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
     // @     A        B        C        D        E        F        G
-    KC_2,    CM_A,    CM_B,    CM_C,    CM_D,    CM_E,    CM_F,    CM_G,
+    KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
     // H     I        J        K        L        M        N        O
-    CM_H,    CM_I,    CM_J,    CM_K,    CM_L,    CM_M,    CM_N,    CM_O,
+    CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
     // P     Q        R        S        T        U        V        W
-    CM_P,    CM_Q,    CM_R,    CM_S,    CM_T,    CM_U,    CM_V,    CM_W,
+    CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
     // X     Y        Z        [        \        ]        ^        _
-    CM_X,    CM_Y,    CM_Z,    KC_LBRC, KC_BSLS, KC_RBRC, KC_6,    KC_MINS,
+    CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
     // `     a        b        c        d        e        f        g
-    KC_GRV,  CM_A,    CM_B,    CM_C,    CM_D,    CM_E,    CM_F,    CM_G,
+    KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
     // h     i        j        k        l        m        n        o
-    CM_H,    CM_I,    CM_J,    CM_K,    CM_L,    CM_M,    CM_N,    CM_O,
+    CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
     // p     q        r        s        t        u        v        w
-    CM_P,    CM_Q,    CM_R,    CM_S,    CM_T,    CM_U,    CM_V,    CM_W,
+    CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
     // x     y        z        {        |        }        ~        DEL
-    CM_X,    CM_Y,    CM_Z,    KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV,  KC_DEL
-};
+    CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL};
index f2cb6c4a0710cecc6a3a7fa9676f3f5ee9dff934..3ddb00b11261f05823c9c59165ec651517531ecf 100644 (file)
@@ -24,34 +24,33 @@ const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    KC_SPC,  DV_1,    DV_QUOT, DV_3,    DV_4,    DV_5,    DV_7,    DV_QUOT,
+    KC_SPC, DV_1, DV_QUOT, DV_3, DV_4, DV_5, DV_7, DV_QUOT,
     // (     )        *        +        ,        -        .        /
-    DV_9,    DV_0,    DV_8,    DV_EQL,  DV_COMM, DV_MINS, DV_DOT,  DV_SLSH,
+    DV_9, DV_0, DV_8, DV_EQL, DV_COMM, DV_MINS, DV_DOT, DV_SLSH,
     // 0     1        2        3        4        5        6        7
-    DV_0,    DV_1,    DV_2,    DV_3,    DV_4,    DV_5,    DV_6,    DV_7,
+    DV_0, DV_1, DV_2, DV_3, DV_4, DV_5, DV_6, DV_7,
     // 8     9        :        ;        <        =        >        ?
-    DV_8,    DV_9,    DV_SCLN, DV_SCLN, DV_COMM, DV_EQL,  DV_DOT,  DV_SLSH,
+    DV_8, DV_9, DV_SCLN, DV_SCLN, DV_COMM, DV_EQL, DV_DOT, DV_SLSH,
     // @     A        B        C        D        E        F        G
-    DV_2,    DV_A,    DV_B,    DV_C,    DV_D,    DV_E,    DV_F,    DV_G,
+    DV_2, DV_A, DV_B, DV_C, DV_D, DV_E, DV_F, DV_G,
     // H     I        J        K        L        M        N        O
-    DV_H,    DV_I,    DV_J,    DV_K,    DV_L,    DV_M,    DV_N,    DV_O,
+    DV_H, DV_I, DV_J, DV_K, DV_L, DV_M, DV_N, DV_O,
     // P     Q        R        S        T        U        V        W
-    DV_P,    DV_Q,    DV_R,    DV_S,    DV_T,    DV_U,    DV_V,    DV_W,
+    DV_P, DV_Q, DV_R, DV_S, DV_T, DV_U, DV_V, DV_W,
     // X     Y        Z        [        \        ]        ^        _
-    DV_X,    DV_Y,    DV_Z,    DV_LBRC, DV_BSLS, DV_RBRC, DV_6,    DV_MINS,
+    DV_X, DV_Y, DV_Z, DV_LBRC, DV_BSLS, DV_RBRC, DV_6, DV_MINS,
     // `     a        b        c        d        e        f        g
-    DV_GRV,  DV_A,    DV_B,    DV_C,    DV_D,    DV_E,    DV_F,    DV_G,
+    DV_GRV, DV_A, DV_B, DV_C, DV_D, DV_E, DV_F, DV_G,
     // h     i        j        k        l        m        n        o
-    DV_H,    DV_I,    DV_J,    DV_K,    DV_L,    DV_M,    DV_N,    DV_O,
+    DV_H, DV_I, DV_J, DV_K, DV_L, DV_M, DV_N, DV_O,
     // p     q        r        s        t        u        v        w
-    DV_P,    DV_Q,    DV_R,    DV_S,    DV_T,    DV_U,    DV_V,    DV_W,
+    DV_P, DV_Q, DV_R, DV_S, DV_T, DV_U, DV_V, DV_W,
     // x     y        z        {        |        }        ~        DEL
-    DV_X,    DV_Y,    DV_Z,    DV_LBRC, DV_BSLS, DV_RBRC, DV_GRV,  KC_DEL
-};
+    DV_X, DV_Y, DV_Z, DV_LBRC, DV_BSLS, DV_RBRC, DV_GRV, KC_DEL};
index 66b53fbfd6e52452a7767877b23b1548e5e15d6f..df72f9f5b891cb7086f4c4f90bf586be9dbb8b51 100644 (file)
 
 #include "keymap_french.h"
 
-const bool ascii_to_shift_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 0, 0, 0, 0, 1, 0, 0,
-    0, 0, 0, 1, 0, 0, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 0, 0, 0, 0, 1, 1,
-    0, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0
-};
+                                              0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-const bool ascii_to_altgr_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_altgr_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 0, 0, 1, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    1, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 0,
-    1, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 0
-};
+                                              0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0};
 
 const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    KC_SPC,  FR_EXLM, FR_QUOT, FR_QUOT, FR_DLR,  FR_UGRV, FR_AMP,  FR_APOS,
+    KC_SPC, FR_EXLM, FR_QUOT, FR_QUOT, FR_DLR, FR_UGRV, FR_AMP, FR_APOS,
     // (     )        *        +        ,        -        .        /
-    FR_LPRN, FR_RPRN, FR_ASTR, FR_EQL,  FR_COMM, FR_MINS, FR_SCLN, FR_COLN,
+    FR_LPRN, FR_RPRN, FR_ASTR, FR_EQL, FR_COMM, FR_MINS, FR_SCLN, FR_COLN,
     // 0     1        2        3        4        5        6        7
-    FR_AGRV, FR_AMP,  FR_EACU, FR_QUOT, FR_APOS, FR_LPRN, FR_MINS, FR_EGRV,
+    FR_AGRV, FR_AMP, FR_EACU, FR_QUOT, FR_APOS, FR_LPRN, FR_MINS, FR_EGRV,
     // 8     9        :        ;        <        =        >        ?
-    FR_CCED, FR_AGRV, FR_COLN, FR_SCLN, FR_LESS, FR_EQL,  FR_LESS, FR_COMM,
+    FR_CCED, FR_AGRV, FR_COLN, FR_SCLN, FR_LESS, FR_EQL, FR_LESS, FR_COMM,
     // @     A        B        C        D        E        F        G
-    FR_AGRV, FR_A,    KC_B,    KC_C,    KC_D,    KC_E,    KC_F,    KC_G,
+    FR_AGRV, FR_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
     // H     I        J        K        L        M        N        O
-    KC_H,    KC_I,    KC_J,    KC_K,    KC_L,    FR_M,    KC_N,    KC_O,
+    KC_H, KC_I, KC_J, KC_K, KC_L, FR_M, KC_N, KC_O,
     // P     Q        R        S        T        U        V        W
-    KC_P,    FR_Q,    KC_R,    KC_S,    KC_T,    KC_U,    KC_V,    FR_W,
+    KC_P, FR_Q, KC_R, KC_S, KC_T, KC_U, KC_V, FR_W,
     // X     Y        Z        [        \        ]        ^        _
-    KC_X,    KC_Y,    FR_Z,    FR_LPRN, FR_UNDS, FR_RPRN, FR_CCED, FR_UNDS,
+    KC_X, KC_Y, FR_Z, FR_LPRN, FR_UNDS, FR_RPRN, FR_CCED, FR_UNDS,
     // `     a        b        c        d        e        f        g
-    FR_EGRV, FR_A,    KC_B,    KC_C,    KC_D,    KC_E,    KC_F,    KC_G,
+    FR_EGRV, FR_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
     // h     i        j        k        l        m        n        o
-    KC_H,    KC_I,    KC_J,    KC_K,    KC_L,    FR_M,    KC_N,    KC_O,
+    KC_H, KC_I, KC_J, KC_K, KC_L, FR_M, KC_N, KC_O,
     // p     q        r        s        t        u        v        w
-    KC_P,    FR_Q,    KC_R,    KC_S,    KC_T,    KC_U,    KC_V,    FR_W,
+    KC_P, FR_Q, KC_R, KC_S, KC_T, KC_U, KC_V, FR_W,
     // x     y        z        {        |        }        ~        DEL
-    KC_X,    KC_Y,    FR_Z,    FR_APOS, FR_MINS, FR_EQL,  FR_EACU, KC_DEL
-};
+    KC_X, KC_Y, FR_Z, FR_APOS, FR_MINS, FR_EQL, FR_EACU, KC_DEL};
index 61d224824734cfb36127ef899012925bc215dfae..6efb6df01d6111cc97e1bf0693d7dc822e462da2 100644 (file)
 
 #include "keymap_german.h"
 
-const bool ascii_to_shift_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 1, 1, 0, 1, 1, 1, 1,
-    1, 1, 1, 0, 0, 0, 0, 1,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 1, 1, 0, 1, 1, 1,
-    0, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 0, 0, 0, 0, 1,
-    1, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0
-};
+                                              0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-const bool ascii_to_altgr_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_altgr_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    1, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 0
-};
+                                              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0};
 
 const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    KC_SPC,  DE_1,    DE_2,    DE_HASH, DE_4,    DE_5,    DE_6,    DE_HASH,
+    KC_SPC, DE_1, DE_2, DE_HASH, DE_4, DE_5, DE_6, DE_HASH,
     // (     )        *        +        ,        -        .        /
-    DE_8,    DE_9,    DE_PLUS, DE_PLUS, DE_COMM, DE_MINS, DE_DOT,  DE_7,
+    DE_8, DE_9, DE_PLUS, DE_PLUS, DE_COMM, DE_MINS, DE_DOT, DE_7,
     // 0     1        2        3        4        5        6        7
-    DE_0,    DE_1,    DE_2,    DE_3,    DE_4,    DE_5,    DE_6,    DE_7,
+    DE_0, DE_1, DE_2, DE_3, DE_4, DE_5, DE_6, DE_7,
     // 8     9        :        ;        <        =        >        ?
-    DE_8,    DE_9,    DE_DOT,  DE_COMM, DE_LESS, DE_0,    DE_LESS, DE_SS,
+    DE_8, DE_9, DE_DOT, DE_COMM, DE_LESS, DE_0, DE_LESS, DE_SS,
     // @     A        B        C        D        E        F        G
-    DE_Q,    DE_A,    DE_B,    DE_C,    DE_D,    DE_E,    DE_F,    DE_G,
+    DE_Q, DE_A, DE_B, DE_C, DE_D, DE_E, DE_F, DE_G,
     // H     I        J        K        L        M        N        O
-    DE_H,    DE_I,    DE_J,    DE_K,    DE_L,    DE_M,    DE_N,    DE_O,
+    DE_H, DE_I, DE_J, DE_K, DE_L, DE_M, DE_N, DE_O,
     // P     Q        R        S        T        U        V        W
-    DE_P,    DE_Q,    DE_R,    DE_S,    DE_T,    DE_U,    DE_V,    DE_W,
+    DE_P, DE_Q, DE_R, DE_S, DE_T, DE_U, DE_V, DE_W,
     // X     Y        Z        [        \        ]        ^        _
-    DE_X,    DE_Y,    DE_Z,    DE_8,    DE_SS,   DE_9,    DE_CIRC, DE_MINS,
+    DE_X, DE_Y, DE_Z, DE_8, DE_SS, DE_9, DE_CIRC, DE_MINS,
     // `     a        b        c        d        e        f        g
-    DE_ACUT, DE_A,    DE_B,    DE_C,    DE_D,    DE_E,    DE_F,    DE_G,
+    DE_ACUT, DE_A, DE_B, DE_C, DE_D, DE_E, DE_F, DE_G,
     // h     i        j        k        l        m        n        o
-    DE_H,    DE_I,    DE_J,    DE_K,    DE_L,    DE_M,    DE_N,    DE_O,
+    DE_H, DE_I, DE_J, DE_K, DE_L, DE_M, DE_N, DE_O,
     // p     q        r        s        t        u        v        w
-    DE_P,    DE_Q,    DE_R,    DE_S,    DE_T,    DE_U,    DE_V,    DE_W,
+    DE_P, DE_Q, DE_R, DE_S, DE_T, DE_U, DE_V, DE_W,
     // x     y        z        {        |        }        ~        DEL
-    DE_X,    DE_Y,    DE_Z,    DE_7,    DE_LESS, DE_0,    DE_PLUS, KC_DEL
-};
+    DE_X, DE_Y, DE_Z, DE_7, DE_LESS, DE_0, DE_PLUS, KC_DEL};
index fe42445f4aeeb6f3bd35c7131a06e15b4c8a9797..d0e65e446bef70ee32ecf6293258dba096be0c6d 100644 (file)
 
 #include "keymap_jp.h"
 
-const bool ascii_to_shift_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 1, 1, 1, 1,
-    0, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 0, 0, 0, 0, 1,
-    1, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 0
-};
+                                              0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0};
 
 const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    KC_SPC,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,
+    KC_SPC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
     // (     )        *        +        ,        -        .        /
-    KC_8,    KC_9,    JP_COLN, JP_SCLN, JP_COMM, JP_MINS, JP_DOT,  JP_SLSH,
+    KC_8, KC_9, JP_COLN, JP_SCLN, JP_COMM, JP_MINS, JP_DOT, JP_SLSH,
     // 0     1        2        3        4        5        6        7
-    KC_0,    KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,
+    KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
     // 8     9        :        ;        <        =        >        ?
-    KC_8,    KC_9,    JP_COLN, JP_SCLN, JP_COMM, JP_MINS, JP_DOT,  JP_SLSH,
+    KC_8, KC_9, JP_COLN, JP_SCLN, JP_COMM, JP_MINS, JP_DOT, JP_SLSH,
     // @     A        B        C        D        E        F        G
-    JP_AT,   KC_A,    KC_B,    KC_C,    KC_D,    KC_E,    KC_F,    KC_G,
+    JP_AT, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
     // H     I        J        K        L        M        N        O
-    KC_H,    KC_I,    KC_J,    KC_K,    KC_L,    KC_M,    KC_N,    KC_O,
+    KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
     // P     Q        R        S        T        U        V        W
-    KC_P,    KC_Q,    KC_R,    KC_S,    KC_T,    KC_U,    KC_V,    KC_W,
+    KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
     // X     Y        Z        [        \        ]        ^        _
-    KC_X,    KC_Y,    KC_Z,    JP_LBRC, JP_BSLS, JP_RBRC, JP_CIRC, JP_BSLS,
+    KC_X, KC_Y, KC_Z, JP_LBRC, JP_BSLS, JP_RBRC, JP_CIRC, JP_BSLS,
     // `     a        b        c        d        e        f        g
-    JP_AT,   KC_A,    KC_B,    KC_C,    KC_D,    KC_E,    KC_F,    KC_G,
+    JP_AT, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
     // h     i        j        k        l        m        n        o
-    KC_H,    KC_I,    KC_J,    KC_K,    KC_L,    KC_M,    KC_N,    KC_O,
+    KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
     // p     q        r        s        t        u        v        w
-    KC_P,    KC_Q,    KC_R,    KC_S,    KC_T,    KC_U,    KC_V,    KC_W,
+    KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
     // x     y        z        {        |        }        ~        DEL
-    KC_X,    KC_Y,    KC_Z,    JP_LBRC, JP_YEN,  JP_RBRC, JP_CIRC, KC_DEL
-};
+    KC_X, KC_Y, KC_Z, JP_LBRC, JP_YEN, JP_RBRC, JP_CIRC, KC_DEL};
index 8d4ec8dabd2cbace47c28dd37da7c430ad982771..312247d6ef4410c1451355295309d882896640cb 100644 (file)
@@ -24,34 +24,33 @@ const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    KC_SPC,  KC_1,    KC_QUOT, KC_3,    KC_4,    KC_5,    KC_7,    KC_QUOT,
+    KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
     // (     )        *        +        ,        -        .        /
-    KC_9,    KC_0,    KC_8,    KC_EQL,  KC_COMM, KC_MINS, KC_DOT,  KC_SLSH,
+    KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
     // 0     1        2        3        4        5        6        7
-    KC_0,    KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,
+    KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
     // 8     9        :        ;        <        =        >        ?
-    KC_8,    KC_9,    NM_SCLN, NM_SCLN, KC_COMM, KC_EQL,  KC_DOT,  KC_SLSH,
+    KC_8, KC_9, NM_SCLN, NM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
     // @     A        B        C        D        E        F        G
-    KC_2,    NM_A,    NM_B,    NM_C,    NM_D,    NM_E,    NM_F,    NM_G,
+    KC_2, NM_A, NM_B, NM_C, NM_D, NM_E, NM_F, NM_G,
     // H     I        J        K        L        M        N        O
-    NM_H,    NM_I,    NM_J,    NM_K,    NM_L,    NM_M,    NM_N,    NM_O,
+    NM_H, NM_I, NM_J, NM_K, NM_L, NM_M, NM_N, NM_O,
     // P     Q        R        S        T        U        V        W
-    NM_P,    NM_Q,    NM_R,    NM_S,    NM_T,    NM_U,    NM_V,    NM_W,
+    NM_P, NM_Q, NM_R, NM_S, NM_T, NM_U, NM_V, NM_W,
     // X     Y        Z        [        \        ]        ^        _
-    NM_X,    NM_Y,    NM_Z,    KC_LBRC, KC_BSLS, KC_RBRC, KC_6,    KC_MINS,
+    NM_X, NM_Y, NM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
     // `     a        b        c        d        e        f        g
-    KC_GRV,  NM_A,    NM_B,    NM_C,    NM_D,    NM_E,    NM_F,    NM_G,
+    KC_GRV, NM_A, NM_B, NM_C, NM_D, NM_E, NM_F, NM_G,
     // h     i        j        k        l        m        n        o
-    NM_H,    NM_I,    NM_J,    NM_K,    NM_L,    NM_M,    NM_N,    NM_O,
+    NM_H, NM_I, NM_J, NM_K, NM_L, NM_M, NM_N, NM_O,
     // p     q        r        s        t        u        v        w
-    NM_P,    NM_Q,    NM_R,    NM_S,    NM_T,    NM_U,    NM_V,    NM_W,
+    NM_P, NM_Q, NM_R, NM_S, NM_T, NM_U, NM_V, NM_W,
     // x     y        z        {        |        }        ~        DEL
-    NM_X,    NM_Y,    NM_Z,    KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV,  KC_DEL
-};
+    NM_X, NM_Y, NM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL};
index 985d602880036b1c80ef42e0336f23566c7a90bf..af2c2014915852c10f73a61c934703f795180bca 100644 (file)
 
 #include "keymap_spanish.h"
 
-const bool ascii_to_shift_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 1, 1, 0, 1, 1, 1, 0,
-    1, 1, 1, 0, 0, 0, 0, 1,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 1, 1, 0, 1, 1, 1,
-    0, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 0, 0, 0, 1, 1,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0
-};
+                                              0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-const bool ascii_to_altgr_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_altgr_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 0, 0, 1, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    1, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 0
-};
+                                              0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0};
 
 const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    KC_SPC,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    ES_APOS,
+    KC_SPC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, ES_APOS,
     // (     )        *        +        ,        -        .        /
-    KC_8,    KC_9,    ES_PLUS, ES_PLUS, KC_COMM, ES_MINS, KC_DOT,  KC_7,
+    KC_8, KC_9, ES_PLUS, ES_PLUS, KC_COMM, ES_MINS, KC_DOT, KC_7,
     // 0     1        2        3        4        5        6        7
-    KC_0,    KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,
+    KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
     // 8     9        :        ;        <        =        >        ?
-    KC_8,    KC_9,    KC_DOT,  KC_COMM, ES_LESS, KC_0,    ES_LESS, ES_APOS,
+    KC_8, KC_9, KC_DOT, KC_COMM, ES_LESS, KC_0, ES_LESS, ES_APOS,
     // @     A        B        C        D        E        F        G
-    KC_2,    KC_A,    KC_B,    KC_C,    KC_D,    KC_E,    KC_F,    KC_G,
+    KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
     // H     I        J        K        L        M        N        O
-    KC_H,    KC_I,    KC_J,    KC_K,    KC_L,    KC_M,    KC_N,    KC_O,
+    KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
     // P     Q        R        S        T        U        V        W
-    KC_P,    KC_Q,    KC_R,    KC_S,    KC_T,    KC_U,    KC_V,    KC_W,
+    KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
     // X     Y        Z        [        \        ]        ^        _
-    KC_X,    KC_Y,    KC_Z,    ES_GRV,  ES_OVRR, ES_PLUS, ES_GRV,  ES_MINS,
+    KC_X, KC_Y, KC_Z, ES_GRV, ES_OVRR, ES_PLUS, ES_GRV, ES_MINS,
     // `     a        b        c        d        e        f        g
-    ES_GRV,  KC_A,    KC_B,    KC_C,    KC_D,    KC_E,    KC_F,    KC_G,
+    ES_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
     // h     i        j        k        l        m        n        o
-    KC_H,    KC_I,    KC_J,    KC_K,    KC_L,    KC_M,    KC_N,    KC_O,
+    KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
     // p     q        r        s        t        u        v        w
-    KC_P,    KC_Q,    KC_R,    KC_S,    KC_T,    KC_U,    KC_V,    KC_W,
+    KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
     // x     y        z        {        |        }        ~        DEL
-    KC_X,    KC_Y,    KC_Z,    ES_ACUT, KC_1,    ES_CCED, ES_NTIL, KC_DEL
-};
+    KC_X, KC_Y, KC_Z, ES_ACUT, KC_1, ES_CCED, ES_NTIL, KC_DEL};
index a01c9bc43909b96d0876c63c126bd64a52f2c7aa..e5bbe25644485d6852e2682a7cb04f41e51fa53d 100644 (file)
 
 #include "keymap_uk.h"
 
-const bool ascii_to_shift_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
+const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
-    0, 1, 1, 0, 1, 1, 1, 0,
-    1, 1, 1, 1, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 1, 0, 1, 0, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 0, 0, 0, 1, 1,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 0
-};
+                                              0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0};
 
 const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    UK_SPC,  UK_1,    UK_2,    UK_HASH, UK_4,    UK_5,    UK_7,    UK_QUOT,
+    UK_SPC, UK_1, UK_2, UK_HASH, UK_4, UK_5, UK_7, UK_QUOT,
     // (     )        *        +        ,        -        .        /
-    UK_9,    UK_0,    UK_8,    UK_EQL,  UK_COMM, UK_MINS, UK_DOT,  UK_SLSH,
+    UK_9, UK_0, UK_8, UK_EQL, UK_COMM, UK_MINS, UK_DOT, UK_SLSH,
     // 0     1        2        3        4        5        6        7
-    UK_0,    UK_1,    UK_2,    UK_3,    UK_4,    UK_5,    UK_6,    UK_7,
+    UK_0, UK_1, UK_2, UK_3, UK_4, UK_5, UK_6, UK_7,
     // 8     9        :        ;        <        =        >        ?
-    UK_8,    UK_9,    UK_SCLN, UK_SCLN, UK_COMM, UK_EQL,  UK_DOT,  UK_SLSH,
+    UK_8, UK_9, UK_SCLN, UK_SCLN, UK_COMM, UK_EQL, UK_DOT, UK_SLSH,
     // @     A        B        C        D        E        F        G
-    UK_QUOT, UK_A,    UK_B,    UK_C,    UK_D,    UK_E,    UK_F,    UK_G,
+    UK_QUOT, UK_A, UK_B, UK_C, UK_D, UK_E, UK_F, UK_G,
     // H     I        J        K        L        M        N        O
-    UK_H,    UK_I,    UK_J,    UK_K,    UK_L,    UK_M,    UK_N,    UK_O,
+    UK_H, UK_I, UK_J, UK_K, UK_L, UK_M, UK_N, UK_O,
     // P     Q        R        S        T        U        V        W
-    UK_P,    UK_Q,    UK_R,    UK_S,    UK_T,    UK_U,    UK_V,    UK_W,
+    UK_P, UK_Q, UK_R, UK_S, UK_T, UK_U, UK_V, UK_W,
     // X     Y        Z        [        \        ]        ^        _
-    UK_X,    UK_Y,    UK_Z,    UK_LBRC, UK_BSLS, UK_RBRC, UK_6,    UK_MINS,
+    UK_X, UK_Y, UK_Z, UK_LBRC, UK_BSLS, UK_RBRC, UK_6, UK_MINS,
     // `     a        b        c        d        e        f        g
-    UK_GRV,  UK_A,    UK_B,    UK_C,    UK_D,    UK_E,    UK_F,    UK_G,
+    UK_GRV, UK_A, UK_B, UK_C, UK_D, UK_E, UK_F, UK_G,
     // h     i        j        k        l        m        n        o
-    UK_H,    UK_I,    UK_J,    UK_K,    UK_L,    UK_M,    UK_N,    UK_O,
+    UK_H, UK_I, UK_J, UK_K, UK_L, UK_M, UK_N, UK_O,
     // p     q        r        s        t        u        v        w
-    UK_P,    UK_Q,    UK_R,    UK_S,    UK_T,    UK_U,    UK_V,    UK_W,
+    UK_P, UK_Q, UK_R, UK_S, UK_T, UK_U, UK_V, UK_W,
     // x     y        z        {        |        }        ~        DEL
-    UK_X,    UK_Y,    UK_Z,    UK_LBRC, UK_BSLS, UK_RBRC, UK_HASH, KC_DEL
-};
+    UK_X, UK_Y, UK_Z, UK_LBRC, UK_BSLS, UK_RBRC, UK_HASH, KC_DEL};
index a0dd4756fffed3d39fd4f7df40087437b5542b85..239c9c0b6d43e91d74517c0e0e98cebf7f869895 100644 (file)
@@ -24,34 +24,33 @@ const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
     // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
     XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
     // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
 
     //       !        "        #        $        %        &        '
-    KC_SPC,  KC_1,    KC_QUOT, KC_3,    KC_4,    KC_5,    KC_7,    KC_QUOT,
+    KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
     // (     )        *        +        ,        -        .        /
-    KC_9,    KC_0,    KC_8,    KC_EQL,  KC_COMM, KC_MINS, KC_DOT,  KC_SLSH,
+    KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
     // 0     1        2        3        4        5        6        7
-    KC_0,    KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,
+    KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
     // 8     9        :        ;        <        =        >        ?
-    KC_8,    KC_9,    KC_SCLN, KC_SCLN, KC_COMM, KC_EQL,  KC_DOT,  KC_SLSH,
+    KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
     // @     A        B        C        D        E        F        G
-    KC_2,    WK_A,    WK_B,    WK_C,    WK_D,    WK_E,    WK_F,    WK_G,
+    KC_2, WK_A, WK_B, WK_C, WK_D, WK_E, WK_F, WK_G,
     // H     I        J        K        L        M        N        O
-    WK_H,    WK_I,    WK_J,    WK_K,    WK_L,    WK_M,    WK_N,    WK_O,
+    WK_H, WK_I, WK_J, WK_K, WK_L, WK_M, WK_N, WK_O,
     // P     Q        R        S        T        U        V        W
-    WK_P,    WK_Q,    WK_R,    WK_S,    WK_T,    WK_U,    WK_V,    WK_W,
+    WK_P, WK_Q, WK_R, WK_S, WK_T, WK_U, WK_V, WK_W,
     // X     Y        Z        [        \        ]        ^        _
-    WK_X,    WK_Y,    WK_Z,    KC_LBRC, KC_BSLS, KC_RBRC, KC_6,    KC_MINS,
+    WK_X, WK_Y, WK_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
     // `     a        b        c        d        e        f        g
-    KC_GRV,  WK_A,    WK_B,    WK_C,    WK_D,    WK_E,    WK_F,    WK_G,
+    KC_GRV, WK_A, WK_B, WK_C, WK_D, WK_E, WK_F, WK_G,
     // h     i        j        k        l        m        n        o
-    WK_H,    WK_I,    WK_J,    WK_K,    WK_L,    WK_M,    WK_N,    WK_O,
+    WK_H, WK_I, WK_J, WK_K, WK_L, WK_M, WK_N, WK_O,
     // p     q        r        s        t        u        v        w
-    WK_P,    WK_Q,    WK_R,    WK_S,    WK_T,    WK_U,    WK_V,    WK_W,
+    WK_P, WK_Q, WK_R, WK_S, WK_T, WK_U, WK_V, WK_W,
     // x     y        z        {        |        }        ~        DEL
-    WK_X,    WK_Y,    WK_Z,    KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV,  KC_DEL
-};
+    WK_X, WK_Y, WK_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL};
index 8ef8abe712b99cba2a45027451c24f9d73fca53b..5c24c797a91f0d0b69a0437cc02ceb483a1d2d81 100644 (file)
 led_config_t led_matrix_config;
 
 #ifndef MAX
-    #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
+#    define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
 #endif
 
 #ifndef MIN
-    #define MIN(a,b) ((a) < (b)? (a): (b))
+#    define MIN(a, b) ((a) < (b) ? (a) : (b))
 #endif
 
 #ifndef LED_DISABLE_AFTER_TIMEOUT
-    #define LED_DISABLE_AFTER_TIMEOUT 0
+#    define LED_DISABLE_AFTER_TIMEOUT 0
 #endif
 
 #ifndef LED_DISABLE_WHEN_USB_SUSPENDED
-    #define LED_DISABLE_WHEN_USB_SUSPENDED false
+#    define LED_DISABLE_WHEN_USB_SUSPENDED false
 #endif
 
 #ifndef EECONFIG_LED_MATRIX
-    #define EECONFIG_LED_MATRIX EECONFIG_RGBLIGHT
+#    define EECONFIG_LED_MATRIX EECONFIG_RGBLIGHT
 #endif
 
 #if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > 255
-    #define LED_MATRIX_MAXIMUM_BRIGHTNESS 255
+#    define LED_MATRIX_MAXIMUM_BRIGHTNESS 255
 #endif
 
 bool g_suspend_state = false;
@@ -64,37 +64,33 @@ uint8_t g_key_hit[LED_DRIVER_LED_COUNT];
 // Ticks since any key was last hit.
 uint32_t g_any_key_hit = 0;
 
-uint32_t eeconfig_read_led_matrix(void) {
-  return eeprom_read_dword(EECONFIG_LED_MATRIX);
-}
+uint32_t eeconfig_read_led_matrix(void) { return eeprom_read_dword(EECONFIG_LED_MATRIX); }
 
-void eeconfig_update_led_matrix(uint32_t config_value) {
-  eeprom_update_dword(EECONFIG_LED_MATRIX, config_value);
-}
+void eeconfig_update_led_matrix(uint32_t config_value) { eeprom_update_dword(EECONFIG_LED_MATRIX, config_value); }
 
 void eeconfig_update_led_matrix_default(void) {
-  dprintf("eeconfig_update_led_matrix_default\n");
-  led_matrix_config.enable = 1;
-  led_matrix_config.mode = LED_MATRIX_UNIFORM_BRIGHTNESS;
-  led_matrix_config.val = 128;
-  led_matrix_config.speed = 0;
-  eeconfig_update_led_matrix(led_matrix_config.raw);
+    dprintf("eeconfig_update_led_matrix_default\n");
+    led_matrix_config.enable = 1;
+    led_matrix_config.mode   = LED_MATRIX_UNIFORM_BRIGHTNESS;
+    led_matrix_config.val    = 128;
+    led_matrix_config.speed  = 0;
+    eeconfig_update_led_matrix(led_matrix_config.raw);
 }
 
 void eeconfig_debug_led_matrix(void) {
-  dprintf("led_matrix_config eeprom\n");
-  dprintf("led_matrix_config.enable = %d\n", led_matrix_config.enable);
-  dprintf("led_matrix_config.mode = %d\n", led_matrix_config.mode);
-  dprintf("led_matrix_config.val = %d\n", led_matrix_config.val);
-  dprintf("led_matrix_config.speed = %d\n", led_matrix_config.speed);
+    dprintf("led_matrix_config eeprom\n");
+    dprintf("led_matrix_config.enable = %d\n", led_matrix_config.enable);
+    dprintf("led_matrix_config.mode = %d\n", led_matrix_config.mode);
+    dprintf("led_matrix_config.val = %d\n", led_matrix_config.val);
+    dprintf("led_matrix_config.speed = %d\n", led_matrix_config.speed);
 }
 
 // Last led hit
 #ifndef LED_HITS_TO_REMEMBER
-    #define LED_HITS_TO_REMEMBER 8
+#    define LED_HITS_TO_REMEMBER 8
 #endif
 uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255};
-uint8_t g_last_led_count = 0;
+uint8_t g_last_led_count                     = 0;
 
 void map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i, uint8_t *led_count) {
     led_matrix led;
@@ -110,17 +106,11 @@ void map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i, uint8_t
     }
 }
 
-void led_matrix_update_pwm_buffers(void) {
-    led_matrix_driver.flush();
-}
+void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); }
 
-void led_matrix_set_index_value(int index, uint8_t value) {
-    led_matrix_driver.set_value(index, value);
-}
+void led_matrix_set_index_value(int index, uint8_t value) { led_matrix_driver.set_value(index, value); }
 
-void led_matrix_set_index_value_all(uint8_t value) {
-    led_matrix_driver.set_value_all(value);
-}
+void led_matrix_set_index_value_all(uint8_t value) { led_matrix_driver.set_value_all(value); }
 
 bool process_led_matrix(uint16_t keycode, keyrecord_t *record) {
     if (record->event.pressed) {
@@ -131,37 +121,29 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record) {
                 g_last_led_hit[i - 1] = g_last_led_hit[i - 2];
             }
             g_last_led_hit[0] = led[0];
-            g_last_led_count = MIN(LED_HITS_TO_REMEMBER, g_last_led_count + 1);
+            g_last_led_count  = MIN(LED_HITS_TO_REMEMBER, g_last_led_count + 1);
         }
-        for(uint8_t i = 0; i < led_count; i++)
-            g_key_hit[led[i]] = 0;
+        for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 0;
         g_any_key_hit = 0;
     } else {
-        #ifdef LED_MATRIX_KEYRELEASES
+#ifdef LED_MATRIX_KEYRELEASES
         uint8_t led[8], led_count;
         map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count);
-        for(uint8_t i = 0; i < led_count; i++)
-            g_key_hit[led[i]] = 255;
+        for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 255;
 
         g_any_key_hit = 255;
-        #endif
+#endif
     }
     return true;
 }
 
-void led_matrix_set_suspend_state(bool state) {
-    g_suspend_state = state;
-}
+void led_matrix_set_suspend_state(bool state) { g_suspend_state = state; }
 
 // All LEDs off
-void led_matrix_all_off(void) {
-    led_matrix_set_index_value_all(0);
-}
+void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); }
 
 // Uniform brightness
-void led_matrix_uniform_brightness(void) {
-    led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_config.val);
-}
+void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_config.val); }
 
 void led_matrix_custom(void) {}
 
@@ -180,17 +162,15 @@ void led_matrix_task(void) {
 
     for (int led = 0; led < LED_DRIVER_LED_COUNT; led++) {
         if (g_key_hit[led] < 255) {
-            if (g_key_hit[led] == 254)
-                g_last_led_count = MAX(g_last_led_count - 1, 0);
+            if (g_key_hit[led] == 254) g_last_led_count = MAX(g_last_led_count - 1, 0);
             g_key_hit[led]++;
         }
     }
 
     // Ideally we would also stop sending zeros to the LED driver PWM buffers
     // while suspended and just do a software shutdown. This is a cheap hack for now.
-    bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) ||
-            (LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20));
-    uint8_t effect = suspend_backlight ? 0 : led_matrix_config.mode;
+    bool    suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) || (LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20));
+    uint8_t effect            = suspend_backlight ? 0 : led_matrix_config.mode;
 
     // this gets ticked at 20 Hz.
     // each effect can opt to do calculations
@@ -217,12 +197,9 @@ void led_matrix_indicators(void) {
     led_matrix_indicators_user();
 }
 
-__attribute__((weak))
-void led_matrix_indicators_kb(void) {}
-
-__attribute__((weak))
-void led_matrix_indicators_user(void) {}
+__attribute__((weak)) void led_matrix_indicators_kb(void) {}
 
+__attribute__((weak)) void led_matrix_indicators_user(void) {}
 
 // void led_matrix_set_indicator_index(uint8_t *index, uint8_t row, uint8_t column)
 // {
@@ -248,7 +225,7 @@ void led_matrix_init(void) {
     wait_ms(500);
 
     // clear the key hits
-    for (int led=0; led<LED_DRIVER_LED_COUNT; led++) {
+    for (int led = 0; led < LED_DRIVER_LED_COUNT; led++) {
         g_key_hit[led] = 255;
     }
 
@@ -266,7 +243,7 @@ void led_matrix_init(void) {
         led_matrix_config.raw = eeconfig_read_led_matrix();
     }
 
-    eeconfig_debug_led_matrix(); // display current eeprom values
+    eeconfig_debug_led_matrix();  // display current eeprom values
 }
 
 // Deals with the messy details of incrementing an integer
@@ -303,32 +280,26 @@ static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max)
 //     }
 // }
 
-uint32_t led_matrix_get_tick(void) {
-    return g_tick;
-}
+uint32_t led_matrix_get_tick(void) { return g_tick; }
 
 void led_matrix_toggle(void) {
-         led_matrix_config.enable ^= 1;
+    led_matrix_config.enable ^= 1;
     eeconfig_update_led_matrix(led_matrix_config.raw);
 }
 
 void led_matrix_enable(void) {
-         led_matrix_config.enable = 1;
+    led_matrix_config.enable = 1;
     eeconfig_update_led_matrix(led_matrix_config.raw);
 }
 
-void led_matrix_enable_noeeprom(void) {
-         led_matrix_config.enable = 1;
-}
+void led_matrix_enable_noeeprom(void) { led_matrix_config.enable = 1; }
 
 void led_matrix_disable(void) {
-         led_matrix_config.enable = 0;
+    led_matrix_config.enable = 0;
     eeconfig_update_led_matrix(led_matrix_config.raw);
 }
 
-void led_matrix_disable_noeeprom(void) {
-         led_matrix_config.enable = 0;
-}
+void led_matrix_disable_noeeprom(void) { led_matrix_config.enable = 0; }
 
 void led_matrix_step(void) {
     led_matrix_config.mode++;
@@ -358,12 +329,12 @@ void led_matrix_decrease_val(void) {
 
 void led_matrix_increase_speed(void) {
     led_matrix_config.speed = increment(led_matrix_config.speed, 1, 0, 3);
-    eeconfig_update_led_matrix(led_matrix_config.raw);//EECONFIG needs to be increased to support this
+    eeconfig_update_led_matrix(led_matrix_config.raw);  // EECONFIG needs to be increased to support this
 }
 
 void led_matrix_decrease_speed(void) {
     led_matrix_config.speed = decrement(led_matrix_config.speed, 1, 0, 3);
-    eeconfig_update_led_matrix(led_matrix_config.raw);//EECONFIG needs to be increased to support this
+    eeconfig_update_led_matrix(led_matrix_config.raw);  // EECONFIG needs to be increased to support this
 }
 
 void led_matrix_mode(uint8_t mode, bool eeprom_write) {
@@ -373,19 +344,13 @@ void led_matrix_mode(uint8_t mode, bool eeprom_write) {
     }
 }
 
-uint8_t led_matrix_get_mode(void) {
-    return led_matrix_config.mode;
-}
+uint8_t led_matrix_get_mode(void) { return led_matrix_config.mode; }
 
-void led_matrix_set_value_noeeprom(uint8_t val) {
-    led_matrix_config.val = val;
-}
+void led_matrix_set_value_noeeprom(uint8_t val) { led_matrix_config.val = val; }
 
 void led_matrix_set_value(uint8_t val) {
     led_matrix_set_value_noeeprom(val);
     eeconfig_update_led_matrix(led_matrix_config.raw);
 }
 
-void backlight_set(uint8_t val) {
-    led_matrix_set_value(val);
-}
+void backlight_set(uint8_t val) { led_matrix_set_value(val); }
index cb91821a4028533a6a7cd9086947724e24d60df6..6877bf4c6bbbc121e6e7975f340ecac8e5f03780 100644 (file)
 
 #if defined(IS31FL3731) || defined(IS31FL3733)
 
-#if defined(IS31FL3731)
-    #include "is31fl3731-simple.h"
-#endif
+#    if defined(IS31FL3731)
+#        include "is31fl3731-simple.h"
+#    endif
 
-#include "i2c_master.h"
+#    include "i2c_master.h"
 
 static void init(void) {
     i2c_init();
-    #ifdef IS31FL3731
-        #ifdef LED_DRIVER_ADDR_1
-            IS31FL3731_init(LED_DRIVER_ADDR_1);
-        #endif
-        #ifdef LED_DRIVER_ADDR_2
-            IS31FL3731_init(LED_DRIVER_ADDR_2);
-        #endif
-        #ifdef LED_DRIVER_ADDR_3
-            IS31FL3731_init(LED_DRIVER_ADDR_3);
-        #endif
-        #ifdef LED_DRIVER_ADDR_4
-            IS31FL3731_init(LED_DRIVER_ADDR_4);
-        #endif
-    #else
-        #ifdef LED_DRIVER_ADDR_1
-            IS31FL3733_init(LED_DRIVER_ADDR_1, 0 );
-        #endif
-        #ifdef LED_DRIVER_ADDR_2
-            IS31FL3733_init(LED_DRIVER_ADDR_2, 0 );
-        #endif
-        #ifdef LED_DRIVER_ADDR_3
-            IS31FL3733_init(LED_DRIVER_ADDR_3, 0 );
-        #endif
-        #ifdef LED_DRIVER_ADDR_4
-            IS31FL3733_init(LED_DRIVER_ADDR_4, 0 );
-        #endif
-    #endif
+#    ifdef IS31FL3731
+#        ifdef LED_DRIVER_ADDR_1
+    IS31FL3731_init(LED_DRIVER_ADDR_1);
+#        endif
+#        ifdef LED_DRIVER_ADDR_2
+    IS31FL3731_init(LED_DRIVER_ADDR_2);
+#        endif
+#        ifdef LED_DRIVER_ADDR_3
+    IS31FL3731_init(LED_DRIVER_ADDR_3);
+#        endif
+#        ifdef LED_DRIVER_ADDR_4
+    IS31FL3731_init(LED_DRIVER_ADDR_4);
+#        endif
+#    else
+#        ifdef LED_DRIVER_ADDR_1
+    IS31FL3733_init(LED_DRIVER_ADDR_1, 0);
+#        endif
+#        ifdef LED_DRIVER_ADDR_2
+    IS31FL3733_init(LED_DRIVER_ADDR_2, 0);
+#        endif
+#        ifdef LED_DRIVER_ADDR_3
+    IS31FL3733_init(LED_DRIVER_ADDR_3, 0);
+#        endif
+#        ifdef LED_DRIVER_ADDR_4
+    IS31FL3733_init(LED_DRIVER_ADDR_4, 0);
+#        endif
+#    endif
 
     for (int index = 0; index < LED_DRIVER_LED_COUNT; index++) {
-        #ifdef IS31FL3731
-            IS31FL3731_set_led_control_register(index, true);
-        #else
-            IS31FL3733_set_led_control_register(index, true);
-        #endif
+#    ifdef IS31FL3731
+        IS31FL3731_set_led_control_register(index, true);
+#    else
+        IS31FL3733_set_led_control_register(index, true);
+#    endif
     }
-    // This actually updates the LED drivers
-    #ifdef IS31FL3731
-        #ifdef LED_DRIVER_ADDR_1
-            IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
-        #endif
-        #ifdef LED_DRIVER_ADDR_2
-            IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
-        #endif
-        #ifdef LED_DRIVER_ADDR_3
-            IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
-        #endif
-        #ifdef LED_DRIVER_ADDR_4
-            IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
-        #endif
-    #else
-        #ifdef LED_DRIVER_ADDR_1
-            IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
-        #endif
-        #ifdef LED_DRIVER_ADDR_2
-            IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
-        #endif
-        #ifdef LED_DRIVER_ADDR_3
-            IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
-        #endif
-        #ifdef LED_DRIVER_ADDR_4
-            IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
-        #endif
-    #endif
+// This actually updates the LED drivers
+#    ifdef IS31FL3731
+#        ifdef LED_DRIVER_ADDR_1
+    IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
+#        endif
+#        ifdef LED_DRIVER_ADDR_2
+    IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
+#        endif
+#        ifdef LED_DRIVER_ADDR_3
+    IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
+#        endif
+#        ifdef LED_DRIVER_ADDR_4
+    IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
+#        endif
+#    else
+#        ifdef LED_DRIVER_ADDR_1
+    IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
+#        endif
+#        ifdef LED_DRIVER_ADDR_2
+    IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
+#        endif
+#        ifdef LED_DRIVER_ADDR_3
+    IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
+#        endif
+#        ifdef LED_DRIVER_ADDR_4
+    IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
+#        endif
+#    endif
 }
 
 static void flush(void) {
-    #ifdef IS31FL3731
-        #ifdef LED_DRIVER_ADDR_1
-            IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
-        #endif
-        #ifdef LED_DRIVER_ADDR_2
-            IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
-        #endif
-        #ifdef LED_DRIVER_ADDR_3
-            IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
-        #endif
-        #ifdef LED_DRIVER_ADDR_4
-            IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
-        #endif
-    #else
-        #ifdef LED_DRIVER_ADDR_1
-            IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
-        #endif
-        #ifdef LED_DRIVER_ADDR_2
-            IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
-        #endif
-        #ifdef LED_DRIVER_ADDR_3
-            IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
-        #endif
-        #ifdef LED_DRIVER_ADDR_4
-            IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
-        #endif
-    #endif
+#    ifdef IS31FL3731
+#        ifdef LED_DRIVER_ADDR_1
+    IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
+#        endif
+#        ifdef LED_DRIVER_ADDR_2
+    IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
+#        endif
+#        ifdef LED_DRIVER_ADDR_3
+    IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
+#        endif
+#        ifdef LED_DRIVER_ADDR_4
+    IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
+#        endif
+#    else
+#        ifdef LED_DRIVER_ADDR_1
+    IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
+#        endif
+#        ifdef LED_DRIVER_ADDR_2
+    IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
+#        endif
+#        ifdef LED_DRIVER_ADDR_3
+    IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
+#        endif
+#        ifdef LED_DRIVER_ADDR_4
+    IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
+#        endif
+#    endif
 }
 
 const led_matrix_driver_t led_matrix_driver = {
-    .init = init,
+    .init  = init,
     .flush = flush,
-#ifdef IS31FL3731
-    .set_value = IS31FL3731_set_value,
+#    ifdef IS31FL3731
+    .set_value     = IS31FL3731_set_value,
     .set_value_all = IS31FL3731_set_value_all,
-#else
+#    else
     .set_value = IS31FL3733_set_value,
     .set_value_all = IS31FL3733_set_value_all,
-#endif
+#    endif
 };
 
-
 #endif
index 0eeb5c44b6026c8008c9548d3322033ec488fcb1..8cbf6f4c022422b05782441cefa9d0f6d3f6812a 100644 (file)
@@ -15,47 +15,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "led_tables.h"
 
-
 #ifdef USE_CIE1931_CURVE
 // Lightness curve using the CIE 1931 lightness formula
-//Generated by the python script provided in http://jared.geek.nz/2013/feb/linear-led-pwm
-const uint8_t CIE1931_CURVE[256] PROGMEM = {
-  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   1,   1,   1,   1,   1,   1,
-  1,   1,   1,   2,   2,   2,   2,   2,   2,   2,   2,   3,   3,   3,   3,   3,
-  3,   3,   4,   4,   4,   4,   4,   5,   5,   5,   5,   5,   6,   6,   6,   6,
-  6,   7,   7,   7,   7,   8,   8,   8,   8,   9,   9,   9,  10,  10,  10,  11,
- 11,  11,  12,  12,  12,  13,  13,  13,  14,  14,  14,  15,  15,  16,  16,  16,
- 17,  17,  18,  18,  19,  19,  20,  20,  21,  21,  22,  22,  23,  23,  24,  24,
- 25,  25,  26,  26,  27,  28,  28,  29,  29,  30,  31,  31,  32,  33,  33,  34,
- 35,  35,  36,  37,  37,  38,  39,  40,  40,  41,  42,  43,  44,  44,  45,  46,
- 47,  48,  49,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,
- 62,  63,  64,  65,  66,  67,  68,  69,  70,  71,  72,  73,  75,  76,  77,  78,
- 79,  80,  82,  83,  84,  85,  87,  88,  89,  90,  92,  93,  94,  96,  97,  99,
-100, 101, 103, 104, 106, 107, 108, 110, 111, 113, 114, 116, 118, 119, 121, 122,
-124, 125, 127, 129, 130, 132, 134, 135, 137, 139, 141, 142, 144, 146, 148, 149,
-151, 153, 155, 157, 159, 161, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180,
-182, 185, 187, 189, 191, 193, 195, 197, 200, 202, 204, 206, 208, 211, 213, 215,
-218, 220, 222, 225, 227, 230, 232, 234, 237, 239, 242, 244, 247, 249, 252, 255
-};
+// Generated by the python script provided in http://jared.geek.nz/2013/feb/linear-led-pwm
+const uint8_t CIE1931_CURVE[256] PROGMEM = {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,   7,   7,   7,   7,   8,   8,   8,   8,   9,   9,   9,   10,  10,  10,  11,  11,  11,  12,  12,  12,  13,  13,  13,  14,  14,  14,  15,  15,  16,  16,  16,  17,  17,  18,  18,  19,  19,  20,  20,  21,  21,  22,  22,  23,  23,  24,  24,  25,  25,  26,  26,  27,  28,  28,  29,  29,  30,  31,  31,  32,  33,  33,  34,  35,  35,  36,  37,  37,  38,  39,  40,  40,  41,  42,  43,  44,  44,  45,  46,
+                                            47, 48, 49, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 96, 97, 99, 100, 101, 103, 104, 106, 107, 108, 110, 111, 113, 114, 116, 118, 119, 121, 122, 124, 125, 127, 129, 130, 132, 134, 135, 137, 139, 141, 142, 144, 146, 148, 149, 151, 153, 155, 157, 159, 161, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 185, 187, 189, 191, 193, 195, 197, 200, 202, 204, 206, 208, 211, 213, 215, 218, 220, 222, 225, 227, 230, 232, 234, 237, 239, 242, 244, 247, 249, 252, 255};
 #endif
 
 #ifdef USE_LED_BREATHING_TABLE
-const uint8_t LED_BREATHING_TABLE[256] PROGMEM = {
-  0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9,
-  10, 11, 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35,
-  37, 40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76,
-  79, 82, 85, 88, 90, 93, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124,
-  127, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 162, 165, 167, 170, 173,
-  176, 179, 182, 185, 188, 190, 193, 196, 198, 201, 203, 206, 208, 211, 213, 215,
-  218, 220, 222, 224, 226, 228, 230, 232, 234, 235, 237, 238, 240, 241, 243, 244,
-  245, 246, 248, 249, 250, 250, 251, 252, 253, 253, 254, 254, 254, 255, 255, 255,
-  255, 255, 255, 255, 254, 254, 254, 253, 253, 252, 251, 250, 250, 249, 248, 246,
-  245, 244, 243, 241, 240, 238, 237, 235, 234, 232, 230, 228, 226, 224, 222, 220,
-  218, 215, 213, 211, 208, 206, 203, 201, 198, 196, 193, 190, 188, 185, 182, 179,
-  176, 173, 170, 167, 165, 162, 158, 155, 152, 149, 146, 143, 140, 137, 134, 131,
-  128, 124, 121, 118, 115, 112, 109, 106, 103, 100, 97, 93, 90, 88, 85, 82,
-  79, 76, 73, 70, 67, 65, 62, 59, 57, 54, 52, 49, 47, 44, 42, 40,
-  37, 35, 33, 31, 29, 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11,
-  10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0
-};
+const uint8_t LED_BREATHING_TABLE[256] PROGMEM = {0,   0,   0,   0,   1,   1,   1,   2,   2,   3,   4,   5,   5,   6,   7,   9,   10,  11,  12,  14,  15,  17,  18,  20,  21,  23,  25,  27,  29,  31,  33,  35,  37,  40,  42,  44,  47,  49,  52,  54,  57,  59,  62,  65,  67,  70,  73,  76,  79,  82,  85,  88,  90,  93,  97,  100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 162, 165, 167, 170, 173, 176, 179, 182, 185, 188, 190, 193, 196, 198, 201, 203, 206, 208, 211, 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 234, 235, 237, 238, 240, 241, 243, 244, 245, 246, 248, 249, 250, 250, 251, 252, 253, 253, 254, 254, 254, 255, 255, 255,
+                                                  255, 255, 255, 255, 254, 254, 254, 253, 253, 252, 251, 250, 250, 249, 248, 246, 245, 244, 243, 241, 240, 238, 237, 235, 234, 232, 230, 228, 226, 224, 222, 220, 218, 215, 213, 211, 208, 206, 203, 201, 198, 196, 193, 190, 188, 185, 182, 179, 176, 173, 170, 167, 165, 162, 158, 155, 152, 149, 146, 143, 140, 137, 134, 131, 128, 124, 121, 118, 115, 112, 109, 106, 103, 100, 97,  93,  90,  88,  85,  82,  79,  76,  73,  70,  67,  65,  62,  59,  57,  54,  52,  49,  47,  44,  42,  40,  37,  35,  33,  31,  29,  27,  25,  23,  21,  20,  18,  17,  15,  14,  12,  11,  10,  9,   7,   6,   5,   5,   4,   3,   2,   2,   1,   1,   1,   0,   0,   0};
 #endif
index 618c5d67674e863a4399ba18eb45417066496621..5867ba9876515201b9307b77ad984740546e9eff 100644 (file)
 #ifndef LED_MATRIX_H
 #define LED_MATRIX_H
 
-
 #ifndef BACKLIGHT_ENABLE
-  #error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE
+#    error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE
 #endif
 
-
 typedef struct Point {
-       uint8_t x;
-       uint8_t y;
+    uint8_t x;
+    uint8_t y;
 } __attribute__((packed)) Point;
 
 typedef struct led_matrix {
-       union {
-               uint8_t raw;
-               struct {
-                       uint8_t row:4; // 16 max
-                       uint8_t col:4; // 16 max
-               };
-       } matrix_co;
-       Point point;
-       uint8_t modifier:1;
+    union {
+        uint8_t raw;
+        struct {
+            uint8_t row : 4;  // 16 max
+            uint8_t col : 4;  // 16 max
+        };
+    } matrix_co;
+    Point   point;
+    uint8_t modifier : 1;
 } __attribute__((packed)) led_matrix;
 
 extern const led_matrix g_leds[LED_DRIVER_LED_COUNT];
 
 typedef struct {
-       uint8_t index;
-       uint8_t value;
+    uint8_t index;
+    uint8_t value;
 } led_indicator;
 
 typedef union {
-  uint32_t raw;
-  struct {
-    bool     enable  :1;
-    uint8_t  mode    :6;
-    uint8_t  hue     :8; // Unused by led_matrix
-    uint8_t  sat     :8; // Unused by led_matrix
-    uint8_t  val     :8;
-    uint8_t  speed   :8;//EECONFIG needs to be increased to support this
-  };
+    uint32_t raw;
+    struct {
+        bool    enable : 1;
+        uint8_t mode : 6;
+        uint8_t hue : 8;  // Unused by led_matrix
+        uint8_t sat : 8;  // Unused by led_matrix
+        uint8_t val : 8;
+        uint8_t speed : 8;  // EECONFIG needs to be increased to support this
+    };
 } led_config_t;
 
 enum led_matrix_effects {
@@ -95,22 +93,22 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record);
 
 uint32_t led_matrix_get_tick(void);
 
-void led_matrix_toggle(void);
-void led_matrix_enable(void);
-void led_matrix_enable_noeeprom(void);
-void led_matrix_disable(void);
-void led_matrix_disable_noeeprom(void);
-void led_matrix_step(void);
-void led_matrix_step_reverse(void);
-void led_matrix_increase_val(void);
-void led_matrix_decrease_val(void);
-void led_matrix_increase_speed(void);
-void led_matrix_decrease_speed(void);
-void led_matrix_mode(uint8_t mode, bool eeprom_write);
-void led_matrix_mode_noeeprom(uint8_t mode);
+void    led_matrix_toggle(void);
+void    led_matrix_enable(void);
+void    led_matrix_enable_noeeprom(void);
+void    led_matrix_disable(void);
+void    led_matrix_disable_noeeprom(void);
+void    led_matrix_step(void);
+void    led_matrix_step_reverse(void);
+void    led_matrix_increase_val(void);
+void    led_matrix_decrease_val(void);
+void    led_matrix_increase_speed(void);
+void    led_matrix_decrease_speed(void);
+void    led_matrix_mode(uint8_t mode, bool eeprom_write);
+void    led_matrix_mode_noeeprom(uint8_t mode);
 uint8_t led_matrix_get_mode(void);
-void led_matrix_set_value(uint8_t mode);
-void led_matrix_set_value_noeeprom(uint8_t mode);
+void    led_matrix_set_value(uint8_t mode);
+void    led_matrix_set_value_noeeprom(uint8_t mode);
 
 typedef struct {
     /* Perform any initialisation required for the other driver functions to work. */
index 7ccac3533195d8898b211a29f727824681520816..907492a0f620b63bbd2ee1531eb6c593c03af78e 100644 (file)
@@ -25,24 +25,24 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "quantum.h"
 
 #if (MATRIX_COLS <= 8)
-#    define print_matrix_header()  print("\nr/c 01234567\n")
-#    define print_matrix_row(row)  print_bin_reverse8(matrix_get_row(row))
-#    define matrix_bitpop(i)       bitpop(matrix[i])
+#    define print_matrix_header() print("\nr/c 01234567\n")
+#    define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
+#    define matrix_bitpop(i) bitpop(matrix[i])
 #    define ROW_SHIFTER ((uint8_t)1)
 #elif (MATRIX_COLS <= 16)
-#    define print_matrix_header()  print("\nr/c 0123456789ABCDEF\n")
-#    define print_matrix_row(row)  print_bin_reverse16(matrix_get_row(row))
-#    define matrix_bitpop(i)       bitpop16(matrix[i])
+#    define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
+#    define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
+#    define matrix_bitpop(i) bitpop16(matrix[i])
 #    define ROW_SHIFTER ((uint16_t)1)
 #elif (MATRIX_COLS <= 32)
-#    define print_matrix_header()  print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
-#    define print_matrix_row(row)  print_bin_reverse32(matrix_get_row(row))
-#    define matrix_bitpop(i)       bitpop32(matrix[i])
-#    define ROW_SHIFTER  ((uint32_t)1)
+#    define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
+#    define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
+#    define matrix_bitpop(i) bitpop32(matrix[i])
+#    define ROW_SHIFTER ((uint32_t)1)
 #endif
 
 #ifdef MATRIX_MASKED
-    extern const matrix_row_t matrix_mask[];
+extern const matrix_row_t matrix_mask[];
 #endif
 
 #ifdef DIRECT_PINS
@@ -53,63 +53,34 @@ static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
 #endif
 
 /* matrix state(1:on, 0:off) */
-static matrix_row_t raw_matrix[MATRIX_ROWS]; //raw values
-static matrix_row_t matrix[MATRIX_ROWS]; //debounced values
+static matrix_row_t raw_matrix[MATRIX_ROWS];  // raw values
+static matrix_row_t matrix[MATRIX_ROWS];      // debounced values
 
-__attribute__ ((weak))
-void matrix_init_quantum(void) {
-    matrix_init_kb();
-}
+__attribute__((weak)) void matrix_init_quantum(void) { matrix_init_kb(); }
 
-__attribute__ ((weak))
-void matrix_scan_quantum(void) {
-    matrix_scan_kb();
-}
+__attribute__((weak)) void matrix_scan_quantum(void) { matrix_scan_kb(); }
 
-__attribute__ ((weak))
-void matrix_init_kb(void) {
-    matrix_init_user();
-}
+__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); }
 
-__attribute__ ((weak))
-void matrix_scan_kb(void) {
-    matrix_scan_user();
-}
+__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); }
 
-__attribute__ ((weak))
-void matrix_init_user(void) {
-}
+__attribute__((weak)) void matrix_init_user(void) {}
 
-__attribute__ ((weak))
-void matrix_scan_user(void) {
-}
+__attribute__((weak)) void matrix_scan_user(void) {}
 
-inline
-uint8_t matrix_rows(void) {
-    return MATRIX_ROWS;
-}
+inline uint8_t matrix_rows(void) { return MATRIX_ROWS; }
 
-inline
-uint8_t matrix_cols(void) {
-    return MATRIX_COLS;
-}
+inline uint8_t matrix_cols(void) { return MATRIX_COLS; }
 
-//Deprecated.
-bool matrix_is_modified(void)
-{
+// Deprecated.
+bool matrix_is_modified(void) {
     if (debounce_active()) return false;
     return true;
 }
 
-inline
-bool matrix_is_on(uint8_t row, uint8_t col)
-{
-    return (matrix[row] & ((matrix_row_t)1<<col));
-}
+inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); }
 
-inline
-matrix_row_t matrix_get_row(uint8_t row)
-{
+inline matrix_row_t matrix_get_row(uint8_t row) {
     // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a
     // switch blocker installed and the switch is always pressed.
 #ifdef MATRIX_MASKED
@@ -119,19 +90,18 @@ matrix_row_t matrix_get_row(uint8_t row)
 #endif
 }
 
-void matrix_print(void)
-{
+void matrix_print(void) {
     print_matrix_header();
 
     for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
-        phex(row); print(": ");
+        phex(row);
+        print(": ");
         print_matrix_row(row);
         print("\n");
     }
 }
 
-uint8_t matrix_key_count(void)
-{
+uint8_t matrix_key_count(void) {
     uint8_t count = 0;
     for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
         count += matrix_bitpop(i);
@@ -139,63 +109,56 @@ uint8_t matrix_key_count(void)
     return count;
 }
 
-
 #ifdef DIRECT_PINS
 
 static void init_pins(void) {
-  for (int row = 0; row < MATRIX_ROWS; row++) {
-    for (int col = 0; col < MATRIX_COLS; col++) {
-      pin_t pin = direct_pins[row][col];
-      if (pin != NO_PIN) {
-        setPinInputHigh(pin);
-      }
+    for (int row = 0; row < MATRIX_ROWS; row++) {
+        for (int col = 0; col < MATRIX_COLS; col++) {
+            pin_t pin = direct_pins[row][col];
+            if (pin != NO_PIN) {
+                setPinInputHigh(pin);
+            }
+        }
     }
-  }
 }
 
 static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
-  matrix_row_t last_row_value = current_matrix[current_row];
-  current_matrix[current_row] = 0;
+    matrix_row_t last_row_value = current_matrix[current_row];
+    current_matrix[current_row] = 0;
 
-  for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
-    pin_t pin = direct_pins[current_row][col_index];
-    if (pin != NO_PIN) {
-      current_matrix[current_row] |= readPin(pin) ? 0 : (ROW_SHIFTER << col_index);
+    for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
+        pin_t pin = direct_pins[current_row][col_index];
+        if (pin != NO_PIN) {
+            current_matrix[current_row] |= readPin(pin) ? 0 : (ROW_SHIFTER << col_index);
+        }
     }
-  }
 
-  return (last_row_value != current_matrix[current_row]);
+    return (last_row_value != current_matrix[current_row]);
 }
 
 #elif (DIODE_DIRECTION == COL2ROW)
 
-static void select_row(uint8_t row)
-{
+static void select_row(uint8_t row) {
     setPinOutput(row_pins[row]);
     writePinLow(row_pins[row]);
 }
 
-static void unselect_row(uint8_t row)
-{
-    setPinInputHigh(row_pins[row]);
-}
+static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); }
 
-static void unselect_rows(void)
-{
-    for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
+static void unselect_rows(void) {
+    for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
         setPinInputHigh(row_pins[x]);
     }
 }
 
 static void init_pins(void) {
-  unselect_rows();
-  for (uint8_t x = 0; x < MATRIX_COLS; x++) {
-    setPinInputHigh(col_pins[x]);
-  }
+    unselect_rows();
+    for (uint8_t x = 0; x < MATRIX_COLS; x++) {
+        setPinInputHigh(col_pins[x]);
+    }
 }
 
-static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
-{
+static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
     // Store last value of row prior to reading
     matrix_row_t last_row_value = current_matrix[current_row];
 
@@ -207,13 +170,12 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
     wait_us(30);
 
     // For each col...
-    for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
-
+    for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
         // Select the col pin to read (active low)
         uint8_t pin_state = readPin(col_pins[col_index]);
 
         // Populate the matrix row with the state of the col pin
-        current_matrix[current_row] |=  pin_state ? 0 : (ROW_SHIFTER << col_index);
+        current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
     }
 
     // Unselect row
@@ -224,33 +186,27 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
 
 #elif (DIODE_DIRECTION == ROW2COL)
 
-static void select_col(uint8_t col)
-{
+static void select_col(uint8_t col) {
     setPinOutput(col_pins[col]);
     writePinLow(col_pins[col]);
 }
 
-static void unselect_col(uint8_t col)
-{
-    setPinInputHigh(col_pins[col]);
-}
+static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); }
 
-static void unselect_cols(void)
-{
-    for(uint8_t x = 0; x < MATRIX_COLS; x++) {
+static void unselect_cols(void) {
+    for (uint8_t x = 0; x < MATRIX_COLS; x++) {
         setPinInputHigh(col_pins[x]);
     }
 }
 
 static void init_pins(void) {
-  unselect_cols();
-  for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
-    setPinInputHigh(row_pins[x]);
-  }
+    unselect_cols();
+    for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
+        setPinInputHigh(row_pins[x]);
+    }
 }
 
-static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
-{
+static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) {
     bool matrix_changed = false;
 
     // Select col and wait for col selecton to stabilize
@@ -258,27 +214,21 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
     wait_us(30);
 
     // For each row...
-    for(uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++)
-    {
-
+    for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) {
         // Store last value of row prior to reading
         matrix_row_t last_row_value = current_matrix[row_index];
 
         // Check row pin state
-        if (readPin(row_pins[row_index]) == 0)
-        {
+        if (readPin(row_pins[row_index]) == 0) {
             // Pin LO, set col bit
             current_matrix[row_index] |= (ROW_SHIFTER << current_col);
-        }
-        else
-        {
+        } else {
             // Pin HI, clear col bit
             current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
         }
 
         // Determine if the matrix changed state
-        if ((last_row_value != current_matrix[row_index]) && !(matrix_changed))
-        {
+        if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) {
             matrix_changed = true;
         }
     }
@@ -292,14 +242,13 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
 #endif
 
 void matrix_init(void) {
-
     // initialize key pins
     init_pins();
 
     // initialize matrix state: all keys off
-    for (uint8_t i=0; i < MATRIX_ROWS; i++) {
+    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
         raw_matrix[i] = 0;
-        matrix[i] = 0;
+        matrix[i]     = 0;
     }
 
     debounce_init(MATRIX_ROWS);
@@ -307,24 +256,23 @@ void matrix_init(void) {
     matrix_init_quantum();
 }
 
-uint8_t matrix_scan(void)
-{
-  bool changed = false;
+uint8_t matrix_scan(void) {
+    bool changed = false;
 
 #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW)
-  // Set row, read cols
-  for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
-    changed |= read_cols_on_row(raw_matrix, current_row);
-  }
+    // Set row, read cols
+    for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
+        changed |= read_cols_on_row(raw_matrix, current_row);
+    }
 #elif (DIODE_DIRECTION == ROW2COL)
-  // Set col, read rows
-  for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
-    changed |= read_rows_on_col(raw_matrix, current_col);
-  }
+    // Set col, read rows
+    for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
+        changed |= read_rows_on_col(raw_matrix, current_col);
+    }
 #endif
 
-  debounce(raw_matrix, matrix, MATRIX_ROWS, changed);
+    debounce(raw_matrix, matrix, MATRIX_ROWS, changed);
 
-  matrix_scan_quantum();
-  return (uint8_t)changed;
+    matrix_scan_quantum();
+    return (uint8_t)changed;
 }
index d77977ebe245a027352c98cc4ed7806a4f29e92a..204fddf30c5cf80d1e54c639cd5ac46a627a4ad8 100644 (file)
 #include <avr/io.h>
 
 enum {
-  PinDirectionInput = 0,
-  PinDirectionOutput = 1,
-  PinLevelHigh = 1,
-  PinLevelLow = 0,
+    PinDirectionInput  = 0,
+    PinDirectionOutput = 1,
+    PinLevelHigh       = 1,
+    PinLevelLow        = 0,
 };
 
 // ex: pinMode(B0, PinDirectionOutput);
 static inline void pinMode(uint8_t pin, int mode) {
-  uint8_t bv = _BV(pin & 0xf);
-  if (mode == PinDirectionOutput) {
-    _SFR_IO8((pin >> 4) + 1) |= bv;
-  } else {
-    _SFR_IO8((pin >> 4) + 1) &= ~bv;
-    _SFR_IO8((pin >> 4) + 2) &= ~bv;
-  }
+    uint8_t bv = _BV(pin & 0xf);
+    if (mode == PinDirectionOutput) {
+        _SFR_IO8((pin >> 4) + 1) |= bv;
+    } else {
+        _SFR_IO8((pin >> 4) + 1) &= ~bv;
+        _SFR_IO8((pin >> 4) + 2) &= ~bv;
+    }
 }
 
 // ex: digitalWrite(B0, PinLevelHigh);
 static inline void digitalWrite(uint8_t pin, int mode) {
-  uint8_t bv = _BV(pin & 0xf);
-  if (mode == PinLevelHigh) {
-    _SFR_IO8((pin >> 4) + 2) |= bv;
-  } else {
-    _SFR_IO8((pin >> 4) + 2) &= ~bv;
-  }
+    uint8_t bv = _BV(pin & 0xf);
+    if (mode == PinLevelHigh) {
+        _SFR_IO8((pin >> 4) + 2) |= bv;
+    } else {
+        _SFR_IO8((pin >> 4) + 2) &= ~bv;
+    }
 }
 
 // Return true if the pin is HIGH
 // digitalRead(B0)
-static inline bool digitalRead(uint8_t pin) {
-  return _SFR_IO8(pin >> 4) & _BV(pin & 0xf);
-}
+static inline bool digitalRead(uint8_t pin) { return _SFR_IO8(pin >> 4) & _BV(pin & 0xf); }
index e60ae8d93e40af982b050faf253a390845403f9d..24a487b9aac7b83edbebd806e99e4b72c47ce122 100644 (file)
@@ -25,38 +25,31 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 static report_mouse_t mouseReport = {};
 
-__attribute__ ((weak))
-void pointing_device_init(void){
-    //initialize device, if that needs to be done.
+__attribute__((weak)) void pointing_device_init(void) {
+    // initialize device, if that needs to be done.
 }
 
-__attribute__ ((weak))
-void pointing_device_send(void){
-    //If you need to do other things, like debugging, this is the place to do it.
+__attribute__((weak)) void pointing_device_send(void) {
+    // If you need to do other things, like debugging, this is the place to do it.
     host_mouse_send(&mouseReport);
-       //send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
-       mouseReport.x = 0;
-       mouseReport.y = 0;
-       mouseReport.v = 0;
-       mouseReport.h = 0;
+    // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
+    mouseReport.x = 0;
+    mouseReport.y = 0;
+    mouseReport.v = 0;
+    mouseReport.h = 0;
 }
 
-__attribute__ ((weak))
-void pointing_device_task(void){
-    //gather info and put it in:
-    //mouseReport.x = 127 max -127 min
-    //mouseReport.y = 127 max -127 min
-    //mouseReport.v = 127 max -127 min (scroll vertical)
-    //mouseReport.h = 127 max -127 min (scroll horizontal)
-    //mouseReport.buttons = 0x1F (decimal 31, binary 00011111) max (bitmask for mouse buttons 1-5, 1 is rightmost, 5 is leftmost) 0x00 min
-    //send the report
+__attribute__((weak)) void pointing_device_task(void) {
+    // gather info and put it in:
+    // mouseReport.x = 127 max -127 min
+    // mouseReport.y = 127 max -127 min
+    // mouseReport.v = 127 max -127 min (scroll vertical)
+    // mouseReport.h = 127 max -127 min (scroll horizontal)
+    // mouseReport.buttons = 0x1F (decimal 31, binary 00011111) max (bitmask for mouse buttons 1-5, 1 is rightmost, 5 is leftmost) 0x00 min
+    // send the report
     pointing_device_send();
 }
 
-report_mouse_t pointing_device_get_report(void){
-       return mouseReport;
-}
+report_mouse_t pointing_device_get_report(void) { return mouseReport; }
 
-void pointing_device_set_report(report_mouse_t newMouseReport){
-       mouseReport = newMouseReport;
-}
\ No newline at end of file
+void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = newMouseReport; }
\ No newline at end of file
index 1944d820659ba491aee5db518861c0270481cef7..29398ebb3acced78a144bc8a7dd8ae2bbcf875e6 100644 (file)
@@ -22,10 +22,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "host.h"
 #include "report.h"
 
-void pointing_device_init(void);
-void pointing_device_task(void);
-void pointing_device_send(void);
+void           pointing_device_init(void);
+void           pointing_device_task(void);
+void           pointing_device_send(void);
 report_mouse_t pointing_device_get_report(void);
-void pointing_device_set_report(report_mouse_t newMouseReport);
+void           pointing_device_set_report(report_mouse_t newMouseReport);
 
 #endif
index 0a25aa5354f14c45923255f9c322864830d5a1ef..3b5fa8490b93ae76c8eb7e9a221bb6687570c3dd 100644 (file)
@@ -2,30 +2,28 @@
 #include "process_audio.h"
 
 #ifndef VOICE_CHANGE_SONG
-    #define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND)
+#    define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND)
 #endif
 float voice_change_song[][2] = VOICE_CHANGE_SONG;
 
 #ifndef PITCH_STANDARD_A
-    #define PITCH_STANDARD_A 440.0f
+#    define PITCH_STANDARD_A 440.0f
 #endif
 
-float compute_freq_for_midi_note(uint8_t note)
-{
+float compute_freq_for_midi_note(uint8_t note) {
     // https://en.wikipedia.org/wiki/MIDI_tuning_standard
     return pow(2.0, (note - 69) / 12.0) * PITCH_STANDARD_A;
 }
 
 bool process_audio(uint16_t keycode, keyrecord_t *record) {
-
     if (keycode == AU_ON && record->event.pressed) {
-      audio_on();
-      return false;
+        audio_on();
+        return false;
     }
 
     if (keycode == AU_OFF && record->event.pressed) {
-      audio_off();
-      return false;
+        audio_off();
+        return false;
     }
 
     if (keycode == AU_TOG && record->event.pressed) {
@@ -52,17 +50,10 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
     return true;
 }
 
-void process_audio_noteon(uint8_t note) {
-    play_note(compute_freq_for_midi_note(note), 0xF);
-}
+void process_audio_noteon(uint8_t note) { play_note(compute_freq_for_midi_note(note), 0xF); }
 
-void process_audio_noteoff(uint8_t note) {
-    stop_note(compute_freq_for_midi_note(note));
-}
+void process_audio_noteoff(uint8_t note) { stop_note(compute_freq_for_midi_note(note)); }
 
-void process_audio_all_notes_off(void) {
-    stop_all_notes();
-}
+void process_audio_all_notes_off(void) { stop_all_notes(); }
 
-__attribute__ ((weak))
-void audio_on_user() {}
+__attribute__((weak)) void audio_on_user() {}
index 0d0930ee67752e5a7d544ee3c2dbc6264bbde406..4ae3fe446e351f07813a9f17b81e4e9917f52120 100644 (file)
 
 #ifdef AUTO_SHIFT_ENABLE
 
-#include <stdio.h>
+#    include <stdio.h>
 
-#include "process_auto_shift.h"
+#    include "process_auto_shift.h"
 
-#define TAP(key) \
-  register_code(key); \
-  unregister_code(key)
+#    define TAP(key)        \
+        register_code(key); \
+        unregister_code(key)
 
-#define TAP_WITH_MOD(mod, key) \
-  register_code(mod); \
-  register_code(key); \
-  unregister_code(key); \
-  unregister_code(mod)
+#    define TAP_WITH_MOD(mod, key) \
+        register_code(mod);        \
+        register_code(key);        \
+        unregister_code(key);      \
+        unregister_code(mod)
 
-uint16_t autoshift_time = 0;
+uint16_t autoshift_time    = 0;
 uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT;
 uint16_t autoshift_lastkey = KC_NO;
 
 void autoshift_timer_report(void) {
-  char display[8];
+    char display[8];
 
-  snprintf(display, 8, "\n%d\n", autoshift_timeout);
+    snprintf(display, 8, "\n%d\n", autoshift_timeout);
 
-  send_string((const char *)display);
+    send_string((const char *)display);
 }
 
 void autoshift_on(uint16_t keycode) {
-  autoshift_time = timer_read();
-  autoshift_lastkey = keycode;
+    autoshift_time    = timer_read();
+    autoshift_lastkey = keycode;
 }
 
 void autoshift_flush(void) {
-  if (autoshift_lastkey != KC_NO) {
-    uint16_t elapsed = timer_elapsed(autoshift_time);
+    if (autoshift_lastkey != KC_NO) {
+        uint16_t elapsed = timer_elapsed(autoshift_time);
 
-    if (elapsed > autoshift_timeout) {
-      register_code(KC_LSFT);
-    }
+        if (elapsed > autoshift_timeout) {
+            register_code(KC_LSFT);
+        }
 
-    register_code(autoshift_lastkey);
-    unregister_code(autoshift_lastkey);
+        register_code(autoshift_lastkey);
+        unregister_code(autoshift_lastkey);
 
-    if (elapsed > autoshift_timeout) {
-      unregister_code(KC_LSFT);
-    }
+        if (elapsed > autoshift_timeout) {
+            unregister_code(KC_LSFT);
+        }
 
-    autoshift_time = 0;
-    autoshift_lastkey = KC_NO;
-  }
+        autoshift_time    = 0;
+        autoshift_lastkey = KC_NO;
+    }
 }
 
 bool autoshift_enabled = true;
 
-void autoshift_enable(void) {
-    autoshift_enabled = true;
-}
+void autoshift_enable(void) { autoshift_enabled = true; }
 void autoshift_disable(void) {
-  autoshift_enabled = false;
-  autoshift_flush();
-}
-
-void autoshift_toggle(void) {
-  if (autoshift_enabled) {
     autoshift_enabled = false;
     autoshift_flush();
-  }
-  else {
-    autoshift_enabled = true;
-  }
 }
 
-bool autoshift_state(void) {
-  return autoshift_enabled;
+void autoshift_toggle(void) {
+    if (autoshift_enabled) {
+        autoshift_enabled = false;
+        autoshift_flush();
+    } else {
+        autoshift_enabled = true;
+    }
 }
 
-bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
-#ifndef AUTO_SHIFT_MODIFIERS
-  static uint8_t any_mod_pressed;
-#endif
-
-  if (record->event.pressed) {
-    switch (keycode) {
-      case KC_ASUP:
-        autoshift_timeout += 5;
-        return false;
-
-      case KC_ASDN:
-        autoshift_timeout -= 5;
-        return false;
-
-      case KC_ASRP:
-        autoshift_timer_report();
-        return false;
-
-      case KC_ASTG:
-        autoshift_toggle();
-        return false;
-      case KC_ASON:
-        autoshift_enable();
-        return false;
-      case KC_ASOFF:
-        autoshift_disable();
-        return false;
-
-#ifndef NO_AUTO_SHIFT_ALPHA
-      case KC_A:
-      case KC_B:
-      case KC_C:
-      case KC_D:
-      case KC_E:
-      case KC_F:
-      case KC_G:
-      case KC_H:
-      case KC_I:
-      case KC_J:
-      case KC_K:
-      case KC_L:
-      case KC_M:
-      case KC_N:
-      case KC_O:
-      case KC_P:
-      case KC_Q:
-      case KC_R:
-      case KC_S:
-      case KC_T:
-      case KC_U:
-      case KC_V:
-      case KC_W:
-      case KC_X:
-      case KC_Y:
-      case KC_Z:
-#endif
-#ifndef NO_AUTO_SHIFT_NUMERIC
-      case KC_1:
-      case KC_2:
-      case KC_3:
-      case KC_4:
-      case KC_5:
-      case KC_6:
-      case KC_7:
-      case KC_8:
-      case KC_9:
-      case KC_0:
-#endif
-#ifndef NO_AUTO_SHIFT_SPECIAL
-      case KC_MINUS:
-      case KC_EQL:
-      case KC_TAB:
-      case KC_LBRC:
-      case KC_RBRC:
-      case KC_BSLS:
-      case KC_SCLN:
-      case KC_QUOT:
-      case KC_COMM:
-      case KC_DOT:
-      case KC_SLSH:
-      case KC_GRAVE:
-      case KC_NONUS_BSLASH:
-      case KC_NONUS_HASH:
-#endif
+bool autoshift_state(void) { return autoshift_enabled; }
 
-        autoshift_flush();
-        if (!autoshift_enabled) return true;
-
-#ifndef AUTO_SHIFT_MODIFIERS
-        any_mod_pressed = get_mods() & (
-          MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)|
-          MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT)|
-          MOD_BIT(KC_LCTL)|MOD_BIT(KC_RCTL)|
-          MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)
-        );
-
-        if (any_mod_pressed) {
-          return true;
+bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
+#    ifndef AUTO_SHIFT_MODIFIERS
+    static uint8_t any_mod_pressed;
+#    endif
+
+    if (record->event.pressed) {
+        switch (keycode) {
+            case KC_ASUP:
+                autoshift_timeout += 5;
+                return false;
+
+            case KC_ASDN:
+                autoshift_timeout -= 5;
+                return false;
+
+            case KC_ASRP:
+                autoshift_timer_report();
+                return false;
+
+            case KC_ASTG:
+                autoshift_toggle();
+                return false;
+            case KC_ASON:
+                autoshift_enable();
+                return false;
+            case KC_ASOFF:
+                autoshift_disable();
+                return false;
+
+#    ifndef NO_AUTO_SHIFT_ALPHA
+            case KC_A:
+            case KC_B:
+            case KC_C:
+            case KC_D:
+            case KC_E:
+            case KC_F:
+            case KC_G:
+            case KC_H:
+            case KC_I:
+            case KC_J:
+            case KC_K:
+            case KC_L:
+            case KC_M:
+            case KC_N:
+            case KC_O:
+            case KC_P:
+            case KC_Q:
+            case KC_R:
+            case KC_S:
+            case KC_T:
+            case KC_U:
+            case KC_V:
+            case KC_W:
+            case KC_X:
+            case KC_Y:
+            case KC_Z:
+#    endif
+#    ifndef NO_AUTO_SHIFT_NUMERIC
+            case KC_1:
+            case KC_2:
+            case KC_3:
+            case KC_4:
+            case KC_5:
+            case KC_6:
+            case KC_7:
+            case KC_8:
+            case KC_9:
+            case KC_0:
+#    endif
+#    ifndef NO_AUTO_SHIFT_SPECIAL
+            case KC_MINUS:
+            case KC_EQL:
+            case KC_TAB:
+            case KC_LBRC:
+            case KC_RBRC:
+            case KC_BSLS:
+            case KC_SCLN:
+            case KC_QUOT:
+            case KC_COMM:
+            case KC_DOT:
+            case KC_SLSH:
+            case KC_GRAVE:
+            case KC_NONUS_BSLASH:
+            case KC_NONUS_HASH:
+#    endif
+
+                autoshift_flush();
+                if (!autoshift_enabled) return true;
+
+#    ifndef AUTO_SHIFT_MODIFIERS
+                any_mod_pressed = get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI) | MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT) | MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL) | MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT));
+
+                if (any_mod_pressed) {
+                    return true;
+                }
+#    endif
+
+                autoshift_on(keycode);
+                return false;
+
+            default:
+                autoshift_flush();
+                return true;
         }
-#endif
-
-        autoshift_on(keycode);
-        return false;
-
-      default:
+    } else {
         autoshift_flush();
-        return true;
     }
-  } else {
-    autoshift_flush();
-  }
 
-  return true;
+    return true;
 }
 
 #endif
index a4abf04145653c82f14562774dcb55b7e9e4dd4b..083325d8e391245d26064cf512224dd2df7bf2a8 100644 (file)
@@ -20,7 +20,7 @@
 #include "quantum.h"
 
 #ifndef AUTO_SHIFT_TIMEOUT
-  #define AUTO_SHIFT_TIMEOUT 175
+#    define AUTO_SHIFT_TIMEOUT 175
 #endif
 
 bool process_auto_shift(uint16_t keycode, keyrecord_t *record);
index 43b803afe7fd465a7a3646c7f57ead9f7f0c82ef..6ab382d4aadf7f57e804516bf853548ee7089ec7 100644 (file)
 
 #ifdef AUDIO_CLICKY
 
-#ifndef AUDIO_CLICKY_DELAY_DURATION
-#define AUDIO_CLICKY_DELAY_DURATION 1
-#endif // !AUDIO_CLICKY_DELAY_DURATION
-#ifndef AUDIO_CLICKY_FREQ_DEFAULT
-#define AUDIO_CLICKY_FREQ_DEFAULT 440.0f
-#endif // !AUDIO_CLICKY_FREQ_DEFAULT
-#ifndef AUDIO_CLICKY_FREQ_MIN
-#define AUDIO_CLICKY_FREQ_MIN 65.0f
-#endif // !AUDIO_CLICKY_FREQ_MIN
-#ifndef AUDIO_CLICKY_FREQ_MAX
-#define AUDIO_CLICKY_FREQ_MAX 1500.0f
-#endif // !AUDIO_CLICKY_FREQ_MAX
-#ifndef AUDIO_CLICKY_FREQ_FACTOR
-#define AUDIO_CLICKY_FREQ_FACTOR 1.18921f
-#endif // !AUDIO_CLICKY_FREQ_FACTOR
-#ifndef AUDIO_CLICKY_FREQ_RANDOMNESS
-#define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f
-#endif // !AUDIO_CLICKY_FREQ_RANDOMNESS
+#    ifndef AUDIO_CLICKY_DELAY_DURATION
+#        define AUDIO_CLICKY_DELAY_DURATION 1
+#    endif  // !AUDIO_CLICKY_DELAY_DURATION
+#    ifndef AUDIO_CLICKY_FREQ_DEFAULT
+#        define AUDIO_CLICKY_FREQ_DEFAULT 440.0f
+#    endif  // !AUDIO_CLICKY_FREQ_DEFAULT
+#    ifndef AUDIO_CLICKY_FREQ_MIN
+#        define AUDIO_CLICKY_FREQ_MIN 65.0f
+#    endif  // !AUDIO_CLICKY_FREQ_MIN
+#    ifndef AUDIO_CLICKY_FREQ_MAX
+#        define AUDIO_CLICKY_FREQ_MAX 1500.0f
+#    endif  // !AUDIO_CLICKY_FREQ_MAX
+#    ifndef AUDIO_CLICKY_FREQ_FACTOR
+#        define AUDIO_CLICKY_FREQ_FACTOR 1.18921f
+#    endif  // !AUDIO_CLICKY_FREQ_FACTOR
+#    ifndef AUDIO_CLICKY_FREQ_RANDOMNESS
+#        define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f
+#    endif  // !AUDIO_CLICKY_FREQ_RANDOMNESS
 
 float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT;
 float clicky_rand = AUDIO_CLICKY_FREQ_RANDOMNESS;
 
 // the first "note" is an intentional delay; the 2nd and 3rd notes are the "clicky"
-float clicky_song[][2]  = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations
+float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}};  // 3 and 1 --> durations
 
 extern audio_config_t audio_config;
 
-#ifndef NO_MUSIC_MODE
+#    ifndef NO_MUSIC_MODE
 extern bool music_activated;
 extern bool midi_activated;
-#endif // !NO_MUSIC_MODE
+#    endif  // !NO_MUSIC_MODE
 
 void clicky_play(void) {
-#ifndef NO_MUSIC_MODE
-  if (music_activated || midi_activated || !audio_config.enable) return;
-#endif // !NO_MUSIC_MODE
-  clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
-  clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
-  PLAY_SONG(clicky_song);
+#    ifndef NO_MUSIC_MODE
+    if (music_activated || midi_activated || !audio_config.enable) return;
+#    endif  // !NO_MUSIC_MODE
+    clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX))));
+    clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX))));
+    PLAY_SONG(clicky_song);
 }
 
 void clicky_freq_up(void) {
-  float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR;
-  if (new_freq < AUDIO_CLICKY_FREQ_MAX) {
-    clicky_freq = new_freq;
-  }
+    float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR;
+    if (new_freq < AUDIO_CLICKY_FREQ_MAX) {
+        clicky_freq = new_freq;
+    }
 }
 
 void clicky_freq_down(void) {
-  float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR;
-  if (new_freq > AUDIO_CLICKY_FREQ_MIN) {
-    clicky_freq = new_freq;
-  }
+    float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR;
+    if (new_freq > AUDIO_CLICKY_FREQ_MIN) {
+        clicky_freq = new_freq;
+    }
 }
 
-void clicky_freq_reset(void) {
-  clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT;
-}
+void clicky_freq_reset(void) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; }
 
 void clicky_toggle(void) {
-  audio_config.clicky_enable ^= 1;
-  eeconfig_update_audio(audio_config.raw);
+    audio_config.clicky_enable ^= 1;
+    eeconfig_update_audio(audio_config.raw);
 }
 
 void clicky_on(void) {
-  audio_config.clicky_enable = 1;
-  eeconfig_update_audio(audio_config.raw);
+    audio_config.clicky_enable = 1;
+    eeconfig_update_audio(audio_config.raw);
 }
 
 void clicky_off(void) {
-  audio_config.clicky_enable = 0;
-  eeconfig_update_audio(audio_config.raw);
+    audio_config.clicky_enable = 0;
+    eeconfig_update_audio(audio_config.raw);
 }
 
-bool is_clicky_on(void) {
-  return (audio_config.clicky_enable != 0);
-}
+bool is_clicky_on(void) { return (audio_config.clicky_enable != 0); }
 
 bool process_clicky(uint16_t keycode, keyrecord_t *record) {
-  if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_toggle(); }
-
-  if (keycode == CLICKY_ENABLE && record->event.pressed) { clicky_on(); }
-  if (keycode == CLICKY_DISABLE && record->event.pressed) { clicky_off(); }
+    if (keycode == CLICKY_TOGGLE && record->event.pressed) {
+        clicky_toggle();
+    }
 
-  if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq_reset(); }
+    if (keycode == CLICKY_ENABLE && record->event.pressed) {
+        clicky_on();
+    }
+    if (keycode == CLICKY_DISABLE && record->event.pressed) {
+        clicky_off();
+    }
 
-  if (keycode == CLICKY_UP && record->event.pressed) { clicky_freq_up(); }
-  if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); }
+    if (keycode == CLICKY_RESET && record->event.pressed) {
+        clicky_freq_reset();
+    }
 
+    if (keycode == CLICKY_UP && record->event.pressed) {
+        clicky_freq_up();
+    }
+    if (keycode == CLICKY_DOWN && record->event.pressed) {
+        clicky_freq_down();
+    }
 
-  if (audio_config.enable && audio_config.clicky_enable) {
-    if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound
-      if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM
-        clicky_play();
-      }
+    if (audio_config.enable && audio_config.clicky_enable) {
+        if (record->event.pressed) {                       // Leave this separate so it's easier to add upstroke sound
+            if (keycode != AU_OFF && keycode != AU_TOG) {  // DO NOT PLAY if audio will be disabled, and causes issuse on ARM
+                clicky_play();
+            }
+        }
     }
-  }
-  return true;
+    return true;
 }
 
-#endif //AUDIO_CLICKY
+#endif  // AUDIO_CLICKY
index d3c3b1673c385fe138388808f6e433b5b3cc4824..f40ca745252b0724d302e645482f96e224b5e1c3 100644 (file)
@@ -21,14 +21,13 @@ __attribute__((weak)) combo_t key_combos[COMBO_COUNT] = {
 
 };
 
-__attribute__((weak)) void process_combo_event(uint8_t combo_index,
-                                               bool pressed) {}
+__attribute__((weak)) void process_combo_event(uint8_t combo_index, bool pressed) {}
 
-static uint16_t timer = 0;
-static uint8_t current_combo_index = 0;
-static bool drop_buffer = false;
-static bool is_active = false;
-static bool b_combo_enable = true; // defaults to enabled
+static uint16_t timer               = 0;
+static uint8_t  current_combo_index = 0;
+static bool     drop_buffer         = false;
+static bool     is_active           = false;
+static bool     b_combo_enable      = true;  // defaults to enabled
 
 static uint8_t buffer_size = 0;
 #ifdef COMBO_ALLOW_ACTION_KEYS
@@ -38,171 +37,163 @@ static uint16_t key_buffer[MAX_COMBO_LENGTH];
 #endif
 
 static inline void send_combo(uint16_t action, bool pressed) {
-  if (action) {
-    if (pressed) {
-      register_code16(action);
+    if (action) {
+        if (pressed) {
+            register_code16(action);
+        } else {
+            unregister_code16(action);
+        }
     } else {
-      unregister_code16(action);
+        process_combo_event(current_combo_index, pressed);
     }
-  } else {
-    process_combo_event(current_combo_index, pressed);
-  }
 }
 
 static inline void dump_key_buffer(bool emit) {
-  if (buffer_size == 0) {
-    return;
-  }
+    if (buffer_size == 0) {
+        return;
+    }
 
-  if (emit) {
-    for (uint8_t i = 0; i < buffer_size; i++) {
+    if (emit) {
+        for (uint8_t i = 0; i < buffer_size; i++) {
 #ifdef COMBO_ALLOW_ACTION_KEYS
-      const action_t action = store_or_get_action(key_buffer[i].event.pressed,
-                                                  key_buffer[i].event.key);
-      process_action(&(key_buffer[i]), action);
+            const action_t action = store_or_get_action(key_buffer[i].event.pressed, key_buffer[i].event.key);
+            process_action(&(key_buffer[i]), action);
 #else
-      register_code16(key_buffer[i]);
-      send_keyboard_report();
+            register_code16(key_buffer[i]);
+            send_keyboard_report();
 #endif
+        }
     }
-  }
 
-  buffer_size = 0;
+    buffer_size = 0;
 }
 
 #define ALL_COMBO_KEYS_ARE_DOWN (((1 << count) - 1) == combo->state)
-#define KEY_STATE_DOWN(key)                                                    \
-  do {                                                                         \
-    combo->state |= (1 << key);                                                \
-  } while (0)
-#define KEY_STATE_UP(key)                                                      \
-  do {                                                                         \
-    combo->state &= ~(1 << key);                                               \
-  } while (0)
-
-static bool process_single_combo(combo_t *combo, uint16_t keycode,
-                                 keyrecord_t *record) {
-  uint8_t count = 0;
-  uint8_t index = -1;
-  /* Find index of keycode and number of combo keys */
-  for (const uint16_t *keys = combo->keys;; ++count) {
-    uint16_t key = pgm_read_word(&keys[count]);
-    if (keycode == key)
-      index = count;
-    if (COMBO_END == key)
-      break;
-  }
-
-  /* Continue processing if not a combo key */
-  if (-1 == (int8_t)index)
-    return false;
-
-  bool is_combo_active = is_active;
-
-  if (record->event.pressed) {
-    KEY_STATE_DOWN(index);
-
-    if (is_combo_active) {
-      if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */
-        send_combo(combo->keycode, true);
-        drop_buffer = true;
-      }
+#define KEY_STATE_DOWN(key)         \
+    do {                            \
+        combo->state |= (1 << key); \
+    } while (0)
+#define KEY_STATE_UP(key)            \
+    do {                             \
+        combo->state &= ~(1 << key); \
+    } while (0)
+
+static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *record) {
+    uint8_t count = 0;
+    uint8_t index = -1;
+    /* Find index of keycode and number of combo keys */
+    for (const uint16_t *keys = combo->keys;; ++count) {
+        uint16_t key = pgm_read_word(&keys[count]);
+        if (keycode == key) index = count;
+        if (COMBO_END == key) break;
     }
-  } else {
-    if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */
-      send_combo(combo->keycode, false);
+
+    /* Continue processing if not a combo key */
+    if (-1 == (int8_t)index) return false;
+
+    bool is_combo_active = is_active;
+
+    if (record->event.pressed) {
+        KEY_STATE_DOWN(index);
+
+        if (is_combo_active) {
+            if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */
+                send_combo(combo->keycode, true);
+                drop_buffer = true;
+            }
+        }
     } else {
-      /* continue processing without immediately returning */
-      is_combo_active = false;
+        if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */
+            send_combo(combo->keycode, false);
+        } else {
+            /* continue processing without immediately returning */
+            is_combo_active = false;
+        }
+
+        KEY_STATE_UP(index);
     }
 
-    KEY_STATE_UP(index);
-  }
-
-  return is_combo_active;
+    return is_combo_active;
 }
 
 #define NO_COMBO_KEYS_ARE_DOWN (0 == combo->state)
 
 bool process_combo(uint16_t keycode, keyrecord_t *record) {
-  bool is_combo_key = false;
-  drop_buffer = false;
-  bool no_combo_keys_pressed = true;
-
-  if (keycode == CMB_ON && record->event.pressed) {
-    combo_enable();
-    return true;
-  }
-
-  if (keycode == CMB_OFF && record->event.pressed) {
-    combo_disable();
-    return true;
-  }
-
-  if (keycode == CMB_TOG && record->event.pressed) {
-    combo_toggle();
-    return true;
-  }
-
-  if (!is_combo_enabled()) { return true; }
-
-  for (current_combo_index = 0; current_combo_index < COMBO_COUNT;
-       ++current_combo_index) {
-    combo_t *combo = &key_combos[current_combo_index];
-    is_combo_key |= process_single_combo(combo, keycode, record);
-    no_combo_keys_pressed = no_combo_keys_pressed && NO_COMBO_KEYS_ARE_DOWN;
-  }
-
-  if (drop_buffer) {
-    /* buffer is only dropped when we complete a combo, so we refresh the timer
-     * here */
-    timer = timer_read();
-    dump_key_buffer(false);
-  } else if (!is_combo_key) {
-    /* if no combos claim the key we need to emit the keybuffer */
-    dump_key_buffer(true);
+    bool is_combo_key          = false;
+    drop_buffer                = false;
+    bool no_combo_keys_pressed = true;
+
+    if (keycode == CMB_ON && record->event.pressed) {
+        combo_enable();
+        return true;
+    }
 
-    // reset state if there are no combo keys pressed at all
-    if (no_combo_keys_pressed) {
-      timer = 0;
-      is_active = true;
+    if (keycode == CMB_OFF && record->event.pressed) {
+        combo_disable();
+        return true;
     }
-  } else if (record->event.pressed && is_active) {
-    /* otherwise the key is consumed and placed in the buffer */
-    timer = timer_read();
 
-    if (buffer_size < MAX_COMBO_LENGTH) {
+    if (keycode == CMB_TOG && record->event.pressed) {
+        combo_toggle();
+        return true;
+    }
+
+    if (!is_combo_enabled()) {
+        return true;
+    }
+
+    for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) {
+        combo_t *combo = &key_combos[current_combo_index];
+        is_combo_key |= process_single_combo(combo, keycode, record);
+        no_combo_keys_pressed = no_combo_keys_pressed && NO_COMBO_KEYS_ARE_DOWN;
+    }
+
+    if (drop_buffer) {
+        /* buffer is only dropped when we complete a combo, so we refresh the timer
+         * here */
+        timer = timer_read();
+        dump_key_buffer(false);
+    } else if (!is_combo_key) {
+        /* if no combos claim the key we need to emit the keybuffer */
+        dump_key_buffer(true);
+
+        // reset state if there are no combo keys pressed at all
+        if (no_combo_keys_pressed) {
+            timer     = 0;
+            is_active = true;
+        }
+    } else if (record->event.pressed && is_active) {
+        /* otherwise the key is consumed and placed in the buffer */
+        timer = timer_read();
+
+        if (buffer_size < MAX_COMBO_LENGTH) {
 #ifdef COMBO_ALLOW_ACTION_KEYS
-      key_buffer[buffer_size++] = *record;
+            key_buffer[buffer_size++] = *record;
 #else
-      key_buffer[buffer_size++] = keycode;
+            key_buffer[buffer_size++] = keycode;
 #endif
+        }
     }
-  }
 
-  return !is_combo_key;
+    return !is_combo_key;
 }
 
 void matrix_scan_combo(void) {
-  if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) {
-
-    /* This disables the combo, meaning key events for this
-     * combo will be handled by the next processors in the chain
-     */
-    is_active = false;
-    dump_key_buffer(true);
-  }
+    if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) {
+        /* This disables the combo, meaning key events for this
+         * combo will be handled by the next processors in the chain
+         */
+        is_active = false;
+        dump_key_buffer(true);
+    }
 }
 
-void combo_enable(void) {
-    b_combo_enable = true;
-}
+void combo_enable(void) { b_combo_enable = true; }
 
 void combo_disable(void) {
     b_combo_enable = is_active = false;
-    timer = 0;
+    timer                      = 0;
     dump_key_buffer(true);
-
 }
 
 void combo_toggle(void) {
@@ -213,6 +204,4 @@ void combo_toggle(void) {
     }
 }
 
-bool is_combo_enabled(void) {
-    return b_combo_enable;
-}
+bool is_combo_enabled(void) { return b_combo_enable; }
index aab2849572808011dc9fbee9589333f6b660c879..e21ee19609f609efa5f3b713e5b99fd9e92f7193 100644 (file)
 #include <stdint.h>
 
 #ifdef EXTRA_EXTRA_LONG_COMBOS
-#define MAX_COMBO_LENGTH 32
+#    define MAX_COMBO_LENGTH 32
 #elif EXTRA_LONG_COMBOS
-#define MAX_COMBO_LENGTH 16
+#    define MAX_COMBO_LENGTH 16
 #else
-#define MAX_COMBO_LENGTH 8
+#    define MAX_COMBO_LENGTH 8
 #endif
 
 typedef struct {
-  const uint16_t *keys;
-  uint16_t keycode;
+    const uint16_t *keys;
+    uint16_t        keycode;
 #ifdef EXTRA_EXTRA_LONG_COMBOS
-  uint32_t state;
+    uint32_t state;
 #elif EXTRA_LONG_COMBOS
-  uint16_t state;
+    uint16_t state;
 #else
-  uint8_t state;
+    uint8_t state;
 #endif
 } combo_t;
 
-#define COMBO(ck, ca)                                                          \
-  { .keys = &(ck)[0], .keycode = (ca) }
-#define COMBO_ACTION(ck)                                                       \
-  { .keys = &(ck)[0] }
+#define COMBO(ck, ca) \
+    { .keys = &(ck)[0], .keycode = (ca) }
+#define COMBO_ACTION(ck) \
+    { .keys = &(ck)[0] }
 
 #define COMBO_END 0
 #ifndef COMBO_COUNT
-#define COMBO_COUNT 0
+#    define COMBO_COUNT 0
 #endif
 #ifndef COMBO_TERM
-#define COMBO_TERM TAPPING_TERM
+#    define COMBO_TERM TAPPING_TERM
 #endif
 
 bool process_combo(uint16_t keycode, keyrecord_t *record);
index 50cc0a5ccbb2415c7091fb57655f2e72935e9abf..602127a74b6c56f2c5fdec73d4a772aa4ecac55d 100644 (file)
 #include "process_key_lock.h"
 
 #define BV_64(shift) (((uint64_t)1) << (shift))
-#define GET_KEY_ARRAY(code) (((code) < 0x40) ? key_state[0] : \
-                             ((code) < 0x80) ? key_state[1] : \
-                             ((code) < 0xC0) ? key_state[2] : key_state[3])
-#define GET_CODE_INDEX(code) (((code) < 0x40) ? (code) : \
-                              ((code) < 0x80) ? (code) - 0x40 : \
-                              ((code) < 0xC0) ? (code) - 0x80 : (code) - 0xC0)
-#define KEY_STATE(code)  (GET_KEY_ARRAY(code) & BV_64(GET_CODE_INDEX(code))) == BV_64(GET_CODE_INDEX(code))
-#define SET_KEY_ARRAY_STATE(code, val) do { \
-    switch (code) { \
-        case 0x00 ... 0x3F: \
-            key_state[0] = (val); \
-            break; \
-        case 0x40 ... 0x7F: \
-            key_state[1] = (val); \
-            break; \
-        case 0x80 ... 0xBF: \
-            key_state[2] = (val); \
-            break; \
-        case 0xC0 ... 0xFF: \
-            key_state[3] = (val); \
-            break; \
-    } \
-} while(0)
+#define GET_KEY_ARRAY(code) (((code) < 0x40) ? key_state[0] : ((code) < 0x80) ? key_state[1] : ((code) < 0xC0) ? key_state[2] : key_state[3])
+#define GET_CODE_INDEX(code) (((code) < 0x40) ? (code) : ((code) < 0x80) ? (code)-0x40 : ((code) < 0xC0) ? (code)-0x80 : (code)-0xC0)
+#define KEY_STATE(code) (GET_KEY_ARRAY(code) & BV_64(GET_CODE_INDEX(code))) == BV_64(GET_CODE_INDEX(code))
+#define SET_KEY_ARRAY_STATE(code, val) \
+    do {                               \
+        switch (code) {                \
+            case 0x00 ... 0x3F:        \
+                key_state[0] = (val);  \
+                break;                 \
+            case 0x40 ... 0x7F:        \
+                key_state[1] = (val);  \
+                break;                 \
+            case 0x80 ... 0xBF:        \
+                key_state[2] = (val);  \
+                break;                 \
+            case 0xC0 ... 0xFF:        \
+                key_state[3] = (val);  \
+                break;                 \
+        }                              \
+    } while (0)
 #define SET_KEY_STATE(code) SET_KEY_ARRAY_STATE(code, (GET_KEY_ARRAY(code) | BV_64(GET_CODE_INDEX(code))))
 #define UNSET_KEY_STATE(code) SET_KEY_ARRAY_STATE(code, (GET_KEY_ARRAY(code)) & ~(BV_64(GET_CODE_INDEX(code))))
 #define IS_STANDARD_KEYCODE(code) ((code) <= 0xFF)
 
 // Locked key state. This is an array of 256 bits, one for each of the standard keys supported qmk.
-uint64_t key_state[4] = { 0x0, 0x0, 0x0, 0x0 };
-bool watching = false;
+uint64_t key_state[4] = {0x0, 0x0, 0x0, 0x0};
+bool     watching     = false;
 
 // Translate any OSM keycodes back to their unmasked versions.
 static inline uint16_t translate_keycode(uint16_t keycode) {
@@ -135,4 +132,3 @@ bool process_key_lock(uint16_t *keycode, keyrecord_t *record) {
         return !(IS_STANDARD_KEYCODE(translated_keycode) && KEY_STATE(translated_keycode));
     }
 }
-
index 876db4a324c440f3dca4658091ec7738f047ab4f..a8e110a4bf93d408e74ac318d6a71cc6a15ed790 100644 (file)
@@ -21,4 +21,4 @@
 
 bool process_key_lock(uint16_t *keycode, keyrecord_t *record);
 
-#endif // PROCESS_KEY_LOCK_H
+#endif  // PROCESS_KEY_LOCK_H
index f787e6b017a7a809a72b34918db25c7cf94680fe..58a615d85a593053f378c866712c547d6dfdb8fd 100644 (file)
 
 #ifdef LEADER_ENABLE
 
-#include "process_leader.h"
-#include <string.h>
+#    include "process_leader.h"
+#    include <string.h>
 
-#ifndef LEADER_TIMEOUT
-  #define LEADER_TIMEOUT 300
-#endif
+#    ifndef LEADER_TIMEOUT
+#        define LEADER_TIMEOUT 300
+#    endif
 
-__attribute__ ((weak))
-void leader_start(void) {}
+__attribute__((weak)) void leader_start(void) {}
 
-__attribute__ ((weak))
-void leader_end(void) {}
+__attribute__((weak)) void leader_end(void) {}
 
 // Leader key stuff
-bool leading = false;
+bool     leading     = false;
 uint16_t leader_time = 0;
 
-uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
-uint8_t leader_sequence_size = 0;
+uint16_t leader_sequence[5]   = {0, 0, 0, 0, 0};
+uint8_t  leader_sequence_size = 0;
 
 void qk_leader_start(void) {
-  if (leading) { return; }
-  leader_start();
-  leading = true;
-  leader_time = timer_read();
-  leader_sequence_size = 0;
-  memset(leader_sequence, 0, sizeof(leader_sequence));
+    if (leading) {
+        return;
+    }
+    leader_start();
+    leading              = true;
+    leader_time          = timer_read();
+    leader_sequence_size = 0;
+    memset(leader_sequence, 0, sizeof(leader_sequence));
 }
 
 bool process_leader(uint16_t keycode, keyrecord_t *record) {
-  // Leader key set-up
-  if (record->event.pressed) {
-    if (leading) {
-      if (timer_elapsed(leader_time) < LEADER_TIMEOUT) {
-#ifndef LEADER_KEY_STRICT_KEY_PROCESSING
-        if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
-          keycode = keycode & 0xFF;
-        }
-#endif // LEADER_KEY_STRICT_KEY_PROCESSING
-        if ( leader_sequence_size < ( sizeof(leader_sequence) / sizeof(leader_sequence[0]) ) ) {
-          leader_sequence[leader_sequence_size] = keycode;
-          leader_sequence_size++;
+    // Leader key set-up
+    if (record->event.pressed) {
+        if (leading) {
+            if (timer_elapsed(leader_time) < LEADER_TIMEOUT) {
+#    ifndef LEADER_KEY_STRICT_KEY_PROCESSING
+                if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
+                    keycode = keycode & 0xFF;
+                }
+#    endif  // LEADER_KEY_STRICT_KEY_PROCESSING
+                if (leader_sequence_size < (sizeof(leader_sequence) / sizeof(leader_sequence[0]))) {
+                    leader_sequence[leader_sequence_size] = keycode;
+                    leader_sequence_size++;
+                } else {
+                    leading = false;
+                    leader_end();
+                }
+#    ifdef LEADER_PER_KEY_TIMING
+                leader_time = timer_read();
+#    endif
+                return false;
+            }
         } else {
-          leading = false;
-          leader_end();
+            if (keycode == KC_LEAD) {
+                qk_leader_start();
+            }
         }
-#ifdef LEADER_PER_KEY_TIMING
-        leader_time = timer_read();
-#endif
-        return false;
-      }
-    } else {
-      if (keycode == KC_LEAD) {
-        qk_leader_start();
-      }
     }
-  }
-  return true;
+    return true;
 }
 
 #endif
index 15bccc3f670bdfcbc03d43fb2e901ccaa7578f01..e0edf57b32725a19be335fc24c3cb6676c53c777 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "quantum.h"
 
-
 bool process_leader(uint16_t keycode, keyrecord_t *record);
 
 void leader_start(void);
@@ -32,7 +31,11 @@ void qk_leader_start(void);
 #define SEQ_FOUR_KEYS(key1, key2, key3, key4) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == 0)
 #define SEQ_FIVE_KEYS(key1, key2, key3, key4, key5) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == (key5))
 
-#define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[5]; extern uint8_t leader_sequence_size
+#define LEADER_EXTERNS()                \
+    extern bool     leading;            \
+    extern uint16_t leader_time;        \
+    extern uint16_t leader_sequence[5]; \
+    extern uint8_t  leader_sequence_size
 #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT)
 
 #endif
index be6455ee944b7e10fca1eb013c84ed572aada448..b2fb902eb40ebfa293a2da143b5b77fc200c984f 100644 (file)
 #include "process_midi.h"
 
 #ifdef MIDI_ENABLE
-#include <LUFA/Drivers/USB/USB.h>
-#include "midi.h"
-#include "qmk_midi.h"
+#    include <LUFA/Drivers/USB/USB.h>
+#    include "midi.h"
+#    include "qmk_midi.h"
 
-#ifdef MIDI_BASIC
+#    ifdef MIDI_BASIC
 
-void process_midi_basic_noteon(uint8_t note)
-{
-    midi_send_noteon(&midi_device, 0, note, 127);
-}
+void process_midi_basic_noteon(uint8_t note) { midi_send_noteon(&midi_device, 0, note, 127); }
 
-void process_midi_basic_noteoff(uint8_t note)
-{
-    midi_send_noteoff(&midi_device, 0, note, 0);
-}
+void process_midi_basic_noteoff(uint8_t note) { midi_send_noteoff(&midi_device, 0, note, 0); }
 
-void process_midi_all_notes_off(void)
-{
-    midi_send_cc(&midi_device, 0, 0x7B, 0);
-}
+void process_midi_all_notes_off(void) { midi_send_cc(&midi_device, 0, 0x7B, 0); }
 
-#endif // MIDI_BASIC
+#    endif  // MIDI_BASIC
 
-#ifdef MIDI_ADVANCED
+#    ifdef MIDI_ADVANCED
 
-#include "timer.h"
+#        include "timer.h"
 
 static uint8_t tone_status[MIDI_TONE_COUNT];
 
-static uint8_t midi_modulation;
-static int8_t midi_modulation_step;
+static uint8_t  midi_modulation;
+static int8_t   midi_modulation_step;
 static uint16_t midi_modulation_timer;
-midi_config_t midi_config;
+midi_config_t   midi_config;
 
-inline uint8_t compute_velocity(uint8_t setting)
-{
-    return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1));
-}
+inline uint8_t compute_velocity(uint8_t setting) { return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); }
 
-void midi_init(void)
-{
-    midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN;
-    midi_config.transpose = 0;
-    midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN);
-    midi_config.channel = 0;
+void midi_init(void) {
+    midi_config.octave              = MI_OCT_2 - MIDI_OCTAVE_MIN;
+    midi_config.transpose           = 0;
+    midi_config.velocity            = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN);
+    midi_config.channel             = 0;
     midi_config.modulation_interval = 8;
 
-    for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++)
-    {
+    for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) {
         tone_status[i] = MIDI_INVALID_NOTE;
     }
 
-    midi_modulation = 0;
-    midi_modulation_step = 0;
+    midi_modulation       = 0;
+    midi_modulation_step  = 0;
     midi_modulation_timer = 0;
 }
 
-uint8_t midi_compute_note(uint16_t keycode)
-{
-    return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose;
-}
+uint8_t midi_compute_note(uint16_t keycode) { return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose; }
 
-bool process_midi(uint16_t keycode, keyrecord_t *record)
-{
+bool process_midi(uint16_t keycode, keyrecord_t *record) {
     switch (keycode) {
-        case MIDI_TONE_MIN ... MIDI_TONE_MAX:
-        {
-            uint8_t channel = midi_config.channel;
-            uint8_t tone = keycode - MIDI_TONE_MIN;
+        case MIDI_TONE_MIN ... MIDI_TONE_MAX: {
+            uint8_t channel  = midi_config.channel;
+            uint8_t tone     = keycode - MIDI_TONE_MIN;
             uint8_t velocity = compute_velocity(midi_config.velocity);
             if (record->event.pressed) {
                 uint8_t note = midi_compute_note(keycode);
                 midi_send_noteon(&midi_device, channel, note, velocity);
                 dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity);
                 tone_status[tone] = note;
-            }
-            else {
+            } else {
                 uint8_t note = tone_status[tone];
-                if (note != MIDI_INVALID_NOTE)
-                {
+                if (note != MIDI_INVALID_NOTE) {
                     midi_send_noteoff(&midi_device, channel, note, velocity);
                     dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity);
                 }
@@ -137,8 +116,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
             if (record->event.pressed && midi_config.transpose < (MIDI_TRANSPOSE_MAX - MI_TRNS_0)) {
                 const bool positive = midi_config.transpose > 0;
                 midi_config.transpose++;
-                if (positive && midi_config.transpose < 0)
-                    midi_config.transpose--;
+                if (positive && midi_config.transpose < 0) midi_config.transpose--;
                 dprintf("midi transpose %d\n", midi_config.transpose);
             }
             return false;
@@ -211,8 +189,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
             if (record->event.pressed) {
                 midi_config.modulation_interval++;
                 // prevent overflow
-                if (midi_config.modulation_interval == 0)
-                    midi_config.modulation_interval--;
+                if (midi_config.modulation_interval == 0) midi_config.modulation_interval--;
                 dprintf("midi modulation interval %d\n", midi_config.modulation_interval);
             }
             return false;
@@ -226,8 +203,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
             if (record->event.pressed) {
                 midi_send_pitchbend(&midi_device, midi_config.channel, -0x2000);
                 dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, -0x2000);
-            }
-            else {
+            } else {
                 midi_send_pitchbend(&midi_device, midi_config.channel, 0);
                 dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0);
             }
@@ -236,8 +212,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
             if (record->event.pressed) {
                 midi_send_pitchbend(&midi_device, midi_config.channel, 0x1fff);
                 dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0x1fff);
-            }
-            else {
+            } else {
                 midi_send_pitchbend(&midi_device, midi_config.channel, 0);
                 dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0);
             }
@@ -247,35 +222,29 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
     return true;
 }
 
-#endif // MIDI_ADVANCED
+#    endif  // MIDI_ADVANCED
 
-void midi_task(void)
-{
+void midi_task(void) {
     midi_device_process(&midi_device);
-#ifdef MIDI_ADVANCED
-    if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval)
-        return;
+#    ifdef MIDI_ADVANCED
+    if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) return;
     midi_modulation_timer = timer_read();
 
-    if (midi_modulation_step != 0)
-    {
+    if (midi_modulation_step != 0) {
         dprintf("midi modulation %d\n", midi_modulation);
         midi_send_cc(&midi_device, midi_config.channel, 0x1, midi_modulation);
 
         if (midi_modulation_step < 0 && midi_modulation < -midi_modulation_step) {
-            midi_modulation = 0;
+            midi_modulation      = 0;
             midi_modulation_step = 0;
             return;
         }
 
         midi_modulation += midi_modulation_step;
 
-        if (midi_modulation > 127)
-            midi_modulation = 127;
+        if (midi_modulation > 127) midi_modulation = 127;
     }
-#endif
+#    endif
 }
 
-
-
-#endif // MIDI_ENABLE
+#endif  // MIDI_ENABLE
index 1968fbe3fa9b9d847f207a6211af359690eb4cf1..0007b3ed255ae413448c4747f962fd08a1c1efba 100644 (file)
 
 #ifdef MIDI_ENABLE
 
-#ifdef MIDI_BASIC
+#    ifdef MIDI_BASIC
 void process_midi_basic_noteon(uint8_t note);
 void process_midi_basic_noteoff(uint8_t note);
 void process_midi_all_notes_off(void);
-#endif
+#    endif
 
 void midi_task(void);
 
-#ifdef MIDI_ADVANCED
+#    ifdef MIDI_ADVANCED
 typedef union {
-  uint32_t raw;
-  struct {
-    uint8_t octave              :4;
-    int8_t transpose            :4;
-    uint8_t velocity            :4;
-    uint8_t channel             :4;
-    uint8_t modulation_interval :4;
-  };
+    uint32_t raw;
+    struct {
+        uint8_t octave : 4;
+        int8_t  transpose : 4;
+        uint8_t velocity : 4;
+        uint8_t channel : 4;
+        uint8_t modulation_interval : 4;
+    };
 } midi_config_t;
 
 extern midi_config_t midi_config;
@@ -46,12 +46,12 @@ extern midi_config_t midi_config;
 void midi_init(void);
 bool process_midi(uint16_t keycode, keyrecord_t *record);
 
-#define MIDI_INVALID_NOTE 0xFF
-#define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1)
+#        define MIDI_INVALID_NOTE 0xFF
+#        define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1)
 
 uint8_t midi_compute_note(uint16_t keycode);
-#endif // MIDI_ADVANCED
+#    endif  // MIDI_ADVANCED
 
-#endif // MIDI_ENABLE
+#endif  // MIDI_ENABLE
 
 #endif
index 697aa237facdb8dd383a396966d82706b2efffa3..b61a16e8785fdb02f618c5588951d3eea7c9640f 100644 (file)
 #include "process_music.h"
 
 #ifdef AUDIO_ENABLE
-#include "process_audio.h"
+#    include "process_audio.h"
 #endif
 #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
-#include "process_midi.h"
+#    include "process_midi.h"
 #endif
 
 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
 
-bool music_activated = false;
-bool midi_activated = false;
+bool    music_activated     = false;
+bool    midi_activated      = false;
 uint8_t music_starting_note = 0x0C;
-int music_offset = 7;
-uint8_t music_mode = MUSIC_MODE_MAJOR;
+int     music_offset        = 7;
+uint8_t music_mode          = MUSIC_MODE_MAJOR;
 
 // music sequencer
-static bool music_sequence_recording = false;
-static bool music_sequence_recorded = false;
-static bool music_sequence_playing = false;
-static uint8_t music_sequence[16] = {0};
-static uint8_t music_sequence_count = 0;
-static uint8_t music_sequence_position = 0;
-
-static uint16_t music_sequence_timer = 0;
+static bool    music_sequence_recording = false;
+static bool    music_sequence_recorded  = false;
+static bool    music_sequence_playing   = false;
+static uint8_t music_sequence[16]       = {0};
+static uint8_t music_sequence_count     = 0;
+static uint8_t music_sequence_position  = 0;
+
+static uint16_t music_sequence_timer    = 0;
 static uint16_t music_sequence_interval = 100;
 
-#ifdef AUDIO_ENABLE
-  #ifndef MUSIC_ON_SONG
-    #define MUSIC_ON_SONG SONG(MUSIC_ON_SOUND)
-  #endif
-  #ifndef MUSIC_OFF_SONG
-    #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND)
-  #endif
-  #ifndef MIDI_ON_SONG
-    #define MIDI_ON_SONG SONG(MUSIC_ON_SOUND)
-  #endif
-  #ifndef MIDI_OFF_SONG
-    #define MIDI_OFF_SONG SONG(MUSIC_OFF_SOUND)
-  #endif
-  #ifndef CHROMATIC_SONG
-    #define CHROMATIC_SONG SONG(CHROMATIC_SOUND)
-  #endif
-  #ifndef GUITAR_SONG
-    #define GUITAR_SONG SONG(GUITAR_SOUND)
-  #endif
-  #ifndef VIOLIN_SONG
-    #define VIOLIN_SONG SONG(VIOLIN_SOUND)
-  #endif
-  #ifndef MAJOR_SONG
-    #define MAJOR_SONG SONG(MAJOR_SOUND)
-  #endif
-  float music_mode_songs[NUMBER_OF_MODES][5][2] = {
-    CHROMATIC_SONG,
-    GUITAR_SONG,
-    VIOLIN_SONG,
-    MAJOR_SONG
-  };
-  float music_on_song[][2] = MUSIC_ON_SONG;
-  float music_off_song[][2] = MUSIC_OFF_SONG;
-  float midi_on_song[][2] = MIDI_ON_SONG;
-  float midi_off_song[][2] = MIDI_OFF_SONG;
-#endif
+#    ifdef AUDIO_ENABLE
+#        ifndef MUSIC_ON_SONG
+#            define MUSIC_ON_SONG SONG(MUSIC_ON_SOUND)
+#        endif
+#        ifndef MUSIC_OFF_SONG
+#            define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND)
+#        endif
+#        ifndef MIDI_ON_SONG
+#            define MIDI_ON_SONG SONG(MUSIC_ON_SOUND)
+#        endif
+#        ifndef MIDI_OFF_SONG
+#            define MIDI_OFF_SONG SONG(MUSIC_OFF_SOUND)
+#        endif
+#        ifndef CHROMATIC_SONG
+#            define CHROMATIC_SONG SONG(CHROMATIC_SOUND)
+#        endif
+#        ifndef GUITAR_SONG
+#            define GUITAR_SONG SONG(GUITAR_SOUND)
+#        endif
+#        ifndef VIOLIN_SONG
+#            define VIOLIN_SONG SONG(VIOLIN_SOUND)
+#        endif
+#        ifndef MAJOR_SONG
+#            define MAJOR_SONG SONG(MAJOR_SOUND)
+#        endif
+float music_mode_songs[NUMBER_OF_MODES][5][2] = {CHROMATIC_SONG, GUITAR_SONG, VIOLIN_SONG, MAJOR_SONG};
+float music_on_song[][2]                      = MUSIC_ON_SONG;
+float music_off_song[][2]                     = MUSIC_OFF_SONG;
+float midi_on_song[][2]                       = MIDI_ON_SONG;
+float midi_off_song[][2]                      = MIDI_OFF_SONG;
+#    endif
 
 static void music_noteon(uint8_t note) {
-    #ifdef AUDIO_ENABLE
-    if (music_activated)
-      process_audio_noteon(note);
-    #endif
-    #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
-    if (midi_activated)
-      process_midi_basic_noteon(note);
-    #endif
+#    ifdef AUDIO_ENABLE
+    if (music_activated) process_audio_noteon(note);
+#    endif
+#    if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
+    if (midi_activated) process_midi_basic_noteon(note);
+#    endif
 }
 
 static void music_noteoff(uint8_t note) {
-    #ifdef AUDIO_ENABLE
-    if (music_activated)
-      process_audio_noteoff(note);
-    #endif
-    #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
-    if (midi_activated)
-      process_midi_basic_noteoff(note);
-    #endif
+#    ifdef AUDIO_ENABLE
+    if (music_activated) process_audio_noteoff(note);
+#    endif
+#    if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
+    if (midi_activated) process_midi_basic_noteoff(note);
+#    endif
 }
 
 void music_all_notes_off(void) {
-    #ifdef AUDIO_ENABLE
-    if (music_activated)
-      process_audio_all_notes_off();
-    #endif
-    #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
-    if (midi_activated)
-      process_midi_all_notes_off();
-    #endif
+#    ifdef AUDIO_ENABLE
+    if (music_activated) process_audio_all_notes_off();
+#    endif
+#    if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
+    if (midi_activated) process_midi_all_notes_off();
+#    endif
 }
 
 bool process_music(uint16_t keycode, keyrecord_t *record) {
-
     if (keycode == MU_ON && record->event.pressed) {
         music_on();
         return false;
@@ -152,110 +140,101 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
     }
 
     if (keycode == MU_MOD && record->event.pressed) {
-      music_mode_cycle();
-      return false;
+        music_mode_cycle();
+        return false;
     }
 
     if (music_activated || midi_activated) {
-      if (record->event.pressed) {
-        if (keycode == KC_LCTL) { // Start recording
-          music_all_notes_off();
-          music_sequence_recording = true;
-          music_sequence_recorded = false;
-          music_sequence_playing = false;
-          music_sequence_count = 0;
-          return false;
-        }
-
-        if (keycode == KC_LALT) { // Stop recording/playing
-          music_all_notes_off();
-          if (music_sequence_recording) { // was recording
-            music_sequence_recorded = true;
-          }
-          music_sequence_recording = false;
-          music_sequence_playing = false;
-          return false;
-        }
-
-        if (keycode == KC_LGUI && music_sequence_recorded) { // Start playing
-          music_all_notes_off();
-          music_sequence_recording = false;
-          music_sequence_playing = true;
-          music_sequence_position = 0;
-          music_sequence_timer = 0;
-          return false;
-        }
-
-        if (keycode == KC_UP) {
-          music_sequence_interval-=10;
-          return false;
+        if (record->event.pressed) {
+            if (keycode == KC_LCTL) {  // Start recording
+                music_all_notes_off();
+                music_sequence_recording = true;
+                music_sequence_recorded  = false;
+                music_sequence_playing   = false;
+                music_sequence_count     = 0;
+                return false;
+            }
+
+            if (keycode == KC_LALT) {  // Stop recording/playing
+                music_all_notes_off();
+                if (music_sequence_recording) {  // was recording
+                    music_sequence_recorded = true;
+                }
+                music_sequence_recording = false;
+                music_sequence_playing   = false;
+                return false;
+            }
+
+            if (keycode == KC_LGUI && music_sequence_recorded) {  // Start playing
+                music_all_notes_off();
+                music_sequence_recording = false;
+                music_sequence_playing   = true;
+                music_sequence_position  = 0;
+                music_sequence_timer     = 0;
+                return false;
+            }
+
+            if (keycode == KC_UP) {
+                music_sequence_interval -= 10;
+                return false;
+            }
+
+            if (keycode == KC_DOWN) {
+                music_sequence_interval += 10;
+                return false;
+            }
         }
 
-        if (keycode == KC_DOWN) {
-          music_sequence_interval+=10;
-          return false;
-        }
-      }
-
-      uint8_t note = 36;
-      #ifdef MUSIC_MAP
+        uint8_t note = 36;
+#    ifdef MUSIC_MAP
         if (music_mode == MUSIC_MODE_CHROMATIC) {
-          note = music_starting_note + music_offset + 36 + music_map[record->event.key.row][record->event.key.col];
+            note = music_starting_note + music_offset + 36 + music_map[record->event.key.row][record->event.key.col];
         } else {
-          uint8_t position = music_map[record->event.key.row][record->event.key.col];
-          note = music_starting_note + music_offset + 36 + SCALE[position % 12] + (position / 12)*12;
+            uint8_t position = music_map[record->event.key.row][record->event.key.col];
+            note             = music_starting_note + music_offset + 36 + SCALE[position % 12] + (position / 12) * 12;
         }
-      #else
+#    else
         if (music_mode == MUSIC_MODE_CHROMATIC)
-          note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row);
+            note = (music_starting_note + record->event.key.col + music_offset - 3) + 12 * (MATRIX_ROWS - record->event.key.row);
         else if (music_mode == MUSIC_MODE_GUITAR)
-          note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row);
+            note = (music_starting_note + record->event.key.col + music_offset + 32) + 5 * (MATRIX_ROWS - record->event.key.row);
         else if (music_mode == MUSIC_MODE_VIOLIN)
-          note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row);
+            note = (music_starting_note + record->event.key.col + music_offset + 32) + 7 * (MATRIX_ROWS - record->event.key.row);
         else if (music_mode == MUSIC_MODE_MAJOR)
-          note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row);
+            note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3) + 12 * (MATRIX_ROWS - record->event.key.row);
         else
-          note = music_starting_note;
-      #endif
-
-      if (record->event.pressed) {
-        music_noteon(note);
-        if (music_sequence_recording) {
-          music_sequence[music_sequence_count] = note;
-          music_sequence_count++;
+            note = music_starting_note;
+#    endif
+
+        if (record->event.pressed) {
+            music_noteon(note);
+            if (music_sequence_recording) {
+                music_sequence[music_sequence_count] = note;
+                music_sequence_count++;
+            }
+        } else {
+            music_noteoff(note);
         }
-      } else {
-        music_noteoff(note);
-      }
 
-      if (music_mask(keycode))
-        return false;
+        if (music_mask(keycode)) return false;
     }
 
     return true;
 }
 
 bool music_mask(uint16_t keycode) {
-  #ifdef MUSIC_MASK
+#    ifdef MUSIC_MASK
     return MUSIC_MASK;
-  #else
+#    else
     return music_mask_kb(keycode);
-  #endif
+#    endif
 }
 
-__attribute__((weak))
-bool music_mask_kb(uint16_t keycode) {
-  return music_mask_user(keycode);
-}
+__attribute__((weak)) bool music_mask_kb(uint16_t keycode) { return music_mask_user(keycode); }
 
-__attribute__((weak))
-bool music_mask_user(uint16_t keycode) {
-  return keycode < 0xFF;
-}
+__attribute__((weak)) bool music_mask_user(uint16_t keycode) { return keycode < 0xFF; }
 
-bool is_music_on(void) {
-    return (music_activated != 0);
-}
+bool is_music_on(void) { return (music_activated != 0); }
 
 void music_toggle(void) {
     if (!music_activated) {
@@ -267,23 +246,21 @@ void music_toggle(void) {
 
 void music_on(void) {
     music_activated = 1;
-    #ifdef AUDIO_ENABLE
-      PLAY_SONG(music_on_song);
-    #endif
+#    ifdef AUDIO_ENABLE
+    PLAY_SONG(music_on_song);
+#    endif
     music_on_user();
 }
 
 void music_off(void) {
     music_all_notes_off();
     music_activated = 0;
-    #ifdef AUDIO_ENABLE
-      PLAY_SONG(music_off_song);
-    #endif
+#    ifdef AUDIO_ENABLE
+    PLAY_SONG(music_off_song);
+#    endif
 }
 
-bool is_midi_on(void) {
-    return (midi_activated != 0);
-}
+bool is_midi_on(void) { return (midi_activated != 0); }
 
 void midi_toggle(void) {
     if (!midi_activated) {
@@ -295,50 +272,47 @@ void midi_toggle(void) {
 
 void midi_on(void) {
     midi_activated = 1;
-    #ifdef AUDIO_ENABLE
-      PLAY_SONG(midi_on_song);
-    #endif
+#    ifdef AUDIO_ENABLE
+    PLAY_SONG(midi_on_song);
+#    endif
     midi_on_user();
 }
 
 void midi_off(void) {
-    #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
-      process_midi_all_notes_off();
-    #endif
+#    if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
+    process_midi_all_notes_off();
+#    endif
     midi_activated = 0;
-    #ifdef AUDIO_ENABLE
-      PLAY_SONG(midi_off_song);
-    #endif
+#    ifdef AUDIO_ENABLE
+    PLAY_SONG(midi_off_song);
+#    endif
 }
 
 void music_mode_cycle(void) {
-  music_all_notes_off();
-  music_mode = (music_mode + 1) % NUMBER_OF_MODES;
-  #ifdef AUDIO_ENABLE
+    music_all_notes_off();
+    music_mode = (music_mode + 1) % NUMBER_OF_MODES;
+#    ifdef AUDIO_ENABLE
     PLAY_SONG(music_mode_songs[music_mode]);
-  #endif
+#    endif
 }
 
 void matrix_scan_music(void) {
-  if (music_sequence_playing) {
-    if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
-      music_sequence_timer = timer_read();
-      uint8_t prev_note = music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)];
-      uint8_t next_note = music_sequence[music_sequence_position];
-      music_noteoff(prev_note);
-      music_noteon(next_note);
-      music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
+    if (music_sequence_playing) {
+        if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
+            music_sequence_timer = timer_read();
+            uint8_t prev_note    = music_sequence[(music_sequence_position - 1 < 0) ? (music_sequence_position - 1 + music_sequence_count) : (music_sequence_position - 1)];
+            uint8_t next_note    = music_sequence[music_sequence_position];
+            music_noteoff(prev_note);
+            music_noteon(next_note);
+            music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
+        }
     }
-  }
 }
 
-__attribute__ ((weak))
-void music_on_user() {}
+__attribute__((weak)) void music_on_user() {}
 
-__attribute__ ((weak))
-void midi_on_user() {}
+__attribute__((weak)) void midi_on_user() {}
 
-__attribute__ ((weak))
-void music_scale_user() {}
+__attribute__((weak)) void music_scale_user() {}
 
-#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
+#endif  // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
index f6753d4f24dcf520432e1ec0d15103bc69188e28..292bc537424be9a1a636f7c22360ba2ce4745fb1 100644 (file)
 
 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
 
-enum music_modes {
-  MUSIC_MODE_CHROMATIC,
-  MUSIC_MODE_GUITAR,
-  MUSIC_MODE_VIOLIN,
-  MUSIC_MODE_MAJOR,
-  NUMBER_OF_MODES
-};
+enum music_modes { MUSIC_MODE_CHROMATIC, MUSIC_MODE_GUITAR, MUSIC_MODE_VIOLIN, MUSIC_MODE_MAJOR, NUMBER_OF_MODES };
 
-
-#ifdef MUSIC_MAP
-       extern const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS];
-#endif
+#    ifdef MUSIC_MAP
+extern const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS];
+#    endif
 
 bool process_music(uint16_t keycode, keyrecord_t *record);
 
@@ -58,14 +51,11 @@ bool music_mask(uint16_t keycode);
 bool music_mask_kb(uint16_t keycode);
 bool music_mask_user(uint16_t keycode);
 
-#ifndef SCALE
-#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
-                           0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
-                           0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
-                           0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
-                           0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
-#endif
+#    ifndef SCALE
+#        define SCALE \
+            (int8_t[]) { 0 + (12 * 0), 2 + (12 * 0), 4 + (12 * 0), 5 + (12 * 0), 7 + (12 * 0), 9 + (12 * 0), 11 + (12 * 0), 0 + (12 * 1), 2 + (12 * 1), 4 + (12 * 1), 5 + (12 * 1), 7 + (12 * 1), 9 + (12 * 1), 11 + (12 * 1), 0 + (12 * 2), 2 + (12 * 2), 4 + (12 * 2), 5 + (12 * 2), 7 + (12 * 2), 9 + (12 * 2), 11 + (12 * 2), 0 + (12 * 3), 2 + (12 * 3), 4 + (12 * 3), 5 + (12 * 3), 7 + (12 * 3), 9 + (12 * 3), 11 + (12 * 3), 0 + (12 * 4), 2 + (12 * 4), 4 + (12 * 4), 5 + (12 * 4), 7 + (12 * 4), 9 + (12 * 4), 11 + (12 * 4), }
+#    endif
 
-#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
+#endif  // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
 
 #endif
index 613af70183b9cd677bff8ed102d97f499dd052e2..7c5e4169a6044a097917d42d5b64464739070157 100644 (file)
 #include "process_printer.h"
 #include "action_util.h"
 
-bool printing_enabled = false;
-uint8_t character_shift = 0;
+bool    printing_enabled = false;
+uint8_t character_shift  = 0;
 
 void enable_printing(void) {
-       printing_enabled = true;
-       serial_init();
+    printing_enabled = true;
+    serial_init();
 }
 
-void disable_printing(void) {
-       printing_enabled = false;
-}
+void disable_printing(void) { printing_enabled = false; }
 
 uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29};
 
@@ -36,235 +34,232 @@ uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0
 // keycode_to_ascii[KC_MINS] = {0x2D, 0x5F};
 
 void print_char(char c) {
-       USB_Disable();
-       serial_send(c);
-       USB_Init();
+    USB_Disable();
+    serial_send(c);
+    USB_Init();
 }
 
 void print_string(char c[]) {
-       for(uint8_t i = 0; i < strlen(c); i++)
-               print_char(c[i]);
+    for (uint8_t i = 0; i < strlen(c); i++) print_char(c[i]);
 }
 
 void print_box_string(const char text[]) {
-       size_t len = strlen(text);
-       char out[len * 3 + 8];
-       out[0] = 0xDA;
-       for (uint8_t i = 0; i < len; i++) {
-               out[i+1] = 0xC4;
-       }
-       out[len + 1] = 0xBF;
-       out[len + 2] = '\n';
-
-       out[len + 3] = 0xB3;
-       for (uint8_t i = 0; i < len; i++) {
-               out[len + 4 + i] = text[i];
-       }
-       out[len * 2 + 4] = 0xB3;
-       out[len * 2 + 5] = '\n';
+    size_t len = strlen(text);
+    char   out[len * 3 + 8];
+    out[0] = 0xDA;
+    for (uint8_t i = 0; i < len; i++) {
+        out[i + 1] = 0xC4;
+    }
+    out[len + 1] = 0xBF;
+    out[len + 2] = '\n';
 
+    out[len + 3] = 0xB3;
+    for (uint8_t i = 0; i < len; i++) {
+        out[len + 4 + i] = text[i];
+    }
+    out[len * 2 + 4] = 0xB3;
+    out[len * 2 + 5] = '\n';
 
-       out[len * 2 + 6] = 0xC0;
-       for (uint8_t i = 0; i < len; i++) {
-               out[len * 2 + 7 + i] = 0xC4;
-       }
-       out[len * 3 + 7] = 0xD9;
-       out[len * 3 + 8] = '\n';
+    out[len * 2 + 6] = 0xC0;
+    for (uint8_t i = 0; i < len; i++) {
+        out[len * 2 + 7 + i] = 0xC4;
+    }
+    out[len * 3 + 7] = 0xD9;
+    out[len * 3 + 8] = '\n';
 
-       print_string(out); 
+    print_string(out);
 }
 
 bool process_printer(uint16_t keycode, keyrecord_t *record) {
-       if (keycode == PRINT_ON) {
-               enable_printing();
-               return false;
-       }
-       if (keycode == PRINT_OFF) {
-               disable_printing();
-               return false;
-       }
-
-       if (printing_enabled) {
-               switch(keycode) {
-                       case KC_EXLM ... KC_RPRN:
-                       case KC_UNDS:
-                       case KC_PLUS:
-                       case KC_LCBR:
-                       case KC_RCBR:
-                       case KC_PIPE:
-                       case KC_TILD:
-                               keycode &= 0xFF;
-                       case KC_LSFT:
-                       case KC_RSFT:
-                               if (record->event.pressed) {
-                                       character_shift++;
-                               } else {
-                                       character_shift--;
-                               }
-                               return false;
-                       break;
-               }
+    if (keycode == PRINT_ON) {
+        enable_printing();
+        return false;
+    }
+    if (keycode == PRINT_OFF) {
+        disable_printing();
+        return false;
+    }
 
-               switch(keycode) {
-                       case KC_F1:
-                               if (record->event.pressed) {
-                                       print_box_string("This is a line of text!");
-                               }
-                               return false;
-                       case KC_ESC:
-                               if (record->event.pressed) {
-                                       print_char(0x1B);
-                               }
-                               return false;
-                       break;
-                       case KC_SPC:
-                               if (record->event.pressed) {
-                                       print_char(0x20);
-                               }
-                               return false;
-                       break;
-                       case KC_A ... KC_Z:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x41 + (keycode - KC_A));
-                                       } else {
-                                               print_char(0x61 + (keycode - KC_A));
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_1 ... KC_0:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                                       print_char(shifted_numbers[keycode - KC_1]);
-                                       } else {
-                                                       print_char(0x30 + ((keycode - KC_1 + 1) % 10));
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_ENT:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x0C);
-                                       } else {
-                                               print_char(0x0A);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_BSPC:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x18);
-                                       } else {
-                                               print_char(0x1A);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_DOT:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x3E);
-                                       } else {
-                                               print_char(0x2E);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_COMM:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x3C);
-                                       } else {
-                                               print_char(0x2C);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_SLSH:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x3F);
-                                       } else {
-                                               print_char(0x2F);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_QUOT:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x22);
-                                       } else {
-                                               print_char(0x27);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_GRV:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x7E);
-                                       } else {
-                                               print_char(0x60);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_MINS:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x5F);
-                                       } else {
-                                               print_char(0x2D);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_EQL:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x2B);
-                                       } else {
-                                               print_char(0x3D);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_LBRC:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x7B);
-                                       } else {
-                                               print_char(0x5B);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_RBRC:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x7D);
-                                       } else {
-                                               print_char(0x5D);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_BSLS:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x7C);
-                                       } else {
-                                               print_char(0x5C);
-                                       }
-                               }
-                               return false;
-                       break;
-               }
-       }
-       return true;
+    if (printing_enabled) {
+        switch (keycode) {
+            case KC_EXLM ... KC_RPRN:
+            case KC_UNDS:
+            case KC_PLUS:
+            case KC_LCBR:
+            case KC_RCBR:
+            case KC_PIPE:
+            case KC_TILD:
+                keycode &= 0xFF;
+            case KC_LSFT:
+            case KC_RSFT:
+                if (record->event.pressed) {
+                    character_shift++;
+                } else {
+                    character_shift--;
+                }
+                return false;
+                break;
+        }
 
+        switch (keycode) {
+            case KC_F1:
+                if (record->event.pressed) {
+                    print_box_string("This is a line of text!");
+                }
+                return false;
+            case KC_ESC:
+                if (record->event.pressed) {
+                    print_char(0x1B);
+                }
+                return false;
+                break;
+            case KC_SPC:
+                if (record->event.pressed) {
+                    print_char(0x20);
+                }
+                return false;
+                break;
+            case KC_A ... KC_Z:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x41 + (keycode - KC_A));
+                    } else {
+                        print_char(0x61 + (keycode - KC_A));
+                    }
+                }
+                return false;
+                break;
+            case KC_1 ... KC_0:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(shifted_numbers[keycode - KC_1]);
+                    } else {
+                        print_char(0x30 + ((keycode - KC_1 + 1) % 10));
+                    }
+                }
+                return false;
+                break;
+            case KC_ENT:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x0C);
+                    } else {
+                        print_char(0x0A);
+                    }
+                }
+                return false;
+                break;
+            case KC_BSPC:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x18);
+                    } else {
+                        print_char(0x1A);
+                    }
+                }
+                return false;
+                break;
+            case KC_DOT:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x3E);
+                    } else {
+                        print_char(0x2E);
+                    }
+                }
+                return false;
+                break;
+            case KC_COMM:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x3C);
+                    } else {
+                        print_char(0x2C);
+                    }
+                }
+                return false;
+                break;
+            case KC_SLSH:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x3F);
+                    } else {
+                        print_char(0x2F);
+                    }
+                }
+                return false;
+                break;
+            case KC_QUOT:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x22);
+                    } else {
+                        print_char(0x27);
+                    }
+                }
+                return false;
+                break;
+            case KC_GRV:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x7E);
+                    } else {
+                        print_char(0x60);
+                    }
+                }
+                return false;
+                break;
+            case KC_MINS:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x5F);
+                    } else {
+                        print_char(0x2D);
+                    }
+                }
+                return false;
+                break;
+            case KC_EQL:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x2B);
+                    } else {
+                        print_char(0x3D);
+                    }
+                }
+                return false;
+                break;
+            case KC_LBRC:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x7B);
+                    } else {
+                        print_char(0x5B);
+                    }
+                }
+                return false;
+                break;
+            case KC_RBRC:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x7D);
+                    } else {
+                        print_char(0x5D);
+                    }
+                }
+                return false;
+                break;
+            case KC_BSLS:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x7C);
+                    } else {
+                        print_char(0x5C);
+                    }
+                }
+                return false;
+                break;
+        }
+    }
+    return true;
 }
index 3a00f169d8b4d656b0f24ce626cdfce9ea047e4e..e482d82591aa1d885d2beca6a5af0fcffd1ab090 100644 (file)
 #include "process_printer.h"
 #include "action_util.h"
 
-bool printing_enabled = false;
-uint8_t character_shift = 0;
+bool    printing_enabled = false;
+uint8_t character_shift  = 0;
 
 #define SERIAL_PIN_DDR DDRD
 #define SERIAL_PIN_PORT PORTD
 #define SERIAL_PIN_MASK _BV(PD3)
 #define SERIAL_DELAY 52
 
-inline static
-void serial_delay(void) {
-  _delay_us(SERIAL_DELAY);
-}
+inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); }
 
-inline static
-void serial_high(void) {
-  SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
-}
+inline static void serial_high(void) { SERIAL_PIN_PORT |= SERIAL_PIN_MASK; }
 
-inline static
-void serial_low(void) {
-  SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
-}
-
-inline static
-void serial_output(void) {
-  SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
-}
+inline static void serial_low(void) { SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; }
 
+inline static void serial_output(void) { SERIAL_PIN_DDR |= SERIAL_PIN_MASK; }
 
 void enable_printing() {
-       printing_enabled = true;
-       serial_output();
-       serial_high();
+    printing_enabled = true;
+    serial_output();
+    serial_high();
 }
 
-void disable_printing() {
-       printing_enabled = false;
-}
+void disable_printing() { printing_enabled = false; }
 
 uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29};
 
@@ -63,214 +48,212 @@ uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0
 // keycode_to_ascii[KC_MINS] = {0x2D, 0x5F};
 
 void print_char(char c) {
-  uint8_t b = 8;
-  serial_output();
-  while( b-- ) {
-    if(c & (1 << b)) {
-      serial_high();
-    } else {
-      serial_low();
+    uint8_t b = 8;
+    serial_output();
+    while (b--) {
+        if (c & (1 << b)) {
+            serial_high();
+        } else {
+            serial_low();
+        }
+        serial_delay();
     }
-    serial_delay();
-  }
 }
 
 void print_string(char c[]) {
-       for(uint8_t i = 0; i < strlen(c); i++)
-               print_char(c[i]);
+    for (uint8_t i = 0; i < strlen(c); i++) print_char(c[i]);
 }
 
 bool process_printer(uint16_t keycode, keyrecord_t *record) {
-       if (keycode == PRINT_ON) {
-               enable_printing();
-               return false;
-       }
-       if (keycode == PRINT_OFF) {
-               disable_printing();
-               return false;
-       }
-
-       if (printing_enabled) {
-               switch(keycode) {
-                       case KC_EXLM ... KC_RPRN:
-                       case KC_UNDS:
-                       case KC_PLUS:
-                       case KC_LCBR:
-                       case KC_RCBR:
-                       case KC_PIPE:
-                       case KC_TILD:
-                               keycode &= 0xFF;
-                       case KC_LSFT:
-                       case KC_RSFT:
-                               if (record->event.pressed) {
-                                       character_shift++;
-                               } else {
-                                       character_shift--;
-                               }
-                               return false;
-                       break;
-               }
+    if (keycode == PRINT_ON) {
+        enable_printing();
+        return false;
+    }
+    if (keycode == PRINT_OFF) {
+        disable_printing();
+        return false;
+    }
 
-               switch(keycode) {
-                       case KC_F1:
-                               if (record->event.pressed) {
-                                       print_string("This is a line of text!\n\n\n");
-                               }
-                               return false;
-                       case KC_ESC:
-                               if (record->event.pressed) {
-                                       print_char(0x1B);
-                               }
-                               return false;
-                       break;
-                       case KC_SPC:
-                               if (record->event.pressed) {
-                                       print_char(0x20);
-                               }
-                               return false;
-                       break;
-                       case KC_A ... KC_Z:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x41 + (keycode - KC_A));
-                                       } else {
-                                               print_char(0x61 + (keycode - KC_A));
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_1 ... KC_0:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                                       print_char(shifted_numbers[keycode - KC_1]);
-                                       } else {
-                                                       print_char(0x30 + ((keycode - KC_1 + 1) % 10));
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_ENT:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x0C);
-                                       } else {
-                                               print_char(0x0A);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_BSPC:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x18);
-                                       } else {
-                                               print_char(0x1A);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_DOT:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x3E);
-                                       } else {
-                                               print_char(0x2E);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_COMM:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x3C);
-                                       } else {
-                                               print_char(0x2C);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_SLSH:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x3F);
-                                       } else {
-                                               print_char(0x2F);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_QUOT:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x22);
-                                       } else {
-                                               print_char(0x27);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_GRV:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x7E);
-                                       } else {
-                                               print_char(0x60);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_MINS:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x5F);
-                                       } else {
-                                               print_char(0x2D);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_EQL:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x2B);
-                                       } else {
-                                               print_char(0x3D);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_LBRC:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x7B);
-                                       } else {
-                                               print_char(0x5B);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_RBRC:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x7D);
-                                       } else {
-                                               print_char(0x5D);
-                                       }
-                               }
-                               return false;
-                       break;
-                       case KC_BSLS:
-                               if (record->event.pressed) {
-                                       if (character_shift) {
-                                               print_char(0x7C);
-                                       } else {
-                                               print_char(0x5C);
-                                       }
-                               }
-                               return false;
-                       break;
-               }
-       }
-       return true;
+    if (printing_enabled) {
+        switch (keycode) {
+            case KC_EXLM ... KC_RPRN:
+            case KC_UNDS:
+            case KC_PLUS:
+            case KC_LCBR:
+            case KC_RCBR:
+            case KC_PIPE:
+            case KC_TILD:
+                keycode &= 0xFF;
+            case KC_LSFT:
+            case KC_RSFT:
+                if (record->event.pressed) {
+                    character_shift++;
+                } else {
+                    character_shift--;
+                }
+                return false;
+                break;
+        }
 
+        switch (keycode) {
+            case KC_F1:
+                if (record->event.pressed) {
+                    print_string("This is a line of text!\n\n\n");
+                }
+                return false;
+            case KC_ESC:
+                if (record->event.pressed) {
+                    print_char(0x1B);
+                }
+                return false;
+                break;
+            case KC_SPC:
+                if (record->event.pressed) {
+                    print_char(0x20);
+                }
+                return false;
+                break;
+            case KC_A ... KC_Z:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x41 + (keycode - KC_A));
+                    } else {
+                        print_char(0x61 + (keycode - KC_A));
+                    }
+                }
+                return false;
+                break;
+            case KC_1 ... KC_0:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(shifted_numbers[keycode - KC_1]);
+                    } else {
+                        print_char(0x30 + ((keycode - KC_1 + 1) % 10));
+                    }
+                }
+                return false;
+                break;
+            case KC_ENT:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x0C);
+                    } else {
+                        print_char(0x0A);
+                    }
+                }
+                return false;
+                break;
+            case KC_BSPC:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x18);
+                    } else {
+                        print_char(0x1A);
+                    }
+                }
+                return false;
+                break;
+            case KC_DOT:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x3E);
+                    } else {
+                        print_char(0x2E);
+                    }
+                }
+                return false;
+                break;
+            case KC_COMM:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x3C);
+                    } else {
+                        print_char(0x2C);
+                    }
+                }
+                return false;
+                break;
+            case KC_SLSH:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x3F);
+                    } else {
+                        print_char(0x2F);
+                    }
+                }
+                return false;
+                break;
+            case KC_QUOT:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x22);
+                    } else {
+                        print_char(0x27);
+                    }
+                }
+                return false;
+                break;
+            case KC_GRV:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x7E);
+                    } else {
+                        print_char(0x60);
+                    }
+                }
+                return false;
+                break;
+            case KC_MINS:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x5F);
+                    } else {
+                        print_char(0x2D);
+                    }
+                }
+                return false;
+                break;
+            case KC_EQL:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x2B);
+                    } else {
+                        print_char(0x3D);
+                    }
+                }
+                return false;
+                break;
+            case KC_LBRC:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x7B);
+                    } else {
+                        print_char(0x5B);
+                    }
+                }
+                return false;
+                break;
+            case KC_RBRC:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x7D);
+                    } else {
+                        print_char(0x5D);
+                    }
+                }
+                return false;
+                break;
+            case KC_BSLS:
+                if (record->event.pressed) {
+                    if (character_shift) {
+                        print_char(0x7C);
+                    } else {
+                        print_char(0x5C);
+                    }
+                }
+                return false;
+                break;
+        }
+    }
+    return true;
 }
index c8721d446ca256d703b81709c6b1d48dfd3d1895..6833fdb9fb38ddd1e2a70f2835bdac4dfef75fe8 100644 (file)
 #include "process_space_cadet.h"
 
 #ifndef TAPPING_TERM
-  #define TAPPING_TERM 200
+#    define TAPPING_TERM 200
 #endif
 
 // ********** OBSOLETE DEFINES, STOP USING! (pls?) **********
 // Shift / paren setup
 #ifndef LSPO_KEY
-  #define LSPO_KEY KC_9
+#    define LSPO_KEY KC_9
 #endif
 #ifndef RSPC_KEY
-  #define RSPC_KEY KC_0
+#    define RSPC_KEY KC_0
 #endif
 
 // Shift / Enter setup
 #ifndef SFTENT_KEY
-  #define SFTENT_KEY KC_ENT
+#    define SFTENT_KEY KC_ENT
 #endif
 
 #ifdef DISABLE_SPACE_CADET_MODIFIER
-  #ifndef LSPO_MOD
-    #define LSPO_MOD KC_TRNS
-  #endif
-  #ifndef RSPC_MOD
-    #define RSPC_MOD KC_TRNS
-  #endif
+#    ifndef LSPO_MOD
+#        define LSPO_MOD KC_TRNS
+#    endif
+#    ifndef RSPC_MOD
+#        define RSPC_MOD KC_TRNS
+#    endif
 #else
-  #ifndef LSPO_MOD
-    #define LSPO_MOD KC_LSFT
-  #endif
-  #ifndef RSPC_MOD
-    #define RSPC_MOD KC_RSFT
-  #endif
+#    ifndef LSPO_MOD
+#        define LSPO_MOD KC_LSFT
+#    endif
+#    ifndef RSPC_MOD
+#        define RSPC_MOD KC_RSFT
+#    endif
 #endif
 // **********************************************************
 
 // Shift / paren setup
 #ifndef LSPO_KEYS
-  #define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY
+#    define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY
 #endif
 #ifndef RSPC_KEYS
-  #define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY
+#    define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY
 #endif
 
 // Control / paren setup
 #ifndef LCPO_KEYS
-  #define LCPO_KEYS KC_LCTL, KC_LSFT, KC_9
+#    define LCPO_KEYS KC_LCTL, KC_LSFT, KC_9
 #endif
 #ifndef RCPC_KEYS
-  #define RCPC_KEYS KC_RCTL, KC_RSFT, KC_0
+#    define RCPC_KEYS KC_RCTL, KC_RSFT, KC_0
 #endif
 
 // Alt / paren setup
 #ifndef LAPO_KEYS
-  #define LAPO_KEYS KC_LALT, KC_LSFT, KC_9
+#    define LAPO_KEYS KC_LALT, KC_LSFT, KC_9
 #endif
 #ifndef RAPC_KEYS
-  #define RAPC_KEYS KC_RALT, KC_RSFT, KC_0
+#    define RAPC_KEYS KC_RALT, KC_RSFT, KC_0
 #endif
 
 // Shift / Enter setup
 #ifndef SFTENT_KEYS
-  #define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY
+#    define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY
 #endif
 
-static uint8_t sc_last = 0;
+static uint8_t  sc_last  = 0;
 static uint16_t sc_timer = 0;
 #ifdef SPACE_CADET_MODIFIER_CARRYOVER
 static uint8_t sc_mods = 0;
 #endif
 
 void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode) {
-  if (record->event.pressed) {
-    sc_last = holdMod;
-    sc_timer = timer_read ();
+    if (record->event.pressed) {
+        sc_last  = holdMod;
+        sc_timer = timer_read();
 #ifdef SPACE_CADET_MODIFIER_CARRYOVER
-    sc_mods = get_mods();
+        sc_mods = get_mods();
 #endif
-    if (IS_MOD(holdMod)) {
-      register_mods(MOD_BIT(holdMod));
-    }
-  }
-  else {
-    if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) {
-      if (holdMod != tapMod) {
         if (IS_MOD(holdMod)) {
-          unregister_mods(MOD_BIT(holdMod));
-        }
-        if (IS_MOD(tapMod)) {
-          register_mods(MOD_BIT(tapMod));
+            register_mods(MOD_BIT(holdMod));
         }
-      }
+    } else {
+        if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) {
+            if (holdMod != tapMod) {
+                if (IS_MOD(holdMod)) {
+                    unregister_mods(MOD_BIT(holdMod));
+                }
+                if (IS_MOD(tapMod)) {
+                    register_mods(MOD_BIT(tapMod));
+                }
+            }
 #ifdef SPACE_CADET_MODIFIER_CARRYOVER
-    set_weak_mods(sc_mods);
+            set_weak_mods(sc_mods);
 #endif
-      tap_code(keycode);
+            tap_code(keycode);
 #ifdef SPACE_CADET_MODIFIER_CARRYOVER
-    clear_weak_mods();
-#endif
-      if (IS_MOD(tapMod)) {
-        unregister_mods(MOD_BIT(tapMod));
-      }
-    } else {
-      if (IS_MOD(holdMod)) {
-        unregister_mods(MOD_BIT(holdMod));
-      }
+            clear_weak_mods();
+#endif
+            if (IS_MOD(tapMod)) {
+                unregister_mods(MOD_BIT(tapMod));
+            }
+        } else {
+            if (IS_MOD(holdMod)) {
+                unregister_mods(MOD_BIT(holdMod));
+            }
+        }
     }
-  }
 }
 
 bool process_space_cadet(uint16_t keycode, keyrecord_t *record) {
-  switch(keycode) {
-    case KC_LSPO: {
-      perform_space_cadet(record, LSPO_KEYS);
-      return false;
-    }
-    case KC_RSPC: {
-      perform_space_cadet(record, RSPC_KEYS);
-      return false;
-    }
-    case KC_LCPO: {
-      perform_space_cadet(record, LCPO_KEYS);
-      return false;
-    }
-    case KC_RCPC: {
-      perform_space_cadet(record, RCPC_KEYS);
-      return false;
-    }
-    case KC_LAPO: {
-      perform_space_cadet(record, LAPO_KEYS);
-      return false;
-    }
-    case KC_RAPC: {
-      perform_space_cadet(record, RAPC_KEYS);
-      return false;
-    }
-    case KC_SFTENT: {
-      perform_space_cadet(record, SFTENT_KEYS);
-      return false;
-    }
-    default: {
-      if (record->event.pressed) {
-        sc_last = 0;
-      }
-      break;
+    switch (keycode) {
+        case KC_LSPO: {
+            perform_space_cadet(record, LSPO_KEYS);
+            return false;
+        }
+        case KC_RSPC: {
+            perform_space_cadet(record, RSPC_KEYS);
+            return false;
+        }
+        case KC_LCPO: {
+            perform_space_cadet(record, LCPO_KEYS);
+            return false;
+        }
+        case KC_RCPC: {
+            perform_space_cadet(record, RCPC_KEYS);
+            return false;
+        }
+        case KC_LAPO: {
+            perform_space_cadet(record, LAPO_KEYS);
+            return false;
+        }
+        case KC_RAPC: {
+            perform_space_cadet(record, RAPC_KEYS);
+            return false;
+        }
+        case KC_SFTENT: {
+            perform_space_cadet(record, SFTENT_KEYS);
+            return false;
+        }
+        default: {
+            if (record->event.pressed) {
+                sc_last = 0;
+            }
+            break;
+        }
     }
-  }
-  return true;
+    return true;
 }
index 50a1ef2fcf99eedcdb8b2317e1b44f6e5cc3e2ce..e0b33ec861a660fb283d78ac36775a86a1c1f250 100644 (file)
 #define GEMINI_STATE_SIZE 6
 #define MAX_STATE_SIZE GEMINI_STATE_SIZE
 
-static uint8_t state[MAX_STATE_SIZE] = {0};
-static uint8_t chord[MAX_STATE_SIZE] = {0};
-static int8_t pressed = 0;
+static uint8_t      state[MAX_STATE_SIZE] = {0};
+static uint8_t      chord[MAX_STATE_SIZE] = {0};
+static int8_t       pressed               = 0;
 static steno_mode_t mode;
 
-static const uint8_t boltmap[64] PROGMEM = {
-  TXB_NUL, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM,
-  TXB_S_L, TXB_S_L, TXB_T_L, TXB_K_L, TXB_P_L, TXB_W_L, TXB_H_L,
-  TXB_R_L, TXB_A_L, TXB_O_L, TXB_STR, TXB_STR, TXB_NUL, TXB_NUL,
-  TXB_NUL, TXB_STR, TXB_STR, TXB_E_R, TXB_U_R, TXB_F_R, TXB_R_R,
-  TXB_P_R, TXB_B_R, TXB_L_R, TXB_G_R, TXB_T_R, TXB_S_R, TXB_D_R,
-  TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_Z_R
-};
+static const uint8_t boltmap[64] PROGMEM = {TXB_NUL, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_S_L, TXB_S_L, TXB_T_L, TXB_K_L, TXB_P_L, TXB_W_L, TXB_H_L, TXB_R_L, TXB_A_L, TXB_O_L, TXB_STR, TXB_STR, TXB_NUL, TXB_NUL, TXB_NUL, TXB_STR, TXB_STR, TXB_E_R, TXB_U_R, TXB_F_R, TXB_R_R, TXB_P_R, TXB_B_R, TXB_L_R, TXB_G_R, TXB_T_R, TXB_S_R, TXB_D_R, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_Z_R};
 
 static void steno_clear_state(void) {
-  memset(state, 0, sizeof(state));
-  memset(chord, 0, sizeof(chord));
+    memset(state, 0, sizeof(state));
+    memset(chord, 0, sizeof(chord));
 }
 
 static void send_steno_state(uint8_t size, bool send_empty) {
-  for (uint8_t i = 0; i < size; ++i) {
-    if (chord[i] || send_empty) {
-      virtser_send(chord[i]);
+    for (uint8_t i = 0; i < size; ++i) {
+        if (chord[i] || send_empty) {
+            virtser_send(chord[i]);
+        }
     }
-  }
 }
 
 void steno_init() {
-  if (!eeconfig_is_enabled()) {
-    eeconfig_init();
-  }
-  mode = eeprom_read_byte(EECONFIG_STENOMODE);
+    if (!eeconfig_is_enabled()) {
+        eeconfig_init();
+    }
+    mode = eeprom_read_byte(EECONFIG_STENOMODE);
 }
 
 void steno_set_mode(steno_mode_t new_mode) {
-  steno_clear_state();
-  mode = new_mode;
-  eeprom_update_byte(EECONFIG_STENOMODE, mode);
+    steno_clear_state();
+    mode = new_mode;
+    eeprom_update_byte(EECONFIG_STENOMODE, mode);
 }
 
 /* override to intercept chords right before they get sent.
  * return zero to suppress normal sending behavior.
  */
-__attribute__ ((weak))
-bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[6]) { return true; }
+__attribute__((weak)) bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[6]) { return true; }
 
-__attribute__ ((weak))
-bool postprocess_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[6], int8_t pressed) { return true; }
+__attribute__((weak)) bool postprocess_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[6], int8_t pressed) { return true; }
 
-__attribute__ ((weak))
-bool process_steno_user(uint16_t keycode, keyrecord_t *record) { return true; }
+__attribute__((weak)) bool process_steno_user(uint16_t keycode, keyrecord_t *record) { return true; }
 
 static void send_steno_chord(void) {
-  if (send_steno_chord_user(mode, chord)) {
-    switch(mode) {
-      case STENO_MODE_BOLT:
-        send_steno_state(BOLT_STATE_SIZE, false);
-        virtser_send(0); // terminating byte
-        break;
-      case STENO_MODE_GEMINI:
-        chord[0] |= 0x80; // Indicate start of packet
-        send_steno_state(GEMINI_STATE_SIZE, true);
-        break;
+    if (send_steno_chord_user(mode, chord)) {
+        switch (mode) {
+            case STENO_MODE_BOLT:
+                send_steno_state(BOLT_STATE_SIZE, false);
+                virtser_send(0);  // terminating byte
+                break;
+            case STENO_MODE_GEMINI:
+                chord[0] |= 0x80;  // Indicate start of packet
+                send_steno_state(GEMINI_STATE_SIZE, true);
+                break;
+        }
     }
-  }
-  steno_clear_state();
+    steno_clear_state();
 }
 
-uint8_t *steno_get_state(void) {
-  return &state[0];
-}
+uint8_t *steno_get_state(void) { return &state[0]; }
 
-uint8_t *steno_get_chord(void) {
-  return &chord[0];
-}
+uint8_t *steno_get_chord(void) { return &chord[0]; }
 
 static bool update_state_bolt(uint8_t key, bool press) {
-  uint8_t boltcode = pgm_read_byte(boltmap + key);
-  if (press) {
-    state[TXB_GET_GROUP(boltcode)] |= boltcode;
-    chord[TXB_GET_GROUP(boltcode)] |= boltcode;
-  } else {
-    state[TXB_GET_GROUP(boltcode)] &= ~boltcode;
-  }
-  return false;
+    uint8_t boltcode = pgm_read_byte(boltmap + key);
+    if (press) {
+        state[TXB_GET_GROUP(boltcode)] |= boltcode;
+        chord[TXB_GET_GROUP(boltcode)] |= boltcode;
+    } else {
+        state[TXB_GET_GROUP(boltcode)] &= ~boltcode;
+    }
+    return false;
 }
 
 static bool update_state_gemini(uint8_t key, bool press) {
-  int idx = key / 7;
-  uint8_t bit = 1 << (6 - (key % 7));
-  if (press) {
-    state[idx] |= bit;
-    chord[idx] |= bit;
-  } else {
-    state[idx] &= ~bit;
-  }
-  return false;
+    int     idx = key / 7;
+    uint8_t bit = 1 << (6 - (key % 7));
+    if (press) {
+        state[idx] |= bit;
+        chord[idx] |= bit;
+    } else {
+        state[idx] &= ~bit;
+    }
+    return false;
 }
 
 bool process_steno(uint16_t keycode, keyrecord_t *record) {
-  switch (keycode) {
-    case QK_STENO_BOLT:
-      if (!process_steno_user(keycode, record)) {
-        return false;
-      }
-      if (IS_PRESSED(record->event)) {
-        steno_set_mode(STENO_MODE_BOLT);
-      }
-      return false;
-
-    case QK_STENO_GEMINI:
-      if (!process_steno_user(keycode, record)) {
-        return false;
-      }
-      if (IS_PRESSED(record->event)) {
-        steno_set_mode(STENO_MODE_GEMINI);
-      }
-      return false;
-
-    case STN__MIN...STN__MAX:
-      if (!process_steno_user(keycode, record)) {
-        return false;
-      }
-      switch(mode) {
-        case STENO_MODE_BOLT:
-          update_state_bolt(keycode - QK_STENO, IS_PRESSED(record->event));
-          break;
-        case STENO_MODE_GEMINI:
-          update_state_gemini(keycode - QK_STENO, IS_PRESSED(record->event));
-          break;
-      }
-      // allow postprocessing hooks
-      if (postprocess_steno_user(keycode, record, mode, chord, pressed)) {
-        if (IS_PRESSED(record->event)) {
-          ++pressed;
-        } else {
-          --pressed;
-          if (pressed <= 0) {
-            pressed = 0;
-            send_steno_chord();
-          }
-        }
-      }
-      return false;
-  }
-  return true;
+    switch (keycode) {
+        case QK_STENO_BOLT:
+            if (!process_steno_user(keycode, record)) {
+                return false;
+            }
+            if (IS_PRESSED(record->event)) {
+                steno_set_mode(STENO_MODE_BOLT);
+            }
+            return false;
+
+        case QK_STENO_GEMINI:
+            if (!process_steno_user(keycode, record)) {
+                return false;
+            }
+            if (IS_PRESSED(record->event)) {
+                steno_set_mode(STENO_MODE_GEMINI);
+            }
+            return false;
+
+        case STN__MIN ... STN__MAX:
+            if (!process_steno_user(keycode, record)) {
+                return false;
+            }
+            switch (mode) {
+                case STENO_MODE_BOLT:
+                    update_state_bolt(keycode - QK_STENO, IS_PRESSED(record->event));
+                    break;
+                case STENO_MODE_GEMINI:
+                    update_state_gemini(keycode - QK_STENO, IS_PRESSED(record->event));
+                    break;
+            }
+            // allow postprocessing hooks
+            if (postprocess_steno_user(keycode, record, mode, chord, pressed)) {
+                if (IS_PRESSED(record->event)) {
+                    ++pressed;
+                } else {
+                    --pressed;
+                    if (pressed <= 0) {
+                        pressed = 0;
+                        send_steno_chord();
+                    }
+                }
+            }
+            return false;
+    }
+    return true;
 }
index 71f9731224a3a20ad7d818466d9a54b56649bb1c..367542372838c80abe4547232c110249532f555e 100644 (file)
 #include "quantum.h"
 
 #if defined(STENO_ENABLE) && !defined(VIRTSER_ENABLE)
-  #error "must have virtser enabled to use steno"
+#    error "must have virtser enabled to use steno"
 #endif
 
 typedef enum { STENO_MODE_BOLT, STENO_MODE_GEMINI } steno_mode_t;
 
-bool process_steno(uint16_t keycode, keyrecord_t *record);
-void steno_init(void);
-void steno_set_mode(steno_mode_t mode);
+bool     process_steno(uint16_t keycode, keyrecord_t *record);
+void     steno_init(void);
+void     steno_set_mode(steno_mode_t mode);
 uint8_t *steno_get_state(void);
 uint8_t *steno_get_chord(void);
 
index 16d33dddeee534471d1e91d9ab8bc7e41fca732c..c27fe48347b783aa326f221142283fdc1414c06a 100644 (file)
@@ -17,7 +17,7 @@
 #include "action_tapping.h"
 
 #ifndef TAPPING_TERM
-#define TAPPING_TERM 200
+#    define TAPPING_TERM 200
 #endif
 
 #ifndef NO_ACTION_ONESHOT
@@ -25,191 +25,173 @@ uint8_t get_oneshot_mods(void);
 #endif
 
 static uint16_t last_td;
-static int8_t highest_td = -1;
+static int8_t   highest_td = -1;
 
-void qk_tap_dance_pair_on_each_tap (qk_tap_dance_state_t *state, void *user_data) {
-  qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
+void qk_tap_dance_pair_on_each_tap(qk_tap_dance_state_t *state, void *user_data) {
+    qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
 
-  if (state->count == 2) {
-    register_code16 (pair->kc2);
-    state->finished = true;
-  }
+    if (state->count == 2) {
+        register_code16(pair->kc2);
+        state->finished = true;
+    }
 }
 
-void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data) {
-  qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
+void qk_tap_dance_pair_finished(qk_tap_dance_state_t *state, void *user_data) {
+    qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
 
-  if (state->count == 1) {
-    register_code16 (pair->kc1);
-  } else if (state->count == 2) {
-    register_code16 (pair->kc2);
-  }
+    if (state->count == 1) {
+        register_code16(pair->kc1);
+    } else if (state->count == 2) {
+        register_code16(pair->kc2);
+    }
 }
 
-void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data) {
-  qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
+void qk_tap_dance_pair_reset(qk_tap_dance_state_t *state, void *user_data) {
+    qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
 
-  if (state->count == 1) {
-    unregister_code16 (pair->kc1);
-  } else if (state->count == 2) {
-    unregister_code16 (pair->kc2);
-  }
+    if (state->count == 1) {
+        unregister_code16(pair->kc1);
+    } else if (state->count == 2) {
+        unregister_code16(pair->kc2);
+    }
 }
 
-void qk_tap_dance_dual_role_on_each_tap (qk_tap_dance_state_t *state, void *user_data) {
-  qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
+void qk_tap_dance_dual_role_on_each_tap(qk_tap_dance_state_t *state, void *user_data) {
+    qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
 
-  if (state->count == 2) {
-    layer_move (pair->layer);
-    state->finished = true;
-  }
+    if (state->count == 2) {
+        layer_move(pair->layer);
+        state->finished = true;
+    }
 }
 
-void qk_tap_dance_dual_role_finished (qk_tap_dance_state_t *state, void *user_data) {
-  qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
+void qk_tap_dance_dual_role_finished(qk_tap_dance_state_t *state, void *user_data) {
+    qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
 
-  if (state->count == 1) {
-    register_code16 (pair->kc);
-  } else if (state->count == 2) {
-    layer_move (pair->layer);
-  }
+    if (state->count == 1) {
+        register_code16(pair->kc);
+    } else if (state->count == 2) {
+        layer_move(pair->layer);
+    }
 }
 
-void qk_tap_dance_dual_role_reset (qk_tap_dance_state_t *state, void *user_data) {
-  qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
+void qk_tap_dance_dual_role_reset(qk_tap_dance_state_t *state, void *user_data) {
+    qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
 
-  if (state->count == 1) {
-    unregister_code16 (pair->kc);
-  }
+    if (state->count == 1) {
+        unregister_code16(pair->kc);
+    }
 }
 
-static inline void _process_tap_dance_action_fn (qk_tap_dance_state_t *state,
-                                                 void *user_data,
-                                                 qk_tap_dance_user_fn_t fn)
-{
-  if (fn) {
-    fn(state, user_data);
-  }
+static inline void _process_tap_dance_action_fn(qk_tap_dance_state_t *state, void *user_data, qk_tap_dance_user_fn_t fn) {
+    if (fn) {
+        fn(state, user_data);
+    }
 }
 
-static inline void process_tap_dance_action_on_each_tap (qk_tap_dance_action_t *action)
-{
-  _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_each_tap);
-}
+static inline void process_tap_dance_action_on_each_tap(qk_tap_dance_action_t *action) { _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_tap); }
 
-static inline void process_tap_dance_action_on_dance_finished (qk_tap_dance_action_t *action)
-{
-  if (action->state.finished)
-    return;
-  action->state.finished = true;
-  add_mods(action->state.oneshot_mods);
-  add_weak_mods(action->state.weak_mods);
-  send_keyboard_report();
-  _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_dance_finished);
+static inline void process_tap_dance_action_on_dance_finished(qk_tap_dance_action_t *action) {
+    if (action->state.finished) return;
+    action->state.finished = true;
+    add_mods(action->state.oneshot_mods);
+    add_weak_mods(action->state.weak_mods);
+    send_keyboard_report();
+    _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_dance_finished);
 }
 
-static inline void process_tap_dance_action_on_reset (qk_tap_dance_action_t *action)
-{
-  _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_reset);
-  del_mods(action->state.oneshot_mods);
-  del_weak_mods(action->state.weak_mods);
-  send_keyboard_report();
+static inline void process_tap_dance_action_on_reset(qk_tap_dance_action_t *action) {
+    _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_reset);
+    del_mods(action->state.oneshot_mods);
+    del_weak_mods(action->state.weak_mods);
+    send_keyboard_report();
 }
 
 void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
-  qk_tap_dance_action_t *action;
-
-  if (!record->event.pressed)
-    return;
-
-  if (highest_td == -1)
-    return;
-
-  for (int i = 0; i <= highest_td; i++) {
-    action = &tap_dance_actions[i];
-    if (action->state.count) {
-      if (keycode == action->state.keycode && keycode == last_td)
-        continue;
-      action->state.interrupted = true;
-      action->state.interrupting_keycode = keycode;
-      process_tap_dance_action_on_dance_finished (action);
-      reset_tap_dance (&action->state);
+    qk_tap_dance_action_t *action;
+
+    if (!record->event.pressed) return;
+
+    if (highest_td == -1) return;
+
+    for (int i = 0; i <= highest_td; i++) {
+        action = &tap_dance_actions[i];
+        if (action->state.count) {
+            if (keycode == action->state.keycode && keycode == last_td) continue;
+            action->state.interrupted          = true;
+            action->state.interrupting_keycode = keycode;
+            process_tap_dance_action_on_dance_finished(action);
+            reset_tap_dance(&action->state);
+        }
     }
-  }
 }
 
 bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
-  uint16_t idx = keycode - QK_TAP_DANCE;
-  qk_tap_dance_action_t *action;
-
-  switch(keycode) {
-  case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
-    if ((int16_t)idx > highest_td)
-      highest_td = idx;
-    action = &tap_dance_actions[idx];
-
-    action->state.pressed = record->event.pressed;
-    if (record->event.pressed) {
-      action->state.keycode = keycode;
-      action->state.count++;
-      action->state.timer = timer_read();
+    uint16_t               idx = keycode - QK_TAP_DANCE;
+    qk_tap_dance_action_t *action;
+
+    switch (keycode) {
+        case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
+            if ((int16_t)idx > highest_td) highest_td = idx;
+            action = &tap_dance_actions[idx];
+
+            action->state.pressed = record->event.pressed;
+            if (record->event.pressed) {
+                action->state.keycode = keycode;
+                action->state.count++;
+                action->state.timer = timer_read();
 #ifndef NO_ACTION_ONESHOT
-      action->state.oneshot_mods = get_oneshot_mods();
+                action->state.oneshot_mods = get_oneshot_mods();
 #else
-      action->state.oneshot_mods = 0;
+                action->state.oneshot_mods = 0;
 #endif
-      action->state.weak_mods = get_mods();
-      action->state.weak_mods |= get_weak_mods();
-      process_tap_dance_action_on_each_tap (action);
-
-      last_td = keycode;
-    } else {
-      if (action->state.count && action->state.finished) {
-        reset_tap_dance (&action->state);
-      }
+                action->state.weak_mods = get_mods();
+                action->state.weak_mods |= get_weak_mods();
+                process_tap_dance_action_on_each_tap(action);
+
+                last_td = keycode;
+            } else {
+                if (action->state.count && action->state.finished) {
+                    reset_tap_dance(&action->state);
+                }
+            }
+
+            break;
     }
 
-    break;
-  }
-
-  return true;
+    return true;
 }
 
-
-
-void matrix_scan_tap_dance () {
-  if (highest_td == -1)
-    return;
-  uint16_t tap_user_defined;
-
-  for (uint8_t i = 0; i <= highest_td; i++) {
-    qk_tap_dance_action_t *action = &tap_dance_actions[i];
-    if(action->custom_tapping_term > 0 ) {
-      tap_user_defined = action->custom_tapping_term;
-    }
-    else{
-      tap_user_defined = TAPPING_TERM;
-    }
-    if (action->state.count && timer_elapsed (action->state.timer) > tap_user_defined) {
-      process_tap_dance_action_on_dance_finished (action);
-      reset_tap_dance (&action->state);
+void matrix_scan_tap_dance() {
+    if (highest_td == -1) return;
+    uint16_t tap_user_defined;
+
+    for (uint8_t i = 0; i <= highest_td; i++) {
+        qk_tap_dance_action_t *action = &tap_dance_actions[i];
+        if (action->custom_tapping_term > 0) {
+            tap_user_defined = action->custom_tapping_term;
+        } else {
+            tap_user_defined = TAPPING_TERM;
+        }
+        if (action->state.count && timer_elapsed(action->state.timer) > tap_user_defined) {
+            process_tap_dance_action_on_dance_finished(action);
+            reset_tap_dance(&action->state);
+        }
     }
-  }
 }
 
-void reset_tap_dance (qk_tap_dance_state_t *state) {
-  qk_tap_dance_action_t *action;
+void reset_tap_dance(qk_tap_dance_state_t *state) {
+    qk_tap_dance_action_t *action;
 
-  if (state->pressed)
-    return;
+    if (state->pressed) return;
 
-  action = &tap_dance_actions[state->keycode - QK_TAP_DANCE];
+    action = &tap_dance_actions[state->keycode - QK_TAP_DANCE];
 
-  process_tap_dance_action_on_reset (action);
+    process_tap_dance_action_on_reset(action);
 
-  state->count = 0;
-  state->interrupted = false;
-  state->finished = false;
-  state->interrupting_keycode = 0;
-  last_td = 0;
+    state->count                = 0;
+    state->interrupted          = false;
+    state->finished             = false;
+    state->interrupting_keycode = 0;
+    last_td                     = 0;
 }
index 00d70cbc59d0a748f9e9a2beb28ca5f9db0befad..b2d0cb8297cdc94bba61240ed77daf86a4603ee8 100644 (file)
 
 #ifdef TAP_DANCE_ENABLE
 
-#include <stdbool.h>
-#include <inttypes.h>
-
-typedef struct
-{
-  uint8_t count;
-  uint8_t oneshot_mods;
-  uint8_t weak_mods;
-  uint16_t keycode;
-  uint16_t interrupting_keycode;
-  uint16_t timer;
-  bool interrupted;
-  bool pressed;
-  bool finished;
+#    include <stdbool.h>
+#    include <inttypes.h>
+
+typedef struct {
+    uint8_t  count;
+    uint8_t  oneshot_mods;
+    uint8_t  weak_mods;
+    uint16_t keycode;
+    uint16_t interrupting_keycode;
+    uint16_t timer;
+    bool     interrupted;
+    bool     pressed;
+    bool     finished;
 } qk_tap_dance_state_t;
 
-#define TD(n) (QK_TAP_DANCE | ((n) & 0xFF))
+#    define TD(n) (QK_TAP_DANCE | ((n)&0xFF))
 
-typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data);
+typedef void (*qk_tap_dance_user_fn_t)(qk_tap_dance_state_t *state, void *user_data);
 
-typedef struct
-{
-  struct {
-    qk_tap_dance_user_fn_t on_each_tap;
-    qk_tap_dance_user_fn_t on_dance_finished;
-    qk_tap_dance_user_fn_t on_reset;
-  } fn;
-  qk_tap_dance_state_t state;
-  uint16_t custom_tapping_term;
-  void *user_data;
+typedef struct {
+    struct {
+        qk_tap_dance_user_fn_t on_each_tap;
+        qk_tap_dance_user_fn_t on_dance_finished;
+        qk_tap_dance_user_fn_t on_reset;
+    } fn;
+    qk_tap_dance_state_t state;
+    uint16_t             custom_tapping_term;
+    void *               user_data;
 } qk_tap_dance_action_t;
 
-typedef struct
-{
-  uint16_t kc1;
-  uint16_t kc2;
+typedef struct {
+    uint16_t kc1;
+    uint16_t kc2;
 } qk_tap_dance_pair_t;
 
-typedef struct
-{
-  uint16_t kc;
-  uint8_t layer;
+typedef struct {
+    uint16_t kc;
+    uint8_t  layer;
 } qk_tap_dance_dual_role_t;
 
-#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
-    .fn = { qk_tap_dance_pair_on_each_tap, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \
-    .user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }),  \
-  }
+#    define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) \
+        { .fn = {qk_tap_dance_pair_on_each_tap, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset}, .user_data = (void *)&((qk_tap_dance_pair_t){kc1, kc2}), }
 
-#define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) { \
-    .fn = { qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, \
-    .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer }), \
-  }
+#    define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) \
+        { .fn = {qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset}, .user_data = (void *)&((qk_tap_dance_dual_role_t){kc, layer}), }
 
-#define ACTION_TAP_DANCE_FN(user_fn) {  \
-    .fn = { NULL, user_fn, NULL }, \
-    .user_data = NULL, \
-  }
+#    define ACTION_TAP_DANCE_FN(user_fn) \
+        { .fn = {NULL, user_fn, NULL}, .user_data = NULL, }
 
-#define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) { \
-    .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \
-    .user_data = NULL, \
-  }
+#    define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) \
+        { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, }
 
-#define ACTION_TAP_DANCE_FN_ADVANCED_TIME(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, tap_specific_tapping_term) { \
-    .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \
-    .user_data = NULL, \
-    .custom_tapping_term = tap_specific_tapping_term, \
-  }
+#    define ACTION_TAP_DANCE_FN_ADVANCED_TIME(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, tap_specific_tapping_term) \
+        { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, .custom_tapping_term = tap_specific_tapping_term, }
 
 extern qk_tap_dance_action_t tap_dance_actions[];
 
@@ -94,20 +79,20 @@ extern qk_tap_dance_action_t tap_dance_actions[];
 
 void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record);
 bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
-void matrix_scan_tap_dance (void);
-void reset_tap_dance (qk_tap_dance_state_t *state);
+void matrix_scan_tap_dance(void);
+void reset_tap_dance(qk_tap_dance_state_t *state);
 
-void qk_tap_dance_pair_on_each_tap (qk_tap_dance_state_t *state, void *user_data);
-void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data);
-void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data);
+void qk_tap_dance_pair_on_each_tap(qk_tap_dance_state_t *state, void *user_data);
+void qk_tap_dance_pair_finished(qk_tap_dance_state_t *state, void *user_data);
+void qk_tap_dance_pair_reset(qk_tap_dance_state_t *state, void *user_data);
 
-void qk_tap_dance_dual_role_on_each_tap (qk_tap_dance_state_t *state, void *user_data);
-void qk_tap_dance_dual_role_finished (qk_tap_dance_state_t *state, void *user_data);
-void qk_tap_dance_dual_role_reset (qk_tap_dance_state_t *state, void *user_data);
+void qk_tap_dance_dual_role_on_each_tap(qk_tap_dance_state_t *state, void *user_data);
+void qk_tap_dance_dual_role_finished(qk_tap_dance_state_t *state, void *user_data);
+void qk_tap_dance_dual_role_reset(qk_tap_dance_state_t *state, void *user_data);
 
 #else
 
-#define TD(n) KC_NO
+#    define TD(n) KC_NO
 
 #endif
 
index e791deffc10b1b6e930ea569995e91cb55dde8b8..f48f3d702d57aecc15e8e47b9e6a8032dfa1e864 100644 (file)
 #include <math.h>
 
 #ifndef CMD_BUFF_SIZE
-  #define CMD_BUFF_SIZE 5
+#    define CMD_BUFF_SIZE 5
 #endif
 
-
 bool terminal_enabled = false;
-char buffer[80] = "";
+char buffer[80]       = "";
 char cmd_buffer[CMD_BUFF_SIZE][80];
-bool cmd_buffer_enabled = true; //replace with ifdef?
-char newline[2] = "\n";
+bool cmd_buffer_enabled = true;  // replace with ifdef?
+char newline[2]         = "\n";
 char arguments[6][20];
 bool firstTime = true;
 
-short int current_cmd_buffer_pos = 0; //used for up/down arrows - keeps track of where you are in the command buffer
+short int current_cmd_buffer_pos = 0;  // used for up/down arrows - keeps track of where you are in the command buffer
 
-__attribute__ ((weak))
-const char terminal_prompt[8] = "> ";
+__attribute__((weak)) const char terminal_prompt[8] = "> ";
 
 #ifdef AUDIO_ENABLE
-    #ifndef TERMINAL_SONG
-        #define TERMINAL_SONG SONG(TERMINAL_SOUND)
-    #endif
-    float terminal_song[][2] = TERMINAL_SONG;
-    #define TERMINAL_BELL() PLAY_SONG(terminal_song)
+#    ifndef TERMINAL_SONG
+#        define TERMINAL_SONG SONG(TERMINAL_SOUND)
+#    endif
+float terminal_song[][2] = TERMINAL_SONG;
+#    define TERMINAL_BELL() PLAY_SONG(terminal_song)
 #else
-    #define TERMINAL_BELL()
+#    define TERMINAL_BELL()
 #endif
 
-__attribute__ ((weak))
-const char keycode_to_ascii_lut[58] = {
-    0, 0, 0, 0,
-    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
-    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
-    '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0, 0, 0, '\t',
-    ' ', '-', '=', '[', ']', '\\', 0, ';', '\'', '`', ',', '.', '/'
-};
-
-__attribute__ ((weak))
-const char shifted_keycode_to_ascii_lut[58] = {
-    0, 0, 0, 0,
-    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
-    'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
-    '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', 0, 0, 0, '\t',
-    ' ', '_', '+', '{', '}', '|', 0, ':', '\'', '~', '<', '>', '?'
-};
+__attribute__((weak)) const char keycode_to_ascii_lut[58] = {0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0, 0, 0, '\t', ' ', '-', '=', '[', ']', '\\', 0, ';', '\'', '`', ',', '.', '/'};
+
+__attribute__((weak)) const char shifted_keycode_to_ascii_lut[58] = {0, 0, 0, 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', 0, 0, 0, '\t', ' ', '_', '+', '{', '}', '|', 0, ':', '\'', '~', '<', '>', '?'};
 
 struct stringcase {
-    charstring;
+    char *string;
     void (*func)(void);
 } typedef stringcase;
 
 void enable_terminal(void) {
     terminal_enabled = true;
     strcpy(buffer, "");
-    memset(cmd_buffer,0,CMD_BUFF_SIZE * 80);
-    for (int i = 0; i < 6; i++)
-        strcpy(arguments[i], "");
+    memset(cmd_buffer, 0, CMD_BUFF_SIZE * 80);
+    for (int i = 0; i < 6; i++) strcpy(arguments[i], "");
     // select all text to start over
     // SEND_STRING(SS_LCTRL("a"));
     send_string(terminal_prompt);
@@ -88,41 +71,41 @@ void disable_terminal(void) {
 }
 
 void push_to_cmd_buffer(void) {
-if (cmd_buffer_enabled) {
-    if (cmd_buffer == NULL) {
-      return;
-    } else {
-    if (firstTime) {
-     firstTime = false;
-     strcpy(cmd_buffer[0],buffer);
-     return;
-   }
+    if (cmd_buffer_enabled) {
+        if (cmd_buffer == NULL) {
+            return;
+        } else {
+            if (firstTime) {
+                firstTime = false;
+                strcpy(cmd_buffer[0], buffer);
+                return;
+            }
 
-   for (int i= CMD_BUFF_SIZE - 1;i > 0 ;--i) {
-      strncpy(cmd_buffer[i],cmd_buffer[i-1],80);
-   }
+            for (int i = CMD_BUFF_SIZE - 1; i > 0; --i) {
+                strncpy(cmd_buffer[i], cmd_buffer[i - 1], 80);
+            }
 
-   strcpy(cmd_buffer[0],buffer);
+            strcpy(cmd_buffer[0], buffer);
 
-   return;
+            return;
+        }
     }
-  }
 }
 
 void terminal_about(void) {
     SEND_STRING("QMK Firmware\n");
     SEND_STRING("  v");
     SEND_STRING(QMK_VERSION);
-    SEND_STRING("\n"SS_TAP(X_HOME)"  Built: ");
+    SEND_STRING("\n" SS_TAP(X_HOME) "  Built: ");
     SEND_STRING(QMK_BUILDDATE);
     send_string(newline);
-    #ifdef TERMINAL_HELP
-        if (strlen(arguments[1]) != 0) {
-            SEND_STRING("You entered: ");
-            send_string(arguments[1]);
-            send_string(newline);
-        }
-    #endif
+#ifdef TERMINAL_HELP
+    if (strlen(arguments[1]) != 0) {
+        SEND_STRING("You entered: ");
+        send_string(arguments[1]);
+        send_string(newline);
+    }
+#endif
 }
 
 void terminal_help(void);
@@ -131,11 +114,11 @@ extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
 
 void terminal_keycode(void) {
     if (strlen(arguments[1]) != 0 && strlen(arguments[2]) != 0 && strlen(arguments[3]) != 0) {
-        char keycode_dec[5];
-        char keycode_hex[5];
-        uint16_t layer = strtol(arguments[1], (char **)NULL, 10);
-        uint16_t row = strtol(arguments[2], (char **)NULL, 10);
-        uint16_t col = strtol(arguments[3], (char **)NULL, 10);
+        char     keycode_dec[5];
+        char     keycode_hex[5];
+        uint16_t layer   = strtol(arguments[1], (char **)NULL, 10);
+        uint16_t row     = strtol(arguments[2], (char **)NULL, 10);
+        uint16_t col     = strtol(arguments[3], (char **)NULL, 10);
         uint16_t keycode = pgm_read_word(&keymaps[layer][row][col]);
         itoa(keycode, keycode_dec, 10);
         itoa(keycode, keycode_hex, 16);
@@ -145,9 +128,9 @@ void terminal_keycode(void) {
         send_string(keycode_dec);
         SEND_STRING(")\n");
     } else {
-        #ifdef TERMINAL_HELP
-            SEND_STRING("usage: keycode <layer> <row> <col>\n");
-        #endif
+#ifdef TERMINAL_HELP
+        SEND_STRING("usage: keycode <layer> <row> <col>\n");
+#endif
     }
 }
 
@@ -157,53 +140,44 @@ void terminal_keymap(void) {
         for (int r = 0; r < MATRIX_ROWS; r++) {
             for (int c = 0; c < MATRIX_COLS; c++) {
                 uint16_t keycode = pgm_read_word(&keymaps[layer][r][c]);
-                char keycode_s[8];
+                char     keycode_s[8];
                 sprintf(keycode_s, "0x%04x,", keycode);
                 send_string(keycode_s);
             }
             send_string(newline);
         }
     } else {
-        #ifdef TERMINAL_HELP
-            SEND_STRING("usage: keymap <layer>\n");
-        #endif
+#ifdef TERMINAL_HELP
+        SEND_STRING("usage: keymap <layer>\n");
+#endif
     }
 }
 
 void print_cmd_buff(void) {
-  /* without the below wait, a race condition can occur wherein the
-   buffer can be printed before it has been fully moved */
-  wait_ms(250);
-  for(int i=0;i<CMD_BUFF_SIZE;i++){
-    char tmpChar = ' ';
-    itoa(i ,&tmpChar,10);
-    const char * tmpCnstCharStr = &tmpChar; //because sned_string wont take a normal char *
-    send_string(tmpCnstCharStr);
-    SEND_STRING(". ");
-    send_string(cmd_buffer[i]);
-    SEND_STRING("\n");
-  }
+    /* without the below wait, a race condition can occur wherein the
+     buffer can be printed before it has been fully moved */
+    wait_ms(250);
+    for (int i = 0; i < CMD_BUFF_SIZE; i++) {
+        char tmpChar = ' ';
+        itoa(i, &tmpChar, 10);
+        const char *tmpCnstCharStr = &tmpChar;  // because sned_string wont take a normal char *
+        send_string(tmpCnstCharStr);
+        SEND_STRING(". ");
+        send_string(cmd_buffer[i]);
+        SEND_STRING("\n");
+    }
 }
 
-
 void flush_cmd_buffer(void) {
-  memset(cmd_buffer,0,CMD_BUFF_SIZE * 80);
-  SEND_STRING("Buffer Cleared!\n");
+    memset(cmd_buffer, 0, CMD_BUFF_SIZE * 80);
+    SEND_STRING("Buffer Cleared!\n");
 }
 
-stringcase terminal_cases[] = {
-    { "about", terminal_about },
-    { "help", terminal_help },
-    { "keycode", terminal_keycode },
-    { "keymap", terminal_keymap },
-    { "flush-buffer" , flush_cmd_buffer},
-    { "print-buffer" , print_cmd_buff},
-    { "exit", disable_terminal }
-};
+stringcase terminal_cases[] = {{"about", terminal_about}, {"help", terminal_help}, {"keycode", terminal_keycode}, {"keymap", terminal_keymap}, {"flush-buffer", flush_cmd_buffer}, {"print-buffer", print_cmd_buff}, {"exit", disable_terminal}};
 
 void terminal_help(void) {
     SEND_STRING("commands available:\n  ");
-    for( stringcase* case_p = terminal_cases; case_p != terminal_cases + sizeof( terminal_cases ) / sizeof( terminal_cases[0] ); case_p++ ) {
+    for (stringcase *case_p = terminal_cases; case_p != terminal_cases + sizeof(terminal_cases) / sizeof(terminal_cases[0]); case_p++) {
         send_string(case_p->string);
         SEND_STRING(" ");
     }
@@ -211,7 +185,7 @@ void terminal_help(void) {
 }
 
 void command_not_found(void) {
-    wait_ms(50); //sometimes buffer isnt grabbed quick enough
+    wait_ms(50);  // sometimes buffer isnt grabbed quick enough
     SEND_STRING("command \"");
     send_string(buffer);
     SEND_STRING("\" not found\n");
@@ -221,9 +195,9 @@ void process_terminal_command(void) {
     // we capture return bc of the order of events, so we need to manually send a newline
     send_string(newline);
 
-    char * pch;
+    char *  pch;
     uint8_t i = 0;
-    pch = strtok(buffer, " ");
+    pch       = strtok(buffer, " ");
     while (pch != NULL) {
         strcpy(arguments[i], pch);
         pch = strtok(NULL, " ");
@@ -231,38 +205,32 @@ void process_terminal_command(void) {
     }
 
     bool command_found = false;
-    for( stringcase* case_p = terminal_cases; case_p != terminal_cases + sizeof( terminal_cases ) / sizeof( terminal_cases[0] ); case_p++ ) {
-        if( 0 == strcmp( case_p->string, buffer ) ) {
+    for (stringcase *case_p = terminal_cases; case_p != terminal_cases + sizeof(terminal_cases) / sizeof(terminal_cases[0]); case_p++) {
+        if (0 == strcmp(case_p->string, buffer)) {
             command_found = true;
             (*case_p->func)();
             break;
         }
     }
 
-    if (!command_found)
-        command_not_found();
+    if (!command_found) command_not_found();
 
     if (terminal_enabled) {
         strcpy(buffer, "");
-        for (int i = 0; i < 6; i++)
-            strcpy(arguments[i], "");
+        for (int i = 0; i < 6; i++) strcpy(arguments[i], "");
         SEND_STRING(SS_TAP(X_HOME));
         send_string(terminal_prompt);
     }
 }
 void check_pos(void) {
-  if (current_cmd_buffer_pos >= CMD_BUFF_SIZE) { //if over the top, move it back down to the top of the buffer so you can climb back down...
-    current_cmd_buffer_pos = CMD_BUFF_SIZE - 1;
-  } else  if (current_cmd_buffer_pos < 0) { //...and if you fall under the bottom of the buffer, reset back to 0 so you can climb back up
-    current_cmd_buffer_pos = 0;
-  }
+    if (current_cmd_buffer_pos >= CMD_BUFF_SIZE) {  // if over the top, move it back down to the top of the buffer so you can climb back down...
+        current_cmd_buffer_pos = CMD_BUFF_SIZE - 1;
+    } else if (current_cmd_buffer_pos < 0) {  //...and if you fall under the bottom of the buffer, reset back to 0 so you can climb back up
+        current_cmd_buffer_pos = 0;
+    }
 }
 
-
-
-
 bool process_terminal(uint16_t keycode, keyrecord_t *record) {
-
     if (keycode == TERM_ON && record->event.pressed) {
         enable_terminal();
         return false;
@@ -280,59 +248,66 @@ bool process_terminal(uint16_t keycode, keyrecord_t *record) {
 
         if (keycode < 256) {
             uint8_t str_len;
-            char char_to_add;
+            char    char_to_add;
             switch (keycode) {
                 case KC_ENTER:
                 case KC_KP_ENTER:
                     push_to_cmd_buffer();
                     current_cmd_buffer_pos = 0;
                     process_terminal_command();
-                    return false; break;
+                    return false;
+                    break;
                 case KC_ESC:
                     SEND_STRING("\n");
                     enable_terminal();
-                    return false; break;
+                    return false;
+                    break;
                 case KC_BSPC:
                     str_len = strlen(buffer);
                     if (str_len > 0) {
-                        buffer[str_len-1] = 0;
+                        buffer[str_len - 1] = 0;
                         return true;
                     } else {
                         TERMINAL_BELL();
                         return false;
-                    } break;
+                    }
+                    break;
                 case KC_LEFT:
-                    return false; break;
+                    return false;
+                    break;
                 case KC_RIGHT:
-                    return false; break;
-                case KC_UP: // 0 = recent
-                  check_pos(); //check our current buffer position is valid
-                  if (current_cmd_buffer_pos <= CMD_BUFF_SIZE - 1) { //once we get to the top, dont do anything
-                    str_len = strlen(buffer);
-                    for(int  i= 0;i < str_len ;++i) {
-                        send_string(SS_TAP(X_BSPACE)); //clear w/e is on the line already
-                        //process_terminal(KC_BSPC,record);
-                    }
-                    strncpy(buffer,cmd_buffer[current_cmd_buffer_pos],80);
+                    return false;
+                    break;
+                case KC_UP:                                             // 0 = recent
+                    check_pos();                                        // check our current buffer position is valid
+                    if (current_cmd_buffer_pos <= CMD_BUFF_SIZE - 1) {  // once we get to the top, dont do anything
+                        str_len = strlen(buffer);
+                        for (int i = 0; i < str_len; ++i) {
+                            send_string(SS_TAP(X_BSPACE));  // clear w/e is on the line already
+                            // process_terminal(KC_BSPC,record);
+                        }
+                        strncpy(buffer, cmd_buffer[current_cmd_buffer_pos], 80);
 
-                    send_string(buffer);
-                    ++current_cmd_buffer_pos; //get ready to access the above cmd if up/down is pressed again
-                  }
-                    return false; break;
+                        send_string(buffer);
+                        ++current_cmd_buffer_pos;  // get ready to access the above cmd if up/down is pressed again
+                    }
+                    return false;
+                    break;
                 case KC_DOWN:
-                  check_pos();
-                  if (current_cmd_buffer_pos >= 0) { //once we get to the bottom, dont do anything
-                      str_len = strlen(buffer);
-                      for(int  i= 0;i < str_len ;++i) {
-                          send_string(SS_TAP(X_BSPACE)); //clear w/e is on the line already
-                          //process_terminal(KC_BSPC,record);
-                      }
-                      strncpy(buffer,cmd_buffer[current_cmd_buffer_pos],79);
-
-                      send_string(buffer);
-                      --current_cmd_buffer_pos; //get ready to access the above cmd if down/up is pressed again
+                    check_pos();
+                    if (current_cmd_buffer_pos >= 0) {  // once we get to the bottom, dont do anything
+                        str_len = strlen(buffer);
+                        for (int i = 0; i < str_len; ++i) {
+                            send_string(SS_TAP(X_BSPACE));  // clear w/e is on the line already
+                            // process_terminal(KC_BSPC,record);
+                        }
+                        strncpy(buffer, cmd_buffer[current_cmd_buffer_pos], 79);
+
+                        send_string(buffer);
+                        --current_cmd_buffer_pos;  // get ready to access the above cmd if down/up is pressed again
                     }
-                    return false; break;
+                    return false;
+                    break;
                 default:
                     if (keycode <= 58) {
                         char_to_add = 0;
@@ -344,11 +319,9 @@ bool process_terminal(uint16_t keycode, keyrecord_t *record) {
                         if (char_to_add != 0) {
                             strncat(buffer, &char_to_add, 1);
                         }
-                    } break;
+                    }
+                    break;
             }
-
-
-
         }
     }
     return true;
index d945949a41d53b86cf4fff2850a0f7d684c9a6f4..8426f442b66731d738a2eea26cd36f344a330958 100644 (file)
@@ -22,6 +22,6 @@
 extern const char keycode_to_ascii_lut[58];
 extern const char shifted_keycode_to_ascii_lut[58];
 extern const char terminal_prompt[8];
-bool process_terminal(uint16_t keycode, keyrecord_t *record);
+bool              process_terminal(uint16_t keycode, keyrecord_t *record);
 
 #endif
\ No newline at end of file
index fd4508b53547860032022e18374f03222fca7877..024077317f3d7195158261d64f8fb9f7f5ac6925 100644 (file)
 qk_ucis_state_t qk_ucis_state;
 
 void qk_ucis_start(void) {
-  qk_ucis_state.count = 0;
-  qk_ucis_state.in_progress = true;
+    qk_ucis_state.count       = 0;
+    qk_ucis_state.in_progress = true;
 
-  qk_ucis_start_user();
+    qk_ucis_start_user();
 }
 
-__attribute__((weak))
-void qk_ucis_start_user(void) {
-  unicode_input_start();
-  register_hex(0x2328);
-  unicode_input_finish();
+__attribute__((weak)) void qk_ucis_start_user(void) {
+    unicode_input_start();
+    register_hex(0x2328);
+    unicode_input_finish();
 }
 
-__attribute__((weak))
-void qk_ucis_success(uint8_t symbol_index) {
-}
+__attribute__((weak)) void qk_ucis_success(uint8_t symbol_index) {}
 
 static bool is_uni_seq(char *seq) {
-  uint8_t i;
+    uint8_t i;
 
-  for (i = 0; seq[i]; i++) {
-    uint16_t code;
-    if (('1' <= seq[i]) && (seq[i] <= '0'))
-      code = seq[i] - '1' + KC_1;
-    else
-      code = seq[i] - 'a' + KC_A;
+    for (i = 0; seq[i]; i++) {
+        uint16_t code;
+        if (('1' <= seq[i]) && (seq[i] <= '0'))
+            code = seq[i] - '1' + KC_1;
+        else
+            code = seq[i] - 'a' + KC_A;
 
-    if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code)
-      return false;
-  }
+        if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code) return false;
+    }
 
-  return (qk_ucis_state.codes[i] == KC_ENT ||
-          qk_ucis_state.codes[i] == KC_SPC);
+    return (qk_ucis_state.codes[i] == KC_ENT || qk_ucis_state.codes[i] == KC_SPC);
 }
 
-__attribute__((weak))
-void qk_ucis_symbol_fallback (void) {
-  for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
-    uint8_t code = qk_ucis_state.codes[i];
-    register_code(code);
-    unregister_code(code);
-    wait_ms(UNICODE_TYPE_DELAY);
-  }
+__attribute__((weak)) void qk_ucis_symbol_fallback(void) {
+    for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
+        uint8_t code = qk_ucis_state.codes[i];
+        register_code(code);
+        unregister_code(code);
+        wait_ms(UNICODE_TYPE_DELAY);
+    }
 }
 
-__attribute__((weak))
-void qk_ucis_cancel(void) {
-}
+__attribute__((weak)) void qk_ucis_cancel(void) {}
 
 void register_ucis(const char *hex) {
-  for(int i = 0; hex[i]; i++) {
-    uint8_t kc = 0;
-    char c = hex[i];
-
-    switch (c) {
-    case '0':
-      kc = KC_0;
-      break;
-    case '1' ... '9':
-      kc = c - '1' + KC_1;
-      break;
-    case 'a' ... 'f':
-      kc = c - 'a' + KC_A;
-      break;
-    case 'A' ... 'F':
-      kc = c - 'A' + KC_A;
-      break;
+    for (int i = 0; hex[i]; i++) {
+        uint8_t kc = 0;
+        char    c  = hex[i];
+
+        switch (c) {
+            case '0':
+                kc = KC_0;
+                break;
+            case '1' ... '9':
+                kc = c - '1' + KC_1;
+                break;
+            case 'a' ... 'f':
+                kc = c - 'a' + KC_A;
+                break;
+            case 'A' ... 'F':
+                kc = c - 'A' + KC_A;
+                break;
+        }
+
+        if (kc) {
+            register_code(kc);
+            unregister_code(kc);
+            wait_ms(UNICODE_TYPE_DELAY);
+        }
     }
-
-    if (kc) {
-      register_code (kc);
-      unregister_code (kc);
-      wait_ms (UNICODE_TYPE_DELAY);
-    }
-  }
 }
 
-bool process_ucis (uint16_t keycode, keyrecord_t *record) {
-  uint8_t i;
+bool process_ucis(uint16_t keycode, keyrecord_t *record) {
+    uint8_t i;
 
-  if (!qk_ucis_state.in_progress)
-    return true;
+    if (!qk_ucis_state.in_progress) return true;
 
-  if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH &&
-      !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) {
-    return false;
-  }
-
-  if (!record->event.pressed)
-    return true;
-
-  qk_ucis_state.codes[qk_ucis_state.count] = keycode;
-  qk_ucis_state.count++;
-
-  if (keycode == KC_BSPC) {
-    if (qk_ucis_state.count >= 2) {
-      qk_ucis_state.count -= 2;
-      return true;
-    } else {
-      qk_ucis_state.count--;
-      return false;
+    if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) {
+        return false;
     }
-  }
 
-  if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) {
-    bool symbol_found = false;
+    if (!record->event.pressed) return true;
 
-    for (i = qk_ucis_state.count; i > 0; i--) {
-      register_code (KC_BSPC);
-      unregister_code (KC_BSPC);
-      wait_ms(UNICODE_TYPE_DELAY);
-    }
-
-    if (keycode == KC_ESC) {
-      qk_ucis_state.in_progress = false;
-      qk_ucis_cancel();
-      return false;
-    }
+    qk_ucis_state.codes[qk_ucis_state.count] = keycode;
+    qk_ucis_state.count++;
 
-    unicode_input_start();
-    for (i = 0; ucis_symbol_table[i].symbol; i++) {
-      if (is_uni_seq (ucis_symbol_table[i].symbol)) {
-        symbol_found = true;
-        register_ucis(ucis_symbol_table[i].code + 2);
-        break;
-      }
-    }
-    if (!symbol_found) {
-      qk_ucis_symbol_fallback();
+    if (keycode == KC_BSPC) {
+        if (qk_ucis_state.count >= 2) {
+            qk_ucis_state.count -= 2;
+            return true;
+        } else {
+            qk_ucis_state.count--;
+            return false;
+        }
     }
-    unicode_input_finish();
 
-    if (symbol_found) {
-      qk_ucis_success(i);
+    if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) {
+        bool symbol_found = false;
+
+        for (i = qk_ucis_state.count; i > 0; i--) {
+            register_code(KC_BSPC);
+            unregister_code(KC_BSPC);
+            wait_ms(UNICODE_TYPE_DELAY);
+        }
+
+        if (keycode == KC_ESC) {
+            qk_ucis_state.in_progress = false;
+            qk_ucis_cancel();
+            return false;
+        }
+
+        unicode_input_start();
+        for (i = 0; ucis_symbol_table[i].symbol; i++) {
+            if (is_uni_seq(ucis_symbol_table[i].symbol)) {
+                symbol_found = true;
+                register_ucis(ucis_symbol_table[i].code + 2);
+                break;
+            }
+        }
+        if (!symbol_found) {
+            qk_ucis_symbol_fallback();
+        }
+        unicode_input_finish();
+
+        if (symbol_found) {
+            qk_ucis_success(i);
+        }
+
+        qk_ucis_state.in_progress = false;
+        return false;
     }
-
-    qk_ucis_state.in_progress = false;
-    return false;
-  }
-  return true;
+    return true;
 }
index b114d839ab8d72030c36c7b9ab5e2e22bae60be3..0f93a198bb0f7239f38df418a8795b095b2ac66e 100644 (file)
 #include "process_unicode_common.h"
 
 #ifndef UCIS_MAX_SYMBOL_LENGTH
-#define UCIS_MAX_SYMBOL_LENGTH 32
+#    define UCIS_MAX_SYMBOL_LENGTH 32
 #endif
 
 typedef struct {
-  char *symbol;
-  char *code;
+    char *symbol;
+    char *code;
 } qk_ucis_symbol_t;
 
 typedef struct {
-  uint8_t count;
-  uint16_t codes[UCIS_MAX_SYMBOL_LENGTH];
-  bool in_progress:1;
+    uint8_t  count;
+    uint16_t codes[UCIS_MAX_SYMBOL_LENGTH];
+    bool     in_progress : 1;
 } qk_ucis_state_t;
 
 extern qk_ucis_state_t qk_ucis_state;
 
-#define UCIS_TABLE(...) {__VA_ARGS__, {NULL, NULL}}
-#define UCIS_SYM(name, code) {name, #code}
+#define UCIS_TABLE(...)             \
+    {                               \
+        __VA_ARGS__, { NULL, NULL } \
+    }
+#define UCIS_SYM(name, code) \
+    { name, #code }
 
 extern const qk_ucis_symbol_t ucis_symbol_table[];
 
 void qk_ucis_start(void);
 void qk_ucis_start_user(void);
-void qk_ucis_symbol_fallback (void);
+void qk_ucis_symbol_fallback(void);
 void qk_ucis_success(uint8_t symbol_index);
 void register_ucis(const char *hex);
-bool process_ucis (uint16_t keycode, keyrecord_t *record);
+bool process_ucis(uint16_t keycode, keyrecord_t *record);
index 2c914013ac052a5312882dc2e575e2a9dcb3c0dc..18a1d8bc1f0df0e79ce5c4091494b201e7d3d1bb 100644 (file)
 #include "eeprom.h"
 
 bool process_unicode(uint16_t keycode, keyrecord_t *record) {
-  if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX && record->event.pressed) {
-    unicode_input_start();
-    register_hex(keycode & 0x7FFF);
-    unicode_input_finish();
-  }
-  return true;
+    if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX && record->event.pressed) {
+        unicode_input_start();
+        register_hex(keycode & 0x7FFF);
+        unicode_input_finish();
+    }
+    return true;
 }
index 21ac2291dba5fb61e9328df992437143b6ea42f6..94383f19b749de209cee447adfe6c0c0d7450187 100644 (file)
@@ -23,220 +23,215 @@ unicode_config_t unicode_config;
 uint8_t          unicode_saved_mods;
 
 #if UNICODE_SELECTED_MODES != -1
-static uint8_t selected[] = { UNICODE_SELECTED_MODES };
+static uint8_t selected[]     = {UNICODE_SELECTED_MODES};
 static uint8_t selected_count = sizeof selected / sizeof *selected;
 static uint8_t selected_index;
 #endif
 
 void unicode_input_mode_init(void) {
-  unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE);
+    unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE);
 #if UNICODE_SELECTED_MODES != -1
-  #if UNICODE_CYCLE_PERSIST
-  // Find input_mode in selected modes
-  uint8_t i;
-  for (i = 0; i < selected_count; i++) {
-    if (selected[i] == unicode_config.input_mode) {
-      selected_index = i;
-      break;
+#    if UNICODE_CYCLE_PERSIST
+    // Find input_mode in selected modes
+    uint8_t i;
+    for (i = 0; i < selected_count; i++) {
+        if (selected[i] == unicode_config.input_mode) {
+            selected_index = i;
+            break;
+        }
     }
-  }
-  if (i == selected_count) {
-    // Not found: input_mode isn't selected, change to one that is
+    if (i == selected_count) {
+        // Not found: input_mode isn't selected, change to one that is
+        unicode_config.input_mode = selected[selected_index = 0];
+    }
+#    else
+    // Always change to the first selected input mode
     unicode_config.input_mode = selected[selected_index = 0];
-  }
-  #else
-  // Always change to the first selected input mode
-  unicode_config.input_mode = selected[selected_index = 0];
-  #endif
+#    endif
 #endif
-  dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode);
+    dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode);
 }
 
-uint8_t get_unicode_input_mode(void) {
-  return unicode_config.input_mode;
-}
+uint8_t get_unicode_input_mode(void) { return unicode_config.input_mode; }
 
 void set_unicode_input_mode(uint8_t mode) {
-  unicode_config.input_mode = mode;
-  persist_unicode_input_mode();
-  dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode);
+    unicode_config.input_mode = mode;
+    persist_unicode_input_mode();
+    dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode);
 }
 
 void cycle_unicode_input_mode(uint8_t offset) {
 #if UNICODE_SELECTED_MODES != -1
-  selected_index = (selected_index + offset) % selected_count;
-  unicode_config.input_mode = selected[selected_index];
-  #if UNICODE_CYCLE_PERSIST
-  persist_unicode_input_mode();
-  #endif
-  dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode);
+    selected_index            = (selected_index + offset) % selected_count;
+    unicode_config.input_mode = selected[selected_index];
+#    if UNICODE_CYCLE_PERSIST
+    persist_unicode_input_mode();
+#    endif
+    dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode);
 #endif
 }
 
-void persist_unicode_input_mode(void) {
-  eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode);
-}
+void persist_unicode_input_mode(void) { eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); }
+
+__attribute__((weak)) void unicode_input_start(void) {
+    unicode_saved_mods = get_mods();  // Save current mods
+    clear_mods();                     // Unregister mods to start from a clean state
+
+    switch (unicode_config.input_mode) {
+        case UC_OSX:
+            register_code(UNICODE_KEY_OSX);
+            break;
+        case UC_LNX:
+            tap_code16(UNICODE_KEY_LNX);
+            break;
+        case UC_WIN:
+            register_code(KC_LALT);
+            tap_code(KC_PPLS);
+            break;
+        case UC_WINC:
+            tap_code(UNICODE_KEY_WINC);
+            tap_code(KC_U);
+            break;
+    }
 
-__attribute__((weak))
-void unicode_input_start(void) {
-  unicode_saved_mods = get_mods(); // Save current mods
-  clear_mods(); // Unregister mods to start from a clean state
-
-  switch (unicode_config.input_mode) {
-  case UC_OSX:
-    register_code(UNICODE_KEY_OSX);
-    break;
-  case UC_LNX:
-    tap_code16(UNICODE_KEY_LNX);
-    break;
-  case UC_WIN:
-    register_code(KC_LALT);
-    tap_code(KC_PPLS);
-    break;
-  case UC_WINC:
-    tap_code(UNICODE_KEY_WINC);
-    tap_code(KC_U);
-    break;
-  }
-
-  wait_ms(UNICODE_TYPE_DELAY);
+    wait_ms(UNICODE_TYPE_DELAY);
 }
 
-__attribute__((weak))
-void unicode_input_finish(void) {
-  switch (unicode_config.input_mode) {
-  case UC_OSX:
-    unregister_code(UNICODE_KEY_OSX);
-    break;
-  case UC_LNX:
-    tap_code(KC_SPC);
-    break;
-  case UC_WIN:
-    unregister_code(KC_LALT);
-    break;
-  case UC_WINC:
-    tap_code(KC_ENTER);
-    break;
-  }
-
-  set_mods(unicode_saved_mods); // Reregister previously set mods
+__attribute__((weak)) void unicode_input_finish(void) {
+    switch (unicode_config.input_mode) {
+        case UC_OSX:
+            unregister_code(UNICODE_KEY_OSX);
+            break;
+        case UC_LNX:
+            tap_code(KC_SPC);
+            break;
+        case UC_WIN:
+            unregister_code(KC_LALT);
+            break;
+        case UC_WINC:
+            tap_code(KC_ENTER);
+            break;
+    }
+
+    set_mods(unicode_saved_mods);  // Reregister previously set mods
 }
 
-__attribute__((weak))
-void unicode_input_cancel(void) {
-  switch (unicode_config.input_mode) {
-  case UC_OSX:
-    unregister_code(UNICODE_KEY_OSX);
-    break;
-  case UC_LNX:
-  case UC_WINC:
-    tap_code(KC_ESC);
-    break;
-  case UC_WIN:
-    unregister_code(KC_LALT);
-    break;
-  }
-
-  set_mods(unicode_saved_mods); // Reregister previously set mods
+__attribute__((weak)) void unicode_input_cancel(void) {
+    switch (unicode_config.input_mode) {
+        case UC_OSX:
+            unregister_code(UNICODE_KEY_OSX);
+            break;
+        case UC_LNX:
+        case UC_WINC:
+            tap_code(KC_ESC);
+            break;
+        case UC_WIN:
+            unregister_code(KC_LALT);
+            break;
+    }
+
+    set_mods(unicode_saved_mods);  // Reregister previously set mods
 }
 
-__attribute__((weak))
-uint16_t hex_to_keycode(uint8_t hex) {
-  if (hex == 0x0) {
-    return KC_0;
-  } else if (hex < 0xA) {
-    return KC_1 + (hex - 0x1);
-  } else {
-    return KC_A + (hex - 0xA);
-  }
+__attribute__((weak)) uint16_t hex_to_keycode(uint8_t hex) {
+    if (hex == 0x0) {
+        return KC_0;
+    } else if (hex < 0xA) {
+        return KC_1 + (hex - 0x1);
+    } else {
+        return KC_A + (hex - 0xA);
+    }
 }
 
 void register_hex(uint16_t hex) {
-  for(int i = 3; i >= 0; i--) {
-    uint8_t digit = ((hex >> (i*4)) & 0xF);
-    tap_code(hex_to_keycode(digit));
-  }
+    for (int i = 3; i >= 0; i--) {
+        uint8_t digit = ((hex >> (i * 4)) & 0xF);
+        tap_code(hex_to_keycode(digit));
+    }
 }
 
 void send_unicode_hex_string(const char *str) {
-  if (!str) { return; }
-
-  while (*str) {
-    // Find the next code point (token) in the string
-    for (; *str == ' '; str++);
-    size_t n = strcspn(str, " "); // Length of the current token
-    char code_point[n+1];
-    strncpy(code_point, str, n);
-    code_point[n] = '\0'; // Make sure it's null-terminated
-
-    // Normalize the code point: make all hex digits lowercase
-    for (char *p = code_point; *p; p++) {
-      *p = tolower((unsigned char)*p);
+    if (!str) {
+        return;
     }
 
-    // Send the code point as a Unicode input string
-    unicode_input_start();
-    send_string(code_point);
-    unicode_input_finish();
-
-    str += n; // Move to the first ' ' (or '\0') after the current token
-  }
+    while (*str) {
+        // Find the next code point (token) in the string
+        for (; *str == ' '; str++)
+            ;
+        size_t n = strcspn(str, " ");  // Length of the current token
+        char   code_point[n + 1];
+        strncpy(code_point, str, n);
+        code_point[n] = '\0';  // Make sure it's null-terminated
+
+        // Normalize the code point: make all hex digits lowercase
+        for (char *p = code_point; *p; p++) {
+            *p = tolower((unsigned char)*p);
+        }
+
+        // Send the code point as a Unicode input string
+        unicode_input_start();
+        send_string(code_point);
+        unicode_input_finish();
+
+        str += n;  // Move to the first ' ' (or '\0') after the current token
+    }
 }
 
 bool process_unicode_common(uint16_t keycode, keyrecord_t *record) {
-  if (record->event.pressed) {
-    switch (keycode) {
-    case UNICODE_MODE_FORWARD:
-      cycle_unicode_input_mode(+1);
-      break;
-    case UNICODE_MODE_REVERSE:
-      cycle_unicode_input_mode(-1);
-      break;
-
-    case UNICODE_MODE_OSX:
-      set_unicode_input_mode(UC_OSX);
+    if (record->event.pressed) {
+        switch (keycode) {
+            case UNICODE_MODE_FORWARD:
+                cycle_unicode_input_mode(+1);
+                break;
+            case UNICODE_MODE_REVERSE:
+                cycle_unicode_input_mode(-1);
+                break;
+
+            case UNICODE_MODE_OSX:
+                set_unicode_input_mode(UC_OSX);
 #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX)
-      static float song_osx[][2] = UNICODE_SONG_OSX;
-      PLAY_SONG(song_osx);
+                static float song_osx[][2] = UNICODE_SONG_OSX;
+                PLAY_SONG(song_osx);
 #endif
-      break;
-    case UNICODE_MODE_LNX:
-      set_unicode_input_mode(UC_LNX);
+                break;
+            case UNICODE_MODE_LNX:
+                set_unicode_input_mode(UC_LNX);
 #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX)
-      static float song_lnx[][2] = UNICODE_SONG_LNX;
-      PLAY_SONG(song_lnx);
+                static float song_lnx[][2] = UNICODE_SONG_LNX;
+                PLAY_SONG(song_lnx);
 #endif
-      break;
-    case UNICODE_MODE_WIN:
-      set_unicode_input_mode(UC_WIN);
+                break;
+            case UNICODE_MODE_WIN:
+                set_unicode_input_mode(UC_WIN);
 #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN)
-      static float song_win[][2] = UNICODE_SONG_WIN;
-      PLAY_SONG(song_win);
+                static float song_win[][2] = UNICODE_SONG_WIN;
+                PLAY_SONG(song_win);
 #endif
-      break;
-    case UNICODE_MODE_BSD:
-      set_unicode_input_mode(UC_BSD);
+                break;
+            case UNICODE_MODE_BSD:
+                set_unicode_input_mode(UC_BSD);
 #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD)
-      static float song_bsd[][2] = UNICODE_SONG_BSD;
-      PLAY_SONG(song_bsd);
+                static float song_bsd[][2] = UNICODE_SONG_BSD;
+                PLAY_SONG(song_bsd);
 #endif
-      break;
-    case UNICODE_MODE_WINC:
-      set_unicode_input_mode(UC_WINC);
+                break;
+            case UNICODE_MODE_WINC:
+                set_unicode_input_mode(UC_WINC);
 #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC)
-      static float song_winc[][2] = UNICODE_SONG_WINC;
-      PLAY_SONG(song_winc);
+                static float song_winc[][2] = UNICODE_SONG_WINC;
+                PLAY_SONG(song_winc);
 #endif
-      break;
+                break;
+        }
     }
-  }
-#if   defined(UNICODE_ENABLE)
-  return process_unicode(keycode, record);
+#if defined(UNICODE_ENABLE)
+    return process_unicode(keycode, record);
 #elif defined(UNICODEMAP_ENABLE)
-  return process_unicodemap(keycode, record);
+    return process_unicodemap(keycode, record);
 #elif defined(UCIS_ENABLE)
-  return process_ucis(keycode, record);
+    return process_ucis(keycode, record);
 #else
-  return true;
+    return true;
 #endif
 }
index 7340800e567fec744a277d0ca24c3bbfcaed2f3b..cab6eea6eafdc9b790e5e920ab034fa4bc627878 100644 (file)
 #include "quantum.h"
 
 #if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1
-  #error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time"
+#    error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time"
 #endif
 
 // Keycodes used for starting Unicode input on different platforms
 #ifndef UNICODE_KEY_OSX
-  #define UNICODE_KEY_OSX  KC_LALT
+#    define UNICODE_KEY_OSX KC_LALT
 #endif
 #ifndef UNICODE_KEY_LNX
-  #define UNICODE_KEY_LNX  LCTL(LSFT(KC_U))
+#    define UNICODE_KEY_LNX LCTL(LSFT(KC_U))
 #endif
 #ifndef UNICODE_KEY_WINC
-  #define UNICODE_KEY_WINC KC_RALT
+#    define UNICODE_KEY_WINC KC_RALT
 #endif
 
 // Comma-delimited, ordered list of input modes selected for use (e.g. in cycle)
 // Example: #define UNICODE_SELECTED_MODES UC_WINC, UC_LNX
 #ifndef UNICODE_SELECTED_MODES
-  #define UNICODE_SELECTED_MODES -1
+#    define UNICODE_SELECTED_MODES -1
 #endif
 
 // Whether input mode changes in cycle should be written to EEPROM
 #ifndef UNICODE_CYCLE_PERSIST
-  #define UNICODE_CYCLE_PERSIST true
+#    define UNICODE_CYCLE_PERSIST true
 #endif
 
 // Delay between starting Unicode input and sending a sequence, in ms
 #ifndef UNICODE_TYPE_DELAY
-  #define UNICODE_TYPE_DELAY 10
+#    define UNICODE_TYPE_DELAY 10
 #endif
 
 enum unicode_input_modes {
-  UC_OSX,   // Mac OS X using Unicode Hex Input
-  UC_LNX,   // Linux using IBus
-  UC_WIN,   // Windows using EnableHexNumpad
-  UC_BSD,   // BSD (not implemented)
-  UC_WINC,  // Windows using WinCompose (https://github.com/samhocevar/wincompose)
-  UC__COUNT // Number of available input modes (always leave at the end)
+    UC_OSX,    // Mac OS X using Unicode Hex Input
+    UC_LNX,    // Linux using IBus
+    UC_WIN,    // Windows using EnableHexNumpad
+    UC_BSD,    // BSD (not implemented)
+    UC_WINC,   // Windows using WinCompose (https://github.com/samhocevar/wincompose)
+    UC__COUNT  // Number of available input modes (always leave at the end)
 };
 
 typedef union {
-  uint32_t raw;
-  struct {
-    uint8_t input_mode : 8;
-  };
+    uint32_t raw;
+    struct {
+        uint8_t input_mode : 8;
+    };
 } unicode_config_t;
 
 extern unicode_config_t unicode_config;
 extern uint8_t          unicode_saved_mods;
 
-void unicode_input_mode_init(void);
+void    unicode_input_mode_init(void);
 uint8_t get_unicode_input_mode(void);
-void set_unicode_input_mode(uint8_t mode);
-void cycle_unicode_input_mode(uint8_t offset);
-void persist_unicode_input_mode(void);
+void    set_unicode_input_mode(uint8_t mode);
+void    cycle_unicode_input_mode(uint8_t offset);
+void    persist_unicode_input_mode(void);
 
 void unicode_input_start(void);
 void unicode_input_finish(void);
@@ -83,108 +83,108 @@ void send_unicode_hex_string(const char *str);
 
 bool process_unicode_common(uint16_t keycode, keyrecord_t *record);
 
-#define UC_BSPC        UC(0x0008)
-#define UC_SPC UC(0x0020)
-
-#define UC_EXLM        UC(0x0021)
-#define UC_DQUT        UC(0x0022)
-#define UC_HASH        UC(0x0023)
-#define UC_DLR UC(0x0024)
-#define UC_PERC        UC(0x0025)
-#define UC_AMPR        UC(0x0026)
-#define UC_QUOT        UC(0x0027)
-#define UC_LPRN        UC(0x0028)
-#define UC_RPRN        UC(0x0029)
-#define UC_ASTR        UC(0x002A)
-#define UC_PLUS        UC(0x002B)
-#define UC_COMM        UC(0x002C)
-#define UC_DASH        UC(0x002D)
-#define UC_DOT UC(0x002E)
-#define UC_SLSH        UC(0x002F)
-
-#define UC_0   UC(0x0030)
-#define UC_1   UC(0x0031)
-#define UC_2   UC(0x0032)
-#define UC_3   UC(0x0033)
-#define UC_4   UC(0x0034)
-#define UC_5   UC(0x0035)
-#define UC_6   UC(0x0036)
-#define UC_7   UC(0x0037)
-#define UC_8   UC(0x0038)
-#define UC_9   UC(0x0039)
+#define UC_BSPC UC(0x0008)
+#define UC_SPC UC(0x0020)
+
+#define UC_EXLM UC(0x0021)
+#define UC_DQUT UC(0x0022)
+#define UC_HASH UC(0x0023)
+#define UC_DLR UC(0x0024)
+#define UC_PERC UC(0x0025)
+#define UC_AMPR UC(0x0026)
+#define UC_QUOT UC(0x0027)
+#define UC_LPRN UC(0x0028)
+#define UC_RPRN UC(0x0029)
+#define UC_ASTR UC(0x002A)
+#define UC_PLUS UC(0x002B)
+#define UC_COMM UC(0x002C)
+#define UC_DASH UC(0x002D)
+#define UC_DOT UC(0x002E)
+#define UC_SLSH UC(0x002F)
+
+#define UC_0 UC(0x0030)
+#define UC_1 UC(0x0031)
+#define UC_2 UC(0x0032)
+#define UC_3 UC(0x0033)
+#define UC_4 UC(0x0034)
+#define UC_5 UC(0x0035)
+#define UC_6 UC(0x0036)
+#define UC_7 UC(0x0037)
+#define UC_8 UC(0x0038)
+#define UC_9 UC(0x0039)
 
 #define UC_COLN UC(0x003A)
 #define UC_SCLN UC(0x003B)
-#define UC_LT  UC(0x003C)
-#define UC_EQL UC(0x003D)
-#define UC_GT  UC(0x003E)
-#define UC_QUES        UC(0x003F)
-#define UC_AT  UC(0x0040)
-
-#define UC_A   UC(0x0041)
-#define UC_B   UC(0x0042)
-#define UC_C   UC(0x0043)
-#define UC_D   UC(0x0044)
-#define UC_E   UC(0x0045)
-#define UC_F   UC(0x0046)
-#define UC_G   UC(0x0047)
-#define UC_H   UC(0x0048)
-#define UC_I   UC(0x0049)
-#define UC_J   UC(0x004A)
-#define UC_K   UC(0x004B)
-#define UC_L   UC(0x004C)
-#define UC_M   UC(0x004D)
-#define UC_N   UC(0x004E)
-#define UC_O   UC(0x004F)
-#define UC_P   UC(0x0050)
-#define UC_Q   UC(0x0051)
-#define UC_R   UC(0x0052)
-#define UC_S   UC(0x0053)
-#define UC_T   UC(0x0054)
-#define UC_U   UC(0x0055)
-#define UC_V   UC(0x0056)
-#define UC_W   UC(0x0057)
-#define UC_X   UC(0x0058)
-#define UC_Y   UC(0x0059)
-#define UC_Z   UC(0x005A)
-
-#define UC_LBRC        UC(0x005B)
-#define UC_BSLS        UC(0x005C)
-#define UC_RBRC        UC(0x005D)
-#define UC_CIRM        UC(0x005E)
-#define UC_UNDR        UC(0x005F)
-
-#define UC_GRV         UC(0x0060)
-
-#define UC_a   UC(0x0061)
-#define UC_b   UC(0x0062)
-#define UC_c   UC(0x0063)
-#define UC_d   UC(0x0064)
-#define UC_e   UC(0x0065)
-#define UC_f   UC(0x0066)
-#define UC_g   UC(0x0067)
-#define UC_h   UC(0x0068)
-#define UC_i   UC(0x0069)
-#define UC_j   UC(0x006A)
-#define UC_k   UC(0x006B)
-#define UC_l   UC(0x006C)
-#define UC_m   UC(0x006D)
-#define UC_n   UC(0x006E)
-#define UC_o   UC(0x006F)
-#define UC_p   UC(0x0070)
-#define UC_q   UC(0x0071)
-#define UC_r   UC(0x0072)
-#define UC_s   UC(0x0073)
-#define UC_t   UC(0x0074)
-#define UC_u   UC(0x0075)
-#define UC_v   UC(0x0076)
-#define UC_w   UC(0x0077)
-#define UC_x   UC(0x0078)
-#define UC_y   UC(0x0079)
-#define UC_z   UC(0x007A)
-
-#define UC_LCBR        UC(0x007B)
-#define UC_PIPE        UC(0x007C)
-#define UC_RCBR        UC(0x007D)
-#define UC_TILD        UC(0x007E)
-#define UC_DEL UC(0x007F)
+#define UC_LT UC(0x003C)
+#define UC_EQL UC(0x003D)
+#define UC_GT UC(0x003E)
+#define UC_QUES UC(0x003F)
+#define UC_AT UC(0x0040)
+
+#define UC_A UC(0x0041)
+#define UC_B UC(0x0042)
+#define UC_C UC(0x0043)
+#define UC_D UC(0x0044)
+#define UC_E UC(0x0045)
+#define UC_F UC(0x0046)
+#define UC_G UC(0x0047)
+#define UC_H UC(0x0048)
+#define UC_I UC(0x0049)
+#define UC_J UC(0x004A)
+#define UC_K UC(0x004B)
+#define UC_L UC(0x004C)
+#define UC_M UC(0x004D)
+#define UC_N UC(0x004E)
+#define UC_O UC(0x004F)
+#define UC_P UC(0x0050)
+#define UC_Q UC(0x0051)
+#define UC_R UC(0x0052)
+#define UC_S UC(0x0053)
+#define UC_T UC(0x0054)
+#define UC_U UC(0x0055)
+#define UC_V UC(0x0056)
+#define UC_W UC(0x0057)
+#define UC_X UC(0x0058)
+#define UC_Y UC(0x0059)
+#define UC_Z UC(0x005A)
+
+#define UC_LBRC UC(0x005B)
+#define UC_BSLS UC(0x005C)
+#define UC_RBRC UC(0x005D)
+#define UC_CIRM UC(0x005E)
+#define UC_UNDR UC(0x005F)
+
+#define UC_GRV UC(0x0060)
+
+#define UC_a UC(0x0061)
+#define UC_b UC(0x0062)
+#define UC_c UC(0x0063)
+#define UC_d UC(0x0064)
+#define UC_e UC(0x0065)
+#define UC_f UC(0x0066)
+#define UC_g UC(0x0067)
+#define UC_h UC(0x0068)
+#define UC_i UC(0x0069)
+#define UC_j UC(0x006A)
+#define UC_k UC(0x006B)
+#define UC_l UC(0x006C)
+#define UC_m UC(0x006D)
+#define UC_n UC(0x006E)
+#define UC_o UC(0x006F)
+#define UC_p UC(0x0070)
+#define UC_q UC(0x0071)
+#define UC_r UC(0x0072)
+#define UC_s UC(0x0073)
+#define UC_t UC(0x0074)
+#define UC_u UC(0x0075)
+#define UC_v UC(0x0076)
+#define UC_w UC(0x0077)
+#define UC_x UC(0x0078)
+#define UC_y UC(0x0079)
+#define UC_z UC(0x007A)
+
+#define UC_LCBR UC(0x007B)
+#define UC_PIPE UC(0x007C)
+#define UC_RCBR UC(0x007D)
+#define UC_TILD UC(0x007E)
+#define UC_DEL UC(0x007F)
index b887879860656180b6592145de387d90c76b4f4f..4364f156c4237cf3516b23e9caae853e64f1aa26 100644 (file)
 #include "process_unicodemap.h"
 
 void register_hex32(uint32_t hex) {
-  bool onzerostart = true;
-  for(int i = 7; i >= 0; i--) {
-    if (i <= 3) {
-      onzerostart = false;
+    bool onzerostart = true;
+    for (int i = 7; i >= 0; i--) {
+        if (i <= 3) {
+            onzerostart = false;
+        }
+        uint8_t digit = ((hex >> (i * 4)) & 0xF);
+        if (digit == 0) {
+            if (!onzerostart) {
+                register_code(hex_to_keycode(digit));
+                unregister_code(hex_to_keycode(digit));
+            }
+        } else {
+            register_code(hex_to_keycode(digit));
+            unregister_code(hex_to_keycode(digit));
+            onzerostart = false;
+        }
     }
-    uint8_t digit = ((hex >> (i*4)) & 0xF);
-    if (digit == 0) {
-      if (!onzerostart) {
-        register_code(hex_to_keycode(digit));
-        unregister_code(hex_to_keycode(digit));
-      }
-    } else {
-      register_code(hex_to_keycode(digit));
-      unregister_code(hex_to_keycode(digit));
-      onzerostart = false;
-    }
-  }
 }
 
-__attribute__((weak))
-uint16_t unicodemap_index(uint16_t keycode) {
-  if (keycode >= QK_UNICODEMAP_PAIR) {
-    // Keycode is a pair: extract index based on Shift / Caps Lock state
-    uint16_t index = keycode - QK_UNICODEMAP_PAIR;
+__attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) {
+    if (keycode >= QK_UNICODEMAP_PAIR) {
+        // Keycode is a pair: extract index based on Shift / Caps Lock state
+        uint16_t index = keycode - QK_UNICODEMAP_PAIR;
 
-    bool shift = unicode_saved_mods & MOD_MASK_SHIFT, caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK);
-    if (shift ^ caps) { index >>= 7; }
+        bool shift = unicode_saved_mods & MOD_MASK_SHIFT, caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK);
+        if (shift ^ caps) {
+            index >>= 7;
+        }
 
-    return index & 0x7F;
-  } else {
-    // Keycode is a regular index
-    return keycode - QK_UNICODEMAP;
-  }
+        return index & 0x7F;
+    } else {
+        // Keycode is a regular index
+        return keycode - QK_UNICODEMAP;
+    }
 }
 
 bool process_unicodemap(uint16_t keycode, keyrecord_t *record) {
-  if (keycode >= QK_UNICODEMAP && keycode <= QK_UNICODEMAP_PAIR_MAX && record->event.pressed) {
-    unicode_input_start();
+    if (keycode >= QK_UNICODEMAP && keycode <= QK_UNICODEMAP_PAIR_MAX && record->event.pressed) {
+        unicode_input_start();
 
-    uint32_t code = pgm_read_dword(unicode_map + unicodemap_index(keycode));
-    uint8_t input_mode = get_unicode_input_mode();
+        uint32_t code       = pgm_read_dword(unicode_map + unicodemap_index(keycode));
+        uint8_t  input_mode = get_unicode_input_mode();
 
-    if (code > 0x10FFFF || (code > 0xFFFF && input_mode == UC_WIN)) {
-      // Character is out of range supported by the platform
-      unicode_input_cancel();
-    } else if (code > 0xFFFF && input_mode == UC_OSX) {
-      // Convert to UTF-16 surrogate pair on Mac
-      code -= 0x10000;
-      uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10;
-      register_hex32(hi + 0xD800);
-      register_hex32(lo + 0xDC00);
-      unicode_input_finish();
-    } else {
-      register_hex32(code);
-      unicode_input_finish();
+        if (code > 0x10FFFF || (code > 0xFFFF && input_mode == UC_WIN)) {
+            // Character is out of range supported by the platform
+            unicode_input_cancel();
+        } else if (code > 0xFFFF && input_mode == UC_OSX) {
+            // Convert to UTF-16 surrogate pair on Mac
+            code -= 0x10000;
+            uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10;
+            register_hex32(hi + 0xD800);
+            register_hex32(lo + 0xDC00);
+            unicode_input_finish();
+        } else {
+            register_hex32(code);
+            unicode_input_finish();
+        }
     }
-  }
-  return true;
+    return true;
 }
index 51709c5dc8a638b9bb6768abf8516dcb9f5dd803..a4b6d77f3a5950bdb189cd353ee538a07afcf14d 100644 (file)
@@ -20,6 +20,6 @@
 
 extern const uint32_t PROGMEM unicode_map[];
 
-void register_hex32(uint32_t hex);
+void     register_hex32(uint32_t hex);
 uint16_t unicodemap_index(uint16_t keycode);
-bool process_unicodemap(uint16_t keycode, keyrecord_t *record);
+bool     process_unicodemap(uint16_t keycode, keyrecord_t *record);
index cbd1f9df0c843ddc150946f37942d7856a24a913..61e9003b720dd31399adbd147da29a3db9357dc2 100644 (file)
 #include "quantum.h"
 
 #if !defined(RGBLIGHT_ENABLE) && !defined(RGB_MATRIX_ENABLE)
-       #include "rgb.h"
+#    include "rgb.h"
 #endif
 
 #ifdef PROTOCOL_LUFA
-#include "outputselect.h"
+#    include "outputselect.h"
 #endif
 
 #ifndef BREATHING_PERIOD
-#define BREATHING_PERIOD 6
+#    define BREATHING_PERIOD 6
 #endif
 
 #include "backlight.h"
 extern backlight_config_t backlight_config;
 
 #ifdef FAUXCLICKY_ENABLE
-#include "fauxclicky.h"
+#    include "fauxclicky.h"
 #endif
 
 #ifdef API_ENABLE
-#include "api.h"
+#    include "api.h"
 #endif
 
 #ifdef MIDI_ENABLE
-#include "process_midi.h"
+#    include "process_midi.h"
 #endif
 
 #ifdef VELOCIKEY_ENABLE
-#include "velocikey.h"
+#    include "velocikey.h"
 #endif
 
 #ifdef HAPTIC_ENABLE
-    #include "haptic.h"
+#    include "haptic.h"
 #endif
 
 #ifdef ENCODER_ENABLE
-#include "encoder.h"
+#    include "encoder.h"
 #endif
 
 #ifdef AUDIO_ENABLE
-  #ifndef GOODBYE_SONG
-    #define GOODBYE_SONG SONG(GOODBYE_SOUND)
-  #endif
-  #ifndef AG_NORM_SONG
-    #define AG_NORM_SONG SONG(AG_NORM_SOUND)
-  #endif
-  #ifndef AG_SWAP_SONG
-    #define AG_SWAP_SONG SONG(AG_SWAP_SOUND)
-  #endif
-  #ifndef CG_NORM_SONG
-    #define CG_NORM_SONG SONG(AG_NORM_SOUND)
-  #endif
-  #ifndef CG_SWAP_SONG
-    #define CG_SWAP_SONG SONG(AG_SWAP_SOUND)
-  #endif
-  float goodbye_song[][2] = GOODBYE_SONG;
-  float ag_norm_song[][2] = AG_NORM_SONG;
-  float ag_swap_song[][2] = AG_SWAP_SONG;
-  float cg_norm_song[][2] = CG_NORM_SONG;
-  float cg_swap_song[][2] = CG_SWAP_SONG;
-  #ifdef DEFAULT_LAYER_SONGS
-    float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
-  #endif
-#endif
-
-static void do_code16 (uint16_t code, void (*f) (uint8_t)) {
-  switch (code) {
-  case QK_MODS ... QK_MODS_MAX:
-    break;
-  default:
-    return;
-  }
-
-  if (code & QK_LCTL)
-    f(KC_LCTL);
-  if (code & QK_LSFT)
-    f(KC_LSFT);
-  if (code & QK_LALT)
-    f(KC_LALT);
-  if (code & QK_LGUI)
-    f(KC_LGUI);
-
-  if (code < QK_RMODS_MIN) return;
-
-  if (code & QK_RCTL)
-    f(KC_RCTL);
-  if (code & QK_RSFT)
-    f(KC_RSFT);
-  if (code & QK_RALT)
-    f(KC_RALT);
-  if (code & QK_RGUI)
-    f(KC_RGUI);
+#    ifndef GOODBYE_SONG
+#        define GOODBYE_SONG SONG(GOODBYE_SOUND)
+#    endif
+#    ifndef AG_NORM_SONG
+#        define AG_NORM_SONG SONG(AG_NORM_SOUND)
+#    endif
+#    ifndef AG_SWAP_SONG
+#        define AG_SWAP_SONG SONG(AG_SWAP_SOUND)
+#    endif
+#    ifndef CG_NORM_SONG
+#        define CG_NORM_SONG SONG(AG_NORM_SOUND)
+#    endif
+#    ifndef CG_SWAP_SONG
+#        define CG_SWAP_SONG SONG(AG_SWAP_SOUND)
+#    endif
+float goodbye_song[][2] = GOODBYE_SONG;
+float ag_norm_song[][2] = AG_NORM_SONG;
+float ag_swap_song[][2] = AG_SWAP_SONG;
+float cg_norm_song[][2] = CG_NORM_SONG;
+float cg_swap_song[][2] = CG_SWAP_SONG;
+#    ifdef DEFAULT_LAYER_SONGS
+float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
+#    endif
+#endif
+
+static void do_code16(uint16_t code, void (*f)(uint8_t)) {
+    switch (code) {
+        case QK_MODS ... QK_MODS_MAX:
+            break;
+        default:
+            return;
+    }
+
+    if (code & QK_LCTL) f(KC_LCTL);
+    if (code & QK_LSFT) f(KC_LSFT);
+    if (code & QK_LALT) f(KC_LALT);
+    if (code & QK_LGUI) f(KC_LGUI);
+
+    if (code < QK_RMODS_MIN) return;
+
+    if (code & QK_RCTL) f(KC_RCTL);
+    if (code & QK_RSFT) f(KC_RSFT);
+    if (code & QK_RALT) f(KC_RALT);
+    if (code & QK_RGUI) f(KC_RGUI);
 }
 
 static inline void qk_register_weak_mods(uint8_t kc) {
@@ -130,74 +122,64 @@ static inline void qk_unregister_mods(uint8_t kc) {
     send_keyboard_report();
 }
 
-void register_code16 (uint16_t code) {
-  if (IS_MOD(code) || code == KC_NO) {
-      do_code16 (code, qk_register_mods);
-  } else {
-      do_code16 (code, qk_register_weak_mods);
-  }
-  register_code (code);
+void register_code16(uint16_t code) {
+    if (IS_MOD(code) || code == KC_NO) {
+        do_code16(code, qk_register_mods);
+    } else {
+        do_code16(code, qk_register_weak_mods);
+    }
+    register_code(code);
 }
 
-void unregister_code16 (uint16_t code) {
-  unregister_code (code);
-  if (IS_MOD(code) || code == KC_NO) {
-      do_code16 (code, qk_unregister_mods);
-  } else {
-      do_code16 (code, qk_unregister_weak_mods);
-  }
+void unregister_code16(uint16_t code) {
+    unregister_code(code);
+    if (IS_MOD(code) || code == KC_NO) {
+        do_code16(code, qk_unregister_mods);
+    } else {
+        do_code16(code, qk_unregister_weak_mods);
+    }
 }
 
 void tap_code16(uint16_t code) {
-  register_code16(code);
-  #if TAP_CODE_DELAY > 0
+    register_code16(code);
+#if TAP_CODE_DELAY > 0
     wait_ms(TAP_CODE_DELAY);
-  #endif
-  unregister_code16(code);
+#endif
+    unregister_code16(code);
 }
 
-__attribute__ ((weak))
-bool process_action_kb(keyrecord_t *record) {
-  return true;
-}
+__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; }
 
-__attribute__ ((weak))
-bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
-  return process_record_user(keycode, record);
-}
+__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); }
 
-__attribute__ ((weak))
-bool process_record_user(uint16_t keycode, keyrecord_t *record) {
-  return true;
-}
+__attribute__((weak)) bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; }
 
 void reset_keyboard(void) {
-  clear_keyboard();
+    clear_keyboard();
 #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
-  process_midi_all_notes_off();
+    process_midi_all_notes_off();
 #endif
 #ifdef AUDIO_ENABLE
-  #ifndef NO_MUSIC_MODE
+#    ifndef NO_MUSIC_MODE
     music_all_notes_off();
-  #endif
-  uint16_t timer_start = timer_read();
-  PLAY_SONG(goodbye_song);
-  shutdown_user();
-  while(timer_elapsed(timer_start) < 250)
-    wait_ms(1);
-  stop_all_notes();
+#    endif
+    uint16_t timer_start = timer_read();
+    PLAY_SONG(goodbye_song);
+    shutdown_user();
+    while (timer_elapsed(timer_start) < 250) wait_ms(1);
+    stop_all_notes();
 #else
-  shutdown_user();
-  wait_ms(250);
+    shutdown_user();
+    wait_ms(250);
 #endif
 #ifdef HAPTIC_ENABLE
-  haptic_shutdown();
+    haptic_shutdown();
 #endif
 // this is also done later in bootloader.c - not sure if it's neccesary here
 #ifdef BOOTLOADER_CATERINA
-  *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
+    *(uint16_t *)0x0800 = 0x7777;  // these two are a-star-specific
 #endif
-  bootloader_jump();
+    bootloader_jump();
 }
 
 /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise.
@@ -206,31 +188,27 @@ void reset_keyboard(void) {
 static bool grave_esc_was_shifted = false;
 
 /* Convert record into usable keycode via the contained event. */
-uint16_t get_record_keycode(keyrecord_t *record) {
-  return get_event_keycode(record->event);
-}
-
+uint16_t get_record_keycode(keyrecord_t *record) { return get_event_keycode(record->event); }
 
 /* Convert event into usable keycode. Checks the layer cache to ensure that it
  * retains the correct keycode after a layer change, if the key is still pressed.
  */
 uint16_t get_event_keycode(keyevent_t event) {
-
-  #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
+#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
     /* TODO: Use store_or_get_action() or a similar function. */
     if (!disable_action_cache) {
-      uint8_t layer;
-
-      if (event.pressed) {
-        layer = layer_switch_get_layer(event.key);
-        update_source_layers_cache(event.key, layer);
-      } else {
-        layer = read_source_layers_cache(event.key);
-      }
-      return keymap_key_to_keycode(layer, event.key);
+        uint8_t layer;
+
+        if (event.pressed) {
+            layer = layer_switch_get_layer(event.key);
+            update_source_layers_cache(event.key, layer);
+        } else {
+            layer = read_source_layers_cache(event.key);
+        }
+        return keymap_key_to_keycode(layer, event.key);
     } else
-  #endif
-    return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
+#endif
+        return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
 }
 
 /* Main keycode processing function. Hands off handling to other functions,
@@ -247,629 +225,582 @@ bool process_record_quantum(keyrecord_t *record) {
     //   return false;
     // }
 
-  #ifdef VELOCIKEY_ENABLE
-    if (velocikey_enabled() && record->event.pressed) { velocikey_accelerate(); }
-  #endif
+#ifdef VELOCIKEY_ENABLE
+    if (velocikey_enabled() && record->event.pressed) {
+        velocikey_accelerate();
+    }
+#endif
 
-  #ifdef TAP_DANCE_ENABLE
+#ifdef TAP_DANCE_ENABLE
     preprocess_tap_dance(keycode, record);
-  #endif
-
-  if (!(
-  #if defined(KEY_LOCK_ENABLE)
-    // Must run first to be able to mask key_up events.
-    process_key_lock(&keycode, record) &&
-  #endif
-  #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
-    process_clicky(keycode, record) &&
-  #endif //AUDIO_CLICKY
-  #ifdef HAPTIC_ENABLE
-    process_haptic(keycode, record) &&
-  #endif //HAPTIC_ENABLE
-  #if defined(RGB_MATRIX_ENABLE)
-    process_rgb_matrix(keycode, record) &&
-  #endif
-    process_record_kb(keycode, record) &&
-  #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
-    process_midi(keycode, record) &&
-  #endif
-  #ifdef AUDIO_ENABLE
-    process_audio(keycode, record) &&
-  #endif
-  #ifdef STENO_ENABLE
-    process_steno(keycode, record) &&
-  #endif
-  #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE)
-    process_music(keycode, record) &&
-  #endif
-  #ifdef TAP_DANCE_ENABLE
-    process_tap_dance(keycode, record) &&
-  #endif
-  #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
-    process_unicode_common(keycode, record) &&
-  #endif
-  #ifdef LEADER_ENABLE
-    process_leader(keycode, record) &&
-  #endif
-  #ifdef COMBO_ENABLE
-    process_combo(keycode, record) &&
-  #endif
-  #ifdef PRINTING_ENABLE
-    process_printer(keycode, record) &&
-  #endif
-  #ifdef AUTO_SHIFT_ENABLE
-    process_auto_shift(keycode, record) &&
-  #endif
-  #ifdef TERMINAL_ENABLE
-    process_terminal(keycode, record) &&
-  #endif
-  #ifdef SPACE_CADET_ENABLE
-    process_space_cadet(keycode, record) &&
-  #endif
-      true)) {
-    return false;
-  }
-
-  // Shift / paren setup
-
-  switch(keycode) {
-    case RESET:
-      if (record->event.pressed) {
-        reset_keyboard();
-      }
-    return false;
-    case DEBUG:
-      if (record->event.pressed) {
-        debug_enable ^= 1;
-        if (debug_enable) {
-          print("DEBUG: enabled.\n");
-        } else {
-          print("DEBUG: disabled.\n");
-        }
-      }
-    return false;
-    case EEPROM_RESET:
-      if (record->event.pressed) {
-          eeconfig_init();
-      }
-    return false;
-  #ifdef FAUXCLICKY_ENABLE
-  case FC_TOG:
-    if (record->event.pressed) {
-      FAUXCLICKY_TOGGLE;
-    }
-    return false;
-  case FC_ON:
-    if (record->event.pressed) {
-      FAUXCLICKY_ON;
-    }
-    return false;
-  case FC_OFF:
-    if (record->event.pressed) {
-      FAUXCLICKY_OFF;
-    }
-    return false;
-  #endif
-  #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
-  case RGB_TOG:
-    // Split keyboards need to trigger on key-up for edge-case issue
-    #ifndef SPLIT_KEYBOARD
-    if (record->event.pressed) {
-    #else
-    if (!record->event.pressed) {
-    #endif
-      rgblight_toggle();
-    }
-    return false;
-  case RGB_MODE_FORWARD:
-    if (record->event.pressed) {
-      uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT));
-      if(shifted) {
-        rgblight_step_reverse();
-      }
-      else {
-        rgblight_step();
-      }
-    }
-    return false;
-  case RGB_MODE_REVERSE:
-    if (record->event.pressed) {
-      uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT));
-      if(shifted) {
-        rgblight_step();
-      }
-      else {
-        rgblight_step_reverse();
-      }
-    }
-    return false;
-  case RGB_HUI:
-    // Split keyboards need to trigger on key-up for edge-case issue
-    #ifndef SPLIT_KEYBOARD
-    if (record->event.pressed) {
-    #else
-    if (!record->event.pressed) {
-    #endif
-      rgblight_increase_hue();
-    }
-    return false;
-  case RGB_HUD:
-    // Split keyboards need to trigger on key-up for edge-case issue
-    #ifndef SPLIT_KEYBOARD
-    if (record->event.pressed) {
-    #else
-    if (!record->event.pressed) {
-    #endif
-      rgblight_decrease_hue();
-    }
-    return false;
-  case RGB_SAI:
-    // Split keyboards need to trigger on key-up for edge-case issue
-    #ifndef SPLIT_KEYBOARD
-    if (record->event.pressed) {
-    #else
-    if (!record->event.pressed) {
-    #endif
-      rgblight_increase_sat();
-    }
-    return false;
-  case RGB_SAD:
-    // Split keyboards need to trigger on key-up for edge-case issue
-    #ifndef SPLIT_KEYBOARD
-    if (record->event.pressed) {
-    #else
-    if (!record->event.pressed) {
-    #endif
-      rgblight_decrease_sat();
-    }
-    return false;
-  case RGB_VAI:
-    // Split keyboards need to trigger on key-up for edge-case issue
-    #ifndef SPLIT_KEYBOARD
-    if (record->event.pressed) {
-    #else
-    if (!record->event.pressed) {
-    #endif
-      rgblight_increase_val();
-    }
-    return false;
-  case RGB_VAD:
-    // Split keyboards need to trigger on key-up for edge-case issue
-    #ifndef SPLIT_KEYBOARD
-    if (record->event.pressed) {
-    #else
-    if (!record->event.pressed) {
-    #endif
-      rgblight_decrease_val();
-    }
-    return false;
-  case RGB_SPI:
-    if (record->event.pressed) {
-      rgblight_increase_speed();
-    }
-    return false;
-  case RGB_SPD:
-    if (record->event.pressed) {
-      rgblight_decrease_speed();
-    }
-    return false;
-  case RGB_MODE_PLAIN:
-    if (record->event.pressed) {
-      rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
-    }
-    return false;
-  case RGB_MODE_BREATHE:
-  #ifdef RGBLIGHT_EFFECT_BREATHING
-    if (record->event.pressed) {
-      if ((RGBLIGHT_MODE_BREATHING <= rgblight_get_mode()) &&
-          (rgblight_get_mode() < RGBLIGHT_MODE_BREATHING_end)) {
-        rgblight_step();
-      } else {
-        rgblight_mode(RGBLIGHT_MODE_BREATHING);
-      }
-    }
-  #endif
-    return false;
-  case RGB_MODE_RAINBOW:
-  #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
-    if (record->event.pressed) {
-      if ((RGBLIGHT_MODE_RAINBOW_MOOD <= rgblight_get_mode()) &&
-          (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_MOOD_end)) {
-        rgblight_step();
-      } else {
-        rgblight_mode(RGBLIGHT_MODE_RAINBOW_MOOD);
-      }
-    }
-  #endif
-    return false;
-  case RGB_MODE_SWIRL:
-  #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
-    if (record->event.pressed) {
-      if ((RGBLIGHT_MODE_RAINBOW_SWIRL <= rgblight_get_mode()) &&
-          (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_SWIRL_end)) {
-        rgblight_step();
-      } else {
-        rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL);
-      }
-    }
-  #endif
-    return false;
-  case RGB_MODE_SNAKE:
-  #ifdef RGBLIGHT_EFFECT_SNAKE
-    if (record->event.pressed) {
-      if ((RGBLIGHT_MODE_SNAKE <= rgblight_get_mode()) &&
-          (rgblight_get_mode() < RGBLIGHT_MODE_SNAKE_end)) {
-        rgblight_step();
-      } else {
-        rgblight_mode(RGBLIGHT_MODE_SNAKE);
-      }
-    }
-  #endif
-    return false;
-  case RGB_MODE_KNIGHT:
-  #ifdef RGBLIGHT_EFFECT_KNIGHT
-    if (record->event.pressed) {
-      if ((RGBLIGHT_MODE_KNIGHT <= rgblight_get_mode()) &&
-          (rgblight_get_mode() < RGBLIGHT_MODE_KNIGHT_end)) {
-        rgblight_step();
-      } else {
-        rgblight_mode(RGBLIGHT_MODE_KNIGHT);
-      }
-    }
-  #endif
-    return false;
-  case RGB_MODE_XMAS:
-  #ifdef RGBLIGHT_EFFECT_CHRISTMAS
-    if (record->event.pressed) {
-      rgblight_mode(RGBLIGHT_MODE_CHRISTMAS);
-    }
-  #endif
-    return false;
-  case RGB_MODE_GRADIENT:
-  #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
-    if (record->event.pressed) {
-      if ((RGBLIGHT_MODE_STATIC_GRADIENT <= rgblight_get_mode()) &&
-          (rgblight_get_mode() < RGBLIGHT_MODE_STATIC_GRADIENT_end)) {
-        rgblight_step();
-      } else {
-        rgblight_mode(RGBLIGHT_MODE_STATIC_GRADIENT);
-      }
-    }
-  #endif
-    return false;
-  case RGB_MODE_RGBTEST:
-  #ifdef RGBLIGHT_EFFECT_RGB_TEST
-    if (record->event.pressed) {
-      rgblight_mode(RGBLIGHT_MODE_RGB_TEST);
-    }
-  #endif
-    return false;
-  #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
-  #ifdef VELOCIKEY_ENABLE
-    case VLK_TOG:
-      if (record->event.pressed) {
-        velocikey_toggle();
-      }
-      return false;
-  #endif
-  #ifdef PROTOCOL_LUFA
-    case OUT_AUTO:
-      if (record->event.pressed) {
-        set_output(OUTPUT_AUTO);
-      }
-      return false;
-    case OUT_USB:
-      if (record->event.pressed) {
-        set_output(OUTPUT_USB);
-      }
-      return false;
-    #ifdef BLUETOOTH_ENABLE
-    case OUT_BT:
-      if (record->event.pressed) {
-        set_output(OUTPUT_BLUETOOTH);
-      }
-      return false;
-    #endif
-    #endif
-    case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI:
-    case MAGIC_SWAP_LCTL_LGUI ... MAGIC_TOGGLE_CTL_GUI:
-      if (record->event.pressed) {
-        // MAGIC actions (BOOTMAGIC without the boot)
-        if (!eeconfig_is_enabled()) {
-            eeconfig_init();
-        }
-        /* keymap config */
-        keymap_config.raw = eeconfig_read_keymap();
-        switch (keycode)
-        {
-          case MAGIC_SWAP_CONTROL_CAPSLOCK:
-            keymap_config.swap_control_capslock = true;
-            break;
-          case MAGIC_CAPSLOCK_TO_CONTROL:
-            keymap_config.capslock_to_control = true;
-            break;
-          case MAGIC_SWAP_LALT_LGUI:
-            keymap_config.swap_lalt_lgui = true;
-            break;
-          case MAGIC_SWAP_RALT_RGUI:
-            keymap_config.swap_ralt_rgui = true;
-            break;
-          case MAGIC_SWAP_LCTL_LGUI:
-            keymap_config.swap_lctl_lgui = true;
-            break;
-          case MAGIC_SWAP_RCTL_RGUI:
-            keymap_config.swap_rctl_rgui = true;
-            break;
-          case MAGIC_NO_GUI:
-            keymap_config.no_gui = true;
-            break;
-          case MAGIC_SWAP_GRAVE_ESC:
-            keymap_config.swap_grave_esc = true;
-            break;
-          case MAGIC_SWAP_BACKSLASH_BACKSPACE:
-            keymap_config.swap_backslash_backspace = true;
-            break;
-          case MAGIC_HOST_NKRO:
-            keymap_config.nkro = true;
-            break;
-          case MAGIC_SWAP_ALT_GUI:
-            keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true;
-            #ifdef AUDIO_ENABLE
-              PLAY_SONG(ag_swap_song);
-            #endif
-            break;
-          case MAGIC_SWAP_CTL_GUI:
-            keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true;
-            #ifdef AUDIO_ENABLE
-              PLAY_SONG(cg_swap_song);
-            #endif
-            break;
-          case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
-            keymap_config.swap_control_capslock = false;
-            break;
-          case MAGIC_UNCAPSLOCK_TO_CONTROL:
-            keymap_config.capslock_to_control = false;
-            break;
-          case MAGIC_UNSWAP_LALT_LGUI:
-            keymap_config.swap_lalt_lgui = false;
-            break;
-          case MAGIC_UNSWAP_RALT_RGUI:
-            keymap_config.swap_ralt_rgui = false;
-            break;
-          case MAGIC_UNSWAP_LCTL_LGUI:
-            keymap_config.swap_lctl_lgui = false;
-            break;
-          case MAGIC_UNSWAP_RCTL_RGUI:
-            keymap_config.swap_rctl_rgui = false;
-            break;
-          case MAGIC_UNNO_GUI:
-            keymap_config.no_gui = false;
-            break;
-          case MAGIC_UNSWAP_GRAVE_ESC:
-            keymap_config.swap_grave_esc = false;
-            break;
-          case MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
-            keymap_config.swap_backslash_backspace = false;
-            break;
-          case MAGIC_UNHOST_NKRO:
-            keymap_config.nkro = false;
-            break;
-          case MAGIC_UNSWAP_ALT_GUI:
-            keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false;
-            #ifdef AUDIO_ENABLE
-              PLAY_SONG(ag_norm_song);
-            #endif
-            break;
-          case MAGIC_UNSWAP_CTL_GUI:
-            keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false;
-            #ifdef AUDIO_ENABLE
-              PLAY_SONG(cg_norm_song);
-            #endif
-            break;
-          case MAGIC_TOGGLE_ALT_GUI:
-            keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
-            keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui;
-            #ifdef AUDIO_ENABLE
-              if (keymap_config.swap_ralt_rgui) {
-                PLAY_SONG(ag_swap_song);
-              } else {
-                PLAY_SONG(ag_norm_song);
-              }
-            #endif
-            break;
-          case MAGIC_TOGGLE_CTL_GUI:
-            keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui;
-            keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui;
-            #ifdef AUDIO_ENABLE
-              if (keymap_config.swap_rctl_rgui) {
-                PLAY_SONG(cg_swap_song);
-              } else {
-                PLAY_SONG(cg_norm_song);
-              }
-            #endif
-            break;
-          case MAGIC_TOGGLE_NKRO:
-            keymap_config.nkro = !keymap_config.nkro;
-            break;
-          default:
-            break;
-        }
-        eeconfig_update_keymap(keymap_config.raw);
-        clear_keyboard(); // clear to prevent stuck keys
+#endif
 
+    if (!(
+#if defined(KEY_LOCK_ENABLE)
+            // Must run first to be able to mask key_up events.
+            process_key_lock(&keycode, record) &&
+#endif
+#if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
+            process_clicky(keycode, record) &&
+#endif  // AUDIO_CLICKY
+#ifdef HAPTIC_ENABLE
+            process_haptic(keycode, record) &&
+#endif  // HAPTIC_ENABLE
+#if defined(RGB_MATRIX_ENABLE)
+            process_rgb_matrix(keycode, record) &&
+#endif
+            process_record_kb(keycode, record) &&
+#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
+            process_midi(keycode, record) &&
+#endif
+#ifdef AUDIO_ENABLE
+            process_audio(keycode, record) &&
+#endif
+#ifdef STENO_ENABLE
+            process_steno(keycode, record) &&
+#endif
+#if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE)
+            process_music(keycode, record) &&
+#endif
+#ifdef TAP_DANCE_ENABLE
+            process_tap_dance(keycode, record) &&
+#endif
+#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
+            process_unicode_common(keycode, record) &&
+#endif
+#ifdef LEADER_ENABLE
+            process_leader(keycode, record) &&
+#endif
+#ifdef COMBO_ENABLE
+            process_combo(keycode, record) &&
+#endif
+#ifdef PRINTING_ENABLE
+            process_printer(keycode, record) &&
+#endif
+#ifdef AUTO_SHIFT_ENABLE
+            process_auto_shift(keycode, record) &&
+#endif
+#ifdef TERMINAL_ENABLE
+            process_terminal(keycode, record) &&
+#endif
+#ifdef SPACE_CADET_ENABLE
+            process_space_cadet(keycode, record) &&
+#endif
+            true)) {
         return false;
-      }
-      break;
+    }
 
-    case GRAVE_ESC: {
-      uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT)
-                                      |MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)));
+    // Shift / paren setup
+
+    switch (keycode) {
+        case RESET:
+            if (record->event.pressed) {
+                reset_keyboard();
+            }
+            return false;
+        case DEBUG:
+            if (record->event.pressed) {
+                debug_enable ^= 1;
+                if (debug_enable) {
+                    print("DEBUG: enabled.\n");
+                } else {
+                    print("DEBUG: disabled.\n");
+                }
+            }
+            return false;
+        case EEPROM_RESET:
+            if (record->event.pressed) {
+                eeconfig_init();
+            }
+            return false;
+#ifdef FAUXCLICKY_ENABLE
+        case FC_TOG:
+            if (record->event.pressed) {
+                FAUXCLICKY_TOGGLE;
+            }
+            return false;
+        case FC_ON:
+            if (record->event.pressed) {
+                FAUXCLICKY_ON;
+            }
+            return false;
+        case FC_OFF:
+            if (record->event.pressed) {
+                FAUXCLICKY_OFF;
+            }
+            return false;
+#endif
+#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
+        case RGB_TOG:
+// Split keyboards need to trigger on key-up for edge-case issue
+#    ifndef SPLIT_KEYBOARD
+            if (record->event.pressed) {
+#    else
+            if (!record->event.pressed) {
+#    endif
+                rgblight_toggle();
+            }
+            return false;
+        case RGB_MODE_FORWARD:
+            if (record->event.pressed) {
+                uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
+                if (shifted) {
+                    rgblight_step_reverse();
+                } else {
+                    rgblight_step();
+                }
+            }
+            return false;
+        case RGB_MODE_REVERSE:
+            if (record->event.pressed) {
+                uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
+                if (shifted) {
+                    rgblight_step();
+                } else {
+                    rgblight_step_reverse();
+                }
+            }
+            return false;
+        case RGB_HUI:
+// Split keyboards need to trigger on key-up for edge-case issue
+#    ifndef SPLIT_KEYBOARD
+            if (record->event.pressed) {
+#    else
+            if (!record->event.pressed) {
+#    endif
+                rgblight_increase_hue();
+            }
+            return false;
+        case RGB_HUD:
+// Split keyboards need to trigger on key-up for edge-case issue
+#    ifndef SPLIT_KEYBOARD
+            if (record->event.pressed) {
+#    else
+            if (!record->event.pressed) {
+#    endif
+                rgblight_decrease_hue();
+            }
+            return false;
+        case RGB_SAI:
+// Split keyboards need to trigger on key-up for edge-case issue
+#    ifndef SPLIT_KEYBOARD
+            if (record->event.pressed) {
+#    else
+            if (!record->event.pressed) {
+#    endif
+                rgblight_increase_sat();
+            }
+            return false;
+        case RGB_SAD:
+// Split keyboards need to trigger on key-up for edge-case issue
+#    ifndef SPLIT_KEYBOARD
+            if (record->event.pressed) {
+#    else
+            if (!record->event.pressed) {
+#    endif
+                rgblight_decrease_sat();
+            }
+            return false;
+        case RGB_VAI:
+// Split keyboards need to trigger on key-up for edge-case issue
+#    ifndef SPLIT_KEYBOARD
+            if (record->event.pressed) {
+#    else
+            if (!record->event.pressed) {
+#    endif
+                rgblight_increase_val();
+            }
+            return false;
+        case RGB_VAD:
+// Split keyboards need to trigger on key-up for edge-case issue
+#    ifndef SPLIT_KEYBOARD
+            if (record->event.pressed) {
+#    else
+            if (!record->event.pressed) {
+#    endif
+                rgblight_decrease_val();
+            }
+            return false;
+        case RGB_SPI:
+            if (record->event.pressed) {
+                rgblight_increase_speed();
+            }
+            return false;
+        case RGB_SPD:
+            if (record->event.pressed) {
+                rgblight_decrease_speed();
+            }
+            return false;
+        case RGB_MODE_PLAIN:
+            if (record->event.pressed) {
+                rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
+            }
+            return false;
+        case RGB_MODE_BREATHE:
+#    ifdef RGBLIGHT_EFFECT_BREATHING
+            if (record->event.pressed) {
+                if ((RGBLIGHT_MODE_BREATHING <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_BREATHING_end)) {
+                    rgblight_step();
+                } else {
+                    rgblight_mode(RGBLIGHT_MODE_BREATHING);
+                }
+            }
+#    endif
+            return false;
+        case RGB_MODE_RAINBOW:
+#    ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
+            if (record->event.pressed) {
+                if ((RGBLIGHT_MODE_RAINBOW_MOOD <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_MOOD_end)) {
+                    rgblight_step();
+                } else {
+                    rgblight_mode(RGBLIGHT_MODE_RAINBOW_MOOD);
+                }
+            }
+#    endif
+            return false;
+        case RGB_MODE_SWIRL:
+#    ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
+            if (record->event.pressed) {
+                if ((RGBLIGHT_MODE_RAINBOW_SWIRL <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_SWIRL_end)) {
+                    rgblight_step();
+                } else {
+                    rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL);
+                }
+            }
+#    endif
+            return false;
+        case RGB_MODE_SNAKE:
+#    ifdef RGBLIGHT_EFFECT_SNAKE
+            if (record->event.pressed) {
+                if ((RGBLIGHT_MODE_SNAKE <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_SNAKE_end)) {
+                    rgblight_step();
+                } else {
+                    rgblight_mode(RGBLIGHT_MODE_SNAKE);
+                }
+            }
+#    endif
+            return false;
+        case RGB_MODE_KNIGHT:
+#    ifdef RGBLIGHT_EFFECT_KNIGHT
+            if (record->event.pressed) {
+                if ((RGBLIGHT_MODE_KNIGHT <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_KNIGHT_end)) {
+                    rgblight_step();
+                } else {
+                    rgblight_mode(RGBLIGHT_MODE_KNIGHT);
+                }
+            }
+#    endif
+            return false;
+        case RGB_MODE_XMAS:
+#    ifdef RGBLIGHT_EFFECT_CHRISTMAS
+            if (record->event.pressed) {
+                rgblight_mode(RGBLIGHT_MODE_CHRISTMAS);
+            }
+#    endif
+            return false;
+        case RGB_MODE_GRADIENT:
+#    ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
+            if (record->event.pressed) {
+                if ((RGBLIGHT_MODE_STATIC_GRADIENT <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_STATIC_GRADIENT_end)) {
+                    rgblight_step();
+                } else {
+                    rgblight_mode(RGBLIGHT_MODE_STATIC_GRADIENT);
+                }
+            }
+#    endif
+            return false;
+        case RGB_MODE_RGBTEST:
+#    ifdef RGBLIGHT_EFFECT_RGB_TEST
+            if (record->event.pressed) {
+                rgblight_mode(RGBLIGHT_MODE_RGB_TEST);
+            }
+#    endif
+            return false;
+#endif  // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
+#ifdef VELOCIKEY_ENABLE
+        case VLK_TOG:
+            if (record->event.pressed) {
+                velocikey_toggle();
+            }
+            return false;
+#endif
+#ifdef PROTOCOL_LUFA
+        case OUT_AUTO:
+            if (record->event.pressed) {
+                set_output(OUTPUT_AUTO);
+            }
+            return false;
+        case OUT_USB:
+            if (record->event.pressed) {
+                set_output(OUTPUT_USB);
+            }
+            return false;
+#    ifdef BLUETOOTH_ENABLE
+        case OUT_BT:
+            if (record->event.pressed) {
+                set_output(OUTPUT_BLUETOOTH);
+            }
+            return false;
+#    endif
+#endif
+        case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI:
+        case MAGIC_SWAP_LCTL_LGUI ... MAGIC_TOGGLE_CTL_GUI:
+            if (record->event.pressed) {
+                // MAGIC actions (BOOTMAGIC without the boot)
+                if (!eeconfig_is_enabled()) {
+                    eeconfig_init();
+                }
+                /* keymap config */
+                keymap_config.raw = eeconfig_read_keymap();
+                switch (keycode) {
+                    case MAGIC_SWAP_CONTROL_CAPSLOCK:
+                        keymap_config.swap_control_capslock = true;
+                        break;
+                    case MAGIC_CAPSLOCK_TO_CONTROL:
+                        keymap_config.capslock_to_control = true;
+                        break;
+                    case MAGIC_SWAP_LALT_LGUI:
+                        keymap_config.swap_lalt_lgui = true;
+                        break;
+                    case MAGIC_SWAP_RALT_RGUI:
+                        keymap_config.swap_ralt_rgui = true;
+                        break;
+                    case MAGIC_SWAP_LCTL_LGUI:
+                        keymap_config.swap_lctl_lgui = true;
+                        break;
+                    case MAGIC_SWAP_RCTL_RGUI:
+                        keymap_config.swap_rctl_rgui = true;
+                        break;
+                    case MAGIC_NO_GUI:
+                        keymap_config.no_gui = true;
+                        break;
+                    case MAGIC_SWAP_GRAVE_ESC:
+                        keymap_config.swap_grave_esc = true;
+                        break;
+                    case MAGIC_SWAP_BACKSLASH_BACKSPACE:
+                        keymap_config.swap_backslash_backspace = true;
+                        break;
+                    case MAGIC_HOST_NKRO:
+                        keymap_config.nkro = true;
+                        break;
+                    case MAGIC_SWAP_ALT_GUI:
+                        keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true;
+#ifdef AUDIO_ENABLE
+                        PLAY_SONG(ag_swap_song);
+#endif
+                        break;
+                    case MAGIC_SWAP_CTL_GUI:
+                        keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true;
+#ifdef AUDIO_ENABLE
+                        PLAY_SONG(cg_swap_song);
+#endif
+                        break;
+                    case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
+                        keymap_config.swap_control_capslock = false;
+                        break;
+                    case MAGIC_UNCAPSLOCK_TO_CONTROL:
+                        keymap_config.capslock_to_control = false;
+                        break;
+                    case MAGIC_UNSWAP_LALT_LGUI:
+                        keymap_config.swap_lalt_lgui = false;
+                        break;
+                    case MAGIC_UNSWAP_RALT_RGUI:
+                        keymap_config.swap_ralt_rgui = false;
+                        break;
+                    case MAGIC_UNSWAP_LCTL_LGUI:
+                        keymap_config.swap_lctl_lgui = false;
+                        break;
+                    case MAGIC_UNSWAP_RCTL_RGUI:
+                        keymap_config.swap_rctl_rgui = false;
+                        break;
+                    case MAGIC_UNNO_GUI:
+                        keymap_config.no_gui = false;
+                        break;
+                    case MAGIC_UNSWAP_GRAVE_ESC:
+                        keymap_config.swap_grave_esc = false;
+                        break;
+                    case MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
+                        keymap_config.swap_backslash_backspace = false;
+                        break;
+                    case MAGIC_UNHOST_NKRO:
+                        keymap_config.nkro = false;
+                        break;
+                    case MAGIC_UNSWAP_ALT_GUI:
+                        keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false;
+#ifdef AUDIO_ENABLE
+                        PLAY_SONG(ag_norm_song);
+#endif
+                        break;
+                    case MAGIC_UNSWAP_CTL_GUI:
+                        keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false;
+#ifdef AUDIO_ENABLE
+                        PLAY_SONG(cg_norm_song);
+#endif
+                        break;
+                    case MAGIC_TOGGLE_ALT_GUI:
+                        keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
+                        keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui;
+#ifdef AUDIO_ENABLE
+                        if (keymap_config.swap_ralt_rgui) {
+                            PLAY_SONG(ag_swap_song);
+                        } else {
+                            PLAY_SONG(ag_norm_song);
+                        }
+#endif
+                        break;
+                    case MAGIC_TOGGLE_CTL_GUI:
+                        keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui;
+                        keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui;
+#ifdef AUDIO_ENABLE
+                        if (keymap_config.swap_rctl_rgui) {
+                            PLAY_SONG(cg_swap_song);
+                        } else {
+                            PLAY_SONG(cg_norm_song);
+                        }
+#endif
+                        break;
+                    case MAGIC_TOGGLE_NKRO:
+                        keymap_config.nkro = !keymap_config.nkro;
+                        break;
+                    default:
+                        break;
+                }
+                eeconfig_update_keymap(keymap_config.raw);
+                clear_keyboard();  // clear to prevent stuck keys
+
+                return false;
+            }
+            break;
+
+        case GRAVE_ESC: {
+            uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT) | MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)));
 
 #ifdef GRAVE_ESC_ALT_OVERRIDE
-      // if ALT is pressed, ESC is always sent
-      // this is handy for the cmd+opt+esc shortcut on macOS, among other things.
-      if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) {
-        shifted = 0;
-      }
+            // if ALT is pressed, ESC is always sent
+            // this is handy for the cmd+opt+esc shortcut on macOS, among other things.
+            if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) {
+                shifted = 0;
+            }
 #endif
 
 #ifdef GRAVE_ESC_CTRL_OVERRIDE
-      // if CTRL is pressed, ESC is always sent
-      // this is handy for the ctrl+shift+esc shortcut on windows, among other things.
-      if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) {
-        shifted = 0;
-      }
+            // if CTRL is pressed, ESC is always sent
+            // this is handy for the ctrl+shift+esc shortcut on windows, among other things.
+            if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) {
+                shifted = 0;
+            }
 #endif
 
 #ifdef GRAVE_ESC_GUI_OVERRIDE
-      // if GUI is pressed, ESC is always sent
-      if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) {
-        shifted = 0;
-      }
+            // if GUI is pressed, ESC is always sent
+            if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) {
+                shifted = 0;
+            }
 #endif
 
 #ifdef GRAVE_ESC_SHIFT_OVERRIDE
-      // if SHIFT is pressed, ESC is always sent
-      if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) {
-        shifted = 0;
-      }
-#endif
-
-      if (record->event.pressed) {
-        grave_esc_was_shifted = shifted;
-        add_key(shifted ? KC_GRAVE : KC_ESCAPE);
-      }
-      else {
-        del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE);
-      }
-
-      send_keyboard_report();
-      return false;
-    }
+            // if SHIFT is pressed, ESC is always sent
+            if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) {
+                shifted = 0;
+            }
+#endif
+
+            if (record->event.pressed) {
+                grave_esc_was_shifted = shifted;
+                add_key(shifted ? KC_GRAVE : KC_ESCAPE);
+            } else {
+                del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE);
+            }
+
+            send_keyboard_report();
+            return false;
+        }
 
 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING)
-    case BL_BRTG: {
-      if (record->event.pressed) {
-        backlight_toggle_breathing();
-      }
-      return false;
-    }
+        case BL_BRTG: {
+            if (record->event.pressed) {
+                backlight_toggle_breathing();
+            }
+            return false;
+        }
 #endif
-  }
-
-  return process_action_kb(record);
-}
+    }
 
-__attribute__ ((weak))
-const bool ascii_to_shift_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-
-    0, 1, 1, 1, 1, 1, 1, 0,
-    1, 1, 1, 1, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 1, 0, 1, 0, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 0, 0, 0, 1, 1,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 1, 1, 1, 1, 0
-};
-
-__attribute__ ((weak))
-const bool ascii_to_altgr_lut[128] PROGMEM = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0
-};
-
-__attribute__ ((weak))
-const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
-    // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
-    XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
-    // BS    TAB      LF       VT       FF       CR       SO       SI
-    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
-    // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
-    XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
-    // CAN   EM       SUB      ESC      FS       GS       RS       US
-    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
-
-    //       !        "        #        $        %        &        '
-    KC_SPC,  KC_1,    KC_QUOT, KC_3,    KC_4,    KC_5,    KC_7,    KC_QUOT,
-    // (     )        *        +        ,        -        .        /
-    KC_9,    KC_0,    KC_8,    KC_EQL,  KC_COMM, KC_MINS, KC_DOT,  KC_SLSH,
-    // 0     1        2        3        4        5        6        7
-    KC_0,    KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,
-    // 8     9        :        ;        <        =        >        ?
-    KC_8,    KC_9,    KC_SCLN, KC_SCLN, KC_COMM, KC_EQL,  KC_DOT,  KC_SLSH,
-    // @     A        B        C        D        E        F        G
-    KC_2,    KC_A,    KC_B,    KC_C,    KC_D,    KC_E,    KC_F,    KC_G,
-    // H     I        J        K        L        M        N        O
-    KC_H,    KC_I,    KC_J,    KC_K,    KC_L,    KC_M,    KC_N,    KC_O,
-    // P     Q        R        S        T        U        V        W
-    KC_P,    KC_Q,    KC_R,    KC_S,    KC_T,    KC_U,    KC_V,    KC_W,
-    // X     Y        Z        [        \        ]        ^        _
-    KC_X,    KC_Y,    KC_Z,    KC_LBRC, KC_BSLS, KC_RBRC, KC_6,    KC_MINS,
-    // `     a        b        c        d        e        f        g
-    KC_GRV,  KC_A,    KC_B,    KC_C,    KC_D,    KC_E,    KC_F,    KC_G,
-    // h     i        j        k        l        m        n        o
-    KC_H,    KC_I,    KC_J,    KC_K,    KC_L,    KC_M,    KC_N,    KC_O,
-    // p     q        r        s        t        u        v        w
-    KC_P,    KC_Q,    KC_R,    KC_S,    KC_T,    KC_U,    KC_V,    KC_W,
-    // x     y        z        {        |        }        ~        DEL
-    KC_X,    KC_Y,    KC_Z,    KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV,  KC_DEL
-};
-
-void send_string(const char *str) {
-  send_string_with_delay(str, 0);
+    return process_action_kb(record);
 }
 
-void send_string_P(const char *str) {
-  send_string_with_delay_P(str, 0);
-}
+__attribute__((weak)) const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+                                                                    0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0};
+
+__attribute__((weak)) const bool ascii_to_altgr_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+                                                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+__attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = {// NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
+                                                                         XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+                                                                         // BS    TAB      LF       VT       FF       CR       SO       SI
+                                                                         KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+                                                                         // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
+                                                                         XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+                                                                         // CAN   EM       SUB      ESC      FS       GS       RS       US
+                                                                         XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
+
+                                                                         //       !        "        #        $        %        &        '
+                                                                         KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
+                                                                         // (     )        *        +        ,        -        .        /
+                                                                         KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
+                                                                         // 0     1        2        3        4        5        6        7
+                                                                         KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
+                                                                         // 8     9        :        ;        <        =        >        ?
+                                                                         KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
+                                                                         // @     A        B        C        D        E        F        G
+                                                                         KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
+                                                                         // H     I        J        K        L        M        N        O
+                                                                         KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
+                                                                         // P     Q        R        S        T        U        V        W
+                                                                         KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
+                                                                         // X     Y        Z        [        \        ]        ^        _
+                                                                         KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
+                                                                         // `     a        b        c        d        e        f        g
+                                                                         KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
+                                                                         // h     i        j        k        l        m        n        o
+                                                                         KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
+                                                                         // p     q        r        s        t        u        v        w
+                                                                         KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
+                                                                         // x     y        z        {        |        }        ~        DEL
+                                                                         KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL};
+
+void send_string(const char *str) { send_string_with_delay(str, 0); }
+
+void send_string_P(const char *str) { send_string_with_delay_P(str, 0); }
 
 void send_string_with_delay(const char *str, uint8_t interval) {
     while (1) {
         char ascii_code = *str;
         if (!ascii_code) break;
         if (ascii_code == SS_TAP_CODE) {
-          // tap
-          uint8_t keycode = *(++str);
-          register_code(keycode);
-          unregister_code(keycode);
+            // tap
+            uint8_t keycode = *(++str);
+            register_code(keycode);
+            unregister_code(keycode);
         } else if (ascii_code == SS_DOWN_CODE) {
-          // down
-          uint8_t keycode = *(++str);
-          register_code(keycode);
+            // down
+            uint8_t keycode = *(++str);
+            register_code(keycode);
         } else if (ascii_code == SS_UP_CODE) {
-          // up
-          uint8_t keycode = *(++str);
-          unregister_code(keycode);
+            // up
+            uint8_t keycode = *(++str);
+            unregister_code(keycode);
         } else {
-          send_char(ascii_code);
+            send_char(ascii_code);
         }
         ++str;
         // interval
-        { uint8_t ms = interval; while (ms--) wait_ms(1); }
+        {
+            uint8_t ms = interval;
+            while (ms--) wait_ms(1);
+        }
     }
 }
 
@@ -878,201 +809,201 @@ void send_string_with_delay_P(const char *str, uint8_t interval) {
         char ascii_code = pgm_read_byte(str);
         if (!ascii_code) break;
         if (ascii_code == SS_TAP_CODE) {
-          // tap
-          uint8_t keycode = pgm_read_byte(++str);
-          register_code(keycode);
-          unregister_code(keycode);
+            // tap
+            uint8_t keycode = pgm_read_byte(++str);
+            register_code(keycode);
+            unregister_code(keycode);
         } else if (ascii_code == SS_DOWN_CODE) {
-          // down
-          uint8_t keycode = pgm_read_byte(++str);
-          register_code(keycode);
+            // down
+            uint8_t keycode = pgm_read_byte(++str);
+            register_code(keycode);
         } else if (ascii_code == SS_UP_CODE) {
-          // up
-          uint8_t keycode = pgm_read_byte(++str);
-          unregister_code(keycode);
+            // up
+            uint8_t keycode = pgm_read_byte(++str);
+            unregister_code(keycode);
         } else {
-          send_char(ascii_code);
+            send_char(ascii_code);
         }
         ++str;
         // interval
-        { uint8_t ms = interval; while (ms--) wait_ms(1); }
+        {
+            uint8_t ms = interval;
+            while (ms--) wait_ms(1);
+        }
     }
 }
 
 void send_char(char ascii_code) {
-  uint8_t keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]);
-  bool is_shifted = pgm_read_byte(&ascii_to_shift_lut[(uint8_t)ascii_code]);
-  bool is_altgred = pgm_read_byte(&ascii_to_altgr_lut[(uint8_t)ascii_code]);
-
-  if (is_shifted) {
-    register_code(KC_LSFT);
-  }
-  if (is_altgred) {
-    register_code(KC_RALT);
-  }
-  tap_code(keycode);
-  if (is_altgred) {
-    unregister_code(KC_RALT);
-  }
-  if (is_shifted) {
-    unregister_code(KC_LSFT);
-  }
+    uint8_t keycode    = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]);
+    bool    is_shifted = pgm_read_byte(&ascii_to_shift_lut[(uint8_t)ascii_code]);
+    bool    is_altgred = pgm_read_byte(&ascii_to_altgr_lut[(uint8_t)ascii_code]);
+
+    if (is_shifted) {
+        register_code(KC_LSFT);
+    }
+    if (is_altgred) {
+        register_code(KC_RALT);
+    }
+    tap_code(keycode);
+    if (is_altgred) {
+        unregister_code(KC_RALT);
+    }
+    if (is_shifted) {
+        unregister_code(KC_LSFT);
+    }
 }
 
 void set_single_persistent_default_layer(uint8_t default_layer) {
-  #if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS)
+#if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS)
     PLAY_SONG(default_layer_songs[default_layer]);
-  #endif
-  eeconfig_update_default_layer(1U<<default_layer);
-  default_layer_set(1U<<default_layer);
+#endif
+    eeconfig_update_default_layer(1U << default_layer);
+    default_layer_set(1U << default_layer);
 }
 
 layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3) {
-  layer_state_t mask12 = (1UL << layer1) | (1UL << layer2);
-  layer_state_t mask3 = 1UL << layer3;
-  return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3);
+    layer_state_t mask12 = (1UL << layer1) | (1UL << layer2);
+    layer_state_t mask3  = 1UL << layer3;
+    return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3);
 }
 
-void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
-  layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3));
-}
+void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3)); }
 
 void tap_random_base64(void) {
-  #if defined(__AVR_ATmega32U4__)
+#if defined(__AVR_ATmega32U4__)
     uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
-  #else
+#else
     uint8_t key = rand() % 64;
-  #endif
-  switch (key) {
-    case 0 ... 25:
-      register_code(KC_LSFT);
-      register_code(key + KC_A);
-      unregister_code(key + KC_A);
-      unregister_code(KC_LSFT);
-      break;
-    case 26 ... 51:
-      register_code(key - 26 + KC_A);
-      unregister_code(key - 26 + KC_A);
-      break;
-    case 52:
-      register_code(KC_0);
-      unregister_code(KC_0);
-      break;
-    case 53 ... 61:
-      register_code(key - 53 + KC_1);
-      unregister_code(key - 53 + KC_1);
-      break;
-    case 62:
-      register_code(KC_LSFT);
-      register_code(KC_EQL);
-      unregister_code(KC_EQL);
-      unregister_code(KC_LSFT);
-      break;
-    case 63:
-      register_code(KC_SLSH);
-      unregister_code(KC_SLSH);
-      break;
-  }
+#endif
+    switch (key) {
+        case 0 ... 25:
+            register_code(KC_LSFT);
+            register_code(key + KC_A);
+            unregister_code(key + KC_A);
+            unregister_code(KC_LSFT);
+            break;
+        case 26 ... 51:
+            register_code(key - 26 + KC_A);
+            unregister_code(key - 26 + KC_A);
+            break;
+        case 52:
+            register_code(KC_0);
+            unregister_code(KC_0);
+            break;
+        case 53 ... 61:
+            register_code(key - 53 + KC_1);
+            unregister_code(key - 53 + KC_1);
+            break;
+        case 62:
+            register_code(KC_LSFT);
+            register_code(KC_EQL);
+            unregister_code(KC_EQL);
+            unregister_code(KC_LSFT);
+            break;
+        case 63:
+            register_code(KC_SLSH);
+            unregister_code(KC_SLSH);
+            break;
+    }
 }
 
-__attribute__((weak))
-void bootmagic_lite(void) {
-  // The lite version of TMK's bootmagic based on Wilba.
-  // 100% less potential for accidentally making the
-  // keyboard do stupid things.
+__attribute__((weak)) void bootmagic_lite(void) {
+    // The lite version of TMK's bootmagic based on Wilba.
+    // 100% less potential for accidentally making the
+    // keyboard do stupid things.
 
-  // We need multiple scans because debouncing can't be turned off.
-  matrix_scan();
-  #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
+    // We need multiple scans because debouncing can't be turned off.
+    matrix_scan();
+#if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
     wait_ms(DEBOUNCING_DELAY * 2);
-  #elif defined(DEBOUNCE) && DEBOUNCE > 0
+#elif defined(DEBOUNCE) && DEBOUNCE > 0
     wait_ms(DEBOUNCE * 2);
-  #else
+#else
     wait_ms(30);
-  #endif
-  matrix_scan();
-
-  // If the Esc and space bar are held down on power up,
-  // reset the EEPROM valid state and jump to bootloader.
-  // Assumes Esc is at [0,0].
-  // This isn't very generalized, but we need something that doesn't
-  // rely on user's keymaps in firmware or EEPROM.
-  if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
-    eeconfig_disable();
-    // Jump to bootloader.
-    bootloader_jump();
-  }
+#endif
+    matrix_scan();
+
+    // If the Esc and space bar are held down on power up,
+    // reset the EEPROM valid state and jump to bootloader.
+    // Assumes Esc is at [0,0].
+    // This isn't very generalized, but we need something that doesn't
+    // rely on user's keymaps in firmware or EEPROM.
+    if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
+        eeconfig_disable();
+        // Jump to bootloader.
+        bootloader_jump();
+    }
 }
 
 void matrix_init_quantum() {
-  #ifdef BOOTMAGIC_LITE
+#ifdef BOOTMAGIC_LITE
     bootmagic_lite();
-  #endif
-  if (!eeconfig_is_enabled()) {
-    eeconfig_init();
-  }
-  #ifdef BACKLIGHT_ENABLE
-    #ifdef LED_MATRIX_ENABLE
-        led_matrix_init();
-    #else
-        backlight_init_ports();
-    #endif
-  #endif
-  #ifdef AUDIO_ENABLE
+#endif
+    if (!eeconfig_is_enabled()) {
+        eeconfig_init();
+    }
+#ifdef BACKLIGHT_ENABLE
+#    ifdef LED_MATRIX_ENABLE
+    led_matrix_init();
+#    else
+    backlight_init_ports();
+#    endif
+#endif
+#ifdef AUDIO_ENABLE
     audio_init();
-  #endif
-  #ifdef RGB_MATRIX_ENABLE
+#endif
+#ifdef RGB_MATRIX_ENABLE
     rgb_matrix_init();
-  #endif
-  #ifdef ENCODER_ENABLE
+#endif
+#ifdef ENCODER_ENABLE
     encoder_init();
-  #endif
-  #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
+#endif
+#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
     unicode_input_mode_init();
-  #endif
-  #ifdef HAPTIC_ENABLE
+#endif
+#ifdef HAPTIC_ENABLE
     haptic_init();
-  #endif
-  #ifdef OUTPUT_AUTO_ENABLE
+#endif
+#ifdef OUTPUT_AUTO_ENABLE
     set_output(OUTPUT_AUTO);
-  #endif
-  matrix_init_kb();
+#endif
+    matrix_init_kb();
 }
 
 void matrix_scan_quantum() {
-  #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
+#if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
     matrix_scan_music();
-  #endif
+#endif
 
-  #ifdef TAP_DANCE_ENABLE
+#ifdef TAP_DANCE_ENABLE
     matrix_scan_tap_dance();
-  #endif
+#endif
 
-  #ifdef COMBO_ENABLE
+#ifdef COMBO_ENABLE
     matrix_scan_combo();
-  #endif
+#endif
 
-  #if defined(BACKLIGHT_ENABLE)
-    #if defined(LED_MATRIX_ENABLE)
-        led_matrix_task();
-    #elif defined(BACKLIGHT_PIN)
-        backlight_task();
-    #endif
-  #endif
+#if defined(BACKLIGHT_ENABLE)
+#    if defined(LED_MATRIX_ENABLE)
+    led_matrix_task();
+#    elif defined(BACKLIGHT_PIN)
+    backlight_task();
+#    endif
+#endif
 
-  #ifdef RGB_MATRIX_ENABLE
+#ifdef RGB_MATRIX_ENABLE
     rgb_matrix_task();
-  #endif
+#endif
 
-  #ifdef ENCODER_ENABLE
+#ifdef ENCODER_ENABLE
     encoder_read();
-  #endif
+#endif
 
-  #ifdef HAPTIC_ENABLE
+#ifdef HAPTIC_ENABLE
     haptic_task();
-  #endif
+#endif
 
-  matrix_scan_kb();
+    matrix_scan_kb();
 }
 #if defined(BACKLIGHT_ENABLE) && (defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS))
 
@@ -1084,241 +1015,219 @@ void matrix_scan_quantum() {
 //      depends on the Audio setup (Audio wins over Backlight).
 //   3. Full software PWM, driven by the matrix scan, if both timers are used by Audio.
 
-#if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) \
-  || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) \
-  || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) \
-  && (BACKLIGHT_PIN == B5 || BACKLIGHT_PIN == B6 || BACKLIGHT_PIN == B7)
-  #define HARDWARE_PWM
-  #define ICRx            ICR1
-  #define TCCRxA          TCCR1A
-  #define TCCRxB          TCCR1B
-  #define TIMERx_OVF_vect TIMER1_OVF_vect
-  #define TIMSKx          TIMSK1
-  #define TOIEx           TOIE1
-
-  #if BACKLIGHT_PIN == B5
-    #define COMxx1        COM1A1
-    #define OCRxx         OCR1A
-  #elif BACKLIGHT_PIN == B6
-    #define COMxx1        COM1B1
-    #define OCRxx         OCR1B
-  #elif BACKLIGHT_PIN == B7
-    #define COMxx1        COM1C1
-    #define OCRxx         OCR1C
-  #endif
-#elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) \
-  || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) \
-  || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) \
-  && (BACKLIGHT_PIN == C4 || BACKLIGHT_PIN == C5 || BACKLIGHT_PIN == C6)
-  #define HARDWARE_PWM
-  #define ICRx            ICR3
-  #define TCCRxA          TCCR3A
-  #define TCCRxB          TCCR3B
-  #define TIMERx_OVF_vect TIMER3_OVF_vect
-  #define TIMSKx          TIMSK3
-  #define TOIEx           TOIE3
-
-  #if BACKLIGHT_PIN == C4
-    #if (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
-      #error This MCU has no C4 pin!
-    #else
-      #define COMxx1      COM3C1
-      #define OCRxx       OCR3C
-    #endif
-  #elif BACKLIGHT_PIN == C5
-    #if (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
-      #error This MCU has no C5 pin!
-    #else
-      #define COMxx1      COM3B1
-      #define OCRxx       OCR3B
-    #endif
-  #elif BACKLIGHT_PIN == C6
-    #define COMxx1        COM3A1
-    #define OCRxx         OCR3A
-  #endif
-#elif (defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__)) \
-  && (BACKLIGHT_PIN == B7 || BACKLIGHT_PIN == C5 || BACKLIGHT_PIN == C6)
-  #define HARDWARE_PWM
-  #define ICRx            ICR1
-  #define TCCRxA          TCCR1A
-  #define TCCRxB          TCCR1B
-  #define TIMERx_OVF_vect TIMER1_OVF_vect
-  #define TIMSKx          TIMSK1
-  #define TOIEx           TOIE1
-
-  #if BACKLIGHT_PIN == B7
-    #define COMxx1        COM1C1
-    #define OCRxx         OCR1C
-  #elif BACKLIGHT_PIN == C5
-    #define COMxx1        COM1B1
-    #define OCRxx         OCR1B
-  #elif BACKLIGHT_PIN == C6
-    #define COMxx1        COM1A1
-    #define OCRxx         OCR1A
-  #endif
-#elif defined(__AVR_ATmega32A__) \
-  && (BACKLIGHT_PIN == D4 || BACKLIGHT_PIN == D5)
-  #define HARDWARE_PWM
-  #define ICRx            ICR1
-  #define TCCRxA          TCCR1A
-  #define TCCRxB          TCCR1B
-  #define TIMERx_OVF_vect TIMER1_OVF_vect
-  #define TIMSKx          TIMSK
-  #define TOIEx           TOIE1
-
-  #if BACKLIGHT_PIN == D4
-    #define COMxx1        COM1B1
-    #define OCRxx         OCR1B
-  #elif BACKLIGHT_PIN == D5
-    #define COMxx1        COM1A1
-    #define OCRxx         OCR1A
-  #endif
-#else
-  #if !defined(BACKLIGHT_CUSTOM_DRIVER)
-    #if !defined(B5_AUDIO) && !defined(B6_AUDIO) && !defined(B7_AUDIO)
-      // Timer 1 is not in use by Audio feature, Backlight can use it
-      #pragma message "Using hardware timer 1 with software PWM"
-      #define HARDWARE_PWM
-      #define BACKLIGHT_PWM_TIMER
-      #define ICRx              ICR1
-      #define TCCRxA            TCCR1A
-      #define TCCRxB            TCCR1B
-      #define TIMERx_COMPA_vect TIMER1_COMPA_vect
-      #define TIMERx_OVF_vect   TIMER1_OVF_vect
-      #if defined(__AVR_ATmega32A__) // This MCU has only one TIMSK register
-        #define TIMSKx          TIMSK
-      #else
-        #define TIMSKx          TIMSK1
-      #endif
-      #define TOIEx             TOIE1
-
-      #define OCIExA            OCIE1A
-      #define OCRxx             OCR1A
-    #elif !defined(C6_AUDIO) && !defined(C5_AUDIO) && !defined(C4_AUDIO)
-      #pragma message "Using hardware timer 3 with software PWM"
-      // Timer 3 is not in use by Audio feature, Backlight can use it
-      #define HARDWARE_PWM
-      #define BACKLIGHT_PWM_TIMER
-      #define ICRx              ICR1
-      #define TCCRxA            TCCR3A
-      #define TCCRxB            TCCR3B
-      #define TIMERx_COMPA_vect TIMER3_COMPA_vect
-      #define TIMERx_OVF_vect   TIMER3_OVF_vect
-      #define TIMSKx            TIMSK3
-      #define TOIEx             TOIE3
-
-      #define OCIExA            OCIE3A
-      #define OCRxx             OCR3A
-    #else
-      #pragma message "Audio in use - using pure software PWM"
-      #define NO_HARDWARE_PWM
-    #endif
-  #else
-    #pragma message "Custom driver defined - using pure software PWM"
-    #define NO_HARDWARE_PWM
-  #endif
-#endif
-
-#ifndef BACKLIGHT_ON_STATE
-#define BACKLIGHT_ON_STATE 0
-#endif
+#    if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) && (BACKLIGHT_PIN == B5 || BACKLIGHT_PIN == B6 || BACKLIGHT_PIN == B7)
+#        define HARDWARE_PWM
+#        define ICRx ICR1
+#        define TCCRxA TCCR1A
+#        define TCCRxB TCCR1B
+#        define TIMERx_OVF_vect TIMER1_OVF_vect
+#        define TIMSKx TIMSK1
+#        define TOIEx TOIE1
+
+#        if BACKLIGHT_PIN == B5
+#            define COMxx1 COM1A1
+#            define OCRxx OCR1A
+#        elif BACKLIGHT_PIN == B6
+#            define COMxx1 COM1B1
+#            define OCRxx OCR1B
+#        elif BACKLIGHT_PIN == B7
+#            define COMxx1 COM1C1
+#            define OCRxx OCR1C
+#        endif
+#    elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) && (BACKLIGHT_PIN == C4 || BACKLIGHT_PIN == C5 || BACKLIGHT_PIN == C6)
+#        define HARDWARE_PWM
+#        define ICRx ICR3
+#        define TCCRxA TCCR3A
+#        define TCCRxB TCCR3B
+#        define TIMERx_OVF_vect TIMER3_OVF_vect
+#        define TIMSKx TIMSK3
+#        define TOIEx TOIE3
+
+#        if BACKLIGHT_PIN == C4
+#            if (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
+#                error This MCU has no C4 pin!
+#            else
+#                define COMxx1 COM3C1
+#                define OCRxx OCR3C
+#            endif
+#        elif BACKLIGHT_PIN == C5
+#            if (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
+#                error This MCU has no C5 pin!
+#            else
+#                define COMxx1 COM3B1
+#                define OCRxx OCR3B
+#            endif
+#        elif BACKLIGHT_PIN == C6
+#            define COMxx1 COM3A1
+#            define OCRxx OCR3A
+#        endif
+#    elif (defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__)) && (BACKLIGHT_PIN == B7 || BACKLIGHT_PIN == C5 || BACKLIGHT_PIN == C6)
+#        define HARDWARE_PWM
+#        define ICRx ICR1
+#        define TCCRxA TCCR1A
+#        define TCCRxB TCCR1B
+#        define TIMERx_OVF_vect TIMER1_OVF_vect
+#        define TIMSKx TIMSK1
+#        define TOIEx TOIE1
+
+#        if BACKLIGHT_PIN == B7
+#            define COMxx1 COM1C1
+#            define OCRxx OCR1C
+#        elif BACKLIGHT_PIN == C5
+#            define COMxx1 COM1B1
+#            define OCRxx OCR1B
+#        elif BACKLIGHT_PIN == C6
+#            define COMxx1 COM1A1
+#            define OCRxx OCR1A
+#        endif
+#    elif defined(__AVR_ATmega32A__) && (BACKLIGHT_PIN == D4 || BACKLIGHT_PIN == D5)
+#        define HARDWARE_PWM
+#        define ICRx ICR1
+#        define TCCRxA TCCR1A
+#        define TCCRxB TCCR1B
+#        define TIMERx_OVF_vect TIMER1_OVF_vect
+#        define TIMSKx TIMSK
+#        define TOIEx TOIE1
+
+#        if BACKLIGHT_PIN == D4
+#            define COMxx1 COM1B1
+#            define OCRxx OCR1B
+#        elif BACKLIGHT_PIN == D5
+#            define COMxx1 COM1A1
+#            define OCRxx OCR1A
+#        endif
+#    else
+#        if !defined(BACKLIGHT_CUSTOM_DRIVER)
+#            if !defined(B5_AUDIO) && !defined(B6_AUDIO) && !defined(B7_AUDIO)
+// Timer 1 is not in use by Audio feature, Backlight can use it
+#                pragma message "Using hardware timer 1 with software PWM"
+#                define HARDWARE_PWM
+#                define BACKLIGHT_PWM_TIMER
+#                define ICRx ICR1
+#                define TCCRxA TCCR1A
+#                define TCCRxB TCCR1B
+#                define TIMERx_COMPA_vect TIMER1_COMPA_vect
+#                define TIMERx_OVF_vect TIMER1_OVF_vect
+#                if defined(__AVR_ATmega32A__)  // This MCU has only one TIMSK register
+#                    define TIMSKx TIMSK
+#                else
+#                    define TIMSKx TIMSK1
+#                endif
+#                define TOIEx TOIE1
+
+#                define OCIExA OCIE1A
+#                define OCRxx OCR1A
+#            elif !defined(C6_AUDIO) && !defined(C5_AUDIO) && !defined(C4_AUDIO)
+#                pragma message "Using hardware timer 3 with software PWM"
+// Timer 3 is not in use by Audio feature, Backlight can use it
+#                define HARDWARE_PWM
+#                define BACKLIGHT_PWM_TIMER
+#                define ICRx ICR1
+#                define TCCRxA TCCR3A
+#                define TCCRxB TCCR3B
+#                define TIMERx_COMPA_vect TIMER3_COMPA_vect
+#                define TIMERx_OVF_vect TIMER3_OVF_vect
+#                define TIMSKx TIMSK3
+#                define TOIEx TOIE3
+
+#                define OCIExA OCIE3A
+#                define OCRxx OCR3A
+#            else
+#                pragma message "Audio in use - using pure software PWM"
+#                define NO_HARDWARE_PWM
+#            endif
+#        else
+#            pragma message "Custom driver defined - using pure software PWM"
+#            define NO_HARDWARE_PWM
+#        endif
+#    endif
+
+#    ifndef BACKLIGHT_ON_STATE
+#        define BACKLIGHT_ON_STATE 0
+#    endif
 
 void backlight_on(uint8_t backlight_pin) {
-#if BACKLIGHT_ON_STATE == 0
-  writePinLow(backlight_pin);
-#else
-  writePinHigh(backlight_pin);
-#endif
+#    if BACKLIGHT_ON_STATE == 0
+    writePinLow(backlight_pin);
+#    else
+    writePinHigh(backlight_pin);
+#    endif
 }
 
 void backlight_off(uint8_t backlight_pin) {
-#if BACKLIGHT_ON_STATE == 0
-  writePinHigh(backlight_pin);
-#else
-  writePinLow(backlight_pin);
-#endif
+#    if BACKLIGHT_ON_STATE == 0
+    writePinHigh(backlight_pin);
+#    else
+    writePinLow(backlight_pin);
+#    endif
 }
 
-
-#if defined(NO_HARDWARE_PWM) || defined(BACKLIGHT_PWM_TIMER)  // pwm through software
+#    if defined(NO_HARDWARE_PWM) || defined(BACKLIGHT_PWM_TIMER)  // pwm through software
 
 // we support multiple backlight pins
-#ifndef BACKLIGHT_LED_COUNT
-#define BACKLIGHT_LED_COUNT 1
-#endif
-
-#if BACKLIGHT_LED_COUNT == 1
-#define BACKLIGHT_PIN_INIT { BACKLIGHT_PIN }
-#else
-#define BACKLIGHT_PIN_INIT BACKLIGHT_PINS
-#endif
-
-#define FOR_EACH_LED(x) \
-  for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) \
-  { \
-    uint8_t backlight_pin = backlight_pins[i]; \
-    { \
-      x \
-    } \
-  }
+#        ifndef BACKLIGHT_LED_COUNT
+#            define BACKLIGHT_LED_COUNT 1
+#        endif
+
+#        if BACKLIGHT_LED_COUNT == 1
+#            define BACKLIGHT_PIN_INIT \
+                { BACKLIGHT_PIN }
+#        else
+#            define BACKLIGHT_PIN_INIT BACKLIGHT_PINS
+#        endif
+
+#        define FOR_EACH_LED(x)                                 \
+            for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \
+                uint8_t backlight_pin = backlight_pins[i];      \
+                { x }                                           \
+            }
 
 static const uint8_t backlight_pins[BACKLIGHT_LED_COUNT] = BACKLIGHT_PIN_INIT;
 
-#else // full hardware PWM
+#    else  // full hardware PWM
 
 // we support only one backlight pin
 static const uint8_t backlight_pin = BACKLIGHT_PIN;
-#define FOR_EACH_LED(x) x
+#        define FOR_EACH_LED(x) x
 
-#endif
+#    endif
 
-#ifdef NO_HARDWARE_PWM
-__attribute__((weak))
-void backlight_init_ports(void)
-{
-  // Setup backlight pin as output and output to on state.
-  FOR_EACH_LED(
-    setPinOutput(backlight_pin);
-    backlight_on(backlight_pin);
-  )
-
-  #ifdef BACKLIGHT_BREATHING
-  if (is_backlight_breathing()) {
-    breathing_enable();
-  }
-  #endif
+#    ifdef NO_HARDWARE_PWM
+__attribute__((weak)) void backlight_init_ports(void) {
+    // Setup backlight pin as output and output to on state.
+    FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);)
+
+#        ifdef BACKLIGHT_BREATHING
+    if (is_backlight_breathing()) {
+        breathing_enable();
+    }
+#        endif
 }
 
-__attribute__ ((weak))
-void backlight_set(uint8_t level) {}
+__attribute__((weak)) void backlight_set(uint8_t level) {}
 
 uint8_t backlight_tick = 0;
 
-#ifndef BACKLIGHT_CUSTOM_DRIVER
+#        ifndef BACKLIGHT_CUSTOM_DRIVER
 void backlight_task(void) {
-  if ((0xFFFF >> ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) {
-    FOR_EACH_LED(
-      backlight_on(backlight_pin);
-    )
-  }
-  else {
-    FOR_EACH_LED(
-      backlight_off(backlight_pin);
-    )
-  }
-  backlight_tick = (backlight_tick + 1) % 16;
+    if ((0xFFFF >> ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) {
+        FOR_EACH_LED(backlight_on(backlight_pin);)
+    } else {
+        FOR_EACH_LED(backlight_off(backlight_pin);)
+    }
+    backlight_tick = (backlight_tick + 1) % 16;
 }
-#endif
+#        endif
 
-#ifdef BACKLIGHT_BREATHING
-  #ifndef BACKLIGHT_CUSTOM_DRIVER
-  #error "Backlight breathing only available with hardware PWM. Please disable."
-  #endif
-#endif
+#        ifdef BACKLIGHT_BREATHING
+#            ifndef BACKLIGHT_CUSTOM_DRIVER
+#                error "Backlight breathing only available with hardware PWM. Please disable."
+#            endif
+#        endif
 
-#else // hardware pwm through timer
+#    else  // hardware pwm through timer
 
-#ifdef BACKLIGHT_PWM_TIMER
+#        ifdef BACKLIGHT_PWM_TIMER
 
 // The idea of software PWM assisted by hardware timers is the following
 // we use the hardware timer in fast PWM mode like for hardware PWM, but
@@ -1334,189 +1243,177 @@ void backlight_task(void) {
 // The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz.
 
 // Triggered when the counter reaches the OCRx value
-ISR(TIMERx_COMPA_vect) {
-  FOR_EACH_LED(
-    backlight_off(backlight_pin);
-  )
-}
+ISR(TIMERx_COMPA_vect) { FOR_EACH_LED(backlight_off(backlight_pin);) }
 
 // Triggered when the counter reaches the TOP value
 // this one triggers at F_CPU/65536 =~ 244 Hz
 ISR(TIMERx_OVF_vect) {
-#ifdef BACKLIGHT_BREATHING
-  if(is_breathing()) {
-    breathing_task();
-  }
-#endif
-  // for very small values of OCRxx (or backlight level)
-  // we can't guarantee this whole code won't execute
-  // at the same time as the compare match interrupt
-  // which means that we might turn on the leds while
-  // trying to turn them off, leading to flickering
-  // artifacts (especially while breathing, because breathing_task
-  // takes many computation cycles).
-  // so better not turn them on while the counter TOP is very low.
-  if (OCRxx > 256) {
-    FOR_EACH_LED(
-      backlight_on(backlight_pin);
-    )
-  }
+#            ifdef BACKLIGHT_BREATHING
+    if (is_breathing()) {
+        breathing_task();
+    }
+#            endif
+    // for very small values of OCRxx (or backlight level)
+    // we can't guarantee this whole code won't execute
+    // at the same time as the compare match interrupt
+    // which means that we might turn on the leds while
+    // trying to turn them off, leading to flickering
+    // artifacts (especially while breathing, because breathing_task
+    // takes many computation cycles).
+    // so better not turn them on while the counter TOP is very low.
+    if (OCRxx > 256) {
+        FOR_EACH_LED(backlight_on(backlight_pin);)
+    }
 }
 
-#endif
+#        endif
 
-#define TIMER_TOP 0xFFFFU
+#        define TIMER_TOP 0xFFFFU
 
 // See http://jared.geek.nz/2013/feb/linear-led-pwm
 static uint16_t cie_lightness(uint16_t v) {
-  if (v <= 5243) // if below 8% of max
-    return v / 9; // same as dividing by 900%
-  else {
-    uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare
-    // to get a useful result with integer division, we shift left in the expression above
-    // and revert what we've done again after squaring.
-    y = y * y * y >> 8;
-    if (y > 0xFFFFUL) // prevent overflow
-      return 0xFFFFU;
-    else
-      return (uint16_t) y;
-  }
+    if (v <= 5243)     // if below 8% of max
+        return v / 9;  // same as dividing by 900%
+    else {
+        uint32_t y = (((uint32_t)v + 10486) << 8) / (10486 + 0xFFFFUL);  // add 16% of max and compare
+        // to get a useful result with integer division, we shift left in the expression above
+        // and revert what we've done again after squaring.
+        y = y * y * y >> 8;
+        if (y > 0xFFFFUL)  // prevent overflow
+            return 0xFFFFU;
+        else
+            return (uint16_t)y;
+    }
 }
 
 // range for val is [0..TIMER_TOP]. PWM pin is high while the timer count is below val.
-static inline void set_pwm(uint16_t val) {
-  OCRxx = val;
-}
-
-#ifndef BACKLIGHT_CUSTOM_DRIVER
-__attribute__ ((weak))
-void backlight_set(uint8_t level) {
-  if (level > BACKLIGHT_LEVELS)
-    level = BACKLIGHT_LEVELS;
-
-  if (level == 0) {
-    #ifdef BACKLIGHT_PWM_TIMER
-      if (OCRxx) {
-        TIMSKx &= ~(_BV(OCIExA));
-        TIMSKx &= ~(_BV(TOIEx));
-        FOR_EACH_LED(
-          backlight_off(backlight_pin);
-        )
-      }
-    #else
-    // Turn off PWM control on backlight pin
-    TCCRxA &= ~(_BV(COMxx1));
-    #endif
-  } else {
-    #ifdef BACKLIGHT_PWM_TIMER
-      if (!OCRxx) {
-        TIMSKx |= _BV(OCIExA);
-        TIMSKx |= _BV(TOIEx);
-      }
-    #else
-    // Turn on PWM control of backlight pin
-    TCCRxA |= _BV(COMxx1);
-    #endif
-  }
-  // Set the brightness
-  set_pwm(cie_lightness(TIMER_TOP * (uint32_t)level / BACKLIGHT_LEVELS));
+static inline void set_pwm(uint16_t val) { OCRxx = val; }
+
+#        ifndef BACKLIGHT_CUSTOM_DRIVER
+__attribute__((weak)) void backlight_set(uint8_t level) {
+    if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS;
+
+    if (level == 0) {
+#            ifdef BACKLIGHT_PWM_TIMER
+        if (OCRxx) {
+            TIMSKx &= ~(_BV(OCIExA));
+            TIMSKx &= ~(_BV(TOIEx));
+            FOR_EACH_LED(backlight_off(backlight_pin);)
+        }
+#            else
+        // Turn off PWM control on backlight pin
+        TCCRxA &= ~(_BV(COMxx1));
+#            endif
+    } else {
+#            ifdef BACKLIGHT_PWM_TIMER
+        if (!OCRxx) {
+            TIMSKx |= _BV(OCIExA);
+            TIMSKx |= _BV(TOIEx);
+        }
+#            else
+        // Turn on PWM control of backlight pin
+        TCCRxA |= _BV(COMxx1);
+#            endif
+    }
+    // Set the brightness
+    set_pwm(cie_lightness(TIMER_TOP * (uint32_t)level / BACKLIGHT_LEVELS));
 }
 
 void backlight_task(void) {}
-#endif  // BACKLIGHT_CUSTOM_DRIVER
+#        endif  // BACKLIGHT_CUSTOM_DRIVER
 
-#ifdef BACKLIGHT_BREATHING
+#        ifdef BACKLIGHT_BREATHING
 
-#define BREATHING_NO_HALT  0
-#define BREATHING_HALT_OFF 1
-#define BREATHING_HALT_ON  2
-#define BREATHING_STEPS 128
+#            define BREATHING_NO_HALT 0
+#            define BREATHING_HALT_OFF 1
+#            define BREATHING_HALT_ON 2
+#            define BREATHING_STEPS 128
 
 static uint8_t breathing_period = BREATHING_PERIOD;
 static uint8_t breathing_halt = BREATHING_NO_HALT;
 static uint16_t breathing_counter = 0;
 
-#ifdef BACKLIGHT_PWM_TIMER
+#            ifdef BACKLIGHT_PWM_TIMER
 static bool breathing = false;
 
-bool is_breathing(void) {
-  return breathing;
-}
-
-#define breathing_interrupt_enable() do { breathing = true; } while (0)
-#define breathing_interrupt_disable() do { breathing = false; } while (0)
-#else
-
-bool is_breathing(void) {
-    return !!(TIMSKx & _BV(TOIEx));
-}
-
-#define breathing_interrupt_enable() do {TIMSKx |= _BV(TOIEx);} while (0)
-#define breathing_interrupt_disable() do {TIMSKx &= ~_BV(TOIEx);} while (0)
-#endif
-
-#define breathing_min() do {breathing_counter = 0;} while (0)
-#define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0)
-
-void breathing_enable(void)
-{
-  breathing_counter = 0;
-  breathing_halt = BREATHING_NO_HALT;
-  breathing_interrupt_enable();
+bool is_breathing(void) { return breathing; }
+
+#                define breathing_interrupt_enable() \
+                    do {                             \
+                        breathing = true;            \
+                    } while (0)
+#                define breathing_interrupt_disable() \
+                    do {                              \
+                        breathing = false;            \
+                    } while (0)
+#            else
+
+bool is_breathing(void) { return !!(TIMSKx & _BV(TOIEx)); }
+
+#                define breathing_interrupt_enable() \
+                    do {                             \
+                        TIMSKx |= _BV(TOIEx);        \
+                    } while (0)
+#                define breathing_interrupt_disable() \
+                    do {                              \
+                        TIMSKx &= ~_BV(TOIEx);        \
+                    } while (0)
+#            endif
+
+#            define breathing_min()        \
+                do {                       \
+                    breathing_counter = 0; \
+                } while (0)
+#            define breathing_max()                                 \
+                do {                                                \
+                    breathing_counter = breathing_period * 244 / 2; \
+                } while (0)
+
+void breathing_enable(void) {
+    breathing_counter = 0;
+    breathing_halt = BREATHING_NO_HALT;
+    breathing_interrupt_enable();
 }
 
-void breathing_pulse(void)
-{
+void breathing_pulse(void) {
     if (get_backlight_level() == 0)
-      breathing_min();
+        breathing_min();
     else
-      breathing_max();
+        breathing_max();
     breathing_halt = BREATHING_HALT_ON;
     breathing_interrupt_enable();
 }
 
-void breathing_disable(void)
-{
+void breathing_disable(void) {
     breathing_interrupt_disable();
     // Restore backlight level
     backlight_set(get_backlight_level());
 }
 
-void breathing_self_disable(void)
-{
-  if (get_backlight_level() == 0)
-    breathing_halt = BREATHING_HALT_OFF;
-  else
-    breathing_halt = BREATHING_HALT_ON;
+void breathing_self_disable(void) {
+    if (get_backlight_level() == 0)
+        breathing_halt = BREATHING_HALT_OFF;
+    else
+        breathing_halt = BREATHING_HALT_ON;
 }
 
 void breathing_toggle(void) {
-  if (is_breathing())
-    breathing_disable();
-  else
-    breathing_enable();
+    if (is_breathing())
+        breathing_disable();
+    else
+        breathing_enable();
 }
 
-void breathing_period_set(uint8_t value)
-{
-  if (!value)
-    value = 1;
-  breathing_period = value;
+void breathing_period_set(uint8_t value) {
+    if (!value) value = 1;
+    breathing_period = value;
 }
 
-void breathing_period_default(void) {
-  breathing_period_set(BREATHING_PERIOD);
-}
+void breathing_period_default(void) { breathing_period_set(BREATHING_PERIOD); }
 
-void breathing_period_inc(void)
-{
-  breathing_period_set(breathing_period+1);
-}
+void breathing_period_inc(void) { breathing_period_set(breathing_period + 1); }
 
-void breathing_period_dec(void)
-{
-  breathing_period_set(breathing_period-1);
-}
+void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); }
 
 /* To generate breathing curve in python:
  * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
@@ -1524,100 +1421,88 @@ void breathing_period_dec(void)
 static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
 // Use this before the cie_lightness function.
-static inline uint16_t scale_backlight(uint16_t v) {
-  return v / BACKLIGHT_LEVELS * get_backlight_level();
-}
+static inline uint16_t scale_backlight(uint16_t v) { return v / BACKLIGHT_LEVELS * get_backlight_level(); }
 
-#ifdef BACKLIGHT_PWM_TIMER
+#            ifdef BACKLIGHT_PWM_TIMER
 void breathing_task(void)
-#else
+#            else
 /* Assuming a 16MHz CPU clock and a timer that resets at 64k (ICR1), the following interrupt handler will run
  * about 244 times per second.
  */
 ISR(TIMERx_OVF_vect)
-#endif
+#            endif
 {
-  uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS;
-  // resetting after one period to prevent ugly reset at overflow.
-  breathing_counter = (breathing_counter + 1) % (breathing_period * 244);
-  uint8_t index = breathing_counter / interval % BREATHING_STEPS;
-
-  if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) ||
-      ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1)))
-  {
-      breathing_interrupt_disable();
-  }
-
-  set_pwm(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U)));
-}
+    uint16_t interval = (uint16_t)breathing_period * 244 / BREATHING_STEPS;
+    // resetting after one period to prevent ugly reset at overflow.
+    breathing_counter = (breathing_counter + 1) % (breathing_period * 244);
+    uint8_t index = breathing_counter / interval % BREATHING_STEPS;
 
-#endif // BACKLIGHT_BREATHING
+    if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) {
+        breathing_interrupt_disable();
+    }
 
-__attribute__ ((weak))
-void backlight_init_ports(void)
-{
-  // Setup backlight pin as output and output to on state.
-  FOR_EACH_LED(
-    setPinOutput(backlight_pin);
-    backlight_on(backlight_pin);
-  )
-
-  // I could write a wall of text here to explain... but TL;DW
-  // Go read the ATmega32u4 datasheet.
-  // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
-
-#ifdef BACKLIGHT_PWM_TIMER
-  // TimerX setup, Fast PWM mode count to TOP set in ICRx
-  TCCRxA = _BV(WGM11); // = 0b00000010;
-  // clock select clk/1
-  TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
-#else // hardware PWM
-  // Pin PB7 = OCR1C (Timer 1, Channel C)
-  // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
-  // (i.e. start high, go low when counter matches.)
-  // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
-  // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
-
-  /*
-  14.8.3:
-  "In fast PWM mode, the compare units allow generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to two will produce a non-inverted PWM [..]."
-  "In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGMn3:0 = 5, 6, or 7), the value in ICRn (WGMn3:0 = 14), or the value in OCRnA (WGMn3:0 = 15)."
-  */
-  TCCRxA = _BV(COMxx1) | _BV(WGM11);            // = 0b00001010;
-  TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
-#endif
-  // Use full 16-bit resolution. Counter counts to ICR1 before reset to 0.
-  ICRx = TIMER_TOP;
-
-  backlight_init();
-  #ifdef BACKLIGHT_BREATHING
+    set_pwm(cie_lightness(scale_backlight((uint16_t)pgm_read_byte(&breathing_table[index]) * 0x0101U)));
+}
+
+#        endif  // BACKLIGHT_BREATHING
+
+__attribute__((weak)) void backlight_init_ports(void) {
+    // Setup backlight pin as output and output to on state.
+    FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);)
+
+    // I could write a wall of text here to explain... but TL;DW
+    // Go read the ATmega32u4 datasheet.
+    // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
+
+#        ifdef BACKLIGHT_PWM_TIMER
+    // TimerX setup, Fast PWM mode count to TOP set in ICRx
+    TCCRxA = _BV(WGM11);  // = 0b00000010;
+    // clock select clk/1
+    TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10);  // = 0b00011001;
+#        else  // hardware PWM
+    // Pin PB7 = OCR1C (Timer 1, Channel C)
+    // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
+    // (i.e. start high, go low when counter matches.)
+    // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
+    // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
+
+    /*
+    14.8.3:
+    "In fast PWM mode, the compare units allow generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to two will produce a non-inverted PWM [..]."
+    "In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGMn3:0 = 5, 6, or 7), the value in ICRn (WGMn3:0 = 14), or the value in OCRnA (WGMn3:0 = 15)."
+    */
+    TCCRxA = _BV(COMxx1) | _BV(WGM11);             // = 0b00001010;
+    TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10);  // = 0b00011001;
+#        endif
+    // Use full 16-bit resolution. Counter counts to ICR1 before reset to 0.
+    ICRx = TIMER_TOP;
+
+    backlight_init();
+#        ifdef BACKLIGHT_BREATHING
     if (is_backlight_breathing()) {
-      breathing_enable();
+        breathing_enable();
     }
-  #endif
+#        endif
 }
 
-#endif // hardware backlight
+#    endif  // hardware backlight
 
-#else // no backlight
+#else  // no backlight
 
-__attribute__ ((weak))
-void backlight_init_ports(void) {}
+__attribute__((weak)) void backlight_init_ports(void) {}
 
-__attribute__ ((weak))
-void backlight_set(uint8_t level) {}
+__attribute__((weak)) void backlight_set(uint8_t level) {}
 
-#endif // backlight
+#endif  // backlight
 
 #ifdef HD44780_ENABLED
-#include "hd44780.h"
+#    include "hd44780.h"
 #endif
 
-
 // Functions for spitting out values
 //
 
-void send_dword(uint32_t number) { // this might not actually work
+void send_dword(uint32_t number) {  // this might not actually work
     uint16_t word = (number >> 16);
     send_word(word);
     send_word(number & 0xFFFFUL);
@@ -1652,18 +1537,15 @@ void send_nibble(uint8_t number) {
     }
 }
 
-
-__attribute__((weak))
-uint16_t hex_to_keycode(uint8_t hex)
-{
-  hex = hex & 0xF;
-  if (hex == 0x0) {
-    return KC_0;
-  } else if (hex < 0xA) {
-    return KC_1 + (hex - 0x1);
-  } else {
-    return KC_A + (hex - 0xA);
-  }
+__attribute__((weak)) uint16_t hex_to_keycode(uint8_t hex) {
+    hex = hex & 0xF;
+    if (hex == 0x0) {
+        return KC_0;
+    } else if (hex < 0xA) {
+        return KC_1 + (hex - 0x1);
+    } else {
+        return KC_A + (hex - 0xA);
+    }
 }
 
 void api_send_unicode(uint32_t unicode) {
@@ -1674,55 +1556,40 @@ void api_send_unicode(uint32_t unicode) {
 #endif
 }
 
-__attribute__ ((weak))
-void led_set_user(uint8_t usb_led) {
+__attribute__((weak)) void led_set_user(uint8_t usb_led) {}
 
-}
+__attribute__((weak)) void led_set_kb(uint8_t usb_led) { led_set_user(usb_led); }
 
-__attribute__ ((weak))
-void led_set_kb(uint8_t usb_led) {
-    led_set_user(usb_led);
-}
+__attribute__((weak)) void led_init_ports(void) {}
 
-__attribute__ ((weak))
-void led_init_ports(void)
-{
-
-}
-
-__attribute__ ((weak))
-void led_set(uint8_t usb_led)
-{
+__attribute__((weak)) void led_set(uint8_t usb_led) {
 #if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
-  // Use backlight as Caps Lock indicator
-  uint8_t bl_toggle_lvl = 0;
-
-  if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK) && !backlight_config.enable) {
-    // Turning Caps Lock ON and backlight is disabled in config
-    // Toggling backlight to the brightest level
-    bl_toggle_lvl = BACKLIGHT_LEVELS;
-  } else if (IS_LED_OFF(usb_led, USB_LED_CAPS_LOCK) && backlight_config.enable) {
-    // Turning Caps Lock OFF and backlight is enabled in config
-    // Toggling backlight and restoring config level
-    bl_toggle_lvl = backlight_config.level;
-  }
+    // Use backlight as Caps Lock indicator
+    uint8_t bl_toggle_lvl = 0;
+
+    if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK) && !backlight_config.enable) {
+        // Turning Caps Lock ON and backlight is disabled in config
+        // Toggling backlight to the brightest level
+        bl_toggle_lvl = BACKLIGHT_LEVELS;
+    } else if (IS_LED_OFF(usb_led, USB_LED_CAPS_LOCK) && backlight_config.enable) {
+        // Turning Caps Lock OFF and backlight is enabled in config
+        // Toggling backlight and restoring config level
+        bl_toggle_lvl = backlight_config.level;
+    }
 
-  // Set level without modify backlight_config to keep ability to restore state
-  backlight_set(bl_toggle_lvl);
+    // Set level without modify backlight_config to keep ability to restore state
+    backlight_set(bl_toggle_lvl);
 #endif
 
-  led_set_kb(usb_led);
+    led_set_kb(usb_led);
 }
 
-
 //------------------------------------------------------------------------------
 // Override these functions in your keymap file to play different tunes on
 // different events such as startup and bootloader jump
 
-__attribute__ ((weak))
-void startup_user() {}
+__attribute__((weak)) void startup_user() {}
 
-__attribute__ ((weak))
-void shutdown_user() {}
+__attribute__((weak)) void shutdown_user() {}
 
 //------------------------------------------------------------------------------
index 2cb26d4f4610d59bf2208da612fab3f6b321fc58..066113590ef60a93aa1cd447339232a4087f804d 100644 (file)
 #pragma once
 
 #if defined(__AVR__)
-    #include <avr/pgmspace.h>
-    #include <avr/io.h>
-    #include <avr/interrupt.h>
+#    include <avr/pgmspace.h>
+#    include <avr/io.h>
+#    include <avr/interrupt.h>
 #endif
 #if defined(PROTOCOL_CHIBIOS)
-    #include "hal.h"
+#    include "hal.h"
 #endif
 
 #include "wait.h"
 #include "keymap.h"
 
 #ifdef BACKLIGHT_ENABLE
-    #ifdef LED_MATRIX_ENABLE
-        #include "ledmatrix.h"
-    #else
-        #include "backlight.h"
-    #endif
+#    ifdef LED_MATRIX_ENABLE
+#        include "ledmatrix.h"
+#    else
+#        include "backlight.h"
+#    endif
 #endif
 
 #if defined(RGBLIGHT_ENABLE)
-    #include "rgblight.h"
+#    include "rgblight.h"
 #elif defined(RGB_MATRIX_ENABLE)
-    // Dummy define RGBLIGHT_MODE_xxxx
-    #define RGBLIGHT_H_DUMMY_DEFINE
-    #include "rgblight.h"
+// Dummy define RGBLIGHT_MODE_xxxx
+#    define RGBLIGHT_H_DUMMY_DEFINE
+#    include "rgblight.h"
 #endif
 
 #ifdef RGB_MATRIX_ENABLE
-    #include "rgb_matrix.h"
+#    include "rgb_matrix.h"
 #endif
 
 #include "action_layer.h"
 extern layer_state_t default_layer_state;
 
 #ifndef NO_ACTION_LAYER
-    extern layer_state_t layer_state;
+extern layer_state_t layer_state;
 #endif
 
 #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
-    #include "process_midi.h"
+#    include "process_midi.h"
 #endif
 
 #ifdef AUDIO_ENABLE
-    #include "audio.h"
-    #include "process_audio.h"
-    #ifdef AUDIO_CLICKY
-        #include "process_clicky.h"
-    #endif
+#    include "audio.h"
+#    include "process_audio.h"
+#    ifdef AUDIO_CLICKY
+#        include "process_clicky.h"
+#    endif
 #endif
 
 #ifdef STENO_ENABLE
-    #include "process_steno.h"
+#    include "process_steno.h"
 #endif
 
 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
-    #include "process_music.h"
+#    include "process_music.h"
 #endif
 
 #ifdef LEADER_ENABLE
-    #include "process_leader.h"
+#    include "process_leader.h"
 #endif
 
 #ifdef UNICODE_ENABLE
-    #include "process_unicode.h"
+#    include "process_unicode.h"
 #endif
 
 #ifdef UCIS_ENABLE
-    #include "process_ucis.h"
+#    include "process_ucis.h"
 #endif
 
 #ifdef UNICODEMAP_ENABLE
-    #include "process_unicodemap.h"
+#    include "process_unicodemap.h"
 #endif
 
 #ifdef TAP_DANCE_ENABLE
-    #include "process_tap_dance.h"
+#    include "process_tap_dance.h"
 #endif
 
 #ifdef PRINTING_ENABLE
-    #include "process_printer.h"
+#    include "process_printer.h"
 #endif
 
 #ifdef AUTO_SHIFT_ENABLE
-    #include "process_auto_shift.h"
+#    include "process_auto_shift.h"
 #endif
 
 #ifdef COMBO_ENABLE
-    #include "process_combo.h"
+#    include "process_combo.h"
 #endif
 
 #ifdef KEY_LOCK_ENABLE
-    #include "process_key_lock.h"
+#    include "process_key_lock.h"
 #endif
 
 #ifdef TERMINAL_ENABLE
-    #include "process_terminal.h"
+#    include "process_terminal.h"
 #else
-    #include "process_terminal_nop.h"
+#    include "process_terminal_nop.h"
 #endif
 
 #ifdef SPACE_CADET_ENABLE
-    #include "process_space_cadet.h"
+#    include "process_space_cadet.h"
 #endif
 
 #ifdef HD44780_ENABLE
-    #include "hd44780.h"
+#    include "hd44780.h"
 #endif
 
 #ifdef HAPTIC_ENABLE
-    #include "haptic.h"
+#    include "haptic.h"
 #endif
 
 #ifdef OLED_DRIVER_ENABLE
-    #include "oled_driver.h"
+#    include "oled_driver.h"
 #endif
 
 // Function substitutions to ease GPIO manipulation
 #if defined(__AVR__)
-    typedef uint8_t pin_t;
+typedef uint8_t pin_t;
 
-    #define setPinInput(pin)        (DDRx_ADDRESS(pin)  &= ~_BV((pin) & 0xF))
-    #define setPinInputHigh(pin)    (DDRx_ADDRESS(pin)  &= ~_BV((pin) & 0xF), \
-                                     PORTx_ADDRESS(pin) |=  _BV((pin) & 0xF))
-    #define setPinInputLow(pin)     _Static_assert(0, "AVR processors cannot implement an input as pull low")
-    #define setPinOutput(pin)       (DDRx_ADDRESS(pin)  |=  _BV((pin) & 0xF))
+#    define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF))
+#    define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
+#    define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low")
+#    define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
 
-    #define writePinHigh(pin)       (PORTx_ADDRESS(pin) |=  _BV((pin) & 0xF))
-    #define writePinLow(pin)        (PORTx_ADDRESS(pin) &= ~_BV((pin) & 0xF))
-    #define writePin(pin, level)    ((level) ? writePinHigh(pin) : writePinLow(pin))
+#    define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
+#    define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
+#    define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
 
-    #define readPin(pin)            ((bool)(PINx_ADDRESS(pin) & _BV((pin) & 0xF)))
+#    define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
 #elif defined(PROTOCOL_CHIBIOS)
-    typedef ioline_t pin_t;
+typedef ioline_t pin_t;
 
-    #define setPinInput(pin)        palSetLineMode(pin, PAL_MODE_INPUT)
-    #define setPinInputHigh(pin)    palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
-    #define setPinInputLow(pin)     palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
-    #define setPinOutput(pin)       palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
+#    define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
+#    define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
+#    define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
+#    define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
 
-    #define writePinHigh(pin)       palSetLine(pin)
-    #define writePinLow(pin)        palClearLine(pin)
-    #define writePin(pin, level)    ((level) ? writePinHigh(pin) : writePinLow(pin))
+#    define writePinHigh(pin) palSetLine(pin)
+#    define writePinLow(pin) palClearLine(pin)
+#    define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
 
-    #define readPin(pin)            palReadLine(pin)
+#    define readPin(pin) palReadLine(pin)
 #endif
 
 // Send string macros
 #define STRINGIZE(z) #z
-#define ADD_SLASH_X(y) STRINGIZE(\x ## y)
+#define ADD_SLASH_X(y) STRINGIZE(\x##y)
 #define SYMBOL_STR(x) ADD_SLASH_X(x)
 
 #define SS_TAP_CODE 1
@@ -200,8 +199,8 @@ extern layer_state_t default_layer_state;
 
 #define SEND_STRING(string) send_string_P(PSTR(string))
 
-extern const bool ascii_to_shift_lut[128];
-extern const bool ascii_to_altgr_lut[128];
+extern const bool    ascii_to_shift_lut[128];
+extern const bool    ascii_to_altgr_lut[128];
 extern const uint8_t ascii_to_keycode_lut[128];
 
 void send_string(const char *str);
@@ -211,31 +210,31 @@ void send_string_with_delay_P(const char *str, uint8_t interval);
 void send_char(char ascii_code);
 
 // For tri-layer
-void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
+void          update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
 layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
 
 void set_single_persistent_default_layer(uint8_t default_layer);
 
 void tap_random_base64(void);
 
-#define IS_LAYER_ON(layer)  (layer_state & (1UL << (layer)))
+#define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
 #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
 
-void matrix_init_kb(void);
-void matrix_scan_kb(void);
-void matrix_init_user(void);
-void matrix_scan_user(void);
+void     matrix_init_kb(void);
+void     matrix_scan_kb(void);
+void     matrix_init_user(void);
+void     matrix_scan_user(void);
 uint16_t get_record_keycode(keyrecord_t *record);
 uint16_t get_event_keycode(keyevent_t event);
-bool process_action_kb(keyrecord_t *record);
-bool process_record_kb(uint16_t keycode, keyrecord_t *record);
-bool process_record_user(uint16_t keycode, keyrecord_t *record);
+bool     process_action_kb(keyrecord_t *record);
+bool     process_record_kb(uint16_t keycode, keyrecord_t *record);
+bool     process_record_user(uint16_t keycode, keyrecord_t *record);
 
 #ifndef BOOTMAGIC_LITE_COLUMN
-    #define BOOTMAGIC_LITE_COLUMN 0
+#    define BOOTMAGIC_LITE_COLUMN 0
 #endif
 #ifndef BOOTMAGIC_LITE_ROW
-    #define BOOTMAGIC_LITE_ROW 0
+#    define BOOTMAGIC_LITE_ROW 0
 #endif
 
 void bootmagic_lite(void);
@@ -256,7 +255,7 @@ void backlight_task_internal(void);
 void backlight_on(uint8_t backlight_pin);
 void backlight_off(uint8_t backlight_pin);
 
-    #ifdef BACKLIGHT_BREATHING
+#    ifdef BACKLIGHT_BREATHING
 void breathing_task(void);
 void breathing_enable(void);
 void breathing_pulse(void);
@@ -270,13 +269,13 @@ void breathing_period_default(void);
 void breathing_period_set(uint8_t value);
 void breathing_period_inc(void);
 void breathing_period_dec(void);
-    #endif
+#    endif
 #endif
 
-void send_dword(uint32_t number);
-void send_word(uint16_t number);
-void send_byte(uint8_t number);
-void send_nibble(uint8_t number);
+void     send_dword(uint32_t number);
+void     send_word(uint16_t number);
+void     send_byte(uint8_t number);
+void     send_nibble(uint8_t number);
 uint16_t hex_to_keycode(uint8_t hex);
 
 void led_set_user(uint8_t usb_led);
index c112d76ba6ab17dc6825cc3fac94e35a53f6e1cb..f5dca02e6bf26f98141253e23a61302e76b66a86 100644 (file)
 #define QUANTUM_KEYCODES_H
 
 #ifndef MIDI_ENABLE_STRICT
-#define MIDI_ENABLE_STRICT 0
+#    define MIDI_ENABLE_STRICT 0
 #endif
 
 #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED))
-#ifndef MIDI_TONE_KEYCODE_OCTAVES
-#define MIDI_TONE_KEYCODE_OCTAVES 3
-#endif
+#    ifndef MIDI_TONE_KEYCODE_OCTAVES
+#        define MIDI_TONE_KEYCODE_OCTAVES 3
+#    endif
 #endif
 
 // Fillers to make layering more clear
 
 enum quantum_keycodes {
     // Ranges used in shortcuts - not to be used directly
-    QK_BASIC              = 0x0000,
-    QK_BASIC_MAX          = 0x00FF,
-    QK_MODS               = 0x0100,
-    QK_LCTL               = 0x0100,
-    QK_LSFT               = 0x0200,
-    QK_LALT               = 0x0400,
-    QK_LGUI               = 0x0800,
-    QK_RMODS_MIN          = 0x1000,
-    QK_RCTL               = 0x1100,
-    QK_RSFT               = 0x1200,
-    QK_RALT               = 0x1400,
-    QK_RGUI               = 0x1800,
-    QK_MODS_MAX           = 0x1FFF,
-    QK_FUNCTION           = 0x2000,
-    QK_FUNCTION_MAX       = 0x2FFF,
-    QK_MACRO              = 0x3000,
-    QK_MACRO_MAX          = 0x3FFF,
-    QK_LAYER_TAP          = 0x4000,
-    QK_LAYER_TAP_MAX      = 0x4FFF,
-    QK_TO                 = 0x5000,
-    QK_TO_MAX             = 0x50FF,
-    QK_MOMENTARY          = 0x5100,
-    QK_MOMENTARY_MAX      = 0x51FF,
-    QK_DEF_LAYER          = 0x5200,
-    QK_DEF_LAYER_MAX      = 0x52FF,
-    QK_TOGGLE_LAYER       = 0x5300,
-    QK_TOGGLE_LAYER_MAX   = 0x53FF,
-    QK_ONE_SHOT_LAYER     = 0x5400,
-    QK_ONE_SHOT_LAYER_MAX = 0x54FF,
-    QK_ONE_SHOT_MOD       = 0x5500,
-    QK_ONE_SHOT_MOD_MAX   = 0x55FF,
-    QK_TAP_DANCE          = 0x5700,
-    QK_TAP_DANCE_MAX      = 0x57FF,
-    QK_LAYER_TAP_TOGGLE   = 0x5800,
+    QK_BASIC                = 0x0000,
+    QK_BASIC_MAX            = 0x00FF,
+    QK_MODS                 = 0x0100,
+    QK_LCTL                 = 0x0100,
+    QK_LSFT                 = 0x0200,
+    QK_LALT                 = 0x0400,
+    QK_LGUI                 = 0x0800,
+    QK_RMODS_MIN            = 0x1000,
+    QK_RCTL                 = 0x1100,
+    QK_RSFT                 = 0x1200,
+    QK_RALT                 = 0x1400,
+    QK_RGUI                 = 0x1800,
+    QK_MODS_MAX             = 0x1FFF,
+    QK_FUNCTION             = 0x2000,
+    QK_FUNCTION_MAX         = 0x2FFF,
+    QK_MACRO                = 0x3000,
+    QK_MACRO_MAX            = 0x3FFF,
+    QK_LAYER_TAP            = 0x4000,
+    QK_LAYER_TAP_MAX        = 0x4FFF,
+    QK_TO                   = 0x5000,
+    QK_TO_MAX               = 0x50FF,
+    QK_MOMENTARY            = 0x5100,
+    QK_MOMENTARY_MAX        = 0x51FF,
+    QK_DEF_LAYER            = 0x5200,
+    QK_DEF_LAYER_MAX        = 0x52FF,
+    QK_TOGGLE_LAYER         = 0x5300,
+    QK_TOGGLE_LAYER_MAX     = 0x53FF,
+    QK_ONE_SHOT_LAYER       = 0x5400,
+    QK_ONE_SHOT_LAYER_MAX   = 0x54FF,
+    QK_ONE_SHOT_MOD         = 0x5500,
+    QK_ONE_SHOT_MOD_MAX     = 0x55FF,
+    QK_TAP_DANCE            = 0x5700,
+    QK_TAP_DANCE_MAX        = 0x57FF,
+    QK_LAYER_TAP_TOGGLE     = 0x5800,
     QK_LAYER_TAP_TOGGLE_MAX = 0x58FF,
-    QK_LAYER_MOD          = 0x5900,
-    QK_LAYER_MOD_MAX      = 0x59FF,
+    QK_LAYER_MOD            = 0x5900,
+    QK_LAYER_MOD_MAX        = 0x59FF,
 #ifdef STENO_ENABLE
-    QK_STENO              = 0x5A00,
-    QK_STENO_BOLT         = 0x5A30,
-    QK_STENO_GEMINI       = 0x5A31,
-    QK_STENO_MAX          = 0x5A3F,
+    QK_STENO        = 0x5A00,
+    QK_STENO_BOLT   = 0x5A30,
+    QK_STENO_GEMINI = 0x5A31,
+    QK_STENO_MAX    = 0x5A3F,
 #endif
 #ifdef SWAP_HANDS_ENABLE
-    QK_SWAP_HANDS         = 0x5B00,
-    QK_SWAP_HANDS_MAX     = 0x5BFF,
+    QK_SWAP_HANDS     = 0x5B00,
+    QK_SWAP_HANDS_MAX = 0x5BFF,
 #endif
-    QK_MOD_TAP            = 0x6000,
-    QK_MOD_TAP_MAX        = 0x7FFF,
+    QK_MOD_TAP     = 0x6000,
+    QK_MOD_TAP_MAX = 0x7FFF,
 #ifdef UNICODE_ENABLE
-    QK_UNICODE            = 0x8000,
-    QK_UNICODE_MAX        = 0xFFFF,
+    QK_UNICODE     = 0x8000,
+    QK_UNICODE_MAX = 0xFFFF,
 #endif
 #ifdef UNICODEMAP_ENABLE
-    QK_UNICODEMAP         = 0x8000,
-    QK_UNICODEMAP_MAX     = 0xBFFF,
-    QK_UNICODEMAP_PAIR    = 0xC000,
+    QK_UNICODEMAP          = 0x8000,
+    QK_UNICODEMAP_MAX      = 0xBFFF,
+    QK_UNICODEMAP_PAIR     = 0xC000,
     QK_UNICODEMAP_PAIR_MAX = 0xFFFF,
 #endif
 
@@ -118,7 +118,7 @@ enum quantum_keycodes {
     MAGIC_TOGGLE_ALT_GUI,
     GRAVE_ESC,
 
-    // Leader key
+// Leader key
 #ifdef LEADER_ENABLE
     KC_LEAD,
 #endif
@@ -144,7 +144,6 @@ enum quantum_keycodes {
     CLICKY_DOWN,
     CLICKY_RESET,
 
-
 #ifdef FAUXCLICKY_ENABLE
     // Faux clicky
     FC_ON,
@@ -164,7 +163,7 @@ enum quantum_keycodes {
     MUV_IN,
     MUV_DE,
 
-    // Midi
+// Midi
 #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
     MI_ON,
     MI_OFF,
@@ -174,7 +173,7 @@ enum quantum_keycodes {
 #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED))
     MIDI_TONE_MIN,
 
-#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 0
+#    if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 0
     MI_C = MIDI_TONE_MIN,
     MI_Cs,
     MI_Db = MI_Cs,
@@ -192,9 +191,9 @@ enum quantum_keycodes {
     MI_As,
     MI_Bb = MI_As,
     MI_B,
-#endif
+#    endif
 
-#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 1
+#    if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 1
     MI_C_1,
     MI_Cs_1,
     MI_Db_1 = MI_Cs_1,
@@ -212,9 +211,9 @@ enum quantum_keycodes {
     MI_As_1,
     MI_Bb_1 = MI_As_1,
     MI_B_1,
-#endif
+#    endif
 
-#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 2
+#    if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 2
     MI_C_2,
     MI_Cs_2,
     MI_Db_2 = MI_Cs_2,
@@ -232,9 +231,9 @@ enum quantum_keycodes {
     MI_As_2,
     MI_Bb_2 = MI_As_2,
     MI_B_2,
-#endif
+#    endif
 
-#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 3
+#    if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 3
     MI_C_3,
     MI_Cs_3,
     MI_Db_3 = MI_Cs_3,
@@ -252,9 +251,9 @@ enum quantum_keycodes {
     MI_As_3,
     MI_Bb_3 = MI_As_3,
     MI_B_3,
-#endif
+#    endif
 
-#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 4
+#    if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 4
     MI_C_4,
     MI_Cs_4,
     MI_Db_4 = MI_Cs_4,
@@ -272,9 +271,9 @@ enum quantum_keycodes {
     MI_As_4,
     MI_Bb_4 = MI_As_4,
     MI_B_4,
-#endif
+#    endif
 
-#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 5
+#    if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 5
     MI_C_5,
     MI_Cs_5,
     MI_Db_5 = MI_Cs_5,
@@ -292,21 +291,21 @@ enum quantum_keycodes {
     MI_As_5,
     MI_Bb_5 = MI_As_5,
     MI_B_5,
-#endif
+#    endif
 
-#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 5
+#    if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 5
     MIDI_TONE_MAX = MI_B_5,
-#elif MIDI_TONE_KEYCODE_OCTAVES > 4
+#    elif MIDI_TONE_KEYCODE_OCTAVES > 4
     MIDI_TONE_MAX = MI_B_4,
-#elif MIDI_TONE_KEYCODE_OCTAVES > 3
+#    elif MIDI_TONE_KEYCODE_OCTAVES > 3
     MIDI_TONE_MAX = MI_B_3,
-#elif MIDI_TONE_KEYCODE_OCTAVES > 2
+#    elif MIDI_TONE_KEYCODE_OCTAVES > 2
     MIDI_TONE_MAX = MI_B_2,
-#elif MIDI_TONE_KEYCODE_OCTAVES > 1
+#    elif MIDI_TONE_KEYCODE_OCTAVES > 1
     MIDI_TONE_MAX = MI_B_1,
-#elif MIDI_TONE_KEYCODE_OCTAVES > 0
+#    elif MIDI_TONE_KEYCODE_OCTAVES > 0
     MIDI_TONE_MAX = MI_B,
-#endif
+#    endif
 
     MIDI_OCTAVE_MIN,
     MI_OCT_N2 = MIDI_OCTAVE_MIN,
@@ -320,8 +319,8 @@ enum quantum_keycodes {
     MI_OCT_6,
     MI_OCT_7,
     MIDI_OCTAVE_MAX = MI_OCT_7,
-    MI_OCTD, // octave down
-    MI_OCTU, // octave up
+    MI_OCTD,  // octave down
+    MI_OCTU,  // octave up
 
     MIDI_TRANSPOSE_MIN,
     MI_TRNS_N6 = MIDI_TRANSPOSE_MIN,
@@ -338,8 +337,8 @@ enum quantum_keycodes {
     MI_TRNS_5,
     MI_TRNS_6,
     MIDI_TRANSPOSE_MAX = MI_TRNS_6,
-    MI_TRNSD, // transpose down
-    MI_TRNSU, // transpose up
+    MI_TRNSD,  // transpose down
+    MI_TRNSU,  // transpose up
 
     MIDI_VELOCITY_MIN,
     MI_VEL_1 = MIDI_VELOCITY_MIN,
@@ -353,8 +352,8 @@ enum quantum_keycodes {
     MI_VEL_9,
     MI_VEL_10,
     MIDI_VELOCITY_MAX = MI_VEL_10,
-    MI_VELD, // velocity down
-    MI_VELU, // velocity up
+    MI_VELD,  // velocity down
+    MI_VELU,  // velocity up
 
     MIDI_CHANNEL_MIN,
     MI_CH1 = MIDI_CHANNEL_MIN,
@@ -374,24 +373,24 @@ enum quantum_keycodes {
     MI_CH15,
     MI_CH16,
     MIDI_CHANNEL_MAX = MI_CH16,
-    MI_CHD, // previous channel
-    MI_CHU, // next channel
+    MI_CHD,  // previous channel
+    MI_CHU,  // next channel
 
-    MI_ALLOFF, // all notes off
+    MI_ALLOFF,  // all notes off
 
-    MI_SUS, // sustain
-    MI_PORT, // portamento
-    MI_SOST, // sostenuto
-    MI_SOFT, // soft pedal
-    MI_LEG,  // legato
+    MI_SUS,   // sustain
+    MI_PORT,  // portamento
+    MI_SOST,  // sostenuto
+    MI_SOFT,  // soft pedal
+    MI_LEG,   // legato
 
-    MI_MOD, // modulation
-    MI_MODSD, // decrease modulation speed
-    MI_MODSU, // increase modulation speed
+    MI_MOD,    // modulation
+    MI_MODSD,  // decrease modulation speed
+    MI_MODSU,  // increase modulation speed
 
-    MI_BENDD, // Bend down
-    MI_BENDU, // Bend up
-#endif // MIDI_ADVANCED
+    MI_BENDD,  // Bend down
+    MI_BENDU,  // Bend up
+#endif         // MIDI_ADVANCED
 
     // Backlight functionality
     BL_ON,
@@ -424,7 +423,7 @@ enum quantum_keycodes {
     RGB_MODE_GRADIENT,
     RGB_MODE_RGBTEST,
 
-    //Momentum matching toggle
+    // Momentum matching toggle
     VLK_TOG,
 
     // Left shift, open paren
@@ -492,7 +491,7 @@ enum quantum_keycodes {
     CMB_ON,
     CMB_OFF,
     CMB_TOG,
-  
+
     MAGIC_SWAP_LCTL_LGUI,
     MAGIC_SWAP_RCTL_RGUI,
     MAGIC_UNSWAP_LCTL_LGUI,
@@ -521,86 +520,86 @@ enum quantum_keycodes {
 #define RWIN(kc) RGUI(kc)
 
 #define HYPR(kc) (QK_LCTL | QK_LSFT | QK_LALT | QK_LGUI | (kc))
-#define MEH(kc)  (QK_LCTL | QK_LSFT | QK_LALT | (kc))
+#define MEH(kc) (QK_LCTL | QK_LSFT | QK_LALT | (kc))
 #define LCAG(kc) (QK_LCTL | QK_LALT | QK_LGUI | (kc))
 #define SGUI(kc) (QK_LGUI | QK_LSFT | (kc))
 #define SCMD(kc) SGUI(kc)
 #define SWIN(kc) SGUI(kc)
-#define LCA(kc)  (QK_LCTL | QK_LALT | (kc))
+#define LCA(kc) (QK_LCTL | QK_LALT | (kc))
 
 #define MOD_HYPR 0xF
-#define MOD_MEH  0x7
+#define MOD_MEH 0x7
 
 // Aliases for shifted symbols
 // Each key has a 4-letter code, and some have longer aliases too.
 // While the long aliases are descriptive, the 4-letter codes
 // make for nicer grid layouts (everything lines up), and are
 // the preferred style for Quantum.
-#define KC_TILD LSFT(KC_GRV)    // ~
-#define KC_TILDE    KC_TILD
+#define KC_TILD LSFT(KC_GRV)  // ~
+#define KC_TILDE KC_TILD
 
-#define KC_EXLM LSFT(KC_1)      // !
-#define KC_EXCLAIM  KC_EXLM
+#define KC_EXLM LSFT(KC_1)  // !
+#define KC_EXCLAIM KC_EXLM
 
-#define KC_AT   LSFT(KC_2)      // @
+#define KC_AT LSFT(KC_2)  // @
 
-#define KC_HASH LSFT(KC_3)      // #
+#define KC_HASH LSFT(KC_3)  // #
 
-#define KC_DLR  LSFT(KC_4)      // $
-#define KC_DOLLAR   KC_DLR
+#define KC_DLR LSFT(KC_4)  // $
+#define KC_DOLLAR KC_DLR
 
-#define KC_PERC LSFT(KC_5)      // %
-#define KC_PERCENT  KC_PERC
+#define KC_PERC LSFT(KC_5)  // %
+#define KC_PERCENT KC_PERC
 
-#define KC_CIRC LSFT(KC_6)      // ^
-#define KC_CIRCUMFLEX   KC_CIRC
+#define KC_CIRC LSFT(KC_6)  // ^
+#define KC_CIRCUMFLEX KC_CIRC
 
-#define KC_AMPR LSFT(KC_7)      // &
-#define KC_AMPERSAND    KC_AMPR
+#define KC_AMPR LSFT(KC_7)  // &
+#define KC_AMPERSAND KC_AMPR
 
-#define KC_ASTR LSFT(KC_8)      // *
+#define KC_ASTR LSFT(KC_8)  // *
 #define KC_ASTERISK KC_ASTR
 
-#define KC_LPRN LSFT(KC_9)      // (
-#define KC_LEFT_PAREN   KC_LPRN
+#define KC_LPRN LSFT(KC_9)  // (
+#define KC_LEFT_PAREN KC_LPRN
 
-#define KC_RPRN LSFT(KC_0)      // )
-#define KC_RIGHT_PAREN  KC_RPRN
+#define KC_RPRN LSFT(KC_0)  // )
+#define KC_RIGHT_PAREN KC_RPRN
 
-#define KC_UNDS LSFT(KC_MINS)   // _
-#define KC_UNDERSCORE   KC_UNDS
+#define KC_UNDS LSFT(KC_MINS)  // _
+#define KC_UNDERSCORE KC_UNDS
 
-#define KC_PLUS LSFT(KC_EQL)    // +
+#define KC_PLUS LSFT(KC_EQL)  // +
 
-#define KC_LCBR LSFT(KC_LBRC)   // {
+#define KC_LCBR LSFT(KC_LBRC)  // {
 #define KC_LEFT_CURLY_BRACE KC_LCBR
 
-#define KC_RCBR LSFT(KC_RBRC)   // }
-#define KC_RIGHT_CURLY_BRACE    KC_RCBR
+#define KC_RCBR LSFT(KC_RBRC)  // }
+#define KC_RIGHT_CURLY_BRACE KC_RCBR
 
-#define KC_LABK LSFT(KC_COMM)   // <
-#define KC_LEFT_ANGLE_BRACKET   KC_LABK
+#define KC_LABK LSFT(KC_COMM)  // <
+#define KC_LEFT_ANGLE_BRACKET KC_LABK
 
-#define KC_RABK LSFT(KC_DOT)    // >
-#define KC_RIGHT_ANGLE_BRACKET  KC_RABK
+#define KC_RABK LSFT(KC_DOT)  // >
+#define KC_RIGHT_ANGLE_BRACKET KC_RABK
 
-#define KC_COLN LSFT(KC_SCLN)   // :
-#define KC_COLON    KC_COLN
+#define KC_COLN LSFT(KC_SCLN)  // :
+#define KC_COLON KC_COLN
 
-#define KC_PIPE LSFT(KC_BSLS)   // |
+#define KC_PIPE LSFT(KC_BSLS)  // |
 
-#define KC_LT LSFT(KC_COMM)     // <
+#define KC_LT LSFT(KC_COMM)  // <
 
-#define KC_GT LSFT(KC_DOT)      // >
+#define KC_GT LSFT(KC_DOT)  // >
 
-#define KC_QUES LSFT(KC_SLSH)   // ?
+#define KC_QUES LSFT(KC_SLSH)  // ?
 #define KC_QUESTION KC_QUES
 
-#define KC_DQT LSFT(KC_QUOT)   // "
+#define KC_DQT LSFT(KC_QUOT)  // "
 #define KC_DOUBLE_QUOTE KC_DQT
 #define KC_DQUO KC_DQT
 
-#define KC_DELT KC_DELETE       // Del key (four letter code)
+#define KC_DELT KC_DELETE  // Del key (four letter code)
 
 // Alias for function layers than expand past FN31
 #define FUNC(kc) (QK_FUNCTION | (kc))
@@ -642,7 +641,7 @@ enum quantum_keycodes {
 #define RGB_M_T RGB_MODE_RGBTEST
 
 // L-ayer, T-ap - 256 keycode max, 16 layer max
-#define LT(layer, kc) (QK_LAYER_TAP | (((layer) & 0xF) << 8) | ((kc) & 0xFF))
+#define LT(layer, kc) (QK_LAYER_TAP | (((layer)&0xF) << 8) | ((kc)&0xFF))
 
 #define AG_SWAP MAGIC_SWAP_ALT_GUI
 #define AG_NORM MAGIC_UNSWAP_ALT_GUI
@@ -660,43 +659,43 @@ enum quantum_keycodes {
 // In fact, we changed it to assume ON_PRESS for sanity/simplicity. If needed, you can add your own
 // keycode modeled after the old version, kept below for this.
 /* #define TO(layer, when) (QK_TO | (when << 0x4) | (layer & 0xFF)) */
-#define TO(layer) (QK_TO | (ON_PRESS << 0x4) | ((layer) & 0xFF))
+#define TO(layer) (QK_TO | (ON_PRESS << 0x4) | ((layer)&0xFF))
 
 // Momentary switch layer - 256 layer max
-#define MO(layer) (QK_MOMENTARY | ((layer) & 0xFF))
+#define MO(layer) (QK_MOMENTARY | ((layer)&0xFF))
 
 // Set default layer - 256 layer max
-#define DF(layer) (QK_DEF_LAYER | ((layer) & 0xFF))
+#define DF(layer) (QK_DEF_LAYER | ((layer)&0xFF))
 
 // Toggle to layer - 256 layer max
-#define TG(layer) (QK_TOGGLE_LAYER | ((layer) & 0xFF))
+#define TG(layer) (QK_TOGGLE_LAYER | ((layer)&0xFF))
 
 // One-shot layer - 256 layer max
-#define OSL(layer) (QK_ONE_SHOT_LAYER | ((layer) & 0xFF))
+#define OSL(layer) (QK_ONE_SHOT_LAYER | ((layer)&0xFF))
 
 // L-ayer M-od: Momentary switch layer with modifiers active - 16 layer max, left mods only
-#define LM(layer, mod) (QK_LAYER_MOD | (((layer) & 0xF) << 4) | ((mod) & 0xF))
+#define LM(layer, mod) (QK_LAYER_MOD | (((layer)&0xF) << 4) | ((mod)&0xF))
 
 // One-shot mod
-#define OSM(mod) (QK_ONE_SHOT_MOD | ((mod) & 0xFF))
+#define OSM(mod) (QK_ONE_SHOT_MOD | ((mod)&0xFF))
 
 // Layer tap-toggle
-#define TT(layer) (QK_LAYER_TAP_TOGGLE | ((layer) & 0xFF))
+#define TT(layer) (QK_LAYER_TAP_TOGGLE | ((layer)&0xFF))
 
 // M-od, T-ap - 256 keycode max
-#define MT(mod, kc) (QK_MOD_TAP | (((mod) & 0x1F) << 8) | ((kc) & 0xFF))
+#define MT(mod, kc) (QK_MOD_TAP | (((mod)&0x1F) << 8) | ((kc)&0xFF))
 
 #define LCTL_T(kc) MT(MOD_LCTL, kc)
 #define RCTL_T(kc) MT(MOD_RCTL, kc)
-#define CTL_T(kc)  LCTL_T(kc)
+#define CTL_T(kc) LCTL_T(kc)
 
 #define LSFT_T(kc) MT(MOD_LSFT, kc)
 #define RSFT_T(kc) MT(MOD_RSFT, kc)
-#define SFT_T(kc)  LSFT_T(kc)
+#define SFT_T(kc) LSFT_T(kc)
 
 #define LALT_T(kc) MT(MOD_LALT, kc)
 #define RALT_T(kc) MT(MOD_RALT, kc)
-#define ALT_T(kc)  LALT_T(kc)
+#define ALT_T(kc) LALT_T(kc)
 #define ALGR_T(kc) RALT_T(kc)
 
 #define LGUI_T(kc) MT(MOD_LGUI, kc)
@@ -705,36 +704,36 @@ enum quantum_keycodes {
 #define LWIN_T(kc) LGUI_T(kc)
 #define RCMD_T(kc) RGUI_T(kc)
 #define RWIN_T(kc) RGUI_T(kc)
-#define GUI_T(kc)  LGUI_T(kc)
-#define CMD_T(kc)  LCMD_T(kc)
-#define WIN_T(kc)  LWIN_T(kc)
-
-#define C_S_T(kc)  MT(MOD_LCTL | MOD_LSFT, kc) // Left Control + Shift e.g. for gnome-terminal
-#define MEH_T(kc)  MT(MOD_LCTL | MOD_LSFT | MOD_LALT, kc) // Meh is a less hyper version of the Hyper key -- doesn't include GUI, so just Left Control + Shift + Alt
-#define LCAG_T(kc) MT(MOD_LCTL | MOD_LALT | MOD_LGUI, kc) // Left Control + Alt + GUI
-#define RCAG_T(kc) MT(MOD_RCTL | MOD_RALT | MOD_RGUI, kc) // Right Control + Alt + GUI
-#define HYPR_T(kc) MT(MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI, kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/
-#define SGUI_T(kc) MT(MOD_LGUI | MOD_LSFT, kc) // Left Shift + GUI
+#define GUI_T(kc) LGUI_T(kc)
+#define CMD_T(kc) LCMD_T(kc)
+#define WIN_T(kc) LWIN_T(kc)
+
+#define C_S_T(kc) MT(MOD_LCTL | MOD_LSFT, kc)                         // Left Control + Shift e.g. for gnome-terminal
+#define MEH_T(kc) MT(MOD_LCTL | MOD_LSFT | MOD_LALT, kc)              // Meh is a less hyper version of the Hyper key -- doesn't include GUI, so just Left Control + Shift + Alt
+#define LCAG_T(kc) MT(MOD_LCTL | MOD_LALT | MOD_LGUI, kc)             // Left Control + Alt + GUI
+#define RCAG_T(kc) MT(MOD_RCTL | MOD_RALT | MOD_RGUI, kc)             // Right Control + Alt + GUI
+#define HYPR_T(kc) MT(MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI, kc)  // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/
+#define SGUI_T(kc) MT(MOD_LGUI | MOD_LSFT, kc)                        // Left Shift + GUI
 #define SCMD_T(kc) SGUI_T(kc)
 #define SWIN_T(kc) SGUI_T(kc)
-#define LCA_T(kc)  MT(MOD_LCTL | MOD_LALT, kc) // Left Control + Alt
-#define ALL_T(kc)  HYPR_T(kc)
+#define LCA_T(kc) MT(MOD_LCTL | MOD_LALT, kc)  // Left Control + Alt
+#define ALL_T(kc) HYPR_T(kc)
 
 // Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap
 #define KC_HYPR HYPR(KC_NO)
-#define KC_MEH  MEH(KC_NO)
+#define KC_MEH MEH(KC_NO)
 
 #ifdef UNICODE_ENABLE
-  // Allows Unicode input up to 0x7FFF
-  #define UC(c) (QK_UNICODE | (c))
+// Allows Unicode input up to 0x7FFF
+#    define UC(c) (QK_UNICODE | (c))
 #endif
 #ifdef UNICODEMAP_ENABLE
-  // Allows Unicode input up to 0x10FFFF, requires unicode_map
-  #define X(i)     (QK_UNICODEMAP | (i))
-  #define XP(i, j) (QK_UNICODEMAP_PAIR | ((i) & 0x7F) | (((j) & 0x7F) << 7)) // 127 max i and j
+// Allows Unicode input up to 0x10FFFF, requires unicode_map
+#    define X(i) (QK_UNICODEMAP | (i))
+#    define XP(i, j) (QK_UNICODEMAP_PAIR | ((i)&0x7F) | (((j)&0x7F) << 7))  // 127 max i and j
 #endif
 
-#define UC_MOD  UNICODE_MODE_FORWARD
+#define UC_MOD UNICODE_MODE_FORWARD
 #define UC_RMOD UNICODE_MODE_REVERSE
 
 #define UC_M_OS UNICODE_MODE_OSX
@@ -744,13 +743,13 @@ enum quantum_keycodes {
 #define UC_M_WC UNICODE_MODE_WINC
 
 #ifdef SWAP_HANDS_ENABLE
-  #define SH_T(kc) (QK_SWAP_HANDS | (kc))
-  #define SH_TG    (QK_SWAP_HANDS | OP_SH_TOGGLE)
-  #define SH_TT    (QK_SWAP_HANDS | OP_SH_TAP_TOGGLE)
-  #define SH_MON   (QK_SWAP_HANDS | OP_SH_ON_OFF)
-  #define SH_MOFF  (QK_SWAP_HANDS | OP_SH_OFF_ON)
-  #define SH_ON    (QK_SWAP_HANDS | OP_SH_ON)
-  #define SH_OFF   (QK_SWAP_HANDS | OP_SH_OFF)
+#    define SH_T(kc) (QK_SWAP_HANDS | (kc))
+#    define SH_TG (QK_SWAP_HANDS | OP_SH_TOGGLE)
+#    define SH_TT (QK_SWAP_HANDS | OP_SH_TAP_TOGGLE)
+#    define SH_MON (QK_SWAP_HANDS | OP_SH_ON_OFF)
+#    define SH_MOFF (QK_SWAP_HANDS | OP_SH_OFF_ON)
+#    define SH_ON (QK_SWAP_HANDS | OP_SH_ON)
+#    define SH_OFF (QK_SWAP_HANDS | OP_SH_OFF)
 #endif
 
-#endif // QUANTUM_KEYCODES_H
+#endif  // QUANTUM_KEYCODES_H
index ce674ce6bce7f3d21abfbd552257a6888b475685..7b6ea0542f282af29a3a997804e4738de9dbcc2e 100644 (file)
 #ifndef RGB_H
 #define RGB_H
 
-__attribute__((weak))
-void rgblight_toggle(void) {};
+__attribute__((weak)) void rgblight_toggle(void){};
 
-__attribute__((weak))
-void rgblight_step(void) {};
+__attribute__((weak)) void rgblight_step(void){};
 
-__attribute__((weak))
-void rgblight_step_reverse(void) {};
+__attribute__((weak)) void rgblight_step_reverse(void){};
 
-__attribute__((weak))
-void rgblight_increase_hue(void) {};
+__attribute__((weak)) void rgblight_increase_hue(void){};
 
-__attribute__((weak))
-void rgblight_decrease_hue(void) {};
+__attribute__((weak)) void rgblight_decrease_hue(void){};
 
-__attribute__((weak))
-void rgblight_increase_sat(void) {};
+__attribute__((weak)) void rgblight_increase_sat(void){};
 
-__attribute__((weak))
-void rgblight_decrease_sat(void) {};
+__attribute__((weak)) void rgblight_decrease_sat(void){};
 
-__attribute__((weak))
-void rgblight_increase_val(void) {};
+__attribute__((weak)) void rgblight_increase_val(void){};
 
-__attribute__((weak))
-void rgblight_decrease_val(void) {};
+__attribute__((weak)) void rgblight_decrease_val(void){};
 
-__attribute__((weak))
-void rgblight_increase_speed(void) {};
+__attribute__((weak)) void rgblight_increase_speed(void){};
 
-__attribute__((weak))
-void rgblight_decrease_speed(void) {};
+__attribute__((weak)) void rgblight_decrease_speed(void){};
 
 #endif
\ No newline at end of file
index f649525ccb66dbc84f23ab4a620f9b3d25255969..55a6f74be75c7a794d4fd845e7085eecc163dbdc 100644 (file)
@@ -16,7 +16,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #include "rgb_matrix.h"
 #include "progmem.h"
 #include "config.h"
@@ -27,9 +26,9 @@
 #include "lib/lib8tion/lib8tion.h"
 
 #ifndef RGB_MATRIX_CENTER
-  const point_t k_rgb_matrix_center = { 112, 32 };
+const point_t k_rgb_matrix_center = {112, 32};
 #else
-  const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER;
+const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER;
 #endif
 
 // Generic effect runners
 
 #include "rgb_matrix_animations/rgb_matrix_effects.inc"
 #ifdef RGB_MATRIX_CUSTOM_KB
-    #include "rgb_matrix_kb.inc"
+#    include "rgb_matrix_kb.inc"
 #endif
 #ifdef RGB_MATRIX_CUSTOM_USER
-    #include "rgb_matrix_user.inc"
+#    include "rgb_matrix_user.inc"
 #endif
 
 #undef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 // ------------------------------------------
 
 #ifndef RGB_DISABLE_AFTER_TIMEOUT
-  #define RGB_DISABLE_AFTER_TIMEOUT 0
+#    define RGB_DISABLE_AFTER_TIMEOUT 0
 #endif
 
 #ifndef RGB_DISABLE_WHEN_USB_SUSPENDED
-  #define RGB_DISABLE_WHEN_USB_SUSPENDED false
+#    define RGB_DISABLE_WHEN_USB_SUSPENDED false
 #endif
 
 #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
-  #undef RGB_MATRIX_MAXIMUM_BRIGHTNESS
-  #define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
+#    undef RGB_MATRIX_MAXIMUM_BRIGHTNESS
+#    define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
 #endif
 
 #if !defined(RGB_MATRIX_HUE_STEP)
-  #define RGB_MATRIX_HUE_STEP 8
+#    define RGB_MATRIX_HUE_STEP 8
 #endif
 
 #if !defined(RGB_MATRIX_SAT_STEP)
-  #define RGB_MATRIX_SAT_STEP 16
+#    define RGB_MATRIX_SAT_STEP 16
 #endif
 
 #if !defined(RGB_MATRIX_VAL_STEP)
-  #define RGB_MATRIX_VAL_STEP 16
+#    define RGB_MATRIX_VAL_STEP 16
 #endif
 
 #if !defined(RGB_MATRIX_SPD_STEP)
-  #define RGB_MATRIX_SPD_STEP 16
+#    define RGB_MATRIX_SPD_STEP 16
 #endif
 
 #if !defined(RGB_MATRIX_STARTUP_MODE)
-  #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
-    #define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT
-  #else
-    // fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace
-    #define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_SOLID_COLOR
-  #endif
+#    ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
+#        define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT
+#    else
+// fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace
+#        define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_SOLID_COLOR
+#    endif
 #endif
 
 bool g_suspend_state = false;
 
 rgb_config_t rgb_matrix_config;
 
-rgb_counters_t g_rgb_counters;
+rgb_counters_t  g_rgb_counters;
 static uint32_t rgb_counters_buffer;
 
 #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
@@ -108,454 +107,421 @@ uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}};
 #endif
 
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-  last_hit_t g_last_hit_tracker;
-  static last_hit_t last_hit_buffer;
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+last_hit_t        g_last_hit_tracker;
+static last_hit_t last_hit_buffer;
+#endif  // RGB_MATRIX_KEYREACTIVE_ENABLED
 
-void eeconfig_read_rgb_matrix(void) {
-  eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config));
-}
+void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); }
 
-void eeconfig_update_rgb_matrix(void) {
-  eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config));
-}
+void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); }
 
 void eeconfig_update_rgb_matrix_default(void) {
-  dprintf("eeconfig_update_rgb_matrix_default\n");
-  rgb_matrix_config.enable = 1;
-  rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE;
-  rgb_matrix_config.hsv = (HSV){ 0,  UINT8_MAX, RGB_MATRIX_MAXIMUM_BRIGHTNESS };
-  rgb_matrix_config.speed = UINT8_MAX / 2;
-  eeconfig_update_rgb_matrix();
+    dprintf("eeconfig_update_rgb_matrix_default\n");
+    rgb_matrix_config.enable = 1;
+    rgb_matrix_config.mode   = RGB_MATRIX_STARTUP_MODE;
+    rgb_matrix_config.hsv    = (HSV){0, UINT8_MAX, RGB_MATRIX_MAXIMUM_BRIGHTNESS};
+    rgb_matrix_config.speed  = UINT8_MAX / 2;
+    eeconfig_update_rgb_matrix();
 }
 
 void eeconfig_debug_rgb_matrix(void) {
-  dprintf("rgb_matrix_config eprom\n");
-  dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable);
-  dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode);
-  dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h);
-  dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s);
-  dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v);
-  dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed);
+    dprintf("rgb_matrix_config eprom\n");
+    dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable);
+    dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode);
+    dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h);
+    dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s);
+    dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v);
+    dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed);
 }
 
-__attribute__ ((weak))
-uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) {
-  return 0;
-}
+__attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; }
 
 uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
-  uint8_t led_count = rgb_matrix_map_row_column_to_led_kb(row, column, led_i);
-  uint8_t led_index = g_led_config.matrix_co[row][column];
-  if (led_index != NO_LED) {
-    led_i[led_count] = led_index;
-    led_count++;
-  }
-  return led_count;
+    uint8_t led_count = rgb_matrix_map_row_column_to_led_kb(row, column, led_i);
+    uint8_t led_index = g_led_config.matrix_co[row][column];
+    if (led_index != NO_LED) {
+        led_i[led_count] = led_index;
+        led_count++;
+    }
+    return led_count;
 }
 
-void rgb_matrix_update_pwm_buffers(void) {
-  rgb_matrix_driver.flush();
-}
+void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); }
 
-void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) {
-  rgb_matrix_driver.set_color(index, red, green, blue);
-}
+void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color(index, red, green, blue); }
 
-void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) {
-  rgb_matrix_driver.set_color_all(red, green, blue);
-}
+void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color_all(red, green, blue); }
 
 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-  uint8_t led[LED_HITS_TO_REMEMBER];
-  uint8_t led_count = 0;
-
-#if defined(RGB_MATRIX_KEYRELEASES)
-  if (!record->event.pressed) {
-    led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
-    g_rgb_counters.any_key_hit = 0;
-  }
-#elif defined(RGB_MATRIX_KEYPRESSES)
-  if (record->event.pressed) {
-    led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
-    g_rgb_counters.any_key_hit = 0;
-  }
-#endif // defined(RGB_MATRIX_KEYRELEASES)
-
-  if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
-    memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count);
-    memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count);
-    memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit
-    memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count);
-    last_hit_buffer.count--;
-  }
-
-  for(uint8_t i = 0; i < led_count; i++) {
-    uint8_t index = last_hit_buffer.count;
-    last_hit_buffer.x[index] = g_led_config.point[led[i]].x;
-    last_hit_buffer.y[index] = g_led_config.point[led[i]].y;
-    last_hit_buffer.index[index] = led[i];
-    last_hit_buffer.tick[index] = 0;
-    last_hit_buffer.count++;
-  }
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+    uint8_t led[LED_HITS_TO_REMEMBER];
+    uint8_t led_count = 0;
+
+#    if defined(RGB_MATRIX_KEYRELEASES)
+    if (!record->event.pressed) {
+        led_count                  = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
+        g_rgb_counters.any_key_hit = 0;
+    }
+#    elif defined(RGB_MATRIX_KEYPRESSES)
+    if (record->event.pressed) {
+        led_count                  = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
+        g_rgb_counters.any_key_hit = 0;
+    }
+#    endif  // defined(RGB_MATRIX_KEYRELEASES)
+
+    if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
+        memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count);
+        memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count);
+        memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2);  // 16 bit
+        memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count);
+        last_hit_buffer.count--;
+    }
+
+    for (uint8_t i = 0; i < led_count; i++) {
+        uint8_t index                = last_hit_buffer.count;
+        last_hit_buffer.x[index]     = g_led_config.point[led[i]].x;
+        last_hit_buffer.y[index]     = g_led_config.point[led[i]].y;
+        last_hit_buffer.index[index] = led[i];
+        last_hit_buffer.tick[index]  = 0;
+        last_hit_buffer.count++;
+    }
+#endif  // RGB_MATRIX_KEYREACTIVE_ENABLED
 
 #if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
-  if (rgb_matrix_config.mode == RGB_MATRIX_TYPING_HEATMAP) {
-    process_rgb_matrix_typing_heatmap(record);
-  }
-#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
+    if (rgb_matrix_config.mode == RGB_MATRIX_TYPING_HEATMAP) {
+        process_rgb_matrix_typing_heatmap(record);
+    }
+#endif  // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
 
-  return true;
+    return true;
 }
 
 void rgb_matrix_test(void) {
-  // Mask out bits 4 and 5
-  // Increase the factor to make the test animation slower (and reduce to make it faster)
-  uint8_t factor = 10;
-  switch ( (g_rgb_counters.tick & (0b11 << factor)) >> factor )
-  {
-    case 0: {
-      rgb_matrix_set_color_all( 20, 0, 0 );
-      break;
-    }
-    case 1: {
-      rgb_matrix_set_color_all( 0, 20, 0 );
-      break;
+    // Mask out bits 4 and 5
+    // Increase the factor to make the test animation slower (and reduce to make it faster)
+    uint8_t factor = 10;
+    switch ((g_rgb_counters.tick & (0b11 << factor)) >> factor) {
+        case 0: {
+            rgb_matrix_set_color_all(20, 0, 0);
+            break;
+        }
+        case 1: {
+            rgb_matrix_set_color_all(0, 20, 0);
+            break;
+        }
+        case 2: {
+            rgb_matrix_set_color_all(0, 0, 20);
+            break;
+        }
+        case 3: {
+            rgb_matrix_set_color_all(20, 20, 20);
+            break;
+        }
     }
-    case 2: {
-      rgb_matrix_set_color_all( 0, 0, 20 );
-      break;
-    }
-    case 3: {
-      rgb_matrix_set_color_all( 20, 20, 20 );
-      break;
-    }
-  }
 }
 
-static bool rgb_matrix_none(effect_params_tparams) {
-  if (!params->init) {
-    return false;
-  }
+static bool rgb_matrix_none(effect_params_t *params) {
+    if (!params->init) {
+        return false;
+    }
 
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
-  for (uint8_t i = led_min; i < led_max; i++) {
-    rgb_matrix_set_color(i, 0, 0, 0);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    for (uint8_t i = led_min; i < led_max; i++) {
+        rgb_matrix_set_color(i, 0, 0, 0);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
 
-static uint8_t rgb_last_enable = UINT8_MAX;
-static uint8_t rgb_last_effect = UINT8_MAX;
-static effect_params_t rgb_effect_params = { 0, 0xFF };
-static rgb_task_states rgb_task_state = SYNCING;
+static uint8_t         rgb_last_enable   = UINT8_MAX;
+static uint8_t         rgb_last_effect   = UINT8_MAX;
+static effect_params_t rgb_effect_params = {0, 0xFF};
+static rgb_task_states rgb_task_state    = SYNCING;
 
 static void rgb_task_timers(void) {
-  // Update double buffer timers
-  uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer);
-  rgb_counters_buffer = timer_read32();
-  if (g_rgb_counters.any_key_hit < UINT32_MAX) {
-    if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) {
-      g_rgb_counters.any_key_hit = UINT32_MAX;
-    } else {
-      g_rgb_counters.any_key_hit += deltaTime;
+    // Update double buffer timers
+    uint16_t deltaTime  = timer_elapsed32(rgb_counters_buffer);
+    rgb_counters_buffer = timer_read32();
+    if (g_rgb_counters.any_key_hit < UINT32_MAX) {
+        if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) {
+            g_rgb_counters.any_key_hit = UINT32_MAX;
+        } else {
+            g_rgb_counters.any_key_hit += deltaTime;
+        }
     }
-  }
 
-  // Update double buffer last hit timers
+    // Update double buffer last hit timers
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-  uint8_t count = last_hit_buffer.count;
-  for (uint8_t i = 0; i < count; ++i) {
-    if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
-      last_hit_buffer.count--;
-      continue;
+    uint8_t count = last_hit_buffer.count;
+    for (uint8_t i = 0; i < count; ++i) {
+        if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
+            last_hit_buffer.count--;
+            continue;
+        }
+        last_hit_buffer.tick[i] += deltaTime;
     }
-    last_hit_buffer.tick[i] += deltaTime;
-  }
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#endif  // RGB_MATRIX_KEYREACTIVE_ENABLED
 }
 
 static void rgb_task_sync(void) {
-  // next task
-  if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT)
-    rgb_task_state = STARTING;
+    // next task
+    if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING;
 }
 
 static void rgb_task_start(void) {
-  // reset iter
-  rgb_effect_params.iter = 0;
+    // reset iter
+    rgb_effect_params.iter = 0;
 
-  // update double buffers
-  g_rgb_counters.tick = rgb_counters_buffer;
+    // update double buffers
+    g_rgb_counters.tick = rgb_counters_buffer;
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-  g_last_hit_tracker = last_hit_buffer;
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+    g_last_hit_tracker = last_hit_buffer;
+#endif  // RGB_MATRIX_KEYREACTIVE_ENABLED
 
-  // next task
-  rgb_task_state = RENDERING;
+    // next task
+    rgb_task_state = RENDERING;
 }
 
 static void rgb_task_render(uint8_t effect) {
-  bool rendering = false;
-  rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
+    bool rendering         = false;
+    rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
 
-  // each effect can opt to do calculations
-  // and/or request PWM buffer updates.
-  switch (effect) {
-    case RGB_MATRIX_NONE:
-      rendering = rgb_matrix_none(&rgb_effect_params);
-      break;
+    // each effect can opt to do calculations
+    // and/or request PWM buffer updates.
+    switch (effect) {
+        case RGB_MATRIX_NONE:
+            rendering = rgb_matrix_none(&rgb_effect_params);
+            break;
 
 // ---------------------------------------------
 // -----Begin rgb effect switch case macros-----
-#define RGB_MATRIX_EFFECT(name, ...) \
-    case RGB_MATRIX_##name: \
-      rendering = name(&rgb_effect_params); \
-      break;
+#define RGB_MATRIX_EFFECT(name, ...)          \
+    case RGB_MATRIX_##name:                   \
+        rendering = name(&rgb_effect_params); \
+        break;
 #include "rgb_matrix_animations/rgb_matrix_effects.inc"
 #undef RGB_MATRIX_EFFECT
 
 #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER)
-  #define RGB_MATRIX_EFFECT(name, ...) \
-    case RGB_MATRIX_CUSTOM_##name: \
-      rendering = name(&rgb_effect_params); \
-      break;
-  #ifdef RGB_MATRIX_CUSTOM_KB
-    #include "rgb_matrix_kb.inc"
-  #endif
-  #ifdef RGB_MATRIX_CUSTOM_USER
-    #include "rgb_matrix_user.inc"
-  #endif
-  #undef RGB_MATRIX_EFFECT
+#    define RGB_MATRIX_EFFECT(name, ...)          \
+        case RGB_MATRIX_CUSTOM_##name:            \
+            rendering = name(&rgb_effect_params); \
+            break;
+#    ifdef RGB_MATRIX_CUSTOM_KB
+#        include "rgb_matrix_kb.inc"
+#    endif
+#    ifdef RGB_MATRIX_CUSTOM_USER
+#        include "rgb_matrix_user.inc"
+#    endif
+#    undef RGB_MATRIX_EFFECT
 #endif
-// -----End rgb effect switch case macros-------
-// ---------------------------------------------
+            // -----End rgb effect switch case macros-------
+            // ---------------------------------------------
+
+        // Factory default magic value
+        case UINT8_MAX: {
+            rgb_matrix_test();
+            rgb_task_state = FLUSHING;
+        }
+            return;
+    }
+
+    rgb_effect_params.iter++;
 
-    // Factory default magic value
-    case UINT8_MAX: {
-        rgb_matrix_test();
+    // next task
+    if (!rendering) {
         rgb_task_state = FLUSHING;
-      }
-      return;
-  }
-
-  rgb_effect_params.iter++;
-
-  // next task
-  if (!rendering) {
-    rgb_task_state = FLUSHING;
-    if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) {
-      // We only need to flush once if we are RGB_MATRIX_NONE
-      rgb_task_state = SYNCING;
+        if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) {
+            // We only need to flush once if we are RGB_MATRIX_NONE
+            rgb_task_state = SYNCING;
+        }
     }
-  }
 }
 
 static void rgb_task_flush(uint8_t effect) {
-  // update last trackers after the first full render so we can init over several frames
-  rgb_last_effect = effect;
-  rgb_last_enable = rgb_matrix_config.enable;
+    // update last trackers after the first full render so we can init over several frames
+    rgb_last_effect = effect;
+    rgb_last_enable = rgb_matrix_config.enable;
 
-  // update pwm buffers
-  rgb_matrix_update_pwm_buffers();
+    // update pwm buffers
+    rgb_matrix_update_pwm_buffers();
 
-  // next task
-  rgb_task_state = SYNCING;
+    // next task
+    rgb_task_state = SYNCING;
 }
 
 void rgb_matrix_task(void) {
-  rgb_task_timers();
-
-  // Ideally we would also stop sending zeros to the LED driver PWM buffers
-  // while suspended and just do a software shutdown. This is a cheap hack for now.
-  bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) || (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_rgb_counters.any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20));
-  uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode;
-
-  switch (rgb_task_state) {
-    case STARTING:
-      rgb_task_start();
-      break;
-    case RENDERING:
-      rgb_task_render(effect);
-      break;
-    case FLUSHING:
-      rgb_task_flush(effect);
-      break;
-    case SYNCING:
-      rgb_task_sync();
-      break;
-  }
-
-  if (!suspend_backlight) {
-    rgb_matrix_indicators();
-  }
+    rgb_task_timers();
+
+    // Ideally we would also stop sending zeros to the LED driver PWM buffers
+    // while suspended and just do a software shutdown. This is a cheap hack for now.
+    bool    suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) || (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_rgb_counters.any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20));
+    uint8_t effect            = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode;
+
+    switch (rgb_task_state) {
+        case STARTING:
+            rgb_task_start();
+            break;
+        case RENDERING:
+            rgb_task_render(effect);
+            break;
+        case FLUSHING:
+            rgb_task_flush(effect);
+            break;
+        case SYNCING:
+            rgb_task_sync();
+            break;
+    }
+
+    if (!suspend_backlight) {
+        rgb_matrix_indicators();
+    }
 }
 
 void rgb_matrix_indicators(void) {
-  rgb_matrix_indicators_kb();
-  rgb_matrix_indicators_user();
+    rgb_matrix_indicators_kb();
+    rgb_matrix_indicators_user();
 }
 
-__attribute__((weak))
-void rgb_matrix_indicators_kb(void) {}
+__attribute__((weak)) void rgb_matrix_indicators_kb(void) {}
 
-__attribute__((weak))
-void rgb_matrix_indicators_user(void) {}
+__attribute__((weak)) void rgb_matrix_indicators_user(void) {}
 
 void rgb_matrix_init(void) {
-  rgb_matrix_driver.init();
+    rgb_matrix_driver.init();
 
-  // TODO: put the 1 second startup delay here?
+    // TODO: put the 1 second startup delay here?
 
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-  g_last_hit_tracker.count = 0;
-  for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
-    g_last_hit_tracker.tick[i] = UINT16_MAX;
-  }
+    g_last_hit_tracker.count = 0;
+    for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
+        g_last_hit_tracker.tick[i] = UINT16_MAX;
+    }
 
-  last_hit_buffer.count = 0;
-  for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
-    last_hit_buffer.tick[i] = UINT16_MAX;
-  }
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+    last_hit_buffer.count = 0;
+    for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
+        last_hit_buffer.tick[i] = UINT16_MAX;
+    }
+#endif  // RGB_MATRIX_KEYREACTIVE_ENABLED
 
-  if (!eeconfig_is_enabled()) {
-    dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n");
-    eeconfig_init();
-    eeconfig_update_rgb_matrix_default();
-  }
+    if (!eeconfig_is_enabled()) {
+        dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n");
+        eeconfig_init();
+        eeconfig_update_rgb_matrix_default();
+    }
 
-  eeconfig_read_rgb_matrix();
-  if (!rgb_matrix_config.mode) {
-    dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
-    eeconfig_update_rgb_matrix_default();
-  }
-  eeconfig_debug_rgb_matrix(); // display current eeprom values
+    eeconfig_read_rgb_matrix();
+    if (!rgb_matrix_config.mode) {
+        dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
+        eeconfig_update_rgb_matrix_default();
+    }
+    eeconfig_debug_rgb_matrix();  // display current eeprom values
 }
 
-void rgb_matrix_set_suspend_state(bool state) {
-  g_suspend_state = state;
-}
+void rgb_matrix_set_suspend_state(bool state) { g_suspend_state = state; }
 
 void rgb_matrix_toggle(void) {
-  rgb_matrix_config.enable ^= 1;
-  rgb_task_state = STARTING;
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.enable ^= 1;
+    rgb_task_state = STARTING;
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_enable(void) {
-  rgb_matrix_enable_noeeprom();
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_enable_noeeprom();
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_enable_noeeprom(void) {
-  if (!rgb_matrix_config.enable)
-    rgb_task_state = STARTING;
-  rgb_matrix_config.enable = 1;
+    if (!rgb_matrix_config.enable) rgb_task_state = STARTING;
+    rgb_matrix_config.enable = 1;
 }
 
 void rgb_matrix_disable(void) {
-  rgb_matrix_disable_noeeprom();
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_disable_noeeprom();
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_disable_noeeprom(void) {
-  if (rgb_matrix_config.enable)
-    rgb_task_state = STARTING;
-  rgb_matrix_config.enable = 0;
+    if (rgb_matrix_config.enable) rgb_task_state = STARTING;
+    rgb_matrix_config.enable = 0;
 }
 
 void rgb_matrix_step(void) {
-  rgb_matrix_config.mode++;
-  if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX)
-    rgb_matrix_config.mode = 1;
-  rgb_task_state = STARTING;
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.mode++;
+    if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) rgb_matrix_config.mode = 1;
+    rgb_task_state = STARTING;
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_step_reverse(void) {
-  rgb_matrix_config.mode--;
-  if (rgb_matrix_config.mode < 1)
-    rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
-  rgb_task_state = STARTING;
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.mode--;
+    if (rgb_matrix_config.mode < 1) rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
+    rgb_task_state = STARTING;
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_increase_hue(void) {
-  rgb_matrix_config.hsv.h += RGB_MATRIX_HUE_STEP;
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.hsv.h += RGB_MATRIX_HUE_STEP;
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_decrease_hue(void) {
-  rgb_matrix_config.hsv.h -= RGB_MATRIX_HUE_STEP;
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.hsv.h -= RGB_MATRIX_HUE_STEP;
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_increase_sat(void) {
-  rgb_matrix_config.hsv.s = qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP);
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.hsv.s = qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP);
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_decrease_sat(void) {
-  rgb_matrix_config.hsv.s = qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP);
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.hsv.s = qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP);
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_increase_val(void) {
-  rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP);
-  if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
-    rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP);
+    if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_decrease_val(void) {
-  rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP);
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP);
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_increase_speed(void) {
-  rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_decrease_speed(void) {
-  rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
+    eeconfig_update_rgb_matrix();
 }
 
-led_flags_t rgb_matrix_get_flags(void) {
-  return rgb_effect_params.flags;
-}
+led_flags_t rgb_matrix_get_flags(void) { return rgb_effect_params.flags; }
 
-void rgb_matrix_set_flags(led_flags_t flags) {
-  rgb_effect_params.flags = flags;
-}
+void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; }
 
 void rgb_matrix_mode(uint8_t mode) {
-  rgb_matrix_config.mode = mode;
-  rgb_task_state = STARTING;
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_config.mode = mode;
+    rgb_task_state         = STARTING;
+    eeconfig_update_rgb_matrix();
 }
 
-void rgb_matrix_mode_noeeprom(uint8_t mode) {
-  rgb_matrix_config.mode = mode;
-}
+void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_config.mode = mode; }
 
-uint8_t rgb_matrix_get_mode(void) {
-  return rgb_matrix_config.mode;
-}
+uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; }
 
 void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
-  rgb_matrix_sethsv_noeeprom(hue, sat, val);
-  eeconfig_update_rgb_matrix();
+    rgb_matrix_sethsv_noeeprom(hue, sat, val);
+    eeconfig_update_rgb_matrix();
 }
 
 void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
-  rgb_matrix_config.hsv.h = hue;
-  rgb_matrix_config.hsv.s = sat;
-  rgb_matrix_config.hsv.v = val;
-  if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
-    rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
+    rgb_matrix_config.hsv.h = hue;
+    rgb_matrix_config.hsv.s = sat;
+    rgb_matrix_config.hsv.v = val;
+    if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
 }
index 749926822a8f528794abc19e19a8a00bda1604a4..16ec96f03684629dff5a722bb4b6c5d4699c5701 100644 (file)
 #include "rgblight_list.h"
 
 #ifdef IS31FL3731
-  #include "is31fl3731.h"
-#elif defined (IS31FL3733)
-  #include "is31fl3733.h"
-#elif defined (IS31FL3737)
-  #include "is31fl3737.h"
-#elif defined (WS2812)
-  #include "ws2812.h"
+#    include "is31fl3731.h"
+#elif defined(IS31FL3733)
+#    include "is31fl3733.h"
+#elif defined(IS31FL3737)
+#    include "is31fl3737.h"
+#elif defined(WS2812)
+#    include "ws2812.h"
 #endif
 
 #ifndef RGB_MATRIX_LED_FLUSH_LIMIT
-  #define RGB_MATRIX_LED_FLUSH_LIMIT 16
+#    define RGB_MATRIX_LED_FLUSH_LIMIT 16
 #endif
 
 #ifndef RGB_MATRIX_LED_PROCESS_LIMIT
-  #define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
+#    define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
 #endif
 
 #if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
-#define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \
-  uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \
-  if (max > DRIVER_LED_TOTAL) \
-    max = DRIVER_LED_TOTAL;
+#    define RGB_MATRIX_USE_LIMITS(min, max)                        \
+        uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \
+        uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT;          \
+        if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
 #else
-#define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = 0; \
-  uint8_t max = DRIVER_LED_TOTAL;
+#    define RGB_MATRIX_USE_LIMITS(min, max) \
+        uint8_t min = 0;                    \
+        uint8_t max = DRIVER_LED_TOTAL;
 #endif
 
-#define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
+#define RGB_MATRIX_TEST_LED_FLAGS() \
+    if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
 
 enum rgb_matrix_effects {
-  RGB_MATRIX_NONE = 0,
+    RGB_MATRIX_NONE = 0,
 
 // --------------------------------------
 // -----Begin rgb effect enum macros-----
@@ -66,28 +68,28 @@ enum rgb_matrix_effects {
 #undef RGB_MATRIX_EFFECT
 
 #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER)
-  #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name,
-  #ifdef RGB_MATRIX_CUSTOM_KB
-    #include "rgb_matrix_kb.inc"
-  #endif
-  #ifdef RGB_MATRIX_CUSTOM_USER
-    #include "rgb_matrix_user.inc"
-  #endif
-  #undef RGB_MATRIX_EFFECT
+#    define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name,
+#    ifdef RGB_MATRIX_CUSTOM_KB
+#        include "rgb_matrix_kb.inc"
+#    endif
+#    ifdef RGB_MATRIX_CUSTOM_USER
+#        include "rgb_matrix_user.inc"
+#    endif
+#    undef RGB_MATRIX_EFFECT
 #endif
-// --------------------------------------
-// -----End rgb effect enum macros-------
+    // --------------------------------------
+    // -----End rgb effect enum macros-------
 
-  RGB_MATRIX_EFFECT_MAX
+    RGB_MATRIX_EFFECT_MAX
 };
 
 void eeconfig_update_rgb_matrix_default(void);
 
 uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
-uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i);
+uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i);
 
-void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
-void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
+void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
 
 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
 
@@ -101,51 +103,51 @@ void rgb_matrix_indicators_user(void);
 
 void rgb_matrix_init(void);
 
-void rgb_matrix_set_suspend_state(bool state);
-void rgb_matrix_toggle(void);
-void rgb_matrix_enable(void);
-void rgb_matrix_enable_noeeprom(void);
-void rgb_matrix_disable(void);
-void rgb_matrix_disable_noeeprom(void);
-void rgb_matrix_step(void);
-void rgb_matrix_step_reverse(void);
-void rgb_matrix_increase_hue(void);
-void rgb_matrix_decrease_hue(void);
-void rgb_matrix_increase_sat(void);
-void rgb_matrix_decrease_sat(void);
-void rgb_matrix_increase_val(void);
-void rgb_matrix_decrease_val(void);
-void rgb_matrix_increase_speed(void);
-void rgb_matrix_decrease_speed(void);
+void        rgb_matrix_set_suspend_state(bool state);
+void        rgb_matrix_toggle(void);
+void        rgb_matrix_enable(void);
+void        rgb_matrix_enable_noeeprom(void);
+void        rgb_matrix_disable(void);
+void        rgb_matrix_disable_noeeprom(void);
+void        rgb_matrix_step(void);
+void        rgb_matrix_step_reverse(void);
+void        rgb_matrix_increase_hue(void);
+void        rgb_matrix_decrease_hue(void);
+void        rgb_matrix_increase_sat(void);
+void        rgb_matrix_decrease_sat(void);
+void        rgb_matrix_increase_val(void);
+void        rgb_matrix_decrease_val(void);
+void        rgb_matrix_increase_speed(void);
+void        rgb_matrix_decrease_speed(void);
 led_flags_t rgb_matrix_get_flags(void);
-void rgb_matrix_set_flags(led_flags_t flags);
-void rgb_matrix_mode(uint8_t mode);
-void rgb_matrix_mode_noeeprom(uint8_t mode);
-uint8_t rgb_matrix_get_mode(void);
-void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
-void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
+void        rgb_matrix_set_flags(led_flags_t flags);
+void        rgb_matrix_mode(uint8_t mode);
+void        rgb_matrix_mode_noeeprom(uint8_t mode);
+uint8_t     rgb_matrix_get_mode(void);
+void        rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
+void        rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
 
 #ifndef RGBLIGHT_ENABLE
-#define rgblight_toggle() rgb_matrix_toggle()
-#define rgblight_enable() rgb_matrix_enable()
-#define rgblight_enable_noeeprom() rgb_matrix_enable_noeeprom()
-#define rgblight_disable() rgb_matrix_disable()
-#define rgblight_disable_noeeprom() rgb_matrix_disable_noeeprom()
-#define rgblight_step() rgb_matrix_step()
-#define rgblight_sethsv(hue, sat, val) rgb_matrix_sethsv(hue, sat, val)
-#define rgblight_sethsv_noeeprom(hue, sat, val) rgb_matrix_sethsv_noeeprom(hue, sat, val)
-#define rgblight_step_reverse() rgb_matrix_step_reverse()
-#define rgblight_increase_hue() rgb_matrix_increase_hue()
-#define rgblight_decrease_hue() rgb_matrix_decrease_hue()
-#define rgblight_increase_sat() rgb_matrix_increase_sat()
-#define rgblight_decrease_sat() rgb_matrix_decrease_sat()
-#define rgblight_increase_val() rgb_matrix_increase_val()
-#define rgblight_decrease_val() rgb_matrix_decrease_val()
-#define rgblight_increase_speed() rgb_matrix_increase_speed()
-#define rgblight_decrease_speed() rgb_matrix_decrease_speed()
-#define rgblight_mode(mode) rgb_matrix_mode(mode)
-#define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode)
-#define rgblight_get_mode() rgb_matrix_get_mode()
+#    define rgblight_toggle() rgb_matrix_toggle()
+#    define rgblight_enable() rgb_matrix_enable()
+#    define rgblight_enable_noeeprom() rgb_matrix_enable_noeeprom()
+#    define rgblight_disable() rgb_matrix_disable()
+#    define rgblight_disable_noeeprom() rgb_matrix_disable_noeeprom()
+#    define rgblight_step() rgb_matrix_step()
+#    define rgblight_sethsv(hue, sat, val) rgb_matrix_sethsv(hue, sat, val)
+#    define rgblight_sethsv_noeeprom(hue, sat, val) rgb_matrix_sethsv_noeeprom(hue, sat, val)
+#    define rgblight_step_reverse() rgb_matrix_step_reverse()
+#    define rgblight_increase_hue() rgb_matrix_increase_hue()
+#    define rgblight_decrease_hue() rgb_matrix_decrease_hue()
+#    define rgblight_increase_sat() rgb_matrix_increase_sat()
+#    define rgblight_decrease_sat() rgb_matrix_decrease_sat()
+#    define rgblight_increase_val() rgb_matrix_increase_val()
+#    define rgblight_decrease_val() rgb_matrix_decrease_val()
+#    define rgblight_increase_speed() rgb_matrix_increase_speed()
+#    define rgblight_decrease_speed() rgb_matrix_decrease_speed()
+#    define rgblight_mode(mode) rgb_matrix_mode(mode)
+#    define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode)
+#    define rgblight_get_mode() rgb_matrix_get_mode()
 #endif
 
 typedef struct {
@@ -163,9 +165,9 @@ extern const rgb_matrix_driver_t rgb_matrix_driver;
 
 extern rgb_config_t rgb_matrix_config;
 
-extern bool g_suspend_state;
+extern bool           g_suspend_state;
 extern rgb_counters_t g_rgb_counters;
-extern led_config_t g_led_config;
+extern led_config_t   g_led_config;
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
 extern last_hit_t g_last_hit_tracker;
 #endif
index 8df3356f611eaee3a0d62460aded23d198b22fae..0778ab2098f47e42e74a5c275c1069e523e01c72 100644 (file)
@@ -1,26 +1,26 @@
 #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
 RGB_MATRIX_EFFECT(ALPHAS_MODS)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 // alphas = color1, mods = color2
 bool ALPHAS_MODS(effect_params_t* params) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
 
-  HSV hsv = rgb_matrix_config.hsv;
-  RGB rgb1 = hsv_to_rgb(hsv);
-  hsv.h += rgb_matrix_config.speed;
-  RGB rgb2 = hsv_to_rgb(hsv);
+    HSV hsv  = rgb_matrix_config.hsv;
+    RGB rgb1 = hsv_to_rgb(hsv);
+    hsv.h += rgb_matrix_config.speed;
+    RGB rgb2 = hsv_to_rgb(hsv);
 
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) {
-      rgb_matrix_set_color(i, rgb2.r, rgb2.g, rgb2.b);
-    } else {
-      rgb_matrix_set_color(i, rgb1.r, rgb1.g, rgb1.b);
+    for (uint8_t i = led_min; i < led_max; i++) {
+        RGB_MATRIX_TEST_LED_FLAGS();
+        if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) {
+            rgb_matrix_set_color(i, rgb2.r, rgb2.g, rgb2.b);
+        } else {
+            rgb_matrix_set_color(i, rgb1.r, rgb1.g, rgb1.b);
+        }
     }
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    return led_max < DRIVER_LED_TOTAL;
 }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_ALPHAS_MODS
index 0af7b42cf3f3f1a45851713a8514f5a93181c922..92431555e7a879d4e12c80b9e90bcc20f118314f 100644 (file)
@@ -1,20 +1,20 @@
 #ifndef DISABLE_RGB_MATRIX_BREATHING
 RGB_MATRIX_EFFECT(BREATHING)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 bool BREATHING(effect_params_t* params) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
 
-  HSV hsv = rgb_matrix_config.hsv;
-  uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 8);
-  hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
-  RGB rgb = hsv_to_rgb(hsv);
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    HSV      hsv  = rgb_matrix_config.hsv;
+    uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 8);
+    hsv.v         = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
+    RGB rgb       = hsv_to_rgb(hsv);
+    for (uint8_t i = led_min; i < led_max; i++) {
+        RGB_MATRIX_TEST_LED_FLAGS();
+        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_BREATHING
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_BREATHING
index 4585c52716b95d12513acbc4afc7c7be0a627881..3df3cfda7d67684fdfc6cc7234fb9156686909ab 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT
 RGB_MATRIX_EFFECT(BAND_PINWHEEL_SAT)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 static HSV BAND_PINWHEEL_SAT_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) {
     hsv.s = scale8(hsv.s - time - atan2_8(dy, dx) * 3, hsv.s);
     return hsv;
 }
 
-bool BAND_PINWHEEL_SAT(effect_params_t* params) {
-    return effect_runner_dx_dy(params, &BAND_PINWHEEL_SAT_math);
-}
+bool BAND_PINWHEEL_SAT(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_SAT_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT
index 5cdb8734895b3103660dd5e02c31e44de5cd1f77..7d80074fd5dde7f94efed48539ab66b52b130877 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL
 RGB_MATRIX_EFFECT(BAND_PINWHEEL_VAL)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 static HSV BAND_PINWHEEL_VAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) {
     hsv.v = scale8(hsv.v - time - atan2_8(dy, dx) * 3, hsv.v);
     return hsv;
 }
 
-bool BAND_PINWHEEL_VAL(effect_params_t* params) {
-    return effect_runner_dx_dy(params, &BAND_PINWHEEL_VAL_math);
-}
+bool BAND_PINWHEEL_VAL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_VAL_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL
index a5175f1cd98b0c94d4897b23ec0a926bb566d0bc..35b830af6b93363329fefb7736df4815e480b5b8 100644 (file)
@@ -1,16 +1,14 @@
 #ifndef DISABLE_RGB_MATRIX_BAND_SAT
 RGB_MATRIX_EFFECT(BAND_SAT)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 static HSV BAND_SAT_math(HSV hsv, uint8_t i, uint8_t time) {
     int16_t s = hsv.s - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8;
-    hsv.s = scale8(s < 0 ? 0 : s, hsv.s);
+    hsv.s     = scale8(s < 0 ? 0 : s, hsv.s);
     return hsv;
 }
 
-bool BAND_SAT(effect_params_t* params) {
-    return effect_runner_i(params, &BAND_SAT_math);
-}
+bool BAND_SAT(effect_params_t* params) { return effect_runner_i(params, &BAND_SAT_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_BAND_SAT
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_BAND_SAT
index 096c675de8d21811fb33a5e67b55886b87de62f2..048157aa1be1fe465408334ec4523c8bccb20216 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT
 RGB_MATRIX_EFFECT(BAND_SPIRAL_SAT)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 static HSV BAND_SPIRAL_SAT_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
     hsv.s = scale8(hsv.s + dist - time - atan2_8(dy, dx), hsv.s);
     return hsv;
 }
 
-bool BAND_SPIRAL_SAT(effect_params_t* params) {
-    return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_SAT_math);
-}
+bool BAND_SPIRAL_SAT(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_SAT_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT
index 1d4cc0c84fe722647cbfd94ba21a22c5caa17543..bff2da1616a271e496ac3cab9f6568646bac2c32 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL
 RGB_MATRIX_EFFECT(BAND_SPIRAL_VAL)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 static HSV BAND_SPIRAL_VAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
     hsv.v = scale8(hsv.v + dist - time - atan2_8(dy, dx), hsv.v);
     return hsv;
 }
 
-bool BAND_SPIRAL_VAL(effect_params_t* params) {
-    return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_VAL_math);
-}
+bool BAND_SPIRAL_VAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_VAL_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL
index de0bbb47159aa5e382b8a589c659f5043d0f0fbc..f1aaf1d067dd6a5a57a806ea1a0293947bb27480 100644 (file)
@@ -1,16 +1,14 @@
 #ifndef DISABLE_RGB_MATRIX_BAND_VAL
 RGB_MATRIX_EFFECT(BAND_VAL)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 static HSV BAND_VAL_math(HSV hsv, uint8_t i, uint8_t time) {
     int16_t v = hsv.v - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8;
-    hsv.v = scale8(v < 0 ? 0 : v, hsv.v);
+    hsv.v     = scale8(v < 0 ? 0 : v, hsv.v);
     return hsv;
 }
 
-bool BAND_VAL(effect_params_t* params) {
-    return effect_runner_i(params, &BAND_VAL_math);
-}
+bool BAND_VAL(effect_params_t* params) { return effect_runner_i(params, &BAND_VAL_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_BAND_VAL
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_BAND_VAL
index 0c45aba8b13b34a1146289058f55f235a2a5e3bc..faf8598a39f6948009d9e054d48c9e89c9d3fa41 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
 RGB_MATRIX_EFFECT(CYCLE_ALL)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV CYCLE_ALL_math(HSV hsv,  uint8_t i, uint8_t time){
+static HSV CYCLE_ALL_math(HSV hsv, uint8_t i, uint8_t time) {
     hsv.h = time;
     return hsv;
 }
 
-bool CYCLE_ALL(effect_params_t* params) {
-    return effect_runner_i(params, &CYCLE_ALL_math);
-}
+bool CYCLE_ALL(effect_params_t* params) { return effect_runner_i(params, &CYCLE_ALL_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_CYCLE_ALL
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_CYCLE_ALL
index d2e5b4fbdf5a356e1f1e8791510287f302ee014a..cf911eb9370fe05878234da819e2927572ee0dc6 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
 RGB_MATRIX_EFFECT(CYCLE_LEFT_RIGHT)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV CYCLE_LEFT_RIGHT_math(HSV hsv,  uint8_t i, uint8_t time) {
+static HSV CYCLE_LEFT_RIGHT_math(HSV hsv, uint8_t i, uint8_t time) {
     hsv.h = g_led_config.point[i].x - time;
     return hsv;
 }
 
-bool CYCLE_LEFT_RIGHT(effect_params_t* params) {
-    return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math);
-}
+bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
index fa7c3b09cf7543fdf0c00c73ef35f2875eb7739c..d66acd4b2b306fd2ad7bc18d21b7d450557bdbc3 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN
 RGB_MATRIX_EFFECT(CYCLE_OUT_IN)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV CYCLE_OUT_IN_math(HSV hsv,  int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
+static HSV CYCLE_OUT_IN_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
     hsv.h = 3 * dist / 2 + time;
     return hsv;
 }
 
-bool CYCLE_OUT_IN(effect_params_t* params) {
-    return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math);
-}
+bool CYCLE_OUT_IN(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_CYCLE_OUT_IN
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_CYCLE_OUT_IN
index 74a2c9aa584b384edd019ae446a24fc84d50b320..fe8396140fb1b7d7f65ea7a11538a12bfa45b3d4 100644 (file)
@@ -1,17 +1,15 @@
 #ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL
 RGB_MATRIX_EFFECT(CYCLE_OUT_IN_DUAL)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV CYCLE_OUT_IN_DUAL_math(HSV hsv,  int16_t dx, int16_t dy, uint8_t time) {
-    dx = (k_rgb_matrix_center.x / 2) - abs8(dx);
+static HSV CYCLE_OUT_IN_DUAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) {
+    dx           = (k_rgb_matrix_center.x / 2) - abs8(dx);
     uint8_t dist = sqrt16(dx * dx + dy * dy);
-    hsv.h = 3 * dist + time;
+    hsv.h        = 3 * dist + time;
     return hsv;
 }
 
-bool CYCLE_OUT_IN_DUAL(effect_params_t* params) {
-    return effect_runner_dx_dy(params, &CYCLE_OUT_IN_DUAL_math);
-}
+bool CYCLE_OUT_IN_DUAL(effect_params_t* params) { return effect_runner_dx_dy(params, &CYCLE_OUT_IN_DUAL_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL
index 54e222dc2e3777bd6b89e015b19df2639124d62d..7799887099e6b92965da9b391d8cb767f887ad36 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_CYCLE_PINWHEEL
 RGB_MATRIX_EFFECT(CYCLE_PINWHEEL)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV CYCLE_PINWHEEL_math(HSV hsv,  int16_t dx, int16_t dy, uint8_t time) {
+static HSV CYCLE_PINWHEEL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) {
     hsv.h = atan2_8(dy, dx) + time;
     return hsv;
 }
 
-bool CYCLE_PINWHEEL(effect_params_t* params) {
-    return effect_runner_dx_dy(params, &CYCLE_PINWHEEL_math);
-}
+bool CYCLE_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &CYCLE_PINWHEEL_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_CYCLE_PINWHEEL
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_CYCLE_PINWHEEL
index b27d7a83c7212b34f7b6f4226fe03e18eb2a9473..80cfb0dbc7daffec90c8810490d17a58f75e7594 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_CYCLE_SPIRAL
 RGB_MATRIX_EFFECT(CYCLE_SPIRAL)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV CYCLE_SPIRAL_math(HSV hsv,  int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
+static HSV CYCLE_SPIRAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
     hsv.h = dist - time - atan2_8(dy, dx);
     return hsv;
 }
 
-bool CYCLE_SPIRAL(effect_params_t* params) {
-    return effect_runner_dx_dy_dist(params, &CYCLE_SPIRAL_math);
-}
+bool CYCLE_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_SPIRAL_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_CYCLE_SPIRAL
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_CYCLE_SPIRAL
index 4bf8ef2ae4a561dcaa4d9961410fe7141c111ab6..5016f739d6717499eb5207033ce1531ead6c8f8b 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
 RGB_MATRIX_EFFECT(CYCLE_UP_DOWN)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV CYCLE_UP_DOWN_math(HSV hsv,  uint8_t i, uint8_t time) {
+static HSV CYCLE_UP_DOWN_math(HSV hsv, uint8_t i, uint8_t time) {
     hsv.h = g_led_config.point[i].y - time;
     return hsv;
 }
 
-bool CYCLE_UP_DOWN(effect_params_t* params) {
-    return effect_runner_i(params, &CYCLE_UP_DOWN_math);
-}
+bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
index 982399cbdef1de2ea0b1c304d8c8d5b296e59945..7a4a52db1b433d64e775694b68c34cb4177e4c14 100644 (file)
@@ -1,77 +1,75 @@
 #if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN)
 RGB_MATRIX_EFFECT(DIGITAL_RAIN)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-#ifndef RGB_DIGITAL_RAIN_DROPS
-    // lower the number for denser effect/wider keyboard
-    #define RGB_DIGITAL_RAIN_DROPS 24
-#endif
+#        ifndef RGB_DIGITAL_RAIN_DROPS
+// lower the number for denser effect/wider keyboard
+#            define RGB_DIGITAL_RAIN_DROPS 24
+#        endif
 
 bool DIGITAL_RAIN(effect_params_t* params) {
-  // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
-  const uint8_t drop_ticks           = 28;
-  const uint8_t pure_green_intensity = 0xd0;
-  const uint8_t max_brightness_boost = 0xc0;
-  const uint8_t max_intensity        = 0xff;
+    // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
+    const uint8_t drop_ticks           = 28;
+    const uint8_t pure_green_intensity = 0xd0;
+    const uint8_t max_brightness_boost = 0xc0;
+    const uint8_t max_intensity        = 0xff;
 
-  static uint8_t drop = 0;
+    static uint8_t drop = 0;
 
-  if (params->init) {
-    rgb_matrix_set_color_all(0, 0, 0);
-    memset(rgb_frame_buffer, 0, sizeof(rgb_frame_buffer));
-    drop = 0;
-  }
+    if (params->init) {
+        rgb_matrix_set_color_all(0, 0, 0);
+        memset(rgb_frame_buffer, 0, sizeof(rgb_frame_buffer));
+        drop = 0;
+    }
 
-  for (uint8_t col = 0; col < MATRIX_COLS; col++) {
-    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
-      if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) {
-        // top row, pixels have just fallen and we're
-        // making a new rain drop in this column
-        rgb_frame_buffer[row][col] = max_intensity;
-      }
-      else if (rgb_frame_buffer[row][col] > 0 && rgb_frame_buffer[row][col] < max_intensity) {
-        // neither fully bright nor dark, decay it
-        rgb_frame_buffer[row][col]--;
-      }
-      // set the pixel colour
-      uint8_t led[LED_HITS_TO_REMEMBER];
-      uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
+    for (uint8_t col = 0; col < MATRIX_COLS; col++) {
+        for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
+            if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) {
+                // top row, pixels have just fallen and we're
+                // making a new rain drop in this column
+                rgb_frame_buffer[row][col] = max_intensity;
+            } else if (rgb_frame_buffer[row][col] > 0 && rgb_frame_buffer[row][col] < max_intensity) {
+                // neither fully bright nor dark, decay it
+                rgb_frame_buffer[row][col]--;
+            }
+            // set the pixel colour
+            uint8_t led[LED_HITS_TO_REMEMBER];
+            uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
 
-      // TODO: multiple leds are supported mapped to the same row/column
-      if (led_count > 0) {
-        if (rgb_frame_buffer[row][col] > pure_green_intensity) {
-          const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (rgb_frame_buffer[row][col] - pure_green_intensity) / (max_intensity - pure_green_intensity));
-          rgb_matrix_set_color(led[0], boost, max_intensity, boost);
-        }
-        else {
-          const uint8_t green = (uint8_t) ((uint16_t) max_intensity * rgb_frame_buffer[row][col] / pure_green_intensity);
-          rgb_matrix_set_color(led[0], 0, green, 0);
+            // TODO: multiple leds are supported mapped to the same row/column
+            if (led_count > 0) {
+                if (rgb_frame_buffer[row][col] > pure_green_intensity) {
+                    const uint8_t boost = (uint8_t)((uint16_t)max_brightness_boost * (rgb_frame_buffer[row][col] - pure_green_intensity) / (max_intensity - pure_green_intensity));
+                    rgb_matrix_set_color(led[0], boost, max_intensity, boost);
+                } else {
+                    const uint8_t green = (uint8_t)((uint16_t)max_intensity * rgb_frame_buffer[row][col] / pure_green_intensity);
+                    rgb_matrix_set_color(led[0], 0, green, 0);
+                }
+            }
         }
-      }
     }
-  }
 
-  if (++drop > drop_ticks) {
-    // reset drop timer
-    drop = 0;
-    for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) {
-      for (uint8_t col = 0; col < MATRIX_COLS; col++) {
-        // if ths is on the bottom row and bright allow decay
-        if (row == MATRIX_ROWS - 1 && rgb_frame_buffer[row][col] == max_intensity) {
-          rgb_frame_buffer[row][col]--;
-        }
-        // check if the pixel above is bright
-        if (rgb_frame_buffer[row - 1][col] == max_intensity) {
-          // allow old bright pixel to decay
-          rgb_frame_buffer[row - 1][col]--;
-          // make this pixel bright
-          rgb_frame_buffer[row][col] = max_intensity;
+    if (++drop > drop_ticks) {
+        // reset drop timer
+        drop = 0;
+        for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) {
+            for (uint8_t col = 0; col < MATRIX_COLS; col++) {
+                // if ths is on the bottom row and bright allow decay
+                if (row == MATRIX_ROWS - 1 && rgb_frame_buffer[row][col] == max_intensity) {
+                    rgb_frame_buffer[row][col]--;
+                }
+                // check if the pixel above is bright
+                if (rgb_frame_buffer[row - 1][col] == max_intensity) {
+                    // allow old bright pixel to decay
+                    rgb_frame_buffer[row - 1][col]--;
+                    // make this pixel bright
+                    rgb_frame_buffer[row][col] = max_intensity;
+                }
+            }
         }
-      }
     }
-  }
-  return false;
+    return false;
 }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN)
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN)
index 336a41b2ce69e73edc371b1826833d1545f6dfbf..ce948716815ab875ab20104815c75c83ad1c13de 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
 RGB_MATRIX_EFFECT(DUAL_BEACON)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV DUAL_BEACON_math(HSV hsv,  int8_t sin, int8_t cos, uint8_t i, uint8_t time) {
+static HSV DUAL_BEACON_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) {
     hsv.h += ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos + (g_led_config.point[i].x - k_rgb_matrix_center.x) * sin) / 128;
     return hsv;
 }
 
-bool DUAL_BEACON(effect_params_t* params) {
-    return effect_runner_sin_cos_i(params, &DUAL_BEACON_math);
-}
+bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_DUAL_BEACON
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_DUAL_BEACON
index 12848ab4cc7d35586efb204cd8cadeb93d206b21..0f1f8e23cf22bd6f672c0e584722b2af43ad3f6e 100644 (file)
@@ -1,22 +1,22 @@
 #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
 RGB_MATRIX_EFFECT(GRADIENT_UP_DOWN)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 bool GRADIENT_UP_DOWN(effect_params_t* params) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
 
-  HSV hsv = rgb_matrix_config.hsv;
-  uint8_t scale = scale8(64, rgb_matrix_config.speed);
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    // The y range will be 0..64, map this to 0..4
-    // Relies on hue being 8-bit and wrapping
-    hsv.h = rgb_matrix_config.hsv.h + scale * (g_led_config.point[i].y >> 4);
-    RGB rgb = hsv_to_rgb(hsv);
-    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    HSV     hsv   = rgb_matrix_config.hsv;
+    uint8_t scale = scale8(64, rgb_matrix_config.speed);
+    for (uint8_t i = led_min; i < led_max; i++) {
+        RGB_MATRIX_TEST_LED_FLAGS();
+        // The y range will be 0..64, map this to 0..4
+        // Relies on hue being 8-bit and wrapping
+        hsv.h   = rgb_matrix_config.hsv.h + scale * (g_led_config.point[i].y >> 4);
+        RGB rgb = hsv_to_rgb(hsv);
+        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
index bffa0a42d78542307f20e4b14452600c98f56508..5596146a380080762725457d91bbadb57dc47630 100644 (file)
@@ -1,29 +1,29 @@
 #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
 RGB_MATRIX_EFFECT(JELLYBEAN_RAINDROPS)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 static void jellybean_raindrops_set_color(int i, effect_params_t* params) {
-  if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return;
-  HSV hsv = { rand() & 0xFF , rand() & 0xFF, rgb_matrix_config.hsv.v };
-  RGB rgb = hsv_to_rgb(hsv);
-  rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+    if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return;
+    HSV hsv = {rand() & 0xFF, rand() & 0xFF, rgb_matrix_config.hsv.v};
+    RGB rgb = hsv_to_rgb(hsv);
+    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
 }
 
 bool JELLYBEAN_RAINDROPS(effect_params_t* params) {
-  if (!params->init) {
-    // Change one LED every tick, make sure speed is not 0
-    if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) {
-      jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL, params);
+    if (!params->init) {
+        // Change one LED every tick, make sure speed is not 0
+        if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) {
+            jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL, params);
+        }
+        return false;
     }
-    return false;
-  }
 
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
-  for (int i = led_min; i < led_max; i++) {
-    jellybean_raindrops_set_color(i, params);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    for (int i = led_min; i < led_max; i++) {
+        jellybean_raindrops_set_color(i, params);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
index f53c819a9e93cc897f41bfad12e6b0cf7c4b91ea..977261182f4d8097a6f9a5def2358b395f7319ff 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
 RGB_MATRIX_EFFECT(RAINBOW_BEACON)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV RAINBOW_BEACON_math(HSV hsv,  int8_t sin, int8_t cos, uint8_t i, uint8_t time) {
+static HSV RAINBOW_BEACON_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) {
     hsv.h += ((g_led_config.point[i].y - k_rgb_matrix_center.y) * 2 * cos + (g_led_config.point[i].x - k_rgb_matrix_center.x) * 2 * sin) / 128;
     return hsv;
 }
 
-bool RAINBOW_BEACON(effect_params_t* params) {
-    return effect_runner_sin_cos_i(params, &RAINBOW_BEACON_math);
-}
+bool RAINBOW_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &RAINBOW_BEACON_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_RAINBOW_BEACON
index e78c55e8dddee763317b7537d0abe131599e268c..e51e7b251621eaca82cf9c3e4ef8202604e5dcc4 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
 RGB_MATRIX_EFFECT(RAINBOW_MOVING_CHEVRON)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV RAINBOW_MOVING_CHEVRON_math(HSV hsv,  uint8_t i, uint8_t time) {
+static HSV RAINBOW_MOVING_CHEVRON_math(HSV hsv, uint8_t i, uint8_t time) {
     hsv.h += abs8(g_led_config.point[i].y - k_rgb_matrix_center.y) + (g_led_config.point[i].x - time);
     return hsv;
 }
 
-bool RAINBOW_MOVING_CHEVRON(effect_params_t* params) {
-    return effect_runner_i(params, &RAINBOW_MOVING_CHEVRON_math);
-}
+bool RAINBOW_MOVING_CHEVRON(effect_params_t* params) { return effect_runner_i(params, &RAINBOW_MOVING_CHEVRON_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
index 8298fec468dfe57ab71863070dd6a25b763dd774..4f69456c3acb0d8950c784a15015c7bd4ee92224 100644 (file)
@@ -1,15 +1,13 @@
 #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
 RGB_MATRIX_EFFECT(PINWHEELS)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV PINWHEELS_math(HSV hsv,  int8_t sin, int8_t cos, uint8_t i, uint8_t time) {
+static HSV PINWHEELS_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) {
     hsv.h += ((g_led_config.point[i].y - k_rgb_matrix_center.y) * 3 * cos + (56 - abs8(g_led_config.point[i].x - k_rgb_matrix_center.x)) * 3 * sin) / 128;
     return hsv;
 }
 
-bool PINWHEELS(effect_params_t* params) {
-    return effect_runner_sin_cos_i(params, &PINWHEELS_math);
-}
+bool PINWHEELS(effect_params_t* params) { return effect_runner_sin_cos_i(params, &PINWHEELS_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
index a4fed51658b75ca95e7ee7a36bc9185b292c92ed..9f839a1bce000b96170792faf81c806179835d01 100644 (file)
@@ -1,39 +1,39 @@
 #ifndef DISABLE_RGB_MATRIX_RAINDROPS
 RGB_MATRIX_EFFECT(RAINDROPS)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 static void raindrops_set_color(int i, effect_params_t* params) {
-  if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return;
-  HSV hsv = { 0 , rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v };
+    if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return;
+    HSV hsv = {0, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v};
 
-  // Take the shortest path between hues
-  int16_t deltaH = ((rgb_matrix_config.hsv.h + 180) % 360 - rgb_matrix_config.hsv.h) / 4;
-  if (deltaH > 127) {
-    deltaH -= 256;
-  } else if (deltaH < -127) {
-    deltaH += 256;
-  }
+    // Take the shortest path between hues
+    int16_t deltaH = ((rgb_matrix_config.hsv.h + 180) % 360 - rgb_matrix_config.hsv.h) / 4;
+    if (deltaH > 127) {
+        deltaH -= 256;
+    } else if (deltaH < -127) {
+        deltaH += 256;
+    }
 
-  hsv.h = rgb_matrix_config.hsv.h + (deltaH * (rand() & 0x03));
-  RGB rgb = hsv_to_rgb(hsv);
-  rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+    hsv.h   = rgb_matrix_config.hsv.h + (deltaH * (rand() & 0x03));
+    RGB rgb = hsv_to_rgb(hsv);
+    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
 }
 
 bool RAINDROPS(effect_params_t* params) {
-  if (!params->init) {
-    // Change one LED every tick, make sure speed is not 0
-    if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) {
-      raindrops_set_color(rand() % DRIVER_LED_TOTAL, params);
+    if (!params->init) {
+        // Change one LED every tick, make sure speed is not 0
+        if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) {
+            raindrops_set_color(rand() % DRIVER_LED_TOTAL, params);
+        }
+        return false;
     }
-    return false;
-  }
 
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
-  for (int i = led_min; i < led_max; i++) {
-    raindrops_set_color(i, params);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    for (int i = led_min; i < led_max; i++) {
+        raindrops_set_color(i, params);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_RAINDROPS
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // DISABLE_RGB_MATRIX_RAINDROPS
index 6e406380350997c9cb963c1082ea796d529a982b..c8f5e70e7a64f6ee9d86a9610aecb782fb2d9dcb 100644 (file)
@@ -2,14 +2,14 @@ RGB_MATRIX_EFFECT(SOLID_COLOR)
 #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
 bool SOLID_COLOR(effect_params_t* params) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
 
-  RGB rgb = hsv_to_rgb(rgb_matrix_config.hsv);
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    RGB rgb = hsv_to_rgb(rgb_matrix_config.hsv);
+    for (uint8_t i = led_min; i < led_max; i++) {
+        RGB_MATRIX_TEST_LED_FLAGS();
+        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
index dd49b6530eb6fba8c4c30a773fda11474bce412a..d45bb961bc5a8234853f83e4bff20b67dd1afdd0 100644 (file)
@@ -1,17 +1,15 @@
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
+#    ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
 RGB_MATRIX_EFFECT(SOLID_REACTIVE)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#        ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV SOLID_REACTIVE_math(HSV hsv,  uint16_t offset) {
+static HSV SOLID_REACTIVE_math(HSV hsv, uint16_t offset) {
     hsv.h += qsub8(130, offset);
     return hsv;
 }
 
-bool SOLID_REACTIVE(effect_params_t* params) {
-    return effect_runner_reactive(params, &SOLID_REACTIVE_math);
-}
+bool SOLID_REACTIVE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#        endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    endif      // DISABLE_RGB_MATRIX_SOLID_REACTIVE
+#endif          // RGB_MATRIX_KEYREACTIVE_ENABLED
index 5b9cfcbd52549a26e79d980fe02c1636775bd6e1..f76c68e8c747da0ddd9d0f81f73194d77cb911c0 100644 (file)
@@ -1,41 +1,36 @@
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-#if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS)
+#    if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS)
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
+#        ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
 RGB_MATRIX_EFFECT(SOLID_REACTIVE_CROSS)
-#endif
+#        endif
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
+#        ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
 RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTICROSS)
-#endif
+#        endif
 
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#        ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV SOLID_REACTIVE_CROSS_math(HSV hsv,  int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
+static HSV SOLID_REACTIVE_CROSS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
     uint16_t effect = tick + dist;
-    dx = dx < 0 ? dx * -1 : dx;
-    dy = dy < 0 ? dy * -1 : dy;
-    dx = dx * 16 > 255 ? 255 : dx * 16;
-    dy = dy * 16 > 255 ? 255 : dy * 16;
+    dx              = dx < 0 ? dx * -1 : dx;
+    dy              = dy < 0 ? dy * -1 : dy;
+    dx              = dx * 16 > 255 ? 255 : dx * 16;
+    dy              = dy * 16 > 255 ? 255 : dy * 16;
     effect += dx > dy ? dy : dx;
-    if (effect > 255)
-        effect = 255;
+    if (effect > 255) effect = 255;
     hsv.v = qadd8(hsv.v, 255 - effect);
     return hsv;
 }
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
-bool SOLID_REACTIVE_CROSS(effect_params_t* params) {
-    return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math);
-}
-#endif
+#            ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
+bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); }
+#            endif
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
-bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) {
-    return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math);
-}
-#endif
+#            ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
+bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); }
+#            endif
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS)
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#        endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    endif      // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS)
+#endif          // RGB_MATRIX_KEYREACTIVE_ENABLED
index e90eaf4b289eb47c0c3e5e5926a28d7539afce78..17f94e3c1800785cfe892699e83745bae325205e 100644 (file)
@@ -1,41 +1,34 @@
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-#if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS)
+#    if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS)
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
+#        ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
 RGB_MATRIX_EFFECT(SOLID_REACTIVE_NEXUS)
-#endif
+#        endif
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
+#        ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
 RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTINEXUS)
-#endif
+#        endif
 
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#        ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV SOLID_REACTIVE_NEXUS_math(HSV hsv,  int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
+static HSV SOLID_REACTIVE_NEXUS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
     uint16_t effect = tick - dist;
-    if (effect > 255)
-        effect = 255;
-    if (dist > 72)
-        effect = 255;
-    if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8))
-        effect = 255;
+    if (effect > 255) effect = 255;
+    if (dist > 72) effect = 255;
+    if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255;
     hsv.v = qadd8(hsv.v, 255 - effect);
     hsv.h = rgb_matrix_config.hsv.h + dy / 4;
     return hsv;
 }
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
-bool SOLID_REACTIVE_NEXUS(effect_params_t* params) {
-    return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math);
-}
-#endif
+#            ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
+bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); }
+#            endif
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
-bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) {
-    return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math);
-}
-#endif
+#            ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
+bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); }
+#            endif
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS)
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#        endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    endif      // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS)
+#endif          // RGB_MATRIX_KEYREACTIVE_ENABLED
index 77c8ff672402eba3b3c43126055a1241e05964c7..12eb248cc0b2728e1e537d5d7c5e7c4e6067ad72 100644 (file)
@@ -1,17 +1,15 @@
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
+#    ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
 RGB_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#        ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV SOLID_REACTIVE_SIMPLE_math(HSV hsv,  uint16_t offset) {
+static HSV SOLID_REACTIVE_SIMPLE_math(HSV hsv, uint16_t offset) {
     hsv.v = scale8(255 - offset, hsv.v);
     return hsv;
 }
 
-bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) {
-    return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math);
-}
+bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#        endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    endif      // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
+#endif          // RGB_MATRIX_KEYREACTIVE_ENABLED
index 73779dfa74e83786e503abad5bbf6c6ba9007d50..1cc4dca728e723f07290980410a7be36c5f13786 100644 (file)
@@ -1,36 +1,31 @@
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-#if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE)
+#    if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE)
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
+#        ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
 RGB_MATRIX_EFFECT(SOLID_REACTIVE_WIDE)
-#endif
+#        endif
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
+#        ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
 RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE)
-#endif
+#        endif
 
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#        ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static HSV SOLID_REACTIVE_WIDE_math(HSV hsv,  int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
+static HSV SOLID_REACTIVE_WIDE_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
     uint16_t effect = tick + dist * 5;
-    if (effect > 255)
-        effect = 255;
+    if (effect > 255) effect = 255;
     hsv.v = qadd8(hsv.v, 255 - effect);
     return hsv;
 }
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
-bool SOLID_REACTIVE_WIDE(effect_params_t* params) {
-    return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math);
-}
-#endif
+#            ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
+bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); }
+#            endif
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
-bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) {
-    return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math);
-}
-#endif
+#            ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
+bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); }
+#            endif
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE)
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#        endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    endif      // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE)
+#endif          // RGB_MATRIX_KEYREACTIVE_ENABLED
index 441f35576b0f5b6997c8fc0ccc63d981d7c27faa..99efb4996aa8d559bf3e06ff248f926ba730c0da 100644 (file)
@@ -1,36 +1,31 @@
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-#if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH)
+#    if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH)
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
+#        ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
 RGB_MATRIX_EFFECT(SOLID_SPLASH)
-#endif
+#        endif
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
+#        ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
 RGB_MATRIX_EFFECT(SOLID_MULTISPLASH)
-#endif
+#        endif
 
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#        ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-HSV SOLID_SPLASH_math(HSV hsv,  int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
+HSV SOLID_SPLASH_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
     uint16_t effect = tick - dist;
-    if (effect > 255)
-        effect = 255;
+    if (effect > 255) effect = 255;
     hsv.v = qadd8(hsv.v, 255 - effect);
     return hsv;
 }
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
-bool SOLID_SPLASH(effect_params_t* params) {
-    return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math);
-}
-#endif
+#            ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
+bool SOLID_SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); }
+#            endif
 
-#ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
-bool SOLID_MULTISPLASH(effect_params_t* params) {
-    return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math);
-}
-#endif
+#            ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
+bool SOLID_MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); }
+#            endif
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // !defined(DISABLE_RGB_MATRIX_SPLASH) && !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#        endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    endif      // !defined(DISABLE_RGB_MATRIX_SPLASH) && !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
+#endif          // RGB_MATRIX_KEYREACTIVE_ENABLED
index 19ccb256e957761a7b231e072da606ac23b2e676..1415bcc0fa41e1bb48df157a2e3a6d660f897a91 100644 (file)
@@ -1,37 +1,32 @@
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
-#if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
+#    if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
 
-#ifndef DISABLE_RGB_MATRIX_SPLASH
+#        ifndef DISABLE_RGB_MATRIX_SPLASH
 RGB_MATRIX_EFFECT(SPLASH)
-#endif
+#        endif
 
-#ifndef DISABLE_RGB_MATRIX_MULTISPLASH
+#        ifndef DISABLE_RGB_MATRIX_MULTISPLASH
 RGB_MATRIX_EFFECT(MULTISPLASH)
-#endif
+#        endif
 
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#        ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-HSV SPLASH_math(HSV hsv,  int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
+HSV SPLASH_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
     uint16_t effect = tick - dist;
-    if (effect > 255)
-        effect = 255;
+    if (effect > 255) effect = 255;
     hsv.h += effect;
     hsv.v = qadd8(hsv.v, 255 - effect);
     return hsv;
 }
 
-#ifndef DISABLE_RGB_MATRIX_SPLASH
-bool SPLASH(effect_params_t* params) {
-    return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SPLASH_math);
-}
-#endif
+#            ifndef DISABLE_RGB_MATRIX_SPLASH
+bool SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SPLASH_math); }
+#            endif
 
-#ifndef DISABLE_RGB_MATRIX_MULTISPLASH
-bool MULTISPLASH(effect_params_t* params) {
-    return effect_runner_reactive_splash(0, params, &SPLASH_math);
-}
-#endif
+#            ifndef DISABLE_RGB_MATRIX_MULTISPLASH
+bool MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SPLASH_math); }
+#            endif
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#        endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    endif      // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
+#endif          // RGB_MATRIX_KEYREACTIVE_ENABLED
index 374b7fea0cf105a60c3bdc6028fc4a8a510f47e8..dd313f16a5bc4bf2fb8b21d622db7f28e045d7f8 100644 (file)
@@ -1,74 +1,65 @@
 #if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
 RGB_MATRIX_EFFECT(TYPING_HEATMAP)
-#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-void process_rgb_matrix_typing_heatmap(keyrecord_t *record) {
-    uint8_t row = record->event.key.row;
-    uint8_t col = record->event.key.col;
+void process_rgb_matrix_typing_heatmap(keyrecord_trecord) {
+    uint8_t row   = record->event.key.row;
+    uint8_t col   = record->event.key.col;
     uint8_t m_row = row - 1;
     uint8_t p_row = row + 1;
     uint8_t m_col = col - 1;
     uint8_t p_col = col + 1;
 
-    if (m_col < col)
-      rgb_frame_buffer[row][m_col] = qadd8(rgb_frame_buffer[row][m_col], 16);
+    if (m_col < col) rgb_frame_buffer[row][m_col] = qadd8(rgb_frame_buffer[row][m_col], 16);
     rgb_frame_buffer[row][col] = qadd8(rgb_frame_buffer[row][col], 32);
-    if (p_col < MATRIX_COLS)
-      rgb_frame_buffer[row][p_col] = qadd8(rgb_frame_buffer[row][p_col], 16);
+    if (p_col < MATRIX_COLS) rgb_frame_buffer[row][p_col] = qadd8(rgb_frame_buffer[row][p_col], 16);
 
     if (p_row < MATRIX_ROWS) {
-      if (m_col < col)
-        rgb_frame_buffer[p_row][m_col] = qadd8(rgb_frame_buffer[p_row][m_col], 13);
-      rgb_frame_buffer[p_row][col] = qadd8(rgb_frame_buffer[p_row][col], 16);
-      if (p_col < MATRIX_COLS)
-        rgb_frame_buffer[p_row][p_col] = qadd8(rgb_frame_buffer[p_row][p_col], 13);
+        if (m_col < col) rgb_frame_buffer[p_row][m_col] = qadd8(rgb_frame_buffer[p_row][m_col], 13);
+        rgb_frame_buffer[p_row][col] = qadd8(rgb_frame_buffer[p_row][col], 16);
+        if (p_col < MATRIX_COLS) rgb_frame_buffer[p_row][p_col] = qadd8(rgb_frame_buffer[p_row][p_col], 13);
     }
 
     if (m_row < row) {
-      if (m_col < col)
-        rgb_frame_buffer[m_row][m_col] = qadd8(rgb_frame_buffer[m_row][m_col], 13);
-      rgb_frame_buffer[m_row][col] = qadd8(rgb_frame_buffer[m_row][col], 16);
-      if (p_col < MATRIX_COLS)
-        rgb_frame_buffer[m_row][p_col] = qadd8(rgb_frame_buffer[m_row][p_col], 13);
+        if (m_col < col) rgb_frame_buffer[m_row][m_col] = qadd8(rgb_frame_buffer[m_row][m_col], 13);
+        rgb_frame_buffer[m_row][col] = qadd8(rgb_frame_buffer[m_row][col], 16);
+        if (p_col < MATRIX_COLS) rgb_frame_buffer[m_row][p_col] = qadd8(rgb_frame_buffer[m_row][p_col], 13);
     }
 }
 
 bool TYPING_HEATMAP(effect_params_t* params) {
-  // Modified version of RGB_MATRIX_USE_LIMITS to work off of matrix row / col size
-  uint8_t led_min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter;
-  uint8_t led_max = led_min + RGB_MATRIX_LED_PROCESS_LIMIT;
-  if (led_max > sizeof(rgb_frame_buffer))
-    led_max = sizeof(rgb_frame_buffer);
+    // Modified version of RGB_MATRIX_USE_LIMITS to work off of matrix row / col size
+    uint8_t led_min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter;
+    uint8_t led_max = led_min + RGB_MATRIX_LED_PROCESS_LIMIT;
+    if (led_max > sizeof(rgb_frame_buffer)) led_max = sizeof(rgb_frame_buffer);
 
-  if (params->init) {
-    rgb_matrix_set_color_all(0, 0, 0);
-    memset(rgb_frame_buffer, 0, sizeof rgb_frame_buffer);
-  }
+    if (params->init) {
+        rgb_matrix_set_color_all(0, 0, 0);
+        memset(rgb_frame_buffer, 0, sizeof rgb_frame_buffer);
+    }
 
-  // Render heatmap & decrease
-  for (int i = led_min; i < led_max; i++) {
-    uint8_t row = i % MATRIX_ROWS;
-    uint8_t col = i / MATRIX_ROWS;
-    uint8_t val = rgb_frame_buffer[row][col];
+    // Render heatmap & decrease
+    for (int i = led_min; i < led_max; i++) {
+        uint8_t row = i % MATRIX_ROWS;
+        uint8_t col = i / MATRIX_ROWS;
+        uint8_t val = rgb_frame_buffer[row][col];
 
-    // set the pixel colour
-    uint8_t led[LED_HITS_TO_REMEMBER];
-    uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
-    for (uint8_t j = 0; j < led_count; ++j)
-    {
-      if (!HAS_ANY_FLAGS(g_led_config.flags[led[j]], params->flags))
-        continue;
+        // set the pixel colour
+        uint8_t led[LED_HITS_TO_REMEMBER];
+        uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
+        for (uint8_t j = 0; j < led_count; ++j) {
+            if (!HAS_ANY_FLAGS(g_led_config.flags[led[j]], params->flags)) continue;
 
-      HSV hsv = { 170 - qsub8(val, 85), rgb_matrix_config.hsv.s, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.hsv.v) };
-      RGB rgb = hsv_to_rgb(hsv);
-      rgb_matrix_set_color(led[j], rgb.r, rgb.g, rgb.b);
-    }
+            HSV hsv = {170 - qsub8(val, 85), rgb_matrix_config.hsv.s, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.hsv.v)};
+            RGB rgb = hsv_to_rgb(hsv);
+            rgb_matrix_set_color(led[j], rgb.r, rgb.g, rgb.b);
+        }
 
-    rgb_frame_buffer[row][col] = qsub8(val, 1);
-  }
+        rgb_frame_buffer[row][col] = qsub8(val, 1);
+    }
 
-  return led_max < sizeof(rgb_frame_buffer);
+    return led_max < sizeof(rgb_frame_buffer);
 }
 
-#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
+#    endif  // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
+#endif      // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
index 4d8f05892cdf750ccf5e5e55fe2f8a72fabab6d6..5b54bd5956d7f27b7840ac029b49cc7c0eef8d5e 100644 (file)
 
 #if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737)
 
-#include "i2c_master.h"
+#    include "i2c_master.h"
 
-static void init( void )
-{
+static void init(void) {
     i2c_init();
-#ifdef IS31FL3731
-    IS31FL3731_init( DRIVER_ADDR_1 );
-    IS31FL3731_init( DRIVER_ADDR_2 );
-#elif defined(IS31FL3733)
-    IS31FL3733_init( DRIVER_ADDR_1, 0 );
-#else
-    IS31FL3737_init( DRIVER_ADDR_1 );
-#endif
-    for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) {
+#    ifdef IS31FL3731
+    IS31FL3731_init(DRIVER_ADDR_1);
+    IS31FL3731_init(DRIVER_ADDR_2);
+#    elif defined(IS31FL3733)
+    IS31FL3733_init(DRIVER_ADDR_1, 0);
+#    else
+    IS31FL3737_init(DRIVER_ADDR_1);
+#    endif
+    for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
         bool enabled = true;
         // This only caches it for later
-#ifdef IS31FL3731
-        IS31FL3731_set_led_control_register( index, enabled, enabled, enabled );
-#elif defined(IS31FL3733)
-        IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
-#else
-        IS31FL3737_set_led_control_register( index, enabled, enabled, enabled );
-#endif
+#    ifdef IS31FL3731
+        IS31FL3731_set_led_control_register(index, enabled, enabled, enabled);
+#    elif defined(IS31FL3733)
+        IS31FL3733_set_led_control_register(index, enabled, enabled, enabled);
+#    else
+        IS31FL3737_set_led_control_register(index, enabled, enabled, enabled);
+#    endif
     }
     // This actually updates the LED drivers
-#ifdef IS31FL3731
-    IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, 0 );
-    IS31FL3731_update_led_control_registers( DRIVER_ADDR_2, 1 );
-#elif defined(IS31FL3733)
-    IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, 0 );
-    IS31FL3733_update_led_control_registers( DRIVER_ADDR_2, 1 );
-#else
-    IS31FL3737_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
-#endif
+#    ifdef IS31FL3731
+    IS31FL3731_update_led_control_registers(DRIVER_ADDR_1, 0);
+    IS31FL3731_update_led_control_registers(DRIVER_ADDR_2, 1);
+#    elif defined(IS31FL3733)
+    IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0);
+    IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1);
+#    else
+    IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2);
+#    endif
 }
 
-#ifdef IS31FL3731
-static void flush( void )
-{
-    IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, 0 ); 
-    IS31FL3731_update_pwm_buffers( DRIVER_ADDR_2, 1 );
+#    ifdef IS31FL3731
+static void flush(void) {
+    IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, 0);
+    IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2, 1);
 }
 
 const rgb_matrix_driver_t rgb_matrix_driver = {
-    .init = init,
-    .flush = flush,
-    .set_color = IS31FL3731_set_color,
+    .init          = init,
+    .flush         = flush,
+    .set_color     = IS31FL3731_set_color,
     .set_color_all = IS31FL3731_set_color_all,
 };
-#elif defined(IS31FL3733)
-static void flush( void )
-{
-    IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, 0);
-    IS31FL3733_update_pwm_buffers( DRIVER_ADDR_2, 1);
+#    elif defined(IS31FL3733)
+static void flush(void) {
+    IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0);
+    IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1);
 }
 
 const rgb_matrix_driver_t rgb_matrix_driver = {
@@ -87,11 +84,8 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
     .set_color = IS31FL3733_set_color,
     .set_color_all = IS31FL3733_set_color_all,
 };
-#else
-static void flush( void )
-{
-    IS31FL3737_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
-}
+#    else
+static void flush(void) { IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); }
 
 const rgb_matrix_driver_t rgb_matrix_driver = {
     .init = init,
@@ -99,27 +93,23 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
     .set_color = IS31FL3737_set_color,
     .set_color_all = IS31FL3737_set_color_all,
 };
-#endif
+#    endif
 
 #elif defined(WS2812)
 
 extern LED_TYPE led[DRIVER_LED_TOTAL];
 
-  static void flush( void )
-  {
+static void flush(void) {
     // Assumes use of RGB_DI_PIN
     ws2812_setleds(led, DRIVER_LED_TOTAL);
-  }
-
-  static void init( void )
-  {
+}
 
-  }
+static void init(void) {}
 
-  const rgb_matrix_driver_t rgb_matrix_driver = {
-      .init = init,
-      .flush = flush,
-      .set_color = ws2812_setled,
-      .set_color_all = ws2812_setled_all,
-  };
+const rgb_matrix_driver_t rgb_matrix_driver = {
+    .init          = init,
+    .flush         = flush,
+    .set_color     = ws2812_setled,
+    .set_color_all = ws2812_setled_all,
+};
 #endif
index 9650c9a1316408561a24f43bebf476aaae0d926d..3d312190a525ff3dd530cbda8993bd4bc88c6964 100644 (file)
@@ -3,15 +3,15 @@
 typedef HSV (*dx_dy_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t time);
 
 bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
 
-  uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2);
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x;
-    int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y;
-    RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, time));
-    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2);
+    for (uint8_t i = led_min; i < led_max; i++) {
+        RGB_MATRIX_TEST_LED_FLAGS();
+        int16_t dx  = g_led_config.point[i].x - k_rgb_matrix_center.x;
+        int16_t dy  = g_led_config.point[i].y - k_rgb_matrix_center.y;
+        RGB     rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, time));
+        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
index eb0c4d8dd332f3457c10f45dd341fa54b28480a3..1f4767e3214c20d48788dc3706052a6769076a50 100644 (file)
@@ -3,16 +3,16 @@
 typedef HSV (*dx_dy_dist_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time);
 
 bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
 
-  uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2);
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x;
-    int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y;
-    uint8_t dist = sqrt16(dx * dx + dy * dy);
-    RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, dist, time));
-    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2);
+    for (uint8_t i = led_min; i < led_max; i++) {
+        RGB_MATRIX_TEST_LED_FLAGS();
+        int16_t dx   = g_led_config.point[i].x - k_rgb_matrix_center.x;
+        int16_t dy   = g_led_config.point[i].y - k_rgb_matrix_center.y;
+        uint8_t dist = sqrt16(dx * dx + dy * dy);
+        RGB     rgb  = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, dist, time));
+        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
index d4a7ef392aa1c0f962e0196a4daca78fcd5b26a7..eebfb78c028a4717c4aa7ca1007aa71fa2eaaa8a 100644 (file)
@@ -3,13 +3,13 @@
 typedef HSV (*i_f)(HSV hsv, uint8_t i, uint8_t time);
 
 bool effect_runner_i(effect_params_t* params, i_f effect_func) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
 
-  uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
-    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
+    for (uint8_t i = led_min; i < led_max; i++) {
+        RGB_MATRIX_TEST_LED_FLAGS();
+        RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
+        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
index 9da2814ce8555c2a74ef504dc26e3c60f51283b1..53e77e3fb2628dfdc62f827e66df6108c46252b7 100644 (file)
@@ -7,23 +7,23 @@ typedef HSV (*reactive_f)(HSV hsv, uint16_t offset);
 bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) {
     RGB_MATRIX_USE_LIMITS(led_min, led_max);
 
-  uint16_t max_tick = 65535 / rgb_matrix_config.speed;
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    uint16_t tick = max_tick;
-    // Reverse search to find most recent key hit
-    for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) {
-      if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) {
-        tick = g_last_hit_tracker.tick[j];
-        break;
-      }
-    }
+    uint16_t max_tick = 65535 / rgb_matrix_config.speed;
+    for (uint8_t i = led_min; i < led_max; i++) {
+        RGB_MATRIX_TEST_LED_FLAGS();
+        uint16_t tick = max_tick;
+        // Reverse search to find most recent key hit
+        for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) {
+            if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) {
+                tick = g_last_hit_tracker.tick[j];
+                break;
+            }
+        }
 
-    uint16_t  offset = scale16by8(tick, rgb_matrix_config.speed);
-    RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, offset));
-    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+        uint16_t offset = scale16by8(tick, rgb_matrix_config.speed);
+        RGB      rgb    = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, offset));
+        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
 
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#endif  // RGB_MATRIX_KEYREACTIVE_ENABLED
index 4f2059c99c383bbdc8f9ee81124c8a8a0db175b2..b5d284a40fb40bafb8b03738c96af503a92aeeb6 100644 (file)
@@ -5,25 +5,25 @@
 typedef HSV (*reactive_splash_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick);
 
 bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, reactive_splash_f effect_func) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
 
-  uint8_t count = g_last_hit_tracker.count;
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    HSV hsv = rgb_matrix_config.hsv;
-    hsv.v = 0;
-    for (uint8_t j = start; j < count; j++) {
-      int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j];
-      int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j];
-      uint8_t dist = sqrt16(dx * dx + dy * dy);
-      uint16_t tick = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed);
-      hsv = effect_func(hsv, dx, dy, dist, tick);
+    uint8_t count = g_last_hit_tracker.count;
+    for (uint8_t i = led_min; i < led_max; i++) {
+        RGB_MATRIX_TEST_LED_FLAGS();
+        HSV hsv = rgb_matrix_config.hsv;
+        hsv.v   = 0;
+        for (uint8_t j = start; j < count; j++) {
+            int16_t  dx   = g_led_config.point[i].x - g_last_hit_tracker.x[j];
+            int16_t  dy   = g_led_config.point[i].y - g_last_hit_tracker.y[j];
+            uint8_t  dist = sqrt16(dx * dx + dy * dy);
+            uint16_t tick = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed);
+            hsv           = effect_func(hsv, dx, dy, dist, tick);
+        }
+        hsv.v   = scale8(hsv.v, rgb_matrix_config.hsv.v);
+        RGB rgb = hsv_to_rgb(hsv);
+        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
     }
-    hsv.v = scale8(hsv.v, rgb_matrix_config.hsv.v);
-    RGB rgb = hsv_to_rgb(hsv);
-    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    return led_max < DRIVER_LED_TOTAL;
 }
 
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#endif  // RGB_MATRIX_KEYREACTIVE_ENABLED
index e68a7a968c7abf874d61e482d276c13b16a9b0a0..c02352b86d5c4e064c2e166e4e9bf36b2ce3aef1 100644 (file)
@@ -3,15 +3,15 @@
 typedef HSV (*sin_cos_i_f)(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time);
 
 bool effect_runner_sin_cos_i(effect_params_t* params, sin_cos_i_f effect_func) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
 
-  uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
-  int8_t cos_value = cos8(time) - 128;
-  int8_t sin_value = sin8(time) - 128;
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, cos_value, sin_value, i, time));
-    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
-  }
-  return led_max < DRIVER_LED_TOTAL;
+    uint16_t time      = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
+    int8_t   cos_value = cos8(time) - 128;
+    int8_t   sin_value = sin8(time) - 128;
+    for (uint8_t i = led_min; i < led_max; i++) {
+        RGB_MATRIX_TEST_LED_FLAGS();
+        RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, cos_value, sin_value, i, time));
+        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+    }
+    return led_max < DRIVER_LED_TOTAL;
 }
index 04a84f4ac753bf9d9a55516730789155b238444f..fc23f55d0eb73a7da5b4dcdb2fc7dd76696131eb 100644 (file)
@@ -5,59 +5,54 @@
 #include "color.h"
 
 #if defined(__GNUC__)
-#define PACKED __attribute__ ((__packed__))
+#    define PACKED __attribute__((__packed__))
 #else
-#define PACKED
+#    define PACKED
 #endif
 
 #if defined(_MSC_VER)
-#pragma pack( push, 1 )
+#    pragma pack(push, 1)
 #endif
 
 #if defined(RGB_MATRIX_KEYPRESSES) || defined(RGB_MATRIX_KEYRELEASES)
-  #define RGB_MATRIX_KEYREACTIVE_ENABLED
+#    define RGB_MATRIX_KEYREACTIVE_ENABLED
 #endif
 
 // Last led hit
 #ifndef LED_HITS_TO_REMEMBER
-  #define LED_HITS_TO_REMEMBER 8
-#endif // LED_HITS_TO_REMEMBER
+#    define LED_HITS_TO_REMEMBER 8
+#endif  // LED_HITS_TO_REMEMBER
 
 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
 typedef struct PACKED {
-  uint8_t count;
-  uint8_t x[LED_HITS_TO_REMEMBER];
-  uint8_t y[LED_HITS_TO_REMEMBER];
-  uint8_t index[LED_HITS_TO_REMEMBER];
-  uint16_t tick[LED_HITS_TO_REMEMBER];
+    uint8_t  count;
+    uint8_t  x[LED_HITS_TO_REMEMBER];
+    uint8_t  y[LED_HITS_TO_REMEMBER];
+    uint8_t  index[LED_HITS_TO_REMEMBER];
+    uint16_t tick[LED_HITS_TO_REMEMBER];
 } last_hit_t;
-#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+#endif  // RGB_MATRIX_KEYREACTIVE_ENABLED
 
-typedef enum rgb_task_states {
-  STARTING,
-  RENDERING,
-  FLUSHING,
-  SYNCING
-} rgb_task_states;
+typedef enum rgb_task_states { STARTING, RENDERING, FLUSHING, SYNCING } rgb_task_states;
 
 typedef uint8_t led_flags_t;
 
 typedef struct PACKED {
-  uint8_t iter;
-  led_flags_t flags;
-  bool init;
+    uint8_t     iter;
+    led_flags_t flags;
+    bool        init;
 } effect_params_t;
 
 typedef struct PACKED {
-  // Global tick at 20 Hz
-  uint32_t tick;
-  // Ticks since this key was last hit.
-  uint32_t any_key_hit;
+    // Global tick at 20 Hz
+    uint32_t tick;
+    // Ticks since this key was last hit.
+    uint32_t any_key_hit;
 } rgb_counters_t;
 
 typedef struct PACKED {
-       uint8_t x;
-       uint8_t y;
+    uint8_t x;
+    uint8_t y;
 } point_t;
 
 #define HAS_FLAGS(bits, flags) ((bits & flags) == flags)
@@ -72,21 +67,21 @@ typedef struct PACKED {
 #define NO_LED 255
 
 typedef struct PACKED {
-  uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS];
-  point_t point[DRIVER_LED_TOTAL];
-  uint8_t flags[DRIVER_LED_TOTAL];
+    uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS];
+    point_t point[DRIVER_LED_TOTAL];
+    uint8_t flags[DRIVER_LED_TOTAL];
 } led_config_t;
 
 typedef union {
-  uint32_t raw;
-  struct PACKED {
-    uint8_t  enable  :2;
-    uint8_t  mode    :6;
-    HSV      hsv;
-    uint8_t  speed;  //EECONFIG needs to be increased to support this
-  };
+    uint32_t raw;
+    struct PACKED {
+        uint8_t enable : 2;
+        uint8_t mode : 6;
+        HSV     hsv;
+        uint8_t speed;  // EECONFIG needs to be increased to support this
+    };
 } rgb_config_t;
 
 #if defined(_MSC_VER)
-#pragma pack( pop )
+#    pragma pack(pop)
 #endif
index f569d6b9e3f4f35b1fe7711f11472845baf6fb72..a094863fe9b436ab8ae9c597dd3ef50d5c240dba 100644 (file)
 #include <math.h>
 #include <string.h>
 #ifdef __AVR__
-  #include <avr/eeprom.h>
-  #include <avr/interrupt.h>
+#    include <avr/eeprom.h>
+#    include <avr/interrupt.h>
 #endif
 #ifdef STM32_EEPROM_ENABLE
-  #include "hal.h"
-  #include "eeprom.h"
-  #include "eeprom_stm32.h"
+#    include "hal.h"
+#    include "eeprom.h"
+#    include "eeprom_stm32.h"
 #endif
 #include "wait.h"
 #include "progmem.h"
 #include "led_tables.h"
 #include "lib/lib8tion/lib8tion.h"
 #ifdef VELOCIKEY_ENABLE
-  #include "velocikey.h"
+#    include "velocikey.h"
 #endif
 
 #ifdef RGBLIGHT_SPLIT
-  /* for split keyboard */
-  #define RGBLIGHT_SPLIT_SET_CHANGE_MODE         rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE
-  #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS         rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS
-  #define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS     rgblight_status.change_flags |= (RGBLIGHT_STATUS_CHANGE_MODE|RGBLIGHT_STATUS_CHANGE_HSVS)
-  #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER
-  #define RGBLIGHT_SPLIT_ANIMATION_TICK          rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK
+/* for split keyboard */
+#    define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE
+#    define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS
+#    define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS rgblight_status.change_flags |= (RGBLIGHT_STATUS_CHANGE_MODE | RGBLIGHT_STATUS_CHANGE_HSVS)
+#    define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER
+#    define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK
 #else
-  #define RGBLIGHT_SPLIT_SET_CHANGE_MODE
-  #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS
-  #define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS
-  #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE
-  #define RGBLIGHT_SPLIT_ANIMATION_TICK
+#    define RGBLIGHT_SPLIT_SET_CHANGE_MODE
+#    define RGBLIGHT_SPLIT_SET_CHANGE_HSVS
+#    define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS
+#    define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE
+#    define RGBLIGHT_SPLIT_ANIMATION_TICK
 #endif
 
-#define _RGBM_SINGLE_STATIC(sym)   RGBLIGHT_MODE_ ## sym,
+#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_##sym,
 #define _RGBM_SINGLE_DYNAMIC(sym)
-#define _RGBM_MULTI_STATIC(sym)    RGBLIGHT_MODE_ ## sym,
+#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_##sym,
 #define _RGBM_MULTI_DYNAMIC(sym)
-#define _RGBM_TMP_STATIC(sym, msym)      RGBLIGHT_MODE_ ## sym,
+#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_##sym,
 #define _RGBM_TMP_DYNAMIC(sym, msym)
-static uint8_t static_effect_table [] = {
+static uint8_t static_effect_table[] = {
 #include "rgblight_modes.h"
 };
 
-#define _RGBM_SINGLE_STATIC(sym)   RGBLIGHT_MODE_ ## sym,
-#define _RGBM_SINGLE_DYNAMIC(sym)  RGBLIGHT_MODE_ ## sym,
-#define _RGBM_MULTI_STATIC(sym)    RGBLIGHT_MODE_ ## sym,
-#define _RGBM_MULTI_DYNAMIC(sym)   RGBLIGHT_MODE_ ## sym,
-#define _RGBM_TMP_STATIC(sym, msym)  RGBLIGHT_MODE_ ## msym,
-#define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_ ## msym,
-static uint8_t mode_base_table [] = {
-    0, // RGBLIGHT_MODE_zero
+#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_##sym,
+#define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_##sym,
+#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_##sym,
+#define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_##sym,
+#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_##msym,
+#define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_##msym,
+static uint8_t mode_base_table[] = {
+    0,  // RGBLIGHT_MODE_zero
 #include "rgblight_modes.h"
 };
 
-static inline int is_static_effect(uint8_t mode) {
-    return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL;
-}
+static inline int is_static_effect(uint8_t mode) { return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; }
 
 #ifdef RGBLIGHT_LED_MAP
 const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP;
 #endif
 
 #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
-__attribute__ ((weak))
-const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 170, 127, 85, 64};
+__attribute__((weak)) const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 170, 127, 85, 64};
 #endif
 
 rgblight_config_t rgblight_config;
-rgblight_status_t rgblight_status = { .timer_enabled = false };
-bool is_rgblight_initialized = false;
+rgblight_status_t rgblight_status         = {.timer_enabled = false};
+bool              is_rgblight_initialized = false;
 
 #ifdef RGBLIGHT_USE_TIMER
 animation_status_t animation_status = {};
@@ -95,596 +92,533 @@ animation_status_t animation_status = {};
 
 #ifndef LED_ARRAY
 LED_TYPE led[RGBLED_NUM];
-  #define LED_ARRAY led
+#    define LED_ARRAY led
 #endif
 
-
 static uint8_t clipping_start_pos = 0;
-static uint8_t clipping_num_leds = RGBLED_NUM;
-static uint8_t effect_start_pos = 0;
-static uint8_t effect_end_pos = RGBLED_NUM;
-static uint8_t effect_num_leds = RGBLED_NUM;
+static uint8_t clipping_num_leds  = RGBLED_NUM;
+static uint8_t effect_start_pos   = 0;
+static uint8_t effect_end_pos     = RGBLED_NUM;
+static uint8_t effect_num_leds    = RGBLED_NUM;
 
 void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) {
-  clipping_start_pos = start_pos;
-  clipping_num_leds = num_leds;
+    clipping_start_pos = start_pos;
+    clipping_num_leds  = num_leds;
 }
 
 void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) {
-  if (start_pos >= RGBLED_NUM) return;
-  if (start_pos + num_leds > RGBLED_NUM) return;
-  effect_start_pos = start_pos;
-  effect_end_pos = start_pos + num_leds;
-  effect_num_leds = num_leds;
+    if (start_pos >= RGBLED_NUM) return;
+    if (start_pos + num_leds > RGBLED_NUM) return;
+    effect_start_pos = start_pos;
+    effect_end_pos   = start_pos + num_leds;
+    effect_num_leds  = num_leds;
 }
 
 void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) {
-  HSV hsv = { hue, sat, val };
-  RGB rgb = hsv_to_rgb(hsv);
-  setrgb(rgb.r, rgb.g, rgb.b, led1);
+    HSV hsv = {hue, sat, val};
+    RGB rgb = hsv_to_rgb(hsv);
+    setrgb(rgb.r, rgb.g, rgb.b, led1);
 }
 
-void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) {
-  sethsv_raw( hue, sat,
-              val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val,
-              led1);
-}
+void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { sethsv_raw(hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, led1); }
 
 void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) {
-  (*led1).r = r;
-  (*led1).g = g;
-  (*led1).b = b;
+    (*led1).r = r;
+    (*led1).g = g;
+    (*led1).b = b;
 }
 
 void rgblight_check_config(void) {
-  /* Add some out of bound checks for RGB light config */
-
-  if (rgblight_config.mode < RGBLIGHT_MODE_STATIC_LIGHT) {
-    rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
-  }
-  else if (rgblight_config.mode > RGBLIGHT_MODES) {
-    rgblight_config.mode = RGBLIGHT_MODES;
-  }
-
-  if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) {
-    rgblight_config.val = RGBLIGHT_LIMIT_VAL;
-  }
+    /* Add some out of bound checks for RGB light config */
+
+    if (rgblight_config.mode < RGBLIGHT_MODE_STATIC_LIGHT) {
+        rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
+    } else if (rgblight_config.mode > RGBLIGHT_MODES) {
+        rgblight_config.mode = RGBLIGHT_MODES;
+    }
+
+    if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) {
+        rgblight_config.val = RGBLIGHT_LIMIT_VAL;
+    }
 }
 
 uint32_t eeconfig_read_rgblight(void) {
-  #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
+#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
     return eeprom_read_dword(EECONFIG_RGBLIGHT);
-  #else
+#else
     return 0;
-  #endif
+#endif
 }
 
 void eeconfig_update_rgblight(uint32_t val) {
-  #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
+#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
     rgblight_check_config();
     eeprom_update_dword(EECONFIG_RGBLIGHT, val);
-  #endif
+#endif
 }
 
 void eeconfig_update_rgblight_default(void) {
-  rgblight_config.enable = 1;
-  rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
-  rgblight_config.hue = 0;
-  rgblight_config.sat = UINT8_MAX;
-  rgblight_config.val = RGBLIGHT_LIMIT_VAL;
-  rgblight_config.speed = 0;
-  RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
-  eeconfig_update_rgblight(rgblight_config.raw);
+    rgblight_config.enable = 1;
+    rgblight_config.mode   = RGBLIGHT_MODE_STATIC_LIGHT;
+    rgblight_config.hue    = 0;
+    rgblight_config.sat    = UINT8_MAX;
+    rgblight_config.val    = RGBLIGHT_LIMIT_VAL;
+    rgblight_config.speed  = 0;
+    RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
+    eeconfig_update_rgblight(rgblight_config.raw);
 }
 
 void eeconfig_debug_rgblight(void) {
-  dprintf("rgblight_config EEPROM:\n");
-  dprintf("rgblight_config.enable = %d\n", rgblight_config.enable);
-  dprintf("rghlight_config.mode = %d\n", rgblight_config.mode);
-  dprintf("rgblight_config.hue = %d\n", rgblight_config.hue);
-  dprintf("rgblight_config.sat = %d\n", rgblight_config.sat);
-  dprintf("rgblight_config.val = %d\n", rgblight_config.val);
-  dprintf("rgblight_config.speed = %d\n", rgblight_config.speed);
+    dprintf("rgblight_config EEPROM:\n");
+    dprintf("rgblight_config.enable = %d\n", rgblight_config.enable);
+    dprintf("rghlight_config.mode = %d\n", rgblight_config.mode);
+    dprintf("rgblight_config.hue = %d\n", rgblight_config.hue);
+    dprintf("rgblight_config.sat = %d\n", rgblight_config.sat);
+    dprintf("rgblight_config.val = %d\n", rgblight_config.val);
+    dprintf("rgblight_config.speed = %d\n", rgblight_config.speed);
 }
 
 void rgblight_init(void) {
-  /* if already initialized, don't do it again.
-     If you must do it again, extern this and set to false, first.
-     This is a dirty, dirty hack until proper hooks can be added for keyboard startup. */
-  if (is_rgblight_initialized) { return; }
-
-  debug_enable = 1; // Debug ON!
-  dprintf("rgblight_init called.\n");
-  dprintf("rgblight_init start!\n");
-  if (!eeconfig_is_enabled()) {
-    dprintf("rgblight_init eeconfig is not enabled.\n");
-    eeconfig_init();
-    eeconfig_update_rgblight_default();
-  }
-  rgblight_config.raw = eeconfig_read_rgblight();
-  RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
-  if (!rgblight_config.mode) {
-    dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n");
-    eeconfig_update_rgblight_default();
+    /* if already initialized, don't do it again.
+       If you must do it again, extern this and set to false, first.
+       This is a dirty, dirty hack until proper hooks can be added for keyboard startup. */
+    if (is_rgblight_initialized) {
+        return;
+    }
+
+    debug_enable = 1;  // Debug ON!
+    dprintf("rgblight_init called.\n");
+    dprintf("rgblight_init start!\n");
+    if (!eeconfig_is_enabled()) {
+        dprintf("rgblight_init eeconfig is not enabled.\n");
+        eeconfig_init();
+        eeconfig_update_rgblight_default();
+    }
     rgblight_config.raw = eeconfig_read_rgblight();
-  }
-  rgblight_check_config();
+    RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
+    if (!rgblight_config.mode) {
+        dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n");
+        eeconfig_update_rgblight_default();
+        rgblight_config.raw = eeconfig_read_rgblight();
+    }
+    rgblight_check_config();
 
-  eeconfig_debug_rgblight(); // display current eeprom values
+    eeconfig_debug_rgblight();  // display current eeprom values
 
 #ifdef RGBLIGHT_USE_TIMER
-    rgblight_timer_init(); // setup the timer
+    rgblight_timer_init();  // setup the timer
 #endif
 
-  if (rgblight_config.enable) {
-    rgblight_mode_noeeprom(rgblight_config.mode);
-  }
-
-  is_rgblight_initialized = true;
+    if (rgblight_config.enable) {
+        rgblight_mode_noeeprom(rgblight_config.mode);
+    }
 
+    is_rgblight_initialized = true;
 }
 
-uint32_t rgblight_read_dword(void) {
-  return rgblight_config.raw;
-}
+uint32_t rgblight_read_dword(void) { return rgblight_config.raw; }
 
 void rgblight_update_dword(uint32_t dword) {
-  RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
-  rgblight_config.raw = dword;
-  if (rgblight_config.enable)
-    rgblight_mode_noeeprom(rgblight_config.mode);
-  else {
+    RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
+    rgblight_config.raw = dword;
+    if (rgblight_config.enable)
+        rgblight_mode_noeeprom(rgblight_config.mode);
+    else {
 #ifdef RGBLIGHT_USE_TIMER
-      rgblight_timer_disable();
+        rgblight_timer_disable();
 #endif
-      rgblight_set();
-  }
+        rgblight_set();
+    }
 }
 
 void rgblight_increase(void) {
-  uint8_t mode = 0;
-  if (rgblight_config.mode < RGBLIGHT_MODES) {
-    mode = rgblight_config.mode + 1;
-  }
-  rgblight_mode(mode);
+    uint8_t mode = 0;
+    if (rgblight_config.mode < RGBLIGHT_MODES) {
+        mode = rgblight_config.mode + 1;
+    }
+    rgblight_mode(mode);
 }
 void rgblight_decrease(void) {
-  uint8_t mode = 0;
-  // Mode will never be < 1. If it ever is, eeprom needs to be initialized.
-  if (rgblight_config.mode > RGBLIGHT_MODE_STATIC_LIGHT) {
-    mode = rgblight_config.mode - 1;
-  }
-  rgblight_mode(mode);
+    uint8_t mode = 0;
+    // Mode will never be < 1. If it ever is, eeprom needs to be initialized.
+    if (rgblight_config.mode > RGBLIGHT_MODE_STATIC_LIGHT) {
+        mode = rgblight_config.mode - 1;
+    }
+    rgblight_mode(mode);
 }
 void rgblight_step_helper(bool write_to_eeprom) {
-  uint8_t mode = 0;
-  mode = rgblight_config.mode + 1;
-  if (mode > RGBLIGHT_MODES) {
-    mode = 1;
-  }
-  rgblight_mode_eeprom_helper(mode, write_to_eeprom);
-}
-void rgblight_step_noeeprom(void) {
-  rgblight_step_helper(false);
-}
-void rgblight_step(void) {
-  rgblight_step_helper(true);
+    uint8_t mode = 0;
+    mode         = rgblight_config.mode + 1;
+    if (mode > RGBLIGHT_MODES) {
+        mode = 1;
+    }
+    rgblight_mode_eeprom_helper(mode, write_to_eeprom);
 }
+void rgblight_step_noeeprom(void) { rgblight_step_helper(false); }
+void rgblight_step(void) { rgblight_step_helper(true); }
 void rgblight_step_reverse_helper(bool write_to_eeprom) {
-  uint8_t mode = 0;
-  mode = rgblight_config.mode - 1;
-  if (mode < 1) {
-    mode = RGBLIGHT_MODES;
-  }
-  rgblight_mode_eeprom_helper(mode, write_to_eeprom);
-}
-void rgblight_step_reverse_noeeprom(void) {
-  rgblight_step_reverse_helper(false);
-}
-void rgblight_step_reverse(void) {
-  rgblight_step_reverse_helper(true);
+    uint8_t mode = 0;
+    mode         = rgblight_config.mode - 1;
+    if (mode < 1) {
+        mode = RGBLIGHT_MODES;
+    }
+    rgblight_mode_eeprom_helper(mode, write_to_eeprom);
 }
+void rgblight_step_reverse_noeeprom(void) { rgblight_step_reverse_helper(false); }
+void rgblight_step_reverse(void) { rgblight_step_reverse_helper(true); }
 
 uint8_t rgblight_get_mode(void) {
-  if (!rgblight_config.enable) {
-    return false;
-  }
+    if (!rgblight_config.enable) {
+        return false;
+    }
 
-  return rgblight_config.mode;
+    return rgblight_config.mode;
 }
 
 void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
-  if (!rgblight_config.enable) {
-    return;
-  }
-  if (mode < RGBLIGHT_MODE_STATIC_LIGHT) {
-    rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
-  } else if (mode > RGBLIGHT_MODES) {
-    rgblight_config.mode = RGBLIGHT_MODES;
-  } else {
-    rgblight_config.mode = mode;
-  }
-  RGBLIGHT_SPLIT_SET_CHANGE_MODE;
-  if (write_to_eeprom) {
-    eeconfig_update_rgblight(rgblight_config.raw);
-    dprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode);
-  } else {
-    dprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode);
-  }
-  if( is_static_effect(rgblight_config.mode) ) {
+    if (!rgblight_config.enable) {
+        return;
+    }
+    if (mode < RGBLIGHT_MODE_STATIC_LIGHT) {
+        rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
+    } else if (mode > RGBLIGHT_MODES) {
+        rgblight_config.mode = RGBLIGHT_MODES;
+    } else {
+        rgblight_config.mode = mode;
+    }
+    RGBLIGHT_SPLIT_SET_CHANGE_MODE;
+    if (write_to_eeprom) {
+        eeconfig_update_rgblight(rgblight_config.raw);
+        dprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode);
+    } else {
+        dprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode);
+    }
+    if (is_static_effect(rgblight_config.mode)) {
 #ifdef RGBLIGHT_USE_TIMER
-      rgblight_timer_disable();
+        rgblight_timer_disable();
 #endif
-  } else {
+    } else {
 #ifdef RGBLIGHT_USE_TIMER
-      rgblight_timer_enable();
+        rgblight_timer_enable();
 #endif
-  }
+    }
 #ifdef RGBLIGHT_USE_TIMER
     animation_status.restart = true;
 #endif
-  rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
+    rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
 }
 
-void rgblight_mode(uint8_t mode) {
-  rgblight_mode_eeprom_helper(mode, true);
-}
-
-void rgblight_mode_noeeprom(uint8_t mode) {
-  rgblight_mode_eeprom_helper(mode, false);
-}
+void rgblight_mode(uint8_t mode) { rgblight_mode_eeprom_helper(mode, true); }
 
+void rgblight_mode_noeeprom(uint8_t mode) { rgblight_mode_eeprom_helper(mode, false); }
 
 void rgblight_toggle(void) {
-  dprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
-  if (rgblight_config.enable) {
-    rgblight_disable();
-  }
-  else {
-    rgblight_enable();
-  }
+    dprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
+    if (rgblight_config.enable) {
+        rgblight_disable();
+    } else {
+        rgblight_enable();
+    }
 }
 
 void rgblight_toggle_noeeprom(void) {
-  dprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
-  if (rgblight_config.enable) {
-    rgblight_disable_noeeprom();
-  }
-  else {
-    rgblight_enable_noeeprom();
-  }
+    dprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
+    if (rgblight_config.enable) {
+        rgblight_disable_noeeprom();
+    } else {
+        rgblight_enable_noeeprom();
+    }
 }
 
 void rgblight_enable(void) {
-  rgblight_config.enable = 1;
-  // No need to update EEPROM here. rgblight_mode() will do that, actually
-  //eeconfig_update_rgblight(rgblight_config.raw);
-  dprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
-  rgblight_mode(rgblight_config.mode);
+    rgblight_config.enable = 1;
+    // No need to update EEPROM here. rgblight_mode() will do that, actually
+    // eeconfig_update_rgblight(rgblight_config.raw);
+    dprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
+    rgblight_mode(rgblight_config.mode);
 }
 
 void rgblight_enable_noeeprom(void) {
-  rgblight_config.enable = 1;
-  dprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
-  rgblight_mode_noeeprom(rgblight_config.mode);
+    rgblight_config.enable = 1;
+    dprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
+    rgblight_mode_noeeprom(rgblight_config.mode);
 }
 
 void rgblight_disable(void) {
-  rgblight_config.enable = 0;
-  eeconfig_update_rgblight(rgblight_config.raw);
-  dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
+    rgblight_config.enable = 0;
+    eeconfig_update_rgblight(rgblight_config.raw);
+    dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
 #ifdef RGBLIGHT_USE_TIMER
-      rgblight_timer_disable();
+    rgblight_timer_disable();
 #endif
-  RGBLIGHT_SPLIT_SET_CHANGE_MODE;
-  wait_ms(50);
-  rgblight_set();
+    RGBLIGHT_SPLIT_SET_CHANGE_MODE;
+    wait_ms(50);
+    rgblight_set();
 }
 
 void rgblight_disable_noeeprom(void) {
-  rgblight_config.enable = 0;
-  dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
+    rgblight_config.enable = 0;
+    dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
 #ifdef RGBLIGHT_USE_TIMER
     rgblight_timer_disable();
 #endif
-  RGBLIGHT_SPLIT_SET_CHANGE_MODE;
-  wait_ms(50);
-  rgblight_set();
+    RGBLIGHT_SPLIT_SET_CHANGE_MODE;
+    wait_ms(50);
+    rgblight_set();
 }
 
 void rgblight_increase_hue_helper(bool write_to_eeprom) {
-  uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP;
-  rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom);
-}
-void rgblight_increase_hue_noeeprom(void) {
-  rgblight_increase_hue_helper(false);
-}
-void rgblight_increase_hue(void) {
-  rgblight_increase_hue_helper(true);
+    uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP;
+    rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom);
 }
+void rgblight_increase_hue_noeeprom(void) { rgblight_increase_hue_helper(false); }
+void rgblight_increase_hue(void) { rgblight_increase_hue_helper(true); }
 void rgblight_decrease_hue_helper(bool write_to_eeprom) {
-  uint8_t hue = rgblight_config.hue - RGBLIGHT_HUE_STEP;
-  rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom);
-}
-void rgblight_decrease_hue_noeeprom(void) {
-  rgblight_decrease_hue_helper(false);
-}
-void rgblight_decrease_hue(void) {
-  rgblight_decrease_hue_helper(true);
+    uint8_t hue = rgblight_config.hue - RGBLIGHT_HUE_STEP;
+    rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom);
 }
+void rgblight_decrease_hue_noeeprom(void) { rgblight_decrease_hue_helper(false); }
+void rgblight_decrease_hue(void) { rgblight_decrease_hue_helper(true); }
 void rgblight_increase_sat_helper(bool write_to_eeprom) {
-  uint8_t sat = qadd8(rgblight_config.sat, RGBLIGHT_SAT_STEP);
-  rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom);
-}
-void rgblight_increase_sat_noeeprom(void) {
-  rgblight_increase_sat_helper(false);
-}
-void rgblight_increase_sat(void) {
-  rgblight_increase_sat_helper(true);
+    uint8_t sat = qadd8(rgblight_config.sat, RGBLIGHT_SAT_STEP);
+    rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom);
 }
+void rgblight_increase_sat_noeeprom(void) { rgblight_increase_sat_helper(false); }
+void rgblight_increase_sat(void) { rgblight_increase_sat_helper(true); }
 void rgblight_decrease_sat_helper(bool write_to_eeprom) {
-  uint8_t sat = qsub8(rgblight_config.sat, RGBLIGHT_SAT_STEP);
-  rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom);
-}
-void rgblight_decrease_sat_noeeprom(void) {
-  rgblight_decrease_sat_helper(false);
-}
-void rgblight_decrease_sat(void) {
-  rgblight_decrease_sat_helper(true);
+    uint8_t sat = qsub8(rgblight_config.sat, RGBLIGHT_SAT_STEP);
+    rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom);
 }
+void rgblight_decrease_sat_noeeprom(void) { rgblight_decrease_sat_helper(false); }
+void rgblight_decrease_sat(void) { rgblight_decrease_sat_helper(true); }
 void rgblight_increase_val_helper(bool write_to_eeprom) {
-  uint8_t val = qadd8(rgblight_config.val, RGBLIGHT_VAL_STEP);
-  rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom);
-}
-void rgblight_increase_val_noeeprom(void) {
-  rgblight_increase_val_helper(false);
-}
-void rgblight_increase_val(void) {
-  rgblight_increase_val_helper(true);
+    uint8_t val = qadd8(rgblight_config.val, RGBLIGHT_VAL_STEP);
+    rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom);
 }
+void rgblight_increase_val_noeeprom(void) { rgblight_increase_val_helper(false); }
+void rgblight_increase_val(void) { rgblight_increase_val_helper(true); }
 void rgblight_decrease_val_helper(bool write_to_eeprom) {
-  uint8_t val = qsub8(rgblight_config.val, RGBLIGHT_VAL_STEP);
-  rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom);
-}
-void rgblight_decrease_val_noeeprom(void) {
-  rgblight_decrease_val_helper(false);
-}
-void rgblight_decrease_val(void) {
-  rgblight_decrease_val_helper(true);
+    uint8_t val = qsub8(rgblight_config.val, RGBLIGHT_VAL_STEP);
+    rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom);
 }
+void rgblight_decrease_val_noeeprom(void) { rgblight_decrease_val_helper(false); }
+void rgblight_decrease_val(void) { rgblight_decrease_val_helper(true); }
 void rgblight_increase_speed(void) {
-    if (rgblight_config.speed < 3)
-        rgblight_config.speed++;
-    //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?
-    eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this
+    if (rgblight_config.speed < 3) rgblight_config.speed++;
+    // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?
+    eeconfig_update_rgblight(rgblight_config.raw);  // EECONFIG needs to be increased to support this
 }
 
 void rgblight_decrease_speed(void) {
-    if (rgblight_config.speed > 0)
-        rgblight_config.speed--;
-    //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED??
-    eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this
+    if (rgblight_config.speed > 0) rgblight_config.speed--;
+    // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED??
+    eeconfig_update_rgblight(rgblight_config.raw);  // EECONFIG needs to be increased to support this
 }
 
 void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) {
-  if (rgblight_config.enable) {
-    LED_TYPE tmp_led;
-    sethsv(hue, sat, val, &tmp_led);
-    rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
-  }
+    if (rgblight_config.enable) {
+        LED_TYPE tmp_led;
+        sethsv(hue, sat, val, &tmp_led);
+        rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
+    }
 }
 
 void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) {
-  if (rgblight_config.enable) {
-    rgblight_status.base_mode = mode_base_table[rgblight_config.mode];
-    if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) {
-      // same static color
-      LED_TYPE tmp_led;
-      sethsv(hue, sat, val, &tmp_led);
-      rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
-    } else {
-      // all LEDs in same color
-      if ( 1 == 0 ) { //dummy
-      }
+    if (rgblight_config.enable) {
+        rgblight_status.base_mode = mode_base_table[rgblight_config.mode];
+        if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) {
+            // same static color
+            LED_TYPE tmp_led;
+            sethsv(hue, sat, val, &tmp_led);
+            rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
+        } else {
+            // all LEDs in same color
+            if (1 == 0) {  // dummy
+            }
 #ifdef RGBLIGHT_EFFECT_BREATHING
-      else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING ) {
-        // breathing mode, ignore the change of val, use in memory value instead
-        val = rgblight_config.val;
-      }
+            else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) {
+                // breathing mode, ignore the change of val, use in memory value instead
+                val = rgblight_config.val;
+            }
 #endif
 #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
-      else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) {
-        // rainbow mood, ignore the change of hue
-        hue = rgblight_config.hue;
-      }
+            else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) {
+                // rainbow mood, ignore the change of hue
+                hue = rgblight_config.hue;
+            }
 #endif
 #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
-      else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) {
-        // rainbow swirl, ignore the change of hue
-        hue = rgblight_config.hue;
-      }
+            else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) {
+                // rainbow swirl, ignore the change of hue
+                hue = rgblight_config.hue;
+            }
 #endif
 #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
-      else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) {
-        // static gradient
-        uint8_t delta = rgblight_config.mode - rgblight_status.base_mode;
-        bool direction = (delta % 2) == 0;
-#ifdef __AVR__
-        // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line
-        uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]);
-#else
-        uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2];
+            else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) {
+                // static gradient
+                uint8_t delta     = rgblight_config.mode - rgblight_status.base_mode;
+                bool    direction = (delta % 2) == 0;
+#    ifdef __AVR__
+                // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line
+                uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]);
+#    else
+                uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2];
+#    endif
+                for (uint8_t i = 0; i < effect_num_leds; i++) {
+                    uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds;
+                    if (direction) {
+                        _hue = hue + _hue;
+                    } else {
+                        _hue = hue - _hue;
+                    }
+                    dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range);
+                    sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]);
+                }
+                rgblight_set();
+            }
 #endif
-        for (uint8_t i = 0; i < effect_num_leds; i++) {
-          uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds;
-          if (direction) {
-            _hue = hue + _hue;
-          } else {
-            _hue = hue - _hue;
-          }
-          dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range);
-          sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]);
         }
-        rgblight_set();
-      }
-#endif
-    }
 #ifdef RGBLIGHT_SPLIT
-    if( rgblight_config.hue != hue ||
-        rgblight_config.sat != sat ||
-        rgblight_config.val != val ) {
-        RGBLIGHT_SPLIT_SET_CHANGE_HSVS;
-    }
+        if (rgblight_config.hue != hue || rgblight_config.sat != sat || rgblight_config.val != val) {
+            RGBLIGHT_SPLIT_SET_CHANGE_HSVS;
+        }
 #endif
-    rgblight_config.hue = hue;
-    rgblight_config.sat = sat;
-    rgblight_config.val = val;
-    if (write_to_eeprom) {
-      eeconfig_update_rgblight(rgblight_config.raw);
-      dprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
-    } else {
-      dprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
+        rgblight_config.hue = hue;
+        rgblight_config.sat = sat;
+        rgblight_config.val = val;
+        if (write_to_eeprom) {
+            eeconfig_update_rgblight(rgblight_config.raw);
+            dprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
+        } else {
+            dprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
+        }
     }
-  }
 }
 
-void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) {
-  rgblight_sethsv_eeprom_helper(hue, sat, val, true);
-}
+void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, true); }
 
-void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) {
-  rgblight_sethsv_eeprom_helper(hue, sat, val, false);
-}
+void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, false); }
 
-uint8_t rgblight_get_hue(void) {
-  return rgblight_config.hue;
-}
+uint8_t rgblight_get_hue(void) { return rgblight_config.hue; }
 
-uint8_t rgblight_get_sat(void) {
-  return rgblight_config.sat;
-}
+uint8_t rgblight_get_sat(void) { return rgblight_config.sat; }
 
-uint8_t rgblight_get_val(void) {
-  return rgblight_config.val;
-}
+uint8_t rgblight_get_val(void) { return rgblight_config.val; }
 
 void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) {
-  if (!rgblight_config.enable) { return; }
-
-  for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) {
-    led[i].r = r;
-    led[i].g = g;
-    led[i].b = b;
-  }
-  rgblight_set();
+    if (!rgblight_config.enable) {
+        return;
+    }
+
+    for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) {
+        led[i].r = r;
+        led[i].g = g;
+        led[i].b = b;
+    }
+    rgblight_set();
 }
 
 void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) {
-  if (!rgblight_config.enable || index >= RGBLED_NUM) { return; }
+    if (!rgblight_config.enable || index >= RGBLED_NUM) {
+        return;
+    }
 
-  led[index].r = r;
-  led[index].g = g;
-  led[index].b = b;
-  rgblight_set();
+    led[index].r = r;
+    led[index].g = g;
+    led[index].b = b;
+    rgblight_set();
 }
 
 void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) {
-  if (!rgblight_config.enable) { return; }
+    if (!rgblight_config.enable) {
+        return;
+    }
 
-  LED_TYPE tmp_led;
-  sethsv(hue, sat, val, &tmp_led);
-  rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index);
+    LED_TYPE tmp_led;
+    sethsv(hue, sat, val, &tmp_led);
+    rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index);
 }
 
-#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) \
-  || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT)
+#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT)
 
-static uint8_t get_interval_time(const uint8_tdefault_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) {
-  return
-#ifdef VELOCIKEY_ENABLE
-    velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) :
-#endif
-    pgm_read_byte(default_interval_address);
+static uint8_t get_interval_time(const uint8_t *default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) {
+    return
+#    ifdef VELOCIKEY_ENABLE
+        velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) :
+#    endif
+                            pgm_read_byte(default_interval_address);
 }
 
 #endif
 
 void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) {
-  if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; }
-
-  for (uint8_t i = start; i < end; i++) {
-    led[i].r = r;
-    led[i].g = g;
-    led[i].b = b;
-  }
-  rgblight_set();
-  wait_ms(1);
+    if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) {
+        return;
+    }
+
+    for (uint8_t i = start; i < end; i++) {
+        led[i].r = r;
+        led[i].g = g;
+        led[i].b = b;
+    }
+    rgblight_set();
+    wait_ms(1);
 }
 
 void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) {
-  if (!rgblight_config.enable) { return; }
+    if (!rgblight_config.enable) {
+        return;
+    }
 
-  LED_TYPE tmp_led;
-  sethsv(hue, sat, val, &tmp_led);
-  rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end);
+    LED_TYPE tmp_led;
+    sethsv(hue, sat, val, &tmp_led);
+    rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end);
 }
 
 #ifndef RGBLIGHT_SPLIT
-void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) {
-  rgblight_setrgb_range(r, g, b, 0 , (uint8_t) RGBLED_NUM/2);
-}
+void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb_range(r, g, b, 0, (uint8_t)RGBLED_NUM / 2); }
 
-void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) {
-  rgblight_setrgb_range(r, g, b, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM);
-}
+void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb_range(r, g, b, (uint8_t)RGBLED_NUM / 2, (uint8_t)RGBLED_NUM); }
 
-void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) {
-  rgblight_sethsv_range(hue, sat, val, 0, (uint8_t) RGBLED_NUM/2);
-}
+void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_range(hue, sat, val, 0, (uint8_t)RGBLED_NUM / 2); }
 
-void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) {
-  rgblight_sethsv_range(hue, sat, val, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM);
-}
-#endif // ifndef RGBLIGHT_SPLIT
+void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_range(hue, sat, val, (uint8_t)RGBLED_NUM / 2, (uint8_t)RGBLED_NUM); }
+#endif  // ifndef RGBLIGHT_SPLIT
 
 #ifndef RGBLIGHT_CUSTOM_DRIVER
 void rgblight_set(void) {
-  LED_TYPE *start_led;
-  uint16_t num_leds = clipping_num_leds;
-
-  if (!rgblight_config.enable) {
-    for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) {
-      led[i].r = 0;
-      led[i].g = 0;
-      led[i].b = 0;
+    LED_TYPE *start_led;
+    uint16_t  num_leds = clipping_num_leds;
+
+    if (!rgblight_config.enable) {
+        for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) {
+            led[i].r = 0;
+            led[i].g = 0;
+            led[i].b = 0;
+        }
     }
-  }
-#ifdef RGBLIGHT_LED_MAP
-  LED_TYPE led0[RGBLED_NUM];
-  for(uint8_t i = 0; i < RGBLED_NUM; i++) {
-      led0[i] = led[pgm_read_byte(&led_map[i])];
-  }
-  start_led = led0 + clipping_start_pos;
-#else
-  start_led = led + clipping_start_pos;
-#endif
-#ifdef RGBW
-  ws2812_setleds_rgbw(start_led, num_leds);
-#else
-  ws2812_setleds(start_led, num_leds);
-#endif
+#    ifdef RGBLIGHT_LED_MAP
+    LED_TYPE led0[RGBLED_NUM];
+    for (uint8_t i = 0; i < RGBLED_NUM; i++) {
+        led0[i] = led[pgm_read_byte(&led_map[i])];
+    }
+    start_led = led0 + clipping_start_pos;
+#    else
+    start_led = led + clipping_start_pos;
+#    endif
+#    ifdef RGBW
+    ws2812_setleds_rgbw(start_led, num_leds);
+#    else
+    ws2812_setleds(start_led, num_leds);
+#    endif
 }
 #endif
 
 #ifdef RGBLIGHT_SPLIT
 /* for split keyboard master side */
-uint8_t rgblight_get_change_flags(void) {
-    return rgblight_status.change_flags;
-}
+uint8_t rgblight_get_change_flags(void) { return rgblight_status.change_flags; }
 
-void rgblight_clear_change_flags(void) {
-    rgblight_status.change_flags = 0;
-}
+void rgblight_clear_change_flags(void) { rgblight_status.change_flags = 0; }
 
 void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) {
     syncinfo->config = rgblight_config;
@@ -695,7 +629,7 @@ void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) {
 void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) {
     if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_MODE) {
         if (syncinfo->config.enable) {
-            rgblight_config.enable = 1; // == rgblight_enable_noeeprom();
+            rgblight_config.enable = 1;  // == rgblight_enable_noeeprom();
             rgblight_mode_eeprom_helper(syncinfo->config.mode, write_to_eeprom);
         } else {
             rgblight_disable_noeeprom();
@@ -705,7 +639,7 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) {
         rgblight_sethsv_eeprom_helper(syncinfo->config.hue, syncinfo->config.sat, syncinfo->config.val, write_to_eeprom);
         // rgblight_config.speed = config->speed; // NEED???
     }
-  #ifdef RGBLIGHT_USE_TIMER
+#    ifdef RGBLIGHT_USE_TIMER
     if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_TIMER) {
         if (syncinfo->status.timer_enabled) {
             rgblight_timer_enable();
@@ -713,12 +647,12 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) {
             rgblight_timer_disable();
         }
     }
-    #ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC
+#        ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC
     if (syncinfo->status.change_flags & RGBLIGHT_STATUS_ANIMATION_TICK) {
         animation_status.restart = true;
     }
-    #endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */
-  #endif /* RGBLIGHT_USE_TIMER */
+#        endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */
+#    endif     /* RGBLIGHT_USE_TIMER */
 }
 #endif /* RGBLIGHT_SPLIT */
 
@@ -728,51 +662,51 @@ typedef void (*effect_func_t)(animation_status_t *anim);
 
 // Animation timer -- use system timer (AVR Timer0)
 void rgblight_timer_init(void) {
-  // OLD!!!! Animation timer -- AVR Timer3
-  // static uint8_t rgblight_timer_is_init = 0;
-  // if (rgblight_timer_is_init) {
-  //   return;
-  // }
-  // rgblight_timer_is_init = 1;
-  // /* Timer 3 setup */
-  // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP
-  //       | _BV(CS30); // Clock selelct: clk/1
-  // /* Set TOP value */
-  // uint8_t sreg = SREG;
-  // cli();
-  // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff;
-  // OCR3AL = RGBLED_TIMER_TOP & 0xff;
-  // SREG = sreg;
-
-  rgblight_status.timer_enabled = false;
-  RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
+    // OLD!!!! Animation timer -- AVR Timer3
+    // static uint8_t rgblight_timer_is_init = 0;
+    // if (rgblight_timer_is_init) {
+    //   return;
+    // }
+    // rgblight_timer_is_init = 1;
+    // /* Timer 3 setup */
+    // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP
+    //       | _BV(CS30); // Clock selelct: clk/1
+    // /* Set TOP value */
+    // uint8_t sreg = SREG;
+    // cli();
+    // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff;
+    // OCR3AL = RGBLED_TIMER_TOP & 0xff;
+    // SREG = sreg;
+
+    rgblight_status.timer_enabled = false;
+    RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
 }
 void rgblight_timer_enable(void) {
-  if( !is_static_effect(rgblight_config.mode) ) {
-      rgblight_status.timer_enabled = true;
-  }
-  animation_status.last_timer = timer_read();
-  RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
-  dprintf("rgblight timer enabled.\n");
+    if (!is_static_effect(rgblight_config.mode)) {
+        rgblight_status.timer_enabled = true;
+    }
+    animation_status.last_timer = timer_read();
+    RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
+    dprintf("rgblight timer enabled.\n");
 }
 void rgblight_timer_disable(void) {
-  rgblight_status.timer_enabled = false;
-  RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
-  dprintf("rgblight timer disable.\n");
+    rgblight_status.timer_enabled = false;
+    RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
+    dprintf("rgblight timer disable.\n");
 }
 void rgblight_timer_toggle(void) {
-  dprintf("rgblight timer toggle.\n");
-  if(rgblight_status.timer_enabled) {
-      rgblight_timer_disable();
-  } else {
-      rgblight_timer_enable();
-  }
+    dprintf("rgblight timer toggle.\n");
+    if (rgblight_status.timer_enabled) {
+        rgblight_timer_disable();
+    } else {
+        rgblight_timer_enable();
+    }
 }
 
 void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
-  rgblight_enable();
-  rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
-  rgblight_setrgb(r, g, b);
+    rgblight_enable();
+    rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
+    rgblight_setrgb(r, g, b);
 }
 
 static void rgblight_effect_dummy(animation_status_t *anim) {
@@ -788,99 +722,99 @@ static void rgblight_effect_dummy(animation_status_t *anim) {
 }
 
 void rgblight_task(void) {
-  if (rgblight_status.timer_enabled) {
-    effect_func_t effect_func = rgblight_effect_dummy;
-    uint16_t interval_time = 2000; // dummy interval
-    uint8_t delta = rgblight_config.mode - rgblight_status.base_mode;
-    animation_status.delta = delta;
-
-    // static light mode, do nothing here
-    if ( 1 == 0 ) { //dummy
-    }
-#ifdef RGBLIGHT_EFFECT_BREATHING
-    else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) {
-      // breathing mode
-      interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[delta], 1, 100);
-      effect_func = rgblight_effect_breathing;
-    }
-#endif
-#ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
-    else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) {
-      // rainbow mood mode
-      interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[delta], 5, 100);
-      effect_func = rgblight_effect_rainbow_mood;
-    }
-#endif
-#ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
-    else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) {
-      // rainbow swirl mode
-      interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[delta / 2], 1, 100);
-      effect_func = rgblight_effect_rainbow_swirl;
-    }
-#endif
-#ifdef RGBLIGHT_EFFECT_SNAKE
-    else if (rgblight_status.base_mode == RGBLIGHT_MODE_SNAKE) {
-      // snake mode
-      interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[delta / 2], 1, 200);
-      effect_func = rgblight_effect_snake;
-    }
-#endif
-#ifdef RGBLIGHT_EFFECT_KNIGHT
-    else if (rgblight_status.base_mode == RGBLIGHT_MODE_KNIGHT) {
-      // knight mode
-      interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[delta], 5, 100);
-      effect_func = rgblight_effect_knight;
-    }
-#endif
-#ifdef RGBLIGHT_EFFECT_CHRISTMAS
-    else if (rgblight_status.base_mode == RGBLIGHT_MODE_CHRISTMAS) {
-      // christmas mode
-      interval_time = RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL;
-      effect_func = (effect_func_t)rgblight_effect_christmas;
-    }
-#endif
-#ifdef RGBLIGHT_EFFECT_RGB_TEST
-    else if (rgblight_status.base_mode == RGBLIGHT_MODE_RGB_TEST) {
-      // RGB test mode
-      interval_time = pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0]);
-      effect_func = (effect_func_t)rgblight_effect_rgbtest;
-    }
-#endif
-#ifdef RGBLIGHT_EFFECT_ALTERNATING
-    else if (rgblight_status.base_mode == RGBLIGHT_MODE_ALTERNATING){
-      interval_time = 500;
-      effect_func = (effect_func_t)rgblight_effect_alternating;
-    }
-#endif
-    if (animation_status.restart) {
-      animation_status.restart = false;
-      animation_status.last_timer = timer_read() - interval_time - 1;
-      animation_status.pos16 = 0; // restart signal to local each effect
-    }
-    if (timer_elapsed(animation_status.last_timer) >= interval_time) {
-#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
-      static uint16_t report_last_timer = 0;
-      static bool tick_flag = false;
-      uint16_t oldpos16;
-      if (tick_flag) {
-        tick_flag = false;
-        if (timer_elapsed(report_last_timer) >= 30000) {
-            report_last_timer = timer_read();
-            dprintf("rgblight animation tick report to slave\n");
-            RGBLIGHT_SPLIT_ANIMATION_TICK;
+    if (rgblight_status.timer_enabled) {
+        effect_func_t effect_func   = rgblight_effect_dummy;
+        uint16_t      interval_time = 2000;  // dummy interval
+        uint8_t       delta         = rgblight_config.mode - rgblight_status.base_mode;
+        animation_status.delta      = delta;
+
+        // static light mode, do nothing here
+        if (1 == 0) {  // dummy
+        }
+#    ifdef RGBLIGHT_EFFECT_BREATHING
+        else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) {
+            // breathing mode
+            interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[delta], 1, 100);
+            effect_func   = rgblight_effect_breathing;
+        }
+#    endif
+#    ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
+        else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) {
+            // rainbow mood mode
+            interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[delta], 5, 100);
+            effect_func   = rgblight_effect_rainbow_mood;
+        }
+#    endif
+#    ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
+        else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) {
+            // rainbow swirl mode
+            interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[delta / 2], 1, 100);
+            effect_func   = rgblight_effect_rainbow_swirl;
+        }
+#    endif
+#    ifdef RGBLIGHT_EFFECT_SNAKE
+        else if (rgblight_status.base_mode == RGBLIGHT_MODE_SNAKE) {
+            // snake mode
+            interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[delta / 2], 1, 200);
+            effect_func   = rgblight_effect_snake;
+        }
+#    endif
+#    ifdef RGBLIGHT_EFFECT_KNIGHT
+        else if (rgblight_status.base_mode == RGBLIGHT_MODE_KNIGHT) {
+            // knight mode
+            interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[delta], 5, 100);
+            effect_func   = rgblight_effect_knight;
+        }
+#    endif
+#    ifdef RGBLIGHT_EFFECT_CHRISTMAS
+        else if (rgblight_status.base_mode == RGBLIGHT_MODE_CHRISTMAS) {
+            // christmas mode
+            interval_time = RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL;
+            effect_func   = (effect_func_t)rgblight_effect_christmas;
+        }
+#    endif
+#    ifdef RGBLIGHT_EFFECT_RGB_TEST
+        else if (rgblight_status.base_mode == RGBLIGHT_MODE_RGB_TEST) {
+            // RGB test mode
+            interval_time = pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0]);
+            effect_func   = (effect_func_t)rgblight_effect_rgbtest;
+        }
+#    endif
+#    ifdef RGBLIGHT_EFFECT_ALTERNATING
+        else if (rgblight_status.base_mode == RGBLIGHT_MODE_ALTERNATING) {
+            interval_time = 500;
+            effect_func   = (effect_func_t)rgblight_effect_alternating;
+        }
+#    endif
+        if (animation_status.restart) {
+            animation_status.restart    = false;
+            animation_status.last_timer = timer_read() - interval_time - 1;
+            animation_status.pos16      = 0;  // restart signal to local each effect
+        }
+        if (timer_elapsed(animation_status.last_timer) >= interval_time) {
+#    if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
+            static uint16_t report_last_timer = 0;
+            static bool     tick_flag         = false;
+            uint16_t        oldpos16;
+            if (tick_flag) {
+                tick_flag = false;
+                if (timer_elapsed(report_last_timer) >= 30000) {
+                    report_last_timer = timer_read();
+                    dprintf("rgblight animation tick report to slave\n");
+                    RGBLIGHT_SPLIT_ANIMATION_TICK;
+                }
+            }
+            oldpos16 = animation_status.pos16;
+#    endif
+            animation_status.last_timer += interval_time;
+            effect_func(&animation_status);
+#    if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
+            if (animation_status.pos16 == 0 && oldpos16 != 0) {
+                tick_flag = true;
+            }
+#    endif
         }
-      }
-      oldpos16 = animation_status.pos16;
-#endif
-      animation_status.last_timer += interval_time;
-      effect_func(&animation_status);
-#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
-      if (animation_status.pos16 == 0 && oldpos16 != 0) {
-          tick_flag = true;
-      }
-#endif
     }
-  }
 }
 
 #endif /* RGBLIGHT_USE_TIMER */
@@ -888,237 +822,235 @@ void rgblight_task(void) {
 // Effects
 #ifdef RGBLIGHT_EFFECT_BREATHING
 
-#ifndef RGBLIGHT_EFFECT_BREATHE_CENTER
-  #ifndef RGBLIGHT_BREATHE_TABLE_SIZE
-    #define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64
-  #endif
-  #include <rgblight_breathe_table.h>
-#endif
+#    ifndef RGBLIGHT_EFFECT_BREATHE_CENTER
+#        ifndef RGBLIGHT_BREATHE_TABLE_SIZE
+#            define RGBLIGHT_BREATHE_TABLE_SIZE 256  // 256 or 128 or 64
+#        endif
+#        include <rgblight_breathe_table.h>
+#    endif
 
-__attribute__ ((weak))
-const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5};
+__attribute__((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5};
 
 void rgblight_effect_breathing(animation_status_t *anim) {
-  float val;
+    float val;
 
-  // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
-#ifdef RGBLIGHT_EFFECT_BREATHE_TABLE
-  val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos / table_scale]);
-#else
-  val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E));
-#endif
-  rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val);
-  anim->pos = (anim->pos + 1);
+    // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
+#    ifdef RGBLIGHT_EFFECT_BREATHE_TABLE
+    val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos / table_scale]);
+#    else
+    val = (exp(sin((anim->pos / 255.0) * M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER / M_E) * (RGBLIGHT_EFFECT_BREATHE_MAX / (M_E - 1 / M_E));
+#    endif
+    rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val);
+    anim->pos = (anim->pos + 1);
 }
 #endif
 
 #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
-__attribute__ ((weak))
-const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30};
+__attribute__((weak)) const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30};
 
 void rgblight_effect_rainbow_mood(animation_status_t *anim) {
-  rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val);
-  anim->current_hue++;
+    rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val);
+    anim->current_hue++;
 }
 #endif
 
 #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
-#ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE
-  #define RGBLIGHT_RAINBOW_SWIRL_RANGE 255
-#endif
+#    ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE
+#        define RGBLIGHT_RAINBOW_SWIRL_RANGE 255
+#    endif
 
-__attribute__ ((weak))
-const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20};
+__attribute__((weak)) const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20};
 
 void rgblight_effect_rainbow_swirl(animation_status_t *anim) {
-  uint8_t hue;
-  uint8_t i;
+    uint8_t hue;
+    uint8_t i;
 
-  for (i = 0; i < effect_num_leds; i++) {
-    hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue);
-    sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]);
-  }
-  rgblight_set();
+    for (i = 0; i < effect_num_leds; i++) {
+        hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue);
+        sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]);
+    }
+    rgblight_set();
 
-  if (anim->delta % 2) {
-    anim->current_hue++;
-  } else {
-    anim->current_hue--;
-  }
+    if (anim->delta % 2) {
+        anim->current_hue++;
+    } else {
+        anim->current_hue--;
+    }
 }
 #endif
 
 #ifdef RGBLIGHT_EFFECT_SNAKE
-__attribute__ ((weak))
-const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20};
+__attribute__((weak)) const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20};
 
 void rgblight_effect_snake(animation_status_t *anim) {
-  static uint8_t pos = 0;
-  uint8_t i, j;
-  int8_t k;
-  int8_t increment = 1;
-
-  if (anim->delta % 2) {
-    increment = -1;
-  }
+    static uint8_t pos = 0;
+    uint8_t        i, j;
+    int8_t         k;
+    int8_t         increment = 1;
 
-#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
-  if (anim->pos == 0) { // restart signal
-    if (increment == 1) {
-      pos = effect_num_leds - 1;
-    } else {
-      pos = 0;
+    if (anim->delta % 2) {
+        increment = -1;
     }
-    anim->pos = 1;
-  }
-#endif
 
-  for (i = 0; i < effect_num_leds; i++) {
-    LED_TYPE *ledp = led + i + effect_start_pos;
-    ledp->r = 0;
-    ledp->g = 0;
-    ledp->b = 0;
-    for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) {
-      k = pos + j * increment;
-      if (k < 0) {
-        k = k + effect_num_leds;
-      }
-      if (i == k) {
-        sethsv(rgblight_config.hue, rgblight_config.sat,
-               (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH),
-               ledp);
-      }
+#    if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
+    if (anim->pos == 0) {  // restart signal
+        if (increment == 1) {
+            pos = effect_num_leds - 1;
+        } else {
+            pos = 0;
+        }
+        anim->pos = 1;
     }
-  }
-  rgblight_set();
-  if (increment == 1) {
-    if (pos - 1 < 0) {
-      pos = effect_num_leds - 1;
-#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
-      anim->pos = 0;
-#endif
+#    endif
+
+    for (i = 0; i < effect_num_leds; i++) {
+        LED_TYPE *ledp = led + i + effect_start_pos;
+        ledp->r        = 0;
+        ledp->g        = 0;
+        ledp->b        = 0;
+        for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) {
+            k = pos + j * increment;
+            if (k < 0) {
+                k = k + effect_num_leds;
+            }
+            if (i == k) {
+                sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val * (RGBLIGHT_EFFECT_SNAKE_LENGTH - j) / RGBLIGHT_EFFECT_SNAKE_LENGTH), ledp);
+            }
+        }
+    }
+    rgblight_set();
+    if (increment == 1) {
+        if (pos - 1 < 0) {
+            pos = effect_num_leds - 1;
+#    if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
+            anim->pos = 0;
+#    endif
+        } else {
+            pos -= 1;
+#    if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
+            anim->pos = 1;
+#    endif
+        }
     } else {
-      pos -= 1;
-#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
-      anim->pos = 1;
-#endif
+        pos = (pos + 1) % effect_num_leds;
+#    if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
+        anim->pos = pos;
+#    endif
     }
-  } else {
-    pos = (pos + 1) % effect_num_leds;
-#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
-    anim->pos = pos;
-#endif
-  }
 }
 #endif
 
 #ifdef RGBLIGHT_EFFECT_KNIGHT
-__attribute__ ((weak))
-const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31};
+__attribute__((weak)) const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31};
 
 void rgblight_effect_knight(animation_status_t *anim) {
-
-  static int8_t low_bound = 0;
-  static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
-  static int8_t increment = 1;
-  uint8_t i, cur;
-
-#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
-  if (anim->pos == 0) { // restart signal
-      anim->pos = 1;
-      low_bound = 0;
-      high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
-      increment = 1;
-  }
-#endif
-  // Set all the LEDs to 0
-  for (i = effect_start_pos; i < effect_end_pos; i++) {
-    led[i].r = 0;
-    led[i].g = 0;
-    led[i].b = 0;
-  }
-  // Determine which LEDs should be lit up
-  for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) {
-    cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos;
-
-    if (i >= low_bound && i <= high_bound) {
-      sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]);
-    } else {
-      led[cur].r = 0;
-      led[cur].g = 0;
-      led[cur].b = 0;
+    static int8_t low_bound  = 0;
+    static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
+    static int8_t increment  = 1;
+    uint8_t       i, cur;
+
+#    if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
+    if (anim->pos == 0) {  // restart signal
+        anim->pos  = 1;
+        low_bound  = 0;
+        high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
+        increment  = 1;
     }
-  }
-  rgblight_set();
-
-  // Move from low_bound to high_bound changing the direction we increment each
-  // time a boundary is hit.
-  low_bound += increment;
-  high_bound += increment;
+#    endif
+    // Set all the LEDs to 0
+    for (i = effect_start_pos; i < effect_end_pos; i++) {
+        led[i].r = 0;
+        led[i].g = 0;
+        led[i].b = 0;
+    }
+    // Determine which LEDs should be lit up
+    for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) {
+        cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos;
 
-  if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) {
-    increment = -increment;
-#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
-    if (increment == 1) {
-        anim->pos = 0;
+        if (i >= low_bound && i <= high_bound) {
+            sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]);
+        } else {
+            led[cur].r = 0;
+            led[cur].g = 0;
+            led[cur].b = 0;
+        }
+    }
+    rgblight_set();
+
+    // Move from low_bound to high_bound changing the direction we increment each
+    // time a boundary is hit.
+    low_bound += increment;
+    high_bound += increment;
+
+    if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) {
+        increment = -increment;
+#    if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
+        if (increment == 1) {
+            anim->pos = 0;
+        }
+#    endif
     }
-#endif
-  }
 }
 #endif
 
 #ifdef RGBLIGHT_EFFECT_CHRISTMAS
 void rgblight_effect_christmas(animation_status_t *anim) {
-  uint8_t hue;
-  uint8_t i;
-
-  anim->current_offset = (anim->current_offset + 1) % 2;
-  for (i = 0; i < effect_num_leds; i++) {
-    hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85;
-    sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]);
-  }
-  rgblight_set();
+    uint8_t hue;
+    uint8_t i;
+
+    anim->current_offset = (anim->current_offset + 1) % 2;
+    for (i = 0; i < effect_num_leds; i++) {
+        hue = 0 + ((i / RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85;
+        sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]);
+    }
+    rgblight_set();
 }
 #endif
 
 #ifdef RGBLIGHT_EFFECT_RGB_TEST
-__attribute__ ((weak))
-const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024};
+__attribute__((weak)) const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024};
 
 void rgblight_effect_rgbtest(animation_status_t *anim) {
-  static uint8_t maxval = 0;
-  uint8_t g; uint8_t r; uint8_t b;
-
-  if( maxval == 0 ) {
-      LED_TYPE tmp_led;
-      sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led);
-      maxval = tmp_led.r;
-  }
-  g = r = b = 0;
-  switch( anim->pos ) {
-    case 0: r = maxval; break;
-    case 1: g = maxval; break;
-    case 2: b = maxval; break;
-  }
-  rgblight_setrgb(r, g, b);
-  anim->pos = (anim->pos + 1) % 3;
+    static uint8_t maxval = 0;
+    uint8_t        g;
+    uint8_t        r;
+    uint8_t        b;
+
+    if (maxval == 0) {
+        LED_TYPE tmp_led;
+        sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led);
+        maxval = tmp_led.r;
+    }
+    g = r = b = 0;
+    switch (anim->pos) {
+        case 0:
+            r = maxval;
+            break;
+        case 1:
+            g = maxval;
+            break;
+        case 2:
+            b = maxval;
+            break;
+    }
+    rgblight_setrgb(r, g, b);
+    anim->pos = (anim->pos + 1) % 3;
 }
 #endif
 
 #ifdef RGBLIGHT_EFFECT_ALTERNATING
 void rgblight_effect_alternating(animation_status_t *anim) {
-
-  for (int i = 0; i < effect_num_leds; i++) {
-      LED_TYPE *ledp = led + i + effect_start_pos;
-      if (i<effect_num_leds/2 && anim->pos) {
-          sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp);
-      } else if (i>=effect_num_leds/2 && !anim->pos) {
-          sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp);
-      } else {
-          sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp);
-      }
-  }
-  rgblight_set();
-  anim->pos = (anim->pos + 1) % 2;
+    for (int i = 0; i < effect_num_leds; i++) {
+        LED_TYPE *ledp = led + i + effect_start_pos;
+        if (i < effect_num_leds / 2 && anim->pos) {
+            sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp);
+        } else if (i >= effect_num_leds / 2 && !anim->pos) {
+            sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp);
+        } else {
+            sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp);
+        }
+    }
+    rgblight_set();
+    anim->pos = (anim->pos + 1) % 2;
 }
 #endif
index cba18ae729120fdc3e2d9fec9e9d8607bf5cc560..e3aa098e4db16684bd19aafa4aa12311a9471515 100644 (file)
 |-----------------|-----------------------------------|
  *****/
 
-#define _RGBM_SINGLE_STATIC(sym)   RGBLIGHT_MODE_ ## sym,
-#define _RGBM_SINGLE_DYNAMIC(sym)  RGBLIGHT_MODE_ ## sym,
-#define _RGBM_MULTI_STATIC(sym)    RGBLIGHT_MODE_ ## sym,
-#define _RGBM_MULTI_DYNAMIC(sym)   RGBLIGHT_MODE_ ## sym,
-#define _RGBM_TMP_STATIC(sym, msym)  RGBLIGHT_MODE_ ## sym,
-#define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_ ## sym,
+#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_##sym,
+#define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_##sym,
+#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_##sym,
+#define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_##sym,
+#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_##sym,
+#define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_##sym,
 enum RGBLIGHT_EFFECT_MODE {
     RGBLIGHT_MODE_zero = 0,
 #include "rgblight_modes.h"
@@ -78,101 +78,101 @@ enum RGBLIGHT_EFFECT_MODE {
 
 #ifndef RGBLIGHT_H_DUMMY_DEFINE
 
-#define RGBLIGHT_MODES (RGBLIGHT_MODE_last-1)
+#    define RGBLIGHT_MODES (RGBLIGHT_MODE_last - 1)
 
 // sample: #define RGBLIGHT_EFFECT_BREATHE_CENTER   1.85
 
-#ifndef RGBLIGHT_EFFECT_BREATHE_MAX
-#define RGBLIGHT_EFFECT_BREATHE_MAX 255   // 0-255
-#endif
-
-#ifndef RGBLIGHT_EFFECT_SNAKE_LENGTH
-#define RGBLIGHT_EFFECT_SNAKE_LENGTH 4
-#endif
-
-#ifndef RGBLIGHT_EFFECT_KNIGHT_LENGTH
-#define RGBLIGHT_EFFECT_KNIGHT_LENGTH 3
-#endif
-
-#ifndef RGBLIGHT_EFFECT_KNIGHT_OFFSET
-#define RGBLIGHT_EFFECT_KNIGHT_OFFSET 0
-#endif
-
-#ifndef RGBLIGHT_EFFECT_KNIGHT_LED_NUM
-#define RGBLIGHT_EFFECT_KNIGHT_LED_NUM (effect_num_leds)
-#endif
-
-#ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL
-#define RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL 1000
-#endif
-
-#ifndef RGBLIGHT_EFFECT_CHRISTMAS_STEP
-#define RGBLIGHT_EFFECT_CHRISTMAS_STEP 2
-#endif
-
-#ifndef RGBLIGHT_HUE_STEP
-#define RGBLIGHT_HUE_STEP 8
-#endif
-#ifndef RGBLIGHT_SAT_STEP
-#define RGBLIGHT_SAT_STEP 17
-#endif
-#ifndef RGBLIGHT_VAL_STEP
-#define RGBLIGHT_VAL_STEP 17
-#endif
-#ifndef RGBLIGHT_LIMIT_VAL
-#define RGBLIGHT_LIMIT_VAL 255
-#endif
-
-#define RGBLED_TIMER_TOP F_CPU/(256*64)
+#    ifndef RGBLIGHT_EFFECT_BREATHE_MAX
+#        define RGBLIGHT_EFFECT_BREATHE_MAX 255  // 0-255
+#    endif
+
+#    ifndef RGBLIGHT_EFFECT_SNAKE_LENGTH
+#        define RGBLIGHT_EFFECT_SNAKE_LENGTH 4
+#    endif
+
+#    ifndef RGBLIGHT_EFFECT_KNIGHT_LENGTH
+#        define RGBLIGHT_EFFECT_KNIGHT_LENGTH 3
+#    endif
+
+#    ifndef RGBLIGHT_EFFECT_KNIGHT_OFFSET
+#        define RGBLIGHT_EFFECT_KNIGHT_OFFSET 0
+#    endif
+
+#    ifndef RGBLIGHT_EFFECT_KNIGHT_LED_NUM
+#        define RGBLIGHT_EFFECT_KNIGHT_LED_NUM (effect_num_leds)
+#    endif
+
+#    ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL
+#        define RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL 1000
+#    endif
+
+#    ifndef RGBLIGHT_EFFECT_CHRISTMAS_STEP
+#        define RGBLIGHT_EFFECT_CHRISTMAS_STEP 2
+#    endif
+
+#    ifndef RGBLIGHT_HUE_STEP
+#        define RGBLIGHT_HUE_STEP 8
+#    endif
+#    ifndef RGBLIGHT_SAT_STEP
+#        define RGBLIGHT_SAT_STEP 17
+#    endif
+#    ifndef RGBLIGHT_VAL_STEP
+#        define RGBLIGHT_VAL_STEP 17
+#    endif
+#    ifndef RGBLIGHT_LIMIT_VAL
+#        define RGBLIGHT_LIMIT_VAL 255
+#    endif
+
+#    define RGBLED_TIMER_TOP F_CPU / (256 * 64)
 // #define RGBLED_TIMER_TOP 0xFF10
 
-#include <stdint.h>
-#include <stdbool.h>
-#include "eeconfig.h"
-#ifndef RGBLIGHT_CUSTOM_DRIVER
-#include "ws2812.h"
-#endif
-#include "color.h"
-#include "rgblight_list.h"
+#    include <stdint.h>
+#    include <stdbool.h>
+#    include "eeconfig.h"
+#    ifndef RGBLIGHT_CUSTOM_DRIVER
+#        include "ws2812.h"
+#    endif
+#    include "color.h"
+#    include "rgblight_list.h"
 
-#if defined(__AVR__)
-    #include <avr/pgmspace.h>
-#endif
+#    if defined(__AVR__)
+#        include <avr/pgmspace.h>
+#    endif
 
 extern LED_TYPE led[RGBLED_NUM];
 
-extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM;
-extern const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM;
-extern const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[3] PROGMEM;
-extern const uint8_t RGBLED_SNAKE_INTERVALS[3] PROGMEM;
-extern const uint8_t RGBLED_KNIGHT_INTERVALS[3] PROGMEM;
+extern const uint8_t  RGBLED_BREATHING_INTERVALS[4] PROGMEM;
+extern const uint8_t  RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM;
+extern const uint8_t  RGBLED_RAINBOW_SWIRL_INTERVALS[3] PROGMEM;
+extern const uint8_t  RGBLED_SNAKE_INTERVALS[3] PROGMEM;
+extern const uint8_t  RGBLED_KNIGHT_INTERVALS[3] PROGMEM;
 extern const uint16_t RGBLED_RGBTEST_INTERVALS[1] PROGMEM;
-extern bool is_rgblight_initialized;
+extern bool           is_rgblight_initialized;
 
 // Should stay in sycn with rgb matrix config as we reuse eeprom storage for both (for now)
 typedef union {
-  uint32_t raw;
-  struct {
-    bool     enable  :1;
-    uint8_t  mode    :7;
-    uint8_t  hue     :8;
-    uint8_t  sat     :8;
-    uint8_t  val     :8;
-    uint8_t  speed   :8;//EECONFIG needs to be increased to support this
-  };
+    uint32_t raw;
+    struct {
+        bool    enable : 1;
+        uint8_t mode : 7;
+        uint8_t hue : 8;
+        uint8_t sat : 8;
+        uint8_t val : 8;
+        uint8_t speed : 8;  // EECONFIG needs to be increased to support this
+    };
 } rgblight_config_t;
 
 typedef struct _rgblight_status_t {
-    uint8_t  base_mode;
-    bool timer_enabled;
-#ifdef RGBLIGHT_SPLIT
+    uint8_t base_mode;
+    bool    timer_enabled;
+#    ifdef RGBLIGHT_SPLIT
     uint8_t change_flags;
-#endif
+#    endif
 } rgblight_status_t;
 
 /* === Utility Functions ===*/
 void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1);
-void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); // without RGBLIGHT_LIMIT_VAL check
+void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1);  // without RGBLIGHT_LIMIT_VAL check
 void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1);
 
 /* === Low level Functions === */
@@ -190,12 +190,12 @@ void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8
 void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end);
 void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b);
 
-#ifndef RGBLIGHT_SPLIT
+#    ifndef RGBLIGHT_SPLIT
 void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b);
 void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b);
 void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val);
 void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val);
-#endif
+#    endif
 
 /*   effect mode change */
 void rgblight_mode(uint8_t mode);
@@ -240,13 +240,13 @@ uint8_t rgblight_get_sat(void);
 uint8_t rgblight_get_val(void);
 
 /* === qmk_firmware (core)internal Functions === */
-void rgblight_init(void);
+void     rgblight_init(void);
 uint32_t rgblight_read_dword(void);
-void rgblight_update_dword(uint32_t dword);
+void     rgblight_update_dword(uint32_t dword);
 uint32_t eeconfig_read_rgblight(void);
-void eeconfig_update_rgblight(uint32_t val);
-void eeconfig_update_rgblight_default(void);
-void eeconfig_debug_rgblight(void);
+void     eeconfig_update_rgblight(uint32_t val);
+void     eeconfig_update_rgblight_default(void);
+void     eeconfig_debug_rgblight(void);
 
 void rgb_matrix_increase(void);
 void rgb_matrix_decrease(void);
@@ -254,7 +254,7 @@ void rgb_matrix_decrease(void);
 void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom);
 void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom);
 
-#define EZ_RGB(val) rgblight_show_solid_color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)
+#    define EZ_RGB(val) rgblight_show_solid_color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)
 void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b);
 
 void rgblight_task(void);
@@ -264,26 +264,26 @@ void rgblight_timer_enable(void);
 void rgblight_timer_disable(void);
 void rgblight_timer_toggle(void);
 
-#ifdef RGBLIGHT_SPLIT
-  #define RGBLIGHT_STATUS_CHANGE_MODE (1<<0)
-  #define RGBLIGHT_STATUS_CHANGE_HSVS (1<<1)
-  #define RGBLIGHT_STATUS_CHANGE_TIMER (1<<2)
-  #define RGBLIGHT_STATUS_ANIMATION_TICK (1<<3)
+#    ifdef RGBLIGHT_SPLIT
+#        define RGBLIGHT_STATUS_CHANGE_MODE (1 << 0)
+#        define RGBLIGHT_STATUS_CHANGE_HSVS (1 << 1)
+#        define RGBLIGHT_STATUS_CHANGE_TIMER (1 << 2)
+#        define RGBLIGHT_STATUS_ANIMATION_TICK (1 << 3)
 
-  typedef struct _rgblight_syncinfo_t {
+typedef struct _rgblight_syncinfo_t {
     rgblight_config_t config;
     rgblight_status_t status;
-  } rgblight_syncinfo_t;
+} rgblight_syncinfo_t;
 
-  /* for split keyboard master side */
-  uint8_t rgblight_get_change_flags(void);
-  void    rgblight_clear_change_flags(void);
-  void    rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo);
-  /* for split keyboard slave side */
-  void    rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom);
-#endif
+/* for split keyboard master side */
+uint8_t rgblight_get_change_flags(void);
+void    rgblight_clear_change_flags(void);
+void    rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo);
+/* for split keyboard slave side */
+void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom);
+#    endif
 
-#ifdef RGBLIGHT_USE_TIMER
+#    ifdef RGBLIGHT_USE_TIMER
 
 typedef struct _animation_status_t {
     uint16_t last_timer;
@@ -308,7 +308,7 @@ void rgblight_effect_christmas(animation_status_t *anim);
 void rgblight_effect_rgbtest(animation_status_t *anim);
 void rgblight_effect_alternating(animation_status_t *anim);
 
-#endif
+#    endif
 
-#endif // #ifndef RGBLIGHT_H_DUMMY_DEFINE
-#endif // RGBLIGHT_H
+#endif  // #ifndef RGBLIGHT_H_DUMMY_DEFINE
+#endif  // RGBLIGHT_H
index 7ab8cc9479ae250239a87d41210769dc9d3931a1..a438332bd3a375ede458dc01d21367a99981dca6 100644 (file)
 #define RGBLIGHT_EFFECT_BREATHE_TABLE
 
 const uint8_t rgblight_effect_breathe_table[] PROGMEM = {
-  /* #define RGBLIGHT_EFFECT_BREATHE_CENTER   1.85 */
-  /* #define RGBLIGHT_EFFECT_BREATHE_MAX      255 */
+/* #define RGBLIGHT_EFFECT_BREATHE_CENTER   1.85 */
+/* #define RGBLIGHT_EFFECT_BREATHE_MAX      255 */
 
- #if RGBLIGHT_BREATHE_TABLE_SIZE == 256
-  0x22,  0x23,  0x25,  0x26,  0x28,  0x29,  0x2a,  0x2c,
-  0x2d,  0x2f,  0x30,  0x32,  0x33,  0x35,  0x36,  0x38,
-  0x3a,  0x3b,  0x3d,  0x3e,  0x40,  0x42,  0x43,  0x45,
-  0x47,  0x49,  0x4a,  0x4c,  0x4e,  0x50,  0x51,  0x53,
-  0x55,  0x57,  0x59,  0x5a,  0x5c,  0x5e,  0x60,  0x62,
-  0x64,  0x66,  0x68,  0x69,  0x6b,  0x6d,  0x6f,  0x71,
-  0x73,  0x75,  0x77,  0x79,  0x7b,  0x7d,  0x7f,  0x81,
-  0x83,  0x85,  0x87,  0x89,  0x8a,  0x8c,  0x8e,  0x90,
-  0x92,  0x94,  0x96,  0x98,  0x9a,  0x9c,  0x9e,  0x9f,
-  0xa1,  0xa3,  0xa5,  0xa7,  0xa8,  0xaa,  0xac,  0xae,
-  0xaf,  0xb1,  0xb3,  0xb4,  0xb6,  0xb8,  0xb9,  0xbb,
-  0xbc,  0xbe,  0xbf,  0xc1,  0xc2,  0xc3,  0xc5,  0xc6,
-  0xc7,  0xc9,  0xca,  0xcb,  0xcc,  0xcd,  0xce,  0xd0,
-  0xd1,  0xd2,  0xd2,  0xd3,  0xd4,  0xd5,  0xd6,  0xd7,
-  0xd7,  0xd8,  0xd9,  0xd9,  0xda,  0xda,  0xdb,  0xdb,
-  0xdb,  0xdc,  0xdc,  0xdc,  0xdc,  0xdc,  0xdd,  0xdd,
-  0xdd,  0xdd,  0xdc,  0xdc,  0xdc,  0xdc,  0xdc,  0xdb,
-  0xdb,  0xdb,  0xda,  0xda,  0xd9,  0xd9,  0xd8,  0xd7,
-  0xd7,  0xd6,  0xd5,  0xd4,  0xd3,  0xd2,  0xd2,  0xd1,
-  0xd0,  0xce,  0xcd,  0xcc,  0xcb,  0xca,  0xc9,  0xc7,
-  0xc6,  0xc5,  0xc3,  0xc2,  0xc1,  0xbf,  0xbe,  0xbc,
-  0xbb,  0xb9,  0xb8,  0xb6,  0xb4,  0xb3,  0xb1,  0xaf,
-  0xae,  0xac,  0xaa,  0xa8,  0xa7,  0xa5,  0xa3,  0xa1,
-  0x9f,  0x9e,  0x9c,  0x9a,  0x98,  0x96,  0x94,  0x92,
-  0x90,  0x8e,  0x8c,  0x8a,  0x89,  0x87,  0x85,  0x83,
-  0x81,  0x7f,  0x7d,  0x7b,  0x79,  0x77,  0x75,  0x73,
-  0x71,  0x6f,  0x6d,  0x6b,  0x69,  0x68,  0x66,  0x64,
-  0x62,  0x60,  0x5e,  0x5c,  0x5a,  0x59,  0x57,  0x55,
-  0x53,  0x51,  0x50,  0x4e,  0x4c,  0x4a,  0x49,  0x47,
-  0x45,  0x43,  0x42,  0x40,  0x3e,  0x3d,  0x3b,  0x3a,
-  0x38,  0x36,  0x35,  0x33,  0x32,  0x30,  0x2f,  0x2d,
-  0x2c,  0x2a,  0x29,  0x28,  0x26,  0x25,  0x23,  0x22
- #endif /* 256 bytes table */
+#if RGBLIGHT_BREATHE_TABLE_SIZE == 256
+    0x22,
+    0x23,
+    0x25,
+    0x26,
+    0x28,
+    0x29,
+    0x2a,
+    0x2c,
+    0x2d,
+    0x2f,
+    0x30,
+    0x32,
+    0x33,
+    0x35,
+    0x36,
+    0x38,
+    0x3a,
+    0x3b,
+    0x3d,
+    0x3e,
+    0x40,
+    0x42,
+    0x43,
+    0x45,
+    0x47,
+    0x49,
+    0x4a,
+    0x4c,
+    0x4e,
+    0x50,
+    0x51,
+    0x53,
+    0x55,
+    0x57,
+    0x59,
+    0x5a,
+    0x5c,
+    0x5e,
+    0x60,
+    0x62,
+    0x64,
+    0x66,
+    0x68,
+    0x69,
+    0x6b,
+    0x6d,
+    0x6f,
+    0x71,
+    0x73,
+    0x75,
+    0x77,
+    0x79,
+    0x7b,
+    0x7d,
+    0x7f,
+    0x81,
+    0x83,
+    0x85,
+    0x87,
+    0x89,
+    0x8a,
+    0x8c,
+    0x8e,
+    0x90,
+    0x92,
+    0x94,
+    0x96,
+    0x98,
+    0x9a,
+    0x9c,
+    0x9e,
+    0x9f,
+    0xa1,
+    0xa3,
+    0xa5,
+    0xa7,
+    0xa8,
+    0xaa,
+    0xac,
+    0xae,
+    0xaf,
+    0xb1,
+    0xb3,
+    0xb4,
+    0xb6,
+    0xb8,
+    0xb9,
+    0xbb,
+    0xbc,
+    0xbe,
+    0xbf,
+    0xc1,
+    0xc2,
+    0xc3,
+    0xc5,
+    0xc6,
+    0xc7,
+    0xc9,
+    0xca,
+    0xcb,
+    0xcc,
+    0xcd,
+    0xce,
+    0xd0,
+    0xd1,
+    0xd2,
+    0xd2,
+    0xd3,
+    0xd4,
+    0xd5,
+    0xd6,
+    0xd7,
+    0xd7,
+    0xd8,
+    0xd9,
+    0xd9,
+    0xda,
+    0xda,
+    0xdb,
+    0xdb,
+    0xdb,
+    0xdc,
+    0xdc,
+    0xdc,
+    0xdc,
+    0xdc,
+    0xdd,
+    0xdd,
+    0xdd,
+    0xdd,
+    0xdc,
+    0xdc,
+    0xdc,
+    0xdc,
+    0xdc,
+    0xdb,
+    0xdb,
+    0xdb,
+    0xda,
+    0xda,
+    0xd9,
+    0xd9,
+    0xd8,
+    0xd7,
+    0xd7,
+    0xd6,
+    0xd5,
+    0xd4,
+    0xd3,
+    0xd2,
+    0xd2,
+    0xd1,
+    0xd0,
+    0xce,
+    0xcd,
+    0xcc,
+    0xcb,
+    0xca,
+    0xc9,
+    0xc7,
+    0xc6,
+    0xc5,
+    0xc3,
+    0xc2,
+    0xc1,
+    0xbf,
+    0xbe,
+    0xbc,
+    0xbb,
+    0xb9,
+    0xb8,
+    0xb6,
+    0xb4,
+    0xb3,
+    0xb1,
+    0xaf,
+    0xae,
+    0xac,
+    0xaa,
+    0xa8,
+    0xa7,
+    0xa5,
+    0xa3,
+    0xa1,
+    0x9f,
+    0x9e,
+    0x9c,
+    0x9a,
+    0x98,
+    0x96,
+    0x94,
+    0x92,
+    0x90,
+    0x8e,
+    0x8c,
+    0x8a,
+    0x89,
+    0x87,
+    0x85,
+    0x83,
+    0x81,
+    0x7f,
+    0x7d,
+    0x7b,
+    0x79,
+    0x77,
+    0x75,
+    0x73,
+    0x71,
+    0x6f,
+    0x6d,
+    0x6b,
+    0x69,
+    0x68,
+    0x66,
+    0x64,
+    0x62,
+    0x60,
+    0x5e,
+    0x5c,
+    0x5a,
+    0x59,
+    0x57,
+    0x55,
+    0x53,
+    0x51,
+    0x50,
+    0x4e,
+    0x4c,
+    0x4a,
+    0x49,
+    0x47,
+    0x45,
+    0x43,
+    0x42,
+    0x40,
+    0x3e,
+    0x3d,
+    0x3b,
+    0x3a,
+    0x38,
+    0x36,
+    0x35,
+    0x33,
+    0x32,
+    0x30,
+    0x2f,
+    0x2d,
+    0x2c,
+    0x2a,
+    0x29,
+    0x28,
+    0x26,
+    0x25,
+    0x23,
+    0x22
+#endif /* 256 bytes table */
 
- #if RGBLIGHT_BREATHE_TABLE_SIZE == 128
-  0x22,  0x25,  0x28,  0x2a,
-  0x2d,  0x30,  0x33,  0x36,
-  0x3a,  0x3d,  0x40,  0x43,
-  0x47,  0x4a,  0x4e,  0x51,
-  0x55,  0x59,  0x5c,  0x60,
-  0x64,  0x68,  0x6b,  0x6f,
-  0x73,  0x77,  0x7b,  0x7f,
-  0x83,  0x87,  0x8a,  0x8e,
-  0x92,  0x96,  0x9a,  0x9e,
-  0xa1,  0xa5,  0xa8,  0xac,
-  0xaf,  0xb3,  0xb6,  0xb9,
-  0xbc,  0xbf,  0xc2,  0xc5,
-  0xc7,  0xca,  0xcc,  0xce,
-  0xd1,  0xd2,  0xd4,  0xd6,
-  0xd7,  0xd9,  0xda,  0xdb,
-  0xdb,  0xdc,  0xdc,  0xdd,
-  0xdd,  0xdc,  0xdc,  0xdc,
-  0xdb,  0xda,  0xd9,  0xd8,
-  0xd7,  0xd5,  0xd3,  0xd2,
-  0xd0,  0xcd,  0xcb,  0xc9,
-  0xc6,  0xc3,  0xc1,  0xbe,
-  0xbb,  0xb8,  0xb4,  0xb1,
-  0xae,  0xaa,  0xa7,  0xa3,
-  0x9f,  0x9c,  0x98,  0x94,
-  0x90,  0x8c,  0x89,  0x85,
-  0x81,  0x7d,  0x79,  0x75,
-  0x71,  0x6d,  0x69,  0x66,
-  0x62,  0x5e,  0x5a,  0x57,
-  0x53,  0x50,  0x4c,  0x49,
-  0x45,  0x42,  0x3e,  0x3b,
-  0x38,  0x35,  0x32,  0x2f,
-  0x2c,  0x29,  0x26,  0x23
- #endif /* 128 bytes table */
+#if RGBLIGHT_BREATHE_TABLE_SIZE == 128
+    0x22,
+    0x25,
+    0x28,
+    0x2a,
+    0x2d,
+    0x30,
+    0x33,
+    0x36,
+    0x3a,
+    0x3d,
+    0x40,
+    0x43,
+    0x47,
+    0x4a,
+    0x4e,
+    0x51,
+    0x55,
+    0x59,
+    0x5c,
+    0x60,
+    0x64,
+    0x68,
+    0x6b,
+    0x6f,
+    0x73,
+    0x77,
+    0x7b,
+    0x7f,
+    0x83,
+    0x87,
+    0x8a,
+    0x8e,
+    0x92,
+    0x96,
+    0x9a,
+    0x9e,
+    0xa1,
+    0xa5,
+    0xa8,
+    0xac,
+    0xaf,
+    0xb3,
+    0xb6,
+    0xb9,
+    0xbc,
+    0xbf,
+    0xc2,
+    0xc5,
+    0xc7,
+    0xca,
+    0xcc,
+    0xce,
+    0xd1,
+    0xd2,
+    0xd4,
+    0xd6,
+    0xd7,
+    0xd9,
+    0xda,
+    0xdb,
+    0xdb,
+    0xdc,
+    0xdc,
+    0xdd,
+    0xdd,
+    0xdc,
+    0xdc,
+    0xdc,
+    0xdb,
+    0xda,
+    0xd9,
+    0xd8,
+    0xd7,
+    0xd5,
+    0xd3,
+    0xd2,
+    0xd0,
+    0xcd,
+    0xcb,
+    0xc9,
+    0xc6,
+    0xc3,
+    0xc1,
+    0xbe,
+    0xbb,
+    0xb8,
+    0xb4,
+    0xb1,
+    0xae,
+    0xaa,
+    0xa7,
+    0xa3,
+    0x9f,
+    0x9c,
+    0x98,
+    0x94,
+    0x90,
+    0x8c,
+    0x89,
+    0x85,
+    0x81,
+    0x7d,
+    0x79,
+    0x75,
+    0x71,
+    0x6d,
+    0x69,
+    0x66,
+    0x62,
+    0x5e,
+    0x5a,
+    0x57,
+    0x53,
+    0x50,
+    0x4c,
+    0x49,
+    0x45,
+    0x42,
+    0x3e,
+    0x3b,
+    0x38,
+    0x35,
+    0x32,
+    0x2f,
+    0x2c,
+    0x29,
+    0x26,
+    0x23
+#endif /* 128 bytes table */
 
- #if RGBLIGHT_BREATHE_TABLE_SIZE == 64
-  0x22,  0x28,
-  0x2d,  0x33,
-  0x3a,  0x40,
-  0x47,  0x4e,
-  0x55,  0x5c,
-  0x64,  0x6b,
-  0x73,  0x7b,
-  0x83,  0x8a,
-  0x92,  0x9a,
-  0xa1,  0xa8,
-  0xaf,  0xb6,
-  0xbc,  0xc2,
-  0xc7,  0xcc,
-  0xd1,  0xd4,
-  0xd7,  0xda,
-  0xdb,  0xdc,
-  0xdd,  0xdc,
-  0xdb,  0xd9,
-  0xd7,  0xd3,
-  0xd0,  0xcb,
-  0xc6,  0xc1,
-  0xbb,  0xb4,
-  0xae,  0xa7,
-  0x9f,  0x98,
-  0x90,  0x89,
-  0x81,  0x79,
-  0x71,  0x69,
-  0x62,  0x5a,
-  0x53,  0x4c,
-  0x45,  0x3e,
-  0x38,  0x32,
-  0x2c,  0x26
- #endif /* 64 bytes table */
+#if RGBLIGHT_BREATHE_TABLE_SIZE == 64
+    0x22,
+    0x28,
+    0x2d,
+    0x33,
+    0x3a,
+    0x40,
+    0x47,
+    0x4e,
+    0x55,
+    0x5c,
+    0x64,
+    0x6b,
+    0x73,
+    0x7b,
+    0x83,
+    0x8a,
+    0x92,
+    0x9a,
+    0xa1,
+    0xa8,
+    0xaf,
+    0xb6,
+    0xbc,
+    0xc2,
+    0xc7,
+    0xcc,
+    0xd1,
+    0xd4,
+    0xd7,
+    0xda,
+    0xdb,
+    0xdc,
+    0xdd,
+    0xdc,
+    0xdb,
+    0xd9,
+    0xd7,
+    0xd3,
+    0xd0,
+    0xcb,
+    0xc6,
+    0xc1,
+    0xbb,
+    0xb4,
+    0xae,
+    0xa7,
+    0x9f,
+    0x98,
+    0x90,
+    0x89,
+    0x81,
+    0x79,
+    0x71,
+    0x69,
+    0x62,
+    0x5a,
+    0x53,
+    0x4c,
+    0x45,
+    0x3e,
+    0x38,
+    0x32,
+    0x2c,
+    0x26
+#endif /* 64 bytes table */
 };
 
-static const int table_scale = 256/sizeof(rgblight_effect_breathe_table);
+static const int table_scale = 256 / sizeof(rgblight_effect_breathe_table);
 
 #endif /* RGBLIGHT_EFFECT_BREATHE_TABLE */
index 702e33e76542d52f7795eabde582effae2f67d35..e30733baa6be584a19dab19405a3623b5843bf81 100644 (file)
 #pragma once
 
 /*              RGB COLORS             */
-#define RGB_WHITE        0xFF, 0xFF, 0xFF
-#define RGB_RED          0xFF, 0x00, 0x00
-#define RGB_CORAL        0xFF, 0x7C, 0x4D
-#define RGB_ORANGE       0xFF, 0x80, 0x00
-#define RGB_GOLDENROD    0xD9, 0xA5, 0x21
-#define RGB_GOLD         0xFF, 0xD9, 0x00
-#define RGB_YELLOW       0xFF, 0xFF, 0x00
-#define RGB_CHARTREUSE   0x80, 0xFF, 0x00
-#define RGB_GREEN        0x00, 0xFF, 0x00
-#define RGB_SPRINGGREEN  0x00, 0xFF, 0x80
-#define RGB_TURQUOISE    0x47, 0x6E, 0x6A
-#define RGB_TEAL         0x00, 0x80, 0x80
-#define RGB_CYAN         0x00, 0xFF, 0xFF
-#define RGB_AZURE        0x99, 0xf5, 0xFF
-#define RGB_BLUE         0x00, 0x00, 0xFF
-#define RGB_PURPLE       0x7A, 0x00, 0xFF
-#define RGB_MAGENTA      0xFF, 0x00, 0xFF
-#define RGB_PINK         0xFF, 0x80, 0xBF
+#define RGB_WHITE 0xFF, 0xFF, 0xFF
+#define RGB_RED 0xFF, 0x00, 0x00
+#define RGB_CORAL 0xFF, 0x7C, 0x4D
+#define RGB_ORANGE 0xFF, 0x80, 0x00
+#define RGB_GOLDENROD 0xD9, 0xA5, 0x21
+#define RGB_GOLD 0xFF, 0xD9, 0x00
+#define RGB_YELLOW 0xFF, 0xFF, 0x00
+#define RGB_CHARTREUSE 0x80, 0xFF, 0x00
+#define RGB_GREEN 0x00, 0xFF, 0x00
+#define RGB_SPRINGGREEN 0x00, 0xFF, 0x80
+#define RGB_TURQUOISE 0x47, 0x6E, 0x6A
+#define RGB_TEAL 0x00, 0x80, 0x80
+#define RGB_CYAN 0x00, 0xFF, 0xFF
+#define RGB_AZURE 0x99, 0xf5, 0xFF
+#define RGB_BLUE 0x00, 0x00, 0xFF
+#define RGB_PURPLE 0x7A, 0x00, 0xFF
+#define RGB_MAGENTA 0xFF, 0x00, 0xFF
+#define RGB_PINK 0xFF, 0x80, 0xBF
 
 /*            HSV COLORS            */
-#define HSV_WHITE          0,   0, 255
-#define HSV_RED            0, 255, 255
-#define HSV_CORAL         11, 176, 255
-#define HSV_ORANGE        28, 255, 255
-#define HSV_GOLDENROD     30, 218, 218
-#define HSV_GOLD          36, 255, 255
-#define HSV_YELLOW        43, 255, 255
-#define HSV_CHARTREUSE    64, 255, 255
-#define HSV_GREEN         85, 255, 255
-#define HSV_SPRINGGREEN  106, 255, 255
-#define HSV_TURQUOISE    123,  90, 112
-#define HSV_TEAL         128, 255, 128
-#define HSV_CYAN         128, 255, 255
-#define HSV_AZURE        132, 102, 255
-#define HSV_BLUE         170, 255, 255
-#define HSV_PURPLE       191, 255, 255
-#define HSV_MAGENTA      213, 255, 255
-#define HSV_PINK         234, 128, 255
-
+#define HSV_WHITE 0, 0, 255
+#define HSV_RED 0, 255, 255
+#define HSV_CORAL 11, 176, 255
+#define HSV_ORANGE 28, 255, 255
+#define HSV_GOLDENROD 30, 218, 218
+#define HSV_GOLD 36, 255, 255
+#define HSV_YELLOW 43, 255, 255
+#define HSV_CHARTREUSE 64, 255, 255
+#define HSV_GREEN 85, 255, 255
+#define HSV_SPRINGGREEN 106, 255, 255
+#define HSV_TURQUOISE 123, 90, 112
+#define HSV_TEAL 128, 255, 128
+#define HSV_CYAN 128, 255, 255
+#define HSV_AZURE 132, 102, 255
+#define HSV_BLUE 170, 255, 255
+#define HSV_PURPLE 191, 255, 255
+#define HSV_MAGENTA 213, 255, 255
+#define HSV_PINK 234, 128, 255
 
 /*
 ########################################################################################
 */
 
 /*                            SET RGB List                            */
-#define rgblight_setrgb_white()       rgblight_setrgb (RGB_WHITE)
-#define rgblight_setrgb_red()         rgblight_setrgb (RGB_RED)
-#define rgblight_setrgb_coral()       rgblight_setrgb (RGB_CORAL)
-#define rgblight_setrgb_orange()      rgblight_setrgb (RGB_ORANGE)
-#define rgblight_setrgb_goldenrod()   rgblight_setrgb (RGB_GOLDENROD)
-#define rgblight_setrgb_gold()        rgblight_setrgb (RGB_GOLD)
-#define rgblight_setrgb_yellow()      rgblight_setrgb (RGB_YELLOW)
-#define rgblight_setrgb_chartreuse()  rgblight_setrgb (RGB_CHARTREUSE)
-#define rgblight_setrgb_green()       rgblight_setrgb (RGB_GREEN)
-#define rgblight_setrgb_springgreen() rgblight_setrgb (RGB_SPRINGGREEN)
-#define rgblight_setrgb_turquoise()   rgblight_setrgb (RGB_TURQUOISE)
-#define rgblight_setrgb_teal()        rgblight_setrgb (RGB_TEAL)
-#define rgblight_setrgb_cyan()        rgblight_setrgb (RGB_CYAN)
-#define rgblight_setrgb_azure()       rgblight_setrgb (RGB_AZURE)
-#define rgblight_setrgb_blue()        rgblight_setrgb (RGB_BLUE)
-#define rgblight_setrgb_purple()      rgblight_setrgb (RGB_PURPLE)
-#define rgblight_setrgb_magenta()     rgblight_setrgb (RGB_MAGENTA)
-#define rgblight_setrgb_pink()        rgblight_setrgb (RGB_PINK)
+#define rgblight_setrgb_white() rgblight_setrgb(RGB_WHITE)
+#define rgblight_setrgb_red() rgblight_setrgb(RGB_RED)
+#define rgblight_setrgb_coral() rgblight_setrgb(RGB_CORAL)
+#define rgblight_setrgb_orange() rgblight_setrgb(RGB_ORANGE)
+#define rgblight_setrgb_goldenrod() rgblight_setrgb(RGB_GOLDENROD)
+#define rgblight_setrgb_gold() rgblight_setrgb(RGB_GOLD)
+#define rgblight_setrgb_yellow() rgblight_setrgb(RGB_YELLOW)
+#define rgblight_setrgb_chartreuse() rgblight_setrgb(RGB_CHARTREUSE)
+#define rgblight_setrgb_green() rgblight_setrgb(RGB_GREEN)
+#define rgblight_setrgb_springgreen() rgblight_setrgb(RGB_SPRINGGREEN)
+#define rgblight_setrgb_turquoise() rgblight_setrgb(RGB_TURQUOISE)
+#define rgblight_setrgb_teal() rgblight_setrgb(RGB_TEAL)
+#define rgblight_setrgb_cyan() rgblight_setrgb(RGB_CYAN)
+#define rgblight_setrgb_azure() rgblight_setrgb(RGB_AZURE)
+#define rgblight_setrgb_blue() rgblight_setrgb(RGB_BLUE)
+#define rgblight_setrgb_purple() rgblight_setrgb(RGB_PURPLE)
+#define rgblight_setrgb_magenta() rgblight_setrgb(RGB_MAGENTA)
+#define rgblight_setrgb_pink() rgblight_setrgb(RGB_PINK)
 
 /*                            SET RGB List                            */
-#define rgblight_setrgb_white_at(at)       rgblight_setrgb_at (RGB_WHITE, at)
-#define rgblight_setrgb_red_at(at)         rgblight_setrgb_at (RGB_RED, at)
-#define rgblight_setrgb_coral_at(at)       rgblight_setrgb_at (RGB_CORAL, at)
-#define rgblight_setrgb_orange_at(at)      rgblight_setrgb_at (RGB_ORANGE at)
-#define rgblight_setrgb_goldenrod_at(at)   rgblight_setrgb_at (RGB_GOLDENROD, at)
-#define rgblight_setrgb_gold_at(at)        rgblight_setrgb_at (RGB_GOLD, at)
-#define rgblight_setrgb_yellow_at(at)      rgblight_setrgb_at (RGB_YELLOW, at)
-#define rgblight_setrgb_chartreuse_at(at)  rgblight_setrgb_at (RGB_CHARTREUSE, at)
-#define rgblight_setrgb_green_at(at)       rgblight_setrgb_at (RGB_GREEN, at)
-#define rgblight_setrgb_springgreen_at(at) rgblight_setrgb_at (RGB_SPRINGGREEN, at)
-#define rgblight_setrgb_turquoise_at(at)   rgblight_setrgb_at (RGB_TURQUOISE, at)
-#define rgblight_setrgb_teal_at(at)        rgblight_setrgb_at (RGB_TEAL, at)
-#define rgblight_setrgb_cyan_at(at)        rgblight_setrgb_at (RGB_CYAN, at)
-#define rgblight_setrgb_azure_at(at)       rgblight_setrgb_at (RGB_AZURE, at)
-#define rgblight_setrgb_blue_at(at)        rgblight_setrgb_at (RGB_BLUE, at)
-#define rgblight_setrgb_purple_at(at)      rgblight_setrgb_at (RGB_PURPLE, at)
-#define rgblight_setrgb_magenta_at(at)     rgblight_setrgb_at (RGB_MAGENTA, at)
-#define rgblight_setrgb_pink_at(at)        rgblight_setrgb_at (RGB_PINK, at)
+#define rgblight_setrgb_white_at(at) rgblight_setrgb_at(RGB_WHITE, at)
+#define rgblight_setrgb_red_at(at) rgblight_setrgb_at(RGB_RED, at)
+#define rgblight_setrgb_coral_at(at) rgblight_setrgb_at(RGB_CORAL, at)
+#define rgblight_setrgb_orange_at(at) rgblight_setrgb_at(RGB_ORANGE at)
+#define rgblight_setrgb_goldenrod_at(at) rgblight_setrgb_at(RGB_GOLDENROD, at)
+#define rgblight_setrgb_gold_at(at) rgblight_setrgb_at(RGB_GOLD, at)
+#define rgblight_setrgb_yellow_at(at) rgblight_setrgb_at(RGB_YELLOW, at)
+#define rgblight_setrgb_chartreuse_at(at) rgblight_setrgb_at(RGB_CHARTREUSE, at)
+#define rgblight_setrgb_green_at(at) rgblight_setrgb_at(RGB_GREEN, at)
+#define rgblight_setrgb_springgreen_at(at) rgblight_setrgb_at(RGB_SPRINGGREEN, at)
+#define rgblight_setrgb_turquoise_at(at) rgblight_setrgb_at(RGB_TURQUOISE, at)
+#define rgblight_setrgb_teal_at(at) rgblight_setrgb_at(RGB_TEAL, at)
+#define rgblight_setrgb_cyan_at(at) rgblight_setrgb_at(RGB_CYAN, at)
+#define rgblight_setrgb_azure_at(at) rgblight_setrgb_at(RGB_AZURE, at)
+#define rgblight_setrgb_blue_at(at) rgblight_setrgb_at(RGB_BLUE, at)
+#define rgblight_setrgb_purple_at(at) rgblight_setrgb_at(RGB_PURPLE, at)
+#define rgblight_setrgb_magenta_at(at) rgblight_setrgb_at(RGB_MAGENTA, at)
+#define rgblight_setrgb_pink_at(at) rgblight_setrgb_at(RGB_PINK, at)
 
 /*                            SET HSV List                            */
-#define rgblight_sethsv_white()       rgblight_sethsv (HSV_WHITE)
-#define rgblight_sethsv_red()         rgblight_sethsv (HSV_RED)
-#define rgblight_sethsv_coral()       rgblight_sethsv (HSV_CORAL)
-#define rgblight_sethsv_orange()      rgblight_sethsv (HSV_ORANGE)
-#define rgblight_sethsv_goldenrod()   rgblight_sethsv (HSV_GOLDENROD)
-#define rgblight_sethsv_gold()        rgblight_sethsv (HSV_GOLD)
-#define rgblight_sethsv_yellow()      rgblight_sethsv (HSV_YELLOW)
-#define rgblight_sethsv_chartreuse()  rgblight_sethsv (HSV_CHARTREUSE)
-#define rgblight_sethsv_green()       rgblight_sethsv (HSV_GREEN)
-#define rgblight_sethsv_springgreen() rgblight_sethsv (HSV_SPRINGGREEN)
-#define rgblight_sethsv_turquoise()   rgblight_sethsv (HSV_TURQUOISE)
-#define rgblight_sethsv_teal()        rgblight_sethsv (HSV_TEAL)
-#define rgblight_sethsv_cyan()        rgblight_sethsv (HSV_CYAN)
-#define rgblight_sethsv_azure()       rgblight_sethsv (HSV_AZURE)
-#define rgblight_sethsv_blue()        rgblight_sethsv (HSV_BLUE)
-#define rgblight_sethsv_purple()      rgblight_sethsv (HSV_PURPLE)
-#define rgblight_sethsv_magenta()     rgblight_sethsv (HSV_MAGENTA)
-#define rgblight_sethsv_pink()        rgblight_sethsv (HSV_PINK)
+#define rgblight_sethsv_white() rgblight_sethsv(HSV_WHITE)
+#define rgblight_sethsv_red() rgblight_sethsv(HSV_RED)
+#define rgblight_sethsv_coral() rgblight_sethsv(HSV_CORAL)
+#define rgblight_sethsv_orange() rgblight_sethsv(HSV_ORANGE)
+#define rgblight_sethsv_goldenrod() rgblight_sethsv(HSV_GOLDENROD)
+#define rgblight_sethsv_gold() rgblight_sethsv(HSV_GOLD)
+#define rgblight_sethsv_yellow() rgblight_sethsv(HSV_YELLOW)
+#define rgblight_sethsv_chartreuse() rgblight_sethsv(HSV_CHARTREUSE)
+#define rgblight_sethsv_green() rgblight_sethsv(HSV_GREEN)
+#define rgblight_sethsv_springgreen() rgblight_sethsv(HSV_SPRINGGREEN)
+#define rgblight_sethsv_turquoise() rgblight_sethsv(HSV_TURQUOISE)
+#define rgblight_sethsv_teal() rgblight_sethsv(HSV_TEAL)
+#define rgblight_sethsv_cyan() rgblight_sethsv(HSV_CYAN)
+#define rgblight_sethsv_azure() rgblight_sethsv(HSV_AZURE)
+#define rgblight_sethsv_blue() rgblight_sethsv(HSV_BLUE)
+#define rgblight_sethsv_purple() rgblight_sethsv(HSV_PURPLE)
+#define rgblight_sethsv_magenta() rgblight_sethsv(HSV_MAGENTA)
+#define rgblight_sethsv_pink() rgblight_sethsv(HSV_PINK)
 
 /*                            SET HSV List                            */
 /*   If you're doing layer indication, this is best, as it won't      */
 /*   write to the eeprom, since it's limited (very high value).       */
 /*   If you want to use modes with this (since you can), then you     */
 /*   want to use rgblight_mode_noeeprom(x) instead.                   */
-#define rgblight_sethsv_noeeprom_white()       rgblight_sethsv_noeeprom (HSV_WHITE)
-#define rgblight_sethsv_noeeprom_red()         rgblight_sethsv_noeeprom (HSV_RED)
-#define rgblight_sethsv_noeeprom_coral()       rgblight_sethsv_noeeprom (HSV_CORAL)
-#define rgblight_sethsv_noeeprom_orange()      rgblight_sethsv_noeeprom (HSV_ORANGE)
-#define rgblight_sethsv_noeeprom_goldenrod()   rgblight_sethsv_noeeprom (HSV_GOLDENROD)
-#define rgblight_sethsv_noeeprom_gold()        rgblight_sethsv_noeeprom (HSV_GOLD)
-#define rgblight_sethsv_noeeprom_yellow()      rgblight_sethsv_noeeprom (HSV_YELLOW)
-#define rgblight_sethsv_noeeprom_chartreuse()  rgblight_sethsv_noeeprom (HSV_CHARTREUSE)
-#define rgblight_sethsv_noeeprom_green()       rgblight_sethsv_noeeprom (HSV_GREEN)
-#define rgblight_sethsv_noeeprom_springgreen() rgblight_sethsv_noeeprom (HSV_SPRINGGREEN)
-#define rgblight_sethsv_noeeprom_turquoise()   rgblight_sethsv_noeeprom (HSV_TURQUOISE)
-#define rgblight_sethsv_noeeprom_teal()        rgblight_sethsv_noeeprom (HSV_TEAL)
-#define rgblight_sethsv_noeeprom_cyan()        rgblight_sethsv_noeeprom (HSV_CYAN)
-#define rgblight_sethsv_noeeprom_azure()       rgblight_sethsv_noeeprom (HSV_AZURE)
-#define rgblight_sethsv_noeeprom_blue()        rgblight_sethsv_noeeprom (HSV_BLUE)
-#define rgblight_sethsv_noeeprom_purple()      rgblight_sethsv_noeeprom (HSV_PURPLE)
-#define rgblight_sethsv_noeeprom_magenta()     rgblight_sethsv_noeeprom (HSV_MAGENTA)
-#define rgblight_sethsv_noeeprom_pink()        rgblight_sethsv_noeeprom (HSV_PINK)
+#define rgblight_sethsv_noeeprom_white() rgblight_sethsv_noeeprom(HSV_WHITE)
+#define rgblight_sethsv_noeeprom_red() rgblight_sethsv_noeeprom(HSV_RED)
+#define rgblight_sethsv_noeeprom_coral() rgblight_sethsv_noeeprom(HSV_CORAL)
+#define rgblight_sethsv_noeeprom_orange() rgblight_sethsv_noeeprom(HSV_ORANGE)
+#define rgblight_sethsv_noeeprom_goldenrod() rgblight_sethsv_noeeprom(HSV_GOLDENROD)
+#define rgblight_sethsv_noeeprom_gold() rgblight_sethsv_noeeprom(HSV_GOLD)
+#define rgblight_sethsv_noeeprom_yellow() rgblight_sethsv_noeeprom(HSV_YELLOW)
+#define rgblight_sethsv_noeeprom_chartreuse() rgblight_sethsv_noeeprom(HSV_CHARTREUSE)
+#define rgblight_sethsv_noeeprom_green() rgblight_sethsv_noeeprom(HSV_GREEN)
+#define rgblight_sethsv_noeeprom_springgreen() rgblight_sethsv_noeeprom(HSV_SPRINGGREEN)
+#define rgblight_sethsv_noeeprom_turquoise() rgblight_sethsv_noeeprom(HSV_TURQUOISE)
+#define rgblight_sethsv_noeeprom_teal() rgblight_sethsv_noeeprom(HSV_TEAL)
+#define rgblight_sethsv_noeeprom_cyan() rgblight_sethsv_noeeprom(HSV_CYAN)
+#define rgblight_sethsv_noeeprom_azure() rgblight_sethsv_noeeprom(HSV_AZURE)
+#define rgblight_sethsv_noeeprom_blue() rgblight_sethsv_noeeprom(HSV_BLUE)
+#define rgblight_sethsv_noeeprom_purple() rgblight_sethsv_noeeprom(HSV_PURPLE)
+#define rgblight_sethsv_noeeprom_magenta() rgblight_sethsv_noeeprom(HSV_MAGENTA)
+#define rgblight_sethsv_noeeprom_pink() rgblight_sethsv_noeeprom(HSV_PINK)
 
 /*                            SET HSV List                            */
-#define rgblight_sethsv_white_at(at)       rgblight_sethsv_at (HSV_WHITE, at)
-#define rgblight_sethsv_red_at(at)         rgblight_sethsv_at (HSV_RED, at)
-#define rgblight_sethsv_coral_at(at)       rgblight_sethsv_at (HSV_CORAL, at)
-#define rgblight_sethsv_orange_at(at)      rgblight_sethsv_at (HSV_ORANGE, at)
-#define rgblight_sethsv_goldenrod_at(at)   rgblight_sethsv_at (HSV_GOLDENROD, at)
-#define rgblight_sethsv_gold_at(at)        rgblight_sethsv_at (HSV_GOLD, at)
-#define rgblight_sethsv_yellow_at(at)      rgblight_sethsv_at (HSV_YELLOW, at)
-#define rgblight_sethsv_chartreuse_at(at)  rgblight_sethsv_at (HSV_CHARTREUSE, at)
-#define rgblight_sethsv_green_at(at)       rgblight_sethsv_at (HSV_GREEN, at)
-#define rgblight_sethsv_springgreen_at(at) rgblight_sethsv_at (HSV_SPRINGGREEN, at)
-#define rgblight_sethsv_turquoise_at(at)   rgblight_sethsv_at (HSV_TURQUOISE, at)
-#define rgblight_sethsv_teal_at(at)        rgblight_sethsv_at (HSV_TEAL, at)
-#define rgblight_sethsv_cyan_at(at)        rgblight_sethsv_at (HSV_CYAN, at)
-#define rgblight_sethsv_azure_at(at)       rgblight_sethsv_at (HSV_AZURE, at)
-#define rgblight_sethsv_blue_at(at)        rgblight_sethsv_at (HSV_BLUE, at)
-#define rgblight_sethsv_purple_at(at)      rgblight_sethsv_at (HSV_PURPLE, at)
-#define rgblight_sethsv_magenta_at(at)     rgblight_sethsv_at (HSV_MAGENTA, at)
-#define rgblight_sethsv_pink_at(at)        rgblight_sethsv_at (HSV_PINK, at)
+#define rgblight_sethsv_white_at(at) rgblight_sethsv_at(HSV_WHITE, at)
+#define rgblight_sethsv_red_at(at) rgblight_sethsv_at(HSV_RED, at)
+#define rgblight_sethsv_coral_at(at) rgblight_sethsv_at(HSV_CORAL, at)
+#define rgblight_sethsv_orange_at(at) rgblight_sethsv_at(HSV_ORANGE, at)
+#define rgblight_sethsv_goldenrod_at(at) rgblight_sethsv_at(HSV_GOLDENROD, at)
+#define rgblight_sethsv_gold_at(at) rgblight_sethsv_at(HSV_GOLD, at)
+#define rgblight_sethsv_yellow_at(at) rgblight_sethsv_at(HSV_YELLOW, at)
+#define rgblight_sethsv_chartreuse_at(at) rgblight_sethsv_at(HSV_CHARTREUSE, at)
+#define rgblight_sethsv_green_at(at) rgblight_sethsv_at(HSV_GREEN, at)
+#define rgblight_sethsv_springgreen_at(at) rgblight_sethsv_at(HSV_SPRINGGREEN, at)
+#define rgblight_sethsv_turquoise_at(at) rgblight_sethsv_at(HSV_TURQUOISE, at)
+#define rgblight_sethsv_teal_at(at) rgblight_sethsv_at(HSV_TEAL, at)
+#define rgblight_sethsv_cyan_at(at) rgblight_sethsv_at(HSV_CYAN, at)
+#define rgblight_sethsv_azure_at(at) rgblight_sethsv_at(HSV_AZURE, at)
+#define rgblight_sethsv_blue_at(at) rgblight_sethsv_at(HSV_BLUE, at)
+#define rgblight_sethsv_purple_at(at) rgblight_sethsv_at(HSV_PURPLE, at)
+#define rgblight_sethsv_magenta_at(at) rgblight_sethsv_at(HSV_MAGENTA, at)
+#define rgblight_sethsv_pink_at(at) rgblight_sethsv_at(HSV_PINK, at)
index 8a8f9bdda97e2d7e1e6c95f18be3db60c309d258..40c9ce4980a78cc29b413aa3b12a892b9cf4d22c 100644 (file)
@@ -1,62 +1,62 @@
 #ifdef _RGBM_SINGLE_STATIC
-  _RGBM_SINGLE_STATIC( STATIC_LIGHT )
-  #ifdef RGBLIGHT_EFFECT_BREATHING
-    _RGBM_MULTI_DYNAMIC( BREATHING )
-    _RGBM_TMP_DYNAMIC( breathing_3, BREATHING )
-    _RGBM_TMP_DYNAMIC( breathing_4, BREATHING )
-    _RGBM_TMP_DYNAMIC( BREATHING_end, BREATHING )
-  #endif
-  #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
-    _RGBM_MULTI_DYNAMIC( RAINBOW_MOOD )
-    _RGBM_TMP_DYNAMIC( rainbow_mood_7, RAINBOW_MOOD )
-    _RGBM_TMP_DYNAMIC( RAINBOW_MOOD_end, RAINBOW_MOOD )
-  #endif
-  #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
-    _RGBM_MULTI_DYNAMIC( RAINBOW_SWIRL )
-    _RGBM_TMP_DYNAMIC( rainbow_swirl_10, RAINBOW_SWIRL )
-    _RGBM_TMP_DYNAMIC( rainbow_swirl_11, RAINBOW_SWIRL )
-    _RGBM_TMP_DYNAMIC( rainbow_swirl_12, RAINBOW_SWIRL )
-    _RGBM_TMP_DYNAMIC( rainbow_swirl_13, RAINBOW_SWIRL )
-    _RGBM_TMP_DYNAMIC( RAINBOW_SWIRL_end, RAINBOW_SWIRL )
-  #endif
-  #ifdef RGBLIGHT_EFFECT_SNAKE
-    _RGBM_MULTI_DYNAMIC( SNAKE )
-    _RGBM_TMP_DYNAMIC( snake_16, SNAKE )
-    _RGBM_TMP_DYNAMIC( snake_17, SNAKE )
-    _RGBM_TMP_DYNAMIC( snake_18, SNAKE )
-    _RGBM_TMP_DYNAMIC( snake_19, SNAKE )
-    _RGBM_TMP_DYNAMIC( SNAKE_end, SNAKE )
-  #endif
-  #ifdef RGBLIGHT_EFFECT_KNIGHT
-    _RGBM_MULTI_DYNAMIC( KNIGHT )
-    _RGBM_TMP_DYNAMIC( knight_22, KNIGHT )
-    _RGBM_TMP_DYNAMIC( KNIGHT_end, KNIGHT )
-  #endif
-  #ifdef RGBLIGHT_EFFECT_CHRISTMAS
-    _RGBM_SINGLE_DYNAMIC( CHRISTMAS )
-  #endif
-  #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
-    _RGBM_MULTI_STATIC( STATIC_GRADIENT )
-    _RGBM_TMP_STATIC( static_gradient_26, STATIC_GRADIENT )
-    _RGBM_TMP_STATIC( static_gradient_27, STATIC_GRADIENT )
-    _RGBM_TMP_STATIC( static_gradient_28, STATIC_GRADIENT )
-    _RGBM_TMP_STATIC( static_gradient_29, STATIC_GRADIENT )
-    _RGBM_TMP_STATIC( static_gradient_30, STATIC_GRADIENT )
-    _RGBM_TMP_STATIC( static_gradient_31, STATIC_GRADIENT )
-    _RGBM_TMP_STATIC( static_gradient_32, STATIC_GRADIENT )
-    _RGBM_TMP_STATIC( static_gradient_33, STATIC_GRADIENT )
-    _RGBM_TMP_STATIC( STATIC_GRADIENT_end, STATIC_GRADIENT )
-  #endif
-  #ifdef RGBLIGHT_EFFECT_RGB_TEST
-    _RGBM_SINGLE_DYNAMIC( RGB_TEST )
-  #endif
-  #ifdef RGBLIGHT_EFFECT_ALTERNATING
-    _RGBM_SINGLE_DYNAMIC( ALTERNATING )
-  #endif
-  ////  Add a new mode here.
-  // #ifdef RGBLIGHT_EFFECT_<name>
-  //    _RGBM_<SINGLE|MULTI>_<STATIC|DYNAMIC>( <name> )
-  // #endif
+_RGBM_SINGLE_STATIC(STATIC_LIGHT)
+#    ifdef RGBLIGHT_EFFECT_BREATHING
+_RGBM_MULTI_DYNAMIC(BREATHING)
+_RGBM_TMP_DYNAMIC(breathing_3, BREATHING)
+_RGBM_TMP_DYNAMIC(breathing_4, BREATHING)
+_RGBM_TMP_DYNAMIC(BREATHING_end, BREATHING)
+#    endif
+#    ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
+_RGBM_MULTI_DYNAMIC(RAINBOW_MOOD)
+_RGBM_TMP_DYNAMIC(rainbow_mood_7, RAINBOW_MOOD)
+_RGBM_TMP_DYNAMIC(RAINBOW_MOOD_end, RAINBOW_MOOD)
+#    endif
+#    ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
+_RGBM_MULTI_DYNAMIC(RAINBOW_SWIRL)
+_RGBM_TMP_DYNAMIC(rainbow_swirl_10, RAINBOW_SWIRL)
+_RGBM_TMP_DYNAMIC(rainbow_swirl_11, RAINBOW_SWIRL)
+_RGBM_TMP_DYNAMIC(rainbow_swirl_12, RAINBOW_SWIRL)
+_RGBM_TMP_DYNAMIC(rainbow_swirl_13, RAINBOW_SWIRL)
+_RGBM_TMP_DYNAMIC(RAINBOW_SWIRL_end, RAINBOW_SWIRL)
+#    endif
+#    ifdef RGBLIGHT_EFFECT_SNAKE
+_RGBM_MULTI_DYNAMIC(SNAKE)
+_RGBM_TMP_DYNAMIC(snake_16, SNAKE)
+_RGBM_TMP_DYNAMIC(snake_17, SNAKE)
+_RGBM_TMP_DYNAMIC(snake_18, SNAKE)
+_RGBM_TMP_DYNAMIC(snake_19, SNAKE)
+_RGBM_TMP_DYNAMIC(SNAKE_end, SNAKE)
+#    endif
+#    ifdef RGBLIGHT_EFFECT_KNIGHT
+_RGBM_MULTI_DYNAMIC(KNIGHT)
+_RGBM_TMP_DYNAMIC(knight_22, KNIGHT)
+_RGBM_TMP_DYNAMIC(KNIGHT_end, KNIGHT)
+#    endif
+#    ifdef RGBLIGHT_EFFECT_CHRISTMAS
+_RGBM_SINGLE_DYNAMIC(CHRISTMAS)
+#    endif
+#    ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
+_RGBM_MULTI_STATIC(STATIC_GRADIENT)
+_RGBM_TMP_STATIC(static_gradient_26, STATIC_GRADIENT)
+_RGBM_TMP_STATIC(static_gradient_27, STATIC_GRADIENT)
+_RGBM_TMP_STATIC(static_gradient_28, STATIC_GRADIENT)
+_RGBM_TMP_STATIC(static_gradient_29, STATIC_GRADIENT)
+_RGBM_TMP_STATIC(static_gradient_30, STATIC_GRADIENT)
+_RGBM_TMP_STATIC(static_gradient_31, STATIC_GRADIENT)
+_RGBM_TMP_STATIC(static_gradient_32, STATIC_GRADIENT)
+_RGBM_TMP_STATIC(static_gradient_33, STATIC_GRADIENT)
+_RGBM_TMP_STATIC(STATIC_GRADIENT_end, STATIC_GRADIENT)
+#    endif
+#    ifdef RGBLIGHT_EFFECT_RGB_TEST
+_RGBM_SINGLE_DYNAMIC(RGB_TEST)
+#    endif
+#    ifdef RGBLIGHT_EFFECT_ALTERNATING
+_RGBM_SINGLE_DYNAMIC(ALTERNATING)
+#    endif
+////  Add a new mode here.
+// #ifdef RGBLIGHT_EFFECT_<name>
+//    _RGBM_<SINGLE|MULTI>_<STATIC|DYNAMIC>( <name> )
+// #endif
 #endif
 
 #undef _RGBM_SINGLE_STATIC
index 048746c4b7dc7d0886031af8e77161aba7001192..3c14cb6109f7d819b704c3ba928e41fb960c2766 100644 (file)
@@ -1,5 +1,5 @@
 #if defined(RGBLED_SPLIT) && !defined(RGBLIGHT_SPLIT)
-  // When RGBLED_SPLIT is defined,
-  // it is considered that RGBLIGHT_SPLIT is defined implicitly.
-  #define RGBLIGHT_SPLIT
+// When RGBLED_SPLIT is defined,
+// it is considered that RGBLIGHT_SPLIT is defined implicitly.
+#    define RGBLIGHT_SPLIT
 #endif
index 11bd4fd11820198c199a8faf6a8cb2e30992fe80..4b9d6c4c2f42da8ad4e289e22251d37ae7a9f899 100644 (file)
@@ -2,35 +2,28 @@
 #define RGBLIGHT_RECONFIG_H
 
 #ifdef RGBLIGHT_ANIMATIONS
-   // for backward compatibility
-   #define RGBLIGHT_EFFECT_BREATHING
-   #define RGBLIGHT_EFFECT_RAINBOW_MOOD
-   #define RGBLIGHT_EFFECT_RAINBOW_SWIRL
-   #define RGBLIGHT_EFFECT_SNAKE
-   #define RGBLIGHT_EFFECT_KNIGHT
-   #define RGBLIGHT_EFFECT_CHRISTMAS
-   #define RGBLIGHT_EFFECT_STATIC_GRADIENT
-   #define RGBLIGHT_EFFECT_RGB_TEST
-   #define RGBLIGHT_EFFECT_ALTERNATING
+// for backward compatibility
+#    define RGBLIGHT_EFFECT_BREATHING
+#    define RGBLIGHT_EFFECT_RAINBOW_MOOD
+#    define RGBLIGHT_EFFECT_RAINBOW_SWIRL
+#    define RGBLIGHT_EFFECT_SNAKE
+#    define RGBLIGHT_EFFECT_KNIGHT
+#    define RGBLIGHT_EFFECT_CHRISTMAS
+#    define RGBLIGHT_EFFECT_STATIC_GRADIENT
+#    define RGBLIGHT_EFFECT_RGB_TEST
+#    define RGBLIGHT_EFFECT_ALTERNATING
 #endif
 
 #ifdef RGBLIGHT_STATIC_PATTERNS
-   #define RGBLIGHT_EFFECT_STATIC_GRADIENT
+#    define RGBLIGHT_EFFECT_STATIC_GRADIENT
 #endif
 
 // check dynamic animation effects chose ?
-#if defined(RGBLIGHT_EFFECT_BREATHING) || \
-    defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || \
-    defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) ||  \
-    defined(RGBLIGHT_EFFECT_SNAKE) ||          \
-    defined(RGBLIGHT_EFFECT_KNIGHT) ||         \
-    defined(RGBLIGHT_EFFECT_CHRISTMAS) ||      \
-    defined(RGBLIGHT_EFFECT_RGB_TEST) ||       \
-    defined(RGBLIGHT_EFFECT_ALTERNATING)
-  #define RGBLIGHT_USE_TIMER
-  #ifndef RGBLIGHT_ANIMATIONS
-    #define RGBLIGHT_ANIMATIONS  // for backward compatibility
-  #endif
+#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT) || defined(RGBLIGHT_EFFECT_CHRISTMAS) || defined(RGBLIGHT_EFFECT_RGB_TEST) || defined(RGBLIGHT_EFFECT_ALTERNATING)
+#    define RGBLIGHT_USE_TIMER
+#    ifndef RGBLIGHT_ANIMATIONS
+#        define RGBLIGHT_ANIMATIONS  // for backward compatibility
+#    endif
 #endif
 
-#endif // RGBLIGHT_RECONFIG_H
+#endif  // RGBLIGHT_RECONFIG_H
index 82195f6e55576c360e365ea1b85cbdb4a9beb836..e71790a1dcfd65a8b8d4463b9db21d698684373d 100644 (file)
 #ifndef SEND_STRING_KEYCODES
 #define SEND_STRING_KEYCODES
 
-#define X_NO                 00
-#define X_ROLL_OVER          01
-#define X_POST_FAIL          02
-#define X_UNDEFINED          03
-#define X_A                  04
-#define X_B                  05
-#define X_C                  06
-#define X_D                  07
-#define X_E                  08
-#define X_F                  09
-#define X_G                  0a
-#define X_H                  0b
-#define X_I                  0c
-#define X_J                  0d
-#define X_K                  0e
-#define X_L                  0f
-#define X_M                  10
-#define X_N                  11
-#define X_O                  12
-#define X_P                  13
-#define X_Q                  14
-#define X_R                  15
-#define X_S                  16
-#define X_T                  17
-#define X_U                  18
-#define X_V                  19
-#define X_W                  1a
-#define X_X                  1b
-#define X_Y                  1c
-#define X_Z                  1d
-#define X_1                  1e
-#define X_2                  1f
-#define X_3                  20
-#define X_4                  21
-#define X_5                  22
-#define X_6                  23
-#define X_7                  24
-#define X_8                  25
-#define X_9                  26
-#define X_0                  27
-#define X_ENTER              28
-#define X_ESCAPE             29
-#define X_BSPACE             2a
-#define X_TAB                2b
-#define X_SPACE              2c
-#define X_MINUS              2d
-#define X_EQUAL              2e
-#define X_LBRACKET           2f
-#define X_RBRACKET           30
-#define X_BSLASH             31
-#define X_NONUS_HASH         32
-#define X_SCOLON             33
-#define X_QUOTE              34
-#define X_GRAVE              35
-#define X_COMMA              36
-#define X_DOT                37
-#define X_SLASH              38
-#define X_CAPSLOCK           39
-#define X_F1                 3a
-#define X_F2                 3b
-#define X_F3                 3c
-#define X_F4                 3d
-#define X_F5                 3e
-#define X_F6                 3f
-#define X_F7                 40
-#define X_F8                 41
-#define X_F9                 42
-#define X_F10                43
-#define X_F11                44
-#define X_F12                45
-#define X_PSCREEN            46
-#define X_SCROLLLOCK         47
-#define X_PAUSE              48
-#define X_INSERT             49
-#define X_HOME               4a
-#define X_PGUP               4b
-#define X_DELETE             4c
-#define X_END                4d
-#define X_PGDOWN             4e
-#define X_RIGHT              4f
-#define X_LEFT               50
-#define X_DOWN               51
-#define X_UP                 52
-#define X_NUMLOCK            53
-#define X_KP_SLASH           54
-#define X_KP_ASTERISK        55
-#define X_KP_MINUS           56
-#define X_KP_PLUS            57
-#define X_KP_ENTER           58
-#define X_KP_1               59
-#define X_KP_2               5a
-#define X_KP_3               5b
-#define X_KP_4               5c
-#define X_KP_5               5d
-#define X_KP_6               5e
-#define X_KP_7               5f
-#define X_KP_8               60
-#define X_KP_9               61
-#define X_KP_0               62
-#define X_KP_DOT             63
-#define X_NONUS_BSLASH       64
-#define X_APPLICATION        65
-#define X_POWER              66
-#define X_KP_EQUAL           67
-#define X_F13                68
-#define X_F14                69
-#define X_F15                6a
-#define X_F16                6b
-#define X_F17                6c
-#define X_F18                6d
-#define X_F19                6e
-#define X_F20                6f
-#define X_F21                70
-#define X_F22                71
-#define X_F23                72
-#define X_F24                73
-#define X_EXECUTE            74
-#define X_HELP               75
-#define X_MENU               76
-#define X_SELECT             77
-#define X_STOP               78
-#define X_AGAIN              79
-#define X_UNDO               7a
-#define X_CUT                7b
-#define X_COPY               7c
-#define X_PASTE              7d
-#define X_FIND               7e
-#define X__MUTE              7f
-#define X__VOLUP             80
-#define X__VOLDOWN           81
-#define X_LOCKING_CAPS       82
-#define X_LOCKING_NUM        83
-#define X_LOCKING_SCROLL     84
-#define X_KP_COMMA           85
-#define X_KP_EQUAL_AS400     86
-#define X_INT1               87
-#define X_INT2               88
-#define X_INT3               89
-#define X_INT4               8a
-#define X_INT5               8b
-#define X_INT6               8c
-#define X_INT7               8d
-#define X_INT8               8e
-#define X_INT9               8f
-#define X_LANG1              90
-#define X_LANG2              91
-#define X_LANG3              92
-#define X_LANG4              93
-#define X_LANG5              94
-#define X_LANG6              95
-#define X_LANG7              96
-#define X_LANG8              97
-#define X_LANG9              98
-#define X_ALT_ERASE          99
-#define X_SYSREQ             9a
-#define X_CANCEL             9b
-#define X_CLEAR              9c
-#define X_PRIOR              9d
-#define X_RETURN             9e
-#define X_SEPARATOR          9f
-#define X_OUT                a0
-#define X_OPER               a1
-#define X_CLEAR_AGAIN        a2
-#define X_CRSEL              a3
-#define X_EXSEL              a4
+#define X_NO 00
+#define X_ROLL_OVER 01
+#define X_POST_FAIL 02
+#define X_UNDEFINED 03
+#define X_A 04
+#define X_B 05
+#define X_C 06
+#define X_D 07
+#define X_E 08
+#define X_F 09
+#define X_G 0a
+#define X_H 0b
+#define X_I 0c
+#define X_J 0d
+#define X_K 0e
+#define X_L 0f
+#define X_M 10
+#define X_N 11
+#define X_O 12
+#define X_P 13
+#define X_Q 14
+#define X_R 15
+#define X_S 16
+#define X_T 17
+#define X_U 18
+#define X_V 19
+#define X_W 1a
+#define X_X 1b
+#define X_Y 1c
+#define X_Z 1d
+#define X_1 1e
+#define X_2 1f
+#define X_3 20
+#define X_4 21
+#define X_5 22
+#define X_6 23
+#define X_7 24
+#define X_8 25
+#define X_9 26
+#define X_0 27
+#define X_ENTER 28
+#define X_ESCAPE 29
+#define X_BSPACE 2a
+#define X_TAB 2b
+#define X_SPACE 2c
+#define X_MINUS 2d
+#define X_EQUAL 2e
+#define X_LBRACKET 2f
+#define X_RBRACKET 30
+#define X_BSLASH 31
+#define X_NONUS_HASH 32
+#define X_SCOLON 33
+#define X_QUOTE 34
+#define X_GRAVE 35
+#define X_COMMA 36
+#define X_DOT 37
+#define X_SLASH 38
+#define X_CAPSLOCK 39
+#define X_F1 3a
+#define X_F2 3b
+#define X_F3 3c
+#define X_F4 3d
+#define X_F5 3e
+#define X_F6 3f
+#define X_F7 40
+#define X_F8 41
+#define X_F9 42
+#define X_F10 43
+#define X_F11 44
+#define X_F12 45
+#define X_PSCREEN 46
+#define X_SCROLLLOCK 47
+#define X_PAUSE 48
+#define X_INSERT 49
+#define X_HOME 4a
+#define X_PGUP 4b
+#define X_DELETE 4c
+#define X_END 4d
+#define X_PGDOWN 4e
+#define X_RIGHT 4f
+#define X_LEFT 50
+#define X_DOWN 51
+#define X_UP 52
+#define X_NUMLOCK 53
+#define X_KP_SLASH 54
+#define X_KP_ASTERISK 55
+#define X_KP_MINUS 56
+#define X_KP_PLUS 57
+#define X_KP_ENTER 58
+#define X_KP_1 59
+#define X_KP_2 5a
+#define X_KP_3 5b
+#define X_KP_4 5c
+#define X_KP_5 5d
+#define X_KP_6 5e
+#define X_KP_7 5f
+#define X_KP_8 60
+#define X_KP_9 61
+#define X_KP_0 62
+#define X_KP_DOT 63
+#define X_NONUS_BSLASH 64
+#define X_APPLICATION 65
+#define X_POWER 66
+#define X_KP_EQUAL 67
+#define X_F13 68
+#define X_F14 69
+#define X_F15 6a
+#define X_F16 6b
+#define X_F17 6c
+#define X_F18 6d
+#define X_F19 6e
+#define X_F20 6f
+#define X_F21 70
+#define X_F22 71
+#define X_F23 72
+#define X_F24 73
+#define X_EXECUTE 74
+#define X_HELP 75
+#define X_MENU 76
+#define X_SELECT 77
+#define X_STOP 78
+#define X_AGAIN 79
+#define X_UNDO 7a
+#define X_CUT 7b
+#define X_COPY 7c
+#define X_PASTE 7d
+#define X_FIND 7e
+#define X__MUTE 7f
+#define X__VOLUP 80
+#define X__VOLDOWN 81
+#define X_LOCKING_CAPS 82
+#define X_LOCKING_NUM 83
+#define X_LOCKING_SCROLL 84
+#define X_KP_COMMA 85
+#define X_KP_EQUAL_AS400 86
+#define X_INT1 87
+#define X_INT2 88
+#define X_INT3 89
+#define X_INT4 8a
+#define X_INT5 8b
+#define X_INT6 8c
+#define X_INT7 8d
+#define X_INT8 8e
+#define X_INT9 8f
+#define X_LANG1 90
+#define X_LANG2 91
+#define X_LANG3 92
+#define X_LANG4 93
+#define X_LANG5 94
+#define X_LANG6 95
+#define X_LANG7 96
+#define X_LANG8 97
+#define X_LANG9 98
+#define X_ALT_ERASE 99
+#define X_SYSREQ 9a
+#define X_CANCEL 9b
+#define X_CLEAR 9c
+#define X_PRIOR 9d
+#define X_RETURN 9e
+#define X_SEPARATOR 9f
+#define X_OUT a0
+#define X_OPER a1
+#define X_CLEAR_AGAIN a2
+#define X_CRSEL a3
+#define X_EXSEL a4
 
 /* Modifiers */
-#define X_LCTRL              e0
-#define X_LSHIFT             e1
-#define X_LALT               e2
-#define X_LGUI               e3
-#define X_RCTRL              e4
-#define X_RSHIFT             e5
-#define X_RALT               e6
-#define X_RGUI               e7
+#define X_LCTRL e0
+#define X_LSHIFT e1
+#define X_LALT e2
+#define X_LGUI e3
+#define X_RCTRL e4
+#define X_RSHIFT e5
+#define X_RALT e6
+#define X_RGUI e7
 
 /* System Control */
-#define X_SYSTEM_POWER       a5
-#define X_SYSTEM_SLEEP       a6
-#define X_SYSTEM_WAKE        a7
+#define X_SYSTEM_POWER a5
+#define X_SYSTEM_SLEEP a6
+#define X_SYSTEM_WAKE a7
 
 /* Media Control */
-#define X_AUDIO_MUTE         a8
-#define X_AUDIO_VOL_UP       a9
-#define X_AUDIO_VOL_DOWN     aa
-#define X_MEDIA_NEXT_TRACK   ab
-#define X_MEDIA_PREV_TRACK   ac
-#define X_MEDIA_STOP         ad
-#define X_MEDIA_PLAY_PAUSE   ae
-#define X_MEDIA_SELECT       af
-#define X_MEDIA_EJECT        b0
-#define X_MAIL               b1
-#define X_CALCULATOR         b2
-#define X_MY_COMPUTER        b3
-#define X_WWW_SEARCH         b4
-#define X_WWW_HOME           b5
-#define X_WWW_BACK           b6
-#define X_WWW_FORWARD        b7
-#define X_WWW_STOP           b8
-#define X_WWW_REFRESH        b9
-#define X_WWW_FAVORITES      ba
+#define X_AUDIO_MUTE a8
+#define X_AUDIO_VOL_UP a9
+#define X_AUDIO_VOL_DOWN aa
+#define X_MEDIA_NEXT_TRACK ab
+#define X_MEDIA_PREV_TRACK ac
+#define X_MEDIA_STOP ad
+#define X_MEDIA_PLAY_PAUSE ae
+#define X_MEDIA_SELECT af
+#define X_MEDIA_EJECT b0
+#define X_MAIL b1
+#define X_CALCULATOR b2
+#define X_MY_COMPUTER b3
+#define X_WWW_SEARCH b4
+#define X_WWW_HOME b5
+#define X_WWW_BACK b6
+#define X_WWW_FORWARD b7
+#define X_WWW_STOP b8
+#define X_WWW_REFRESH b9
+#define X_WWW_FAVORITES ba
 #define X_MEDIA_FAST_FORWARD bb
-#define X_MEDIA_REWIND       bc
+#define X_MEDIA_REWIND bc
 #endif
index 2c87d64c29c14b395e600ec528ccbdf1891c8d7f..d3a91d8286d9ec645163765aeac0e2c523faec55 100644 (file)
@@ -34,21 +34,21 @@ SOFTWARE.
 typedef struct byte_stuffer_state {
     uint16_t next_zero;
     uint16_t data_pos;
-    bool long_frame;
-    uint8_t data[MAX_FRAME_SIZE];
-}byte_stuffer_state_t;
+    bool     long_frame;
+    uint8_t  data[MAX_FRAME_SIZE];
+} byte_stuffer_state_t;
 
 static byte_stuffer_state_t states[NUM_LINKS];
 
 void init_byte_stuffer_state(byte_stuffer_state_t* state) {
-    state->next_zero = 0;
-    state->data_pos = 0;
+    state->next_zero  = 0;
+    state->data_pos   = 0;
     state->long_frame = false;
 }
 
 void init_byte_stuffer(void) {
     int i;
-    for (i=0;i<NUM_LINKS;i++) {
+    for (i = 0; i < NUM_LINKS; i++) {
         init_byte_stuffer_state(&states[i]);
     }
 }
@@ -57,9 +57,9 @@ void byte_stuffer_recv_byte(uint8_t link, uint8_t data) {
     byte_stuffer_state_t* state = &states[link];
     // Start of a new frame
     if (state->next_zero == 0) {
-        state->next_zero = data;
+        state->next_zero  = data;
         state->long_frame = data == 0xFF;
-        state->data_pos = 0;
+        state->data_pos   = 0;
         return;
     }
 
@@ -70,33 +70,28 @@ void byte_stuffer_recv_byte(uint8_t link, uint8_t data) {
             if (state->data_pos > 0) {
                 validator_recv_frame(link, state->data, state->data_pos);
             }
-        }
-        else {
+        } else {
             // The frame is invalid, so reset
             init_byte_stuffer_state(state);
         }
-    }
-    else {
+    } else {
         if (state->data_pos == MAX_FRAME_SIZE) {
             // We exceeded our maximum frame size
             // therefore there's nothing else to do than reset to a new frame
-            state->next_zero = data;
+            state->next_zero  = data;
             state->long_frame = data == 0xFF;
-            state->data_pos = 0;
-        }
-        else if (state->next_zero == 0) {
+            state->data_pos   = 0;
+        } else if (state->next_zero == 0) {
             if (state->long_frame) {
                 // This is part of a long frame, so continue
-                state->next_zero = data;
+                state->next_zero  = data;
                 state->long_frame = data == 0xFF;
-            }
-            else {
+            } else {
                 // Special case for zeroes
-                state->next_zero = data;
+                state->next_zero               = data;
                 state->data[state->data_pos++] = 0;
             }
-        }
-        else {
+        } else {
             state->data[state->data_pos++] = data;
         }
     }
@@ -105,7 +100,7 @@ void byte_stuffer_recv_byte(uint8_t link, uint8_t data) {
 static void send_block(uint8_t link, uint8_t* start, uint8_t* end, uint8_t num_non_zero) {
     send_data(link, &num_non_zero, 1);
     if (end > start) {
-        send_data(link, start, end-start);
+        send_data(link, start, end - start);
     }
 }
 
@@ -113,24 +108,22 @@ void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size) {
     const uint8_t zero = 0;
     if (size > 0) {
         uint16_t num_non_zero = 1;
-        uint8_t* end = data + size;
-        uint8_t* start = data;
+        uint8_t* end          = data + size;
+        uint8_t* start        = data;
         while (data < end) {
             if (num_non_zero == 0xFF) {
                 // There's more data after big non-zero block
                 // So send it, and start a new block
                 send_block(link, start, data, num_non_zero);
-                start = data;
+                start        = data;
                 num_non_zero = 1;
-            }
-            else {
+            } else {
                 if (*data == 0) {
                     // A zero encountered, so send the block
                     send_block(link, start, data, num_non_zero);
-                    start = data + 1;
+                    start        = data + 1;
                     num_non_zero = 1;
-                }
-                else {
+                } else {
                     num_non_zero++;
                 }
                 ++data;
index 04b8c2e75ca60a15fc29080ffd8505cb0a1e91d0..5292673700c61e80783c240f039f2c953cf8c89e 100644 (file)
@@ -28,26 +28,22 @@ SOFTWARE.
 
 static bool is_master;
 
-void router_set_master(bool master) {
-   is_master = master;
-}
+void router_set_master(bool master) { is_master = master; }
 
-void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size){
+void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size) {
     if (is_master) {
         if (link == DOWN_LINK) {
-            transport_recv_frame(data[size-1], data, size - 1);
+            transport_recv_frame(data[size - 1], data, size - 1);
         }
-    }
-    else {
+    } else {
         if (link == UP_LINK) {
-            if (data[size-1] & 1) {
+            if (data[size - 1] & 1) {
                 transport_recv_frame(0, data, size - 1);
             }
-            data[size-1] >>= 1;
+            data[size - 1] >>= 1;
             validator_send_frame(DOWN_LINK, data, size);
-        }
-        else {
-            data[size-1]++;
+        } else {
+            data[size - 1]++;
             validator_send_frame(UP_LINK, data, size);
         }
     }
@@ -59,8 +55,7 @@ void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
             data[size] = 1;
             validator_send_frame(UP_LINK, data, size + 1);
         }
-    }
-    else {
+    } else {
         if (is_master) {
             data[size] = destination;
             validator_send_frame(DOWN_LINK, data, size + 1);
index 474f80ee8ecd60243bee4c9ed6cb08057dcf100f..bc9136f70befc2eb570536655ce65d0f4d7aafef 100644 (file)
@@ -27,78 +27,14 @@ SOFTWARE.
 #include "serial_link/protocol/byte_stuffer.h"
 #include <string.h>
 
-const uint32_t poly8_lookup[256] =
-{
- 0, 0x77073096, 0xEE0E612C, 0x990951BA,
- 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
- 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
- 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
- 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
- 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
- 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
- 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
- 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
- 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
- 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
- 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
- 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
- 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
- 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
- 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
- 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
- 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
- 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
- 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
- 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
- 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
- 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
- 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
- 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
- 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
- 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
- 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
- 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
- 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
- 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
- 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
- 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
- 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
- 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
- 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
- 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
- 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
- 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
- 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
- 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
- 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
- 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
- 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
- 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
- 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
- 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
- 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
- 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
- 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
- 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
- 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
- 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
- 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
- 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
- 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
- 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
- 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
- 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
- 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
- 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
- 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
- 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
- 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
-};
+const uint32_t poly8_lookup[256] = {0,          0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
+                                    0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
+                                    0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
+                                    0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D};
 
-static uint32_t crc32_byte(uint8_t *p, uint32_t bytelength)
-{
+static uint32_t crc32_byte(uint8_t* p, uint32_t bytelength) {
     uint32_t crc = 0xffffffff;
-    while (bytelength-- !=0) crc = poly8_lookup[((uint8_t) crc ^ *(p++))] ^ (crc >> 8);
+    while (bytelength-- != 0) crc = poly8_lookup[((uint8_t)crc ^ *(p++))] ^ (crc >> 8);
     // return (~crc); also works
     return (crc ^ 0xffffffff);
 }
@@ -106,10 +42,10 @@ static uint32_t crc32_byte(uint8_t *p, uint32_t bytelength)
 void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size) {
     if (size > 4) {
         uint32_t frame_crc;
-        memcpy(&frame_crc, data + size -4, 4);
+        memcpy(&frame_crc, data + size - 4, 4);
         uint32_t expected_crc = crc32_byte(data, size - 4);
         if (frame_crc == expected_crc) {
-            route_incoming_frame(link, data, size-4);
+            route_incoming_frame(link, data, size - 4);
         }
     }
 }
index ff795fe20176df00e21b94d8bbe2b3f398d5f623..73b8dc62e9e60fb91c1515e0643ac171dafd8894 100644 (file)
@@ -29,42 +29,38 @@ SOFTWARE.
 
 #define MAX_REMOTE_OBJECTS 16
 static remote_object_t* remote_objects[MAX_REMOTE_OBJECTS];
-static uint32_t num_remote_objects = 0;
+static uint32_t         num_remote_objects = 0;
 
-void reinitialize_serial_link_transport(void) {
-    num_remote_objects = 0;
-}
+void reinitialize_serial_link_transport(void) { num_remote_objects = 0; }
 
 void add_remote_objects(remote_object_t** _remote_objects, uint32_t _num_remote_objects) {
     unsigned int i;
-    for(i=0;i<_num_remote_objects;i++) {
-        remote_object_t* obj = _remote_objects[i];
+    for (i = 0; i < _num_remote_objects; i++) {
+        remote_object_t* obj                 = _remote_objects[i];
         remote_objects[num_remote_objects++] = obj;
         if (obj->object_type == MASTER_TO_ALL_SLAVES) {
             triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer;
             triple_buffer_init(tb);
             uint8_t* start = obj->buffer + LOCAL_OBJECT_SIZE(obj->object_size);
-            tb = (triple_buffer_object_t*)start;
+            tb             = (triple_buffer_object_t*)start;
             triple_buffer_init(tb);
-        }
-        else if(obj->object_type == MASTER_TO_SINGLE_SLAVE) {
-            uint8_t* start = obj->buffer;
+        } else if (obj->object_type == MASTER_TO_SINGLE_SLAVE) {
+            uint8_t*     start = obj->buffer;
             unsigned int j;
-            for (j=0;j<NUM_SLAVES;j++) {
+            for (j = 0; j < NUM_SLAVES; j++) {
                 triple_buffer_object_t* tb = (triple_buffer_object_t*)start;
                 triple_buffer_init(tb);
                 start += LOCAL_OBJECT_SIZE(obj->object_size);
             }
             triple_buffer_object_t* tb = (triple_buffer_object_t*)start;
             triple_buffer_init(tb);
-        }
-        else {
-            uint8_t* start = obj->buffer;
-            triple_buffer_object_t* tb = (triple_buffer_object_t*)start;
+        } else {
+            uint8_t*                start = obj->buffer;
+            triple_buffer_object_t* tb    = (triple_buffer_object_t*)start;
             triple_buffer_init(tb);
             start += LOCAL_OBJECT_SIZE(obj->object_size);
             unsigned int j;
-            for (j=0;j<NUM_SLAVES;j++) {
+            for (j = 0; j < NUM_SLAVES; j++) {
                 tb = (triple_buffer_object_t*)start;
                 triple_buffer_init(tb);
                 start += REMOTE_OBJECT_SIZE(obj->object_size);
@@ -74,23 +70,21 @@ void add_remote_objects(remote_object_t** _remote_objects, uint32_t _num_remote_
 }
 
 void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) {
-    uint8_t id = data[size-1];
+    uint8_t id = data[size - 1];
     if (id < num_remote_objects) {
         remote_object_t* obj = remote_objects[id];
         if (obj->object_size == size - 1) {
             uint8_t* start;
             if (obj->object_type == MASTER_TO_ALL_SLAVES) {
                 start = obj->buffer + LOCAL_OBJECT_SIZE(obj->object_size);
-            }
-            else if(obj->object_type == SLAVE_TO_MASTER) {
+            } else if (obj->object_type == SLAVE_TO_MASTER) {
                 start = obj->buffer + LOCAL_OBJECT_SIZE(obj->object_size);
                 start += (from - 1) * REMOTE_OBJECT_SIZE(obj->object_size);
-            }
-            else {
+            } else {
                 start = obj->buffer + NUM_SLAVES * LOCAL_OBJECT_SIZE(obj->object_size);
             }
-            triple_buffer_object_t* tb = (triple_buffer_object_t*)start;
-            void* ptr = triple_buffer_begin_write_internal(obj->object_size, tb);
+            triple_buffer_object_t* tb  = (triple_buffer_object_t*)start;
+            void*                   ptr = triple_buffer_begin_write_internal(obj->object_size, tb);
             memcpy(ptr, data, size - 1);
             triple_buffer_end_write_internal(tb);
         }
@@ -99,26 +93,25 @@ void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) {
 
 void update_transport(void) {
     unsigned int i;
-    for(i=0;i<num_remote_objects;i++) {
+    for (i = 0; i < num_remote_objects; i++) {
         remote_object_t* obj = remote_objects[i];
         if (obj->object_type == MASTER_TO_ALL_SLAVES || obj->object_type == SLAVE_TO_MASTER) {
-            triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer;
-            uint8_t* ptr = (uint8_t*)triple_buffer_read_internal(obj->object_size + LOCAL_OBJECT_EXTRA, tb);
+            triple_buffer_object_t* tb  = (triple_buffer_object_t*)obj->buffer;
+            uint8_t*                ptr = (uint8_t*)triple_buffer_read_internal(obj->object_size + LOCAL_OBJECT_EXTRA, tb);
             if (ptr) {
                 ptr[obj->object_size] = i;
-                uint8_t dest = obj->object_type == MASTER_TO_ALL_SLAVES ? 0xFF : 0;
+                uint8_t dest          = obj->object_type == MASTER_TO_ALL_SLAVES ? 0xFF : 0;
                 router_send_frame(dest, ptr, obj->object_size + 1);
             }
-        }
-        else {
-            uint8_t* start = obj->buffer;
+        } else {
+            uint8_t*     start = obj->buffer;
             unsigned int j;
-            for (j=0;j<NUM_SLAVES;j++) {
-                triple_buffer_object_t* tb = (triple_buffer_object_t*)start;
-                uint8_t* ptr = (uint8_t*)triple_buffer_read_internal(obj->object_size + LOCAL_OBJECT_EXTRA, tb);
+            for (j = 0; j < NUM_SLAVES; j++) {
+                triple_buffer_object_t* tb  = (triple_buffer_object_t*)start;
+                uint8_t*                ptr = (uint8_t*)triple_buffer_read_internal(obj->object_size + LOCAL_OBJECT_EXTRA, tb);
                 if (ptr) {
                     ptr[obj->object_size] = i;
-                    uint8_t dest = j + 1;
+                    uint8_t dest          = j + 1;
                     router_send_frame(dest, ptr, obj->object_size + 1);
                 }
                 start += LOCAL_OBJECT_SIZE(obj->object_size);
index 2c5d890b219aa02bd15845922c57d82e604fa53f..309a56b000a2d4fb19dac58fa2f70c04e1f6190d 100644 (file)
@@ -42,104 +42,94 @@ typedef enum {
 
 typedef struct {
     remote_object_type object_type;
-    uint16_t object_size;
-    uint8_t buffer[] __attribute__((aligned(4)));
+    uint16_t           object_size;
+    uint8_t            buffer[] __attribute__((aligned(4)));
 } remote_object_t;
 
-#define REMOTE_OBJECT_SIZE(objectsize) \
-    (sizeof(triple_buffer_object_t) + objectsize * 3)
-#define LOCAL_OBJECT_SIZE(objectsize) \
-    (sizeof(triple_buffer_object_t) + (objectsize + LOCAL_OBJECT_EXTRA) * 3)
-
-#define REMOTE_OBJECT_HELPER(name, type, num_local, num_remote) \
-typedef struct { \
-    remote_object_t object; \
-    uint8_t buffer[ \
-        num_remote * REMOTE_OBJECT_SIZE(sizeof(type)) + \
-        num_local * LOCAL_OBJECT_SIZE(sizeof(type))]; \
-} remote_object_##name##_t;
-
-#define MASTER_TO_ALL_SLAVES_OBJECT(name, type) \
-    REMOTE_OBJECT_HELPER(name, type, 1, 1) \
-    remote_object_##name##_t remote_object_##name = { \
-        .object = { \
-            .object_type = MASTER_TO_ALL_SLAVES, \
-            .object_size = sizeof(type), \
-        } \
-    }; \
-    type* begin_write_##name(void) { \
-        remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
-        triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer; \
+#define REMOTE_OBJECT_SIZE(objectsize) (sizeof(triple_buffer_object_t) + objectsize * 3)
+#define LOCAL_OBJECT_SIZE(objectsize) (sizeof(triple_buffer_object_t) + (objectsize + LOCAL_OBJECT_EXTRA) * 3)
+
+#define REMOTE_OBJECT_HELPER(name, type, num_local, num_remote)                                                              \
+    typedef struct {                                                                                                         \
+        remote_object_t object;                                                                                              \
+        uint8_t         buffer[num_remote * REMOTE_OBJECT_SIZE(sizeof(type)) + num_local * LOCAL_OBJECT_SIZE(sizeof(type))]; \
+    } remote_object_##name##_t;
+
+#define MASTER_TO_ALL_SLAVES_OBJECT(name, type)                                                                     \
+    REMOTE_OBJECT_HELPER(name, type, 1, 1)                                                                          \
+    remote_object_##name##_t remote_object_##name = {.object = {                                                    \
+                                                         .object_type = MASTER_TO_ALL_SLAVES,                       \
+                                                         .object_size = sizeof(type),                               \
+                                                     }};                                                            \
+    type*                    begin_write_##name(void) {                                                             \
+        remote_object_t*        obj = (remote_object_t*)&remote_object_##name;                   \
+        triple_buffer_object_t* tb  = (triple_buffer_object_t*)obj->buffer;                      \
         return (type*)triple_buffer_begin_write_internal(sizeof(type) + LOCAL_OBJECT_EXTRA, tb); \
-    }\
-    void end_write_##name(void) { \
-        remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
-        triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer; \
-        triple_buffer_end_write_internal(tb); \
-        signal_data_written(); \
-    }\
-    type* read_##name(void) { \
-        remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
-        uint8_t* start = obj->buffer + LOCAL_OBJECT_SIZE(obj->object_size);\
-        triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \
-        return (type*)triple_buffer_read_internal(obj->object_size, tb); \
+    }                                                                                                               \
+    void end_write_##name(void) {                                                                                   \
+        remote_object_t*        obj = (remote_object_t*)&remote_object_##name;                                      \
+        triple_buffer_object_t* tb  = (triple_buffer_object_t*)obj->buffer;                                         \
+        triple_buffer_end_write_internal(tb);                                                                       \
+        signal_data_written();                                                                                      \
+    }                                                                                                               \
+    type* read_##name(void) {                                                                                       \
+        remote_object_t*        obj   = (remote_object_t*)&remote_object_##name;                                    \
+        uint8_t*                start = obj->buffer + LOCAL_OBJECT_SIZE(obj->object_size);                          \
+        triple_buffer_object_t* tb    = (triple_buffer_object_t*)start;                                             \
+        return (type*)triple_buffer_read_internal(obj->object_size, tb);                                            \
     }
 
-#define MASTER_TO_SINGLE_SLAVE_OBJECT(name, type) \
-    REMOTE_OBJECT_HELPER(name, type, NUM_SLAVES, 1) \
-    remote_object_##name##_t remote_object_##name = { \
-        .object = { \
-            .object_type = MASTER_TO_SINGLE_SLAVE, \
-            .object_size = sizeof(type), \
-        } \
-    }; \
-    type* begin_write_##name(uint8_t slave) { \
-        remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
-        uint8_t* start = obj->buffer;\
-        start += slave * LOCAL_OBJECT_SIZE(obj->object_size); \
-        triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \
+#define MASTER_TO_SINGLE_SLAVE_OBJECT(name, type)                                                                   \
+    REMOTE_OBJECT_HELPER(name, type, NUM_SLAVES, 1)                                                                 \
+    remote_object_##name##_t remote_object_##name = {.object = {                                                    \
+                                                         .object_type = MASTER_TO_SINGLE_SLAVE,                     \
+                                                         .object_size = sizeof(type),                               \
+                                                     }};                                                            \
+    type*                    begin_write_##name(uint8_t slave) {                                                    \
+        remote_object_t* obj   = (remote_object_t*)&remote_object_##name;                        \
+        uint8_t*         start = obj->buffer;                                                    \
+        start += slave * LOCAL_OBJECT_SIZE(obj->object_size);                                    \
+        triple_buffer_object_t* tb = (triple_buffer_object_t*)start;                             \
         return (type*)triple_buffer_begin_write_internal(sizeof(type) + LOCAL_OBJECT_EXTRA, tb); \
-    }\
-    void end_write_##name(uint8_t slave) { \
-        remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
-        uint8_t* start = obj->buffer;\
-        start += slave * LOCAL_OBJECT_SIZE(obj->object_size); \
-        triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \
-        triple_buffer_end_write_internal(tb); \
-        signal_data_written(); \
-    }\
-    type* read_##name() { \
-        remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
-        uint8_t* start = obj->buffer + NUM_SLAVES * LOCAL_OBJECT_SIZE(obj->object_size);\
-        triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \
-        return (type*)triple_buffer_read_internal(obj->object_size, tb); \
+    }                                                                                                               \
+    void end_write_##name(uint8_t slave) {                                                                          \
+        remote_object_t* obj   = (remote_object_t*)&remote_object_##name;                                           \
+        uint8_t*         start = obj->buffer;                                                                       \
+        start += slave * LOCAL_OBJECT_SIZE(obj->object_size);                                                       \
+        triple_buffer_object_t* tb = (triple_buffer_object_t*)start;                                                \
+        triple_buffer_end_write_internal(tb);                                                                       \
+        signal_data_written();                                                                                      \
+    }                                                                                                               \
+    type* read_##name() {                                                                                           \
+        remote_object_t*        obj   = (remote_object_t*)&remote_object_##name;                                    \
+        uint8_t*                start = obj->buffer + NUM_SLAVES * LOCAL_OBJECT_SIZE(obj->object_size);             \
+        triple_buffer_object_t* tb    = (triple_buffer_object_t*)start;                                             \
+        return (type*)triple_buffer_read_internal(obj->object_size, tb);                                            \
     }
 
-#define SLAVE_TO_MASTER_OBJECT(name, type) \
-    REMOTE_OBJECT_HELPER(name, type, 1, NUM_SLAVES) \
-    remote_object_##name##_t remote_object_##name = { \
-        .object = { \
-            .object_type = SLAVE_TO_MASTER, \
-            .object_size = sizeof(type), \
-        } \
-    }; \
-    type* begin_write_##name(void) { \
-        remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
-        triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer; \
+#define SLAVE_TO_MASTER_OBJECT(name, type)                                                                          \
+    REMOTE_OBJECT_HELPER(name, type, 1, NUM_SLAVES)                                                                 \
+    remote_object_##name##_t remote_object_##name = {.object = {                                                    \
+                                                         .object_type = SLAVE_TO_MASTER,                            \
+                                                         .object_size = sizeof(type),                               \
+                                                     }};                                                            \
+    type*                    begin_write_##name(void) {                                                             \
+        remote_object_t*        obj = (remote_object_t*)&remote_object_##name;                   \
+        triple_buffer_object_t* tb  = (triple_buffer_object_t*)obj->buffer;                      \
         return (type*)triple_buffer_begin_write_internal(sizeof(type) + LOCAL_OBJECT_EXTRA, tb); \
-    }\
-    void end_write_##name(void) { \
-        remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
-        triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer; \
-        triple_buffer_end_write_internal(tb); \
-        signal_data_written(); \
-    }\
-    type* read_##name(uint8_t slave) { \
-        remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
-        uint8_t* start = obj->buffer + LOCAL_OBJECT_SIZE(obj->object_size);\
-        start+=slave * REMOTE_OBJECT_SIZE(obj->object_size); \
-        triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \
-        return (type*)triple_buffer_read_internal(obj->object_size, tb); \
+    }                                                                                                               \
+    void end_write_##name(void) {                                                                                   \
+        remote_object_t*        obj = (remote_object_t*)&remote_object_##name;                                      \
+        triple_buffer_object_t* tb  = (triple_buffer_object_t*)obj->buffer;                                         \
+        triple_buffer_end_write_internal(tb);                                                                       \
+        signal_data_written();                                                                                      \
+    }                                                                                                               \
+    type* read_##name(uint8_t slave) {                                                                              \
+        remote_object_t* obj   = (remote_object_t*)&remote_object_##name;                                           \
+        uint8_t*         start = obj->buffer + LOCAL_OBJECT_SIZE(obj->object_size);                                 \
+        start += slave * REMOTE_OBJECT_SIZE(obj->object_size);                                                      \
+        triple_buffer_object_t* tb = (triple_buffer_object_t*)start;                                                \
+        return (type*)triple_buffer_read_internal(obj->object_size, tb);                                            \
     }
 
 #define REMOTE_OBJECT(name) (remote_object_t*)&remote_object_##name
index e3e8989d30b4a4e699304ea9ef3af6e5b667b44a..e0c6d702a54c66125560adc608a0d447efd32378 100644 (file)
@@ -49,14 +49,13 @@ void* triple_buffer_read_internal(uint16_t object_size, triple_buffer_object_t*
     serial_link_lock();
     if (GET_DATA_AVAILABLE()) {
         uint8_t shared_index = GET_SHARED_INDEX();
-        uint8_t read_index = GET_READ_INDEX();
+        uint8_t read_index   = GET_READ_INDEX();
         SET_READ_INDEX(shared_index);
         SET_SHARED_INDEX(read_index);
         SET_DATA_AVAILABLE(false);
         serial_link_unlock();
         return object->buffer + object_size * shared_index;
-    }
-    else {
+    } else {
         serial_link_unlock();
         return NULL;
     }
@@ -70,7 +69,7 @@ void* triple_buffer_begin_write_internal(uint16_t object_size, triple_buffer_obj
 void triple_buffer_end_write_internal(triple_buffer_object_t* object) {
     serial_link_lock();
     uint8_t shared_index = GET_SHARED_INDEX();
-    uint8_t write_index = GET_WRITE_INDEX();
+    uint8_t write_index  = GET_WRITE_INDEX();
     SET_SHARED_INDEX(write_index);
     SET_WRITE_INDEX(shared_index);
     SET_DATA_AVAILABLE(true);
index 2e57db3f50f58c678ff94f0363851a8bc3ef6081..6ec98d52bf40ef85d5b5c8c12fa660f59d80eb3d 100644 (file)
@@ -30,22 +30,18 @@ SOFTWARE.
 typedef struct {
     uint8_t state;
     uint8_t buffer[] __attribute__((aligned(4)));
-}triple_buffer_object_t;
+} triple_buffer_object_t;
 
 void triple_buffer_init(triple_buffer_object_t* object);
 
-#define triple_buffer_begin_write(object) \
-    (typeof(*object.buffer[0])*)triple_buffer_begin_write_internal(sizeof(*object.buffer[0]), (triple_buffer_object_t*)object)
+#define triple_buffer_begin_write(object) (typeof(*object.buffer[0])*)triple_buffer_begin_write_internal(sizeof(*object.buffer[0]), (triple_buffer_object_t*)object)
 
-#define triple_buffer_end_write(object) \
-    triple_buffer_end_write_internal((triple_buffer_object_t*)object)
+#define triple_buffer_end_write(object) triple_buffer_end_write_internal((triple_buffer_object_t*)object)
 
-#define triple_buffer_read(object) \
-    (typeof(*object.buffer[0])*)triple_buffer_read_internal(sizeof(*object.buffer[0]), (triple_buffer_object_t*)object)
+#define triple_buffer_read(object) (typeof(*object.buffer[0])*)triple_buffer_read_internal(sizeof(*object.buffer[0]), (triple_buffer_object_t*)object)
 
 void* triple_buffer_begin_write_internal(uint16_t object_size, triple_buffer_object_t* object);
-void triple_buffer_end_write_internal(triple_buffer_object_t* object);
+void  triple_buffer_end_write_internal(triple_buffer_object_t* object);
 void* triple_buffer_read_internal(uint16_t object_size, triple_buffer_object_t* object);
 
-
 #endif
index b3bee62a18a44d00aa3c1406663ea2d50c4502bc..feac64e297dbfadb4c05a5d0ef4b050b7024a7be 100644 (file)
@@ -34,45 +34,37 @@ SOFTWARE.
 #include "config.h"
 
 static event_source_t new_data_event;
-static bool serial_link_connected;
-static bool is_master = false;
+static bool           serial_link_connected;
+static bool           is_master = false;
 
 static uint8_t keyboard_leds(void);
-static void send_keyboard(report_keyboard_t *report);
-static void send_mouse(report_mouse_t *report);
-static void send_system(uint16_t data);
-static void send_consumer(uint16_t data);
-
-host_driver_t serial_driver = {
-  keyboard_leds,
-  send_keyboard,
-  send_mouse,
-  send_system,
-  send_consumer
-};
+static void    send_keyboard(report_keyboard_t* report);
+static void    send_mouse(report_mouse_t* report);
+static void    send_system(uint16_t data);
+static void    send_consumer(uint16_t data);
+
+host_driver_t serial_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
 
 // Define these in your Config.h file
 #ifndef SERIAL_LINK_BAUD
-#error "Serial link baud is not set"
+#    error "Serial link baud is not set"
 #endif
 
 #ifndef SERIAL_LINK_THREAD_PRIORITY
-#error "Serial link thread priority not set"
+#    error "Serial link thread priority not set"
 #endif
 
-static SerialConfig config = {
-    .sc_speed = SERIAL_LINK_BAUD
-};
+static SerialConfig config = {.sc_speed = SERIAL_LINK_BAUD};
 
 //#define DEBUG_LINK_ERRORS
 
 static uint32_t read_from_serial(SerialDriver* driver, uint8_t link) {
     const uint32_t buffer_size = 16;
-    uint8_t buffer[buffer_size];
-    uint32_t bytes_read = sdAsynchronousRead(driver, buffer, buffer_size);
-    uint8_t* current = buffer;
-    uint8_t* end = current + bytes_read;
-    while(current < end) {
+    uint8_t        buffer[buffer_size];
+    uint32_t       bytes_read = sdAsynchronousRead(driver, buffer, buffer_size);
+    uint8_t*       current    = buffer;
+    uint8_t*       end        = current + bytes_read;
+    while (current < end) {
         byte_stuffer_recv_byte(link, *current);
         current++;
     }
@@ -93,7 +85,6 @@ static void print_error(char* str, eventflags_t flags, SerialDriver* driver) {
         print(str);
         uint32_t size = qSpaceI(&(driver->iqueue));
         xprintf(" Overrun error, queue size %d\n", size);
-
     }
     if (flags & SD_NOISE_ERROR) {
         print(str);
@@ -110,9 +101,7 @@ static void print_error(char* str, eventflags_t flags, SerialDriver* driver) {
 #endif
 }
 
-bool is_serial_link_master(void) {
-    return is_master;
-}
+bool is_serial_link_master(void) { return is_master; }
 
 // TODO: Optimize the stack size, this is probably way too big
 static THD_WORKING_AREA(serialThreadStack, 1024);
@@ -122,18 +111,11 @@ static THD_FUNCTION(serialThread, arg) {
     event_listener_t sd1_listener;
     event_listener_t sd2_listener;
     chEvtRegister(&new_data_event, &new_data_listener, 0);
-    eventflags_t events = CHN_INPUT_AVAILABLE
-            | SD_PARITY_ERROR | SD_FRAMING_ERROR | SD_OVERRUN_ERROR | SD_NOISE_ERROR | SD_BREAK_DETECTED;
-    chEvtRegisterMaskWithFlags(chnGetEventSource(&SD1),
-        &sd1_listener,
-        EVENT_MASK(1),
-        events);
-    chEvtRegisterMaskWithFlags(chnGetEventSource(&SD2),
-        &sd2_listener,
-        EVENT_MASK(2),
-        events);
+    eventflags_t events = CHN_INPUT_AVAILABLE | SD_PARITY_ERROR | SD_FRAMING_ERROR | SD_OVERRUN_ERROR | SD_NOISE_ERROR | SD_BREAK_DETECTED;
+    chEvtRegisterMaskWithFlags(chnGetEventSource(&SD1), &sd1_listener, EVENT_MASK(1), events);
+    chEvtRegisterMaskWithFlags(chnGetEventSource(&SD2), &sd2_listener, EVENT_MASK(2), events);
     bool need_wait = false;
-    while(true) {
+    while (true) {
         eventflags_t flags1 = 0;
         eventflags_t flags2 = 0;
         if (need_wait) {
@@ -162,8 +144,7 @@ static THD_FUNCTION(serialThread, arg) {
 void send_data(uint8_t link, const uint8_t* data, uint16_t size) {
     if (link == DOWN_LINK) {
         sdWrite(&SD1, data, size);
-    }
-    else {
+    } else {
         sdWrite(&SD2, data, size);
     }
 }
@@ -187,13 +168,12 @@ static remote_object_t* remote_objects[] = {
 void init_serial_link(void) {
     serial_link_connected = false;
     init_serial_link_hal();
-    add_remote_objects(remote_objects, sizeof(remote_objects)/sizeof(remote_object_t*));
+    add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*));
     init_byte_stuffer();
     sdStart(&SD1, &config);
     sdStart(&SD2, &config);
     chEvtObjectInit(&new_data_event);
-    (void)chThdCreateStatic(serialThreadStack, sizeof(serialThreadStack),
-                              SERIAL_LINK_THREAD_PRIORITY, serialThread, NULL);
+    (void)chThdCreateStatic(serialThreadStack, sizeof(serialThreadStack), SERIAL_LINK_THREAD_PRIORITY, serialThread, NULL);
 }
 
 void matrix_set_remote(matrix_row_t* rows, uint8_t index);
@@ -204,19 +184,19 @@ void serial_link_update(void) {
     }
 
     matrix_object_t matrix;
-    bool changed = false;
-    for(uint8_t i=0;i<MATRIX_ROWS;i++) {
+    bool            changed = false;
+    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
         matrix.rows[i] = matrix_get_row(i);
         changed |= matrix.rows[i] != last_matrix.rows[i];
     }
 
     systime_t current_time = chVTGetSystemTimeX();
-    systime_t delta = current_time - last_update;
+    systime_t delta        = current_time - last_update;
     if (changed || delta > US2ST(5000)) {
-        last_update = current_time;
-        last_matrix = matrix;
+        last_update        = current_time;
+        last_matrix        = matrix;
         matrix_object_t* m = begin_write_keyboard_matrix();
-        for(uint8_t i=0;i<MATRIX_ROWS;i++) {
+        for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
             m->rows[i] = matrix.rows[i];
         }
         end_write_keyboard_matrix();
@@ -230,36 +210,19 @@ void serial_link_update(void) {
     }
 }
 
-void signal_data_written(void) {
-    chEvtBroadcast(&new_data_event);
-}
+void signal_data_written(void) { chEvtBroadcast(&new_data_event); }
 
-bool is_serial_link_connected(void) {
-    return serial_link_connected;
-}
+bool is_serial_link_connected(void) { return serial_link_connected; }
 
-host_driver_t* get_serial_link_driver(void) {
-    return &serial_driver;
-}
+host_driver_t* get_serial_link_driver(void) { return &serial_driver; }
 
 // NOTE: The driver does nothing, because the master handles everything
-uint8_t keyboard_leds(void) {
-    return 0;
-}
+uint8_t keyboard_leds(void) { return 0; }
 
-void send_keyboard(report_keyboard_t *report) {
-    (void)report;
-}
+void send_keyboard(report_keyboard_t* report) { (void)report; }
 
-void send_mouse(report_mouse_t *report) {
-    (void)report;
-}
+void send_mouse(report_mouse_t* report) { (void)report; }
 
-void send_system(uint16_t data) {
-    (void)data;
-}
-
-void send_consumer(uint16_t data) {
-    (void)data;
-}
+void send_system(uint16_t data) { (void)data; }
 
+void send_consumer(uint16_t data) { (void)data; }
index 351e03877b0f5bb29d1b735c29fe7d403108b04c..f48fbe9ea75fa273ff2aac048cb6f4ba5c876dbd 100644 (file)
@@ -28,33 +28,27 @@ SOFTWARE.
 #include "host_driver.h"
 #include <stdbool.h>
 
-void init_serial_link(void);
-void init_serial_link_hal(void);
-bool is_serial_link_connected(void);
-bool is_serial_link_master(void);
+void           init_serial_link(void);
+void           init_serial_link_hal(void);
+bool           is_serial_link_connected(void);
+bool           is_serial_link_master(void);
 host_driver_t* get_serial_link_driver(void);
-void serial_link_update(void);
+void           serial_link_update(void);
 
 #if defined(PROTOCOL_CHIBIOS)
-#include "ch.h"
+#    include "ch.h"
 
-static inline void serial_link_lock(void) {
-    chSysLock();
-}
+static inline void serial_link_lock(void) { chSysLock(); }
 
-static inline void serial_link_unlock(void) {
-    chSysUnlock();
-}
+static inline void serial_link_unlock(void) { chSysUnlock(); }
 
 void signal_data_written(void);
 
 #else
 
-inline void serial_link_lock(void) {
-}
+inline void serial_link_lock(void) {}
 
-inline void serial_link_unlock(void) {
-}
+inline void serial_link_unlock(void) {}
 
 void signal_data_written(void);
 
index ff49d727bb1020bc5a6f6ee1998c043c57dea2be..9e4e1768f4f264714e1f5bb46b78137c04f1f764 100644 (file)
@@ -33,25 +33,21 @@ extern "C" {
 }
 
 using testing::_;
-using testing::ElementsAreArray;
 using testing::Args;
+using testing::ElementsAreArray;
 
-class ByteStuffer : public ::testing::Test{
-public:
+class ByteStuffer : public ::testing::Test {
+   public:
     ByteStuffer() {
         Instance = this;
         init_byte_stuffer();
     }
 
-    ~ByteStuffer() {
-        Instance = nullptr;
-    }
+    ~ByteStuffer() { Instance = nullptr; }
 
-    MOCK_METHOD3(validator_recv_frame, void (uint8_t link, uint8_t* data, uint16_t size));
+    MOCK_METHOD3(validator_recv_frame, void(uint8_t link, uint8_t* data, uint16_t size));
 
-    void send_data(uint8_t link, const uint8_t* data, uint16_t size) {
-        std::copy(data, data + size, std::back_inserter(sent_data));
-    }
+    void                 send_data(uint8_t link, const uint8_t* data, uint16_t size) { std::copy(data, data + size, std::back_inserter(sent_data)); }
     std::vector<uint8_t> sent_data;
 
     static ByteStuffer* Instance;
@@ -60,52 +56,42 @@ public:
 ByteStuffer* ByteStuffer::Instance = nullptr;
 
 extern "C" {
-    void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size) {
-        ByteStuffer::Instance->validator_recv_frame(link, data, size);
-    }
+void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size) { ByteStuffer::Instance->validator_recv_frame(link, data, size); }
 
-    void send_data(uint8_t link, const uint8_t* data, uint16_t size) {
-        ByteStuffer::Instance->send_data(link, data, size);
-    }
+void send_data(uint8_t link, const uint8_t* data, uint16_t size) { ByteStuffer::Instance->send_data(link, data, size); }
 }
 
 TEST_F(ByteStuffer, receives_no_frame_for_a_single_zero_byte) {
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .Times(0);
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).Times(0);
     byte_stuffer_recv_byte(0, 0);
 }
 
 TEST_F(ByteStuffer, receives_no_frame_for_a_single_FF_byte) {
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .Times(0);
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).Times(0);
     byte_stuffer_recv_byte(0, 0xFF);
 }
 
 TEST_F(ByteStuffer, receives_no_frame_for_a_single_random_byte) {
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .Times(0);
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).Times(0);
     byte_stuffer_recv_byte(0, 0x4A);
 }
 
 TEST_F(ByteStuffer, receives_no_frame_for_a_zero_length_frame) {
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .Times(0);
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).Times(0);
     byte_stuffer_recv_byte(0, 1);
     byte_stuffer_recv_byte(0, 0);
 }
 
 TEST_F(ByteStuffer, receives_single_byte_valid_frame) {
     uint8_t expected[] = {0x37};
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     byte_stuffer_recv_byte(0, 2);
     byte_stuffer_recv_byte(0, 0x37);
     byte_stuffer_recv_byte(0, 0);
 }
 TEST_F(ByteStuffer, receives_three_bytes_valid_frame) {
     uint8_t expected[] = {0x37, 0x99, 0xFF};
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     byte_stuffer_recv_byte(0, 4);
     byte_stuffer_recv_byte(0, 0x37);
     byte_stuffer_recv_byte(0, 0x99);
@@ -115,8 +101,7 @@ TEST_F(ByteStuffer, receives_three_bytes_valid_frame) {
 
 TEST_F(ByteStuffer, receives_single_zero_valid_frame) {
     uint8_t expected[] = {0};
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     byte_stuffer_recv_byte(0, 1);
     byte_stuffer_recv_byte(0, 1);
     byte_stuffer_recv_byte(0, 0);
@@ -124,8 +109,7 @@ TEST_F(ByteStuffer, receives_single_zero_valid_frame) {
 
 TEST_F(ByteStuffer, receives_valid_frame_with_zeroes) {
     uint8_t expected[] = {5, 0, 3, 0};
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     byte_stuffer_recv_byte(0, 2);
     byte_stuffer_recv_byte(0, 5);
     byte_stuffer_recv_byte(0, 2);
@@ -134,14 +118,11 @@ TEST_F(ByteStuffer, receives_valid_frame_with_zeroes) {
     byte_stuffer_recv_byte(0, 0);
 }
 
-
 TEST_F(ByteStuffer, receives_two_valid_frames) {
     uint8_t expected1[] = {5, 0};
     uint8_t expected2[] = {3};
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected1)));
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected2)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected1)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected2)));
     byte_stuffer_recv_byte(1, 2);
     byte_stuffer_recv_byte(1, 5);
     byte_stuffer_recv_byte(1, 1);
@@ -153,8 +134,7 @@ TEST_F(ByteStuffer, receives_two_valid_frames) {
 
 TEST_F(ByteStuffer, receives_valid_frame_after_unexpected_zero) {
     uint8_t expected[] = {5, 7};
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     byte_stuffer_recv_byte(1, 3);
     byte_stuffer_recv_byte(1, 1);
     byte_stuffer_recv_byte(1, 0);
@@ -166,11 +146,10 @@ TEST_F(ByteStuffer, receives_valid_frame_after_unexpected_zero) {
 
 TEST_F(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) {
     uint8_t expected[] = {5, 7};
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     byte_stuffer_recv_byte(0, 2);
     byte_stuffer_recv_byte(0, 9);
-    byte_stuffer_recv_byte(0, 4); // This should have been zero
+    byte_stuffer_recv_byte(0, 4);  // This should have been zero
     byte_stuffer_recv_byte(0, 0);
     byte_stuffer_recv_byte(0, 3);
     byte_stuffer_recv_byte(0, 5);
@@ -180,31 +159,29 @@ TEST_F(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) {
 
 TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_and_then_end_of_frame) {
     uint8_t expected[254];
-    int i;
-    for (i=0;i<254;i++) {
+    int     i;
+    for (i = 0; i < 254; i++) {
         expected[i] = i + 1;
     }
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     byte_stuffer_recv_byte(0, 0xFF);
-    for (i=0;i<254;i++) {
-        byte_stuffer_recv_byte(0, i+1);
+    for (i = 0; i < 254; i++) {
+        byte_stuffer_recv_byte(0, i + 1);
     }
     byte_stuffer_recv_byte(0, 0);
 }
 
 TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_non_zero) {
     uint8_t expected[255];
-    int i;
-    for (i=0;i<254;i++) {
+    int     i;
+    for (i = 0; i < 254; i++) {
         expected[i] = i + 1;
     }
     expected[254] = 7;
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     byte_stuffer_recv_byte(0, 0xFF);
-    for (i=0;i<254;i++) {
-        byte_stuffer_recv_byte(0, i+1);
+    for (i = 0; i < 254; i++) {
+        byte_stuffer_recv_byte(0, i + 1);
     }
     byte_stuffer_recv_byte(0, 2);
     byte_stuffer_recv_byte(0, 7);
@@ -213,16 +190,15 @@ TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_
 
 TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_zero) {
     uint8_t expected[255];
-    int i;
-    for (i=0;i<254;i++) {
+    int     i;
+    for (i = 0; i < 254; i++) {
         expected[i] = i + 1;
     }
     expected[254] = 0;
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     byte_stuffer_recv_byte(0, 0xFF);
-    for (i=0;i<254;i++) {
-        byte_stuffer_recv_byte(0, i+1);
+    for (i = 0; i < 254; i++) {
+        byte_stuffer_recv_byte(0, i + 1);
     }
     byte_stuffer_recv_byte(0, 1);
     byte_stuffer_recv_byte(0, 1);
@@ -231,25 +207,24 @@ TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_
 
 TEST_F(ByteStuffer, receives_two_long_frames_and_some_more) {
     uint8_t expected[515];
-    int i;
-    int j;
-    for (j=0;j<2;j++) {
-        for (i=0;i<254;i++) {
-            expected[i+254*j] = i + 1;
+    int     i;
+    int     j;
+    for (j = 0; j < 2; j++) {
+        for (i = 0; i < 254; i++) {
+            expected[i + 254 * j] = i + 1;
         }
     }
-    for (i=0;i<7;i++) {
-        expected[254*2+i] = i + 1;
+    for (i = 0; i < 7; i++) {
+        expected[254 * 2 + i] = i + 1;
     }
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     byte_stuffer_recv_byte(0, 0xFF);
-    for (i=0;i<254;i++) {
-        byte_stuffer_recv_byte(0, i+1);
+    for (i = 0; i < 254; i++) {
+        byte_stuffer_recv_byte(0, i + 1);
     }
     byte_stuffer_recv_byte(0, 0xFF);
-    for (i=0;i<254;i++) {
-        byte_stuffer_recv_byte(0, i+1);
+    for (i = 0; i < 254; i++) {
+        byte_stuffer_recv_byte(0, i + 1);
     }
     byte_stuffer_recv_byte(0, 8);
     byte_stuffer_recv_byte(0, 1);
@@ -264,24 +239,22 @@ TEST_F(ByteStuffer, receives_two_long_frames_and_some_more) {
 
 TEST_F(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) {
     uint8_t expected[MAX_FRAME_SIZE] = {};
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     int i;
     byte_stuffer_recv_byte(0, 1);
-    for(i=0;i<MAX_FRAME_SIZE;i++) {
-       byte_stuffer_recv_byte(0, 1);
+    for (i = 0; i < MAX_FRAME_SIZE; i++) {
+        byte_stuffer_recv_byte(0, 1);
     }
     byte_stuffer_recv_byte(0, 0);
 }
 
 TEST_F(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) {
     uint8_t expected[1] = {0};
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .Times(0);
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).Times(0);
     int i;
     byte_stuffer_recv_byte(0, 1);
-    for(i=0;i<MAX_FRAME_SIZE;i++) {
-       byte_stuffer_recv_byte(0, 1);
+    for (i = 0; i < MAX_FRAME_SIZE; i++) {
+        byte_stuffer_recv_byte(0, 1);
     }
     byte_stuffer_recv_byte(0, 1);
     byte_stuffer_recv_byte(0, 0);
@@ -289,12 +262,11 @@ TEST_F(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) {
 
 TEST_F(ByteStuffer, received_frame_is_aborted_when_its_too_long) {
     uint8_t expected[1] = {1};
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     int i;
     byte_stuffer_recv_byte(0, 1);
-    for(i=0;i<MAX_FRAME_SIZE;i++) {
-       byte_stuffer_recv_byte(0, 1);
+    for (i = 0; i < MAX_FRAME_SIZE; i++) {
+        byte_stuffer_recv_byte(0, 1);
     }
     byte_stuffer_recv_byte(0, 2);
     byte_stuffer_recv_byte(0, 1);
@@ -364,14 +336,14 @@ TEST_F(ByteStuffer, sends_three_byte_frame_with_all_zeroes) {
 
 TEST_F(ByteStuffer, sends_frame_with_254_non_zeroes) {
     uint8_t data[254];
-    int i;
-    for(i=0;i<254;i++) {
+    int     i;
+    for (i = 0; i < 254; i++) {
         data[i] = i + 1;
     }
     byte_stuffer_send_frame(0, data, 254);
     uint8_t expected[256];
     expected[0] = 0xFF;
-    for(i=1;i<255;i++) {
+    for (i = 1; i < 255; i++) {
         expected[i] = i;
     }
     expected[255] = 0;
@@ -380,14 +352,14 @@ TEST_F(ByteStuffer, sends_frame_with_254_non_zeroes) {
 
 TEST_F(ByteStuffer, sends_frame_with_255_non_zeroes) {
     uint8_t data[255];
-    int i;
-    for(i=0;i<255;i++) {
+    int     i;
+    for (i = 0; i < 255; i++) {
         data[i] = i + 1;
     }
     byte_stuffer_send_frame(0, data, 255);
     uint8_t expected[258];
     expected[0] = 0xFF;
-    for(i=1;i<255;i++) {
+    for (i = 1; i < 255; i++) {
         expected[i] = i;
     }
     expected[255] = 2;
@@ -398,15 +370,15 @@ TEST_F(ByteStuffer, sends_frame_with_255_non_zeroes) {
 
 TEST_F(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) {
     uint8_t data[255];
-    int i;
-    for(i=0;i<254;i++) {
+    int     i;
+    for (i = 0; i < 254; i++) {
         data[i] = i + 1;
     }
     data[254] = 0;
     byte_stuffer_send_frame(0, data, 255);
     uint8_t expected[258];
     expected[0] = 0xFF;
-    for(i=1;i<255;i++) {
+    for (i = 1; i < 255; i++) {
         expected[i] = i;
     }
     expected[255] = 1;
@@ -416,68 +388,63 @@ TEST_F(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) {
 }
 
 TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_small_packet) {
-    uint8_t original_data[] = { 1, 2, 3};
+    uint8_t original_data[] = {1, 2, 3};
     byte_stuffer_send_frame(0, original_data, sizeof(original_data));
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(original_data)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(original_data)));
     int i;
-    for(auto& d : sent_data) {
-       byte_stuffer_recv_byte(1, d);
+    for (auto& d : sent_data) {
+        byte_stuffer_recv_byte(1, d);
     }
 }
 
 TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_small_packet_with_zeros) {
-    uint8_t original_data[] = { 1, 0, 3, 0, 0, 9};
+    uint8_t original_data[] = {1, 0, 3, 0, 0, 9};
     byte_stuffer_send_frame(1, original_data, sizeof(original_data));
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(original_data)));
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(original_data)));
     int i;
-    for(auto& d : sent_data) {
-       byte_stuffer_recv_byte(1, d);
+    for (auto& d : sent_data) {
+        byte_stuffer_recv_byte(1, d);
     }
 }
 
 TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes) {
     uint8_t original_data[254];
-    int i;
-    for(i=0;i<254;i++) {
+    int     i;
+    for (i = 0; i < 254; i++) {
         original_data[i] = i + 1;
     }
     byte_stuffer_send_frame(0, original_data, sizeof(original_data));
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(original_data)));
-    for(auto& d : sent_data) {
-       byte_stuffer_recv_byte(1, d);
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(original_data)));
+    for (auto& d : sent_data) {
+        byte_stuffer_recv_byte(1, d);
     }
 }
 
 TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_256_bytes) {
     uint8_t original_data[256];
-    int i;
-    for(i=0;i<254;i++) {
+    int     i;
+    for (i = 0; i < 254; i++) {
         original_data[i] = i + 1;
     }
     original_data[254] = 22;
     original_data[255] = 23;
     byte_stuffer_send_frame(0, original_data, sizeof(original_data));
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(original_data)));
-    for(auto& d : sent_data) {
-       byte_stuffer_recv_byte(1, d);
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(original_data)));
+    for (auto& d : sent_data) {
+        byte_stuffer_recv_byte(1, d);
     }
 }
 
 TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes_and_then_zero) {
     uint8_t original_data[255];
-    int i;
-    for(i=0;i<254;i++) {
+    int     i;
+    for (i = 0; i < 254; i++) {
         original_data[i] = i + 1;
     }
     original_data[254] = 0;
     byte_stuffer_send_frame(0, original_data, sizeof(original_data));
-    EXPECT_CALL(*this, validator_recv_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(original_data)));
-    for(auto& d : sent_data) {
-       byte_stuffer_recv_byte(1, d);
+    EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(original_data)));
+    for (auto& d : sent_data) {
+        byte_stuffer_recv_byte(1, d);
     }
 }
index 2bd5bf830d66d036a13ad7c3cf06d8f63c94f5f9..f76dfb33d6e9992c64697bf16eb1db9e1197e870 100644 (file)
@@ -26,27 +26,23 @@ SOFTWARE.
 #include "gmock/gmock.h"
 #include <array>
 extern "C" {
-    #include "serial_link/protocol/transport.h"
-    #include "serial_link/protocol/byte_stuffer.h"
-    #include "serial_link/protocol/frame_router.h"
+#include "serial_link/protocol/transport.h"
+#include "serial_link/protocol/byte_stuffer.h"
+#include "serial_link/protocol/frame_router.h"
 }
 
 using testing::_;
-using testing::ElementsAreArray;
 using testing::Args;
+using testing::ElementsAreArray;
 
 class FrameRouter : public testing::Test {
-public:
-    FrameRouter() :
-        current_router_buffer(nullptr)
-    {
+   public:
+    FrameRouter() : current_router_buffer(nullptr) {
         Instance = this;
         init_byte_stuffer();
     }
 
-    ~FrameRouter() {
-        Instance = nullptr;
-    }
+    ~FrameRouter() { Instance = nullptr; }
 
     void send_data(uint8_t link, const uint8_t* data, uint16_t size) {
         auto& buffer = current_router_buffer->send_buffers[link];
@@ -55,31 +51,26 @@ public:
 
     void receive_data(uint8_t link, uint8_t* data, uint16_t size) {
         int i;
-        for(i=0;i<size;i++) {
+        for (i = 0; i < size; i++) {
             byte_stuffer_recv_byte(link, data[i]);
         }
     }
 
     void activate_router(uint8_t num) {
         current_router_buffer = router_buffers + num;
-        router_set_master(num==0);
+        router_set_master(num == 0);
     }
 
     void simulate_transport(uint8_t from, uint8_t to) {
-       activate_router(to);
-       if (from > to) {
-           receive_data(DOWN_LINK,
-                   router_buffers[from].send_buffers[UP_LINK].data(),
-                   router_buffers[from].send_buffers[UP_LINK].size());
-       }
-       else if(to > from) {
-           receive_data(UP_LINK,
-                   router_buffers[from].send_buffers[DOWN_LINK].data(),
-                   router_buffers[from].send_buffers[DOWN_LINK].size());
-       }
+        activate_router(to);
+        if (from > to) {
+            receive_data(DOWN_LINK, router_buffers[from].send_buffers[UP_LINK].data(), router_buffers[from].send_buffers[UP_LINK].size());
+        } else if (to > from) {
+            receive_data(UP_LINK, router_buffers[from].send_buffers[DOWN_LINK].data(), router_buffers[from].send_buffers[DOWN_LINK].size());
+        }
     }
 
-    MOCK_METHOD3(transport_recv_frame, void (uint8_t from, uint8_t* data, uint16_t size));
+    MOCK_METHOD3(transport_recv_frame, void(uint8_t from, uint8_t* data, uint16_t size));
 
     std::vector<uint8_t> received_data;
 
@@ -87,7 +78,7 @@ public:
         std::vector<uint8_t> send_buffers[2];
     };
 
-    router_buffer router_buffers[8];
+    router_buffer  router_buffers[8];
     router_buffer* current_router_buffer;
 
     static FrameRouter* Instance;
@@ -95,22 +86,15 @@ public:
 
 FrameRouter* FrameRouter::Instance = nullptr;
 
-
 typedef struct {
     std::array<uint8_t, 4> data;
-    uint8_t extra[16];
+    uint8_t                extra[16];
 } frame_buffer_t;
 
-
 extern "C" {
-    void send_data(uint8_t link, const uint8_t* data, uint16_t size) {
-        FrameRouter::Instance->send_data(link, data, size);
-    }
+void send_data(uint8_t link, const uint8_t* data, uint16_t size) { FrameRouter::Instance->send_data(link, data, size); }
 
-
-    void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) {
-        FrameRouter::Instance->transport_recv_frame(from, data, size);
-    }
+void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) { FrameRouter::Instance->transport_recv_frame(from, data, size); }
 }
 
 TEST_F(FrameRouter, master_broadcast_is_received_by_everyone) {
@@ -120,14 +104,12 @@ TEST_F(FrameRouter, master_broadcast_is_received_by_everyone) {
     router_send_frame(0xFF, (uint8_t*)&data, 4);
     EXPECT_GT(router_buffers[0].send_buffers[DOWN_LINK].size(), 0);
     EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0);
-    EXPECT_CALL(*this, transport_recv_frame(0, _, _))
-        .With(Args<1, 2>(ElementsAreArray(data.data)));
+    EXPECT_CALL(*this, transport_recv_frame(0, _, _)).With(Args<1, 2>(ElementsAreArray(data.data)));
     simulate_transport(0, 1);
     EXPECT_GT(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
     EXPECT_EQ(router_buffers[1].send_buffers[UP_LINK].size(), 0);
 
-    EXPECT_CALL(*this, transport_recv_frame(0, _, _))
-        .With(Args<1, 2>(ElementsAreArray(data.data)));
+    EXPECT_CALL(*this, transport_recv_frame(0, _, _)).With(Args<1, 2>(ElementsAreArray(data.data)));
     simulate_transport(1, 2);
     EXPECT_GT(router_buffers[2].send_buffers[DOWN_LINK].size(), 0);
     EXPECT_EQ(router_buffers[2].send_buffers[UP_LINK].size(), 0);
@@ -145,14 +127,12 @@ TEST_F(FrameRouter, master_send_is_received_by_targets) {
     EXPECT_GT(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
     EXPECT_EQ(router_buffers[1].send_buffers[UP_LINK].size(), 0);
 
-    EXPECT_CALL(*this, transport_recv_frame(0, _, _))
-        .With(Args<1, 2>(ElementsAreArray(data.data)));
+    EXPECT_CALL(*this, transport_recv_frame(0, _, _)).With(Args<1, 2>(ElementsAreArray(data.data)));
     simulate_transport(1, 2);
     EXPECT_GT(router_buffers[2].send_buffers[DOWN_LINK].size(), 0);
     EXPECT_EQ(router_buffers[2].send_buffers[UP_LINK].size(), 0);
 
-    EXPECT_CALL(*this, transport_recv_frame(0, _, _))
-        .With(Args<1, 2>(ElementsAreArray(data.data)));
+    EXPECT_CALL(*this, transport_recv_frame(0, _, _)).With(Args<1, 2>(ElementsAreArray(data.data)));
     simulate_transport(2, 3);
     EXPECT_GT(router_buffers[3].send_buffers[DOWN_LINK].size(), 0);
     EXPECT_EQ(router_buffers[3].send_buffers[UP_LINK].size(), 0);
@@ -166,8 +146,7 @@ TEST_F(FrameRouter, first_link_sends_to_master) {
     EXPECT_GT(router_buffers[1].send_buffers[UP_LINK].size(), 0);
     EXPECT_EQ(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
 
-    EXPECT_CALL(*this, transport_recv_frame(1, _, _))
-        .With(Args<1, 2>(ElementsAreArray(data.data)));
+    EXPECT_CALL(*this, transport_recv_frame(1, _, _)).With(Args<1, 2>(ElementsAreArray(data.data)));
     simulate_transport(1, 0);
     EXPECT_EQ(router_buffers[0].send_buffers[DOWN_LINK].size(), 0);
     EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0);
@@ -185,8 +164,7 @@ TEST_F(FrameRouter, second_link_sends_to_master) {
     EXPECT_GT(router_buffers[1].send_buffers[UP_LINK].size(), 0);
     EXPECT_EQ(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
 
-    EXPECT_CALL(*this, transport_recv_frame(2, _, _))
-        .With(Args<1, 2>(ElementsAreArray(data.data)));
+    EXPECT_CALL(*this, transport_recv_frame(2, _, _)).With(Args<1, 2>(ElementsAreArray(data.data)));
     simulate_transport(1, 0);
     EXPECT_EQ(router_buffers[0].send_buffers[DOWN_LINK].size(), 0);
     EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0);
@@ -218,12 +196,9 @@ TEST_F(FrameRouter, master_receives_on_uplink_does_nothing) {
     EXPECT_GT(router_buffers[1].send_buffers[UP_LINK].size(), 0);
     EXPECT_EQ(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
 
-    EXPECT_CALL(*this, transport_recv_frame(_, _, _))
-        .Times(0);
+    EXPECT_CALL(*this, transport_recv_frame(_, _, _)).Times(0);
     activate_router(0);
-    receive_data(UP_LINK,
-        router_buffers[1].send_buffers[UP_LINK].data(),
-        router_buffers[1].send_buffers[UP_LINK].size());
+    receive_data(UP_LINK, router_buffers[1].send_buffers[UP_LINK].data(), router_buffers[1].send_buffers[UP_LINK].size());
     EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0);
     EXPECT_EQ(router_buffers[0].send_buffers[DOWN_LINK].size(), 0);
 }
index 9223af83b07039c93b43dc9c1b1cf55b25fae7d9..43dc57b6330e4afd4319811d48cc801eac003c3f 100644 (file)
@@ -29,21 +29,17 @@ extern "C" {
 }
 
 using testing::_;
-using testing::ElementsAreArray;
 using testing::Args;
+using testing::ElementsAreArray;
 
 class FrameValidator : public testing::Test {
-public:
-    FrameValidator() {
-        Instance = this;
-    }
+   public:
+    FrameValidator() { Instance = this; }
 
-    ~FrameValidator() {
-        Instance = nullptr;
-    }
+    ~FrameValidator() { Instance = nullptr; }
 
-    MOCK_METHOD3(route_incoming_frame, void (uint8_t link, uint8_t* data, uint16_t size));
-    MOCK_METHOD3(byte_stuffer_send_frame, void (uint8_t link, uint8_t* data, uint16_t size));
+    MOCK_METHOD3(route_incoming_frame, void(uint8_t link, uint8_t* data, uint16_t size));
+    MOCK_METHOD3(byte_stuffer_send_frame, void(uint8_t link, uint8_t* data, uint16_t size));
 
     static FrameValidator* Instance;
 };
@@ -51,18 +47,13 @@ public:
 FrameValidator* FrameValidator::Instance = nullptr;
 
 extern "C" {
-void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size) {
-    FrameValidator::Instance->route_incoming_frame(link, data, size);
-}
+void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size) { FrameValidator::Instance->route_incoming_frame(link, data, size); }
 
-void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size) {
-    FrameValidator::Instance->byte_stuffer_send_frame(link, data, size);
-}
+void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size) { FrameValidator::Instance->byte_stuffer_send_frame(link, data, size); }
 }
 
 TEST_F(FrameValidator, doesnt_validate_frames_under_5_bytes) {
-    EXPECT_CALL(*this, route_incoming_frame(_, _, _))
-        .Times(0);
+    EXPECT_CALL(*this, route_incoming_frame(_, _, _)).Times(0);
     uint8_t data[] = {1, 2};
     validator_recv_frame(0, 0, 1);
     validator_recv_frame(0, data, 2);
@@ -72,44 +63,38 @@ TEST_F(FrameValidator, doesnt_validate_frames_under_5_bytes) {
 
 TEST_F(FrameValidator, validates_one_byte_frame_with_correct_crc) {
     uint8_t data[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3};
-    EXPECT_CALL(*this, route_incoming_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(data, 1)));
+    EXPECT_CALL(*this, route_incoming_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(data, 1)));
     validator_recv_frame(0, data, 5);
 }
 
 TEST_F(FrameValidator, does_not_validate_one_byte_frame_with_incorrect_crc) {
     uint8_t data[] = {0x44, 0, 0, 0, 0};
-    EXPECT_CALL(*this, route_incoming_frame(_, _, _))
-        .Times(0);
+    EXPECT_CALL(*this, route_incoming_frame(_, _, _)).Times(0);
     validator_recv_frame(1, data, 5);
 }
 
 TEST_F(FrameValidator, validates_four_byte_frame_with_correct_crc) {
     uint8_t data[] = {0x44, 0x10, 0xFF, 0x00, 0x74, 0x4E, 0x30, 0xBA};
-    EXPECT_CALL(*this, route_incoming_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(data, 4)));
+    EXPECT_CALL(*this, route_incoming_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(data, 4)));
     validator_recv_frame(1, data, 8);
 }
 
 TEST_F(FrameValidator, validates_five_byte_frame_with_correct_crc) {
     uint8_t data[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47};
-    EXPECT_CALL(*this, route_incoming_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(data, 5)));
+    EXPECT_CALL(*this, route_incoming_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(data, 5)));
     validator_recv_frame(0, data, 9);
 }
 
 TEST_F(FrameValidator, sends_one_byte_with_correct_crc) {
     uint8_t original[] = {0x44, 0, 0, 0, 0};
     uint8_t expected[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3};
-    EXPECT_CALL(*this, byte_stuffer_send_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, byte_stuffer_send_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     validator_send_frame(0, original, 1);
 }
 
 TEST_F(FrameValidator, sends_five_bytes_with_correct_crc) {
     uint8_t original[] = {1, 2, 3, 4, 5, 0, 0, 0, 0};
     uint8_t expected[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47};
-    EXPECT_CALL(*this, byte_stuffer_send_frame(_, _, _))
-        .With(Args<1, 2>(ElementsAreArray(expected)));
+    EXPECT_CALL(*this, byte_stuffer_send_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected)));
     validator_send_frame(0, original, 5);
 }
index 21b7b165f624e89398583caebcbdf007153ffcea..cfd11104609bb97661a0120792c5bcf554ec3978 100644 (file)
@@ -26,8 +26,8 @@ SOFTWARE.
 #include "gmock/gmock.h"
 
 using testing::_;
-using testing::ElementsAreArray;
 using testing::Args;
+using testing::ElementsAreArray;
 
 extern "C" {
 #include "serial_link/protocol/transport.h"
@@ -53,7 +53,7 @@ static remote_object_t* test_remote_objects[] = {
 };
 
 class Transport : public testing::Test {
-public:
+   public:
     Transport() {
         Instance = this;
         add_remote_objects(test_remote_objects, sizeof(test_remote_objects) / sizeof(remote_object_t*));
@@ -64,8 +64,8 @@ public:
         reinitialize_serial_link_transport();
     }
 
-    MOCK_METHOD0(signal_data_written, void ());
-    MOCK_METHOD1(router_send_frame, void (uint8_t destination));
+    MOCK_METHOD0(signal_data_written, void());
+    MOCK_METHOD1(router_send_frame, void(uint8_t destination));
 
     void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
         router_send_frame(destination);
@@ -80,13 +80,9 @@ public:
 Transport* Transport::Instance = nullptr;
 
 extern "C" {
-void signal_data_written(void) {
-    Transport::Instance->signal_data_written();
-}
+void signal_data_written(void) { Transport::Instance->signal_data_written(); }
 
-void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
-    Transport::Instance->router_send_frame(destination, data, size);
-}
+void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) { Transport::Instance->router_send_frame(destination, data, size); }
 }
 
 TEST_F(Transport, write_to_local_signals_an_event) {
@@ -104,7 +100,7 @@ TEST_F(Transport, write_to_local_signals_an_event) {
 TEST_F(Transport, writes_from_master_to_all_slaves) {
     update_transport();
     test_object1* obj = begin_write_master_to_slave();
-    obj->test = 5;
+    obj->test         = 5;
     EXPECT_CALL(*this, signal_data_written());
     end_write_master_to_slave();
     EXPECT_CALL(*this, router_send_frame(0xFF));
@@ -118,7 +114,7 @@ TEST_F(Transport, writes_from_master_to_all_slaves) {
 TEST_F(Transport, writes_from_slave_to_master) {
     update_transport();
     test_object1* obj = begin_write_slave_to_master();
-    obj->test = 7;
+    obj->test         = 7;
     EXPECT_CALL(*this, signal_data_written());
     end_write_slave_to_master();
     EXPECT_CALL(*this, router_send_frame(0));
@@ -133,7 +129,7 @@ TEST_F(Transport, writes_from_slave_to_master) {
 TEST_F(Transport, writes_from_master_to_single_slave) {
     update_transport();
     test_object1* obj = begin_write_master_to_single_slave(3);
-    obj->test = 7;
+    obj->test         = 7;
     EXPECT_CALL(*this, signal_data_written());
     end_write_master_to_single_slave(3);
     EXPECT_CALL(*this, router_send_frame(4));
@@ -147,7 +143,7 @@ TEST_F(Transport, writes_from_master_to_single_slave) {
 TEST_F(Transport, ignores_object_with_invalid_id) {
     update_transport();
     test_object1* obj = begin_write_master_to_single_slave(3);
-    obj->test = 7;
+    obj->test         = 7;
     EXPECT_CALL(*this, signal_data_written());
     end_write_master_to_single_slave(3);
     EXPECT_CALL(*this, router_send_frame(4));
@@ -161,7 +157,7 @@ TEST_F(Transport, ignores_object_with_invalid_id) {
 TEST_F(Transport, ignores_object_with_size_too_small) {
     update_transport();
     test_object1* obj = begin_write_master_to_slave();
-    obj->test = 7;
+    obj->test         = 7;
     EXPECT_CALL(*this, signal_data_written());
     end_write_master_to_slave();
     EXPECT_CALL(*this, router_send_frame(_));
@@ -175,7 +171,7 @@ TEST_F(Transport, ignores_object_with_size_too_small) {
 TEST_F(Transport, ignores_object_with_size_too_big) {
     update_transport();
     test_object1* obj = begin_write_master_to_slave();
-    obj->test = 7;
+    obj->test         = 7;
     EXPECT_CALL(*this, signal_data_written());
     end_write_master_to_slave();
     EXPECT_CALL(*this, router_send_frame(_));
index 7724bbee9c331cf368eb7ee1f5ceecdb078efd83..8de9bfdebf3c2ff32e9dbfb2e59fdadc61e41aed 100644 (file)
@@ -27,18 +27,16 @@ extern "C" {
 #include "serial_link/protocol/triple_buffered_object.h"
 }
 
-struct test_object{
-    uint8_t state;
+struct test_object {
+    uint8_t  state;
     uint32_t buffer[3];
 };
 
 test_object test_object;
 
 class TripleBufferedObject : public testing::Test {
-public:
-    TripleBufferedObject() {
-        triple_buffer_init((triple_buffer_object_t*)&test_object);
-    }
+   public:
+    TripleBufferedObject() { triple_buffer_init((triple_buffer_object_t*)&test_object); }
 };
 
 TEST_F(TripleBufferedObject, writes_and_reads_object) {
@@ -47,9 +45,7 @@ TEST_F(TripleBufferedObject, writes_and_reads_object) {
     EXPECT_EQ(*triple_buffer_read(&test_object), 0x3456ABCC);
 }
 
-TEST_F(TripleBufferedObject, does_not_read_empty) {
-    EXPECT_EQ(triple_buffer_read(&test_object), nullptr);
-}
+TEST_F(TripleBufferedObject, does_not_read_empty) { EXPECT_EQ(triple_buffer_read(&test_object), nullptr); }
 
 TEST_F(TripleBufferedObject, writes_twice_and_reads_object) {
     *triple_buffer_begin_write(&test_object) = 0x3456ABCC;
@@ -62,7 +58,7 @@ TEST_F(TripleBufferedObject, writes_twice_and_reads_object) {
 TEST_F(TripleBufferedObject, performs_another_write_in_the_middle_of_read) {
     *triple_buffer_begin_write(&test_object) = 1;
     triple_buffer_end_write(&test_object);
-    uint32_t* read = triple_buffer_read(&test_object);
+    uint32_t* read                           = triple_buffer_read(&test_object);
     *triple_buffer_begin_write(&test_object) = 2;
     triple_buffer_end_write(&test_object);
     EXPECT_EQ(*read, 1);
@@ -73,7 +69,7 @@ TEST_F(TripleBufferedObject, performs_another_write_in_the_middle_of_read) {
 TEST_F(TripleBufferedObject, performs_two_writes_in_the_middle_of_read) {
     *triple_buffer_begin_write(&test_object) = 1;
     triple_buffer_end_write(&test_object);
-    uint32_t* read = triple_buffer_read(&test_object);
+    uint32_t* read                           = triple_buffer_read(&test_object);
     *triple_buffer_begin_write(&test_object) = 2;
     triple_buffer_end_write(&test_object);
     *triple_buffer_begin_write(&test_object) = 3;
index e0f094e34ba1d1a9a4b17cdcd3be783545c8a8cc..313f7830b64797241a991579d4a98bafbbbd7881 100644 (file)
@@ -30,24 +30,24 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "transport.h"
 
 #ifdef ENCODER_ENABLE
-  #include "encoder.h"
+#    include "encoder.h"
 #endif
 
 #if (MATRIX_COLS <= 8)
-#  define print_matrix_header() print("\nr/c 01234567\n")
-#  define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
-#  define matrix_bitpop(i) bitpop(matrix[i])
-#  define ROW_SHIFTER ((uint8_t)1)
+#    define print_matrix_header() print("\nr/c 01234567\n")
+#    define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
+#    define matrix_bitpop(i) bitpop(matrix[i])
+#    define ROW_SHIFTER ((uint8_t)1)
 #elif (MATRIX_COLS <= 16)
-#  define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
-#  define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
-#  define matrix_bitpop(i) bitpop16(matrix[i])
-#  define ROW_SHIFTER ((uint16_t)1)
+#    define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
+#    define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
+#    define matrix_bitpop(i) bitpop16(matrix[i])
+#    define ROW_SHIFTER ((uint16_t)1)
 #elif (MATRIX_COLS <= 32)
-#  define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
-#  define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
-#  define matrix_bitpop(i) bitpop32(matrix[i])
-#  define ROW_SHIFTER ((uint32_t)1)
+#    define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
+#    define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
+#    define matrix_bitpop(i) bitpop32(matrix[i])
+#    define ROW_SHIFTER ((uint32_t)1)
 #endif
 
 #define ERROR_DISCONNECT_COUNT 5
@@ -87,8 +87,8 @@ inline uint8_t matrix_rows(void) { return MATRIX_ROWS; }
 inline uint8_t matrix_cols(void) { return MATRIX_COLS; }
 
 bool matrix_is_modified(void) {
-  if (debounce_active()) return false;
-  return true;
+    if (debounce_active()) return false;
+    return true;
 }
 
 inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); }
@@ -96,22 +96,22 @@ inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((mat
 inline matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; }
 
 void matrix_print(void) {
-  print_matrix_header();
-
-  for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
-    phex(row);
-    print(": ");
-    print_matrix_row(row);
-    print("\n");
-  }
+    print_matrix_header();
+
+    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
+        phex(row);
+        print(": ");
+        print_matrix_row(row);
+        print("\n");
+    }
 }
 
 uint8_t matrix_key_count(void) {
-  uint8_t count = 0;
-  for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
-    count += matrix_bitpop(i);
-  }
-  return count;
+    uint8_t count = 0;
+    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+        count += matrix_bitpop(i);
+    }
+    return count;
 }
 
 // matrix code
@@ -119,224 +119,224 @@ uint8_t matrix_key_count(void) {
 #ifdef DIRECT_PINS
 
 static void init_pins(void) {
-  for (int row = 0; row < MATRIX_ROWS; row++) {
-    for (int col = 0; col < MATRIX_COLS; col++) {
-      pin_t pin = direct_pins[row][col];
-      if (pin != NO_PIN) {
-        setPinInputHigh(pin);
-      }
+    for (int row = 0; row < MATRIX_ROWS; row++) {
+        for (int col = 0; col < MATRIX_COLS; col++) {
+            pin_t pin = direct_pins[row][col];
+            if (pin != NO_PIN) {
+                setPinInputHigh(pin);
+            }
+        }
     }
-  }
 }
 
 static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
-  matrix_row_t last_row_value = current_matrix[current_row];
-  current_matrix[current_row] = 0;
+    matrix_row_t last_row_value = current_matrix[current_row];
+    current_matrix[current_row] = 0;
 
-  for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
-    pin_t pin = direct_pins[current_row][col_index];
-    if (pin != NO_PIN) {
-      current_matrix[current_row] |= readPin(pin) ? 0 : (ROW_SHIFTER << col_index);
+    for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
+        pin_t pin = direct_pins[current_row][col_index];
+        if (pin != NO_PIN) {
+            current_matrix[current_row] |= readPin(pin) ? 0 : (ROW_SHIFTER << col_index);
+        }
     }
-  }
 
-  return (last_row_value != current_matrix[current_row]);
+    return (last_row_value != current_matrix[current_row]);
 }
 
 #elif (DIODE_DIRECTION == COL2ROW)
 
 static void select_row(uint8_t row) {
-  setPinOutput(row_pins[row]);
-  writePinLow(row_pins[row]);
+    setPinOutput(row_pins[row]);
+    writePinLow(row_pins[row]);
 }
 
 static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); }
 
 static void unselect_rows(void) {
-  for (uint8_t x = 0; x < ROWS_PER_HAND; x++) {
-    setPinInputHigh(row_pins[x]);
-  }
+    for (uint8_t x = 0; x < ROWS_PER_HAND; x++) {
+        setPinInputHigh(row_pins[x]);
+    }
 }
 
 static void init_pins(void) {
-  unselect_rows();
-  for (uint8_t x = 0; x < MATRIX_COLS; x++) {
-    setPinInputHigh(col_pins[x]);
-  }
+    unselect_rows();
+    for (uint8_t x = 0; x < MATRIX_COLS; x++) {
+        setPinInputHigh(col_pins[x]);
+    }
 }
 
 static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
-  // Store last value of row prior to reading
-  matrix_row_t last_row_value = current_matrix[current_row];
+    // Store last value of row prior to reading
+    matrix_row_t last_row_value = current_matrix[current_row];
 
-  // Clear data in matrix row
-  current_matrix[current_row] = 0;
+    // Clear data in matrix row
+    current_matrix[current_row] = 0;
 
-  // Select row and wait for row selecton to stabilize
-  select_row(current_row);
-  wait_us(30);
+    // Select row and wait for row selecton to stabilize
+    select_row(current_row);
+    wait_us(30);
 
-  // For each col...
-  for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
-    // Populate the matrix row with the state of the col pin
-    current_matrix[current_row] |= readPin(col_pins[col_index]) ? 0 : (ROW_SHIFTER << col_index);
-  }
+    // For each col...
+    for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
+        // Populate the matrix row with the state of the col pin
+        current_matrix[current_row] |= readPin(col_pins[col_index]) ? 0 : (ROW_SHIFTER << col_index);
+    }
 
-  // Unselect row
-  unselect_row(current_row);
+    // Unselect row
+    unselect_row(current_row);
 
-  return (last_row_value != current_matrix[current_row]);
+    return (last_row_value != current_matrix[current_row]);
 }
 
 #elif (DIODE_DIRECTION == ROW2COL)
 
 static void select_col(uint8_t col) {
-  setPinOutput(col_pins[col]);
-  writePinLow(col_pins[col]);
+    setPinOutput(col_pins[col]);
+    writePinLow(col_pins[col]);
 }
 
 static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); }
 
 static void unselect_cols(void) {
-  for (uint8_t x = 0; x < MATRIX_COLS; x++) {
-    setPinInputHigh(col_pins[x]);
-  }
+    for (uint8_t x = 0; x < MATRIX_COLS; x++) {
+        setPinInputHigh(col_pins[x]);
+    }
 }
 
 static void init_pins(void) {
-  unselect_cols();
-  for (uint8_t x = 0; x < ROWS_PER_HAND; x++) {
-    setPinInputHigh(row_pins[x]);
-  }
+    unselect_cols();
+    for (uint8_t x = 0; x < ROWS_PER_HAND; x++) {
+        setPinInputHigh(row_pins[x]);
+    }
 }
 
 static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) {
-  bool matrix_changed = false;
-
-  // Select col and wait for col selecton to stabilize
-  select_col(current_col);
-  wait_us(30);
-
-  // For each row...
-  for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) {
-    // Store last value of row prior to reading
-    matrix_row_t last_row_value = current_matrix[row_index];
-
-    // Check row pin state
-    if (readPin(row_pins[row_index])) {
-      // Pin HI, clear col bit
-      current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
-    } else {
-      // Pin LO, set col bit
-      current_matrix[row_index] |= (ROW_SHIFTER << current_col);
-    }
+    bool matrix_changed = false;
+
+    // Select col and wait for col selecton to stabilize
+    select_col(current_col);
+    wait_us(30);
+
+    // For each row...
+    for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) {
+        // Store last value of row prior to reading
+        matrix_row_t last_row_value = current_matrix[row_index];
+
+        // Check row pin state
+        if (readPin(row_pins[row_index])) {
+            // Pin HI, clear col bit
+            current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
+        } else {
+            // Pin LO, set col bit
+            current_matrix[row_index] |= (ROW_SHIFTER << current_col);
+        }
 
-    // Determine if the matrix changed state
-    if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) {
-      matrix_changed = true;
+        // Determine if the matrix changed state
+        if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) {
+            matrix_changed = true;
+        }
     }
-  }
 
-  // Unselect col
-  unselect_col(current_col);
+    // Unselect col
+    unselect_col(current_col);
 
-  return matrix_changed;
+    return matrix_changed;
 }
 
 #endif
 
 void matrix_init(void) {
-  debug_enable = true;
-  debug_matrix = true;
-  debug_mouse  = true;
+    debug_enable = true;
+    debug_matrix = true;
+    debug_mouse  = true;
 
-  // Set pinout for right half if pinout for that half is defined
-  if (!isLeftHand) {
+    // Set pinout for right half if pinout for that half is defined
+    if (!isLeftHand) {
 #ifdef DIRECT_PINS_RIGHT
-    const pin_t direct_pins_right[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS_RIGHT;
-    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
-      for (uint8_t j = 0; j < MATRIX_COLS; j++) {
-        direct_pins[i][j] = direct_pins_right[i][j];
-      }
-    }
+        const pin_t direct_pins_right[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS_RIGHT;
+        for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+            for (uint8_t j = 0; j < MATRIX_COLS; j++) {
+                direct_pins[i][j] = direct_pins_right[i][j];
+            }
+        }
 #endif
 #ifdef MATRIX_ROW_PINS_RIGHT
-    const pin_t row_pins_right[MATRIX_ROWS] = MATRIX_ROW_PINS_RIGHT;
-    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
-      row_pins[i] = row_pins_right[i];
-    }
+        const pin_t row_pins_right[MATRIX_ROWS] = MATRIX_ROW_PINS_RIGHT;
+        for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+            row_pins[i] = row_pins_right[i];
+        }
 #endif
 #ifdef MATRIX_COL_PINS_RIGHT
-    const pin_t col_pins_right[MATRIX_COLS] = MATRIX_COL_PINS_RIGHT;
-    for (uint8_t i = 0; i < MATRIX_COLS; i++) {
-      col_pins[i] = col_pins_right[i];
-    }
+        const pin_t col_pins_right[MATRIX_COLS] = MATRIX_COL_PINS_RIGHT;
+        for (uint8_t i = 0; i < MATRIX_COLS; i++) {
+            col_pins[i] = col_pins_right[i];
+        }
 #endif
-  }
+    }
 
-  thisHand = isLeftHand ? 0 : (ROWS_PER_HAND);
-  thatHand = ROWS_PER_HAND - thisHand;
+    thisHand = isLeftHand ? 0 : (ROWS_PER_HAND);
+    thatHand = ROWS_PER_HAND - thisHand;
 
-  // initialize key pins
-  init_pins();
+    // initialize key pins
+    init_pins();
 
-  // initialize matrix state: all keys off
-  for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
-    matrix[i] = 0;
-  }
+    // initialize matrix state: all keys off
+    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+        matrix[i] = 0;
+    }
 
-  debounce_init(ROWS_PER_HAND);
+    debounce_init(ROWS_PER_HAND);
 
-  matrix_init_quantum();
+    matrix_init_quantum();
 }
 
 uint8_t _matrix_scan(void) {
-  bool changed = false;
+    bool changed = false;
 
 #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW)
-  // Set row, read cols
-  for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) {
-    changed |= read_cols_on_row(raw_matrix, current_row);
-  }
+    // Set row, read cols
+    for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) {
+        changed |= read_cols_on_row(raw_matrix, current_row);
+    }
 #elif (DIODE_DIRECTION == ROW2COL)
-  // Set col, read rows
-  for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
-    changed |= read_rows_on_col(raw_matrix, current_col);
-  }
+    // Set col, read rows
+    for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
+        changed |= read_rows_on_col(raw_matrix, current_col);
+    }
 #endif
 
-  debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed);
+    debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed);
 
-  return (uint8_t)changed;
+    return (uint8_t)changed;
 }
 
 uint8_t matrix_scan(void) {
-  uint8_t ret = _matrix_scan();
-
-  if (is_keyboard_master()) {
-    static uint8_t error_count;
-
-    if (!transport_master(matrix + thatHand)) {
-      error_count++;
-
-      if (error_count > ERROR_DISCONNECT_COUNT) {
-        // reset other half if disconnected
-        for (int i = 0; i < ROWS_PER_HAND; ++i) {
-          matrix[thatHand + i] = 0;
+    uint8_t ret = _matrix_scan();
+
+    if (is_keyboard_master()) {
+        static uint8_t error_count;
+
+        if (!transport_master(matrix + thatHand)) {
+            error_count++;
+
+            if (error_count > ERROR_DISCONNECT_COUNT) {
+                // reset other half if disconnected
+                for (int i = 0; i < ROWS_PER_HAND; ++i) {
+                    matrix[thatHand + i] = 0;
+                }
+            }
+        } else {
+            error_count = 0;
         }
-      }
-    } else {
-      error_count = 0;
-    }
 
-    matrix_scan_quantum();
-  } else {
-    transport_slave(matrix + thisHand);
+        matrix_scan_quantum();
+    } else {
+        transport_slave(matrix + thisHand);
 #ifdef ENCODER_ENABLE
-    encoder_read();
+        encoder_read();
 #endif
-    matrix_slave_scan_user();
-  }
+        matrix_slave_scan_user();
+    }
 
-  return ret;
+    return ret;
 }
index ff0fc5e1930dcf68b9b4755c9a689279582ff127..5c0b414fb380a65f1d244548da1adc3e6deadb67 100644 (file)
@@ -1,19 +1,19 @@
 #if defined(USE_I2C) || defined(EH)
-  // When using I2C, using rgblight implicitly involves split support.
-  #if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_SPLIT)
-    #define RGBLIGHT_SPLIT
-  #endif
+// When using I2C, using rgblight implicitly involves split support.
+#    if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_SPLIT)
+#        define RGBLIGHT_SPLIT
+#    endif
 
-  #ifndef F_SCL
-    #define F_SCL 100000UL  // SCL frequency
-  #endif
+#    ifndef F_SCL
+#        define F_SCL 100000UL  // SCL frequency
+#    endif
 
 #else  // use serial
-  // When using serial, the user must define RGBLIGHT_SPLIT explicitly
-  //  in config.h as needed.
-  //      see quantum/rgblight_post_config.h
-  #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
-    // When using serial and RGBLIGHT_SPLIT need separate transaction
-    #define SERIAL_USE_MULTI_TRANSACTION
-  #endif
+// When using serial, the user must define RGBLIGHT_SPLIT explicitly
+//  in config.h as needed.
+//      see quantum/rgblight_post_config.h
+#    if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+// When using serial and RGBLIGHT_SPLIT need separate transaction
+#        define SERIAL_USE_MULTI_TRANSACTION
+#    endif
 #endif
index 322ab8030bd88638bfa7d18a04f446494e8f4542..c4ef2a97e7d7fc053152e3a246040d4e85db2428 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #ifndef F_CPU
-#define F_CPU 16000000
+#    define F_CPU 16000000
 #endif
 
 #include <avr/io.h>
 
 #ifdef SOFT_SERIAL_PIN
 
-#ifdef __AVR_ATmega32U4__
-  // if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial.
-  #ifdef USE_AVR_I2C
-    #if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1
-      #error Using ATmega32U4 I2C, so can not use PD0, PD1
-    #endif
-  #endif
-
-  #define setPinInputHigh(pin)    (DDRx_ADDRESS(pin)  &= ~_BV((pin) & 0xF), \
-                                   PORTx_ADDRESS(pin) |=  _BV((pin) & 0xF))
-  #define setPinOutput(pin)       (DDRx_ADDRESS(pin)  |=  _BV((pin) & 0xF))
-  #define writePinHigh(pin)       (PORTx_ADDRESS(pin) |=  _BV((pin) & 0xF))
-  #define writePinLow(pin)        (PORTx_ADDRESS(pin) &= ~_BV((pin) & 0xF))
-  #define readPin(pin)            ((bool)(PINx_ADDRESS(pin) & _BV((pin) & 0xF)))
-
-  #if SOFT_SERIAL_PIN >= D0 && SOFT_SERIAL_PIN <= D3
-    #if SOFT_SERIAL_PIN == D0
-      #define EIMSK_BIT       _BV(INT0)
-      #define EICRx_BIT       (~(_BV(ISC00) | _BV(ISC01)))
-      #define SERIAL_PIN_INTERRUPT INT0_vect
-    #elif  SOFT_SERIAL_PIN == D1
-      #define EIMSK_BIT       _BV(INT1)
-      #define EICRx_BIT       (~(_BV(ISC10) | _BV(ISC11)))
-      #define SERIAL_PIN_INTERRUPT INT1_vect
-    #elif  SOFT_SERIAL_PIN == D2
-      #define EIMSK_BIT       _BV(INT2)
-      #define EICRx_BIT       (~(_BV(ISC20) | _BV(ISC21)))
-      #define SERIAL_PIN_INTERRUPT INT2_vect
-    #elif  SOFT_SERIAL_PIN == D3
-      #define EIMSK_BIT       _BV(INT3)
-      #define EICRx_BIT       (~(_BV(ISC30) | _BV(ISC31)))
-      #define SERIAL_PIN_INTERRUPT INT3_vect
-    #endif
-  #elif  SOFT_SERIAL_PIN == E6
-    #define EIMSK_BIT        _BV(INT6)
-    #define EICRx_BIT        (~(_BV(ISC60) | _BV(ISC61)))
-    #define SERIAL_PIN_INTERRUPT INT6_vect
-  #else
-  #error invalid SOFT_SERIAL_PIN value
-  #endif
-
-#else
- #error serial.c now support ATmega32U4 only
-#endif
-
-#define ALWAYS_INLINE __attribute__((always_inline))
-#define NO_INLINE __attribute__((noinline))
-#define _delay_sub_us(x)    __builtin_avr_delay_cycles(x)
+#    ifdef __AVR_ATmega32U4__
+// if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial.
+#        ifdef USE_AVR_I2C
+#            if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1
+#                error Using ATmega32U4 I2C, so can not use PD0, PD1
+#            endif
+#        endif
+
+#        define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
+#        define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
+#        define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
+#        define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
+#        define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
+
+#        if SOFT_SERIAL_PIN >= D0 && SOFT_SERIAL_PIN <= D3
+#            if SOFT_SERIAL_PIN == D0
+#                define EIMSK_BIT _BV(INT0)
+#                define EICRx_BIT (~(_BV(ISC00) | _BV(ISC01)))
+#                define SERIAL_PIN_INTERRUPT INT0_vect
+#            elif SOFT_SERIAL_PIN == D1
+#                define EIMSK_BIT _BV(INT1)
+#                define EICRx_BIT (~(_BV(ISC10) | _BV(ISC11)))
+#                define SERIAL_PIN_INTERRUPT INT1_vect
+#            elif SOFT_SERIAL_PIN == D2
+#                define EIMSK_BIT _BV(INT2)
+#                define EICRx_BIT (~(_BV(ISC20) | _BV(ISC21)))
+#                define SERIAL_PIN_INTERRUPT INT2_vect
+#            elif SOFT_SERIAL_PIN == D3
+#                define EIMSK_BIT _BV(INT3)
+#                define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31)))
+#                define SERIAL_PIN_INTERRUPT INT3_vect
+#            endif
+#        elif SOFT_SERIAL_PIN == E6
+#            define EIMSK_BIT _BV(INT6)
+#            define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61)))
+#            define SERIAL_PIN_INTERRUPT INT6_vect
+#        else
+#            error invalid SOFT_SERIAL_PIN value
+#        endif
+
+#    else
+#        error serial.c now support ATmega32U4 only
+#    endif
+
+#    define ALWAYS_INLINE __attribute__((always_inline))
+#    define NO_INLINE __attribute__((noinline))
+#    define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
 
 // parity check
-#define ODD_PARITY 1
-#define EVEN_PARITY 0
-#define PARITY EVEN_PARITY
-
-#ifdef SERIAL_DELAY
-  // custom setup in config.h
-  // #define TID_SEND_ADJUST 2
-  // #define SERIAL_DELAY 6             // micro sec
-  // #define READ_WRITE_START_ADJUST 30 // cycles
-  // #define READ_WRITE_WIDTH_ADJUST 8 // cycles
-#else
+#    define ODD_PARITY 1
+#    define EVEN_PARITY 0
+#    define PARITY EVEN_PARITY
+
+#    ifdef SERIAL_DELAY
+// custom setup in config.h
+// #define TID_SEND_ADJUST 2
+// #define SERIAL_DELAY 6             // micro sec
+// #define READ_WRITE_START_ADJUST 30 // cycles
+// #define READ_WRITE_WIDTH_ADJUST 8 // cycles
+#    else
 // ============ Standard setups ============
 
-#ifndef SELECT_SOFT_SERIAL_SPEED
-#define SELECT_SOFT_SERIAL_SPEED 1
+#        ifndef SELECT_SOFT_SERIAL_SPEED
+#            define SELECT_SOFT_SERIAL_SPEED 1
 //  0: about 189kbps (Experimental only)
 //  1: about 137kbps (default)
 //  2: about 75kbps
 //  3: about 39kbps
 //  4: about 26kbps
 //  5: about 20kbps
-#endif
-
-#if __GNUC__ < 6
-  #define TID_SEND_ADJUST 14
-#else
-  #define TID_SEND_ADJUST 2
-#endif
-
-#if SELECT_SOFT_SERIAL_SPEED == 0
-  // Very High speed
-  #define SERIAL_DELAY 4             // micro sec
-  #if __GNUC__ < 6
-    #define READ_WRITE_START_ADJUST 33 // cycles
-    #define READ_WRITE_WIDTH_ADJUST 3 // cycles
-  #else
-    #define READ_WRITE_START_ADJUST 34 // cycles
-    #define READ_WRITE_WIDTH_ADJUST 7 // cycles
-  #endif
-#elif SELECT_SOFT_SERIAL_SPEED == 1
-  // High speed
-  #define SERIAL_DELAY 6             // micro sec
-  #if __GNUC__ < 6
-    #define READ_WRITE_START_ADJUST 30 // cycles
-    #define READ_WRITE_WIDTH_ADJUST 3 // cycles
-  #else
-    #define READ_WRITE_START_ADJUST 33 // cycles
-    #define READ_WRITE_WIDTH_ADJUST 7 // cycles
-  #endif
-#elif SELECT_SOFT_SERIAL_SPEED == 2
-  // Middle speed
-  #define SERIAL_DELAY 12            // micro sec
-  #define READ_WRITE_START_ADJUST 30 // cycles
-  #if __GNUC__ < 6
-    #define READ_WRITE_WIDTH_ADJUST 3 // cycles
-  #else
-    #define READ_WRITE_WIDTH_ADJUST 7 // cycles
-  #endif
-#elif SELECT_SOFT_SERIAL_SPEED == 3
-  // Low speed
-  #define SERIAL_DELAY 24            // micro sec
-  #define READ_WRITE_START_ADJUST 30 // cycles
-  #if __GNUC__ < 6
-    #define READ_WRITE_WIDTH_ADJUST 3 // cycles
-  #else
-    #define READ_WRITE_WIDTH_ADJUST 7 // cycles
-  #endif
-#elif SELECT_SOFT_SERIAL_SPEED == 4
-  // Very Low speed
-  #define SERIAL_DELAY 36            // micro sec
-  #define READ_WRITE_START_ADJUST 30 // cycles
-  #if __GNUC__ < 6
-    #define READ_WRITE_WIDTH_ADJUST 3 // cycles
-  #else
-    #define READ_WRITE_WIDTH_ADJUST 7 // cycles
-  #endif
-#elif SELECT_SOFT_SERIAL_SPEED == 5
-  // Ultra Low speed
-  #define SERIAL_DELAY 48            // micro sec
-  #define READ_WRITE_START_ADJUST 30 // cycles
-  #if __GNUC__ < 6
-    #define READ_WRITE_WIDTH_ADJUST 3 // cycles
-  #else
-    #define READ_WRITE_WIDTH_ADJUST 7 // cycles
-  #endif
-#else
-#error invalid SELECT_SOFT_SERIAL_SPEED value
-#endif /* SELECT_SOFT_SERIAL_SPEED */
-#endif /* SERIAL_DELAY */
-
-#define SERIAL_DELAY_HALF1 (SERIAL_DELAY/2)
-#define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2)
-
-#define SLAVE_INT_WIDTH_US 1
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-  #define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
-#else
-  #define SLAVE_INT_ACK_WIDTH_UNIT 2
-  #define SLAVE_INT_ACK_WIDTH 4
-#endif
-
-static SSTD_t *Transaction_table = NULL;
+#        endif
+
+#        if __GNUC__ < 6
+#            define TID_SEND_ADJUST 14
+#        else
+#            define TID_SEND_ADJUST 2
+#        endif
+
+#        if SELECT_SOFT_SERIAL_SPEED == 0
+// Very High speed
+#            define SERIAL_DELAY 4  // micro sec
+#            if __GNUC__ < 6
+#                define READ_WRITE_START_ADJUST 33  // cycles
+#                define READ_WRITE_WIDTH_ADJUST 3   // cycles
+#            else
+#                define READ_WRITE_START_ADJUST 34  // cycles
+#                define READ_WRITE_WIDTH_ADJUST 7   // cycles
+#            endif
+#        elif SELECT_SOFT_SERIAL_SPEED == 1
+// High speed
+#            define SERIAL_DELAY 6  // micro sec
+#            if __GNUC__ < 6
+#                define READ_WRITE_START_ADJUST 30  // cycles
+#                define READ_WRITE_WIDTH_ADJUST 3   // cycles
+#            else
+#                define READ_WRITE_START_ADJUST 33  // cycles
+#                define READ_WRITE_WIDTH_ADJUST 7   // cycles
+#            endif
+#        elif SELECT_SOFT_SERIAL_SPEED == 2
+// Middle speed
+#            define SERIAL_DELAY 12             // micro sec
+#            define READ_WRITE_START_ADJUST 30  // cycles
+#            if __GNUC__ < 6
+#                define READ_WRITE_WIDTH_ADJUST 3  // cycles
+#            else
+#                define READ_WRITE_WIDTH_ADJUST 7  // cycles
+#            endif
+#        elif SELECT_SOFT_SERIAL_SPEED == 3
+// Low speed
+#            define SERIAL_DELAY 24             // micro sec
+#            define READ_WRITE_START_ADJUST 30  // cycles
+#            if __GNUC__ < 6
+#                define READ_WRITE_WIDTH_ADJUST 3  // cycles
+#            else
+#                define READ_WRITE_WIDTH_ADJUST 7  // cycles
+#            endif
+#        elif SELECT_SOFT_SERIAL_SPEED == 4
+// Very Low speed
+#            define SERIAL_DELAY 36             // micro sec
+#            define READ_WRITE_START_ADJUST 30  // cycles
+#            if __GNUC__ < 6
+#                define READ_WRITE_WIDTH_ADJUST 3  // cycles
+#            else
+#                define READ_WRITE_WIDTH_ADJUST 7  // cycles
+#            endif
+#        elif SELECT_SOFT_SERIAL_SPEED == 5
+// Ultra Low speed
+#            define SERIAL_DELAY 48             // micro sec
+#            define READ_WRITE_START_ADJUST 30  // cycles
+#            if __GNUC__ < 6
+#                define READ_WRITE_WIDTH_ADJUST 3  // cycles
+#            else
+#                define READ_WRITE_WIDTH_ADJUST 7  // cycles
+#            endif
+#        else
+#            error invalid SELECT_SOFT_SERIAL_SPEED value
+#        endif /* SELECT_SOFT_SERIAL_SPEED */
+#    endif     /* SERIAL_DELAY */
+
+#    define SERIAL_DELAY_HALF1 (SERIAL_DELAY / 2)
+#    define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY / 2)
+
+#    define SLAVE_INT_WIDTH_US 1
+#    ifndef SERIAL_USE_MULTI_TRANSACTION
+#        define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
+#    else
+#        define SLAVE_INT_ACK_WIDTH_UNIT 2
+#        define SLAVE_INT_ACK_WIDTH 4
+#    endif
+
+static SSTD_t *Transaction_table      = NULL;
 static uint8_t Transaction_table_size = 0;
 
 inline static void serial_delay(void) ALWAYS_INLINE;
-inline static
-void serial_delay(void) {
-  _delay_us(SERIAL_DELAY);
-}
+inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); }
 
 inline static void serial_delay_half1(void) ALWAYS_INLINE;
-inline static
-void serial_delay_half1(void) {
-  _delay_us(SERIAL_DELAY_HALF1);
-}
+inline static void serial_delay_half1(void) { _delay_us(SERIAL_DELAY_HALF1); }
 
 inline static void serial_delay_half2(void) ALWAYS_INLINE;
-inline static
-void serial_delay_half2(void) {
-  _delay_us(SERIAL_DELAY_HALF2);
-}
+inline static void serial_delay_half2(void) { _delay_us(SERIAL_DELAY_HALF2); }
 
 inline static void serial_output(void) ALWAYS_INLINE;
-inline static
-void serial_output(void) {
-  setPinOutput(SOFT_SERIAL_PIN);
-}
+inline static void serial_output(void) { setPinOutput(SOFT_SERIAL_PIN); }
 
 // make the serial pin an input with pull-up resistor
 inline static void serial_input_with_pullup(void) ALWAYS_INLINE;
-inline static
-void serial_input_with_pullup(void) {
-  setPinInputHigh(SOFT_SERIAL_PIN);
-}
+inline static void serial_input_with_pullup(void) { setPinInputHigh(SOFT_SERIAL_PIN); }
 
 inline static uint8_t serial_read_pin(void) ALWAYS_INLINE;
-inline static
-uint8_t serial_read_pin(void) {
-  return !! readPin(SOFT_SERIAL_PIN);
-}
+inline static uint8_t serial_read_pin(void) { return !!readPin(SOFT_SERIAL_PIN); }
 
 inline static void serial_low(void) ALWAYS_INLINE;
-inline static
-void serial_low(void) {
-  writePinLow(SOFT_SERIAL_PIN);
-}
+inline static void serial_low(void) { writePinLow(SOFT_SERIAL_PIN); }
 
 inline static void serial_high(void) ALWAYS_INLINE;
-inline static
-void serial_high(void) {
-  writePinHigh(SOFT_SERIAL_PIN);
-}
+inline static void serial_high(void) { writePinHigh(SOFT_SERIAL_PIN); }
 
-void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size)
-{
-    Transaction_table = sstd_table;
+void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size) {
+    Transaction_table      = sstd_table;
     Transaction_table_size = (uint8_t)sstd_table_size;
     serial_output();
     serial_high();
 }
 
-void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size)
-{
-    Transaction_table = sstd_table;
+void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size) {
+    Transaction_table      = sstd_table;
     Transaction_table_size = (uint8_t)sstd_table_size;
     serial_input_with_pullup();
 
     // Enable INT0-INT3,INT6
     EIMSK |= EIMSK_BIT;
-#if SOFT_SERIAL_PIN == E6
+#    if SOFT_SERIAL_PIN == E6
     // Trigger on falling edge of INT6
     EICRB &= EICRx_BIT;
-#else
+#    else
     // Trigger on falling edge of INT0-INT3
     EICRA &= EICRx_BIT;
-#endif
+#    endif
 }
 
 // Used by the sender to synchronize timing with the reciver.
 static void sync_recv(void) NO_INLINE;
-static
-void sync_recv(void) {
-  for (uint8_t i = 0; i < SERIAL_DELAY*5 && serial_read_pin(); i++ ) {
-  }
-  // This shouldn't hang if the target disconnects because the
-  // serial line will float to high if the target does disconnect.
-  while (!serial_read_pin());
+static void sync_recv(void) {
+    for (uint8_t i = 0; i < SERIAL_DELAY * 5 && serial_read_pin(); i++) {
+    }
+    // This shouldn't hang if the target disconnects because the
+    // serial line will float to high if the target does disconnect.
+    while (!serial_read_pin())
+        ;
 }
 
 // Used by the reciver to send a synchronization signal to the sender.
 static void sync_send(void) NO_INLINE;
-static
-void sync_send(void) {
-  serial_low();
-  serial_delay();
-  serial_high();
+static void sync_send(void) {
+    serial_low();
+    serial_delay();
+    serial_high();
 }
 
 // Reads a byte from the serial line
@@ -274,92 +246,94 @@ static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) NO_INLINE;
 static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) {
     uint8_t byte, i, p, pb;
 
-  _delay_sub_us(READ_WRITE_START_ADJUST);
-  for( i = 0, byte = 0, p = PARITY; i < bit; i++ ) {
-      serial_delay_half1();   // read the middle of pulses
-      if( serial_read_pin() ) {
-          byte = (byte << 1) | 1; p ^= 1;
-      } else {
-          byte = (byte << 1) | 0; p ^= 0;
-      }
-      _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
-      serial_delay_half2();
-  }
-  /* recive parity bit */
-  serial_delay_half1();   // read the middle of pulses
-  pb = serial_read_pin();
-  _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
-  serial_delay_half2();
-
-  *pterrcount += (p != pb)? 1 : 0;
-
-  return byte;
+    _delay_sub_us(READ_WRITE_START_ADJUST);
+    for (i = 0, byte = 0, p = PARITY; i < bit; i++) {
+        serial_delay_half1();  // read the middle of pulses
+        if (serial_read_pin()) {
+            byte = (byte << 1) | 1;
+            p ^= 1;
+        } else {
+            byte = (byte << 1) | 0;
+            p ^= 0;
+        }
+        _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
+        serial_delay_half2();
+    }
+    /* recive parity bit */
+    serial_delay_half1();  // read the middle of pulses
+    pb = serial_read_pin();
+    _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
+    serial_delay_half2();
+
+    *pterrcount += (p != pb) ? 1 : 0;
+
+    return byte;
 }
 
 // Sends a byte with MSB ordering
 void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE;
 void serial_write_chunk(uint8_t data, uint8_t bit) {
     uint8_t b, p;
-    for( p = PARITY, b = 1<<(bit-1); b ; b >>= 1) {
-        if(data & b) {
-            serial_high(); p ^= 1;
+    for (p = PARITY, b = 1 << (bit - 1); b; b >>= 1) {
+        if (data & b) {
+            serial_high();
+            p ^= 1;
         } else {
-            serial_low();  p ^= 0;
+            serial_low();
+            p ^= 0;
         }
         serial_delay();
     }
     /* send parity bit */
-    if(p & 1) { serial_high(); }
-    else      { serial_low(); }
+    if (p & 1) {
+        serial_high();
+    } else {
+        serial_low();
+    }
     serial_delay();
 
-    serial_low(); // sync_send() / senc_recv() need raise edge
+    serial_low();  // sync_send() / senc_recv() need raise edge
 }
 
 static void serial_send_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
-static
-void serial_send_packet(uint8_t *buffer, uint8_t size) {
-  for (uint8_t i = 0; i < size; ++i) {
-    uint8_t data;
-    data = buffer[i];
-    sync_send();
-    serial_write_chunk(data,8);
-  }
+static void serial_send_packet(uint8_t *buffer, uint8_t size) {
+    for (uint8_t i = 0; i < size; ++i) {
+        uint8_t data;
+        data = buffer[i];
+        sync_send();
+        serial_write_chunk(data, 8);
+    }
 }
 
 static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
-static
-uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
-  uint8_t pecount = 0;
-  for (uint8_t i = 0; i < size; ++i) {
-    uint8_t data;
-    sync_recv();
-    data = serial_read_chunk(&pecount, 8);
-    buffer[i] = data;
-  }
-  return pecount == 0;
+static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
+    uint8_t pecount = 0;
+    for (uint8_t i = 0; i < size; ++i) {
+        uint8_t data;
+        sync_recv();
+        data      = serial_read_chunk(&pecount, 8);
+        buffer[i] = data;
+    }
+    return pecount == 0;
 }
 
-inline static
-void change_sender2reciver(void) {
-    sync_send();          //0
-    serial_delay_half1(); //1
-    serial_low();         //2
-    serial_input_with_pullup(); //2
-    serial_delay_half1(); //3
+inline static void change_sender2reciver(void) {
+    sync_send();                 // 0
+    serial_delay_half1();        // 1
+    serial_low();                // 2
+    serial_input_with_pullup();  // 2
+    serial_delay_half1();        // 3
 }
 
-inline static
-void change_reciver2sender(void) {
-    sync_recv();     //0
-    serial_delay();  //1
-    serial_low();    //3
-    serial_output(); //3
-    serial_delay_half1(); //4
+inline static void change_reciver2sender(void) {
+    sync_recv();           // 0
+    serial_delay();        // 1
+    serial_low();          // 3
+    serial_output();       // 3
+    serial_delay_half1();  // 4
 }
 
-static inline uint8_t nibble_bits_count(uint8_t bits)
-{
+static inline uint8_t nibble_bits_count(uint8_t bits) {
     bits = (bits & 0x5) + (bits >> 1 & 0x5);
     bits = (bits & 0x3) + (bits >> 2 & 0x3);
     return bits;
@@ -367,51 +341,47 @@ static inline uint8_t nibble_bits_count(uint8_t bits)
 
 // interrupt handle to be used by the target device
 ISR(SERIAL_PIN_INTERRUPT) {
+#    ifndef SERIAL_USE_MULTI_TRANSACTION
+    serial_low();
+    serial_output();
+    SSTD_t *trans = Transaction_table;
+#    else
+    // recive transaction table index
+    uint8_t tid, bits;
+    uint8_t pecount = 0;
+    sync_recv();
+    bits = serial_read_chunk(&pecount, 7);
+    tid  = bits >> 3;
+    bits = (bits & 7) != nibble_bits_count(tid);
+    if (bits || pecount > 0 || tid > Transaction_table_size) {
+        return;
+    }
+    serial_delay_half1();
 
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-  serial_low();
-  serial_output();
-  SSTD_t *trans = Transaction_table;
-#else
-  // recive transaction table index
-  uint8_t tid, bits;
-  uint8_t pecount = 0;
-  sync_recv();
-  bits = serial_read_chunk(&pecount,7);
-  tid = bits>>3;
-  bits = (bits&7) != nibble_bits_count(tid);
-  if( bits || pecount> 0 || tid > Transaction_table_size ) {
-      return;
-  }
-  serial_delay_half1();
-
-  serial_high(); // response step1 low->high
-  serial_output();
-  _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT*SLAVE_INT_ACK_WIDTH);
-  SSTD_t *trans = &Transaction_table[tid];
-  serial_low(); // response step2 ack high->low
-#endif
+    serial_high();  // response step1 low->high
+    serial_output();
+    _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT * SLAVE_INT_ACK_WIDTH);
+    SSTD_t *trans = &Transaction_table[tid];
+    serial_low();  // response step2 ack high->low
+#    endif
+
+    // target send phase
+    if (trans->target2initiator_buffer_size > 0) serial_send_packet((uint8_t *)trans->target2initiator_buffer, trans->target2initiator_buffer_size);
+    // target switch to input
+    change_sender2reciver();
+
+    // target recive phase
+    if (trans->initiator2target_buffer_size > 0) {
+        if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer, trans->initiator2target_buffer_size)) {
+            *trans->status = TRANSACTION_ACCEPTED;
+        } else {
+            *trans->status = TRANSACTION_DATA_ERROR;
+        }
+    } else {
+        *trans->status = TRANSACTION_ACCEPTED;
+    }
 
-  // target send phase
-  if( trans->target2initiator_buffer_size > 0 )
-      serial_send_packet((uint8_t *)trans->target2initiator_buffer,
-                         trans->target2initiator_buffer_size);
-  // target switch to input
-  change_sender2reciver();
-
-  // target recive phase
-  if( trans->initiator2target_buffer_size > 0 ) {
-      if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer,
-                               trans->initiator2target_buffer_size) ) {
-          *trans->status = TRANSACTION_ACCEPTED;
-      } else {
-          *trans->status = TRANSACTION_DATA_ERROR;
-      }
-  } else {
-      *trans->status = TRANSACTION_ACCEPTED;
-  }
-
-  sync_recv(); //weit initiator output to high
+    sync_recv();  // weit initiator output to high
 }
 
 /////////
@@ -424,105 +394,103 @@ ISR(SERIAL_PIN_INTERRUPT) {
 //    TRANSACTION_NO_RESPONSE
 //    TRANSACTION_DATA_ERROR
 // this code is very time dependent, so we need to disable interrupts
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-int  soft_serial_transaction(void) {
-  SSTD_t *trans = Transaction_table;
-#else
-int  soft_serial_transaction(int sstd_index) {
-  if( sstd_index > Transaction_table_size )
-      return TRANSACTION_TYPE_ERROR;
-  SSTD_t *trans = &Transaction_table[sstd_index];
-#endif
-  cli();
+#    ifndef SERIAL_USE_MULTI_TRANSACTION
+int soft_serial_transaction(void) {
+    SSTD_t *trans = Transaction_table;
+#    else
+int soft_serial_transaction(int sstd_index) {
+    if (sstd_index > Transaction_table_size) return TRANSACTION_TYPE_ERROR;
+    SSTD_t *trans = &Transaction_table[sstd_index];
+#    endif
+    cli();
 
-  // signal to the target that we want to start a transaction
-  serial_output();
-  serial_low();
-  _delay_us(SLAVE_INT_WIDTH_US);
+    // signal to the target that we want to start a transaction
+    serial_output();
+    serial_low();
+    _delay_us(SLAVE_INT_WIDTH_US);
 
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-  // wait for the target response
-  serial_input_with_pullup();
-  _delay_us(SLAVE_INT_RESPONSE_TIME);
+#    ifndef SERIAL_USE_MULTI_TRANSACTION
+    // wait for the target response
+    serial_input_with_pullup();
+    _delay_us(SLAVE_INT_RESPONSE_TIME);
+
+    // check if the target is present
+    if (serial_read_pin()) {
+        // target failed to pull the line low, assume not present
+        serial_output();
+        serial_high();
+        *trans->status = TRANSACTION_NO_RESPONSE;
+        sei();
+        return TRANSACTION_NO_RESPONSE;
+    }
 
-  // check if the target is present
-  if (serial_read_pin()) {
-    // target failed to pull the line low, assume not present
-    serial_output();
-    serial_high();
-    *trans->status = TRANSACTION_NO_RESPONSE;
-    sei();
-    return TRANSACTION_NO_RESPONSE;
-  }
-
-#else
-  // send transaction table index
-  int tid = (sstd_index<<3) | (7 & nibble_bits_count(sstd_index));
-  sync_send();
-  _delay_sub_us(TID_SEND_ADJUST);
-  serial_write_chunk(tid, 7);
-  serial_delay_half1();
-
-  // wait for the target response (step1 low->high)
-  serial_input_with_pullup();
-  while( !serial_read_pin() ) {
-      _delay_sub_us(2);
-  }
-
-  // check if the target is present (step2 high->low)
-  for( int i = 0; serial_read_pin(); i++ ) {
-      if (i > SLAVE_INT_ACK_WIDTH + 1) {
-          // slave failed to pull the line low, assume not present
-          serial_output();
-          serial_high();
-          *trans->status = TRANSACTION_NO_RESPONSE;
-          sei();
-          return TRANSACTION_NO_RESPONSE;
-      }
-      _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
-  }
-#endif
+#    else
+    // send transaction table index
+    int tid = (sstd_index << 3) | (7 & nibble_bits_count(sstd_index));
+    sync_send();
+    _delay_sub_us(TID_SEND_ADJUST);
+    serial_write_chunk(tid, 7);
+    serial_delay_half1();
+
+    // wait for the target response (step1 low->high)
+    serial_input_with_pullup();
+    while (!serial_read_pin()) {
+        _delay_sub_us(2);
+    }
+
+    // check if the target is present (step2 high->low)
+    for (int i = 0; serial_read_pin(); i++) {
+        if (i > SLAVE_INT_ACK_WIDTH + 1) {
+            // slave failed to pull the line low, assume not present
+            serial_output();
+            serial_high();
+            *trans->status = TRANSACTION_NO_RESPONSE;
+            sei();
+            return TRANSACTION_NO_RESPONSE;
+        }
+        _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
+    }
+#    endif
+
+    // initiator recive phase
+    // if the target is present syncronize with it
+    if (trans->target2initiator_buffer_size > 0) {
+        if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer, trans->target2initiator_buffer_size)) {
+            serial_output();
+            serial_high();
+            *trans->status = TRANSACTION_DATA_ERROR;
+            sei();
+            return TRANSACTION_DATA_ERROR;
+        }
+    }
+
+    // initiator switch to output
+    change_reciver2sender();
+
+    // initiator send phase
+    if (trans->initiator2target_buffer_size > 0) {
+        serial_send_packet((uint8_t *)trans->initiator2target_buffer, trans->initiator2target_buffer_size);
+    }
 
-  // initiator recive phase
-  // if the target is present syncronize with it
-  if( trans->target2initiator_buffer_size > 0 ) {
-      if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer,
-                                trans->target2initiator_buffer_size) ) {
-          serial_output();
-          serial_high();
-          *trans->status = TRANSACTION_DATA_ERROR;
-          sei();
-          return TRANSACTION_DATA_ERROR;
-      }
-   }
-
-  // initiator switch to output
-  change_reciver2sender();
-
-  // initiator send phase
-  if( trans->initiator2target_buffer_size > 0 ) {
-      serial_send_packet((uint8_t *)trans->initiator2target_buffer,
-                         trans->initiator2target_buffer_size);
-  }
-
-  // always, release the line when not in use
-  sync_send();
-
-  *trans->status = TRANSACTION_END;
-  sei();
-  return TRANSACTION_END;
+    // always, release the line when not in use
+    sync_send();
+
+    *trans->status = TRANSACTION_END;
+    sei();
+    return TRANSACTION_END;
 }
 
-#ifdef SERIAL_USE_MULTI_TRANSACTION
+#    ifdef SERIAL_USE_MULTI_TRANSACTION
 int soft_serial_get_and_clean_status(int sstd_index) {
     SSTD_t *trans = &Transaction_table[sstd_index];
     cli();
-    int retval = *trans->status;
-    *trans->status = 0;;
+    int retval     = *trans->status;
+    *trans->status = 0;
+    ;
     sei();
     return retval;
 }
-#endif
+#    endif
 
 #endif
 
index 1c1e640069c91e6245946ea3c6a7e3b421223eda..53e66cf905cc33487f76f718f9117b46a7f6a9cc 100644 (file)
 // /////////////////////////////////////////////////////////////////
 
 // Soft Serial Transaction Descriptor
-typedef struct _SSTD_t  {
+typedef struct _SSTD_t {
     uint8_t *status;
-    uint8_t initiator2target_buffer_size;
+    uint8_t  initiator2target_buffer_size;
     uint8_t *initiator2target_buffer;
-    uint8_t target2initiator_buffer_size;
+    uint8_t  target2initiator_buffer_size;
     uint8_t *target2initiator_buffer;
 } SSTD_t;
-#define TID_LIMIT( table ) (sizeof(table) / sizeof(SSTD_t))
+#define TID_LIMIT(table) (sizeof(table) / sizeof(SSTD_t))
 
 // initiator is transaction start side
 void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size);
@@ -39,12 +39,12 @@ void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size);
 // initiator resullt
 #define TRANSACTION_END 0
 #define TRANSACTION_NO_RESPONSE 0x1
-#define TRANSACTION_DATA_ERROR  0x2
-#define TRANSACTION_TYPE_ERROR  0x4
+#define TRANSACTION_DATA_ERROR 0x2
+#define TRANSACTION_TYPE_ERROR 0x4
 #ifndef SERIAL_USE_MULTI_TRANSACTION
-int  soft_serial_transaction(void);
+int soft_serial_transaction(void);
 #else
-int  soft_serial_transaction(int sstd_index);
+int soft_serial_transaction(int sstd_index);
 #endif
 
 // target status
@@ -58,5 +58,5 @@ int  soft_serial_transaction(int sstd_index);
 //    or TRANSACTION_ACCEPTED
 #define TRANSACTION_ACCEPTED 0x8
 #ifdef SERIAL_USE_MULTI_TRANSACTION
-int  soft_serial_get_and_clean_status(int sstd_index);
+int soft_serial_get_and_clean_status(int sstd_index);
 #endif
index d7ed6989f63f6c356e5b7cebd2748064d6293d5f..5114b188ec6ccc43397a44d8bf3e62b76490d022 100644 (file)
@@ -7,87 +7,75 @@
 #include "quantum.h"
 
 #ifdef EE_HANDS
-#   include "tmk_core/common/eeprom.h"
-#   include "eeconfig.h"
+#    include "tmk_core/common/eeprom.h"
+#    include "eeconfig.h"
 #endif
 
 #if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
-#include "rgblight.h"
+#    include "rgblight.h"
 #endif
 
 volatile bool isLeftHand = true;
 
-__attribute__((weak))
-bool is_keyboard_left(void) {
-  #if defined(SPLIT_HAND_PIN)
+__attribute__((weak)) bool is_keyboard_left(void) {
+#if defined(SPLIT_HAND_PIN)
     // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
     setPinInput(SPLIT_HAND_PIN);
     return readPin(SPLIT_HAND_PIN);
-  #elif defined(EE_HANDS)
+#elif defined(EE_HANDS)
     return eeprom_read_byte(EECONFIG_HANDEDNESS);
-  #elif defined(MASTER_RIGHT)
+#elif defined(MASTER_RIGHT)
     return !is_keyboard_master();
-  #endif
+#endif
 
-  return is_keyboard_master();
+    return is_keyboard_master();
 }
 
-__attribute__((weak))
-bool is_keyboard_master(void)
-{
+__attribute__((weak)) bool is_keyboard_master(void) {
 #ifdef __AVR__
-  static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN;
+    static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN;
 
-  // only check once, as this is called often
-  if (usbstate == UNKNOWN)
-  {
-    USBCON |= (1 << OTGPADE);  // enables VBUS pad
-    wait_us(5);
+    // only check once, as this is called often
+    if (usbstate == UNKNOWN) {
+        USBCON |= (1 << OTGPADE);  // enables VBUS pad
+        wait_us(5);
 
-    usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE;  // checks state of VBUS
-  }
+        usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE;  // checks state of VBUS
+    }
 
-  return (usbstate == MASTER);
+    return (usbstate == MASTER);
 #else
-  return true;
+    return true;
 #endif
 }
 
 static void keyboard_master_setup(void) {
 #if defined(USE_I2C) || defined(EH)
-  #ifdef SSD1306OLED
-    matrix_master_OLED_init ();
-  #endif
+#    ifdef SSD1306OLED
+    matrix_master_OLED_init();
+#    endif
 #endif
-  transport_master_init();
+    transport_master_init();
 }
 
-static void keyboard_slave_setup(void)
-{
-  transport_slave_init();
-}
+static void keyboard_slave_setup(void) { transport_slave_init(); }
 
 // this code runs before the usb and keyboard is initialized
-void matrix_setup(void)
-{
-  isLeftHand = is_keyboard_left();
+void matrix_setup(void) {
+    isLeftHand = is_keyboard_left();
 
 #if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
-  uint8_t num_rgb_leds_split[2] = RGBLED_SPLIT;
-  if (isLeftHand) {
-    rgblight_set_clipping_range(0, num_rgb_leds_split[0]);
-  }
-  else {
-    rgblight_set_clipping_range(num_rgb_leds_split[0], num_rgb_leds_split[1]);
-  }
+    uint8_t num_rgb_leds_split[2] = RGBLED_SPLIT;
+    if (isLeftHand) {
+        rgblight_set_clipping_range(0, num_rgb_leds_split[0]);
+    } else {
+        rgblight_set_clipping_range(num_rgb_leds_split[0], num_rgb_leds_split[1]);
+    }
 #endif
 
-  if (is_keyboard_master())
-  {
-    keyboard_master_setup();
-  }
-  else
-  {
-    keyboard_slave_setup();
-  }
+    if (is_keyboard_master()) {
+        keyboard_master_setup();
+    } else {
+        keyboard_slave_setup();
+    }
 }
index 20f7535bf44b975ae3950af6b331c93f8f85d515..f41c77605b1f01a064063c2be9f9c7126e194fc7 100644 (file)
@@ -7,4 +7,4 @@
 
 extern volatile bool isLeftHand;
 
-void matrix_master_OLED_init (void);
+void matrix_master_OLED_init(void);
index ba21d0c7b1db9adea17da1276f4d1d2c4daa3e55..3c783dc568fe1505e97821282c26705704ec83a6 100644 (file)
 #define ROWS_PER_HAND (MATRIX_ROWS / 2)
 
 #ifdef RGBLIGHT_ENABLE
-#  include "rgblight.h"
+#    include "rgblight.h"
 #endif
 
 #ifdef BACKLIGHT_ENABLE
-#  include "backlight.h"
+#    include "backlight.h"
 #endif
 
 #ifdef ENCODER_ENABLE
-#  include "encoder.h"
+#    include "encoder.h"
 static pin_t encoders_pad[] = ENCODERS_PAD_A;
-#  define NUMBER_OF_ENCODERS (sizeof(encoders_pad)/sizeof(pin_t))
+#    define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t))
 #endif
 
 #if defined(USE_I2C) || defined(EH)
 
-#  include "i2c_master.h"
-#  include "i2c_slave.h"
+#    include "i2c_master.h"
+#    include "i2c_slave.h"
 
 typedef struct _I2C_slave_buffer_t {
     matrix_row_t smatrix[ROWS_PER_HAND];
     uint8_t      backlight_level;
-#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+#    if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
     rgblight_syncinfo_t rgblight_sync;
-#endif
-#ifdef ENCODER_ENABLE
+#    endif
+#    ifdef ENCODER_ENABLE
     uint8_t encoder_state[NUMBER_OF_ENCODERS];
-#endif
+#    endif
 } I2C_slave_buffer_t;
 
-static I2C_slave_buffer_t * const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg;
+static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg;
 
-#  define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level)
-#  define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync)
-#  define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix)
-#  define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state)
+#    define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level)
+#    define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync)
+#    define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix)
+#    define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state)
 
-#  define TIMEOUT 100
+#    define TIMEOUT 100
 
-#  ifndef SLAVE_I2C_ADDRESS
-#    define SLAVE_I2C_ADDRESS 0x32
-#  endif
+#    ifndef SLAVE_I2C_ADDRESS
+#        define SLAVE_I2C_ADDRESS 0x32
+#    endif
 
 // Get rows from other half over i2c
 bool transport_master(matrix_row_t matrix[]) {
-  i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_START, (void *)matrix, sizeof(i2c_buffer->smatrix), TIMEOUT);
-
-  // write backlight info
-#  ifdef BACKLIGHT_ENABLE
-  uint8_t level = is_backlight_enabled() ? get_backlight_level() : 0;
-  if (level != i2c_buffer->backlight_level) {
-    if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_BACKLIGHT_START, (void *)&level, sizeof(level), TIMEOUT) >= 0) {
-      i2c_buffer->backlight_level = level;
+    i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_START, (void *)matrix, sizeof(i2c_buffer->smatrix), TIMEOUT);
+
+    // write backlight info
+#    ifdef BACKLIGHT_ENABLE
+    uint8_t level = is_backlight_enabled() ? get_backlight_level() : 0;
+    if (level != i2c_buffer->backlight_level) {
+        if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_BACKLIGHT_START, (void *)&level, sizeof(level), TIMEOUT) >= 0) {
+            i2c_buffer->backlight_level = level;
+        }
     }
-  }
-#  endif
-
-#  if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
-  if (rgblight_get_change_flags()) {
-    rgblight_syncinfo_t rgblight_sync;
-    rgblight_get_syncinfo(&rgblight_sync);
-    if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_START,
-                     (void *)&rgblight_sync, sizeof(rgblight_sync), TIMEOUT) >= 0) {
-      rgblight_clear_change_flags();
+#    endif
+
+#    if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+    if (rgblight_get_change_flags()) {
+        rgblight_syncinfo_t rgblight_sync;
+        rgblight_get_syncinfo(&rgblight_sync);
+        if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_START, (void *)&rgblight_sync, sizeof(rgblight_sync), TIMEOUT) >= 0) {
+            rgblight_clear_change_flags();
+        }
     }
-  }
-#  endif
+#    endif
 
-#  ifdef ENCODER_ENABLE
-  i2c_readReg(SLAVE_I2C_ADDRESS, I2C_ENCODER_START, (void *)i2c_buffer->encoder_state, sizeof(i2c_buffer->encoder_state), TIMEOUT);
-  encoder_update_raw(i2c_buffer->encoder_state);
-#  endif
+#    ifdef ENCODER_ENABLE
+    i2c_readReg(SLAVE_I2C_ADDRESS, I2C_ENCODER_START, (void *)i2c_buffer->encoder_state, sizeof(i2c_buffer->encoder_state), TIMEOUT);
+    encoder_update_raw(i2c_buffer->encoder_state);
+#    endif
 
-  return true;
+    return true;
 }
 
 void transport_slave(matrix_row_t matrix[]) {
-  // Copy matrix to I2C buffer
-  memcpy((void*)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix));
+    // Copy matrix to I2C buffer
+    memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix));
 
 // Read Backlight Info
-#  ifdef BACKLIGHT_ENABLE
-  backlight_set(i2c_buffer->backlight_level);
-#  endif
-
-#  if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
-  // Update the RGB with the new data
-  if (i2c_buffer->rgblight_sync.status.change_flags != 0) {
-      rgblight_update_sync(&i2c_buffer->rgblight_sync, false);
-      i2c_buffer->rgblight_sync.status.change_flags = 0;
-  }
-#  endif
-
-#  ifdef ENCODER_ENABLE
-  encoder_state_raw(i2c_buffer->encoder_state);
-#  endif
+#    ifdef BACKLIGHT_ENABLE
+    backlight_set(i2c_buffer->backlight_level);
+#    endif
+
+#    if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+    // Update the RGB with the new data
+    if (i2c_buffer->rgblight_sync.status.change_flags != 0) {
+        rgblight_update_sync(&i2c_buffer->rgblight_sync, false);
+        i2c_buffer->rgblight_sync.status.change_flags = 0;
+    }
+#    endif
+
+#    ifdef ENCODER_ENABLE
+    encoder_state_raw(i2c_buffer->encoder_state);
+#    endif
 }
 
 void transport_master_init(void) { i2c_init(); }
@@ -111,25 +110,25 @@ void transport_slave_init(void) { i2c_slave_init(SLAVE_I2C_ADDRESS); }
 
 #else  // USE_SERIAL
 
-#  include "serial.h"
+#    include "serial.h"
 
 typedef struct _Serial_s2m_buffer_t {
-  // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
-  matrix_row_t smatrix[ROWS_PER_HAND];
+    // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
+    matrix_row_t smatrix[ROWS_PER_HAND];
 
-#  ifdef ENCODER_ENABLE
-  uint8_t encoder_state[NUMBER_OF_ENCODERS];
-#  endif
+#    ifdef ENCODER_ENABLE
+    uint8_t      encoder_state[NUMBER_OF_ENCODERS];
+#    endif
 
 } Serial_s2m_buffer_t;
 
 typedef struct _Serial_m2s_buffer_t {
-#  ifdef BACKLIGHT_ENABLE
-  uint8_t           backlight_level;
-#  endif
+#    ifdef BACKLIGHT_ENABLE
+    uint8_t backlight_level;
+#    endif
 } Serial_m2s_buffer_t;
 
-#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+#    if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
 // When MCUs on both sides drive their respective RGB LED chains,
 // it is necessary to synchronize, so it is necessary to communicate RGB
 // information. In that case, define RGBLIGHT_SPLIT with info on the number
@@ -144,7 +143,7 @@ typedef struct _Serial_rgblight_t {
 
 volatile Serial_rgblight_t serial_rgblight = {};
 uint8_t volatile status_rgblight           = 0;
-#endif
+#    endif
 
 volatile Serial_s2m_buffer_t serial_s2m_buffer = {};
 volatile Serial_m2s_buffer_t serial_m2s_buffer = {};
@@ -152,102 +151,99 @@ uint8_t volatile status0                       = 0;
 
 enum serial_transaction_id {
     GET_SLAVE_MATRIX = 0,
-#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+#    if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
     PUT_RGBLIGHT,
-#endif
+#    endif
 };
 
 SSTD_t transactions[] = {
-    [GET_SLAVE_MATRIX] = {
-        (uint8_t *)&status0,
-        sizeof(serial_m2s_buffer),
-        (uint8_t *)&serial_m2s_buffer,
-        sizeof(serial_s2m_buffer),
-        (uint8_t *)&serial_s2m_buffer,
-    },
-#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
-    [PUT_RGBLIGHT] = {
-        (uint8_t *)&status_rgblight,
-        sizeof(serial_rgblight),
-        (uint8_t *)&serial_rgblight,
-        0, NULL // no slave to master transfer
-    },
-#endif
+    [GET_SLAVE_MATRIX] =
+        {
+            (uint8_t *)&status0,
+            sizeof(serial_m2s_buffer),
+            (uint8_t *)&serial_m2s_buffer,
+            sizeof(serial_s2m_buffer),
+            (uint8_t *)&serial_s2m_buffer,
+        },
+#    if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+    [PUT_RGBLIGHT] =
+        {
+            (uint8_t *)&status_rgblight, sizeof(serial_rgblight), (uint8_t *)&serial_rgblight, 0, NULL  // no slave to master transfer
+        },
+#    endif
 };
 
 void transport_master_init(void) { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); }
 
 void transport_slave_init(void) { soft_serial_target_init(transactions, TID_LIMIT(transactions)); }
 
-#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+#    if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
 
 // rgblight synchronization information communication.
 
 void transport_rgblight_master(void) {
-  if (rgblight_get_change_flags()) {
-    rgblight_get_syncinfo((rgblight_syncinfo_t *)&serial_rgblight.rgblight_sync);
-    if (soft_serial_transaction(PUT_RGBLIGHT) == TRANSACTION_END) {
-        rgblight_clear_change_flags();
+    if (rgblight_get_change_flags()) {
+        rgblight_get_syncinfo((rgblight_syncinfo_t *)&serial_rgblight.rgblight_sync);
+        if (soft_serial_transaction(PUT_RGBLIGHT) == TRANSACTION_END) {
+            rgblight_clear_change_flags();
+        }
     }
-  }
 }
 
 void transport_rgblight_slave(void) {
-  if (status_rgblight == TRANSACTION_ACCEPTED) {
-    rgblight_update_sync((rgblight_syncinfo_t *)&serial_rgblight.rgblight_sync,
-                         false);
-    status_rgblight = TRANSACTION_END;
-  }
+    if (status_rgblight == TRANSACTION_ACCEPTED) {
+        rgblight_update_sync((rgblight_syncinfo_t *)&serial_rgblight.rgblight_sync, false);
+        status_rgblight = TRANSACTION_END;
+    }
 }
 
-#else
-#define transport_rgblight_master()
-#define transport_rgblight_slave()
-#endif
+#    else
+#        define transport_rgblight_master()
+#        define transport_rgblight_slave()
+#    endif
 
 bool transport_master(matrix_row_t matrix[]) {
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-  if (soft_serial_transaction() != TRANSACTION_END) {
-    return false;
-  }
-#else
-  transport_rgblight_master();
-  if (soft_serial_transaction(GET_SLAVE_MATRIX) != TRANSACTION_END) {
-    return false;
-  }
-#endif
+#    ifndef SERIAL_USE_MULTI_TRANSACTION
+    if (soft_serial_transaction() != TRANSACTION_END) {
+        return false;
+    }
+#    else
+    transport_rgblight_master();
+    if (soft_serial_transaction(GET_SLAVE_MATRIX) != TRANSACTION_END) {
+        return false;
+    }
+#    endif
 
-  // TODO:  if MATRIX_COLS > 8 change to unpack()
-  for (int i = 0; i < ROWS_PER_HAND; ++i) {
-    matrix[i] = serial_s2m_buffer.smatrix[i];
-  }
+    // TODO:  if MATRIX_COLS > 8 change to unpack()
+    for (int i = 0; i < ROWS_PER_HAND; ++i) {
+        matrix[i] = serial_s2m_buffer.smatrix[i];
+    }
 
-#  ifdef BACKLIGHT_ENABLE
-  // Write backlight level for slave to read
-  serial_m2s_buffer.backlight_level = is_backlight_enabled() ? get_backlight_level() : 0;
-#  endif
+#    ifdef BACKLIGHT_ENABLE
+    // Write backlight level for slave to read
+    serial_m2s_buffer.backlight_level = is_backlight_enabled() ? get_backlight_level() : 0;
+#    endif
 
-#  ifdef ENCODER_ENABLE
-  encoder_update_raw((uint8_t *)serial_s2m_buffer.encoder_state);
-#  endif
+#    ifdef ENCODER_ENABLE
+    encoder_update_raw((uint8_t *)serial_s2m_buffer.encoder_state);
+#    endif
 
-  return true;
+    return true;
 }
 
 void transport_slave(matrix_row_t matrix[]) {
-  transport_rgblight_slave();
-  // TODO: if MATRIX_COLS > 8 change to pack()
-  for (int i = 0; i < ROWS_PER_HAND; ++i) {
-    serial_s2m_buffer.smatrix[i] = matrix[i];
-  }
-#  ifdef BACKLIGHT_ENABLE
-  backlight_set(serial_m2s_buffer.backlight_level);
-#  endif
-
-#  ifdef ENCODER_ENABLE
-  encoder_state_raw((uint8_t *)serial_s2m_buffer.encoder_state);
-#  endif
+    transport_rgblight_slave();
+    // TODO: if MATRIX_COLS > 8 change to pack()
+    for (int i = 0; i < ROWS_PER_HAND; ++i) {
+        serial_s2m_buffer.smatrix[i] = matrix[i];
+    }
+#    ifdef BACKLIGHT_ENABLE
+    backlight_set(serial_m2s_buffer.backlight_level);
+#    endif
 
+#    ifdef ENCODER_ENABLE
+    encoder_state_raw((uint8_t *)serial_s2m_buffer.encoder_state);
+#    endif
 }
 
 #endif
index 1d9f12ff1f8b7c4f5c9b982481beb4b11dbaaf1a..f7b1b077d3580e7e41c21a6bce4ae70071811e03 100644 (file)
@@ -26,9 +26,9 @@
  */
 
 #ifndef CHCONF_H
-#define CHCONF_H
+#    define CHCONF_H
 
-#define _CHIBIOS_RT_CONF_
+#    define _CHIBIOS_RT_CONF_
 
 /*===========================================================================*/
 /**
  * @brief   System time counter resolution.
  * @note    Allowed values are 16 or 32 bits.
  */
-#define CH_CFG_ST_RESOLUTION                32
+#    define CH_CFG_ST_RESOLUTION 32
 
 /**
  * @brief   System tick frequency.
  * @details Frequency of the system timer that drives the system ticks. This
  *          setting also defines the system tick time unit.
  */
-#define CH_CFG_ST_FREQUENCY                 100000
+#    define CH_CFG_ST_FREQUENCY 100000
 
 /**
  * @brief   Time delta constant for the tick-less mode.
@@ -58,7 +58,7 @@
  *          The value one is not valid, timeouts are rounded up to
  *          this value.
  */
-#define CH_CFG_ST_TIMEDELTA                 2
+#    define CH_CFG_ST_TIMEDELTA 2
 
 /** @} */
 
@@ -81,7 +81,7 @@
  * @note    The round robin preemption is not supported in tickless mode and
  *          must be set to zero in that case.
  */
-#define CH_CFG_TIME_QUANTUM                 0
+#    define CH_CFG_TIME_QUANTUM 0
 
 /**
  * @brief   Managed RAM size.
@@ -94,7 +94,7 @@
  *          provide the @p __heap_base__ and @p __heap_end__ symbols.
  * @note    Requires @p CH_CFG_USE_MEMCORE.
  */
-#define CH_CFG_MEMCORE_SIZE                 0
+#    define CH_CFG_MEMCORE_SIZE 0
 
 /**
  * @brief   Idle thread automatic spawn suppression.
  *          function becomes the idle thread and must implement an
  *          infinite loop.
  */
-#define CH_CFG_NO_IDLE_THREAD               FALSE
+#    define CH_CFG_NO_IDLE_THREAD FALSE
 
 /** @} */
 
  * @note    This is not related to the compiler optimization options.
  * @note    The default is @p TRUE.
  */
-#define CH_CFG_OPTIMIZE_SPEED               TRUE
+#    define CH_CFG_OPTIMIZE_SPEED TRUE
 
 /** @} */
 
  *
  * @note    The default is @p TRUE.
  */
-#define CH_CFG_USE_TM                       TRUE
+#    define CH_CFG_USE_TM TRUE
 
 /**
  * @brief   Threads registry APIs.
  *
  * @note    The default is @p TRUE.
  */
-#define CH_CFG_USE_REGISTRY                 TRUE
+#    define CH_CFG_USE_REGISTRY TRUE
 
 /**
  * @brief   Threads synchronization APIs.
  *
  * @note    The default is @p TRUE.
  */
-#define CH_CFG_USE_WAITEXIT                 TRUE
+#    define CH_CFG_USE_WAITEXIT TRUE
 
 /**
  * @brief   Semaphores APIs.
  *
  * @note    The default is @p TRUE.
  */
-#define CH_CFG_USE_SEMAPHORES               TRUE
+#    define CH_CFG_USE_SEMAPHORES TRUE
 
 /**
  * @brief   Semaphores queuing mode.
  *          requirements.
  * @note    Requires @p CH_CFG_USE_SEMAPHORES.
  */
-#define CH_CFG_USE_SEMAPHORES_PRIORITY      FALSE
+#    define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
 
 /**
  * @brief   Mutexes APIs.
  *
  * @note    The default is @p TRUE.
  */
-#define CH_CFG_USE_MUTEXES                  TRUE
+#    define CH_CFG_USE_MUTEXES TRUE
 
 /**
  * @brief   Enables recursive behavior on mutexes.
  * @note    The default is @p FALSE.
  * @note    Requires @p CH_CFG_USE_MUTEXES.
  */
-#define CH_CFG_USE_MUTEXES_RECURSIVE        FALSE
+#    define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
 
 /**
  * @brief   Conditional Variables APIs.
  * @note    The default is @p TRUE.
  * @note    Requires @p CH_CFG_USE_MUTEXES.
  */
-#define CH_CFG_USE_CONDVARS                 TRUE
+#    define CH_CFG_USE_CONDVARS TRUE
 
 /**
  * @brief   Conditional Variables APIs with timeout.
  * @note    The default is @p TRUE.
  * @note    Requires @p CH_CFG_USE_CONDVARS.
  */
-#define CH_CFG_USE_CONDVARS_TIMEOUT         TRUE
+#    define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
 
 /**
  * @brief   Events Flags APIs.
  *
  * @note    The default is @p TRUE.
  */
-#define CH_CFG_USE_EVENTS                   TRUE
+#    define CH_CFG_USE_EVENTS TRUE
 
 /**
  * @brief   Events Flags APIs with timeout.
  * @note    The default is @p TRUE.
  * @note    Requires @p CH_CFG_USE_EVENTS.
  */
-#define CH_CFG_USE_EVENTS_TIMEOUT           TRUE
+#    define CH_CFG_USE_EVENTS_TIMEOUT TRUE
 
 /**
  * @brief   Synchronous Messages APIs.
  *
  * @note    The default is @p TRUE.
  */
-#define CH_CFG_USE_MESSAGES                 TRUE
+#    define CH_CFG_USE_MESSAGES TRUE
 
 /**
  * @brief   Synchronous Messages queuing mode.
  *          requirements.
  * @note    Requires @p CH_CFG_USE_MESSAGES.
  */
-#define CH_CFG_USE_MESSAGES_PRIORITY        TRUE
+#    define CH_CFG_USE_MESSAGES_PRIORITY TRUE
 
 /**
  * @brief   Mailboxes APIs.
  * @note    The default is @p TRUE.
  * @note    Requires @p CH_CFG_USE_SEMAPHORES.
  */
-#define CH_CFG_USE_MAILBOXES                TRUE
+#    define CH_CFG_USE_MAILBOXES TRUE
 
 /**
  * @brief   Core Memory Manager APIs.
  *
  * @note    The default is @p TRUE.
  */
-#define CH_CFG_USE_MEMCORE                  TRUE
+#    define CH_CFG_USE_MEMCORE TRUE
 
 /**
  * @brief   Heap Allocator APIs.
  *          @p CH_CFG_USE_SEMAPHORES.
  * @note    Mutexes are recommended.
  */
-#define CH_CFG_USE_HEAP                     TRUE
+#    define CH_CFG_USE_HEAP TRUE
 
 /**
  * @brief   Memory Pools Allocator APIs.
  *
  * @note    The default is @p TRUE.
  */
-#define CH_CFG_USE_MEMPOOLS                 TRUE
+#    define CH_CFG_USE_MEMPOOLS TRUE
 
 /**
  * @brief   Dynamic Threads APIs.
  * @note    Requires @p CH_CFG_USE_WAITEXIT.
  * @note    Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
  */
-#define CH_CFG_USE_DYNAMIC                  TRUE
+#    define CH_CFG_USE_DYNAMIC TRUE
 
 /** @} */
 
  *
  * @note    The default is @p FALSE.
  */
-#define CH_DBG_STATISTICS                   FALSE
+#    define CH_DBG_STATISTICS FALSE
 
 /**
  * @brief   Debug option, system state check.
  *
  * @note    The default is @p FALSE.
  */
-#define CH_DBG_SYSTEM_STATE_CHECK           FALSE
+#    define CH_DBG_SYSTEM_STATE_CHECK FALSE
 
 /**
  * @brief   Debug option, parameters checks.
  *
  * @note    The default is @p FALSE.
  */
-#define CH_DBG_ENABLE_CHECKS                FALSE
+#    define CH_DBG_ENABLE_CHECKS FALSE
 
 /**
  * @brief   Debug option, consistency checks.
  *
  * @note    The default is @p FALSE.
  */
-#define CH_DBG_ENABLE_ASSERTS               FALSE
+#    define CH_DBG_ENABLE_ASSERTS FALSE
 
 /**
  * @brief   Debug option, trace buffer.
  *
  * @note    The default is @p CH_DBG_TRACE_MASK_DISABLED.
  */
-#define CH_DBG_TRACE_MASK                   CH_DBG_TRACE_MASK_DISABLED
+#    define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
 
 /**
  * @brief   Trace buffer entries.
  * @note    The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
  *          different from @p CH_DBG_TRACE_MASK_DISABLED.
  */
-#define CH_DBG_TRACE_BUFFER_SIZE            128
+#    define CH_DBG_TRACE_BUFFER_SIZE 128
 
 /**
  * @brief   Debug option, stack checks.
  * @note    The default failure mode is to halt the system with the global
  *          @p panic_msg variable set to @p NULL.
  */
-#define CH_DBG_ENABLE_STACK_CHECK           TRUE
+#    define CH_DBG_ENABLE_STACK_CHECK TRUE
 
 /**
  * @brief   Debug option, stacks initialization.
  *
  * @note    The default is @p FALSE.
  */
-#define CH_DBG_FILL_THREADS                 FALSE
+#    define CH_DBG_FILL_THREADS FALSE
 
 /**
  * @brief   Debug option, threads profiling.
  * @note    This debug option is not currently compatible with the
  *          tickless mode.
  */
-#define CH_DBG_THREADS_PROFILING            FALSE
+#    define CH_DBG_THREADS_PROFILING FALSE
 
 /** @} */
 
  * @brief   Threads descriptor structure extension.
  * @details User fields added to the end of the @p thread_t structure.
  */
-#define CH_CFG_THREAD_EXTRA_FIELDS                                          \
-  /* Add threads custom fields here.*/
+#    define CH_CFG_THREAD_EXTRA_FIELDS /* Add threads custom fields here.*/
 
 /**
  * @brief   Threads initialization hook.
  * @note    It is invoked from within @p chThdInit() and implicitly from all
  *          the threads creation APIs.
  */
-#define CH_CFG_THREAD_INIT_HOOK(tp) {                                       \
-  /* Add threads initialization code here.*/                                \
-}
+#    define CH_CFG_THREAD_INIT_HOOK(tp) \
+        { /* Add threads initialization code here.*/ }
 
 /**
  * @brief   Threads finalization hook.
  * @details User finalization code added to the @p chThdExit() API.
  */
-#define CH_CFG_THREAD_EXIT_HOOK(tp) {                                       \
-  /* Add threads finalization code here.*/                                  \
-}
+#    define CH_CFG_THREAD_EXIT_HOOK(tp) \
+        { /* Add threads finalization code here.*/ }
 
 /**
  * @brief   Context switch hook.
  * @details This hook is invoked just before switching between threads.
  */
-#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) {                              \
-  /* Context switch code here.*/                                            \
-}
+#    define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) \
+        { /* Context switch code here.*/ }
 
 /**
  * @brief   ISR enter hook.
  */
-#define CH_CFG_IRQ_PROLOGUE_HOOK() {                                        \
-  /* IRQ prologue code here.*/                                              \
-}
+#    define CH_CFG_IRQ_PROLOGUE_HOOK() \
+        { /* IRQ prologue code here.*/ }
 
 /**
  * @brief   ISR exit hook.
  */
-#define CH_CFG_IRQ_EPILOGUE_HOOK() {                                        \
-  /* IRQ epilogue code here.*/                                              \
-}
+#    define CH_CFG_IRQ_EPILOGUE_HOOK() \
+        { /* IRQ epilogue code here.*/ }
 
 /**
  * @brief   Idle thread enter hook.
  *          should be invoked from here.
  * @note    This macro can be used to activate a power saving mode.
  */
-#define CH_CFG_IDLE_ENTER_HOOK() {                                          \
-  /* Idle-enter code here.*/                                                \
-}
+#    define CH_CFG_IDLE_ENTER_HOOK() \
+        { /* Idle-enter code here.*/ }
 
 /**
  * @brief   Idle thread leave hook.
  *          should be invoked from here.
  * @note    This macro can be used to deactivate a power saving mode.
  */
-#define CH_CFG_IDLE_LEAVE_HOOK() {                                          \
-  /* Idle-leave code here.*/                                                \
-}
+#    define CH_CFG_IDLE_LEAVE_HOOK() \
+        { /* Idle-leave code here.*/ }
 
 /**
  * @brief   Idle Loop hook.
  * @details This hook is continuously invoked by the idle thread loop.
  */
-#define CH_CFG_IDLE_LOOP_HOOK() {                                           \
-  /* Idle loop code here.*/                                                 \
-}
+#    define CH_CFG_IDLE_LOOP_HOOK() \
+        { /* Idle loop code here.*/ }
 
 /**
  * @brief   System tick event hook.
  * @details This hook is invoked in the system tick handler immediately
  *          after processing the virtual timers queue.
  */
-#define CH_CFG_SYSTEM_TICK_HOOK() {                                         \
-  /* System tick event code here.*/                                         \
-}
+#    define CH_CFG_SYSTEM_TICK_HOOK() \
+        { /* System tick event code here.*/ }
 
 /**
  * @brief   System halt hook.
  * @details This hook is invoked in case to a system halting error before
  *          the system is halted.
  */
-#define CH_CFG_SYSTEM_HALT_HOOK(reason) {                                   \
-  /* System halt code here.*/                                               \
-}
+#    define CH_CFG_SYSTEM_HALT_HOOK(reason) \
+        { /* System halt code here.*/ }
 
 /**
  * @brief   Trace hook.
  * @details This hook is invoked each time a new record is written in the
  *          trace buffer.
  */
-#define CH_CFG_TRACE_HOOK(tep) {                                            \
-  /* Trace code here.*/                                                     \
-}
+#    define CH_CFG_TRACE_HOOK(tep) \
+        { /* Trace code here.*/ }
 
 /** @} */
 
 /* Port-specific settings (override port settings defaulted in chcore.h).    */
 /*===========================================================================*/
 
-#endif  /* CHCONF_H */
+#endif /* CHCONF_H */
 
 /** @} */
index a14ace02b4b075fff1937a8834f2d1816e898c8f..72e011d3dc6b3f1c413428e53ae10c5c60b48f0e 100644 (file)
  */
 
 #ifndef HALCONF_H
-#define HALCONF_H
+#    define HALCONF_H
 
-#include "mcuconf.h"
+#    include "mcuconf.h"
 
 /**
  * @brief   Enables the PAL subsystem.
  */
-#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
-#define HAL_USE_PAL                 TRUE
-#endif
+#    if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
+#        define HAL_USE_PAL TRUE
+#    endif
 
 /**
  * @brief   Enables the ADC subsystem.
  */
-#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
-#define HAL_USE_ADC                 FALSE
-#endif
+#    if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
+#        define HAL_USE_ADC FALSE
+#    endif
 
 /**
  * @brief   Enables the CAN subsystem.
  */
-#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
-#define HAL_USE_CAN                 FALSE
-#endif
+#    if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
+#        define HAL_USE_CAN FALSE
+#    endif
 
 /**
  * @brief   Enables the DAC subsystem.
  */
-#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)
-#define HAL_USE_DAC                 TRUE
-#endif
+#    if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)
+#        define HAL_USE_DAC TRUE
+#    endif
 
 /**
  * @brief   Enables the EXT subsystem.
  */
-#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
-#define HAL_USE_EXT                 FALSE
-#endif
+#    if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
+#        define HAL_USE_EXT FALSE
+#    endif
 
 /**
  * @brief   Enables the GPT subsystem.
  */
-#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
-#define HAL_USE_GPT                 TRUE
-#endif
+#    if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
+#        define HAL_USE_GPT TRUE
+#    endif
 
 /**
  * @brief   Enables the I2C subsystem.
  */
-#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
-#define HAL_USE_I2C                 TRUE
-#endif
+#    if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
+#        define HAL_USE_I2C TRUE
+#    endif
 
 /**
  * @brief   Enables the I2S subsystem.
  */
-#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
-#define HAL_USE_I2S                 FALSE
-#endif
+#    if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
+#        define HAL_USE_I2S FALSE
+#    endif
 
 /**
  * @brief   Enables the ICU subsystem.
  */
-#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
-#define HAL_USE_ICU                 FALSE
-#endif
+#    if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
+#        define HAL_USE_ICU FALSE
+#    endif
 
 /**
  * @brief   Enables the MAC subsystem.
  */
-#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
-#define HAL_USE_MAC                 FALSE
-#endif
+#    if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
+#        define HAL_USE_MAC FALSE
+#    endif
 
 /**
  * @brief   Enables the MMC_SPI subsystem.
  */
-#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
-#define HAL_USE_MMC_SPI             FALSE
-#endif
+#    if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
+#        define HAL_USE_MMC_SPI FALSE
+#    endif
 
 /**
  * @brief   Enables the PWM subsystem.
  */
-#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
-#define HAL_USE_PWM                 TRUE
-#endif
+#    if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
+#        define HAL_USE_PWM TRUE
+#    endif
 
 /**
  * @brief   Enables the QSPI subsystem.
  */
-#if !defined(HAL_USE_QSPI) || defined(__DOXYGEN__)
-#define HAL_USE_QSPI                FALSE
-#endif
+#    if !defined(HAL_USE_QSPI) || defined(__DOXYGEN__)
+#        define HAL_USE_QSPI FALSE
+#    endif
 
 /**
  * @brief   Enables the RTC subsystem.
  */
-#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
-#define HAL_USE_RTC                 FALSE
-#endif
+#    if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
+#        define HAL_USE_RTC FALSE
+#    endif
 
 /**
  * @brief   Enables the SDC subsystem.
  */
-#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
-#define HAL_USE_SDC                 FALSE
-#endif
+#    if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
+#        define HAL_USE_SDC FALSE
+#    endif
 
 /**
  * @brief   Enables the SERIAL subsystem.
  */
-#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL              FALSE
-#endif
+#    if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
+#        define HAL_USE_SERIAL FALSE
+#    endif
 
 /**
  * @brief   Enables the SERIAL over USB subsystem.
  */
-#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL_USB          TRUE
-#endif
+#    if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
+#        define HAL_USE_SERIAL_USB TRUE
+#    endif
 
 /**
  * @brief   Enables the SPI subsystem.
  */
-#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
-#define HAL_USE_SPI                 FALSE
-#endif
+#    if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
+#        define HAL_USE_SPI FALSE
+#    endif
 
 /**
  * @brief   Enables the UART subsystem.
  */
-#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
-#define HAL_USE_UART                FALSE
-#endif
+#    if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
+#        define HAL_USE_UART FALSE
+#    endif
 
 /**
  * @brief   Enables the USB subsystem.
  */
-#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
-#define HAL_USE_USB                 TRUE
-#endif
+#    if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
+#        define HAL_USE_USB TRUE
+#    endif
 
 /**
  * @brief   Enables the WDG subsystem.
  */
-#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__)
-#define HAL_USE_WDG                 FALSE
-#endif
+#    if !defined(HAL_USE_WDG) || defined(__DOXYGEN__)
+#        define HAL_USE_WDG FALSE
+#    endif
 
 /*===========================================================================*/
 /* ADC driver related settings.                                              */
  * @brief   Enables synchronous APIs.
  * @note    Disabling this option saves both code and data space.
  */
-#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
-#define ADC_USE_WAIT                TRUE
-#endif
+#    if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
+#        define ADC_USE_WAIT TRUE
+#    endif
 
 /**
  * @brief   Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.
  * @note    Disabling this option saves both code and data space.
  */
-#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define ADC_USE_MUTUAL_EXCLUSION    TRUE
-#endif
+#    if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#        define ADC_USE_MUTUAL_EXCLUSION TRUE
+#    endif
 
 /*===========================================================================*/
 /* CAN driver related settings.                                              */
 /**
  * @brief   Sleep mode related APIs inclusion switch.
  */
-#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
-#define CAN_USE_SLEEP_MODE          TRUE
-#endif
+#    if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
+#        define CAN_USE_SLEEP_MODE TRUE
+#    endif
 
 /*===========================================================================*/
 /* I2C driver related settings.                                              */
 /**
  * @brief   Enables the mutual exclusion APIs on the I2C bus.
  */
-#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define I2C_USE_MUTUAL_EXCLUSION    TRUE
-#endif
+#    if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#        define I2C_USE_MUTUAL_EXCLUSION TRUE
+#    endif
 
 /*===========================================================================*/
 /* MAC driver related settings.                                              */
 /**
  * @brief   Enables an event sources for incoming packets.
  */
-#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
-#define MAC_USE_ZERO_COPY           FALSE
-#endif
+#    if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
+#        define MAC_USE_ZERO_COPY FALSE
+#    endif
 
 /**
  * @brief   Enables an event sources for incoming packets.
  */
-#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
-#define MAC_USE_EVENTS              TRUE
-#endif
+#    if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
+#        define MAC_USE_EVENTS TRUE
+#    endif
 
 /*===========================================================================*/
 /* MMC_SPI driver related settings.                                          */
  *          This option is recommended also if the SPI driver does not
  *          use a DMA channel and heavily loads the CPU.
  */
-#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
-#define MMC_NICE_WAITING            TRUE
-#endif
+#    if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
+#        define MMC_NICE_WAITING TRUE
+#    endif
 
 /*===========================================================================*/
 /* SDC driver related settings.                                              */
  * @brief   Number of initialization attempts before rejecting the card.
  * @note    Attempts are performed at 10mS intervals.
  */
-#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
-#define SDC_INIT_RETRY              100
-#endif
+#    if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
+#        define SDC_INIT_RETRY 100
+#    endif
 
 /**
  * @brief   Include support for MMC cards.
  * @note    MMC support is not yet implemented so this option must be kept
  *          at @p FALSE.
  */
-#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
-#define SDC_MMC_SUPPORT             FALSE
-#endif
+#    if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
+#        define SDC_MMC_SUPPORT FALSE
+#    endif
 
 /**
  * @brief   Delays insertions.
  *          routines releasing some extra CPU time for the threads with
  *          lower priority, this may slow down the driver a bit however.
  */
-#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
-#define SDC_NICE_WAITING            TRUE
-#endif
+#    if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
+#        define SDC_NICE_WAITING TRUE
+#    endif
 
 /*===========================================================================*/
 /* SERIAL driver related settings.                                           */
  * @details Configuration parameter, this is the baud rate selected for the
  *          default configuration.
  */
-#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
-#define SERIAL_DEFAULT_BITRATE      38400
-#endif
+#    if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
+#        define SERIAL_DEFAULT_BITRATE 38400
+#    endif
 
 /**
  * @brief   Serial buffers size.
  * @note    The default is 16 bytes for both the transmission and receive
  *          buffers.
  */
-#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_BUFFERS_SIZE         16
-#endif
+#    if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
+#        define SERIAL_BUFFERS_SIZE 16
+#    endif
 
 /*===========================================================================*/
 /* SERIAL_USB driver related setting.                                        */
  * @note    The default is 256 bytes for both the transmission and receive
  *          buffers.
  */
-#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_USB_BUFFERS_SIZE     1
-#endif
+#    if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
+#        define SERIAL_USB_BUFFERS_SIZE 1
+#    endif
 
 /**
  * @brief   Serial over USB number of buffers.
  * @note    The default is 2 buffers.
  */
-#if !defined(SERIAL_USB_BUFFERS_NUMBER) || defined(__DOXYGEN__)
-#define SERIAL_USB_BUFFERS_NUMBER   2
-#endif
+#    if !defined(SERIAL_USB_BUFFERS_NUMBER) || defined(__DOXYGEN__)
+#        define SERIAL_USB_BUFFERS_NUMBER 2
+#    endif
 
 /*===========================================================================*/
 /* SPI driver related settings.                                              */
  * @brief   Enables synchronous APIs.
  * @note    Disabling this option saves both code and data space.
  */
-#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
-#define SPI_USE_WAIT                TRUE
-#endif
+#    if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
+#        define SPI_USE_WAIT TRUE
+#    endif
 
 /**
  * @brief   Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.
  * @note    Disabling this option saves both code and data space.
  */
-#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define SPI_USE_MUTUAL_EXCLUSION    TRUE
-#endif
+#    if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#        define SPI_USE_MUTUAL_EXCLUSION TRUE
+#    endif
 
 /*===========================================================================*/
 /* UART driver related settings.                                             */
  * @brief   Enables synchronous APIs.
  * @note    Disabling this option saves both code and data space.
  */
-#if !defined(UART_USE_WAIT) || defined(__DOXYGEN__)
-#define UART_USE_WAIT               FALSE
-#endif
+#    if !defined(UART_USE_WAIT) || defined(__DOXYGEN__)
+#        define UART_USE_WAIT FALSE
+#    endif
 
 /**
  * @brief   Enables the @p uartAcquireBus() and @p uartReleaseBus() APIs.
  * @note    Disabling this option saves both code and data space.
  */
-#if !defined(UART_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define UART_USE_MUTUAL_EXCLUSION   FALSE
-#endif
+#    if !defined(UART_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#        define UART_USE_MUTUAL_EXCLUSION FALSE
+#    endif
 
 /*===========================================================================*/
 /* USB driver related settings.                                              */
  * @brief   Enables synchronous APIs.
  * @note    Disabling this option saves both code and data space.
  */
-#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)
-#define USB_USE_WAIT                TRUE
-#endif
+#    if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)
+#        define USB_USE_WAIT TRUE
+#    endif
 
 #endif /* HALCONF_H */
 
index 32a73fb38eaea6d046e011e28957d27d8c52844f..4490dfed7e475d556ca34a47aacd53e364b25b2e 100644 (file)
 /*
  * HAL driver system settings.
  */
-#define STM32_NO_INIT                       FALSE
-#define STM32_PVD_ENABLE                    FALSE
-#define STM32_PLS                           STM32_PLS_LEV0
-#define STM32_HSI_ENABLED                   TRUE
-#define STM32_LSI_ENABLED                   TRUE
-#define STM32_HSE_ENABLED                   TRUE
-#define STM32_LSE_ENABLED                   FALSE
-#define STM32_SW                            STM32_SW_PLL
-#define STM32_PLLSRC                        STM32_PLLSRC_HSE
-#define STM32_PREDIV_VALUE                  1
-#define STM32_PLLMUL_VALUE                  9
-#define STM32_HPRE                          STM32_HPRE_DIV1
-#define STM32_PPRE1                         STM32_PPRE1_DIV2
-#define STM32_PPRE2                         STM32_PPRE2_DIV2
-#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK
-#define STM32_ADC12PRES                     STM32_ADC12PRES_DIV1
-#define STM32_ADC34PRES                     STM32_ADC34PRES_DIV1
-#define STM32_USART1SW                      STM32_USART1SW_PCLK
-#define STM32_USART2SW                      STM32_USART2SW_PCLK
-#define STM32_USART3SW                      STM32_USART3SW_PCLK
-#define STM32_UART4SW                       STM32_UART4SW_PCLK
-#define STM32_UART5SW                       STM32_UART5SW_PCLK
-#define STM32_I2C1SW                        STM32_I2C1SW_SYSCLK
-#define STM32_I2C2SW                        STM32_I2C2SW_SYSCLK
-#define STM32_TIM1SW                        STM32_TIM1SW_PCLK2
-#define STM32_TIM8SW                        STM32_TIM8SW_PCLK2
-#define STM32_RTCSEL                        STM32_RTCSEL_LSI
-#define STM32_USB_CLOCK_REQUIRED            TRUE
-#define STM32_USBPRE                        STM32_USBPRE_DIV1P5
+#define STM32_NO_INIT FALSE
+#define STM32_PVD_ENABLE FALSE
+#define STM32_PLS STM32_PLS_LEV0
+#define STM32_HSI_ENABLED TRUE
+#define STM32_LSI_ENABLED TRUE
+#define STM32_HSE_ENABLED TRUE
+#define STM32_LSE_ENABLED FALSE
+#define STM32_SW STM32_SW_PLL
+#define STM32_PLLSRC STM32_PLLSRC_HSE
+#define STM32_PREDIV_VALUE 1
+#define STM32_PLLMUL_VALUE 9
+#define STM32_HPRE STM32_HPRE_DIV1
+#define STM32_PPRE1 STM32_PPRE1_DIV2
+#define STM32_PPRE2 STM32_PPRE2_DIV2
+#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
+#define STM32_ADC12PRES STM32_ADC12PRES_DIV1
+#define STM32_ADC34PRES STM32_ADC34PRES_DIV1
+#define STM32_USART1SW STM32_USART1SW_PCLK
+#define STM32_USART2SW STM32_USART2SW_PCLK
+#define STM32_USART3SW STM32_USART3SW_PCLK
+#define STM32_UART4SW STM32_UART4SW_PCLK
+#define STM32_UART5SW STM32_UART5SW_PCLK
+#define STM32_I2C1SW STM32_I2C1SW_SYSCLK
+#define STM32_I2C2SW STM32_I2C2SW_SYSCLK
+#define STM32_TIM1SW STM32_TIM1SW_PCLK2
+#define STM32_TIM8SW STM32_TIM8SW_PCLK2
+#define STM32_RTCSEL STM32_RTCSEL_LSI
+#define STM32_USB_CLOCK_REQUIRED TRUE
+#define STM32_USBPRE STM32_USBPRE_DIV1P5
 
 #undef STM32_HSE_BYPASS
 // #error "oh no"
 /*
  * ADC driver system settings.
  */
-#define STM32_ADC_DUAL_MODE                 FALSE
-#define STM32_ADC_COMPACT_SAMPLES           FALSE
-#define STM32_ADC_USE_ADC1                  FALSE
-#define STM32_ADC_USE_ADC2                  FALSE
-#define STM32_ADC_USE_ADC3                  FALSE
-#define STM32_ADC_USE_ADC4                  FALSE
-#define STM32_ADC_ADC1_DMA_STREAM           STM32_DMA_STREAM_ID(1, 1)
-#define STM32_ADC_ADC2_DMA_STREAM           STM32_DMA_STREAM_ID(2, 1)
-#define STM32_ADC_ADC3_DMA_STREAM           STM32_DMA_STREAM_ID(2, 5)
-#define STM32_ADC_ADC4_DMA_STREAM           STM32_DMA_STREAM_ID(2, 2)
-#define STM32_ADC_ADC1_DMA_PRIORITY         2
-#define STM32_ADC_ADC2_DMA_PRIORITY         2
-#define STM32_ADC_ADC3_DMA_PRIORITY         2
-#define STM32_ADC_ADC4_DMA_PRIORITY         2
-#define STM32_ADC_ADC12_IRQ_PRIORITY        5
-#define STM32_ADC_ADC3_IRQ_PRIORITY         5
-#define STM32_ADC_ADC4_IRQ_PRIORITY         5
-#define STM32_ADC_ADC1_DMA_IRQ_PRIORITY     5
-#define STM32_ADC_ADC2_DMA_IRQ_PRIORITY     5
-#define STM32_ADC_ADC3_DMA_IRQ_PRIORITY     5
-#define STM32_ADC_ADC4_DMA_IRQ_PRIORITY     5
-#define STM32_ADC_ADC12_CLOCK_MODE          ADC_CCR_CKMODE_AHB_DIV1
-#define STM32_ADC_ADC34_CLOCK_MODE          ADC_CCR_CKMODE_AHB_DIV1
+#define STM32_ADC_DUAL_MODE FALSE
+#define STM32_ADC_COMPACT_SAMPLES FALSE
+#define STM32_ADC_USE_ADC1 FALSE
+#define STM32_ADC_USE_ADC2 FALSE
+#define STM32_ADC_USE_ADC3 FALSE
+#define STM32_ADC_USE_ADC4 FALSE
+#define STM32_ADC_ADC1_DMA_STREAM STM32_DMA_STREAM_ID(1, 1)
+#define STM32_ADC_ADC2_DMA_STREAM STM32_DMA_STREAM_ID(2, 1)
+#define STM32_ADC_ADC3_DMA_STREAM STM32_DMA_STREAM_ID(2, 5)
+#define STM32_ADC_ADC4_DMA_STREAM STM32_DMA_STREAM_ID(2, 2)
+#define STM32_ADC_ADC1_DMA_PRIORITY 2
+#define STM32_ADC_ADC2_DMA_PRIORITY 2
+#define STM32_ADC_ADC3_DMA_PRIORITY 2
+#define STM32_ADC_ADC4_DMA_PRIORITY 2
+#define STM32_ADC_ADC12_IRQ_PRIORITY 5
+#define STM32_ADC_ADC3_IRQ_PRIORITY 5
+#define STM32_ADC_ADC4_IRQ_PRIORITY 5
+#define STM32_ADC_ADC1_DMA_IRQ_PRIORITY 5
+#define STM32_ADC_ADC2_DMA_IRQ_PRIORITY 5
+#define STM32_ADC_ADC3_DMA_IRQ_PRIORITY 5
+#define STM32_ADC_ADC4_DMA_IRQ_PRIORITY 5
+#define STM32_ADC_ADC12_CLOCK_MODE ADC_CCR_CKMODE_AHB_DIV1
+#define STM32_ADC_ADC34_CLOCK_MODE ADC_CCR_CKMODE_AHB_DIV1
 
 /*
  * CAN driver system settings.
  */
-#define STM32_CAN_USE_CAN1                  FALSE
-#define STM32_CAN_CAN1_IRQ_PRIORITY         11
+#define STM32_CAN_USE_CAN1 FALSE
+#define STM32_CAN_CAN1_IRQ_PRIORITY 11
 
 /*
  * DAC driver system settings.
  */
-#define STM32_DAC_DUAL_MODE                 FALSE
-#define STM32_DAC_USE_DAC1_CH1              TRUE
-#define STM32_DAC_USE_DAC1_CH2              TRUE
-#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY     10
-#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY     10
-#define STM32_DAC_DAC1_CH1_DMA_PRIORITY     2
-#define STM32_DAC_DAC1_CH2_DMA_PRIORITY     2
+#define STM32_DAC_DUAL_MODE FALSE
+#define STM32_DAC_USE_DAC1_CH1 TRUE
+#define STM32_DAC_USE_DAC1_CH2 TRUE
+#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY 10
+#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY 10
+#define STM32_DAC_DAC1_CH1_DMA_PRIORITY 2
+#define STM32_DAC_DAC1_CH2_DMA_PRIORITY 2
 
 /*
  * EXT driver system settings.
  */
-#define STM32_EXT_EXTI0_IRQ_PRIORITY        6
-#define STM32_EXT_EXTI1_IRQ_PRIORITY        6
-#define STM32_EXT_EXTI2_IRQ_PRIORITY        6
-#define STM32_EXT_EXTI3_IRQ_PRIORITY        6
-#define STM32_EXT_EXTI4_IRQ_PRIORITY        6
-#define STM32_EXT_EXTI5_9_IRQ_PRIORITY      6
-#define STM32_EXT_EXTI10_15_IRQ_PRIORITY    6
-#define STM32_EXT_EXTI16_IRQ_PRIORITY       6
-#define STM32_EXT_EXTI17_IRQ_PRIORITY       6
-#define STM32_EXT_EXTI18_IRQ_PRIORITY       6
-#define STM32_EXT_EXTI19_IRQ_PRIORITY       6
-#define STM32_EXT_EXTI20_IRQ_PRIORITY       6
+#define STM32_EXT_EXTI0_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI1_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI2_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI3_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI4_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI5_9_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI10_15_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI16_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI17_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI18_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI19_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI20_IRQ_PRIORITY 6
 #define STM32_EXT_EXTI21_22_29_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI30_32_IRQ_PRIORITY    6
-#define STM32_EXT_EXTI33_IRQ_PRIORITY       6
+#define STM32_EXT_EXTI30_32_IRQ_PRIORITY 6
+#define STM32_EXT_EXTI33_IRQ_PRIORITY 6
 
 /*
  * GPT driver system settings.
  */
-#define STM32_GPT_USE_TIM1                  FALSE
-#define STM32_GPT_USE_TIM2                  FALSE
-#define STM32_GPT_USE_TIM3                  FALSE
-#define STM32_GPT_USE_TIM4                  FALSE
-#define STM32_GPT_USE_TIM6                  TRUE
-#define STM32_GPT_USE_TIM7                  TRUE
-#define STM32_GPT_USE_TIM8                  TRUE
-#define STM32_GPT_TIM1_IRQ_PRIORITY         7
-#define STM32_GPT_TIM2_IRQ_PRIORITY         7
-#define STM32_GPT_TIM3_IRQ_PRIORITY         7
-#define STM32_GPT_TIM4_IRQ_PRIORITY         7
-#define STM32_GPT_TIM6_IRQ_PRIORITY         7
-#define STM32_GPT_TIM7_IRQ_PRIORITY         7
-#define STM32_GPT_TIM8_IRQ_PRIORITY         7
+#define STM32_GPT_USE_TIM1 FALSE
+#define STM32_GPT_USE_TIM2 FALSE
+#define STM32_GPT_USE_TIM3 FALSE
+#define STM32_GPT_USE_TIM4 FALSE
+#define STM32_GPT_USE_TIM6 TRUE
+#define STM32_GPT_USE_TIM7 TRUE
+#define STM32_GPT_USE_TIM8 TRUE
+#define STM32_GPT_TIM1_IRQ_PRIORITY 7
+#define STM32_GPT_TIM2_IRQ_PRIORITY 7
+#define STM32_GPT_TIM3_IRQ_PRIORITY 7
+#define STM32_GPT_TIM4_IRQ_PRIORITY 7
+#define STM32_GPT_TIM6_IRQ_PRIORITY 7
+#define STM32_GPT_TIM7_IRQ_PRIORITY 7
+#define STM32_GPT_TIM8_IRQ_PRIORITY 7
 
 /*
  * I2C driver system settings.
  */
-#define STM32_I2C_USE_I2C1                  TRUE
-#define STM32_I2C_USE_I2C2                  FALSE
-#define STM32_I2C_BUSY_TIMEOUT              50
-#define STM32_I2C_I2C1_IRQ_PRIORITY         10
-#define STM32_I2C_I2C2_IRQ_PRIORITY         10
-#define STM32_I2C_USE_DMA                   TRUE
-#define STM32_I2C_I2C1_DMA_PRIORITY         1
-#define STM32_I2C_I2C2_DMA_PRIORITY         1
-#define STM32_I2C_DMA_ERROR_HOOK(i2cp)      osalSysHalt("DMA failure")
+#define STM32_I2C_USE_I2C1 TRUE
+#define STM32_I2C_USE_I2C2 FALSE
+#define STM32_I2C_BUSY_TIMEOUT 50
+#define STM32_I2C_I2C1_IRQ_PRIORITY 10
+#define STM32_I2C_I2C2_IRQ_PRIORITY 10
+#define STM32_I2C_USE_DMA TRUE
+#define STM32_I2C_I2C1_DMA_PRIORITY 1
+#define STM32_I2C_I2C2_DMA_PRIORITY 1
+#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
 
 /*
  * ICU driver system settings.
  */
-#define STM32_ICU_USE_TIM1                  FALSE
-#define STM32_ICU_USE_TIM2                  FALSE
-#define STM32_ICU_USE_TIM3                  FALSE
-#define STM32_ICU_USE_TIM4                  FALSE
-#define STM32_ICU_USE_TIM8                  FALSE
-#define STM32_ICU_TIM1_IRQ_PRIORITY         7
-#define STM32_ICU_TIM2_IRQ_PRIORITY         7
-#define STM32_ICU_TIM3_IRQ_PRIORITY         7
-#define STM32_ICU_TIM4_IRQ_PRIORITY         7
-#define STM32_ICU_TIM8_IRQ_PRIORITY         7
+#define STM32_ICU_USE_TIM1 FALSE
+#define STM32_ICU_USE_TIM2 FALSE
+#define STM32_ICU_USE_TIM3 FALSE
+#define STM32_ICU_USE_TIM4 FALSE
+#define STM32_ICU_USE_TIM8 FALSE
+#define STM32_ICU_TIM1_IRQ_PRIORITY 7
+#define STM32_ICU_TIM2_IRQ_PRIORITY 7
+#define STM32_ICU_TIM3_IRQ_PRIORITY 7
+#define STM32_ICU_TIM4_IRQ_PRIORITY 7
+#define STM32_ICU_TIM8_IRQ_PRIORITY 7
 
 /*
  * PWM driver system settings.
  */
-#define STM32_PWM_USE_ADVANCED              FALSE
-#define STM32_PWM_USE_TIM1                  FALSE
-#define STM32_PWM_USE_TIM2                  FALSE
-#define STM32_PWM_USE_TIM3                  TRUE
-#define STM32_PWM_USE_TIM4                  TRUE
-#define STM32_PWM_USE_TIM8                  FALSE
-#define STM32_PWM_TIM1_IRQ_PRIORITY         7
-#define STM32_PWM_TIM2_IRQ_PRIORITY         7
-#define STM32_PWM_TIM3_IRQ_PRIORITY         7
-#define STM32_PWM_TIM4_IRQ_PRIORITY         7
-#define STM32_PWM_TIM8_IRQ_PRIORITY         7
+#define STM32_PWM_USE_ADVANCED FALSE
+#define STM32_PWM_USE_TIM1 FALSE
+#define STM32_PWM_USE_TIM2 FALSE
+#define STM32_PWM_USE_TIM3 TRUE
+#define STM32_PWM_USE_TIM4 TRUE
+#define STM32_PWM_USE_TIM8 FALSE
+#define STM32_PWM_TIM1_IRQ_PRIORITY 7
+#define STM32_PWM_TIM2_IRQ_PRIORITY 7
+#define STM32_PWM_TIM3_IRQ_PRIORITY 7
+#define STM32_PWM_TIM4_IRQ_PRIORITY 7
+#define STM32_PWM_TIM8_IRQ_PRIORITY 7
 
 /*
  * SERIAL driver system settings.
  */
-#define STM32_SERIAL_USE_USART1             FALSE
-#define STM32_SERIAL_USE_USART2             TRUE
-#define STM32_SERIAL_USE_USART3             FALSE
-#define STM32_SERIAL_USE_UART4              FALSE
-#define STM32_SERIAL_USE_UART5              FALSE
-#define STM32_SERIAL_USART1_PRIORITY        12
-#define STM32_SERIAL_USART2_PRIORITY        12
-#define STM32_SERIAL_USART3_PRIORITY        12
-#define STM32_SERIAL_UART4_PRIORITY         12
-#define STM32_SERIAL_UART5_PRIORITY         12
+#define STM32_SERIAL_USE_USART1 FALSE
+#define STM32_SERIAL_USE_USART2 TRUE
+#define STM32_SERIAL_USE_USART3 FALSE
+#define STM32_SERIAL_USE_UART4 FALSE
+#define STM32_SERIAL_USE_UART5 FALSE
+#define STM32_SERIAL_USART1_PRIORITY 12
+#define STM32_SERIAL_USART2_PRIORITY 12
+#define STM32_SERIAL_USART3_PRIORITY 12
+#define STM32_SERIAL_UART4_PRIORITY 12
+#define STM32_SERIAL_UART5_PRIORITY 12
 
 /*
  * SPI driver system settings.
  */
-#define STM32_SPI_USE_SPI1                  FALSE
-#define STM32_SPI_USE_SPI2                  FALSE
-#define STM32_SPI_USE_SPI3                  FALSE
-#define STM32_SPI_SPI1_DMA_PRIORITY         1
-#define STM32_SPI_SPI2_DMA_PRIORITY         1
-#define STM32_SPI_SPI3_DMA_PRIORITY         1
-#define STM32_SPI_SPI1_IRQ_PRIORITY         10
-#define STM32_SPI_SPI2_IRQ_PRIORITY         10
-#define STM32_SPI_SPI3_IRQ_PRIORITY         10
-#define STM32_SPI_DMA_ERROR_HOOK(spip)      osalSysHalt("DMA failure")
+#define STM32_SPI_USE_SPI1 FALSE
+#define STM32_SPI_USE_SPI2 FALSE
+#define STM32_SPI_USE_SPI3 FALSE
+#define STM32_SPI_SPI1_DMA_PRIORITY 1
+#define STM32_SPI_SPI2_DMA_PRIORITY 1
+#define STM32_SPI_SPI3_DMA_PRIORITY 1
+#define STM32_SPI_SPI1_IRQ_PRIORITY 10
+#define STM32_SPI_SPI2_IRQ_PRIORITY 10
+#define STM32_SPI_SPI3_IRQ_PRIORITY 10
+#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
 
 /*
  * ST driver system settings.
  */
-#define STM32_ST_IRQ_PRIORITY               8
-#define STM32_ST_USE_TIMER                  2
+#define STM32_ST_IRQ_PRIORITY 8
+#define STM32_ST_USE_TIMER 2
 
 /*
  * UART driver system settings.
  */
-#define STM32_UART_USE_USART1               FALSE
-#define STM32_UART_USE_USART2               FALSE
-#define STM32_UART_USE_USART3               FALSE
-#define STM32_UART_USART1_IRQ_PRIORITY      12
-#define STM32_UART_USART2_IRQ_PRIORITY      12
-#define STM32_UART_USART3_IRQ_PRIORITY      12
-#define STM32_UART_USART1_DMA_PRIORITY      0
-#define STM32_UART_USART2_DMA_PRIORITY      0
-#define STM32_UART_USART3_DMA_PRIORITY      0
-#define STM32_UART_DMA_ERROR_HOOK(uartp)    osalSysHalt("DMA failure")
+#define STM32_UART_USE_USART1 FALSE
+#define STM32_UART_USE_USART2 FALSE
+#define STM32_UART_USE_USART3 FALSE
+#define STM32_UART_USART1_IRQ_PRIORITY 12
+#define STM32_UART_USART2_IRQ_PRIORITY 12
+#define STM32_UART_USART3_IRQ_PRIORITY 12
+#define STM32_UART_USART1_DMA_PRIORITY 0
+#define STM32_UART_USART2_DMA_PRIORITY 0
+#define STM32_UART_USART3_DMA_PRIORITY 0
+#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
 
 /*
  * USB driver system settings.
  */
-#define STM32_USB_USE_USB1                  TRUE
-#define STM32_USB_LOW_POWER_ON_SUSPEND      FALSE
-#define STM32_USB_USB1_HP_IRQ_PRIORITY      13
-#define STM32_USB_USB1_LP_IRQ_PRIORITY      14
+#define STM32_USB_USE_USB1 TRUE
+#define STM32_USB_LOW_POWER_ON_SUSPEND FALSE
+#define STM32_USB_USB1_HP_IRQ_PRIORITY 13
+#define STM32_USB_USB1_LP_IRQ_PRIORITY 14
 
 /*
  * WDG driver system settings.
  */
-#define STM32_WDG_USE_IWDG                  FALSE
+#define STM32_WDG_USE_IWDG FALSE
 
 #endif /* MCUCONF_H */
index 0fc7cf9cb91cffe15b8643d7642349c63bce4c34..713d6be3a505c0025bc0d1001b3e992e6b422b18 100644 (file)
@@ -20,12 +20,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "config_common.h"
 
 /* USB Device descriptor parameter */
-#define VENDOR_ID       0xFEED
-#define PRODUCT_ID      0x0000
-#define DEVICE_VER      0x0001
-#define MANUFACTURER    %YOUR_NAME%
-#define PRODUCT         %KEYBOARD%
-#define DESCRIPTION     A custom keyboard
+#define VENDOR_ID 0xFEED
+#define PRODUCT_ID 0x0000
+#define DEVICE_VER 0x0001
+#define MANUFACTURER % YOUR_NAME %
+#define PRODUCT % KEYBOARD %
+#define DESCRIPTION A custom keyboard
 
 /* key matrix size */
 #define MATRIX_ROWS 2
@@ -40,9 +40,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
  *                  ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
  *
-*/
-#define MATRIX_ROW_PINS { D0, D5 }
-#define MATRIX_COL_PINS { F1, F0, B0 }
+ */
+#define MATRIX_ROW_PINS \
+    { D0, D5 }
+#define MATRIX_COL_PINS \
+    { F1, F0, B0 }
 #define UNUSED_PINS
 
 /* COL2ROW, ROW2COL*/
@@ -51,7 +53,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /*
  * Split Keyboard specific options, make sure you have 'SPLIT_KEYBOARD = yes' in your rules.mk, and define SOFT_SERIAL_PIN.
  */
-#define SOFT_SERIAL_PIN D0 // or D1, D2, D3, E6
+#define SOFT_SERIAL_PIN D0  // or D1, D2, D3, E6
 
 // #define BACKLIGHT_PIN B7
 // #define BACKLIGHT_BREATHING
index 5eeedd45ef9f06c7228a408a5a89bd8b86522d81..308cb92a7760df0a8728e169154dea43fe72a0ac 100644 (file)
 #include QMK_KEYBOARD_H
 
 // Defines the keycodes used by our macros in process_record_user
-enum custom_keycodes {
-  QMKBEST = SAFE_RANGE,
-  QMKURL
-};
+enum custom_keycodes { QMKBEST = SAFE_RANGE, QMKURL };
 
 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
-  [0] = LAYOUT( /* Base */
-    KC_A,  KC_1,  KC_H,
-      KC_TAB,  KC_SPC
-  ),
+    [0] = LAYOUT(/* Base */
+                 KC_A, KC_1, KC_H, KC_TAB, KC_SPC),
 };
 
 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
-  switch (keycode) {
-    case QMKBEST:
-      if (record->event.pressed) {
-        // when keycode QMKBEST is pressed
-        SEND_STRING("QMK is the best thing ever!");
-      } else {
-        // when keycode QMKBEST is released
-      }
-      break;
-    case QMKURL:
-      if (record->event.pressed) {
-        // when keycode QMKURL is pressed
-        SEND_STRING("https://qmk.fm/" SS_TAP(X_ENTER));
-      } else {
-        // when keycode QMKURL is released
-      }
-      break;
-  }
-  return true;
+    switch (keycode) {
+        case QMKBEST:
+            if (record->event.pressed) {
+                // when keycode QMKBEST is pressed
+                SEND_STRING("QMK is the best thing ever!");
+            } else {
+                // when keycode QMKBEST is released
+            }
+            break;
+        case QMKURL:
+            if (record->event.pressed) {
+                // when keycode QMKURL is pressed
+                SEND_STRING("https://qmk.fm/" SS_TAP(X_ENTER));
+            } else {
+                // when keycode QMKURL is released
+            }
+            break;
+    }
+    return true;
 }
 
-void matrix_init_user(void) {
-
-}
+void matrix_init_user(void) {}
 
-void matrix_scan_user(void) {
+void matrix_scan_user(void) {}
 
-}
-
-void led_set_user(uint8_t usb_led) {
-
-}
+void led_set_user(uint8_t usb_led) {}
index 2e531b1fd42b071550239946fd017747a8c6f62e..595da73c60e3f038d55d96814e5680985780e90c 100644 (file)
  * The second converts the arguments into a two-dimensional array which
  * represents the switch matrix.
  */
-#define LAYOUT( \
-    k00, k01, k02, \
-      k10,  k11   \
-) \
-{ \
-    { k00, k01,   k02 }, \
-    { k10, KC_NO, k11 }, \
-}
+#define LAYOUT(k00, k01, k02, k10, k11) \
+    { {k00, k01, k02}, {k10, KC_NO, k11}, }
index 3ab841d745597c0e831bd0f15c5057a349e4728f..a780a10afc397df83be6b7729c4fed604df71938 100644 (file)
@@ -19,22 +19,25 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "config_common.h"
 
-#define VENDOR_ID       0x20A0
-#define PRODUCT_ID      0x422D
-#define DEVICE_VER      0x0001
-#define MANUFACTURER    You
-#define PRODUCT         %KEYBOARD%
-#define DESCRIPTION     A custom keyboard
+#define VENDOR_ID 0x20A0
+#define PRODUCT_ID 0x422D
+#define DEVICE_VER 0x0001
+#define MANUFACTURER You
+#define PRODUCT % KEYBOARD %
+#define DESCRIPTION A custom keyboard
 
 #define RGBLED_NUM 16
 
 #define MATRIX_ROWS 8
 #define MATRIX_COLS 11
 
-#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
-#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5 }
+#define MATRIX_ROW_PINS \
+    { B0, B1, B2, B3, B4, B5, B6, B7 }
+#define MATRIX_COL_PINS \
+    { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5 }
 // #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, C1, C0, D7 }
-#define UNUSED_PINS     {}
+#define UNUSED_PINS \
+    {}
 
 #define DIODE_DIRECTION COL2ROW
 #define DEBOUNCE 5
index 07f27bbb2296027ca4de47dda6c3dd72a568326e..efc8517485f4a74b63981b10c8b828486d46fb4c 100644 (file)
 
 #ifdef RGBLIGHT_ENABLE
 
-#include <string.h>
-#include "i2c_master.h"
-#include "rgblight.h"
+#    include <string.h>
+#    include "i2c_master.h"
+#    include "rgblight.h"
 
 extern rgblight_config_t rgblight_config;
 
 void matrix_init_kb(void) {
-  i2c_init();
-  // call user level keymaps, if any
-  matrix_init_user();
+    i2c_init();
+    // call user level keymaps, if any
+    matrix_init_user();
 }
 
 // custom RGB driver
 void rgblight_set(void) {
-  if (!rgblight_config.enable) {
-    memset(led, 0, 3 * RGBLED_NUM);
-  }
+    if (!rgblight_config.enable) {
+        memset(led, 0, 3 * RGBLED_NUM);
+    }
 
-  i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
+    i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
 }
 
 bool rgb_init = false;
 
 void matrix_scan_kb(void) {
-  // if LEDs were previously on before poweroff, turn them back on
-  if (rgb_init == false && rgblight_config.enable) {
-    i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
-    rgb_init = true;
-  }
-
-  rgblight_task();
-  matrix_scan_user();
+    // if LEDs were previously on before poweroff, turn them back on
+    if (rgb_init == false && rgblight_config.enable) {
+        i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
+        rgb_init = true;
+    }
+
+    rgblight_task();
+    matrix_scan_user();
 }
 
 #endif
index 465db3a134178ee63ef9ed39a4e0cd93b025ba7d..9ef232f045f2ac9fa2a86d93dbc52f6415bf408f 100644 (file)
@@ -14,15 +14,15 @@ section at the end of this file).
 
 /* ---------------------------- Hardware Config ---------------------------- */
 
-#define USB_CFG_IOPORTNAME      D
+#define USB_CFG_IOPORTNAME D
 /* This is the port where the USB bus is connected. When you configure it to
  * "B", the registers PORTB, PINB and DDRB will be used.
  */
-#define USB_CFG_DMINUS_BIT      3
+#define USB_CFG_DMINUS_BIT 3
 /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
  * This may be any bit in the port.
  */
-#define USB_CFG_DPLUS_BIT       2
+#define USB_CFG_DPLUS_BIT 2
 /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
  * This may be any bit in the port. Please note that D+ must also be connected
  * to interrupt pin INT0! [You can also use other interrupts, see section
@@ -31,7 +31,7 @@ section at the end of this file).
  * interrupt, the USB interrupt will also be triggered at Start-Of-Frame
  * markers every millisecond.]
  */
-#define USB_CFG_CLOCK_KHZ       (F_CPU/1000)
+#define USB_CFG_CLOCK_KHZ (F_CPU / 1000)
 /* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000,
  * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code
  * require no crystal, they tolerate +/- 1% deviation from the nominal
@@ -40,7 +40,7 @@ section at the end of this file).
  * Since F_CPU should be defined to your actual clock rate anyway, you should
  * not need to modify this setting.
  */
-#define USB_CFG_CHECK_CRC       0
+#define USB_CFG_CHECK_CRC 0
 /* Define this to 1 if you want that the driver checks integrity of incoming
  * data packets (CRC checks). CRC checks cost quite a bit of code size and are
  * currently only available for 18 MHz crystal clock. You must choose
@@ -63,18 +63,18 @@ section at the end of this file).
 
 /* --------------------------- Functional Range ---------------------------- */
 
-#define USB_CFG_HAVE_INTRIN_ENDPOINT    1
+#define USB_CFG_HAVE_INTRIN_ENDPOINT 1
 /* Define this to 1 if you want to compile a version with two endpoints: The
  * default control endpoint 0 and an interrupt-in endpoint (any other endpoint
  * number).
  */
-#define USB_CFG_HAVE_INTRIN_ENDPOINT3   1
+#define USB_CFG_HAVE_INTRIN_ENDPOINT3 1
 /* Define this to 1 if you want to compile a version with three endpoints: The
  * default control endpoint 0, an interrupt-in endpoint 3 (or the number
  * configured below) and a catch-all default interrupt-in endpoint as above.
  * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
  */
-#define USB_CFG_EP3_NUMBER              3
+#define USB_CFG_EP3_NUMBER 3
 /* If the so-called endpoint 3 is used, it can now be configured to any other
  * endpoint number (except 0) with this macro. Default if undefined is 3.
  */
@@ -84,13 +84,13 @@ section at the end of this file).
  * Since the token is toggled BEFORE sending any data, the first packet is
  * sent with the oposite value of this configuration!
  */
-#define USB_CFG_IMPLEMENT_HALT          0
+#define USB_CFG_IMPLEMENT_HALT 0
 /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
  * for endpoint 1 (interrupt endpoint). Although you may not need this feature,
  * it is required by the standard. We have made it a config option because it
  * bloats the code considerably.
  */
-#define USB_CFG_SUPPRESS_INTR_CODE      0
+#define USB_CFG_SUPPRESS_INTR_CODE 0
 /* Define this to 1 if you want to declare interrupt-in endpoints, but don't
  * want to send any data over them. If this macro is defined to 1, functions
  * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
@@ -98,48 +98,48 @@ section at the end of this file).
  * (e.g. HID), but never want to send any data. This option saves a couple
  * of bytes in flash memory and the transmit buffers in RAM.
  */
-#define USB_CFG_INTR_POLL_INTERVAL      1
+#define USB_CFG_INTR_POLL_INTERVAL 1
 /* If you compile a version with endpoint 1 (interrupt-in), this is the poll
  * interval. The value is in milliseconds and must not be less than 10 ms for
  * low speed devices.
  */
-#define USB_CFG_IS_SELF_POWERED         0
+#define USB_CFG_IS_SELF_POWERED 0
 /* Define this to 1 if the device has its own power supply. Set it to 0 if the
  * device is powered from the USB bus.
  */
-#define USB_CFG_MAX_BUS_POWER           500
+#define USB_CFG_MAX_BUS_POWER 500
 /* Set this variable to the maximum USB bus power consumption of your device.
  * The value is in milliamperes. [It will be divided by two since USB
  * communicates power requirements in units of 2 mA.]
  */
-#define USB_CFG_IMPLEMENT_FN_WRITE      1
+#define USB_CFG_IMPLEMENT_FN_WRITE 1
 /* Set this to 1 if you want usbFunctionWrite() to be called for control-out
  * transfers. Set it to 0 if you don't need it and want to save a couple of
  * bytes.
  */
-#define USB_CFG_IMPLEMENT_FN_READ       0
+#define USB_CFG_IMPLEMENT_FN_READ 0
 /* Set this to 1 if you need to send control replies which are generated
  * "on the fly" when usbFunctionRead() is called. If you only want to send
  * data from a static buffer, set it to 0 and return the data from
  * usbFunctionSetup(). This saves a couple of bytes.
  */
-#define USB_CFG_IMPLEMENT_FN_WRITEOUT   0
+#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0
 /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints.
  * You must implement the function usbFunctionWriteOut() which receives all
  * interrupt/bulk data sent to any endpoint other than 0. The endpoint number
  * can be found in 'usbRxToken'.
  */
-#define USB_CFG_HAVE_FLOWCONTROL        0
+#define USB_CFG_HAVE_FLOWCONTROL 0
 /* Define this to 1 if you want flowcontrol over USB data. See the definition
  * of the macros usbDisableAllRequests() and usbEnableAllRequests() in
  * usbdrv.h.
  */
-#define USB_CFG_DRIVER_FLASH_PAGE       0
+#define USB_CFG_DRIVER_FLASH_PAGE 0
 /* If the device has more than 64 kBytes of flash, define this to the 64 k page
  * where the driver's constants (descriptors) are located. Or in other words:
  * Define this to 1 for boot loaders on the ATMega128.
  */
-#define USB_CFG_LONG_TRANSFERS          0
+#define USB_CFG_LONG_TRANSFERS 0
 /* Define this to 1 if you want to send/receive blocks of more than 254 bytes
  * in a single control-in or control-out transfer. Note that the capability
  * for long transfers increases the driver size.
@@ -160,7 +160,7 @@ section at the end of this file).
 /* This macro (if defined) is executed when a USB SET_ADDRESS request was
  * received.
  */
-#define USB_COUNT_SOF                   1
+#define USB_COUNT_SOF 1
 /* define this macro to 1 if you need the global variable "usbSofCount" which
  * counts SOF packets. This feature requires that the hardware interrupt is
  * connected to D- instead of D+.
@@ -184,7 +184,7 @@ section at the end of this file).
  * Please note that Start Of Frame detection works only if D- is wired to the
  * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
  */
-#define USB_CFG_CHECK_DATA_TOGGLING     0
+#define USB_CFG_CHECK_DATA_TOGGLING 0
 /* define this macro to 1 if you want to filter out duplicate data packets
  * sent by the host. Duplicates occur only as a consequence of communication
  * errors, when the host does not receive an ACK. Please note that you need to
@@ -192,11 +192,11 @@ section at the end of this file).
  * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
  * for each control- and out-endpoint to check for duplicate packets.
  */
-#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH   0
+#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
 /* define this macro to 1 if you want the function usbMeasureFrameLength()
  * compiled in. This function can be used to calibrate the AVR's RC oscillator.
  */
-#define USB_USE_FAST_CRC                0
+#define USB_USE_FAST_CRC 0
 /* The assembler module has two implementations for the CRC algorithm. One is
  * faster, the other is smaller. This CRC routine is only used for transmitted
  * messages where timing is not critical. The faster routine needs 31 cycles
@@ -207,7 +207,7 @@ section at the end of this file).
 
 /* -------------------------- Device Description --------------------------- */
 
-#define USB_CFG_VENDOR_ID       (VENDOR_ID & 0xFF), ((VENDOR_ID >> 8) & 0xFF)
+#define USB_CFG_VENDOR_ID (VENDOR_ID & 0xFF), ((VENDOR_ID >> 8) & 0xFF)
 /* USB vendor ID for the device, low byte first. If you have registered your
  * own Vendor ID, define it here. Otherwise you may use one of obdev's free
  * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules!
@@ -216,7 +216,7 @@ section at the end of this file).
  * with libusb: 0x16c0/0x5dc.  Use this VID/PID pair ONLY if you understand
  * the implications!
  */
-#define USB_CFG_DEVICE_ID       (PRODUCT_ID & 0xFF), ((PRODUCT_ID >> 8) & 0xFF)
+#define USB_CFG_DEVICE_ID (PRODUCT_ID & 0xFF), ((PRODUCT_ID >> 8) & 0xFF)
 /* This is the ID of the product, low byte first. It is interpreted in the
  * scope of the vendor ID. If you have registered your own VID with usb.org
  * or if you have licensed a PID from somebody else, define it here. Otherwise
@@ -227,10 +227,10 @@ section at the end of this file).
  * with libusb: 0x16c0/0x5dc.  Use this VID/PID pair ONLY if you understand
  * the implications!
  */
-#define USB_CFG_DEVICE_VERSION  0x00, 0x02
+#define USB_CFG_DEVICE_VERSION 0x00, 0x02
 /* Version number of the device: Minor number first, then major number.
  */
-#define USB_CFG_VENDOR_NAME     'w', 'i', 'n', 'k', 'e', 'y', 'l', 'e', 's', 's', '.', 'k', 'r'
+#define USB_CFG_VENDOR_NAME 'w', 'i', 'n', 'k', 'e', 'y', 'l', 'e', 's', 's', '.', 'k', 'r'
 #define USB_CFG_VENDOR_NAME_LEN 13
 /* These two values define the vendor name returned by the USB device. The name
  * must be given as a list of characters under single quotes. The characters
@@ -240,7 +240,7 @@ section at the end of this file).
  * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for
  * details.
  */
-#define USB_CFG_DEVICE_NAME     'p', 's', '2', 'a', 'v', 'r', 'G', 'B'
+#define USB_CFG_DEVICE_NAME 'p', 's', '2', 'a', 'v', 'r', 'G', 'B'
 #define USB_CFG_DEVICE_NAME_LEN 8
 /* Same as above for the device name. If you don't want a device name, undefine
  * the macros. See the file USB-IDs-for-free.txt before you assign a name if
@@ -255,20 +255,20 @@ section at the end of this file).
  * to fine tune control over USB descriptors such as the string descriptor
  * for the serial number.
  */
-#define USB_CFG_DEVICE_CLASS        0
-#define USB_CFG_DEVICE_SUBCLASS     0
+#define USB_CFG_DEVICE_CLASS 0
+#define USB_CFG_DEVICE_SUBCLASS 0
 /* See USB specification if you want to conform to an existing device class.
  * Class 0xff is "vendor specific".
  */
-#define USB_CFG_INTERFACE_CLASS     3   /* HID */
-#define USB_CFG_INTERFACE_SUBCLASS  1   /* Boot */
-#define USB_CFG_INTERFACE_PROTOCOL  1   /* Keyboard */
+#define USB_CFG_INTERFACE_CLASS    /* HID */
+#define USB_CFG_INTERFACE_SUBCLASS 1 /* Boot */
+#define USB_CFG_INTERFACE_PROTOCOL 1 /* Keyboard */
 /* See USB specification if you want to conform to an existing device class or
  * protocol. The following classes must be set at interface level:
  * HID class is 3, no subclass and protocol required (but may be useful!)
  * CDC class is 2, use subclass 2 and protocol 1 for ACM
  */
-#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH    0
+#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 0
 /* Define this to the length of the HID report descriptor, if you implement
  * an HID device. Otherwise don't define it or define it to 0.
  * If you use this define, you must add a PROGMEM character array named
@@ -333,19 +333,19 @@ section at the end of this file).
  * };
  */
 
-#define USB_CFG_DESCR_PROPS_DEVICE                  0
-#define USB_CFG_DESCR_PROPS_CONFIGURATION           USB_PROP_IS_DYNAMIC
+#define USB_CFG_DESCR_PROPS_DEVICE 0
+#define USB_CFG_DESCR_PROPS_CONFIGURATION USB_PROP_IS_DYNAMIC
 //#define USB_CFG_DESCR_PROPS_CONFIGURATION           0
-#define USB_CFG_DESCR_PROPS_STRINGS                 0
-#define USB_CFG_DESCR_PROPS_STRING_0                0
-#define USB_CFG_DESCR_PROPS_STRING_VENDOR           0
-#define USB_CFG_DESCR_PROPS_STRING_PRODUCT          0
-#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    0
-#define USB_CFG_DESCR_PROPS_HID                     USB_PROP_IS_DYNAMIC
+#define USB_CFG_DESCR_PROPS_STRINGS 0
+#define USB_CFG_DESCR_PROPS_STRING_0 0
+#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0
+#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0
+#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0
+#define USB_CFG_DESCR_PROPS_HID USB_PROP_IS_DYNAMIC
 //#define USB_CFG_DESCR_PROPS_HID                     0
-#define USB_CFG_DESCR_PROPS_HID_REPORT              USB_PROP_IS_DYNAMIC
+#define USB_CFG_DESCR_PROPS_HID_REPORT USB_PROP_IS_DYNAMIC
 //#define USB_CFG_DESCR_PROPS_HID_REPORT              0
-#define USB_CFG_DESCR_PROPS_UNKNOWN                 0
+#define USB_CFG_DESCR_PROPS_UNKNOWN 0
 
 #define usbMsgPtr_t unsigned short
 /* If usbMsgPtr_t is not defined, it defaults to 'uchar *'. We define it to
@@ -374,10 +374,10 @@ section at the end of this file).
 
 /* Set INT1 for D- falling edge to count SOF */
 /* #define USB_INTR_CFG            EICRA */
-#define USB_INTR_CFG_SET        ((1 << ISC11) | (0 << ISC10))
+#define USB_INTR_CFG_SET ((1 << ISC11) | (0 << ISC10))
 /* #define USB_INTR_CFG_CLR        0 */
 /* #define USB_INTR_ENABLE         EIMSK */
-#define USB_INTR_ENABLE_BIT     INT1
+#define USB_INTR_ENABLE_BIT INT1
 /* #define USB_INTR_PENDING        EIFR */
-#define USB_INTR_PENDING_BIT    INTF1
-#define USB_INTR_VECTOR         INT1_vect
+#define USB_INTR_PENDING_BIT INTF1
+#define USB_INTR_VECTOR INT1_vect
index 713747cfc2040a0ee33a210326f92ca0bb6f6fc1..00562bc9200a40f2190ea4a489b58c00eb720e66 100644 (file)
 #include <string.h>
 
 #ifdef NO_PRINT
-#error "You need undef NO_PRINT to use the variable trace feature"
+#    error "You need undef NO_PRINT to use the variable trace feature"
 #endif
 
 #ifndef CONSOLE_ENABLE
-#error "The console needs to be enabled in the makefile to use the variable trace feature"
+#    error "The console needs to be enabled in the makefile to use the variable trace feature"
 #endif
 
-
 #define NUM_TRACED_VARIABLES 1
 #ifndef MAX_VARIABLE_TRACE_SIZE
-    #define MAX_VARIABLE_TRACE_SIZE 4
+#    define MAX_VARIABLE_TRACE_SIZE 4
 #endif
 
 typedef struct {
     const char* name;
-    void* addr;
-    unsigned size;
+    void*       addr;
+    unsigned    size;
     const char* func;
-    int line;
-    uint8_t last_value[MAX_VARIABLE_TRACE_SIZE];
+    int         line;
+    uint8_t     last_value[MAX_VARIABLE_TRACE_SIZE];
 
 } traced_variable_t;
 
@@ -48,18 +47,17 @@ void add_traced_variable(const char* name, void* addr, unsigned size, const char
     verify_traced_variables(func, line);
     if (size > MAX_VARIABLE_TRACE_SIZE) {
 #if defined(__AVR__)
-       xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size);
+        xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size);
 #else
-       xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size);
+        xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size);
 #endif
-       size = MAX_VARIABLE_TRACE_SIZE;
+        size = MAX_VARIABLE_TRACE_SIZE;
     }
     int index = -1;
     for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
-        if (index == -1 && traced_variables[i].addr == NULL){
+        if (index == -1 && traced_variables[i].addr == NULL) {
             index = i;
-        }
-        else if (strcmp_P(name, traced_variables[i].name)==0) {
+        } else if (strcmp_P(name, traced_variables[i].name) == 0) {
             index = i;
             break;
         }
@@ -71,19 +69,18 @@ void add_traced_variable(const char* name, void* addr, unsigned size, const char
     }
 
     traced_variable_t* t = &traced_variables[index];
-    t->name = name;
-    t->addr = addr;
-    t->size = size;
-    t->func = func;
-    t->line = line;
+    t->name              = name;
+    t->addr              = addr;
+    t->size              = size;
+    t->func              = func;
+    t->line              = line;
     memcpy(&t->last_value[0], addr, size);
-
 }
 
 void remove_traced_variable(const char* name, const char* func, int line) {
     verify_traced_variables(func, line);
     for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
-        if (strcmp_P(name, traced_variables[i].name)==0) {
+        if (strcmp_P(name, traced_variables[i].name) == 0) {
             traced_variables[i].name = 0;
             traced_variables[i].addr = NULL;
             break;
@@ -95,29 +92,29 @@ void verify_traced_variables(const char* func, int line) {
     for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
         traced_variable_t* t = &traced_variables[i];
         if (t->addr != NULL && t->name != NULL) {
-            if (memcmp(t->last_value, t->addr, t->size)!=0){
+            if (memcmp(t->last_value, t->addr, t->size) != 0) {
 #if defined(__AVR__)
-               xprintf("Traced variable \"%S\" has been modified\n", t->name);
-               xprintf("Between %S:%d\n", t->func, t->line);
-               xprintf("And %S:%d\n", func, line);
+                xprintf("Traced variable \"%S\" has been modified\n", t->name);
+                xprintf("Between %S:%d\n", t->func, t->line);
+                xprintf("And %S:%d\n", func, line);
 
 #else
-               xprintf("Traced variable \"%s\" has been modified\n", t->name);
-               xprintf("Between %s:%d\n", t->func, t->line);
-               xprintf("And %s:%d\n", func, line);
+                xprintf("Traced variable \"%s\" has been modified\n", t->name);
+                xprintf("Between %s:%d\n", t->func, t->line);
+                xprintf("And %s:%d\n", func, line);
 #endif
-               xprintf("Previous value ");
-               for (int j=0; j<t->size;j++) {
-                   print_hex8(t->last_value[j]);
-               }
-               xprintf("\nNew value ");
-               uint8_t* addr = (uint8_t*)(t->addr);
-               for (int j=0; j<t->size;j++) {
-                   print_hex8(addr[j]);
-               }
-               xprintf("\n");
-               memcpy(t->last_value, addr, t->size);
-           }
+                xprintf("Previous value ");
+                for (int j = 0; j < t->size; j++) {
+                    print_hex8(t->last_value[j]);
+                }
+                xprintf("\nNew value ");
+                uint8_t* addr = (uint8_t*)(t->addr);
+                for (int j = 0; j < t->size; j++) {
+                    print_hex8(addr[j]);
+                }
+                xprintf("\n");
+                memcpy(t->last_value, addr, t->size);
+            }
         }
 
         t->func = func;
index dacc13858d229c2c9829e1ff5dadb0fecb299125..26b810d3cd25bf35869bc719b96d63d17eb92038 100644 (file)
 // Start tracing a variable at the memory address addr
 // The name can be anything and is used only for reporting
 // The size should usually be the same size as the variable you are interested in
-#define ADD_TRACED_VARIABLE(name, addr, size) \
-    add_traced_variable(PSTR(name), (void*)addr, size, PSTR(__FILE__), __LINE__)
+#    define ADD_TRACED_VARIABLE(name, addr, size) add_traced_variable(PSTR(name), (void*)addr, size, PSTR(__FILE__), __LINE__)
 
 // Stop tracing the variable with the given name
-#define REMOVE_TRACED_VARIABLE(name) remove_traced_variable(PSTR(name), PSTR(__FILE__), __LINE__)
+#    define REMOVE_TRACED_VARIABLE(name) remove_traced_variable(PSTR(name), PSTR(__FILE__), __LINE__)
 
 // Call to get messages when the variable has been changed
-#define VERIFY_TRACED_VARIABLES() verify_traced_variables(PSTR(__FILE__), __LINE__)
+#    define VERIFY_TRACED_VARIABLES() verify_traced_variables(PSTR(__FILE__), __LINE__)
 
 #else
 
-#define ADD_TRACED_VARIABLE(name, addr, size)
-#define REMOVE_TRACED_VARIABLE(name)
-#define VERIFY_TRACED_VARIABLES()
+#    define ADD_TRACED_VARIABLE(name, addr, size)
+#    define REMOVE_TRACED_VARIABLE(name)
+#    define VERIFY_TRACED_VARIABLES()
 
 #endif
 
index 550c3b70a6478cb250a9b3e761f29de78203849f..6b7f82d9508d4bab35245606df6a3661cdbff263 100644 (file)
@@ -4,23 +4,21 @@
 #include "eeprom.h"
 
 #ifndef MIN
-#define MIN(a,b) (((a)<(b))?(a):(b))
+#    define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #endif
 #ifndef MAX
-#define MAX(a,b) (((a)>(b))?(a):(b))
+#    define MAX(a, b) (((a) > (b)) ? (a) : (b))
 #endif
 
 #define TYPING_SPEED_MAX_VALUE 200
 uint8_t typing_speed = 0;
 
-bool velocikey_enabled(void) {
-    return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1;
-}
+bool velocikey_enabled(void) { return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1; }
 
 void velocikey_toggle(void) {
-    if (velocikey_enabled()) 
+    if (velocikey_enabled())
         eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
-    else 
+    else
         eeprom_update_byte(EECONFIG_VELOCIKEY, 1);
 }
 
@@ -29,18 +27,16 @@ void velocikey_accelerate(void) {
 }
 
 void velocikey_decelerate(void) {
-  static uint16_t decay_timer = 0;
-
-  if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
-    if (typing_speed > 0) typing_speed -= 1;
-    //Decay a little faster at half of max speed
-    if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
-    //Decay even faster at 3/4 of max speed
-    if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2;
-    decay_timer = timer_read();
-  }
+    static uint16_t decay_timer = 0;
+
+    if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
+        if (typing_speed > 0) typing_speed -= 1;
+        // Decay a little faster at half of max speed
+        if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
+        // Decay even faster at 3/4 of max speed
+        if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2;
+        decay_timer = timer_read();
+    }
 }
 
-uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) {
-  return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
-}
+uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) { return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE)); }
index 1910f0f4e96f2b21443a7775f03111464092bfcb..b977606c5dc775cde504129ba9da3d71a1e7b025 100644 (file)
@@ -4,10 +4,10 @@
 #include <stdint.h>
 #include <stdbool.h>
 
-bool velocikey_enabled(void);
-void velocikey_toggle(void);
-void velocikey_accelerate(void);
-void velocikey_decelerate(void);
+bool    velocikey_enabled(void);
+void    velocikey_toggle(void);
+void    velocikey_accelerate(void);
+void    velocikey_decelerate(void);
 uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue);
 
 #endif
\ No newline at end of file
index eb705b1881328016a0b884ef354138bfcc820388..865e5886930964de98f1f2b110eb923b921eb935 100644 (file)
@@ -22,7 +22,6 @@
 #ifndef COMMON_GFXCONF_H
 #define COMMON_GFXCONF_H
 
-
 ///////////////////////////////////////////////////////////////////////////
 // GOS - One of these must be defined, preferably in your Makefile       //
 ///////////////////////////////////////////////////////////////////////////
 //    #define INTERRUPTS_OFF()                         optional_code
 //    #define INTERRUPTS_ON()                          optional_code
 // These are not defined by default for some reason
-#define GOS_NEED_X_THREADS     FALSE
-#define GOS_NEED_X_HEAP                FALSE
+#define GOS_NEED_X_THREADS FALSE
+#define GOS_NEED_X_HEAP FALSE
 
 // Options that (should where relevant) apply to all operating systems
-    #define GFX_NO_INLINE                            FALSE
+#define GFX_NO_INLINE FALSE
 //    #define GFX_COMPILER                             GFX_COMPILER_UNKNOWN
 //    #define GFX_CPU                                  GFX_CPU_UNKNOWN
 //    #define GFX_OS_HEAP_SIZE                         0
 //    #define GFX_OS_EXTRA_INIT_FUNCTION               myOSInitRoutine
 //    #define GFX_OS_EXTRA_DEINIT_FUNCTION             myOSDeInitRoutine
 
-
 ///////////////////////////////////////////////////////////////////////////
 // GDISP                                                                 //
 ///////////////////////////////////////////////////////////////////////////
-#define GFX_USE_GDISP                                TRUE
+#define GFX_USE_GDISP TRUE
 
 //#define GDISP_NEED_AUTOFLUSH                         FALSE
 //#define GDISP_NEED_TIMERFLUSH                        FALSE
 //#define GDISP_NEED_VALIDATION                        TRUE
 //#define GDISP_NEED_CLIP                              TRUE
-#define GDISP_NEED_CIRCLE                            TRUE
-#define GDISP_NEED_ELLIPSE                           TRUE
-#define GDISP_NEED_ARC                               TRUE
-#define GDISP_NEED_ARCSECTORS                        TRUE
-#define GDISP_NEED_CONVEX_POLYGON                    TRUE
+#define GDISP_NEED_CIRCLE TRUE
+#define GDISP_NEED_ELLIPSE TRUE
+#define GDISP_NEED_ARC TRUE
+#define GDISP_NEED_ARCSECTORS TRUE
+#define GDISP_NEED_CONVEX_POLYGON TRUE
 //#define GDISP_NEED_SCROLL                            FALSE
-#define GDISP_NEED_PIXELREAD                         TRUE
-#define GDISP_NEED_CONTROL                           TRUE
+#define GDISP_NEED_PIXELREAD TRUE
+#define GDISP_NEED_CONTROL TRUE
 //#define GDISP_NEED_QUERY                             FALSE
 //#define GDISP_NEED_MULTITHREAD                       FALSE
 //#define GDISP_NEED_STREAMING                         FALSE
-#define GDISP_NEED_TEXT                              TRUE
+#define GDISP_NEED_TEXT TRUE
 //    #define GDISP_NEED_TEXT_WORDWRAP                 FALSE
 //    #define GDISP_NEED_ANTIALIAS                     FALSE
 //    #define GDISP_NEED_UTF8                          FALSE
-    #define GDISP_NEED_TEXT_KERNING                  TRUE
+#define GDISP_NEED_TEXT_KERNING TRUE
 //    #define GDISP_INCLUDE_FONT_UI1                   FALSE
 //    #define GDISP_INCLUDE_FONT_UI2                   FALSE           // The smallest preferred font.
 //    #define GDISP_INCLUDE_FONT_LARGENUMBERS          FALSE
 //    #define GDISP_INCLUDE_FONT_DEJAVUSANS20          FALSE
 //    #define GDISP_INCLUDE_FONT_DEJAVUSANS24          FALSE
 //    #define GDISP_INCLUDE_FONT_DEJAVUSANS32          FALSE
-    #define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12      TRUE
+#define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12 TRUE
 //    #define GDISP_INCLUDE_FONT_FIXED_10X20           FALSE
 //    #define GDISP_INCLUDE_FONT_FIXED_7X14            FALSE
-    #define GDISP_INCLUDE_FONT_FIXED_5X8             TRUE
+#define GDISP_INCLUDE_FONT_FIXED_5X8 TRUE
 //    #define GDISP_INCLUDE_FONT_DEJAVUSANS12_AA       FALSE
 //    #define GDISP_INCLUDE_FONT_DEJAVUSANS16_AA       FALSE
 //    #define GDISP_INCLUDE_FONT_DEJAVUSANS20_AA       FALSE
 //    #define GDISP_NEED_IMAGE_PNG                     FALSE
 //    #define GDISP_NEED_IMAGE_ACCOUNTING              FALSE
 #ifdef EMULATOR
-#define GDISP_NEED_PIXMAP                            TRUE
+#    define GDISP_NEED_PIXMAP TRUE
 #endif
 //    #define GDISP_NEED_PIXMAP_IMAGE                  FALSE
 
 //#define GDISP_DEFAULT_ORIENTATION                    GDISP_ROTATE_LANDSCAPE    // If not defined the native hardware orientation is used.
 //#define GDISP_LINEBUF_SIZE                           128
 //#define GDISP_STARTUP_COLOR                          Black
-#define GDISP_NEED_STARTUP_LOGO                      FALSE
+#define GDISP_NEED_STARTUP_LOGO FALSE
 
 //#define GDISP_TOTAL_DISPLAYS                          2
 
-    #ifdef GDISP_DRIVER_LIST
-        // For code and speed optimization define as TRUE or FALSE if all controllers have the same capability
-        #define GDISP_HARDWARE_STREAM_WRITE          FALSE
-        #define GDISP_HARDWARE_STREAM_READ           FALSE
-        #define GDISP_HARDWARE_STREAM_POS            FALSE
-        #define GDISP_HARDWARE_DRAWPIXEL             TRUE
-        #define GDISP_HARDWARE_CLEARS                FALSE
-        #define GDISP_HARDWARE_FILLS                 FALSE
-        //#define GDISP_HARDWARE_BITFILLS              FALSE
-        #define GDISP_HARDWARE_SCROLL                FALSE
-        #define GDISP_HARDWARE_PIXELREAD             TRUE
-        #define GDISP_HARDWARE_CONTROL               TRUE
-        #define GDISP_HARDWARE_QUERY                 FALSE
-        #define GDISP_HARDWARE_CLIP                  FALSE
-
-        #define GDISP_PIXELFORMAT                    GDISP_PIXELFORMAT_RGB888
-    #endif
+#ifdef GDISP_DRIVER_LIST
+// For code and speed optimization define as TRUE or FALSE if all controllers have the same capability
+#    define GDISP_HARDWARE_STREAM_WRITE FALSE
+#    define GDISP_HARDWARE_STREAM_READ FALSE
+#    define GDISP_HARDWARE_STREAM_POS FALSE
+#    define GDISP_HARDWARE_DRAWPIXEL TRUE
+#    define GDISP_HARDWARE_CLEARS FALSE
+#    define GDISP_HARDWARE_FILLS FALSE
+//#define GDISP_HARDWARE_BITFILLS              FALSE
+#    define GDISP_HARDWARE_SCROLL FALSE
+#    define GDISP_HARDWARE_PIXELREAD TRUE
+#    define GDISP_HARDWARE_CONTROL TRUE
+#    define GDISP_HARDWARE_QUERY FALSE
+#    define GDISP_HARDWARE_CLIP FALSE
+
+#    define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888
+#endif
 
 // The custom format is not defined for some reason, so define it as error
 // so we don't get compiler warnings
 #define GDISP_PIXELFORMAT_CUSTOM GDISP_PIXELFORMAT_ERROR
 
-#define GDISP_USE_GFXNET                             FALSE
+#define GDISP_USE_GFXNET FALSE
 //    #define GDISP_GFXNET_PORT                        13001
 //    #define GDISP_GFXNET_CUSTOM_LWIP_STARTUP         FALSE
 //    #define GDISP_DONT_WAIT_FOR_NET_DISPLAY          FALSE
 //    #define GDISP_GFXNET_UNSAFE_SOCKETS              FALSE
 
-
 ///////////////////////////////////////////////////////////////////////////
 // GWIN                                                                  //
 ///////////////////////////////////////////////////////////////////////////
-#define GFX_USE_GWIN                                 FALSE
+#define GFX_USE_GWIN FALSE
 
 //#define GWIN_NEED_WINDOWMANAGER                      FALSE
 //    #define GWIN_REDRAW_IMMEDIATE                    FALSE
 //    #define GWIN_NEED_TABSET                         FALSE
 //        #define GWIN_TABSET_TABHEIGHT                18
 
-
 ///////////////////////////////////////////////////////////////////////////
 // GEVENT                                                                //
 ///////////////////////////////////////////////////////////////////////////
-#define GFX_USE_GEVENT                               TRUE
+#define GFX_USE_GEVENT TRUE
 
 //#define GEVENT_ASSERT_NO_RESOURCE                    FALSE
 //#define GEVENT_MAXIMUM_SIZE                          32
 //#define GEVENT_MAX_SOURCE_LISTENERS                  32
 
-
 ///////////////////////////////////////////////////////////////////////////
 // GTIMER                                                                //
 ///////////////////////////////////////////////////////////////////////////
-#define GFX_USE_GTIMER                               FALSE
+#define GFX_USE_GTIMER FALSE
 
 //#define GTIMER_THREAD_PRIORITY                       HIGH_PRIORITY
 //#define GTIMER_THREAD_WORKAREA_SIZE                  2048
 
-
 ///////////////////////////////////////////////////////////////////////////
 // GQUEUE                                                                //
 ///////////////////////////////////////////////////////////////////////////
-#define GFX_USE_GQUEUE                               FALSE
+#define GFX_USE_GQUEUE FALSE
 
 //#define GQUEUE_NEED_ASYNC                            FALSE
 //#define GQUEUE_NEED_GSYNC                            FALSE
 ///////////////////////////////////////////////////////////////////////////
 // GINPUT                                                                //
 ///////////////////////////////////////////////////////////////////////////
-#define GFX_USE_GINPUT                               FALSE
+#define GFX_USE_GINPUT FALSE
 
 //#define GINPUT_NEED_MOUSE                            FALSE
 //    #define GINPUT_TOUCH_STARTRAW                    FALSE
 //#define GINPUT_NEED_TOGGLE                           FALSE
 //#define GINPUT_NEED_DIAL                             FALSE
 
-
 ///////////////////////////////////////////////////////////////////////////
 // GFILE                                                                 //
 ///////////////////////////////////////////////////////////////////////////
-#define GFX_USE_GFILE                                FALSE
+#define GFX_USE_GFILE FALSE
 
 //#define GFILE_NEED_PRINTG                            FALSE
 //#define GFILE_NEED_SCANG                             FALSE
 ///////////////////////////////////////////////////////////////////////////
 // GADC                                                                  //
 ///////////////////////////////////////////////////////////////////////////
-#define GFX_USE_GADC                                 FALSE
+#define GFX_USE_GADC FALSE
 
 //#define GADC_MAX_LOWSPEED_DEVICES                    4
 
-
 ///////////////////////////////////////////////////////////////////////////
 // GAUDIO                                                                //
 ///////////////////////////////////////////////////////////////////////////
-#define GFX_USE_GAUDIO                               FALSE
+#define GFX_USE_GAUDIO FALSE
 // There seems to be a bug in the ugfx code, the wrong define is used
 // So define it in order to avoid warnings
-#define GFX_USE_GAUDIN                               GFX_USE_GAUDIO
+#define GFX_USE_GAUDIN GFX_USE_GAUDIO
 //    #define GAUDIO_NEED_PLAY                         FALSE
 //    #define GAUDIO_NEED_RECORD                       FALSE
 
-
 ///////////////////////////////////////////////////////////////////////////
 // GMISC                                                                 //
 ///////////////////////////////////////////////////////////////////////////
-#define GFX_USE_GMISC                                TRUE
+#define GFX_USE_GMISC TRUE
 
 //#define GMISC_NEED_ARRAYOPS                          FALSE
 //#define GMISC_NEED_FASTTRIG                          FALSE
 //#define GMISC_NEED_INVSQRT                           FALSE
 //    #define GMISC_INVSQRT_MIXED_ENDIAN               FALSE
 //    #define GMISC_INVSQRT_REAL_SLOW                  FALSE
-#define GMISC_NEED_MATRIXFLOAT2D                     TRUE
-#define GMISC_NEED_MATRIXFIXED2D                     FALSE
+#define GMISC_NEED_MATRIXFLOAT2D TRUE
+#define GMISC_NEED_MATRIXFIXED2D FALSE
 
 #endif /* COMMON_GFXCONF_H */
index 2d03273720cb8f319b3ec8f34506b872779f03e4..2f43c67cc8776e7df31b9e1be1379db5ba058099 100644 (file)
 
 #if defined(VISUALIZER_ENABLE)
 
-#include "default_animations.h"
-#include "visualizer.h"
-#ifdef LCD_ENABLE
-#include "lcd_keyframes.h"
-#endif
-#ifdef LCD_BACKLIGHT_ENABLE
-#include "lcd_backlight_keyframes.h"
-#endif
-
-#ifdef BACKLIGHT_ENABLE
-#include "led_backlight_keyframes.h"
-#endif
+#    include "default_animations.h"
+#    include "visualizer.h"
+#    ifdef LCD_ENABLE
+#        include "lcd_keyframes.h"
+#    endif
+#    ifdef LCD_BACKLIGHT_ENABLE
+#        include "lcd_backlight_keyframes.h"
+#    endif
 
-#include "visualizer_keyframes.h"
+#    ifdef BACKLIGHT_ENABLE
+#        include "led_backlight_keyframes.h"
+#    endif
 
+#    include "visualizer_keyframes.h"
 
-#if defined(LCD_ENABLE) || defined(LCD_BACKLIGHT_ENABLE) || defined(BACKLIGHT_ENABLE)
+#    if defined(LCD_ENABLE) || defined(LCD_BACKLIGHT_ENABLE) || defined(BACKLIGHT_ENABLE)
 
 static bool keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
-#ifdef LCD_ENABLE
+#        ifdef LCD_ENABLE
     lcd_keyframe_enable(animation, state);
-#endif
-#ifdef LCD_BACKLIGHT_ENABLE
+#        endif
+#        ifdef LCD_BACKLIGHT_ENABLE
     lcd_backlight_keyframe_enable(animation, state);
-#endif
-#ifdef BACKLIGHT_ENABLE
+#        endif
+#        ifdef BACKLIGHT_ENABLE
     led_backlight_keyframe_enable(animation, state);
-#endif
+#        endif
     return false;
 }
 
 static bool keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
-#ifdef LCD_ENABLE
+#        ifdef LCD_ENABLE
     lcd_keyframe_disable(animation, state);
-#endif
-#ifdef LCD_BACKLIGHT_ENABLE
+#        endif
+#        ifdef LCD_BACKLIGHT_ENABLE
     lcd_backlight_keyframe_disable(animation, state);
-#endif
-#ifdef BACKLIGHT_ENABLE
+#        endif
+#        ifdef BACKLIGHT_ENABLE
     led_backlight_keyframe_disable(animation, state);
-#endif
+#        endif
     return false;
 }
 
 static bool keyframe_fade_in(keyframe_animation_t* animation, visualizer_state_t* state) {
     bool ret = false;
-#ifdef LCD_BACKLIGHT_ENABLE
+#        ifdef LCD_BACKLIGHT_ENABLE
     ret |= lcd_backlight_keyframe_animate_color(animation, state);
-#endif
-#ifdef BACKLIGHT_ENABLE
+#        endif
+#        ifdef BACKLIGHT_ENABLE
     ret |= led_backlight_keyframe_fade_in_all(animation, state);
-#endif
+#        endif
     return ret;
 }
 
 static bool keyframe_fade_out(keyframe_animation_t* animation, visualizer_state_t* state) {
     bool ret = false;
-#ifdef LCD_BACKLIGHT_ENABLE
+#        ifdef LCD_BACKLIGHT_ENABLE
     ret |= lcd_backlight_keyframe_animate_color(animation, state);
-#endif
-#ifdef BACKLIGHT_ENABLE
+#        endif
+#        ifdef BACKLIGHT_ENABLE
     ret |= led_backlight_keyframe_fade_out_all(animation, state);
-#endif
+#        endif
     return ret;
 }
 
-
 // Don't worry, if the startup animation is long, you can use the keyboard like normal
 // during that time
 keyframe_animation_t default_startup_animation = {
-#if LCD_ENABLE
+#        if LCD_ENABLE
     .num_frames = 3,
-#else
+#        else
     .num_frames = 2,
-#endif
-    .loop = false,
-    .frame_lengths = {
-        0, 
-#if LCD_ENABLE
-        0, 
-#endif
-        gfxMillisecondsToTicks(5000)},
-    .frame_functions = {
+#        endif
+    .loop          = false,
+    .frame_lengths = {0,
+#        if LCD_ENABLE
+                      0,
+#        endif
+                      gfxMillisecondsToTicks(5000)},
+    .frame_functions =
+        {
             keyframe_enable,
-#if LCD_ENABLE
+#        if LCD_ENABLE
             lcd_keyframe_draw_logo,
-#endif
+#        endif
             keyframe_fade_in,
-    },
+        },
 };
 
 keyframe_animation_t default_suspend_animation = {
-#if LCD_ENABLE
+#        if LCD_ENABLE
     .num_frames = 3,
-#else
+#        else
     .num_frames = 2,
-#endif
+#        endif
     .loop = false,
-    .frame_lengths = {
-#if LCD_ENABLE
-        0, 
-#endif
-        gfxMillisecondsToTicks(1000), 
-        0},
-    .frame_functions = {
-#if LCD_ENABLE
+    .frame_lengths =
+        {
+#        if LCD_ENABLE
+            0,
+#        endif
+            gfxMillisecondsToTicks(1000), 0},
+    .frame_functions =
+        {
+#        if LCD_ENABLE
             lcd_keyframe_display_layer_text,
-#endif
+#        endif
             keyframe_fade_out,
             keyframe_disable,
-    },
+        },
 };
-#endif
+#    endif
 
-#if defined(BACKLIGHT_ENABLE)
-#define CROSSFADE_TIME 1000
-#define GRADIENT_TIME 3000
+#    if defined(BACKLIGHT_ENABLE)
+#        define CROSSFADE_TIME 1000
+#        define GRADIENT_TIME 3000
 
 keyframe_animation_t led_test_animation = {
     .num_frames = 14,
-    .loop = true,
-    .frame_lengths = {
-        gfxMillisecondsToTicks(1000), // fade in
-        gfxMillisecondsToTicks(1000), // no op (leds on)
-        gfxMillisecondsToTicks(1000), // fade out
-        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
-        gfxMillisecondsToTicks(GRADIENT_TIME), // left to rigt (outside in)
-        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
-        gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
-        0,           // mirror leds
-        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
-        gfxMillisecondsToTicks(GRADIENT_TIME), // left_to_right (mirrored, so inside out)
-        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
-        gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
-        0,           // normal leds
-        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
-
-    },
-    .frame_functions = {
-        led_backlight_keyframe_fade_in_all,
-        keyframe_no_operation,
-        led_backlight_keyframe_fade_out_all,
-        led_backlight_keyframe_crossfade,
-        led_backlight_keyframe_left_to_right_gradient,
-        led_backlight_keyframe_crossfade,
-        led_backlight_keyframe_top_to_bottom_gradient,
-        led_backlight_keyframe_mirror_orientation,
-        led_backlight_keyframe_crossfade,
-        led_backlight_keyframe_left_to_right_gradient,
-        led_backlight_keyframe_crossfade,
-        led_backlight_keyframe_top_to_bottom_gradient,
-        led_backlight_keyframe_normal_orientation,
-        led_backlight_keyframe_crossfade,
-    },
+    .loop       = true,
+    .frame_lengths =
+        {
+            gfxMillisecondsToTicks(1000),            // fade in
+            gfxMillisecondsToTicks(1000),            // no op (leds on)
+            gfxMillisecondsToTicks(1000),            // fade out
+            gfxMillisecondsToTicks(CROSSFADE_TIME),  // crossfade
+            gfxMillisecondsToTicks(GRADIENT_TIME),   // left to rigt (outside in)
+            gfxMillisecondsToTicks(CROSSFADE_TIME),  // crossfade
+            gfxMillisecondsToTicks(GRADIENT_TIME),   // top_to_bottom
+            0,                                       // mirror leds
+            gfxMillisecondsToTicks(CROSSFADE_TIME),  // crossfade
+            gfxMillisecondsToTicks(GRADIENT_TIME),   // left_to_right (mirrored, so inside out)
+            gfxMillisecondsToTicks(CROSSFADE_TIME),  // crossfade
+            gfxMillisecondsToTicks(GRADIENT_TIME),   // top_to_bottom
+            0,                                       // normal leds
+            gfxMillisecondsToTicks(CROSSFADE_TIME),  // crossfade
+
+        },
+    .frame_functions =
+        {
+            led_backlight_keyframe_fade_in_all,
+            keyframe_no_operation,
+            led_backlight_keyframe_fade_out_all,
+            led_backlight_keyframe_crossfade,
+            led_backlight_keyframe_left_to_right_gradient,
+            led_backlight_keyframe_crossfade,
+            led_backlight_keyframe_top_to_bottom_gradient,
+            led_backlight_keyframe_mirror_orientation,
+            led_backlight_keyframe_crossfade,
+            led_backlight_keyframe_left_to_right_gradient,
+            led_backlight_keyframe_crossfade,
+            led_backlight_keyframe_top_to_bottom_gradient,
+            led_backlight_keyframe_normal_orientation,
+            led_backlight_keyframe_crossfade,
+        },
 };
-#endif
+#    endif
 
 #endif
index 6cd996f75e5f076d108a7631b20e7c62017eeba8..23978974e3e173dfdce2fc28670b293c83400dd2 100644 (file)
@@ -25,9 +25,9 @@ SOFTWARE.
 #include "lcd_backlight.h"
 #include <math.h>
 
-static uint8_t current_hue = 0;
+static uint8_t current_hue        = 0;
 static uint8_t current_saturation = 0;
-static uint8_t current_intensity = 0;
+static uint8_t current_intensity  = 0;
 static uint8_t current_brightness = 0;
 
 void lcd_backlight_init(void) {
@@ -40,26 +40,26 @@ void lcd_backlight_init(void) {
 // http://blog.saikoled.com/post/43693602826/why-every-led-light-should-be-using-hsi
 static void hsi_to_rgb(float h, float s, float i, uint16_t* r_out, uint16_t* g_out, uint16_t* b_out) {
     unsigned int r, g, b;
-    h = fmodf(h, 360.0f); // cycle h around to 0-360 degrees
-    h = 3.14159f * h / 180.0f; // Convert to radians.
-    s = s > 0.0f ? (s < 1.0f ? s : 1.0f) : 0.0f; // clamp s and i to interval [0,1]
+    h = fmodf(h, 360.0f);                         // cycle h around to 0-360 degrees
+    h = 3.14159f * h / 180.0f;                    // Convert to radians.
+    s = s > 0.0f ? (s < 1.0f ? s : 1.0f) : 0.0f;  // clamp s and i to interval [0,1]
     i = i > 0.0f ? (i < 1.0f ? i : 1.0f) : 0.0f;
 
     // Math! Thanks in part to Kyle Miller.
-    if(h < 2.09439f) {
-        r = 65535.0f * i/3.0f *(1.0f + s * cos(h) / cosf(1.047196667f - h));
-        g = 65535.0f * i/3.0f *(1.0f + s *(1.0f - cosf(h) / cos(1.047196667f - h)));
-        b = 65535.0f * i/3.0f *(1.0f - s);
-    } else if(h < 4.188787) {
+    if (h < 2.09439f) {
+        r = 65535.0f * i / 3.0f * (1.0f + s * cos(h) / cosf(1.047196667f - h));
+        g = 65535.0f * i / 3.0f * (1.0f + s * (1.0f - cosf(h) / cos(1.047196667f - h)));
+        b = 65535.0f * i / 3.0f * (1.0f - s);
+    } else if (h < 4.188787) {
         h = h - 2.09439;
-        g = 65535.0f * i/3.0f *(1.0f + s * cosf(h) / cosf(1.047196667f - h));
-        b = 65535.0f * i/3.0f *(1.0f + s * (1.0f - cosf(h) / cosf(1.047196667f - h)));
-        r = 65535.0f * i/3.0f *(1.0f - s);
+        g = 65535.0f * i / 3.0f * (1.0f + s * cosf(h) / cosf(1.047196667f - h));
+        b = 65535.0f * i / 3.0f * (1.0f + s * (1.0f - cosf(h) / cosf(1.047196667f - h)));
+        r = 65535.0f * i / 3.0f * (1.0f - s);
     } else {
         h = h - 4.188787;
-        b = 65535.0f*i/3.0f * (1.0f + s * cosf(h) / cosf(1.047196667f - h));
-        r = 65535.0f*i/3.0f * (1.0f + s * (1.0f - cosf(h) / cosf(1.047196667f - h)));
-        g = 65535.0f*i/3.0f * (1.0f - s);
+        b = 65535.0f * i / 3.0f * (1.0f + s * cosf(h) / cosf(1.047196667f - h));
+        r = 65535.0f * i / 3.0f * (1.0f + s * (1.0f - cosf(h) / cosf(1.047196667f - h)));
+        g = 65535.0f * i / 3.0f * (1.0f - s);
     }
     *r_out = r > 65535 ? 65535 : r;
     *g_out = g > 65535 ? 65535 : g;
@@ -68,15 +68,15 @@ static void hsi_to_rgb(float h, float s, float i, uint16_t* r_out, uint16_t* g_o
 
 void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity) {
     uint16_t r, g, b;
-    float hue_f = 360.0f * (float)hue / 255.0f;
-    float saturation_f = (float)saturation / 255.0f;
-    float intensity_f = (float)intensity / 255.0f;
+    float    hue_f        = 360.0f * (float)hue / 255.0f;
+    float    saturation_f = (float)saturation / 255.0f;
+    float    intensity_f  = (float)intensity / 255.0f;
     intensity_f *= (float)current_brightness / 255.0f;
     hsi_to_rgb(hue_f, saturation_f, intensity_f, &r, &g, &b);
-       current_hue = hue;
-       current_saturation = saturation;
-       current_intensity = intensity;
-       lcd_backlight_hal_color(r, g, b);
+    current_hue        = hue;
+    current_saturation = saturation;
+    current_intensity  = intensity;
+    lcd_backlight_hal_color(r, g, b);
 }
 
 void lcd_backlight_brightness(uint8_t b) {
@@ -84,6 +84,4 @@ void lcd_backlight_brightness(uint8_t b) {
     lcd_backlight_color(current_hue, current_saturation, current_intensity);
 }
 
-uint8_t lcd_get_backlight_brightness(void) {
-       return current_brightness;
-}
+uint8_t lcd_get_backlight_brightness(void) { return current_brightness; }
index 95d7a07b46ee1b16d705332762d4d46239c857b3..7b0b6a9fd5366c9c4f639128a34c7cffbf354d43 100644 (file)
@@ -32,13 +32,11 @@ SOFTWARE.
 #define LCD_SAT(color) ((color >> 8) & 0xFF)
 #define LCD_INT(color) (color & 0xFF)
 
-static inline uint32_t change_lcd_color_intensity(uint32_t color, uint8_t new_intensity) {
-    return (color & 0xFFFFFF00) | new_intensity;
-}
+static inline uint32_t change_lcd_color_intensity(uint32_t color, uint8_t new_intensity) { return (color & 0xFFFFFF00) | new_intensity; }
 
-void lcd_backlight_init(void);
-void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity);
-void lcd_backlight_brightness(uint8_t b);
+void    lcd_backlight_init(void);
+void    lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity);
+void    lcd_backlight_brightness(uint8_t b);
 uint8_t lcd_get_backlight_brightness(void);
 
 void lcd_backlight_hal_init(void);
index 8c402baf6ca772d47e0d009aed49e727ed071fc6..c13cce311d58b2e7ea2c586b1d7d77df771e8f1a 100644 (file)
 #include "lcd_backlight_keyframes.h"
 
 bool lcd_backlight_keyframe_animate_color(keyframe_animation_t* animation, visualizer_state_t* state) {
-    int frame_length = animation->frame_lengths[animation->current_frame];
-    int current_pos = frame_length - animation->time_left_in_frame;
-    uint8_t t_h = LCD_HUE(state->target_lcd_color);
-    uint8_t t_s = LCD_SAT(state->target_lcd_color);
-    uint8_t t_i = LCD_INT(state->target_lcd_color);
-    uint8_t p_h = LCD_HUE(state->prev_lcd_color);
-    uint8_t p_s = LCD_SAT(state->prev_lcd_color);
-    uint8_t p_i = LCD_INT(state->prev_lcd_color);
+    int     frame_length = animation->frame_lengths[animation->current_frame];
+    int     current_pos  = frame_length - animation->time_left_in_frame;
+    uint8_t t_h          = LCD_HUE(state->target_lcd_color);
+    uint8_t t_s          = LCD_SAT(state->target_lcd_color);
+    uint8_t t_i          = LCD_INT(state->target_lcd_color);
+    uint8_t p_h          = LCD_HUE(state->prev_lcd_color);
+    uint8_t p_s          = LCD_SAT(state->prev_lcd_color);
+    uint8_t p_i          = LCD_INT(state->prev_lcd_color);
 
-    uint8_t d_h1 = t_h - p_h; //Modulo arithmetic since we want to wrap around
-    int d_h2 = t_h - p_h;
+    uint8_t d_h1 = t_h - p_h;  // Modulo arithmetic since we want to wrap around
+    int     d_h2 = t_h - p_h;
     // Chose the shortest way around
     int d_h = abs(d_h2) < d_h1 ? d_h2 : d_h1;
     int d_s = t_s - p_s;
     int d_i = t_i - p_i;
 
-    int hue = (d_h * current_pos) / frame_length;
-    int sat = (d_s * current_pos) / frame_length;
+    int hue       = (d_h * current_pos) / frame_length;
+    int sat       = (d_s * current_pos) / frame_length;
     int intensity = (d_i * current_pos) / frame_length;
-    //dprintf("%X -> %X = %X\n", p_h, t_h, hue);
+    // dprintf("%X -> %X = %X\n", p_h, t_h, hue);
     hue += p_h;
     sat += p_s;
     intensity += p_i;
     state->current_lcd_color = LCD_COLOR(hue, sat, intensity);
-    lcd_backlight_color(
-            LCD_HUE(state->current_lcd_color),
-            LCD_SAT(state->current_lcd_color),
-            LCD_INT(state->current_lcd_color));
+    lcd_backlight_color(LCD_HUE(state->current_lcd_color), LCD_SAT(state->current_lcd_color), LCD_INT(state->current_lcd_color));
 
     return true;
 }
 
 bool lcd_backlight_keyframe_set_color(keyframe_animation_t* animation, visualizer_state_t* state) {
     (void)animation;
-    state->prev_lcd_color = state->target_lcd_color;
+    state->prev_lcd_color    = state->target_lcd_color;
     state->current_lcd_color = state->target_lcd_color;
-    lcd_backlight_color(
-            LCD_HUE(state->current_lcd_color),
-            LCD_SAT(state->current_lcd_color),
-            LCD_INT(state->current_lcd_color));
+    lcd_backlight_color(LCD_HUE(state->current_lcd_color), LCD_SAT(state->current_lcd_color), LCD_INT(state->current_lcd_color));
     return false;
 }
 
@@ -70,8 +64,6 @@ bool lcd_backlight_keyframe_disable(keyframe_animation_t* animation, visualizer_
 bool lcd_backlight_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
     (void)animation;
     (void)state;
-    lcd_backlight_color(LCD_HUE(state->current_lcd_color),
-        LCD_SAT(state->current_lcd_color),
-        LCD_INT(state->current_lcd_color));
+    lcd_backlight_color(LCD_HUE(state->current_lcd_color), LCD_SAT(state->current_lcd_color), LCD_INT(state->current_lcd_color));
     return false;
 }
index 75eb457001c321f65bd799ea292e8c5655c389a2..c7d9841df3bc9839e887c57023990058d2228343 100644 (file)
@@ -28,8 +28,7 @@ bool lcd_keyframe_display_layer_text(keyframe_animation_t* animation, visualizer
 }
 
 static void format_layer_bitmap_string(uint16_t default_layer, uint16_t layer, char* buffer) {
-    for (int i=0; i<16;i++)
-    {
+    for (int i = 0; i < 16; i++) {
         uint32_t mask = (1u << i);
         if (default_layer & mask) {
             if (layer & mask) {
@@ -44,7 +43,7 @@ static void format_layer_bitmap_string(uint16_t default_layer, uint16_t layer, c
         }
         ++buffer;
 
-        if (i==3 || i==7 || i==11) {
+        if (i == 3 || i == 7 || i == 11) {
             *buffer = ' ';
             ++buffer;
         }
@@ -55,7 +54,7 @@ static void format_layer_bitmap_string(uint16_t default_layer, uint16_t layer, c
 bool lcd_keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
     (void)animation;
     const char* layer_help = "1=On D=Default B=Both";
-    char layer_buffer[16 + 4]; // 3 spaces and one null terminator
+    char        layer_buffer[16 + 4];  // 3 spaces and one null terminator
     gdispClear(White);
     gdispDrawString(0, 0, layer_help, state->font_fixed5x8, Black);
     format_layer_bitmap_string(state->status.default_layer, state->status.layer, layer_buffer);
@@ -69,8 +68,7 @@ static void format_mods_bitmap_string(uint8_t mods, char* buffer) {
     *buffer = ' ';
     ++buffer;
 
-    for (int i = 0; i<8; i++)
-    {
+    for (int i = 0; i < 8; i++) {
         uint32_t mask = (1u << i);
         if (mods & mask) {
             *buffer = '1';
@@ -79,7 +77,7 @@ static void format_mods_bitmap_string(uint8_t mods, char* buffer) {
         }
         ++buffer;
 
-        if (i==3) {
+        if (i == 3) {
             *buffer = ' ';
             ++buffer;
         }
@@ -90,9 +88,9 @@ static void format_mods_bitmap_string(uint8_t mods, char* buffer) {
 bool lcd_keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
     (void)animation;
 
-    const char* title = "Modifier states";
+    const char* title       = "Modifier states";
     const char* mods_header = " CSAG CSAG ";
-    char status_buffer[12];
+    char        status_buffer[12];
 
     gdispClear(White);
     gdispDrawString(0, 0, title, state->font_fixed5x8, Black);
@@ -109,30 +107,29 @@ static void get_led_state_string(char* output, visualizer_state_t* state) {
     uint8_t pos = 0;
 
     if (state->status.leds & (1u << USB_LED_NUM_LOCK)) {
-       memcpy(output + pos, "NUM ", 4);
-       pos += 4;
+        memcpy(output + pos, "NUM ", 4);
+        pos += 4;
     }
     if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) {
-       memcpy(output + pos, "CAPS ", 5);
-       pos += 5;
+        memcpy(output + pos, "CAPS ", 5);
+        pos += 5;
     }
     if (state->status.leds & (1u << USB_LED_SCROLL_LOCK)) {
-       memcpy(output + pos, "SCRL ", 5);
-       pos += 5;
+        memcpy(output + pos, "SCRL ", 5);
+        pos += 5;
     }
     if (state->status.leds & (1u << USB_LED_COMPOSE)) {
-       memcpy(output + pos, "COMP ", 5);
-       pos += 5;
+        memcpy(output + pos, "COMP ", 5);
+        pos += 5;
     }
     if (state->status.leds & (1u << USB_LED_KANA)) {
-       memcpy(output + pos, "KANA", 4);
-       pos += 4;
+        memcpy(output + pos, "KANA", 4);
+        pos += 4;
     }
     output[pos] = 0;
 }
 
-bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state)
-{
+bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state) {
     (void)animation;
     char output[LED_STATE_STRING_SIZE];
     get_led_state_string(output, state);
@@ -165,14 +162,13 @@ bool lcd_keyframe_draw_logo(keyframe_animation_t* animation, visualizer_state_t*
     // You can use static variables for things that can't be found in the animation
     // or state structs, here we use the image
 
-    //gdispGBlitArea is a tricky function to use since it supports blitting part of the image
+    // gdispGBlitArea is a tricky function to use since it supports blitting part of the image
     // if you have full screen image, then just use LCD_WIDTH and LCD_HEIGHT for both source and target dimensions
     gdispGBlitArea(GDISP, 0, 0, LCD_WIDTH, LCD_HEIGHT, 0, 0, LCD_WIDTH, (pixel_t*)resource_lcd_logo);
 
     return false;
 }
 
-
 bool lcd_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
     (void)animation;
     (void)state;
index 2e912b4c73d27ee703ee053a8e046331ffcec801..6346c8643b49e9fddf08fc5a4764c93a7cc2db91 100644 (file)
@@ -35,5 +35,4 @@ bool lcd_keyframe_draw_logo(keyframe_animation_t* animation, visualizer_state_t*
 bool lcd_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state);
 bool lcd_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state);
 
-
 #endif /* QUANTUM_VISUALIZER_LCD_KEYFRAMES_H_ */
index eb3f5561d86274733f84da09633c39801c87a505..d81117d2be3fbdf4880c339f74597522db1b8eb1 100644 (file)
@@ -27,15 +27,15 @@ SOFTWARE.
 
 static uint8_t fade_led_color(keyframe_animation_t* animation, int from, int to) {
     int frame_length = animation->frame_lengths[animation->current_frame];
-    int current_pos = frame_length - animation->time_left_in_frame;
-    int delta = to - from;
-    int luma = (delta * current_pos) / frame_length;
+    int current_pos  = frame_length - animation->time_left_in_frame;
+    int delta        = to - from;
+    int luma         = (delta * current_pos) / frame_length;
     luma += from;
     return luma;
 }
 
 static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint8_t from, uint8_t to) {
-    uint8_t luma = fade_led_color(animation, from, to);
+    uint8_t luma  = fade_led_color(animation, from, to);
     color_t color = LUMA2COLOR(luma);
     gdispGClear(LED_DISPLAY, color);
 }
@@ -48,10 +48,10 @@ static uint8_t crossfade_start_frame[NUM_ROWS][NUM_COLS];
 static uint8_t crossfade_end_frame[NUM_ROWS][NUM_COLS];
 
 static uint8_t compute_gradient_color(float t, float index, float num) {
-    const float two_pi = M_PI * 2.0f;
-    float normalized_index = (1.0f - index / (num - 1.0f)) * two_pi;
-    float x = t * two_pi + normalized_index;
-    float v = 0.5 * (cosf(x) + 1.0f);
+    const float two_pi           = M_PI * 2.0f;
+    float       normalized_index = (1.0f - index / (num - 1.0f)) * two_pi;
+    float       x                = t * two_pi + normalized_index;
+    float       v                = 0.5 * (cosf(x) + 1.0f);
     return (uint8_t)(255.0f * v);
 }
 
@@ -70,9 +70,9 @@ bool led_backlight_keyframe_fade_out_all(keyframe_animation_t* animation, visual
 bool led_backlight_keyframe_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
     (void)state;
     float frame_length = animation->frame_lengths[animation->current_frame];
-    float current_pos = frame_length - animation->time_left_in_frame;
-    float t = current_pos / frame_length;
-    for (int i=0; i< NUM_COLS; i++) {
+    float current_pos  = frame_length - animation->time_left_in_frame;
+    float t            = current_pos / frame_length;
+    for (int i = 0; i < NUM_COLS; i++) {
         uint8_t color = compute_gradient_color(t, i, NUM_COLS);
         gdispGDrawLine(LED_DISPLAY, i, 0, i, NUM_ROWS - 1, LUMA2COLOR(color));
     }
@@ -82,9 +82,9 @@ bool led_backlight_keyframe_left_to_right_gradient(keyframe_animation_t* animati
 bool led_backlight_keyframe_top_to_bottom_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
     (void)state;
     float frame_length = animation->frame_lengths[animation->current_frame];
-    float current_pos = frame_length - animation->time_left_in_frame;
-    float t = current_pos / frame_length;
-    for (int i=0; i< NUM_ROWS; i++) {
+    float current_pos  = frame_length - animation->time_left_in_frame;
+    float t            = current_pos / frame_length;
+    for (int i = 0; i < NUM_ROWS; i++) {
         uint8_t color = compute_gradient_color(t, i, NUM_ROWS);
         gdispGDrawLine(LED_DISPLAY, 0, i, NUM_COLS - 1, i, LUMA2COLOR(color));
     }
@@ -92,9 +92,9 @@ bool led_backlight_keyframe_top_to_bottom_gradient(keyframe_animation_t* animati
 }
 
 static void copy_current_led_state(uint8_t* dest) {
-    for (int i=0;i<NUM_ROWS;i++) {
-        for (int j=0;j<NUM_COLS;j++) {
-            dest[i*NUM_COLS + j] = gdispGGetPixelColor(LED_DISPLAY, j, i);
+    for (int i = 0; i < NUM_ROWS; i++) {
+        for (int j = 0; j < NUM_COLS; j++) {
+            dest[i * NUM_COLS + j] = gdispGGetPixelColor(LED_DISPLAY, j, i);
         }
     }
 }
@@ -105,9 +105,9 @@ bool led_backlight_keyframe_crossfade(keyframe_animation_t* animation, visualize
         run_next_keyframe(animation, state);
         copy_current_led_state(&crossfade_end_frame[0][0]);
     }
-    for (int i=0;i<NUM_ROWS;i++) {
-        for (int j=0;j<NUM_COLS;j++) {
-            color_t color  = LUMA2COLOR(fade_led_color(animation, crossfade_start_frame[i][j], crossfade_end_frame[i][j]));
+    for (int i = 0; i < NUM_ROWS; i++) {
+        for (int j = 0; j < NUM_COLS; j++) {
+            color_t color = LUMA2COLOR(fade_led_color(animation, crossfade_start_frame[i][j], crossfade_end_frame[i][j]));
             gdispGDrawPixel(LED_DISPLAY, j, i, color);
         }
     }
index 487151013a7468cce29a85883764d805935ddd84..648f92b915f7512f0c7f14174a65c348b2ce53c4 100644 (file)
@@ -40,5 +40,4 @@ bool led_backlight_keyframe_enable(keyframe_animation_t* animation, visualizer_s
 
 extern keyframe_animation_t led_test_animation;
 
-
 #endif /* LED_KEYFRAMES_H */
index 314776c0b29688c5985ac516db4b33f111bf2783..165e6d1f53e243a38a8c7f2197b9442172bd112f 100644 (file)
@@ -16,7 +16,6 @@
 
 #include "resources.h"
 
-
 // To generate an image array like this
 // Ensure the image is 128 x 32 or smaller
 // Convert the bitmap to a C array using a program like http://www.riuson.com/lcd-image-converter/
 // Update array in the source code with the C array produced by the conversion program
 
 // The image below is generated from lcd_logo.png
-__attribute__((weak))
-const uint8_t resource_lcd_logo[512] = {
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0xf8, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x38, 0x38, 0x38, 0x06, 0x29, 0x41, 0x24, 0x52, 0x24, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x42, 0xaa, 0xaa, 0xaa, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x82, 0x28, 0xaa, 0xae, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x43, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x38, 0x38, 0x38, 0x0a, 0x55, 0x42, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x38, 0x38, 0x38, 0x05, 0x45, 0x42, 0x28, 0x89, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x18, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x1c, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x0e, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x03, 0xff, 0x80, 0x04, 0x45, 0x14, 0xa4, 0x92, 0x83, 0x52, 0x22, 0x22, 0x36, 0x00, 0x00,
-    0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0xba, 0x84, 0x55, 0x55, 0x57, 0x45, 0x00, 0x00,
-    0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0xb2, 0x55, 0x55, 0x42, 0x65, 0x00, 0x00,
-    0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x56, 0x65, 0x42, 0x45, 0x00, 0x00,
-    0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x54, 0x45, 0x42, 0x45, 0x00, 0x00,
-    0x00, 0x00, 0x38, 0x00, 0x04, 0x48, 0xa2, 0x4a, 0x89, 0x06, 0x24, 0x42, 0x41, 0x36, 0x00, 0x00,
-    0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
+__attribute__((weak)) const uint8_t resource_lcd_logo[512] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                              0x00, 0x38, 0x38, 0x38, 0x06, 0x29, 0x41, 0x24, 0x52, 0x24, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x42, 0xaa, 0xaa, 0xaa, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x82, 0x28, 0xaa, 0xae, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x43, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x0a, 0x55, 0x42, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x05, 0x45, 0x42, 0x28, 0x89, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                              0x00, 0x0e, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x80, 0x04, 0x45, 0x14, 0xa4, 0x92, 0x83, 0x52, 0x22, 0x22, 0x36, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0xba, 0x84, 0x55, 0x55, 0x57, 0x45, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0xb2, 0x55, 0x55, 0x42, 0x65, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x56, 0x65, 0x42, 0x45, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x54, 0x45, 0x42, 0x45, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x04, 0x48, 0xa2, 0x4a, 0x89, 0x06, 0x24, 0x42, 0x41, 0x36, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                              0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
index 1ea27a5364ae9ad07d7327a6dd465ee00cdf0862..74fd8d2f6522133b1176d050f0016f130b3fd21d 100644 (file)
@@ -23,5 +23,4 @@
 extern const uint8_t resource_lcd_logo[];
 #endif
 
-
 #endif /* QUANTUM_VISUALIZER_RESOURCES_RESOURCES_H_ */
index 516cf2a84792ca70e75135013b222fe0d0cf90b0..3f182e74d8529b8e6fe8abe995234599e185c9db 100644 (file)
@@ -26,26 +26,26 @@ SOFTWARE.
 #include "visualizer.h"
 #include <string.h>
 #ifdef PROTOCOL_CHIBIOS
-#include "ch.h"
+#    include "ch.h"
 #endif
 
 #include "gfx.h"
 
 #ifdef LCD_BACKLIGHT_ENABLE
-#include "lcd_backlight.h"
+#    include "lcd_backlight.h"
 #endif
 
 //#define DEBUG_VISUALIZER
 
 #ifdef DEBUG_VISUALIZER
-#include "debug.h"
+#    include "debug.h"
 #else
-#include "nodebug.h"
+#    include "nodebug.h"
 #endif
 
 #ifdef SERIAL_LINK_ENABLE
-#include "serial_link/protocol/transport.h"
-#include "serial_link/system/serial_link.h"
+#    include "serial_link/protocol/transport.h"
+#    include "serial_link/system/serial_link.h"
 #endif
 
 #include "action_util.h"
@@ -53,36 +53,31 @@ SOFTWARE.
 // Define this in config.h
 #ifndef VISUALIZER_THREAD_PRIORITY
 // The visualizer needs gfx thread priorities
-#define VISUALIZER_THREAD_PRIORITY (NORMAL_PRIORITY - 2)
+#    define VISUALIZER_THREAD_PRIORITY (NORMAL_PRIORITY - 2)
 #endif
 
-static visualizer_keyboard_status_t current_status = {
-    .layer = 0xFFFFFFFF,
-    .default_layer = 0xFFFFFFFF,
-    .leds = 0xFFFFFFFF,
+static visualizer_keyboard_status_t current_status = {.layer         = 0xFFFFFFFF,
+                                                      .default_layer = 0xFFFFFFFF,
+                                                      .leds          = 0xFFFFFFFF,
 #ifdef BACKLIGHT_ENABLE
-    .backlight_level = 0,
+                                                      .backlight_level = 0,
 #endif
-    .mods = 0xFF,
-    .suspended = false,
+                                                      .mods      = 0xFF,
+                                                      .suspended = false,
 #ifdef VISUALIZER_USER_DATA_SIZE
-    .user_data = {0}
+                                                      .user_data = {0}
 #endif
 };
 
 static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) {
-    return status1->layer == status2->layer &&
-        status1->default_layer == status2->default_layer &&
-        status1->mods == status2->mods &&
-        status1->leds == status2->leds &&
-        status1->suspended == status2->suspended
+    return status1->layer == status2->layer && status1->default_layer == status2->default_layer && status1->mods == status2->mods && status1->leds == status2->leds && status1->suspended == status2->suspended
 #ifdef BACKLIGHT_ENABLE
-        && status1->backlight_level == status2->backlight_level
+           && status1->backlight_level == status2->backlight_level
 #endif
 #ifdef VISUALIZER_USER_DATA_SIZE
-        && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0
+           && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0
 #endif
-    ;
+        ;
 }
 
 static bool visualizer_enabled = false;
@@ -107,44 +102,38 @@ GDisplay* LCD_DISPLAY = 0;
 GDisplay* LED_DISPLAY = 0;
 
 #ifdef LCD_DISPLAY_NUMBER
-__attribute__((weak))
-GDisplay* get_lcd_display(void) {
-    return gdispGetDisplay(LCD_DISPLAY_NUMBER);
-}
+__attribute__((weak)) GDisplay* get_lcd_display(void) { return gdispGetDisplay(LCD_DISPLAY_NUMBER); }
 #endif
 
 #ifdef LED_DISPLAY_NUMBER
-__attribute__((weak))
-GDisplay* get_led_display(void) {
-    return gdispGetDisplay(LED_DISPLAY_NUMBER);
-}
+__attribute__((weak)) GDisplay* get_led_display(void) { return gdispGetDisplay(LED_DISPLAY_NUMBER); }
 #endif
 
 void start_keyframe_animation(keyframe_animation_t* animation) {
-    animation->current_frame = -1;
+    animation->current_frame      = -1;
     animation->time_left_in_frame = 0;
-    animation->need_update = true;
-    int free_index = -1;
-    for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
+    animation->need_update        = true;
+    int free_index                = -1;
+    for (int i = 0; i < MAX_SIMULTANEOUS_ANIMATIONS; i++) {
         if (animations[i] == animation) {
             return;
         }
         if (free_index == -1 && animations[i] == NULL) {
-           free_index=i;
+            free_index = i;
         }
     }
-    if (free_index!=-1) {
+    if (free_index != -1) {
         animations[free_index] = animation;
     }
 }
 
 void stop_keyframe_animation(keyframe_animation_t* animation) {
-    animation->current_frame = animation->num_frames;
-    animation->time_left_in_frame = 0;
-    animation->need_update = true;
+    animation->current_frame         = animation->num_frames;
+    animation->time_left_in_frame    = 0;
+    animation->need_update           = true;
     animation->first_update_of_frame = false;
-    animation->last_update_of_frame = false;
-    for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
+    animation->last_update_of_frame  = false;
+    for (int i = 0; i < MAX_SIMULTANEOUS_ANIMATIONS; i++) {
         if (animations[i] == animation) {
             animations[i] = NULL;
             return;
@@ -153,21 +142,21 @@ void stop_keyframe_animation(keyframe_animation_t* animation) {
 }
 
 void stop_all_keyframe_animations(void) {
-    for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
+    for (int i = 0; i < MAX_SIMULTANEOUS_ANIMATIONS; i++) {
         if (animations[i]) {
-            animations[i]->current_frame = animations[i]->num_frames;
-            animations[i]->time_left_in_frame = 0;
-            animations[i]->need_update = true;
+            animations[i]->current_frame         = animations[i]->num_frames;
+            animations[i]->time_left_in_frame    = 0;
+            animations[i]->need_update           = true;
             animations[i]->first_update_of_frame = false;
-            animations[i]->last_update_of_frame = false;
-            animations[i] = NULL;
+            animations[i]->last_update_of_frame  = false;
+            animations[i]                        = NULL;
         }
     }
 }
 
 static uint8_t get_num_running_animations(void) {
     uint8_t count = 0;
-    for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
+    for (int i = 0; i < MAX_SIMULTANEOUS_ANIMATIONS; i++) {
         count += animations[i] ? 1 : 0;
     }
     return count;
@@ -175,46 +164,44 @@ static uint8_t get_num_running_animations(void) {
 
 static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) {
     // TODO: Clean up this messy code
-    dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame,
-            animation->time_left_in_frame, delta);
+    dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame, animation->time_left_in_frame, delta);
     if (animation->current_frame == animation->num_frames) {
         animation->need_update = false;
         return false;
     }
     if (animation->current_frame == -1) {
-       animation->current_frame = 0;
-       animation->time_left_in_frame = animation->frame_lengths[0];
-       animation->need_update = true;
-       animation->first_update_of_frame = true;
+        animation->current_frame         = 0;
+        animation->time_left_in_frame    = animation->frame_lengths[0];
+        animation->need_update           = true;
+        animation->first_update_of_frame = true;
     } else {
         animation->time_left_in_frame -= delta;
         while (animation->time_left_in_frame <= 0) {
             int left = animation->time_left_in_frame;
             if (animation->need_update) {
-                animation->time_left_in_frame = 0;
+                animation->time_left_in_frame   = 0;
                 animation->last_update_of_frame = true;
                 (*animation->frame_functions[animation->current_frame])(animation, state);
                 animation->last_update_of_frame = false;
             }
             animation->current_frame++;
-            animation->need_update = true;
+            animation->need_update           = true;
             animation->first_update_of_frame = true;
             if (animation->current_frame == animation->num_frames) {
                 if (animation->loop) {
                     animation->current_frame = 0;
-                }
-                else {
+                } else {
                     stop_keyframe_animation(animation);
                     return false;
                 }
             }
-            delta = -left;
+            delta                         = -left;
             animation->time_left_in_frame = animation->frame_lengths[animation->current_frame];
             animation->time_left_in_frame -= delta;
         }
     }
     if (animation->need_update) {
-        animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state);
+        animation->need_update           = (*animation->frame_functions[animation->current_frame])(animation, state);
         animation->first_update_of_frame = false;
     }
 
@@ -231,13 +218,13 @@ void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* stat
     if (next_frame == animation->num_frames) {
         next_frame = 0;
     }
-    keyframe_animation_t temp_animation = *animation;
-    temp_animation.current_frame = next_frame;
-    temp_animation.time_left_in_frame = animation->frame_lengths[next_frame];
+    keyframe_animation_t temp_animation  = *animation;
+    temp_animation.current_frame         = next_frame;
+    temp_animation.time_left_in_frame    = animation->frame_lengths[next_frame];
     temp_animation.first_update_of_frame = true;
-    temp_animation.last_update_of_frame = false;
-    temp_animation.need_update  = false;
-    visualizer_state_t temp_state = *state;
+    temp_animation.last_update_of_frame  = false;
+    temp_animation.need_update           = false;
+    visualizer_state_t temp_state        = *state;
     (*temp_animation.frame_functions[next_frame])(&temp_animation, &temp_state);
 }
 
@@ -252,70 +239,64 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
 
     visualizer_keyboard_status_t initial_status = {
         .default_layer = 0xFFFFFFFF,
-        .layer = 0xFFFFFFFF,
-        .mods = 0xFF,
-        .leds = 0xFFFFFFFF,
-        .suspended = false,
-    #ifdef BACKLIGHT_ENABLE
+        .layer         = 0xFFFFFFFF,
+        .mods          = 0xFF,
+        .leds          = 0xFFFFFFFF,
+        .suspended     = false,
+#ifdef BACKLIGHT_ENABLE
         .backlight_level = 0,
-    #endif
-    #ifdef VISUALIZER_USER_DATA_SIZE
+#endif
+#ifdef VISUALIZER_USER_DATA_SIZE
         .user_data = {0},
-    #endif
+#endif
     };
 
-    visualizer_state_t state = {
-        .status = initial_status,
-        .current_lcd_color = 0,
+    visualizer_state_t state = {.status            = initial_status,
+                                .current_lcd_color = 0,
 #ifdef LCD_ENABLE
-        .font_fixed5x8 = gdispOpenFont("fixed_5x8"),
-        .font_dejavusansbold12 = gdispOpenFont("DejaVuSansBold12")
+                                .font_fixed5x8         = gdispOpenFont("fixed_5x8"),
+                                .font_dejavusansbold12 = gdispOpenFont("DejaVuSansBold12")
 #endif
     };
     initialize_user_visualizer(&state);
     state.prev_lcd_color = state.current_lcd_color;
 
 #ifdef LCD_BACKLIGHT_ENABLE
-    lcd_backlight_color(
-            LCD_HUE(state.current_lcd_color),
-            LCD_SAT(state.current_lcd_color),
-            LCD_INT(state.current_lcd_color));
+    lcd_backlight_color(LCD_HUE(state.current_lcd_color), LCD_SAT(state.current_lcd_color), LCD_INT(state.current_lcd_color));
 #endif
 
-    systemticks_t sleep_time = TIME_INFINITE;
+    systemticks_t sleep_time   = TIME_INFINITE;
     systemticks_t current_time = gfxSystemTicks();
-    bool force_update = true;
+    bool          force_update = true;
 
-    while(true) {
+    while (true) {
         systemticks_t new_time = gfxSystemTicks();
-        systemticks_t delta = new_time - current_time;
-        current_time = new_time;
-        bool enabled = visualizer_enabled;
+        systemticks_t delta    = new_time - current_time;
+        current_time           = new_time;
+        bool enabled           = visualizer_enabled;
         if (force_update || !same_status(&state.status, &current_status)) {
             force_update = false;
-    #if BACKLIGHT_ENABLE
-            if(current_status.backlight_level != state.status.backlight_level) {
+#if BACKLIGHT_ENABLE
+            if (current_status.backlight_level != state.status.backlight_level) {
                 if (current_status.backlight_level != 0) {
                     gdispGSetPowerMode(LED_DISPLAY, powerOn);
                     uint16_t percent = (uint16_t)current_status.backlight_level * 100 / BACKLIGHT_LEVELS;
                     gdispGSetBacklight(LED_DISPLAY, percent);
-                }
-                else {
+                } else {
                     gdispGSetPowerMode(LED_DISPLAY, powerOff);
                 }
                 state.status.backlight_level = current_status.backlight_level;
             }
-    #endif
+#endif
             if (visualizer_enabled) {
                 if (current_status.suspended) {
                     stop_all_keyframe_animations();
                     visualizer_enabled = false;
-                    state.status = current_status;
+                    state.status       = current_status;
                     user_visualizer_suspend(&state);
-                }
-                else {
+                } else {
                     visualizer_keyboard_status_t prev_status = state.status;
-                    state.status = current_status;
+                    state.status                             = current_status;
                     update_user_visualizer_state(&state, &prev_status);
                 }
                 state.prev_lcd_color = state.current_lcd_color;
@@ -324,14 +305,14 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
         if (!enabled && state.status.suspended && current_status.suspended == false) {
             // Setting the status to the initial status will force an update
             // when the visualizer is enabled again
-            state.status = initial_status;
+            state.status           = initial_status;
             state.status.suspended = false;
             stop_all_keyframe_animations();
             user_visualizer_resume(&state);
             state.prev_lcd_color = state.current_lcd_color;
         }
         sleep_time = TIME_INFINITE;
-        for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
+        for (int i = 0; i < MAX_SIMULTANEOUS_ANIMATIONS; i++) {
             if (animations[i]) {
                 update_keyframe_animation(animations[i], &state, delta, &sleep_time);
             }
@@ -350,17 +331,16 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
         // Enable the visualizer when the startup or the suspend animation has finished
         if (!visualizer_enabled && state.status.suspended == false && get_num_running_animations() == 0) {
             visualizer_enabled = true;
-            force_update = true;
-            sleep_time = 0;
+            force_update       = true;
+            sleep_time         = 0;
         }
 
         systemticks_t after_update = gfxSystemTicks();
-        unsigned update_delta = after_update - current_time;
+        unsigned      update_delta = after_update - current_time;
         if (sleep_time != TIME_INFINITE) {
             if (sleep_time > update_delta) {
                 sleep_time -= update_delta;
-            }
-            else {
+            } else {
                 sleep_time = 0;
             }
         }
@@ -388,26 +368,25 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
 void visualizer_init(void) {
     gfxInit();
 
-  #ifdef LCD_BACKLIGHT_ENABLE
+#ifdef LCD_BACKLIGHT_ENABLE
     lcd_backlight_init();
-  #endif
+#endif
 
-  #ifdef SERIAL_LINK_ENABLE
-    add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) );
-  #endif
+#ifdef SERIAL_LINK_ENABLE
+    add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*));
+#endif
 
-  #ifdef LCD_ENABLE
+#ifdef LCD_ENABLE
     LCD_DISPLAY = get_lcd_display();
-  #endif
+#endif
 
-  #ifdef BACKLIGHT_ENABLE
+#ifdef BACKLIGHT_ENABLE
     LED_DISPLAY = get_led_display();
-  #endif
+#endif
 
     // We are using a low priority thread, the idea is to have it run only
     // when the main thread is sleeping during the matrix scanning
-  gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack),
-                  VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL);
+    gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack), VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL);
 }
 
 void update_status(bool changed) {
@@ -418,33 +397,31 @@ void update_status(bool changed) {
         }
     }
 #ifdef SERIAL_LINK_ENABLE
-    static systime_t last_update = 0;
-    systime_t current_update = chVTGetSystemTimeX();
-    systime_t delta = current_update - last_update;
+    static systime_t last_update    = 0;
+    systime_t        current_update = chVTGetSystemTimeX();
+    systime_t        delta          = current_update - last_update;
     if (changed || delta > MS2ST(10)) {
-        last_update = current_update;
+        last_update                     = current_update;
         visualizer_keyboard_status_t* r = begin_write_current_status();
-        *r = current_status;
+        *r                              = current_status;
         end_write_current_status();
     }
 #endif
 }
 
 uint8_t visualizer_get_mods() {
-  uint8_t mods = get_mods();
+    uint8_t mods = get_mods();
 
 #ifndef NO_ACTION_ONESHOT
-  if (!has_oneshot_mods_timed_out()) {
-    mods |= get_oneshot_mods();
-  }
+    if (!has_oneshot_mods_timed_out()) {
+        mods |= get_oneshot_mods();
+    }
 #endif
-  return mods;
+    return mods;
 }
 
 #ifdef VISUALIZER_USER_DATA_SIZE
-void visualizer_set_user_data(void* u) {
-    memcpy(user_data, u, VISUALIZER_USER_DATA_SIZE);
-}
+void visualizer_set_user_data(void* u) { memcpy(user_data, u, VISUALIZER_USER_DATA_SIZE); }
 #endif
 
 void visualizer_update(layer_state_t default_state, layer_state_t state, uint8_t mods, uint32_t leds) {
@@ -455,34 +432,33 @@ void visualizer_update(layer_state_t default_state, layer_state_t state, uint8_t
 
     bool changed = false;
 #ifdef SERIAL_LINK_ENABLE
-    if (is_serial_link_connected ()) {
+    if (is_serial_link_connected()) {
         visualizer_keyboard_status_t* new_status = read_current_status();
         if (new_status) {
             if (!same_status(&current_status, new_status)) {
-                changed = true;
+                changed        = true;
                 current_status = *new_status;
             }
         }
-    }
-    else {
+    } else {
 #else
-   {
+    {
 #endif
         visualizer_keyboard_status_t new_status = {
-            .layer = state,
+            .layer         = state,
             .default_layer = default_state,
-            .mods = mods,
-            .leds = leds,
+            .mods          = mods,
+            .leds          = leds,
 #ifdef BACKLIGHT_ENABLE
             .backlight_level = current_status.backlight_level,
 #endif
             .suspended = current_status.suspended,
         };
 #ifdef VISUALIZER_USER_DATA_SIZE
-       memcpy(new_status.user_data, user_data, VISUALIZER_USER_DATA_SIZE);
+        memcpy(new_status.user_data, user_data, VISUALIZER_USER_DATA_SIZE);
 #endif
         if (!same_status(&current_status, &new_status)) {
-            changed = true;
+            changed        = true;
             current_status = new_status;
         }
     }
index 56ea1fd98c29b15e743768ad4077de2ea00b90f2..7ca6837ce60aba50bdd84d49347d9c7ec3890369 100644 (file)
@@ -33,11 +33,11 @@ SOFTWARE.
 #include "action_layer.h"
 
 #ifdef LCD_BACKLIGHT_ENABLE
-#include "lcd_backlight.h"
+#    include "lcd_backlight.h"
 #endif
 
 #ifdef BACKLIGHT_ENABLE
-#include "backlight.h"
+#    include "backlight.h"
 #endif
 
 // use this function to merge both real_mods and oneshot_mods in a uint16_t
@@ -71,9 +71,9 @@ struct keyframe_animation_t;
 typedef struct {
     layer_state_t layer;
     layer_state_t default_layer;
-    uint32_t leds; // See led.h for available statuses
-    uint8_t mods;
-    bool suspended;
+    uint32_t      leds;  // See led.h for available statuses
+    uint8_t       mods;
+    bool          suspended;
 #ifdef BACKLIGHT_ENABLE
     uint8_t backlight_level;
 #endif
@@ -87,7 +87,7 @@ typedef struct {
 // from the user customized code
 typedef struct visualizer_state_t {
     // The user code should primarily be modifying these
-    uint32_t target_lcd_color;
+    uint32_t    target_lcd_color;
     const char* layer_text;
 
     // The user visualizer(and animation functions) can read these
@@ -111,15 +111,15 @@ typedef bool (*frame_func)(struct keyframe_animation_t*, visualizer_state_t*);
 // while others are meant to be initialized by the user code
 typedef struct keyframe_animation_t {
     // These should be initialized
-    int num_frames;
-    bool loop;
-    int frame_lengths[MAX_VISUALIZER_KEY_FRAMES];
+    int        num_frames;
+    bool       loop;
+    int        frame_lengths[MAX_VISUALIZER_KEY_FRAMES];
     frame_func frame_functions[MAX_VISUALIZER_KEY_FRAMES];
 
     // Used internally by the system, and can also be read by
     // keyframe update functions
-    int current_frame;
-    int time_left_in_frame;
+    int  current_frame;
+    int  time_left_in_frame;
     bool first_update_of_frame;
     bool last_update_of_frame;
     bool need_update;
index 5dd9aaeb6ee947d69e7fde8c2be89c00c7fbb996..02b3cc961a2ba78119f75b3727b47a155f55697b 100644 (file)
 
 #define COMBO1 RSFT(LCTL(KC_O))
 
-const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
-    [0] = {
-        // 0    1      2      3        4        5        6       7            8      9
-        {KC_A,  KC_B,  KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0),  KC_NO},
-        {KC_NO, KC_NO, KC_NO, KC_NO,   KC_NO,   KC_NO,   KC_NO,  KC_NO,       KC_NO, KC_NO},
-        {KC_NO, KC_NO, KC_NO, KC_NO,   KC_NO,   KC_NO,   KC_NO,  KC_NO,       KC_NO, KC_NO},
-        {KC_C,  KC_D,  KC_NO, KC_NO,   KC_NO,   KC_NO,   KC_NO,  KC_NO,       KC_NO, KC_NO},
-    },
+const uint16_t PROGMEM
+               keymaps[][MATRIX_ROWS][MATRIX_COLS] =
+        {
+            [0] =
+                {
+                    // 0    1      2      3        4        5        6       7            8      9
+                    {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0), KC_NO},
+                    {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
+                    {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
+                    {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
+                },
 };
 
 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
     if (record->event.pressed) {
-        switch(id) {
-        case 0:
-            return MACRO(D(LSFT), T(H), U(LSFT), T(E), T(L), T(L), T(O), T(SPACE), W(100), 
-            D(LSFT), T(W), U(LSFT), I(10), T(O), T(R), T(L), T(D), D(LSFT), T(1), U(LSFT), END);
+        switch (id) {
+            case 0:
+                return MACRO(D(LSFT), T(H), U(LSFT), T(E), T(L), T(L), T(O), T(SPACE), W(100), D(LSFT), T(W), U(LSFT), I(10), T(O), T(R), T(L), T(D), D(LSFT), T(1), U(LSFT), END);
         }
     }
     return MACRO_NONE;
index 194b1745b125870cd79a87ca4fd9143118fa2812..e5247911cbb9b2e5423465f7542f26eb3eb0bd09 100644 (file)
@@ -41,15 +41,15 @@ TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
     TestDriver driver;
     press_key(1, 0);
     press_key(0, 3);
-    //Note that QMK only processes one key at a time
-    //See issue #1476 for more information
+    // Note that QMK only processes one key at a time
+    // See issue #1476 for more information
     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
     keyboard_task();
     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
     keyboard_task();
     release_key(1, 0);
     release_key(0, 3);
-    //Note that the first key released is the first one in the matrix order
+    // Note that the first key released is the first one in the matrix order
     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C)));
     keyboard_task();
     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
index 80676d515319cf0f3420243d394585a1d49c788d..a1fa3170897b34d6e2d3d8117fcc39383912453e 100644 (file)
@@ -22,78 +22,50 @@ using testing::InvokeWithoutArgs;
 
 class Macro : public TestFixture {};
 
-#define AT_TIME(t) WillOnce(InvokeWithoutArgs([current_time]() {EXPECT_EQ(timer_elapsed32(current_time), t);}))
+#define AT_TIME(t) WillOnce(InvokeWithoutArgs([current_time]() { EXPECT_EQ(timer_elapsed32(current_time), t); }))
 
 TEST_F(Macro, PlayASimpleMacro) {
     TestDriver driver;
     InSequence s;
     press_key(8, 0);
     uint32_t current_time = timer_read32();
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_H)))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E)))
-        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_H))).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E))).AT_TIME(0);
     // The macro system could actually skip these empty keyboard reports
     // it should be enough to just send a report with the next key down
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O)))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_SPACE)))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
-        .AT_TIME(100);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_W)))
-        .AT_TIME(100);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
-        .AT_TIME(100);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(100);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O))).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_SPACE))).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(100);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_W))).AT_TIME(100);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(100);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(100);
     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O)))
-    // BUG: The timer should not really have advanced 10 ms here
-    // See issue #1477
+        // BUG: The timer should not really have advanced 10 ms here
+        // See issue #1477
         .AT_TIME(110);
     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-    // BUG: The timer should not advance on both keydown and key-up
-    // See issue #1477
+        // BUG: The timer should not advance on both keydown and key-up
+        // See issue #1477
         .AT_TIME(120);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R)))
-        .AT_TIME(130);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(140);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)))
-        .AT_TIME(150);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(160);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_D)))
-        .AT_TIME(170);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(180);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
-        .AT_TIME(190);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_1)))
-        .AT_TIME(200);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
-        .AT_TIME(210);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
-        .AT_TIME(220);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R))).AT_TIME(130);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(140);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(150);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(160);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_D))).AT_TIME(170);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(180);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(190);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_1))).AT_TIME(200);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(210);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(220);
     run_one_scan_loop();
 }
\ No newline at end of file
index bf728b9a2a801bba3c4efcfa84a09ea6e55be4b5..245072c0ea53aa3e3cc82aad248d5a31a7885a3f 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
- #include "keyboard_report_util.hpp"
- #include <vector>
- #include <algorithm>
- using namespace testing;
+#include "keyboard_report_util.hpp"
+#include <vector>
+#include <algorithm>
+using namespace testing;
 
- namespace
- {
-     std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
-        std::vector<uint8_t> result;
-        #if defined(NKRO_ENABLE)
-        #error NKRO support not implemented yet
-        #elif defined(USB_6KRO_ENABLE)
-        #error 6KRO support not implemented yet
-        #else
-        for(size_t i=0; i<KEYBOARD_REPORT_KEYS; i++) {
-            if (report.keys[i]) {
-                result.emplace_back(report.keys[i]);
-            }
+namespace {
+std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
+    std::vector<uint8_t> result;
+#if defined(NKRO_ENABLE)
+#    error NKRO support not implemented yet
+#elif defined(USB_6KRO_ENABLE)
+#    error 6KRO support not implemented yet
+#else
+    for (size_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
+        if (report.keys[i]) {
+            result.emplace_back(report.keys[i]);
         }
-        #endif
-        std::sort(result.begin(), result.end());
-        return result;
-     }
- }
+    }
+#endif
+    std::sort(result.begin(), result.end());
+    return result;
+}
+}  // namespace
 
 bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
     auto lhskeys = get_keys(lhs);
@@ -50,7 +49,7 @@ std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
     stream << "Mods: " << (uint32_t)value.mods << std::endl;
     stream << "Keys: ";
     // TODO: This should probably print friendly names for the keys
-    for (uint32_t k: get_keys(value)) {
+    for (uint32_t k : get_keys(value)) {
         stream << k << " ";
     }
     stream << std::endl;
@@ -59,24 +58,17 @@ std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
 
 KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
     memset(m_report.raw, 0, sizeof(m_report.raw));
-    for (auto k: keys) {
+    for (auto k : keys) {
         if (IS_MOD(k)) {
             m_report.mods |= MOD_BIT(k);
-        }
-        else {
+        } else {
             add_key_to_report(&m_report, k);
         }
     }
 }
 
-bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const {
-    return m_report == report;
-}
+bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const { return m_report == report; }
 
-void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const {
-    *os << "is equal to " << m_report;
-}
+void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const { *os << "is equal to " << m_report; }
 
-void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const {
-    *os << "is not equal to " << m_report;
-}
\ No newline at end of file
+void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const { *os << "is not equal to " << m_report; }
\ No newline at end of file
index 4b501039b6bb2c45c27a88de32871637cf8e5b40..9a92a801c78061f23df4710ded9352ae2dda8569 100644 (file)
@@ -14,7 +14,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #include "matrix.h"
 #include "test_matrix.h"
 #include <string.h>
@@ -31,33 +30,18 @@ uint8_t matrix_scan(void) {
     return 1;
 }
 
-matrix_row_t matrix_get_row(uint8_t row) {
-    return matrix[row];
-}
-
-void matrix_print(void) {
-
-}
-
-void matrix_init_kb(void) {
+matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; }
 
-}
+void matrix_print(void) {}
 
-void matrix_scan_kb(void) {
+void matrix_init_kb(void) {}
 
-}
+void matrix_scan_kb(void) {}
 
-void press_key(uint8_t col, uint8_t row) {
-    matrix[row] |= 1 << col;
-}
+void press_key(uint8_t col, uint8_t row) { matrix[row] |= 1 << col; }
 
-void release_key(uint8_t col, uint8_t row) {
-    matrix[row] &= ~(1 << col);
-}
+void release_key(uint8_t col, uint8_t row) { matrix[row] &= ~(1 << col); }
 
-void clear_all_keys(void) {
-    memset(matrix, 0, sizeof(matrix));
-}
+void clear_all_keys(void) { memset(matrix, 0, sizeof(matrix)); }
 
-void led_set(uint8_t usb_led) {
-}
+void led_set(uint8_t usb_led) {}
index 5113099698707fff9dea1ab60a74af73b1222ace..84e249d838e523b016bccdb60bf3c888d7eb5975 100644 (file)
 
 TestDriver* TestDriver::m_this = nullptr;
 
-TestDriver::TestDriver()
-    : m_driver{
-        &TestDriver::keyboard_leds,
-        &TestDriver::send_keyboard,
-        &TestDriver::send_mouse,
-        &TestDriver::send_system,
-        &TestDriver::send_consumer
-    }
-{
+TestDriver::TestDriver() : m_driver{&TestDriver::keyboard_leds, &TestDriver::send_keyboard, &TestDriver::send_mouse, &TestDriver::send_system, &TestDriver::send_consumer} {
     host_set_driver(&m_driver);
     m_this = this;
 }
 
-TestDriver::~TestDriver() {
-    m_this = nullptr;
-}
+TestDriver::~TestDriver() { m_this = nullptr; }
 
-uint8_t TestDriver::keyboard_leds(void) {
-    return m_this->m_leds;
-}
+uint8_t TestDriver::keyboard_leds(void) { return m_this->m_leds; }
 
-void TestDriver::send_keyboard(report_keyboard_t* report) {
-    m_this->send_keyboard_mock(*report);
+void TestDriver::send_keyboard(report_keyboard_t* report) { m_this->send_keyboard_mock(*report); }
 
-}
+void TestDriver::send_mouse(report_mouse_t* report) { m_this->send_mouse_mock(*report); }
 
-void TestDriver::send_mouse(report_mouse_t* report) {
-    m_this->send_mouse_mock(*report);
-}
+void TestDriver::send_system(uint16_t data) { m_this->send_system_mock(data); }
 
-void TestDriver::send_system(uint16_t data) {
-    m_this->send_system_mock(data);
-}
-
-void TestDriver::send_consumer(uint16_t data) {
-    m_this->send_consumer(data);
-}
+void TestDriver::send_consumer(uint16_t data) { m_this->send_consumer(data); }
index d86681eeaa35b722c032cbb1cc32eea3312cf1c0..8caf1fca4a1d147e30be45907ba0daf59d755aa2 100644 (file)
@@ -11,14 +11,14 @@ extern "C" {
 }
 
 extern "C" {
-    void set_time(uint32_t t);
-    void advance_time(uint32_t ms);
+void set_time(uint32_t t);
+void advance_time(uint32_t ms);
 }
 
 using testing::_;
 using testing::AnyNumber;
-using testing::Return;
 using testing::Between;
+using testing::Return;
 
 void TestFixture::SetUpTestCase() {
     TestDriver driver;
@@ -26,11 +26,9 @@ void TestFixture::SetUpTestCase() {
     keyboard_init();
 }
 
-void TestFixture::TearDownTestCase() {
-}
+void TestFixture::TearDownTestCase() {}
 
-TestFixture::TestFixture() {
-}
+TestFixture::TestFixture() {}
 
 TestFixture::~TestFixture() {
     TestDriver driver;
@@ -50,7 +48,7 @@ void TestFixture::run_one_scan_loop() {
 }
 
 void TestFixture::idle_for(unsigned time) {
-    for (unsigned i=0; i<time; i++) {
+    for (unsigned i = 0; i < time; i++) {
         run_one_scan_loop();
     }
 }
index f47fd20fc96877f739b5a3ba6069fba7cefd5f98..1ba38a285ed8ffdf7defcaf8e2f111e606d66b86 100644 (file)
@@ -29,9 +29,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "wait.h"
 
 #ifdef DEBUG_ACTION
-#include "debug.h"
+#    include "debug.h"
 #else
-#include "nodebug.h"
+#    include "nodebug.h"
 #endif
 
 int tp_buttons;
@@ -41,24 +41,25 @@ int retro_tapping_counter = 0;
 #endif
 
 #ifdef FAUXCLICKY_ENABLE
-#include <fauxclicky.h>
+#    include <fauxclicky.h>
 #endif
 
 #ifndef TAP_CODE_DELAY
-#  define TAP_CODE_DELAY 0
+#    define TAP_CODE_DELAY 0
 #endif
 #ifndef TAP_HOLD_CAPS_DELAY
-#  define TAP_HOLD_CAPS_DELAY 80
+#    define TAP_HOLD_CAPS_DELAY 80
 #endif
 /** \brief Called to execute an action.
  *
  * FIXME: Needs documentation.
  */
-void action_exec(keyevent_t event)
-{
+void action_exec(keyevent_t event) {
     if (!IS_NOEVENT(event)) {
         dprint("\n---- action_exec: start -----\n");
-        dprint("EVENT: "); debug_event(event); dprintln();
+        dprint("EVENT: ");
+        debug_event(event);
+        dprintln();
 #ifdef RETRO_TAPPING
         retro_tapping_counter++;
 #endif
@@ -80,7 +81,7 @@ void action_exec(keyevent_t event)
     }
 #endif
 
-    keyrecord_t record = { .event = event };
+    keyrecord_t record = {.event = event};
 
 #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
     if (has_oneshot_layer_timed_out()) {
@@ -96,14 +97,16 @@ void action_exec(keyevent_t event)
 #else
     process_record(&record);
     if (!IS_NOEVENT(record.event)) {
-        dprint("processed: "); debug_record(record); dprintln();
+        dprint("processed: ");
+        debug_record(record);
+        dprintln();
     }
 #endif
 }
 
 #ifdef SWAP_HANDS_ENABLE
 bool swap_hands = false;
-bool swap_held = false;
+bool swap_held  = false;
 
 /** \brief Process Hand Swap
  *
@@ -112,10 +115,9 @@ bool swap_held = false;
 void process_hand_swap(keyevent_t *event) {
     static swap_state_row_t swap_state[MATRIX_ROWS];
 
-    keypos_t pos = event->key;
-    swap_state_row_t col_bit = (swap_state_row_t)1<<pos.col;
-    bool do_swap = event->pressed ? swap_hands :
-                                    swap_state[pos.row] & (col_bit);
+    keypos_t         pos     = event->key;
+    swap_state_row_t col_bit = (swap_state_row_t)1 << pos.col;
+    bool             do_swap = event->pressed ? swap_hands : swap_state[pos.row] & (col_bit);
 
     if (do_swap) {
         event->key = hand_swap_config[pos.row][pos.col];
@@ -129,44 +131,36 @@ void process_hand_swap(keyevent_t *event) {
 #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
 bool disable_action_cache = false;
 
-void process_record_nocache(keyrecord_t *record)
-{
+void process_record_nocache(keyrecord_t *record) {
     disable_action_cache = true;
     process_record(record);
     disable_action_cache = false;
 }
 #else
-void process_record_nocache(keyrecord_t *record)
-{
-    process_record(record);
-}
+void process_record_nocache(keyrecord_t *record) { process_record(record); }
 #endif
 
-__attribute__ ((weak))
-bool process_record_quantum(keyrecord_t *record) {
-    return true;
-}
+__attribute__((weak)) bool process_record_quantum(keyrecord_t *record) { return true; }
 
 #ifndef NO_ACTION_TAPPING
 /** \brief Allows for handling tap-hold actions immediately instead of waiting for TAPPING_TERM or another keypress.
  *
  * FIXME: Needs documentation.
  */
-void process_record_tap_hint(keyrecord_t *record)
-{
+void process_record_tap_hint(keyrecord_t *record) {
     action_t action = layer_switch_get_action(record->event.key);
 
     switch (action.kind.id) {
-#ifdef SWAP_HANDS_ENABLE
+#    ifdef SWAP_HANDS_ENABLE
         case ACT_SWAP_HANDS:
             switch (action.swap.code) {
                 case OP_SH_TAP_TOGGLE:
                 default:
                     swap_hands = !swap_hands;
-                    swap_held = true;
+                    swap_held  = true;
             }
             break;
-#endif
+#    endif
     }
 }
 #endif
@@ -175,18 +169,21 @@ void process_record_tap_hint(keyrecord_t *record)
  *
  * FIXME: Needs documentation.
  */
-void process_record(keyrecord_t *record)
-{
-    if (IS_NOEVENT(record->event)) { return; }
-
-    if(!process_record_quantum(record))
+void process_record(keyrecord_t *record) {
+    if (IS_NOEVENT(record->event)) {
         return;
+    }
+
+    if (!process_record_quantum(record)) return;
 
     action_t action = store_or_get_action(record->event.pressed, record->event.key);
-    dprint("ACTION: "); debug_action(action);
+    dprint("ACTION: ");
+    debug_action(action);
 #ifndef NO_ACTION_LAYER
-    dprint(" layer_state: "); layer_debug();
-    dprint(" default_layer_state: "); default_layer_debug();
+    dprint(" layer_state: ");
+    layer_debug();
+    dprint(" default_layer_state: ");
+    default_layer_debug();
 #endif
     dprintln();
 
@@ -197,8 +194,7 @@ void process_record(keyrecord_t *record)
  *
  * FIXME: Needs documentation.
  */
-void process_action(keyrecord_t *record, action_t action)
-{
+void process_action(keyrecord_t *record, action_t action) {
     keyevent_t event = record->event;
 #ifndef NO_ACTION_TAPPING
     uint8_t tap_count = record->tap.count;
@@ -221,131 +217,125 @@ void process_action(keyrecord_t *record, action_t action)
     switch (action.kind.id) {
         /* Key and Mods */
         case ACT_LMODS:
-        case ACT_RMODS:
-            {
-                uint8_t mods = (action.kind.id == ACT_LMODS) ?  action.key.mods :
-                                                                action.key.mods<<4;
-                if (event.pressed) {
-                    if (mods) {
-                        if (IS_MOD(action.key.code) || action.key.code == KC_NO) {
-                            // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless.
-                            // This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT).
-                            // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO).
-                            add_mods(mods);
-                        } else {
-                            add_weak_mods(mods);
-                        }
-                        send_keyboard_report();
+        case ACT_RMODS: {
+            uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods : action.key.mods << 4;
+            if (event.pressed) {
+                if (mods) {
+                    if (IS_MOD(action.key.code) || action.key.code == KC_NO) {
+                        // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless.
+                        // This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT).
+                        // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO).
+                        add_mods(mods);
+                    } else {
+                        add_weak_mods(mods);
                     }
-                    register_code(action.key.code);
-                } else {
-                    unregister_code(action.key.code);
-                    if (mods) {
-                        if (IS_MOD(action.key.code) || action.key.code == KC_NO) {
-                            del_mods(mods);
-                        } else {
-                            del_weak_mods(mods);
-                        }
-                        send_keyboard_report();
+                    send_keyboard_report();
+                }
+                register_code(action.key.code);
+            } else {
+                unregister_code(action.key.code);
+                if (mods) {
+                    if (IS_MOD(action.key.code) || action.key.code == KC_NO) {
+                        del_mods(mods);
+                    } else {
+                        del_weak_mods(mods);
                     }
+                    send_keyboard_report();
                 }
             }
-            break;
+        } break;
 #ifndef NO_ACTION_TAPPING
         case ACT_LMODS_TAP:
-        case ACT_RMODS_TAP:
-            {
-                uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ?  action.key.mods :
-                                                                    action.key.mods<<4;
-                switch (action.layer_tap.code) {
-    #ifndef NO_ACTION_ONESHOT
-                    case MODS_ONESHOT:
-                        // Oneshot modifier
-                        if (event.pressed) {
-                            if (tap_count == 0) {
-                                dprint("MODS_TAP: Oneshot: 0\n");
-                                register_mods(mods | get_oneshot_mods());
-                            } else if (tap_count == 1) {
-                                dprint("MODS_TAP: Oneshot: start\n");
-                                set_oneshot_mods(mods | get_oneshot_mods());
-                    #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
-                            } else if (tap_count == ONESHOT_TAP_TOGGLE) {
-                                dprint("MODS_TAP: Toggling oneshot");
-                                clear_oneshot_mods();
-                                set_oneshot_locked_mods(mods);
-                                register_mods(mods);
-                    #endif
-                            } else {
-                                register_mods(mods | get_oneshot_mods());
-                            }
+        case ACT_RMODS_TAP: {
+            uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : action.key.mods << 4;
+            switch (action.layer_tap.code) {
+#    ifndef NO_ACTION_ONESHOT
+                case MODS_ONESHOT:
+                    // Oneshot modifier
+                    if (event.pressed) {
+                        if (tap_count == 0) {
+                            dprint("MODS_TAP: Oneshot: 0\n");
+                            register_mods(mods | get_oneshot_mods());
+                        } else if (tap_count == 1) {
+                            dprint("MODS_TAP: Oneshot: start\n");
+                            set_oneshot_mods(mods | get_oneshot_mods());
+#        if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
+                        } else if (tap_count == ONESHOT_TAP_TOGGLE) {
+                            dprint("MODS_TAP: Toggling oneshot");
+                            clear_oneshot_mods();
+                            set_oneshot_locked_mods(mods);
+                            register_mods(mods);
+#        endif
                         } else {
-                            if (tap_count == 0) {
-                                clear_oneshot_mods();
-                                unregister_mods(mods);
-                            } else if (tap_count == 1) {
-                                // Retain Oneshot mods
-                    #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
-                                if (mods & get_mods()) {
-                                    clear_oneshot_locked_mods();
-                                    clear_oneshot_mods();
-                                    unregister_mods(mods);
-                                }
-                            } else if (tap_count == ONESHOT_TAP_TOGGLE) {
-                                // Toggle Oneshot Layer
-                    #endif
-                            } else {
+                            register_mods(mods | get_oneshot_mods());
+                        }
+                    } else {
+                        if (tap_count == 0) {
+                            clear_oneshot_mods();
+                            unregister_mods(mods);
+                        } else if (tap_count == 1) {
+                            // Retain Oneshot mods
+#        if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
+                            if (mods & get_mods()) {
+                                clear_oneshot_locked_mods();
                                 clear_oneshot_mods();
                                 unregister_mods(mods);
                             }
+                        } else if (tap_count == ONESHOT_TAP_TOGGLE) {
+                            // Toggle Oneshot Layer
+#        endif
+                        } else {
+                            clear_oneshot_mods();
+                            unregister_mods(mods);
                         }
-                        break;
-    #endif
-                    case MODS_TAP_TOGGLE:
-                        if (event.pressed) {
-                            if (tap_count <= TAPPING_TOGGLE) {
+                    }
+                    break;
+#    endif
+                case MODS_TAP_TOGGLE:
+                    if (event.pressed) {
+                        if (tap_count <= TAPPING_TOGGLE) {
+                            register_mods(mods);
+                        }
+                    } else {
+                        if (tap_count < TAPPING_TOGGLE) {
+                            unregister_mods(mods);
+                        }
+                    }
+                    break;
+                default:
+                    if (event.pressed) {
+                        if (tap_count > 0) {
+#    ifndef IGNORE_MOD_TAP_INTERRUPT
+                            if (record->tap.interrupted) {
+                                dprint("mods_tap: tap: cancel: add_mods\n");
+                                // ad hoc: set 0 to cancel tap
+                                record->tap.count = 0;
                                 register_mods(mods);
+                            } else
+#    endif
+                            {
+                                dprint("MODS_TAP: Tap: register_code\n");
+                                register_code(action.key.code);
                             }
                         } else {
-                            if (tap_count < TAPPING_TOGGLE) {
-                                unregister_mods(mods);
-                            }
+                            dprint("MODS_TAP: No tap: add_mods\n");
+                            register_mods(mods);
                         }
-                        break;
-                    default:
-                        if (event.pressed) {
-                            if (tap_count > 0) {
-#ifndef IGNORE_MOD_TAP_INTERRUPT
-                                if (record->tap.interrupted) {
-                                    dprint("mods_tap: tap: cancel: add_mods\n");
-                                    // ad hoc: set 0 to cancel tap
-                                    record->tap.count = 0;
-                                    register_mods(mods);
-                                } else
-#endif
-                                {
-                                    dprint("MODS_TAP: Tap: register_code\n");
-                                    register_code(action.key.code);
-                                }
-                            } else {
-                                dprint("MODS_TAP: No tap: add_mods\n");
-                                register_mods(mods);
+                    } else {
+                        if (tap_count > 0) {
+                            dprint("MODS_TAP: Tap: unregister_code\n");
+                            if (action.layer_tap.code == KC_CAPS) {
+                                wait_ms(TAP_HOLD_CAPS_DELAY);
                             }
+                            unregister_code(action.key.code);
                         } else {
-                            if (tap_count > 0) {
-                                dprint("MODS_TAP: Tap: unregister_code\n");
-                                if (action.layer_tap.code == KC_CAPS) {
-                                  wait_ms(TAP_HOLD_CAPS_DELAY);
-                                }
-                                unregister_code(action.key.code);
-                            } else {
-                                dprint("MODS_TAP: No tap: add_mods\n");
-                                unregister_mods(mods);
-                            }
+                            dprint("MODS_TAP: No tap: add_mods\n");
+                            unregister_mods(mods);
                         }
-                        break;
-                }
+                    }
+                    break;
             }
-            break;
+        } break;
 #endif
 #ifdef EXTRAKEY_ENABLE
         /* other HID usage */
@@ -374,13 +364,13 @@ void process_action(keyrecord_t *record, action_t action)
             if (event.pressed) {
                 switch (action.key.code) {
                     case KC_MS_BTN1:
-                        tp_buttons |= (1<<0);
+                        tp_buttons |= (1 << 0);
                         break;
                     case KC_MS_BTN2:
-                        tp_buttons |= (1<<1);
+                        tp_buttons |= (1 << 1);
                         break;
                     case KC_MS_BTN3:
-                        tp_buttons |= (1<<2);
+                        tp_buttons |= (1 << 2);
                         break;
                     default:
                         break;
@@ -390,13 +380,13 @@ void process_action(keyrecord_t *record, action_t action)
             } else {
                 switch (action.key.code) {
                     case KC_MS_BTN1:
-                        tp_buttons &= ~(1<<0);
+                        tp_buttons &= ~(1 << 0);
                         break;
                     case KC_MS_BTN2:
-                        tp_buttons &= ~(1<<1);
+                        tp_buttons &= ~(1 << 1);
                         break;
                     case KC_MS_BTN3:
-                        tp_buttons &= ~(1<<2);
+                        tp_buttons &= ~(1 << 2);
                         break;
                     default:
                         break;
@@ -411,28 +401,43 @@ void process_action(keyrecord_t *record, action_t action)
             if (action.layer_bitop.on == 0) {
                 /* Default Layer Bitwise Operation */
                 if (!event.pressed) {
-                    uint8_t shift = action.layer_bitop.part*4;
-                    layer_state_t bits = ((layer_state_t)action.layer_bitop.bits)<<shift;
-                    layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<<shift) : 0;
+                    uint8_t       shift = action.layer_bitop.part * 4;
+                    layer_state_t bits  = ((layer_state_t)action.layer_bitop.bits) << shift;
+                    layer_state_t mask  = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf) << shift) : 0;
                     switch (action.layer_bitop.op) {
-                        case OP_BIT_AND: default_layer_and(bits | mask); break;
-                        case OP_BIT_OR:  default_layer_or(bits | mask);  break;
-                        case OP_BIT_XOR: default_layer_xor(bits | mask); break;
-                        case OP_BIT_SET: default_layer_set(bits | mask); break;
+                        case OP_BIT_AND:
+                            default_layer_and(bits | mask);
+                            break;
+                        case OP_BIT_OR:
+                            default_layer_or(bits | mask);
+                            break;
+                        case OP_BIT_XOR:
+                            default_layer_xor(bits | mask);
+                            break;
+                        case OP_BIT_SET:
+                            default_layer_set(bits | mask);
+                            break;
                     }
                 }
             } else {
                 /* Layer Bitwise Operation */
-                if (event.pressed ? (action.layer_bitop.on & ON_PRESS) :
-                                    (action.layer_bitop.on & ON_RELEASE)) {
-                    uint8_t shift = action.layer_bitop.part*4;
-                    layer_state_t bits = ((layer_state_t)action.layer_bitop.bits)<<shift;
-                    layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<<shift) : 0;
+                if (event.pressed ? (action.layer_bitop.on & ON_PRESS) : (action.layer_bitop.on & ON_RELEASE)) {
+                    uint8_t       shift = action.layer_bitop.part * 4;
+                    layer_state_t bits  = ((layer_state_t)action.layer_bitop.bits) << shift;
+                    layer_state_t mask  = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf) << shift) : 0;
                     switch (action.layer_bitop.op) {
-                        case OP_BIT_AND: layer_and(bits | mask); break;
-                        case OP_BIT_OR:  layer_or(bits | mask);  break;
-                        case OP_BIT_XOR: layer_xor(bits | mask); break;
-                        case OP_BIT_SET: layer_state_set(bits | mask); break;
+                        case OP_BIT_AND:
+                            layer_and(bits | mask);
+                            break;
+                        case OP_BIT_OR:
+                            layer_or(bits | mask);
+                            break;
+                        case OP_BIT_XOR:
+                            layer_xor(bits | mask);
+                            break;
+                        case OP_BIT_SET:
+                            layer_state_set(bits | mask);
+                            break;
                     }
                 }
             }
@@ -446,7 +451,7 @@ void process_action(keyrecord_t *record, action_t action)
                 layer_off(action.layer_mods.layer);
             }
             break;
-    #ifndef NO_ACTION_TAPPING
+#    ifndef NO_ACTION_TAPPING
         case ACT_LAYER_TAP:
         case ACT_LAYER_TAP_EXT:
             switch (action.layer_tap.code) {
@@ -463,21 +468,18 @@ void process_action(keyrecord_t *record, action_t action)
                     }
                     break;
                 case OP_ON_OFF:
-                    event.pressed ? layer_on(action.layer_tap.val) :
-                                    layer_off(action.layer_tap.val);
+                    event.pressed ? layer_on(action.layer_tap.val) : layer_off(action.layer_tap.val);
                     break;
                 case OP_OFF_ON:
-                    event.pressed ? layer_off(action.layer_tap.val) :
-                                    layer_on(action.layer_tap.val);
+                    event.pressed ? layer_off(action.layer_tap.val) : layer_on(action.layer_tap.val);
                     break;
                 case OP_SET_CLEAR:
-                    event.pressed ? layer_move(action.layer_tap.val) :
-                                    layer_clear();
+                    event.pressed ? layer_move(action.layer_tap.val) : layer_clear();
                     break;
-            #ifndef NO_ACTION_ONESHOT
+#        ifndef NO_ACTION_ONESHOT
                 case OP_ONESHOT:
                     // Oneshot modifier
-                #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
+#            if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
                     do_release_oneshot = false;
                     if (event.pressed) {
                         del_mods(get_oneshot_locked_mods());
@@ -499,7 +501,7 @@ void process_action(keyrecord_t *record, action_t action)
                             clear_oneshot_layer_state(ONESHOT_PRESSED);
                         }
                     }
-                #else
+#            else
                     if (event.pressed) {
                         layer_on(action.layer_tap.val);
                         set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
@@ -509,9 +511,9 @@ void process_action(keyrecord_t *record, action_t action)
                             clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
                         }
                     }
-                #endif
+#            endif
                     break;
-            #endif
+#        endif
                 default:
                     /* tap key */
                     if (event.pressed) {
@@ -529,7 +531,7 @@ void process_action(keyrecord_t *record, action_t action)
                                 wait_ms(TAP_HOLD_CAPS_DELAY);
                             } else {
                                 wait_ms(TAP_CODE_DELAY);
-                              }
+                            }
                             unregister_code(action.layer_tap.code);
                         } else {
                             dprint("KEYMAP_TAP_KEY: No tap: Off on release\n");
@@ -539,9 +541,9 @@ void process_action(keyrecord_t *record, action_t action)
                     break;
             }
             break;
-    #endif
+#    endif
 #endif
-        /* Extentions */
+            /* Extentions */
 #ifndef NO_ACTION_MACRO
         case ACT_MACRO:
             action_macro_play(action_get_macro(record, action.func.id, action.func.opt));
@@ -599,7 +601,7 @@ void process_action(keyrecord_t *record, action_t action)
                         swap_hands = false;
                     }
                     break;
-    #ifndef NO_ACTION_TAPPING
+#    ifndef NO_ACTION_TAPPING
                 case OP_SH_TAP_TOGGLE:
                     /* tap toggle */
 
@@ -619,23 +621,23 @@ void process_action(keyrecord_t *record, action_t action)
                     /* tap key */
                     if (tap_count > 0) {
                         if (swap_held) {
-                            swap_hands = !swap_hands; // undo hold set up in _tap_hint
-                            swap_held = false;
+                            swap_hands = !swap_hands;  // undo hold set up in _tap_hint
+                            swap_held  = false;
                         }
                         if (event.pressed) {
                             register_code(action.swap.code);
                         } else {
                             wait_ms(TAP_CODE_DELAY);
                             unregister_code(action.swap.code);
-                            *record = (keyrecord_t){}; // hack: reset tap mode
+                            *record = (keyrecord_t){};  // hack: reset tap mode
                         }
                     } else {
                         if (swap_held && !event.pressed) {
-                            swap_hands = !swap_hands; // undo hold set up in _tap_hint
-                            swap_held = false;
+                            swap_hands = !swap_hands;  // undo hold set up in _tap_hint
+                            swap_held  = false;
                         }
                     }
-    #endif
+#    endif
             }
 #endif
 #ifndef NO_ACTION_FUNCTION
@@ -652,10 +654,10 @@ void process_action(keyrecord_t *record, action_t action)
     switch (action.kind.id) {
         case ACT_LAYER:
         case ACT_LAYER_MODS:
-        #ifndef NO_ACTION_TAPPING
+#    ifndef NO_ACTION_TAPPING
         case ACT_LAYER_TAP:
         case ACT_LAYER_TAP_EXT:
-        #endif
+#    endif
             led_set(host_keyboard_leds());
             break;
         default:
@@ -664,35 +666,34 @@ void process_action(keyrecord_t *record, action_t action)
 #endif
 
 #ifndef NO_ACTION_TAPPING
-  #ifdef RETRO_TAPPING
-  if (!is_tap_action(action)) {
-    retro_tapping_counter = 0;
-  } else {
-    if (event.pressed) {
-        if (tap_count > 0) {
-          retro_tapping_counter = 0;
-        } else {
-
-        }
-    } else {
-      if (tap_count > 0) {
+#    ifdef RETRO_TAPPING
+    if (!is_tap_action(action)) {
         retro_tapping_counter = 0;
-      } else {
-        if (retro_tapping_counter == 2) {
-          tap_code(action.layer_tap.code);
+    } else {
+        if (event.pressed) {
+            if (tap_count > 0) {
+                retro_tapping_counter = 0;
+            } else {
+            }
+        } else {
+            if (tap_count > 0) {
+                retro_tapping_counter = 0;
+            } else {
+                if (retro_tapping_counter == 2) {
+                    tap_code(action.layer_tap.code);
+                }
+                retro_tapping_counter = 0;
+            }
         }
-        retro_tapping_counter = 0;
-      }
     }
-  }
-  #endif
+#    endif
 #endif
 
 #ifndef NO_ACTION_ONESHOT
     /* Because we switch layers after a oneshot event, we need to release the
      * key before we leave the layer or no key up event will be generated.
      */
-    if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED )   ) {
+    if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED)) {
         record->event.pressed = false;
         layer_on(get_oneshot_layer());
         process_record(record);
@@ -701,25 +702,20 @@ void process_action(keyrecord_t *record, action_t action)
 #endif
 }
 
-
-
-
 /** \brief Utilities for actions. (FIXME: Needs better description)
  *
  * FIXME: Needs documentation.
  */
-void register_code(uint8_t code)
-{
+void register_code(uint8_t code) {
     if (code == KC_NO) {
         return;
     }
-
 #ifdef LOCKING_SUPPORT_ENABLE
     else if (KC_LOCKING_CAPS == code) {
-#ifdef LOCKING_RESYNC_ENABLE
+#    ifdef LOCKING_RESYNC_ENABLE
         // Resync: ignore if caps lock already is on
-        if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return;
-#endif
+        if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return;
+#    endif
         add_key(KC_CAPSLOCK);
         send_keyboard_report();
         wait_ms(100);
@@ -728,9 +724,9 @@ void register_code(uint8_t code)
     }
 
     else if (KC_LOCKING_NUM == code) {
-#ifdef LOCKING_RESYNC_ENABLE
-        if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return;
-#endif
+#    ifdef LOCKING_RESYNC_ENABLE
+        if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return;
+#    endif
         add_key(KC_NUMLOCK);
         send_keyboard_report();
         wait_ms(100);
@@ -739,9 +735,9 @@ void register_code(uint8_t code)
     }
 
     else if (KC_LOCKING_SCROLL == code) {
-#ifdef LOCKING_RESYNC_ENABLE
-        if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return;
-#endif
+#    ifdef LOCKING_RESYNC_ENABLE
+        if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return;
+#    endif
         add_key(KC_SCROLLLOCK);
         send_keyboard_report();
         wait_ms(100);
@@ -750,9 +746,10 @@ void register_code(uint8_t code)
     }
 #endif
 
-    else if IS_KEY(code) {
-        // TODO: should push command_proc out of this block?
-        if (command_proc(code)) return;
+    else if
+        IS_KEY(code) {
+            // TODO: should push command_proc out of this block?
+            if (command_proc(code)) return;
 
 #ifndef NO_ACTION_ONESHOT
 /* TODO: remove
@@ -769,46 +766,44 @@ void register_code(uint8_t code)
         } else
 */
 #endif
-        {
-            add_key(code);
+            {
+                add_key(code);
+                send_keyboard_report();
+            }
+        }
+    else if
+        IS_MOD(code) {
+            add_mods(MOD_BIT(code));
             send_keyboard_report();
         }
-    }
-    else if IS_MOD(code) {
-        add_mods(MOD_BIT(code));
-        send_keyboard_report();
-    }
-    else if IS_SYSTEM(code) {
-        host_system_send(KEYCODE2SYSTEM(code));
-    }
-    else if IS_CONSUMER(code) {
-        host_consumer_send(KEYCODE2CONSUMER(code));
-    }
+    else if
+        IS_SYSTEM(code) { host_system_send(KEYCODE2SYSTEM(code)); }
+    else if
+        IS_CONSUMER(code) { host_consumer_send(KEYCODE2CONSUMER(code)); }
 
-    #ifdef MOUSEKEY_ENABLE
-      else if IS_MOUSEKEY(code) {
-        mousekey_on(code);
-        mousekey_send();
-      }
-    #endif
+#ifdef MOUSEKEY_ENABLE
+    else if
+        IS_MOUSEKEY(code) {
+            mousekey_on(code);
+            mousekey_send();
+        }
+#endif
 }
 
 /** \brief Utilities for actions. (FIXME: Needs better description)
  *
  * FIXME: Needs documentation.
  */
-void unregister_code(uint8_t code)
-{
+void unregister_code(uint8_t code) {
     if (code == KC_NO) {
         return;
     }
-
 #ifdef LOCKING_SUPPORT_ENABLE
     else if (KC_LOCKING_CAPS == code) {
-#ifdef LOCKING_RESYNC_ENABLE
+#    ifdef LOCKING_RESYNC_ENABLE
         // Resync: ignore if caps lock already is off
-        if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return;
-#endif
+        if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return;
+#    endif
         add_key(KC_CAPSLOCK);
         send_keyboard_report();
         del_key(KC_CAPSLOCK);
@@ -816,9 +811,9 @@ void unregister_code(uint8_t code)
     }
 
     else if (KC_LOCKING_NUM == code) {
-#ifdef LOCKING_RESYNC_ENABLE
-        if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return;
-#endif
+#    ifdef LOCKING_RESYNC_ENABLE
+        if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return;
+#    endif
         add_key(KC_NUMLOCK);
         send_keyboard_report();
         del_key(KC_NUMLOCK);
@@ -826,9 +821,9 @@ void unregister_code(uint8_t code)
     }
 
     else if (KC_LOCKING_SCROLL == code) {
-#ifdef LOCKING_RESYNC_ENABLE
-        if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return;
-#endif
+#    ifdef LOCKING_RESYNC_ENABLE
+        if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return;
+#    endif
         add_key(KC_SCROLLLOCK);
         send_keyboard_report();
         del_key(KC_SCROLLLOCK);
@@ -836,26 +831,27 @@ void unregister_code(uint8_t code)
     }
 #endif
 
-    else if IS_KEY(code) {
-        del_key(code);
-        send_keyboard_report();
-    }
-    else if IS_MOD(code) {
-        del_mods(MOD_BIT(code));
-        send_keyboard_report();
-    }
-    else if IS_SYSTEM(code) {
-        host_system_send(0);
-    }
-    else if IS_CONSUMER(code) {
-        host_consumer_send(0);
-    }
-    #ifdef MOUSEKEY_ENABLE
-      else if IS_MOUSEKEY(code) {
-        mousekey_off(code);
-        mousekey_send();
-      }
-    #endif
+    else if
+        IS_KEY(code) {
+            del_key(code);
+            send_keyboard_report();
+        }
+    else if
+        IS_MOD(code) {
+            del_mods(MOD_BIT(code));
+            send_keyboard_report();
+        }
+    else if
+        IS_SYSTEM(code) { host_system_send(0); }
+    else if
+        IS_CONSUMER(code) { host_consumer_send(0); }
+#ifdef MOUSEKEY_ENABLE
+    else if
+        IS_MOUSEKEY(code) {
+            mousekey_off(code);
+            mousekey_send();
+        }
+#endif
 }
 
 /** \brief Utilities for actions. (FIXME: Needs better description)
@@ -863,21 +859,20 @@ void unregister_code(uint8_t code)
  * FIXME: Needs documentation.
  */
 void tap_code(uint8_t code) {
-  register_code(code);
-  if (code == KC_CAPS) {
-    wait_ms(TAP_HOLD_CAPS_DELAY);
-  } else {
-    wait_ms(TAP_CODE_DELAY);
-  }
-  unregister_code(code);
+    register_code(code);
+    if (code == KC_CAPS) {
+        wait_ms(TAP_HOLD_CAPS_DELAY);
+    } else {
+        wait_ms(TAP_CODE_DELAY);
+    }
+    unregister_code(code);
 }
 
 /** \brief Utilities for actions. (FIXME: Needs better description)
  *
  * FIXME: Needs documentation.
  */
-void register_mods(uint8_t mods)
-{
+void register_mods(uint8_t mods) {
     if (mods) {
         add_mods(mods);
         send_keyboard_report();
@@ -888,8 +883,7 @@ void register_mods(uint8_t mods)
  *
  * FIXME: Needs documentation.
  */
-void unregister_mods(uint8_t mods)
-{
+void unregister_mods(uint8_t mods) {
     if (mods) {
         del_mods(mods);
         send_keyboard_report();
@@ -900,8 +894,7 @@ void unregister_mods(uint8_t mods)
  *
  * FIXME: Needs documentation.
  */
-void clear_keyboard(void)
-{
+void clear_keyboard(void) {
     clear_mods();
     clear_keyboard_but_mods();
 }
@@ -910,8 +903,7 @@ void clear_keyboard(void)
  *
  * FIXME: Needs documentation.
  */
-void clear_keyboard_but_mods(void)
-{
+void clear_keyboard_but_mods(void) {
     clear_keys();
     clear_keyboard_but_mods_and_keys();
 }
@@ -920,8 +912,7 @@ void clear_keyboard_but_mods(void)
  *
  * FIXME: Needs documentation.
  */
-void clear_keyboard_but_mods_and_keys()
-{
+void clear_keyboard_but_mods_and_keys() {
     clear_weak_mods();
     clear_macro_mods();
     send_keyboard_report();
@@ -939,8 +930,7 @@ void clear_keyboard_but_mods_and_keys()
  *
  * FIXME: Needs documentation.
  */
-bool is_tap_key(keypos_t key)
-{
+bool is_tap_key(keypos_t key) {
     action_t action = layer_switch_get_action(key);
     return is_tap_action(action);
 }
@@ -949,8 +939,7 @@ bool is_tap_key(keypos_t key)
  *
  * FIXME: Needs documentation.
  */
-bool is_tap_action(action_t action)
-{
+bool is_tap_action(action_t action) {
     switch (action.kind.id) {
         case ACT_LMODS_TAP:
         case ACT_RMODS_TAP:
@@ -972,28 +961,25 @@ bool is_tap_action(action_t action)
             return false;
         case ACT_MACRO:
         case ACT_FUNCTION:
-            if (action.func.opt & FUNC_TAP) { return true; }
+            if (action.func.opt & FUNC_TAP) {
+                return true;
+            }
             return false;
     }
     return false;
 }
 
-
 /** \brief Debug print (FIXME: Needs better description)
  *
  * FIXME: Needs documentation.
  */
-void debug_event(keyevent_t event)
-{
-    dprintf("%04X%c(%u)", (event.key.row<<8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time);
-}
+void debug_event(keyevent_t event) { dprintf("%04X%c(%u)", (event.key.row << 8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time); }
 
 /** \brief Debug print (FIXME: Needs better description)
  *
  * FIXME: Needs documentation.
  */
-void debug_record(keyrecord_t record)
-{
+void debug_record(keyrecord_t record) {
     debug_event(record.event);
 #ifndef NO_ACTION_TAPPING
     dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' '));
@@ -1004,24 +990,53 @@ void debug_record(keyrecord_t record)
  *
  * FIXME: Needs documentation.
  */
-void debug_action(action_t action)
-{
+void debug_action(action_t action) {
     switch (action.kind.id) {
-        case ACT_LMODS:             dprint("ACT_LMODS");             break;
-        case ACT_RMODS:             dprint("ACT_RMODS");             break;
-        case ACT_LMODS_TAP:         dprint("ACT_LMODS_TAP");         break;
-        case ACT_RMODS_TAP:         dprint("ACT_RMODS_TAP");         break;
-        case ACT_USAGE:             dprint("ACT_USAGE");             break;
-        case ACT_MOUSEKEY:          dprint("ACT_MOUSEKEY");          break;
-        case ACT_LAYER:             dprint("ACT_LAYER");             break;
-        case ACT_LAYER_MODS:        dprint("ACT_LAYER_MODS");        break;
-        case ACT_LAYER_TAP:         dprint("ACT_LAYER_TAP");         break;
-        case ACT_LAYER_TAP_EXT:     dprint("ACT_LAYER_TAP_EXT");     break;
-        case ACT_MACRO:             dprint("ACT_MACRO");             break;
-        case ACT_COMMAND:           dprint("ACT_COMMAND");           break;
-        case ACT_FUNCTION:          dprint("ACT_FUNCTION");          break;
-        case ACT_SWAP_HANDS:        dprint("ACT_SWAP_HANDS");        break;
-        default:                    dprint("UNKNOWN");               break;
+        case ACT_LMODS:
+            dprint("ACT_LMODS");
+            break;
+        case ACT_RMODS:
+            dprint("ACT_RMODS");
+            break;
+        case ACT_LMODS_TAP:
+            dprint("ACT_LMODS_TAP");
+            break;
+        case ACT_RMODS_TAP:
+            dprint("ACT_RMODS_TAP");
+            break;
+        case ACT_USAGE:
+            dprint("ACT_USAGE");
+            break;
+        case ACT_MOUSEKEY:
+            dprint("ACT_MOUSEKEY");
+            break;
+        case ACT_LAYER:
+            dprint("ACT_LAYER");
+            break;
+        case ACT_LAYER_MODS:
+            dprint("ACT_LAYER_MODS");
+            break;
+        case ACT_LAYER_TAP:
+            dprint("ACT_LAYER_TAP");
+            break;
+        case ACT_LAYER_TAP_EXT:
+            dprint("ACT_LAYER_TAP_EXT");
+            break;
+        case ACT_MACRO:
+            dprint("ACT_MACRO");
+            break;
+        case ACT_COMMAND:
+            dprint("ACT_COMMAND");
+            break;
+        case ACT_FUNCTION:
+            dprint("ACT_FUNCTION");
+            break;
+        case ACT_SWAP_HANDS:
+            dprint("ACT_SWAP_HANDS");
+            break;
+        default:
+            dprint("UNKNOWN");
+            break;
     }
-    dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff);
+    dprintf("[%X:%02X]", action.kind.param >> 8, action.kind.param & 0xff);
 }
index 799e3bb0efd52d5a7a400145c4ef6a8b1cdfaaad..633cedb06bbbe81037b80bc74ea8d1b27f499ad7 100644 (file)
@@ -24,23 +24,22 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "action_code.h"
 #include "action_macro.h"
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /* tapping count and state */
 typedef struct {
-    bool    interrupted :1;
-    bool    reserved2   :1;
-    bool    reserved1   :1;
-    bool    reserved0   :1;
-    uint8_t count       :4;
+    bool    interrupted : 1;
+    bool    reserved2 1;
+    bool    reserved1 1;
+    bool    reserved0 1;
+    uint8_t count 4;
 } tap_t;
 
 /* Key event container for recording */
 typedef struct {
-    keyevent_t  event;
+    keyevent_t event;
 #ifndef NO_ACTION_TAPPING
     tap_t tap;
 #endif
@@ -68,17 +67,17 @@ extern bool disable_action_cache;
 
 /* Code for handling one-handed key modifiers. */
 #ifdef SWAP_HANDS_ENABLE
-extern bool swap_hands;
+extern bool           swap_hands;
 extern const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
-#if (MATRIX_COLS <= 8)
-typedef  uint8_t    swap_state_row_t;
-#elif (MATRIX_COLS <= 16)
-typedef  uint16_t   swap_state_row_t;
-#elif (MATRIX_COLS <= 32)
-typedef  uint32_t   swap_state_row_t;
-#else
-#error "MATRIX_COLS: invalid value"
-#endif
+#    if (MATRIX_COLS <= 8)
+typedef uint8_t swap_state_row_t;
+#    elif (MATRIX_COLS <= 16)
+typedef uint16_t swap_state_row_t;
+#    elif (MATRIX_COLS <= 32)
+typedef uint32_t swap_state_row_t;
+#    else
+#        error "MATRIX_COLS: invalid value"
+#    endif
 
 void process_hand_swap(keyevent_t *record);
 #endif
@@ -91,7 +90,7 @@ void unregister_code(uint8_t code);
 void tap_code(uint8_t code);
 void register_mods(uint8_t mods);
 void unregister_mods(uint8_t mods);
-//void set_mods(uint8_t mods);
+// void set_mods(uint8_t mods);
 void clear_keyboard(void);
 void clear_keyboard_but_mods(void);
 void clear_keyboard_but_mods_and_keys(void);
@@ -112,4 +111,4 @@ void debug_action(action_t action);
 }
 #endif
 
-#endif  /* ACTION_H */
+#endif /* ACTION_H */
index 5b5d0e566041d0d63213491b3de6872914aafa91..03fcb3382bbbcfb336ba1097f4c0de53a858942b 100644 (file)
@@ -98,30 +98,29 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 enum action_kind_id {
     /* Key Actions */
-    ACT_MODS            = 0b0000,
-    ACT_LMODS           = 0b0000,
-    ACT_RMODS           = 0b0001,
-    ACT_MODS_TAP        = 0b0010,
-    ACT_LMODS_TAP       = 0b0010,
-    ACT_RMODS_TAP       = 0b0011,
+    ACT_MODS      = 0b0000,
+    ACT_LMODS     = 0b0000,
+    ACT_RMODS     = 0b0001,
+    ACT_MODS_TAP  = 0b0010,
+    ACT_LMODS_TAP = 0b0010,
+    ACT_RMODS_TAP = 0b0011,
     /* Other Keys */
-    ACT_USAGE           = 0b0100,
-    ACT_MOUSEKEY        = 0b0101,
+    ACT_USAGE    = 0b0100,
+    ACT_MOUSEKEY = 0b0101,
     /* One-hand Support */
-    ACT_SWAP_HANDS      = 0b0110,
+    ACT_SWAP_HANDS = 0b0110,
     /* Layer Actions */
-    ACT_LAYER           = 0b1000,
-    ACT_LAYER_MODS      = 0b1001,
-    ACT_LAYER_TAP       = 0b1010, /* Layer  0-15 */
-    ACT_LAYER_TAP_EXT   = 0b1011, /* Layer 16-31 */
+    ACT_LAYER         = 0b1000,
+    ACT_LAYER_MODS    = 0b1001,
+    ACT_LAYER_TAP     = 0b1010, /* Layer  0-15 */
+    ACT_LAYER_TAP_EXT = 0b1011, /* Layer 16-31 */
     /* Extensions */
-    ACT_MACRO           = 0b1100,
-    ACT_BACKLIGHT       = 0b1101,
-    ACT_COMMAND         = 0b1110,
-    ACT_FUNCTION        = 0b1111
+    ACT_MACRO     = 0b1100,
+    ACT_BACKLIGHT = 0b1101,
+    ACT_COMMAND   = 0b1110,
+    ACT_FUNCTION  = 0b1111
 };
 
-
 /** \brief Action Code Struct
  *
  * NOTE:
@@ -139,66 +138,63 @@ enum action_kind_id {
 typedef union {
     uint16_t code;
     struct action_kind {
-        uint16_t param  :12;
-        uint8_t  id     :4;
+        uint16_t param 12;
+        uint8_t  id 4;
     } kind;
     struct action_key {
-        uint8_t  code   :8;
-        uint8_t  mods   :4;
-        uint8_t  kind   :4;
+        uint8_t code : 8;
+        uint8_t mods : 4;
+        uint8_t kind : 4;
     } key;
     struct action_layer_bitop {
-        uint8_t  bits   :4;
-        uint8_t  xbit   :1;
-        uint8_t  part   :3;
-        uint8_t  on     :2;
-        uint8_t  op     :2;
-        uint8_t  kind   :4;
+        uint8_t bits : 4;
+        uint8_t xbit : 1;
+        uint8_t part : 3;
+        uint8_t on : 2;
+        uint8_t op : 2;
+        uint8_t kind : 4;
     } layer_bitop;
-    struct action_layer_mods
-    {
-        uint8_t  mods   :8;
-        uint8_t  layer  :4;
-        uint8_t  kind   :4;
+    struct action_layer_mods {
+        uint8_t mods : 8;
+        uint8_t layer : 4;
+        uint8_t kind : 4;
     } layer_mods;
     struct action_layer_tap {
-        uint8_t  code   :8;
-        uint8_t  val    :5;
-        uint8_t  kind   :3;
+        uint8_t code : 8;
+        uint8_t val : 5;
+        uint8_t kind : 3;
     } layer_tap;
     struct action_usage {
-        uint16_t code   :10;
-        uint8_t  page   :2;
-        uint8_t  kind   :4;
+        uint16_t code 10;
+        uint8_t  page 2;
+        uint8_t  kind 4;
     } usage;
     struct action_backlight {
-        uint8_t  level  :8;
-        uint8_t  opt    :4;
-        uint8_t  kind   :4;
+        uint8_t level : 8;
+        uint8_t opt : 4;
+        uint8_t kind : 4;
     } backlight;
     struct action_command {
-        uint8_t  id     :8;
-        uint8_t  opt    :4;
-        uint8_t  kind   :4;
+        uint8_t id : 8;
+        uint8_t opt : 4;
+        uint8_t kind : 4;
     } command;
     struct action_function {
-        uint8_t  id     :8;
-        uint8_t  opt    :4;
-        uint8_t  kind   :4;
+        uint8_t id : 8;
+        uint8_t opt : 4;
+        uint8_t kind : 4;
     } func;
     struct action_swap {
-        uint8_t  code   :8;
-        uint8_t  opt    :4;
-        uint8_t  kind   :4;
+        uint8_t code : 8;
+        uint8_t opt : 4;
+        uint8_t kind : 4;
     } swap;
 } action_t;
 
-
 /* action utility */
-#define ACTION_NO                       0
-#define ACTION_TRANSPARENT              1
-#define ACTION(kind, param)             ((kind)<<12 | (param))
-
+#define ACTION_NO 0
+#define ACTION_TRANSPARENT 1
+#define ACTION(kind, param) ((kind) << 12 | (param))
 
 /** \brief Key Actions
  *
@@ -220,35 +216,29 @@ enum mods_bit {
     MOD_RGUI = 0x18,
 };
 enum mods_codes {
-    MODS_ONESHOT = 0x00,
+    MODS_ONESHOT    = 0x00,
     MODS_TAP_TOGGLE = 0x01,
 };
-#define ACTION_KEY(key)                 ACTION(ACT_MODS, (key))
-#define ACTION_MODS(mods)               ACTION(ACT_MODS, ((mods)&0x1f)<<8 | 0)
-#define ACTION_MODS_KEY(mods, key)      ACTION(ACT_MODS, ((mods)&0x1f)<<8 | (key))
-#define ACTION_MODS_TAP_KEY(mods, key)  ACTION(ACT_MODS_TAP, ((mods)&0x1f)<<8 | (key))
-#define ACTION_MODS_ONESHOT(mods)       ACTION(ACT_MODS_TAP, ((mods)&0x1f)<<8 | MODS_ONESHOT)
-#define ACTION_MODS_TAP_TOGGLE(mods)    ACTION(ACT_MODS_TAP, ((mods)&0x1f)<<8 | MODS_TAP_TOGGLE)
-
+#define ACTION_KEY(key) ACTION(ACT_MODS, (key))
+#define ACTION_MODS(mods) ACTION(ACT_MODS, ((mods)&0x1f) << 8 | 0)
+#define ACTION_MODS_KEY(mods, key) ACTION(ACT_MODS, ((mods)&0x1f) << 8 | (key))
+#define ACTION_MODS_TAP_KEY(mods, key) ACTION(ACT_MODS_TAP, ((mods)&0x1f) << 8 | (key))
+#define ACTION_MODS_ONESHOT(mods) ACTION(ACT_MODS_TAP, ((mods)&0x1f) << 8 | MODS_ONESHOT)
+#define ACTION_MODS_TAP_TOGGLE(mods) ACTION(ACT_MODS_TAP, ((mods)&0x1f) << 8 | MODS_TAP_TOGGLE)
 
 /** \brief Other Keys
  */
-enum usage_pages {
-    PAGE_SYSTEM,
-    PAGE_CONSUMER
-};
-#define ACTION_USAGE_SYSTEM(id)         ACTION(ACT_USAGE, PAGE_SYSTEM<<10 | (id))
-#define ACTION_USAGE_CONSUMER(id)       ACTION(ACT_USAGE, PAGE_CONSUMER<<10 | (id))
-#define ACTION_MOUSEKEY(key)            ACTION(ACT_MOUSEKEY, key)
-
-
+enum usage_pages { PAGE_SYSTEM, PAGE_CONSUMER };
+#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM << 10 | (id))
+#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER << 10 | (id))
+#define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key)
 
 /** \brief Layer Actions
  */
 enum layer_param_on {
-    ON_PRESS    = 1,
-    ON_RELEASE  = 2,
-    ON_BOTH     = 3,
+    ON_PRESS   = 1,
+    ON_RELEASE = 2,
+    ON_BOTH    = 3,
 };
 
 /** \brief Layer Actions
@@ -269,37 +259,36 @@ enum layer_param_tap_op {
     OP_SET_CLEAR,
     OP_ONESHOT,
 };
-#define ACTION_LAYER_BITOP(op, part, bits, on)      ACTION(ACT_LAYER, (op)<<10 | (on)<<8 | (part)<<5 | ((bits)&0x1f))
-#define ACTION_LAYER_TAP(layer, key)                ACTION(ACT_LAYER_TAP, (layer)<<8 | (key))
+#define ACTION_LAYER_BITOP(op, part, bits, on) ACTION(ACT_LAYER, (op) << 10 | (on) << 8 | (part) << 5 | ((bits)&0x1f))
+#define ACTION_LAYER_TAP(layer, key) ACTION(ACT_LAYER_TAP, (layer) << 8 | (key))
 /* Default Layer */
-#define ACTION_DEFAULT_LAYER_SET(layer)             ACTION_DEFAULT_LAYER_BIT_SET((layer)/4, 1<<((layer)%4))
+#define ACTION_DEFAULT_LAYER_SET(layer) ACTION_DEFAULT_LAYER_BIT_SET((layer) / 4, 1 << ((layer) % 4))
 /* Layer Operation */
-#define ACTION_LAYER_CLEAR(on)                      ACTION_LAYER_BIT_AND(0, 0, (on))
-#define ACTION_LAYER_MOMENTARY(layer)               ACTION_LAYER_ON_OFF(layer)
-#define ACTION_LAYER_TOGGLE(layer)                  ACTION_LAYER_INVERT(layer, ON_RELEASE)
-#define ACTION_LAYER_INVERT(layer, on)              ACTION_LAYER_BIT_XOR((layer)/4,   1<<((layer)%4),  (on))
-#define ACTION_LAYER_ON(layer, on)                  ACTION_LAYER_BIT_OR( (layer)/4,   1<<((layer)%4),  (on))
-#define ACTION_LAYER_OFF(layer, on)                 ACTION_LAYER_BIT_AND((layer)/4, ~(1<<((layer)%4)), (on))
-#define ACTION_LAYER_SET(layer, on)                 ACTION_LAYER_BIT_SET((layer)/4,   1<<((layer)%4),  (on))
-#define ACTION_LAYER_ON_OFF(layer)                  ACTION_LAYER_TAP((layer), OP_ON_OFF)
-#define ACTION_LAYER_OFF_ON(layer)                  ACTION_LAYER_TAP((layer), OP_OFF_ON)
-#define ACTION_LAYER_SET_CLEAR(layer)               ACTION_LAYER_TAP((layer), OP_SET_CLEAR)
-#define ACTION_LAYER_ONESHOT(layer)                 ACTION_LAYER_TAP((layer), OP_ONESHOT)
-#define ACTION_LAYER_MODS(layer, mods)              ACTION(ACT_LAYER_MODS, (layer) << 8 | (mods))
+#define ACTION_LAYER_CLEAR(on) ACTION_LAYER_BIT_AND(0, 0, (on))
+#define ACTION_LAYER_MOMENTARY(layer) ACTION_LAYER_ON_OFF(layer)
+#define ACTION_LAYER_TOGGLE(layer) ACTION_LAYER_INVERT(layer, ON_RELEASE)
+#define ACTION_LAYER_INVERT(layer, on) ACTION_LAYER_BIT_XOR((layer) / 4, 1 << ((layer) % 4), (on))
+#define ACTION_LAYER_ON(layer, on) ACTION_LAYER_BIT_OR((layer) / 4, 1 << ((layer) % 4), (on))
+#define ACTION_LAYER_OFF(layer, on) ACTION_LAYER_BIT_AND((layer) / 4, ~(1 << ((layer) % 4)), (on))
+#define ACTION_LAYER_SET(layer, on) ACTION_LAYER_BIT_SET((layer) / 4, 1 << ((layer) % 4), (on))
+#define ACTION_LAYER_ON_OFF(layer) ACTION_LAYER_TAP((layer), OP_ON_OFF)
+#define ACTION_LAYER_OFF_ON(layer) ACTION_LAYER_TAP((layer), OP_OFF_ON)
+#define ACTION_LAYER_SET_CLEAR(layer) ACTION_LAYER_TAP((layer), OP_SET_CLEAR)
+#define ACTION_LAYER_ONESHOT(layer) ACTION_LAYER_TAP((layer), OP_ONESHOT)
+#define ACTION_LAYER_MODS(layer, mods) ACTION(ACT_LAYER_MODS, (layer) << 8 | (mods))
 /* With Tapping */
-#define ACTION_LAYER_TAP_KEY(layer, key)            ACTION_LAYER_TAP((layer), (key))
-#define ACTION_LAYER_TAP_TOGGLE(layer)              ACTION_LAYER_TAP((layer), OP_TAP_TOGGLE)
+#define ACTION_LAYER_TAP_KEY(layer, key) ACTION_LAYER_TAP((layer), (key))
+#define ACTION_LAYER_TAP_TOGGLE(layer) ACTION_LAYER_TAP((layer), OP_TAP_TOGGLE)
 /* Bitwise Operation */
-#define ACTION_LAYER_BIT_AND(part, bits, on)        ACTION_LAYER_BITOP(OP_BIT_AND, (part), (bits), (on))
-#define ACTION_LAYER_BIT_OR( part, bits, on)        ACTION_LAYER_BITOP(OP_BIT_OR,  (part), (bits), (on))
-#define ACTION_LAYER_BIT_XOR(part, bits, on)        ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), (on))
-#define ACTION_LAYER_BIT_SET(part, bits, on)        ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), (on))
+#define ACTION_LAYER_BIT_AND(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_AND, (part), (bits), (on))
+#define ACTION_LAYER_BIT_OR(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_OR, (part), (bits), (on))
+#define ACTION_LAYER_BIT_XOR(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), (on))
+#define ACTION_LAYER_BIT_SET(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), (on))
 /* Default Layer Bitwise Operation */
-#define ACTION_DEFAULT_LAYER_BIT_AND(part, bits)    ACTION_LAYER_BITOP(OP_BIT_AND, (part), (bits), 0)
-#define ACTION_DEFAULT_LAYER_BIT_OR( part, bits)    ACTION_LAYER_BITOP(OP_BIT_OR,  (part), (bits), 0)
-#define ACTION_DEFAULT_LAYER_BIT_XOR(part, bits)    ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), 0)
-#define ACTION_DEFAULT_LAYER_BIT_SET(part, bits)    ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), 0)
-
+#define ACTION_DEFAULT_LAYER_BIT_AND(part, bits) ACTION_LAYER_BITOP(OP_BIT_AND, (part), (bits), 0)
+#define ACTION_DEFAULT_LAYER_BIT_OR(part, bits) ACTION_LAYER_BITOP(OP_BIT_OR, (part), (bits), 0)
+#define ACTION_DEFAULT_LAYER_BIT_XOR(part, bits) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), 0)
+#define ACTION_DEFAULT_LAYER_BIT_SET(part, bits) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), 0)
 
 /** \brief Extensions
  */
@@ -313,25 +302,25 @@ enum backlight_opt {
 };
 
 /* Macro */
-#define ACTION_MACRO(id)                ACTION(ACT_MACRO, (id))
-#define ACTION_MACRO_TAP(id)            ACTION(ACT_MACRO, FUNC_TAP<<8 | (id))
-#define ACTION_MACRO_OPT(id, opt)       ACTION(ACT_MACRO, (opt)<<8 | (id))
+#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id))
+#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP << 8 | (id))
+#define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt) << 8 | (id))
 /* Backlight */
-#define ACTION_BACKLIGHT_INCREASE()     ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE << 8)
-#define ACTION_BACKLIGHT_DECREASE()     ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE << 8)
-#define ACTION_BACKLIGHT_TOGGLE()       ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE << 8)
-#define ACTION_BACKLIGHT_STEP()         ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8)
-#define ACTION_BACKLIGHT_ON()           ACTION(ACT_BACKLIGHT, BACKLIGHT_ON << 8)
-#define ACTION_BACKLIGHT_OFF()          ACTION(ACT_BACKLIGHT, BACKLIGHT_OFF << 8)
+#define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE << 8)
+#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE << 8)
+#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE << 8)
+#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8)
+#define ACTION_BACKLIGHT_ON() ACTION(ACT_BACKLIGHT, BACKLIGHT_ON << 8)
+#define ACTION_BACKLIGHT_OFF() ACTION(ACT_BACKLIGHT, BACKLIGHT_OFF << 8)
 /* Command */
-#define ACTION_COMMAND(id, opt)         ACTION(ACT_COMMAND,  (opt)<<8 | (id))
+#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt) << 8 | (id))
 /* Function */
 enum function_opts {
-    FUNC_TAP = 0x8,     /* indciates function is tappable */
+    FUNC_TAP = 0x8, /* indciates function is tappable */
 };
-#define ACTION_FUNCTION(id)             ACTION(ACT_FUNCTION, (id))
-#define ACTION_FUNCTION_TAP(id)         ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id))
-#define ACTION_FUNCTION_OPT(id, opt)    ACTION(ACT_FUNCTION, (opt)<<8 | (id))
+#define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id))
+#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP << 8 | (id))
+#define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt) << 8 | (id))
 /* OneHand Support */
 enum swap_hands_param_tap_op {
     OP_SH_TOGGLE = 0xF0,
@@ -342,13 +331,13 @@ enum swap_hands_param_tap_op {
     OP_SH_ON,
 };
 
-#define ACTION_SWAP_HANDS()             ACTION_SWAP_HANDS_ON_OFF()
-#define ACTION_SWAP_HANDS_TOGGLE()      ACTION(ACT_SWAP_HANDS, OP_SH_TOGGLE)
-#define ACTION_SWAP_HANDS_TAP_TOGGLE()  ACTION(ACT_SWAP_HANDS, OP_SH_TAP_TOGGLE)
-#define ACTION_SWAP_HANDS_TAP_KEY(key)  ACTION(ACT_SWAP_HANDS, key)
-#define ACTION_SWAP_HANDS_ON_OFF()      ACTION(ACT_SWAP_HANDS, OP_SH_ON_OFF)
-#define ACTION_SWAP_HANDS_OFF_ON()      ACTION(ACT_SWAP_HANDS, OP_SH_OFF_ON)
-#define ACTION_SWAP_HANDS_ON()          ACTION(ACT_SWAP_HANDS, OP_SH_ON)
-#define ACTION_SWAP_HANDS_OFF()         ACTION(ACT_SWAP_HANDS, OP_SH_OFF)
+#define ACTION_SWAP_HANDS() ACTION_SWAP_HANDS_ON_OFF()
+#define ACTION_SWAP_HANDS_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TOGGLE)
+#define ACTION_SWAP_HANDS_TAP_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TAP_TOGGLE)
+#define ACTION_SWAP_HANDS_TAP_KEY(key) ACTION(ACT_SWAP_HANDS, key)
+#define ACTION_SWAP_HANDS_ON_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_ON_OFF)
+#define ACTION_SWAP_HANDS_OFF_ON() ACTION(ACT_SWAP_HANDS, OP_SH_OFF_ON)
+#define ACTION_SWAP_HANDS_ON() ACTION(ACT_SWAP_HANDS, OP_SH_ON)
+#define ACTION_SWAP_HANDS_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_OFF)
 
 #endif /* ACTION_CODE_H */
index dfcbc110ad1941ef4cea4c9223f0dc2970dbcf75..07d78c56d4f9c50a187a0fb3da95be40300b51df 100644 (file)
@@ -5,12 +5,11 @@
 #include "action_layer.h"
 
 #ifdef DEBUG_ACTION
-#include "debug.h"
+#    include "debug.h"
 #else
-#include "nodebug.h"
+#    include "nodebug.h"
 #endif
 
-
 /** \brief Default Layer State
  */
 layer_state_t default_layer_state = 0;
@@ -19,34 +18,30 @@ layer_state_t default_layer_state = 0;
  *
  * Run user code on default layer state change
  */
-__attribute__((weak))
-layer_state_t default_layer_state_set_user(layer_state_t state) {
-  return state;
-}
+__attribute__((weak)) layer_state_t default_layer_state_set_user(layer_state_t state) { return state; }
 
 /** \brief Default Layer State Set At Keyboard Level
  *
  *  Run keyboard code on default layer state change
  */
-__attribute__((weak))
-layer_state_t default_layer_state_set_kb(layer_state_t state) {
-  return default_layer_state_set_user(state);
-}
+__attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t state) { return default_layer_state_set_user(state); }
 
 /** \brief Default Layer State Set
  *
  * Static function to set the default layer state, prints debug info and clears keys
  */
 static void default_layer_state_set(layer_state_t state) {
-  state = default_layer_state_set_kb(state);
-  debug("default_layer_state: ");
-  default_layer_debug(); debug(" to ");
-  default_layer_state = state;
-  default_layer_debug(); debug("\n");
+    state = default_layer_state_set_kb(state);
+    debug("default_layer_state: ");
+    default_layer_debug();
+    debug(" to ");
+    default_layer_state = state;
+    default_layer_debug();
+    debug("\n");
 #ifdef STRICT_LAYER_RELEASE
-  clear_keyboard_but_mods(); // To avoid stuck keys
+    clear_keyboard_but_mods();  // To avoid stuck keys
 #else
-  clear_keyboard_but_mods_and_keys(); // Don't reset held keys
+    clear_keyboard_but_mods_and_keys();  // Don't reset held keys
 #endif
 }
 
@@ -54,43 +49,32 @@ static void default_layer_state_set(layer_state_t state) {
  *
  * Print out the hex value of the 32-bit default layer state, as well as the value of the highest bit.
  */
-void default_layer_debug(void) {
-  dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state));
-}
+void default_layer_debug(void) { dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state)); }
 
 /** \brief Default Layer Set
  *
  * Sets the default layer state.
  */
-void default_layer_set(layer_state_t state) {
-  default_layer_state_set(state);
-}
+void default_layer_set(layer_state_t state) { default_layer_state_set(state); }
 
 #ifndef NO_ACTION_LAYER
 /** \brief Default Layer Or
  *
  * Turns on the default layer based on matching bits between specifed layer and existing layer state
  */
-void default_layer_or(layer_state_t state) {
-  default_layer_state_set(default_layer_state | state);
-}
+void default_layer_or(layer_state_t state) { default_layer_state_set(default_layer_state | state); }
 /** \brief Default Layer And
  *
  * Turns on default layer based on matching enabled bits between specifed layer and existing layer state
  */
-void default_layer_and(layer_state_t state) {
-  default_layer_state_set(default_layer_state & state);
-}
+void default_layer_and(layer_state_t state) { default_layer_state_set(default_layer_state & state); }
 /** \brief Default Layer Xor
  *
  * Turns on default layer based on non-matching bits between specifed layer and existing layer state
  */
-void default_layer_xor(layer_state_t state) {
-  default_layer_state_set(default_layer_state ^ state);
-}
+void default_layer_xor(layer_state_t state) { default_layer_state_set(default_layer_state ^ state); }
 #endif
 
-
 #ifndef NO_ACTION_LAYER
 /** \brief Keymap Layer State
  */
@@ -100,123 +84,101 @@ layer_state_t layer_state = 0;
  *
  * Runs user code on layer state change
  */
-__attribute__((weak))
-layer_state_t layer_state_set_user(layer_state_t state) {
-  return state;
-}
+__attribute__((weak)) layer_state_t layer_state_set_user(layer_state_t state) { return state; }
 
 /** \brief Layer state set keyboard
  *
  * Runs keyboard code on layer state change
  */
-__attribute__((weak))
-layer_state_t layer_state_set_kb(layer_state_t state) {
-  return layer_state_set_user(state);
-}
+__attribute__((weak)) layer_state_t layer_state_set_kb(layer_state_t state) { return layer_state_set_user(state); }
 
 /** \brief Layer state set
  *
  * Sets the layer to match the specifed state (a bitmask)
  */
 void layer_state_set(layer_state_t state) {
-  state = layer_state_set_kb(state);
-  dprint("layer_state: ");
-  layer_debug(); dprint(" to ");
-  layer_state = state;
-  layer_debug(); dprintln();
-#ifdef STRICT_LAYER_RELEASE
-  clear_keyboard_but_mods(); // To avoid stuck keys
-#else
-  clear_keyboard_but_mods_and_keys(); // Don't reset held keys
-#endif
+    state = layer_state_set_kb(state);
+    dprint("layer_state: ");
+    layer_debug();
+    dprint(" to ");
+    layer_state = state;
+    layer_debug();
+    dprintln();
+#    ifdef STRICT_LAYER_RELEASE
+    clear_keyboard_but_mods();  // To avoid stuck keys
+#    else
+    clear_keyboard_but_mods_and_keys();  // Don't reset held keys
+#    endif
 }
 
 /** \brief Layer clear
  *
  * Turn off all layers
  */
-void layer_clear(void) {
-  layer_state_set(0);
-}
+void layer_clear(void) { layer_state_set(0); }
 
 /** \brief Layer state is
  *
  * Return whether the given state is on (it might still be shadowed by a higher state, though)
  */
-bool layer_state_is(uint8_t layer) {
-  return layer_state_cmp(layer_state, layer);
-}
+bool layer_state_is(uint8_t layer) { return layer_state_cmp(layer_state, layer); }
 
 /** \brief Layer state compare
  *
  * Used for comparing layers {mostly used for unit testing}
  */
 bool layer_state_cmp(layer_state_t cmp_layer_state, uint8_t layer) {
-  if (!cmp_layer_state) { return layer == 0; }
-  return (cmp_layer_state & (1UL<<layer)) != 0;
+    if (!cmp_layer_state) {
+        return layer == 0;
+    }
+    return (cmp_layer_state & (1UL << layer)) != 0;
 }
 
 /** \brief Layer move
  *
  * Turns on the given layer and turn off all other layers
  */
-void layer_move(uint8_t layer) {
-  layer_state_set(1UL<<layer);
-}
+void layer_move(uint8_t layer) { layer_state_set(1UL << layer); }
 
 /** \brief Layer on
  *
  * Turns on given layer
  */
-void layer_on(uint8_t layer) {
-  layer_state_set(layer_state | (1UL<<layer));
-}
+void layer_on(uint8_t layer) { layer_state_set(layer_state | (1UL << layer)); }
 
 /** \brief Layer off
  *
  * Turns off given layer
  */
-void layer_off(uint8_t layer) {
-  layer_state_set(layer_state & ~(1UL<<layer));
-}
+void layer_off(uint8_t layer) { layer_state_set(layer_state & ~(1UL << layer)); }
 
 /** \brief Layer invert
  *
  * Toggle the given layer (set it if it's unset, or unset it if it's set)
  */
-void layer_invert(uint8_t layer) {
-  layer_state_set(layer_state ^ (1UL<<layer));
-}
+void layer_invert(uint8_t layer) { layer_state_set(layer_state ^ (1UL << layer)); }
 
 /** \brief Layer or
  *
  * Turns on layers based on matching bits between specifed layer and existing layer state
  */
-void layer_or(layer_state_t state) {
-  layer_state_set(layer_state | state);
-}
+void layer_or(layer_state_t state) { layer_state_set(layer_state | state); }
 /** \brief Layer and
  *
  * Turns on layers based on matching enabled bits between specifed layer and existing layer state
  */
-void layer_and(layer_state_t state) {
-  layer_state_set(layer_state & state);
-}
+void layer_and(layer_state_t state) { layer_state_set(layer_state & state); }
 /** \brief Layer xor
  *
  * Turns on layers based on non-matching bits between specifed layer and existing layer state
  */
-void layer_xor(layer_state_t state) {
-  layer_state_set(layer_state ^ state);
-}
+void layer_xor(layer_state_t state) { layer_state_set(layer_state ^ state); }
 
 /** \brief Layer debug printing
  *
  * Print out the hex value of the 32-bit layer state, as well as the value of the highest bit.
  */
-void layer_debug(void) {
-  dprintf("%08lX(%u)", layer_state, biton32(layer_state));
-}
+void layer_debug(void) { dprintf("%08lX(%u)", layer_state, biton32(layer_state)); }
 #endif
 
 #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
@@ -230,16 +192,13 @@ uint8_t source_layers_cache[(MATRIX_ROWS * MATRIX_COLS + 7) / 8][MAX_LAYER_BITS]
  * Updates the cached keys when changing layers
  */
 void update_source_layers_cache(keypos_t key, uint8_t layer) {
-  const uint8_t key_number = key.col + (key.row * MATRIX_COLS);
-  const uint8_t storage_row = key_number / 8;
-  const uint8_t storage_bit = key_number % 8;
-
-  for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) {
-    source_layers_cache[storage_row][bit_number] ^=
-      (-((layer & (1U << bit_number)) != 0)
-        ^ source_layers_cache[storage_row][bit_number])
-      & (1U << storage_bit);
-  }
+    const uint8_t key_number  = key.col + (key.row * MATRIX_COLS);
+    const uint8_t storage_row = key_number / 8;
+    const uint8_t storage_bit = key_number % 8;
+
+    for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) {
+        source_layers_cache[storage_row][bit_number] ^= (-((layer & (1U << bit_number)) != 0) ^ source_layers_cache[storage_row][bit_number]) & (1U << storage_bit);
+    }
 }
 
 /** \brief read source layers cache
@@ -247,19 +206,16 @@ void update_source_layers_cache(keypos_t key, uint8_t layer) {
  * reads the cached keys stored when the layer was changed
  */
 uint8_t read_source_layers_cache(keypos_t key) {
-  const uint8_t key_number = key.col + (key.row * MATRIX_COLS);
-  const uint8_t storage_row = key_number / 8;
-  const uint8_t storage_bit = key_number % 8;
-  uint8_t layer = 0;
-
-  for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) {
-    layer |=
-      ((source_layers_cache[storage_row][bit_number]
-        & (1U << storage_bit)) != 0)
-      << bit_number;
-  }
-
-  return layer;
+    const uint8_t key_number  = key.col + (key.row * MATRIX_COLS);
+    const uint8_t storage_row = key_number / 8;
+    const uint8_t storage_bit = key_number % 8;
+    uint8_t       layer       = 0;
+
+    for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) {
+        layer |= ((source_layers_cache[storage_row][bit_number] & (1U << storage_bit)) != 0) << bit_number;
+    }
+
+    return layer;
 }
 #endif
 
@@ -272,49 +228,47 @@ uint8_t read_source_layers_cache(keypos_t key) {
  */
 action_t store_or_get_action(bool pressed, keypos_t key) {
 #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
-  if (disable_action_cache) {
-    return layer_switch_get_action(key);
-  }
-
-  uint8_t layer;
-
-  if (pressed) {
-    layer = layer_switch_get_layer(key);
-    update_source_layers_cache(key, layer);
-  }
-  else {
-    layer = read_source_layers_cache(key);
-  }
-  return action_for_key(layer, key);
+    if (disable_action_cache) {
+        return layer_switch_get_action(key);
+    }
+
+    uint8_t layer;
+
+    if (pressed) {
+        layer = layer_switch_get_layer(key);
+        update_source_layers_cache(key, layer);
+    } else {
+        layer = read_source_layers_cache(key);
+    }
+    return action_for_key(layer, key);
 #else
-  return layer_switch_get_action(key);
+    return layer_switch_get_action(key);
 #endif
 }
 
-
 /** \brief Layer switch get layer
  *
  * Gets the layer based on key info
  */
 uint8_t layer_switch_get_layer(keypos_t key) {
 #ifndef NO_ACTION_LAYER
-  action_t action;
-  action.code = ACTION_TRANSPARENT;
-
-  layer_state_t layers = layer_state | default_layer_state;
-  /* check top layer first */
-  for (int8_t i = sizeof(layer_state_t) * 8 - 1; i >= 0; i--) {
-    if (layers & (1UL << i)) {
-      action = action_for_key(i, key);
-      if (action.code != ACTION_TRANSPARENT) {
-          return i;
-      }
+    action_t action;
+    action.code = ACTION_TRANSPARENT;
+
+    layer_state_t layers = layer_state | default_layer_state;
+    /* check top layer first */
+    for (int8_t i = sizeof(layer_state_t) * 8 - 1; i >= 0; i--) {
+        if (layers & (1UL << i)) {
+            action = action_for_key(i, key);
+            if (action.code != ACTION_TRANSPARENT) {
+                return i;
+            }
+        }
     }
-  }
-  /* fall back to layer 0 */
-  return 0;
+    /* fall back to layer 0 */
+    return 0;
 #else
-  return biton32(default_layer_state);
+    return biton32(default_layer_state);
 #endif
 }
 
@@ -322,6 +276,4 @@ uint8_t layer_switch_get_layer(keypos_t key) {
  *
  * Gets action code based on key position
  */
-action_t layer_switch_get_action(keypos_t key) {
-  return action_for_key(layer_switch_get_layer(key), key);
-}
+action_t layer_switch_get_action(keypos_t key) { return action_for_key(layer_switch_get_layer(key), key); }
index a2734a29ee552020d2d2b220cef46f2d5bf42284..fee9b244df001dd938f9ea064006a3a72ea4619b 100644 (file)
@@ -23,27 +23,24 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #if defined(LAYER_STATE_8BIT)
 typedef uint8_t layer_state_t;
-#define get_highest_layer(state) biton8(state)
+#    define get_highest_layer(state) biton8(state)
 #elif defined(LAYER_STATE_16BIT)
 typedef uint16_t layer_state_t;
-#define get_highest_layer(state) biton16(state)
+#    define get_highest_layer(state) biton16(state)
 #else
 typedef uint32_t layer_state_t;
-#define get_highest_layer(state) biton32(state)
+#    define get_highest_layer(state) biton32(state)
 #endif
 
-
 /*
  * Default Layer
  */
 extern layer_state_t default_layer_state;
-void default_layer_debug(void);
-void default_layer_set(layer_state_t state);
+void                 default_layer_debug(void);
+void                 default_layer_set(layer_state_t state);
 
-__attribute__((weak))
-layer_state_t default_layer_state_set_kb(layer_state_t state);
-__attribute__((weak))
-layer_state_t default_layer_state_set_user(layer_state_t state);
+__attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t state);
+__attribute__((weak)) layer_state_t default_layer_state_set_user(layer_state_t state);
 
 #ifndef NO_ACTION_LAYER
 /* bitwise operation */
@@ -51,12 +48,11 @@ void default_layer_or(layer_state_t state);
 void default_layer_and(layer_state_t state);
 void default_layer_xor(layer_state_t state);
 #else
-#define default_layer_or(state)
-#define default_layer_and(state)
-#define default_layer_xor(state)
+#    define default_layer_or(state)
+#    define default_layer_and(state)
+#    define default_layer_xor(state)
 #endif
 
-
 /*
  * Keymap Layer
  */
@@ -78,21 +74,21 @@ void layer_or(layer_state_t state);
 void layer_and(layer_state_t state);
 void layer_xor(layer_state_t state);
 #else
-#define layer_state                    0
-
-#define layer_state_set(layer)
-#define layer_state_is(layer)          (layer == 0)
-#define layer_state_cmp(state, layer)  (state == 0 ? layer == 0 : (state & 1UL << layer) != 0)
-
-#define layer_debug()
-#define layer_clear()
-#define layer_move(layer)
-#define layer_on(layer)
-#define layer_off(layer)
-#define layer_invert(layer)
-#define layer_or(state)
-#define layer_and(state)
-#define layer_xor(state)
+#    define layer_state 0
+
+#    define layer_state_set(layer)
+#    define layer_state_is(layer) (layer == 0)
+#    define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & 1UL << layer) != 0)
+
+#    define layer_debug()
+#    define layer_clear()
+#    define layer_move(layer)
+#    define layer_on(layer)
+#    define layer_off(layer)
+#    define layer_invert(layer)
+#    define layer_or(state)
+#    define layer_and(state)
+#    define layer_xor(state)
 #endif
 
 layer_state_t layer_state_set_user(layer_state_t state);
@@ -101,8 +97,8 @@ layer_state_t layer_state_set_kb(layer_state_t state);
 /* pressed actions cache */
 #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
 /* The number of bits needed to represent the layer number: log2(32). */
-#define MAX_LAYER_BITS 5
-void update_source_layers_cache(keypos_t key, uint8_t layer);
+#    define MAX_LAYER_BITS 5
+void    update_source_layers_cache(keypos_t key, uint8_t layer);
 uint8_t read_source_layers_cache(keypos_t key);
 #endif
 action_t store_or_get_action(bool pressed, keypos_t key);
index 12bef295861ee64c6021015ac66ea2c9f5c431e4..92228c0ba81665f9740dbb620818003107230ccf 100644 (file)
@@ -20,22 +20,20 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "wait.h"
 
 #ifdef DEBUG_ACTION
-#include "debug.h"
+#    include "debug.h"
 #else
-#include "nodebug.h"
+#    include "nodebug.h"
 #endif
 
-
 #ifndef NO_ACTION_MACRO
 
-#define MACRO_READ()  (macro = MACRO_GET(macro_p++))
+#    define MACRO_READ() (macro = MACRO_GET(macro_p++))
 /** \brief Action Macro Play
  *
  * FIXME: Needs doc
  */
-void action_macro_play(const macro_t *macro_p)
-{
-    macro_t macro = END;
+void action_macro_play(const macro_t *macro_p) {
+    macro_t macro    = END;
     uint8_t interval = 0;
 
     if (!macro_p) return;
@@ -64,7 +62,10 @@ void action_macro_play(const macro_t *macro_p)
             case WAIT:
                 MACRO_READ();
                 dprintf("WAIT(%u)\n", macro);
-                { uint8_t ms = macro; while (ms--) wait_ms(1); }
+                {
+                    uint8_t ms = macro;
+                    while (ms--) wait_ms(1);
+                }
                 break;
             case INTERVAL:
                 interval = MACRO_READ();
@@ -76,14 +77,17 @@ void action_macro_play(const macro_t *macro_p)
                 break;
             case 0x84 ... 0xF3:
                 dprintf("UP(%02X)\n", macro);
-                unregister_code(macro&0x7F);
+                unregister_code(macro & 0x7F);
                 break;
             case END:
             default:
                 return;
         }
         // interval
-        { uint8_t ms = interval; while (ms--) wait_ms(1); }
+        {
+            uint8_t ms = interval;
+            while (ms--) wait_ms(1);
+        }
     }
 }
 #endif
index f373f5068e57a709a88ca752616fb7cb1b7a137a..21004ead62be31c1e59f98a959000deaa7efc0bd 100644 (file)
@@ -19,18 +19,18 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdint.h>
 #include "progmem.h"
 
-
-
 typedef uint8_t macro_t;
 
-#define MACRO_NONE      (macro_t*)0
-#define MACRO(...)      ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })
-#define MACRO_GET(p)    pgm_read_byte(p)
+#define MACRO_NONE (macro_t *)0
+#define MACRO(...)                                          \
+    ({                                                      \
+        static const macro_t __m[] PROGMEM = {__VA_ARGS__}; \
+        &__m[0];                                            \
+    })
+#define MACRO_GET(p) pgm_read_byte(p)
 
 // Sends press when the macro key is pressed, release when release, or tap_macro when the key has been tapped
-#define MACRO_TAP_HOLD(record, press, release, tap_macro) ( ((record)->event.pressed) ? \
-     ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? (press) : MACRO_NONE ) : \
-     ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (tap_macro) : (release) ) )
+#define MACRO_TAP_HOLD(record, press, release, tap_macro) (((record)->event.pressed) ? (((record)->tap.count <= 0 || (record)->tap.interrupted) ? (press) : MACRO_NONE) : (((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (tap_macro) : (release)))
 
 // Holds down the modifier mod when the macro key is held, or sends macro instead when tapped
 #define MACRO_TAP_HOLD_MOD(record, macro, mod) MACRO_TAP_HOLD(record, (MACRO(D(mod), END)), MACRO(U(mod), END), macro)
@@ -38,25 +38,27 @@ typedef uint8_t macro_t;
 // Holds down the modifier mod when the macro key is held, or pressed a shifted key when tapped (eg: shift+3 for #)
 #define MACRO_TAP_SHFT_KEY_HOLD_MOD(record, key, mod) MACRO_TAP_HOLD_MOD(record, (MACRO(I(10), D(LSFT), T(key), U(LSFT), END)), mod)
 
-
 // Momentary switch layer when held, sends macro if tapped
-#define MACRO_TAP_HOLD_LAYER(record, macro, layer) ( ((record)->event.pressed) ? \
-     ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? ({layer_on((layer)); MACRO_NONE; }) : MACRO_NONE ) : \
-     ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (macro) : ({layer_off((layer)); MACRO_NONE; }) ) )
+#define MACRO_TAP_HOLD_LAYER(record, macro, layer)                                                         \
+    (((record)->event.pressed) ? (((record)->tap.count <= 0 || (record)->tap.interrupted) ? ({             \
+        layer_on((layer));                                                                                 \
+        MACRO_NONE;                                                                                        \
+    })                                                                                                     \
+                                                                                          : MACRO_NONE)    \
+                               : (((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (macro) : ({ \
+                                     layer_off((layer));                                                   \
+                                     MACRO_NONE;                                                           \
+                                 })))
 
 // Momentary switch layer when held, presses a shifted key when tapped (eg: shift+3 for #)
 #define MACRO_TAP_SHFT_KEY_HOLD_LAYER(record, key, layer) MACRO_TAP_HOLD_LAYER(record, MACRO(I(10), D(LSFT), T(key), U(LSFT), END), layer)
-     
-
 
 #ifndef NO_ACTION_MACRO
 void action_macro_play(const macro_t *macro_p);
 #else
-#define action_macro_play(macro)
+#    define action_macro_play(macro)
 #endif
 
-
-
 /* Macro commands
  *   code(0x04-73)                      // key down(1byte)
  *   code(0x04-73) | 0x80               // key up(1byte)
@@ -75,16 +77,16 @@ void action_macro_play(const macro_t *macro_p);
  *   conditionals
  *   loop
  */
-enum macro_command_id{
+enum macro_command_id {
     /* 0x00 - 0x03 */
-    END                 = 0x00,
+    END = 0x00,
     KEY_DOWN,
     KEY_UP,
 
     /* 0x04 - 0x73 (reserved for keycode down) */
 
     /* 0x74 - 0x83 */
-    WAIT                = 0x74,
+    WAIT = 0x74,
     INTERVAL,
 
     /* 0x84 - 0xf3 (reserved for keycode up) */
@@ -92,33 +94,31 @@ enum macro_command_id{
     /* 0xf4 - 0xff */
 };
 
-
 /* TODO: keycode:0x04-0x73 can be handled by 1byte command  else 2bytes are needed
  * if keycode between 0x04 and 0x73
  *      keycode / (keycode|0x80)
  * else
  *      {KEY_DOWN, keycode} / {KEY_UP, keycode}
-*/
-#define DOWN(key)       KEY_DOWN, (key)
-#define UP(key)         KEY_UP, (key)
-#define TYPE(key)       DOWN(key), UP(key)
-#define WAIT(ms)        WAIT, (ms)
-#define INTERVAL(ms)    INTERVAL, (ms)
+ */
+#define DOWN(key) KEY_DOWN, (key)
+#define UP(key) KEY_UP, (key)
+#define TYPE(key) DOWN(key), UP(key)
+#define WAIT(ms) WAIT, (ms)
+#define INTERVAL(ms) INTERVAL, (ms)
 
 /* key down */
-#define D(key)          DOWN(KC_##key)
+#define D(key) DOWN(KC_##key)
 /* key up */
-#define U(key)          UP(KC_##key)
+#define U(key) UP(KC_##key)
 /* key type */
-#define T(key)          TYPE(KC_##key)
+#define T(key) TYPE(KC_##key)
 /* wait */
-#define W(ms)           WAIT(ms)
+#define W(ms) WAIT(ms)
 /* interval */
-#define I(ms)           INTERVAL(ms)
+#define I(ms) INTERVAL(ms)
 
 /* for backward comaptibility */
-#define MD(key)         DOWN(KC_##key)
-#define MU(key)         UP(KC_##key)
-
+#define MD(key) DOWN(KC_##key)
+#define MU(key) UP(KC_##key)
 
 #endif /* ACTION_MACRO_H */
index 3b67ed152f798f47778824d674d4328385183976..e0f524ad7a640dc63269bb837d7aa90521cd0227 100644 (file)
@@ -7,33 +7,30 @@
 #include "timer.h"
 
 #ifdef DEBUG_ACTION
-#include "debug.h"
+#    include "debug.h"
 #else
-#include "nodebug.h"
+#    include "nodebug.h"
 #endif
 
 #ifndef NO_ACTION_TAPPING
 
-#define IS_TAPPING()            !IS_NOEVENT(tapping_key.event)
-#define IS_TAPPING_PRESSED()    (IS_TAPPING() && tapping_key.event.pressed)
-#define IS_TAPPING_RELEASED()   (IS_TAPPING() && !tapping_key.event.pressed)
-#define IS_TAPPING_KEY(k)       (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k)))
+#    define IS_TAPPING() !IS_NOEVENT(tapping_key.event)
+#    define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed)
+#    define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed)
+#    define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k)))
 
-__attribute__ ((weak))
-uint16_t get_tapping_term(uint16_t keycode) {
-  return TAPPING_TERM;
-}
+__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode) { return TAPPING_TERM; }
 
-#ifdef TAPPING_TERM_PER_KEY
-#define WITHIN_TAPPING_TERM(e)  (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event)))
-#else
-#define WITHIN_TAPPING_TERM(e)  (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM)
-#endif
+#    ifdef TAPPING_TERM_PER_KEY
+#        define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event)))
+#    else
+#        define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM)
+#    endif
 
-static keyrecord_t tapping_key = {};
+static keyrecord_t tapping_key                         = {};
 static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {};
-static uint8_t waiting_buffer_head = 0;
-static uint8_t waiting_buffer_tail = 0;
+static uint8_t     waiting_buffer_head                 = 0;
+static uint8_t     waiting_buffer_tail                 = 0;
 
 static bool process_tapping(keyrecord_t *record);
 static bool waiting_buffer_enq(keyrecord_t record);
@@ -44,16 +41,16 @@ static void waiting_buffer_scan_tap(void);
 static void debug_tapping_key(void);
 static void debug_waiting_buffer(void);
 
-
 /** \brief Action Tapping Process
  *
  * FIXME: Needs doc
  */
-void action_tapping_process(keyrecord_t record)
-{
+void action_tapping_process(keyrecord_t record) {
     if (process_tapping(&record)) {
         if (!IS_NOEVENT(record.event)) {
-            debug("processed: "); debug_record(record); debug("\n");
+            debug("processed: ");
+            debug_record(record);
+            debug("\n");
         }
     } else {
         if (!waiting_buffer_enq(record)) {
@@ -71,8 +68,11 @@ void action_tapping_process(keyrecord_t record)
     }
     for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) {
         if (process_tapping(&waiting_buffer[waiting_buffer_tail])) {
-            debug("processed: waiting_buffer["); debug_dec(waiting_buffer_tail); debug("] = ");
-            debug_record(waiting_buffer[waiting_buffer_tail]); debug("\n\n");
+            debug("processed: waiting_buffer[");
+            debug_dec(waiting_buffer_tail);
+            debug("] = ");
+            debug_record(waiting_buffer[waiting_buffer_tail]);
+            debug("\n\n");
         } else {
             break;
         }
@@ -82,15 +82,13 @@ void action_tapping_process(keyrecord_t record)
     }
 }
 
-
 /** \brief Tapping
  *
  * Rule: Tap key is typed(pressed and released) within TAPPING_TERM.
  *       (without interfering by typing other key)
  */
 /* return true when key event is processed or consumed. */
-bool process_tapping(keyrecord_t *keyp)
-{
+bool process_tapping(keyrecord_t *keyp) {
     keyevent_t event = keyp->event;
 
     // if tapping
@@ -113,12 +111,12 @@ bool process_tapping(keyrecord_t *keyp)
                  * This can register the key before settlement of tapping,
                  * useful for long TAPPING_TERM but may prevent fast typing.
                  */
-#if defined(TAPPING_TERM_PER_KEY) || (!defined(PER_KEY_TAPPING_TERM) && TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD)
-#ifdef TAPPING_TERM_PER_KEY
-                else if ( ( get_tapping_term(get_event_keycode(tapping_key.event)) >= 500) && IS_RELEASED(event) && waiting_buffer_typed(event))
-#else
-                else if ( IS_RELEASED(event) && waiting_buffer_typed(event))
-#endif
+#    if defined(TAPPING_TERM_PER_KEY) || (!defined(PER_KEY_TAPPING_TERM) && TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD)
+#        ifdef TAPPING_TERM_PER_KEY
+                else if ((get_tapping_term(get_event_keycode(tapping_key.event)) >= 500) && IS_RELEASED(event) && waiting_buffer_typed(event))
+#        else
+                else if (IS_RELEASED(event) && waiting_buffer_typed(event))
+#        endif
                 {
                     debug("Tapping: End. No tap. Interfered by typing key\n");
                     process_record(&tapping_key);
@@ -127,7 +125,7 @@ bool process_tapping(keyrecord_t *keyp)
                     // enqueue
                     return false;
                 }
-#endif
+#    endif
                 /* Process release event of a key pressed before tapping starts
                  * Without this unexpected repeating will occur with having fast repeating setting
                  * https://github.com/tmk/tmk_keyboard/issues/60
@@ -151,8 +149,7 @@ bool process_tapping(keyrecord_t *keyp)
                     debug("Tapping: release event of a key pressed before tapping\n");
                     process_record(keyp);
                     return true;
-                }
-                else {
+                } else {
                     // set interrupted flag when other key preesed during tapping
                     if (event.pressed) {
                         tapping_key.tap.interrupted = true;
@@ -164,23 +161,19 @@ bool process_tapping(keyrecord_t *keyp)
             // tap_count > 0
             else {
                 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
-                    debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n");
+                    debug("Tapping: Tap release(");
+                    debug_dec(tapping_key.tap.count);
+                    debug(")\n");
                     keyp->tap = tapping_key.tap;
                     process_record(keyp);
                     tapping_key = *keyp;
                     debug_tapping_key();
                     return true;
-                }
-                else if (is_tap_key(event.key) && event.pressed) {
+                } else if (is_tap_key(event.key) && event.pressed) {
                     if (tapping_key.tap.count > 1) {
                         debug("Tapping: Start new tap with releasing last tap(>1).\n");
                         // unregister key
-                        process_record(&(keyrecord_t){
-                                .tap = tapping_key.tap,
-                                .event.key = tapping_key.event.key,
-                                .event.time = event.time,
-                                .event.pressed = false
-                        });
+                        process_record(&(keyrecord_t){.tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false});
                     } else {
                         debug("Tapping: Start while last tap(1).\n");
                     }
@@ -188,8 +181,7 @@ bool process_tapping(keyrecord_t *keyp)
                     waiting_buffer_scan_tap();
                     debug_tapping_key();
                     return true;
-                }
-                else {
+                } else {
                     if (!IS_NOEVENT(event)) {
                         debug("Tapping: key event while last tap(>0).\n");
                     }
@@ -202,29 +194,24 @@ bool process_tapping(keyrecord_t *keyp)
         else {
             if (tapping_key.tap.count == 0) {
                 debug("Tapping: End. Timeout. Not tap(0): ");
-                debug_event(event); debug("\n");
+                debug_event(event);
+                debug("\n");
                 process_record(&tapping_key);
                 tapping_key = (keyrecord_t){};
                 debug_tapping_key();
                 return false;
-            }  else {
+            } else {
                 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
                     debug("Tapping: End. last timeout tap release(>0).");
                     keyp->tap = tapping_key.tap;
                     process_record(keyp);
                     tapping_key = (keyrecord_t){};
                     return true;
-                }
-                else if (is_tap_key(event.key) && event.pressed) {
+                } else if (is_tap_key(event.key) && event.pressed) {
                     if (tapping_key.tap.count > 1) {
                         debug("Tapping: Start new tap with releasing last timeout tap(>1).\n");
                         // unregister key
-                        process_record(&(keyrecord_t){
-                                .tap = tapping_key.tap,
-                                .event.key = tapping_key.event.key,
-                                .event.time = event.time,
-                                .event.pressed = false
-                        });
+                        process_record(&(keyrecord_t){.tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false});
                     } else {
                         debug("Tapping: Start while last timeout tap(1).\n");
                     }
@@ -232,8 +219,7 @@ bool process_tapping(keyrecord_t *keyp)
                     waiting_buffer_scan_tap();
                     debug_tapping_key();
                     return true;
-                }
-                else {
+                } else {
                     if (!IS_NOEVENT(event)) {
                         debug("Tapping: key event while last timeout tap(>0).\n");
                     }
@@ -246,18 +232,20 @@ bool process_tapping(keyrecord_t *keyp)
         if (WITHIN_TAPPING_TERM(event)) {
             if (event.pressed) {
                 if (IS_TAPPING_KEY(event.key)) {
-#ifndef TAPPING_FORCE_HOLD
+#    ifndef TAPPING_FORCE_HOLD
                     if (!tapping_key.tap.interrupted && tapping_key.tap.count > 0) {
                         // sequential tap.
                         keyp->tap = tapping_key.tap;
                         if (keyp->tap.count < 15) keyp->tap.count += 1;
-                        debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n");
+                        debug("Tapping: Tap press(");
+                        debug_dec(keyp->tap.count);
+                        debug(")\n");
                         process_record(keyp);
                         tapping_key = *keyp;
                         debug_tapping_key();
                         return true;
                     }
-#endif
+#    endif
                     // FIX: start new tap again
                     tapping_key = *keyp;
                     return true;
@@ -284,7 +272,8 @@ bool process_tapping(keyrecord_t *keyp)
             // FIX: process_action here?
             // timeout. no sequential tap.
             debug("Tapping: End(Timeout after releasing last tap): ");
-            debug_event(event); debug("\n");
+            debug_event(event);
+            debug("\n");
             tapping_key = (keyrecord_t){};
             debug_tapping_key();
             return false;
@@ -306,13 +295,11 @@ bool process_tapping(keyrecord_t *keyp)
     }
 }
 
-
 /** \brief Waiting buffer enq
  *
  * FIXME: Needs docs
  */
-bool waiting_buffer_enq(keyrecord_t record)
-{
+bool waiting_buffer_enq(keyrecord_t record) {
     if (IS_NOEVENT(record.event)) {
         return true;
     }
@@ -323,9 +310,10 @@ bool waiting_buffer_enq(keyrecord_t record)
     }
 
     waiting_buffer[waiting_buffer_head] = record;
-    waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE;
+    waiting_buffer_head                 = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE;
 
-    debug("waiting_buffer_enq: "); debug_waiting_buffer();
+    debug("waiting_buffer_enq: ");
+    debug_waiting_buffer();
     return true;
 }
 
@@ -333,8 +321,7 @@ bool waiting_buffer_enq(keyrecord_t record)
  *
  * FIXME: Needs docs
  */
-void waiting_buffer_clear(void)
-{
+void waiting_buffer_clear(void) {
     waiting_buffer_head = 0;
     waiting_buffer_tail = 0;
 }
@@ -343,10 +330,9 @@ void waiting_buffer_clear(void)
  *
  * FIXME: Needs docs
  */
-bool waiting_buffer_typed(keyevent_t event)
-{
+bool waiting_buffer_typed(keyevent_t event) {
     for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
-        if (KEYEQ(event.key, waiting_buffer[i].event.key) && event.pressed !=  waiting_buffer[i].event.pressed) {
+        if (KEYEQ(event.key, waiting_buffer[i].event.key) && event.pressed != waiting_buffer[i].event.pressed) {
             return true;
         }
     }
@@ -357,9 +343,7 @@ bool waiting_buffer_typed(keyevent_t event)
  *
  * FIXME: Needs docs
  */
-__attribute__((unused))
-bool waiting_buffer_has_anykey_pressed(void)
-{
+__attribute__((unused)) bool waiting_buffer_has_anykey_pressed(void) {
     for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
         if (waiting_buffer[i].event.pressed) return true;
     }
@@ -370,47 +354,49 @@ bool waiting_buffer_has_anykey_pressed(void)
  *
  * FIXME: Needs docs
  */
-void waiting_buffer_scan_tap(void)
-{
+void waiting_buffer_scan_tap(void) {
     // tapping already is settled
     if (tapping_key.tap.count > 0) return;
     // invalid state: tapping_key released && tap.count == 0
     if (!tapping_key.event.pressed) return;
 
     for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
-        if (IS_TAPPING_KEY(waiting_buffer[i].event.key) &&
-                !waiting_buffer[i].event.pressed &&
-                WITHIN_TAPPING_TERM(waiting_buffer[i].event)) {
-            tapping_key.tap.count = 1;
+        if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && !waiting_buffer[i].event.pressed && WITHIN_TAPPING_TERM(waiting_buffer[i].event)) {
+            tapping_key.tap.count       = 1;
             waiting_buffer[i].tap.count = 1;
             process_record(&tapping_key);
 
-            debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n");
+            debug("waiting_buffer_scan_tap: found at [");
+            debug_dec(i);
+            debug("]\n");
             debug_waiting_buffer();
             return;
         }
     }
 }
 
-
 /** \brief Tapping key debug print
  *
  * FIXME: Needs docs
  */
-static void debug_tapping_key(void)
-{
-    debug("TAPPING_KEY="); debug_record(tapping_key); debug("\n");
+static void debug_tapping_key(void) {
+    debug("TAPPING_KEY=");
+    debug_record(tapping_key);
+    debug("\n");
 }
 
 /** \brief Waiting buffer debug print
  *
  * FIXME: Needs docs
  */
-static void debug_waiting_buffer(void)
-{
+static void debug_waiting_buffer(void) {
     debug("{ ");
     for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
-        debug("["); debug_dec(i); debug("]="); debug_record(waiting_buffer[i]); debug(" ");
+        debug("[");
+        debug_dec(i);
+        debug("]=");
+        debug_record(waiting_buffer[i]);
+        debug(" ");
     }
     debug("}\n");
 }
index 1db43a442e33cd98a2e266419866563cf0875701..509d5eabd84f6bcfa9ab8758255c80d2a13a98a4 100644 (file)
@@ -17,27 +17,24 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef ACTION_TAPPING_H
 #define ACTION_TAPPING_H
 
-
-
 /* period of tapping(ms) */
 #ifndef TAPPING_TERM
-#define TAPPING_TERM    200
+#    define TAPPING_TERM 200
 #endif
 
 //#define RETRO_TAPPING // Tap anyway, even after TAPPING_TERM, as long as there was no interruption
 
 /* tap count needed for toggling a feature */
 #ifndef TAPPING_TOGGLE
-#define TAPPING_TOGGLE  5
+#    define TAPPING_TOGGLE 5
 #endif
 
 #define WAITING_BUFFER_SIZE 8
 
-
 #ifndef NO_ACTION_TAPPING
 uint16_t get_event_keycode(keyevent_t event);
 uint16_t get_tapping_term(uint16_t keycode);
-void action_tapping_process(keyrecord_t record);
+void     action_tapping_process(keyrecord_t record);
 #endif
 
 #endif
index 365ed6a1ddff696aeb44a79e97ee532d463e9544..335aa36e62a14f737e49784f7b3ff49f35d0a529 100644 (file)
@@ -24,23 +24,22 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 extern keymap_config_t keymap_config;
 
-
-static uint8_t real_mods = 0;
-static uint8_t weak_mods = 0;
+static uint8_t real_mods  = 0;
+static uint8_t weak_mods  = 0;
 static uint8_t macro_mods = 0;
 
 #ifdef USB_6KRO_ENABLE
-#define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS)
-#define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS)
-#define RO_INC(a) RO_ADD(a, 1)
-#define RO_DEC(a) RO_SUB(a, 1)
-static int8_t cb_head = 0;
-static int8_t cb_tail = 0;
+#    define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS)
+#    define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS)
+#    define RO_INC(a) RO_ADD(a, 1)
+#    define RO_DEC(a) RO_SUB(a, 1)
+static int8_t cb_head  = 0;
+static int8_t cb_tail  = 0;
 static int8_t cb_count = 0;
 #endif
 
 // TODO: pointer variable is not needed
-//report_keyboard_t keyboard_report = {};
+// report_keyboard_t keyboard_report = {};
 report_keyboard_t *keyboard_report = &(report_keyboard_t){};
 
 extern inline void add_key(uint8_t key);
@@ -48,10 +47,10 @@ extern inline void del_key(uint8_t key);
 extern inline void clear_keys(void);
 
 #ifndef NO_ACTION_ONESHOT
-static uint8_t oneshot_mods = 0;
+static uint8_t oneshot_mods        = 0;
 static uint8_t oneshot_locked_mods = 0;
-uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; }
-void set_oneshot_locked_mods(uint8_t mods) {
+uint8_t        get_oneshot_locked_mods(void) { return oneshot_locked_mods; }
+void           set_oneshot_locked_mods(uint8_t mods) {
     if (mods != oneshot_locked_mods) {
         oneshot_locked_mods = mods;
         oneshot_locked_mods_changed_kb(oneshot_locked_mods);
@@ -63,16 +62,12 @@ void clear_oneshot_locked_mods(void) {
         oneshot_locked_mods_changed_kb(oneshot_locked_mods);
     }
 }
-#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+#    if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
 static uint16_t oneshot_time = 0;
-bool has_oneshot_mods_timed_out(void) {
-  return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT;
-}
-#else
-bool has_oneshot_mods_timed_out(void) {
-    return false;
-}
-#endif
+bool            has_oneshot_mods_timed_out(void) { return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT; }
+#    else
+bool has_oneshot_mods_timed_out(void) { return false; }
+#    endif
 #endif
 
 /* oneshot layer */
@@ -88,44 +83,39 @@ static int8_t oneshot_layer_data = 0;
 inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; }
 inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; }
 
-#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+#    if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
 static uint16_t oneshot_layer_time = 0;
-inline bool has_oneshot_layer_timed_out() {
-    return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT &&
-        !(get_oneshot_layer_state() & ONESHOT_TOGGLED);
-}
-#endif
+inline bool     has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); }
+#    endif
 
-/** \brief Set oneshot layer 
+/** \brief Set oneshot layer
  *
  * FIXME: needs doc
  */
-void set_oneshot_layer(uint8_t layer, uint8_t state)
-{
+void set_oneshot_layer(uint8_t layer, uint8_t state) {
     oneshot_layer_data = layer << 3 | state;
     layer_on(layer);
-#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+#    if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
     oneshot_layer_time = timer_read();
-#endif
+#    endif
     oneshot_layer_changed_kb(get_oneshot_layer());
 }
-/** \brief Reset oneshot layer 
+/** \brief Reset oneshot layer
  *
  * FIXME: needs doc
  */
 void reset_oneshot_layer(void) {
     oneshot_layer_data = 0;
-#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+#    if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
     oneshot_layer_time = 0;
-#endif
+#    endif
     oneshot_layer_changed_kb(get_oneshot_layer());
 }
-/** \brief Clear oneshot layer 
+/** \brief Clear oneshot layer
  *
  * FIXME: needs doc
  */
-void clear_oneshot_layer_state(oneshot_fullfillment_t state)
-{
+void clear_oneshot_layer_state(oneshot_fullfillment_t state) {
     uint8_t start_state = oneshot_layer_data;
     oneshot_layer_data &= ~state;
     if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) {
@@ -137,10 +127,7 @@ void clear_oneshot_layer_state(oneshot_fullfillment_t state)
  *
  * FIXME: needs doc
  */
-bool is_oneshot_layer_active(void)
-{
-    return get_oneshot_layer_state();
-}
+bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); }
 #endif
 
 /** \brief Send keyboard report
@@ -148,17 +135,17 @@ bool is_oneshot_layer_active(void)
  * FIXME: needs doc
  */
 void send_keyboard_report(void) {
-    keyboard_report->mods  = real_mods;
+    keyboard_report->mods = real_mods;
     keyboard_report->mods |= weak_mods;
     keyboard_report->mods |= macro_mods;
 #ifndef NO_ACTION_ONESHOT
     if (oneshot_mods) {
-#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+#    if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
         if (has_oneshot_mods_timed_out()) {
             dprintf("Oneshot: timeout\n");
             clear_oneshot_mods();
         }
-#endif
+#    endif
         keyboard_report->mods |= oneshot_mods;
         if (has_anykey(keyboard_report)) {
             clear_oneshot_mods();
@@ -254,90 +241,72 @@ void clear_macro_mods(void) { macro_mods = 0; }
  * FIXME: needs doc
  */
 void set_oneshot_mods(uint8_t mods) {
-  if (oneshot_mods != mods) {
-#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
-    oneshot_time = timer_read();
-#endif
-    oneshot_mods = mods;
-    oneshot_mods_changed_kb(mods);
-  }
+    if (oneshot_mods != mods) {
+#    if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+        oneshot_time = timer_read();
+#    endif
+        oneshot_mods = mods;
+        oneshot_mods_changed_kb(mods);
+    }
 }
 /** \brief clear oneshot mods
  *
  * FIXME: needs doc
  */
 void clear_oneshot_mods(void) {
-  if (oneshot_mods) {
-    oneshot_mods = 0;
-#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
-    oneshot_time = 0;
-#endif
-    oneshot_mods_changed_kb(oneshot_mods);
-  }
+    if (oneshot_mods) {
+        oneshot_mods = 0;
+#    if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+        oneshot_time = 0;
+#    endif
+        oneshot_mods_changed_kb(oneshot_mods);
+    }
 }
 /** \brief get oneshot mods
  *
  * FIXME: needs doc
  */
-uint8_t get_oneshot_mods(void)
-{
-    return oneshot_mods;
-}
+uint8_t get_oneshot_mods(void) { return oneshot_mods; }
 #endif
 
 /** \brief Called when the one shot modifiers have been changed.
- * 
- * \param mods Contains the active modifiers active after the change. 
+ *
+ * \param mods Contains the active modifiers active after the change.
  */
-__attribute__((weak))
-void oneshot_locked_mods_changed_user(uint8_t mods) { }
+__attribute__((weak)) void oneshot_locked_mods_changed_user(uint8_t mods) {}
 
 /** \brief Called when the locked one shot modifiers have been changed.
- * 
- * \param mods Contains the active modifiers active after the change. 
+ *
+ * \param mods Contains the active modifiers active after the change.
  */
-__attribute__((weak))
-void oneshot_locked_mods_changed_kb(uint8_t mods) {
-    oneshot_locked_mods_changed_user(mods);
-}
+__attribute__((weak)) void oneshot_locked_mods_changed_kb(uint8_t mods) { oneshot_locked_mods_changed_user(mods); }
 
 /** \brief Called when the one shot modifiers have been changed.
- * 
+ *
  * \param mods Contains the active modifiers active after the change.
  */
-__attribute__((weak))
-void oneshot_mods_changed_user(uint8_t mods) { }
+__attribute__((weak)) void oneshot_mods_changed_user(uint8_t mods) {}
 
 /** \brief Called when the one shot modifiers have been changed.
- * 
+ *
  * \param mods Contains the active modifiers active after the change.
  */
-__attribute__((weak))
-void oneshot_mods_changed_kb(uint8_t mods) {
-    oneshot_mods_changed_user(mods);
-}
+__attribute__((weak)) void oneshot_mods_changed_kb(uint8_t mods) { oneshot_mods_changed_user(mods); }
 
 /** \brief Called when the one shot layers have been changed.
- * 
- * \param layer Contains the layer that is toggled on, or zero when toggled off. 
+ *
+ * \param layer Contains the layer that is toggled on, or zero when toggled off.
  */
-__attribute__((weak))
-void oneshot_layer_changed_user(uint8_t layer) { }
+__attribute__((weak)) void oneshot_layer_changed_user(uint8_t layer) {}
 
 /** \brief Called when the one shot layers have been changed.
- * 
+ *
  * \param layer Contains the layer that is toggled on, or zero when toggled off.
  */
-__attribute__((weak))
-void oneshot_layer_changed_kb(uint8_t layer) {
-    oneshot_layer_changed_user(layer);
-}
+__attribute__((weak)) void oneshot_layer_changed_kb(uint8_t layer) { oneshot_layer_changed_user(layer); }
 
 /** \brief inspect keyboard state
  *
  * FIXME: needs doc
  */
-uint8_t has_anymod(void)
-{
-    return bitpop(real_mods);
-}
+uint8_t has_anymod(void) { return bitpop(real_mods); }
index d03f5682a331c4ec552b348f7049e09b92db19ea..1ce03ed0e44a3a26b4b0e35bf0cafd25d669e28c 100644 (file)
@@ -29,65 +29,54 @@ extern report_keyboard_t *keyboard_report;
 void send_keyboard_report(void);
 
 /* key */
-inline void add_key(uint8_t key) {
-  add_key_to_report(keyboard_report, key);
-}
+inline void add_key(uint8_t key) { add_key_to_report(keyboard_report, key); }
 
-inline void del_key(uint8_t key) {
-  del_key_from_report(keyboard_report, key);
-}
+inline void del_key(uint8_t key) { del_key_from_report(keyboard_report, key); }
 
-inline void clear_keys(void) {
-  clear_keys_from_report(keyboard_report);
-}
+inline void clear_keys(void) { clear_keys_from_report(keyboard_report); }
 
 /* modifier */
 uint8_t get_mods(void);
-void add_mods(uint8_t mods);
-void del_mods(uint8_t mods);
-void set_mods(uint8_t mods);
-void clear_mods(void);
+void    add_mods(uint8_t mods);
+void    del_mods(uint8_t mods);
+void    set_mods(uint8_t mods);
+void    clear_mods(void);
 
 /* weak modifier */
 uint8_t get_weak_mods(void);
-void add_weak_mods(uint8_t mods);
-void del_weak_mods(uint8_t mods);
-void set_weak_mods(uint8_t mods);
-void clear_weak_mods(void);
+void    add_weak_mods(uint8_t mods);
+void    del_weak_mods(uint8_t mods);
+void    set_weak_mods(uint8_t mods);
+void    clear_weak_mods(void);
 
 /* macro modifier */
 uint8_t get_macro_mods(void);
-void add_macro_mods(uint8_t mods);
-void del_macro_mods(uint8_t mods);
-void set_macro_mods(uint8_t mods);
-void clear_macro_mods(void);
+void    add_macro_mods(uint8_t mods);
+void    del_macro_mods(uint8_t mods);
+void    set_macro_mods(uint8_t mods);
+void    clear_macro_mods(void);
 
 /* oneshot modifier */
-void set_oneshot_mods(uint8_t mods);
+void    set_oneshot_mods(uint8_t mods);
 uint8_t get_oneshot_mods(void);
-void clear_oneshot_mods(void);
-void oneshot_toggle(void);
-void oneshot_enable(void);
-void oneshot_disable(void);
-bool has_oneshot_mods_timed_out(void);
+void    clear_oneshot_mods(void);
+void    oneshot_toggle(void);
+void    oneshot_enable(void);
+void    oneshot_disable(void);
+bool    has_oneshot_mods_timed_out(void);
 
 uint8_t get_oneshot_locked_mods(void);
-void set_oneshot_locked_mods(uint8_t mods);
-void clear_oneshot_locked_mods(void);
-
-typedef enum {
-  ONESHOT_PRESSED = 0b01,
-  ONESHOT_OTHER_KEY_PRESSED = 0b10,
-  ONESHOT_START = 0b11,
-  ONESHOT_TOGGLED = 0b100
-} oneshot_fullfillment_t;
-void set_oneshot_layer(uint8_t layer, uint8_t state);
+void    set_oneshot_locked_mods(uint8_t mods);
+void    clear_oneshot_locked_mods(void);
+
+typedef enum { ONESHOT_PRESSED = 0b01, ONESHOT_OTHER_KEY_PRESSED = 0b10, ONESHOT_START = 0b11, ONESHOT_TOGGLED = 0b100 } oneshot_fullfillment_t;
+void    set_oneshot_layer(uint8_t layer, uint8_t state);
 uint8_t get_oneshot_layer(void);
-void clear_oneshot_layer_state(oneshot_fullfillment_t state);
-void reset_oneshot_layer(void);
-bool is_oneshot_layer_active(void);
+void    clear_oneshot_layer_state(oneshot_fullfillment_t state);
+void    reset_oneshot_layer(void);
+bool    is_oneshot_layer_active(void);
 uint8_t get_oneshot_layer_state(void);
-bool has_oneshot_layer_timed_out(void);
+bool    has_oneshot_layer_timed_out(void);
 
 void oneshot_locked_mods_changed_user(uint8_t mods);
 void oneshot_locked_mods_changed_kb(uint8_t mods);
index ba71bfeb0b74a1030fdd3e6641674debdb63162c..9015b00aab1a3dc907c146872a41c7e5247622f8 100644 (file)
 #include "samd51j18a.h"
 #include "md_bootloader.h"
 
-//Set watchdog timer to reset. Directs the bootloader to stay in programming mode.
+// Set watchdog timer to reset. Directs the bootloader to stay in programming mode.
 void bootloader_jump(void) {
 #ifdef KEYBOARD_massdrop_ctrl
-    //CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method.
-    uint8_t ver_ram_method[] = "v2.18Jun 22 2018 17:28:08";     //The version to match (NULL terminated by compiler)
-    uint8_t *ver_check = ver_ram_method;                        //Pointer to version match string for traversal
-    uint8_t *ver_rom = (uint8_t *)0x21A0;                       //Pointer to address in ROM where this specific bootloader version would exist
+    // CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method.
+    uint8_t  ver_ram_method[] = "v2.18Jun 22 2018 17:28:08";  // The version to match (NULL terminated by compiler)
+    uint8_t *ver_check        = ver_ram_method;               // Pointer to version match string for traversal
+    uint8_t *ver_rom          = (uint8_t *)0x21A0;            // Pointer to address in ROM where this specific bootloader version would exist
 
-    while (*ver_check && *ver_rom == *ver_check) {              //While there are check version characters to match and bootloader's version matches check's version
-        ver_check++;                                            //Move check version pointer to next character
-        ver_rom++;                                              //Move ROM version pointer to next character
+    while (*ver_check && *ver_rom == *ver_check) {  // While there are check version characters to match and bootloader's version matches check's version
+        ver_check++;                                // Move check version pointer to next character
+        ver_rom++;                                  // Move ROM version pointer to next character
     }
 
-    if (!*ver_check) {                                          //If check version pointer is NULL, all characters have matched
-        *MAGIC_ADDR = BOOTLOADER_MAGIC;                         //Set magic number into RAM
-        NVIC_SystemReset();                                     //Perform system reset
-        while (1) {}                                            //Won't get here
+    if (!*ver_check) {                   // If check version pointer is NULL, all characters have matched
+        *MAGIC_ADDR = BOOTLOADER_MAGIC;  // Set magic number into RAM
+        NVIC_SystemReset();              // Perform system reset
+        while (1) {
+        }  // Won't get here
     }
 #endif
 
     WDT->CTRLA.bit.ENABLE = 0;
-    while (WDT->SYNCBUSY.bit.ENABLE) {}
-    while (WDT->CTRLA.bit.ENABLE) {}
-    WDT->CONFIG.bit.WINDOW = 0;
-    WDT->CONFIG.bit.PER = 0;
+    while (WDT->SYNCBUSY.bit.ENABLE) {
+    }
+    while (WDT->CTRLA.bit.ENABLE) {
+    }
+    WDT->CONFIG.bit.WINDOW   = 0;
+    WDT->CONFIG.bit.PER      = 0;
     WDT->EWCTRL.bit.EWOFFSET = 0;
-    WDT->CTRLA.bit.ENABLE = 1;
-    while (WDT->SYNCBUSY.bit.ENABLE) {}
-    while (!WDT->CTRLA.bit.ENABLE) {}
-    while (1) {} //Wait on timeout
+    WDT->CTRLA.bit.ENABLE    = 1;
+    while (WDT->SYNCBUSY.bit.ENABLE) {
+    }
+    while (!WDT->CTRLA.bit.ENABLE) {
+    }
+    while (1) {
+    }  // Wait on timeout
 }
index 61cc039efaff75afc2144dbdff1ccff5a7d12664..44a0bf4d763b938d63b2b48e6bbf7cb4e2193498 100644 (file)
 static uint8_t buffer[EEPROM_SIZE];
 
 uint8_t eeprom_read_byte(const uint8_t *addr) {
-       uintptr_t offset = (uintptr_t)addr;
-       return buffer[offset];
+    uintptr_t offset = (uintptr_t)addr;
+    return buffer[offset];
 }
 
 void eeprom_write_byte(uint8_t *addr, uint8_t value) {
-       uintptr_t offset = (uintptr_t)addr;
-       buffer[offset] = value;
+    uintptr_t offset = (uintptr_t)addr;
+    buffer[offset]   = value;
 }
 
 uint16_t eeprom_read_word(const uint16_t *addr) {
-       const uint8_t *p = (const uint8_t *)addr;
-       return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8);
+    const uint8_t *p = (const uint8_t *)addr;
+    return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8);
 }
 
 uint32_t eeprom_read_dword(const uint32_t *addr) {
-       const uint8_t *p = (const uint8_t *)addr;
-       return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8)
-               | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24);
+    const uint8_t *p = (const uint8_t *)addr;
+    return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24);
 }
 
 void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
-       const uint8_t *p = (const uint8_t *)addr;
-       uint8_t *dest = (uint8_t *)buf;
-       while (len--) {
-               *dest++ = eeprom_read_byte(p++);
-       }
+    const uint8_t *p    = (const uint8_t *)addr;
+    uint8_t *      dest = (uint8_t *)buf;
+    while (len--) {
+        *dest++ = eeprom_read_byte(p++);
+    }
 }
 
 void eeprom_write_word(uint16_t *addr, uint16_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p, value >> 8);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p, value >> 8);
 }
 
 void eeprom_write_dword(uint32_t *addr, uint32_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p++, value >> 8);
-       eeprom_write_byte(p++, value >> 16);
-       eeprom_write_byte(p, value >> 24);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p++, value >> 8);
+    eeprom_write_byte(p++, value >> 16);
+    eeprom_write_byte(p, value >> 24);
 }
 
 void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
-       uint8_t *p = (uint8_t *)addr;
-       const uint8_t *src = (const uint8_t *)buf;
-       while (len--) {
-               eeprom_write_byte(p++, *src++);
-       }
+    uint8_t *      p   = (uint8_t *)addr;
+    const uint8_t *src = (const uint8_t *)buf;
+    while (len--) {
+        eeprom_write_byte(p++, *src++);
+    }
 }
 
-void eeprom_update_byte(uint8_t *addr, uint8_t value) {
-       eeprom_write_byte(addr, value);
-}
+void eeprom_update_byte(uint8_t *addr, uint8_t value) { eeprom_write_byte(addr, value); }
 
 void eeprom_update_word(uint16_t *addr, uint16_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p, value >> 8);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p, value >> 8);
 }
 
 void eeprom_update_dword(uint32_t *addr, uint32_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p++, value >> 8);
-       eeprom_write_byte(p++, value >> 16);
-       eeprom_write_byte(p, value >> 24);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p++, value >> 8);
+    eeprom_write_byte(p++, value >> 16);
+    eeprom_write_byte(p, value >> 24);
 }
 
 void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
-       uint8_t *p = (uint8_t *)addr;
-       const uint8_t *src = (const uint8_t *)buf;
-       while (len--) {
-               eeprom_write_byte(p++, *src++);
-       }
+    uint8_t *      p   = (uint8_t *)addr;
+    const uint8_t *src = (const uint8_t *)buf;
+    while (len--) {
+        eeprom_write_byte(p++, *src++);
+    }
 }
index 7f298d1fda5cff852778606a3dc3538e21f5fab6..cd7cdb52e682442231ad52a7867bf16932df6f4b 100644 (file)
@@ -17,50 +17,52 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #ifdef CONSOLE_ENABLE
 
-#include "samd51j18a.h"
-#include "arm_atsam_protocol.h"
-#include "printf.h"
-#include <string.h>
-#include <stdarg.h>
+#    include "samd51j18a.h"
+#    include "arm_atsam_protocol.h"
+#    include "printf.h"
+#    include <string.h>
+#    include <stdarg.h>
 
 void console_printf(char *fmt, ...) {
-    while (udi_hid_con_b_report_trans_ongoing) {}           //Wait for any previous transfers to complete
+    while (udi_hid_con_b_report_trans_ongoing) {
+    }  // Wait for any previous transfers to complete
 
-    static char console_printbuf[CONSOLE_PRINTBUF_SIZE];    //Print and send buffer
-    va_list va;
-    int result;
+    static char console_printbuf[CONSOLE_PRINTBUF_SIZE];  // Print and send buffer
+    va_list     va;
+    int         result;
 
     va_start(va, fmt);
     result = vsnprintf(console_printbuf, CONSOLE_PRINTBUF_SIZE, fmt, va);
     va_end(va);
 
     uint32_t irqflags;
-    char *pconbuf = console_printbuf;                       //Pointer to start send from
-    int send_out = CONSOLE_EPSIZE;                          //Bytes to send per transfer
+    char *   pconbuf  = console_printbuf;  // Pointer to start send from
+    int      send_out = CONSOLE_EPSIZE;    // Bytes to send per transfer
 
-    while (result > 0) {                                    //While not error and bytes remain
-        while (udi_hid_con_b_report_trans_ongoing) {}       //Wait for any previous transfers to complete
+    while (result > 0) {  // While not error and bytes remain
+        while (udi_hid_con_b_report_trans_ongoing) {
+        }  // Wait for any previous transfers to complete
 
         irqflags = __get_PRIMASK();
         __disable_irq();
         __DMB();
 
-        if (result < CONSOLE_EPSIZE) {                      //If remaining bytes are less than console epsize
-            memset(udi_hid_con_report, 0, CONSOLE_EPSIZE);  //Clear the buffer
-            send_out = result;                              //Send remaining size
+        if (result < CONSOLE_EPSIZE) {                      // If remaining bytes are less than console epsize
+            memset(udi_hid_con_report, 0, CONSOLE_EPSIZE);  // Clear the buffer
+            send_out = result;                              // Send remaining size
         }
 
-        memcpy(udi_hid_con_report, pconbuf, send_out);      //Copy data into the send buffer
+        memcpy(udi_hid_con_report, pconbuf, send_out);  // Copy data into the send buffer
 
-        udi_hid_con_b_report_valid = 1;                     //Set report valid
-        udi_hid_con_send_report();                          //Send report
+        udi_hid_con_b_report_valid = 1;  // Set report valid
+        udi_hid_con_send_report();       // Send report
 
         __DMB();
         __set_PRIMASK(irqflags);
 
-        result -= send_out;                                 //Decrement result by bytes sent
-        pconbuf += send_out;                                //Increment buffer point by bytes sent
+        result -= send_out;   // Decrement result by bytes sent
+        pconbuf += send_out;  // Increment buffer point by bytes sent
     }
 }
 
-#endif //CONSOLE_ENABLE
+#endif  // CONSOLE_ENABLE
index 1f1c2280b5c0304643053dd61eb816704606b0dc..ad66722205c89fca56bfe9242f2b1bd5d3522d81 100644 (file)
@@ -7,5 +7,4 @@ void console_printf(char *fmt, ...);
 
 #define __xprintf console_printf
 
-#endif //_PRINTF_H_
-
+#endif  //_PRINTF_H_
index ecf8f0ed1892cef37a1acc68846af9463a64646c..2dad005706cd1130924b07bfa48c03ee089b0735 100644 (file)
@@ -7,44 +7,35 @@
  *
  * FIXME: needs doc
  */
-void suspend_idle(uint8_t time) {
-    /* Note: Not used anywhere currently */
-}
+void suspend_idle(uint8_t time) { /* Note: Not used anywhere currently */ }
 
 /** \brief Run user level Power down
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_power_down_user (void) {
-
-}
+__attribute__((weak)) void suspend_power_down_user(void) {}
 
 /** \brief Run keyboard level Power down
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_power_down_kb(void) {
-    suspend_power_down_user();
-}
+__attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); }
 
 /** \brief Suspend power down
  *
  * FIXME: needs doc
  */
-void suspend_power_down(void)
-{
+void suspend_power_down(void) {
 #ifdef RGB_MATRIX_ENABLE
-    I2C3733_Control_Set(0); //Disable LED driver
+    I2C3733_Control_Set(0);  // Disable LED driver
 #endif
 
     suspend_power_down_kb();
 }
 
-__attribute__ ((weak)) void matrix_power_up(void) {}
-__attribute__ ((weak)) void matrix_power_down(void) {}
-bool suspend_wakeup_condition(void) {
+__attribute__((weak)) void matrix_power_up(void) {}
+__attribute__((weak)) void matrix_power_down(void) {}
+bool                       suspend_wakeup_condition(void) {
     matrix_power_up();
     matrix_scan();
     matrix_power_down();
@@ -58,19 +49,13 @@ bool suspend_wakeup_condition(void) {
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_wakeup_init_user(void) {
-
-}
+__attribute__((weak)) void suspend_wakeup_init_user(void) {}
 
 /** \brief run keyboard level code immediately after wakeup
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_wakeup_init_kb(void) {
-    suspend_wakeup_init_user();
-}
+__attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); }
 
 /** \brief run immediately after wakeup
  *
@@ -78,15 +63,14 @@ void suspend_wakeup_init_kb(void) {
  */
 void suspend_wakeup_init(void) {
 #ifdef RGB_MATRIX_ENABLE
-#ifdef USE_MASSDROP_CONFIGURATOR
+#    ifdef USE_MASSDROP_CONFIGURATOR
     if (led_enabled) {
         I2C3733_Control_Set(1);
     }
-#else
+#    else
     I2C3733_Control_Set(1);
-#endif
+#    endif
 #endif
 
     suspend_wakeup_init_kb();
 }
-
index 6c3905e3087f5e83418605e890ecfe1e8c6e5782..b835dd5e753f6c1423e056cbe2d01898e741d070 100644 (file)
@@ -2,42 +2,18 @@
 #include "timer.h"
 #include "tmk_core/protocol/arm_atsam/clks.h"
 
-void set_time(uint64_t tset)
-{
-    ms_clk = tset;
-}
-
-void timer_init(void)
-{
-    timer_clear();
-}
-
-uint16_t timer_read(void)
-{
-    return (uint16_t)ms_clk;
-}
-
-uint32_t timer_read32(void)
-{
-    return (uint32_t)ms_clk;
-}
-
-uint64_t timer_read64(void)
-{
-    return ms_clk;
-}
-
-uint16_t timer_elapsed(uint16_t tlast)
-{
-    return TIMER_DIFF_16(timer_read(), tlast);
-}
-
-uint32_t timer_elapsed32(uint32_t tlast)
-{
-    return TIMER_DIFF_32(timer_read32(), tlast);
-}
-
-void timer_clear(void)
-{
-    set_time(0);
-}
+void set_time(uint64_t tset) { ms_clk = tset; }
+
+void timer_init(void) { timer_clear(); }
+
+uint16_t timer_read(void) { return (uint16_t)ms_clk; }
+
+uint32_t timer_read32(void) { return (uint32_t)ms_clk; }
+
+uint64_t timer_read64(void) { return ms_clk; }
+
+uint16_t timer_elapsed(uint16_t tlast) { return TIMER_DIFF_16(timer_read(), tlast); }
+
+uint32_t timer_elapsed32(uint32_t tlast) { return TIMER_DIFF_32(timer_read32(), tlast); }
+
+void timer_clear(void) { set_time(0); }
index 29036f7c5a87ef518763402a2863cae47c2886e9..5f9ecc5101874b7927117966aab17979d27cb48d 100644 (file)
@@ -9,10 +9,9 @@
 #include <avr/boot.h>
 
 #ifdef PROTOCOL_LUFA
-#include <LUFA/Drivers/USB/USB.h>
+#    include <LUFA/Drivers/USB/USB.h>
 #endif
 
-
 /** \brief Bootloader Size in *bytes*
  *
  * AVR Boot section size are defined by setting BOOTSZ fuse in fact. Consult with your MCU datasheet.
 #define FLASH_SIZE (FLASHEND + 1L)
 
 #if !defined(BOOTLOADER_SIZE)
-    uint16_t bootloader_start;
+uint16_t bootloader_start;
 #endif
 
-#define BOOT_SIZE_256  0b110
-#define BOOT_SIZE_512  0b100
+#define BOOT_SIZE_256 0b110
+#define BOOT_SIZE_512 0b100
 #define BOOT_SIZE_1024 0b010
 #define BOOT_SIZE_2048 0b000
 
-//compatibility between ATMega8 and ATMega88
-#if !defined (MCUCSR)
-    #if defined (MCUSR)
-        #define MCUCSR MCUSR
-    #endif
+// compatibility between ATMega8 and ATMega88
+#if !defined(MCUCSR)
+#    if defined(MCUSR)
+#        define MCUCSR MCUSR
+#    endif
 #endif
 
 /** \brief Entering the Bootloader via Software
  * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html
  */
 #define BOOTLOADER_RESET_KEY 0xB007B007
-uint32_t reset_key  __attribute__ ((section (".noinit,\"aw\",@nobits;")));
+uint32_t reset_key __attribute__((section(".noinit,\"aw\",@nobits;")));
 
 /** \brief initialize MCU status by watchdog reset
  *
  * FIXME: needs doc
  */
 void bootloader_jump(void) {
+#if !defined(BOOTLOADER_SIZE)
+    uint8_t high_fuse = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
 
-    #if !defined(BOOTLOADER_SIZE)
-        uint8_t high_fuse = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
-
-        if (high_fuse & BOOT_SIZE_256) {
-            bootloader_start = (FLASH_SIZE - 512) >> 1;
-        } else if (high_fuse & BOOT_SIZE_512) {
-            bootloader_start = (FLASH_SIZE - 1024) >> 1;
-        } else if (high_fuse & BOOT_SIZE_1024) {
-            bootloader_start = (FLASH_SIZE - 2048) >> 1;
-        } else {
-            bootloader_start = (FLASH_SIZE - 4096) >> 1;
-        }
-    #endif
+    if (high_fuse & BOOT_SIZE_256) {
+        bootloader_start = (FLASH_SIZE - 512) >> 1;
+    } else if (high_fuse & BOOT_SIZE_512) {
+        bootloader_start = (FLASH_SIZE - 1024) >> 1;
+    } else if (high_fuse & BOOT_SIZE_1024) {
+        bootloader_start = (FLASH_SIZE - 2048) >> 1;
+    } else {
+        bootloader_start = (FLASH_SIZE - 4096) >> 1;
+    }
+#endif
 
     // Something like this might work, but it compiled larger than the block above
     // bootloader_start = FLASH_SIZE - (256 << (~high_fuse & 0b110 >> 1));
 
+#if defined(BOOTLOADER_HALFKAY)
+    //  http://www.pjrc.com/teensy/jump_to_bootloader.html
+    cli();
+    // disable watchdog, if enabled (it's not)
+    // disable all peripherals
+    // a shutdown call might make sense here
+    UDCON  = 1;
+    USBCON = (1 << FRZCLK);  // disable USB
+    UCSR1B = 0;
+    _delay_ms(5);
+#    if defined(__AVR_AT90USB162__)  // Teensy 1.0
+    EIMSK  = 0;
+    PCICR  = 0;
+    SPCR   = 0;
+    ACSR   = 0;
+    EECR   = 0;
+    TIMSK0 = 0;
+    TIMSK1 = 0;
+    UCSR1B = 0;
+    DDRB   = 0;
+    DDRC   = 0;
+    DDRD   = 0;
+    PORTB  = 0;
+    PORTC  = 0;
+    PORTD  = 0;
+    asm volatile("jmp 0x3E00");
+#    elif defined(__AVR_ATmega32U4__)   // Teensy 2.0
+    EIMSK  = 0;
+    PCICR  = 0;
+    SPCR   = 0;
+    ACSR   = 0;
+    EECR   = 0;
+    ADCSRA = 0;
+    TIMSK0 = 0;
+    TIMSK1 = 0;
+    TIMSK3 = 0;
+    TIMSK4 = 0;
+    UCSR1B = 0;
+    TWCR   = 0;
+    DDRB   = 0;
+    DDRC   = 0;
+    DDRD   = 0;
+    DDRE   = 0;
+    DDRF   = 0;
+    TWCR   = 0;
+    PORTB  = 0;
+    PORTC  = 0;
+    PORTD  = 0;
+    PORTE  = 0;
+    PORTF  = 0;
+    asm volatile("jmp 0x7E00");
+#    elif defined(__AVR_AT90USB646__)   // Teensy++ 1.0
+    EIMSK  = 0;
+    PCICR  = 0;
+    SPCR   = 0;
+    ACSR   = 0;
+    EECR   = 0;
+    ADCSRA = 0;
+    TIMSK0 = 0;
+    TIMSK1 = 0;
+    TIMSK2 = 0;
+    TIMSK3 = 0;
+    UCSR1B = 0;
+    TWCR   = 0;
+    DDRA   = 0;
+    DDRB   = 0;
+    DDRC   = 0;
+    DDRD   = 0;
+    DDRE   = 0;
+    DDRF   = 0;
+    PORTA  = 0;
+    PORTB  = 0;
+    PORTC  = 0;
+    PORTD  = 0;
+    PORTE  = 0;
+    PORTF  = 0;
+    asm volatile("jmp 0xFC00");
+#    elif defined(__AVR_AT90USB1286__)  // Teensy++ 2.0
+    EIMSK  = 0;
+    PCICR  = 0;
+    SPCR   = 0;
+    ACSR   = 0;
+    EECR   = 0;
+    ADCSRA = 0;
+    TIMSK0 = 0;
+    TIMSK1 = 0;
+    TIMSK2 = 0;
+    TIMSK3 = 0;
+    UCSR1B = 0;
+    TWCR   = 0;
+    DDRA   = 0;
+    DDRB   = 0;
+    DDRC   = 0;
+    DDRD   = 0;
+    DDRE   = 0;
+    DDRF   = 0;
+    PORTA  = 0;
+    PORTB  = 0;
+    PORTC  = 0;
+    PORTD  = 0;
+    PORTE  = 0;
+    PORTF  = 0;
+    asm volatile("jmp 0x1FC00");
+#    endif
+
+#elif defined(BOOTLOADER_CATERINA)
+    // this block may be optional
+    // TODO: figure it out
+
+    uint16_t *const bootKeyPtr = (uint16_t *)0x0800;
+
+    // Value used by Caterina bootloader use to determine whether to run the
+    // sketch or the bootloader programmer.
+    uint16_t bootKey = 0x7777;
+
+    *bootKeyPtr = bootKey;
+
+    // setup watchdog timeout
+    wdt_enable(WDTO_60MS);
 
-    #if defined(BOOTLOADER_HALFKAY)
-        //  http://www.pjrc.com/teensy/jump_to_bootloader.html
-        cli();
-        // disable watchdog, if enabled (it's not)
-        // disable all peripherals
-        // a shutdown call might make sense here
-        UDCON = 1;
-        USBCON = (1<<FRZCLK);  // disable USB
-        UCSR1B = 0;
-        _delay_ms(5);
-        #if defined(__AVR_AT90USB162__)                // Teensy 1.0
-            EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0;
-            TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0;
-            DDRB = 0; DDRC = 0; DDRD = 0;
-            PORTB = 0; PORTC = 0; PORTD = 0;
-            asm volatile("jmp 0x3E00");
-        #elif defined(__AVR_ATmega32U4__)              // Teensy 2.0
-            EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
-            TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0;
-            DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0;
-            PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
-            asm volatile("jmp 0x7E00");
-        #elif defined(__AVR_AT90USB646__)              // Teensy++ 1.0
-            EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
-            TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
-            DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
-            PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
-            asm volatile("jmp 0xFC00");
-        #elif defined(__AVR_AT90USB1286__)             // Teensy++ 2.0
-            EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
-            TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
-            DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
-            PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
-            asm volatile("jmp 0x1FC00");
-        #endif
-
-    #elif defined(BOOTLOADER_CATERINA)
-        // this block may be optional
-        // TODO: figure it out
-
-        uint16_t *const bootKeyPtr = (uint16_t *)0x0800;
-
-        // Value used by Caterina bootloader use to determine whether to run the
-        // sketch or the bootloader programmer.
-        uint16_t bootKey = 0x7777;
-
-        *bootKeyPtr = bootKey;
-
-        // setup watchdog timeout
-        wdt_enable(WDTO_60MS);
-
-        while(1) {} // wait for watchdog timer to trigger
-
-    #elif defined(BOOTLOADER_USBASP)
-        // Taken with permission of Stephan Baerwolf from https://github.com/tinyusbboard/API/blob/master/apipage.c
-        wdt_enable(WDTO_15MS);
-        wdt_reset();
-        asm volatile (
-            "cli                    \n\t"
-            "ldi    r29 ,       %[ramendhi] \n\t"
-            "ldi    r28 ,       %[ramendlo] \n\t"
-            #if (FLASHEND>131071)
-                "ldi    r18 ,       %[bootaddrhi]   \n\t"
-                "st     Y+,         r18     \n\t"
-            #endif
-            "ldi    r18 ,       %[bootaddrme]   \n\t"
-            "st     Y+,     r18     \n\t"
-            "ldi    r18 ,       %[bootaddrlo]   \n\t"
-            "st     Y+,     r18     \n\t"
-            "out    %[mcucsrio],    __zero_reg__    \n\t"
-            "bootloader_startup_loop%=:         \n\t"
-            "rjmp bootloader_startup_loop%=     \n\t"
-            : 
-            : [mcucsrio]    "I" (_SFR_IO_ADDR(MCUCSR)),
-            #if (FLASHEND>131071)
-                [ramendhi]    "M" (((RAMEND - 2) >> 8) & 0xff),
-                [ramendlo]    "M" (((RAMEND - 2) >> 0) & 0xff),
-                [bootaddrhi]  "M" ((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >>16) & 0xff),
-            #else
-                [ramendhi]    "M" (((RAMEND - 1) >> 8) & 0xff),
-                [ramendlo]    "M" (((RAMEND - 1) >> 0) & 0xff),
-            #endif
-            [bootaddrme]  "M" ((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 8) & 0xff),
-            [bootaddrlo]  "M" ((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 0) & 0xff)
-        );
-
-    #else // Assume remaining boards are DFU, even if the flag isn't set
-
-        #if !(defined(__AVR_ATmega32A__) || defined(__AVR_ATmega328P__)) // no USB - maybe BOOTLOADER_BOOTLOADHID instead though?
-            UDCON = 1;
-            USBCON = (1<<FRZCLK);  // disable USB
-            UCSR1B = 0;
-            _delay_ms(5); // 5 seems to work fine
-        #endif
-
-        #ifdef BOOTLOADER_BOOTLOADHID
-            // force bootloadHID to stay in bootloader mode, so that it waits
-            // for a new firmware to be flashed
-            eeprom_write_byte((uint8_t *)1, 0x00);
-        #endif
-
-        // watchdog reset
-        reset_key = BOOTLOADER_RESET_KEY;
-        wdt_enable(WDTO_250MS);
-        for (;;);
-    #endif
+    while (1) {
+    }  // wait for watchdog timer to trigger
 
+#elif defined(BOOTLOADER_USBASP)
+    // Taken with permission of Stephan Baerwolf from https://github.com/tinyusbboard/API/blob/master/apipage.c
+    wdt_enable(WDTO_15MS);
+    wdt_reset();
+    asm volatile("cli                    \n\t"
+                 "ldi    r29 ,       %[ramendhi] \n\t"
+                 "ldi    r28 ,       %[ramendlo] \n\t"
+#    if (FLASHEND > 131071)
+                 "ldi    r18 ,       %[bootaddrhi]   \n\t"
+                 "st     Y+,         r18     \n\t"
+#    endif
+                 "ldi    r18 ,       %[bootaddrme]   \n\t"
+                 "st     Y+,     r18     \n\t"
+                 "ldi    r18 ,       %[bootaddrlo]   \n\t"
+                 "st     Y+,     r18     \n\t"
+                 "out    %[mcucsrio],    __zero_reg__    \n\t"
+                 "bootloader_startup_loop%=:         \n\t"
+                 "rjmp bootloader_startup_loop%=     \n\t"
+                 :
+                 : [ mcucsrio ] "I"(_SFR_IO_ADDR(MCUCSR)),
+#    if (FLASHEND > 131071)
+                   [ ramendhi ] "M"(((RAMEND - 2) >> 8) & 0xff), [ ramendlo ] "M"(((RAMEND - 2) >> 0) & 0xff), [ bootaddrhi ] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 16) & 0xff),
+#    else
+                   [ ramendhi ] "M"(((RAMEND - 1) >> 8) & 0xff), [ ramendlo ] "M"(((RAMEND - 1) >> 0) & 0xff),
+#    endif
+                   [ bootaddrme ] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 8) & 0xff), [ bootaddrlo ] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 0) & 0xff));
+
+#else  // Assume remaining boards are DFU, even if the flag isn't set
+
+#    if !(defined(__AVR_ATmega32A__) || defined(__AVR_ATmega328P__))  // no USB - maybe BOOTLOADER_BOOTLOADHID instead though?
+    UDCON  = 1;
+    USBCON = (1 << FRZCLK);  // disable USB
+    UCSR1B = 0;
+    _delay_ms(5);  // 5 seems to work fine
+#    endif
+
+#    ifdef BOOTLOADER_BOOTLOADHID
+    // force bootloadHID to stay in bootloader mode, so that it waits
+    // for a new firmware to be flashed
+    eeprom_write_byte((uint8_t *)1, 0x00);
+#    endif
+
+    // watchdog reset
+    reset_key = BOOTLOADER_RESET_KEY;
+    wdt_enable(WDTO_250MS);
+    for (;;)
+        ;
+#endif
 }
 
 /* this runs before main() */
-void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3")));
-void bootloader_jump_after_watchdog_reset(void)
-{
-    #ifndef BOOTLOADER_HALFKAY
-        if ((MCUCSR & (1<<WDRF)) && reset_key == BOOTLOADER_RESET_KEY) {
-            reset_key = 0;
-
-            // My custom USBasploader requires this to come up.
-            MCUCSR = 0;
-
-            // Seems like Teensy halfkay loader requires clearing WDRF and disabling watchdog.
-            MCUCSR &= ~(1<<WDRF);
-            wdt_disable();
-
-
-            // This is compled into 'icall', address should be in word unit, not byte.
-            #ifdef BOOTLOADER_SIZE
-                ((void (*)(void))( (FLASH_SIZE - BOOTLOADER_SIZE) >> 1))();
-            #else
-                asm("ijmp" :: "z" (bootloader_start));
-            #endif
-        }
-    #endif
+void bootloader_jump_after_watchdog_reset(void) __attribute__((used, naked, section(".init3")));
+void bootloader_jump_after_watchdog_reset(void) {
+#ifndef BOOTLOADER_HALFKAY
+    if ((MCUCSR & (1 << WDRF)) && reset_key == BOOTLOADER_RESET_KEY) {
+        reset_key = 0;
+
+        // My custom USBasploader requires this to come up.
+        MCUCSR = 0;
+
+        // Seems like Teensy halfkay loader requires clearing WDRF and disabling watchdog.
+        MCUCSR &= ~(1 << WDRF);
+        wdt_disable();
+
+// This is compled into 'icall', address should be in word unit, not byte.
+#    ifdef BOOTLOADER_SIZE
+        ((void (*)(void))((FLASH_SIZE - BOOTLOADER_SIZE) >> 1))();
+#    else
+        asm("ijmp" ::"z"(bootloader_start));
+#    endif
+    }
+#endif
 }
index 0cb774c81f53d0211b32ec64b85aea11e52b26f5..61fa70dc3eceda59c5758b6e2226cc1d39c4c737 100644 (file)
  * 256*64           interrupts/second
  * F_CPU/(256*64)   clocks/interrupt
  */
-#define SLEEP_LED_TIMER_TOP F_CPU/(256*64)
+#define SLEEP_LED_TIMER_TOP F_CPU / (256 * 64)
 
 /** \brief Sleep LED initialization
  *
  * FIXME: needs doc
  */
-void sleep_led_init(void)
-{
+void sleep_led_init(void) {
     /* Timer1 setup */
     /* CTC mode */
     TCCR1B |= _BV(WGM12);
@@ -32,17 +31,16 @@ void sleep_led_init(void)
     /* Set TOP value */
     uint8_t sreg = SREG;
     cli();
-    OCR1AH = (SLEEP_LED_TIMER_TOP>>8)&0xff;
-    OCR1AL = SLEEP_LED_TIMER_TOP&0xff;
-    SREG = sreg;
+    OCR1AH = (SLEEP_LED_TIMER_TOP >> 8) & 0xff;
+    OCR1AL = SLEEP_LED_TIMER_TOP & 0xff;
+    SREG   = sreg;
 }
 
 /** \brief Sleep LED enable
  *
  * FIXME: needs doc
  */
-void sleep_led_enable(void)
-{
+void sleep_led_enable(void) {
     /* Enable Compare Match Interrupt */
     TIMSK1 |= _BV(OCIE1A);
 }
@@ -51,8 +49,7 @@ void sleep_led_enable(void)
  *
  * FIXME: needs doc
  */
-void sleep_led_disable(void)
-{
+void sleep_led_disable(void) {
     /* Disable Compare Match Interrupt */
     TIMSK1 &= ~_BV(OCIE1A);
 }
@@ -61,13 +58,11 @@ void sleep_led_disable(void)
  *
  * FIXME: needs doc
  */
-void sleep_led_toggle(void)
-{
+void sleep_led_toggle(void) {
     /* Disable Compare Match Interrupt */
     TIMSK1 ^= _BV(OCIE1A);
 }
 
-
 /** \brief Breathing Sleep LED brighness(PWM On period) table
  *
  * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
@@ -75,15 +70,9 @@ void sleep_led_toggle(void)
  * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
  * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
  */
-static const uint8_t breathing_table[64] PROGMEM = {
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
-15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
-255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
-15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
+static const uint8_t breathing_table[64] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-ISR(TIMER1_COMPA_vect)
-{
+ISR(TIMER1_COMPA_vect) {
     /* Software PWM
      * timer:1111 1111 1111 1111
      *       \_____/\/ \_______/____  count(0-255)
@@ -93,17 +82,17 @@ ISR(TIMER1_COMPA_vect)
     static union {
         uint16_t row;
         struct {
-            uint8_t count:8;
-            uint8_t duration:2;
-            uint8_t index:6;
+            uint8_t count : 8;
+            uint8_t duration : 2;
+            uint8_t index : 6;
         } pwm;
-    } timer = { .row = 0 };
+    } timer = {.row = 0};
 
     timer.row++;
-    
+
     // LED on
     if (timer.pwm.count == 0) {
-        led_set(1<<USB_LED_CAPS_LOCK);
+        led_set(1 << USB_LED_CAPS_LOCK);
     }
     // LED off
     if (timer.pwm.count == pgm_read_byte(&breathing_table[timer.pwm.index])) {
index 2259201b5d99cf37c6b9bf7630c731b3606cd40c..574000fcd8f954b4efe562f4bae31a82849a412e 100644 (file)
 #include "rgblight_reconfig.h"
 
 #ifdef PROTOCOL_LUFA
-       #include "lufa.h"
+#    include "lufa.h"
 #endif
 
 #ifdef AUDIO_ENABLE
-    #include "audio.h"
+#    include "audio.h"
 #endif /* AUDIO_ENABLE */
 
 #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
-  #include "rgblight.h"
-  extern rgblight_config_t rgblight_config;
-  static bool rgblight_enabled;
-  static bool is_suspended;
+#    include "rgblight.h"
+extern rgblight_config_t rgblight_config;
+static bool              rgblight_enabled;
+static bool              is_suspended;
 #endif
 
-
-#define wdt_intr_enable(value)   \
-__asm__ __volatile__ (  \
-    "in __tmp_reg__,__SREG__" "\n\t"    \
-    "cli" "\n\t"    \
-    "wdr" "\n\t"    \
-    "sts %0,%1" "\n\t"  \
-    "out __SREG__,__tmp_reg__" "\n\t"   \
-    "sts %0,%2" "\n\t" \
-    : /* no outputs */  \
-    : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
-    "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
-    "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
-        _BV(WDIE) | (value & 0x07)) ) \
-    : "r0"  \
-)
-
+#define wdt_intr_enable(value)                                                                                                                                                         \
+    __asm__ __volatile__("in __tmp_reg__,__SREG__"                                                                                                                                     \
+                         "\n\t"                                                                                                                                                        \
+                         "cli"                                                                                                                                                         \
+                         "\n\t"                                                                                                                                                        \
+                         "wdr"                                                                                                                                                         \
+                         "\n\t"                                                                                                                                                        \
+                         "sts %0,%1"                                                                                                                                                   \
+                         "\n\t"                                                                                                                                                        \
+                         "out __SREG__,__tmp_reg__"                                                                                                                                    \
+                         "\n\t"                                                                                                                                                        \
+                         "sts %0,%2"                                                                                                                                                   \
+                         "\n\t"                                                                                                                                                        \
+                         : /* no outputs */                                                                                                                                            \
+                         : "M"(_SFR_MEM_ADDR(_WD_CONTROL_REG)), "r"(_BV(_WD_CHANGE_BIT) | _BV(WDE)), "r"((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00) | _BV(WDIE) | (value & 0x07))) \
+                         : "r0")
 
 /** \brief Suspend idle
  *
@@ -58,23 +57,18 @@ void suspend_idle(uint8_t time) {
     sleep_disable();
 }
 
-
 // TODO: This needs some cleanup
 
 /** \brief Run keyboard level Power down
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_power_down_user (void) { }
+__attribute__((weak)) void suspend_power_down_user(void) {}
 /** \brief Run keyboard level Power down
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_power_down_kb(void) {
-  suspend_power_down_user();
-}
+__attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); }
 
 #ifndef NO_SUSPEND_POWER_DOWN
 /** \brief Power down MCU with watchdog timer
@@ -98,43 +92,43 @@ static uint8_t wdt_timeout = 0;
  * FIXME: needs doc
  */
 static void power_down(uint8_t wdto) {
-#ifdef PROTOCOL_LUFA
-  if (USB_DeviceState == DEVICE_STATE_Configured) return;
-#endif
-  wdt_timeout = wdto;
-
-  // Watchdog Interrupt Mode
-  wdt_intr_enable(wdto);
-
-#ifdef BACKLIGHT_ENABLE
-  backlight_set(0);
-#endif
-
-  // Turn off LED indicators
-  uint8_t leds_off = 0;
-#if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
-  if (is_backlight_enabled()) {
-    // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
-    leds_off |= (1<<USB_LED_CAPS_LOCK);
-  }
-#endif
-  led_set(leds_off);
-
-#ifdef AUDIO_ENABLE
-  // This sometimes disables the start-up noise, so it's been disabled
-  // stop_all_notes();
-#endif /* AUDIO_ENABLE */
-#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
-#ifdef RGBLIGHT_ANIMATIONS
-  rgblight_timer_disable();
-#endif
-  if (!is_suspended) {
-    is_suspended = true;
-    rgblight_enabled = rgblight_config.enable;
-    rgblight_disable_noeeprom();
-  }
-#endif
-  suspend_power_down_kb();
+#    ifdef PROTOCOL_LUFA
+    if (USB_DeviceState == DEVICE_STATE_Configured) return;
+#    endif
+    wdt_timeout = wdto;
+
+    // Watchdog Interrupt Mode
+    wdt_intr_enable(wdto);
+
+#    ifdef BACKLIGHT_ENABLE
+    backlight_set(0);
+#    endif
+
+    // Turn off LED indicators
+    uint8_t leds_off = 0;
+#    if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
+    if (is_backlight_enabled()) {
+        // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
+        leds_off |= (1 << USB_LED_CAPS_LOCK);
+    }
+#    endif
+    led_set(leds_off);
+
+#    ifdef AUDIO_ENABLE
+    // This sometimes disables the start-up noise, so it's been disabled
+    // stop_all_notes();
+#    endif /* AUDIO_ENABLE */
+#    if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
+#        ifdef RGBLIGHT_ANIMATIONS
+    rgblight_timer_disable();
+#        endif
+    if (!is_suspended) {
+        is_suspended     = true;
+        rgblight_enabled = rgblight_config.enable;
+        rgblight_disable_noeeprom();
+    }
+#    endif
+    suspend_power_down_kb();
 
     // TODO: more power saving
     // See PicoPower application note
@@ -158,40 +152,36 @@ static void power_down(uint8_t wdto) {
  * FIXME: needs doc
  */
 void suspend_power_down(void) {
-       suspend_power_down_kb();
+    suspend_power_down_kb();
 
 #ifndef NO_SUSPEND_POWER_DOWN
     power_down(WDTO_15MS);
 #endif
 }
 
-__attribute__ ((weak)) void matrix_power_up(void) {}
-__attribute__ ((weak)) void matrix_power_down(void) {}
-bool suspend_wakeup_condition(void) {
+__attribute__((weak)) void matrix_power_up(void) {}
+__attribute__((weak)) void matrix_power_down(void) {}
+bool                       suspend_wakeup_condition(void) {
     matrix_power_up();
     matrix_scan();
     matrix_power_down();
     for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
         if (matrix_get_row(r)) return true;
     }
-     return false;
+    return false;
 }
 
 /** \brief run user level code immediately after wakeup
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_wakeup_init_user(void) { }
+__attribute__((weak)) void suspend_wakeup_init_user(void) {}
 
 /** \brief run keyboard level code immediately after wakeup
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_wakeup_init_kb(void) {
-  suspend_wakeup_init_user();
-}
+__attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); }
 /** \brief run immediately after wakeup
  *
  * FIXME: needs doc
@@ -202,18 +192,18 @@ void suspend_wakeup_init(void) {
 #ifdef BACKLIGHT_ENABLE
     backlight_init();
 #endif
-       led_set(host_keyboard_leds());
+    led_set(host_keyboard_leds());
 #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
-  is_suspended = false;
-  if (rgblight_enabled) {
-    #ifdef BOOTLOADER_TEENSY
-      wait_ms(10);
-    #endif
-    rgblight_enable_noeeprom();
-  }
-#ifdef RGBLIGHT_ANIMATIONS
-  rgblight_timer_enable();
-#endif
+    is_suspended = false;
+    if (rgblight_enabled) {
+#    ifdef BOOTLOADER_TEENSY
+        wait_ms(10);
+#    endif
+        rgblight_enable_noeeprom();
+    }
+#    ifdef RGBLIGHT_ANIMATIONS
+    rgblight_timer_enable();
+#    endif
 #endif
     suspend_wakeup_init_kb();
 }
@@ -226,8 +216,7 @@ ISR(WDT_vect) {
         case WDTO_15MS:
             timer_count += 15 + 2;  // WDTO_15MS + 2(from observation)
             break;
-        default:
-            ;
+        default:;
     }
 }
 #endif
index 357102da44d4d2112cc487f0374105d2f00f4d5d..d73852ba11c2589de1bb02b6b68045f2255b0ca9 100644 (file)
@@ -7,21 +7,21 @@
 #include <avr/wdt.h>
 #include <avr/interrupt.h>
 
-
-#define wdt_intr_enable(value)   \
-__asm__ __volatile__ (  \
-    "in __tmp_reg__,__SREG__" "\n\t"    \
-    "cli" "\n\t"    \
-    "wdr" "\n\t"    \
-    "sts %0,%1" "\n\t"  \
-    "out __SREG__,__tmp_reg__" "\n\t"   \
-    "sts %0,%2" "\n\t" \
-    : /* no outputs */  \
-    : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
-    "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
-    "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
-        _BV(WDIE) | (value & 0x07)) ) \
-    : "r0"  \
-)
+#define wdt_intr_enable(value)                                                                                                                                                         \
+    __asm__ __volatile__("in __tmp_reg__,__SREG__"                                                                                                                                     \
+                         "\n\t"                                                                                                                                                        \
+                         "cli"                                                                                                                                                         \
+                         "\n\t"                                                                                                                                                        \
+                         "wdr"                                                                                                                                                         \
+                         "\n\t"                                                                                                                                                        \
+                         "sts %0,%1"                                                                                                                                                   \
+                         "\n\t"                                                                                                                                                        \
+                         "out __SREG__,__tmp_reg__"                                                                                                                                    \
+                         "\n\t"                                                                                                                                                        \
+                         "sts %0,%2"                                                                                                                                                   \
+                         "\n\t"                                                                                                                                                        \
+                         : /* no outputs */                                                                                                                                            \
+                         : "M"(_SFR_MEM_ADDR(_WD_CONTROL_REG)), "r"(_BV(_WD_CHANGE_BIT) | _BV(WDE)), "r"((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00) | _BV(WDIE) | (value & 0x07))) \
+                         : "r0")
 
 #endif
index b7d4f060ef0993a01d2cd9d2ea84bb17ed8b0019..63ec549dff1c3f7e9b792c7df2fe5ec35e4e4d4d 100644 (file)
@@ -22,7 +22,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "timer_avr.h"
 #include "timer.h"
 
-
 // counter resolution 1ms
 // NOTE: union { uint32_t timer32; struct { uint16_t dummy; uint16_t timer16; }}
 volatile uint32_t timer_count;
@@ -31,8 +30,7 @@ volatile uint32_t timer_count;
  *
  * FIXME: needs doc
  */
-void timer_init(void)
-{
+void timer_init(void) {
 #if TIMER_PRESCALER == 1
     uint8_t prescaler = 0x01;
 #elif TIMER_PRESCALER == 8
@@ -44,7 +42,7 @@ void timer_init(void)
 #elif TIMER_PRESCALER == 1024
     uint8_t prescaler = 0x05;
 #else
-#   error "Timer prescaler value is NOT vaild."
+#    error "Timer prescaler value is NOT vaild."
 #endif
 
 #ifndef __AVR_ATmega32A__
@@ -53,13 +51,13 @@ void timer_init(void)
 
     TCCR0B = prescaler;
 
-    OCR0A = TIMER_RAW_TOP;
-    TIMSK0 = (1<<OCIE0A);
+    OCR0A  = TIMER_RAW_TOP;
+    TIMSK0 = (1 << OCIE0A);
 #else
     // Timer0 CTC mode
     TCCR0 = (1 << WGM01) | prescaler;
 
-    OCR0 = TIMER_RAW_TOP;
+    OCR0  = TIMER_RAW_TOP;
     TIMSK = (1 << OCIE0);
 #endif
 }
@@ -68,26 +66,18 @@ void timer_init(void)
  *
  * FIXME: needs doc
  */
-inline
-void timer_clear(void)
-{
-  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
-    timer_count = 0;
-  }
+inline void timer_clear(void) {
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { timer_count = 0; }
 }
 
 /** \brief timer read
  *
  * FIXME: needs doc
  */
-inline
-uint16_t timer_read(void)
-{
+inline uint16_t timer_read(void) {
     uint32_t t;
 
-    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
-      t = timer_count;
-    }
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; }
 
     return (t & 0xFFFF);
 }
@@ -96,14 +86,10 @@ uint16_t timer_read(void)
  *
  * FIXME: needs doc
  */
-inline
-uint32_t timer_read32(void)
-{
+inline uint32_t timer_read32(void) {
     uint32_t t;
 
-    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
-      t = timer_count;
-    }
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; }
 
     return t;
 }
@@ -112,14 +98,10 @@ uint32_t timer_read32(void)
  *
  * FIXME: needs doc
  */
-inline
-uint16_t timer_elapsed(uint16_t last)
-{
+inline uint16_t timer_elapsed(uint16_t last) {
     uint32_t t;
 
-    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
-      t = timer_count;
-    }
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; }
 
     return TIMER_DIFF_16((t & 0xFFFF), last);
 }
@@ -128,25 +110,18 @@ uint16_t timer_elapsed(uint16_t last)
  *
  * FIXME: needs doc
  */
-inline
-uint32_t timer_elapsed32(uint32_t last)
-{
+inline uint32_t timer_elapsed32(uint32_t last) {
     uint32_t t;
 
-    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
-      t = timer_count;
-    }
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t = timer_count; }
 
     return TIMER_DIFF_32(t, last);
 }
 
 // excecuted once per 1ms.(excess for just timer count?)
 #ifndef __AVR_ATmega32A__
-#define TIMER_INTERRUPT_VECTOR TIMER0_COMPA_vect
+#    define TIMER_INTERRUPT_VECTOR TIMER0_COMPA_vect
 #else
-#define TIMER_INTERRUPT_VECTOR TIMER0_COMP_vect
+#    define TIMER_INTERRUPT_VECTOR TIMER0_COMP_vect
 #endif
-ISR(TIMER_INTERRUPT_VECTOR, ISR_NOBLOCK)
-{
-    timer_count++;
-}
+ISR(TIMER_INTERRUPT_VECTOR, ISR_NOBLOCK) { timer_count++; }
index 0e85eb1017aacc3b3f679d4cb04e58f2a7522eb7..9aea21c6511570d539b815a6acfa5e25645dd712 100644 (file)
@@ -21,22 +21,22 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdint.h>
 
 #ifndef TIMER_PRESCALER
-#   if F_CPU > 16000000
-#       define TIMER_PRESCALER      256
-#   elif F_CPU > 2000000
-#       define TIMER_PRESCALER      64
-#   elif F_CPU > 250000
-#       define TIMER_PRESCALER      8
-#   else
-#       define TIMER_PRESCALER      1
-#   endif
+#    if F_CPU > 16000000
+#        define TIMER_PRESCALER 256
+#    elif F_CPU > 2000000
+#        define TIMER_PRESCALER 64
+#    elif F_CPU > 250000
+#        define TIMER_PRESCALER 8
+#    else
+#        define TIMER_PRESCALER 1
+#    endif
 #endif
-#define TIMER_RAW_FREQ      (F_CPU/TIMER_PRESCALER)
-#define TIMER_RAW           TCNT0
-#define TIMER_RAW_TOP       (TIMER_RAW_FREQ/1000)
+#define TIMER_RAW_FREQ (F_CPU / TIMER_PRESCALER)
+#define TIMER_RAW TCNT0
+#define TIMER_RAW_TOP (TIMER_RAW_FREQ / 1000)
 
 #if (TIMER_RAW_TOP > 255)
-#   error "Timer0 can't count 1ms at this clock freq. Use larger prescaler."
+#    error "Timer0 can't count 1ms at this clock freq. Use larger prescaler."
 #endif
 
 #endif
index 08d9f93a0c1cc9a1c671ea456d3e9dd7bf6b1ac1..70e0f8e48af01a88c03fea50bfde4ea7a8762051 100644 (file)
@@ -13,7 +13,7 @@ extern "C" {
 #endif
 
 extern void (*xfunc_out)(uint8_t);
-#define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func)
+#define xdev_out(func) xfunc_out = (void (*)(uint8_t))(func)
 
 /* This is a pointer to user defined output function. It must be initialized
    before using this modle.
@@ -25,13 +25,11 @@ void xputc(char chr);
    All outputs from this module are output via this function.
 */
 
-
 /*-----------------------------------------------------------------------------*/
 void xputs(const char *string_p);
 
 /*  The string placed in the ROM is forwarded to xputc() directly.
-*/
-
+ */
 
 /*-----------------------------------------------------------------------------*/
 void xitoa(long value, char radix, char width);
@@ -49,13 +47,12 @@ void xitoa(long value, char radix, char width);
        0x55      2     -8   "01010101"
 */
 
-
 /*-----------------------------------------------------------------------------*/
-#define xprintf(format, ...)            __xprintf(PSTR(format), ##__VA_ARGS__)
-#define xsprintf(str, format, ...)      __xsprintf(str, PSTR(format), ##__VA_ARGS__)
-#define xfprintf(func, format, ...)     __xfprintf(func, PSTR(format), ##__VA_ARGS__)
+#define xprintf(format, ...) __xprintf(PSTR(format), ##__VA_ARGS__)
+#define xsprintf(str, format, ...) __xsprintf(str, PSTR(format), ##__VA_ARGS__)
+#define xfprintf(func, format, ...) __xfprintf(func, PSTR(format), ##__VA_ARGS__)
 
-void __xprintf(const char *format_p, ...);     /* Send formatted string to the registered device */
+void __xprintf(const char *format_p, ...); /* Send formatted string to the registered device */
 // void __xsprintf(char*, const char *format_p, ...);  /* Put formatted string to the memory */
 // void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */
 
@@ -84,7 +81,6 @@ void __xprintf(const char *format_p, ...);    /* Send formatted string to the regis
 
 */
 
-
 /*-----------------------------------------------------------------------------*/
 char xatoi(char **str, long *ret);
 
@@ -108,4 +104,3 @@ char xatoi(char **str, long *ret);
 #endif
 
 #endif
-
index c0e9fb5ee48994ad4dc3927d4fd1b4278bf02222..708022f68f66cbccfddee2832245328d1475e3e4 100644 (file)
@@ -25,15 +25,14 @@ backlight_config_t backlight_config;
  *
  * FIXME: needs doc
  */
-void backlight_init(void)
-{
+void backlight_init(void) {
     /* check signature */
     if (!eeconfig_is_enabled()) {
         eeconfig_init();
     }
     backlight_config.raw = eeconfig_read_backlight();
     if (backlight_config.level > BACKLIGHT_LEVELS) {
-       backlight_config.level = BACKLIGHT_LEVELS;
+        backlight_config.level = BACKLIGHT_LEVELS;
     }
     backlight_set(backlight_config.enable ? backlight_config.level : 0);
 }
@@ -42,10 +41,8 @@ void backlight_init(void)
  *
  * FIXME: needs doc
  */
-void backlight_increase(void)
-{
-    if(backlight_config.level < BACKLIGHT_LEVELS)
-    {
+void backlight_increase(void) {
+    if (backlight_config.level < BACKLIGHT_LEVELS) {
         backlight_config.level++;
     }
     backlight_config.enable = 1;
@@ -58,10 +55,8 @@ void backlight_increase(void)
  *
  * FIXME: needs doc
  */
-void backlight_decrease(void)
-{
-    if(backlight_config.level > 0)
-    {
+void backlight_decrease(void) {
+    if (backlight_config.level > 0) {
         backlight_config.level--;
         backlight_config.enable = !!backlight_config.level;
         eeconfig_update_backlight(backlight_config.raw);
@@ -74,64 +69,56 @@ void backlight_decrease(void)
  *
  * FIXME: needs doc
  */
-void backlight_toggle(void)
-{
-       bool enabled = backlight_config.enable;
-       dprintf("backlight toggle: %u\n", enabled);
-       if (enabled) 
-               backlight_disable();
-       else
-               backlight_enable();
+void backlight_toggle(void) {
+    bool enabled = backlight_config.enable;
+    dprintf("backlight toggle: %u\n", enabled);
+    if (enabled)
+        backlight_disable();
+    else
+        backlight_enable();
 }
 
 /** \brief Enable backlight
  *
  * FIXME: needs doc
  */
-void backlight_enable(void)
-{
-       if (backlight_config.enable) return; // do nothing if backlight is already on
-
-       backlight_config.enable = true;
-       if (backlight_config.raw == 1) // enabled but level == 0
-               backlight_config.level = 1;
-       eeconfig_update_backlight(backlight_config.raw);
-       dprintf("backlight enable\n");
-       backlight_set(backlight_config.level);
+void backlight_enable(void) {
+    if (backlight_config.enable) return;  // do nothing if backlight is already on
+
+    backlight_config.enable = true;
+    if (backlight_config.raw == 1)  // enabled but level == 0
+        backlight_config.level = 1;
+    eeconfig_update_backlight(backlight_config.raw);
+    dprintf("backlight enable\n");
+    backlight_set(backlight_config.level);
 }
 
 /** \brief Disable backlight
  *
  * FIXME: needs doc
  */
-void backlight_disable(void)
-{
-       if (!backlight_config.enable) return; // do nothing if backlight is already off
-
-       backlight_config.enable = false;
-       eeconfig_update_backlight(backlight_config.raw);
-       dprintf("backlight disable\n");
-       backlight_set(0);
+void backlight_disable(void) {
+    if (!backlight_config.enable) return;  // do nothing if backlight is already off
+
+    backlight_config.enable = false;
+    eeconfig_update_backlight(backlight_config.raw);
+    dprintf("backlight disable\n");
+    backlight_set(0);
 }
 
 /** /brief Get the backlight status
  *
  * FIXME: needs doc
  */
-bool is_backlight_enabled(void)
-{
-       return backlight_config.enable;
-}
+bool is_backlight_enabled(void) { return backlight_config.enable; }
 
 /** \brief Backlight step through levels
  *
  * FIXME: needs doc
  */
-void backlight_step(void)
-{
+void backlight_step(void) {
     backlight_config.level++;
-    if(backlight_config.level > BACKLIGHT_LEVELS)
-    {
+    if (backlight_config.level > BACKLIGHT_LEVELS) {
         backlight_config.level = 0;
     }
     backlight_config.enable = !!backlight_config.level;
@@ -144,11 +131,9 @@ void backlight_step(void)
  *
  * FIXME: needs doc
  */
-void backlight_level(uint8_t level)
-{
-    if (level > BACKLIGHT_LEVELS)
-        level = BACKLIGHT_LEVELS;
-    backlight_config.level = level;
+void backlight_level(uint8_t level) {
+    if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS;
+    backlight_config.level  = level;
     backlight_config.enable = !!backlight_config.level;
     eeconfig_update_backlight(backlight_config.raw);
     backlight_set(backlight_config.level);
@@ -158,21 +143,17 @@ void backlight_level(uint8_t level)
  *
  * FIXME: needs doc
  */
-uint8_t get_backlight_level(void)
-{
-    return backlight_config.level;
-}
+uint8_t get_backlight_level(void) { return backlight_config.level; }
 
 #ifdef BACKLIGHT_BREATHING
 /** \brief Backlight breathing toggle
  *
  * FIXME: needs doc
  */
-void backlight_toggle_breathing(void)
-{
+void backlight_toggle_breathing(void) {
     bool breathing = backlight_config.breathing;
     dprintf("backlight breathing toggle: %u\n", breathing);
-    if (breathing) 
+    if (breathing)
         backlight_disable_breathing();
     else
         backlight_enable_breathing();
@@ -182,9 +163,8 @@ void backlight_toggle_breathing(void)
  *
  * FIXME: needs doc
  */
-void backlight_enable_breathing(void)
-{
-    if (backlight_config.breathing) return; // do nothing if breathing is already on
+void backlight_enable_breathing(void) {
+    if (backlight_config.breathing) return;  // do nothing if breathing is already on
 
     backlight_config.breathing = true;
     eeconfig_update_backlight(backlight_config.raw);
@@ -196,9 +176,8 @@ void backlight_enable_breathing(void)
  *
  * FIXME: needs doc
  */
-void backlight_disable_breathing(void)
-{
-    if (!backlight_config.breathing) return; // do nothing if breathing is already off
+void backlight_disable_breathing(void) {
+    if (!backlight_config.breathing) return;  // do nothing if breathing is already off
 
     backlight_config.breathing = false;
     eeconfig_update_backlight(backlight_config.raw);
@@ -210,8 +189,5 @@ void backlight_disable_breathing(void)
  *
  * FIXME: needs doc
  */
-bool is_backlight_breathing(void)
-{
-    return backlight_config.breathing;
-}
+bool is_backlight_breathing(void) { return backlight_config.breathing; }
 #endif
index 0a38771206071571048e2734e7015c5875b930ed..bb1f897ee874a8351234bff6135b6e989a3b813a 100644 (file)
@@ -21,31 +21,31 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdbool.h>
 
 #ifndef BACKLIGHT_LEVELS
-  #define BACKLIGHT_LEVELS 3
+#    define BACKLIGHT_LEVELS 3
 #elif BACKLIGHT_LEVELS > 31
-  #error "Maximum value of BACKLIGHT_LEVELS is 31"
+#    error "Maximum value of BACKLIGHT_LEVELS is 31"
 #endif
 
 typedef union {
     uint8_t raw;
     struct {
-        bool    enable    :1;
-        bool    breathing :1;
-        uint8_t reserved  :1; // Reserved for possible future backlight modes
-        uint8_t level     :5;
+        bool    enable 1;
+        bool    breathing : 1;
+        uint8_t reserved : 1;  // Reserved for possible future backlight modes
+        uint8_t level 5;
     };
 } backlight_config_t;
 
-void backlight_init(void);
-void backlight_increase(void);
-void backlight_decrease(void);
-void backlight_toggle(void);
-void backlight_enable(void);
-void backlight_disable(void);
-bool is_backlight_enabled(void);
-void backlight_step(void);
-void backlight_set(uint8_t level);
-void backlight_level(uint8_t level);
+void    backlight_init(void);
+void    backlight_increase(void);
+void    backlight_decrease(void);
+void    backlight_toggle(void);
+void    backlight_enable(void);
+void    backlight_disable(void);
+bool    is_backlight_enabled(void);
+void    backlight_step(void);
+void    backlight_set(uint8_t level);
+void    backlight_level(uint8_t level);
 uint8_t get_backlight_level(void);
 
 #ifdef BACKLIGHT_BREATHING
index 44775039d5b37a05252fcfa593cb855f8d67afea..19260a079713cfb50e18244a3f3d2988ae3b28c0 100644 (file)
@@ -18,7 +18,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef BOOTLOADER_H
 #define BOOTLOADER_H
 
-
 /* give code for your bootloader to come up if needed */
 void bootloader_jump(void);
 
index cc780d17abb5e2c495686d8772329df0cc6d280a..09b1664c9048ee08a993681115126bb92c065c37 100644 (file)
@@ -16,8 +16,7 @@ keymap_config_t keymap_config;
  *
  * FIXME: needs doc
  */
-void bootmagic(void)
-{
+void bootmagic(void) {
     /* check signature */
     if (!eeconfig_is_enabled()) {
         eeconfig_init();
@@ -26,7 +25,10 @@ void bootmagic(void)
     /* do scans in case of bounce */
     print("bootmagic scan: ... ");
     uint8_t scan = 100;
-    while (scan--) { matrix_scan(); wait_ms(10); }
+    while (scan--) {
+        matrix_scan();
+        wait_ms(10);
+    }
     print("done.\n");
 
     /* bootmagic skip */
@@ -89,14 +91,30 @@ void bootmagic(void)
 
     /* default layer */
     uint8_t default_layer = 0;
-    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); }
-    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { default_layer |= (1<<1); }
-    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { default_layer |= (1<<2); }
-    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { default_layer |= (1<<3); }
-    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { default_layer |= (1<<4); }
-    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { default_layer |= (1<<5); }
-    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { default_layer |= (1<<6); }
-    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); }
+    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) {
+        default_layer |= (1 << 0);
+    }
+    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) {
+        default_layer |= (1 << 1);
+    }
+    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) {
+        default_layer |= (1 << 2);
+    }
+    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) {
+        default_layer |= (1 << 3);
+    }
+    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) {
+        default_layer |= (1 << 4);
+    }
+    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) {
+        default_layer |= (1 << 5);
+    }
+    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) {
+        default_layer |= (1 << 6);
+    }
+    if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) {
+        default_layer |= (1 << 7);
+    }
     if (default_layer) {
         eeconfig_update_default_layer(default_layer);
         default_layer_set((layer_state_t)default_layer);
@@ -110,13 +128,12 @@ void bootmagic(void)
  *
  * FIXME: needs doc
  */
-static bool scan_keycode(uint8_t keycode)
-{
+static bool scan_keycode(uint8_t keycode) {
     for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
         matrix_row_t matrix_row = matrix_get_row(r);
         for (uint8_t c = 0; c < MATRIX_COLS; c++) {
-            if (matrix_row & ((matrix_row_t)1<<c)) {
-                if (keycode == keymap_key_to_keycode(0, (keypos_t){ .row = r, .col = c })) {
+            if (matrix_row & ((matrix_row_t)1 << c)) {
+                if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) {
                     return true;
                 }
             }
@@ -129,8 +146,7 @@ static bool scan_keycode(uint8_t keycode)
  *
  * FIXME: needs doc
  */
-bool bootmagic_scan_keycode(uint8_t keycode)
-{
+bool bootmagic_scan_keycode(uint8_t keycode) {
     if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
 
     return scan_keycode(keycode);
index f3ea6a24d422e83dc6917f6f1e508bcc7a2ded4e..fb764725798f3c0839bdc1e76944e7195385e3dd 100644 (file)
 #ifndef BOOTMAGIC_H
 #define BOOTMAGIC_H
 
-
 /* FIXME: Add special doxygen comments for defines here. */
 
 /* bootmagic salt key */
 #ifndef BOOTMAGIC_KEY_SALT
-#define BOOTMAGIC_KEY_SALT              KC_SPACE
+#    define BOOTMAGIC_KEY_SALT KC_SPACE
 #endif
 
 /* skip bootmagic and eeconfig */
 #ifndef BOOTMAGIC_KEY_SKIP
-#define BOOTMAGIC_KEY_SKIP              KC_ESC
+#    define BOOTMAGIC_KEY_SKIP KC_ESC
 #endif
 
 /* eeprom clear */
 #ifndef BOOTMAGIC_KEY_EEPROM_CLEAR
-#define BOOTMAGIC_KEY_EEPROM_CLEAR      KC_BSPACE
+#    define BOOTMAGIC_KEY_EEPROM_CLEAR KC_BSPACE
 #endif
 
 /* kick up bootloader */
 #ifndef BOOTMAGIC_KEY_BOOTLOADER
-#define BOOTMAGIC_KEY_BOOTLOADER        KC_B
+#    define BOOTMAGIC_KEY_BOOTLOADER KC_B
 #endif
 
 /* debug enable */
 #ifndef BOOTMAGIC_KEY_DEBUG_ENABLE
-#define BOOTMAGIC_KEY_DEBUG_ENABLE      KC_D
+#    define BOOTMAGIC_KEY_DEBUG_ENABLE KC_D
 #endif
 #ifndef BOOTMAGIC_KEY_DEBUG_MATRIX
-#define BOOTMAGIC_KEY_DEBUG_MATRIX      KC_X
+#    define BOOTMAGIC_KEY_DEBUG_MATRIX KC_X
 #endif
 #ifndef BOOTMAGIC_KEY_DEBUG_KEYBOARD
-#define BOOTMAGIC_KEY_DEBUG_KEYBOARD    KC_K
+#    define BOOTMAGIC_KEY_DEBUG_KEYBOARD KC_K
 #endif
 #ifndef BOOTMAGIC_KEY_DEBUG_MOUSE
-#define BOOTMAGIC_KEY_DEBUG_MOUSE       KC_M
+#    define BOOTMAGIC_KEY_DEBUG_MOUSE KC_M
 #endif
 
 /*
  * keymap config
  */
 #ifndef BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK
-#define BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK     KC_LCTRL
+#    define BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK KC_LCTRL
 #endif
 #ifndef BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL
-#define BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL       KC_CAPSLOCK
+#    define BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL KC_CAPSLOCK
 #endif
 #ifndef BOOTMAGIC_KEY_SWAP_LALT_LGUI
-#define BOOTMAGIC_KEY_SWAP_LALT_LGUI            KC_LALT
+#    define BOOTMAGIC_KEY_SWAP_LALT_LGUI KC_LALT
 #endif
 #ifndef BOOTMAGIC_KEY_SWAP_RALT_RGUI
-#define BOOTMAGIC_KEY_SWAP_RALT_RGUI            KC_RALT
+#    define BOOTMAGIC_KEY_SWAP_RALT_RGUI KC_RALT
 #endif
 #ifndef BOOTMAGIC_KEY_NO_GUI
-#define BOOTMAGIC_KEY_NO_GUI                    KC_LGUI
+#    define BOOTMAGIC_KEY_NO_GUI KC_LGUI
 #endif
 #ifndef BOOTMAGIC_KEY_SWAP_GRAVE_ESC
-#define BOOTMAGIC_KEY_SWAP_GRAVE_ESC            KC_GRAVE
+#    define BOOTMAGIC_KEY_SWAP_GRAVE_ESC KC_GRAVE
 #endif
 #ifndef BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE
-#define BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE  KC_BSLASH
+#    define BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE KC_BSLASH
 #endif
 #ifndef BOOTMAGIC_HOST_NKRO
-#define BOOTMAGIC_HOST_NKRO              KC_N
+#    define BOOTMAGIC_HOST_NKRO KC_N
 #endif
 
-
 /*
  * change default layer
  */
 #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_0
-#define BOOTMAGIC_KEY_DEFAULT_LAYER_0   KC_0
+#    define BOOTMAGIC_KEY_DEFAULT_LAYER_0 KC_0
 #endif
 #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_1
-#define BOOTMAGIC_KEY_DEFAULT_LAYER_1   KC_1
+#    define BOOTMAGIC_KEY_DEFAULT_LAYER_1 KC_1
 #endif
 #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_2
-#define BOOTMAGIC_KEY_DEFAULT_LAYER_2   KC_2
+#    define BOOTMAGIC_KEY_DEFAULT_LAYER_2 KC_2
 #endif
 #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_3
-#define BOOTMAGIC_KEY_DEFAULT_LAYER_3   KC_3
+#    define BOOTMAGIC_KEY_DEFAULT_LAYER_3 KC_3
 #endif
 #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_4
-#define BOOTMAGIC_KEY_DEFAULT_LAYER_4   KC_4
+#    define BOOTMAGIC_KEY_DEFAULT_LAYER_4 KC_4
 #endif
 #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_5
-#define BOOTMAGIC_KEY_DEFAULT_LAYER_5   KC_5
+#    define BOOTMAGIC_KEY_DEFAULT_LAYER_5 KC_5
 #endif
 #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_6
-#define BOOTMAGIC_KEY_DEFAULT_LAYER_6   KC_6
+#    define BOOTMAGIC_KEY_DEFAULT_LAYER_6 KC_6
 #endif
 #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7
-#define BOOTMAGIC_KEY_DEFAULT_LAYER_7   KC_7
+#    define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7
 #endif
 
-
 void bootmagic(void);
 bool bootmagic_scan_keycode(uint8_t keycode);
 
index f9895237b9bc5c49c296547e7f19cbb93bf656cf..4cf5dae7e6451eda9f3bfc44d464c41db92d6013 100644 (file)
@@ -7,63 +7,62 @@
 /* STM32 */
 
 /* This code should be checked whether it runs correctly on platforms */
-#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
+#    define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
 extern uint32_t __ram0_end__;
-#define BOOTLOADER_MAGIC 0xDEADBEEF
-#define MAGIC_ADDR (unsigned long*)(SYMVAL(__ram0_end__) - 4)
-
+#    define BOOTLOADER_MAGIC 0xDEADBEEF
+#    define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
 
 /** \brief Jump to the bootloader
  *
  * FIXME: needs doc
  */
 void bootloader_jump(void) {
-  *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader
-   NVIC_SystemReset();
+    *MAGIC_ADDR = BOOTLOADER_MAGIC;  // set magic flag => reset handler will jump into boot loader
+    NVIC_SystemReset();
 }
 
 /** \brief Enter bootloader mode if requested
  *
  * FIXME: needs doc
  */
-void enter_bootloader_mode_if_requested(void)  {
-  unsigned long* check = MAGIC_ADDR;
-  if(*check == BOOTLOADER_MAGIC)  {
-    *check = 0;
-    __set_CONTROL(0);
-    __set_MSP(*(__IO uint32_t*)STM32_BOOTLOADER_ADDRESS);
-    __enable_irq();
+void enter_bootloader_mode_if_requested(void) {
+    unsigned long *check = MAGIC_ADDR;
+    if (*check == BOOTLOADER_MAGIC) {
+        *check = 0;
+        __set_CONTROL(0);
+        __set_MSP(*(__IO uint32_t *)STM32_BOOTLOADER_ADDRESS);
+        __enable_irq();
 
-    typedef void (*BootJump_t)(void);
-    BootJump_t boot_jump = *(BootJump_t*)(STM32_BOOTLOADER_ADDRESS + 4);
-    boot_jump();
-    while(1);
-  }
- }
+        typedef void (*BootJump_t)(void);
+        BootJump_t boot_jump = *(BootJump_t *)(STM32_BOOTLOADER_ADDRESS + 4);
+        boot_jump();
+        while (1)
+            ;
+    }
+}
 
 #elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */
 /* Kinetis */
 
-#if defined(KIIBOHD_BOOTLOADER)
+#    if defined(KIIBOHD_BOOTLOADER)
 /* Kiibohd Bootloader (MCHCK and Infinity KB) */
-#define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
+#        define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
 const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
-void bootloader_jump(void) {
-  __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
-  // request reset
-  SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
+void          bootloader_jump(void) {
+    __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
+    // request reset
+    SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
 }
 
-#else /* defined(KIIBOHD_BOOTLOADER) */
+#    else /* defined(KIIBOHD_BOOTLOADER) */
 /* Default for Kinetis - expecting an ARM Teensy */
-#include "wait.h"
+#        include "wait.h"
 void bootloader_jump(void) {
-       wait_ms(100);
-       __BKPT(0);
+    wait_ms(100);
+    __BKPT(0);
 }
-#endif /* defined(KIIBOHD_BOOTLOADER) */
+#    endif /* defined(KIIBOHD_BOOTLOADER) */
 
 #else /* neither STM32 nor KINETIS */
-__attribute__((weak))
-void bootloader_jump(void) {}
+__attribute__((weak)) void bootloader_jump(void) {}
 #endif
old mode 100755 (executable)
new mode 100644 (file)
index 4b1abc9..926b581
@@ -24,7 +24,7 @@
  * the functionality use the EEPROM_Init() function. Be sure that by reprogramming
  * of the controller just affected pages will be deleted. In other case the non
  * volatile data will be lost.
-******************************************************************************/
+ ******************************************************************************/
 
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 
 uint8_t DataBuf[FEE_PAGE_SIZE];
 /*****************************************************************************
-*  Delete Flash Space used for user Data, deletes the whole space between
-*  RW_PAGE_BASE_ADDRESS and the last uC Flash Page
-******************************************************************************/
+ *  Delete Flash Space used for user Data, deletes the whole space between
+ *  RW_PAGE_BASE_ADDRESS and the last uC Flash Page
+ ******************************************************************************/
 uint16_t EEPROM_Init(void) {
     // unlock flash
     FLASH_Unlock();
 
     // Clear Flags
-    //FLASH_ClearFlag(FLASH_SR_EOP|FLASH_SR_PGERR|FLASH_SR_WRPERR);
+    // FLASH_ClearFlag(FLASH_SR_EOP|FLASH_SR_PGERR|FLASH_SR_WRPERR);
 
     return FEE_DENSITY_BYTES;
 }
 /*****************************************************************************
-*  Erase the whole reserved Flash Space used for user Data
-******************************************************************************/
-void EEPROM_Erase (void) {
-
+ *  Erase the whole reserved Flash Space used for user Data
+ ******************************************************************************/
+void EEPROM_Erase(void) {
     int page_num = 0;
 
     // delete all pages from specified start page to the last page
@@ -58,16 +57,15 @@ void EEPROM_Erase (void) {
     } while (page_num < FEE_DENSITY_PAGES);
 }
 /*****************************************************************************
-*  Writes once data byte to flash on specified address. If a byte is already
-*  written, the whole page must be copied to a buffer, the byte changed and
-*  the manipulated buffer written after PageErase.
-*******************************************************************************/
-uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) {
-
+ *  Writes once data byte to flash on specified address. If a byte is already
+ *  written, the whole page must be copied to a buffer, the byte changed and
+ *  the manipulated buffer written after PageErase.
+ *******************************************************************************/
+uint16_t EEPROM_WriteDataByte(uint16_t Address, uint8_t DataByte) {
     FLASH_Status FlashStatus = FLASH_COMPLETE;
 
     uint32_t page;
-    int i;
+    int      i;
 
     // exit if desired address is above the limit (e.G. under 2048 Bytes for 4 pages)
     if (Address > FEE_DENSITY_BYTES) {
@@ -78,27 +76,25 @@ uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) {
     page = FEE_ADDR_OFFSET(Address) / FEE_PAGE_SIZE;
 
     // if current data is 0xFF, the byte is empty, just overwrite with the new one
-    if ((*(__IO uint16_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) == FEE_EMPTY_WORD) {
-
+    if ((*(__IO uint16_t *)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) == FEE_EMPTY_WORD) {
         FlashStatus = FLASH_ProgramHalfWord(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address), (uint16_t)(0x00FF & DataByte));
     } else {
-
         // Copy Page to a buffer
-        memcpy(DataBuf, (uint8_t*)FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE), FEE_PAGE_SIZE); // !!! Calculate base address for the desired page
+        memcpy(DataBuf, (uint8_t *)FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE), FEE_PAGE_SIZE);  // !!! Calculate base address for the desired page
 
         // check if new data is differ to current data, return if not, proceed if yes
-        if (DataByte == *(__IO uint8_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) {
+        if (DataByte == *(__IO uint8_t *)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) {
             return 0;
         }
 
         // manipulate desired data byte in temp data array if new byte is differ to the current
         DataBuf[FEE_ADDR_OFFSET(Address) % FEE_PAGE_SIZE] = DataByte;
 
-        //Erase Page
+        // Erase Page
         FlashStatus = FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE));
 
         // Write new data (whole page) to flash if data has been changed
-        for(i = 0; i < (FEE_PAGE_SIZE / 2); i++) {
+        for (i = 0; i < (FEE_PAGE_SIZE / 2); i++) {
             if ((__IO uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)]) != 0xFFFF) {
                 FlashStatus = FLASH_ProgramHalfWord((FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE)) + (i * 2), (uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)]));
             }
@@ -107,98 +103,86 @@ uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) {
     return FlashStatus;
 }
 /*****************************************************************************
-*  Read once data byte from a specified address.
-*******************************************************************************/
-uint8_t EEPROM_ReadDataByte (uint16_t Address) {
-
+ *  Read once data byte from a specified address.
+ *******************************************************************************/
+uint8_t EEPROM_ReadDataByte(uint16_t Address) {
     uint8_t DataByte = 0xFF;
 
     // Get Byte from specified address
-    DataByte = (*(__IO uint8_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address)));
+    DataByte = (*(__IO uint8_t *)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address)));
 
     return DataByte;
 }
 
 /*****************************************************************************
-*  Wrap library in AVR style functions.
-*******************************************************************************/
-uint8_t eeprom_read_byte (const uint8_t *Address)
-{
-    const uint16_t p = (const uint32_t) Address;
+ *  Wrap library in AVR style functions.
+ *******************************************************************************/
+uint8_t eeprom_read_byte(const uint8_t *Address) {
+    const uint16_t p = (const uint32_t)Address;
     return EEPROM_ReadDataByte(p);
 }
 
-void eeprom_write_byte (uint8_t *Address, uint8_t Value)
-{
-    uint16_t p = (uint32_t) Address;
+void eeprom_write_byte(uint8_t *Address, uint8_t Value) {
+    uint16_t p = (uint32_t)Address;
     EEPROM_WriteDataByte(p, Value);
 }
 
-void eeprom_update_byte (uint8_t *Address, uint8_t Value)
-{
-    uint16_t p = (uint32_t) Address;
+void eeprom_update_byte(uint8_t *Address, uint8_t Value) {
+    uint16_t p = (uint32_t)Address;
     EEPROM_WriteDataByte(p, Value);
 }
 
-uint16_t eeprom_read_word (const uint16_t *Address)
-{
-    const uint16_t p = (const uint32_t) Address;
-    return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8);
+uint16_t eeprom_read_word(const uint16_t *Address) {
+    const uint16_t p = (const uint32_t)Address;
+    return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p + 1) << 8);
 }
 
-void eeprom_write_word (uint16_t *Address, uint16_t Value)
-{
-    uint16_t p = (uint32_t) Address;
-    EEPROM_WriteDataByte(p, (uint8_t) Value);
-    EEPROM_WriteDataByte(p + 1, (uint8_t) (Value >> 8));
+void eeprom_write_word(uint16_t *Address, uint16_t Value) {
+    uint16_t p = (uint32_t)Address;
+    EEPROM_WriteDataByte(p, (uint8_t)Value);
+    EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8));
 }
 
-void eeprom_update_word (uint16_t *Address, uint16_t Value)
-{
-    uint16_t p = (uint32_t) Address;
-    EEPROM_WriteDataByte(p, (uint8_t) Value);
-    EEPROM_WriteDataByte(p + 1, (uint8_t) (Value >> 8));
+void eeprom_update_word(uint16_t *Address, uint16_t Value) {
+    uint16_t p = (uint32_t)Address;
+    EEPROM_WriteDataByte(p, (uint8_t)Value);
+    EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8));
 }
 
-uint32_t eeprom_read_dword (const uint32_t *Address)
-{
-    const uint16_t p = (const uint32_t) Address;
-    return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8)
-        | (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24);
+uint32_t eeprom_read_dword(const uint32_t *Address) {
+    const uint16_t p = (const uint32_t)Address;
+    return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p + 1) << 8) | (EEPROM_ReadDataByte(p + 2) << 16) | (EEPROM_ReadDataByte(p + 3) << 24);
 }
 
-void eeprom_write_dword (uint32_t *Address, uint32_t Value)
-{
-    uint16_t p = (const uint32_t) Address;
-    EEPROM_WriteDataByte(p, (uint8_t) Value);
-    EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8));
-    EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16));
-    EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24));
+void eeprom_write_dword(uint32_t *Address, uint32_t Value) {
+    uint16_t p = (const uint32_t)Address;
+    EEPROM_WriteDataByte(p, (uint8_t)Value);
+    EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8));
+    EEPROM_WriteDataByte(p + 2, (uint8_t)(Value >> 16));
+    EEPROM_WriteDataByte(p + 3, (uint8_t)(Value >> 24));
 }
 
-void eeprom_update_dword (uint32_t *Address, uint32_t Value)
-{
-    uint16_t p = (const uint32_t) Address;
-    uint32_t existingValue = EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8)
-        | (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24);
-    if(Value != existingValue){
-      EEPROM_WriteDataByte(p, (uint8_t) Value);
-      EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8));
-      EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16));
-      EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24));
+void eeprom_update_dword(uint32_t *Address, uint32_t Value) {
+    uint16_t p             = (const uint32_t)Address;
+    uint32_t existingValue = EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p + 1) << 8) | (EEPROM_ReadDataByte(p + 2) << 16) | (EEPROM_ReadDataByte(p + 3) << 24);
+    if (Value != existingValue) {
+        EEPROM_WriteDataByte(p, (uint8_t)Value);
+        EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8));
+        EEPROM_WriteDataByte(p + 2, (uint8_t)(Value >> 16));
+        EEPROM_WriteDataByte(p + 3, (uint8_t)(Value >> 24));
     }
 }
 
 void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
-    const uint8_t *p = (const uint8_t *)addr;
-    uint8_t *dest = (uint8_t *)buf;
+    const uint8_t *p    = (const uint8_t *)addr;
+    uint8_t *      dest = (uint8_t *)buf;
     while (len--) {
         *dest++ = eeprom_read_byte(p++);
     }
 }
 
 void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
-    uint8_t *p = (uint8_t *)addr;
+    uint8_t *      p   = (uint8_t *)addr;
     const uint8_t *src = (const uint8_t *)buf;
     while (len--) {
         eeprom_write_byte(p++, *src++);
@@ -206,7 +190,7 @@ void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
 }
 
 void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
-    uint8_t *p = (uint8_t *)addr;
+    uint8_t *      p   = (uint8_t *)addr;
     const uint8_t *src = (const uint8_t *)buf;
     while (len--) {
         eeprom_write_byte(p++, *src++);
old mode 100755 (executable)
new mode 100644 (file)
index 083eb16..e689145
 // HACK ALERT. This definition may not match your processor
 // To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc
 #if defined(EEPROM_EMU_STM32F303xC)
-  #define MCU_STM32F303CC
+#    define MCU_STM32F303CC
 #elif defined(EEPROM_EMU_STM32F103xB)
-  #define MCU_STM32F103RB
+#    define MCU_STM32F103RB
 #elif defined(EEPROM_EMU_STM32F072xB)
-  #define MCU_STM32F072CB
+#    define MCU_STM32F072CB
 #else
-  #error "not implemented."
+#    error "not implemented."
 #endif
 
 #ifndef EEPROM_PAGE_SIZE
-    #if defined (MCU_STM32F103RB)
-        #define FEE_PAGE_SIZE    (uint16_t)0x400 // Page size = 1KByte
-        #define FEE_DENSITY_PAGES          2     // How many pages are used
-    #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) || defined (MCU_STM32F103RD) || defined (MCU_STM32F303CC) || defined(MCU_STM32F072CB)
-        #define FEE_PAGE_SIZE    (uint16_t)0x800 // Page size = 2KByte
-        #define FEE_DENSITY_PAGES          4     // How many pages are used
-    #else
-        #error  "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
-    #endif
+#    if defined(MCU_STM32F103RB)
+#        define FEE_PAGE_SIZE (uint16_t)0x400  // Page size = 1KByte
+#        define FEE_DENSITY_PAGES 2            // How many pages are used
+#    elif defined(MCU_STM32F103ZE) || defined(MCU_STM32F103RE) || defined(MCU_STM32F103RD) || defined(MCU_STM32F303CC) || defined(MCU_STM32F072CB)
+#        define FEE_PAGE_SIZE (uint16_t)0x800  // Page size = 2KByte
+#        define FEE_DENSITY_PAGES 4            // How many pages are used
+#    else
+#        error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
+#    endif
 #endif
 
 #ifndef EEPROM_START_ADDRESS
-    #if defined (MCU_STM32F103RB) || defined(MCU_STM32F072CB)
-        #define FEE_MCU_FLASH_SIZE  128     // Size in Kb
-    #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE)
-        #define FEE_MCU_FLASH_SIZE  512     // Size in Kb
-    #elif defined (MCU_STM32F103RD)
-        #define FEE_MCU_FLASH_SIZE  384     // Size in Kb
-    #elif defined (MCU_STM32F303CC)
-        #define FEE_MCU_FLASH_SIZE  256     // Size in Kb
-    #else
-        #error  "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
-    #endif
+#    if defined(MCU_STM32F103RB) || defined(MCU_STM32F072CB)
+#        define FEE_MCU_FLASH_SIZE 128  // Size in Kb
+#    elif defined(MCU_STM32F103ZE) || defined(MCU_STM32F103RE)
+#        define FEE_MCU_FLASH_SIZE 512  // Size in Kb
+#    elif defined(MCU_STM32F103RD)
+#        define FEE_MCU_FLASH_SIZE 384  // Size in Kb
+#    elif defined(MCU_STM32F303CC)
+#        define FEE_MCU_FLASH_SIZE 256  // Size in Kb
+#    else
+#        error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
+#    endif
 #endif
 
 // DONT CHANGE
 // Choose location for the first EEPROM Page address on the top of flash
 #define FEE_PAGE_BASE_ADDRESS ((uint32_t)(0x8000000 + FEE_MCU_FLASH_SIZE * 1024 - FEE_DENSITY_PAGES * FEE_PAGE_SIZE))
-#define FEE_DENSITY_BYTES       ((FEE_PAGE_SIZE / 2) * FEE_DENSITY_PAGES - 1)
-#define FEE_LAST_PAGE_ADDRESS   (FEE_PAGE_BASE_ADDRESS + (FEE_PAGE_SIZE * FEE_DENSITY_PAGES))
-#define FEE_EMPTY_WORD          ((uint16_t)0xFFFF)
-#define FEE_ADDR_OFFSET(Address)(Address * 2) // 1Byte per Word will be saved to preserve Flash
+#define FEE_DENSITY_BYTES ((FEE_PAGE_SIZE / 2) * FEE_DENSITY_PAGES - 1)
+#define FEE_LAST_PAGE_ADDRESS (FEE_PAGE_BASE_ADDRESS + (FEE_PAGE_SIZE * FEE_DENSITY_PAGES))
+#define FEE_EMPTY_WORD ((uint16_t)0xFFFF)
+#define FEE_ADDR_OFFSET(Address) (Address * 2)  // 1Byte per Word will be saved to preserve Flash
 
 // Use this function to initialize the functionality
 uint16_t EEPROM_Init(void);
-void EEPROM_Erase (void);
-uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte);
-uint8_t EEPROM_ReadDataByte (uint16_t Address);
+void     EEPROM_Erase(void);
+uint16_t EEPROM_WriteDataByte(uint16_t Address, uint8_t DataByte);
+uint8_t  EEPROM_ReadDataByte(uint16_t Address);
 
-#endif  /* __EEPROM_H */
+#endif /* __EEPROM_H */
index 9061b790c442f1e5d3682670c5f14619ba597b16..a4093fb3bac161a7582697c8c07d0f7d10ae004d 100644 (file)
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
  *
- * 1. The above copyright notice and this permission notice shall be 
+ * 1. The above copyright notice and this permission notice shall be
  * included in all copies or substantial portions of the Software.
  *
- * 2. If the Software is incorporated into a build system that allows 
+ * 2. If the Software is incorporated into a build system that allows
  * selection among a list of target devices, then similar target
  * devices manufactured by PJRC.COM must be included in the list of
  * target devices and selectable in the same manner.
@@ -39,7 +39,6 @@
  * SOFTWARE.
  */
 
-
 #if defined(K20x) /* chip selection */
 /* Teensy 3.0, 3.1, 3.2; mchck; infinity keyboard */
 
@@ -51,7 +50,7 @@
 // (aligned to 2 or 4 byte boundaries) has twice the endurance
 // compared to writing 8 bit bytes.
 //
-#define EEPROM_SIZE 32
+#    define EEPROM_SIZE 32
 
 // Writing unaligned 16 or 32 bit data is handled automatically when
 // this is defined, but at a cost of extra code size.  Without this,
 // absolutely sure all 16 and 32 bit writes will be aligned, you can
 // remove the extra unnecessary code.
 //
-#define HANDLE_UNALIGNED_WRITES
+#    define HANDLE_UNALIGNED_WRITES
 
 // Minimum EEPROM Endurance
 // ------------------------
-#if (EEPROM_SIZE == 2048)      // 35000 writes/byte or 70000 writes/word
-  #define EEESIZE 0x33
-#elif (EEPROM_SIZE == 1024)    // 75000 writes/byte or 150000 writes/word
-  #define EEESIZE 0x34
-#elif (EEPROM_SIZE == 512)     // 155000 writes/byte or 310000 writes/word
-  #define EEESIZE 0x35
-#elif (EEPROM_SIZE == 256)     // 315000 writes/byte or 630000 writes/word
-  #define EEESIZE 0x36
-#elif (EEPROM_SIZE == 128)     // 635000 writes/byte or 1270000 writes/word
-  #define EEESIZE 0x37
-#elif (EEPROM_SIZE == 64)      // 1275000 writes/byte or 2550000 writes/word
-  #define EEESIZE 0x38
-#elif (EEPROM_SIZE == 32)      // 2555000 writes/byte or 5110000 writes/word
-  #define EEESIZE 0x39
-#endif
+#    if (EEPROM_SIZE == 2048)  // 35000 writes/byte or 70000 writes/word
+#        define EEESIZE 0x33
+#    elif (EEPROM_SIZE == 1024)  // 75000 writes/byte or 150000 writes/word
+#        define EEESIZE 0x34
+#    elif (EEPROM_SIZE == 512)  // 155000 writes/byte or 310000 writes/word
+#        define EEESIZE 0x35
+#    elif (EEPROM_SIZE == 256)  // 315000 writes/byte or 630000 writes/word
+#        define EEESIZE 0x36
+#    elif (EEPROM_SIZE == 128)  // 635000 writes/byte or 1270000 writes/word
+#        define EEESIZE 0x37
+#    elif (EEPROM_SIZE == 64)  // 1275000 writes/byte or 2550000 writes/word
+#        define EEESIZE 0x38
+#    elif (EEPROM_SIZE == 32)  // 2555000 writes/byte or 5110000 writes/word
+#        define EEESIZE 0x39
+#    endif
 
 /** \brief eeprom initialization
  *
  * FIXME: needs doc
  */
-void eeprom_initialize(void)
-{
-       uint32_t count=0;
-       uint16_t do_flash_cmd[] = {
-               0xf06f, 0x037f, 0x7003, 0x7803,
-               0xf013, 0x0f80, 0xd0fb, 0x4770};
-       uint8_t status;
-
-       if (FTFL->FCNFG & FTFL_FCNFG_RAMRDY) {
-               // FlexRAM is configured as traditional RAM
-               // We need to reconfigure for EEPROM usage
-               FTFL->FCCOB0 = 0x80; // PGMPART = Program Partition Command
-               FTFL->FCCOB4 = EEESIZE; // EEPROM Size
-               FTFL->FCCOB5 = 0x03; // 0K for Dataflash, 32K for EEPROM backup
-               __disable_irq();
-               // do_flash_cmd() must execute from RAM.  Luckily the C syntax is simple...
-               (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFL->FSTAT));
-               __enable_irq();
-               status = FTFL->FSTAT;
-               if (status & (FTFL_FSTAT_RDCOLERR|FTFL_FSTAT_ACCERR|FTFL_FSTAT_FPVIOL)) {
-                       FTFL->FSTAT = (status & (FTFL_FSTAT_RDCOLERR|FTFL_FSTAT_ACCERR|FTFL_FSTAT_FPVIOL));
-                       return; // error
-               }
-       }
-       // wait for eeprom to become ready (is this really necessary?)
-       while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
-               if (++count > 20000) break;
-       }
-}
-
-#define FlexRAM ((uint8_t *)0x14000000)
+void eeprom_initialize(void) {
+    uint32_t count          = 0;
+    uint16_t do_flash_cmd[] = {0xf06f, 0x037f, 0x7003, 0x7803, 0xf013, 0x0f80, 0xd0fb, 0x4770};
+    uint8_t  status;
+
+    if (FTFL->FCNFG & FTFL_FCNFG_RAMRDY) {
+        // FlexRAM is configured as traditional RAM
+        // We need to reconfigure for EEPROM usage
+        FTFL->FCCOB0 = 0x80;     // PGMPART = Program Partition Command
+        FTFL->FCCOB4 = EEESIZE;  // EEPROM Size
+        FTFL->FCCOB5 = 0x03;     // 0K for Dataflash, 32K for EEPROM backup
+        __disable_irq();
+        // do_flash_cmd() must execute from RAM.  Luckily the C syntax is simple...
+        (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFL->FSTAT));
+        __enable_irq();
+        status = FTFL->FSTAT;
+        if (status & (FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL)) {
+            FTFL->FSTAT = (status & (FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL));
+            return;  // error
+        }
+    }
+    // wait for eeprom to become ready (is this really necessary?)
+    while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
+        if (++count > 20000) break;
+    }
+}
+
+#    define FlexRAM ((uint8_t *)0x14000000)
 
 /** \brief eeprom read byte
  *
  * FIXME: needs doc
  */
-uint8_t eeprom_read_byte(const uint8_t *addr)
-{
-       uint32_t offset = (uint32_t)addr;
-       if (offset >= EEPROM_SIZE) return 0;
-       if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
-       return FlexRAM[offset];
+uint8_t eeprom_read_byte(const uint8_t *addr) {
+    uint32_t offset = (uint32_t)addr;
+    if (offset >= EEPROM_SIZE) return 0;
+    if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+    return FlexRAM[offset];
 }
 
 /** \brief eeprom read word
  *
  * FIXME: needs doc
  */
-uint16_t eeprom_read_word(const uint16_t *addr)
-{
-       uint32_t offset = (uint32_t)addr;
-       if (offset >= EEPROM_SIZE-1) return 0;
-       if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
-       return *(uint16_t *)(&FlexRAM[offset]);
+uint16_t eeprom_read_word(const uint16_t *addr) {
+    uint32_t offset = (uint32_t)addr;
+    if (offset >= EEPROM_SIZE - 1) return 0;
+    if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+    return *(uint16_t *)(&FlexRAM[offset]);
 }
 
 /** \brief eeprom read dword
  *
  * FIXME: needs doc
  */
-uint32_t eeprom_read_dword(const uint32_t *addr)
-{
-       uint32_t offset = (uint32_t)addr;
-       if (offset >= EEPROM_SIZE-3) return 0;
-       if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
-       return *(uint32_t *)(&FlexRAM[offset]);
+uint32_t eeprom_read_dword(const uint32_t *addr) {
+    uint32_t offset = (uint32_t)addr;
+    if (offset >= EEPROM_SIZE - 3) return 0;
+    if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+    return *(uint32_t *)(&FlexRAM[offset]);
 }
 
 /** \brief eeprom read block
  *
  * FIXME: needs doc
  */
-void eeprom_read_block(void *buf, const void *addr, uint32_t len)
-{
-       uint32_t offset = (uint32_t)addr;
-       uint8_t *dest = (uint8_t *)buf;
-       uint32_t end = offset + len;
-       
-       if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
-       if (end > EEPROM_SIZE) end = EEPROM_SIZE;
-       while (offset < end) {
-               *dest++ = FlexRAM[offset++];
-       }
+void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
+    uint32_t offset = (uint32_t)addr;
+    uint8_t *dest   = (uint8_t *)buf;
+    uint32_t end    = offset + len;
+
+    if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+    if (end > EEPROM_SIZE) end = EEPROM_SIZE;
+    while (offset < end) {
+        *dest++ = FlexRAM[offset++];
+    }
 }
 
 /** \brief eeprom is ready
  *
  * FIXME: needs doc
  */
-int eeprom_is_ready(void)
-{
-       return (FTFL->FCNFG & FTFL_FCNFG_EEERDY) ? 1 : 0;
-}
+int eeprom_is_ready(void) { return (FTFL->FCNFG & FTFL_FCNFG_EEERDY) ? 1 : 0; }
 
 /** \brief flexram wait
  *
  * FIXME: needs doc
  */
-static void flexram_wait(void)
-{
-       while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
-               // TODO: timeout
-       }
+static void flexram_wait(void) {
+    while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
+        // TODO: timeout
+    }
 }
 
 /** \brief eeprom_write_byte
  *
  * FIXME: needs doc
  */
-void eeprom_write_byte(uint8_t *addr, uint8_t value)
-{
-       uint32_t offset = (uint32_t)addr;
+void eeprom_write_byte(uint8_t *addr, uint8_t value) {
+    uint32_t offset = (uint32_t)addr;
 
-       if (offset >= EEPROM_SIZE) return;
-       if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
-       if (FlexRAM[offset] != value) {
-               FlexRAM[offset] = value;
-               flexram_wait();
-       }
+    if (offset >= EEPROM_SIZE) return;
+    if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+    if (FlexRAM[offset] != value) {
+        FlexRAM[offset] = value;
+        flexram_wait();
+    }
 }
 
 /** \brief eeprom write word
  *
  * FIXME: needs doc
  */
-void eeprom_write_word(uint16_t *addr, uint16_t value)
-{
-       uint32_t offset = (uint32_t)addr;
-
-       if (offset >= EEPROM_SIZE-1) return;
-       if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
-#ifdef HANDLE_UNALIGNED_WRITES
-       if ((offset & 1) == 0) {
-#endif
-               if (*(uint16_t *)(&FlexRAM[offset]) != value) {
-                       *(uint16_t *)(&FlexRAM[offset]) = value;
-                       flexram_wait();
-               }
-#ifdef HANDLE_UNALIGNED_WRITES
-       } else {
-               if (FlexRAM[offset] != value) {
-                       FlexRAM[offset] = value;
-                       flexram_wait();
-               }
-               if (FlexRAM[offset + 1] != (value >> 8)) {
-                       FlexRAM[offset + 1] = value >> 8;
-                       flexram_wait();
-               }
-       }
-#endif
+void eeprom_write_word(uint16_t *addr, uint16_t value) {
+    uint32_t offset = (uint32_t)addr;
+
+    if (offset >= EEPROM_SIZE - 1) return;
+    if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+#    ifdef HANDLE_UNALIGNED_WRITES
+    if ((offset & 1) == 0) {
+#    endif
+        if (*(uint16_t *)(&FlexRAM[offset]) != value) {
+            *(uint16_t *)(&FlexRAM[offset]) = value;
+            flexram_wait();
+        }
+#    ifdef HANDLE_UNALIGNED_WRITES
+    } else {
+        if (FlexRAM[offset] != value) {
+            FlexRAM[offset] = value;
+            flexram_wait();
+        }
+        if (FlexRAM[offset + 1] != (value >> 8)) {
+            FlexRAM[offset + 1] = value >> 8;
+            flexram_wait();
+        }
+    }
+#    endif
 }
 
 /** \brief eeprom write dword
  *
  * FIXME: needs doc
  */
-void eeprom_write_dword(uint32_t *addr, uint32_t value)
-{
-       uint32_t offset = (uint32_t)addr;
-
-       if (offset >= EEPROM_SIZE-3) return;
-       if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
-#ifdef HANDLE_UNALIGNED_WRITES
-       switch (offset & 3) {
-       case 0:
-#endif
-               if (*(uint32_t *)(&FlexRAM[offset]) != value) {
-                       *(uint32_t *)(&FlexRAM[offset]) = value;
-                       flexram_wait();
-               }
-               return;
-#ifdef HANDLE_UNALIGNED_WRITES
-       case 2:
-               if (*(uint16_t *)(&FlexRAM[offset]) != value) {
-                       *(uint16_t *)(&FlexRAM[offset]) = value;
-                       flexram_wait();
-               }
-               if (*(uint16_t *)(&FlexRAM[offset + 2]) != (value >> 16)) {
-                       *(uint16_t *)(&FlexRAM[offset + 2]) = value >> 16;
-                       flexram_wait();
-               }
-               return;
-       default:
-               if (FlexRAM[offset] != value) {
-                       FlexRAM[offset] = value;
-                       flexram_wait();
-               }
-               if (*(uint16_t *)(&FlexRAM[offset + 1]) != (value >> 8)) {
-                       *(uint16_t *)(&FlexRAM[offset + 1]) = value >> 8;
-                       flexram_wait();
-               }
-               if (FlexRAM[offset + 3] != (value >> 24)) {
-                       FlexRAM[offset + 3] = value >> 24;
-                       flexram_wait();
-               }
-       }
-#endif
+void eeprom_write_dword(uint32_t *addr, uint32_t value) {
+    uint32_t offset = (uint32_t)addr;
+
+    if (offset >= EEPROM_SIZE - 3) return;
+    if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+#    ifdef HANDLE_UNALIGNED_WRITES
+    switch (offset & 3) {
+        case 0:
+#    endif
+            if (*(uint32_t *)(&FlexRAM[offset]) != value) {
+                *(uint32_t *)(&FlexRAM[offset]) = value;
+                flexram_wait();
+            }
+            return;
+#    ifdef HANDLE_UNALIGNED_WRITES
+        case 2:
+            if (*(uint16_t *)(&FlexRAM[offset]) != value) {
+                *(uint16_t *)(&FlexRAM[offset]) = value;
+                flexram_wait();
+            }
+            if (*(uint16_t *)(&FlexRAM[offset + 2]) != (value >> 16)) {
+                *(uint16_t *)(&FlexRAM[offset + 2]) = value >> 16;
+                flexram_wait();
+            }
+            return;
+        default:
+            if (FlexRAM[offset] != value) {
+                FlexRAM[offset] = value;
+                flexram_wait();
+            }
+            if (*(uint16_t *)(&FlexRAM[offset + 1]) != (value >> 8)) {
+                *(uint16_t *)(&FlexRAM[offset + 1]) = value >> 8;
+                flexram_wait();
+            }
+            if (FlexRAM[offset + 3] != (value >> 24)) {
+                FlexRAM[offset + 3] = value >> 24;
+                flexram_wait();
+            }
+    }
+#    endif
 }
 
 /** \brief eeprom write block
  *
  * FIXME: needs doc
  */
-void eeprom_write_block(const void *buf, void *addr, uint32_t len)
-{
-       uint32_t offset = (uint32_t)addr;
-       const uint8_t *src = (const uint8_t *)buf;
-
-       if (offset >= EEPROM_SIZE) return;
-       if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
-       if (len >= EEPROM_SIZE) len = EEPROM_SIZE;
-       if (offset + len >= EEPROM_SIZE) len = EEPROM_SIZE - offset;
-       while (len > 0) {
-               uint32_t lsb = offset & 3;
-               if (lsb == 0 && len >= 4) {
-                       // write aligned 32 bits
-                       uint32_t val32;
-                       val32 = *src++;
-                       val32 |= (*src++ << 8);
-                       val32 |= (*src++ << 16);
-                       val32 |= (*src++ << 24);
-                       if (*(uint32_t *)(&FlexRAM[offset]) != val32) {
-                               *(uint32_t *)(&FlexRAM[offset]) = val32;
-                               flexram_wait();
-                       }
-                       offset += 4;
-                       len -= 4;
-               } else if ((lsb == 0 || lsb == 2) && len >= 2) {
-                       // write aligned 16 bits
-                       uint16_t val16;
-                       val16 = *src++;
-                       val16 |= (*src++ << 8);
-                       if (*(uint16_t *)(&FlexRAM[offset]) != val16) {
-                               *(uint16_t *)(&FlexRAM[offset]) = val16;
-                               flexram_wait();
-                       }
-                       offset += 2;
-                       len -= 2;
-               } else {
-                       // write 8 bits
-                       uint8_t val8 = *src++;
-                       if (FlexRAM[offset] != val8) {
-                               FlexRAM[offset] = val8;
-                               flexram_wait();
-                       }
-                       offset++;
-                       len--;
-               }
-       }
+void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
+    uint32_t       offset = (uint32_t)addr;
+    const uint8_t *src    = (const uint8_t *)buf;
+
+    if (offset >= EEPROM_SIZE) return;
+    if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+    if (len >= EEPROM_SIZE) len = EEPROM_SIZE;
+    if (offset + len >= EEPROM_SIZE) len = EEPROM_SIZE - offset;
+    while (len > 0) {
+        uint32_t lsb = offset & 3;
+        if (lsb == 0 && len >= 4) {
+            // write aligned 32 bits
+            uint32_t val32;
+            val32 = *src++;
+            val32 |= (*src++ << 8);
+            val32 |= (*src++ << 16);
+            val32 |= (*src++ << 24);
+            if (*(uint32_t *)(&FlexRAM[offset]) != val32) {
+                *(uint32_t *)(&FlexRAM[offset]) = val32;
+                flexram_wait();
+            }
+            offset += 4;
+            len -= 4;
+        } else if ((lsb == 0 || lsb == 2) && len >= 2) {
+            // write aligned 16 bits
+            uint16_t val16;
+            val16 = *src++;
+            val16 |= (*src++ << 8);
+            if (*(uint16_t *)(&FlexRAM[offset]) != val16) {
+                *(uint16_t *)(&FlexRAM[offset]) = val16;
+                flexram_wait();
+            }
+            offset += 2;
+            len -= 2;
+        } else {
+            // write 8 bits
+            uint8_t val8 = *src++;
+            if (FlexRAM[offset] != val8) {
+                FlexRAM[offset] = val8;
+                flexram_wait();
+            }
+            offset++;
+            len--;
+        }
+    }
 }
 
 /*
 void do_flash_cmd(volatile uint8_t *fstat)
 {
-       *fstat = 0x80;
-       while ((*fstat & 0x80) == 0) ; // wait
+    *fstat = 0x80;
+    while ((*fstat & 0x80) == 0) ; // wait
 }
 00000000 <do_flash_cmd>:
    0:  f06f 037f       mvn.w   r3, #127        ; 0x7f
@@ -352,128 +336,124 @@ void do_flash_cmd(volatile uint8_t *fstat)
 #elif defined(KL2x) /* chip selection */
 /* Teensy LC (emulated) */
 
-#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
+#    define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
 
 extern uint32_t __eeprom_workarea_start__;
 extern uint32_t __eeprom_workarea_end__;
 
-#define EEPROM_SIZE 128
+#    define EEPROM_SIZE 128
 
 static uint32_t flashend = 0;
 
-void eeprom_initialize(void)
-{
-       const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__);
+void eeprom_initialize(void) {
+    const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__);
 
-       do {
-               if (*p++ == 0xFFFF) {
-                       flashend = (uint32_t)(p - 2);
-                       return;
-               }
-       } while (p < (uint16_t *)SYMVAL(__eeprom_workarea_end__));
-       flashend = (uint32_t)((uint16_t *)SYMVAL(__eeprom_workarea_end__) - 1);
+    do {
+        if (*p++ == 0xFFFF) {
+            flashend = (uint32_t)(p - 2);
+            return;
+        }
+    } while (p < (uint16_t *)SYMVAL(__eeprom_workarea_end__));
+    flashend = (uint32_t)((uint16_t *)SYMVAL(__eeprom_workarea_end__) - 1);
 }
 
-uint8_t eeprom_read_byte(const uint8_t *addr)
-{
-       uint32_t offset = (uint32_t)addr;
-       const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__);
-       const uint16_t *end = (const uint16_t *)((uint32_t)flashend);
-       uint16_t val;
-       uint8_t data=0xFF;
-
-       if (!end) {
-               eeprom_initialize();
-               end = (const uint16_t *)((uint32_t)flashend);
-       }
-       if (offset < EEPROM_SIZE) {
-               while (p <= end) {
-                       val = *p++;
-                       if ((val & 255) == offset) data = val >> 8;
-               }
-       }
-       return data;
-}
-
-static void flash_write(const uint16_t *code, uint32_t addr, uint32_t data)
-{
-       // with great power comes great responsibility....
-       uint32_t stat;
-       *(uint32_t *)&(FTFA->FCCOB3) = 0x06000000 | (addr & 0x00FFFFFC);
-       *(uint32_t *)&(FTFA->FCCOB7) = data;
-       __disable_irq();
-       (*((void (*)(volatile uint8_t *))((uint32_t)code | 1)))(&(FTFA->FSTAT));
-       __enable_irq();
-       stat = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR|FTFA_FSTAT_ACCERR|FTFA_FSTAT_FPVIOL);
-       if (stat) {
-               FTFA->FSTAT = stat;
-       }
-       MCM->PLACR |= MCM_PLACR_CFCC;
-}
-
-void eeprom_write_byte(uint8_t *addr, uint8_t data)
-{
-       uint32_t offset = (uint32_t)addr;
-       const uint16_t *p, *end = (const uint16_t *)((uint32_t)flashend);
-       uint32_t i, val, flashaddr;
-       uint16_t do_flash_cmd[] = {
-               0x2380, 0x7003, 0x7803, 0xb25b, 0x2b00, 0xdafb, 0x4770};
-       uint8_t buf[EEPROM_SIZE];
-
-       if (offset >= EEPROM_SIZE) return;
-       if (!end) {
-               eeprom_initialize();
-               end = (const uint16_t *)((uint32_t)flashend);
-       }
-       if (++end < (uint16_t *)SYMVAL(__eeprom_workarea_end__)) {
-               val = (data << 8) | offset;
-               flashaddr = (uint32_t)end;
-               flashend = flashaddr;
-               if ((flashaddr & 2) == 0) {
-                       val |= 0xFFFF0000;
-               } else {
-                       val <<= 16;
-                       val |= 0x0000FFFF;
-               }
-               flash_write(do_flash_cmd, flashaddr, val);
-       } else {
-               for (i=0; i < EEPROM_SIZE; i++) {
-                       buf[i] = 0xFF;
-               }
-               val = 0;
-               for (p = (uint16_t *)SYMVAL(__eeprom_workarea_start__); p < (uint16_t *)SYMVAL(__eeprom_workarea_end__); p++) {
-                       val = *p;
-                       if ((val & 255) < EEPROM_SIZE) {
-                               buf[val & 255] = val >> 8;
-                       }
-               }
-               buf[offset] = data;
-               for (flashaddr=(uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__); flashaddr < (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_end__); flashaddr += 1024) {
-                       *(uint32_t *)&(FTFA->FCCOB3) = 0x09000000 | flashaddr;
-                       __disable_irq();
-                       (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFA->FSTAT));
-                       __enable_irq();
-                       val = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR|FTFA_FSTAT_ACCERR|FTFA_FSTAT_FPVIOL);;
-                       if (val) FTFA->FSTAT = val;
-                       MCM->PLACR |= MCM_PLACR_CFCC;
-               }
-               flashaddr=(uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__);
-               for (i=0; i < EEPROM_SIZE; i++) {
-                       if (buf[i] == 0xFF) continue;
-                       if ((flashaddr & 2) == 0) {
-                               val = (buf[i] << 8) | i;
-                       } else {
-                               val = val | (buf[i] << 24) | (i << 16);
-                               flash_write(do_flash_cmd, flashaddr, val);
-                       }
-                       flashaddr += 2;
-               }
-               flashend = flashaddr;
-               if ((flashaddr & 2)) {
-                       val |= 0xFFFF0000;
-                       flash_write(do_flash_cmd, flashaddr, val);
-               }
-       }
+uint8_t eeprom_read_byte(const uint8_t *addr) {
+    uint32_t        offset = (uint32_t)addr;
+    const uint16_t *p      = (uint16_t *)SYMVAL(__eeprom_workarea_start__);
+    const uint16_t *end    = (const uint16_t *)((uint32_t)flashend);
+    uint16_t        val;
+    uint8_t         data = 0xFF;
+
+    if (!end) {
+        eeprom_initialize();
+        end = (const uint16_t *)((uint32_t)flashend);
+    }
+    if (offset < EEPROM_SIZE) {
+        while (p <= end) {
+            val = *p++;
+            if ((val & 255) == offset) data = val >> 8;
+        }
+    }
+    return data;
+}
+
+static void flash_write(const uint16_t *code, uint32_t addr, uint32_t data) {
+    // with great power comes great responsibility....
+    uint32_t stat;
+    *(uint32_t *)&(FTFA->FCCOB3) = 0x06000000 | (addr & 0x00FFFFFC);
+    *(uint32_t *)&(FTFA->FCCOB7) = data;
+    __disable_irq();
+    (*((void (*)(volatile uint8_t *))((uint32_t)code | 1)))(&(FTFA->FSTAT));
+    __enable_irq();
+    stat = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR | FTFA_FSTAT_ACCERR | FTFA_FSTAT_FPVIOL);
+    if (stat) {
+        FTFA->FSTAT = stat;
+    }
+    MCM->PLACR |= MCM_PLACR_CFCC;
+}
+
+void eeprom_write_byte(uint8_t *addr, uint8_t data) {
+    uint32_t        offset = (uint32_t)addr;
+    const uint16_t *p, *end = (const uint16_t *)((uint32_t)flashend);
+    uint32_t        i, val, flashaddr;
+    uint16_t        do_flash_cmd[] = {0x2380, 0x7003, 0x7803, 0xb25b, 0x2b00, 0xdafb, 0x4770};
+    uint8_t         buf[EEPROM_SIZE];
+
+    if (offset >= EEPROM_SIZE) return;
+    if (!end) {
+        eeprom_initialize();
+        end = (const uint16_t *)((uint32_t)flashend);
+    }
+    if (++end < (uint16_t *)SYMVAL(__eeprom_workarea_end__)) {
+        val       = (data << 8) | offset;
+        flashaddr = (uint32_t)end;
+        flashend  = flashaddr;
+        if ((flashaddr & 2) == 0) {
+            val |= 0xFFFF0000;
+        } else {
+            val <<= 16;
+            val |= 0x0000FFFF;
+        }
+        flash_write(do_flash_cmd, flashaddr, val);
+    } else {
+        for (i = 0; i < EEPROM_SIZE; i++) {
+            buf[i] = 0xFF;
+        }
+        val = 0;
+        for (p = (uint16_t *)SYMVAL(__eeprom_workarea_start__); p < (uint16_t *)SYMVAL(__eeprom_workarea_end__); p++) {
+            val = *p;
+            if ((val & 255) < EEPROM_SIZE) {
+                buf[val & 255] = val >> 8;
+            }
+        }
+        buf[offset] = data;
+        for (flashaddr = (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__); flashaddr < (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_end__); flashaddr += 1024) {
+            *(uint32_t *)&(FTFA->FCCOB3) = 0x09000000 | flashaddr;
+            __disable_irq();
+            (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFA->FSTAT));
+            __enable_irq();
+            val = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR | FTFA_FSTAT_ACCERR | FTFA_FSTAT_FPVIOL);
+            ;
+            if (val) FTFA->FSTAT = val;
+            MCM->PLACR |= MCM_PLACR_CFCC;
+        }
+        flashaddr = (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__);
+        for (i = 0; i < EEPROM_SIZE; i++) {
+            if (buf[i] == 0xFF) continue;
+            if ((flashaddr & 2) == 0) {
+                val = (buf[i] << 8) | i;
+            } else {
+                val = val | (buf[i] << 24) | (i << 16);
+                flash_write(do_flash_cmd, flashaddr, val);
+            }
+            flashaddr += 2;
+        }
+        flashend = flashaddr;
+        if ((flashaddr & 2)) {
+            val |= 0xFFFF0000;
+            flash_write(do_flash_cmd, flashaddr, val);
+        }
+    }
 }
 
 /*
@@ -492,141 +472,127 @@ void do_flash_cmd(volatile uint8_t *fstat)
    c:  4770            bx      lr
 */
 
-
-uint16_t eeprom_read_word(const uint16_t *addr)
-{
-       const uint8_t *p = (const uint8_t *)addr;
-       return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8);
+uint16_t eeprom_read_word(const uint16_t *addr) {
+    const uint8_t *p = (const uint8_t *)addr;
+    return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8);
 }
 
-uint32_t eeprom_read_dword(const uint32_t *addr)
-{
-       const uint8_t *p = (const uint8_t *)addr;
-       return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8)
-               | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24);
+uint32_t eeprom_read_dword(const uint32_t *addr) {
+    const uint8_t *p = (const uint8_t *)addr;
+    return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24);
 }
 
-void eeprom_read_block(void *buf, const void *addr, uint32_t len)
-{
-       const uint8_t *p = (const uint8_t *)addr;
-       uint8_t *dest = (uint8_t *)buf;
-       while (len--) {
-               *dest++ = eeprom_read_byte(p++);
-       }
+void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
+    const uint8_t *p    = (const uint8_t *)addr;
+    uint8_t *      dest = (uint8_t *)buf;
+    while (len--) {
+        *dest++ = eeprom_read_byte(p++);
+    }
 }
 
-int eeprom_is_ready(void)
-{
-       return 1;
-}
+int eeprom_is_ready(void) { return 1; }
 
-void eeprom_write_word(uint16_t *addr, uint16_t value)
-{
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p, value >> 8);
+void eeprom_write_word(uint16_t *addr, uint16_t value) {
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p, value >> 8);
 }
 
-void eeprom_write_dword(uint32_t *addr, uint32_t value)
-{
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p++, value >> 8);
-       eeprom_write_byte(p++, value >> 16);
-       eeprom_write_byte(p, value >> 24);
+void eeprom_write_dword(uint32_t *addr, uint32_t value) {
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p++, value >> 8);
+    eeprom_write_byte(p++, value >> 16);
+    eeprom_write_byte(p, value >> 24);
 }
 
-void eeprom_write_block(const void *buf, void *addr, uint32_t len)
-{
-       uint8_t *p = (uint8_t *)addr;
-       const uint8_t *src = (const uint8_t *)buf;
-       while (len--) {
-               eeprom_write_byte(p++, *src++);
-       }
+void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
+    uint8_t *      p   = (uint8_t *)addr;
+    const uint8_t *src = (const uint8_t *)buf;
+    while (len--) {
+        eeprom_write_byte(p++, *src++);
+    }
 }
 
 #else
 // No EEPROM supported, so emulate it
 
-#define EEPROM_SIZE 32
+#    define EEPROM_SIZE 32
 static uint8_t buffer[EEPROM_SIZE];
 
 uint8_t eeprom_read_byte(const uint8_t *addr) {
-       uint32_t offset = (uint32_t)addr;
-       return buffer[offset];
+    uint32_t offset = (uint32_t)addr;
+    return buffer[offset];
 }
 
 void eeprom_write_byte(uint8_t *addr, uint8_t value) {
-       uint32_t offset = (uint32_t)addr;
-       buffer[offset] = value;
+    uint32_t offset = (uint32_t)addr;
+    buffer[offset]  = value;
 }
 
 uint16_t eeprom_read_word(const uint16_t *addr) {
-       const uint8_t *p = (const uint8_t *)addr;
-       return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8);
+    const uint8_t *p = (const uint8_t *)addr;
+    return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8);
 }
 
 uint32_t eeprom_read_dword(const uint32_t *addr) {
-       const uint8_t *p = (const uint8_t *)addr;
-       return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8)
-               | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24);
+    const uint8_t *p = (const uint8_t *)addr;
+    return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24);
 }
 
 void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
-       const uint8_t *p = (const uint8_t *)addr;
-       uint8_t *dest = (uint8_t *)buf;
-       while (len--) {
-               *dest++ = eeprom_read_byte(p++);
-       }
+    const uint8_t *p    = (const uint8_t *)addr;
+    uint8_t *      dest = (uint8_t *)buf;
+    while (len--) {
+        *dest++ = eeprom_read_byte(p++);
+    }
 }
 
 void eeprom_write_word(uint16_t *addr, uint16_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p, value >> 8);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p, value >> 8);
 }
 
 void eeprom_write_dword(uint32_t *addr, uint32_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p++, value >> 8);
-       eeprom_write_byte(p++, value >> 16);
-       eeprom_write_byte(p, value >> 24);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p++, value >> 8);
+    eeprom_write_byte(p++, value >> 16);
+    eeprom_write_byte(p, value >> 24);
 }
 
 void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
-       uint8_t *p = (uint8_t *)addr;
-       const uint8_t *src = (const uint8_t *)buf;
-       while (len--) {
-               eeprom_write_byte(p++, *src++);
-       }
+    uint8_t *      p   = (uint8_t *)addr;
+    const uint8_t *src = (const uint8_t *)buf;
+    while (len--) {
+        eeprom_write_byte(p++, *src++);
+    }
 }
 
 #endif /* chip selection */
 // The update functions just calls write for now, but could probably be optimized
 
-void eeprom_update_byte(uint8_t *addr, uint8_t value) {
-       eeprom_write_byte(addr, value);
-}
+void eeprom_update_byte(uint8_t *addr, uint8_t value) { eeprom_write_byte(addr, value); }
 
 void eeprom_update_word(uint16_t *addr, uint16_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p, value >> 8);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p, value >> 8);
 }
 
 void eeprom_update_dword(uint32_t *addr, uint32_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p++, value >> 8);
-       eeprom_write_byte(p++, value >> 16);
-       eeprom_write_byte(p, value >> 24);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p++, value >> 8);
+    eeprom_write_byte(p++, value >> 16);
+    eeprom_write_byte(p, value >> 24);
 }
 
 void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
-       uint8_t *p = (uint8_t *)addr;
-       const uint8_t *src = (const uint8_t *)buf;
-       while (len--) {
-               eeprom_write_byte(p++, *src++);
-       }
+    uint8_t *      p   = (uint8_t *)addr;
+    const uint8_t *src = (const uint8_t *)buf;
+    while (len--) {
+        eeprom_write_byte(p++, *src++);
+    }
 }
old mode 100755 (executable)
new mode 100644 (file)
index 832bf39..e166fc5
  */
 
 #if defined(EEPROM_EMU_STM32F303xC)
-    #define STM32F303xC
-    #include "stm32f3xx.h"
+#    define STM32F303xC
+#    include "stm32f3xx.h"
 #elif defined(EEPROM_EMU_STM32F103xB)
-    #define STM32F103xB
-    #include "stm32f1xx.h"
+#    define STM32F103xB
+#    include "stm32f1xx.h"
 #elif defined(EEPROM_EMU_STM32F072xB)
-    #define STM32F072xB
-    #include "stm32f0xx.h"
+#    define STM32F072xB
+#    include "stm32f0xx.h"
 #else
-    #error "not implemented."
+#    error "not implemented."
 #endif
 
 #include "flash_stm32.h"
 
 #if defined(EEPROM_EMU_STM32F103xB)
-    #define FLASH_SR_WRPERR FLASH_SR_WRPRTERR
+#    define FLASH_SR_WRPERR FLASH_SR_WRPRTERR
 #endif
 
 /* Delay definition */
-#define EraseTimeout        ((uint32_t)0x00000FFF)
-#define ProgramTimeout      ((uint32_t)0x0000001F)
+#define EraseTimeout ((uint32_t)0x00000FFF)
+#define ProgramTimeout ((uint32_t)0x0000001F)
 
 #define ASSERT(exp) (void)((0))
 
 /**
-  * @brief  Inserts a time delay.
-  * @param  None
-  * @retval None
-  */
-static void delay(void)
-{
+ * @brief  Inserts a time delay.
+ * @param  None
+ * @retval None
+ */
+static void delay(void) {
     __IO uint32_t i = 0;
-    for(i = 0xFF; i != 0; i--) { }
+    for (i = 0xFF; i != 0; i--) {
+    }
 }
 
 /**
-  * @brief  Returns the FLASH Status.
-  * @param  None
-  * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
-  *   FLASH_ERROR_WRP or FLASH_COMPLETE
-  */
-FLASH_Status FLASH_GetStatus(void)
-{
-    if ((FLASH->SR & FLASH_SR_BSY) == FLASH_SR_BSY)
-        return FLASH_BUSY;
+ * @brief  Returns the FLASH Status.
+ * @param  None
+ * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
+ *   FLASH_ERROR_WRP or FLASH_COMPLETE
+ */
+FLASH_Status FLASH_GetStatus(void) {
+    if ((FLASH->SR & FLASH_SR_BSY) == FLASH_SR_BSY) return FLASH_BUSY;
 
-    if ((FLASH->SR & FLASH_SR_PGERR) != 0)
-        return FLASH_ERROR_PG;
+    if ((FLASH->SR & FLASH_SR_PGERR) != 0) return FLASH_ERROR_PG;
 
-    if ((FLASH->SR & FLASH_SR_WRPERR) != 0 )
-        return FLASH_ERROR_WRP;
+    if ((FLASH->SR & FLASH_SR_WRPERR) != 0) return FLASH_ERROR_WRP;
 
-    if ((FLASH->SR & FLASH_OBR_OPTERR) != 0 )
-        return FLASH_ERROR_OPT;
+    if ((FLASH->SR & FLASH_OBR_OPTERR) != 0) return FLASH_ERROR_OPT;
 
     return FLASH_COMPLETE;
 }
 
 /**
-  * @brief  Waits for a Flash operation to complete or a TIMEOUT to occur.
-  * @param  Timeout: FLASH progamming Timeout
-  * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
-  *   FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
-  */
-FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout)
-{
+ * @brief  Waits for a Flash operation to complete or a TIMEOUT to occur.
+ * @param  Timeout: FLASH progamming Timeout
+ * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
+ *   FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
+ */
+FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) {
     FLASH_Status status;
 
     /* Check for the Flash Status */
     status = FLASH_GetStatus();
     /* Wait for a Flash operation to complete or a TIMEOUT to occur */
-    while ((status == FLASH_BUSY) && (Timeout != 0x00))
-    {
+    while ((status == FLASH_BUSY) && (Timeout != 0x00)) {
         delay();
         status = FLASH_GetStatus();
         Timeout--;
     }
-    if (Timeout == 0)
-        status = FLASH_TIMEOUT;
+    if (Timeout == 0) status = FLASH_TIMEOUT;
     /* Return the operation status */
     return status;
 }
 
 /**
-  * @brief  Erases a specified FLASH page.
-  * @param  Page_Address: The page address to be erased.
-  * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
-  *   FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
-  */
-FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
-{
+ * @brief  Erases a specified FLASH page.
+ * @param  Page_Address: The page address to be erased.
+ * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
+ *   FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
+ */
+FLASH_Status FLASH_ErasePage(uint32_t Page_Address) {
     FLASH_Status status = FLASH_COMPLETE;
     /* Check the parameters */
     ASSERT(IS_FLASH_ADDRESS(Page_Address));
     /* Wait for last operation to be completed */
     status = FLASH_WaitForLastOperation(EraseTimeout);
 
-    if(status == FLASH_COMPLETE)
-    {
+    if (status == FLASH_COMPLETE) {
         /* if the previous operation is completed, proceed to erase the page */
         FLASH->CR |= FLASH_CR_PER;
         FLASH->AR = Page_Address;
@@ -123,8 +113,7 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
 
         /* Wait for last operation to be completed */
         status = FLASH_WaitForLastOperation(EraseTimeout);
-        if(status != FLASH_TIMEOUT)
-        {
+        if (status != FLASH_TIMEOUT) {
             /* if the erase operation is completed, disable the PER Bit */
             FLASH->CR &= ~FLASH_CR_PER;
         }
@@ -135,29 +124,25 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
 }
 
 /**
-  * @brief  Programs a half word at a specified address.
-  * @param  Address: specifies the address to be programmed.
-  * @param  Data: specifies the data to be programmed.
-  * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
-  *   FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
-  */
-FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
-{
+ * @brief  Programs a half word at a specified address.
+ * @param  Address: specifies the address to be programmed.
+ * @param  Data: specifies the data to be programmed.
+ * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
+ *   FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
+ */
+FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) {
     FLASH_Status status = FLASH_BAD_ADDRESS;
 
-    if (IS_FLASH_ADDRESS(Address))
-    {
+    if (IS_FLASH_ADDRESS(Address)) {
         /* Wait for last operation to be completed */
         status = FLASH_WaitForLastOperation(ProgramTimeout);
-        if(status == FLASH_COMPLETE)
-        {
+        if (status == FLASH_COMPLETE) {
             /* if the previous operation is completed, proceed to program the new data */
             FLASH->CR |= FLASH_CR_PG;
             *(__IO uint16_t*)Address = Data;
             /* Wait for last operation to be completed */
             status = FLASH_WaitForLastOperation(ProgramTimeout);
-            if(status != FLASH_TIMEOUT)
-            {
+            if (status != FLASH_TIMEOUT) {
                 /* if the program operation is completed, disable the PG Bit */
                 FLASH->CR &= ~FLASH_CR_PG;
             }
@@ -168,39 +153,36 @@ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
 }
 
 /**
-  * @brief  Unlocks the FLASH Program Erase Controller.
-  * @param  None
-  * @retval None
-  */
-void FLASH_Unlock(void)
-{
+ * @brief  Unlocks the FLASH Program Erase Controller.
+ * @param  None
+ * @retval None
+ */
+void FLASH_Unlock(void) {
     /* Authorize the FPEC Access */
     FLASH->KEYR = FLASH_KEY1;
     FLASH->KEYR = FLASH_KEY2;
 }
 
 /**
-  * @brief  Locks the FLASH Program Erase Controller.
-  * @param  None
-  * @retval None
-  */
-void FLASH_Lock(void)
-{
+ * @brief  Locks the FLASH Program Erase Controller.
+ * @param  None
+ * @retval None
+ */
+void FLASH_Lock(void) {
     /* Set the Lock Bit to lock the FPEC and the FCR */
     FLASH->CR |= FLASH_CR_LOCK;
 }
 
 /**
-  * @brief  Clears the FLASH's pending flags.
-  * @param  FLASH_FLAG: specifies the FLASH flags to clear.
-  *   This parameter can be any combination of the following values:
-  *     @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag
-  *     @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
-  *     @arg FLASH_FLAG_EOP: FLASH End of Programming flag
-  * @retval None
-  */
-void FLASH_ClearFlag(uint32_t FLASH_FLAG)
-{
+ * @brief  Clears the FLASH's pending flags.
+ * @param  FLASH_FLAG: specifies the FLASH flags to clear.
+ *   This parameter can be any combination of the following values:
+ *     @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag
+ *     @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
+ *     @arg FLASH_FLAG_EOP: FLASH End of Programming flag
+ * @retval None
+ */
+void FLASH_ClearFlag(uint32_t FLASH_FLAG) {
     /* Clear the flags */
     FLASH->SR = FLASH_FLAG;
 }
old mode 100755 (executable)
new mode 100644 (file)
index 3c99cc5..33ab786
@@ -10,7 +10,7 @@
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  *
- * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and 
+ * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and
  * https://github.com/leaflabs/libmaple
  *
  * Modifications for QMK and STM32F303 by Yiancar
 #define __FLASH_STM32_H
 
 #ifdef __cplusplus
- extern "C" {
+extern "C" {
 #endif
 
 #include "ch.h"
 #include "hal.h"
 
-typedef enum
-    {
-    FLASH_BUSY = 1,
-    FLASH_ERROR_PG,
-    FLASH_ERROR_WRP,
-    FLASH_ERROR_OPT,
-    FLASH_COMPLETE,
-    FLASH_TIMEOUT,
-    FLASH_BAD_ADDRESS
-    } FLASH_Status;
+typedef enum { FLASH_BUSY = 1, FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_ERROR_OPT, FLASH_COMPLETE, FLASH_TIMEOUT, FLASH_BAD_ADDRESS } FLASH_Status;
 
 #define IS_FLASH_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x0807FFFF))
 
index 72e3d4f8c4248d3174922ee596bdbf8447565f0e..dbd059448c17c1be90b133b5f9f1ff8a2aaf7a1a 100644 (file)
@@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 #include "printf.h"
 
-typedef void (*putcf) (void*,char);
+typedef void (*putcf)(void*, char);
 static putcf stdout_putf;
 static void* stdout_putp;
 
@@ -35,206 +35,185 @@ static void* stdout_putp;
 
 #ifdef PRINTF_LONG_SUPPORT
 
-static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf)
-    {
-    int n=0;
-    unsigned int d=1;
-    while (num/d >= base)
-        d*=base;         
-    while (d!=0) {
+static void uli2a(unsigned long int num, unsigned int base, int uc, char* bf) {
+    int          n = 0;
+    unsigned int d = 1;
+    while (num / d >= base) d *= base;
+    while (d != 0) {
         int dgt = num / d;
-        num%=d;
-        d/=base;
-        if (n || dgt>0|| d==0) {
-            *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
+        num %= d;
+        d /= base;
+        if (n || dgt > 0 || d == 0) {
+            *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10);
             ++n;
-            }
         }
-    *bf=0;
     }
+    *bf = 0;
+}
 
-static void li2a (long num, char * bf)
-    {
-    if (num<0) {
-        num=-num;
+static void li2a(long num, char* bf) {
+    if (num < 0) {
+        num   = -num;
         *bf++ = '-';
-        }
-    uli2a(num,10,0,bf);
     }
+    uli2a(num, 10, 0, bf);
+}
 
 #endif
 
-static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
-    {
-    int n=0;
-    unsigned int d=1;
-    while (num/d >= base)
-        d*=base;        
-    while (d!=0) {
+static void ui2a(unsigned int num, unsigned int base, int uc, char* bf) {
+    int          n = 0;
+    unsigned int d = 1;
+    while (num / d >= base) d *= base;
+    while (d != 0) {
         int dgt = num / d;
-        num%= d;
-        d/=base;
-        if (n || dgt>0 || d==0) {
-            *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
+        num %= d;
+        d /= base;
+        if (n || dgt > 0 || d == 0) {
+            *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10);
             ++n;
-            }
         }
-    *bf=0;
     }
+    *bf = 0;
+}
 
-static void i2a (int num, char * bf)
-    {
-    if (num<0) {
-        num=-num;
+static void i2a(int num, char* bf) {
+    if (num < 0) {
+        num   = -num;
         *bf++ = '-';
-        }
-    ui2a(num,10,0,bf);
     }
-
-static int a2d(char ch)
-    {
-    if (ch>='0' && ch<='9') 
-        return ch-'0';
-    else if (ch>='a' && ch<='f')
-        return ch-'a'+10;
-    else if (ch>='A' && ch<='F')
-        return ch-'A'+10;
-    else return -1;
+    ui2a(num, 10, 0, bf);
+}
+
+static int a2d(char ch) {
+    if (ch >= '0' && ch <= '9')
+        return ch - '0';
+    else if (ch >= 'a' && ch <= 'f')
+        return ch - 'a' + 10;
+    else if (ch >= 'A' && ch <= 'F')
+        return ch - 'A' + 10;
+    else
+        return -1;
+}
+
+static char a2i(char ch, char** src, int base, int* nump) {
+    char* p   = *src;
+    int   num = 0;
+    int   digit;
+    while ((digit = a2d(ch)) >= 0) {
+        if (digit > base) break;
+        num = num * base + digit;
+        ch  = *p++;
     }
-
-static char a2i(char ch, char** src,int base,int* nump)
-    {
-    char* p= *src;
-    int num=0;
-    int digit;
-    while ((digit=a2d(ch))>=0) {
-        if (digit>base) break;
-        num=num*base+digit;
-        ch=*p++;
-        }
-    *src=p;
-    *nump=num;
+    *src  = p;
+    *nump = num;
     return ch;
-    }
-
-static void putchw(void* putp,putcf putf,int n, char z, char* bf)
-    {
-    char fc=z? '0' : ' ';
-    char ch;
-    char* p=bf;
-    while (*p++ && n > 0)
-        n--;
-    while (n-- > 0) 
-        putf(putp,fc);
-    while ((ch= *bf++))
-        putf(putp,ch);
-    }
-
-void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
-    {
+}
+
+static void putchw(void* putp, putcf putf, int n, char z, char* bf) {
+    char  fc = z ? '0' : ' ';
+    char  ch;
+    char* p = bf;
+    while (*p++ && n > 0) n--;
+    while (n-- > 0) putf(putp, fc);
+    while ((ch = *bf++)) putf(putp, ch);
+}
+
+void tfp_format(void* putp, putcf putf, char* fmt, va_list va) {
     char bf[12];
-    
-    char ch;
 
+    char ch;
 
-    while ((ch=*(fmt++))) {
-        if (ch!='%') 
-            putf(putp,ch);
+    while ((ch = *(fmt++))) {
+        if (ch != '%')
+            putf(putp, ch);
         else {
-            char lz=0;
-#ifdef  PRINTF_LONG_SUPPORT
-            char lng=0;
+            char lz = 0;
+#ifdef PRINTF_LONG_SUPPORT
+            char lng = 0;
 #endif
-            int w=0;
-            ch=*(fmt++);
-            if (ch=='0') {
-                ch=*(fmt++);
-                lz=1;
-                }
-            if (ch>='0' && ch<='9') {
-                ch=a2i(ch,&fmt,10,&w);
-                }
-#ifdef  PRINTF_LONG_SUPPORT
-            if (ch=='l') {
-                ch=*(fmt++);
-                lng=1;
+            int w = 0;
+            ch    = *(fmt++);
+            if (ch == '0') {
+                ch = *(fmt++);
+                lz = 1;
+            }
+            if (ch >= '0' && ch <= '9') {
+                ch = a2i(ch, &fmt, 10, &w);
+            }
+#ifdef PRINTF_LONG_SUPPORT
+            if (ch == 'l') {
+                ch  = *(fmt++);
+                lng = 1;
             }
 #endif
             switch (ch) {
-                case 0: 
+                case 0:
                     goto abort;
-                case 'u' : {
-#ifdef  PRINTF_LONG_SUPPORT
+                case 'u': {
+#ifdef PRINTF_LONG_SUPPORT
                     if (lng)
-                        uli2a(va_arg(va, unsigned long int),10,0,bf);
+                        uli2a(va_arg(va, unsigned long int), 10, 0, bf);
                     else
 #endif
-                    ui2a(va_arg(va, unsigned int),10,0,bf);
-                    putchw(putp,putf,w,lz,bf);
+                        ui2a(va_arg(va, unsigned int), 10, 0, bf);
+                    putchw(putp, putf, w, lz, bf);
                     break;
-                    }
-                case 'd' :  {
-#ifdef  PRINTF_LONG_SUPPORT
+                }
+                case 'd': {
+#ifdef PRINTF_LONG_SUPPORT
                     if (lng)
-                        li2a(va_arg(va, unsigned long int),bf);
+                        li2a(va_arg(va, unsigned long int), bf);
                     else
 #endif
-                    i2a(va_arg(va, int),bf);
-                    putchw(putp,putf,w,lz,bf);
+                        i2a(va_arg(va, int), bf);
+                    putchw(putp, putf, w, lz, bf);
                     break;
-                    }
-                case 'x': case 'X' : 
-#ifdef  PRINTF_LONG_SUPPORT
+                }
+                case 'x':
+                case 'X':
+#ifdef PRINTF_LONG_SUPPORT
                     if (lng)
-                        uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf);
+                        uli2a(va_arg(va, unsigned long int), 16, (ch == 'X'), bf);
                     else
 #endif
-                    ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf);
-                    putchw(putp,putf,w,lz,bf);
+                        ui2a(va_arg(va, unsigned int), 16, (ch == 'X'), bf);
+                    putchw(putp, putf, w, lz, bf);
                     break;
-                case 'c' : 
-                    putf(putp,(char)(va_arg(va, int)));
+                case 'c':
+                    putf(putp, (char)(va_arg(va, int)));
                     break;
-                case 's' : 
-                    putchw(putp,putf,w,0,va_arg(va, char*));
+                case 's':
+                    putchw(putp, putf, w, 0, va_arg(va, char*));
                     break;
-                case '%' :
-                    putf(putp,ch);
+                case '%':
+                    putf(putp, ch);
                 default:
                     break;
-                }
             }
         }
-    abort:;
     }
+abort:;
+}
 
+void init_printf(void* putp, void (*putf)(void*, char)) {
+    stdout_putf = putf;
+    stdout_putp = putp;
+}
 
-void init_printf(void* putp,void (*putf) (void*,char))
-    {
-    stdout_putf=putf;
-    stdout_putp=putp;
-    }
-
-void tfp_printf(char *fmt, ...)
-    {
+void tfp_printf(char* fmt, ...) {
     va_list va;
-    va_start(va,fmt);
-    tfp_format(stdout_putp,stdout_putf,fmt,va);
+    va_start(va, fmt);
+    tfp_format(stdout_putp, stdout_putf, fmt, va);
     va_end(va);
-    }
-
-static void putcp(void* p,char c)
-    {
-    *(*((char**)p))++ = c;
-    }
+}
 
+static void putcp(void* p, char c) { *(*((char**)p))++ = c; }
 
-
-void tfp_sprintf(char* s,char *fmt, ...)
-    {
+void tfp_sprintf(char* s, char* fmt, ...) {
     va_list va;
-    va_start(va,fmt);
-    tfp_format(&s,putcp,fmt,va);
-    putcp(&s,0);
+    va_start(va, fmt);
+    tfp_format(&s, putcp, fmt, va);
+    putcp(&s, 0);
     va_end(va);
-    }
+}
index 678a100c6e00b894cd9d1b992f7119d16dd35bff..2cdf55ed904535acfe0c7beaede94281883f8a65 100644 (file)
@@ -15,7 +15,7 @@ version 2.1 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 See the GNU Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
@@ -24,35 +24,35 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 This library is realy just two files: 'printf.h' and 'printf.c'.
 
-They provide a simple and small (+200 loc) printf functionality to 
+They provide a simple and small (+200 loc) printf functionality to
 be used in embedded systems.
 
-I've found them so usefull in debugging that I do not bother with a 
+I've found them so usefull in debugging that I do not bother with a
 debugger at all.
 
-They are distributed in source form, so to use them, just compile them 
-into your project. 
+They are distributed in source form, so to use them, just compile them
+into your project.
 
-Two printf variants are provided: printf and sprintf. 
+Two printf variants are provided: printf and sprintf.
 
 The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
 
 Zero padding and field width are also supported.
 
-If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the 
+If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
 long specifier is also
 supported. Note that this will pull in some long math routines (pun intended!)
 and thus make your executable noticably longer.
 
-The memory foot print of course depends on the target cpu, compiler and 
-compiler options, but a rough guestimate (based on a H8S target) is about 
-1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space. 
-Not too bad. Your milage may vary. By hacking the source code you can 
-get rid of some hunred bytes, I'm sure, but personally I feel the balance of 
+The memory foot print of course depends on the target cpu, compiler and
+compiler options, but a rough guestimate (based on a H8S target) is about
+1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
+Not too bad. Your milage may vary. By hacking the source code you can
+get rid of some hunred bytes, I'm sure, but personally I feel the balance of
 functionality and flexibility versus  code size is close to optimal for
 many embedded systems.
 
-To use the printf you need to supply your own character output function, 
+To use the printf you need to supply your own character output function,
 something like :
 
     void putc ( void* p, char c)
@@ -61,25 +61,25 @@ something like :
         SERIAL_PORT_TX_REGISTER = c;
         }
 
-Before you can call printf you need to initialize it to use your 
+Before you can call printf you need to initialize it to use your
 character output function with something like:
 
     init_printf(NULL,putc);
 
-Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc', 
-the NULL (or any pointer) you pass into the 'init_printf' will eventually be 
-passed to your 'putc' routine. This allows you to pass some storage space (or 
-anything realy) to the character output function, if necessary. 
-This is not often needed but it was implemented like that because it made 
+Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
+the NULL (or any pointer) you pass into the 'init_printf' will eventually be
+passed to your 'putc' routine. This allows you to pass some storage space (or
+anything realy) to the character output function, if necessary.
+This is not often needed but it was implemented like that because it made
 implementing the sprintf function so neat (look at the source code).
 
-The code is re-entrant, except for the 'init_printf' function, so it 
-is safe to call it from interupts too, although this may result in mixed output. 
+The code is re-entrant, except for the 'init_printf' function, so it
+is safe to call it from interupts too, although this may result in mixed output.
 If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
 
-The printf and sprintf functions are actually macros that translate to 
+The printf and sprintf functions are actually macros that translate to
 'tfp_printf' and 'tfp_sprintf'. This makes it possible
-to use them along with 'stdio.h' printf's in a single source file. 
+to use them along with 'stdio.h' printf's in a single source file.
 You just need to undef the names before you include the 'stdio.h'.
 Note that these are not function like macros, so if you have variables
 or struct members with these names, things will explode in your face.
@@ -92,20 +92,19 @@ For further details see source code.
 regs Kusti, 23.10.2004
 */
 
-
 #ifndef __TFP_PRINTF__
 #define __TFP_PRINTF__
 
 #include <stdarg.h>
 
-void init_printf(void* putp,void (*putf) (void*,char));
+void init_printf(void* putp, void (*putf)(void*, char));
 
-void tfp_printf(char *fmt, ...);
-void tfp_sprintf(char* s,char *fmt, ...);
+void tfp_printf(charfmt, ...);
+void tfp_sprintf(char* s, char* fmt, ...);
 
-void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va);
+void tfp_format(void* putp, void (*putf)(void*, char), char* fmt, va_list va);
 
-#define printf tfp_printf 
-#define sprintf tfp_sprintf 
+#define printf tfp_printf
+#define sprintf tfp_sprintf
 
 #endif
index 4c35cfcbacf7d80d887b0d5ee174c1a205475c4e..df1a1b5fcd16d46c69737d16d70ca3a56529a9f3 100644 (file)
 #if defined(KL2x) || defined(K20x)
 
 /* Use Low Power Timer (LPTMR) */
-#define TIMER_INTERRUPT_VECTOR KINETIS_LPTMR0_IRQ_VECTOR
-#define RESET_COUNTER LPTMR0->CSR |= LPTMRx_CSR_TCF
+#    define TIMER_INTERRUPT_VECTOR KINETIS_LPTMR0_IRQ_VECTOR
+#    define RESET_COUNTER LPTMR0->CSR |= LPTMRx_CSR_TCF
 
 #elif defined(STM32F0XX)
 
 /* Use TIM14 manually */
-#define TIMER_INTERRUPT_VECTOR STM32_TIM14_HANDLER
-#define RESET_COUNTER STM32_TIM14->SR &= ~STM32_TIM_SR_UIF
+#    define TIMER_INTERRUPT_VECTOR STM32_TIM14_HANDLER
+#    define RESET_COUNTER STM32_TIM14->SR &= ~STM32_TIM_SR_UIF
 
 #endif
 
  * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
  * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
  */
-static const uint8_t breathing_table[64] = {
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
-15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
-255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
-15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
+static const uint8_t breathing_table[64] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
 /* interrupt handler */
 OSAL_IRQ_HANDLER(TIMER_INTERRUPT_VECTOR) {
     OSAL_IRQ_PROLOGUE();
 
     /* Software PWM
-    * timer:1111 1111 1111 1111
-    *       \_____/\/ \_______/____  count(0-255)
-    *          \    \______________  duration of step(4)
-    *           \__________________  index of step table(0-63)
-    */
+     * timer:1111 1111 1111 1111
+     *       \_____/\/ \_______/____  count(0-255)
+     *          \    \______________  duration of step(4)
+     *           \__________________  index of step table(0-63)
+     */
 
     // this works for cca 65536 irqs/sec
     static union {
-    uint16_t row;
-    struct {
-      uint8_t count:8;
-      uint8_t duration:2;
-      uint8_t index:6;
-    } pwm;
-    } timer = { .row = 0 };
+        uint16_t row;
+        struct {
+            uint8_t count : 8;
+            uint8_t duration : 2;
+            uint8_t index : 6;
+        } pwm;
+    } timer = {.row = 0};
 
     timer.row++;
 
     // LED on
     if (timer.pwm.count == 0) {
-        led_set(1<<USB_LED_CAPS_LOCK);
+        led_set(1 << USB_LED_CAPS_LOCK);
     }
     // LED off
     if (timer.pwm.count == breathing_table[timer.pwm.index]) {
@@ -78,19 +73,18 @@ OSAL_IRQ_HANDLER(TIMER_INTERRUPT_VECTOR) {
 
 #endif /* common parts for known platforms */
 
-
 #if defined(KL2x) || defined(K20x) /* platform selection: familiar Kinetis chips */
 
 /* LPTMR clock options */
-#define LPTMR_CLOCK_MCGIRCLK 0 /* 4MHz clock */
-#define LPTMR_CLOCK_LPO      1 /* 1kHz clock */
-#define LPTMR_CLOCK_ERCLK32K 2 /* external 32kHz crystal */
-#define LPTMR_CLOCK_OSCERCLK 3 /* output from OSC */
+#    define LPTMR_CLOCK_MCGIRCLK 0 /* 4MHz clock */
+#    define LPTMR_CLOCK_LPO 1      /* 1kHz clock */
+#    define LPTMR_CLOCK_ERCLK32K 2 /* external 32kHz crystal */
+#    define LPTMR_CLOCK_OSCERCLK 3 /* output from OSC */
 
 /* Work around inconsistencies in Freescale naming */
-#if !defined(SIM_SCGC5_LPTMR)
-#define SIM_SCGC5_LPTMR SIM_SCGC5_LPTIMER
-#endif
+#    if !defined(SIM_SCGC5_LPTMR)
+#        define SIM_SCGC5_LPTMR SIM_SCGC5_LPTIMER
+#    endif
 
 /* Initialise the timer */
 void sleep_led_init(void) {
@@ -101,52 +95,52 @@ void sleep_led_init(void) {
     /* Set the compare value */
     LPTMR0->CMR = 0;  // trigger on counter value (i.e. every time)
 
-    /* Set up clock source and prescaler */
-    /* Software PWM
   *  ______           ______           __
   * |  ON  |___OFF___|  ON  |___OFF___|   ....
   * |<-------------->|<-------------->|<- ....
   *     PWM period       PWM period
   *
   * R                interrupts/period[resolution]
   * F                periods/second[frequency]
   * R * F            interrupts/second
   */
-
-    /* === OPTION 1 === */
-    #if 0
+/* Set up clock source and prescaler */
+/* Software PWM
+ *  ______           ______           __
+ * |  ON  |___OFF___|  ON  |___OFF___|   ....
+ * |<-------------->|<-------------->|<- ....
+ *     PWM period       PWM period
+ *
+ * R                interrupts/period[resolution]
+ * F                periods/second[frequency]
+ * R * F            interrupts/second
+ */
+
+/* === OPTION 1 === */
+#    if 0
     //  1kHz LPO
     //  No prescaler => 1024 irqs/sec
     //  Note: this is too slow for a smooth breathe
     LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_LPO)|LPTMRx_PSR_PBYP;
-    #endif /* OPTION 1 */
+#    endif /* OPTION 1 */
 
-    /* === OPTION 2 === */
-    #if 1
+/* === OPTION 2 === */
+#    if 1
     //  nMHz IRC (n=4 on KL25Z, KL26Z and K20x; n=2 or 8 on KL27Z)
-    MCG->C2 |= MCG_C2_IRCS; // fast (4MHz) internal ref clock
-    #if defined(KL27) // divide the 8MHz IRC by 2, to have the same MCGIRCLK speed as others
+    MCG->C2 |= MCG_C2_IRCS;  // fast (4MHz) internal ref clock
+#        if defined(KL27)    // divide the 8MHz IRC by 2, to have the same MCGIRCLK speed as others
     MCG->MC |= MCG_MC_LIRC_DIV2_DIV2;
-    #endif /* KL27 */
-    MCG->C1 |= MCG_C1_IRCLKEN; // enable internal ref clock
+#        endif                  /* KL27 */
+    MCG->C1 |= MCG_C1_IRCLKEN;  // enable internal ref clock
     //  to work in stop mode, also MCG_C1_IREFSTEN
     //  Divide 4MHz by 2^N (N=6) => 62500 irqs/sec =>
     //  => approx F=61, R=256, duration = 4
-    LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_MCGIRCLK)|LPTMRx_PSR_PRESCALE(6);
-    #endif /* OPTION 2 */
+    LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_MCGIRCLK) | LPTMRx_PSR_PRESCALE(6);
+#    endif /* OPTION 2 */
 
-    /* === OPTION 3 === */
-    #if 0
+/* === OPTION 3 === */
+#    if 0
     //  OSC output (external crystal), usually 8MHz or 16MHz
     OSC0->CR |= OSC_CR_ERCLKEN; // enable ext ref clock
     //  to work in stop mode, also OSC_CR_EREFSTEN
     //  Divide by 2^N
     LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_OSCERCLK)|LPTMRx_PSR_PRESCALE(7);
-    #endif /* OPTION 3 */
+#    endif /* OPTION 3 */
     /* === END OPTIONS === */
 
     /* Interrupt on TCF set (compare flag) */
-    nvicEnableVector(LPTMR0_IRQn, 2); // vector, priority
+    nvicEnableVector(LPTMR0_IRQn, 2);  // vector, priority
     LPTMR0->CSR |= LPTMRx_CSR_TIE;
 }
 
@@ -205,20 +199,14 @@ void sleep_led_toggle(void) {
     STM32_TIM14->CR1 ^= STM32_TIM_CR1_CEN;
 }
 
-
 #else /* platform selection: not on familiar chips */
 
-void sleep_led_init(void) {
-}
-void sleep_led_enable(void) {
-    led_set(1<<USB_LED_CAPS_LOCK);
-}
-void sleep_led_disable(void) {
-    led_set(0);
-}
+void sleep_led_init(void) {}
+
+void sleep_led_enable(void) { led_set(1 << USB_LED_CAPS_LOCK); }
+
+void sleep_led_disable(void) { led_set(0); }
+
 void sleep_led_toggle(void) {
     // not implemented
 }
index 6027d69b78ea6355fe76a23985a6dfd03798ba73..ae1c6f53e2ec6ced25685f2a74cafd9cbdd870c4 100644 (file)
  * FIXME: needs doc
  */
 void suspend_idle(uint8_t time) {
-       // TODO: this is not used anywhere - what units is 'time' in?
-       wait_ms(time);
+    // TODO: this is not used anywhere - what units is 'time' in?
+    wait_ms(time);
 }
 
 /** \brief Run keyboard level Power down
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_power_down_user (void) { }
+__attribute__((weak)) void suspend_power_down_user(void) {}
 /** \brief Run keyboard level Power down
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_power_down_kb(void) {
-  suspend_power_down_user();
-}
+__attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); }
 
 /** \brief suspend power down
  *
  * FIXME: needs doc
  */
 void suspend_power_down(void) {
-       // TODO: figure out what to power down and how
-       // shouldn't power down TPM/FTM if we want a breathing LED
-       // also shouldn't power down USB
+    // TODO: figure out what to power down and how
+    // shouldn't power down TPM/FTM if we want a breathing LED
+    // also shouldn't power down USB
 
-  suspend_power_down_kb();
-       // on AVR, this enables the watchdog for 15ms (max), and goes to
-       // SLEEP_MODE_PWR_DOWN
+    suspend_power_down_kb();
+    // on AVR, this enables the watchdog for 15ms (max), and goes to
+    // SLEEP_MODE_PWR_DOWN
 
-       wait_ms(17);
+    wait_ms(17);
 }
 
 /** \brief suspend wakeup condition
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak)) void matrix_power_up(void) {}
-__attribute__ ((weak)) void matrix_power_down(void) {}
-bool suspend_wakeup_condition(void)
-{
+__attribute__((weak)) void matrix_power_up(void) {}
+__attribute__((weak)) void matrix_power_down(void) {}
+bool                       suspend_wakeup_condition(void) {
     matrix_power_up();
     matrix_scan();
     matrix_power_down();
@@ -73,25 +68,20 @@ bool suspend_wakeup_condition(void)
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_wakeup_init_user(void) { }
+__attribute__((weak)) void suspend_wakeup_init_user(void) {}
 
 /** \brief run keyboard level code immediately after wakeup
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void suspend_wakeup_init_kb(void) {
-  suspend_wakeup_init_user();
-}
+__attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); }
 
 /** \brief suspend wakeup condition
  *
  * run immediately after wakeup
  * FIXME: needs doc
  */
-void suspend_wakeup_init(void)
-{
+void suspend_wakeup_init(void) {
     // clear keyboard state
     // need to do it manually, because we're running from ISR
     //  and clear_keyboard() calls print
@@ -111,5 +101,5 @@ void suspend_wakeup_init(void)
 #ifdef BACKLIGHT_ENABLE
     backlight_init();
 #endif /* BACKLIGHT_ENABLE */
-  suspend_wakeup_init_kb();
+    suspend_wakeup_init_kb();
 }
index 473e533caa67dbce7ddb4503473009823415763e..1ce9d1d17c1facb0febe49a9e281b9fefa6ff37f 100644 (file)
@@ -2,40 +2,32 @@
 
 #include "timer.h"
 
-static systime_t last_systime = 0;
-static systime_t overflow = 0;
-static uint32_t current_time_ms = 0;
+static systime_t last_systime    = 0;
+static systime_t overflow        = 0;
+static uint32_t  current_time_ms = 0;
 
-void timer_init(void) {
-  timer_clear();
-}
+void timer_init(void) { timer_clear(); }
 
 void timer_clear(void) {
-  last_systime = chVTGetSystemTime();
-  overflow = 0;
-  current_time_ms = 0;
+    last_systime    = chVTGetSystemTime();
+    overflow        = 0;
+    current_time_ms = 0;
 }
 
-uint16_t timer_read(void) {
-  return (uint16_t)timer_read32();
-}
+uint16_t timer_read(void) { return (uint16_t)timer_read32(); }
 
 uint32_t timer_read32(void) {
-  // Note: We assume that the timer update is called at least once betweeen every wrap around of the system time
-  systime_t current_systime = chVTGetSystemTime();
-  systime_t elapsed = current_systime - last_systime + overflow;
-  uint32_t elapsed_ms = ST2MS(elapsed);
-  current_time_ms += elapsed_ms;
-  overflow = elapsed - MS2ST(elapsed_ms);
-  last_systime = current_systime;
-
-  return current_time_ms;
+    // Note: We assume that the timer update is called at least once betweeen every wrap around of the system time
+    systime_t current_systime = chVTGetSystemTime();
+    systime_t elapsed         = current_systime - last_systime + overflow;
+    uint32_t  elapsed_ms      = ST2MS(elapsed);
+    current_time_ms += elapsed_ms;
+    overflow     = elapsed - MS2ST(elapsed_ms);
+    last_systime = current_systime;
+
+    return current_time_ms;
 }
 
-uint16_t timer_elapsed(uint16_t last) {
-  return timer_read() - last;
-}
+uint16_t timer_elapsed(uint16_t last) { return timer_read() - last; }
 
-uint32_t timer_elapsed32(uint32_t last) {
-  return timer_read32() - last;
-}
+uint32_t timer_elapsed32(uint32_t last) { return timer_read32() - last; }
index 949615ecf912684c7270ade095d1a7e6306f080d..8bf72ef25820b7f751c577d4bbfb233bff685885 100644 (file)
@@ -37,25 +37,24 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "version.h"
 
 #ifdef MOUSEKEY_ENABLE
-#include "mousekey.h"
+#    include "mousekey.h"
 #endif
 
 #ifdef PROTOCOL_PJRC
-       #include "usb_keyboard.h"
-               #ifdef EXTRAKEY_ENABLE
-               #include "usb_extra.h"
-       #endif
+#    include "usb_keyboard.h"
+#    ifdef EXTRAKEY_ENABLE
+#        include "usb_extra.h"
+#    endif
 #endif
 
 #ifdef PROTOCOL_VUSB
-       #include "usbdrv.h"
+#    include "usbdrv.h"
 #endif
 
 #ifdef AUDIO_ENABLE
-    #include "audio.h"
+#    include "audio.h"
 #endif /* AUDIO_ENABLE */
 
-
 static bool command_common(uint8_t code);
 static void command_common_help(void);
 static void print_version(void);
@@ -69,16 +68,12 @@ static void mousekey_console_help(void);
 
 static void switch_default_layer(uint8_t layer);
 
-
 command_state_t command_state = ONESHOT;
 
-
-bool command_proc(uint8_t code)
-{
+bool command_proc(uint8_t code) {
     switch (command_state) {
         case ONESHOT:
-            if (!IS_COMMAND())
-                return false;
+            if (!IS_COMMAND()) return false;
             return (command_extra(code) || command_common(code));
             break;
         case CONSOLE:
@@ -101,86 +96,63 @@ bool command_proc(uint8_t code)
 
 /* TODO: Refactoring is needed. */
 /* This allows to define extra commands. return false when not processed. */
-bool command_extra(uint8_t code) __attribute__ ((weak));
-bool command_extra(uint8_t code)
-{
+bool command_extra(uint8_t code) __attribute__((weak));
+bool command_extra(uint8_t code) {
     (void)code;
     return false;
 }
 
-bool command_console_extra(uint8_t code) __attribute__ ((weak));
-bool command_console_extra(uint8_t code)
-{
+bool command_console_extra(uint8_t code) __attribute__((weak));
+bool command_console_extra(uint8_t code) {
     (void)code;
     return false;
 }
 
-
 /***********************************************************
  * Command common
  ***********************************************************/
-static void command_common_help(void)
-{
-       print(                            "\n\t- Magic -\n"
-               STR(MAGIC_KEY_DEBUG       ) ":  Debug Message Toggle\n"
-               STR(MAGIC_KEY_DEBUG_MATRIX) ":  Matrix Debug Mode Toggle - Show keypresses in matrix grid\n"
-               STR(MAGIC_KEY_DEBUG_KBD   ) ":  Keyboard Debug Toggle - Show keypress report\n"
-               STR(MAGIC_KEY_DEBUG_MOUSE ) ":  Debug Mouse Toggle\n"
-               STR(MAGIC_KEY_VERSION     ) ":  Version\n"
-               STR(MAGIC_KEY_STATUS      ) ":  Status\n"
-               STR(MAGIC_KEY_CONSOLE     ) ":  Activate Console Mode\n"
+static void command_common_help(void) {
+    print("\n\t- Magic -\n" STR(MAGIC_KEY_DEBUG) ":    Debug Message Toggle\n" STR(MAGIC_KEY_DEBUG_MATRIX) ":  Matrix Debug Mode Toggle - Show keypresses in matrix grid\n" STR(MAGIC_KEY_DEBUG_KBD) ":        Keyboard Debug Toggle - Show keypress report\n" STR(MAGIC_KEY_DEBUG_MOUSE) ":   Debug Mouse Toggle\n" STR(MAGIC_KEY_VERSION) ": Version\n" STR(MAGIC_KEY_STATUS) ":     Status\n" STR(MAGIC_KEY_CONSOLE) ":     Activate Console Mode\n"
 
 #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
-               STR(MAGIC_KEY_LAYER0      ) ":  Switch to Layer 0\n"
-               STR(MAGIC_KEY_LAYER1      ) ":  Switch to Layer 1\n"
-               STR(MAGIC_KEY_LAYER2      ) ":  Switch to Layer 2\n"
-               STR(MAGIC_KEY_LAYER3      ) ":  Switch to Layer 3\n"
-               STR(MAGIC_KEY_LAYER4      ) ":  Switch to Layer 4\n"
-               STR(MAGIC_KEY_LAYER5      ) ":  Switch to Layer 5\n"
-               STR(MAGIC_KEY_LAYER6      ) ":  Switch to Layer 6\n"
-               STR(MAGIC_KEY_LAYER7      ) ":  Switch to Layer 7\n"
-               STR(MAGIC_KEY_LAYER8      ) ":  Switch to Layer 8\n"
-               STR(MAGIC_KEY_LAYER9      ) ":  Switch to Layer 9\n"
+          STR(MAGIC_KEY_LAYER0) ":     Switch to Layer 0\n" STR(MAGIC_KEY_LAYER1) ":   Switch to Layer 1\n" STR(MAGIC_KEY_LAYER2) ":   Switch to Layer 2\n" STR(MAGIC_KEY_LAYER3) ":   Switch to Layer 3\n" STR(MAGIC_KEY_LAYER4) ":   Switch to Layer 4\n" STR(MAGIC_KEY_LAYER5) ":   Switch to Layer 5\n" STR(MAGIC_KEY_LAYER6) ":   Switch to Layer 6\n" STR(MAGIC_KEY_LAYER7) ":   Switch to Layer 7\n" STR(MAGIC_KEY_LAYER8) ":   Switch to Layer 8\n" STR(MAGIC_KEY_LAYER9) ":   Switch to Layer 9\n"
 #endif
 
 #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
-                                           "F1-F10:    Switch to Layer 0-9 (F10 = L0)\n"
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                               "F1-F10:        Switch to Layer 0-9 (F10 = L0)\n"
 #endif
 
 #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
-                                           "0-9:       Switch to Layer 0-9\n"
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                               "0-9:   Switch to Layer 0-9\n"
 #endif
 
-               STR(MAGIC_KEY_LAYER0_ALT  ) ":  Switch to Layer 0 (alternate)\n"
+          STR(MAGIC_KEY_LAYER0_ALT) ": Switch to Layer 0 (alternate)\n"
 
-               STR(MAGIC_KEY_BOOTLOADER    ) ":        Jump to Bootloader\n"
-               STR(MAGIC_KEY_BOOTLOADER_ALT) ":        Jump to Bootloader (alternate)\n"
+          STR(MAGIC_KEY_BOOTLOADER) ": Jump to Bootloader\n" STR(MAGIC_KEY_BOOTLOADER_ALT) ":  Jump to Bootloader (alternate)\n"
 
 #ifdef KEYBOARD_LOCK_ENABLE
-               STR(MAGIC_KEY_LOCK        ) ":  Lock Keyboard\n"
+          STR(MAGIC_KEY_LOCK) ":       Lock Keyboard\n"
 #endif
 
-               STR(MAGIC_KEY_EEPROM      ) ":  Print EEPROM Settings\n"
-               STR(MAGIC_KEY_EEPROM_CLEAR) ":  Clear EEPROM\n"
+          STR(MAGIC_KEY_EEPROM) ":     Print EEPROM Settings\n" STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n"
 
 #ifdef NKRO_ENABLE
-               STR(MAGIC_KEY_NKRO        ) ":  NKRO Toggle\n"
+          STR(MAGIC_KEY_NKRO) ":       NKRO Toggle\n"
 #endif
 
 #ifdef SLEEP_LED_ENABLE
-               STR(MAGIC_KEY_SLEEP_LED   ) ":  Sleep LED Test\n"
+          STR(MAGIC_KEY_SLEEP_LED) ":  Sleep LED Test\n"
 #endif
     );
 }
 
-static void print_version(void)
-{
-       // print version & information
+static void print_version(void) {
+    // print version & information
     print("\n\t- Version -\n");
     print("DESC: " STR(DESCRIPTION) "\n");
     print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") "
-          "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") "
-          "VER: " STR(DEVICE_VER) "\n");
+                                                       "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") "
+                                                                                                "VER: " STR(DEVICE_VER) "\n");
 #ifdef SKIP_VERSION
     print("BUILD:  (" __DATE__ ")\n");
 #else
@@ -191,51 +163,48 @@ static void print_version(void)
     print("OPTIONS:"
 
 #ifdef PROTOCOL_PJRC
-           " PJRC"
+          " PJRC"
 #endif
 #ifdef PROTOCOL_LUFA
-           " LUFA"
+          " LUFA"
 #endif
 #ifdef PROTOCOL_VUSB
-           " VUSB"
+          " VUSB"
 #endif
 #ifdef BOOTMAGIC_ENABLE
-           " BOOTMAGIC"
+          " BOOTMAGIC"
 #endif
 #ifdef MOUSEKEY_ENABLE
-           " MOUSEKEY"
+          " MOUSEKEY"
 #endif
 #ifdef EXTRAKEY_ENABLE
-           " EXTRAKEY"
+          " EXTRAKEY"
 #endif
 #ifdef CONSOLE_ENABLE
-           " CONSOLE"
+          " CONSOLE"
 #endif
 #ifdef COMMAND_ENABLE
-           " COMMAND"
+          " COMMAND"
 #endif
 #ifdef NKRO_ENABLE
-           " NKRO"
+          " NKRO"
 #endif
 #ifdef KEYMAP_SECTION_ENABLE
-           " KEYMAP_SECTION"
+          " KEYMAP_SECTION"
 #endif
 
-           " " STR(BOOTLOADER_SIZE) "\n");
+          " " STR(BOOTLOADER_SIZE) "\n");
 
     print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__)
 #if defined(__AVR__)
-          " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__
-          " AVR_ARCH: avr" STR(__AVR_ARCH__)
+              " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ " AVR_ARCH: avr" STR(__AVR_ARCH__)
 #endif
-                 "\n");
+                  "\n");
 
-       return;
+    return;
 }
 
-static void print_status(void)
-{
-
+static void print_status(void) {
     print("\n\t- Status -\n");
 
     print_val_hex8(host_keyboard_leds());
@@ -258,67 +227,101 @@ static void print_status(void)
 #endif
 
 #ifdef PROTOCOL_PJRC
-#   if USB_COUNT_SOF
+#    if USB_COUNT_SOF
     print_val_hex8(usbSofCount);
-#   endif
+#    endif
 #endif
-       return;
+    return;
 }
 
-static void print_eeconfig(void)
-{
-
+static void print_eeconfig(void) {
 // Print these variables if NO_PRINT or USER_PRINT are not defined.
 #if !defined(NO_PRINT) && !defined(USER_PRINT)
 
-    print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n");
+    print("default_layer: ");
+    print_dec(eeconfig_read_default_layer());
+    print("\n");
 
     debug_config_t dc;
     dc.raw = eeconfig_read_debug();
-    print("debug_config.raw: "); print_hex8(dc.raw); print("\n");
-    print(".enable: "); print_dec(dc.enable); print("\n");
-    print(".matrix: "); print_dec(dc.matrix); print("\n");
-    print(".keyboard: "); print_dec(dc.keyboard); print("\n");
-    print(".mouse: "); print_dec(dc.mouse); print("\n");
+    print("debug_config.raw: ");
+    print_hex8(dc.raw);
+    print("\n");
+    print(".enable: ");
+    print_dec(dc.enable);
+    print("\n");
+    print(".matrix: ");
+    print_dec(dc.matrix);
+    print("\n");
+    print(".keyboard: ");
+    print_dec(dc.keyboard);
+    print("\n");
+    print(".mouse: ");
+    print_dec(dc.mouse);
+    print("\n");
 
     keymap_config_t kc;
     kc.raw = eeconfig_read_keymap();
-    print("keymap_config.raw: "); print_hex8(kc.raw); print("\n");
-    print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n");
-    print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n");
-    print(".swap_lctl_lgui: "); print_dec(kc.swap_lctl_lgui); print("\n");
-    print(".swap_rctl_rgui: "); print_dec(kc.swap_rctl_rgui); print("\n");
-    print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n");
-    print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n");
-    print(".no_gui: "); print_dec(kc.no_gui); print("\n");
-    print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n");
-    print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n");
-    print(".nkro: "); print_dec(kc.nkro); print("\n");
-
-#ifdef BACKLIGHT_ENABLE
+    print("keymap_config.raw: ");
+    print_hex8(kc.raw);
+    print("\n");
+    print(".swap_control_capslock: ");
+    print_dec(kc.swap_control_capslock);
+    print("\n");
+    print(".capslock_to_control: ");
+    print_dec(kc.capslock_to_control);
+    print("\n");
+    print(".swap_lctl_lgui: ");
+    print_dec(kc.swap_lctl_lgui);
+    print("\n");
+    print(".swap_rctl_rgui: ");
+    print_dec(kc.swap_rctl_rgui);
+    print("\n");
+    print(".swap_lalt_lgui: ");
+    print_dec(kc.swap_lalt_lgui);
+    print("\n");
+    print(".swap_ralt_rgui: ");
+    print_dec(kc.swap_ralt_rgui);
+    print("\n");
+    print(".no_gui: ");
+    print_dec(kc.no_gui);
+    print("\n");
+    print(".swap_grave_esc: ");
+    print_dec(kc.swap_grave_esc);
+    print("\n");
+    print(".swap_backslash_backspace: ");
+    print_dec(kc.swap_backslash_backspace);
+    print("\n");
+    print(".nkro: ");
+    print_dec(kc.nkro);
+    print("\n");
+
+#    ifdef BACKLIGHT_ENABLE
     backlight_config_t bc;
     bc.raw = eeconfig_read_backlight();
-    print("backlight_config.raw: "); print_hex8(bc.raw); print("\n");
-    print(".enable: "); print_dec(bc.enable); print("\n");
-    print(".level: "); print_dec(bc.level); print("\n");
-#endif /* BACKLIGHT_ENABLE */
+    print("backlight_config.raw: ");
+    print_hex8(bc.raw);
+    print("\n");
+    print(".enable: ");
+    print_dec(bc.enable);
+    print("\n");
+    print(".level: ");
+    print_dec(bc.level);
+    print("\n");
+#    endif /* BACKLIGHT_ENABLE */
 
 #endif /* !NO_PRINT */
-
 }
 
-static bool command_common(uint8_t code)
-{
-
+static bool command_common(uint8_t code) {
 #ifdef KEYBOARD_LOCK_ENABLE
     static host_driver_t *host_driver = 0;
 #endif
 
     switch (code) {
-
 #ifdef SLEEP_LED_ENABLE
 
-               // test breathing sleep LED
+        // test breathing sleep LED
         case MAGIC_KC(MAGIC_KEY_SLEEP_LED):
             print("Sleep LED Test\n");
             sleep_led_toggle();
@@ -326,21 +329,21 @@ static bool command_common(uint8_t code)
             break;
 #endif
 
-               // print stored eeprom config
+        // print stored eeprom config
         case MAGIC_KC(MAGIC_KEY_EEPROM):
             print("eeconfig:\n");
             print_eeconfig();
             break;
 
-               // clear eeprom
+        // clear eeprom
         case MAGIC_KC(MAGIC_KEY_EEPROM_CLEAR):
             print("Clearing EEPROM\n");
-           eeconfig_init();
+            eeconfig_init();
             break;
 
 #ifdef KEYBOARD_LOCK_ENABLE
 
-               // lock/unlock keyboard
+        // lock/unlock keyboard
         case MAGIC_KC(MAGIC_KEY_LOCK):
             if (host_get_driver()) {
                 host_driver = host_get_driver();
@@ -354,13 +357,13 @@ static bool command_common(uint8_t code)
             break;
 #endif
 
-               // print help
+        // print help
         case MAGIC_KC(MAGIC_KEY_HELP):
         case MAGIC_KC(MAGIC_KEY_HELP_ALT):
             command_common_help();
             break;
 
-               // activate console
+        // activate console
         case MAGIC_KC(MAGIC_KEY_CONSOLE):
             debug_matrix   = false;
             debug_keyboard = false;
@@ -374,15 +377,15 @@ static bool command_common(uint8_t code)
         // jump to bootloader
         case MAGIC_KC(MAGIC_KEY_BOOTLOADER):
         case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT):
-            clear_keyboard(); // clear to prevent stuck keys
+            clear_keyboard();  // clear to prevent stuck keys
             print("\n\nJumping to bootloader... ");
-            #ifdef AUDIO_ENABLE
-                   stop_all_notes();
-                shutdown_user();
-            #else
-                   wait_ms(1000);
-            #endif
-            bootloader_jump(); // not return
+#ifdef AUDIO_ENABLE
+            stop_all_notes();
+            shutdown_user();
+#else
+            wait_ms(1000);
+#endif
+            bootloader_jump();  // not return
             break;
 
         // debug toggle
@@ -427,25 +430,25 @@ static bool command_common(uint8_t code)
                 print("\nmouse: on\n");
                 debug_enable = true;
             } else {
-                               print("\nmouse: off\n");
+                print("\nmouse: off\n");
             }
             break;
 
-               // print version
+        // print version
         case MAGIC_KC(MAGIC_KEY_VERSION):
-               print_version();
-                   break;
+            print_version();
+            break;
 
-               // print status
-               case MAGIC_KC(MAGIC_KEY_STATUS):
-                       print_status();
+        // print status
+        case MAGIC_KC(MAGIC_KEY_STATUS):
+            print_status();
             break;
 
 #ifdef NKRO_ENABLE
 
-               // NKRO toggle
+        // NKRO toggle
         case MAGIC_KC(MAGIC_KEY_NKRO):
-            clear_keyboard(); // clear to prevent stuck keys
+            clear_keyboard();  // clear to prevent stuck keys
             keymap_config.nkro = !keymap_config.nkro;
             if (keymap_config.nkro) {
                 print("NKRO: on\n");
@@ -455,56 +458,55 @@ static bool command_common(uint8_t code)
             break;
 #endif
 
-               // switch layers
+            // switch layers
 
-               case MAGIC_KC(MAGIC_KEY_LAYER0_ALT):
+        case MAGIC_KC(MAGIC_KEY_LAYER0_ALT):
             switch_default_layer(0);
             break;
 
 #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
 
-               case MAGIC_KC(MAGIC_KEY_LAYER0):
+        case MAGIC_KC(MAGIC_KEY_LAYER0):
             switch_default_layer(0);
             break;
 
-               case MAGIC_KC(MAGIC_KEY_LAYER1):
+        case MAGIC_KC(MAGIC_KEY_LAYER1):
             switch_default_layer(1);
             break;
 
-               case MAGIC_KC(MAGIC_KEY_LAYER2):
+        case MAGIC_KC(MAGIC_KEY_LAYER2):
             switch_default_layer(2);
             break;
 
-               case MAGIC_KC(MAGIC_KEY_LAYER3):
+        case MAGIC_KC(MAGIC_KEY_LAYER3):
             switch_default_layer(3);
             break;
 
-               case MAGIC_KC(MAGIC_KEY_LAYER4):
+        case MAGIC_KC(MAGIC_KEY_LAYER4):
             switch_default_layer(4);
             break;
 
-               case MAGIC_KC(MAGIC_KEY_LAYER5):
+        case MAGIC_KC(MAGIC_KEY_LAYER5):
             switch_default_layer(5);
             break;
 
-               case MAGIC_KC(MAGIC_KEY_LAYER6):
+        case MAGIC_KC(MAGIC_KEY_LAYER6):
             switch_default_layer(6);
             break;
 
-               case MAGIC_KC(MAGIC_KEY_LAYER7):
+        case MAGIC_KC(MAGIC_KEY_LAYER7):
             switch_default_layer(7);
             break;
 
-               case MAGIC_KC(MAGIC_KEY_LAYER8):
+        case MAGIC_KC(MAGIC_KEY_LAYER8):
             switch_default_layer(8);
             break;
 
-               case MAGIC_KC(MAGIC_KEY_LAYER9):
+        case MAGIC_KC(MAGIC_KEY_LAYER9):
             switch_default_layer(9);
             break;
 #endif
 
-
 #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
 
         case KC_F1 ... KC_F9:
@@ -532,12 +534,10 @@ static bool command_common(uint8_t code)
     return true;
 }
 
-
 /***********************************************************
  * Command console
  ***********************************************************/
-static void command_console_help(void)
-{
+static void command_console_help(void) {
     print("\n\t- Console -\n"
           "ESC/q:      quit\n"
 #ifdef MOUSEKEY_ENABLE
@@ -546,8 +546,7 @@ static void command_console_help(void)
     );
 }
 
-static bool command_console(uint8_t code)
-{
+static bool command_console(uint8_t code) {
     switch (code) {
         case KC_H:
         case KC_SLASH: /* ? */
@@ -572,32 +571,40 @@ static bool command_console(uint8_t code)
     return true;
 }
 
-
 #ifdef MOUSEKEY_ENABLE
 /***********************************************************
  * Mousekey console
  ***********************************************************/
 static uint8_t mousekey_param = 0;
 
-static void mousekey_param_print(void)
-{
+static void mousekey_param_print(void) {
 // Print these variables if NO_PRINT or USER_PRINT are not defined.
-#if !defined(NO_PRINT) && !defined(USER_PRINT)
+#    if !defined(NO_PRINT) && !defined(USER_PRINT)
     print("\n\t- Values -\n");
-    print("1: delay(*10ms): "); pdec(mk_delay); print("\n");
-    print("2: interval(ms): "); pdec(mk_interval); print("\n");
-    print("3: max_speed: "); pdec(mk_max_speed); print("\n");
-    print("4: time_to_max: "); pdec(mk_time_to_max); print("\n");
-    print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n");
-    print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
-#endif /* !NO_PRINT */
-
+    print("1: delay(*10ms): ");
+    pdec(mk_delay);
+    print("\n");
+    print("2: interval(ms): ");
+    pdec(mk_interval);
+    print("\n");
+    print("3: max_speed: ");
+    pdec(mk_max_speed);
+    print("\n");
+    print("4: time_to_max: ");
+    pdec(mk_time_to_max);
+    print("\n");
+    print("5: wheel_max_speed: ");
+    pdec(mk_wheel_max_speed);
+    print("\n");
+    print("6: wheel_time_to_max: ");
+    pdec(mk_wheel_time_to_max);
+    print("\n");
+#    endif /* !NO_PRINT */
 }
 
 //#define PRINT_SET_VAL(v)  print(#v " = "); print_dec(v); print("\n");
-#define PRINT_SET_VAL(v)  xprintf(#v " = %d\n", (v))
-static void mousekey_param_inc(uint8_t param, uint8_t inc)
-{
+#    define PRINT_SET_VAL(v) xprintf(#    v " = %d\n", (v))
+static void mousekey_param_inc(uint8_t param, uint8_t inc) {
     switch (param) {
         case 1:
             if (mk_delay + inc < UINT8_MAX)
@@ -644,8 +651,7 @@ static void mousekey_param_inc(uint8_t param, uint8_t inc)
     }
 }
 
-static void mousekey_param_dec(uint8_t param, uint8_t dec)
-{
+static void mousekey_param_dec(uint8_t param, uint8_t dec) {
     switch (param) {
         case 1:
             if (mk_delay > dec)
@@ -692,8 +698,7 @@ static void mousekey_param_dec(uint8_t param, uint8_t dec)
     }
 }
 
-static void mousekey_console_help(void)
-{
+static void mousekey_console_help(void) {
     print("\n\t- Mousekey -\n"
           "ESC/q:      quit\n"
           "1:  delay(*10ms)\n"
@@ -712,11 +717,11 @@ static void mousekey_console_help(void)
           "\n"
           "speed = delta * max_speed * (repeat / time_to_max)\n");
     xprintf("where delta: cursor=%d, wheel=%d\n"
-            "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA,  MOUSEKEY_WHEEL_DELTA);
+            "See http://en.wikipedia.org/wiki/Mouse_keys\n",
+            MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA);
 }
 
-static bool mousekey_console(uint8_t code)
-{
+static bool mousekey_console(uint8_t code) {
     switch (code) {
         case KC_H:
         case KC_SLASH: /* ? */
@@ -756,11 +761,11 @@ static bool mousekey_console(uint8_t code)
             mousekey_param_dec(mousekey_param, 10);
             break;
         case KC_D:
-            mk_delay = MOUSEKEY_DELAY/10;
-            mk_interval = MOUSEKEY_INTERVAL;
-            mk_max_speed = MOUSEKEY_MAX_SPEED;
-            mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
-            mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
+            mk_delay             = MOUSEKEY_DELAY / 10;
+            mk_interval          = MOUSEKEY_INTERVAL;
+            mk_max_speed         = MOUSEKEY_MAX_SPEED;
+            mk_time_to_max       = MOUSEKEY_TIME_TO_MAX;
+            mk_wheel_max_speed   = MOUSEKEY_WHEEL_MAX_SPEED;
             mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
             print("set default\n");
             break;
@@ -771,36 +776,43 @@ static bool mousekey_console(uint8_t code)
     if (mousekey_param) {
         xprintf("M%d> ", mousekey_param);
     } else {
-        print("M>" );
+        print("M>");
     }
     return true;
 }
 #endif
 
-
 /***********************************************************
  * Utilities
  ***********************************************************/
-uint8_t numkey2num(uint8_t code)
-{
+uint8_t numkey2num(uint8_t code) {
     switch (code) {
-        case KC_1: return 1;
-        case KC_2: return 2;
-        case KC_3: return 3;
-        case KC_4: return 4;
-        case KC_5: return 5;
-        case KC_6: return 6;
-        case KC_7: return 7;
-        case KC_8: return 8;
-        case KC_9: return 9;
-        case KC_0: return 0;
+        case KC_1:
+            return 1;
+        case KC_2:
+            return 2;
+        case KC_3:
+            return 3;
+        case KC_4:
+            return 4;
+        case KC_5:
+            return 5;
+        case KC_6:
+            return 6;
+        case KC_7:
+            return 7;
+        case KC_8:
+            return 8;
+        case KC_9:
+            return 9;
+        case KC_0:
+            return 0;
     }
     return 0;
 }
 
-static void switch_default_layer(uint8_t layer)
-{
+static void switch_default_layer(uint8_t layer) {
     xprintf("L%d\n", layer);
-    default_layer_set(1UL<<layer);
+    default_layer_set(1UL << layer);
     clear_keyboard();
 }
index e6e67fae4ade2f449c4bbcb9c1094c7f0c0e1e9b..4f77be085c9a15de5198d3e003a2412cd63ac23b 100644 (file)
@@ -29,135 +29,135 @@ bool command_console_extra(uint8_t code);
 
 #ifdef COMMAND_ENABLE
 uint8_t numkey2num(uint8_t code);
-bool command_proc(uint8_t code);
+bool    command_proc(uint8_t code);
 #else
-#define command_proc(code)      false
+#    define command_proc(code) false
 #endif
 
 #ifndef IS_COMMAND
-#define IS_COMMAND() (get_mods() == MOD_MASK_SHIFT)
+#    define IS_COMMAND() (get_mods() == MOD_MASK_SHIFT)
 #endif
 
 #ifndef MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
-#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS  true
+#    define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS true
 #endif
 
 #ifndef MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
-#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS  true
+#    define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS true
 #endif
 
 #ifndef MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
-#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM false
+#    define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM false
 #endif
 
 #ifndef MAGIC_KEY_HELP
-#define MAGIC_KEY_HELP           H
+#    define MAGIC_KEY_HELP H
 #endif
 
 #ifndef MAGIC_KEY_HELP_ALT
-#define MAGIC_KEY_HELP_ALT       SLASH
+#    define MAGIC_KEY_HELP_ALT SLASH
 #endif
 
 #ifndef MAGIC_KEY_DEBUG
-#define MAGIC_KEY_DEBUG          D
+#    define MAGIC_KEY_DEBUG D
 #endif
 
 #ifndef MAGIC_KEY_DEBUG_MATRIX
-#define MAGIC_KEY_DEBUG_MATRIX   X
+#    define MAGIC_KEY_DEBUG_MATRIX X
 #endif
 
 #ifndef MAGIC_KEY_DEBUG_KBD
-#define MAGIC_KEY_DEBUG_KBD      K
+#    define MAGIC_KEY_DEBUG_KBD K
 #endif
 
 #ifndef MAGIC_KEY_DEBUG_MOUSE
-#define MAGIC_KEY_DEBUG_MOUSE    M
+#    define MAGIC_KEY_DEBUG_MOUSE M
 #endif
 
 #ifndef MAGIC_KEY_VERSION
-#define MAGIC_KEY_VERSION        V
+#    define MAGIC_KEY_VERSION V
 #endif
 
 #ifndef MAGIC_KEY_STATUS
-#define MAGIC_KEY_STATUS         S
+#    define MAGIC_KEY_STATUS S
 #endif
 
 #ifndef MAGIC_KEY_CONSOLE
-#define MAGIC_KEY_CONSOLE        C
+#    define MAGIC_KEY_CONSOLE C
 #endif
 
 #ifndef MAGIC_KEY_LAYER0
-#define MAGIC_KEY_LAYER0         0
+#    define MAGIC_KEY_LAYER0 0
 #endif
 
 #ifndef MAGIC_KEY_LAYER0_ALT
-#define MAGIC_KEY_LAYER0_ALT     GRAVE
+#    define MAGIC_KEY_LAYER0_ALT GRAVE
 #endif
 
 #ifndef MAGIC_KEY_LAYER1
-#define MAGIC_KEY_LAYER1         1
+#    define MAGIC_KEY_LAYER1 1
 #endif
 
 #ifndef MAGIC_KEY_LAYER2
-#define MAGIC_KEY_LAYER2         2
+#    define MAGIC_KEY_LAYER2 2
 #endif
 
 #ifndef MAGIC_KEY_LAYER3
-#define MAGIC_KEY_LAYER3         3
+#    define MAGIC_KEY_LAYER3 3
 #endif
 
 #ifndef MAGIC_KEY_LAYER4
-#define MAGIC_KEY_LAYER4         4
+#    define MAGIC_KEY_LAYER4 4
 #endif
 
 #ifndef MAGIC_KEY_LAYER5
-#define MAGIC_KEY_LAYER5         5
+#    define MAGIC_KEY_LAYER5 5
 #endif
 
 #ifndef MAGIC_KEY_LAYER6
-#define MAGIC_KEY_LAYER6         6
+#    define MAGIC_KEY_LAYER6 6
 #endif
 
 #ifndef MAGIC_KEY_LAYER7
-#define MAGIC_KEY_LAYER7         7
+#    define MAGIC_KEY_LAYER7 7
 #endif
 
 #ifndef MAGIC_KEY_LAYER8
-#define MAGIC_KEY_LAYER8         8
+#    define MAGIC_KEY_LAYER8 8
 #endif
 
 #ifndef MAGIC_KEY_LAYER9
-#define MAGIC_KEY_LAYER9         9
+#    define MAGIC_KEY_LAYER9 9
 #endif
 
 #ifndef MAGIC_KEY_BOOTLOADER
-#define MAGIC_KEY_BOOTLOADER     B
+#    define MAGIC_KEY_BOOTLOADER B
 #endif
 
 #ifndef MAGIC_KEY_BOOTLOADER_ALT
-#define MAGIC_KEY_BOOTLOADER_ALT ESC
+#    define MAGIC_KEY_BOOTLOADER_ALT ESC
 #endif
 
 #ifndef MAGIC_KEY_LOCK
-#define MAGIC_KEY_LOCK           CAPS
+#    define MAGIC_KEY_LOCK CAPS
 #endif
 
 #ifndef MAGIC_KEY_EEPROM
-#define MAGIC_KEY_EEPROM         E
+#    define MAGIC_KEY_EEPROM E
 #endif
 
 #ifndef MAGIC_KEY_EEPROM_CLEAR
-#define MAGIC_KEY_EEPROM_CLEAR   BSPACE
+#    define MAGIC_KEY_EEPROM_CLEAR BSPACE
 #endif
 
 #ifndef MAGIC_KEY_NKRO
-#define MAGIC_KEY_NKRO           N
+#    define MAGIC_KEY_NKRO N
 #endif
 
 #ifndef MAGIC_KEY_SLEEP_LED
-#define MAGIC_KEY_SLEEP_LED      Z
+#    define MAGIC_KEY_SLEEP_LED Z
 
 #endif
 
-#define XMAGIC_KC(key)  KC_ ## key
-#define MAGIC_KC(key)   XMAGIC_KC(key)
+#define XMAGIC_KC(key) KC_##key
+#define MAGIC_KC(key) XMAGIC_KC(key)
index 18613fc28bdd532fafb3d9b1b514a9b2bc6414b2..bea96dfc14a1278a93a40226ac552e779b644eac 100644 (file)
@@ -7,10 +7,10 @@ debug_config_t debug_config = {
 /* GCC Bug 10676 - Using unnamed fields in initializers
  * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676 */
 #if GCC_VERSION >= 40600
-    .enable = false,
-    .matrix = false,
+    .enable   = false,
+    .matrix   = false,
     .keyboard = false,
-    .mouse = false,
+    .mouse    = false,
     .reserved = 0
 #else
     {
index 3cbe2092d1e9b2fb375dedb5977801bb64267857..f9d611bb03cd8276887c3c01e47411671fb5cb74 100644 (file)
@@ -21,7 +21,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdbool.h>
 #include "print.h"
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -31,11 +30,11 @@ extern "C" {
  */
 typedef union {
     struct {
-        bool enable:1;
-        bool matrix:1;
-        bool keyboard:1;
-        bool mouse:1;
-        uint8_t reserved:4;
+        bool    enable : 1;
+        bool    matrix : 1;
+        bool    keyboard : 1;
+        bool    mouse : 1;
+        uint8_t reserved : 4;
     };
     uint8_t raw;
 } debug_config_t;
@@ -47,70 +46,126 @@ extern debug_config_t debug_config;
 #endif
 
 /* for backward compatibility */
-#define debug_enable    (debug_config.enable)
-#define debug_matrix    (debug_config.matrix)
-#define debug_keyboard  (debug_config.keyboard)
-#define debug_mouse     (debug_config.mouse)
-
+#define debug_enable (debug_config.enable)
+#define debug_matrix (debug_config.matrix)
+#define debug_keyboard (debug_config.keyboard)
+#define debug_mouse (debug_config.mouse)
 
 /*
  * Debug print utils
  */
 #ifndef NO_DEBUG
 
-#define dprint(s)                   do { if (debug_enable) print(s); } while (0)
-#define dprintln(s)                 do { if (debug_enable) println(s); } while (0)
-#define dprintf(fmt, ...)           do { if (debug_enable) xprintf(fmt, ##__VA_ARGS__); } while (0)
-#define dmsg(s)                     dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s))
+#    define dprint(s)                   \
+        do {                            \
+            if (debug_enable) print(s); \
+        } while (0)
+#    define dprintln(s)                   \
+        do {                              \
+            if (debug_enable) println(s); \
+        } while (0)
+#    define dprintf(fmt, ...)                              \
+        do {                                               \
+            if (debug_enable) xprintf(fmt, ##__VA_ARGS__); \
+        } while (0)
+#    define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s))
 
 /* Deprecated. DO NOT USE these anymore, use dprintf instead. */
-#define debug(s)                    do { if (debug_enable) print(s); } while (0)
-#define debugln(s)                  do { if (debug_enable) println(s); } while (0)
-#define debug_msg(s)                do { \
-    if (debug_enable) { \
-        print(__FILE__); print(" at "); print_dec(__LINE__); print(" in "); print(": "); print(s); \
-    } \
-} while (0)
-#define debug_dec(data)             do { if (debug_enable) print_dec(data); } while (0)
-#define debug_decs(data)            do { if (debug_enable) print_decs(data); } while (0)
-#define debug_hex4(data)            do { if (debug_enable) print_hex4(data); } while (0)
-#define debug_hex8(data)            do { if (debug_enable) print_hex8(data); } while (0)
-#define debug_hex16(data)           do { if (debug_enable) print_hex16(data); } while (0)
-#define debug_hex32(data)           do { if (debug_enable) print_hex32(data); } while (0)
-#define debug_bin8(data)            do { if (debug_enable) print_bin8(data); } while (0)
-#define debug_bin16(data)           do { if (debug_enable) print_bin16(data); } while (0)
-#define debug_bin32(data)           do { if (debug_enable) print_bin32(data); } while (0)
-#define debug_bin_reverse8(data)    do { if (debug_enable) print_bin_reverse8(data); } while (0)
-#define debug_bin_reverse16(data)   do { if (debug_enable) print_bin_reverse16(data); } while (0)
-#define debug_bin_reverse32(data)   do { if (debug_enable) print_bin_reverse32(data); } while (0)
-#define debug_hex(data)             debug_hex8(data)
-#define debug_bin(data)             debug_bin8(data)
-#define debug_bin_reverse(data)     debug_bin8(data)
+#    define debug(s)                    \
+        do {                            \
+            if (debug_enable) print(s); \
+        } while (0)
+#    define debugln(s)                    \
+        do {                              \
+            if (debug_enable) println(s); \
+        } while (0)
+#    define debug_msg(s)             \
+        do {                         \
+            if (debug_enable) {      \
+                print(__FILE__);     \
+                print(" at ");       \
+                print_dec(__LINE__); \
+                print(" in ");       \
+                print(": ");         \
+                print(s);            \
+            }                        \
+        } while (0)
+#    define debug_dec(data)                    \
+        do {                                   \
+            if (debug_enable) print_dec(data); \
+        } while (0)
+#    define debug_decs(data)                    \
+        do {                                    \
+            if (debug_enable) print_decs(data); \
+        } while (0)
+#    define debug_hex4(data)                    \
+        do {                                    \
+            if (debug_enable) print_hex4(data); \
+        } while (0)
+#    define debug_hex8(data)                    \
+        do {                                    \
+            if (debug_enable) print_hex8(data); \
+        } while (0)
+#    define debug_hex16(data)                    \
+        do {                                     \
+            if (debug_enable) print_hex16(data); \
+        } while (0)
+#    define debug_hex32(data)                    \
+        do {                                     \
+            if (debug_enable) print_hex32(data); \
+        } while (0)
+#    define debug_bin8(data)                    \
+        do {                                    \
+            if (debug_enable) print_bin8(data); \
+        } while (0)
+#    define debug_bin16(data)                    \
+        do {                                     \
+            if (debug_enable) print_bin16(data); \
+        } while (0)
+#    define debug_bin32(data)                    \
+        do {                                     \
+            if (debug_enable) print_bin32(data); \
+        } while (0)
+#    define debug_bin_reverse8(data)                    \
+        do {                                            \
+            if (debug_enable) print_bin_reverse8(data); \
+        } while (0)
+#    define debug_bin_reverse16(data)                    \
+        do {                                             \
+            if (debug_enable) print_bin_reverse16(data); \
+        } while (0)
+#    define debug_bin_reverse32(data)                    \
+        do {                                             \
+            if (debug_enable) print_bin_reverse32(data); \
+        } while (0)
+#    define debug_hex(data) debug_hex8(data)
+#    define debug_bin(data) debug_bin8(data)
+#    define debug_bin_reverse(data) debug_bin8(data)
 
 #else /* NO_DEBUG */
 
-#define dprint(s)
-#define dprintln(s)
-#define dprintf(fmt, ...)
-#define dmsg(s)
-#define debug(s)
-#define debugln(s)
-#define debug_msg(s)
-#define debug_dec(data)
-#define debug_decs(data)
-#define debug_hex4(data)
-#define debug_hex8(data)
-#define debug_hex16(data)
-#define debug_hex32(data)
-#define debug_bin8(data)
-#define debug_bin16(data)
-#define debug_bin32(data)
-#define debug_bin_reverse8(data)
-#define debug_bin_reverse16(data)
-#define debug_bin_reverse32(data)
-#define debug_hex(data)
-#define debug_bin(data)
-#define debug_bin_reverse(data)
+#    define dprint(s)
+#    define dprintln(s)
+#    define dprintf(fmt, ...)
+#    define dmsg(s)
+#    define debug(s)
+#    define debugln(s)
+#    define debug_msg(s)
+#    define debug_dec(data)
+#    define debug_decs(data)
+#    define debug_hex4(data)
+#    define debug_hex8(data)
+#    define debug_hex16(data)
+#    define debug_hex32(data)
+#    define debug_bin8(data)
+#    define debug_bin16(data)
+#    define debug_bin32(data)
+#    define debug_bin_reverse8(data)
+#    define debug_bin_reverse16(data)
+#    define debug_bin_reverse32(data)
+#    define debug_hex(data)
+#    define debug_bin(data)
+#    define debug_bin_reverse(data)
 
 #endif /* NO_DEBUG */
 
index 28f5d3ad5e97edae4ed0b9fe1a260bcc3d488355..61aaec205479e6d22f7a627913e631446e59edd2 100644 (file)
@@ -4,8 +4,8 @@
 #include "eeconfig.h"
 
 #ifdef STM32_EEPROM_ENABLE
-#include "hal.h"
-#include "eeprom_stm32.h"
+#    include "hal.h"
+#    include "eeprom_stm32.h"
 #endif
 
 extern uint32_t default_layer_state;
@@ -13,21 +13,18 @@ extern uint32_t default_layer_state;
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void eeconfig_init_user(void) {
-  // Reset user EEPROM value to blank, rather than to a set value
-  eeconfig_update_user(0);
+__attribute__((weak)) void eeconfig_init_user(void) {
+    // Reset user EEPROM value to blank, rather than to a set value
+    eeconfig_update_user(0);
 }
 
-__attribute__ ((weak))
-void eeconfig_init_kb(void) {
-  // Reset Keyboard EEPROM value to blank, rather than to a set value
-  eeconfig_update_kb(0);
+__attribute__((weak)) void eeconfig_init_kb(void) {
+    // Reset Keyboard EEPROM value to blank, rather than to a set value
+    eeconfig_update_kb(0);
 
-  eeconfig_init_user();
+    eeconfig_init_user();
 }
 
-
 /*
  * FIXME: needs doc
  */
@@ -35,49 +32,42 @@ void eeconfig_init_quantum(void) {
 #ifdef STM32_EEPROM_ENABLE
     EEPROM_Erase();
 #endif
-  eeprom_update_word(EECONFIG_MAGIC,          EECONFIG_MAGIC_NUMBER);
-  eeprom_update_byte(EECONFIG_DEBUG,          0);
-  eeprom_update_byte(EECONFIG_DEFAULT_LAYER,  0);
-  default_layer_state = 0;
-  eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0);
-  eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0);
-  eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
-  eeprom_update_byte(EECONFIG_BACKLIGHT,      0);
-  eeprom_update_byte(EECONFIG_AUDIO,             0xFF); // On by default
-  eeprom_update_dword(EECONFIG_RGBLIGHT,      0);
-  eeprom_update_byte(EECONFIG_STENOMODE,      0);
-  eeprom_update_dword(EECONFIG_HAPTIC,        0);
-  eeprom_update_byte(EECONFIG_VELOCIKEY,      0);
-  eeprom_update_dword(EECONFIG_RGB_MATRIX,    0);
-  eeprom_update_byte(EECONFIG_RGB_MATRIX_SPEED, 0);
-
-  eeconfig_init_kb();
+    eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
+    eeprom_update_byte(EECONFIG_DEBUG, 0);
+    eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
+    default_layer_state = 0;
+    eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0);
+    eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0);
+    eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
+    eeprom_update_byte(EECONFIG_BACKLIGHT, 0);
+    eeprom_update_byte(EECONFIG_AUDIO, 0xFF);  // On by default
+    eeprom_update_dword(EECONFIG_RGBLIGHT, 0);
+    eeprom_update_byte(EECONFIG_STENOMODE, 0);
+    eeprom_update_dword(EECONFIG_HAPTIC, 0);
+    eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
+    eeprom_update_dword(EECONFIG_RGB_MATRIX, 0);
+    eeprom_update_byte(EECONFIG_RGB_MATRIX_SPEED, 0);
+
+    eeconfig_init_kb();
 }
 
 /** \brief eeconfig initialization
  *
  * FIXME: needs doc
  */
-void eeconfig_init(void) {
-
-  eeconfig_init_quantum();
-}
+void eeconfig_init(void) { eeconfig_init_quantum(); }
 
 /** \brief eeconfig enable
  *
  * FIXME: needs doc
  */
-void eeconfig_enable(void)
-{
-    eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
-}
+void eeconfig_enable(void) { eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); }
 
 /** \brief eeconfig disable
  *
  * FIXME: needs doc
  */
-void eeconfig_disable(void)
-{
+void eeconfig_disable(void) {
 #ifdef STM32_EEPROM_ENABLE
     EEPROM_Erase();
 #endif
@@ -88,25 +78,19 @@ void eeconfig_disable(void)
  *
  * FIXME: needs doc
  */
-bool eeconfig_is_enabled(void)
-{
-    return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
-}
+bool eeconfig_is_enabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); }
 
 /** \brief eeconfig is disabled
  *
  * FIXME: needs doc
  */
-bool eeconfig_is_disabled(void)
-{
-    return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF);
-}
+bool eeconfig_is_disabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF); }
 
 /** \brief eeconfig read debug
  *
  * FIXME: needs doc
  */
-uint8_t eeconfig_read_debug(void)      { return eeprom_read_byte(EECONFIG_DEBUG); }
+uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }
 /** \brief eeconfig update debug
  *
  * FIXME: needs doc
@@ -117,7 +101,7 @@ void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val
  *
  * FIXME: needs doc
  */
-uint8_t eeconfig_read_default_layer(void)      { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
+uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
 /** \brief eeconfig update default layer
  *
  * FIXME: needs doc
@@ -128,47 +112,43 @@ void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DE
  *
  * FIXME: needs doc
  */
-uint16_t eeconfig_read_keymap(void) {
-    return ( eeprom_read_byte(EECONFIG_KEYMAP_LOWER_BYTE) | (eeprom_read_byte(EECONFIG_KEYMAP_UPPER_BYTE) << 8) );
-}
+uint16_t eeconfig_read_keymap(void) { return (eeprom_read_byte(EECONFIG_KEYMAP_LOWER_BYTE) | (eeprom_read_byte(EECONFIG_KEYMAP_UPPER_BYTE) << 8)); }
 /** \brief eeconfig update keymap
  *
  * FIXME: needs doc
  */
 void eeconfig_update_keymap(uint16_t val) {
     eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, val & 0xFF);
-    eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, ( val >> 8 ) & 0xFF );
+    eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, (val >> 8) & 0xFF);
 }
 
 /** \brief eeconfig read backlight
  *
  * FIXME: needs doc
  */
-uint8_t eeconfig_read_backlight(void)      { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
+uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
 /** \brief eeconfig update backlight
  *
  * FIXME: needs doc
  */
 void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); }
 
-
 /** \brief eeconfig read audio
  *
  * FIXME: needs doc
  */
-uint8_t eeconfig_read_audio(void)      { return eeprom_read_byte(EECONFIG_AUDIO); }
+uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); }
 /** \brief eeconfig update audio
  *
  * FIXME: needs doc
  */
 void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); }
 
-
 /** \brief eeconfig read kb
  *
  * FIXME: needs doc
  */
-uint32_t eeconfig_read_kb(void)      { return eeprom_read_dword(EECONFIG_KEYBOARD); }
+uint32_t eeconfig_read_kb(void) { return eeprom_read_dword(EECONFIG_KEYBOARD); }
 /** \brief eeconfig update kb
  *
  * FIXME: needs doc
@@ -179,15 +159,14 @@ void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, v
  *
  * FIXME: needs doc
  */
-uint32_t eeconfig_read_user(void)      { return eeprom_read_dword(EECONFIG_USER); }
+uint32_t eeconfig_read_user(void) { return eeprom_read_dword(EECONFIG_USER); }
 /** \brief eeconfig update user
  *
  * FIXME: needs doc
  */
 void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); }
 
-
-uint32_t eeconfig_read_haptic(void)      { return eeprom_read_dword(EECONFIG_HAPTIC); }
+uint32_t eeconfig_read_haptic(void) { return eeprom_read_dword(EECONFIG_HAPTIC); }
 /** \brief eeconfig update user
  *
  * FIXME: needs doc
index a5fc801a3bd0704fef2c0f1da86fe0b06747af35..aea4eff9f6ed21285ec838bb6fd517cd3fd4e1e9 100644 (file)
@@ -21,49 +21,48 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdint.h>
 #include <stdbool.h>
 
-
 #ifndef EECONFIG_MAGIC_NUMBER
-#     define EECONFIG_MAGIC_NUMBER                       (uint16_t)0xFEEC
+#    define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEEC
 #endif
-#define EECONFIG_MAGIC_NUMBER_OFF                   (uint16_t)0xFFFF
+#define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF
 
 /* EEPROM parameter address */
-#define EECONFIG_MAGIC                              (uint16_t *)0
-#define EECONFIG_DEBUG                               (uint8_t *)2
-#define EECONFIG_DEFAULT_LAYER                       (uint8_t *)3
-#define EECONFIG_KEYMAP                              (uint8_t *)4
-#define EECONFIG_MOUSEKEY_ACCEL                      (uint8_t *)5
-#define EECONFIG_BACKLIGHT                           (uint8_t *)6
-#define EECONFIG_AUDIO                               (uint8_t *)7
-#define EECONFIG_RGBLIGHT                           (uint32_t *)8
-#define EECONFIG_UNICODEMODE                        (uint8_t *)12
-#define EECONFIG_STENOMODE                          (uint8_t *)13
+#define EECONFIG_MAGIC (uint16_t *)0
+#define EECONFIG_DEBUG (uint8_t *)2
+#define EECONFIG_DEFAULT_LAYER (uint8_t *)3
+#define EECONFIG_KEYMAP (uint8_t *)4
+#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5
+#define EECONFIG_BACKLIGHT (uint8_t *)6
+#define EECONFIG_AUDIO (uint8_t *)7
+#define EECONFIG_RGBLIGHT (uint32_t *)8
+#define EECONFIG_UNICODEMODE (uint8_t *)12
+#define EECONFIG_STENOMODE (uint8_t *)13
 // EEHANDS for two handed boards
-#define EECONFIG_HANDEDNESS                         (uint8_t *)14
-#define EECONFIG_KEYBOARD                          (uint32_t *)15
-#define EECONFIG_USER                              (uint32_t *)19
-#define EECONFIG_VELOCIKEY                          (uint8_t *)23
-
-#define EECONFIG_HAPTIC                            (uint32_t *)24
-#define EECONFIG_RGB_MATRIX                        (uint32_t *)28
-#define EECONFIG_RGB_MATRIX_SPEED                   (uint8_t *)32
+#define EECONFIG_HANDEDNESS (uint8_t *)14
+#define EECONFIG_KEYBOARD (uint32_t *)15
+#define EECONFIG_USER (uint32_t *)19
+#define EECONFIG_VELOCIKEY (uint8_t *)23
+
+#define EECONFIG_HAPTIC (uint32_t *)24
+#define EECONFIG_RGB_MATRIX (uint32_t *)28
+#define EECONFIG_RGB_MATRIX_SPEED (uint8_t *)32
 // TODO: Combine these into a single word and single block of EEPROM
-#define EECONFIG_KEYMAP_UPPER_BYTE                  (uint8_t *)33
+#define EECONFIG_KEYMAP_UPPER_BYTE (uint8_t *)33
 /* debug bit */
-#define EECONFIG_DEBUG_ENABLE                       (1<<0)
-#define EECONFIG_DEBUG_MATRIX                       (1<<1)
-#define EECONFIG_DEBUG_KEYBOARD                     (1<<2)
-#define EECONFIG_DEBUG_MOUSE                        (1<<3)
+#define EECONFIG_DEBUG_ENABLE (1 << 0)
+#define EECONFIG_DEBUG_MATRIX (1 << 1)
+#define EECONFIG_DEBUG_KEYBOARD (1 << 2)
+#define EECONFIG_DEBUG_MOUSE (1 << 3)
 
 /* keyconf bit */
-#define EECONFIG_KEYMAP_SWAP_CONTROL_CAPSLOCK       (1<<0)
-#define EECONFIG_KEYMAP_CAPSLOCK_TO_CONTROL         (1<<1)
-#define EECONFIG_KEYMAP_SWAP_LALT_LGUI              (1<<2)
-#define EECONFIG_KEYMAP_SWAP_RALT_RGUI              (1<<3)
-#define EECONFIG_KEYMAP_NO_GUI                      (1<<4)
-#define EECONFIG_KEYMAP_SWAP_GRAVE_ESC              (1<<5)
-#define EECONFIG_KEYMAP_SWAP_BACKSLASH_BACKSPACE    (1<<6)
-#define EECONFIG_KEYMAP_NKRO                        (1<<7)
+#define EECONFIG_KEYMAP_SWAP_CONTROL_CAPSLOCK (1 << 0)
+#define EECONFIG_KEYMAP_CAPSLOCK_TO_CONTROL (1 << 1)
+#define EECONFIG_KEYMAP_SWAP_LALT_LGUI (1 << 2)
+#define EECONFIG_KEYMAP_SWAP_RALT_RGUI (1 << 3)
+#define EECONFIG_KEYMAP_NO_GUI (1 << 4)
+#define EECONFIG_KEYMAP_SWAP_GRAVE_ESC (1 << 5)
+#define EECONFIG_KEYMAP_SWAP_BACKSLASH_BACKSPACE (1 << 6)
+#define EECONFIG_KEYMAP_NKRO (1 << 7)
 
 #define EECONFIG_KEYMAP_LOWER_BYTE EECONFIG_KEYMAP
 
@@ -80,32 +79,32 @@ void eeconfig_enable(void);
 void eeconfig_disable(void);
 
 uint8_t eeconfig_read_debug(void);
-void eeconfig_update_debug(uint8_t val);
+void    eeconfig_update_debug(uint8_t val);
 
 uint8_t eeconfig_read_default_layer(void);
-void eeconfig_update_default_layer(uint8_t val);
+void    eeconfig_update_default_layer(uint8_t val);
 
 uint16_t eeconfig_read_keymap(void);
-void eeconfig_update_keymap(uint16_t val);
+void     eeconfig_update_keymap(uint16_t val);
 
 #ifdef BACKLIGHT_ENABLE
 uint8_t eeconfig_read_backlight(void);
-void eeconfig_update_backlight(uint8_t val);
+void    eeconfig_update_backlight(uint8_t val);
 #endif
 
 #ifdef AUDIO_ENABLE
 uint8_t eeconfig_read_audio(void);
-void eeconfig_update_audio(uint8_t val);
+void    eeconfig_update_audio(uint8_t val);
 #endif
 
 uint32_t eeconfig_read_kb(void);
-void eeconfig_update_kb(uint32_t val);
+void     eeconfig_update_kb(uint32_t val);
 uint32_t eeconfig_read_user(void);
-void eeconfig_update_user(uint32_t val);
+void     eeconfig_update_user(uint32_t val);
 
 #ifdef HAPTIC_ENABLE
 uint32_t eeconfig_read_haptic(void);
-void eeconfig_update_haptic(uint32_t val);
+void     eeconfig_update_haptic(uint32_t val);
 #endif
 
 #endif
index 5ae0f6eebd9361ca9cc20e7bbf002782341a1130..fcd1667c0646384ab028937be516491f12605694 100644 (file)
@@ -2,22 +2,22 @@
 #define TMK_CORE_COMMON_EEPROM_H_
 
 #if defined(__AVR__)
-#include <avr/eeprom.h>
+#    include <avr/eeprom.h>
 #else
-#include <stdint.h>
+#    include <stdint.h>
 
-uint8_t        eeprom_read_byte (const uint8_t *__p);
-uint16_t       eeprom_read_word (const uint16_t *__p);
-uint32_t       eeprom_read_dword (const uint32_t *__p);
-void   eeprom_read_block (void *__dst, const void *__src, uint32_t __n);
-void   eeprom_write_byte (uint8_t *__p, uint8_t __value);
-void   eeprom_write_word (uint16_t *__p, uint16_t __value);
-void   eeprom_write_dword (uint32_t *__p, uint32_t __value);
-void   eeprom_write_block (const void *__src, void *__dst, uint32_t __n);
-void   eeprom_update_byte (uint8_t *__p, uint8_t __value);
-void   eeprom_update_word (uint16_t *__p, uint16_t __value);
-void   eeprom_update_dword (uint32_t *__p, uint32_t __value);
-void   eeprom_update_block (const void *__src, void *__dst, uint32_t __n);
+uint8_t  eeprom_read_byte(const uint8_t *__p);
+uint16_t eeprom_read_word(const uint16_t *__p);
+uint32_t eeprom_read_dword(const uint32_t *__p);
+void     eeprom_read_block(void *__dst, const void *__src, uint32_t __n);
+void     eeprom_write_byte(uint8_t *__p, uint8_t __value);
+void     eeprom_write_word(uint16_t *__p, uint16_t __value);
+void     eeprom_write_dword(uint32_t *__p, uint32_t __value);
+void     eeprom_write_block(const void *__src, void *__dst, uint32_t __n);
+void     eeprom_update_byte(uint8_t *__p, uint8_t __value);
+void     eeprom_update_word(uint16_t *__p, uint16_t __value);
+void     eeprom_update_dword(uint32_t *__p, uint32_t __value);
+void     eeprom_update_block(const void *__src, void *__dst, uint32_t __n);
 #endif
 
 #endif /* TMK_CORE_COMMON_EEPROM_H_ */
index f5d0416996b10b23959f8dcc862011a95d6ec31c..ce39760a5bb85c0a41c5f44eee4e9407b80e18da 100644 (file)
@@ -23,40 +23,31 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "debug.h"
 
 #ifdef NKRO_ENABLE
-  #include "keycode_config.h"
-  extern keymap_config_t keymap_config;
+#    include "keycode_config.h"
+extern keymap_config_t keymap_config;
 #endif
 
 static host_driver_t *driver;
-static uint16_t last_system_report = 0;
-static uint16_t last_consumer_report = 0;
+static uint16_t       last_system_report   = 0;
+static uint16_t       last_consumer_report = 0;
 
+void host_set_driver(host_driver_t *d) { driver = d; }
 
-void host_set_driver(host_driver_t *d)
-{
-    driver = d;
-}
-
-host_driver_t *host_get_driver(void)
-{
-    return driver;
-}
+host_driver_t *host_get_driver(void) { return driver; }
 
-uint8_t host_keyboard_leds(void)
-{
+uint8_t host_keyboard_leds(void) {
     if (!driver) return 0;
     return (*driver->keyboard_leds)();
 }
 /* send report */
-void host_keyboard_send(report_keyboard_t *report)
-{
+void host_keyboard_send(report_keyboard_t *report) {
     if (!driver) return;
 #if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP)
     if (keyboard_protocol && keymap_config.nkro) {
         /* The callers of this function assume that report->mods is where mods go in.
          * But report->nkro.mods can be at a different offset if core keyboard does not have a report ID.
          */
-        report->nkro.mods = report->mods;
+        report->nkro.mods      = report->mods;
         report->nkro.report_id = REPORT_ID_NKRO;
     } else
 #endif
@@ -76,8 +67,7 @@ void host_keyboard_send(report_keyboard_t *report)
     }
 }
 
-void host_mouse_send(report_mouse_t *report)
-{
+void host_mouse_send(report_mouse_t *report) {
     if (!driver) return;
 #ifdef MOUSE_SHARED_EP
     report->report_id = REPORT_ID_MOUSE;
@@ -85,8 +75,7 @@ void host_mouse_send(report_mouse_t *report)
     (*driver->send_mouse)(report);
 }
 
-void host_system_send(uint16_t report)
-{
+void host_system_send(uint16_t report) {
     if (report == last_system_report) return;
     last_system_report = report;
 
@@ -94,8 +83,7 @@ void host_system_send(uint16_t report)
     (*driver->send_system)(report);
 }
 
-void host_consumer_send(uint16_t report)
-{
+void host_consumer_send(uint16_t report) {
     if (report == last_consumer_report) return;
     last_consumer_report = report;
 
@@ -103,12 +91,6 @@ void host_consumer_send(uint16_t report)
     (*driver->send_consumer)(report);
 }
 
-uint16_t host_last_system_report(void)
-{
-    return last_system_report;
-}
+uint16_t host_last_system_report(void) { return last_system_report; }
 
-uint16_t host_last_consumer_report(void)
-{
-    return last_consumer_report;
-}
+uint16_t host_last_consumer_report(void) { return last_consumer_report; }
index 3d172eed66d214050384f053e718c34b7df5af27..b2a7f984277fa745f24b1cd7c06dc7fd4d05f031 100644 (file)
@@ -22,11 +22,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "report.h"
 #include "host_driver.h"
 
-#define IS_LED_ON(leds, led_name)   ( (leds) & (1 << (led_name)))
-#define IS_LED_OFF(leds, led_name)  (~(leds) & (1 << (led_name)))
+#define IS_LED_ON(leds, led_name) ((leds) & (1 << (led_name)))
+#define IS_LED_OFF(leds, led_name) (~(leds) & (1 << (led_name)))
 
-#define IS_HOST_LED_ON(led_name)    IS_LED_ON(host_keyboard_leds(), led_name)
-#define IS_HOST_LED_OFF(led_name)   IS_LED_OFF(host_keyboard_leds(), led_name)
+#define IS_HOST_LED_ON(led_name) IS_LED_ON(host_keyboard_leds(), led_name)
+#define IS_HOST_LED_OFF(led_name) IS_LED_OFF(host_keyboard_leds(), led_name)
 
 #ifdef __cplusplus
 extern "C" {
@@ -36,15 +36,15 @@ extern uint8_t keyboard_idle;
 extern uint8_t keyboard_protocol;
 
 /* host driver */
-void host_set_driver(host_driver_t *driver);
+void           host_set_driver(host_driver_t *driver);
 host_driver_t *host_get_driver(void);
 
 /* host driver interface */
 uint8_t host_keyboard_leds(void);
-void host_keyboard_send(report_keyboard_t *report);
-void host_mouse_send(report_mouse_t *report);
-void host_system_send(uint16_t data);
-void host_consumer_send(uint16_t data);
+void    host_keyboard_send(report_keyboard_t *report);
+void    host_mouse_send(report_mouse_t *report);
+void    host_system_send(uint16_t data);
+void    host_consumer_send(uint16_t data);
 
 uint16_t host_last_system_report(void);
 uint16_t host_last_consumer_report(void);
index e40f0bfd65900a335b5edfd07c839f83fbb33f86..3cfec40cca3d92d979bdec709c33581df7688565 100644 (file)
@@ -21,7 +21,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdint.h>
 #include "report.h"
 #ifdef MIDI_ENABLE
-       #include "midi.h"
+#    include "midi.h"
 #endif
 
 typedef struct {
index 8f0257cf66606de1f52489c52e5309c125ab2f42..f4d2cd73893c0f18a710045c0c9332ab27588dab 100644 (file)
@@ -32,84 +32,82 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "backlight.h"
 #include "action_layer.h"
 #ifdef BOOTMAGIC_ENABLE
-#   include "bootmagic.h"
+#    include "bootmagic.h"
 #else
-#   include "magic.h"
+#    include "magic.h"
 #endif
 #ifdef MOUSEKEY_ENABLE
-#   include "mousekey.h"
+#    include "mousekey.h"
 #endif
 #ifdef PS2_MOUSE_ENABLE
-#   include "ps2_mouse.h"
+#    include "ps2_mouse.h"
 #endif
 #ifdef SERIAL_MOUSE_ENABLE
-#   include "serial_mouse.h"
+#    include "serial_mouse.h"
 #endif
 #ifdef ADB_MOUSE_ENABLE
-#   include "adb.h"
+#    include "adb.h"
 #endif
 #ifdef RGBLIGHT_ENABLE
-#   include "rgblight.h"
+#    include "rgblight.h"
 #endif
 #ifdef STENO_ENABLE
-#   include "process_steno.h"
+#    include "process_steno.h"
 #endif
 #ifdef FAUXCLICKY_ENABLE
-#   include "fauxclicky.h"
+#    include "fauxclicky.h"
 #endif
 #ifdef SERIAL_LINK_ENABLE
-#   include "serial_link/system/serial_link.h"
+#    include "serial_link/system/serial_link.h"
 #endif
 #ifdef VISUALIZER_ENABLE
-#   include "visualizer/visualizer.h"
+#    include "visualizer/visualizer.h"
 #endif
 #ifdef POINTING_DEVICE_ENABLE
-#   include "pointing_device.h"
+#    include "pointing_device.h"
 #endif
 #ifdef MIDI_ENABLE
-#   include "process_midi.h"
+#    include "process_midi.h"
 #endif
 #ifdef HD44780_ENABLE
-#   include "hd44780.h"
+#    include "hd44780.h"
 #endif
 #ifdef QWIIC_ENABLE
-#   include "qwiic.h"
+#    include "qwiic.h"
 #endif
 #ifdef OLED_DRIVER_ENABLE
-    #include "oled_driver.h"
+#    include "oled_driver.h"
 #endif
 #ifdef VELOCIKEY_ENABLE
-  #include "velocikey.h"
+#    include "velocikey.h"
 #endif
 
 #ifdef MATRIX_HAS_GHOST
 extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
-static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata){
+static matrix_row_t   get_real_keys(uint8_t row, matrix_row_t rowdata) {
     matrix_row_t out = 0;
     for (uint8_t col = 0; col < MATRIX_COLS; col++) {
-        //read each key in the row data and check if the keymap defines it as a real key
-        if (pgm_read_byte(&keymaps[0][row][col]) && (rowdata & (1<<col))){
-            //this creates new row data, if a key is defined in the keymap, it will be set here
-            out |= 1<<col;
+        // read each key in the row data and check if the keymap defines it as a real key
+        if (pgm_read_byte(&keymaps[0][row][col]) && (rowdata & (1 << col))) {
+            // this creates new row data, if a key is defined in the keymap, it will be set here
+            out |= 1 << col;
         }
     }
     return out;
 }
 
-static inline bool popcount_more_than_one(matrix_row_t rowdata)
-{
-    rowdata &= rowdata-1; //if there are less than two bits (keys) set, rowdata will become zero
+static inline bool popcount_more_than_one(matrix_row_t rowdata) {
+    rowdata &= rowdata - 1;  // if there are less than two bits (keys) set, rowdata will become zero
     return rowdata;
 }
 
-static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata)
-{
+static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) {
     /* No ghost exists when less than 2 keys are down on the row.
     If there are "active" blanks in the matrix, the key can't be pressed by the user,
     there is no doubt as to which keys are really being pressed.
     The ghosts will be ignored, they are KC_NO.   */
     rowdata = get_real_keys(row, rowdata);
-    if ((popcount_more_than_one(rowdata)) == 0){
+    if ((popcount_more_than_one(rowdata)) == 0) {
         return false;
     }
     /* Ghost occurs when the row shares a column line with other row,
@@ -119,8 +117,8 @@ static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata)
     at least two of another row's real keys, the row will be ignored. Keep in mind,
     we are checking one row at a time, not all of them at once.
     */
-    for (uint8_t i=0; i < MATRIX_ROWS; i++) {
-        if (i != row && popcount_more_than_one(get_real_keys(i, matrix_get_row(i)) & rowdata)){
+    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+        if (i != row && popcount_more_than_one(get_real_keys(i, matrix_get_row(i)) & rowdata)) {
             return true;
         }
     }
@@ -131,9 +129,7 @@ static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata)
 
 void disable_jtag(void) {
 // To use PF4-7 (PC2-5 on ATmega32A), disable JTAG by writing JTD bit twice within four cycles.
-#if (defined(__AVR_AT90USB646__)  || defined(__AVR_AT90USB647__)  || \
-     defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || \
-     defined(__AVR_ATmega16U4__)  || defined(__AVR_ATmega32U4__))
+#if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
     MCUCR |= _BV(JTD);
     MCUCR |= _BV(JTD);
 #elif defined(__AVR_ATmega32A__)
@@ -146,43 +142,33 @@ void disable_jtag(void) {
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void matrix_setup(void) {
-}
+__attribute__((weak)) void matrix_setup(void) {}
 
 /** \brief keyboard_pre_init_user
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void keyboard_pre_init_user(void) { }
+__attribute__((weak)) void keyboard_pre_init_user(void) {}
 
 /** \brief keyboard_pre_init_kb
  *
  * FIXME: needs doc
  */
-__attribute__ ((weak))
-void keyboard_pre_init_kb(void) {
-  keyboard_pre_init_user();
-}
+__attribute__((weak)) void keyboard_pre_init_kb(void) { keyboard_pre_init_user(); }
 
 /** \brief keyboard_post_init_user
  *
  * FIXME: needs doc
  */
 
-__attribute__ ((weak))
-void keyboard_post_init_user() {}
+__attribute__((weak)) void keyboard_post_init_user() {}
 
 /** \brief keyboard_post_init_kb
  *
  * FIXME: needs doc
  */
 
-__attribute__ ((weak))
-void keyboard_post_init_kb(void) {
-  keyboard_post_init_user();
-}
+__attribute__((weak)) void keyboard_post_init_kb(void) { keyboard_post_init_user(); }
 
 /** \brief keyboard_setup
  *
@@ -200,10 +186,7 @@ void keyboard_setup(void) {
  *
  * FIXME: needs doc
  */
-__attribute__((weak))
-bool is_keyboard_master(void) {
-    return true;
-}
+__attribute__((weak)) bool is_keyboard_master(void) { return true; }
 
 /** \brief keyboard_init
  *
@@ -265,12 +248,11 @@ void keyboard_init(void) {
  *
  * This is repeatedly called as fast as possible.
  */
-void keyboard_task(void)
-{
+void keyboard_task(void) {
     static matrix_row_t matrix_prev[MATRIX_ROWS];
-    static uint8_t led_status = 0;
-    matrix_row_t matrix_row = 0;
-    matrix_row_t matrix_change = 0;
+    static uint8_t      led_status    = 0;
+    matrix_row_t        matrix_row    = 0;
+    matrix_row_t        matrix_change = 0;
 #ifdef QMK_KEYS_PER_SCAN
     uint8_t keys_processed = 0;
 #endif
@@ -283,28 +265,28 @@ void keyboard_task(void)
 
     if (is_keyboard_master()) {
         for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
-            matrix_row = matrix_get_row(r);
+            matrix_row    = matrix_get_row(r);
             matrix_change = matrix_row ^ matrix_prev[r];
             if (matrix_change) {
 #ifdef MATRIX_HAS_GHOST
-                if (has_ghost_in_row(r, matrix_row)) { continue; }
+                if (has_ghost_in_row(r, matrix_row)) {
+                    continue;
+                }
 #endif
                 if (debug_matrix) matrix_print();
                 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
-                    if (matrix_change & ((matrix_row_t)1<<c)) {
+                    if (matrix_change & ((matrix_row_t)1 << c)) {
                         action_exec((keyevent_t){
-                            .key = (keypos_t){ .row = r, .col = c },
-                            .pressed = (matrix_row & ((matrix_row_t)1<<c)),
-                            .time = (timer_read() | 1) /* time should not be 0 */
+                            .key = (keypos_t){.row = r, .col = c}, .pressed = (matrix_row & ((matrix_row_t)1 << c)), .time = (timer_read() | 1) /* time should not be 0 */
                         });
                         // record a processed key
-                        matrix_prev[r] ^= ((matrix_row_t)1<<c);
+                        matrix_prev[r] ^= ((matrix_row_t)1 << c);
 #ifdef QMK_KEYS_PER_SCAN
                         // only jump out if we have processed "enough" keys.
                         if (++keys_processed >= QMK_KEYS_PER_SCAN)
 #endif
-                        // process a key per task call
-                        goto MATRIX_LOOP_END;
+                            // process a key per task call
+                            goto MATRIX_LOOP_END;
                     }
                 }
             }
@@ -315,7 +297,7 @@ void keyboard_task(void)
     // we can get here with some keys processed now.
     if (!keys_processed)
 #endif
-    action_exec(TICK);
+        action_exec(TICK);
 
 MATRIX_LOOP_END:
 
@@ -325,11 +307,10 @@ MATRIX_LOOP_END:
 
 #ifdef OLED_DRIVER_ENABLE
     oled_task();
-#ifndef OLED_DISABLE_TIMEOUT
+#    ifndef OLED_DISABLE_TIMEOUT
     // Wake up oled if user is using those fabulous keys!
-    if (ret)
-        oled_on();
-#endif
+    if (ret) oled_on();
+#    endif
 #endif
 
 #ifdef MOUSEKEY_ENABLE
@@ -350,7 +331,7 @@ MATRIX_LOOP_END:
 #endif
 
 #ifdef SERIAL_LINK_ENABLE
-       serial_link_update();
+    serial_link_update();
 #endif
 
 #ifdef VISUALIZER_ENABLE
@@ -366,7 +347,9 @@ MATRIX_LOOP_END:
 #endif
 
 #ifdef VELOCIKEY_ENABLE
-    if (velocikey_enabled()) { velocikey_decelerate();  }
+    if (velocikey_enabled()) {
+        velocikey_decelerate();
+    }
 #endif
 
     // update LED
@@ -380,8 +363,11 @@ MATRIX_LOOP_END:
  *
  * FIXME: needs doc
  */
-void keyboard_set_leds(uint8_t leds)
-{
-    if (debug_keyboard) { debug("keyboard_set_led: "); debug_hex8(leds); debug("\n"); }
+void keyboard_set_leds(uint8_t leds) {
+    if (debug_keyboard) {
+        debug("keyboard_set_led: ");
+        debug_hex8(leds);
+        debug("\n");
+    }
     led_set(leds);
 }
index 19f98c74ec770af90220ccf841073e2c95ea9b40..98ceca49b1a6d69ceaf133b5a515d4cb9a9bb87d 100644 (file)
@@ -21,7 +21,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdbool.h>
 #include <stdint.h>
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -40,7 +39,7 @@ typedef struct {
 } keyevent_t;
 
 /* equivalent test of keypos_t */
-#define KEYEQ(keya, keyb)       ((keya).row == (keyb).row && (keya).col == (keyb).col)
+#define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col)
 
 /* Rules for No Event:
  * 1) (time == 0) to handle (keyevent_t){} as empty event
@@ -51,11 +50,8 @@ static inline bool IS_PRESSED(keyevent_t event) { return (!IS_NOEVENT(event) &&
 static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) && !event.pressed); }
 
 /* Tick event */
-#define TICK                    (keyevent_t){           \
-    .key = (keypos_t){ .row = 255, .col = 255 },           \
-    .pressed = false,                                   \
-    .time = (timer_read() | 1)                          \
-}
+#define TICK \
+    (keyevent_t) { .key = (keypos_t){.row = 255, .col = 255}, .pressed = false, .time = (timer_read() | 1) }
 
 /* it runs once at early stage of startup before keyboard_init. */
 void keyboard_setup(void);
index d5904276eebbc1155a5ad6242a27b0eae44ebeba..fd5d606805e3ae710b1d34d2b5475283c6e8beca 100644 (file)
@@ -26,68 +26,68 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /* FIXME: Add doxygen comments here */
 
-#define IS_ERROR(code)           (KC_ROLL_OVER <= (code) && (code) <= KC_UNDEFINED)
-#define IS_ANY(code)             (KC_A         <= (code) && (code) <= 0xFF)
-#define IS_KEY(code)             (KC_A         <= (code) && (code) <= KC_EXSEL)
-#define IS_MOD(code)             (KC_LCTRL     <= (code) && (code) <= KC_RGUI)
-
-#define IS_SPECIAL(code)         ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
-#define IS_SYSTEM(code)          (KC_PWR       <= (code) && (code) <= KC_WAKE)
-#define IS_CONSUMER(code)        (KC_MUTE      <= (code) && (code) <= KC_BRID)
-
-#define IS_FN(code)              (KC_FN0       <= (code) && (code) <= KC_FN31)
-
-#define IS_MOUSEKEY(code)        (KC_MS_UP     <= (code) && (code) <= KC_MS_ACCEL2)
-#define IS_MOUSEKEY_MOVE(code)   (KC_MS_UP     <= (code) && (code) <= KC_MS_RIGHT)
-#define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1   <= (code) && (code) <= KC_MS_BTN5)
-#define IS_MOUSEKEY_WHEEL(code)  (KC_MS_WH_UP  <= (code) && (code) <= KC_MS_WH_RIGHT)
-#define IS_MOUSEKEY_ACCEL(code)  (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2)
-
-#define MOD_BIT(code)            (1 << MOD_INDEX(code))
-#define MOD_INDEX(code)          ((code) & 0x07)
-
-#define MOD_MASK_CTRL            (MOD_BIT(KC_LCTRL)  | MOD_BIT(KC_RCTRL))
-#define MOD_MASK_SHIFT           (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))
-#define MOD_MASK_ALT             (MOD_BIT(KC_LALT)   | MOD_BIT(KC_RALT))
-#define MOD_MASK_GUI             (MOD_BIT(KC_LGUI)   | MOD_BIT(KC_RGUI))
-#define MOD_MASK_CS              (MOD_MASK_CTRL  | MOD_MASK_SHIFT)
-#define MOD_MASK_CA              (MOD_MASK_CTRL  | MOD_MASK_ALT)
-#define MOD_MASK_CG              (MOD_MASK_CTRL  | MOD_MASK_GUI)
-#define MOD_MASK_SA              (MOD_MASK_SHIFT | MOD_MASK_ALT)
-#define MOD_MASK_SG              (MOD_MASK_SHIFT | MOD_MASK_GUI)
-#define MOD_MASK_AG              (MOD_MASK_ALT   | MOD_MASK_GUI)
-#define MOD_MASK_CSA             (MOD_MASK_CTRL  | MOD_MASK_SHIFT | MOD_MASK_ALT)
-#define MOD_MASK_CSG             (MOD_MASK_CTRL  | MOD_MASK_SHIFT | MOD_MASK_GUI)
-#define MOD_MASK_CAG             (MOD_MASK_CTRL  | MOD_MASK_ALT   | MOD_MASK_GUI)
-#define MOD_MASK_SAG             (MOD_MASK_SHIFT | MOD_MASK_ALT   | MOD_MASK_GUI)
-#define MOD_MASK_CSAG            (MOD_MASK_CTRL  | MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI)
-
-#define FN_BIT(code)             (1 << FN_INDEX(code))
-#define FN_INDEX(code)           ((code) - KC_FN0)
-#define FN_MIN                   KC_FN0
-#define FN_MAX                   KC_FN31
+#define IS_ERROR(code) (KC_ROLL_OVER <= (code) && (code) <= KC_UNDEFINED)
+#define IS_ANY(code) (KC_A <= (code) && (code) <= 0xFF)
+#define IS_KEY(code) (KC_A <= (code) && (code) <= KC_EXSEL)
+#define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI)
+
+#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
+#define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE)
+#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID)
+
+#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31)
+
+#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2)
+#define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT)
+#define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN5)
+#define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT)
+#define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2)
+
+#define MOD_BIT(code) (1 << MOD_INDEX(code))
+#define MOD_INDEX(code) ((code)&0x07)
+
+#define MOD_MASK_CTRL (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RCTRL))
+#define MOD_MASK_SHIFT (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))
+#define MOD_MASK_ALT (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))
+#define MOD_MASK_GUI (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))
+#define MOD_MASK_CS (MOD_MASK_CTRL | MOD_MASK_SHIFT)
+#define MOD_MASK_CA (MOD_MASK_CTRL | MOD_MASK_ALT)
+#define MOD_MASK_CG (MOD_MASK_CTRL | MOD_MASK_GUI)
+#define MOD_MASK_SA (MOD_MASK_SHIFT | MOD_MASK_ALT)
+#define MOD_MASK_SG (MOD_MASK_SHIFT | MOD_MASK_GUI)
+#define MOD_MASK_AG (MOD_MASK_ALT | MOD_MASK_GUI)
+#define MOD_MASK_CSA (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT)
+#define MOD_MASK_CSG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_GUI)
+#define MOD_MASK_CAG (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI)
+#define MOD_MASK_SAG (MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI)
+#define MOD_MASK_CSAG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI)
+
+#define FN_BIT(code) (1 << FN_INDEX(code))
+#define FN_INDEX(code) ((code)-KC_FN0)
+#define FN_MIN KC_FN0
+#define FN_MAX KC_FN31
 
 /*
  * Short names for ease of definition of keymap
  */
 /* Transparent */
 #define KC_TRANSPARENT 0x01
-#define KC_TRNS        KC_TRANSPARENT
+#define KC_TRNS KC_TRANSPARENT
 
 /* Punctuation */
-#define KC_ENT  KC_ENTER
-#define KC_ESC  KC_ESCAPE
+#define KC_ENT KC_ENTER
+#define KC_ESC KC_ESCAPE
 #define KC_BSPC KC_BSPACE
-#define KC_SPC  KC_SPACE
+#define KC_SPC KC_SPACE
 #define KC_MINS KC_MINUS
-#define KC_EQL  KC_EQUAL
+#define KC_EQL KC_EQUAL
 #define KC_LBRC KC_LBRACKET
 #define KC_RBRC KC_RBRACKET
 #define KC_BSLS KC_BSLASH
 #define KC_NUHS KC_NONUS_HASH
 #define KC_SCLN KC_SCOLON
 #define KC_QUOT KC_QUOTE
-#define KC_GRV  KC_GRAVE
+#define KC_GRV KC_GRAVE
 #define KC_COMM KC_COMMA
 #define KC_SLSH KC_SLASH
 #define KC_NUBS KC_NONUS_BSLASH
@@ -104,18 +104,18 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /* Commands */
 #define KC_PSCR KC_PSCREEN
 #define KC_PAUS KC_PAUSE
-#define KC_BRK  KC_PAUSE
-#define KC_INS  KC_INSERT
-#define KC_DEL  KC_DELETE
+#define KC_BRK KC_PAUSE
+#define KC_INS KC_INSERT
+#define KC_DEL KC_DELETE
 #define KC_PGDN KC_PGDOWN
 #define KC_RGHT KC_RIGHT
-#define KC_APP  KC_APPLICATION
+#define KC_APP KC_APPLICATION
 #define KC_EXEC KC_EXECUTE
 #define KC_SLCT KC_SELECT
 #define KC_AGIN KC_AGAIN
 #define KC_PSTE KC_PASTE
 #define KC_ERAS KC_ALT_ERASE
-#define KC_CLR  KC_CLEAR
+#define KC_CLR KC_CLEAR
 
 /* Keypad */
 #define KC_PSLS KC_KP_SLASH
@@ -123,23 +123,23 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define KC_PMNS KC_KP_MINUS
 #define KC_PPLS KC_KP_PLUS
 #define KC_PENT KC_KP_ENTER
-#define KC_P1   KC_KP_1
-#define KC_P2   KC_KP_2
-#define KC_P3   KC_KP_3
-#define KC_P4   KC_KP_4
-#define KC_P5   KC_KP_5
-#define KC_P6   KC_KP_6
-#define KC_P7   KC_KP_7
-#define KC_P8   KC_KP_8
-#define KC_P9   KC_KP_9
-#define KC_P0   KC_KP_0
+#define KC_P1 KC_KP_1
+#define KC_P2 KC_KP_2
+#define KC_P3 KC_KP_3
+#define KC_P4 KC_KP_4
+#define KC_P5 KC_KP_5
+#define KC_P6 KC_KP_6
+#define KC_P7 KC_KP_7
+#define KC_P8 KC_KP_8
+#define KC_P9 KC_KP_9
+#define KC_P0 KC_KP_0
 #define KC_PDOT KC_KP_DOT
 #define KC_PEQL KC_KP_EQUAL
 #define KC_PCMM KC_KP_COMMA
 
 /* Japanese specific */
 #define KC_ZKHK KC_GRAVE
-#define KC_RO   KC_INT1
+#define KC_RO KC_INT1
 #define KC_KANA KC_INT2
 #define KC_JYEN KC_INT3
 #define KC_HENK KC_INT4
@@ -161,7 +161,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define KC_RWIN KC_RGUI
 
 /* Generic Desktop Page (0x01) */
-#define KC_PWR  KC_SYSTEM_POWER
+#define KC_PWR KC_SYSTEM_POWER
 #define KC_SLEP KC_SYSTEM_SLEEP
 #define KC_WAKE KC_SYSTEM_WAKE
 
@@ -214,171 +214,171 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /* Keyboard/Keypad Page (0x07) */
 enum hid_keyboard_keypad_usage {
-  KC_NO                   = 0x00,
-  KC_ROLL_OVER,
-  KC_POST_FAIL,
-  KC_UNDEFINED,
-  KC_A,
-  KC_B,
-  KC_C,
-  KC_D,
-  KC_E,
-  KC_F,
-  KC_G,
-  KC_H,
-  KC_I,
-  KC_J,
-  KC_K,
-  KC_L,
-  KC_M,                   //0x10
-  KC_N,
-  KC_O,
-  KC_P,
-  KC_Q,
-  KC_R,
-  KC_S,
-  KC_T,
-  KC_U,
-  KC_V,
-  KC_W,
-  KC_X,
-  KC_Y,
-  KC_Z,
-  KC_1,
-  KC_2,
-  KC_3,                   //0x20
-  KC_4,
-  KC_5,
-  KC_6,
-  KC_7,
-  KC_8,
-  KC_9,
-  KC_0,
-  KC_ENTER,
-  KC_ESCAPE,
-  KC_BSPACE,
-  KC_TAB,
-  KC_SPACE,
-  KC_MINUS,
-  KC_EQUAL,
-  KC_LBRACKET,
-  KC_RBRACKET,            //0x30
-  KC_BSLASH,
-  KC_NONUS_HASH,
-  KC_SCOLON,
-  KC_QUOTE,
-  KC_GRAVE,
-  KC_COMMA,
-  KC_DOT,
-  KC_SLASH,
-  KC_CAPSLOCK,
-  KC_F1,
-  KC_F2,
-  KC_F3,
-  KC_F4,
-  KC_F5,
-  KC_F6,
-  KC_F7,                  //0x40
-  KC_F8,
-  KC_F9,
-  KC_F10,
-  KC_F11,
-  KC_F12,
-  KC_PSCREEN,
-  KC_SCROLLLOCK,
-  KC_PAUSE,
-  KC_INSERT,
-  KC_HOME,
-  KC_PGUP,
-  KC_DELETE,
-  KC_END,
-  KC_PGDOWN,
-  KC_RIGHT,
-  KC_LEFT,                //0x50
-  KC_DOWN,
-  KC_UP,
-  KC_NUMLOCK,
-  KC_KP_SLASH,
-  KC_KP_ASTERISK,
-  KC_KP_MINUS,
-  KC_KP_PLUS,
-  KC_KP_ENTER,
-  KC_KP_1,
-  KC_KP_2,
-  KC_KP_3,
-  KC_KP_4,
-  KC_KP_5,
-  KC_KP_6,
-  KC_KP_7,
-  KC_KP_8,                //0x60
-  KC_KP_9,
-  KC_KP_0,
-  KC_KP_DOT,
-  KC_NONUS_BSLASH,
-  KC_APPLICATION,
-  KC_POWER,
-  KC_KP_EQUAL,
-  KC_F13,
-  KC_F14,
-  KC_F15,
-  KC_F16,
-  KC_F17,
-  KC_F18,
-  KC_F19,
-  KC_F20,
-  KC_F21,                 //0x70
-  KC_F22,
-  KC_F23,
-  KC_F24,
-  KC_EXECUTE,
-  KC_HELP,
-  KC_MENU,
-  KC_SELECT,
-  KC_STOP,
-  KC_AGAIN,
-  KC_UNDO,
-  KC_CUT,
-  KC_COPY,
-  KC_PASTE,
-  KC_FIND,
-  KC__MUTE,
-  KC__VOLUP,              //0x80
-  KC__VOLDOWN,
-  KC_LOCKING_CAPS,
-  KC_LOCKING_NUM,
-  KC_LOCKING_SCROLL,
-  KC_KP_COMMA,
-  KC_KP_EQUAL_AS400,
-  KC_INT1,
-  KC_INT2,
-  KC_INT3,
-  KC_INT4,
-  KC_INT5,
-  KC_INT6,
-  KC_INT7,
-  KC_INT8,
-  KC_INT9,
-  KC_LANG1,               //0x90
-  KC_LANG2,
-  KC_LANG3,
-  KC_LANG4,
-  KC_LANG5,
-  KC_LANG6,
-  KC_LANG7,
-  KC_LANG8,
-  KC_LANG9,
-  KC_ALT_ERASE,
-  KC_SYSREQ,
-  KC_CANCEL,
-  KC_CLEAR,
-  KC_PRIOR,
-  KC_RETURN,
-  KC_SEPARATOR,
-  KC_OUT,                 //0xA0
-  KC_OPER,
-  KC_CLEAR_AGAIN,
-  KC_CRSEL,
-  KC_EXSEL,
+    KC_NO = 0x00,
+    KC_ROLL_OVER,
+    KC_POST_FAIL,
+    KC_UNDEFINED,
+    KC_A,
+    KC_B,
+    KC_C,
+    KC_D,
+    KC_E,
+    KC_F,
+    KC_G,
+    KC_H,
+    KC_I,
+    KC_J,
+    KC_K,
+    KC_L,
+    KC_M,  // 0x10
+    KC_N,
+    KC_O,
+    KC_P,
+    KC_Q,
+    KC_R,
+    KC_S,
+    KC_T,
+    KC_U,
+    KC_V,
+    KC_W,
+    KC_X,
+    KC_Y,
+    KC_Z,
+    KC_1,
+    KC_2,
+    KC_3,  // 0x20
+    KC_4,
+    KC_5,
+    KC_6,
+    KC_7,
+    KC_8,
+    KC_9,
+    KC_0,
+    KC_ENTER,
+    KC_ESCAPE,
+    KC_BSPACE,
+    KC_TAB,
+    KC_SPACE,
+    KC_MINUS,
+    KC_EQUAL,
+    KC_LBRACKET,
+    KC_RBRACKET,  // 0x30
+    KC_BSLASH,
+    KC_NONUS_HASH,
+    KC_SCOLON,
+    KC_QUOTE,
+    KC_GRAVE,
+    KC_COMMA,
+    KC_DOT,
+    KC_SLASH,
+    KC_CAPSLOCK,
+    KC_F1,
+    KC_F2,
+    KC_F3,
+    KC_F4,
+    KC_F5,
+    KC_F6,
+    KC_F7,  // 0x40
+    KC_F8,
+    KC_F9,
+    KC_F10,
+    KC_F11,
+    KC_F12,
+    KC_PSCREEN,
+    KC_SCROLLLOCK,
+    KC_PAUSE,
+    KC_INSERT,
+    KC_HOME,
+    KC_PGUP,
+    KC_DELETE,
+    KC_END,
+    KC_PGDOWN,
+    KC_RIGHT,
+    KC_LEFT,  // 0x50
+    KC_DOWN,
+    KC_UP,
+    KC_NUMLOCK,
+    KC_KP_SLASH,
+    KC_KP_ASTERISK,
+    KC_KP_MINUS,
+    KC_KP_PLUS,
+    KC_KP_ENTER,
+    KC_KP_1,
+    KC_KP_2,
+    KC_KP_3,
+    KC_KP_4,
+    KC_KP_5,
+    KC_KP_6,
+    KC_KP_7,
+    KC_KP_8,  // 0x60
+    KC_KP_9,
+    KC_KP_0,
+    KC_KP_DOT,
+    KC_NONUS_BSLASH,
+    KC_APPLICATION,
+    KC_POWER,
+    KC_KP_EQUAL,
+    KC_F13,
+    KC_F14,
+    KC_F15,
+    KC_F16,
+    KC_F17,
+    KC_F18,
+    KC_F19,
+    KC_F20,
+    KC_F21,  // 0x70
+    KC_F22,
+    KC_F23,
+    KC_F24,
+    KC_EXECUTE,
+    KC_HELP,
+    KC_MENU,
+    KC_SELECT,
+    KC_STOP,
+    KC_AGAIN,
+    KC_UNDO,
+    KC_CUT,
+    KC_COPY,
+    KC_PASTE,
+    KC_FIND,
+    KC__MUTE,
+    KC__VOLUP,  // 0x80
+    KC__VOLDOWN,
+    KC_LOCKING_CAPS,
+    KC_LOCKING_NUM,
+    KC_LOCKING_SCROLL,
+    KC_KP_COMMA,
+    KC_KP_EQUAL_AS400,
+    KC_INT1,
+    KC_INT2,
+    KC_INT3,
+    KC_INT4,
+    KC_INT5,
+    KC_INT6,
+    KC_INT7,
+    KC_INT8,
+    KC_INT9,
+    KC_LANG1,  // 0x90
+    KC_LANG2,
+    KC_LANG3,
+    KC_LANG4,
+    KC_LANG5,
+    KC_LANG6,
+    KC_LANG7,
+    KC_LANG8,
+    KC_LANG9,
+    KC_ALT_ERASE,
+    KC_SYSREQ,
+    KC_CANCEL,
+    KC_CLEAR,
+    KC_PRIOR,
+    KC_RETURN,
+    KC_SEPARATOR,
+    KC_OUT,  // 0xA0
+    KC_OPER,
+    KC_CLEAR_AGAIN,
+    KC_CRSEL,
+    KC_EXSEL,
 
 #if 0
   // ***************************************************************
@@ -435,110 +435,110 @@ enum hid_keyboard_keypad_usage {
   KC_KP_HEXADECIMAL,
 #endif
 
-  /* Modifiers */
-  KC_LCTRL                = 0xE0,
-  KC_LSHIFT,
-  KC_LALT,
-  KC_LGUI,
-  KC_RCTRL,
-  KC_RSHIFT,
-  KC_RALT,
-  KC_RGUI
-
-  // **********************************************
-  // * 0xF0-0xFF are unallocated in the HID spec. *
-  // * QMK uses these for Mouse Keys - see below. *
-  // **********************************************
+    /* Modifiers */
+    KC_LCTRL = 0xE0,
+    KC_LSHIFT,
+    KC_LALT,
+    KC_LGUI,
+    KC_RCTRL,
+    KC_RSHIFT,
+    KC_RALT,
+    KC_RGUI
+
+    // **********************************************
+    // * 0xF0-0xFF are unallocated in the HID spec. *
+    // * QMK uses these for Mouse Keys - see below. *
+    // **********************************************
 };
 
 /* Media and Function keys */
 enum internal_special_keycodes {
-  /* Generic Desktop Page (0x01) */
-  KC_SYSTEM_POWER         = 0xA5,
-  KC_SYSTEM_SLEEP,
-  KC_SYSTEM_WAKE,
-
-  /* Consumer Page (0x0C) */
-  KC_AUDIO_MUTE,
-  KC_AUDIO_VOL_UP,
-  KC_AUDIO_VOL_DOWN,
-  KC_MEDIA_NEXT_TRACK,
-  KC_MEDIA_PREV_TRACK,
-  KC_MEDIA_STOP,
-  KC_MEDIA_PLAY_PAUSE,
-  KC_MEDIA_SELECT,
-  KC_MEDIA_EJECT,         //0xB0
-  KC_MAIL,
-  KC_CALCULATOR,
-  KC_MY_COMPUTER,
-  KC_WWW_SEARCH,
-  KC_WWW_HOME,
-  KC_WWW_BACK,
-  KC_WWW_FORWARD,
-  KC_WWW_STOP,
-  KC_WWW_REFRESH,
-  KC_WWW_FAVORITES,
-  KC_MEDIA_FAST_FORWARD,
-  KC_MEDIA_REWIND,
-  KC_BRIGHTNESS_UP,
-  KC_BRIGHTNESS_DOWN,
-
-  /* Fn keys */
-  KC_FN0                  = 0xC0,
-  KC_FN1,
-  KC_FN2,
-  KC_FN3,
-  KC_FN4,
-  KC_FN5,
-  KC_FN6,
-  KC_FN7,
-  KC_FN8,
-  KC_FN9,
-  KC_FN10,
-  KC_FN11,
-  KC_FN12,
-  KC_FN13,
-  KC_FN14,
-  KC_FN15,
-  KC_FN16,                //0xD0
-  KC_FN17,
-  KC_FN18,
-  KC_FN19,
-  KC_FN20,
-  KC_FN21,
-  KC_FN22,
-  KC_FN23,
-  KC_FN24,
-  KC_FN25,
-  KC_FN26,
-  KC_FN27,
-  KC_FN28,
-  KC_FN29,
-  KC_FN30,
-  KC_FN31
+    /* Generic Desktop Page (0x01) */
+    KC_SYSTEM_POWER = 0xA5,
+    KC_SYSTEM_SLEEP,
+    KC_SYSTEM_WAKE,
+
+    /* Consumer Page (0x0C) */
+    KC_AUDIO_MUTE,
+    KC_AUDIO_VOL_UP,
+    KC_AUDIO_VOL_DOWN,
+    KC_MEDIA_NEXT_TRACK,
+    KC_MEDIA_PREV_TRACK,
+    KC_MEDIA_STOP,
+    KC_MEDIA_PLAY_PAUSE,
+    KC_MEDIA_SELECT,
+    KC_MEDIA_EJECT,  // 0xB0
+    KC_MAIL,
+    KC_CALCULATOR,
+    KC_MY_COMPUTER,
+    KC_WWW_SEARCH,
+    KC_WWW_HOME,
+    KC_WWW_BACK,
+    KC_WWW_FORWARD,
+    KC_WWW_STOP,
+    KC_WWW_REFRESH,
+    KC_WWW_FAVORITES,
+    KC_MEDIA_FAST_FORWARD,
+    KC_MEDIA_REWIND,
+    KC_BRIGHTNESS_UP,
+    KC_BRIGHTNESS_DOWN,
+
+    /* Fn keys */
+    KC_FN0 = 0xC0,
+    KC_FN1,
+    KC_FN2,
+    KC_FN3,
+    KC_FN4,
+    KC_FN5,
+    KC_FN6,
+    KC_FN7,
+    KC_FN8,
+    KC_FN9,
+    KC_FN10,
+    KC_FN11,
+    KC_FN12,
+    KC_FN13,
+    KC_FN14,
+    KC_FN15,
+    KC_FN16,  // 0xD0
+    KC_FN17,
+    KC_FN18,
+    KC_FN19,
+    KC_FN20,
+    KC_FN21,
+    KC_FN22,
+    KC_FN23,
+    KC_FN24,
+    KC_FN25,
+    KC_FN26,
+    KC_FN27,
+    KC_FN28,
+    KC_FN29,
+    KC_FN30,
+    KC_FN31
 };
 
 enum mouse_keys {
-  /* Mouse Buttons */
-  KC_MS_UP                = 0xF0,
-  KC_MS_DOWN,
-  KC_MS_LEFT,
-  KC_MS_RIGHT,
-  KC_MS_BTN1,
-  KC_MS_BTN2,
-  KC_MS_BTN3,
-  KC_MS_BTN4,
-  KC_MS_BTN5,
-
-  /* Mouse Wheel */
-  KC_MS_WH_UP,
-  KC_MS_WH_DOWN,
-  KC_MS_WH_LEFT,
-  KC_MS_WH_RIGHT,
-
-  /* Acceleration */
-  KC_MS_ACCEL0,
-  KC_MS_ACCEL1,
-  KC_MS_ACCEL2
+    /* Mouse Buttons */
+    KC_MS_UP = 0xF0,
+    KC_MS_DOWN,
+    KC_MS_LEFT,
+    KC_MS_RIGHT,
+    KC_MS_BTN1,
+    KC_MS_BTN2,
+    KC_MS_BTN3,
+    KC_MS_BTN4,
+    KC_MS_BTN5,
+
+    /* Mouse Wheel */
+    KC_MS_WH_UP,
+    KC_MS_WH_DOWN,
+    KC_MS_WH_LEFT,
+    KC_MS_WH_RIGHT,
+
+    /* Acceleration */
+    KC_MS_ACCEL0,
+    KC_MS_ACCEL1,
+    KC_MS_ACCEL2
 };
 #endif
index c16305129b9fca290bb0a31b8902c746d60de474..2c28fe5401a7da27afdc0be2eaeb22af976b03dd 100644 (file)
@@ -22,12 +22,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /* FIXME: Add doxygen comments here. */
 
 /* keyboard LEDs */
-#define USB_LED_NUM_LOCK                0
-#define USB_LED_CAPS_LOCK               1
-#define USB_LED_SCROLL_LOCK             2
-#define USB_LED_COMPOSE                 3
-#define USB_LED_KANA                    4
-
+#define USB_LED_NUM_LOCK 0
+#define USB_LED_CAPS_LOCK 1
+#define USB_LED_SCROLL_LOCK 2
+#define USB_LED_COMPOSE 3
+#define USB_LED_KANA 4
 
 #ifdef __cplusplus
 extern "C" {
index 2b1a6a6ad256e72696f4476ae921a2cdcef18246..d8ab525735110cc3539912aa89a1f9099a11099b 100644 (file)
@@ -1,7 +1,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #if defined(__AVR__)
-#include <util/delay.h>
+#    include <util/delay.h>
 #endif
 #include "matrix.h"
 #include "bootloader.h"
@@ -18,8 +18,7 @@ keymap_config_t keymap_config;
  *
  * FIXME: Needs doc
  */
-void magic(void)
-{
+void magic(void) {
     /* check signature */
     if (!eeconfig_is_enabled()) {
         eeconfig_init();
@@ -32,7 +31,6 @@ void magic(void)
     keymap_config.raw = eeconfig_read_keymap();
 
     uint8_t default_layer = 0;
-    default_layer = eeconfig_read_default_layer();
+    default_layer         = eeconfig_read_default_layer();
     default_layer_set((layer_state_t)default_layer);
-
 }
index e5665bf40a3f52baabfdd8a36d0ef89baf75fa01..7624d513763f21ede1389a83745d1a295a1697d0 100644 (file)
@@ -20,29 +20,27 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdint.h>
 #include <stdbool.h>
 
-
 #if (MATRIX_COLS <= 8)
-typedef  uint8_t    matrix_row_t;
+typedef uint8_t matrix_row_t;
 #elif (MATRIX_COLS <= 16)
-typedef  uint16_t   matrix_row_t;
+typedef uint16_t matrix_row_t;
 #elif (MATRIX_COLS <= 32)
-typedef  uint32_t   matrix_row_t;
+typedef uint32_t matrix_row_t;
 #else
-#error "MATRIX_COLS: invalid value"
+#    error "MATRIX_COLS: invalid value"
 #endif
 
 #if (MATRIX_ROWS <= 8)
-typedef  uint8_t    matrix_col_t;
+typedef uint8_t matrix_col_t;
 #elif (MATRIX_ROWS <= 16)
-typedef  uint16_t   matrix_col_t;
+typedef uint16_t matrix_col_t;
 #elif (MATRIX_ROWS <= 32)
-typedef  uint32_t   matrix_col_t;
+typedef uint32_t matrix_col_t;
 #else
-#error "MATRIX_ROWS: invalid value"
+#    error "MATRIX_ROWS: invalid value"
 #endif
 
-#define MATRIX_IS_ON(row, col)  (matrix_get_row(row) && (1<<col))
-
+#define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1 << col))
 
 #ifdef __cplusplus
 extern "C" {
@@ -59,7 +57,7 @@ void matrix_init(void);
 /* scan all key states on matrix */
 uint8_t matrix_scan(void);
 /* whether modified from previous scan. used after matrix_scan. */
-bool matrix_is_modified(void) __attribute__ ((deprecated));
+bool matrix_is_modified(void) __attribute__((deprecated));
 /* whether a switch is on */
 bool matrix_is_on(uint8_t row, uint8_t col);
 /* matrix state on row */
@@ -67,7 +65,6 @@ matrix_row_t matrix_get_row(uint8_t row);
 /* print matrix for debug */
 void matrix_print(void);
 
-
 /* power control */
 void matrix_power_up(void);
 void matrix_power_down(void);
@@ -83,8 +80,8 @@ void matrix_init_user(void);
 void matrix_scan_user(void);
 
 #ifdef I2C_SPLIT
-       void slave_matrix_init(void);
-       uint8_t slave_matrix_scan(void);
+void    slave_matrix_init(void);
+uint8_t slave_matrix_scan(void);
 #endif
 
 #ifdef __cplusplus
index b51e83943a0de4f42665b85bb414832dfd54f4cb..88945eb05054ec640e13b7aeafd90b16c74c8cc5 100644 (file)
@@ -1,4 +1,3 @@
 #include "bootloader.h"
 
-
 void bootloader_jump(void) {}
index 32651574f8a2800607be717c37636ded3008d546..3d0554f87bd3eae3093bf0b131e2dc59c601308f 100644 (file)
@@ -1,6 +1,5 @@
 #include <stdbool.h>
 
-
 void suspend_power_down(void) {}
 bool suspend_wakeup_condition(void) { return true; }
 void suspend_wakeup_init(void) {}
index c357ceb7863c92c07fd94f86da54c7642e8d2e2f..7e4070af2933211a0976f0a51c29fe07e3772b0f 100644 (file)
@@ -5,37 +5,19 @@
 volatile uint32_t timer_count = 0;
 
 /* Timer interrupt handler */
-void SysTick_Handler(void)  {
-    timer_count++;
-}
+void SysTick_Handler(void) { timer_count++; }
 
-void timer_init(void)
-{
+void timer_init(void) {
     timer_count = 0;
     SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */
 }
 
-void timer_clear(void)
-{
-    timer_count = 0;
-}
+void timer_clear(void) { timer_count = 0; }
 
-uint16_t timer_read(void)
-{
-    return (uint16_t)(timer_count & 0xFFFF);
-}
+uint16_t timer_read(void) { return (uint16_t)(timer_count & 0xFFFF); }
 
-uint32_t timer_read32(void)
-{
-    return timer_count;
-}
+uint32_t timer_read32(void) { return timer_count; }
 
-uint16_t timer_elapsed(uint16_t last)
-{
-    return TIMER_DIFF_16(timer_read(), last);
-}
+uint16_t timer_elapsed(uint16_t last) { return TIMER_DIFF_16(timer_read(), last); }
 
-uint32_t timer_elapsed32(uint32_t last)
-{
-    return TIMER_DIFF_32(timer_read32(), last);
-}
+uint32_t timer_elapsed32(uint32_t last) { return TIMER_DIFF_32(timer_read32(), last); }
index b1aac2c99d1e2e1248c6b1f4285e9ffa39a9d14a..184b7fa7a0a23ce5ba524eee7003b2ec30e8e694 100644 (file)
@@ -3,10 +3,9 @@
 #include "mbed.h"
 #include "mbed/xprintf.h"
 
+#define STRING_STACK_LIMIT 120
 
-#define STRING_STACK_LIMIT    120
-
-//TODO
+// TODO
 int __xprintf(const char* format, ...) { return 0; }
 
 #if 0
index 1e7a48c06dbe8c638dc4dd3456ef0bb3f40e601f..e27822d3a8eb47cfd35c8a724f4814753c9d652d 100644 (file)
@@ -13,5 +13,4 @@ int __xprintf(const char *format, ...);
 }
 #endif
 
-
 #endif
index bb08576b9faf96d0ca071f68adc28c781226896d..2df7728a41f34648f34cec5917505c2908963675 100644 (file)
@@ -24,25 +24,21 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "mousekey.h"
 
 inline int8_t times_inv_sqrt2(int8_t x) {
-  // 181/256 is pretty close to 1/sqrt(2)
-  // 0.70703125                 0.707106781
-  // 1 too small for x=99 and x=198
-  // This ends up being a mult and discard lower 8 bits
-  return (x * 181) >> 8;
+    // 181/256 is pretty close to 1/sqrt(2)
+    // 0.70703125                 0.707106781
+    // 1 too small for x=99 and x=198
+    // This ends up being a mult and discard lower 8 bits
+    return (x * 181) >> 8;
 }
 
 static report_mouse_t mouse_report = {0};
-static void mousekey_debug(void);
-static uint8_t mousekey_accel = 0;
-static uint8_t mousekey_repeat =  0;
-static uint16_t last_timer = 0;
-
-
+static void           mousekey_debug(void);
+static uint8_t        mousekey_accel  = 0;
+static uint8_t        mousekey_repeat = 0;
+static uint16_t       last_timer      = 0;
 
 #ifndef MK_3_SPEED
 
-
-
 /*
  * Mouse keys  acceleration algorithm
  *  http://en.wikipedia.org/wiki/Mouse_keys
@@ -50,7 +46,7 @@ static uint16_t last_timer = 0;
  *  speed = delta * max_speed * (repeat / time_to_max)**((1000+curve)/1000)
  */
 /* milliseconds between the initial key press and first repeated motion event (0-2550) */
-uint8_t mk_delay = MOUSEKEY_DELAY/10;
+uint8_t mk_delay = MOUSEKEY_DELAY / 10;
 /* milliseconds between repeated motion events (0-255) */
 uint8_t mk_interval = MOUSEKEY_INTERVAL;
 /* steady speed (in action_delta units) applied each event (0-255) */
@@ -58,268 +54,320 @@ uint8_t mk_max_speed = MOUSEKEY_MAX_SPEED;
 /* number of events (count) accelerating to steady speed (0-255) */
 uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
 /* ramp used to reach maximum pointer speed (NOT SUPPORTED) */
-//int8_t mk_curve = 0;
+// int8_t mk_curve = 0;
 /* wheel params */
-uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
+uint8_t mk_wheel_max_speed   = MOUSEKEY_WHEEL_MAX_SPEED;
 uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
 
 static uint8_t move_unit(void) {
-  uint16_t unit;
-  if (mousekey_accel & (1<<0)) {
-    unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/4;
-  } else if (mousekey_accel & (1<<1)) {
-    unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/2;
-  } else if (mousekey_accel & (1<<2)) {
-    unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed);
-  } else if (mousekey_repeat == 0) {
-    unit = MOUSEKEY_MOVE_DELTA;
-  } else if (mousekey_repeat >= mk_time_to_max) {
-    unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
-  } else {
-    unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
-  }
-  return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
+    uint16_t unit;
+    if (mousekey_accel & (1 << 0)) {
+        unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 4;
+    } else if (mousekey_accel & (1 << 1)) {
+        unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 2;
+    } else if (mousekey_accel & (1 << 2)) {
+        unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed);
+    } else if (mousekey_repeat == 0) {
+        unit = MOUSEKEY_MOVE_DELTA;
+    } else if (mousekey_repeat >= mk_time_to_max) {
+        unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
+    } else {
+        unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
+    }
+    return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
 }
 
 static uint8_t wheel_unit(void) {
-  uint16_t unit;
-  if (mousekey_accel & (1<<0)) {
-    unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/4;
-  } else if (mousekey_accel & (1<<1)) {
-    unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/2;
-  } else if (mousekey_accel & (1<<2)) {
-    unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
-  } else if (mousekey_repeat == 0) {
-    unit = MOUSEKEY_WHEEL_DELTA;
-  } else if (mousekey_repeat >= mk_wheel_time_to_max) {
-    unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
-  } else {
-    unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max;
-  }
-  return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
+    uint16_t unit;
+    if (mousekey_accel & (1 << 0)) {
+        unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 4;
+    } else if (mousekey_accel & (1 << 1)) {
+        unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
+    } else if (mousekey_accel & (1 << 2)) {
+        unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
+    } else if (mousekey_repeat == 0) {
+        unit = MOUSEKEY_WHEEL_DELTA;
+    } else if (mousekey_repeat >= mk_wheel_time_to_max) {
+        unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
+    } else {
+        unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max;
+    }
+    return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
 }
 
 void mousekey_task(void) {
-  if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay*10)) {
-    return;
-  }
-  if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) {
-    return;
-       }
-  if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
-  if (mouse_report.x > 0) mouse_report.x = move_unit();
-  if (mouse_report.x < 0) mouse_report.x = move_unit() * -1;
-  if (mouse_report.y > 0) mouse_report.y = move_unit();
-  if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
-  /* diagonal move [1/sqrt(2)] */
-  if (mouse_report.x && mouse_report.y) {
-    mouse_report.x = times_inv_sqrt2(mouse_report.x);
-    if (mouse_report.x == 0) { mouse_report.x = 1; }
-    mouse_report.y = times_inv_sqrt2(mouse_report.y);
-    if (mouse_report.y == 0) { mouse_report.y = 1; }
-  }
-  if (mouse_report.v > 0) mouse_report.v = wheel_unit();
-  if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1;
-  if (mouse_report.h > 0) mouse_report.h = wheel_unit();
-  if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1;
-  mousekey_send();
+    if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay * 10)) {
+        return;
+    }
+    if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) {
+        return;
+    }
+    if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
+    if (mouse_report.x > 0) mouse_report.x = move_unit();
+    if (mouse_report.x < 0) mouse_report.x = move_unit() * -1;
+    if (mouse_report.y > 0) mouse_report.y = move_unit();
+    if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
+    /* diagonal move [1/sqrt(2)] */
+    if (mouse_report.x && mouse_report.y) {
+        mouse_report.x = times_inv_sqrt2(mouse_report.x);
+        if (mouse_report.x == 0) {
+            mouse_report.x = 1;
+        }
+        mouse_report.y = times_inv_sqrt2(mouse_report.y);
+        if (mouse_report.y == 0) {
+            mouse_report.y = 1;
+        }
+    }
+    if (mouse_report.v > 0) mouse_report.v = wheel_unit();
+    if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1;
+    if (mouse_report.h > 0) mouse_report.h = wheel_unit();
+    if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1;
+    mousekey_send();
 }
 
 void mousekey_on(uint8_t code) {
-  if      (code == KC_MS_UP)       mouse_report.y = move_unit() * -1;
-  else if (code == KC_MS_DOWN)     mouse_report.y = move_unit();
-  else if (code == KC_MS_LEFT)     mouse_report.x = move_unit() * -1;
-  else if (code == KC_MS_RIGHT)    mouse_report.x = move_unit();
-  else if (code == KC_MS_WH_UP)    mouse_report.v = wheel_unit();
-  else if (code == KC_MS_WH_DOWN)  mouse_report.v = wheel_unit() * -1;
-  else if (code == KC_MS_WH_LEFT)  mouse_report.h = wheel_unit() * -1;
-  else if (code == KC_MS_WH_RIGHT) mouse_report.h = wheel_unit();
-  else if (code == KC_MS_BTN1)     mouse_report.buttons |= MOUSE_BTN1;
-  else if (code == KC_MS_BTN2)     mouse_report.buttons |= MOUSE_BTN2;
-  else if (code == KC_MS_BTN3)     mouse_report.buttons |= MOUSE_BTN3;
-  else if (code == KC_MS_BTN4)     mouse_report.buttons |= MOUSE_BTN4;
-  else if (code == KC_MS_BTN5)     mouse_report.buttons |= MOUSE_BTN5;
-  else if (code == KC_MS_ACCEL0)   mousekey_accel |= (1<<0);
-  else if (code == KC_MS_ACCEL1)   mousekey_accel |= (1<<1);
-  else if (code == KC_MS_ACCEL2)   mousekey_accel |= (1<<2);
+    if (code == KC_MS_UP)
+        mouse_report.y = move_unit() * -1;
+    else if (code == KC_MS_DOWN)
+        mouse_report.y = move_unit();
+    else if (code == KC_MS_LEFT)
+        mouse_report.x = move_unit() * -1;
+    else if (code == KC_MS_RIGHT)
+        mouse_report.x = move_unit();
+    else if (code == KC_MS_WH_UP)
+        mouse_report.v = wheel_unit();
+    else if (code == KC_MS_WH_DOWN)
+        mouse_report.v = wheel_unit() * -1;
+    else if (code == KC_MS_WH_LEFT)
+        mouse_report.h = wheel_unit() * -1;
+    else if (code == KC_MS_WH_RIGHT)
+        mouse_report.h = wheel_unit();
+    else if (code == KC_MS_BTN1)
+        mouse_report.buttons |= MOUSE_BTN1;
+    else if (code == KC_MS_BTN2)
+        mouse_report.buttons |= MOUSE_BTN2;
+    else if (code == KC_MS_BTN3)
+        mouse_report.buttons |= MOUSE_BTN3;
+    else if (code == KC_MS_BTN4)
+        mouse_report.buttons |= MOUSE_BTN4;
+    else if (code == KC_MS_BTN5)
+        mouse_report.buttons |= MOUSE_BTN5;
+    else if (code == KC_MS_ACCEL0)
+        mousekey_accel |= (1 << 0);
+    else if (code == KC_MS_ACCEL1)
+        mousekey_accel |= (1 << 1);
+    else if (code == KC_MS_ACCEL2)
+        mousekey_accel |= (1 << 2);
 }
 
 void mousekey_off(uint8_t code) {
-  if      (code == KC_MS_UP       && mouse_report.y < 0) mouse_report.y = 0;
-  else if (code == KC_MS_DOWN     && mouse_report.y > 0) mouse_report.y = 0;
-  else if (code == KC_MS_LEFT     && mouse_report.x < 0) mouse_report.x = 0;
-  else if (code == KC_MS_RIGHT    && mouse_report.x > 0) mouse_report.x = 0;
-  else if (code == KC_MS_WH_UP    && mouse_report.v > 0) mouse_report.v = 0;
-  else if (code == KC_MS_WH_DOWN  && mouse_report.v < 0) mouse_report.v = 0;
-  else if (code == KC_MS_WH_LEFT  && mouse_report.h < 0) mouse_report.h = 0;
-  else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) mouse_report.h = 0;
-  else if (code == KC_MS_BTN1) mouse_report.buttons &= ~MOUSE_BTN1;
-  else if (code == KC_MS_BTN2) mouse_report.buttons &= ~MOUSE_BTN2;
-  else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3;
-  else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4;
-  else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5;
-  else if (code == KC_MS_ACCEL0) mousekey_accel &= ~(1<<0);
-  else if (code == KC_MS_ACCEL1) mousekey_accel &= ~(1<<1);
-  else if (code == KC_MS_ACCEL2) mousekey_accel &= ~(1<<2);
-  if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0)
-    mousekey_repeat = 0;
+    if (code == KC_MS_UP && mouse_report.y < 0)
+        mouse_report.y = 0;
+    else if (code == KC_MS_DOWN && mouse_report.y > 0)
+        mouse_report.y = 0;
+    else if (code == KC_MS_LEFT && mouse_report.x < 0)
+        mouse_report.x = 0;
+    else if (code == KC_MS_RIGHT && mouse_report.x > 0)
+        mouse_report.x = 0;
+    else if (code == KC_MS_WH_UP && mouse_report.v > 0)
+        mouse_report.v = 0;
+    else if (code == KC_MS_WH_DOWN && mouse_report.v < 0)
+        mouse_report.v = 0;
+    else if (code == KC_MS_WH_LEFT && mouse_report.h < 0)
+        mouse_report.h = 0;
+    else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0)
+        mouse_report.h = 0;
+    else if (code == KC_MS_BTN1)
+        mouse_report.buttons &= ~MOUSE_BTN1;
+    else if (code == KC_MS_BTN2)
+        mouse_report.buttons &= ~MOUSE_BTN2;
+    else if (code == KC_MS_BTN3)
+        mouse_report.buttons &= ~MOUSE_BTN3;
+    else if (code == KC_MS_BTN4)
+        mouse_report.buttons &= ~MOUSE_BTN4;
+    else if (code == KC_MS_BTN5)
+        mouse_report.buttons &= ~MOUSE_BTN5;
+    else if (code == KC_MS_ACCEL0)
+        mousekey_accel &= ~(1 << 0);
+    else if (code == KC_MS_ACCEL1)
+        mousekey_accel &= ~(1 << 1);
+    else if (code == KC_MS_ACCEL2)
+        mousekey_accel &= ~(1 << 2);
+    if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) mousekey_repeat = 0;
 }
 
+#else /* #ifndef MK_3_SPEED */
 
-
-
-#else  /* #ifndef MK_3_SPEED */
-
-
-
-enum {
-  mkspd_unmod,
-  mkspd_0,
-  mkspd_1,
-  mkspd_2,
-  mkspd_COUNT
-};
-#ifndef MK_MOMENTARY_ACCEL
-static uint8_t mk_speed = mkspd_1;
-#else
-static uint8_t mk_speed = mkspd_unmod;
+enum { mkspd_unmod, mkspd_0, mkspd_1, mkspd_2, mkspd_COUNT };
+#    ifndef MK_MOMENTARY_ACCEL
+static uint8_t  mk_speed                 = mkspd_1;
+#    else
+static uint8_t mk_speed      = mkspd_unmod;
 static uint8_t mkspd_DEFAULT = mkspd_unmod;
-#endif
-static uint16_t last_timer_c = 0;
-static uint16_t last_timer_w = 0;
-uint16_t c_offsets[mkspd_COUNT] = {
-  MK_C_OFFSET_UNMOD, MK_C_OFFSET_0, MK_C_OFFSET_1, MK_C_OFFSET_2
-};
-uint16_t c_intervals[mkspd_COUNT] = {
-  MK_C_INTERVAL_UNMOD, MK_C_INTERVAL_0, MK_C_INTERVAL_1, MK_C_INTERVAL_2
-};
-uint16_t w_offsets[mkspd_COUNT] = {
-  MK_W_OFFSET_UNMOD, MK_W_OFFSET_0, MK_W_OFFSET_1, MK_W_OFFSET_2
-};
-uint16_t w_intervals[mkspd_COUNT] = {
-  MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0, MK_W_INTERVAL_1, MK_W_INTERVAL_2
-};
-
+#    endif
+static uint16_t last_timer_c             = 0;
+static uint16_t last_timer_w             = 0;
+uint16_t        c_offsets[mkspd_COUNT]   = {MK_C_OFFSET_UNMOD, MK_C_OFFSET_0, MK_C_OFFSET_1, MK_C_OFFSET_2};
+uint16_t        c_intervals[mkspd_COUNT] = {MK_C_INTERVAL_UNMOD, MK_C_INTERVAL_0, MK_C_INTERVAL_1, MK_C_INTERVAL_2};
+uint16_t        w_offsets[mkspd_COUNT]   = {MK_W_OFFSET_UNMOD, MK_W_OFFSET_0, MK_W_OFFSET_1, MK_W_OFFSET_2};
+uint16_t        w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0, MK_W_INTERVAL_1, MK_W_INTERVAL_2};
 
 void mousekey_task(void) {
-  // report cursor and scroll movement independently
-  report_mouse_t const tmpmr = mouse_report;
-  if ((mouse_report.x  ||  mouse_report.y)  &&  timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
-  mouse_report.h = 0;
-  mouse_report.v = 0;
-  mousekey_send();
-  last_timer_c = last_timer;
-  mouse_report = tmpmr;
-  }
-  if ((mouse_report.h  ||  mouse_report.v)  &&  timer_elapsed(last_timer_w) > w_intervals[mk_speed]) {
-  mouse_report.x = 0;
-  mouse_report.y = 0;
-  mousekey_send();
-  last_timer_w = last_timer;
-  mouse_report = tmpmr;
-  }
+    // report cursor and scroll movement independently
+    report_mouse_t const tmpmr = mouse_report;
+    if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
+        mouse_report.h = 0;
+        mouse_report.v = 0;
+        mousekey_send();
+        last_timer_c = last_timer;
+        mouse_report = tmpmr;
+    }
+    if ((mouse_report.h || mouse_report.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) {
+        mouse_report.x = 0;
+        mouse_report.y = 0;
+        mousekey_send();
+        last_timer_w = last_timer;
+        mouse_report = tmpmr;
+    }
 }
 
 void adjust_speed(void) {
-  uint16_t const c_offset = c_offsets[mk_speed];
-  uint16_t const w_offset = w_offsets[mk_speed];
-  if (mouse_report.x > 0) mouse_report.x = c_offset;
-  if (mouse_report.x < 0) mouse_report.x = c_offset * -1;
-  if (mouse_report.y > 0) mouse_report.y = c_offset;
-  if (mouse_report.y < 0) mouse_report.y = c_offset * -1;
-  if (mouse_report.h > 0) mouse_report.h = w_offset;
-  if (mouse_report.h < 0) mouse_report.h = w_offset * -1;
-  if (mouse_report.v > 0) mouse_report.v = w_offset;
-  if (mouse_report.v < 0) mouse_report.v = w_offset * -1;
-  // adjust for diagonals
-  if (mouse_report.x && mouse_report.y) {
-  mouse_report.x = times_inv_sqrt2(mouse_report.x);
-  if (mouse_report.x == 0) { mouse_report.x = 1; }
-  mouse_report.y = times_inv_sqrt2(mouse_report.y);
-  if (mouse_report.y == 0) { mouse_report.y = 1; }
-  }
-  if (mouse_report.h && mouse_report.v) {
-  mouse_report.h = times_inv_sqrt2(mouse_report.h);
-  mouse_report.v = times_inv_sqrt2(mouse_report.v);
-  }
+    uint16_t const c_offset = c_offsets[mk_speed];
+    uint16_t const w_offset = w_offsets[mk_speed];
+    if (mouse_report.x > 0) mouse_report.x = c_offset;
+    if (mouse_report.x < 0) mouse_report.x = c_offset * -1;
+    if (mouse_report.y > 0) mouse_report.y = c_offset;
+    if (mouse_report.y < 0) mouse_report.y = c_offset * -1;
+    if (mouse_report.h > 0) mouse_report.h = w_offset;
+    if (mouse_report.h < 0) mouse_report.h = w_offset * -1;
+    if (mouse_report.v > 0) mouse_report.v = w_offset;
+    if (mouse_report.v < 0) mouse_report.v = w_offset * -1;
+    // adjust for diagonals
+    if (mouse_report.x && mouse_report.y) {
+        mouse_report.x = times_inv_sqrt2(mouse_report.x);
+        if (mouse_report.x == 0) {
+            mouse_report.x = 1;
+        }
+        mouse_report.y = times_inv_sqrt2(mouse_report.y);
+        if (mouse_report.y == 0) {
+            mouse_report.y = 1;
+        }
+    }
+    if (mouse_report.h && mouse_report.v) {
+        mouse_report.h = times_inv_sqrt2(mouse_report.h);
+        mouse_report.v = times_inv_sqrt2(mouse_report.v);
+    }
 }
 
 void mousekey_on(uint8_t code) {
-  uint16_t const c_offset = c_offsets[mk_speed];
-  uint16_t const w_offset = w_offsets[mk_speed];
-  uint8_t const old_speed = mk_speed;
-  if      (code == KC_MS_UP)       mouse_report.y = c_offset * -1;
-  else if (code == KC_MS_DOWN)     mouse_report.y = c_offset;
-  else if (code == KC_MS_LEFT)     mouse_report.x = c_offset * -1;
-  else if (code == KC_MS_RIGHT)    mouse_report.x = c_offset;
-  else if (code == KC_MS_WH_UP)    mouse_report.v = w_offset;
-  else if (code == KC_MS_WH_DOWN)  mouse_report.v = w_offset * -1;
-  else if (code == KC_MS_WH_LEFT)  mouse_report.h = w_offset * -1;
-  else if (code == KC_MS_WH_RIGHT) mouse_report.h = w_offset;
-  else if (code == KC_MS_BTN1)     mouse_report.buttons |= MOUSE_BTN1;
-  else if (code == KC_MS_BTN2)     mouse_report.buttons |= MOUSE_BTN2;
-  else if (code == KC_MS_BTN3)     mouse_report.buttons |= MOUSE_BTN3;
-  else if (code == KC_MS_BTN4)     mouse_report.buttons |= MOUSE_BTN4;
-  else if (code == KC_MS_BTN5)     mouse_report.buttons |= MOUSE_BTN5;
-  else if (code == KC_MS_ACCEL0)   mk_speed = mkspd_0;
-  else if (code == KC_MS_ACCEL1)   mk_speed = mkspd_1;
-  else if (code == KC_MS_ACCEL2)   mk_speed = mkspd_2;
-  if (mk_speed != old_speed) adjust_speed();
+    uint16_t const c_offset  = c_offsets[mk_speed];
+    uint16_t const w_offset  = w_offsets[mk_speed];
+    uint8_t const  old_speed = mk_speed;
+    if (code == KC_MS_UP)
+        mouse_report.y = c_offset * -1;
+    else if (code == KC_MS_DOWN)
+        mouse_report.y = c_offset;
+    else if (code == KC_MS_LEFT)
+        mouse_report.x = c_offset * -1;
+    else if (code == KC_MS_RIGHT)
+        mouse_report.x = c_offset;
+    else if (code == KC_MS_WH_UP)
+        mouse_report.v = w_offset;
+    else if (code == KC_MS_WH_DOWN)
+        mouse_report.v = w_offset * -1;
+    else if (code == KC_MS_WH_LEFT)
+        mouse_report.h = w_offset * -1;
+    else if (code == KC_MS_WH_RIGHT)
+        mouse_report.h = w_offset;
+    else if (code == KC_MS_BTN1)
+        mouse_report.buttons |= MOUSE_BTN1;
+    else if (code == KC_MS_BTN2)
+        mouse_report.buttons |= MOUSE_BTN2;
+    else if (code == KC_MS_BTN3)
+        mouse_report.buttons |= MOUSE_BTN3;
+    else if (code == KC_MS_BTN4)
+        mouse_report.buttons |= MOUSE_BTN4;
+    else if (code == KC_MS_BTN5)
+        mouse_report.buttons |= MOUSE_BTN5;
+    else if (code == KC_MS_ACCEL0)
+        mk_speed = mkspd_0;
+    else if (code == KC_MS_ACCEL1)
+        mk_speed = mkspd_1;
+    else if (code == KC_MS_ACCEL2)
+        mk_speed = mkspd_2;
+    if (mk_speed != old_speed) adjust_speed();
 }
 
 void mousekey_off(uint8_t code) {
-#ifdef MK_MOMENTARY_ACCEL
-  uint8_t const old_speed = mk_speed;
-#endif
-  if      (code == KC_MS_UP       && mouse_report.y < 0) mouse_report.y = 0;
-  else if (code == KC_MS_DOWN     && mouse_report.y > 0) mouse_report.y = 0;
-  else if (code == KC_MS_LEFT     && mouse_report.x < 0) mouse_report.x = 0;
-  else if (code == KC_MS_RIGHT    && mouse_report.x > 0) mouse_report.x = 0;
-  else if (code == KC_MS_WH_UP    && mouse_report.v > 0) mouse_report.v = 0;
-  else if (code == KC_MS_WH_DOWN  && mouse_report.v < 0) mouse_report.v = 0;
-  else if (code == KC_MS_WH_LEFT  && mouse_report.h < 0) mouse_report.h = 0;
-  else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) mouse_report.h = 0;
-  else if (code == KC_MS_BTN1) mouse_report.buttons &= ~MOUSE_BTN1;
-  else if (code == KC_MS_BTN2) mouse_report.buttons &= ~MOUSE_BTN2;
-  else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3;
-  else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4;
-  else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5;
-#ifdef MK_MOMENTARY_ACCEL
-  else if (code == KC_MS_ACCEL0) mk_speed = mkspd_DEFAULT;
-  else if (code == KC_MS_ACCEL1) mk_speed = mkspd_DEFAULT;
-  else if (code == KC_MS_ACCEL2) mk_speed = mkspd_DEFAULT;
-  if (mk_speed != old_speed) adjust_speed();
-#endif
+#    ifdef MK_MOMENTARY_ACCEL
+    uint8_t const old_speed = mk_speed;
+#    endif
+    if (code == KC_MS_UP && mouse_report.y < 0)
+        mouse_report.y = 0;
+    else if (code == KC_MS_DOWN && mouse_report.y > 0)
+        mouse_report.y = 0;
+    else if (code == KC_MS_LEFT && mouse_report.x < 0)
+        mouse_report.x = 0;
+    else if (code == KC_MS_RIGHT && mouse_report.x > 0)
+        mouse_report.x = 0;
+    else if (code == KC_MS_WH_UP && mouse_report.v > 0)
+        mouse_report.v = 0;
+    else if (code == KC_MS_WH_DOWN && mouse_report.v < 0)
+        mouse_report.v = 0;
+    else if (code == KC_MS_WH_LEFT && mouse_report.h < 0)
+        mouse_report.h = 0;
+    else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0)
+        mouse_report.h = 0;
+    else if (code == KC_MS_BTN1)
+        mouse_report.buttons &= ~MOUSE_BTN1;
+    else if (code == KC_MS_BTN2)
+        mouse_report.buttons &= ~MOUSE_BTN2;
+    else if (code == KC_MS_BTN3)
+        mouse_report.buttons &= ~MOUSE_BTN3;
+    else if (code == KC_MS_BTN4)
+        mouse_report.buttons &= ~MOUSE_BTN4;
+    else if (code == KC_MS_BTN5)
+        mouse_report.buttons &= ~MOUSE_BTN5;
+#    ifdef MK_MOMENTARY_ACCEL
+    else if (code == KC_MS_ACCEL0)
+        mk_speed = mkspd_DEFAULT;
+    else if (code == KC_MS_ACCEL1)
+        mk_speed = mkspd_DEFAULT;
+    else if (code == KC_MS_ACCEL2)
+        mk_speed = mkspd_DEFAULT;
+    if (mk_speed != old_speed) adjust_speed();
+#    endif
 }
 
-
-
-
 #endif /* #ifndef MK_3_SPEED */
 
-
-
-
 void mousekey_send(void) {
-  mousekey_debug();
-  host_mouse_send(&mouse_report);
-  last_timer = timer_read();
+    mousekey_debug();
+    host_mouse_send(&mouse_report);
+    last_timer = timer_read();
 }
 
 void mousekey_clear(void) {
-  mouse_report = (report_mouse_t){};
-  mousekey_repeat = 0;
-  mousekey_accel = 0;
+    mouse_report    = (report_mouse_t){};
+    mousekey_repeat = 0;
+    mousekey_accel  = 0;
 }
 
 static void mousekey_debug(void) {
-  if (!debug_mouse) return;
-  print("mousekey [btn|x y v h](rep/acl): [");
-  phex(mouse_report.buttons); print("|");
-  print_decs(mouse_report.x); print(" ");
-  print_decs(mouse_report.y); print(" ");
-  print_decs(mouse_report.v); print(" ");
-  print_decs(mouse_report.h); print("](");
-  print_dec(mousekey_repeat); print("/");
-  print_dec(mousekey_accel); print(")\n");
+    if (!debug_mouse) return;
+    print("mousekey [btn|x y v h](rep/acl): [");
+    phex(mouse_report.buttons);
+    print("|");
+    print_decs(mouse_report.x);
+    print(" ");
+    print_decs(mouse_report.y);
+    print(" ");
+    print_decs(mouse_report.v);
+    print(" ");
+    print_decs(mouse_report.h);
+    print("](");
+    print_dec(mousekey_repeat);
+    print("/");
+    print_dec(mousekey_accel);
+    print(")\n");
 }
index 89c1eaf11a5ff5f5feec409ecea6a97a3341cf26..48946987ceec8cbe816fc8975d669e5b3900a953 100644 (file)
@@ -16,7 +16,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef MOUSEKEY_H
-#define MOUSEKEY_H
+#    define MOUSEKEY_H
 #endif
 
 #include <stdbool.h>
@@ -25,94 +25,94 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef MK_3_SPEED
 
 /* max value on report descriptor */
-#ifndef MOUSEKEY_MOVE_MAX
-  #define MOUSEKEY_MOVE_MAX       127
-#elif MOUSEKEY_MOVE_MAX > 127
-  #error MOUSEKEY_MOVE_MAX needs to be smaller than 127
-#endif
-
-#ifndef MOUSEKEY_WHEEL_MAX
-  #define MOUSEKEY_WHEEL_MAX      127
-#elif MOUSEKEY_WHEEL_MAX > 127
-  #error MOUSEKEY_WHEEL_MAX needs to be smaller than 127
-#endif
-
-#ifndef MOUSEKEY_MOVE_DELTA
-#define MOUSEKEY_MOVE_DELTA     5
-#endif
-#ifndef MOUSEKEY_WHEEL_DELTA
-#define MOUSEKEY_WHEEL_DELTA    1
-#endif
-#ifndef MOUSEKEY_DELAY
-#define MOUSEKEY_DELAY 300
-#endif
-#ifndef MOUSEKEY_INTERVAL
-#define MOUSEKEY_INTERVAL 50
-#endif
-#ifndef MOUSEKEY_MAX_SPEED
-#define MOUSEKEY_MAX_SPEED 10
-#endif
-#ifndef MOUSEKEY_TIME_TO_MAX
-#define MOUSEKEY_TIME_TO_MAX 20
-#endif
-#ifndef MOUSEKEY_WHEEL_MAX_SPEED
-#define MOUSEKEY_WHEEL_MAX_SPEED 8
-#endif
-#ifndef MOUSEKEY_WHEEL_TIME_TO_MAX
-#define MOUSEKEY_WHEEL_TIME_TO_MAX 40
-#endif
+#    ifndef MOUSEKEY_MOVE_MAX
+#        define MOUSEKEY_MOVE_MAX 127
+#    elif MOUSEKEY_MOVE_MAX > 127
+#        error MOUSEKEY_MOVE_MAX needs to be smaller than 127
+#    endif
+
+#    ifndef MOUSEKEY_WHEEL_MAX
+#        define MOUSEKEY_WHEEL_MAX 127
+#    elif MOUSEKEY_WHEEL_MAX > 127
+#        error MOUSEKEY_WHEEL_MAX needs to be smaller than 127
+#    endif
+
+#    ifndef MOUSEKEY_MOVE_DELTA
+#        define MOUSEKEY_MOVE_DELTA 5
+#    endif
+#    ifndef MOUSEKEY_WHEEL_DELTA
+#        define MOUSEKEY_WHEEL_DELTA 1
+#    endif
+#    ifndef MOUSEKEY_DELAY
+#        define MOUSEKEY_DELAY 300
+#    endif
+#    ifndef MOUSEKEY_INTERVAL
+#        define MOUSEKEY_INTERVAL 50
+#    endif
+#    ifndef MOUSEKEY_MAX_SPEED
+#        define MOUSEKEY_MAX_SPEED 10
+#    endif
+#    ifndef MOUSEKEY_TIME_TO_MAX
+#        define MOUSEKEY_TIME_TO_MAX 20
+#    endif
+#    ifndef MOUSEKEY_WHEEL_MAX_SPEED
+#        define MOUSEKEY_WHEEL_MAX_SPEED 8
+#    endif
+#    ifndef MOUSEKEY_WHEEL_TIME_TO_MAX
+#        define MOUSEKEY_WHEEL_TIME_TO_MAX 40
+#    endif
 
 #else /* #ifndef MK_3_SPEED */
 
-#ifndef MK_C_OFFSET_UNMOD
-#define MK_C_OFFSET_UNMOD 16
-#endif
-#ifndef MK_C_INTERVAL_UNMOD
-#define MK_C_INTERVAL_UNMOD 16
-#endif
-#ifndef MK_C_OFFSET_0
-#define MK_C_OFFSET_0 1
-#endif
-#ifndef MK_C_INTERVAL_0
-#define MK_C_INTERVAL_0 32
-#endif
-#ifndef MK_C_OFFSET_1
-#define MK_C_OFFSET_1 4
-#endif
-#ifndef MK_C_INTERVAL_1
-#define MK_C_INTERVAL_1 16
-#endif
-#ifndef MK_C_OFFSET_2
-#define MK_C_OFFSET_2 32
-#endif
-#ifndef MK_C_INTERVAL_2
-#define MK_C_INTERVAL_2 16
-#endif
-
-#ifndef MK_W_OFFSET_UNMOD
-#define MK_W_OFFSET_UNMOD 1
-#endif
-#ifndef MK_W_INTERVAL_UNMOD
-#define MK_W_INTERVAL_UNMOD 40
-#endif
-#ifndef MK_W_OFFSET_0
-#define MK_W_OFFSET_0 1
-#endif
-#ifndef MK_W_INTERVAL_0
-#define MK_W_INTERVAL_0 360
-#endif
-#ifndef MK_W_OFFSET_1
-#define MK_W_OFFSET_1 1
-#endif
-#ifndef MK_W_INTERVAL_1
-#define MK_W_INTERVAL_1 120
-#endif
-#ifndef MK_W_OFFSET_2
-#define MK_W_OFFSET_2 1
-#endif
-#ifndef MK_W_INTERVAL_2
-#define MK_W_INTERVAL_2 20
-#endif
+#    ifndef MK_C_OFFSET_UNMOD
+#        define MK_C_OFFSET_UNMOD 16
+#    endif
+#    ifndef MK_C_INTERVAL_UNMOD
+#        define MK_C_INTERVAL_UNMOD 16
+#    endif
+#    ifndef MK_C_OFFSET_0
+#        define MK_C_OFFSET_0 1
+#    endif
+#    ifndef MK_C_INTERVAL_0
+#        define MK_C_INTERVAL_0 32
+#    endif
+#    ifndef MK_C_OFFSET_1
+#        define MK_C_OFFSET_1 4
+#    endif
+#    ifndef MK_C_INTERVAL_1
+#        define MK_C_INTERVAL_1 16
+#    endif
+#    ifndef MK_C_OFFSET_2
+#        define MK_C_OFFSET_2 32
+#    endif
+#    ifndef MK_C_INTERVAL_2
+#        define MK_C_INTERVAL_2 16
+#    endif
+
+#    ifndef MK_W_OFFSET_UNMOD
+#        define MK_W_OFFSET_UNMOD 1
+#    endif
+#    ifndef MK_W_INTERVAL_UNMOD
+#        define MK_W_INTERVAL_UNMOD 40
+#    endif
+#    ifndef MK_W_OFFSET_0
+#        define MK_W_OFFSET_0 1
+#    endif
+#    ifndef MK_W_INTERVAL_0
+#        define MK_W_INTERVAL_0 360
+#    endif
+#    ifndef MK_W_OFFSET_1
+#        define MK_W_OFFSET_1 1
+#    endif
+#    ifndef MK_W_INTERVAL_1
+#        define MK_W_INTERVAL_1 120
+#    endif
+#    ifndef MK_W_OFFSET_2
+#        define MK_W_OFFSET_2 1
+#    endif
+#    ifndef MK_W_INTERVAL_2
+#        define MK_W_INTERVAL_2 20
+#    endif
 
 #endif /* #ifndef MK_3_SPEED */
 
index 5e18656e5bf180747a7137c2778a8603c87fe0ca..b9c8b3ac0f3f5495f4e442ffab469e4bcfe0cb61 100644 (file)
@@ -19,11 +19,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define NODEBUG_H
 
 #ifndef NO_DEBUG
-       #define NO_DEBUG
-       #include "debug.h"
-       #undef NO_DEBUG
+#    define NO_DEBUG
+#    include "debug.h"
+#    undef NO_DEBUG
 #else
-       #include "debug.h"
+#    include "debug.h"
 #endif
 
 #endif
index 00489557f2245b6fcef72f7c8053188586c9d08d..07aef0b0eb27a5f1fe6b95cad78475d8732e0f3b 100644 (file)
@@ -2,17 +2,17 @@
 /* Very basic print functions, intended to be used with usb_debug_only.c
  * http://www.pjrc.com/teensy/
  * Copyright (c) 2008 PJRC.COM, LLC
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 #include <stdint.h>
 #include "print.h"
 
-
 #ifndef NO_PRINT
 
-#if defined(__AVR__)
-
-#define sendchar(c)    xputc(c)
+#    if defined(__AVR__)
 
+#        define sendchar(c) xputc(c)
 
-void print_set_sendchar(int8_t (*sendchar_func)(uint8_t))
-{
-    xdev_out(sendchar_func);
-}
+void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { xdev_out(sendchar_func); }
 
-#elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */
+#    elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */
 
 // don't need anything extra
 
-#elif defined(__arm__) /* __AVR__ */
+#    elif defined(__arm__) /* __AVR__ */
 
 // TODO
-//void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { }
+// void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { }
 
-#endif /* __AVR__ */
+#    endif /* __AVR__ */
 
 #endif
index 2d7184bd0d40db924121fc8e3e3755bd575fd504..20189838feeb64c1cdacc66e6d30823413737281 100644 (file)
 #include "util.h"
 
 #if defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM)
-#define PSTR(x) x
+#    define PSTR(x) x
 #endif
 
-
 #ifndef NO_PRINT
 
-#if defined(__AVR__) /* __AVR__ */
+#    if defined(__AVR__) /* __AVR__ */
 
-#  include "avr/xprintf.h"
+#        include "avr/xprintf.h"
 
-#  ifdef USER_PRINT /* USER_PRINT */
+#        ifdef USER_PRINT /* USER_PRINT */
 
 // Remove normal print defines
-#    define print(s)
-#    define println(s)
-#    undef xprintf
-#    define xprintf(fmt, ...)
+#            define print(s)
+#            define println(s)
+#            undef xprintf
+#            define xprintf(fmt, ...)
 
 // Create user print defines
-#    define uprint(s)          xputs(PSTR(s))
-#    define uprintln(s)        xputs(PSTR(s "\r\n"))
-#    define uprintf(fmt, ...)  __xprintf(PSTR(fmt), ##__VA_ARGS__)
+#            define uprint(s) xputs(PSTR(s))
+#            define uprintln(s) xputs(PSTR(s "\r\n"))
+#            define uprintf(fmt, ...) __xprintf(PSTR(fmt), ##__VA_ARGS__)
 
-#  else /* NORMAL PRINT */
+#        else /* NORMAL PRINT */
 
 // Create user & normal print defines
-#    define print(s)           xputs(PSTR(s))
-#    define println(s)         xputs(PSTR(s "\r\n"))
-#    define uprint(s)          print(s)
-#    define uprintln(s)        println(s)
-#    define uprintf(fmt, ...)  xprintf(fmt, ##__VA_ARGS__)
+#            define print(s) xputs(PSTR(s))
+#            define println(s) xputs(PSTR(s "\r\n"))
+#            define uprint(s) print(s)
+#            define uprintln(s) println(s)
+#            define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__)
 
-#  endif /* USER_PRINT / NORMAL PRINT */
+#        endif /* USER_PRINT / NORMAL PRINT */
 
-#  ifdef __cplusplus
+#        ifdef __cplusplus
 extern "C"
-#  endif
+#        endif
 
-/* function pointer of sendchar to be used by print utility */
-void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
+    /* function pointer of sendchar to be used by print utility */
+    void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
 
-#elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */
+#    elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */
 
-#ifndef TERMINAL_ENABLE
-#  include "chibios/printf.h"
-#endif
+#        ifndef TERMINAL_ENABLE
+#            include "chibios/printf.h"
+#        endif
 
-#  ifdef USER_PRINT /* USER_PRINT */
+#        ifdef USER_PRINT /* USER_PRINT */
 
 // Remove normal print defines
-#    define print(s)
-#    define println(s)
-#    define xprintf(fmt, ...)
+#            define print(s)
+#            define println(s)
+#            define xprintf(fmt, ...)
 
 // Create user print defines
-#    define uprint(s)    printf(s)
-#    define uprintln(s)  printf(s "\r\n")
-#    define uprintf      printf
+#            define uprint(s) printf(s)
+#            define uprintln(s) printf(s "\r\n")
+#            define uprintf printf
 
-#  else /* NORMAL PRINT */
+#        else /* NORMAL PRINT */
 
 // Create user & normal print defines
-#    define print(s)     printf(s)
-#    define println(s)   printf(s "\r\n")
-#    define xprintf      printf
-#    define uprint(s)    printf(s)
-#    define uprintln(s)  printf(s "\r\n")
-#    define uprintf      printf
+#            define print(s) printf(s)
+#            define println(s) printf(s "\r\n")
+#            define xprintf printf
+#            define uprint(s) printf(s)
+#            define uprintln(s) printf(s "\r\n")
+#            define uprintf printf
 
-#  endif /* USER_PRINT / NORMAL PRINT */
+#        endif /* USER_PRINT / NORMAL PRINT */
 
-#elif defined(PROTOCOL_ARM_ATSAM) /* PROTOCOL_ARM_ATSAM */
+#    elif defined(PROTOCOL_ARM_ATSAM) /* PROTOCOL_ARM_ATSAM */
 
-#  include "arm_atsam/printf.h"
+#        include "arm_atsam/printf.h"
 
-#  ifdef USER_PRINT /* USER_PRINT */
+#        ifdef USER_PRINT /* USER_PRINT */
 
 // Remove normal print defines
-#    define print(s)
-#    define println(s)
-#    define xprintf(fmt, ...)
+#            define print(s)
+#            define println(s)
+#            define xprintf(fmt, ...)
 
 // Create user print defines
-#    define uprintf(fmt, ...)  __xprintf(fmt, ##__VA_ARGS__)
-#    define uprint(s)          xprintf(s)
-#    define uprintln(s)        xprintf(s "\r\n")
+#            define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__)
+#            define uprint(s) xprintf(s)
+#            define uprintln(s) xprintf(s "\r\n")
 
-#  else /* NORMAL PRINT */
+#        else /* NORMAL PRINT */
 
 // Create user & normal print defines
-#    define xprintf(fmt, ...)  __xprintf(fmt, ##__VA_ARGS__)
-#    define print(s)           xprintf(s)
-#    define println(s)         xprintf(s "\r\n")
-#    define uprint(s)          print(s)
-#    define uprintln(s)        println(s)
-#    define uprintf(fmt, ...)  xprintf(fmt, ##__VA_ARGS__)
+#            define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__)
+#            define print(s) xprintf(s)
+#            define println(s) xprintf(s "\r\n")
+#            define uprint(s) print(s)
+#            define uprintln(s) println(s)
+#            define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__)
 
-#  endif /* USER_PRINT / NORMAL PRINT */
+#        endif /* USER_PRINT / NORMAL PRINT */
 
-#elif defined(__arm__) /* __arm__ */
+#    elif defined(__arm__) /* __arm__ */
 
-#  include "mbed/xprintf.h"
+#        include "mbed/xprintf.h"
 
-#  ifdef USER_PRINT /* USER_PRINT */
+#        ifdef USER_PRINT /* USER_PRINT */
 
 // Remove normal print defines
-#    define print(s)
-#    define println(s)
-#    define xprintf(fmt, ...)
+#            define print(s)
+#            define println(s)
+#            define xprintf(fmt, ...)
 
 // Create user print defines
-#    define uprintf(fmt, ...)  __xprintf(fmt, ##__VA_ARGS__)
-#    define uprint(s)          xprintf(s)
-#    define uprintln(s)        xprintf(s "\r\n")
+#            define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__)
+#            define uprint(s) xprintf(s)
+#            define uprintln(s) xprintf(s "\r\n")
 
-#  else /* NORMAL PRINT */
+#        else /* NORMAL PRINT */
 
 // Create user & normal print defines
-#    define xprintf(fmt, ...)  __xprintf(fmt, ##__VA_ARGS__)
-#    define print(s)           xprintf(s)
-#    define println(s)         xprintf(s "\r\n")
-#    define uprint(s)          print(s)
-#    define uprintln(s)        println(s)
-#    define uprintf(fmt, ...)  xprintf(fmt, ##__VA_ARGS__)
+#            define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__)
+#            define print(s) xprintf(s)
+#            define println(s) xprintf(s "\r\n")
+#            define uprint(s) print(s)
+#            define uprintln(s) println(s)
+#            define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__)
 
-#  endif /* USER_PRINT / NORMAL PRINT */
+#        endif /* USER_PRINT / NORMAL PRINT */
 
 /* TODO: to select output destinations: UART/USBSerial */
-#  define print_set_sendchar(func)
+#        define print_set_sendchar(func)
 
-#endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM / __arm__ */
+#    endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM / __arm__ */
 
 // User print disables the normal print messages in the body of QMK/TMK code and
 // is meant as a lightweight alternative to NOPRINT. Use it when you only want to do
@@ -169,141 +168,140 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
 //
 // !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!!
 //
-#ifdef USER_PRINT
+#    ifdef USER_PRINT
 
 // Disable normal print
-#define print_dec(data)
-#define print_decs(data)
-#define print_hex4(data)
-#define print_hex8(data)
-#define print_hex16(data)
-#define print_hex32(data)
-#define print_bin4(data)
-#define print_bin8(data)
-#define print_bin16(data)
-#define print_bin32(data)
-#define print_bin_reverse8(data)
-#define print_bin_reverse16(data)
-#define print_bin_reverse32(data)
-#define print_val_dec(v)
-#define print_val_decs(v)
-#define print_val_hex8(v)
-#define print_val_hex16(v)
-#define print_val_hex32(v)
-#define print_val_bin8(v)
-#define print_val_bin16(v)
-#define print_val_bin32(v)
-#define print_val_bin_reverse8(v)
-#define print_val_bin_reverse16(v)
-#define print_val_bin_reverse32(v)
-
-#else /* NORMAL_PRINT */
-
-//Enable normal print
+#        define print_dec(data)
+#        define print_decs(data)
+#        define print_hex4(data)
+#        define print_hex8(data)
+#        define print_hex16(data)
+#        define print_hex32(data)
+#        define print_bin4(data)
+#        define print_bin8(data)
+#        define print_bin16(data)
+#        define print_bin32(data)
+#        define print_bin_reverse8(data)
+#        define print_bin_reverse16(data)
+#        define print_bin_reverse32(data)
+#        define print_val_dec(v)
+#        define print_val_decs(v)
+#        define print_val_hex8(v)
+#        define print_val_hex16(v)
+#        define print_val_hex32(v)
+#        define print_val_bin8(v)
+#        define print_val_bin16(v)
+#        define print_val_bin32(v)
+#        define print_val_bin_reverse8(v)
+#        define print_val_bin_reverse16(v)
+#        define print_val_bin_reverse32(v)
+
+#    else /* NORMAL_PRINT */
+
+// Enable normal print
 /* decimal */
-#define print_dec(i)                xprintf("%u", i)
-#define print_decs(i)               xprintf("%d", i)
+#        define print_dec(i) xprintf("%u", i)
+#        define print_decs(i) xprintf("%d", i)
 /* hex */
-#define print_hex4(i)               xprintf("%X", i)
-#define print_hex8(i)               xprintf("%02X", i)
-#define print_hex16(i)              xprintf("%04X", i)
-#define print_hex32(i)              xprintf("%08lX", i)
+#        define print_hex4(i) xprintf("%X", i)
+#        define print_hex8(i) xprintf("%02X", i)
+#        define print_hex16(i) xprintf("%04X", i)
+#        define print_hex32(i) xprintf("%08lX", i)
 /* binary */
-#define print_bin4(i)               xprintf("%04b", i)
-#define print_bin8(i)               xprintf("%08b", i)
-#define print_bin16(i)              xprintf("%016b", i)
-#define print_bin32(i)              xprintf("%032lb", i)
-#define print_bin_reverse8(i)       xprintf("%08b", bitrev(i))
-#define print_bin_reverse16(i)      xprintf("%016b", bitrev16(i))
-#define print_bin_reverse32(i)      xprintf("%032lb", bitrev32(i))
+#        define print_bin4(i) xprintf("%04b", i)
+#        define print_bin8(i) xprintf("%08b", i)
+#        define print_bin16(i) xprintf("%016b", i)
+#        define print_bin32(i) xprintf("%032lb", i)
+#        define print_bin_reverse8(i) xprintf("%08b", bitrev(i))
+#        define print_bin_reverse16(i) xprintf("%016b", bitrev16(i))
+#        define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i))
 /* print value utility */
-#define print_val_dec(v)            xprintf(#v ": %u\n", v)
-#define print_val_decs(v)           xprintf(#v ": %d\n", v)
-#define print_val_hex8(v)           xprintf(#v ": %X\n", v)
-#define print_val_hex16(v)          xprintf(#v ": %02X\n", v)
-#define print_val_hex32(v)          xprintf(#v ": %04lX\n", v)
-#define print_val_bin8(v)           xprintf(#v ": %08b\n", v)
-#define print_val_bin16(v)          xprintf(#v ": %016b\n", v)
-#define print_val_bin32(v)          xprintf(#v ": %032lb\n", v)
-#define print_val_bin_reverse8(v)   xprintf(#v ": %08b\n", bitrev(v))
-#define print_val_bin_reverse16(v)  xprintf(#v ": %016b\n", bitrev16(v))
-#define print_val_bin_reverse32(v)  xprintf(#v ": %032lb\n", bitrev32(v))
-
-#endif /* USER_PRINT / NORMAL_PRINT */
+#        define print_val_dec(v) xprintf(#        v ": %u\n", v)
+#        define print_val_decs(v) xprintf(#        v ": %d\n", v)
+#        define print_val_hex8(v) xprintf(#        v ": %X\n", v)
+#        define print_val_hex16(v) xprintf(#        v ": %02X\n", v)
+#        define print_val_hex32(v) xprintf(#        v ": %04lX\n", v)
+#        define print_val_bin8(v) xprintf(#        v ": %08b\n", v)
+#        define print_val_bin16(v) xprintf(#        v ": %016b\n", v)
+#        define print_val_bin32(v) xprintf(#        v ": %032lb\n", v)
+#        define print_val_bin_reverse8(v) xprintf(#        v ": %08b\n", bitrev(v))
+#        define print_val_bin_reverse16(v) xprintf(#        v ": %016b\n", bitrev16(v))
+#        define print_val_bin_reverse32(v) xprintf(#        v ": %032lb\n", bitrev32(v))
+
+#    endif /* USER_PRINT / NORMAL_PRINT */
 
 // User Print
 
 /* decimal */
-#define uprint_dec(i)               uprintf("%u", i)
-#define uprint_decs(i)              uprintf("%d", i)
+#    define uprint_dec(i) uprintf("%u", i)
+#    define uprint_decs(i) uprintf("%d", i)
 /* hex */
-#define uprint_hex4(i)              uprintf("%X", i)
-#define uprint_hex8(i)              uprintf("%02X", i)
-#define uprint_hex16(i)             uprintf("%04X", i)
-#define uprint_hex32(i)             uprintf("%08lX", i)
+#    define uprint_hex4(i) uprintf("%X", i)
+#    define uprint_hex8(i) uprintf("%02X", i)
+#    define uprint_hex16(i) uprintf("%04X", i)
+#    define uprint_hex32(i) uprintf("%08lX", i)
 /* binary */
-#define uprint_bin4(i)              uprintf("%04b", i)
-#define uprint_bin8(i)              uprintf("%08b", i)
-#define uprint_bin16(i)             uprintf("%016b", i)
-#define uprint_bin32(i)             uprintf("%032lb", i)
-#define uprint_bin_reverse8(i)      uprintf("%08b", bitrev(i))
-#define uprint_bin_reverse16(i)     uprintf("%016b", bitrev16(i))
-#define uprint_bin_reverse32(i)     uprintf("%032lb", bitrev32(i))
+#    define uprint_bin4(i) uprintf("%04b", i)
+#    define uprint_bin8(i) uprintf("%08b", i)
+#    define uprint_bin16(i) uprintf("%016b", i)
+#    define uprint_bin32(i) uprintf("%032lb", i)
+#    define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i))
+#    define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i))
+#    define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i))
 /* print value utility */
-#define uprint_val_dec(v)           uprintf(#v ": %u\n", v)
-#define uprint_val_decs(v)          uprintf(#v ": %d\n", v)
-#define uprint_val_hex8(v)          uprintf(#v ": %X\n", v)
-#define uprint_val_hex16(v)         uprintf(#v ": %02X\n", v)
-#define uprint_val_hex32(v)         uprintf(#v ": %04lX\n", v)
-#define uprint_val_bin8(v)          uprintf(#v ": %08b\n", v)
-#define uprint_val_bin16(v)         uprintf(#v ": %016b\n", v)
-#define uprint_val_bin32(v)         uprintf(#v ": %032lb\n", v)
-#define uprint_val_bin_reverse8(v)  uprintf(#v ": %08b\n", bitrev(v))
-#define uprint_val_bin_reverse16(v) uprintf(#v ": %016b\n", bitrev16(v))
-#define uprint_val_bin_reverse32(v) uprintf(#v ": %032lb\n", bitrev32(v))
-
-#else   /* NO_PRINT */
-
-#define xprintf(fmt, ...)
-#define print(s)
-#define println(s)
-#define print_set_sendchar(func)
-#define print_dec(data)
-#define print_decs(data)
-#define print_hex4(data)
-#define print_hex8(data)
-#define print_hex16(data)
-#define print_hex32(data)
-#define print_bin4(data)
-#define print_bin8(data)
-#define print_bin16(data)
-#define print_bin32(data)
-#define print_bin_reverse8(data)
-#define print_bin_reverse16(data)
-#define print_bin_reverse32(data)
-#define print_val_dec(v)
-#define print_val_decs(v)
-#define print_val_hex8(v)
-#define print_val_hex16(v)
-#define print_val_hex32(v)
-#define print_val_bin8(v)
-#define print_val_bin16(v)
-#define print_val_bin32(v)
-#define print_val_bin_reverse8(v)
-#define print_val_bin_reverse16(v)
-#define print_val_bin_reverse32(v)
-
-#endif  /* NO_PRINT */
+#    define uprint_val_dec(v) uprintf(#    v ": %u\n", v)
+#    define uprint_val_decs(v) uprintf(#    v ": %d\n", v)
+#    define uprint_val_hex8(v) uprintf(#    v ": %X\n", v)
+#    define uprint_val_hex16(v) uprintf(#    v ": %02X\n", v)
+#    define uprint_val_hex32(v) uprintf(#    v ": %04lX\n", v)
+#    define uprint_val_bin8(v) uprintf(#    v ": %08b\n", v)
+#    define uprint_val_bin16(v) uprintf(#    v ": %016b\n", v)
+#    define uprint_val_bin32(v) uprintf(#    v ": %032lb\n", v)
+#    define uprint_val_bin_reverse8(v) uprintf(#    v ": %08b\n", bitrev(v))
+#    define uprint_val_bin_reverse16(v) uprintf(#    v ": %016b\n", bitrev16(v))
+#    define uprint_val_bin_reverse32(v) uprintf(#    v ": %032lb\n", bitrev32(v))
+
+#else /* NO_PRINT */
 
+#    define xprintf(fmt, ...)
+#    define print(s)
+#    define println(s)
+#    define print_set_sendchar(func)
+#    define print_dec(data)
+#    define print_decs(data)
+#    define print_hex4(data)
+#    define print_hex8(data)
+#    define print_hex16(data)
+#    define print_hex32(data)
+#    define print_bin4(data)
+#    define print_bin8(data)
+#    define print_bin16(data)
+#    define print_bin32(data)
+#    define print_bin_reverse8(data)
+#    define print_bin_reverse16(data)
+#    define print_bin_reverse32(data)
+#    define print_val_dec(v)
+#    define print_val_decs(v)
+#    define print_val_hex8(v)
+#    define print_val_hex16(v)
+#    define print_val_hex32(v)
+#    define print_val_bin8(v)
+#    define print_val_bin16(v)
+#    define print_val_bin32(v)
+#    define print_val_bin_reverse8(v)
+#    define print_val_bin_reverse16(v)
+#    define print_val_bin_reverse32(v)
+
+#endif /* NO_PRINT */
 
 /* Backward compatiblitly for old name */
-#define pdec(data)              print_dec(data)
-#define pdec16(data)            print_dec(data)
-#define phex(data)              print_hex8(data)
-#define phex16(data)            print_hex16(data)
-#define pbin(data)              print_bin8(data)
-#define pbin16(data)            print_bin16(data)
-#define pbin_reverse(data)      print_bin_reverse8(data)
-#define pbin_reverse16(data)    print_bin_reverse16(data)
+#define pdec(data) print_dec(data)
+#define pdec16(data) print_dec(data)
+#define phex(data) print_hex8(data)
+#define phex16(data) print_hex16(data)
+#define pbin(data) print_bin8(data)
+#define pbin16(data) print_bin16(data)
+#define pbin_reverse(data) print_bin_reverse8(data)
+#define pbin_reverse16(data) print_bin_reverse16(data)
 
 #endif
index de931383972ddf1cf8280e42247b8052c8464590..88373f478b3f69805b9b6b2d7eff545d43c8dad1 100644 (file)
@@ -2,12 +2,12 @@
 #define PROGMEM_H 1
 
 #if defined(__AVR__)
-#   include <avr/pgmspace.h>
+#    include <avr/pgmspace.h>
 #else
-#   define PROGMEM
-#   define pgm_read_byte(p)     *((unsigned char*)(p))
-#   define pgm_read_word(p)     *((uint16_t*)(p))
-#   define pgm_read_dword(p)    *((uint32_t*)(p))
+#    define PROGMEM
+#    define pgm_read_byte(p) *((unsigned char*)(p))
+#    define pgm_read_word(p) *((uint16_t*)(p))
+#    define pgm_read_dword(p) *((uint32_t*)(p))
 #endif
 
 #endif
index 86da02fd155ff26997145e810e069da7d28c4590..c579157f14e59cf53bb529cc99b26c5b50fabccd 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef _RAW_HID_H_
 #define _RAW_HID_H_
 
-void raw_hid_receive( uint8_t *data, uint8_t length );
+void raw_hid_receive(uint8_t *data, uint8_t length);
 
-void raw_hid_send( uint8_t *data, uint8_t length );
+void raw_hid_send(uint8_t *data, uint8_t length);
 
 #endif
index 6a06b70c60afc8fd89b64cea48dbf1c3a73bcf0c..f4758b48ec76b212e6b41066f28ee695921de609 100644 (file)
  *
  * FIXME: Needs doc
  */
-uint8_t has_anykey(report_keyboard_t* keyboard_report)
-{
-    uint8_t cnt = 0;
-    uint8_t *p = keyboard_report->keys;
-    uint8_t lp = sizeof(keyboard_report->keys);
+uint8_t has_anykey(report_keyboard_t* keyboard_report) {
+    uint8_t  cnt = 0;
+    uint8_t* p   = keyboard_report->keys;
+    uint8_t  lp  = sizeof(keyboard_report->keys);
 #ifdef NKRO_ENABLE
     if (keyboard_protocol && keymap_config.nkro) {
-        p = keyboard_report->nkro.bits;
+        p  = keyboard_report->nkro.bits;
         lp = sizeof(keyboard_report->nkro.bits);
     }
 #endif
     while (lp--) {
-        if (*p++)
-            cnt++;
+        if (*p++) cnt++;
     }
     return cnt;
 }
@@ -47,14 +45,13 @@ uint8_t has_anykey(report_keyboard_t* keyboard_report)
  *
  * FIXME: Needs doc
  */
-uint8_t get_first_key(report_keyboard_t* keyboard_report)
-{
+uint8_t get_first_key(report_keyboard_t* keyboard_report) {
 #ifdef NKRO_ENABLE
     if (keyboard_protocol && keymap_config.nkro) {
         uint8_t i = 0;
         for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
             ;
-        return i<<3 | biton(keyboard_report->nkro.bits[i]);
+        return i << 3 | biton(keyboard_report->nkro.bits[i]);
     }
 #endif
 #ifdef USB_6KRO_ENABLE
@@ -75,10 +72,9 @@ uint8_t get_first_key(report_keyboard_t* keyboard_report)
  *
  * FIXME: Needs doc
  */
-void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code)
-{
+void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) {
 #ifdef USB_6KRO_ENABLE
-    int8_t i = cb_head;
+    int8_t i     = cb_head;
     int8_t empty = -1;
     if (cb_count) {
         do {
@@ -97,18 +93,16 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code)
                     // pop head when has no empty space
                     cb_head = RO_INC(cb_head);
                     cb_count--;
-                }
-                else {
+                } else {
                     // left shift when has empty space
                     uint8_t offset = 1;
-                    i = RO_INC(empty);
+                    i              = RO_INC(empty);
                     do {
                         if (keyboard_report->keys[i] != 0) {
                             keyboard_report->keys[empty] = keyboard_report->keys[i];
-                            keyboard_report->keys[i] = 0;
-                            empty = RO_INC(empty);
-                        }
-                        else {
+                            keyboard_report->keys[i]     = 0;
+                            empty                        = RO_INC(empty);
+                        } else {
                             offset++;
                         }
                         i = RO_INC(i);
@@ -120,10 +114,10 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code)
     }
     // add to tail
     keyboard_report->keys[cb_tail] = code;
-    cb_tail = RO_INC(cb_tail);
+    cb_tail                        = RO_INC(cb_tail);
     cb_count++;
 #else
-    int8_t i = 0;
+    int8_t i     = 0;
     int8_t empty = -1;
     for (; i < KEYBOARD_REPORT_KEYS; i++) {
         if (keyboard_report->keys[i] == code) {
@@ -145,8 +139,7 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code)
  *
  * FIXME: Needs doc
  */
-void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code)
-{
+void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) {
 #ifdef USB_6KRO_ENABLE
     uint8_t i = cb_head;
     if (cb_count) {
@@ -186,10 +179,9 @@ void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code)
  *
  * FIXME: Needs doc
  */
-void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code)
-{
-    if ((code>>3) < KEYBOARD_REPORT_BITS) {
-        keyboard_report->nkro.bits[code>>3] |= 1<<(code&7);
+void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code) {
+    if ((code >> 3) < KEYBOARD_REPORT_BITS) {
+        keyboard_report->nkro.bits[code >> 3] |= 1 << (code & 7);
     } else {
         dprintf("add_key_bit: can't add: %02X\n", code);
     }
@@ -199,10 +191,9 @@ void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code)
  *
  * FIXME: Needs doc
  */
-void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code)
-{
-    if ((code>>3) < KEYBOARD_REPORT_BITS) {
-        keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7));
+void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) {
+    if ((code >> 3) < KEYBOARD_REPORT_BITS) {
+        keyboard_report->nkro.bits[code >> 3] &= ~(1 << (code & 7));
     } else {
         dprintf("del_key_bit: can't del: %02X\n", code);
     }
@@ -213,8 +204,7 @@ void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code)
  *
  * FIXME: Needs doc
  */
-void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key)
-{
+void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key) {
 #ifdef NKRO_ENABLE
     if (keyboard_protocol && keymap_config.nkro) {
         add_key_bit(keyboard_report, key);
@@ -228,8 +218,7 @@ void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key)
  *
  * FIXME: Needs doc
  */
-void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key)
-{
+void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key) {
 #ifdef NKRO_ENABLE
     if (keyboard_protocol && keymap_config.nkro) {
         del_key_bit(keyboard_report, key);
@@ -243,8 +232,7 @@ void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key)
  *
  * FIXME: Needs doc
  */
-void clear_keys_from_report(report_keyboard_t* keyboard_report)
-{
+void clear_keys_from_report(report_keyboard_t* keyboard_report) {
     // not clear mods
 #ifdef NKRO_ENABLE
     if (keyboard_protocol && keymap_config.nkro) {
index e7c31bd376a08fa4263bddef15a18abb4ebb7bb6..ccc6d599b37321c269225bc25942f5308b8f9e81 100644 (file)
@@ -21,90 +21,88 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdint.h>
 #include "keycode.h"
 
-
 /* report id */
-#define REPORT_ID_KEYBOARD  1
-#define REPORT_ID_MOUSE     2
-#define REPORT_ID_SYSTEM    3
-#define REPORT_ID_CONSUMER  4
-#define REPORT_ID_NKRO      5
+#define REPORT_ID_KEYBOARD 1
+#define REPORT_ID_MOUSE 2
+#define REPORT_ID_SYSTEM 3
+#define REPORT_ID_CONSUMER 4
+#define REPORT_ID_NKRO 5
 
 /* mouse buttons */
-#define MOUSE_BTN1 (1<<0)
-#define MOUSE_BTN2 (1<<1)
-#define MOUSE_BTN3 (1<<2)
-#define MOUSE_BTN4 (1<<3)
-#define MOUSE_BTN5 (1<<4)
+#define MOUSE_BTN1 (1 << 0)
+#define MOUSE_BTN2 (1 << 1)
+#define MOUSE_BTN3 (1 << 2)
+#define MOUSE_BTN4 (1 << 3)
+#define MOUSE_BTN5 (1 << 4)
 
 /* Consumer Page(0x0C)
  * following are supported by Windows: http://msdn.microsoft.com/en-us/windows/hardware/gg463372.aspx
  * see also https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/display-brightness-control
  */
-#define AUDIO_MUTE              0x00E2
-#define AUDIO_VOL_UP            0x00E9
-#define AUDIO_VOL_DOWN          0x00EA
-#define TRANSPORT_NEXT_TRACK    0x00B5
-#define TRANSPORT_PREV_TRACK    0x00B6
-#define TRANSPORT_STOP          0x00B7
-#define TRANSPORT_STOP_EJECT    0x00CC
-#define TRANSPORT_PLAY_PAUSE    0x00CD
-#define BRIGHTNESS_UP           0x006F
-#define BRIGHTNESS_DOWN         0x0070
+#define AUDIO_MUTE 0x00E2
+#define AUDIO_VOL_UP 0x00E9
+#define AUDIO_VOL_DOWN 0x00EA
+#define TRANSPORT_NEXT_TRACK 0x00B5
+#define TRANSPORT_PREV_TRACK 0x00B6
+#define TRANSPORT_STOP 0x00B7
+#define TRANSPORT_STOP_EJECT 0x00CC
+#define TRANSPORT_PLAY_PAUSE 0x00CD
+#define BRIGHTNESS_UP 0x006F
+#define BRIGHTNESS_DOWN 0x0070
 /* application launch */
-#define AL_CC_CONFIG            0x0183
-#define AL_EMAIL                0x018A
-#define AL_CALCULATOR           0x0192
-#define AL_LOCAL_BROWSER        0x0194
+#define AL_CC_CONFIG 0x0183
+#define AL_EMAIL 0x018A
+#define AL_CALCULATOR 0x0192
+#define AL_LOCAL_BROWSER 0x0194
 /* application control */
-#define AC_SEARCH               0x0221
-#define AC_HOME                 0x0223
-#define AC_BACK                 0x0224
-#define AC_FORWARD              0x0225
-#define AC_STOP                 0x0226
-#define AC_REFRESH              0x0227
-#define AC_BOOKMARKS            0x022A
+#define AC_SEARCH 0x0221
+#define AC_HOME 0x0223
+#define AC_BACK 0x0224
+#define AC_FORWARD 0x0225
+#define AC_STOP 0x0226
+#define AC_REFRESH 0x0227
+#define AC_BOOKMARKS 0x022A
 /* supplement for Bluegiga iWRAP HID(not supported by Windows?) */
-#define AL_LOCK                 0x019E
-#define TRANSPORT_RECORD        0x00B2
-#define TRANSPORT_FAST_FORWARD  0x00B3
-#define TRANSPORT_REWIND        0x00B4
-#define TRANSPORT_EJECT         0x00B8
-#define AC_MINIMIZE             0x0206
+#define AL_LOCK 0x019E
+#define TRANSPORT_RECORD 0x00B2
+#define TRANSPORT_FAST_FORWARD 0x00B3
+#define TRANSPORT_REWIND 0x00B4
+#define TRANSPORT_EJECT 0x00B8
+#define AC_MINIMIZE 0x0206
 
 /* Generic Desktop Page(0x01) - system power control */
-#define SYSTEM_POWER_DOWN       0x0081
-#define SYSTEM_SLEEP            0x0082
-#define SYSTEM_WAKE_UP          0x0083
-
+#define SYSTEM_POWER_DOWN 0x0081
+#define SYSTEM_SLEEP 0x0082
+#define SYSTEM_WAKE_UP 0x0083
 
 #define NKRO_SHARED_EP
 /* key report size(NKRO or boot mode) */
 #if defined(NKRO_ENABLE)
-  #if defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS)
-    #include "protocol/usb_descriptor.h"
-    #define KEYBOARD_REPORT_BITS (SHARED_EPSIZE - 2)
-  #elif defined(PROTOCOL_ARM_ATSAM)
-    #include "protocol/arm_atsam/usb/udi_device_epsize.h"
-    #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
-    #undef NKRO_SHARED_EP
-    #undef MOUSE_SHARED_EP
-  #else
-    #error "NKRO not supported with this protocol"
-  #endif
+#    if defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS)
+#        include "protocol/usb_descriptor.h"
+#        define KEYBOARD_REPORT_BITS (SHARED_EPSIZE - 2)
+#    elif defined(PROTOCOL_ARM_ATSAM)
+#        include "protocol/arm_atsam/usb/udi_device_epsize.h"
+#        define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
+#        undef NKRO_SHARED_EP
+#        undef MOUSE_SHARED_EP
+#    else
+#        error "NKRO not supported with this protocol"
+#    endif
 #endif
 
 #ifdef KEYBOARD_SHARED_EP
-#   define KEYBOARD_REPORT_SIZE 9
+#    define KEYBOARD_REPORT_SIZE 9
 #else
-#   define KEYBOARD_REPORT_SIZE 8
+#    define KEYBOARD_REPORT_SIZE 8
 #endif
 
 #define KEYBOARD_REPORT_KEYS 6
 
 /* VUSB hardcodes keyboard and mouse+extrakey only */
 #if defined(PROTOCOL_VUSB)
-  #undef KEYBOARD_SHARED_EP
-  #undef MOUSE_SHARED_EP
+#    undef KEYBOARD_SHARED_EP
+#    undef MOUSE_SHARED_EP
 #endif
 
 #ifdef __cplusplus
@@ -143,58 +141,32 @@ typedef union {
     };
 #ifdef NKRO_ENABLE
     struct nkro_report {
-#ifdef NKRO_SHARED_EP
+#    ifdef NKRO_SHARED_EP
         uint8_t report_id;
-#endif
+#    endif
         uint8_t mods;
         uint8_t bits[KEYBOARD_REPORT_BITS];
     } nkro;
 #endif
-} __attribute__ ((packed)) report_keyboard_t;
+} __attribute__((packed)) report_keyboard_t;
 
 typedef struct {
 #ifdef MOUSE_SHARED_EP
     uint8_t report_id;
 #endif
     uint8_t buttons;
-    int8_t x;
-    int8_t y;
-    int8_t v;
-    int8_t h;
-} __attribute__ ((packed)) report_mouse_t;
-
+    int8_t  x;
+    int8_t  y;
+    int8_t  v;
+    int8_t  h;
+} __attribute__((packed)) report_mouse_t;
 
 /* keycode to system usage */
-#define KEYCODE2SYSTEM(key) \
-    (key == KC_SYSTEM_POWER ? SYSTEM_POWER_DOWN : \
-    (key == KC_SYSTEM_SLEEP ? SYSTEM_SLEEP : \
-    (key == KC_SYSTEM_WAKE  ? SYSTEM_WAKE_UP : 0)))
+#define KEYCODE2SYSTEM(key) (key == KC_SYSTEM_POWER ? SYSTEM_POWER_DOWN : (key == KC_SYSTEM_SLEEP ? SYSTEM_SLEEP : (key == KC_SYSTEM_WAKE ? SYSTEM_WAKE_UP : 0)))
 
 /* keycode to consumer usage */
 #define KEYCODE2CONSUMER(key) \
-    (key == KC_AUDIO_MUTE       ?  AUDIO_MUTE : \
-    (key == KC_AUDIO_VOL_UP     ?  AUDIO_VOL_UP : \
-    (key == KC_AUDIO_VOL_DOWN   ?  AUDIO_VOL_DOWN : \
-    (key == KC_MEDIA_NEXT_TRACK ?  TRANSPORT_NEXT_TRACK : \
-    (key == KC_MEDIA_PREV_TRACK ?  TRANSPORT_PREV_TRACK : \
-    (key == KC_MEDIA_FAST_FORWARD ?  TRANSPORT_FAST_FORWARD : \
-    (key == KC_MEDIA_REWIND     ?  TRANSPORT_REWIND : \
-    (key == KC_MEDIA_STOP       ?  TRANSPORT_STOP : \
-    (key == KC_MEDIA_EJECT      ?  TRANSPORT_STOP_EJECT : \
-    (key == KC_MEDIA_PLAY_PAUSE ?  TRANSPORT_PLAY_PAUSE : \
-    (key == KC_MEDIA_SELECT     ?  AL_CC_CONFIG : \
-    (key == KC_MAIL             ?  AL_EMAIL : \
-    (key == KC_CALCULATOR       ?  AL_CALCULATOR : \
-    (key == KC_MY_COMPUTER      ?  AL_LOCAL_BROWSER : \
-    (key == KC_WWW_SEARCH       ?  AC_SEARCH : \
-    (key == KC_WWW_HOME         ?  AC_HOME : \
-    (key == KC_WWW_BACK         ?  AC_BACK : \
-    (key == KC_WWW_FORWARD      ?  AC_FORWARD : \
-    (key == KC_WWW_STOP         ?  AC_STOP : \
-    (key == KC_WWW_REFRESH      ?  AC_REFRESH : \
-    (key == KC_BRIGHTNESS_UP    ?  BRIGHTNESS_UP : \
-    (key == KC_BRIGHTNESS_DOWN  ?  BRIGHTNESS_DOWN : \
-    (key == KC_WWW_FAVORITES    ?  AC_BOOKMARKS : 0)))))))))))))))))))))))
+    (key == KC_AUDIO_MUTE ? AUDIO_MUTE : (key == KC_AUDIO_VOL_UP ? AUDIO_VOL_UP : (key == KC_AUDIO_VOL_DOWN ? AUDIO_VOL_DOWN : (key == KC_MEDIA_NEXT_TRACK ? TRANSPORT_NEXT_TRACK : (key == KC_MEDIA_PREV_TRACK ? TRANSPORT_PREV_TRACK : (key == KC_MEDIA_FAST_FORWARD ? TRANSPORT_FAST_FORWARD : (key == KC_MEDIA_REWIND ? TRANSPORT_REWIND : (key == KC_MEDIA_STOP ? TRANSPORT_STOP : (key == KC_MEDIA_EJECT ? TRANSPORT_STOP_EJECT : (key == KC_MEDIA_PLAY_PAUSE ? TRANSPORT_PLAY_PAUSE : (key == KC_MEDIA_SELECT ? AL_CC_CONFIG : (key == KC_MAIL ? AL_EMAIL : (key == KC_CALCULATOR ? AL_CALCULATOR : (key == KC_MY_COMPUTER ? AL_LOCAL_BROWSER : (key == KC_WWW_SEARCH ? AC_SEARCH : (key == KC_WWW_HOME ? AC_HOME : (key == KC_WWW_BACK ? AC_BACK : (key == KC_WWW_FORWARD ? AC_FORWARD : (key == KC_WWW_STOP ? AC_STOP : (key == KC_WWW_REFRESH ? AC_REFRESH : (key == KC_BRIGHTNESS_UP ? BRIGHTNESS_UP : (key == KC_BRIGHTNESS_DOWN ? BRIGHTNESS_DOWN : (key == KC_WWW_FAVORITES ? AC_BOOKMARKS : 0)))))))))))))))))))))))
 
 uint8_t has_anykey(report_keyboard_t* keyboard_report);
 uint8_t get_first_key(report_keyboard_t* keyboard_report);
index 7a64d00c7f7aade309906eb737f411c5a227835b..bd7b94fd99ff7528afa9c9e6f8d48d15b6493c6f 100644 (file)
@@ -20,7 +20,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <stdint.h>
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
index 29333062282dff472bfbd9e98cf403ce40d09453..f6cab1b9d1f5399d693f085c1ffe8859698ca6c5 100644 (file)
@@ -16,8 +16,4 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "sendchar.h"
 
-
-int8_t sendchar(uint8_t c)
-{
-    return 0;
-}
+int8_t sendchar(uint8_t c) { return 0; }
index 0241859eb7087548f468698afeb1966e093a16a3..2fc48bafffbc3f5427f4c296ffd661f25c335b31 100644 (file)
@@ -17,9 +17,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "uart.h"
 #include "sendchar.h"
 
-
-int8_t sendchar(uint8_t c)
-{
+int8_t sendchar(uint8_t c) {
     uart_putchar(c);
     return 0;
 }
index 6bdcf558a4503f50b1c81a81546482cf56a4112a..d160213f11c71e5327c11482b0b3397b305fd476 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef SLEEP_LED_H
 #define SLEEP_LED_H
 
-
 #ifdef SLEEP_LED_ENABLE
 
 void sleep_led_init(void);
@@ -11,10 +10,10 @@ void sleep_led_toggle(void);
 
 #else
 
-#define sleep_led_init()
-#define sleep_led_enable()
-#define sleep_led_disable()
-#define sleep_led_toggle()
+#    define sleep_led_init()
+#    define sleep_led_enable()
+#    define sleep_led_disable()
+#    define sleep_led_toggle()
 
 #endif
 
index c3e4447085c239d55d4cf13c2dc0eba317103ab5..87f5025da77b8b7087f5bbdf0d748445182e986e 100644 (file)
@@ -4,7 +4,6 @@
 #include <stdint.h>
 #include <stdbool.h>
 
-
 void suspend_idle(uint8_t timeout);
 void suspend_power_down(void);
 bool suspend_wakeup_condition(void);
@@ -12,7 +11,7 @@ void suspend_wakeup_init(void);
 
 void suspend_wakeup_init_user(void);
 void suspend_wakeup_init_kb(void);
-void suspend_power_down_user (void);
+void suspend_power_down_user(void);
 void suspend_power_down_kb(void);
 
 #endif
index 61cc039efaff75afc2144dbdff1ccff5a7d12664..44a0bf4d763b938d63b2b48e6bbf7cb4e2193498 100644 (file)
 static uint8_t buffer[EEPROM_SIZE];
 
 uint8_t eeprom_read_byte(const uint8_t *addr) {
-       uintptr_t offset = (uintptr_t)addr;
-       return buffer[offset];
+    uintptr_t offset = (uintptr_t)addr;
+    return buffer[offset];
 }
 
 void eeprom_write_byte(uint8_t *addr, uint8_t value) {
-       uintptr_t offset = (uintptr_t)addr;
-       buffer[offset] = value;
+    uintptr_t offset = (uintptr_t)addr;
+    buffer[offset]   = value;
 }
 
 uint16_t eeprom_read_word(const uint16_t *addr) {
-       const uint8_t *p = (const uint8_t *)addr;
-       return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8);
+    const uint8_t *p = (const uint8_t *)addr;
+    return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8);
 }
 
 uint32_t eeprom_read_dword(const uint32_t *addr) {
-       const uint8_t *p = (const uint8_t *)addr;
-       return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8)
-               | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24);
+    const uint8_t *p = (const uint8_t *)addr;
+    return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24);
 }
 
 void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
-       const uint8_t *p = (const uint8_t *)addr;
-       uint8_t *dest = (uint8_t *)buf;
-       while (len--) {
-               *dest++ = eeprom_read_byte(p++);
-       }
+    const uint8_t *p    = (const uint8_t *)addr;
+    uint8_t *      dest = (uint8_t *)buf;
+    while (len--) {
+        *dest++ = eeprom_read_byte(p++);
+    }
 }
 
 void eeprom_write_word(uint16_t *addr, uint16_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p, value >> 8);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p, value >> 8);
 }
 
 void eeprom_write_dword(uint32_t *addr, uint32_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p++, value >> 8);
-       eeprom_write_byte(p++, value >> 16);
-       eeprom_write_byte(p, value >> 24);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p++, value >> 8);
+    eeprom_write_byte(p++, value >> 16);
+    eeprom_write_byte(p, value >> 24);
 }
 
 void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
-       uint8_t *p = (uint8_t *)addr;
-       const uint8_t *src = (const uint8_t *)buf;
-       while (len--) {
-               eeprom_write_byte(p++, *src++);
-       }
+    uint8_t *      p   = (uint8_t *)addr;
+    const uint8_t *src = (const uint8_t *)buf;
+    while (len--) {
+        eeprom_write_byte(p++, *src++);
+    }
 }
 
-void eeprom_update_byte(uint8_t *addr, uint8_t value) {
-       eeprom_write_byte(addr, value);
-}
+void eeprom_update_byte(uint8_t *addr, uint8_t value) { eeprom_write_byte(addr, value); }
 
 void eeprom_update_word(uint16_t *addr, uint16_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p, value >> 8);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p, value >> 8);
 }
 
 void eeprom_update_dword(uint32_t *addr, uint32_t value) {
-       uint8_t *p = (uint8_t *)addr;
-       eeprom_write_byte(p++, value);
-       eeprom_write_byte(p++, value >> 8);
-       eeprom_write_byte(p++, value >> 16);
-       eeprom_write_byte(p, value >> 24);
+    uint8_t *p = (uint8_t *)addr;
+    eeprom_write_byte(p++, value);
+    eeprom_write_byte(p++, value >> 8);
+    eeprom_write_byte(p++, value >> 16);
+    eeprom_write_byte(p, value >> 24);
 }
 
 void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
-       uint8_t *p = (uint8_t *)addr;
-       const uint8_t *src = (const uint8_t *)buf;
-       while (len--) {
-               eeprom_write_byte(p++, *src++);
-       }
+    uint8_t *      p   = (uint8_t *)addr;
+    const uint8_t *src = (const uint8_t *)buf;
+    while (len--) {
+        eeprom_write_byte(p++, *src++);
+    }
 }
index 01d1930ea502e723e7d954fb9666db71b65a9990..76b705967b3150c88cd009f08eadfa4b21430144 100644 (file)
@@ -13,5 +13,3 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-
-
index 19e79e1f54b4f0aceab7625e890e5b2ec44c4ddd..3c786ae2931326f7188bda5fa90943ec66cbcc55 100644 (file)
@@ -18,9 +18,9 @@
 
 static uint32_t current_time = 0;
 
-void timer_init(void) {current_time = 0;}
+void timer_init(void) { current_time = 0; }
 
-void timer_clear(void) {current_time = 0;}
+void timer_clear(void) { current_time = 0; }
 
 uint16_t timer_read(void) { return current_time & 0xFFFF; }
 uint32_t timer_read32(void) { return current_time; }
@@ -30,6 +30,4 @@ uint32_t timer_elapsed32(uint32_t last) { return TIMER_DIFF_32(timer_read32(), l
 void set_time(uint32_t t) { current_time = t; }
 void advance_time(uint32_t ms) { current_time += ms; }
 
-void wait_ms(uint32_t ms) {
-    advance_time(ms);
-}
\ No newline at end of file
+void wait_ms(uint32_t ms) { advance_time(ms); }
\ No newline at end of file
index a8dd85663fabb267f3873b30d957804ae4bad224..853cb9839687670ebf3518f118f8efcf0eac87a9 100644 (file)
@@ -22,16 +22,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdbool.h>
 
 #if defined(__AVR__)
-#include "avr/timer_avr.h"
+#    include "avr/timer_avr.h"
 #endif
 
-
-#define TIMER_DIFF(a, b, max)   ((a) >= (b) ?  (a) - (b) : (max) - (b) + (a))
-#define TIMER_DIFF_8(a, b)      TIMER_DIFF(a, b, UINT8_MAX)
-#define TIMER_DIFF_16(a, b)     TIMER_DIFF(a, b, UINT16_MAX)
-#define TIMER_DIFF_32(a, b)     TIMER_DIFF(a, b, UINT32_MAX)
-#define TIMER_DIFF_RAW(a, b)    TIMER_DIFF_8(a, b)
-
+#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a))
+#define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX)
+#define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX)
+#define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX)
+#define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b)
 
 #ifdef __cplusplus
 extern "C" {
@@ -39,23 +37,17 @@ extern "C" {
 
 extern volatile uint32_t timer_count;
 
-
-void timer_init(void);
-void timer_clear(void);
+void     timer_init(void);
+void     timer_clear(void);
 uint16_t timer_read(void);
 uint32_t timer_read32(void);
 uint16_t timer_elapsed(uint16_t last);
 uint32_t timer_elapsed32(uint32_t last);
 
 // Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value)
-inline bool timer_expired(uint16_t current, uint16_t last)
-{
-    return current - last < 0x8000;
-}
+inline bool timer_expired(uint16_t current, uint16_t last) { return current - last < 0x8000; }
 
-inline bool timer_expired32(uint32_t current, uint32_t future) {
-    return current - future < 0x80000000;
-}
+inline bool timer_expired32(uint32_t current, uint32_t future) { return current - future < 0x80000000; }
 
 #ifdef __cplusplus
 }
index c17649b08220393e13cb948ef6f914b26bc6fce1..f2e4bc4f34e9ea8232233db0f2460486797ed909 100644 (file)
@@ -3,17 +3,17 @@
 /* UART Example for Teensy USB Development Board
  * http://www.pjrc.com/teensy/
  * Copyright (c) 2009 PJRC.COM, LLC
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -26,7 +26,6 @@
 // Version 1.0: Initial Release
 // Version 1.1: Add support for Teensy 2.0, minor optimizations
 
-
 #include <avr/io.h>
 #include <avr/interrupt.h>
 
@@ -44,86 +43,81 @@ static volatile uint8_t rx_buffer_head;
 static volatile uint8_t rx_buffer_tail;
 
 // Initialize the UART
-void uart_init(uint32_t baud)
-{
-       cli();
-       UBRR0 = (F_CPU / 4 / baud - 1) / 2;
-       UCSR0A = (1<<U2X0);
-       UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
-       UCSR0C = (1<<UCSZ01) | (1<<UCSZ00);
-       tx_buffer_head = tx_buffer_tail = 0;
-       rx_buffer_head = rx_buffer_tail = 0;
-       sei();
+void uart_init(uint32_t baud) {
+    cli();
+    UBRR0          = (F_CPU / 4 / baud - 1) / 2;
+    UCSR0A         = (1 << U2X0);
+    UCSR0B         = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
+    UCSR0C         = (1 << UCSZ01) | (1 << UCSZ00);
+    tx_buffer_head = tx_buffer_tail = 0;
+    rx_buffer_head = rx_buffer_tail = 0;
+    sei();
 }
 
 // Transmit a byte
-void uart_putchar(uint8_t c)
-{
-       uint8_t i;
-
-       i = tx_buffer_head + 1;
-       if (i >= TX_BUFFER_SIZE) i = 0;
-       while (tx_buffer_tail == i) ; // wait until space in buffer
-       //cli();
-       tx_buffer[i] = c;
-       tx_buffer_head = i;
-       UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0) | (1<<UDRIE0);
-       //sei();
+void uart_putchar(uint8_t c) {
+    uint8_t i;
+
+    i = tx_buffer_head + 1;
+    if (i >= TX_BUFFER_SIZE) i = 0;
+    while (tx_buffer_tail == i)
+        ;  // wait until space in buffer
+    // cli();
+    tx_buffer[i]   = c;
+    tx_buffer_head = i;
+    UCSR0B         = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0) | (1 << UDRIE0);
+    // sei();
 }
 
 // Receive a byte
-uint8_t uart_getchar(void)
-{
-        uint8_t c, i;
-
-       while (rx_buffer_head == rx_buffer_tail) ; // wait for character
-        i = rx_buffer_tail + 1;
-        if (i >= RX_BUFFER_SIZE) i = 0;
-        c = rx_buffer[i];
-        rx_buffer_tail = i;
-        return c;
+uint8_t uart_getchar(void) {
+    uint8_t c, i;
+
+    while (rx_buffer_head == rx_buffer_tail)
+        ;  // wait for character
+    i = rx_buffer_tail + 1;
+    if (i >= RX_BUFFER_SIZE) i = 0;
+    c              = rx_buffer[i];
+    rx_buffer_tail = i;
+    return c;
 }
 
 // Return the number of bytes waiting in the receive buffer.
 // Call this before uart_getchar() to check if it will need
 // to wait for a byte to arrive.
-uint8_t uart_available(void)
-{
-       uint8_t head, tail;
-
-       head = rx_buffer_head;
-       tail = rx_buffer_tail;
-       if (head >= tail) return head - tail;
-       return RX_BUFFER_SIZE + head - tail;
+uint8_t uart_available(void) {
+    uint8_t head, tail;
+
+    head = rx_buffer_head;
+    tail = rx_buffer_tail;
+    if (head >= tail) return head - tail;
+    return RX_BUFFER_SIZE + head - tail;
 }
 
 // Transmit Interrupt
-ISR(USART_UDRE_vect)
-{
-       uint8_t i;
-
-       if (tx_buffer_head == tx_buffer_tail) {
-               // buffer is empty, disable transmit interrupt
-               UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
-       } else {
-               i = tx_buffer_tail + 1;
-               if (i >= TX_BUFFER_SIZE) i = 0;
-               UDR0 = tx_buffer[i];
-               tx_buffer_tail = i;
-       }
+ISR(USART_UDRE_vect) {
+    uint8_t i;
+
+    if (tx_buffer_head == tx_buffer_tail) {
+        // buffer is empty, disable transmit interrupt
+        UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
+    } else {
+        i = tx_buffer_tail + 1;
+        if (i >= TX_BUFFER_SIZE) i = 0;
+        UDR0           = tx_buffer[i];
+        tx_buffer_tail = i;
+    }
 }
 
 // Receive Interrupt
-ISR(USART_RX_vect)
-{
-       uint8_t c, i;
-
-       c = UDR0;
-       i = rx_buffer_head + 1;
-       if (i >= RX_BUFFER_SIZE) i = 0;
-       if (i != rx_buffer_tail) {
-               rx_buffer[i] = c;
-               rx_buffer_head = i;
-       }
+ISR(USART_RX_vect) {
+    uint8_t c, i;
+
+    c = UDR0;
+    i = rx_buffer_head + 1;
+    if (i >= RX_BUFFER_SIZE) i = 0;
+    if (i != rx_buffer_tail) {
+        rx_buffer[i]   = c;
+        rx_buffer_head = i;
+    }
 }
-
index 41136a396fd9a22056e1608075d32293921733df..59a1a7cd12e4ec41c209e849b004c0b5cb07187f 100644 (file)
@@ -3,8 +3,8 @@
 
 #include <stdint.h>
 
-void uart_init(uint32_t baud);
-void uart_putchar(uint8_t c);
+void    uart_init(uint32_t baud);
+void    uart_putchar(uint8_t c);
 uint8_t uart_getchar(void);
 uint8_t uart_available(void);
 
index 7e0d542993a955be815c2dbb495793f40ed68dd1..f4f018de8d64a0cfaaf6b2384ecf4a194f7f6671 100644 (file)
@@ -18,84 +18,106 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "util.h"
 
 // bit population - return number of on-bit
-uint8_t bitpop(uint8_t bits)
-{
+uint8_t bitpop(uint8_t bits) {
     uint8_t c;
-    for (c = 0; bits; c++)
-        bits &= bits - 1;
+    for (c = 0; bits; c++) bits &= bits - 1;
     return c;
-/*
-    const uint8_t bit_count[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
-    return bit_count[bits>>4] + bit_count[bits&0x0F]
-*/
+    /*
+        const uint8_t bit_count[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
+        return bit_count[bits>>4] + bit_count[bits&0x0F]
+    */
 }
 
-uint8_t bitpop16(uint16_t bits)
-{
+uint8_t bitpop16(uint16_t bits) {
     uint8_t c;
-    for (c = 0; bits; c++)
-        bits &= bits - 1;
+    for (c = 0; bits; c++) bits &= bits - 1;
     return c;
 }
 
-uint8_t bitpop32(uint32_t bits)
-{
+uint8_t bitpop32(uint32_t bits) {
     uint8_t c;
-    for (c = 0; bits; c++)
-        bits &= bits - 1;
+    for (c = 0; bits; c++) bits &= bits - 1;
     return c;
 }
 
 // most significant on-bit - return highest location of on-bit
 // NOTE: return 0 when bit0 is on or all bits are off
-uint8_t biton(uint8_t bits)
-{
+uint8_t biton(uint8_t bits) {
     uint8_t n = 0;
-    if (bits >> 4) { bits >>= 4; n += 4;}
-    if (bits >> 2) { bits >>= 2; n += 2;}
-    if (bits >> 1) { bits >>= 1; n += 1;}
+    if (bits >> 4) {
+        bits >>= 4;
+        n += 4;
+    }
+    if (bits >> 2) {
+        bits >>= 2;
+        n += 2;
+    }
+    if (bits >> 1) {
+        bits >>= 1;
+        n += 1;
+    }
     return n;
 }
 
-uint8_t biton16(uint16_t bits)
-{
+uint8_t biton16(uint16_t bits) {
     uint8_t n = 0;
-    if (bits >> 8) { bits >>= 8; n += 8;}
-    if (bits >> 4) { bits >>= 4; n += 4;}
-    if (bits >> 2) { bits >>= 2; n += 2;}
-    if (bits >> 1) { bits >>= 1; n += 1;}
+    if (bits >> 8) {
+        bits >>= 8;
+        n += 8;
+    }
+    if (bits >> 4) {
+        bits >>= 4;
+        n += 4;
+    }
+    if (bits >> 2) {
+        bits >>= 2;
+        n += 2;
+    }
+    if (bits >> 1) {
+        bits >>= 1;
+        n += 1;
+    }
     return n;
 }
 
-uint8_t biton32(uint32_t bits)
-{
+uint8_t biton32(uint32_t bits) {
     uint8_t n = 0;
-    if (bits >>16) { bits >>=16; n +=16;}
-    if (bits >> 8) { bits >>= 8; n += 8;}
-    if (bits >> 4) { bits >>= 4; n += 4;}
-    if (bits >> 2) { bits >>= 2; n += 2;}
-    if (bits >> 1) { bits >>= 1; n += 1;}
+    if (bits >> 16) {
+        bits >>= 16;
+        n += 16;
+    }
+    if (bits >> 8) {
+        bits >>= 8;
+        n += 8;
+    }
+    if (bits >> 4) {
+        bits >>= 4;
+        n += 4;
+    }
+    if (bits >> 2) {
+        bits >>= 2;
+        n += 2;
+    }
+    if (bits >> 1) {
+        bits >>= 1;
+        n += 1;
+    }
     return n;
 }
 
-
-
-uint8_t bitrev(uint8_t bits)
-{
-    bits = (bits & 0x0f)<<4 | (bits & 0xf0)>>4;
-    bits = (bits & 0b00110011)<<2 | (bits & 0b11001100)>>2;
-    bits = (bits & 0b01010101)<<1 | (bits & 0b10101010)>>1;
+uint8_t bitrev(uint8_t bits) {
+    bits = (bits & 0x0f) << 4 | (bits & 0xf0) >> 4;
+    bits = (bits & 0b00110011) << 2 | (bits & 0b11001100) >> 2;
+    bits = (bits & 0b01010101) << 1 | (bits & 0b10101010) >> 1;
     return bits;
 }
 
-uint16_t bitrev16(uint16_t bits)
-{
-    bits = bitrev(bits & 0x00ff)<<8 | bitrev((bits & 0xff00)>>8);
+uint16_t bitrev16(uint16_t bits) {
+    bits = bitrev(bits & 0x00ff) << 8 | bitrev((bits & 0xff00) >> 8);
     return bits;
 }
 
-uint32_t bitrev32(uint32_t bits)
-{
-    bits = (uint32_t)bitrev16(bits & 0x0000ffff)<<16 | bitrev16((bits & 0xffff0000)>>16);
+uint32_t bitrev32(uint32_t bits) {
+    bits = (uint32_t)bitrev16(bits & 0x0000ffff) << 16 | bitrev16((bits & 0xffff0000) >> 16);
     return bits;
 }
index 7451cc084da9e4483977411dc1ed19eb99475d5a..5706b047d060c86dd319accbc9be89f4b487cd07 100644 (file)
@@ -22,12 +22,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // convert to L string
 #define LSTR(s) XLSTR(s)
-#define XLSTR(s) L ## #s
+#define XLSTR(s) L## #s
 // convert to string
 #define STR(s) XSTR(s)
 #define XSTR(s) #s
 
-
 uint8_t bitpop(uint8_t bits);
 uint8_t bitpop16(uint16_t bits);
 uint8_t bitpop32(uint32_t bits);
index 9aed372b7f214e5e2e9cc7558455faf4962e0635..cb1f386a6169e25bf739148b19356f57640cf817 100644 (file)
@@ -8,22 +8,36 @@ extern "C" {
 #endif
 
 #if defined(__AVR__)
-#   include <util/delay.h>
-#   define wait_ms(ms)  _delay_ms(ms)
-#   define wait_us(us)  _delay_us(us)
+#    include <util/delay.h>
+#    define wait_ms(ms) _delay_ms(ms)
+#    define wait_us(us) _delay_us(us)
 #elif defined PROTOCOL_CHIBIOS
-#   include "ch.h"
-#   define wait_ms(ms) do { if (ms != 0) { chThdSleepMilliseconds(ms); } else { chThdSleepMicroseconds(1); } } while (0)
-#   define wait_us(us) do { if (us != 0) { chThdSleepMicroseconds(us); } else { chThdSleepMicroseconds(1); } } while (0)
+#    include "ch.h"
+#    define wait_ms(ms)                     \
+        do {                                \
+            if (ms != 0) {                  \
+                chThdSleepMilliseconds(ms); \
+            } else {                        \
+                chThdSleepMicroseconds(1);  \
+            }                               \
+        } while (0)
+#    define wait_us(us)                     \
+        do {                                \
+            if (us != 0) {                  \
+                chThdSleepMicroseconds(us); \
+            } else {                        \
+                chThdSleepMicroseconds(1);  \
+            }                               \
+        } while (0)
 #elif defined PROTOCOL_ARM_ATSAM
-#   include "clks.h"
-#   define wait_ms(ms) CLK_delay_ms(ms)
-#   define wait_us(us) CLK_delay_us(us)
+#    include "clks.h"
+#    define wait_ms(ms) CLK_delay_ms(ms)
+#    define wait_us(us) CLK_delay_us(us)
 #elif defined(__arm__)
-#   include "wait_api.h"
+#    include "wait_api.h"
 #else  // Unit tests
 void wait_ms(uint32_t ms);
-#define wait_us(us) wait_ms(us / 1000)
+#    define wait_us(us) wait_ms(us / 1000)
 #endif
 
 #ifdef __cplusplus
index 5c6c99b4fcc225fd4b5293eeafe1459271608a9c..a23c919619a7eccb673614bc7f83b2f11701c8ea 100644 (file)
@@ -42,11 +42,10 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <avr/interrupt.h>
 #include "adb.h"
 
-
 // GCC doesn't inline functions normally
-#define data_lo() (ADB_DDR |=  (1<<ADB_DATA_BIT))
-#define data_hi() (ADB_DDR &= ~(1<<ADB_DATA_BIT))
-#define data_in() (ADB_PIN &   (1<<ADB_DATA_BIT))
+#define data_lo() (ADB_DDR |= (1 << ADB_DATA_BIT))
+#define data_hi() (ADB_DDR &= ~(1 << ADB_DATA_BIT))
+#define data_in() (ADB_PIN & (1 << ADB_DATA_BIT))
 
 #ifdef ADB_PSW_BIT
 static inline void psw_lo(void);
@@ -54,18 +53,16 @@ static inline void psw_hi(void);
 static inline bool psw_in(void);
 #endif
 
-static inline void attention(void);
-static inline void place_bit0(void);
-static inline void place_bit1(void);
-static inline void send_byte(uint8_t data);
+static inline void     attention(void);
+static inline void     place_bit0(void);
+static inline void     place_bit1(void);
+static inline void     send_byte(uint8_t data);
 static inline uint16_t wait_data_lo(uint16_t us);
 static inline uint16_t wait_data_hi(uint16_t us);
 static inline uint16_t adb_host_dev_recv(uint8_t device);
 
-
-void adb_host_init(void)
-{
-    ADB_PORT &= ~(1<<ADB_DATA_BIT);
+void adb_host_init(void) {
+    ADB_PORT &= ~(1 << ADB_DATA_BIT);
     data_hi();
 #ifdef ADB_PSW_BIT
     psw_hi();
@@ -73,10 +70,7 @@ void adb_host_init(void)
 }
 
 #ifdef ADB_PSW_BIT
-bool adb_host_psw(void)
-{
-    return psw_in();
-}
+bool adb_host_psw(void) { return psw_in(); }
 #endif
 
 /*
@@ -105,11 +99,11 @@ bool adb_host_psw(void)
 // bit0:
 //    70us bit cell:
 //      ____________~~~~~~
-//      42-49        21-28  
+//      42-49        21-28
 //
 //    130us bit cell:
 //      ____________~~~~~~
-//      78-91        39-52  
+//      78-91        39-52
 //
 // bit1:
 //    70us bit cell:
@@ -122,66 +116,50 @@ bool adb_host_psw(void)
 //
 // [from Apple IIgs Hardware Reference Second Edition]
 
-enum {
-    ADDR_KEYB  = 0x20,
-    ADDR_MOUSE = 0x30
-};
+enum { ADDR_KEYB = 0x20, ADDR_MOUSE = 0x30 };
 
-uint16_t adb_host_kbd_recv(void)
-{
-    return adb_host_dev_recv(ADDR_KEYB);
-}
+uint16_t adb_host_kbd_recv(void) { return adb_host_dev_recv(ADDR_KEYB); }
 
 #ifdef ADB_MOUSE_ENABLE
-void adb_mouse_init(void) {
-           return;
-}
+void adb_mouse_init(void) { return; }
 
-uint16_t adb_host_mouse_recv(void)
-{
-    return adb_host_dev_recv(ADDR_MOUSE);
-}
+uint16_t adb_host_mouse_recv(void) { return adb_host_dev_recv(ADDR_MOUSE); }
 #endif
 
-static inline uint16_t adb_host_dev_recv(uint8_t device)
-{
+static inline uint16_t adb_host_dev_recv(uint8_t device) {
     uint16_t data = 0;
     cli();
     attention();
-    send_byte(device|0x0C);     // Addr:Keyboard(0010)/Mouse(0011), Cmd:Talk(11), Register0(00)
-    place_bit0();               // Stopbit(0)
-    if (!wait_data_hi(500)) {    // Service Request(310us Adjustable Keyboard): just ignored
+    send_byte(device | 0x0C);  // Addr:Keyboard(0010)/Mouse(0011), Cmd:Talk(11), Register0(00)
+    place_bit0();              // Stopbit(0)
+    if (!wait_data_hi(500)) {  // Service Request(310us Adjustable Keyboard): just ignored
         sei();
-        return -30;             // something wrong
+        return -30;  // something wrong
     }
-    if (!wait_data_lo(500)) {   // Tlt/Stop to Start(140-260us)
+    if (!wait_data_lo(500)) {  // Tlt/Stop to Start(140-260us)
         sei();
-        return 0;               // No data to send
+        return 0;  // No data to send
     }
-    
-    uint8_t n = 17; // start bit + 16 data bits
+
+    uint8_t n = 17;  // start bit + 16 data bits
     do {
-        uint8_t lo = (uint8_t) wait_data_hi(130);
-        if (!lo)
-            goto error;
-        
-        uint8_t hi = (uint8_t) wait_data_lo(lo);
-        if (!hi)
-            goto error;
-        
+        uint8_t lo = (uint8_t)wait_data_hi(130);
+        if (!lo) goto error;
+
+        uint8_t hi = (uint8_t)wait_data_lo(lo);
+        if (!hi) goto error;
+
         hi = lo - hi;
         lo = 130 - lo;
-        
+
         data <<= 1;
         if (lo < hi) {
             data |= 1;
-        }
-        else if (n == 17) {
+        } else if (n == 17) {
             sei();
             return -20;
         }
-    }
-    while ( --n );
+    } while (--n);
 
     // Stop bit can't be checked normally since it could have service request lenghtening
     // and its high state never goes low.
@@ -197,76 +175,66 @@ error:
     return -n;
 }
 
-void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l)
-{
+void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l) {
     cli();
     attention();
     send_byte(cmd);
-    place_bit0();               // Stopbit(0)
-    _delay_us(200);             // Tlt/Stop to Start
-    place_bit1();               // Startbit(1)
-    send_byte(data_h); 
+    place_bit0();    // Stopbit(0)
+    _delay_us(200);  // Tlt/Stop to Start
+    place_bit1();    // Startbit(1)
+    send_byte(data_h);
     send_byte(data_l);
-    place_bit0();               // Stopbit(0);
+    place_bit0();  // Stopbit(0);
     sei();
 }
 
 // send state of LEDs
-void adb_host_kbd_led(uint8_t led)
-{
+void adb_host_kbd_led(uint8_t led) {
     // Addr:Keyboard(0010), Cmd:Listen(10), Register2(10)
     // send upper byte (not used)
     // send lower byte (bit2: ScrollLock, bit1: CapsLock, bit0:
-    adb_host_listen(0x2A,0,led&0x07);
+    adb_host_listen(0x2A, 0, led & 0x07);
 }
 
-
 #ifdef ADB_PSW_BIT
-static inline void psw_lo()
-{
-    ADB_DDR  |=  (1<<ADB_PSW_BIT);
-    ADB_PORT &= ~(1<<ADB_PSW_BIT);
+static inline void psw_lo() {
+    ADB_DDR |= (1 << ADB_PSW_BIT);
+    ADB_PORT &= ~(1 << ADB_PSW_BIT);
 }
-static inline void psw_hi()
-{
-    ADB_PORT |=  (1<<ADB_PSW_BIT);
-    ADB_DDR  &= ~(1<<ADB_PSW_BIT);
+static inline void psw_hi() {
+    ADB_PORT |= (1 << ADB_PSW_BIT);
+    ADB_DDR &= ~(1 << ADB_PSW_BIT);
 }
-static inline bool psw_in()
-{
-    ADB_PORT |=  (1<<ADB_PSW_BIT);
-    ADB_DDR  &= ~(1<<ADB_PSW_BIT);
-    return ADB_PIN&(1<<ADB_PSW_BIT);
+static inline bool psw_in() {
+    ADB_PORT |= (1 << ADB_PSW_BIT);
+    ADB_DDR &= ~(1 << ADB_PSW_BIT);
+    return ADB_PIN & (1 << ADB_PSW_BIT);
 }
 #endif
 
-static inline void attention(void)
-{
+static inline void attention(void) {
     data_lo();
-    _delay_us(800-35); // bit1 holds lo for 35 more
+    _delay_us(800 - 35);  // bit1 holds lo for 35 more
     place_bit1();
 }
 
-static inline void place_bit0(void)
-{
+static inline void place_bit0(void) {
     data_lo();
     _delay_us(65);
     data_hi();
     _delay_us(35);
 }
 
-static inline void place_bit1(void)
-{
+static inline void place_bit1(void) {
     data_lo();
     _delay_us(35);
     data_hi();
     _delay_us(65);
 }
 
-static inline void send_byte(uint8_t data)
-{
+static inline void send_byte(uint8_t data) {
     for (int i = 0; i < 8; i++) {
-        if (data&(0x80>>i))
+        if (data & (0x80 >> i))
             place_bit1();
         else
             place_bit0();
@@ -275,29 +243,22 @@ static inline void send_byte(uint8_t data)
 
 // These are carefully coded to take 6 cycles of overhead.
 // inline asm approach became too convoluted
-static inline uint16_t wait_data_lo(uint16_t us)
-{
+static inline uint16_t wait_data_lo(uint16_t us) {
     do {
-        if ( !data_in() )
-            break;
+        if (!data_in()) break;
         _delay_us(1 - (6 * 1000000.0 / F_CPU));
-    }
-    while ( --us );
+    } while (--us);
     return us;
 }
 
-static inline uint16_t wait_data_hi(uint16_t us)
-{
+static inline uint16_t wait_data_hi(uint16_t us) {
     do {
-        if ( data_in() )
-            break;
+        if (data_in()) break;
         _delay_us(1 - (6 * 1000000.0 / F_CPU));
-    }
-    while ( --us );
+    } while (--us);
     return us;
 }
 
-
 /*
 ADB Protocol
 ============
@@ -375,7 +336,7 @@ Commands
     A A A A 1 1 R R     Talk(read from a device)
 
     The command to read keycodes from keyboard is 0x2C which
-    consist of keyboard address 2 and Talk against register 0. 
+    consist of keyboard address 2 and Talk against register 0.
 
     Address:
     2:  keyboard
@@ -457,7 +418,7 @@ Keyboard Data(Register0)
 Keyboard LEDs & state of keys(Register2)
     This register hold current state of three LEDs and nine keys.
     The state of LEDs can be changed by sending Listen command.
-    
+
     1514 . . . . . . 7 6 5 . 3 2 1 0
      | | | | | | | | | | | | | | | +-   LED1(NumLock)
      | | | | | | | | | | | | | | +---   LED2(CapsLock)
index b4b3633cf450a5bd6ba37a3a952f692ce3e313a1..7d37485fcd77f374fe2794b50ef4a76f58b7c367 100644 (file)
@@ -41,16 +41,12 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <stdint.h>
 #include <stdbool.h>
 
-#if !(defined(ADB_PORT) && \
-      defined(ADB_PIN)  && \
-      defined(ADB_DDR)  && \
-      defined(ADB_DATA_BIT))
-#   error "ADB port setting is required in config.h"
+#if !(defined(ADB_PORT) && defined(ADB_PIN) && defined(ADB_DDR) && defined(ADB_DATA_BIT))
+#    error "ADB port setting is required in config.h"
 #endif
 
-#define ADB_POWER       0x7F
-#define ADB_CAPS        0x39
-
+#define ADB_POWER 0x7F
+#define ADB_CAPS 0x39
 
 // ADB host
 void     adb_host_init(void);
@@ -62,5 +58,4 @@ void     adb_host_kbd_led(uint8_t led);
 void     adb_mouse_task(void);
 void     adb_mouse_init(void);
 
-
 #endif
index cb5c349b7305b65e539b5b6e32147e0e21d99a67..1ef1b11d572179b57df9cdee39cee892cb45bdb9 100644 (file)
@@ -24,76 +24,92 @@ uint16_t v_con_2;
 uint16_t v_con_1_boot;
 uint16_t v_con_2_boot;
 
-void ADC0_clock_init(void)
-{
+void ADC0_clock_init(void) {
     DBGC(DC_ADC0_CLOCK_INIT_BEGIN);
 
-    MCLK->APBDMASK.bit.ADC0_ = 1;                        //ADC0 Clock Enable
+    MCLK->APBDMASK.bit.ADC0_ = 1;  // ADC0 Clock Enable
 
-    GCLK->PCHCTRL[ADC0_GCLK_ID].bit.GEN = GEN_OSC0;      //Select generator clock
-    GCLK->PCHCTRL[ADC0_GCLK_ID].bit.CHEN = 1;            //Enable peripheral clock
+    GCLK->PCHCTRL[ADC0_GCLK_ID].bit.GEN  = GEN_OSC0;  // Select generator clock
+    GCLK->PCHCTRL[ADC0_GCLK_ID].bit.CHEN = 1;         // Enable peripheral clock
 
     DBGC(DC_ADC0_CLOCK_INIT_COMPLETE);
 }
 
-void ADC0_init(void)
-{
+void ADC0_init(void) {
     DBGC(DC_ADC0_INIT_BEGIN);
 
-    //MCU
-    PORT->Group[1].DIRCLR.reg = 1 << 0;                   //PB00 as input 5V
-    PORT->Group[1].DIRCLR.reg = 1 << 1;                   //PB01 as input CON2
-    PORT->Group[1].DIRCLR.reg = 1 << 2;                   //PB02 as input CON1
-    PORT->Group[1].PMUX[0].bit.PMUXE = 1;                 //PB00 mux select B ADC 5V
-    PORT->Group[1].PMUX[0].bit.PMUXO = 1;                 //PB01 mux select B ADC CON2
-    PORT->Group[1].PMUX[1].bit.PMUXE = 1;                 //PB02 mux select B ADC CON1
-    PORT->Group[1].PINCFG[0].bit.PMUXEN = 1;              //PB01 mux ADC Enable 5V
-    PORT->Group[1].PINCFG[1].bit.PMUXEN = 1;              //PB01 mux ADC Enable CON2
-    PORT->Group[1].PINCFG[2].bit.PMUXEN = 1;              //PB02 mux ADC Enable CON1
-
-    //ADC
+    // MCU
+    PORT->Group[1].DIRCLR.reg           = 1 << 0;  // PB00 as input 5V
+    PORT->Group[1].DIRCLR.reg           = 1 << 1;  // PB01 as input CON2
+    PORT->Group[1].DIRCLR.reg           = 1 << 2;  // PB02 as input CON1
+    PORT->Group[1].PMUX[0].bit.PMUXE    = 1;       // PB00 mux select B ADC 5V
+    PORT->Group[1].PMUX[0].bit.PMUXO    = 1;       // PB01 mux select B ADC CON2
+    PORT->Group[1].PMUX[1].bit.PMUXE    = 1;       // PB02 mux select B ADC CON1
+    PORT->Group[1].PINCFG[0].bit.PMUXEN = 1;       // PB01 mux ADC Enable 5V
+    PORT->Group[1].PINCFG[1].bit.PMUXEN = 1;       // PB01 mux ADC Enable CON2
+    PORT->Group[1].PINCFG[2].bit.PMUXEN = 1;       // PB02 mux ADC Enable CON1
+
+    // ADC
     ADC0->CTRLA.bit.SWRST = 1;
-    while (ADC0->SYNCBUSY.bit.SWRST) { DBGC(DC_ADC0_SWRST_SYNCING_1); }
-    while (ADC0->CTRLA.bit.SWRST) { DBGC(DC_ADC0_SWRST_SYNCING_2); }
-
-    //Clock divide
+    while (ADC0->SYNCBUSY.bit.SWRST) {
+        DBGC(DC_ADC0_SWRST_SYNCING_1);
+    }
+    while (ADC0->CTRLA.bit.SWRST) {
+        DBGC(DC_ADC0_SWRST_SYNCING_2);
+    }
+
+    // Clock divide
     ADC0->CTRLA.bit.PRESCALER = ADC_CTRLA_PRESCALER_DIV2_Val;
 
-    //Averaging
+    // Averaging
     ADC0->AVGCTRL.bit.SAMPLENUM = ADC_AVGCTRL_SAMPLENUM_4_Val;
-    while (ADC0->SYNCBUSY.bit.AVGCTRL) { DBGC(DC_ADC0_AVGCTRL_SYNCING_1); }
-    if      (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_1_Val) ADC0->AVGCTRL.bit.ADJRES = 0;
-    else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_2_Val) ADC0->AVGCTRL.bit.ADJRES = 1;
-    else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_4_Val) ADC0->AVGCTRL.bit.ADJRES = 2;
-    else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_8_Val) ADC0->AVGCTRL.bit.ADJRES = 3;
-    else                                                                 ADC0->AVGCTRL.bit.ADJRES = 4;
-    while (ADC0->SYNCBUSY.bit.AVGCTRL) { DBGC(DC_ADC0_AVGCTRL_SYNCING_2); }
-
-    //Settling
-    ADC0->SAMPCTRL.bit.SAMPLEN = 45;      //Sampling Time Length: 1-63, 1 ADC CLK per
-    while (ADC0->SYNCBUSY.bit.SAMPCTRL) { DBGC(DC_ADC0_SAMPCTRL_SYNCING_1); }
-
-    //Load factory calibration data
-    ADC0->CALIB.bit.BIASCOMP = ((*(uint32_t *)ADC0_FUSES_BIASCOMP_ADDR) & ADC0_FUSES_BIASCOMP_Msk) >> ADC0_FUSES_BIASCOMP_Pos;
-    ADC0->CALIB.bit.BIASR2R = ((*(uint32_t *)ADC0_FUSES_BIASR2R_ADDR) & ADC0_FUSES_BIASR2R_Msk) >> ADC0_FUSES_BIASR2R_Pos;
+    while (ADC0->SYNCBUSY.bit.AVGCTRL) {
+        DBGC(DC_ADC0_AVGCTRL_SYNCING_1);
+    }
+    if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_1_Val)
+        ADC0->AVGCTRL.bit.ADJRES = 0;
+    else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_2_Val)
+        ADC0->AVGCTRL.bit.ADJRES = 1;
+    else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_4_Val)
+        ADC0->AVGCTRL.bit.ADJRES = 2;
+    else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_8_Val)
+        ADC0->AVGCTRL.bit.ADJRES = 3;
+    else
+        ADC0->AVGCTRL.bit.ADJRES = 4;
+    while (ADC0->SYNCBUSY.bit.AVGCTRL) {
+        DBGC(DC_ADC0_AVGCTRL_SYNCING_2);
+    }
+
+    // Settling
+    ADC0->SAMPCTRL.bit.SAMPLEN = 45;  // Sampling Time Length: 1-63, 1 ADC CLK per
+    while (ADC0->SYNCBUSY.bit.SAMPCTRL) {
+        DBGC(DC_ADC0_SAMPCTRL_SYNCING_1);
+    }
+
+    // Load factory calibration data
+    ADC0->CALIB.bit.BIASCOMP   = ((*(uint32_t *)ADC0_FUSES_BIASCOMP_ADDR) & ADC0_FUSES_BIASCOMP_Msk) >> ADC0_FUSES_BIASCOMP_Pos;
+    ADC0->CALIB.bit.BIASR2R    = ((*(uint32_t *)ADC0_FUSES_BIASR2R_ADDR) & ADC0_FUSES_BIASR2R_Msk) >> ADC0_FUSES_BIASR2R_Pos;
     ADC0->CALIB.bit.BIASREFBUF = ((*(uint32_t *)ADC0_FUSES_BIASREFBUF_ADDR) & ADC0_FUSES_BIASREFBUF_Msk) >> ADC0_FUSES_BIASREFBUF_Pos;
 
-    //Enable
+    // Enable
     ADC0->CTRLA.bit.ENABLE = 1;
-    while (ADC0->SYNCBUSY.bit.ENABLE) { DBGC(DC_ADC0_ENABLE_SYNCING_1); }
+    while (ADC0->SYNCBUSY.bit.ENABLE) {
+        DBGC(DC_ADC0_ENABLE_SYNCING_1);
+    }
 
     DBGC(DC_ADC0_INIT_COMPLETE);
 }
 
-uint16_t adc_get(uint8_t muxpos)
-{
+uint16_t adc_get(uint8_t muxpos) {
     ADC0->INPUTCTRL.bit.MUXPOS = muxpos;
-    while (ADC0->SYNCBUSY.bit.INPUTCTRL) {}
+    while (ADC0->SYNCBUSY.bit.INPUTCTRL) {
+    }
 
     ADC0->SWTRIG.bit.START = 1;
-    while (ADC0->SYNCBUSY.bit.SWTRIG) {}
-    while (!ADC0->INTFLAG.bit.RESRDY) {}
+    while (ADC0->SYNCBUSY.bit.SWTRIG) {
+    }
+    while (!ADC0->INTFLAG.bit.RESRDY) {
+    }
 
     return ADC0->RESULT.reg;
 }
-
index 5a90ece3fe3e9cc2c41e80b27046cce4cb45c269..9ab653e5a206fe343182d5221842793aca3a362f 100644 (file)
@@ -18,11 +18,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef _ADC_H_
 #define _ADC_H_
 
-#define ADC_5V_START_LEVEL              2365
+#define ADC_5V_START_LEVEL 2365
 
-#define ADC_5V     ADC_INPUTCTRL_MUXPOS_AIN12_Val
-#define ADC_CON1   ADC_INPUTCTRL_MUXPOS_AIN14_Val
-#define ADC_CON2   ADC_INPUTCTRL_MUXPOS_AIN13_Val
+#define ADC_5V ADC_INPUTCTRL_MUXPOS_AIN12_Val
+#define ADC_CON1 ADC_INPUTCTRL_MUXPOS_AIN14_Val
+#define ADC_CON2 ADC_INPUTCTRL_MUXPOS_AIN13_Val
 
 extern uint16_t v_5v;
 extern uint16_t v_5v_avg;
@@ -34,4 +34,4 @@ extern uint16_t v_con_2_boot;
 void ADC0_clock_init(void);
 void ADC0_init(void);
 
-#endif //_ADC_H_
+#endif  //_ADC_H_
index 88109186aad9dd73631fb427886500163dffebac..8cb00b872ae96ac01f9c42a61fe247c2546c90d6 100644 (file)
@@ -33,17 +33,16 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #ifndef MD_BOOTLOADER
 
-#include "main_arm_atsam.h"
-#ifdef RGB_MATRIX_ENABLE
-#include "led_matrix.h"
-#include "rgb_matrix.h"
-#endif
-#include "issi3733_driver.h"
-#include "./usb/compiler.h"
-#include "./usb/udc.h"
-#include "./usb/udi_cdc.h"
-
-#endif //MD_BOOTLOADER
-
-#endif //_ARM_ATSAM_PROTOCOL_H_
-
+#    include "main_arm_atsam.h"
+#    ifdef RGB_MATRIX_ENABLE
+#        include "led_matrix.h"
+#        include "rgb_matrix.h"
+#    endif
+#    include "issi3733_driver.h"
+#    include "./usb/compiler.h"
+#    include "./usb/udc.h"
+#    include "./usb/udi_cdc.h"
+
+#endif  // MD_BOOTLOADER
+
+#endif  //_ARM_ATSAM_PROTOCOL_H_
index 1ff318e59b3530a5fbbd6af2ca5ea7cb14008550..84ed6d83af5784a42636fa9051042d754e56a106 100644 (file)
@@ -19,83 +19,105 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <string.h>
 
-volatile clk_t system_clks;
+volatile clk_t    system_clks;
 volatile uint64_t ms_clk;
-uint32_t usec_delay_mult;
-#define USEC_DELAY_LOOP_CYCLES 3 //Sum of instruction cycles in us delay loop
+uint32_t          usec_delay_mult;
+#define USEC_DELAY_LOOP_CYCLES 3  // Sum of instruction cycles in us delay loop
 
-const uint32_t sercom_apbbase[] = {(uint32_t)SERCOM0,(uint32_t)SERCOM1,(uint32_t)SERCOM2,(uint32_t)SERCOM3,(uint32_t)SERCOM4,(uint32_t)SERCOM5};
-const uint8_t sercom_pchan[] = {7, 8, 23, 24, 34, 35};
+const uint32_t sercom_apbbase[] = {(uint32_t)SERCOM0, (uint32_t)SERCOM1, (uint32_t)SERCOM2, (uint32_t)SERCOM3, (uint32_t)SERCOM4, (uint32_t)SERCOM5};
+const uint8_t  sercom_pchan[]   = {7, 8, 23, 24, 34, 35};
 
-#define USE_DPLL_IND    0
-#define USE_DPLL_DEF    GCLK_SOURCE_DPLL0
+#define USE_DPLL_IND 0
+#define USE_DPLL_DEF GCLK_SOURCE_DPLL0
 
-void CLK_oscctrl_init(void)
-{
+void CLK_oscctrl_init(void) {
     Oscctrl *posctrl = OSCCTRL;
-    Gclk *pgclk = GCLK;
+    Gclk *   pgclk   = GCLK;
 
     DBGC(DC_CLK_OSC_INIT_BEGIN);
 
-    //default setup on por
-    system_clks.freq_dfll = FREQ_DFLL_DEFAULT;
+    // default setup on por
+    system_clks.freq_dfll    = FREQ_DFLL_DEFAULT;
     system_clks.freq_gclk[0] = system_clks.freq_dfll;
 
-    //configure and startup 16MHz xosc0
-    posctrl->XOSCCTRL[0].bit.ENABLE = 0;
-    posctrl->XOSCCTRL[0].bit.STARTUP = 0xD;
-    posctrl->XOSCCTRL[0].bit.ENALC = 1;
-    posctrl->XOSCCTRL[0].bit.IMULT = 5;
-    posctrl->XOSCCTRL[0].bit.IPTAT = 3;
+    // configure and startup 16MHz xosc0
+    posctrl->XOSCCTRL[0].bit.ENABLE   = 0;
+    posctrl->XOSCCTRL[0].bit.STARTUP  = 0xD;
+    posctrl->XOSCCTRL[0].bit.ENALC    = 1;
+    posctrl->XOSCCTRL[0].bit.IMULT    = 5;
+    posctrl->XOSCCTRL[0].bit.IPTAT    = 3;
     posctrl->XOSCCTRL[0].bit.ONDEMAND = 0;
-    posctrl->XOSCCTRL[0].bit.XTALEN = 1;
-    posctrl->XOSCCTRL[0].bit.ENABLE = 1;
-    while (posctrl->STATUS.bit.XOSCRDY0 == 0) { DBGC(DC_CLK_OSC_INIT_XOSC0_SYNC); }
+    posctrl->XOSCCTRL[0].bit.XTALEN   = 1;
+    posctrl->XOSCCTRL[0].bit.ENABLE   = 1;
+    while (posctrl->STATUS.bit.XOSCRDY0 == 0) {
+        DBGC(DC_CLK_OSC_INIT_XOSC0_SYNC);
+    }
     system_clks.freq_xosc0 = FREQ_XOSC0;
 
-    //configure and startup DPLL
+    // configure and startup DPLL
     posctrl->Dpll[USE_DPLL_IND].DPLLCTRLA.bit.ENABLE = 0;
-    while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.ENABLE) { DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_DISABLE); }
-    posctrl->Dpll[USE_DPLL_IND].DPLLCTRLB.bit.REFCLK = 2;              //select XOSC0 (16MHz)
-    posctrl->Dpll[USE_DPLL_IND].DPLLCTRLB.bit.DIV = 7;                 //16 MHz / (2 * (7 + 1)) = 1 MHz
-    posctrl->Dpll[USE_DPLL_IND].DPLLRATIO.bit.LDR = PLL_RATIO;         //1 MHz * (PLL_RATIO(47) + 1) = 48MHz
-    while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.DPLLRATIO) { DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_RATIO); }
+    while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.ENABLE) {
+        DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_DISABLE);
+    }
+    posctrl->Dpll[USE_DPLL_IND].DPLLCTRLB.bit.REFCLK = 2;          // select XOSC0 (16MHz)
+    posctrl->Dpll[USE_DPLL_IND].DPLLCTRLB.bit.DIV    = 7;          // 16 MHz / (2 * (7 + 1)) = 1 MHz
+    posctrl->Dpll[USE_DPLL_IND].DPLLRATIO.bit.LDR    = PLL_RATIO;  // 1 MHz * (PLL_RATIO(47) + 1) = 48MHz
+    while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.DPLLRATIO) {
+        DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_RATIO);
+    }
     posctrl->Dpll[USE_DPLL_IND].DPLLCTRLA.bit.ONDEMAND = 0;
-    posctrl->Dpll[USE_DPLL_IND].DPLLCTRLA.bit.ENABLE = 1;
-    while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.ENABLE) { DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_ENABLE); }
-    while (posctrl->Dpll[USE_DPLL_IND].DPLLSTATUS.bit.LOCK == 0) { DBGC(DC_CLK_OSC_INIT_DPLL_WAIT_LOCK); }
-    while (posctrl->Dpll[USE_DPLL_IND].DPLLSTATUS.bit.CLKRDY == 0) { DBGC(DC_CLK_OSC_INIT_DPLL_WAIT_CLKRDY); }
+    posctrl->Dpll[USE_DPLL_IND].DPLLCTRLA.bit.ENABLE   = 1;
+    while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.ENABLE) {
+        DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_ENABLE);
+    }
+    while (posctrl->Dpll[USE_DPLL_IND].DPLLSTATUS.bit.LOCK == 0) {
+        DBGC(DC_CLK_OSC_INIT_DPLL_WAIT_LOCK);
+    }
+    while (posctrl->Dpll[USE_DPLL_IND].DPLLSTATUS.bit.CLKRDY == 0) {
+        DBGC(DC_CLK_OSC_INIT_DPLL_WAIT_CLKRDY);
+    }
     system_clks.freq_dpll[0] = (system_clks.freq_xosc0 / 2 / (posctrl->Dpll[USE_DPLL_IND].DPLLCTRLB.bit.DIV + 1)) * (posctrl->Dpll[USE_DPLL_IND].DPLLRATIO.bit.LDR + 1);
 
-    //change gclk0 to DPLL
+    // change gclk0 to DPLL
     pgclk->GENCTRL[GEN_DPLL0].bit.SRC = USE_DPLL_DEF;
-    while (pgclk->SYNCBUSY.bit.GENCTRL0) { DBGC(DC_CLK_OSC_INIT_GCLK_SYNC_GENCTRL0); }
+    while (pgclk->SYNCBUSY.bit.GENCTRL0) {
+        DBGC(DC_CLK_OSC_INIT_GCLK_SYNC_GENCTRL0);
+    }
 
     system_clks.freq_gclk[0] = system_clks.freq_dpll[0];
 
     usec_delay_mult = system_clks.freq_gclk[0] / (USEC_DELAY_LOOP_CYCLES * 1000000);
-    if (usec_delay_mult < 1) usec_delay_mult = 1; //Never allow a multiplier of zero
+    if (usec_delay_mult < 1) usec_delay_mult = 1;  // Never allow a multiplier of zero
 
     DBGC(DC_CLK_OSC_INIT_COMPLETE);
 }
 
-//configure for 1MHz (1 usec timebase)
-//call CLK_set_gclk_freq(GEN_TC45, FREQ_TC45_DEFAULT);
-uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq)
-{
+// configure for 1MHz (1 usec timebase)
+// call CLK_set_gclk_freq(GEN_TC45, FREQ_TC45_DEFAULT);
+uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq) {
     Gclk *pgclk = GCLK;
 
     DBGC(DC_CLK_SET_GCLK_FREQ_BEGIN);
 
-    while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_1); }
+    while (pgclk->SYNCBUSY.vec.GENCTRL) {
+        DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_1);
+    }
     pgclk->GENCTRL[gclkn].bit.SRC = USE_DPLL_DEF;
-    while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_2); }
+    while (pgclk->SYNCBUSY.vec.GENCTRL) {
+        DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_2);
+    }
     pgclk->GENCTRL[gclkn].bit.DIV = (uint8_t)(system_clks.freq_dpll[0] / freq);
-    while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_3); }
+    while (pgclk->SYNCBUSY.vec.GENCTRL) {
+        DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_3);
+    }
     pgclk->GENCTRL[gclkn].bit.DIVSEL = 0;
-    while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_4); }
+    while (pgclk->SYNCBUSY.vec.GENCTRL) {
+        DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_4);
+    }
     pgclk->GENCTRL[gclkn].bit.GENEN = 1;
-    while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_5); }
+    while (pgclk->SYNCBUSY.vec.GENCTRL) {
+        DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_5);
+    }
     system_clks.freq_gclk[gclkn] = system_clks.freq_dpll[0] / pgclk->GENCTRL[gclkn].bit.DIV;
 
     DBGC(DC_CLK_SET_GCLK_FREQ_COMPLETE);
@@ -103,29 +125,37 @@ uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq)
     return system_clks.freq_gclk[gclkn];
 }
 
-void CLK_init_osc(void)
-{
+void CLK_init_osc(void) {
     uint8_t gclkn = GEN_OSC0;
-    Gclk *pgclk = GCLK;
+    Gclk *  pgclk = GCLK;
 
     DBGC(DC_CLK_INIT_OSC_BEGIN);
 
-    while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_INIT_OSC_SYNC_1); }
+    while (pgclk->SYNCBUSY.vec.GENCTRL) {
+        DBGC(DC_CLK_INIT_OSC_SYNC_1);
+    }
     pgclk->GENCTRL[gclkn].bit.SRC = GCLK_SOURCE_XOSC0;
-    while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_INIT_OSC_SYNC_2); }
+    while (pgclk->SYNCBUSY.vec.GENCTRL) {
+        DBGC(DC_CLK_INIT_OSC_SYNC_2);
+    }
     pgclk->GENCTRL[gclkn].bit.DIV = 1;
-    while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_INIT_OSC_SYNC_3); }
+    while (pgclk->SYNCBUSY.vec.GENCTRL) {
+        DBGC(DC_CLK_INIT_OSC_SYNC_3);
+    }
     pgclk->GENCTRL[gclkn].bit.DIVSEL = 0;
-    while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_INIT_OSC_SYNC_4); }
+    while (pgclk->SYNCBUSY.vec.GENCTRL) {
+        DBGC(DC_CLK_INIT_OSC_SYNC_4);
+    }
     pgclk->GENCTRL[gclkn].bit.GENEN = 1;
-    while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_INIT_OSC_SYNC_5); }
+    while (pgclk->SYNCBUSY.vec.GENCTRL) {
+        DBGC(DC_CLK_INIT_OSC_SYNC_5);
+    }
     system_clks.freq_gclk[gclkn] = system_clks.freq_xosc0;
 
     DBGC(DC_CLK_INIT_OSC_COMPLETE);
 }
 
-void CLK_reset_time(void)
-{
+void CLK_reset_time(void) {
     Tc *ptc4 = TC4;
     Tc *ptc0 = TC0;
 
@@ -133,72 +163,85 @@ void CLK_reset_time(void)
 
     DBGC(DC_CLK_RESET_TIME_BEGIN);
 
-    //stop counters
+    // stop counters
     ptc4->COUNT16.CTRLA.bit.ENABLE = 0;
-    while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) {}
+    while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) {
+    }
     ptc0->COUNT32.CTRLA.bit.ENABLE = 0;
-    while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) {}
-    //zero counters
+    while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) {
+    }
+    // zero counters
     ptc4->COUNT16.COUNT.reg = 0;
-    while (ptc4->COUNT16.SYNCBUSY.bit.COUNT) {}
+    while (ptc4->COUNT16.SYNCBUSY.bit.COUNT) {
+    }
     ptc0->COUNT32.COUNT.reg = 0;
-    while (ptc0->COUNT32.SYNCBUSY.bit.COUNT) {}
-    //start counters
+    while (ptc0->COUNT32.SYNCBUSY.bit.COUNT) {
+    }
+    // start counters
     ptc0->COUNT32.CTRLA.bit.ENABLE = 1;
-    while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) {}
+    while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) {
+    }
     ptc4->COUNT16.CTRLA.bit.ENABLE = 1;
-    while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) {}
+    while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) {
+    }
 
     DBGC(DC_CLK_RESET_TIME_COMPLETE);
 }
 
-void TC4_Handler()
-{
-    if (TC4->COUNT16.INTFLAG.bit.MC0)
-    {
+void TC4_Handler() {
+    if (TC4->COUNT16.INTFLAG.bit.MC0) {
         TC4->COUNT16.INTFLAG.reg = TC_INTENCLR_MC0;
         ms_clk++;
     }
 }
 
-uint32_t CLK_enable_timebase(void)
-{
-    Gclk *pgclk = GCLK;
-    Mclk *pmclk = MCLK;
-    Tc *ptc4 = TC4;
-    Tc *ptc0 = TC0;
+uint32_t CLK_enable_timebase(void) {
+    Gclk * pgclk  = GCLK;
+    Mclk * pmclk  = MCLK;
+    Tc *   ptc4   = TC4;
+    Tc *   ptc0   = TC0;
     Evsys *pevsys = EVSYS;
 
     DBGC(DC_CLK_ENABLE_TIMEBASE_BEGIN);
 
-    //gclk2  highspeed time base
+    // gclk2  highspeed time base
     CLK_set_gclk_freq(GEN_TC45, FREQ_TC45_DEFAULT);
     CLK_init_osc();
 
-    //unmask TC4, sourcegclk2 to TC4
-    pmclk->APBCMASK.bit.TC4_ = 1;
-    pgclk->PCHCTRL[TC4_GCLK_ID].bit.GEN = GEN_TC45;
+    // unmask TC4, sourcegclk2 to TC4
+    pmclk->APBCMASK.bit.TC4_             = 1;
+    pgclk->PCHCTRL[TC4_GCLK_ID].bit.GEN  = GEN_TC45;
     pgclk->PCHCTRL[TC4_GCLK_ID].bit.CHEN = 1;
 
-    //configure TC4
+    // configure TC4
     DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_BEGIN);
     ptc4->COUNT16.CTRLA.bit.ENABLE = 0;
-    while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_DISABLE); }
+    while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) {
+        DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_DISABLE);
+    }
     ptc4->COUNT16.CTRLA.bit.SWRST = 1;
-    while (ptc4->COUNT16.SYNCBUSY.bit.SWRST) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_SWRST_1); }
-    while (ptc4->COUNT16.CTRLA.bit.SWRST) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_SWRST_2); }
+    while (ptc4->COUNT16.SYNCBUSY.bit.SWRST) {
+        DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_SWRST_1);
+    }
+    while (ptc4->COUNT16.CTRLA.bit.SWRST) {
+        DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_SWRST_2);
+    }
 
-    //CTRLA defaults
-    //CTRLB as default, counting up
+    // CTRLA defaults
+    // CTRLB as default, counting up
     ptc4->COUNT16.CTRLBCLR.reg = 5;
-    while (ptc4->COUNT16.SYNCBUSY.bit.CTRLB) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_CLTRB); }
+    while (ptc4->COUNT16.SYNCBUSY.bit.CTRLB) {
+        DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_CLTRB);
+    }
     ptc4->COUNT16.CC[0].reg = 999;
-    while (ptc4->COUNT16.SYNCBUSY.bit.CC0) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_CC0); }
-    //ptc4->COUNT16.DBGCTRL.bit.DBGRUN = 1;
+    while (ptc4->COUNT16.SYNCBUSY.bit.CC0) {
+        DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_CC0);
+    }
+    // ptc4->COUNT16.DBGCTRL.bit.DBGRUN = 1;
 
-    //wave mode
-    ptc4->COUNT16.WAVE.bit.WAVEGEN = 1; //MFRQ match frequency mode, toggle each CC match
-    //generate event for next stage
+    // wave mode
+    ptc4->COUNT16.WAVE.bit.WAVEGEN = 1;  // MFRQ match frequency mode, toggle each CC match
+    // generate event for next stage
     ptc4->COUNT16.EVCTRL.bit.MCEO0 = 1;
 
     NVIC_EnableIRQ(TC4_IRQn);
@@ -206,39 +249,45 @@ uint32_t CLK_enable_timebase(void)
 
     DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_COMPLETE);
 
-    //unmask TC0,1, sourcegclk2 to TC0,1
-    pmclk->APBAMASK.bit.TC0_ = 1;
-    pgclk->PCHCTRL[TC0_GCLK_ID].bit.GEN = GEN_TC45;
+    // unmask TC0,1, sourcegclk2 to TC0,1
+    pmclk->APBAMASK.bit.TC0_             = 1;
+    pgclk->PCHCTRL[TC0_GCLK_ID].bit.GEN  = GEN_TC45;
     pgclk->PCHCTRL[TC0_GCLK_ID].bit.CHEN = 1;
 
-    pmclk->APBAMASK.bit.TC1_ = 1;
-    pgclk->PCHCTRL[TC1_GCLK_ID].bit.GEN = GEN_TC45;
+    pmclk->APBAMASK.bit.TC1_             = 1;
+    pgclk->PCHCTRL[TC1_GCLK_ID].bit.GEN  = GEN_TC45;
     pgclk->PCHCTRL[TC1_GCLK_ID].bit.CHEN = 1;
 
-    //configure TC0
+    // configure TC0
     DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_BEGIN);
     ptc0->COUNT32.CTRLA.bit.ENABLE = 0;
-    while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_DISABLE); }
+    while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) {
+        DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_DISABLE);
+    }
     ptc0->COUNT32.CTRLA.bit.SWRST = 1;
-    while (ptc0->COUNT32.SYNCBUSY.bit.SWRST) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_SWRST_1); }
-    while (ptc0->COUNT32.CTRLA.bit.SWRST) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_SWRST_2); }
-    //CTRLA as default
-    ptc0->COUNT32.CTRLA.bit.MODE = 2; //32 bit mode
-    ptc0->COUNT32.EVCTRL.bit.TCEI = 1; //enable incoming events
-    ptc0->COUNT32.EVCTRL.bit.EVACT = 2 ; //count events
+    while (ptc0->COUNT32.SYNCBUSY.bit.SWRST) {
+        DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_SWRST_1);
+    }
+    while (ptc0->COUNT32.CTRLA.bit.SWRST) {
+        DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_SWRST_2);
+    }
+    // CTRLA as default
+    ptc0->COUNT32.CTRLA.bit.MODE   = 2;  // 32 bit mode
+    ptc0->COUNT32.EVCTRL.bit.TCEI  = 1;  // enable incoming events
+    ptc0->COUNT32.EVCTRL.bit.EVACT = 2;  // count events
 
     DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_COMPLETE);
 
     DBGC(DC_CLK_ENABLE_TIMEBASE_EVSYS_BEGIN);
 
-    //configure event system
-    pmclk->APBBMASK.bit.EVSYS_ = 1;
-    pgclk->PCHCTRL[EVSYS_GCLK_ID_0].bit.GEN = GEN_TC45;
+    // configure event system
+    pmclk->APBBMASK.bit.EVSYS_               = 1;
+    pgclk->PCHCTRL[EVSYS_GCLK_ID_0].bit.GEN  = GEN_TC45;
     pgclk->PCHCTRL[EVSYS_GCLK_ID_0].bit.CHEN = 1;
-    pevsys->USER[44].reg = EVSYS_ID_USER_PORT_EV_0;                               //TC0 will get event channel 0
-    pevsys->Channel[0].CHANNEL.bit.EDGSEL = EVSYS_CHANNEL_EDGSEL_RISING_EDGE_Val; //Rising edge
-    pevsys->Channel[0].CHANNEL.bit.PATH = EVSYS_CHANNEL_PATH_SYNCHRONOUS_Val;     //Synchronous
-    pevsys->Channel[0].CHANNEL.bit.EVGEN = EVSYS_ID_GEN_TC4_MCX_0;                //TC4 MC0
+    pevsys->USER[44].reg                     = EVSYS_ID_USER_PORT_EV_0;               // TC0 will get event channel 0
+    pevsys->Channel[0].CHANNEL.bit.EDGSEL    = EVSYS_CHANNEL_EDGSEL_RISING_EDGE_Val;  // Rising edge
+    pevsys->Channel[0].CHANNEL.bit.PATH      = EVSYS_CHANNEL_PATH_SYNCHRONOUS_Val;    // Synchronous
+    pevsys->Channel[0].CHANNEL.bit.EVGEN     = EVSYS_ID_GEN_TC4_MCX_0;                // TC4 MC0
 
     DBGC(DC_CLK_ENABLE_TIMEBASE_EVSYS_COMPLETE);
 
@@ -251,34 +300,29 @@ uint32_t CLK_enable_timebase(void)
     return 0;
 }
 
-void CLK_delay_us(uint32_t usec)
-{
-    asm (
-        "CBZ R0, return\n\t"        //If usec == 0, branch to return label
+void CLK_delay_us(uint32_t usec) {
+    asm("CBZ R0, return\n\t"  // If usec == 0, branch to return label
     );
-    asm (
-        "MULS R0, %0\n\t"           //Multiply R0(usec) by usec_delay_mult and store in R0
-        ".balign 16\n\t"            //Ensure loop is aligned for fastest performance
-        "loop: SUBS R0, #1\n\t"     //Subtract 1 from R0 and update flags (1 cycle)
-        "BNE loop\n\t"              //Branch if non-zero to loop label (2 cycles)  NOTE: USEC_DELAY_LOOP_CYCLES is the sum of loop cycles
-        "return:\n\t"               //Return label
-        : //No output registers
-        : "r" (usec_delay_mult)     //For %0
+    asm("MULS R0, %0\n\t"        // Multiply R0(usec) by usec_delay_mult and store in R0
+        ".balign 16\n\t"         // Ensure loop is aligned for fastest performance
+        "loop: SUBS R0, #1\n\t"  // Subtract 1 from R0 and update flags (1 cycle)
+        "BNE loop\n\t"           // Branch if non-zero to loop label (2 cycles)  NOTE: USEC_DELAY_LOOP_CYCLES is the sum of loop cycles
+        "return:\n\t"            // Return label
+        :                        // No output registers
+        : "r"(usec_delay_mult)   // For %0
     );
-    //Note: BX LR generated
+    // Note: BX LR generated
 }
 
-void CLK_delay_ms(uint64_t msec)
-{
+void CLK_delay_ms(uint64_t msec) {
     msec += timer_read64();
-    while (msec > timer_read64()) {}
+    while (msec > timer_read64()) {
+    }
 }
 
-void clk_enable_sercom_apbmask(int sercomn)
-{
+void clk_enable_sercom_apbmask(int sercomn) {
     Mclk *pmclk = MCLK;
-    switch (sercomn)
-    {
+    switch (sercomn) {
         case 0:
             pmclk->APBAMASK.bit.SERCOM0_ = 1;
             break;
@@ -296,26 +340,27 @@ void clk_enable_sercom_apbmask(int sercomn)
     }
 }
 
-//call CLK_oscctrl_init first
-//call CLK_set_spi_freq(CHAN_SERCOM_SPI, FREQ_SPI_DEFAULT);
-uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq)
-{
+// call CLK_oscctrl_init first
+// call CLK_set_spi_freq(CHAN_SERCOM_SPI, FREQ_SPI_DEFAULT);
+uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq) {
     DBGC(DC_CLK_SET_SPI_FREQ_BEGIN);
 
-    Gclk *pgclk = GCLK;
+    Gclk *  pgclk   = GCLK;
     Sercom *psercom = (Sercom *)sercom_apbbase[sercomn];
     clk_enable_sercom_apbmask(sercomn);
 
-    //all gclk0 for now
-    pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN = 0;
+    // all gclk0 for now
+    pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN  = 0;
     pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.CHEN = 1;
 
     psercom->I2CM.CTRLA.bit.SWRST = 1;
-    while (psercom->I2CM.SYNCBUSY.bit.SWRST) {}
-    while (psercom->I2CM.CTRLA.bit.SWRST) {}
+    while (psercom->I2CM.SYNCBUSY.bit.SWRST) {
+    }
+    while (psercom->I2CM.CTRLA.bit.SWRST) {
+    }
 
-    psercom->SPI.BAUD.reg = (uint8_t) (system_clks.freq_gclk[0]/2/freq-1);
-    system_clks.freq_spi = system_clks.freq_gclk[0]/2/(psercom->SPI.BAUD.reg+1);
+    psercom->SPI.BAUD.reg            = (uint8_t)(system_clks.freq_gclk[0] / 2 / freq - 1);
+    system_clks.freq_spi             = system_clks.freq_gclk[0] / 2 / (psercom->SPI.BAUD.reg + 1);
     system_clks.freq_sercom[sercomn] = system_clks.freq_spi;
 
     DBGC(DC_CLK_SET_SPI_FREQ_COMPLETE);
@@ -323,26 +368,27 @@ uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq)
     return system_clks.freq_spi;
 }
 
-//call CLK_oscctrl_init first
-//call CLK_set_i2c0_freq(CHAN_SERCOM_I2C0, FREQ_I2C0_DEFAULT);
-uint32_t CLK_set_i2c0_freq(uint8_t sercomn, uint32_t freq)
-{
+// call CLK_oscctrl_init first
+// call CLK_set_i2c0_freq(CHAN_SERCOM_I2C0, FREQ_I2C0_DEFAULT);
+uint32_t CLK_set_i2c0_freq(uint8_t sercomn, uint32_t freq) {
     DBGC(DC_CLK_SET_I2C0_FREQ_BEGIN);
 
-    Gclk *pgclk = GCLK;
+    Gclk *  pgclk   = GCLK;
     Sercom *psercom = (Sercom *)sercom_apbbase[sercomn];
     clk_enable_sercom_apbmask(sercomn);
 
-    //all gclk0 for now
-    pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN = 0;
+    // all gclk0 for now
+    pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN  = 0;
     pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.CHEN = 1;
 
     psercom->I2CM.CTRLA.bit.SWRST = 1;
-    while (psercom->I2CM.SYNCBUSY.bit.SWRST) {}
-    while (psercom->I2CM.CTRLA.bit.SWRST) {}
+    while (psercom->I2CM.SYNCBUSY.bit.SWRST) {
+    }
+    while (psercom->I2CM.CTRLA.bit.SWRST) {
+    }
 
-    psercom->I2CM.BAUD.bit.BAUD = (uint8_t) (system_clks.freq_gclk[0]/2/freq-1);
-    system_clks.freq_i2c0 = system_clks.freq_gclk[0]/2/(psercom->I2CM.BAUD.bit.BAUD+1);
+    psercom->I2CM.BAUD.bit.BAUD      = (uint8_t)(system_clks.freq_gclk[0] / 2 / freq - 1);
+    system_clks.freq_i2c0            = system_clks.freq_gclk[0] / 2 / (psercom->I2CM.BAUD.bit.BAUD + 1);
     system_clks.freq_sercom[sercomn] = system_clks.freq_i2c0;
 
     DBGC(DC_CLK_SET_I2C0_FREQ_COMPLETE);
@@ -350,26 +396,27 @@ uint32_t CLK_set_i2c0_freq(uint8_t sercomn, uint32_t freq)
     return system_clks.freq_i2c0;
 }
 
-//call CLK_oscctrl_init first
-//call CLK_set_i2c1_freq(CHAN_SERCOM_I2C1, FREQ_I2C1_DEFAULT);
-uint32_t CLK_set_i2c1_freq(uint8_t sercomn, uint32_t freq)
-{
+// call CLK_oscctrl_init first
+// call CLK_set_i2c1_freq(CHAN_SERCOM_I2C1, FREQ_I2C1_DEFAULT);
+uint32_t CLK_set_i2c1_freq(uint8_t sercomn, uint32_t freq) {
     DBGC(DC_CLK_SET_I2C1_FREQ_BEGIN);
 
-    Gclk *pgclk = GCLK;
+    Gclk *  pgclk   = GCLK;
     Sercom *psercom = (Sercom *)sercom_apbbase[sercomn];
     clk_enable_sercom_apbmask(sercomn);
 
-    //all gclk0 for now
-    pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN = 0;
+    // all gclk0 for now
+    pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN  = 0;
     pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.CHEN = 1;
 
     psercom->I2CM.CTRLA.bit.SWRST = 1;
-    while (psercom->I2CM.SYNCBUSY.bit.SWRST) {}
-    while (psercom->I2CM.CTRLA.bit.SWRST) {}
+    while (psercom->I2CM.SYNCBUSY.bit.SWRST) {
+    }
+    while (psercom->I2CM.CTRLA.bit.SWRST) {
+    }
 
-    psercom->I2CM.BAUD.bit.BAUD = (uint8_t) (system_clks.freq_gclk[0]/2/freq-10);
-    system_clks.freq_i2c1 = system_clks.freq_gclk[0]/2/(psercom->I2CM.BAUD.bit.BAUD+10);
+    psercom->I2CM.BAUD.bit.BAUD      = (uint8_t)(system_clks.freq_gclk[0] / 2 / freq - 10);
+    system_clks.freq_i2c1            = system_clks.freq_gclk[0] / 2 / (psercom->I2CM.BAUD.bit.BAUD + 10);
     system_clks.freq_sercom[sercomn] = system_clks.freq_i2c1;
 
     DBGC(DC_CLK_SET_I2C1_FREQ_COMPLETE);
@@ -377,15 +424,13 @@ uint32_t CLK_set_i2c1_freq(uint8_t sercomn, uint32_t freq)
     return system_clks.freq_i2c1;
 }
 
-void CLK_init(void)
-{
+void CLK_init(void) {
     DBGC(DC_CLK_INIT_BEGIN);
 
-    memset((void *)&system_clks,0,sizeof(system_clks));
+    memset((void *)&system_clks, 0, sizeof(system_clks));
 
     CLK_oscctrl_init();
     CLK_enable_timebase();
 
     DBGC(DC_CLK_INIT_COMPLETE);
 }
-
index 1b01a1764ef81d34e2a5ae09aa40f92e118568ee..72df3a8e3f3f898f08f8b96e77175cfd1013a87f 100644 (file)
@@ -20,20 +20,20 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #ifndef MD_BOOTLOADER
 
-//From keyboard
-#include "config_led.h"
-#include "config.h"
+// From keyboard
+#    include "config_led.h"
+#    include "config.h"
 
-#endif //MD_BOOTLOADER
+#endif  // MD_BOOTLOADER
 
-#define PLL_RATIO                   47  //mcu frequency ((X+1)MHz)
-#define FREQ_DFLL_DEFAULT     48000000  //DFLL frequency / usb clock
-#define FREQ_SPI_DEFAULT       1000000  //spi to 595 shift regs
-#define FREQ_I2C0_DEFAULT       100000  //i2c to hub
-#define FREQ_I2C1_DEFAULT       I2C_HZ  //i2c to LED drivers
-#define FREQ_TC45_DEFAULT      1000000  //1 usec resolution
+#define PLL_RATIO 47                // mcu frequency ((X+1)MHz)
+#define FREQ_DFLL_DEFAULT 48000000  // DFLL frequency / usb clock
+#define FREQ_SPI_DEFAULT 1000000    // spi to 595 shift regs
+#define FREQ_I2C0_DEFAULT 100000    // i2c to hub
+#define FREQ_I2C1_DEFAULT I2C_HZ    // i2c to LED drivers
+#define FREQ_TC45_DEFAULT 1000000   // 1 usec resolution
 
-//I2C1 Set      ~Result     PWM Time (2x Drivers)
+// I2C1 Set      ~Result     PWM Time (2x Drivers)
 //     1000000  1090000
 //     900000   1000000     3.82ms
 //     800000   860000
@@ -42,20 +42,20 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //     580000   615000      6.08ms
 //     500000   522000
 
-#define FREQ_XOSC0            16000000
+#define FREQ_XOSC0 16000000
 
-#define CHAN_SERCOM_SPI   2 //shift regs
-#define CHAN_SERCOM_I2C0  0 //hub
-#define CHAN_SERCOM_I2C1  1 //led drivers
-#define CHAN_SERCOM_UART  3 //debug util
+#define CHAN_SERCOM_SPI 2   // shift regs
+#define CHAN_SERCOM_I2C0 0  // hub
+#define CHAN_SERCOM_I2C1 1  // led drivers
+#define CHAN_SERCOM_UART 3  // debug util
 
-//Generator clock channels
-#define GEN_DPLL0   0
-#define GEN_OSC0    1
-#define GEN_TC45    2
+// Generator clock channels
+#define GEN_DPLL0 0
+#define GEN_OSC0 1
+#define GEN_TC45 2
 
 #define SERCOM_COUNT 5
-#define GCLK_COUNT  12
+#define GCLK_COUNT 12
 
 typedef struct clk_s {
     uint32_t freq_dfll;
@@ -70,20 +70,20 @@ typedef struct clk_s {
     uint32_t freq_adc0;
 } clk_t;
 
-extern volatile clk_t system_clks;
+extern volatile clk_t    system_clks;
 extern volatile uint64_t ms_clk;
 
-void CLK_oscctrl_init(void);
-void CLK_reset_time(void);
+void     CLK_oscctrl_init(void);
+void     CLK_reset_time(void);
 uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq);
 uint32_t CLK_enable_timebase(void);
 uint64_t timer_read64(void);
-void CLK_delay_us(uint32_t usec);
-void CLK_delay_ms(uint64_t msec);
+void     CLK_delay_us(uint32_t usec);
+void     CLK_delay_ms(uint64_t msec);
 
 uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq);
 uint32_t CLK_set_i2c0_freq(uint8_t sercomn, uint32_t freq);
 uint32_t CLK_set_i2c1_freq(uint8_t sercomn, uint32_t freq);
-void CLK_init(void);
+void     CLK_init(void);
 
-#endif // _CLKS_H_
+#endif  // _CLKS_H_
index ea422585757fdbc4aa7041b721d0e7b6cf96b9bc..df596f7ba242b2d29b36e9f56555f8679d8e789b 100644 (file)
@@ -1,46 +1,50 @@
 #include "d51_util.h"
 
 static volatile uint32_t w;
-    
-//Display unsigned 32-bit number by port toggling DBG_1 (to view on a scope)
-//Read as follows: 1230 = |    | |    | | |    ||  (note zero is fast double toggle)
+
+// Display unsigned 32-bit number by port toggling DBG_1 (to view on a scope)
+// Read as follows: 1230 = |    | |    | | |    ||  (note zero is fast double toggle)
 #define DBG_PAUSE 5
-void dbg_print(uint32_t x)
-{
-    int8_t t;
+void dbg_print(uint32_t x) {
+    int8_t   t;
     uint32_t n;
     uint32_t p, p2;
 
-    if      (x < 10) t = 0;
-    else if (x < 100) t = 1;
-    else if (x < 1000) t = 2;
-    else if (x < 10000) t = 3;
-    else if (x < 100000) t = 4;
-    else if (x < 1000000) t = 5;
-    else if (x < 10000000) t = 6;
-    else if (x < 100000000) t = 7;
-    else if (x < 1000000000) t = 8;
-    else t = 9;
-
-    while (t >= 0)
-    {
+    if (x < 10)
+        t = 0;
+    else if (x < 100)
+        t = 1;
+    else if (x < 1000)
+        t = 2;
+    else if (x < 10000)
+        t = 3;
+    else if (x < 100000)
+        t = 4;
+    else if (x < 1000000)
+        t = 5;
+    else if (x < 10000000)
+        t = 6;
+    else if (x < 100000000)
+        t = 7;
+    else if (x < 1000000000)
+        t = 8;
+    else
+        t = 9;
+
+    while (t >= 0) {
         p2 = t;
-        p = 1;
+        p  = 1;
         while (p2--) p *= 10;
         n = x / p;
         x -= n * p;
-        if (!n)
-        {
+        if (!n) {
             DBG_1_ON;
             DBG_1_OFF;
             DBG_1_ON;
             DBG_1_OFF;
             n--;
-        }
-        else
-        {
-            while (n > 0)
-            {
+        } else {
+            while (n > 0) {
                 DBG_1_ON;
                 DBG_1_OFF;
                 n--;
@@ -50,68 +54,80 @@ void dbg_print(uint32_t x)
         t--;
     }
 
-    for (w = DBG_PAUSE; w; w--); //Long pause after number is complete
+    for (w = DBG_PAUSE; w; w--)
+        ;  // Long pause after number is complete
 }
 
-//Display unsigned 32-bit number through debug led
-//Read as follows: 1230 = [*]  [* *]  [* * *]  [**]  (note zero is fast double flash)
+// Display unsigned 32-bit number through debug led
+// Read as follows: 1230 = [*]  [* *]  [* * *]  [**]  (note zero is fast double flash)
 #define DLED_ONTIME 1000000
 #define DLED_PAUSE 1500000
-void dled_print(uint32_t x, uint8_t long_pause)
-{
-    int8_t t;
+void dled_print(uint32_t x, uint8_t long_pause) {
+    int8_t   t;
     uint32_t n;
     uint32_t p, p2;
 
-    if      (x < 10) t = 0;
-    else if (x < 100) t = 1;
-    else if (x < 1000) t = 2;
-    else if (x < 10000) t = 3;
-    else if (x < 100000) t = 4;
-    else if (x < 1000000) t = 5;
-    else if (x < 10000000) t = 6;
-    else if (x < 100000000) t = 7;
-    else if (x < 1000000000) t = 8;
-    else t = 9;
-
-    while (t >= 0)
-    {
+    if (x < 10)
+        t = 0;
+    else if (x < 100)
+        t = 1;
+    else if (x < 1000)
+        t = 2;
+    else if (x < 10000)
+        t = 3;
+    else if (x < 100000)
+        t = 4;
+    else if (x < 1000000)
+        t = 5;
+    else if (x < 10000000)
+        t = 6;
+    else if (x < 100000000)
+        t = 7;
+    else if (x < 1000000000)
+        t = 8;
+    else
+        t = 9;
+
+    while (t >= 0) {
         p2 = t;
-        p = 1;
+        p  = 1;
         while (p2--) p *= 10;
         n = x / p;
         x -= n * p;
-        if (!n)
-        {
+        if (!n) {
             DBG_LED_ON;
-            for (w = DLED_ONTIME / 4; w; w--);
+            for (w = DLED_ONTIME / 4; w; w--)
+                ;
             DBG_LED_OFF;
-            for (w = DLED_ONTIME / 4; w; w--);
+            for (w = DLED_ONTIME / 4; w; w--)
+                ;
             DBG_LED_ON;
-            for (w = DLED_ONTIME / 4; w; w--);
+            for (w = DLED_ONTIME / 4; w; w--)
+                ;
             DBG_LED_OFF;
-            for (w = DLED_ONTIME / 4; w; w--);
+            for (w = DLED_ONTIME / 4; w; w--)
+                ;
             n--;
-        }
-        else
-        {
-            while (n > 0)
-            {
+        } else {
+            while (n > 0) {
                 DBG_LED_ON;
-                for (w = DLED_ONTIME; w; w--);
+                for (w = DLED_ONTIME; w; w--)
+                    ;
                 DBG_LED_OFF;
-                for (w = DLED_ONTIME / 2; w; w--);
+                for (w = DLED_ONTIME / 2; w; w--)
+                    ;
                 n--;
             }
         }
 
-        for (w = DLED_PAUSE; w; w--);
+        for (w = DLED_PAUSE; w; w--)
+            ;
         t--;
     }
 
-    if (long_pause)
-    {
-        for (w = DLED_PAUSE * 4; w; w--);
+    if (long_pause) {
+        for (w = DLED_PAUSE * 4; w; w--)
+            ;
     }
 }
 
@@ -119,103 +135,102 @@ void dled_print(uint32_t x, uint8_t long_pause)
 
 volatile uint32_t debug_code;
 
-//These macros are for compile time substitution
-#define DEBUG_BOOT_TRACING_EXTINTn (DEBUG_BOOT_TRACING_PIN % _U_(0x10))
-#define DEBUG_BOOT_TRACING_EXTINTb (_U_(0x1) << DEBUG_BOOT_TRACING_EXTINTn)
-#define DEBUG_BOOT_TRACING_CONFIG_INDn (DEBUG_BOOT_TRACING_EXTINTn / _U_(0x8))
-#define DEBUG_BOOT_TRACING_CONFIG_SENSEn (DEBUG_BOOT_TRACING_EXTINTn % _U_(0x8))
-#define DEBUG_BOOT_TRACING_CONFIG_SENSEb (DEBUG_BOOT_TRACING_CONFIG_SENSEn * _U_(0x4))
-#define DEBUG_BOOT_TRACING_IRQn (EIC_0_IRQn + DEBUG_BOOT_TRACING_EXTINTn)
-
-//These macros perform PORT+PIN definition translation to IRQn in the preprocessor
-#define PORTPIN_TO_IRQn_EXPAND(def) def
-#define PORTPIN_TO_IRQn_DEF(def) PORTPIN_TO_IRQn_EXPAND(def)
-#if DEBUG_BOOT_TRACING_PIN < 10
-#define PORTPIN_TO_IRQn_TODEF(port, pin) PORTPIN_TO_IRQn_DEF(PIN_ ## port ## 0 ## pin ## A_EIC_EXTINT_NUM)
-#else
-#define PORTPIN_TO_IRQn_TODEF(port, pin) PORTPIN_TO_IRQn_DEF(PIN_ ## port ## pin ## A_EIC_EXTINT_NUM)
-#endif
-#define PORTPIN_TO_IRQn(port, pin) PORTPIN_TO_IRQn_TODEF(port, pin)
-
-//These macros perform function name output in the preprocessor
-#define DEBUG_BOOT_TRACING_HANDLER_CONCAT(irq) void EIC_ ## irq ## _Handler(void)
-#define DEBUG_BOOT_TRACING_HANDLER(irq) DEBUG_BOOT_TRACING_HANDLER_CONCAT(irq)
-
-//To generate the function name of the IRQ handler catching boot tracing,
+// These macros are for compile time substitution
+#    define DEBUG_BOOT_TRACING_EXTINTn (DEBUG_BOOT_TRACING_PIN % _U_(0x10))
+#    define DEBUG_BOOT_TRACING_EXTINTb (_U_(0x1) << DEBUG_BOOT_TRACING_EXTINTn)
+#    define DEBUG_BOOT_TRACING_CONFIG_INDn (DEBUG_BOOT_TRACING_EXTINTn / _U_(0x8))
+#    define DEBUG_BOOT_TRACING_CONFIG_SENSEn (DEBUG_BOOT_TRACING_EXTINTn % _U_(0x8))
+#    define DEBUG_BOOT_TRACING_CONFIG_SENSEb (DEBUG_BOOT_TRACING_CONFIG_SENSEn * _U_(0x4))
+#    define DEBUG_BOOT_TRACING_IRQn (EIC_0_IRQn + DEBUG_BOOT_TRACING_EXTINTn)
+
+// These macros perform PORT+PIN definition translation to IRQn in the preprocessor
+#    define PORTPIN_TO_IRQn_EXPAND(def) def
+#    define PORTPIN_TO_IRQn_DEF(def) PORTPIN_TO_IRQn_EXPAND(def)
+#    if DEBUG_BOOT_TRACING_PIN < 10
+#        define PORTPIN_TO_IRQn_TODEF(port, pin) PORTPIN_TO_IRQn_DEF(PIN_##port##0##pin##A_EIC_EXTINT_NUM)
+#    else
+#        define PORTPIN_TO_IRQn_TODEF(port, pin) PORTPIN_TO_IRQn_DEF(PIN_##port##pin##A_EIC_EXTINT_NUM)
+#    endif
+#    define PORTPIN_TO_IRQn(port, pin) PORTPIN_TO_IRQn_TODEF(port, pin)
+
+// These macros perform function name output in the preprocessor
+#    define DEBUG_BOOT_TRACING_HANDLER_CONCAT(irq) void EIC_##irq##_Handler(void)
+#    define DEBUG_BOOT_TRACING_HANDLER(irq) DEBUG_BOOT_TRACING_HANDLER_CONCAT(irq)
+
+// To generate the function name of the IRQ handler catching boot tracing,
 //  certain macros must be undefined, so save their current values to macro stack
-#pragma push_macro("PA")
-#pragma push_macro("PB")
-#pragma push_macro("_L_")
-
-//Undefine / redefine pushed macros
-#undef PA
-#undef PB
-#undef _L_
-#define _L_(x) x
-
-//Perform the work and output
-//Ex: PORT PB, PIN 31 = void EIC_15_Handler(void)
+#    pragma push_macro("PA")
+#    pragma push_macro("PB")
+#    pragma push_macro("_L_")
+
+// Undefine / redefine pushed macros
+#    undef PA
+#    undef PB
+#    undef _L_
+#    define _L_(x) x
+
+// Perform the work and output
+// Ex: PORT PB, PIN 31 = void EIC_15_Handler(void)
 DEBUG_BOOT_TRACING_HANDLER(PORTPIN_TO_IRQn(DEBUG_BOOT_TRACING_PORT, DEBUG_BOOT_TRACING_PIN))
-
-//Restore macros
-#pragma pop_macro("PA")
-#pragma pop_macro("PB")
-#pragma pop_macro("_L_")
+// Restore macros
+#    pragma pop_macro("PA")
+#    pragma pop_macro("PB")
+#    pragma pop_macro("_L_")
 {
-    //This is only for non-functional keyboard troubleshooting and should be disabled after boot
-    //Intention is to lock up the keyboard here with repeating debug led code
-    while (1)
-    {
+    // This is only for non-functional keyboard troubleshooting and should be disabled after boot
+    // Intention is to lock up the keyboard here with repeating debug led code
+    while (1) {
         dled_print(debug_code, 1);
     }
 }
 
-void debug_code_init(void)
-{
+void debug_code_init(void) {
     DBGC(DC_UNSET);
 
-    //Configure Ports for EIC
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].DIRCLR.reg = 1 << DEBUG_BOOT_TRACING_PIN; //Input
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].OUTSET.reg = 1 << DEBUG_BOOT_TRACING_PIN; //High
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.INEN = 1; //Input Enable
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PULLEN = 1; //Pull Enable
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PMUXEN = 1; //Mux Enable
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].PMUX[DEBUG_BOOT_TRACING_PIN / 2].bit.PMUXO = 0; //Mux A
+    // Configure Ports for EIC
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].DIRCLR.reg                                 = 1 << DEBUG_BOOT_TRACING_PIN;  // Input
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].OUTSET.reg                                 = 1 << DEBUG_BOOT_TRACING_PIN;  // High
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.INEN    = 1;                            // Input Enable
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PULLEN  = 1;                            // Pull Enable
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PMUXEN  = 1;                            // Mux Enable
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].PMUX[DEBUG_BOOT_TRACING_PIN / 2].bit.PMUXO = 0;                            // Mux A
 
-    //Enable CLK_EIC_APB
+    // Enable CLK_EIC_APB
     MCLK->APBAMASK.bit.EIC_ = 1;
 
-    //Configure EIC
+    // Configure EIC
     EIC->CTRLA.bit.SWRST = 1;
-    while (EIC->SYNCBUSY.bit.SWRST) {}
-    EIC->ASYNCH.reg = DEBUG_BOOT_TRACING_EXTINTb;
+    while (EIC->SYNCBUSY.bit.SWRST) {
+    }
+    EIC->ASYNCH.reg   = DEBUG_BOOT_TRACING_EXTINTb;
     EIC->INTENSET.reg = DEBUG_BOOT_TRACING_EXTINTb;
     EIC->CONFIG[DEBUG_BOOT_TRACING_CONFIG_INDn].reg |= (EIC_CONFIG_SENSE0_FALL_Val << DEBUG_BOOT_TRACING_CONFIG_SENSEb);
     EIC->CTRLA.bit.ENABLE = 1;
-    while (EIC->SYNCBUSY.bit.ENABLE) {}
+    while (EIC->SYNCBUSY.bit.ENABLE) {
+    }
 
-    //Enable EIC IRQ
+    // Enable EIC IRQ
     NVIC_EnableIRQ(DEBUG_BOOT_TRACING_IRQn);
 }
 
-void debug_code_disable(void)
-{
-    //Disable EIC IRQ
+void debug_code_disable(void) {
+    // Disable EIC IRQ
     NVIC_DisableIRQ(DEBUG_BOOT_TRACING_IRQn);
 
-    //Disable EIC
+    // Disable EIC
     EIC->CTRLA.bit.ENABLE = 0;
-    while (EIC->SYNCBUSY.bit.ENABLE) {}
+    while (EIC->SYNCBUSY.bit.ENABLE) {
+    }
 
-    //Default port configuration
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].DIRCLR.reg = 1 << DEBUG_BOOT_TRACING_PIN; //Input
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].OUTCLR.reg = 1 << DEBUG_BOOT_TRACING_PIN; //Low
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.INEN = 0; //Input Disable
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PULLEN = 0; //Pull Disable
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PMUXEN = 0; //Mux Disable
-    PORT->Group[DEBUG_BOOT_TRACING_PORT].PMUX[DEBUG_BOOT_TRACING_PIN / 2].bit.PMUXO = 0; //Mux A
+    // Default port configuration
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].DIRCLR.reg                                 = 1 << DEBUG_BOOT_TRACING_PIN;  // Input
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].OUTCLR.reg                                 = 1 << DEBUG_BOOT_TRACING_PIN;  // Low
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.INEN    = 0;                            // Input Disable
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PULLEN  = 0;                            // Pull Disable
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PMUXEN  = 0;                            // Mux Disable
+    PORT->Group[DEBUG_BOOT_TRACING_PORT].PMUX[DEBUG_BOOT_TRACING_PIN / 2].bit.PMUXO = 0;                            // Mux A
 
-    //Disable CLK_EIC_APB
+    // Disable CLK_EIC_APB
     MCLK->APBAMASK.bit.EIC_ = 0;
 }
 
@@ -224,4 +239,4 @@ void debug_code_disable(void)
 void debug_code_init(void) {}
 void debug_code_disable(void) {}
 
-#endif //DEBUG_BOOT_TRACING_ENABLE
+#endif  // DEBUG_BOOT_TRACING_ENABLE
index 71431942c7ec242831713154c858d0e0fd884431..89cf338d2340132160f717c600b88206e45494df 100644 (file)
@@ -22,54 +22,54 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /* Debug LED */
 #if DEBUG_LED_ENABLE == 1
-#define DBG_LED_ENA PORT->Group[DEBUG_LED_PORT].DIRSET.reg = (1 << DEBUG_LED_PIN)
-#define DBG_LED_DIS PORT->Group[DEBUG_LED_PORT].DIRCLR.reg = (1 << DEBUG_LED_PIN)
-#define DBG_LED_ON  PORT->Group[DEBUG_LED_PORT].OUTSET.reg = (1 << DEBUG_LED_PIN)
-#define DBG_LED_OFF PORT->Group[DEBUG_LED_PORT].OUTCLR.reg = (1 << DEBUG_LED_PIN)
+#    define DBG_LED_ENA PORT->Group[DEBUG_LED_PORT].DIRSET.reg = (1 << DEBUG_LED_PIN)
+#    define DBG_LED_DIS PORT->Group[DEBUG_LED_PORT].DIRCLR.reg = (1 << DEBUG_LED_PIN)
+#    define DBG_LED_ON PORT->Group[DEBUG_LED_PORT].OUTSET.reg = (1 << DEBUG_LED_PIN)
+#    define DBG_LED_OFF PORT->Group[DEBUG_LED_PORT].OUTCLR.reg = (1 << DEBUG_LED_PIN)
 #else
-#define DBG_LED_ENA
-#define DBG_LED_DIS
-#define DBG_LED_ON
-#define DBG_LED_OFF
+#    define DBG_LED_ENA
+#    define DBG_LED_DIS
+#    define DBG_LED_ON
+#    define DBG_LED_OFF
 #endif
 
 /* Debug Port 1 */
 #if DEBUG_PORT1_ENABLE == 1
-#define DBG_1_ENA PORT->Group[DEBUG_PORT1_PORT].DIRSET.reg = (1 << DEBUG_PORT1_PIN)
-#define DBG_1_DIS PORT->Group[DEBUG_PORT1_PORT].DIRCLR.reg = (1 << DEBUG_PORT1_PIN)
-#define DBG_1_ON  PORT->Group[DEBUG_PORT1_PORT].OUTSET.reg = (1 << DEBUG_PORT1_PIN)
-#define DBG_1_OFF PORT->Group[DEBUG_PORT1_PORT].OUTCLR.reg = (1 << DEBUG_PORT1_PIN)
+#    define DBG_1_ENA PORT->Group[DEBUG_PORT1_PORT].DIRSET.reg = (1 << DEBUG_PORT1_PIN)
+#    define DBG_1_DIS PORT->Group[DEBUG_PORT1_PORT].DIRCLR.reg = (1 << DEBUG_PORT1_PIN)
+#    define DBG_1_ON PORT->Group[DEBUG_PORT1_PORT].OUTSET.reg = (1 << DEBUG_PORT1_PIN)
+#    define DBG_1_OFF PORT->Group[DEBUG_PORT1_PORT].OUTCLR.reg = (1 << DEBUG_PORT1_PIN)
 #else
-#define DBG_1_ENA
-#define DBG_1_DIS
-#define DBG_1_ON 
-#define DBG_1_OFF
+#    define DBG_1_ENA
+#    define DBG_1_DIS
+#    define DBG_1_ON
+#    define DBG_1_OFF
 #endif
 
 /* Debug Port 2 */
 #if DEBUG_PORT2_ENABLE == 1
-#define DBG_2_ENA PORT->Group[DEBUG_PORT2_PORT].DIRSET.reg = (1 << DEBUG_PORT2_PIN)
-#define DBG_2_DIS PORT->Group[DEBUG_PORT2_PORT].DIRCLR.reg = (1 << DEBUG_PORT2_PIN)
-#define DBG_2_ON  PORT->Group[DEBUG_PORT2_PORT].OUTSET.reg = (1 << DEBUG_PORT2_PIN)
-#define DBG_2_OFF PORT->Group[DEBUG_PORT2_PORT].OUTCLR.reg = (1 << DEBUG_PORT2_PIN)
+#    define DBG_2_ENA PORT->Group[DEBUG_PORT2_PORT].DIRSET.reg = (1 << DEBUG_PORT2_PIN)
+#    define DBG_2_DIS PORT->Group[DEBUG_PORT2_PORT].DIRCLR.reg = (1 << DEBUG_PORT2_PIN)
+#    define DBG_2_ON PORT->Group[DEBUG_PORT2_PORT].OUTSET.reg = (1 << DEBUG_PORT2_PIN)
+#    define DBG_2_OFF PORT->Group[DEBUG_PORT2_PORT].OUTCLR.reg = (1 << DEBUG_PORT2_PIN)
 #else
-#define DBG_2_ENA
-#define DBG_2_DIS
-#define DBG_2_ON 
-#define DBG_2_OFF
+#    define DBG_2_ENA
+#    define DBG_2_DIS
+#    define DBG_2_ON
+#    define DBG_2_OFF
 #endif
 
 /* Debug Port 3 */
 #if DEBUG_PORT3_ENABLE == 1
-#define DBG_3_ENA PORT->Group[DEBUG_PORT3_PORT].DIRSET.reg = (1 << DEBUG_PORT3_PIN)
-#define DBG_3_DIS PORT->Group[DEBUG_PORT3_PORT].DIRCLR.reg = (1 << DEBUG_PORT3_PIN)
-#define DBG_3_ON  PORT->Group[DEBUG_PORT3_PORT].OUTSET.reg = (1 << DEBUG_PORT3_PIN)
-#define DBG_3_OFF PORT->Group[DEBUG_PORT3_PORT].OUTCLR.reg = (1 << DEBUG_PORT3_PIN)
+#    define DBG_3_ENA PORT->Group[DEBUG_PORT3_PORT].DIRSET.reg = (1 << DEBUG_PORT3_PIN)
+#    define DBG_3_DIS PORT->Group[DEBUG_PORT3_PORT].DIRCLR.reg = (1 << DEBUG_PORT3_PIN)
+#    define DBG_3_ON PORT->Group[DEBUG_PORT3_PORT].OUTSET.reg = (1 << DEBUG_PORT3_PIN)
+#    define DBG_3_OFF PORT->Group[DEBUG_PORT3_PORT].OUTCLR.reg = (1 << DEBUG_PORT3_PIN)
 #else
-#define DBG_3_ENA
-#define DBG_3_DIS
-#define DBG_3_ON 
-#define DBG_3_OFF
+#    define DBG_3_ENA
+#    define DBG_3_DIS
+#    define DBG_3_ON
+#    define DBG_3_OFF
 #endif
 
 void dbg_print(uint32_t x);
@@ -80,7 +80,7 @@ void debug_code_disable(void);
 
 #ifdef DEBUG_BOOT_TRACING_ENABLE
 
-#define DBGC(n) debug_code = n
+#    define DBGC(n) debug_code = n
 
 extern volatile uint32_t debug_code;
 
@@ -216,8 +216,9 @@ enum debug_code_list {
 
 #else
 
-#define DBGC(n) {}
+#    define DBGC(n) \
+        {}
 
-#endif //DEBUG_BOOT_TRACING_ENABLE
+#endif  // DEBUG_BOOT_TRACING_ENABLE
 
-#endif //_D51_UTIL_H_
+#endif  //_D51_UTIL_H_
index 1741d9ac5b02b3e3c9045e8f280bac4128acefaa..d3319ab447d25c586898fd1a05f6b14675ee74e2 100644 (file)
@@ -19,77 +19,84 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #if !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
 
-#include <string.h>
+#    include <string.h>
 
-//From keyboard
-#include "config.h"
-#include "config_led.h"
-#include "matrix.h"
+// From keyboard
+#    include "config.h"
+#    include "config_led.h"
+#    include "matrix.h"
 
-#define I2C_LED_USE_DMA 1               //Set 1 to use background DMA transfers for leds, Set 0 to use inline software transfers
+#    define I2C_LED_USE_DMA 1  // Set 1 to use background DMA transfers for leds, Set 0 to use inline software transfers
 
-static uint8_t i2c_led_q[I2C_Q_SIZE];   //I2C queue circular buffer
-static uint8_t i2c_led_q_s;             //Start of circular buffer
-static uint8_t i2c_led_q_e;             //End of circular buffer
-static uint8_t i2c_led_q_full;          //Queue full counter for reset
+static uint8_t i2c_led_q[I2C_Q_SIZE];  // I2C queue circular buffer
+static uint8_t i2c_led_q_s;            // Start of circular buffer
+static uint8_t i2c_led_q_e;            // End of circular buffer
+static uint8_t i2c_led_q_full;         // Queue full counter for reset
 
-static uint8_t dma_sendbuf[I2C_DMA_MAX_SEND]; //Data being written to I2C
+static uint8_t dma_sendbuf[I2C_DMA_MAX_SEND];  // Data being written to I2C
 
 volatile uint8_t i2c_led_q_running;
 
-#endif // !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
+#endif  // !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
 
-void i2c0_init(void)
-{
+void i2c0_init(void) {
     DBGC(DC_I2C0_INIT_BEGIN);
 
     CLK_set_i2c0_freq(CHAN_SERCOM_I2C0, FREQ_I2C0_DEFAULT);
 
-    //MCU
-    PORT->Group[0].PMUX[4].bit.PMUXE = 2;
-    PORT->Group[0].PMUX[4].bit.PMUXO = 2;
+    // MCU
+    PORT->Group[0].PMUX[4].bit.PMUXE    = 2;
+    PORT->Group[0].PMUX[4].bit.PMUXO    = 2;
     PORT->Group[0].PINCFG[8].bit.PMUXEN = 1;
     PORT->Group[0].PINCFG[9].bit.PMUXEN = 1;
 
-    //I2C
-    //Note: SW Reset handled in CLK_set_i2c0_freq clks.c
+    // I2C
+    // Note: SW Reset handled in CLK_set_i2c0_freq clks.c
 
-    SERCOM0->I2CM.CTRLA.bit.MODE = 5;                           //Set master mode
+    SERCOM0->I2CM.CTRLA.bit.MODE = 5;  // Set master mode
 
-    SERCOM0->I2CM.CTRLA.bit.SPEED = 0;                          //Set to 1 for Fast-mode Plus (FM+) up to 1 MHz
-    SERCOM0->I2CM.CTRLA.bit.RUNSTDBY = 1;                       //Enabled
+    SERCOM0->I2CM.CTRLA.bit.SPEED    = 0;  // Set to 1 for Fast-mode Plus (FM+) up to 1 MHz
+    SERCOM0->I2CM.CTRLA.bit.RUNSTDBY = 1;  // Enabled
 
-    SERCOM0->I2CM.CTRLA.bit.ENABLE = 1;                         //Enable the device
-    while (SERCOM0->I2CM.SYNCBUSY.bit.ENABLE) { DBGC(DC_I2C0_INIT_SYNC_ENABLING); }                //Wait for SYNCBUSY.ENABLE to clear
+    SERCOM0->I2CM.CTRLA.bit.ENABLE = 1;  // Enable the device
+    while (SERCOM0->I2CM.SYNCBUSY.bit.ENABLE) {
+        DBGC(DC_I2C0_INIT_SYNC_ENABLING);
+    }  // Wait for SYNCBUSY.ENABLE to clear
 
-    SERCOM0->I2CM.STATUS.bit.BUSSTATE = 1;                      //Force into IDLE state
-    while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) { DBGC(DC_I2C0_INIT_SYNC_SYSOP); }
-    while (SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1) { DBGC(DC_I2C0_INIT_WAIT_IDLE); }           //Wait while not idle
+    SERCOM0->I2CM.STATUS.bit.BUSSTATE = 1;  // Force into IDLE state
+    while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) {
+        DBGC(DC_I2C0_INIT_SYNC_SYSOP);
+    }
+    while (SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1) {
+        DBGC(DC_I2C0_INIT_WAIT_IDLE);
+    }  // Wait while not idle
 
     DBGC(DC_I2C0_INIT_COMPLETE);
 }
 
-uint8_t i2c0_start(uint8_t address)
-{
+uint8_t i2c0_start(uint8_t address) {
     SERCOM0->I2CM.ADDR.bit.ADDR = address;
-    while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) {}
-    while (SERCOM0->I2CM.INTFLAG.bit.MB == 0) {}
-    while (SERCOM0->I2CM.STATUS.bit.RXNACK) {}
+    while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) {
+    }
+    while (SERCOM0->I2CM.INTFLAG.bit.MB == 0) {
+    }
+    while (SERCOM0->I2CM.STATUS.bit.RXNACK) {
+    }
 
     return 1;
 }
 
-uint8_t i2c0_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout)
-{
+uint8_t i2c0_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout) {
     if (!length) return 0;
 
     i2c0_start(address);
 
-    while (length)
-    {
+    while (length) {
         SERCOM0->I2CM.DATA.bit.DATA = *data;
-        while (SERCOM0->I2CM.INTFLAG.bit.MB == 0) {}
-        while (SERCOM0->I2CM.STATUS.bit.RXNACK) {}
+        while (SERCOM0->I2CM.INTFLAG.bit.MB == 0) {
+        }
+        while (SERCOM0->I2CM.STATUS.bit.RXNACK) {
+        }
 
         data++;
         length--;
@@ -100,74 +107,83 @@ uint8_t i2c0_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t
     return 1;
 }
 
-void i2c0_stop(void)
-{
-    if (SERCOM0->I2CM.STATUS.bit.CLKHOLD || SERCOM0->I2CM.INTFLAG.bit.MB == 1 || SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1)
-    {
+void i2c0_stop(void) {
+    if (SERCOM0->I2CM.STATUS.bit.CLKHOLD || SERCOM0->I2CM.INTFLAG.bit.MB == 1 || SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1) {
         SERCOM0->I2CM.CTRLB.bit.CMD = 3;
-        while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP);
-        while (SERCOM0->I2CM.STATUS.bit.CLKHOLD);
-        while (SERCOM0->I2CM.INTFLAG.bit.MB);
-        while (SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1);
+        while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP)
+            ;
+        while (SERCOM0->I2CM.STATUS.bit.CLKHOLD)
+            ;
+        while (SERCOM0->I2CM.INTFLAG.bit.MB)
+            ;
+        while (SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1)
+            ;
     }
 }
 
 #if !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
-void i2c1_init(void)
-{
+void i2c1_init(void) {
     DBGC(DC_I2C1_INIT_BEGIN);
 
     CLK_set_i2c1_freq(CHAN_SERCOM_I2C1, FREQ_I2C1_DEFAULT);
 
     /* MCU */
-    PORT->Group[0].PMUX[8].bit.PMUXE = 2;
-    PORT->Group[0].PMUX[8].bit.PMUXO = 2;
+    PORT->Group[0].PMUX[8].bit.PMUXE     = 2;
+    PORT->Group[0].PMUX[8].bit.PMUXO     = 2;
     PORT->Group[0].PINCFG[16].bit.PMUXEN = 1;
     PORT->Group[0].PINCFG[17].bit.PMUXEN = 1;
 
     /* I2C */
-    //Note: SW Reset handled in CLK_set_i2c1_freq clks.c
+    // Note: SW Reset handled in CLK_set_i2c1_freq clks.c
 
-    SERCOM1->I2CM.CTRLA.bit.MODE = 5;                   //MODE: Set master mode (No sync)
-    SERCOM1->I2CM.CTRLA.bit.SPEED = 1;                  //SPEED: Fm+ up to 1MHz (No sync)
-    SERCOM1->I2CM.CTRLA.bit.RUNSTDBY = 1;               //RUNSTBY: Enabled (No sync)
+    SERCOM1->I2CM.CTRLA.bit.MODE     = 5;  // MODE: Set master mode (No sync)
+    SERCOM1->I2CM.CTRLA.bit.SPEED    = 1;  // SPEED: Fm+ up to 1MHz (No sync)
+    SERCOM1->I2CM.CTRLA.bit.RUNSTDBY = 1;  // RUNSTBY: Enabled (No sync)
 
-    SERCOM1->I2CM.CTRLB.bit.SMEN = 1;                   //SMEN: Smart mode enabled (For DMA)(No sync)
+    SERCOM1->I2CM.CTRLB.bit.SMEN = 1;  // SMEN: Smart mode enabled (For DMA)(No sync)
 
     NVIC_EnableIRQ(SERCOM1_0_IRQn);
     SERCOM1->I2CM.INTENSET.bit.ERROR = 1;
 
-    SERCOM1->I2CM.CTRLA.bit.ENABLE = 1;                 //ENABLE: Enable the device (sync SYNCBUSY.ENABLE)
-    while (SERCOM1->I2CM.SYNCBUSY.bit.ENABLE) { DBGC(DC_I2C1_INIT_SYNC_ENABLING); }        //Wait for SYNCBUSY.ENABLE to clear
+    SERCOM1->I2CM.CTRLA.bit.ENABLE = 1;  // ENABLE: Enable the device (sync SYNCBUSY.ENABLE)
+    while (SERCOM1->I2CM.SYNCBUSY.bit.ENABLE) {
+        DBGC(DC_I2C1_INIT_SYNC_ENABLING);
+    }  // Wait for SYNCBUSY.ENABLE to clear
 
-    SERCOM1->I2CM.STATUS.bit.BUSSTATE = 1;              //BUSSTATE: Force into IDLE state (sync SYNCBUSY.SYSOP)
-    while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP) { DBGC(DC_I2C1_INIT_SYNC_SYSOP); }
-    while (SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1) { DBGC(DC_I2C1_INIT_WAIT_IDLE); }  //Wait while not idle
+    SERCOM1->I2CM.STATUS.bit.BUSSTATE = 1;  // BUSSTATE: Force into IDLE state (sync SYNCBUSY.SYSOP)
+    while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP) {
+        DBGC(DC_I2C1_INIT_SYNC_SYSOP);
+    }
+    while (SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1) {
+        DBGC(DC_I2C1_INIT_WAIT_IDLE);
+    }  // Wait while not idle
 
     DBGC(DC_I2C1_INIT_COMPLETE);
 }
 
-uint8_t i2c1_start(uint8_t address)
-{
+uint8_t i2c1_start(uint8_t address) {
     SERCOM1->I2CM.ADDR.bit.ADDR = address;
-    while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP) {}
-    while (SERCOM1->I2CM.INTFLAG.bit.MB == 0) {}
-    while (SERCOM1->I2CM.STATUS.bit.RXNACK) {}
+    while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP) {
+    }
+    while (SERCOM1->I2CM.INTFLAG.bit.MB == 0) {
+    }
+    while (SERCOM1->I2CM.STATUS.bit.RXNACK) {
+    }
 
     return 1;
 }
 
-uint8_t i2c1_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout)
-{
+uint8_t i2c1_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout) {
     if (!length) return 0;
 
     i2c1_start(address);
 
-    while (length)
-    {
+    while (length) {
         SERCOM1->I2CM.DATA.bit.DATA = *data;
-        while (SERCOM1->I2CM.INTFLAG.bit.MB == 0) {}
-        while (SERCOM1->I2CM.STATUS.bit.RXNACK) {}
+        while (SERCOM1->I2CM.INTFLAG.bit.MB == 0) {
+        }
+        while (SERCOM1->I2CM.STATUS.bit.RXNACK) {
+        }
 
         data++;
         length--;
@@ -178,33 +194,32 @@ uint8_t i2c1_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t
     return 1;
 }
 
-void i2c1_stop(void)
-{
-    if (SERCOM1->I2CM.STATUS.bit.CLKHOLD || SERCOM1->I2CM.INTFLAG.bit.MB == 1 || SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1)
-    {
+void i2c1_stop(void) {
+    if (SERCOM1->I2CM.STATUS.bit.CLKHOLD || SERCOM1->I2CM.INTFLAG.bit.MB == 1 || SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1) {
         SERCOM1->I2CM.CTRLB.bit.CMD = 3;
-        while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP);
-        while (SERCOM1->I2CM.STATUS.bit.CLKHOLD);
-        while (SERCOM1->I2CM.INTFLAG.bit.MB);
-        while (SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1);
+        while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP)
+            ;
+        while (SERCOM1->I2CM.STATUS.bit.CLKHOLD)
+            ;
+        while (SERCOM1->I2CM.INTFLAG.bit.MB)
+            ;
+        while (SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1)
+            ;
     }
 }
 
-void i2c_led_send_CRWL(uint8_t drvid)
-{
-    uint8_t i2cdata[] = { ISSI3733_CMDRWL, ISSI3733_CMDRWL_WRITE_ENABLE_ONCE };
+void i2c_led_send_CRWL(uint8_t drvid) {
+    uint8_t i2cdata[] = {ISSI3733_CMDRWL, ISSI3733_CMDRWL_WRITE_ENABLE_ONCE};
     i2c1_transmit(issidrv[drvid].addr, i2cdata, sizeof(i2cdata), 0);
 }
 
-void i2c_led_select_page(uint8_t drvid, uint8_t pageno)
-{
-    uint8_t i2cdata[] = { ISSI3733_CMDR, pageno };
+void i2c_led_select_page(uint8_t drvid, uint8_t pageno) {
+    uint8_t i2cdata[] = {ISSI3733_CMDR, pageno};
     i2c1_transmit(issidrv[drvid].addr, i2cdata, sizeof(i2cdata), 0);
 }
 
-void i2c_led_send_GCR(uint8_t drvid)
-{
-    uint8_t i2cdata[] = { ISSI3733_GCCR, 0x00 };
+void i2c_led_send_GCR(uint8_t drvid) {
+    uint8_t i2cdata[] = {ISSI3733_GCCR, 0x00};
 
     if (gcr_actual > LED_GCR_MAX) gcr_actual = LED_GCR_MAX;
     i2cdata[1] = gcr_actual;
@@ -212,57 +227,50 @@ void i2c_led_send_GCR(uint8_t drvid)
     i2c1_transmit(issidrv[drvid].addr, i2cdata, sizeof(i2cdata), 0);
 }
 
-void i2c_led_send_onoff(uint8_t drvid)
-{
-#if I2C_LED_USE_DMA != 1
-    if (!i2c_led_q_running)
-    {
-#endif
+void i2c_led_send_onoff(uint8_t drvid) {
+#    if I2C_LED_USE_DMA != 1
+    if (!i2c_led_q_running) {
+#    endif
         i2c_led_send_CRWL(drvid);
         i2c_led_select_page(drvid, 0);
-#if I2C_LED_USE_DMA != 1
+#    if I2C_LED_USE_DMA != 1
     }
-#endif
+#    endif
 
-    *issidrv[drvid].onoff = 0; //Force start location offset to zero
+    *issidrv[drvid].onoff = 0;  // Force start location offset to zero
     i2c1_transmit(issidrv[drvid].addr, issidrv[drvid].onoff, ISSI3733_PG0_BYTES, 0);
 }
 
-void i2c_led_send_mode_op_gcr(uint8_t drvid, uint8_t mode, uint8_t operation)
-{
-    uint8_t i2cdata[] = { ISSI3733_CR, mode | operation, gcr_actual};
+void i2c_led_send_mode_op_gcr(uint8_t drvid, uint8_t mode, uint8_t operation) {
+    uint8_t i2cdata[] = {ISSI3733_CR, mode | operation, gcr_actual};
     i2c1_transmit(issidrv[drvid].addr, i2cdata, sizeof(i2cdata), 0);
 }
 
-void i2c_led_send_pur_pdr(uint8_t drvid, uint8_t pur, uint8_t pdr)
-{
-    uint8_t i2cdata[] = { ISSI3733_SWYR_PUR, pur, pdr };
+void i2c_led_send_pur_pdr(uint8_t drvid, uint8_t pur, uint8_t pdr) {
+    uint8_t i2cdata[] = {ISSI3733_SWYR_PUR, pur, pdr};
 
     i2c1_transmit(issidrv[drvid].addr, i2cdata, sizeof(i2cdata), 0);
 }
 
-void i2c_led_send_pwm(uint8_t drvid)
-{
-#if I2C_LED_USE_DMA != 1
-    if (!i2c_led_q_running)
-    {
-#endif
+void i2c_led_send_pwm(uint8_t drvid) {
+#    if I2C_LED_USE_DMA != 1
+    if (!i2c_led_q_running) {
+#    endif
         i2c_led_send_CRWL(drvid);
         i2c_led_select_page(drvid, 0);
-#if I2C_LED_USE_DMA != 1
+#    if I2C_LED_USE_DMA != 1
     }
-#endif
+#    endif
 
-    *issidrv[drvid].pwm = 0; //Force start location offset to zero
+    *issidrv[drvid].pwm = 0;  // Force start location offset to zero
     i2c1_transmit(issidrv[drvid].addr, issidrv[drvid].pwm, ISSI3733_PG1_BYTES, 0);
 }
 
-uint8_t I2C3733_Init_Control(void)
-{
+uint8_t I2C3733_Init_Control(void) {
     DBGC(DC_I2C3733_INIT_CONTROL_BEGIN);
 
-    //Hardware state shutdown on boot
-    //USB state machine will enable driver when communication is ready
+    // Hardware state shutdown on boot
+    // USB state machine will enable driver when communication is ready
     I2C3733_Control_Set(0);
 
     wait_ms(1);
@@ -277,25 +285,24 @@ uint8_t I2C3733_Init_Control(void)
     return 1;
 }
 
-uint8_t I2C3733_Init_Drivers(void)
-{
+uint8_t I2C3733_Init_Drivers(void) {
     DBGC(DC_I2C3733_INIT_DRIVERS_BEGIN);
 
-    gcr_actual = ISSI3733_GCR_DEFAULT;
+    gcr_actual      = ISSI3733_GCR_DEFAULT;
     gcr_actual_last = gcr_actual;
 
     if (gcr_actual > LED_GCR_MAX) gcr_actual = LED_GCR_MAX;
     gcr_desired = gcr_actual;
 
-    //Set up master device
+    // Set up master device
     i2c_led_send_CRWL(0);
     i2c_led_select_page(0, 3);
-    i2c_led_send_mode_op_gcr(0, 0, ISSI3733_CR_SSD_NORMAL); //No SYNC due to brightness mismatch with second driver
+    i2c_led_send_mode_op_gcr(0, 0, ISSI3733_CR_SSD_NORMAL);  // No SYNC due to brightness mismatch with second driver
 
-    //Set up slave device
+    // Set up slave device
     i2c_led_send_CRWL(1);
     i2c_led_select_page(1, 3);
-    i2c_led_send_mode_op_gcr(1, 0, ISSI3733_CR_SSD_NORMAL); //No SYNC due to brightness mismatch with first driver and slight flicker at rgb values 1,2
+    i2c_led_send_mode_op_gcr(1, 0, ISSI3733_CR_SSD_NORMAL);  // No SYNC due to brightness mismatch with first driver and slight flicker at rgb values 1,2
 
     i2c_led_send_CRWL(0);
     i2c_led_select_page(0, 3);
@@ -310,51 +317,54 @@ uint8_t I2C3733_Init_Drivers(void)
     return 1;
 }
 
-void I2C_DMAC_LED_Init(void)
-{
+void I2C_DMAC_LED_Init(void) {
     Dmac *dmac = DMAC;
 
     DBGC(DC_I2C_DMAC_LED_INIT_BEGIN);
 
-    //Disable device
-    dmac->CTRL.bit.DMAENABLE = 0;                   //Disable DMAC
-    while (dmac->CTRL.bit.DMAENABLE) {}             //Wait for disabled state in case of ongoing transfers
-    dmac->CTRL.bit.SWRST = 1;                       //Software Reset DMAC
-    while (dmac->CTRL.bit.SWRST) {}                 //Wait for software reset to complete
-
-    //Configure device
-    dmac->BASEADDR.reg = (uint32_t)&dmac_desc;      //Set descriptor base address
-    dmac->WRBADDR.reg = (uint32_t)&dmac_desc_wb;    //Set descriptor write back address
-    dmac->CTRL.reg |= 0x0f00;                       //Handle all priorities (LVL0-3)
-
-    //Disable channel
-    dmac->Channel[0].CHCTRLA.bit.ENABLE = 0;        //Disable the channel
-    while (dmac->Channel[0].CHCTRLA.bit.ENABLE) {}  //Wait for disabled state in case of ongoing transfers
-    dmac->Channel[0].CHCTRLA.bit.SWRST = 1;         //Software Reset the channel
-    while (dmac->Channel[0].CHCTRLA.bit.SWRST) {}   //Wait for software reset to complete
-
-    //Configure channel
-    dmac->Channel[0].CHCTRLA.bit.THRESHOLD = 0;     //1BEAT
-    dmac->Channel[0].CHCTRLA.bit.BURSTLEN = 0;      //SINGLE
-    dmac->Channel[0].CHCTRLA.bit.TRIGACT = 2;       //BURST
-    dmac->Channel[0].CHCTRLA.bit.TRIGSRC = SERCOM1_DMAC_ID_TX;  //Trigger source
-    dmac->Channel[0].CHCTRLA.bit.RUNSTDBY = 1;      //Run in standby
+    // Disable device
+    dmac->CTRL.bit.DMAENABLE = 0;  // Disable DMAC
+    while (dmac->CTRL.bit.DMAENABLE) {
+    }                          // Wait for disabled state in case of ongoing transfers
+    dmac->CTRL.bit.SWRST = 1;  // Software Reset DMAC
+    while (dmac->CTRL.bit.SWRST) {
+    }  // Wait for software reset to complete
+
+    // Configure device
+    dmac->BASEADDR.reg = (uint32_t)&dmac_desc;     // Set descriptor base address
+    dmac->WRBADDR.reg  = (uint32_t)&dmac_desc_wb;  // Set descriptor write back address
+    dmac->CTRL.reg |= 0x0f00;                      // Handle all priorities (LVL0-3)
+
+    // Disable channel
+    dmac->Channel[0].CHCTRLA.bit.ENABLE = 0;  // Disable the channel
+    while (dmac->Channel[0].CHCTRLA.bit.ENABLE) {
+    }                                        // Wait for disabled state in case of ongoing transfers
+    dmac->Channel[0].CHCTRLA.bit.SWRST = 1;  // Software Reset the channel
+    while (dmac->Channel[0].CHCTRLA.bit.SWRST) {
+    }  // Wait for software reset to complete
+
+    // Configure channel
+    dmac->Channel[0].CHCTRLA.bit.THRESHOLD = 0;                   // 1BEAT
+    dmac->Channel[0].CHCTRLA.bit.BURSTLEN  = 0;                   // SINGLE
+    dmac->Channel[0].CHCTRLA.bit.TRIGACT   = 2;                   // BURST
+    dmac->Channel[0].CHCTRLA.bit.TRIGSRC   = SERCOM1_DMAC_ID_TX;  // Trigger source
+    dmac->Channel[0].CHCTRLA.bit.RUNSTDBY  = 1;                   // Run in standby
 
     NVIC_EnableIRQ(DMAC_0_IRQn);
     dmac->Channel[0].CHINTENSET.bit.TCMPL = 1;
-    dmac->Channel[0].CHINTENSET.bit.TERR = 1;
+    dmac->Channel[0].CHINTENSET.bit.TERR  = 1;
 
-    //Enable device
-    dmac->CTRL.bit.DMAENABLE = 1;                   //Enable DMAC
-    while (dmac->CTRL.bit.DMAENABLE == 0) {}        //Wait for enable state
+    // Enable device
+    dmac->CTRL.bit.DMAENABLE = 1;  // Enable DMAC
+    while (dmac->CTRL.bit.DMAENABLE == 0) {
+    }  // Wait for enable state
 
     DBGC(DC_I2C_DMAC_LED_INIT_COMPLETE);
 }
 
-//state = 1 enable
-//state = 0 disable
-void I2C3733_Control_Set(uint8_t state)
-{
+// state = 1 enable
+// state = 0 disable
+void I2C3733_Control_Set(uint8_t state) {
     DBGC(DC_I2C3733_CONTROL_SET_BEGIN);
 
     sr_exp_data.bit.SDB_N = (state == 1 ? 1 : 0);
@@ -363,131 +373,111 @@ void I2C3733_Control_Set(uint8_t state)
     DBGC(DC_I2C3733_CONTROL_SET_COMPLETE);
 }
 
-void i2c_led_desc_defaults(void)
-{
-    dmac_desc.BTCTRL.bit.STEPSIZE = 0;      //SRCINC used in favor for auto 1 inc
-    dmac_desc.BTCTRL.bit.STEPSEL = 0;       //SRCINC used in favor for auto 1 inc
-    dmac_desc.BTCTRL.bit.DSTINC = 0;        //The Destination Address Increment is disabled
-    dmac_desc.BTCTRL.bit.SRCINC = 1;        //The Source Address Increment is enabled (Inc by 1)
-    dmac_desc.BTCTRL.bit.BEATSIZE = 0;      //8-bit bus transfer
-    dmac_desc.BTCTRL.bit.BLOCKACT = 0;      //Channel will be disabled if it is the last block transfer in the transaction
-    dmac_desc.BTCTRL.bit.EVOSEL = 0;        //Event generation disabled
-    dmac_desc.BTCTRL.bit.VALID = 1;         //Set dmac valid
+void i2c_led_desc_defaults(void) {
+    dmac_desc.BTCTRL.bit.STEPSIZE = 0;  // SRCINC used in favor for auto 1 inc
+    dmac_desc.BTCTRL.bit.STEPSEL  = 0;  // SRCINC used in favor for auto 1 inc
+    dmac_desc.BTCTRL.bit.DSTINC   = 0;  // The Destination Address Increment is disabled
+    dmac_desc.BTCTRL.bit.SRCINC   = 1;  // The Source Address Increment is enabled (Inc by 1)
+    dmac_desc.BTCTRL.bit.BEATSIZE = 0;  // 8-bit bus transfer
+    dmac_desc.BTCTRL.bit.BLOCKACT = 0;  // Channel will be disabled if it is the last block transfer in the transaction
+    dmac_desc.BTCTRL.bit.EVOSEL   = 0;  // Event generation disabled
+    dmac_desc.BTCTRL.bit.VALID    = 1;  // Set dmac valid
 }
 
-void i2c_led_prepare_send_dma(uint8_t *data, uint8_t len)
-{
+void i2c_led_prepare_send_dma(uint8_t *data, uint8_t len) {
     i2c_led_desc_defaults();
 
-    dmac_desc.BTCNT.reg = len;
-    dmac_desc.SRCADDR.reg = (uint32_t)data + len;
-    dmac_desc.DSTADDR.reg = (uint32_t)&SERCOM1->I2CM.DATA.reg;
+    dmac_desc.BTCNT.reg    = len;
+    dmac_desc.SRCADDR.reg  = (uint32_t)data + len;
+    dmac_desc.DSTADDR.reg  = (uint32_t)&SERCOM1->I2CM.DATA.reg;
     dmac_desc.DESCADDR.reg = 0;
 }
 
-void i2c_led_begin_dma(uint8_t drvid)
-{
-    DMAC->Channel[0].CHCTRLA.bit.ENABLE = 1; //Enable the channel
+void i2c_led_begin_dma(uint8_t drvid) {
+    DMAC->Channel[0].CHCTRLA.bit.ENABLE = 1;  // Enable the channel
 
-    SERCOM1->I2CM.ADDR.reg = (dmac_desc.BTCNT.reg << 16) | 0x2000 | issidrv[drvid].addr; //Begin transfer
+    SERCOM1->I2CM.ADDR.reg = (dmac_desc.BTCNT.reg << 16) | 0x2000 | issidrv[drvid].addr;  // Begin transfer
 }
 
-void i2c_led_send_CRWL_dma(uint8_t drvid)
-{
-    *(dma_sendbuf+0) = ISSI3733_CMDRWL;
-    *(dma_sendbuf+1) = ISSI3733_CMDRWL_WRITE_ENABLE_ONCE;
+void i2c_led_send_CRWL_dma(uint8_t drvid) {
+    *(dma_sendbuf + 0) = ISSI3733_CMDRWL;
+    *(dma_sendbuf + 1) = ISSI3733_CMDRWL_WRITE_ENABLE_ONCE;
     i2c_led_prepare_send_dma(dma_sendbuf, 2);
 
     i2c_led_begin_dma(drvid);
 }
 
-void i2c_led_select_page_dma(uint8_t drvid, uint8_t pageno)
-{
-    *(dma_sendbuf+0) = ISSI3733_CMDR;
-    *(dma_sendbuf+1) = pageno;
+void i2c_led_select_page_dma(uint8_t drvid, uint8_t pageno) {
+    *(dma_sendbuf + 0) = ISSI3733_CMDR;
+    *(dma_sendbuf + 1) = pageno;
     i2c_led_prepare_send_dma(dma_sendbuf, 2);
 
     i2c_led_begin_dma(drvid);
 }
 
-void i2c_led_send_GCR_dma(uint8_t drvid)
-{
-    *(dma_sendbuf+0) = ISSI3733_GCCR;
-    *(dma_sendbuf+1) = gcr_actual;
+void i2c_led_send_GCR_dma(uint8_t drvid) {
+    *(dma_sendbuf + 0) = ISSI3733_GCCR;
+    *(dma_sendbuf + 1) = gcr_actual;
     i2c_led_prepare_send_dma(dma_sendbuf, 2);
 
     i2c_led_begin_dma(drvid);
 }
 
-void i2c_led_send_pwm_dma(uint8_t drvid)
-{
-    //Note: This copies the CURRENT pwm buffer, which may be getting modified
+void i2c_led_send_pwm_dma(uint8_t drvid) {
+    // Note: This copies the CURRENT pwm buffer, which may be getting modified
     memcpy(dma_sendbuf, issidrv[drvid].pwm, ISSI3733_PG1_BYTES);
-    *dma_sendbuf = 0; //Force start location offset to zero
+    *dma_sendbuf = 0;  // Force start location offset to zero
     i2c_led_prepare_send_dma(dma_sendbuf, ISSI3733_PG1_BYTES);
 
     i2c_led_begin_dma(drvid);
 }
 
-void i2c_led_send_onoff_dma(uint8_t drvid)
-{
-    //Note: This copies the CURRENT onoff buffer, which may be getting modified
+void i2c_led_send_onoff_dma(uint8_t drvid) {
+    // Note: This copies the CURRENT onoff buffer, which may be getting modified
     memcpy(dma_sendbuf, issidrv[drvid].onoff, ISSI3733_PG0_BYTES);
-    *dma_sendbuf = 0; //Force start location offset to zero
+    *dma_sendbuf = 0;  // Force start location offset to zero
     i2c_led_prepare_send_dma(dma_sendbuf, ISSI3733_PG0_BYTES);
 
     i2c_led_begin_dma(drvid);
 }
 
-void i2c_led_q_init(void)
-{
+void i2c_led_q_init(void) {
     memset(i2c_led_q, 0, I2C_Q_SIZE);
-    i2c_led_q_s = 0;
-    i2c_led_q_e = 0;
+    i2c_led_q_s       = 0;
+    i2c_led_q_e       = 0;
     i2c_led_q_running = 0;
-    i2c_led_q_full = 0;
+    i2c_led_q_full    = 0;
 }
 
-uint8_t i2c_led_q_isempty(void)
-{
-    return i2c_led_q_s == i2c_led_q_e;
-}
+uint8_t i2c_led_q_isempty(void) { return i2c_led_q_s == i2c_led_q_e; }
 
-uint8_t i2c_led_q_size(void)
-{
-    return (i2c_led_q_e - i2c_led_q_s) % I2C_Q_SIZE;
-}
+uint8_t i2c_led_q_size(void) { return (i2c_led_q_e - i2c_led_q_s) % I2C_Q_SIZE; }
 
-uint8_t i2c_led_q_available(void)
-{
-    return I2C_Q_SIZE - i2c_led_q_size() - 1; //Never allow end to meet start
+uint8_t i2c_led_q_available(void) {
+    return I2C_Q_SIZE - i2c_led_q_size() - 1;  // Never allow end to meet start
 }
 
-void i2c_led_q_add(uint8_t cmd)
-{
-    //WARNING: Always request room before adding commands!
+void i2c_led_q_add(uint8_t cmd) {
+    // WARNING: Always request room before adding commands!
 
-    //Assign command
+    // Assign command
     i2c_led_q[i2c_led_q_e] = cmd;
 
-    i2c_led_q_e = (i2c_led_q_e + 1) % I2C_Q_SIZE; //Move end up one or wrap
+    i2c_led_q_e = (i2c_led_q_e + 1) % I2C_Q_SIZE;  // Move end up one or wrap
 }
 
-void i2c_led_q_s_advance(void)
-{
-    i2c_led_q_s = (i2c_led_q_s + 1) % I2C_Q_SIZE; //Move start up one or wrap
+void i2c_led_q_s_advance(void) {
+    i2c_led_q_s = (i2c_led_q_s + 1) % I2C_Q_SIZE;  // Move start up one or wrap
 }
 
-//Always request room before adding commands
-//PS: In case the queue somehow gets filled, it will reset if it can not clear up
-//PS: Could only get this to happen through unrealistic timings to overload the I2C bus
-uint8_t i2c_led_q_request_room(uint8_t request_size)
-{
-    if (request_size > i2c_led_q_available())
-    {
+// Always request room before adding commands
+// PS: In case the queue somehow gets filled, it will reset if it can not clear up
+// PS: Could only get this to happen through unrealistic timings to overload the I2C bus
+uint8_t i2c_led_q_request_room(uint8_t request_size) {
+    if (request_size > i2c_led_q_available()) {
         i2c_led_q_full++;
 
-        if (i2c_led_q_full >= 100) //Give the queue a chance to clear up
+        if (i2c_led_q_full >= 100)  // Give the queue a chance to clear up
         {
             DBG_LED_ON;
             I2C_DMAC_LED_Init();
@@ -503,10 +493,8 @@ uint8_t i2c_led_q_request_room(uint8_t request_size)
     return 1;
 }
 
-uint8_t i2c_led_q_run(void)
-{
-    if (i2c_led_q_isempty())
-    {
+uint8_t i2c_led_q_run(void) {
+    if (i2c_led_q_isempty()) {
         i2c_led_q_running = 0;
         return 0;
     }
@@ -515,72 +503,62 @@ uint8_t i2c_led_q_run(void)
 
     i2c_led_q_running = 1;
 
-#if I2C_LED_USE_DMA != 1
-    while (!i2c_led_q_isempty())
-    {
-#endif
-        //run command
-        if (i2c_led_q[i2c_led_q_s] == I2C_Q_CRWL)
-        {
+#    if I2C_LED_USE_DMA != 1
+    while (!i2c_led_q_isempty()) {
+#    endif
+        // run command
+        if (i2c_led_q[i2c_led_q_s] == I2C_Q_CRWL) {
             i2c_led_q_s_advance();
             uint8_t drvid = i2c_led_q[i2c_led_q_s];
-#if I2C_LED_USE_DMA == 1
+#    if I2C_LED_USE_DMA == 1
             i2c_led_send_CRWL_dma(drvid);
-#else
-            i2c_led_send_CRWL(drvid);
-#endif
-        }
-        else if (i2c_led_q[i2c_led_q_s] == I2C_Q_PAGE_SELECT)
-        {
+#    else
+        i2c_led_send_CRWL(drvid);
+#    endif
+        } else if (i2c_led_q[i2c_led_q_s] == I2C_Q_PAGE_SELECT) {
             i2c_led_q_s_advance();
             uint8_t drvid = i2c_led_q[i2c_led_q_s];
             i2c_led_q_s_advance();
             uint8_t page = i2c_led_q[i2c_led_q_s];
-#if I2C_LED_USE_DMA == 1
+#    if I2C_LED_USE_DMA == 1
             i2c_led_select_page_dma(drvid, page);
-#else
-            i2c_led_select_page(drvid, page);
-#endif
-        }
-        else if (i2c_led_q[i2c_led_q_s] == I2C_Q_PWM)
-        {
+#    else
+        i2c_led_select_page(drvid, page);
+#    endif
+        } else if (i2c_led_q[i2c_led_q_s] == I2C_Q_PWM) {
             i2c_led_q_s_advance();
             uint8_t drvid = i2c_led_q[i2c_led_q_s];
-#if I2C_LED_USE_DMA == 1
+#    if I2C_LED_USE_DMA == 1
             i2c_led_send_pwm_dma(drvid);
-#else
-            i2c_led_send_pwm(drvid);
-#endif
-        }
-        else if (i2c_led_q[i2c_led_q_s] == I2C_Q_GCR)
-        {
+#    else
+        i2c_led_send_pwm(drvid);
+#    endif
+        } else if (i2c_led_q[i2c_led_q_s] == I2C_Q_GCR) {
             i2c_led_q_s_advance();
             uint8_t drvid = i2c_led_q[i2c_led_q_s];
-#if I2C_LED_USE_DMA == 1
+#    if I2C_LED_USE_DMA == 1
             i2c_led_send_GCR_dma(drvid);
-#else
-            i2c_led_send_GCR(drvid);
-#endif
-        }
-        else if (i2c_led_q[i2c_led_q_s] == I2C_Q_ONOFF)
-        {
+#    else
+        i2c_led_send_GCR(drvid);
+#    endif
+        } else if (i2c_led_q[i2c_led_q_s] == I2C_Q_ONOFF) {
             i2c_led_q_s_advance();
             uint8_t drvid = i2c_led_q[i2c_led_q_s];
-#if I2C_LED_USE_DMA == 1
+#    if I2C_LED_USE_DMA == 1
             i2c_led_send_onoff_dma(drvid);
-#else
-            i2c_led_send_onoff(drvid);
-#endif
+#    else
+        i2c_led_send_onoff(drvid);
+#    endif
         }
 
-        i2c_led_q_s_advance(); //Advance last run command or if the command byte was not serviced
+        i2c_led_q_s_advance();  // Advance last run command or if the command byte was not serviced
 
-#if I2C_LED_USE_DMA != 1
+#    if I2C_LED_USE_DMA != 1
     }
 
     i2c_led_q_running = 0;
-#endif
+#    endif
 
     return 1;
 }
-#endif // !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
+#endif  // !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
index 99481366a575f793ef629c030aea19836b8d4a86..44dbdfbffaaf18e92c55e027f9ef0234d1a5433d 100644 (file)
@@ -20,89 +20,85 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #ifndef MD_BOOTLOADER
 
-#include "samd51j18a.h"
-#include "issi3733_driver.h"
-#include "config.h"
+#    include "samd51j18a.h"
+#    include "issi3733_driver.h"
+#    include "config.h"
 
-__attribute__((__aligned__(16)))
-DmacDescriptor dmac_desc;
-__attribute__((__aligned__(16)))
-DmacDescriptor dmac_desc_wb;
+__attribute__((__aligned__(16))) DmacDescriptor dmac_desc;
+__attribute__((__aligned__(16))) DmacDescriptor dmac_desc_wb;
 
 uint8_t I2C3733_Init_Control(void);
 uint8_t I2C3733_Init_Drivers(void);
-void I2C3733_Control_Set(uint8_t state);
-void I2C_DMAC_LED_Init(void);
+void    I2C3733_Control_Set(uint8_t state);
+void    I2C_DMAC_LED_Init(void);
 
-#define I2C_Q_SIZE              100
+#    define I2C_Q_SIZE 100
 
-#define I2C_Q_NA                100
-#define I2C_Q_CRWL              101
-#define I2C_Q_PAGE_SELECT       102
-#define I2C_Q_PWM               103
-#define I2C_Q_GCR               104
-#define I2C_Q_ONOFF             105
+#    define I2C_Q_NA 100
+#    define I2C_Q_CRWL 101
+#    define I2C_Q_PAGE_SELECT 102
+#    define I2C_Q_PWM 103
+#    define I2C_Q_GCR 104
+#    define I2C_Q_ONOFF 105
 
-#define I2C_DMA_MAX_SEND        255
+#    define I2C_DMA_MAX_SEND 255
 
 extern volatile uint8_t i2c_led_q_running;
 
-#define I2C_LED_Q_PWM(a)    { \
-                                if (i2c_led_q_request_room(7)) \
-                                { \
-                                    i2c_led_q_add(I2C_Q_CRWL); \
-                                    i2c_led_q_add(a); \
-                                    i2c_led_q_add(I2C_Q_PAGE_SELECT); \
-                                    i2c_led_q_add(a); \
-                                    i2c_led_q_add(ISSI3733_PG_PWM); \
-                                    i2c_led_q_add(I2C_Q_PWM); \
-                                    i2c_led_q_add(a); \
-                                } \
-                            }
-
-#define I2C_LED_Q_GCR(a)    { \
-                                if (i2c_led_q_request_room(7)) \
-                                { \
-                                    i2c_led_q_add(I2C_Q_CRWL); \
-                                    i2c_led_q_add(a); \
-                                    i2c_led_q_add(I2C_Q_PAGE_SELECT); \
-                                    i2c_led_q_add(a); \
-                                    i2c_led_q_add(ISSI3733_PG_FN); \
-                                    i2c_led_q_add(I2C_Q_GCR); \
-                                    i2c_led_q_add(a); \
-                                } \
-                            }
-
-#define I2C_LED_Q_ONOFF(a)  { \
-                                if (i2c_led_q_request_room(7)) \
-                                { \
-                                    i2c_led_q_add(I2C_Q_CRWL); \
-                                    i2c_led_q_add(a); \
-                                    i2c_led_q_add(I2C_Q_PAGE_SELECT); \
-                                    i2c_led_q_add(a); \
-                                    i2c_led_q_add(ISSI3733_PG_ONOFF); \
-                                    i2c_led_q_add(I2C_Q_ONOFF); \
-                                    i2c_led_q_add(a); \
-                                } \
-                            }
-
-
-void i2c_led_q_init(void);
-void i2c_led_q_add(uint8_t cmd);
-void i2c_led_q_s_advance(void);
+#    define I2C_LED_Q_PWM(a)                      \
+        {                                         \
+            if (i2c_led_q_request_room(7)) {      \
+                i2c_led_q_add(I2C_Q_CRWL);        \
+                i2c_led_q_add(a);                 \
+                i2c_led_q_add(I2C_Q_PAGE_SELECT); \
+                i2c_led_q_add(a);                 \
+                i2c_led_q_add(ISSI3733_PG_PWM);   \
+                i2c_led_q_add(I2C_Q_PWM);         \
+                i2c_led_q_add(a);                 \
+            }                                     \
+        }
+
+#    define I2C_LED_Q_GCR(a)                      \
+        {                                         \
+            if (i2c_led_q_request_room(7)) {      \
+                i2c_led_q_add(I2C_Q_CRWL);        \
+                i2c_led_q_add(a);                 \
+                i2c_led_q_add(I2C_Q_PAGE_SELECT); \
+                i2c_led_q_add(a);                 \
+                i2c_led_q_add(ISSI3733_PG_FN);    \
+                i2c_led_q_add(I2C_Q_GCR);         \
+                i2c_led_q_add(a);                 \
+            }                                     \
+        }
+
+#    define I2C_LED_Q_ONOFF(a)                    \
+        {                                         \
+            if (i2c_led_q_request_room(7)) {      \
+                i2c_led_q_add(I2C_Q_CRWL);        \
+                i2c_led_q_add(a);                 \
+                i2c_led_q_add(I2C_Q_PAGE_SELECT); \
+                i2c_led_q_add(a);                 \
+                i2c_led_q_add(ISSI3733_PG_ONOFF); \
+                i2c_led_q_add(I2C_Q_ONOFF);       \
+                i2c_led_q_add(a);                 \
+            }                                     \
+        }
+
+void    i2c_led_q_init(void);
+void    i2c_led_q_add(uint8_t cmd);
+void    i2c_led_q_s_advance(void);
 uint8_t i2c_led_q_size(void);
 uint8_t i2c_led_q_request_room(uint8_t request_size);
 uint8_t i2c_led_q_run(void);
 
-void i2c1_init(void);
+void    i2c1_init(void);
 uint8_t i2c1_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout);
-void i2c1_stop(void);
+void    i2c1_stop(void);
 
-#endif //MD_BOOTLOADER
+#endif  // MD_BOOTLOADER
 
-void i2c0_init(void);
+void    i2c0_init(void);
 uint8_t i2c0_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout);
-void i2c0_stop(void);
-
-#endif // _I2C_MASTER_H_
+void    i2c0_stop(void);
 
+#endif  // _I2C_MASTER_H_
index a537029f0ea15428756a8486fb48da2a4e158f83..bd29fe76b6b54d208a35941881a6576b8d54f020 100644 (file)
@@ -18,31 +18,31 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef _ISSI3733_DRIVER_H_
 #define _ISSI3733_DRIVER_H_
 
-//ISII3733 Registers
+// ISII3733 Registers
 
-#define ISSI3733_CMDR 0xFD                      //Command Register (Write Only)
+#define ISSI3733_CMDR 0xFD  // Command Register (Write Only)
 
-#define ISSI3733_CMDRWL 0xFE                    //Command Register Write Lock (Read/Write)
-#define ISSI3733_CMDRWL_WRITE_DISABLE 0x00      //Lock register
-#define ISSI3733_CMDRWL_WRITE_ENABLE_ONCE 0xC5  //Enable one write to register then reset to locked
+#define ISSI3733_CMDRWL 0xFE                    // Command Register Write Lock (Read/Write)
+#define ISSI3733_CMDRWL_WRITE_DISABLE 0x00      // Lock register
+#define ISSI3733_CMDRWL_WRITE_ENABLE_ONCE 0xC5  // Enable one write to register then reset to locked
 
-#define ISSI3733_IMR 0xF0                       //Interrupt Mask Register (Write Only)
-#define ISSI3733_IMR_IAC_ON 0x08                //Auto Clear Interrupt Bit - Interrupt auto clear when INTB stay low exceeds 8ms
-#define ISSI3733_IMR_IAB_ON 0x04                //Auto Breath Interrupt Bit - Enable auto breath loop finish interrupt
-#define ISSI3733_IMR_IS_ON 0x02                 //Dot Short Interrupt Bit - Enable dot short interrupt
-#define ISSI3733_IMR_IO_ON 0x01                 //Dot Open Interrupt Bit - Enable dot open interrupt
+#define ISSI3733_IMR 0xF0         // Interrupt Mask Register (Write Only)
+#define ISSI3733_IMR_IAC_ON 0x08  // Auto Clear Interrupt Bit - Interrupt auto clear when INTB stay low exceeds 8ms
+#define ISSI3733_IMR_IAB_ON 0x04  // Auto Breath Interrupt Bit - Enable auto breath loop finish interrupt
+#define ISSI3733_IMR_IS_ON 0x02   // Dot Short Interrupt Bit - Enable dot short interrupt
+#define ISSI3733_IMR_IO_ON 0x01   // Dot Open Interrupt Bit - Enable dot open interrupt
 
-#define ISSI3733_ISR 0xF1                       //Interrupt Status Register (Read Only)
-#define ISSI3733_ISR_ABM3_FINISH 0x10           //Auto Breath Mode 3 Finish Bit - ABM3 finished
-#define ISSI3733_ISR_ABM2_FINISH 0x08           //Auto Breath Mode 2 Finish Bit - ABM2 finished
-#define ISSI3733_ISR_ABM1_FINISH 0x04           //Auto Breath Mode 1 Finish Bit - ABM1 finished
-#define ISSI3733_ISR_SB 0x02                    //Short Bit - Shorted
-#define ISSI3733_ISR_OB 0x01                    //Open Bit - Opened
+#define ISSI3733_ISR 0xF1              // Interrupt Status Register (Read Only)
+#define ISSI3733_ISR_ABM3_FINISH 0x10  // Auto Breath Mode 3 Finish Bit - ABM3 finished
+#define ISSI3733_ISR_ABM2_FINISH 0x08  // Auto Breath Mode 2 Finish Bit - ABM2 finished
+#define ISSI3733_ISR_ABM1_FINISH 0x04  // Auto Breath Mode 1 Finish Bit - ABM1 finished
+#define ISSI3733_ISR_SB 0x02           // Short Bit - Shorted
+#define ISSI3733_ISR_OB 0x01           // Open Bit - Opened
 
-#define ISSI3733_PG0 0x00                       //LED Control Register
-#define ISSI3733_PG1 0x01                       //PWM Register
-#define ISSI3733_PG2 0x02                       //Auto Breath Mode Register
-#define ISSI3733_PG3 0x03                       //Function Register
+#define ISSI3733_PG0 0x00  // LED Control Register
+#define ISSI3733_PG1 0x01  // PWM Register
+#define ISSI3733_PG2 0x02  // Auto Breath Mode Register
+#define ISSI3733_PG3 0x03  // Function Register
 
 #define ISSI3733_PG_ONOFF ISSI3733_PG0
 #define ISSI3733_PG_OR ISSI3733_PG0
@@ -51,88 +51,88 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define ISSI3733_PG_ABM ISSI3733_PG2
 #define ISSI3733_PG_FN ISSI3733_PG3
 
-#define ISSI3733_CR 0x00                        //Configuration Register
+#define ISSI3733_CR 0x00  // Configuration Register
 
-//PG3: Configuration Register: Synchronize Configuration
-#define ISSI3733_CR_SYNC_MASTER 0x40            //Master
-#define ISSI3733_CR_SYNC_SLAVE 0x80             //Slave
-#define ISSI3733_CR_SYNC_HIGH_IMP 0xC0          //High Impedance
+// PG3: Configuration Register: Synchronize Configuration
+#define ISSI3733_CR_SYNC_MASTER 0x40    // Master
+#define ISSI3733_CR_SYNC_SLAVE 0x80     // Slave
+#define ISSI3733_CR_SYNC_HIGH_IMP 0xC0  // High Impedance
 
-//PG3: Configuration Register: Open/Short Detection Enable Bit
+// PG3: Configuration Register: Open/Short Detection Enable Bit
 //#define ISSI3733_CR_OSD_DISABLE 0x00          //Disable open/short detection
-#define ISSI3733_CR_OSD_ENABLE 0x04             //Enable open/short detection
+#define ISSI3733_CR_OSD_ENABLE 0x04  // Enable open/short detection
 
-//PG3: Configuration Register: Auto Breath Enable
+// PG3: Configuration Register: Auto Breath Enable
 //#define ISSI3733_CR_B_EN_PWM 0x00             //PWM Mode Enable
-#define ISSI3733_CR_B_EN_AUTO 0x02              //Auto Breath Mode Enable
+#define ISSI3733_CR_B_EN_AUTO 0x02  // Auto Breath Mode Enable
 
-//PG3: Configuration Register: Software Shutdown Control
+// PG3: Configuration Register: Software Shutdown Control
 //#define ISSI3733_CR_SSD_SHUTDOWN 0x00         //Software shutdown
-#define ISSI3733_CR_SSD_NORMAL 0x01             //Normal operation
-
-#define ISSI3733_GCCR 0x01              //Global Current Control Register
-
-//1 Byte, Iout = (GCC / 256) * (840 / Rext)
-//TODO: Give user define for Rext
-
-//PG3: Auto Breath Control Register 1
-#define ISSI3733_ABCR1_ABM1 0x02        //Auto Breath Control Register 1 of ABM-1
-#define ISSI3733_ABCR1_ABM2 0x06        //Auto Breath Control Register 1 of ABM-2
-#define ISSI3733_ABCR1_ABM3 0x0A        //Auto Breath Control Register 1 of ABM-3
-
-//Rise time
-#define ISSI3733_ABCR1_T1_0021 0x00     //0.21s
-#define ISSI3733_ABCR1_T1_0042 0x20     //0.42s
-#define ISSI3733_ABCR1_T1_0084 0x40     //0.84s
-#define ISSI3733_ABCR1_T1_0168 0x60     //1.68s
-#define ISSI3733_ABCR1_T1_0336 0x80     //3.36s
-#define ISSI3733_ABCR1_T1_0672 0xA0     //6.72s
-#define ISSI3733_ABCR1_T1_1344 0xC0     //13.44s
-#define ISSI3733_ABCR1_T1_2688 0xE0     //26.88s
-
-//Max value time
-#define ISSI3733_ABCR1_T2_0000 0x00     //0s
-#define ISSI3733_ABCR1_T2_0021 0x02     //0.21s
-#define ISSI3733_ABCR1_T2_0042 0x04     //0.42s
-#define ISSI3733_ABCR1_T2_0084 0x06     //0.84s
-#define ISSI3733_ABCR1_T2_0168 0x08     //1.68s
-#define ISSI3733_ABCR1_T2_0336 0x0A     //3.36s
-#define ISSI3733_ABCR1_T2_0672 0x0C     //6.72s
-#define ISSI3733_ABCR1_T2_1344 0x0E     //13.44s
-#define ISSI3733_ABCR1_T2_2688 0x10     //26.88s
-
-//PG3: Auto Breath Control Register 2
-#define ISSI3733_ABCR2_ABM1 0x03        //Auto Breath Control Register 2 of ABM-1
-#define ISSI3733_ABCR2_ABM2 0x07        //Auto Breath Control Register 2 of ABM-2
-#define ISSI3733_ABCR2_ABM3 0x0B        //Auto Breath Control Register 2 of ABM-3
-
-//Fall time
-#define ISSI3733_ABCR2_T3_0021 0x00     //0.21s
-#define ISSI3733_ABCR2_T3_0042 0x20     //0.42s
-#define ISSI3733_ABCR2_T3_0084 0x40     //0.84s
-#define ISSI3733_ABCR2_T3_0168 0x60     //1.68s
-#define ISSI3733_ABCR2_T3_0336 0x80     //3.36s
-#define ISSI3733_ABCR2_T3_0672 0xA0     //6.72s
-#define ISSI3733_ABCR2_T3_1344 0xC0     //13.44s
-#define ISSI3733_ABCR2_T3_2688 0xE0     //26.88s
-
-//Min value time
-#define ISSI3733_ABCR2_T4_0000 0x00     //0s
-#define ISSI3733_ABCR2_T4_0021 0x02     //0.21s
-#define ISSI3733_ABCR2_T4_0042 0x04     //0.42s
-#define ISSI3733_ABCR2_T4_0084 0x06     //0.84s
-#define ISSI3733_ABCR2_T4_0168 0x08     //1.68s
-#define ISSI3733_ABCR2_T4_0336 0x0A     //3.36s
-#define ISSI3733_ABCR2_T4_0672 0x0C     //6.72s
-#define ISSI3733_ABCR2_T4_1344 0x0E     //13.44s
-#define ISSI3733_ABCR2_T4_2688 0x10     //26.88s
-#define ISSI3733_ABCR2_T4_5376 0x12     //53.76s
-#define ISSI3733_ABCR2_T4_10752 0x14    //107.52s
-
-//PG3: Auto Breath Control Register 3
-#define ISSI3733_ABCR3_ABM1 0x04        //Auto Breath Control Register 3 of ABM-1
-#define ISSI3733_ABCR3_ABM2 0x08        //Auto Breath Control Register 3 of ABM-2
-#define ISSI3733_ABCR3_ABM3 0x0C        //Auto Breath Control Register 3 of ABM-3
+#define ISSI3733_CR_SSD_NORMAL 0x01  // Normal operation
+
+#define ISSI3733_GCCR 0x01  // Global Current Control Register
+
+// 1 Byte, Iout = (GCC / 256) * (840 / Rext)
+// TODO: Give user define for Rext
+
+// PG3: Auto Breath Control Register 1
+#define ISSI3733_ABCR1_ABM1 0x02  // Auto Breath Control Register 1 of ABM-1
+#define ISSI3733_ABCR1_ABM2 0x06  // Auto Breath Control Register 1 of ABM-2
+#define ISSI3733_ABCR1_ABM3 0x0A  // Auto Breath Control Register 1 of ABM-3
+
+// Rise time
+#define ISSI3733_ABCR1_T1_0021 0x00  // 0.21s
+#define ISSI3733_ABCR1_T1_0042 0x20  // 0.42s
+#define ISSI3733_ABCR1_T1_0084 0x40  // 0.84s
+#define ISSI3733_ABCR1_T1_0168 0x60  // 1.68s
+#define ISSI3733_ABCR1_T1_0336 0x80  // 3.36s
+#define ISSI3733_ABCR1_T1_0672 0xA0  // 6.72s
+#define ISSI3733_ABCR1_T1_1344 0xC0  // 13.44s
+#define ISSI3733_ABCR1_T1_2688 0xE0  // 26.88s
+
+// Max value time
+#define ISSI3733_ABCR1_T2_0000 0x00  // 0s
+#define ISSI3733_ABCR1_T2_0021 0x02  // 0.21s
+#define ISSI3733_ABCR1_T2_0042 0x04  // 0.42s
+#define ISSI3733_ABCR1_T2_0084 0x06  // 0.84s
+#define ISSI3733_ABCR1_T2_0168 0x08  // 1.68s
+#define ISSI3733_ABCR1_T2_0336 0x0A  // 3.36s
+#define ISSI3733_ABCR1_T2_0672 0x0C  // 6.72s
+#define ISSI3733_ABCR1_T2_1344 0x0E  // 13.44s
+#define ISSI3733_ABCR1_T2_2688 0x10  // 26.88s
+
+// PG3: Auto Breath Control Register 2
+#define ISSI3733_ABCR2_ABM1 0x03  // Auto Breath Control Register 2 of ABM-1
+#define ISSI3733_ABCR2_ABM2 0x07  // Auto Breath Control Register 2 of ABM-2
+#define ISSI3733_ABCR2_ABM3 0x0B  // Auto Breath Control Register 2 of ABM-3
+
+// Fall time
+#define ISSI3733_ABCR2_T3_0021 0x00  // 0.21s
+#define ISSI3733_ABCR2_T3_0042 0x20  // 0.42s
+#define ISSI3733_ABCR2_T3_0084 0x40  // 0.84s
+#define ISSI3733_ABCR2_T3_0168 0x60  // 1.68s
+#define ISSI3733_ABCR2_T3_0336 0x80  // 3.36s
+#define ISSI3733_ABCR2_T3_0672 0xA0  // 6.72s
+#define ISSI3733_ABCR2_T3_1344 0xC0  // 13.44s
+#define ISSI3733_ABCR2_T3_2688 0xE0  // 26.88s
+
+// Min value time
+#define ISSI3733_ABCR2_T4_0000 0x00   // 0s
+#define ISSI3733_ABCR2_T4_0021 0x02   // 0.21s
+#define ISSI3733_ABCR2_T4_0042 0x04   // 0.42s
+#define ISSI3733_ABCR2_T4_0084 0x06   // 0.84s
+#define ISSI3733_ABCR2_T4_0168 0x08   // 1.68s
+#define ISSI3733_ABCR2_T4_0336 0x0A   // 3.36s
+#define ISSI3733_ABCR2_T4_0672 0x0C   // 6.72s
+#define ISSI3733_ABCR2_T4_1344 0x0E   // 13.44s
+#define ISSI3733_ABCR2_T4_2688 0x10   // 26.88s
+#define ISSI3733_ABCR2_T4_5376 0x12   // 53.76s
+#define ISSI3733_ABCR2_T4_10752 0x14  // 107.52s
+
+// PG3: Auto Breath Control Register 3
+#define ISSI3733_ABCR3_ABM1 0x04  // Auto Breath Control Register 3 of ABM-1
+#define ISSI3733_ABCR3_ABM2 0x08  // Auto Breath Control Register 3 of ABM-2
+#define ISSI3733_ABCR3_ABM3 0x0C  // Auto Breath Control Register 3 of ABM-3
 
 #define ISSI3733_ABCR3_LTA_LOOP_ENDLESS 0x00
 #define ISSI3733_ABCR3_LTA_LOOP_1 0x01
@@ -151,51 +151,51 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define ISSI3733_ABCR3_LTA_LOOP_14 0x0E
 #define ISSI3733_ABCR3_LTA_LOOP_15 0x0F
 
-//Loop Begin
+// Loop Begin
 #define ISSI3733_ABCR3_LB_T1 0x00
 #define ISSI3733_ABCR3_LB_T2 0x10
 #define ISSI3733_ABCR3_LB_T3 0x20
 #define ISSI3733_ABCR3_LB_T4 0x30
 
-//Loop End
-#define ISSI3733_ABCR3_LE_T3 0x00       //End at Off state
-#define ISSI3733_ABCR3_LE_T1 0x40       //End at On State
+// Loop End
+#define ISSI3733_ABCR3_LE_T3 0x00  // End at Off state
+#define ISSI3733_ABCR3_LE_T1 0x40  // End at On State
 
-//PG3: Auto Breath Control Register 4
-#define ISSI3733_ABCR4_ABM1 0x05        //Auto Breath Control Register 4 of ABM-1
-#define ISSI3733_ABCR4_ABM2 0x09        //Auto Breath Control Register 4 of ABM-2
-#define ISSI3733_ABCR4_ABM3 0x0D        //Auto Breath Control Register 4 of ABM-3
+// PG3: Auto Breath Control Register 4
+#define ISSI3733_ABCR4_ABM1 0x05  // Auto Breath Control Register 4 of ABM-1
+#define ISSI3733_ABCR4_ABM2 0x09  // Auto Breath Control Register 4 of ABM-2
+#define ISSI3733_ABCR4_ABM3 0x0D  // Auto Breath Control Register 4 of ABM-3
 
 #define ISSI3733_ABCR4_LTB_LOOP_ENDLESS 0x00
-//Or 8bit loop times
+// Or 8bit loop times
 
-//PG3: Time Update Register
+// PG3: Time Update Register
 #define ISSI3733_TUR 0x0E
-#define ISSI3733_TUR_UPDATE 0x00        //Write to update 02h~0Dh time registers after configuring
+#define ISSI3733_TUR_UPDATE 0x00  // Write to update 02h~0Dh time registers after configuring
 
-//PG3: SWy Pull-Up Resistor Selection Register
+// PG3: SWy Pull-Up Resistor Selection Register
 #define ISSI3733_SWYR_PUR 0x0F
-#define ISSI3733_SWYR_PUR_NONE 0x00     //No pull-up resistor
-#define ISSI3733_SWYR_PUR_500 0x01      //0.5k Ohm
-#define ISSI3733_SWYR_PUR_1000 0x02     //1.0k Ohm
-#define ISSI3733_SWYR_PUR_2000 0x03     //2.0k Ohm
-#define ISSI3733_SWYR_PUR_4000 0x04     //4.0k Ohm
-#define ISSI3733_SWYR_PUR_8000 0x05     //8.0k Ohm
-#define ISSI3733_SWYR_PUR_16000 0x06    //16k Ohm
-#define ISSI3733_SWYR_PUR_32000 0x07    //32k Ohm
-
-//PG3: CSx Pull-Down Resistor Selection Register
+#define ISSI3733_SWYR_PUR_NONE 0x00   // No pull-up resistor
+#define ISSI3733_SWYR_PUR_500 0x01    // 0.5k Ohm
+#define ISSI3733_SWYR_PUR_1000 0x02   // 1.0k Ohm
+#define ISSI3733_SWYR_PUR_2000 0x03   // 2.0k Ohm
+#define ISSI3733_SWYR_PUR_4000 0x04   // 4.0k Ohm
+#define ISSI3733_SWYR_PUR_8000 0x05   // 8.0k Ohm
+#define ISSI3733_SWYR_PUR_16000 0x06  // 16k Ohm
+#define ISSI3733_SWYR_PUR_32000 0x07  // 32k Ohm
+
+// PG3: CSx Pull-Down Resistor Selection Register
 #define ISSI3733_CSXR_PDR 0x10
-#define ISSI3733_CSXR_PDR_NONE 0x00     //No pull-down resistor
-#define ISSI3733_CSXR_PDR_500 0x01      //0.5k Ohm
-#define ISSI3733_CSXR_PDR_1000 0x02     //1.0k Ohm
-#define ISSI3733_CSXR_PDR_2000 0x03     //2.0k Ohm
-#define ISSI3733_CSXR_PDR_4000 0x04     //4.0k Ohm
-#define ISSI3733_CSXR_PDR_8000 0x05     //8.0k Ohm
-#define ISSI3733_CSXR_PDR_16000 0x06    //16k Ohm
-#define ISSI3733_CSXR_PDR_32000 0x07    //32k Ohm
-
-//PG3: Reset Register
-#define ISSI3733_RR 0x11                //Read to reset all registers to default values
-
-#endif //_ISSI3733_DRIVER_H_
+#define ISSI3733_CSXR_PDR_NONE 0x00   // No pull-down resistor
+#define ISSI3733_CSXR_PDR_500 0x01    // 0.5k Ohm
+#define ISSI3733_CSXR_PDR_1000 0x02   // 1.0k Ohm
+#define ISSI3733_CSXR_PDR_2000 0x03   // 2.0k Ohm
+#define ISSI3733_CSXR_PDR_4000 0x04   // 4.0k Ohm
+#define ISSI3733_CSXR_PDR_8000 0x05   // 8.0k Ohm
+#define ISSI3733_CSXR_PDR_16000 0x06  // 16k Ohm
+#define ISSI3733_CSXR_PDR_32000 0x07  // 32k Ohm
+
+// PG3: Reset Register
+#define ISSI3733_RR 0x11  // Read to reset all registers to default values
+
+#endif  //_ISSI3733_DRIVER_H_
index 42dfccbc50f04405326c53941e209c30e299bfcc..c078980d681a2a36d1ca79efa5b0e53769e38b42 100644 (file)
@@ -22,24 +22,18 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <math.h>
 
 #ifdef USE_MASSDROP_CONFIGURATOR
-__attribute__((weak))
-led_instruction_t led_instructions[] = { { .end = 1 } };
-static void led_matrix_massdrop_config_override(int i);
-#endif // USE_MASSDROP_CONFIGURATOR
+__attribute__((weak)) led_instruction_t led_instructions[] = {{.end = 1}};
+static void                             led_matrix_massdrop_config_override(int i);
+#endif  // USE_MASSDROP_CONFIGURATOR
 
-
-void SERCOM1_0_Handler( void )
-{
-    if (SERCOM1->I2CM.INTFLAG.bit.ERROR)
-    {
+void SERCOM1_0_Handler(void) {
+    if (SERCOM1->I2CM.INTFLAG.bit.ERROR) {
         SERCOM1->I2CM.INTFLAG.reg = SERCOM_I2CM_INTENCLR_ERROR;
     }
 }
 
-void DMAC_0_Handler( void )
-{
-    if (DMAC->Channel[0].CHINTFLAG.bit.TCMPL)
-    {
+void DMAC_0_Handler(void) {
+    if (DMAC->Channel[0].CHINTFLAG.bit.TCMPL) {
         DMAC->Channel[0].CHINTFLAG.reg = DMAC_CHINTENCLR_TCMPL;
 
         i2c1_stop();
@@ -51,8 +45,7 @@ void DMAC_0_Handler( void )
         return;
     }
 
-    if (DMAC->Channel[0].CHINTFLAG.bit.TERR)
-    {
+    if (DMAC->Channel[0].CHINTFLAG.bit.TERR) {
         DMAC->Channel[0].CHINTFLAG.reg = DMAC_CHINTENCLR_TERR;
     }
 }
@@ -60,118 +53,109 @@ void DMAC_0_Handler( void )
 issi3733_driver_t issidrv[ISSI3733_DRIVER_COUNT];
 
 issi3733_led_t led_map[ISSI3733_LED_COUNT] = ISSI3733_LED_MAP;
-RGB led_buffer[ISSI3733_LED_COUNT];
+RGB            led_buffer[ISSI3733_LED_COUNT];
 
 uint8_t gcr_desired;
 uint8_t gcr_actual;
 uint8_t gcr_actual_last;
 #ifdef USE_MASSDROP_CONFIGURATOR
 uint8_t gcr_breathe;
-float breathe_mult;
-float pomod;
+float   breathe_mult;
+float   pomod;
 #endif
 
-#define ACT_GCR_NONE    0
-#define ACT_GCR_INC     1
-#define ACT_GCR_DEC     2
+#define ACT_GCR_NONE 0
+#define ACT_GCR_INC 1
+#define ACT_GCR_DEC 2
 
 #define LED_GCR_STEP_AUTO 2
 
 static uint8_t gcr_min_counter;
 static uint8_t v_5v_cat_hit;
 
-//WARNING: Automatic GCR is in place to prevent USB shutdown and LED driver overloading
-void gcr_compute(void)
-{
-    uint8_t action = ACT_GCR_NONE;
+// WARNING: Automatic GCR is in place to prevent USB shutdown and LED driver overloading
+void gcr_compute(void) {
+    uint8_t action  = ACT_GCR_NONE;
     uint8_t gcr_use = gcr_desired;
 
 #ifdef USE_MASSDROP_CONFIGURATOR
-    if (led_animation_breathing)
-    {
+    if (led_animation_breathing) {
         gcr_use = gcr_breathe;
     }
 #endif
 
-    //If the 5v takes a catastrophic hit, disable the LED drivers briefly, assert auto gcr mode, min gcr and let the auto take over
-    if (v_5v < V5_CAT)
-    {
+    // If the 5v takes a catastrophic hit, disable the LED drivers briefly, assert auto gcr mode, min gcr and let the auto take over
+    if (v_5v < V5_CAT) {
         I2C3733_Control_Set(0);
-        //CDC_print("USB: WARNING: 5V catastrophic level reached! Disabling LED drivers!\r\n"); //Blocking print is bad here!
-        v_5v_cat_hit = 20; //~100ms recover
-        gcr_actual = 0; //Minimize GCR
-        usb_gcr_auto = 1; //Force auto mode enabled
+        // CDC_print("USB: WARNING: 5V catastrophic level reached! Disabling LED drivers!\r\n"); //Blocking print is bad here!
+        v_5v_cat_hit = 20;  //~100ms recover
+        gcr_actual   = 0;   // Minimize GCR
+        usb_gcr_auto = 1;   // Force auto mode enabled
         return;
-    }
-    else if (v_5v_cat_hit > 1)
-    {
+    } else if (v_5v_cat_hit > 1) {
         v_5v_cat_hit--;
         return;
-    }
-    else if (v_5v_cat_hit == 1)
-    {
+    } else if (v_5v_cat_hit == 1) {
         I2C3733_Control_Set(1);
         CDC_print("USB: WARNING: Re-enabling LED drivers\r\n");
         v_5v_cat_hit = 0;
         return;
     }
 
-    if (usb_gcr_auto)
-    {
-        if (v_5v_avg < V5_LOW) action = ACT_GCR_DEC;
-        else if (v_5v_avg > V5_HIGH && gcr_actual < gcr_use) action = ACT_GCR_INC;
-        else if (gcr_actual > gcr_use) action = ACT_GCR_DEC;
-    }
-    else
-    {
-        if (gcr_actual < gcr_use) action = ACT_GCR_INC;
-        else if (gcr_actual > gcr_use) action = ACT_GCR_DEC;
+    if (usb_gcr_auto) {
+        if (v_5v_avg < V5_LOW)
+            action = ACT_GCR_DEC;
+        else if (v_5v_avg > V5_HIGH && gcr_actual < gcr_use)
+            action = ACT_GCR_INC;
+        else if (gcr_actual > gcr_use)
+            action = ACT_GCR_DEC;
+    } else {
+        if (gcr_actual < gcr_use)
+            action = ACT_GCR_INC;
+        else if (gcr_actual > gcr_use)
+            action = ACT_GCR_DEC;
     }
 
-    if (action == ACT_GCR_NONE)
-    {
+    if (action == ACT_GCR_NONE) {
         gcr_min_counter = 0;
-    }
-    else if (action == ACT_GCR_INC)
-    {
-        if (LED_GCR_STEP_AUTO > LED_GCR_MAX - gcr_actual) gcr_actual = LED_GCR_MAX; //Obey max and prevent wrapping
-        else gcr_actual += LED_GCR_STEP_AUTO;
+    } else if (action == ACT_GCR_INC) {
+        if (LED_GCR_STEP_AUTO > LED_GCR_MAX - gcr_actual)
+            gcr_actual = LED_GCR_MAX;  // Obey max and prevent wrapping
+        else
+            gcr_actual += LED_GCR_STEP_AUTO;
         gcr_min_counter = 0;
-    }
-    else if (action == ACT_GCR_DEC)
-    {
-        if (LED_GCR_STEP_AUTO > gcr_actual) //Prevent wrapping
+    } else if (action == ACT_GCR_DEC) {
+        if (LED_GCR_STEP_AUTO > gcr_actual)  // Prevent wrapping
         {
             gcr_actual = 0;
-            //At this point, power can no longer be cut from the LED drivers, so focus on cutting out extra port if active
-            if (usb_extra_state != USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG) //If not in a wait for replug state
+            // At this point, power can no longer be cut from the LED drivers, so focus on cutting out extra port if active
+            if (usb_extra_state != USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG)  // If not in a wait for replug state
             {
-                if (usb_extra_state == USB_EXTRA_STATE_ENABLED) //If extra usb is enabled
+                if (usb_extra_state == USB_EXTRA_STATE_ENABLED)  // If extra usb is enabled
                 {
                     gcr_min_counter++;
-                    if (gcr_min_counter > 200) //5ms per check = 1s delay
+                    if (gcr_min_counter > 200)  // 5ms per check = 1s delay
                     {
                         USB_ExtraSetState(USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG);
-                        usb_extra_manual = 0; //Force disable manual mode of extra port
-                        if (usb_extra_manual) CDC_print("USB: Disabling extra port until replug and manual mode toggle!\r\n");
-                        else CDC_print("USB: Disabling extra port until replug!\r\n");
+                        usb_extra_manual = 0;  // Force disable manual mode of extra port
+                        if (usb_extra_manual)
+                            CDC_print("USB: Disabling extra port until replug and manual mode toggle!\r\n");
+                        else
+                            CDC_print("USB: Disabling extra port until replug!\r\n");
                     }
                 }
             }
-        }
-        else
-        {
-            //Power successfully cut back from LED drivers
+        } else {
+            // Power successfully cut back from LED drivers
             gcr_actual -= LED_GCR_STEP_AUTO;
             gcr_min_counter = 0;
 
 #ifdef USE_MASSDROP_CONFIGURATOR
-            //If breathe mode is active, the top end can fluctuate if the host can not supply enough current
-            //So set the breathe GCR to where it becomes stable
-            if (led_animation_breathing == 1)
-            {
+            // If breathe mode is active, the top end can fluctuate if the host can not supply enough current
+            // So set the breathe GCR to where it becomes stable
+            if (led_animation_breathing == 1) {
                 gcr_breathe = gcr_actual;
-                //PS: At this point, setting breathing to exhale makes a noticebly shorter cycle
+                // PS: At this point, setting breathing to exhale makes a noticebly shorter cycle
                 //    and the same would happen maybe one or two more times. Therefore I'm favoring
                 //    powering through one full breathe and letting gcr settle completely
             }
@@ -180,47 +164,40 @@ void gcr_compute(void)
     }
 }
 
-void issi3733_prepare_arrays(void)
-{
-    memset(issidrv,0,sizeof(issi3733_driver_t) * ISSI3733_DRIVER_COUNT);
+void issi3733_prepare_arrays(void) {
+    memset(issidrv, 0, sizeof(issi3733_driver_t) * ISSI3733_DRIVER_COUNT);
 
-    int i;
+    int     i;
     uint8_t addrs[ISSI3733_DRIVER_COUNT] = ISSI3773_DRIVER_ADDRESSES;
 
-    for (i=0;i<ISSI3733_DRIVER_COUNT;i++)
-    {
+    for (i = 0; i < ISSI3733_DRIVER_COUNT; i++) {
         issidrv[i].addr = addrs[i];
     }
 
-    for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++)
-    {
-        //BYTE: 1 + (SW-1)*16 + (CS-1)
-        led_map[i].rgb.g = issidrv[led_map[i].adr.drv-1].pwm + 1 + ((led_map[i].adr.swg-1)*16 + (led_map[i].adr.cs-1));
-        led_map[i].rgb.r = issidrv[led_map[i].adr.drv-1].pwm + 1 + ((led_map[i].adr.swr-1)*16 + (led_map[i].adr.cs-1));
-        led_map[i].rgb.b = issidrv[led_map[i].adr.drv-1].pwm + 1 + ((led_map[i].adr.swb-1)*16 + (led_map[i].adr.cs-1));
-
-        //BYTE: 1 + (SW-1)*2 + (CS-1)/8
-        //BIT: (CS-1)%8
-        *(issidrv[led_map[i].adr.drv-1].onoff + 1 + (led_map[i].adr.swg-1)*2+(led_map[i].adr.cs-1)/8) |= (1<<((led_map[i].adr.cs-1)%8));
-        *(issidrv[led_map[i].adr.drv-1].onoff + 1 + (led_map[i].adr.swr-1)*2+(led_map[i].adr.cs-1)/8) |= (1<<((led_map[i].adr.cs-1)%8));
-        *(issidrv[led_map[i].adr.drv-1].onoff + 1 + (led_map[i].adr.swb-1)*2+(led_map[i].adr.cs-1)/8) |= (1<<((led_map[i].adr.cs-1)%8));
+    for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
+        // BYTE: 1 + (SW-1)*16 + (CS-1)
+        led_map[i].rgb.g = issidrv[led_map[i].adr.drv - 1].pwm + 1 + ((led_map[i].adr.swg - 1) * 16 + (led_map[i].adr.cs - 1));
+        led_map[i].rgb.r = issidrv[led_map[i].adr.drv - 1].pwm + 1 + ((led_map[i].adr.swr - 1) * 16 + (led_map[i].adr.cs - 1));
+        led_map[i].rgb.b = issidrv[led_map[i].adr.drv - 1].pwm + 1 + ((led_map[i].adr.swb - 1) * 16 + (led_map[i].adr.cs - 1));
+
+        // BYTE: 1 + (SW-1)*2 + (CS-1)/8
+        // BIT: (CS-1)%8
+        *(issidrv[led_map[i].adr.drv - 1].onoff + 1 + (led_map[i].adr.swg - 1) * 2 + (led_map[i].adr.cs - 1) / 8) |= (1 << ((led_map[i].adr.cs - 1) % 8));
+        *(issidrv[led_map[i].adr.drv - 1].onoff + 1 + (led_map[i].adr.swr - 1) * 2 + (led_map[i].adr.cs - 1) / 8) |= (1 << ((led_map[i].adr.cs - 1) % 8));
+        *(issidrv[led_map[i].adr.drv - 1].onoff + 1 + (led_map[i].adr.swb - 1) * 2 + (led_map[i].adr.cs - 1) / 8) |= (1 << ((led_map[i].adr.cs - 1) % 8));
     }
 }
 
-void led_matrix_prepare(void)
-{
-    for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++)
-    {
+void led_matrix_prepare(void) {
+    for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
         *led_map[i].rgb.r = 0;
         *led_map[i].rgb.g = 0;
         *led_map[i].rgb.b = 0;
     }
 }
 
-void led_set_one(int i, uint8_t r, uint8_t g, uint8_t b)
-{
-    if (i < ISSI3733_LED_COUNT)
-    {
+void led_set_one(int i, uint8_t r, uint8_t g, uint8_t b) {
+    if (i < ISSI3733_LED_COUNT) {
 #ifdef USE_MASSDROP_CONFIGURATOR
         led_matrix_massdrop_config_override(i);
 #else
@@ -231,16 +208,13 @@ void led_set_one(int i, uint8_t r, uint8_t g, uint8_t b)
     }
 }
 
-void led_set_all(uint8_t r, uint8_t g, uint8_t b)
-{
-  for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++)
-  {
-    led_set_one(i, r, g, b);
-  }
+void led_set_all(uint8_t r, uint8_t g, uint8_t b) {
+    for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
+        led_set_one(i, r, g, b);
+    }
 }
 
-void init(void)
-{
+void init(void) {
     DBGC(DC_LED_MATRIX_INIT_BEGIN);
 
     issi3733_prepare_arrays();
@@ -248,25 +222,28 @@ void init(void)
     led_matrix_prepare();
 
     gcr_min_counter = 0;
-    v_5v_cat_hit = 0;
+    v_5v_cat_hit    = 0;
 
     DBGC(DC_LED_MATRIX_INIT_COMPLETE);
 }
 
-void flush(void)
-{
+void flush(void) {
 #ifdef USE_MASSDROP_CONFIGURATOR
-    if (!led_enabled) { return; } //Prevent calculations and I2C traffic if LED drivers are not enabled
+    if (!led_enabled) {
+        return;
+    }  // Prevent calculations and I2C traffic if LED drivers are not enabled
 #else
-    if (!sr_exp_data.bit.SDB_N) { return; } //Prevent calculations and I2C traffic if LED drivers are not enabled
+    if (!sr_exp_data.bit.SDB_N) {
+        return;
+    }  // Prevent calculations and I2C traffic if LED drivers are not enabled
 #endif
 
     // Wait for previous transfer to complete
-    while (i2c_led_q_running) {}
+    while (i2c_led_q_running) {
+    }
 
     // Copy buffer to live DMA region
-    for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++)
-    {
+    for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
         *led_map[i].rgb.r = led_buffer[i].r;
         *led_map[i].rgb.g = led_buffer[i].g;
         *led_map[i].rgb.b = led_buffer[i].b;
@@ -275,8 +252,7 @@ void flush(void)
 #ifdef USE_MASSDROP_CONFIGURATOR
     breathe_mult = 1;
 
-    if (led_animation_breathing)
-    {
+    if (led_animation_breathing) {
         //+60us 119 LED
         led_animation_breathe_cur += BREATHE_STEP * breathe_dir;
 
@@ -285,76 +261,65 @@ void flush(void)
         else if (led_animation_breathe_cur <= BREATHE_MIN_STEP)
             breathe_dir = 1;
 
-        //Brightness curve created for 256 steps, 0 - ~98%
+        // Brightness curve created for 256 steps, 0 - ~98%
         breathe_mult = 0.000015 * led_animation_breathe_cur * led_animation_breathe_cur;
-        if (breathe_mult > 1) breathe_mult = 1;
-        else if (breathe_mult < 0) breathe_mult = 0;
+        if (breathe_mult > 1)
+            breathe_mult = 1;
+        else if (breathe_mult < 0)
+            breathe_mult = 0;
     }
 
-    //This should only be performed once per frame
+    // This should only be performed once per frame
     pomod = (float)((g_rgb_counters.tick / 10) % (uint32_t)(1000.0f / led_animation_speed)) / 10.0f * led_animation_speed;
     pomod *= 100.0f;
     pomod = (uint32_t)pomod % 10000;
     pomod /= 100.0f;
 
-#endif // USE_MASSDROP_CONFIGURATOR
+#endif  // USE_MASSDROP_CONFIGURATOR
 
     uint8_t drvid;
 
-    //NOTE: GCR does not need to be timed with LED processing, but there is really no harm
-    if (gcr_actual != gcr_actual_last)
-    {
-        for (drvid=0;drvid<ISSI3733_DRIVER_COUNT;drvid++)
-            I2C_LED_Q_GCR(drvid); //Queue data
+    // NOTE: GCR does not need to be timed with LED processing, but there is really no harm
+    if (gcr_actual != gcr_actual_last) {
+        for (drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++) I2C_LED_Q_GCR(drvid);  // Queue data
         gcr_actual_last = gcr_actual;
     }
 
-    for (drvid=0;drvid<ISSI3733_DRIVER_COUNT;drvid++)
-        I2C_LED_Q_PWM(drvid); //Queue data
+    for (drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++) I2C_LED_Q_PWM(drvid);  // Queue data
 
     i2c_led_q_run();
 }
 
-void led_matrix_indicators(void)
-{
+void led_matrix_indicators(void) {
     uint8_t kbled = keyboard_leds();
-    if (kbled && rgb_matrix_config.enable)
-    {
-        for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++)
-        {
+    if (kbled && rgb_matrix_config.enable) {
+        for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
             if (
-            #if USB_LED_NUM_LOCK_SCANCODE != 255
-                (led_map[i].scan == USB_LED_NUM_LOCK_SCANCODE && (kbled & (1<<USB_LED_NUM_LOCK))) ||
-            #endif //NUM LOCK
-            #if USB_LED_CAPS_LOCK_SCANCODE != 255
-                (led_map[i].scan == USB_LED_CAPS_LOCK_SCANCODE && (kbled & (1<<USB_LED_CAPS_LOCK))) ||
-            #endif //CAPS LOCK
-            #if USB_LED_SCROLL_LOCK_SCANCODE != 255
-                (led_map[i].scan == USB_LED_SCROLL_LOCK_SCANCODE && (kbled & (1<<USB_LED_SCROLL_LOCK))) ||
-            #endif //SCROLL LOCK
-            #if USB_LED_COMPOSE_SCANCODE != 255
-                (led_map[i].scan == USB_LED_COMPOSE_SCANCODE && (kbled & (1<<USB_LED_COMPOSE))) ||
-            #endif //COMPOSE
-            #if USB_LED_KANA_SCANCODE != 255
-                (led_map[i].scan == USB_LED_KANA_SCANCODE && (kbled & (1<<USB_LED_KANA))) ||
-            #endif //KANA
-            (0))
-            {
+#if USB_LED_NUM_LOCK_SCANCODE != 255
+                (led_map[i].scan == USB_LED_NUM_LOCK_SCANCODE && (kbled & (1 << USB_LED_NUM_LOCK))) ||
+#endif  // NUM LOCK
+#if USB_LED_CAPS_LOCK_SCANCODE != 255
+                (led_map[i].scan == USB_LED_CAPS_LOCK_SCANCODE && (kbled & (1 << USB_LED_CAPS_LOCK))) ||
+#endif  // CAPS LOCK
+#if USB_LED_SCROLL_LOCK_SCANCODE != 255
+                (led_map[i].scan == USB_LED_SCROLL_LOCK_SCANCODE && (kbled & (1 << USB_LED_SCROLL_LOCK))) ||
+#endif  // SCROLL LOCK
+#if USB_LED_COMPOSE_SCANCODE != 255
+                (led_map[i].scan == USB_LED_COMPOSE_SCANCODE && (kbled & (1 << USB_LED_COMPOSE))) ||
+#endif  // COMPOSE
+#if USB_LED_KANA_SCANCODE != 255
+                (led_map[i].scan == USB_LED_KANA_SCANCODE && (kbled & (1 << USB_LED_KANA))) ||
+#endif  // KANA
+                (0)) {
                 led_buffer[i].r = 255 - led_buffer[i].r;
                 led_buffer[i].g = 255 - led_buffer[i].g;
                 led_buffer[i].b = 255 - led_buffer[i].b;
             }
         }
     }
-
 }
 
-const rgb_matrix_driver_t rgb_matrix_driver = {
-  .init = init,
-  .flush = flush,
-  .set_color = led_set_one,
-  .set_color_all = led_set_all
-};
+const rgb_matrix_driver_t rgb_matrix_driver = {.init = init, .flush = flush, .set_color = led_set_one, .set_color_all = led_set_all};
 
 /*==============================================================================
 =                           Legacy Lighting Support                            =
@@ -365,103 +330,100 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
 
 // TODO?: wire these up to keymap.c
 uint8_t led_animation_orientation = 0;
-uint8_t led_animation_direction = 0;
-uint8_t led_animation_breathing = 0;
-uint8_t led_animation_id = 0;
-float led_animation_speed = 4.0f;
-uint8_t led_lighting_mode = LED_MODE_NORMAL;
-uint8_t led_enabled = 1;
+uint8_t led_animation_direction   = 0;
+uint8_t led_animation_breathing   = 0;
+uint8_t led_animation_id          = 0;
+float   led_animation_speed       = 4.0f;
+uint8_t led_lighting_mode         = LED_MODE_NORMAL;
+uint8_t led_enabled               = 1;
 uint8_t led_animation_breathe_cur = BREATHE_MIN_STEP;
-uint8_t breathe_dir = 1;
+uint8_t breathe_dir               = 1;
 
-static void led_run_pattern(led_setup_t *f, float* ro, float* go, float* bo, float pos) {
+static void led_run_pattern(led_setup_tf, float* ro, float* go, float* bo, float pos) {
     float po;
 
-    while (f->end != 1)
-    {
-        po = pos; //Reset po for new frame
+    while (f->end != 1) {
+        po = pos;  // Reset po for new frame
 
-        //Add in any moving effects
-        if ((!led_animation_direction && f->ef & EF_SCR_R) || (led_animation_direction && (f->ef & EF_SCR_L)))
-        {
+        // Add in any moving effects
+        if ((!led_animation_direction && f->ef & EF_SCR_R) || (led_animation_direction && (f->ef & EF_SCR_L))) {
             po -= pomod;
 
-            if (po > 100) po -= 100;
-            else if (po < 0) po += 100;
-        }
-        else if ((!led_animation_direction && f->ef & EF_SCR_L) || (led_animation_direction && (f->ef & EF_SCR_R)))
-        {
+            if (po > 100)
+                po -= 100;
+            else if (po < 0)
+                po += 100;
+        } else if ((!led_animation_direction && f->ef & EF_SCR_L) || (led_animation_direction && (f->ef & EF_SCR_R))) {
             po += pomod;
 
-            if (po > 100) po -= 100;
-            else if (po < 0) po += 100;
+            if (po > 100)
+                po -= 100;
+            else if (po < 0)
+                po += 100;
         }
 
-        //Check if LED's po is in current frame
-        if (po < f->hs) { f++; continue; }
-        if (po > f->he) { f++; continue; }
-        //note: < 0 or > 100 continue
+        // Check if LED's po is in current frame
+        if (po < f->hs) {
+            f++;
+            continue;
+        }
+        if (po > f->he) {
+            f++;
+            continue;
+        }
+        // note: < 0 or > 100 continue
 
-        //Calculate the po within the start-stop percentage for color blending
+        // Calculate the po within the start-stop percentage for color blending
         po = (po - f->hs) / (f->he - f->hs);
 
-        //Add in any color effects
-        if (f->ef & EF_OVER)
-        {
-            *ro = (po * (f->re - f->rs)) + f->rs;// + 0.5;
-            *go = (po * (f->ge - f->gs)) + f->gs;// + 0.5;
-            *bo = (po * (f->be - f->bs)) + f->bs;// + 0.5;
-        }
-        else if (f->ef & EF_SUBTRACT)
-        {
-            *ro -= (po * (f->re - f->rs)) + f->rs;// + 0.5;
-            *go -= (po * (f->ge - f->gs)) + f->gs;// + 0.5;
-            *bo -= (po * (f->be - f->bs)) + f->bs;// + 0.5;
-        }
-        else
-        {
-            *ro += (po * (f->re - f->rs)) + f->rs;// + 0.5;
-            *go += (po * (f->ge - f->gs)) + f->gs;// + 0.5;
-            *bo += (po * (f->be - f->bs)) + f->bs;// + 0.5;
+        // Add in any color effects
+        if (f->ef & EF_OVER) {
+            *ro = (po * (f->re - f->rs)) + f->rs;  // + 0.5;
+            *go = (po * (f->ge - f->gs)) + f->gs;  // + 0.5;
+            *bo = (po * (f->be - f->bs)) + f->bs;  // + 0.5;
+        } else if (f->ef & EF_SUBTRACT) {
+            *ro -= (po * (f->re - f->rs)) + f->rs;  // + 0.5;
+            *go -= (po * (f->ge - f->gs)) + f->gs;  // + 0.5;
+            *bo -= (po * (f->be - f->bs)) + f->bs;  // + 0.5;
+        } else {
+            *ro += (po * (f->re - f->rs)) + f->rs;  // + 0.5;
+            *go += (po * (f->ge - f->gs)) + f->gs;  // + 0.5;
+            *bo += (po * (f->be - f->bs)) + f->bs;  // + 0.5;
         }
 
         f++;
     }
 }
 
-static void led_matrix_massdrop_config_override(int i)
-{
+static void led_matrix_massdrop_config_override(int i) {
     float ro = 0;
     float go = 0;
     float bo = 0;
 
-    float po = (led_animation_orientation)
-        ? (float)g_led_config.point[i].y / 64.f * 100
-        : (float)g_led_config.point[i].x / 224.f * 100;
+    float po = (led_animation_orientation) ? (float)g_led_config.point[i].y / 64.f * 100 : (float)g_led_config.point[i].x / 224.f * 100;
 
     uint8_t highest_active_layer = biton32(layer_state);
 
     if (led_lighting_mode == LED_MODE_KEYS_ONLY && HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) {
-        //Do not act on this LED
+        // Do not act on this LED
     } else if (led_lighting_mode == LED_MODE_NON_KEYS_ONLY && !HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) {
-        //Do not act on this LED
+        // Do not act on this LED
     } else if (led_lighting_mode == LED_MODE_INDICATORS_ONLY) {
-        //Do not act on this LED (Only show indicators)
+        // Do not act on this LED (Only show indicators)
     } else {
         led_instruction_t* led_cur_instruction = led_instructions;
         while (!led_cur_instruction->end) {
             // Check if this applies to current layer
-            if ((led_cur_instruction->flags & LED_FLAG_MATCH_LAYER) &&
-                (led_cur_instruction->layer != highest_active_layer)) {
+            if ((led_cur_instruction->flags & LED_FLAG_MATCH_LAYER) && (led_cur_instruction->layer != highest_active_layer)) {
                 goto next_iter;
             }
 
             // Check if this applies to current index
             if (led_cur_instruction->flags & LED_FLAG_MATCH_ID) {
-                uint8_t modid = i / 32;                                     //Calculate which id# contains the led bit
-                uint32_t modidbit = 1 << (i % 32);                          //Calculate the bit within the id#
-                uint32_t *bitfield = &led_cur_instruction->id0 + modid;     //Add modid as offset to id0 address. *bitfield is now idX of the led id
-                if (~(*bitfield) & modidbit) {                              //Check if led bit is not set in idX
+                uint8_t   modid    = i / 32;                             // Calculate which id# contains the led bit
+                uint32_t  modidbit = 1 << (i % 32);                      // Calculate the bit within the id#
+                uint32_t* bitfield = &led_cur_instruction->id0 + modid;  // Add modid as offset to id0 address. *bitfield is now idX of the led id
+                if (~(*bitfield) & modidbit) {                           // Check if led bit is not set in idX
                     goto next_iter;
                 }
             }
@@ -476,16 +438,24 @@ static void led_matrix_massdrop_config_override(int i)
                 led_run_pattern(led_setups[led_animation_id], &ro, &go, &bo, po);
             }
 
-            next_iter:
-                led_cur_instruction++;
+        next_iter:
+            led_cur_instruction++;
         }
 
-        if (ro > 255) ro = 255; else if (ro < 0) ro = 0;
-        if (go > 255) go = 255; else if (go < 0) go = 0;
-        if (bo > 255) bo = 255; else if (bo < 0) bo = 0;
-
-        if (led_animation_breathing)
-        {
+        if (ro > 255)
+            ro = 255;
+        else if (ro < 0)
+            ro = 0;
+        if (go > 255)
+            go = 255;
+        else if (go < 0)
+            go = 0;
+        if (bo > 255)
+            bo = 255;
+        else if (bo < 0)
+            bo = 0;
+
+        if (led_animation_breathing) {
             ro *= breathe_mult;
             go *= breathe_mult;
             bo *= breathe_mult;
@@ -497,4 +467,4 @@ static void led_matrix_massdrop_config_override(int i)
     led_buffer[i].b = (uint8_t)bo;
 }
 
-#endif // USE_MASSDROP_CONFIGURATOR
+#endif  // USE_MASSDROP_CONFIGURATOR
index 1316efd9a4fd2a669a2f77c56bc4df14377b2f10..8eaa5623bda5eee1d416a412c4fb640a7827e9f0 100644 (file)
@@ -20,20 +20,20 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "quantum.h"
 
-//From keyboard
+// From keyboard
 #include "config_led.h"
 
-//CS1-CS16 Current Source "Col"
+// CS1-CS16 Current Source "Col"
 #define ISSI3733_CS_COUNT 16
 
-//SW1-SW12 Switch "Row"
+// SW1-SW12 Switch "Row"
 #define ISSI3733_SW_COUNT 12
 
-#define ISSI3733_LED_RGB_COUNT ISSI3733_CS_COUNT * ISSI3733_SW_COUNT
-#define ISSI3733_PG0_BYTES ISSI3733_LED_RGB_COUNT / 8 + 1       //+1 for first byte being memory start offset for I2C transfer
-#define ISSI3733_PG1_BYTES ISSI3733_LED_RGB_COUNT + 1           //+1 for first byte being memory start offset for I2C transfer
-#define ISSI3733_PG2_BYTES ISSI3733_LED_RGB_COUNT + 1           //+1 for first byte being memory start offset for I2C transfer
-#define ISSI3733_PG3_BYTES 18 + 1                               //+1 for first byte being memory start offset for I2C transfer
+#define ISSI3733_LED_RGB_COUNT ISSI3733_CS_COUNT *ISSI3733_SW_COUNT
+#define ISSI3733_PG0_BYTES ISSI3733_LED_RGB_COUNT / 8 + 1  //+1 for first byte being memory start offset for I2C transfer
+#define ISSI3733_PG1_BYTES ISSI3733_LED_RGB_COUNT + 1      //+1 for first byte being memory start offset for I2C transfer
+#define ISSI3733_PG2_BYTES ISSI3733_LED_RGB_COUNT + 1      //+1 for first byte being memory start offset for I2C transfer
+#define ISSI3733_PG3_BYTES 18 + 1                          //+1 for first byte being memory start offset for I2C transfer
 
 #define ISSI3733_PG_ONOFF_BYTES ISSI3733_PG0_BYTES
 #define ISSI3733_PG_OR_BYTES ISSI3733_PG0_BYTES
@@ -43,38 +43,38 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define ISSI3733_PG_FN_BYTES ISSI3733_PG3_BYTES
 
 typedef struct issi3733_driver_s {
-    uint8_t addr; //Address of the driver according to wiring "ISSI3733: Table 1 Slave Address"
-    uint8_t onoff[ISSI3733_PG_ONOFF_BYTES]; //PG0 - LED Control Register - LED On/Off Register
-    uint8_t open[ISSI3733_PG_OR_BYTES];     //PG0 - LED Control Register - LED Open Register
-    uint8_t shrt[ISSI3733_PG_SR_BYTES];     //PG0 - LED Control Register - LED Short Register
-    uint8_t pwm[ISSI3733_PG_PWM_BYTES];     //PG1 - PWM Register
-    uint8_t abm[ISSI3733_PG_ABM_BYTES];     //PG2 - Auto Breath Mode Register
-    uint8_t conf[ISSI3733_PG_FN_BYTES];     //PG3 - Function Register
+    uint8_t addr;                            // Address of the driver according to wiring "ISSI3733: Table 1 Slave Address"
+    uint8_t onoff[ISSI3733_PG_ONOFF_BYTES];  // PG0 - LED Control Register - LED On/Off Register
+    uint8_t open[ISSI3733_PG_OR_BYTES];      // PG0 - LED Control Register - LED Open Register
+    uint8_t shrt[ISSI3733_PG_SR_BYTES];      // PG0 - LED Control Register - LED Short Register
+    uint8_t pwm[ISSI3733_PG_PWM_BYTES];      // PG1 - PWM Register
+    uint8_t abm[ISSI3733_PG_ABM_BYTES];      // PG2 - Auto Breath Mode Register
+    uint8_t conf[ISSI3733_PG_FN_BYTES];      // PG3 - Function Register
 } issi3733_driver_t;
 
 typedef struct issi3733_rgb_s {
-    uint8_t *r;         //Direct access into PWM data
-    uint8_t *g;         //Direct access into PWM data
-    uint8_t *b;         //Direct access into PWM data
+    uint8_t *r;  // Direct access into PWM data
+    uint8_t *g;  // Direct access into PWM data
+    uint8_t *b;  // Direct access into PWM data
 } issi3733_rgb_t;
 
 typedef struct issi3733_rgb_adr_s {
-    uint8_t drv;        //Driver from given list
-    uint8_t cs;         //CS
-    uint8_t swr;        //SW Red
-    uint8_t swg;        //SW Green
-    uint8_t swb;        //SW Blue
+    uint8_t drv;  // Driver from given list
+    uint8_t cs;   // CS
+    uint8_t swr;  // SW Red
+    uint8_t swg;  // SW Green
+    uint8_t swb;  // SW Blue
 } issi3733_rgb_adr_t;
 
 typedef struct issi3733_led_s {
-    uint8_t id;                 //According to PCB ref
-    issi3733_rgb_t rgb;         //PWM settings of R G B
-    issi3733_rgb_adr_t adr;     //Hardware addresses
-    float x;                    //Physical position X
-    float y;                    //Physical position Y
-    float px;                   //Physical position X in percent
-    float py;                   //Physical position Y in percent
-    uint8_t scan;               //Key scan code from wiring (set 0xFF if no key)
+    uint8_t            id;    // According to PCB ref
+    issi3733_rgb_t     rgb;   // PWM settings of R G B
+    issi3733_rgb_adr_t adr;   // Hardware addresses
+    float              x;     // Physical position X
+    float              y;     // Physical position Y
+    float              px;    // Physical position X in percent
+    float              py;    // Physical position Y in percent
+    uint8_t            scan;  // Key scan code from wiring (set 0xFF if no key)
 } issi3733_led_t;
 
 extern issi3733_driver_t issidrv[ISSI3733_DRIVER_COUNT];
@@ -92,67 +92,67 @@ void led_matrix_indicators(void);
 
 #ifdef USE_MASSDROP_CONFIGURATOR
 
-#define EF_NONE         0x00000000  //No effect
-#define EF_OVER         0x00000001  //Overwrite any previous color information with new
-#define EF_SCR_L        0x00000002  //Scroll left
-#define EF_SCR_R        0x00000004  //Scroll right
-#define EF_SUBTRACT     0x00000008  //Subtract color values
+#    define EF_NONE 0x00000000      // No effect
+#    define EF_OVER 0x00000001      // Overwrite any previous color information with new
+#    define EF_SCR_L 0x00000002     // Scroll left
+#    define EF_SCR_R 0x00000004     // Scroll right
+#    define EF_SUBTRACT 0x00000008  // Subtract color values
 
 typedef struct led_setup_s {
-  float hs;         //Band begin at percent
-  float he;         //Band end at percent
-  uint8_t rs;       //Red start value
-  uint8_t re;       //Red end value
-  uint8_t gs;       //Green start value
-  uint8_t ge;       //Green end value
-  uint8_t bs;       //Blue start value
-  uint8_t be;       //Blue end value
-  uint32_t ef;      //Animation and color effects
-  uint8_t end;      //Set to signal end of the setup
+    float    hs;   // Band begin at percent
+    float    he;   // Band end at percent
+    uint8_t  rs;   // Red start value
+    uint8_t  re;   // Red end value
+    uint8_t  gs;   // Green start value
+    uint8_t  ge;   // Green end value
+    uint8_t  bs;   // Blue start value
+    uint8_t  be;   // Blue end value
+    uint32_t ef;   // Animation and color effects
+    uint8_t  end;  // Set to signal end of the setup
 } led_setup_t;
 
 extern const uint8_t led_setups_count;
-extern void *led_setups[];
+extern void *        led_setups[];
 
-//LED Extra Instructions
-#define LED_FLAG_NULL                0x00       //Matching and coloring not used (default)
-#define LED_FLAG_MATCH_ID            0x01       //Match on the ID of the LED (set id#'s to desired bit pattern, first LED is id 1)
-#define LED_FLAG_MATCH_LAYER         0x02       //Match on the current active layer (set layer to desired match layer)
-#define LED_FLAG_USE_RGB             0x10       //Use a specific RGB value (set r, g, b to desired output color values)
-#define LED_FLAG_USE_PATTERN         0x20       //Use a specific pattern ID (set pattern_id to desired output pattern)
-#define LED_FLAG_USE_ROTATE_PATTERN  0x40       //Use pattern the user has cycled to manually
+// LED Extra Instructions
+#    define LED_FLAG_NULL 0x00                // Matching and coloring not used (default)
+#    define LED_FLAG_MATCH_ID 0x01            // Match on the ID of the LED (set id#'s to desired bit pattern, first LED is id 1)
+#    define LED_FLAG_MATCH_LAYER 0x02         // Match on the current active layer (set layer to desired match layer)
+#    define LED_FLAG_USE_RGB 0x10             // Use a specific RGB value (set r, g, b to desired output color values)
+#    define LED_FLAG_USE_PATTERN 0x20         // Use a specific pattern ID (set pattern_id to desired output pattern)
+#    define LED_FLAG_USE_ROTATE_PATTERN 0x40  // Use pattern the user has cycled to manually
 
 typedef struct led_instruction_s {
-    uint16_t flags; // Bitfield for LED instructions
-    uint32_t id0; // Bitwise id, IDs 0-31
-    uint32_t id1; // Bitwise id, IDs 32-63
-    uint32_t id2; // Bitwise id, IDs 64-95
-    uint32_t id3; // Bitwise id, IDs 96-127
-    uint8_t layer;
-    uint8_t r;
-    uint8_t g;
-    uint8_t b;
-    uint8_t pattern_id;
-    uint8_t end;
+    uint16_t flags;  // Bitfield for LED instructions
+    uint32_t id0;    // Bitwise id, IDs 0-31
+    uint32_t id1;    // Bitwise id, IDs 32-63
+    uint32_t id2;    // Bitwise id, IDs 64-95
+    uint32_t id3;    // Bitwise id, IDs 96-127
+    uint8_t  layer;
+    uint8_t  r;
+    uint8_t  g;
+    uint8_t  b;
+    uint8_t  pattern_id;
+    uint8_t  end;
 } led_instruction_t;
 
 extern led_instruction_t led_instructions[];
 
 extern uint8_t led_animation_breathing;
 extern uint8_t led_animation_id;
-extern float led_animation_speed;
+extern float   led_animation_speed;
 extern uint8_t led_lighting_mode;
 extern uint8_t led_enabled;
 extern uint8_t led_animation_breathe_cur;
 extern uint8_t led_animation_direction;
 extern uint8_t breathe_dir;
 
-#define LED_MODE_NORMAL             0   //Must be 0
-#define LED_MODE_KEYS_ONLY          1
-#define LED_MODE_NON_KEYS_ONLY      2
-#define LED_MODE_INDICATORS_ONLY    3
-#define LED_MODE_MAX_INDEX          LED_MODE_INDICATORS_ONLY   //Must be highest value
+#    define LED_MODE_NORMAL 0  // Must be 0
+#    define LED_MODE_KEYS_ONLY 1
+#    define LED_MODE_NON_KEYS_ONLY 2
+#    define LED_MODE_INDICATORS_ONLY 3
+#    define LED_MODE_MAX_INDEX LED_MODE_INDICATORS_ONLY  // Must be highest value
 
-#endif // USE_MASSDROP_CONFIGURATOR
+#endif  // USE_MASSDROP_CONFIGURATOR
 
-#endif //_LED_MATRIX_H_
+#endif  //_LED_MATRIX_H_
index cf7478dc312e6dc58a41f5af8da513f7eeecb17a..360102ba8455973078c606afee5f11d7af64c574 100644 (file)
@@ -17,106 +17,82 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #ifdef USE_MASSDROP_CONFIGURATOR
 
-#include "led_matrix.h"
+#    include "led_matrix.h"
 
-//Teal <-> Salmon
+// Teal <-> Salmon
 led_setup_t leds_teal_salmon[] = {
-    { .hs = 0,  .he = 33,  .rs = 24,  .re = 24,  .gs = 215, .ge = 215, .bs = 204, .be = 204, .ef = EF_NONE },
-    { .hs = 33, .he = 66,  .rs = 24,  .re = 255, .gs = 215, .ge = 114, .bs = 204, .be = 118, .ef = EF_NONE },
-    { .hs = 66, .he = 100, .rs = 255, .re = 255, .gs = 114, .ge = 114, .bs = 118, .be = 118, .ef = EF_NONE },
-    { .end = 1 },
+    {.hs = 0, .he = 33, .rs = 24, .re = 24, .gs = 215, .ge = 215, .bs = 204, .be = 204, .ef = EF_NONE},
+    {.hs = 33, .he = 66, .rs = 24, .re = 255, .gs = 215, .ge = 114, .bs = 204, .be = 118, .ef = EF_NONE},
+    {.hs = 66, .he = 100, .rs = 255, .re = 255, .gs = 114, .ge = 114, .bs = 118, .be = 118, .ef = EF_NONE},
+    {.end = 1},
 };
 
-//Yellow
+// Yellow
 led_setup_t leds_yellow[] = {
-    { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE },
-    { .end = 1 },
+    {.hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE},
+    {.end = 1},
 };
 
-//Off
+// Off
 led_setup_t leds_off[] = {
-    { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE },
-    { .end = 1 },
+    {.hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE},
+    {.end = 1},
 };
 
-//Red
+// Red
 led_setup_t leds_red[] = {
-    { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE },
-    { .end = 1 },
+    {.hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE},
+    {.end = 1},
 };
 
-//Green
+// Green
 led_setup_t leds_green[] = {
-    { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE },
-    { .end = 1 },
+    {.hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE},
+    {.end = 1},
 };
 
-//Blue
+// Blue
 led_setup_t leds_blue[] = {
-    { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_NONE },
-    { .end = 1 },
+    {.hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_NONE},
+    {.end = 1},
 };
 
-//White
+// White
 led_setup_t leds_white[] = {
-    { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE },
-    { .end = 1 },
+    {.hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE},
+    {.end = 1},
 };
 
-//White with moving red stripe
+// White with moving red stripe
 led_setup_t leds_white_with_red_stripe[] = {
-    { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE },
-    { .hs = 0, .he = 15, .rs = 0, .re = 0, .gs = 0, .ge = 255, .bs = 0, .be = 255, .ef = EF_SCR_R | EF_SUBTRACT },
-    { .hs = 15, .he = 30, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 0, .ef = EF_SCR_R | EF_SUBTRACT },
-    { .end = 1 },
+    {.hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE},
+    {.hs = 0, .he = 15, .rs = 0, .re = 0, .gs = 0, .ge = 255, .bs = 0, .be = 255, .ef = EF_SCR_R | EF_SUBTRACT},
+    {.hs = 15, .he = 30, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 0, .ef = EF_SCR_R | EF_SUBTRACT},
+    {.end = 1},
 };
 
-//Black with moving red stripe
+// Black with moving red stripe
 led_setup_t leds_black_with_red_stripe[] = {
-    { .hs = 0, .he = 15, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R },
-    { .hs = 15, .he = 30, .rs = 255, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R },
-    { .end = 1 },
+    {.hs = 0, .he = 15, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R},
+    {.hs = 15, .he = 30, .rs = 255, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R},
+    {.end = 1},
 };
 
-//Rainbow no scrolling
+// Rainbow no scrolling
 led_setup_t leds_rainbow_ns[] = {
-    { .hs = 0,      .he = 16.67,  .rs = 255, .re = 255, .gs = 0,   .ge = 255, .bs = 0,   .be = 0,   .ef = EF_OVER },
-    { .hs = 16.67,  .he = 33.33,  .rs = 255, .re = 0,   .gs = 255, .ge = 255, .bs = 0,   .be = 0,   .ef = EF_OVER },
-    { .hs = 33.33,  .he = 50,     .rs = 0,   .re = 0,   .gs = 255, .ge = 255, .bs = 0,   .be = 255, .ef = EF_OVER },
-    { .hs = 50,     .he = 66.67,  .rs = 0,   .re = 0,   .gs = 255, .ge = 0,   .bs = 255, .be = 255, .ef = EF_OVER },
-    { .hs = 66.67,  .he = 83.33,  .rs = 0,   .re = 255, .gs = 0,   .ge = 0,   .bs = 255, .be = 255, .ef = EF_OVER },
-    { .hs = 83.33,  .he = 100,    .rs = 255, .re = 255, .gs = 0,   .ge = 0,   .bs = 255, .be = 0,   .ef = EF_OVER },
-    { .end = 1 },
+    {.hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER}, {.hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER}, {.hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_OVER}, {.hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER}, {.hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER}, {.hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_OVER}, {.end = 1},
 };
 
-//Rainbow scrolling
+// Rainbow scrolling
 led_setup_t leds_rainbow_s[] = {
-    { .hs = 0,      .he = 16.67,  .rs = 255, .re = 255, .gs = 0,   .ge = 255, .bs = 0,   .be = 0,   .ef = EF_OVER | EF_SCR_R },
-    { .hs = 16.67,  .he = 33.33,  .rs = 255, .re = 0,   .gs = 255, .ge = 255, .bs = 0,   .be = 0,   .ef = EF_OVER | EF_SCR_R },
-    { .hs = 33.33,  .he = 50,     .rs = 0,   .re = 0,   .gs = 255, .ge = 255, .bs = 0,   .be = 255, .ef = EF_OVER | EF_SCR_R },
-    { .hs = 50,     .he = 66.67,  .rs = 0,   .re = 0,   .gs = 255, .ge = 0,   .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R },
-    { .hs = 66.67,  .he = 83.33,  .rs = 0,   .re = 255, .gs = 0,   .ge = 0,   .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R },
-    { .hs = 83.33,  .he = 100,    .rs = 255, .re = 255, .gs = 0,   .ge = 0,   .bs = 255, .be = 0,   .ef = EF_OVER | EF_SCR_R },
-    { .end = 1 },
+    {.hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER | EF_SCR_R}, {.hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER | EF_SCR_R}, {.hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_OVER | EF_SCR_R}, {.hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R}, {.hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R}, {.hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_OVER | EF_SCR_R}, {.end = 1},
 };
 
-//Add new LED animations here using one from above as example
-//The last entry must be { .end = 1 }
-//Add the new animation name to the list below following its format
-
-void *led_setups[] = {
-    leds_rainbow_s,
-    leds_rainbow_ns,
-    leds_teal_salmon,
-    leds_yellow,
-    leds_red,
-    leds_green,
-    leds_blue,
-    leds_white,
-    leds_white_with_red_stripe,
-    leds_black_with_red_stripe,
-    leds_off
-};
+// Add new LED animations here using one from above as example
+// The last entry must be { .end = 1 }
+// Add the new animation name to the list below following its format
+
+void *led_setups[] = {leds_rainbow_s, leds_rainbow_ns, leds_teal_salmon, leds_yellow, leds_red, leds_green, leds_blue, leds_white, leds_white_with_red_stripe, leds_black_with_red_stripe, leds_off};
 
 const uint8_t led_setups_count = sizeof(led_setups) / sizeof(led_setups[0]);
 
index 0974a230d4c1571b8c1e929b7c78fcb649348e97..a42d9daf38fcb7e631fcb91ea84fb56e6441fe99 100644 (file)
@@ -25,50 +25,43 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <string.h>
 #include "quantum.h"
 
-//From protocol directory
+// From protocol directory
 #include "arm_atsam_protocol.h"
 
-//From keyboard's directory
+// From keyboard's directory
 #include "config_led.h"
 
-uint8_t g_usb_state = USB_FSMSTATUS_FSMSTATE_OFF_Val;   //Saved USB state from hardware value to detect changes
+uint8_t g_usb_state = USB_FSMSTATUS_FSMSTATE_OFF_Val;  // Saved USB state from hardware value to detect changes
 
-void main_subtasks(void);
+void    main_subtasks(void);
 uint8_t keyboard_leds(void);
-void send_keyboard(report_keyboard_t *report);
-void send_mouse(report_mouse_t *report);
-void send_system(uint16_t data);
-void send_consumer(uint16_t data);
-
-host_driver_t arm_atsam_driver = {
-    keyboard_leds,
-    send_keyboard,
-    send_mouse,
-    send_system,
-    send_consumer
-};
+void    send_keyboard(report_keyboard_t *report);
+void    send_mouse(report_mouse_t *report);
+void    send_system(uint16_t data);
+void    send_consumer(uint16_t data);
+
+host_driver_t arm_atsam_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
 
 uint8_t led_states;
 
-uint8_t keyboard_leds(void)
-{
+uint8_t keyboard_leds(void) {
 #ifdef NKRO_ENABLE
     if (keymap_config.nkro)
         return udi_hid_nkro_report_set;
     else
-#endif //NKRO_ENABLE
+#endif  // NKRO_ENABLE
         return udi_hid_kbd_report_set;
 }
 
-void send_keyboard(report_keyboard_t *report)
-{
+void send_keyboard(report_keyboard_t *report) {
     uint32_t irqflags;
 
 #ifdef NKRO_ENABLE
-    if (!keymap_config.nkro)
-    {
-#endif //NKRO_ENABLE
-        while (udi_hid_kbd_b_report_trans_ongoing) { main_subtasks(); } //Run other tasks while waiting for USB to be free
+    if (!keymap_config.nkro) {
+#endif  // NKRO_ENABLE
+        while (udi_hid_kbd_b_report_trans_ongoing) {
+            main_subtasks();
+        }  // Run other tasks while waiting for USB to be free
 
         irqflags = __get_PRIMASK();
         __disable_irq();
@@ -81,10 +74,10 @@ void send_keyboard(report_keyboard_t *report)
         __DMB();
         __set_PRIMASK(irqflags);
 #ifdef NKRO_ENABLE
-    }
-    else
-    {
-        while (udi_hid_nkro_b_report_trans_ongoing) { main_subtasks(); } //Run other tasks while waiting for USB to be free
+    } else {
+        while (udi_hid_nkro_b_report_trans_ongoing) {
+            main_subtasks();
+        }  // Run other tasks while waiting for USB to be free
 
         irqflags = __get_PRIMASK();
         __disable_irq();
@@ -97,11 +90,10 @@ void send_keyboard(report_keyboard_t *report)
         __DMB();
         __set_PRIMASK(irqflags);
     }
-#endif //NKRO_ENABLE
+#endif  // NKRO_ENABLE
 }
 
-void send_mouse(report_mouse_t *report)
-{
+void send_mouse(report_mouse_t *report) {
 #ifdef MOUSEKEY_ENABLE
     uint32_t irqflags;
 
@@ -115,11 +107,10 @@ void send_mouse(report_mouse_t *report)
 
     __DMB();
     __set_PRIMASK(irqflags);
-#endif //MOUSEKEY_ENABLE
+#endif  // MOUSEKEY_ENABLE
 }
 
-void send_system(uint16_t data)
-{
+void send_system(uint16_t data) {
 #ifdef EXTRAKEY_ENABLE
     uint32_t irqflags;
 
@@ -130,16 +121,15 @@ void send_system(uint16_t data)
     udi_hid_exk_report.desc.report_id = REPORT_ID_SYSTEM;
     if (data != 0) data = data - SYSTEM_POWER_DOWN + 1;
     udi_hid_exk_report.desc.report_data = data;
-    udi_hid_exk_b_report_valid = 1;
+    udi_hid_exk_b_report_valid          = 1;
     udi_hid_exk_send_report();
 
     __DMB();
     __set_PRIMASK(irqflags);
-#endif //EXTRAKEY_ENABLE
+#endif  // EXTRAKEY_ENABLE
 }
 
-void send_consumer(uint16_t data)
-{
+void send_consumer(uint16_t data) {
 #ifdef EXTRAKEY_ENABLE
     uint32_t irqflags;
 
@@ -147,71 +137,64 @@ void send_consumer(uint16_t data)
     __disable_irq();
     __DMB();
 
-    udi_hid_exk_report.desc.report_id = REPORT_ID_CONSUMER;
+    udi_hid_exk_report.desc.report_id   = REPORT_ID_CONSUMER;
     udi_hid_exk_report.desc.report_data = data;
-    udi_hid_exk_b_report_valid = 1;
+    udi_hid_exk_b_report_valid          = 1;
     udi_hid_exk_send_report();
 
     __DMB();
     __set_PRIMASK(irqflags);
-#endif //EXTRAKEY_ENABLE
+#endif  // EXTRAKEY_ENABLE
 }
 
-void main_subtask_usb_state(void)
-{
-    static uint64_t fsmstate_on_delay = 0;                          //Delay timer to be sure USB is actually operating before bringing up hardware
-    uint8_t fsmstate_now = USB->DEVICE.FSMSTATUS.reg;               //Current state from hardware register
+void main_subtask_usb_state(void) {
+    static uint64_t fsmstate_on_delay = 0;                          // Delay timer to be sure USB is actually operating before bringing up hardware
+    uint8_t         fsmstate_now      = USB->DEVICE.FSMSTATUS.reg;  // Current state from hardware register
 
-    if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val)         //If USB SUSPENDED
+    if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val)  // If USB SUSPENDED
     {
-        fsmstate_on_delay = 0;                                      //Clear ON delay timer
+        fsmstate_on_delay = 0;  // Clear ON delay timer
 
-        if (g_usb_state != USB_FSMSTATUS_FSMSTATE_SUSPEND_Val)      //If previously not SUSPENDED
+        if (g_usb_state != USB_FSMSTATUS_FSMSTATE_SUSPEND_Val)  // If previously not SUSPENDED
         {
-            suspend_power_down();                                   //Run suspend routine
-            g_usb_state = fsmstate_now;                             //Save current USB state
+            suspend_power_down();        // Run suspend routine
+            g_usb_state = fsmstate_now;  // Save current USB state
         }
-    }
-    else if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SLEEP_Val)      //Else if USB SLEEPING
+    } else if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SLEEP_Val)  // Else if USB SLEEPING
     {
-        fsmstate_on_delay = 0;                                      //Clear ON delay timer
+        fsmstate_on_delay = 0;  // Clear ON delay timer
 
-        if (g_usb_state != USB_FSMSTATUS_FSMSTATE_SLEEP_Val)        //If previously not SLEEPING
+        if (g_usb_state != USB_FSMSTATUS_FSMSTATE_SLEEP_Val)  // If previously not SLEEPING
         {
-            suspend_power_down();                                   //Run suspend routine
-            g_usb_state = fsmstate_now;                             //Save current USB state
+            suspend_power_down();        // Run suspend routine
+            g_usb_state = fsmstate_now;  // Save current USB state
         }
-    }
-    else if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_ON_Val)         //Else if USB ON
+    } else if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_ON_Val)  // Else if USB ON
     {
-        if (g_usb_state != USB_FSMSTATUS_FSMSTATE_ON_Val)           //If previously not ON
+        if (g_usb_state != USB_FSMSTATUS_FSMSTATE_ON_Val)  // If previously not ON
         {
-            if (fsmstate_on_delay == 0)                             //If ON delay timer is cleared
+            if (fsmstate_on_delay == 0)  // If ON delay timer is cleared
             {
-                fsmstate_on_delay = timer_read64() + 250;             //Set ON delay timer
-            }
-            else if (timer_read64() > fsmstate_on_delay)              //Else if ON delay timer is active and timed out
+                fsmstate_on_delay = timer_read64() + 250;   // Set ON delay timer
+            } else if (timer_read64() > fsmstate_on_delay)  // Else if ON delay timer is active and timed out
             {
-                suspend_wakeup_init();                              //Run wakeup routine
-                g_usb_state = fsmstate_now;                         //Save current USB state
+                suspend_wakeup_init();       // Run wakeup routine
+                g_usb_state = fsmstate_now;  // Save current USB state
             }
         }
-    }
-    else                                                            //Else if USB is in a state not being tracked
+    } else  // Else if USB is in a state not being tracked
     {
-        fsmstate_on_delay = 0;                                      //Clear ON delay timer
+        fsmstate_on_delay = 0;  // Clear ON delay timer
     }
 }
 
-void main_subtask_power_check(void)
-{
+void main_subtask_power_check(void) {
     static uint64_t next_5v_checkup = 0;
 
-    if (timer_read64() > next_5v_checkup)
-    {
+    if (timer_read64() > next_5v_checkup) {
         next_5v_checkup = timer_read64() + 5;
 
-        v_5v = adc_get(ADC_5V);
+        v_5v     = adc_get(ADC_5V);
         v_5v_avg = 0.9 * v_5v_avg + 0.1 * v_5v;
 
 #ifdef RGB_MATRIX_ENABLE
@@ -220,27 +203,23 @@ void main_subtask_power_check(void)
     }
 }
 
-void main_subtask_usb_extra_device(void)
-{
+void main_subtask_usb_extra_device(void) {
     static uint64_t next_usb_checkup = 0;
 
-    if (timer_read64() > next_usb_checkup)
-    {
+    if (timer_read64() > next_usb_checkup) {
         next_usb_checkup = timer_read64() + 10;
 
         USB_HandleExtraDevice();
     }
 }
 
-void main_subtasks(void)
-{
+void main_subtasks(void) {
     main_subtask_usb_state();
     main_subtask_power_check();
     main_subtask_usb_extra_device();
 }
 
-int main(void)
-{
+int main(void) {
     DBG_LED_ENA;
     DBG_1_ENA;
     DBG_1_OFF;
@@ -259,7 +238,7 @@ int main(void)
 
 #ifdef RGB_MATRIX_ENABLE
     i2c1_init();
-#endif // RGB_MATRIX_ENABLE
+#endif  // RGB_MATRIX_ENABLE
 
     matrix_init();
 
@@ -273,21 +252,23 @@ int main(void)
     CDC_init();
     DBGC(DC_MAIN_CDC_INIT_COMPLETE);
 
-    while (USB2422_Port_Detect_Init() == 0) {}
+    while (USB2422_Port_Detect_Init() == 0) {
+    }
 
     DBG_LED_OFF;
 
 #ifdef RGB_MATRIX_ENABLE
-    while (I2C3733_Init_Control() != 1) {}
-    while (I2C3733_Init_Drivers() != 1) {}
+    while (I2C3733_Init_Control() != 1) {
+    }
+    while (I2C3733_Init_Drivers() != 1) {
+    }
 
     I2C_DMAC_LED_Init();
 
     i2c_led_q_init();
 
-    for (uint8_t drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++)
-        I2C_LED_Q_ONOFF(drvid); //Queue data
-#endif // RGB_MATRIX_ENABLE
+    for (uint8_t drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++) I2C_LED_Q_ONOFF(drvid);  // Queue data
+#endif                                                                                       // RGB_MATRIX_ENABLE
 
     keyboard_setup();
 
@@ -297,21 +278,18 @@ int main(void)
 
 #ifdef CONSOLE_ENABLE
     uint64_t next_print = 0;
-#endif //CONSOLE_ENABLE
+#endif  // CONSOLE_ENABLE
 
     v_5v_avg = adc_get(ADC_5V);
 
     debug_code_disable();
 
-    while (1)
-    {
-        main_subtasks(); //Note these tasks will also be run while waiting for USB keyboard polling intervals
+    while (1) {
+        main_subtasks();  // Note these tasks will also be run while waiting for USB keyboard polling intervals
 
-        if (g_usb_state == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val || g_usb_state == USB_FSMSTATUS_FSMSTATE_SLEEP_Val)
-        {
-            if (suspend_wakeup_condition())
-            {
-                udc_remotewakeup(); //Send remote wakeup signal
+        if (g_usb_state == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val || g_usb_state == USB_FSMSTATUS_FSMSTATE_SLEEP_Val) {
+            if (suspend_wakeup_condition()) {
+                udc_remotewakeup();  // Send remote wakeup signal
                 wait_ms(50);
             }
 
@@ -321,16 +299,13 @@ int main(void)
         keyboard_task();
 
 #ifdef CONSOLE_ENABLE
-        if (timer_read64() > next_print)
-        {
+        if (timer_read64() > next_print) {
             next_print = timer_read64() + 250;
-            //Add any debug information here that you want to see very often
-            //dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n", v_5v, v_5v_avg, v_5v_avg - V5_LOW, v_5v_avg - V5_HIGH, gcr_actual, gcr_desired);
+            // Add any debug information here that you want to see very often
+            // dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n", v_5v, v_5v_avg, v_5v_avg - V5_LOW, v_5v_avg - V5_HIGH, gcr_actual, gcr_desired);
         }
-#endif //CONSOLE_ENABLE
+#endif  // CONSOLE_ENABLE
     }
 
-
     return 1;
 }
-
index 78205e2e1be9b0e4ffe4c7fd41cf20a10990d592..5b088f0e20ccd9e5fe1c5234f62b2ce83c49498a 100644 (file)
@@ -20,4 +20,4 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 uint8_t keyboard_leds(void);
 
-#endif //_MAIN_ARM_ATSAM_H_
+#endif  //_MAIN_ARM_ATSAM_H_
index 6b80ef49221e17c15a6379341fc295c8e4f6cce8..362b9bd52a8fc3ce525ec912ebc9edd381cd88b6 100644 (file)
@@ -5,20 +5,20 @@ extern uint32_t _srom;
 extern uint32_t _lrom;
 extern uint32_t _erom;
 
-#define BOOTLOADER_SERIAL_MAX_SIZE 20   //DO NOT MODIFY!
+#define BOOTLOADER_SERIAL_MAX_SIZE 20  // DO NOT MODIFY!
 
 #ifdef KEYBOARD_massdrop_ctrl
-//WARNING: These are only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support
+// WARNING: These are only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support
 extern uint32_t _eram;
-#define BOOTLOADER_MAGIC 0x3B9ACA00
-#define MAGIC_ADDR (uint32_t *)((intptr_t)(&_eram) - 4)
+#    define BOOTLOADER_MAGIC 0x3B9ACA00
+#    define MAGIC_ADDR (uint32_t *)((intptr_t)(&_eram) - 4)
 #endif
 
 #ifdef MD_BOOTLOADER
 
-#define MCU_HZ 48000000
-#define I2C_HZ 0 //Not used
+#    define MCU_HZ 48000000
+#    define I2C_HZ 0  // Not used
 
-#endif //MD_BOOTLOADER
+#endif  // MD_BOOTLOADER
 
-#endif //_MD_BOOTLOADER_H_
+#endif  //_MD_BOOTLOADER_H_
index e275ba13f4daaf98410a1c8df6cd76166a3aeed9..3b118bc1f1344777a9f9c42d99a8140f31730856 100644 (file)
@@ -19,69 +19,74 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 sr_exp_t sr_exp_data;
 
-void SR_EXP_WriteData(void)
-{
+void SR_EXP_WriteData(void) {
     SR_EXP_RCLK_LO;
 
-    while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.DRE)) { DBGC(DC_SPI_WRITE_DRE); }
+    while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.DRE)) {
+        DBGC(DC_SPI_WRITE_DRE);
+    }
 
-    SR_EXP_SERCOM->SPI.DATA.bit.DATA = sr_exp_data.reg & 0xFF; //Shift in bits 7-0
-    while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.TXC)) { DBGC(DC_SPI_WRITE_TXC_1); }
+    SR_EXP_SERCOM->SPI.DATA.bit.DATA = sr_exp_data.reg & 0xFF;  // Shift in bits 7-0
+    while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.TXC)) {
+        DBGC(DC_SPI_WRITE_TXC_1);
+    }
 
-    SR_EXP_SERCOM->SPI.DATA.bit.DATA = (sr_exp_data.reg >> 8) & 0xFF; //Shift in bits 15-8
-    while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.TXC)) { DBGC(DC_SPI_WRITE_TXC_2); }
+    SR_EXP_SERCOM->SPI.DATA.bit.DATA = (sr_exp_data.reg >> 8) & 0xFF;  // Shift in bits 15-8
+    while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.TXC)) {
+        DBGC(DC_SPI_WRITE_TXC_2);
+    }
 
     SR_EXP_RCLK_HI;
 }
 
-void SR_EXP_Init(void)
-{
+void SR_EXP_Init(void) {
     DBGC(DC_SPI_INIT_BEGIN);
 
     CLK_set_spi_freq(CHAN_SERCOM_SPI, FREQ_SPI_DEFAULT);
 
-    //Set up MCU Shift Register pins
+    // Set up MCU Shift Register pins
     PORT->Group[SR_EXP_RCLK_PORT].DIRSET.reg = (1 << SR_EXP_RCLK_PIN);
     PORT->Group[SR_EXP_OE_N_PORT].DIRSET.reg = (1 << SR_EXP_OE_N_PIN);
-    
-    //Set up MCU SPI pins
-    PORT->Group[SR_EXP_DATAOUT_PORT].PMUX[SR_EXP_DATAOUT_PIN / 2].bit.SR_EXP_DATAOUT_MUX_SEL = SR_EXP_DATAOUT_MUX; //MUX select for sercom
-    PORT->Group[SR_EXP_SCLK_PORT].PMUX[SR_EXP_SCLK_PIN / 2].bit.SR_EXP_SCLK_MUX_SEL = SR_EXP_SCLK_MUX; //MUX select for sercom
-    PORT->Group[SR_EXP_DATAOUT_PORT].PINCFG[SR_EXP_DATAOUT_PIN].bit.PMUXEN = 1; //MUX Enable
-    PORT->Group[SR_EXP_SCLK_PORT].PINCFG[SR_EXP_SCLK_PIN].bit.PMUXEN = 1; //MUX Enable
-
-    //Initialize Shift Register
+
+    // Set up MCU SPI pins
+    PORT->Group[SR_EXP_DATAOUT_PORT].PMUX[SR_EXP_DATAOUT_PIN / 2].bit.SR_EXP_DATAOUT_MUX_SEL = SR_EXP_DATAOUT_MUX;  // MUX select for sercom
+    PORT->Group[SR_EXP_SCLK_PORT].PMUX[SR_EXP_SCLK_PIN / 2].bit.SR_EXP_SCLK_MUX_SEL          = SR_EXP_SCLK_MUX;     // MUX select for sercom
+    PORT->Group[SR_EXP_DATAOUT_PORT].PINCFG[SR_EXP_DATAOUT_PIN].bit.PMUXEN                   = 1;                   // MUX Enable
+    PORT->Group[SR_EXP_SCLK_PORT].PINCFG[SR_EXP_SCLK_PIN].bit.PMUXEN                         = 1;                   // MUX Enable
+
+    // Initialize Shift Register
     SR_EXP_OE_N_DIS;
     SR_EXP_RCLK_HI;
 
-    SR_EXP_SERCOM->SPI.CTRLA.bit.DORD = 1; //Data Order - LSB is transferred first
-    SR_EXP_SERCOM->SPI.CTRLA.bit.CPOL = 1; //Clock Polarity - SCK high when idle. Leading edge of cycle is falling. Trailing rising.
-    SR_EXP_SERCOM->SPI.CTRLA.bit.CPHA = 1; //Clock Phase - Leading Edge Falling, change, Trailing Edge - Rising, sample
-    SR_EXP_SERCOM->SPI.CTRLA.bit.DIPO = 3; //Data In Pinout - SERCOM PAD[3] is used as data input (Configure away from DOPO. Not using input.)
-    SR_EXP_SERCOM->SPI.CTRLA.bit.DOPO = 0; //Data Output PAD[0], Serial Clock PAD[1]
-    SR_EXP_SERCOM->SPI.CTRLA.bit.MODE = 3; //Operating Mode - Master operation
+    SR_EXP_SERCOM->SPI.CTRLA.bit.DORD = 1;  // Data Order - LSB is transferred first
+    SR_EXP_SERCOM->SPI.CTRLA.bit.CPOL = 1;  // Clock Polarity - SCK high when idle. Leading edge of cycle is falling. Trailing rising.
+    SR_EXP_SERCOM->SPI.CTRLA.bit.CPHA = 1;  // Clock Phase - Leading Edge Falling, change, Trailing Edge - Rising, sample
+    SR_EXP_SERCOM->SPI.CTRLA.bit.DIPO = 3;  // Data In Pinout - SERCOM PAD[3] is used as data input (Configure away from DOPO. Not using input.)
+    SR_EXP_SERCOM->SPI.CTRLA.bit.DOPO = 0;  // Data Output PAD[0], Serial Clock PAD[1]
+    SR_EXP_SERCOM->SPI.CTRLA.bit.MODE = 3;  // Operating Mode - Master operation
 
-    SR_EXP_SERCOM->SPI.CTRLA.bit.ENABLE = 1; //Enable - Peripheral is enabled or being enabled
-    while (SR_EXP_SERCOM->SPI.SYNCBUSY.bit.ENABLE) { DBGC(DC_SPI_SYNC_ENABLING); }
+    SR_EXP_SERCOM->SPI.CTRLA.bit.ENABLE = 1;  // Enable - Peripheral is enabled or being enabled
+    while (SR_EXP_SERCOM->SPI.SYNCBUSY.bit.ENABLE) {
+        DBGC(DC_SPI_SYNC_ENABLING);
+    }
 
-    sr_exp_data.reg = 0;
+    sr_exp_data.reg             = 0;
     sr_exp_data.bit.HUB_CONNECT = 0;
     sr_exp_data.bit.HUB_RESET_N = 0;
-    sr_exp_data.bit.S_UP = 0;
-    sr_exp_data.bit.E_UP_N = 1;
-    sr_exp_data.bit.S_DN1 = 1;
-    sr_exp_data.bit.E_DN1_N = 1;
-    sr_exp_data.bit.E_VBUS_1 = 0;
-    sr_exp_data.bit.E_VBUS_2 = 0;
-    sr_exp_data.bit.SRC_1 = 1;
-    sr_exp_data.bit.SRC_2 = 1;
-    sr_exp_data.bit.IRST = 1;
-    sr_exp_data.bit.SDB_N = 0;
+    sr_exp_data.bit.S_UP        = 0;
+    sr_exp_data.bit.E_UP_N      = 1;
+    sr_exp_data.bit.S_DN1       = 1;
+    sr_exp_data.bit.E_DN1_N     = 1;
+    sr_exp_data.bit.E_VBUS_1    = 0;
+    sr_exp_data.bit.E_VBUS_2    = 0;
+    sr_exp_data.bit.SRC_1       = 1;
+    sr_exp_data.bit.SRC_2       = 1;
+    sr_exp_data.bit.IRST        = 1;
+    sr_exp_data.bit.SDB_N       = 0;
     SR_EXP_WriteData();
 
-    //Enable Shift Register output
+    // Enable Shift Register output
     SR_EXP_OE_N_ENA;
 
     DBGC(DC_SPI_INIT_COMPLETE);
 }
-
index 4739b775db46047b9c1aa24e66bc064d7899b82b..dcd45f31afe8d04f722f8a0cb37e70dd9ad07d97 100644 (file)
@@ -26,40 +26,40 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /* Determine bits to set for mux selection */
 #if SR_EXP_DATAOUT_PIN % 2 == 0
-#define SR_EXP_DATAOUT_MUX_SEL PMUXE
+#    define SR_EXP_DATAOUT_MUX_SEL PMUXE
 #else
-#define SR_EXP_DATAOUT_MUX_SEL PMUXO
+#    define SR_EXP_DATAOUT_MUX_SEL PMUXO
 #endif
 
 /* Determine bits to set for mux selection */
 #if SR_EXP_SCLK_PIN % 2 == 0
-#define SR_EXP_SCLK_MUX_SEL PMUXE
+#    define SR_EXP_SCLK_MUX_SEL PMUXE
 #else
-#define SR_EXP_SCLK_MUX_SEL PMUXO
+#    define SR_EXP_SCLK_MUX_SEL PMUXO
 #endif
 
 /* Data structure to define Shift Register output expander hardware */
 /* This structure gets shifted into registers LSB first */
 typedef union {
-  struct {
-    uint16_t RSVD4:1;          /*!< bit:      0                                               */
-    uint16_t RSVD3:1;          /*!< bit:      1                                               */
-    uint16_t RSVD2:1;          /*!< bit:      2                                               */
-    uint16_t RSVD1:1;          /*!< bit:      3                                               */
-    uint16_t SDB_N:1;          /*!< bit:      4  SHUTDOWN THE CHIP WHEN 0, RUN WHEN 1         */
-    uint16_t IRST:1;           /*!< bit:      5  RESET THE IS3733 I2C WHEN 1, RUN WHEN 0      */
-    uint16_t SRC_2:1;          /*!< bit:      6  ADVERTISE A SOURCE TO USBC-2 CC              */
-    uint16_t SRC_1:1;          /*!< bit:      7  ADVERTISE A SOURCE TO USBC-1 CC              */
-    uint16_t E_VBUS_2:1;       /*!< bit:      8  ENABLE 5V OUT TO USBC-2 WHEN 1               */
-    uint16_t E_VBUS_1:1;       /*!< bit:      9  ENABLE 5V OUT TO USBC-1 WHEN 1               */
-    uint16_t E_DN1_N:1;        /*!< bit:     10  ENABLE DN1 1:2 MUX WHEN 0                    */
-    uint16_t S_DN1:1;          /*!< bit:     11  SELECT DN1 PATH 0:USBC-1, 1:USBC-2           */
-    uint16_t E_UP_N:1;         /*!< bit:     12  ENABLE SUP 1:2 MUX WHEN 0                    */
-    uint16_t S_UP:1;           /*!< bit:     13  SELECT UP PATH 0:USBC-1, 1:USBC-2            */
-    uint16_t HUB_RESET_N:1;    /*!< bit:     14  RESET USB HUB WHEN 0, RUN WHEN 1             */
-    uint16_t HUB_CONNECT:1;    /*!< bit:     15  SIGNAL VBUS CONNECT TO USB HUB WHEN 1        */
-  } bit;                       /*!< Structure used for bit access                             */
-  uint16_t reg;                /*!< Type      used for register access                        */
+    struct {
+        uint16_t RSVD4 : 1;       /*!< bit:      0                                               */
+        uint16_t RSVD3 : 1;       /*!< bit:      1                                               */
+        uint16_t RSVD2 : 1;       /*!< bit:      2                                               */
+        uint16_t RSVD1 : 1;       /*!< bit:      3                                               */
+        uint16_t SDB_N : 1;       /*!< bit:      4  SHUTDOWN THE CHIP WHEN 0, RUN WHEN 1         */
+        uint16_t IRST : 1;        /*!< bit:      5  RESET THE IS3733 I2C WHEN 1, RUN WHEN 0      */
+        uint16_t SRC_2 : 1;       /*!< bit:      6  ADVERTISE A SOURCE TO USBC-2 CC              */
+        uint16_t SRC_1 : 1;       /*!< bit:      7  ADVERTISE A SOURCE TO USBC-1 CC              */
+        uint16_t E_VBUS_2 : 1;    /*!< bit:      8  ENABLE 5V OUT TO USBC-2 WHEN 1               */
+        uint16_t E_VBUS_1 : 1;    /*!< bit:      9  ENABLE 5V OUT TO USBC-1 WHEN 1               */
+        uint16_t E_DN1_N : 1;     /*!< bit:     10  ENABLE DN1 1:2 MUX WHEN 0                    */
+        uint16_t S_DN1 : 1;       /*!< bit:     11  SELECT DN1 PATH 0:USBC-1, 1:USBC-2           */
+        uint16_t E_UP_N : 1;      /*!< bit:     12  ENABLE SUP 1:2 MUX WHEN 0                    */
+        uint16_t S_UP : 1;        /*!< bit:     13  SELECT UP PATH 0:USBC-1, 1:USBC-2            */
+        uint16_t HUB_RESET_N : 1; /*!< bit:     14  RESET USB HUB WHEN 0, RUN WHEN 1             */
+        uint16_t HUB_CONNECT : 1; /*!< bit:     15  SIGNAL VBUS CONNECT TO USB HUB WHEN 1        */
+    } bit;                        /*!< Structure used for bit access                             */
+    uint16_t reg;                 /*!< Type      used for register access                        */
 } sr_exp_t;
 
 extern sr_exp_t sr_exp_data;
@@ -67,4 +67,4 @@ extern sr_exp_t sr_exp_data;
 void SR_EXP_WriteData(void);
 void SR_EXP_Init(void);
 
-#endif //_SPI_H_
+#endif  //_SPI_H_
index f29fac179b8ce239390fa57d25c8f368bbb9aff6..7a5791ab557a82f38dcea7958f7a465d308b1b31 100644 (file)
@@ -14,9 +14,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License"); you may
  * not use this file except in compliance with the License.
  * You may obtain a copy of the Licence at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -51,447 +51,448 @@ void __libc_init_array(void);
 void Dummy_Handler(void);
 
 /* Cortex-M4 core handlers */
-void NMI_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void HardFault_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void MemManage_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void BusFault_Handler        ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void UsageFault_Handler      ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void SVC_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void DebugMon_Handler        ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void PendSV_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void SysTick_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void NMI_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void HardFault_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void MemManage_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void BusFault_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void UsageFault_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void SVC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void DebugMon_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void PendSV_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void SysTick_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 
 /* Peripherals handlers */
-void PM_Handler              ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void MCLK_Handler            ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void OSCCTRL_0_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* OSCCTRL_XOSCFAIL_0, OSCCTRL_XOSCRDY_0 */
-void OSCCTRL_1_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* OSCCTRL_XOSCFAIL_1, OSCCTRL_XOSCRDY_1 */
-void OSCCTRL_2_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* OSCCTRL_DFLLLOCKC, OSCCTRL_DFLLLOCKF, OSCCTRL_DFLLOOB, OSCCTRL_DFLLRCS, OSCCTRL_DFLLRDY */
-void OSCCTRL_3_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* OSCCTRL_DPLLLCKF_0, OSCCTRL_DPLLLCKR_0, OSCCTRL_DPLLLDRTO_0, OSCCTRL_DPLLLTO_0 */
-void OSCCTRL_4_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* OSCCTRL_DPLLLCKF_1, OSCCTRL_DPLLLCKR_1, OSCCTRL_DPLLLDRTO_1, OSCCTRL_DPLLLTO_1 */
-void OSC32KCTRL_Handler      ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void SUPC_0_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SUPC_B12SRDY, SUPC_B33SRDY, SUPC_BOD12RDY, SUPC_BOD33RDY, SUPC_VCORERDY, SUPC_VREGRDY */
-void SUPC_1_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SUPC_BOD12DET, SUPC_BOD33DET */
-void WDT_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void RTC_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void EIC_0_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_0 */
-void EIC_1_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_1 */
-void EIC_2_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_2 */
-void EIC_3_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_3 */
-void EIC_4_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_4 */
-void EIC_5_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_5 */
-void EIC_6_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_6 */
-void EIC_7_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_7 */
-void EIC_8_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_8 */
-void EIC_9_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_9 */
-void EIC_10_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_10 */
-void EIC_11_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_11 */
-void EIC_12_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_12 */
-void EIC_13_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_13 */
-void EIC_14_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_14 */
-void EIC_15_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_15 */
-void FREQM_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void NVMCTRL_0_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* NVMCTRL_0, NVMCTRL_1, NVMCTRL_2, NVMCTRL_3, NVMCTRL_4, NVMCTRL_5, NVMCTRL_6, NVMCTRL_7 */
-void NVMCTRL_1_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* NVMCTRL_10, NVMCTRL_8, NVMCTRL_9 */
-void DMAC_0_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_0, DMAC_TCMPL_0, DMAC_TERR_0 */
-void DMAC_1_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_1, DMAC_TCMPL_1, DMAC_TERR_1 */
-void DMAC_2_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_2, DMAC_TCMPL_2, DMAC_TERR_2 */
-void DMAC_3_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_3, DMAC_TCMPL_3, DMAC_TERR_3 */
-void DMAC_4_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_10, DMAC_SUSP_11, DMAC_SUSP_12, DMAC_SUSP_13, DMAC_SUSP_14, DMAC_SUSP_15, DMAC_SUSP_16, DMAC_SUSP_17, DMAC_SUSP_18, DMAC_SUSP_19, DMAC_SUSP_20, DMAC_SUSP_21, DMAC_SUSP_22, DMAC_SUSP_23, DMAC_SUSP_24, DMAC_SUSP_25, DMAC_SUSP_26, DMAC_SUSP_27, DMAC_SUSP_28, DMAC_SUSP_29, DMAC_SUSP_30, DMAC_SUSP_31, DMAC_SUSP_4, DMAC_SUSP_5, DMAC_SUSP_6, DMAC_SUSP_7, DMAC_SUSP_8, DMAC_SUSP_9, DMAC_TCMPL_10, DMAC_TCMPL_11, DMAC_TCMPL_12, DMAC_TCMPL_13, DMAC_TCMPL_14, DMAC_TCMPL_15, DMAC_TCMPL_16, DMAC_TCMPL_17, DMAC_TCMPL_18, DMAC_TCMPL_19, DMAC_TCMPL_20, DMAC_TCMPL_21, DMAC_TCMPL_22, DMAC_TCMPL_23, DMAC_TCMPL_24, DMAC_TCMPL_25, DMAC_TCMPL_26, DMAC_TCMPL_27, DMAC_TCMPL_28, DMAC_TCMPL_29, DMAC_TCMPL_30, DMAC_TCMPL_31, DMAC_TCMPL_4, DMAC_TCMPL_5, DMAC_TCMPL_6, DMAC_TCMPL_7, DMAC_TCMPL_8, DMAC_TCMPL_9, DMAC_TERR_10, DMAC_TERR_11, DMAC_TERR_12, DMAC_TERR_13, DMAC_TERR_14, DMAC_TERR_15, DMAC_TERR_16, DMAC_TERR_17, DMAC_TERR_18, DMAC_TERR_19, DMAC_TERR_20, DMAC_TERR_21, DMAC_TERR_22, DMAC_TERR_23, DMAC_TERR_24, DMAC_TERR_25, DMAC_TERR_26, DMAC_TERR_27, DMAC_TERR_28, DMAC_TERR_29, DMAC_TERR_30, DMAC_TERR_31, DMAC_TERR_4, DMAC_TERR_5, DMAC_TERR_6, DMAC_TERR_7, DMAC_TERR_8, DMAC_TERR_9 */
-void EVSYS_0_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_0, EVSYS_OVR_0 */
-void EVSYS_1_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_1, EVSYS_OVR_1 */
-void EVSYS_2_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_2, EVSYS_OVR_2 */
-void EVSYS_3_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_3, EVSYS_OVR_3 */
-void EVSYS_4_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_10, EVSYS_EVD_11, EVSYS_EVD_4, EVSYS_EVD_5, EVSYS_EVD_6, EVSYS_EVD_7, EVSYS_EVD_8, EVSYS_EVD_9, EVSYS_OVR_10, EVSYS_OVR_11, EVSYS_OVR_4, EVSYS_OVR_5, EVSYS_OVR_6, EVSYS_OVR_7, EVSYS_OVR_8, EVSYS_OVR_9 */
-void PAC_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void TAL_0_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TAL_BRK */
-void TAL_1_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TAL_IPS_0, TAL_IPS_1 */
-void RAMECC_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void SERCOM0_0_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM0_0 */
-void SERCOM0_1_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM0_1 */
-void SERCOM0_2_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM0_2 */
-void SERCOM0_3_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM0_3, SERCOM0_4, SERCOM0_5, SERCOM0_6 */
-void SERCOM1_0_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM1_0 */
-void SERCOM1_1_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM1_1 */
-void SERCOM1_2_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM1_2 */
-void SERCOM1_3_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM1_3, SERCOM1_4, SERCOM1_5, SERCOM1_6 */
-void SERCOM2_0_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM2_0 */
-void SERCOM2_1_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM2_1 */
-void SERCOM2_2_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM2_2 */
-void SERCOM2_3_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM2_3, SERCOM2_4, SERCOM2_5, SERCOM2_6 */
-void SERCOM3_0_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM3_0 */
-void SERCOM3_1_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM3_1 */
-void SERCOM3_2_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM3_2 */
-void SERCOM3_3_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM3_3, SERCOM3_4, SERCOM3_5, SERCOM3_6 */
+void PM_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void MCLK_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void OSCCTRL_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* OSCCTRL_XOSCFAIL_0, OSCCTRL_XOSCRDY_0 */
+void OSCCTRL_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* OSCCTRL_XOSCFAIL_1, OSCCTRL_XOSCRDY_1 */
+void OSCCTRL_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* OSCCTRL_DFLLLOCKC, OSCCTRL_DFLLLOCKF, OSCCTRL_DFLLOOB, OSCCTRL_DFLLRCS, OSCCTRL_DFLLRDY */
+void OSCCTRL_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* OSCCTRL_DPLLLCKF_0, OSCCTRL_DPLLLCKR_0, OSCCTRL_DPLLLDRTO_0, OSCCTRL_DPLLLTO_0 */
+void OSCCTRL_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* OSCCTRL_DPLLLCKF_1, OSCCTRL_DPLLLCKR_1, OSCCTRL_DPLLLDRTO_1, OSCCTRL_DPLLLTO_1 */
+void OSC32KCTRL_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void SUPC_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SUPC_B12SRDY, SUPC_B33SRDY, SUPC_BOD12RDY, SUPC_BOD33RDY, SUPC_VCORERDY, SUPC_VREGRDY */
+void SUPC_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SUPC_BOD12DET, SUPC_BOD33DET */
+void WDT_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void RTC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void EIC_0_Handler(void) __attribute__((weak, alias("Dummy_Handler")));  /* EIC_EXTINT_0 */
+void EIC_1_Handler(void) __attribute__((weak, alias("Dummy_Handler")));  /* EIC_EXTINT_1 */
+void EIC_2_Handler(void) __attribute__((weak, alias("Dummy_Handler")));  /* EIC_EXTINT_2 */
+void EIC_3_Handler(void) __attribute__((weak, alias("Dummy_Handler")));  /* EIC_EXTINT_3 */
+void EIC_4_Handler(void) __attribute__((weak, alias("Dummy_Handler")));  /* EIC_EXTINT_4 */
+void EIC_5_Handler(void) __attribute__((weak, alias("Dummy_Handler")));  /* EIC_EXTINT_5 */
+void EIC_6_Handler(void) __attribute__((weak, alias("Dummy_Handler")));  /* EIC_EXTINT_6 */
+void EIC_7_Handler(void) __attribute__((weak, alias("Dummy_Handler")));  /* EIC_EXTINT_7 */
+void EIC_8_Handler(void) __attribute__((weak, alias("Dummy_Handler")));  /* EIC_EXTINT_8 */
+void EIC_9_Handler(void) __attribute__((weak, alias("Dummy_Handler")));  /* EIC_EXTINT_9 */
+void EIC_10_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_10 */
+void EIC_11_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_11 */
+void EIC_12_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_12 */
+void EIC_13_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_13 */
+void EIC_14_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_14 */
+void EIC_15_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_15 */
+void FREQM_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void NVMCTRL_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* NVMCTRL_0, NVMCTRL_1, NVMCTRL_2, NVMCTRL_3, NVMCTRL_4, NVMCTRL_5, NVMCTRL_6, NVMCTRL_7 */
+void NVMCTRL_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* NVMCTRL_10, NVMCTRL_8, NVMCTRL_9 */
+void DMAC_0_Handler(void) __attribute__((weak, alias("Dummy_Handler")));    /* DMAC_SUSP_0, DMAC_TCMPL_0, DMAC_TERR_0 */
+void DMAC_1_Handler(void) __attribute__((weak, alias("Dummy_Handler")));    /* DMAC_SUSP_1, DMAC_TCMPL_1, DMAC_TERR_1 */
+void DMAC_2_Handler(void) __attribute__((weak, alias("Dummy_Handler")));    /* DMAC_SUSP_2, DMAC_TCMPL_2, DMAC_TERR_2 */
+void DMAC_3_Handler(void) __attribute__((weak, alias("Dummy_Handler")));    /* DMAC_SUSP_3, DMAC_TCMPL_3, DMAC_TERR_3 */
+void DMAC_4_Handler(void) __attribute__((weak, alias("Dummy_Handler")));    /* DMAC_SUSP_10, DMAC_SUSP_11, DMAC_SUSP_12, DMAC_SUSP_13, DMAC_SUSP_14, DMAC_SUSP_15, DMAC_SUSP_16, DMAC_SUSP_17, DMAC_SUSP_18, DMAC_SUSP_19, DMAC_SUSP_20, DMAC_SUSP_21, DMAC_SUSP_22, DMAC_SUSP_23, DMAC_SUSP_24, DMAC_SUSP_25, DMAC_SUSP_26, DMAC_SUSP_27, DMAC_SUSP_28, DMAC_SUSP_29, DMAC_SUSP_30, DMAC_SUSP_31, DMAC_SUSP_4, DMAC_SUSP_5, DMAC_SUSP_6, DMAC_SUSP_7, DMAC_SUSP_8, DMAC_SUSP_9, DMAC_TCMPL_10, DMAC_TCMPL_11, DMAC_TCMPL_12, DMAC_TCMPL_13, DMAC_TCMPL_14, DMAC_TCMPL_15, DMAC_TCMPL_16, DMAC_TCMPL_17, DMAC_TCMPL_18, DMAC_TCMPL_19, DMAC_TCMPL_20, DMAC_TCMPL_21, DMAC_TCMPL_22, DMAC_TCMPL_23, DMAC_TCMPL_24, DMAC_TCMPL_25, DMAC_TCMPL_26, DMAC_TCMPL_27, DMAC_TCMPL_28, DMAC_TCMPL_29, DMAC_TCMPL_30, DMAC_TCMPL_31, DMAC_TCMPL_4, DMAC_TCMPL_5, DMAC_TCMPL_6, DMAC_TCMPL_7, DMAC_TCMPL_8, DMAC_TCMPL_9, DMAC_TERR_10, DMAC_TERR_11, DMAC_TERR_12, DMAC_TERR_13, DMAC_TERR_14, DMAC_TERR_15, DMAC_TERR_16, DMAC_TERR_17,
+                                                                               DMAC_TERR_18, DMAC_TERR_19, DMAC_TERR_20, DMAC_TERR_21, DMAC_TERR_22, DMAC_TERR_23, DMAC_TERR_24, DMAC_TERR_25, DMAC_TERR_26, DMAC_TERR_27, DMAC_TERR_28, DMAC_TERR_29, DMAC_TERR_30, DMAC_TERR_31, DMAC_TERR_4, DMAC_TERR_5, DMAC_TERR_6, DMAC_TERR_7, DMAC_TERR_8, DMAC_TERR_9 */
+void EVSYS_0_Handler(void) __attribute__((weak, alias("Dummy_Handler")));   /* EVSYS_EVD_0, EVSYS_OVR_0 */
+void EVSYS_1_Handler(void) __attribute__((weak, alias("Dummy_Handler")));   /* EVSYS_EVD_1, EVSYS_OVR_1 */
+void EVSYS_2_Handler(void) __attribute__((weak, alias("Dummy_Handler")));   /* EVSYS_EVD_2, EVSYS_OVR_2 */
+void EVSYS_3_Handler(void) __attribute__((weak, alias("Dummy_Handler")));   /* EVSYS_EVD_3, EVSYS_OVR_3 */
+void EVSYS_4_Handler(void) __attribute__((weak, alias("Dummy_Handler")));   /* EVSYS_EVD_10, EVSYS_EVD_11, EVSYS_EVD_4, EVSYS_EVD_5, EVSYS_EVD_6, EVSYS_EVD_7, EVSYS_EVD_8, EVSYS_EVD_9, EVSYS_OVR_10, EVSYS_OVR_11, EVSYS_OVR_4, EVSYS_OVR_5, EVSYS_OVR_6, EVSYS_OVR_7, EVSYS_OVR_8, EVSYS_OVR_9 */
+void PAC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void TAL_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TAL_BRK */
+void TAL_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TAL_IPS_0, TAL_IPS_1 */
+void RAMECC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void SERCOM0_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM0_0 */
+void SERCOM0_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM0_1 */
+void SERCOM0_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM0_2 */
+void SERCOM0_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM0_3, SERCOM0_4, SERCOM0_5, SERCOM0_6 */
+void SERCOM1_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM1_0 */
+void SERCOM1_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM1_1 */
+void SERCOM1_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM1_2 */
+void SERCOM1_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM1_3, SERCOM1_4, SERCOM1_5, SERCOM1_6 */
+void SERCOM2_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM2_0 */
+void SERCOM2_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM2_1 */
+void SERCOM2_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM2_2 */
+void SERCOM2_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM2_3, SERCOM2_4, SERCOM2_5, SERCOM2_6 */
+void SERCOM3_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM3_0 */
+void SERCOM3_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM3_1 */
+void SERCOM3_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM3_2 */
+void SERCOM3_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM3_3, SERCOM3_4, SERCOM3_5, SERCOM3_6 */
 #ifdef ID_SERCOM4
-void SERCOM4_0_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM4_0 */
-void SERCOM4_1_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM4_1 */
-void SERCOM4_2_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM4_2 */
-void SERCOM4_3_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM4_3, SERCOM4_4, SERCOM4_5, SERCOM4_6 */
+void SERCOM4_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM4_0 */
+void SERCOM4_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM4_1 */
+void SERCOM4_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM4_2 */
+void SERCOM4_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM4_3, SERCOM4_4, SERCOM4_5, SERCOM4_6 */
 #endif
 #ifdef ID_SERCOM5
-void SERCOM5_0_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM5_0 */
-void SERCOM5_1_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM5_1 */
-void SERCOM5_2_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM5_2 */
-void SERCOM5_3_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM5_3, SERCOM5_4, SERCOM5_5, SERCOM5_6 */
+void SERCOM5_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM5_0 */
+void SERCOM5_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM5_1 */
+void SERCOM5_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM5_2 */
+void SERCOM5_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM5_3, SERCOM5_4, SERCOM5_5, SERCOM5_6 */
 #endif
 #ifdef ID_SERCOM6
-void SERCOM6_0_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM6_0 */
-void SERCOM6_1_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM6_1 */
-void SERCOM6_2_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM6_2 */
-void SERCOM6_3_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM6_3, SERCOM6_4, SERCOM6_5, SERCOM6_6 */
+void SERCOM6_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM6_0 */
+void SERCOM6_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM6_1 */
+void SERCOM6_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM6_2 */
+void SERCOM6_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM6_3, SERCOM6_4, SERCOM6_5, SERCOM6_6 */
 #endif
 #ifdef ID_SERCOM7
-void SERCOM7_0_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM7_0 */
-void SERCOM7_1_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM7_1 */
-void SERCOM7_2_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM7_2 */
-void SERCOM7_3_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM7_3, SERCOM7_4, SERCOM7_5, SERCOM7_6 */
+void SERCOM7_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM7_0 */
+void SERCOM7_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM7_1 */
+void SERCOM7_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM7_2 */
+void SERCOM7_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM7_3, SERCOM7_4, SERCOM7_5, SERCOM7_6 */
 #endif
 #ifdef ID_CAN0
-void CAN0_Handler            ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void CAN0_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #endif
 #ifdef ID_CAN1
-void CAN1_Handler            ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void CAN1_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #endif
 #ifdef ID_USB
-void USB_0_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* USB_EORSM_DNRSM, USB_EORST_RST, USB_LPMSUSP_DDISC, USB_LPM_DCONN, USB_MSOF, USB_RAMACER, USB_RXSTP_TXSTP_0, USB_RXSTP_TXSTP_1, USB_RXSTP_TXSTP_2, USB_RXSTP_TXSTP_3, USB_RXSTP_TXSTP_4, USB_RXSTP_TXSTP_5, USB_RXSTP_TXSTP_6, USB_RXSTP_TXSTP_7, USB_STALL0_STALL_0, USB_STALL0_STALL_1, USB_STALL0_STALL_2, USB_STALL0_STALL_3, USB_STALL0_STALL_4, USB_STALL0_STALL_5, USB_STALL0_STALL_6, USB_STALL0_STALL_7, USB_STALL1_0, USB_STALL1_1, USB_STALL1_2, USB_STALL1_3, USB_STALL1_4, USB_STALL1_5, USB_STALL1_6, USB_STALL1_7, USB_SUSPEND, USB_TRFAIL0_TRFAIL_0, USB_TRFAIL0_TRFAIL_1, USB_TRFAIL0_TRFAIL_2, USB_TRFAIL0_TRFAIL_3, USB_TRFAIL0_TRFAIL_4, USB_TRFAIL0_TRFAIL_5, USB_TRFAIL0_TRFAIL_6, USB_TRFAIL0_TRFAIL_7, USB_TRFAIL1_PERR_0, USB_TRFAIL1_PERR_1, USB_TRFAIL1_PERR_2, USB_TRFAIL1_PERR_3, USB_TRFAIL1_PERR_4, USB_TRFAIL1_PERR_5, USB_TRFAIL1_PERR_6, USB_TRFAIL1_PERR_7, USB_UPRSM, USB_WAKEUP */
-void USB_1_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* USB_SOF_HSOF */
-void USB_2_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* USB_TRCPT0_0, USB_TRCPT0_1, USB_TRCPT0_2, USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5, USB_TRCPT0_6, USB_TRCPT0_7 */
-void USB_3_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* USB_TRCPT1_0, USB_TRCPT1_1, USB_TRCPT1_2, USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5, USB_TRCPT1_6, USB_TRCPT1_7 */
+void USB_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* USB_EORSM_DNRSM, USB_EORST_RST, USB_LPMSUSP_DDISC, USB_LPM_DCONN, USB_MSOF, USB_RAMACER, USB_RXSTP_TXSTP_0, USB_RXSTP_TXSTP_1, USB_RXSTP_TXSTP_2, USB_RXSTP_TXSTP_3, USB_RXSTP_TXSTP_4, USB_RXSTP_TXSTP_5, USB_RXSTP_TXSTP_6, USB_RXSTP_TXSTP_7, USB_STALL0_STALL_0, USB_STALL0_STALL_1, USB_STALL0_STALL_2, USB_STALL0_STALL_3, USB_STALL0_STALL_4, USB_STALL0_STALL_5, USB_STALL0_STALL_6, USB_STALL0_STALL_7, USB_STALL1_0, USB_STALL1_1, USB_STALL1_2, USB_STALL1_3, USB_STALL1_4, USB_STALL1_5, USB_STALL1_6, USB_STALL1_7, USB_SUSPEND, USB_TRFAIL0_TRFAIL_0, USB_TRFAIL0_TRFAIL_1, USB_TRFAIL0_TRFAIL_2, USB_TRFAIL0_TRFAIL_3, USB_TRFAIL0_TRFAIL_4, USB_TRFAIL0_TRFAIL_5, USB_TRFAIL0_TRFAIL_6, USB_TRFAIL0_TRFAIL_7, USB_TRFAIL1_PERR_0, USB_TRFAIL1_PERR_1, USB_TRFAIL1_PERR_2, USB_TRFAIL1_PERR_3, USB_TRFAIL1_PERR_4, USB_TRFAIL1_PERR_5, USB_TRFAIL1_PERR_6, USB_TRFAIL1_PERR_7, USB_UPRSM, USB_WAKEUP */
+void USB_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* USB_SOF_HSOF */
+void USB_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* USB_TRCPT0_0, USB_TRCPT0_1, USB_TRCPT0_2, USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5, USB_TRCPT0_6, USB_TRCPT0_7 */
+void USB_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* USB_TRCPT1_0, USB_TRCPT1_1, USB_TRCPT1_2, USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5, USB_TRCPT1_6, USB_TRCPT1_7 */
 #endif
 #ifdef ID_GMAC
-void GMAC_Handler            ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-#endif
-void TCC0_0_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_CNT_A, TCC0_DFS_A, TCC0_ERR_A, TCC0_FAULT0_A, TCC0_FAULT1_A, TCC0_FAULTA_A, TCC0_FAULTB_A, TCC0_OVF, TCC0_TRG, TCC0_UFS_A */
-void TCC0_1_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_0 */
-void TCC0_2_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_1 */
-void TCC0_3_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_2 */
-void TCC0_4_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_3 */
-void TCC0_5_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_4 */
-void TCC0_6_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_5 */
-void TCC1_0_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC1_CNT_A, TCC1_DFS_A, TCC1_ERR_A, TCC1_FAULT0_A, TCC1_FAULT1_A, TCC1_FAULTA_A, TCC1_FAULTB_A, TCC1_OVF, TCC1_TRG, TCC1_UFS_A */
-void TCC1_1_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC1_MC_0 */
-void TCC1_2_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC1_MC_1 */
-void TCC1_3_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC1_MC_2 */
-void TCC1_4_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC1_MC_3 */
-void TCC2_0_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC2_CNT_A, TCC2_DFS_A, TCC2_ERR_A, TCC2_FAULT0_A, TCC2_FAULT1_A, TCC2_FAULTA_A, TCC2_FAULTB_A, TCC2_OVF, TCC2_TRG, TCC2_UFS_A */
-void TCC2_1_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC2_MC_0 */
-void TCC2_2_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC2_MC_1 */
-void TCC2_3_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC2_MC_2 */
+void GMAC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+#endif
+void TCC0_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_CNT_A, TCC0_DFS_A, TCC0_ERR_A, TCC0_FAULT0_A, TCC0_FAULT1_A, TCC0_FAULTA_A, TCC0_FAULTB_A, TCC0_OVF, TCC0_TRG, TCC0_UFS_A */
+void TCC0_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_0 */
+void TCC0_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_1 */
+void TCC0_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_2 */
+void TCC0_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_3 */
+void TCC0_5_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_4 */
+void TCC0_6_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_5 */
+void TCC1_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC1_CNT_A, TCC1_DFS_A, TCC1_ERR_A, TCC1_FAULT0_A, TCC1_FAULT1_A, TCC1_FAULTA_A, TCC1_FAULTB_A, TCC1_OVF, TCC1_TRG, TCC1_UFS_A */
+void TCC1_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC1_MC_0 */
+void TCC1_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC1_MC_1 */
+void TCC1_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC1_MC_2 */
+void TCC1_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC1_MC_3 */
+void TCC2_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC2_CNT_A, TCC2_DFS_A, TCC2_ERR_A, TCC2_FAULT0_A, TCC2_FAULT1_A, TCC2_FAULTA_A, TCC2_FAULTB_A, TCC2_OVF, TCC2_TRG, TCC2_UFS_A */
+void TCC2_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC2_MC_0 */
+void TCC2_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC2_MC_1 */
+void TCC2_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC2_MC_2 */
 #ifdef ID_TCC3
-void TCC3_0_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC3_CNT_A, TCC3_DFS_A, TCC3_ERR_A, TCC3_FAULT0_A, TCC3_FAULT1_A, TCC3_FAULTA_A, TCC3_FAULTB_A, TCC3_OVF, TCC3_TRG, TCC3_UFS_A */
-void TCC3_1_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC3_MC_0 */
-void TCC3_2_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC3_MC_1 */
+void TCC3_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC3_CNT_A, TCC3_DFS_A, TCC3_ERR_A, TCC3_FAULT0_A, TCC3_FAULT1_A, TCC3_FAULTA_A, TCC3_FAULTB_A, TCC3_OVF, TCC3_TRG, TCC3_UFS_A */
+void TCC3_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC3_MC_0 */
+void TCC3_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC3_MC_1 */
 #endif
 #ifdef ID_TCC4
-void TCC4_0_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC4_CNT_A, TCC4_DFS_A, TCC4_ERR_A, TCC4_FAULT0_A, TCC4_FAULT1_A, TCC4_FAULTA_A, TCC4_FAULTB_A, TCC4_OVF, TCC4_TRG, TCC4_UFS_A */
-void TCC4_1_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC4_MC_0 */
-void TCC4_2_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC4_MC_1 */
-#endif
-void TC0_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void TC1_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void TC2_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void TC3_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void TCC4_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC4_CNT_A, TCC4_DFS_A, TCC4_ERR_A, TCC4_FAULT0_A, TCC4_FAULT1_A, TCC4_FAULTA_A, TCC4_FAULTB_A, TCC4_OVF, TCC4_TRG, TCC4_UFS_A */
+void TCC4_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC4_MC_0 */
+void TCC4_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC4_MC_1 */
+#endif
+void TC0_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void TC1_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void TC2_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void TC3_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #ifdef ID_TC4
-void TC4_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void TC4_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #endif
 #ifdef ID_TC5
-void TC5_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void TC5_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #endif
 #ifdef ID_TC6
-void TC6_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void TC6_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #endif
 #ifdef ID_TC7
-void TC7_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-#endif
-void PDEC_0_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* PDEC_DIR_A, PDEC_ERR_A, PDEC_OVF, PDEC_VLC_A */
-void PDEC_1_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* PDEC_MC_0 */
-void PDEC_2_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* PDEC_MC_1 */
-void ADC0_0_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* ADC0_OVERRUN, ADC0_WINMON */
-void ADC0_1_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* ADC0_RESRDY */
-void ADC1_0_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* ADC1_OVERRUN, ADC1_WINMON */
-void ADC1_1_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* ADC1_RESRDY */
-void AC_Handler              ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void DAC_0_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DAC_OVERRUN_A_0, DAC_OVERRUN_A_1, DAC_UNDERRUN_A_0, DAC_UNDERRUN_A_1 */
-void DAC_1_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DAC_EMPTY_0 */
-void DAC_2_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DAC_EMPTY_1 */
-void DAC_3_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DAC_RESRDY_0 */
-void DAC_4_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DAC_RESRDY_1 */
+void TC7_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+#endif
+void PDEC_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* PDEC_DIR_A, PDEC_ERR_A, PDEC_OVF, PDEC_VLC_A */
+void PDEC_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* PDEC_MC_0 */
+void PDEC_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* PDEC_MC_1 */
+void ADC0_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* ADC0_OVERRUN, ADC0_WINMON */
+void ADC0_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* ADC0_RESRDY */
+void ADC1_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* ADC1_OVERRUN, ADC1_WINMON */
+void ADC1_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* ADC1_RESRDY */
+void AC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void DAC_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DAC_OVERRUN_A_0, DAC_OVERRUN_A_1, DAC_UNDERRUN_A_0, DAC_UNDERRUN_A_1 */
+void DAC_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DAC_EMPTY_0 */
+void DAC_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DAC_EMPTY_1 */
+void DAC_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DAC_RESRDY_0 */
+void DAC_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DAC_RESRDY_1 */
 #ifdef ID_I2S
-void I2S_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void I2S_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #endif
-void PCC_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void AES_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
-void TRNG_Handler            ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void PCC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void AES_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
+void TRNG_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #ifdef ID_ICM
-void ICM_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void ICM_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #endif
 #ifdef ID_PUKCC
-void PUKCC_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void PUKCC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #endif
-void QSPI_Handler            ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void QSPI_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #ifdef ID_SDHC0
-void SDHC0_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void SDHC0_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #endif
 #ifdef ID_SDHC1
-void SDHC1_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
+void SDHC1_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
 #endif
 
 /* Exception Table */
-__attribute__ ((section(".vectors")))
-const DeviceVectors exception_table = {
+__attribute__((section(".vectors"))) const DeviceVectors exception_table = {
 
-        /* Configure Initial Stack Pointer, using linker-generated symbols */
-        .pvStack                = (void*) (&_estack),
+    /* Configure Initial Stack Pointer, using linker-generated symbols */
+    .pvStack = (void *)(&_estack),
 
-        .pfnReset_Handler       = (void*) Reset_Handler,
-        .pfnNMI_Handler         = (void*) NMI_Handler,
-        .pfnHardFault_Handler   = (void*) HardFault_Handler,
-        .pfnMemManage_Handler   = (void*) MemManage_Handler,
-        .pfnBusFault_Handler    = (void*) BusFault_Handler,
-        .pfnUsageFault_Handler  = (void*) UsageFault_Handler,
-        .pvReservedM9           = (void*) (0UL), /* Reserved */
-        .pvReservedM8           = (void*) (0UL), /* Reserved */
-        .pvReservedM7           = (void*) (0UL), /* Reserved */
-        .pvReservedM6           = (void*) (0UL), /* Reserved */
-        .pfnSVC_Handler         = (void*) SVC_Handler,
-        .pfnDebugMon_Handler    = (void*) DebugMon_Handler,
-        .pvReservedM3           = (void*) (0UL), /* Reserved */
-        .pfnPendSV_Handler      = (void*) PendSV_Handler,
-        .pfnSysTick_Handler     = (void*) SysTick_Handler,
+    .pfnReset_Handler      = (void *)Reset_Handler,
+    .pfnNMI_Handler        = (void *)NMI_Handler,
+    .pfnHardFault_Handler  = (void *)HardFault_Handler,
+    .pfnMemManage_Handler  = (void *)MemManage_Handler,
+    .pfnBusFault_Handler   = (void *)BusFault_Handler,
+    .pfnUsageFault_Handler = (void *)UsageFault_Handler,
+    .pvReservedM9          = (void *)(0UL), /* Reserved */
+    .pvReservedM8          = (void *)(0UL), /* Reserved */
+    .pvReservedM7          = (void *)(0UL), /* Reserved */
+    .pvReservedM6          = (void *)(0UL), /* Reserved */
+    .pfnSVC_Handler        = (void *)SVC_Handler,
+    .pfnDebugMon_Handler   = (void *)DebugMon_Handler,
+    .pvReservedM3          = (void *)(0UL), /* Reserved */
+    .pfnPendSV_Handler     = (void *)PendSV_Handler,
+    .pfnSysTick_Handler    = (void *)SysTick_Handler,
 
-        /* Configurable interrupts */
-        .pfnPM_Handler          = (void*) PM_Handler,             /*  0 Power Manager */
-        .pfnMCLK_Handler        = (void*) MCLK_Handler,           /*  1 Main Clock */
-        .pfnOSCCTRL_0_Handler   = (void*) OSCCTRL_0_Handler,      /*  2 OSCCTRL_XOSCFAIL_0, OSCCTRL_XOSCRDY_0 */
-        .pfnOSCCTRL_1_Handler   = (void*) OSCCTRL_1_Handler,      /*  3 OSCCTRL_XOSCFAIL_1, OSCCTRL_XOSCRDY_1 */
-        .pfnOSCCTRL_2_Handler   = (void*) OSCCTRL_2_Handler,      /*  4 OSCCTRL_DFLLLOCKC, OSCCTRL_DFLLLOCKF, OSCCTRL_DFLLOOB, OSCCTRL_DFLLRCS, OSCCTRL_DFLLRDY */
-        .pfnOSCCTRL_3_Handler   = (void*) OSCCTRL_3_Handler,      /*  5 OSCCTRL_DPLLLCKF_0, OSCCTRL_DPLLLCKR_0, OSCCTRL_DPLLLDRTO_0, OSCCTRL_DPLLLTO_0 */
-        .pfnOSCCTRL_4_Handler   = (void*) OSCCTRL_4_Handler,      /*  6 OSCCTRL_DPLLLCKF_1, OSCCTRL_DPLLLCKR_1, OSCCTRL_DPLLLDRTO_1, OSCCTRL_DPLLLTO_1 */
-        .pfnOSC32KCTRL_Handler  = (void*) OSC32KCTRL_Handler,     /*  7 32kHz Oscillators Control */
-        .pfnSUPC_0_Handler      = (void*) SUPC_0_Handler,         /*  8 SUPC_B12SRDY, SUPC_B33SRDY, SUPC_BOD12RDY, SUPC_BOD33RDY, SUPC_VCORERDY, SUPC_VREGRDY */
-        .pfnSUPC_1_Handler      = (void*) SUPC_1_Handler,         /*  9 SUPC_BOD12DET, SUPC_BOD33DET */
-        .pfnWDT_Handler         = (void*) WDT_Handler,            /* 10 Watchdog Timer */
-        .pfnRTC_Handler         = (void*) RTC_Handler,            /* 11 Real-Time Counter */
-        .pfnEIC_0_Handler       = (void*) EIC_0_Handler,          /* 12 EIC_EXTINT_0 */
-        .pfnEIC_1_Handler       = (void*) EIC_1_Handler,          /* 13 EIC_EXTINT_1 */
-        .pfnEIC_2_Handler       = (void*) EIC_2_Handler,          /* 14 EIC_EXTINT_2 */
-        .pfnEIC_3_Handler       = (void*) EIC_3_Handler,          /* 15 EIC_EXTINT_3 */
-        .pfnEIC_4_Handler       = (void*) EIC_4_Handler,          /* 16 EIC_EXTINT_4 */
-        .pfnEIC_5_Handler       = (void*) EIC_5_Handler,          /* 17 EIC_EXTINT_5 */
-        .pfnEIC_6_Handler       = (void*) EIC_6_Handler,          /* 18 EIC_EXTINT_6 */
-        .pfnEIC_7_Handler       = (void*) EIC_7_Handler,          /* 19 EIC_EXTINT_7 */
-        .pfnEIC_8_Handler       = (void*) EIC_8_Handler,          /* 20 EIC_EXTINT_8 */
-        .pfnEIC_9_Handler       = (void*) EIC_9_Handler,          /* 21 EIC_EXTINT_9 */
-        .pfnEIC_10_Handler      = (void*) EIC_10_Handler,         /* 22 EIC_EXTINT_10 */
-        .pfnEIC_11_Handler      = (void*) EIC_11_Handler,         /* 23 EIC_EXTINT_11 */
-        .pfnEIC_12_Handler      = (void*) EIC_12_Handler,         /* 24 EIC_EXTINT_12 */
-        .pfnEIC_13_Handler      = (void*) EIC_13_Handler,         /* 25 EIC_EXTINT_13 */
-        .pfnEIC_14_Handler      = (void*) EIC_14_Handler,         /* 26 EIC_EXTINT_14 */
-        .pfnEIC_15_Handler      = (void*) EIC_15_Handler,         /* 27 EIC_EXTINT_15 */
-        .pfnFREQM_Handler       = (void*) FREQM_Handler,          /* 28 Frequency Meter */
-        .pfnNVMCTRL_0_Handler   = (void*) NVMCTRL_0_Handler,      /* 29 NVMCTRL_0, NVMCTRL_1, NVMCTRL_2, NVMCTRL_3, NVMCTRL_4, NVMCTRL_5, NVMCTRL_6, NVMCTRL_7 */
-        .pfnNVMCTRL_1_Handler   = (void*) NVMCTRL_1_Handler,      /* 30 NVMCTRL_10, NVMCTRL_8, NVMCTRL_9 */
-        .pfnDMAC_0_Handler      = (void*) DMAC_0_Handler,         /* 31 DMAC_SUSP_0, DMAC_TCMPL_0, DMAC_TERR_0 */
-        .pfnDMAC_1_Handler      = (void*) DMAC_1_Handler,         /* 32 DMAC_SUSP_1, DMAC_TCMPL_1, DMAC_TERR_1 */
-        .pfnDMAC_2_Handler      = (void*) DMAC_2_Handler,         /* 33 DMAC_SUSP_2, DMAC_TCMPL_2, DMAC_TERR_2 */
-        .pfnDMAC_3_Handler      = (void*) DMAC_3_Handler,         /* 34 DMAC_SUSP_3, DMAC_TCMPL_3, DMAC_TERR_3 */
-        .pfnDMAC_4_Handler      = (void*) DMAC_4_Handler,         /* 35 DMAC_SUSP_10, DMAC_SUSP_11, DMAC_SUSP_12, DMAC_SUSP_13, DMAC_SUSP_14, DMAC_SUSP_15, DMAC_SUSP_16, DMAC_SUSP_17, DMAC_SUSP_18, DMAC_SUSP_19, DMAC_SUSP_20, DMAC_SUSP_21, DMAC_SUSP_22, DMAC_SUSP_23, DMAC_SUSP_24, DMAC_SUSP_25, DMAC_SUSP_26, DMAC_SUSP_27, DMAC_SUSP_28, DMAC_SUSP_29, DMAC_SUSP_30, DMAC_SUSP_31, DMAC_SUSP_4, DMAC_SUSP_5, DMAC_SUSP_6, DMAC_SUSP_7, DMAC_SUSP_8, DMAC_SUSP_9, DMAC_TCMPL_10, DMAC_TCMPL_11, DMAC_TCMPL_12, DMAC_TCMPL_13, DMAC_TCMPL_14, DMAC_TCMPL_15, DMAC_TCMPL_16, DMAC_TCMPL_17, DMAC_TCMPL_18, DMAC_TCMPL_19, DMAC_TCMPL_20, DMAC_TCMPL_21, DMAC_TCMPL_22, DMAC_TCMPL_23, DMAC_TCMPL_24, DMAC_TCMPL_25, DMAC_TCMPL_26, DMAC_TCMPL_27, DMAC_TCMPL_28, DMAC_TCMPL_29, DMAC_TCMPL_30, DMAC_TCMPL_31, DMAC_TCMPL_4, DMAC_TCMPL_5, DMAC_TCMPL_6, DMAC_TCMPL_7, DMAC_TCMPL_8, DMAC_TCMPL_9, DMAC_TERR_10, DMAC_TERR_11, DMAC_TERR_12, DMAC_TERR_13, DMAC_TERR_14, DMAC_TERR_15, DMAC_TERR_16, DMAC_TERR_17, DMAC_TERR_18, DMAC_TERR_19, DMAC_TERR_20, DMAC_TERR_21, DMAC_TERR_22, DMAC_TERR_23, DMAC_TERR_24, DMAC_TERR_25, DMAC_TERR_26, DMAC_TERR_27, DMAC_TERR_28, DMAC_TERR_29, DMAC_TERR_30, DMAC_TERR_31, DMAC_TERR_4, DMAC_TERR_5, DMAC_TERR_6, DMAC_TERR_7, DMAC_TERR_8, DMAC_TERR_9 */
-        .pfnEVSYS_0_Handler     = (void*) EVSYS_0_Handler,        /* 36 EVSYS_EVD_0, EVSYS_OVR_0 */
-        .pfnEVSYS_1_Handler     = (void*) EVSYS_1_Handler,        /* 37 EVSYS_EVD_1, EVSYS_OVR_1 */
-        .pfnEVSYS_2_Handler     = (void*) EVSYS_2_Handler,        /* 38 EVSYS_EVD_2, EVSYS_OVR_2 */
-        .pfnEVSYS_3_Handler     = (void*) EVSYS_3_Handler,        /* 39 EVSYS_EVD_3, EVSYS_OVR_3 */
-        .pfnEVSYS_4_Handler     = (void*) EVSYS_4_Handler,        /* 40 EVSYS_EVD_10, EVSYS_EVD_11, EVSYS_EVD_4, EVSYS_EVD_5, EVSYS_EVD_6, EVSYS_EVD_7, EVSYS_EVD_8, EVSYS_EVD_9, EVSYS_OVR_10, EVSYS_OVR_11, EVSYS_OVR_4, EVSYS_OVR_5, EVSYS_OVR_6, EVSYS_OVR_7, EVSYS_OVR_8, EVSYS_OVR_9 */
-        .pfnPAC_Handler         = (void*) PAC_Handler,            /* 41 Peripheral Access Controller */
-        .pfnTAL_0_Handler       = (void*) TAL_0_Handler,          /* 42 TAL_BRK */
-        .pfnTAL_1_Handler       = (void*) TAL_1_Handler,          /* 43 TAL_IPS_0, TAL_IPS_1 */
-        .pvReserved44           = (void*) (0UL),                  /* 44 Reserved */
-        .pfnRAMECC_Handler      = (void*) RAMECC_Handler,         /* 45 RAM ECC */
-        .pfnSERCOM0_0_Handler   = (void*) SERCOM0_0_Handler,      /* 46 SERCOM0_0 */
-        .pfnSERCOM0_1_Handler   = (void*) SERCOM0_1_Handler,      /* 47 SERCOM0_1 */
-        .pfnSERCOM0_2_Handler   = (void*) SERCOM0_2_Handler,      /* 48 SERCOM0_2 */
-        .pfnSERCOM0_3_Handler   = (void*) SERCOM0_3_Handler,      /* 49 SERCOM0_3, SERCOM0_4, SERCOM0_5, SERCOM0_6 */
-        .pfnSERCOM1_0_Handler   = (void*) SERCOM1_0_Handler,      /* 50 SERCOM1_0 */
-        .pfnSERCOM1_1_Handler   = (void*) SERCOM1_1_Handler,      /* 51 SERCOM1_1 */
-        .pfnSERCOM1_2_Handler   = (void*) SERCOM1_2_Handler,      /* 52 SERCOM1_2 */
-        .pfnSERCOM1_3_Handler   = (void*) SERCOM1_3_Handler,      /* 53 SERCOM1_3, SERCOM1_4, SERCOM1_5, SERCOM1_6 */
-        .pfnSERCOM2_0_Handler   = (void*) SERCOM2_0_Handler,      /* 54 SERCOM2_0 */
-        .pfnSERCOM2_1_Handler   = (void*) SERCOM2_1_Handler,      /* 55 SERCOM2_1 */
-        .pfnSERCOM2_2_Handler   = (void*) SERCOM2_2_Handler,      /* 56 SERCOM2_2 */
-        .pfnSERCOM2_3_Handler   = (void*) SERCOM2_3_Handler,      /* 57 SERCOM2_3, SERCOM2_4, SERCOM2_5, SERCOM2_6 */
-        .pfnSERCOM3_0_Handler   = (void*) SERCOM3_0_Handler,      /* 58 SERCOM3_0 */
-        .pfnSERCOM3_1_Handler   = (void*) SERCOM3_1_Handler,      /* 59 SERCOM3_1 */
-        .pfnSERCOM3_2_Handler   = (void*) SERCOM3_2_Handler,      /* 60 SERCOM3_2 */
-        .pfnSERCOM3_3_Handler   = (void*) SERCOM3_3_Handler,      /* 61 SERCOM3_3, SERCOM3_4, SERCOM3_5, SERCOM3_6 */
+    /* Configurable interrupts */
+    .pfnPM_Handler         = (void *)PM_Handler,         /*  0 Power Manager */
+    .pfnMCLK_Handler       = (void *)MCLK_Handler,       /*  1 Main Clock */
+    .pfnOSCCTRL_0_Handler  = (void *)OSCCTRL_0_Handler,  /*  2 OSCCTRL_XOSCFAIL_0, OSCCTRL_XOSCRDY_0 */
+    .pfnOSCCTRL_1_Handler  = (void *)OSCCTRL_1_Handler,  /*  3 OSCCTRL_XOSCFAIL_1, OSCCTRL_XOSCRDY_1 */
+    .pfnOSCCTRL_2_Handler  = (void *)OSCCTRL_2_Handler,  /*  4 OSCCTRL_DFLLLOCKC, OSCCTRL_DFLLLOCKF, OSCCTRL_DFLLOOB, OSCCTRL_DFLLRCS, OSCCTRL_DFLLRDY */
+    .pfnOSCCTRL_3_Handler  = (void *)OSCCTRL_3_Handler,  /*  5 OSCCTRL_DPLLLCKF_0, OSCCTRL_DPLLLCKR_0, OSCCTRL_DPLLLDRTO_0, OSCCTRL_DPLLLTO_0 */
+    .pfnOSCCTRL_4_Handler  = (void *)OSCCTRL_4_Handler,  /*  6 OSCCTRL_DPLLLCKF_1, OSCCTRL_DPLLLCKR_1, OSCCTRL_DPLLLDRTO_1, OSCCTRL_DPLLLTO_1 */
+    .pfnOSC32KCTRL_Handler = (void *)OSC32KCTRL_Handler, /*  7 32kHz Oscillators Control */
+    .pfnSUPC_0_Handler     = (void *)SUPC_0_Handler,     /*  8 SUPC_B12SRDY, SUPC_B33SRDY, SUPC_BOD12RDY, SUPC_BOD33RDY, SUPC_VCORERDY, SUPC_VREGRDY */
+    .pfnSUPC_1_Handler     = (void *)SUPC_1_Handler,     /*  9 SUPC_BOD12DET, SUPC_BOD33DET */
+    .pfnWDT_Handler        = (void *)WDT_Handler,        /* 10 Watchdog Timer */
+    .pfnRTC_Handler        = (void *)RTC_Handler,        /* 11 Real-Time Counter */
+    .pfnEIC_0_Handler      = (void *)EIC_0_Handler,      /* 12 EIC_EXTINT_0 */
+    .pfnEIC_1_Handler      = (void *)EIC_1_Handler,      /* 13 EIC_EXTINT_1 */
+    .pfnEIC_2_Handler      = (void *)EIC_2_Handler,      /* 14 EIC_EXTINT_2 */
+    .pfnEIC_3_Handler      = (void *)EIC_3_Handler,      /* 15 EIC_EXTINT_3 */
+    .pfnEIC_4_Handler      = (void *)EIC_4_Handler,      /* 16 EIC_EXTINT_4 */
+    .pfnEIC_5_Handler      = (void *)EIC_5_Handler,      /* 17 EIC_EXTINT_5 */
+    .pfnEIC_6_Handler      = (void *)EIC_6_Handler,      /* 18 EIC_EXTINT_6 */
+    .pfnEIC_7_Handler      = (void *)EIC_7_Handler,      /* 19 EIC_EXTINT_7 */
+    .pfnEIC_8_Handler      = (void *)EIC_8_Handler,      /* 20 EIC_EXTINT_8 */
+    .pfnEIC_9_Handler      = (void *)EIC_9_Handler,      /* 21 EIC_EXTINT_9 */
+    .pfnEIC_10_Handler     = (void *)EIC_10_Handler,     /* 22 EIC_EXTINT_10 */
+    .pfnEIC_11_Handler     = (void *)EIC_11_Handler,     /* 23 EIC_EXTINT_11 */
+    .pfnEIC_12_Handler     = (void *)EIC_12_Handler,     /* 24 EIC_EXTINT_12 */
+    .pfnEIC_13_Handler     = (void *)EIC_13_Handler,     /* 25 EIC_EXTINT_13 */
+    .pfnEIC_14_Handler     = (void *)EIC_14_Handler,     /* 26 EIC_EXTINT_14 */
+    .pfnEIC_15_Handler     = (void *)EIC_15_Handler,     /* 27 EIC_EXTINT_15 */
+    .pfnFREQM_Handler      = (void *)FREQM_Handler,      /* 28 Frequency Meter */
+    .pfnNVMCTRL_0_Handler  = (void *)NVMCTRL_0_Handler,  /* 29 NVMCTRL_0, NVMCTRL_1, NVMCTRL_2, NVMCTRL_3, NVMCTRL_4, NVMCTRL_5, NVMCTRL_6, NVMCTRL_7 */
+    .pfnNVMCTRL_1_Handler  = (void *)NVMCTRL_1_Handler,  /* 30 NVMCTRL_10, NVMCTRL_8, NVMCTRL_9 */
+    .pfnDMAC_0_Handler     = (void *)DMAC_0_Handler,     /* 31 DMAC_SUSP_0, DMAC_TCMPL_0, DMAC_TERR_0 */
+    .pfnDMAC_1_Handler     = (void *)DMAC_1_Handler,     /* 32 DMAC_SUSP_1, DMAC_TCMPL_1, DMAC_TERR_1 */
+    .pfnDMAC_2_Handler     = (void *)DMAC_2_Handler,     /* 33 DMAC_SUSP_2, DMAC_TCMPL_2, DMAC_TERR_2 */
+    .pfnDMAC_3_Handler     = (void *)DMAC_3_Handler,     /* 34 DMAC_SUSP_3, DMAC_TCMPL_3, DMAC_TERR_3 */
+    .pfnDMAC_4_Handler     = (void *)DMAC_4_Handler,   /* 35 DMAC_SUSP_10, DMAC_SUSP_11, DMAC_SUSP_12, DMAC_SUSP_13, DMAC_SUSP_14, DMAC_SUSP_15, DMAC_SUSP_16, DMAC_SUSP_17, DMAC_SUSP_18, DMAC_SUSP_19, DMAC_SUSP_20, DMAC_SUSP_21, DMAC_SUSP_22, DMAC_SUSP_23, DMAC_SUSP_24, DMAC_SUSP_25, DMAC_SUSP_26, DMAC_SUSP_27, DMAC_SUSP_28, DMAC_SUSP_29, DMAC_SUSP_30, DMAC_SUSP_31, DMAC_SUSP_4, DMAC_SUSP_5, DMAC_SUSP_6, DMAC_SUSP_7, DMAC_SUSP_8, DMAC_SUSP_9, DMAC_TCMPL_10, DMAC_TCMPL_11, DMAC_TCMPL_12, DMAC_TCMPL_13, DMAC_TCMPL_14, DMAC_TCMPL_15, DMAC_TCMPL_16, DMAC_TCMPL_17, DMAC_TCMPL_18, DMAC_TCMPL_19, DMAC_TCMPL_20, DMAC_TCMPL_21, DMAC_TCMPL_22, DMAC_TCMPL_23, DMAC_TCMPL_24, DMAC_TCMPL_25, DMAC_TCMPL_26, DMAC_TCMPL_27, DMAC_TCMPL_28, DMAC_TCMPL_29, DMAC_TCMPL_30, DMAC_TCMPL_31, DMAC_TCMPL_4, DMAC_TCMPL_5, DMAC_TCMPL_6, DMAC_TCMPL_7, DMAC_TCMPL_8, DMAC_TCMPL_9, DMAC_TERR_10, DMAC_TERR_11, DMAC_TERR_12, DMAC_TERR_13, DMAC_TERR_14, DMAC_TERR_15, DMAC_TERR_16, DMAC_TERR_17, DMAC_TERR_18, DMAC_TERR_19,
+                                                          DMAC_TERR_20, DMAC_TERR_21, DMAC_TERR_22, DMAC_TERR_23, DMAC_TERR_24, DMAC_TERR_25, DMAC_TERR_26, DMAC_TERR_27, DMAC_TERR_28, DMAC_TERR_29, DMAC_TERR_30, DMAC_TERR_31, DMAC_TERR_4, DMAC_TERR_5, DMAC_TERR_6, DMAC_TERR_7, DMAC_TERR_8, DMAC_TERR_9 */
+    .pfnEVSYS_0_Handler   = (void *)EVSYS_0_Handler,   /* 36 EVSYS_EVD_0, EVSYS_OVR_0 */
+    .pfnEVSYS_1_Handler   = (void *)EVSYS_1_Handler,   /* 37 EVSYS_EVD_1, EVSYS_OVR_1 */
+    .pfnEVSYS_2_Handler   = (void *)EVSYS_2_Handler,   /* 38 EVSYS_EVD_2, EVSYS_OVR_2 */
+    .pfnEVSYS_3_Handler   = (void *)EVSYS_3_Handler,   /* 39 EVSYS_EVD_3, EVSYS_OVR_3 */
+    .pfnEVSYS_4_Handler   = (void *)EVSYS_4_Handler,   /* 40 EVSYS_EVD_10, EVSYS_EVD_11, EVSYS_EVD_4, EVSYS_EVD_5, EVSYS_EVD_6, EVSYS_EVD_7, EVSYS_EVD_8, EVSYS_EVD_9, EVSYS_OVR_10, EVSYS_OVR_11, EVSYS_OVR_4, EVSYS_OVR_5, EVSYS_OVR_6, EVSYS_OVR_7, EVSYS_OVR_8, EVSYS_OVR_9 */
+    .pfnPAC_Handler       = (void *)PAC_Handler,       /* 41 Peripheral Access Controller */
+    .pfnTAL_0_Handler     = (void *)TAL_0_Handler,     /* 42 TAL_BRK */
+    .pfnTAL_1_Handler     = (void *)TAL_1_Handler,     /* 43 TAL_IPS_0, TAL_IPS_1 */
+    .pvReserved44         = (void *)(0UL),             /* 44 Reserved */
+    .pfnRAMECC_Handler    = (void *)RAMECC_Handler,    /* 45 RAM ECC */
+    .pfnSERCOM0_0_Handler = (void *)SERCOM0_0_Handler, /* 46 SERCOM0_0 */
+    .pfnSERCOM0_1_Handler = (void *)SERCOM0_1_Handler, /* 47 SERCOM0_1 */
+    .pfnSERCOM0_2_Handler = (void *)SERCOM0_2_Handler, /* 48 SERCOM0_2 */
+    .pfnSERCOM0_3_Handler = (void *)SERCOM0_3_Handler, /* 49 SERCOM0_3, SERCOM0_4, SERCOM0_5, SERCOM0_6 */
+    .pfnSERCOM1_0_Handler = (void *)SERCOM1_0_Handler, /* 50 SERCOM1_0 */
+    .pfnSERCOM1_1_Handler = (void *)SERCOM1_1_Handler, /* 51 SERCOM1_1 */
+    .pfnSERCOM1_2_Handler = (void *)SERCOM1_2_Handler, /* 52 SERCOM1_2 */
+    .pfnSERCOM1_3_Handler = (void *)SERCOM1_3_Handler, /* 53 SERCOM1_3, SERCOM1_4, SERCOM1_5, SERCOM1_6 */
+    .pfnSERCOM2_0_Handler = (void *)SERCOM2_0_Handler, /* 54 SERCOM2_0 */
+    .pfnSERCOM2_1_Handler = (void *)SERCOM2_1_Handler, /* 55 SERCOM2_1 */
+    .pfnSERCOM2_2_Handler = (void *)SERCOM2_2_Handler, /* 56 SERCOM2_2 */
+    .pfnSERCOM2_3_Handler = (void *)SERCOM2_3_Handler, /* 57 SERCOM2_3, SERCOM2_4, SERCOM2_5, SERCOM2_6 */
+    .pfnSERCOM3_0_Handler = (void *)SERCOM3_0_Handler, /* 58 SERCOM3_0 */
+    .pfnSERCOM3_1_Handler = (void *)SERCOM3_1_Handler, /* 59 SERCOM3_1 */
+    .pfnSERCOM3_2_Handler = (void *)SERCOM3_2_Handler, /* 60 SERCOM3_2 */
+    .pfnSERCOM3_3_Handler = (void *)SERCOM3_3_Handler, /* 61 SERCOM3_3, SERCOM3_4, SERCOM3_5, SERCOM3_6 */
 #ifdef ID_SERCOM4
-        .pfnSERCOM4_0_Handler   = (void*) SERCOM4_0_Handler,      /* 62 SERCOM4_0 */
-        .pfnSERCOM4_1_Handler   = (void*) SERCOM4_1_Handler,      /* 63 SERCOM4_1 */
-        .pfnSERCOM4_2_Handler   = (void*) SERCOM4_2_Handler,      /* 64 SERCOM4_2 */
-        .pfnSERCOM4_3_Handler   = (void*) SERCOM4_3_Handler,      /* 65 SERCOM4_3, SERCOM4_4, SERCOM4_5, SERCOM4_6 */
+    .pfnSERCOM4_0_Handler = (void *)SERCOM4_0_Handler, /* 62 SERCOM4_0 */
+    .pfnSERCOM4_1_Handler = (void *)SERCOM4_1_Handler, /* 63 SERCOM4_1 */
+    .pfnSERCOM4_2_Handler = (void *)SERCOM4_2_Handler, /* 64 SERCOM4_2 */
+    .pfnSERCOM4_3_Handler = (void *)SERCOM4_3_Handler, /* 65 SERCOM4_3, SERCOM4_4, SERCOM4_5, SERCOM4_6 */
 #else
-        .pvReserved62           = (void*) (0UL),                  /* 62 Reserved */
-        .pvReserved63           = (void*) (0UL),                  /* 63 Reserved */
-        .pvReserved64           = (void*) (0UL),                  /* 64 Reserved */
-        .pvReserved65           = (void*) (0UL),                  /* 65 Reserved */
+    .pvReserved62  = (void *)(0UL), /* 62 Reserved */
+    .pvReserved63  = (void *)(0UL), /* 63 Reserved */
+    .pvReserved64  = (void *)(0UL), /* 64 Reserved */
+    .pvReserved65  = (void *)(0UL), /* 65 Reserved */
 #endif
 #ifdef ID_SERCOM5
-        .pfnSERCOM5_0_Handler   = (void*) SERCOM5_0_Handler,      /* 66 SERCOM5_0 */
-        .pfnSERCOM5_1_Handler   = (void*) SERCOM5_1_Handler,      /* 67 SERCOM5_1 */
-        .pfnSERCOM5_2_Handler   = (void*) SERCOM5_2_Handler,      /* 68 SERCOM5_2 */
-        .pfnSERCOM5_3_Handler   = (void*) SERCOM5_3_Handler,      /* 69 SERCOM5_3, SERCOM5_4, SERCOM5_5, SERCOM5_6 */
+    .pfnSERCOM5_0_Handler = (void *)SERCOM5_0_Handler, /* 66 SERCOM5_0 */
+    .pfnSERCOM5_1_Handler = (void *)SERCOM5_1_Handler, /* 67 SERCOM5_1 */
+    .pfnSERCOM5_2_Handler = (void *)SERCOM5_2_Handler, /* 68 SERCOM5_2 */
+    .pfnSERCOM5_3_Handler = (void *)SERCOM5_3_Handler, /* 69 SERCOM5_3, SERCOM5_4, SERCOM5_5, SERCOM5_6 */
 #else
-        .pvReserved66           = (void*) (0UL),                  /* 66 Reserved */
-        .pvReserved67           = (void*) (0UL),                  /* 67 Reserved */
-        .pvReserved68           = (void*) (0UL),                  /* 68 Reserved */
-        .pvReserved69           = (void*) (0UL),                  /* 69 Reserved */
+    .pvReserved66  = (void *)(0UL), /* 66 Reserved */
+    .pvReserved67  = (void *)(0UL), /* 67 Reserved */
+    .pvReserved68  = (void *)(0UL), /* 68 Reserved */
+    .pvReserved69  = (void *)(0UL), /* 69 Reserved */
 #endif
 #ifdef ID_SERCOM6
-        .pfnSERCOM6_0_Handler   = (void*) SERCOM6_0_Handler,      /* 70 SERCOM6_0 */
-        .pfnSERCOM6_1_Handler   = (void*) SERCOM6_1_Handler,      /* 71 SERCOM6_1 */
-        .pfnSERCOM6_2_Handler   = (void*) SERCOM6_2_Handler,      /* 72 SERCOM6_2 */
-        .pfnSERCOM6_3_Handler   = (void*) SERCOM6_3_Handler,      /* 73 SERCOM6_3, SERCOM6_4, SERCOM6_5, SERCOM6_6 */
+    .pfnSERCOM6_0_Handler = (void *)SERCOM6_0_Handler, /* 70 SERCOM6_0 */
+    .pfnSERCOM6_1_Handler = (void *)SERCOM6_1_Handler, /* 71 SERCOM6_1 */
+    .pfnSERCOM6_2_Handler = (void *)SERCOM6_2_Handler, /* 72 SERCOM6_2 */
+    .pfnSERCOM6_3_Handler = (void *)SERCOM6_3_Handler, /* 73 SERCOM6_3, SERCOM6_4, SERCOM6_5, SERCOM6_6 */
 #else
-        .pvReserved70           = (void*) (0UL),                  /* 70 Reserved */
-        .pvReserved71           = (void*) (0UL),                  /* 71 Reserved */
-        .pvReserved72           = (void*) (0UL),                  /* 72 Reserved */
-        .pvReserved73           = (void*) (0UL),                  /* 73 Reserved */
+    .pvReserved70  = (void *)(0UL), /* 70 Reserved */
+    .pvReserved71  = (void *)(0UL), /* 71 Reserved */
+    .pvReserved72  = (void *)(0UL), /* 72 Reserved */
+    .pvReserved73  = (void *)(0UL), /* 73 Reserved */
 #endif
 #ifdef ID_SERCOM7
-        .pfnSERCOM7_0_Handler   = (void*) SERCOM7_0_Handler,      /* 74 SERCOM7_0 */
-        .pfnSERCOM7_1_Handler   = (void*) SERCOM7_1_Handler,      /* 75 SERCOM7_1 */
-        .pfnSERCOM7_2_Handler   = (void*) SERCOM7_2_Handler,      /* 76 SERCOM7_2 */
-        .pfnSERCOM7_3_Handler   = (void*) SERCOM7_3_Handler,      /* 77 SERCOM7_3, SERCOM7_4, SERCOM7_5, SERCOM7_6 */
+    .pfnSERCOM7_0_Handler = (void *)SERCOM7_0_Handler, /* 74 SERCOM7_0 */
+    .pfnSERCOM7_1_Handler = (void *)SERCOM7_1_Handler, /* 75 SERCOM7_1 */
+    .pfnSERCOM7_2_Handler = (void *)SERCOM7_2_Handler, /* 76 SERCOM7_2 */
+    .pfnSERCOM7_3_Handler = (void *)SERCOM7_3_Handler, /* 77 SERCOM7_3, SERCOM7_4, SERCOM7_5, SERCOM7_6 */
 #else
-        .pvReserved74           = (void*) (0UL),                  /* 74 Reserved */
-        .pvReserved75           = (void*) (0UL),                  /* 75 Reserved */
-        .pvReserved76           = (void*) (0UL),                  /* 76 Reserved */
-        .pvReserved77           = (void*) (0UL),                  /* 77 Reserved */
+    .pvReserved74  = (void *)(0UL), /* 74 Reserved */
+    .pvReserved75  = (void *)(0UL), /* 75 Reserved */
+    .pvReserved76  = (void *)(0UL), /* 76 Reserved */
+    .pvReserved77  = (void *)(0UL), /* 77 Reserved */
 #endif
 #ifdef ID_CAN0
-        .pfnCAN0_Handler        = (void*) CAN0_Handler,           /* 78 Control Area Network 0 */
+    .pfnCAN0_Handler = (void *)CAN0_Handler, /* 78 Control Area Network 0 */
 #else
-        .pvReserved78           = (void*) (0UL),                  /* 78 Reserved */
+    .pvReserved78  = (void *)(0UL), /* 78 Reserved */
 #endif
 #ifdef ID_CAN1
-        .pfnCAN1_Handler        = (void*) CAN1_Handler,           /* 79 Control Area Network 1 */
+    .pfnCAN1_Handler = (void *)CAN1_Handler, /* 79 Control Area Network 1 */
 #else
-        .pvReserved79           = (void*) (0UL),                  /* 79 Reserved */
+    .pvReserved79  = (void *)(0UL), /* 79 Reserved */
 #endif
 #ifdef ID_USB
-        .pfnUSB_0_Handler       = (void*) USB_0_Handler,          /* 80 USB_EORSM_DNRSM, USB_EORST_RST, USB_LPMSUSP_DDISC, USB_LPM_DCONN, USB_MSOF, USB_RAMACER, USB_RXSTP_TXSTP_0, USB_RXSTP_TXSTP_1, USB_RXSTP_TXSTP_2, USB_RXSTP_TXSTP_3, USB_RXSTP_TXSTP_4, USB_RXSTP_TXSTP_5, USB_RXSTP_TXSTP_6, USB_RXSTP_TXSTP_7, USB_STALL0_STALL_0, USB_STALL0_STALL_1, USB_STALL0_STALL_2, USB_STALL0_STALL_3, USB_STALL0_STALL_4, USB_STALL0_STALL_5, USB_STALL0_STALL_6, USB_STALL0_STALL_7, USB_STALL1_0, USB_STALL1_1, USB_STALL1_2, USB_STALL1_3, USB_STALL1_4, USB_STALL1_5, USB_STALL1_6, USB_STALL1_7, USB_SUSPEND, USB_TRFAIL0_TRFAIL_0, USB_TRFAIL0_TRFAIL_1, USB_TRFAIL0_TRFAIL_2, USB_TRFAIL0_TRFAIL_3, USB_TRFAIL0_TRFAIL_4, USB_TRFAIL0_TRFAIL_5, USB_TRFAIL0_TRFAIL_6, USB_TRFAIL0_TRFAIL_7, USB_TRFAIL1_PERR_0, USB_TRFAIL1_PERR_1, USB_TRFAIL1_PERR_2, USB_TRFAIL1_PERR_3, USB_TRFAIL1_PERR_4, USB_TRFAIL1_PERR_5, USB_TRFAIL1_PERR_6, USB_TRFAIL1_PERR_7, USB_UPRSM, USB_WAKEUP */
-        .pfnUSB_1_Handler       = (void*) USB_1_Handler,          /* 81 USB_SOF_HSOF */
-        .pfnUSB_2_Handler       = (void*) USB_2_Handler,          /* 82 USB_TRCPT0_0, USB_TRCPT0_1, USB_TRCPT0_2, USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5, USB_TRCPT0_6, USB_TRCPT0_7 */
-        .pfnUSB_3_Handler       = (void*) USB_3_Handler,          /* 83 USB_TRCPT1_0, USB_TRCPT1_1, USB_TRCPT1_2, USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5, USB_TRCPT1_6, USB_TRCPT1_7 */
+    .pfnUSB_0_Handler = (void *)USB_0_Handler, /* 80 USB_EORSM_DNRSM, USB_EORST_RST, USB_LPMSUSP_DDISC, USB_LPM_DCONN, USB_MSOF, USB_RAMACER, USB_RXSTP_TXSTP_0, USB_RXSTP_TXSTP_1, USB_RXSTP_TXSTP_2, USB_RXSTP_TXSTP_3, USB_RXSTP_TXSTP_4, USB_RXSTP_TXSTP_5, USB_RXSTP_TXSTP_6, USB_RXSTP_TXSTP_7, USB_STALL0_STALL_0, USB_STALL0_STALL_1, USB_STALL0_STALL_2, USB_STALL0_STALL_3, USB_STALL0_STALL_4, USB_STALL0_STALL_5, USB_STALL0_STALL_6, USB_STALL0_STALL_7, USB_STALL1_0, USB_STALL1_1, USB_STALL1_2, USB_STALL1_3, USB_STALL1_4, USB_STALL1_5, USB_STALL1_6, USB_STALL1_7, USB_SUSPEND, USB_TRFAIL0_TRFAIL_0, USB_TRFAIL0_TRFAIL_1, USB_TRFAIL0_TRFAIL_2, USB_TRFAIL0_TRFAIL_3, USB_TRFAIL0_TRFAIL_4, USB_TRFAIL0_TRFAIL_5, USB_TRFAIL0_TRFAIL_6, USB_TRFAIL0_TRFAIL_7, USB_TRFAIL1_PERR_0, USB_TRFAIL1_PERR_1, USB_TRFAIL1_PERR_2, USB_TRFAIL1_PERR_3, USB_TRFAIL1_PERR_4, USB_TRFAIL1_PERR_5, USB_TRFAIL1_PERR_6, USB_TRFAIL1_PERR_7, USB_UPRSM, USB_WAKEUP */
+    .pfnUSB_1_Handler = (void *)USB_1_Handler, /* 81 USB_SOF_HSOF */
+    .pfnUSB_2_Handler = (void *)USB_2_Handler, /* 82 USB_TRCPT0_0, USB_TRCPT0_1, USB_TRCPT0_2, USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5, USB_TRCPT0_6, USB_TRCPT0_7 */
+    .pfnUSB_3_Handler = (void *)USB_3_Handler, /* 83 USB_TRCPT1_0, USB_TRCPT1_1, USB_TRCPT1_2, USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5, USB_TRCPT1_6, USB_TRCPT1_7 */
 #else
-        .pvReserved80           = (void*) (0UL),                  /* 80 Reserved */
-        .pvReserved81           = (void*) (0UL),                  /* 81 Reserved */
-        .pvReserved82           = (void*) (0UL),                  /* 82 Reserved */
-        .pvReserved83           = (void*) (0UL),                  /* 83 Reserved */
+    .pvReserved80  = (void *)(0UL), /* 80 Reserved */
+    .pvReserved81  = (void *)(0UL), /* 81 Reserved */
+    .pvReserved82  = (void *)(0UL), /* 82 Reserved */
+    .pvReserved83  = (void *)(0UL), /* 83 Reserved */
 #endif
 #ifdef ID_GMAC
-        .pfnGMAC_Handler        = (void*) GMAC_Handler,           /* 84 Ethernet MAC */
+    .pfnGMAC_Handler = (void *)GMAC_Handler, /* 84 Ethernet MAC */
 #else
-        .pvReserved84           = (void*) (0UL),                  /* 84 Reserved */
-#endif
-        .pfnTCC0_0_Handler      = (void*) TCC0_0_Handler,         /* 85 TCC0_CNT_A, TCC0_DFS_A, TCC0_ERR_A, TCC0_FAULT0_A, TCC0_FAULT1_A, TCC0_FAULTA_A, TCC0_FAULTB_A, TCC0_OVF, TCC0_TRG, TCC0_UFS_A */
-        .pfnTCC0_1_Handler      = (void*) TCC0_1_Handler,         /* 86 TCC0_MC_0 */
-        .pfnTCC0_2_Handler      = (void*) TCC0_2_Handler,         /* 87 TCC0_MC_1 */
-        .pfnTCC0_3_Handler      = (void*) TCC0_3_Handler,         /* 88 TCC0_MC_2 */
-        .pfnTCC0_4_Handler      = (void*) TCC0_4_Handler,         /* 89 TCC0_MC_3 */
-        .pfnTCC0_5_Handler      = (void*) TCC0_5_Handler,         /* 90 TCC0_MC_4 */
-        .pfnTCC0_6_Handler      = (void*) TCC0_6_Handler,         /* 91 TCC0_MC_5 */
-        .pfnTCC1_0_Handler      = (void*) TCC1_0_Handler,         /* 92 TCC1_CNT_A, TCC1_DFS_A, TCC1_ERR_A, TCC1_FAULT0_A, TCC1_FAULT1_A, TCC1_FAULTA_A, TCC1_FAULTB_A, TCC1_OVF, TCC1_TRG, TCC1_UFS_A */
-        .pfnTCC1_1_Handler      = (void*) TCC1_1_Handler,         /* 93 TCC1_MC_0 */
-        .pfnTCC1_2_Handler      = (void*) TCC1_2_Handler,         /* 94 TCC1_MC_1 */
-        .pfnTCC1_3_Handler      = (void*) TCC1_3_Handler,         /* 95 TCC1_MC_2 */
-        .pfnTCC1_4_Handler      = (void*) TCC1_4_Handler,         /* 96 TCC1_MC_3 */
-        .pfnTCC2_0_Handler      = (void*) TCC2_0_Handler,         /* 97 TCC2_CNT_A, TCC2_DFS_A, TCC2_ERR_A, TCC2_FAULT0_A, TCC2_FAULT1_A, TCC2_FAULTA_A, TCC2_FAULTB_A, TCC2_OVF, TCC2_TRG, TCC2_UFS_A */
-        .pfnTCC2_1_Handler      = (void*) TCC2_1_Handler,         /* 98 TCC2_MC_0 */
-        .pfnTCC2_2_Handler      = (void*) TCC2_2_Handler,         /* 99 TCC2_MC_1 */
-        .pfnTCC2_3_Handler      = (void*) TCC2_3_Handler,         /* 100 TCC2_MC_2 */
+    .pvReserved84  = (void *)(0UL), /* 84 Reserved */
+#endif
+    .pfnTCC0_0_Handler = (void *)TCC0_0_Handler, /* 85 TCC0_CNT_A, TCC0_DFS_A, TCC0_ERR_A, TCC0_FAULT0_A, TCC0_FAULT1_A, TCC0_FAULTA_A, TCC0_FAULTB_A, TCC0_OVF, TCC0_TRG, TCC0_UFS_A */
+    .pfnTCC0_1_Handler = (void *)TCC0_1_Handler, /* 86 TCC0_MC_0 */
+    .pfnTCC0_2_Handler = (void *)TCC0_2_Handler, /* 87 TCC0_MC_1 */
+    .pfnTCC0_3_Handler = (void *)TCC0_3_Handler, /* 88 TCC0_MC_2 */
+    .pfnTCC0_4_Handler = (void *)TCC0_4_Handler, /* 89 TCC0_MC_3 */
+    .pfnTCC0_5_Handler = (void *)TCC0_5_Handler, /* 90 TCC0_MC_4 */
+    .pfnTCC0_6_Handler = (void *)TCC0_6_Handler, /* 91 TCC0_MC_5 */
+    .pfnTCC1_0_Handler = (void *)TCC1_0_Handler, /* 92 TCC1_CNT_A, TCC1_DFS_A, TCC1_ERR_A, TCC1_FAULT0_A, TCC1_FAULT1_A, TCC1_FAULTA_A, TCC1_FAULTB_A, TCC1_OVF, TCC1_TRG, TCC1_UFS_A */
+    .pfnTCC1_1_Handler = (void *)TCC1_1_Handler, /* 93 TCC1_MC_0 */
+    .pfnTCC1_2_Handler = (void *)TCC1_2_Handler, /* 94 TCC1_MC_1 */
+    .pfnTCC1_3_Handler = (void *)TCC1_3_Handler, /* 95 TCC1_MC_2 */
+    .pfnTCC1_4_Handler = (void *)TCC1_4_Handler, /* 96 TCC1_MC_3 */
+    .pfnTCC2_0_Handler = (void *)TCC2_0_Handler, /* 97 TCC2_CNT_A, TCC2_DFS_A, TCC2_ERR_A, TCC2_FAULT0_A, TCC2_FAULT1_A, TCC2_FAULTA_A, TCC2_FAULTB_A, TCC2_OVF, TCC2_TRG, TCC2_UFS_A */
+    .pfnTCC2_1_Handler = (void *)TCC2_1_Handler, /* 98 TCC2_MC_0 */
+    .pfnTCC2_2_Handler = (void *)TCC2_2_Handler, /* 99 TCC2_MC_1 */
+    .pfnTCC2_3_Handler = (void *)TCC2_3_Handler, /* 100 TCC2_MC_2 */
 #ifdef ID_TCC3
-        .pfnTCC3_0_Handler      = (void*) TCC3_0_Handler,         /* 101 TCC3_CNT_A, TCC3_DFS_A, TCC3_ERR_A, TCC3_FAULT0_A, TCC3_FAULT1_A, TCC3_FAULTA_A, TCC3_FAULTB_A, TCC3_OVF, TCC3_TRG, TCC3_UFS_A */
-        .pfnTCC3_1_Handler      = (void*) TCC3_1_Handler,         /* 102 TCC3_MC_0 */
-        .pfnTCC3_2_Handler      = (void*) TCC3_2_Handler,         /* 103 TCC3_MC_1 */
+    .pfnTCC3_0_Handler = (void *)TCC3_0_Handler, /* 101 TCC3_CNT_A, TCC3_DFS_A, TCC3_ERR_A, TCC3_FAULT0_A, TCC3_FAULT1_A, TCC3_FAULTA_A, TCC3_FAULTB_A, TCC3_OVF, TCC3_TRG, TCC3_UFS_A */
+    .pfnTCC3_1_Handler = (void *)TCC3_1_Handler, /* 102 TCC3_MC_0 */
+    .pfnTCC3_2_Handler = (void *)TCC3_2_Handler, /* 103 TCC3_MC_1 */
 #else
-        .pvReserved101          = (void*) (0UL),                  /* 101 Reserved */
-        .pvReserved102          = (void*) (0UL),                  /* 102 Reserved */
-        .pvReserved103          = (void*) (0UL),                  /* 103 Reserved */
+    .pvReserved101 = (void *)(0UL), /* 101 Reserved */
+    .pvReserved102 = (void *)(0UL), /* 102 Reserved */
+    .pvReserved103 = (void *)(0UL), /* 103 Reserved */
 #endif
 #ifdef ID_TCC4
-        .pfnTCC4_0_Handler      = (void*) TCC4_0_Handler,         /* 104 TCC4_CNT_A, TCC4_DFS_A, TCC4_ERR_A, TCC4_FAULT0_A, TCC4_FAULT1_A, TCC4_FAULTA_A, TCC4_FAULTB_A, TCC4_OVF, TCC4_TRG, TCC4_UFS_A */
-        .pfnTCC4_1_Handler      = (void*) TCC4_1_Handler,         /* 105 TCC4_MC_0 */
-        .pfnTCC4_2_Handler      = (void*) TCC4_2_Handler,         /* 106 TCC4_MC_1 */
+    .pfnTCC4_0_Handler = (void *)TCC4_0_Handler, /* 104 TCC4_CNT_A, TCC4_DFS_A, TCC4_ERR_A, TCC4_FAULT0_A, TCC4_FAULT1_A, TCC4_FAULTA_A, TCC4_FAULTB_A, TCC4_OVF, TCC4_TRG, TCC4_UFS_A */
+    .pfnTCC4_1_Handler = (void *)TCC4_1_Handler, /* 105 TCC4_MC_0 */
+    .pfnTCC4_2_Handler = (void *)TCC4_2_Handler, /* 106 TCC4_MC_1 */
 #else
-        .pvReserved104          = (void*) (0UL),                  /* 104 Reserved */
-        .pvReserved105          = (void*) (0UL),                  /* 105 Reserved */
-        .pvReserved106          = (void*) (0UL),                  /* 106 Reserved */
-#endif
-        .pfnTC0_Handler         = (void*) TC0_Handler,            /* 107 Basic Timer Counter 0 */
-        .pfnTC1_Handler         = (void*) TC1_Handler,            /* 108 Basic Timer Counter 1 */
-        .pfnTC2_Handler         = (void*) TC2_Handler,            /* 109 Basic Timer Counter 2 */
-        .pfnTC3_Handler         = (void*) TC3_Handler,            /* 110 Basic Timer Counter 3 */
+    .pvReserved104 = (void *)(0UL), /* 104 Reserved */
+    .pvReserved105 = (void *)(0UL), /* 105 Reserved */
+    .pvReserved106 = (void *)(0UL), /* 106 Reserved */
+#endif
+    .pfnTC0_Handler = (void *)TC0_Handler, /* 107 Basic Timer Counter 0 */
+    .pfnTC1_Handler = (void *)TC1_Handler, /* 108 Basic Timer Counter 1 */
+    .pfnTC2_Handler = (void *)TC2_Handler, /* 109 Basic Timer Counter 2 */
+    .pfnTC3_Handler = (void *)TC3_Handler, /* 110 Basic Timer Counter 3 */
 #ifdef ID_TC4
-        .pfnTC4_Handler         = (void*) TC4_Handler,            /* 111 Basic Timer Counter 4 */
+    .pfnTC4_Handler = (void *)TC4_Handler, /* 111 Basic Timer Counter 4 */
 #else
-        .pvReserved111          = (void*) (0UL),                  /* 111 Reserved */
+    .pvReserved111 = (void *)(0UL), /* 111 Reserved */
 #endif
 #ifdef ID_TC5
-        .pfnTC5_Handler         = (void*) TC5_Handler,            /* 112 Basic Timer Counter 5 */
+    .pfnTC5_Handler = (void *)TC5_Handler, /* 112 Basic Timer Counter 5 */
 #else
-        .pvReserved112          = (void*) (0UL),                  /* 112 Reserved */
+    .pvReserved112 = (void *)(0UL), /* 112 Reserved */
 #endif
 #ifdef ID_TC6
-        .pfnTC6_Handler         = (void*) TC6_Handler,            /* 113 Basic Timer Counter 6 */
+    .pfnTC6_Handler = (void *)TC6_Handler, /* 113 Basic Timer Counter 6 */
 #else
-        .pvReserved113          = (void*) (0UL),                  /* 113 Reserved */
+    .pvReserved113 = (void *)(0UL), /* 113 Reserved */
 #endif
 #ifdef ID_TC7
-        .pfnTC7_Handler         = (void*) TC7_Handler,            /* 114 Basic Timer Counter 7 */
+    .pfnTC7_Handler = (void *)TC7_Handler, /* 114 Basic Timer Counter 7 */
 #else
-        .pvReserved114          = (void*) (0UL),                  /* 114 Reserved */
-#endif
-        .pfnPDEC_0_Handler      = (void*) PDEC_0_Handler,         /* 115 PDEC_DIR_A, PDEC_ERR_A, PDEC_OVF, PDEC_VLC_A */
-        .pfnPDEC_1_Handler      = (void*) PDEC_1_Handler,         /* 116 PDEC_MC_0 */
-        .pfnPDEC_2_Handler      = (void*) PDEC_2_Handler,         /* 117 PDEC_MC_1 */
-        .pfnADC0_0_Handler      = (void*) ADC0_0_Handler,         /* 118 ADC0_OVERRUN, ADC0_WINMON */
-        .pfnADC0_1_Handler      = (void*) ADC0_1_Handler,         /* 119 ADC0_RESRDY */
-        .pfnADC1_0_Handler      = (void*) ADC1_0_Handler,         /* 120 ADC1_OVERRUN, ADC1_WINMON */
-        .pfnADC1_1_Handler      = (void*) ADC1_1_Handler,         /* 121 ADC1_RESRDY */
-        .pfnAC_Handler          = (void*) AC_Handler,             /* 122 Analog Comparators */
-        .pfnDAC_0_Handler       = (void*) DAC_0_Handler,          /* 123 DAC_OVERRUN_A_0, DAC_OVERRUN_A_1, DAC_UNDERRUN_A_0, DAC_UNDERRUN_A_1 */
-        .pfnDAC_1_Handler       = (void*) DAC_1_Handler,          /* 124 DAC_EMPTY_0 */
-        .pfnDAC_2_Handler       = (void*) DAC_2_Handler,          /* 125 DAC_EMPTY_1 */
-        .pfnDAC_3_Handler       = (void*) DAC_3_Handler,          /* 126 DAC_RESRDY_0 */
-        .pfnDAC_4_Handler       = (void*) DAC_4_Handler,          /* 127 DAC_RESRDY_1 */
+    .pvReserved114 = (void *)(0UL), /* 114 Reserved */
+#endif
+    .pfnPDEC_0_Handler = (void *)PDEC_0_Handler, /* 115 PDEC_DIR_A, PDEC_ERR_A, PDEC_OVF, PDEC_VLC_A */
+    .pfnPDEC_1_Handler = (void *)PDEC_1_Handler, /* 116 PDEC_MC_0 */
+    .pfnPDEC_2_Handler = (void *)PDEC_2_Handler, /* 117 PDEC_MC_1 */
+    .pfnADC0_0_Handler = (void *)ADC0_0_Handler, /* 118 ADC0_OVERRUN, ADC0_WINMON */
+    .pfnADC0_1_Handler = (void *)ADC0_1_Handler, /* 119 ADC0_RESRDY */
+    .pfnADC1_0_Handler = (void *)ADC1_0_Handler, /* 120 ADC1_OVERRUN, ADC1_WINMON */
+    .pfnADC1_1_Handler = (void *)ADC1_1_Handler, /* 121 ADC1_RESRDY */
+    .pfnAC_Handler     = (void *)AC_Handler,     /* 122 Analog Comparators */
+    .pfnDAC_0_Handler  = (void *)DAC_0_Handler,  /* 123 DAC_OVERRUN_A_0, DAC_OVERRUN_A_1, DAC_UNDERRUN_A_0, DAC_UNDERRUN_A_1 */
+    .pfnDAC_1_Handler  = (void *)DAC_1_Handler,  /* 124 DAC_EMPTY_0 */
+    .pfnDAC_2_Handler  = (void *)DAC_2_Handler,  /* 125 DAC_EMPTY_1 */
+    .pfnDAC_3_Handler  = (void *)DAC_3_Handler,  /* 126 DAC_RESRDY_0 */
+    .pfnDAC_4_Handler  = (void *)DAC_4_Handler,  /* 127 DAC_RESRDY_1 */
 #ifdef ID_I2S
-        .pfnI2S_Handler         = (void*) I2S_Handler,            /* 128 Inter-IC Sound Interface */
+    .pfnI2S_Handler = (void *)I2S_Handler, /* 128 Inter-IC Sound Interface */
 #else
-        .pvReserved128          = (void*) (0UL),                  /* 128 Reserved */
+    .pvReserved128 = (void *)(0UL), /* 128 Reserved */
 #endif
-        .pfnPCC_Handler         = (void*) PCC_Handler,            /* 129 Parallel Capture Controller */
-        .pfnAES_Handler         = (void*) AES_Handler,            /* 130 Advanced Encryption Standard */
-        .pfnTRNG_Handler        = (void*) TRNG_Handler,           /* 131 True Random Generator */
+    .pfnPCC_Handler  = (void *)PCC_Handler,  /* 129 Parallel Capture Controller */
+    .pfnAES_Handler  = (void *)AES_Handler,  /* 130 Advanced Encryption Standard */
+    .pfnTRNG_Handler = (void *)TRNG_Handler, /* 131 True Random Generator */
 #ifdef ID_ICM
-        .pfnICM_Handler         = (void*) ICM_Handler,            /* 132 Integrity Check Monitor */
+    .pfnICM_Handler = (void *)ICM_Handler, /* 132 Integrity Check Monitor */
 #else
-        .pvReserved132          = (void*) (0UL),                  /* 132 Reserved */
+    .pvReserved132 = (void *)(0UL), /* 132 Reserved */
 #endif
 #ifdef ID_PUKCC
-        .pfnPUKCC_Handler       = (void*) PUKCC_Handler,          /* 133 PUblic-Key Cryptography Controller */
+    .pfnPUKCC_Handler = (void *)PUKCC_Handler, /* 133 PUblic-Key Cryptography Controller */
 #else
-        .pvReserved133          = (void*) (0UL),                  /* 133 Reserved */
+    .pvReserved133 = (void *)(0UL), /* 133 Reserved */
 #endif
-        .pfnQSPI_Handler        = (void*) QSPI_Handler,           /* 134 Quad SPI interface */
+    .pfnQSPI_Handler = (void *)QSPI_Handler, /* 134 Quad SPI interface */
 #ifdef ID_SDHC0
-        .pfnSDHC0_Handler       = (void*) SDHC0_Handler,          /* 135 SD/MMC Host Controller 0 */
+    .pfnSDHC0_Handler = (void *)SDHC0_Handler, /* 135 SD/MMC Host Controller 0 */
 #else
-        .pvReserved135          = (void*) (0UL),                  /* 135 Reserved */
+    .pvReserved135 = (void *)(0UL), /* 135 Reserved */
 #endif
 #ifdef ID_SDHC1
-        .pfnSDHC1_Handler       = (void*) SDHC1_Handler           /* 136 SD/MMC Host Controller 1 */
+    .pfnSDHC1_Handler = (void *)SDHC1_Handler /* 136 SD/MMC Host Controller 1 */
 #else
-        .pvReserved136          = (void*) (0UL)                   /* 136 Reserved */
+    .pvReserved136 = (void *)(0UL)  /* 136 Reserved */
 #endif
 };
 
@@ -499,61 +500,60 @@ const DeviceVectors exception_table = {
  * \brief This is the code that gets called on processor reset.
  * To initialize the device, and call the main() routine.
  */
-void Reset_Handler(void)
-{
+void Reset_Handler(void) {
 #ifdef KEYBOARD_massdrop_ctrl
-        /* WARNING: This is only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support */
-        if (*MAGIC_ADDR == BOOTLOADER_MAGIC) {
-                /* At this point, the bootloader's memory is initialized properly, so undo the jump to here, then jump back */
-                *MAGIC_ADDR = 0x00000000;           /* Change value to prevent potential bootloader entrance loop */
-                __set_MSP(0x20008818);              /* MSP according to bootloader */
-                SCB->VTOR = 0x00000000;             /* Vector table back to bootloader's */
-                asm("bx %0"::"r"(0x00001267));      /* Jump past bootloader RCAUSE check using THUMB */
-        }
-#endif
-        uint32_t *pSrc, *pDest;
+    /* WARNING: This is only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support */
+    if (*MAGIC_ADDR == BOOTLOADER_MAGIC) {
+        /* At this point, the bootloader's memory is initialized properly, so undo the jump to here, then jump back */
+        *MAGIC_ADDR = 0x00000000;       /* Change value to prevent potential bootloader entrance loop */
+        __set_MSP(0x20008818);          /* MSP according to bootloader */
+        SCB->VTOR = 0x00000000;         /* Vector table back to bootloader's */
+        asm("bx %0" ::"r"(0x00001267)); /* Jump past bootloader RCAUSE check using THUMB */
+    }
+#endif
+    uint32_t *pSrc, *pDest;
 
-        /* Initialize the relocate segment */
-        pSrc = &_etext;
-        pDest = &_srelocate;
+    /* Initialize the relocate segment */
+    pSrc  = &_etext;
+    pDest = &_srelocate;
 
-        if (pSrc != pDest) {
-                for (; pDest < &_erelocate;) {
-                        *pDest++ = *pSrc++;
-                }
+    if (pSrc != pDest) {
+        for (; pDest < &_erelocate;) {
+            *pDest++ = *pSrc++;
         }
+    }
 
-        /* Clear the zero segment */
-        for (pDest = &_szero; pDest < &_ezero;) {
-                *pDest++ = 0;
-        }
+    /* Clear the zero segment */
+    for (pDest = &_szero; pDest < &_ezero;) {
+        *pDest++ = 0;
+    }
 
-        /* Set the vector table base address */
-        pSrc = (uint32_t *) & _sfixed;
-        SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk);
+    /* Set the vector table base address */
+    pSrc      = (uint32_t *)&_sfixed;
+    SCB->VTOR = ((uint32_t)pSrc & SCB_VTOR_TBLOFF_Msk);
 
 #if __FPU_USED
-        /* Enable FPU */
-        SCB->CPACR |=  (0xFu << 20);
-        __DSB();
-        __ISB();
+    /* Enable FPU */
+    SCB->CPACR |= (0xFu << 20);
+    __DSB();
+    __ISB();
 #endif
 
-        /* Initialize the C library */
-        __libc_init_array();
+    /* Initialize the C library */
+    __libc_init_array();
 
-        /* Branch to main function */
-        main();
+    /* Branch to main function */
+    main();
 
-        /* Infinite loop */
-        while (1);
+    /* Infinite loop */
+    while (1)
+        ;
 }
 
 /**
  * \brief Default interrupt handler for unused IRQs.
  */
-void Dummy_Handler(void)
-{
-        while (1) {
-        }
+void Dummy_Handler(void) {
+    while (1) {
+    }
 }
index b2ccfd73edb555bba7b0e1e2acc0e4c1ab998771..6ba23223403855aa7e349498a08db6f21139255c 100644 (file)
@@ -43,7 +43,7 @@
  */
 
 #ifndef UTILS_COMPILER_H_INCLUDED
-#define UTILS_COMPILER_H_INCLUDED
+#    define UTILS_COMPILER_H_INCLUDED
 
 /**
  * \defgroup group_sam0_utils Compiler abstraction layer and code utilities
  * @{
  */
 
-#if (defined __ICCARM__)
-#  include <intrinsics.h>
-#endif
+#    if (defined __ICCARM__)
+#        include <intrinsics.h>
+#    endif
 
-#include <stddef.h>
+#    include <stddef.h>
 //#include <parts.h>
 //#include <status_codes.h>
 //#include <preprocessor.h>
 //#include <io.h>
 
-#ifndef __ASSEMBLY__
+#    ifndef __ASSEMBLY__
 
-#include <stdio.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
+#        include <stdio.h>
+#        include <stdbool.h>
+#        include <stdint.h>
+#        include <stdlib.h>
 
 /**
  * \def UNUSED
  * \brief Marking \a v as a unused parameter or value.
  */
-#define UNUSED(v)          (void)(v)
+#        define UNUSED(v) (void)(v)
 
 /**
  * \def barrier
  * \brief Memory barrier
  */
-#ifdef __GNUC__
-#  define barrier()        asm volatile("" ::: "memory")
-#else
-#  define barrier()        asm ("")
-#endif
+#        ifdef __GNUC__
+#            define barrier() asm volatile("" ::: "memory")
+#        else
+#            define barrier() asm("")
+#        endif
 
 /**
  * \brief Emit the compiler pragma \a arg.
  * \param[in] arg  The pragma directive as it would appear after \e \#pragma
  *             (i.e. not stringified).
  */
-#define COMPILER_PRAGMA(arg)          _Pragma(#arg)
+#        define COMPILER_PRAGMA(arg) _Pragma(#        arg)
 
 /**
  * \def COMPILER_PACK_SET(alignment)
  * \brief Set maximum alignment for subsequent struct and union definitions to \a alignment.
  */
-#define COMPILER_PACK_SET(alignment)  COMPILER_PRAGMA(pack(alignment))
+#        define COMPILER_PACK_SET(alignment) COMPILER_PRAGMA(pack(alignment))
 
 /**
  * \def COMPILER_PACK_RESET()
  * \brief Set default alignment for subsequent struct and union definitions.
  */
-#define COMPILER_PACK_RESET()         COMPILER_PRAGMA(pack())
-
+#        define COMPILER_PACK_RESET() COMPILER_PRAGMA(pack())
 
 /**
  * \brief Set aligned boundary.
  */
-#if (defined __GNUC__) || (defined __CC_ARM)
-#   define COMPILER_ALIGNED(a)        __attribute__((__aligned__(a)))
-#elif (defined __ICCARM__)
-#   define COMPILER_ALIGNED(a)        COMPILER_PRAGMA(data_alignment = a)
-#endif
+#        if (defined __GNUC__) || (defined __CC_ARM)
+#            define COMPILER_ALIGNED(a) __attribute__((__aligned__(a)))
+#        elif (defined __ICCARM__)
+#            define COMPILER_ALIGNED(a) COMPILER_PRAGMA(data_alignment = a)
+#        endif
 
 /**
  * \brief Set word-aligned boundary.
  */
-#if (defined __GNUC__) || defined(__CC_ARM)
-#define COMPILER_WORD_ALIGNED         __attribute__((__aligned__(4)))
-#elif (defined __ICCARM__)
-#define COMPILER_WORD_ALIGNED         COMPILER_PRAGMA(data_alignment = 4)
-#endif
+#        if (defined __GNUC__) || defined(__CC_ARM)
+#            define COMPILER_WORD_ALIGNED __attribute__((__aligned__(4)))
+#        elif (defined __ICCARM__)
+#            define COMPILER_WORD_ALIGNED COMPILER_PRAGMA(data_alignment = 4)
+#        endif
 
 /**
  * \def __always_inline
  * heuristics and inline the function no matter how big it thinks it
  * becomes.
  */
-#if !defined(__always_inline)
-#if defined(__CC_ARM)
-#  define __always_inline             __forceinline
-#elif (defined __GNUC__)
-#  define __always_inline             __attribute__((__always_inline__))
-#elif (defined __ICCARM__)
-#  define __always_inline             _Pragma("inline=forced")
-#endif
-#endif
+#        if !defined(__always_inline)
+#            if defined(__CC_ARM)
+#                define __always_inline __forceinline
+#            elif (defined __GNUC__)
+#                define __always_inline __attribute__((__always_inline__))
+#            elif (defined __ICCARM__)
+#                define __always_inline _Pragma("inline=forced")
+#            endif
+#        endif
 
 /**
  * \def __no_inline
  * heuristics and not inline the function no matter how small it thinks it
  * becomes.
  */
-#if defined(__CC_ARM)
-#  define __no_inline                 __attribute__((noinline))
-#elif (defined __GNUC__)
-#  define __no_inline                 __attribute__((noinline))
-#elif (defined __ICCARM__)
-#  define __no_inline                 _Pragma("inline=never")
-#endif
-
+#        if defined(__CC_ARM)
+#            define __no_inline __attribute__((noinline))
+#        elif (defined __GNUC__)
+#            define __no_inline __attribute__((noinline))
+#        elif (defined __ICCARM__)
+#            define __no_inline _Pragma("inline=never")
+#        endif
 
 /** \brief This macro is used to test fatal errors.
  *
  *
  * \param[in] expr  Expression to evaluate and supposed to be nonzero.
  */
-#if defined(_ASSERT_ENABLE_)
-#  if defined(TEST_SUITE_DEFINE_ASSERT_MACRO)
-#    include "unit_test/suite.h"
-#  else
-#    undef TEST_SUITE_DEFINE_ASSERT_MACRO
-#    define Assert(expr) \
-        {\
-           if (!(expr)) asm("BKPT #0");\
-        }
-#  endif
-#else
-#  define Assert(expr) ((void) 0)
-#endif
+#        if defined(_ASSERT_ENABLE_)
+#            if defined(TEST_SUITE_DEFINE_ASSERT_MACRO)
+#                include "unit_test/suite.h"
+#            else
+#                undef TEST_SUITE_DEFINE_ASSERT_MACRO
+#                define Assert(expr)                 \
+                    {                                \
+                        if (!(expr)) asm("BKPT #0"); \
+                    }
+#            endif
+#        else
+#            define Assert(expr) ((void)0)
+#        endif
 
 /* Define WEAK attribute */
-#if defined   ( __CC_ARM   )
-#   define WEAK __attribute__ ((weak))
-#elif defined ( __ICCARM__ )
-#   define WEAK __weak
-#elif defined (  __GNUC__  )
-#   define WEAK __attribute__ ((weak))
-#endif
+#        if defined(__CC_ARM)
+#            define WEAK __attribute__((weak))
+#        elif defined(__ICCARM__)
+#            define WEAK __weak
+#        elif defined(__GNUC__)
+#            define WEAK __attribute__((weak))
+#        endif
 
 /* Define NO_INIT attribute */
-#if defined   ( __CC_ARM   )
-#   define NO_INIT __attribute__((zero_init))
-#elif defined ( __ICCARM__ )
-#   define NO_INIT __no_init
-#elif defined (  __GNUC__  )
-#   define NO_INIT __attribute__((section(".no_init")))
-#endif
+#        if defined(__CC_ARM)
+#            define NO_INIT __attribute__((zero_init))
+#        elif defined(__ICCARM__)
+#            define NO_INIT __no_init
+#        elif defined(__GNUC__)
+#            define NO_INIT __attribute__((section(".no_init")))
+#        endif
 
 //#include "interrupt.h"
 
 /** \name Usual Types
  * @{ */
-#ifndef __cplusplus
-#  if !defined(__bool_true_false_are_defined)
-typedef unsigned char           bool;
-#  endif
-#endif
-typedef uint16_t                le16_t;
-typedef uint16_t                be16_t;
-typedef uint32_t                le32_t;
-typedef uint32_t                be32_t;
-typedef uint32_t                iram_size_t;
+#        ifndef __cplusplus
+#            if !defined(__bool_true_false_are_defined)
+typedef unsigned char bool;
+#            endif
+#        endif
+typedef uint16_t le16_t;
+typedef uint16_t be16_t;
+typedef uint32_t le32_t;
+typedef uint32_t be32_t;
+typedef uint32_t iram_size_t;
 /** @} */
 
 /** \name Aliasing Aggregate Types
  * @{ */
 
 /** 16-bit union. */
-typedef union
-{
-  int16_t  s16;
-  uint16_t u16;
-  int8_t   s8[2];
-  uint8_t  u8[2];
+typedef union {
+    int16_t  s16;
+    uint16_t u16;
+    int8_t   s8[2];
+    uint8_t  u8[2];
 } Union16;
 
 /** 32-bit union. */
-typedef union
-{
-  int32_t  s32;
-  uint32_t u32;
-  int16_t  s16[2];
-  uint16_t u16[2];
-  int8_t   s8[4];
-  uint8_t  u8[4];
+typedef union {
+    int32_t  s32;
+    uint32_t u32;
+    int16_t  s16[2];
+    uint16_t u16[2];
+    int8_t   s8[4];
+    uint8_t  u8[4];
 } Union32;
 
 /** 64-bit union. */
-typedef union
-{
-  int64_t  s64;
-  uint64_t u64;
-  int32_t  s32[2];
-  uint32_t u32[2];
-  int16_t  s16[4];
-  uint16_t u16[4];
-  int8_t   s8[8];
-  uint8_t  u8[8];
+typedef union {
+    int64_t  s64;
+    uint64_t u64;
+    int32_t  s32[2];
+    uint32_t u32[2];
+    int16_t  s16[4];
+    uint16_t u16[4];
+    int8_t   s8[8];
+    uint8_t  u8[8];
 } Union64;
 
 /** Union of pointers to 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef union
-{
-  int64_t  *s64ptr;
-  uint64_t *u64ptr;
-  int32_t  *s32ptr;
-  uint32_t *u32ptr;
-  int16_t  *s16ptr;
-  uint16_t *u16ptr;
-  int8_t   *s8ptr;
-  uint8_t  *u8ptr;
+typedef union {
+    int64_t * s64ptr;
+    uint64_t *u64ptr;
+    int32_t * s32ptr;
+    uint32_t *u32ptr;
+    int16_t * s16ptr;
+    uint16_t *u16ptr;
+    int8_t *  s8ptr;
+    uint8_t * u8ptr;
 } UnionPtr;
 
 /** Union of pointers to volatile 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef union
-{
-  volatile int64_t  *s64ptr;
-  volatile uint64_t *u64ptr;
-  volatile int32_t  *s32ptr;
-  volatile uint32_t *u32ptr;
-  volatile int16_t  *s16ptr;
-  volatile uint16_t *u16ptr;
-  volatile int8_t   *s8ptr;
-  volatile uint8_t  *u8ptr;
+typedef union {
+    volatile int64_t * s64ptr;
+    volatile uint64_t *u64ptr;
+    volatile int32_t * s32ptr;
+    volatile uint32_t *u32ptr;
+    volatile int16_t * s16ptr;
+    volatile uint16_t *u16ptr;
+    volatile int8_t *  s8ptr;
+    volatile uint8_t * u8ptr;
 } UnionVPtr;
 
 /** Union of pointers to constant 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef union
-{
-  const int64_t  *s64ptr;
-  const uint64_t *u64ptr;
-  const int32_t  *s32ptr;
-  const uint32_t *u32ptr;
-  const int16_t  *s16ptr;
-  const uint16_t *u16ptr;
-  const int8_t   *s8ptr;
-  const uint8_t  *u8ptr;
+typedef union {
+    const int64_t * s64ptr;
+    const uint64_t *u64ptr;
+    const int32_t * s32ptr;
+    const uint32_t *u32ptr;
+    const int16_t * s16ptr;
+    const uint16_t *u16ptr;
+    const int8_t *  s8ptr;
+    const uint8_t * u8ptr;
 } UnionCPtr;
 
 /** Union of pointers to constant volatile 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef union
-{
-  const volatile int64_t  *s64ptr;
-  const volatile uint64_t *u64ptr;
-  const volatile int32_t  *s32ptr;
-  const volatile uint32_t *u32ptr;
-  const volatile int16_t  *s16ptr;
-  const volatile uint16_t *u16ptr;
-  const volatile int8_t   *s8ptr;
-  const volatile uint8_t  *u8ptr;
+typedef union {
+    const volatile int64_t * s64ptr;
+    const volatile uint64_t *u64ptr;
+    const volatile int32_t * s32ptr;
+    const volatile uint32_t *u32ptr;
+    const volatile int16_t * s16ptr;
+    const volatile uint16_t *u16ptr;
+    const volatile int8_t *  s8ptr;
+    const volatile uint8_t * u8ptr;
 } UnionCVPtr;
 
 /** Structure of pointers to 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef struct
-{
-  int64_t  *s64ptr;
-  uint64_t *u64ptr;
-  int32_t  *s32ptr;
-  uint32_t *u32ptr;
-  int16_t  *s16ptr;
-  uint16_t *u16ptr;
-  int8_t   *s8ptr;
-  uint8_t  *u8ptr;
+typedef struct {
+    int64_t * s64ptr;
+    uint64_t *u64ptr;
+    int32_t * s32ptr;
+    uint32_t *u32ptr;
+    int16_t * s16ptr;
+    uint16_t *u16ptr;
+    int8_t *  s8ptr;
+    uint8_t * u8ptr;
 } StructPtr;
 
 /** Structure of pointers to volatile 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef struct
-{
-  volatile int64_t  *s64ptr;
-  volatile uint64_t *u64ptr;
-  volatile int32_t  *s32ptr;
-  volatile uint32_t *u32ptr;
-  volatile int16_t  *s16ptr;
-  volatile uint16_t *u16ptr;
-  volatile int8_t   *s8ptr;
-  volatile uint8_t  *u8ptr;
+typedef struct {
+    volatile int64_t * s64ptr;
+    volatile uint64_t *u64ptr;
+    volatile int32_t * s32ptr;
+    volatile uint32_t *u32ptr;
+    volatile int16_t * s16ptr;
+    volatile uint16_t *u16ptr;
+    volatile int8_t *  s8ptr;
+    volatile uint8_t * u8ptr;
 } StructVPtr;
 
 /** Structure of pointers to constant 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef struct
-{
-  const int64_t  *s64ptr;
-  const uint64_t *u64ptr;
-  const int32_t  *s32ptr;
-  const uint32_t *u32ptr;
-  const int16_t  *s16ptr;
-  const uint16_t *u16ptr;
-  const int8_t   *s8ptr;
-  const uint8_t  *u8ptr;
+typedef struct {
+    const int64_t * s64ptr;
+    const uint64_t *u64ptr;
+    const int32_t * s32ptr;
+    const uint32_t *u32ptr;
+    const int16_t * s16ptr;
+    const uint16_t *u16ptr;
+    const int8_t *  s8ptr;
+    const uint8_t * u8ptr;
 } StructCPtr;
 
 /** Structure of pointers to constant volatile 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef struct
-{
-  const volatile int64_t  *s64ptr;
-  const volatile uint64_t *u64ptr;
-  const volatile int32_t  *s32ptr;
-  const volatile uint32_t *u32ptr;
-  const volatile int16_t  *s16ptr;
-  const volatile uint16_t *u16ptr;
-  const volatile int8_t   *s8ptr;
-  const volatile uint8_t  *u8ptr;
+typedef struct {
+    const volatile int64_t * s64ptr;
+    const volatile uint64_t *u64ptr;
+    const volatile int32_t * s32ptr;
+    const volatile uint32_t *u32ptr;
+    const volatile int16_t * s16ptr;
+    const volatile uint16_t *u16ptr;
+    const volatile int8_t *  s8ptr;
+    const volatile uint8_t * u8ptr;
 } StructCVPtr;
 
 /** @} */
 
-#endif  /* #ifndef __ASSEMBLY__ */
+#    endif /* #ifndef __ASSEMBLY__ */
 
 /** \name Usual Constants
  * @{ */
-//kmod #define DISABLE   0
-//kmod #define ENABLE    1
-
-#ifndef __cplusplus
-#  if !defined(__bool_true_false_are_defined)
-#    define false     0
-#    define true      1
-#  endif
-#endif
+// kmod #define DISABLE   0
+// kmod #define ENABLE    1
+
+#    ifndef __cplusplus
+#        if !defined(__bool_true_false_are_defined)
+#            define false 0
+#            define true 1
+#        endif
+#    endif
 /** @} */
 
-#ifndef __ASSEMBLY__
+#    ifndef __ASSEMBLY__
 
 /** \name Optimization Control
  * @{ */
@@ -384,17 +371,17 @@ typedef struct
  * \def likely(exp)
  * \brief The expression \a exp is likely to be true
  */
-#if !defined(likely) || defined(__DOXYGEN__)
-#   define likely(exp)    (exp)
-#endif
+#        if !defined(likely) || defined(__DOXYGEN__)
+#            define likely(exp) (exp)
+#        endif
 
 /**
  * \def unlikely(exp)
  * \brief The expression \a exp is unlikely to be true
  */
-#if !defined(unlikely) || defined(__DOXYGEN__)
-#   define unlikely(exp)  (exp)
-#endif
+#        if !defined(unlikely) || defined(__DOXYGEN__)
+#            define unlikely(exp) (exp)
+#        endif
 
 /**
  * \def is_constant(exp)
@@ -404,11 +391,11 @@ typedef struct
  *
  * \return true if \a exp is constant, false otherwise.
  */
-#if (defined __GNUC__) || (defined __CC_ARM)
-#   define is_constant(exp)       __builtin_constant_p(exp)
-#else
-#   define is_constant(exp)       (0)
-#endif
+#        if (defined __GNUC__) || (defined __CC_ARM)
+#            define is_constant(exp) __builtin_constant_p(exp)
+#        else
+#            define is_constant(exp) (0)
+#        endif
 
 /** @} */
 
@@ -422,7 +409,7 @@ typedef struct
  *
  * \return Read bits.
  */
-#define Rd_bits( value, mask)        ((value) & (mask))
+#        define Rd_bits(value, mask) ((value) & (mask))
 
 /** \brief Writes the bits of a C lvalue specified by a given bit-mask.
  *
@@ -432,8 +419,7 @@ typedef struct
  *
  * \return Resulting value with written bits.
  */
-#define Wr_bits(lvalue, mask, bits)  ((lvalue) = ((lvalue) & ~(mask)) |\
-                                                 ((bits  ) &  (mask)))
+#        define Wr_bits(lvalue, mask, bits) ((lvalue) = ((lvalue) & ~(mask)) | ((bits) & (mask)))
 
 /** \brief Tests the bits of a value specified by a given bit-mask.
  *
@@ -442,7 +428,7 @@ typedef struct
  *
  * \return \c 1 if at least one of the tested bits is set, else \c 0.
  */
-#define Tst_bits( value, mask)  (Rd_bits(value, mask) != 0)
+#        define Tst_bits(value, mask) (Rd_bits(value, mask) != 0)
 
 /** \brief Clears the bits of a C lvalue specified by a given bit-mask.
  *
@@ -451,7 +437,7 @@ typedef struct
  *
  * \return Resulting value with cleared bits.
  */
-#define Clr_bits(lvalue, mask)  ((lvalue) &= ~(mask))
+#        define Clr_bits(lvalue, mask) ((lvalue) &= ~(mask))
 
 /** \brief Sets the bits of a C lvalue specified by a given bit-mask.
  *
@@ -460,7 +446,7 @@ typedef struct
  *
  * \return Resulting value with set bits.
  */
-#define Set_bits(lvalue, mask)  ((lvalue) |=  (mask))
+#        define Set_bits(lvalue, mask) ((lvalue) |= (mask))
 
 /** \brief Toggles the bits of a C lvalue specified by a given bit-mask.
  *
@@ -469,7 +455,7 @@ typedef struct
  *
  * \return Resulting value with toggled bits.
  */
-#define Tgl_bits(lvalue, mask)  ((lvalue) ^=  (mask))
+#        define Tgl_bits(lvalue, mask) ((lvalue) ^= (mask))
 
 /** \brief Reads the bit-field of a value specified by a given bit-mask.
  *
@@ -478,7 +464,7 @@ typedef struct
  *
  * \return Read bit-field.
  */
-#define Rd_bitfield( value, mask)           (Rd_bits( value, mask) >> ctz(mask))
+#        define Rd_bitfield(value, mask) (Rd_bits(value, mask) >> ctz(mask))
 
 /** \brief Writes the bit-field of a C lvalue specified by a given bit-mask.
  *
@@ -488,11 +474,10 @@ typedef struct
  *
  * \return Resulting value with written bit-field.
  */
-#define Wr_bitfield(lvalue, mask, bitfield) (Wr_bits(lvalue, mask, (uint32_t)(bitfield) << ctz(mask)))
+#        define Wr_bitfield(lvalue, mask, bitfield) (Wr_bits(lvalue, mask, (uint32_t)(bitfield) << ctz(mask)))
 
 /** @} */
 
-
 /** \name Zero-Bit Counting
  *
  * Under GCC, __builtin_clz and __builtin_ctz behave like macros when
@@ -513,43 +498,11 @@ typedef struct
  *
  * \return The count of leading zero bits in \a u.
  */
-#if (defined __GNUC__) || (defined __CC_ARM)
-#   define clz(u)              ((u) ? __builtin_clz(u) : 32)
-#else
-#   define clz(u)              (((u) == 0)          ? 32 : \
-                                ((u) & (1ul << 31)) ?  0 : \
-                                ((u) & (1ul << 30)) ?  1 : \
-                                ((u) & (1ul << 29)) ?  2 : \
-                                ((u) & (1ul << 28)) ?  3 : \
-                                ((u) & (1ul << 27)) ?  4 : \
-                                ((u) & (1ul << 26)) ?  5 : \
-                                ((u) & (1ul << 25)) ?  6 : \
-                                ((u) & (1ul << 24)) ?  7 : \
-                                ((u) & (1ul << 23)) ?  8 : \
-                                ((u) & (1ul << 22)) ?  9 : \
-                                ((u) & (1ul << 21)) ? 10 : \
-                                ((u) & (1ul << 20)) ? 11 : \
-                                ((u) & (1ul << 19)) ? 12 : \
-                                ((u) & (1ul << 18)) ? 13 : \
-                                ((u) & (1ul << 17)) ? 14 : \
-                                ((u) & (1ul << 16)) ? 15 : \
-                                ((u) & (1ul << 15)) ? 16 : \
-                                ((u) & (1ul << 14)) ? 17 : \
-                                ((u) & (1ul << 13)) ? 18 : \
-                                ((u) & (1ul << 12)) ? 19 : \
-                                ((u) & (1ul << 11)) ? 20 : \
-                                ((u) & (1ul << 10)) ? 21 : \
-                                ((u) & (1ul <<  9)) ? 22 : \
-                                ((u) & (1ul <<  8)) ? 23 : \
-                                ((u) & (1ul <<  7)) ? 24 : \
-                                ((u) & (1ul <<  6)) ? 25 : \
-                                ((u) & (1ul <<  5)) ? 26 : \
-                                ((u) & (1ul <<  4)) ? 27 : \
-                                ((u) & (1ul <<  3)) ? 28 : \
-                                ((u) & (1ul <<  2)) ? 29 : \
-                                ((u) & (1ul <<  1)) ? 30 : \
-                                31)
-#endif
+#        if (defined __GNUC__) || (defined __CC_ARM)
+#            define clz(u) ((u) ? __builtin_clz(u) : 32)
+#        else
+#            define clz(u) (((u) == 0) ? 32 : ((u) & (1ul << 31)) ? 0 : ((u) & (1ul << 30)) ? 1 : ((u) & (1ul << 29)) ? 2 : ((u) & (1ul << 28)) ? 3 : ((u) & (1ul << 27)) ? 4 : ((u) & (1ul << 26)) ? 5 : ((u) & (1ul << 25)) ? 6 : ((u) & (1ul << 24)) ? 7 : ((u) & (1ul << 23)) ? 8 : ((u) & (1ul << 22)) ? 9 : ((u) & (1ul << 21)) ? 10 : ((u) & (1ul << 20)) ? 11 : ((u) & (1ul << 19)) ? 12 : ((u) & (1ul << 18)) ? 13 : ((u) & (1ul << 17)) ? 14 : ((u) & (1ul << 16)) ? 15 : ((u) & (1ul << 15)) ? 16 : ((u) & (1ul << 14)) ? 17 : ((u) & (1ul << 13)) ? 18 : ((u) & (1ul << 12)) ? 19 : ((u) & (1ul << 11)) ? 20 : ((u) & (1ul << 10)) ? 21 : ((u) & (1ul << 9)) ? 22 : ((u) & (1ul << 8)) ? 23 : ((u) & (1ul << 7)) ? 24 : ((u) & (1ul << 6)) ? 25 : ((u) & (1ul << 5)) ? 26 : ((u) & (1ul << 4)) ? 27 : ((u) & (1ul << 3)) ? 28 : ((u) & (1ul << 2)) ? 29 : ((u) & (1ul << 1)) ? 30 : 31)
+#        endif
 
 /** \brief Counts the trailing zero bits of the given value considered as a 32-bit integer.
  *
@@ -557,47 +510,14 @@ typedef struct
  *
  * \return The count of trailing zero bits in \a u.
  */
-#if (defined __GNUC__) || (defined __CC_ARM)
-#   define ctz(u)              ((u) ? __builtin_ctz(u) : 32)
-#else
-#   define ctz(u)              ((u) & (1ul <<  0) ?  0 : \
-                                (u) & (1ul <<  1) ?  1 : \
-                                (u) & (1ul <<  2) ?  2 : \
-                                (u) & (1ul <<  3) ?  3 : \
-                                (u) & (1ul <<  4) ?  4 : \
-                                (u) & (1ul <<  5) ?  5 : \
-                                (u) & (1ul <<  6) ?  6 : \
-                                (u) & (1ul <<  7) ?  7 : \
-                                (u) & (1ul <<  8) ?  8 : \
-                                (u) & (1ul <<  9) ?  9 : \
-                                (u) & (1ul << 10) ? 10 : \
-                                (u) & (1ul << 11) ? 11 : \
-                                (u) & (1ul << 12) ? 12 : \
-                                (u) & (1ul << 13) ? 13 : \
-                                (u) & (1ul << 14) ? 14 : \
-                                (u) & (1ul << 15) ? 15 : \
-                                (u) & (1ul << 16) ? 16 : \
-                                (u) & (1ul << 17) ? 17 : \
-                                (u) & (1ul << 18) ? 18 : \
-                                (u) & (1ul << 19) ? 19 : \
-                                (u) & (1ul << 20) ? 20 : \
-                                (u) & (1ul << 21) ? 21 : \
-                                (u) & (1ul << 22) ? 22 : \
-                                (u) & (1ul << 23) ? 23 : \
-                                (u) & (1ul << 24) ? 24 : \
-                                (u) & (1ul << 25) ? 25 : \
-                                (u) & (1ul << 26) ? 26 : \
-                                (u) & (1ul << 27) ? 27 : \
-                                (u) & (1ul << 28) ? 28 : \
-                                (u) & (1ul << 29) ? 29 : \
-                                (u) & (1ul << 30) ? 30 : \
-                                (u) & (1ul << 31) ? 31 : \
-                                32)
-#endif
+#        if (defined __GNUC__) || (defined __CC_ARM)
+#            define ctz(u) ((u) ? __builtin_ctz(u) : 32)
+#        else
+#            define ctz(u) ((u) & (1ul << 0) ? 0 : (u) & (1ul << 1) ? 1 : (u) & (1ul << 2) ? 2 : (u) & (1ul << 3) ? 3 : (u) & (1ul << 4) ? 4 : (u) & (1ul << 5) ? 5 : (u) & (1ul << 6) ? 6 : (u) & (1ul << 7) ? 7 : (u) & (1ul << 8) ? 8 : (u) & (1ul << 9) ? 9 : (u) & (1ul << 10) ? 10 : (u) & (1ul << 11) ? 11 : (u) & (1ul << 12) ? 12 : (u) & (1ul << 13) ? 13 : (u) & (1ul << 14) ? 14 : (u) & (1ul << 15) ? 15 : (u) & (1ul << 16) ? 16 : (u) & (1ul << 17) ? 17 : (u) & (1ul << 18) ? 18 : (u) & (1ul << 19) ? 19 : (u) & (1ul << 20) ? 20 : (u) & (1ul << 21) ? 21 : (u) & (1ul << 22) ? 22 : (u) & (1ul << 23) ? 23 : (u) & (1ul << 24) ? 24 : (u) & (1ul << 25) ? 25 : (u) & (1ul << 26) ? 26 : (u) & (1ul << 27) ? 27 : (u) & (1ul << 28) ? 28 : (u) & (1ul << 29) ? 29 : (u) & (1ul << 30) ? 30 : (u) & (1ul << 31) ? 31 : 32)
+#        endif
 
 /** @} */
 
-
 /** \name Bit Reversing
  * @{ */
 
@@ -607,7 +527,7 @@ typedef struct
  *
  * \return Value resulting from \a u8 with reversed bits.
  */
-#define bit_reverse8(u8)    ((U8)(bit_reverse32((U8)(u8)) >> 24))
+#        define bit_reverse8(u8) ((U8)(bit_reverse32((U8)(u8)) >> 24))
 
 /** \brief Reverses the bits of \a u16.
  *
@@ -615,7 +535,7 @@ typedef struct
  *
  * \return Value resulting from \a u16 with reversed bits.
  */
-#define bit_reverse16(u16)  ((uint16_t)(bit_reverse32((uint16_t)(u16)) >> 16))
+#        define bit_reverse16(u16) ((uint16_t)(bit_reverse32((uint16_t)(u16)) >> 16))
 
 /** \brief Reverses the bits of \a u32.
  *
@@ -623,7 +543,7 @@ typedef struct
  *
  * \return Value resulting from \a u32 with reversed bits.
  */
-#define bit_reverse32(u32)   __RBIT(u32)
+#        define bit_reverse32(u32) __RBIT(u32)
 
 /** \brief Reverses the bits of \a u64.
  *
@@ -631,12 +551,10 @@ typedef struct
  *
  * \return Value resulting from \a u64 with reversed bits.
  */
-#define bit_reverse64(u64)  ((uint64_t)(((uint64_t)bit_reverse32((uint64_t)(u64) >> 32)) |\
-                                   ((uint64_t)bit_reverse32((uint64_t)(u64)) << 32)))
+#        define bit_reverse64(u64) ((uint64_t)(((uint64_t)bit_reverse32((uint64_t)(u64) >> 32)) | ((uint64_t)bit_reverse32((uint64_t)(u64)) << 32)))
 
 /** @} */
 
-
 /** \name Alignment
  * @{ */
 
@@ -647,7 +565,7 @@ typedef struct
  *
  * \return \c 1 if the number \a val is aligned with the \a n boundary, else \c 0.
  */
-#define Test_align(val, n) (!Tst_bits( val, (n) - 1     )   )
+#        define Test_align(val, n) (!Tst_bits(val, (n)-1))
 
 /** \brief Gets alignment of the number \a val with respect to the \a n boundary.
  *
@@ -656,7 +574,7 @@ typedef struct
  *
  * \return Alignment of the number \a val with respect to the \a n boundary.
  */
-#define Get_align(val, n) (  Rd_bits( val, (n) - 1     )   )
+#        define Get_align(val, n) (Rd_bits(val, (n)-1))
 
 /** \brief Sets alignment of the lvalue number \a lval to \a alg with respect to the \a n boundary.
  *
@@ -666,7 +584,7 @@ typedef struct
  *
  * \return New value of \a lval resulting from its alignment set to \a alg with respect to the \a n boundary.
  */
-#define Set_align(lval, n, alg) (  Wr_bits(lval, (n) - 1, alg)   )
+#        define Set_align(lval, n, alg) (Wr_bits(lval, (n)-1, alg))
 
 /** \brief Aligns the number \a val with the upper \a n boundary.
  *
@@ -675,7 +593,7 @@ typedef struct
  *
  * \return Value resulting from the number \a val aligned with the upper \a n boundary.
  */
-#define Align_up(  val, n) (((val) + ((n) - 1)) & ~((n) - 1))
+#        define Align_up(val, n) (((val) + ((n)-1)) & ~((n)-1))
 
 /** \brief Aligns the number \a val with the lower \a n boundary.
  *
@@ -684,11 +602,10 @@ typedef struct
  *
  * \return Value resulting from the number \a val aligned with the lower \a n boundary.
  */
-#define Align_down(val, n) ( (val)              & ~((n) - 1))
+#        define Align_down(val, n) ((val) & ~((n)-1))
 
 /** @} */
 
-
 /** \name Mathematics
  *
  * The same considerations as for clz and ctz apply here but GCC does not
@@ -710,9 +627,9 @@ typedef struct
  *
  * \note More optimized if only used with values known at compile time.
  */
-#define Abs(a)              (((a) <  0 ) ? -(a) : (a))
+#        define Abs(a) (((a) < 0) ? -(a) : (a))
 
-#ifndef __cplusplus
+#        ifndef __cplusplus
 /** \brief Takes the minimal value of \a a and \a b.
  *
  * \param[in] a Input value.
@@ -722,7 +639,7 @@ typedef struct
  *
  * \note More optimized if only used with values known at compile time.
  */
-#define Min(a, b)           (((a) < (b)) ?  (a) : (b))
+#            define Min(a, b) (((a) < (b)) ? (a) : (b))
 
 /** \brief Takes the maximal value of \a a and \a b.
  *
@@ -733,7 +650,7 @@ typedef struct
  *
  * \note More optimized if only used with values known at compile time.
  */
-#define Max(a, b)           (((a) > (b)) ?  (a) : (b))
+#            define Max(a, b) (((a) > (b)) ? (a) : (b))
 
 /** \brief Takes the minimal value of \a a and \a b.
  *
@@ -744,7 +661,7 @@ typedef struct
  *
  * \note More optimized if only used with values unknown at compile time.
  */
-#define min(a, b)   Min(a, b)
+#            define min(a, b) Min(a, b)
 
 /** \brief Takes the maximal value of \a a and \a b.
  *
@@ -755,12 +672,11 @@ typedef struct
  *
  * \note More optimized if only used with values unknown at compile time.
  */
-#define max(a, b)   Max(a, b)
-#endif
+#            define max(a, b) Max(a, b)
+#        endif
 
 /** @} */
 
-
 /** \brief Calls the routine at address \a addr.
  *
  * It generates a long call opcode.
@@ -772,38 +688,36 @@ typedef struct
  *
  * \note It may be used as a long jump opcode in some special cases.
  */
-#define Long_call(addr)                   ((*(void (*)(void))(addr))())
-
+#        define Long_call(addr) ((*(void (*)(void))(addr))())
 
 /** \name MCU Endianism Handling
  *  ARM is MCU little endian.
  *
  * @{ */
-#define  BE16(x)        swap16(x)
-#define  LE16(x)        (x)
-
-#define  le16_to_cpu(x) (x)
-#define  cpu_to_le16(x) (x)
-#define  LE16_TO_CPU(x) (x)
-#define  CPU_TO_LE16(x) (x)
-
-#define  be16_to_cpu(x) swap16(x)
-#define  cpu_to_be16(x) swap16(x)
-#define  BE16_TO_CPU(x) swap16(x)
-#define  CPU_TO_BE16(x) swap16(x)
-
-#define  le32_to_cpu(x) (x)
-#define  cpu_to_le32(x) (x)
-#define  LE32_TO_CPU(x) (x)
-#define  CPU_TO_LE32(x) (x)
-
-#define  be32_to_cpu(x) swap32(x)
-#define  cpu_to_be32(x) swap32(x)
-#define  BE32_TO_CPU(x) swap32(x)
-#define  CPU_TO_BE32(x) swap32(x)
+#        define BE16(x) swap16(x)
+#        define LE16(x) (x)
+
+#        define le16_to_cpu(x) (x)
+#        define cpu_to_le16(x) (x)
+#        define LE16_TO_CPU(x) (x)
+#        define CPU_TO_LE16(x) (x)
+
+#        define be16_to_cpu(x) swap16(x)
+#        define cpu_to_be16(x) swap16(x)
+#        define BE16_TO_CPU(x) swap16(x)
+#        define CPU_TO_BE16(x) swap16(x)
+
+#        define le32_to_cpu(x) (x)
+#        define cpu_to_le32(x) (x)
+#        define LE32_TO_CPU(x) (x)
+#        define CPU_TO_LE32(x) (x)
+
+#        define be32_to_cpu(x) swap32(x)
+#        define cpu_to_be32(x) swap32(x)
+#        define BE32_TO_CPU(x) swap32(x)
+#        define CPU_TO_BE32(x) swap32(x)
 /** @} */
 
-
 /** \name Endianism Conversion
  *
  * The same considerations as for clz and ctz apply here but GCC's
@@ -824,8 +738,7 @@ typedef struct
  *
  * \note More optimized if only used with values known at compile time.
  */
-#define Swap16(u16) ((uint16_t)(((uint16_t)(u16) >> 8) |\
-                           ((uint16_t)(u16) << 8)))
+#        define Swap16(u16) ((uint16_t)(((uint16_t)(u16) >> 8) | ((uint16_t)(u16) << 8)))
 
 /** \brief Toggles the endianism of \a u32 (by swapping its bytes).
  *
@@ -835,8 +748,7 @@ typedef struct
  *
  * \note More optimized if only used with values known at compile time.
  */
-#define Swap32(u32) ((uint32_t)(((uint32_t)Swap16((uint32_t)(u32) >> 16)) |\
-                           ((uint32_t)Swap16((uint32_t)(u32)) << 16)))
+#        define Swap32(u32) ((uint32_t)(((uint32_t)Swap16((uint32_t)(u32) >> 16)) | ((uint32_t)Swap16((uint32_t)(u32)) << 16)))
 
 /** \brief Toggles the endianism of \a u64 (by swapping its bytes).
  *
@@ -846,8 +758,7 @@ typedef struct
  *
  * \note More optimized if only used with values known at compile time.
  */
-#define Swap64(u64) ((uint64_t)(((uint64_t)Swap32((uint64_t)(u64) >> 32)) |\
-                           ((uint64_t)Swap32((uint64_t)(u64)) << 32)))
+#        define Swap64(u64) ((uint64_t)(((uint64_t)Swap32((uint64_t)(u64) >> 32)) | ((uint64_t)Swap32((uint64_t)(u64)) << 32)))
 
 /** \brief Toggles the endianism of \a u16 (by swapping its bytes).
  *
@@ -857,7 +768,7 @@ typedef struct
  *
  * \note More optimized if only used with values unknown at compile time.
  */
-#define swap16(u16) Swap16(u16)
+#        define swap16(u16) Swap16(u16)
 
 /** \brief Toggles the endianism of \a u32 (by swapping its bytes).
  *
@@ -867,11 +778,11 @@ typedef struct
  *
  * \note More optimized if only used with values unknown at compile time.
  */
-#if (defined __GNUC__)
-#  define swap32(u32) ((uint32_t)__builtin_bswap32((uint32_t)(u32)))
-#else
-#  define swap32(u32) Swap32(u32)
-#endif
+#        if (defined __GNUC__)
+#            define swap32(u32) ((uint32_t)__builtin_bswap32((uint32_t)(u32)))
+#        else
+#            define swap32(u32) Swap32(u32)
+#        endif
 
 /** \brief Toggles the endianism of \a u64 (by swapping its bytes).
  *
@@ -881,30 +792,28 @@ typedef struct
  *
  * \note More optimized if only used with values unknown at compile time.
  */
-#if (defined __GNUC__)
-#  define swap64(u64) ((uint64_t)__builtin_bswap64((uint64_t)(u64)))
-#else
-#  define swap64(u64) ((uint64_t)(((uint64_t)swap32((uint64_t)(u64) >> 32)) |\
-                         ((uint64_t)swap32((uint64_t)(u64)) << 32)))
-#endif
+#        if (defined __GNUC__)
+#            define swap64(u64) ((uint64_t)__builtin_bswap64((uint64_t)(u64)))
+#        else
+#            define swap64(u64) ((uint64_t)(((uint64_t)swap32((uint64_t)(u64) >> 32)) | ((uint64_t)swap32((uint64_t)(u64)) << 32)))
+#        endif
 
 /** @} */
 
-
 /** \name Target Abstraction
  *
  * @{ */
 
-#define _GLOBEXT_           extern      /**< extern storage-class specifier. */
-#define _CONST_TYPE_        const       /**< const type qualifier. */
-#define _MEM_TYPE_SLOW_                 /**< Slow memory type. */
-#define _MEM_TYPE_MEDFAST_              /**< Fairly fast memory type. */
-#define _MEM_TYPE_FAST_                 /**< Fast memory type. */
+#        define _GLOBEXT_ extern   /**< extern storage-class specifier. */
+#        define _CONST_TYPE_ const /**< const type qualifier. */
+#        define _MEM_TYPE_SLOW_    /**< Slow memory type. */
+#        define _MEM_TYPE_MEDFAST_ /**< Fairly fast memory type. */
+#        define _MEM_TYPE_FAST_    /**< Fast memory type. */
 
-#define memcmp_ram2ram      memcmp      /**< Target-specific memcmp of RAM to RAM. */
-#define memcmp_code2ram     memcmp      /**< Target-specific memcmp of RAM to NVRAM. */
-#define memcpy_ram2ram      memcpy      /**< Target-specific memcpy from RAM to RAM. */
-#define memcpy_code2ram     memcpy      /**< Target-specific memcpy from NVRAM to RAM. */
+#        define memcmp_ram2ram memcmp  /**< Target-specific memcmp of RAM to RAM. */
+#        define memcmp_code2ram memcmp /**< Target-specific memcmp of RAM to NVRAM. */
+#        define memcpy_ram2ram memcpy  /**< Target-specific memcpy from RAM to RAM. */
+#        define memcpy_code2ram memcpy /**< Target-specific memcpy from NVRAM to RAM. */
 
 /** @} */
 
@@ -917,159 +826,162 @@ typedef struct
  *
  * \return (\a a / \a b) rounded up to the nearest integer.
  */
-#define div_ceil(a, b)      (((a) + (b) - 1) / (b))
+#        define div_ceil(a, b) (((a) + (b)-1) / (b))
 
-#endif  /* #ifndef __ASSEMBLY__ */
-#ifdef __ICCARM__
+#    endif /* #ifndef __ASSEMBLY__ */
+#    ifdef __ICCARM__
 /** \name Compiler Keywords
  *
  * Port of some keywords from GCC to IAR Embedded Workbench.
  *
  * @{ */
 
-#define __asm__             asm
-#define __inline__          inline
-#define __volatile__
+#        define __asm__ asm
+#        define __inline__ inline
+#        define __volatile__
 
 /** @} */
 
-#endif
+#    endif
 
-#define FUNC_PTR                            void *
+#    define FUNC_PTR void *
 /**
  * \def unused
  * \brief Marking \a v as a unused parameter or value.
  */
-#define unused(v)          do { (void)(v); } while(0)
+#    define unused(v)  \
+        do {           \
+            (void)(v); \
+        } while (0)
 
 /* Define RAMFUNC attribute */
-#if defined   ( __CC_ARM   ) /* Keil uVision 4 */
-#   define RAMFUNC __attribute__ ((section(".ramfunc")))
-#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
-#   define RAMFUNC __ramfunc
-#elif defined (  __GNUC__  ) /* GCC CS3 2009q3-68 */
-#   define RAMFUNC __attribute__ ((section(".ramfunc")))
-#endif
+#    if defined(__CC_ARM) /* Keil uVision 4 */
+#        define RAMFUNC __attribute__((section(".ramfunc")))
+#    elif defined(__ICCARM__) /* IAR Ewarm 5.41+ */
+#        define RAMFUNC __ramfunc
+#    elif defined(__GNUC__) /* GCC CS3 2009q3-68 */
+#        define RAMFUNC __attribute__((section(".ramfunc")))
+#    endif
 
 /* Define OPTIMIZE_HIGH attribute */
-#if defined   ( __CC_ARM   ) /* Keil uVision 4 */
-#   define OPTIMIZE_HIGH _Pragma("O3")
-#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
-#   define OPTIMIZE_HIGH _Pragma("optimize=high")
-#elif defined (  __GNUC__  ) /* GCC CS3 2009q3-68 */
-#   define OPTIMIZE_HIGH __attribute__((optimize("s")))
-#endif
-//kmod #define PASS      0
-//kmod #define FAIL      1
-//kmod #define LOW       0
-//kmod #define HIGH      1
-
-typedef int8_t                  S8 ;  //!< 8-bit signed integer.
-typedef uint8_t                 U8 ;  //!< 8-bit unsigned integer.
-typedef int16_t                 S16;  //!< 16-bit signed integer.
-typedef uint16_t                U16;  //!< 16-bit unsigned integer.
-typedef int32_t                 S32;  //!< 32-bit signed integer.
-typedef uint32_t                U32;  //!< 32-bit unsigned integer.
-typedef int64_t                 S64;  //!< 64-bit signed integer.
-typedef uint64_t                U64;  //!< 64-bit unsigned integer.
-typedef float                   F32;  //!< 32-bit floating-point number.
-typedef double                  F64;  //!< 64-bit floating-point number.
-
-#define  MSB(u16)       (((U8  *)&(u16))[1]) //!< Most significant byte of \a u16.
-#define  LSB(u16)       (((U8  *)&(u16))[0]) //!< Least significant byte of \a u16.
-
-#define  MSH(u32)       (((U16 *)&(u32))[1]) //!< Most significant half-word of \a u32.
-#define  LSH(u32)       (((U16 *)&(u32))[0]) //!< Least significant half-word of \a u32.
-#define  MSB0W(u32)     (((U8  *)&(u32))[3]) //!< Most significant byte of 1st rank of \a u32.
-#define  MSB1W(u32)     (((U8  *)&(u32))[2]) //!< Most significant byte of 2nd rank of \a u32.
-#define  MSB2W(u32)     (((U8  *)&(u32))[1]) //!< Most significant byte of 3rd rank of \a u32.
-#define  MSB3W(u32)     (((U8  *)&(u32))[0]) //!< Most significant byte of 4th rank of \a u32.
-#define  LSB3W(u32)     MSB0W(u32)           //!< Least significant byte of 4th rank of \a u32.
-#define  LSB2W(u32)     MSB1W(u32)           //!< Least significant byte of 3rd rank of \a u32.
-#define  LSB1W(u32)     MSB2W(u32)           //!< Least significant byte of 2nd rank of \a u32.
-#define  LSB0W(u32)     MSB3W(u32)           //!< Least significant byte of 1st rank of \a u32.
-
-#define  MSW(u64)       (((U32 *)&(u64))[1]) //!< Most significant word of \a u64.
-#define  LSW(u64)       (((U32 *)&(u64))[0]) //!< Least significant word of \a u64.
-#define  MSH0(u64)      (((U16 *)&(u64))[3]) //!< Most significant half-word of 1st rank of \a u64.
-#define  MSH1(u64)      (((U16 *)&(u64))[2]) //!< Most significant half-word of 2nd rank of \a u64.
-#define  MSH2(u64)      (((U16 *)&(u64))[1]) //!< Most significant half-word of 3rd rank of \a u64.
-#define  MSH3(u64)      (((U16 *)&(u64))[0]) //!< Most significant half-word of 4th rank of \a u64.
-#define  LSH3(u64)      MSH0(u64)            //!< Least significant half-word of 4th rank of \a u64.
-#define  LSH2(u64)      MSH1(u64)            //!< Least significant half-word of 3rd rank of \a u64.
-#define  LSH1(u64)      MSH2(u64)            //!< Least significant half-word of 2nd rank of \a u64.
-#define  LSH0(u64)      MSH3(u64)            //!< Least significant half-word of 1st rank of \a u64.
-#define  MSB0D(u64)     (((U8  *)&(u64))[7]) //!< Most significant byte of 1st rank of \a u64.
-#define  MSB1D(u64)     (((U8  *)&(u64))[6]) //!< Most significant byte of 2nd rank of \a u64.
-#define  MSB2D(u64)     (((U8  *)&(u64))[5]) //!< Most significant byte of 3rd rank of \a u64.
-#define  MSB3D(u64)     (((U8  *)&(u64))[4]) //!< Most significant byte of 4th rank of \a u64.
-#define  MSB4D(u64)     (((U8  *)&(u64))[3]) //!< Most significant byte of 5th rank of \a u64.
-#define  MSB5D(u64)     (((U8  *)&(u64))[2]) //!< Most significant byte of 6th rank of \a u64.
-#define  MSB6D(u64)     (((U8  *)&(u64))[1]) //!< Most significant byte of 7th rank of \a u64.
-#define  MSB7D(u64)     (((U8  *)&(u64))[0]) //!< Most significant byte of 8th rank of \a u64.
-#define  LSB7D(u64)     MSB0D(u64)           //!< Least significant byte of 8th rank of \a u64.
-#define  LSB6D(u64)     MSB1D(u64)           //!< Least significant byte of 7th rank of \a u64.
-#define  LSB5D(u64)     MSB2D(u64)           //!< Least significant byte of 6th rank of \a u64.
-#define  LSB4D(u64)     MSB3D(u64)           //!< Least significant byte of 5th rank of \a u64.
-#define  LSB3D(u64)     MSB4D(u64)           //!< Least significant byte of 4th rank of \a u64.
-#define  LSB2D(u64)     MSB5D(u64)           //!< Least significant byte of 3rd rank of \a u64.
-#define  LSB1D(u64)     MSB6D(u64)           //!< Least significant byte of 2nd rank of \a u64.
-#define  LSB0D(u64)     MSB7D(u64)           //!< Least significant byte of 1st rank of \a u64.
-
-#define LSB0(u32)           LSB0W(u32)  //!< Least significant byte of 1st rank of \a u32.
-#define LSB1(u32)           LSB1W(u32)  //!< Least significant byte of 2nd rank of \a u32.
-#define LSB2(u32)           LSB2W(u32)  //!< Least significant byte of 3rd rank of \a u32.
-#define LSB3(u32)           LSB3W(u32)  //!< Least significant byte of 4th rank of \a u32.
-#define MSB3(u32)           MSB3W(u32)  //!< Most significant byte of 4th rank of \a u32.
-#define MSB2(u32)           MSB2W(u32)  //!< Most significant byte of 3rd rank of \a u32.
-#define MSB1(u32)           MSB1W(u32)  //!< Most significant byte of 2nd rank of \a u32.
-#define MSB0(u32)           MSB0W(u32)  //!< Most significant byte of 1st rank of \a u32.
-
-#if defined(__ICCARM__)
-#define SHORTENUM           __packed
-#elif defined(__GNUC__)
-#define SHORTENUM           __attribute__((packed))
-#endif
+#    if defined(__CC_ARM) /* Keil uVision 4 */
+#        define OPTIMIZE_HIGH _Pragma("O3")
+#    elif defined(__ICCARM__) /* IAR Ewarm 5.41+ */
+#        define OPTIMIZE_HIGH _Pragma("optimize=high")
+#    elif defined(__GNUC__) /* GCC CS3 2009q3-68 */
+#        define OPTIMIZE_HIGH __attribute__((optimize("s")))
+#    endif
+// kmod #define PASS      0
+// kmod #define FAIL      1
+// kmod #define LOW       0
+// kmod #define HIGH      1
+
+typedef int8_t   S8;   //!< 8-bit signed integer.
+typedef uint8_t  U8;   //!< 8-bit unsigned integer.
+typedef int16_t  S16;  //!< 16-bit signed integer.
+typedef uint16_t U16;  //!< 16-bit unsigned integer.
+typedef int32_t  S32;  //!< 32-bit signed integer.
+typedef uint32_t U32;  //!< 32-bit unsigned integer.
+typedef int64_t  S64;  //!< 64-bit signed integer.
+typedef uint64_t U64;  //!< 64-bit unsigned integer.
+typedef float    F32;  //!< 32-bit floating-point number.
+typedef double   F64;  //!< 64-bit floating-point number.
+
+#    define MSB(u16) (((U8 *)&(u16))[1])  //!< Most significant byte of \a u16.
+#    define LSB(u16) (((U8 *)&(u16))[0])  //!< Least significant byte of \a u16.
+
+#    define MSH(u32) (((U16 *)&(u32))[1])   //!< Most significant half-word of \a u32.
+#    define LSH(u32) (((U16 *)&(u32))[0])   //!< Least significant half-word of \a u32.
+#    define MSB0W(u32) (((U8 *)&(u32))[3])  //!< Most significant byte of 1st rank of \a u32.
+#    define MSB1W(u32) (((U8 *)&(u32))[2])  //!< Most significant byte of 2nd rank of \a u32.
+#    define MSB2W(u32) (((U8 *)&(u32))[1])  //!< Most significant byte of 3rd rank of \a u32.
+#    define MSB3W(u32) (((U8 *)&(u32))[0])  //!< Most significant byte of 4th rank of \a u32.
+#    define LSB3W(u32) MSB0W(u32)           //!< Least significant byte of 4th rank of \a u32.
+#    define LSB2W(u32) MSB1W(u32)           //!< Least significant byte of 3rd rank of \a u32.
+#    define LSB1W(u32) MSB2W(u32)           //!< Least significant byte of 2nd rank of \a u32.
+#    define LSB0W(u32) MSB3W(u32)           //!< Least significant byte of 1st rank of \a u32.
+
+#    define MSW(u64) (((U32 *)&(u64))[1])   //!< Most significant word of \a u64.
+#    define LSW(u64) (((U32 *)&(u64))[0])   //!< Least significant word of \a u64.
+#    define MSH0(u64) (((U16 *)&(u64))[3])  //!< Most significant half-word of 1st rank of \a u64.
+#    define MSH1(u64) (((U16 *)&(u64))[2])  //!< Most significant half-word of 2nd rank of \a u64.
+#    define MSH2(u64) (((U16 *)&(u64))[1])  //!< Most significant half-word of 3rd rank of \a u64.
+#    define MSH3(u64) (((U16 *)&(u64))[0])  //!< Most significant half-word of 4th rank of \a u64.
+#    define LSH3(u64) MSH0(u64)             //!< Least significant half-word of 4th rank of \a u64.
+#    define LSH2(u64) MSH1(u64)             //!< Least significant half-word of 3rd rank of \a u64.
+#    define LSH1(u64) MSH2(u64)             //!< Least significant half-word of 2nd rank of \a u64.
+#    define LSH0(u64) MSH3(u64)             //!< Least significant half-word of 1st rank of \a u64.
+#    define MSB0D(u64) (((U8 *)&(u64))[7])  //!< Most significant byte of 1st rank of \a u64.
+#    define MSB1D(u64) (((U8 *)&(u64))[6])  //!< Most significant byte of 2nd rank of \a u64.
+#    define MSB2D(u64) (((U8 *)&(u64))[5])  //!< Most significant byte of 3rd rank of \a u64.
+#    define MSB3D(u64) (((U8 *)&(u64))[4])  //!< Most significant byte of 4th rank of \a u64.
+#    define MSB4D(u64) (((U8 *)&(u64))[3])  //!< Most significant byte of 5th rank of \a u64.
+#    define MSB5D(u64) (((U8 *)&(u64))[2])  //!< Most significant byte of 6th rank of \a u64.
+#    define MSB6D(u64) (((U8 *)&(u64))[1])  //!< Most significant byte of 7th rank of \a u64.
+#    define MSB7D(u64) (((U8 *)&(u64))[0])  //!< Most significant byte of 8th rank of \a u64.
+#    define LSB7D(u64) MSB0D(u64)           //!< Least significant byte of 8th rank of \a u64.
+#    define LSB6D(u64) MSB1D(u64)           //!< Least significant byte of 7th rank of \a u64.
+#    define LSB5D(u64) MSB2D(u64)           //!< Least significant byte of 6th rank of \a u64.
+#    define LSB4D(u64) MSB3D(u64)           //!< Least significant byte of 5th rank of \a u64.
+#    define LSB3D(u64) MSB4D(u64)           //!< Least significant byte of 4th rank of \a u64.
+#    define LSB2D(u64) MSB5D(u64)           //!< Least significant byte of 3rd rank of \a u64.
+#    define LSB1D(u64) MSB6D(u64)           //!< Least significant byte of 2nd rank of \a u64.
+#    define LSB0D(u64) MSB7D(u64)           //!< Least significant byte of 1st rank of \a u64.
+
+#    define LSB0(u32) LSB0W(u32)  //!< Least significant byte of 1st rank of \a u32.
+#    define LSB1(u32) LSB1W(u32)  //!< Least significant byte of 2nd rank of \a u32.
+#    define LSB2(u32) LSB2W(u32)  //!< Least significant byte of 3rd rank of \a u32.
+#    define LSB3(u32) LSB3W(u32)  //!< Least significant byte of 4th rank of \a u32.
+#    define MSB3(u32) MSB3W(u32)  //!< Most significant byte of 4th rank of \a u32.
+#    define MSB2(u32) MSB2W(u32)  //!< Most significant byte of 3rd rank of \a u32.
+#    define MSB1(u32) MSB1W(u32)  //!< Most significant byte of 2nd rank of \a u32.
+#    define MSB0(u32) MSB0W(u32)  //!< Most significant byte of 1st rank of \a u32.
+
+#    if defined(__ICCARM__)
+#        define SHORTENUM __packed
+#    elif defined(__GNUC__)
+#        define SHORTENUM __attribute__((packed))
+#    endif
 
 /* No operation */
-#if defined(__ICCARM__)
-#define nop()               __no_operation()
-#elif defined(__GNUC__)
-#define nop()               (__NOP())
-#endif
-
-#define FLASH_DECLARE(x)  const x
-#define FLASH_EXTERN(x) extern const x
-#define PGM_READ_BYTE(x) *(x)
-#define PGM_READ_WORD(x) *(x)
-#define MEMCPY_ENDIAN memcpy
-#define PGM_READ_BLOCK(dst, src, len) memcpy((dst), (src), (len))
+#    if defined(__ICCARM__)
+#        define nop() __no_operation()
+#    elif defined(__GNUC__)
+#        define nop() (__NOP())
+#    endif
+
+#    define FLASH_DECLARE(x) const x
+#    define FLASH_EXTERN(x) extern const x
+#    define PGM_READ_BYTE(x) *(x)
+#    define PGM_READ_WORD(x) *(x)
+#    define MEMCPY_ENDIAN memcpy
+#    define PGM_READ_BLOCK(dst, src, len) memcpy((dst), (src), (len))
 
 /*Defines the Flash Storage for the request and response of MAC*/
-#define CMD_ID_OCTET    (0)
+#    define CMD_ID_OCTET (0)
 
 /* Converting of values from CPU endian to little endian. */
-#define CPU_ENDIAN_TO_LE16(x)   (x)
-#define CPU_ENDIAN_TO_LE32(x)   (x)
-#define CPU_ENDIAN_TO_LE64(x)   (x)
+#    define CPU_ENDIAN_TO_LE16(x) (x)
+#    define CPU_ENDIAN_TO_LE32(x) (x)
+#    define CPU_ENDIAN_TO_LE64(x) (x)
 
 /* Converting of values from little endian to CPU endian. */
-#define LE16_TO_CPU_ENDIAN(x)   (x)
-#define LE32_TO_CPU_ENDIAN(x)   (x)
-#define LE64_TO_CPU_ENDIAN(x)   (x)
+#    define LE16_TO_CPU_ENDIAN(x) (x)
+#    define LE32_TO_CPU_ENDIAN(x) (x)
+#    define LE64_TO_CPU_ENDIAN(x) (x)
 
 /* Converting of constants from little endian to CPU endian. */
-#define CLE16_TO_CPU_ENDIAN(x)  (x)
-#define CLE32_TO_CPU_ENDIAN(x)  (x)
-#define CLE64_TO_CPU_ENDIAN(x)  (x)
+#    define CLE16_TO_CPU_ENDIAN(x) (x)
+#    define CLE32_TO_CPU_ENDIAN(x) (x)
+#    define CLE64_TO_CPU_ENDIAN(x) (x)
 
 /* Converting of constants from CPU endian to little endian. */
-#define CCPU_ENDIAN_TO_LE16(x)  (x)
-#define CCPU_ENDIAN_TO_LE32(x)  (x)
-#define CCPU_ENDIAN_TO_LE64(x)  (x)
+#    define CCPU_ENDIAN_TO_LE16(x) (x)
+#    define CCPU_ENDIAN_TO_LE32(x) (x)
+#    define CCPU_ENDIAN_TO_LE64(x) (x)
 
-#define ADDR_COPY_DST_SRC_16(dst, src)  ((dst) = (src))
-#define ADDR_COPY_DST_SRC_64(dst, src)  ((dst) = (src))
+#    define ADDR_COPY_DST_SRC_16(dst, src) ((dst) = (src))
+#    define ADDR_COPY_DST_SRC_64(dst, src) ((dst) = (src))
 
 /**
  * @brief Converts a 64-Bit value into  a 8 Byte array
@@ -1078,14 +990,12 @@ typedef double                  F64;  //!< 64-bit floating-point number.
  * @param[out] data Pointer to the 8 Byte array to be updated with 64-Bit value
  * @ingroup apiPalApi
  */
-static inline void convert_64_bit_to_byte_array(uint64_t value, uint8_t *data)
-{
+static inline void convert_64_bit_to_byte_array(uint64_t value, uint8_t *data) {
     uint8_t index = 0;
 
-    while (index < 8)
-    {
+    while (index < 8) {
         data[index++] = value & 0xFF;
-        value = value >> 8;
+        value         = value >> 8;
     }
 }
 
@@ -1096,22 +1006,19 @@ static inline void convert_64_bit_to_byte_array(uint64_t value, uint8_t *data)
  * @param[out] data Pointer to the 2 Byte array to be updated with 16-Bit value
  * @ingroup apiPalApi
  */
-static inline void convert_16_bit_to_byte_array(uint16_t value, uint8_t *data)
-{
+static inline void convert_16_bit_to_byte_array(uint16_t value, uint8_t *data) {
     data[0] = value & 0xFF;
     data[1] = (value >> 8) & 0xFF;
 }
 
 /* Converts a 16-Bit value into a 2 Byte array */
-static inline void convert_spec_16_bit_to_byte_array(uint16_t value, uint8_t *data)
-{
+static inline void convert_spec_16_bit_to_byte_array(uint16_t value, uint8_t *data) {
     data[0] = value & 0xFF;
     data[1] = (value >> 8) & 0xFF;
 }
 
 /* Converts a 16-Bit value into a 2 Byte array */
-static inline void convert_16_bit_to_byte_address(uint16_t value, uint8_t *data)
-{
+static inline void convert_16_bit_to_byte_address(uint16_t value, uint8_t *data) {
     data[0] = value & 0xFF;
     data[1] = (value >> 8) & 0xFF;
 }
@@ -1124,24 +1031,18 @@ static inline void convert_16_bit_to_byte_address(uint16_t value, uint8_t *data)
  * @return 16-Bit value
  * @ingroup apiPalApi
  */
-static inline uint16_t convert_byte_array_to_16_bit(uint8_t *data)
-{
-    return (data[0] | ((uint16_t)data[1] << 8));
-}
+static inline uint16_t convert_byte_array_to_16_bit(uint8_t *data) { return (data[0] | ((uint16_t)data[1] << 8)); }
 
 /* Converts a 4 Byte array into a 32-Bit value */
-static inline uint32_t convert_byte_array_to_32_bit(uint8_t *data)
-{
-    union
-    {
+static inline uint32_t convert_byte_array_to_32_bit(uint8_t *data) {
+    union {
         uint32_t u32;
-        uint8_t u8[4];
+        uint8_t  u8[4];
     } long_addr;
 
     uint8_t index;
 
-    for (index = 0; index < 4; index++)
-    {
+    for (index = 0; index < 4; index++) {
         long_addr.u8[index] = *data++;
     }
 
@@ -1156,18 +1057,15 @@ static inline uint32_t convert_byte_array_to_32_bit(uint8_t *data)
  * @return 64-Bit value
  * @ingroup apiPalApi
  */
-static inline uint64_t convert_byte_array_to_64_bit(uint8_t *data)
-{
-    union
-    {
+static inline uint64_t convert_byte_array_to_64_bit(uint8_t *data) {
+    union {
         uint64_t u64;
-        uint8_t u8[8];
+        uint8_t  u8[8];
     } long_addr;
 
     uint8_t index;
 
-    for (index = 0; index < 8; index++)
-    {
+    for (index = 0; index < 8; index++) {
         long_addr.u8[index] = *data++;
     }
 
index c91caffe02fe265c24aeb0b277d582eafef23557..f23c2a80dda0aecf927a70f71d58ae4f947d7dc5 100644 (file)
 #include "compiler.h"
 #include "udi_device_conf.h"
 
-#define  UDI_CDC_DEFAULT_RATE           115200
-#define  UDI_CDC_DEFAULT_STOPBITS       CDC_STOP_BITS_1
-#define  UDI_CDC_DEFAULT_PARITY         CDC_PAR_NONE
-#define  UDI_CDC_DEFAULT_DATABITS       8
+#define UDI_CDC_DEFAULT_RATE 115200
+#define UDI_CDC_DEFAULT_STOPBITS CDC_STOP_BITS_1
+#define UDI_CDC_DEFAULT_PARITY CDC_PAR_NONE
+#define UDI_CDC_DEFAULT_DATABITS 8
 
 //! Device definition (mandatory)
-#define  USB_DEVICE_VENDOR_ID           VENDOR_ID
-#define  USB_DEVICE_PRODUCT_ID          PRODUCT_ID
-#define  USB_DEVICE_VERSION             DEVICE_VER
-#define  USB_DEVICE_POWER               500 // Consumption on Vbus line (mA)
-#define  USB_DEVICE_ATTR                (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_BUS_POWERED)
+#define USB_DEVICE_VENDOR_ID VENDOR_ID
+#define USB_DEVICE_PRODUCT_ID PRODUCT_ID
+#define USB_DEVICE_VERSION DEVICE_VER
+#define USB_DEVICE_POWER 500  // Consumption on Vbus line (mA)
+#define USB_DEVICE_ATTR (USB_CONFIG_ATTR_REMOTE_WAKEUP | USB_CONFIG_ATTR_BUS_POWERED)
 //                                      (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_BUS_POWERED)
 //                                      (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_SELF_POWERED)
 //                                      (USB_CONFIG_ATTR_SELF_POWERED)
 //                                      (USB_CONFIG_ATTR_BUS_POWERED)
 
 //! USB Device string definitions (Optional)
-#define  USB_DEVICE_MANUFACTURE_NAME      MANUFACTURER
-#define  USB_DEVICE_PRODUCT_NAME          PRODUCT
-#define  USB_DEVICE_SERIAL_NAME           SERIAL_NUM
+#define USB_DEVICE_MANUFACTURE_NAME MANUFACTURER
+#define USB_DEVICE_PRODUCT_NAME PRODUCT
+#define USB_DEVICE_SERIAL_NAME SERIAL_NUM
 
-//Comment out USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL to prevent ROM lookup of factory programmed serial number
-#define  USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL
+// Comment out USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL to prevent ROM lookup of factory programmed serial number
+#define USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL
 
 /**
  * Device speeds support
@@ -82,9 +82,9 @@
 //#define  USB_DEVICE_LOW_SPEED
 
 //! To authorize the High speed
-#if (UC3A3||UC3A4)
+#if (UC3A3 || UC3A4)
 //#define  USB_DEVICE_HS_SUPPORT
-#elif (SAM3XA||SAM3U)
+#elif (SAM3XA || SAM3U)
 //#define  USB_DEVICE_HS_SUPPORT
 #endif
 //@}
  * USB Device Callbacks definitions (Optional)
  * @{
  */
-#define  UDC_VBUS_EVENT(b_vbus_high)
-#define  UDC_SOF_EVENT()                  main_sof_action()
-#define  UDC_SUSPEND_EVENT()              main_suspend_action()
-#define  UDC_RESUME_EVENT()               main_resume_action()
+#define UDC_VBUS_EVENT(b_vbus_high)
+#define UDC_SOF_EVENT() main_sof_action()
+#define UDC_SUSPEND_EVENT() main_suspend_action()
+#define UDC_RESUME_EVENT() main_resume_action()
 //! Mandatory when USB_DEVICE_ATTR authorizes remote wakeup feature
-#define  UDC_REMOTEWAKEUP_ENABLE()        main_remotewakeup_enable()
-#define  UDC_REMOTEWAKEUP_DISABLE()       main_remotewakeup_disable()
+#define UDC_REMOTEWAKEUP_ENABLE() main_remotewakeup_enable()
+#define UDC_REMOTEWAKEUP_DISABLE() main_remotewakeup_disable()
 //! When a extra string descriptor must be supported
 //! other than manufacturer, product and serial string
 // #define  UDC_GET_EXTRA_STRING()
 
 //@}
 
-
 /**
  * USB Interface Configuration
  * @{
  */
 //! Interface callback definition
 #ifdef KBD
-#define  UDI_HID_KBD_ENABLE_EXT()       main_kbd_enable()
-#define  UDI_HID_KBD_DISABLE_EXT()      main_kbd_disable()
+#    define UDI_HID_KBD_ENABLE_EXT() main_kbd_enable()
+#    define UDI_HID_KBD_DISABLE_EXT() main_kbd_disable()
 //#define  UDI_HID_KBD_CHANGE_LED(value)  ui_kbd_led(value)
 #endif
 
 #ifdef NKRO
-#define  UDI_HID_NKRO_ENABLE_EXT()       main_nkro_enable()
-#define  UDI_HID_NKRO_DISABLE_EXT()      main_nkro_disable()
+#    define UDI_HID_NKRO_ENABLE_EXT() main_nkro_enable()
+#    define UDI_HID_NKRO_DISABLE_EXT() main_nkro_disable()
 //#define  UDI_HID_NKRO_CHANGE_LED(value)   ui_kbd_led(value)
 #endif
 
 #ifdef EXK
-#define  UDI_HID_EXK_ENABLE_EXT()       main_exk_enable()
-#define  UDI_HID_EXK_DISABLE_EXT()      main_exk_disable()
+#    define UDI_HID_EXK_ENABLE_EXT() main_exk_enable()
+#    define UDI_HID_EXK_DISABLE_EXT() main_exk_disable()
 #endif
 
 #ifdef CON
-#define  UDI_HID_CON_ENABLE_EXT()       main_con_enable()
-#define  UDI_HID_CON_DISABLE_EXT()      main_con_disable()
+#    define UDI_HID_CON_ENABLE_EXT() main_con_enable()
+#    define UDI_HID_CON_DISABLE_EXT() main_con_disable()
 #endif
 
 #ifdef MOU
-#define  UDI_HID_MOU_ENABLE_EXT()       main_mou_enable()
-#define  UDI_HID_MOU_DISABLE_EXT()      main_mou_disable()
+#    define UDI_HID_MOU_ENABLE_EXT() main_mou_enable()
+#    define UDI_HID_MOU_DISABLE_EXT() main_mou_disable()
 #endif
 
 #ifdef RAW
-#define  UDI_HID_RAW_ENABLE_EXT()       main_raw_enable()
-#define  UDI_HID_RAW_DISABLE_EXT()      main_raw_disable()
+#    define UDI_HID_RAW_ENABLE_EXT() main_raw_enable()
+#    define UDI_HID_RAW_DISABLE_EXT() main_raw_disable()
 #endif
 
-
 //@}
 //@}
 
-
 /**
  * USB Device Driver Configuration
  * @{
 #include "usb_main.h"
 #include "ui.h"
 
-#endif // _CONF_USB_H_
+#endif  // _CONF_USB_H_
index 0f676ab639d95d3335e40da0e32d680210cd3816..82ab123fd0f913868092de6eaf920652e47ea4f3 100644 (file)
@@ -21,112 +21,72 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 uint8_t keyboard_protocol = 1;
 
-void main_suspend_action(void)
-{
-    ui_powerdown();
-}
+void main_suspend_action(void) { ui_powerdown(); }
 
-void main_resume_action(void)
-{
-    ui_wakeup();
-}
+void main_resume_action(void) { ui_wakeup(); }
 
-void main_sof_action(void)
-{
-    ui_process(udd_get_frame_number());
-}
+void main_sof_action(void) { ui_process(udd_get_frame_number()); }
 
-void main_remotewakeup_enable(void)
-{
-    ui_wakeup_enable();
-}
+void main_remotewakeup_enable(void) { ui_wakeup_enable(); }
 
-void main_remotewakeup_disable(void)
-{
-    ui_wakeup_disable();
-}
+void main_remotewakeup_disable(void) { ui_wakeup_disable(); }
 
 #ifdef KBD
 volatile bool main_b_kbd_enable = false;
-bool main_kbd_enable(void)
-{
+bool          main_kbd_enable(void) {
     main_b_kbd_enable = true;
     return true;
 }
 
-void main_kbd_disable(void)
-{
-    main_b_kbd_enable = false;
-}
+void main_kbd_disable(void) { main_b_kbd_enable = false; }
 #endif
 
 #ifdef NKRO
 volatile bool main_b_nkro_enable = false;
-bool main_nkro_enable(void)
-{
+bool          main_nkro_enable(void) {
     main_b_nkro_enable = true;
     return true;
 }
 
-void main_nkro_disable(void)
-{
-    main_b_nkro_enable = false;
-}
+void main_nkro_disable(void) { main_b_nkro_enable = false; }
 #endif
 
 #ifdef EXK
 volatile bool main_b_exk_enable = false;
-bool main_exk_enable(void)
-{
+bool          main_exk_enable(void) {
     main_b_exk_enable = true;
     return true;
 }
 
-void main_exk_disable(void)
-{
-    main_b_exk_enable = false;
-}
+void main_exk_disable(void) { main_b_exk_enable = false; }
 #endif
 
 #ifdef CON
 volatile bool main_b_con_enable = false;
-bool main_con_enable(void)
-{
+bool          main_con_enable(void) {
     main_b_con_enable = true;
     return true;
 }
 
-void main_con_disable(void)
-{
-    main_b_con_enable = false;
-}
+void main_con_disable(void) { main_b_con_enable = false; }
 #endif
 
 #ifdef MOU
 volatile bool main_b_mou_enable = false;
-bool main_mou_enable(void)
-{
+bool          main_mou_enable(void) {
     main_b_mou_enable = true;
     return true;
 }
 
-void main_mou_disable(void)
-{
-    main_b_mou_enable = false;
-}
+void main_mou_disable(void) { main_b_mou_enable = false; }
 #endif
 
 #ifdef RAW
 volatile bool main_b_raw_enable = false;
-bool main_raw_enable(void)
-{
+bool          main_raw_enable(void) {
     main_b_raw_enable = true;
     return true;
 }
 
-void main_raw_disable(void)
-{
-    main_b_raw_enable = false;
-}
+void main_raw_disable(void) { main_b_raw_enable = false; }
 #endif
-
index f56d2faed14562b0b85a702e29f94292f1df2df9..a7a1230be0a9babe250eebebd5d60940de0fb81d 100644 (file)
  */
 
 /** Mask to retrieve the error category of a status code. */
-#define STATUS_CATEGORY_MASK  0xF0
+#define STATUS_CATEGORY_MASK 0xF0
 
 /** Mask to retrieve the error code within the category of a status code. */
-#define STATUS_ERROR_MASK     0x0F
+#define STATUS_ERROR_MASK 0x0F
 
 /** Status code error categories. */
 enum status_categories {
-    STATUS_CATEGORY_OK                = 0x00,
-    STATUS_CATEGORY_COMMON            = 0x10,
-    STATUS_CATEGORY_ANALOG            = 0x30,
-    STATUS_CATEGORY_COM               = 0x40,
-    STATUS_CATEGORY_IO                = 0x50,
+    STATUS_CATEGORY_OK     = 0x00,
+    STATUS_CATEGORY_COMMON = 0x10,
+    STATUS_CATEGORY_ANALOG = 0x30,
+    STATUS_CATEGORY_COM    = 0x40,
+    STATUS_CATEGORY_IO     = 0x50,
 };
 
 /**
@@ -85,37 +85,37 @@ enum status_categories {
  * at the same time.
  */
 enum status_code {
-    STATUS_OK                         = STATUS_CATEGORY_OK     | 0x00,
-    STATUS_VALID_DATA                 = STATUS_CATEGORY_OK     | 0x01,
-    STATUS_NO_CHANGE                  = STATUS_CATEGORY_OK     | 0x02,
-    STATUS_ABORTED                    = STATUS_CATEGORY_OK     | 0x04,
-    STATUS_BUSY                       = STATUS_CATEGORY_OK     | 0x05,
-    STATUS_SUSPEND                    = STATUS_CATEGORY_OK     | 0x06,
-
-    STATUS_ERR_IO                     = STATUS_CATEGORY_COMMON | 0x00,
-    STATUS_ERR_REQ_FLUSHED            = STATUS_CATEGORY_COMMON | 0x01,
-    STATUS_ERR_TIMEOUT                = STATUS_CATEGORY_COMMON | 0x02,
-    STATUS_ERR_BAD_DATA               = STATUS_CATEGORY_COMMON | 0x03,
-    STATUS_ERR_NOT_FOUND              = STATUS_CATEGORY_COMMON | 0x04,
-    STATUS_ERR_UNSUPPORTED_DEV        = STATUS_CATEGORY_COMMON | 0x05,
-    STATUS_ERR_NO_MEMORY              = STATUS_CATEGORY_COMMON | 0x06,
-    STATUS_ERR_INVALID_ARG            = STATUS_CATEGORY_COMMON | 0x07,
-    STATUS_ERR_BAD_ADDRESS            = STATUS_CATEGORY_COMMON | 0x08,
-    STATUS_ERR_BAD_FORMAT             = STATUS_CATEGORY_COMMON | 0x0A,
-    STATUS_ERR_BAD_FRQ                = STATUS_CATEGORY_COMMON | 0x0B,
-    STATUS_ERR_DENIED                 = STATUS_CATEGORY_COMMON | 0x0c,
-    STATUS_ERR_ALREADY_INITIALIZED    = STATUS_CATEGORY_COMMON | 0x0d,
-    STATUS_ERR_OVERFLOW               = STATUS_CATEGORY_COMMON | 0x0e,
-    STATUS_ERR_NOT_INITIALIZED        = STATUS_CATEGORY_COMMON | 0x0f,
+    STATUS_OK         = STATUS_CATEGORY_OK | 0x00,
+    STATUS_VALID_DATA = STATUS_CATEGORY_OK | 0x01,
+    STATUS_NO_CHANGE  = STATUS_CATEGORY_OK | 0x02,
+    STATUS_ABORTED    = STATUS_CATEGORY_OK | 0x04,
+    STATUS_BUSY       = STATUS_CATEGORY_OK | 0x05,
+    STATUS_SUSPEND    = STATUS_CATEGORY_OK | 0x06,
+
+    STATUS_ERR_IO                  = STATUS_CATEGORY_COMMON | 0x00,
+    STATUS_ERR_REQ_FLUSHED         = STATUS_CATEGORY_COMMON | 0x01,
+    STATUS_ERR_TIMEOUT             = STATUS_CATEGORY_COMMON | 0x02,
+    STATUS_ERR_BAD_DATA            = STATUS_CATEGORY_COMMON | 0x03,
+    STATUS_ERR_NOT_FOUND           = STATUS_CATEGORY_COMMON | 0x04,
+    STATUS_ERR_UNSUPPORTED_DEV     = STATUS_CATEGORY_COMMON | 0x05,
+    STATUS_ERR_NO_MEMORY           = STATUS_CATEGORY_COMMON | 0x06,
+    STATUS_ERR_INVALID_ARG         = STATUS_CATEGORY_COMMON | 0x07,
+    STATUS_ERR_BAD_ADDRESS         = STATUS_CATEGORY_COMMON | 0x08,
+    STATUS_ERR_BAD_FORMAT          = STATUS_CATEGORY_COMMON | 0x0A,
+    STATUS_ERR_BAD_FRQ             = STATUS_CATEGORY_COMMON | 0x0B,
+    STATUS_ERR_DENIED              = STATUS_CATEGORY_COMMON | 0x0c,
+    STATUS_ERR_ALREADY_INITIALIZED = STATUS_CATEGORY_COMMON | 0x0d,
+    STATUS_ERR_OVERFLOW            = STATUS_CATEGORY_COMMON | 0x0e,
+    STATUS_ERR_NOT_INITIALIZED     = STATUS_CATEGORY_COMMON | 0x0f,
 
     STATUS_ERR_SAMPLERATE_UNAVAILABLE = STATUS_CATEGORY_ANALOG | 0x00,
     STATUS_ERR_RESOLUTION_UNAVAILABLE = STATUS_CATEGORY_ANALOG | 0x01,
 
-    STATUS_ERR_BAUDRATE_UNAVAILABLE   = STATUS_CATEGORY_COM    | 0x00,
-    STATUS_ERR_PACKET_COLLISION       = STATUS_CATEGORY_COM    | 0x01,
-    STATUS_ERR_PROTOCOL               = STATUS_CATEGORY_COM    | 0x02,
+    STATUS_ERR_BAUDRATE_UNAVAILABLE = STATUS_CATEGORY_COM | 0x00,
+    STATUS_ERR_PACKET_COLLISION     = STATUS_CATEGORY_COM | 0x01,
+    STATUS_ERR_PROTOCOL             = STATUS_CATEGORY_COM | 0x02,
 
-    STATUS_ERR_PIN_MUX_INVALID        = STATUS_CATEGORY_IO     | 0x00,
+    STATUS_ERR_PIN_MUX_INVALID = STATUS_CATEGORY_IO | 0x00,
 };
 typedef enum status_code status_code_genare_t;
 
@@ -123,21 +123,21 @@ typedef enum status_code status_code_genare_t;
   Status codes used by MAC stack.
  */
 enum status_code_wireless {
-    //STATUS_OK               =  0, //!< Success
-    ERR_IO_ERROR            =  -1, //!< I/O error
-    ERR_FLUSHED             =  -2, //!< Request flushed from queue
-    ERR_TIMEOUT             =  -3, //!< Operation timed out
-    ERR_BAD_DATA            =  -4, //!< Data integrity check failed
-    ERR_PROTOCOL            =  -5, //!< Protocol error
-    ERR_UNSUPPORTED_DEV     =  -6, //!< Unsupported device
-    ERR_NO_MEMORY           =  -7, //!< Insufficient memory
-    ERR_INVALID_ARG         =  -8, //!< Invalid argument
-    ERR_BAD_ADDRESS         =  -9, //!< Bad address
-    ERR_BUSY                =  -10, //!< Resource is busy
-    ERR_BAD_FORMAT          =  -11, //!< Data format not recognized
-    ERR_NO_TIMER            =  -12, //!< No timer available
-    ERR_TIMER_ALREADY_RUNNING   =  -13, //!< Timer already running
-    ERR_TIMER_NOT_RUNNING   =  -14, //!< Timer not running
+    // STATUS_OK               =  0, //!< Success
+    ERR_IO_ERROR              = -1,   //!< I/O error
+    ERR_FLUSHED               = -2,   //!< Request flushed from queue
+    ERR_TIMEOUT               = -3,   //!< Operation timed out
+    ERR_BAD_DATA              = -4,   //!< Data integrity check failed
+    ERR_PROTOCOL              = -5,   //!< Protocol error
+    ERR_UNSUPPORTED_DEV       = -6,   //!< Unsupported device
+    ERR_NO_MEMORY             = -7,   //!< Insufficient memory
+    ERR_INVALID_ARG           = -8,   //!< Invalid argument
+    ERR_BAD_ADDRESS           = -9,   //!< Bad address
+    ERR_BUSY                  = -10,  //!< Resource is busy
+    ERR_BAD_FORMAT            = -11,  //!< Data format not recognized
+    ERR_NO_TIMER              = -12,  //!< No timer available
+    ERR_TIMER_ALREADY_RUNNING = -13,  //!< Timer already running
+    ERR_TIMER_NOT_RUNNING     = -14,  //!< Timer not running
 
     /**
      * \brief Operation in progress
@@ -148,7 +148,7 @@ enum status_code_wireless {
      * \note Drivers should never return this status code to any
      * callers. It is strictly for internal use.
      */
-    OPERATION_IN_PROGRESS   = -128,
+    OPERATION_IN_PROGRESS = -128,
 };
 
 typedef enum status_code_wireless status_code_t;
index 12444d305968e58814fa156397a048ad82ee0cde..d04e9b7b287700f4005806a740c9fe7c0e5896ec 100644 (file)
@@ -83,7 +83,6 @@ static usb_iface_desc_t UDC_DESC_STORAGE *udc_ptr_iface;
 
 //! @}
 
-
 //! \name Internal structure to store the USB device main strings
 //! @{
 
@@ -91,11 +90,7 @@ static usb_iface_desc_t UDC_DESC_STORAGE *udc_ptr_iface;
  * \brief Language ID of USB device (US ID by default)
  */
 COMPILER_WORD_ALIGNED
-static UDC_DESC_STORAGE usb_str_lgid_desc_t udc_string_desc_languageid = {
-    .desc.bLength = sizeof(usb_str_lgid_desc_t),
-    .desc.bDescriptorType = USB_DT_STRING,
-    .string = {LE16(USB_LANGID_EN_US)}
-};
+static UDC_DESC_STORAGE usb_str_lgid_desc_t udc_string_desc_languageid = {.desc.bLength = sizeof(usb_str_lgid_desc_t), .desc.bDescriptorType = USB_DT_STRING, .string = {LE16(USB_LANGID_EN_US)}};
 
 /**
  * \brief USB device manufacture name storage
@@ -104,9 +99,9 @@ static UDC_DESC_STORAGE usb_str_lgid_desc_t udc_string_desc_languageid = {
  */
 #ifdef USB_DEVICE_MANUFACTURE_NAME
 static uint8_t udc_string_manufacturer_name[] = USB_DEVICE_MANUFACTURE_NAME;
-#define USB_DEVICE_MANUFACTURE_NAME_SIZE (sizeof(udc_string_manufacturer_name)-1)
+#    define USB_DEVICE_MANUFACTURE_NAME_SIZE (sizeof(udc_string_manufacturer_name) - 1)
 #else
-#define USB_DEVICE_MANUFACTURE_NAME_SIZE 0
+#    define USB_DEVICE_MANUFACTURE_NAME_SIZE 0
 #endif
 
 /**
@@ -116,37 +111,34 @@ static uint8_t udc_string_manufacturer_name[] = USB_DEVICE_MANUFACTURE_NAME;
  */
 #ifdef USB_DEVICE_PRODUCT_NAME
 static uint8_t udc_string_product_name[] = USB_DEVICE_PRODUCT_NAME;
-#define USB_DEVICE_PRODUCT_NAME_SIZE (sizeof(udc_string_product_name)-1)
+#    define USB_DEVICE_PRODUCT_NAME_SIZE (sizeof(udc_string_product_name) - 1)
 #else
-#define USB_DEVICE_PRODUCT_NAME_SIZE 0
+#    define USB_DEVICE_PRODUCT_NAME_SIZE 0
 #endif
 
 #if defined USB_DEVICE_SERIAL_NAME
-#define USB_DEVICE_SERIAL_NAME_SIZE (sizeof(USB_DEVICE_SERIAL_NAME)-1)
+#    define USB_DEVICE_SERIAL_NAME_SIZE (sizeof(USB_DEVICE_SERIAL_NAME) - 1)
 #else
-#define USB_DEVICE_SERIAL_NAME_SIZE 0
+#    define USB_DEVICE_SERIAL_NAME_SIZE 0
 #endif
 
-uint8_t usb_device_serial_name_size = 0;
+uint8_t     usb_device_serial_name_size = 0;
 #if defined USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL
-uint8_t bootloader_serial_number[BOOTLOADER_SERIAL_MAX_SIZE+1]="";
+uint8_t     bootloader_serial_number[BOOTLOADER_SERIAL_MAX_SIZE + 1] = "";
 #endif
-static const uint8_t *udc_get_string_serial_name(void)
-{
-#if defined USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL
-    uint32_t serial_ptrloc = (uint32_t)&_srom - 4;
-    uint32_t serial_address = *(uint32_t *)serial_ptrloc; //Address of bootloader's serial number if available
+static const uint8_t *udc_get_string_serial_name(void) {
+#if defined           USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL
+    uint32_t serial_ptrloc  = (uint32_t)&_srom - 4;
+    uint32_t serial_address = *(uint32_t *)serial_ptrloc;  // Address of bootloader's serial number if available
 
-    if (serial_address != 0xFFFFFFFF && serial_address < serial_ptrloc) //Check for factory programmed serial address
+    if (serial_address != 0xFFFFFFFF && serial_address < serial_ptrloc)  // Check for factory programmed serial address
     {
-        if ((serial_address & 0xFF) % 4 == 0) //Check alignment
+        if ((serial_address & 0xFF) % 4 == 0)  // Check alignment
         {
-            uint16_t *serial_use = (uint16_t *)(serial_address); //Point to address of string in rom
-            uint8_t serial_length = 0;
+            uint16_t *serial_use    = (uint16_t *)(serial_address);  // Point to address of string in rom
+            uint8_t   serial_length = 0;
 
-            while ((*(serial_use + serial_length) > 32 && *(serial_use + serial_length) < 127) &&
-                   serial_length < BOOTLOADER_SERIAL_MAX_SIZE)
-            {
+            while ((*(serial_use + serial_length) > 32 && *(serial_use + serial_length) < 127) && serial_length < BOOTLOADER_SERIAL_MAX_SIZE) {
                 bootloader_serial_number[serial_length] = *(serial_use + serial_length) & 0xFF;
                 serial_length++;
             }
@@ -154,7 +146,7 @@ static const uint8_t *udc_get_string_serial_name(void)
 
             usb_device_serial_name_size = serial_length;
 
-            return bootloader_serial_number; //Use serial programmed into bootloader rom
+            return bootloader_serial_number;  // Use serial programmed into bootloader rom
         }
     }
 #endif
@@ -162,9 +154,9 @@ static const uint8_t *udc_get_string_serial_name(void)
     usb_device_serial_name_size = USB_DEVICE_SERIAL_NAME_SIZE;
 
 #if defined USB_DEVICE_SERIAL_NAME
-    return (const uint8_t *)USB_DEVICE_SERIAL_NAME; //Use serial supplied by keyboard's config.h
+    return (const uint8_t *)USB_DEVICE_SERIAL_NAME;  // Use serial supplied by keyboard's config.h
 #else
-    return 0; //No serial supplied
+    return 0;  // No serial supplied
 #endif
 }
 
@@ -173,38 +165,26 @@ static const uint8_t *udc_get_string_serial_name(void)
  * Structure used to transfer ASCII strings to USB String descriptor structure.
  */
 #ifndef BOOTLOADER_SERIAL_MAX_SIZE
-#define BOOTLOADER_SERIAL_MAX_SIZE 0
-#endif //BOOTLOADER_SERIAL_MAX_SIZE
+#    define BOOTLOADER_SERIAL_MAX_SIZE 0
+#endif  // BOOTLOADER_SERIAL_MAX_SIZE
 struct udc_string_desc_t {
     usb_str_desc_t header;
-    le16_t string[Max(Max(Max(USB_DEVICE_MANUFACTURE_NAME_SIZE, \
-                  USB_DEVICE_PRODUCT_NAME_SIZE), USB_DEVICE_SERIAL_NAME_SIZE), \
-                  BOOTLOADER_SERIAL_MAX_SIZE)];
+    le16_t         string[Max(Max(Max(USB_DEVICE_MANUFACTURE_NAME_SIZE, USB_DEVICE_PRODUCT_NAME_SIZE), USB_DEVICE_SERIAL_NAME_SIZE), BOOTLOADER_SERIAL_MAX_SIZE)];
 };
 COMPILER_WORD_ALIGNED
-static UDC_DESC_STORAGE struct udc_string_desc_t udc_string_desc = {
-    .header.bDescriptorType = USB_DT_STRING
-};
+static UDC_DESC_STORAGE struct udc_string_desc_t udc_string_desc = {.header.bDescriptorType = USB_DT_STRING};
 //! @}
 
-usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void)
-{
-    return udc_ptr_iface;
-}
+usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void) { return udc_ptr_iface; }
 
 /**
  * \brief Returns a value to check the end of USB Configuration descriptor
  *
  * \return address after the last byte of USB Configuration descriptor
  */
-static usb_conf_desc_t UDC_DESC_STORAGE *udc_get_eof_conf(void)
-{
-    return (UDC_DESC_STORAGE usb_conf_desc_t *) ((uint8_t *)
-            udc_ptr_conf->desc +
-            le16_to_cpu(udc_ptr_conf->desc->wTotalLength));
-}
+static usb_conf_desc_t UDC_DESC_STORAGE *udc_get_eof_conf(void) { return (UDC_DESC_STORAGE usb_conf_desc_t *)((uint8_t *)udc_ptr_conf->desc + le16_to_cpu(udc_ptr_conf->desc->wTotalLength)); }
 
-#if (0!=USB_DEVICE_MAX_EP)
+#if (0 != USB_DEVICE_MAX_EP)
 /**
  * \brief Search specific descriptor in global interface descriptor
  *
@@ -215,30 +195,26 @@ static usb_conf_desc_t UDC_DESC_STORAGE *udc_get_eof_conf(void)
  * \return address of specific descriptor found
  * \return NULL if it is the end of global interface descriptor
  */
-static usb_conf_desc_t UDC_DESC_STORAGE *udc_next_desc_in_iface(usb_conf_desc_t
-        UDC_DESC_STORAGE * desc, uint8_t desc_id)
-{
+static usb_conf_desc_t UDC_DESC_STORAGE *udc_next_desc_in_iface(usb_conf_desc_t UDC_DESC_STORAGE *desc, uint8_t desc_id) {
     usb_conf_desc_t UDC_DESC_STORAGE *ptr_eof_desc;
 
     ptr_eof_desc = udc_get_eof_conf();
     // Go to next descriptor
-    desc = (UDC_DESC_STORAGE usb_conf_desc_t *) ((uint8_t *) desc +
-            desc->bLength);
+    desc = (UDC_DESC_STORAGE usb_conf_desc_t *)((uint8_t *)desc + desc->bLength);
     // Check the end of configuration descriptor
     while (ptr_eof_desc > desc) {
         // If new interface descriptor is found,
         // then it is the end of the current global interface descriptor
         if (USB_DT_INTERFACE == desc->bDescriptorType) {
-            break; // End of global interface descriptor
+            break;  // End of global interface descriptor
         }
         if (desc_id == desc->bDescriptorType) {
-            return desc; // Specific descriptor found
+            return desc;  // Specific descriptor found
         }
         // Go to next descriptor
-        desc = (UDC_DESC_STORAGE usb_conf_desc_t *) ((uint8_t *) desc +
-                desc->bLength);
+        desc = (UDC_DESC_STORAGE usb_conf_desc_t *)((uint8_t *)desc + desc->bLength);
     }
-    return NULL; // No specific descriptor found
+    return NULL;  // No specific descriptor found
 }
 #endif
 
@@ -251,8 +227,7 @@ static usb_conf_desc_t UDC_DESC_STORAGE *udc_next_desc_in_iface(usb_conf_desc_t
  *
  * \return 1 if found or 0 if not found
  */
-static bool udc_update_iface_desc(uint8_t iface_num, uint8_t setting_num)
-{
+static bool udc_update_iface_desc(uint8_t iface_num, uint8_t setting_num) {
     usb_conf_desc_t UDC_DESC_STORAGE *ptr_end_desc;
 
     if (0 == udc_num_configuration) {
@@ -264,28 +239,22 @@ static bool udc_update_iface_desc(uint8_t iface_num, uint8_t setting_num)
     }
 
     // Start at the beginning of configuration descriptor
-    udc_ptr_iface = (UDC_DESC_STORAGE usb_iface_desc_t *)
-            udc_ptr_conf->desc;
+    udc_ptr_iface = (UDC_DESC_STORAGE usb_iface_desc_t *)udc_ptr_conf->desc;
 
     // Check the end of configuration descriptor
     ptr_end_desc = udc_get_eof_conf();
-    while (ptr_end_desc >
-            (UDC_DESC_STORAGE usb_conf_desc_t *) udc_ptr_iface) {
+    while (ptr_end_desc > (UDC_DESC_STORAGE usb_conf_desc_t *)udc_ptr_iface) {
         if (USB_DT_INTERFACE == udc_ptr_iface->bDescriptorType) {
             // A interface descriptor is found
             // Check interface and alternate setting number
-            if ((iface_num == udc_ptr_iface->bInterfaceNumber) &&
-                    (setting_num ==
-                    udc_ptr_iface->bAlternateSetting)) {
-                return true; // Interface found
+            if ((iface_num == udc_ptr_iface->bInterfaceNumber) && (setting_num == udc_ptr_iface->bAlternateSetting)) {
+                return true;  // Interface found
             }
         }
         // Go to next descriptor
-        udc_ptr_iface = (UDC_DESC_STORAGE usb_iface_desc_t *) (
-                (uint8_t *) udc_ptr_iface +
-                udc_ptr_iface->bLength);
+        udc_ptr_iface = (UDC_DESC_STORAGE usb_iface_desc_t *)((uint8_t *)udc_ptr_iface + udc_ptr_iface->bLength);
     }
-    return false; // Interface not found
+    return false;  // Interface not found
 }
 
 /**
@@ -296,8 +265,7 @@ static bool udc_update_iface_desc(uint8_t iface_num, uint8_t setting_num)
  *
  * \return 1 if it is done or 0 if interface is not found
  */
-static bool udc_iface_disable(uint8_t iface_num)
-{
+static bool udc_iface_disable(uint8_t iface_num) {
     udi_api_t UDC_DESC_STORAGE *udi_api;
 
     // Select first alternate setting of the interface
@@ -309,7 +277,7 @@ static bool udc_iface_disable(uint8_t iface_num)
     // Select the interface with the current alternate setting
     udi_api = udc_ptr_conf->udi_apis[iface_num];
 
-#if (0!=USB_DEVICE_MAX_EP)
+#if (0 != USB_DEVICE_MAX_EP)
     if (!udc_update_iface_desc(iface_num, udi_api->getsetting())) {
         return false;
     }
@@ -317,13 +285,10 @@ static bool udc_iface_disable(uint8_t iface_num)
     // Start at the beginning of interface descriptor
     {
         usb_ep_desc_t UDC_DESC_STORAGE *ep_desc;
-        ep_desc = (UDC_DESC_STORAGE usb_ep_desc_t *) udc_ptr_iface;
+        ep_desc = (UDC_DESC_STORAGE usb_ep_desc_t *)udc_ptr_iface;
         while (1) {
             // Search Endpoint descriptor included in global interface descriptor
-            ep_desc = (UDC_DESC_STORAGE usb_ep_desc_t *)
-                    udc_next_desc_in_iface((UDC_DESC_STORAGE
-                    usb_conf_desc_t *)
-                    ep_desc, USB_DT_ENDPOINT);
+            ep_desc = (UDC_DESC_STORAGE usb_ep_desc_t *)udc_next_desc_in_iface((UDC_DESC_STORAGE usb_conf_desc_t *)ep_desc, USB_DT_ENDPOINT);
             if (NULL == ep_desc) {
                 break;
             }
@@ -348,31 +313,23 @@ static bool udc_iface_disable(uint8_t iface_num)
  *
  * \return 1 if it is done or 0 if interface is not found
  */
-static bool udc_iface_enable(uint8_t iface_num, uint8_t setting_num)
-{
+static bool udc_iface_enable(uint8_t iface_num, uint8_t setting_num) {
     // Select the interface descriptor
     if (!udc_update_iface_desc(iface_num, setting_num)) {
         return false;
     }
 
-#if (0!=USB_DEVICE_MAX_EP)
+#if (0 != USB_DEVICE_MAX_EP)
     usb_ep_desc_t UDC_DESC_STORAGE *ep_desc;
 
     // Start at the beginning of the global interface descriptor
-    ep_desc = (UDC_DESC_STORAGE usb_ep_desc_t *) udc_ptr_iface;
+    ep_desc = (UDC_DESC_STORAGE usb_ep_desc_t *)udc_ptr_iface;
     while (1) {
         // Search Endpoint descriptor included in the global interface descriptor
-        ep_desc = (UDC_DESC_STORAGE usb_ep_desc_t *)
-                udc_next_desc_in_iface((UDC_DESC_STORAGE
-                        usb_conf_desc_t *) ep_desc,
-                USB_DT_ENDPOINT);
-        if (NULL == ep_desc)
-            break;
+        ep_desc = (UDC_DESC_STORAGE usb_ep_desc_t *)udc_next_desc_in_iface((UDC_DESC_STORAGE usb_conf_desc_t *)ep_desc, USB_DT_ENDPOINT);
+        if (NULL == ep_desc) break;
         // Alloc the endpoint used by the interface
-        if (!udd_ep_alloc(ep_desc->bEndpointAddress,
-                ep_desc->bmAttributes,
-                le16_to_cpu
-                (ep_desc->wMaxPacketSize))) {
+        if (!udd_ep_alloc(ep_desc->bEndpointAddress, ep_desc->bmAttributes, le16_to_cpu(ep_desc->wMaxPacketSize))) {
             return false;
         }
     }
@@ -383,15 +340,11 @@ static bool udc_iface_enable(uint8_t iface_num, uint8_t setting_num)
 
 /*! \brief Start the USB Device stack
  */
-void udc_start(void)
-{
-    udd_enable();
-}
+void udc_start(void) { udd_enable(); }
 
 /*! \brief Stop the USB Device stack
  */
-void udc_stop(void)
-{
+void udc_stop(void) {
     udd_disable();
     udc_reset();
 }
@@ -400,20 +353,16 @@ void udc_stop(void)
  * \brief Reset the current configuration of the USB device,
  * This routines can be called by UDD when a RESET on the USB line occurs.
  */
-void udc_reset(void)
-{
+void udc_reset(void) {
     uint8_t iface_num;
 
     if (udc_num_configuration) {
-        for (iface_num = 0;
-                iface_num < udc_ptr_conf->desc->bNumInterfaces;
-                iface_num++) {
+        for (iface_num = 0; iface_num < udc_ptr_conf->desc->bNumInterfaces; iface_num++) {
             udc_iface_disable(iface_num);
         }
     }
     udc_num_configuration = 0;
-#if (USB_CONFIG_ATTR_REMOTE_WAKEUP \
-    == (USB_DEVICE_ATTR & USB_CONFIG_ATTR_REMOTE_WAKEUP))
+#if (USB_CONFIG_ATTR_REMOTE_WAKEUP == (USB_DEVICE_ATTR & USB_CONFIG_ATTR_REMOTE_WAKEUP))
     if (CPU_TO_LE16(USB_DEV_STATUS_REMOTEWAKEUP) & udc_device_status) {
         // Remote wakeup is enabled then disable it
         UDC_REMOTEWAKEUP_DISABLE();
@@ -421,20 +370,17 @@ void udc_reset(void)
 #endif
     udc_device_status =
 #if (USB_DEVICE_ATTR & USB_CONFIG_ATTR_SELF_POWERED)
-            CPU_TO_LE16(USB_DEV_STATUS_SELF_POWERED);
+        CPU_TO_LE16(USB_DEV_STATUS_SELF_POWERED);
 #else
-            CPU_TO_LE16(USB_DEV_STATUS_BUS_POWERED);
+        CPU_TO_LE16(USB_DEV_STATUS_BUS_POWERED);
 #endif
 }
 
-void udc_sof_notify(void)
-{
+void udc_sof_notify(void) {
     uint8_t iface_num;
 
     if (udc_num_configuration) {
-        for (iface_num = 0;
-                iface_num < udc_ptr_conf->desc->bNumInterfaces;
-                iface_num++) {
+        for (iface_num = 0; iface_num < udc_ptr_conf->desc->bNumInterfaces; iface_num++) {
             if (udc_ptr_conf->udi_apis[iface_num]->sof_notify != NULL) {
                 udc_ptr_conf->udi_apis[iface_num]->sof_notify();
             }
@@ -447,36 +393,31 @@ void udc_sof_notify(void)
  *
  * \return true if success
  */
-static bool udc_req_std_dev_get_status(void)
-{
+static bool udc_req_std_dev_get_status(void) {
     if (udd_g_ctrlreq.req.wLength != sizeof(udc_device_status)) {
         return false;
     }
 
-    udd_set_setup_payload( (uint8_t *) & udc_device_status,
-            sizeof(udc_device_status));
+    udd_set_setup_payload((uint8_t *)&udc_device_status, sizeof(udc_device_status));
     return true;
 }
 
-#if (0!=USB_DEVICE_MAX_EP)
+#if (0 != USB_DEVICE_MAX_EP)
 /**
  * \brief Standard endpoint request to get endpoint status
  *
  * \return true if success
  */
-static bool udc_req_std_ep_get_status(void)
-{
+static bool udc_req_std_ep_get_status(void) {
     static le16_t udc_ep_status;
 
     if (udd_g_ctrlreq.req.wLength != sizeof(udc_ep_status)) {
         return false;
     }
 
-    udc_ep_status = udd_ep_is_halted(udd_g_ctrlreq.req.
-            wIndex & 0xFF) ? CPU_TO_LE16(USB_EP_STATUS_HALTED) : 0;
+    udc_ep_status = udd_ep_is_halted(udd_g_ctrlreq.req.wIndex & 0xFF) ? CPU_TO_LE16(USB_EP_STATUS_HALTED) : 0;
 
-    udd_set_setup_payload( (uint8_t *) & udc_ep_status,
-            sizeof(udc_ep_status));
+    udd_set_setup_payload((uint8_t *)&udc_ep_status, sizeof(udc_ep_status));
     return true;
 }
 #endif
@@ -486,16 +427,14 @@ static bool udc_req_std_ep_get_status(void)
  *
  * \return true if success
  */
-static bool udc_req_std_dev_clear_feature(void)
-{
+static bool udc_req_std_dev_clear_feature(void) {
     if (udd_g_ctrlreq.req.wLength) {
         return false;
     }
 
     if (udd_g_ctrlreq.req.wValue == USB_DEV_FEATURE_REMOTE_WAKEUP) {
         udc_device_status &= CPU_TO_LE16(~(uint32_t)USB_DEV_STATUS_REMOTEWAKEUP);
-#if (USB_CONFIG_ATTR_REMOTE_WAKEUP \
-    == (USB_DEVICE_ATTR & USB_CONFIG_ATTR_REMOTE_WAKEUP))
+#if (USB_CONFIG_ATTR_REMOTE_WAKEUP == (USB_DEVICE_ATTR & USB_CONFIG_ATTR_REMOTE_WAKEUP))
         UDC_REMOTEWAKEUP_DISABLE();
 #endif
         return true;
@@ -503,14 +442,13 @@ static bool udc_req_std_dev_clear_feature(void)
     return false;
 }
 
-#if (0!=USB_DEVICE_MAX_EP)
+#if (0 != USB_DEVICE_MAX_EP)
 /**
  * \brief Standard endpoint request to clear endpoint feature
  *
  * \return true if success
  */
-static bool udc_req_std_ep_clear_feature(void)
-{
+static bool udc_req_std_ep_clear_feature(void) {
     if (udd_g_ctrlreq.req.wLength) {
         return false;
     }
@@ -527,59 +465,56 @@ static bool udc_req_std_ep_clear_feature(void)
  *
  * \return true if success
  */
-static bool udc_req_std_dev_set_feature(void)
-{
+static bool udc_req_std_dev_set_feature(void) {
     if (udd_g_ctrlreq.req.wLength) {
         return false;
     }
 
     switch (udd_g_ctrlreq.req.wValue) {
-
-    case USB_DEV_FEATURE_REMOTE_WAKEUP:
-#if (USB_CONFIG_ATTR_REMOTE_WAKEUP \
-    == (USB_DEVICE_ATTR & USB_CONFIG_ATTR_REMOTE_WAKEUP))
-        udc_device_status |= CPU_TO_LE16(USB_DEV_STATUS_REMOTEWAKEUP);
-        UDC_REMOTEWAKEUP_ENABLE();
-        return true;
+        case USB_DEV_FEATURE_REMOTE_WAKEUP:
+#if (USB_CONFIG_ATTR_REMOTE_WAKEUP == (USB_DEVICE_ATTR & USB_CONFIG_ATTR_REMOTE_WAKEUP))
+            udc_device_status |= CPU_TO_LE16(USB_DEV_STATUS_REMOTEWAKEUP);
+            UDC_REMOTEWAKEUP_ENABLE();
+            return true;
 #else
-        return false;
+            return false;
 #endif
 
 #ifdef USB_DEVICE_HS_SUPPORT
-    case USB_DEV_FEATURE_TEST_MODE:
-        if (!udd_is_high_speed()) {
-            break;
-        }
-        if (udd_g_ctrlreq.req.wIndex & 0xff) {
+        case USB_DEV_FEATURE_TEST_MODE:
+            if (!udd_is_high_speed()) {
+                break;
+            }
+            if (udd_g_ctrlreq.req.wIndex & 0xff) {
+                break;
+            }
+            // Unconfigure the device, terminating all ongoing requests
+            udc_reset();
+            switch ((udd_g_ctrlreq.req.wIndex >> 8) & 0xFF) {
+                case USB_DEV_TEST_MODE_J:
+                    udd_g_ctrlreq.callback = udd_test_mode_j;
+                    return true;
+
+                case USB_DEV_TEST_MODE_K:
+                    udd_g_ctrlreq.callback = udd_test_mode_k;
+                    return true;
+
+                case USB_DEV_TEST_MODE_SE0_NAK:
+                    udd_g_ctrlreq.callback = udd_test_mode_se0_nak;
+                    return true;
+
+                case USB_DEV_TEST_MODE_PACKET:
+                    udd_g_ctrlreq.callback = udd_test_mode_packet;
+                    return true;
+
+                case USB_DEV_TEST_MODE_FORCE_ENABLE:  // Only for downstream facing hub ports
+                default:
+                    break;
+            }
             break;
-        }
-        // Unconfigure the device, terminating all ongoing requests
-        udc_reset();
-        switch ((udd_g_ctrlreq.req.wIndex >> 8) & 0xFF) {
-        case USB_DEV_TEST_MODE_J:
-            udd_g_ctrlreq.callback = udd_test_mode_j;
-            return true;
-
-        case USB_DEV_TEST_MODE_K:
-            udd_g_ctrlreq.callback = udd_test_mode_k;
-            return true;
-
-        case USB_DEV_TEST_MODE_SE0_NAK:
-            udd_g_ctrlreq.callback = udd_test_mode_se0_nak;
-            return true;
-
-        case USB_DEV_TEST_MODE_PACKET:
-            udd_g_ctrlreq.callback = udd_test_mode_packet;
-            return true;
-
-        case USB_DEV_TEST_MODE_FORCE_ENABLE: // Only for downstream facing hub ports
+#endif
         default:
             break;
-        }
-        break;
-#endif
-    default:
-        break;
     }
     return false;
 }
@@ -589,9 +524,8 @@ static bool udc_req_std_dev_set_feature(void)
  *
  * \return true if success
  */
-#if (0!=USB_DEVICE_MAX_EP)
-static bool udc_req_std_ep_set_feature(void)
-{
+#if (0 != USB_DEVICE_MAX_EP)
+static bool udc_req_std_ep_set_feature(void) {
     if (udd_g_ctrlreq.req.wLength) {
         return false;
     }
@@ -607,18 +541,14 @@ static bool udc_req_std_ep_set_feature(void)
  * \brief Change the address of device
  * Callback called at the end of request set address
  */
-static void udc_valid_address(void)
-{
-    udd_set_address(udd_g_ctrlreq.req.wValue & 0x7F);
-}
+static void udc_valid_address(void) { udd_set_address(udd_g_ctrlreq.req.wValue & 0x7F); }
 
 /**
  * \brief Standard device request to set device address
  *
  * \return true if success
  */
-static bool udc_req_std_dev_set_address(void)
-{
+static bool udc_req_std_dev_set_address(void) {
     if (udd_g_ctrlreq.req.wLength) {
         return false;
     }
@@ -634,53 +564,49 @@ static bool udc_req_std_dev_set_address(void)
  *
  * \return true if success
  */
-static bool udc_req_std_dev_get_str_desc(void)
-{
-    uint8_t i;
+static bool udc_req_std_dev_get_str_desc(void) {
+    uint8_t        i;
     const uint8_t *str;
-    uint8_t str_length = 0;
+    uint8_t        str_length = 0;
 
     // Link payload pointer to the string corresponding at request
     switch (udd_g_ctrlreq.req.wValue & 0xff) {
-    case 0:
-        udd_set_setup_payload((uint8_t *) &udc_string_desc_languageid,
-                sizeof(udc_string_desc_languageid));
-        break;
+        case 0:
+            udd_set_setup_payload((uint8_t *)&udc_string_desc_languageid, sizeof(udc_string_desc_languageid));
+            break;
 
 #ifdef USB_DEVICE_MANUFACTURE_NAME
-    case 1:
-        str_length = USB_DEVICE_MANUFACTURE_NAME_SIZE;
-        str = udc_string_manufacturer_name;
-        break;
+        case 1:
+            str_length = USB_DEVICE_MANUFACTURE_NAME_SIZE;
+            str        = udc_string_manufacturer_name;
+            break;
 #endif
 #ifdef USB_DEVICE_PRODUCT_NAME
-    case 2:
-        str_length = USB_DEVICE_PRODUCT_NAME_SIZE;
-        str = udc_string_product_name;
-        break;
+        case 2:
+            str_length = USB_DEVICE_PRODUCT_NAME_SIZE;
+            str        = udc_string_product_name;
+            break;
 #endif
-    case 3:
-        str = udc_get_string_serial_name();
-        str_length = usb_device_serial_name_size;
-        break;
-    default:
-#ifdef UDC_GET_EXTRA_STRING
-        if (UDC_GET_EXTRA_STRING()) {
+        case 3:
+            str        = udc_get_string_serial_name();
+            str_length = usb_device_serial_name_size;
             break;
-        }
+        default:
+#ifdef UDC_GET_EXTRA_STRING
+            if (UDC_GET_EXTRA_STRING()) {
+                break;
+            }
 #endif
-        return false;
+            return false;
     }
 
     if (str_length) {
-        for(i = 0; i < str_length; i++) {
+        for (i = 0; i < str_length; i++) {
             udc_string_desc.string[i] = cpu_to_le16((le16_t)str[i]);
         }
 
-        udc_string_desc.header.bLength = 2 + (str_length) * 2;
-        udd_set_setup_payload(
-            (uint8_t *) &udc_string_desc,
-            udc_string_desc.header.bLength);
+        udc_string_desc.header.bLength = 2 + (str_length)*2;
+        udd_set_setup_payload((uint8_t *)&udc_string_desc, udc_string_desc.header.bLength);
     }
 
     return true;
@@ -691,106 +617,89 @@ static bool udc_req_std_dev_get_str_desc(void)
  *
  * \return true if success
  */
-static bool udc_req_std_dev_get_descriptor(void)
-{
+static bool udc_req_std_dev_get_descriptor(void) {
     uint8_t conf_num;
 
     conf_num = udd_g_ctrlreq.req.wValue & 0xff;
 
     // Check descriptor ID
-    switch ((uint8_t) (udd_g_ctrlreq.req.wValue >> 8)) {
-    case USB_DT_DEVICE:
-        // Device descriptor requested
+    switch ((uint8_t)(udd_g_ctrlreq.req.wValue >> 8)) {
+        case USB_DT_DEVICE:
+            // Device descriptor requested
 #ifdef USB_DEVICE_HS_SUPPORT
-        if (!udd_is_high_speed()) {
-            udd_set_setup_payload(
-                (uint8_t *) udc_config.confdev_hs,
-                udc_config.confdev_hs->bLength);
-        } else
+            if (!udd_is_high_speed()) {
+                udd_set_setup_payload((uint8_t *)udc_config.confdev_hs, udc_config.confdev_hs->bLength);
+            } else
 #endif
-        {
-            udd_set_setup_payload(
-                (uint8_t *) udc_config.confdev_lsfs,
-                udc_config.confdev_lsfs->bLength);
-        }
-        break;
+            {
+                udd_set_setup_payload((uint8_t *)udc_config.confdev_lsfs, udc_config.confdev_lsfs->bLength);
+            }
+            break;
 
-    case USB_DT_CONFIGURATION:
-        // Configuration descriptor requested
+        case USB_DT_CONFIGURATION:
+            // Configuration descriptor requested
 #ifdef USB_DEVICE_HS_SUPPORT
-        if (udd_is_high_speed()) {
-            // HS descriptor
-            if (conf_num >= udc_config.confdev_hs->bNumConfigurations) {
-                return false;
-            }
-            udd_set_setup_payload(
-                (uint8_t *)udc_config.conf_hs[conf_num].desc,
-                le16_to_cpu(udc_config.conf_hs[conf_num].desc->wTotalLength));
-        } else
+            if (udd_is_high_speed()) {
+                // HS descriptor
+                if (conf_num >= udc_config.confdev_hs->bNumConfigurations) {
+                    return false;
+                }
+                udd_set_setup_payload((uint8_t *)udc_config.conf_hs[conf_num].desc, le16_to_cpu(udc_config.conf_hs[conf_num].desc->wTotalLength));
+            } else
 #endif
-        {
-            // FS descriptor
-            if (conf_num >= udc_config.confdev_lsfs->bNumConfigurations) {
-                return false;
+            {
+                // FS descriptor
+                if (conf_num >= udc_config.confdev_lsfs->bNumConfigurations) {
+                    return false;
+                }
+                udd_set_setup_payload((uint8_t *)udc_config.conf_lsfs[conf_num].desc, le16_to_cpu(udc_config.conf_lsfs[conf_num].desc->wTotalLength));
             }
-            udd_set_setup_payload(
-                (uint8_t *)udc_config.conf_lsfs[conf_num].desc,
-                le16_to_cpu(udc_config.conf_lsfs[conf_num].desc->wTotalLength));
-        }
-        ((usb_conf_desc_t *) udd_g_ctrlreq.payload)->bDescriptorType =
-                USB_DT_CONFIGURATION;
-        break;
+            ((usb_conf_desc_t *)udd_g_ctrlreq.payload)->bDescriptorType = USB_DT_CONFIGURATION;
+            break;
 
 #ifdef USB_DEVICE_HS_SUPPORT
-    case USB_DT_DEVICE_QUALIFIER:
-        // Device qualifier descriptor requested
-        udd_set_setup_payload( (uint8_t *) udc_config.qualifier,
-                udc_config.qualifier->bLength);
-        break;
-
-    case USB_DT_OTHER_SPEED_CONFIGURATION:
-        // Other configuration descriptor requested
-        if (!udd_is_high_speed()) {
-            // HS descriptor
-            if (conf_num >= udc_config.confdev_hs->bNumConfigurations) {
-                return false;
+        case USB_DT_DEVICE_QUALIFIER:
+            // Device qualifier descriptor requested
+            udd_set_setup_payload((uint8_t *)udc_config.qualifier, udc_config.qualifier->bLength);
+            break;
+
+        case USB_DT_OTHER_SPEED_CONFIGURATION:
+            // Other configuration descriptor requested
+            if (!udd_is_high_speed()) {
+                // HS descriptor
+                if (conf_num >= udc_config.confdev_hs->bNumConfigurations) {
+                    return false;
+                }
+                udd_set_setup_payload((uint8_t *)udc_config.conf_hs[conf_num].desc, le16_to_cpu(udc_config.conf_hs[conf_num].desc->wTotalLength));
+            } else {
+                // FS descriptor
+                if (conf_num >= udc_config.confdev_lsfs->bNumConfigurations) {
+                    return false;
+                }
+                udd_set_setup_payload((uint8_t *)udc_config.conf_lsfs[conf_num].desc, le16_to_cpu(udc_config.conf_lsfs[conf_num].desc->wTotalLength));
             }
-            udd_set_setup_payload(
-                (uint8_t *)udc_config.conf_hs[conf_num].desc,
-                le16_to_cpu(udc_config.conf_hs[conf_num].desc->wTotalLength));
-        } else {
-            // FS descriptor
-            if (conf_num >= udc_config.confdev_lsfs->bNumConfigurations) {
+            ((usb_conf_desc_t *)udd_g_ctrlreq.payload)->bDescriptorType = USB_DT_OTHER_SPEED_CONFIGURATION;
+            break;
+#endif
+
+        case USB_DT_BOS:
+            // Device BOS descriptor requested
+            if (udc_config.conf_bos == NULL) {
                 return false;
             }
-            udd_set_setup_payload(
-                (uint8_t *)udc_config.conf_lsfs[conf_num].desc,
-                le16_to_cpu(udc_config.conf_lsfs[conf_num].desc->wTotalLength));
-        }
-        ((usb_conf_desc_t *) udd_g_ctrlreq.payload)->bDescriptorType =
-                USB_DT_OTHER_SPEED_CONFIGURATION;
-        break;
-#endif
+            udd_set_setup_payload((uint8_t *)udc_config.conf_bos, udc_config.conf_bos->wTotalLength);
+            break;
 
-    case USB_DT_BOS:
-        // Device BOS descriptor requested
-        if (udc_config.conf_bos == NULL) {
-            return false;
-        }
-        udd_set_setup_payload( (uint8_t *) udc_config.conf_bos,
-                udc_config.conf_bos->wTotalLength);
-        break;
+        case USB_DT_STRING:
+            // String descriptor requested
+            if (!udc_req_std_dev_get_str_desc()) {
+                return false;
+            }
+            break;
 
-    case USB_DT_STRING:
-        // String descriptor requested
-        if (!udc_req_std_dev_get_str_desc()) {
+        default:
+            // Unknown descriptor requested
             return false;
-        }
-        break;
-
-    default:
-        // Unknown descriptor requested
-        return false;
     }
     // if the descriptor is larger than length requested, then reduce it
     if (udd_g_ctrlreq.req.wLength < udd_g_ctrlreq.payload_size) {
@@ -804,13 +713,12 @@ static bool udc_req_std_dev_get_descriptor(void)
  *
  * \return true if success
  */
-static bool udc_req_std_dev_get_configuration(void)
-{
+static bool udc_req_std_dev_get_configuration(void) {
     if (udd_g_ctrlreq.req.wLength != 1) {
         return false;
     }
 
-    udd_set_setup_payload(&udc_num_configuration,1);
+    udd_set_setup_payload(&udc_num_configuration, 1);
     return true;
 }
 
@@ -819,8 +727,7 @@ static bool udc_req_std_dev_get_configuration(void)
  *
  * \return true if success
  */
-static bool udc_req_std_dev_set_configuration(void)
-{
+static bool udc_req_std_dev_set_configuration(void) {
     uint8_t iface_num;
 
     // Check request length
@@ -835,16 +742,14 @@ static bool udc_req_std_dev_set_configuration(void)
 #ifdef USB_DEVICE_HS_SUPPORT
     if (udd_is_high_speed()) {
         // HS descriptor
-        if ((udd_g_ctrlreq.req.wValue & 0xFF) >
-                udc_config.confdev_hs->bNumConfigurations) {
+        if ((udd_g_ctrlreq.req.wValue & 0xFF) > udc_config.confdev_hs->bNumConfigurations) {
             return false;
         }
     } else
 #endif
     {
         // FS descriptor
-        if ((udd_g_ctrlreq.req.wValue & 0xFF) >
-                udc_config.confdev_lsfs->bNumConfigurations) {
+        if ((udd_g_ctrlreq.req.wValue & 0xFF) > udc_config.confdev_lsfs->bNumConfigurations) {
             return false;
         }
     }
@@ -855,7 +760,7 @@ static bool udc_req_std_dev_set_configuration(void)
     // Enable new configuration
     udc_num_configuration = udd_g_ctrlreq.req.wValue & 0xFF;
     if (udc_num_configuration == 0) {
-        return true; // Default empty configuration requested
+        return true;  // Default empty configuration requested
     }
     // Update pointer of the configuration descriptor
 #ifdef USB_DEVICE_HS_SUPPORT
@@ -869,8 +774,7 @@ static bool udc_req_std_dev_set_configuration(void)
         udc_ptr_conf = &udc_config.conf_lsfs[udc_num_configuration - 1];
     }
     // Enable all interfaces of the selected configuration
-    for (iface_num = 0; iface_num < udc_ptr_conf->desc->bNumInterfaces;
-            iface_num++) {
+    for (iface_num = 0; iface_num < udc_ptr_conf->desc->bNumInterfaces; iface_num++) {
         if (!udc_iface_enable(iface_num, 0)) {
             return false;
         }
@@ -884,16 +788,15 @@ static bool udc_req_std_dev_set_configuration(void)
  *
  * \return true if success
  */
-static bool udc_req_std_iface_get_setting(void)
-{
-    uint8_t iface_num;
+static bool udc_req_std_iface_get_setting(void) {
+    uint8_t   iface_num;
     udi_api_t UDC_DESC_STORAGE *udi_api;
 
     if (udd_g_ctrlreq.req.wLength != 1) {
-        return false; // Error in request
+        return false;  // Error in request
     }
     if (!udc_num_configuration) {
-        return false; // The device is not is configured state yet
+        return false;  // The device is not is configured state yet
     }
 
     // Check the interface number included in the request
@@ -908,11 +811,11 @@ static bool udc_req_std_iface_get_setting(void)
         return false;
     }
     // Get alternate setting from UDI
-    udi_api = udc_ptr_conf->udi_apis[iface_num];
+    udi_api           = udc_ptr_conf->udi_apis[iface_num];
     udc_iface_setting = udi_api->getsetting();
 
     // Link value to payload pointer of request
-    udd_set_setup_payload(&udc_iface_setting,1);
+    udd_set_setup_payload(&udc_iface_setting, 1);
     return true;
 }
 
@@ -922,18 +825,17 @@ static bool udc_req_std_iface_get_setting(void)
  *
  * \return true if success
  */
-static bool udc_req_std_iface_set_setting(void)
-{
+static bool udc_req_std_iface_set_setting(void) {
     uint8_t iface_num, setting_num;
 
     if (udd_g_ctrlreq.req.wLength) {
-        return false; // Error in request
+        return false;  // Error in request
     }
     if (!udc_num_configuration) {
-        return false; // The device is not is configured state yet
+        return false;  // The device is not is configured state yet
     }
 
-    iface_num = udd_g_ctrlreq.req.wIndex & 0xFF;
+    iface_num   = udd_g_ctrlreq.req.wIndex & 0xFF;
     setting_num = udd_g_ctrlreq.req.wValue & 0xFF;
 
     // Disable current setting
@@ -950,45 +852,44 @@ static bool udc_req_std_iface_set_setting(void)
  *
  * \return true if the request is supported
  */
-static bool udc_reqstd(void)
-{
+static bool udc_reqstd(void) {
     if (Udd_setup_is_in()) {
         // GET Standard Requests
         if (udd_g_ctrlreq.req.wLength == 0) {
-            return false; // Error for USB host
+            return false;  // Error for USB host
         }
 
         if (USB_REQ_RECIP_DEVICE == Udd_setup_recipient()) {
             // Standard Get Device request
             switch (udd_g_ctrlreq.req.bRequest) {
-            case USB_REQ_GET_STATUS:
-                return udc_req_std_dev_get_status();
-            case USB_REQ_GET_DESCRIPTOR:
-                return udc_req_std_dev_get_descriptor();
-            case USB_REQ_GET_CONFIGURATION:
-                return udc_req_std_dev_get_configuration();
-            default:
-                break;
+                case USB_REQ_GET_STATUS:
+                    return udc_req_std_dev_get_status();
+                case USB_REQ_GET_DESCRIPTOR:
+                    return udc_req_std_dev_get_descriptor();
+                case USB_REQ_GET_CONFIGURATION:
+                    return udc_req_std_dev_get_configuration();
+                default:
+                    break;
             }
         }
 
         if (USB_REQ_RECIP_INTERFACE == Udd_setup_recipient()) {
             // Standard Get Interface request
             switch (udd_g_ctrlreq.req.bRequest) {
-            case USB_REQ_GET_INTERFACE:
-                return udc_req_std_iface_get_setting();
-            default:
-                break;
+                case USB_REQ_GET_INTERFACE:
+                    return udc_req_std_iface_get_setting();
+                default:
+                    break;
             }
         }
-#if (0!=USB_DEVICE_MAX_EP)
+#if (0 != USB_DEVICE_MAX_EP)
         if (USB_REQ_RECIP_ENDPOINT == Udd_setup_recipient()) {
             // Standard Get Endpoint request
             switch (udd_g_ctrlreq.req.bRequest) {
-            case USB_REQ_GET_STATUS:
-                return udc_req_std_ep_get_status();
-            default:
-                break;
+                case USB_REQ_GET_STATUS:
+                    return udc_req_std_ep_get_status();
+                default:
+                    break;
             }
         }
 #endif
@@ -997,41 +898,41 @@ static bool udc_reqstd(void)
         if (USB_REQ_RECIP_DEVICE == Udd_setup_recipient()) {
             // Standard Set Device request
             switch (udd_g_ctrlreq.req.bRequest) {
-            case USB_REQ_SET_ADDRESS:
-                return udc_req_std_dev_set_address();
-            case USB_REQ_CLEAR_FEATURE:
-                return udc_req_std_dev_clear_feature();
-            case USB_REQ_SET_FEATURE:
-                return udc_req_std_dev_set_feature();
-            case USB_REQ_SET_CONFIGURATION:
-                return udc_req_std_dev_set_configuration();
-            case USB_REQ_SET_DESCRIPTOR:
-                /* Not supported (defined as optional by the USB 2.0 spec) */
-                break;
-            default:
-                break;
+                case USB_REQ_SET_ADDRESS:
+                    return udc_req_std_dev_set_address();
+                case USB_REQ_CLEAR_FEATURE:
+                    return udc_req_std_dev_clear_feature();
+                case USB_REQ_SET_FEATURE:
+                    return udc_req_std_dev_set_feature();
+                case USB_REQ_SET_CONFIGURATION:
+                    return udc_req_std_dev_set_configuration();
+                case USB_REQ_SET_DESCRIPTOR:
+                    /* Not supported (defined as optional by the USB 2.0 spec) */
+                    break;
+                default:
+                    break;
             }
         }
 
         if (USB_REQ_RECIP_INTERFACE == Udd_setup_recipient()) {
             // Standard Set Interface request
             switch (udd_g_ctrlreq.req.bRequest) {
-            case USB_REQ_SET_INTERFACE:
-                return udc_req_std_iface_set_setting();
-            default:
-                break;
+                case USB_REQ_SET_INTERFACE:
+                    return udc_req_std_iface_set_setting();
+                default:
+                    break;
             }
         }
-#if (0!=USB_DEVICE_MAX_EP)
+#if (0 != USB_DEVICE_MAX_EP)
         if (USB_REQ_RECIP_ENDPOINT == Udd_setup_recipient()) {
             // Standard Set Endpoint request
             switch (udd_g_ctrlreq.req.bRequest) {
-            case USB_REQ_CLEAR_FEATURE:
-                return udc_req_std_ep_clear_feature();
-            case USB_REQ_SET_FEATURE:
-                return udc_req_std_ep_set_feature();
-            default:
-                break;
+                case USB_REQ_CLEAR_FEATURE:
+                    return udc_req_std_ep_clear_feature();
+                case USB_REQ_SET_FEATURE:
+                    return udc_req_std_ep_set_feature();
+                default:
+                    break;
             }
         }
 #endif
@@ -1044,13 +945,12 @@ static bool udc_reqstd(void)
  *
  * \return true if the request is supported
  */
-static bool udc_req_iface(void)
-{
-    uint8_t iface_num;
+static bool udc_req_iface(void) {
+    uint8_t   iface_num;
     udi_api_t UDC_DESC_STORAGE *udi_api;
 
     if (0 == udc_num_configuration) {
-        return false; // The device is not is configured state yet
+        return false;  // The device is not is configured state yet
     }
     // Check interface number
     iface_num = udd_g_ctrlreq.req.wIndex & 0xFF;
@@ -1079,18 +979,16 @@ static bool udc_req_iface(void)
  *
  * \return true if the request is supported
  */
-static bool udc_req_ep(void)
-{
-    uint8_t iface_num;
+static bool udc_req_ep(void) {
+    uint8_t   iface_num;
     udi_api_t UDC_DESC_STORAGE *udi_api;
 
     if (0 == udc_num_configuration) {
-        return false; // The device is not is configured state yet
+        return false;  // The device is not is configured state yet
     }
     // Send this request on all enabled interfaces
     iface_num = udd_g_ctrlreq.req.wIndex & 0xFF;
-    for (iface_num = 0; iface_num < udc_ptr_conf->desc->bNumInterfaces;
-            iface_num++) {
+    for (iface_num = 0; iface_num < udc_ptr_conf->desc->bNumInterfaces; iface_num++) {
         // Select the interface with the current alternate setting
         udi_api = udc_ptr_conf->udi_apis[iface_num];
         if (!udc_update_iface_desc(iface_num, udi_api->getsetting())) {
@@ -1118,16 +1016,15 @@ static bool udc_req_ep(void)
  *
  * \return true if the request is supported, else the request is stalled by UDD
  */
-bool udc_process_setup(void)
-{
+bool udc_process_setup(void) {
     // By default no data (receive/send) and no callbacks registered
-    udd_g_ctrlreq.payload_size = 0;
-    udd_g_ctrlreq.callback = NULL;
+    udd_g_ctrlreq.payload_size   = 0;
+    udd_g_ctrlreq.callback       = NULL;
     udd_g_ctrlreq.over_under_run = NULL;
 
     if (Udd_setup_is_in()) {
         if (udd_g_ctrlreq.req.wLength == 0) {
-            return false; // Error from USB host
+            return false;  // Error from USB host
         }
     }
 
@@ -1155,7 +1052,7 @@ bool udc_process_setup(void)
     // Here SETUP request unknown by UDC and UDIs
 #ifdef USB_DEVICE_SPECIFIC_REQUEST
     // Try to decode it in specific callback
-    return USB_DEVICE_SPECIFIC_REQUEST(); // Ex: Vendor request,...
+    return USB_DEVICE_SPECIFIC_REQUEST();  // Ex: Vendor request,...
 #else
     return false;
 #endif
index 33335d1869fb20541b534deaf24e191fb6a77719..8d33307d3c86c96185070adf9cdbc1c91013ae94 100644 (file)
 #include "udd.h"
 
 #if USB_DEVICE_VENDOR_ID == 0
-#   error USB_DEVICE_VENDOR_ID cannot be equal to 0
+#    error USB_DEVICE_VENDOR_ID cannot be equal to 0
 #endif
 
 #if USB_DEVICE_PRODUCT_ID == 0
-#   error USB_DEVICE_PRODUCT_ID cannot be equal to 0
+#    error USB_DEVICE_PRODUCT_ID cannot be equal to 0
 #endif
 
 #ifdef __cplusplus
@@ -172,10 +172,7 @@ extern "C" {
     }
 \endcode
  */
-static inline bool udc_include_vbus_monitoring(void)
-{
-    return udd_include_vbus_monitoring();
-}
+static inline bool udc_include_vbus_monitoring(void) { return udd_include_vbus_monitoring(); }
 
 /*! \brief Start the USB Device stack
  */
@@ -192,28 +189,19 @@ void udc_stop(void);
  * then it will attach device when an acceptable Vbus
  * level from the host is detected.
  */
-static inline void udc_attach(void)
-{
-    udd_attach();
-}
+static inline void udc_attach(void) { udd_attach(); }
 
 /**
  * \brief Detaches the device from the bus
  *
  * The driver must remove pull-up on USB line D- or D+.
  */
-static inline void udc_detach(void)
-{
-    udd_detach();
-}
+static inline void udc_detach(void) { udd_detach(); }
 
 /*! \brief The USB driver sends a resume signal called \e "Upstream Resume"
  * This is authorized only when the remote wakeup feature is enabled by host.
  */
-inline void udc_remotewakeup(void)
-{
-    udd_send_remotewakeup();
-}
+inline void udc_remotewakeup(void) { udd_send_remotewakeup(); }
 
 /**
  * \brief Returns a pointer on the current interface descriptor
@@ -257,4 +245,4 @@ usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
 }
 #endif
 
-#endif // _UDC_H_
+#endif  // _UDC_H_
index 9cab03dcb3f9b38ed701f9a1f0b87df2241fe466..39ea153b401b93b6c7027698a4b3accc922f1e96 100644 (file)
@@ -77,23 +77,21 @@ extern "C" {
  *
  * For Mega application used "code".
  */
-#define  UDC_DESC_STORAGE
-    // Descriptor storage in internal RAM
+#define UDC_DESC_STORAGE
+// Descriptor storage in internal RAM
 #if (defined UDC_DATA_USE_HRAM_SUPPORT)
-#if defined(__GNUC__)
-#define UDC_DATA(x)              COMPILER_WORD_ALIGNED __attribute__((__section__(".data_hram0")))
-#define UDC_BSS(x)               COMPILER_ALIGNED(x)   __attribute__((__section__(".bss_hram0")))
-#elif defined(__ICCAVR32__)
-#define UDC_DATA(x)              COMPILER_ALIGNED(x)   __data32
-#define UDC_BSS(x)               COMPILER_ALIGNED(x)   __data32
-#endif
+#    if defined(__GNUC__)
+#        define UDC_DATA(x) COMPILER_WORD_ALIGNED __attribute__((__section__(".data_hram0")))
+#        define UDC_BSS(x) COMPILER_ALIGNED(x) __attribute__((__section__(".bss_hram0")))
+#    elif defined(__ICCAVR32__)
+#        define UDC_DATA(x) COMPILER_ALIGNED(x) __data32
+#        define UDC_BSS(x) COMPILER_ALIGNED(x) __data32
+#    endif
 #else
-#define UDC_DATA(x)              COMPILER_ALIGNED(x)
-#define UDC_BSS(x)               COMPILER_ALIGNED(x)
+#    define UDC_DATA(x) COMPILER_ALIGNED(x)
+#    define UDC_BSS(x) COMPILER_ALIGNED(x)
 #endif
 
-
-
 /**
  * \brief Configuration descriptor and UDI link for one USB speed
  */
@@ -101,10 +99,9 @@ typedef struct {
     //! USB configuration descriptor
     usb_conf_desc_t UDC_DESC_STORAGE *desc;
     //! Array of UDI API pointer
-    udi_api_t UDC_DESC_STORAGE *UDC_DESC_STORAGE * udi_apis;
+    udi_api_t UDC_DESC_STORAGE *UDC_DESC_STORAGE *udi_apis;
 } udc_config_speed_t;
 
-
 /**
  * \brief All information about the USB Device
  */
@@ -132,4 +129,4 @@ extern UDC_DESC_STORAGE udc_config_t udc_config;
 #ifdef __cplusplus
 }
 #endif
-#endif // _UDC_DESC_H_
+#endif  // _UDC_DESC_H_
index b580e58479859688cf3d6b2b07c5611316d9e4b9..805b761a7755898392fd614052b06e4d17cd036a 100644 (file)
@@ -71,7 +71,7 @@ typedef uint8_t udd_ep_id_t;
 //! \brief Endpoint transfer status
 //! Returned in parameters of callback register via udd_ep_run routine.
 typedef enum {
-    UDD_EP_TRANSFER_OK = 0,
+    UDD_EP_TRANSFER_OK    = 0,
     UDD_EP_TRANSFER_ABORT = 1,
 } udd_ep_status_t;
 
@@ -94,36 +94,32 @@ typedef struct {
     uint16_t payload_size;
 
     //! Callback called after reception of ZLP from setup request
-    void (*callback) (void);
+    void (*callback)(void);
 
     //! Callback called when the buffer given (.payload) is full or empty.
     //! This one return false to abort data transfer, or true with a new buffer in .payload.
-    bool(*over_under_run) (void);
+    bool (*over_under_run)(void);
 } udd_ctrl_request_t;
 extern udd_ctrl_request_t udd_g_ctrlreq;
 
 //! Return true if the setup request \a udd_g_ctrlreq indicates IN data transfer
-#define  Udd_setup_is_in()       \
-      (USB_REQ_DIR_IN == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK))
+#define Udd_setup_is_in() (USB_REQ_DIR_IN == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK))
 
 //! Return true if the setup request \a udd_g_ctrlreq indicates OUT data transfer
-#define  Udd_setup_is_out()      \
-      (USB_REQ_DIR_OUT == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK))
+#define Udd_setup_is_out() (USB_REQ_DIR_OUT == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK))
 
 //! Return the type of the SETUP request \a udd_g_ctrlreq. \see usb_reqtype.
-#define  Udd_setup_type()        \
-      (udd_g_ctrlreq.req.bmRequestType & USB_REQ_TYPE_MASK)
+#define Udd_setup_type() (udd_g_ctrlreq.req.bmRequestType & USB_REQ_TYPE_MASK)
 
 //! Return the recipient of the SETUP request \a udd_g_ctrlreq. \see usb_recipient
-#define  Udd_setup_recipient()   \
-      (udd_g_ctrlreq.req.bmRequestType & USB_REQ_RECIP_MASK)
+#define Udd_setup_recipient() (udd_g_ctrlreq.req.bmRequestType & USB_REQ_RECIP_MASK)
 
 /**
  * \brief End of halt callback function type.
  * Registered by routine udd_ep_wait_stall_clear()
  * Callback called when endpoint stall is cleared.
  */
-typedef void (*udd_callback_halt_cleared_t) (void);
+typedef void (*udd_callback_halt_cleared_t)(void);
 
 /**
  * \brief End of transfer callback function type.
@@ -134,8 +130,7 @@ typedef void (*udd_callback_halt_cleared_t) (void);
  * \param status     UDD_EP_TRANSFER_ABORT, if transfer is aborted
  * \param n          number of data transfered
  */
-typedef void (*udd_callback_trans_t) (udd_ep_status_t status,
-        iram_size_t nb_transfered, udd_ep_id_t ep);
+typedef void (*udd_callback_trans_t)(udd_ep_status_t status, iram_size_t nb_transfered, udd_ep_id_t ep);
 
 /**
  * \brief Authorizes the VBUS event
@@ -216,8 +211,7 @@ void udd_send_remotewakeup(void);
  * \param payload       Pointer on payload
  * \param payload_size  Size of payload
  */
-void udd_set_setup_payload( uint8_t *payload, uint16_t payload_size );
-
+void udd_set_setup_payload(uint8_t *payload, uint16_t payload_size);
 
 /**
  * \name Endpoint Management
@@ -239,8 +233,7 @@ void udd_set_setup_payload( uint8_t *payload, uint16_t payload_size );
  *
  * \return \c 1 if the endpoint is enabled, otherwise \c 0.
  */
-bool udd_ep_alloc(udd_ep_id_t ep, uint8_t bmAttributes,
-        uint16_t MaxEndpointSize);
+bool udd_ep_alloc(udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize);
 
 /**
  * \brief Disables an endpoint
@@ -294,8 +287,7 @@ bool udd_ep_clear_halt(udd_ep_id_t ep);
  *
  * \return \c 1 if the register is accepted, otherwise \c 0.
  */
-bool udd_ep_wait_stall_clear(udd_ep_id_t ep,
-        udd_callback_halt_cleared_t callback);
+bool udd_ep_wait_stall_clear(udd_ep_id_t ep, udd_callback_halt_cleared_t callback);
 
 /**
  * \brief Allows to receive or send data on an endpoint
@@ -321,9 +313,7 @@ bool udd_ep_wait_stall_clear(udd_ep_id_t ep,
  *
  * \return \c 1 if function was successfully done, otherwise \c 0.
  */
-bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket,
-        uint8_t *buf, iram_size_t buf_size,
-        udd_callback_trans_t callback);
+bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, udd_callback_trans_t callback);
 /**
  * \brief Aborts transfer on going on endpoint
  *
@@ -339,7 +329,6 @@ void udd_ep_abort(udd_ep_id_t ep);
 
 //@}
 
-
 /**
  * \name High speed test mode management
  *
@@ -352,7 +341,6 @@ void udd_test_mode_se0_nak(void);
 void udd_test_mode_packet(void);
 //@}
 
-
 /**
  * \name UDC callbacks to provide for UDD
  *
@@ -393,4 +381,4 @@ extern void udc_sof_notify(void);
 #ifdef __cplusplus
 }
 #endif
-#endif // _UDD_H_
+#endif  // _UDD_H_
index 9e4d4baf7fa05536395044882b50df4dbb0753cc..89942cce4d937f034db71fe73d42ad6e0230ff0b 100644 (file)
@@ -72,57 +72,57 @@ extern "C" {
  * selected by UDC.
  */
 typedef struct {
-        /**
-         * \brief Enable the interface.
-         *
-         * This function is called when the host selects a configuration
-         * to which this interface belongs through a Set Configuration
-         * request, and when the host selects an alternate setting of
-         * this interface through a Set Interface request.
-         *
-         * \return \c 1 if function was successfully done, otherwise \c 0.
-         */
-        bool(*enable) (void);
+    /**
+     * \brief Enable the interface.
+     *
+     * This function is called when the host selects a configuration
+     * to which this interface belongs through a Set Configuration
+     * request, and when the host selects an alternate setting of
+     * this interface through a Set Interface request.
+     *
+     * \return \c 1 if function was successfully done, otherwise \c 0.
+     */
+    bool (*enable)(void);
 
-        /**
-         * \brief Disable the interface.
-         *
-         * This function is called when this interface is currently
-         * active, and
-         * - the host selects any configuration through a Set
-         *   Configuration request, or
-         * - the host issues a USB reset, or
-         * - the device is detached from the host (i.e. Vbus is no
-         *   longer present)
-         */
-        void (*disable) (void);
+    /**
+     * \brief Disable the interface.
+     *
+     * This function is called when this interface is currently
+     * active, and
+     * - the host selects any configuration through a Set
+     *   Configuration request, or
+     * - the host issues a USB reset, or
+     * - the device is detached from the host (i.e. Vbus is no
+     *   longer present)
+     */
+    void (*disable)(void);
 
-        /**
-         * \brief Handle a control request directed at an interface.
-         *
-         * This function is called when this interface is currently
-         * active and the host sends a SETUP request
-         * with this interface as the recipient.
-         *
-         * Use udd_g_ctrlreq to decode and response to SETUP request.
-         *
-         * \return \c 1 if this interface supports the SETUP request, otherwise \c 0.
-         */
-        bool(*setup) (void);
+    /**
+     * \brief Handle a control request directed at an interface.
+     *
+     * This function is called when this interface is currently
+     * active and the host sends a SETUP request
+     * with this interface as the recipient.
+     *
+     * Use udd_g_ctrlreq to decode and response to SETUP request.
+     *
+     * \return \c 1 if this interface supports the SETUP request, otherwise \c 0.
+     */
+    bool (*setup)(void);
 
-        /**
-         * \brief Returns the current setting of the selected interface.
-         *
-         * This function is called when UDC when know alternate setting of selected interface.
-         *
-         * \return alternate setting of selected interface
-         */
-        uint8_t(*getsetting) (void);
+    /**
+     * \brief Returns the current setting of the selected interface.
+     *
+     * This function is called when UDC when know alternate setting of selected interface.
+     *
+     * \return alternate setting of selected interface
+     */
+    uint8_t (*getsetting)(void);
 
-        /**
-         * \brief To signal that a SOF is occurred
-         */
-        void(*sof_notify) (void);
+    /**
+     * \brief To signal that a SOF is occurred
+     */
+    void (*sof_notify)(void);
 } udi_api_t;
 
 //@}
@@ -130,4 +130,4 @@ typedef struct {
 #ifdef __cplusplus
 }
 #endif
-#endif // _UDI_H_
+#endif  // _UDI_H_
index ffe3526db56793191a558f83f33e870301cc5073..8271f3b97faa86ed3e220900c3830ea008ad973b 100644 (file)
 
 #ifdef CDC
 
-#ifdef UDI_CDC_LOW_RATE
-#  ifdef USB_DEVICE_HS_SUPPORT
-#    define UDI_CDC_TX_BUFFERS     (UDI_CDC_DATA_EPS_HS_SIZE)
-#    define UDI_CDC_RX_BUFFERS     (UDI_CDC_DATA_EPS_HS_SIZE)
-#  else
-#    define UDI_CDC_TX_BUFFERS     (UDI_CDC_DATA_EPS_FS_SIZE)
-#    define UDI_CDC_RX_BUFFERS     (UDI_CDC_DATA_EPS_FS_SIZE)
-#  endif
-#else
-#  ifdef USB_DEVICE_HS_SUPPORT
-#    define UDI_CDC_TX_BUFFERS     (UDI_CDC_DATA_EPS_HS_SIZE)
-#    define UDI_CDC_RX_BUFFERS     (UDI_CDC_DATA_EPS_HS_SIZE)
-#  else
-#    define UDI_CDC_TX_BUFFERS     (5*UDI_CDC_DATA_EPS_FS_SIZE)
-#    define UDI_CDC_RX_BUFFERS     (5*UDI_CDC_DATA_EPS_FS_SIZE)
-#  endif
-#endif
-
-#ifndef UDI_CDC_TX_EMPTY_NOTIFY
-#  define UDI_CDC_TX_EMPTY_NOTIFY(port)
-#endif
+#    ifdef UDI_CDC_LOW_RATE
+#        ifdef USB_DEVICE_HS_SUPPORT
+#            define UDI_CDC_TX_BUFFERS (UDI_CDC_DATA_EPS_HS_SIZE)
+#            define UDI_CDC_RX_BUFFERS (UDI_CDC_DATA_EPS_HS_SIZE)
+#        else
+#            define UDI_CDC_TX_BUFFERS (UDI_CDC_DATA_EPS_FS_SIZE)
+#            define UDI_CDC_RX_BUFFERS (UDI_CDC_DATA_EPS_FS_SIZE)
+#        endif
+#    else
+#        ifdef USB_DEVICE_HS_SUPPORT
+#            define UDI_CDC_TX_BUFFERS (UDI_CDC_DATA_EPS_HS_SIZE)
+#            define UDI_CDC_RX_BUFFERS (UDI_CDC_DATA_EPS_HS_SIZE)
+#        else
+#            define UDI_CDC_TX_BUFFERS (5 * UDI_CDC_DATA_EPS_FS_SIZE)
+#            define UDI_CDC_RX_BUFFERS (5 * UDI_CDC_DATA_EPS_FS_SIZE)
+#        endif
+#    endif
+
+#    ifndef UDI_CDC_TX_EMPTY_NOTIFY
+#        define UDI_CDC_TX_EMPTY_NOTIFY(port)
+#    endif
 
 /**
  * \ingroup udi_cdc_group
  *
  * @{
  */
-bool udi_cdc_comm_enable(void);
-void udi_cdc_comm_disable(void);
-bool udi_cdc_comm_setup(void);
-bool udi_cdc_data_enable(void);
-void udi_cdc_data_disable(void);
-bool udi_cdc_data_setup(void);
-uint8_t udi_cdc_getsetting(void);
-void udi_cdc_data_sof_notify(void);
-UDC_DESC_STORAGE udi_api_t udi_api_cdc_comm = {
-    .enable = udi_cdc_comm_enable,
-    .disable = udi_cdc_comm_disable,
-    .setup = udi_cdc_comm_setup,
-    .getsetting = udi_cdc_getsetting,
-    .sof_notify = NULL
-};
+bool             udi_cdc_comm_enable(void);
+void             udi_cdc_comm_disable(void);
+bool             udi_cdc_comm_setup(void);
+bool             udi_cdc_data_enable(void);
+void             udi_cdc_data_disable(void);
+bool             udi_cdc_data_setup(void);
+uint8_t          udi_cdc_getsetting(void);
+void             udi_cdc_data_sof_notify(void);
+UDC_DESC_STORAGE udi_api_t udi_api_cdc_comm = {.enable = udi_cdc_comm_enable, .disable = udi_cdc_comm_disable, .setup = udi_cdc_comm_setup, .getsetting = udi_cdc_getsetting, .sof_notify = NULL};
 UDC_DESC_STORAGE udi_api_t udi_api_cdc_data = {
-    .enable = udi_cdc_data_enable,
-    .disable = udi_cdc_data_disable,
-    .setup = udi_cdc_data_setup,
+    .enable     = udi_cdc_data_enable,
+    .disable    = udi_cdc_data_disable,
+    .setup      = udi_cdc_data_setup,
     .getsetting = udi_cdc_getsetting,
     .sof_notify = udi_cdc_data_sof_notify,
 };
@@ -226,9 +220,9 @@ static void udi_cdc_tx_send(uint8_t port);
  */
 //@{
 COMPILER_WORD_ALIGNED
-static usb_cdc_line_coding_t udi_cdc_line_coding[UDI_CDC_PORT_NB];
-static bool udi_cdc_serial_state_msg_ongoing[UDI_CDC_PORT_NB];
-static volatile le16_t udi_cdc_state[UDI_CDC_PORT_NB];
+static usb_cdc_line_coding_t                               udi_cdc_line_coding[UDI_CDC_PORT_NB];
+static bool                                                udi_cdc_serial_state_msg_ongoing[UDI_CDC_PORT_NB];
+static volatile le16_t                                     udi_cdc_state[UDI_CDC_PORT_NB];
 COMPILER_WORD_ALIGNED static usb_cdc_notify_serial_state_t uid_cdc_state_msg[UDI_CDC_PORT_NB];
 
 //! Status of CDC COMM interfaces
@@ -243,7 +237,7 @@ static volatile uint8_t udi_cdc_nb_comm_enabled = 0;
 
 //! Status of CDC DATA interfaces
 static volatile uint8_t udi_cdc_nb_data_enabled = 0;
-static volatile bool udi_cdc_data_running = false;
+static volatile bool    udi_cdc_data_running    = false;
 //! Buffer to receive data
 COMPILER_WORD_ALIGNED static uint8_t udi_cdc_rx_buf[UDI_CDC_PORT_NB][2][UDI_CDC_RX_BUFFERS];
 //! Data available in RX buffers
@@ -256,7 +250,7 @@ static volatile uint16_t udi_cdc_rx_pos[UDI_CDC_PORT_NB];
 static volatile bool udi_cdc_rx_trans_ongoing[UDI_CDC_PORT_NB];
 
 //! Define a transfer halted
-#define  UDI_CDC_TRANS_HALTED    2
+#    define UDI_CDC_TRANS_HALTED 2
 
 //! Buffer to send data
 COMPILER_WORD_ALIGNED static uint8_t udi_cdc_tx_buf[UDI_CDC_PORT_NB][2][UDI_CDC_TX_BUFFERS];
@@ -273,29 +267,26 @@ static volatile bool udi_cdc_tx_both_buf_to_send[UDI_CDC_PORT_NB];
 
 //@}
 
-bool udi_cdc_comm_enable(void)
-{
+bool udi_cdc_comm_enable(void) {
     uint8_t port;
     uint8_t iface_comm_num;
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
-    port = 0;
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
+    port                    = 0;
     udi_cdc_nb_comm_enabled = 0;
-//#else
-//    if (udi_cdc_nb_comm_enabled > UDI_CDC_PORT_NB) {
-//        udi_cdc_nb_comm_enabled = 0;
-//    }
-//    port = udi_cdc_nb_comm_enabled;
-//#endif
+    //#else
+    //    if (udi_cdc_nb_comm_enabled > UDI_CDC_PORT_NB) {
+    //        udi_cdc_nb_comm_enabled = 0;
+    //    }
+    //    port = udi_cdc_nb_comm_enabled;
+    //#endif
 
     // Initialize control signal management
     udi_cdc_state[port] = CPU_TO_LE16(0);
 
-    uid_cdc_state_msg[port].header.bmRequestType =
-            USB_REQ_DIR_IN | USB_REQ_TYPE_CLASS |
-            USB_REQ_RECIP_INTERFACE;
+    uid_cdc_state_msg[port].header.bmRequestType = USB_REQ_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_RECIP_INTERFACE;
     uid_cdc_state_msg[port].header.bNotification = USB_REQ_CDC_NOTIFY_SERIAL_STATE;
-    uid_cdc_state_msg[port].header.wValue = LE16(0);
+    uid_cdc_state_msg[port].header.wValue        = LE16(0);
 
     /*
     switch (port) {
@@ -312,55 +303,54 @@ bool udi_cdc_comm_enable(void)
     */
     iface_comm_num = UDI_CDC_COMM_IFACE_NUMBER_0;
 
-    uid_cdc_state_msg[port].header.wIndex = LE16(iface_comm_num);
+    uid_cdc_state_msg[port].header.wIndex  = LE16(iface_comm_num);
     uid_cdc_state_msg[port].header.wLength = LE16(2);
-    uid_cdc_state_msg[port].value = CPU_TO_LE16(0);
+    uid_cdc_state_msg[port].value          = CPU_TO_LE16(0);
 
-    udi_cdc_line_coding[port].dwDTERate = CPU_TO_LE32(UDI_CDC_DEFAULT_RATE);
+    udi_cdc_line_coding[port].dwDTERate   = CPU_TO_LE32(UDI_CDC_DEFAULT_RATE);
     udi_cdc_line_coding[port].bCharFormat = UDI_CDC_DEFAULT_STOPBITS;
     udi_cdc_line_coding[port].bParityType = UDI_CDC_DEFAULT_PARITY;
-    udi_cdc_line_coding[port].bDataBits = UDI_CDC_DEFAULT_DATABITS;
+    udi_cdc_line_coding[port].bDataBits   = UDI_CDC_DEFAULT_DATABITS;
     // Call application callback
     // to initialize memories or indicate that interface is enabled
-#if 0
+#    if 0
     UDI_CDC_SET_CODING_EXT(port,(&udi_cdc_line_coding[port]));
     if (!UDI_CDC_ENABLE_EXT(port)) {
         return false;
     }
-#endif
+#    endif
     udi_cdc_nb_comm_enabled++;
     return true;
 }
 
-bool udi_cdc_data_enable(void)
-{
+bool udi_cdc_data_enable(void) {
     uint8_t port;
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
-    port = 0;
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
+    port                    = 0;
     udi_cdc_nb_data_enabled = 0;
-//#else
-//    if (udi_cdc_nb_data_enabled > UDI_CDC_PORT_NB) {
-//        udi_cdc_nb_data_enabled = 0;
-//    }
-//    port = udi_cdc_nb_data_enabled;
-//#endif
+    //#else
+    //    if (udi_cdc_nb_data_enabled > UDI_CDC_PORT_NB) {
+    //        udi_cdc_nb_data_enabled = 0;
+    //    }
+    //    port = udi_cdc_nb_data_enabled;
+    //#endif
 
     // Initialize TX management
-    udi_cdc_tx_trans_ongoing[port] = false;
+    udi_cdc_tx_trans_ongoing[port]    = false;
     udi_cdc_tx_both_buf_to_send[port] = false;
-    udi_cdc_tx_buf_sel[port] = 0;
-    udi_cdc_tx_buf_nb[port][0] = 0;
-    udi_cdc_tx_buf_nb[port][1] = 0;
-    udi_cdc_tx_sof_num[port] = 0;
+    udi_cdc_tx_buf_sel[port]          = 0;
+    udi_cdc_tx_buf_nb[port][0]        = 0;
+    udi_cdc_tx_buf_nb[port][1]        = 0;
+    udi_cdc_tx_sof_num[port]          = 0;
     udi_cdc_tx_send(port);
 
     // Initialize RX management
     udi_cdc_rx_trans_ongoing[port] = false;
-    udi_cdc_rx_buf_sel[port] = 0;
-    udi_cdc_rx_buf_nb[port][0] = 0;
-    udi_cdc_rx_buf_nb[port][1] = 0;
-    udi_cdc_rx_pos[port] = 0;
+    udi_cdc_rx_buf_sel[port]       = 0;
+    udi_cdc_rx_buf_nb[port][0]     = 0;
+    udi_cdc_rx_buf_nb[port][1]     = 0;
+    udi_cdc_rx_pos[port]           = 0;
     if (!udi_cdc_rx_start(port)) {
         return false;
     }
@@ -371,25 +361,22 @@ bool udi_cdc_data_enable(void)
     return true;
 }
 
-void udi_cdc_comm_disable(void)
-{
+void udi_cdc_comm_disable(void) {
     Assert(udi_cdc_nb_comm_enabled != 0);
     udi_cdc_nb_comm_enabled--;
 }
 
-void udi_cdc_data_disable(void)
-{
-//  uint8_t port;
+void udi_cdc_data_disable(void) {
+    //  uint8_t port;
 
     Assert(udi_cdc_nb_data_enabled != 0);
     udi_cdc_nb_data_enabled--;
-//  port = udi_cdc_nb_data_enabled;
-//  UDI_CDC_DISABLE_EXT(port);
+    //  port = udi_cdc_nb_data_enabled;
+    //  UDI_CDC_DISABLE_EXT(port);
     udi_cdc_data_running = false;
 }
 
-bool udi_cdc_comm_setup(void)
-{
+bool udi_cdc_comm_setup(void) {
     uint8_t port = udi_cdc_setup_to_port();
 
     if (Udd_setup_is_in()) {
@@ -397,17 +384,12 @@ bool udi_cdc_comm_setup(void)
         if (Udd_setup_type() == USB_REQ_TYPE_CLASS) {
             // Requests Class Interface Get
             switch (udd_g_ctrlreq.req.bRequest) {
-            case USB_REQ_CDC_GET_LINE_CODING:
-                // Get configuration of CDC line
-                if (sizeof(usb_cdc_line_coding_t) !=
-                        udd_g_ctrlreq.req.wLength)
-                    return false; // Error for USB host
-                udd_g_ctrlreq.payload =
-                        (uint8_t *) &
-                        udi_cdc_line_coding[port];
-                udd_g_ctrlreq.payload_size =
-                        sizeof(usb_cdc_line_coding_t);
-                return true;
+                case USB_REQ_CDC_GET_LINE_CODING:
+                    // Get configuration of CDC line
+                    if (sizeof(usb_cdc_line_coding_t) != udd_g_ctrlreq.req.wLength) return false;  // Error for USB host
+                    udd_g_ctrlreq.payload      = (uint8_t *)&udi_cdc_line_coding[port];
+                    udd_g_ctrlreq.payload_size = sizeof(usb_cdc_line_coding_t);
+                    return true;
             }
         }
     }
@@ -416,46 +398,37 @@ bool udi_cdc_comm_setup(void)
         if (Udd_setup_type() == USB_REQ_TYPE_CLASS) {
             // Requests Class Interface Set
             switch (udd_g_ctrlreq.req.bRequest) {
-            case USB_REQ_CDC_SET_LINE_CODING:
-                // Change configuration of CDC line
-                if (sizeof(usb_cdc_line_coding_t) !=
-                        udd_g_ctrlreq.req.wLength)
-                    return false; // Error for USB host
-                udd_g_ctrlreq.callback =
-                        udi_cdc_line_coding_received;
-                udd_g_ctrlreq.payload =
-                        (uint8_t *) &
-                        udi_cdc_line_coding[port];
-                udd_g_ctrlreq.payload_size =
-                        sizeof(usb_cdc_line_coding_t);
-                return true;
-            case USB_REQ_CDC_SET_CONTROL_LINE_STATE:
-                // According cdc spec 1.1 chapter 6.2.14
-//              UDI_CDC_SET_DTR_EXT(port, (0 !=
-//                      (udd_g_ctrlreq.req.wValue
-//                       & CDC_CTRL_SIGNAL_DTE_PRESENT)));
-//              UDI_CDC_SET_RTS_EXT(port, (0 !=
-//                      (udd_g_ctrlreq.req.wValue
-//                       & CDC_CTRL_SIGNAL_ACTIVATE_CARRIER)));
-                return true;
+                case USB_REQ_CDC_SET_LINE_CODING:
+                    // Change configuration of CDC line
+                    if (sizeof(usb_cdc_line_coding_t) != udd_g_ctrlreq.req.wLength) return false;  // Error for USB host
+                    udd_g_ctrlreq.callback     = udi_cdc_line_coding_received;
+                    udd_g_ctrlreq.payload      = (uint8_t *)&udi_cdc_line_coding[port];
+                    udd_g_ctrlreq.payload_size = sizeof(usb_cdc_line_coding_t);
+                    return true;
+                case USB_REQ_CDC_SET_CONTROL_LINE_STATE:
+                    // According cdc spec 1.1 chapter 6.2.14
+                    //              UDI_CDC_SET_DTR_EXT(port, (0 !=
+                    //                      (udd_g_ctrlreq.req.wValue
+                    //                       & CDC_CTRL_SIGNAL_DTE_PRESENT)));
+                    //              UDI_CDC_SET_RTS_EXT(port, (0 !=
+                    //                      (udd_g_ctrlreq.req.wValue
+                    //                       & CDC_CTRL_SIGNAL_ACTIVATE_CARRIER)));
+                    return true;
             }
         }
     }
     return false;  // request Not supported
 }
 
-bool udi_cdc_data_setup(void)
-{
+bool udi_cdc_data_setup(void) {
     return false;  // request Not supported
 }
 
-uint8_t udi_cdc_getsetting(void)
-{
-    return 0;      // CDC don't have multiple alternate setting
+uint8_t udi_cdc_getsetting(void) {
+    return 0;  // CDC don't have multiple alternate setting
 }
 
-void udi_cdc_data_sof_notify(void)
-{
+void udi_cdc_data_sof_notify(void) {
     static uint8_t port_notify = 0;
 
     // A call of udi_cdc_data_sof_notify() is done for each port
@@ -470,12 +443,10 @@ void udi_cdc_data_sof_notify(void)
     */
 }
 
-
 //-------------------------------------------------
 //------- Internal routines to control serial line
 
-static uint8_t udi_cdc_setup_to_port(void)
-{
+static uint8_t udi_cdc_setup_to_port(void) {
     uint8_t port;
 
     /*
@@ -496,35 +467,32 @@ static uint8_t udi_cdc_setup_to_port(void)
     return port;
 }
 
-static void udi_cdc_line_coding_received(void)
-{
+static void udi_cdc_line_coding_received(void) {
     uint8_t port = udi_cdc_setup_to_port();
     UNUSED(port);
 
-//  UDI_CDC_SET_CODING_EXT(port, (&udi_cdc_line_coding[port]));
+    //  UDI_CDC_SET_CODING_EXT(port, (&udi_cdc_line_coding[port]));
 }
 
-static void udi_cdc_ctrl_state_change(uint8_t port, bool b_set, le16_t bit_mask)
-{
+static void udi_cdc_ctrl_state_change(uint8_t port, bool b_set, le16_t bit_mask) {
     udd_ep_id_t ep_comm;
-    uint32_t irqflags;  //irqflags_t
-
+    uint32_t    irqflags;  // irqflags_t
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
     port = 0;
-//#endif
+    //#endif
 
     // Update state
-  irqflags = __get_PRIMASK();
-  __disable_irq();
-  __DMB();
+    irqflags = __get_PRIMASK();
+    __disable_irq();
+    __DMB();
     if (b_set) {
         udi_cdc_state[port] |= bit_mask;
     } else {
         udi_cdc_state[port] &= ~(unsigned)bit_mask;
     }
     __DMB();
-  __set_PRIMASK(irqflags);
+    __set_PRIMASK(irqflags);
 
     /*
     // Send it if possible and state changed
@@ -545,31 +513,21 @@ static void udi_cdc_ctrl_state_change(uint8_t port, bool b_set, le16_t bit_mask)
     udi_cdc_ctrl_state_notify(port, ep_comm);
 }
 
-
-static void udi_cdc_ctrl_state_notify(uint8_t port, udd_ep_id_t ep)
-{
-#if UDI_CDC_PORT_NB == 1 // To optimize code
+static void udi_cdc_ctrl_state_notify(uint8_t port, udd_ep_id_t ep) {
+#    if UDI_CDC_PORT_NB == 1  // To optimize code
     port = 0;
-#endif
+#    endif
 
     // Send it if possible and state changed
-    if ((!udi_cdc_serial_state_msg_ongoing[port])
-            && (udi_cdc_state[port] != uid_cdc_state_msg[port].value)) {
+    if ((!udi_cdc_serial_state_msg_ongoing[port]) && (udi_cdc_state[port] != uid_cdc_state_msg[port].value)) {
         // Fill notification message
         uid_cdc_state_msg[port].value = udi_cdc_state[port];
         // Send notification message
-        udi_cdc_serial_state_msg_ongoing[port] =
-                udd_ep_run(ep,
-                false,
-                (uint8_t *) & uid_cdc_state_msg[port],
-                sizeof(uid_cdc_state_msg[0]),
-                udi_cdc_serial_state_msg_sent);
+        udi_cdc_serial_state_msg_ongoing[port] = udd_ep_run(ep, false, (uint8_t *)&uid_cdc_state_msg[port], sizeof(uid_cdc_state_msg[0]), udi_cdc_serial_state_msg_sent);
     }
 }
 
-
-static void udi_cdc_serial_state_msg_sent(udd_ep_status_t status, iram_size_t n, udd_ep_id_t ep)
-{
+static void udi_cdc_serial_state_msg_sent(udd_ep_status_t status, iram_size_t n, udd_ep_id_t ep) {
     uint8_t port;
     UNUSED(n);
     UNUSED(status);
@@ -594,14 +552,8 @@ static void udi_cdc_serial_state_msg_sent(udd_ep_status_t status, iram_size_t n,
     // For the irregular signals like break, the incoming ring signal,
     // or the overrun error state, this will reset their values to zero
     // and again will not send another notification until their state changes.
-    udi_cdc_state[port] &= ~(CDC_SERIAL_STATE_BREAK |
-            CDC_SERIAL_STATE_RING |
-            CDC_SERIAL_STATE_FRAMING |
-            CDC_SERIAL_STATE_PARITY | CDC_SERIAL_STATE_OVERRUN);
-    uid_cdc_state_msg[port].value &= ~(CDC_SERIAL_STATE_BREAK |
-            CDC_SERIAL_STATE_RING |
-            CDC_SERIAL_STATE_FRAMING |
-            CDC_SERIAL_STATE_PARITY | CDC_SERIAL_STATE_OVERRUN);
+    udi_cdc_state[port] &= ~(CDC_SERIAL_STATE_BREAK | CDC_SERIAL_STATE_RING | CDC_SERIAL_STATE_FRAMING | CDC_SERIAL_STATE_PARITY | CDC_SERIAL_STATE_OVERRUN);
+    uid_cdc_state_msg[port].value &= ~(CDC_SERIAL_STATE_BREAK | CDC_SERIAL_STATE_RING | CDC_SERIAL_STATE_FRAMING | CDC_SERIAL_STATE_PARITY | CDC_SERIAL_STATE_OVERRUN);
     // Send it if possible and state changed
     udi_cdc_ctrl_state_notify(port, ep);
 }
@@ -609,39 +561,37 @@ static void udi_cdc_serial_state_msg_sent(udd_ep_status_t status, iram_size_t n,
 //-------------------------------------------------
 //------- Internal routines to process data transfer
 
-static bool udi_cdc_rx_start(uint8_t port)
-{
-    uint32_t irqflags;  //irqflags_t
-    uint8_t buf_sel_trans;
+static bool udi_cdc_rx_start(uint8_t port) {
+    uint32_t    irqflags;  // irqflags_t
+    uint8_t     buf_sel_trans;
     udd_ep_id_t ep;
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
     port = 0;
-//#endif
+    //#endif
 
     irqflags = __get_PRIMASK();
-  __disable_irq();
-  __DMB();
+    __disable_irq();
+    __DMB();
     buf_sel_trans = udi_cdc_rx_buf_sel[port];
-    if (udi_cdc_rx_trans_ongoing[port] ||
-        (udi_cdc_rx_pos[port] < udi_cdc_rx_buf_nb[port][buf_sel_trans])) {
+    if (udi_cdc_rx_trans_ongoing[port] || (udi_cdc_rx_pos[port] < udi_cdc_rx_buf_nb[port][buf_sel_trans])) {
         // Transfer already on-going or current buffer no empty
-      __DMB();
-    __set_PRIMASK(irqflags);
+        __DMB();
+        __set_PRIMASK(irqflags);
         return false;
     }
 
     // Change current buffer
-    udi_cdc_rx_pos[port] = 0;
-    udi_cdc_rx_buf_sel[port] = (buf_sel_trans==0)?1:0;
+    udi_cdc_rx_pos[port]     = 0;
+    udi_cdc_rx_buf_sel[port] = (buf_sel_trans == 0) ? 1 : 0;
 
     // Start transfer on RX
     udi_cdc_rx_trans_ongoing[port] = true;
-  __DMB();
-  __set_PRIMASK(irqflags);
+    __DMB();
+    __set_PRIMASK(irqflags);
 
     if (udi_cdc_multi_is_rx_ready(port)) {
-//      UDI_CDC_RX_NOTIFY(port);
+        //      UDI_CDC_RX_NOTIFY(port);
     }
 
     /*
@@ -660,15 +610,10 @@ static bool udi_cdc_rx_start(uint8_t port)
     */
     ep = UDI_CDC_DATA_EP_OUT_0;
 
-    return udd_ep_run(ep,
-            true,
-            udi_cdc_rx_buf[port][buf_sel_trans],
-            UDI_CDC_RX_BUFFERS,
-            udi_cdc_data_received);
+    return udd_ep_run(ep, true, udi_cdc_rx_buf[port][buf_sel_trans], UDI_CDC_RX_BUFFERS, udi_cdc_data_received);
 }
 
-static void udi_cdc_data_received(udd_ep_status_t status, iram_size_t n, udd_ep_id_t ep)
-{
+static void udi_cdc_data_received(udd_ep_status_t status, iram_size_t n, udd_ep_id_t ep) {
     uint8_t buf_sel_trans;
     uint8_t port;
 
@@ -692,24 +637,19 @@ static void udi_cdc_data_received(udd_ep_status_t status, iram_size_t n, udd_ep_
         return;
     }
 
-    buf_sel_trans = (udi_cdc_rx_buf_sel[port]==0)?1:0;
+    buf_sel_trans = (udi_cdc_rx_buf_sel[port] == 0) ? 1 : 0;
 
     if (!n) {
-        udd_ep_run( ep,
-                true,
-                udi_cdc_rx_buf[port][buf_sel_trans],
-                UDI_CDC_RX_BUFFERS,
-                udi_cdc_data_received);
+        udd_ep_run(ep, true, udi_cdc_rx_buf[port][buf_sel_trans], UDI_CDC_RX_BUFFERS, udi_cdc_data_received);
         return;
     }
 
     udi_cdc_rx_buf_nb[port][buf_sel_trans] = n;
-    udi_cdc_rx_trans_ongoing[port] = false;
+    udi_cdc_rx_trans_ongoing[port]         = false;
     udi_cdc_rx_start(port);
 }
 
-static void udi_cdc_data_sent(udd_ep_status_t status, iram_size_t n, udd_ep_id_t ep)
-{
+static void udi_cdc_data_sent(udd_ep_status_t status, iram_size_t n, udd_ep_id_t ep) {
     uint8_t port;
     UNUSED(n);
 
@@ -733,9 +673,9 @@ static void udi_cdc_data_sent(udd_ep_status_t status, iram_size_t n, udd_ep_id_t
         return;
     }
 
-    udi_cdc_tx_buf_nb[port][(udi_cdc_tx_buf_sel[port]==0)?1:0] = 0;
-    udi_cdc_tx_both_buf_to_send[port] = false;
-    udi_cdc_tx_trans_ongoing[port] = false;
+    udi_cdc_tx_buf_nb[port][(udi_cdc_tx_buf_sel[port] == 0) ? 1 : 0] = 0;
+    udi_cdc_tx_both_buf_to_send[port]                                = false;
+    udi_cdc_tx_trans_ongoing[port]                                   = false;
 
     if (n != 0) {
         UDI_CDC_TX_EMPTY_NOTIFY(port);
@@ -744,41 +684,39 @@ static void udi_cdc_data_sent(udd_ep_status_t status, iram_size_t n, udd_ep_id_t
     udi_cdc_tx_send(port);
 }
 
-static void udi_cdc_tx_send(uint8_t port)
-{
-    uint32_t irqflags;  //irqflags_t
-    uint8_t buf_sel_trans;
-    bool b_short_packet;
-    udd_ep_id_t ep;
+static void udi_cdc_tx_send(uint8_t port) {
+    uint32_t        irqflags;  // irqflags_t
+    uint8_t         buf_sel_trans;
+    bool            b_short_packet;
+    udd_ep_id_t     ep;
     static uint16_t sof_zlp_counter = 0;
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
     port = 0;
-//#endif
+    //#endif
 
     if (udi_cdc_tx_trans_ongoing[port]) {
-        return; // Already on going or wait next SOF to send next data
+        return;  // Already on going or wait next SOF to send next data
     }
     if (udd_is_high_speed()) {
         if (udi_cdc_tx_sof_num[port] == udd_get_micro_frame_number()) {
-            return; // Wait next SOF to send next data
+            return;  // Wait next SOF to send next data
         }
-    }else{
+    } else {
         if (udi_cdc_tx_sof_num[port] == udd_get_frame_number()) {
-            return; // Wait next SOF to send next data
+            return;  // Wait next SOF to send next data
         }
     }
 
     irqflags = __get_PRIMASK();
-  __disable_irq();
-  __DMB();
+    __disable_irq();
+    __DMB();
     buf_sel_trans = udi_cdc_tx_buf_sel[port];
     if (udi_cdc_tx_buf_nb[port][buf_sel_trans] == 0) {
         sof_zlp_counter++;
-        if (((!udd_is_high_speed()) && (sof_zlp_counter < 100))
-                || (udd_is_high_speed() && (sof_zlp_counter < 800))) {
-      __DMB();
-    __set_PRIMASK(irqflags);
+        if (((!udd_is_high_speed()) && (sof_zlp_counter < 100)) || (udd_is_high_speed() && (sof_zlp_counter < 800))) {
+            __DMB();
+            __set_PRIMASK(irqflags);
             return;
         }
     }
@@ -787,25 +725,25 @@ static void udi_cdc_tx_send(uint8_t port)
     if (!udi_cdc_tx_both_buf_to_send[port]) {
         // Send current Buffer
         // and switch the current buffer
-        udi_cdc_tx_buf_sel[port] = (buf_sel_trans==0)?1:0;
-    }else{
+        udi_cdc_tx_buf_sel[port] = (buf_sel_trans == 0) ? 1 : 0;
+    } else {
         // Send the other Buffer
         // and no switch the current buffer
-        buf_sel_trans = (buf_sel_trans==0)?1:0;
+        buf_sel_trans = (buf_sel_trans == 0) ? 1 : 0;
     }
     udi_cdc_tx_trans_ongoing[port] = true;
-  __DMB();
-  __set_PRIMASK(irqflags);
+    __DMB();
+    __set_PRIMASK(irqflags);
 
     b_short_packet = (udi_cdc_tx_buf_nb[port][buf_sel_trans] != UDI_CDC_TX_BUFFERS);
     if (b_short_packet) {
         if (udd_is_high_speed()) {
             udi_cdc_tx_sof_num[port] = udd_get_micro_frame_number();
-        }else{
+        } else {
             udi_cdc_tx_sof_num[port] = udd_get_frame_number();
         }
-    }else{
-        udi_cdc_tx_sof_num[port] = 0; // Force next transfer without wait SOF
+    } else {
+        udi_cdc_tx_sof_num[port] = 0;  // Force next transfer without wait SOF
     }
 
     /*
@@ -824,126 +762,81 @@ static void udi_cdc_tx_send(uint8_t port)
     */
     ep = UDI_CDC_DATA_EP_IN_0;
 
-    udd_ep_run( ep,
-            b_short_packet,
-            udi_cdc_tx_buf[port][buf_sel_trans],
-            udi_cdc_tx_buf_nb[port][buf_sel_trans],
-            udi_cdc_data_sent);
+    udd_ep_run(ep, b_short_packet, udi_cdc_tx_buf[port][buf_sel_trans], udi_cdc_tx_buf_nb[port][buf_sel_trans], udi_cdc_data_sent);
 }
 
 //---------------------------------------------
 //------- Application interface
 
-void udi_cdc_ctrl_signal_dcd(bool b_set)
-{
-    udi_cdc_ctrl_state_change(0, b_set, CDC_SERIAL_STATE_DCD);
-}
+void udi_cdc_ctrl_signal_dcd(bool b_set) { udi_cdc_ctrl_state_change(0, b_set, CDC_SERIAL_STATE_DCD); }
 
-void udi_cdc_ctrl_signal_dsr(bool b_set)
-{
-    udi_cdc_ctrl_state_change(0, b_set, CDC_SERIAL_STATE_DSR);
-}
+void udi_cdc_ctrl_signal_dsr(bool b_set) { udi_cdc_ctrl_state_change(0, b_set, CDC_SERIAL_STATE_DSR); }
 
-void udi_cdc_signal_framing_error(void)
-{
-    udi_cdc_ctrl_state_change(0, true, CDC_SERIAL_STATE_FRAMING);
-}
+void udi_cdc_signal_framing_error(void) { udi_cdc_ctrl_state_change(0, true, CDC_SERIAL_STATE_FRAMING); }
 
-void udi_cdc_signal_parity_error(void)
-{
-    udi_cdc_ctrl_state_change(0, true, CDC_SERIAL_STATE_PARITY);
-}
+void udi_cdc_signal_parity_error(void) { udi_cdc_ctrl_state_change(0, true, CDC_SERIAL_STATE_PARITY); }
 
-void udi_cdc_signal_overrun(void)
-{
-    udi_cdc_ctrl_state_change(0, true, CDC_SERIAL_STATE_OVERRUN);
-}
+void udi_cdc_signal_overrun(void) { udi_cdc_ctrl_state_change(0, true, CDC_SERIAL_STATE_OVERRUN); }
 
-void udi_cdc_multi_ctrl_signal_dcd(uint8_t port, bool b_set)
-{
-    udi_cdc_ctrl_state_change(port, b_set, CDC_SERIAL_STATE_DCD);
-}
+void udi_cdc_multi_ctrl_signal_dcd(uint8_t port, bool b_set) { udi_cdc_ctrl_state_change(port, b_set, CDC_SERIAL_STATE_DCD); }
 
-void udi_cdc_multi_ctrl_signal_dsr(uint8_t port, bool b_set)
-{
-    udi_cdc_ctrl_state_change(port, b_set, CDC_SERIAL_STATE_DSR);
-}
+void udi_cdc_multi_ctrl_signal_dsr(uint8_t port, bool b_set) { udi_cdc_ctrl_state_change(port, b_set, CDC_SERIAL_STATE_DSR); }
 
-void udi_cdc_multi_signal_framing_error(uint8_t port)
-{
-    udi_cdc_ctrl_state_change(port, true, CDC_SERIAL_STATE_FRAMING);
-}
+void udi_cdc_multi_signal_framing_error(uint8_t port) { udi_cdc_ctrl_state_change(port, true, CDC_SERIAL_STATE_FRAMING); }
 
-void udi_cdc_multi_signal_parity_error(uint8_t port)
-{
-    udi_cdc_ctrl_state_change(port, true, CDC_SERIAL_STATE_PARITY);
-}
+void udi_cdc_multi_signal_parity_error(uint8_t port) { udi_cdc_ctrl_state_change(port, true, CDC_SERIAL_STATE_PARITY); }
 
-void udi_cdc_multi_signal_overrun(uint8_t port)
-{
-    udi_cdc_ctrl_state_change(port, true, CDC_SERIAL_STATE_OVERRUN);
-}
+void udi_cdc_multi_signal_overrun(uint8_t port) { udi_cdc_ctrl_state_change(port, true, CDC_SERIAL_STATE_OVERRUN); }
 
-iram_size_t udi_cdc_multi_get_nb_received_data(uint8_t port)
-{
-    uint32_t irqflags;  //irqflags_t
-    uint16_t pos;
+iram_size_t udi_cdc_multi_get_nb_received_data(uint8_t port) {
+    uint32_t    irqflags;  // irqflags_t
+    uint16_t    pos;
     iram_size_t nb_received;
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
     port = 0;
-//#endif
+    //#endif
 
     irqflags = __get_PRIMASK();
-  __disable_irq();
-  __DMB();
-    pos = udi_cdc_rx_pos[port];
+    __disable_irq();
+    __DMB();
+    pos         = udi_cdc_rx_pos[port];
     nb_received = udi_cdc_rx_buf_nb[port][udi_cdc_rx_buf_sel[port]] - pos;
     __DMB();
-  __set_PRIMASK(irqflags);
+    __set_PRIMASK(irqflags);
     return nb_received;
 }
 
-iram_size_t udi_cdc_get_nb_received_data(void)
-{
-    return udi_cdc_multi_get_nb_received_data(0);
-}
+iram_size_t udi_cdc_get_nb_received_data(void) { return udi_cdc_multi_get_nb_received_data(0); }
 
-bool udi_cdc_multi_is_rx_ready(uint8_t port)
-{
-    return (udi_cdc_multi_get_nb_received_data(port) > 0);
-}
+bool udi_cdc_multi_is_rx_ready(uint8_t port) { return (udi_cdc_multi_get_nb_received_data(port) > 0); }
 
-bool udi_cdc_is_rx_ready(void)
-{
-    return udi_cdc_multi_is_rx_ready(0);
-}
+bool udi_cdc_is_rx_ready(void) { return udi_cdc_multi_is_rx_ready(0); }
 
-int udi_cdc_multi_getc(uint8_t port)
-{
-    uint32_t irqflags;  //irqflags_t
-    int rx_data = 0;
-    bool b_databit_9;
+int udi_cdc_multi_getc(uint8_t port) {
+    uint32_t irqflags;  // irqflags_t
+    int      rx_data = 0;
+    bool     b_databit_9;
     uint16_t pos;
-    uint8_t buf_sel;
-    bool again;
+    uint8_t  buf_sel;
+    bool     again;
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
     port = 0;
-//#endif
+    //#endif
 
     b_databit_9 = (9 == udi_cdc_line_coding[port].bDataBits);
 
 udi_cdc_getc_process_one_byte:
     // Check available data
     irqflags = __get_PRIMASK();
-  __disable_irq();
-  __DMB();
-    pos = udi_cdc_rx_pos[port];
+    __disable_irq();
+    __DMB();
+    pos     = udi_cdc_rx_pos[port];
     buf_sel = udi_cdc_rx_buf_sel[port];
-    again = pos >= udi_cdc_rx_buf_nb[port][buf_sel];
+    again   = pos >= udi_cdc_rx_buf_nb[port][buf_sel];
     __DMB();
-  __set_PRIMASK(irqflags);
+    __set_PRIMASK(irqflags);
     while (again) {
         if (!udi_cdc_data_running) {
             return 0;
@@ -953,46 +846,43 @@ udi_cdc_getc_process_one_byte:
 
     // Read data
     rx_data |= udi_cdc_rx_buf[port][buf_sel][pos];
-    udi_cdc_rx_pos[port] = pos+1;
+    udi_cdc_rx_pos[port] = pos + 1;
 
     udi_cdc_rx_start(port);
 
     if (b_databit_9) {
         // Receive MSB
         b_databit_9 = false;
-        rx_data = rx_data << 8;
+        rx_data     = rx_data << 8;
         goto udi_cdc_getc_process_one_byte;
     }
     return rx_data;
 }
 
-int udi_cdc_getc(void)
-{
-    return udi_cdc_multi_getc(0);
-}
+int udi_cdc_getc(void) { return udi_cdc_multi_getc(0); }
 
-iram_size_t udi_cdc_multi_read_buf(uint8_t port, void* buf, iram_size_t size)
-{
-    uint32_t irqflags;  //irqflags_t
-    uint8_t *ptr_buf = (uint8_t *)buf;
+iram_size_t udi_cdc_multi_read_buf(uint8_t port, void *buf, iram_size_t size) {
+    uint32_t    irqflags;  // irqflags_t
+    uint8_t *   ptr_buf = (uint8_t *)buf;
     iram_size_t copy_nb;
-    uint16_t pos;
-    uint8_t buf_sel;
-    bool again;
+    uint16_t    pos;
+    uint8_t     buf_sel;
+    bool        again;
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
     port = 0;
-//#endif
+    //#endif
 
 udi_cdc_read_buf_loop_wait:
     // Check available data
     irqflags = __get_PRIMASK();
-  __disable_irq();
-  __DMB();  pos = udi_cdc_rx_pos[port];
+    __disable_irq();
+    __DMB();
+    pos     = udi_cdc_rx_pos[port];
     buf_sel = udi_cdc_rx_buf_sel[port];
-    again = pos >= udi_cdc_rx_buf_nb[port][buf_sel];
+    again   = pos >= udi_cdc_rx_buf_nb[port][buf_sel];
     __DMB();
-  __set_PRIMASK(irqflags);
+    __set_PRIMASK(irqflags);
     while (again) {
         if (!udi_cdc_data_running) {
             return size;
@@ -1002,7 +892,7 @@ udi_cdc_read_buf_loop_wait:
 
     // Read data
     copy_nb = udi_cdc_rx_buf_nb[port][buf_sel] - pos;
-    if (copy_nb>size) {
+    if (copy_nb > size) {
         copy_nb = size;
     }
     memcpy(ptr_buf, &udi_cdc_rx_buf[port][buf_sel][pos], copy_nb);
@@ -1017,118 +907,99 @@ udi_cdc_read_buf_loop_wait:
     return 0;
 }
 
-static iram_size_t udi_cdc_multi_read_no_polling(uint8_t port, void* buf, iram_size_t size)
-{
-    uint8_t *ptr_buf = (uint8_t *)buf;
+static iram_size_t udi_cdc_multi_read_no_polling(uint8_t port, void *buf, iram_size_t size) {
+    uint8_t *   ptr_buf = (uint8_t *)buf;
     iram_size_t nb_avail_data;
-    uint16_t pos;
-    uint8_t buf_sel;
-    uint32_t irqflags;  //irqflags_t
+    uint16_t    pos;
+    uint8_t     buf_sel;
+    uint32_t    irqflags;  // irqflags_t
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
     port = 0;
-//#endif
+    //#endif
 
-    //Data interface not started... exit
+    // Data interface not started... exit
     if (!udi_cdc_data_running) {
         return 0;
     }
 
-    //Get number of available data
+    // Get number of available data
     // Check available data
     irqflags = __get_PRIMASK();
-  __disable_irq();
-  __DMB();
-    pos = udi_cdc_rx_pos[port];
-    buf_sel = udi_cdc_rx_buf_sel[port];
+    __disable_irq();
+    __DMB();
+    pos           = udi_cdc_rx_pos[port];
+    buf_sel       = udi_cdc_rx_buf_sel[port];
     nb_avail_data = udi_cdc_rx_buf_nb[port][buf_sel] - pos;
     __DMB();
-  __set_PRIMASK(irqflags);
-    //If the buffer contains less than the requested number of data,
-    //adjust read size
-    if(nb_avail_data<size) {
+    __set_PRIMASK(irqflags);
+    // If the buffer contains less than the requested number of data,
+    // adjust read size
+    if (nb_avail_data < size) {
         size = nb_avail_data;
     }
-    if(size>0) {
+    if (size > 0) {
         memcpy(ptr_buf, &udi_cdc_rx_buf[port][buf_sel][pos], size);
-    irqflags = __get_PRIMASK();
-    __disable_irq();
-    __DMB();
+        irqflags = __get_PRIMASK();
+        __disable_irq();
+        __DMB();
         udi_cdc_rx_pos[port] += size;
-    __DMB();
-    __set_PRIMASK(irqflags);
+        __DMB();
+        __set_PRIMASK(irqflags);
         ptr_buf += size;
         udi_cdc_rx_start(port);
     }
-    return(nb_avail_data);
+    return (nb_avail_data);
 }
 
-iram_size_t udi_cdc_read_no_polling(void* buf, iram_size_t size)
-{
-    return udi_cdc_multi_read_no_polling(0, buf, size);
-}
+iram_size_t udi_cdc_read_no_polling(void *buf, iram_size_t size) { return udi_cdc_multi_read_no_polling(0, buf, size); }
 
-iram_size_t udi_cdc_read_buf(void* buf, iram_size_t size)
-{
-    return udi_cdc_multi_read_buf(0, buf, size);
-}
+iram_size_t udi_cdc_read_buf(void *buf, iram_size_t size) { return udi_cdc_multi_read_buf(0, buf, size); }
 
-iram_size_t udi_cdc_multi_get_free_tx_buffer(uint8_t port)
-{
-    uint32_t irqflags;  //irqflags_t
+iram_size_t udi_cdc_multi_get_free_tx_buffer(uint8_t port) {
+    uint32_t    irqflags;  // irqflags_t
     iram_size_t buf_sel_nb, retval;
-    uint8_t buf_sel;
+    uint8_t     buf_sel;
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
     port = 0;
-//#endif
+    //#endif
 
     irqflags = __get_PRIMASK();
-  __disable_irq();
-  __DMB();
-    buf_sel = udi_cdc_tx_buf_sel[port];
+    __disable_irq();
+    __DMB();
+    buf_sel    = udi_cdc_tx_buf_sel[port];
     buf_sel_nb = udi_cdc_tx_buf_nb[port][buf_sel];
     if (buf_sel_nb == UDI_CDC_TX_BUFFERS) {
-        if ((!udi_cdc_tx_trans_ongoing[port])
-            && (!udi_cdc_tx_both_buf_to_send[port])) {
+        if ((!udi_cdc_tx_trans_ongoing[port]) && (!udi_cdc_tx_both_buf_to_send[port])) {
             /* One buffer is full, but the other buffer is not used.
              * (not used = transfer on-going)
              * then move to the other buffer to store data */
             udi_cdc_tx_both_buf_to_send[port] = true;
-            udi_cdc_tx_buf_sel[port] = (buf_sel == 0)? 1 : 0;
-            buf_sel_nb = 0;
+            udi_cdc_tx_buf_sel[port]          = (buf_sel == 0) ? 1 : 0;
+            buf_sel_nb                        = 0;
         }
     }
     retval = UDI_CDC_TX_BUFFERS - buf_sel_nb;
     __DMB();
-  __set_PRIMASK(irqflags);
+    __set_PRIMASK(irqflags);
     return retval;
 }
 
-iram_size_t udi_cdc_get_free_tx_buffer(void)
-{
-    return udi_cdc_multi_get_free_tx_buffer(0);
-}
+iram_size_t udi_cdc_get_free_tx_buffer(void) { return udi_cdc_multi_get_free_tx_buffer(0); }
 
-bool udi_cdc_multi_is_tx_ready(uint8_t port)
-{
-    return (udi_cdc_multi_get_free_tx_buffer(port) != 0);
-}
+bool udi_cdc_multi_is_tx_ready(uint8_t port) { return (udi_cdc_multi_get_free_tx_buffer(port) != 0); }
 
-bool udi_cdc_is_tx_ready(void)
-{
-    return udi_cdc_multi_is_tx_ready(0);
-}
+bool udi_cdc_is_tx_ready(void) { return udi_cdc_multi_is_tx_ready(0); }
 
-int udi_cdc_multi_putc(uint8_t port, int value)
-{
-    uint32_t irqflags;  //irqflags_t
-    bool b_databit_9;
-    uint8_t buf_sel;
+int udi_cdc_multi_putc(uint8_t port, int value) {
+    uint32_t irqflags;  // irqflags_t
+    bool     b_databit_9;
+    uint8_t  buf_sel;
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
     port = 0;
-//#endif
+    //#endif
 
     b_databit_9 = (9 == udi_cdc_line_coding[port].bDataBits);
 
@@ -1143,44 +1014,40 @@ udi_cdc_putc_process_one_byte:
 
     // Write value
     irqflags = __get_PRIMASK();
-  __disable_irq();
-  __DMB();
-    buf_sel = udi_cdc_tx_buf_sel[port];
+    __disable_irq();
+    __DMB();
+    buf_sel                                                           = udi_cdc_tx_buf_sel[port];
     udi_cdc_tx_buf[port][buf_sel][udi_cdc_tx_buf_nb[port][buf_sel]++] = value;
-  __DMB();
-  __set_PRIMASK(irqflags);
+    __DMB();
+    __set_PRIMASK(irqflags);
 
     if (b_databit_9) {
         // Send MSB
         b_databit_9 = false;
-        value = value >> 8;
+        value       = value >> 8;
         goto udi_cdc_putc_process_one_byte;
     }
     return true;
 }
 
-int udi_cdc_putc(int value)
-{
-    return udi_cdc_multi_putc(0, value);
-}
+int udi_cdc_putc(int value) { return udi_cdc_multi_putc(0, value); }
 
-iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t size)
-{
-    uint32_t irqflags;  //irqflags_t
-    uint8_t buf_sel;
-    uint16_t buf_nb;
+iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void *buf, iram_size_t size) {
+    uint32_t    irqflags;  // irqflags_t
+    uint8_t     buf_sel;
+    uint16_t    buf_nb;
     iram_size_t copy_nb;
-    uint8_t *ptr_buf = (uint8_t *)buf;
+    uint8_t *   ptr_buf = (uint8_t *)buf;
 
-//#if UDI_CDC_PORT_NB == 1 // To optimize code
+    //#if UDI_CDC_PORT_NB == 1 // To optimize code
     port = 0;
-//#endif
+    //#endif
 
     if (9 == udi_cdc_line_coding[port].bDataBits) {
-        size *=2;
+        size *= 2;
     }
 
-    udi_cdc_write_buf_loop_wait:
+udi_cdc_write_buf_loop_wait:
 
     // Check available space
     if (!udi_cdc_multi_is_tx_ready(port)) {
@@ -1195,7 +1062,7 @@ iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t s
     __disable_irq();
     __DMB();
     buf_sel = udi_cdc_tx_buf_sel[port];
-    buf_nb = udi_cdc_tx_buf_nb[port][buf_sel];
+    buf_nb  = udi_cdc_tx_buf_nb[port][buf_sel];
     copy_nb = UDI_CDC_TX_BUFFERS - buf_nb;
     if (copy_nb > size) {
         copy_nb = size;
@@ -1216,43 +1083,36 @@ iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t s
     return 0;
 }
 
-iram_size_t udi_cdc_write_buf(const void* buf, iram_size_t size)
-{
-    return udi_cdc_multi_write_buf(0, buf, size);
-}
+iram_size_t udi_cdc_write_buf(const void *buf, iram_size_t size) { return udi_cdc_multi_write_buf(0, buf, size); }
 
-#define MAX_PRINT 256
-#define CDC_SEND_INTERVAL 2
+#    define MAX_PRINT 256
+#    define CDC_SEND_INTERVAL 2
 uint32_t cdc_tx_send_time_next;
 
-void CDC_send(void)
-{
-    while (timer_read64() < cdc_tx_send_time_next);
+void CDC_send(void) {
+    while (timer_read64() < cdc_tx_send_time_next)
+        ;
     udi_cdc_tx_send(0);
     cdc_tx_send_time_next = timer_read64() + CDC_SEND_INTERVAL;
 }
 
-uint32_t CDC_print(char *printbuf)
-{
-    uint32_t count=0;
-    char *buf = printbuf;
-    char c;
+uint32_t CDC_print(char *printbuf) {
+    uint32_t count = 0;
+    char *   buf   = printbuf;
+    char     c;
 
     if (timer_read64() < 5000) return 0;
 
-    while ((c = *buf++) != 0 && !(count >= MAX_PRINT))
-    {
+    while ((c = *buf++) != 0 && !(count >= MAX_PRINT)) {
         count++;
         if (!udi_cdc_is_tx_ready()) return 0;
         udi_cdc_putc(c);
-        if (count >= UDI_CDC_TX_BUFFERS)
-        {
+        if (count >= UDI_CDC_TX_BUFFERS) {
             count = 0;
             CDC_send();
         }
     }
-    if (count)
-    {
+    if (count) {
         CDC_send();
     }
     return 1;
@@ -1260,12 +1120,11 @@ uint32_t CDC_print(char *printbuf)
 
 char printbuf[CDC_PRINTBUF_SIZE];
 
-int CDC_printf(const char *_Format, ...)
-{
-    va_list va; //Variable argument list variable
-    int result;
+int CDC_printf(const char *_Format, ...) {
+    va_list va;  // Variable argument list variable
+    int     result;
 
-    va_start(va, _Format); //Initialize the variable argument list
+    va_start(va, _Format);  // Initialize the variable argument list
     result = vsnprintf(printbuf, CDC_PRINTBUF_SIZE, _Format, va);
     va_end(va);
 
@@ -1274,107 +1133,83 @@ int CDC_printf(const char *_Format, ...)
     return result;
 }
 
-//global "inbuf" if desired
+// global "inbuf" if desired
 inbuf_t inbuf;
 
-uint32_t CDC_input_buf(inbuf_t inbuf, uint32_t inbuf_size)
-{
+uint32_t CDC_input_buf(inbuf_t inbuf, uint32_t inbuf_size) {
     int RXChar;
     int entered = 0;
 
     if (!udi_cdc_is_rx_ready()) return 0;
     udi_cdc_get_nb_received_data();
-    RXChar =  udi_cdc_getc();
-
-    if (RXChar)
-    {
-        switch (RXChar)
-        {
-            case '\t':  //tab - repeat last
-                inbuf.count=inbuf.lastcount;
-                inbuf.buf[inbuf.count+1] = 0;
+    RXChar = udi_cdc_getc();
+
+    if (RXChar) {
+        switch (RXChar) {
+            case '\t':  // tab - repeat last
+                inbuf.count                = inbuf.lastcount;
+                inbuf.buf[inbuf.count + 1] = 0;
                 CDC_print(inbuf.buf);
                 break;
-            case '\r':  //enter
-                inbuf.buf[inbuf.count]=0;
-                inbuf.lastcount = inbuf.count;
-                inbuf.count = 0;
-                entered = 1;
+            case '\r':  // enter
+                inbuf.buf[inbuf.count] = 0;
+                inbuf.lastcount        = inbuf.count;
+                inbuf.count            = 0;
+                entered                = 1;
                 break;
-            case '\b': //backspace
+            case '\b':  // backspace
                 if (inbuf.count > 0) {
                     inbuf.count -= 1;
                     CDC_print("\b \b\0");
-                }
-                else
+                } else
                     CDC_print("\a\0");
                 break;
-        default:
-            if ((RXChar >= 32) && (RXChar <= 126))
-            {
-                if (inbuf.count < inbuf_size-1)
-                {
-                    inbuf.buf[inbuf.count] = RXChar;
-                    inbuf.buf[inbuf.count+1] = 0;
-                    CDC_print(&inbuf.buf[inbuf.count]);
-                    inbuf.count += 1;
+            default:
+                if ((RXChar >= 32) && (RXChar <= 126)) {
+                    if (inbuf.count < inbuf_size - 1) {
+                        inbuf.buf[inbuf.count]     = RXChar;
+                        inbuf.buf[inbuf.count + 1] = 0;
+                        CDC_print(&inbuf.buf[inbuf.count]);
+                        inbuf.count += 1;
+                    } else
+                        CDC_print("\a\0");
                 }
-                else
-                    CDC_print("\a\0");
-            }
-            break;
+                break;
         }
         RXChar = 0;
     }
     return entered;
 }
 
-uint32_t CDC_input()
-{
-    return CDC_input_buf(inbuf, CDC_INBUF_SIZE);
-}
+uint32_t CDC_input() { return CDC_input_buf(inbuf, CDC_INBUF_SIZE); }
 
-void CDC_init(void)
-{
-    inbuf.count = 0;
-    inbuf.lastcount = 0;
-    printbuf[0] = 0;
+void CDC_init(void) {
+    inbuf.count           = 0;
+    inbuf.lastcount       = 0;
+    printbuf[0]           = 0;
     cdc_tx_send_time_next = timer_read64() + CDC_SEND_INTERVAL;
 }
 
-#else //CDC line 62
+#else  // CDC line 62
 
 char printbuf[CDC_PRINTBUF_SIZE];
 
-void CDC_send(void)
-{
-    return;
-}
+void CDC_send(void) { return; }
 
-uint32_t CDC_print(char *printbuf)
-{
-    return 0;
-}
+uint32_t CDC_print(char *printbuf) { return 0; }
 
-int CDC_printf(const char *_Format, ...)
-{
-    return 0;
-}
+int CDC_printf(const char *_Format, ...) { return 0; }
 
 inbuf_t inbuf;
 
-uint32_t CDC_input(void)
-{
-    return 0;
-}
+uint32_t CDC_input(void) { return 0; }
 
-void CDC_init(void)
-{
-    inbuf.count = 0;
+void CDC_init(void) {
+    inbuf.count     = 0;
     inbuf.lastcount = 0;
-    printbuf[0]=0;
+    printbuf[0]     = 0;
 }
 
-#endif //CDC line 62
+#endif  // CDC line 62
 
 //@}
index 86077ce53bd69e904141dbfd797b7cc1d96da764..9135bab546ef89d471cb82a1d86f7462a06a3139 100644 (file)
 
 #ifdef CDC
 
-#include "conf_usb.h"
-#include "usb_protocol.h"
-#include "usb_protocol_cdc.h"
-#include "udd.h"
-#include "udc_desc.h"
-#include "udi.h"
+#    include "conf_usb.h"
+#    include "usb_protocol.h"
+#    include "usb_protocol_cdc.h"
+#    include "udd.h"
+#    include "udc_desc.h"
+#    include "udi.h"
 
 // Check the number of port
-#ifndef UDI_CDC_PORT_NB
-# define UDI_CDC_PORT_NB 1
-#endif
-#if (UDI_CDC_PORT_NB > 1)
-# error UDI_CDC_PORT_NB must be at most 1
-#endif
-
-#ifdef __cplusplus
+#    ifndef UDI_CDC_PORT_NB
+#        define UDI_CDC_PORT_NB 1
+#    endif
+#    if (UDI_CDC_PORT_NB > 1)
+#        error UDI_CDC_PORT_NB must be at most 1
+#    endif
+
+#    ifdef __cplusplus
 extern "C" {
-#endif
+#    endif
 
 /**
  * \addtogroup udi_cdc_group_udc
@@ -82,9 +82,9 @@ extern UDC_DESC_STORAGE udi_api_t udi_api_cdc_data;
 //#define CDC_RX_SIZE   64
 
 //! CDC communication endpoints size for all speeds
-#define UDI_CDC_COMM_EP_SIZE        CDC_ACM_SIZE
+#    define UDI_CDC_COMM_EP_SIZE CDC_ACM_SIZE
 //! CDC data endpoints size for FS speed (8B, 16B, 32B, 64B)
-#define UDI_CDC_DATA_EPS_FS_SIZE    CDC_RX_SIZE
+#    define UDI_CDC_DATA_EPS_FS_SIZE CDC_RX_SIZE
 
 //@}
 
@@ -335,42 +335,42 @@ int udi_cdc_multi_putc(uint8_t port, int value);
 iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t size);
 //@}
 
-#define CDC_PRINTBUF_SIZE  256
+#    define CDC_PRINTBUF_SIZE 256
 extern char printbuf[CDC_PRINTBUF_SIZE];
 
-#define CDC_INBUF_SIZE 256
+#    define CDC_INBUF_SIZE 256
 
 typedef struct {
     uint32_t count;
     uint32_t lastcount;
-    char buf[CDC_INBUF_SIZE];
+    char     buf[CDC_INBUF_SIZE];
 } inbuf_t;
 
-#else //CDC
+#else  // CDC
 
 // keep these to accommodate calls if remaining
-#define CDC_PRINTBUF_SIZE  1
+#    define CDC_PRINTBUF_SIZE 1
 extern char printbuf[CDC_PRINTBUF_SIZE];
 
-#define CDC_INBUF_SIZE 1
+#    define CDC_INBUF_SIZE 1
 
 typedef struct {
     uint32_t count;
     uint32_t lastcount;
-    char buf[CDC_INBUF_SIZE];
+    char     buf[CDC_INBUF_SIZE];
 } inbuf_t;
 
 extern inbuf_t inbuf;
 
-#endif //CDC
+#endif  // CDC
 
-uint32_t CDC_print(char *printbuf);
-int CDC_printf(const char *_Format, ...);
+uint32_t CDC_print(charprintbuf);
+int      CDC_printf(const char* _Format, ...);
 uint32_t CDC_input(void);
-void CDC_init(void);
+void     CDC_init(void);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif // _UDI_CDC_H_
+#endif  // _UDI_CDC_H_
index 2db61fab54d668ecac5f7e37ce4030c206c2838d..e0795124926254b3ca0cd5ce92beef9712dce722 100644 (file)
 #include "conf_usb.h"
 #include "udi_device_conf.h"
 
-#ifndef  UDI_CDC_PORT_NB
-#define  UDI_CDC_PORT_NB 1
+#ifndef UDI_CDC_PORT_NB
+#    define UDI_CDC_PORT_NB 1
 #endif
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#define  UDI_CDC_DATA_EP_IN_0   ((CDC_TX_ENDPOINT) | (USB_EP_DIR_IN)) //TX
-#define  UDI_CDC_DATA_EP_OUT_0  ((CDC_RX_ENDPOINT) | (USB_EP_DIR_OUT)) // RX
-#define  UDI_CDC_COMM_EP_0      ((CDC_ACM_ENDPOINT) | (USB_EP_DIR_IN))  // Notify endpoint
+#define UDI_CDC_DATA_EP_IN_0 ((CDC_TX_ENDPOINT) | (USB_EP_DIR_IN))    // TX
+#define UDI_CDC_DATA_EP_OUT_0 ((CDC_RX_ENDPOINT) | (USB_EP_DIR_OUT))  // RX
+#define UDI_CDC_COMM_EP_0 ((CDC_ACM_ENDPOINT) | (USB_EP_DIR_IN))      // Notify endpoint
 
-#define  UDI_CDC_COMM_IFACE_NUMBER_0   (CDC_STATUS_INTERFACE)
-#define  UDI_CDC_DATA_IFACE_NUMBER_0   (CDC_DATA_INTERFACE)
+#define UDI_CDC_COMM_IFACE_NUMBER_0 (CDC_STATUS_INTERFACE)
+#define UDI_CDC_DATA_IFACE_NUMBER_0 (CDC_DATA_INTERFACE)
 
 #ifdef __cplusplus
 }
 #endif
-#endif // _UDI_CDC_CONF_H_
+#endif  // _UDI_CDC_CONF_H_
index 1e82b9eccbb0cc3f7eb1b7a484b0a6185c967a37..f22f5003abadf128f5f519b329bcae9c501120a6 100644 (file)
@@ -31,27 +31,27 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 //#define MOUSE_ENABLE //rules.mk
 #ifdef MOUSE_ENABLE
-#define MOU
+#    define MOU
 #endif
 
 //#define EXTRAKEY_ENABLE //rules.mk
 #ifdef EXTRAKEY_ENABLE
-#define EXK
+#    define EXK
 #endif
 
 //#define RAW_ENABLE //rules.mk
 #ifdef RAW_ENABLE
-#define RAW
+#    define RAW
 #endif
 
 //#define CONSOLE_ENABLE //rules.mk
 #ifdef CONSOLE_ENABLE
-#define CON
+#    define CON
 #endif
 
 //#define NKRO_ENABLE //rules.mk
 #ifdef NKRO_ENABLE
-#define NKRO
+#    define NKRO
 #endif
 
 //#define MIDI_ENABLE //deferred implementation
@@ -61,229 +61,227 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 //#define VIRTSER_ENABLE //rules.mk
 #ifdef VIRTSER_ENABLE
-#define CDC
-//because CDC uses IAD (interface association descriptor
-//per USB Interface Association Descriptor Device Class Code and Use Model 7/23/2003 Rev 1.0)
-#undef DEVICE_CLASS
-#define DEVICE_CLASS 0xEF
-#undef DEVICE_SUBCLASS
-#define DEVICE_SUBCLASS 0x02
-#undef DEVICE_PROTOCOL
-#define DEVICE_PROTOCOL 0x01
+#    define CDC
+// because CDC uses IAD (interface association descriptor
+// per USB Interface Association Descriptor Device Class Code and Use Model 7/23/2003 Rev 1.0)
+#    undef DEVICE_CLASS
+#    define DEVICE_CLASS 0xEF
+#    undef DEVICE_SUBCLASS
+#    define DEVICE_SUBCLASS 0x02
+#    undef DEVICE_PROTOCOL
+#    define DEVICE_PROTOCOL 0x01
 #endif
 
 /* number of interfaces */
-#define NEXT_INTERFACE_0            0
+#define NEXT_INTERFACE_0 0
 
 #ifdef KBD
-#define KEYBOARD_INTERFACE          NEXT_INTERFACE_0
-#define NEXT_INTERFACE_1            (KEYBOARD_INTERFACE + 1)
-#define UDI_HID_KBD_IFACE_NUMBER    KEYBOARD_INTERFACE
+#    define KEYBOARD_INTERFACE NEXT_INTERFACE_0
+#    define NEXT_INTERFACE_1 (KEYBOARD_INTERFACE + 1)
+#    define UDI_HID_KBD_IFACE_NUMBER KEYBOARD_INTERFACE
 #else
-#define NEXT_INTERFACE_1            NEXT_INTERFACE_0
+#    define NEXT_INTERFACE_1 NEXT_INTERFACE_0
 #endif
 
 // It is important that the Raw HID interface is at a constant
 // interface number, to support Linux/OSX platforms and chrome.hid
 // If Raw HID is enabled, let it be always 1.
 #ifdef RAW
-#define RAW_INTERFACE               NEXT_INTERFACE_1
-#define NEXT_INTERFACE_2            (RAW_INTERFACE + 1)
+#    define RAW_INTERFACE NEXT_INTERFACE_1
+#    define NEXT_INTERFACE_2 (RAW_INTERFACE + 1)
 #else
-#define NEXT_INTERFACE_2            NEXT_INTERFACE_1
+#    define NEXT_INTERFACE_2 NEXT_INTERFACE_1
 #endif
 
 #ifdef MOU
-#define MOUSE_INTERFACE             NEXT_INTERFACE_2
-#define UDI_HID_MOU_IFACE_NUMBER    MOUSE_INTERFACE
-#define NEXT_INTERFACE_3            (MOUSE_INTERFACE + 1)
+#    define MOUSE_INTERFACE NEXT_INTERFACE_2
+#    define UDI_HID_MOU_IFACE_NUMBER MOUSE_INTERFACE
+#    define NEXT_INTERFACE_3 (MOUSE_INTERFACE + 1)
 #else
-#define NEXT_INTERFACE_3            NEXT_INTERFACE_2
+#    define NEXT_INTERFACE_3 NEXT_INTERFACE_2
 #endif
 
 #ifdef EXK
-#define EXTRAKEY_INTERFACE          NEXT_INTERFACE_3
-#define NEXT_INTERFACE_4            (EXTRAKEY_INTERFACE + 1)
-#define UDI_HID_EXK_IFACE_NUMBER    EXTRAKEY_INTERFACE
+#    define EXTRAKEY_INTERFACE NEXT_INTERFACE_3
+#    define NEXT_INTERFACE_4 (EXTRAKEY_INTERFACE + 1)
+#    define UDI_HID_EXK_IFACE_NUMBER EXTRAKEY_INTERFACE
 #else
-#define NEXT_INTERFACE_4            NEXT_INTERFACE_3
+#    define NEXT_INTERFACE_4 NEXT_INTERFACE_3
 #endif
 
 #ifdef CON
-#define CON_INTERFACE               NEXT_INTERFACE_4
-#define NEXT_INTERFACE_5            (CON_INTERFACE + 1)
-#define UDI_HID_CON_IFACE_NUMBER    CON_INTERFACE
+#    define CON_INTERFACE NEXT_INTERFACE_4
+#    define NEXT_INTERFACE_5 (CON_INTERFACE + 1)
+#    define UDI_HID_CON_IFACE_NUMBER CON_INTERFACE
 #else
-#define NEXT_INTERFACE_5            NEXT_INTERFACE_4
+#    define NEXT_INTERFACE_5 NEXT_INTERFACE_4
 #endif
 
 #ifdef NKRO
-#define NKRO_INTERFACE              NEXT_INTERFACE_5
-#define NEXT_INTERFACE_6            (NKRO_INTERFACE + 1)
-#define UDI_HID_NKRO_IFACE_NUMBER   NKRO_INTERFACE
+#    define NKRO_INTERFACE NEXT_INTERFACE_5
+#    define NEXT_INTERFACE_6 (NKRO_INTERFACE + 1)
+#    define UDI_HID_NKRO_IFACE_NUMBER NKRO_INTERFACE
 #else
-#define NEXT_INTERFACE_6            NEXT_INTERFACE_5
+#    define NEXT_INTERFACE_6 NEXT_INTERFACE_5
 #endif
 
 #ifdef MIDI
-#define AC_INTERFACE                NEXT_INTERFACE_6
-#define AS_INTERFACE                (AC_INTERFACE + 1)
-#define NEXT_INTERFACE_7            (AS_INTERFACE + 1)
+#    define AC_INTERFACE NEXT_INTERFACE_6
+#    define AS_INTERFACE (AC_INTERFACE + 1)
+#    define NEXT_INTERFACE_7 (AS_INTERFACE + 1)
 #else
-#define NEXT_INTERFACE_7            NEXT_INTERFACE_6
+#    define NEXT_INTERFACE_7 NEXT_INTERFACE_6
 #endif
 
 #ifdef CDC
-#define CCI_INTERFACE               NEXT_INTERFACE_7
-#define CDI_INTERFACE               (CCI_INTERFACE + 1)
-#define NEXT_INTERFACE_8            (CDI_INTERFACE + 1)
-#define CDC_STATUS_INTERFACE        CCI_INTERFACE
-#define CDC_DATA_INTERFACE          CDI_INTERFACE
+#    define CCI_INTERFACE NEXT_INTERFACE_7
+#    define CDI_INTERFACE (CCI_INTERFACE + 1)
+#    define NEXT_INTERFACE_8 (CDI_INTERFACE + 1)
+#    define CDC_STATUS_INTERFACE CCI_INTERFACE
+#    define CDC_DATA_INTERFACE CDI_INTERFACE
 #else
-#define NEXT_INTERFACE_8            NEXT_INTERFACE_7
+#    define NEXT_INTERFACE_8 NEXT_INTERFACE_7
 #endif
 
 /* nubmer of interfaces */
-#define TOTAL_INTERFACES            NEXT_INTERFACE_8
-#define USB_DEVICE_NB_INTERFACE     TOTAL_INTERFACES
-
+#define TOTAL_INTERFACES NEXT_INTERFACE_8
+#define USB_DEVICE_NB_INTERFACE TOTAL_INTERFACES
 
 // **********************************************************************
 // Endopoint number and size
 // **********************************************************************
-#define USB_DEVICE_EP_CTRL_SIZE     8
+#define USB_DEVICE_EP_CTRL_SIZE 8
 
-#define NEXT_IN_EPNUM_0             1
-#define NEXT_OUT_EPNUM_0            1
+#define NEXT_IN_EPNUM_0 1
+#define NEXT_OUT_EPNUM_0 1
 
 #ifdef KBD
-#define KEYBOARD_IN_EPNUM           NEXT_IN_EPNUM_0
-#define UDI_HID_KBD_EP_IN           KEYBOARD_IN_EPNUM
-#define NEXT_IN_EPNUM_1             (KEYBOARD_IN_EPNUM + 1)
-#define UDI_HID_KBD_EP_SIZE         KEYBOARD_EPSIZE
-#define KBD_POLLING_INTERVAL        10
-#ifndef UDI_HID_KBD_STRING_ID
-#define UDI_HID_KBD_STRING_ID       0
-#endif
+#    define KEYBOARD_IN_EPNUM NEXT_IN_EPNUM_0
+#    define UDI_HID_KBD_EP_IN KEYBOARD_IN_EPNUM
+#    define NEXT_IN_EPNUM_1 (KEYBOARD_IN_EPNUM + 1)
+#    define UDI_HID_KBD_EP_SIZE KEYBOARD_EPSIZE
+#    define KBD_POLLING_INTERVAL 10
+#    ifndef UDI_HID_KBD_STRING_ID
+#        define UDI_HID_KBD_STRING_ID 0
+#    endif
 #else
-#define NEXT_IN_EPNUM_1             NEXT_IN_EPNUM_0
+#    define NEXT_IN_EPNUM_1 NEXT_IN_EPNUM_0
 #endif
 
 #ifdef MOU
-#define MOUSE_IN_EPNUM              NEXT_IN_EPNUM_1
-#define NEXT_IN_EPNUM_2             (MOUSE_IN_EPNUM + 1)
-#define UDI_HID_MOU_EP_IN           MOUSE_IN_EPNUM
-#define UDI_HID_MOU_EP_SIZE         MOUSE_EPSIZE
-#define MOU_POLLING_INTERVAL        10
-#ifndef UDI_HID_MOU_STRING_ID
-#define UDI_HID_MOU_STRING_ID       0
-#endif
+#    define MOUSE_IN_EPNUM NEXT_IN_EPNUM_1
+#    define NEXT_IN_EPNUM_2 (MOUSE_IN_EPNUM + 1)
+#    define UDI_HID_MOU_EP_IN MOUSE_IN_EPNUM
+#    define UDI_HID_MOU_EP_SIZE MOUSE_EPSIZE
+#    define MOU_POLLING_INTERVAL 10
+#    ifndef UDI_HID_MOU_STRING_ID
+#        define UDI_HID_MOU_STRING_ID 0
+#    endif
 #else
-#define NEXT_IN_EPNUM_2             NEXT_IN_EPNUM_1
+#    define NEXT_IN_EPNUM_2 NEXT_IN_EPNUM_1
 #endif
 
 #ifdef EXK
-#define EXTRAKEY_IN_EPNUM           NEXT_IN_EPNUM_2
-#define UDI_HID_EXK_EP_IN           EXTRAKEY_IN_EPNUM
-#define NEXT_IN_EPNUM_3             (EXTRAKEY_IN_EPNUM + 1)
-#define UDI_HID_EXK_EP_SIZE         EXTRAKEY_EPSIZE
-#define EXTRAKEY_POLLING_INTERVAL   10
-#ifndef UDI_HID_EXK_STRING_ID
-#define UDI_HID_EXK_STRING_ID       0
-#endif
+#    define EXTRAKEY_IN_EPNUM NEXT_IN_EPNUM_2
+#    define UDI_HID_EXK_EP_IN EXTRAKEY_IN_EPNUM
+#    define NEXT_IN_EPNUM_3 (EXTRAKEY_IN_EPNUM + 1)
+#    define UDI_HID_EXK_EP_SIZE EXTRAKEY_EPSIZE
+#    define EXTRAKEY_POLLING_INTERVAL 10
+#    ifndef UDI_HID_EXK_STRING_ID
+#        define UDI_HID_EXK_STRING_ID 0
+#    endif
 #else
-#define NEXT_IN_EPNUM_3             NEXT_IN_EPNUM_2
+#    define NEXT_IN_EPNUM_3 NEXT_IN_EPNUM_2
 #endif
 
 #ifdef RAW
-#define RAW_IN_EPNUM                NEXT_IN_EPNUM_3
-#define UDI_HID_RAW_EP_IN           RAW_IN_EPNUM
-#define NEXT_IN_EPNUM_4             (RAW_IN_EPNUM + 1)
-#define RAW_OUT_EPNUM               NEXT_OUT_EPNUM_0
-#define UDI_HID_RAW_EP_OUT          RAW_OUT_EPNUM
-#define NEXT_OUT_EPNUM_1            (RAW_OUT_EPNUM + 1)
-#define RAW_POLLING_INTERVAL        1
-#ifndef UDI_HID_RAW_STRING_ID
-#define UDI_HID_RAW_STRING_ID       0
-#endif
+#    define RAW_IN_EPNUM NEXT_IN_EPNUM_3
+#    define UDI_HID_RAW_EP_IN RAW_IN_EPNUM
+#    define NEXT_IN_EPNUM_4 (RAW_IN_EPNUM + 1)
+#    define RAW_OUT_EPNUM NEXT_OUT_EPNUM_0
+#    define UDI_HID_RAW_EP_OUT RAW_OUT_EPNUM
+#    define NEXT_OUT_EPNUM_1 (RAW_OUT_EPNUM + 1)
+#    define RAW_POLLING_INTERVAL 1
+#    ifndef UDI_HID_RAW_STRING_ID
+#        define UDI_HID_RAW_STRING_ID 0
+#    endif
 #else
-#define NEXT_IN_EPNUM_4             NEXT_IN_EPNUM_3
-#define NEXT_OUT_EPNUM_1            NEXT_OUT_EPNUM_0
+#    define NEXT_IN_EPNUM_4 NEXT_IN_EPNUM_3
+#    define NEXT_OUT_EPNUM_1 NEXT_OUT_EPNUM_0
 #endif
 
 #ifdef CON
-#define CON_IN_EPNUM                NEXT_IN_EPNUM_4
-#define UDI_HID_CON_EP_IN           CON_IN_EPNUM
-#define NEXT_IN_EPNUM_5             (CON_IN_EPNUM + 1)
-#define CON_OUT_EPNUM               NEXT_OUT_EPNUM_1
-#define UDI_HID_CON_EP_OUT          CON_OUT_EPNUM
-#define NEXT_OUT_EPNUM_2            (CON_OUT_EPNUM + 1)
-#define CON_POLLING_INTERVAL        1
-#ifndef UDI_HID_CON_STRING_ID
-#define UDI_HID_CON_STRING_ID       0
-#endif
+#    define CON_IN_EPNUM NEXT_IN_EPNUM_4
+#    define UDI_HID_CON_EP_IN CON_IN_EPNUM
+#    define NEXT_IN_EPNUM_5 (CON_IN_EPNUM + 1)
+#    define CON_OUT_EPNUM NEXT_OUT_EPNUM_1
+#    define UDI_HID_CON_EP_OUT CON_OUT_EPNUM
+#    define NEXT_OUT_EPNUM_2 (CON_OUT_EPNUM + 1)
+#    define CON_POLLING_INTERVAL 1
+#    ifndef UDI_HID_CON_STRING_ID
+#        define UDI_HID_CON_STRING_ID 0
+#    endif
 #else
-#define NEXT_IN_EPNUM_5             NEXT_IN_EPNUM_4
-#define NEXT_OUT_EPNUM_2            NEXT_OUT_EPNUM_1
+#    define NEXT_IN_EPNUM_5 NEXT_IN_EPNUM_4
+#    define NEXT_OUT_EPNUM_2 NEXT_OUT_EPNUM_1
 #endif
 
 #ifdef NKRO
-#define NKRO_IN_EPNUM               NEXT_IN_EPNUM_5
-#define UDI_HID_NKRO_EP_IN          NKRO_IN_EPNUM
-#define NEXT_IN_EPNUM_6             (NKRO_IN_EPNUM + 1)
-#define UDI_HID_NKRO_EP_SIZE        NKRO_EPSIZE
-#define NKRO_POLLING_INTERVAL       1
-#ifndef UDI_HID_NKRO_STRING_ID
-#define UDI_HID_NKRO_STRING_ID      0
-#endif
+#    define NKRO_IN_EPNUM NEXT_IN_EPNUM_5
+#    define UDI_HID_NKRO_EP_IN NKRO_IN_EPNUM
+#    define NEXT_IN_EPNUM_6 (NKRO_IN_EPNUM + 1)
+#    define UDI_HID_NKRO_EP_SIZE NKRO_EPSIZE
+#    define NKRO_POLLING_INTERVAL 1
+#    ifndef UDI_HID_NKRO_STRING_ID
+#        define UDI_HID_NKRO_STRING_ID 0
+#    endif
 #else
-#define NEXT_IN_EPNUM_6             NEXT_IN_EPNUM_5
+#    define NEXT_IN_EPNUM_6 NEXT_IN_EPNUM_5
 #endif
 
 #ifdef MIDI
-#define MIDI_STREAM_IN_EPNUM        NEXT_IN_EPNUM_6
-#define NEXT_IN_EPNUM_7             (MIDI_STREAM_IN_EPNUM + 1)
-#define MIDI_STREAM_OUT_EPNUM       NEXT_OUT_EPNUM_2
-#define NEXT_OUT_EPNUM_3            (MIDI_STREAM_OUT_EPNUM + 1)
-#define MIDI_POLLING_INTERVAL       5
+#    define MIDI_STREAM_IN_EPNUM NEXT_IN_EPNUM_6
+#    define NEXT_IN_EPNUM_7 (MIDI_STREAM_IN_EPNUM + 1)
+#    define MIDI_STREAM_OUT_EPNUM NEXT_OUT_EPNUM_2
+#    define NEXT_OUT_EPNUM_3 (MIDI_STREAM_OUT_EPNUM + 1)
+#    define MIDI_POLLING_INTERVAL 5
 #else
-#define NEXT_IN_EPNUM_7             NEXT_IN_EPNUM_6
-#define NEXT_OUT_EPNUM_3            NEXT_OUT_EPNUM_2
+#    define NEXT_IN_EPNUM_7 NEXT_IN_EPNUM_6
+#    define NEXT_OUT_EPNUM_3 NEXT_OUT_EPNUM_2
 #endif
 
 #ifdef CDC
-#define CDC_NOTIFICATION_EPNUM      NEXT_IN_EPNUM_7
-#define CDC_ACM_ENDPOINT            CDC_NOTIFICATION_EPNUM
-#define CDC_TX_ENDPOINT             (CDC_NOTIFICATION_EPNUM + 1)
-#define NEXT_IN_EPNUM_8             (CDC_TX_ENDPOINT + 1)
-
-#define CDC_OUT_EPNUM               NEXT_OUT_EPNUM_3
-#define CDC_RX_ENDPOINT             CDC_OUT_EPNUM
-#define NEXT_OUT_EPNUM_4            (CDC_OUT_EPNUM + 1)
-
-#define CDC_ACM_SIZE                CDC_NOTIFICATION_EPSIZE
-#define CDC_RX_SIZE                 CDC_EPSIZE  //KFSMOD was 64
-#define CDC_TX_SIZE                 CDC_RX_SIZE
-#define CDC_ACM_POLLING_INTERVAL    255
-#define CDC_EP_INTERVAL_STATUS      CDC_ACM_POLLING_INTERVAL
-#define CDC_DATA_POLLING_INTERVAL   5
-#define CDC_EP_INTERVAL_DATA        CDC_DATA_POLLING_INTERVAL
-#define CDC_STATUS_NAME             L"Virtual Serial Port - Status"
-#define CDC_DATA_NAME               L"Virtual Serial Port - Data"
+#    define CDC_NOTIFICATION_EPNUM NEXT_IN_EPNUM_7
+#    define CDC_ACM_ENDPOINT CDC_NOTIFICATION_EPNUM
+#    define CDC_TX_ENDPOINT (CDC_NOTIFICATION_EPNUM + 1)
+#    define NEXT_IN_EPNUM_8 (CDC_TX_ENDPOINT + 1)
+
+#    define CDC_OUT_EPNUM NEXT_OUT_EPNUM_3
+#    define CDC_RX_ENDPOINT CDC_OUT_EPNUM
+#    define NEXT_OUT_EPNUM_4 (CDC_OUT_EPNUM + 1)
+
+#    define CDC_ACM_SIZE CDC_NOTIFICATION_EPSIZE
+#    define CDC_RX_SIZE CDC_EPSIZE  // KFSMOD was 64
+#    define CDC_TX_SIZE CDC_RX_SIZE
+#    define CDC_ACM_POLLING_INTERVAL 255
+#    define CDC_EP_INTERVAL_STATUS CDC_ACM_POLLING_INTERVAL
+#    define CDC_DATA_POLLING_INTERVAL 5
+#    define CDC_EP_INTERVAL_DATA CDC_DATA_POLLING_INTERVAL
+#    define CDC_STATUS_NAME L"Virtual Serial Port - Status"
+#    define CDC_DATA_NAME L"Virtual Serial Port - Data"
 #else
-#define NEXT_IN_EPNUM_8             NEXT_IN_EPNUM_7
-#define NEXT_OUT_EPNUM_4            NEXT_OUT_EPNUM_3
+#    define NEXT_IN_EPNUM_8 NEXT_IN_EPNUM_7
+#    define NEXT_OUT_EPNUM_4 NEXT_OUT_EPNUM_3
 #endif
 
-#define TOTAL_OUT_EP                NEXT_OUT_EPNUM_4
-#define TOTAL_IN_EP                 NEXT_IN_EPNUM_8
-#define USB_DEVICE_MAX_EP           (max(NEXT_OUT_EPNUM_4, NEXT_IN_EPNUM_8))
+#define TOTAL_OUT_EP NEXT_OUT_EPNUM_4
+#define TOTAL_IN_EP NEXT_IN_EPNUM_8
+#define USB_DEVICE_MAX_EP (max(NEXT_OUT_EPNUM_4, NEXT_IN_EPNUM_8))
 
 #if USB_DEVICE_MAX_EP > 8
-#error "There are not enough available endpoints to support all functions. Remove some in the rules.mk file.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, VIRTSER)"
+#    error "There are not enough available endpoints to support all functions. Remove some in the rules.mk file.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, VIRTSER)"
 #endif
 
-
 // **********************************************************************
 // KBD Descriptor structure and content
 // **********************************************************************
@@ -292,50 +290,28 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 COMPILER_PACK_SET(1)
 
 typedef struct {
-    usb_iface_desc_t iface;
+    usb_iface_desc_t     iface;
     usb_hid_descriptor_t hid;
-    usb_ep_desc_t ep;
+    usb_ep_desc_t        ep;
 } udi_hid_kbd_desc_t;
 
 typedef struct {
     uint8_t array[59];
 } udi_hid_kbd_report_desc_t;
 
-#define UDI_HID_KBD_DESC {\
-    .iface.bLength             = sizeof(usb_iface_desc_t),\
-    .iface.bDescriptorType     = USB_DT_INTERFACE,\
-    .iface.bInterfaceNumber    = UDI_HID_KBD_IFACE_NUMBER,\
-    .iface.bAlternateSetting   = 0,\
-    .iface.bNumEndpoints       = 1,\
-    .iface.bInterfaceClass     = HID_CLASS,\
-    .iface.bInterfaceSubClass  = HID_SUB_CLASS_BOOT,\
-    .iface.bInterfaceProtocol  = HID_PROTOCOL_KEYBOARD,\
-    .iface.iInterface          = UDI_HID_KBD_STRING_ID,\
-    .hid.bLength               = sizeof(usb_hid_descriptor_t),\
-    .hid.bDescriptorType       = USB_DT_HID,\
-    .hid.bcdHID                = LE16(USB_HID_BDC_V1_11),\
-    .hid.bCountryCode          = USB_HID_NO_COUNTRY_CODE,\
-    .hid.bNumDescriptors       = USB_HID_NUM_DESC,\
-    .hid.bRDescriptorType      = USB_DT_HID_REPORT,\
-    .hid.wDescriptorLength     = LE16(sizeof(udi_hid_kbd_report_desc_t)),\
-    .ep.bLength                = sizeof(usb_ep_desc_t),\
-    .ep.bDescriptorType        = USB_DT_ENDPOINT,\
-    .ep.bEndpointAddress       = UDI_HID_KBD_EP_IN | USB_EP_DIR_IN,\
-    .ep.bmAttributes           = USB_EP_TYPE_INTERRUPT,\
-    .ep.wMaxPacketSize         = LE16(UDI_HID_KBD_EP_SIZE),\
-    .ep.bInterval              = KBD_POLLING_INTERVAL,\
-}
-
-//set report buffer (from host)
+#    define UDI_HID_KBD_DESC \
+        { .iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = UDI_HID_KBD_IFACE_NUMBER, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 1, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_BOOT, .iface.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD, .iface.iInterface = UDI_HID_KBD_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_kbd_report_desc_t)), .ep.bLength = sizeof(usb_ep_desc_t), .ep.bDescriptorType = USB_DT_ENDPOINT, .ep.bEndpointAddress = UDI_HID_KBD_EP_IN | USB_EP_DIR_IN, .ep.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep.wMaxPacketSize = LE16(UDI_HID_KBD_EP_SIZE), .ep.bInterval = KBD_POLLING_INTERVAL, }
+
+// set report buffer (from host)
 extern uint8_t udi_hid_kbd_report_set;
 
-//report buffer (to host)
-#define UDI_HID_KBD_REPORT_SIZE 8
+// report buffer (to host)
+#    define UDI_HID_KBD_REPORT_SIZE 8
 extern uint8_t udi_hid_kbd_report[UDI_HID_KBD_REPORT_SIZE];
 
 COMPILER_PACK_RESET()
 
-#endif //KBD
+#endif  // KBD
 
 // **********************************************************************
 // EXK Descriptor structure and content
@@ -345,59 +321,37 @@ COMPILER_PACK_RESET()
 COMPILER_PACK_SET(1)
 
 typedef struct {
-    usb_iface_desc_t iface;
+    usb_iface_desc_t     iface;
     usb_hid_descriptor_t hid;
-    usb_ep_desc_t ep;
+    usb_ep_desc_t        ep;
 } udi_hid_exk_desc_t;
 
 typedef struct {
     uint8_t array[54];
 } udi_hid_exk_report_desc_t;
 
-#define UDI_HID_EXK_DESC {\
-    .iface.bLength             = sizeof(usb_iface_desc_t),\
-    .iface.bDescriptorType     = USB_DT_INTERFACE,\
-    .iface.bInterfaceNumber    = UDI_HID_EXK_IFACE_NUMBER,\
-    .iface.bAlternateSetting   = 0,\
-    .iface.bNumEndpoints       = 1,\
-    .iface.bInterfaceClass     = HID_CLASS,\
-    .iface.bInterfaceSubClass  = HID_SUB_CLASS_BOOT,\
-    .iface.bInterfaceProtocol  = HID_PROTOCOL_GENERIC,\
-    .iface.iInterface          = UDI_HID_EXK_STRING_ID,\
-    .hid.bLength               = sizeof(usb_hid_descriptor_t),\
-    .hid.bDescriptorType       = USB_DT_HID,\
-    .hid.bcdHID                = LE16(USB_HID_BDC_V1_11),\
-    .hid.bCountryCode          = USB_HID_NO_COUNTRY_CODE,\
-    .hid.bNumDescriptors       = USB_HID_NUM_DESC,\
-    .hid.bRDescriptorType      = USB_DT_HID_REPORT,\
-    .hid.wDescriptorLength     = LE16(sizeof(udi_hid_exk_report_desc_t)),\
-    .ep.bLength                = sizeof(usb_ep_desc_t),\
-    .ep.bDescriptorType        = USB_DT_ENDPOINT,\
-    .ep.bEndpointAddress       = UDI_HID_EXK_EP_IN | USB_EP_DIR_IN,\
-    .ep.bmAttributes           = USB_EP_TYPE_INTERRUPT,\
-    .ep.wMaxPacketSize         = LE16(UDI_HID_EXK_EP_SIZE),\
-    .ep.bInterval              = EXTRAKEY_POLLING_INTERVAL,\
-}
-
-//set report buffer (from host)
+#    define UDI_HID_EXK_DESC \
+        { .iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = UDI_HID_EXK_IFACE_NUMBER, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 1, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_BOOT, .iface.bInterfaceProtocol = HID_PROTOCOL_GENERIC, .iface.iInterface = UDI_HID_EXK_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_exk_report_desc_t)), .ep.bLength = sizeof(usb_ep_desc_t), .ep.bDescriptorType = USB_DT_ENDPOINT, .ep.bEndpointAddress = UDI_HID_EXK_EP_IN | USB_EP_DIR_IN, .ep.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep.wMaxPacketSize = LE16(UDI_HID_EXK_EP_SIZE), .ep.bInterval = EXTRAKEY_POLLING_INTERVAL, }
+
+// set report buffer (from host)
 extern uint8_t udi_hid_exk_report_set;
 
-//report buffer
-#define UDI_HID_EXK_REPORT_SIZE 3
+// report buffer
+#    define UDI_HID_EXK_REPORT_SIZE 3
 
 typedef union {
-  struct {
-    uint8_t report_id;
-    uint16_t report_data;
- } desc;
- uint8_t raw[UDI_HID_EXK_REPORT_SIZE];
+    struct {
+        uint8_t  report_id;
+        uint16_t report_data;
   } desc;
   uint8_t raw[UDI_HID_EXK_REPORT_SIZE];
 } udi_hid_exk_report_t;
 
 extern udi_hid_exk_report_t udi_hid_exk_report;
 
 COMPILER_PACK_RESET()
 
-#endif //EXK
+#endif  // EXK
 
 // **********************************************************************
 // NKRO Descriptor structure and content
@@ -407,50 +361,28 @@ COMPILER_PACK_RESET()
 COMPILER_PACK_SET(1)
 
 typedef struct {
-    usb_iface_desc_t iface;
+    usb_iface_desc_t     iface;
     usb_hid_descriptor_t hid;
-    usb_ep_desc_t ep;
+    usb_ep_desc_t        ep;
 } udi_hid_nkro_desc_t;
 
 typedef struct {
     uint8_t array[57];
 } udi_hid_nkro_report_desc_t;
 
-#define UDI_HID_NKRO_DESC {\
-    .iface.bLength             = sizeof(usb_iface_desc_t),\
-    .iface.bDescriptorType     = USB_DT_INTERFACE,\
-    .iface.bInterfaceNumber    = UDI_HID_NKRO_IFACE_NUMBER,\
-    .iface.bAlternateSetting   = 0,\
-    .iface.bNumEndpoints       = 1,\
-    .iface.bInterfaceClass     = HID_CLASS,\
-    .iface.bInterfaceSubClass  = HID_SUB_CLASS_NOBOOT,\
-    .iface.bInterfaceProtocol  = HID_PROTOCOL_KEYBOARD,\
-    .iface.iInterface          = UDI_HID_NKRO_STRING_ID,\
-    .hid.bLength               = sizeof(usb_hid_descriptor_t),\
-    .hid.bDescriptorType       = USB_DT_HID,\
-    .hid.bcdHID                = LE16(USB_HID_BDC_V1_11),\
-    .hid.bCountryCode          = USB_HID_NO_COUNTRY_CODE,\
-    .hid.bNumDescriptors       = USB_HID_NUM_DESC,\
-    .hid.bRDescriptorType      = USB_DT_HID_REPORT,\
-    .hid.wDescriptorLength     = LE16(sizeof(udi_hid_nkro_report_desc_t)),\
-    .ep.bLength                = sizeof(usb_ep_desc_t),\
-    .ep.bDescriptorType        = USB_DT_ENDPOINT,\
-    .ep.bEndpointAddress       = UDI_HID_NKRO_EP_IN | USB_EP_DIR_IN,\
-    .ep.bmAttributes           = USB_EP_TYPE_INTERRUPT,\
-    .ep.wMaxPacketSize         = LE16(UDI_HID_NKRO_EP_SIZE),\
-    .ep.bInterval              = NKRO_POLLING_INTERVAL,\
-}
-
-//set report buffer
+#    define UDI_HID_NKRO_DESC \
+        { .iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = UDI_HID_NKRO_IFACE_NUMBER, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 1, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT, .iface.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD, .iface.iInterface = UDI_HID_NKRO_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_nkro_report_desc_t)), .ep.bLength = sizeof(usb_ep_desc_t), .ep.bDescriptorType = USB_DT_ENDPOINT, .ep.bEndpointAddress = UDI_HID_NKRO_EP_IN | USB_EP_DIR_IN, .ep.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep.wMaxPacketSize = LE16(UDI_HID_NKRO_EP_SIZE), .ep.bInterval = NKRO_POLLING_INTERVAL, }
+
+// set report buffer
 extern uint8_t udi_hid_nkro_report_set;
 
-//report buffer
-#define UDI_HID_NKRO_REPORT_SIZE 32
+// report buffer
+#    define UDI_HID_NKRO_REPORT_SIZE 32
 extern uint8_t udi_hid_nkro_report[UDI_HID_NKRO_REPORT_SIZE];
 
 COMPILER_PACK_RESET()
 
-#endif //NKRO
+#endif  // NKRO
 
 // **********************************************************************
 // MOU Descriptor structure and content
@@ -460,49 +392,27 @@ COMPILER_PACK_RESET()
 COMPILER_PACK_SET(1)
 
 typedef struct {
-    usb_iface_desc_t iface;
+    usb_iface_desc_t     iface;
     usb_hid_descriptor_t hid;
-    usb_ep_desc_t ep;
+    usb_ep_desc_t        ep;
 } udi_hid_mou_desc_t;
 
 typedef struct {
-    uint8_t array[77];//MOU PDS
+    uint8_t array[77];  // MOU PDS
 } udi_hid_mou_report_desc_t;
 
-#define UDI_HID_MOU_DESC {\
-    .iface.bLength             = sizeof(usb_iface_desc_t),\
-    .iface.bDescriptorType     = USB_DT_INTERFACE,\
-    .iface.bInterfaceNumber    = MOUSE_INTERFACE,\
-    .iface.bAlternateSetting   = 0,\
-    .iface.bNumEndpoints       = 1,\
-    .iface.bInterfaceClass     = HID_CLASS,\
-    .iface.bInterfaceSubClass  = HID_SUB_CLASS_BOOT,\
-    .iface.bInterfaceProtocol  = HID_PROTOCOL_MOUSE,\
-    .iface.iInterface          = UDI_HID_MOU_STRING_ID,\
-    .hid.bLength               = sizeof(usb_hid_descriptor_t),\
-    .hid.bDescriptorType       = USB_DT_HID,\
-    .hid.bcdHID                = LE16(USB_HID_BDC_V1_11),\
-    .hid.bCountryCode          = USB_HID_NO_COUNTRY_CODE,\
-    .hid.bNumDescriptors       = USB_HID_NUM_DESC,\
-    .hid.bRDescriptorType      = USB_DT_HID_REPORT,\
-    .hid.wDescriptorLength     = LE16(sizeof(udi_hid_mou_report_desc_t)),\
-    .ep.bLength                = sizeof(usb_ep_desc_t),\
-    .ep.bDescriptorType        = USB_DT_ENDPOINT,\
-    .ep.bEndpointAddress       = UDI_HID_MOU_EP_IN | USB_EP_DIR_IN,\
-    .ep.bmAttributes           = USB_EP_TYPE_INTERRUPT,\
-    .ep.wMaxPacketSize         = LE16(UDI_HID_MOU_EP_SIZE),\
-    .ep.bInterval              = MOU_POLLING_INTERVAL,\
-}
-
-//no set report buffer
-
-//report buffer
-#define UDI_HID_MOU_REPORT_SIZE 5 //MOU PDS
+#    define UDI_HID_MOU_DESC \
+        { .iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = MOUSE_INTERFACE, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 1, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_BOOT, .iface.bInterfaceProtocol = HID_PROTOCOL_MOUSE, .iface.iInterface = UDI_HID_MOU_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_mou_report_desc_t)), .ep.bLength = sizeof(usb_ep_desc_t), .ep.bDescriptorType = USB_DT_ENDPOINT, .ep.bEndpointAddress = UDI_HID_MOU_EP_IN | USB_EP_DIR_IN, .ep.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep.wMaxPacketSize = LE16(UDI_HID_MOU_EP_SIZE), .ep.bInterval = MOU_POLLING_INTERVAL, }
+
+// no set report buffer
+
+// report buffer
+#    define UDI_HID_MOU_REPORT_SIZE 5  // MOU PDS
 extern uint8_t udi_hid_mou_report[UDI_HID_MOU_REPORT_SIZE];
 
 COMPILER_PACK_RESET()
 
-#endif //MOU
+#endif  // MOU
 
 // **********************************************************************
 // RAW Descriptor structure and content
@@ -512,57 +422,32 @@ COMPILER_PACK_RESET()
 COMPILER_PACK_SET(1)
 
 typedef struct {
-    usb_iface_desc_t iface;
+    usb_iface_desc_t     iface;
     usb_hid_descriptor_t hid;
-    usb_ep_desc_t ep_out;
-    usb_ep_desc_t ep_in;
+    usb_ep_desc_t        ep_out;
+    usb_ep_desc_t        ep_in;
 } udi_hid_raw_desc_t;
 
 typedef struct {
     uint8_t array[27];
 } udi_hid_raw_report_desc_t;
 
-#define UDI_HID_RAW_DESC {\
-    .iface.bLength             = sizeof(usb_iface_desc_t),\
-    .iface.bDescriptorType     = USB_DT_INTERFACE,\
-    .iface.bInterfaceNumber    = RAW_INTERFACE,\
-    .iface.bAlternateSetting   = 0,\
-    .iface.bNumEndpoints       = 2,\
-    .iface.bInterfaceClass     = HID_CLASS,\
-    .iface.bInterfaceSubClass  = HID_SUB_CLASS_NOBOOT,\
-    .iface.bInterfaceProtocol  = HID_SUB_CLASS_NOBOOT,\
-    .iface.iInterface          = UDI_HID_RAW_STRING_ID,\
-    .hid.bLength               = sizeof(usb_hid_descriptor_t),\
-    .hid.bDescriptorType       = USB_DT_HID,\
-    .hid.bcdHID                = LE16(USB_HID_BDC_V1_11),\
-    .hid.bCountryCode          = USB_HID_NO_COUNTRY_CODE,\
-    .hid.bNumDescriptors       = USB_HID_NUM_DESC,\
-    .hid.bRDescriptorType      = USB_DT_HID_REPORT,\
-    .hid.wDescriptorLength     = LE16(sizeof(udi_hid_raw_report_desc_t)),\
-    .ep_out.bLength            = sizeof(usb_ep_desc_t),\
-    .ep_out.bDescriptorType    = USB_DT_ENDPOINT,\
-    .ep_out.bEndpointAddress   = UDI_HID_RAW_EP_OUT | USB_EP_DIR_OUT,\
-    .ep_out.bmAttributes       = USB_EP_TYPE_INTERRUPT,\
-    .ep_out.wMaxPacketSize     = LE16(RAW_EPSIZE),\
-    .ep_out.bInterval          = RAW_POLLING_INTERVAL,\
-    .ep_in.bLength             = sizeof(usb_ep_desc_t),\
-    .ep_in.bDescriptorType     = USB_DT_ENDPOINT,\
-    .ep_in.bEndpointAddress    = UDI_HID_RAW_EP_IN | USB_EP_DIR_IN,\
-    .ep_in.bmAttributes        = USB_EP_TYPE_INTERRUPT,\
-    .ep_in.wMaxPacketSize      = LE16(RAW_EPSIZE),\
-    .ep_in.bInterval           = RAW_POLLING_INTERVAL,\
-}
-
-#define UDI_HID_RAW_REPORT_SIZE RAW_EPSIZE
+#    define UDI_HID_RAW_DESC                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           \
+        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              \
+            .iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = RAW_INTERFACE, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 2, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT, .iface.bInterfaceProtocol = HID_SUB_CLASS_NOBOOT, .iface.iInterface = UDI_HID_RAW_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_raw_report_desc_t)), .ep_out.bLength = sizeof(usb_ep_desc_t), .ep_out.bDescriptorType = USB_DT_ENDPOINT, .ep_out.bEndpointAddress = UDI_HID_RAW_EP_OUT | USB_EP_DIR_OUT, .ep_out.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep_out.wMaxPacketSize = LE16(RAW_EPSIZE), .ep_out.bInterval = RAW_POLLING_INTERVAL, \
+            .ep_in.bLength = sizeof(usb_ep_desc_t), .ep_in.bDescriptorType = USB_DT_ENDPOINT, .ep_in.bEndpointAddress = UDI_HID_RAW_EP_IN | USB_EP_DIR_IN, .ep_in.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep_in.wMaxPacketSize = LE16(RAW_EPSIZE), .ep_in.bInterval = RAW_POLLING_INTERVAL,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             \
+        }
+
+#    define UDI_HID_RAW_REPORT_SIZE RAW_EPSIZE
 
 extern uint8_t udi_hid_raw_report_set[UDI_HID_RAW_REPORT_SIZE];
 
-//report buffer
+// report buffer
 extern uint8_t udi_hid_raw_report[UDI_HID_RAW_REPORT_SIZE];
 
 COMPILER_PACK_RESET()
 
-#endif //RAW
+#endif  // RAW
 
 // **********************************************************************
 // CON Descriptor structure and content
@@ -572,57 +457,32 @@ COMPILER_PACK_RESET()
 COMPILER_PACK_SET(1)
 
 typedef struct {
-    usb_iface_desc_t iface;
+    usb_iface_desc_t     iface;
     usb_hid_descriptor_t hid;
-    usb_ep_desc_t ep_out;
-    usb_ep_desc_t ep_in;
+    usb_ep_desc_t        ep_out;
+    usb_ep_desc_t        ep_in;
 } udi_hid_con_desc_t;
 
 typedef struct {
     uint8_t array[34];
 } udi_hid_con_report_desc_t;
 
-#define UDI_HID_CON_DESC {\
-    .iface.bLength             = sizeof(usb_iface_desc_t),\
-    .iface.bDescriptorType     = USB_DT_INTERFACE,\
-    .iface.bInterfaceNumber    = UDI_HID_CON_IFACE_NUMBER,\
-    .iface.bAlternateSetting   = 0,\
-    .iface.bNumEndpoints       = 2,\
-    .iface.bInterfaceClass     = HID_CLASS,\
-    .iface.bInterfaceSubClass  = HID_SUB_CLASS_NOBOOT,\
-    .iface.bInterfaceProtocol  = HID_SUB_CLASS_NOBOOT,\
-    .iface.iInterface          = UDI_HID_CON_STRING_ID,\
-    .hid.bLength               = sizeof(usb_hid_descriptor_t),\
-    .hid.bDescriptorType       = USB_DT_HID,\
-    .hid.bcdHID                = LE16(USB_HID_BDC_V1_11),\
-    .hid.bCountryCode          = USB_HID_NO_COUNTRY_CODE,\
-    .hid.bNumDescriptors       = USB_HID_NUM_DESC,\
-    .hid.bRDescriptorType      = USB_DT_HID_REPORT,\
-    .hid.wDescriptorLength     = LE16(sizeof(udi_hid_con_report_desc_t)),\
-    .ep_out.bLength            = sizeof(usb_ep_desc_t),\
-    .ep_out.bDescriptorType    = USB_DT_ENDPOINT,\
-    .ep_out.bEndpointAddress   = UDI_HID_CON_EP_OUT | USB_EP_DIR_OUT,\
-    .ep_out.bmAttributes       = USB_EP_TYPE_INTERRUPT,\
-    .ep_out.wMaxPacketSize     = LE16(CONSOLE_EPSIZE),\
-    .ep_out.bInterval          = CON_POLLING_INTERVAL,\
-    .ep_in.bLength             = sizeof(usb_ep_desc_t),\
-    .ep_in.bDescriptorType     = USB_DT_ENDPOINT,\
-    .ep_in.bEndpointAddress    = UDI_HID_CON_EP_IN | USB_EP_DIR_IN,\
-    .ep_in.bmAttributes        = USB_EP_TYPE_INTERRUPT,\
-    .ep_in.wMaxPacketSize      = LE16(CONSOLE_EPSIZE),\
-    .ep_in.bInterval           = CON_POLLING_INTERVAL,\
-}
-
-#define UDI_HID_CON_REPORT_SIZE CONSOLE_EPSIZE
+#    define UDI_HID_CON_DESC                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          \
+        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             \
+            .iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = UDI_HID_CON_IFACE_NUMBER, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 2, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT, .iface.bInterfaceProtocol = HID_SUB_CLASS_NOBOOT, .iface.iInterface = UDI_HID_CON_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_con_report_desc_t)), .ep_out.bLength = sizeof(usb_ep_desc_t), .ep_out.bDescriptorType = USB_DT_ENDPOINT, .ep_out.bEndpointAddress = UDI_HID_CON_EP_OUT | USB_EP_DIR_OUT, .ep_out.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep_out.wMaxPacketSize = LE16(CONSOLE_EPSIZE), .ep_out.bInterval = CON_POLLING_INTERVAL, \
+            .ep_in.bLength = sizeof(usb_ep_desc_t), .ep_in.bDescriptorType = USB_DT_ENDPOINT, .ep_in.bEndpointAddress = UDI_HID_CON_EP_IN | USB_EP_DIR_IN, .ep_in.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep_in.wMaxPacketSize = LE16(CONSOLE_EPSIZE), .ep_in.bInterval = CON_POLLING_INTERVAL,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        \
+        }
+
+#    define UDI_HID_CON_REPORT_SIZE CONSOLE_EPSIZE
 
 extern uint8_t udi_hid_con_report_set[UDI_HID_CON_REPORT_SIZE];
 
-//report buffer
+// report buffer
 extern uint8_t udi_hid_con_report[UDI_HID_CON_REPORT_SIZE];
 
 COMPILER_PACK_RESET()
 
-#endif //CON
+#endif  // CON
 
 // **********************************************************************
 // CDC Descriptor structure and content
@@ -662,86 +522,28 @@ typedef struct {
 } usb_cdc_union_desc_t;
 
 typedef struct {
-    usb_association_desc_t iaface;
-    usb_iface_desc_t iface_c;
-    usb_cdc_hdr_desc_t fd;
+    usb_association_desc_t   iaface;
+    usb_iface_desc_t         iface_c;
+    usb_cdc_hdr_desc_t       fd;
     usb_cdc_call_mgmt_desc_t mfd;
-    usb_cdc_acm_desc_t acmd;
-    usb_cdc_union_desc_t ufd;
-    usb_ep_desc_t ep_c;
-    usb_iface_desc_t iface_d;
-    usb_ep_desc_t ep_tx;
-    usb_ep_desc_t ep_rx;
+    usb_cdc_acm_desc_t       acmd;
+    usb_cdc_union_desc_t     ufd;
+    usb_ep_desc_t            ep_c;
+    usb_iface_desc_t         iface_d;
+    usb_ep_desc_t            ep_tx;
+    usb_ep_desc_t            ep_rx;
 } udi_cdc_desc_t;
 
-#define CDC_DESCRIPTOR {\
-    .iaface.bLength            = sizeof(usb_association_desc_t),\
-    .iaface.bDescriptorType    = USB_DT_IAD,\
-    .iaface.bFirstInterface    = CDC_STATUS_INTERFACE,\
-    .iaface.bInterfaceCount    = 2,\
-    .iaface.bFunctionClass     = CDC_CLASS_DEVICE,\
-    .iaface.bFunctionSubClass  = CDC_SUBCLASS_ACM,\
-    .iaface.bFunctionProtocol  = CDC_PROTOCOL_V25TER,\
-    .iaface.iFunction          = 0,\
-    .iface_c.bLength             = sizeof(usb_iface_desc_t),\
-    .iface_c.bDescriptorType     = USB_DT_INTERFACE,\
-    .iface_c.bInterfaceNumber    = CDC_STATUS_INTERFACE,\
-    .iface_c.bAlternateSetting   = 0,\
-    .iface_c.bNumEndpoints       = 1,\
-    .iface_c.bInterfaceClass     = 0x02,\
-    .iface_c.bInterfaceSubClass  = 0x02,\
-    .iface_c.bInterfaceProtocol  = CDC_PROTOCOL_V25TER,\
-    .iface_c.iInterface          = 0,\
-    .fd.bFunctionLength        = sizeof(usb_cdc_hdr_desc_t),\
-    .fd.bDescriptorType        = CDC_CS_INTERFACE,\
-    .fd.bDescriptorSubtype     = CDC_SCS_HEADER,\
-    .fd.bcdCDC                 = 0x0110,\
-    .mfd.bFunctionLength       = sizeof(usb_cdc_call_mgmt_desc_t),\
-    .mfd.bDescriptorType       = CDC_CS_INTERFACE,\
-    .mfd.bDescriptorSubtype    = CDC_SCS_CALL_MGMT,\
-    .mfd.bmCapabilities        = CDC_CALL_MGMT_SUPPORTED,\
-    .mfd.bDataInterface        = CDC_DATA_INTERFACE,\
-    .acmd.bFunctionLength      = sizeof(usb_cdc_acm_desc_t),\
-    .acmd.bDescriptorType      = CDC_CS_INTERFACE,\
-    .acmd.bDescriptorSubtype   = CDC_SCS_ACM,\
-    .acmd.bmCapabilities       = CDC_ACM_SUPPORT_LINE_REQUESTS,\
-    .ufd.bFunctionLength       = sizeof(usb_cdc_union_desc_t),\
-    .ufd.bDescriptorType       = CDC_CS_INTERFACE,\
-    .ufd.bDescriptorSubtype    = CDC_SCS_UNION,\
-    .ufd.bMasterInterface      = CDC_STATUS_INTERFACE,\
-    .ufd.bSlaveInterface0      = CDC_DATA_INTERFACE,\
-    .ep_c.bLength                = sizeof(usb_ep_desc_t),\
-    .ep_c.bDescriptorType        = USB_DT_ENDPOINT,\
-    .ep_c.bEndpointAddress       = CDC_ACM_ENDPOINT | USB_EP_DIR_IN,\
-    .ep_c.bmAttributes           = USB_EP_TYPE_INTERRUPT,\
-    .ep_c.wMaxPacketSize         = LE16(CDC_ACM_SIZE),\
-    .ep_c.bInterval              = CDC_EP_INTERVAL_STATUS,\
-    .iface_d.bLength             = sizeof(usb_iface_desc_t),\
-    .iface_d.bDescriptorType     = USB_DT_INTERFACE,\
-    .iface_d.bInterfaceNumber    = CDC_DATA_INTERFACE,\
-    .iface_d.bAlternateSetting   = 0,\
-    .iface_d.bNumEndpoints       = 2,\
-    .iface_d.bInterfaceClass     = CDC_CLASS_DATA,\
-    .iface_d.bInterfaceSubClass  = 0,\
-    .iface_d.bInterfaceProtocol  = 0,\
-    .iface_d.iInterface          = 0,\
-    .ep_rx.bLength                = sizeof(usb_ep_desc_t),\
-    .ep_rx.bDescriptorType        = USB_DT_ENDPOINT,\
-    .ep_rx.bEndpointAddress       = CDC_RX_ENDPOINT | USB_EP_DIR_OUT,\
-    .ep_rx.bmAttributes           = USB_EP_TYPE_BULK,\
-    .ep_rx.wMaxPacketSize         = LE16(CDC_RX_SIZE),\
-    .ep_rx.bInterval              = CDC_EP_INTERVAL_DATA,\
-    .ep_tx.bLength                = sizeof(usb_ep_desc_t),\
-    .ep_tx.bDescriptorType        = USB_DT_ENDPOINT,\
-    .ep_tx.bEndpointAddress       = CDC_TX_ENDPOINT | USB_EP_DIR_IN,\
-    .ep_tx.bmAttributes           = USB_EP_TYPE_BULK,\
-    .ep_tx.wMaxPacketSize         = LE16(CDC_TX_SIZE),\
-    .ep_tx.bInterval              = CDC_EP_INTERVAL_DATA,\
-}
+#    define CDC_DESCRIPTOR                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          \
+        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           \
+            .iaface.bLength = sizeof(usb_association_desc_t), .iaface.bDescriptorType = USB_DT_IAD, .iaface.bFirstInterface = CDC_STATUS_INTERFACE, .iaface.bInterfaceCount = 2, .iaface.bFunctionClass = CDC_CLASS_DEVICE, .iaface.bFunctionSubClass = CDC_SUBCLASS_ACM, .iaface.bFunctionProtocol = CDC_PROTOCOL_V25TER, .iaface.iFunction = 0, .iface_c.bLength = sizeof(usb_iface_desc_t), .iface_c.bDescriptorType = USB_DT_INTERFACE, .iface_c.bInterfaceNumber = CDC_STATUS_INTERFACE, .iface_c.bAlternateSetting = 0, .iface_c.bNumEndpoints = 1, .iface_c.bInterfaceClass = 0x02, .iface_c.bInterfaceSubClass = 0x02, .iface_c.bInterfaceProtocol = CDC_PROTOCOL_V25TER, .iface_c.iInterface = 0, .fd.bFunctionLength = sizeof(usb_cdc_hdr_desc_t), .fd.bDescriptorType = CDC_CS_INTERFACE, .fd.bDescriptorSubtype = CDC_SCS_HEADER, .fd.bcdCDC = 0x0110, .mfd.bFunctionLength = sizeof(usb_cdc_call_mgmt_desc_t), .mfd.bDescriptorType = CDC_CS_INTERFACE, .mfd.bDescriptorSubtype = CDC_SCS_CALL_MGMT,   \
+            .mfd.bmCapabilities = CDC_CALL_MGMT_SUPPORTED, .mfd.bDataInterface = CDC_DATA_INTERFACE, .acmd.bFunctionLength = sizeof(usb_cdc_acm_desc_t), .acmd.bDescriptorType = CDC_CS_INTERFACE, .acmd.bDescriptorSubtype = CDC_SCS_ACM, .acmd.bmCapabilities = CDC_ACM_SUPPORT_LINE_REQUESTS, .ufd.bFunctionLength = sizeof(usb_cdc_union_desc_t), .ufd.bDescriptorType = CDC_CS_INTERFACE, .ufd.bDescriptorSubtype = CDC_SCS_UNION, .ufd.bMasterInterface = CDC_STATUS_INTERFACE, .ufd.bSlaveInterface0 = CDC_DATA_INTERFACE, .ep_c.bLength = sizeof(usb_ep_desc_t), .ep_c.bDescriptorType = USB_DT_ENDPOINT, .ep_c.bEndpointAddress = CDC_ACM_ENDPOINT | USB_EP_DIR_IN, .ep_c.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep_c.wMaxPacketSize = LE16(CDC_ACM_SIZE), .ep_c.bInterval = CDC_EP_INTERVAL_STATUS, .iface_d.bLength = sizeof(usb_iface_desc_t), .iface_d.bDescriptorType = USB_DT_INTERFACE, .iface_d.bInterfaceNumber = CDC_DATA_INTERFACE, .iface_d.bAlternateSetting = 0, .iface_d.bNumEndpoints = 2, \
+            .iface_d.bInterfaceClass = CDC_CLASS_DATA, .iface_d.bInterfaceSubClass = 0, .iface_d.bInterfaceProtocol = 0, .iface_d.iInterface = 0, .ep_rx.bLength = sizeof(usb_ep_desc_t), .ep_rx.bDescriptorType = USB_DT_ENDPOINT, .ep_rx.bEndpointAddress = CDC_RX_ENDPOINT | USB_EP_DIR_OUT, .ep_rx.bmAttributes = USB_EP_TYPE_BULK, .ep_rx.wMaxPacketSize = LE16(CDC_RX_SIZE), .ep_rx.bInterval = CDC_EP_INTERVAL_DATA, .ep_tx.bLength = sizeof(usb_ep_desc_t), .ep_tx.bDescriptorType = USB_DT_ENDPOINT, .ep_tx.bEndpointAddress = CDC_TX_ENDPOINT | USB_EP_DIR_IN, .ep_tx.bmAttributes = USB_EP_TYPE_BULK, .ep_tx.wMaxPacketSize = LE16(CDC_TX_SIZE), .ep_tx.bInterval = CDC_EP_INTERVAL_DATA,                                                                                                                                                                                                                                                                                                                \
+        }
 
 COMPILER_PACK_RESET()
 
-#endif //CDC
+#endif  // CDC
 
 // **********************************************************************
 // CONFIGURATION Descriptor structure and content
@@ -778,4 +580,4 @@ typedef struct {
 
 COMPILER_PACK_RESET()
 
-#endif //_UDI_DEVICE_CONF_H_
+#endif  //_UDI_DEVICE_CONF_H_
index 96d03c286959cbb84ddc3e64ecd2d5254c4f810b..65339bffec32243d45436e7c6c51e84555c4ee21 100644 (file)
@@ -18,15 +18,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef _UDI_DEVICE_EPSIZE_H_
 #define _UDI_DEVICE_EPSIZE_H_
 
-#define KEYBOARD_EPSIZE             8
-#define MOUSE_EPSIZE                8
-#define EXTRAKEY_EPSIZE             8
-#define RAW_EPSIZE                  64
-#define CONSOLE_EPSIZE              32
-#define NKRO_EPSIZE                 32
-#define MIDI_STREAM_EPSIZE          64
-#define CDC_NOTIFICATION_EPSIZE     8
-#define CDC_EPSIZE                  16
-
-#endif //_UDI_DEVICE_EPSIZE_H_
+#define KEYBOARD_EPSIZE 8
+#define MOUSE_EPSIZE 8
+#define EXTRAKEY_EPSIZE 8
+#define RAW_EPSIZE 64
+#define CONSOLE_EPSIZE 32
+#define NKRO_EPSIZE 32
+#define MIDI_STREAM_EPSIZE 64
+#define CDC_NOTIFICATION_EPSIZE 8
+#define CDC_EPSIZE 16
 
+#endif  //_UDI_DEVICE_EPSIZE_H_
index 131b7a0ece8246ad4cc361ad87726224081f0668..b0bdcc6932523774c7181c0dd3d6055486ab6fb2 100644 (file)
@@ -50,7 +50,6 @@
 #include "udc.h"
 #include "udi_hid.h"
 
-
 /**
  * \ingroup udi_hid_group
  * \defgroup udi_hid_group_internal Implementation of HID common library
  */
 static bool udi_hid_reqstdifaceget_descriptor(uint8_t *report_desc);
 
-bool udi_hid_setup( uint8_t *rate, uint8_t *protocol, uint8_t *report_desc, bool (*setup_report)(void) )
-{
+bool udi_hid_setup(uint8_t *rate, uint8_t *protocol, uint8_t *report_desc, bool (*setup_report)(void)) {
     if (Udd_setup_is_in()) {
         // Requests Interface GET
         if (Udd_setup_type() == USB_REQ_TYPE_STANDARD) {
             // Requests Standard Interface Get
             switch (udd_g_ctrlreq.req.bRequest) {
-
-            case USB_REQ_GET_DESCRIPTOR:
-                return udi_hid_reqstdifaceget_descriptor(report_desc);
+                case USB_REQ_GET_DESCRIPTOR:
+                    return udi_hid_reqstdifaceget_descriptor(report_desc);
             }
         }
         if (Udd_setup_type() == USB_REQ_TYPE_CLASS) {
             // Requests Class Interface Get
             switch (udd_g_ctrlreq.req.bRequest) {
-
-            case USB_REQ_HID_GET_REPORT:
-                return setup_report();
-
-            case USB_REQ_HID_GET_IDLE:
-                udd_g_ctrlreq.payload = rate;
-                udd_g_ctrlreq.payload_size = 1;
-                return true;
-
-            case USB_REQ_HID_GET_PROTOCOL:
-                udd_g_ctrlreq.payload = protocol;
-                udd_g_ctrlreq.payload_size = 1;
-                return true;
+                case USB_REQ_HID_GET_REPORT:
+                    return setup_report();
+
+                case USB_REQ_HID_GET_IDLE:
+                    udd_g_ctrlreq.payload      = rate;
+                    udd_g_ctrlreq.payload_size = 1;
+                    return true;
+
+                case USB_REQ_HID_GET_PROTOCOL:
+                    udd_g_ctrlreq.payload      = protocol;
+                    udd_g_ctrlreq.payload_size = 1;
+                    return true;
             }
         }
     }
@@ -100,60 +96,50 @@ bool udi_hid_setup( uint8_t *rate, uint8_t *protocol, uint8_t *report_desc, bool
         if (Udd_setup_type() == USB_REQ_TYPE_CLASS) {
             // Requests Class Interface Set
             switch (udd_g_ctrlreq.req.bRequest) {
+                case USB_REQ_HID_SET_REPORT:
+                    return setup_report();
 
-            case USB_REQ_HID_SET_REPORT:
-                return setup_report();
-
-            case USB_REQ_HID_SET_IDLE:
-                *rate = udd_g_ctrlreq.req.wValue >> 8;
-                return true;
+                case USB_REQ_HID_SET_IDLE:
+                    *rate = udd_g_ctrlreq.req.wValue >> 8;
+                    return true;
 
-            case USB_REQ_HID_SET_PROTOCOL:
-                if (0 != udd_g_ctrlreq.req.wLength)
-                    return false;
-                *protocol = udd_g_ctrlreq.req.wValue;
-                return true;
+                case USB_REQ_HID_SET_PROTOCOL:
+                    if (0 != udd_g_ctrlreq.req.wLength) return false;
+                    *protocol = udd_g_ctrlreq.req.wValue;
+                    return true;
             }
         }
     }
-    return false;   // Request not supported
+    return false;  // Request not supported
 }
 
 //---------------------------------------------
 //------- Internal routines
 
-static bool udi_hid_reqstdifaceget_descriptor(uint8_t *report_desc)
-{
+static bool udi_hid_reqstdifaceget_descriptor(uint8_t *report_desc) {
     usb_hid_descriptor_t UDC_DESC_STORAGE *ptr_hid_desc;
 
     // Get the USB descriptor which is located after the interface descriptor
     // This descriptor must be the HID descriptor
-    ptr_hid_desc = (usb_hid_descriptor_t UDC_DESC_STORAGE *) ((uint8_t *)
-            udc_get_interface_desc() + sizeof(usb_iface_desc_t));
-    if (USB_DT_HID != ptr_hid_desc->bDescriptorType)
-        return false;
+    ptr_hid_desc = (usb_hid_descriptor_t UDC_DESC_STORAGE *)((uint8_t *)udc_get_interface_desc() + sizeof(usb_iface_desc_t));
+    if (USB_DT_HID != ptr_hid_desc->bDescriptorType) return false;
 
     // The SETUP request can ask for:
     // - an USB_DT_HID descriptor
     // - or USB_DT_HID_REPORT descriptor
     // - or USB_DT_HID_PHYSICAL descriptor
-    if (USB_DT_HID == (uint8_t) (udd_g_ctrlreq.req.wValue >> 8)) {
+    if (USB_DT_HID == (uint8_t)(udd_g_ctrlreq.req.wValue >> 8)) {
         // USB_DT_HID descriptor requested then send it
-        udd_g_ctrlreq.payload = (uint8_t *) ptr_hid_desc;
-        udd_g_ctrlreq.payload_size =
-                min(udd_g_ctrlreq.req.wLength,
-                ptr_hid_desc->bLength);
+        udd_g_ctrlreq.payload      = (uint8_t *)ptr_hid_desc;
+        udd_g_ctrlreq.payload_size = min(udd_g_ctrlreq.req.wLength, ptr_hid_desc->bLength);
         return true;
     }
     // The HID_X descriptor requested must correspond to report type
     // included in the HID descriptor
-    if (ptr_hid_desc->bRDescriptorType ==
-            (uint8_t) (udd_g_ctrlreq.req.wValue >> 8)) {
+    if (ptr_hid_desc->bRDescriptorType == (uint8_t)(udd_g_ctrlreq.req.wValue >> 8)) {
         // Send HID Report descriptor given by high level
-        udd_g_ctrlreq.payload = report_desc;
-        udd_g_ctrlreq.payload_size =
-                min(udd_g_ctrlreq.req.wLength,
-                le16_to_cpu(ptr_hid_desc->wDescriptorLength));
+        udd_g_ctrlreq.payload      = report_desc;
+        udd_g_ctrlreq.payload_size = min(udd_g_ctrlreq.req.wLength, le16_to_cpu(ptr_hid_desc->wDescriptorLength));
         return true;
     }
     return false;
index 0edb09c1c3d3b54707e16f2e34bb34d67e5a25d0..6fd2cabd4cefa46a58d0e0c95e89d33059c92ac4 100644 (file)
@@ -75,11 +75,11 @@ extern "C" {
  *
  * \return \c 1 if function was successfully done, otherwise \c 0.
  */
-bool udi_hid_setup( uint8_t *rate, uint8_t *protocol, uint8_t *report_desc, bool (*setup_report)(void) );
+bool udi_hid_setup(uint8_t *rate, uint8_t *protocol, uint8_t *report_desc, bool (*setup_report)(void));
 
 //@}
 
 #ifdef __cplusplus
 }
 #endif
-#endif // _UDI_HID_H_
+#endif  // _UDI_HID_H_
index b715b702658a06ca9a417c331db3dfed3f195968..c3952d50c82ba4cf46e18e233b09e1dc86e7f15c 100644 (file)
 //***************************************************************************
 #ifdef KBD
 
-bool udi_hid_kbd_enable(void);
-void udi_hid_kbd_disable(void);
-bool udi_hid_kbd_setup(void);
+bool    udi_hid_kbd_enable(void);
+void    udi_hid_kbd_disable(void);
+bool    udi_hid_kbd_setup(void);
 uint8_t udi_hid_kbd_getsetting(void);
 
 UDC_DESC_STORAGE udi_api_t udi_api_hid_kbd = {
-    .enable = (bool(*)(void))udi_hid_kbd_enable,
-    .disable = (void (*)(void))udi_hid_kbd_disable,
-    .setup = (bool(*)(void))udi_hid_kbd_setup,
+    .enable     = (bool (*)(void))udi_hid_kbd_enable,
+    .disable    = (void (*)(void))udi_hid_kbd_disable,
+    .setup      = (bool (*)(void))udi_hid_kbd_setup,
     .getsetting = (uint8_t(*)(void))udi_hid_kbd_getsetting,
     .sof_notify = NULL,
 };
@@ -94,40 +94,38 @@ COMPILER_WORD_ALIGNED
 static uint8_t udi_hid_kbd_report_trans[UDI_HID_KBD_REPORT_SIZE];
 
 COMPILER_WORD_ALIGNED
-UDC_DESC_STORAGE udi_hid_kbd_report_desc_t udi_hid_kbd_report_desc = {
-    {
-        0x05, 0x01,     // Usage Page (Generic Desktop)
-        0x09, 0x06,     // Usage (Keyboard)
-        0xA1, 0x01,     // Collection (Application)
-        0x05, 0x07,     //   Usage Page (Keyboard)
-        0x19, 0xE0,     //   Usage Minimum (224)
-        0x29, 0xE7,     //   Usage Maximum (231)
-        0x15, 0x00,     //   Logical Minimum (0)
-        0x25, 0x01,     //   Logical Maximum (1)
-        0x75, 0x01,     //   Report Size (1)
-        0x95, 0x08,     //   Report Count (8)
-        0x81, 0x02,     //   Input (Data, Variable, Absolute)
-        0x81, 0x01,     //   Input (Constant)
-        0x19, 0x00,     //   Usage Minimum (0)
-        0x29, 0xFF,     //   Usage Maximum (255)
-        0x15, 0x00,     //   Logical Minimum (0)
-        0x25, 0xFF,     //   Logical Maximum (255)
-        0x75, 0x08,     //   Report Size (8)
-        0x95, 0x06,     //   Report Count (6)
-        0x81, 0x00,     //   Input (Data, Array)
-        0x05, 0x08,     //   Usage Page (LED)
-        0x19, 0x01,     //   Usage Minimum (1)
-        0x29, 0x05,     //   Usage Maximum (5)
-        0x15, 0x00,     //   Logical Minimum (0)
-        0x25, 0x01,     //   Logical Maximum (1)
-        0x75, 0x01,     //   Report Size (1)
-        0x95, 0x05,     //   Report Count (5)
-        0x91, 0x02,     //   Output (Data, Variable, Absolute)
-        0x95, 0x03,     //   Report Count (3)
-        0x91, 0x01,     //   Output (Constant)
-        0xC0            // End Collection
-    }
-};
+UDC_DESC_STORAGE udi_hid_kbd_report_desc_t udi_hid_kbd_report_desc = {{
+    0x05, 0x01,  // Usage Page (Generic Desktop)
+    0x09, 0x06,  // Usage (Keyboard)
+    0xA1, 0x01,  // Collection (Application)
+    0x05, 0x07,  //   Usage Page (Keyboard)
+    0x19, 0xE0,  //   Usage Minimum (224)
+    0x29, 0xE7,  //   Usage Maximum (231)
+    0x15, 0x00,  //   Logical Minimum (0)
+    0x25, 0x01,  //   Logical Maximum (1)
+    0x75, 0x01,  //   Report Size (1)
+    0x95, 0x08,  //   Report Count (8)
+    0x81, 0x02,  //   Input (Data, Variable, Absolute)
+    0x81, 0x01,  //   Input (Constant)
+    0x19, 0x00,  //   Usage Minimum (0)
+    0x29, 0xFF,  //   Usage Maximum (255)
+    0x15, 0x00,  //   Logical Minimum (0)
+    0x25, 0xFF,  //   Logical Maximum (255)
+    0x75, 0x08,  //   Report Size (8)
+    0x95, 0x06,  //   Report Count (6)
+    0x81, 0x00,  //   Input (Data, Array)
+    0x05, 0x08,  //   Usage Page (LED)
+    0x19, 0x01,  //   Usage Minimum (1)
+    0x29, 0x05,  //   Usage Maximum (5)
+    0x15, 0x00,  //   Logical Minimum (0)
+    0x25, 0x01,  //   Logical Maximum (1)
+    0x75, 0x01,  //   Report Size (1)
+    0x95, 0x05,  //   Report Count (5)
+    0x91, 0x02,  //   Output (Data, Variable, Absolute)
+    0x95, 0x03,  //   Report Count (3)
+    0x91, 0x01,  //   Output (Constant)
+    0xC0         // End Collection
+}};
 
 static bool udi_hid_kbd_setreport(void);
 
@@ -135,51 +133,34 @@ static void udi_hid_kbd_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
 
 static void udi_hid_kbd_setreport_valid(void);
 
-bool udi_hid_kbd_enable(void)
-{
+bool udi_hid_kbd_enable(void) {
     // Initialize internal values
-    udi_hid_kbd_rate = 0;
-    udi_hid_kbd_protocol = 0;
+    udi_hid_kbd_rate                   = 0;
+    udi_hid_kbd_protocol               = 0;
     udi_hid_kbd_b_report_trans_ongoing = false;
     memset(udi_hid_kbd_report, 0, UDI_HID_KBD_REPORT_SIZE);
     udi_hid_kbd_b_report_valid = false;
     return UDI_HID_KBD_ENABLE_EXT();
 }
 
-void udi_hid_kbd_disable(void)
-{
-    UDI_HID_KBD_DISABLE_EXT();
-}
+void udi_hid_kbd_disable(void) { UDI_HID_KBD_DISABLE_EXT(); }
 
-bool udi_hid_kbd_setup(void)
-{
-    return udi_hid_setup(&udi_hid_kbd_rate,
-                            &udi_hid_kbd_protocol,
-                            (uint8_t *) &udi_hid_kbd_report_desc,
-                            udi_hid_kbd_setreport);
-}
+bool udi_hid_kbd_setup(void) { return udi_hid_setup(&udi_hid_kbd_rate, &udi_hid_kbd_protocol, (uint8_t *)&udi_hid_kbd_report_desc, udi_hid_kbd_setreport); }
 
-uint8_t udi_hid_kbd_getsetting(void)
-{
-    return 0;
-}
+uint8_t udi_hid_kbd_getsetting(void) { return 0; }
 
-static bool udi_hid_kbd_setreport(void)
-{
-    if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8))
-            && (0 == (0xFF & udd_g_ctrlreq.req.wValue))
-            && (1 == udd_g_ctrlreq.req.wLength)) {
+static bool udi_hid_kbd_setreport(void) {
+    if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (1 == udd_g_ctrlreq.req.wLength)) {
         // Report OUT type on report ID 0 from USB Host
-        udd_g_ctrlreq.payload = &udi_hid_kbd_report_set;
-        udd_g_ctrlreq.callback = udi_hid_kbd_setreport_valid;
+        udd_g_ctrlreq.payload      = &udi_hid_kbd_report_set;
+        udd_g_ctrlreq.callback     = udi_hid_kbd_setreport_valid;
         udd_g_ctrlreq.payload_size = 1;
         return true;
     }
     return false;
 }
 
-bool udi_hid_kbd_send_report(void)
-{
+bool udi_hid_kbd_send_report(void) {
     if (!main_b_kbd_enable) {
         return false;
     }
@@ -189,19 +170,13 @@ bool udi_hid_kbd_send_report(void)
     }
 
     memcpy(udi_hid_kbd_report_trans, udi_hid_kbd_report, UDI_HID_KBD_REPORT_SIZE);
-    udi_hid_kbd_b_report_valid = false;
-    udi_hid_kbd_b_report_trans_ongoing =
-            udd_ep_run(UDI_HID_KBD_EP_IN | USB_EP_DIR_IN,
-                        false,
-                        udi_hid_kbd_report_trans,
-                        UDI_HID_KBD_REPORT_SIZE,
-                        udi_hid_kbd_report_sent);
+    udi_hid_kbd_b_report_valid         = false;
+    udi_hid_kbd_b_report_trans_ongoing = udd_ep_run(UDI_HID_KBD_EP_IN | USB_EP_DIR_IN, false, udi_hid_kbd_report_trans, UDI_HID_KBD_REPORT_SIZE, udi_hid_kbd_report_sent);
 
     return udi_hid_kbd_b_report_trans_ongoing;
 }
 
-static void udi_hid_kbd_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep)
-{
+static void udi_hid_kbd_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
     UNUSED(status);
     UNUSED(nb_sent);
     UNUSED(ep);
@@ -211,27 +186,26 @@ static void udi_hid_kbd_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
     }
 }
 
-static void udi_hid_kbd_setreport_valid(void)
-{
-    //UDI_HID_KBD_CHANGE_LED(udi_hid_kbd_report_set);
+static void udi_hid_kbd_setreport_valid(void) {
+    // UDI_HID_KBD_CHANGE_LED(udi_hid_kbd_report_set);
 }
 
-#endif //KBD
+#endif  // KBD
 
 //********************************************************************************************
 // NKRO Keyboard
 //********************************************************************************************
 #ifdef NKRO
 
-bool udi_hid_nkro_enable(void);
-void udi_hid_nkro_disable(void);
-bool udi_hid_nkro_setup(void);
+bool    udi_hid_nkro_enable(void);
+void    udi_hid_nkro_disable(void);
+bool    udi_hid_nkro_setup(void);
 uint8_t udi_hid_nkro_getsetting(void);
 
 UDC_DESC_STORAGE udi_api_t udi_api_hid_nkro = {
-    .enable = (bool(*)(void))udi_hid_nkro_enable,
-    .disable = (void (*)(void))udi_hid_nkro_disable,
-    .setup = (bool(*)(void))udi_hid_nkro_setup,
+    .enable     = (bool (*)(void))udi_hid_nkro_enable,
+    .disable    = (void (*)(void))udi_hid_nkro_disable,
+    .setup      = (bool (*)(void))udi_hid_nkro_setup,
     .getsetting = (uint8_t(*)(void))udi_hid_nkro_getsetting,
     .sof_notify = NULL,
 };
@@ -256,98 +230,79 @@ COMPILER_WORD_ALIGNED
 static uint8_t udi_hid_nkro_report_trans[UDI_HID_NKRO_REPORT_SIZE];
 
 COMPILER_WORD_ALIGNED
-UDC_DESC_STORAGE udi_hid_nkro_report_desc_t udi_hid_nkro_report_desc = {
-    {
-        0x05, 0x01,     // Usage Page (Generic Desktop),
-        0x09, 0x06,     // Usage (Keyboard),
-        0xA1, 0x01,     // Collection (Application) - Keyboard,
-
-        //Mods
-        0x75, 0x01,     //   Report Size (1),
-        0x95, 0x08,     //   Report Count (8),
-        0x15, 0x00,     //   Logical Minimum (0),
-        0x25, 0x01,     //   Logical Maximum (1),
-        0x05, 0x07,     //   Usage Page (Key Codes),
-        0x19, 0xE0,     //   Usage Minimum (224),
-        0x29, 0xE7,     //   Usage Maximum (231),
-        0x81, 0x02,     //   Input (Data, Variable, Absolute),
-
-        //LED Report
-        0x75, 0x01,     //   Report Size (1),
-        0x95, 0x05,     //   Report Count (5),
-        0x05, 0x08,     //   Usage Page (LEDs),
-        0x19, 0x01,     //   Usage Minimum (1),
-        0x29, 0x05,     //   Usage Maximum (5),
-        0x91, 0x02,     //   Output (Data, Variable, Absolute),
-
-        //LED Report Padding
-        0x75, 0x03,     //   Report Size (3),
-        0x95, 0x01,     //   Report Count (1),
-        0x91, 0x03,     //   Output (Constant),
-
-        //Main keys
-        0x75, 0x01,     //   Report Size (1),
-        0x95, 0xF8,     //   Report Count (248),
-        0x15, 0x00,     //   Logical Minimum (0),
-        0x25, 0x01,     //   Logical Maximum (1),
-        0x05, 0x07,     //   Usage Page (Key Codes),
-        0x19, 0x00,     //   Usage Minimum (0),
-        0x29, 0xF7,     //   Usage Maximum (247),
-        0x81, 0x02,     //   Input (Data, Variable, Absolute, Bitfield),
-        0xc0,           // End Collection - Keyboard
-    }
-};
+UDC_DESC_STORAGE udi_hid_nkro_report_desc_t udi_hid_nkro_report_desc = {{
+    0x05, 0x01,  // Usage Page (Generic Desktop),
+    0x09, 0x06,  // Usage (Keyboard),
+    0xA1, 0x01,  // Collection (Application) - Keyboard,
+
+    // Mods
+    0x75, 0x01,  //   Report Size (1),
+    0x95, 0x08,  //   Report Count (8),
+    0x15, 0x00,  //   Logical Minimum (0),
+    0x25, 0x01,  //   Logical Maximum (1),
+    0x05, 0x07,  //   Usage Page (Key Codes),
+    0x19, 0xE0,  //   Usage Minimum (224),
+    0x29, 0xE7,  //   Usage Maximum (231),
+    0x81, 0x02,  //   Input (Data, Variable, Absolute),
+
+    // LED Report
+    0x75, 0x01,  //   Report Size (1),
+    0x95, 0x05,  //   Report Count (5),
+    0x05, 0x08,  //   Usage Page (LEDs),
+    0x19, 0x01,  //   Usage Minimum (1),
+    0x29, 0x05,  //   Usage Maximum (5),
+    0x91, 0x02,  //   Output (Data, Variable, Absolute),
+
+    // LED Report Padding
+    0x75, 0x03,  //   Report Size (3),
+    0x95, 0x01,  //   Report Count (1),
+    0x91, 0x03,  //   Output (Constant),
+
+    // Main keys
+    0x75, 0x01,  //   Report Size (1),
+    0x95, 0xF8,  //   Report Count (248),
+    0x15, 0x00,  //   Logical Minimum (0),
+    0x25, 0x01,  //   Logical Maximum (1),
+    0x05, 0x07,  //   Usage Page (Key Codes),
+    0x19, 0x00,  //   Usage Minimum (0),
+    0x29, 0xF7,  //   Usage Maximum (247),
+    0x81, 0x02,  //   Input (Data, Variable, Absolute, Bitfield),
+    0xc0,        // End Collection - Keyboard
+}};
 
 static bool udi_hid_nkro_setreport(void);
 static void udi_hid_nkro_setreport_valid(void);
 static void udi_hid_nkro_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
 
-bool udi_hid_nkro_enable(void)
-{
+bool udi_hid_nkro_enable(void) {
     // Initialize internal values
-    udi_hid_nkro_rate = 0;
-    udi_hid_nkro_protocol = 0;
+    udi_hid_nkro_rate                   = 0;
+    udi_hid_nkro_protocol               = 0;
     udi_hid_nkro_b_report_trans_ongoing = false;
     memset(udi_hid_nkro_report, 0, UDI_HID_NKRO_REPORT_SIZE);
     udi_hid_nkro_b_report_valid = false;
     return UDI_HID_NKRO_ENABLE_EXT();
 }
 
-void udi_hid_nkro_disable(void)
-{
-    UDI_HID_NKRO_DISABLE_EXT();
-}
+void udi_hid_nkro_disable(void) { UDI_HID_NKRO_DISABLE_EXT(); }
 
-bool udi_hid_nkro_setup(void)
-{
-    return udi_hid_setup(&udi_hid_nkro_rate,
-                            &udi_hid_nkro_protocol,
-                            (uint8_t *) &udi_hid_nkro_report_desc,
-                            udi_hid_nkro_setreport);
-}
+bool udi_hid_nkro_setup(void) { return udi_hid_setup(&udi_hid_nkro_rate, &udi_hid_nkro_protocol, (uint8_t *)&udi_hid_nkro_report_desc, udi_hid_nkro_setreport); }
 
-uint8_t udi_hid_nkro_getsetting(void)
-{
-    return 0;
-}
+uint8_t udi_hid_nkro_getsetting(void) { return 0; }
 
-//keyboard receives LED report here
-static bool udi_hid_nkro_setreport(void)
-{
-    if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8))
-        && (0 == (0xFF & udd_g_ctrlreq.req.wValue))
-        && (1 == udd_g_ctrlreq.req.wLength)) {
+// keyboard receives LED report here
+static bool udi_hid_nkro_setreport(void) {
+    if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (1 == udd_g_ctrlreq.req.wLength)) {
         // Report OUT type on report ID 0 from USB Host
-        udd_g_ctrlreq.payload = &udi_hid_nkro_report_set;
-        udd_g_ctrlreq.callback = udi_hid_nkro_setreport_valid; //must call routine to transform setreport to LED state
+        udd_g_ctrlreq.payload      = &udi_hid_nkro_report_set;
+        udd_g_ctrlreq.callback     = udi_hid_nkro_setreport_valid;  // must call routine to transform setreport to LED state
         udd_g_ctrlreq.payload_size = 1;
         return true;
     }
     return false;
 }
 
-bool udi_hid_nkro_send_report(void)
-{
+bool udi_hid_nkro_send_report(void) {
     if (!main_b_nkro_enable) {
         return false;
     }
@@ -357,19 +312,13 @@ bool udi_hid_nkro_send_report(void)
     }
 
     memcpy(udi_hid_nkro_report_trans, udi_hid_nkro_report, UDI_HID_NKRO_REPORT_SIZE);
-    udi_hid_nkro_b_report_valid = false;
-    udi_hid_nkro_b_report_trans_ongoing =
-            udd_ep_run(UDI_HID_NKRO_EP_IN | USB_EP_DIR_IN,
-                        false,
-                        udi_hid_nkro_report_trans,
-                        UDI_HID_NKRO_REPORT_SIZE,
-                        udi_hid_nkro_report_sent);
+    udi_hid_nkro_b_report_valid         = false;
+    udi_hid_nkro_b_report_trans_ongoing = udd_ep_run(UDI_HID_NKRO_EP_IN | USB_EP_DIR_IN, false, udi_hid_nkro_report_trans, UDI_HID_NKRO_REPORT_SIZE, udi_hid_nkro_report_sent);
 
     return udi_hid_nkro_b_report_trans_ongoing;
 }
 
-static void udi_hid_nkro_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep)
-{
+static void udi_hid_nkro_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
     UNUSED(status);
     UNUSED(nb_sent);
     UNUSED(ep);
@@ -379,27 +328,26 @@ static void udi_hid_nkro_report_sent(udd_ep_status_t status, iram_size_t nb_sent
     }
 }
 
-static void udi_hid_nkro_setreport_valid(void)
-{
-    //UDI_HID_NKRO_CHANGE_LED(udi_hid_nkro_report_set);
+static void udi_hid_nkro_setreport_valid(void) {
+    // UDI_HID_NKRO_CHANGE_LED(udi_hid_nkro_report_set);
 }
 
-#endif //NKRO
+#endif  // NKRO
 
 //********************************************************************************************
 // EXK (extra-keys) SYS-CTRL  Keyboard
 //********************************************************************************************
 #ifdef EXK
 
-bool udi_hid_exk_enable(void);
-void udi_hid_exk_disable(void);
-bool udi_hid_exk_setup(void);
+bool    udi_hid_exk_enable(void);
+void    udi_hid_exk_disable(void);
+bool    udi_hid_exk_setup(void);
 uint8_t udi_hid_exk_getsetting(void);
 
 UDC_DESC_STORAGE udi_api_t udi_api_hid_exk = {
-    .enable = (bool(*)(void))udi_hid_exk_enable,
-    .disable = (void (*)(void))udi_hid_exk_disable,
-    .setup = (bool(*)(void))udi_hid_exk_setup,
+    .enable     = (bool (*)(void))udi_hid_exk_enable,
+    .disable    = (void (*)(void))udi_hid_exk_disable,
+    .setup      = (bool (*)(void))udi_hid_exk_setup,
     .getsetting = (uint8_t(*)(void))udi_hid_exk_getsetting,
     .sof_notify = NULL,
 };
@@ -424,39 +372,37 @@ COMPILER_WORD_ALIGNED
 static uint8_t udi_hid_exk_report_trans[UDI_HID_EXK_REPORT_SIZE];
 
 COMPILER_WORD_ALIGNED
-UDC_DESC_STORAGE udi_hid_exk_report_desc_t udi_hid_exk_report_desc = {
-    {
-        // System Control Collection (8 bits)
-
-        0x05, 0x01,         // Usage Page (Generic Desktop),
-        0x09, 0x80,         // Usage (System Control),
-        0xA1, 0x01,         // Collection (Application),
-        0x85, REPORT_ID_SYSTEM,         //   Report ID (2) (System),
-        0x16, 0x01, 0x00,   //   Logical Minimum (1),
-        0x26, 0x03, 0x00,   //   Logical Maximum (3),
-        0x1A, 0x81, 0x00,   //   Usage Minimum (81) (System Power Down),
-        0x2A, 0x83, 0x00,   //   Usage Maximum (83) (System Wake Up),
-        0x75, 0x10,         //   Report Size (16),
-        0x95, 0x01,         //   Report Count (1),
-        0x81, 0x00,         //   Input (Data, Array),
-        0xC0,               // End Collection - System Control
-
-        // Consumer Control Collection - Media Keys (16 bits)
-
-        0x05, 0x0C,         // Usage Page (Consumer),
-        0x09, 0x01,         // Usage (Consumer Control),
-        0xA1, 0x01,         // Collection (Application),
-        0x85, REPORT_ID_CONSUMER,         //   Report ID (3) (Consumer),
-        0x16, 0x01, 0x00,   //   Logical Minimum (1),
-        0x26, 0x9C, 0x02,   //   Logical Maximum (668),
-        0x1A, 0x01, 0x00,   //   Usage Minimum (1),
-        0x2A, 0x9C, 0x02,   //   Usage Maximum (668),
-        0x75, 0x10,         //   Report Size (16),
-        0x95, 0x01,         //   Report Count (1),
-        0x81, 0x00,         //   Input (Data, Array),
-        0xC0,               // End Collection - Consumer Control
-    }
-};
+UDC_DESC_STORAGE udi_hid_exk_report_desc_t udi_hid_exk_report_desc = {{
+    // System Control Collection (8 bits)
+
+    0x05, 0x01,              // Usage Page (Generic Desktop),
+    0x09, 0x80,              // Usage (System Control),
+    0xA1, 0x01,              // Collection (Application),
+    0x85, REPORT_ID_SYSTEM,  //   Report ID (2) (System),
+    0x16, 0x01, 0x00,        //   Logical Minimum (1),
+    0x26, 0x03, 0x00,        //   Logical Maximum (3),
+    0x1A, 0x81, 0x00,        //   Usage Minimum (81) (System Power Down),
+    0x2A, 0x83, 0x00,        //   Usage Maximum (83) (System Wake Up),
+    0x75, 0x10,              //   Report Size (16),
+    0x95, 0x01,              //   Report Count (1),
+    0x81, 0x00,              //   Input (Data, Array),
+    0xC0,                    // End Collection - System Control
+
+    // Consumer Control Collection - Media Keys (16 bits)
+
+    0x05, 0x0C,                // Usage Page (Consumer),
+    0x09, 0x01,                // Usage (Consumer Control),
+    0xA1, 0x01,                // Collection (Application),
+    0x85, REPORT_ID_CONSUMER,  //   Report ID (3) (Consumer),
+    0x16, 0x01, 0x00,          //   Logical Minimum (1),
+    0x26, 0x9C, 0x02,          //   Logical Maximum (668),
+    0x1A, 0x01, 0x00,          //   Usage Minimum (1),
+    0x2A, 0x9C, 0x02,          //   Usage Maximum (668),
+    0x75, 0x10,                //   Report Size (16),
+    0x95, 0x01,                //   Report Count (1),
+    0x81, 0x00,                //   Input (Data, Array),
+    0xC0,                      // End Collection - Consumer Control
+}};
 
 static bool udi_hid_exk_setreport(void);
 
@@ -464,51 +410,34 @@ static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
 
 static void udi_hid_exk_setreport_valid(void);
 
-bool udi_hid_exk_enable(void)
-{
+bool udi_hid_exk_enable(void) {
     // Initialize internal values
-    udi_hid_exk_rate = 0;
-    udi_hid_exk_protocol = 0;
+    udi_hid_exk_rate                   = 0;
+    udi_hid_exk_protocol               = 0;
     udi_hid_exk_b_report_trans_ongoing = false;
     memset(udi_hid_exk_report.raw, 0, UDI_HID_EXK_REPORT_SIZE);
     udi_hid_exk_b_report_valid = false;
     return UDI_HID_EXK_ENABLE_EXT();
 }
 
-void udi_hid_exk_disable(void)
-{
-    UDI_HID_EXK_DISABLE_EXT();
-}
+void udi_hid_exk_disable(void) { UDI_HID_EXK_DISABLE_EXT(); }
 
-bool udi_hid_exk_setup(void)
-{
-    return udi_hid_setup(&udi_hid_exk_rate,
-                            &udi_hid_exk_protocol,
-                            (uint8_t *) &udi_hid_exk_report_desc,
-                            udi_hid_exk_setreport);
-}
+bool udi_hid_exk_setup(void) { return udi_hid_setup(&udi_hid_exk_rate, &udi_hid_exk_protocol, (uint8_t *)&udi_hid_exk_report_desc, udi_hid_exk_setreport); }
 
-uint8_t udi_hid_exk_getsetting(void)
-{
-    return 0;
-}
+uint8_t udi_hid_exk_getsetting(void) { return 0; }
 
-static bool udi_hid_exk_setreport(void)
-{
-    if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8))
-            && (0 == (0xFF & udd_g_ctrlreq.req.wValue))
-            && (1 == udd_g_ctrlreq.req.wLength)) {
+static bool udi_hid_exk_setreport(void) {
+    if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (1 == udd_g_ctrlreq.req.wLength)) {
         // Report OUT type on report ID 0 from USB Host
-        udd_g_ctrlreq.payload = &udi_hid_exk_report_set;
-        udd_g_ctrlreq.callback = udi_hid_exk_setreport_valid;
+        udd_g_ctrlreq.payload      = &udi_hid_exk_report_set;
+        udd_g_ctrlreq.callback     = udi_hid_exk_setreport_valid;
         udd_g_ctrlreq.payload_size = 1;
         return true;
     }
     return false;
 }
 
-bool udi_hid_exk_send_report(void)
-{
+bool udi_hid_exk_send_report(void) {
     if (!main_b_exk_enable) {
         return false;
     }
@@ -518,19 +447,13 @@ bool udi_hid_exk_send_report(void)
     }
 
     memcpy(udi_hid_exk_report_trans, udi_hid_exk_report.raw, UDI_HID_EXK_REPORT_SIZE);
-    udi_hid_exk_b_report_valid = false;
-    udi_hid_exk_b_report_trans_ongoing =
-            udd_ep_run(UDI_HID_EXK_EP_IN | USB_EP_DIR_IN,
-                        false,
-                        udi_hid_exk_report_trans,
-                        UDI_HID_EXK_REPORT_SIZE,
-                        udi_hid_exk_report_sent);
+    udi_hid_exk_b_report_valid         = false;
+    udi_hid_exk_b_report_trans_ongoing = udd_ep_run(UDI_HID_EXK_EP_IN | USB_EP_DIR_IN, false, udi_hid_exk_report_trans, UDI_HID_EXK_REPORT_SIZE, udi_hid_exk_report_sent);
 
     return udi_hid_exk_b_report_trans_ongoing;
 }
 
-static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep)
-{
+static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
     UNUSED(status);
     UNUSED(nb_sent);
     UNUSED(ep);
@@ -540,27 +463,24 @@ static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
     }
 }
 
-static void udi_hid_exk_setreport_valid(void)
-{
+static void udi_hid_exk_setreport_valid(void) {}
 
-}
-
-#endif //EXK
+#endif  // EXK
 
 //********************************************************************************************
 // MOU Mouse
 //********************************************************************************************
 #ifdef MOU
 
-bool udi_hid_mou_enable(void);
-void udi_hid_mou_disable(void);
-bool udi_hid_mou_setup(void);
+bool    udi_hid_mou_enable(void);
+void    udi_hid_mou_disable(void);
+bool    udi_hid_mou_setup(void);
 uint8_t udi_hid_mou_getsetting(void);
 
 UDC_DESC_STORAGE udi_api_t udi_api_hid_mou = {
-    .enable = (bool(*)(void))udi_hid_mou_enable,
-    .disable = (void (*)(void))udi_hid_mou_disable,
-    .setup = (bool(*)(void))udi_hid_mou_setup,
+    .enable     = (bool (*)(void))udi_hid_mou_enable,
+    .disable    = (void (*)(void))udi_hid_mou_disable,
+    .setup      = (bool (*)(void))udi_hid_mou_setup,
     .getsetting = (uint8_t(*)(void))udi_hid_mou_getsetting,
     .sof_notify = NULL,
 };
@@ -571,8 +491,8 @@ static uint8_t udi_hid_mou_rate;
 COMPILER_WORD_ALIGNED
 static uint8_t udi_hid_mou_protocol;
 
-//COMPILER_WORD_ALIGNED
-//uint8_t udi_hid_mou_report_set; //No set report
+// COMPILER_WORD_ALIGNED
+// uint8_t udi_hid_mou_report_set; //No set report
 
 bool udi_hid_mou_b_report_valid;
 
@@ -585,87 +505,71 @@ COMPILER_WORD_ALIGNED
 static uint8_t udi_hid_mou_report_trans[UDI_HID_MOU_REPORT_SIZE];
 
 COMPILER_WORD_ALIGNED
-UDC_DESC_STORAGE udi_hid_mou_report_desc_t udi_hid_mou_report_desc = {
-    {
-        0x05, 0x01,         // Usage Page (Generic Desktop),
-        0x09, 0x02,         // Usage (Mouse),
-        0xA1, 0x01,         // Collection (Application),
-        0x09, 0x01,         //   Usage (Pointer),
-        0xA1, 0x00,         //   Collection (Physical),
-        0x05, 0x09,         //     Usage Page (Buttons),
-        0x19, 0x01,         //     Usage Minimum (01),
-        0x29, 0x05,         //     Usage Maximun (05),
-        0x15, 0x00,         //     Logical Minimum (0),
-        0x25, 0x01,         //     Logical Maximum (1),
-        0x95, 0x05,         //     Report Count (5),
-        0x75, 0x01,         //     Report Size (1),
-        0x81, 0x02,         //     Input (Data, Variable, Absolute), ;5 button bits
-        0x95, 0x01,         //     Report Count (1),
-        0x75, 0x03,         //     Report Size (3),
-        0x81, 0x01,         //     Input (Constant), ;3 bit padding,
-
-        0x05, 0x01,         //     Usage Page (Generic Desktop),
-        0x09, 0x30,         //     Usage (X),
-        0x09, 0x31,         //     Usage (Y),
-        0x15, 0x81,         //     Logical Minimum (-127),
-        0x25, 0x7F,         //     Logical Maximum (127),
-        0x95, 0x02,         //     Report Count (2),
-        0x75, 0x08,         //     Report Size (8),
-        0x81, 0x06,         //     Input (Data, Variable, Relative), ;2 position bytes (X & Y),
-
-        0x09, 0x38,         //     Usage (Wheel),
-        0x15, 0x81,         //     Logical Minimum (-127),
-        0x25, 0x7F,         //     Logical Maximum (127),
-        0x95, 0x01,         //     Report Count (1),
-        0x75, 0x08,         //     Report Size (8),
-        0x81, 0x06,         //     Input (Data, Variable, Relative),
-
-        0x05, 0x0C,         //     Usage Page (Consumer),
-        0x0A, 0x38, 0x02,   //     Usage (AC Pan (Horizontal wheel)),
-        0x15, 0x81,         //     Logical Minimum (-127),
-        0x25, 0x7F,         //     Logical Maximum (127),
-        0x95, 0x01,         //     Report Count (1),
-        0x75, 0x08,         //     Report Size (8),
-        0x81, 0x06,         //     Input (Data, Variable, Relative),
-
-        0xC0,               //   End Collection,
-        0xC0,               // End Collection
-    }
-};
+UDC_DESC_STORAGE udi_hid_mou_report_desc_t udi_hid_mou_report_desc = {{
+    0x05, 0x01,  // Usage Page (Generic Desktop),
+    0x09, 0x02,  // Usage (Mouse),
+    0xA1, 0x01,  // Collection (Application),
+    0x09, 0x01,  //   Usage (Pointer),
+    0xA1, 0x00,  //   Collection (Physical),
+    0x05, 0x09,  //     Usage Page (Buttons),
+    0x19, 0x01,  //     Usage Minimum (01),
+    0x29, 0x05,  //     Usage Maximun (05),
+    0x15, 0x00,  //     Logical Minimum (0),
+    0x25, 0x01,  //     Logical Maximum (1),
+    0x95, 0x05,  //     Report Count (5),
+    0x75, 0x01,  //     Report Size (1),
+    0x81, 0x02,  //     Input (Data, Variable, Absolute), ;5 button bits
+    0x95, 0x01,  //     Report Count (1),
+    0x75, 0x03,  //     Report Size (3),
+    0x81, 0x01,  //     Input (Constant), ;3 bit padding,
+
+    0x05, 0x01,  //     Usage Page (Generic Desktop),
+    0x09, 0x30,  //     Usage (X),
+    0x09, 0x31,  //     Usage (Y),
+    0x15, 0x81,  //     Logical Minimum (-127),
+    0x25, 0x7F,  //     Logical Maximum (127),
+    0x95, 0x02,  //     Report Count (2),
+    0x75, 0x08,  //     Report Size (8),
+    0x81, 0x06,  //     Input (Data, Variable, Relative), ;2 position bytes (X & Y),
+
+    0x09, 0x38,  //     Usage (Wheel),
+    0x15, 0x81,  //     Logical Minimum (-127),
+    0x25, 0x7F,  //     Logical Maximum (127),
+    0x95, 0x01,  //     Report Count (1),
+    0x75, 0x08,  //     Report Size (8),
+    0x81, 0x06,  //     Input (Data, Variable, Relative),
+
+    0x05, 0x0C,        //     Usage Page (Consumer),
+    0x0A, 0x38, 0x02,  //     Usage (AC Pan (Horizontal wheel)),
+    0x15, 0x81,        //     Logical Minimum (-127),
+    0x25, 0x7F,        //     Logical Maximum (127),
+    0x95, 0x01,        //     Report Count (1),
+    0x75, 0x08,        //     Report Size (8),
+    0x81, 0x06,        //     Input (Data, Variable, Relative),
+
+    0xC0,  //   End Collection,
+    0xC0,  // End Collection
+}};
 
 static void udi_hid_mou_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
 
-bool udi_hid_mou_enable(void)
-{
+bool udi_hid_mou_enable(void) {
     // Initialize internal values
-    udi_hid_mou_rate = 0;
-    udi_hid_mou_protocol = 0;
+    udi_hid_mou_rate                   = 0;
+    udi_hid_mou_protocol               = 0;
     udi_hid_mou_b_report_trans_ongoing = false;
     memset(udi_hid_mou_report, 0, UDI_HID_MOU_REPORT_SIZE);
     udi_hid_mou_b_report_valid = false;
     return UDI_HID_MOU_ENABLE_EXT();
 }
 
-void udi_hid_mou_disable(void)
-{
-    UDI_HID_MOU_DISABLE_EXT();
-}
+void udi_hid_mou_disable(void) { UDI_HID_MOU_DISABLE_EXT(); }
 
-bool udi_hid_mou_setup(void)
-{
-    return udi_hid_setup(&udi_hid_mou_rate,
-                            &udi_hid_mou_protocol,
-                            (uint8_t *) &udi_hid_mou_report_desc,
-                            NULL);
-}
+bool udi_hid_mou_setup(void) { return udi_hid_setup(&udi_hid_mou_rate, &udi_hid_mou_protocol, (uint8_t *)&udi_hid_mou_report_desc, NULL); }
 
-uint8_t udi_hid_mou_getsetting(void)
-{
-    return 0;
-}
+uint8_t udi_hid_mou_getsetting(void) { return 0; }
 
-bool udi_hid_mou_send_report(void)
-{
+bool udi_hid_mou_send_report(void) {
     if (!main_b_mou_enable) {
         return false;
     }
@@ -675,19 +579,13 @@ bool udi_hid_mou_send_report(void)
     }
 
     memcpy(udi_hid_mou_report_trans, udi_hid_mou_report, UDI_HID_MOU_REPORT_SIZE);
-    udi_hid_mou_b_report_valid = false;
-    udi_hid_mou_b_report_trans_ongoing =
-            udd_ep_run(UDI_HID_MOU_EP_IN | USB_EP_DIR_IN,
-                        false,
-                        udi_hid_mou_report_trans,
-                        UDI_HID_MOU_REPORT_SIZE,
-                        udi_hid_mou_report_sent);
+    udi_hid_mou_b_report_valid         = false;
+    udi_hid_mou_b_report_trans_ongoing = udd_ep_run(UDI_HID_MOU_EP_IN | USB_EP_DIR_IN, false, udi_hid_mou_report_trans, UDI_HID_MOU_REPORT_SIZE, udi_hid_mou_report_sent);
 
     return udi_hid_mou_b_report_trans_ongoing;
 }
 
-static void udi_hid_mou_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep)
-{
+static void udi_hid_mou_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
     UNUSED(status);
     UNUSED(nb_sent);
     UNUSED(ep);
@@ -697,22 +595,22 @@ static void udi_hid_mou_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
     }
 }
 
-#endif //MOU
+#endif  // MOU
 
 //********************************************************************************************
 // RAW
 //********************************************************************************************
 #ifdef RAW
 
-bool udi_hid_raw_enable(void);
-void udi_hid_raw_disable(void);
-bool udi_hid_raw_setup(void);
+bool    udi_hid_raw_enable(void);
+void    udi_hid_raw_disable(void);
+bool    udi_hid_raw_setup(void);
 uint8_t udi_hid_raw_getsetting(void);
 
 UDC_DESC_STORAGE udi_api_t udi_api_hid_raw = {
-    .enable = (bool(*)(void))udi_hid_raw_enable,
-    .disable = (void (*)(void))udi_hid_raw_disable,
-    .setup = (bool(*)(void))udi_hid_raw_setup,
+    .enable     = (bool (*)(void))udi_hid_raw_enable,
+    .disable    = (void (*)(void))udi_hid_raw_disable,
+    .setup      = (bool (*)(void))udi_hid_raw_setup,
     .getsetting = (uint8_t(*)(void))udi_hid_raw_getsetting,
     .sof_notify = NULL,
 };
@@ -737,76 +635,56 @@ COMPILER_WORD_ALIGNED
 static uint8_t udi_hid_raw_report_trans[UDI_HID_RAW_REPORT_SIZE];
 
 COMPILER_WORD_ALIGNED
-UDC_DESC_STORAGE udi_hid_raw_report_desc_t udi_hid_raw_report_desc = {
-    {
-        0x06,         // Usage Page (Vendor Defined)
-        0xFF, 0xFF,
-        0x0A,         // Usage (Mouse)
-        0xFF, 0xFF,
-        0xA1, 0x01,   // Collection (Application)
-        0x75, 0x08,   //   Report Size (8)
-        0x15, 0x00,   //   Logical Minimum (0)
-        0x25, 0xFF,   //   Logical Maximum (255)
-        0x95, 0x40,   //     Report Count
-        0x09, 0x01,   //     Usage (Input)
-        0x81, 0x02,   //     Input (Data
-        0x95, 0x40,   //     Report Count
-        0x09, 0x02,   //     Usage (Output)
-        0x91, 0x02,   //     Output (Data
-        0xC0,         // End Collection - Consumer Control
-    }
-};
+UDC_DESC_STORAGE udi_hid_raw_report_desc_t udi_hid_raw_report_desc = {{
+    0x06,  // Usage Page (Vendor Defined)
+    0xFF, 0xFF,
+    0x0A,                    // Usage (Mouse)
+    0xFF, 0xFF, 0xA1, 0x01,  // Collection (Application)
+    0x75, 0x08,              //   Report Size (8)
+    0x15, 0x00,              //   Logical Minimum (0)
+    0x25, 0xFF,              //   Logical Maximum (255)
+    0x95, 0x40,              //     Report Count
+    0x09, 0x01,              //     Usage (Input)
+    0x81, 0x02,              //     Input (Data
+    0x95, 0x40,              //     Report Count
+    0x09, 0x02,              //     Usage (Output)
+    0x91, 0x02,              //     Output (Data
+    0xC0,                    // End Collection - Consumer Control
+}};
 
 static bool udi_hid_raw_setreport(void);
 static void udi_hid_raw_setreport_valid(void);
 
 static void udi_hid_raw_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
 
-bool udi_hid_raw_enable(void)
-{
+bool udi_hid_raw_enable(void) {
     // Initialize internal values
-    udi_hid_raw_rate = 0;
-    udi_hid_raw_protocol = 0;
+    udi_hid_raw_rate                   = 0;
+    udi_hid_raw_protocol               = 0;
     udi_hid_raw_b_report_trans_ongoing = false;
     memset(udi_hid_raw_report, 0, UDI_HID_RAW_REPORT_SIZE);
     udi_hid_raw_b_report_valid = false;
     return UDI_HID_RAW_ENABLE_EXT();
 }
 
-void udi_hid_raw_disable(void)
-{
-    UDI_HID_RAW_DISABLE_EXT();
-}
+void udi_hid_raw_disable(void) { UDI_HID_RAW_DISABLE_EXT(); }
 
-bool udi_hid_raw_setup(void)
-{
-    return udi_hid_setup(&udi_hid_raw_rate,
-                            &udi_hid_raw_protocol,
-                            (uint8_t *) &udi_hid_raw_report_desc,
-                            udi_hid_raw_setreport);
-}
+bool udi_hid_raw_setup(void) { return udi_hid_setup(&udi_hid_raw_rate, &udi_hid_raw_protocol, (uint8_t *)&udi_hid_raw_report_desc, udi_hid_raw_setreport); }
 
-uint8_t udi_hid_raw_getsetting(void)
-{
-    return 0;
-}
+uint8_t udi_hid_raw_getsetting(void) { return 0; }
 
-static bool udi_hid_raw_setreport(void)
-{
-    if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8))
-            && (0 == (0xFF & udd_g_ctrlreq.req.wValue))
-            && (UDI_HID_RAW_REPORT_SIZE == udd_g_ctrlreq.req.wLength)) {
+static bool udi_hid_raw_setreport(void) {
+    if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (UDI_HID_RAW_REPORT_SIZE == udd_g_ctrlreq.req.wLength)) {
         // Report OUT type on report ID 0 from USB Host
-        udd_g_ctrlreq.payload = udi_hid_raw_report_set;
-        udd_g_ctrlreq.callback = udi_hid_raw_setreport_valid; //must call routine to transform setreport to LED state
+        udd_g_ctrlreq.payload      = udi_hid_raw_report_set;
+        udd_g_ctrlreq.callback     = udi_hid_raw_setreport_valid;  // must call routine to transform setreport to LED state
         udd_g_ctrlreq.payload_size = UDI_HID_RAW_REPORT_SIZE;
         return true;
     }
     return false;
 }
 
-bool udi_hid_raw_send_report(void)
-{
+bool udi_hid_raw_send_report(void) {
     if (!main_b_raw_enable) {
         return false;
     }
@@ -815,20 +693,14 @@ bool udi_hid_raw_send_report(void)
         return false;
     }
 
-    memcpy(udi_hid_raw_report_trans, udi_hid_raw_report,UDI_HID_RAW_REPORT_SIZE);
-    udi_hid_raw_b_report_valid = false;
-    udi_hid_raw_b_report_trans_ongoing =
-            udd_ep_run(UDI_HID_RAW_EP_IN | USB_EP_DIR_IN,
-                        false,
-                        udi_hid_raw_report_trans,
-                        UDI_HID_RAW_REPORT_SIZE,
-                        udi_hid_raw_report_sent);
+    memcpy(udi_hid_raw_report_trans, udi_hid_raw_report, UDI_HID_RAW_REPORT_SIZE);
+    udi_hid_raw_b_report_valid         = false;
+    udi_hid_raw_b_report_trans_ongoing = udd_ep_run(UDI_HID_RAW_EP_IN | USB_EP_DIR_IN, false, udi_hid_raw_report_trans, UDI_HID_RAW_REPORT_SIZE, udi_hid_raw_report_sent);
 
     return udi_hid_raw_b_report_trans_ongoing;
 }
 
-static void udi_hid_raw_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep)
-{
+static void udi_hid_raw_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
     UNUSED(status);
     UNUSED(nb_sent);
     UNUSED(ep);
@@ -838,27 +710,24 @@ static void udi_hid_raw_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
     }
 }
 
-static void udi_hid_raw_setreport_valid(void)
-{
+static void udi_hid_raw_setreport_valid(void) {}
 
-}
-
-#endif //RAW
+#endif  // RAW
 
 //********************************************************************************************
 // CON
 //********************************************************************************************
 #ifdef CON
 
-bool udi_hid_con_enable(void);
-void udi_hid_con_disable(void);
-bool udi_hid_con_setup(void);
+bool    udi_hid_con_enable(void);
+void    udi_hid_con_disable(void);
+bool    udi_hid_con_setup(void);
 uint8_t udi_hid_con_getsetting(void);
 
 UDC_DESC_STORAGE udi_api_t udi_api_hid_con = {
-    .enable = (bool(*)(void))udi_hid_con_enable,
-    .disable = (void (*)(void))udi_hid_con_disable,
-    .setup = (bool(*)(void))udi_hid_con_setup,
+    .enable     = (bool (*)(void))udi_hid_con_enable,
+    .disable    = (void (*)(void))udi_hid_con_disable,
+    .setup      = (bool (*)(void))udi_hid_con_setup,
     .getsetting = (uint8_t(*)(void))udi_hid_con_getsetting,
     .sof_notify = NULL,
 };
@@ -883,76 +752,57 @@ COMPILER_WORD_ALIGNED
 static uint8_t udi_hid_con_report_trans[UDI_HID_CON_REPORT_SIZE];
 
 COMPILER_WORD_ALIGNED
-UDC_DESC_STORAGE udi_hid_con_report_desc_t udi_hid_con_report_desc = {
-    {
-        0x06, 0x31, 0xFF,           // Vendor Page (PJRC Teensy compatible)
-        0x09, 0x74,                 // Vendor Usage (PJRC Teensy compatible)
-        0xA1, 0x01,                 // Collection (Application)
-            0x09, 0x75,             //   Usage (Vendor)
-            0x15, 0x00,             //   Logical Minimum (0x00)
-            0x26, 0xFF, 0x00,       //   Logical Maximum (0x00FF)
-            0x95, CONSOLE_EPSIZE,   //   Report Count
-            0x75, 0x08,             //   Report Size (8)
-            0x81, 0x02,             //   Input (Data)
-            0x09, 0x76,             //   Usage (Vendor)
-            0x15, 0x00,             //   Logical Minimum (0x00)
-            0x26, 0xFF, 0x00,       //   Logical Maximum (0x00FF)
-            0x95, CONSOLE_EPSIZE,   //   Report Count
-            0x75, 0x08,             //   Report Size (8)
-            0x91, 0x02,             //   Output (Data)
-        0xC0,                       // End Collection
-    }
-};
+UDC_DESC_STORAGE udi_hid_con_report_desc_t udi_hid_con_report_desc = {{
+    0x06, 0x31,           0xFF,  // Vendor Page (PJRC Teensy compatible)
+    0x09, 0x74,                  // Vendor Usage (PJRC Teensy compatible)
+    0xA1, 0x01,                  // Collection (Application)
+    0x09, 0x75,                  //   Usage (Vendor)
+    0x15, 0x00,                  //   Logical Minimum (0x00)
+    0x26, 0xFF,           0x00,  //   Logical Maximum (0x00FF)
+    0x95, CONSOLE_EPSIZE,        //   Report Count
+    0x75, 0x08,                  //   Report Size (8)
+    0x81, 0x02,                  //   Input (Data)
+    0x09, 0x76,                  //   Usage (Vendor)
+    0x15, 0x00,                  //   Logical Minimum (0x00)
+    0x26, 0xFF,           0x00,  //   Logical Maximum (0x00FF)
+    0x95, CONSOLE_EPSIZE,        //   Report Count
+    0x75, 0x08,                  //   Report Size (8)
+    0x91, 0x02,                  //   Output (Data)
+    0xC0,                        // End Collection
+}};
 
 static bool udi_hid_con_setreport(void);
 static void udi_hid_con_setreport_valid(void);
 
 static void udi_hid_con_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
 
-bool udi_hid_con_enable(void)
-{
+bool udi_hid_con_enable(void) {
     // Initialize internal values
-    udi_hid_con_rate = 0;
-    udi_hid_con_protocol = 0;
+    udi_hid_con_rate                   = 0;
+    udi_hid_con_protocol               = 0;
     udi_hid_con_b_report_trans_ongoing = false;
     memset(udi_hid_con_report, 0, UDI_HID_CON_REPORT_SIZE);
     udi_hid_con_b_report_valid = false;
     return UDI_HID_CON_ENABLE_EXT();
 }
 
-void udi_hid_con_disable(void)
-{
-    UDI_HID_CON_DISABLE_EXT();
-}
+void udi_hid_con_disable(void) { UDI_HID_CON_DISABLE_EXT(); }
 
-bool udi_hid_con_setup(void)
-{
-    return udi_hid_setup(&udi_hid_con_rate,
-                            &udi_hid_con_protocol,
-                            (uint8_t *) &udi_hid_con_report_desc,
-                            udi_hid_con_setreport);
-}
+bool udi_hid_con_setup(void) { return udi_hid_setup(&udi_hid_con_rate, &udi_hid_con_protocol, (uint8_t *)&udi_hid_con_report_desc, udi_hid_con_setreport); }
 
-uint8_t udi_hid_con_getsetting(void)
-{
-    return 0;
-}
+uint8_t udi_hid_con_getsetting(void) { return 0; }
 
-static bool udi_hid_con_setreport(void)
-{
-    if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8))
-            && (0 == (0xFF & udd_g_ctrlreq.req.wValue))
-            && (UDI_HID_CON_REPORT_SIZE == udd_g_ctrlreq.req.wLength)) {
-        udd_g_ctrlreq.payload = udi_hid_con_report_set;
-        udd_g_ctrlreq.callback = udi_hid_con_setreport_valid;
+static bool udi_hid_con_setreport(void) {
+    if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (UDI_HID_CON_REPORT_SIZE == udd_g_ctrlreq.req.wLength)) {
+        udd_g_ctrlreq.payload      = udi_hid_con_report_set;
+        udd_g_ctrlreq.callback     = udi_hid_con_setreport_valid;
         udd_g_ctrlreq.payload_size = UDI_HID_CON_REPORT_SIZE;
         return true;
     }
     return false;
 }
 
-bool udi_hid_con_send_report(void)
-{
+bool udi_hid_con_send_report(void) {
     if (!main_b_con_enable) {
         return false;
     }
@@ -961,20 +811,14 @@ bool udi_hid_con_send_report(void)
         return false;
     }
 
-    memcpy(udi_hid_con_report_trans, udi_hid_con_report,UDI_HID_CON_REPORT_SIZE);
-    udi_hid_con_b_report_valid = false;
-    udi_hid_con_b_report_trans_ongoing =
-            udd_ep_run(UDI_HID_CON_EP_IN | USB_EP_DIR_IN,
-                        false,
-                        udi_hid_con_report_trans,
-                        UDI_HID_CON_REPORT_SIZE,
-                        udi_hid_con_report_sent);
+    memcpy(udi_hid_con_report_trans, udi_hid_con_report, UDI_HID_CON_REPORT_SIZE);
+    udi_hid_con_b_report_valid         = false;
+    udi_hid_con_b_report_trans_ongoing = udd_ep_run(UDI_HID_CON_EP_IN | USB_EP_DIR_IN, false, udi_hid_con_report_trans, UDI_HID_CON_REPORT_SIZE, udi_hid_con_report_sent);
 
     return udi_hid_con_b_report_trans_ongoing;
 }
 
-static void udi_hid_con_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep)
-{
+static void udi_hid_con_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
     UNUSED(status);
     UNUSED(nb_sent);
     UNUSED(ep);
@@ -984,9 +828,6 @@ static void udi_hid_con_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
     }
 }
 
-static void udi_hid_con_setreport_valid(void)
-{
-
-}
+static void udi_hid_con_setreport_valid(void) {}
 
-#endif //CON
+#endif  // CON
index e442919a9b6d482a783ac6c36aa276988831c634..82b1cbfe072d42d525e3c19adc06966e943c6509 100644 (file)
@@ -59,59 +59,59 @@ extern "C" {
 //******************************************************************************
 #ifdef KBD
 extern UDC_DESC_STORAGE udi_api_t udi_api_hid_kbd;
-extern bool udi_hid_kbd_b_report_valid;
-extern volatile bool udi_hid_kbd_b_report_trans_ongoing;
-extern uint8_t udi_hid_kbd_report_set;
-bool udi_hid_kbd_send_report(void);
-#endif //KBD
+extern bool                       udi_hid_kbd_b_report_valid;
+extern volatile bool              udi_hid_kbd_b_report_trans_ongoing;
+extern uint8_t                    udi_hid_kbd_report_set;
+bool                              udi_hid_kbd_send_report(void);
+#endif  // KBD
 
 //********************************************************************************************
 // NKRO Keyboard
 //********************************************************************************************
 #ifdef NKRO
 extern UDC_DESC_STORAGE udi_api_t udi_api_hid_nkro;
-extern bool udi_hid_nkro_b_report_valid;
-extern volatile bool udi_hid_nkro_b_report_trans_ongoing;
-bool udi_hid_nkro_send_report(void);
-#endif //NKRO
+extern bool                       udi_hid_nkro_b_report_valid;
+extern volatile bool              udi_hid_nkro_b_report_trans_ongoing;
+bool                              udi_hid_nkro_send_report(void);
+#endif  // NKRO
 
 //********************************************************************************************
 // SYS-CTRL interface
 //********************************************************************************************
 #ifdef EXK
 extern UDC_DESC_STORAGE udi_api_t udi_api_hid_exk;
-extern bool udi_hid_exk_b_report_valid;
-extern uint8_t udi_hid_exk_report_set;
-bool udi_hid_exk_send_report(void);
-#endif //EXK
+extern bool                       udi_hid_exk_b_report_valid;
+extern uint8_t                    udi_hid_exk_report_set;
+bool                              udi_hid_exk_send_report(void);
+#endif  // EXK
 
 //********************************************************************************************
 // CON Console
 //********************************************************************************************
 #ifdef CON
 extern UDC_DESC_STORAGE udi_api_t udi_api_hid_con;
-extern bool udi_hid_con_b_report_valid;
-extern uint8_t udi_hid_con_report_set[UDI_HID_CON_REPORT_SIZE];
-extern volatile bool udi_hid_con_b_report_trans_ongoing;
-bool udi_hid_con_send_report(void);
-#endif //CON
+extern bool                       udi_hid_con_b_report_valid;
+extern uint8_t                    udi_hid_con_report_set[UDI_HID_CON_REPORT_SIZE];
+extern volatile bool              udi_hid_con_b_report_trans_ongoing;
+bool                              udi_hid_con_send_report(void);
+#endif  // CON
 
 //********************************************************************************************
 // MOU Mouse
 //********************************************************************************************
 #ifdef MOU
 extern UDC_DESC_STORAGE udi_api_t udi_api_hid_mou;
-extern bool udi_hid_mou_b_report_valid;
-bool udi_hid_mou_send_report(void);
-#endif //MOU
+extern bool                       udi_hid_mou_b_report_valid;
+bool                              udi_hid_mou_send_report(void);
+#endif  // MOU
 
 //********************************************************************************************
 // RAW Raw
 //********************************************************************************************
 #ifdef RAW
 extern UDC_DESC_STORAGE udi_api_t udi_api_hid_raw;
-bool udi_hid_raw_send_report(void);
-#endif //RAW
+bool                              udi_hid_raw_send_report(void);
+#endif  // RAW
 
 //@}
 
@@ -119,4 +119,4 @@ bool udi_hid_raw_send_report(void);
 }
 #endif
 
-#endif // _UDC_HID_KBD_H_
+#endif  // _UDC_HID_KBD_H_
index db5db17ed506b95815d8a5a6b88db282db43dbe2..ec73252b69988ec2174a3a418f5a2b006934389b 100644 (file)
@@ -57,4 +57,4 @@
 
 #include "udi_hid_kbd.h"
 
-#endif // _UDI_HID_KBD_CONF_H_
+#endif  // _UDI_HID_KBD_CONF_H_
index 2d6e35e254e270c4612dcef9639aed18f1bdff7b..4e7deaaa381e7c6a3884c3ae31dfb1ee51ffdffc 100644 (file)
 
 //! USB Device Descriptor
 COMPILER_WORD_ALIGNED
-UDC_DESC_STORAGE usb_dev_desc_t udc_device_desc = {
-    .bLength                   = sizeof(usb_dev_desc_t),
-    .bDescriptorType           = USB_DT_DEVICE,
-    .bcdUSB                    = LE16(USB_V2_0),
-    .bDeviceClass              = DEVICE_CLASS,
-    .bDeviceSubClass           = DEVICE_SUBCLASS,
-    .bDeviceProtocol           = DEVICE_PROTOCOL,
-    .bMaxPacketSize0           = USB_DEVICE_EP_CTRL_SIZE,
-    .idVendor                  = LE16(USB_DEVICE_VENDOR_ID),
-    .idProduct                 = LE16(USB_DEVICE_PRODUCT_ID),
-    .bcdDevice                 = LE16(USB_DEVICE_VERSION),
+UDC_DESC_STORAGE usb_dev_desc_t udc_device_desc = {.bLength         = sizeof(usb_dev_desc_t),
+                                                   .bDescriptorType = USB_DT_DEVICE,
+                                                   .bcdUSB          = LE16(USB_V2_0),
+                                                   .bDeviceClass    = DEVICE_CLASS,
+                                                   .bDeviceSubClass = DEVICE_SUBCLASS,
+                                                   .bDeviceProtocol = DEVICE_PROTOCOL,
+                                                   .bMaxPacketSize0 = USB_DEVICE_EP_CTRL_SIZE,
+                                                   .idVendor        = LE16(USB_DEVICE_VENDOR_ID),
+                                                   .idProduct       = LE16(USB_DEVICE_PRODUCT_ID),
+                                                   .bcdDevice       = LE16(USB_DEVICE_VERSION),
 #ifdef USB_DEVICE_MANUFACTURE_NAME
-    .iManufacturer             = 1,
+                                                   .iManufacturer = 1,
 #else
-    .iManufacturer             = 0,  // No manufacture string
+                                                   .iManufacturer = 0,  // No manufacture string
 #endif
 #ifdef USB_DEVICE_PRODUCT_NAME
-    .iProduct                  = 2,
+                                                   .iProduct = 2,
 #else
-    .iProduct                  = 0,  // No product string
+                                                   .iProduct      = 0,  // No product string
 #endif
 #if (defined USB_DEVICE_SERIAL_NAME || defined USB_DEVICE_GET_SERIAL_NAME_POINTER)
-    .iSerialNumber             = 3,
+                                                   .iSerialNumber = 3,
 #else
-    .iSerialNumber             = 0,  // No serial string
+                                                   .iSerialNumber = 0,  // No serial string
 #endif
-    .bNumConfigurations        = 1
-};
+                                                   .bNumConfigurations = 1};
 
 #if 0
-#ifdef USB_DEVICE_HS_SUPPORT
+#    ifdef USB_DEVICE_HS_SUPPORT
 //! USB Device Qualifier Descriptor for HS
 COMPILER_WORD_ALIGNED
 UDC_DESC_STORAGE usb_dev_qual_desc_t udc_device_qual = {
@@ -108,77 +106,77 @@ UDC_DESC_STORAGE usb_dev_qual_desc_t udc_device_qual = {
     .bMaxPacketSize0           = USB_DEVICE_EP_CTRL_SIZE,
     .bNumConfigurations        = 1
 };
-#endif
+#    endif
 #endif
 
 //! USB Device Configuration Descriptor filled for FS and HS
 COMPILER_WORD_ALIGNED
 UDC_DESC_STORAGE udc_desc_t udc_desc = {
-    .conf.bLength              = sizeof(usb_conf_desc_t),
-    .conf.bDescriptorType      = USB_DT_CONFIGURATION,
-    .conf.wTotalLength         = LE16(sizeof(udc_desc_t)),
-    .conf.bNumInterfaces       = USB_DEVICE_NB_INTERFACE,
-    .conf.bConfigurationValue  = 1,
-    .conf.iConfiguration       = 0,
-    .conf.bmAttributes         = /* USB_CONFIG_ATTR_MUST_SET | */ USB_DEVICE_ATTR,
-    .conf.bMaxPower            = USB_CONFIG_MAX_POWER(USB_DEVICE_POWER),
+    .conf.bLength             = sizeof(usb_conf_desc_t),
+    .conf.bDescriptorType     = USB_DT_CONFIGURATION,
+    .conf.wTotalLength        = LE16(sizeof(udc_desc_t)),
+    .conf.bNumInterfaces      = USB_DEVICE_NB_INTERFACE,
+    .conf.bConfigurationValue = 1,
+    .conf.iConfiguration      = 0,
+    .conf.bmAttributes        = /* USB_CONFIG_ATTR_MUST_SET | */ USB_DEVICE_ATTR,
+    .conf.bMaxPower           = USB_CONFIG_MAX_POWER(USB_DEVICE_POWER),
 #ifdef KBD
-    .hid_kbd                   = UDI_HID_KBD_DESC,
+    .hid_kbd = UDI_HID_KBD_DESC,
 #endif
 #ifdef RAW
-    .hid_raw                   = UDI_HID_RAW_DESC,
+    .hid_raw = UDI_HID_RAW_DESC,
 #endif
 #ifdef MOU
-    .hid_mou                   = UDI_HID_MOU_DESC,
+    .hid_mou = UDI_HID_MOU_DESC,
 #endif
 #ifdef EXK
-  .hid_exk                   = UDI_HID_EXK_DESC,
+    .hid_exk = UDI_HID_EXK_DESC,
 #endif
 #ifdef CON
-  .hid_con                   = UDI_HID_CON_DESC,
+    .hid_con = UDI_HID_CON_DESC,
 #endif
 #ifdef NKRO
-  .hid_nkro                  = UDI_HID_NKRO_DESC,
+    .hid_nkro = UDI_HID_NKRO_DESC,
 #endif
 #ifdef CDC
-  .cdc_serial                = CDC_DESCRIPTOR,
+    .cdc_serial = CDC_DESCRIPTOR,
 #endif
 };
 
 UDC_DESC_STORAGE udi_api_t *udi_apis[USB_DEVICE_NB_INTERFACE] = {
-  #ifdef KBD
+#ifdef KBD
     &udi_api_hid_kbd,
-  #endif
-  #ifdef RAW
+#endif
+#ifdef RAW
     &udi_api_hid_raw,
-  #endif
-  #ifdef MOU
+#endif
+#ifdef MOU
     &udi_api_hid_mou,
-  #endif
-  #ifdef EXK
+#endif
+#ifdef EXK
     &udi_api_hid_exk,
-  #endif
-  #ifdef CON
+#endif
+#ifdef CON
     &udi_api_hid_con,
-  #endif
-  #ifdef NKRO
+#endif
+#ifdef NKRO
     &udi_api_hid_nkro,
-  #endif
-  #ifdef CDC
-  &udi_api_cdc_comm, &udi_api_cdc_data,
-  #endif
+#endif
+#ifdef CDC
+    &udi_api_cdc_comm, &udi_api_cdc_data,
+#endif
 };
 
 //! Add UDI with USB Descriptors FS & HS
-UDC_DESC_STORAGE udc_config_speed_t   udc_config_fshs[1] = {{
-    .desc          = (usb_conf_desc_t UDC_DESC_STORAGE*)&udc_desc,
-    .udi_apis      = udi_apis,
+UDC_DESC_STORAGE udc_config_speed_t udc_config_fshs[1] = {{
+    .desc     = (usb_conf_desc_t UDC_DESC_STORAGE *)&udc_desc,
+    .udi_apis = udi_apis,
 }};
 
 //! Add all information about USB Device in global structure for UDC
 UDC_DESC_STORAGE udc_config_t udc_config = {
     .confdev_lsfs = &udc_device_desc,
-    .conf_lsfs = udc_config_fshs,
+    .conf_lsfs    = udc_config_fshs,
 };
 
 //@}
index 70a6191098abbe3886e5390cadb146c23ef02902..86c7edc94e18feb2f151f6ad065b12c678a09307 100644 (file)
  */
 
 #ifndef ARM_MATH_CM4
- #define ARM_MATH_CM4
+#    define ARM_MATH_CM4
 #endif
 
-#undef LITTLE_ENDIAN  //redefined in samd51j18a.h
+#undef LITTLE_ENDIAN  // redefined in samd51j18a.h
 #include "samd51j18a.h"
 #include "ui.h"
 
@@ -68,37 +68,16 @@ static void ui_wakeup_handler(void)
 }
 #endif
 
-void ui_init(void)
-{
+void ui_init(void) {}
 
-}
+void ui_powerdown(void) {}
 
-void ui_powerdown(void)
-{
+void ui_wakeup_enable(void) {}
 
-}
+void ui_wakeup_disable(void) {}
 
-void ui_wakeup_enable(void)
-{
+void ui_wakeup(void) {}
 
-}
+void ui_process(uint16_t framenumber) {}
 
-void ui_wakeup_disable(void)
-{
-
-}
-
-void ui_wakeup(void)
-{
-
-}
-
-void ui_process(uint16_t framenumber)
-{
-
-}
-
-void ui_kbd_led(uint8_t value)
-{
-
-}
+void ui_kbd_led(uint8_t value) {}
index d1c767d457645a2eb1d6c341d752e68022f1af63..f7bc6523609baf6453aff13c3ebb87e7e9f88a3c 100644 (file)
@@ -73,4 +73,4 @@ void ui_process(uint16_t framenumber);
  */
 void ui_kbd_led(uint8_t value);
 
-#endif // _UI_H_
+#endif  // _UI_H_
index d30d76dd112e11f5af864a125aa5ed786b841a13..b7393660b15ff5e50c17b1b888e747043227fb89 100644 (file)
 #define SAMD11 DEVICE_MODE_ONLY
 
 #ifndef ARM_MATH_CM4
-  #define ARM_MATH_CM4
+#    define ARM_MATH_CM4
 #endif
 
 #include "compiler.h"
-#undef LITTLE_ENDIAN  //redefined in samd51j18a.h
+#undef LITTLE_ENDIAN  // redefined in samd51j18a.h
 #include "samd51j18a.h"
 #include <stdbool.h>
 #include <string.h>
 #include "usb.h"
 
 /** Fields definition from a LPM TOKEN  */
-#define  USB_LPM_ATTRIBUT_BLINKSTATE_MASK      (0xF << 0)
-#define  USB_LPM_ATTRIBUT_HIRD_MASK            (0xF << 4)
-#define  USB_LPM_ATTRIBUT_REMOTEWAKE_MASK      (1 << 8)
-#define  USB_LPM_ATTRIBUT_BLINKSTATE(value)    ((value & 0xF) << 0)
-#define  USB_LPM_ATTRIBUT_HIRD(value)          ((value & 0xF) << 4)
-#define  USB_LPM_ATTRIBUT_REMOTEWAKE(value)    ((value & 1) << 8)
-#define  USB_LPM_ATTRIBUT_BLINKSTATE_L1        USB_LPM_ATTRIBUT_BLINKSTATE(1)
+#define USB_LPM_ATTRIBUT_BLINKSTATE_MASK (0xF << 0)
+#define USB_LPM_ATTRIBUT_HIRD_MASK (0xF << 4)
+#define USB_LPM_ATTRIBUT_REMOTEWAKE_MASK (1 << 8)
+#define USB_LPM_ATTRIBUT_BLINKSTATE(value) ((value & 0xF) << 0)
+#define USB_LPM_ATTRIBUT_HIRD(value) ((value & 0xF) << 4)
+#define USB_LPM_ATTRIBUT_REMOTEWAKE(value) ((value & 1) << 8)
+#define USB_LPM_ATTRIBUT_BLINKSTATE_L1 USB_LPM_ATTRIBUT_BLINKSTATE(1)
 
 /**
  * \brief Mask selecting the index part of an endpoint address
  */
-#define  USB_EP_ADDR_MASK     0x0f
+#define USB_EP_ADDR_MASK 0x0f
 
 /**
  * \brief Endpoint transfer direction is IN
  */
-#define  USB_EP_DIR_IN        0x80
+#define USB_EP_DIR_IN 0x80
 
 /**
  * \brief Endpoint transfer direction is OUT
  */
-#define  USB_EP_DIR_OUT       0x00
+#define USB_EP_DIR_OUT 0x00
 
 /**
  * \name USB SRAM data containing pipe descriptor table
@@ -120,24 +120,13 @@ static struct usb_endpoint_callback_parameter ep_callback_para;
  * \internal USB Device IRQ Mask Bits Map
  */
 static const uint16_t _usb_device_irq_bits[USB_DEVICE_CALLBACK_N] = {
-    USB_DEVICE_INTFLAG_SOF,
-    USB_DEVICE_INTFLAG_EORST,
-    USB_DEVICE_INTFLAG_WAKEUP | USB_DEVICE_INTFLAG_EORSM | USB_DEVICE_INTFLAG_UPRSM,
-    USB_DEVICE_INTFLAG_RAMACER,
-    USB_DEVICE_INTFLAG_SUSPEND,
-    USB_DEVICE_INTFLAG_LPMNYET,
-    USB_DEVICE_INTFLAG_LPMSUSP,
+    USB_DEVICE_INTFLAG_SOF, USB_DEVICE_INTFLAG_EORST, USB_DEVICE_INTFLAG_WAKEUP | USB_DEVICE_INTFLAG_EORSM | USB_DEVICE_INTFLAG_UPRSM, USB_DEVICE_INTFLAG_RAMACER, USB_DEVICE_INTFLAG_SUSPEND, USB_DEVICE_INTFLAG_LPMNYET, USB_DEVICE_INTFLAG_LPMSUSP,
 };
 
 /**
  * \internal USB Device IRQ Mask Bits Map
  */
-static const uint8_t _usb_endpoint_irq_bits[USB_DEVICE_EP_CALLBACK_N] = {
-    USB_DEVICE_EPINTFLAG_TRCPT_Msk,
-    USB_DEVICE_EPINTFLAG_TRFAIL_Msk,
-    USB_DEVICE_EPINTFLAG_RXSTP,
-    USB_DEVICE_EPINTFLAG_STALL_Msk
-};
+static const uint8_t _usb_endpoint_irq_bits[USB_DEVICE_EP_CALLBACK_N] = {USB_DEVICE_EPINTFLAG_TRCPT_Msk, USB_DEVICE_EPINTFLAG_TRFAIL_Msk, USB_DEVICE_EPINTFLAG_RXSTP, USB_DEVICE_EPINTFLAG_STALL_Msk};
 
 /**
  * \brief Registers a USB device callback
@@ -155,10 +144,7 @@ static const uint8_t _usb_endpoint_irq_bits[USB_DEVICE_EP_CALLBACK_N] = {
  * \return Status of the registration operation.
  * \retval STATUS_OK    The callback was registered successfully.
  */
-enum status_code usb_device_register_callback(struct usb_module *module_inst,
-        enum usb_device_callback callback_type,
-        usb_device_callback_t callback_func)
-{
+enum status_code usb_device_register_callback(struct usb_module *module_inst, enum usb_device_callback callback_type, usb_device_callback_t callback_func) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(callback_func);
@@ -184,9 +170,7 @@ enum status_code usb_device_register_callback(struct usb_module *module_inst,
  * \return Status of the de-registration operation.
  * \retval STATUS_OK    The callback was unregistered successfully.
  */
-enum status_code usb_device_unregister_callback(struct usb_module *module_inst,
-        enum usb_device_callback callback_type)
-{
+enum status_code usb_device_unregister_callback(struct usb_module *module_inst, enum usb_device_callback callback_type) {
     /* Sanity check arguments */
     Assert(module_inst);
 
@@ -211,9 +195,7 @@ enum status_code usb_device_unregister_callback(struct usb_module *module_inst,
  * \return Status of the callback enable operation.
  * \retval STATUS_OK    The callback was enabled successfully.
  */
-enum status_code usb_device_enable_callback(struct usb_module *module_inst,
-        enum usb_device_callback callback_type)
-{
+enum status_code usb_device_enable_callback(struct usb_module *module_inst, enum usb_device_callback callback_type) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(module_inst->hw);
@@ -240,9 +222,7 @@ enum status_code usb_device_enable_callback(struct usb_module *module_inst,
  * \return Status of the callback disable operation.
  * \retval STATUS_OK    The callback was disabled successfully.
  */
-enum status_code usb_device_disable_callback(struct usb_module *module_inst,
-        enum usb_device_callback callback_type)
-{
+enum status_code usb_device_disable_callback(struct usb_module *module_inst, enum usb_device_callback callback_type) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(module_inst->hw);
@@ -272,11 +252,7 @@ enum status_code usb_device_disable_callback(struct usb_module *module_inst,
  * \return Status of the registration operation.
  * \retval STATUS_OK    The callback was registered successfully.
  */
-enum status_code usb_device_endpoint_register_callback(
-        struct usb_module *module_inst, uint8_t ep_num,
-        enum usb_device_endpoint_callback callback_type,
-        usb_device_endpoint_callback_t callback_func)
-{
+enum status_code usb_device_endpoint_register_callback(struct usb_module *module_inst, uint8_t ep_num, enum usb_device_endpoint_callback callback_type, usb_device_endpoint_callback_t callback_func) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(ep_num < USB_EPT_NUM);
@@ -304,10 +280,7 @@ enum status_code usb_device_endpoint_register_callback(
  * \return Status of the de-registration operation.
  * \retval STATUS_OK    The callback was unregistered successfully.
  */
-enum status_code usb_device_endpoint_unregister_callback(
-        struct usb_module *module_inst, uint8_t ep_num,
-        enum usb_device_endpoint_callback callback_type)
-{
+enum status_code usb_device_endpoint_unregister_callback(struct usb_module *module_inst, uint8_t ep_num, enum usb_device_endpoint_callback callback_type) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(ep_num < USB_EPT_NUM);
@@ -334,10 +307,7 @@ enum status_code usb_device_endpoint_unregister_callback(
  * \return Status of the callback enable operation.
  * \retval STATUS_OK    The callback was enabled successfully.
  */
-enum status_code usb_device_endpoint_enable_callback(
-        struct usb_module *module_inst, uint8_t ep,
-        enum usb_device_endpoint_callback callback_type)
-{
+enum status_code usb_device_endpoint_enable_callback(struct usb_module *module_inst, uint8_t ep, enum usb_device_endpoint_callback callback_type) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(module_inst->hw);
@@ -349,7 +319,7 @@ enum status_code usb_device_endpoint_enable_callback(
     module_inst->device_endpoint_enabled_callback_mask[ep_num] |= _usb_endpoint_irq_bits[callback_type];
 
     if (callback_type == USB_DEVICE_ENDPOINT_CALLBACK_TRCPT) {
-        if (ep_num == 0) { // control endpoint
+        if (ep_num == 0) {  // control endpoint
             module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRCPT0 | USB_DEVICE_EPINTENSET_TRCPT1;
         } else if (ep & USB_EP_DIR_IN) {
             module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRCPT1;
@@ -359,7 +329,7 @@ enum status_code usb_device_endpoint_enable_callback(
     }
 
     if (callback_type == USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL) {
-        if (ep_num == 0) { // control endpoint
+        if (ep_num == 0) {  // control endpoint
             module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRFAIL0 | USB_DEVICE_EPINTENSET_TRFAIL1;
         } else if (ep & USB_EP_DIR_IN) {
             module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRFAIL1;
@@ -395,10 +365,7 @@ enum status_code usb_device_endpoint_enable_callback(
  * \return Status of the callback disable operation.
  * \retval STATUS_OK    The callback was disabled successfully.
  */
-enum status_code usb_device_endpoint_disable_callback(
-        struct usb_module *module_inst, uint8_t ep,
-        enum usb_device_endpoint_callback callback_type)
-{
+enum status_code usb_device_endpoint_disable_callback(struct usb_module *module_inst, uint8_t ep, enum usb_device_endpoint_callback callback_type) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(module_inst->hw);
@@ -410,17 +377,17 @@ enum status_code usb_device_endpoint_disable_callback(
     module_inst->device_endpoint_enabled_callback_mask[ep_num] &= ~_usb_endpoint_irq_bits[callback_type];
 
     if (callback_type == USB_DEVICE_ENDPOINT_CALLBACK_TRCPT) {
-        if (ep_num == 0) { // control endpoint
-            module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg =  USB_DEVICE_EPINTENCLR_TRCPT0 | USB_DEVICE_EPINTENCLR_TRCPT1;
+        if (ep_num == 0) {  // control endpoint
+            module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT0 | USB_DEVICE_EPINTENCLR_TRCPT1;
         } else if (ep & USB_EP_DIR_IN) {
-            module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg =  USB_DEVICE_EPINTENCLR_TRCPT1;
+            module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT1;
         } else {
-            module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg =  USB_DEVICE_EPINTENCLR_TRCPT0;
+            module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT0;
         }
     }
 
     if (callback_type == USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL) {
-        if (ep_num == 0) { // control endpoint
+        if (ep_num == 0) {  // control endpoint
             module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRFAIL0 | USB_DEVICE_EPINTENCLR_TRFAIL1;
         } else if (ep & USB_EP_DIR_IN) {
             module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRFAIL1;
@@ -460,16 +427,15 @@ enum status_code usb_device_endpoint_disable_callback(
  *
  * \param[out] ep_config  Configuration structure to initialize to default values
  */
-void usb_device_endpoint_get_config_defaults(struct usb_device_endpoint_config *ep_config)
-{
+void usb_device_endpoint_get_config_defaults(struct usb_device_endpoint_config *ep_config) {
     /* Sanity check arguments */
     Assert(ep_config);
 
     /* Write default config to config struct */
     ep_config->ep_address = 0;
-    ep_config->ep_size = USB_ENDPOINT_8_BYTE;
-    ep_config->auto_zlp = false;
-    ep_config->ep_type = USB_DEVICE_ENDPOINT_TYPE_CONTROL;
+    ep_config->ep_size    = USB_ENDPOINT_8_BYTE;
+    ep_config->auto_zlp   = false;
+    ep_config->ep_type    = USB_DEVICE_ENDPOINT_TYPE_CONTROL;
 }
 
 /**
@@ -486,25 +452,22 @@ void usb_device_endpoint_get_config_defaults(struct usb_device_endpoint_config *
  * \retval STATUS_OK         The device endpoint was configured successfully
  * \retval STATUS_ERR_DENIED The endpoint address is already configured
  */
-enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
-        struct usb_device_endpoint_config *ep_config)
-{
+enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst, struct usb_device_endpoint_config *ep_config) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(ep_config);
 
-    uint8_t ep_num = ep_config->ep_address & USB_EP_ADDR_MASK;
+    uint8_t ep_num  = ep_config->ep_address & USB_EP_ADDR_MASK;
     uint8_t ep_bank = (ep_config->ep_address & USB_EP_DIR_IN) ? 1 : 0;
 
     switch (ep_config->ep_type) {
         case USB_DEVICE_ENDPOINT_TYPE_DISABLE:
-            module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg = USB_DEVICE_EPCFG_EPTYPE0(0) |  USB_DEVICE_EPCFG_EPTYPE1(0);
+            module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg = USB_DEVICE_EPCFG_EPTYPE0(0) | USB_DEVICE_EPCFG_EPTYPE1(0);
             return STATUS_OK;
 
         case USB_DEVICE_ENDPOINT_TYPE_CONTROL:
-            if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0 && \
-                (module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0) {
-                module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg = USB_DEVICE_EPCFG_EPTYPE0(1) | USB_DEVICE_EPCFG_EPTYPE1(1);
+            if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0 && (module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0) {
+                module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg       = USB_DEVICE_EPCFG_EPTYPE0(1) | USB_DEVICE_EPCFG_EPTYPE1(1);
                 module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK0RDY;
                 module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
             } else {
@@ -523,14 +486,14 @@ enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
 
         case USB_DEVICE_ENDPOINT_TYPE_ISOCHRONOUS:
             if (ep_bank) {
-                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0){
+                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0) {
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE1(2);
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
                 } else {
                     return STATUS_ERR_DENIED;
                 }
             } else {
-                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0){
+                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0) {
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE0(2);
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK0RDY;
                 } else {
@@ -541,14 +504,14 @@ enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
 
         case USB_DEVICE_ENDPOINT_TYPE_BULK:
             if (ep_bank) {
-                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0){
+                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0) {
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE1(3);
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
                 } else {
                     return STATUS_ERR_DENIED;
                 }
             } else {
-                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0){
+                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0) {
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE0(3);
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK0RDY;
                 } else {
@@ -559,14 +522,14 @@ enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
 
         case USB_DEVICE_ENDPOINT_TYPE_INTERRUPT:
             if (ep_bank) {
-                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0){
+                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0) {
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE1(4);
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
                 } else {
                     return STATUS_ERR_DENIED;
                 }
             } else {
-                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0){
+                if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0) {
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE0(4);
                     module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK0RDY;
                 } else {
@@ -583,7 +546,7 @@ enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
 
     if (true == ep_config->auto_zlp) {
         usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[ep_bank].PCKSIZE.reg |= USB_DEVICE_PCKSIZE_AUTO_ZLP;
-        } else {
+    } else {
         usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[ep_bank].PCKSIZE.reg &= ~USB_DEVICE_PCKSIZE_AUTO_ZLP;
     }
 
@@ -598,8 +561,7 @@ enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
  *
  * \return \c true if endpoint is configured and ready to use
  */
-bool usb_device_endpoint_is_configured(struct usb_module *module_inst, uint8_t ep)
-{
+bool usb_device_endpoint_is_configured(struct usb_module *module_inst, uint8_t ep) {
     uint8_t ep_num = ep & USB_EP_ADDR_MASK;
     uint8_t flag;
 
@@ -611,15 +573,13 @@ bool usb_device_endpoint_is_configured(struct usb_module *module_inst, uint8_t e
     return ((enum usb_device_endpoint_type)(flag) != USB_DEVICE_ENDPOINT_TYPE_DISABLE);
 }
 
-
 /**
  * \brief Abort ongoing job on the endpoint
  *
  * \param module_inst Pointer to USB software instance struct
  * \param ep          Endpoint address
  */
-void usb_device_endpoint_abort_job(struct usb_module *module_inst, uint8_t ep)
-{
+void usb_device_endpoint_abort_job(struct usb_module *module_inst, uint8_t ep) {
     uint8_t ep_num;
     ep_num = ep & USB_EP_ADDR_MASK;
 
@@ -643,8 +603,7 @@ void usb_device_endpoint_abort_job(struct usb_module *module_inst, uint8_t ep)
  *
  * \return \c true if the endpoint is halted
  */
-bool usb_device_endpoint_is_halted(struct usb_module *module_inst, uint8_t ep)
-{
+bool usb_device_endpoint_is_halted(struct usb_module *module_inst, uint8_t ep) {
     uint8_t ep_num = ep & USB_EP_ADDR_MASK;
 
     if (ep & USB_EP_DIR_IN) {
@@ -660,8 +619,7 @@ bool usb_device_endpoint_is_halted(struct usb_module *module_inst, uint8_t ep)
  * \param module_inst Pointer to USB software instance struct
  * \param ep          Endpoint address
  */
-void usb_device_endpoint_set_halt(struct usb_module *module_inst, uint8_t ep)
-{
+void usb_device_endpoint_set_halt(struct usb_module *module_inst, uint8_t ep) {
     uint8_t ep_num = ep & USB_EP_ADDR_MASK;
 
     // Stall endpoint
@@ -678,8 +636,7 @@ void usb_device_endpoint_set_halt(struct usb_module *module_inst, uint8_t ep)
  * \param module_inst Pointer to USB software instance struct
  * \param ep          Endpoint address
  */
-void usb_device_endpoint_clear_halt(struct usb_module *module_inst, uint8_t ep)
-{
+void usb_device_endpoint_clear_halt(struct usb_module *module_inst, uint8_t ep) {
     uint8_t ep_num = ep & USB_EP_ADDR_MASK;
 
     if (ep & USB_EP_DIR_IN) {
@@ -717,9 +674,7 @@ void usb_device_endpoint_clear_halt(struct usb_module *module_inst, uint8_t ep)
  * \retval STATUS_OK Job started successfully
  * \retval STATUS_ERR_DENIED Endpoint is not ready
  */
-enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_inst,uint8_t ep_num,
-        uint8_t* pbuf, uint32_t buf_size)
-{
+enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_inst, uint8_t ep_num, uint8_t *pbuf, uint32_t buf_size) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(module_inst->hw);
@@ -732,10 +687,10 @@ enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_
     };
 
     /* get endpoint configuration from setting register */
-    usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[1].ADDR.reg = (uint32_t)pbuf;
+    usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[1].ADDR.reg                      = (uint32_t)pbuf;
     usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[1].PCKSIZE.bit.MULTI_PACKET_SIZE = 0;
-    usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT = buf_size;
-    module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK1RDY;
+    usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT        = buf_size;
+    module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg                                  = USB_DEVICE_EPSTATUSSET_BK1RDY;
 
     return STATUS_OK;
 }
@@ -752,9 +707,7 @@ enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_
  * \retval STATUS_OK Job started successfully
  * \retval STATUS_ERR_DENIED Endpoint is not ready
  */
-enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_inst,uint8_t ep_num,
-        uint8_t* pbuf, uint32_t buf_size)
-{
+enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_inst, uint8_t ep_num, uint8_t *pbuf, uint32_t buf_size) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(module_inst->hw);
@@ -767,10 +720,10 @@ enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_i
     };
 
     /* get endpoint configuration from setting register */
-    usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[0].ADDR.reg = (uint32_t)pbuf;
+    usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[0].ADDR.reg                      = (uint32_t)pbuf;
     usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[0].PCKSIZE.bit.MULTI_PACKET_SIZE = buf_size;
-    usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT = 0;
-    module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK0RDY;
+    usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT        = 0;
+    module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg                                  = USB_DEVICE_EPSTATUSCLR_BK0RDY;
 
     return STATUS_OK;
 }
@@ -785,24 +738,21 @@ enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_i
  * \retval STATUS_OK Job started successfully
  * \retval STATUS_ERR_DENIED Endpoint is not ready
  */
-enum status_code usb_device_endpoint_setup_buffer_job(struct usb_module *module_inst,
-        uint8_t* pbuf)
-{
+enum status_code usb_device_endpoint_setup_buffer_job(struct usb_module *module_inst, uint8_t *pbuf) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(module_inst->hw);
 
     /* get endpoint configuration from setting register */
-    usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].ADDR.reg = (uint32_t)pbuf;
+    usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].ADDR.reg                      = (uint32_t)pbuf;
     usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].PCKSIZE.bit.MULTI_PACKET_SIZE = 8;
-    usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT = 0;
-    module_inst->hw->DEVICE.DeviceEndpoint[0].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK0RDY;
+    usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT        = 0;
+    module_inst->hw->DEVICE.DeviceEndpoint[0].EPSTATUSCLR.reg                                  = USB_DEVICE_EPSTATUSCLR_BK0RDY;
 
     return STATUS_OK;
 }
 
-static void _usb_device_interrupt_handler(void)
-{
+static void _usb_device_interrupt_handler(void) {
     uint16_t ep_inst;
     uint16_t flags, flags_run;
     ep_inst = _usb_instances->hw->DEVICE.EPINTSMRY.reg;
@@ -812,21 +762,16 @@ static void _usb_device_interrupt_handler(void)
         int i;
 
         /* get interrupt flags */
-        flags = _usb_instances->hw->DEVICE.INTFLAG.reg;
-        flags_run = flags &
-                _usb_instances->device_enabled_callback_mask &
-                _usb_instances->device_registered_callback_mask;
+        flags     = _usb_instances->hw->DEVICE.INTFLAG.reg;
+        flags_run = flags & _usb_instances->device_enabled_callback_mask & _usb_instances->device_registered_callback_mask;
 
-        for (i = 0; i < USB_DEVICE_CALLBACK_N; i ++) {
+        for (i = 0; i < USB_DEVICE_CALLBACK_N; i++) {
             if (flags & _usb_device_irq_bits[i]) {
-                _usb_instances->hw->DEVICE.INTFLAG.reg =
-                        _usb_device_irq_bits[i];
+                _usb_instances->hw->DEVICE.INTFLAG.reg = _usb_device_irq_bits[i];
             }
             if (flags_run & _usb_device_irq_bits[i]) {
                 if (i == USB_DEVICE_CALLBACK_LPMSUSP) {
-                    device_callback_lpm_wakeup_enable =
-                            usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].EXTREG.bit.VARIABLE
-                            & USB_LPM_ATTRIBUT_REMOTEWAKE_MASK;
+                    device_callback_lpm_wakeup_enable = usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].EXTREG.bit.VARIABLE & USB_LPM_ATTRIBUT_REMOTEWAKE_MASK;
                 }
                 (_usb_instances->device_callback[i])(_usb_instances, &device_callback_lpm_wakeup_enable);
             }
@@ -836,25 +781,22 @@ static void _usb_device_interrupt_handler(void)
         /* endpoint interrupt */
 
         for (uint8_t i = 0; i < USB_EPT_NUM; i++) {
-
             if (ep_inst & (1 << i)) {
-                flags = _usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg;
-                flags_run = flags &
-                        _usb_instances->device_endpoint_enabled_callback_mask[i] &
-                        _usb_instances->device_endpoint_registered_callback_mask[i];
+                flags     = _usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg;
+                flags_run = flags & _usb_instances->device_endpoint_enabled_callback_mask[i] & _usb_instances->device_endpoint_registered_callback_mask[i];
 
                 // endpoint transfer stall interrupt
                 if (flags & USB_DEVICE_EPINTFLAG_STALL_Msk) {
                     if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_STALL1) {
                         _usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_STALL1;
-                        ep_callback_para.endpoint_address = USB_EP_DIR_IN | i;
+                        ep_callback_para.endpoint_address                          = USB_EP_DIR_IN | i;
                     } else if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_STALL0) {
                         _usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_STALL0;
-                        ep_callback_para.endpoint_address = USB_EP_DIR_OUT | i;
+                        ep_callback_para.endpoint_address                          = USB_EP_DIR_OUT | i;
                     }
 
                     if (flags_run & USB_DEVICE_EPINTFLAG_STALL_Msk) {
-                        (_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_STALL])(_usb_instances,&ep_callback_para);
+                        (_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_STALL])(_usb_instances, &ep_callback_para);
                     }
                     return;
                 }
@@ -862,9 +804,9 @@ static void _usb_device_interrupt_handler(void)
                 // endpoint received setup interrupt
                 if (flags & USB_DEVICE_EPINTFLAG_RXSTP) {
                     _usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
-                    if(_usb_instances->device_endpoint_enabled_callback_mask[i] & _usb_endpoint_irq_bits[USB_DEVICE_ENDPOINT_CALLBACK_RXSTP]) {
+                    if (_usb_instances->device_endpoint_enabled_callback_mask[i] & _usb_endpoint_irq_bits[USB_DEVICE_ENDPOINT_CALLBACK_RXSTP]) {
                         ep_callback_para.received_bytes = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT);
-                        (_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_RXSTP])(_usb_instances,&ep_callback_para);
+                        (_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_RXSTP])(_usb_instances, &ep_callback_para);
                     }
                     return;
                 }
@@ -873,17 +815,17 @@ static void _usb_device_interrupt_handler(void)
                 if (flags & USB_DEVICE_EPINTFLAG_TRCPT_Msk) {
                     if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT1) {
                         _usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
-                        ep_callback_para.endpoint_address = USB_EP_DIR_IN | i;
-                        ep_callback_para.sent_bytes = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT);
+                        ep_callback_para.endpoint_address                          = USB_EP_DIR_IN | i;
+                        ep_callback_para.sent_bytes                                = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT);
 
                     } else if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT0) {
                         _usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
-                        ep_callback_para.endpoint_address = USB_EP_DIR_OUT | i;
-                        ep_callback_para.received_bytes = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT);
-                        ep_callback_para.out_buffer_size = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].PCKSIZE.bit.MULTI_PACKET_SIZE);
+                        ep_callback_para.endpoint_address                          = USB_EP_DIR_OUT | i;
+                        ep_callback_para.received_bytes                            = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT);
+                        ep_callback_para.out_buffer_size                           = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].PCKSIZE.bit.MULTI_PACKET_SIZE);
                     }
-                    if(flags_run & USB_DEVICE_EPINTFLAG_TRCPT_Msk) {
-                        (_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_TRCPT])(_usb_instances,&ep_callback_para);
+                    if (flags_run & USB_DEVICE_EPINTFLAG_TRCPT_Msk) {
+                        (_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_TRCPT])(_usb_instances, &ep_callback_para);
                     }
                     return;
                 }
@@ -899,7 +841,7 @@ static void _usb_device_interrupt_handler(void)
                         if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT1) {
                             return;
                         }
-                    } else if(_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRFAIL0) {
+                    } else if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRFAIL0) {
                         _usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRFAIL0;
                         if (usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].STATUS_BK.reg & USB_DEVICE_STATUS_BK_ERRORFLOW) {
                             usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].STATUS_BK.reg &= ~USB_DEVICE_STATUS_BK_ERRORFLOW;
@@ -910,8 +852,8 @@ static void _usb_device_interrupt_handler(void)
                         }
                     }
 
-                    if(flags_run & USB_DEVICE_EPINTFLAG_TRFAIL_Msk) {
-                        (_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL])(_usb_instances,&ep_callback_para);
+                    if (flags_run & USB_DEVICE_EPINTFLAG_TRFAIL_Msk) {
+                        (_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL])(_usb_instances, &ep_callback_para);
                     }
                     return;
                 }
@@ -925,13 +867,13 @@ static void _usb_device_interrupt_handler(void)
  *
  * \param module_inst pointer to USB module instance
  */
-void usb_enable(struct usb_module *module_inst)
-{
+void usb_enable(struct usb_module *module_inst) {
     Assert(module_inst);
     Assert(module_inst->hw);
 
     module_inst->hw->DEVICE.CTRLA.reg |= USB_CTRLA_ENABLE;
-    while (module_inst->hw->DEVICE.SYNCBUSY.reg == USB_SYNCBUSY_ENABLE);
+    while (module_inst->hw->DEVICE.SYNCBUSY.reg == USB_SYNCBUSY_ENABLE)
+        ;
 }
 
 /**
@@ -939,68 +881,56 @@ void usb_enable(struct usb_module *module_inst)
  *
  * \param module_inst pointer to USB module instance
  */
-void usb_disable(struct usb_module *module_inst)
-{
+void usb_disable(struct usb_module *module_inst) {
     Assert(module_inst);
     Assert(module_inst->hw);
 
     module_inst->hw->DEVICE.INTENCLR.reg = USB_DEVICE_INTENCLR_MASK;
-    module_inst->hw->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_MASK;
+    module_inst->hw->DEVICE.INTFLAG.reg  = USB_DEVICE_INTFLAG_MASK;
     module_inst->hw->DEVICE.CTRLA.reg &= ~USB_CTRLA_ENABLE;
-    while (module_inst->hw->DEVICE.SYNCBUSY.reg == USB_SYNCBUSY_ENABLE);
+    while (module_inst->hw->DEVICE.SYNCBUSY.reg == USB_SYNCBUSY_ENABLE)
+        ;
 }
 
 /**
  * \brief Interrupt handler for the USB module.
  */
-void USB_0_Handler(void)
-{
+void USB_0_Handler(void) {
     if (_usb_instances->hw->DEVICE.CTRLA.bit.MODE) {
-
     } else {
         /*device mode ISR */
         _usb_device_interrupt_handler();
     }
 }
 
-void USB_1_Handler(void)
-{
-    _usb_device_interrupt_handler();
-}
+void USB_1_Handler(void) { _usb_device_interrupt_handler(); }
 
-void USB_2_Handler(void)
-{
-    _usb_device_interrupt_handler();
-}
+void USB_2_Handler(void) { _usb_device_interrupt_handler(); }
 
-void USB_3_Handler(void)
-{
-    _usb_device_interrupt_handler();
-}
+void USB_3_Handler(void) { _usb_device_interrupt_handler(); }
 
 /**
  * \brief Get the default USB module settings
  *
  * \param[out] module_config  Configuration structure to initialize to default values
  */
-void usb_get_config_defaults(struct usb_config *module_config)
-{
+void usb_get_config_defaults(struct usb_config *module_config) {
     Assert(module_config);
 
     /* Sanity check arguments */
     Assert(module_config);
     /* Write default configuration to config struct */
     module_config->select_host_mode = 0;
-    module_config->run_in_standby = 1;
+    module_config->run_in_standby   = 1;
     module_config->source_generator = 0;
-    module_config->speed_mode = USB_SPEED_FULL;
+    module_config->speed_mode       = USB_SPEED_FULL;
 }
 
-#define NVM_USB_PAD_TRANSN_POS  45
+#define NVM_USB_PAD_TRANSN_POS 45
 #define NVM_USB_PAD_TRANSN_SIZE 5
-#define NVM_USB_PAD_TRANSP_POS  50
+#define NVM_USB_PAD_TRANSP_POS 50
 #define NVM_USB_PAD_TRANSP_SIZE 5
-#define NVM_USB_PAD_TRIM_POS  55
+#define NVM_USB_PAD_TRIM_POS 55
 #define NVM_USB_PAD_TRIM_SIZE 3
 
 /**
@@ -1020,56 +950,61 @@ void usb_get_config_defaults(struct usb_config *module_config)
 
 #define GCLK_USB 10
 
-enum status_code usb_init(struct usb_module *module_inst, Usb *const hw,
-        struct usb_config *module_config)
-{
+enum status_code usb_init(struct usb_module *module_inst, Usb *const hw, struct usb_config *module_config) {
     /* Sanity check arguments */
     Assert(hw);
     Assert(module_inst);
     Assert(module_config);
 
-    uint32_t i,j;
+    uint32_t i, j;
     uint32_t pad_transn, pad_transp, pad_trim;
 
-    Gclk *pgclk = GCLK;
-    Mclk *pmclk = MCLK;
-    Port *pport = PORT;
-    Oscctrl *posc = OSCCTRL;
+    Gclk *   pgclk = GCLK;
+    Mclk *   pmclk = MCLK;
+    Port *   pport = PORT;
+    Oscctrl *posc  = OSCCTRL;
 
     _usb_instances = module_inst;
 
     /* Associate the software module instance with the hardware module */
     module_inst->hw = hw;
 
-    //setup peripheral and synchronous bus clocks to USB
-    pmclk->AHBMASK.bit.USB_ = 1;
+    // setup peripheral and synchronous bus clocks to USB
+    pmclk->AHBMASK.bit.USB_  = 1;
     pmclk->APBBMASK.bit.USB_ = 1;
 
     /* Set up the USB DP/DN pins */
-    pport->Group[0].PMUX[12].reg = 0x77; //PA24, PA25, function column H for USB D-, D+
+    pport->Group[0].PMUX[12].reg          = 0x77;  // PA24, PA25, function column H for USB D-, D+
     pport->Group[0].PINCFG[24].bit.PMUXEN = 1;
     pport->Group[0].PINCFG[25].bit.PMUXEN = 1;
-    pport->Group[1].PMUX[11].bit.PMUXE = 7; //PB22, function column H for USB SOF_1KHz output
+    pport->Group[1].PMUX[11].bit.PMUXE    = 7;  // PB22, function column H for USB SOF_1KHz output
     pport->Group[1].PINCFG[22].bit.PMUXEN = 1;
 
-    //configure and enable DFLL for USB clock recovery mode at 48MHz
+    // configure and enable DFLL for USB clock recovery mode at 48MHz
     posc->DFLLCTRLA.bit.ENABLE = 0;
-    while (posc->DFLLSYNC.bit.ENABLE);
-    while (posc->DFLLSYNC.bit.DFLLCTRLB);
+    while (posc->DFLLSYNC.bit.ENABLE)
+        ;
+    while (posc->DFLLSYNC.bit.DFLLCTRLB)
+        ;
     posc->DFLLCTRLB.bit.USBCRM = 1;
-    while (posc->DFLLSYNC.bit.DFLLCTRLB);
+    while (posc->DFLLSYNC.bit.DFLLCTRLB)
+        ;
     posc->DFLLCTRLB.bit.MODE = 1;
-    while (posc->DFLLSYNC.bit.DFLLCTRLB);
+    while (posc->DFLLSYNC.bit.DFLLCTRLB)
+        ;
     posc->DFLLCTRLB.bit.QLDIS = 0;
-    while (posc->DFLLSYNC.bit.DFLLCTRLB);
+    while (posc->DFLLSYNC.bit.DFLLCTRLB)
+        ;
     posc->DFLLCTRLB.bit.CCDIS = 1;
-    posc->DFLLMUL.bit.MUL = 0xbb80;   //4800 x 1KHz
-    while (posc->DFLLSYNC.bit.DFLLMUL);
+    posc->DFLLMUL.bit.MUL     = 0xbb80;  // 4800 x 1KHz
+    while (posc->DFLLSYNC.bit.DFLLMUL)
+        ;
     posc->DFLLCTRLA.bit.ENABLE = 1;
-    while (posc->DFLLSYNC.bit.ENABLE);
+    while (posc->DFLLSYNC.bit.ENABLE)
+        ;
 
     /* Setup clock for module */
-    pgclk->PCHCTRL[GCLK_USB].bit.GEN = 0;
+    pgclk->PCHCTRL[GCLK_USB].bit.GEN  = 0;
     pgclk->PCHCTRL[GCLK_USB].bit.CHEN = 1;
 
     /* Reset */
@@ -1084,21 +1019,21 @@ enum status_code usb_init(struct usb_module *module_inst, Usb *const hw,
 
     /* Load Pad Calibration */
 
-    pad_transn = (USB_FUSES_TRANSN_ADDR >>  USB_FUSES_TRANSN_Pos) & USB_FUSES_TRANSN_Msk;
+    pad_transn = (USB_FUSES_TRANSN_ADDR >> USB_FUSES_TRANSN_Pos) & USB_FUSES_TRANSN_Msk;
     if (pad_transn == 0x1F) {
         pad_transn = 5;
     }
 
     hw->DEVICE.PADCAL.bit.TRANSN = pad_transn;
 
-    pad_transp = (USB_FUSES_TRANSP_ADDR >>  USB_FUSES_TRANSP_Pos) & USB_FUSES_TRANSP_Msk;
+    pad_transp = (USB_FUSES_TRANSP_ADDR >> USB_FUSES_TRANSP_Pos) & USB_FUSES_TRANSP_Msk;
     if (pad_transp == 0x1F) {
         pad_transp = 29;
     }
 
     hw->DEVICE.PADCAL.bit.TRANSP = pad_transp;
 
-    pad_trim = (USB_FUSES_TRIM_ADDR >>  USB_FUSES_TRIM_Pos) & USB_FUSES_TRIM_Msk;
+    pad_trim = (USB_FUSES_TRIM_ADDR >> USB_FUSES_TRIM_Pos) & USB_FUSES_TRIM_Msk;
     if (pad_trim == 0x07) {
         pad_trim = 3;
     }
@@ -1106,32 +1041,31 @@ enum status_code usb_init(struct usb_module *module_inst, Usb *const hw,
     hw->DEVICE.PADCAL.bit.TRIM = pad_trim;
 
     /* Set the configuration */
-    hw->DEVICE.CTRLA.bit.MODE = module_config->select_host_mode;
+    hw->DEVICE.CTRLA.bit.MODE     = module_config->select_host_mode;
     hw->DEVICE.CTRLA.bit.RUNSTDBY = module_config->run_in_standby;
-    hw->DEVICE.DESCADD.reg = (uint32_t)(&usb_descriptor_table.usb_endpoint_table[0]);
+    hw->DEVICE.DESCADD.reg        = (uint32_t)(&usb_descriptor_table.usb_endpoint_table[0]);
     if (USB_SPEED_FULL == module_config->speed_mode) {
         module_inst->hw->DEVICE.CTRLB.bit.SPDCONF = USB_DEVICE_CTRLB_SPDCONF_FS_Val;
-    } else if(USB_SPEED_LOW == module_config->speed_mode) {
+    } else if (USB_SPEED_LOW == module_config->speed_mode) {
         module_inst->hw->DEVICE.CTRLB.bit.SPDCONF = USB_DEVICE_CTRLB_SPDCONF_LS_Val;
     }
 
-    memset((uint8_t *)(&usb_descriptor_table.usb_endpoint_table[0]), 0,
-            sizeof(usb_descriptor_table.usb_endpoint_table));
+    memset((uint8_t *)(&usb_descriptor_table.usb_endpoint_table[0]), 0, sizeof(usb_descriptor_table.usb_endpoint_table));
 
     /*  device callback related */
     for (i = 0; i < USB_DEVICE_CALLBACK_N; i++) {
         module_inst->device_callback[i] = NULL;
     }
     for (i = 0; i < USB_EPT_NUM; i++) {
-        for(j = 0; j < USB_DEVICE_EP_CALLBACK_N; j++) {
+        for (j = 0; j < USB_DEVICE_EP_CALLBACK_N; j++) {
             module_inst->device_endpoint_callback[i][j] = NULL;
         }
     }
     module_inst->device_registered_callback_mask = 0;
-    module_inst->device_enabled_callback_mask = 0;
+    module_inst->device_enabled_callback_mask    = 0;
     for (j = 0; j < USB_EPT_NUM; j++) {
         module_inst->device_endpoint_registered_callback_mask[j] = 0;
-        module_inst->device_endpoint_enabled_callback_mask[j] = 0;
+        module_inst->device_endpoint_enabled_callback_mask[j]    = 0;
     }
 
     /* Enable interrupts for this USB module */
@@ -1141,4 +1075,3 @@ enum status_code usb_init(struct usb_module *module_inst, Usb *const hw,
 
     return STATUS_OK;
 }
-
index 9a452881a76e4a9ae74167e25431484be45bba6d..4c937ecdc92f282aece6e9288f9137e40a215480 100644 (file)
@@ -233,8 +233,8 @@ typedef void (*usb_host_pipe_callback_t)(struct usb_module *module_inst, void *)
  * \name Device Callback Functions Types
  * @{
  */
-typedef void (*usb_device_callback_t)(struct usb_module *module_inst, voidpointer);
-typedef void (*usb_device_endpoint_callback_t)(struct usb_module *module_inst, voidpointer);
+typedef void (*usb_device_callback_t)(struct usb_module *module_inst, void *pointer);
+typedef void (*usb_device_endpoint_callback_t)(struct usb_module *module_inst, void *pointer);
 /** @} */
 
 /** USB configurations */
@@ -247,7 +247,7 @@ struct usb_config {
     // enum gclk_generator source_generator;
     uint8_t source_generator;
     /** Speed mode */
-    //enum usb_speed speed_mode;
+    // enum usb_speed speed_mode;
     uint8_t speed_mode;
 };
 
@@ -263,7 +263,7 @@ struct usb_module {
     Usb *hw;
 
     /** Array to store device related callback functions */
-    usb_device_callback_t device_callback[USB_DEVICE_CALLBACK_N];
+    usb_device_callback_t          device_callback[USB_DEVICE_CALLBACK_N];
     usb_device_endpoint_callback_t device_endpoint_callback[USB_EPT_NUM][USB_DEVICE_EP_CALLBACK_N];
     /** Bit mask for device callbacks registered */
     uint16_t device_registered_callback_mask;
@@ -292,7 +292,7 @@ struct usb_endpoint_callback_parameter {
     uint16_t received_bytes;
     uint16_t sent_bytes;
     uint16_t out_buffer_size;
-    uint8_t endpoint_address;
+    uint8_t  endpoint_address;
 };
 
 void usb_enable(struct usb_module *module_inst);
@@ -303,8 +303,7 @@ void usb_disable(struct usb_module *module_inst);
  *
  * \param module_inst Pointer to USB module instance
  */
-static inline uint8_t usb_get_state_machine_status(struct usb_module *module_inst)
-{
+static inline uint8_t usb_get_state_machine_status(struct usb_module *module_inst) {
     /* Sanity check arguments */
     Assert(module_inst);
     Assert(module_inst->hw);
@@ -312,29 +311,22 @@ static inline uint8_t usb_get_state_machine_status(struct usb_module *module_ins
     return module_inst->hw->DEVICE.FSMSTATUS.reg;
 }
 
-void usb_get_config_defaults(struct usb_config *module_config);
-enum status_code usb_init(struct usb_module *module_inst, Usb *const hw,
-        struct usb_config *module_config);
+void             usb_get_config_defaults(struct usb_config *module_config);
+enum status_code usb_init(struct usb_module *module_inst, Usb *const hw, struct usb_config *module_config);
 
 /**
  * \brief Attach USB device to the bus
  *
  * \param module_inst Pointer to USB device module instance
  */
-static inline void usb_device_attach(struct usb_module *module_inst)
-{
-    module_inst->hw->DEVICE.CTRLB.reg &= ~USB_DEVICE_CTRLB_DETACH;
-}
+static inline void usb_device_attach(struct usb_module *module_inst) { module_inst->hw->DEVICE.CTRLB.reg &= ~USB_DEVICE_CTRLB_DETACH; }
 
 /**
  * \brief Detach USB device from the bus
  *
  * \param module_inst Pointer to USB device module instance
  */
-static inline void usb_device_detach(struct usb_module *module_inst)
-{
-    module_inst->hw->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_DETACH;
-}
+static inline void usb_device_detach(struct usb_module *module_inst) { module_inst->hw->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_DETACH; }
 
 /**
  * \brief Get the speed mode of USB device
@@ -342,8 +334,7 @@ static inline void usb_device_detach(struct usb_module *module_inst)
  * \param module_inst Pointer to USB device module instance
  * \return USB Speed mode (\ref usb_speed).
  */
-static inline enum usb_speed usb_device_get_speed(struct usb_module *module_inst)
-{
+static inline enum usb_speed usb_device_get_speed(struct usb_module *module_inst) {
     if (!(module_inst->hw->DEVICE.STATUS.reg & USB_DEVICE_STATUS_SPEED_Msk)) {
         return USB_SPEED_FULL;
     } else {
@@ -357,10 +348,7 @@ static inline enum usb_speed usb_device_get_speed(struct usb_module *module_inst
  * \param module_inst Pointer to USB device module instance
  * \return USB device address value.
  */
-static inline uint8_t usb_device_get_address(struct usb_module *module_inst)
-{
-    return ((uint8_t)(module_inst->hw->DEVICE.DADD.bit.DADD));
-}
+static inline uint8_t usb_device_get_address(struct usb_module *module_inst) { return ((uint8_t)(module_inst->hw->DEVICE.DADD.bit.DADD)); }
 
 /**
  * \brief Set the speed mode of USB device
@@ -368,10 +356,7 @@ static inline uint8_t usb_device_get_address(struct usb_module *module_inst)
  * \param module_inst Pointer to USB device module instance
  * \param address     USB device address value
  */
-static inline void usb_device_set_address(struct usb_module *module_inst, uint8_t address)
-{
-    module_inst->hw->DEVICE.DADD.reg = USB_DEVICE_DADD_ADDEN | address;
-}
+static inline void usb_device_set_address(struct usb_module *module_inst, uint8_t address) { module_inst->hw->DEVICE.DADD.reg = USB_DEVICE_DADD_ADDEN | address; }
 
 /**
  * \brief Get the frame number of USB device
@@ -379,10 +364,7 @@ static inline void usb_device_set_address(struct usb_module *module_inst, uint8_
  * \param module_inst Pointer to USB device module instance
  * \return USB device frame number value.
  */
-static inline uint16_t usb_device_get_frame_number(struct usb_module *module_inst)
-{
-    return ((uint16_t)(module_inst->hw->DEVICE.FNUM.bit.FNUM));
-}
+static inline uint16_t usb_device_get_frame_number(struct usb_module *module_inst) { return ((uint16_t)(module_inst->hw->DEVICE.FNUM.bit.FNUM)); }
 
 /**
  * \brief Get the micro-frame number of USB device
@@ -390,20 +372,14 @@ static inline uint16_t usb_device_get_frame_number(struct usb_module *module_ins
  * \param module_inst Pointer to USB device module instance
  * \return USB device micro-frame number value.
  */
-static inline uint16_t usb_device_get_micro_frame_number(struct usb_module *module_inst)
-{
-    return ((uint16_t)(module_inst->hw->DEVICE.FNUM.reg));
-}
+static inline uint16_t usb_device_get_micro_frame_number(struct usb_module *module_inst) { return ((uint16_t)(module_inst->hw->DEVICE.FNUM.reg)); }
 
 /**
  * \brief USB device send the resume wakeup
  *
  * \param module_inst Pointer to USB device module instance
  */
-static inline void usb_device_send_remote_wake_up(struct usb_module *module_inst)
-{
-    module_inst->hw->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_UPRSM;
-}
+static inline void usb_device_send_remote_wake_up(struct usb_module *module_inst) { module_inst->hw->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_UPRSM; }
 
 /**
  * \brief USB device set the LPM mode
@@ -411,67 +387,45 @@ static inline void usb_device_send_remote_wake_up(struct usb_module *module_inst
  * \param module_inst Pointer to USB device module instance
  * \param lpm_mode    LPM mode
  */
-static inline void usb_device_set_lpm_mode(struct usb_module *module_inst,
-        enum usb_device_lpm_mode lpm_mode)
-{
-    module_inst->hw->DEVICE.CTRLB.bit.LPMHDSK = lpm_mode;
-}
+static inline void usb_device_set_lpm_mode(struct usb_module *module_inst, enum usb_device_lpm_mode lpm_mode) { module_inst->hw->DEVICE.CTRLB.bit.LPMHDSK = lpm_mode; }
 
 /**
  * \name USB Device Callback Management
  * @{
  */
-enum status_code usb_device_register_callback(struct usb_module *module_inst,
-        enum usb_device_callback callback_type,
-        usb_device_callback_t callback_func);
-enum status_code usb_device_unregister_callback(struct usb_module *module_inst,
-        enum usb_device_callback callback_type);
-enum status_code usb_device_enable_callback(struct usb_module *module_inst,
-        enum usb_device_callback callback_type);
-enum status_code usb_device_disable_callback(struct usb_module *module_inst,
-        enum usb_device_callback callback_type);
+enum status_code usb_device_register_callback(struct usb_module *module_inst, enum usb_device_callback callback_type, usb_device_callback_t callback_func);
+enum status_code usb_device_unregister_callback(struct usb_module *module_inst, enum usb_device_callback callback_type);
+enum status_code usb_device_enable_callback(struct usb_module *module_inst, enum usb_device_callback callback_type);
+enum status_code usb_device_disable_callback(struct usb_module *module_inst, enum usb_device_callback callback_type);
 /** @} */
 
 /**
  * \name USB Device Endpoint Configuration
  * @{
  */
-void usb_device_endpoint_get_config_defaults(struct usb_device_endpoint_config *ep_config);
-enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
-        struct usb_device_endpoint_config *ep_config);
-bool usb_device_endpoint_is_configured(struct usb_module *module_inst, uint8_t ep);
+void             usb_device_endpoint_get_config_defaults(struct usb_device_endpoint_config *ep_config);
+enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst, struct usb_device_endpoint_config *ep_config);
+bool             usb_device_endpoint_is_configured(struct usb_module *module_inst, uint8_t ep);
 /** @} */
 
 /**
  * \name USB Device Endpoint Callback Management
  * @{
  */
-enum status_code usb_device_endpoint_register_callback(
-        struct usb_module *module_inst, uint8_t ep_num,
-        enum usb_device_endpoint_callback callback_type,
-        usb_device_endpoint_callback_t callback_func);
-enum status_code usb_device_endpoint_unregister_callback(
-        struct usb_module *module_inst, uint8_t ep_num,
-        enum usb_device_endpoint_callback callback_type);
-enum status_code usb_device_endpoint_enable_callback(
-        struct usb_module *module_inst, uint8_t ep,
-        enum usb_device_endpoint_callback callback_type);
-enum status_code usb_device_endpoint_disable_callback(
-        struct usb_module *module_inst, uint8_t ep,
-        enum usb_device_endpoint_callback callback_type);
+enum status_code usb_device_endpoint_register_callback(struct usb_module *module_inst, uint8_t ep_num, enum usb_device_endpoint_callback callback_type, usb_device_endpoint_callback_t callback_func);
+enum status_code usb_device_endpoint_unregister_callback(struct usb_module *module_inst, uint8_t ep_num, enum usb_device_endpoint_callback callback_type);
+enum status_code usb_device_endpoint_enable_callback(struct usb_module *module_inst, uint8_t ep, enum usb_device_endpoint_callback callback_type);
+enum status_code usb_device_endpoint_disable_callback(struct usb_module *module_inst, uint8_t ep, enum usb_device_endpoint_callback callback_type);
 /** @} */
 
 /**
  * \name USB Device Endpoint Job Management
  * @{
  */
-enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_inst,uint8_t ep_num,
-        uint8_t* pbuf, uint32_t buf_size);
-enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_inst,uint8_t ep_num,
-        uint8_t* pbuf, uint32_t buf_size);
-enum status_code usb_device_endpoint_setup_buffer_job(struct usb_module *module_inst,
-        uint8_t* pbuf);
-void usb_device_endpoint_abort_job(struct usb_module *module_inst, uint8_t ep);
+enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_inst, uint8_t ep_num, uint8_t *pbuf, uint32_t buf_size);
+enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_inst, uint8_t ep_num, uint8_t *pbuf, uint32_t buf_size);
+enum status_code usb_device_endpoint_setup_buffer_job(struct usb_module *module_inst, uint8_t *pbuf);
+void             usb_device_endpoint_abort_job(struct usb_module *module_inst, uint8_t ep);
 /** @} */
 
 /**
index 76ec3aaaa76f0c1343a1d7e2cacc955bdee09a33..a878cb6b7cabdccb09e518ac415331f23a7da5e3 100644 (file)
@@ -18,23 +18,22 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "arm_atsam_protocol.h"
 #include <string.h>
 
-Usb2422 USB2422_shadow;
+Usb2422       USB2422_shadow;
 unsigned char i2c0_buf[34];
 
-const uint16_t MFRNAME[] = { 'M','a','s','s','d','r','o','p',' ','I','n','c','.' }; //Massdrop Inc.
-const uint16_t PRDNAME[] = { 'M','a','s','s','d','r','o','p',' ','H','u','b' }; //Massdrop Hub
+const uint16_t MFRNAME[] = {'M', 'a', 's', 's', 'd', 'r', 'o', 'p', ' ', 'I', 'n', 'c', '.'};  // Massdrop Inc.
+const uint16_t PRDNAME[] = {'M', 'a', 's', 's', 'd', 'r', 'o', 'p', ' ', 'H', 'u', 'b'};       // Massdrop Hub
 #ifndef MD_BOOTLOADER
-//Serial number reported stops before first found space character or at last found character
-const uint16_t SERNAME[] = { 'U','n','a','v','a','i','l','a','b','l','e' }; //Unavailable
+// Serial number reported stops before first found space character or at last found character
+const uint16_t SERNAME[] = {'U', 'n', 'a', 'v', 'a', 'i', 'l', 'a', 'b', 'l', 'e'};  // Unavailable
 #else
-//In production, this field is found, modified, and offset noted as the last 32-bit word in the bootloader space
-//The offset allows the application to use the factory programmed serial (which may differ from the physical serial label)
-//Serial number reported stops before first found space character or when max size is reached
-__attribute__((__aligned__(4)))
-const uint16_t SERNAME[BOOTLOADER_SERIAL_MAX_SIZE] = { 'M','D','H','U','B','B','O','O','T','L','0','0','0','0','0','0','0','0','0','0' };
-//NOTE: Serial replacer will not write a string longer than given here as a precaution, so give enough
+// In production, this field is found, modified, and offset noted as the last 32-bit word in the bootloader space
+// The offset allows the application to use the factory programmed serial (which may differ from the physical serial label)
+// Serial number reported stops before first found space character or when max size is reached
+__attribute__((__aligned__(4))) const uint16_t SERNAME[BOOTLOADER_SERIAL_MAX_SIZE] = {'M', 'D', 'H', 'U', 'B', 'B', 'O', 'O', 'T', 'L', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'};
+// NOTE: Serial replacer will not write a string longer than given here as a precaution, so give enough
 //      space as needed and adjust BOOTLOADER_SERIAL_MAX_SIZE to match amount given
-#endif //MD_BOOTLOADER
+#endif  // MD_BOOTLOADER
 
 uint8_t usb_host_port;
 
@@ -44,95 +43,116 @@ uint8_t usb_extra_state;
 uint8_t usb_extra_manual;
 uint8_t usb_gcr_auto;
 
-#endif //MD_BOOTLOADER
+#endif  // MD_BOOTLOADER
 
 uint16_t adc_extra;
 
-void USB_write2422_block(void)
-{
+void USB_write2422_block(void) {
     unsigned char *dest = i2c0_buf;
     unsigned char *src;
     unsigned char *base = (unsigned char *)&USB2422_shadow;
 
     DBGC(DC_USB_WRITE2422_BLOCK_BEGIN);
 
-    for (src =  base; src < base + 256; src += 32)
-    {
+    for (src = base; src < base + 256; src += 32) {
         dest[0] = src - base;
         dest[1] = 32;
         memcpy(&dest[2], src, 32);
         i2c0_transmit(USB2422_ADDR, dest, 34, 50000);
         SERCOM0->I2CM.CTRLB.bit.CMD = 0x03;
-        while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) { DBGC(DC_USB_WRITE2422_BLOCK_SYNC_SYSOP); }
+        while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) {
+            DBGC(DC_USB_WRITE2422_BLOCK_SYNC_SYSOP);
+        }
         wait_us(100);
     }
 
     DBGC(DC_USB_WRITE2422_BLOCK_COMPLETE);
 }
 
-void USB2422_init(void)
-{
-    Gclk *pgclk = GCLK;
-    Mclk *pmclk = MCLK;
-    Port *pport = PORT;
-    Oscctrl *posc = OSCCTRL;
-    Usb *pusb = USB;
+void USB2422_init(void) {
+    Gclk *   pgclk = GCLK;
+    Mclk *   pmclk = MCLK;
+    Port *   pport = PORT;
+    Oscctrl *posc  = OSCCTRL;
+    Usb *    pusb  = USB;
 
     DBGC(DC_USB2422_INIT_BEGIN);
 
-    while ((v_5v = adc_get(ADC_5V)) < ADC_5V_START_LEVEL) { DBGC(DC_USB2422_INIT_WAIT_5V_LOW); }
+    while ((v_5v = adc_get(ADC_5V)) < ADC_5V_START_LEVEL) {
+        DBGC(DC_USB2422_INIT_WAIT_5V_LOW);
+    }
 
-    //setup peripheral and synchronous bus clocks to USB
-    pgclk->PCHCTRL[10].bit.GEN = 0;
+    // setup peripheral and synchronous bus clocks to USB
+    pgclk->PCHCTRL[10].bit.GEN  = 0;
     pgclk->PCHCTRL[10].bit.CHEN = 1;
-    pmclk->AHBMASK.bit.USB_ = 1;
-    pmclk->APBBMASK.bit.USB_ = 1;
+    pmclk->AHBMASK.bit.USB_     = 1;
+    pmclk->APBBMASK.bit.USB_    = 1;
 
-    //setup port pins for D-, D+, and SOF_1KHZ
-    pport->Group[0].PMUX[12].reg = 0x77; //PA24, PA25, function column H for USB D-, D+
+    // setup port pins for D-, D+, and SOF_1KHZ
+    pport->Group[0].PMUX[12].reg          = 0x77;  // PA24, PA25, function column H for USB D-, D+
     pport->Group[0].PINCFG[24].bit.PMUXEN = 1;
     pport->Group[0].PINCFG[25].bit.PMUXEN = 1;
-    pport->Group[1].PMUX[11].bit.PMUXE = 7; //PB22, function column H for USB SOF_1KHz output
+    pport->Group[1].PMUX[11].bit.PMUXE    = 7;  // PB22, function column H for USB SOF_1KHz output
     pport->Group[1].PINCFG[22].bit.PMUXEN = 1;
 
-    //configure and enable DFLL for USB clock recovery mode at 48MHz
+    // configure and enable DFLL for USB clock recovery mode at 48MHz
     posc->DFLLCTRLA.bit.ENABLE = 0;
-    while (posc->DFLLSYNC.bit.ENABLE) { DBGC(DC_USB2422_INIT_OSC_SYNC_DISABLING); }
-    while (posc->DFLLSYNC.bit.DFLLCTRLB) { DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_1); }
+    while (posc->DFLLSYNC.bit.ENABLE) {
+        DBGC(DC_USB2422_INIT_OSC_SYNC_DISABLING);
+    }
+    while (posc->DFLLSYNC.bit.DFLLCTRLB) {
+        DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_1);
+    }
     posc->DFLLCTRLB.bit.USBCRM = 1;
-    while (posc->DFLLSYNC.bit.DFLLCTRLB) { DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_2); }
+    while (posc->DFLLSYNC.bit.DFLLCTRLB) {
+        DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_2);
+    }
     posc->DFLLCTRLB.bit.MODE = 1;
-    while (posc->DFLLSYNC.bit.DFLLCTRLB) { DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_3); }
+    while (posc->DFLLSYNC.bit.DFLLCTRLB) {
+        DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_3);
+    }
     posc->DFLLCTRLB.bit.QLDIS = 0;
-    while (posc->DFLLSYNC.bit.DFLLCTRLB) { DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_4); }
+    while (posc->DFLLSYNC.bit.DFLLCTRLB) {
+        DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_4);
+    }
     posc->DFLLCTRLB.bit.CCDIS = 1;
-    posc->DFLLMUL.bit.MUL = 0xBB80; //4800 x 1KHz
-    while (posc->DFLLSYNC.bit.DFLLMUL) { DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLMUL); }
+    posc->DFLLMUL.bit.MUL     = 0xBB80;  // 4800 x 1KHz
+    while (posc->DFLLSYNC.bit.DFLLMUL) {
+        DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLMUL);
+    }
     posc->DFLLCTRLA.bit.ENABLE = 1;
-    while (posc->DFLLSYNC.bit.ENABLE) { DBGC(DC_USB2422_INIT_OSC_SYNC_ENABLING); }
+    while (posc->DFLLSYNC.bit.ENABLE) {
+        DBGC(DC_USB2422_INIT_OSC_SYNC_ENABLING);
+    }
 
     pusb->DEVICE.CTRLA.bit.SWRST = 1;
-    while (pusb->DEVICE.SYNCBUSY.bit.SWRST) { DBGC(DC_USB2422_INIT_USB_SYNC_SWRST); }
-    while (pusb->DEVICE.CTRLA.bit.SWRST) { DBGC(DC_USB2422_INIT_USB_WAIT_SWRST); }
-    //calibration from factory presets
+    while (pusb->DEVICE.SYNCBUSY.bit.SWRST) {
+        DBGC(DC_USB2422_INIT_USB_SYNC_SWRST);
+    }
+    while (pusb->DEVICE.CTRLA.bit.SWRST) {
+        DBGC(DC_USB2422_INIT_USB_WAIT_SWRST);
+    }
+    // calibration from factory presets
     pusb->DEVICE.PADCAL.bit.TRANSN = (USB_FUSES_TRANSN_ADDR >> USB_FUSES_TRANSN_Pos) & USB_FUSES_TRANSN_Msk;
     pusb->DEVICE.PADCAL.bit.TRANSP = (USB_FUSES_TRANSP_ADDR >> USB_FUSES_TRANSP_Pos) & USB_FUSES_TRANSP_Msk;
-    pusb->DEVICE.PADCAL.bit.TRIM = (USB_FUSES_TRIM_ADDR >> USB_FUSES_TRIM_Pos) & USB_FUSES_TRIM_Msk;
-    //device mode, enabled
-    pusb->DEVICE.CTRLB.bit.SPDCONF = 0; //full speed
-    pusb->DEVICE.CTRLA.bit.MODE = 0;
-    pusb->DEVICE.CTRLA.bit.ENABLE = 1;
-    while (pusb->DEVICE.SYNCBUSY.bit.ENABLE) { DBGC(DC_USB2422_INIT_USB_SYNC_ENABLING); }
+    pusb->DEVICE.PADCAL.bit.TRIM   = (USB_FUSES_TRIM_ADDR >> USB_FUSES_TRIM_Pos) & USB_FUSES_TRIM_Msk;
+    // device mode, enabled
+    pusb->DEVICE.CTRLB.bit.SPDCONF = 0;  // full speed
+    pusb->DEVICE.CTRLA.bit.MODE    = 0;
+    pusb->DEVICE.CTRLA.bit.ENABLE  = 1;
+    while (pusb->DEVICE.SYNCBUSY.bit.ENABLE) {
+        DBGC(DC_USB2422_INIT_USB_SYNC_ENABLING);
+    }
 
     pusb->DEVICE.QOSCTRL.bit.DQOS = 2;
     pusb->DEVICE.QOSCTRL.bit.CQOS = 2;
 
     pport->Group[USB2422_HUB_ACTIVE_GROUP].PINCFG[USB2422_HUB_ACTIVE_PIN].bit.INEN = 1;
 
-    i2c0_init(); //IC2 clk must be high at USB2422 reset release time to signal SMB configuration
+    i2c0_init();  // IC2 clk must be high at USB2422 reset release time to signal SMB configuration
 
-    sr_exp_data.bit.HUB_CONNECT = 1; //connect signal
-    sr_exp_data.bit.HUB_RESET_N = 1; //reset high
+    sr_exp_data.bit.HUB_CONNECT = 1;  // connect signal
+    sr_exp_data.bit.HUB_RESET_N = 1;  // reset high
     SR_EXP_WriteData();
 
     wait_us(100);
@@ -140,78 +160,74 @@ void USB2422_init(void)
 #ifndef MD_BOOTLOADER
 
     usb_extra_manual = 0;
-    usb_gcr_auto = 1;
+    usb_gcr_auto     = 1;
 
-#endif //MD_BOOTLOADER
+#endif  // MD_BOOTLOADER
 
     DBGC(DC_USB2422_INIT_COMPLETE);
 }
 
-void USB_reset(void)
-{
+void USB_reset(void) {
     DBGC(DC_USB_RESET_BEGIN);
 
-    //pulse reset for at least 1 usec
-    sr_exp_data.bit.HUB_RESET_N = 0; //reset low
+    // pulse reset for at least 1 usec
+    sr_exp_data.bit.HUB_RESET_N = 0;  // reset low
     SR_EXP_WriteData();
     wait_us(2);
-    sr_exp_data.bit.HUB_RESET_N = 1; //reset high to run
+    sr_exp_data.bit.HUB_RESET_N = 1;  // reset high to run
     SR_EXP_WriteData();
 
     DBGC(DC_USB_RESET_COMPLETE);
 }
 
-void USB_configure(void)
-{
+void USB_configure(void) {
     Usb2422 *pusb2422 = &USB2422_shadow;
     memset(pusb2422, 0, sizeof(Usb2422));
 
-    uint16_t *serial_use = (uint16_t *)SERNAME; //Default to use SERNAME from this file
-    uint8_t serial_length = sizeof(SERNAME) / sizeof(uint16_t); //Default to use SERNAME from this file
+    uint16_t *serial_use    = (uint16_t *)SERNAME;                 // Default to use SERNAME from this file
+    uint8_t   serial_length = sizeof(SERNAME) / sizeof(uint16_t);  // Default to use SERNAME from this file
 #ifndef MD_BOOTLOADER
     uint32_t serial_ptrloc = (uint32_t)&_srom - 4;
-#else //MD_BOOTLOADER
+#else                                                      // MD_BOOTLOADER
     uint32_t serial_ptrloc = (uint32_t)&_erom - 4;
-#endif //MD_BOOTLOADER
-    uint32_t serial_address = *(uint32_t *)serial_ptrloc; //Address of bootloader's serial number if available
+#endif                                                     // MD_BOOTLOADER
+    uint32_t serial_address = *(uint32_t *)serial_ptrloc;  // Address of bootloader's serial number if available
 
     DBGC(DC_USB_CONFIGURE_BEGIN);
 
-    if (serial_address != 0xFFFFFFFF && serial_address < serial_ptrloc) //Check for factory programmed serial address
+    if (serial_address != 0xFFFFFFFF && serial_address < serial_ptrloc)  // Check for factory programmed serial address
     {
-        if ((serial_address & 0xFF) % 4 == 0) //Check alignment
+        if ((serial_address & 0xFF) % 4 == 0)  // Check alignment
         {
-            serial_use = (uint16_t *)(serial_address);
+            serial_use    = (uint16_t *)(serial_address);
             serial_length = 0;
-            while ((*(serial_use + serial_length) > 32 && *(serial_use + serial_length) < 127) &&
-                   serial_length < BOOTLOADER_SERIAL_MAX_SIZE)
-            {
+            while ((*(serial_use + serial_length) > 32 && *(serial_use + serial_length) < 127) && serial_length < BOOTLOADER_SERIAL_MAX_SIZE) {
                 serial_length++;
                 DBGC(DC_USB_CONFIGURE_GET_SERIAL);
             }
         }
     }
 
-    //configure Usb2422 registers
-    pusb2422->VID.reg = 0x04D8; // from Microchip 4/19/2018
-    pusb2422->PID.reg = 0xEEC5; // from Microchip 4/19/2018 = Massdrop, Inc. USB Hub
-    pusb2422->DID.reg = 0x0101; // BCD 01.01
-    pusb2422->CFG1.bit.SELF_BUS_PWR = 1; // self powered for now
-    pusb2422->CFG1.bit.HS_DISABLE = 1; // full or high speed
-    //pusb2422->CFG2.bit.COMPOUND = 0; // compound device
-    pusb2422->CFG3.bit.STRING_EN = 1; // strings enabled
-    //pusb2422->NRD.bit.PORT2_NR = 0; // MCU is non-removable
-    pusb2422->MAXPB.reg = 20; // 0mA
-    pusb2422->HCMCB.reg = 20; // 0mA
+    // configure Usb2422 registers
+    pusb2422->VID.reg               = 0x04D8;  // from Microchip 4/19/2018
+    pusb2422->PID.reg               = 0xEEC5;  // from Microchip 4/19/2018 = Massdrop, Inc. USB Hub
+    pusb2422->DID.reg               = 0x0101;  // BCD 01.01
+    pusb2422->CFG1.bit.SELF_BUS_PWR = 1;       // self powered for now
+    pusb2422->CFG1.bit.HS_DISABLE   = 1;       // full or high speed
+    // pusb2422->CFG2.bit.COMPOUND = 0; // compound device
+    pusb2422->CFG3.bit.STRING_EN = 1;  // strings enabled
+    // pusb2422->NRD.bit.PORT2_NR = 0; // MCU is non-removable
+    pusb2422->MAXPB.reg = 20;  // 0mA
+    pusb2422->HCMCB.reg = 20;  // 0mA
     pusb2422->MFRSL.reg = sizeof(MFRNAME) / sizeof(uint16_t);
     pusb2422->PRDSL.reg = sizeof(PRDNAME) / sizeof(uint16_t);
     pusb2422->SERSL.reg = serial_length;
     memcpy(pusb2422->MFRSTR, MFRNAME, sizeof(MFRNAME));
     memcpy(pusb2422->PRDSTR, PRDNAME, sizeof(PRDNAME));
     memcpy(pusb2422->SERSTR, serial_use, serial_length * sizeof(uint16_t));
-    //pusb2422->BOOSTUP.bit.BOOST=3;    //upstream port
-    //pusb2422->BOOSTDOWN.bit.BOOST1=0; // extra port
-    //pusb2422->BOOSTDOWN.bit.BOOST2=2; //MCU is close
+    // pusb2422->BOOSTUP.bit.BOOST=3;    //upstream port
+    // pusb2422->BOOSTDOWN.bit.BOOST1=0; // extra port
+    // pusb2422->BOOSTDOWN.bit.BOOST2=2; //MCU is close
     pusb2422->STCD.bit.USB_ATTACH = 1;
     USB_write2422_block();
 
@@ -220,35 +236,33 @@ void USB_configure(void)
     DBGC(DC_USB_CONFIGURE_COMPLETE);
 }
 
-uint16_t USB_active(void)
-{
-    return (PORT->Group[USB2422_HUB_ACTIVE_GROUP].IN.reg & (1 << USB2422_HUB_ACTIVE_PIN)) != 0;
-}
+uint16_t USB_active(void) { return (PORT->Group[USB2422_HUB_ACTIVE_GROUP].IN.reg & (1 << USB2422_HUB_ACTIVE_PIN)) != 0; }
 
-void USB_set_host_by_voltage(void)
-{
-    //UP is upstream device (HOST)
-    //DN1 is downstream device (EXTRA)
-    //DN2 is keyboard (KEYB)
+void USB_set_host_by_voltage(void) {
+    // UP is upstream device (HOST)
+    // DN1 is downstream device (EXTRA)
+    // DN2 is keyboard (KEYB)
 
     DBGC(DC_USB_SET_HOST_BY_VOLTAGE_BEGIN);
 
     usb_host_port = USB_HOST_PORT_UNKNOWN;
 #ifndef MD_BOOTLOADER
     usb_extra_state = USB_EXTRA_STATE_UNKNOWN;
-#endif //MD_BOOTLOADER
-    sr_exp_data.bit.SRC_1 = 1;       //USBC-1 available for test
-    sr_exp_data.bit.SRC_2 = 1;       //USBC-2 available for test
-    sr_exp_data.bit.E_UP_N = 1;      //HOST disable
-    sr_exp_data.bit.E_DN1_N = 1;     //EXTRA disable
-    sr_exp_data.bit.E_VBUS_1 = 0;    //USBC-1 disable full power I/O
-    sr_exp_data.bit.E_VBUS_2 = 0;    //USBC-2 disable full power I/O
+#endif                             // MD_BOOTLOADER
+    sr_exp_data.bit.SRC_1    = 1;  // USBC-1 available for test
+    sr_exp_data.bit.SRC_2    = 1;  // USBC-2 available for test
+    sr_exp_data.bit.E_UP_N   = 1;  // HOST disable
+    sr_exp_data.bit.E_DN1_N  = 1;  // EXTRA disable
+    sr_exp_data.bit.E_VBUS_1 = 0;  // USBC-1 disable full power I/O
+    sr_exp_data.bit.E_VBUS_2 = 0;  // USBC-2 disable full power I/O
 
     SR_EXP_WriteData();
 
     wait_ms(250);
 
-    while ((v_5v = adc_get(ADC_5V)) < ADC_5V_START_LEVEL) { DBGC(DC_USB_SET_HOST_5V_LOW_WAITING); }
+    while ((v_5v = adc_get(ADC_5V)) < ADC_5V_START_LEVEL) {
+        DBGC(DC_USB_SET_HOST_5V_LOW_WAITING);
+    }
 
     v_con_1 = adc_get(ADC_CON1);
     v_con_2 = adc_get(ADC_CON2);
@@ -256,37 +270,34 @@ void USB_set_host_by_voltage(void)
     v_con_1_boot = v_con_1;
     v_con_2_boot = v_con_2;
 
-    if (v_con_1 > v_con_2)
-    {
-        sr_exp_data.bit.S_UP = 0;        //HOST to USBC-1
-        sr_exp_data.bit.S_DN1 = 1;       //EXTRA to USBC-2
-        sr_exp_data.bit.SRC_1 = 1;       //HOST on USBC-1
-        sr_exp_data.bit.SRC_2 = 0;       //EXTRA available on USBC-2
+    if (v_con_1 > v_con_2) {
+        sr_exp_data.bit.S_UP  = 0;  // HOST to USBC-1
+        sr_exp_data.bit.S_DN1 = 1;  // EXTRA to USBC-2
+        sr_exp_data.bit.SRC_1 = 1;  // HOST on USBC-1
+        sr_exp_data.bit.SRC_2 = 0;  // EXTRA available on USBC-2
 
-        sr_exp_data.bit.E_VBUS_1 = 1;    //USBC-1 enable full power I/O
-        sr_exp_data.bit.E_VBUS_2 = 0;    //USBC-2 disable full power I/O
+        sr_exp_data.bit.E_VBUS_1 = 1;  // USBC-1 enable full power I/O
+        sr_exp_data.bit.E_VBUS_2 = 0;  // USBC-2 disable full power I/O
 
         SR_EXP_WriteData();
 
-        sr_exp_data.bit.E_UP_N = 0;      //HOST enable
+        sr_exp_data.bit.E_UP_N = 0;  // HOST enable
 
         SR_EXP_WriteData();
 
         usb_host_port = USB_HOST_PORT_1;
-    }
-    else
-    {
-        sr_exp_data.bit.S_UP = 1;        //EXTRA to USBC-1
-        sr_exp_data.bit.S_DN1 = 0;       //HOST to USBC-2
-        sr_exp_data.bit.SRC_1 = 0;       //EXTRA available on USBC-1
-        sr_exp_data.bit.SRC_2 = 1;       //HOST on USBC-2
+    } else {
+        sr_exp_data.bit.S_UP  = 1;  // EXTRA to USBC-1
+        sr_exp_data.bit.S_DN1 = 0;  // HOST to USBC-2
+        sr_exp_data.bit.SRC_1 = 0;  // EXTRA available on USBC-1
+        sr_exp_data.bit.SRC_2 = 1;  // HOST on USBC-2
 
-        sr_exp_data.bit.E_VBUS_1 = 0;    //USBC-1 disable full power I/O
-        sr_exp_data.bit.E_VBUS_2 = 1;    //USBC-2 enable full power I/O
+        sr_exp_data.bit.E_VBUS_1 = 0;  // USBC-1 disable full power I/O
+        sr_exp_data.bit.E_VBUS_2 = 1;  // USBC-2 enable full power I/O
 
         SR_EXP_WriteData();
 
-        sr_exp_data.bit.E_UP_N = 0;      //HOST enable
+        sr_exp_data.bit.E_UP_N = 0;  // HOST enable
 
         SR_EXP_WriteData();
 
@@ -295,7 +306,7 @@ void USB_set_host_by_voltage(void)
 
 #ifndef MD_BOOTLOADER
     usb_extra_state = USB_EXTRA_STATE_DISABLED;
-#endif //MD_BOOTLOADER
+#endif  // MD_BOOTLOADER
 
     USB_reset();
     USB_configure();
@@ -303,8 +314,7 @@ void USB_set_host_by_voltage(void)
     DBGC(DC_USB_SET_HOST_BY_VOLTAGE_COMPLETE);
 }
 
-uint8_t USB2422_Port_Detect_Init(void)
-{
+uint8_t USB2422_Port_Detect_Init(void) {
     uint32_t port_detect_retry_ms;
     uint32_t tmod;
 
@@ -314,26 +324,30 @@ uint8_t USB2422_Port_Detect_Init(void)
 
     port_detect_retry_ms = timer_read64() + PORT_DETECT_RETRY_INTERVAL;
 
-    while (!USB_active())
-    {
+    while (!USB_active()) {
         tmod = timer_read64() % PORT_DETECT_RETRY_INTERVAL;
 
-        if (v_con_1 > v_con_2) //Values updated from USB_set_host_by_voltage();
+        if (v_con_1 > v_con_2)  // Values updated from USB_set_host_by_voltage();
         {
-            //1 flash for port 1 detected
-            if (tmod > 500 && tmod < 600) { DBG_LED_ON; }
-            else { DBG_LED_OFF; }
-        }
-        else if (v_con_2 > v_con_1) //Values updated from USB_set_host_by_voltage();
+            // 1 flash for port 1 detected
+            if (tmod > 500 && tmod < 600) {
+                DBG_LED_ON;
+            } else {
+                DBG_LED_OFF;
+            }
+        } else if (v_con_2 > v_con_1)  // Values updated from USB_set_host_by_voltage();
         {
-            //2 flash for port 2 detected
-            if (tmod > 500 && tmod < 600) { DBG_LED_ON; }
-            else if (tmod > 700 && tmod < 800) { DBG_LED_ON; }
-            else { DBG_LED_OFF; }
+            // 2 flash for port 2 detected
+            if (tmod > 500 && tmod < 600) {
+                DBG_LED_ON;
+            } else if (tmod > 700 && tmod < 800) {
+                DBG_LED_ON;
+            } else {
+                DBG_LED_OFF;
+            }
         }
 
-        if (timer_read64() > port_detect_retry_ms)
-        {
+        if (timer_read64() > port_detect_retry_ms) {
             DBGC(DC_PORT_DETECT_INIT_FAILED);
             return 0;
         }
@@ -346,65 +360,67 @@ uint8_t USB2422_Port_Detect_Init(void)
 
 #ifndef MD_BOOTLOADER
 
-void USB_ExtraSetState(uint8_t state)
-{
+void USB_ExtraSetState(uint8_t state) {
     uint8_t state_save = state;
 
-    if (state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG)
-        state = USB_EXTRA_STATE_DISABLED;
+    if (state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG) state = USB_EXTRA_STATE_DISABLED;
 
-    if (usb_host_port == USB_HOST_PORT_1) sr_exp_data.bit.E_VBUS_2 = state;
-    else if (usb_host_port == USB_HOST_PORT_2) sr_exp_data.bit.E_VBUS_1 = state;
-    else return;
+    if (usb_host_port == USB_HOST_PORT_1)
+        sr_exp_data.bit.E_VBUS_2 = state;
+    else if (usb_host_port == USB_HOST_PORT_2)
+        sr_exp_data.bit.E_VBUS_1 = state;
+    else
+        return;
 
     sr_exp_data.bit.E_DN1_N = !state;
     SR_EXP_WriteData();
 
     usb_extra_state = state_save;
 
-    if (usb_extra_state == USB_EXTRA_STATE_ENABLED) CDC_print("USB: Extra enabled\r\n");
-    else if (usb_extra_state == USB_EXTRA_STATE_DISABLED)
-    {
+    if (usb_extra_state == USB_EXTRA_STATE_ENABLED)
+        CDC_print("USB: Extra enabled\r\n");
+    else if (usb_extra_state == USB_EXTRA_STATE_DISABLED) {
         CDC_print("USB: Extra disabled\r\n");
-#ifdef USE_MASSDROP_CONFIGURATOR
+#    ifdef USE_MASSDROP_CONFIGURATOR
         if (led_animation_breathing) gcr_breathe = gcr_desired;
-#endif
-    }
-    else if (usb_extra_state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG) CDC_print("USB: Extra disabled until replug\r\n");
-    else CDC_print("USB: Extra state unknown\r\n");
+#    endif
+    } else if (usb_extra_state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG)
+        CDC_print("USB: Extra disabled until replug\r\n");
+    else
+        CDC_print("USB: Extra state unknown\r\n");
 }
 
-void USB_HandleExtraDevice(void)
-{
+void USB_HandleExtraDevice(void) {
     uint16_t adcval;
 
-    if (usb_host_port == USB_HOST_PORT_1) adcval = adc_get(ADC_CON2);
-    else if (usb_host_port == USB_HOST_PORT_2) adcval = adc_get(ADC_CON1);
-    else return;
+    if (usb_host_port == USB_HOST_PORT_1)
+        adcval = adc_get(ADC_CON2);
+    else if (usb_host_port == USB_HOST_PORT_2)
+        adcval = adc_get(ADC_CON1);
+    else
+        return;
 
     adc_extra = adc_extra * 0.9 + adcval * 0.1;
 
-    //Check for a forced disable state (such as overload prevention)
-    if (usb_extra_state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG)
-    {
-        //Detect unplug and reset state to disabled
+    // Check for a forced disable state (such as overload prevention)
+    if (usb_extra_state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG) {
+        // Detect unplug and reset state to disabled
         if (adc_extra > USB_EXTRA_ADC_THRESHOLD) usb_extra_state = USB_EXTRA_STATE_DISABLED;
 
-        return; //Return even if unplug detected
+        return;  // Return even if unplug detected
     }
 
-    if (usb_extra_manual)
-    {
-        if (usb_extra_state == USB_EXTRA_STATE_DISABLED)
-        USB_ExtraSetState(USB_EXTRA_STATE_ENABLED);
+    if (usb_extra_manual) {
+        if (usb_extra_state == USB_EXTRA_STATE_DISABLED) USB_ExtraSetState(USB_EXTRA_STATE_ENABLED);
 
         return;
     }
 
-    //dpf("a %i %i\r\n",adcval, adc_extra);
-    if (usb_extra_state == USB_EXTRA_STATE_DISABLED && adc_extra < USB_EXTRA_ADC_THRESHOLD) USB_ExtraSetState(USB_EXTRA_STATE_ENABLED);
-    else if (usb_extra_state == USB_EXTRA_STATE_ENABLED && adc_extra > USB_EXTRA_ADC_THRESHOLD) USB_ExtraSetState(USB_EXTRA_STATE_DISABLED);
+    // dpf("a %i %i\r\n",adcval, adc_extra);
+    if (usb_extra_state == USB_EXTRA_STATE_DISABLED && adc_extra < USB_EXTRA_ADC_THRESHOLD)
+        USB_ExtraSetState(USB_EXTRA_STATE_ENABLED);
+    else if (usb_extra_state == USB_EXTRA_STATE_ENABLED && adc_extra > USB_EXTRA_ADC_THRESHOLD)
+        USB_ExtraSetState(USB_EXTRA_STATE_DISABLED);
 }
 
-#endif //MD_BOOTLOADER
-
+#endif  // MD_BOOTLOADER
index 85ad596a62e354858482f92a46b44a1931d88217..b4830b5bc8faf1e2af7d26f6ad20e9b303b07472 100644 (file)
@@ -18,226 +18,225 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef _USB2422_H_
 #define _USB2422_H_
 
-#define REV_USB2422        0x100
+#define REV_USB2422 0x100
 
-#define USB2422_ADDR       0x58 //I2C device address, one instance
+#define USB2422_ADDR 0x58  // I2C device address, one instance
 
-#define USB2422_HUB_ACTIVE_GROUP    0   //PA
-#define USB2422_HUB_ACTIVE_PIN      18  //18
+#define USB2422_HUB_ACTIVE_GROUP 0  // PA
+#define USB2422_HUB_ACTIVE_PIN 18   // 18
 
 /* -------- USB2422_VID : (USB2422L Offset: 0x00) (R/W 16) Vendor ID -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint16_t VID_LSB : 8;
-    uint16_t VID_MSB : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint16_t reg;                /*!< Type      used for register access              */
+    struct {
+        uint16_t VID_LSB : 8;
+        uint16_t VID_MSB : 8;
+    } bit;        /*!< Structure used for bit  access                  */
+    uint16_t reg; /*!< Type      used for register access              */
 } USB2422_VID_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_PID : (USB2422L Offset: 0x02) (R/W 16) Product ID -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint16_t PID_LSB : 8;
-    uint16_t PID_MSB : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint16_t reg;                /*!< Type      used for register access              */
+    struct {
+        uint16_t PID_LSB : 8;
+        uint16_t PID_MSB : 8;
+    } bit;        /*!< Structure used for bit  access                  */
+    uint16_t reg; /*!< Type      used for register access              */
 } USB2422_PID_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_DID : (USB2422L Offset: 0x04) (R/W 16) Device ID -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint16_t DID_LSB : 8;
-    uint16_t DID_MSB : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint16_t reg;                /*!< Type      used for register access              */
+    struct {
+        uint16_t DID_LSB : 8;
+        uint16_t DID_MSB : 8;
+    } bit;        /*!< Structure used for bit  access                  */
+    uint16_t reg; /*!< Type      used for register access              */
 } USB2422_DID_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_CFG1 : (USB2422L Offset: 0x06) (R/W 8) Configuration Data Byte 1-------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t PORT_PWR : 1;
-    uint8_t CURRENT_SNS : 2;
-    uint8_t EOP_DISABLE : 1;
-    uint8_t MTT_ENABLE : 1;
-    uint8_t HS_DISABLE :1;
-    uint8_t :1;
-    uint8_t SELF_BUS_PWR : 1;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t PORT_PWR : 1;
+        uint8_t CURRENT_SNS : 2;
+        uint8_t EOP_DISABLE : 1;
+        uint8_t MTT_ENABLE : 1;
+        uint8_t HS_DISABLE : 1;
+        uint8_t : 1;
+        uint8_t SELF_BUS_PWR : 1;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_CFG1_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_CFG2 : (USB2422L Offset: 0x07) (R/W 8) Configuration Data Byte 2-------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t : 3;
-    uint8_t COMPOUND : 1;
-    uint8_t OC_TIMER :2;
-    uint8_t :1;
-    uint8_t DYNAMIC : 1;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t : 3;
+        uint8_t COMPOUND : 1;
+        uint8_t OC_TIMER : 2;
+        uint8_t : 1;
+        uint8_t DYNAMIC : 1;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_CFG2_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_CFG3 : (USB2422L Offset: 0x08) (R/W 16) Configuration Data Byte 3-------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t STRING_EN : 1;
-    uint8_t  :2;
-    uint8_t PRTMAP_EN :1;
-    uint8_t : 4;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t STRING_EN : 1;
+        uint8_t : 2;
+        uint8_t PRTMAP_EN : 1;
+        uint8_t : 4;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_CFG3_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_NRD : (USB2422L Offset: 0x09) (R/W 8) Non Removable Device -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t : 5;
-    uint8_t PORT2_NR :1;
-    uint8_t PORT1_NR :1;
-    uint8_t : 1;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t : 5;
+        uint8_t PORT2_NR : 1;
+        uint8_t PORT1_NR : 1;
+        uint8_t : 1;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_NRD_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_PDS : (USB2422L Offset: 0x0A) (R/W 8) Port Diable for Self-Powered Operation -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t : 1;
-    uint8_t PORT1_DIS :1;
-    uint8_t PORT2_DIS :1;
-    uint8_t : 5;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t : 1;
+        uint8_t PORT1_DIS : 1;
+        uint8_t PORT2_DIS : 1;
+        uint8_t : 5;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_PDS_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_PDB : (USB2422L Offset: 0x0B) (R/W 8) Port Diable for Bus-Powered Operation -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t : 1;
-    uint8_t PORT1_DIS :1;
-    uint8_t PORT2_DIS :1;
-    uint8_t : 5;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t : 1;
+        uint8_t PORT1_DIS : 1;
+        uint8_t PORT2_DIS : 1;
+        uint8_t : 5;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_PDB_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_MAXPS : (USB2422L Offset: 0x0C) (R/W 8) Max Power for Self-Powered Operation -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t MAX_PWR_SP : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t MAX_PWR_SP : 8;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_MAXPS_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_MAXPB : (USB2422L Offset: 0x0D) (R/W 8) Max Power for Bus-Powered Operation -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t MAX_PWR_BP : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t MAX_PWR_BP : 8;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_MAXPB_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_HCMCS : (USB2422L Offset: 0x0E) (R/W 8) Hub Controller Max Current for Self-Powered Operation -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t HC_MAX_C_SP : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t HC_MAX_C_SP : 8;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_HCMCS_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_HCMCB : (USB2422L Offset: 0x0F) (R/W 8) Hub Controller Max Current for Bus-Powered Operation -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t HC_MAX_C_BP : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t HC_MAX_C_BP : 8;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_HCMCB_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_PWRT : (USB2422L Offset: 0x10) (R/W 8) Power On Time -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t POWER_ON_TIME : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t POWER_ON_TIME : 8;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_PWRT_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_LANGID LSB : (USB2422L Offset: 0x11) (R/W 16) Language ID -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t LANGID_LSB : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t LANGID_LSB : 8;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_LANGID_LSB_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_LANGID MSB : (USB2422L Offset: 0x12) (R/W 16) Language ID -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t LANGID_MSB : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t LANGID_MSB : 8;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_LANGID_MSB_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
-
 /* -------- USB2422_MFRSL : (USB2422L Offset: 0x13) (R/W 8) Manufacturer String Length -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t MFR_STR_LEN : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t MFR_STR_LEN : 8;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_MFRSL_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_PRDSL : (USB2422L Offset: 0x14) (R/W 8) Product String Length -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t PRD_STR_LEN : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t PRD_STR_LEN : 8;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_PRDSL_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_SERSL : (USB2422L Offset: 0x15) (R/W 8) Serial String Length -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t SER_STR_LEN : 8;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t SER_STR_LEN : 8;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_SERSL_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
@@ -259,60 +258,60 @@ typedef uint16_t USB2422_SERSTR_Type;
 /* -------- USB2422_BCEN : (USB2422L Offset: 0xD0) (R/W 8) Battery Charging Enable -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t : 1;
-    uint8_t PORT1_BCE :1;
-    uint8_t PORT2_BCE :1;
-    uint8_t : 5;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t : 1;
+        uint8_t PORT1_BCE : 1;
+        uint8_t PORT2_BCE : 1;
+        uint8_t : 5;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_BCEN_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_BOOSTUP : (USB2422L Offset: 0xF6) (R/W 8) Boost Upstream -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t BOOST :2;
-    uint8_t : 6;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t BOOST : 2;
+        uint8_t : 6;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_BOOSTUP_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_BOOSTDOWN : (USB2422L Offset: 0xF8) (R/W 8) Boost Downstream -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t BOOST1 :2;
-    uint8_t BOOST2 :2;
-    uint8_t : 4;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t BOOST1 : 2;
+        uint8_t BOOST2 : 2;
+        uint8_t : 4;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_BOOSTDOWN_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_PRTSP : (USB2422L Offset: 0xFA) (R/W 8) Port Swap -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t : 1;
-    uint8_t PORT1_SP :1;
-    uint8_t PORT2_SP :1;
-    uint8_t : 5;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t : 1;
+        uint8_t PORT1_SP : 1;
+        uint8_t PORT2_SP : 1;
+        uint8_t : 5;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_PRTSP_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /* -------- USB2422_PRTR12 : (USB2422L Offset: 0xFB) (R/W 8) Port 1/2 Remap -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t PORT1_REMAP: 4;
-    uint8_t PORT2_REMAP: 4;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t PORT1_REMAP : 4;
+        uint8_t PORT2_REMAP : 4;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_PRTR12_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 #define USB2422_PRTR12_DISABLE 0
@@ -324,81 +323,80 @@ typedef union {
 /* -------- USB2422_STCD : (USB2422L Offset: 0xFF) (R/W 8) Status Command -------- */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef union {
-  struct {
-    uint8_t USB_ATTACH: 1;
-    uint8_t RESET: 1;
-    uint8_t INTF_PWRDN: 1;
-    uint8_t : 5;
-  } bit;                       /*!< Structure used for bit  access                  */
-  uint8_t reg;                 /*!< Type      used for register access              */
+    struct {
+        uint8_t USB_ATTACH : 1;
+        uint8_t RESET : 1;
+        uint8_t INTF_PWRDN : 1;
+        uint8_t : 5;
+    } bit;       /*!< Structure used for bit  access                  */
+    uint8_t reg; /*!< Type      used for register access              */
 } USB2422_STCD_Type;
 #endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
 
 /** \brief USB2422 device hardware registers */
 #if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
 typedef struct {
-  USB2422_VID_Type          VID;        /**< \brief Offset: 0x00*/
-  USB2422_PID_Type          PID;        /**< \brief Offset: 0x02*/
-  USB2422_DID_Type          DID;        /**< \brief Offset: 0x04*/
-  USB2422_CFG1_Type         CFG1;       /**< \brief Offset: 0x06*/
-  USB2422_CFG2_Type         CFG2;       /**< \brief Offset: 0x07*/
-  USB2422_CFG3_Type         CFG3;       /**< \brief Offset: 0x08*/
-  USB2422_NRD_Type          NRD;        /**< \brief Offset: 0x09*/
-  USB2422_PDS_Type          PDS;        /**< \brief Offset: 0x0A*/
-  USB2422_PDB_Type          PDB;        /**< \brief Offset: 0x0B*/
-  USB2422_MAXPS_Type        MAXPS;      /**< \brief Offset: 0x0C*/
-  USB2422_MAXPB_Type        MAXPB;      /**< \brief Offset: 0x0D*/
-  USB2422_HCMCS_Type        HCMCS;      /**< \brief Offset: 0x0E*/
-  USB2422_HCMCB_Type        HCMCB;      /**< \brief Offset: 0x0F*/
-  USB2422_PWRT_Type         PWRT;       /**< \brief Offset: 0x10*/
-  USB2422_LANGID_LSB_Type   LANGID_LSB; /**< \brief Offset: 0x11*/
-  USB2422_LANGID_MSB_Type   LANGID_MSB; /**< \brief Offset: 0x12*/
-  USB2422_MFRSL_Type        MFRSL;      /**< \brief Offset: 0x13*/
-  USB2422_PRDSL_Type        PRDSL;      /**< \brief Offset: 0x14*/
-  USB2422_SERSL_Type        SERSL;      /**< \brief Offset: 0x15*/
-  USB2422_MFRSTR_Type       MFRSTR[31]; /**< \brief Offset: 0x16*/
-  USB2422_PRDSTR_Type       PRDSTR[31]; /**< \brief Offset: 0x54*/
-  USB2422_SERSTR_Type       SERSTR[31]; /**< \brief Offset: 0x92*/
-  USB2422_BCEN_Type         BCEN;       /**< \brief Offset: 0xD0*/
-  uint8_t                   Reserved1[0x25];
-  USB2422_BOOSTUP_Type      BOOSTUP;    /**< \brief Offset: 0xF6*/
-  uint8_t                   Reserved2[0x1];
-  USB2422_BOOSTDOWN_Type    BOOSTDOWN;  /**< \brief Offset: 0xF8*/
-  uint8_t                   Reserved3[0x1];
-  USB2422_PRTSP_Type        PRTSP;      /**< \brief Offset: 0xFA*/
-  USB2422_PRTR12_Type       PRTR12;     /**< \brief Offset: 0xFB*/
-  uint8_t                   Reserved4[0x3];
-  USB2422_STCD_Type         STCD;       /**< \brief Offset: 0xFF*/
+    USB2422_VID_Type        VID;        /**< \brief Offset: 0x00*/
+    USB2422_PID_Type        PID;        /**< \brief Offset: 0x02*/
+    USB2422_DID_Type        DID;        /**< \brief Offset: 0x04*/
+    USB2422_CFG1_Type       CFG1;       /**< \brief Offset: 0x06*/
+    USB2422_CFG2_Type       CFG2;       /**< \brief Offset: 0x07*/
+    USB2422_CFG3_Type       CFG3;       /**< \brief Offset: 0x08*/
+    USB2422_NRD_Type        NRD;        /**< \brief Offset: 0x09*/
+    USB2422_PDS_Type        PDS;        /**< \brief Offset: 0x0A*/
+    USB2422_PDB_Type        PDB;        /**< \brief Offset: 0x0B*/
+    USB2422_MAXPS_Type      MAXPS;      /**< \brief Offset: 0x0C*/
+    USB2422_MAXPB_Type      MAXPB;      /**< \brief Offset: 0x0D*/
+    USB2422_HCMCS_Type      HCMCS;      /**< \brief Offset: 0x0E*/
+    USB2422_HCMCB_Type      HCMCB;      /**< \brief Offset: 0x0F*/
+    USB2422_PWRT_Type       PWRT;       /**< \brief Offset: 0x10*/
+    USB2422_LANGID_LSB_Type LANGID_LSB; /**< \brief Offset: 0x11*/
+    USB2422_LANGID_MSB_Type LANGID_MSB; /**< \brief Offset: 0x12*/
+    USB2422_MFRSL_Type      MFRSL;      /**< \brief Offset: 0x13*/
+    USB2422_PRDSL_Type      PRDSL;      /**< \brief Offset: 0x14*/
+    USB2422_SERSL_Type      SERSL;      /**< \brief Offset: 0x15*/
+    USB2422_MFRSTR_Type     MFRSTR[31]; /**< \brief Offset: 0x16*/
+    USB2422_PRDSTR_Type     PRDSTR[31]; /**< \brief Offset: 0x54*/
+    USB2422_SERSTR_Type     SERSTR[31]; /**< \brief Offset: 0x92*/
+    USB2422_BCEN_Type       BCEN;       /**< \brief Offset: 0xD0*/
+    uint8_t                 Reserved1[0x25];
+    USB2422_BOOSTUP_Type    BOOSTUP; /**< \brief Offset: 0xF6*/
+    uint8_t                 Reserved2[0x1];
+    USB2422_BOOSTDOWN_Type  BOOSTDOWN; /**< \brief Offset: 0xF8*/
+    uint8_t                 Reserved3[0x1];
+    USB2422_PRTSP_Type      PRTSP;  /**< \brief Offset: 0xFA*/
+    USB2422_PRTR12_Type     PRTR12; /**< \brief Offset: 0xFB*/
+    uint8_t                 Reserved4[0x3];
+    USB2422_STCD_Type       STCD; /**< \brief Offset: 0xFF*/
 } Usb2422;
 #endif
 
-#define PORT_DETECT_RETRY_INTERVAL      2000
+#define PORT_DETECT_RETRY_INTERVAL 2000
 
-#define USB_EXTRA_ADC_THRESHOLD         900
+#define USB_EXTRA_ADC_THRESHOLD 900
 
-#define USB_EXTRA_STATE_DISABLED                0
-#define USB_EXTRA_STATE_ENABLED                 1
-#define USB_EXTRA_STATE_UNKNOWN                 2
-#define USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG   3
+#define USB_EXTRA_STATE_DISABLED 0
+#define USB_EXTRA_STATE_ENABLED 1
+#define USB_EXTRA_STATE_UNKNOWN 2
+#define USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG 3
 
-#define USB_HOST_PORT_1             0
-#define USB_HOST_PORT_2             1
-#define USB_HOST_PORT_UNKNOWN       2
+#define USB_HOST_PORT_1 0
+#define USB_HOST_PORT_2 1
+#define USB_HOST_PORT_UNKNOWN 2
 
 extern uint8_t usb_host_port;
 extern uint8_t usb_extra_state;
 extern uint8_t usb_extra_manual;
 extern uint8_t usb_gcr_auto;
 
-void USB2422_init(void);
-void USB_reset(void);
-void USB_configure(void);
+void     USB2422_init(void);
+void     USB_reset(void);
+void     USB_configure(void);
 uint16_t USB_active(void);
-void USB_set_host_by_voltage(void);
+void     USB_set_host_by_voltage(void);
 uint16_t adc_get(uint8_t muxpos);
-uint8_t USB2422_Port_Detect_Init(void);
-void USB_HandleExtraDevice(void);
-void USB_ExtraSetState(uint8_t state);
-
-#endif //_USB2422_H_
+uint8_t  USB2422_Port_Detect_Init(void);
+void     USB_HandleExtraDevice(void);
+void     USB_ExtraSetState(uint8_t state);
 
+#endif  //_USB2422_H_
index 7febdc9eceaa2f8b682f9fd5f2a5606a2f847e13..1cef7037882230b723b2982c0b96719415eecc23 100644 (file)
  */
 
 //! \name Vendor Identifier assigned by USB org to ATMEL
-#define  USB_VID_ATMEL                             0x03EB
+#define USB_VID_ATMEL 0x03EB
 
 //! \name Product Identifier assigned by ATMEL to AVR applications
 //! @{
 
 //! \name The range from 2000h to 20FFh is reserved to the old PID for C51, MEGA, and others.
 //! @{
-#define  USB_PID_ATMEL_MEGA_HIDGENERIC             0x2013
-#define  USB_PID_ATMEL_MEGA_HIDKEYBOARD            0x2017
-#define  USB_PID_ATMEL_MEGA_CDC                    0x2018
-#define  USB_PID_ATMEL_MEGA_AUDIO_IN               0x2019
-#define  USB_PID_ATMEL_MEGA_MS                     0x201A
-#define  USB_PID_ATMEL_MEGA_AUDIO_IN_OUT           0x201B
-#define  USB_PID_ATMEL_MEGA_HIDMOUSE               0x201C
-#define  USB_PID_ATMEL_MEGA_HIDMOUSE_CERTIF_U4     0x201D
-#define  USB_PID_ATMEL_MEGA_CDC_MULTI              0x201E
-#define  USB_PID_ATMEL_MEGA_MS_HIDMS_HID_USBKEY    0x2022
-#define  USB_PID_ATMEL_MEGA_MS_HIDMS_HID_STK525    0x2023
-#define  USB_PID_ATMEL_MEGA_MS_2                   0x2029
-#define  USB_PID_ATMEL_MEGA_MS_HIDMS               0x202A
-#define  USB_PID_ATMEL_MEGA_MS_3                   0x2032
-#define  USB_PID_ATMEL_MEGA_LIBUSB                 0x2050
+#define USB_PID_ATMEL_MEGA_HIDGENERIC 0x2013
+#define USB_PID_ATMEL_MEGA_HIDKEYBOARD 0x2017
+#define USB_PID_ATMEL_MEGA_CDC 0x2018
+#define USB_PID_ATMEL_MEGA_AUDIO_IN 0x2019
+#define USB_PID_ATMEL_MEGA_MS 0x201A
+#define USB_PID_ATMEL_MEGA_AUDIO_IN_OUT 0x201B
+#define USB_PID_ATMEL_MEGA_HIDMOUSE 0x201C
+#define USB_PID_ATMEL_MEGA_HIDMOUSE_CERTIF_U4 0x201D
+#define USB_PID_ATMEL_MEGA_CDC_MULTI 0x201E
+#define USB_PID_ATMEL_MEGA_MS_HIDMS_HID_USBKEY 0x2022
+#define USB_PID_ATMEL_MEGA_MS_HIDMS_HID_STK525 0x2023
+#define USB_PID_ATMEL_MEGA_MS_2 0x2029
+#define USB_PID_ATMEL_MEGA_MS_HIDMS 0x202A
+#define USB_PID_ATMEL_MEGA_MS_3 0x2032
+#define USB_PID_ATMEL_MEGA_LIBUSB 0x2050
 //! @}
 
 //! \name The range 2100h to 21FFh is reserved to PIDs for AVR Tools.
 //! @{
-#define  USB_PID_ATMEL_XPLAINED                    0x2122
-#define  USB_PID_ATMEL_XMEGA_USB_ZIGBIT_2_4GHZ     0x214A
-#define  USB_PID_ATMEL_XMEGA_USB_ZIGBIT_SUBGHZ     0x214B
+#define USB_PID_ATMEL_XPLAINED 0x2122
+#define USB_PID_ATMEL_XMEGA_USB_ZIGBIT_2_4GHZ 0x214A
+#define USB_PID_ATMEL_XMEGA_USB_ZIGBIT_SUBGHZ 0x214B
 //! @}
 
 //! \name The range 2300h to 23FFh is reserved to PIDs for demo from ASF1.7=>
 //! @{
-#define  USB_PID_ATMEL_UC3_ENUM                    0x2300
-#define  USB_PID_ATMEL_UC3_MS                      0x2301
-#define  USB_PID_ATMEL_UC3_MS_SDRAM_LOADER         0x2302
-#define  USB_PID_ATMEL_UC3_EVK1100_CTRLPANEL       0x2303
-#define  USB_PID_ATMEL_UC3_HID                     0x2304
-#define  USB_PID_ATMEL_UC3_EVK1101_CTRLPANEL_HID   0x2305
-#define  USB_PID_ATMEL_UC3_EVK1101_CTRLPANEL_HID_MS 0x2306
-#define  USB_PID_ATMEL_UC3_CDC                     0x2307
-#define  USB_PID_ATMEL_UC3_AUDIO_MICRO             0x2308
-#define  USB_PID_ATMEL_UC3_CDC_DEBUG               0x2310 // Virtual Com (debug interface) on EVK11xx
-#define  USB_PID_ATMEL_UC3_AUDIO_SPEAKER_MICRO     0x2311
-#define  USB_PID_ATMEL_UC3_CDC_MSC                 0x2312
+#define USB_PID_ATMEL_UC3_ENUM 0x2300
+#define USB_PID_ATMEL_UC3_MS 0x2301
+#define USB_PID_ATMEL_UC3_MS_SDRAM_LOADER 0x2302
+#define USB_PID_ATMEL_UC3_EVK1100_CTRLPANEL 0x2303
+#define USB_PID_ATMEL_UC3_HID 0x2304
+#define USB_PID_ATMEL_UC3_EVK1101_CTRLPANEL_HID 0x2305
+#define USB_PID_ATMEL_UC3_EVK1101_CTRLPANEL_HID_MS 0x2306
+#define USB_PID_ATMEL_UC3_CDC 0x2307
+#define USB_PID_ATMEL_UC3_AUDIO_MICRO 0x2308
+#define USB_PID_ATMEL_UC3_CDC_DEBUG 0x2310  // Virtual Com (debug interface) on EVK11xx
+#define USB_PID_ATMEL_UC3_AUDIO_SPEAKER_MICRO 0x2311
+#define USB_PID_ATMEL_UC3_CDC_MSC 0x2312
 //! @}
 
 //! \name The range 2400h to 24FFh is reserved to PIDs for ASF applications
 //! @{
-#define  USB_PID_ATMEL_ASF_HIDMOUSE                0x2400
-#define  USB_PID_ATMEL_ASF_HIDKEYBOARD             0x2401
-#define  USB_PID_ATMEL_ASF_HIDGENERIC              0x2402
-#define  USB_PID_ATMEL_ASF_MSC                     0x2403
-#define  USB_PID_ATMEL_ASF_CDC                     0x2404
-#define  USB_PID_ATMEL_ASF_PHDC                    0x2405
-#define  USB_PID_ATMEL_ASF_HIDMTOUCH               0x2406
-#define  USB_PID_ATMEL_ASF_MSC_HIDMOUSE            0x2420
-#define  USB_PID_ATMEL_ASF_MSC_HIDS_CDC            0x2421
-#define  USB_PID_ATMEL_ASF_MSC_HIDKEYBOARD         0x2422
-#define  USB_PID_ATMEL_ASF_VENDOR_CLASS            0x2423
-#define  USB_PID_ATMEL_ASF_MSC_CDC                 0x2424
-#define  USB_PID_ATMEL_ASF_TWO_CDC                 0x2425
-#define  USB_PID_ATMEL_ASF_SEVEN_CDC               0x2426
-#define  USB_PID_ATMEL_ASF_XPLAIN_BC_POWERONLY     0x2430
-#define  USB_PID_ATMEL_ASF_XPLAIN_BC_TERMINAL      0x2431
-#define  USB_PID_ATMEL_ASF_XPLAIN_BC_TOUCH         0x2432
-#define  USB_PID_ATMEL_ASF_AUDIO_SPEAKER           0x2433
-#define  USB_PID_ATMEL_ASF_XMEGA_B1_XPLAINED       0x2434
+#define USB_PID_ATMEL_ASF_HIDMOUSE 0x2400
+#define USB_PID_ATMEL_ASF_HIDKEYBOARD 0x2401
+#define USB_PID_ATMEL_ASF_HIDGENERIC 0x2402
+#define USB_PID_ATMEL_ASF_MSC 0x2403
+#define USB_PID_ATMEL_ASF_CDC 0x2404
+#define USB_PID_ATMEL_ASF_PHDC 0x2405
+#define USB_PID_ATMEL_ASF_HIDMTOUCH 0x2406
+#define USB_PID_ATMEL_ASF_MSC_HIDMOUSE 0x2420
+#define USB_PID_ATMEL_ASF_MSC_HIDS_CDC 0x2421
+#define USB_PID_ATMEL_ASF_MSC_HIDKEYBOARD 0x2422
+#define USB_PID_ATMEL_ASF_VENDOR_CLASS 0x2423
+#define USB_PID_ATMEL_ASF_MSC_CDC 0x2424
+#define USB_PID_ATMEL_ASF_TWO_CDC 0x2425
+#define USB_PID_ATMEL_ASF_SEVEN_CDC 0x2426
+#define USB_PID_ATMEL_ASF_XPLAIN_BC_POWERONLY 0x2430
+#define USB_PID_ATMEL_ASF_XPLAIN_BC_TERMINAL 0x2431
+#define USB_PID_ATMEL_ASF_XPLAIN_BC_TOUCH 0x2432
+#define USB_PID_ATMEL_ASF_AUDIO_SPEAKER 0x2433
+#define USB_PID_ATMEL_ASF_XMEGA_B1_XPLAINED 0x2434
 //! @}
 
 //! \name The range 2F00h to 2FFFh is reserved to official PIDs for AVR bootloaders
 //! Note, !!!! don't use this range for demos or examples !!!!
 //! @{
-#define  USB_PID_ATMEL_DFU_ATXMEGA64C3             0x2FD6
-#define  USB_PID_ATMEL_DFU_ATXMEGA128C3            0x2FD7
-#define  USB_PID_ATMEL_DFU_ATXMEGA16C4             0x2FD8
-#define  USB_PID_ATMEL_DFU_ATXMEGA32C4             0x2FD9
-#define  USB_PID_ATMEL_DFU_ATXMEGA256C3            0x2FDA
-#define  USB_PID_ATMEL_DFU_ATXMEGA384C3            0x2FDB
-#define  USB_PID_ATMEL_DFU_ATUCL3_L4               0x2FDC
-#define  USB_PID_ATMEL_DFU_ATXMEGA64A4U            0x2FDD
-#define  USB_PID_ATMEL_DFU_ATXMEGA128A4U           0x2FDE
-
-#define  USB_PID_ATMEL_DFU_ATXMEGA64B3             0x2FDF
-#define  USB_PID_ATMEL_DFU_ATXMEGA128B3            0x2FE0
-#define  USB_PID_ATMEL_DFU_ATXMEGA64B1             0x2FE1
-#define  USB_PID_ATMEL_DFU_ATXMEGA256A3BU          0x2FE2
-#define  USB_PID_ATMEL_DFU_ATXMEGA16A4U            0x2FE3
-#define  USB_PID_ATMEL_DFU_ATXMEGA32A4U            0x2FE4
-#define  USB_PID_ATMEL_DFU_ATXMEGA64A3U            0x2FE5
-#define  USB_PID_ATMEL_DFU_ATXMEGA128A3U           0x2FE6
-#define  USB_PID_ATMEL_DFU_ATXMEGA192A3U           0x2FE7
-#define  USB_PID_ATMEL_DFU_ATXMEGA64A1U            0x2FE8
-#define  USB_PID_ATMEL_DFU_ATUC3D                  0x2FE9
-#define  USB_PID_ATMEL_DFU_ATXMEGA128B1            0x2FEA
-#define  USB_PID_ATMEL_DFU_AT32UC3C                0x2FEB
-#define  USB_PID_ATMEL_DFU_ATXMEGA256A3U           0x2FEC
-#define  USB_PID_ATMEL_DFU_ATXMEGA128A1U           0x2FED
-#define  USB_PID_ATMEL_DFU_ATMEGA8U2               0x2FEE
-#define  USB_PID_ATMEL_DFU_ATMEGA16U2              0x2FEF
-#define  USB_PID_ATMEL_DFU_ATMEGA32U2              0x2FF0
-#define  USB_PID_ATMEL_DFU_AT32UC3A3               0x2FF1
-#define  USB_PID_ATMEL_DFU_ATMEGA32U6              0x2FF2
-#define  USB_PID_ATMEL_DFU_ATMEGA16U4              0x2FF3
-#define  USB_PID_ATMEL_DFU_ATMEGA32U4              0x2FF4
-#define  USB_PID_ATMEL_DFU_AT32AP7200              0x2FF5
-#define  USB_PID_ATMEL_DFU_AT32UC3B                0x2FF6
-#define  USB_PID_ATMEL_DFU_AT90USB82               0x2FF7
-#define  USB_PID_ATMEL_DFU_AT32UC3A                0x2FF8
-#define  USB_PID_ATMEL_DFU_AT90USB64               0x2FF9
-#define  USB_PID_ATMEL_DFU_AT90USB162              0x2FFA
-#define  USB_PID_ATMEL_DFU_AT90USB128              0x2FFB
+#define USB_PID_ATMEL_DFU_ATXMEGA64C3 0x2FD6
+#define USB_PID_ATMEL_DFU_ATXMEGA128C3 0x2FD7
+#define USB_PID_ATMEL_DFU_ATXMEGA16C4 0x2FD8
+#define USB_PID_ATMEL_DFU_ATXMEGA32C4 0x2FD9
+#define USB_PID_ATMEL_DFU_ATXMEGA256C3 0x2FDA
+#define USB_PID_ATMEL_DFU_ATXMEGA384C3 0x2FDB
+#define USB_PID_ATMEL_DFU_ATUCL3_L4 0x2FDC
+#define USB_PID_ATMEL_DFU_ATXMEGA64A4U 0x2FDD
+#define USB_PID_ATMEL_DFU_ATXMEGA128A4U 0x2FDE
+
+#define USB_PID_ATMEL_DFU_ATXMEGA64B3 0x2FDF
+#define USB_PID_ATMEL_DFU_ATXMEGA128B3 0x2FE0
+#define USB_PID_ATMEL_DFU_ATXMEGA64B1 0x2FE1
+#define USB_PID_ATMEL_DFU_ATXMEGA256A3BU 0x2FE2
+#define USB_PID_ATMEL_DFU_ATXMEGA16A4U 0x2FE3
+#define USB_PID_ATMEL_DFU_ATXMEGA32A4U 0x2FE4
+#define USB_PID_ATMEL_DFU_ATXMEGA64A3U 0x2FE5
+#define USB_PID_ATMEL_DFU_ATXMEGA128A3U 0x2FE6
+#define USB_PID_ATMEL_DFU_ATXMEGA192A3U 0x2FE7
+#define USB_PID_ATMEL_DFU_ATXMEGA64A1U 0x2FE8
+#define USB_PID_ATMEL_DFU_ATUC3D 0x2FE9
+#define USB_PID_ATMEL_DFU_ATXMEGA128B1 0x2FEA
+#define USB_PID_ATMEL_DFU_AT32UC3C 0x2FEB
+#define USB_PID_ATMEL_DFU_ATXMEGA256A3U 0x2FEC
+#define USB_PID_ATMEL_DFU_ATXMEGA128A1U 0x2FED
+#define USB_PID_ATMEL_DFU_ATMEGA8U2 0x2FEE
+#define USB_PID_ATMEL_DFU_ATMEGA16U2 0x2FEF
+#define USB_PID_ATMEL_DFU_ATMEGA32U2 0x2FF0
+#define USB_PID_ATMEL_DFU_AT32UC3A3 0x2FF1
+#define USB_PID_ATMEL_DFU_ATMEGA32U6 0x2FF2
+#define USB_PID_ATMEL_DFU_ATMEGA16U4 0x2FF3
+#define USB_PID_ATMEL_DFU_ATMEGA32U4 0x2FF4
+#define USB_PID_ATMEL_DFU_AT32AP7200 0x2FF5
+#define USB_PID_ATMEL_DFU_AT32UC3B 0x2FF6
+#define USB_PID_ATMEL_DFU_AT90USB82 0x2FF7
+#define USB_PID_ATMEL_DFU_AT32UC3A 0x2FF8
+#define USB_PID_ATMEL_DFU_AT90USB64 0x2FF9
+#define USB_PID_ATMEL_DFU_AT90USB162 0x2FFA
+#define USB_PID_ATMEL_DFU_AT90USB128 0x2FFB
 // 2FFCh to 2FFFh used by C51 family products
 //! @}
 
 
 //! @}
 
-
-#endif // _USB_ATMEL_H_
+#endif  // _USB_ATMEL_H_
index b31256df7cda66c144239162c5febaedb6845582..f138b42786b290e5ca20c6f4ec2b87a971f60968 100644 (file)
  */
 // Check USB device configuration
 #ifdef USB_DEVICE_HS_SUPPORT
-#  error The High speed mode is not supported on this part, please remove USB_DEVICE_HS_SUPPORT in conf_usb.h
+#    error The High speed mode is not supported on this part, please remove USB_DEVICE_HS_SUPPORT in conf_usb.h
 #endif
 
-//Note: This driver is adapted for SAMD51
+// Note: This driver is adapted for SAMD51
 
 #ifndef UDC_REMOTEWAKEUP_LPM_ENABLE
-#define UDC_REMOTEWAKEUP_LPM_ENABLE()
+#    define UDC_REMOTEWAKEUP_LPM_ENABLE()
 #endif
 #ifndef UDC_REMOTEWAKEUP_LPM_DISABLE
-#define UDC_REMOTEWAKEUP_LPM_DISABLE()
+#    define UDC_REMOTEWAKEUP_LPM_DISABLE()
 #endif
 #ifndef UDC_SUSPEND_LPM_EVENT
-#define UDC_SUSPEND_LPM_EVENT()
+#    define UDC_SUSPEND_LPM_EVENT()
 #endif
 
 /* for debug text */
 #ifdef USB_DEBUG
-#   define dbg_print printf
+#    define dbg_print printf
 #else
-#   define dbg_print(...)
+#    define dbg_print(...)
 #endif
 
 /** Maximum size of a transfer in multi-packet mode */
-#define UDD_ENDPOINT_MAX_TRANS ((8*1024)-1)
+#define UDD_ENDPOINT_MAX_TRANS ((8 * 1024) - 1)
 
 /** USB software device instance structure */
 struct usb_module usb_device;
@@ -97,10 +97,7 @@ struct usb_module usb_device;
 
 #define UDD_CLOCK_GEN 0
 
-static inline void udd_wait_clock_ready(void)
-{
-
-}
+static inline void udd_wait_clock_ready(void) {}
 
 /**
  * \name Power management
@@ -130,12 +127,12 @@ uint8_t udd_ctrl_buffer[USB_DEVICE_EP_CTRL_SIZE];
 
 /** Bit definitions about endpoint control state machine for udd_ep_control_state */
 typedef enum {
-    UDD_EPCTRL_SETUP                  = 0, //!< Wait a SETUP packet
-    UDD_EPCTRL_DATA_OUT               = 1, //!< Wait a OUT data packet
-    UDD_EPCTRL_DATA_IN                = 2, //!< Wait a IN data packet
-    UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP  = 3, //!< Wait a IN ZLP packet
-    UDD_EPCTRL_HANDSHAKE_WAIT_OUT_ZLP = 4, //!< Wait a OUT ZLP packet
-    UDD_EPCTRL_STALL_REQ              = 5, //!< STALL enabled on IN & OUT packet
+    UDD_EPCTRL_SETUP                  = 0,  //!< Wait a SETUP packet
+    UDD_EPCTRL_DATA_OUT               = 1,  //!< Wait a OUT data packet
+    UDD_EPCTRL_DATA_IN                = 2,  //!< Wait a IN data packet
+    UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP  = 3,  //!< Wait a IN ZLP packet
+    UDD_EPCTRL_HANDSHAKE_WAIT_OUT_ZLP = 4,  //!< Wait a OUT ZLP packet
+    UDD_EPCTRL_STALL_REQ              = 5,  //!< STALL enabled on IN & OUT packet
 } udd_ctrl_ep_state_t;
 
 /** Global variable to give and record information of the set up request management */
@@ -200,11 +197,11 @@ typedef struct {
     //! Endpoint size
     uint16_t ep_size;
     //! A job is registered on this endpoint
-    uint8_t busy:1;
+    uint8_t busy : 1;
     //! A short packet is requested for this job on endpoint IN
-    uint8_t b_shortpacket:1;
+    uint8_t b_shortpacket : 1;
     //! The cache buffer is currently used on endpoint OUT
-    uint8_t b_use_out_cache_buffer:1;
+    uint8_t b_use_out_cache_buffer : 1;
 } udd_ep_job_t;
 
 /** Array to register a job on bulk/interrupt/isochronous endpoint */
@@ -217,8 +214,7 @@ static udd_ep_job_t udd_ep_job[2 * USB_DEVICE_MAX_EP];
  * \param[in] ep  Endpoint Address
  * \retval    pointer to an udd_ep_job_t structure instance
  */
-static udd_ep_job_t* udd_ep_get_job(udd_ep_id_t ep)
-{
+static udd_ep_job_t *udd_ep_get_job(udd_ep_id_t ep) {
     if ((ep == 0) || (ep == 0x80)) {
         return NULL;
     } else {
@@ -230,17 +226,16 @@ static udd_ep_job_t* udd_ep_get_job(udd_ep_id_t ep)
  * \brief     Endpoint IN process, continue to send packets or zero length packet
  * \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
  */
-static void udd_ep_trans_in_next(void* pointer)
-{
-    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
-    udd_ep_id_t ep = ep_callback_para->endpoint_address;
-    uint16_t ep_size, nb_trans;
-    uint16_t next_trans;
-    udd_ep_id_t ep_num;
-    udd_ep_job_t *ptr_job;
+static void udd_ep_trans_in_next(void *pointer) {
+    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
+    udd_ep_id_t                             ep               = ep_callback_para->endpoint_address;
+    uint16_t                                ep_size, nb_trans;
+    uint16_t                                next_trans;
+    udd_ep_id_t                             ep_num;
+    udd_ep_job_t *                          ptr_job;
 
     ptr_job = udd_ep_get_job(ep);
-    ep_num = ep & USB_EP_ADDR_MASK;
+    ep_num  = ep & USB_EP_ADDR_MASK;
 
     ep_size = ptr_job->ep_size;
     /* Update number of data transferred */
@@ -251,13 +246,13 @@ static void udd_ep_trans_in_next(void* pointer)
     if (ptr_job->nb_trans != ptr_job->buf_size) {
         next_trans = ptr_job->buf_size - ptr_job->nb_trans;
         if (UDD_ENDPOINT_MAX_TRANS < next_trans) {
-        /* The USB hardware support a maximum
-         * transfer size of UDD_ENDPOINT_MAX_TRANS Bytes */
-            next_trans = UDD_ENDPOINT_MAX_TRANS -(UDD_ENDPOINT_MAX_TRANS % ep_size);
+            /* The USB hardware support a maximum
+             * transfer size of UDD_ENDPOINT_MAX_TRANS Bytes */
+            next_trans = UDD_ENDPOINT_MAX_TRANS - (UDD_ENDPOINT_MAX_TRANS % ep_size);
         }
         /* Need ZLP, if requested and last packet is not a short packet */
         ptr_job->b_shortpacket = ptr_job->b_shortpacket && (0 == (next_trans % ep_size));
-        usb_device_endpoint_write_buffer_job(&usb_device,ep_num,&ptr_job->buf[ptr_job->nb_trans],next_trans);
+        usb_device_endpoint_write_buffer_job(&usb_device, ep_num, &ptr_job->buf[ptr_job->nb_trans], next_trans);
         return;
     }
 
@@ -265,7 +260,7 @@ static void udd_ep_trans_in_next(void* pointer)
     if (ptr_job->b_shortpacket) {
         ptr_job->b_shortpacket = false;
         /* Start new transfer */
-        usb_device_endpoint_write_buffer_job(&usb_device,ep_num,&ptr_job->buf[ptr_job->nb_trans],0);
+        usb_device_endpoint_write_buffer_job(&usb_device, ep_num, &ptr_job->buf[ptr_job->nb_trans], 0);
         return;
     }
 
@@ -280,17 +275,16 @@ static void udd_ep_trans_in_next(void* pointer)
  * \brief     Endpoint OUT process, continue to receive packets or zero length packet
  * \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
  */
-static void udd_ep_trans_out_next(void* pointer)
-{
-    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
-    udd_ep_id_t ep = ep_callback_para->endpoint_address;
-    uint16_t ep_size, nb_trans;
-    uint16_t next_trans;
-    udd_ep_id_t ep_num;
-    udd_ep_job_t *ptr_job;
+static void udd_ep_trans_out_next(void *pointer) {
+    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
+    udd_ep_id_t                             ep               = ep_callback_para->endpoint_address;
+    uint16_t                                ep_size, nb_trans;
+    uint16_t                                next_trans;
+    udd_ep_id_t                             ep_num;
+    udd_ep_job_t *                          ptr_job;
 
     ptr_job = udd_ep_get_job(ep);
-    ep_num = ep & USB_EP_ADDR_MASK;
+    ep_num  = ep & USB_EP_ADDR_MASK;
 
     ep_size = ptr_job->ep_size;
     /* Update number of data transferred */
@@ -312,9 +306,9 @@ static void udd_ep_trans_out_next(void* pointer)
     if ((nb_trans == ep_callback_para->out_buffer_size) && (ptr_job->nb_trans != ptr_job->buf_size)) {
         next_trans = ptr_job->buf_size - ptr_job->nb_trans;
         if (UDD_ENDPOINT_MAX_TRANS < next_trans) {
-        /* The USB hardware support a maximum transfer size
-         * of UDD_ENDPOINT_MAX_TRANS Bytes */
-        next_trans = UDD_ENDPOINT_MAX_TRANS - (UDD_ENDPOINT_MAX_TRANS % ep_size);
+            /* The USB hardware support a maximum transfer size
+             * of UDD_ENDPOINT_MAX_TRANS Bytes */
+            next_trans = UDD_ENDPOINT_MAX_TRANS - (UDD_ENDPOINT_MAX_TRANS % ep_size);
         } else {
             next_trans -= next_trans % ep_size;
         }
@@ -322,9 +316,9 @@ static void udd_ep_trans_out_next(void* pointer)
         if (next_trans < ep_size) {
             /* Use the cache buffer for Bulk or Interrupt size endpoint */
             ptr_job->b_use_out_cache_buffer = true;
-            usb_device_endpoint_read_buffer_job(&usb_device,ep_num,udd_ep_out_cache_buffer[ep_num - 1],ep_size);
+            usb_device_endpoint_read_buffer_job(&usb_device, ep_num, udd_ep_out_cache_buffer[ep_num - 1], ep_size);
         } else {
-            usb_device_endpoint_read_buffer_job(&usb_device,ep_num,&ptr_job->buf[ptr_job->nb_trans],next_trans);
+            usb_device_endpoint_read_buffer_job(&usb_device, ep_num, &ptr_job->buf[ptr_job->nb_trans], next_trans);
         }
         return;
     }
@@ -341,10 +335,9 @@ static void udd_ep_trans_out_next(void* pointer)
  * \param[in] module_inst Pointer to USB module instance
  * \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
  */
-static void udd_ep_transfer_process(struct usb_module *module_inst, void* pointer)
-{
-    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
-    udd_ep_id_t ep = ep_callback_para->endpoint_address;
+static void udd_ep_transfer_process(struct usb_module *module_inst, void *pointer) {
+    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
+    udd_ep_id_t                             ep               = ep_callback_para->endpoint_address;
 
     if (ep & USB_EP_DIR_IN) {
         udd_ep_trans_in_next(pointer);
@@ -353,8 +346,7 @@ static void udd_ep_transfer_process(struct usb_module *module_inst, void* pointe
     }
 }
 
-void udd_ep_abort(udd_ep_id_t ep)
-{
+void udd_ep_abort(udd_ep_id_t ep) {
     udd_ep_job_t *ptr_job;
 
     usb_device_endpoint_abort_job(&usb_device, ep);
@@ -371,23 +363,13 @@ void udd_ep_abort(udd_ep_id_t ep)
     }
 }
 
-bool udd_is_high_speed(void)
-{
-    return false;
-}
+bool udd_is_high_speed(void) { return false; }
 
-uint16_t udd_get_frame_number(void)
-{
-    return usb_device_get_frame_number(&usb_device);
-}
+uint16_t udd_get_frame_number(void) { return usb_device_get_frame_number(&usb_device); }
 
-uint16_t udd_get_micro_frame_number(void)
-{
-    return usb_device_get_micro_frame_number(&usb_device);
-}
+uint16_t udd_get_micro_frame_number(void) { return usb_device_get_micro_frame_number(&usb_device); }
 
-void udd_ep_free(udd_ep_id_t ep)
-{
+void udd_ep_free(udd_ep_id_t ep) {
     struct usb_device_endpoint_config config_ep;
     usb_device_endpoint_get_config_defaults(&config_ep);
 
@@ -395,45 +377,44 @@ void udd_ep_free(udd_ep_id_t ep)
     udd_ep_abort(ep);
 
     config_ep.ep_address = ep;
-    config_ep.ep_type = USB_DEVICE_ENDPOINT_TYPE_DISABLE;
+    config_ep.ep_type    = USB_DEVICE_ENDPOINT_TYPE_DISABLE;
     usb_device_endpoint_set_config(&usb_device, &config_ep);
-    usb_device_endpoint_unregister_callback(&usb_device,ep_num,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
-    usb_device_endpoint_disable_callback(&usb_device,ep,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
+    usb_device_endpoint_unregister_callback(&usb_device, ep_num, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
+    usb_device_endpoint_disable_callback(&usb_device, ep, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
 }
 
-bool udd_ep_alloc(udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize)
-{
+bool udd_ep_alloc(udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize) {
     struct usb_device_endpoint_config config_ep;
     usb_device_endpoint_get_config_defaults(&config_ep);
 
     config_ep.ep_address = ep;
 
-    if(MaxEndpointSize <= 8) {
+    if (MaxEndpointSize <= 8) {
         config_ep.ep_size = USB_ENDPOINT_8_BYTE;
-    } else if(MaxEndpointSize <= 16) {
+    } else if (MaxEndpointSize <= 16) {
         config_ep.ep_size = USB_ENDPOINT_16_BYTE;
-    } else if(MaxEndpointSize <= 32) {
+    } else if (MaxEndpointSize <= 32) {
         config_ep.ep_size = USB_ENDPOINT_32_BYTE;
-    } else if(MaxEndpointSize <= 64) {
+    } else if (MaxEndpointSize <= 64) {
         config_ep.ep_size = USB_ENDPOINT_64_BYTE;
-    } else if(MaxEndpointSize <= 128) {
+    } else if (MaxEndpointSize <= 128) {
         config_ep.ep_size = USB_ENDPOINT_128_BYTE;
-    } else if(MaxEndpointSize <= 256) {
+    } else if (MaxEndpointSize <= 256) {
         config_ep.ep_size = USB_ENDPOINT_256_BYTE;
-    } else if(MaxEndpointSize <= 512) {
+    } else if (MaxEndpointSize <= 512) {
         config_ep.ep_size = USB_ENDPOINT_512_BYTE;
-    } else if(MaxEndpointSize <= 1023) {
+    } else if (MaxEndpointSize <= 1023) {
         config_ep.ep_size = USB_ENDPOINT_1023_BYTE;
     } else {
         return false;
     }
     udd_ep_job_t *ptr_job = udd_ep_get_job(ep);
-    ptr_job->ep_size = MaxEndpointSize;
+    ptr_job->ep_size      = MaxEndpointSize;
 
     bmAttributes = bmAttributes & USB_EP_TYPE_MASK;
 
     /* Check endpoint type */
-    if(USB_EP_TYPE_ISOCHRONOUS == bmAttributes) {
+    if (USB_EP_TYPE_ISOCHRONOUS == bmAttributes) {
         config_ep.ep_type = USB_DEVICE_ENDPOINT_TYPE_ISOCHRONOUS;
     } else if (USB_EP_TYPE_BULK == bmAttributes) {
         config_ep.ep_type = USB_DEVICE_ENDPOINT_TYPE_BULK;
@@ -448,20 +429,16 @@ bool udd_ep_alloc(udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize
     if (STATUS_OK != usb_device_endpoint_set_config(&usb_device, &config_ep)) {
         return false;
     }
-    usb_device_endpoint_register_callback(&usb_device,ep_num,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT,udd_ep_transfer_process);
-    usb_device_endpoint_enable_callback(&usb_device,ep,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
-    usb_device_endpoint_enable_callback(&usb_device,ep,USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL);
+    usb_device_endpoint_register_callback(&usb_device, ep_num, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT, udd_ep_transfer_process);
+    usb_device_endpoint_enable_callback(&usb_device, ep, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
+    usb_device_endpoint_enable_callback(&usb_device, ep, USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL);
 
     return true;
 }
 
-bool udd_ep_is_halted(udd_ep_id_t ep)
-{
-    return usb_device_endpoint_is_halted(&usb_device, ep);
-}
+bool udd_ep_is_halted(udd_ep_id_t ep) { return usb_device_endpoint_is_halted(&usb_device, ep); }
 
-bool udd_ep_set_halt(udd_ep_id_t ep)
-{
+bool udd_ep_set_halt(udd_ep_id_t ep) {
     uint8_t ep_num = ep & USB_EP_ADDR_MASK;
 
     if (USB_DEVICE_MAX_EP < ep_num) {
@@ -474,10 +451,9 @@ bool udd_ep_set_halt(udd_ep_id_t ep)
     return true;
 }
 
-bool udd_ep_clear_halt(udd_ep_id_t ep)
-{
+bool udd_ep_clear_halt(udd_ep_id_t ep) {
     udd_ep_job_t *ptr_job;
-    uint8_t ep_num = ep & USB_EP_ADDR_MASK;
+    uint8_t       ep_num = ep & USB_EP_ADDR_MASK;
 
     if (USB_DEVICE_MAX_EP < ep_num) {
         return false;
@@ -495,9 +471,8 @@ bool udd_ep_clear_halt(udd_ep_id_t ep)
     return true;
 }
 
-bool udd_ep_wait_stall_clear(udd_ep_id_t ep, udd_callback_halt_cleared_t callback)
-{
-    udd_ep_id_t ep_num;
+bool udd_ep_wait_stall_clear(udd_ep_id_t ep, udd_callback_halt_cleared_t callback) {
+    udd_ep_id_t   ep_num;
     udd_ep_job_t *ptr_job;
 
     ep_num = ep & USB_EP_ADDR_MASK;
@@ -513,7 +488,7 @@ bool udd_ep_wait_stall_clear(udd_ep_id_t ep, udd_callback_halt_cleared_t callbac
     /* Wait clear halt endpoint */
     if (usb_device_endpoint_is_halted(&usb_device, ep)) {
         /* Endpoint halted then registers the callback */
-        ptr_job->busy = true;
+        ptr_job->busy        = true;
         ptr_job->call_nohalt = callback;
         return true;
     } else if (usb_device_endpoint_is_configured(&usb_device, ep)) {
@@ -527,19 +502,17 @@ bool udd_ep_wait_stall_clear(udd_ep_id_t ep, udd_callback_halt_cleared_t callbac
 /**
  * \brief Control Endpoint stall sending data
  */
-static void udd_ctrl_stall_data(void)
-{
+static void udd_ctrl_stall_data(void) {
     udd_ep_control_state = UDD_EPCTRL_STALL_REQ;
 
     usb_device_endpoint_set_halt(&usb_device, USB_EP_DIR_IN);
     usb_device_endpoint_clear_halt(&usb_device, USB_EP_DIR_OUT);
 }
 
-bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, udd_callback_trans_t callback)
-{
-    udd_ep_id_t ep_num;
+bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, udd_callback_trans_t callback) {
+    udd_ep_id_t   ep_num;
     udd_ep_job_t *ptr_job;
-    uint32_t irqflags;
+    uint32_t      irqflags;
 
     ep_num = ep & USB_EP_ADDR_MASK;
 
@@ -564,11 +537,11 @@ bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t bu
     __set_PRIMASK(irqflags);
 
     /* No job running, set up a new one */
-    ptr_job->buf = buf;
-    ptr_job->buf_size = buf_size;
-    ptr_job->nb_trans = 0;
-    ptr_job->call_trans = callback;
-    ptr_job->b_shortpacket = b_shortpacket;
+    ptr_job->buf                    = buf;
+    ptr_job->buf_size               = buf_size;
+    ptr_job->nb_trans               = 0;
+    ptr_job->call_trans             = callback;
+    ptr_job->b_shortpacket          = b_shortpacket;
     ptr_job->b_use_out_cache_buffer = false;
 
     /* Initialize value to simulate a empty transfer */
@@ -580,10 +553,10 @@ bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t bu
             if (UDD_ENDPOINT_MAX_TRANS < next_trans) {
                 next_trans = UDD_ENDPOINT_MAX_TRANS - (UDD_ENDPOINT_MAX_TRANS % ptr_job->ep_size);
             }
-            ptr_job->b_shortpacket = ptr_job->b_shortpacket &&  (0 == (next_trans % ptr_job->ep_size));
+            ptr_job->b_shortpacket = ptr_job->b_shortpacket && (0 == (next_trans % ptr_job->ep_size));
         } else if (true == ptr_job->b_shortpacket) {
             ptr_job->b_shortpacket = false; /* avoid to send zero length packet again */
-            next_trans = 0;
+            next_trans             = 0;
         } else {
             ptr_job->busy = false;
             if (NULL != ptr_job->call_trans) {
@@ -591,30 +564,22 @@ bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t bu
             }
             return true;
         }
-        return (STATUS_OK ==
-                usb_device_endpoint_write_buffer_job(&usb_device,
-                        ep_num,&ptr_job->buf[0],next_trans));
+        return (STATUS_OK == usb_device_endpoint_write_buffer_job(&usb_device, ep_num, &ptr_job->buf[0], next_trans));
     } else {
         if (0 != ptr_job->buf_size) {
             next_trans = ptr_job->buf_size;
             if (UDD_ENDPOINT_MAX_TRANS < next_trans) {
                 /* The USB hardware support a maximum transfer size
                  * of UDD_ENDPOINT_MAX_TRANS Bytes */
-                next_trans = UDD_ENDPOINT_MAX_TRANS -
-                        (UDD_ENDPOINT_MAX_TRANS % ptr_job->ep_size);
+                next_trans = UDD_ENDPOINT_MAX_TRANS - (UDD_ENDPOINT_MAX_TRANS % ptr_job->ep_size);
             } else {
                 next_trans -= next_trans % ptr_job->ep_size;
             }
             if (next_trans < ptr_job->ep_size) {
                 ptr_job->b_use_out_cache_buffer = true;
-                return (STATUS_OK ==
-                        usb_device_endpoint_read_buffer_job(&usb_device, ep_num,
-                                udd_ep_out_cache_buffer[ep_num - 1],
-                                ptr_job->ep_size));
+                return (STATUS_OK == usb_device_endpoint_read_buffer_job(&usb_device, ep_num, udd_ep_out_cache_buffer[ep_num - 1], ptr_job->ep_size));
             } else {
-                return (STATUS_OK ==
-                        usb_device_endpoint_read_buffer_job(&usb_device, ep_num,
-                                &ptr_job->buf[0],next_trans));
+                return (STATUS_OK == usb_device_endpoint_read_buffer_job(&usb_device, ep_num, &ptr_job->buf[0], next_trans));
             }
         } else {
             ptr_job->busy = false;
@@ -626,61 +591,51 @@ bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t bu
     }
 }
 
-void udd_set_address(uint8_t address)
-{
-    usb_device_set_address(&usb_device,address);
-}
+void udd_set_address(uint8_t address) { usb_device_set_address(&usb_device, address); }
 
-uint8_t udd_getaddress(void)
-{
-    return usb_device_get_address(&usb_device);
-}
+uint8_t udd_getaddress(void) { return usb_device_get_address(&usb_device); }
 
-void udd_send_remotewakeup(void)
-{
-    uint32_t try = 5;
+void udd_send_remotewakeup(void) {
+    uint32_t try
+        = 5;
     udd_wait_clock_ready();
     udd_sleep_mode(UDD_STATE_IDLE);
-    while(2 != usb_get_state_machine_status(&usb_device) && try --) {
+    while (2 != usb_get_state_machine_status(&usb_device) && try --) {
         usb_device_send_remote_wake_up(&usb_device);
     }
 }
 
-void udd_set_setup_payload( uint8_t *payload, uint16_t payload_size )
-{
-    udd_g_ctrlreq.payload = payload;
+void udd_set_setup_payload(uint8_t *payload, uint16_t payload_size) {
+    udd_g_ctrlreq.payload      = payload;
     udd_g_ctrlreq.payload_size = payload_size;
 }
 
 /**
  * \brief Control Endpoint translate the data in buffer into Device Request Struct
  */
-static void udd_ctrl_fetch_ram(void)
-{
+static void udd_ctrl_fetch_ram(void) {
     udd_g_ctrlreq.req.bmRequestType = udd_ctrl_buffer[0];
-    udd_g_ctrlreq.req.bRequest = udd_ctrl_buffer[1];
-    udd_g_ctrlreq.req.wValue = ((uint16_t)(udd_ctrl_buffer[3]) << 8) + udd_ctrl_buffer[2];
-    udd_g_ctrlreq.req.wIndex = ((uint16_t)(udd_ctrl_buffer[5]) << 8) + udd_ctrl_buffer[4];
-    udd_g_ctrlreq.req.wLength = ((uint16_t)(udd_ctrl_buffer[7]) << 8) + udd_ctrl_buffer[6];
+    udd_g_ctrlreq.req.bRequest      = udd_ctrl_buffer[1];
+    udd_g_ctrlreq.req.wValue        = ((uint16_t)(udd_ctrl_buffer[3]) << 8) + udd_ctrl_buffer[2];
+    udd_g_ctrlreq.req.wIndex        = ((uint16_t)(udd_ctrl_buffer[5]) << 8) + udd_ctrl_buffer[4];
+    udd_g_ctrlreq.req.wLength       = ((uint16_t)(udd_ctrl_buffer[7]) << 8) + udd_ctrl_buffer[6];
 }
 
 /**
  * \brief Control Endpoint send out zero length packet
  */
-static void udd_ctrl_send_zlp_in(void)
-{
+static void udd_ctrl_send_zlp_in(void) {
     udd_ep_control_state = UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP;
-    usb_device_endpoint_setup_buffer_job(&usb_device,udd_ctrl_buffer);
-    usb_device_endpoint_write_buffer_job(&usb_device,0,udd_g_ctrlreq.payload,0);
+    usb_device_endpoint_setup_buffer_job(&usb_device, udd_ctrl_buffer);
+    usb_device_endpoint_write_buffer_job(&usb_device, 0, udd_g_ctrlreq.payload, 0);
 }
 
 /**
  * \brief Process control endpoint IN transaction
  */
-static void udd_ctrl_in_sent(void)
-{
+static void udd_ctrl_in_sent(void) {
     static bool b_shortpacket = false;
-    uint16_t nb_remain;
+    uint16_t    nb_remain;
 
     nb_remain = udd_g_ctrlreq.payload_size - udd_ctrl_payload_nb_trans;
 
@@ -691,7 +646,7 @@ static void udd_ctrl_in_sent(void)
             /* All data requested are transferred or a short packet has been sent, then it is the end of data phase.
              * Generate an OUT ZLP for handshake phase */
             udd_ep_control_state = UDD_EPCTRL_HANDSHAKE_WAIT_OUT_ZLP;
-            usb_device_endpoint_setup_buffer_job(&usb_device,udd_ctrl_buffer);
+            usb_device_endpoint_setup_buffer_job(&usb_device, udd_ctrl_buffer);
             return;
         }
         /* Need of new buffer because the data phase is not complete */
@@ -701,20 +656,20 @@ static void udd_ctrl_in_sent(void)
         } else {
             /* A new payload buffer is given */
             udd_ctrl_payload_nb_trans = 0;
-            nb_remain = udd_g_ctrlreq.payload_size;
+            nb_remain                 = udd_g_ctrlreq.payload_size;
         }
     }
 
     /* Continue transfer and send next data */
     if (nb_remain >= USB_DEVICE_EP_CTRL_SIZE) {
-        nb_remain = USB_DEVICE_EP_CTRL_SIZE;
+        nb_remain     = USB_DEVICE_EP_CTRL_SIZE;
         b_shortpacket = false;
     } else {
         b_shortpacket = true;
     }
 
     /* Link payload buffer directly on USB hardware */
-    usb_device_endpoint_write_buffer_job(&usb_device,0,udd_g_ctrlreq.payload + udd_ctrl_payload_nb_trans,nb_remain);
+    usb_device_endpoint_write_buffer_job(&usb_device, 0, udd_g_ctrlreq.payload + udd_ctrl_payload_nb_trans, nb_remain);
 
     udd_ctrl_payload_nb_trans += nb_remain;
 }
@@ -723,9 +678,8 @@ static void udd_ctrl_in_sent(void)
  * \brief Process control endpoint OUT transaction
  * \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
  */
-static void udd_ctrl_out_received(void* pointer)
-{
-    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
+static void udd_ctrl_out_received(void *pointer) {
+    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
 
     uint16_t nb_data;
     nb_data = ep_callback_para->received_bytes; /* Read data received during OUT phase */
@@ -735,11 +689,10 @@ static void udd_ctrl_out_received(void* pointer)
         nb_data = udd_g_ctrlreq.payload_size - udd_ctrl_payload_nb_trans;
     }
 
-    memcpy((uint8_t *) (udd_g_ctrlreq.payload + udd_ctrl_payload_nb_trans), udd_ctrl_buffer, nb_data);
+    memcpy((uint8_t *)(udd_g_ctrlreq.payload + udd_ctrl_payload_nb_trans), udd_ctrl_buffer, nb_data);
     udd_ctrl_payload_nb_trans += nb_data;
 
-    if ((USB_DEVICE_EP_CTRL_SIZE != nb_data) || \
-    (udd_g_ctrlreq.req.wLength <= (udd_ctrl_prev_payload_nb_trans + udd_ctrl_payload_nb_trans))) {
+    if ((USB_DEVICE_EP_CTRL_SIZE != nb_data) || (udd_g_ctrlreq.req.wLength <= (udd_ctrl_prev_payload_nb_trans + udd_ctrl_payload_nb_trans))) {
         /* End of reception because it is a short packet
          * or all data are transferred */
 
@@ -786,7 +739,7 @@ static void udd_ctrl_out_received(void* pointer)
         /* Reinitialize reception on payload buffer */
         udd_ctrl_payload_nb_trans = 0;
     }
-    usb_device_endpoint_read_buffer_job(&usb_device,0,udd_ctrl_buffer,USB_DEVICE_EP_CTRL_SIZE);
+    usb_device_endpoint_read_buffer_job(&usb_device, 0, udd_ctrl_buffer, USB_DEVICE_EP_CTRL_SIZE);
 }
 
 /**
@@ -795,9 +748,8 @@ static void udd_ctrl_out_received(void* pointer)
  * \param[in] module_inst pointer to USB module instance
  * \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
  */
-static void _usb_ep0_on_setup(struct usb_module *module_inst, void* pointer)
-{
-    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
+static void _usb_ep0_on_setup(struct usb_module *module_inst, void *pointer) {
+    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
 
     if (UDD_EPCTRL_SETUP != udd_ep_control_state) {
         if (NULL != udd_g_ctrlreq.callback) {
@@ -805,7 +757,7 @@ static void _usb_ep0_on_setup(struct usb_module *module_inst, void* pointer)
         }
         udd_ep_control_state = UDD_EPCTRL_SETUP;
     }
-    if ( 8 != ep_callback_para->received_bytes) {
+    if (8 != ep_callback_para->received_bytes) {
         udd_ctrl_stall_data();
         return;
     } else {
@@ -815,20 +767,20 @@ static void _usb_ep0_on_setup(struct usb_module *module_inst, void* pointer)
             return;
         } else if (Udd_setup_is_in()) {
             udd_ctrl_prev_payload_nb_trans = 0;
-            udd_ctrl_payload_nb_trans = 0;
-            udd_ep_control_state = UDD_EPCTRL_DATA_IN;
-            usb_device_endpoint_read_buffer_job(&usb_device,0,udd_ctrl_buffer,USB_DEVICE_EP_CTRL_SIZE);
+            udd_ctrl_payload_nb_trans      = 0;
+            udd_ep_control_state           = UDD_EPCTRL_DATA_IN;
+            usb_device_endpoint_read_buffer_job(&usb_device, 0, udd_ctrl_buffer, USB_DEVICE_EP_CTRL_SIZE);
             udd_ctrl_in_sent();
         } else {
-            if(0 == udd_g_ctrlreq.req.wLength) {
+            if (0 == udd_g_ctrlreq.req.wLength) {
                 udd_ctrl_send_zlp_in();
                 return;
             } else {
                 udd_ctrl_prev_payload_nb_trans = 0;
-                udd_ctrl_payload_nb_trans = 0;
-                udd_ep_control_state = UDD_EPCTRL_DATA_OUT;
+                udd_ctrl_payload_nb_trans      = 0;
+                udd_ep_control_state           = UDD_EPCTRL_DATA_OUT;
                 /* Initialize buffer size and enable OUT bank */
-                usb_device_endpoint_read_buffer_job(&usb_device,0,udd_ctrl_buffer,USB_DEVICE_EP_CTRL_SIZE);
+                usb_device_endpoint_read_buffer_job(&usb_device, 0, udd_ctrl_buffer, USB_DEVICE_EP_CTRL_SIZE);
             }
         }
     }
@@ -838,9 +790,8 @@ static void _usb_ep0_on_setup(struct usb_module *module_inst, void* pointer)
  * \brief Control Endpoint Process when underflow condition has occurred
  * \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
  */
-static void udd_ctrl_underflow(void* pointer)
-{
-    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
+static void udd_ctrl_underflow(void *pointer) {
+    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
 
     if (UDD_EPCTRL_DATA_OUT == udd_ep_control_state) {
         /* Host want to stop OUT transaction
@@ -857,9 +808,8 @@ static void udd_ctrl_underflow(void* pointer)
  * \brief Control Endpoint Process when overflow condition has occurred
  * \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
  */
-static void udd_ctrl_overflow(void* pointer)
-{
-    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
+static void udd_ctrl_overflow(void *pointer) {
+    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
 
     if (UDD_EPCTRL_DATA_IN == udd_ep_control_state) {
         /* Host want to stop IN transaction
@@ -878,11 +828,10 @@ static void udd_ctrl_overflow(void* pointer)
  * \param[in] module_inst Pointer to USB module instance
  * \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
  */
-static void _usb_ep0_on_tansfer_fail(struct usb_module *module_inst, void* pointer)
-{
-    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
+static void _usb_ep0_on_tansfer_fail(struct usb_module *module_inst, void *pointer) {
+    struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
 
-    if(ep_callback_para->endpoint_address & USB_EP_DIR_IN) {
+    if (ep_callback_para->endpoint_address & USB_EP_DIR_IN) {
         udd_ctrl_underflow(pointer);
     } else {
         udd_ctrl_overflow(pointer);
@@ -895,9 +844,8 @@ static void _usb_ep0_on_tansfer_fail(struct usb_module *module_inst, void* point
  * \param[in] module_inst Pointer to USB module instance
  * \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
  */
-static void _usb_ep0_on_tansfer_ok(struct usb_module *module_inst, void *pointer)
-{
-    if (UDD_EPCTRL_DATA_OUT  == udd_ep_control_state) { /* handshake Out for status stage */
+static void _usb_ep0_on_tansfer_ok(struct usb_module *module_inst, void *pointer) {
+    if (UDD_EPCTRL_DATA_OUT == udd_ep_control_state) { /* handshake Out for status stage */
         udd_ctrl_out_received(pointer);
     } else if (UDD_EPCTRL_DATA_IN == udd_ep_control_state) { /* handshake In for status stage */
         udd_ctrl_in_sent();
@@ -913,25 +861,24 @@ static void _usb_ep0_on_tansfer_ok(struct usb_module *module_inst, void *pointer
  * \brief Enable Control Endpoint
  * \param[in] module_inst Pointer to USB module instance
  */
-static void udd_ctrl_ep_enable(struct usb_module *module_inst)
-{
+static void udd_ctrl_ep_enable(struct usb_module *module_inst) {
     /* USB Device Endpoint0 Configuration */
     struct usb_device_endpoint_config config_ep0;
 
     usb_device_endpoint_get_config_defaults(&config_ep0);
     config_ep0.ep_size = (enum usb_endpoint_size)(32 - clz(((uint32_t)Min(Max(USB_DEVICE_EP_CTRL_SIZE, 8), 1024) << 1) - 1) - 1 - 3);
-    usb_device_endpoint_set_config(module_inst,&config_ep0);
+    usb_device_endpoint_set_config(module_inst, &config_ep0);
 
-    usb_device_endpoint_setup_buffer_job(module_inst,udd_ctrl_buffer);
+    usb_device_endpoint_setup_buffer_job(module_inst, udd_ctrl_buffer);
 
-    usb_device_endpoint_register_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_RXSTP, _usb_ep0_on_setup );
-    usb_device_endpoint_register_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT,_usb_ep0_on_tansfer_ok );
-    usb_device_endpoint_register_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL,_usb_ep0_on_tansfer_fail );
-    usb_device_endpoint_enable_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_RXSTP);
-    usb_device_endpoint_enable_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
-    usb_device_endpoint_enable_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL);
+    usb_device_endpoint_register_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_RXSTP, _usb_ep0_on_setup);
+    usb_device_endpoint_register_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT, _usb_ep0_on_tansfer_ok);
+    usb_device_endpoint_register_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL, _usb_ep0_on_tansfer_fail);
+    usb_device_endpoint_enable_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_RXSTP);
+    usb_device_endpoint_enable_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
+    usb_device_endpoint_enable_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL);
 
-#ifdef  USB_DEVICE_LPM_SUPPORT
+#ifdef USB_DEVICE_LPM_SUPPORT
     // Enable LPM feature
     usb_device_set_lpm_mode(module_inst, USB_DEVICE_LPM_ACK);
 #endif
@@ -945,8 +892,7 @@ static void udd_ctrl_ep_enable(struct usb_module *module_inst)
  * \param[in] module_inst Pointer to USB module instance
  * \param[in] pointer Pointer to the callback parameter from driver layer.
  */
-static void _usb_on_suspend(struct usb_module *module_inst, void *pointer)
-{
+static void _usb_on_suspend(struct usb_module *module_inst, void *pointer) {
     usb_device_disable_callback(&usb_device, USB_DEVICE_CALLBACK_SUSPEND);
     usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_WAKEUP);
     udd_sleep_mode(UDD_STATE_SUSPEND);
@@ -955,9 +901,8 @@ static void _usb_on_suspend(struct usb_module *module_inst, void *pointer)
 #endif
 }
 
-#ifdef  USB_DEVICE_LPM_SUPPORT
-static void _usb_device_lpm_suspend(struct usb_module *module_inst, void *pointer)
-{
+#ifdef USB_DEVICE_LPM_SUPPORT
+static void _usb_device_lpm_suspend(struct usb_module *module_inst, void *pointer) {
     dbg_print("LPM_SUSP\n");
 
     uint32_t *lpm_wakeup_enable;
@@ -967,7 +912,7 @@ static void _usb_device_lpm_suspend(struct usb_module *module_inst, void *pointe
     usb_device_disable_callback(&usb_device, USB_DEVICE_CALLBACK_SUSPEND);
     usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_WAKEUP);
 
-//#warning Here the sleep mode must be choose to have a DFLL startup time < bmAttribut.HIRD
+    //#warning Here the sleep mode must be choose to have a DFLL startup time < bmAttribut.HIRD
     udd_sleep_mode(UDD_STATE_SUSPEND_LPM);  // Enter in LPM SUSPEND mode
     if ((*lpm_wakeup_enable)) {
         UDC_REMOTEWAKEUP_LPM_ENABLE();
@@ -985,8 +930,7 @@ static void _usb_device_lpm_suspend(struct usb_module *module_inst, void *pointe
  * \param[in] module_inst Pointer to USB module instance
  * \param[in] pointer Pointer to the callback parameter from driver layer.
  */
-static void _usb_on_sof_notify(struct usb_module *module_inst, void *pointer)
-{
+static void _usb_on_sof_notify(struct usb_module *module_inst, void *pointer) {
     udc_sof_notify();
 #ifdef UDC_SOF_EVENT
     UDC_SOF_EVENT();
@@ -999,11 +943,10 @@ static void _usb_on_sof_notify(struct usb_module *module_inst, void *pointer)
  * \param[in] module_inst Pointer to USB module instance
  * \param[in] pointer Pointer to the callback parameter from driver layer.
  */
-static void _usb_on_bus_reset(struct usb_module *module_inst, void *pointer)
-{
+static void _usb_on_bus_reset(struct usb_module *module_inst, void *pointer) {
     // Reset USB Device Stack Core
     udc_reset();
-    usb_device_set_address(module_inst,0);
+    usb_device_set_address(module_inst, 0);
     udd_ctrl_ep_enable(module_inst);
 }
 
@@ -1013,13 +956,12 @@ static void _usb_on_bus_reset(struct usb_module *module_inst, void *pointer)
  * \param[in] module_inst Pointer to USB module instance
  * \param[in] pointer Pointer to the callback parameter from driver layer.
  */
-static void _usb_on_wakeup(struct usb_module *module_inst, void *pointer)
-{
+static void _usb_on_wakeup(struct usb_module *module_inst, void *pointer) {
     udd_wait_clock_ready();
 
     usb_device_disable_callback(&usb_device, USB_DEVICE_CALLBACK_WAKEUP);
     usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_SUSPEND);
-#ifdef  USB_DEVICE_LPM_SUPPORT
+#ifdef USB_DEVICE_LPM_SUPPORT
     usb_device_register_callback(&usb_device, USB_DEVICE_CALLBACK_LPMSUSP, _usb_device_lpm_suspend);
     usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_LPMSUSP);
 #endif
@@ -1029,14 +971,12 @@ static void _usb_on_wakeup(struct usb_module *module_inst, void *pointer)
 #endif
 }
 
-void udd_detach(void)
-{
+void udd_detach(void) {
     usb_device_detach(&usb_device);
     udd_sleep_mode(UDD_STATE_SUSPEND);
 }
 
-void udd_attach(void)
-{
+void udd_attach(void) {
     udd_sleep_mode(UDD_STATE_IDLE);
     usb_device_attach(&usb_device);
 
@@ -1049,14 +989,13 @@ void udd_attach(void)
     usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_SOF);
     usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_RESET);
     usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_WAKEUP);
-#ifdef  USB_DEVICE_LPM_SUPPORT
+#ifdef USB_DEVICE_LPM_SUPPORT
     usb_device_register_callback(&usb_device, USB_DEVICE_CALLBACK_LPMSUSP, _usb_device_lpm_suspend);
     usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_LPMSUSP);
 #endif
 }
 
-void udd_enable(void)
-{
+void udd_enable(void) {
     uint32_t irqflags;
 
     /* To avoid USB interrupt before end of initialization */
@@ -1088,8 +1027,7 @@ void udd_enable(void)
     __set_PRIMASK(irqflags);
 }
 
-void udd_disable(void)
-{
+void udd_disable(void) {
     udd_detach();
 
     udd_sleep_mode(UDD_STATE_OFF);
index 76ced474dc22ba9906b5db41192cf605d4e41043..e1ffa3e18468a339ca29361bf0e2b876716830e6 100644 (file)
 #ifndef _MAIN_H_
 #define _MAIN_H_
 
-//Enters the application in low power mode
-//Callback called when USB host sets USB line in suspend state
+// Enters the application in low power mode
+// Callback called when USB host sets USB line in suspend state
 void main_suspend_action(void);
 
-//Called by UDD when the USB line exit of suspend state
+// Called by UDD when the USB line exit of suspend state
 void main_resume_action(void);
 
-//Called when a start of frame is received on USB line
+// Called when a start of frame is received on USB line
 void main_sof_action(void);
 
-//Called by UDC when USB Host request to enable remote wakeup
+// Called by UDC when USB Host request to enable remote wakeup
 void main_remotewakeup_enable(void);
 
-//Called by UDC when USB Host request to disable remote wakeup
+// Called by UDC when USB Host request to disable remote wakeup
 void main_remotewakeup_disable(void);
 
-
 #ifdef KBD
 extern volatile bool main_b_kbd_enable;
-bool main_kbd_enable(void);
-void main_kbd_disable(void);
-#endif //KBD
+bool                 main_kbd_enable(void);
+void                 main_kbd_disable(void);
+#endif  // KBD
 
 #ifdef NKRO
 extern volatile bool main_b_nkro_enable;
-bool main_nkro_enable(void);
-void main_nkro_disable(void);
-#endif //NKRO
+bool                 main_nkro_enable(void);
+void                 main_nkro_disable(void);
+#endif  // NKRO
 
 #ifdef EXK
 extern volatile bool main_b_exk_enable;
-bool main_exk_enable(void);
-void main_exk_disable(void);
-#endif //EXK
+bool                 main_exk_enable(void);
+void                 main_exk_disable(void);
+#endif  // EXK
 
 #ifdef CON
 extern volatile bool main_b_con_enable;
-bool main_con_enable(void);
-void main_con_disable(void);
-#endif //CON
+bool                 main_con_enable(void);
+void                 main_con_disable(void);
+#endif  // CON
 
 #ifdef MOU
 extern volatile bool main_b_mou_enable;
-bool main_mou_enable(void);
-void main_mou_disable(void);
-#endif //MOU
+bool                 main_mou_enable(void);
+void                 main_mou_disable(void);
+#endif  // MOU
 
 #ifdef RAW
 extern volatile bool main_b_raw_enable;
-bool main_raw_enable(void);
-void main_raw_disable(void);
-#endif //RAW
+bool                 main_raw_enable(void);
+void                 main_raw_disable(void);
+#endif  // RAW
 
-#endif // _MAIN_H_
+#endif  // _MAIN_H_
index 892a7d3a5a5e1c7190409325cbbc99aa7561df94..54d023a6eeea696d93e8e450f57ad817b68d3cd6 100644 (file)
  */
 
 //! Value for field bcdUSB
-#define  USB_V2_0    0x0200 //!< USB Specification version 2.00
-#define  USB_V2_1    0x0201 //!< USB Specification version 2.01
+#define USB_V2_0 0x0200  //!< USB Specification version 2.00
+#define USB_V2_1 0x0201  //!< USB Specification version 2.01
 
 /*! \name Generic definitions (Class, subclass and protocol)
  */
 //! @{
-#define  NO_CLASS                0x00
-#define  CLASS_VENDOR_SPECIFIC   0xFF
-#define  NO_SUBCLASS             0x00
-#define  NO_PROTOCOL             0x00
+#define NO_CLASS 0x00
+#define CLASS_VENDOR_SPECIFIC 0xFF
+#define NO_SUBCLASS 0x00
+#define NO_PROTOCOL 0x00
 //! @}
 
 //! \name IAD (Interface Association Descriptor) constants
 //! @{
-#define  CLASS_IAD               0xEF
-#define  SUB_CLASS_IAD           0x02
-#define  PROTOCOL_IAD            0x01
+#define CLASS_IAD 0xEF
+#define SUB_CLASS_IAD 0x02
+#define PROTOCOL_IAD 0x01
 //! @}
 
 /**
  * \brief USB request data transfer direction (bmRequestType)
  */
-#define  USB_REQ_DIR_OUT         (0<<7) //!< Host to device
-#define  USB_REQ_DIR_IN          (1<<7) //!< Device to host
-#define  USB_REQ_DIR_MASK        (1<<7) //!< Mask
+#define USB_REQ_DIR_OUT (0 << 7)   //!< Host to device
+#define USB_REQ_DIR_IN (1 << 7)    //!< Device to host
+#define USB_REQ_DIR_MASK (1 << 7)  //!< Mask
 
 /**
  * \brief USB request types (bmRequestType)
  */
-#define  USB_REQ_TYPE_STANDARD   (0<<5) //!< Standard request
-#define  USB_REQ_TYPE_CLASS      (1<<5) //!< Class-specific request
-#define  USB_REQ_TYPE_VENDOR     (2<<5) //!< Vendor-specific request
-#define  USB_REQ_TYPE_MASK       (3<<5) //!< Mask
+#define USB_REQ_TYPE_STANDARD (0 << 5)  //!< Standard request
+#define USB_REQ_TYPE_CLASS (1 << 5)     //!< Class-specific request
+#define USB_REQ_TYPE_VENDOR (2 << 5)    //!< Vendor-specific request
+#define USB_REQ_TYPE_MASK (3 << 5)      //!< Mask
 
 /**
  * \brief USB recipient codes (bmRequestType)
  */
-#define  USB_REQ_RECIP_DEVICE    (0<<0) //!< Recipient device
-#define  USB_REQ_RECIP_INTERFACE (1<<0) //!< Recipient interface
-#define  USB_REQ_RECIP_ENDPOINT  (2<<0) //!< Recipient endpoint
-#define  USB_REQ_RECIP_OTHER     (3<<0) //!< Recipient other
-#define  USB_REQ_RECIP_MASK      (0x1F) //!< Mask
+#define USB_REQ_RECIP_DEVICE (0 << 0)     //!< Recipient device
+#define USB_REQ_RECIP_INTERFACE (1 << 0)  //!< Recipient interface
+#define USB_REQ_RECIP_ENDPOINT (2 << 0)   //!< Recipient endpoint
+#define USB_REQ_RECIP_OTHER (3 << 0)      //!< Recipient other
+#define USB_REQ_RECIP_MASK (0x1F)         //!< Mask
 
 /**
  * \brief Standard USB requests (bRequest)
  */
 enum usb_reqid {
-    USB_REQ_GET_STATUS = 0,
-    USB_REQ_CLEAR_FEATURE = 1,
-    USB_REQ_SET_FEATURE = 3,
-    USB_REQ_SET_ADDRESS = 5,
-    USB_REQ_GET_DESCRIPTOR = 6,
-    USB_REQ_SET_DESCRIPTOR = 7,
+    USB_REQ_GET_STATUS        = 0,
+    USB_REQ_CLEAR_FEATURE     = 1,
+    USB_REQ_SET_FEATURE       = 3,
+    USB_REQ_SET_ADDRESS       = 5,
+    USB_REQ_GET_DESCRIPTOR    = 6,
+    USB_REQ_SET_DESCRIPTOR    = 7,
     USB_REQ_GET_CONFIGURATION = 8,
     USB_REQ_SET_CONFIGURATION = 9,
-    USB_REQ_GET_INTERFACE = 10,
-    USB_REQ_SET_INTERFACE = 11,
-    USB_REQ_SYNCH_FRAME = 12,
+    USB_REQ_GET_INTERFACE     = 10,
+    USB_REQ_SET_INTERFACE     = 11,
+    USB_REQ_SYNCH_FRAME       = 12,
 };
 
 /**
  * \brief Standard USB device status flags
  *
  */
-enum usb_device_status {
-    USB_DEV_STATUS_BUS_POWERED = 0,
-    USB_DEV_STATUS_SELF_POWERED = 1,
-    USB_DEV_STATUS_REMOTEWAKEUP = 2
-};
+enum usb_device_status { USB_DEV_STATUS_BUS_POWERED = 0, USB_DEV_STATUS_SELF_POWERED = 1, USB_DEV_STATUS_REMOTEWAKEUP = 2 };
 
 /**
  * \brief Standard USB Interface status flags
  *
  */
-enum usb_interface_status {
-    USB_IFACE_STATUS_RESERVED = 0
-};
+enum usb_interface_status { USB_IFACE_STATUS_RESERVED = 0 };
 
 /**
  * \brief Standard USB endpoint status flags
@@ -155,10 +149,10 @@ enum usb_endpoint_status {
  * \note valid for SetFeature request.
  */
 enum usb_device_feature {
-    USB_DEV_FEATURE_REMOTE_WAKEUP = 1, //!< Remote wakeup enabled
-    USB_DEV_FEATURE_TEST_MODE = 2,     //!< USB test mode
-    USB_DEV_FEATURE_OTG_B_HNP_ENABLE = 3,
-    USB_DEV_FEATURE_OTG_A_HNP_SUPPORT = 4,
+    USB_DEV_FEATURE_REMOTE_WAKEUP         = 1,  //!< Remote wakeup enabled
+    USB_DEV_FEATURE_TEST_MODE             = 2,  //!< USB test mode
+    USB_DEV_FEATURE_OTG_B_HNP_ENABLE      = 3,
+    USB_DEV_FEATURE_OTG_A_HNP_SUPPORT     = 4,
     USB_DEV_FEATURE_OTG_A_ALT_HNP_SUPPORT = 5
 };
 
@@ -168,10 +162,10 @@ enum usb_device_feature {
  * \note valid for USB_DEV_FEATURE_TEST_MODE request.
  */
 enum usb_device_hs_test_mode {
-    USB_DEV_TEST_MODE_J = 1,
-    USB_DEV_TEST_MODE_K = 2,
-    USB_DEV_TEST_MODE_SE0_NAK = 3,
-    USB_DEV_TEST_MODE_PACKET = 4,
+    USB_DEV_TEST_MODE_J            = 1,
+    USB_DEV_TEST_MODE_K            = 2,
+    USB_DEV_TEST_MODE_SE0_NAK      = 3,
+    USB_DEV_TEST_MODE_PACKET       = 4,
     USB_DEV_TEST_MODE_FORCE_ENABLE = 5,
 };
 
@@ -186,10 +180,10 @@ enum usb_endpoint_feature {
  * \brief Standard USB Test Mode Selectors
  */
 enum usb_test_mode_selector {
-    USB_TEST_J = 0x01,
-    USB_TEST_K = 0x02,
-    USB_TEST_SE0_NAK = 0x03,
-    USB_TEST_PACKET = 0x04,
+    USB_TEST_J            = 0x01,
+    USB_TEST_K            = 0x02,
+    USB_TEST_SE0_NAK      = 0x03,
+    USB_TEST_PACKET       = 0x04,
     USB_TEST_FORCE_ENABLE = 0x05,
 };
 
@@ -197,18 +191,18 @@ enum usb_test_mode_selector {
  * \brief Standard USB descriptor types
  */
 enum usb_descriptor_type {
-    USB_DT_DEVICE = 1,
-    USB_DT_CONFIGURATION = 2,
-    USB_DT_STRING = 3,
-    USB_DT_INTERFACE = 4,
-    USB_DT_ENDPOINT = 5,
-    USB_DT_DEVICE_QUALIFIER = 6,
+    USB_DT_DEVICE                    = 1,
+    USB_DT_CONFIGURATION             = 2,
+    USB_DT_STRING                    = 3,
+    USB_DT_INTERFACE                 = 4,
+    USB_DT_ENDPOINT                  = 5,
+    USB_DT_DEVICE_QUALIFIER          = 6,
     USB_DT_OTHER_SPEED_CONFIGURATION = 7,
-    USB_DT_INTERFACE_POWER = 8,
-    USB_DT_OTG = 9,
-    USB_DT_IAD = 0x0B,
-    USB_DT_BOS = 0x0F,
-    USB_DT_DEVICE_CAPABILITY = 0x10,
+    USB_DT_INTERFACE_POWER           = 8,
+    USB_DT_OTG                       = 9,
+    USB_DT_IAD                       = 0x0B,
+    USB_DT_BOS                       = 0x0F,
+    USB_DT_DEVICE_CAPABILITY         = 0x10,
 };
 
 /**
@@ -223,57 +217,57 @@ enum usb_capability_type {
  * To fill bmAttributes field of usb_capa_ext_desc_t structure.
  */
 enum usb_capability_extension_attr {
-    USB_DC_EXT_LPM  = 0x00000002,
+    USB_DC_EXT_LPM = 0x00000002,
 };
 
-#define HIRD_50_US    0
-#define HIRD_125_US   1
-#define HIRD_200_US   2
-#define HIRD_275_US   3
-#define HIRD_350_US   4
-#define HIRD_425_US   5
-#define HIRD_500_US   6
-#define HIRD_575_US  7
-#define HIRD_650_US  8
-#define HIRD_725_US  9
-#define HIRD_800_US  10
-#define HIRD_875_US  11
-#define HIRD_950_US  12
-#define HIRD_1025_US  13
-#define HIRD_1100_US  14
-#define HIRD_1175_US  15
+#define HIRD_50_US 0
+#define HIRD_125_US 1
+#define HIRD_200_US 2
+#define HIRD_275_US 3
+#define HIRD_350_US 4
+#define HIRD_425_US 5
+#define HIRD_500_US 6
+#define HIRD_575_US 7
+#define HIRD_650_US 8
+#define HIRD_725_US 9
+#define HIRD_800_US 10
+#define HIRD_875_US 11
+#define HIRD_950_US 12
+#define HIRD_1025_US 13
+#define HIRD_1100_US 14
+#define HIRD_1175_US 15
 
 /** Fields definition from a LPM TOKEN  */
-#define  USB_LPM_ATTRIBUT_BLINKSTATE_MASK      (0xF << 0)
-#define  USB_LPM_ATTRIBUT_FIRD_MASK            (0xF << 4)
-#define  USB_LPM_ATTRIBUT_REMOTEWAKE_MASK      (1 << 8)
-#define  USB_LPM_ATTRIBUT_BLINKSTATE(value)    ((value & 0xF) << 0)
-#define  USB_LPM_ATTRIBUT_FIRD(value)          ((value & 0xF) << 4)
-#define  USB_LPM_ATTRIBUT_REMOTEWAKE(value)    ((value & 1) << 8)
-#define  USB_LPM_ATTRIBUT_BLINKSTATE_L1        USB_LPM_ATTRIBUT_BLINKSTATE(1)
+#define USB_LPM_ATTRIBUT_BLINKSTATE_MASK (0xF << 0)
+#define USB_LPM_ATTRIBUT_FIRD_MASK (0xF << 4)
+#define USB_LPM_ATTRIBUT_REMOTEWAKE_MASK (1 << 8)
+#define USB_LPM_ATTRIBUT_BLINKSTATE(value) ((value & 0xF) << 0)
+#define USB_LPM_ATTRIBUT_FIRD(value) ((value & 0xF) << 4)
+#define USB_LPM_ATTRIBUT_REMOTEWAKE(value) ((value & 1) << 8)
+#define USB_LPM_ATTRIBUT_BLINKSTATE_L1 USB_LPM_ATTRIBUT_BLINKSTATE(1)
 
 /**
  * \brief Standard USB endpoint transfer types
  */
 enum usb_ep_type {
-    USB_EP_TYPE_CONTROL = 0x00,
+    USB_EP_TYPE_CONTROL     = 0x00,
     USB_EP_TYPE_ISOCHRONOUS = 0x01,
-    USB_EP_TYPE_BULK = 0x02,
-    USB_EP_TYPE_INTERRUPT = 0x03,
-    USB_EP_TYPE_MASK = 0x03,
+    USB_EP_TYPE_BULK        = 0x02,
+    USB_EP_TYPE_INTERRUPT   = 0x03,
+    USB_EP_TYPE_MASK        = 0x03,
 };
 
 /**
  * \brief Standard USB language IDs for string descriptors
  */
 enum usb_langid {
-    USB_LANGID_EN_US = 0x0409, //!< English (United States)
+    USB_LANGID_EN_US = 0x0409,  //!< English (United States)
 };
 
 /**
  * \brief Mask selecting the index part of an endpoint address
  */
-#define  USB_EP_ADDR_MASK     0x0f
+#define USB_EP_ADDR_MASK 0x0f
 
 //! \brief USB address identifier
 typedef uint8_t usb_add_t;
@@ -281,12 +275,12 @@ typedef uint8_t usb_add_t;
 /**
  * \brief Endpoint transfer direction is IN
  */
-#define  USB_EP_DIR_IN        0x80
+#define USB_EP_DIR_IN 0x80
 
 /**
  * \brief Endpoint transfer direction is OUT
  */
-#define  USB_EP_DIR_OUT       0x00
+#define USB_EP_DIR_OUT 0x00
 
 //! \brief Endpoint identifier
 typedef uint8_t usb_ep_t;
@@ -297,7 +291,7 @@ typedef uint8_t usb_ep_t;
  * The maximum length of a USB descriptor is limited by the 8-bit
  * bLength field.
  */
-#define  USB_MAX_DESC_LEN     255
+#define USB_MAX_DESC_LEN 255
 
 /*
  * 2-byte alignment requested for all USB structures.
@@ -312,9 +306,9 @@ COMPILER_PACK_SET(1)
 typedef struct {
     uint8_t bmRequestType;
     uint8_t bRequest;
-    le16_t wValue;
-    le16_t wIndex;
-    le16_t wLength;
+    le16_t  wValue;
+    le16_t  wIndex;
+    le16_t  wLength;
 } usb_setup_req_t;
 
 /**
@@ -323,14 +317,14 @@ typedef struct {
 typedef struct {
     uint8_t bLength;
     uint8_t bDescriptorType;
-    le16_t bcdUSB;
+    le16_t  bcdUSB;
     uint8_t bDeviceClass;
     uint8_t bDeviceSubClass;
     uint8_t bDeviceProtocol;
     uint8_t bMaxPacketSize0;
-    le16_t idVendor;
-    le16_t idProduct;
-    le16_t bcdDevice;
+    le16_t  idVendor;
+    le16_t  idProduct;
+    le16_t  bcdDevice;
     uint8_t iManufacturer;
     uint8_t iProduct;
     uint8_t iSerialNumber;
@@ -348,7 +342,7 @@ typedef struct {
 typedef struct {
     uint8_t bLength;
     uint8_t bDescriptorType;
-    le16_t bcdUSB;
+    le16_t  bcdUSB;
     uint8_t bDeviceClass;
     uint8_t bDeviceSubClass;
     uint8_t bDeviceProtocol;
@@ -376,7 +370,6 @@ typedef struct {
     uint8_t bNumDeviceCaps;
 } usb_dev_bos_desc_t;
 
-
 /**
  * \brief USB Device Capabilities - USB 2.0 Extension Descriptor structure
  *
@@ -395,7 +388,7 @@ typedef struct {
  * The BOS descriptor and capabilities descriptors for LPM.
  */
 typedef struct {
-    usb_dev_bos_desc_t bos;
+    usb_dev_bos_desc_t      bos;
     usb_dev_capa_ext_desc_t capa_ext;
 } usb_dev_lpm_desc_t;
 
@@ -403,24 +396,23 @@ typedef struct {
  * \brief Standard USB Interface Association Descriptor structure
  */
 typedef struct {
-    uint8_t bLength;          //!< size of this descriptor in bytes
-    uint8_t bDescriptorType;  //!< INTERFACE descriptor type
-    uint8_t bFirstInterface;  //!< Number of interface
-    uint8_t bInterfaceCount;  //!< value to select alternate setting
-    uint8_t bFunctionClass;   //!< Class code assigned by the USB
-    uint8_t bFunctionSubClass;//!< Sub-class code assigned by the USB
-    uint8_t bFunctionProtocol;//!< Protocol code assigned by the USB
-    uint8_t iFunction;        //!< Index of string descriptor
+    uint8_t bLength;            //!< size of this descriptor in bytes
+    uint8_t bDescriptorType;    //!< INTERFACE descriptor type
+    uint8_t bFirstInterface;    //!< Number of interface
+    uint8_t bInterfaceCount;    //!< value to select alternate setting
+    uint8_t bFunctionClass;     //!< Class code assigned by the USB
+    uint8_t bFunctionSubClass;  //!< Sub-class code assigned by the USB
+    uint8_t bFunctionProtocol;  //!< Protocol code assigned by the USB
+    uint8_t iFunction;          //!< Index of string descriptor
 } usb_association_desc_t;
 
-
 /**
  * \brief Standard USB configuration descriptor structure
  */
 typedef struct {
     uint8_t bLength;
     uint8_t bDescriptorType;
-    le16_t wTotalLength;
+    le16_t  wTotalLength;
     uint8_t bNumInterfaces;
     uint8_t bConfigurationValue;
     uint8_t iConfiguration;
@@ -428,26 +420,25 @@ typedef struct {
     uint8_t bMaxPower;
 } usb_conf_desc_t;
 
+#define USB_CONFIG_ATTR_MUST_SET (1 << 7)       //!< Must always be set
+#define USB_CONFIG_ATTR_BUS_POWERED (0 << 6)    //!< Bus-powered
+#define USB_CONFIG_ATTR_SELF_POWERED (1 << 6)   //!< Self-powered
+#define USB_CONFIG_ATTR_REMOTE_WAKEUP (1 << 5)  //!< remote wakeup supported
 
-#define  USB_CONFIG_ATTR_MUST_SET         (1 << 7) //!< Must always be set
-#define  USB_CONFIG_ATTR_BUS_POWERED      (0 << 6) //!< Bus-powered
-#define  USB_CONFIG_ATTR_SELF_POWERED     (1 << 6) //!< Self-powered
-#define  USB_CONFIG_ATTR_REMOTE_WAKEUP    (1 << 5) //!< remote wakeup supported
-
-#define  USB_CONFIG_MAX_POWER(ma)         (((ma) + 1) / 2) //!< Max power in mA
+#define USB_CONFIG_MAX_POWER(ma) (((ma) + 1) / 2)  //!< Max power in mA
 
 /**
  * \brief Standard USB association descriptor structure
  */
 typedef struct {
-    uint8_t bLength;              //!< Size of this descriptor in bytes
-    uint8_t bDescriptorType;      //!< Interface descriptor type
-    uint8_t bFirstInterface;      //!< Number of interface
-    uint8_t bInterfaceCount;      //!< value to select alternate setting
-    uint8_t bFunctionClass;       //!< Class code assigned by the USB
-    uint8_t bFunctionSubClass;    //!< Sub-class code assigned by the USB
-    uint8_t bFunctionProtocol;    //!< Protocol code assigned by the USB
-    uint8_t iFunction;            //!< Index of string descriptor
+    uint8_t bLength;            //!< Size of this descriptor in bytes
+    uint8_t bDescriptorType;    //!< Interface descriptor type
+    uint8_t bFirstInterface;    //!< Number of interface
+    uint8_t bInterfaceCount;    //!< value to select alternate setting
+    uint8_t bFunctionClass;     //!< Class code assigned by the USB
+    uint8_t bFunctionSubClass;  //!< Sub-class code assigned by the USB
+    uint8_t bFunctionProtocol;  //!< Protocol code assigned by the USB
+    uint8_t iFunction;          //!< Index of string descriptor
 } usb_iad_desc_t;
 
 /**
@@ -473,11 +464,10 @@ typedef struct {
     uint8_t bDescriptorType;
     uint8_t bEndpointAddress;
     uint8_t bmAttributes;
-    le16_t wMaxPacketSize;
+    le16_t  wMaxPacketSize;
     uint8_t bInterval;
 } usb_ep_desc_t;
 
-
 /**
  * \brief A standard USB string descriptor structure
  */
@@ -488,7 +478,7 @@ typedef struct {
 
 typedef struct {
     usb_str_desc_t desc;
-    le16_t string[1];
+    le16_t         string[1];
 } usb_str_lgid_desc_t;
 
 COMPILER_PACK_RESET()
index 479f25d4e30365616bc6cb129e42e6fd710a6e29..aa639a6e5d2ef54328957ac3fee56fa3136566b8 100644 (file)
 
 #ifdef CDC
 
-#define  CDC_CLASS_DEVICE     0x02  //!< USB Communication Device Class
-#define  CDC_CLASS_COMM       0x02  //!< CDC Communication Class Interface
-#define  CDC_CLASS_DATA       0x0A  //!< CDC Data Class Interface
-
-#define  CDC_SUBCLASS_DLCM    0x01  //!< Direct Line Control Model
-#define  CDC_SUBCLASS_ACM     0x02  //!< Abstract Control Model
-#define  CDC_SUBCLASS_TCM     0x03  //!< Telephone Control Model
-#define  CDC_SUBCLASS_MCCM    0x04  //!< Multi-Channel Control Model
-#define  CDC_SUBCLASS_CCM     0x05  //!< CAPI Control Model
-#define  CDC_SUBCLASS_ETH     0x06  //!< Ethernet Networking Control Model
-#define  CDC_SUBCLASS_ATM     0x07  //!< ATM Networking Control Model
-
-#define  CDC_PROTOCOL_V25TER  0x01  //!< Common AT commands
-
-#define  CDC_PROTOCOL_I430    0x30  //!< ISDN BRI
-#define  CDC_PROTOCOL_HDLC    0x31  //!< HDLC
-#define  CDC_PROTOCOL_TRANS   0x32  //!< Transparent
-#define  CDC_PROTOCOL_Q921M   0x50  //!< Q.921 management protocol
-#define  CDC_PROTOCOL_Q921    0x51  //!< Q.931 [sic] Data link protocol
-#define  CDC_PROTOCOL_Q921TM  0x52  //!< Q.921 TEI-multiplexor
-#define  CDC_PROTOCOL_V42BIS  0x90  //!< Data compression procedures
-#define  CDC_PROTOCOL_Q931    0x91  //!< Euro-ISDN protocol control
-#define  CDC_PROTOCOL_V120    0x92  //!< V.24 rate adaption to ISDN
-#define  CDC_PROTOCOL_CAPI20  0x93  //!< CAPI Commands
-#define  CDC_PROTOCOL_HOST    0xFD  //!< Host based driver
-
-#define  CDC_PROTOCOL_PUFD    0xFE
-
-#define  CDC_CS_INTERFACE     0x24  //!< Interface Functional Descriptor
-#define  CDC_CS_ENDPOINT      0x25  //!< Endpoint Functional Descriptor
-
-#define  CDC_SCS_HEADER       0x00  //!< Header Functional Descriptor
-#define  CDC_SCS_CALL_MGMT    0x01  //!< Call Management
-#define  CDC_SCS_ACM          0x02  //!< Abstract Control Management
-#define  CDC_SCS_UNION        0x06  //!< Union Functional Descriptor
-
-#define  USB_REQ_CDC_SEND_ENCAPSULATED_COMMAND                   0x00
-#define  USB_REQ_CDC_GET_ENCAPSULATED_RESPONSE                   0x01
-#define  USB_REQ_CDC_SET_COMM_FEATURE                            0x02
-#define  USB_REQ_CDC_GET_COMM_FEATURE                            0x03
-#define  USB_REQ_CDC_CLEAR_COMM_FEATURE                          0x04
-#define  USB_REQ_CDC_SET_AUX_LINE_STATE                          0x10
-#define  USB_REQ_CDC_SET_HOOK_STATE                              0x11
-#define  USB_REQ_CDC_PULSE_SETUP                                 0x12
-#define  USB_REQ_CDC_SEND_PULSE                                  0x13
-#define  USB_REQ_CDC_SET_PULSE_TIME                              0x14
-#define  USB_REQ_CDC_RING_AUX_JACK                               0x15
-#define  USB_REQ_CDC_SET_LINE_CODING                             0x20
-#define  USB_REQ_CDC_GET_LINE_CODING                             0x21
-#define  USB_REQ_CDC_SET_CONTROL_LINE_STATE                      0x22
-#define  USB_REQ_CDC_SEND_BREAK                                  0x23
-#define  USB_REQ_CDC_SET_RINGER_PARMS                            0x30
-#define  USB_REQ_CDC_GET_RINGER_PARMS                            0x31
-#define  USB_REQ_CDC_SET_OPERATION_PARMS                         0x32
-#define  USB_REQ_CDC_GET_OPERATION_PARMS                         0x33
-#define  USB_REQ_CDC_SET_LINE_PARMS                              0x34
-#define  USB_REQ_CDC_GET_LINE_PARMS                              0x35
-#define  USB_REQ_CDC_DIAL_DIGITS                                 0x36
-#define  USB_REQ_CDC_SET_UNIT_PARAMETER                          0x37
-#define  USB_REQ_CDC_GET_UNIT_PARAMETER                          0x38
-#define  USB_REQ_CDC_CLEAR_UNIT_PARAMETER                        0x39
-#define  USB_REQ_CDC_GET_PROFILE                                 0x3A
-#define  USB_REQ_CDC_SET_ETHERNET_MULTICAST_FILTERS              0x40
-#define  USB_REQ_CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERNFILTER 0x41
-#define  USB_REQ_CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERNFILTER 0x42
-#define  USB_REQ_CDC_SET_ETHERNET_PACKET_FILTER                  0x43
-#define  USB_REQ_CDC_GET_ETHERNET_STATISTIC                      0x44
-#define  USB_REQ_CDC_SET_ATM_DATA_FORMAT                         0x50
-#define  USB_REQ_CDC_GET_ATM_DEVICE_STATISTICS                   0x51
-#define  USB_REQ_CDC_SET_ATM_DEFAULT_VC                          0x52
-#define  USB_REQ_CDC_GET_ATM_VC_STATISTICS                       0x53
+#    define CDC_CLASS_DEVICE 0x02  //!< USB Communication Device Class
+#    define CDC_CLASS_COMM 0x02    //!< CDC Communication Class Interface
+#    define CDC_CLASS_DATA 0x0A    //!< CDC Data Class Interface
+
+#    define CDC_SUBCLASS_DLCM 0x01  //!< Direct Line Control Model
+#    define CDC_SUBCLASS_ACM 0x02   //!< Abstract Control Model
+#    define CDC_SUBCLASS_TCM 0x03   //!< Telephone Control Model
+#    define CDC_SUBCLASS_MCCM 0x04  //!< Multi-Channel Control Model
+#    define CDC_SUBCLASS_CCM 0x05   //!< CAPI Control Model
+#    define CDC_SUBCLASS_ETH 0x06   //!< Ethernet Networking Control Model
+#    define CDC_SUBCLASS_ATM 0x07   //!< ATM Networking Control Model
+
+#    define CDC_PROTOCOL_V25TER 0x01  //!< Common AT commands
+
+#    define CDC_PROTOCOL_I430 0x30    //!< ISDN BRI
+#    define CDC_PROTOCOL_HDLC 0x31    //!< HDLC
+#    define CDC_PROTOCOL_TRANS 0x32   //!< Transparent
+#    define CDC_PROTOCOL_Q921M 0x50   //!< Q.921 management protocol
+#    define CDC_PROTOCOL_Q921 0x51    //!< Q.931 [sic] Data link protocol
+#    define CDC_PROTOCOL_Q921TM 0x52  //!< Q.921 TEI-multiplexor
+#    define CDC_PROTOCOL_V42BIS 0x90  //!< Data compression procedures
+#    define CDC_PROTOCOL_Q931 0x91    //!< Euro-ISDN protocol control
+#    define CDC_PROTOCOL_V120 0x92    //!< V.24 rate adaption to ISDN
+#    define CDC_PROTOCOL_CAPI20 0x93  //!< CAPI Commands
+#    define CDC_PROTOCOL_HOST 0xFD    //!< Host based driver
+
+#    define CDC_PROTOCOL_PUFD 0xFE
+
+#    define CDC_CS_INTERFACE 0x24  //!< Interface Functional Descriptor
+#    define CDC_CS_ENDPOINT 0x25   //!< Endpoint Functional Descriptor
+
+#    define CDC_SCS_HEADER 0x00     //!< Header Functional Descriptor
+#    define CDC_SCS_CALL_MGMT 0x01  //!< Call Management
+#    define CDC_SCS_ACM 0x02        //!< Abstract Control Management
+#    define CDC_SCS_UNION 0x06      //!< Union Functional Descriptor
+
+#    define USB_REQ_CDC_SEND_ENCAPSULATED_COMMAND 0x00
+#    define USB_REQ_CDC_GET_ENCAPSULATED_RESPONSE 0x01
+#    define USB_REQ_CDC_SET_COMM_FEATURE 0x02
+#    define USB_REQ_CDC_GET_COMM_FEATURE 0x03
+#    define USB_REQ_CDC_CLEAR_COMM_FEATURE 0x04
+#    define USB_REQ_CDC_SET_AUX_LINE_STATE 0x10
+#    define USB_REQ_CDC_SET_HOOK_STATE 0x11
+#    define USB_REQ_CDC_PULSE_SETUP 0x12
+#    define USB_REQ_CDC_SEND_PULSE 0x13
+#    define USB_REQ_CDC_SET_PULSE_TIME 0x14
+#    define USB_REQ_CDC_RING_AUX_JACK 0x15
+#    define USB_REQ_CDC_SET_LINE_CODING 0x20
+#    define USB_REQ_CDC_GET_LINE_CODING 0x21
+#    define USB_REQ_CDC_SET_CONTROL_LINE_STATE 0x22
+#    define USB_REQ_CDC_SEND_BREAK 0x23
+#    define USB_REQ_CDC_SET_RINGER_PARMS 0x30
+#    define USB_REQ_CDC_GET_RINGER_PARMS 0x31
+#    define USB_REQ_CDC_SET_OPERATION_PARMS 0x32
+#    define USB_REQ_CDC_GET_OPERATION_PARMS 0x33
+#    define USB_REQ_CDC_SET_LINE_PARMS 0x34
+#    define USB_REQ_CDC_GET_LINE_PARMS 0x35
+#    define USB_REQ_CDC_DIAL_DIGITS 0x36
+#    define USB_REQ_CDC_SET_UNIT_PARAMETER 0x37
+#    define USB_REQ_CDC_GET_UNIT_PARAMETER 0x38
+#    define USB_REQ_CDC_CLEAR_UNIT_PARAMETER 0x39
+#    define USB_REQ_CDC_GET_PROFILE 0x3A
+#    define USB_REQ_CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
+#    define USB_REQ_CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERNFILTER 0x41
+#    define USB_REQ_CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERNFILTER 0x42
+#    define USB_REQ_CDC_SET_ETHERNET_PACKET_FILTER 0x43
+#    define USB_REQ_CDC_GET_ETHERNET_STATISTIC 0x44
+#    define USB_REQ_CDC_SET_ATM_DATA_FORMAT 0x50
+#    define USB_REQ_CDC_GET_ATM_DEVICE_STATISTICS 0x51
+#    define USB_REQ_CDC_SET_ATM_DEFAULT_VC 0x52
+#    define USB_REQ_CDC_GET_ATM_VC_STATISTICS 0x53
 // Added bNotification codes according cdc spec 1.1 chapter 6.3
-#define  USB_REQ_CDC_NOTIFY_RING_DETECT                          0x09
-#define  USB_REQ_CDC_NOTIFY_SERIAL_STATE                         0x20
-#define  USB_REQ_CDC_NOTIFY_CALL_STATE_CHANGE                    0x28
-#define  USB_REQ_CDC_NOTIFY_LINE_STATE_CHANGE                    0x29
-
-
-#define  CDC_CALL_MGMT_SUPPORTED             (1 << 0)
-#define  CDC_CALL_MGMT_OVER_DCI              (1 << 1)
-#define  CDC_ACM_SUPPORT_FEATURE_REQUESTS    (1 << 0)
-#define  CDC_ACM_SUPPORT_LINE_REQUESTS       (1 << 1)
-#define  CDC_ACM_SUPPORT_SENDBREAK_REQUESTS  (1 << 2)
-#define  CDC_ACM_SUPPORT_NOTIFY_REQUESTS     (1 << 3)
-
-#pragma pack(push,1)
+#    define USB_REQ_CDC_NOTIFY_RING_DETECT 0x09
+#    define USB_REQ_CDC_NOTIFY_SERIAL_STATE 0x20
+#    define USB_REQ_CDC_NOTIFY_CALL_STATE_CHANGE 0x28
+#    define USB_REQ_CDC_NOTIFY_LINE_STATE_CHANGE 0x29
+
+#    define CDC_CALL_MGMT_SUPPORTED (1 << 0)
+#    define CDC_CALL_MGMT_OVER_DCI (1 << 1)
+#    define CDC_ACM_SUPPORT_FEATURE_REQUESTS (1 << 0)
+#    define CDC_ACM_SUPPORT_LINE_REQUESTS (1 << 1)
+#    define CDC_ACM_SUPPORT_SENDBREAK_REQUESTS (1 << 2)
+#    define CDC_ACM_SUPPORT_NOTIFY_REQUESTS (1 << 3)
+
+#    pragma pack(push, 1)
 typedef struct {
-    le32_t dwDTERate;
+    le32_t  dwDTERate;
     uint8_t bCharFormat;
     uint8_t bParityType;
     uint8_t bDataBits;
 } usb_cdc_line_coding_t;
-#pragma pack(pop)
+#    pragma pack(pop)
 
 enum cdc_char_format {
-    CDC_STOP_BITS_1 = 0,    //!< 1 stop bit
+    CDC_STOP_BITS_1   = 0,  //!< 1 stop bit
     CDC_STOP_BITS_1_5 = 1,  //!< 1.5 stop bits
-    CDC_STOP_BITS_2 = 2,    //!< 2 stop bits
+    CDC_STOP_BITS_2   = 2,  //!< 2 stop bits
 };
 
 enum cdc_parity {
-    CDC_PAR_NONE = 0,   //!< No parity
-    CDC_PAR_ODD = 1,    //!< Odd parity
-    CDC_PAR_EVEN = 2,   //!< Even parity
-    CDC_PAR_MARK = 3,   //!< Parity forced to 0 (space)
+    CDC_PAR_NONE  = 0,  //!< No parity
+    CDC_PAR_ODD   = 1,  //!< Odd parity
+    CDC_PAR_EVEN  = 2,  //!< Even parity
+    CDC_PAR_MARK  = 3,  //!< Parity forced to 0 (space)
     CDC_PAR_SPACE = 4,  //!< Parity forced to 1 (mark)
 };
 
-
 typedef struct {
     uint16_t value;
 } usb_cdc_control_signal_t;
 
-#define  CDC_CTRL_SIGNAL_ACTIVATE_CARRIER    (1 << 1)
-#define  CDC_CTRL_SIGNAL_DTE_PRESENT         (1 << 0)
-
+#    define CDC_CTRL_SIGNAL_ACTIVATE_CARRIER (1 << 1)
+#    define CDC_CTRL_SIGNAL_DTE_PRESENT (1 << 0)
 
 typedef struct {
     uint8_t bmRequestType;
     uint8_t bNotification;
-    le16_t wValue;
-    le16_t wIndex;
-    le16_t wLength;
+    le16_t  wValue;
+    le16_t  wIndex;
+    le16_t  wLength;
 } usb_cdc_notify_msg_t;
 
 typedef struct {
     usb_cdc_notify_msg_t header;
-    le16_t value;
+    le16_t               value;
 } usb_cdc_notify_serial_state_t;
 
-#define  CDC_SERIAL_STATE_DCD       CPU_TO_LE16((1<<0))
-#define  CDC_SERIAL_STATE_DSR       CPU_TO_LE16((1<<1))
-#define  CDC_SERIAL_STATE_BREAK     CPU_TO_LE16((1<<2))
-#define  CDC_SERIAL_STATE_RING      CPU_TO_LE16((1<<3))
-#define  CDC_SERIAL_STATE_FRAMING   CPU_TO_LE16((1<<4))
-#define  CDC_SERIAL_STATE_PARITY    CPU_TO_LE16((1<<5))
-#define  CDC_SERIAL_STATE_OVERRUN   CPU_TO_LE16((1<<6))
+#    define CDC_SERIAL_STATE_DCD CPU_TO_LE16((1 << 0))
+#    define CDC_SERIAL_STATE_DSR CPU_TO_LE16((1 << 1))
+#    define CDC_SERIAL_STATE_BREAK CPU_TO_LE16((1 << 2))
+#    define CDC_SERIAL_STATE_RING CPU_TO_LE16((1 << 3))
+#    define CDC_SERIAL_STATE_FRAMING CPU_TO_LE16((1 << 4))
+#    define CDC_SERIAL_STATE_PARITY CPU_TO_LE16((1 << 5))
+#    define CDC_SERIAL_STATE_OVERRUN CPU_TO_LE16((1 << 6))
 
 #endif
 
-#endif // _USB_PROTOCOL_CDC_H_
+#endif  // _USB_PROTOCOL_CDC_H_
index c482e9c069451ecbe4bc28976253364a51c69de3..2f8a39bdd8aab8d65d8cd955500ed00418780cab 100644 (file)
 
 //! \name Possible Class value
 //@{
-#define  HID_CLASS                            0x03
+#define HID_CLASS 0x03
 //@}
 
 //! \name Possible SubClass value
 //@{
 //! Interface subclass NO support BOOT protocol
-#define  HID_SUB_CLASS_NOBOOT                 0x00
+#define HID_SUB_CLASS_NOBOOT 0x00
 //! Interface subclass support BOOT protocol
-#define  HID_SUB_CLASS_BOOT                   0x01
+#define HID_SUB_CLASS_BOOT 0x01
 //@}
 
 //! \name Possible protocol value
 //@{
 //! Protocol generic standard
-#define  HID_PROTOCOL_GENERIC                 0x00
+#define HID_PROTOCOL_GENERIC 0x00
 //! Protocol keyboard standard
-#define  HID_PROTOCOL_KEYBOARD                0x01
+#define HID_PROTOCOL_KEYBOARD 0x01
 //! Protocol mouse standard
-#define  HID_PROTOCOL_MOUSE                   0x02
+#define HID_PROTOCOL_MOUSE 0x02
 //@}
 
-
 //! \brief Hid USB requests (bRequest)
 enum usb_reqid_hid {
-    USB_REQ_HID_GET_REPORT = 0x01,
-    USB_REQ_HID_GET_IDLE = 0x02,
+    USB_REQ_HID_GET_REPORT   = 0x01,
+    USB_REQ_HID_GET_IDLE     = 0x02,
     USB_REQ_HID_GET_PROTOCOL = 0x03,
-    USB_REQ_HID_SET_REPORT = 0x09,
-    USB_REQ_HID_SET_IDLE = 0x0A,
+    USB_REQ_HID_SET_REPORT   = 0x09,
+    USB_REQ_HID_SET_IDLE     = 0x0A,
     USB_REQ_HID_SET_PROTOCOL = 0x0B,
 };
 
 //! \brief HID USB descriptor types
 enum usb_descriptor_type_hid {
-    USB_DT_HID = 0x21,
-    USB_DT_HID_REPORT = 0x22,
+    USB_DT_HID          = 0x21,
+    USB_DT_HID_REPORT   = 0x22,
     USB_DT_HID_PHYSICAL = 0x23,
 };
 
 //! \brief HID Type for report descriptor
 enum usb_hid_item_report_type {
-    USB_HID_ITEM_REPORT_TYPE_MAIN = 0,
+    USB_HID_ITEM_REPORT_TYPE_MAIN   = 0,
     USB_HID_ITEM_REPORT_TYPE_GLOBAL = 1,
-    USB_HID_ITEM_REPORT_TYPE_LOCAL = 2,
-    USB_HID_ITEM_REPORT_TYPE_LONG = 3,
+    USB_HID_ITEM_REPORT_TYPE_LOCAL  = 2,
+    USB_HID_ITEM_REPORT_TYPE_LONG   = 3,
 };
 
 //! \brief HID report type
 enum usb_hid_report_type {
-    USB_HID_REPORT_TYPE_INPUT = 1,
-    USB_HID_REPORT_TYPE_OUTPUT = 2,
+    USB_HID_REPORT_TYPE_INPUT   = 1,
+    USB_HID_REPORT_TYPE_OUTPUT  = 2,
     USB_HID_REPORT_TYPE_FEATURE = 3,
 };
 
-
 //! \brief HID protocol
 enum usb_hid_protocol {
-    USB_HID_PROCOTOL_BOOT = 0,
+    USB_HID_PROCOTOL_BOOT   = 0,
     USB_HID_PROCOTOL_REPORT = 1,
 };
 
@@ -123,197 +121,196 @@ COMPILER_PACK_SET(1)
 
 //! \brief HID Descriptor
 typedef struct {
-    uint8_t bLength;          //!< Size of this descriptor in bytes
-    uint8_t bDescriptorType;  //!< HID descriptor type
-    le16_t bcdHID;            //!< Binary Coded Decimal Spec. release
-    uint8_t bCountryCode;     //!< Hardware target country
-    uint8_t bNumDescriptors;  //!< Number of HID class descriptors to follow
-    uint8_t bRDescriptorType; //!< Report descriptor type
-    le16_t wDescriptorLength; //!< Total length of Report descriptor
+    uint8_t bLength;            //!< Size of this descriptor in bytes
+    uint8_t bDescriptorType;    //!< HID descriptor type
+    le16_t  bcdHID;             //!< Binary Coded Decimal Spec. release
+    uint8_t bCountryCode;       //!< Hardware target country
+    uint8_t bNumDescriptors;    //!< Number of HID class descriptors to follow
+    uint8_t bRDescriptorType;   //!< Report descriptor type
+    le16_t  wDescriptorLength;  //!< Total length of Report descriptor
 } usb_hid_descriptor_t;
 
 COMPILER_PACK_RESET()
 
-   //! \name HID Report type
-   //! Used by SETUP_HID_GET_REPORT & SETUP_HID_SET_REPORT
-   //! @{
-#define  REPORT_TYPE_INPUT                    0x01
-#define  REPORT_TYPE_OUTPUT                   0x02
-#define  REPORT_TYPE_FEATURE                  0x03
-   //! @}
+//! \name HID Report type
+//! Used by SETUP_HID_GET_REPORT & SETUP_HID_SET_REPORT
+//! @{
+#define REPORT_TYPE_INPUT 0x01
+#define REPORT_TYPE_OUTPUT 0x02
+#define REPORT_TYPE_FEATURE 0x03
+//! @}
 
-   //! \name Constants of field DESCRIPTOR_HID
-   //! @{
+//! \name Constants of field DESCRIPTOR_HID
+//! @{
 //! Numeric expression identifying the HID Class
 //! Specification release (here V1.11)
-#define  USB_HID_BDC_V1_11                    0x0111
+#define USB_HID_BDC_V1_11 0x0111
 //! Numeric expression specifying the number of class descriptors
 //! Note: Always at least one i.e. Report descriptor.
-#define  USB_HID_NUM_DESC                     0x01
+#define USB_HID_NUM_DESC 0x01
 
-      //! \name Country code
-      //! @{
-#define  USB_HID_NO_COUNTRY_CODE            0   // Not Supported
-#define  USB_HID_COUNTRY_ARABIC             1   // Arabic
-#define  USB_HID_COUNTRY_BELGIAN            2   // Belgian
-#define  USB_HID_COUNTRY_CANADIAN_BILINGUAL 3   // Canadian-Bilingual
-#define  USB_HID_COUNTRY_CANADIAN_FRENCH    4   // Canadian-French
-#define  USB_HID_COUNTRY_CZECH_REPUBLIC     5   // Czech Republic
-#define  USB_HID_COUNTRY_DANISH             6   // Danish
-#define  USB_HID_COUNTRY_FINNISH            7   // Finnish
-#define  USB_HID_COUNTRY_FRENCH             8   // French
-#define  USB_HID_COUNTRY_GERMAN             9   // German
-#define  USB_HID_COUNTRY_GREEK              10  // Greek
-#define  USB_HID_COUNTRY_HEBREW             11  // Hebrew
-#define  USB_HID_COUNTRY_HUNGARY            12  // Hungary
-#define  USB_HID_COUNTRY_INTERNATIONAL_ISO  13  // International (ISO)
-#define  USB_HID_COUNTRY_ITALIAN            14  // Italian
-#define  USB_HID_COUNTRY_JAPAN_KATAKANA     15  // Japan (Katakana)
-#define  USB_HID_COUNTRY_KOREAN             16  // Korean
-#define  USB_HID_COUNTRY_LATIN_AMERICAN     17  // Latin American
-#define  USB_HID_COUNTRY_NETHERLANDS_DUTCH  18  // Netherlands/Dutch
-#define  USB_HID_COUNTRY_NORWEGIAN          19  // Norwegian
-#define  USB_HID_COUNTRY_PERSIAN_FARSI      20  // Persian (Farsi)
-#define  USB_HID_COUNTRY_POLAND             21  // Poland
-#define  USB_HID_COUNTRY_PORTUGUESE         22  // Portuguese
-#define  USB_HID_COUNTRY_RUSSIA             23  // Russia
-#define  USB_HID_COUNTRY_SLOVAKIA           24  // Slovakia
-#define  USB_HID_COUNTRY_SPANISH            25  // Spanish
-#define  USB_HID_COUNTRY_SWEDISH            26  // Swedish
-#define  USB_HID_COUNTRY_SWISS_FRENCH       27  // Swiss/French
-#define  USB_HID_COUNTRY_SWISS_GERMAN       28  // Swiss/German
-#define  USB_HID_COUNTRY_SWITZERLAND        29  // Switzerland
-#define  USB_HID_COUNTRY_TAIWAN             30  // Taiwan
-#define  USB_HID_COUNTRY_TURKISH_Q          31  // Turkish-Q
-#define  USB_HID_COUNTRY_UK                 32  // UK
-#define  USB_HID_COUNTRY_US                 33  // US
-#define  USB_HID_COUNTRY_YUGOSLAVIA         34  // Yugoslavia
-#define  USB_HID_COUNTRY_TURKISH_F          35  // Turkish-F
-      //! @}
-   //! @}
+//! \name Country code
+//! @{
+#define USB_HID_NO_COUNTRY_CODE 0             // Not Supported
+#define USB_HID_COUNTRY_ARABIC 1              // Arabic
+#define USB_HID_COUNTRY_BELGIAN 2             // Belgian
+#define USB_HID_COUNTRY_CANADIAN_BILINGUAL 3  // Canadian-Bilingual
+#define USB_HID_COUNTRY_CANADIAN_FRENCH 4     // Canadian-French
+#define USB_HID_COUNTRY_CZECH_REPUBLIC 5      // Czech Republic
+#define USB_HID_COUNTRY_DANISH 6              // Danish
+#define USB_HID_COUNTRY_FINNISH 7             // Finnish
+#define USB_HID_COUNTRY_FRENCH 8              // French
+#define USB_HID_COUNTRY_GERMAN 9              // German
+#define USB_HID_COUNTRY_GREEK 10              // Greek
+#define USB_HID_COUNTRY_HEBREW 11             // Hebrew
+#define USB_HID_COUNTRY_HUNGARY 12            // Hungary
+#define USB_HID_COUNTRY_INTERNATIONAL_ISO 13  // International (ISO)
+#define USB_HID_COUNTRY_ITALIAN 14            // Italian
+#define USB_HID_COUNTRY_JAPAN_KATAKANA 15     // Japan (Katakana)
+#define USB_HID_COUNTRY_KOREAN 16             // Korean
+#define USB_HID_COUNTRY_LATIN_AMERICAN 17     // Latin American
+#define USB_HID_COUNTRY_NETHERLANDS_DUTCH 18  // Netherlands/Dutch
+#define USB_HID_COUNTRY_NORWEGIAN 19          // Norwegian
+#define USB_HID_COUNTRY_PERSIAN_FARSI 20      // Persian (Farsi)
+#define USB_HID_COUNTRY_POLAND 21             // Poland
+#define USB_HID_COUNTRY_PORTUGUESE 22         // Portuguese
+#define USB_HID_COUNTRY_RUSSIA 23             // Russia
+#define USB_HID_COUNTRY_SLOVAKIA 24           // Slovakia
+#define USB_HID_COUNTRY_SPANISH 25            // Spanish
+#define USB_HID_COUNTRY_SWEDISH 26            // Swedish
+#define USB_HID_COUNTRY_SWISS_FRENCH 27       // Swiss/French
+#define USB_HID_COUNTRY_SWISS_GERMAN 28       // Swiss/German
+#define USB_HID_COUNTRY_SWITZERLAND 29        // Switzerland
+#define USB_HID_COUNTRY_TAIWAN 30             // Taiwan
+#define USB_HID_COUNTRY_TURKISH_Q 31          // Turkish-Q
+#define USB_HID_COUNTRY_UK 32                 // UK
+#define USB_HID_COUNTRY_US 33                 // US
+#define USB_HID_COUNTRY_YUGOSLAVIA 34         // Yugoslavia
+#define USB_HID_COUNTRY_TURKISH_F 35          // Turkish-F
+                                              //! @}
+                                              //! @}
 //! @}
 
-
 //! \name HID KEYS values
 //! @{
-#define  HID_A                0x04
-#define  HID_B                0x05
-#define  HID_C                0x06
-#define  HID_D                0x07
-#define  HID_E                0x08
-#define  HID_F                0x09
-#define  HID_G                0x0A
-#define  HID_H                0x0B
-#define  HID_I                0x0C
-#define  HID_J                0x0D
-#define  HID_K                0x0E
-#define  HID_L                0x0F
-#define  HID_M                0x10
-#define  HID_N                0x11
-#define  HID_O                0x12
-#define  HID_P                0x13
-#define  HID_Q                0x14
-#define  HID_R                0x15
-#define  HID_S                0x16
-#define  HID_T                0x17
-#define  HID_U                0x18
-#define  HID_V                0x19
-#define  HID_W                0x1A
-#define  HID_X                0x1B
-#define  HID_Y                0x1C
-#define  HID_Z                0x1D
-#define  HID_1                30
-#define  HID_2                31
-#define  HID_3                32
-#define  HID_4                33
-#define  HID_5                34
-#define  HID_6                35
-#define  HID_7                36
-#define  HID_8                37
-#define  HID_9                38
-#define  HID_0                39
-#define  HID_ENTER            40
-#define  HID_ESCAPE           41
-#define  HID_BACKSPACE        42
-#define  HID_TAB              43
-#define  HID_SPACEBAR         44
-#define  HID_UNDERSCORE       45
-#define  HID_PLUS             46
-#define  HID_OPEN_BRACKET     47 // {
-#define  HID_CLOSE_BRACKET    48 // }
-#define  HID_BACKSLASH        49
-#define  HID_ASH              50 // # ~
-#define  HID_COLON            51 // ; :
-#define  HID_QUOTE            52 // ' "
-#define  HID_TILDE            53
-#define  HID_COMMA            54
-#define  HID_DOT              55
-#define  HID_SLASH            56
-#define  HID_CAPS_LOCK        57
-#define  HID_F1               58
-#define  HID_F2               59
-#define  HID_F3               60
-#define  HID_F4               61
-#define  HID_F5               62
-#define  HID_F6               63
-#define  HID_F7               64
-#define  HID_F8               65
-#define  HID_F9               66
-#define  HID_F10              67
-#define  HID_F11              68
-#define  HID_F12              69
-#define  HID_PRINTSCREEN      70
-#define  HID_SCROLL_LOCK      71
-#define  HID_PAUSE            72
-#define  HID_INSERT           73
-#define  HID_HOME             74
-#define  HID_PAGEUP           75
-#define  HID_DELETE           76
-#define  HID_END              77
-#define  HID_PAGEDOWN         78
-#define  HID_RIGHT            79
-#define  HID_LEFT             80
-#define  HID_DOWN             81
-#define  HID_UP               82
-#define  HID_KEYPAD_NUM_LOCK  83
-#define  HID_KEYPAD_DIVIDE    84
-#define  HID_KEYPAD_AT        85
-#define  HID_KEYPAD_MULTIPLY  85
-#define  HID_KEYPAD_MINUS     86
-#define  HID_KEYPAD_PLUS      87
-#define  HID_KEYPAD_ENTER     88
-#define  HID_KEYPAD_1         89
-#define  HID_KEYPAD_2         90
-#define  HID_KEYPAD_3         91
-#define  HID_KEYPAD_4         92
-#define  HID_KEYPAD_5         93
-#define  HID_KEYPAD_6         94
-#define  HID_KEYPAD_7         95
-#define  HID_KEYPAD_8         96
-#define  HID_KEYPAD_9         97
-#define  HID_KEYPAD_0         98
+#define HID_A 0x04
+#define HID_B 0x05
+#define HID_C 0x06
+#define HID_D 0x07
+#define HID_E 0x08
+#define HID_F 0x09
+#define HID_G 0x0A
+#define HID_H 0x0B
+#define HID_I 0x0C
+#define HID_J 0x0D
+#define HID_K 0x0E
+#define HID_L 0x0F
+#define HID_M 0x10
+#define HID_N 0x11
+#define HID_O 0x12
+#define HID_P 0x13
+#define HID_Q 0x14
+#define HID_R 0x15
+#define HID_S 0x16
+#define HID_T 0x17
+#define HID_U 0x18
+#define HID_V 0x19
+#define HID_W 0x1A
+#define HID_X 0x1B
+#define HID_Y 0x1C
+#define HID_Z 0x1D
+#define HID_1 30
+#define HID_2 31
+#define HID_3 32
+#define HID_4 33
+#define HID_5 34
+#define HID_6 35
+#define HID_7 36
+#define HID_8 37
+#define HID_9 38
+#define HID_0 39
+#define HID_ENTER 40
+#define HID_ESCAPE 41
+#define HID_BACKSPACE 42
+#define HID_TAB 43
+#define HID_SPACEBAR 44
+#define HID_UNDERSCORE 45
+#define HID_PLUS 46
+#define HID_OPEN_BRACKET 47   // {
+#define HID_CLOSE_BRACKET 48  // }
+#define HID_BACKSLASH 49
+#define HID_ASH 50    // # ~
+#define HID_COLON 51  // ; :
+#define HID_QUOTE 52  // ' "
+#define HID_TILDE 53
+#define HID_COMMA 54
+#define HID_DOT 55
+#define HID_SLASH 56
+#define HID_CAPS_LOCK 57
+#define HID_F1 58
+#define HID_F2 59
+#define HID_F3 60
+#define HID_F4 61
+#define HID_F5 62
+#define HID_F6 63
+#define HID_F7 64
+#define HID_F8 65
+#define HID_F9 66
+#define HID_F10 67
+#define HID_F11 68
+#define HID_F12 69
+#define HID_PRINTSCREEN 70
+#define HID_SCROLL_LOCK 71
+#define HID_PAUSE 72
+#define HID_INSERT 73
+#define HID_HOME 74
+#define HID_PAGEUP 75
+#define HID_DELETE 76
+#define HID_END 77
+#define HID_PAGEDOWN 78
+#define HID_RIGHT 79
+#define HID_LEFT 80
+#define HID_DOWN 81
+#define HID_UP 82
+#define HID_KEYPAD_NUM_LOCK 83
+#define HID_KEYPAD_DIVIDE 84
+#define HID_KEYPAD_AT 85
+#define HID_KEYPAD_MULTIPLY 85
+#define HID_KEYPAD_MINUS 86
+#define HID_KEYPAD_PLUS 87
+#define HID_KEYPAD_ENTER 88
+#define HID_KEYPAD_1 89
+#define HID_KEYPAD_2 90
+#define HID_KEYPAD_3 91
+#define HID_KEYPAD_4 92
+#define HID_KEYPAD_5 93
+#define HID_KEYPAD_6 94
+#define HID_KEYPAD_7 95
+#define HID_KEYPAD_8 96
+#define HID_KEYPAD_9 97
+#define HID_KEYPAD_0 98
 
-   //! \name HID modifier values
-   //! @{
-#define  HID_MODIFIER_NONE          0x00
-#define  HID_MODIFIER_LEFT_CTRL     0x01
-#define  HID_MODIFIER_LEFT_SHIFT    0x02
-#define  HID_MODIFIER_LEFT_ALT      0x04
-#define  HID_MODIFIER_LEFT_UI       0x08
-#define  HID_MODIFIER_RIGHT_CTRL    0x10
-#define  HID_MODIFIER_RIGHT_SHIFT   0x20
-#define  HID_MODIFIER_RIGHT_ALT     0x40
-#define  HID_MODIFIER_RIGHT_UI      0x80
-   //! @}
+//! \name HID modifier values
+//! @{
+#define HID_MODIFIER_NONE 0x00
+#define HID_MODIFIER_LEFT_CTRL 0x01
+#define HID_MODIFIER_LEFT_SHIFT 0x02
+#define HID_MODIFIER_LEFT_ALT 0x04
+#define HID_MODIFIER_LEFT_UI 0x08
+#define HID_MODIFIER_RIGHT_CTRL 0x10
+#define HID_MODIFIER_RIGHT_SHIFT 0x20
+#define HID_MODIFIER_RIGHT_ALT 0x40
+#define HID_MODIFIER_RIGHT_UI 0x80
+//! @}
 //! @}
 
 //! \name HID KEYS values
 //! @{
-#define  HID_LED_NUM_LOCK           (1<<0)
-#define  HID_LED_CAPS_LOCK          (1<<1)
-#define  HID_LED_SCROLL_LOCK        (1<<2)
-#define  HID_LED_COMPOSE            (1<<3)
-#define  HID_LED_KANA               (1<<4)
+#define HID_LED_NUM_LOCK (1 << 0)
+#define HID_LED_CAPS_LOCK (1 << 1)
+#define HID_LED_SCROLL_LOCK (1 << 2)
+#define HID_LED_COMPOSE (1 << 3)
+#define HID_LED_KANA (1 << 4)
 //! @}
 
-#endif // _USB_PROTOCOL_HID_H_
+#endif  // _USB_PROTOCOL_HID_H_
index 58b349362ed5bac236e92d5cc5810063c469c5ff..a682c00b5807c245ebc3a594c7b758f5f62138be 100644 (file)
@@ -2,58 +2,42 @@
 #include "string.h"
 #include "usb_util.h"
 
-char digit(int d, int radix)
-{
-    if (d < 10)
-    {
+char digit(int d, int radix) {
+    if (d < 10) {
         return d + '0';
-    }
-    else
-    {
+    } else {
         return d - 10 + 'A';
     }
 }
 
-int UTIL_ltoa_radix(int64_t value, char *dest, int radix)
-{
-    int64_t original = value;       //save original value
-    char buf[25] = "";
-    int c = sizeof(buf)-1;
-    int last = c;
-    int d;
-    int size;
+int UTIL_ltoa_radix(int64_t value, char *dest, int radix) {
+    int64_t original = value;  // save original value
+    char    buf[25]  = "";
+    int     c        = sizeof(buf) - 1;
+    int     last     = c;
+    int     d;
+    int     size;
 
-    if (value < 0)                  //if it's negative, take the absolute value
+    if (value < 0)  // if it's negative, take the absolute value
         value = -value;
 
-    do                              //write least significant digit of value that's left
+    do  // write least significant digit of value that's left
     {
-        d = (value % radix);
+        d        = (value % radix);
         buf[--c] = digit(d, radix);
         value /= radix;
     } while (value);
 
-    if (original < 0)
-        buf[--c] = '-';
+    if (original < 0) buf[--c] = '-';
 
-    size = last - c + 1;            //includes null at end
+    size = last - c + 1;  // includes null at end
     memcpy(dest, &buf[c], last - c + 1);
 
-    return (size - 1);              //without null termination
+    return (size - 1);  // without null termination
 }
 
-int UTIL_ltoa(int64_t value, char *dest)
-{
-    return UTIL_ltoa_radix(value, dest, 10);
-}
+int UTIL_ltoa(int64_t value, char *dest) { return UTIL_ltoa_radix(value, dest, 10); }
 
-int UTIL_itoa(int value, char *dest)
-{
-    return UTIL_ltoa_radix((int64_t)value, dest, 10);
-}
-
-int UTIL_utoa(uint32_t value, char *dest)
-{
-    return UTIL_ltoa_radix((int64_t)value, dest, 10);
-}
+int UTIL_itoa(int value, char *dest) { return UTIL_ltoa_radix((int64_t)value, dest, 10); }
 
+int UTIL_utoa(uint32_t value, char *dest) { return UTIL_ltoa_radix((int64_t)value, dest, 10); }
index 2134d5d279b6293992a87123e8cc7a6bc26933ce..3bad2c26f2a6e1e79235b03e9f6dc411443c90d8 100644 (file)
@@ -6,5 +6,4 @@ int UTIL_ltoa(int64_t value, char *dest);
 int UTIL_itoa(int value, char *dest);
 int UTIL_utoa(uint32_t value, char *dest);
 
-#endif //_USB_UTIL_H_
-
+#endif  //_USB_UTIL_H_
index 424fbb53bb49bf8d8528e00dcc9217c249545228..b3918e534632758141654d7048a3f052b874a78f 100644 (file)
@@ -5,4 +5,3 @@ void wait_ms(uint64_t msec);
 void wait_us(uint16_t usec);
 
 #endif
-
index 47c63555cd814ffea120e0f5dc74a98566e76eef..fb001855ea4a4bf66d1a790e7da54193792d23eb 100644 (file)
@@ -29,31 +29,31 @@ static uint8_t bluefruit_keyboard_leds = 0;
 
 static void bluefruit_serial_send(uint8_t);
 
-void bluefruit_keyboard_print_report(report_keyboard_t *report)
-{
+void bluefruit_keyboard_print_report(report_keyboard_t *report) {
     if (!debug_keyboard) return;
-    dprintf("keys: "); for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) { debug_hex8(report->keys[i]); dprintf(" "); }
-    dprintf(" mods: "); debug_hex8(report->mods);
-    dprintf(" reserved: "); debug_hex8(report->reserved); 
+    dprintf("keys: ");
+    for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
+        debug_hex8(report->keys[i]);
+        dprintf(" ");
+    }
+    dprintf(" mods: ");
+    debug_hex8(report->mods);
+    dprintf(" reserved: ");
+    debug_hex8(report->reserved);
     dprintf("\n");
 }
 
 #ifdef BLUEFRUIT_TRACE_SERIAL
-static void bluefruit_trace_header()
-{
+static void bluefruit_trace_header() {
     dprintf("+------------------------------------+\n");
     dprintf("| HID report to Bluefruit via serial |\n");
     dprintf("+------------------------------------+\n|");
 }
 
-static void bluefruit_trace_footer()
-{
-    dprintf("|\n+------------------------------------+\n\n");
-}
+static void bluefruit_trace_footer() { dprintf("|\n+------------------------------------+\n\n"); }
 #endif
 
-static void bluefruit_serial_send(uint8_t data)
-{
+static void bluefruit_serial_send(uint8_t data) {
 #ifdef BLUEFRUIT_TRACE_SERIAL
     dprintf(" ");
     debug_hex8(data);
@@ -67,53 +67,38 @@ static void bluefruit_serial_send(uint8_t data)
  *------------------------------------------------------------------*/
 
 static uint8_t keyboard_leds(void);
-static void send_keyboard(report_keyboard_t *report);
-static void send_mouse(report_mouse_t *report);
-static void send_system(uint16_t data);
-static void send_consumer(uint16_t data);
-
+static void    send_keyboard(report_keyboard_t *report);
+static void    send_mouse(report_mouse_t *report);
+static void    send_system(uint16_t data);
+static void    send_consumer(uint16_t data);
 
 void sendString(char string[], int length) {
-    for(int i = 0; i < length; i++) {
+    for (int i = 0; i < length; i++) {
         serial_send(string[i]);
     }
 }
 
-static host_driver_t driver = {
-        keyboard_leds,
-        send_keyboard,
-        send_mouse,
-        send_system,
-        send_consumer
-};
-
-host_driver_t *bluefruit_driver(void)
-{
-    return &driver;
-}
+static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
 
-static uint8_t keyboard_leds(void) {
-    return bluefruit_keyboard_leds;
-}
+host_driver_t *bluefruit_driver(void) { return &driver; }
+
+static uint8_t keyboard_leds(void) { return bluefruit_keyboard_leds; }
 
-static void send_keyboard(report_keyboard_t *report)
-{
-#ifdef BLUEFRUIT_TRACE_SERIAL   
+static void send_keyboard(report_keyboard_t *report) {
+#ifdef BLUEFRUIT_TRACE_SERIAL
     bluefruit_trace_header();
 #endif
     bluefruit_serial_send(0xFD);
     for (uint8_t i = 0; i < KEYBOARD_REPORT_SIZE; i++) {
-
         bluefruit_serial_send(report->raw[i]);
     }
-#ifdef BLUEFRUIT_TRACE_SERIAL   
-    bluefruit_trace_footer();   
+#ifdef BLUEFRUIT_TRACE_SERIAL
+    bluefruit_trace_footer();
 #endif
 }
 
-static void send_mouse(report_mouse_t *report)
-{
-#ifdef BLUEFRUIT_TRACE_SERIAL   
+static void send_mouse(report_mouse_t *report) {
+#ifdef BLUEFRUIT_TRACE_SERIAL
     bluefruit_trace_header();
 #endif
     bluefruit_serial_send(0xFD);
@@ -122,17 +107,15 @@ static void send_mouse(report_mouse_t *report)
     bluefruit_serial_send(report->buttons);
     bluefruit_serial_send(report->x);
     bluefruit_serial_send(report->y);
-    bluefruit_serial_send(report->v); // should try sending the wheel v here
-    bluefruit_serial_send(report->h); // should try sending the wheel h here
+    bluefruit_serial_send(report->v);  // should try sending the wheel v here
+    bluefruit_serial_send(report->h);  // should try sending the wheel h here
     bluefruit_serial_send(0x00);
 #ifdef BLUEFRUIT_TRACE_SERIAL
     bluefruit_trace_footer();
 #endif
 }
 
-static void send_system(uint16_t data)
-{
-}
+static void send_system(uint16_t data) {}
 
 /*
 +-----------------+-------------------+-------+
@@ -153,48 +136,28 @@ static void send_system(uint16_t data)
 | Stop            | 00000000 00010000 | 00 10 |
 +-------------------------------------+-------+
 */
-#define CONSUMER2BLUEFRUIT(usage) \
-    (usage == AUDIO_MUTE           ? 0x0000  : \
-    (usage == AUDIO_VOL_UP         ? 0x1000  : \
-    (usage == AUDIO_VOL_DOWN       ? 0x2000  : \
-    (usage == TRANSPORT_NEXT_TRACK ? 0x0002  : \
-    (usage == TRANSPORT_PREV_TRACK ? 0x0004  : \
-    (usage == TRANSPORT_STOP       ? 0x0010  : \
-    (usage == TRANSPORT_STOP_EJECT ? 0x0000  : \
-    (usage == TRANSPORT_PLAY_PAUSE ? 0x4000  : \
-    (usage == AL_CC_CONFIG         ? 0x0000  : \
-    (usage == AL_EMAIL             ? 0x0000  : \
-    (usage == AL_CALCULATOR        ? 0x0000  : \
-    (usage == AL_LOCAL_BROWSER     ? 0x0000  : \
-    (usage == AC_SEARCH            ? 0x0400  : \
-    (usage == AC_HOME              ? 0x0100  : \
-    (usage == AC_BACK              ? 0x0000  : \
-    (usage == AC_FORWARD           ? 0x0000  : \
-    (usage == AC_STOP              ? 0x0000  : \
-    (usage == AC_REFRESH           ? 0x0000  : \
-    (usage == AC_BOOKMARKS         ? 0x0000  : 0)))))))))))))))))))
-
-static void send_consumer(uint16_t data)
-{
+#define CONSUMER2BLUEFRUIT(usage) (usage == AUDIO_MUTE ? 0x0000 : (usage == AUDIO_VOL_UP ? 0x1000 : (usage == AUDIO_VOL_DOWN ? 0x2000 : (usage == TRANSPORT_NEXT_TRACK ? 0x0002 : (usage == TRANSPORT_PREV_TRACK ? 0x0004 : (usage == TRANSPORT_STOP ? 0x0010 : (usage == TRANSPORT_STOP_EJECT ? 0x0000 : (usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : (usage == AL_CC_CONFIG ? 0x0000 : (usage == AL_EMAIL ? 0x0000 : (usage == AL_CALCULATOR ? 0x0000 : (usage == AL_LOCAL_BROWSER ? 0x0000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : (usage == AC_BACK ? 0x0000 : (usage == AC_FORWARD ? 0x0000 : (usage == AC_STOP ? 0x0000 : (usage == AC_REFRESH ? 0x0000 : (usage == AC_BOOKMARKS ? 0x0000 : 0)))))))))))))))))))
+
+static void send_consumer(uint16_t data) {
     static uint16_t last_data = 0;
     if (data == last_data) return;
     last_data = data;
-    
+
     uint16_t bitmap = CONSUMER2BLUEFRUIT(data);
-    
-#ifdef BLUEFRUIT_TRACE_SERIAL   
-    dprintf("\nData: "); 
-    debug_hex16(data); 
-    dprintf("; bitmap: "); 
-    debug_hex16(bitmap); 
+
+#ifdef BLUEFRUIT_TRACE_SERIAL
+    dprintf("\nData: ");
+    debug_hex16(data);
+    dprintf("; bitmap: ");
+    debug_hex16(bitmap);
     dprintf("\n");
     bluefruit_trace_header();
 #endif
     bluefruit_serial_send(0xFD);
     bluefruit_serial_send(0x00);
     bluefruit_serial_send(0x02);
-    bluefruit_serial_send((bitmap>>8)&0xFF);
-    bluefruit_serial_send(bitmap&0xFF); 
+    bluefruit_serial_send((bitmap >> 8) & 0xFF);
+    bluefruit_serial_send(bitmap & 0xFF);
     bluefruit_serial_send(0x00);
     bluefruit_serial_send(0x00);
     bluefruit_serial_send(0x00);
index ceacc4a36711279bbb705f945e423d0c41e64b8f..7b636abb955bcba537c13847ac65753aa2ff3d4c 100644 (file)
@@ -19,7 +19,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "host_driver.h"
 
-
 host_driver_t *bluefruit_driver(void);
 
 #endif
\ No newline at end of file
index 8a6386b4ebaa2b673df0eeacddef8c67d19914f5..3adcab4f426dcbb94c44477126b066d8f63d521b 100644 (file)
@@ -34,16 +34,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "bluefruit.h"
 #include "pjrc.h"
 
-#define CPU_PRESCALE(n)    (CLKPR = 0x80, CLKPR = (n))
+#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
 
-#define HOST_DRIVER_NOT_SET     0
-#define BLUEFRUIT_HOST_DRIVER   1
-#define PJRC_HOST_DRIVER        2
-
-
-int main(void)
-{
+#define HOST_DRIVER_NOT_SET 0
+#define BLUEFRUIT_HOST_DRIVER 1
+#define PJRC_HOST_DRIVER 2
 
+int main(void) {
     CPU_PRESCALE(0);
 
     // DDRD  = _BV(PD5);
@@ -58,7 +55,6 @@ int main(void)
     // _delay_ms(2000);
     // while (!usb_configured()) /* wait */
 
-
     keyboard_setup();
 
     dprintf("Initializing keyboard...\n");
@@ -76,11 +72,11 @@ int main(void)
     //     DDRB   = _BV(PB6);
     //     PORTB |= _BV(PB6);
 
-        dprintf("Setting host driver to bluefruit...\n");
-        host_set_driver(bluefruit_driver());
+    dprintf("Setting host driver to bluefruit...\n");
+    host_set_driver(bluefruit_driver());
 
-        dprintf("Initializing serial...\n");
-        serial_init();
+    dprintf("Initializing serial...\n");
+    serial_init();
 
     // char swpa[] = "+++\r\n";
     // for (int i = 0; i < 5; i++) {
@@ -101,39 +97,38 @@ int main(void)
     //     serial_send(swpa[i]);
     // }
 
-        // wait an extra second for the PC's operating system
-        // to load drivers and do whatever it does to actually
-        // be ready for input
-        _delay_ms(1000);
-        // PORTD = ~_BV(PD5);
-        dprintf("Starting main loop");
-        while (1) {
-            keyboard_task();
-        }
-
-//     } else {
-
-//         // I'm not smart enough to get this done with LUFA - BCG
-//         dprintf("Setting host driver to PJRC...\n");
-//         host_set_driver(pjrc_driver());
-// #ifdef SLEEP_LED_ENABLE
-//     sleep_led_init();
-// #endif
-//         // wait an extra second for the PC's operating system
-//         // to load drivers and do whatever it does to actually
-//         // be ready for input
-//         _delay_ms(1000);
-//         PORTB = ~_BV(PB0);
-//         dprintf("Starting main loop");
-//         while (1) {
-//             while (suspend) {
-//                 suspend_power_down();
-//                 if (remote_wakeup && suspend_wakeup_condition()) {
-//                     usb_remote_wakeup();
-//                 }
-//             }
-//             keyboard_task();
-//         }
-//     }
-
+    // wait an extra second for the PC's operating system
+    // to load drivers and do whatever it does to actually
+    // be ready for input
+    _delay_ms(1000);
+    // PORTD = ~_BV(PD5);
+    dprintf("Starting main loop");
+    while (1) {
+        keyboard_task();
+    }
+
+    //     } else {
+
+    //         // I'm not smart enough to get this done with LUFA - BCG
+    //         dprintf("Setting host driver to PJRC...\n");
+    //         host_set_driver(pjrc_driver());
+    // #ifdef SLEEP_LED_ENABLE
+    //     sleep_led_init();
+    // #endif
+    //         // wait an extra second for the PC's operating system
+    //         // to load drivers and do whatever it does to actually
+    //         // be ready for input
+    //         _delay_ms(1000);
+    //         PORTB = ~_BV(PB0);
+    //         dprintf("Starting main loop");
+    //         while (1) {
+    //             while (suspend) {
+    //                 suspend_power_down();
+    //                 if (remote_wakeup && suspend_wakeup_condition()) {
+    //                     usb_remote_wakeup();
+    //                 }
+    //             }
+    //             keyboard_task();
+    //         }
+    //     }
 }
index a5374d820c010bef0e3bee1f69f67028261c0739..f59c8d1ddaa49447d62d8703937d663f9a074918 100644 (file)
@@ -2,7 +2,7 @@
 #include "stddef.h"
 #include "inttypes.h"
 
-#define ATTR_PACKED                      __attribute__ ((packed))
+#define ATTR_PACKED __attribute__((packed))
 /** Concatenates the given input into a single token, via the C Preprocessor.
  *
  *  \param[in] x  First item to concatenate.
@@ -10,7 +10,7 @@
  *
  *  \return Concatenated version of the input.
  */
-#define CONCAT(x, y)            x ## y
+#define CONCAT(x, y) x##y
 
 /** CConcatenates the given input into a single token after macro expansion, via the C Preprocessor.
  *
@@ -19,8 +19,8 @@
  *
  *  \return Concatenated version of the expanded input.
  */
-#define CONCAT_EXPANDED(x, y)   CONCAT(x, y)
-#define CPU_TO_LE16(x)           (x)
+#define CONCAT_EXPANDED(x, y) CONCAT(x, y)
+#define CPU_TO_LE16(x) (x)
 
 // We don't need anything from the following files, or we have defined it already
 #define __LUFA_COMMON_H__
index 8de55bfe3fd23300a91c2df4c0fba534c7d5fc06..de2b493b8418ce12397ab07d7b4c5ac06dc01673 100644 (file)
 #include "debug.h"
 #include "printf.h"
 #ifdef SLEEP_LED_ENABLE
-#include "sleep_led.h"
+#    include "sleep_led.h"
 #endif
 #ifdef SERIAL_LINK_ENABLE
-#include "serial_link/system/serial_link.h"
+#    include "serial_link/system/serial_link.h"
 #endif
 #ifdef VISUALIZER_ENABLE
-#include "visualizer/visualizer.h"
+#    include "visualizer/visualizer.h"
 #endif
 #ifdef MIDI_ENABLE
-#include "qmk_midi.h"
+#    include "qmk_midi.h"
 #endif
 #ifdef STM32_EEPROM_ENABLE
-#include "eeprom_stm32.h"
+#    include "eeprom_stm32.h"
 #endif
 #include "suspend.h"
 #include "wait.h"
 
 /* declarations */
 uint8_t keyboard_leds(void);
-void send_keyboard(report_keyboard_t *report);
-void send_mouse(report_mouse_t *report);
-void send_system(uint16_t data);
-void send_consumer(uint16_t data);
+void    send_keyboard(report_keyboard_t *report);
+void    send_mouse(report_mouse_t *report);
+void    send_system(uint16_t data);
+void    send_consumer(uint16_t data);
 
 /* host struct */
-host_driver_t chibios_driver = {
-  keyboard_leds,
-  send_keyboard,
-  send_mouse,
-  send_system,
-  send_consumer
-};
+host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
 
 #ifdef VIRTSER_ENABLE
 void virtser_task(void);
@@ -103,127 +97,123 @@ void console_task(void);
 //   }
 // }
 
-
-
 /* Main thread
  */
 int main(void) {
-  /* ChibiOS/RT init */
-  halInit();
-  chSysInit();
+    /* ChibiOS/RT init */
+    halInit();
+    chSysInit();
 
 #ifdef STM32_EEPROM_ENABLE
-  EEPROM_Init();
+    EEPROM_Init();
 #endif
 
-  // TESTING
-  // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+    // TESTING
+    // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
 
-  keyboard_setup();
+    keyboard_setup();
 
-  /* Init USB */
-  init_usb_driver(&USB_DRIVER);
+    /* Init USB */
+    init_usb_driver(&USB_DRIVER);
 
-  /* init printf */
-  init_printf(NULL,sendchar_pf);
+    /* init printf */
+    init_printf(NULL, sendchar_pf);
 
 #ifdef MIDI_ENABLE
-  setup_midi();
+    setup_midi();
 #endif
 
 #ifdef SERIAL_LINK_ENABLE
-  init_serial_link();
+    init_serial_link();
 #endif
 
 #ifdef VISUALIZER_ENABLE
-  visualizer_init();
+    visualizer_init();
 #endif
 
+    host_driver_t *driver = NULL;
 
-  host_driver_t* driver = NULL;
-
-  /* Wait until the USB or serial link is active */
-  while (true) {
+    /* Wait until the USB or serial link is active */
+    while (true) {
 #if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE)
-    if(USB_DRIVER.state == USB_ACTIVE) {
-      driver = &chibios_driver;
-      break;
-    }
+        if (USB_DRIVER.state == USB_ACTIVE) {
+            driver = &chibios_driver;
+            break;
+        }
 #else
-    driver = &chibios_driver;
-    break;
+        driver = &chibios_driver;
+        break;
 #endif
 #ifdef SERIAL_LINK_ENABLE
-    if(is_serial_link_connected()) {
-      driver = get_serial_link_driver();
-      break;
-    }
-    serial_link_update();
+        if (is_serial_link_connected()) {
+            driver = get_serial_link_driver();
+            break;
+        }
+        serial_link_update();
 #endif
-    wait_ms(50);
-  }
+        wait_ms(50);
+    }
 
-  /* Do need to wait here!
-   * Otherwise the next print might start a transfer on console EP
-   * before the USB is completely ready, which sometimes causes
-   * HardFaults.
-   */
-  wait_ms(50);
+    /* Do need to wait here!
+     * Otherwise the next print might start a transfer on console EP
+     * before the USB is completely ready, which sometimes causes
+     * HardFaults.
+     */
+    wait_ms(50);
 
-  print("USB configured.\n");
+    print("USB configured.\n");
 
-  /* init TMK modules */
-  keyboard_init();
-  host_set_driver(driver);
+    /* init TMK modules */
+    keyboard_init();
+    host_set_driver(driver);
 
 #ifdef SLEEP_LED_ENABLE
-  sleep_led_init();
+    sleep_led_init();
 #endif
 
-  print("Keyboard start.\n");
-
-  /* Main loop */
-  while(true) {
+    print("Keyboard start.\n");
 
+    /* Main loop */
+    while (true) {
 #if !defined(NO_USB_STARTUP_CHECK)
-    if(USB_DRIVER.state == USB_SUSPENDED) {
-      print("[s]");
-#ifdef VISUALIZER_ENABLE
-      visualizer_suspend();
-#endif
-      while(USB_DRIVER.state == USB_SUSPENDED) {
-        /* Do this in the suspended state */
-#ifdef SERIAL_LINK_ENABLE
-        serial_link_update();
-#endif
-        suspend_power_down(); // on AVR this deep sleeps for 15ms
-        /* Remote wakeup */
-        if(suspend_wakeup_condition()) {
-          usbWakeupHost(&USB_DRIVER);
+        if (USB_DRIVER.state == USB_SUSPENDED) {
+            print("[s]");
+#    ifdef VISUALIZER_ENABLE
+            visualizer_suspend();
+#    endif
+            while (USB_DRIVER.state == USB_SUSPENDED) {
+                /* Do this in the suspended state */
+#    ifdef SERIAL_LINK_ENABLE
+                serial_link_update();
+#    endif
+                suspend_power_down();  // on AVR this deep sleeps for 15ms
+                /* Remote wakeup */
+                if (suspend_wakeup_condition()) {
+                    usbWakeupHost(&USB_DRIVER);
+                }
+            }
+            /* Woken up */
+            // variables has been already cleared by the wakeup hook
+            send_keyboard_report();
+#    ifdef MOUSEKEY_ENABLE
+            mousekey_send();
+#    endif /* MOUSEKEY_ENABLE */
+
+#    ifdef VISUALIZER_ENABLE
+            visualizer_resume();
+#    endif
         }
-      }
-      /* Woken up */
-      // variables has been already cleared by the wakeup hook
-      send_keyboard_report();
-#ifdef MOUSEKEY_ENABLE
-      mousekey_send();
-#endif /* MOUSEKEY_ENABLE */
-
-#ifdef VISUALIZER_ENABLE
-      visualizer_resume();
-#endif
-    }
 #endif
 
-    keyboard_task();
+        keyboard_task();
 #ifdef CONSOLE_ENABLE
-    console_task();
+        console_task();
 #endif
 #ifdef VIRTSER_ENABLE
-    virtser_task();
+        virtser_task();
 #endif
 #ifdef RAW_ENABLE
-    raw_hid_task();
+        raw_hid_task();
 #endif
-  }
+    }
 }
index fe535eeb3a8b3393d44d3bcfc5135d9bb1dd7995..28a8c666355dfd00fc9055a08c201270ed076287 100644 (file)
 /*
  * Current Line Coding.
  */
-static cdc_linecoding_t linecoding = {
-  {0x00, 0x96, 0x00, 0x00},             /* 38400.                           */
-  LC_STOP_1, LC_PARITY_NONE, 8
-};
+static cdc_linecoding_t linecoding = {{0x00, 0x96, 0x00, 0x00}, /* 38400.                           */
+                                      LC_STOP_1,
+                                      LC_PARITY_NONE,
+                                      8};
 
 /*===========================================================================*/
 /* Driver local functions.                                                   */
 /*===========================================================================*/
 
 static bool qmkusb_start_receive(QMKUSBDriver *qmkusbp) {
-  uint8_t *buf;
-
-  /* If the USB driver is not in the appropriate state then transactions
-     must not be started.*/
-  if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) ||
-      (qmkusbp->state != QMKUSB_READY)) {
-    return true;
-  }
-
-  /* Checking if there is already a transaction ongoing on the endpoint.*/
-  if (usbGetReceiveStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
-    return true;
-  }
-
-  /* Checking if there is a buffer ready for incoming data.*/
-  buf = ibqGetEmptyBufferI(&qmkusbp->ibqueue);
-  if (buf == NULL) {
-    return true;
-  }
-
-  /* Buffer found, starting a new transaction.*/
-  usbStartReceiveI(qmkusbp->config->usbp, qmkusbp->config->bulk_out,
-                   buf, qmkusbp->ibqueue.bsize - sizeof(size_t));
-
-  return false;
-}
-
-/*
- * Interface implementation.
- */
-
-static size_t _write(void *ip, const uint8_t *bp, size_t n) {
+    uint8_t *buf;
 
-  return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp,
-                         n, TIME_INFINITE);
-}
+    /* If the USB driver is not in the appropriate state then transactions
+       must not be started.*/
+    if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) || (qmkusbp->state != QMKUSB_READY)) {
+        return true;
+    }
 
-static size_t _read(void *ip, uint8_t *bp, size_t n) {
+    /* Checking if there is already a transaction ongoing on the endpoint.*/
+    if (usbGetReceiveStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
+        return true;
+    }
 
-  return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp,
-                        n, TIME_INFINITE);
-}
+    /* Checking if there is a buffer ready for incoming data.*/
+    buf = ibqGetEmptyBufferI(&qmkusbp->ibqueue);
+    if (buf == NULL) {
+        return true;
+    }
 
-static msg_t _put(void *ip, uint8_t b) {
+    /* Buffer found, starting a new transaction.*/
+    usbStartReceiveI(qmkusbp->config->usbp, qmkusbp->config->bulk_out, buf, qmkusbp->ibqueue.bsize - sizeof(size_t));
 
-  return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, TIME_INFINITE);
+    return false;
 }
 
-static msg_t _get(void *ip) {
-
-  return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, TIME_INFINITE);
-}
+/*
+ * Interface implementation.
+ */
 
-static msg_t _putt(void *ip, uint8_t b, systime_t timeout) {
+static size_t _write(void *ip, const uint8_t *bp, size_t n) { return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, TIME_INFINITE); }
 
-  return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, timeout);
-}
+static size_t _read(void *ip, uint8_t *bp, size_t n) { return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, TIME_INFINITE); }
 
-static msg_t _gett(void *ip, systime_t timeout) {
+static msg_t _put(void *ip, uint8_t b) { return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, TIME_INFINITE); }
 
-  return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, timeout);
-}
+static msg_t _get(void *ip) { return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, TIME_INFINITE); }
 
-static size_t _writet(void *ip, const uint8_t *bp, size_t n, systime_t timeout) {
+static msg_t _putt(void *ip, uint8_t b, systime_t timeout) { return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, timeout); }
 
-  return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, timeout);
-}
+static msg_t _gett(void *ip, systime_t timeout) { return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, timeout); }
 
-static size_t _readt(void *ip, uint8_t *bp, size_t n, systime_t timeout) {
+static size_t _writet(void *ip, const uint8_t *bp, size_t n, systime_t timeout) { return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, timeout); }
 
-  return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, timeout);
-}
+static size_t _readt(void *ip, uint8_t *bp, size_t n, systime_t timeout) { return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, timeout); }
 
-static const struct QMKUSBDriverVMT vmt = {
-  _write, _read, _put, _get,
-  _putt, _gett, _writet, _readt
-};
+static const struct QMKUSBDriverVMT vmt = {_write, _read, _put, _get, _putt, _gett, _writet, _readt};
 
 /**
  * @brief   Notification of empty buffer released into the input buffers queue.
@@ -135,8 +104,8 @@ static const struct QMKUSBDriverVMT vmt = {
  * @param[in] bqp       the buffers queue pointer.
  */
 static void ibnotify(io_buffers_queue_t *bqp) {
-  QMKUSBDriver *qmkusbp = bqGetLinkX(bqp);
-  (void) qmkusb_start_receive(qmkusbp);
+    QMKUSBDriver *qmkusbp = bqGetLinkX(bqp);
+    (void)qmkusb_start_receive(qmkusbp);
 }
 
 /**
@@ -145,25 +114,24 @@ static void ibnotify(io_buffers_queue_t *bqp) {
  * @param[in] bqp       the buffers queue pointer.
  */
 static void obnotify(io_buffers_queue_t *bqp) {
-  size_t n;
-  QMKUSBDriver *qmkusbp = bqGetLinkX(bqp);
-
-  /* If the USB driver is not in the appropriate state then transactions
-     must not be started.*/
-  if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) ||
-      (qmkusbp->state != QMKUSB_READY)) {
-    return;
-  }
-
-  /* Checking if there is already a transaction ongoing on the endpoint.*/
-  if (!usbGetTransmitStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
-    /* Trying to get a full buffer.*/
-    uint8_t *buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
-    if (buf != NULL) {
-      /* Buffer found, starting a new transaction.*/
-      usbStartTransmitI(qmkusbp->config->usbp, qmkusbp->config->bulk_in, buf, n);
+    size_t        n;
+    QMKUSBDriver *qmkusbp = bqGetLinkX(bqp);
+
+    /* If the USB driver is not in the appropriate state then transactions
+       must not be started.*/
+    if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) || (qmkusbp->state != QMKUSB_READY)) {
+        return;
+    }
+
+    /* Checking if there is already a transaction ongoing on the endpoint.*/
+    if (!usbGetTransmitStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
+        /* Trying to get a full buffer.*/
+        uint8_t *buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
+        if (buf != NULL) {
+            /* Buffer found, starting a new transaction.*/
+            usbStartTransmitI(qmkusbp->config->usbp, qmkusbp->config->bulk_in, buf, n);
+        }
     }
-  }
 }
 
 /*===========================================================================*/
@@ -177,8 +145,7 @@ static void obnotify(io_buffers_queue_t *bqp) {
  *
  * @init
  */
-void qmkusbInit(void) {
-}
+void qmkusbInit(void) {}
 
 /**
  * @brief   Initializes a generic full duplex driver object.
@@ -190,17 +157,12 @@ void qmkusbInit(void) {
  * @init
  */
 void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config) {
-
-  qmkusbp->vmt = &vmt;
-  osalEventObjectInit(&qmkusbp->event);
-  qmkusbp->state = QMKUSB_STOP;
-  // Note that the config uses the USB direction naming
-  ibqObjectInit(&qmkusbp->ibqueue, true, config->ob,
-                config->out_size, config->out_buffers,
-                ibnotify, qmkusbp);
-  obqObjectInit(&qmkusbp->obqueue, true, config->ib,
-                config->in_size, config->in_buffers,
-                obnotify, qmkusbp);
+    qmkusbp->vmt = &vmt;
+    osalEventObjectInit(&qmkusbp->event);
+    qmkusbp->state = QMKUSB_STOP;
+    // Note that the config uses the USB direction naming
+    ibqObjectInit(&qmkusbp->ibqueue, true, config->ob, config->out_size, config->out_buffers, ibnotify, qmkusbp);
+    obqObjectInit(&qmkusbp->obqueue, true, config->ib, config->in_size, config->in_buffers, obnotify, qmkusbp);
 }
 
 /**
@@ -212,21 +174,20 @@ void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config) {
  * @api
  */
 void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config) {
-  USBDriver *usbp = config->usbp;
-
-  osalDbgCheck(qmkusbp != NULL);
-
-  osalSysLock();
-  osalDbgAssert((qmkusbp->state == QMKUSB_STOP) || (qmkusbp->state == QMKUSB_READY),
-                "invalid state");
-  usbp->in_params[config->bulk_in - 1U]   = qmkusbp;
-  usbp->out_params[config->bulk_out - 1U] = qmkusbp;
-  if (config->int_in > 0U) {
-    usbp->in_params[config->int_in - 1U]  = qmkusbp;
-  }
-  qmkusbp->config = config;
-  qmkusbp->state = QMKUSB_READY;
-  osalSysUnlock();
+    USBDriver *usbp = config->usbp;
+
+    osalDbgCheck(qmkusbp != NULL);
+
+    osalSysLock();
+    osalDbgAssert((qmkusbp->state == QMKUSB_STOP) || (qmkusbp->state == QMKUSB_READY), "invalid state");
+    usbp->in_params[config->bulk_in - 1U]   = qmkusbp;
+    usbp->out_params[config->bulk_out - 1U] = qmkusbp;
+    if (config->int_in > 0U) {
+        usbp->in_params[config->int_in - 1U] = qmkusbp;
+    }
+    qmkusbp->config = config;
+    qmkusbp->state  = QMKUSB_READY;
+    osalSysUnlock();
 }
 
 /**
@@ -239,31 +200,30 @@ void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config) {
  * @api
  */
 void qmkusbStop(QMKUSBDriver *qmkusbp) {
-  USBDriver *usbp = qmkusbp->config->usbp;
+    USBDriver *usbp = qmkusbp->config->usbp;
 
-  osalDbgCheck(qmkusbp != NULL);
+    osalDbgCheck(qmkusbp != NULL);
 
-  osalSysLock();
+    osalSysLock();
 
-  osalDbgAssert((qmkusbp->state == QMKUSB_STOP) || (qmkusbp->state == QMKUSB_READY),
-                "invalid state");
+    osalDbgAssert((qmkusbp->state == QMKUSB_STOP) || (qmkusbp->state == QMKUSB_READY), "invalid state");
 
-  /* Driver in stopped state.*/
-  usbp->in_params[qmkusbp->config->bulk_in - 1U]   = NULL;
-  usbp->out_params[qmkusbp->config->bulk_out - 1U] = NULL;
-  if (qmkusbp->config->int_in > 0U) {
-    usbp->in_params[qmkusbp->config->int_in - 1U]  = NULL;
-  }
-  qmkusbp->config = NULL;
-  qmkusbp->state  = QMKUSB_STOP;
+    /* Driver in stopped state.*/
+    usbp->in_params[qmkusbp->config->bulk_in - 1U]   = NULL;
+    usbp->out_params[qmkusbp->config->bulk_out - 1U] = NULL;
+    if (qmkusbp->config->int_in > 0U) {
+        usbp->in_params[qmkusbp->config->int_in - 1U] = NULL;
+    }
+    qmkusbp->config = NULL;
+    qmkusbp->state  = QMKUSB_STOP;
 
-  /* Enforces a disconnection.*/
-  chnAddFlagsI(qmkusbp, CHN_DISCONNECTED);
-  ibqResetI(&qmkusbp->ibqueue);
-  obqResetI(&qmkusbp->obqueue);
-  osalOsRescheduleS();
+    /* Enforces a disconnection.*/
+    chnAddFlagsI(qmkusbp, CHN_DISCONNECTED);
+    ibqResetI(&qmkusbp->ibqueue);
+    obqResetI(&qmkusbp->obqueue);
+    osalOsRescheduleS();
 
-  osalSysUnlock();
+    osalSysUnlock();
 }
 
 /**
@@ -279,10 +239,9 @@ void qmkusbStop(QMKUSBDriver *qmkusbp) {
  * @iclass
  */
 void qmkusbSuspendHookI(QMKUSBDriver *qmkusbp) {
-
-  chnAddFlagsI(qmkusbp, CHN_DISCONNECTED);
-  bqSuspendI(&qmkusbp->ibqueue);
-  bqSuspendI(&qmkusbp->obqueue);
+    chnAddFlagsI(qmkusbp, CHN_DISCONNECTED);
+    bqSuspendI(&qmkusbp->ibqueue);
+    bqSuspendI(&qmkusbp->obqueue);
 }
 
 /**
@@ -298,10 +257,9 @@ void qmkusbSuspendHookI(QMKUSBDriver *qmkusbp) {
  * @iclass
  */
 void qmkusbWakeupHookI(QMKUSBDriver *qmkusbp) {
-
-  chnAddFlagsI(qmkusbp, CHN_CONNECTED);
-  bqResumeX(&qmkusbp->ibqueue);
-  bqResumeX(&qmkusbp->obqueue);
+    chnAddFlagsI(qmkusbp, CHN_CONNECTED);
+    bqResumeX(&qmkusbp->ibqueue);
+    bqResumeX(&qmkusbp->obqueue);
 }
 
 /**
@@ -312,13 +270,12 @@ void qmkusbWakeupHookI(QMKUSBDriver *qmkusbp) {
  * @iclass
  */
 void qmkusbConfigureHookI(QMKUSBDriver *qmkusbp) {
-
-  ibqResetI(&qmkusbp->ibqueue);
-  bqResumeX(&qmkusbp->ibqueue);
-  obqResetI(&qmkusbp->obqueue);
-  bqResumeX(&qmkusbp->obqueue);
-  chnAddFlagsI(qmkusbp, CHN_CONNECTED);
-  (void) qmkusb_start_receive(qmkusbp);
+    ibqResetI(&qmkusbp->ibqueue);
+    bqResumeX(&qmkusbp->ibqueue);
+    obqResetI(&qmkusbp->obqueue);
+    bqResumeX(&qmkusbp->obqueue);
+    chnAddFlagsI(qmkusbp, CHN_CONNECTED);
+    (void)qmkusb_start_receive(qmkusbp);
 }
 
 /**
@@ -337,24 +294,23 @@ void qmkusbConfigureHookI(QMKUSBDriver *qmkusbp) {
  * @retval false        Message not handled.
  */
 bool qmkusbRequestsHook(USBDriver *usbp) {
-
-  if ((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) {
-    switch (usbp->setup[1]) {
-    case CDC_GET_LINE_CODING:
-      usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL);
-      return true;
-    case CDC_SET_LINE_CODING:
-      usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL);
-      return true;
-    case CDC_SET_CONTROL_LINE_STATE:
-      /* Nothing to do, there are no control lines.*/
-      usbSetupTransfer(usbp, NULL, 0, NULL);
-      return true;
-    default:
-      return false;
+    if ((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) {
+        switch (usbp->setup[1]) {
+            case CDC_GET_LINE_CODING:
+                usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL);
+                return true;
+            case CDC_SET_LINE_CODING:
+                usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL);
+                return true;
+            case CDC_SET_CONTROL_LINE_STATE:
+                /* Nothing to do, there are no control lines.*/
+                usbSetupTransfer(usbp, NULL, 0, NULL);
+                return true;
+            default:
+                return false;
+        }
     }
-  }
-  return false;
+    return false;
 }
 
 /**
@@ -367,36 +323,34 @@ bool qmkusbRequestsHook(USBDriver *usbp) {
  * @iclass
  */
 void qmkusbSOFHookI(QMKUSBDriver *qmkusbp) {
+    /* If the USB driver is not in the appropriate state then transactions
+       must not be started.*/
+    if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) || (qmkusbp->state != QMKUSB_READY)) {
+        return;
+    }
 
-  /* If the USB driver is not in the appropriate state then transactions
-     must not be started.*/
-  if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) ||
-      (qmkusbp->state != QMKUSB_READY)) {
-    return;
-  }
-
-  /* If there is already a transaction ongoing then another one cannot be
-     started.*/
-  if (usbGetTransmitStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
-    return;
-  }
-
-  /* Checking if there only a buffer partially filled, if so then it is
-     enforced in the queue and transmitted.*/
-  if (obqTryFlushI(&qmkusbp->obqueue)) {
-    size_t n;
-    uint8_t *buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
-
-    /* For fixed size drivers, fill the end with zeros */
-    if (qmkusbp->config->fixed_size) {
-      memset(buf + n, 0, qmkusbp->config->in_size - n);
-      n = qmkusbp->config->in_size;
+    /* If there is already a transaction ongoing then another one cannot be
+       started.*/
+    if (usbGetTransmitStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
+        return;
     }
 
-    osalDbgAssert(buf != NULL, "queue is empty");
+    /* Checking if there only a buffer partially filled, if so then it is
+       enforced in the queue and transmitted.*/
+    if (obqTryFlushI(&qmkusbp->obqueue)) {
+        size_t   n;
+        uint8_t *buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
 
-    usbStartTransmitI(qmkusbp->config->usbp, qmkusbp->config->bulk_in, buf, n);
-  }
+        /* For fixed size drivers, fill the end with zeros */
+        if (qmkusbp->config->fixed_size) {
+            memset(buf + n, 0, qmkusbp->config->in_size - n);
+            n = qmkusbp->config->in_size;
+        }
+
+        osalDbgAssert(buf != NULL, "queue is empty");
+
+        usbStartTransmitI(qmkusbp->config->usbp, qmkusbp->config->bulk_in, buf, n);
+    }
 }
 
 /**
@@ -408,49 +362,45 @@ void qmkusbSOFHookI(QMKUSBDriver *qmkusbp) {
  * @param[in] ep        IN endpoint number
  */
 void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep) {
-  uint8_t *buf;
-  size_t n;
-  QMKUSBDriver *qmkusbp = usbp->in_params[ep - 1U];
+    uint8_t *     buf;
+    size_t        n;
+    QMKUSBDriver *qmkusbp = usbp->in_params[ep - 1U];
 
-  if (qmkusbp == NULL) {
-    return;
-  }
+    if (qmkusbp == NULL) {
+        return;
+    }
 
-  osalSysLockFromISR();
+    osalSysLockFromISR();
 
-  /* Signaling that space is available in the output queue.*/
-  chnAddFlagsI(qmkusbp, CHN_OUTPUT_EMPTY);
+    /* Signaling that space is available in the output queue.*/
+    chnAddFlagsI(qmkusbp, CHN_OUTPUT_EMPTY);
 
-  /* Freeing the buffer just transmitted, if it was not a zero size packet.*/
-  if (usbp->epc[ep]->in_state->txsize > 0U) {
-    obqReleaseEmptyBufferI(&qmkusbp->obqueue);
-  }
+    /* Freeing the buffer just transmitted, if it was not a zero size packet.*/
+    if (usbp->epc[ep]->in_state->txsize > 0U) {
+        obqReleaseEmptyBufferI(&qmkusbp->obqueue);
+    }
 
-  /* Checking if there is a buffer ready for transmission.*/
-  buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
+    /* Checking if there is a buffer ready for transmission.*/
+    buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
 
-  if (buf != NULL) {
-    /* The endpoint cannot be busy, we are in the context of the callback,
-       so it is safe to transmit without a check.*/
-    usbStartTransmitI(usbp, ep, buf, n);
-  }
-  else if ((usbp->epc[ep]->in_state->txsize > 0U) &&
-           ((usbp->epc[ep]->in_state->txsize &
-            ((size_t)usbp->epc[ep]->in_maxsize - 1U)) == 0U)) {
-    /* Transmit zero sized packet in case the last one has maximum allowed
-       size. Otherwise the recipient may expect more data coming soon and
-       not return buffered data to app. See section 5.8.3 Bulk Transfer
-       Packet Size Constraints of the USB Specification document.*/
-    if (!qmkusbp->config->fixed_size) {
-      usbStartTransmitI(usbp, ep, usbp->setup, 0);
+    if (buf != NULL) {
+        /* The endpoint cannot be busy, we are in the context of the callback,
+           so it is safe to transmit without a check.*/
+        usbStartTransmitI(usbp, ep, buf, n);
+    } else if ((usbp->epc[ep]->in_state->txsize > 0U) && ((usbp->epc[ep]->in_state->txsize & ((size_t)usbp->epc[ep]->in_maxsize - 1U)) == 0U)) {
+        /* Transmit zero sized packet in case the last one has maximum allowed
+           size. Otherwise the recipient may expect more data coming soon and
+           not return buffered data to app. See section 5.8.3 Bulk Transfer
+           Packet Size Constraints of the USB Specification document.*/
+        if (!qmkusbp->config->fixed_size) {
+            usbStartTransmitI(usbp, ep, usbp->setup, 0);
+        }
+
+    } else {
+        /* Nothing to transmit.*/
     }
 
-  }
-  else {
-    /* Nothing to transmit.*/
-  }
-
-  osalSysUnlockFromISR();
+    osalSysUnlockFromISR();
 }
 
 /**
@@ -462,27 +412,25 @@ void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep) {
  * @param[in] ep        OUT endpoint number
  */
 void qmkusbDataReceived(USBDriver *usbp, usbep_t ep) {
-  QMKUSBDriver *qmkusbp = usbp->out_params[ep - 1U];
-  if (qmkusbp == NULL) {
-    return;
-  }
+    QMKUSBDriver *qmkusbp = usbp->out_params[ep - 1U];
+    if (qmkusbp == NULL) {
+        return;
+    }
 
-  osalSysLockFromISR();
+    osalSysLockFromISR();
 
-  /* Signaling that data is available in the input queue.*/
-  chnAddFlagsI(qmkusbp, CHN_INPUT_AVAILABLE);
+    /* Signaling that data is available in the input queue.*/
+    chnAddFlagsI(qmkusbp, CHN_INPUT_AVAILABLE);
 
-  /* Posting the filled buffer in the queue.*/
-  ibqPostFullBufferI(&qmkusbp->ibqueue,
-                     usbGetReceiveTransactionSizeX(qmkusbp->config->usbp,
-                                                   qmkusbp->config->bulk_out));
+    /* Posting the filled buffer in the queue.*/
+    ibqPostFullBufferI(&qmkusbp->ibqueue, usbGetReceiveTransactionSizeX(qmkusbp->config->usbp, qmkusbp->config->bulk_out));
 
-  /* The endpoint cannot be busy, we are in the context of the callback,
-     so a packet is in the buffer for sure. Trying to get a free buffer
-     for the next transaction.*/
-  (void) qmkusb_start_receive(qmkusbp);
+    /* The endpoint cannot be busy, we are in the context of the callback,
+       so a packet is in the buffer for sure. Trying to get a free buffer
+       for the next transaction.*/
+    (void)qmkusb_start_receive(qmkusbp);
 
-  osalSysUnlockFromISR();
+    osalSysUnlockFromISR();
 }
 
 /**
@@ -494,9 +442,8 @@ void qmkusbDataReceived(USBDriver *usbp, usbep_t ep) {
  * @param[in] ep        endpoint number
  */
 void qmkusbInterruptTransmitted(USBDriver *usbp, usbep_t ep) {
-
-  (void)usbp;
-  (void)ep;
+    (void)usbp;
+    (void)ep;
 }
 
 /** @} */
index 558479e19734747a6fcf9cb52771692dd4cbe4e4..77dff80669a0fab181e36108e7db4f7ef14c0ac5 100644 (file)
@@ -23,9 +23,9 @@
  */
 
 #ifndef USB_DRIVER_H
-#define USB_DRIVER_H
+#    define USB_DRIVER_H
 
-#include "hal_usb_cdc.h"
+#    include "hal_usb_cdc.h"
 
 /*===========================================================================*/
 /* Driver constants.                                                         */
@@ -35,9 +35,9 @@
 /* Derived constants and error checks.                                       */
 /*===========================================================================*/
 
-#if HAL_USE_USB == FALSE
-#error "The USB Driver requires HAL_USE_USB"
-#endif
+#    if HAL_USE_USB == FALSE
+#        error "The USB Driver requires HAL_USE_USB"
+#    endif
 
 /*===========================================================================*/
 /* Driver data structures and types.                                         */
@@ -47,9 +47,9 @@
  * @brief Driver state machine possible states.
  */
 typedef enum {
-  QMKUSB_UNINIT = 0,                   /**< Not initialized.                   */
-  QMKUSB_STOP = 1,                     /**< Stopped.                           */
-  QMKUSB_READY = 2                     /**< Ready.                             */
+    QMKUSB_UNINIT = 0, /**< Not initialized.                   */
+    QMKUSB_STOP   = 1, /**< Stopped.                           */
+    QMKUSB_READY  = 2  /**< Ready.                             */
 } qmkusbstate_t;
 
 /**
@@ -63,72 +63,70 @@ typedef struct QMKUSBDriver QMKUSBDriver;
  *          in order to configure and start the driver operations.
  */
 typedef struct {
-  /**
-   * @brief   USB driver to use.
-   */
-  USBDriver                 *usbp;
-  /**
-   * @brief   Bulk IN endpoint used for outgoing data transfer.
-   */
-  usbep_t                   bulk_in;
-  /**
-   * @brief   Bulk OUT endpoint used for incoming data transfer.
-   */
-  usbep_t                   bulk_out;
-  /**
-   * @brief   Interrupt IN endpoint used for notifications.
-   * @note    If set to zero then the INT endpoint is assumed to be not
-   *          present, USB descriptors must be changed accordingly.
-   */
-  usbep_t                   int_in;
-
-  /**
-   * @brief The number of buffers in the queues
-   */
-  size_t                    in_buffers;
-  size_t                    out_buffers;
-
-  /**
-   * @brief The size of each buffer in the queue, typically the same as the endpoint size
-   */
-  size_t                    in_size;
-  size_t                    out_size;
-
-  /**
-   * @brief Always send full buffers in_size (the rest is filled with zeroes)
-   */
-  bool                      fixed_size;
-
-  /* Input buffer
-   * @note needs to be initialized with a memory buffer of the right size
-   */
-  uint8_t*                  ib;
-  /* Output buffer
-   * @note needs to be initialized with a memory buffer of the right size
-   */
-  uint8_t*                  ob;
+    /**
+     * @brief   USB driver to use.
+     */
+    USBDriver *usbp;
+    /**
+     * @brief   Bulk IN endpoint used for outgoing data transfer.
+     */
+    usbep_t bulk_in;
+    /**
+     * @brief   Bulk OUT endpoint used for incoming data transfer.
+     */
+    usbep_t bulk_out;
+    /**
+     * @brief   Interrupt IN endpoint used for notifications.
+     * @note    If set to zero then the INT endpoint is assumed to be not
+     *          present, USB descriptors must be changed accordingly.
+     */
+    usbep_t int_in;
+
+    /**
+     * @brief The number of buffers in the queues
+     */
+    size_t in_buffers;
+    size_t out_buffers;
+
+    /**
+     * @brief The size of each buffer in the queue, typically the same as the endpoint size
+     */
+    size_t in_size;
+    size_t out_size;
+
+    /**
+     * @brief Always send full buffers in_size (the rest is filled with zeroes)
+     */
+    bool fixed_size;
+
+    /* Input buffer
+     * @note needs to be initialized with a memory buffer of the right size
+     */
+    uint8_t *ib;
+    /* Output buffer
+     * @note needs to be initialized with a memory buffer of the right size
+     */
+    uint8_t *ob;
 } QMKUSBConfig;
 
 /**
  * @brief   @p SerialDriver specific data.
  */
-#define _qmk_usb_driver_data                                                \
-  _base_asynchronous_channel_data                                           \
-  /* Driver state.*/                                                        \
-  qmkusbstate_t             state;                                          \
-  /* Input buffers queue.*/                                                 \
-  input_buffers_queue_t     ibqueue;                                        \
-  /* Output queue.*/                                                        \
-  output_buffers_queue_t    obqueue;                                        \
-  /* End of the mandatory fields.*/                                         \
-  /* Current configuration data.*/                                          \
-  const QMKUSBConfig     *config;
+#    define _qmk_usb_driver_data                           \
+        _base_asynchronous_channel_data /* Driver state.*/ \
+            qmkusbstate_t state;                           \
+        /* Input buffers queue.*/                          \
+        input_buffers_queue_t ibqueue;                     \
+        /* Output queue.*/                                 \
+        output_buffers_queue_t obqueue;                    \
+        /* End of the mandatory fields.*/                  \
+        /* Current configuration data.*/                   \
+        const QMKUSBConfig *config;
 
 /**
  * @brief   @p SerialUSBDriver specific methods.
  */
-#define _qmk_usb_driver_methods                                             \
-  _base_asynchronous_channel_methods
+#    define _qmk_usb_driver_methods _base_asynchronous_channel_methods
 
 /**
  * @extends BaseAsynchronousChannelVMT
@@ -136,7 +134,7 @@ typedef struct {
  * @brief   @p SerialDriver virtual methods table.
  */
 struct QMKUSBDriverVMT {
-  _qmk_usb_driver_methods
+    _qmk_usb_driver_methods
 };
 
 /**
@@ -147,9 +145,9 @@ struct QMKUSBDriverVMT {
  *          I/O queues.
  */
 struct QMKUSBDriver {
-  /** @brief Virtual Methods Table.*/
-  const struct QMKUSBDriverVMT *vmt;
-  _qmk_usb_driver_data
+    /** @brief Virtual Methods Table.*/
+    const struct QMKUSBDriverVMT *vmt;
+    _qmk_usb_driver_data
 };
 
 /*===========================================================================*/
@@ -160,24 +158,24 @@ struct QMKUSBDriver {
 /* External declarations.                                                    */
 /*===========================================================================*/
 
-#ifdef __cplusplus
+#    ifdef __cplusplus
 extern "C" {
-#endif
-  void qmkusbInit(void);
-  void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig * config);
-  void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
-  void qmkusbStop(QMKUSBDriver *qmkusbp);
-  void qmkusbSuspendHookI(QMKUSBDriver *qmkusbp);
-  void qmkusbWakeupHookI(QMKUSBDriver *qmkusbp);
-  void qmkusbConfigureHookI(QMKUSBDriver *qmkusbp);
-  bool qmkusbRequestsHook(USBDriver *usbp);
-  void qmkusbSOFHookI(QMKUSBDriver *qmkusbp);
-  void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep);
-  void qmkusbDataReceived(USBDriver *usbp, usbep_t ep);
-  void qmkusbInterruptTransmitted(USBDriver *usbp, usbep_t ep);
-#ifdef __cplusplus
+#    endif
+void qmkusbInit(void);
+void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
+void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
+void qmkusbStop(QMKUSBDriver *qmkusbp);
+void qmkusbSuspendHookI(QMKUSBDriver *qmkusbp);
+void qmkusbWakeupHookI(QMKUSBDriver *qmkusbp);
+void qmkusbConfigureHookI(QMKUSBDriver *qmkusbp);
+bool qmkusbRequestsHook(USBDriver *usbp);
+void qmkusbSOFHookI(QMKUSBDriver *qmkusbp);
+void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep);
+void qmkusbDataReceived(USBDriver *usbp, usbep_t ep);
+void qmkusbInterruptTransmitted(USBDriver *usbp, usbep_t ep);
+#    ifdef __cplusplus
 }
-#endif
+#    endif
 
 #endif /* USB_DRIVER_H */
 
index 8223d9722867749846301276c088453c2c799bf3..c8a6bbb43f0db231483ad2b9810e999056283660 100644 (file)
 #include "debug.h"
 #include "suspend.h"
 #ifdef SLEEP_LED_ENABLE
-#include "sleep_led.h"
-#include "led.h"
+#    include "sleep_led.h"
+#    include "led.h"
 #endif
 #include "wait.h"
 #include "usb_descriptor.h"
 #include "usb_driver.h"
 
 #ifdef NKRO_ENABLE
-  #include "keycode_config.h"
+#    include "keycode_config.h"
 
-  extern keymap_config_t keymap_config;
+extern keymap_config_t keymap_config;
 #endif
 
 /* ---------------------------------------------------------
  */
 
 #ifndef usb_lld_connect_bus
-  #define usb_lld_connect_bus(usbp)
+#    define usb_lld_connect_bus(usbp)
 #endif
 
 #ifndef usb_lld_disconnect_bus
-  #define usb_lld_disconnect_bus(usbp)
+#    define usb_lld_disconnect_bus(usbp)
 #endif
 
-uint8_t keyboard_idle __attribute__((aligned(2))) = 0;
-uint8_t keyboard_protocol __attribute__((aligned(2))) = 1;
-uint16_t keyboard_led_stats __attribute__((aligned(2))) = 0;
-volatile uint16_t keyboard_idle_count = 0;
+uint8_t                keyboard_idle __attribute__((aligned(2)))      = 0;
+uint8_t                keyboard_protocol __attribute__((aligned(2)))  = 1;
+uint16_t               keyboard_led_stats __attribute__((aligned(2))) = 0;
+volatile uint16_t      keyboard_idle_count                            = 0;
 static virtual_timer_t keyboard_idle_timer;
-static void keyboard_idle_timer_cb(void *arg);
+static void            keyboard_idle_timer_cb(void *arg);
 
 report_keyboard_t keyboard_report_sent = {{0}};
 #ifdef MOUSE_ENABLE
@@ -84,15 +84,15 @@ uint8_t extra_report_blank[3] = {0};
  * Returns the proper descriptor
  */
 static const USBDescriptor *usb_get_descriptor_cb(USBDriver *usbp, uint8_t dtype, uint8_t dindex, uint16_t wIndex) {
-  (void)usbp;
-  static USBDescriptor desc;
-  uint16_t wValue = ((uint16_t)dtype << 8) | dindex;
-  desc.ud_string = NULL;
-  desc.ud_size = get_usb_descriptor(wValue, wIndex, (const void** const)&desc.ud_string);
-  if (desc.ud_string == NULL)
-    return NULL;
-  else
-    return &desc;
+    (void)usbp;
+    static USBDescriptor desc;
+    uint16_t             wValue = ((uint16_t)dtype << 8) | dindex;
+    desc.ud_string              = NULL;
+    desc.ud_size                = get_usb_descriptor(wValue, wIndex, (const void **const) & desc.ud_string);
+    if (desc.ud_string == NULL)
+        return NULL;
+    else
+        return &desc;
 }
 
 #ifndef KEYBOARD_SHARED_EP
@@ -100,16 +100,16 @@ static const USBDescriptor *usb_get_descriptor_cb(USBDriver *usbp, uint8_t dtype
 static USBInEndpointState kbd_ep_state;
 /* keyboard endpoint initialization structure (IN) */
 static const USBEndpointConfig kbd_ep_config = {
-  USB_EP_MODE_TYPE_INTR,        /* Interrupt EP */
-  NULL,                         /* SETUP packet notification callback */
-  kbd_in_cb,                    /* IN notification callback */
-  NULL,                         /* OUT notification callback */
-  KEYBOARD_EPSIZE,              /* IN maximum packet size */
-  0,                            /* OUT maximum packet size */
-  &kbd_ep_state,                /* IN Endpoint state */
-  NULL,                         /* OUT endpoint state */
-  2,                            /* IN multiplier */
-  NULL                          /* SETUP buffer (not a SETUP endpoint) */
+    USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
+    NULL,                  /* SETUP packet notification callback */
+    kbd_in_cb,             /* IN notification callback */
+    NULL,                  /* OUT notification callback */
+    KEYBOARD_EPSIZE,       /* IN maximum packet size */
+    0,                     /* OUT maximum packet size */
+    &kbd_ep_state,         /* IN Endpoint state */
+    NULL,                  /* OUT endpoint state */
+    2,                     /* IN multiplier */
+    NULL                   /* SETUP buffer (not a SETUP endpoint) */
 };
 #endif
 
@@ -119,16 +119,16 @@ static USBInEndpointState mouse_ep_state;
 
 /* mouse endpoint initialization structure (IN) */
 static const USBEndpointConfig mouse_ep_config = {
-  USB_EP_MODE_TYPE_INTR,        /* Interrupt EP */
-  NULL,                         /* SETUP packet notification callback */
-  mouse_in_cb,                  /* IN notification callback */
-  NULL,                         /* OUT notification callback */
-  MOUSE_EPSIZE,                 /* IN maximum packet size */
-  0,                            /* OUT maximum packet size */
-  &mouse_ep_state,              /* IN Endpoint state */
-  NULL,                         /* OUT endpoint state */
-  2,                            /* IN multiplier */
-  NULL                          /* SETUP buffer (not a SETUP endpoint) */
+    USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
+    NULL,                  /* SETUP packet notification callback */
+    mouse_in_cb,           /* IN notification callback */
+    NULL,                  /* OUT notification callback */
+    MOUSE_EPSIZE,          /* IN maximum packet size */
+    0,                     /* OUT maximum packet size */
+    &mouse_ep_state,       /* IN Endpoint state */
+    NULL,                  /* OUT endpoint state */
+    2,                     /* IN multiplier */
+    NULL                   /* SETUP buffer (not a SETUP endpoint) */
 };
 #endif
 
@@ -138,145 +138,141 @@ static USBInEndpointState shared_ep_state;
 
 /* shared endpoint initialization structure (IN) */
 static const USBEndpointConfig shared_ep_config = {
-  USB_EP_MODE_TYPE_INTR,        /* Interrupt EP */
-  NULL,                         /* SETUP packet notification callback */
-  shared_in_cb,                 /* IN notification callback */
-  NULL,                         /* OUT notification callback */
-  SHARED_EPSIZE,                /* IN maximum packet size */
-  0,                            /* OUT maximum packet size */
-  &shared_ep_state,             /* IN Endpoint state */
-  NULL,                         /* OUT endpoint state */
-  2,                            /* IN multiplier */
-  NULL                          /* SETUP buffer (not a SETUP endpoint) */
+    USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
+    NULL,                  /* SETUP packet notification callback */
+    shared_in_cb,          /* IN notification callback */
+    NULL,                  /* OUT notification callback */
+    SHARED_EPSIZE,         /* IN maximum packet size */
+    0,                     /* OUT maximum packet size */
+    &shared_ep_state,      /* IN Endpoint state */
+    NULL,                  /* OUT endpoint state */
+    2,                     /* IN multiplier */
+    NULL                   /* SETUP buffer (not a SETUP endpoint) */
 };
 #endif
 
 typedef struct {
-  size_t queue_capacity_in;
-  size_t queue_capacity_out;
-  USBInEndpointState in_ep_state;
-  USBOutEndpointState out_ep_state;
-  USBInEndpointState int_ep_state;
-  USBEndpointConfig in_ep_config;
-  USBEndpointConfig out_ep_config;
-  USBEndpointConfig int_ep_config;
-  const QMKUSBConfig config;
-  QMKUSBDriver driver;
+    size_t              queue_capacity_in;
+    size_t              queue_capacity_out;
+    USBInEndpointState  in_ep_state;
+    USBOutEndpointState out_ep_state;
+    USBInEndpointState  int_ep_state;
+    USBEndpointConfig   in_ep_config;
+    USBEndpointConfig   out_ep_config;
+    USBEndpointConfig   int_ep_config;
+    const QMKUSBConfig  config;
+    QMKUSBDriver        driver;
 } usb_driver_config_t;
 
-#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) { \
-  .queue_capacity_in = stream##_IN_CAPACITY, \
-  .queue_capacity_out = stream##_OUT_CAPACITY, \
-  .in_ep_config = { \
-    .ep_mode = stream##_IN_MODE, \
-    .setup_cb = NULL, \
-    .in_cb = qmkusbDataTransmitted, \
-    .out_cb = NULL, \
-    .in_maxsize = stream##_EPSIZE, \
-    .out_maxsize = 0, \
-    /* The pointer to the states will be filled during initialization */ \
-    .in_state = NULL, \
-    .out_state = NULL, \
-    .ep_buffers = 2, \
-    .setup_buf = NULL \
-  }, \
-  .out_ep_config = { \
-    .ep_mode = stream##_OUT_MODE, \
-    .setup_cb = NULL, \
-    .in_cb = NULL, \
-    .out_cb = qmkusbDataReceived, \
-    .in_maxsize = 0, \
-    .out_maxsize = stream##_EPSIZE, \
-    /* The pointer to the states will be filled during initialization */ \
-    .in_state = NULL, \
-    .out_state = NULL, \
-    .ep_buffers = 2, \
-    .setup_buf = NULL, \
-  }, \
-  .int_ep_config = { \
-    .ep_mode = USB_EP_MODE_TYPE_INTR, \
-    .setup_cb = NULL, \
-    .in_cb = qmkusbInterruptTransmitted, \
-    .out_cb = NULL, \
-    .in_maxsize = CDC_NOTIFICATION_EPSIZE, \
-    .out_maxsize = 0, \
-    /* The pointer to the states will be filled during initialization */ \
-    .in_state = NULL, \
-    .out_state = NULL, \
-    .ep_buffers = 2, \
-    .setup_buf = NULL, \
-  }, \
-  .config = { \
-    .usbp = &USB_DRIVER, \
-    .bulk_in = stream##_IN_EPNUM, \
-    .bulk_out = stream##_OUT_EPNUM, \
-    .int_in = notification, \
-    .in_buffers = stream##_IN_CAPACITY, \
-    .out_buffers = stream##_OUT_CAPACITY, \
-    .in_size = stream##_EPSIZE, \
-    .out_size = stream##_EPSIZE, \
-    .fixed_size = fixedsize, \
-    .ib = (uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]) {}, \
-    .ob = (uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY,stream##_EPSIZE)]) {}, \
-  } \
-}
+#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize)                                                       \
+    {                                                                                                                \
+        .queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY,                      \
+        .in_ep_config = {.ep_mode     = stream##_IN_MODE,                                                            \
+                         .setup_cb    = NULL,                                                                        \
+                         .in_cb       = qmkusbDataTransmitted,                                                       \
+                         .out_cb      = NULL,                                                                        \
+                         .in_maxsize  = stream##_EPSIZE,                                                             \
+                         .out_maxsize = 0, /* The pointer to the states will be filled during initialization */      \
+                         .in_state    = NULL,                                                                        \
+                         .out_state   = NULL,                                                                        \
+                         .ep_buffers  = 2,                                                                           \
+                         .setup_buf   = NULL},                                                                         \
+        .out_ep_config =                                                                                             \
+            {                                                                                                        \
+                .ep_mode     = stream##_OUT_MODE,                                                                    \
+                .setup_cb    = NULL,                                                                                 \
+                .in_cb       = NULL,                                                                                 \
+                .out_cb      = qmkusbDataReceived,                                                                   \
+                .in_maxsize  = 0,                                                                                    \
+                .out_maxsize = stream##_EPSIZE, /* The pointer to the states will be filled during initialization */ \
+                .in_state    = NULL,                                                                                 \
+                .out_state   = NULL,                                                                                 \
+                .ep_buffers  = 2,                                                                                    \
+                .setup_buf   = NULL,                                                                                 \
+            },                                                                                                       \
+        .int_ep_config =                                                                                             \
+            {                                                                                                        \
+                .ep_mode     = USB_EP_MODE_TYPE_INTR,                                                                \
+                .setup_cb    = NULL,                                                                                 \
+                .in_cb       = qmkusbInterruptTransmitted,                                                           \
+                .out_cb      = NULL,                                                                                 \
+                .in_maxsize  = CDC_NOTIFICATION_EPSIZE,                                                              \
+                .out_maxsize = 0, /* The pointer to the states will be filled during initialization */               \
+                .in_state    = NULL,                                                                                 \
+                .out_state   = NULL,                                                                                 \
+                .ep_buffers  = 2,                                                                                    \
+                .setup_buf   = NULL,                                                                                 \
+            },                                                                                                       \
+        .config = {                                                                                                  \
+            .usbp        = &USB_DRIVER,                                                                              \
+            .bulk_in     = stream##_IN_EPNUM,                                                                        \
+            .bulk_out    = stream##_OUT_EPNUM,                                                                       \
+            .int_in      = notification,                                                                             \
+            .in_buffers  = stream##_IN_CAPACITY,                                                                     \
+            .out_buffers = stream##_OUT_CAPACITY,                                                                    \
+            .in_size     = stream##_EPSIZE,                                                                          \
+            .out_size    = stream##_EPSIZE,                                                                          \
+            .fixed_size  = fixedsize,                                                                                \
+            .ib          = (uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){},                       \
+            .ob          = (uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){},                      \
+        }                                                                                                            \
+    }
 
 typedef struct {
-  union {
-    struct {
+    union {
+        struct {
 #ifdef CONSOLE_ENABLE
-      usb_driver_config_t console_driver;
+            usb_driver_config_t console_driver;
 #endif
 #ifdef RAW_ENABLE
-      usb_driver_config_t raw_driver;
+            usb_driver_config_t raw_driver;
 #endif
 #ifdef MIDI_ENABLE
-      usb_driver_config_t midi_driver;
+            usb_driver_config_t midi_driver;
 #endif
 #ifdef VIRTSER_ENABLE
-      usb_driver_config_t serial_driver;
+            usb_driver_config_t serial_driver;
 #endif
+        };
+        usb_driver_config_t array[0];
     };
-    usb_driver_config_t array[0];
-  };
 } usb_driver_configs_t;
 
 static usb_driver_configs_t drivers = {
 #ifdef CONSOLE_ENABLE
-  #define CONSOLE_IN_CAPACITY 4
-  #define CONSOLE_OUT_CAPACITY 4
-  #define CONSOLE_IN_MODE USB_EP_MODE_TYPE_INTR
-  #define CONSOLE_OUT_MODE USB_EP_MODE_TYPE_INTR
-  .console_driver = QMK_USB_DRIVER_CONFIG(CONSOLE, 0, true),
+#    define CONSOLE_IN_CAPACITY 4
+#    define CONSOLE_OUT_CAPACITY 4
+#    define CONSOLE_IN_MODE USB_EP_MODE_TYPE_INTR
+#    define CONSOLE_OUT_MODE USB_EP_MODE_TYPE_INTR
+    .console_driver = QMK_USB_DRIVER_CONFIG(CONSOLE, 0, true),
 #endif
 #ifdef RAW_ENABLE
-  #define RAW_IN_CAPACITY 4
-  #define RAW_OUT_CAPACITY 4
-  #define RAW_IN_MODE USB_EP_MODE_TYPE_INTR
-  #define RAW_OUT_MODE USB_EP_MODE_TYPE_INTR
-  .raw_driver = QMK_USB_DRIVER_CONFIG(RAW, 0, false),
+#    define RAW_IN_CAPACITY 4
+#    define RAW_OUT_CAPACITY 4
+#    define RAW_IN_MODE USB_EP_MODE_TYPE_INTR
+#    define RAW_OUT_MODE USB_EP_MODE_TYPE_INTR
+    .raw_driver = QMK_USB_DRIVER_CONFIG(RAW, 0, false),
 #endif
 
 #ifdef MIDI_ENABLE
-  #define MIDI_STREAM_IN_CAPACITY 4
-  #define MIDI_STREAM_OUT_CAPACITY 4
-  #define MIDI_STREAM_IN_MODE USB_EP_MODE_TYPE_BULK
-  #define MIDI_STREAM_OUT_MODE USB_EP_MODE_TYPE_BULK
-  .midi_driver = QMK_USB_DRIVER_CONFIG(MIDI_STREAM, 0, false),
+#    define MIDI_STREAM_IN_CAPACITY 4
+#    define MIDI_STREAM_OUT_CAPACITY 4
+#    define MIDI_STREAM_IN_MODE USB_EP_MODE_TYPE_BULK
+#    define MIDI_STREAM_OUT_MODE USB_EP_MODE_TYPE_BULK
+    .midi_driver = QMK_USB_DRIVER_CONFIG(MIDI_STREAM, 0, false),
 #endif
 
 #ifdef VIRTSER_ENABLE
-  #define CDC_IN_CAPACITY 4
-  #define CDC_OUT_CAPACITY 4
-  #define CDC_IN_MODE USB_EP_MODE_TYPE_BULK
-  #define CDC_OUT_MODE USB_EP_MODE_TYPE_BULK
-  .serial_driver = QMK_USB_DRIVER_CONFIG(CDC, CDC_NOTIFICATION_EPNUM, false),
+#    define CDC_IN_CAPACITY 4
+#    define CDC_OUT_CAPACITY 4
+#    define CDC_IN_MODE USB_EP_MODE_TYPE_BULK
+#    define CDC_OUT_MODE USB_EP_MODE_TYPE_BULK
+    .serial_driver = QMK_USB_DRIVER_CONFIG(CDC, CDC_NOTIFICATION_EPNUM, false),
 #endif
 };
 
 #define NUM_USB_DRIVERS (sizeof(drivers) / sizeof(usb_driver_config_t))
 
-
 /* ---------------------------------------------------------
  *                  USB driver functions
  * ---------------------------------------------------------
@@ -285,77 +281,77 @@ static usb_driver_configs_t drivers = {
 /* Handles the USB driver global events
  * TODO: maybe disable some things when connection is lost? */
 static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
-  switch(event) {
-  case USB_EVENT_ADDRESS:
-    return;
+    switch (event) {
+        case USB_EVENT_ADDRESS:
+            return;
 
-  case USB_EVENT_CONFIGURED:
-    osalSysLockFromISR();
-    /* Enable the endpoints specified into the configuration. */
+        case USB_EVENT_CONFIGURED:
+            osalSysLockFromISR();
+            /* Enable the endpoints specified into the configuration. */
 #ifndef KEYBOARD_SHARED_EP
-    usbInitEndpointI(usbp, KEYBOARD_IN_EPNUM, &kbd_ep_config);
+            usbInitEndpointI(usbp, KEYBOARD_IN_EPNUM, &kbd_ep_config);
 #endif
 #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
-    usbInitEndpointI(usbp, MOUSE_IN_EPNUM, &mouse_ep_config);
+            usbInitEndpointI(usbp, MOUSE_IN_EPNUM, &mouse_ep_config);
 #endif
 #ifdef SHARED_EP_ENABLE
-    usbInitEndpointI(usbp, SHARED_IN_EPNUM, &shared_ep_config);
+            usbInitEndpointI(usbp, SHARED_IN_EPNUM, &shared_ep_config);
 #endif
-    for (int i=0;i<NUM_USB_DRIVERS;i++) {
-      usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].in_ep_config);
-      usbInitEndpointI(usbp, drivers.array[i].config.bulk_out, &drivers.array[i].out_ep_config);
-      if (drivers.array[i].config.int_in) {
-        usbInitEndpointI(usbp, drivers.array[i].config.int_in, &drivers.array[i].int_ep_config);
-      }
-      qmkusbConfigureHookI(&drivers.array[i].driver);
-    }
-    osalSysUnlockFromISR();
-    return;
-  case USB_EVENT_SUSPEND:
+            for (int i = 0; i < NUM_USB_DRIVERS; i++) {
+                usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].in_ep_config);
+                usbInitEndpointI(usbp, drivers.array[i].config.bulk_out, &drivers.array[i].out_ep_config);
+                if (drivers.array[i].config.int_in) {
+                    usbInitEndpointI(usbp, drivers.array[i].config.int_in, &drivers.array[i].int_ep_config);
+                }
+                qmkusbConfigureHookI(&drivers.array[i].driver);
+            }
+            osalSysUnlockFromISR();
+            return;
+        case USB_EVENT_SUSPEND:
 #ifdef SLEEP_LED_ENABLE
-    sleep_led_enable();
-#endif /* SLEEP_LED_ENABLE */
-    /* Falls into.*/
-  case USB_EVENT_UNCONFIGURED:
-    /* Falls into.*/
-  case USB_EVENT_RESET:
-      for (int i=0;i<NUM_USB_DRIVERS;i++) {
-        chSysLockFromISR();
-        /* Disconnection event on suspend.*/
-        qmkusbSuspendHookI(&drivers.array[i].driver);
-        chSysUnlockFromISR();
-      }
-    return;
-
-  case USB_EVENT_WAKEUP:
-    //TODO: from ISR! print("[W]");
-      for (int i=0;i<NUM_USB_DRIVERS;i++) {
-        chSysLockFromISR();
-        /* Disconnection event on suspend.*/
-        qmkusbWakeupHookI(&drivers.array[i].driver);
-        chSysUnlockFromISR();
-      }
-    suspend_wakeup_init();
+            sleep_led_enable();
+#endif      /* SLEEP_LED_ENABLE */
+            /* Falls into.*/
+        case USB_EVENT_UNCONFIGURED:
+            /* Falls into.*/
+        case USB_EVENT_RESET:
+            for (int i = 0; i < NUM_USB_DRIVERS; i++) {
+                chSysLockFromISR();
+                /* Disconnection event on suspend.*/
+                qmkusbSuspendHookI(&drivers.array[i].driver);
+                chSysUnlockFromISR();
+            }
+            return;
+
+        case USB_EVENT_WAKEUP:
+            // TODO: from ISR! print("[W]");
+            for (int i = 0; i < NUM_USB_DRIVERS; i++) {
+                chSysLockFromISR();
+                /* Disconnection event on suspend.*/
+                qmkusbWakeupHookI(&drivers.array[i].driver);
+                chSysUnlockFromISR();
+            }
+            suspend_wakeup_init();
 #ifdef SLEEP_LED_ENABLE
-    sleep_led_disable();
-    // NOTE: converters may not accept this
-    led_set(host_keyboard_leds());
+            sleep_led_disable();
+            // NOTE: converters may not accept this
+            led_set(host_keyboard_leds());
 #endif /* SLEEP_LED_ENABLE */
-    return;
+            return;
 
-  case USB_EVENT_STALLED:
-    return;
-  }
+        case USB_EVENT_STALLED:
+            return;
+    }
 }
 
 /* Function used locally in os/hal/src/usb.c for getting descriptors
  * need it here for HID descriptor */
 static uint16_t get_hword(uint8_t *p) {
-  uint16_t hw;
+    uint16_t hw;
 
-  hw = (uint16_t)*p++;
-  hw |= (uint16_t)*p << 8U;
-  return hw;
+    hw = (uint16_t)*p++;
+    hw |= (uint16_t)*p << 8U;
+    return hw;
 }
 
 /*
@@ -373,197 +369,193 @@ static uint16_t get_hword(uint8_t *p) {
 
 #ifdef SHARED_EP_ENABLE
 static uint8_t set_report_buf[2] __attribute__((aligned(2)));
-static void set_led_transfer_cb(USBDriver *usbp) {
-  if ((set_report_buf[0] == REPORT_ID_KEYBOARD) ||
-      (set_report_buf[0] == REPORT_ID_NKRO)) {
-    keyboard_led_stats = set_report_buf[1];
-  }
+static void    set_led_transfer_cb(USBDriver *usbp) {
+    if ((set_report_buf[0] == REPORT_ID_KEYBOARD) || (set_report_buf[0] == REPORT_ID_NKRO)) {
+        keyboard_led_stats = set_report_buf[1];
+    }
 }
 #endif
 
 /* Callback for SETUP request on the endpoint 0 (control) */
 static bool usb_request_hook_cb(USBDriver *usbp) {
-  const USBDescriptor *dp;
-  int has_report_id;
-
-  /* usbp->setup fields:
-   *  0:   bmRequestType (bitmask)
-   *  1:   bRequest
-   *  2,3: (LSB,MSB) wValue
-   *  4,5: (LSB,MSB) wIndex
-   *  6,7: (LSB,MSB) wLength (number of bytes to transfer if there is a data phase) */
-
-  /* Handle HID class specific requests */
-  if(((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) &&
-     ((usbp->setup[0] & USB_RTYPE_RECIPIENT_MASK) == USB_RTYPE_RECIPIENT_INTERFACE)) {
-    switch(usbp->setup[0] & USB_RTYPE_DIR_MASK) {
-    case USB_RTYPE_DIR_DEV2HOST:
-      switch(usbp->setup[1]) {   /* bRequest */
-      case HID_GET_REPORT:
-        switch(usbp->setup[4]) {     /* LSB(wIndex) (check MSB==0?) */
-        case KEYBOARD_INTERFACE:
-          usbSetupTransfer(usbp, (uint8_t *)&keyboard_report_sent, sizeof(keyboard_report_sent), NULL);
-          return TRUE;
-          break;
+    const USBDescriptor *dp;
+    int                  has_report_id;
+
+    /* usbp->setup fields:
+     *  0:   bmRequestType (bitmask)
+     *  1:   bRequest
+     *  2,3: (LSB,MSB) wValue
+     *  4,5: (LSB,MSB) wIndex
+     *  6,7: (LSB,MSB) wLength (number of bytes to transfer if there is a data phase) */
+
+    /* Handle HID class specific requests */
+    if (((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) && ((usbp->setup[0] & USB_RTYPE_RECIPIENT_MASK) == USB_RTYPE_RECIPIENT_INTERFACE)) {
+        switch (usbp->setup[0] & USB_RTYPE_DIR_MASK) {
+            case USB_RTYPE_DIR_DEV2HOST:
+                switch (usbp->setup[1]) { /* bRequest */
+                    case HID_GET_REPORT:
+                        switch (usbp->setup[4]) { /* LSB(wIndex) (check MSB==0?) */
+                            case KEYBOARD_INTERFACE:
+                                usbSetupTransfer(usbp, (uint8_t *)&keyboard_report_sent, sizeof(keyboard_report_sent), NULL);
+                                return TRUE;
+                                break;
 
 #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
-        case MOUSE_INTERFACE:
-          usbSetupTransfer(usbp, (uint8_t *)&mouse_report_blank, sizeof(mouse_report_blank), NULL);
-          return TRUE;
-          break;
+                            case MOUSE_INTERFACE:
+                                usbSetupTransfer(usbp, (uint8_t *)&mouse_report_blank, sizeof(mouse_report_blank), NULL);
+                                return TRUE;
+                                break;
 #endif
 
-        default:
-          usbSetupTransfer(usbp, NULL, 0, NULL);
-          return TRUE;
-          break;
-        }
-        break;
-
-      case HID_GET_PROTOCOL:
-        if((usbp->setup[4] == KEYBOARD_INTERFACE) && (usbp->setup[5] == 0)) {   /* wIndex */
-          usbSetupTransfer(usbp, &keyboard_protocol, 1, NULL);
-          return TRUE;
-        }
-        break;
-
-      case HID_GET_IDLE:
-        usbSetupTransfer(usbp, &keyboard_idle, 1, NULL);
-        return TRUE;
-        break;
-      }
-      break;
-
-    case USB_RTYPE_DIR_HOST2DEV:
-      switch(usbp->setup[1]) {   /* bRequest */
-      case HID_SET_REPORT:
-        switch(usbp->setup[4]) {       /* LSB(wIndex) (check MSB==0 and wLength==1?) */
-        case KEYBOARD_INTERFACE:
+                            default:
+                                usbSetupTransfer(usbp, NULL, 0, NULL);
+                                return TRUE;
+                                break;
+                        }
+                        break;
+
+                    case HID_GET_PROTOCOL:
+                        if ((usbp->setup[4] == KEYBOARD_INTERFACE) && (usbp->setup[5] == 0)) { /* wIndex */
+                            usbSetupTransfer(usbp, &keyboard_protocol, 1, NULL);
+                            return TRUE;
+                        }
+                        break;
+
+                    case HID_GET_IDLE:
+                        usbSetupTransfer(usbp, &keyboard_idle, 1, NULL);
+                        return TRUE;
+                        break;
+                }
+                break;
+
+            case USB_RTYPE_DIR_HOST2DEV:
+                switch (usbp->setup[1]) { /* bRequest */
+                    case HID_SET_REPORT:
+                        switch (usbp->setup[4]) { /* LSB(wIndex) (check MSB==0 and wLength==1?) */
+                            case KEYBOARD_INTERFACE:
 #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
-        case SHARED_INTERFACE:
+                            case SHARED_INTERFACE:
 #endif
-        /* keyboard_led_stats = <read byte from next OUT report>
-         * keyboard_led_stats needs be word (or dword), otherwise we get an exception on F0 */
-          has_report_id = 0;
+                                /* keyboard_led_stats = <read byte from next OUT report>
+                                 * keyboard_led_stats needs be word (or dword), otherwise we get an exception on F0 */
+                                has_report_id = 0;
 #if defined(SHARED_EP_ENABLE)
-          if (usbp->setup[4] == SHARED_INTERFACE) {
-            has_report_id = 1;
-          }
+                                if (usbp->setup[4] == SHARED_INTERFACE) {
+                                    has_report_id = 1;
+                                }
 #endif
-          if (usbp->setup[4] == KEYBOARD_INTERFACE && !keyboard_protocol) {
-            has_report_id = 0;
-          }
-          if (has_report_id) {
-            usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb);
-          } else {
-            usbSetupTransfer(usbp, (uint8_t *)&keyboard_led_stats, 1, NULL);
-          }
-          return TRUE;
-          break;
-        }
-        break;
-
-      case HID_SET_PROTOCOL:
-        if((usbp->setup[4] == KEYBOARD_INTERFACE) && (usbp->setup[5] == 0)) {   /* wIndex */
-          keyboard_protocol = ((usbp->setup[2]) != 0x00);   /* LSB(wValue) */
+                                if (usbp->setup[4] == KEYBOARD_INTERFACE && !keyboard_protocol) {
+                                    has_report_id = 0;
+                                }
+                                if (has_report_id) {
+                                    usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb);
+                                } else {
+                                    usbSetupTransfer(usbp, (uint8_t *)&keyboard_led_stats, 1, NULL);
+                                }
+                                return TRUE;
+                                break;
+                        }
+                        break;
+
+                    case HID_SET_PROTOCOL:
+                        if ((usbp->setup[4] == KEYBOARD_INTERFACE) && (usbp->setup[5] == 0)) { /* wIndex */
+                            keyboard_protocol = ((usbp->setup[2]) != 0x00);                    /* LSB(wValue) */
 #ifdef NKRO_ENABLE
-          keymap_config.nkro = !!keyboard_protocol;
-          if(!keymap_config.nkro && keyboard_idle) {
-#else /* NKRO_ENABLE */
-          if(keyboard_idle) {
-#endif /* NKRO_ENABLE */
-          /* arm the idle timer if boot protocol & idle */
-            osalSysLockFromISR();
-            chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
-            osalSysUnlockFromISR();
-          }
-        }
-        usbSetupTransfer(usbp, NULL, 0, NULL);
-        return TRUE;
-        break;
-
-      case HID_SET_IDLE:
-        keyboard_idle = usbp->setup[3];     /* MSB(wValue) */
-        /* arm the timer */
+                            keymap_config.nkro = !!keyboard_protocol;
+                            if (!keymap_config.nkro && keyboard_idle) {
+#else                           /* NKRO_ENABLE */
+                            if (keyboard_idle) {
+#endif                          /* NKRO_ENABLE */
+                                /* arm the idle timer if boot protocol & idle */
+                                osalSysLockFromISR();
+                                chVTSetI(&keyboard_idle_timer, 4 * MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
+                                osalSysUnlockFromISR();
+                            }
+                        }
+                        usbSetupTransfer(usbp, NULL, 0, NULL);
+                        return TRUE;
+                        break;
+
+                    case HID_SET_IDLE:
+                        keyboard_idle = usbp->setup[3]; /* MSB(wValue) */
+                                                        /* arm the timer */
 #ifdef NKRO_ENABLE
-        if(!keymap_config.nkro && keyboard_idle) {
-#else /* NKRO_ENABLE */
-        if(keyboard_idle) {
+                        if (!keymap_config.nkro && keyboard_idle) {
+#else  /* NKRO_ENABLE */
+                        if (keyboard_idle) {
 #endif /* NKRO_ENABLE */
-          osalSysLockFromISR();
-          chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
-          osalSysUnlockFromISR();
+                            osalSysLockFromISR();
+                            chVTSetI(&keyboard_idle_timer, 4 * MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
+                            osalSysUnlockFromISR();
+                        }
+                        usbSetupTransfer(usbp, NULL, 0, NULL);
+                        return TRUE;
+                        break;
+                }
+                break;
         }
-        usbSetupTransfer(usbp, NULL, 0, NULL);
+    }
+
+    /* Handle the Get_Descriptor Request for HID class (not handled by the default hook) */
+    if ((usbp->setup[0] == 0x81) && (usbp->setup[1] == USB_REQ_GET_DESCRIPTOR)) {
+        dp = usbp->config->get_descriptor_cb(usbp, usbp->setup[3], usbp->setup[2], get_hword(&usbp->setup[4]));
+        if (dp == NULL) return FALSE;
+        usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL);
         return TRUE;
-        break;
-      }
-      break;
     }
-  }
-
-  /* Handle the Get_Descriptor Request for HID class (not handled by the default hook) */
-  if((usbp->setup[0] == 0x81) && (usbp->setup[1] == USB_REQ_GET_DESCRIPTOR)) {
-    dp = usbp->config->get_descriptor_cb(usbp, usbp->setup[3], usbp->setup[2], get_hword(&usbp->setup[4]));
-    if(dp == NULL)
-      return FALSE;
-    usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL);
-    return TRUE;
-  }
-
-  for (int i=0;i<NUM_USB_DRIVERS;i++) {
-    if (drivers.array[i].config.int_in) {
-      // NOTE: Assumes that we only have one serial driver
-      return qmkusbRequestsHook(usbp);
+
+    for (int i = 0; i < NUM_USB_DRIVERS; i++) {
+        if (drivers.array[i].config.int_in) {
+            // NOTE: Assumes that we only have one serial driver
+            return qmkusbRequestsHook(usbp);
+        }
     }
-  }
 
-  return FALSE;
+    return FALSE;
 }
 
 /* Start-of-frame callback */
 static void usb_sof_cb(USBDriver *usbp) {
-  kbd_sof_cb(usbp);
-  osalSysLockFromISR();
-  for (int i=0; i<NUM_USB_DRIVERS;i++) {
-    qmkusbSOFHookI(&drivers.array[i].driver);
-  }
-  osalSysUnlockFromISR();
+    kbd_sof_cb(usbp);
+    osalSysLockFromISR();
+    for (int i = 0; i < NUM_USB_DRIVERS; i++) {
+        qmkusbSOFHookI(&drivers.array[i].driver);
+    }
+    osalSysUnlockFromISR();
 }
 
-
 /* USB driver configuration */
 static const USBConfig usbcfg = {
-  usb_event_cb,                 /* USB events callback */
-  usb_get_descriptor_cb,        /* Device GET_DESCRIPTOR request callback */
-  usb_request_hook_cb,          /* Requests hook callback */
-  usb_sof_cb                    /* Start Of Frame callback */
+    usb_event_cb,          /* USB events callback */
+    usb_get_descriptor_cb, /* Device GET_DESCRIPTOR request callback */
+    usb_request_hook_cb,   /* Requests hook callback */
+    usb_sof_cb             /* Start Of Frame callback */
 };
 
 /*
  * Initialize the USB driver
  */
 void init_usb_driver(USBDriver *usbp) {
-  for (int i=0; i<NUM_USB_DRIVERS;i++) {
-    QMKUSBDriver* driver = &drivers.array[i].driver;
-    drivers.array[i].in_ep_config.in_state = &drivers.array[i].in_ep_state;
-    drivers.array[i].out_ep_config.out_state = &drivers.array[i].out_ep_state;
-    drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state;
-    qmkusbObjectInit(driver, &drivers.array[i].config);
-    qmkusbStart(driver, &drivers.array[i].config);
-  }
-
-  /*
-   * Activates the USB driver and then the USB bus pull-up on D+.
-   * Note, a delay is inserted in order to not have to disconnect the cable
-   * after a reset.
-   */
-  usbDisconnectBus(usbp);
-  wait_ms(1500);
-  usbStart(usbp, &usbcfg);
-  usbConnectBus(usbp);
-
-  chVTObjectInit(&keyboard_idle_timer);
+    for (int i = 0; i < NUM_USB_DRIVERS; i++) {
+        QMKUSBDriver *driver                     = &drivers.array[i].driver;
+        drivers.array[i].in_ep_config.in_state   = &drivers.array[i].in_ep_state;
+        drivers.array[i].out_ep_config.out_state = &drivers.array[i].out_ep_state;
+        drivers.array[i].int_ep_config.in_state  = &drivers.array[i].int_ep_state;
+        qmkusbObjectInit(driver, &drivers.array[i].config);
+        qmkusbStart(driver, &drivers.array[i].config);
+    }
+
+    /*
+     * Activates the USB driver and then the USB bus pull-up on D+.
+     * Note, a delay is inserted in order to not have to disconnect the cable
+     * after a reset.
+     */
+    usbDisconnectBus(usbp);
+    wait_ms(1500);
+    usbStart(usbp, &usbcfg);
+    usbConnectBus(usbp);
+
+    chVTObjectInit(&keyboard_idle_timer);
 }
 
 /* ---------------------------------------------------------
@@ -573,108 +565,104 @@ void init_usb_driver(USBDriver *usbp) {
 /* keyboard IN callback hander (a kbd report has made it IN) */
 #ifndef KEYBOARD_SHARED_EP
 void kbd_in_cb(USBDriver *usbp, usbep_t ep) {
-  /* STUB */
-  (void)usbp;
-  (void)ep;
+    /* STUB */
+    (void)usbp;
+    (void)ep;
 }
 #endif
 
 /* start-of-frame handler
  * TODO: i guess it would be better to re-implement using timers,
  *  so that this is not going to have to be checked every 1ms */
-void kbd_sof_cb(USBDriver *usbp) {
-  (void)usbp;
-}
+void kbd_sof_cb(USBDriver *usbp) { (void)usbp; }
 
 /* Idle requests timer code
  * callback (called from ISR, unlocked state) */
 static void keyboard_idle_timer_cb(void *arg) {
-  USBDriver *usbp = (USBDriver *)arg;
+    USBDriver *usbp = (USBDriver *)arg;
 
-  osalSysLockFromISR();
+    osalSysLockFromISR();
 
-  /* check that the states of things are as they're supposed to */
-  if(usbGetDriverStateI(usbp) != USB_ACTIVE) {
-    /* do not rearm the timer, should be enabled on IDLE request */
-    osalSysUnlockFromISR();
-    return;
-  }
+    /* check that the states of things are as they're supposed to */
+    if (usbGetDriverStateI(usbp) != USB_ACTIVE) {
+        /* do not rearm the timer, should be enabled on IDLE request */
+        osalSysUnlockFromISR();
+        return;
+    }
 
 #ifdef NKRO_ENABLE
-  if(!keymap_config.nkro && keyboard_idle && keyboard_protocol) {
-#else /* NKRO_ENABLE */
-  if(keyboard_idle && keyboard_protocol) {
+    if (!keymap_config.nkro && keyboard_idle && keyboard_protocol) {
+#else  /* NKRO_ENABLE */
+    if (keyboard_idle && keyboard_protocol) {
 #endif /* NKRO_ENABLE */
-    /* TODO: are we sure we want the KBD_ENDPOINT? */
-    if(!usbGetTransmitStatusI(usbp, KEYBOARD_IN_EPNUM)) {
-      usbStartTransmitI(usbp, KEYBOARD_IN_EPNUM, (uint8_t *)&keyboard_report_sent, KEYBOARD_EPSIZE);
+        /* TODO: are we sure we want the KBD_ENDPOINT? */
+        if (!usbGetTransmitStatusI(usbp, KEYBOARD_IN_EPNUM)) {
+            usbStartTransmitI(usbp, KEYBOARD_IN_EPNUM, (uint8_t *)&keyboard_report_sent, KEYBOARD_EPSIZE);
+        }
+        /* rearm the timer */
+        chVTSetI(&keyboard_idle_timer, 4 * MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
     }
-    /* rearm the timer */
-    chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
-  }
 
-  /* do not rearm the timer if the condition above fails
-   * it should be enabled again on either IDLE or SET_PROTOCOL requests */
-  osalSysUnlockFromISR();
+    /* do not rearm the timer if the condition above fails
+     * it should be enabled again on either IDLE or SET_PROTOCOL requests */
+    osalSysUnlockFromISR();
 }
 
 /* LED status */
-uint8_t keyboard_leds(void) {
-  return (uint8_t)(keyboard_led_stats & 0xFF);
-}
+uint8_t keyboard_leds(void) { return (uint8_t)(keyboard_led_stats & 0xFF); }
 
 /* prepare and start sending a report IN
  * not callable from ISR or locked state */
 void send_keyboard(report_keyboard_t *report) {
-  osalSysLock();
-  if(usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
-    osalSysUnlock();
-    return;
-  }
-  osalSysUnlock();
-
-#ifdef NKRO_ENABLE
-  if(keymap_config.nkro && keyboard_protocol) {  /* NKRO protocol */
-    /* need to wait until the previous packet has made it through */
-    /* can rewrite this using the synchronous API, then would wait
-     * until *after* the packet has been transmitted. I think
-     * this is more efficient */
-    /* busy wait, should be short and not very common */
     osalSysLock();
-    if(usbGetTransmitStatusI(&USB_DRIVER, SHARED_IN_EPNUM)) {
-      /* Need to either suspend, or loop and call unlock/lock during
-       * every iteration - otherwise the system will remain locked,
-       * no interrupts served, so USB not going through as well.
-       * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
-      osalThreadSuspendS(&(&USB_DRIVER)->epc[SHARED_IN_EPNUM]->in_state->thread);
+    if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
+        osalSysUnlock();
+        return;
     }
-    usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)report, sizeof(struct nkro_report));
     osalSysUnlock();
-  } else
+
+#ifdef NKRO_ENABLE
+    if (keymap_config.nkro && keyboard_protocol) { /* NKRO protocol */
+        /* need to wait until the previous packet has made it through */
+        /* can rewrite this using the synchronous API, then would wait
+         * until *after* the packet has been transmitted. I think
+         * this is more efficient */
+        /* busy wait, should be short and not very common */
+        osalSysLock();
+        if (usbGetTransmitStatusI(&USB_DRIVER, SHARED_IN_EPNUM)) {
+            /* Need to either suspend, or loop and call unlock/lock during
+             * every iteration - otherwise the system will remain locked,
+             * no interrupts served, so USB not going through as well.
+             * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
+            osalThreadSuspendS(&(&USB_DRIVER)->epc[SHARED_IN_EPNUM]->in_state->thread);
+        }
+        usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)report, sizeof(struct nkro_report));
+        osalSysUnlock();
+    } else
 #endif /* NKRO_ENABLE */
-  { /* regular protocol */
-    /* need to wait until the previous packet has made it through */
-    /* busy wait, should be short and not very common */
-    osalSysLock();
-    if(usbGetTransmitStatusI(&USB_DRIVER, KEYBOARD_IN_EPNUM)) {
-      /* Need to either suspend, or loop and call unlock/lock during
-       * every iteration - otherwise the system will remain locked,
-       * no interrupts served, so USB not going through as well.
-       * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
-      osalThreadSuspendS(&(&USB_DRIVER)->epc[KEYBOARD_IN_EPNUM]->in_state->thread);
-    }
-    uint8_t *data, size;
-    if (keyboard_protocol) {
-      data = (uint8_t*)report;
-      size = KEYBOARD_REPORT_SIZE;
-    } else {    /* boot protocol */
-      data = &report->mods;
-      size = 8;
+    {  /* regular protocol */
+        /* need to wait until the previous packet has made it through */
+        /* busy wait, should be short and not very common */
+        osalSysLock();
+        if (usbGetTransmitStatusI(&USB_DRIVER, KEYBOARD_IN_EPNUM)) {
+            /* Need to either suspend, or loop and call unlock/lock during
+             * every iteration - otherwise the system will remain locked,
+             * no interrupts served, so USB not going through as well.
+             * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
+            osalThreadSuspendS(&(&USB_DRIVER)->epc[KEYBOARD_IN_EPNUM]->in_state->thread);
+        }
+        uint8_t *data, size;
+        if (keyboard_protocol) {
+            data = (uint8_t *)report;
+            size = KEYBOARD_REPORT_SIZE;
+        } else { /* boot protocol */
+            data = &report->mods;
+            size = 8;
+        }
+        usbStartTransmitI(&USB_DRIVER, KEYBOARD_IN_EPNUM, data, size);
+        osalSysUnlock();
     }
-    usbStartTransmitI(&USB_DRIVER, KEYBOARD_IN_EPNUM, data, size);
-    osalSysUnlock();
-  }
-  keyboard_report_sent = *report;
+    keyboard_report_sent = *report;
 }
 
 /* ---------------------------------------------------------
@@ -684,39 +672,37 @@ void send_keyboard(report_keyboard_t *report) {
 
 #ifdef MOUSE_ENABLE
 
-#ifndef MOUSE_SHARED_EP
+#    ifndef MOUSE_SHARED_EP
 /* mouse IN callback hander (a mouse report has made it IN) */
 void mouse_in_cb(USBDriver *usbp, usbep_t ep) {
-  (void)usbp;
-  (void)ep;
+    (void)usbp;
+    (void)ep;
 }
-#endif
+#    endif
 
 void send_mouse(report_mouse_t *report) {
-  osalSysLock();
-  if(usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
-    osalSysUnlock();
-    return;
-  }
-
-  if(usbGetTransmitStatusI(&USB_DRIVER, MOUSE_IN_EPNUM)) {
-    /* Need to either suspend, or loop and call unlock/lock during
-     * every iteration - otherwise the system will remain locked,
-     * no interrupts served, so USB not going through as well.
-     * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
-    if (osalThreadSuspendTimeoutS(&(&USB_DRIVER)->epc[MOUSE_IN_EPNUM]->in_state->thread, MS2ST(10))==MSG_TIMEOUT) {
-      osalSysUnlock();
-      return;
+    osalSysLock();
+    if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
+        osalSysUnlock();
+        return;
     }
-  }
-  usbStartTransmitI(&USB_DRIVER, MOUSE_IN_EPNUM, (uint8_t *)report, sizeof(report_mouse_t));
-  osalSysUnlock();
-}
 
-#else /* MOUSE_ENABLE */
-void send_mouse(report_mouse_t *report) {
-  (void)report;
+    if (usbGetTransmitStatusI(&USB_DRIVER, MOUSE_IN_EPNUM)) {
+        /* Need to either suspend, or loop and call unlock/lock during
+         * every iteration - otherwise the system will remain locked,
+         * no interrupts served, so USB not going through as well.
+         * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
+        if (osalThreadSuspendTimeoutS(&(&USB_DRIVER)->epc[MOUSE_IN_EPNUM]->in_state->thread, MS2ST(10)) == MSG_TIMEOUT) {
+            osalSysUnlock();
+            return;
+        }
+    }
+    usbStartTransmitI(&USB_DRIVER, MOUSE_IN_EPNUM, (uint8_t *)report, sizeof(report_mouse_t));
+    osalSysUnlock();
 }
+
+#else  /* MOUSE_ENABLE */
+void send_mouse(report_mouse_t *report) { (void)report; }
 #endif /* MOUSE_ENABLE */
 
 /* ---------------------------------------------------------
@@ -726,9 +712,9 @@ void send_mouse(report_mouse_t *report) {
 #ifdef SHARED_EP_ENABLE
 /* shared IN callback hander */
 void shared_in_cb(USBDriver *usbp, usbep_t ep) {
-  /* STUB */
-  (void)usbp;
-  (void)ep;
+    /* STUB */
+    (void)usbp;
+    (void)ep;
 }
 #endif
 
@@ -739,36 +725,25 @@ void shared_in_cb(USBDriver *usbp, usbep_t ep) {
 
 #ifdef EXTRAKEY_ENABLE
 static void send_extra_report(uint8_t report_id, uint16_t data) {
-  osalSysLock();
-  if(usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
-    osalSysUnlock();
-    return;
-  }
+    osalSysLock();
+    if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
+        osalSysUnlock();
+        return;
+    }
 
-  report_extra_t report = {
-    .report_id = report_id,
-    .usage = data
-  };
+    report_extra_t report = {.report_id = report_id, .usage = data};
 
-  usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report_extra_t));
-  osalSysUnlock();
+    usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report_extra_t));
+    osalSysUnlock();
 }
 
-void send_system(uint16_t data) {
-  send_extra_report(REPORT_ID_SYSTEM, data);
-}
+void send_system(uint16_t data) { send_extra_report(REPORT_ID_SYSTEM, data); }
 
-void send_consumer(uint16_t data) {
-  send_extra_report(REPORT_ID_CONSUMER, data);
-}
+void send_consumer(uint16_t data) { send_extra_report(REPORT_ID_CONSUMER, data); }
 
-#else /* EXTRAKEY_ENABLE */
-void send_system(uint16_t data) {
-  (void)data;
-}
-void send_consumer(uint16_t data) {
-  (void)data;
-}
+#else  /* EXTRAKEY_ENABLE */
+void send_system(uint16_t data) { (void)data; }
+void send_consumer(uint16_t data) { (void)data; }
 #endif /* EXTRAKEY_ENABLE */
 
 /* ---------------------------------------------------------
@@ -779,106 +754,97 @@ void send_consumer(uint16_t data) {
 #ifdef CONSOLE_ENABLE
 
 int8_t sendchar(uint8_t c) {
-  // The previous implmentation had timeouts, but I think it's better to just slow down
-  // and make sure that everything is transferred, rather than dropping stuff
-  return chnWrite(&drivers.console_driver.driver, &c, 1);
+    // The previous implmentation had timeouts, but I think it's better to just slow down
+    // and make sure that everything is transferred, rather than dropping stuff
+    return chnWrite(&drivers.console_driver.driver, &c, 1);
 }
 
 // Just a dummy function for now, this could be exposed as a weak function
 // Or connected to the actual QMK console
-static void console_receive( uint8_t *data, uint8_t length ) {
-  (void)data;
-  (void)length;
+static void console_receive(uint8_t *data, uint8_t length) {
+    (void)data;
+    (void)length;
 }
 
 void console_task(void) {
-  uint8_t buffer[CONSOLE_EPSIZE];
-  size_t size = 0;
-  do {
-    size_t size = chnReadTimeout(&drivers.console_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
-    if (size > 0) {
-        console_receive(buffer, size);
-    }
-  } while(size > 0);
+    uint8_t buffer[CONSOLE_EPSIZE];
+    size_t  size = 0;
+    do {
+        size_t size = chnReadTimeout(&drivers.console_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
+        if (size > 0) {
+            console_receive(buffer, size);
+        }
+    } while (size > 0);
 }
 
-#else /* CONSOLE_ENABLE */
+#else  /* CONSOLE_ENABLE */
 int8_t sendchar(uint8_t c) {
-  (void)c;
-  return 0;
+    (void)c;
+    return 0;
 }
 #endif /* CONSOLE_ENABLE */
 
 void sendchar_pf(void *p, char c) {
-  (void)p;
-  sendchar((uint8_t)c);
+    (void)p;
+    sendchar((uint8_t)c);
 }
 
 #ifdef RAW_ENABLE
-void raw_hid_send( uint8_t *data, uint8_t length ) {
-       // TODO: implement variable size packet
-       if ( length != RAW_EPSIZE )
-       {
-               return;
-
-       }
-  chnWrite(&drivers.raw_driver.driver, data, length);
+void raw_hid_send(uint8_t *data, uint8_t length) {
+    // TODO: implement variable size packet
+    if (length != RAW_EPSIZE) {
+        return;
+    }
+    chnWrite(&drivers.raw_driver.driver, data, length);
 }
 
-__attribute__ ((weak))
-void raw_hid_receive( uint8_t *data, uint8_t length ) {
-       // Users should #include "raw_hid.h" in their own code
-       // and implement this function there. Leave this as weak linkage
-       // so users can opt to not handle data coming in.
+__attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) {
+    // Users should #include "raw_hid.h" in their own code
+    // and implement this function there. Leave this as weak linkage
+    // so users can opt to not handle data coming in.
 }
 
 void raw_hid_task(void) {
-  uint8_t buffer[RAW_EPSIZE];
-  size_t size = 0;
-  do {
-    size_t size = chnReadTimeout(&drivers.raw_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
-    if (size > 0) {
-        raw_hid_receive(buffer, size);
-    }
-  } while(size > 0);
+    uint8_t buffer[RAW_EPSIZE];
+    size_t  size = 0;
+    do {
+        size_t size = chnReadTimeout(&drivers.raw_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
+        if (size > 0) {
+            raw_hid_receive(buffer, size);
+        }
+    } while (size > 0);
 }
 
 #endif
 
 #ifdef MIDI_ENABLE
 
-void send_midi_packet(MIDI_EventPacket_t* event) {
-  chnWrite(&drivers.midi_driver.driver, (uint8_t*)event, sizeof(MIDI_EventPacket_t));
-}
+void send_midi_packet(MIDI_EventPacket_t *event) { chnWrite(&drivers.midi_driver.driver, (uint8_t *)event, sizeof(MIDI_EventPacket_t)); }
 
-bool recv_midi_packet(MIDI_EventPacket_tconst event) {
-  size_t size = chnReadTimeout(&drivers.midi_driver.driver, (uint8_t*)event, sizeof(MIDI_EventPacket_t), TIME_IMMEDIATE);
-  return size == sizeof(MIDI_EventPacket_t);
+bool recv_midi_packet(MIDI_EventPacket_t *const event) {
+    size_t size = chnReadTimeout(&drivers.midi_driver.driver, (uint8_t *)event, sizeof(MIDI_EventPacket_t), TIME_IMMEDIATE);
+    return size == sizeof(MIDI_EventPacket_t);
 }
 
 #endif
 
 #ifdef VIRTSER_ENABLE
 
-void virtser_send(const uint8_t byte) {
-  chnWrite(&drivers.serial_driver.driver, &byte, 1);
-}
+void virtser_send(const uint8_t byte) { chnWrite(&drivers.serial_driver.driver, &byte, 1); }
 
-__attribute__ ((weak))
-void virtser_recv(uint8_t c)
-{
-  // Ignore by default
+__attribute__((weak)) void virtser_recv(uint8_t c) {
+    // Ignore by default
 }
 
 void virtser_task(void) {
-  uint8_t numBytesReceived = 0;
-  uint8_t buffer[16];
-  do {
-    numBytesReceived = chnReadTimeout(&drivers.serial_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
-    for (int i=0;i<numBytesReceived;i++) {
-      virtser_recv(buffer[i]);
-    }
-  } while (numBytesReceived > 0);
+    uint8_t numBytesReceived = 0;
+    uint8_t buffer[16];
+    do {
+        numBytesReceived = chnReadTimeout(&drivers.serial_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
+        for (int i = 0; i < numBytesReceived; i++) {
+            virtser_recv(buffer[i]);
+        }
+    } while (numBytesReceived > 0);
 }
 
 #endif
index 55e8882cc4bf46ce7709ff69effcf585197928ef..cd2bb695baadd0f2625b9733bcaf86624b41b1b6 100644 (file)
@@ -15,7 +15,6 @@
  * GPL v2 or later.
  */
 
-
 #ifndef _USB_MAIN_H_
 #define _USB_MAIN_H_
 
@@ -82,9 +81,9 @@ void shared_in_cb(USBDriver *usbp, usbep_t ep);
 
 /* extra report structure */
 typedef struct {
-  uint8_t report_id;
-  uint16_t usage;
-} __attribute__ ((packed)) report_extra_t;
+    uint8_t  report_id;
+    uint16_t usage;
+} __attribute__((packed)) report_extra_t;
 #endif /* EXTRAKEY_ENABLE */
 
 /* --------------
index 6a03cd441959fe9e571fd80997d3f634b448fae6..fd8fc4dbd5ed727f13365e3ff3238d6e05f84c08 100644 (file)
@@ -7,24 +7,21 @@ Copyright 2010,2011,2012,2013 Jun WAKO <wakojun@gmail.com>
 #include "ring_buffer.h"
 #include "ibm4704.h"
 
-
-#define WAIT(stat, us, err) do { \
-    if (!wait_##stat(us)) { \
-        ibm4704_error = err; \
-        goto ERROR; \
-    } \
-} while (0)
-
+#define WAIT(stat, us, err)      \
+    do {                         \
+        if (!wait_##stat(us)) {  \
+            ibm4704_error = err; \
+            goto ERROR;          \
+        }                        \
+    } while (0)
 
 uint8_t ibm4704_error = 0;
 
-
-void ibm4704_init(void)
-{
+void ibm4704_init(void) {
     inhibit();  // keep keyboard from sending
     IBM4704_INT_INIT();
     IBM4704_INT_ON();
-    idle();     // allow keyboard sending
+    idle();  // allow keyboard sending
 }
 
 /*
@@ -46,9 +43,8 @@ Timing:     After Request keyboard pull up Data and down Clock line to low for s
             Host writes a bit while Clock is hi and Keyboard reads while low.
 Stop bit:   Host releases or pulls up Data line to hi after 9th clock and waits for keyboard pull down the line to lo.
 */
-uint8_t ibm4704_send(uint8_t data)
-{
-    bool parity = true; // odd parity
+uint8_t ibm4704_send(uint8_t data) {
+    bool parity   = true;  // odd parity
     ibm4704_error = 0;
 
     IBM4704_INT_OFF();
@@ -62,19 +58,23 @@ uint8_t ibm4704_send(uint8_t data)
 
     /* Data bit */
     for (uint8_t i = 0; i < 8; i++) {
-        WAIT(clock_hi, 100, 0x40+i);
-        if (data&(1<<i)) {
+        WAIT(clock_hi, 100, 0x40 + i);
+        if (data & (1 << i)) {
             parity = !parity;
             data_hi();
         } else {
             data_lo();
         }
-        WAIT(clock_lo, 100, 0x48+i);
+        WAIT(clock_lo, 100, 0x48 + i);
     }
 
     /* Parity bit */
     WAIT(clock_hi, 100, 0x34);
-    if (parity) { data_hi(); } else { data_lo(); }
+    if (parity) {
+        data_hi();
+    } else {
+        data_lo();
+    }
     WAIT(clock_lo, 100, 0x35);
 
     /* Stop bit */
@@ -97,16 +97,14 @@ ERROR:
 }
 
 /* wait forever to receive data */
-uint8_t ibm4704_recv_response(void)
-{
+uint8_t ibm4704_recv_response(void) {
     while (!rbuf_has_data()) {
         _delay_ms(1);
     }
     return rbuf_dequeue();
 }
 
-uint8_t ibm4704_recv(void)
-{
+uint8_t ibm4704_recv(void) {
     if (rbuf_has_data()) {
         return rbuf_dequeue();
     } else {
@@ -121,7 +119,7 @@ Data bits are LSB first and Parity is odd. Clock has around 60us high and 30us l
 
         ____       __   __   __   __   __   __   __   __   __   _______
 Clock       \_____/  \_/  \_/  \_/  \_/  \_/  \_/  \_/  \_/  \_/
-             ____ ____ ____ ____ ____ ____ ____ ____ ____ ____    
+             ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
 Data    ____/    X____X____X____X____X____X____X____X____X____X________
             Start   0    1    2    3    4    5    6    7    P  Stop
 
@@ -130,11 +128,8 @@ Inhibit:    Pull Data line down to inhibit keyboard to send.
 Timing:     Host reads bit while Clock is hi.(rising edge)
 Stop bit:   Keyboard pulls down Data line to lo after 9th clock.
 */
-ISR(IBM4704_INT_VECT)
-{
-    static enum {
-        BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, PARITY, STOP
-    } state = BIT0;
+ISR(IBM4704_INT_VECT) {
+    static enum { BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, PARITY, STOP } state = BIT0;
     // LSB first
     static uint8_t data = 0;
     // Odd parity
@@ -161,8 +156,7 @@ ISR(IBM4704_INT_VECT)
             if (data_in()) {
                 parity = !parity;
             }
-            if (!parity)
-                goto ERROR;
+            if (!parity) goto ERROR;
             break;
         case STOP:
             // Data:Low
@@ -178,11 +172,11 @@ ISR(IBM4704_INT_VECT)
     goto RETURN;
 ERROR:
     ibm4704_error = state;
-    while (ibm4704_send(0xFE)) _delay_ms(1); // resend
+    while (ibm4704_send(0xFE)) _delay_ms(1);  // resend
     xprintf("R:%02X%02X\n", state, data);
 DONE:
-    state = BIT0;
-    data = 0;
+    state  = BIT0;
+    data   = 0;
     parity = false;
 RETURN:
     return;
index 618cce6be0f81ea6959300fa34a60e728fee0f5a..cc2418ee684113fb02611e7185fca78faea1b63e 100644 (file)
@@ -4,105 +4,100 @@ Copyright 2014 Jun WAKO <wakojun@gmail.com>
 #ifndef IBM4704_H
 #define IBM4704_H
 
-#define IBM4704_ERR_NONE        0
-#define IBM4704_ERR_PARITY      0x70
+#define IBM4704_ERR_NONE 0
+#define IBM4704_ERR_PARITY 0x70
 
-
-void ibm4704_init(void);
+void    ibm4704_init(void);
 uint8_t ibm4704_send(uint8_t data);
 uint8_t ibm4704_recv_response(void);
 uint8_t ibm4704_recv(void);
 
-
 /* Check pin configuration */
-#if !(defined(IBM4704_CLOCK_PORT) && \
-      defined(IBM4704_CLOCK_PIN) && \
-      defined(IBM4704_CLOCK_DDR) && \
-      defined(IBM4704_CLOCK_BIT))
-#   error "ibm4704 clock pin configuration is required in config.h"
+#if !(defined(IBM4704_CLOCK_PORT) && defined(IBM4704_CLOCK_PIN) && defined(IBM4704_CLOCK_DDR) && defined(IBM4704_CLOCK_BIT))
+#    error "ibm4704 clock pin configuration is required in config.h"
 #endif
 
-#if !(defined(IBM4704_DATA_PORT) && \
-      defined(IBM4704_DATA_PIN) && \
-      defined(IBM4704_DATA_DDR) && \
-      defined(IBM4704_DATA_BIT))
-#   error "ibm4704 data pin configuration is required in config.h"
+#if !(defined(IBM4704_DATA_PORT) && defined(IBM4704_DATA_PIN) && defined(IBM4704_DATA_DDR) && defined(IBM4704_DATA_BIT))
+#    error "ibm4704 data pin configuration is required in config.h"
 #endif
 
-
 /*--------------------------------------------------------------------
  * static functions
  *------------------------------------------------------------------*/
-static inline void clock_lo(void)
-{
-    IBM4704_CLOCK_PORT &= ~(1<<IBM4704_CLOCK_BIT);
-    IBM4704_CLOCK_DDR  |=  (1<<IBM4704_CLOCK_BIT);
+static inline void clock_lo(void) {
+    IBM4704_CLOCK_PORT &= ~(1 << IBM4704_CLOCK_BIT);
+    IBM4704_CLOCK_DDR |= (1 << IBM4704_CLOCK_BIT);
 }
-static inline void clock_hi(void)
-{
+static inline void clock_hi(void) {
     /* input with pull up */
-    IBM4704_CLOCK_DDR  &= ~(1<<IBM4704_CLOCK_BIT);
-    IBM4704_CLOCK_PORT |=  (1<<IBM4704_CLOCK_BIT);
+    IBM4704_CLOCK_DDR &= ~(1 << IBM4704_CLOCK_BIT);
+    IBM4704_CLOCK_PORT |= (1 << IBM4704_CLOCK_BIT);
 }
-static inline bool clock_in(void)
-{
-    IBM4704_CLOCK_DDR  &= ~(1<<IBM4704_CLOCK_BIT);
-    IBM4704_CLOCK_PORT |=  (1<<IBM4704_CLOCK_BIT);
+static inline bool clock_in(void) {
+    IBM4704_CLOCK_DDR &= ~(1 << IBM4704_CLOCK_BIT);
+    IBM4704_CLOCK_PORT |= (1 << IBM4704_CLOCK_BIT);
     _delay_us(1);
-    return IBM4704_CLOCK_PIN&(1<<IBM4704_CLOCK_BIT);
+    return IBM4704_CLOCK_PIN & (1 << IBM4704_CLOCK_BIT);
 }
-static inline void data_lo(void)
-{
-    IBM4704_DATA_PORT &= ~(1<<IBM4704_DATA_BIT);
-    IBM4704_DATA_DDR  |=  (1<<IBM4704_DATA_BIT);
+static inline void data_lo(void) {
+    IBM4704_DATA_PORT &= ~(1 << IBM4704_DATA_BIT);
+    IBM4704_DATA_DDR |= (1 << IBM4704_DATA_BIT);
 }
-static inline void data_hi(void)
-{
+static inline void data_hi(void) {
     /* input with pull up */
-    IBM4704_DATA_DDR  &= ~(1<<IBM4704_DATA_BIT);
-    IBM4704_DATA_PORT |=  (1<<IBM4704_DATA_BIT);
+    IBM4704_DATA_DDR &= ~(1 << IBM4704_DATA_BIT);
+    IBM4704_DATA_PORT |= (1 << IBM4704_DATA_BIT);
 }
-static inline bool data_in(void)
-{
-    IBM4704_DATA_DDR  &= ~(1<<IBM4704_DATA_BIT);
-    IBM4704_DATA_PORT |=  (1<<IBM4704_DATA_BIT);
+static inline bool data_in(void) {
+    IBM4704_DATA_DDR &= ~(1 << IBM4704_DATA_BIT);
+    IBM4704_DATA_PORT |= (1 << IBM4704_DATA_BIT);
     _delay_us(1);
-    return IBM4704_DATA_PIN&(1<<IBM4704_DATA_BIT);
+    return IBM4704_DATA_PIN & (1 << IBM4704_DATA_BIT);
 }
 
-static inline uint16_t wait_clock_lo(uint16_t us)
-{
-    while (clock_in()  && us) { asm(""); _delay_us(1); us--; }
+static inline uint16_t wait_clock_lo(uint16_t us) {
+    while (clock_in() && us) {
+        asm("");
+        _delay_us(1);
+        us--;
+    }
     return us;
 }
-static inline uint16_t wait_clock_hi(uint16_t us)
-{
-    while (!clock_in() && us) { asm(""); _delay_us(1); us--; }
+static inline uint16_t wait_clock_hi(uint16_t us) {
+    while (!clock_in() && us) {
+        asm("");
+        _delay_us(1);
+        us--;
+    }
     return us;
 }
-static inline uint16_t wait_data_lo(uint16_t us)
-{
-    while (data_in() && us)  { asm(""); _delay_us(1); us--; }
+static inline uint16_t wait_data_lo(uint16_t us) {
+    while (data_in() && us) {
+        asm("");
+        _delay_us(1);
+        us--;
+    }
     return us;
 }
-static inline uint16_t wait_data_hi(uint16_t us)
-{
-    while (!data_in() && us)  { asm(""); _delay_us(1); us--; }
+static inline uint16_t wait_data_hi(uint16_t us) {
+    while (!data_in() && us) {
+        asm("");
+        _delay_us(1);
+        us--;
+    }
     return us;
 }
 
 /* idle state that device can send */
-static inline void idle(void)
-{
+static inline void idle(void) {
     clock_hi();
     data_hi();
 }
 
-/* inhibit device to send 
+/* inhibit device to send
  * keyboard checks Data line on start bit(Data:hi) and it stops sending if Data line is low.
  */
-static inline void inhibit(void)
-{
+static inline void inhibit(void) {
     clock_hi();
     data_lo();
 }
index 71ccc493e2f3b7f02dbc7e45394ebd32a024a8a1..05e632da3823cdc0eb40592bbde0a5f717cb7d89 100644 (file)
@@ -37,43 +37,39 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "iwrap.h"
 #include "print.h"
 
-
 /* iWRAP MUX mode utils. 3.10 HID raw mode(iWRAP_HID_Application_Note.pdf) */
-#define MUX_HEADER(LINK, LENGTH) do { \
-    xmit(0xbf);     /* SOF    */ \
-    xmit(LINK);     /* Link   */ \
-    xmit(0x00);     /* Flags  */ \
-    xmit(LENGTH);   /* Length */ \
-} while (0)
-#define MUX_FOOTER(LINK) xmit(LINK^0xff)
-
+#define MUX_HEADER(LINK, LENGTH)   \
+    do {                           \
+        xmit(0xbf);   /* SOF    */ \
+        xmit(LINK);   /* Link   */ \
+        xmit(0x00);   /* Flags  */ \
+        xmit(LENGTH); /* Length */ \
+    } while (0)
+#define MUX_FOOTER(LINK) xmit(LINK ^ 0xff)
 
 static uint8_t connected = 0;
-//static uint8_t channel = 1;
+// static uint8_t channel = 1;
 
 /* iWRAP buffer */
 #define MUX_BUF_SIZE 64
-static char buf[MUX_BUF_SIZE];
+static char    buf[MUX_BUF_SIZE];
 static uint8_t snd_pos = 0;
 
 #define MUX_RCV_BUF_SIZE 256
-static char rcv_buf[MUX_RCV_BUF_SIZE];
+static char    rcv_buf[MUX_RCV_BUF_SIZE];
 static uint8_t rcv_head = 0;
 static uint8_t rcv_tail = 0;
 
-
 /* receive buffer */
-static void rcv_enq(char c)
-{
+static void rcv_enq(char c) {
     uint8_t next = (rcv_head + 1) % MUX_RCV_BUF_SIZE;
     if (next != rcv_tail) {
         rcv_buf[rcv_head] = c;
-        rcv_head = next;
+        rcv_head          = next;
     }
 }
 
-static char rcv_deq(void)
-{
+static char rcv_deq(void) {
     char c = 0;
     if (rcv_head != rcv_tail) {
         c = rcv_buf[rcv_tail++];
@@ -91,38 +87,33 @@ static char rcv_peek(void)
 }
 */
 
-static void rcv_clear(void)
-{
-    rcv_tail = rcv_head = 0;
-}
+static void rcv_clear(void) { rcv_tail = rcv_head = 0; }
 
 /* iWRAP response */
-ISR(PCINT1_vect, ISR_BLOCK) // recv() runs away in case of ISR_NOBLOCK
+ISR(PCINT1_vect, ISR_BLOCK)  // recv() runs away in case of ISR_NOBLOCK
 {
-    if ((SUART_IN_PIN & (1<<SUART_IN_BIT)))
-        return;
+    if ((SUART_IN_PIN & (1 << SUART_IN_BIT))) return;
 
     static volatile uint8_t mux_state = 0xff;
-    static volatile uint8_t mux_link = 0xff;
-    uint8_t c = recv();
+    static volatile uint8_t mux_link  = 0xff;
+    uint8_t                 c         = recv();
     switch (mux_state) {
-        case 0xff: // SOF
-            if (c == 0xbf)
-                mux_state--;
+        case 0xff:  // SOF
+            if (c == 0xbf) mux_state--;
             break;
-        case 0xfe: // Link
+        case 0xfe:  // Link
             mux_state--;
             mux_link = c;
             break;
-        case 0xfd: // Flags
+        case 0xfd:  // Flags
             mux_state--;
             break;
-        case 0xfc: // Length
+        case 0xfc:  // Length
             mux_state = c;
             break;
         case 0x00:
             mux_state = 0xff;
-            mux_link = 0xff;
+            mux_link  = 0xff;
             break;
         default:
             if (mux_state--) {
@@ -132,12 +123,10 @@ ISR(PCINT1_vect, ISR_BLOCK) // recv() runs away in case of ISR_NOBLOCK
     }
 }
 
-
 /*------------------------------------------------------------------*
  * iWRAP communication
  *------------------------------------------------------------------*/
-void iwrap_init(void)
-{
+void iwrap_init(void) {
     // reset iWRAP if in already MUX mode after AVR software-reset
     iwrap_send("RESET");
     iwrap_mux_send("RESET");
@@ -147,43 +136,34 @@ void iwrap_init(void)
     iwrap_check_connection();
 }
 
-void iwrap_mux_send(const char *s)
-{
+void iwrap_mux_send(const char *s) {
     rcv_clear();
     MUX_HEADER(0xff, strlen((char *)s));
     iwrap_send(s);
     MUX_FOOTER(0xff);
 }
 
-void iwrap_send(const char *s)
-{
-    while (*s)
-        xmit(*s++);
+void iwrap_send(const char *s) {
+    while (*s) xmit(*s++);
 }
 
 /* send buffer */
-void iwrap_buf_add(uint8_t c)
-{
+void iwrap_buf_add(uint8_t c) {
     // need space for '\0'
-    if (snd_pos < MUX_BUF_SIZE-1)
-        buf[snd_pos++] = c;
+    if (snd_pos < MUX_BUF_SIZE - 1) buf[snd_pos++] = c;
 }
 
-void iwrap_buf_del(void)
-{
-    if (snd_pos)
-        snd_pos--;
+void iwrap_buf_del(void) {
+    if (snd_pos) snd_pos--;
 }
 
-void iwrap_buf_send(void)
-{
+void iwrap_buf_send(void) {
     buf[snd_pos] = '\0';
-    snd_pos = 0;
+    snd_pos      = 0;
     iwrap_mux_send(buf);
 }
 
-void iwrap_call(void)
-{
+void iwrap_call(void) {
     char *p;
 
     iwrap_mux_send("SET BT PAIR");
@@ -193,7 +173,7 @@ void iwrap_call(void)
     while (!strncmp(p, "SET BT PAIR", 11)) {
         p += 7;
         strncpy(p, "CALL", 4);
-        strncpy(p+22, " 11 HID\n\0", 9);
+        strncpy(p + 22, " 11 HID\n\0", 9);
         print_S(p);
         iwrap_mux_send(p);
         // TODO: skip to next line
@@ -224,20 +204,21 @@ void iwrap_call(void)
     iwrap_check_connection();
 }
 
-void iwrap_kill(void)
-{
+void iwrap_kill(void) {
     char c;
     iwrap_mux_send("LIST");
     _delay_ms(500);
 
-    while ((c = rcv_deq()) && c != '\n') ;
+    while ((c = rcv_deq()) && c != '\n')
+        ;
     if (strncmp(rcv_buf + rcv_tail, "LIST ", 5)) {
         print("no connection to kill.\n");
         return;
     }
     // skip 10 'space' chars
     for (uint8_t i = 10; i; i--)
-        while ((c = rcv_deq()) && c != ' ') ;
+        while ((c = rcv_deq()) && c != ' ')
+            ;
 
     char *p = rcv_buf + rcv_tail - 5;
     strncpy(p, "KILL ", 5);
@@ -249,47 +230,34 @@ void iwrap_kill(void)
     iwrap_check_connection();
 }
 
-void iwrap_unpair(void)
-{
+void iwrap_unpair(void) {
     iwrap_mux_send("SET BT PAIR");
     _delay_ms(500);
 
     char *p = rcv_buf + rcv_tail;
     if (!strncmp(p, "SET BT PAIR", 11)) {
-        strncpy(p+29, "\n\0", 2);
+        strncpy(p + 29, "\n\0", 2);
         print_S(p);
         iwrap_mux_send(p);
     }
 }
 
-void iwrap_sleep(void)
-{
-    iwrap_mux_send("SLEEP");
-}
+void iwrap_sleep(void) { iwrap_mux_send("SLEEP"); }
 
-void iwrap_sniff(void)
-{
-}
+void iwrap_sniff(void) {}
 
-void iwrap_subrate(void)
-{
-}
+void iwrap_subrate(void) {}
 
-bool iwrap_failed(void)
-{
+bool iwrap_failed(void) {
     if (strncmp(rcv_buf, "SYNTAX ERROR", 12))
         return true;
     else
         return false;
 }
 
-uint8_t iwrap_connected(void)
-{
-    return connected;
-}
+uint8_t iwrap_connected(void) { return connected; }
 
-uint8_t iwrap_check_connection(void)
-{
+uint8_t iwrap_check_connection(void) {
     iwrap_mux_send("LIST");
     _delay_ms(100);
 
@@ -300,44 +268,31 @@ uint8_t iwrap_check_connection(void)
     return connected;
 }
 
-
 /*------------------------------------------------------------------*
  * Host driver
  *------------------------------------------------------------------*/
 static uint8_t keyboard_leds(void);
-static void send_keyboard(report_keyboard_t *report);
-static void send_mouse(report_mouse_t *report);
-static void send_system(uint16_t data);
-static void send_consumer(uint16_t data);
-
-static host_driver_t driver = {
-        keyboard_leds,
-        send_keyboard,
-        send_mouse,
-        send_system,
-        send_consumer
-};
-
-host_driver_t *iwrap_driver(void)
-{
-    return &driver;
-}
+static void    send_keyboard(report_keyboard_t *report);
+static void    send_mouse(report_mouse_t *report);
+static void    send_system(uint16_t data);
+static void    send_consumer(uint16_t data);
 
-static uint8_t keyboard_leds(void) {
-    return 0;
-}
+static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
 
-static void send_keyboard(report_keyboard_t *report)
-{
+host_driver_t *iwrap_driver(void) { return &driver; }
+
+static uint8_t keyboard_leds(void) { return 0; }
+
+static void send_keyboard(report_keyboard_t *report) {
     if (!iwrap_connected() && !iwrap_check_connection()) return;
     MUX_HEADER(0x01, 0x0c);
     // HID raw mode header
     xmit(0x9f);
-    xmit(0x0a); // Length
-    xmit(0xa1); // DATA(Input)
-    xmit(0x01); // Report ID
+    xmit(0x0a);  // Length
+    xmit(0xa1);  // DATA(Input)
+    xmit(0x01);  // Report ID
     xmit(report->mods);
-    xmit(0x00); // reserved byte(always 0)
+    xmit(0x00);  // reserved byte(always 0)
     xmit(report->keys[0]);
     xmit(report->keys[1]);
     xmit(report->keys[2]);
@@ -347,16 +302,15 @@ static void send_keyboard(report_keyboard_t *report)
     MUX_FOOTER(0x01);
 }
 
-static void send_mouse(report_mouse_t *report)
-{
+static void send_mouse(report_mouse_t *report) {
 #if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
     if (!iwrap_connected() && !iwrap_check_connection()) return;
     MUX_HEADER(0x01, 0x09);
     // HID raw mode header
     xmit(0x9f);
-    xmit(0x07); // Length
-    xmit(0xa1); // DATA(Input)
-    xmit(0x02); // Report ID
+    xmit(0x07);  // Length
+    xmit(0xa1);  // DATA(Input)
+    xmit(0x02);  // Report ID
     xmit(report->buttons);
     xmit(report->x);
     xmit(report->y);
@@ -366,18 +320,14 @@ static void send_mouse(report_mouse_t *report)
 #endif
 }
 
-static void send_system(uint16_t data)
-{
-    /* not supported */
-}
+static void send_system(uint16_t data) { /* not supported */ }
 
-static void send_consumer(uint16_t data)
-{
+static void send_consumer(uint16_t data) {
 #ifdef EXTRAKEY_ENABLE
     static uint16_t last_data = 0;
-    uint8_t bits1 = 0;
-    uint8_t bits2 = 0;
-    uint8_t bits3 = 0;
+    uint8_t         bits1     = 0;
+    uint8_t         bits2     = 0;
+    uint8_t         bits3     = 0;
 
     if (!iwrap_connected() && !iwrap_check_connection()) return;
     if (data == last_data) return;
@@ -458,9 +408,9 @@ static void send_consumer(uint16_t data)
 
     MUX_HEADER(0x01, 0x07);
     xmit(0x9f);
-    xmit(0x05); // Length
-    xmit(0xa1); // DATA(Input)
-    xmit(0x03); // Report ID
+    xmit(0x05);  // Length
+    xmit(0xa1);  // DATA(Input)
+    xmit(0x03);  // Report ID
     xmit(bits1);
     xmit(bits2);
     xmit(bits3);
index ffaad9395d03934692bc99cf4f34b82bd5dca1a0..51f2b5670bc8d6b52a97273631e8bc400317b7d6 100644 (file)
@@ -22,11 +22,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdbool.h>
 #include "host_driver.h"
 
-
 /* enable iWRAP MUX mode */
 #define MUX_MODE
 
-
 host_driver_t *iwrap_driver(void);
 
 void iwrap_init(void);
@@ -36,13 +34,13 @@ void iwrap_buf_send(void);
 void iwrap_buf_add(uint8_t c);
 void iwrap_buf_del(void);
 
-void iwrap_call(void);
-void iwrap_kill(void);
-void iwrap_unpair(void);
-void iwrap_sleep(void);
-void iwrap_sniff(void);
-void iwrap_subrate(void);
-bool iwrap_failed(void);
+void    iwrap_call(void);
+void    iwrap_kill(void);
+void    iwrap_unpair(void);
+void    iwrap_sleep(void);
+void    iwrap_sniff(void);
+void    iwrap_subrate(void);
+bool    iwrap_failed(void);
 uint8_t iwrap_connected(void);
 uint8_t iwrap_check_connection(void);
 
index 3abdce8dfc90a6e3e471e3d064d5c4535d8e8248..7ba780ede754684b396c80dd2cba5c1979397554 100644 (file)
@@ -18,7 +18,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <avr/interrupt.h>
 #include <avr/io.h>
 //#include <avr/wdt.h>
-#include "wd.h" // in order to use watchdog in interrupt mode
+#include "wd.h"  // in order to use watchdog in interrupt mode
 #include <avr/sleep.h>
 #include <util/delay.h>
 #include <avr/power.h>
@@ -28,8 +28,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "action.h"
 #include "iwrap.h"
 #ifdef PROTOCOL_VUSB
-#   include "vusb.h"
-#   include "usbdrv.h"
+#    include "vusb.h"
+#    include "usbdrv.h"
 #endif
 #include "uart.h"
 #include "suart.h"
@@ -38,13 +38,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "keycode.h"
 #include "command.h"
 
-
-static void sleep(uint8_t term);
-static bool console(void);
-static bool console_command(uint8_t c);
+static void    sleep(uint8_t term);
+static bool    console(void);
+static bool    console_command(uint8_t c);
 static uint8_t key2asc(uint8_t key);
 
-
 /*
 static void set_prr(void)
 {
@@ -78,37 +76,32 @@ static void pullup_pins(void)
 }
 */
 
-
 #ifdef PROTOCOL_VUSB
-static void disable_vusb(void)
-{
+static void disable_vusb(void) {
     // disable interrupt & disconnect to prevent host from enumerating
     USB_INTR_ENABLE &= ~(1 << USB_INTR_ENABLE_BIT);
     usbDeviceDisconnect();
 }
 
-static void enable_vusb(void)
-{
+static void enable_vusb(void) {
     USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
     usbDeviceConnect();
 }
 
-static void init_vusb(void)
-{
+static void init_vusb(void) {
     uint8_t i = 0;
 
     usbInit();
     disable_vusb();
     /* fake USB disconnect for > 250 ms */
-    while(--i){
+    while (--i) {
         _delay_ms(1);
     }
     enable_vusb();
 }
 #endif
 
-void change_driver(host_driver_t *driver)
-{
+void change_driver(host_driver_t *driver) {
     /*
     host_clear_keyboard_report();
     host_swap_keyboard_report();
@@ -120,20 +113,18 @@ void change_driver(host_driver_t *driver)
     host_set_driver(driver);
 }
 
-
-static bool sleeping = false;
-static bool insomniac = false;   // TODO: should be false for power saving
+static bool     sleeping   = false;
+static bool     insomniac  = false;  // TODO: should be false for power saving
 static uint16_t last_timer = 0;
 
-int main(void)
-{
+int main(void) {
     MCUSR = 0;
     clock_prescale_set(clock_div_1);
     WD_SET(WD_OFF);
 
     // power saving: the result is worse than nothing... why?
-    //pullup_pins();
-    //set_prr();
+    // pullup_pins();
+    // set_prr();
 
 #ifdef PROTOCOL_VUSB
     disable_vusb();
@@ -146,11 +137,11 @@ int main(void)
     print("suart init\n");
     // suart init
     // PC4: Tx Output IDLE(Hi)
-    PORTC |= (1<<4);
-    DDRC  |= (1<<4);
+    PORTC |= (1 << 4);
+    DDRC |= (1 << 4);
     // PC5: Rx Input(pull-up)
-    PORTC |= (1<<5);
-    DDRC  &= ~(1<<5);
+    PORTC |= (1 << 5);
+    DDRC &= ~(1 << 5);
     // suart receive interrut(PC5/PCINT13)
     PCMSK1 = 0b00100000;
     PCICR  = 0b00000010;
@@ -164,18 +155,16 @@ int main(void)
     last_timer = timer_read();
     while (true) {
 #ifdef PROTOCOL_VUSB
-        if (host_get_driver() == vusb_driver())
-            usbPoll();
+        if (host_get_driver() == vusb_driver()) usbPoll();
 #endif
         keyboard_task();
 #ifdef PROTOCOL_VUSB
-        if (host_get_driver() == vusb_driver())
-            vusb_transfer_keyboard();
+        if (host_get_driver() == vusb_driver()) vusb_transfer_keyboard();
 #endif
         // TODO: depricated
         if (matrix_is_modified() || console()) {
             last_timer = timer_read();
-            sleeping = false;
+            sleeping   = false;
         } else if (!sleeping && timer_elapsed(last_timer) > 4000) {
             sleeping = true;
             iwrap_check_connection();
@@ -184,7 +173,7 @@ int main(void)
         // TODO: suspend.h
         if (host_get_driver() == iwrap_driver()) {
             if (sleeping && !insomniac) {
-                _delay_ms(1);   // wait for UART to send
+                _delay_ms(1);  // wait for UART to send
                 iwrap_sleep();
                 sleep(WDTO_60MS);
             }
@@ -192,8 +181,7 @@ int main(void)
     }
 }
 
-static void sleep(uint8_t term)
-{
+static void sleep(uint8_t term) {
     WD_SET(WD_IRQ, term);
 
     cli();
@@ -207,51 +195,46 @@ static void sleep(uint8_t term)
     WD_SET(WD_OFF);
 }
 
-static bool console(void)
-{
-        // Send to Bluetoot module WT12
-        static bool breaked = false;
-        if (!uart_available())
-            return false;
-        else {
-            uint8_t c;
-            c = uart_getchar();
-            uart_putchar(c);
-            switch (c) {
-                case 0x00: // BREAK signal
-                    if (!breaked) {
-                        print("break(? for help): ");
-                        breaked = true;
-                    }
-                    break;
-                case '\r':
-                    uart_putchar('\n');
-                    iwrap_buf_send();
-                    break;
-                case '\b':
-                    iwrap_buf_del();
-                    break;
-                default:
-                    if (breaked) {
-                        print("\n");
-                        console_command(c);
-                        breaked = false;
-                    } else {
-                        iwrap_buf_add(c);
-                    }
-                    break;
-            }
-            return true;
+static bool console(void) {
+    // Send to Bluetoot module WT12
+    static bool breaked = false;
+    if (!uart_available())
+        return false;
+    else {
+        uint8_t c;
+        c = uart_getchar();
+        uart_putchar(c);
+        switch (c) {
+            case 0x00:  // BREAK signal
+                if (!breaked) {
+                    print("break(? for help): ");
+                    breaked = true;
+                }
+                break;
+            case '\r':
+                uart_putchar('\n');
+                iwrap_buf_send();
+                break;
+            case '\b':
+                iwrap_buf_del();
+                break;
+            default:
+                if (breaked) {
+                    print("\n");
+                    console_command(c);
+                    breaked = false;
+                } else {
+                    iwrap_buf_add(c);
+                }
+                break;
         }
+        return true;
+    }
 }
 
-bool command_extra(uint8_t code)
-{
-    return console_command(key2asc(code));
-}
+bool command_extra(uint8_t code) { return console_command(key2asc(code)); }
 
-static bool console_command(uint8_t c)
-{
+static bool console_command(uint8_t c) {
     switch (c) {
         case 'h':
         case '?':
@@ -287,11 +270,11 @@ static bool console_command(uint8_t c)
             print("USB mode\n");
             init_vusb();
             change_driver(vusb_driver());
-            //iwrap_kill();
-            //iwrap_sleep();
+            // iwrap_kill();
+            // iwrap_sleep();
             // disable suart receive interrut(PC5/PCINT13)
             PCMSK1 &= ~(0b00100000);
-            PCICR  &= ~(0b00000010);
+            PCICR &= ~(0b00000010);
             return 1;
         case 'w':
             print("iWRAP mode\n");
@@ -299,7 +282,7 @@ static bool console_command(uint8_t c)
             disable_vusb();
             // enable suart receive interrut(PC5/PCINT13)
             PCMSK1 |= 0b00100000;
-            PCICR  |= 0b00000010;
+            PCICR |= 0b00000010;
             return 1;
 #endif
         case 'k':
@@ -315,62 +298,115 @@ static bool console_command(uint8_t c)
 }
 
 // convert keycode into ascii charactor
-static uint8_t key2asc(uint8_t key)
-{
+static uint8_t key2asc(uint8_t key) {
     switch (key) {
-        case KC_A: return 'a';
-        case KC_B: return 'b';
-        case KC_C: return 'c';
-        case KC_D: return 'd';
-        case KC_E: return 'e';
-        case KC_F: return 'f';
-        case KC_G: return 'g';
-        case KC_H: return 'h';
-        case KC_I: return 'i';
-        case KC_J: return 'j';
-        case KC_K: return 'k';
-        case KC_L: return 'l';
-        case KC_M: return 'm';
-        case KC_N: return 'n';
-        case KC_O: return 'o';
-        case KC_P: return 'p';
-        case KC_Q: return 'q';
-        case KC_R: return 'r';
-        case KC_S: return 's';
-        case KC_T: return 't';
-        case KC_U: return 'u';
-        case KC_V: return 'v';
-        case KC_W: return 'w';
-        case KC_X: return 'x';
-        case KC_Y: return 'y';
-        case KC_Z: return 'z';
-        case KC_1: return '1';
-        case KC_2: return '2';
-        case KC_3: return '3';
-        case KC_4: return '4';
-        case KC_5: return '5';
-        case KC_6: return '6';
-        case KC_7: return '7';
-        case KC_8: return '8';
-        case KC_9: return '9';
-        case KC_0: return '0';
-        case KC_ENTER: return '\n';
-        case KC_ESCAPE: return 0x1B;
-        case KC_BSPACE: return '\b';
-        case KC_TAB: return '\t';
-        case KC_SPACE: return ' ';
-        case KC_MINUS: return '-';
-        case KC_EQUAL: return '=';
-        case KC_LBRACKET: return '[';
-        case KC_RBRACKET: return ']';
-        case KC_BSLASH: return '\\';
-        case KC_NONUS_HASH: return '\\';
-        case KC_SCOLON: return ';';
-        case KC_QUOTE: return '\'';
-        case KC_GRAVE: return '`';
-        case KC_COMMA: return ',';
-        case KC_DOT: return '.';
-        case KC_SLASH: return '/';
-        default: return 0x00;
+        case KC_A:
+            return 'a';
+        case KC_B:
+            return 'b';
+        case KC_C:
+            return 'c';
+        case KC_D:
+            return 'd';
+        case KC_E:
+            return 'e';
+        case KC_F:
+            return 'f';
+        case KC_G:
+            return 'g';
+        case KC_H:
+            return 'h';
+        case KC_I:
+            return 'i';
+        case KC_J:
+            return 'j';
+        case KC_K:
+            return 'k';
+        case KC_L:
+            return 'l';
+        case KC_M:
+            return 'm';
+        case KC_N:
+            return 'n';
+        case KC_O:
+            return 'o';
+        case KC_P:
+            return 'p';
+        case KC_Q:
+            return 'q';
+        case KC_R:
+            return 'r';
+        case KC_S:
+            return 's';
+        case KC_T:
+            return 't';
+        case KC_U:
+            return 'u';
+        case KC_V:
+            return 'v';
+        case KC_W:
+            return 'w';
+        case KC_X:
+            return 'x';
+        case KC_Y:
+            return 'y';
+        case KC_Z:
+            return 'z';
+        case KC_1:
+            return '1';
+        case KC_2:
+            return '2';
+        case KC_3:
+            return '3';
+        case KC_4:
+            return '4';
+        case KC_5:
+            return '5';
+        case KC_6:
+            return '6';
+        case KC_7:
+            return '7';
+        case KC_8:
+            return '8';
+        case KC_9:
+            return '9';
+        case KC_0:
+            return '0';
+        case KC_ENTER:
+            return '\n';
+        case KC_ESCAPE:
+            return 0x1B;
+        case KC_BSPACE:
+            return '\b';
+        case KC_TAB:
+            return '\t';
+        case KC_SPACE:
+            return ' ';
+        case KC_MINUS:
+            return '-';
+        case KC_EQUAL:
+            return '=';
+        case KC_LBRACKET:
+            return '[';
+        case KC_RBRACKET:
+            return ']';
+        case KC_BSLASH:
+            return '\\';
+        case KC_NONUS_HASH:
+            return '\\';
+        case KC_SCOLON:
+            return ';';
+        case KC_QUOTE:
+            return '\'';
+        case KC_GRAVE:
+            return '`';
+        case KC_COMMA:
+            return ',';
+        case KC_DOT:
+            return '.';
+        case KC_SLASH:
+            return '/';
+        default:
+            return 0x00;
     }
 }
index 7d92be069299159b563959b0c9b676a71febd8bf..c634bbc2f44c1645e86e3594076d10d07c4e6143 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef SUART
 #define SUART
 
-void xmit(uint8_t);
+void    xmit(uint8_t);
 uint8_t rcvr(void);
 uint8_t recv(void);
 
-#endif /* SUART */
+#endif /* SUART */
index 12395bf69649606da53e5202877fd306a6aeb896..083d6d44d6c039931e7b419e1ca725660dfc4858 100644 (file)
@@ -61,55 +61,58 @@ cleared on every power up or reset, along with disabling the watchdog-
 
 */
 
-//reset registers to the same name (MCUCSR)
+// reset registers to the same name (MCUCSR)
 #if !defined(MCUCSR)
-#define MCUCSR                  MCUSR
+#    define MCUCSR MCUSR
 #endif
 
-//watchdog registers to the same name (WDTCSR)
+// watchdog registers to the same name (WDTCSR)
 #if !defined(WDTCSR)
-#define WDTCSR                  WDTCR
+#    define WDTCSR WDTCR
 #endif
 
-//if enhanced watchdog, define irq values, create disable macro
+// if enhanced watchdog, define irq values, create disable macro
 #if defined(WDIF)
-#define WD_IRQ                  0xC0
-#define WD_RST_IRQ              0xC8
-#define WD_DISABLE()            do{                       \
-                                    MCUCSR &= ~(1<<WDRF); \
-                                    WD_SET(WD_OFF);       \
-                                }while(0)
+#    define WD_IRQ 0xC0
+#    define WD_RST_IRQ 0xC8
+#    define WD_DISABLE()            \
+        do {                        \
+            MCUCSR &= ~(1 << WDRF); \
+            WD_SET(WD_OFF);         \
+        } while (0)
 #endif
 
-//all watchdogs
-#define WD_RST                  8
-#define WD_OFF                  0
-
-//prescale values
-#define WDTO_15MS               0
-#define WDTO_30MS               1
-#define WDTO_60MS               2
-#define WDTO_120MS              3
-#define WDTO_250MS              4
-#define WDTO_500MS              5
-#define WDTO_1S                 6
-#define WDTO_2S                 7
-
-//prescale values for avrs with WDP3
+// all watchdogs
+#define WD_RST 8
+#define WD_OFF 0
+
+// prescale values
+#define WDTO_15MS 0
+#define WDTO_30MS 1
+#define WDTO_60MS 2
+#define WDTO_120MS 3
+#define WDTO_250MS 4
+#define WDTO_500MS 5
+#define WDTO_1S 6
+#define WDTO_2S 7
+
+// prescale values for avrs with WDP3
 #if defined(WDP3)
-#define WDTO_4S                 0x20
-#define WDTO_8S                 0x21
+#    define WDTO_4S 0x20
+#    define WDTO_8S 0x21
 #endif
 
-//watchdog reset
-#define WDR()                   __asm__ __volatile__("wdr")
+// watchdog reset
+#define WDR() __asm__ __volatile__("wdr")
 
-//avr reset using watchdog
-#define WD_AVR_RESET()          do{                              \
-                                    __asm__ __volatile__("cli"); \
-                                    WD_SET_UNSAFE(WD_RST);       \
-                                    while(1);                    \
-                                }while(0)
+// avr reset using watchdog
+#define WD_AVR_RESET()               \
+    do {                             \
+        __asm__ __volatile__("cli"); \
+        WD_SET_UNSAFE(WD_RST);       \
+        while (1)                    \
+            ;                        \
+    } while (0)
 
 /*set the watchdog-
 1. save SREG
@@ -119,41 +122,40 @@ cleared on every power up or reset, along with disabling the watchdog-
 5. write watchdog value
 6. restore SREG (restoring irq status)
 */
-#define WD_SET(val,...)                                 \
-    __asm__ __volatile__(                               \
-        "in __tmp_reg__,__SREG__"           "\n\t"      \
-        "cli"                               "\n\t"      \
-        "wdr"                               "\n\t"      \
-        "sts %[wdreg],%[wden]"              "\n\t"      \
-        "sts %[wdreg],%[wdval]"             "\n\t"      \
-        "out __SREG__,__tmp_reg__"          "\n\t"      \
-        :                                               \
-        : [wdreg] "M" (&WDTCSR),                        \
-          [wden]  "r" ((uint8_t)(0x18)),                \
-          [wdval] "r" ((uint8_t)(val|(__VA_ARGS__+0)))  \
-        : "r0"                                          \
-)
+#define WD_SET(val, ...)                                                                                                            \
+    __asm__ __volatile__("in __tmp_reg__,__SREG__"                                                                                  \
+                         "\n\t"                                                                                                     \
+                         "cli"                                                                                                      \
+                         "\n\t"                                                                                                     \
+                         "wdr"                                                                                                      \
+                         "\n\t"                                                                                                     \
+                         "sts %[wdreg],%[wden]"                                                                                     \
+                         "\n\t"                                                                                                     \
+                         "sts %[wdreg],%[wdval]"                                                                                    \
+                         "\n\t"                                                                                                     \
+                         "out __SREG__,__tmp_reg__"                                                                                 \
+                         "\n\t"                                                                                                     \
+                         :                                                                                                          \
+                         : [ wdreg ] "M"(&WDTCSR), [ wden ] "r"((uint8_t)(0x18)), [ wdval ] "r"((uint8_t)(val | (__VA_ARGS__ + 0))) \
+                         : "r0")
 
 /*set the watchdog when I bit in SREG known to be clear-
 1. reset watchdog timer
 2. enable watchdog change
 5. write watchdog value
 */
-#define WD_SET_UNSAFE(val,...)                          \
-    __asm__ __volatile__(                               \
-        "wdr"                               "\n\t"      \
-        "sts %[wdreg],%[wden]"              "\n\t"      \
-        "sts %[wdreg],%[wdval]"             "\n\t"      \
-        :                                               \
-        : [wdreg] "M" (&WDTCSR),                        \
-          [wden]  "r" ((uint8_t)(0x18)),                \
-          [wdval] "r" ((uint8_t)(val|(__VA_ARGS__+0)))  \
-)
-
-
-//for compatibility with avr/wdt.h
-#define wdt_enable(val) WD_SET(WD_RST,val)
-#define wdt_disable()   WD_SET(WD_OFF)
-
+#define WD_SET_UNSAFE(val, ...)                  \
+    __asm__ __volatile__("wdr"                   \
+                         "\n\t"                  \
+                         "sts %[wdreg],%[wden]"  \
+                         "\n\t"                  \
+                         "sts %[wdreg],%[wdval]" \
+                         "\n\t"                  \
+                         :                       \
+                         : [ wdreg ] "M"(&WDTCSR), [ wden ] "r"((uint8_t)(0x18)), [ wdval ] "r"((uint8_t)(val | (__VA_ARGS__ + 0))))
+
+// for compatibility with avr/wdt.h
+#define wdt_enable(val) WD_SET(WD_RST, val)
+#define wdt_disable() WD_SET(WD_OFF)
 
 #endif /* _AVR_WD_H_ */
index 80839731fd53c2cc9651f0b85ccef4e634479aef..71d0936f8f4e7040f8c575bbb6ab5f9e0d874612 100644 (file)
 // You may define them to something else in your config.h
 // if yours is wired up differently.
 #ifndef AdafruitBleResetPin
-#define AdafruitBleResetPin D4
+#    define AdafruitBleResetPin D4
 #endif
 
 #ifndef AdafruitBleCSPin
-#define AdafruitBleCSPin    B4
+#    define AdafruitBleCSPin B4
 #endif
 
 #ifndef AdafruitBleIRQPin
-#define AdafruitBleIRQPin   E6
+#    define AdafruitBleIRQPin E6
 #endif
 
-
 #define SAMPLE_BATTERY
 #define ConnectionUpdateInterval 1000 /* milliseconds */
 
 static struct {
-  bool is_connected;
-  bool initialized;
-  bool configured;
+    bool is_connected;
+    bool initialized;
+    bool configured;
 
 #define ProbedEvents 1
 #define UsingEvents 2
-  bool event_flags;
+    bool event_flags;
 
 #ifdef SAMPLE_BATTERY
-  uint16_t last_battery_update;
-  uint32_t vbat;
+    uint16_t last_battery_update;
+    uint32_t vbat;
 #endif
-  uint16_t last_connection_update;
+    uint16_t last_connection_update;
 } state;
 
 // Commands are encoded using SDEP and sent via SPI
@@ -51,14 +50,14 @@ static struct {
 
 #define SdepMaxPayload 16
 struct sdep_msg {
-  uint8_t type;
-  uint8_t cmd_low;
-  uint8_t cmd_high;
-  struct __attribute__((packed)) {
-    uint8_t len:7;
-    uint8_t more:1;
-  };
-  uint8_t payload[SdepMaxPayload];
+    uint8_t type;
+    uint8_t cmd_low;
+    uint8_t cmd_high;
+    struct __attribute__((packed)) {
+        uint8_t len : 7;
+        uint8_t more : 1;
+    };
+    uint8_t payload[SdepMaxPayload];
 } __attribute__((packed));
 
 // The recv latency is relatively high, so when we're hammering keys quickly,
@@ -68,28 +67,28 @@ struct sdep_msg {
 // information here.
 
 enum queue_type {
-  QTKeyReport, // 1-byte modifier + 6-byte key report
-  QTConsumer,  // 16-bit key code
+    QTKeyReport,  // 1-byte modifier + 6-byte key report
+    QTConsumer,   // 16-bit key code
 #ifdef MOUSE_ENABLE
-  QTMouseMove, // 4-byte mouse report
+    QTMouseMove,  // 4-byte mouse report
 #endif
 };
 
 struct queue_item {
-  enum queue_type queue_type;
-  uint16_t added;
-  union __attribute__((packed)) {
-    struct __attribute__((packed)) {
-      uint8_t modifier;
-      uint8_t keys[6];
-    } key;
-
-    uint16_t consumer;
-    struct __attribute__((packed)) {
-      int8_t x, y, scroll, pan;
-      uint8_t buttons;
-    } mousemove;
-  };
+    enum queue_type queue_type;
+    uint16_t        added;
+    union __attribute__((packed)) {
+        struct __attribute__((packed)) {
+            uint8_t modifier;
+            uint8_t keys[6];
+        } key;
+
+        uint16_t consumer;
+        struct __attribute__((packed)) {
+            int8_t  x, y, scroll, pan;
+            uint8_t buttons;
+        } mousemove;
+    };
 };
 
 // Items that we wish to send
@@ -102,108 +101,104 @@ static RingBuffer<uint16_t, 2> resp_buf;
 static bool process_queue_item(struct queue_item *item, uint16_t timeout);
 
 enum sdep_type {
-  SdepCommand = 0x10,
-  SdepResponse = 0x20,
-  SdepAlert = 0x40,
-  SdepError = 0x80,
-  SdepSlaveNotReady = 0xfe, // Try again later
-  SdepSlaveOverflow = 0xff, // You read more data than is available
+    SdepCommand       = 0x10,
+    SdepResponse      = 0x20,
+    SdepAlert         = 0x40,
+    SdepError         = 0x80,
+    SdepSlaveNotReady = 0xfe,  // Try again later
+    SdepSlaveOverflow = 0xff,  // You read more data than is available
 };
 
 enum ble_cmd {
-  BleInitialize = 0xbeef,
-  BleAtWrapper = 0x0a00,
-  BleUartTx = 0x0a01,
-  BleUartRx = 0x0a02,
+    BleInitialize = 0xbeef,
+    BleAtWrapper  = 0x0a00,
+    BleUartTx     = 0x0a01,
+    BleUartRx     = 0x0a02,
 };
 
 enum ble_system_event_bits {
-  BleSystemConnected = 0,
-  BleSystemDisconnected = 1,
-  BleSystemUartRx = 8,
-  BleSystemMidiRx = 10,
+    BleSystemConnected    = 0,
+    BleSystemDisconnected = 1,
+    BleSystemUartRx       = 8,
+    BleSystemMidiRx       = 10,
 };
 
 // The SDEP.md file says 2MHz but the web page and the sample driver
 // both use 4MHz
 #define SpiBusSpeed 4000000
 
-#define SdepTimeout 150 /* milliseconds */
-#define SdepShortTimeout 10 /* milliseconds */
-#define SdepBackOff 25 /* microseconds */
+#define SdepTimeout 150             /* milliseconds */
+#define SdepShortTimeout 10         /* milliseconds */
+#define SdepBackOff 25              /* microseconds */
 #define BatteryUpdateInterval 10000 /* milliseconds */
 
-static bool at_command(const char *cmd, char *resp, uint16_t resplen,
-                       bool verbose, uint16_t timeout = SdepTimeout);
-static bool at_command_P(const char *cmd, char *resp, uint16_t resplen,
-                         bool verbose = false);
+static bool at_command(const char *cmd, char *resp, uint16_t resplen, bool verbose, uint16_t timeout = SdepTimeout);
+static bool at_command_P(const char *cmd, char *resp, uint16_t resplen, bool verbose = false);
 
 struct SPI_Settings {
-  uint8_t spcr, spsr;
+    uint8_t spcr, spsr;
 };
 
 static struct SPI_Settings spi;
 
 // Initialize 4Mhz MSBFIRST MODE0
 void SPI_init(struct SPI_Settings *spi) {
-  spi->spcr = _BV(SPE) | _BV(MSTR);
-  spi->spsr = _BV(SPI2X);
+    spi->spcr = _BV(SPE) | _BV(MSTR);
+    spi->spsr = _BV(SPI2X);
 
-  static_assert(SpiBusSpeed == F_CPU / 2, "hard coded at 4Mhz");
+    static_assert(SpiBusSpeed == F_CPU / 2, "hard coded at 4Mhz");
 
-  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
-    // Ensure that SS is OUTPUT High
-    digitalWrite(B0, PinLevelHigh);
-    pinMode(B0, PinDirectionOutput);
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+        // Ensure that SS is OUTPUT High
+        digitalWrite(B0, PinLevelHigh);
+        pinMode(B0, PinDirectionOutput);
 
-    SPCR |= _BV(MSTR);
-    SPCR |= _BV(SPE);
-    pinMode(B1 /* SCK */, PinDirectionOutput);
-    pinMode(B2 /* MOSI */, PinDirectionOutput);
-  }
+        SPCR |= _BV(MSTR);
+        SPCR |= _BV(SPE);
+        pinMode(B1 /* SCK */, PinDirectionOutput);
+        pinMode(B2 /* MOSI */, PinDirectionOutput);
+    }
 }
 
-static inline void SPI_begin(struct SPI_Settings*spi) {
-  SPCR = spi->spcr;
-  SPSR = spi->spsr;
+static inline void SPI_begin(struct SPI_Settings *spi) {
+    SPCR = spi->spcr;
+    SPSR = spi->spsr;
 }
 
 static inline uint8_t SPI_TransferByte(uint8_t data) {
-  SPDR = data;
-  asm volatile("nop");
-  while (!(SPSR & _BV(SPIF))) {
-    ; // wait
-  }
-  return SPDR;
+    SPDR = data;
+    asm volatile("nop");
+    while (!(SPSR & _BV(SPIF))) {
+        ;  // wait
+    }
+    return SPDR;
 }
 
 static inline void spi_send_bytes(const uint8_t *buf, uint8_t len) {
-  if (len == 0) return;
-  const uint8_t *end = buf + len;
-  while (buf < end) {
-    SPDR = *buf;
-    while (!(SPSR & _BV(SPIF))) {
-      ; // wait
+    if (len == 0) return;
+    const uint8_t *end = buf + len;
+    while (buf < end) {
+        SPDR = *buf;
+        while (!(SPSR & _BV(SPIF))) {
+            ;  // wait
+        }
+        ++buf;
     }
-    ++buf;
-  }
 }
 
-static inline uint16_t spi_read_byte(void) {
-  return SPI_TransferByte(0x00 /* dummy */);
-}
+static inline uint16_t spi_read_byte(void) { return SPI_TransferByte(0x00 /* dummy */); }
 
 static inline void spi_recv_bytes(uint8_t *buf, uint8_t len) {
-  const uint8_t *end = buf + len;
-  if (len == 0) return;
-  while (buf < end) {
-    SPDR = 0; // write a dummy to initiate read
-    while (!(SPSR & _BV(SPIF))) {
-      ; // wait
+    const uint8_t *end = buf + len;
+    if (len == 0) return;
+    while (buf < end) {
+        SPDR = 0;  // write a dummy to initiate read
+        while (!(SPSR & _BV(SPIF))) {
+            ;  // wait
+        }
+        *buf = SPDR;
+        ++buf;
     }
-    *buf = SPDR;
-    ++buf;
-  }
 }
 
 #if 0
@@ -223,600 +218,572 @@ static void dump_pkt(const struct sdep_msg *msg) {
 
 // Send a single SDEP packet
 static bool sdep_send_pkt(const struct sdep_msg *msg, uint16_t timeout) {
-  SPI_begin(&spi);
+    SPI_begin(&spi);
+
+    digitalWrite(AdafruitBleCSPin, PinLevelLow);
+    uint16_t timerStart = timer_read();
+    bool     success    = false;
+    bool     ready      = false;
+
+    do {
+        ready = SPI_TransferByte(msg->type) != SdepSlaveNotReady;
+        if (ready) {
+            break;
+        }
 
-  digitalWrite(AdafruitBleCSPin, PinLevelLow);
-  uint16_t timerStart = timer_read();
-  bool success = false;
-  bool ready = false;
+        // Release it and let it initialize
+        digitalWrite(AdafruitBleCSPin, PinLevelHigh);
+        _delay_us(SdepBackOff);
+        digitalWrite(AdafruitBleCSPin, PinLevelLow);
+    } while (timer_elapsed(timerStart) < timeout);
 
-  do {
-    ready = SPI_TransferByte(msg->type) != SdepSlaveNotReady;
     if (ready) {
-      break;
+        // Slave is ready; send the rest of the packet
+        spi_send_bytes(&msg->cmd_low, sizeof(*msg) - (1 + sizeof(msg->payload)) + msg->len);
+        success = true;
     }
 
-    // Release it and let it initialize
     digitalWrite(AdafruitBleCSPin, PinLevelHigh);
-    _delay_us(SdepBackOff);
-    digitalWrite(AdafruitBleCSPin, PinLevelLow);
-  } while (timer_elapsed(timerStart) < timeout);
-
-  if (ready) {
-    // Slave is ready; send the rest of the packet
-    spi_send_bytes(&msg->cmd_low,
-                   sizeof(*msg) - (1 + sizeof(msg->payload)) + msg->len);
-    success = true;
-  }
 
-  digitalWrite(AdafruitBleCSPin, PinLevelHigh);
-
-  return success;
+    return success;
 }
 
-static inline void sdep_build_pkt(struct sdep_msg *msg, uint16_t command,
-                                  const uint8_t *payload, uint8_t len,
-                                  bool moredata) {
-  msg->type = SdepCommand;
-  msg->cmd_low = command & 0xff;
-  msg->cmd_high = command >> 8;
-  msg->len = len;
-  msg->more = (moredata && len == SdepMaxPayload) ? 1 : 0;
+static inline void sdep_build_pkt(struct sdep_msg *msg, uint16_t command, const uint8_t *payload, uint8_t len, bool moredata) {
+    msg->type     = SdepCommand;
+    msg->cmd_low  = command & 0xff;
+    msg->cmd_high = command >> 8;
+    msg->len      = len;
+    msg->more     = (moredata && len == SdepMaxPayload) ? 1 : 0;
 
-  static_assert(sizeof(*msg) == 20, "msg is correctly packed");
+    static_assert(sizeof(*msg) == 20, "msg is correctly packed");
 
-  memcpy(msg->payload, payload, len);
+    memcpy(msg->payload, payload, len);
 }
 
 // Read a single SDEP packet
 static bool sdep_recv_pkt(struct sdep_msg *msg, uint16_t timeout) {
-  bool success = false;
-  uint16_t timerStart = timer_read();
-  bool ready = false;
+    bool     success    = false;
+    uint16_t timerStart = timer_read();
+    bool     ready      = false;
+
+    do {
+        ready = digitalRead(AdafruitBleIRQPin);
+        if (ready) {
+            break;
+        }
+        _delay_us(1);
+    } while (timer_elapsed(timerStart) < timeout);
 
-  do {
-    ready = digitalRead(AdafruitBleIRQPin);
     if (ready) {
-      break;
-    }
-    _delay_us(1);
-  } while (timer_elapsed(timerStart) < timeout);
+        SPI_begin(&spi);
 
-  if (ready) {
-    SPI_begin(&spi);
+        digitalWrite(AdafruitBleCSPin, PinLevelLow);
 
-    digitalWrite(AdafruitBleCSPin, PinLevelLow);
+        do {
+            // Read the command type, waiting for the data to be ready
+            msg->type = spi_read_byte();
+            if (msg->type == SdepSlaveNotReady || msg->type == SdepSlaveOverflow) {
+                // Release it and let it initialize
+                digitalWrite(AdafruitBleCSPin, PinLevelHigh);
+                _delay_us(SdepBackOff);
+                digitalWrite(AdafruitBleCSPin, PinLevelLow);
+                continue;
+            }
+
+            // Read the rest of the header
+            spi_recv_bytes(&msg->cmd_low, sizeof(*msg) - (1 + sizeof(msg->payload)));
+
+            // and get the payload if there is any
+            if (msg->len <= SdepMaxPayload) {
+                spi_recv_bytes(msg->payload, msg->len);
+            }
+            success = true;
+            break;
+        } while (timer_elapsed(timerStart) < timeout);
 
-    do {
-      // Read the command type, waiting for the data to be ready
-      msg->type = spi_read_byte();
-      if (msg->type == SdepSlaveNotReady || msg->type == SdepSlaveOverflow) {
-        // Release it and let it initialize
         digitalWrite(AdafruitBleCSPin, PinLevelHigh);
-        _delay_us(SdepBackOff);
-        digitalWrite(AdafruitBleCSPin, PinLevelLow);
-        continue;
-      }
-
-      // Read the rest of the header
-      spi_recv_bytes(&msg->cmd_low, sizeof(*msg) - (1 + sizeof(msg->payload)));
-
-      // and get the payload if there is any
-      if (msg->len <= SdepMaxPayload) {
-        spi_recv_bytes(msg->payload, msg->len);
-      }
-      success = true;
-      break;
-    } while (timer_elapsed(timerStart) < timeout);
-
-    digitalWrite(AdafruitBleCSPin, PinLevelHigh);
-  }
-  return success;
+    }
+    return success;
 }
 
 static void resp_buf_read_one(bool greedy) {
-  uint16_t last_send;
-  if (!resp_buf.peek(last_send)) {
-    return;
-  }
+    uint16_t last_send;
+    if (!resp_buf.peek(last_send)) {
+        return;
+    }
 
-  if (digitalRead(AdafruitBleIRQPin)) {
-    struct sdep_msg msg;
+    if (digitalRead(AdafruitBleIRQPin)) {
+        struct sdep_msg msg;
 
-again:
-    if (sdep_recv_pkt(&msg, SdepTimeout)) {
-      if (!msg.more) {
-        // We got it; consume this entry
-        resp_buf.get(last_send);
-        dprintf("recv latency %dms\n", TIMER_DIFF_16(timer_read(), last_send));
-      }
+    again:
+        if (sdep_recv_pkt(&msg, SdepTimeout)) {
+            if (!msg.more) {
+                // We got it; consume this entry
+                resp_buf.get(last_send);
+                dprintf("recv latency %dms\n", TIMER_DIFF_16(timer_read(), last_send));
+            }
 
-      if (greedy && resp_buf.peek(last_send) && digitalRead(AdafruitBleIRQPin)) {
-        goto again;
-      }
-    }
+            if (greedy && resp_buf.peek(last_send) && digitalRead(AdafruitBleIRQPin)) {
+                goto again;
+            }
+        }
 
-  } else if (timer_elapsed(last_send) > SdepTimeout * 2) {
-    dprintf("waiting_for_result: timeout, resp_buf size %d\n",
-            (int)resp_buf.size());
+    } else if (timer_elapsed(last_send) > SdepTimeout * 2) {
+        dprintf("waiting_for_result: timeout, resp_buf size %d\n", (int)resp_buf.size());
 
-    // Timed out: consume this entry
-    resp_buf.get(last_send);
-  }
+        // Timed out: consume this entry
+        resp_buf.get(last_send);
+    }
 }
 
 static void send_buf_send_one(uint16_t timeout = SdepTimeout) {
-  struct queue_item item;
-
-  // Don't send anything more until we get an ACK
-  if (!resp_buf.empty()) {
-    return;
-  }
-
-  if (!send_buf.peek(item)) {
-    return;
-  }
-  if (process_queue_item(&item, timeout)) {
-    // commit that peek
-    send_buf.get(item);
-    dprintf("send_buf_send_one: have %d remaining\n", (int)send_buf.size());
-  } else {
-    dprint("failed to send, will retry\n");
-    _delay_ms(SdepTimeout);
-    resp_buf_read_one(true);
-  }
+    struct queue_item item;
+
+    // Don't send anything more until we get an ACK
+    if (!resp_buf.empty()) {
+        return;
+    }
+
+    if (!send_buf.peek(item)) {
+        return;
+    }
+    if (process_queue_item(&item, timeout)) {
+        // commit that peek
+        send_buf.get(item);
+        dprintf("send_buf_send_one: have %d remaining\n", (int)send_buf.size());
+    } else {
+        dprint("failed to send, will retry\n");
+        _delay_ms(SdepTimeout);
+        resp_buf_read_one(true);
+    }
 }
 
 static void resp_buf_wait(const char *cmd) {
-  bool didPrint = false;
-  while (!resp_buf.empty()) {
-    if (!didPrint) {
-      dprintf("wait on buf for %s\n", cmd);
-      didPrint = true;
+    bool didPrint = false;
+    while (!resp_buf.empty()) {
+        if (!didPrint) {
+            dprintf("wait on buf for %s\n", cmd);
+            didPrint = true;
+        }
+        resp_buf_read_one(true);
     }
-    resp_buf_read_one(true);
-  }
 }
 
 static bool ble_init(void) {
-  state.initialized = false;
-  state.configured = false;
-  state.is_connected = false;
+    state.initialized  = false;
+    state.configured   = false;
+    state.is_connected = false;
 
-  pinMode(AdafruitBleIRQPin, PinDirectionInput);
-  pinMode(AdafruitBleCSPin, PinDirectionOutput);
-  digitalWrite(AdafruitBleCSPin, PinLevelHigh);
+    pinMode(AdafruitBleIRQPin, PinDirectionInput);
+    pinMode(AdafruitBleCSPin, PinDirectionOutput);
+    digitalWrite(AdafruitBleCSPin, PinLevelHigh);
 
-  SPI_init(&spi);
+    SPI_init(&spi);
 
-  // Perform a hardware reset
-  pinMode(AdafruitBleResetPin, PinDirectionOutput);
-  digitalWrite(AdafruitBleResetPin, PinLevelHigh);
-  digitalWrite(AdafruitBleResetPin, PinLevelLow);
-  _delay_ms(10);
-  digitalWrite(AdafruitBleResetPin, PinLevelHigh);
+    // Perform a hardware reset
+    pinMode(AdafruitBleResetPin, PinDirectionOutput);
+    digitalWrite(AdafruitBleResetPin, PinLevelHigh);
+    digitalWrite(AdafruitBleResetPin, PinLevelLow);
+    _delay_ms(10);
+    digitalWrite(AdafruitBleResetPin, PinLevelHigh);
 
-  _delay_ms(1000); // Give it a second to initialize
+    _delay_ms(1000);  // Give it a second to initialize
 
-  state.initialized = true;
-  return state.initialized;
+    state.initialized = true;
+    return state.initialized;
 }
 
-static inline uint8_t min(uint8_t a, uint8_t b) {
-  return a < b ? a : b;
-}
+static inline uint8_t min(uint8_t a, uint8_t b) { return a < b ? a : b; }
 
 static bool read_response(char *resp, uint16_t resplen, bool verbose) {
-  char *dest = resp;
-  char *end = dest + resplen;
-
-  while (true) {
-    struct sdep_msg msg;
-
-    if (!sdep_recv_pkt(&msg, 2 * SdepTimeout)) {
-      dprint("sdep_recv_pkt failed\n");
-      return false;
+    char *dest = resp;
+    char *end  = dest + resplen;
+
+    while (true) {
+        struct sdep_msg msg;
+
+        if (!sdep_recv_pkt(&msg, 2 * SdepTimeout)) {
+            dprint("sdep_recv_pkt failed\n");
+            return false;
+        }
+
+        if (msg.type != SdepResponse) {
+            *resp = 0;
+            return false;
+        }
+
+        uint8_t len = min(msg.len, end - dest);
+        if (len > 0) {
+            memcpy(dest, msg.payload, len);
+            dest += len;
+        }
+
+        if (!msg.more) {
+            // No more data is expected!
+            break;
+        }
     }
 
-    if (msg.type != SdepResponse) {
-      *resp = 0;
-      return false;
-    }
+    // Ensure the response is NUL terminated
+    *dest = 0;
 
-    uint8_t len = min(msg.len, end - dest);
-    if (len > 0) {
-      memcpy(dest, msg.payload, len);
-      dest += len;
+    // "Parse" the result text; we want to snip off the trailing OK or ERROR line
+    // Rewind past the possible trailing CRLF so that we can strip it
+    --dest;
+    while (dest > resp && (dest[0] == '\n' || dest[0] == '\r')) {
+        *dest = 0;
+        --dest;
     }
 
-    if (!msg.more) {
-      // No more data is expected!
-      break;
+    // Look back for start of preceeding line
+    char *last_line = strrchr(resp, '\n');
+    if (last_line) {
+        ++last_line;
+    } else {
+        last_line = resp;
     }
-  }
-
-  // Ensure the response is NUL terminated
-  *dest = 0;
 
-  // "Parse" the result text; we want to snip off the trailing OK or ERROR line
-  // Rewind past the possible trailing CRLF so that we can strip it
-  --dest;
-  while (dest > resp && (dest[0] == '\n' || dest[0] == '\r')) {
-    *dest = 0;
-    --dest;
-  }
+    bool              success       = false;
+    static const char kOK[] PROGMEM = "OK";
 
-  // Look back for start of preceeding line
-  char *last_line = strrchr(resp, '\n');
-  if (last_line) {
-    ++last_line;
-  } else {
-    last_line = resp;
-  }
+    success = !strcmp_P(last_line, kOK);
 
-  bool success = false;
-  static const char kOK[] PROGMEM = "OK";
+    if (verbose || !success) {
+        dprintf("result: %s\n", resp);
+    }
+    return success;
+}
 
-  success = !strcmp_P(last_line, kOK );
+static bool at_command(const char *cmd, char *resp, uint16_t resplen, bool verbose, uint16_t timeout) {
+    const char *    end = cmd + strlen(cmd);
+    struct sdep_msg msg;
 
-  if (verbose || !success) {
-    dprintf("result: %s\n", resp);
-  }
-  return success;
-}
+    if (verbose) {
+        dprintf("ble send: %s\n", cmd);
+    }
 
-static bool at_command(const char *cmd, char *resp, uint16_t resplen,
-                       bool verbose, uint16_t timeout) {
-  const char *end = cmd + strlen(cmd);
-  struct sdep_msg msg;
-
-  if (verbose) {
-    dprintf("ble send: %s\n", cmd);
-  }
-
-  if (resp) {
-    // They want to decode the response, so we need to flush and wait
-    // for all pending I/O to finish before we start this one, so
-    // that we don't confuse the results
-    resp_buf_wait(cmd);
-    *resp = 0;
-  }
-
-  // Fragment the command into a series of SDEP packets
-  while (end - cmd > SdepMaxPayload) {
-    sdep_build_pkt(&msg, BleAtWrapper, (uint8_t *)cmd, SdepMaxPayload, true);
-    if (!sdep_send_pkt(&msg, timeout)) {
-      return false;
+    if (resp) {
+        // They want to decode the response, so we need to flush and wait
+        // for all pending I/O to finish before we start this one, so
+        // that we don't confuse the results
+        resp_buf_wait(cmd);
+        *resp = 0;
     }
-    cmd += SdepMaxPayload;
-  }
 
-  sdep_build_pkt(&msg, BleAtWrapper, (uint8_t *)cmd, end - cmd, false);
-  if (!sdep_send_pkt(&msg, timeout)) {
-    return false;
-  }
+    // Fragment the command into a series of SDEP packets
+    while (end - cmd > SdepMaxPayload) {
+        sdep_build_pkt(&msg, BleAtWrapper, (uint8_t *)cmd, SdepMaxPayload, true);
+        if (!sdep_send_pkt(&msg, timeout)) {
+            return false;
+        }
+        cmd += SdepMaxPayload;
+    }
 
-  if (resp == NULL) {
-    auto now = timer_read();
-    while (!resp_buf.enqueue(now)) {
-      resp_buf_read_one(false);
+    sdep_build_pkt(&msg, BleAtWrapper, (uint8_t *)cmd, end - cmd, false);
+    if (!sdep_send_pkt(&msg, timeout)) {
+        return false;
     }
-    auto later = timer_read();
-    if (TIMER_DIFF_16(later, now) > 0) {
-      dprintf("waited %dms for resp_buf\n", TIMER_DIFF_16(later, now));
+
+    if (resp == NULL) {
+        auto now = timer_read();
+        while (!resp_buf.enqueue(now)) {
+            resp_buf_read_one(false);
+        }
+        auto later = timer_read();
+        if (TIMER_DIFF_16(later, now) > 0) {
+            dprintf("waited %dms for resp_buf\n", TIMER_DIFF_16(later, now));
+        }
+        return true;
     }
-    return true;
-  }
 
-  return read_response(resp, resplen, verbose);
+    return read_response(resp, resplen, verbose);
 }
 
 bool at_command_P(const char *cmd, char *resp, uint16_t resplen, bool verbose) {
-  auto cmdbuf = (char *)alloca(strlen_P(cmd) + 1);
-  strcpy_P(cmdbuf, cmd);
-  return at_command(cmdbuf, resp, resplen, verbose);
+    auto cmdbuf = (char *)alloca(strlen_P(cmd) + 1);
+    strcpy_P(cmdbuf, cmd);
+    return at_command(cmdbuf, resp, resplen, verbose);
 }
 
-bool adafruit_ble_is_connected(void) {
-  return state.is_connected;
-}
+bool adafruit_ble_is_connected(void) { return state.is_connected; }
 
 bool adafruit_ble_enable_keyboard(void) {
-  char resbuf[128];
-
-  if (!state.initialized && !ble_init()) {
-    return false;
-  }
-
-  state.configured = false;
-
-  // Disable command echo
-  static const char kEcho[] PROGMEM = "ATE=0";
-  // Make the advertised name match the keyboard
-  static const char kGapDevName[] PROGMEM = "AT+GAPDEVNAME=" STR(PRODUCT);
-  // Turn on keyboard support
-  static const char kHidEnOn[] PROGMEM = "AT+BLEHIDEN=1";
-
-  // Adjust intervals to improve latency.  This causes the "central"
-  // system (computer/tablet) to poll us every 10-30 ms.  We can't
-  // set a smaller value than 10ms, and 30ms seems to be the natural
-  // processing time on my macbook.  Keeping it constrained to that
-  // feels reasonable to type to.
-  static const char kGapIntervals[] PROGMEM = "AT+GAPINTERVALS=10,30,,";
-
-  // Reset the device so that it picks up the above changes
-  static const char kATZ[] PROGMEM = "ATZ";
-
-  // Turn down the power level a bit
-  static const char kPower[] PROGMEM = "AT+BLEPOWERLEVEL=-12";
-  static PGM_P const configure_commands[] PROGMEM = {
-    kEcho,
-    kGapIntervals,
-    kGapDevName,
-    kHidEnOn,
-    kPower,
-    kATZ,
-  };
-
-  uint8_t i;
-  for (i = 0; i < sizeof(configure_commands) / sizeof(configure_commands[0]);
-       ++i) {
-    PGM_P cmd;
-    memcpy_P(&cmd, configure_commands + i, sizeof(cmd));
-
-    if (!at_command_P(cmd, resbuf, sizeof(resbuf))) {
-      dprintf("failed BLE command: %S: %s\n", cmd, resbuf);
-      goto fail;
-    }
-  }
-
-  state.configured = true;
-
-  // Check connection status in a little while; allow the ATZ time
-  // to kick in.
-  state.last_connection_update = timer_read();
+    char resbuf[128];
+
+    if (!state.initialized && !ble_init()) {
+        return false;
+    }
+
+    state.configured = false;
+
+    // Disable command echo
+    static const char kEcho[] PROGMEM = "ATE=0";
+    // Make the advertised name match the keyboard
+    static const char kGapDevName[] PROGMEM = "AT+GAPDEVNAME=" STR(PRODUCT);
+    // Turn on keyboard support
+    static const char kHidEnOn[] PROGMEM = "AT+BLEHIDEN=1";
+
+    // Adjust intervals to improve latency.  This causes the "central"
+    // system (computer/tablet) to poll us every 10-30 ms.  We can't
+    // set a smaller value than 10ms, and 30ms seems to be the natural
+    // processing time on my macbook.  Keeping it constrained to that
+    // feels reasonable to type to.
+    static const char kGapIntervals[] PROGMEM = "AT+GAPINTERVALS=10,30,,";
+
+    // Reset the device so that it picks up the above changes
+    static const char kATZ[] PROGMEM = "ATZ";
+
+    // Turn down the power level a bit
+    static const char  kPower[] PROGMEM             = "AT+BLEPOWERLEVEL=-12";
+    static PGM_P const configure_commands[] PROGMEM = {
+        kEcho, kGapIntervals, kGapDevName, kHidEnOn, kPower, kATZ,
+    };
+
+    uint8_t i;
+    for (i = 0; i < sizeof(configure_commands) / sizeof(configure_commands[0]); ++i) {
+        PGM_P cmd;
+        memcpy_P(&cmd, configure_commands + i, sizeof(cmd));
+
+        if (!at_command_P(cmd, resbuf, sizeof(resbuf))) {
+            dprintf("failed BLE command: %S: %s\n", cmd, resbuf);
+            goto fail;
+        }
+    }
+
+    state.configured = true;
+
+    // Check connection status in a little while; allow the ATZ time
+    // to kick in.
+    state.last_connection_update = timer_read();
 fail:
-  return state.configured;
+    return state.configured;
 }
 
 static void set_connected(bool connected) {
-  if (connected != state.is_connected) {
-    if (connected) {
-      print("****** BLE CONNECT!!!!\n");
-    } else {
-      print("****** BLE DISCONNECT!!!!\n");
-    }
-    state.is_connected = connected;
-
-    // TODO: if modifiers are down on the USB interface and
-    // we cut over to BLE or vice versa, they will remain stuck.
-    // This feels like a good point to do something like clearing
-    // the keyboard and/or generating a fake all keys up message.
-    // However, I've noticed that it takes a couple of seconds
-    // for macOS to to start recognizing key presses after BLE
-    // is in the connected state, so I worry that doing that
-    // here may not be good enough.
-  }
+    if (connected != state.is_connected) {
+        if (connected) {
+            print("****** BLE CONNECT!!!!\n");
+        } else {
+            print("****** BLE DISCONNECT!!!!\n");
+        }
+        state.is_connected = connected;
+
+        // TODO: if modifiers are down on the USB interface and
+        // we cut over to BLE or vice versa, they will remain stuck.
+        // This feels like a good point to do something like clearing
+        // the keyboard and/or generating a fake all keys up message.
+        // However, I've noticed that it takes a couple of seconds
+        // for macOS to to start recognizing key presses after BLE
+        // is in the connected state, so I worry that doing that
+        // here may not be good enough.
+    }
 }
 
 void adafruit_ble_task(void) {
-  char resbuf[48];
-
-  if (!state.configured && !adafruit_ble_enable_keyboard()) {
-    return;
-  }
-  resp_buf_read_one(true);
-  send_buf_send_one(SdepShortTimeout);
-
-  if (resp_buf.empty() && (state.event_flags & UsingEvents) &&
-      digitalRead(AdafruitBleIRQPin)) {
-    // Must be an event update
-    if (at_command_P(PSTR("AT+EVENTSTATUS"), resbuf, sizeof(resbuf))) {
-      uint32_t mask = strtoul(resbuf, NULL, 16);
-
-      if (mask & BleSystemConnected) {
-        set_connected(true);
-      } else if (mask & BleSystemDisconnected) {
-        set_connected(false);
-      }
-    }
-  }
-
-  if (timer_elapsed(state.last_connection_update) > ConnectionUpdateInterval) {
-    bool shouldPoll = true;
-    if (!(state.event_flags & ProbedEvents)) {
-      // Request notifications about connection status changes.
-      // This only works in SPIFRIEND firmware > 0.6.7, which is why
-      // we check for this conditionally here.
-      // Note that at the time of writing, HID reports only work correctly
-      // with Apple products on firmware version 0.6.7!
-      // https://forums.adafruit.com/viewtopic.php?f=8&t=104052
-      if (at_command_P(PSTR("AT+EVENTENABLE=0x1"), resbuf, sizeof(resbuf))) {
-        at_command_P(PSTR("AT+EVENTENABLE=0x2"), resbuf, sizeof(resbuf));
-        state.event_flags |= UsingEvents;
-      }
-      state.event_flags |= ProbedEvents;
-
-      // leave shouldPoll == true so that we check at least once
-      // before relying solely on events
-    } else {
-      shouldPoll = false;
-    }
+    char resbuf[48];
 
-    static const char kGetConn[] PROGMEM = "AT+GAPGETCONN";
-    state.last_connection_update = timer_read();
+    if (!state.configured && !adafruit_ble_enable_keyboard()) {
+        return;
+    }
+    resp_buf_read_one(true);
+    send_buf_send_one(SdepShortTimeout);
+
+    if (resp_buf.empty() && (state.event_flags & UsingEvents) && digitalRead(AdafruitBleIRQPin)) {
+        // Must be an event update
+        if (at_command_P(PSTR("AT+EVENTSTATUS"), resbuf, sizeof(resbuf))) {
+            uint32_t mask = strtoul(resbuf, NULL, 16);
+
+            if (mask & BleSystemConnected) {
+                set_connected(true);
+            } else if (mask & BleSystemDisconnected) {
+                set_connected(false);
+            }
+        }
+    }
 
-    if (at_command_P(kGetConn, resbuf, sizeof(resbuf))) {
-      set_connected(atoi(resbuf));
+    if (timer_elapsed(state.last_connection_update) > ConnectionUpdateInterval) {
+        bool shouldPoll = true;
+        if (!(state.event_flags & ProbedEvents)) {
+            // Request notifications about connection status changes.
+            // This only works in SPIFRIEND firmware > 0.6.7, which is why
+            // we check for this conditionally here.
+            // Note that at the time of writing, HID reports only work correctly
+            // with Apple products on firmware version 0.6.7!
+            // https://forums.adafruit.com/viewtopic.php?f=8&t=104052
+            if (at_command_P(PSTR("AT+EVENTENABLE=0x1"), resbuf, sizeof(resbuf))) {
+                at_command_P(PSTR("AT+EVENTENABLE=0x2"), resbuf, sizeof(resbuf));
+                state.event_flags |= UsingEvents;
+            }
+            state.event_flags |= ProbedEvents;
+
+            // leave shouldPoll == true so that we check at least once
+            // before relying solely on events
+        } else {
+            shouldPoll = false;
+        }
+
+        static const char kGetConn[] PROGMEM = "AT+GAPGETCONN";
+        state.last_connection_update         = timer_read();
+
+        if (at_command_P(kGetConn, resbuf, sizeof(resbuf))) {
+            set_connected(atoi(resbuf));
+        }
     }
-  }
 
 #ifdef SAMPLE_BATTERY
-  // I don't know if this really does anything useful yet; the reported
-  // voltage level always seems to be around 3200mV.  We may want to just rip
-  // this code out.
-  if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval &&
-      resp_buf.empty()) {
-    state.last_battery_update = timer_read();
-
-    if (at_command_P(PSTR("AT+HWVBAT"), resbuf, sizeof(resbuf))) {
-      state.vbat = atoi(resbuf);
+    // I don't know if this really does anything useful yet; the reported
+    // voltage level always seems to be around 3200mV.  We may want to just rip
+    // this code out.
+    if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) {
+        state.last_battery_update = timer_read();
+
+        if (at_command_P(PSTR("AT+HWVBAT"), resbuf, sizeof(resbuf))) {
+            state.vbat = atoi(resbuf);
+        }
     }
-  }
 #endif
 }
 
 static bool process_queue_item(struct queue_item *item, uint16_t timeout) {
-  char cmdbuf[48];
-  char fmtbuf[64];
+    char cmdbuf[48];
+    char fmtbuf[64];
 
-  // Arrange to re-check connection after keys have settled
-  state.last_connection_update = timer_read();
+    // Arrange to re-check connection after keys have settled
+    state.last_connection_update = timer_read();
 
 #if 1
-  if (TIMER_DIFF_16(state.last_connection_update, item->added) > 0) {
-    dprintf("send latency %dms\n",
-            TIMER_DIFF_16(state.last_connection_update, item->added));
-  }
+    if (TIMER_DIFF_16(state.last_connection_update, item->added) > 0) {
+        dprintf("send latency %dms\n", TIMER_DIFF_16(state.last_connection_update, item->added));
+    }
 #endif
 
-  switch (item->queue_type) {
-    case QTKeyReport:
-      strcpy_P(fmtbuf,
-          PSTR("AT+BLEKEYBOARDCODE=%02x-00-%02x-%02x-%02x-%02x-%02x-%02x"));
-      snprintf(cmdbuf, sizeof(cmdbuf), fmtbuf, item->key.modifier,
-               item->key.keys[0], item->key.keys[1], item->key.keys[2],
-               item->key.keys[3], item->key.keys[4], item->key.keys[5]);
-      return at_command(cmdbuf, NULL, 0, true, timeout);
+    switch (item->queue_type) {
+        case QTKeyReport:
+            strcpy_P(fmtbuf, PSTR("AT+BLEKEYBOARDCODE=%02x-00-%02x-%02x-%02x-%02x-%02x-%02x"));
+            snprintf(cmdbuf, sizeof(cmdbuf), fmtbuf, item->key.modifier, item->key.keys[0], item->key.keys[1], item->key.keys[2], item->key.keys[3], item->key.keys[4], item->key.keys[5]);
+            return at_command(cmdbuf, NULL, 0, true, timeout);
 
-    case QTConsumer:
-      strcpy_P(fmtbuf, PSTR("AT+BLEHIDCONTROLKEY=0x%04x"));
-      snprintf(cmdbuf, sizeof(cmdbuf), fmtbuf, item->consumer);
-      return at_command(cmdbuf, NULL, 0, true, timeout);
+        case QTConsumer:
+            strcpy_P(fmtbuf, PSTR("AT+BLEHIDCONTROLKEY=0x%04x"));
+            snprintf(cmdbuf, sizeof(cmdbuf), fmtbuf, item->consumer);
+            return at_command(cmdbuf, NULL, 0, true, timeout);
 
 #ifdef MOUSE_ENABLE
-    case QTMouseMove:
-      strcpy_P(fmtbuf, PSTR("AT+BLEHIDMOUSEMOVE=%d,%d,%d,%d"));
-      snprintf(cmdbuf, sizeof(cmdbuf), fmtbuf, item->mousemove.x,
-          item->mousemove.y, item->mousemove.scroll, item->mousemove.pan);
-      if (!at_command(cmdbuf, NULL, 0, true, timeout)) {
-        return false;
-      }
-      strcpy_P(cmdbuf, PSTR("AT+BLEHIDMOUSEBUTTON="));
-      if (item->mousemove.buttons & MOUSE_BTN1) {
-        strcat(cmdbuf, "L");
-      }
-      if (item->mousemove.buttons & MOUSE_BTN2) {
-        strcat(cmdbuf, "R");
-      }
-      if (item->mousemove.buttons & MOUSE_BTN3) {
-        strcat(cmdbuf, "M");
-      }
-      if (item->mousemove.buttons == 0) {
-        strcat(cmdbuf, "0");
-      }
-      return at_command(cmdbuf, NULL, 0, true, timeout);
+        case QTMouseMove:
+            strcpy_P(fmtbuf, PSTR("AT+BLEHIDMOUSEMOVE=%d,%d,%d,%d"));
+            snprintf(cmdbuf, sizeof(cmdbuf), fmtbuf, item->mousemove.x, item->mousemove.y, item->mousemove.scroll, item->mousemove.pan);
+            if (!at_command(cmdbuf, NULL, 0, true, timeout)) {
+                return false;
+            }
+            strcpy_P(cmdbuf, PSTR("AT+BLEHIDMOUSEBUTTON="));
+            if (item->mousemove.buttons & MOUSE_BTN1) {
+                strcat(cmdbuf, "L");
+            }
+            if (item->mousemove.buttons & MOUSE_BTN2) {
+                strcat(cmdbuf, "R");
+            }
+            if (item->mousemove.buttons & MOUSE_BTN3) {
+                strcat(cmdbuf, "M");
+            }
+            if (item->mousemove.buttons == 0) {
+                strcat(cmdbuf, "0");
+            }
+            return at_command(cmdbuf, NULL, 0, true, timeout);
 #endif
-    default:
-      return true;
-  }
-}
-
-bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys,
-                            uint8_t nkeys) {
-  struct queue_item item;
-  bool didWait = false;
-
-  item.queue_type = QTKeyReport;
-  item.key.modifier = hid_modifier_mask;
-  item.added = timer_read();
-
-  while (nkeys >= 0) {
-    item.key.keys[0] = keys[0];
-    item.key.keys[1] = nkeys >= 1 ? keys[1] : 0;
-    item.key.keys[2] = nkeys >= 2 ? keys[2] : 0;
-    item.key.keys[3] = nkeys >= 3 ? keys[3] : 0;
-    item.key.keys[4] = nkeys >= 4 ? keys[4] : 0;
-    item.key.keys[5] = nkeys >= 5 ? keys[5] : 0;
-
-    if (!send_buf.enqueue(item)) {
-      if (!didWait) {
-        dprint("wait for buf space\n");
-        didWait = true;
-      }
-      send_buf_send_one();
-      continue;
+        default:
+            return true;
     }
+}
 
-    if (nkeys <= 6) {
-      return true;
+bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys) {
+    struct queue_item item;
+    bool              didWait = false;
+
+    item.queue_type   = QTKeyReport;
+    item.key.modifier = hid_modifier_mask;
+    item.added        = timer_read();
+
+    while (nkeys >= 0) {
+        item.key.keys[0] = keys[0];
+        item.key.keys[1] = nkeys >= 1 ? keys[1] : 0;
+        item.key.keys[2] = nkeys >= 2 ? keys[2] : 0;
+        item.key.keys[3] = nkeys >= 3 ? keys[3] : 0;
+        item.key.keys[4] = nkeys >= 4 ? keys[4] : 0;
+        item.key.keys[5] = nkeys >= 5 ? keys[5] : 0;
+
+        if (!send_buf.enqueue(item)) {
+            if (!didWait) {
+                dprint("wait for buf space\n");
+                didWait = true;
+            }
+            send_buf_send_one();
+            continue;
+        }
+
+        if (nkeys <= 6) {
+            return true;
+        }
+
+        nkeys -= 6;
+        keys += 6;
     }
 
-    nkeys -= 6;
-    keys += 6;
-  }
-
-  return true;
+    return true;
 }
 
 bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration) {
-  struct queue_item item;
+    struct queue_item item;
 
-  item.queue_type = QTConsumer;
-  item.consumer = keycode;
+    item.queue_type = QTConsumer;
+    item.consumer   = keycode;
 
-  while (!send_buf.enqueue(item)) {
-    send_buf_send_one();
-  }
-  return true;
+    while (!send_buf.enqueue(item)) {
+        send_buf_send_one();
+    }
+    return true;
 }
 
 #ifdef MOUSE_ENABLE
-bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll,
-                                  int8_t pan, uint8_t buttons) {
-  struct queue_item item;
-
-  item.queue_type = QTMouseMove;
-  item.mousemove.x = x;
-  item.mousemove.y = y;
-  item.mousemove.scroll = scroll;
-  item.mousemove.pan = pan;
-  item.mousemove.buttons = buttons;
-
-  while (!send_buf.enqueue(item)) {
-    send_buf_send_one();
-  }
-  return true;
+bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons) {
+    struct queue_item item;
+
+    item.queue_type        = QTMouseMove;
+    item.mousemove.x       = x;
+    item.mousemove.y       = y;
+    item.mousemove.scroll  = scroll;
+    item.mousemove.pan     = pan;
+    item.mousemove.buttons = buttons;
+
+    while (!send_buf.enqueue(item)) {
+        send_buf_send_one();
+    }
+    return true;
 }
 #endif
 
-uint32_t adafruit_ble_read_battery_voltage(void) {
-  return state.vbat;
-}
+uint32_t adafruit_ble_read_battery_voltage(void) { return state.vbat; }
 
 bool adafruit_ble_set_mode_leds(bool on) {
-  if (!state.configured) {
-    return false;
-  }
-
-  // The "mode" led is the red blinky one
-  at_command_P(on ? PSTR("AT+HWMODELED=1") : PSTR("AT+HWMODELED=0"), NULL, 0);
-
-  // Pin 19 is the blue "connected" LED; turn that off too.
-  // When turning LEDs back on, don't turn that LED on if we're
-  // not connected, as that would be confusing.
-  at_command_P(on && state.is_connected ? PSTR("AT+HWGPIO=19,1")
-                                        : PSTR("AT+HWGPIO=19,0"),
-               NULL, 0);
-  return true;
+    if (!state.configured) {
+        return false;
+    }
+
+    // The "mode" led is the red blinky one
+    at_command_P(on ? PSTR("AT+HWMODELED=1") : PSTR("AT+HWMODELED=0"), NULL, 0);
+
+    // Pin 19 is the blue "connected" LED; turn that off too.
+    // When turning LEDs back on, don't turn that LED on if we're
+    // not connected, as that would be confusing.
+    at_command_P(on && state.is_connected ? PSTR("AT+HWGPIO=19,1") : PSTR("AT+HWGPIO=19,0"), NULL, 0);
+    return true;
 }
 
 // https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/ble-generic#at-plus-blepowerlevel
 bool adafruit_ble_set_power_level(int8_t level) {
-  char cmd[46];
-  if (!state.configured) {
-    return false;
-  }
-  snprintf(cmd, sizeof(cmd), "AT+BLEPOWERLEVEL=%d", level);
-  return at_command(cmd, NULL, 0, false);
+    char cmd[46];
+    if (!state.configured) {
+        return false;
+    }
+    snprintf(cmd, sizeof(cmd), "AT+BLEPOWERLEVEL=%d", level);
+    return at_command(cmd, NULL, 0, false);
 }
index 5d26a9d5a3e4c9e03c0e4dbb419e4a96eb4f92ff..cef46fe9f75a5bc5daed49aa7d03a4890966735d 100644 (file)
@@ -4,16 +4,16 @@
  */
 #pragma once
 #ifdef MODULE_ADAFRUIT_BLE
-#include <stdbool.h>
-#include <stdint.h>
-#include <string.h>
+#    include <stdbool.h>
+#    include <stdint.h>
+#    include <string.h>
 
-#include "config_common.h"
-#include "progmem.h"
+#    include "config_common.h"
+#    include "progmem.h"
 
-#ifdef __cplusplus
+#    ifdef __cplusplus
 extern "C" {
-#endif
+#    endif
 
 /* Instruct the module to enable HID keyboard support and reset */
 extern bool adafruit_ble_enable_keyboard(void);
@@ -34,20 +34,18 @@ extern void adafruit_ble_task(void);
  * this set of keys.
  * Also sends a key release indicator, so that the keys do not remain
  * held down. */
-extern bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys,
-                                   uint8_t nkeys);
+extern bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys);
 
 /* Send a consumer keycode, holding it down for the specified duration
  * (milliseconds) */
 extern bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration);
 
-#ifdef MOUSE_ENABLE
+#    ifdef MOUSE_ENABLE
 /* Send a mouse/wheel movement report.
  * The parameters are signed and indicate positive of negative direction
  * change. */
-extern bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll,
-                                         int8_t pan, uint8_t buttons);
-#endif
+extern bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons);
+#    endif
 
 /* Compute battery voltage by reading an analog pin.
  * Returns the integer number of millivolts */
@@ -56,8 +54,8 @@ extern uint32_t adafruit_ble_read_battery_voltage(void);
 extern bool adafruit_ble_set_mode_leds(bool on);
 extern bool adafruit_ble_set_power_level(int8_t level);
 
-#ifdef __cplusplus
+#    ifdef __cplusplus
 }
-#endif
+#    endif
 
-#endif // MODULE_ADAFRUIT_BLE
+#endif  // MODULE_ADAFRUIT_BLE
index 549606162db8497d32aa8920056bb03dcb4df886..5eb52860b14a56eb95b270c9083d84d7585694ee 100644 (file)
@@ -21,16 +21,18 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "debug.h"
 #include "bluetooth.h"
 
-void bluefruit_keyboard_print_report(report_keyboard_t *report)
-{
+void bluefruit_keyboard_print_report(report_keyboard_t *report) {
     if (!debug_keyboard) return;
-    dprintf("keys: "); for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) { debug_hex8(report->keys[i]); dprintf(" "); }
-    dprintf(" mods: "); debug_hex8(report->mods);
-    dprintf(" reserved: "); debug_hex8(report->reserved); 
+    dprintf("keys: ");
+    for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
+        debug_hex8(report->keys[i]);
+        dprintf(" ");
+    }
+    dprintf(" mods: ");
+    debug_hex8(report->mods);
+    dprintf(" reserved: ");
+    debug_hex8(report->reserved);
     dprintf("\n");
 }
 
-void bluefruit_serial_send(uint8_t data)
-{
-    serial_send(data);
-}
\ No newline at end of file
+void bluefruit_serial_send(uint8_t data) { serial_send(data); }
\ No newline at end of file
index f4b2f6f8b1c6b54ecb592a43a449099ba93f2361..081271a4e646e20c2b65f3486a19dbfa4089e849 100644 (file)
@@ -41,39 +41,8 @@ void bluefruit_serial_send(uint8_t data);
 | Stop            | 00000000 00010000 | 00 10 |
 +-------------------------------------+-------+
 */
-#define CONSUMER2BLUEFRUIT(usage) \
-    (usage == AUDIO_MUTE           ? 0x0000  : \
-    (usage == AUDIO_VOL_UP         ? 0x1000  : \
-    (usage == AUDIO_VOL_DOWN       ? 0x2000  : \
-    (usage == TRANSPORT_NEXT_TRACK ? 0x0002  : \
-    (usage == TRANSPORT_PREV_TRACK ? 0x0004  : \
-    (usage == TRANSPORT_STOP       ? 0x0010  : \
-    (usage == TRANSPORT_STOP_EJECT ? 0x0000  : \
-    (usage == TRANSPORT_PLAY_PAUSE ? 0x4000  : \
-    (usage == AL_CC_CONFIG         ? 0x0000  : \
-    (usage == AL_EMAIL             ? 0x0000  : \
-    (usage == AL_CALCULATOR        ? 0x0000  : \
-    (usage == AL_LOCAL_BROWSER     ? 0x0000  : \
-    (usage == AC_SEARCH            ? 0x0400  : \
-    (usage == AC_HOME              ? 0x0100  : \
-    (usage == AC_BACK              ? 0x0000  : \
-    (usage == AC_FORWARD           ? 0x0000  : \
-    (usage == AC_STOP              ? 0x0000  : \
-    (usage == AC_REFRESH           ? 0x0000  : \
-    (usage == AC_BOOKMARKS         ? 0x0000  : 0)))))))))))))))))))
+#define CONSUMER2BLUEFRUIT(usage) (usage == AUDIO_MUTE ? 0x0000 : (usage == AUDIO_VOL_UP ? 0x1000 : (usage == AUDIO_VOL_DOWN ? 0x2000 : (usage == TRANSPORT_NEXT_TRACK ? 0x0002 : (usage == TRANSPORT_PREV_TRACK ? 0x0004 : (usage == TRANSPORT_STOP ? 0x0010 : (usage == TRANSPORT_STOP_EJECT ? 0x0000 : (usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : (usage == AL_CC_CONFIG ? 0x0000 : (usage == AL_EMAIL ? 0x0000 : (usage == AL_CALCULATOR ? 0x0000 : (usage == AL_LOCAL_BROWSER ? 0x0000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : (usage == AC_BACK ? 0x0000 : (usage == AC_FORWARD ? 0x0000 : (usage == AC_STOP ? 0x0000 : (usage == AC_REFRESH ? 0x0000 : (usage == AC_BOOKMARKS ? 0x0000 : 0)))))))))))))))))))
 
-#define CONSUMER2RN42(usage) \
-    (usage == AUDIO_MUTE           ? 0x0040 : \
-    (usage == AUDIO_VOL_UP         ? 0x0010 : \
-    (usage == AUDIO_VOL_DOWN       ? 0x0020 : \
-    (usage == TRANSPORT_NEXT_TRACK ? 0x0100 : \
-    (usage == TRANSPORT_PREV_TRACK ? 0x0200 : \
-    (usage == TRANSPORT_STOP       ? 0x0400 : \
-    (usage == TRANSPORT_STOP_EJECT ? 0x0800 : \
-    (usage == TRANSPORT_PLAY_PAUSE ? 0x0080 : \
-    (usage == AL_EMAIL             ? 0x0200 : \
-    (usage == AL_LOCAL_BROWSER     ? 0x8000 : \
-    (usage == AC_SEARCH            ? 0x0400 : \
-    (usage == AC_HOME              ? 0x0100 : 0))))))))))))
+#define CONSUMER2RN42(usage) (usage == AUDIO_MUTE ? 0x0040 : (usage == AUDIO_VOL_UP ? 0x0010 : (usage == AUDIO_VOL_DOWN ? 0x0020 : (usage == TRANSPORT_NEXT_TRACK ? 0x0100 : (usage == TRANSPORT_PREV_TRACK ? 0x0200 : (usage == TRANSPORT_STOP ? 0x0400 : (usage == TRANSPORT_STOP_EJECT ? 0x0800 : (usage == TRANSPORT_PLAY_PAUSE ? 0x0080 : (usage == AL_EMAIL ? 0x0200 : (usage == AL_LOCAL_BROWSER ? 0x8000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : 0))))))))))))
 
- #endif
+#endif
index f2ecf246515686e69df6abadc93cb53d57c2fe94..12a6924fd0043d9d03cd08797f13b05cc48e4fb6 100644 (file)
@@ -45,7 +45,7 @@
 #include "sendchar.h"
 #include "debug.h"
 #ifdef SLEEP_LED_ENABLE
-#include "sleep_led.h"
+#    include "sleep_led.h"
 #endif
 #include "suspend.h"
 
 #include "rgblight_reconfig.h"
 
 #ifdef NKRO_ENABLE
-  #include "keycode_config.h"
+#    include "keycode_config.h"
 
-  extern keymap_config_t keymap_config;
+extern keymap_config_t keymap_config;
 #endif
 
-
 #ifdef AUDIO_ENABLE
-    #include <audio.h>
+#    include <audio.h>
 #endif
 
 #ifdef BLUETOOTH_ENABLE
-  #ifdef MODULE_ADAFRUIT_BLE
-    #include "adafruit_ble.h"
-  #else
-    #include "bluetooth.h"
-  #endif
+#    ifdef MODULE_ADAFRUIT_BLE
+#        include "adafruit_ble.h"
+#    else
+#        include "bluetooth.h"
+#    endif
 #endif
 
 #ifdef VIRTSER_ENABLE
-    #include "virtser.h"
+#    include "virtser.h"
 #endif
 
 #if (defined(RGB_MIDI) | defined(RGBLIGHT_ANIMATIONS)) & defined(RGBLIGHT_ENABLE)
-    #include "rgblight.h"
+#    include "rgblight.h"
 #endif
 
 #ifdef MIDI_ENABLE
-  #include "qmk_midi.h"
+#    include "qmk_midi.h"
 #endif
 
 #ifdef RAW_ENABLE
-       #include "raw_hid.h"
+#    include "raw_hid.h"
 #endif
 
 uint8_t keyboard_idle = 0;
 /* 0: Boot Protocol, 1: Report Protocol(default) */
-uint8_t keyboard_protocol = 1;
+uint8_t        keyboard_protocol  = 1;
 static uint8_t keyboard_led_stats = 0;
 
 static report_keyboard_t keyboard_report_sent;
 
 /* Host driver */
 static uint8_t keyboard_leds(void);
-static void send_keyboard(report_keyboard_t *report);
-static void send_mouse(report_mouse_t *report);
-static void send_system(uint16_t data);
-static void send_consumer(uint16_t data);
-host_driver_t lufa_driver = {
-    keyboard_leds,
-    send_keyboard,
-    send_mouse,
-    send_system,
-    send_consumer,
+static void    send_keyboard(report_keyboard_t *report);
+static void    send_mouse(report_mouse_t *report);
+static void    send_system(uint16_t data);
+static void    send_consumer(uint16_t data);
+host_driver_t  lufa_driver = {
+    keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer,
 };
 
 #ifdef VIRTSER_ENABLE
-USB_ClassInfo_CDC_Device_t cdc_device =
-{
-  .Config =
-  {
-    .ControlInterfaceNumber = CCI_INTERFACE,
-    .DataINEndpoint         =
-    {
-      .Address         = CDC_IN_EPADDR,
-      .Size            = CDC_EPSIZE,
-      .Banks           = 1,
-    },
-    .DataOUTEndpoint       =
-    {
-      .Address         = CDC_OUT_EPADDR,
-      .Size            = CDC_EPSIZE,
-      .Banks           = 1,
-    },
-    .NotificationEndpoint   =
-    {
-      .Address         = CDC_NOTIFICATION_EPADDR,
-      .Size            = CDC_NOTIFICATION_EPSIZE,
-      .Banks           = 1,
-    },
-  },
+USB_ClassInfo_CDC_Device_t cdc_device = {
+    .Config =
+        {
+            .ControlInterfaceNumber = CCI_INTERFACE,
+            .DataINEndpoint =
+                {
+                    .Address = CDC_IN_EPADDR,
+                    .Size    = CDC_EPSIZE,
+                    .Banks   = 1,
+                },
+            .DataOUTEndpoint =
+                {
+                    .Address = CDC_OUT_EPADDR,
+                    .Size    = CDC_EPSIZE,
+                    .Banks   = 1,
+                },
+            .NotificationEndpoint =
+                {
+                    .Address = CDC_NOTIFICATION_EPADDR,
+                    .Size    = CDC_NOTIFICATION_EPSIZE,
+                    .Banks   = 1,
+                },
+        },
 };
 #endif
 
@@ -146,84 +140,73 @@ USB_ClassInfo_CDC_Device_t cdc_device =
  *
  * FIXME: Needs doc
  */
-void raw_hid_send( uint8_t *data, uint8_t length )
-{
-       // TODO: implement variable size packet
-       if ( length != RAW_EPSIZE )
-       {
-               return;
-       }
-
-       if (USB_DeviceState != DEVICE_STATE_Configured)
-       {
-               return;
-       }
-
-       // TODO: decide if we allow calls to raw_hid_send() in the middle
-       // of other endpoint usage.
-       uint8_t ep = Endpoint_GetCurrentEndpoint();
-
-       Endpoint_SelectEndpoint(RAW_IN_EPNUM);
-
-       // Check to see if the host is ready to accept another packet
-       if (Endpoint_IsINReady())
-       {
-               // Write data
-               Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL);
-               // Finalize the stream transfer to send the last packet
-               Endpoint_ClearIN();
-       }
-
-       Endpoint_SelectEndpoint(ep);
+void raw_hid_send(uint8_t *data, uint8_t length) {
+    // TODO: implement variable size packet
+    if (length != RAW_EPSIZE) {
+        return;
+    }
+
+    if (USB_DeviceState != DEVICE_STATE_Configured) {
+        return;
+    }
+
+    // TODO: decide if we allow calls to raw_hid_send() in the middle
+    // of other endpoint usage.
+    uint8_t ep = Endpoint_GetCurrentEndpoint();
+
+    Endpoint_SelectEndpoint(RAW_IN_EPNUM);
+
+    // Check to see if the host is ready to accept another packet
+    if (Endpoint_IsINReady()) {
+        // Write data
+        Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL);
+        // Finalize the stream transfer to send the last packet
+        Endpoint_ClearIN();
+    }
+
+    Endpoint_SelectEndpoint(ep);
 }
 
 /** \brief Raw HID Receive
  *
  * FIXME: Needs doc
  */
-__attribute__ ((weak))
-void raw_hid_receive( uint8_t *data, uint8_t length )
-{
-       // Users should #include "raw_hid.h" in their own code
-       // and implement this function there. Leave this as weak linkage
-       // so users can opt to not handle data coming in.
+__attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) {
+    // Users should #include "raw_hid.h" in their own code
+    // and implement this function there. Leave this as weak linkage
+    // so users can opt to not handle data coming in.
 }
 
 /** \brief Raw HID Task
  *
  * FIXME: Needs doc
  */
-static void raw_hid_task(void)
-{
-       // Create a temporary buffer to hold the read in data from the host
-       uint8_t data[RAW_EPSIZE];
-       bool data_read = false;
-
-       // Device must be connected and configured for the task to run
-       if (USB_DeviceState != DEVICE_STATE_Configured)
-       return;
-
-       Endpoint_SelectEndpoint(RAW_OUT_EPNUM);
-
-       // Check to see if a packet has been sent from the host
-       if (Endpoint_IsOUTReceived())
-       {
-               // Check to see if the packet contains data
-               if (Endpoint_IsReadWriteAllowed())
-               {
-                       /* Read data */
-                       Endpoint_Read_Stream_LE(data, sizeof(data), NULL);
-                       data_read = true;
-               }
-
-               // Finalize the stream transfer to receive the last packet
-               Endpoint_ClearOUT();
-
-               if ( data_read )
-               {
-                       raw_hid_receive( data, sizeof(data) );
-               }
-       }
+static void raw_hid_task(void) {
+    // Create a temporary buffer to hold the read in data from the host
+    uint8_t data[RAW_EPSIZE];
+    bool    data_read = false;
+
+    // Device must be connected and configured for the task to run
+    if (USB_DeviceState != DEVICE_STATE_Configured) return;
+
+    Endpoint_SelectEndpoint(RAW_OUT_EPNUM);
+
+    // Check to see if a packet has been sent from the host
+    if (Endpoint_IsOUTReceived()) {
+        // Check to see if the packet contains data
+        if (Endpoint_IsReadWriteAllowed()) {
+            /* Read data */
+            Endpoint_Read_Stream_LE(data, sizeof(data), NULL);
+            data_read = true;
+        }
+
+        // Finalize the stream transfer to receive the last packet
+        Endpoint_ClearOUT();
+
+        if (data_read) {
+            raw_hid_receive(data, sizeof(data));
+        }
+    }
 }
 #endif
 
@@ -235,15 +218,13 @@ static void raw_hid_task(void)
  *
  * FIXME: Needs doc
  */
-static void Console_Task(void)
-{
+static void Console_Task(void) {
     /* Device must be connected and configured for the task to run */
-    if (USB_DeviceState != DEVICE_STATE_Configured)
-        return;
+    if (USB_DeviceState != DEVICE_STATE_Configured) return;
 
     uint8_t ep = Endpoint_GetCurrentEndpoint();
 
-#if 0
+#    if 0
     // TODO: impl receivechar()/recvchar()
     Endpoint_SelectEndpoint(CONSOLE_OUT_EPNUM);
 
@@ -266,7 +247,7 @@ static void Console_Task(void)
         /* Finalize the stream transfer to send the last packet */
         Endpoint_ClearOUT();
     }
-#endif
+#    endif
 
     /* IN packet */
     Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM);
@@ -276,8 +257,7 @@ static void Console_Task(void)
     }
 
     // fill empty bank
-    while (Endpoint_IsReadWriteAllowed())
-        Endpoint_Write_8(0);
+    while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0);
 
     // flash senchar packet
     if (Endpoint_IsINReady()) {
@@ -288,7 +268,6 @@ static void Console_Task(void)
 }
 #endif
 
-
 /*******************************************************************************
  * USB Events
  ******************************************************************************/
@@ -298,13 +277,12 @@ static void Console_Task(void)
  * 1) EVENT_USB_Device_Suspend
  * 2) EVENT_USB_Device_Reset
  * 3) EVENT_USB_Device_Wake
-*/
+ */
 /** \brief Event USB Device Connect
  *
  * FIXME: Needs doc
  */
-void EVENT_USB_Device_Connect(void)
-{
+void EVENT_USB_Device_Connect(void) {
     print("[C]");
     /* For battery powered device */
     if (!USB_IsInitialized) {
@@ -318,35 +296,30 @@ void EVENT_USB_Device_Connect(void)
  *
  * FIXME: Needs doc
  */
-void EVENT_USB_Device_Disconnect(void)
-{
+void EVENT_USB_Device_Disconnect(void) {
     print("[D]");
     /* For battery powered device */
     USB_IsInitialized = false;
-/* TODO: This doesn't work. After several plug in/outs can not be enumerated.
-    if (USB_IsInitialized) {
-        USB_Disable();  // Disable all interrupts
-       USB_Controller_Enable();
-        USB_INT_Enable(USB_INT_VBUSTI);
-    }
-*/
+    /* TODO: This doesn't work. After several plug in/outs can not be enumerated.
+        if (USB_IsInitialized) {
+            USB_Disable();  // Disable all interrupts
+        USB_Controller_Enable();
+            USB_INT_Enable(USB_INT_VBUSTI);
+        }
+    */
 }
 
 /** \brief Event USB Device Connect
  *
  * FIXME: Needs doc
  */
-void EVENT_USB_Device_Reset(void)
-{
-    print("[R]");
-}
+void EVENT_USB_Device_Reset(void) { print("[R]"); }
 
 /** \brief Event USB Device Connect
  *
  * FIXME: Needs doc
  */
-void EVENT_USB_Device_Suspend()
-{
+void EVENT_USB_Device_Suspend() {
     print("[S]");
 #ifdef SLEEP_LED_ENABLE
     sleep_led_enable();
@@ -357,8 +330,7 @@ void EVENT_USB_Device_Suspend()
  *
  * FIXME: Needs doc
  */
-void EVENT_USB_Device_WakeUp()
-{
+void EVENT_USB_Device_WakeUp() {
     print("[W]");
     suspend_wakeup_init();
 
@@ -369,23 +341,19 @@ void EVENT_USB_Device_WakeUp()
 #endif
 }
 
-
-
 #ifdef CONSOLE_ENABLE
 static bool console_flush = false;
-#define CONSOLE_FLUSH_SET(b)   do { \
-  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {\
-    console_flush = b; \
-  } \
-} while (0)
+#    define CONSOLE_FLUSH_SET(b)                                     \
+        do {                                                         \
+            ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { console_flush = b; } \
+        } while (0)
 
 /** \brief Event USB Device Start Of Frame
  *
  * FIXME: Needs doc
  * called every 1ms
  */
-void EVENT_USB_Device_StartOfFrame(void)
-{
+void EVENT_USB_Device_StartOfFrame(void) {
     static uint8_t count;
     if (++count % 50) return;
     count = 0;
@@ -404,44 +372,37 @@ void EVENT_USB_Device_StartOfFrame(void)
  * ATMega32u2 supports dual bank(ping-pong mode) only on endpoint 3 and 4,
  * it is safe to use single bank for all endpoints.
  */
-void EVENT_USB_Device_ConfigurationChanged(void)
-{
+void EVENT_USB_Device_ConfigurationChanged(void) {
     bool ConfigSuccess = true;
 
     /* Setup Keyboard HID Report Endpoints */
 #ifndef KEYBOARD_SHARED_EP
-    ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
-                                     KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE);
+    ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE);
 #endif
 
 #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
     /* Setup Mouse HID Report Endpoint */
-    ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
-                                     MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE);
+    ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE);
 #endif
 
 #ifdef SHARED_EP_ENABLE
     /* Setup Shared HID Report Endpoint */
-    ConfigSuccess &= ENDPOINT_CONFIG(SHARED_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
-                                     SHARED_EPSIZE, ENDPOINT_BANK_SINGLE);
+    ConfigSuccess &= ENDPOINT_CONFIG(SHARED_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, SHARED_EPSIZE, ENDPOINT_BANK_SINGLE);
 #endif
 
 #ifdef RAW_ENABLE
     /* Setup Raw HID Report Endpoints */
-    ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
-                                                                        RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
-    ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
-                                                                        RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
+    ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
+    ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
 #endif
 
 #ifdef CONSOLE_ENABLE
     /* Setup Console HID Report Endpoints */
-    ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
-                                     CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
-#if 0
+    ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
+#    if 0
     ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
                                      CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
-#endif
+#    endif
 #endif
 
 #ifdef MIDI_ENABLE
@@ -473,26 +434,23 @@ Other Device    Required    Optional    Optional    Optional    Optional    Opti
  *
  *  This is fired before passing along unhandled control requests to the library for processing internally.
  */
-void EVENT_USB_Device_ControlRequest(void)
-{
-    uint8_t* ReportData = NULL;
+void EVENT_USB_Device_ControlRequest(void) {
+    uint8_t *ReportData = NULL;
     uint8_t  ReportSize = 0;
 
     /* Handle HID Class specific requests */
-    switch (USB_ControlRequest.bRequest)
-    {
+    switch (USB_ControlRequest.bRequest) {
         case HID_REQ_GetReport:
-            if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
-            {
+            if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) {
                 Endpoint_ClearSETUP();
 
                 // Interface
                 switch (USB_ControlRequest.wIndex) {
-                case KEYBOARD_INTERFACE:
-                    // TODO: test/check
-                    ReportData = (uint8_t*)&keyboard_report_sent;
-                    ReportSize = sizeof(keyboard_report_sent);
-                    break;
+                    case KEYBOARD_INTERFACE:
+                        // TODO: test/check
+                        ReportData = (uint8_t *)&keyboard_report_sent;
+                        ReportSize = sizeof(keyboard_report_sent);
+                        break;
                 }
 
                 /* Write the report data to the control endpoint */
@@ -502,47 +460,43 @@ void EVENT_USB_Device_ControlRequest(void)
 
             break;
         case HID_REQ_SetReport:
-            if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
-            {
-
+            if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) {
                 // Interface
                 switch (USB_ControlRequest.wIndex) {
-                case KEYBOARD_INTERFACE:
+                    case KEYBOARD_INTERFACE:
 #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
-                case SHARED_INTERFACE:
+                    case SHARED_INTERFACE:
 #endif
-                    Endpoint_ClearSETUP();
+                        Endpoint_ClearSETUP();
 
-                    while (!(Endpoint_IsOUTReceived())) {
-                        if (USB_DeviceState == DEVICE_STATE_Unattached)
-                          return;
-                    }
+                        while (!(Endpoint_IsOUTReceived())) {
+                            if (USB_DeviceState == DEVICE_STATE_Unattached) return;
+                        }
 
-                    if (Endpoint_BytesInEndpoint() == 2) {
-                      uint8_t report_id = Endpoint_Read_8();
+                        if (Endpoint_BytesInEndpoint() == 2) {
+                            uint8_t report_id = Endpoint_Read_8();
 
-                      if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) {
-                        keyboard_led_stats = Endpoint_Read_8();
-                      }
-                    } else {
-                      keyboard_led_stats = Endpoint_Read_8();
-                    }
+                            if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) {
+                                keyboard_led_stats = Endpoint_Read_8();
+                            }
+                        } else {
+                            keyboard_led_stats = Endpoint_Read_8();
+                        }
 
-                    Endpoint_ClearOUT();
-                    Endpoint_ClearStatusStage();
-                    break;
+                        Endpoint_ClearOUT();
+                        Endpoint_ClearStatusStage();
+                        break;
                 }
-
             }
 
             break;
 
         case HID_REQ_GetProtocol:
-            if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
-            {
+            if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) {
                 if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) {
                     Endpoint_ClearSETUP();
-                    while (!(Endpoint_IsINReady()));
+                    while (!(Endpoint_IsINReady()))
+                        ;
                     Endpoint_Write_8(keyboard_protocol);
                     Endpoint_ClearIN();
                     Endpoint_ClearStatusStage();
@@ -551,8 +505,7 @@ void EVENT_USB_Device_ControlRequest(void)
 
             break;
         case HID_REQ_SetProtocol:
-            if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
-            {
+            if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) {
                 if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) {
                     Endpoint_ClearSETUP();
                     Endpoint_ClearStatusStage();
@@ -564,8 +517,7 @@ void EVENT_USB_Device_ControlRequest(void)
 
             break;
         case HID_REQ_SetIdle:
-            if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
-            {
+            if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) {
                 Endpoint_ClearSETUP();
                 Endpoint_ClearStatusStage();
 
@@ -574,10 +526,10 @@ void EVENT_USB_Device_ControlRequest(void)
 
             break;
         case HID_REQ_GetIdle:
-            if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
-            {
+            if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) {
                 Endpoint_ClearSETUP();
-                while (!(Endpoint_IsINReady()));
+                while (!(Endpoint_IsINReady()))
+                    ;
                 Endpoint_Write_8(keyboard_idle);
                 Endpoint_ClearIN();
                 Endpoint_ClearStatusStage();
@@ -598,54 +550,50 @@ void EVENT_USB_Device_ControlRequest(void)
  *
  * FIXME: Needs doc
  */
-static uint8_t keyboard_leds(void)
-{
-    return keyboard_led_stats;
-}
+static uint8_t keyboard_leds(void) { return keyboard_led_stats; }
 
 /** \brief Send Keyboard
  *
  * FIXME: Needs doc
  */
-static void send_keyboard(report_keyboard_t *report)
-{
+static void send_keyboard(report_keyboard_t *report) {
     uint8_t timeout = 255;
-    uint8_t where = where_to_send();
+    uint8_t where   = where_to_send();
 
 #ifdef BLUETOOTH_ENABLE
-  if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
-    #ifdef MODULE_ADAFRUIT_BLE
-      adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys));
-    #elif MODULE_RN42
-      bluefruit_serial_send(0xFD);
-      bluefruit_serial_send(0x09);
-      bluefruit_serial_send(0x01);
-      bluefruit_serial_send(report->mods);
-      bluefruit_serial_send(report->reserved);
-      for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
-        bluefruit_serial_send(report->keys[i]);
-      }
-    #else
-      bluefruit_serial_send(0xFD);
-      bluefruit_serial_send(report->mods);
-      bluefruit_serial_send(report->reserved);
-      for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
-        bluefruit_serial_send(report->keys[i]);
-      }
-    #endif
-  }
+    if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
+#    ifdef MODULE_ADAFRUIT_BLE
+        adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys));
+#    elif MODULE_RN42
+        bluefruit_serial_send(0xFD);
+        bluefruit_serial_send(0x09);
+        bluefruit_serial_send(0x01);
+        bluefruit_serial_send(report->mods);
+        bluefruit_serial_send(report->reserved);
+        for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
+            bluefruit_serial_send(report->keys[i]);
+        }
+#    else
+        bluefruit_serial_send(0xFD);
+        bluefruit_serial_send(report->mods);
+        bluefruit_serial_send(report->reserved);
+        for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
+            bluefruit_serial_send(report->keys[i]);
+        }
+#    endif
+    }
 #endif
 
     if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
-      return;
+        return;
     }
 
     /* Select the Keyboard Report Endpoint */
-    uint8_t ep = KEYBOARD_IN_EPNUM;
+    uint8_t ep   = KEYBOARD_IN_EPNUM;
     uint8_t size = KEYBOARD_REPORT_SIZE;
 #ifdef NKRO_ENABLE
     if (keyboard_protocol && keymap_config.nkro) {
-        ep = SHARED_IN_EPNUM;
+        ep   = SHARED_IN_EPNUM;
         size = sizeof(struct nkro_report);
     }
 #endif
@@ -666,38 +614,37 @@ static void send_keyboard(report_keyboard_t *report)
 
     keyboard_report_sent = *report;
 }
+
 /** \brief Send Mouse
  *
  * FIXME: Needs doc
  */
-static void send_mouse(report_mouse_t *report)
-{
+static void send_mouse(report_mouse_t *report) {
 #ifdef MOUSE_ENABLE
     uint8_t timeout = 255;
-    uint8_t where = where_to_send();
+    uint8_t where   = where_to_send();
 
-#ifdef BLUETOOTH_ENABLE
-  if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
-    #ifdef MODULE_ADAFRUIT_BLE
-      // FIXME: mouse buttons
-      adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons);
-    #else
-      bluefruit_serial_send(0xFD);
-      bluefruit_serial_send(0x00);
-      bluefruit_serial_send(0x03);
-      bluefruit_serial_send(report->buttons);
-      bluefruit_serial_send(report->x);
-      bluefruit_serial_send(report->y);
-      bluefruit_serial_send(report->v); // should try sending the wheel v here
-      bluefruit_serial_send(report->h); // should try sending the wheel h here
-      bluefruit_serial_send(0x00);
-    #endif
-  }
-#endif
+#    ifdef BLUETOOTH_ENABLE
+    if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
+#        ifdef MODULE_ADAFRUIT_BLE
+        // FIXME: mouse buttons
+        adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons);
+#        else
+        bluefruit_serial_send(0xFD);
+        bluefruit_serial_send(0x00);
+        bluefruit_serial_send(0x03);
+        bluefruit_serial_send(report->buttons);
+        bluefruit_serial_send(report->x);
+        bluefruit_serial_send(report->y);
+        bluefruit_serial_send(report->v);  // should try sending the wheel v here
+        bluefruit_serial_send(report->h);  // should try sending the wheel h here
+        bluefruit_serial_send(0x00);
+#        endif
+    }
+#    endif
 
     if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
-      return;
+        return;
     }
 
     /* Select the Mouse Report Endpoint */
@@ -719,18 +666,13 @@ static void send_mouse(report_mouse_t *report)
  *
  * FIXME: Needs doc
  */
-static void send_system(uint16_t data)
-{
+static void send_system(uint16_t data) {
 #ifdef EXTRAKEY_ENABLE
     uint8_t timeout = 255;
 
-    if (USB_DeviceState != DEVICE_STATE_Configured)
-        return;
+    if (USB_DeviceState != DEVICE_STATE_Configured) return;
 
-    report_extra_t r = {
-        .report_id = REPORT_ID_SYSTEM,
-        .usage = data - SYSTEM_POWER_DOWN + 1
-    };
+    report_extra_t r = {.report_id = REPORT_ID_SYSTEM, .usage = data - SYSTEM_POWER_DOWN + 1};
     Endpoint_SelectEndpoint(SHARED_IN_EPNUM);
 
     /* Check if write ready for a polling interval around 10ms */
@@ -746,52 +688,48 @@ static void send_system(uint16_t data)
  *
  * FIXME: Needs doc
  */
-static void send_consumer(uint16_t data)
-{
+static void send_consumer(uint16_t data) {
 #ifdef EXTRAKEY_ENABLE
     uint8_t timeout = 255;
-    uint8_t where = where_to_send();
+    uint8_t where   = where_to_send();
 
-#ifdef BLUETOOTH_ENABLE
+#    ifdef BLUETOOTH_ENABLE
     if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
-      #ifdef MODULE_ADAFRUIT_BLE
+#        ifdef MODULE_ADAFRUIT_BLE
         adafruit_ble_send_consumer_key(data, 0);
-      #elif MODULE_RN42
+#        elif MODULE_RN42
         static uint16_t last_data = 0;
         if (data == last_data) return;
-        last_data = data;
+        last_data       = data;
         uint16_t bitmap = CONSUMER2RN42(data);
         bluefruit_serial_send(0xFD);
         bluefruit_serial_send(0x03);
         bluefruit_serial_send(0x03);
-        bluefruit_serial_send(bitmap&0xFF);
-        bluefruit_serial_send((bitmap>>8)&0xFF);
-      #else
+        bluefruit_serial_send(bitmap & 0xFF);
+        bluefruit_serial_send((bitmap >> 8) & 0xFF);
+#        else
         static uint16_t last_data = 0;
         if (data == last_data) return;
-        last_data = data;
+        last_data       = data;
         uint16_t bitmap = CONSUMER2BLUEFRUIT(data);
         bluefruit_serial_send(0xFD);
         bluefruit_serial_send(0x00);
         bluefruit_serial_send(0x02);
-        bluefruit_serial_send((bitmap>>8)&0xFF);
-        bluefruit_serial_send(bitmap&0xFF);
+        bluefruit_serial_send((bitmap >> 8) & 0xFF);
+        bluefruit_serial_send(bitmap & 0xFF);
         bluefruit_serial_send(0x00);
         bluefruit_serial_send(0x00);
         bluefruit_serial_send(0x00);
         bluefruit_serial_send(0x00);
-      #endif
+#        endif
     }
-#endif
+#    endif
 
     if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
-      return;
+        return;
     }
 
-    report_extra_t r = {
-        .report_id = REPORT_ID_CONSUMER,
-        .usage = data
-    };
+    report_extra_t r = {.report_id = REPORT_ID_CONSUMER, .usage = data};
     Endpoint_SelectEndpoint(SHARED_IN_EPNUM);
 
     /* Check if write ready for a polling interval around 10ms */
@@ -803,18 +741,16 @@ static void send_consumer(uint16_t data)
 #endif
 }
 
-
 /*******************************************************************************
  * sendchar
  ******************************************************************************/
 #ifdef CONSOLE_ENABLE
-#define SEND_TIMEOUT 5
+#    define SEND_TIMEOUT 5
 /** \brief Send Char
  *
  * FIXME: Needs doc
  */
-int8_t sendchar(uint8_t c)
-{
+int8_t sendchar(uint8_t c) {
     // Not wait once timeouted.
     // Because sendchar() is called so many times, waiting each call causes big lag.
     static bool timeouted = false;
@@ -823,8 +759,7 @@ int8_t sendchar(uint8_t c)
     // or char will be lost. These two function is mutually exclusive.
     CONSOLE_FLUSH_SET(false);
 
-    if (USB_DeviceState != DEVICE_STATE_Configured)
-        return -1;
+    if (USB_DeviceState != DEVICE_STATE_Configured) return -1;
 
     uint8_t ep = Endpoint_GetCurrentEndpoint();
     Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM);
@@ -857,7 +792,8 @@ int8_t sendchar(uint8_t c)
 
     // send when bank is full
     if (!Endpoint_IsReadWriteAllowed()) {
-        while (!(Endpoint_IsINReady()));
+        while (!(Endpoint_IsINReady()))
+            ;
         Endpoint_ClearIN();
     } else {
         CONSOLE_FLUSH_SET(true);
@@ -870,10 +806,7 @@ ERROR_EXIT:
     return -1;
 }
 #else
-int8_t sendchar(uint8_t c)
-{
-    return 0;
-}
+int8_t sendchar(uint8_t c) { return 0; }
 #endif
 
 /*******************************************************************************
@@ -881,33 +814,28 @@ int8_t sendchar(uint8_t c)
  ******************************************************************************/
 
 #ifdef MIDI_ENABLE
-USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface =
-{
-  .Config =
-  {
-    .StreamingInterfaceNumber = AS_INTERFACE,
-    .DataINEndpoint           =
-    {
-      .Address          = MIDI_STREAM_IN_EPADDR,
-      .Size             = MIDI_STREAM_EPSIZE,
-      .Banks            = 1,
-    },
-    .DataOUTEndpoint          =
-    {
-      .Address          = MIDI_STREAM_OUT_EPADDR,
-      .Size             = MIDI_STREAM_EPSIZE,
-      .Banks            = 1,
-    },
-  },
+USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = {
+    .Config =
+        {
+            .StreamingInterfaceNumber = AS_INTERFACE,
+            .DataINEndpoint =
+                {
+                    .Address = MIDI_STREAM_IN_EPADDR,
+                    .Size    = MIDI_STREAM_EPSIZE,
+                    .Banks   = 1,
+                },
+            .DataOUTEndpoint =
+                {
+                    .Address = MIDI_STREAM_OUT_EPADDR,
+                    .Size    = MIDI_STREAM_EPSIZE,
+                    .Banks   = 1,
+                },
+        },
 };
 
-void send_midi_packet(MIDI_EventPacket_t* event) {
-  MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event);
-}
+void send_midi_packet(MIDI_EventPacket_t *event) { MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event); }
 
-bool recv_midi_packet(MIDI_EventPacket_t* const event) {
-  return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event);
-}
+bool recv_midi_packet(MIDI_EventPacket_t *const event) { return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event); }
 
 #endif
 
@@ -920,66 +848,60 @@ bool recv_midi_packet(MIDI_EventPacket_t* const event) {
  *
  * FIXME: Needs doc
  */
-void virtser_init(void)
-{
-  cdc_device.State.ControlLineStates.DeviceToHost = CDC_CONTROL_LINE_IN_DSR ;
-  CDC_Device_SendControlLineStateChange(&cdc_device);
+void virtser_init(void) {
+    cdc_device.State.ControlLineStates.DeviceToHost = CDC_CONTROL_LINE_IN_DSR;
+    CDC_Device_SendControlLineStateChange(&cdc_device);
 }
 
 /** \brief Virtual Serial Receive
  *
  * FIXME: Needs doc
  */
-void virtser_recv(uint8_t c) __attribute__ ((weak));
-void virtser_recv(uint8_t c)
-{
-  // Ignore by default
+void virtser_recv(uint8_t c) __attribute__((weak));
+void virtser_recv(uint8_t c) {
+    // Ignore by default
 }
 
 /** \brief Virtual Serial Task
  *
  * FIXME: Needs doc
  */
-void virtser_task(void)
-{
-  uint16_t count = CDC_Device_BytesReceived(&cdc_device);
-  uint8_t ch;
-  if (count)
-  {
-    ch = CDC_Device_ReceiveByte(&cdc_device);
-    virtser_recv(ch);
-  }
+void virtser_task(void) {
+    uint16_t count = CDC_Device_BytesReceived(&cdc_device);
+    uint8_t  ch;
+    if (count) {
+        ch = CDC_Device_ReceiveByte(&cdc_device);
+        virtser_recv(ch);
+    }
 }
 /** \brief Virtual Serial Send
  *
  * FIXME: Needs doc
  */
-void virtser_send(const uint8_t byte)
-{
-  uint8_t timeout = 255;
-  uint8_t ep = Endpoint_GetCurrentEndpoint();
+void virtser_send(const uint8_t byte) {
+    uint8_t timeout = 255;
+    uint8_t ep      = Endpoint_GetCurrentEndpoint();
 
-  if (cdc_device.State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR)
-  {
-    /* IN packet */
-    Endpoint_SelectEndpoint(cdc_device.Config.DataINEndpoint.Address);
+    if (cdc_device.State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR) {
+        /* IN packet */
+        Endpoint_SelectEndpoint(cdc_device.Config.DataINEndpoint.Address);
 
-    if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) {
-        Endpoint_SelectEndpoint(ep);
-        return;
-    }
+        if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) {
+            Endpoint_SelectEndpoint(ep);
+            return;
+        }
 
-    while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
+        while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
 
-    Endpoint_Write_8(byte);
-    CDC_Device_Flush(&cdc_device);
+        Endpoint_Write_8(byte);
+        CDC_Device_Flush(&cdc_device);
 
-    if (Endpoint_IsINReady()) {
-      Endpoint_ClearIN();
-    }
+        if (Endpoint_IsINReady()) {
+            Endpoint_ClearIN();
+        }
 
-    Endpoint_SelectEndpoint(ep);
-  }
+        Endpoint_SelectEndpoint(ep);
+    }
 }
 #endif
 
@@ -990,8 +912,7 @@ void virtser_send(const uint8_t byte)
  *
  * FIXME: Needs doc
  */
-static void setup_mcu(void)
-{
+static void setup_mcu(void) {
     /* Disable watchdog if enabled by bootloader/fuses */
     MCUSR &= ~(1 << WDRF);
     wdt_disable();
@@ -1007,8 +928,7 @@ static void setup_mcu(void)
  *
  * FIXME: Needs doc
  */
-static void setup_usb(void)
-{
+static void setup_usb(void) {
     // Leonardo needs. Without this USB device is not recognized.
     USB_Disable();
 
@@ -1023,9 +943,8 @@ static void setup_usb(void)
  *
  * FIXME: Needs doc
  */
-int main(void)  __attribute__ ((weak));
-int main(void)
-{
+int main(void) __attribute__((weak));
+int main(void) {
 #ifdef MIDI_ENABLE
     setup_midi();
 #endif
@@ -1043,11 +962,11 @@ int main(void)
 
 #ifdef WAIT_FOR_USB
     while (USB_DeviceState != DEVICE_STATE_Configured) {
-    #if defined(INTERRUPT_CONTROL_ENDPOINT)
-            ;
-    #else
-            USB_USBTask();
-    #endif
+#    if defined(INTERRUPT_CONTROL_ENDPOINT)
+        ;
+#    else
+        USB_USBTask();
+#    endif
     }
     print("USB configured.\n");
 #else
@@ -1066,15 +985,15 @@ int main(void)
 
     print("Keyboard start.\n");
     while (1) {
-        #if !defined(NO_USB_STARTUP_CHECK)
+#if !defined(NO_USB_STARTUP_CHECK)
         while (USB_DeviceState == DEVICE_STATE_Suspended) {
             print("[s]");
             suspend_power_down();
             if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
-                    USB_Device_SendRemoteWakeup();
+                USB_Device_SendRemoteWakeup();
             }
         }
-        #endif
+#endif
 
         keyboard_task();
 
@@ -1102,14 +1021,7 @@ int main(void)
 #if !defined(INTERRUPT_CONTROL_ENDPOINT)
         USB_USBTask();
 #endif
-
     }
 }
 
-uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
-                                    const uint16_t wIndex,
-                                    const void** const DescriptorAddress)
-{
-  return get_usb_descriptor(wValue, wIndex, DescriptorAddress);
-}
-
+uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint16_t wIndex, const void **const DescriptorAddress) { return get_usb_descriptor(wValue, wIndex, DescriptorAddress); }
index 7364cdf7ceb3ad10fc99e721632acf7dea423dbf..652e4e79b726d79d1d88bbfa7dca6a010ea91f08 100644 (file)
@@ -62,27 +62,27 @@ extern host_driver_t lufa_driver;
 typedef struct {
     uint8_t  report_id;
     uint16_t usage;
-} __attribute__ ((packed)) report_extra_t;
+} __attribute__((packed)) report_extra_t;
 
 #ifdef API_ENABLE
-  #include "api.h"
+#    include "api.h"
 #endif
 
 #ifdef API_SYSEX_ENABLE
-  #include "api_sysex.h"
-  // Allocate space for encoding overhead.
-  //The header and terminator are not stored to save a few bytes of precious ram
-  #define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
+#    include "api_sysex.h"
+// Allocate space for encoding overhead.
+// The header and terminator are not stored to save a few bytes of precious ram
+#    define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
 #endif
 
 // #if LUFA_VERSION_INTEGER < 0x120730
 //     /* old API 120219 */
 //     #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank)    Endpoint_ConfigureEndpoint(epnum, eptype, epdir, epsize, epbank)
 // #else
-    /* new API >= 120730 */
-    #define ENDPOINT_BANK_SINGLE 1
-    #define ENDPOINT_BANK_DOUBLE 2
-    #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank)    Endpoint_ConfigureEndpoint((epdir) | (epnum) , eptype, epsize, epbank)
+/* new API >= 120730 */
+#define ENDPOINT_BANK_SINGLE 1
+#define ENDPOINT_BANK_DOUBLE 2
+#define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum), eptype, epsize, epbank)
 // #endif
 
 #endif
index 42de806120e23d37de61584e0a16f5a34e951cba..b115ea9691efbf151847ad9921bbfa5f29b99e2b 100644 (file)
@@ -15,7 +15,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "lufa.h"
 #include "outputselect.h"
 #ifdef MODULE_ADAFRUIT_BLE
-    #include "adafruit_ble.h"
+#    include "adafruit_ble.h"
 #endif
 
 uint8_t desired_output = OUTPUT_DEFAULT;
@@ -33,9 +33,7 @@ void set_output(uint8_t output) {
  *
  * FIXME: Needs doc
  */
-__attribute__((weak))
-void set_output_user(uint8_t output) {
-}
+__attribute__((weak)) void set_output_user(uint8_t output) {}
 
 /** \brief Auto Detect Output
  *
@@ -53,7 +51,7 @@ uint8_t auto_detect_output(void) {
 #endif
 
 #ifdef BLUETOOTH_ENABLE
-    return OUTPUT_BLUETOOTH; // should check if BT is connected here
+    return OUTPUT_BLUETOOTH;  // should check if BT is connected here
 #endif
 
     return OUTPUT_NONE;
@@ -69,4 +67,3 @@ uint8_t where_to_send(void) {
     }
     return desired_output;
 }
-
index 28cc3298e61f9a3869b79a07a18e256dd83055af..24fe4daa24fef15d10b217690edf8d5e433087af 100644 (file)
@@ -27,14 +27,14 @@ enum outputs {
  * backward compatibility for BLUETOOTH_ENABLE, send to BT and USB by default
  */
 #ifndef OUTPUT_DEFAULT
-    #ifdef BLUETOOTH_ENABLE
-        #define OUTPUT_DEFAULT OUTPUT_USB_AND_BT
-    #else
-        #define OUTPUT_DEFAULT OUTPUT_AUTO
-    #endif
+#    ifdef BLUETOOTH_ENABLE
+#        define OUTPUT_DEFAULT OUTPUT_USB_AND_BT
+#    else
+#        define OUTPUT_DEFAULT OUTPUT_AUTO
+#    endif
 #endif
 
-void set_output(uint8_t output);
-void set_output_user(uint8_t output);
+void    set_output(uint8_t output);
+void    set_output_user(uint8_t output);
 uint8_t auto_detect_output(void);
 uint8_t where_to_send(void);
\ No newline at end of file
index 0d3a5aaa4251d434ff7912351b4e4b517831c145..b02a6933d2bdb1149c6fa996efb0e2b19ca789d9 100644 (file)
@@ -43,98 +43,95 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "m0110.h"
 #include "debug.h"
 
-
-static inline uint8_t raw2scan(uint8_t raw);
-static inline uint8_t inquiry(void);
-static inline uint8_t instant(void);
-static inline void clock_lo(void);
-static inline void clock_hi(void);
-static inline bool clock_in(void);
-static inline void data_lo(void);
-static inline void data_hi(void);
-static inline bool data_in(void);
+static inline uint8_t  raw2scan(uint8_t raw);
+static inline uint8_t  inquiry(void);
+static inline uint8_t  instant(void);
+static inline void     clock_lo(void);
+static inline void     clock_hi(void);
+static inline bool     clock_in(void);
+static inline void     data_lo(void);
+static inline void     data_hi(void);
+static inline bool     data_in(void);
 static inline uint16_t wait_clock_lo(uint16_t us);
 static inline uint16_t wait_clock_hi(uint16_t us);
 static inline uint16_t wait_data_lo(uint16_t us);
 static inline uint16_t wait_data_hi(uint16_t us);
-static inline void idle(void);
-static inline void request(void);
-
-
-#define WAIT_US(stat, us, err) do { \
-    if (!wait_##stat(us)) { \
-        m0110_error = err; \
-        goto ERROR; \
-    } \
-} while (0)
-
-#define WAIT_MS(stat, ms, err) do { \
-    uint16_t _ms = ms; \
-    while (_ms) { \
-        if (wait_##stat(1000)) { \
-            break; \
-        } \
-        _ms--; \
-    } \
-    if (_ms == 0) { \
-        m0110_error = err; \
-        goto ERROR; \
-    } \
-} while (0)
-
-#define KEY(raw)        ((raw) & 0x7f)
-#define IS_BREAK(raw)   (((raw) & 0x80) == 0x80)
-
+static inline void     idle(void);
+static inline void     request(void);
+
+#define WAIT_US(stat, us, err)  \
+    do {                        \
+        if (!wait_##stat(us)) { \
+            m0110_error = err;  \
+            goto ERROR;         \
+        }                       \
+    } while (0)
+
+#define WAIT_MS(stat, ms, err)       \
+    do {                             \
+        uint16_t _ms = ms;           \
+        while (_ms) {                \
+            if (wait_##stat(1000)) { \
+                break;               \
+            }                        \
+            _ms--;                   \
+        }                            \
+        if (_ms == 0) {              \
+            m0110_error = err;       \
+            goto ERROR;              \
+        }                            \
+    } while (0)
+
+#define KEY(raw) ((raw)&0x7f)
+#define IS_BREAK(raw) (((raw)&0x80) == 0x80)
 
 uint8_t m0110_error = 0;
 
-
-void m0110_init(void)
-{
+void m0110_init(void) {
     idle();
     _delay_ms(1000);
 
-/* Not needed to initialize in fact.
-    uint8_t data;
-    m0110_send(M0110_MODEL);
-    data = m0110_recv();
-    print("m0110_init model: "); phex(data); print("\n");
+    /* Not needed to initialize in fact.
+        uint8_t data;
+        m0110_send(M0110_MODEL);
+        data = m0110_recv();
+        print("m0110_init model: "); phex(data); print("\n");
 
-    m0110_send(M0110_TEST);
-    data = m0110_recv();
-    print("m0110_init test: "); phex(data); print("\n");
-*/
+        m0110_send(M0110_TEST);
+        data = m0110_recv();
+        print("m0110_init test: "); phex(data); print("\n");
+    */
 }
 
-uint8_t m0110_send(uint8_t data)
-{
+uint8_t m0110_send(uint8_t data) {
     m0110_error = 0;
 
     request();
     WAIT_MS(clock_lo, 250, 1);  // keyboard may block long time
     for (uint8_t bit = 0x80; bit; bit >>= 1) {
         WAIT_US(clock_lo, 250, 3);
-        if (data&bit) {
+        if (data & bit) {
             data_hi();
         } else {
             data_lo();
         }
         WAIT_US(clock_hi, 200, 4);
     }
-    _delay_us(100); // hold last bit for 80us
+    _delay_us(100);  // hold last bit for 80us
     idle();
     return 1;
 ERROR:
-    print("m0110_send err: "); phex(m0110_error); print("\n");
+    print("m0110_send err: ");
+    phex(m0110_error);
+    print("\n");
     _delay_ms(500);
     idle();
     return 0;
 }
 
-uint8_t m0110_recv(void)
-{
+uint8_t m0110_recv(void) {
     uint8_t data = 0;
-    m0110_error = 0;
+    m0110_error  = 0;
 
     WAIT_MS(clock_lo, 250, 1);  // keyboard may block long time
     for (uint8_t i = 0; i < 8; i++) {
@@ -148,7 +145,9 @@ uint8_t m0110_recv(void)
     idle();
     return data;
 ERROR:
-    print("m0110_recv err: "); phex(m0110_error); print("\n");
+    print("m0110_recv err: ");
+    phex(m0110_error);
+    print("\n");
     _delay_ms(500);
     idle();
     return 0xFF;
@@ -199,26 +198,25 @@ During Calc key is hold:
     *b: Shift(d) event is ignored.
     *c: Arrow/Calc(d) event is ignored.
 */
-uint8_t m0110_recv_key(void)
-{
-    static uint8_t keybuf = 0x00;
+uint8_t m0110_recv_key(void) {
+    static uint8_t keybuf  = 0x00;
     static uint8_t keybuf2 = 0x00;
-    static uint8_t rawbuf = 0x00;
-    uint8_t raw, raw2, raw3;
+    static uint8_t rawbuf  = 0x00;
+    uint8_t        raw, raw2, raw3;
 
     if (keybuf) {
-        raw = keybuf;
+        raw    = keybuf;
         keybuf = 0x00;
         return raw;
     }
     if (keybuf2) {
-        raw = keybuf2;
+        raw     = keybuf2;
         keybuf2 = 0x00;
         return raw;
     }
 
     if (rawbuf) {
-        raw = rawbuf;
+        raw    = rawbuf;
         rawbuf = 0x00;
     } else {
         raw = instant();  // Use INSTANT for better response. Should be INQUIRY ?
@@ -233,8 +231,8 @@ uint8_t m0110_recv_key(void)
                 case M0110_ARROW_RIGHT:
                     if (IS_BREAK(raw2)) {
                         // Case B,F,N:
-                        keybuf = (raw2scan(raw2) | M0110_CALC_OFFSET); // Calc(u)
-                        return (raw2scan(raw2) | M0110_KEYPAD_OFFSET); // Arrow(u)
+                        keybuf = (raw2scan(raw2) | M0110_CALC_OFFSET);  // Calc(u)
+                        return (raw2scan(raw2) | M0110_KEYPAD_OFFSET);  // Arrow(u)
                     }
                     break;
             }
@@ -247,7 +245,7 @@ uint8_t m0110_recv_key(void)
                 case M0110_SHIFT:
                     // Case: 5-8,C,G,H
                     rawbuf = raw2;
-                    return raw2scan(raw); // Shift(d/u)
+                    return raw2scan(raw);  // Shift(d/u)
                     break;
                 case M0110_KEYPAD:
                     // Shift + Arrow, Calc, or etc.
@@ -261,38 +259,38 @@ uint8_t m0110_recv_key(void)
                                 if (IS_BREAK(raw3)) {
                                     // Case 4:
                                     print("(4)\n");
-                                    keybuf2 = raw2scan(raw); // Shift(u)
-                                    keybuf  = (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(u)
-                                    return (raw2scan(raw3) | M0110_KEYPAD_OFFSET);  // Arrow(u)
+                                    keybuf2 = raw2scan(raw);                         // Shift(u)
+                                    keybuf  = (raw2scan(raw3) | M0110_CALC_OFFSET);  // Calc(u)
+                                    return (raw2scan(raw3) | M0110_KEYPAD_OFFSET);   // Arrow(u)
                                 } else {
                                     // Case 3:
                                     print("(3)\n");
-                                    return (raw2scan(raw)); // Shift(u)
+                                    return (raw2scan(raw));  // Shift(u)
                                 }
                             } else {
                                 if (IS_BREAK(raw3)) {
                                     // Case 2:
                                     print("(2)\n");
-                                    keybuf  = (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(u)
+                                    keybuf = (raw2scan(raw3) | M0110_CALC_OFFSET);  // Calc(u)
                                     return (raw2scan(raw3) | M0110_KEYPAD_OFFSET);  // Arrow(u)
                                 } else {
                                     // Case 1:
                                     print("(1)\n");
-                                    return (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(d)
+                                    return (raw2scan(raw3) | M0110_CALC_OFFSET);  // Calc(d)
                                 }
                             }
                             break;
                         default:
                             // Shift + Keypad
                             keybuf = (raw2scan(raw3) | M0110_KEYPAD_OFFSET);
-                            return raw2scan(raw);   // Shift(d/u)
+                            return raw2scan(raw);  // Shift(d/u)
                             break;
                     }
                     break;
                 default:
                     // Shift + Normal keys
                     keybuf = raw2scan(raw2);
-                    return raw2scan(raw);   // Shift(d/u)
+                    return raw2scan(raw);  // Shift(d/u)
                     break;
             }
             break;
@@ -303,103 +301,97 @@ uint8_t m0110_recv_key(void)
     }
 }
 
+static inline uint8_t raw2scan(uint8_t raw) { return (raw == M0110_NULL) ? M0110_NULL : ((raw == M0110_ERROR) ? M0110_ERROR : (((raw & 0x80) | ((raw & 0x7F) >> 1)))); }
 
-static inline uint8_t raw2scan(uint8_t raw) {
-    return (raw == M0110_NULL) ?  M0110_NULL : (
-                (raw == M0110_ERROR) ?  M0110_ERROR : (
-                    ((raw&0x80) | ((raw&0x7F)>>1))
-                )
-           );
-}
-
-static inline uint8_t inquiry(void)
-{
+static inline uint8_t inquiry(void) {
     m0110_send(M0110_INQUIRY);
     return m0110_recv();
 }
 
-static inline uint8_t instant(void)
-{
+static inline uint8_t instant(void) {
     m0110_send(M0110_INSTANT);
     uint8_t data = m0110_recv();
     if (data != M0110_NULL) {
-        debug_hex(data); debug(" ");
+        debug_hex(data);
+        debug(" ");
     }
     return data;
 }
 
-static inline void clock_lo()
-{
-    M0110_CLOCK_PORT &= ~(1<<M0110_CLOCK_BIT);
-    M0110_CLOCK_DDR  |=  (1<<M0110_CLOCK_BIT);
+static inline void clock_lo() {
+    M0110_CLOCK_PORT &= ~(1 << M0110_CLOCK_BIT);
+    M0110_CLOCK_DDR |= (1 << M0110_CLOCK_BIT);
 }
-static inline void clock_hi()
-{
+static inline void clock_hi() {
     /* input with pull up */
-    M0110_CLOCK_DDR  &= ~(1<<M0110_CLOCK_BIT);
-    M0110_CLOCK_PORT |=  (1<<M0110_CLOCK_BIT);
+    M0110_CLOCK_DDR &= ~(1 << M0110_CLOCK_BIT);
+    M0110_CLOCK_PORT |= (1 << M0110_CLOCK_BIT);
 }
-static inline bool clock_in()
-{
-    M0110_CLOCK_DDR  &= ~(1<<M0110_CLOCK_BIT);
-    M0110_CLOCK_PORT |=  (1<<M0110_CLOCK_BIT);
+static inline bool clock_in() {
+    M0110_CLOCK_DDR &= ~(1 << M0110_CLOCK_BIT);
+    M0110_CLOCK_PORT |= (1 << M0110_CLOCK_BIT);
     _delay_us(1);
-    return M0110_CLOCK_PIN&(1<<M0110_CLOCK_BIT);
+    return M0110_CLOCK_PIN & (1 << M0110_CLOCK_BIT);
 }
-static inline void data_lo()
-{
-    M0110_DATA_PORT &= ~(1<<M0110_DATA_BIT);
-    M0110_DATA_DDR  |=  (1<<M0110_DATA_BIT);
+static inline void data_lo() {
+    M0110_DATA_PORT &= ~(1 << M0110_DATA_BIT);
+    M0110_DATA_DDR |= (1 << M0110_DATA_BIT);
 }
-static inline void data_hi()
-{
+static inline void data_hi() {
     /* input with pull up */
-    M0110_DATA_DDR  &= ~(1<<M0110_DATA_BIT);
-    M0110_DATA_PORT |=  (1<<M0110_DATA_BIT);
+    M0110_DATA_DDR &= ~(1 << M0110_DATA_BIT);
+    M0110_DATA_PORT |= (1 << M0110_DATA_BIT);
 }
-static inline bool data_in()
-{
-    M0110_DATA_DDR  &= ~(1<<M0110_DATA_BIT);
-    M0110_DATA_PORT |=  (1<<M0110_DATA_BIT);
+static inline bool data_in() {
+    M0110_DATA_DDR &= ~(1 << M0110_DATA_BIT);
+    M0110_DATA_PORT |= (1 << M0110_DATA_BIT);
     _delay_us(1);
-    return M0110_DATA_PIN&(1<<M0110_DATA_BIT);
+    return M0110_DATA_PIN & (1 << M0110_DATA_BIT);
 }
 
-static inline uint16_t wait_clock_lo(uint16_t us)
-{
-    while (clock_in()  && us) { asm(""); _delay_us(1); us--; }
+static inline uint16_t wait_clock_lo(uint16_t us) {
+    while (clock_in() && us) {
+        asm("");
+        _delay_us(1);
+        us--;
+    }
     return us;
 }
-static inline uint16_t wait_clock_hi(uint16_t us)
-{
-    while (!clock_in() && us) { asm(""); _delay_us(1); us--; }
+static inline uint16_t wait_clock_hi(uint16_t us) {
+    while (!clock_in() && us) {
+        asm("");
+        _delay_us(1);
+        us--;
+    }
     return us;
 }
-static inline uint16_t wait_data_lo(uint16_t us)
-{
-    while (data_in() && us)  { asm(""); _delay_us(1); us--; }
+static inline uint16_t wait_data_lo(uint16_t us) {
+    while (data_in() && us) {
+        asm("");
+        _delay_us(1);
+        us--;
+    }
     return us;
 }
-static inline uint16_t wait_data_hi(uint16_t us)
-{
-    while (!data_in() && us)  { asm(""); _delay_us(1); us--; }
+static inline uint16_t wait_data_hi(uint16_t us) {
+    while (!data_in() && us) {
+        asm("");
+        _delay_us(1);
+        us--;
+    }
     return us;
 }
 
-static inline void idle(void)
-{
+static inline void idle(void) {
     clock_hi();
     data_hi();
 }
 
-static inline void request(void)
-{
+static inline void request(void) {
     clock_hi();
     data_lo();
 }
 
-
-
 /*
 Primitive M0110 Library for AVR
 ==============================
index 2b95ed34d57a7148cd890ecebe641466b2d12469..3f9686b0d926e3a962e653f61d6fd04eb3a72e26 100644 (file)
@@ -38,51 +38,43 @@ POSSIBILITY OF SUCH DAMAGE.
 #ifndef M0110_H
 #define M0110_H
 
-
 /* port settings for clock and data line */
-#if !(defined(M0110_CLOCK_PORT) && \
-      defined(M0110_CLOCK_PIN) && \
-      defined(M0110_CLOCK_DDR) && \
-      defined(M0110_CLOCK_BIT))
-#   error "M0110 clock port setting is required in config.h"
+#if !(defined(M0110_CLOCK_PORT) && defined(M0110_CLOCK_PIN) && defined(M0110_CLOCK_DDR) && defined(M0110_CLOCK_BIT))
+#    error "M0110 clock port setting is required in config.h"
 #endif
 
-#if !(defined(M0110_DATA_PORT) && \
-      defined(M0110_DATA_PIN) && \
-      defined(M0110_DATA_DDR) && \
-      defined(M0110_DATA_BIT))
-#   error "M0110 data port setting is required in config.h"
+#if !(defined(M0110_DATA_PORT) && defined(M0110_DATA_PIN) && defined(M0110_DATA_DDR) && defined(M0110_DATA_BIT))
+#    error "M0110 data port setting is required in config.h"
 #endif
 
 /* Commands */
-#define M0110_INQUIRY       0x10
-#define M0110_INSTANT       0x14
-#define M0110_MODEL         0x16
-#define M0110_TEST          0x36
+#define M0110_INQUIRY 0x10
+#define M0110_INSTANT 0x14
+#define M0110_MODEL 0x16
+#define M0110_TEST 0x36
 
 /* Response(raw byte from M0110) */
-#define M0110_NULL          0x7B
-#define M0110_KEYPAD        0x79
-#define M0110_TEST_ACK      0x7D
-#define M0110_TEST_NAK      0x77
-#define M0110_SHIFT         0x71
-#define M0110_ARROW_UP      0x1B
-#define M0110_ARROW_DOWN    0x11
-#define M0110_ARROW_LEFT    0x0D
-#define M0110_ARROW_RIGHT   0x05
+#define M0110_NULL 0x7B
+#define M0110_KEYPAD 0x79
+#define M0110_TEST_ACK 0x7D
+#define M0110_TEST_NAK 0x77
+#define M0110_SHIFT 0x71
+#define M0110_ARROW_UP 0x1B
+#define M0110_ARROW_DOWN 0x11
+#define M0110_ARROW_LEFT 0x0D
+#define M0110_ARROW_RIGHT 0x05
 
 /* This inidcates no response. */
-#define M0110_ERROR         0xFF
+#define M0110_ERROR 0xFF
 
 /* scan code offset for keypad and arrow keys */
 #define M0110_KEYPAD_OFFSET 0x40
-#define M0110_CALC_OFFSET   0x60
-
+#define M0110_CALC_OFFSET 0x60
 
 extern uint8_t m0110_error;
 
 /* host role */
-void m0110_init(void);
+void    m0110_init(void);
 uint8_t m0110_send(uint8_t data);
 uint8_t m0110_recv(void);
 uint8_t m0110_recv_key(void);
index 947077cd2453c64ad1bbad9ef3beaed33734608d..dbaf108fa18699aede0957b1feb1792063bd73c2 100644 (file)
@@ -6,20 +6,14 @@
 
 #define DEFAULT_CONFIGURATION (1)
 
-
-HIDKeyboard::HIDKeyboard(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release)
-{
-    USBDevice::connect();
-}
+HIDKeyboard::HIDKeyboard(uint16_t vendor_id, uint16_t product_id, uint16_t product_release) : USBDevice(vendor_id, product_id, product_release) { USBDevice::connect(); }
 
 bool HIDKeyboard::sendReport(report_keyboard_t report) {
     USBDevice::write(EP1IN, report.raw, sizeof(report), MAX_PACKET_SIZE_EP1);
     return true;
 }
 
-uint8_t HIDKeyboard::leds() {
-    return led_state;
-}
+uint8_t HIDKeyboard::leds() { return led_state; }
 
 bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) {
     if (configuration != DEFAULT_CONFIGURATION) {
@@ -28,80 +22,86 @@ bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) {
 
     // Configure endpoints > 0
     addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT);
-    //addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
+    // addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
 
     // We activate the endpoint to be able to recceive data
-    //readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
+    // readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
     return true;
 }
 
-
-uint8_t * HIDKeyboard::stringImanufacturerDesc() {
+uint8_t *HIDKeyboard::stringImanufacturerDesc() {
     static uint8_t stringImanufacturerDescriptor[] = {
-        0x18,                                            /*bLength*/
-        STRING_DESCRIPTOR,                               /*bDescriptorType 0x03*/
-        't',0,'m',0,'k',0,'-',0,'k',0,'b',0,'d',0,'.',0,'c',0,'o',0,'m',0   /*bString iManufacturer*/
+        0x18,              /*bLength*/
+        STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
+        't',
+        0,
+        'm',
+        0,
+        'k',
+        0,
+        '-',
+        0,
+        'k',
+        0,
+        'b',
+        0,
+        'd',
+        0,
+        '.',
+        0,
+        'c',
+        0,
+        'o',
+        0,
+        'm',
+        0 /*bString iManufacturer*/
     };
     return stringImanufacturerDescriptor;
 }
 
-uint8_t * HIDKeyboard::stringIproductDesc() {
+uint8_t *HIDKeyboard::stringIproductDesc() {
     static uint8_t stringIproductDescriptor[] = {
-        0x0a,                                                       /*bLength*/
-        STRING_DESCRIPTOR,                                          /*bDescriptorType 0x03*/
-        'm',0,'b',0,'e',0,'d',0                                     /*bString iProduct*/
+        0x0a,              /*bLength*/
+        STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
+        'm',
+        0,
+        'b',
+        0,
+        'e',
+        0,
+        'd',
+        0 /*bString iProduct*/
     };
     return stringIproductDescriptor;
 }
 
-uint8_t * HIDKeyboard::stringIserialDesc() {
+uint8_t *HIDKeyboard::stringIserialDesc() {
     static uint8_t stringIserialDescriptor[] = {
-        0x04,                                                           /*bLength*/
-        STRING_DESCRIPTOR,                                              /*bDescriptorType 0x03*/
-        '0',0                                                           /*bString iSerial*/
+        0x04,              /*bLength*/
+        STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
+        '0', 0             /*bString iSerial*/
     };
     return stringIserialDescriptor;
 }
 
-uint8_t * HIDKeyboard::reportDesc() {
+uint8_t *HIDKeyboard::reportDesc() {
     static uint8_t reportDescriptor[] = {
-        USAGE_PAGE(1), 0x01,                    // Generic Desktop
-        USAGE(1), 0x06,                         // Keyboard
-        COLLECTION(1), 0x01,                    // Application
-
-        USAGE_PAGE(1), 0x07,                    // Key Codes
-        USAGE_MINIMUM(1), 0xE0,
-        USAGE_MAXIMUM(1), 0xE7,
-        LOGICAL_MINIMUM(1), 0x00,
-        LOGICAL_MAXIMUM(1), 0x01,
-        REPORT_SIZE(1), 0x01,
-        REPORT_COUNT(1), 0x08,
-        INPUT(1), 0x02,                         // Data, Variable, Absolute
+        USAGE_PAGE(1),     0x01,  // Generic Desktop
+        USAGE(1),          0x06,  // Keyboard
+        COLLECTION(1),     0x01,  // Application
 
-        REPORT_COUNT(1), 0x01,
-        REPORT_SIZE(1), 0x08,
-        INPUT(1), 0x01,                         // Constant
+        USAGE_PAGE(1),     0x07,                                                                                                                                           // Key Codes
+        USAGE_MINIMUM(1),  0xE0, USAGE_MAXIMUM(1), 0xE7, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0x01, REPORT_SIZE(1), 0x01, REPORT_COUNT(1), 0x08, INPUT(1), 0x02,  // Data, Variable, Absolute
 
-        REPORT_COUNT(1), 0x05,
-        REPORT_SIZE(1), 0x01,
-        USAGE_PAGE(1), 0x08,                    // LEDs
-        USAGE_MINIMUM(1), 0x01,
-        USAGE_MAXIMUM(1), 0x05,
-        OUTPUT(1), 0x02,                        // Data, Variable, Absolute
+        REPORT_COUNT(1),   0x01, REPORT_SIZE(1),   0x08, INPUT(1),           0x01,  // Constant
 
-        REPORT_COUNT(1), 0x01,
-        REPORT_SIZE(1), 0x03,
-        OUTPUT(1), 0x01,                        // Constant
+        REPORT_COUNT(1),   0x05, REPORT_SIZE(1),   0x01, USAGE_PAGE(1),      0x08,  // LEDs
+        USAGE_MINIMUM(1),  0x01, USAGE_MAXIMUM(1), 0x05, OUTPUT(1),          0x02,  // Data, Variable, Absolute
 
+        REPORT_COUNT(1),   0x01, REPORT_SIZE(1),   0x03, OUTPUT(1),          0x01,  // Constant
 
-        REPORT_COUNT(1), 0x06,
-        REPORT_SIZE(1), 0x08,
-        LOGICAL_MINIMUM(1), 0x00,
-        LOGICAL_MAXIMUM(1), 0xFF,
-        USAGE_PAGE(1), 0x07,                    // Key Codes
-        USAGE_MINIMUM(1), 0x00,
-        USAGE_MAXIMUM(1), 0xFF,
-        INPUT(1), 0x00,                         // Data, Array
+        REPORT_COUNT(1),   0x06, REPORT_SIZE(1),   0x08, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0xFF, USAGE_PAGE(1),  0x07,  // Key Codes
+        USAGE_MINIMUM(1),  0x00, USAGE_MAXIMUM(1), 0xFF, INPUT(1),           0x00,                                                  // Data, Array
         END_COLLECTION(0),
     };
     reportLength = sizeof(reportDescriptor);
@@ -113,48 +113,45 @@ uint16_t HIDKeyboard::reportDescLength() {
     return reportLength;
 }
 
-#define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \
-                               + (1 * INTERFACE_DESCRIPTOR_LENGTH) \
-                               + (1 * HID_DESCRIPTOR_LENGTH) \
-                               + (1 * ENDPOINT_DESCRIPTOR_LENGTH))
-uint8_t * HIDKeyboard::configurationDesc() {
+#define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) + (1 * INTERFACE_DESCRIPTOR_LENGTH) + (1 * HID_DESCRIPTOR_LENGTH) + (1 * ENDPOINT_DESCRIPTOR_LENGTH))
+uint8_t *HIDKeyboard::configurationDesc() {
     static uint8_t configurationDescriptor[] = {
-        CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
-        CONFIGURATION_DESCRIPTOR,       // bDescriptorType
-        LSB(TOTAL_DESCRIPTOR_LENGTH),   // wTotalLength (LSB)
-        MSB(TOTAL_DESCRIPTOR_LENGTH),   // wTotalLength (MSB)
-        0x01,                           // bNumInterfaces
-        DEFAULT_CONFIGURATION,          // bConfigurationValue
-        0x00,                           // iConfiguration
-        C_RESERVED | C_REMOTE_WAKEUP,   // bmAttributes
-        C_POWER(100),                   // bMaxPowerHello World from Mbed
-
-        INTERFACE_DESCRIPTOR_LENGTH,    // bLength
-        INTERFACE_DESCRIPTOR,           // bDescriptorType
-        0x00,                           // bInterfaceNumber
-        0x00,                           // bAlternateSetting
-        0x01,                           // bNumEndpoints
-        HID_CLASS,                      // bInterfaceClass
-        1,                              // bInterfaceSubClass (boot)
-        1,                              // bInterfaceProtocol (keyboard)
-        0x00,                           // iInterface
-
-        HID_DESCRIPTOR_LENGTH,          // bLength
-        HID_DESCRIPTOR,                 // bDescriptorType
-        LSB(HID_VERSION_1_11),          // bcdHID (LSB)
-        MSB(HID_VERSION_1_11),          // bcdHID (MSB)
-        0x00,                           // bCountryCode
-        0x01,                           // bNumDescriptors
-        REPORT_DESCRIPTOR,              // bDescriptorType
+        CONFIGURATION_DESCRIPTOR_LENGTH,  // bLength
+        CONFIGURATION_DESCRIPTOR,         // bDescriptorType
+        LSB(TOTAL_DESCRIPTOR_LENGTH),     // wTotalLength (LSB)
+        MSB(TOTAL_DESCRIPTOR_LENGTH),     // wTotalLength (MSB)
+        0x01,                             // bNumInterfaces
+        DEFAULT_CONFIGURATION,            // bConfigurationValue
+        0x00,                             // iConfiguration
+        C_RESERVED | C_REMOTE_WAKEUP,     // bmAttributes
+        C_POWER(100),                     // bMaxPowerHello World from Mbed
+
+        INTERFACE_DESCRIPTOR_LENGTH,  // bLength
+        INTERFACE_DESCRIPTOR,         // bDescriptorType
+        0x00,                         // bInterfaceNumber
+        0x00,                         // bAlternateSetting
+        0x01,                         // bNumEndpoints
+        HID_CLASS,                    // bInterfaceClass
+        1,                            // bInterfaceSubClass (boot)
+        1,                            // bInterfaceProtocol (keyboard)
+        0x00,                         // iInterface
+
+        HID_DESCRIPTOR_LENGTH,               // bLength
+        HID_DESCRIPTOR,                      // bDescriptorType
+        LSB(HID_VERSION_1_11),               // bcdHID (LSB)
+        MSB(HID_VERSION_1_11),               // bcdHID (MSB)
+        0x00,                                // bCountryCode
+        0x01,                                // bNumDescriptors
+        REPORT_DESCRIPTOR,                   // bDescriptorType
         (uint8_t)(LSB(reportDescLength())),  // wDescriptorLength (LSB)
         (uint8_t)(MSB(reportDescLength())),  // wDescriptorLength (MSB)
 
-        ENDPOINT_DESCRIPTOR_LENGTH,     // bLength
-        ENDPOINT_DESCRIPTOR,            // bDescriptorType
-        PHY_TO_DESC(EP1IN),             // bEndpointAddress
-        E_INTERRUPT,                    // bmAttributes
-        LSB(MAX_PACKET_SIZE_EPINT),     // wMaxPacketSize (LSB)
-        MSB(MAX_PACKET_SIZE_EPINT),     // wMaxPacketSize (MSB)
+        ENDPOINT_DESCRIPTOR_LENGTH,  // bLength
+        ENDPOINT_DESCRIPTOR,         // bDescriptorType
+        PHY_TO_DESC(EP1IN),          // bEndpointAddress
+        E_INTERRUPT,                 // bmAttributes
+        LSB(MAX_PACKET_SIZE_EPINT),  // wMaxPacketSize (LSB)
+        MSB(MAX_PACKET_SIZE_EPINT),  // wMaxPacketSize (MSB)
         1,                           // bInterval (milliseconds)
     };
     return configurationDescriptor;
@@ -187,41 +184,35 @@ uint8_t * HIDKeyboard::deviceDesc() {
 #endif
 
 bool HIDKeyboard::USBCallback_request() {
-    bool success = false;
-    CONTROL_TRANSFER * transfer = getTransferPtr();
-    uint8_t *hidDescriptor;
+    bool              success  = false;
+    CONTROL_TRANSFER *transfer = getTransferPtr();
+    uint8_t *         hidDescriptor;
 
     // Process additional standard requests
 
-    if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE))
-    {
-        switch (transfer->setup.bRequest)
-        {
+    if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE)) {
+        switch (transfer->setup.bRequest) {
             case GET_DESCRIPTOR:
-                switch (DESCRIPTOR_TYPE(transfer->setup.wValue))
-                {
+                switch (DESCRIPTOR_TYPE(transfer->setup.wValue)) {
                     case REPORT_DESCRIPTOR:
-                        if ((reportDesc() != NULL) \
-                            && (reportDescLength() != 0))
-                        {
+                        if ((reportDesc() != NULL) && (reportDescLength() != 0)) {
                             transfer->remaining = reportDescLength();
-                            transfer->ptr = reportDesc();
+                            transfer->ptr       = reportDesc();
                             transfer->direction = DEVICE_TO_HOST;
-                            success = true;
+                            success             = true;
                         }
                         break;
                     case HID_DESCRIPTOR:
-                            // Find the HID descriptor, after the configuration descriptor
-                            hidDescriptor = findDescriptor(HID_DESCRIPTOR);
-                            if (hidDescriptor != NULL)
-                            {
-                                transfer->remaining = HID_DESCRIPTOR_LENGTH;
-                                transfer->ptr = hidDescriptor;
-                                transfer->direction = DEVICE_TO_HOST;
-                                success = true;
-                            }
-                            break;
-                     
+                        // Find the HID descriptor, after the configuration descriptor
+                        hidDescriptor = findDescriptor(HID_DESCRIPTOR);
+                        if (hidDescriptor != NULL) {
+                            transfer->remaining = HID_DESCRIPTOR_LENGTH;
+                            transfer->ptr       = hidDescriptor;
+                            transfer->direction = DEVICE_TO_HOST;
+                            success             = true;
+                        }
+                        break;
+
                     default:
                         break;
                 }
@@ -232,8 +223,7 @@ bool HIDKeyboard::USBCallback_request() {
     }
 
     // Process class-specific requests
-    if (transfer->setup.bmRequestType.Type == CLASS_TYPE)
-    {
+    if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
         switch (transfer->setup.bRequest) {
             case SET_REPORT:
                 // LED indicator
@@ -242,10 +232,10 @@ bool HIDKeyboard::USBCallback_request() {
                 // if (transfer->setup.wLength == 1)
 
                 transfer->remaining = 1;
-                //transfer->ptr = ?? what ptr should be set when OUT(not used?)
+                // transfer->ptr = ?? what ptr should be set when OUT(not used?)
                 transfer->direction = HOST_TO_DEVICE;
-                transfer->notify = true;    /* notify with USBCallback_requestCompleted */
-                success = true;
+                transfer->notify    = true; /* notify with USBCallback_requestCompleted */
+                success             = true;
             default:
                 break;
         }
@@ -254,8 +244,7 @@ bool HIDKeyboard::USBCallback_request() {
     return success;
 }
 
-void HIDKeyboard::USBCallback_requestCompleted(uint8_t * buf, uint32_t length)
-{
+void HIDKeyboard::USBCallback_requestCompleted(uint8_t *buf, uint32_t length) {
     if (length > 0) {
         CONTROL_TRANSFER *transfer = getTransferPtr();
         if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
index c537e5ecee18c8e951ce11572b81fedda9fa2caf..e8ff10869928816413697c0fc6299b6e5003c4d3 100644 (file)
@@ -1,30 +1,31 @@
 #ifndef HIDKEYBOARD_H
 
-#include "stdint.h"
-#include "stdbool.h"
-#include "USBHID.h"
-#include "report.h"
-
+#    include "stdint.h"
+#    include "stdbool.h"
+#    include "USBHID.h"
+#    include "report.h"
 
 class HIDKeyboard : public USBDevice {
-public:
+   public:
     HIDKeyboard(uint16_t vendor_id = 0xFEED, uint16_t product_id = 0xabed, uint16_t product_release = 0x0001);
 
-    bool sendReport(report_keyboard_t report);
+    bool    sendReport(report_keyboard_t report);
     uint8_t leds(void);
-protected:
-    uint16_t reportLength;
-    virtual bool USBCallback_setConfiguration(uint8_t configuration);
-    virtual uint8_t * stringImanufacturerDesc();
-    virtual uint8_t * stringIproductDesc();
-    virtual uint8_t * stringIserialDesc();
+
+   protected:
+    uint16_t         reportLength;
+    virtual bool     USBCallback_setConfiguration(uint8_t configuration);
+    virtual uint8_t* stringImanufacturerDesc();
+    virtual uint8_t* stringIproductDesc();
+    virtual uint8_t* stringIserialDesc();
     virtual uint16_t reportDescLength();
-    virtual uint8_t * reportDesc();
-    virtual uint8_t * configurationDesc();
-    //virtual uint8_t * deviceDesc();
+    virtual uint8_t* reportDesc();
+    virtual uint8_t* configurationDesc();
+    // virtual uint8_t * deviceDesc();
     virtual bool USBCallback_request();
-    virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length);
-private:
+    virtual void USBCallback_requestCompleted(uint8_t* buf, uint32_t length);
+
+   private:
     uint8_t led_state;
 };
 
index 6c7b16e23d2313acd43cb331fe71d9050f1dac20..83086499c77a9f57e77ef22f510a35740c756c7b 100644 (file)
@@ -5,37 +5,17 @@
 
 HIDKeyboard keyboard;
 
-
 /* Host driver */
 static uint8_t keyboard_leds(void);
-static void send_keyboard(report_keyboard_t *report);
-static void send_mouse(report_mouse_t *report);
-static void send_system(uint16_t data);
-static void send_consumer(uint16_t data);
-
-host_driver_t mbed_driver = {
-    keyboard_leds,
-    send_keyboard,
-    send_mouse,
-    send_system,
-    send_consumer
-};
+static void    send_keyboard(report_keyboard_t *report);
+static void    send_mouse(report_mouse_t *report);
+static void    send_system(uint16_t data);
+static void    send_consumer(uint16_t data);
 
+host_driver_t mbed_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
 
-static uint8_t keyboard_leds(void)
-{
-    return keyboard.leds();
-}
-static void send_keyboard(report_keyboard_t *report)
-{
-    keyboard.sendReport(*report);
-}
-static void send_mouse(report_mouse_t *report)
-{
-}
-static void send_system(uint16_t data)
-{
-}
-static void send_consumer(uint16_t data)
-{
-}
+static uint8_t keyboard_leds(void) { return keyboard.leds(); }
+static void    send_keyboard(report_keyboard_t *report) { keyboard.sendReport(*report); }
+static void    send_mouse(report_mouse_t *report) {}
+static void    send_system(uint16_t data) {}
+static void    send_consumer(uint16_t data) {}
old mode 100755 (executable)
new mode 100644 (file)
index a1d7482..b346c05
 #ifndef _LUFA_CONFIG_H_
 #define _LUFA_CONFIG_H_
 
-       #if (ARCH == ARCH_AVR8)
+#if (ARCH == ARCH_AVR8)
 
-               /* Non-USB Related Configuration Tokens: */
+/* Non-USB Related Configuration Tokens: */
 //             #define DISABLE_TERMINAL_CODES
 
-               /* USB Class Driver Related Tokens: */
+/* USB Class Driver Related Tokens: */
 //             #define HID_HOST_BOOT_PROTOCOL_ONLY
 //             #define HID_STATETABLE_STACK_DEPTH       {Insert Value Here}
 //             #define HID_USAGE_STACK_DEPTH            {Insert Value Here}
 //             #define HID_MAX_REPORT_IDS               {Insert Value Here}
 //             #define NO_CLASS_DRIVER_AUTOFLUSH
 
-               /* General USB Driver Related Tokens: */
+/* General USB Driver Related Tokens: */
 //             #define ORDERED_EP_CONFIG
-               #define USE_STATIC_OPTIONS               (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
-               #define USB_DEVICE_ONLY
+#    define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
+#    define USB_DEVICE_ONLY
 //             #define USB_HOST_ONLY
 //             #define USB_STREAM_TIMEOUT_MS            {Insert Value Here}
 //             #define NO_LIMITED_CONTROLLER_CONNECT
 //             #define NO_SOF_EVENTS
 
-               /* USB Device Mode Driver Related Tokens: */
+/* USB Device Mode Driver Related Tokens: */
 //             #define USE_RAM_DESCRIPTORS
-               #define USE_FLASH_DESCRIPTORS
+#    define USE_FLASH_DESCRIPTORS
 //             #define USE_EEPROM_DESCRIPTORS
 //             #define NO_INTERNAL_SERIAL
-               #define FIXED_CONTROL_ENDPOINT_SIZE      8
+#    define FIXED_CONTROL_ENDPOINT_SIZE 8
 //             #define DEVICE_STATE_AS_GPIOR            {Insert Value Here}
-               #define FIXED_NUM_CONFIGURATIONS         1
+#    define FIXED_NUM_CONFIGURATIONS 1
 //             #define CONTROL_ONLY_DEVICE
 //             #define INTERRUPT_CONTROL_ENDPOINT
 //             #define NO_DEVICE_REMOTE_WAKEUP
 //             #define NO_DEVICE_SELF_POWER
 
-               /* USB Host Mode Driver Related Tokens: */
+/* USB Host Mode Driver Related Tokens: */
 //             #define HOST_STATE_AS_GPIOR              {Insert Value Here}
 //             #define USB_HOST_TIMEOUT_MS              {Insert Value Here}
 //             #define HOST_DEVICE_SETTLE_DELAY_MS          {Insert Value Here}
 //      #define NO_AUTO_VBUS_MANAGEMENT
 //      #define INVERTED_VBUS_ENABLE_LINE
 
-       #else
+#else
 
-               #error Unsupported architecture for this LUFA configuration file.
+#    error Unsupported architecture for this LUFA configuration file.
 
-       #endif
+#endif
 #endif
old mode 100755 (executable)
new mode 100644 (file)
index e434956..e36a9e6
@@ -1,65 +1,62 @@
-//this is a single reader [maybe multiple writer?] byte queue
-//Copyright 2008 Alex Norman
-//writen by Alex Norman 
+// this is a single reader [maybe multiple writer?] byte queue
+// Copyright 2008 Alex Norman
+// writen by Alex Norman
 //
-//This file is part of avr-bytequeue.
+// This file is part of avr-bytequeue.
 //
-//avr-bytequeue is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-bytequeue is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-bytequeue is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-bytequeue is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-bytequeue.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-bytequeue.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "bytequeue.h"
 #include "interrupt_setting.h"
 
-void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen){
-   queue->length = arrayLen;
-   queue->data = dataArray;
-   queue->start = queue->end = 0;
+void bytequeue_init(byteQueue_t* queue, uint8_t* dataArray, byteQueueIndex_t arrayLen) {
+    queue->length = arrayLen;
+    queue->data   = dataArray;
+    queue->start = queue->end = 0;
 }
 
-bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item){
-   interrupt_setting_t setting = store_and_clear_interrupt();
-   //full
-   if(((queue->end + 1) % queue->length) == queue->start){
-      restore_interrupt_setting(setting);
-      return false;
-   } else {
-      queue->data[queue->end] = item;
-      queue->end = (queue->end + 1) % queue->length;
-      restore_interrupt_setting(setting);
-      return true;
-   }
+bool bytequeue_enqueue(byteQueue_t* queue, uint8_t item) {
+    interrupt_setting_t setting = store_and_clear_interrupt();
+    // full
+    if (((queue->end + 1) % queue->length) == queue->start) {
+        restore_interrupt_setting(setting);
+        return false;
+    } else {
+        queue->data[queue->end] = item;
+        queue->end              = (queue->end + 1) % queue->length;
+        restore_interrupt_setting(setting);
+        return true;
+    }
 }
 
-byteQueueIndex_t bytequeue_length(byteQueue_t * queue){
-   byteQueueIndex_t len;
-   interrupt_setting_t setting = store_and_clear_interrupt();
-   if(queue->end >= queue->start)
-      len = queue->end - queue->start;
-   else
-      len = (queue->length - queue->start) + queue->end;
-   restore_interrupt_setting(setting);
-   return len;
+byteQueueIndex_t bytequeue_length(byteQueue_t* queue) {
+    byteQueueIndex_t    len;
+    interrupt_setting_t setting = store_and_clear_interrupt();
+    if (queue->end >= queue->start)
+        len = queue->end - queue->start;
+    else
+        len = (queue->length - queue->start) + queue->end;
+    restore_interrupt_setting(setting);
+    return len;
 }
 
-//we don't need to avoid interrupts if there is only one reader
-uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index){
-   return queue->data[(queue->start + index) % queue->length];
-}
+// we don't need to avoid interrupts if there is only one reader
+uint8_t bytequeue_get(byteQueue_t* queue, byteQueueIndex_t index) { return queue->data[(queue->start + index) % queue->length]; }
 
-//we just update the start index to remove elements
-void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove){
-   interrupt_setting_t setting = store_and_clear_interrupt();
-   queue->start = (queue->start + numToRemove) % queue->length;
-   restore_interrupt_setting(setting);
+// we just update the start index to remove elements
+void bytequeue_remove(byteQueue_t* queue, byteQueueIndex_t numToRemove) {
+    interrupt_setting_t setting = store_and_clear_interrupt();
+    queue->start                = (queue->start + numToRemove) % queue->length;
+    restore_interrupt_setting(setting);
 }
-
old mode 100755 (executable)
new mode 100644 (file)
index e4a2861..33fb63a
@@ -1,28 +1,28 @@
-//this is a single reader [maybe multiple writer?] byte queue
-//Copyright 2008 Alex Norman
-//writen by Alex Norman 
+// this is a single reader [maybe multiple writer?] byte queue
+// Copyright 2008 Alex Norman
+// writen by Alex Norman
 //
-//This file is part of avr-bytequeue.
+// This file is part of avr-bytequeue.
 //
-//avr-bytequeue is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-bytequeue is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-bytequeue is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-bytequeue is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-bytequeue.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-bytequeue.  If not, see <http://www.gnu.org/licenses/>.
 
 #ifndef BYTEQUEUE_H
 #define BYTEQUEUE_H
 
 #ifdef __cplusplus
 extern "C" {
-#endif 
+#endif
 
 #include <inttypes.h>
 #include <stdbool.h>
@@ -30,30 +30,29 @@ extern "C" {
 typedef uint8_t byteQueueIndex_t;
 
 typedef struct {
-       byteQueueIndex_t start;
-       byteQueueIndex_t end;
-       byteQueueIndex_t length;
-       uint8_t * data;
+    byteQueueIndex_t start;
+    byteQueueIndex_t end;
+    byteQueueIndex_t length;
+    uint8_t*         data;
 } byteQueue_t;
 
-//you must have a queue, an array of data which the queue will use, and the length of that array
-void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen);
+// you must have a queue, an array of data which the queue will use, and the length of that array
+void bytequeue_init(byteQueue_t* queue, uint8_t* dataArray, byteQueueIndex_t arrayLen);
 
-//add an item to the queue, returns false if the queue is full
-bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item);
+// add an item to the queue, returns false if the queue is full
+bool bytequeue_enqueue(byteQueue_t* queue, uint8_t item);
 
-//get the length of the queue
-byteQueueIndex_t bytequeue_length(byteQueue_t * queue);
+// get the length of the queue
+byteQueueIndex_t bytequeue_length(byteQueue_t* queue);
 
-//this grabs data at the index given [starting at queue->start]
-uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index);
+// this grabs data at the index given [starting at queue->start]
+uint8_t bytequeue_get(byteQueue_t* queue, byteQueueIndex_t index);
 
-//update the index in the queue to reflect data that has been dealt with 
-void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove);
+// update the index in the queue to reflect data that has been dealt with
+void bytequeue_remove(byteQueue_t* queue, byteQueueIndex_t numToRemove);
 
 #ifdef __cplusplus
 }
-#endif 
-
 #endif
 
+#endif
old mode 100755 (executable)
new mode 100644 (file)
index 0ab8b54..1be1fee
@@ -1,49 +1,43 @@
-//Copyright 20010 Alex Norman
-//writen by Alex Norman
+// Copyright 20010 Alex Norman
+// writen by Alex Norman
 //
-//This file is part of avr-bytequeue.
+// This file is part of avr-bytequeue.
 //
-//avr-bytequeue is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-bytequeue is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-bytequeue is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-bytequeue is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-bytequeue.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-bytequeue.  If not, see <http://www.gnu.org/licenses/>.
 
-
-//AVR specific code
-//should be able to port to other systems by simply providing chip specific
-//implementations of the typedef and these functions
+// AVR specific code
+// should be able to port to other systems by simply providing chip specific
+// implementations of the typedef and these functions
 
 #include "interrupt_setting.h"
 #if defined(__AVR__)
-#include <avr/interrupt.h>
+#    include <avr/interrupt.h>
 
 interrupt_setting_t store_and_clear_interrupt(void) {
-   uint8_t sreg = SREG;
-   cli();
-   return sreg;
+    uint8_t sreg = SREG;
+    cli();
+    return sreg;
 }
 
-void restore_interrupt_setting(interrupt_setting_t setting) {
-   SREG = setting;
-}
+void restore_interrupt_setting(interrupt_setting_t setting) { SREG = setting; }
 #elif defined(__arm__)
-#include "ch.h"
+#    include "ch.h"
 
 interrupt_setting_t store_and_clear_interrupt(void) {
-  chSysLock();
-  return 0;
+    chSysLock();
+    return 0;
 }
 
-void restore_interrupt_setting(interrupt_setting_t setting) {
-   chSysUnlock();
-}
+void restore_interrupt_setting(interrupt_setting_t setting) { chSysUnlock(); }
 #endif
-
old mode 100755 (executable)
new mode 100644 (file)
index 053d02c..788f75d
@@ -1,39 +1,38 @@
-//Copyright 20010 Alex Norman
-//writen by Alex Norman 
+// Copyright 20010 Alex Norman
+// writen by Alex Norman
 //
-//This file is part of avr-bytequeue.
+// This file is part of avr-bytequeue.
 //
-//avr-bytequeue is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-bytequeue is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-bytequeue is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-bytequeue is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-bytequeue.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-bytequeue.  If not, see <http://www.gnu.org/licenses/>.
 
 #ifndef INTERRUPT_SETTING_H
 #define INTERRUPT_SETTING_H
 
 #ifdef __cplusplus
 extern "C" {
-#endif 
+#endif
 
 #include <inttypes.h>
 
-//AVR specific typedef
+// AVR specific typedef
 typedef uint8_t interrupt_setting_t;
 
 interrupt_setting_t store_and_clear_interrupt(void);
-void restore_interrupt_setting(interrupt_setting_t setting);
+void                restore_interrupt_setting(interrupt_setting_t setting);
 
 #ifdef __cplusplus
 }
-#endif 
-
 #endif
 
+#endif
old mode 100755 (executable)
new mode 100644 (file)
index 11a5890..643c437
-//midi for embedded chips,
-//Copyright 2010 Alex Norman
+// midi for embedded chips,
+// Copyright 2010 Alex Norman
 //
-//This file is part of avr-midi.
+// This file is part of avr-midi.
 //
-//avr-midi is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-midi is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-midi is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-midi is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "midi.h"
-#include <string.h> //for memcpy
+#include <string.h>  //for memcpy
 
-#define MIN(x,y) (((x) < (y)) ? (x) : (y)) 
+#define MIN(x, y) (((x) < (y)) ? (x) : (y))
 
 #ifndef NULL
-#define NULL 0
+#    define NULL 0
 #endif
 
-bool midi_is_statusbyte(uint8_t theByte){
-   return (bool)(theByte & MIDI_STATUSMASK);
-}
+bool midi_is_statusbyte(uint8_t theByte) { return (bool)(theByte & MIDI_STATUSMASK); }
 
-bool midi_is_realtime(uint8_t theByte){
-   return (theByte >= MIDI_CLOCK);
-}
+bool midi_is_realtime(uint8_t theByte) { return (theByte >= MIDI_CLOCK); }
 
-midi_packet_length_t midi_packet_length(uint8_t status){
-   switch(status & 0xF0){
-      case MIDI_CC:
-      case MIDI_NOTEON:
-      case MIDI_NOTEOFF:
-      case MIDI_AFTERTOUCH:
-      case MIDI_PITCHBEND:
-         return THREE;
-      case MIDI_PROGCHANGE:
-      case MIDI_CHANPRESSURE:
-      case MIDI_SONGSELECT:
-         return TWO;
-      case 0xF0:
-         switch(status) {
-            case MIDI_CLOCK:
-            case MIDI_TICK:
-            case MIDI_START:
-            case MIDI_CONTINUE:
-            case MIDI_STOP:
-            case MIDI_ACTIVESENSE:
-            case MIDI_RESET:
-            case MIDI_TUNEREQUEST:
-               return ONE;
-            case MIDI_SONGPOSITION:
-               return THREE;
-            case MIDI_TC_QUARTERFRAME:
-            case MIDI_SONGSELECT:
-               return TWO;
-            case SYSEX_END:
-            case SYSEX_BEGIN:
-            default:
-               return UNDEFINED;
-         }
-      default:
-         return UNDEFINED;
-   }
+midi_packet_length_t midi_packet_length(uint8_t status) {
+    switch (status & 0xF0) {
+        case MIDI_CC:
+        case MIDI_NOTEON:
+        case MIDI_NOTEOFF:
+        case MIDI_AFTERTOUCH:
+        case MIDI_PITCHBEND:
+            return THREE;
+        case MIDI_PROGCHANGE:
+        case MIDI_CHANPRESSURE:
+        case MIDI_SONGSELECT:
+            return TWO;
+        case 0xF0:
+            switch (status) {
+                case MIDI_CLOCK:
+                case MIDI_TICK:
+                case MIDI_START:
+                case MIDI_CONTINUE:
+                case MIDI_STOP:
+                case MIDI_ACTIVESENSE:
+                case MIDI_RESET:
+                case MIDI_TUNEREQUEST:
+                    return ONE;
+                case MIDI_SONGPOSITION:
+                    return THREE;
+                case MIDI_TC_QUARTERFRAME:
+                case MIDI_SONGSELECT:
+                    return TWO;
+                case SYSEX_END:
+                case SYSEX_BEGIN:
+                default:
+                    return UNDEFINED;
+            }
+        default:
+            return UNDEFINED;
+    }
 }
 
-void midi_send_cc(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val){
-   //CC Status: 0xB0 to 0xBF where the low nibble is the MIDI channel.
-   //CC Data: Controller Num, Controller Val
-   device->send_func(device, 3,
-         MIDI_CC | (chan & MIDI_CHANMASK),
-         num & 0x7F,
-         val & 0x7F);
+void midi_send_cc(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t val) {
+    // CC Status: 0xB0 to 0xBF where the low nibble is the MIDI channel.
+    // CC Data: Controller Num, Controller Val
+    device->send_func(device, 3, MIDI_CC | (chan & MIDI_CHANMASK), num & 0x7F, val & 0x7F);
 }
 
-void midi_send_noteon(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel){
-   //Note Data: Note Num, Note Velocity
-   device->send_func(device, 3,
-         MIDI_NOTEON | (chan & MIDI_CHANMASK),
-         num & 0x7F,
-         vel & 0x7F);
+void midi_send_noteon(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel) {
+    // Note Data: Note Num, Note Velocity
+    device->send_func(device, 3, MIDI_NOTEON | (chan & MIDI_CHANMASK), num & 0x7F, vel & 0x7F);
 }
 
-void midi_send_noteoff(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel){
-   //Note Data: Note Num, Note Velocity
-   device->send_func(device, 3,
-         MIDI_NOTEOFF | (chan & MIDI_CHANMASK),
-         num & 0x7F,
-         vel & 0x7F);
+void midi_send_noteoff(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel) {
+    // Note Data: Note Num, Note Velocity
+    device->send_func(device, 3, MIDI_NOTEOFF | (chan & MIDI_CHANMASK), num & 0x7F, vel & 0x7F);
 }
 
-void midi_send_aftertouch(MidiDevice * device, uint8_t chan, uint8_t note_num, uint8_t amt){
-   device->send_func(device, 3,
-         MIDI_AFTERTOUCH | (chan & MIDI_CHANMASK),
-         note_num & 0x7F,
-         amt & 0x7F);
-}
+void midi_send_aftertouch(MidiDevice* device, uint8_t chan, uint8_t note_num, uint8_t amt) { device->send_func(device, 3, MIDI_AFTERTOUCH | (chan & MIDI_CHANMASK), note_num & 0x7F, amt & 0x7F); }
 
-//XXX does this work right?
-//amt in range -0x2000, 0x1fff
-//uAmt should be in range..
-//0x0000 to 0x3FFF
-void midi_send_pitchbend(MidiDevice * device, uint8_t chan, int16_t amt){
-   uint16_t uAmt;
-   //check range
-   if(amt > 0x1fff){
-      uAmt = 0x3FFF;
-   } else if(amt < -0x2000){
-      uAmt = 0;
-   } else {
-      uAmt = amt + 0x2000;
-   }
-   device->send_func(device, 3,
-         MIDI_PITCHBEND | (chan & MIDI_CHANMASK),
-         uAmt & 0x7F,
-         (uAmt >> 7) & 0x7F);
+// XXX does this work right?
+// amt in range -0x2000, 0x1fff
+// uAmt should be in range..
+// 0x0000 to 0x3FFF
+void midi_send_pitchbend(MidiDevice* device, uint8_t chan, int16_t amt) {
+    uint16_t uAmt;
+    // check range
+    if (amt > 0x1fff) {
+        uAmt = 0x3FFF;
+    } else if (amt < -0x2000) {
+        uAmt = 0;
+    } else {
+        uAmt = amt + 0x2000;
+    }
+    device->send_func(device, 3, MIDI_PITCHBEND | (chan & MIDI_CHANMASK), uAmt & 0x7F, (uAmt >> 7) & 0x7F);
 }
 
-void midi_send_programchange(MidiDevice * device, uint8_t chan, uint8_t num){
-   device->send_func(device, 2,
-         MIDI_PROGCHANGE | (chan & MIDI_CHANMASK),
-         num & 0x7F,
-         0);
-}
+void midi_send_programchange(MidiDevice* device, uint8_t chan, uint8_t num) { device->send_func(device, 2, MIDI_PROGCHANGE | (chan & MIDI_CHANMASK), num & 0x7F, 0); }
 
-void midi_send_channelpressure(MidiDevice * device, uint8_t chan, uint8_t amt){
-   device->send_func(device, 2,
-         MIDI_CHANPRESSURE | (chan & MIDI_CHANMASK),
-         amt & 0x7F,
-         0);
-}
+void midi_send_channelpressure(MidiDevice* device, uint8_t chan, uint8_t amt) { device->send_func(device, 2, MIDI_CHANPRESSURE | (chan & MIDI_CHANMASK), amt & 0x7F, 0); }
 
-void midi_send_clock(MidiDevice * device){
-   device->send_func(device, 1, MIDI_CLOCK, 0, 0);
-}
+void midi_send_clock(MidiDevice* device) { device->send_func(device, 1, MIDI_CLOCK, 0, 0); }
 
-void midi_send_tick(MidiDevice * device){
-   device->send_func(device, 1, MIDI_TICK, 0, 0);
-}
+void midi_send_tick(MidiDevice* device) { device->send_func(device, 1, MIDI_TICK, 0, 0); }
 
-void midi_send_start(MidiDevice * device){
-   device->send_func(device, 1, MIDI_START, 0, 0);
-}
+void midi_send_start(MidiDevice* device) { device->send_func(device, 1, MIDI_START, 0, 0); }
 
-void midi_send_continue(MidiDevice * device){
-   device->send_func(device, 1, MIDI_CONTINUE, 0, 0);
-}
+void midi_send_continue(MidiDevice* device) { device->send_func(device, 1, MIDI_CONTINUE, 0, 0); }
 
-void midi_send_stop(MidiDevice * device){
-   device->send_func(device, 1, MIDI_STOP, 0, 0);
-}
-
-void midi_send_activesense(MidiDevice * device){
-   device->send_func(device, 1, MIDI_ACTIVESENSE, 0, 0);
-}
+void midi_send_stop(MidiDevice* device) { device->send_func(device, 1, MIDI_STOP, 0, 0); }
 
-void midi_send_reset(MidiDevice * device){
-   device->send_func(device, 1, MIDI_RESET, 0, 0);
-}
+void midi_send_activesense(MidiDevice* device) { device->send_func(device, 1, MIDI_ACTIVESENSE, 0, 0); }
 
-void midi_send_tcquarterframe(MidiDevice * device, uint8_t time){
-   device->send_func(device, 2,
-         MIDI_TC_QUARTERFRAME,
-         time & 0x7F,
-         0);
-}
+void midi_send_reset(MidiDevice* device) { device->send_func(device, 1, MIDI_RESET, 0, 0); }
 
-//XXX is this right?
-void midi_send_songposition(MidiDevice * device, uint16_t pos){
-   device->send_func(device, 3,
-         MIDI_SONGPOSITION,
-         pos & 0x7F,
-         (pos >> 7) & 0x7F);
-}
+void midi_send_tcquarterframe(MidiDevice* device, uint8_t time) { device->send_func(device, 2, MIDI_TC_QUARTERFRAME, time & 0x7F, 0); }
 
-void midi_send_songselect(MidiDevice * device, uint8_t song){
-   device->send_func(device, 2,
-         MIDI_SONGSELECT,
-         song & 0x7F,
-         0);
-}
+// XXX is this right?
+void midi_send_songposition(MidiDevice* device, uint16_t pos) { device->send_func(device, 3, MIDI_SONGPOSITION, pos & 0x7F, (pos >> 7) & 0x7F); }
 
-void midi_send_tunerequest(MidiDevice * device){
-   device->send_func(device, 1, MIDI_TUNEREQUEST, 0, 0);
-}
+void midi_send_songselect(MidiDevice* device, uint8_t song) { device->send_func(device, 2, MIDI_SONGSELECT, song & 0x7F, 0); }
 
-void midi_send_byte(MidiDevice * device, uint8_t b){
-   device->send_func(device, 1, b, 0, 0);
-}
+void midi_send_tunerequest(MidiDevice* device) { device->send_func(device, 1, MIDI_TUNEREQUEST, 0, 0); }
 
-void midi_send_data(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2){
-   //ensure that the count passed along is always 3 or lower
-   if (count > 3) {
-      //TODO how to do this correctly?
-   }
-   device->send_func(device, count, byte0, byte1, byte2);
-}
+void midi_send_byte(MidiDevice* device, uint8_t b) { device->send_func(device, 1, b, 0, 0); }
 
-void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array) {
-  uint16_t i;
-  for (i = 0; i < count; i += 3) {
-    uint8_t b[3] = { 0, 0, 0 };
-    uint16_t to_send = count - i;
-    to_send = (to_send > 3) ? 3 : to_send;
-    memcpy(b, array + i, to_send);
-    midi_send_data(device, to_send, b[0], b[1], b[2]);
-  }
+void midi_send_data(MidiDevice* device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
+    // ensure that the count passed along is always 3 or lower
+    if (count > 3) {
+        // TODO how to do this correctly?
+    }
+    device->send_func(device, count, byte0, byte1, byte2);
 }
 
-
-void midi_register_cc_callback(MidiDevice * device, midi_three_byte_func_t func){
-   device->input_cc_callback = func;
+void midi_send_array(MidiDevice* device, uint16_t count, uint8_t* array) {
+    uint16_t i;
+    for (i = 0; i < count; i += 3) {
+        uint8_t  b[3]    = {0, 0, 0};
+        uint16_t to_send = count - i;
+        to_send          = (to_send > 3) ? 3 : to_send;
+        memcpy(b, array + i, to_send);
+        midi_send_data(device, to_send, b[0], b[1], b[2]);
+    }
 }
 
-void midi_register_noteon_callback(MidiDevice * device, midi_three_byte_func_t func){
-   device->input_noteon_callback = func;
-}
+void midi_register_cc_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_cc_callback = func; }
 
-void midi_register_noteoff_callback(MidiDevice * device, midi_three_byte_func_t func){
-   device->input_noteoff_callback = func;
-}
+void midi_register_noteon_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_noteon_callback = func; }
 
-void midi_register_aftertouch_callback(MidiDevice * device, midi_three_byte_func_t func){
-   device->input_aftertouch_callback = func;
-}
+void midi_register_noteoff_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_noteoff_callback = func; }
 
-void midi_register_pitchbend_callback(MidiDevice * device, midi_three_byte_func_t func){
-   device->input_pitchbend_callback = func;
-}
+void midi_register_aftertouch_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_aftertouch_callback = func; }
 
-void midi_register_songposition_callback(MidiDevice * device, midi_three_byte_func_t func){
-   device->input_songposition_callback = func;
-}
+void midi_register_pitchbend_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_pitchbend_callback = func; }
 
-void midi_register_progchange_callback(MidiDevice * device, midi_two_byte_func_t func) {
-   device->input_progchange_callback = func;
-}
+void midi_register_songposition_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_songposition_callback = func; }
 
-void midi_register_chanpressure_callback(MidiDevice * device, midi_two_byte_func_t func) {
-   device->input_chanpressure_callback = func;
-}
+void midi_register_progchange_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_progchange_callback = func; }
 
-void midi_register_songselect_callback(MidiDevice * device, midi_two_byte_func_t func) {
-   device->input_songselect_callback = func;
-}
+void midi_register_chanpressure_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_chanpressure_callback = func; }
 
-void midi_register_tc_quarterframe_callback(MidiDevice * device, midi_two_byte_func_t func) {
-   device->input_tc_quarterframe_callback = func;
-}
+void midi_register_songselect_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_songselect_callback = func; }
 
-void midi_register_realtime_callback(MidiDevice * device, midi_one_byte_func_t func){
-   device->input_realtime_callback = func;
-}
+void midi_register_tc_quarterframe_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_tc_quarterframe_callback = func; }
 
-void midi_register_tunerequest_callback(MidiDevice * device, midi_one_byte_func_t func){
-   device->input_tunerequest_callback = func;
-}
+void midi_register_realtime_callback(MidiDevice* device, midi_one_byte_func_t func) { device->input_realtime_callback = func; }
 
-void midi_register_sysex_callback(MidiDevice * device, midi_sysex_func_t func) {
-   device->input_sysex_callback = func;
-}
+void midi_register_tunerequest_callback(MidiDevice* device, midi_one_byte_func_t func) { device->input_tunerequest_callback = func; }
 
-void midi_register_fallthrough_callback(MidiDevice * device, midi_var_byte_func_t func){
-   device->input_fallthrough_callback = func;
-}
+void midi_register_sysex_callback(MidiDevice* device, midi_sysex_func_t func) { device->input_sysex_callback = func; }
 
-void midi_register_catchall_callback(MidiDevice * device, midi_var_byte_func_t func){
-   device->input_catchall_callback = func;
-}
+void midi_register_fallthrough_callback(MidiDevice* device, midi_var_byte_func_t func) { device->input_fallthrough_callback = func; }
 
+void midi_register_catchall_callback(MidiDevice* device, midi_var_byte_func_t func) { device->input_catchall_callback = func; }
old mode 100755 (executable)
new mode 100644 (file)
index 1a36737..07d8ceb
@@ -1,20 +1,20 @@
-//midi for embedded chips,
-//Copyright 2010 Alex Norman
+// midi for embedded chips,
+// Copyright 2010 Alex Norman
 //
-//This file is part of avr-midi.
+// This file is part of avr-midi.
 //
-//avr-midi is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-midi is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-midi is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-midi is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * @file
@@ -30,7 +30,7 @@
 
 #ifdef __cplusplus
 extern "C" {
-#endif 
+#endif
 
 #include "midi_device.h"
 #include "midi_function_types.h"
@@ -48,8 +48,8 @@ extern "C" {
  * You must call this before using the device in question.
  *
  * @param device the device to initialize
-*/
-void midi_device_init(MidiDevice * device); // [implementation in midi_device.c]
+ */
+void midi_device_init(MidiDevice* device);  // [implementation in midi_device.c]
 
 /**
  * @brief Process input data
@@ -58,8 +58,8 @@ void midi_device_init(MidiDevice * device); // [implementation in midi_device.c]
  * if you expect to have your input callbacks called.
  *
  * @param device the device to process
-*/
-void midi_device_process(MidiDevice * device); // [implementation in midi_device.c]
+ */
+void midi_device_process(MidiDevice* device);  // [implementation in midi_device.c]
 
 /**@}*/
 
@@ -76,8 +76,8 @@ void midi_device_process(MidiDevice * device); // [implementation in midi_device
  * @param chan the channel to send on, 0-15
  * @param num the cc num
  * @param val the value of that cc num
-*/
-void midi_send_cc(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val);
+ */
+void midi_send_cc(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t val);
 
 /**
  * @brief Send a note on message via the given device.
@@ -86,8 +86,8 @@ void midi_send_cc(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val);
  * @param chan the channel to send on, 0-15
  * @param num the note number
  * @param vel the note velocity
-*/
-void midi_send_noteon(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel);
+ */
+void midi_send_noteon(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel);
 
 /**
  * @brief Send a note off message via the given device.
@@ -96,8 +96,8 @@ void midi_send_noteon(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t ve
  * @param chan the channel to send on, 0-15
  * @param num the note number
  * @param vel the note velocity
-*/
-void midi_send_noteoff(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel);
+ */
+void midi_send_noteoff(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel);
 
 /**
  * @brief Send an after touch message via the given device.
@@ -106,8 +106,8 @@ void midi_send_noteoff(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t v
  * @param chan the channel to send on, 0-15
  * @param note_num the note number
  * @param amt the after touch amount
-*/
-void midi_send_aftertouch(MidiDevice * device, uint8_t chan, uint8_t note_num, uint8_t amt);
+ */
+void midi_send_aftertouch(MidiDevice* device, uint8_t chan, uint8_t note_num, uint8_t amt);
 
 /**
  * @brief Send a pitch bend message via the given device.
@@ -115,8 +115,8 @@ void midi_send_aftertouch(MidiDevice * device, uint8_t chan, uint8_t note_num, u
  * @param device the device to use for sending
  * @param chan the channel to send on, 0-15
  * @param amt the bend amount range: -8192..8191, 0 means no bend
-*/
-void midi_send_pitchbend(MidiDevice * device, uint8_t chan, int16_t amt); //range -8192, 8191
+ */
+void midi_send_pitchbend(MidiDevice* device, uint8_t chan, int16_t amt);  // range -8192, 8191
 
 /**
  * @brief Send a program change message via the given device.
@@ -124,8 +124,8 @@ void midi_send_pitchbend(MidiDevice * device, uint8_t chan, int16_t amt); //rang
  * @param device the device to use for sending
  * @param chan the channel to send on, 0-15
  * @param num the program to change to
-*/
-void midi_send_programchange(MidiDevice * device, uint8_t chan, uint8_t num);
+ */
+void midi_send_programchange(MidiDevice* device, uint8_t chan, uint8_t num);
 
 /**
  * @brief Send a channel pressure message via the given device.
@@ -133,58 +133,57 @@ void midi_send_programchange(MidiDevice * device, uint8_t chan, uint8_t num);
  * @param device the device to use for sending
  * @param chan the channel to send on, 0-15
  * @param amt the amount of channel pressure
-*/
-void midi_send_channelpressure(MidiDevice * device, uint8_t chan, uint8_t amt);
+ */
+void midi_send_channelpressure(MidiDevice* device, uint8_t chan, uint8_t amt);
 
 /**
  * @brief Send a clock message via the given device.
  *
  * @param device the device to use for sending
  */
-void midi_send_clock(MidiDevice * device);
+void midi_send_clock(MidiDevice* device);
 
 /**
  * @brief Send a tick message via the given device.
  *
  * @param device the device to use for sending
  */
-void midi_send_tick(MidiDevice * device);
+void midi_send_tick(MidiDevice* device);
 
 /**
  * @brief Send a start message via the given device.
  *
  * @param device the device to use for sending
  */
-void midi_send_start(MidiDevice * device);
+void midi_send_start(MidiDevice* device);
 
 /**
  * @brief Send a continue message via the given device.
  *
  * @param device the device to use for sending
  */
-void midi_send_continue(MidiDevice * device);
+void midi_send_continue(MidiDevice* device);
 
 /**
  * @brief Send a stop message via the given device.
  *
  * @param device the device to use for sending
  */
-void midi_send_stop(MidiDevice * device);
+void midi_send_stop(MidiDevice* device);
 
 /**
  * @brief Send an active sense message via the given device.
  *
  * @param device the device to use for sending
  */
-void midi_send_activesense(MidiDevice * device);
+void midi_send_activesense(MidiDevice* device);
 
 /**
  * @brief Send a reset message via the given device.
  *
  * @param device the device to use for sending
  */
-void midi_send_reset(MidiDevice * device);
-
+void midi_send_reset(MidiDevice* device);
 
 /**
  * @brief Send a tc quarter frame message via the given device.
@@ -192,7 +191,7 @@ void midi_send_reset(MidiDevice * device);
  * @param device the device to use for sending
  * @param time the time of this quarter frame, range 0..16383
  */
-void midi_send_tcquarterframe(MidiDevice * device, uint8_t time);
+void midi_send_tcquarterframe(MidiDevice* device, uint8_t time);
 
 /**
  * @brief Send a song position message via the given device.
@@ -200,7 +199,7 @@ void midi_send_tcquarterframe(MidiDevice * device, uint8_t time);
  * @param device the device to use for sending
  * @param pos the song position
  */
-void midi_send_songposition(MidiDevice * device, uint16_t pos);
+void midi_send_songposition(MidiDevice* device, uint16_t pos);
 
 /**
  * @brief Send a song select message via the given device.
@@ -208,14 +207,14 @@ void midi_send_songposition(MidiDevice * device, uint16_t pos);
  * @param device the device to use for sending
  * @param song the song to select
  */
-void midi_send_songselect(MidiDevice * device, uint8_t song);
+void midi_send_songselect(MidiDevice* device, uint8_t song);
 
 /**
  * @brief Send a tune request message via the given device.
  *
  * @param device the device to use for sending
  */
-void midi_send_tunerequest(MidiDevice * device);
+void midi_send_tunerequest(MidiDevice* device);
 
 /**
  * @brief Send a byte via the given device.
@@ -228,7 +227,7 @@ void midi_send_tunerequest(MidiDevice * device);
  * @param device the device to use for sending
  * @param b the byte to send
  */
-void midi_send_byte(MidiDevice * device, uint8_t b);
+void midi_send_byte(MidiDevice* device, uint8_t b);
 
 /**
  * @brief Send up to 3 bytes of data
@@ -241,7 +240,7 @@ void midi_send_byte(MidiDevice * device, uint8_t b);
  * @param byte1 the second byte, ignored if cnt % 4 != 2
  * @param byte2 the third byte, ignored if cnt % 4 != 3
  */
-void midi_send_data(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2);
+void midi_send_data(MidiDevice* device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2);
 
 /**
  * @brief Send an array of formatted midi data.
@@ -252,14 +251,13 @@ void midi_send_data(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t
  * @param count the count of bytes to send
  * @param array the array of bytes
  */
-void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array);
+void midi_send_array(MidiDevice* device, uint16_t count, uint8_t* array);
 
 /**@}*/
 
-
 /**
  * @defgroup input_callback_reg Input callback registration functions
- * 
+ *
  * @brief These are the functions you use to register your input callbacks.
  *
  * The functions are called when the appropriate midi message is matched on the
@@ -268,7 +266,7 @@ void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array);
  * @{
  */
 
-//three byte funcs
+// three byte funcs
 
 /**
  * @brief Register a control change message (cc) callback.
@@ -276,7 +274,7 @@ void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array);
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_cc_callback(MidiDevice * device, midi_three_byte_func_t func);
+void midi_register_cc_callback(MidiDevice* device, midi_three_byte_func_t func);
 
 /**
  * @brief Register a note on callback.
@@ -284,7 +282,7 @@ void midi_register_cc_callback(MidiDevice * device, midi_three_byte_func_t func)
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_noteon_callback(MidiDevice * device, midi_three_byte_func_t func);
+void midi_register_noteon_callback(MidiDevice* device, midi_three_byte_func_t func);
 
 /**
  * @brief Register a note off callback.
@@ -292,7 +290,7 @@ void midi_register_noteon_callback(MidiDevice * device, midi_three_byte_func_t f
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_noteoff_callback(MidiDevice * device, midi_three_byte_func_t func);
+void midi_register_noteoff_callback(MidiDevice* device, midi_three_byte_func_t func);
 
 /**
  * @brief Register an after touch callback.
@@ -301,7 +299,7 @@ void midi_register_noteoff_callback(MidiDevice * device, midi_three_byte_func_t
  * @param func the callback function to register
  */
 
-void midi_register_aftertouch_callback(MidiDevice * device, midi_three_byte_func_t func);
+void midi_register_aftertouch_callback(MidiDevice* device, midi_three_byte_func_t func);
 
 /**
  * @brief Register a pitch bend callback.
@@ -309,7 +307,7 @@ void midi_register_aftertouch_callback(MidiDevice * device, midi_three_byte_func
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_pitchbend_callback(MidiDevice * device, midi_three_byte_func_t func);
+void midi_register_pitchbend_callback(MidiDevice* device, midi_three_byte_func_t func);
 
 /**
  * @brief Register a song position callback.
@@ -317,9 +315,9 @@ void midi_register_pitchbend_callback(MidiDevice * device, midi_three_byte_func_
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_songposition_callback(MidiDevice * device, midi_three_byte_func_t func);
+void midi_register_songposition_callback(MidiDevice* device, midi_three_byte_func_t func);
 
-//two byte funcs
+// two byte funcs
 
 /**
  * @brief Register a program change callback.
@@ -327,7 +325,7 @@ void midi_register_songposition_callback(MidiDevice * device, midi_three_byte_fu
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_progchange_callback(MidiDevice * device, midi_two_byte_func_t func);
+void midi_register_progchange_callback(MidiDevice* device, midi_two_byte_func_t func);
 
 /**
  * @brief Register a channel pressure callback.
@@ -335,7 +333,7 @@ void midi_register_progchange_callback(MidiDevice * device, midi_two_byte_func_t
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_chanpressure_callback(MidiDevice * device, midi_two_byte_func_t func);
+void midi_register_chanpressure_callback(MidiDevice* device, midi_two_byte_func_t func);
 
 /**
  * @brief Register a song select callback.
@@ -343,7 +341,7 @@ void midi_register_chanpressure_callback(MidiDevice * device, midi_two_byte_func
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_songselect_callback(MidiDevice * device, midi_two_byte_func_t func);
+void midi_register_songselect_callback(MidiDevice* device, midi_two_byte_func_t func);
 
 /**
  * @brief Register a tc quarter frame callback.
@@ -351,9 +349,9 @@ void midi_register_songselect_callback(MidiDevice * device, midi_two_byte_func_t
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_tc_quarterframe_callback(MidiDevice * device, midi_two_byte_func_t func);
+void midi_register_tc_quarterframe_callback(MidiDevice* device, midi_two_byte_func_t func);
 
-//one byte funcs
+// one byte funcs
 
 /**
  * @brief Register a realtime callback.
@@ -363,7 +361,7 @@ void midi_register_tc_quarterframe_callback(MidiDevice * device, midi_two_byte_f
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_realtime_callback(MidiDevice * device, midi_one_byte_func_t func);
+void midi_register_realtime_callback(MidiDevice* device, midi_one_byte_func_t func);
 
 /**
  * @brief Register a tune request callback.
@@ -371,7 +369,7 @@ void midi_register_realtime_callback(MidiDevice * device, midi_one_byte_func_t f
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_tunerequest_callback(MidiDevice * device, midi_one_byte_func_t func);
+void midi_register_tunerequest_callback(MidiDevice* device, midi_one_byte_func_t func);
 
 /**
  * @brief Register a sysex callback.
@@ -379,7 +377,7 @@ void midi_register_tunerequest_callback(MidiDevice * device, midi_one_byte_func_
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_sysex_callback(MidiDevice * device, midi_sysex_func_t func);
+void midi_register_sysex_callback(MidiDevice* device, midi_sysex_func_t func);
 
 /**
  * @brief Register fall through callback.
@@ -391,8 +389,7 @@ void midi_register_sysex_callback(MidiDevice * device, midi_sysex_func_t func);
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_fallthrough_callback(MidiDevice * device, midi_var_byte_func_t func);
-
+void midi_register_fallthrough_callback(MidiDevice* device, midi_var_byte_func_t func);
 
 /**
  * @brief Register a catch all callback.
@@ -403,7 +400,7 @@ void midi_register_fallthrough_callback(MidiDevice * device, midi_var_byte_func_
  * @param device the device associate with
  * @param func the callback function to register
  */
-void midi_register_catchall_callback(MidiDevice * device, midi_var_byte_func_t func);
+void midi_register_catchall_callback(MidiDevice* device, midi_var_byte_func_t func);
 
 /**@}*/
 
@@ -417,11 +414,7 @@ void midi_register_catchall_callback(MidiDevice * device, midi_var_byte_func_t f
  *
  * An enumeration of the possible packet length values.
  */
-typedef enum {
-   UNDEFINED = 0,
-   ONE = 1,
-   TWO = 2,
-   THREE = 3} midi_packet_length_t;
+typedef enum { UNDEFINED = 0, ONE = 1, TWO = 2, THREE = 3 } midi_packet_length_t;
 
 /**
  * @brief Test to see if the byte given is a status byte
@@ -456,11 +449,11 @@ midi_packet_length_t midi_packet_length(uint8_t status);
 #define SYSEX_BEGIN 0xF0
 #define SYSEX_END 0xF7
 
-//if you and this with a byte and you get anything non-zero
-//it is a status message
+// if you and this with a byte and you get anything non-zero
+// it is a status message
 #define MIDI_STATUSMASK 0x80
-//if you and this with a status message that contains channel info,
-//you'll get the channel
+// if you and this with a status message that contains channel info,
+// you'll get the channel
 #define MIDI_CHANMASK 0x0F
 
 #define MIDI_CC 0xB0
@@ -471,7 +464,7 @@ midi_packet_length_t midi_packet_length(uint8_t status);
 #define MIDI_PROGCHANGE 0xC0
 #define MIDI_CHANPRESSURE 0xD0
 
-//midi realtime
+// midi realtime
 #define MIDI_CLOCK 0xF8
 #define MIDI_TICK 0xF9
 #define MIDI_START 0xFA
@@ -485,14 +478,13 @@ midi_packet_length_t midi_packet_length(uint8_t status);
 #define MIDI_SONGSELECT 0xF3
 #define MIDI_TUNEREQUEST 0xF6
 
-//This ID is for educational or development use only
+// This ID is for educational or development use only
 #define SYSEX_EDUMANUFID 0x7D
 
 /**@}*/
 
 #ifdef __cplusplus
 }
-#endif 
-
 #endif
 
+#endif
old mode 100755 (executable)
new mode 100644 (file)
index 3215a00..58fe685
-//midi for embedded chips,
-//Copyright 2010 Alex Norman
+// midi for embedded chips,
+// Copyright 2010 Alex Norman
 //
-//This file is part of avr-midi.
+// This file is part of avr-midi.
 //
-//avr-midi is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-midi is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-midi is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-midi is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "midi_device.h"
 #include "midi.h"
 
 #ifndef NULL
-#define NULL 0
+#    define NULL 0
 #endif
 
-//forward declarations, internally used to call the callbacks
-void midi_input_callbacks(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2);
-void midi_process_byte(MidiDevice * device, uint8_t input);
+// forward declarations, internally used to call the callbacks
+void midi_input_callbacks(MidiDevice* device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2);
+void midi_process_byte(MidiDevice* device, uint8_t input);
 
-void midi_device_init(MidiDevice * device){
-  device->input_state = IDLE;
-  device->input_count = 0;
-  bytequeue_init(&device->input_queue, device->input_queue_data, MIDI_INPUT_QUEUE_LENGTH);
+void midi_device_init(MidiDevice* device) {
+    device->input_state = IDLE;
+    device->input_count = 0;
+    bytequeue_init(&device->input_queue, device->input_queue_data, MIDI_INPUT_QUEUE_LENGTH);
 
-  //three byte funcs
-  device->input_cc_callback = NULL;
-  device->input_noteon_callback = NULL;
-  device->input_noteoff_callback = NULL;
-  device->input_aftertouch_callback = NULL;
-  device->input_pitchbend_callback = NULL;
-  device->input_songposition_callback = NULL;
+    // three byte funcs
+    device->input_cc_callback           = NULL;
+    device->input_noteon_callback       = NULL;
+    device->input_noteoff_callback      = NULL;
+    device->input_aftertouch_callback   = NULL;
+    device->input_pitchbend_callback    = NULL;
+    device->input_songposition_callback = NULL;
 
-  //two byte funcs
-  device->input_progchange_callback = NULL;
-  device->input_chanpressure_callback = NULL;
-  device->input_songselect_callback = NULL;
-  device->input_tc_quarterframe_callback = NULL;
+    // two byte funcs
+    device->input_progchange_callback      = NULL;
+    device->input_chanpressure_callback    = NULL;
+    device->input_songselect_callback      = NULL;
+    device->input_tc_quarterframe_callback = NULL;
 
-  //one byte funcs
-  device->input_realtime_callback = NULL;
-  device->input_tunerequest_callback = NULL;
+    // one byte funcs
+    device->input_realtime_callback    = NULL;
+    device->input_tunerequest_callback = NULL;
 
-  //var byte functions
-  device->input_sysex_callback = NULL;
-  device->input_fallthrough_callback = NULL;
-  device->input_catchall_callback = NULL;
+    // var byte functions
+    device->input_sysex_callback       = NULL;
+    device->input_fallthrough_callback = NULL;
+    device->input_catchall_callback    = NULL;
 
-  device->pre_input_process_callback = NULL;
+    device->pre_input_process_callback = NULL;
 }
 
-void midi_device_input(MidiDevice * device, uint8_t cnt, uint8_t * input) {
-  uint8_t i;
-  for (i = 0; i < cnt; i++)
-    bytequeue_enqueue(&device->input_queue, input[i]);
+void midi_device_input(MidiDevice* device, uint8_t cnt, uint8_t* input) {
+    uint8_t i;
+    for (i = 0; i < cnt; i++) bytequeue_enqueue(&device->input_queue, input[i]);
 }
 
-void midi_device_set_send_func(MidiDevice * device, midi_var_byte_func_t send_func){
-  device->send_func = send_func;
-}
+void midi_device_set_send_func(MidiDevice* device, midi_var_byte_func_t send_func) { device->send_func = send_func; }
 
-void midi_device_set_pre_input_process_func(MidiDevice * device, midi_no_byte_func_t pre_process_func){
-  device->pre_input_process_callback = pre_process_func;
-}
+void midi_device_set_pre_input_process_func(MidiDevice* device, midi_no_byte_func_t pre_process_func) { device->pre_input_process_callback = pre_process_func; }
 
-void midi_device_process(MidiDevice * device) {
-  //call the pre_input_process_callback if there is one
-  if(device->pre_input_process_callback)
-    device->pre_input_process_callback(device);
+void midi_device_process(MidiDevice* device) {
+    // call the pre_input_process_callback if there is one
+    if (device->pre_input_process_callback) device->pre_input_process_callback(device);
 
-  //pull stuff off the queue and process
-  byteQueueIndex_t len = bytequeue_length(&device->input_queue);
-  uint16_t i;
-  //TODO limit number of bytes processed?
-  for(i = 0; i < len; i++) {
-    uint8_t val = bytequeue_get(&device->input_queue, 0);
-    midi_process_byte(device, val);
-    bytequeue_remove(&device->input_queue, 1);
-  }
+    // pull stuff off the queue and process
+    byteQueueIndex_t len = bytequeue_length(&device->input_queue);
+    uint16_t         i;
+    // TODO limit number of bytes processed?
+    for (i = 0; i < len; i++) {
+        uint8_t val = bytequeue_get(&device->input_queue, 0);
+        midi_process_byte(device, val);
+        bytequeue_remove(&device->input_queue, 1);
+    }
 }
 
-void midi_process_byte(MidiDevice * device, uint8_t input) {
-  if (midi_is_realtime(input)) {
-    //call callback, store and restore state
-    input_state_t state = device->input_state;
-    device->input_state = ONE_BYTE_MESSAGE;
-    midi_input_callbacks(device, 1, input, 0, 0);
-    device->input_state = state;
-  } else if (midi_is_statusbyte(input)) {
-    //store the byte
-    if (device->input_state != SYSEX_MESSAGE) {
-      device->input_buffer[0] = input;
-      device->input_count = 1;
-    }
-    switch (midi_packet_length(input)) {
-      case ONE:
-        device->input_state = ONE_BYTE_MESSAGE;;
+void midi_process_byte(MidiDevice* device, uint8_t input) {
+    if (midi_is_realtime(input)) {
+        // call callback, store and restore state
+        input_state_t state = device->input_state;
+        device->input_state = ONE_BYTE_MESSAGE;
         midi_input_callbacks(device, 1, input, 0, 0);
-        device->input_state = IDLE;
-        break;
-      case TWO:
-        device->input_state = TWO_BYTE_MESSAGE;
-        break;
-      case THREE:
-        device->input_state = THREE_BYTE_MESSAGE;
-        break;
-      case UNDEFINED:
-        switch(input) {
-          case SYSEX_BEGIN:
-            device->input_state = SYSEX_MESSAGE;
+        device->input_state = state;
+    } else if (midi_is_statusbyte(input)) {
+        // store the byte
+        if (device->input_state != SYSEX_MESSAGE) {
             device->input_buffer[0] = input;
-            device->input_count = 1;
-            break;
-          case SYSEX_END:
-            //send what is left in the input buffer, set idle
-            device->input_buffer[device->input_count % 3] = input;
-            device->input_count += 1;
-            //call the callback
-            midi_input_callbacks(device, device->input_count, 
-                device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
-            device->input_state = IDLE;
-            break;
-          default:
-            device->input_state = IDLE;
-            device->input_count = 0;
+            device->input_count     = 1;
         }
+        switch (midi_packet_length(input)) {
+            case ONE:
+                device->input_state = ONE_BYTE_MESSAGE;
+                ;
+                midi_input_callbacks(device, 1, input, 0, 0);
+                device->input_state = IDLE;
+                break;
+            case TWO:
+                device->input_state = TWO_BYTE_MESSAGE;
+                break;
+            case THREE:
+                device->input_state = THREE_BYTE_MESSAGE;
+                break;
+            case UNDEFINED:
+                switch (input) {
+                    case SYSEX_BEGIN:
+                        device->input_state     = SYSEX_MESSAGE;
+                        device->input_buffer[0] = input;
+                        device->input_count     = 1;
+                        break;
+                    case SYSEX_END:
+                        // send what is left in the input buffer, set idle
+                        device->input_buffer[device->input_count % 3] = input;
+                        device->input_count += 1;
+                        // call the callback
+                        midi_input_callbacks(device, device->input_count, device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
+                        device->input_state = IDLE;
+                        break;
+                    default:
+                        device->input_state = IDLE;
+                        device->input_count = 0;
+                }
 
-        break;
-      default:
-        device->input_state = IDLE;
-        device->input_count = 0;
-        break;
-    }
-  } else {
-    if (device->input_state != IDLE) {
-      //store the byte
-      device->input_buffer[device->input_count % 3] = input;
-      //increment count
-      uint16_t prev = device->input_count;
-      device->input_count += 1;
+                break;
+            default:
+                device->input_state = IDLE;
+                device->input_count = 0;
+                break;
+        }
+    } else {
+        if (device->input_state != IDLE) {
+            // store the byte
+            device->input_buffer[device->input_count % 3] = input;
+            // increment count
+            uint16_t prev = device->input_count;
+            device->input_count += 1;
 
-      switch(prev % 3) {
-        case 2:
-          //call callback
-          midi_input_callbacks(device, device->input_count,
-              device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
-          if (device->input_state != SYSEX_MESSAGE) {
-            //set to 1, keeping status byte, allowing for running status
-            device->input_count = 1;
-          }
-          break;
-        case 1:
-          if (device->input_state == TWO_BYTE_MESSAGE) {
-            //call callback
-            midi_input_callbacks(device, device->input_count,
-                device->input_buffer[0], device->input_buffer[1], 0);
-            if (device->input_state != SYSEX_MESSAGE) {
-              //set to 1, keeping status byte, allowing for running status
-              device->input_count = 1;
+            switch (prev % 3) {
+                case 2:
+                    // call callback
+                    midi_input_callbacks(device, device->input_count, device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
+                    if (device->input_state != SYSEX_MESSAGE) {
+                        // set to 1, keeping status byte, allowing for running status
+                        device->input_count = 1;
+                    }
+                    break;
+                case 1:
+                    if (device->input_state == TWO_BYTE_MESSAGE) {
+                        // call callback
+                        midi_input_callbacks(device, device->input_count, device->input_buffer[0], device->input_buffer[1], 0);
+                        if (device->input_state != SYSEX_MESSAGE) {
+                            // set to 1, keeping status byte, allowing for running status
+                            device->input_count = 1;
+                        }
+                    }
+                    break;
+                case 0:
+                default:
+                    // one byte messages are dealt with directly
+                    break;
             }
-          }
-          break;
-        case 0:
-        default:
-          //one byte messages are dealt with directly
-          break;
-      }
+        }
     }
-  }
 }
 
-void midi_input_callbacks(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
-  //did we end up calling a callback?
-  bool called = false;
-  if (device->input_state == SYSEX_MESSAGE) {
-    if (device->input_sysex_callback) {
-      const uint16_t start = ((cnt - 1) / 3) * 3;
-      const uint8_t length = (cnt - start);
-      uint8_t data[3];
-      data[0] = byte0;
-      data[1] = byte1;
-      data[2] = byte2;
-      device->input_sysex_callback(device, start, length, data);
-      called = true;
-    }
-  } else {
-    switch (cnt) {
-      case 3:
-        {
-          midi_three_byte_func_t func = NULL;
-          switch (byte0 & 0xF0) {
-            case MIDI_CC:
-              func = device->input_cc_callback;
-              break;
-            case MIDI_NOTEON:
-              func = device->input_noteon_callback;
-              break;
-            case MIDI_NOTEOFF:
-              func = device->input_noteoff_callback;
-              break;
-            case MIDI_AFTERTOUCH:
-              func = device->input_aftertouch_callback;
-              break;
-            case MIDI_PITCHBEND:
-              func = device->input_pitchbend_callback;
-              break;
-            case 0xF0:
-              if (byte0 == MIDI_SONGPOSITION)
-                func = device->input_songposition_callback;
-              break;
-            default:
-              break;
-          }
-          if(func) {
-            //mask off the channel for non song position functions
-            if (byte0 == MIDI_SONGPOSITION)
-              func(device, byte0, byte1, byte2);
-            else
-              func(device, byte0 & 0x0F, byte1, byte2);
+void midi_input_callbacks(MidiDevice* device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
+    // did we end up calling a callback?
+    bool called = false;
+    if (device->input_state == SYSEX_MESSAGE) {
+        if (device->input_sysex_callback) {
+            const uint16_t start  = ((cnt - 1) / 3) * 3;
+            const uint8_t  length = (cnt - start);
+            uint8_t        data[3];
+            data[0] = byte0;
+            data[1] = byte1;
+            data[2] = byte2;
+            device->input_sysex_callback(device, start, length, data);
             called = true;
-          }
         }
-        break;
-      case 2:
-        {
-          midi_two_byte_func_t func = NULL;
-          switch (byte0 & 0xF0) {
-            case MIDI_PROGCHANGE:
-              func = device->input_progchange_callback;
-              break;
-            case MIDI_CHANPRESSURE:
-              func = device->input_chanpressure_callback;
-              break;
-            case 0xF0:
-              if (byte0 == MIDI_SONGSELECT)
-                func = device->input_songselect_callback;
-              else if (byte0 == MIDI_TC_QUARTERFRAME)
-                func = device->input_tc_quarterframe_callback;
-              break;
+    } else {
+        switch (cnt) {
+            case 3: {
+                midi_three_byte_func_t func = NULL;
+                switch (byte0 & 0xF0) {
+                    case MIDI_CC:
+                        func = device->input_cc_callback;
+                        break;
+                    case MIDI_NOTEON:
+                        func = device->input_noteon_callback;
+                        break;
+                    case MIDI_NOTEOFF:
+                        func = device->input_noteoff_callback;
+                        break;
+                    case MIDI_AFTERTOUCH:
+                        func = device->input_aftertouch_callback;
+                        break;
+                    case MIDI_PITCHBEND:
+                        func = device->input_pitchbend_callback;
+                        break;
+                    case 0xF0:
+                        if (byte0 == MIDI_SONGPOSITION) func = device->input_songposition_callback;
+                        break;
+                    default:
+                        break;
+                }
+                if (func) {
+                    // mask off the channel for non song position functions
+                    if (byte0 == MIDI_SONGPOSITION)
+                        func(device, byte0, byte1, byte2);
+                    else
+                        func(device, byte0 & 0x0F, byte1, byte2);
+                    called = true;
+                }
+            } break;
+            case 2: {
+                midi_two_byte_func_t func = NULL;
+                switch (byte0 & 0xF0) {
+                    case MIDI_PROGCHANGE:
+                        func = device->input_progchange_callback;
+                        break;
+                    case MIDI_CHANPRESSURE:
+                        func = device->input_chanpressure_callback;
+                        break;
+                    case 0xF0:
+                        if (byte0 == MIDI_SONGSELECT)
+                            func = device->input_songselect_callback;
+                        else if (byte0 == MIDI_TC_QUARTERFRAME)
+                            func = device->input_tc_quarterframe_callback;
+                        break;
+                    default:
+                        break;
+                }
+                if (func) {
+                    // mask off the channel
+                    if (byte0 == MIDI_SONGSELECT || byte0 == MIDI_TC_QUARTERFRAME)
+                        func(device, byte0, byte1);
+                    else
+                        func(device, byte0 & 0x0F, byte1);
+                    called = true;
+                }
+            } break;
+            case 1: {
+                midi_one_byte_func_t func = NULL;
+                if (midi_is_realtime(byte0))
+                    func = device->input_realtime_callback;
+                else if (byte0 == MIDI_TUNEREQUEST)
+                    func = device->input_tunerequest_callback;
+                if (func) {
+                    func(device, byte0);
+                    called = true;
+                }
+            } break;
             default:
-              break;
-          }
-          if(func) {
-            //mask off the channel
-            if (byte0 == MIDI_SONGSELECT || byte0 == MIDI_TC_QUARTERFRAME)
-              func(device, byte0, byte1);
-            else
-              func(device, byte0 & 0x0F, byte1);
-            called = true;
-          }
-        }
-        break;
-      case 1:
-        {
-          midi_one_byte_func_t func = NULL;
-          if (midi_is_realtime(byte0))
-            func = device->input_realtime_callback;
-          else if (byte0 == MIDI_TUNEREQUEST)
-            func = device->input_tunerequest_callback;
-          if (func) {
-            func(device, byte0);
-            called = true;
-          }
+                // just in case
+                if (cnt > 3) cnt = 0;
+                break;
         }
-        break;
-      default:
-        //just in case
-        if (cnt > 3)
-          cnt = 0;
-        break;
     }
-  }
 
-  //if there is fallthrough default callback and we haven't called a more specific one, 
-  //call the fallthrough
-  if (!called && device->input_fallthrough_callback)
-    device->input_fallthrough_callback(device, cnt, byte0, byte1, byte2);
-  //always call the catch all if it exists
-  if (device->input_catchall_callback)
-    device->input_catchall_callback(device, cnt, byte0, byte1, byte2);
+    // if there is fallthrough default callback and we haven't called a more specific one,
+    // call the fallthrough
+    if (!called && device->input_fallthrough_callback) device->input_fallthrough_callback(device, cnt, byte0, byte1, byte2);
+    // always call the catch all if it exists
+    if (device->input_catchall_callback) device->input_catchall_callback(device, cnt, byte0, byte1, byte2);
 }
-
old mode 100755 (executable)
new mode 100644 (file)
index 0889952..693d81a
@@ -1,20 +1,20 @@
-//midi for embedded chips,
-//Copyright 2010 Alex Norman
+// midi for embedded chips,
+// Copyright 2010 Alex Norman
 //
-//This file is part of avr-midi.
+// This file is part of avr-midi.
 //
-//avr-midi is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-midi is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-midi is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-midi is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * @file
@@ -26,7 +26,7 @@
 
 #ifdef __cplusplus
 extern "C" {
-#endif 
+#endif
 
 /**
  * @defgroup midi_device Functions used when implementing your own midi device.
@@ -51,14 +51,9 @@ extern "C" {
 #include "bytequeue/bytequeue.h"
 #define MIDI_INPUT_QUEUE_LENGTH 192
 
-typedef enum {
-   IDLE, 
-   ONE_BYTE_MESSAGE = 1,
-   TWO_BYTE_MESSAGE = 2, 
-   THREE_BYTE_MESSAGE = 3,
-   SYSEX_MESSAGE} input_state_t;
+typedef enum { IDLE, ONE_BYTE_MESSAGE = 1, TWO_BYTE_MESSAGE = 2, THREE_BYTE_MESSAGE = 3, SYSEX_MESSAGE } input_state_t;
 
-typedef void (* midi_no_byte_func_t)(MidiDevice * device);
+typedef void (*midi_no_byte_func_t)(MidiDevice* device);
 
 /**
  * \struct _midi_device
@@ -71,45 +66,45 @@ typedef void (* midi_no_byte_func_t)(MidiDevice * device);
  * You should not need to modify this structure directly.
  */
 struct _midi_device {
-   //output send function
-   midi_var_byte_func_t send_func;
-
-   //********input callbacks
-   //three byte funcs
-   midi_three_byte_func_t input_cc_callback;
-   midi_three_byte_func_t input_noteon_callback;
-   midi_three_byte_func_t input_noteoff_callback;
-   midi_three_byte_func_t input_aftertouch_callback;
-   midi_three_byte_func_t input_pitchbend_callback;
-   midi_three_byte_func_t input_songposition_callback;
-   //two byte funcs
-   midi_two_byte_func_t input_progchange_callback;
-   midi_two_byte_func_t input_chanpressure_callback;
-   midi_two_byte_func_t input_songselect_callback;
-   midi_two_byte_func_t input_tc_quarterframe_callback;
-   //one byte funcs
-   midi_one_byte_func_t input_realtime_callback;
-   midi_one_byte_func_t input_tunerequest_callback;
-
-   //sysex
-   midi_sysex_func_t input_sysex_callback;
-
-   //only called if more specific callback is not matched
-   midi_var_byte_func_t input_fallthrough_callback;
-   //called if registered, independent of other callbacks
-   midi_var_byte_func_t input_catchall_callback;
-
-   //pre input processing function
-   midi_no_byte_func_t pre_input_process_callback;
-
-   //for internal input processing
-   uint8_t input_buffer[3];
-   input_state_t input_state;
-   uint16_t input_count;
-
-   //for queueing data between the input and the processing functions
-   uint8_t input_queue_data[MIDI_INPUT_QUEUE_LENGTH];
-   byteQueue_t input_queue;
+    // output send function
+    midi_var_byte_func_t send_func;
+
+    //********input callbacks
+    // three byte funcs
+    midi_three_byte_func_t input_cc_callback;
+    midi_three_byte_func_t input_noteon_callback;
+    midi_three_byte_func_t input_noteoff_callback;
+    midi_three_byte_func_t input_aftertouch_callback;
+    midi_three_byte_func_t input_pitchbend_callback;
+    midi_three_byte_func_t input_songposition_callback;
+    // two byte funcs
+    midi_two_byte_func_t input_progchange_callback;
+    midi_two_byte_func_t input_chanpressure_callback;
+    midi_two_byte_func_t input_songselect_callback;
+    midi_two_byte_func_t input_tc_quarterframe_callback;
+    // one byte funcs
+    midi_one_byte_func_t input_realtime_callback;
+    midi_one_byte_func_t input_tunerequest_callback;
+
+    // sysex
+    midi_sysex_func_t input_sysex_callback;
+
+    // only called if more specific callback is not matched
+    midi_var_byte_func_t input_fallthrough_callback;
+    // called if registered, independent of other callbacks
+    midi_var_byte_func_t input_catchall_callback;
+
+    // pre input processing function
+    midi_no_byte_func_t pre_input_process_callback;
+
+    // for internal input processing
+    uint8_t       input_buffer[3];
+    input_state_t input_state;
+    uint16_t      input_count;
+
+    // for queueing data between the input and the processing functions
+    uint8_t     input_queue_data[MIDI_INPUT_QUEUE_LENGTH];
+    byteQueue_t input_queue;
 };
 
 /**
@@ -122,7 +117,7 @@ struct _midi_device {
  * @param cnt the number of bytes you are processing
  * @param input the bytes to process
  */
-void midi_device_input(MidiDevice * device, uint8_t cnt, uint8_t * input);
+void midi_device_input(MidiDevice* device, uint8_t cnt, uint8_t* input);
 
 /**
  * @brief Set the callback function that will be used for sending output
@@ -134,7 +129,7 @@ void midi_device_input(MidiDevice * device, uint8_t cnt, uint8_t * input);
  * \param device the midi device to associate this callback with
  * \param send_func the callback function that will do the sending
  */
-void midi_device_set_send_func(MidiDevice * device, midi_var_byte_func_t send_func);
+void midi_device_set_send_func(MidiDevice* device, midi_var_byte_func_t send_func);
 
 /**
  * @brief Set a callback which is called at the beginning of the
@@ -145,12 +140,12 @@ void midi_device_set_send_func(MidiDevice * device, midi_var_byte_func_t send_fu
  * \param device the midi device to associate this callback with
  * \param midi_no_byte_func_t the actual callback function
  */
-void midi_device_set_pre_input_process_func(MidiDevice * device, midi_no_byte_func_t pre_process_func);
+void midi_device_set_pre_input_process_func(MidiDevice* device, midi_no_byte_func_t pre_process_func);
 
 /**@}*/
 
 #ifdef __cplusplus
 }
-#endif 
+#endif
 
 #endif
old mode 100755 (executable)
new mode 100644 (file)
index 35c4601..761e881
@@ -1,20 +1,20 @@
-//midi for embedded chips,
-//Copyright 2010 Alex Norman
+// midi for embedded chips,
+// Copyright 2010 Alex Norman
 //
-//This file is part of avr-midi.
+// This file is part of avr-midi.
 //
-//avr-midi is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-midi is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-midi is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-midi is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * @file
 
 #ifdef __cplusplus
 extern "C" {
-#endif 
+#endif
 
 #include <inttypes.h>
 #include <stdbool.h>
 
-//forward declaration
+// forward declaration
 typedef struct _midi_device MidiDevice;
 
-typedef void (* midi_one_byte_func_t)(MidiDevice * device, uint8_t byte);
-typedef void (* midi_two_byte_func_t)(MidiDevice * device, uint8_t byte0, uint8_t byte1);
-typedef void (* midi_three_byte_func_t)(MidiDevice * device, uint8_t byte0, uint8_t byte1, uint8_t byte2);
-//all bytes after count bytes should be ignored
-typedef void (* midi_var_byte_func_t)(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2);
+typedef void (*midi_one_byte_func_t)(MidiDevice *device, uint8_t byte);
+typedef void (*midi_two_byte_func_t)(MidiDevice *device, uint8_t byte0, uint8_t byte1);
+typedef void (*midi_three_byte_func_t)(MidiDevice *device, uint8_t byte0, uint8_t byte1, uint8_t byte2);
+// all bytes after count bytes should be ignored
+typedef void (*midi_var_byte_func_t)(MidiDevice *device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2);
 
-//the start byte tells you how far into the sysex message you are, the data_length tells you how many bytes data is
-typedef void (* midi_sysex_func_t)(MidiDevice * device, uint16_t start_byte, uint8_t data_length, uint8_t *data);
+// the start byte tells you how far into the sysex message you are, the data_length tells you how many bytes data is
+typedef void (*midi_sysex_func_t)(MidiDevice *device, uint16_t start_byte, uint8_t data_length, uint8_t *data);
 
 #ifdef __cplusplus
 }
-#endif 
+#endif
 
 #endif
index d4de6caa7dcac4b50b706106b34492f06a7f1b56..6f6aced7253006ae12d0482f95017861483f19e3 100644 (file)
@@ -5,7 +5,7 @@
 #include "usb_descriptor.h"
 #include "process_midi.h"
 #if API_SYSEX_ENABLE
-#include "api.h"
+#    include "api.h"
 #endif
 
 /*******************************************************************************
@@ -23,162 +23,154 @@ MidiDevice midi_device;
 #define SYS_COMMON_2 0x20
 #define SYS_COMMON_3 0x30
 
-static void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
-  MIDI_EventPacket_t event;
-  event.Data1 = byte0;
-  event.Data2 = byte1;
-  event.Data3 = byte2;
-
-  uint8_t cable = 0;
-
-  //if the length is undefined we assume it is a SYSEX message
-  if (midi_packet_length(byte0) == UNDEFINED) {
-    switch(cnt) {
-      case 3:
-        if (byte2 == SYSEX_END)
-          event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_3);
-        else
-          event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
-        break;
-      case 2:
-        if (byte1 == SYSEX_END)
-          event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_2);
-        else
-          event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
-        break;
-      case 1:
-        if (byte0 == SYSEX_END)
-          event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_1);
-        else
-          event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
-        break;
-      default:
-        return; //invalid cnt
+static void usb_send_func(MidiDevice* device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
+    MIDI_EventPacket_t event;
+    event.Data1 = byte0;
+    event.Data2 = byte1;
+    event.Data3 = byte2;
+
+    uint8_t cable = 0;
+
+    // if the length is undefined we assume it is a SYSEX message
+    if (midi_packet_length(byte0) == UNDEFINED) {
+        switch (cnt) {
+            case 3:
+                if (byte2 == SYSEX_END)
+                    event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_3);
+                else
+                    event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
+                break;
+            case 2:
+                if (byte1 == SYSEX_END)
+                    event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_2);
+                else
+                    event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
+                break;
+            case 1:
+                if (byte0 == SYSEX_END)
+                    event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_1);
+                else
+                    event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
+                break;
+            default:
+                return;  // invalid cnt
+        }
+    } else {
+        // deal with 'system common' messages
+        // TODO are there any more?
+        switch (byte0 & 0xF0) {
+            case MIDI_SONGPOSITION:
+                event.Event = MIDI_EVENT(cable, SYS_COMMON_3);
+                break;
+            case MIDI_SONGSELECT:
+            case MIDI_TC_QUARTERFRAME:
+                event.Event = MIDI_EVENT(cable, SYS_COMMON_2);
+                break;
+            default:
+                event.Event = MIDI_EVENT(cable, byte0);
+                break;
+        }
     }
-  } else {
-    //deal with 'system common' messages
-    //TODO are there any more?
-    switch(byte0 & 0xF0){
-      case MIDI_SONGPOSITION:
-        event.Event = MIDI_EVENT(cable, SYS_COMMON_3);
-        break;
-      case MIDI_SONGSELECT:
-      case MIDI_TC_QUARTERFRAME:
-        event.Event = MIDI_EVENT(cable, SYS_COMMON_2);
-        break;
-      default:
-        event.Event = MIDI_EVENT(cable, byte0);
-        break;
-    }
-  }
 
-  send_midi_packet(&event);
+    send_midi_packet(&event);
 }
 
-static void usb_get_midi(MidiDevice * device) {
-  MIDI_EventPacket_t event;
-  while (recv_midi_packet(&event)) {
-
-    midi_packet_length_t length = midi_packet_length(event.Data1);
-    uint8_t input[3];
-    input[0] = event.Data1;
-    input[1] = event.Data2;
-    input[2] = event.Data3;
-    if (length == UNDEFINED) {
-      //sysex
-      if (event.Event == MIDI_EVENT(0, SYSEX_START_OR_CONT) || event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_3)) {
-        length = 3;
-      } else if (event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_2)) {
-        length = 2;
-      } else if(event.Event ==  MIDI_EVENT(0, SYSEX_ENDS_IN_1)) {
-        length = 1;
-      } else {
-        //XXX what to do?
-      }
+static void usb_get_midi(MidiDevice* device) {
+    MIDI_EventPacket_t event;
+    while (recv_midi_packet(&event)) {
+        midi_packet_length_t length = midi_packet_length(event.Data1);
+        uint8_t              input[3];
+        input[0] = event.Data1;
+        input[1] = event.Data2;
+        input[2] = event.Data3;
+        if (length == UNDEFINED) {
+            // sysex
+            if (event.Event == MIDI_EVENT(0, SYSEX_START_OR_CONT) || event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_3)) {
+                length = 3;
+            } else if (event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_2)) {
+                length = 2;
+            } else if (event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_1)) {
+                length = 1;
+            } else {
+                // XXX what to do?
+            }
+        }
+
+        // pass the data to the device input function
+        if (length != UNDEFINED) midi_device_input(device, length, input);
     }
-
-    //pass the data to the device input function
-    if (length != UNDEFINED)
-      midi_device_input(device, length, input);
-  }
 }
 
-static void fallthrough_callback(MidiDevice * device,
-    uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2){
-
+static void fallthrough_callback(MidiDevice* device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
 #ifdef AUDIO_ENABLE
-  if (cnt == 3) {
-    switch (byte0 & 0xF0) {
-        case MIDI_NOTEON:
-            play_note(((double)261.6)*pow(2.0, -4.0)*pow(2.0,(byte1 & 0x7F)/12.0), (byte2 & 0x7F) / 8);
-            break;
-        case MIDI_NOTEOFF:
-            stop_note(((double)261.6)*pow(2.0, -4.0)*pow(2.0,(byte1 & 0x7F)/12.0));
-            break;
+    if (cnt == 3) {
+        switch (byte0 & 0xF0) {
+            case MIDI_NOTEON:
+                play_note(((double)261.6) * pow(2.0, -4.0) * pow(2.0, (byte1 & 0x7F) / 12.0), (byte2 & 0x7F) / 8);
+                break;
+            case MIDI_NOTEOFF:
+                stop_note(((double)261.6) * pow(2.0, -4.0) * pow(2.0, (byte1 & 0x7F) / 12.0));
+                break;
+        }
+    }
+    if (byte0 == MIDI_STOP) {
+        stop_all_notes();
     }
-  }
-  if (byte0 == MIDI_STOP) {
-    stop_all_notes();
-  }
 #endif
 }
 
-
-static void cc_callback(MidiDevice * device,
-    uint8_t chan, uint8_t num, uint8_t val) {
-  //sending it back on the next channel
-  // midi_send_cc(device, (chan + 1) % 16, num, val);
+static void cc_callback(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t val) {
+    // sending it back on the next channel
+    // midi_send_cc(device, (chan + 1) % 16, num, val);
 }
 
 #ifdef API_SYSEX_ENABLE
 uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0};
 
-static void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) {
-  // SEND_STRING("\n");
-  // send_word(start);
-  // SEND_STRING(": ");
-  // Don't store the header
-  int16_t pos = start - 4;
-  for (uint8_t place = 0; place < length; place++) {
-      // send_byte(*data);
-      if (pos >= 0) {
-          if (*data == 0xF7) {
-              // SEND_STRING("\nRD: ");
-              // for (uint8_t i = 0; i < start + place + 1; i++){
-              //     send_byte(midi_buffer[i]);
-              // SEND_STRING(" ");
-              // }
-              const unsigned decoded_length = sysex_decoded_length(pos);
-              uint8_t decoded[API_SYSEX_MAX_SIZE];
-              sysex_decode(decoded, midi_buffer, pos);
-              process_api(decoded_length, decoded);
-              return;
-          }
-          else if (pos >= MIDI_SYSEX_BUFFER) {
-              return;
-          }
-          midi_buffer[pos] = *data;
-      }
-      // SEND_STRING(" ");
-      data++;
-      pos++;
-  }
+static void sysex_callback(MidiDevice* device, uint16_t start, uint8_t length, uint8_t* data) {
+    // SEND_STRING("\n");
+    // send_word(start);
+    // SEND_STRING(": ");
+    // Don't store the header
+    int16_t pos = start - 4;
+    for (uint8_t place = 0; place < length; place++) {
+        // send_byte(*data);
+        if (pos >= 0) {
+            if (*data == 0xF7) {
+                // SEND_STRING("\nRD: ");
+                // for (uint8_t i = 0; i < start + place + 1; i++){
+                //     send_byte(midi_buffer[i]);
+                // SEND_STRING(" ");
+                // }
+                const unsigned decoded_length = sysex_decoded_length(pos);
+                uint8_t        decoded[API_SYSEX_MAX_SIZE];
+                sysex_decode(decoded, midi_buffer, pos);
+                process_api(decoded_length, decoded);
+                return;
+            } else if (pos >= MIDI_SYSEX_BUFFER) {
+                return;
+            }
+            midi_buffer[pos] = *data;
+        }
+        // SEND_STRING(" ");
+        data++;
+        pos++;
+    }
 }
 #endif
 
 void midi_init(void);
 
-void setup_midi(void)
-{
+void setup_midi(void) {
 #ifdef MIDI_ADVANCED
-       midi_init();
+    midi_init();
 #endif
-       midi_device_init(&midi_device);
-  midi_device_set_send_func(&midi_device, usb_send_func);
-  midi_device_set_pre_input_process_func(&midi_device, usb_get_midi);
-  midi_register_fallthrough_callback(&midi_device, fallthrough_callback);
-  midi_register_cc_callback(&midi_device, cc_callback);
+    midi_device_init(&midi_device);
+    midi_device_set_send_func(&midi_device, usb_send_func);
+    midi_device_set_pre_input_process_func(&midi_device, usb_get_midi);
+    midi_register_fallthrough_callback(&midi_device, fallthrough_callback);
+    midi_register_cc_callback(&midi_device, cc_callback);
 #ifdef API_SYSEX_ENABLE
-  midi_register_sysex_callback(&midi_device, sysex_callback);
+    midi_register_sysex_callback(&midi_device, sysex_callback);
 #endif
 }
index 7282a19d408a12366b44e06820efe174d91fdc42..0a348d5fde6426ac779c9caf1678d0e9b8826186 100644 (file)
@@ -1,9 +1,9 @@
 #pragma once
 
 #ifdef MIDI_ENABLE
-  #include "midi.h"
-  extern MidiDevice midi_device;
-  void setup_midi(void);
-  void send_midi_packet(MIDI_EventPacket_t* event);
-  bool recv_midi_packet(MIDI_EventPacket_t* const event);
+#    include "midi.h"
+extern MidiDevice midi_device;
+void              setup_midi(void);
+void              send_midi_packet(MIDI_EventPacket_t* event);
+bool              recv_midi_packet(MIDI_EventPacket_t* const event);
 #endif
old mode 100755 (executable)
new mode 100644 (file)
index 7563a3e..84bca72
@@ -1,99 +1,97 @@
-//midi for embedded chips,
-//Copyright 2010 Alex Norman
+// midi for embedded chips,
+// Copyright 2010 Alex Norman
 //
-//This file is part of avr-midi.
+// This file is part of avr-midi.
 //
-//avr-midi is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-midi is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-midi is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-midi is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "sysex_tools.h"
 
-uint16_t sysex_encoded_length(uint16_t decoded_length){
-   uint8_t remainder = decoded_length % 7;
-   if (remainder)
-      return (decoded_length / 7) * 8 + remainder + 1;
-   else
-      return (decoded_length / 7) * 8;
+uint16_t sysex_encoded_length(uint16_t decoded_length) {
+    uint8_t remainder = decoded_length % 7;
+    if (remainder)
+        return (decoded_length / 7) * 8 + remainder + 1;
+    else
+        return (decoded_length / 7) * 8;
 }
 
-uint16_t sysex_decoded_length(uint16_t encoded_length){
-   uint8_t remainder = encoded_length % 8;
-   if (remainder)
-      return (encoded_length / 8) * 7 + remainder - 1;
-   else
-      return (encoded_length / 8) * 7;
+uint16_t sysex_decoded_length(uint16_t encoded_length) {
+    uint8_t remainder = encoded_length % 8;
+    if (remainder)
+        return (encoded_length / 8) * 7 + remainder - 1;
+    else
+        return (encoded_length / 8) * 7;
 }
 
-uint16_t sysex_encode(uint8_t *encoded, const uint8_t *source, const uint16_t length){
-   uint16_t encoded_full = length / 7; //number of full 8 byte sections from 7 bytes of input
-   uint16_t i,j;
+uint16_t sysex_encode(uint8_t *encoded, const uint8_t *source, const uint16_t length) {
+    uint16_t encoded_full = length / 7;  // number of full 8 byte sections from 7 bytes of input
+    uint16_t i, j;
 
-   //fill out the fully encoded sections
-   for(i = 0; i < encoded_full; i++) {
-      uint16_t encoded_msb_idx = i * 8;
-      uint16_t input_start_idx = i * 7;
-      encoded[encoded_msb_idx] = 0;
-      for(j = 0; j < 7; j++){
-         uint8_t current = source[input_start_idx + j];
-         encoded[encoded_msb_idx] |= (0x80 & current) >> (1 + j);
-         encoded[encoded_msb_idx + 1 + j] = 0x7F & current;
-      }
-   }
+    // fill out the fully encoded sections
+    for (i = 0; i < encoded_full; i++) {
+        uint16_t encoded_msb_idx = i * 8;
+        uint16_t input_start_idx = i * 7;
+        encoded[encoded_msb_idx] = 0;
+        for (j = 0; j < 7; j++) {
+            uint8_t current = source[input_start_idx + j];
+            encoded[encoded_msb_idx] |= (0x80 & current) >> (1 + j);
+            encoded[encoded_msb_idx + 1 + j] = 0x7F & current;
+        }
+    }
 
-   //fill out the rest if there is any more
-   uint8_t remainder = length % 7;
-   if (remainder) {
-      uint16_t encoded_msb_idx = encoded_full * 8;
-      uint16_t input_start_idx = encoded_full * 7;
-      encoded[encoded_msb_idx] = 0;
-      for(j = 0; j < remainder; j++){
-         uint8_t current = source[input_start_idx + j];
-         encoded[encoded_msb_idx] |= (0x80 & current) >> (1 + j);
-         encoded[encoded_msb_idx + 1 + j] = 0x7F & current;
-      }
-      return encoded_msb_idx + remainder + 1;
-   } else {
-      return encoded_full * 8;
-   }
+    // fill out the rest if there is any more
+    uint8_t remainder = length % 7;
+    if (remainder) {
+        uint16_t encoded_msb_idx = encoded_full * 8;
+        uint16_t input_start_idx = encoded_full * 7;
+        encoded[encoded_msb_idx] = 0;
+        for (j = 0; j < remainder; j++) {
+            uint8_t current = source[input_start_idx + j];
+            encoded[encoded_msb_idx] |= (0x80 & current) >> (1 + j);
+            encoded[encoded_msb_idx + 1 + j] = 0x7F & current;
+        }
+        return encoded_msb_idx + remainder + 1;
+    } else {
+        return encoded_full * 8;
+    }
 }
 
-uint16_t sysex_decode(uint8_t *decoded, const uint8_t *source, const uint16_t length){
-   uint16_t decoded_full = length / 8;
-   uint16_t i,j;
+uint16_t sysex_decode(uint8_t *decoded, const uint8_t *source, const uint16_t length) {
+    uint16_t decoded_full = length / 8;
+    uint16_t i, j;
 
-   if (length < 2)
-      return 0;
+    if (length < 2) return 0;
 
-   //fill out the fully encoded sections
-   for(i = 0; i < decoded_full; i++) {
-      uint16_t encoded_msb_idx = i * 8;
-      uint16_t output_start_index = i * 7;
-      for(j = 0; j < 7; j++){
-         decoded[output_start_index + j] = 0x7F & source[encoded_msb_idx + j + 1];
-         decoded[output_start_index + j] |= (0x80 & (source[encoded_msb_idx] << (1 + j)));
-      }
-   }
-   uint8_t remainder = length % 8;
-   if (remainder) {
-      uint16_t encoded_msb_idx = decoded_full * 8;
-      uint16_t output_start_index = decoded_full * 7;
-      for(j = 0; j < (remainder - 1); j++) {
-         decoded[output_start_index + j] = 0x7F & source[encoded_msb_idx + j + 1];
-         decoded[output_start_index + j] |= (0x80 & (source[encoded_msb_idx] << (1 + j)));
-      }
-      return decoded_full * 7 + remainder - 1;
-   } else {
-      return decoded_full * 7;
-   }
+    // fill out the fully encoded sections
+    for (i = 0; i < decoded_full; i++) {
+        uint16_t encoded_msb_idx    = i * 8;
+        uint16_t output_start_index = i * 7;
+        for (j = 0; j < 7; j++) {
+            decoded[output_start_index + j] = 0x7F & source[encoded_msb_idx + j + 1];
+            decoded[output_start_index + j] |= (0x80 & (source[encoded_msb_idx] << (1 + j)));
+        }
+    }
+    uint8_t remainder = length % 8;
+    if (remainder) {
+        uint16_t encoded_msb_idx    = decoded_full * 8;
+        uint16_t output_start_index = decoded_full * 7;
+        for (j = 0; j < (remainder - 1); j++) {
+            decoded[output_start_index + j] = 0x7F & source[encoded_msb_idx + j + 1];
+            decoded[output_start_index + j] |= (0x80 & (source[encoded_msb_idx] << (1 + j)));
+        }
+        return decoded_full * 7 + remainder - 1;
+    } else {
+        return decoded_full * 7;
+    }
 }
-
old mode 100755 (executable)
new mode 100644 (file)
index 3654d01..454a92e
@@ -1,27 +1,27 @@
-//midi for embedded chips,
-//Copyright 2010 Alex Norman
+// midi for embedded chips,
+// Copyright 2010 Alex Norman
 //
-//This file is part of avr-midi.
+// This file is part of avr-midi.
 //
-//avr-midi is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
+// avr-midi is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
 //(at your option) any later version.
 //
-//avr-midi is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//GNU General Public License for more details.
+// avr-midi is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 //
-//You should have received a copy of the GNU General Public License
-//along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
+// You should have received a copy of the GNU General Public License
+// along with avr-midi.  If not, see <http://www.gnu.org/licenses/>.
 
 #ifndef SYSEX_TOOLS_H
 #define SYSEX_TOOLS_H
 
 #ifdef __cplusplus
 extern "C" {
-#endif 
+#endif
 
 #include <inttypes.h>
 
@@ -31,7 +31,7 @@ extern "C" {
  *
  * These functions are for converting data to and from a "midi-safe" format,
  * which can be use to send data with sysex messages.  Sysex messages may only
- * contain data where the to bit is not set. 
+ * contain data where the to bit is not set.
  *
  * An "encoded" midi message is one that contains all of the data from its
  * original state, but does not have any of the top bits set.
@@ -70,7 +70,7 @@ uint16_t sysex_decoded_length(uint16_t encoded_length);
  * @param encoded The output data buffer, must be at least sysex_encoded_length(length) bytes long.
  * @param source The input buffer of data to be encoded.
  * @param length The number of bytes from the input buffer to encode.
- * 
+ *
  * @return number of bytes encoded.
  */
 uint16_t sysex_encode(uint8_t *encoded, const uint8_t *source, uint16_t length);
@@ -81,7 +81,7 @@ uint16_t sysex_encode(uint8_t *encoded, const uint8_t *source, uint16_t length);
  * @param decoded The output data buffer, must be at least sysex_decoded_length(length) bytes long.
  * @param source The input buffer of data to be decoded.
  * @param length The number of bytes from the input buffer to decode.
- * 
+ *
  * @return number of bytes decoded.
  */
 uint16_t sysex_decode(uint8_t *decoded, const uint8_t *source, uint16_t length);
@@ -90,6 +90,6 @@ uint16_t sysex_decode(uint8_t *decoded, const uint8_t *source, uint16_t length);
 
 #ifdef __cplusplus
 }
-#endif 
+#endif
 
 #endif
index 00755a5e2ea85da98cebea0b5e9f24ff1a3c551a..4463e8dd4256814624173266b28cfb54c9d6631c 100644 (file)
@@ -40,41 +40,34 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <avr/interrupt.h>
 #include "news.h"
 
-
-void news_init(void)
-{
-    NEWS_KBD_RX_INIT();
-}
+void news_init(void) { NEWS_KBD_RX_INIT(); }
 
 // RX ring buffer
-#define RBUF_SIZE   8
+#define RBUF_SIZE 8
 static uint8_t rbuf[RBUF_SIZE];
 static uint8_t rbuf_head = 0;
 static uint8_t rbuf_tail = 0;
 
-uint8_t news_recv(void)
-{
+uint8_t news_recv(void) {
     uint8_t data = 0;
     if (rbuf_head == rbuf_tail) {
         return 0;
     }
 
-    data = rbuf[rbuf_tail];
+    data      = rbuf[rbuf_tail];
     rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
     return data;
 }
 
 // USART RX complete interrupt
-ISR(NEWS_KBD_RX_VECT)
-{
+ISR(NEWS_KBD_RX_VECT) {
     uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
     if (next != rbuf_tail) {
         rbuf[rbuf_head] = NEWS_KBD_RX_DATA;
-        rbuf_head = next;
+        rbuf_head       = next;
     }
 }
 
-
 /*
 SONY NEWS Keyboard Protocol
 ===========================
index 35e09c4d20e1aad44f47f76ad2ea505af7079fb6..d0c4bc6a4dceb88f4f0d2ac41ffa582c31345d99 100644 (file)
@@ -41,9 +41,8 @@ POSSIBILITY OF SUCH DAMAGE.
  * Primitive PS/2 Library for AVR
  */
 
-
 /* host role */
-void news_init(void);
+void    news_init(void);
 uint8_t news_recv(void);
 
 /* device role */
index fa3034b3fe0351f71aeaeadbebbfd5da16e19595..6f118e6172986f42dff81a0761871fc3e7f94f79 100644 (file)
@@ -1,7 +1,7 @@
 /*
 
 NeXT non-ADB Keyboard Protocol
+
 Copyright 2013, Benjamin Gould (bgould@github.com)
 
 Based on:
@@ -53,10 +53,10 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "next_kbd.h"
 #include "debug.h"
 
-static inline void out_lo(void);
-static inline void out_hi(void);
-static inline void query(void);
-static inline void reset(void);
+static inline void     out_lo(void);
+static inline void     out_hi(void);
+static inline void     query(void);
+static inline void     reset(void);
 static inline uint32_t response(void);
 
 /* The keyboard sends signal with 50us pulse width on OUT line
@@ -65,53 +65,65 @@ static inline uint32_t response(void);
  * but it works well with 51us(+1us) on TMK converter(ATMeaga32u2) at least.
  * TODO: test on Teensy and Pro Micro configuration
  */
-#define out_hi_delay(intervals)  do { out_hi(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
-#define out_lo_delay(intervals)  do { out_lo(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
-#define query_delay(intervals)   do { query();  _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
-#define reset_delay(intervals)   do { reset();  _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
-
-void next_kbd_init(void)
-{
+#define out_hi_delay(intervals)                       \
+    do {                                              \
+        out_hi();                                     \
+        _delay_us((NEXT_KBD_TIMING + 1) * intervals); \
+    } while (0);
+#define out_lo_delay(intervals)                       \
+    do {                                              \
+        out_lo();                                     \
+        _delay_us((NEXT_KBD_TIMING + 1) * intervals); \
+    } while (0);
+#define query_delay(intervals)                        \
+    do {                                              \
+        query();                                      \
+        _delay_us((NEXT_KBD_TIMING + 1) * intervals); \
+    } while (0);
+#define reset_delay(intervals)                        \
+    do {                                              \
+        reset();                                      \
+        _delay_us((NEXT_KBD_TIMING + 1) * intervals); \
+    } while (0);
+
+void next_kbd_init(void) {
     out_hi();
-    NEXT_KBD_IN_DDR   &= ~(1<<NEXT_KBD_IN_BIT);   // KBD_IN  to input
-    NEXT_KBD_IN_PORT  |=  (1<<NEXT_KBD_IN_BIT);   // KBD_IN  pull up
-    
+    NEXT_KBD_IN_DDR &= ~(1 << NEXT_KBD_IN_BIT);  // KBD_IN  to input
+    NEXT_KBD_IN_PORT |= (1 << NEXT_KBD_IN_BIT);  // KBD_IN  pull up
+
     query_delay(5);
     reset_delay(8);
-    
+
     query_delay(5);
     reset_delay(8);
 }
 
-void next_kbd_set_leds(bool left, bool right)
-{
+void next_kbd_set_leds(bool left, bool right) {
     cli();
     out_lo_delay(9);
-    
+
     out_hi_delay(3);
     out_lo_delay(1);
-    
+
     if (left) {
         out_hi_delay(1);
     } else {
         out_lo_delay(1);
     }
-    
+
     if (right) {
         out_hi_delay(1);
     } else {
         out_lo_delay(1);
     }
-    
+
     out_lo_delay(7);
     out_hi();
     sei();
 }
 
-#define NEXT_KBD_READ (NEXT_KBD_IN_PIN&(1<<NEXT_KBD_IN_BIT))
-uint32_t next_kbd_recv(void)
-{
-    
+#define NEXT_KBD_READ (NEXT_KBD_IN_PIN & (1 << NEXT_KBD_IN_BIT))
+uint32_t next_kbd_recv(void) {
     // First check to make sure that the keyboard is actually connected;
     // if not, just return
     // TODO: reflect the status of the keyboard in a return code
@@ -122,22 +134,23 @@ uint32_t next_kbd_recv(void)
 
     query();
     uint32_t resp = response();
-    
+
     return resp;
 }
 
-static inline uint32_t response(void)
-{
+static inline uint32_t response(void) {
     cli();
-    
+
     // try a 5ms read; this should be called after the query method has
     // been run so if a key is pressed we should get a response within
     // 5ms; if not then send a reset and exit
-    uint8_t     i  = 0;
-    uint32_t data  = 0;
+    uint8_t  i             = 0;
+    uint32_t data          = 0;
     uint16_t reset_timeout = 50000;
-    while (NEXT_KBD_READ && reset_timeout)  {
-        asm(""); _delay_us(1); reset_timeout--;
+    while (NEXT_KBD_READ && reset_timeout) {
+        asm("");
+        _delay_us(1);
+        reset_timeout--;
     }
     if (!reset_timeout) {
         reset();
@@ -145,64 +158,58 @@ static inline uint32_t response(void)
         return 0;
     }
     _delay_us(NEXT_KBD_TIMING / 2);
-    for (; i < 22; i++)
-    {
-        if (NEXT_KBD_READ)
-        {
-            data |= ((uint32_t) 1 << i);
+    for (; i < 22; i++) {
+        if (NEXT_KBD_READ) {
+            data |= ((uint32_t)1 << i);
             /* Note:
              * My testing with the ATmega32u4 showed that there might
              * something wrong with the timing here; by the end of the
              * second data byte some of the modifiers can get bumped out
              * to the next bit over if we just cycle through the data
-             * based on the expected interval.  There is a bit (i = 10) 
-             * in the middle of the data that is always on followed by 
-             * one that is always off - so we'll use that to reset our 
+             * based on the expected interval.  There is a bit (i = 10)
+             * in the middle of the data that is always on followed by
+             * one that is always off - so we'll use that to reset our
              * timing in case we've gotten ahead of the keyboard;
              */
-            if (i == 10)
-            {
+            if (i == 10) {
                 i++;
-                while (NEXT_KBD_READ) ;
+                while (NEXT_KBD_READ)
+                    ;
                 _delay_us(NEXT_KBD_TIMING / 2);
             }
         } else {
             /* redundant - but I don't want to remove if it might screw
              * up the timing
              */
-            data |= ((uint32_t) 0 << i);
+            data |= ((uint32_t)0 << i);
         }
         _delay_us(NEXT_KBD_TIMING);
     }
-    
+
     sei();
-    
+
     return data;
 }
 
-static inline void out_lo(void)
-{
-    NEXT_KBD_OUT_PORT &= ~(1<<NEXT_KBD_OUT_BIT);
-    NEXT_KBD_OUT_DDR  |=  (1<<NEXT_KBD_OUT_BIT);
+static inline void out_lo(void) {
+    NEXT_KBD_OUT_PORT &= ~(1 << NEXT_KBD_OUT_BIT);
+    NEXT_KBD_OUT_DDR |= (1 << NEXT_KBD_OUT_BIT);
 }
 
-static inline void out_hi(void)
-{
+static inline void out_hi(void) {
     /* input with pull up */
-    NEXT_KBD_OUT_DDR  &= ~(1<<NEXT_KBD_OUT_BIT);
-    NEXT_KBD_OUT_PORT |=  (1<<NEXT_KBD_OUT_BIT);
+    NEXT_KBD_OUT_DDR &= ~(1 << NEXT_KBD_OUT_BIT);
+    NEXT_KBD_OUT_PORT |= (1 << NEXT_KBD_OUT_BIT);
 }
 
-static inline void query(void)
-{
+static inline void query(void) {
     out_lo_delay(5);
     out_hi_delay(1);
     out_lo_delay(3);
     out_hi();
 }
 
-static inline void reset(void)
-{
+static inline void reset(void) {
     out_lo_delay(1);
     out_hi_delay(4);
     out_lo_delay(1);
index 6d455d4fab46897adfe9e25118e6d123fce99ce0..bff7a474d330869b45352595b8c09e81a2318682 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NeXT non-ADB Keyboard Protocol
+
 Copyright 2013, Benjamin Gould (bgould@github.com)
 
 Based on:
@@ -48,16 +48,16 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <stdbool.h>
 
 #ifndef NEXT_KBD_H
-#define NEXT_KBD_H
+#    define NEXT_KBD_H
 
-#define NEXT_KBD_KMBUS_IDLE 0x300600
-#define NEXT_KBD_TIMING     50
+#    define NEXT_KBD_KMBUS_IDLE 0x300600
+#    define NEXT_KBD_TIMING 50
 
 extern uint8_t next_kbd_error;
 
 /* host role */
-void next_kbd_init(void);
-void next_kbd_set_leds(bool left, bool right);
+void     next_kbd_init(void);
+void     next_kbd_set_leds(bool left, bool right);
 uint32_t next_kbd_recv(void);
 
 #endif
index 45eb17d4cddc625a8abd1bd8246eee340b093b3f..d16051c5f81697db431e8c668fe49d23b0d3a02a 100644 (file)
@@ -1,17 +1,17 @@
 /* Keyboard example with debug channel, for Teensy USB Development Board
  * http://www.pjrc.com/teensy/usb_keyboard.html
  * Copyright (c) 2008 PJRC.COM, LLC
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 #include "host.h"
 #include "pjrc.h"
 
+#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
 
-#define CPU_PRESCALE(n)    (CLKPR = 0x80, CLKPR = (n))
-
-
-int main(void)
-{
+int main(void) {
     // set for 16 MHz clock
     CPU_PRESCALE(0);
 
@@ -52,7 +49,8 @@ int main(void)
     // If the Teensy is powered without a PC connected to the USB port,
     // this will wait forever.
     usb_init();
-    while (!usb_configured()) /* wait */ ;
+    while (!usb_configured()) /* wait */
+        ;
 
     print_set_sendchar(sendchar);
 
@@ -69,6 +67,6 @@ int main(void)
             }
         }
 
-        keyboard_task(); 
+        keyboard_task();
     }
 }
index 0562a12ffab94c96fb0c60173dd89d8759b7f035..60932f59e8a96e4f1521a68d539878dc6cdf06f0 100644 (file)
@@ -22,54 +22,36 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "host_driver.h"
 #include "pjrc.h"
 
-
 /*------------------------------------------------------------------*
  * Host driver
  *------------------------------------------------------------------*/
 static uint8_t keyboard_leds(void);
-static void send_keyboard(report_keyboard_t *report);
-static void send_mouse(report_mouse_t *report);
-static void send_system(uint16_t data);
-static void send_consumer(uint16_t data);
+static void    send_keyboard(report_keyboard_t *report);
+static void    send_mouse(report_mouse_t *report);
+static void    send_system(uint16_t data);
+static void    send_consumer(uint16_t data);
 
-static host_driver_t driver = {
-        keyboard_leds,
-        send_keyboard,
-        send_mouse,
-        send_system,
-        send_consumer
-};
+static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
 
-host_driver_t *pjrc_driver(void)
-{
-    return &driver;
-}
+host_driver_t *pjrc_driver(void) { return &driver; }
 
-static uint8_t keyboard_leds(void) {
-    return usb_keyboard_leds;
-}
+static uint8_t keyboard_leds(void) { return usb_keyboard_leds; }
 
-static void send_keyboard(report_keyboard_t *report)
-{
-    usb_keyboard_send_report(report);
-}
+static void send_keyboard(report_keyboard_t *report) { usb_keyboard_send_report(report); }
 
-static void send_mouse(report_mouse_t *report)
-{
+static void send_mouse(report_mouse_t *report) {
 #ifdef MOUSE_ENABLE
     usb_mouse_send(report->x, report->y, report->v, report->h, report->buttons);
 #endif
 }
 
-static void send_system(uint16_t data)
-{
+static void send_system(uint16_t data) {
 #ifdef EXTRAKEY_ENABLE
     usb_extra_system_send(data);
 #endif
 }
 
-static void send_consumer(uint16_t data)
-{
+static void send_consumer(uint16_t data) {
 #ifdef EXTRAKEY_ENABLE
     usb_extra_consumer_send(data);
 #endif
index 06e79626fc4800646241a31f7fa0a00f0d751dba..08a1ede1866263f98bd78e0538bfbddee27a1aae 100644 (file)
@@ -20,7 +20,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "host_driver.h"
 
-
 host_driver_t *pjrc_driver(void);
 
 #endif
index 09efbe076268beb5b09ca941292049dd348a98c2..22fbcfdcd4785b7b49f7fabe80763dbaca82d359 100644 (file)
 #include "print.h"
 #include "util.h"
 #ifdef SLEEP_LED_ENABLE
-#include "sleep_led.h"
+#    include "sleep_led.h"
 #endif
 #include "suspend.h"
 #include "action.h"
 #include "action_util.h"
 
 #ifdef NKRO_ENABLE
-  #include "keycode_config.h"
+#    include "keycode_config.h"
 
-  extern keymap_config_t keymap_config;
+extern keymap_config_t keymap_config;
 #endif
 
-
 /**************************************************************************
  *
  *  Configurable Options
 
 // You can change these to give your code its own name.
 #ifndef MANUFACTURER
-#   define STR_MANUFACTURER    L"t.m.k."
+#    define STR_MANUFACTURER L"t.m.k."
 #else
-#   define STR_MANUFACTURER    LSTR(MANUFACTURER)
+#    define STR_MANUFACTURER LSTR(MANUFACTURER)
 #endif
 #ifndef PRODUCT
-#   define STR_PRODUCT         L"t.m.k. keyboard"
+#    define STR_PRODUCT L"t.m.k. keyboard"
 #else
-#   define STR_PRODUCT         LSTR(PRODUCT)
+#    define STR_PRODUCT LSTR(PRODUCT)
 #endif
 
-
 // Mac OS-X and Linux automatically load the correct drivers.  On
 // Windows, even though the driver is supplied by Microsoft, an
 // INF file is needed to load the driver.  These numbers need to
 // match the INF file.
 #ifndef VENDOR_ID
-#   define VENDOR_ID           0xFEED
+#    define VENDOR_ID 0xFEED
 #endif
 
 #ifndef PRODUCT_ID
-#   define PRODUCT_ID          0xBABE
+#    define PRODUCT_ID 0xBABE
 #endif
 
 #ifndef DEVICE_VER
-#   define DEVICE_VER          0x0100
+#    define DEVICE_VER 0x0100
 #endif
 
-
 // USB devices are supposed to implment a halt feature, which is
 // rarely (if ever) used.  If you comment this line out, the halt
 // code will be removed, saving 102 bytes of space (gcc 4.3.0).
 // operating systems.
 #define SUPPORT_ENDPOINT_HALT
 
-
-
 /**************************************************************************
  *
  *  Endpoint Buffer Configuration
  *
  **************************************************************************/
 
-#define ENDPOINT0_SIZE         32
+#define ENDPOINT0_SIZE 32
 
 bool remote_wakeup = false;
-bool suspend = false;
+bool suspend       = false;
 
 // 0:control endpoint is enabled automatically by controller.
 static const uint8_t PROGMEM endpoint_config_table[] = {
-       // enable, UECFG0X(type, direction), UECFG1X(size, bank, allocation)
-       1, EP_TYPE_INTERRUPT_IN,  EP_SIZE(KBD_SIZE)      | KBD_BUFFER,      // 1
+    // enable, UECFG0X(type, direction), UECFG1X(size, bank, allocation)
+    1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD_SIZE) | KBD_BUFFER,  // 1
 #ifdef MOUSE_ENABLE
-       1, EP_TYPE_INTERRUPT_IN,  EP_SIZE(MOUSE_SIZE)    | MOUSE_BUFFER,    // 2
+    1, EP_TYPE_INTERRUPT_IN, EP_SIZE(MOUSE_SIZE) | MOUSE_BUFFER,  // 2
 #else
-        0,                                                                  // 2
+    0,  // 2
 #endif
 #ifdef CONSOLE_ENABLE
-       1, EP_TYPE_INTERRUPT_IN,  EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3
+    1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER,  // 3
 #else
-        0,
+    0,
 #endif
 #ifdef EXTRAKEY_ENABLE
-       1, EP_TYPE_INTERRUPT_IN,  EP_SIZE(EXTRA_SIZE)    | EXTRA_BUFFER,    // 4
+    1, EP_TYPE_INTERRUPT_IN, EP_SIZE(EXTRA_SIZE) | EXTRA_BUFFER,  // 4
 #else
-        0,                                                                  // 4
+    0,  // 4
 #endif
 #ifdef NKRO_ENABLE
-       1, EP_TYPE_INTERRUPT_IN,  EP_SIZE(KBD2_SIZE)     | KBD2_BUFFER,     // 5
+    1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD2_SIZE) | KBD2_BUFFER,  // 5
 #else
-        0,                                                                  // 5
+    0,  // 5
 #endif
-        0,                                                                  // 6
+    0,  // 6
 };
 
-
 /**************************************************************************
  *
  *  Descriptor Data
@@ -144,93 +138,96 @@ static const uint8_t PROGMEM endpoint_config_table[] = {
 // in here should only be done by those who've read chapter 9 of the USB
 // spec and relevant portions of any USB class specifications!
 
-
 static const uint8_t PROGMEM device_descriptor[] = {
-       18,                                     // bLength
-       1,                                      // bDescriptorType
-       0x00, 0x02,                             // bcdUSB
-       0,                                      // bDeviceClass
-       0,                                      // bDeviceSubClass
-       0,                                      // bDeviceProtocol
-       ENDPOINT0_SIZE,                         // bMaxPacketSize0
-       LSB(VENDOR_ID), MSB(VENDOR_ID),         // idVendor
-       LSB(PRODUCT_ID), MSB(PRODUCT_ID),       // idProduct
-       LSB(DEVICE_VER), MSB(DEVICE_VER),       // bcdDevice
-       1,                                      // iManufacturer
-       2,                                      // iProduct
-       0,                                      // iSerialNumber
-       1                                       // bNumConfigurations
+    18,  // bLength
+    1,   // bDescriptorType
+    0x00,
+    0x02,            // bcdUSB
+    0,               // bDeviceClass
+    0,               // bDeviceSubClass
+    0,               // bDeviceProtocol
+    ENDPOINT0_SIZE,  // bMaxPacketSize0
+    LSB(VENDOR_ID),
+    MSB(VENDOR_ID),  // idVendor
+    LSB(PRODUCT_ID),
+    MSB(PRODUCT_ID),  // idProduct
+    LSB(DEVICE_VER),
+    MSB(DEVICE_VER),  // bcdDevice
+    1,                // iManufacturer
+    2,                // iProduct
+    0,                // iSerialNumber
+    1                 // bNumConfigurations
 };
 
 // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
 static const uint8_t PROGMEM keyboard_hid_report_desc[] = {
-        0x05, 0x01,          // Usage Page (Generic Desktop),
-        0x09, 0x06,          // Usage (Keyboard),
-        0xA1, 0x01,          // Collection (Application),
-        0x75, 0x01,          //   Report Size (1),
-        0x95, 0x08,          //   Report Count (8),
-        0x05, 0x07,          //   Usage Page (Key Codes),
-        0x19, 0xE0,          //   Usage Minimum (224),
-        0x29, 0xE7,          //   Usage Maximum (231),
-        0x15, 0x00,          //   Logical Minimum (0),
-        0x25, 0x01,          //   Logical Maximum (1),
-        0x81, 0x02,          //   Input (Data, Variable, Absolute), ;Modifier byte
-        0x95, 0x01,          //   Report Count (1),
-        0x75, 0x08,          //   Report Size (8),
-        0x81, 0x03,          //   Input (Constant),                 ;Reserved byte
-        0x95, 0x05,          //   Report Count (5),
-        0x75, 0x01,          //   Report Size (1),
-        0x05, 0x08,          //   Usage Page (LEDs),
-        0x19, 0x01,          //   Usage Minimum (1),
-        0x29, 0x05,          //   Usage Maximum (5),
-        0x91, 0x02,          //   Output (Data, Variable, Absolute), ;LED report
-        0x95, 0x01,          //   Report Count (1),
-        0x75, 0x03,          //   Report Size (3),
-        0x91, 0x03,          //   Output (Constant),                 ;LED report padding
-        0x95, KBD_REPORT_KEYS,    //   Report Count (),
-        0x75, 0x08,          //   Report Size (8),
-        0x15, 0x00,          //   Logical Minimum (0),
-        0x25, 0xFF,          //   Logical Maximum(255),
-        0x05, 0x07,          //   Usage Page (Key Codes),
-        0x19, 0x00,          //   Usage Minimum (0),
-        0x29, 0xFF,          //   Usage Maximum (255),
-        0x81, 0x00,          //   Input (Data, Array),
-        0xc0                 // End Collection
+    0x05, 0x01,             // Usage Page (Generic Desktop),
+    0x09, 0x06,             // Usage (Keyboard),
+    0xA1, 0x01,             // Collection (Application),
+    0x75, 0x01,             //   Report Size (1),
+    0x95, 0x08,             //   Report Count (8),
+    0x05, 0x07,             //   Usage Page (Key Codes),
+    0x19, 0xE0,             //   Usage Minimum (224),
+    0x29, 0xE7,             //   Usage Maximum (231),
+    0x15, 0x00,             //   Logical Minimum (0),
+    0x25, 0x01,             //   Logical Maximum (1),
+    0x81, 0x02,             //   Input (Data, Variable, Absolute), ;Modifier byte
+    0x95, 0x01,             //   Report Count (1),
+    0x75, 0x08,             //   Report Size (8),
+    0x81, 0x03,             //   Input (Constant),                 ;Reserved byte
+    0x95, 0x05,             //   Report Count (5),
+    0x75, 0x01,             //   Report Size (1),
+    0x05, 0x08,             //   Usage Page (LEDs),
+    0x19, 0x01,             //   Usage Minimum (1),
+    0x29, 0x05,             //   Usage Maximum (5),
+    0x91, 0x02,             //   Output (Data, Variable, Absolute), ;LED report
+    0x95, 0x01,             //   Report Count (1),
+    0x75, 0x03,             //   Report Size (3),
+    0x91, 0x03,             //   Output (Constant),                 ;LED report padding
+    0x95, KBD_REPORT_KEYS,  //   Report Count (),
+    0x75, 0x08,             //   Report Size (8),
+    0x15, 0x00,             //   Logical Minimum (0),
+    0x25, 0xFF,             //   Logical Maximum(255),
+    0x05, 0x07,             //   Usage Page (Key Codes),
+    0x19, 0x00,             //   Usage Minimum (0),
+    0x29, 0xFF,             //   Usage Maximum (255),
+    0x81, 0x00,             //   Input (Data, Array),
+    0xc0                    // End Collection
 };
 #ifdef NKRO_ENABLE
 static const uint8_t PROGMEM keyboard2_hid_report_desc[] = {
-        0x05, 0x01,                     // Usage Page (Generic Desktop),
-        0x09, 0x06,                     // Usage (Keyboard),
-        0xA1, 0x01,                     // Collection (Application),
-        // bitmap of modifiers
-        0x75, 0x01,                     //   Report Size (1),
-        0x95, 0x08,                     //   Report Count (8),
-        0x05, 0x07,                     //   Usage Page (Key Codes),
-        0x19, 0xE0,                     //   Usage Minimum (224),
-        0x29, 0xE7,                     //   Usage Maximum (231),
-        0x15, 0x00,                     //   Logical Minimum (0),
-        0x25, 0x01,                     //   Logical Maximum (1),
-        0x81, 0x02,                     //   Input (Data, Variable, Absolute), ;Modifier byte
-        // LED output report
-        0x95, 0x05,                     //   Report Count (5),
-        0x75, 0x01,                     //   Report Size (1),
-        0x05, 0x08,                     //   Usage Page (LEDs),
-        0x19, 0x01,                     //   Usage Minimum (1),
-        0x29, 0x05,                     //   Usage Maximum (5),
-        0x91, 0x02,                     //   Output (Data, Variable, Absolute),
-        0x95, 0x01,                     //   Report Count (1),
-        0x75, 0x03,                     //   Report Size (3),
-        0x91, 0x03,                     //   Output (Constant),
-        // bitmap of keys
-        0x95, KBD2_REPORT_KEYS*8,       //   Report Count (),
-        0x75, 0x01,                     //   Report Size (1),
-        0x15, 0x00,                     //   Logical Minimum (0),
-        0x25, 0x01,                     //   Logical Maximum(1),
-        0x05, 0x07,                     //   Usage Page (Key Codes),
-        0x19, 0x00,                     //   Usage Minimum (0),
-        0x29, KBD2_REPORT_KEYS*8-1,     //   Usage Maximum (),
-        0x81, 0x02,                     //   Input (Data, Variable, Absolute),
-        0xc0                            // End Collection
+    0x05, 0x01,  // Usage Page (Generic Desktop),
+    0x09, 0x06,  // Usage (Keyboard),
+    0xA1, 0x01,  // Collection (Application),
+    // bitmap of modifiers
+    0x75, 0x01,  //   Report Size (1),
+    0x95, 0x08,  //   Report Count (8),
+    0x05, 0x07,  //   Usage Page (Key Codes),
+    0x19, 0xE0,  //   Usage Minimum (224),
+    0x29, 0xE7,  //   Usage Maximum (231),
+    0x15, 0x00,  //   Logical Minimum (0),
+    0x25, 0x01,  //   Logical Maximum (1),
+    0x81, 0x02,  //   Input (Data, Variable, Absolute), ;Modifier byte
+    // LED output report
+    0x95, 0x05,  //   Report Count (5),
+    0x75, 0x01,  //   Report Size (1),
+    0x05, 0x08,  //   Usage Page (LEDs),
+    0x19, 0x01,  //   Usage Minimum (1),
+    0x29, 0x05,  //   Usage Maximum (5),
+    0x91, 0x02,  //   Output (Data, Variable, Absolute),
+    0x95, 0x01,  //   Report Count (1),
+    0x75, 0x03,  //   Report Size (3),
+    0x91, 0x03,  //   Output (Constant),
+    // bitmap of keys
+    0x95, KBD2_REPORT_KEYS * 8,      //   Report Count (),
+    0x75, 0x01,                      //   Report Size (1),
+    0x15, 0x00,                      //   Logical Minimum (0),
+    0x25, 0x01,                      //   Logical Maximum(1),
+    0x05, 0x07,                      //   Usage Page (Key Codes),
+    0x19, 0x00,                      //   Usage Minimum (0),
+    0x29, KBD2_REPORT_KEYS * 8 - 1,  //   Usage Maximum (),
+    0x81, 0x02,                      //   Input (Data, Variable, Absolute),
+    0xc0                             // End Collection
 };
 #endif
 
@@ -241,66 +238,66 @@ static const uint8_t PROGMEM keyboard2_hid_report_desc[] = {
 // http://www.microsoft.com/whdc/device/input/wheel.mspx
 static const uint8_t PROGMEM mouse_hid_report_desc[] = {
     /* mouse */
-    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
-    0x09, 0x02,                    // USAGE (Mouse)
-    0xa1, 0x01,                    // COLLECTION (Application)
-    //0x85, REPORT_ID_MOUSE,         //   REPORT_ID (1)
-    0x09, 0x01,                    //   USAGE (Pointer)
-    0xa1, 0x00,                    //   COLLECTION (Physical)
-                                   // ----------------------------  Buttons
-    0x05, 0x09,                    //     USAGE_PAGE (Button)
-    0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
-    0x29, 0x05,                    //     USAGE_MAXIMUM (Button 5)
-    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
-    0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
-    0x75, 0x01,                    //     REPORT_SIZE (1)
-    0x95, 0x05,                    //     REPORT_COUNT (5)
-    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
-    0x75, 0x03,                    //     REPORT_SIZE (3)
-    0x95, 0x01,                    //     REPORT_COUNT (1)
-    0x81, 0x03,                    //     INPUT (Cnst,Var,Abs)
-                                   // ----------------------------  X,Y position
-    0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
-    0x09, 0x30,                    //     USAGE (X)
-    0x09, 0x31,                    //     USAGE (Y)
-    0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
-    0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
-    0x75, 0x08,                    //     REPORT_SIZE (8)
-    0x95, 0x02,                    //     REPORT_COUNT (2)
-    0x81, 0x06,                    //     INPUT (Data,Var,Rel)
-                                   // ----------------------------  Vertical wheel
-    0x09, 0x38,                    //     USAGE (Wheel)
-    0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
-    0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
-    0x35, 0x00,                    //     PHYSICAL_MINIMUM (0)        - reset physical
-    0x45, 0x00,                    //     PHYSICAL_MAXIMUM (0)
-    0x75, 0x08,                    //     REPORT_SIZE (8)
-    0x95, 0x01,                    //     REPORT_COUNT (1)
-    0x81, 0x06,                    //     INPUT (Data,Var,Rel)
-                                   // ----------------------------  Horizontal wheel
-    0x05, 0x0c,                    //     USAGE_PAGE (Consumer Devices)
-    0x0a, 0x38, 0x02,              //     USAGE (AC Pan)
-    0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
-    0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
-    0x75, 0x08,                    //     REPORT_SIZE (8)
-    0x95, 0x01,                    //     REPORT_COUNT (1)
-    0x81, 0x06,                    //     INPUT (Data,Var,Rel)
-    0xc0,                          //   END_COLLECTION
-    0xc0,                          // END_COLLECTION
+    0x05, 0x01,  // USAGE_PAGE (Generic Desktop)
+    0x09, 0x02,  // USAGE (Mouse)
+    0xa1, 0x01,  // COLLECTION (Application)
+    // 0x85, REPORT_ID_MOUSE,         //   REPORT_ID (1)
+    0x09, 0x01,        //   USAGE (Pointer)
+    0xa1, 0x00,        //   COLLECTION (Physical)
+                       // ----------------------------  Buttons
+    0x05, 0x09,        //     USAGE_PAGE (Button)
+    0x19, 0x01,        //     USAGE_MINIMUM (Button 1)
+    0x29, 0x05,        //     USAGE_MAXIMUM (Button 5)
+    0x15, 0x00,        //     LOGICAL_MINIMUM (0)
+    0x25, 0x01,        //     LOGICAL_MAXIMUM (1)
+    0x75, 0x01,        //     REPORT_SIZE (1)
+    0x95, 0x05,        //     REPORT_COUNT (5)
+    0x81, 0x02,        //     INPUT (Data,Var,Abs)
+    0x75, 0x03,        //     REPORT_SIZE (3)
+    0x95, 0x01,        //     REPORT_COUNT (1)
+    0x81, 0x03,        //     INPUT (Cnst,Var,Abs)
+                       // ----------------------------  X,Y position
+    0x05, 0x01,        //     USAGE_PAGE (Generic Desktop)
+    0x09, 0x30,        //     USAGE (X)
+    0x09, 0x31,        //     USAGE (Y)
+    0x15, 0x81,        //     LOGICAL_MINIMUM (-127)
+    0x25, 0x7f,        //     LOGICAL_MAXIMUM (127)
+    0x75, 0x08,        //     REPORT_SIZE (8)
+    0x95, 0x02,        //     REPORT_COUNT (2)
+    0x81, 0x06,        //     INPUT (Data,Var,Rel)
+                       // ----------------------------  Vertical wheel
+    0x09, 0x38,        //     USAGE (Wheel)
+    0x15, 0x81,        //     LOGICAL_MINIMUM (-127)
+    0x25, 0x7f,        //     LOGICAL_MAXIMUM (127)
+    0x35, 0x00,        //     PHYSICAL_MINIMUM (0)        - reset physical
+    0x45, 0x00,        //     PHYSICAL_MAXIMUM (0)
+    0x75, 0x08,        //     REPORT_SIZE (8)
+    0x95, 0x01,        //     REPORT_COUNT (1)
+    0x81, 0x06,        //     INPUT (Data,Var,Rel)
+                       // ----------------------------  Horizontal wheel
+    0x05, 0x0c,        //     USAGE_PAGE (Consumer Devices)
+    0x0a, 0x38, 0x02,  //     USAGE (AC Pan)
+    0x15, 0x81,        //     LOGICAL_MINIMUM (-127)
+    0x25, 0x7f,        //     LOGICAL_MAXIMUM (127)
+    0x75, 0x08,        //     REPORT_SIZE (8)
+    0x95, 0x01,        //     REPORT_COUNT (1)
+    0x81, 0x06,        //     INPUT (Data,Var,Rel)
+    0xc0,              //   END_COLLECTION
+    0xc0,              // END_COLLECTION
 };
 #endif
 
 static const uint8_t PROGMEM debug_hid_report_desc[] = {
-       0x06, 0x31, 0xFF,                       // Usage Page 0xFF31 (vendor defined)
-       0x09, 0x74,                             // Usage 0x74
-       0xA1, 0x53,                             // Collection 0x53
-       0x75, 0x08,                             // report size = 8 bits
-       0x15, 0x00,                             // logical minimum = 0
-       0x26, 0xFF, 0x00,                       // logical maximum = 255
-       0x95, DEBUG_TX_SIZE,                    // report count
-       0x09, 0x75,                             // usage
-       0x81, 0x02,                             // Input (array)
-       0xC0                                    // end collection
+    0x06, 0x31,          0xFF,  // Usage Page 0xFF31 (vendor defined)
+    0x09, 0x74,                 // Usage 0x74
+    0xA1, 0x53,                 // Collection 0x53
+    0x75, 0x08,                 // report size = 8 bits
+    0x15, 0x00,                 // logical minimum = 0
+    0x26, 0xFF,          0x00,  // logical maximum = 255
+    0x95, DEBUG_TX_SIZE,        // report count
+    0x09, 0x75,                 // usage
+    0x81, 0x02,                 // Input (array)
+    0xC0                        // end collection
 };
 
 #ifdef EXTRAKEY_ENABLE
@@ -308,225 +305,225 @@ static const uint8_t PROGMEM debug_hid_report_desc[] = {
 // http://www.microsoft.com/whdc/archive/w2kbd.mspx
 static const uint8_t PROGMEM extra_hid_report_desc[] = {
     /* system control */
-    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
-    0x09, 0x80,                    // USAGE (System Control)
-    0xa1, 0x01,                    // COLLECTION (Application)
-    0x85, REPORT_ID_SYSTEM,        //   REPORT_ID (2)
-    0x15, 0x01,                    //   LOGICAL_MINIMUM (0x1)
-    0x25, 0xb7,                    //   LOGICAL_MAXIMUM (0xb7)
-    0x19, 0x01,                    //   USAGE_MINIMUM (0x1)
-    0x29, 0xb7,                    //   USAGE_MAXIMUM (0xb7)
-    0x75, 0x10,                    //   REPORT_SIZE (16)
-    0x95, 0x01,                    //   REPORT_COUNT (1)
-    0x81, 0x00,                    //   INPUT (Data,Array,Abs)
-    0xc0,                          // END_COLLECTION
+    0x05, 0x01,              // USAGE_PAGE (Generic Desktop)
+    0x09, 0x80,              // USAGE (System Control)
+    0xa1, 0x01,              // COLLECTION (Application)
+    0x85, REPORT_ID_SYSTEM,  //   REPORT_ID (2)
+    0x15, 0x01,              //   LOGICAL_MINIMUM (0x1)
+    0x25, 0xb7,              //   LOGICAL_MAXIMUM (0xb7)
+    0x19, 0x01,              //   USAGE_MINIMUM (0x1)
+    0x29, 0xb7,              //   USAGE_MAXIMUM (0xb7)
+    0x75, 0x10,              //   REPORT_SIZE (16)
+    0x95, 0x01,              //   REPORT_COUNT (1)
+    0x81, 0x00,              //   INPUT (Data,Array,Abs)
+    0xc0,                    // END_COLLECTION
     /* consumer */
-    0x05, 0x0c,                    // USAGE_PAGE (Consumer Devices)
-    0x09, 0x01,                    // USAGE (Consumer Control)
-    0xa1, 0x01,                    // COLLECTION (Application)
-    0x85, REPORT_ID_CONSUMER,      //   REPORT_ID (3)
-    0x15, 0x01,                    //   LOGICAL_MINIMUM (0x1)
-    0x26, 0x9c, 0x02,              //   LOGICAL_MAXIMUM (0x29c)
-    0x19, 0x01,                    //   USAGE_MINIMUM (0x1)
-    0x2a, 0x9c, 0x02,              //   USAGE_MAXIMUM (0x29c)
-    0x75, 0x10,                    //   REPORT_SIZE (16)
-    0x95, 0x01,                    //   REPORT_COUNT (1)
-    0x81, 0x00,                    //   INPUT (Data,Array,Abs)
-    0xc0,                          // END_COLLECTION
+    0x05, 0x0c,                // USAGE_PAGE (Consumer Devices)
+    0x09, 0x01,                // USAGE (Consumer Control)
+    0xa1, 0x01,                // COLLECTION (Application)
+    0x85, REPORT_ID_CONSUMER,  //   REPORT_ID (3)
+    0x15, 0x01,                //   LOGICAL_MINIMUM (0x1)
+    0x26, 0x9c, 0x02,          //   LOGICAL_MAXIMUM (0x29c)
+    0x19, 0x01,                //   USAGE_MINIMUM (0x1)
+    0x2a, 0x9c, 0x02,          //   USAGE_MAXIMUM (0x29c)
+    0x75, 0x10,                //   REPORT_SIZE (16)
+    0x95, 0x01,                //   REPORT_COUNT (1)
+    0x81, 0x00,                //   INPUT (Data,Array,Abs)
+    0xc0,                      // END_COLLECTION
 };
 #endif
 
-#define KBD_HID_DESC_NUM                0
-#define KBD_HID_DESC_OFFSET             (9+(9+9+7)*KBD_HID_DESC_NUM+9)
+#define KBD_HID_DESC_NUM 0
+#define KBD_HID_DESC_OFFSET (9 + (9 + 9 + 7) * KBD_HID_DESC_NUM + 9)
 
 #ifdef MOUSE_ENABLE
-#   define MOUSE_HID_DESC_NUM           (KBD_HID_DESC_NUM + 1)
-#   define MOUSE_HID_DESC_OFFSET        (9+(9+9+7)*MOUSE_HID_DESC_NUM+9)
+#    define MOUSE_HID_DESC_NUM (KBD_HID_DESC_NUM + 1)
+#    define MOUSE_HID_DESC_OFFSET (9 + (9 + 9 + 7) * MOUSE_HID_DESC_NUM + 9)
 #else
-#   define MOUSE_HID_DESC_NUM           (KBD_HID_DESC_NUM + 0)
+#    define MOUSE_HID_DESC_NUM (KBD_HID_DESC_NUM + 0)
 #endif
 
 #ifdef CONSOLE_ENABLE
-#define DEBUG_HID_DESC_NUM              (MOUSE_HID_DESC_NUM + 1)
-#define DEBUG_HID_DESC_OFFSET           (9+(9+9+7)*DEBUG_HID_DESC_NUM+9)
+#    define DEBUG_HID_DESC_NUM (MOUSE_HID_DESC_NUM + 1)
+#    define DEBUG_HID_DESC_OFFSET (9 + (9 + 9 + 7) * DEBUG_HID_DESC_NUM + 9)
 #else
-#   define DEBUG_HID_DESC_NUM           (MOUSE_HID_DESC_NUM + 0)
+#    define DEBUG_HID_DESC_NUM (MOUSE_HID_DESC_NUM + 0)
 #endif
 
 #ifdef EXTRAKEY_ENABLE
-#   define EXTRA_HID_DESC_NUM           (DEBUG_HID_DESC_NUM + 1)
-#   define EXTRA_HID_DESC_OFFSET        (9+(9+9+7)*EXTRA_HID_DESC_NUM+9)
+#    define EXTRA_HID_DESC_NUM (DEBUG_HID_DESC_NUM + 1)
+#    define EXTRA_HID_DESC_OFFSET (9 + (9 + 9 + 7) * EXTRA_HID_DESC_NUM + 9)
 #else
-#   define EXTRA_HID_DESC_NUM           (DEBUG_HID_DESC_NUM + 0)
+#    define EXTRA_HID_DESC_NUM (DEBUG_HID_DESC_NUM + 0)
 #endif
 
 #ifdef NKRO_ENABLE
-#   define KBD2_HID_DESC_NUM            (EXTRA_HID_DESC_NUM + 1)
-#   define KBD2_HID_DESC_OFFSET         (9+(9+9+7)*EXTRA_HID_DESC_NUM+9)
+#    define KBD2_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 1)
+#    define KBD2_HID_DESC_OFFSET (9 + (9 + 9 + 7) * EXTRA_HID_DESC_NUM + 9)
 #else
-#   define KBD2_HID_DESC_NUM            (EXTRA_HID_DESC_NUM + 0)
+#    define KBD2_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 0)
 #endif
 
-#define NUM_INTERFACES                  (KBD2_HID_DESC_NUM + 1)
-#define CONFIG1_DESC_SIZE               (9+(9+9+7)*NUM_INTERFACES)
+#define NUM_INTERFACES (KBD2_HID_DESC_NUM + 1)
+#define CONFIG1_DESC_SIZE (9 + (9 + 9 + 7) * NUM_INTERFACES)
 static const uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
-       // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
-       9,                                      // bLength;
-       2,                                      // bDescriptorType;
-       LSB(CONFIG1_DESC_SIZE),                 // wTotalLength
-       MSB(CONFIG1_DESC_SIZE),
-       NUM_INTERFACES,                         // bNumInterfaces
-       1,                                      // bConfigurationValue
-       0,                                      // iConfiguration
-       0xA0,                                   // bmAttributes
-       50,                                     // bMaxPower
-
-       // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
-       9,                                      // bLength
-       4,                                      // bDescriptorType
-       KBD_INTERFACE,                          // bInterfaceNumber
-       0,                                      // bAlternateSetting
-       1,                                      // bNumEndpoints
-       0x03,                                   // bInterfaceClass (0x03 = HID)
-       0x01,                                   // bInterfaceSubClass (0x01 = Boot)
-       0x01,                                   // bInterfaceProtocol (0x01 = Keyboard)
-       0,                                      // iInterface
-       // HID descriptor, HID 1.11 spec, section 6.2.1
-       9,                                      // bLength
-       0x21,                                   // bDescriptorType
-       0x11, 0x01,                             // bcdHID
-       0,                                      // bCountryCode
-       1,                                      // bNumDescriptors
-       0x22,                                   // bDescriptorType
-       sizeof(keyboard_hid_report_desc),       // wDescriptorLength
-       0,
-       // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
-       7,                                      // bLength
-       5,                                      // bDescriptorType
-       KBD_ENDPOINT | 0x80,                    // bEndpointAddress
-       0x03,                                   // bmAttributes (0x03=intr)
-       KBD_SIZE, 0,                            // wMaxPacketSize
-       10,                                     // bInterval
+    // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
+    9,                       // bLength;
+    2,                       // bDescriptorType;
+    LSB(CONFIG1_DESC_SIZE),  // wTotalLength
+    MSB(CONFIG1_DESC_SIZE),
+    NUM_INTERFACES,  // bNumInterfaces
+    1,               // bConfigurationValue
+    0,               // iConfiguration
+    0xA0,            // bmAttributes
+    50,              // bMaxPower
+
+    // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
+    9,              // bLength
+    4,              // bDescriptorType
+    KBD_INTERFACE,  // bInterfaceNumber
+    0,              // bAlternateSetting
+    1,              // bNumEndpoints
+    0x03,           // bInterfaceClass (0x03 = HID)
+    0x01,           // bInterfaceSubClass (0x01 = Boot)
+    0x01,           // bInterfaceProtocol (0x01 = Keyboard)
+    0,              // iInterface
+    // HID descriptor, HID 1.11 spec, section 6.2.1
+    9,                                 // bLength
+    0x21,                              // bDescriptorType
+    0x11, 0x01,                        // bcdHID
+    0,                                 // bCountryCode
+    1,                                 // bNumDescriptors
+    0x22,                              // bDescriptorType
+    sizeof(keyboard_hid_report_desc),  // wDescriptorLength
+    0,
+    // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
+    7,                    // bLength
+    5,                    // bDescriptorType
+    KBD_ENDPOINT | 0x80,  // bEndpointAddress
+    0x03,                 // bmAttributes (0x03=intr)
+    KBD_SIZE, 0,          // wMaxPacketSize
+    10,                   // bInterval
 
 #ifdef MOUSE_ENABLE
-       // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
-       9,                                      // bLength
-       4,                                      // bDescriptorType
-       MOUSE_INTERFACE,                        // bInterfaceNumber
-       0,                                      // bAlternateSetting
-       1,                                      // bNumEndpoints
-       0x03,                                   // bInterfaceClass (0x03 = HID)
-        // ThinkPad T23 BIOS doesn't work with boot mouse.
-       0x00,                                   // bInterfaceSubClass (0x01 = Boot)
-       0x00,                                   // bInterfaceProtocol (0x02 = Mouse)
-/*
-       0x01,                                   // bInterfaceSubClass (0x01 = Boot)
-       0x02,                                   // bInterfaceProtocol (0x02 = Mouse)
-*/
-       0,                                      // iInterface
-       // HID descriptor, HID 1.11 spec, section 6.2.1
-       9,                                      // bLength
-       0x21,                                   // bDescriptorType
-       0x11, 0x01,                             // bcdHID
-       0,                                      // bCountryCode
-       1,                                      // bNumDescriptors
-       0x22,                                   // bDescriptorType
-       sizeof(mouse_hid_report_desc),          // wDescriptorLength
-       0,
-       // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
-       7,                                      // bLength
-       5,                                      // bDescriptorType
-       MOUSE_ENDPOINT | 0x80,                  // bEndpointAddress
-       0x03,                                   // bmAttributes (0x03=intr)
-       MOUSE_SIZE, 0,                          // wMaxPacketSize
-       1,                                      // bInterval
+    // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
+    9,                // bLength
+    4,                // bDescriptorType
+    MOUSE_INTERFACE,  // bInterfaceNumber
+    0,                // bAlternateSetting
+    1,                // bNumEndpoints
+    0x03,             // bInterfaceClass (0x03 = HID)
+                      // ThinkPad T23 BIOS doesn't work with boot mouse.
+    0x00,             // bInterfaceSubClass (0x01 = Boot)
+    0x00,             // bInterfaceProtocol (0x02 = Mouse)
+                      /*
+                          0x01,                                        // bInterfaceSubClass (0x01 = Boot)
+                          0x02,                                        // bInterfaceProtocol (0x02 = Mouse)
+                      */
+    0,                // iInterface
+    // HID descriptor, HID 1.11 spec, section 6.2.1
+    9,                              // bLength
+    0x21,                           // bDescriptorType
+    0x11, 0x01,                     // bcdHID
+    0,                              // bCountryCode
+    1,                              // bNumDescriptors
+    0x22,                           // bDescriptorType
+    sizeof(mouse_hid_report_desc),  // wDescriptorLength
+    0,
+    // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
+    7,                      // bLength
+    5,                      // bDescriptorType
+    MOUSE_ENDPOINT | 0x80,  // bEndpointAddress
+    0x03,                   // bmAttributes (0x03=intr)
+    MOUSE_SIZE, 0,          // wMaxPacketSize
+    1,                      // bInterval
 #endif
 
 #ifdef CONSOLE_ENABLE
-       // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
-       9,                                      // bLength
-       4,                                      // bDescriptorType
-       DEBUG_INTERFACE,                        // bInterfaceNumber
-       0,                                      // bAlternateSetting
-       1,                                      // bNumEndpoints
-       0x03,                                   // bInterfaceClass (0x03 = HID)
-       0x00,                                   // bInterfaceSubClass
-       0x00,                                   // bInterfaceProtocol
-       0,                                      // iInterface
-       // HID descriptor, HID 1.11 spec, section 6.2.1
-       9,                                      // bLength
-       0x21,                                   // bDescriptorType
-       0x11, 0x01,                             // bcdHID
-       0,                                      // bCountryCode
-       1,                                      // bNumDescriptors
-       0x22,                                   // bDescriptorType
-       sizeof(debug_hid_report_desc),          // wDescriptorLength
-       0,
-       // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
-       7,                                      // bLength
-       5,                                      // bDescriptorType
-       DEBUG_TX_ENDPOINT | 0x80,               // bEndpointAddress
-       0x03,                                   // bmAttributes (0x03=intr)
-       DEBUG_TX_SIZE, 0,                       // wMaxPacketSize
-       1,                                      // bInterval
+    // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
+    9,                // bLength
+    4,                // bDescriptorType
+    DEBUG_INTERFACE,  // bInterfaceNumber
+    0,                // bAlternateSetting
+    1,                // bNumEndpoints
+    0x03,             // bInterfaceClass (0x03 = HID)
+    0x00,             // bInterfaceSubClass
+    0x00,             // bInterfaceProtocol
+    0,                // iInterface
+    // HID descriptor, HID 1.11 spec, section 6.2.1
+    9,                              // bLength
+    0x21,                           // bDescriptorType
+    0x11, 0x01,                     // bcdHID
+    0,                              // bCountryCode
+    1,                              // bNumDescriptors
+    0x22,                           // bDescriptorType
+    sizeof(debug_hid_report_desc),  // wDescriptorLength
+    0,
+    // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
+    7,                         // bLength
+    5,                         // bDescriptorType
+    DEBUG_TX_ENDPOINT | 0x80,  // bEndpointAddress
+    0x03,                      // bmAttributes (0x03=intr)
+    DEBUG_TX_SIZE, 0,          // wMaxPacketSize
+    1,                         // bInterval
 #endif
 
 #ifdef EXTRAKEY_ENABLE
-       // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
-       9,                                      // bLength
-       4,                                      // bDescriptorType
-       EXTRA_INTERFACE,                        // bInterfaceNumber
-       0,                                      // bAlternateSetting
-       1,                                      // bNumEndpoints
-       0x03,                                   // bInterfaceClass (0x03 = HID)
-       0x00,                                   // bInterfaceSubClass
-       0x00,                                   // bInterfaceProtocol
-       0,                                      // iInterface
-       // HID descriptor, HID 1.11 spec, section 6.2.1
-       9,                                      // bLength
-       0x21,                                   // bDescriptorType
-       0x11, 0x01,                             // bcdHID
-       0,                                      // bCountryCode
-       1,                                      // bNumDescriptors
-       0x22,                                   // bDescriptorType
-       sizeof(extra_hid_report_desc),          // wDescriptorLength
-       0,
-       // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
-       7,                                      // bLength
-       5,                                      // bDescriptorType
-       EXTRA_ENDPOINT | 0x80,                  // bEndpointAddress
-       0x03,                                   // bmAttributes (0x03=intr)
-       EXTRA_SIZE, 0,                          // wMaxPacketSize
-       10,                                     // bInterval
+    // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
+    9,                // bLength
+    4,                // bDescriptorType
+    EXTRA_INTERFACE,  // bInterfaceNumber
+    0,                // bAlternateSetting
+    1,                // bNumEndpoints
+    0x03,             // bInterfaceClass (0x03 = HID)
+    0x00,             // bInterfaceSubClass
+    0x00,             // bInterfaceProtocol
+    0,                // iInterface
+    // HID descriptor, HID 1.11 spec, section 6.2.1
+    9,                              // bLength
+    0x21,                           // bDescriptorType
+    0x11, 0x01,                     // bcdHID
+    0,                              // bCountryCode
+    1,                              // bNumDescriptors
+    0x22,                           // bDescriptorType
+    sizeof(extra_hid_report_desc),  // wDescriptorLength
+    0,
+    // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
+    7,                      // bLength
+    5,                      // bDescriptorType
+    EXTRA_ENDPOINT | 0x80,  // bEndpointAddress
+    0x03,                   // bmAttributes (0x03=intr)
+    EXTRA_SIZE, 0,          // wMaxPacketSize
+    10,                     // bInterval
 #endif
 
 #ifdef NKRO_ENABLE
-       // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
-       9,                                      // bLength
-       4,                                      // bDescriptorType
-       KBD2_INTERFACE,                         // bInterfaceNumber
-       0,                                      // bAlternateSetting
-       1,                                      // bNumEndpoints
-       0x03,                                   // bInterfaceClass (0x03 = HID)
-       0x00,                                   // bInterfaceSubClass (0x01 = Boot)
-       0x00,                                   // bInterfaceProtocol (0x01 = Keyboard)
-       0,                                      // iInterface
-       // HID descriptor, HID 1.11 spec, section 6.2.1
-       9,                                      // bLength
-       0x21,                                   // bDescriptorType
-       0x11, 0x01,                             // bcdHID
-       0,                                      // bCountryCode
-       1,                                      // bNumDescriptors
-       0x22,                                   // bDescriptorType
-       sizeof(keyboard2_hid_report_desc),      // wDescriptorLength
-       0,
-       // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
-       7,                                      // bLength
-       5,                                      // bDescriptorType
-       KBD2_ENDPOINT | 0x80,                   // bEndpointAddress
-       0x03,                                   // bmAttributes (0x03=intr)
-       KBD2_SIZE, 0,                           // wMaxPacketSize
-       1,                                      // bInterval
+    // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
+    9,               // bLength
+    4,               // bDescriptorType
+    KBD2_INTERFACE,  // bInterfaceNumber
+    0,               // bAlternateSetting
+    1,               // bNumEndpoints
+    0x03,            // bInterfaceClass (0x03 = HID)
+    0x00,            // bInterfaceSubClass (0x01 = Boot)
+    0x00,            // bInterfaceProtocol (0x01 = Keyboard)
+    0,               // iInterface
+    // HID descriptor, HID 1.11 spec, section 6.2.1
+    9,                                  // bLength
+    0x21,                               // bDescriptorType
+    0x11, 0x01,                         // bcdHID
+    0,                                  // bCountryCode
+    1,                                  // bNumDescriptors
+    0x22,                               // bDescriptorType
+    sizeof(keyboard2_hid_report_desc),  // wDescriptorLength
+    0,
+    // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
+    7,                     // bLength
+    5,                     // bDescriptorType
+    KBD2_ENDPOINT | 0x80,  // bEndpointAddress
+    0x03,                  // bmAttributes (0x03=intr)
+    KBD2_SIZE, 0,          // wMaxPacketSize
+    1,                     // bInterval
 #endif
 };
 
@@ -534,64 +531,50 @@ static const uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
 // can be completely removed if iManufacturer, iProduct, iSerialNumber
 // in the device desciptor are changed to zeros.
 struct usb_string_descriptor_struct {
-       uint8_t bLength;
-       uint8_t bDescriptorType;
-       int16_t wString[];
-};
-static const struct usb_string_descriptor_struct PROGMEM string0 = {
-       4,
-       3,
-       {0x0409}
-};
-static const struct usb_string_descriptor_struct PROGMEM string1 = {
-       sizeof(STR_MANUFACTURER),
-       3,
-       STR_MANUFACTURER
-};
-static const struct usb_string_descriptor_struct PROGMEM string2 = {
-       sizeof(STR_PRODUCT),
-       3,
-       STR_PRODUCT
+    uint8_t bLength;
+    uint8_t bDescriptorType;
+    int16_t wString[];
 };
+static const struct usb_string_descriptor_struct PROGMEM string0 = {4, 3, {0x0409}};
+static const struct usb_string_descriptor_struct PROGMEM string1 = {sizeof(STR_MANUFACTURER), 3, STR_MANUFACTURER};
+static const struct usb_string_descriptor_struct PROGMEM string2 = {sizeof(STR_PRODUCT), 3, STR_PRODUCT};
 
 // This table defines which descriptor data is sent for each specific
 // request from the host (in wValue and wIndex).
 static const struct descriptor_list_struct {
-       uint16_t        wValue;     // descriptor type
-       uint16_t        wIndex;
-       const uint8_t   *addr;
-       uint8_t         length;
+    uint16_t       wValue;  // descriptor type
+    uint16_t       wIndex;
+    const uint8_t *addr;
+    uint8_t        length;
 } PROGMEM descriptor_list[] = {
-        // DEVICE descriptor
-       {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
-        // CONFIGURATION descriptor
-       {0x0200, 0x0000, config1_descriptor, sizeof(config1_descriptor)},
-        // HID/REPORT descriptors
-       {0x2100, KBD_INTERFACE, config1_descriptor+KBD_HID_DESC_OFFSET, 9},
-       {0x2200, KBD_INTERFACE, keyboard_hid_report_desc, sizeof(keyboard_hid_report_desc)},
+    // DEVICE descriptor
+    {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
+    // CONFIGURATION descriptor
+    {0x0200, 0x0000, config1_descriptor, sizeof(config1_descriptor)},
+    // HID/REPORT descriptors
+    {0x2100, KBD_INTERFACE, config1_descriptor + KBD_HID_DESC_OFFSET, 9},
+    {0x2200, KBD_INTERFACE, keyboard_hid_report_desc, sizeof(keyboard_hid_report_desc)},
 #ifdef MOUSE_ENABLE
-       {0x2100, MOUSE_INTERFACE, config1_descriptor+MOUSE_HID_DESC_OFFSET, 9},
-       {0x2200, MOUSE_INTERFACE, mouse_hid_report_desc, sizeof(mouse_hid_report_desc)},
+    {0x2100, MOUSE_INTERFACE, config1_descriptor + MOUSE_HID_DESC_OFFSET, 9},
+    {0x2200, MOUSE_INTERFACE, mouse_hid_report_desc, sizeof(mouse_hid_report_desc)},
 #endif
 #ifdef CONSOLE_ENABLE
-       {0x2100, DEBUG_INTERFACE, config1_descriptor+DEBUG_HID_DESC_OFFSET, 9},
-       {0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)},
+    {0x2100, DEBUG_INTERFACE, config1_descriptor + DEBUG_HID_DESC_OFFSET, 9},
+    {0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)},
 #endif
 #ifdef EXTRAKEY_ENABLE
-       {0x2100, EXTRA_INTERFACE, config1_descriptor+EXTRA_HID_DESC_OFFSET, 9},
-       {0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)},
+    {0x2100, EXTRA_INTERFACE, config1_descriptor + EXTRA_HID_DESC_OFFSET, 9},
+    {0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)},
 #endif
 #ifdef NKRO_ENABLE
-       {0x2100, KBD2_INTERFACE, config1_descriptor+KBD2_HID_DESC_OFFSET, 9},
-       {0x2200, KBD2_INTERFACE, keyboard2_hid_report_desc, sizeof(keyboard2_hid_report_desc)},
+    {0x2100, KBD2_INTERFACE, config1_descriptor + KBD2_HID_DESC_OFFSET, 9},
+    {0x2200, KBD2_INTERFACE, keyboard2_hid_report_desc, sizeof(keyboard2_hid_report_desc)},
 #endif
-        // STRING descriptors
-       {0x0300, 0x0000, (const uint8_t *)&string0, 4},
-       {0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)},
-       {0x0302, 0x0409, (const uint8_t *)&string2, sizeof(STR_PRODUCT)}
-};
-#define NUM_DESC_LIST (sizeof(descriptor_list)/sizeof(struct descriptor_list_struct))
-
+    // STRING descriptors
+    {0x0300, 0x0000, (const uint8_t *)&string0, 4},
+    {0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)},
+    {0x0302, 0x0409, (const uint8_t *)&string2, sizeof(STR_PRODUCT)}};
+#define NUM_DESC_LIST (sizeof(descriptor_list) / sizeof(struct descriptor_list_struct))
 
 /**************************************************************************
  *
@@ -600,8 +583,7 @@ static const struct descriptor_list_struct {
  **************************************************************************/
 
 // zero when we are not configured, non-zero when enumerated
-static volatile uint8_t usb_configuration=0;
-
+static volatile uint8_t usb_configuration = 0;
 
 /**************************************************************************
  *
@@ -609,400 +591,380 @@ static volatile uint8_t usb_configuration=0;
  *
  **************************************************************************/
 
-
 // initialize USB
-void usb_init(void)
-{
-       HW_CONFIG();
-       USB_FREEZE();                           // enable USB
-       PLL_CONFIG();                           // config PLL
-        while (!(PLLCSR & (1<<PLOCK))) ;       // wait for PLL lock
-        USB_CONFIG();                          // start USB clock
-        UDCON = 0;                             // enable attach resistor
-       usb_configuration = 0;
-        suspend = false;
-        UDIEN = (1<<EORSTE)|(1<<SOFE)|(1<<SUSPE)|(1<<WAKEUPE);
-       sei();
+void usb_init(void) {
+    HW_CONFIG();
+    USB_FREEZE();  // enable USB
+    PLL_CONFIG();  // config PLL
+    while (!(PLLCSR & (1 << PLOCK)))
+        ;                   // wait for PLL lock
+    USB_CONFIG();           // start USB clock
+    UDCON             = 0;  // enable attach resistor
+    usb_configuration = 0;
+    suspend           = false;
+    UDIEN             = (1 << EORSTE) | (1 << SOFE) | (1 << SUSPE) | (1 << WAKEUPE);
+    sei();
 }
 
 // return 0 if the USB is not configured, or the configuration
 // number selected by the HOST
-uint8_t usb_configured(void)
-{
-       return usb_configuration && !suspend;
-}
+uint8_t usb_configured(void) { return usb_configuration && !suspend; }
 
-void usb_remote_wakeup(void)
-{
-    UDCON |= (1<<RMWKUP);
-    while (UDCON & (1<<RMWKUP));
+void usb_remote_wakeup(void) {
+    UDCON |= (1 << RMWKUP);
+    while (UDCON & (1 << RMWKUP))
+        ;
 }
 
-
-
 /**************************************************************************
  *
  *  Private Functions - not intended for general user consumption....
  *
  **************************************************************************/
 
-
-
 // USB Device Interrupt - handle all device-level events
 // the transmit buffer flushing is triggered by the start of frame
 //
-ISR(USB_GEN_vect)
-{
-       uint8_t intbits, t;
-       static uint8_t div4=0;
-
-        intbits = UDINT;
-        UDINT = 0;
-        if ((intbits & (1<<SUSPI)) && (UDIEN & (1<<SUSPE)) && usb_configuration) {
+ISR(USB_GEN_vect) {
+    uint8_t        intbits, t;
+    static uint8_t div4 = 0;
+
+    intbits = UDINT;
+    UDINT   = 0;
+    if ((intbits & (1 << SUSPI)) && (UDIEN & (1 << SUSPE)) && usb_configuration) {
 #ifdef SLEEP_LED_ENABLE
-            sleep_led_enable();
-#endif
-            UDIEN &= ~(1<<SUSPE);
-            UDIEN |= (1<<WAKEUPE);
-            suspend = true;
-        }
-        if ((intbits & (1<<WAKEUPI)) && (UDIEN & (1<<WAKEUPE)) && usb_configuration) {
-            suspend_wakeup_init();
+        sleep_led_enable();
+#endif
+        UDIEN &= ~(1 << SUSPE);
+        UDIEN |= (1 << WAKEUPE);
+        suspend = true;
+    }
+    if ((intbits & (1 << WAKEUPI)) && (UDIEN & (1 << WAKEUPE)) && usb_configuration) {
+        suspend_wakeup_init();
 #ifdef SLEEP_LED_ENABLE
-            sleep_led_disable();
-            // NOTE: converters may not accept this
-            led_set(host_keyboard_leds());
+        sleep_led_disable();
+        // NOTE: converters may not accept this
+        led_set(host_keyboard_leds());
 #endif
 
-            UDIEN |= (1<<SUSPE);
-            UDIEN &= ~(1<<WAKEUPE);
-            suspend = false;
-        }
-        if (intbits & (1<<EORSTI)) {
-               UENUM = 0;
-               UECONX = 1;
-               UECFG0X = EP_TYPE_CONTROL;
-               UECFG1X = EP_SIZE(ENDPOINT0_SIZE) | EP_SINGLE_BUFFER;
-               UEIENX = (1<<RXSTPE);
-               usb_configuration = 0;
+        UDIEN |= (1 << SUSPE);
+        UDIEN &= ~(1 << WAKEUPE);
+        suspend = false;
+    }
+    if (intbits & (1 << EORSTI)) {
+        UENUM             = 0;
+        UECONX            = 1;
+        UECFG0X           = EP_TYPE_CONTROL;
+        UECFG1X           = EP_SIZE(ENDPOINT0_SIZE) | EP_SINGLE_BUFFER;
+        UEIENX            = (1 << RXSTPE);
+        usb_configuration = 0;
+    }
+    if ((intbits & (1 << SOFI)) && usb_configuration) {
+        t = debug_flush_timer;
+        if (t) {
+            debug_flush_timer = --t;
+            if (!t) {
+                UENUM = DEBUG_TX_ENDPOINT;
+                while ((UEINTX & (1 << RWAL))) {
+                    UEDATX = 0;
+                }
+                UEINTX = 0x3A;
+            }
         }
-       if ((intbits & (1<<SOFI)) && usb_configuration) {
-               t = debug_flush_timer;
-               if (t) {
-                       debug_flush_timer = -- t;
-                       if (!t) {
-                               UENUM = DEBUG_TX_ENDPOINT;
-                               while ((UEINTX & (1<<RWAL))) {
-                                       UEDATX = 0;
-                               }
-                               UEINTX = 0x3A;
-                       }
-               }
-                /* TODO: should keep IDLE rate on each keyboard interface */
+        /* TODO: should keep IDLE rate on each keyboard interface */
 #ifdef NKRO_ENABLE
-               if (!keymap_config.nkro && keyboard_idle && (++div4 & 3) == 0) {
+        if (!keymap_config.nkro && keyboard_idle && (++div4 & 3) == 0) {
 #else
-               if (keyboard_idle && (++div4 & 3) == 0) {
-#endif
-                       UENUM = KBD_ENDPOINT;
-                       if (UEINTX & (1<<RWAL)) {
-                               usb_keyboard_idle_count++;
-                               if (usb_keyboard_idle_count == keyboard_idle) {
-                                       usb_keyboard_idle_count = 0;
-                                        /* TODO: fix keyboard_report inconsistency */
-/* To avoid Mac SET_IDLE behaviour.
-                                       UEDATX = keyboard_report_prev->mods;
-                                       UEDATX = 0;
-                                        uint8_t keys = keyboard_protocol ? KBD_REPORT_KEYS : 6;
-                                       for (uint8_t i=0; i<keys; i++) {
-                                               UEDATX = keyboard_report_prev->keys[i];
-                                       }
-                                       UEINTX = 0x3A;
-*/
-                               }
-                       }
-               }
-       }
+        if (keyboard_idle && (++div4 & 3) == 0) {
+#endif
+            UENUM = KBD_ENDPOINT;
+            if (UEINTX & (1 << RWAL)) {
+                usb_keyboard_idle_count++;
+                if (usb_keyboard_idle_count == keyboard_idle) {
+                    usb_keyboard_idle_count = 0;
+                    /* TODO: fix keyboard_report inconsistency */
+                    /* To avoid Mac SET_IDLE behaviour.
+                                        UEDATX = keyboard_report_prev->mods;
+                                        UEDATX = 0;
+                                                            uint8_t keys = keyboard_protocol ? KBD_REPORT_KEYS : 6;
+                                        for (uint8_t i=0; i<keys; i++) {
+                                            UEDATX = keyboard_report_prev->keys[i];
+                                        }
+                                        UEINTX = 0x3A;
+                    */
+                }
+            }
+        }
+    }
 }
 
-
-
 // Misc functions to wait for ready and send/receive packets
-static inline void usb_wait_in_ready(void)
-{
-       while (!(UEINTX & (1<<TXINI))) ;
-}
-static inline void usb_send_in(void)
-{
-       UEINTX = ~(1<<TXINI);
-}
-static inline void usb_wait_receive_out(void)
-{
-       while (!(UEINTX & (1<<RXOUTI))) ;
+static inline void usb_wait_in_ready(void) {
+    while (!(UEINTX & (1 << TXINI)))
+        ;
 }
-static inline void usb_ack_out(void)
-{
-       UEINTX = ~(1<<RXOUTI);
+static inline void usb_send_in(void) { UEINTX = ~(1 << TXINI); }
+static inline void usb_wait_receive_out(void) {
+    while (!(UEINTX & (1 << RXOUTI)))
+        ;
 }
-
-
+static inline void usb_ack_out(void) { UEINTX = ~(1 << RXOUTI); }
 
 // USB Endpoint Interrupt - endpoint 0 is handled here.  The
 // other endpoints are manipulated by the user-callable
 // functions, and the start-of-frame interrupt.
 //
-ISR(USB_COM_vect)
-{
-        uint8_t intbits;
-       const uint8_t *list;
-        const uint8_t *cfg;
-       uint8_t i, n, len, en;
-       uint8_t bmRequestType;
-       uint8_t bRequest;
-       uint16_t wValue;
-       uint16_t wIndex;
-       uint16_t wLength;
-       uint16_t desc_val;
-       const uint8_t *desc_addr;
-       uint8_t desc_length;
-
-        UENUM = 0;
-       intbits = UEINTX;
-        if (intbits & (1<<RXSTPI)) {
-                bmRequestType = UEDATX;
-                bRequest = UEDATX;
-                wValue = UEDATX;
-                wValue |= (UEDATX << 8);
-                wIndex = UEDATX;
-                wIndex |= (UEDATX << 8);
-                wLength = UEDATX;
-                wLength |= (UEDATX << 8);
-                UEINTX = ~((1<<RXSTPI) | (1<<RXOUTI) | (1<<TXINI));
-                if (bRequest == GET_DESCRIPTOR) {
-                       list = (const uint8_t *)descriptor_list;
-                       for (i=0; ; i++) {
-                               if (i >= NUM_DESC_LIST) {
-                                       UECONX = (1<<STALLRQ)|(1<<EPEN);  //stall
-                                       return;
-                               }
-                               desc_val = pgm_read_word(list);
-                               if (desc_val != wValue) {
-                                       list += sizeof(struct descriptor_list_struct);
-                                       continue;
-                               }
-                               list += 2;
-                               desc_val = pgm_read_word(list);
-                               if (desc_val != wIndex) {
-                                       list += sizeof(struct descriptor_list_struct)-2;
-                                       continue;
-                               }
-                               list += 2;
-                               desc_addr = (const uint8_t *)pgm_read_word(list);
-                               list += 2;
-                               desc_length = pgm_read_byte(list);
-                               break;
-                       }
-                       len = (wLength < 256) ? wLength : 255;
-                       if (len > desc_length) len = desc_length;
-                       do {
-                               // wait for host ready for IN packet
-                               do {
-                                       i = UEINTX;
-                               } while (!(i & ((1<<TXINI)|(1<<RXOUTI))));
-                               if (i & (1<<RXOUTI)) return;    // abort
-                               // send IN packet
-                               n = len < ENDPOINT0_SIZE ? len : ENDPOINT0_SIZE;
-                               for (i = n; i; i--) {
-                                       UEDATX = pgm_read_byte(desc_addr++);
-                               }
-                               len -= n;
-                               usb_send_in();
-                       } while (len || n == ENDPOINT0_SIZE);
-                       return;
+ISR(USB_COM_vect) {
+    uint8_t        intbits;
+    const uint8_t *list;
+    const uint8_t *cfg;
+    uint8_t        i, n, len, en;
+    uint8_t        bmRequestType;
+    uint8_t        bRequest;
+    uint16_t       wValue;
+    uint16_t       wIndex;
+    uint16_t       wLength;
+    uint16_t       desc_val;
+    const uint8_t *desc_addr;
+    uint8_t        desc_length;
+
+    UENUM   = 0;
+    intbits = UEINTX;
+    if (intbits & (1 << RXSTPI)) {
+        bmRequestType = UEDATX;
+        bRequest      = UEDATX;
+        wValue        = UEDATX;
+        wValue |= (UEDATX << 8);
+        wIndex = UEDATX;
+        wIndex |= (UEDATX << 8);
+        wLength = UEDATX;
+        wLength |= (UEDATX << 8);
+        UEINTX = ~((1 << RXSTPI) | (1 << RXOUTI) | (1 << TXINI));
+        if (bRequest == GET_DESCRIPTOR) {
+            list = (const uint8_t *)descriptor_list;
+            for (i = 0;; i++) {
+                if (i >= NUM_DESC_LIST) {
+                    UECONX = (1 << STALLRQ) | (1 << EPEN);  // stall
+                    return;
+                }
+                desc_val = pgm_read_word(list);
+                if (desc_val != wValue) {
+                    list += sizeof(struct descriptor_list_struct);
+                    continue;
+                }
+                list += 2;
+                desc_val = pgm_read_word(list);
+                if (desc_val != wIndex) {
+                    list += sizeof(struct descriptor_list_struct) - 2;
+                    continue;
                 }
-               if (bRequest == SET_ADDRESS) {
-                       usb_send_in();
-                       usb_wait_in_ready();
-                       UDADDR = wValue | (1<<ADDEN);
-                       return;
-               }
-               if (bRequest == SET_CONFIGURATION && bmRequestType == 0) {
-                       usb_configuration = wValue;
-                       usb_send_in();
-                       cfg = endpoint_config_table;
-                       for (i=1; i<=MAX_ENDPOINT; i++) {
-                               UENUM = i;
-                               en = pgm_read_byte(cfg++);
-                                if (en) {
-                                    UECONX = (1<<EPEN);
-                                    UECFG0X = pgm_read_byte(cfg++);
-                                    UECFG1X = pgm_read_byte(cfg++);
-                                } else {
-                                    UECONX = 0;
-                               }
-                       }
-                       UERST = UERST_MASK;
-                       UERST = 0;
-                       return;
-               }
-               if (bRequest == GET_CONFIGURATION && bmRequestType == 0x80) {
-                       usb_wait_in_ready();
-                       UEDATX = usb_configuration;
-                       usb_send_in();
-                       return;
-               }
-
-               if (bRequest == GET_STATUS) {
-                       usb_wait_in_ready();
-                       i = 0;
-                       #ifdef SUPPORT_ENDPOINT_HALT
-                       if (bmRequestType == 0x82) {
-                               UENUM = wIndex;
-                               if (UECONX & (1<<STALLRQ)) i = 1;
-                               UENUM = 0;
-                       }
-                       #endif
-                       UEDATX = i;
-                       UEDATX = 0;
-                       usb_send_in();
-                       return;
-               }
-               if (bRequest == CLEAR_FEATURE || bRequest == SET_FEATURE) {
+                list += 2;
+                desc_addr = (const uint8_t *)pgm_read_word(list);
+                list += 2;
+                desc_length = pgm_read_byte(list);
+                break;
+            }
+            len = (wLength < 256) ? wLength : 255;
+            if (len > desc_length) len = desc_length;
+            do {
+                // wait for host ready for IN packet
+                do {
+                    i = UEINTX;
+                } while (!(i & ((1 << TXINI) | (1 << RXOUTI))));
+                if (i & (1 << RXOUTI)) return;  // abort
+                // send IN packet
+                n = len < ENDPOINT0_SIZE ? len : ENDPOINT0_SIZE;
+                for (i = n; i; i--) {
+                    UEDATX = pgm_read_byte(desc_addr++);
+                }
+                len -= n;
+                usb_send_in();
+            } while (len || n == ENDPOINT0_SIZE);
+            return;
+        }
+        if (bRequest == SET_ADDRESS) {
+            usb_send_in();
+            usb_wait_in_ready();
+            UDADDR = wValue | (1 << ADDEN);
+            return;
+        }
+        if (bRequest == SET_CONFIGURATION && bmRequestType == 0) {
+            usb_configuration = wValue;
+            usb_send_in();
+            cfg = endpoint_config_table;
+            for (i = 1; i <= MAX_ENDPOINT; i++) {
+                UENUM = i;
+                en    = pgm_read_byte(cfg++);
+                if (en) {
+                    UECONX  = (1 << EPEN);
+                    UECFG0X = pgm_read_byte(cfg++);
+                    UECFG1X = pgm_read_byte(cfg++);
+                } else {
+                    UECONX = 0;
+                }
+            }
+            UERST = UERST_MASK;
+            UERST = 0;
+            return;
+        }
+        if (bRequest == GET_CONFIGURATION && bmRequestType == 0x80) {
+            usb_wait_in_ready();
+            UEDATX = usb_configuration;
+            usb_send_in();
+            return;
+        }
+
+        if (bRequest == GET_STATUS) {
+            usb_wait_in_ready();
+            i = 0;
+#ifdef SUPPORT_ENDPOINT_HALT
+            if (bmRequestType == 0x82) {
+                UENUM = wIndex;
+                if (UECONX & (1 << STALLRQ)) i = 1;
+                UENUM = 0;
+            }
+#endif
+            UEDATX = i;
+            UEDATX = 0;
+            usb_send_in();
+            return;
+        }
+        if (bRequest == CLEAR_FEATURE || bRequest == SET_FEATURE) {
 #ifdef SUPPORT_ENDPOINT_HALT
-                   if (bmRequestType == 0x02 && wValue == ENDPOINT_HALT) {
-                       i = wIndex & 0x7F;
-                       if (i >= 1 && i <= MAX_ENDPOINT) {
-                               usb_send_in();
-                               UENUM = i;
-                               if (bRequest == SET_FEATURE) {
-                                       UECONX = (1<<STALLRQ)|(1<<EPEN);
-                               } else {
-                                       UECONX = (1<<STALLRQC)|(1<<RSTDT)|(1<<EPEN);
-                                       UERST = (1 << i);
-                                       UERST = 0;
-                               }
-                               return;
-                       }
+            if (bmRequestType == 0x02 && wValue == ENDPOINT_HALT) {
+                i = wIndex & 0x7F;
+                if (i >= 1 && i <= MAX_ENDPOINT) {
+                    usb_send_in();
+                    UENUM = i;
+                    if (bRequest == SET_FEATURE) {
+                        UECONX = (1 << STALLRQ) | (1 << EPEN);
+                    } else {
+                        UECONX = (1 << STALLRQC) | (1 << RSTDT) | (1 << EPEN);
+                        UERST  = (1 << i);
+                        UERST  = 0;
                     }
+                    return;
+                }
+            }
 #endif
-                    if (bmRequestType == 0x00 && wValue == DEVICE_REMOTE_WAKEUP) {
-                        if (bRequest == SET_FEATURE) {
-                            remote_wakeup = true;
-                        } else {
-                            remote_wakeup = false;
-                        }
-                        usb_send_in();
-                        return;
+            if (bmRequestType == 0x00 && wValue == DEVICE_REMOTE_WAKEUP) {
+                if (bRequest == SET_FEATURE) {
+                    remote_wakeup = true;
+                } else {
+                    remote_wakeup = false;
+                }
+                usb_send_in();
+                return;
+            }
+        }
+        if (wIndex == KBD_INTERFACE) {
+            if (bmRequestType == 0xA1) {
+                if (bRequest == HID_GET_REPORT) {
+                    usb_wait_in_ready();
+                    UEDATX = keyboard_report->mods;
+                    UEDATX = 0;
+                    for (i = 0; i < 6; i++) {
+                        UEDATX = keyboard_report->keys[i];
                     }
-               }
-               if (wIndex == KBD_INTERFACE) {
-                       if (bmRequestType == 0xA1) {
-                               if (bRequest == HID_GET_REPORT) {
-                                       usb_wait_in_ready();
-                                       UEDATX = keyboard_report->mods;
-                                       UEDATX = 0;
-                                       for (i=0; i<6; i++) {
-                                               UEDATX = keyboard_report->keys[i];
-                                       }
-                                       usb_send_in();
-                                       return;
-                               }
-                               if (bRequest == HID_GET_IDLE) {
-                                       usb_wait_in_ready();
-                                       UEDATX = keyboard_idle;
-                                       usb_send_in();
-                                       return;
-                               }
-                               if (bRequest == HID_GET_PROTOCOL) {
-                                       usb_wait_in_ready();
-                                       UEDATX = keyboard_protocol;
-                                       usb_send_in();
-                                       return;
-                               }
-                       }
-                       if (bmRequestType == 0x21) {
-                               if (bRequest == HID_SET_REPORT) {
-                                       usb_wait_receive_out();
-                                       usb_keyboard_leds = UEDATX;
-                                       usb_ack_out();
-                                       usb_send_in();
-                                       return;
-                               }
-                               if (bRequest == HID_SET_IDLE) {
-                                       keyboard_idle = (wValue >> 8);
-                                       usb_keyboard_idle_count = 0;
-                                       //usb_wait_in_ready();
-                                       usb_send_in();
-                                       return;
-                               }
-                               if (bRequest == HID_SET_PROTOCOL) {
-                                       keyboard_protocol = wValue;
+                    usb_send_in();
+                    return;
+                }
+                if (bRequest == HID_GET_IDLE) {
+                    usb_wait_in_ready();
+                    UEDATX = keyboard_idle;
+                    usb_send_in();
+                    return;
+                }
+                if (bRequest == HID_GET_PROTOCOL) {
+                    usb_wait_in_ready();
+                    UEDATX = keyboard_protocol;
+                    usb_send_in();
+                    return;
+                }
+            }
+            if (bmRequestType == 0x21) {
+                if (bRequest == HID_SET_REPORT) {
+                    usb_wait_receive_out();
+                    usb_keyboard_leds = UEDATX;
+                    usb_ack_out();
+                    usb_send_in();
+                    return;
+                }
+                if (bRequest == HID_SET_IDLE) {
+                    keyboard_idle           = (wValue >> 8);
+                    usb_keyboard_idle_count = 0;
+                    // usb_wait_in_ready();
+                    usb_send_in();
+                    return;
+                }
+                if (bRequest == HID_SET_PROTOCOL) {
+                    keyboard_protocol = wValue;
 #ifdef NKRO_ENABLE
-                                        keymap_config.nkro = !!keyboard_protocol;
-#endif
-                                        clear_keyboard();
-                                       //usb_wait_in_ready();
-                                       usb_send_in();
-                                       return;
-                               }
-                       }
-               }
+                    keymap_config.nkro = !!keyboard_protocol;
+#endif
+                    clear_keyboard();
+                    // usb_wait_in_ready();
+                    usb_send_in();
+                    return;
+                }
+            }
+        }
 #ifdef MOUSE_ENABLE
-               if (wIndex == MOUSE_INTERFACE) {
-                       if (bmRequestType == 0xA1) {
-                               if (bRequest == HID_GET_REPORT) {
-                                    if (wValue == HID_REPORT_INPUT) {
-                                       usb_wait_in_ready();
-                                       UEDATX = 0;
-                                       UEDATX = 0;
-                                       UEDATX = 0;
-                                       UEDATX = 0;
-                                       usb_send_in();
-                                       return;
-                                    }
-                                    if (wValue == HID_REPORT_FEATURE) {
-                                       usb_wait_in_ready();
-                                       UEDATX = 0x05;
-                                       usb_send_in();
-                                       return;
-                                    }
-                               }
-                               if (bRequest == HID_GET_PROTOCOL) {
-                                       usb_wait_in_ready();
-                                       UEDATX = usb_mouse_protocol;
-                                       usb_send_in();
-                                       return;
-                               }
-                       }
-                       if (bmRequestType == 0x21) {
-                               if (bRequest == HID_SET_PROTOCOL) {
-                                       usb_mouse_protocol = wValue;
-                                       usb_send_in();
-                                       return;
-                               }
-                       }
-               }
-#endif
-               if (wIndex == DEBUG_INTERFACE) {
-                       if (bRequest == HID_GET_REPORT && bmRequestType == 0xA1) {
-                               len = wLength;
-                               do {
-                                       // wait for host ready for IN packet
-                                       do {
-                                               i = UEINTX;
-                                       } while (!(i & ((1<<TXINI)|(1<<RXOUTI))));
-                                       if (i & (1<<RXOUTI)) return;    // abort
-                                       // send IN packet
-                                       n = len < ENDPOINT0_SIZE ? len : ENDPOINT0_SIZE;
-                                       for (i = n; i; i--) {
-                                               UEDATX = 0;
-                                       }
-                                       len -= n;
-                                       usb_send_in();
-                               } while (len || n == ENDPOINT0_SIZE);
-                               return;
-                       }
-               }
-       }
-       UECONX = (1<<STALLRQ) | (1<<EPEN);      // stall
+        if (wIndex == MOUSE_INTERFACE) {
+            if (bmRequestType == 0xA1) {
+                if (bRequest == HID_GET_REPORT) {
+                    if (wValue == HID_REPORT_INPUT) {
+                        usb_wait_in_ready();
+                        UEDATX = 0;
+                        UEDATX = 0;
+                        UEDATX = 0;
+                        UEDATX = 0;
+                        usb_send_in();
+                        return;
+                    }
+                    if (wValue == HID_REPORT_FEATURE) {
+                        usb_wait_in_ready();
+                        UEDATX = 0x05;
+                        usb_send_in();
+                        return;
+                    }
+                }
+                if (bRequest == HID_GET_PROTOCOL) {
+                    usb_wait_in_ready();
+                    UEDATX = usb_mouse_protocol;
+                    usb_send_in();
+                    return;
+                }
+            }
+            if (bmRequestType == 0x21) {
+                if (bRequest == HID_SET_PROTOCOL) {
+                    usb_mouse_protocol = wValue;
+                    usb_send_in();
+                    return;
+                }
+            }
+        }
+#endif
+        if (wIndex == DEBUG_INTERFACE) {
+            if (bRequest == HID_GET_REPORT && bmRequestType == 0xA1) {
+                len = wLength;
+                do {
+                    // wait for host ready for IN packet
+                    do {
+                        i = UEINTX;
+                    } while (!(i & ((1 << TXINI) | (1 << RXOUTI))));
+                    if (i & (1 << RXOUTI)) return;  // abort
+                    // send IN packet
+                    n = len < ENDPOINT0_SIZE ? len : ENDPOINT0_SIZE;
+                    for (i = n; i; i--) {
+                        UEDATX = 0;
+                    }
+                    len -= n;
+                    usb_send_in();
+                } while (len || n == ENDPOINT0_SIZE);
+                return;
+            }
+        }
+    }
+    UECONX = (1 << STALLRQ) | (1 << EPEN);  // stall
 }
index a195b671d03bb3c44a71008fb508a65a64e2fdf6..50654dccf7f5a9dabe1fc86a1fb3b4a6c5bfc5b2 100644 (file)
  */
 
 #ifndef USB_H
-#define  USB_H 1
+#define USB_H 1
 
 #include <stdint.h>
 #include <stdbool.h>
 #include <avr/io.h>
 
-
 extern bool remote_wakeup;
 extern bool suspend;
 
-void usb_init(void);                   // initialize everything
-uint8_t usb_configured(void);          // is the USB port configured
-void usb_remote_wakeup(void);
-
+void    usb_init(void);        // initialize everything
+uint8_t usb_configured(void);  // is the USB port configured
+void    usb_remote_wakeup(void);
 
-#define EP_TYPE_CONTROL                        0x00
-#define EP_TYPE_BULK_IN                        0x81
-#define EP_TYPE_BULK_OUT               0x80
-#define EP_TYPE_INTERRUPT_IN           0xC1
-#define EP_TYPE_INTERRUPT_OUT          0xC0
-#define EP_TYPE_ISOCHRONOUS_IN         0x41
-#define EP_TYPE_ISOCHRONOUS_OUT                0x40
+#define EP_TYPE_CONTROL 0x00
+#define EP_TYPE_BULK_IN 0x81
+#define EP_TYPE_BULK_OUT 0x80
+#define EP_TYPE_INTERRUPT_IN 0xC1
+#define EP_TYPE_INTERRUPT_OUT 0xC0
+#define EP_TYPE_ISOCHRONOUS_IN 0x41
+#define EP_TYPE_ISOCHRONOUS_OUT 0x40
 
-#define EP_SINGLE_BUFFER               0x02
-#define EP_DOUBLE_BUFFER               0x06
+#define EP_SINGLE_BUFFER 0x02
+#define EP_DOUBLE_BUFFER 0x06
 
-#define EP_SIZE(s)     ((s) == 64 ? 0x30 :     \
-                       ((s) == 32 ? 0x20 :     \
-                       ((s) == 16 ? 0x10 :     \
-                                    0x00)))
+#define EP_SIZE(s) ((s) == 64 ? 0x30 : ((s) == 32 ? 0x20 : ((s) == 16 ? 0x10 : 0x00)))
 
-#if defined (__AVR_AT90USB162__) || defined (__AVR_AT90USB82__)
-#   define MAX_ENDPOINT     4
-#   define UERST_MASK       0x1E
+#if defined(__AVR_AT90USB162__) || defined(__AVR_AT90USB82__)
+#    define MAX_ENDPOINT 4
+#    define UERST_MASK 0x1E
 #else
-#   define MAX_ENDPOINT     6
-#   define UERST_MASK       0x7E
+#    define MAX_ENDPOINT 6
+#    define UERST_MASK 0x7E
 #endif
 
 #define LSB(n) (n & 255)
 #define MSB(n) ((n >> 8) & 255)
 
 #if defined(__AVR_AT90USB162__)
-#define HW_CONFIG() 
-#define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
-#define USB_CONFIG() (USBCON = (1<<USBE))
-#define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
+#    define HW_CONFIG()
+#    define PLL_CONFIG() (PLLCSR = ((1 << PLLE) | (1 << PLLP0)))
+#    define USB_CONFIG() (USBCON = (1 << USBE))
+#    define USB_FREEZE() (USBCON = ((1 << USBE) | (1 << FRZCLK)))
 #elif defined(__AVR_ATmega32U4__)
-#define HW_CONFIG() (UHWCON = 0x01)
-#define PLL_CONFIG() (PLLCSR = 0x12)
-#define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
-#define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
+#    define HW_CONFIG() (UHWCON = 0x01)
+#    define PLL_CONFIG() (PLLCSR = 0x12)
+#    define USB_CONFIG() (USBCON = ((1 << USBE) | (1 << OTGPADE)))
+#    define USB_FREEZE() (USBCON = ((1 << USBE) | (1 << FRZCLK)))
 #elif defined(__AVR_AT90USB646__)
-#define HW_CONFIG() (UHWCON = 0x81)
-#define PLL_CONFIG() (PLLCSR = 0x1A)
-#define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
-#define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
+#    define HW_CONFIG() (UHWCON = 0x81)
+#    define PLL_CONFIG() (PLLCSR = 0x1A)
+#    define USB_CONFIG() (USBCON = ((1 << USBE) | (1 << OTGPADE)))
+#    define USB_FREEZE() (USBCON = ((1 << USBE) | (1 << FRZCLK)))
 #elif defined(__AVR_AT90USB1286__)
-#define HW_CONFIG() (UHWCON = 0x81)
-#define PLL_CONFIG() (PLLCSR = 0x16)
-#define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
-#define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
+#    define HW_CONFIG() (UHWCON = 0x81)
+#    define PLL_CONFIG() (PLLCSR = 0x16)
+#    define USB_CONFIG() (USBCON = ((1 << USBE) | (1 << OTGPADE)))
+#    define USB_FREEZE() (USBCON = ((1 << USBE) | (1 << FRZCLK)))
 #endif
 
 // standard control endpoint request types
-#define GET_STATUS                     0
-#define CLEAR_FEATURE                  1
-#define SET_FEATURE                    3
-#define SET_ADDRESS                    5
-#define GET_DESCRIPTOR                 6
-#define GET_CONFIGURATION              8
-#define SET_CONFIGURATION              9
-#define GET_INTERFACE                  10
-#define SET_INTERFACE                  11
+#define GET_STATUS 0
+#define CLEAR_FEATURE 1
+#define SET_FEATURE 3
+#define SET_ADDRESS 5
+#define GET_DESCRIPTOR 6
+#define GET_CONFIGURATION 8
+#define SET_CONFIGURATION 9
+#define GET_INTERFACE 10
+#define SET_INTERFACE 11
 // HID (human interface device)
-#define HID_GET_REPORT                 1
-#define HID_GET_IDLE                   2
-#define HID_GET_PROTOCOL               3
-#define HID_SET_REPORT                 9
-#define HID_SET_IDLE                   10
-#define HID_SET_PROTOCOL               11
-#define HID_REPORT_INPUT               1
-#define HID_REPORT_OUTPUT              2
-#define HID_REPORT_FEATURE             3
+#define HID_GET_REPORT 1
+#define HID_GET_IDLE 2
+#define HID_GET_PROTOCOL 3
+#define HID_SET_REPORT 9
+#define HID_SET_IDLE 10
+#define HID_SET_PROTOCOL 11
+#define HID_REPORT_INPUT 1
+#define HID_REPORT_OUTPUT 2
+#define HID_REPORT_FEATURE 3
 // CDC (communication class device)
-#define CDC_SET_LINE_CODING            0x20
-#define CDC_GET_LINE_CODING            0x21
-#define CDC_SET_CONTROL_LINE_STATE     0x22
+#define CDC_SET_LINE_CODING 0x20
+#define CDC_GET_LINE_CODING 0x21
+#define CDC_SET_CONTROL_LINE_STATE 0x22
 // HID feature selectors
-#define DEVICE_REMOTE_WAKEUP           1
-#define ENDPOINT_HALT                  0
-#define TEST_MODE                      2
-
+#define DEVICE_REMOTE_WAKEUP 1
+#define ENDPOINT_HALT 0
+#define TEST_MODE 2
 
 /*------------------------------------------------------------------*
  * Keyboard descriptor setting
  *------------------------------------------------------------------*/
-#define KBD_INTERFACE          0
-#define KBD_ENDPOINT           1
-#define KBD_SIZE               8
-#define KBD_BUFFER             EP_SINGLE_BUFFER
-#define KBD_REPORT_KEYS                (KBD_SIZE - 2)
+#define KBD_INTERFACE 0
+#define KBD_ENDPOINT 1
+#define KBD_SIZE 8
+#define KBD_BUFFER EP_SINGLE_BUFFER
+#define KBD_REPORT_KEYS (KBD_SIZE - 2)
 
 // secondary keyboard
 #ifdef NKRO_ENABLE
-#define KBD2_INTERFACE         4
-#define KBD2_ENDPOINT          5
-#define KBD2_SIZE              16
-#define KBD2_BUFFER            EP_DOUBLE_BUFFER
-#define KBD2_REPORT_KEYS       (KBD2_SIZE - 1)
+#    define KBD2_INTERFACE 4
+#    define KBD2_ENDPOINT 5
+#    define KBD2_SIZE 16
+#    define KBD2_BUFFER EP_DOUBLE_BUFFER
+#    define KBD2_REPORT_KEYS (KBD2_SIZE - 1)
 #endif
 
 #endif
index c1e6f6544b92bcecec5e5938d95383ff64a18147..7e78d96c350356e9264e131d38f9921699ae0a8f 100644 (file)
 #include "sendchar.h"
 #include "usb_debug.h"
 
-
 // the time remaining before we transmit any partially full
 // packet, or send a zero length packet.
-volatile uint8_t debug_flush_timer=0;
-
+volatile uint8_t debug_flush_timer = 0;
 
-int8_t sendchar(uint8_t c)
-{
-       static uint8_t previous_timeout=0;
-       uint8_t timeout, intr_state;
+int8_t sendchar(uint8_t c) {
+    static uint8_t previous_timeout = 0;
+    uint8_t        timeout, intr_state;
 
-       // if we're not online (enumerated and configured), error
-       if (!usb_configured()) return -1;
-       // interrupts are disabled so these functions can be
-       // used from the main program or interrupt context,
-       // even both in the same program!
-       intr_state = SREG;
-       cli();
-       UENUM = DEBUG_TX_ENDPOINT;
-       // if we gave up due to timeout before, don't wait again
-       if (previous_timeout) {
-               if (!(UEINTX & (1<<RWAL))) {
-                       SREG = intr_state;
-                       return -1;
-               }
-               previous_timeout = 0;
-       }
-       // wait for the FIFO to be ready to accept data
-       timeout = UDFNUML + 4;
-       while (1) {
-               // are we ready to transmit?
-               if (UEINTX & (1<<RWAL)) break;
-               SREG = intr_state;
-               // have we waited too long?
-               if (UDFNUML == timeout) {
-                       previous_timeout = 1;
-                       return -1;
-               }
-               // has the USB gone offline?
-               if (!usb_configured()) return -1;
-               // get ready to try checking again
-               intr_state = SREG;
-               cli();
-               UENUM = DEBUG_TX_ENDPOINT;
-       }
-       // actually write the byte into the FIFO
-       UEDATX = c;
-       // if this completed a packet, transmit it now!
-       if (!(UEINTX & (1<<RWAL))) {
-               UEINTX = 0x3A;
-               debug_flush_timer = 0;
-       } else {
-               debug_flush_timer = 2;
-       }
-       SREG = intr_state;
-       return 0;
+    // if we're not online (enumerated and configured), error
+    if (!usb_configured()) return -1;
+    // interrupts are disabled so these functions can be
+    // used from the main program or interrupt context,
+    // even both in the same program!
+    intr_state = SREG;
+    cli();
+    UENUM = DEBUG_TX_ENDPOINT;
+    // if we gave up due to timeout before, don't wait again
+    if (previous_timeout) {
+        if (!(UEINTX & (1 << RWAL))) {
+            SREG = intr_state;
+            return -1;
+        }
+        previous_timeout = 0;
+    }
+    // wait for the FIFO to be ready to accept data
+    timeout = UDFNUML + 4;
+    while (1) {
+        // are we ready to transmit?
+        if (UEINTX & (1 << RWAL)) break;
+        SREG = intr_state;
+        // have we waited too long?
+        if (UDFNUML == timeout) {
+            previous_timeout = 1;
+            return -1;
+        }
+        // has the USB gone offline?
+        if (!usb_configured()) return -1;
+        // get ready to try checking again
+        intr_state = SREG;
+        cli();
+        UENUM = DEBUG_TX_ENDPOINT;
+    }
+    // actually write the byte into the FIFO
+    UEDATX = c;
+    // if this completed a packet, transmit it now!
+    if (!(UEINTX & (1 << RWAL))) {
+        UEINTX            = 0x3A;
+        debug_flush_timer = 0;
+    } else {
+        debug_flush_timer = 2;
+    }
+    SREG = intr_state;
+    return 0;
 }
 
 // immediately transmit any buffered output.
-void usb_debug_flush_output(void)
-{
-       uint8_t intr_state;
+void usb_debug_flush_output(void) {
+    uint8_t intr_state;
 
-       intr_state = SREG;
-       cli();
-       if (debug_flush_timer) {
-               UENUM = DEBUG_TX_ENDPOINT;
-               while ((UEINTX & (1<<RWAL))) {
-                       UEDATX = 0;
-               }
-               UEINTX = 0x3A;
-               debug_flush_timer = 0;
-       }
-       SREG = intr_state;
+    intr_state = SREG;
+    cli();
+    if (debug_flush_timer) {
+        UENUM = DEBUG_TX_ENDPOINT;
+        while ((UEINTX & (1 << RWAL))) {
+            UEDATX = 0;
+        }
+        UEINTX            = 0x3A;
+        debug_flush_timer = 0;
+    }
+    SREG = intr_state;
 }
index e70f4ca3a7be2ea26d63dd9a7c9f4db03f39c844..efe075fa97d0b2b7490c82a297889ef9daaa4d1b 100644 (file)
  */
 
 #ifndef USB_DEBUG_H
-#define  USB_DEBUG_H 1
+#define USB_DEBUG_H 1
 
 #include <stdint.h>
 #include "usb.h"
 
-
-#define DEBUG_INTERFACE                2
-#define DEBUG_TX_ENDPOINT      3
-#define DEBUG_TX_SIZE          32
-#define DEBUG_TX_BUFFER                EP_DOUBLE_BUFFER
-
+#define DEBUG_INTERFACE 2
+#define DEBUG_TX_ENDPOINT 3
+#define DEBUG_TX_SIZE 32
+#define DEBUG_TX_BUFFER EP_DOUBLE_BUFFER
 
 extern volatile uint8_t debug_flush_timer;
 
-
-void usb_debug_flush_output(void);     // immediately transmit any buffered output
+void usb_debug_flush_output(void);  // immediately transmit any buffered output
 
 #endif
index fe1f422c0d2b5e4f5ddc003653e97ba24fff343d..1745e651c7ef0ea973864e653a9c9a2b2e528f67 100644 (file)
 #include "host.h"
 #include "usb_extra.h"
 
-
-int8_t usb_extra_send(uint8_t report_id, uint16_t data)
-{
-       uint8_t intr_state, timeout;
-
-       if (!usb_configured()) return -1;
-       intr_state = SREG;
-       cli();
-       UENUM = EXTRA_ENDPOINT;
-       timeout = UDFNUML + 50;
-       while (1) {
-               // are we ready to transmit?
-               if (UEINTX & (1<<RWAL)) break;
-               SREG = intr_state;
-               // has the USB gone offline?
-               if (!usb_configured()) return -1;
-               // have we waited too long?
-               if (UDFNUML == timeout) return -1;
-               // get ready to try checking again
-               intr_state = SREG;
-               cli();
-               UENUM = EXTRA_ENDPOINT;
-       }
-
-       UEDATX = report_id;
-        UEDATX = data&0xFF;
-        UEDATX = (data>>8)&0xFF;
-
-       UEINTX = 0x3A;
-       SREG = intr_state;
-       return 0;
+int8_t usb_extra_send(uint8_t report_id, uint16_t data) {
+    uint8_t intr_state, timeout;
+
+    if (!usb_configured()) return -1;
+    intr_state = SREG;
+    cli();
+    UENUM   = EXTRA_ENDPOINT;
+    timeout = UDFNUML + 50;
+    while (1) {
+        // are we ready to transmit?
+        if (UEINTX & (1 << RWAL)) break;
+        SREG = intr_state;
+        // has the USB gone offline?
+        if (!usb_configured()) return -1;
+        // have we waited too long?
+        if (UDFNUML == timeout) return -1;
+        // get ready to try checking again
+        intr_state = SREG;
+        cli();
+        UENUM = EXTRA_ENDPOINT;
+    }
+
+    UEDATX = report_id;
+    UEDATX = data & 0xFF;
+    UEDATX = (data >> 8) & 0xFF;
+
+    UEINTX = 0x3A;
+    SREG   = intr_state;
+    return 0;
 }
 
-int8_t usb_extra_consumer_send(uint16_t bits)
-{
-       return usb_extra_send(REPORT_ID_CONSUMER, bits);
-}
+int8_t usb_extra_consumer_send(uint16_t bits) { return usb_extra_send(REPORT_ID_CONSUMER, bits); }
 
-int8_t usb_extra_system_send(uint16_t bits)
-{
-       return usb_extra_send(REPORT_ID_SYSTEM, bits);
-}
+int8_t usb_extra_system_send(uint16_t bits) { return usb_extra_send(REPORT_ID_SYSTEM, bits); }
index 042ac48373156a1e41993f145255f7e522b24565..674d582ac2c8d38252c19889da9c807ab76f72e3 100644 (file)
@@ -22,7 +22,7 @@
  */
 
 #ifndef USB_EXTRA_H
-#define  USB_EXTRA_H 1
+#define USB_EXTRA_H 1
 /*
  * Enhanced keyboard features for Windows:
  * Audio control and System control
 #include <stdint.h>
 #include "usb.h"
 
-
-#define EXTRA_INTERFACE                3
-#define EXTRA_ENDPOINT         4
-#define EXTRA_SIZE             8
-#define EXTRA_BUFFER           EP_DOUBLE_BUFFER
-
+#define EXTRA_INTERFACE 3
+#define EXTRA_ENDPOINT 4
+#define EXTRA_SIZE 8
+#define EXTRA_BUFFER EP_DOUBLE_BUFFER
 
 int8_t usb_extra_consumer_send(uint16_t bits);
 int8_t usb_extra_system_send(uint16_t bits);
index 05f4797340df3a63d81bb51d4fafa1fa936aeab1..31856d0fda14d7a7711e72cf5cea80c8dfbbb507 100644 (file)
 #include "host.h"
 
 #ifdef NKRO_ENABLE
-  #include "keycode_config.h"
+#    include "keycode_config.h"
 
-  extern keymap_config_t keymap_config;
+extern keymap_config_t keymap_config;
 #endif
 
-
 // protocol setting from the host.  We use exactly the same report
 // either way, so this variable only stores the setting since we
 // are required to be able to report which setting is in use.
-uint8_t keyboard_protocol=1;
+uint8_t keyboard_protocol = 1;
 
 // the idle configuration, how often we send the report to the
 // host (ms * 4) even when it hasn't changed
 // Windows and Linux set 0 while OS X sets 6(24ms) by SET_IDLE request.
-uint8_t keyboard_idle=125;
+uint8_t keyboard_idle = 125;
 
 // count until idle timeout
-uint8_t usb_keyboard_idle_count=0;
+uint8_t usb_keyboard_idle_count = 0;
 
 // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana
-volatile uint8_t usb_keyboard_leds=0;
-
+volatile uint8_t usb_keyboard_leds = 0;
 
 static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, uint8_t keys_start, uint8_t keys_end);
 
-
-int8_t usb_keyboard_send_report(report_keyboard_t *report)
-{
+int8_t usb_keyboard_send_report(report_keyboard_t *report) {
     int8_t result = 0;
 
 #ifdef NKRO_ENABLE
@@ -76,41 +72,43 @@ int8_t usb_keyboard_send_report(report_keyboard_t *report)
     return 0;
 }
 
-void usb_keyboard_print_report(report_keyboard_t *report)
-{
+void usb_keyboard_print_report(report_keyboard_t *report) {
     if (!debug_keyboard) return;
     print("keys: ");
-    for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) { phex(report->keys[i]); print(" "); }
-    print(" mods: "); phex(report->mods); print("\n");
+    for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
+        phex(report->keys[i]);
+        print(" ");
+    }
+    print(" mods: ");
+    phex(report->mods);
+    print("\n");
 }
 
-
-static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, uint8_t keys_start, uint8_t keys_end)
-{
+static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, uint8_t keys_start, uint8_t keys_end) {
     uint8_t intr_state, timeout;
 
     if (!usb_configured()) return -1;
     intr_state = SREG;
     cli();
-    UENUM = endpoint;
+    UENUM   = endpoint;
     timeout = UDFNUML + 50;
     while (1) {
-            // are we ready to transmit?
-            if (UEINTX & (1<<RWAL)) break;
-            SREG = intr_state;
-            // has the USB gone offline?
-            if (!usb_configured()) return -1;
-            // have we waited too long?
-            if (UDFNUML == timeout) return -1;
-            // get ready to try checking again
-            intr_state = SREG;
-            cli();
-            UENUM = endpoint;
+        // are we ready to transmit?
+        if (UEINTX & (1 << RWAL)) break;
+        SREG = intr_state;
+        // has the USB gone offline?
+        if (!usb_configured()) return -1;
+        // have we waited too long?
+        if (UDFNUML == timeout) return -1;
+        // get ready to try checking again
+        intr_state = SREG;
+        cli();
+        UENUM = endpoint;
     }
     for (uint8_t i = keys_start; i < keys_end; i++) {
-            UEDATX = report->raw[i];
+        UEDATX = report->raw[i];
     }
     UEINTX = 0x3A;
-    SREG = intr_state;
+    SREG   = intr_state;
     return 0;
 }
index 9b798e9a864eee6df01ac5a4e325453857dc015a..919685fde4b8b355f29060dea5fd74b32b5c20d5 100644 (file)
  */
 
 #ifndef USB_KEYBOARD_H
-#define  USB_KEYBOARD_H 1
+#define USB_KEYBOARD_H 1
 
 #include <stdint.h>
 #include <stdbool.h>
 #include "usb.h"
 #include "host.h"
 
-
-extern uint8_t usb_keyboard_idle_count;
+extern uint8_t          usb_keyboard_idle_count;
 extern volatile uint8_t usb_keyboard_leds;
 
-
 int8_t usb_keyboard_send_report(report_keyboard_t *report);
-void usb_keyboard_print_report(report_keyboard_t *report);
+void   usb_keyboard_print_report(report_keyboard_t *report);
 
 #endif
index d81db756f37d3b5acd53d6b8f393c98e0f5ce8cb..9e3639571c130cb4f8b730677f6d6c36ea737709 100644 (file)
 #include "print.h"
 #include "debug.h"
 
+uint8_t usb_mouse_protocol = 1;
 
-uint8_t usb_mouse_protocol=1;
+int8_t usb_mouse_send(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons) {
+    uint8_t intr_state, timeout;
 
+    if (!usb_configured()) return -1;
+    if (x == -128) x = -127;
+    if (y == -128) y = -127;
+    if (wheel_v == -128) wheel_v = -127;
+    if (wheel_h == -128) wheel_h = -127;
+    intr_state = SREG;
+    cli();
+    UENUM   = MOUSE_ENDPOINT;
+    timeout = UDFNUML + 50;
+    while (1) {
+        // are we ready to transmit?
+        if (UEINTX & (1 << RWAL)) break;
+        SREG = intr_state;
+        // has the USB gone offline?
+        if (!usb_configured()) return -1;
+        // have we waited too long?
+        if (UDFNUML == timeout) return -1;
+        // get ready to try checking again
+        intr_state = SREG;
+        cli();
+        UENUM = MOUSE_ENDPOINT;
+    }
+    UEDATX = buttons;
+    UEDATX = x;
+    UEDATX = y;
+    if (usb_mouse_protocol) {
+        UEDATX = wheel_v;
+        UEDATX = wheel_h;
+    }
 
-int8_t usb_mouse_send(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons)
-{
-       uint8_t intr_state, timeout;
-
-       if (!usb_configured()) return -1;
-       if (x == -128) x = -127;
-       if (y == -128) y = -127;
-       if (wheel_v == -128) wheel_v = -127;
-       if (wheel_h == -128) wheel_h = -127;
-       intr_state = SREG;
-       cli();
-       UENUM = MOUSE_ENDPOINT;
-       timeout = UDFNUML + 50;
-       while (1) {
-               // are we ready to transmit?
-               if (UEINTX & (1<<RWAL)) break;
-               SREG = intr_state;
-               // has the USB gone offline?
-               if (!usb_configured()) return -1;
-               // have we waited too long?
-               if (UDFNUML == timeout) return -1;
-               // get ready to try checking again
-               intr_state = SREG;
-               cli();
-               UENUM = MOUSE_ENDPOINT;
-       }
-       UEDATX = buttons;
-       UEDATX = x;
-       UEDATX = y;
-        if (usb_mouse_protocol) {
-            UEDATX = wheel_v;
-            UEDATX = wheel_h;
-        }
-        
-       UEINTX = 0x3A;
-       SREG = intr_state;
-       return 0;
+    UEINTX = 0x3A;
+    SREG   = intr_state;
+    return 0;
 }
 
 void usb_mouse_print(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons) {
     if (!debug_mouse) return;
     print("usb_mouse[btn|x y v h]: ");
-    phex(buttons); print("|");
-    phex(x); print(" ");
-    phex(y); print(" ");
-    phex(wheel_v); print(" ");
-    phex(wheel_h); print("\n");
+    phex(buttons);
+    print("|");
+    phex(x);
+    print(" ");
+    phex(y);
+    print(" ");
+    phex(wheel_v);
+    print(" ");
+    phex(wheel_h);
+    print("\n");
 }
index ce26887c9b2247abeb85f77ee3cff49dc9203e3c..ba7df230de70a3dd244e7fbf57616af4f01790cf 100644 (file)
  */
 
 #ifndef USB_MOUSE_H
-#define  USB_MOUSE_H 1
+#define USB_MOUSE_H 1
 
 #include <stdint.h>
 #include <stdbool.h>
 #include "usb.h"
 
+#define MOUSE_INTERFACE 1
+#define MOUSE_ENDPOINT 2
+#define MOUSE_SIZE 8
+#define MOUSE_BUFFER EP_SINGLE_BUFFER
 
-#define MOUSE_INTERFACE                1
-#define MOUSE_ENDPOINT         2
-#define MOUSE_SIZE             8
-#define MOUSE_BUFFER           EP_SINGLE_BUFFER
-
-#define MOUSE_BTN1 (1<<0)
-#define MOUSE_BTN2 (1<<1)
-#define MOUSE_BTN3 (1<<2)
-#define MOUSE_BTN4 (1<<3)
-#define MOUSE_BTN5 (1<<4)
-
+#define MOUSE_BTN1 (1 << 0)
+#define MOUSE_BTN2 (1 << 1)
+#define MOUSE_BTN3 (1 << 2)
+#define MOUSE_BTN4 (1 << 3)
+#define MOUSE_BTN5 (1 << 4)
 
 extern uint8_t usb_mouse_protocol;
 
-
 int8_t usb_mouse_send(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons);
-void usb_mouse_print(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons);
+void   usb_mouse_print(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons);
 
 #endif
index acde679cf42352fc4c7750bfdbf33ae77c5b19d0..e32cc9603f20d4648462aa73e4f69e713182f371 100644 (file)
@@ -67,66 +67,74 @@ POSSIBILITY OF SUCH DAMAGE.
  * [5] TrackPoint Engineering Specifications for version 3E
  * https://web.archive.org/web/20100526161812/http://wwwcssrv.almaden.ibm.com/trackpoint/download.html
  */
-#define PS2_ACK         0xFA
-#define PS2_RESEND      0xFE
-#define PS2_SET_LED     0xED
+#define PS2_ACK 0xFA
+#define PS2_RESEND 0xFE
+#define PS2_SET_LED 0xED
 
 // TODO: error numbers
-#define PS2_ERR_NONE        0
-#define PS2_ERR_STARTBIT1   1
-#define PS2_ERR_STARTBIT2   2
-#define PS2_ERR_STARTBIT3   3
-#define PS2_ERR_PARITY      0x10
-#define PS2_ERR_NODATA      0x20
+#define PS2_ERR_NONE 0
+#define PS2_ERR_STARTBIT1 1
+#define PS2_ERR_STARTBIT2 2
+#define PS2_ERR_STARTBIT3 3
+#define PS2_ERR_PARITY 0x10
+#define PS2_ERR_NODATA 0x20
 
 #define PS2_LED_SCROLL_LOCK 0
-#define PS2_LED_NUM_LOCK    1
-#define PS2_LED_CAPS_LOCK   2
-
+#define PS2_LED_NUM_LOCK 1
+#define PS2_LED_CAPS_LOCK 2
 
 extern uint8_t ps2_error;
 
-void ps2_host_init(void);
+void    ps2_host_init(void);
 uint8_t ps2_host_send(uint8_t data);
 uint8_t ps2_host_recv_response(void);
 uint8_t ps2_host_recv(void);
-void ps2_host_set_led(uint8_t usb_led);
-
+void    ps2_host_set_led(uint8_t usb_led);
 
 /*--------------------------------------------------------------------
  * static functions
  *------------------------------------------------------------------*/
-static inline uint16_t wait_clock_lo(uint16_t us)
-{
-    while (clock_in()  && us) { asm(""); wait_us(1); us--; }
+static inline uint16_t wait_clock_lo(uint16_t us) {
+    while (clock_in() && us) {
+        asm("");
+        wait_us(1);
+        us--;
+    }
     return us;
 }
-static inline uint16_t wait_clock_hi(uint16_t us)
-{
-    while (!clock_in() && us) { asm(""); wait_us(1); us--; }
+static inline uint16_t wait_clock_hi(uint16_t us) {
+    while (!clock_in() && us) {
+        asm("");
+        wait_us(1);
+        us--;
+    }
     return us;
 }
-static inline uint16_t wait_data_lo(uint16_t us)
-{
-    while (data_in() && us)  { asm(""); wait_us(1); us--; }
+static inline uint16_t wait_data_lo(uint16_t us) {
+    while (data_in() && us) {
+        asm("");
+        wait_us(1);
+        us--;
+    }
     return us;
 }
-static inline uint16_t wait_data_hi(uint16_t us)
-{
-    while (!data_in() && us)  { asm(""); wait_us(1); us--; }
+static inline uint16_t wait_data_hi(uint16_t us) {
+    while (!data_in() && us) {
+        asm("");
+        wait_us(1);
+        us--;
+    }
     return us;
 }
 
 /* idle state that device can send */
-static inline void idle(void)
-{
+static inline void idle(void) {
     clock_hi();
     data_hi();
 }
 
 /* inhibit device to send */
-static inline void inhibit(void)
-{
+static inline void inhibit(void) {
     clock_lo();
     data_hi();
 }
index a64933219ec96e1b48d4f30edf5eb60191306a31..983194eea84d7725b02fd96e4604e93d16835129 100644 (file)
@@ -45,20 +45,17 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "ps2_io.h"
 #include "debug.h"
 
-
-#define WAIT(stat, us, err) do { \
-    if (!wait_##stat(us)) { \
-        ps2_error = err; \
-        goto ERROR; \
-    } \
-} while (0)
-
+#define WAIT(stat, us, err)     \
+    do {                        \
+        if (!wait_##stat(us)) { \
+            ps2_error = err;    \
+            goto ERROR;         \
+        }                       \
+    } while (0)
 
 uint8_t ps2_error = PS2_ERR_NONE;
 
-
-void ps2_host_init(void)
-{
+void ps2_host_init(void) {
     clock_init();
     data_init();
 
@@ -68,24 +65,23 @@ void ps2_host_init(void)
     inhibit();
 }
 
-uint8_t ps2_host_send(uint8_t data)
-{
+uint8_t ps2_host_send(uint8_t data) {
     bool parity = true;
-    ps2_error = PS2_ERR_NONE;
+    ps2_error   = PS2_ERR_NONE;
 
     /* terminate a transmission if we have */
     inhibit();
-    wait_us(100); // 100us [4]p.13, [5]p.50
+    wait_us(100);  // 100us [4]p.13, [5]p.50
 
     /* 'Request to Send' and Start bit */
     data_lo();
     clock_hi();
-    WAIT(clock_lo, 10000, 10);   // 10ms [5]p.50
+    WAIT(clock_lo, 10000, 10);  // 10ms [5]p.50
 
     /* Data bit */
     for (uint8_t i = 0; i < 8; i++) {
         wait_us(15);
-        if (data&(1<<i)) {
+        if (data & (1 << i)) {
             parity = !parity;
             data_hi();
         } else {
@@ -97,7 +93,11 @@ uint8_t ps2_host_send(uint8_t data)
 
     /* Parity bit */
     wait_us(15);
-    if (parity) { data_hi(); } else { data_lo(); }
+    if (parity) {
+        data_hi();
+    } else {
+        data_lo();
+    }
     WAIT(clock_hi, 50, 4);
     WAIT(clock_lo, 50, 5);
 
@@ -121,30 +121,29 @@ ERROR:
 }
 
 /* receive data when host want else inhibit communication */
-uint8_t ps2_host_recv_response(void)
-{
+uint8_t ps2_host_recv_response(void) {
     // Command may take 25ms/20ms at most([5]p.46, [3]p.21)
     // 250 * 100us(wait for start bit in ps2_host_recv)
     uint8_t data = 0;
-    uint8_t try = 250;
+    uint8_t try
+        = 250;
     do {
         data = ps2_host_recv();
-    } while (try-- && ps2_error);
+    } while (try --&&ps2_error);
     return data;
 }
 
 /* called after start bit comes */
-uint8_t ps2_host_recv(void)
-{
-    uint8_t data = 0;
-    bool parity = true;
-    ps2_error = PS2_ERR_NONE;
+uint8_t ps2_host_recv(void) {
+    uint8_t data   = 0;
+    bool    parity = true;
+    ps2_error      = PS2_ERR_NONE;
 
     /* release lines(idle state) */
     idle();
 
     /* start bit [1] */
-    WAIT(clock_lo, 100, 1); // TODO: this is enough?
+    WAIT(clock_lo, 100, 1);  // TODO: this is enough?
     WAIT(data_lo, 1, 2);
     WAIT(clock_hi, 50, 3);
 
@@ -153,7 +152,7 @@ uint8_t ps2_host_recv(void)
         WAIT(clock_lo, 50, 4);
         if (data_in()) {
             parity = !parity;
-            data |= (1<<i);
+            data |= (1 << i);
         }
         WAIT(clock_hi, 50, 5);
     }
@@ -182,8 +181,7 @@ ERROR:
 }
 
 /* send LED state to keyboard */
-void ps2_host_set_led(uint8_t led)
-{
+void ps2_host_set_led(uint8_t led) {
     ps2_host_send(0xED);
     ps2_host_send(led);
 }
index 8114442bac663667f82dfbf78580b4069d381510..5afc8a82e471a38498b2f87ad2cb445df091f321 100644 (file)
@@ -46,26 +46,22 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "ps2_io.h"
 #include "print.h"
 
-
-#define WAIT(stat, us, err) do { \
-    if (!wait_##stat(us)) { \
-        ps2_error = err; \
-        goto ERROR; \
-    } \
-} while (0)
-
+#define WAIT(stat, us, err)     \
+    do {                        \
+        if (!wait_##stat(us)) { \
+            ps2_error = err;    \
+            goto ERROR;         \
+        }                       \
+    } while (0)
 
 uint8_t ps2_error = PS2_ERR_NONE;
 
-
 static inline uint8_t pbuf_dequeue(void);
-static inline void pbuf_enqueue(uint8_t data);
-static inline bool pbuf_has_data(void);
-static inline void pbuf_clear(void);
+static inline void    pbuf_enqueue(uint8_t data);
+static inline bool    pbuf_has_data(void);
+static inline void    pbuf_clear(void);
 
-
-void ps2_host_init(void)
-{
+void ps2_host_init(void) {
     idle();
     PS2_INT_INIT();
     PS2_INT_ON();
@@ -73,26 +69,25 @@ void ps2_host_init(void)
     //_delay_ms(2500);
 }
 
-uint8_t ps2_host_send(uint8_t data)
-{
+uint8_t ps2_host_send(uint8_t data) {
     bool parity = true;
-    ps2_error = PS2_ERR_NONE;
+    ps2_error   = PS2_ERR_NONE;
 
     PS2_INT_OFF();
 
     /* terminate a transmission if we have */
     inhibit();
-    _delay_us(100); // 100us [4]p.13, [5]p.50
+    _delay_us(100);  // 100us [4]p.13, [5]p.50
 
     /* 'Request to Send' and Start bit */
     data_lo();
     clock_hi();
-    WAIT(clock_lo, 10000, 10);   // 10ms [5]p.50
+    WAIT(clock_lo, 10000, 10);  // 10ms [5]p.50
 
     /* Data bit[2-9] */
     for (uint8_t i = 0; i < 8; i++) {
         _delay_us(15);
-        if (data&(1<<i)) {
+        if (data & (1 << i)) {
             parity = !parity;
             data_hi();
         } else {
@@ -104,7 +99,11 @@ uint8_t ps2_host_send(uint8_t data)
 
     /* Parity bit */
     _delay_us(15);
-    if (parity) { data_hi(); } else { data_lo(); }
+    if (parity) {
+        data_hi();
+    } else {
+        data_lo();
+    }
     WAIT(clock_hi, 50, 4);
     WAIT(clock_lo, 50, 5);
 
@@ -129,8 +128,7 @@ ERROR:
     return 0;
 }
 
-uint8_t ps2_host_recv_response(void)
-{
+uint8_t ps2_host_recv_response(void) {
     // Command may take 25ms/20ms at most([5]p.46, [3]p.21)
     uint8_t retry = 25;
     while (retry-- && !pbuf_has_data()) {
@@ -140,8 +138,7 @@ uint8_t ps2_host_recv_response(void)
 }
 
 /* get data received by interrupt */
-uint8_t ps2_host_recv(void)
-{
+uint8_t ps2_host_recv(void) {
     if (pbuf_has_data()) {
         ps2_error = PS2_ERR_NONE;
         return pbuf_dequeue();
@@ -151,16 +148,22 @@ uint8_t ps2_host_recv(void)
     }
 }
 
-ISR(PS2_INT_VECT)
-{
+ISR(PS2_INT_VECT) {
     static enum {
         INIT,
         START,
-        BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7,
+        BIT0,
+        BIT1,
+        BIT2,
+        BIT3,
+        BIT4,
+        BIT5,
+        BIT6,
+        BIT7,
         PARITY,
         STOP,
-    } state = INIT;
-    static uint8_t data = 0;
+    } state               = INIT;
+    static uint8_t data   = 0;
     static uint8_t parity = 1;
 
     // TODO: abort if elapse 100us from previous interrupt
@@ -173,8 +176,7 @@ ISR(PS2_INT_VECT)
     state++;
     switch (state) {
         case START:
-            if (data_in())
-                goto ERROR;
+            if (data_in()) goto ERROR;
             break;
         case BIT0:
         case BIT1:
@@ -192,16 +194,13 @@ ISR(PS2_INT_VECT)
             break;
         case PARITY:
             if (data_in()) {
-                if (!(parity & 0x01))
-                    goto ERROR;
+                if (!(parity & 0x01)) goto ERROR;
             } else {
-                if (parity & 0x01)
-                    goto ERROR;
+                if (parity & 0x01) goto ERROR;
             }
             break;
         case STOP:
-            if (!data_in())
-                goto ERROR;
+            if (!data_in()) goto ERROR;
             pbuf_enqueue(data);
             goto DONE;
             break;
@@ -212,68 +211,61 @@ ISR(PS2_INT_VECT)
 ERROR:
     ps2_error = state;
 DONE:
-    state = INIT;
-    data = 0;
+    state  = INIT;
+    data   = 0;
     parity = 1;
 RETURN:
     return;
 }
 
 /* send LED state to keyboard */
-void ps2_host_set_led(uint8_t led)
-{
+void ps2_host_set_led(uint8_t led) {
     ps2_host_send(0xED);
     ps2_host_send(led);
 }
 
-
 /*--------------------------------------------------------------------
  * Ring buffer to store scan codes from keyboard
  *------------------------------------------------------------------*/
 #define PBUF_SIZE 32
-static uint8_t pbuf[PBUF_SIZE];
-static uint8_t pbuf_head = 0;
-static uint8_t pbuf_tail = 0;
-static inline void pbuf_enqueue(uint8_t data)
-{
+static uint8_t     pbuf[PBUF_SIZE];
+static uint8_t     pbuf_head = 0;
+static uint8_t     pbuf_tail = 0;
+static inline void pbuf_enqueue(uint8_t data) {
     uint8_t sreg = SREG;
     cli();
     uint8_t next = (pbuf_head + 1) % PBUF_SIZE;
     if (next != pbuf_tail) {
         pbuf[pbuf_head] = data;
-        pbuf_head = next;
+        pbuf_head       = next;
     } else {
         print("pbuf: full\n");
     }
     SREG = sreg;
 }
-static inline uint8_t pbuf_dequeue(void)
-{
+static inline uint8_t pbuf_dequeue(void) {
     uint8_t val = 0;
 
     uint8_t sreg = SREG;
     cli();
     if (pbuf_head != pbuf_tail) {
-        val = pbuf[pbuf_tail];
+        val       = pbuf[pbuf_tail];
         pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE;
     }
     SREG = sreg;
 
     return val;
 }
-static inline bool pbuf_has_data(void)
-{
+static inline bool pbuf_has_data(void) {
     uint8_t sreg = SREG;
     cli();
     bool has_data = (pbuf_head != pbuf_tail);
-    SREG = sreg;
+    SREG          = sreg;
     return has_data;
 }
-static inline void pbuf_clear(void)
-{
+static inline void pbuf_clear(void) {
     uint8_t sreg = SREG;
     cli();
     pbuf_head = pbuf_tail = 0;
-    SREG = sreg;
+    SREG                  = sreg;
 }
-
index a46a358e7cd7bc8e105d074337f4a919b82f4bd0..35e26561d41be07e502b6dbe5cf71ba529a35281 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef PS2_IO_H
 #define PS2_IO_H
 
-
 void clock_init(void);
 void clock_lo(void);
 void clock_hi(void);
index ed462345baf1e11648290af78218c718fbbf16c9..a9ac5d338d9bef39324dc14e5d7825125da7db94 100644 (file)
@@ -3,73 +3,56 @@
 #include <util/delay.h>
 
 /* Check port settings for clock and data line */
-#if !(defined(PS2_CLOCK_PORT) && \
-      defined(PS2_CLOCK_PIN) && \
-      defined(PS2_CLOCK_DDR) && \
-      defined(PS2_CLOCK_BIT))
-#   error "PS/2 clock port setting is required in config.h"
+#if !(defined(PS2_CLOCK_PORT) && defined(PS2_CLOCK_PIN) && defined(PS2_CLOCK_DDR) && defined(PS2_CLOCK_BIT))
+#    error "PS/2 clock port setting is required in config.h"
 #endif
 
-#if !(defined(PS2_DATA_PORT) && \
-      defined(PS2_DATA_PIN) && \
-      defined(PS2_DATA_DDR) && \
-      defined(PS2_DATA_BIT))
-#   error "PS/2 data port setting is required in config.h"
+#if !(defined(PS2_DATA_PORT) && defined(PS2_DATA_PIN) && defined(PS2_DATA_DDR) && defined(PS2_DATA_BIT))
+#    error "PS/2 data port setting is required in config.h"
 #endif
 
-
 /*
  * Clock
  */
-void clock_init(void)
-{
-}
+void clock_init(void) {}
 
-void clock_lo(void)
-{
-    PS2_CLOCK_PORT &= ~(1<<PS2_CLOCK_BIT);
-    PS2_CLOCK_DDR  |=  (1<<PS2_CLOCK_BIT);
+void clock_lo(void) {
+    PS2_CLOCK_PORT &= ~(1 << PS2_CLOCK_BIT);
+    PS2_CLOCK_DDR |= (1 << PS2_CLOCK_BIT);
 }
 
-void clock_hi(void)
-{
+void clock_hi(void) {
     /* input with pull up */
-    PS2_CLOCK_DDR  &= ~(1<<PS2_CLOCK_BIT);
-    PS2_CLOCK_PORT |=  (1<<PS2_CLOCK_BIT);
+    PS2_CLOCK_DDR &= ~(1 << PS2_CLOCK_BIT);
+    PS2_CLOCK_PORT |= (1 << PS2_CLOCK_BIT);
 }
 
-bool clock_in(void)
-{
-    PS2_CLOCK_DDR  &= ~(1<<PS2_CLOCK_BIT);
-    PS2_CLOCK_PORT |=  (1<<PS2_CLOCK_BIT);
+bool clock_in(void) {
+    PS2_CLOCK_DDR &= ~(1 << PS2_CLOCK_BIT);
+    PS2_CLOCK_PORT |= (1 << PS2_CLOCK_BIT);
     _delay_us(1);
-    return PS2_CLOCK_PIN&(1<<PS2_CLOCK_BIT);
+    return PS2_CLOCK_PIN & (1 << PS2_CLOCK_BIT);
 }
 
 /*
  * Data
  */
-void data_init(void)
-{
-}
+void data_init(void) {}
 
-void data_lo(void)
-{
-    PS2_DATA_PORT &= ~(1<<PS2_DATA_BIT);
-    PS2_DATA_DDR  |=  (1<<PS2_DATA_BIT);
+void data_lo(void) {
+    PS2_DATA_PORT &= ~(1 << PS2_DATA_BIT);
+    PS2_DATA_DDR |= (1 << PS2_DATA_BIT);
 }
 
-void data_hi(void)
-{
+void data_hi(void) {
     /* input with pull up */
-    PS2_DATA_DDR  &= ~(1<<PS2_DATA_BIT);
-    PS2_DATA_PORT |=  (1<<PS2_DATA_BIT);
+    PS2_DATA_DDR &= ~(1 << PS2_DATA_BIT);
+    PS2_DATA_PORT |= (1 << PS2_DATA_BIT);
 }
 
-bool data_in(void)
-{
-    PS2_DATA_DDR  &= ~(1<<PS2_DATA_BIT);
-    PS2_DATA_PORT |=  (1<<PS2_DATA_BIT);
+bool data_in(void) {
+    PS2_DATA_DDR &= ~(1 << PS2_DATA_BIT);
+    PS2_DATA_PORT |= (1 << PS2_DATA_BIT);
     _delay_us(1);
-    return PS2_DATA_PIN&(1<<PS2_DATA_BIT);
+    return PS2_DATA_PIN & (1 << PS2_DATA_BIT);
 }
index 83bdcef7f5aeebe5a2f55aeec0f23c9c87528730..9cec3dfbb43ccd15732b18c7750bd59f0daea5dc 100644 (file)
@@ -2,32 +2,27 @@
 #include "ps2_io.h"
 #include "gpio_api.h"
 
-
 static gpio_t clock;
 static gpio_t data;
 
 /*
  * Clock
  */
-void clock_init(void)
-{
+void clock_init(void) {
     gpio_init(&clock, P0_9);
-    gpio_mode(&clock, OpenDrain|PullNone);
+    gpio_mode(&clock, OpenDrain | PullNone);
 }
 
-void clock_lo(void)
-{
+void clock_lo(void) {
     gpio_dir(&clock, PIN_OUTPUT);
     gpio_write(&clock, 0);
 }
-void clock_hi(void)
-{
+void clock_hi(void) {
     gpio_dir(&clock, PIN_OUTPUT);
     gpio_write(&clock, 1);
 }
 
-bool clock_in(void)
-{
+bool clock_in(void) {
     gpio_dir(&clock, PIN_INPUT);
     return gpio_read(&clock);
 }
@@ -35,26 +30,22 @@ bool clock_in(void)
 /*
  * Data
  */
-void data_init(void)
-{
+void data_init(void) {
     gpio_init(&data, P0_8);
-    gpio_mode(&data, OpenDrain|PullNone);
+    gpio_mode(&data, OpenDrain | PullNone);
 }
 
-void data_lo(void)
-{
+void data_lo(void) {
     gpio_dir(&data, PIN_OUTPUT);
     gpio_write(&data, 0);
 }
 
-void data_hi(void)
-{
+void data_hi(void) {
     gpio_dir(&data, PIN_OUTPUT);
     gpio_write(&data, 1);
 }
 
-bool data_in(void)
-{
+bool data_in(void) {
     gpio_dir(&data, PIN_INPUT);
     return gpio_read(&data);
 }
index cf1055eb802c30f3f434df6ba55aeb50c8c466b2..aa3a307ebfab5e410139e28477aa3b5510fa7a2f 100644 (file)
@@ -16,8 +16,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include <stdbool.h>
-#include<avr/io.h>
-#include<util/delay.h>
+#include <avr/io.h>
+#include <util/delay.h>
 #include "ps2_mouse.h"
 #include "host.h"
 #include "timer.h"
@@ -42,7 +42,7 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report);
 void ps2_mouse_init(void) {
     ps2_host_init();
 
-    _delay_ms(PS2_MOUSE_INIT_DELAY);    // wait for powering up
+    _delay_ms(PS2_MOUSE_INIT_DELAY);  // wait for powering up
 
     PS2_MOUSE_SEND(PS2_MOUSE_RESET, "ps2_mouse_init: sending reset");
 
@@ -66,21 +66,19 @@ void ps2_mouse_init(void) {
     ps2_mouse_init_user();
 }
 
-__attribute__((weak))
-void ps2_mouse_init_user(void) {
-}
+__attribute__((weak)) void ps2_mouse_init_user(void) {}
 
 void ps2_mouse_task(void) {
     static uint8_t buttons_prev = 0;
-    extern int tp_buttons;
+    extern int     tp_buttons;
 
     /* receives packet from mouse */
     uint8_t rcv;
     rcv = ps2_host_send(PS2_MOUSE_READ_DATA);
     if (rcv == PS2_ACK) {
         mouse_report.buttons = ps2_host_recv_response() | tp_buttons;
-        mouse_report.x = ps2_host_recv_response() * PS2_MOUSE_X_MULTIPLIER;
-        mouse_report.y = ps2_host_recv_response() * PS2_MOUSE_Y_MULTIPLIER;
+        mouse_report.x       = ps2_host_recv_response() * PS2_MOUSE_X_MULTIPLIER;
+        mouse_report.y       = ps2_host_recv_response() * PS2_MOUSE_Y_MULTIPLIER;
 #ifdef PS2_MOUSE_ENABLE_SCROLLING
         mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK) * PS2_MOUSE_V_MULTIPLIER;
 #endif
@@ -90,8 +88,7 @@ void ps2_mouse_task(void) {
     }
 
     /* if mouse moves or buttons state changes */
-    if (mouse_report.x || mouse_report.y || mouse_report.v ||
-            ((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) {
+    if (mouse_report.x || mouse_report.y || mouse_report.v || ((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) {
 #ifdef PS2_MOUSE_DEBUG_RAW
         // Used to debug raw ps2 bytes from mouse
         ps2_mouse_print_report(&mouse_report);
@@ -111,13 +108,9 @@ void ps2_mouse_task(void) {
     ps2_mouse_clear_report(&mouse_report);
 }
 
-void ps2_mouse_disable_data_reporting(void) {
-    PS2_MOUSE_SEND(PS2_MOUSE_DISABLE_DATA_REPORTING, "ps2 mouse disable data reporting");
-}
+void ps2_mouse_disable_data_reporting(void) { PS2_MOUSE_SEND(PS2_MOUSE_DISABLE_DATA_REPORTING, "ps2 mouse disable data reporting"); }
 
-void ps2_mouse_enable_data_reporting(void) {
-    PS2_MOUSE_SEND(PS2_MOUSE_ENABLE_DATA_REPORTING, "ps2 mouse enable data reporting");
-}
+void ps2_mouse_enable_data_reporting(void) { PS2_MOUSE_SEND(PS2_MOUSE_ENABLE_DATA_REPORTING, "ps2 mouse enable data reporting"); }
 
 void ps2_mouse_set_remote_mode(void) {
     PS2_MOUSE_SEND_SAFE(PS2_MOUSE_SET_REMOTE_MODE, "ps2 mouse set remote mode");
@@ -129,28 +122,20 @@ void ps2_mouse_set_stream_mode(void) {
     ps2_mouse_mode = PS2_MOUSE_STREAM_MODE;
 }
 
-void ps2_mouse_set_scaling_2_1(void) {
-    PS2_MOUSE_SEND_SAFE(PS2_MOUSE_SET_SCALING_2_1, "ps2 mouse set scaling 2:1");
-}
+void ps2_mouse_set_scaling_2_1(void) { PS2_MOUSE_SEND_SAFE(PS2_MOUSE_SET_SCALING_2_1, "ps2 mouse set scaling 2:1"); }
 
-void ps2_mouse_set_scaling_1_1(void) {
-    PS2_MOUSE_SEND_SAFE(PS2_MOUSE_SET_SCALING_1_1, "ps2 mouse set scaling 1:1");
-}
+void ps2_mouse_set_scaling_1_1(void) { PS2_MOUSE_SEND_SAFE(PS2_MOUSE_SET_SCALING_1_1, "ps2 mouse set scaling 1:1"); }
 
-void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution) {
-    PS2_MOUSE_SET_SAFE(PS2_MOUSE_SET_RESOLUTION, resolution, "ps2 mouse set resolution");
-}
+void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution) { PS2_MOUSE_SET_SAFE(PS2_MOUSE_SET_RESOLUTION, resolution, "ps2 mouse set resolution"); }
 
-void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate) {
-    PS2_MOUSE_SET_SAFE(PS2_MOUSE_SET_SAMPLE_RATE, sample_rate, "ps2 mouse set sample rate");
-}
+void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate) { PS2_MOUSE_SET_SAFE(PS2_MOUSE_SET_SAMPLE_RATE, sample_rate, "ps2 mouse set sample rate"); }
 
 /* ============================= HELPERS ============================ */
 
-#define X_IS_NEG  (mouse_report->buttons & (1<<PS2_MOUSE_X_SIGN))
-#define Y_IS_NEG  (mouse_report->buttons & (1<<PS2_MOUSE_Y_SIGN))
-#define X_IS_OVF  (mouse_report->buttons & (1<<PS2_MOUSE_X_OVFLW))
-#define Y_IS_OVF  (mouse_report->buttons & (1<<PS2_MOUSE_Y_OVFLW))
+#define X_IS_NEG (mouse_report->buttons & (1 << PS2_MOUSE_X_SIGN))
+#define Y_IS_NEG (mouse_report->buttons & (1 << PS2_MOUSE_Y_SIGN))
+#define X_IS_OVF (mouse_report->buttons & (1 << PS2_MOUSE_X_OVFLW))
+#define Y_IS_OVF (mouse_report->buttons & (1 << PS2_MOUSE_Y_OVFLW))
 static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report) {
     // PS/2 mouse data is '9-bit integer'(-256 to 255) which is comprised of sign-bit and 8-bit value.
     // bit: 8    7 ... 0
@@ -159,12 +144,8 @@ static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report)
     // Meanwhile USB HID mouse indicates 8bit data(-127 to 127), note that -128 is not used.
     //
     // This converts PS/2 data into HID value. Use only -127-127 out of PS/2 9-bit.
-    mouse_report->x = X_IS_NEG ?
-        ((!X_IS_OVF && -127 <= mouse_report->x && mouse_report->x <= -1) ?  mouse_report->x : -127) :
-        ((!X_IS_OVF && 0 <= mouse_report->x && mouse_report->x <= 127) ? mouse_report->x : 127);
-    mouse_report->y = Y_IS_NEG ?
-        ((!Y_IS_OVF && -127 <= mouse_report->y && mouse_report->y <= -1) ?  mouse_report->y : -127) :
-        ((!Y_IS_OVF && 0 <= mouse_report->y && mouse_report->y <= 127) ? mouse_report->y : 127);
+    mouse_report->x = X_IS_NEG ? ((!X_IS_OVF && -127 <= mouse_report->x && mouse_report->x <= -1) ? mouse_report->x : -127) : ((!X_IS_OVF && 0 <= mouse_report->x && mouse_report->x <= 127) ? mouse_report->x : 127);
+    mouse_report->y = Y_IS_NEG ? ((!Y_IS_OVF && -127 <= mouse_report->y && mouse_report->y <= -1) ? mouse_report->y : -127) : ((!Y_IS_OVF && 0 <= mouse_report->y && mouse_report->y <= 127) ? mouse_report->y : 127);
 
     // remove sign and overflow flags
     mouse_report->buttons &= PS2_MOUSE_BTN_MASK;
@@ -172,29 +153,33 @@ static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report)
 #ifdef PS2_MOUSE_INVERT_X
     mouse_report->x = -mouse_report->x;
 #endif
-#ifndef PS2_MOUSE_INVERT_Y // NOTE if not!
+#ifndef PS2_MOUSE_INVERT_Y  // NOTE if not!
     // invert coordinate of y to conform to USB HID mouse
     mouse_report->y = -mouse_report->y;
 #endif
-
 }
 
 static inline void ps2_mouse_clear_report(report_mouse_t *mouse_report) {
-    mouse_report->x = 0;
-    mouse_report->y = 0;
-    mouse_report->v = 0;
-    mouse_report->h = 0;
+    mouse_report->x       = 0;
+    mouse_report->y       = 0;
+    mouse_report->v       = 0;
+    mouse_report->h       = 0;
     mouse_report->buttons = 0;
 }
 
 static inline void ps2_mouse_print_report(report_mouse_t *mouse_report) {
     if (!debug_mouse) return;
     print("ps2_mouse: [");
-    phex(mouse_report->buttons); print("|");
-    print_hex8((uint8_t)mouse_report->x); print(" ");
-    print_hex8((uint8_t)mouse_report->y); print(" ");
-    print_hex8((uint8_t)mouse_report->v); print(" ");
-    print_hex8((uint8_t)mouse_report->h); print("]\n");
+    phex(mouse_report->buttons);
+    print("|");
+    print_hex8((uint8_t)mouse_report->x);
+    print(" ");
+    print_hex8((uint8_t)mouse_report->y);
+    print(" ");
+    print_hex8((uint8_t)mouse_report->v);
+    print(" ");
+    print_hex8((uint8_t)mouse_report->h);
+    print("]\n");
 }
 
 static inline void ps2_mouse_enable_scrolling(void) {
@@ -208,14 +193,14 @@ static inline void ps2_mouse_enable_scrolling(void) {
     _delay_ms(20);
 }
 
-#define PRESS_SCROLL_BUTTONS    mouse_report->buttons |= (PS2_MOUSE_SCROLL_BTN_MASK)
-#define RELEASE_SCROLL_BUTTONS  mouse_report->buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK)
+#define PRESS_SCROLL_BUTTONS mouse_report->buttons |= (PS2_MOUSE_SCROLL_BTN_MASK)
+#define RELEASE_SCROLL_BUTTONS mouse_report->buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK)
 static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report) {
     static enum {
         SCROLL_NONE,
         SCROLL_BTN,
         SCROLL_SENT,
-    } scroll_state = SCROLL_NONE;
+    } scroll_state                     = SCROLL_NONE;
     static uint16_t scroll_button_time = 0;
 
     if (PS2_MOUSE_SCROLL_BTN_MASK == (mouse_report->buttons & (PS2_MOUSE_SCROLL_BTN_MASK))) {
@@ -223,14 +208,14 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report) {
 
         if (scroll_state == SCROLL_NONE) {
             scroll_button_time = timer_read();
-            scroll_state = SCROLL_BTN;
+            scroll_state       = SCROLL_BTN;
         }
 
         // If the mouse has moved, update the report to scroll instead of move the mouse
         if (mouse_report->x || mouse_report->y) {
-            scroll_state = SCROLL_SENT;
-            mouse_report->v = -mouse_report->y/(PS2_MOUSE_SCROLL_DIVISOR_V);
-            mouse_report->h =  mouse_report->x/(PS2_MOUSE_SCROLL_DIVISOR_H);
+            scroll_state    = SCROLL_SENT;
+            mouse_report->v = -mouse_report->y / (PS2_MOUSE_SCROLL_DIVISOR_V);
+            mouse_report->h = mouse_report->x / (PS2_MOUSE_SCROLL_DIVISOR_H);
             mouse_report->x = 0;
             mouse_report->y = 0;
 #ifdef PS2_MOUSE_INVERT_H
@@ -244,8 +229,7 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report) {
         // None of the scroll buttons are pressed
 
 #if PS2_MOUSE_SCROLL_BTN_SEND
-        if (scroll_state == SCROLL_BTN
-                && timer_elapsed(scroll_button_time) < PS2_MOUSE_SCROLL_BTN_SEND) {
+        if (scroll_state == SCROLL_BTN && timer_elapsed(scroll_button_time) < PS2_MOUSE_SCROLL_BTN_SEND) {
             PRESS_SCROLL_BUTTONS;
             host_mouse_send(mouse_report);
             _delay_ms(100);
index eeeffe4d80ca0fc62538ffb8681194b5be0fa3e4..30053ef187039b0ce1cf6cc53ad915baa1c2cdd1 100644 (file)
@@ -16,54 +16,53 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef PS2_MOUSE_H
-#define  PS2_MOUSE_H
+#define PS2_MOUSE_H
 
 #include <stdbool.h>
 #include "debug.h"
 
-#define PS2_MOUSE_SEND(command, message) \
-do { \
-   __attribute__ ((unused)) uint8_t rcv = ps2_host_send(command); \
-   if (debug_mouse) { \
-        print((message)); \
-        xprintf(" command: %X, result: %X, error: %X \n", command, rcv, ps2_error); \
-    } \
-} while(0)
-
-#define PS2_MOUSE_SEND_SAFE(command, message) \
-do { \
-    if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
-        ps2_mouse_disable_data_reporting(); \
-    } \
-    PS2_MOUSE_SEND(command, message); \
-    if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
-        ps2_mouse_enable_data_reporting(); \
-    } \
-} while(0)
-
-#define PS2_MOUSE_SET_SAFE(command, value, message) \
-do { \
-    if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
-        ps2_mouse_disable_data_reporting(); \
-    } \
-    PS2_MOUSE_SEND(command, message); \
-    PS2_MOUSE_SEND(value, "Sending value"); \
-    if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
-        ps2_mouse_enable_data_reporting(); \
-    } \
-} while(0)
-
-#define PS2_MOUSE_RECEIVE(message) \
-do { \
-   __attribute__ ((unused)) uint8_t rcv = ps2_host_recv_response(); \
-   if (debug_mouse) { \
-        print((message)); \
-        xprintf(" result: %X, error: %X \n", rcv, ps2_error); \
-    } \
-} while(0)
-
-__attribute__ ((unused))
-static enum ps2_mouse_mode_e {
+#define PS2_MOUSE_SEND(command, message)                                                \
+    do {                                                                                \
+        __attribute__((unused)) uint8_t rcv = ps2_host_send(command);                   \
+        if (debug_mouse) {                                                              \
+            print((message));                                                           \
+            xprintf(" command: %X, result: %X, error: %X \n", command, rcv, ps2_error); \
+        }                                                                               \
+    } while (0)
+
+#define PS2_MOUSE_SEND_SAFE(command, message)          \
+    do {                                               \
+        if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
+            ps2_mouse_disable_data_reporting();        \
+        }                                              \
+        PS2_MOUSE_SEND(command, message);              \
+        if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
+            ps2_mouse_enable_data_reporting();         \
+        }                                              \
+    } while (0)
+
+#define PS2_MOUSE_SET_SAFE(command, value, message)    \
+    do {                                               \
+        if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
+            ps2_mouse_disable_data_reporting();        \
+        }                                              \
+        PS2_MOUSE_SEND(command, message);              \
+        PS2_MOUSE_SEND(value, "Sending value");        \
+        if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
+            ps2_mouse_enable_data_reporting();         \
+        }                                              \
+    } while (0)
+
+#define PS2_MOUSE_RECEIVE(message)                                      \
+    do {                                                                \
+        __attribute__((unused)) uint8_t rcv = ps2_host_recv_response(); \
+        if (debug_mouse) {                                              \
+            print((message));                                           \
+            xprintf(" result: %X, error: %X \n", rcv, ps2_error);       \
+        }                                                               \
+    } while (0)
+
+__attribute__((unused)) static enum ps2_mouse_mode_e {
     PS2_MOUSE_STREAM_MODE,
     PS2_MOUSE_REMOTE_MODE,
 } ps2_mouse_mode = PS2_MOUSE_STREAM_MODE;
@@ -76,79 +75,79 @@ static enum ps2_mouse_mode_e {
  *    1|[                    X movement(0-255)                         ]
  *    2|[                    Y movement(0-255)                         ]
  */
-#define PS2_MOUSE_BTN_MASK      0x07
-#define PS2_MOUSE_BTN_LEFT      0
-#define PS2_MOUSE_BTN_RIGHT     1
-#define PS2_MOUSE_BTN_MIDDLE    2
-#define PS2_MOUSE_X_SIGN        4
-#define PS2_MOUSE_Y_SIGN        5
-#define PS2_MOUSE_X_OVFLW       6
-#define PS2_MOUSE_Y_OVFLW       7
+#define PS2_MOUSE_BTN_MASK 0x07
+#define PS2_MOUSE_BTN_LEFT 0
+#define PS2_MOUSE_BTN_RIGHT 1
+#define PS2_MOUSE_BTN_MIDDLE 2
+#define PS2_MOUSE_X_SIGN 4
+#define PS2_MOUSE_Y_SIGN 5
+#define PS2_MOUSE_X_OVFLW 6
+#define PS2_MOUSE_Y_OVFLW 7
 
 /* mouse button to start scrolling; set 0 to disable scroll */
 #ifndef PS2_MOUSE_SCROLL_BTN_MASK
-#define PS2_MOUSE_SCROLL_BTN_MASK       (1<<PS2_MOUSE_BTN_MIDDLE)
+#    define PS2_MOUSE_SCROLL_BTN_MASK (1 << PS2_MOUSE_BTN_MIDDLE)
 #endif
 /* send button event when button is released within this value(ms); set 0 to disable  */
 #ifndef PS2_MOUSE_SCROLL_BTN_SEND
-#define PS2_MOUSE_SCROLL_BTN_SEND       300
+#    define PS2_MOUSE_SCROLL_BTN_SEND 300
 #endif
 /* divide virtical and horizontal mouse move by this to convert to scroll move */
 #ifndef PS2_MOUSE_SCROLL_DIVISOR_V
-#define PS2_MOUSE_SCROLL_DIVISOR_V      2
+#    define PS2_MOUSE_SCROLL_DIVISOR_V 2
 #endif
 #ifndef PS2_MOUSE_SCROLL_DIVISOR_H
-#define PS2_MOUSE_SCROLL_DIVISOR_H      2
+#    define PS2_MOUSE_SCROLL_DIVISOR_H 2
 #endif
 /* multiply reported mouse values by these */
 #ifndef PS2_MOUSE_X_MULTIPLIER
-#define PS2_MOUSE_X_MULTIPLIER          1
+#    define PS2_MOUSE_X_MULTIPLIER 1
 #endif
 #ifndef PS2_MOUSE_Y_MULTIPLIER
-#define PS2_MOUSE_Y_MULTIPLIER          1
+#    define PS2_MOUSE_Y_MULTIPLIER 1
 #endif
 #ifndef PS2_MOUSE_V_MULTIPLIER
-#define PS2_MOUSE_V_MULTIPLIER          1
+#    define PS2_MOUSE_V_MULTIPLIER 1
 #endif
 /* For some mice this will need to be 0x0F */
-#ifndef PS2_MOUSE_SCROLL_MASK       
-#define PS2_MOUSE_SCROLL_MASK           0xFF 
+#ifndef PS2_MOUSE_SCROLL_MASK
+#    define PS2_MOUSE_SCROLL_MASK 0xFF
 #endif
 #ifndef PS2_MOUSE_INIT_DELAY
-#define PS2_MOUSE_INIT_DELAY            1000
+#    define PS2_MOUSE_INIT_DELAY 1000
 #endif
 
 enum ps2_mouse_command_e {
-    PS2_MOUSE_RESET = 0xFF,
-    PS2_MOUSE_RESEND = 0xFE,
-    PS2_MOSUE_SET_DEFAULTS = 0xF6,
+    PS2_MOUSE_RESET                  = 0xFF,
+    PS2_MOUSE_RESEND                 = 0xFE,
+    PS2_MOSUE_SET_DEFAULTS           = 0xF6,
     PS2_MOUSE_DISABLE_DATA_REPORTING = 0xF5,
-    PS2_MOUSE_ENABLE_DATA_REPORTING = 0xF4,
-    PS2_MOUSE_SET_SAMPLE_RATE = 0xF3,
-    PS2_MOUSE_GET_DEVICE_ID = 0xF2,
-    PS2_MOUSE_SET_REMOTE_MODE = 0xF0,
-    PS2_MOUSE_SET_WRAP_MODE = 0xEC,
-    PS2_MOUSE_READ_DATA = 0xEB,
-    PS2_MOUSE_SET_STREAM_MODE = 0xEA,
-    PS2_MOUSE_STATUS_REQUEST = 0xE9,
-    PS2_MOUSE_SET_RESOLUTION = 0xE8,
-    PS2_MOUSE_SET_SCALING_2_1 = 0xE7,
-    PS2_MOUSE_SET_SCALING_1_1 = 0xE6,
+    PS2_MOUSE_ENABLE_DATA_REPORTING  = 0xF4,
+    PS2_MOUSE_SET_SAMPLE_RATE        = 0xF3,
+    PS2_MOUSE_GET_DEVICE_ID          = 0xF2,
+    PS2_MOUSE_SET_REMOTE_MODE        = 0xF0,
+    PS2_MOUSE_SET_WRAP_MODE          = 0xEC,
+    PS2_MOUSE_READ_DATA              = 0xEB,
+    PS2_MOUSE_SET_STREAM_MODE        = 0xEA,
+    PS2_MOUSE_STATUS_REQUEST         = 0xE9,
+    PS2_MOUSE_SET_RESOLUTION         = 0xE8,
+    PS2_MOUSE_SET_SCALING_2_1        = 0xE7,
+    PS2_MOUSE_SET_SCALING_1_1        = 0xE6,
 };
 
 typedef enum ps2_mouse_resolution_e {
     PS2_MOUSE_1_COUNT_MM,
     PS2_MOUSE_2_COUNT_MM,
     PS2_MOUSE_4_COUNT_MM,
-    PS2_MOUSE_8_COUNT_MM,   
+    PS2_MOUSE_8_COUNT_MM,
 } ps2_mouse_resolution_t;
 
 typedef enum ps2_mouse_sample_rate_e {
-    PS2_MOUSE_10_SAMPLES_SEC = 10,
-    PS2_MOUSE_20_SAMPLES_SEC = 20,
-    PS2_MOUSE_40_SAMPLES_SEC = 40,
-    PS2_MOUSE_60_SAMPLES_SEC = 60,
-    PS2_MOUSE_80_SAMPLES_SEC = 80,
+    PS2_MOUSE_10_SAMPLES_SEC  = 10,
+    PS2_MOUSE_20_SAMPLES_SEC  = 20,
+    PS2_MOUSE_40_SAMPLES_SEC  = 40,
+    PS2_MOUSE_60_SAMPLES_SEC  = 60,
+    PS2_MOUSE_80_SAMPLES_SEC  = 80,
     PS2_MOUSE_100_SAMPLES_SEC = 100,
     PS2_MOUSE_200_SAMPLES_SEC = 200,
 } ps2_mouse_sample_rate_t;
index 6936ca7b882b3c1055e2ff89906c29f2f2602c44..6a66dc4a1e739343438270cee9fc4f0baf86b6f8 100644 (file)
@@ -46,53 +46,48 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "ps2_io.h"
 #include "print.h"
 
-
-#define WAIT(stat, us, err) do { \
-    if (!wait_##stat(us)) { \
-        ps2_error = err; \
-        goto ERROR; \
-    } \
-} while (0)
-
+#define WAIT(stat, us, err)     \
+    do {                        \
+        if (!wait_##stat(us)) { \
+            ps2_error = err;    \
+            goto ERROR;         \
+        }                       \
+    } while (0)
 
 uint8_t ps2_error = PS2_ERR_NONE;
 
-
 static inline uint8_t pbuf_dequeue(void);
-static inline void pbuf_enqueue(uint8_t data);
-static inline bool pbuf_has_data(void);
-static inline void pbuf_clear(void);
+static inline void    pbuf_enqueue(uint8_t data);
+static inline bool    pbuf_has_data(void);
+static inline void    pbuf_clear(void);
 
-
-void ps2_host_init(void)
-{
-    idle(); // without this many USART errors occur when cable is disconnected
+void ps2_host_init(void) {
+    idle();  // without this many USART errors occur when cable is disconnected
     PS2_USART_INIT();
     PS2_USART_RX_INT_ON();
     // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20)
     //_delay_ms(2500);
 }
 
-uint8_t ps2_host_send(uint8_t data)
-{
+uint8_t ps2_host_send(uint8_t data) {
     bool parity = true;
-    ps2_error = PS2_ERR_NONE;
+    ps2_error   = PS2_ERR_NONE;
 
     PS2_USART_OFF();
 
     /* terminate a transmission if we have */
     inhibit();
-    _delay_us(100); // [4]p.13
+    _delay_us(100);  // [4]p.13
 
     /* 'Request to Send' and Start bit */
     data_lo();
     clock_hi();
-    WAIT(clock_lo, 10000, 10);   // 10ms [5]p.50
+    WAIT(clock_lo, 10000, 10);  // 10ms [5]p.50
 
     /* Data bit[2-9] */
     for (uint8_t i = 0; i < 8; i++) {
         _delay_us(15);
-        if (data&(1<<i)) {
+        if (data & (1 << i)) {
             parity = !parity;
             data_hi();
         } else {
@@ -104,7 +99,11 @@ uint8_t ps2_host_send(uint8_t data)
 
     /* Parity bit */
     _delay_us(15);
-    if (parity) { data_hi(); } else { data_lo(); }
+    if (parity) {
+        data_hi();
+    } else {
+        data_lo();
+    }
     WAIT(clock_hi, 50, 4);
     WAIT(clock_lo, 50, 5);
 
@@ -131,8 +130,7 @@ ERROR:
     return 0;
 }
 
-uint8_t ps2_host_recv_response(void)
-{
+uint8_t ps2_host_recv_response(void) {
     // Command may take 25ms/20ms at most([5]p.46, [3]p.21)
     uint8_t retry = 25;
     while (retry-- && !pbuf_has_data()) {
@@ -141,8 +139,7 @@ uint8_t ps2_host_recv_response(void)
     return pbuf_dequeue();
 }
 
-uint8_t ps2_host_recv(void)
-{
+uint8_t ps2_host_recv(void) {
     if (pbuf_has_data()) {
         ps2_error = PS2_ERR_NONE;
         return pbuf_dequeue();
@@ -152,11 +149,10 @@ uint8_t ps2_host_recv(void)
     }
 }
 
-ISR(PS2_USART_RX_VECT)
-{
+ISR(PS2_USART_RX_VECT) {
     // TODO: request RESEND when error occurs?
-    uint8_t error = PS2_USART_ERROR;    // USART error should be read before data
-    uint8_t data = PS2_USART_RX_DATA;
+    uint8_t error = PS2_USART_ERROR;  // USART error should be read before data
+    uint8_t data  = PS2_USART_RX_DATA;
     if (!error) {
         pbuf_enqueue(data);
     } else {
@@ -165,59 +161,53 @@ ISR(PS2_USART_RX_VECT)
 }
 
 /* send LED state to keyboard */
-void ps2_host_set_led(uint8_t led)
-{
+void ps2_host_set_led(uint8_t led) {
     ps2_host_send(0xED);
     ps2_host_send(led);
 }
 
-
 /*--------------------------------------------------------------------
  * Ring buffer to store scan codes from keyboard
  *------------------------------------------------------------------*/
 #define PBUF_SIZE 32
-static uint8_t pbuf[PBUF_SIZE];
-static uint8_t pbuf_head = 0;
-static uint8_t pbuf_tail = 0;
-static inline void pbuf_enqueue(uint8_t data)
-{
+static uint8_t     pbuf[PBUF_SIZE];
+static uint8_t     pbuf_head = 0;
+static uint8_t     pbuf_tail = 0;
+static inline void pbuf_enqueue(uint8_t data) {
     uint8_t sreg = SREG;
     cli();
     uint8_t next = (pbuf_head + 1) % PBUF_SIZE;
     if (next != pbuf_tail) {
         pbuf[pbuf_head] = data;
-        pbuf_head = next;
+        pbuf_head       = next;
     } else {
         print("pbuf: full\n");
     }
     SREG = sreg;
 }
-static inline uint8_t pbuf_dequeue(void)
-{
+static inline uint8_t pbuf_dequeue(void) {
     uint8_t val = 0;
 
     uint8_t sreg = SREG;
     cli();
     if (pbuf_head != pbuf_tail) {
-        val = pbuf[pbuf_tail];
+        val       = pbuf[pbuf_tail];
         pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE;
     }
     SREG = sreg;
 
     return val;
 }
-static inline bool pbuf_has_data(void)
-{
+static inline bool pbuf_has_data(void) {
     uint8_t sreg = SREG;
     cli();
     bool has_data = (pbuf_head != pbuf_tail);
-    SREG = sreg;
+    SREG          = sreg;
     return has_data;
 }
-static inline void pbuf_clear(void)
-{
+static inline void pbuf_clear(void) {
     uint8_t sreg = SREG;
     cli();
     pbuf_head = pbuf_tail = 0;
-    SREG = sreg;
+    SREG                  = sreg;
 }
index 96913c86755fad15b5681fe53d89c194f383a221..93ac998983feb3e97fa7f770da3e2b068222b202 100644 (file)
@@ -39,9 +39,9 @@ POSSIBILITY OF SUCH DAMAGE.
 #define SERIAL_H
 
 /* host role */
-void serial_init(void);
+void    serial_init(void);
 uint8_t serial_recv(void);
 int16_t serial_recv2(void);
-void serial_send(uint8_t data);
+void    serial_send(uint8_t data);
 
 #endif
index 226314fc0ed4dd9a3f5e9bb1cdb74484be2a25d0..b10315f3660c47567545930e5f018a8d16da5e96 100644 (file)
@@ -22,8 +22,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "serial.h"
 
-static inline uint8_t serial_mouse_init(void)
-{
+static inline uint8_t serial_mouse_init(void) {
     serial_init();
     return 0;
 }
index ab74b7cdd3309e9240a5d5064b2ef1c120e1ceb6..eff0bf6e45f8372d7a00ab29dd38ca729addf209 100644 (file)
@@ -28,36 +28,32 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "debug.h"
 
 #ifdef MAX
-#undef MAX
+#    undef MAX
 #endif
 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
 
 static void print_usb_data(const report_mouse_t *report);
 
-void serial_mouse_task(void)
-{
+void serial_mouse_task(void) {
     /* 3 byte ring buffer */
     static uint8_t buffer[3];
-    static int buffer_cur = 0;
+    static int     buffer_cur = 0;
 
     static report_mouse_t report = {};
 
     int16_t rcv;
 
     rcv = serial_recv2();
-    if (rcv < 0)
-        /* no new data */
+    if (rcv < 0) /* no new data */
         return;
 
-    if (debug_mouse)
-        xprintf("serial_mouse: byte: %04X\n", rcv);
+    if (debug_mouse) xprintf("serial_mouse: byte: %04X\n", rcv);
 
     /*
      * If bit 6 is one, this signals the beginning
      * of a 3 byte sequence/packet.
      */
-    if (rcv & (1 << 6))
-        buffer_cur = 0;
+    if (rcv & (1 << 6)) buffer_cur = 0;
 
     buffer[buffer_cur] = (uint8_t)rcv;
 
@@ -76,8 +72,7 @@ void serial_mouse_task(void)
 
     buffer_cur++;
 
-    if (buffer_cur < 3)
-        return;
+    if (buffer_cur < 3) return;
     buffer_cur = 0;
 
     /*
@@ -87,10 +82,8 @@ void serial_mouse_task(void)
      * change.
      */
     report.buttons = 0;
-    if (buffer[0] & (1 << 5))
-        report.buttons |= MOUSE_BTN1;
-    if (buffer[0] & (1 << 4))
-        report.buttons |= MOUSE_BTN2;
+    if (buffer[0] & (1 << 5)) report.buttons |= MOUSE_BTN1;
+    if (buffer[0] & (1 << 4)) report.buttons |= MOUSE_BTN2;
 
     report.x = (buffer[0] << 6) | buffer[1];
     report.y = ((buffer[0] << 4) & 0xC0) | buffer[2];
@@ -113,12 +106,8 @@ void serial_mouse_task(void)
     host_mouse_send(&report);
 }
 
-static void print_usb_data(const report_mouse_t *report)
-{
-    if (!debug_mouse)
-        return;
+static void print_usb_data(const report_mouse_t *report) {
+    if (!debug_mouse) return;
 
-    xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n",
-            report->buttons, report->x, report->y,
-            report->v, report->h);
+    xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n", report->buttons, report->x, report->y, report->v, report->h);
 }
index cfe899621604657bad9fab03e8726a64a1582a67..0ec2b0399aab825bf0cb1cfece133a101c0d3e76 100644 (file)
@@ -28,7 +28,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "debug.h"
 
 #ifdef MAX
-#undef MAX
+#    undef MAX
 #endif
 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
 
@@ -36,23 +36,20 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 static void print_usb_data(const report_mouse_t *report);
 
-void serial_mouse_task(void)
-{
+void serial_mouse_task(void) {
     /* 5 byte ring buffer */
     static uint8_t buffer[5];
-    static int buffer_cur = 0;
+    static int     buffer_cur = 0;
 
     int16_t rcv;
 
     report_mouse_t report = {0, 0, 0, 0, 0};
 
     rcv = serial_recv2();
-    if (rcv < 0)
-        /* no new data */
+    if (rcv < 0) /* no new data */
         return;
 
-    if (debug_mouse)
-        xprintf("serial_mouse: byte: %04X\n", rcv);
+    if (debug_mouse) xprintf("serial_mouse: byte: %04X\n", rcv);
 
     /*
      * Synchronization: mouse(4) says that all
@@ -61,13 +58,11 @@ void serial_mouse_task(void)
      * Therefore we discard all bytes up to the
      * first one with the characteristic bit pattern.
      */
-    if (buffer_cur == 0 && (rcv >> 3) != 0x10)
-        return;
+    if (buffer_cur == 0 && (rcv >> 3) != 0x10) return;
 
     buffer[buffer_cur++] = (uint8_t)rcv;
 
-    if (buffer_cur < 5)
-        return;
+    if (buffer_cur < 5) return;
     buffer_cur = 0;
 
 #ifdef SERIAL_MOUSE_CENTER_SCROLL
@@ -97,12 +92,9 @@ void serial_mouse_task(void)
      * if the mouse moved or the button states
      * change.
      */
-    if (!(buffer[0] & (1 << 2)))
-        report.buttons |= MOUSE_BTN1;
-    if (!(buffer[0] & (1 << 1)))
-        report.buttons |= MOUSE_BTN3;
-    if (!(buffer[0] & (1 << 0)))
-        report.buttons |= MOUSE_BTN2;
+    if (!(buffer[0] & (1 << 2))) report.buttons |= MOUSE_BTN1;
+    if (!(buffer[0] & (1 << 1))) report.buttons |= MOUSE_BTN3;
+    if (!(buffer[0] & (1 << 0))) report.buttons |= MOUSE_BTN2;
 
     /* USB HID uses only values from -127 to 127 */
     report.x = MAX((int8_t)buffer[1], -127);
@@ -120,12 +112,8 @@ void serial_mouse_task(void)
     }
 }
 
-static void print_usb_data(const report_mouse_t *report)
-{
-    if (!debug_mouse)
-        return;
+static void print_usb_data(const report_mouse_t *report) {
+    if (!debug_mouse) return;
 
-    xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n",
-            report->buttons, report->x, report->y,
-            report->v, report->h);
+    xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n", report->buttons, report->x, report->y, report->v, report->h);
 }
index 44822b7e43e2500daabb11a5c3faa49a1c3b2ce1..b4090799547ad65b08cbf14dc823dbce02cc9d67 100644 (file)
@@ -49,37 +49,35 @@ POSSIBILITY OF SUCH DAMAGE.
  *  TODO: delay is not accurate enough. Instruction cycle should be counted and inline assemby is needed.
  */
 
-#define WAIT_US     (1000000L/SERIAL_SOFT_BAUD)
+#define WAIT_US (1000000L / SERIAL_SOFT_BAUD)
 
 #ifdef SERIAL_SOFT_LOGIC_NEGATIVE
-    #define SERIAL_SOFT_RXD_IN()        !(SERIAL_SOFT_RXD_READ())
-    #define SERIAL_SOFT_TXD_ON()        SERIAL_SOFT_TXD_LO()
-    #define SERIAL_SOFT_TXD_OFF()       SERIAL_SOFT_TXD_HI()
+#    define SERIAL_SOFT_RXD_IN() !(SERIAL_SOFT_RXD_READ())
+#    define SERIAL_SOFT_TXD_ON() SERIAL_SOFT_TXD_LO()
+#    define SERIAL_SOFT_TXD_OFF() SERIAL_SOFT_TXD_HI()
 #else
-    #define SERIAL_SOFT_RXD_IN()        !!(SERIAL_SOFT_RXD_READ())
-    #define SERIAL_SOFT_TXD_ON()        SERIAL_SOFT_TXD_HI()
-    #define SERIAL_SOFT_TXD_OFF()       SERIAL_SOFT_TXD_LO()
+#    define SERIAL_SOFT_RXD_IN() !!(SERIAL_SOFT_RXD_READ())
+#    define SERIAL_SOFT_TXD_ON() SERIAL_SOFT_TXD_HI()
+#    define SERIAL_SOFT_TXD_OFF() SERIAL_SOFT_TXD_LO()
 #endif
 
 #ifdef SERIAL_SOFT_PARITY_EVEN
-    #define SERIAL_SOFT_PARITY_VAL      0
+#    define SERIAL_SOFT_PARITY_VAL 0
 #elif defined(SERIAL_SOFT_PARITY_ODD)
-    #define SERIAL_SOFT_PARITY_VAL      1
+#    define SERIAL_SOFT_PARITY_VAL 1
 #endif
 
 /* debug for signal timing, see debug pin with oscilloscope */
 #define SERIAL_SOFT_DEBUG
 #ifdef SERIAL_SOFT_DEBUG
-    #define SERIAL_SOFT_DEBUG_INIT()    (DDRD |= 1<<7)
-    #define SERIAL_SOFT_DEBUG_TGL()     (PORTD ^= 1<<7)
+#    define SERIAL_SOFT_DEBUG_INIT() (DDRD |= 1 << 7)
+#    define SERIAL_SOFT_DEBUG_TGL() (PORTD ^= 1 << 7)
 #else
-    #define SERIAL_SOFT_DEBUG_INIT()
-    #define SERIAL_SOFT_DEBUG_TGL()
+#    define SERIAL_SOFT_DEBUG_INIT()
+#    define SERIAL_SOFT_DEBUG_TGL()
 #endif
 
-
-void serial_init(void)
-{
+void serial_init(void) {
     SERIAL_SOFT_DEBUG_INIT();
 
     SERIAL_SOFT_RXD_INIT();
@@ -87,46 +85,42 @@ void serial_init(void)
 }
 
 /* RX ring buffer */
-#define RBUF_SIZE   8
+#define RBUF_SIZE 8
 static uint8_t rbuf[RBUF_SIZE];
 static uint8_t rbuf_head = 0;
 static uint8_t rbuf_tail = 0;
 
-
-uint8_t serial_recv(void)
-{
+uint8_t serial_recv(void) {
     uint8_t data = 0;
     if (rbuf_head == rbuf_tail) {
         return 0;
     }
 
-    data = rbuf[rbuf_tail];
+    data      = rbuf[rbuf_tail];
     rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
     return data;
 }
 
-int16_t serial_recv2(void)
-{
+int16_t serial_recv2(void) {
     uint8_t data = 0;
     if (rbuf_head == rbuf_tail) {
         return -1;
     }
 
-    data = rbuf[rbuf_tail];
+    data      = rbuf[rbuf_tail];
     rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
     return data;
 }
 
-void serial_send(uint8_t data)
-{
+void serial_send(uint8_t data) {
     /* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */
 
 #ifdef SERIAL_SOFT_BIT_ORDER_MSB
-    #ifdef SERIAL_SOFT_DATA_7BIT
+#    ifdef SERIAL_SOFT_DATA_7BIT
     uint8_t mask = 0x40;
-    #else
+#    else
     uint8_t mask = 0x80;
-    #endif
+#    endif
 #else
     uint8_t mask = 0x01;
 #endif
@@ -138,11 +132,11 @@ void serial_send(uint8_t data)
     _delay_us(WAIT_US);
 
 #ifdef SERIAL_SOFT_DATA_7BIT
-    while (mask&0x7F) {
+    while (mask & 0x7F) {
 #else
-    while (mask&0xFF) {
+    while (mask & 0xFF) {
 #endif
-        if (data&mask) {
+        if (data & mask) {
             SERIAL_SOFT_TXD_ON();
             parity ^= 1;
         } else {
@@ -173,19 +167,18 @@ void serial_send(uint8_t data)
 }
 
 /* detect edge of start bit */
-ISR(SERIAL_SOFT_RXD_VECT)
-{
+ISR(SERIAL_SOFT_RXD_VECT) {
     SERIAL_SOFT_DEBUG_TGL();
     SERIAL_SOFT_RXD_INT_ENTER()
 
     uint8_t data = 0;
 
 #ifdef SERIAL_SOFT_BIT_ORDER_MSB
-    #ifdef SERIAL_SOFT_DATA_7BIT
+#    ifdef SERIAL_SOFT_DATA_7BIT
     uint8_t mask = 0x40;
-    #else
+#    else
     uint8_t mask = 0x80;
-    #endif
+#    endif
 #else
     uint8_t mask = 0x01;
 #endif
@@ -193,13 +186,13 @@ ISR(SERIAL_SOFT_RXD_VECT)
     uint8_t parity = 0;
 
     /* to center of start bit */
-    _delay_us(WAIT_US/2);
+    _delay_us(WAIT_US / 2);
     SERIAL_SOFT_DEBUG_TGL();
     do {
         /* to center of next bit */
         _delay_us(WAIT_US);
 
-    SERIAL_SOFT_DEBUG_TGL();
+        SERIAL_SOFT_DEBUG_TGL();
         if (SERIAL_SOFT_RXD_IN()) {
             data |= mask;
             parity ^= 1;
@@ -210,15 +203,17 @@ ISR(SERIAL_SOFT_RXD_VECT)
         mask <<= 1;
 #endif
 #ifdef SERIAL_SOFT_DATA_7BIT
-    } while (mask&0x7F);
+    } while (mask & 0x7F);
 #else
-    } while (mask&0xFF);
+    } while (mask & 0xFF);
 #endif
 
 #if defined(SERIAL_SOFT_PARITY_EVEN) || defined(SERIAL_SOFT_PARITY_ODD)
     /* to center of parity bit */
     _delay_us(WAIT_US);
-    if (SERIAL_SOFT_RXD_IN()) { parity ^= 1; }
+    if (SERIAL_SOFT_RXD_IN()) {
+        parity ^= 1;
+    }
     SERIAL_SOFT_DEBUG_TGL();
 #endif
 
@@ -232,7 +227,7 @@ ISR(SERIAL_SOFT_RXD_VECT)
     if (next != rbuf_tail) {
 #endif
         rbuf[rbuf_head] = data;
-        rbuf_head = next;
+        rbuf_head       = next;
     }
 
     SERIAL_SOFT_RXD_INT_EXIT();
index 35df27fd6ece90c5c57259d8068f6d08fb688ebf..a15124193afecb26dceee22ac30782994655fe82 100644 (file)
@@ -40,73 +40,71 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <avr/interrupt.h>
 #include "serial.h"
 
-
 #if defined(SERIAL_UART_RTS_LO) && defined(SERIAL_UART_RTS_HI)
-    // Buffer state
-    //   Empty:           RBUF_SPACE == RBUF_SIZE(head==tail)
-    //   Last 1 space:    RBUF_SPACE == 2
-    //   Full:            RBUF_SPACE == 1(last cell of rbuf be never used.)
-    #define RBUF_SPACE()   (rbuf_head < rbuf_tail ?  (rbuf_tail - rbuf_head) : (RBUF_SIZE - rbuf_head + rbuf_tail))
-    // allow to send
-    #define rbuf_check_rts_lo() do { if (RBUF_SPACE() > 2) SERIAL_UART_RTS_LO(); } while (0)
-    // prohibit to send
-    #define rbuf_check_rts_hi() do { if (RBUF_SPACE() <= 2) SERIAL_UART_RTS_HI(); } while (0)
+// Buffer state
+//   Empty:           RBUF_SPACE == RBUF_SIZE(head==tail)
+//   Last 1 space:    RBUF_SPACE == 2
+//   Full:            RBUF_SPACE == 1(last cell of rbuf be never used.)
+#    define RBUF_SPACE() (rbuf_head < rbuf_tail ? (rbuf_tail - rbuf_head) : (RBUF_SIZE - rbuf_head + rbuf_tail))
+// allow to send
+#    define rbuf_check_rts_lo()                         \
+        do {                                            \
+            if (RBUF_SPACE() > 2) SERIAL_UART_RTS_LO(); \
+        } while (0)
+// prohibit to send
+#    define rbuf_check_rts_hi()                          \
+        do {                                             \
+            if (RBUF_SPACE() <= 2) SERIAL_UART_RTS_HI(); \
+        } while (0)
 #else
-    #define rbuf_check_rts_lo()
-    #define rbuf_check_rts_hi()
+#    define rbuf_check_rts_lo()
+#    define rbuf_check_rts_hi()
 #endif
 
-
-void serial_init(void)
-{
-    SERIAL_UART_INIT();
-}
+void serial_init(void) { SERIAL_UART_INIT(); }
 
 // RX ring buffer
-#define RBUF_SIZE   256
+#define RBUF_SIZE 256
 static uint8_t rbuf[RBUF_SIZE];
 static uint8_t rbuf_head = 0;
 static uint8_t rbuf_tail = 0;
 
-uint8_t serial_recv(void)
-{
+uint8_t serial_recv(void) {
     uint8_t data = 0;
     if (rbuf_head == rbuf_tail) {
         return 0;
     }
 
-    data = rbuf[rbuf_tail];
+    data      = rbuf[rbuf_tail];
     rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
     rbuf_check_rts_lo();
     return data;
 }
 
-int16_t serial_recv2(void)
-{
+int16_t serial_recv2(void) {
     uint8_t data = 0;
     if (rbuf_head == rbuf_tail) {
         return -1;
     }
 
-    data = rbuf[rbuf_tail];
+    data      = rbuf[rbuf_tail];
     rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
     rbuf_check_rts_lo();
     return data;
 }
 
-void serial_send(uint8_t data)
-{
-    while (!SERIAL_UART_TXD_READY) ;
+void serial_send(uint8_t data) {
+    while (!SERIAL_UART_TXD_READY)
+        ;
     SERIAL_UART_DATA = data;
 }
 
 // USART RX complete interrupt
-ISR(SERIAL_UART_RXD_VECT)
-{
+ISR(SERIAL_UART_RXD_VECT) {
     uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
     if (next != rbuf_tail) {
         rbuf[rbuf_head] = SERIAL_UART_DATA;
-        rbuf_head = next;
+        rbuf_head       = next;
     }
     rbuf_check_rts_hi();
 }
index af49eeec3eb0d251bb41cacf3268f35f8869aa31..5349553b7a42ff0df0557f9dbe171674d03ce73b 100644 (file)
  */
 #ifdef KEYBOARD_SHARED_EP
 const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
-    #define SHARED_REPORT_STARTED
+#    define SHARED_REPORT_STARTED
 #else
 const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = {
 #endif
-    HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
-    HID_RI_USAGE(8, 0x06), // Keyboard
-    HID_RI_COLLECTION(8, 0x01), // Application
+    HID_RI_USAGE_PAGE(8, 0x01),  // Generic Desktop
+    HID_RI_USAGE(8, 0x06),       // Keyboard
+    HID_RI_COLLECTION(8, 0x01),  // Application
 #ifdef KEYBOARD_SHARED_EP
-        HID_RI_REPORT_ID(8, REPORT_ID_KEYBOARD),
+    HID_RI_REPORT_ID(8, REPORT_ID_KEYBOARD),
 #endif
-        // Modifiers (8 bits)
-        HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
-        HID_RI_USAGE_MINIMUM(8, 0xE0), // Keyboard Left Control
-        HID_RI_USAGE_MAXIMUM(8, 0xE7), // Keyboard Right GUI
-        HID_RI_LOGICAL_MINIMUM(8, 0x00),
-        HID_RI_LOGICAL_MAXIMUM(8, 0x01),
-        HID_RI_REPORT_COUNT(8, 0x08),
-        HID_RI_REPORT_SIZE(8, 0x01),
-        HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
-        // Reserved (1 byte)
-        HID_RI_REPORT_COUNT(8, 0x01),
-        HID_RI_REPORT_SIZE(8, 0x08),
-        HID_RI_INPUT(8, HID_IOF_CONSTANT),
-        // Keycodes (6 bytes)
-        HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
-        HID_RI_USAGE_MINIMUM(8, 0x00),
-        HID_RI_USAGE_MAXIMUM(8, 0xFF),
-        HID_RI_LOGICAL_MINIMUM(8, 0x00),
-        HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
-        HID_RI_REPORT_COUNT(8, 0x06),
-        HID_RI_REPORT_SIZE(8, 0x08),
-        HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
-
-        // Status LEDs (5 bits)
-        HID_RI_USAGE_PAGE(8, 0x08), // LED
-        HID_RI_USAGE_MINIMUM(8, 0x01), // Num Lock
-        HID_RI_USAGE_MAXIMUM(8, 0x05), // Kana
-        HID_RI_REPORT_COUNT(8, 0x05),
-        HID_RI_REPORT_SIZE(8, 0x01),
-        HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
-        // LED padding (3 bits)
-        HID_RI_REPORT_COUNT(8, 0x01),
-        HID_RI_REPORT_SIZE(8, 0x03),
-        HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
+    // Modifiers (8 bits)
+    HID_RI_USAGE_PAGE(8, 0x07),     // Keyboard/Keypad
+    HID_RI_USAGE_MINIMUM(8, 0xE0),  // Keyboard Left Control
+    HID_RI_USAGE_MAXIMUM(8, 0xE7),  // Keyboard Right GUI
+    HID_RI_LOGICAL_MINIMUM(8, 0x00),
+    HID_RI_LOGICAL_MAXIMUM(8, 0x01),
+    HID_RI_REPORT_COUNT(8, 0x08),
+    HID_RI_REPORT_SIZE(8, 0x01),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+    // Reserved (1 byte)
+    HID_RI_REPORT_COUNT(8, 0x01),
+    HID_RI_REPORT_SIZE(8, 0x08),
+    HID_RI_INPUT(8, HID_IOF_CONSTANT),
+    // Keycodes (6 bytes)
+    HID_RI_USAGE_PAGE(8, 0x07),  // Keyboard/Keypad
+    HID_RI_USAGE_MINIMUM(8, 0x00),
+    HID_RI_USAGE_MAXIMUM(8, 0xFF),
+    HID_RI_LOGICAL_MINIMUM(8, 0x00),
+    HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
+    HID_RI_REPORT_COUNT(8, 0x06),
+    HID_RI_REPORT_SIZE(8, 0x08),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
+
+    // Status LEDs (5 bits)
+    HID_RI_USAGE_PAGE(8, 0x08),     // LED
+    HID_RI_USAGE_MINIMUM(8, 0x01),  // Num Lock
+    HID_RI_USAGE_MAXIMUM(8, 0x05),  // Kana
+    HID_RI_REPORT_COUNT(8, 0x05),
+    HID_RI_REPORT_SIZE(8, 0x01),
+    HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
+    // LED padding (3 bits)
+    HID_RI_REPORT_COUNT(8, 0x01),
+    HID_RI_REPORT_SIZE(8, 0x03),
+    HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
     HID_RI_END_COLLECTION(0),
 #ifndef KEYBOARD_SHARED_EP
 };
 #endif
 
 #ifdef MOUSE_ENABLE
-    #ifndef MOUSE_SHARED_EP
+#    ifndef MOUSE_SHARED_EP
 const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = {
-    #elif !defined(SHARED_REPORT_STARTED)
+#    elif !defined(SHARED_REPORT_STARTED)
 const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
-        #define SHARED_REPORT_STARTED
-    #endif
-    HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
-    HID_RI_USAGE(8, 0x02), // Mouse
-    HID_RI_COLLECTION(8, 0x01), // Application
-    #ifdef MOUSE_SHARED_EP
-        HID_RI_REPORT_ID(8, REPORT_ID_MOUSE),
-    #endif
-        HID_RI_USAGE(8, 0x01), // Pointer
-        HID_RI_COLLECTION(8, 0x00), // Physical
-            // Buttons (5 bits)
-            HID_RI_USAGE_PAGE(8, 0x09), // Button
-            HID_RI_USAGE_MINIMUM(8, 0x01), // Button 1
-            HID_RI_USAGE_MAXIMUM(8, 0x05), // Button 5
-            HID_RI_LOGICAL_MINIMUM(8, 0x00),
-            HID_RI_LOGICAL_MAXIMUM(8, 0x01),
-            HID_RI_REPORT_COUNT(8, 0x05),
-            HID_RI_REPORT_SIZE(8, 0x01),
-            HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
-            // Button padding (3 bits)
-            HID_RI_REPORT_COUNT(8, 0x01),
-            HID_RI_REPORT_SIZE(8, 0x03),
-            HID_RI_INPUT(8, HID_IOF_CONSTANT),
-
-            // X/Y position (2 bytes)
-            HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
-            HID_RI_USAGE(8, 0x30), // X
-            HID_RI_USAGE(8, 0x31), // Y
-            HID_RI_LOGICAL_MINIMUM(8, -127),
-            HID_RI_LOGICAL_MAXIMUM(8, 127),
-            HID_RI_REPORT_COUNT(8, 0x02),
-            HID_RI_REPORT_SIZE(8, 0x08),
-            HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
-
-            // Vertical wheel (1 byte)
-            HID_RI_USAGE(8, 0x38), // Wheel
-            HID_RI_LOGICAL_MINIMUM(8, -127),
-            HID_RI_LOGICAL_MAXIMUM(8, 127),
-            HID_RI_REPORT_COUNT(8, 0x01),
-            HID_RI_REPORT_SIZE(8, 0x08),
-            HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
-            // Horizontal wheel (1 byte)
-            HID_RI_USAGE_PAGE(8, 0x0C), // Consumer
-            HID_RI_USAGE(16, 0x0238), // AC Pan
-            HID_RI_LOGICAL_MINIMUM(8, -127),
-            HID_RI_LOGICAL_MAXIMUM(8, 127),
-            HID_RI_REPORT_COUNT(8, 0x01),
-            HID_RI_REPORT_SIZE(8, 0x08),
-            HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
-        HID_RI_END_COLLECTION(0),
+#        define SHARED_REPORT_STARTED
+#    endif
+    HID_RI_USAGE_PAGE(8, 0x01),  // Generic Desktop
+    HID_RI_USAGE(8, 0x02),       // Mouse
+    HID_RI_COLLECTION(8, 0x01),  // Application
+#    ifdef MOUSE_SHARED_EP
+    HID_RI_REPORT_ID(8, REPORT_ID_MOUSE),
+#    endif
+    HID_RI_USAGE(8, 0x01),       // Pointer
+    HID_RI_COLLECTION(8, 0x00),  // Physical
+                                 // Buttons (5 bits)
+    HID_RI_USAGE_PAGE(8, 0x09),     // Button
+    HID_RI_USAGE_MINIMUM(8, 0x01),  // Button 1
+    HID_RI_USAGE_MAXIMUM(8, 0x05),  // Button 5
+    HID_RI_LOGICAL_MINIMUM(8, 0x00),
+    HID_RI_LOGICAL_MAXIMUM(8, 0x01),
+    HID_RI_REPORT_COUNT(8, 0x05),
+    HID_RI_REPORT_SIZE(8, 0x01),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+    // Button padding (3 bits)
+    HID_RI_REPORT_COUNT(8, 0x01),
+    HID_RI_REPORT_SIZE(8, 0x03),
+    HID_RI_INPUT(8, HID_IOF_CONSTANT),
+
+    // X/Y position (2 bytes)
+    HID_RI_USAGE_PAGE(8, 0x01),  // Generic Desktop
+    HID_RI_USAGE(8, 0x30),       // X
+    HID_RI_USAGE(8, 0x31),       // Y
+    HID_RI_LOGICAL_MINIMUM(8, -127),
+    HID_RI_LOGICAL_MAXIMUM(8, 127),
+    HID_RI_REPORT_COUNT(8, 0x02),
+    HID_RI_REPORT_SIZE(8, 0x08),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
+
+    // Vertical wheel (1 byte)
+    HID_RI_USAGE(8, 0x38),  // Wheel
+    HID_RI_LOGICAL_MINIMUM(8, -127),
+    HID_RI_LOGICAL_MAXIMUM(8, 127),
+    HID_RI_REPORT_COUNT(8, 0x01),
+    HID_RI_REPORT_SIZE(8, 0x08),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
+    // Horizontal wheel (1 byte)
+    HID_RI_USAGE_PAGE(8, 0x0C),  // Consumer
+    HID_RI_USAGE(16, 0x0238),    // AC Pan
+    HID_RI_LOGICAL_MINIMUM(8, -127),
+    HID_RI_LOGICAL_MAXIMUM(8, 127),
+    HID_RI_REPORT_COUNT(8, 0x01),
+    HID_RI_REPORT_SIZE(8, 0x08),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
     HID_RI_END_COLLECTION(0),
-    #ifndef MOUSE_SHARED_EP
+    HID_RI_END_COLLECTION(0),
+#    ifndef MOUSE_SHARED_EP
 };
-    #endif
+#    endif
 #endif
 
 #if defined(SHARED_EP_ENABLE) && !defined(SHARED_REPORT_STARTED)
@@ -160,68 +160,68 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
 #endif
 
 #ifdef EXTRAKEY_ENABLE
-    HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
-    HID_RI_USAGE(8, 0x80), // System Control
-    HID_RI_COLLECTION(8, 0x01), // Application
-        HID_RI_REPORT_ID(8, REPORT_ID_SYSTEM),
-        HID_RI_USAGE_MINIMUM(16, 0x0081), // System Power Down
-        HID_RI_USAGE_MAXIMUM(16, 0x0083), // System Wake Up
-        HID_RI_LOGICAL_MINIMUM(16, 0x0001),
-        HID_RI_LOGICAL_MAXIMUM(16, 0x0003),
-        HID_RI_REPORT_COUNT(8, 1),
-        HID_RI_REPORT_SIZE(8, 16),
-        HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
+    HID_RI_USAGE_PAGE(8, 0x01),  // Generic Desktop
+    HID_RI_USAGE(8, 0x80),       // System Control
+    HID_RI_COLLECTION(8, 0x01),  // Application
+    HID_RI_REPORT_ID(8, REPORT_ID_SYSTEM),
+    HID_RI_USAGE_MINIMUM(16, 0x0081),  // System Power Down
+    HID_RI_USAGE_MAXIMUM(16, 0x0083),  // System Wake Up
+    HID_RI_LOGICAL_MINIMUM(16, 0x0001),
+    HID_RI_LOGICAL_MAXIMUM(16, 0x0003),
+    HID_RI_REPORT_COUNT(8, 1),
+    HID_RI_REPORT_SIZE(8, 16),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
     HID_RI_END_COLLECTION(0),
 
-    HID_RI_USAGE_PAGE(8, 0x0C), // Consumer
-    HID_RI_USAGE(8, 0x01), // Consumer Control
-    HID_RI_COLLECTION(8, 0x01), // Application
-        HID_RI_REPORT_ID(8, REPORT_ID_CONSUMER),
-        HID_RI_USAGE_MINIMUM(16, 0x0001), // Consumer Control
-        HID_RI_USAGE_MAXIMUM(16, 0x029C), // AC Distribute Vertically
-        HID_RI_LOGICAL_MINIMUM(16, 0x0001),
-        HID_RI_LOGICAL_MAXIMUM(16, 0x029C),
-        HID_RI_REPORT_COUNT(8, 1),
-        HID_RI_REPORT_SIZE(8, 16),
-        HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
+    HID_RI_USAGE_PAGE(8, 0x0C),  // Consumer
+    HID_RI_USAGE(8, 0x01),       // Consumer Control
+    HID_RI_COLLECTION(8, 0x01),  // Application
+    HID_RI_REPORT_ID(8, REPORT_ID_CONSUMER),
+    HID_RI_USAGE_MINIMUM(16, 0x0001),  // Consumer Control
+    HID_RI_USAGE_MAXIMUM(16, 0x029C),  // AC Distribute Vertically
+    HID_RI_LOGICAL_MINIMUM(16, 0x0001),
+    HID_RI_LOGICAL_MAXIMUM(16, 0x029C),
+    HID_RI_REPORT_COUNT(8, 1),
+    HID_RI_REPORT_SIZE(8, 16),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
     HID_RI_END_COLLECTION(0),
 #endif
 
 #ifdef NKRO_ENABLE
-    HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
-    HID_RI_USAGE(8, 0x06), // Keyboard
-    HID_RI_COLLECTION(8, 0x01), // Application
-        HID_RI_REPORT_ID(8, REPORT_ID_NKRO),
-        // Modifiers (8 bits)
-        HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
-        HID_RI_USAGE_MINIMUM(8, 0xE0), // Keyboard Left Control
-        HID_RI_USAGE_MAXIMUM(8, 0xE7), // Keyboard Right GUI
-        HID_RI_LOGICAL_MINIMUM(8, 0x00),
-        HID_RI_LOGICAL_MAXIMUM(8, 0x01),
-        HID_RI_REPORT_COUNT(8, 0x08),
-        HID_RI_REPORT_SIZE(8, 0x01),
-        HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
-        // Keycodes
-        HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
-        HID_RI_USAGE_MINIMUM(8, 0x00),
-        HID_RI_USAGE_MAXIMUM(8, KEYBOARD_REPORT_BITS * 8 - 1),
-        HID_RI_LOGICAL_MINIMUM(8, 0x00),
-        HID_RI_LOGICAL_MAXIMUM(8, 0x01),
-        HID_RI_REPORT_COUNT(8, KEYBOARD_REPORT_BITS * 8),
-        HID_RI_REPORT_SIZE(8, 0x01),
-        HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
-
-        // Status LEDs (5 bits)
-        HID_RI_USAGE_PAGE(8, 0x08), // LED
-        HID_RI_USAGE_MINIMUM(8, 0x01), // Num Lock
-        HID_RI_USAGE_MAXIMUM(8, 0x05), // Kana
-        HID_RI_REPORT_COUNT(8, 0x05),
-        HID_RI_REPORT_SIZE(8, 0x01),
-        HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
-        // LED padding (3 bits)
-        HID_RI_REPORT_COUNT(8, 0x01),
-        HID_RI_REPORT_SIZE(8, 0x03),
-        HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
+    HID_RI_USAGE_PAGE(8, 0x01),  // Generic Desktop
+    HID_RI_USAGE(8, 0x06),       // Keyboard
+    HID_RI_COLLECTION(8, 0x01),  // Application
+    HID_RI_REPORT_ID(8, REPORT_ID_NKRO),
+    // Modifiers (8 bits)
+    HID_RI_USAGE_PAGE(8, 0x07),     // Keyboard/Keypad
+    HID_RI_USAGE_MINIMUM(8, 0xE0),  // Keyboard Left Control
+    HID_RI_USAGE_MAXIMUM(8, 0xE7),  // Keyboard Right GUI
+    HID_RI_LOGICAL_MINIMUM(8, 0x00),
+    HID_RI_LOGICAL_MAXIMUM(8, 0x01),
+    HID_RI_REPORT_COUNT(8, 0x08),
+    HID_RI_REPORT_SIZE(8, 0x01),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+    // Keycodes
+    HID_RI_USAGE_PAGE(8, 0x07),  // Keyboard/Keypad
+    HID_RI_USAGE_MINIMUM(8, 0x00),
+    HID_RI_USAGE_MAXIMUM(8, KEYBOARD_REPORT_BITS * 8 - 1),
+    HID_RI_LOGICAL_MINIMUM(8, 0x00),
+    HID_RI_LOGICAL_MAXIMUM(8, 0x01),
+    HID_RI_REPORT_COUNT(8, KEYBOARD_REPORT_BITS * 8),
+    HID_RI_REPORT_SIZE(8, 0x01),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+
+    // Status LEDs (5 bits)
+    HID_RI_USAGE_PAGE(8, 0x08),     // LED
+    HID_RI_USAGE_MINIMUM(8, 0x01),  // Num Lock
+    HID_RI_USAGE_MAXIMUM(8, 0x05),  // Kana
+    HID_RI_REPORT_COUNT(8, 0x05),
+    HID_RI_REPORT_SIZE(8, 0x01),
+    HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
+    // LED padding (3 bits)
+    HID_RI_REPORT_COUNT(8, 0x01),
+    HID_RI_REPORT_SIZE(8, 0x03),
+    HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
     HID_RI_END_COLLECTION(0),
 #endif
 #ifdef SHARED_EP_ENABLE
@@ -230,46 +230,46 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
 
 #ifdef RAW_ENABLE
 const USB_Descriptor_HIDReport_Datatype_t PROGMEM RawReport[] = {
-    HID_RI_USAGE_PAGE(16, 0xFF60), // Vendor Defined
-    HID_RI_USAGE(8, 0x61), // Vendor Defined
-    HID_RI_COLLECTION(8, 0x01), // Application
-        // Data to host
-        HID_RI_USAGE(8, 0x62), // Vendor Defined
-        HID_RI_LOGICAL_MINIMUM(8, 0x00),
-        HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
-        HID_RI_REPORT_COUNT(8, RAW_EPSIZE),
-        HID_RI_REPORT_SIZE(8, 0x08),
-        HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
-        // Data from host
-        HID_RI_USAGE(8, 0x63), // Vendor Defined
-        HID_RI_LOGICAL_MINIMUM(8, 0x00),
-        HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
-        HID_RI_REPORT_COUNT(8, RAW_EPSIZE),
-        HID_RI_REPORT_SIZE(8, 0x08),
-        HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
+    HID_RI_USAGE_PAGE(16, 0xFF60),  // Vendor Defined
+    HID_RI_USAGE(8, 0x61),          // Vendor Defined
+    HID_RI_COLLECTION(8, 0x01),     // Application
+                                 // Data to host
+    HID_RI_USAGE(8, 0x62),  // Vendor Defined
+    HID_RI_LOGICAL_MINIMUM(8, 0x00),
+    HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
+    HID_RI_REPORT_COUNT(8, RAW_EPSIZE),
+    HID_RI_REPORT_SIZE(8, 0x08),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+    // Data from host
+    HID_RI_USAGE(8, 0x63),  // Vendor Defined
+    HID_RI_LOGICAL_MINIMUM(8, 0x00),
+    HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
+    HID_RI_REPORT_COUNT(8, RAW_EPSIZE),
+    HID_RI_REPORT_SIZE(8, 0x08),
+    HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
     HID_RI_END_COLLECTION(0),
 };
 #endif
 
 #ifdef CONSOLE_ENABLE
 const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
-    HID_RI_USAGE_PAGE(16, 0xFF31), // Vendor Defined (PJRC Teensy compatible)
-    HID_RI_USAGE(8, 0x74), // Vendor Defined (PJRC Teensy compatible)
-    HID_RI_COLLECTION(8, 0x01), // Application
-        // Data to host
-        HID_RI_USAGE(8, 0x75), // Vendor Defined
-        HID_RI_LOGICAL_MINIMUM(8, 0x00),
-        HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
-        HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
-        HID_RI_REPORT_SIZE(8, 0x08),
-        HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
-        // Data from host
-        HID_RI_USAGE(8, 0x76), // Vendor Defined
-        HID_RI_LOGICAL_MINIMUM(8, 0x00),
-        HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
-        HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
-        HID_RI_REPORT_SIZE(8, 0x08),
-        HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
+    HID_RI_USAGE_PAGE(16, 0xFF31),  // Vendor Defined (PJRC Teensy compatible)
+    HID_RI_USAGE(8, 0x74),          // Vendor Defined (PJRC Teensy compatible)
+    HID_RI_COLLECTION(8, 0x01),     // Application
+                                 // Data to host
+    HID_RI_USAGE(8, 0x75),  // Vendor Defined
+    HID_RI_LOGICAL_MINIMUM(8, 0x00),
+    HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
+    HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
+    HID_RI_REPORT_SIZE(8, 0x08),
+    HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+    // Data from host
+    HID_RI_USAGE(8, 0x76),  // Vendor Defined
+    HID_RI_LOGICAL_MINIMUM(8, 0x00),
+    HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
+    HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
+    HID_RI_REPORT_SIZE(8, 0x08),
+    HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
     HID_RI_END_COLLECTION(0),
 };
 #endif
@@ -277,577 +277,225 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
 /*
  * Device descriptor
  */
-const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
-    .Header = {
-        .Size               = sizeof(USB_Descriptor_Device_t),
-        .Type               = DTYPE_Device
-    },
-    .USBSpecification       = VERSION_BCD(1, 1, 0),
+const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {.Header           = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
+                                                          .USBSpecification = VERSION_BCD(1, 1, 0),
 #if VIRTSER_ENABLE
-    .Class                  = USB_CSCP_IADDeviceClass,
-    .SubClass               = USB_CSCP_IADDeviceSubclass,
-    .Protocol               = USB_CSCP_IADDeviceProtocol,
+                                                          .Class    = USB_CSCP_IADDeviceClass,
+                                                          .SubClass = USB_CSCP_IADDeviceSubclass,
+                                                          .Protocol = USB_CSCP_IADDeviceProtocol,
 #else
-    .Class                  = USB_CSCP_NoDeviceClass,
-    .SubClass               = USB_CSCP_NoDeviceSubclass,
-    .Protocol               = USB_CSCP_NoDeviceProtocol,
+                                                              .Class    = USB_CSCP_NoDeviceClass,
+                                                              .SubClass = USB_CSCP_NoDeviceSubclass,
+                                                              .Protocol = USB_CSCP_NoDeviceProtocol,
 #endif
-    .Endpoint0Size          = FIXED_CONTROL_ENDPOINT_SIZE,
-    // Specified in config.h
-    .VendorID               = VENDOR_ID,
-    .ProductID              = PRODUCT_ID,
-    .ReleaseNumber          = DEVICE_VER,
-    .ManufacturerStrIndex   = 0x01,
-    .ProductStrIndex        = 0x02,
-    .SerialNumStrIndex      = 0x03,
-    .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
-};
+                                                          .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
+                                                          // Specified in config.h
+                                                          .VendorID               = VENDOR_ID,
+                                                          .ProductID              = PRODUCT_ID,
+                                                          .ReleaseNumber          = DEVICE_VER,
+                                                          .ManufacturerStrIndex   = 0x01,
+                                                          .ProductStrIndex        = 0x02,
+                                                          .SerialNumStrIndex      = 0x03,
+                                                          .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS};
 
 #ifndef USB_MAX_POWER_CONSUMPTION
-    #define USB_MAX_POWER_CONSUMPTION 500
+#    define USB_MAX_POWER_CONSUMPTION 500
 #endif
 
 /*
  * Configuration descriptors
  */
-const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
-    .Config = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Configuration_Header_t),
-            .Type               = DTYPE_Configuration
-        },
-        .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
-        .TotalInterfaces        = TOTAL_INTERFACES,
-        .ConfigurationNumber    = 1,
-        .ConfigurationStrIndex  = NO_DESCRIPTOR,
-        .ConfigAttributes       = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_REMOTEWAKEUP),
-        .MaxPowerConsumption    = USB_CONFIG_POWER_MA(USB_MAX_POWER_CONSUMPTION)
-    },
+const USB_Descriptor_Configuration_t PROGMEM
+                                     ConfigurationDescriptor =
+        {
+            .Config = {.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), .TotalInterfaces = TOTAL_INTERFACES, .ConfigurationNumber = 1, .ConfigurationStrIndex = NO_DESCRIPTOR, .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_REMOTEWAKEUP), .MaxPowerConsumption = USB_CONFIG_POWER_MA(USB_MAX_POWER_CONSUMPTION)},
 
 #ifndef KEYBOARD_SHARED_EP
-    /*
-     * Keyboard
-     */
-    .Keyboard_Interface = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_t),
-            .Type               = DTYPE_Interface
-        },
-        .InterfaceNumber        = KEYBOARD_INTERFACE,
-        .AlternateSetting       = 0x00,
-        .TotalEndpoints         = 1,
-        .Class                  = HID_CSCP_HIDClass,
-        .SubClass               = HID_CSCP_BootSubclass,
-        .Protocol               = HID_CSCP_KeyboardBootProtocol,
-
-        .InterfaceStrIndex      = NO_DESCRIPTOR
-    },
-    .Keyboard_HID = {
-        .Header = {
-            .Size               = sizeof(USB_HID_Descriptor_HID_t),
-            .Type               = HID_DTYPE_HID
-        },
-        .HIDSpec                = VERSION_BCD(1, 1, 1),
-        .CountryCode            = 0x00,
-        .TotalReportDescriptors = 1,
-        .HIDReportType          = HID_DTYPE_Report,
-        .HIDReportLength        = sizeof(KeyboardReport)
-    },
-    .Keyboard_INEndpoint = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Endpoint_t),
-            .Type               = DTYPE_Endpoint
-        },
-        .EndpointAddress        = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM),
-        .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-        .EndpointSize           = KEYBOARD_EPSIZE,
-        .PollingIntervalMS      = 0x0A
-    },
+            /*
+             * Keyboard
+             */
+            .Keyboard_Interface  = {.Header           = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+                                   .InterfaceNumber  = KEYBOARD_INTERFACE,
+                                   .AlternateSetting = 0x00,
+                                   .TotalEndpoints   = 1,
+                                   .Class            = HID_CSCP_HIDClass,
+                                   .SubClass         = HID_CSCP_BootSubclass,
+                                   .Protocol         = HID_CSCP_KeyboardBootProtocol,
+
+                                   .InterfaceStrIndex = NO_DESCRIPTOR},
+            .Keyboard_HID        = {.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, .HIDSpec = VERSION_BCD(1, 1, 1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, .HIDReportLength = sizeof(KeyboardReport)},
+            .Keyboard_INEndpoint = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, .EndpointAddress = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = KEYBOARD_EPSIZE, .PollingIntervalMS = 0x0A},
 #endif
 
 #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
-    /*
-     * Mouse
-     */
-    .Mouse_Interface = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_t),
-            .Type               = DTYPE_Interface
-        },
-        .InterfaceNumber        = MOUSE_INTERFACE,
-        .AlternateSetting       = 0x00,
-        .TotalEndpoints         = 1,
-        .Class                  = HID_CSCP_HIDClass,
-        .SubClass               = HID_CSCP_BootSubclass,
-        .Protocol               = HID_CSCP_MouseBootProtocol,
-        .InterfaceStrIndex      = NO_DESCRIPTOR
-    },
-    .Mouse_HID = {
-        .Header = {
-            .Size               = sizeof(USB_HID_Descriptor_HID_t),
-            .Type               = HID_DTYPE_HID
-        },
-        .HIDSpec                = VERSION_BCD(1, 1, 1),
-        .CountryCode            = 0x00,
-        .TotalReportDescriptors = 1,
-        .HIDReportType          = HID_DTYPE_Report,
-        .HIDReportLength        = sizeof(MouseReport)
-    },
-    .Mouse_INEndpoint = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Endpoint_t),
-            .Type               = DTYPE_Endpoint
-        },
-        .EndpointAddress        = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM),
-        .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-        .EndpointSize           = MOUSE_EPSIZE,
-        .PollingIntervalMS      = 0x0A
-    },
+            /*
+             * Mouse
+             */
+            .Mouse_Interface  = {.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, .InterfaceNumber = MOUSE_INTERFACE, .AlternateSetting = 0x00, .TotalEndpoints = 1, .Class = HID_CSCP_HIDClass, .SubClass = HID_CSCP_BootSubclass, .Protocol = HID_CSCP_MouseBootProtocol, .InterfaceStrIndex = NO_DESCRIPTOR},
+            .Mouse_HID        = {.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, .HIDSpec = VERSION_BCD(1, 1, 1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, .HIDReportLength = sizeof(MouseReport)},
+            .Mouse_INEndpoint = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, .EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = MOUSE_EPSIZE, .PollingIntervalMS = 0x0A},
 #endif
 
 #ifdef SHARED_EP_ENABLE
-    /*
-     * Shared
-     */
-    .Shared_Interface = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_t),
-            .Type               = DTYPE_Interface
-        },
-        .InterfaceNumber        = SHARED_INTERFACE,
-        .AlternateSetting       = 0x00,
-        .TotalEndpoints         = 1,
-        .Class                  = HID_CSCP_HIDClass,
-#ifdef KEYBOARD_SHARED_EP
-        .SubClass               = HID_CSCP_BootSubclass,
-        .Protocol               = HID_CSCP_KeyboardBootProtocol,
-#else
-        .SubClass               = HID_CSCP_NonBootSubclass,
-        .Protocol               = HID_CSCP_NonBootProtocol,
-#endif
-        .InterfaceStrIndex      = NO_DESCRIPTOR
-    },
-    .Shared_HID = {
-        .Header = {
-            .Size               = sizeof(USB_HID_Descriptor_HID_t),
-            .Type               = HID_DTYPE_HID
-        },
-        .HIDSpec                = VERSION_BCD(1, 1, 1),
-        .CountryCode            = 0x00,
-        .TotalReportDescriptors = 1,
-        .HIDReportType          = HID_DTYPE_Report,
-        .HIDReportLength        = sizeof(SharedReport)
-    },
-    .Shared_INEndpoint = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Endpoint_t),
-            .Type               = DTYPE_Endpoint
-        },
-        .EndpointAddress        = (ENDPOINT_DIR_IN | SHARED_IN_EPNUM),
-        .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-        .EndpointSize           = SHARED_EPSIZE,
-        .PollingIntervalMS      = 0x0A
-    },
+            /*
+             * Shared
+             */
+            .Shared_Interface  = {.Header           = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+                                 .InterfaceNumber  = SHARED_INTERFACE,
+                                 .AlternateSetting = 0x00,
+                                 .TotalEndpoints   = 1,
+                                 .Class            = HID_CSCP_HIDClass,
+#    ifdef KEYBOARD_SHARED_EP
+                                 .SubClass = HID_CSCP_BootSubclass,
+                                 .Protocol = HID_CSCP_KeyboardBootProtocol,
+#    else
+                                 .SubClass = HID_CSCP_NonBootSubclass,
+                                 .Protocol = HID_CSCP_NonBootProtocol,
+#    endif
+                                 .InterfaceStrIndex = NO_DESCRIPTOR},
+            .Shared_HID        = {.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, .HIDSpec = VERSION_BCD(1, 1, 1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, .HIDReportLength = sizeof(SharedReport)},
+            .Shared_INEndpoint = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, .EndpointAddress = (ENDPOINT_DIR_IN | SHARED_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = SHARED_EPSIZE, .PollingIntervalMS = 0x0A},
 #endif
 
 #ifdef RAW_ENABLE
-    /*
-     * Raw HID
-     */
-    .Raw_Interface = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_t),
-            .Type               = DTYPE_Interface
-        },
-        .InterfaceNumber        = RAW_INTERFACE,
-        .AlternateSetting       = 0x00,
-        .TotalEndpoints         = 2,
-        .Class                  = HID_CSCP_HIDClass,
-        .SubClass               = HID_CSCP_NonBootSubclass,
-        .Protocol               = HID_CSCP_NonBootProtocol,
-        .InterfaceStrIndex      = NO_DESCRIPTOR
-    },
-    .Raw_HID = {
-        .Header = {
-            .Size               = sizeof(USB_HID_Descriptor_HID_t),
-            .Type               = HID_DTYPE_HID
-        },
-        .HIDSpec                = VERSION_BCD(1, 1, 1),
-        .CountryCode            = 0x00,
-        .TotalReportDescriptors = 1,
-        .HIDReportType          = HID_DTYPE_Report,
-        .HIDReportLength        = sizeof(RawReport)
-    },
-    .Raw_INEndpoint = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Endpoint_t),
-            .Type               = DTYPE_Endpoint
-        },
-        .EndpointAddress        = (ENDPOINT_DIR_IN | RAW_IN_EPNUM),
-        .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-        .EndpointSize           = RAW_EPSIZE,
-        .PollingIntervalMS      = 0x01
-    },
-    .Raw_OUTEndpoint = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Endpoint_t),
-            .Type               = DTYPE_Endpoint
-        },
-        .EndpointAddress        = (ENDPOINT_DIR_OUT | RAW_OUT_EPNUM),
-        .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-        .EndpointSize           = RAW_EPSIZE,
-        .PollingIntervalMS      = 0x01
-    },
+            /*
+             * Raw HID
+             */
+            .Raw_Interface   = {.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, .InterfaceNumber = RAW_INTERFACE, .AlternateSetting = 0x00, .TotalEndpoints = 2, .Class = HID_CSCP_HIDClass, .SubClass = HID_CSCP_NonBootSubclass, .Protocol = HID_CSCP_NonBootProtocol, .InterfaceStrIndex = NO_DESCRIPTOR},
+            .Raw_HID         = {.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, .HIDSpec = VERSION_BCD(1, 1, 1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, .HIDReportLength = sizeof(RawReport)},
+            .Raw_INEndpoint  = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, .EndpointAddress = (ENDPOINT_DIR_IN | RAW_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = RAW_EPSIZE, .PollingIntervalMS = 0x01},
+            .Raw_OUTEndpoint = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, .EndpointAddress = (ENDPOINT_DIR_OUT | RAW_OUT_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = RAW_EPSIZE, .PollingIntervalMS = 0x01},
 #endif
 
 #ifdef CONSOLE_ENABLE
-    /*
-     * Console
-     */
-    .Console_Interface = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_t),
-            .Type               = DTYPE_Interface
-        },
-        .InterfaceNumber        = CONSOLE_INTERFACE,
-        .AlternateSetting       = 0x00,
-        .TotalEndpoints         = 2,
-        .Class                  = HID_CSCP_HIDClass,
-        .SubClass               = HID_CSCP_NonBootSubclass,
-        .Protocol               = HID_CSCP_NonBootProtocol,
-        .InterfaceStrIndex      = NO_DESCRIPTOR
-    },
-    .Console_HID = {
-        .Header = {
-            .Size               = sizeof(USB_HID_Descriptor_HID_t),
-            .Type               = HID_DTYPE_HID
-        },
-        .HIDSpec                = VERSION_BCD(1, 1, 1),
-        .CountryCode            = 0x00,
-        .TotalReportDescriptors = 1,
-        .HIDReportType          = HID_DTYPE_Report,
-        .HIDReportLength        = sizeof(ConsoleReport)
-    },
-    .Console_INEndpoint = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Endpoint_t),
-            .Type               = DTYPE_Endpoint
-        },
-        .EndpointAddress        = (ENDPOINT_DIR_IN | CONSOLE_IN_EPNUM),
-        .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-        .EndpointSize           = CONSOLE_EPSIZE,
-        .PollingIntervalMS      = 0x01
-    },
-    .Console_OUTEndpoint = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Endpoint_t),
-            .Type               = DTYPE_Endpoint
-        },
-        .EndpointAddress        = (ENDPOINT_DIR_OUT | CONSOLE_OUT_EPNUM),
-        .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-        .EndpointSize           = CONSOLE_EPSIZE,
-        .PollingIntervalMS      = 0x01
-    },
+            /*
+             * Console
+             */
+            .Console_Interface   = {.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, .InterfaceNumber = CONSOLE_INTERFACE, .AlternateSetting = 0x00, .TotalEndpoints = 2, .Class = HID_CSCP_HIDClass, .SubClass = HID_CSCP_NonBootSubclass, .Protocol = HID_CSCP_NonBootProtocol, .InterfaceStrIndex = NO_DESCRIPTOR},
+            .Console_HID         = {.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, .HIDSpec = VERSION_BCD(1, 1, 1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, .HIDReportLength = sizeof(ConsoleReport)},
+            .Console_INEndpoint  = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, .EndpointAddress = (ENDPOINT_DIR_IN | CONSOLE_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = CONSOLE_EPSIZE, .PollingIntervalMS = 0x01},
+            .Console_OUTEndpoint = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, .EndpointAddress = (ENDPOINT_DIR_OUT | CONSOLE_OUT_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = CONSOLE_EPSIZE, .PollingIntervalMS = 0x01},
 #endif
 
 #ifdef MIDI_ENABLE
-    /*
-     * MIDI
-     */
-    .Audio_Interface_Association = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_Association_t),
-            .Type               = DTYPE_InterfaceAssociation
-        },
-        .FirstInterfaceIndex    = AC_INTERFACE,
-        .TotalInterfaces        = 2,
-        .Class                  = AUDIO_CSCP_AudioClass,
-        .SubClass               = AUDIO_CSCP_ControlSubclass,
-        .Protocol               = AUDIO_CSCP_ControlProtocol,
-        .IADStrIndex            = NO_DESCRIPTOR,
-    },
-    .Audio_ControlInterface = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_t),
-            .Type               = DTYPE_Interface
-        },
-
-        .InterfaceNumber        = AC_INTERFACE,
-        .AlternateSetting       = 0,
-        .TotalEndpoints         = 0,
-        .Class                  = AUDIO_CSCP_AudioClass,
-        .SubClass               = AUDIO_CSCP_ControlSubclass,
-        .Protocol               = AUDIO_CSCP_ControlProtocol,
-        .InterfaceStrIndex      = NO_DESCRIPTOR
-    },
-    .Audio_ControlInterface_SPC = {
-        .Header = {
-            .Size               = sizeof(USB_Audio_Descriptor_Interface_AC_t),
-            .Type               = AUDIO_DTYPE_CSInterface
-        },
-        .Subtype                = AUDIO_DSUBTYPE_CSInterface_Header,
-        .ACSpecification        = VERSION_BCD(1, 0, 0),
-        .TotalLength            = sizeof(USB_Audio_Descriptor_Interface_AC_t),
-        .InCollection           = 1,
-        .InterfaceNumber        = AS_INTERFACE,
-    },
-    .Audio_StreamInterface = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_t),
-            .Type               = DTYPE_Interface
-        },
-
-        .InterfaceNumber        = AS_INTERFACE,
-        .AlternateSetting       = 0,
-        .TotalEndpoints         = 2,
-        .Class                  = AUDIO_CSCP_AudioClass,
-        .SubClass               = AUDIO_CSCP_MIDIStreamingSubclass,
-        .Protocol               = AUDIO_CSCP_StreamingProtocol,
-        .InterfaceStrIndex      = NO_DESCRIPTOR
-    },
-    .Audio_StreamInterface_SPC = {
-        .Header = {
-            .Size               = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t),
-            .Type               = AUDIO_DTYPE_CSInterface
-        },
-        .Subtype                = AUDIO_DSUBTYPE_CSInterface_General,
-        .AudioSpecification     = VERSION_BCD(1, 0, 0),
-        .TotalLength            = offsetof(USB_Descriptor_Configuration_t, MIDI_Out_Jack_Endpoint_SPC) + sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t) - offsetof(USB_Descriptor_Configuration_t, Audio_StreamInterface_SPC)
-    },
-    .MIDI_In_Jack_Emb = {
-        .Header = {
-            .Size               = sizeof(USB_MIDI_Descriptor_InputJack_t),
-            .Type               = AUDIO_DTYPE_CSInterface
-        },
-        .Subtype                = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
-        .JackType               = MIDI_JACKTYPE_Embedded,
-        .JackID                 = 0x01,
-        .JackStrIndex           = NO_DESCRIPTOR
-    },
-    .MIDI_In_Jack_Ext = {
-        .Header = {
-            .Size               = sizeof(USB_MIDI_Descriptor_InputJack_t),
-            .Type               = AUDIO_DTYPE_CSInterface
-        },
-        .Subtype                = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
-        .JackType               = MIDI_JACKTYPE_External,
-        .JackID                 = 0x02,
-        .JackStrIndex           = NO_DESCRIPTOR
-    },
-    .MIDI_Out_Jack_Emb = {
-        .Header = {
-            .Size               = sizeof(USB_MIDI_Descriptor_OutputJack_t),
-            .Type               = AUDIO_DTYPE_CSInterface
-        },
-        .Subtype                = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
-        .JackType               = MIDI_JACKTYPE_Embedded,
-        .JackID                 = 0x03,
-        .NumberOfPins           = 1,
-        .SourceJackID           = {0x02},
-        .SourcePinID            = {0x01},
-        .JackStrIndex           = NO_DESCRIPTOR
-    },
-    .MIDI_Out_Jack_Ext = {
-        .Header = {
-            .Size               = sizeof(USB_MIDI_Descriptor_OutputJack_t),
-            .Type               = AUDIO_DTYPE_CSInterface
-        },
-        .Subtype                = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
-        .JackType               = MIDI_JACKTYPE_External,
-        .JackID                 = 0x04,
-        .NumberOfPins           = 1,
-        .SourceJackID           = {0x01},
-        .SourcePinID            = {0x01},
-        .JackStrIndex           = NO_DESCRIPTOR
-    },
-    .MIDI_In_Jack_Endpoint = {
-        .Endpoint = {
-            .Header = {
-                .Size           = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t),
-                .Type           = DTYPE_Endpoint
-            },
-            .EndpointAddress    = MIDI_STREAM_OUT_EPADDR,
-            .Attributes         = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-            .EndpointSize       = MIDI_STREAM_EPSIZE,
-            .PollingIntervalMS  = 0x05
-        },
-
-        .Refresh                = 0,
-        .SyncEndpointNumber     = 0
-    },
-    .MIDI_In_Jack_Endpoint_SPC = {
-        .Header = {
-            .Size               = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t),
-            .Type               = AUDIO_DSUBTYPE_CSEndpoint_General
-        },
-        .Subtype                = AUDIO_DSUBTYPE_CSEndpoint_General,
-        .TotalEmbeddedJacks     = 0x01,
-        .AssociatedJackID       = {0x01}
-    },
-    .MIDI_Out_Jack_Endpoint = {
-        .Endpoint = {
-            .Header = {
-                .Size           = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t),
-                .Type           = DTYPE_Endpoint
-            },
-            .EndpointAddress    = MIDI_STREAM_IN_EPADDR,
-            .Attributes         = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-            .EndpointSize       = MIDI_STREAM_EPSIZE,
-            .PollingIntervalMS  = 0x05
-        },
-
-        .Refresh                = 0,
-        .SyncEndpointNumber     = 0
-    },
-    .MIDI_Out_Jack_Endpoint_SPC = {
-        .Header = {
-            .Size               = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t),
-            .Type               = AUDIO_DTYPE_CSEndpoint
-        },
-        .Subtype                = AUDIO_DSUBTYPE_CSEndpoint_General,
-        .TotalEmbeddedJacks     = 0x01,
-        .AssociatedJackID       = {0x03}
-    },
+            /*
+             * MIDI
+             */
+            .Audio_Interface_Association =
+                {
+                    .Header              = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
+                    .FirstInterfaceIndex = AC_INTERFACE,
+                    .TotalInterfaces     = 2,
+                    .Class               = AUDIO_CSCP_AudioClass,
+                    .SubClass            = AUDIO_CSCP_ControlSubclass,
+                    .Protocol            = AUDIO_CSCP_ControlProtocol,
+                    .IADStrIndex         = NO_DESCRIPTOR,
+                },
+            .Audio_ControlInterface = {.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+
+                                       .InterfaceNumber   = AC_INTERFACE,
+                                       .AlternateSetting  = 0,
+                                       .TotalEndpoints    = 0,
+                                       .Class             = AUDIO_CSCP_AudioClass,
+                                       .SubClass          = AUDIO_CSCP_ControlSubclass,
+                                       .Protocol          = AUDIO_CSCP_ControlProtocol,
+                                       .InterfaceStrIndex = NO_DESCRIPTOR},
+            .Audio_ControlInterface_SPC =
+                {
+                    .Header          = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = AUDIO_DTYPE_CSInterface},
+                    .Subtype         = AUDIO_DSUBTYPE_CSInterface_Header,
+                    .ACSpecification = VERSION_BCD(1, 0, 0),
+                    .TotalLength     = sizeof(USB_Audio_Descriptor_Interface_AC_t),
+                    .InCollection    = 1,
+                    .InterfaceNumber = AS_INTERFACE,
+                },
+            .Audio_StreamInterface      = {.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+
+                                      .InterfaceNumber   = AS_INTERFACE,
+                                      .AlternateSetting  = 0,
+                                      .TotalEndpoints    = 2,
+                                      .Class             = AUDIO_CSCP_AudioClass,
+                                      .SubClass          = AUDIO_CSCP_MIDIStreamingSubclass,
+                                      .Protocol          = AUDIO_CSCP_StreamingProtocol,
+                                      .InterfaceStrIndex = NO_DESCRIPTOR},
+            .Audio_StreamInterface_SPC  = {.Header = {.Size = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t), .Type = AUDIO_DTYPE_CSInterface}, .Subtype = AUDIO_DSUBTYPE_CSInterface_General, .AudioSpecification = VERSION_BCD(1, 0, 0), .TotalLength = offsetof(USB_Descriptor_Configuration_t, MIDI_Out_Jack_Endpoint_SPC) + sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t) - offsetof(USB_Descriptor_Configuration_t, Audio_StreamInterface_SPC)},
+            .MIDI_In_Jack_Emb           = {.Header = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = AUDIO_DTYPE_CSInterface}, .Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal, .JackType = MIDI_JACKTYPE_Embedded, .JackID = 0x01, .JackStrIndex = NO_DESCRIPTOR},
+            .MIDI_In_Jack_Ext           = {.Header = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = AUDIO_DTYPE_CSInterface}, .Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal, .JackType = MIDI_JACKTYPE_External, .JackID = 0x02, .JackStrIndex = NO_DESCRIPTOR},
+            .MIDI_Out_Jack_Emb          = {.Header = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = AUDIO_DTYPE_CSInterface}, .Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal, .JackType = MIDI_JACKTYPE_Embedded, .JackID = 0x03, .NumberOfPins = 1, .SourceJackID = {0x02}, .SourcePinID = {0x01}, .JackStrIndex = NO_DESCRIPTOR},
+            .MIDI_Out_Jack_Ext          = {.Header = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = AUDIO_DTYPE_CSInterface}, .Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal, .JackType = MIDI_JACKTYPE_External, .JackID = 0x04, .NumberOfPins = 1, .SourceJackID = {0x01}, .SourcePinID = {0x01}, .JackStrIndex = NO_DESCRIPTOR},
+            .MIDI_In_Jack_Endpoint      = {.Endpoint = {.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint}, .EndpointAddress = MIDI_STREAM_OUT_EPADDR, .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = MIDI_STREAM_EPSIZE, .PollingIntervalMS = 0x05},
+
+                                      .Refresh            = 0,
+                                      .SyncEndpointNumber = 0},
+            .MIDI_In_Jack_Endpoint_SPC  = {.Header = {.Size = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t), .Type = AUDIO_DSUBTYPE_CSEndpoint_General}, .Subtype = AUDIO_DSUBTYPE_CSEndpoint_General, .TotalEmbeddedJacks = 0x01, .AssociatedJackID = {0x01}},
+            .MIDI_Out_Jack_Endpoint     = {.Endpoint = {.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint}, .EndpointAddress = MIDI_STREAM_IN_EPADDR, .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = MIDI_STREAM_EPSIZE, .PollingIntervalMS = 0x05},
+
+                                       .Refresh            = 0,
+                                       .SyncEndpointNumber = 0},
+            .MIDI_Out_Jack_Endpoint_SPC = {.Header = {.Size = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t), .Type = AUDIO_DTYPE_CSEndpoint}, .Subtype = AUDIO_DSUBTYPE_CSEndpoint_General, .TotalEmbeddedJacks = 0x01, .AssociatedJackID = {0x03}},
 #endif
 
 #ifdef VIRTSER_ENABLE
-    /*
-     * Virtual Serial
-     */
-    .CDC_Interface_Association = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_Association_t),
-            .Type               = DTYPE_InterfaceAssociation
-        },
-        .FirstInterfaceIndex    = CCI_INTERFACE,
-        .TotalInterfaces        = 2,
-        .Class                  = CDC_CSCP_CDCClass,
-        .SubClass               = CDC_CSCP_ACMSubclass,
-        .Protocol               = CDC_CSCP_ATCommandProtocol,
-        .IADStrIndex            = NO_DESCRIPTOR,
-    },
-    .CDC_CCI_Interface = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_t),
-            .Type               = DTYPE_Interface
-        },
-        .InterfaceNumber        = CCI_INTERFACE,
-        .AlternateSetting       = 0,
-        .TotalEndpoints         = 1,
-        .Class                  = CDC_CSCP_CDCClass,
-        .SubClass               = CDC_CSCP_ACMSubclass,
-        .Protocol               = CDC_CSCP_ATCommandProtocol,
-        .InterfaceStrIndex      = NO_DESCRIPTOR
-    },
-    .CDC_Functional_Header = {
-        .Header = {
-            .Size               = sizeof(USB_CDC_Descriptor_FunctionalHeader_t),
-            .Type               = CDC_DTYPE_CSInterface
-        },
-        .Subtype                = 0x00,
-        .CDCSpecification       = VERSION_BCD(1, 1, 0),
-    },
-    .CDC_Functional_ACM = {
-        .Header = {
-            .Size               = sizeof(USB_CDC_Descriptor_FunctionalACM_t),
-            .Type               = CDC_DTYPE_CSInterface
-        },
-        .Subtype                = 0x02,
-        .Capabilities           = 0x02,
-    },
-    .CDC_Functional_Union = {
-        .Header = {
-            .Size               = sizeof(USB_CDC_Descriptor_FunctionalUnion_t),
-            .Type               = CDC_DTYPE_CSInterface
-        },
-        .Subtype                = 0x06,
-        .MasterInterfaceNumber  = CCI_INTERFACE,
-        .SlaveInterfaceNumber   = CDI_INTERFACE,
-    },
-    .CDC_NotificationEndpoint = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Endpoint_t),
-            .Type               = DTYPE_Endpoint
-        },
-        .EndpointAddress        = CDC_NOTIFICATION_EPADDR,
-        .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-        .EndpointSize           = CDC_NOTIFICATION_EPSIZE,
-        .PollingIntervalMS      = 0xFF
-    },
-    .CDC_DCI_Interface = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Interface_t),
-            .Type               = DTYPE_Interface
-        },
-        .InterfaceNumber        = CDI_INTERFACE,
-        .AlternateSetting       = 0,
-        .TotalEndpoints         = 2,
-        .Class                  = CDC_CSCP_CDCDataClass,
-        .SubClass               = CDC_CSCP_NoDataSubclass,
-        .Protocol               = CDC_CSCP_NoDataProtocol,
-        .InterfaceStrIndex      = NO_DESCRIPTOR
-    },
-    .CDC_DataOutEndpoint = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Endpoint_t),
-            .Type               = DTYPE_Endpoint
-        },
-        .EndpointAddress        = CDC_OUT_EPADDR,
-        .Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-        .EndpointSize           = CDC_EPSIZE,
-        .PollingIntervalMS      = 0x05
-    },
-    .CDC_DataInEndpoint = {
-        .Header = {
-            .Size               = sizeof(USB_Descriptor_Endpoint_t),
-            .Type               = DTYPE_Endpoint
-        },
-        .EndpointAddress        = CDC_IN_EPADDR,
-        .Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-        .EndpointSize           = CDC_EPSIZE,
-        .PollingIntervalMS      = 0x05
-    },
+            /*
+             * Virtual Serial
+             */
+            .CDC_Interface_Association =
+                {
+                    .Header              = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
+                    .FirstInterfaceIndex = CCI_INTERFACE,
+                    .TotalInterfaces     = 2,
+                    .Class               = CDC_CSCP_CDCClass,
+                    .SubClass            = CDC_CSCP_ACMSubclass,
+                    .Protocol            = CDC_CSCP_ATCommandProtocol,
+                    .IADStrIndex         = NO_DESCRIPTOR,
+                },
+            .CDC_CCI_Interface = {.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, .InterfaceNumber = CCI_INTERFACE, .AlternateSetting = 0, .TotalEndpoints = 1, .Class = CDC_CSCP_CDCClass, .SubClass = CDC_CSCP_ACMSubclass, .Protocol = CDC_CSCP_ATCommandProtocol, .InterfaceStrIndex = NO_DESCRIPTOR},
+            .CDC_Functional_Header =
+                {
+                    .Header           = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = CDC_DTYPE_CSInterface},
+                    .Subtype          = 0x00,
+                    .CDCSpecification = VERSION_BCD(1, 1, 0),
+                },
+            .CDC_Functional_ACM =
+                {
+                    .Header       = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = CDC_DTYPE_CSInterface},
+                    .Subtype      = 0x02,
+                    .Capabilities = 0x02,
+                },
+            .CDC_Functional_Union =
+                {
+                    .Header                = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = CDC_DTYPE_CSInterface},
+                    .Subtype               = 0x06,
+                    .MasterInterfaceNumber = CCI_INTERFACE,
+                    .SlaveInterfaceNumber  = CDI_INTERFACE,
+                },
+            .CDC_NotificationEndpoint = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, .EndpointAddress = CDC_NOTIFICATION_EPADDR, .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = CDC_NOTIFICATION_EPSIZE, .PollingIntervalMS = 0xFF},
+            .CDC_DCI_Interface        = {.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, .InterfaceNumber = CDI_INTERFACE, .AlternateSetting = 0, .TotalEndpoints = 2, .Class = CDC_CSCP_CDCDataClass, .SubClass = CDC_CSCP_NoDataSubclass, .Protocol = CDC_CSCP_NoDataProtocol, .InterfaceStrIndex = NO_DESCRIPTOR},
+            .CDC_DataOutEndpoint      = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, .EndpointAddress = CDC_OUT_EPADDR, .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = CDC_EPSIZE, .PollingIntervalMS = 0x05},
+            .CDC_DataInEndpoint       = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, .EndpointAddress = CDC_IN_EPADDR, .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = CDC_EPSIZE, .PollingIntervalMS = 0x05},
 #endif
 };
 
 /*
  * String descriptors
  */
-const USB_Descriptor_String_t PROGMEM LanguageString = {
-    .Header = {
-        .Size      = USB_STRING_LEN(1),
-        .Type      = DTYPE_String
-    },
-    .UnicodeString = {LANGUAGE_ID_ENG}
-};
+const USB_Descriptor_String_t PROGMEM LanguageString = {.Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, .UnicodeString = {LANGUAGE_ID_ENG}};
 
-const USB_Descriptor_String_t PROGMEM ManufacturerString = {
-    .Header = {
-        .Size      = USB_STRING_LEN(sizeof(STR(MANUFACTURER)) - 1), // Subtract 1 for null terminator
-        .Type      = DTYPE_String
-    },
-    .UnicodeString = LSTR(MANUFACTURER)
-};
+const USB_Descriptor_String_t PROGMEM ManufacturerString = {.Header        = {.Size = USB_STRING_LEN(sizeof(STR(MANUFACTURER)) - 1),  // Subtract 1 for null terminator
+                                                                       .Type = DTYPE_String},
+                                                            .UnicodeString = LSTR(MANUFACTURER)};
 
-const USB_Descriptor_String_t PROGMEM ProductString = {
-    .Header = {
-        .Size      = USB_STRING_LEN(sizeof(STR(PRODUCT)) - 1), // Subtract 1 for null terminator
-        .Type      = DTYPE_String
-    },
-    .UnicodeString = LSTR(PRODUCT)
-};
+const USB_Descriptor_String_t PROGMEM ProductString = {.Header        = {.Size = USB_STRING_LEN(sizeof(STR(PRODUCT)) - 1),  // Subtract 1 for null terminator
+                                                                  .Type = DTYPE_String},
+                                                       .UnicodeString = LSTR(PRODUCT)};
 
 #ifndef SERIAL_NUMBER
-    #define SERIAL_NUMBER 0
+#    define SERIAL_NUMBER 0
 #endif
 
-const USB_Descriptor_String_t PROGMEM SerialNumberString = {
-    .Header = {
-        .Size      = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1), // Subtract 1 for null terminator
-        .Type      = DTYPE_String
-    },
-    .UnicodeString = LSTR(SERIAL_NUMBER)
-};
+const USB_Descriptor_String_t PROGMEM SerialNumberString = {.Header        = {.Size = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1),  // Subtract 1 for null terminator
+                                                                       .Type = DTYPE_String},
+                                                            .UnicodeString = LSTR(SERIAL_NUMBER)};
 
 /**
  * This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
index d419568034a17537cca69b02a8f98d376993e0f9..e922edc4523f54960fb11c3cd3191652c7af7250 100644 (file)
  *  Header file for Descriptors.c.
  */
 #ifndef _DESCRIPTORS_H_
-    #define _DESCRIPTORS_H_
+#define _DESCRIPTORS_H_
 
-    #include <LUFA/Drivers/USB/USB.h>
+#include <LUFA/Drivers/USB/USB.h>
 
-    #ifdef PROTOCOL_CHIBIOS
-        #include "hal.h"
-    #endif
+#ifdef PROTOCOL_CHIBIOS
+#    include "hal.h"
+#endif
 
 /*
  * USB descriptor structure
  */
 typedef struct {
-    USB_Descriptor_Configuration_Header_t    Config;
+    USB_Descriptor_Configuration_Header_t Config;
 
-    #ifndef KEYBOARD_SHARED_EP
+#ifndef KEYBOARD_SHARED_EP
     // Keyboard HID Interface
-    USB_Descriptor_Interface_t                Keyboard_Interface;
-    USB_HID_Descriptor_HID_t                  Keyboard_HID;
-    USB_Descriptor_Endpoint_t                 Keyboard_INEndpoint;
-    #endif
+    USB_Descriptor_Interface_t Keyboard_Interface;
+    USB_HID_Descriptor_HID_t   Keyboard_HID;
+    USB_Descriptor_Endpoint_t  Keyboard_INEndpoint;
+#endif
 
-    #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
+#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
     // Mouse HID Interface
-     USB_Descriptor_Interface_t               Mouse_Interface;
-    USB_HID_Descriptor_HID_t                  Mouse_HID;
-    USB_Descriptor_Endpoint_t                 Mouse_INEndpoint;
-    #endif
+    USB_Descriptor_Interface_t Mouse_Interface;
+    USB_HID_Descriptor_HID_t   Mouse_HID;
+    USB_Descriptor_Endpoint_t  Mouse_INEndpoint;
+#endif
 
-    #ifdef SHARED_EP_ENABLE
+#ifdef SHARED_EP_ENABLE
     // Shared Interface
-    USB_Descriptor_Interface_t                Shared_Interface;
-    USB_HID_Descriptor_HID_t                  Shared_HID;
-    USB_Descriptor_Endpoint_t                 Shared_INEndpoint;
-    #endif
+    USB_Descriptor_Interface_t Shared_Interface;
+    USB_HID_Descriptor_HID_t   Shared_HID;
+    USB_Descriptor_Endpoint_t  Shared_INEndpoint;
+#endif
 
-    #ifdef RAW_ENABLE
+#ifdef RAW_ENABLE
     // Raw HID Interface
-    USB_Descriptor_Interface_t                Raw_Interface;
-    USB_HID_Descriptor_HID_t                  Raw_HID;
-    USB_Descriptor_Endpoint_t                 Raw_INEndpoint;
-    USB_Descriptor_Endpoint_t                 Raw_OUTEndpoint;
-    #endif
+    USB_Descriptor_Interface_t Raw_Interface;
+    USB_HID_Descriptor_HID_t   Raw_HID;
+    USB_Descriptor_Endpoint_t  Raw_INEndpoint;
+    USB_Descriptor_Endpoint_t  Raw_OUTEndpoint;
+#endif
 
-    #ifdef CONSOLE_ENABLE
+#ifdef CONSOLE_ENABLE
     // Console HID Interface
-    USB_Descriptor_Interface_t                Console_Interface;
-    USB_HID_Descriptor_HID_t                  Console_HID;
-    USB_Descriptor_Endpoint_t                 Console_INEndpoint;
-    USB_Descriptor_Endpoint_t                 Console_OUTEndpoint;
-    #endif
-
-    #ifdef MIDI_ENABLE
-    USB_Descriptor_Interface_Association_t    Audio_Interface_Association;
+    USB_Descriptor_Interface_t Console_Interface;
+    USB_HID_Descriptor_HID_t   Console_HID;
+    USB_Descriptor_Endpoint_t  Console_INEndpoint;
+    USB_Descriptor_Endpoint_t  Console_OUTEndpoint;
+#endif
+
+#ifdef MIDI_ENABLE
+    USB_Descriptor_Interface_Association_t Audio_Interface_Association;
     // MIDI Audio Control Interface
-    USB_Descriptor_Interface_t                Audio_ControlInterface;
-    USB_Audio_Descriptor_Interface_AC_t       Audio_ControlInterface_SPC;
+    USB_Descriptor_Interface_t          Audio_ControlInterface;
+    USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;
     // MIDI Audio Streaming Interface
     USB_Descriptor_Interface_t                Audio_StreamInterface;
     USB_MIDI_Descriptor_AudioInterface_AS_t   Audio_StreamInterface_SPC;
@@ -108,146 +108,146 @@ typedef struct {
     USB_MIDI_Descriptor_Jack_Endpoint_t       MIDI_In_Jack_Endpoint_SPC;
     USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
     USB_MIDI_Descriptor_Jack_Endpoint_t       MIDI_Out_Jack_Endpoint_SPC;
-    #endif
+#endif
 
-    #ifdef VIRTSER_ENABLE
-    USB_Descriptor_Interface_Association_t    CDC_Interface_Association;
+#ifdef VIRTSER_ENABLE
+    USB_Descriptor_Interface_Association_t CDC_Interface_Association;
     // CDC Control Interface
-    USB_Descriptor_Interface_t                CDC_CCI_Interface;
-    USB_CDC_Descriptor_FunctionalHeader_t     CDC_Functional_Header;
-    USB_CDC_Descriptor_FunctionalACM_t        CDC_Functional_ACM;
-    USB_CDC_Descriptor_FunctionalUnion_t      CDC_Functional_Union;
-    USB_Descriptor_Endpoint_t                 CDC_NotificationEndpoint;
+    USB_Descriptor_Interface_t            CDC_CCI_Interface;
+    USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header;
+    USB_CDC_Descriptor_FunctionalACM_t    CDC_Functional_ACM;
+    USB_CDC_Descriptor_FunctionalUnion_t  CDC_Functional_Union;
+    USB_Descriptor_Endpoint_t             CDC_NotificationEndpoint;
     // CDC Data Interface
-    USB_Descriptor_Interface_t                CDC_DCI_Interface;
-    USB_Descriptor_Endpoint_t                 CDC_DataOutEndpoint;
-    USB_Descriptor_Endpoint_t                 CDC_DataInEndpoint;
-    #endif
+    USB_Descriptor_Interface_t CDC_DCI_Interface;
+    USB_Descriptor_Endpoint_t  CDC_DataOutEndpoint;
+    USB_Descriptor_Endpoint_t  CDC_DataInEndpoint;
+#endif
 } USB_Descriptor_Configuration_t;
 
 /*
  * Interface indexes
  */
 enum usb_interfaces {
-    #ifndef KEYBOARD_SHARED_EP
+#ifndef KEYBOARD_SHARED_EP
     KEYBOARD_INTERFACE,
-    #else
-        #define KEYBOARD_INTERFACE SHARED_INTERFACE
-    #endif
-
-    // It is important that the Raw HID interface is at a constant
-    // interface number, to support Linux/OSX platforms and chrome.hid
-    // If Raw HID is enabled, let it be always 1.
-    #ifdef RAW_ENABLE
+#else
+#    define KEYBOARD_INTERFACE SHARED_INTERFACE
+#endif
+
+// It is important that the Raw HID interface is at a constant
+// interface number, to support Linux/OSX platforms and chrome.hid
+// If Raw HID is enabled, let it be always 1.
+#ifdef RAW_ENABLE
     RAW_INTERFACE,
-    #endif
+#endif
 
-    #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
+#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
     MOUSE_INTERFACE,
-    #endif
+#endif
 
-    #ifdef SHARED_EP_ENABLE
+#ifdef SHARED_EP_ENABLE
     SHARED_INTERFACE,
-    #endif
+#endif
 
-    #ifdef CONSOLE_ENABLE
+#ifdef CONSOLE_ENABLE
     CONSOLE_INTERFACE,
-    #endif
+#endif
 
-    #ifdef MIDI_ENABLE
+#ifdef MIDI_ENABLE
     AC_INTERFACE,
     AS_INTERFACE,
-    #endif
+#endif
 
-    #ifdef VIRTSER_ENABLE
+#ifdef VIRTSER_ENABLE
     CCI_INTERFACE,
     CDI_INTERFACE,
-    #endif
+#endif
 
     TOTAL_INTERFACES
 };
 
-    #define NEXT_EPNUM __COUNTER__
+#define NEXT_EPNUM __COUNTER__
 
 /*
  * Endpoint numbers
  */
 enum usb_endpoints {
-    __unused_epnum__ = NEXT_EPNUM, // Endpoint numbering starts at 1
+    __unused_epnum__ = NEXT_EPNUM,  // Endpoint numbering starts at 1
 
-    #ifndef KEYBOARD_SHARED_EP
+#ifndef KEYBOARD_SHARED_EP
     KEYBOARD_IN_EPNUM = NEXT_EPNUM,
-    #else
-        #define KEYBOARD_IN_EPNUM SHARED_IN_EPNUM
-    #endif
+#else
+#    define KEYBOARD_IN_EPNUM SHARED_IN_EPNUM
+#endif
 
-    #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
+#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
     MOUSE_IN_EPNUM = NEXT_EPNUM,
-    #else
-        #define MOUSE_IN_EPNUM SHARED_IN_EPNUM
-    #endif
+#else
+#    define MOUSE_IN_EPNUM SHARED_IN_EPNUM
+#endif
 
-    #ifdef RAW_ENABLE
-    RAW_IN_EPNUM = NEXT_EPNUM,
+#ifdef RAW_ENABLE
+    RAW_IN_EPNUM  = NEXT_EPNUM,
     RAW_OUT_EPNUM = NEXT_EPNUM,
-    #endif
+#endif
 
-    #ifdef SHARED_EP_ENABLE
+#ifdef SHARED_EP_ENABLE
     SHARED_IN_EPNUM = NEXT_EPNUM,
-    #endif
+#endif
 
-    #ifdef CONSOLE_ENABLE
+#ifdef CONSOLE_ENABLE
     CONSOLE_IN_EPNUM = NEXT_EPNUM,
 
-        #ifdef PROTOCOL_CHIBIOS
+#    ifdef PROTOCOL_CHIBIOS
     // ChibiOS has enough memory and descriptor to actually enable the endpoint
     // It could use the same endpoint numbers, as that's supported by ChibiOS
     // But the QMK code currently assumes that the endpoint numbers are different
     CONSOLE_OUT_EPNUM = NEXT_EPNUM,
-        #else
-            #define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
-        #endif
-    #endif
+#    else
+#        define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
+#    endif
+#endif
 
-    #ifdef MIDI_ENABLE
-    MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
+#ifdef MIDI_ENABLE
+    MIDI_STREAM_IN_EPNUM  = NEXT_EPNUM,
     MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
-        #define MIDI_STREAM_IN_EPADDR  (ENDPOINT_DIR_IN  | MIDI_STREAM_IN_EPNUM)
-        #define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
-    #endif
+#    define MIDI_STREAM_IN_EPADDR (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
+#    define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
+#endif
 
-    #ifdef VIRTSER_ENABLE
+#ifdef VIRTSER_ENABLE
     CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
-    CDC_IN_EPNUM = NEXT_EPNUM,
-    CDC_OUT_EPNUM = NEXT_EPNUM,
-        #define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN  | CDC_NOTIFICATION_EPNUM)
-        #define CDC_IN_EPADDR           (ENDPOINT_DIR_IN  | CDC_IN_EPNUM)
-        #define CDC_OUT_EPADDR          (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM)
-    #endif
+    CDC_IN_EPNUM           = NEXT_EPNUM,
+    CDC_OUT_EPNUM          = NEXT_EPNUM,
+#    define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM)
+#    define CDC_IN_EPADDR (ENDPOINT_DIR_IN | CDC_IN_EPNUM)
+#    define CDC_OUT_EPADDR (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM)
+#endif
 };
 
-    #ifdef PROTOCOL_LUFA
-        // LUFA tells us total endpoints including control
-        #define MAX_ENDPOINTS (ENDPOINT_TOTAL_ENDPOINTS - 1)
-    #elif defined(PROTOCOL_CHIBIOS)
-        // ChibiOS gives us number of available user endpoints, not control
-        #define MAX_ENDPOINTS USB_MAX_ENDPOINTS
-    #endif
-
-    // TODO - ARM_ATSAM
-
-    #if (NEXT_EPNUM - 1) > MAX_ENDPOINTS
-        #error There are not enough available endpoints to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Console, NKRO, MIDI, Serial, Steno
-    #endif
-
-    #define KEYBOARD_EPSIZE          8
-    #define SHARED_EPSIZE           32
-    #define MOUSE_EPSIZE             8
-    #define RAW_EPSIZE              32
-    #define CONSOLE_EPSIZE          32
-    #define MIDI_STREAM_EPSIZE      64
-    #define CDC_NOTIFICATION_EPSIZE  8
-    #define CDC_EPSIZE              16
+#ifdef PROTOCOL_LUFA
+// LUFA tells us total endpoints including control
+#    define MAX_ENDPOINTS (ENDPOINT_TOTAL_ENDPOINTS - 1)
+#elif defined(PROTOCOL_CHIBIOS)
+// ChibiOS gives us number of available user endpoints, not control
+#    define MAX_ENDPOINTS USB_MAX_ENDPOINTS
+#endif
+
+// TODO - ARM_ATSAM
+
+#if (NEXT_EPNUM - 1) > MAX_ENDPOINTS
+#    error There are not enough available endpoints to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Console, NKRO, MIDI, Serial, Steno
+#endif
+
+#define KEYBOARD_EPSIZE 8
+#define SHARED_EPSIZE 32
+#define MOUSE_EPSIZE 8
+#define RAW_EPSIZE 32
+#define CONSOLE_EPSIZE 32
+#define MIDI_STREAM_EPSIZE 64
+#define CDC_NOTIFICATION_EPSIZE 8
+#define CDC_EPSIZE 16
 
 uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const void** const DescriptorAddress);
 #endif
index 86c2188c878e53065e43a55eb318a45049483a32..f8322d94ac73bfcd17561a0e9b780ff7474d1872 100644 (file)
 #include "uart.h"
 #include "debug.h"
 
-
 #define UART_BAUD_RATE 115200
 
-
 /* This is from main.c of USBaspLoader */
-static void initForUsbConnectivity(void)
-{
+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 */
+    usbDeviceDisconnect(); /* do this while interrupts are disabled */
+    while (--i) {          /* fake USB disconnect for > 250 ms */
         wdt_reset();
         _delay_ms(1);
     }
@@ -41,8 +38,7 @@ static void initForUsbConnectivity(void)
     sei();
 }
 
-int main(void)
-{
+int main(void) {
     bool suspended = false;
 #if USB_COUNT_SOF
     uint16_t last_timer = timer_read();
@@ -68,26 +64,26 @@ int main(void)
     while (1) {
 #if USB_COUNT_SOF
         if (usbSofCount != 0) {
-            suspended = false;
+            suspended   = false;
             usbSofCount = 0;
-            last_timer = timer_read();
+            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');
-*/
+                /*
+                                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
index 8d24f87d1ec254c034b82a57f065d48341531d15..42bd9ee363d931285a0c7be8c62707085695ca75 100644 (file)
@@ -6,18 +6,14 @@
 #include "oddebug.h"
 #include "sendchar.h"
 
-
 #if DEBUG_LEVEL > 0
 /* from oddebug.c */
-int8_t sendchar(uint8_t c)
-{
-    while(!(ODDBG_USR & (1 << ODDBG_UDRE)));    /* wait for data register empty */
+int8_t sendchar(uint8_t c) {
+    while (!(ODDBG_USR & (1 << ODDBG_UDRE)))
+        ; /* wait for data register empty */
     ODDBG_UDR = c;
     return 1;
 }
 #else
-int8_t sendchar(uint8_t c)
-{
-    return 1;
-}
+int8_t sendchar(uint8_t c) { return 1; }
 #endif
index 945457c1f4112298844956e9e6cea66c9921fa70..bcd28ff0147c8d9d42cb1cc70a7a98086a86b8df 100644 (file)
 
 #if DEBUG_LEVEL > 0
 
-#warning "Never compile production devices with debugging enabled"
+#    warning "Never compile production devices with debugging enabled"
 
-static void uartPutc(char c)
-{
-    while(!(ODDBG_USR & (1 << ODDBG_UDRE)));    /* wait for data register empty */
+static void uartPutc(char c) {
+    while (!(ODDBG_USR & (1 << ODDBG_UDRE)))
+        ; /* wait for data register empty */
     ODDBG_UDR = c;
 }
 
-static uchar    hexAscii(uchar h)
-{
+static uchar hexAscii(uchar h) {
     h &= 0xf;
-    if(h >= 10)
-        h += 'a' - (uchar)10 - '0';
+    if (h >= 10) h += 'a' - (uchar)10 - '0';
     h += '0';
     return h;
 }
 
-static void printHex(uchar c)
-{
+static void printHex(uchar c) {
     uartPutc(hexAscii(c >> 4));
     uartPutc(hexAscii(c));
 }
 
-void    odDebug(uchar prefix, uchar *data, uchar len)
-{
+void odDebug(uchar prefix, uchar *data, uchar len) {
     printHex(prefix);
     uartPutc(':');
-    while(len--){
+    while (len--) {
         uartPutc(' ');
         printHex(*data++);
     }
index d61309daacf0d7138fecb4006c9f903c40400e90..f93f338794537887554c24937ff1fcc46f007a71 100644 (file)
@@ -23,39 +23,38 @@ A debug log consists of a label ('prefix') to indicate which debug log created
 the output and a memory block to dump in hex ('data' and 'len').
 */
 
-
 #ifndef F_CPU
-#   define  F_CPU   12000000    /* 12 MHz */
+#    define F_CPU 12000000 /* 12 MHz */
 #endif
 
 /* make sure we have the UART defines: */
 #include "usbportability.h"
 
 #ifndef uchar
-#   define  uchar   unsigned char
+#    define uchar unsigned char
 #endif
 
 #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
-#   warning "Debugging disabled because device has no UART"
-#   undef   DEBUG_LEVEL
+#    warning "Debugging disabled because device has no UART"
+#    undef DEBUG_LEVEL
 #endif
 
 #ifndef DEBUG_LEVEL
-#   define  DEBUG_LEVEL 0
+#    define DEBUG_LEVEL 0
 #endif
 
 /* ------------------------------------------------------------------------- */
 
 #if DEBUG_LEVEL > 0
-#   define  DBG1(prefix, data, len) odDebug(prefix, data, len)
+#    define DBG1(prefix, data, len) odDebug(prefix, data, len)
 #else
-#   define  DBG1(prefix, data, len)
+#    define DBG1(prefix, data, len)
 #endif
 
 #if DEBUG_LEVEL > 1
-#   define  DBG2(prefix, data, len) odDebug(prefix, data, len)
+#    define DBG2(prefix, data, len) odDebug(prefix, data, len)
 #else
-#   define  DBG2(prefix, data, len)
+#    define DBG2(prefix, data, len)
 #endif
 
 /* ------------------------------------------------------------------------- */
@@ -65,57 +64,56 @@ extern void odDebug(uchar prefix, uchar *data, uchar len);
 
 /* Try to find our control registers; ATMEL likes to rename these */
 
-#if defined UBRR
-#   define  ODDBG_UBRR  UBRR
-#elif defined UBRRL
-#   define  ODDBG_UBRR  UBRRL
-#elif defined UBRR0
-#   define  ODDBG_UBRR  UBRR0
-#elif defined UBRR0L
-#   define  ODDBG_UBRR  UBRR0L
-#endif
-
-#if defined UCR
-#   define  ODDBG_UCR   UCR
-#elif defined UCSRB
-#   define  ODDBG_UCR   UCSRB
-#elif defined UCSR0B
-#   define  ODDBG_UCR   UCSR0B
-#endif
-
-#if defined TXEN
-#   define  ODDBG_TXEN  TXEN
-#else
-#   define  ODDBG_TXEN  TXEN0
-#endif
-
-#if defined USR
-#   define  ODDBG_USR   USR
-#elif defined UCSRA
-#   define  ODDBG_USR   UCSRA
-#elif defined UCSR0A
-#   define  ODDBG_USR   UCSR0A
-#endif
-
-#if defined UDRE
-#   define  ODDBG_UDRE  UDRE
-#else
-#   define  ODDBG_UDRE  UDRE0
-#endif
-
-#if defined UDR
-#   define  ODDBG_UDR   UDR
-#elif defined UDR0
-#   define  ODDBG_UDR   UDR0
-#endif
-
-static inline void  odDebugInit(void)
-{
-    ODDBG_UCR |= (1<<ODDBG_TXEN);
+#    if defined UBRR
+#        define ODDBG_UBRR UBRR
+#    elif defined UBRRL
+#        define ODDBG_UBRR UBRRL
+#    elif defined UBRR0
+#        define ODDBG_UBRR UBRR0
+#    elif defined UBRR0L
+#        define ODDBG_UBRR UBRR0L
+#    endif
+
+#    if defined UCR
+#        define ODDBG_UCR UCR
+#    elif defined UCSRB
+#        define ODDBG_UCR UCSRB
+#    elif defined UCSR0B
+#        define ODDBG_UCR UCSR0B
+#    endif
+
+#    if defined TXEN
+#        define ODDBG_TXEN TXEN
+#    else
+#        define ODDBG_TXEN TXEN0
+#    endif
+
+#    if defined USR
+#        define ODDBG_USR USR
+#    elif defined UCSRA
+#        define ODDBG_USR UCSRA
+#    elif defined UCSR0A
+#        define ODDBG_USR UCSR0A
+#    endif
+
+#    if defined UDRE
+#        define ODDBG_UDRE UDRE
+#    else
+#        define ODDBG_UDRE UDRE0
+#    endif
+
+#    if defined UDR
+#        define ODDBG_UDR UDR
+#    elif defined UDR0
+#        define ODDBG_UDR UDR0
+#    endif
+
+static inline void odDebugInit(void) {
+    ODDBG_UCR |= (1 << ODDBG_TXEN);
     ODDBG_UBRR = F_CPU / (19200 * 16L) - 1;
 }
 #else
-#   define odDebugInit()
+#    define odDebugInit()
 #endif
 
 /* ------------------------------------------------------------------------- */
index 847710e2a090cc3ed245a10af527f33fc274aeb1..020ea51474eda1996bf0ddcc0e83486199f51849 100644 (file)
@@ -26,15 +26,15 @@ section at the end of this file).
 
 /* ---------------------------- Hardware Config ---------------------------- */
 
-#define USB_CFG_IOPORTNAME      D
+#define USB_CFG_IOPORTNAME D
 /* This is the port where the USB bus is connected. When you configure it to
  * "B", the registers PORTB, PINB and DDRB will be used.
  */
-#define USB_CFG_DMINUS_BIT      4
+#define USB_CFG_DMINUS_BIT 4
 /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
  * This may be any bit in the port.
  */
-#define USB_CFG_DPLUS_BIT       2
+#define USB_CFG_DPLUS_BIT 2
 /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
  * This may be any bit in the port. Please note that D+ must also be connected
  * to interrupt pin INT0! [You can also use other interrupts, see section
@@ -43,7 +43,7 @@ section at the end of this file).
  * interrupt, the USB interrupt will also be triggered at Start-Of-Frame
  * markers every millisecond.]
  */
-#define USB_CFG_CLOCK_KHZ       (F_CPU/1000)
+#define USB_CFG_CLOCK_KHZ (F_CPU / 1000)
 /* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000,
  * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code
  * require no crystal, they tolerate +/- 1% deviation from the nominal
@@ -52,7 +52,7 @@ section at the end of this file).
  * Since F_CPU should be defined to your actual clock rate anyway, you should
  * not need to modify this setting.
  */
-#define USB_CFG_CHECK_CRC       0
+#define USB_CFG_CHECK_CRC 0
 /* Define this to 1 if you want that the driver checks integrity of incoming
  * data packets (CRC checks). CRC checks cost quite a bit of code size and are
  * currently only available for 18 MHz crystal clock. You must choose
@@ -75,18 +75,18 @@ section at the end of this file).
 
 /* --------------------------- Functional Range ---------------------------- */
 
-#define USB_CFG_HAVE_INTRIN_ENDPOINT    0
+#define USB_CFG_HAVE_INTRIN_ENDPOINT 0
 /* Define this to 1 if you want to compile a version with two endpoints: The
  * default control endpoint 0 and an interrupt-in endpoint (any other endpoint
  * number).
  */
-#define USB_CFG_HAVE_INTRIN_ENDPOINT3   0
+#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
 /* Define this to 1 if you want to compile a version with three endpoints: The
  * default control endpoint 0, an interrupt-in endpoint 3 (or the number
  * configured below) and a catch-all default interrupt-in endpoint as above.
  * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
  */
-#define USB_CFG_EP3_NUMBER              3
+#define USB_CFG_EP3_NUMBER 3
 /* If the so-called endpoint 3 is used, it can now be configured to any other
  * endpoint number (except 0) with this macro. Default if undefined is 3.
  */
@@ -96,13 +96,13 @@ section at the end of this file).
  * Since the token is toggled BEFORE sending any data, the first packet is
  * sent with the oposite value of this configuration!
  */
-#define USB_CFG_IMPLEMENT_HALT          0
+#define USB_CFG_IMPLEMENT_HALT 0
 /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
  * for endpoint 1 (interrupt endpoint). Although you may not need this feature,
  * it is required by the standard. We have made it a config option because it
  * bloats the code considerably.
  */
-#define USB_CFG_SUPPRESS_INTR_CODE      0
+#define USB_CFG_SUPPRESS_INTR_CODE 0
 /* Define this to 1 if you want to declare interrupt-in endpoints, but don't
  * want to send any data over them. If this macro is defined to 1, functions
  * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
@@ -110,48 +110,48 @@ section at the end of this file).
  * (e.g. HID), but never want to send any data. This option saves a couple
  * of bytes in flash memory and the transmit buffers in RAM.
  */
-#define USB_CFG_INTR_POLL_INTERVAL      10
+#define USB_CFG_INTR_POLL_INTERVAL 10
 /* If you compile a version with endpoint 1 (interrupt-in), this is the poll
  * interval. The value is in milliseconds and must not be less than 10 ms for
  * low speed devices.
  */
-#define USB_CFG_IS_SELF_POWERED         0
+#define USB_CFG_IS_SELF_POWERED 0
 /* Define this to 1 if the device has its own power supply. Set it to 0 if the
  * device is powered from the USB bus.
  */
-#define USB_CFG_MAX_BUS_POWER           100
+#define USB_CFG_MAX_BUS_POWER 100
 /* Set this variable to the maximum USB bus power consumption of your device.
  * The value is in milliamperes. [It will be divided by two since USB
  * communicates power requirements in units of 2 mA.]
  */
-#define USB_CFG_IMPLEMENT_FN_WRITE      0
+#define USB_CFG_IMPLEMENT_FN_WRITE 0
 /* Set this to 1 if you want usbFunctionWrite() to be called for control-out
  * transfers. Set it to 0 if you don't need it and want to save a couple of
  * bytes.
  */
-#define USB_CFG_IMPLEMENT_FN_READ       0
+#define USB_CFG_IMPLEMENT_FN_READ 0
 /* Set this to 1 if you need to send control replies which are generated
  * "on the fly" when usbFunctionRead() is called. If you only want to send
  * data from a static buffer, set it to 0 and return the data from
  * usbFunctionSetup(). This saves a couple of bytes.
  */
-#define USB_CFG_IMPLEMENT_FN_WRITEOUT   0
+#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0
 /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints.
  * You must implement the function usbFunctionWriteOut() which receives all
  * interrupt/bulk data sent to any endpoint other than 0. The endpoint number
  * can be found in 'usbRxToken'.
  */
-#define USB_CFG_HAVE_FLOWCONTROL        0
+#define USB_CFG_HAVE_FLOWCONTROL 0
 /* Define this to 1 if you want flowcontrol over USB data. See the definition
  * of the macros usbDisableAllRequests() and usbEnableAllRequests() in
  * usbdrv.h.
  */
-#define USB_CFG_DRIVER_FLASH_PAGE       0
+#define USB_CFG_DRIVER_FLASH_PAGE 0
 /* If the device has more than 64 kBytes of flash, define this to the 64 k page
  * where the driver's constants (descriptors) are located. Or in other words:
  * Define this to 1 for boot loaders on the ATMega128.
  */
-#define USB_CFG_LONG_TRANSFERS          0
+#define USB_CFG_LONG_TRANSFERS 0
 /* Define this to 1 if you want to send/receive blocks of more than 254 bytes
  * in a single control-in or control-out transfer. Note that the capability
  * for long transfers increases the driver size.
@@ -172,7 +172,7 @@ section at the end of this file).
 /* This macro (if defined) is executed when a USB SET_ADDRESS request was
  * received.
  */
-#define USB_COUNT_SOF                   0
+#define USB_COUNT_SOF 0
 /* define this macro to 1 if you need the global variable "usbSofCount" which
  * counts SOF packets. This feature requires that the hardware interrupt is
  * connected to D- instead of D+.
@@ -196,7 +196,7 @@ section at the end of this file).
  * Please note that Start Of Frame detection works only if D- is wired to the
  * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
  */
-#define USB_CFG_CHECK_DATA_TOGGLING     0
+#define USB_CFG_CHECK_DATA_TOGGLING 0
 /* define this macro to 1 if you want to filter out duplicate data packets
  * sent by the host. Duplicates occur only as a consequence of communication
  * errors, when the host does not receive an ACK. Please note that you need to
@@ -204,11 +204,11 @@ section at the end of this file).
  * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
  * for each control- and out-endpoint to check for duplicate packets.
  */
-#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH   0
+#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
 /* define this macro to 1 if you want the function usbMeasureFrameLength()
  * compiled in. This function can be used to calibrate the AVR's RC oscillator.
  */
-#define USB_USE_FAST_CRC                0
+#define USB_USE_FAST_CRC 0
 /* The assembler module has two implementations for the CRC algorithm. One is
  * faster, the other is smaller. This CRC routine is only used for transmitted
  * messages where timing is not critical. The faster routine needs 31 cycles
@@ -219,7 +219,7 @@ section at the end of this file).
 
 /* -------------------------- Device Description --------------------------- */
 
-#define  USB_CFG_VENDOR_ID       0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */
+#define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */
 /* USB vendor ID for the device, low byte first. If you have registered your
  * own Vendor ID, define it here. Otherwise you may use one of obdev's free
  * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules!
@@ -228,7 +228,7 @@ section at the end of this file).
  * with libusb: 0x16c0/0x5dc.  Use this VID/PID pair ONLY if you understand
  * the implications!
  */
-#define  USB_CFG_DEVICE_ID       0xdc, 0x05 /* = 0x05dc = 1500 */
+#define USB_CFG_DEVICE_ID 0xdc, 0x05 /* = 0x05dc = 1500 */
 /* This is the ID of the product, low byte first. It is interpreted in the
  * scope of the vendor ID. If you have registered your own VID with usb.org
  * or if you have licensed a PID from somebody else, define it here. Otherwise
@@ -239,10 +239,10 @@ section at the end of this file).
  * with libusb: 0x16c0/0x5dc.  Use this VID/PID pair ONLY if you understand
  * the implications!
  */
-#define USB_CFG_DEVICE_VERSION  0x00, 0x01
+#define USB_CFG_DEVICE_VERSION 0x00, 0x01
 /* Version number of the device: Minor number first, then major number.
  */
-#define USB_CFG_VENDOR_NAME     'o', 'b', 'd', 'e', 'v', '.', 'a', 't'
+#define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't'
 #define USB_CFG_VENDOR_NAME_LEN 8
 /* These two values define the vendor name returned by the USB device. The name
  * must be given as a list of characters under single quotes. The characters
@@ -252,7 +252,7 @@ section at the end of this file).
  * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for
  * details.
  */
-#define USB_CFG_DEVICE_NAME     'T', 'e', 'm', 'p', 'l', 'a', 't', 'e'
+#define USB_CFG_DEVICE_NAME 'T', 'e', 'm', 'p', 'l', 'a', 't', 'e'
 #define USB_CFG_DEVICE_NAME_LEN 8
 /* Same as above for the device name. If you don't want a device name, undefine
  * the macros. See the file USB-IDs-for-free.txt before you assign a name if
@@ -267,14 +267,14 @@ section at the end of this file).
  * to fine tune control over USB descriptors such as the string descriptor
  * for the serial number.
  */
-#define USB_CFG_DEVICE_CLASS        0xff    /* set to 0 if deferred to interface */
-#define USB_CFG_DEVICE_SUBCLASS     0
+#define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */
+#define USB_CFG_DEVICE_SUBCLASS 0
 /* See USB specification if you want to conform to an existing device class.
  * Class 0xff is "vendor specific".
  */
-#define USB_CFG_INTERFACE_CLASS     0   /* define class here if not at device level */
-#define USB_CFG_INTERFACE_SUBCLASS  0
-#define USB_CFG_INTERFACE_PROTOCOL  0
+#define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */
+#define USB_CFG_INTERFACE_SUBCLASS 0
+#define USB_CFG_INTERFACE_PROTOCOL 0
 /* See USB specification if you want to conform to an existing device class or
  * protocol. The following classes must be set at interface level:
  * HID class is 3, no subclass and protocol required (but may be useful!)
@@ -345,16 +345,16 @@ section at the end of this file).
  * };
  */
 
-#define USB_CFG_DESCR_PROPS_DEVICE                  0
-#define USB_CFG_DESCR_PROPS_CONFIGURATION           0
-#define USB_CFG_DESCR_PROPS_STRINGS                 0
-#define USB_CFG_DESCR_PROPS_STRING_0                0
-#define USB_CFG_DESCR_PROPS_STRING_VENDOR           0
-#define USB_CFG_DESCR_PROPS_STRING_PRODUCT          0
-#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    0
-#define USB_CFG_DESCR_PROPS_HID                     0
-#define USB_CFG_DESCR_PROPS_HID_REPORT              0
-#define USB_CFG_DESCR_PROPS_UNKNOWN                 0
+#define USB_CFG_DESCR_PROPS_DEVICE 0
+#define USB_CFG_DESCR_PROPS_CONFIGURATION 0
+#define USB_CFG_DESCR_PROPS_STRINGS 0
+#define USB_CFG_DESCR_PROPS_STRING_0 0
+#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0
+#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0
+#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0
+#define USB_CFG_DESCR_PROPS_HID 0
+#define USB_CFG_DESCR_PROPS_HID_REPORT 0
+#define USB_CFG_DESCR_PROPS_UNKNOWN 0
 
 /* ----------------------- Optional MCU Description ------------------------ */
 
index 30cdc9dcfc9d933c0b83409640bdc4060299dddd..f69198b1b989fff982f5da261db8879dc3dd2603 100644 (file)
@@ -21,36 +21,36 @@ documentation of the entire driver.
 /* ------------------------------------------------------------------------- */
 
 /* raw USB registers / interface to assembler code: */
-uchar usbRxBuf[2*USB_BUFSIZE];  /* raw RX buffer: PID, 8 bytes data, 2 bytes CRC */
-uchar       usbInputBufOffset;  /* offset in usbRxBuf used for low level receiving */
-uchar       usbDeviceAddr;      /* assigned during enumeration, defaults to 0 */
-uchar       usbNewDeviceAddr;   /* device ID which should be set after status phase */
-uchar       usbConfiguration;   /* currently selected configuration. Administered by driver, but not used */
-volatile schar usbRxLen;        /* = 0; number of bytes in usbRxBuf; 0 means free, -1 for flow control */
-uchar       usbCurrentTok;      /* last token received or endpoint number for last OUT token if != 0 */
-uchar       usbRxToken;         /* token for data we received; or endpont number for last OUT */
-volatile uchar usbTxLen = USBPID_NAK;   /* number of bytes to transmit with next IN token or handshake token */
-uchar       usbTxBuf[USB_BUFSIZE];/* data to transmit with next IN, free if usbTxLen contains handshake token */
+uchar          usbRxBuf[2 * USB_BUFSIZE]; /* raw RX buffer: PID, 8 bytes data, 2 bytes CRC */
+uchar          usbInputBufOffset;         /* offset in usbRxBuf used for low level receiving */
+uchar          usbDeviceAddr;             /* assigned during enumeration, defaults to 0 */
+uchar          usbNewDeviceAddr;          /* device ID which should be set after status phase */
+uchar          usbConfiguration;          /* currently selected configuration. Administered by driver, but not used */
+volatile schar usbRxLen;                  /* = 0; number of bytes in usbRxBuf; 0 means free, -1 for flow control */
+uchar          usbCurrentTok;             /* last token received or endpoint number for last OUT token if != 0 */
+uchar          usbRxToken;                /* token for data we received; or endpont number for last OUT */
+volatile uchar usbTxLen = USBPID_NAK;     /* number of bytes to transmit with next IN token or handshake token */
+uchar          usbTxBuf[USB_BUFSIZE];     /* data to transmit with next IN, free if usbTxLen contains handshake token */
 #if USB_COUNT_SOF
-volatile uchar  usbSofCount;    /* incremented by assembler module every SOF */
+volatile uchar usbSofCount; /* incremented by assembler module every SOF */
 #endif
 #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE
-usbTxStatus_t  usbTxStatus1;
-#   if USB_CFG_HAVE_INTRIN_ENDPOINT3
-usbTxStatus_t  usbTxStatus3;
-#   endif
+usbTxStatus_t usbTxStatus1;
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT3
+usbTxStatus_t usbTxStatus3;
+#    endif
 #endif
 #if USB_CFG_CHECK_DATA_TOGGLING
-uchar       usbCurrentDataToken;/* when we check data toggling to ignore duplicate packets */
+uchar usbCurrentDataToken; /* when we check data toggling to ignore duplicate packets */
 #endif
 
 /* USB status registers / not shared with asm code */
-uchar               *usbMsgPtr;     /* data to transmit next -- ROM or RAM address */
-static usbMsgLen_t  usbMsgLen = USB_NO_MSG; /* remaining number of bytes */
-static uchar        usbMsgFlags;    /* flag values see below */
+uchar *            usbMsgPtr;              /* data to transmit next -- ROM or RAM address */
+static usbMsgLen_t usbMsgLen = USB_NO_MSG; /* remaining number of bytes */
+static uchar       usbMsgFlags;            /* flag values see below */
 
-#define USB_FLG_MSGPTR_IS_ROM   (1<<6)
-#define USB_FLG_USE_USER_RW     (1<<7)
+#define USB_FLG_MSGPTR_IS_ROM (1 << 6)
+#define USB_FLG_USE_USER_RW (1 << 7)
 
 /*
 optimizing hints:
@@ -64,196 +64,174 @@ optimizing hints:
 
 #if USB_CFG_DESCR_PROPS_STRINGS == 0
 
-#if USB_CFG_DESCR_PROPS_STRING_0 == 0
-#undef USB_CFG_DESCR_PROPS_STRING_0
-#define USB_CFG_DESCR_PROPS_STRING_0    sizeof(usbDescriptorString0)
-const PROGMEM char usbDescriptorString0[] = { /* language descriptor */
+#    if USB_CFG_DESCR_PROPS_STRING_0 == 0
+#        undef USB_CFG_DESCR_PROPS_STRING_0
+#        define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0)
+const PROGMEM char usbDescriptorString0[] = {
+    /* language descriptor */
     4,          /* sizeof(usbDescriptorString0): length of descriptor in bytes */
     3,          /* descriptor type */
     0x09, 0x04, /* language index (0x0409 = US-English) */
 };
-#endif
+#    endif
 
-#if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN
-#undef USB_CFG_DESCR_PROPS_STRING_VENDOR
-#define USB_CFG_DESCR_PROPS_STRING_VENDOR   sizeof(usbDescriptorStringVendor)
-const PROGMEM int  usbDescriptorStringVendor[] = {
-    USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN),
-    USB_CFG_VENDOR_NAME
-};
-#endif
+#    if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN
+#        undef USB_CFG_DESCR_PROPS_STRING_VENDOR
+#        define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor)
+const PROGMEM int usbDescriptorStringVendor[] = {USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN), USB_CFG_VENDOR_NAME};
+#    endif
 
-#if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN
-#undef USB_CFG_DESCR_PROPS_STRING_PRODUCT
-#define USB_CFG_DESCR_PROPS_STRING_PRODUCT   sizeof(usbDescriptorStringDevice)
-const PROGMEM int  usbDescriptorStringDevice[] = {
-    USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN),
-    USB_CFG_DEVICE_NAME
-};
-#endif
+#    if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN
+#        undef USB_CFG_DESCR_PROPS_STRING_PRODUCT
+#        define USB_CFG_DESCR_PROPS_STRING_PRODUCT sizeof(usbDescriptorStringDevice)
+const PROGMEM int usbDescriptorStringDevice[] = {USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN), USB_CFG_DEVICE_NAME};
+#    endif
 
-#if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN
-#undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
-#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    sizeof(usbDescriptorStringSerialNumber)
-const PROGMEM int usbDescriptorStringSerialNumber[] = {
-    USB_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LEN),
-    USB_CFG_SERIAL_NUMBER
-};
-#endif
+#    if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN
+#        undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
+#        define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER sizeof(usbDescriptorStringSerialNumber)
+const PROGMEM int usbDescriptorStringSerialNumber[] = {USB_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LEN), USB_CFG_SERIAL_NUMBER};
+#    endif
 
-#endif  /* USB_CFG_DESCR_PROPS_STRINGS == 0 */
+#endif /* USB_CFG_DESCR_PROPS_STRINGS == 0 */
 
 /* --------------------------- Device Descriptor --------------------------- */
 
 #if USB_CFG_DESCR_PROPS_DEVICE == 0
-#undef USB_CFG_DESCR_PROPS_DEVICE
-#define USB_CFG_DESCR_PROPS_DEVICE  sizeof(usbDescriptorDevice)
-const PROGMEM char usbDescriptorDevice[] = {    /* USB device descriptor */
-    18,         /* sizeof(usbDescriptorDevice): length of descriptor in bytes */
-    USBDESCR_DEVICE,        /* descriptor type */
-    0x10, 0x01,             /* USB version supported */
-    USB_CFG_DEVICE_CLASS,
-    USB_CFG_DEVICE_SUBCLASS,
-    0,                      /* protocol */
-    8,                      /* max packet size */
+#    undef USB_CFG_DESCR_PROPS_DEVICE
+#    define USB_CFG_DESCR_PROPS_DEVICE sizeof(usbDescriptorDevice)
+const PROGMEM char usbDescriptorDevice[] = {
+    /* USB device descriptor */
+    18,                                               /* sizeof(usbDescriptorDevice): length of descriptor in bytes */
+    USBDESCR_DEVICE,                                  /* descriptor type */
+    0x10, 0x01,                                       /* USB version supported */
+    USB_CFG_DEVICE_CLASS, USB_CFG_DEVICE_SUBCLASS, 0, /* protocol */
+    8,                                                /* max packet size */
     /* the following two casts affect the first byte of the constant only, but
      * that's sufficient to avoid a warning with the default values.
      */
-    (char)USB_CFG_VENDOR_ID,/* 2 bytes */
-    (char)USB_CFG_DEVICE_ID,/* 2 bytes */
-    USB_CFG_DEVICE_VERSION, /* 2 bytes */
-    USB_CFG_DESCR_PROPS_STRING_VENDOR != 0 ? 1 : 0,         /* manufacturer string index */
-    USB_CFG_DESCR_PROPS_STRING_PRODUCT != 0 ? 2 : 0,        /* product string index */
-    USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER != 0 ? 3 : 0,  /* serial number string index */
-    1,          /* number of configurations */
+    (char)USB_CFG_VENDOR_ID,                               /* 2 bytes */
+    (char)USB_CFG_DEVICE_ID,                               /* 2 bytes */
+    USB_CFG_DEVICE_VERSION,                                /* 2 bytes */
+    USB_CFG_DESCR_PROPS_STRING_VENDOR != 0 ? 1 : 0,        /* manufacturer string index */
+    USB_CFG_DESCR_PROPS_STRING_PRODUCT != 0 ? 2 : 0,       /* product string index */
+    USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER != 0 ? 3 : 0, /* serial number string index */
+    1,                                                     /* number of configurations */
 };
 #endif
 
 /* ----------------------- Configuration Descriptor ------------------------ */
 
 #if USB_CFG_DESCR_PROPS_HID_REPORT != 0 && USB_CFG_DESCR_PROPS_HID == 0
-#undef USB_CFG_DESCR_PROPS_HID
-#define USB_CFG_DESCR_PROPS_HID     9   /* length of HID descriptor in config descriptor below */
+#    undef USB_CFG_DESCR_PROPS_HID
+#    define USB_CFG_DESCR_PROPS_HID 9 /* length of HID descriptor in config descriptor below */
 #endif
 
 #if USB_CFG_DESCR_PROPS_CONFIGURATION == 0
-#undef USB_CFG_DESCR_PROPS_CONFIGURATION
-#define USB_CFG_DESCR_PROPS_CONFIGURATION   sizeof(usbDescriptorConfiguration)
-PROGMEM char usbDescriptorConfiguration[] = {    /* USB configuration descriptor */
-    9,          /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */
-    USBDESCR_CONFIG,    /* descriptor type */
-    18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 +
-                (USB_CFG_DESCR_PROPS_HID & 0xff), 0,
-                /* total length of data returned (including inlined descriptors) */
-    1,          /* number of interfaces in this configuration */
-    1,          /* index of this configuration */
-    0,          /* configuration name string index */
-#if USB_CFG_IS_SELF_POWERED
-    (1 << 7) | USBATTR_SELFPOWER,       /* attributes */
-#else
-    (1 << 7),                           /* attributes */
-#endif
-    USB_CFG_MAX_BUS_POWER/2,            /* max USB current in 2mA units */
-/* interface descriptor follows inline: */
-    9,          /* sizeof(usbDescrInterface): length of descriptor in bytes */
-    USBDESCR_INTERFACE, /* descriptor type */
-    0,          /* index of this interface */
-    0,          /* alternate setting for this interface */
-    USB_CFG_HAVE_INTRIN_ENDPOINT + USB_CFG_HAVE_INTRIN_ENDPOINT3, /* endpoints excl 0: number of endpoint descriptors to follow */
-    USB_CFG_INTERFACE_CLASS,
-    USB_CFG_INTERFACE_SUBCLASS,
-    USB_CFG_INTERFACE_PROTOCOL,
-    0,          /* string index for interface */
-#if (USB_CFG_DESCR_PROPS_HID & 0xff)    /* HID descriptor */
-    9,          /* sizeof(usbDescrHID): length of descriptor in bytes */
-    USBDESCR_HID,   /* descriptor type: HID */
-    0x01, 0x01, /* BCD representation of HID version */
-    0x00,       /* target country code */
-    0x01,       /* number of HID Report (or other HID class) Descriptor infos to follow */
-    0x22,       /* descriptor type: report */
-    USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH, 0,  /* total length of report descriptor */
-#endif
-#if USB_CFG_HAVE_INTRIN_ENDPOINT    /* endpoint descriptor for endpoint 1 */
-    7,          /* sizeof(usbDescrEndpoint) */
-    USBDESCR_ENDPOINT,  /* descriptor type = endpoint */
-    (char)0x81, /* IN endpoint number 1 */
-    0x03,       /* attrib: Interrupt endpoint */
-    8, 0,       /* maximum packet size */
-    USB_CFG_INTR_POLL_INTERVAL, /* in ms */
-#endif
-#if USB_CFG_HAVE_INTRIN_ENDPOINT3   /* endpoint descriptor for endpoint 3 */
-    7,          /* sizeof(usbDescrEndpoint) */
-    USBDESCR_ENDPOINT,  /* descriptor type = endpoint */
+#    undef USB_CFG_DESCR_PROPS_CONFIGURATION
+#    define USB_CFG_DESCR_PROPS_CONFIGURATION sizeof(usbDescriptorConfiguration)
+PROGMEM char usbDescriptorConfiguration[] = {
+    /* USB configuration descriptor */
+    9,               /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */
+    USBDESCR_CONFIG, /* descriptor type */
+    18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + (USB_CFG_DESCR_PROPS_HID & 0xff), 0,
+    /* total length of data returned (including inlined descriptors) */
+    1, /* number of interfaces in this configuration */
+    1, /* index of this configuration */
+    0, /* configuration name string index */
+#    if USB_CFG_IS_SELF_POWERED
+    (1 << 7) | USBATTR_SELFPOWER, /* attributes */
+#    else
+    (1 << 7), /* attributes */
+#    endif
+    USB_CFG_MAX_BUS_POWER / 2,                                                          /* max USB current in 2mA units */
+                                                                                        /* interface descriptor follows inline: */
+    9,                                                                                  /* sizeof(usbDescrInterface): length of descriptor in bytes */
+    USBDESCR_INTERFACE,                                                                 /* descriptor type */
+    0,                                                                                  /* index of this interface */
+    0,                                                                                  /* alternate setting for this interface */
+    USB_CFG_HAVE_INTRIN_ENDPOINT + USB_CFG_HAVE_INTRIN_ENDPOINT3,                       /* endpoints excl 0: number of endpoint descriptors to follow */
+    USB_CFG_INTERFACE_CLASS, USB_CFG_INTERFACE_SUBCLASS, USB_CFG_INTERFACE_PROTOCOL, 0, /* string index for interface */
+#    if (USB_CFG_DESCR_PROPS_HID & 0xff)                                                /* HID descriptor */
+    9,                                                                                  /* sizeof(usbDescrHID): length of descriptor in bytes */
+    USBDESCR_HID,                                                                       /* descriptor type: HID */
+    0x01, 0x01,                                                                         /* BCD representation of HID version */
+    0x00,                                                                               /* target country code */
+    0x01,                                                                               /* number of HID Report (or other HID class) Descriptor infos to follow */
+    0x22,                                                                               /* descriptor type: report */
+    USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH, 0,                                            /* total length of report descriptor */
+#    endif
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT /* endpoint descriptor for endpoint 1 */
+    7,                               /* sizeof(usbDescrEndpoint) */
+    USBDESCR_ENDPOINT,               /* descriptor type = endpoint */
+    (char)0x81,                      /* IN endpoint number 1 */
+    0x03,                            /* attrib: Interrupt endpoint */
+    8, 0,                            /* maximum packet size */
+    USB_CFG_INTR_POLL_INTERVAL,      /* in ms */
+#    endif
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT3  /* endpoint descriptor for endpoint 3 */
+    7,                                 /* sizeof(usbDescrEndpoint) */
+    USBDESCR_ENDPOINT,                 /* descriptor type = endpoint */
     (char)(0x80 | USB_CFG_EP3_NUMBER), /* IN endpoint number 3 */
-    0x03,       /* attrib: Interrupt endpoint */
-    8, 0,       /* maximum packet size */
-    USB_CFG_INTR_POLL_INTERVAL, /* in ms */
-#endif
+    0x03,                              /* attrib: Interrupt endpoint */
+    8, 0,                              /* maximum packet size */
+    USB_CFG_INTR_POLL_INTERVAL,        /* in ms */
+#    endif
 };
 #endif
 
 /* ------------------------------------------------------------------------- */
 
-static inline void  usbResetDataToggling(void)
-{
+static inline void usbResetDataToggling(void) {
 #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE
-    USB_SET_DATATOKEN1(USB_INITIAL_DATATOKEN);  /* reset data toggling for interrupt endpoint */
-#   if USB_CFG_HAVE_INTRIN_ENDPOINT3
-    USB_SET_DATATOKEN3(USB_INITIAL_DATATOKEN);  /* reset data toggling for interrupt endpoint */
-#   endif
+    USB_SET_DATATOKEN1(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT3
+    USB_SET_DATATOKEN3(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */
+#    endif
 #endif
 }
 
-static inline void  usbResetStall(void)
-{
+static inline void usbResetStall(void) {
 #if USB_CFG_IMPLEMENT_HALT && USB_CFG_HAVE_INTRIN_ENDPOINT
-        usbTxLen1 = USBPID_NAK;
-#if USB_CFG_HAVE_INTRIN_ENDPOINT3
-        usbTxLen3 = USBPID_NAK;
-#endif
+    usbTxLen1 = USBPID_NAK;
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT3
+    usbTxLen3 = USBPID_NAK;
+#    endif
 #endif
 }
 
 /* ------------------------------------------------------------------------- */
 
 #if !USB_CFG_SUPPRESS_INTR_CODE
-#if USB_CFG_HAVE_INTRIN_ENDPOINT
-static void usbGenericSetInterrupt(uchar *data, uchar len, usbTxStatus_t *txStatus)
-{
-uchar   *p;
-char    i;
-
-#if USB_CFG_IMPLEMENT_HALT
-    if(usbTxLen1 == USBPID_STALL)
-        return;
-#endif
-    if(txStatus->len & 0x10){   /* packet buffer was empty */
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT
+static void usbGenericSetInterrupt(uchar *data, uchar len, usbTxStatus_t *txStatus) {
+    uchar *p;
+    char   i;
+
+#        if USB_CFG_IMPLEMENT_HALT
+    if (usbTxLen1 == USBPID_STALL) return;
+#        endif
+    if (txStatus->len & 0x10) {                             /* packet buffer was empty */
         txStatus->buffer[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* toggle token */
-    }else{
+    } else {
         txStatus->len = USBPID_NAK; /* avoid sending outdated (overwritten) interrupt data */
     }
     p = txStatus->buffer + 1;
     i = len;
-    do{                         /* if len == 0, we still copy 1 byte, but that's no problem */
+    do { /* if len == 0, we still copy 1 byte, but that's no problem */
         *p++ = *data++;
-    }while(--i > 0);            /* loop control at the end is 2 bytes shorter than at beginning */
+    } while (--i > 0); /* loop control at the end is 2 bytes shorter than at beginning */
     usbCrc16Append(&txStatus->buffer[1], len);
-    txStatus->len = len + 4;    /* len must be given including sync byte */
+    txStatus->len = len + 4; /* len must be given including sync byte */
     DBG2(0x21 + (((int)txStatus >> 3) & 3), txStatus->buffer, len + 3);
 }
 
-USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len)
-{
-    usbGenericSetInterrupt(data, len, &usbTxStatus1);
-}
-#endif
+USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len) { usbGenericSetInterrupt(data, len, &usbTxStatus1); }
+#    endif
 
-#if USB_CFG_HAVE_INTRIN_ENDPOINT3
-USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len)
-{
-    usbGenericSetInterrupt(data, len, &usbTxStatus3);
-}
-#endif
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT3
+USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len) { usbGenericSetInterrupt(data, len, &usbTxStatus3); }
+#    endif
 #endif /* USB_CFG_SUPPRESS_INTR_CODE */
 
 /* ------------------ utilities for code following below ------------------- */
@@ -264,26 +242,58 @@ USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len)
  * cases.
  */
 #if USB_CFG_USE_SWITCH_STATEMENT
-#   define SWITCH_START(cmd)       switch(cmd){{
-#   define SWITCH_CASE(value)      }break; case (value):{
-#   define SWITCH_CASE2(v1,v2)     }break; case (v1): case(v2):{
-#   define SWITCH_CASE3(v1,v2,v3)  }break; case (v1): case(v2): case(v3):{
-#   define SWITCH_DEFAULT          }break; default:{
-#   define SWITCH_END              }}
+#    define SWITCH_START(cmd) \
+        switch (cmd) {        \
+            {
+#    define SWITCH_CASE(value) \
+        }                      \
+        break;                 \
+        case (value): {
+#    define SWITCH_CASE2(v1, v2) \
+        }                        \
+        break;                   \
+        case (v1):               \
+        case (v2): {
+#    define SWITCH_CASE3(v1, v2, v3) \
+        }                            \
+        break;                       \
+        case (v1):                   \
+        case (v2):                   \
+        case (v3): {
+#    define SWITCH_DEFAULT \
+        }                  \
+        break;             \
+        default: {
+#    define SWITCH_END \
+        }              \
+        }
 #else
-#   define SWITCH_START(cmd)       {uchar _cmd = cmd; if(0){
-#   define SWITCH_CASE(value)      }else if(_cmd == (value)){
-#   define SWITCH_CASE2(v1,v2)     }else if(_cmd == (v1) || _cmd == (v2)){
-#   define SWITCH_CASE3(v1,v2,v3)  }else if(_cmd == (v1) || _cmd == (v2) || (_cmd == v3)){
-#   define SWITCH_DEFAULT          }else{
-#   define SWITCH_END              }}
+#    define SWITCH_START(cmd) \
+        {                     \
+            uchar _cmd = cmd; \
+            if (0) {
+#    define SWITCH_CASE(value) \
+        }                      \
+        else if (_cmd == (value)) {
+#    define SWITCH_CASE2(v1, v2) \
+        }                        \
+        else if (_cmd == (v1) || _cmd == (v2)) {
+#    define SWITCH_CASE3(v1, v2, v3) \
+        }                            \
+        else if (_cmd == (v1) || _cmd == (v2) || (_cmd == v3)) {
+#    define SWITCH_DEFAULT \
+        }                  \
+        else {
+#    define SWITCH_END \
+        }              \
+        }
 #endif
 
 #ifndef USB_RX_USER_HOOK
-#define USB_RX_USER_HOOK(data, len)
+#    define USB_RX_USER_HOOK(data, len)
 #endif
 #ifndef USB_SET_ADDRESS_HOOK
-#define USB_SET_ADDRESS_HOOK()
+#    define USB_SET_ADDRESS_HOOK()
 #endif
 
 /* ------------------------------------------------------------------------- */
@@ -293,62 +303,59 @@ USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len)
  * This may cause problems with undefined symbols if compiled without
  * optimizing!
  */
-#define GET_DESCRIPTOR(cfgProp, staticName)         \
-    if(cfgProp){                                    \
-        if((cfgProp) & USB_PROP_IS_RAM)             \
-            flags = 0;                              \
-        if((cfgProp) & USB_PROP_IS_DYNAMIC){        \
-            len = usbFunctionDescriptor(rq);        \
-        }else{                                      \
-            len = USB_PROP_LENGTH(cfgProp);         \
-            usbMsgPtr = (uchar *)(staticName);      \
-        }                                           \
+#define GET_DESCRIPTOR(cfgProp, staticName)       \
+    if (cfgProp) {                                \
+        if ((cfgProp)&USB_PROP_IS_RAM) flags = 0; \
+        if ((cfgProp)&USB_PROP_IS_DYNAMIC) {      \
+            len = usbFunctionDescriptor(rq);      \
+        } else {                                  \
+            len       = USB_PROP_LENGTH(cfgProp); \
+            usbMsgPtr = (uchar *)(staticName);    \
+        }                                         \
     }
 
 /* usbDriverDescriptor() is similar to usbFunctionDescriptor(), but used
  * internally for all types of descriptors.
  */
-static inline usbMsgLen_t usbDriverDescriptor(usbRequest_t *rq)
-{
-usbMsgLen_t len = 0;
-uchar       flags = USB_FLG_MSGPTR_IS_ROM;
+static inline usbMsgLen_t usbDriverDescriptor(usbRequest_t *rq) {
+    usbMsgLen_t len   = 0;
+    uchar       flags = USB_FLG_MSGPTR_IS_ROM;
 
     SWITCH_START(rq->wValue.bytes[1])
-    SWITCH_CASE(USBDESCR_DEVICE)    /* 1 */
-        GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_DEVICE, usbDescriptorDevice)
-    SWITCH_CASE(USBDESCR_CONFIG)    /* 2 */
-        GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_CONFIGURATION, usbDescriptorConfiguration)
-    SWITCH_CASE(USBDESCR_STRING)    /* 3 */
+    SWITCH_CASE(USBDESCR_DEVICE) /* 1 */
+    GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_DEVICE, usbDescriptorDevice)
+    SWITCH_CASE(USBDESCR_CONFIG) /* 2 */
+    GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_CONFIGURATION, usbDescriptorConfiguration)
+    SWITCH_CASE(USBDESCR_STRING) /* 3 */
 #if USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC
-        if(USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_RAM)
-            flags = 0;
+    if (USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_RAM) flags = 0;
+    len = usbFunctionDescriptor(rq);
+#else                              /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */
+    SWITCH_START(rq->wValue.bytes[0])
+    SWITCH_CASE(0)
+    GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_0, usbDescriptorString0)
+    SWITCH_CASE(1)
+    GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_VENDOR, usbDescriptorStringVendor)
+    SWITCH_CASE(2)
+    GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_PRODUCT, usbDescriptorStringDevice)
+    SWITCH_CASE(3)
+    GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER, usbDescriptorStringSerialNumber)
+    SWITCH_DEFAULT
+    if (USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC) {
         len = usbFunctionDescriptor(rq);
-#else   /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */
-        SWITCH_START(rq->wValue.bytes[0])
-        SWITCH_CASE(0)
-            GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_0, usbDescriptorString0)
-        SWITCH_CASE(1)
-            GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_VENDOR, usbDescriptorStringVendor)
-        SWITCH_CASE(2)
-            GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_PRODUCT, usbDescriptorStringDevice)
-        SWITCH_CASE(3)
-            GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER, usbDescriptorStringSerialNumber)
-        SWITCH_DEFAULT
-            if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){
-                len = usbFunctionDescriptor(rq);
-            }
-        SWITCH_END
-#endif  /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */
-#if USB_CFG_DESCR_PROPS_HID_REPORT  /* only support HID descriptors if enabled */
-    SWITCH_CASE(USBDESCR_HID)       /* 0x21 */
-        GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID, usbDescriptorConfiguration + 18)
-    SWITCH_CASE(USBDESCR_HID_REPORT)/* 0x22 */
-        GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID_REPORT, usbDescriptorHidReport)
+    }
+    SWITCH_END
+#endif                             /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */
+#if USB_CFG_DESCR_PROPS_HID_REPORT /* only support HID descriptors if enabled */
+    SWITCH_CASE(USBDESCR_HID)      /* 0x21 */
+    GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID, usbDescriptorConfiguration + 18)
+    SWITCH_CASE(USBDESCR_HID_REPORT) /* 0x22 */
+    GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID_REPORT, usbDescriptorHidReport)
 #endif
     SWITCH_DEFAULT
-        if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){
-            len = usbFunctionDescriptor(rq);
-        }
+    if (USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC) {
+        len = usbFunctionDescriptor(rq);
+    }
     SWITCH_END
     usbMsgFlags = flags;
     return len;
@@ -359,56 +366,53 @@ uchar       flags = USB_FLG_MSGPTR_IS_ROM;
 /* usbDriverSetup() is similar to usbFunctionSetup(), but it's used for
  * standard requests instead of class and custom requests.
  */
-static inline usbMsgLen_t usbDriverSetup(usbRequest_t *rq)
-{
-uchar   len  = 0, *dataPtr = usbTxBuf + 9;  /* there are 2 bytes free space at the end of the buffer */
-uchar   value = rq->wValue.bytes[0];
+static inline usbMsgLen_t usbDriverSetup(usbRequest_t *rq) {
+    uchar len = 0, *dataPtr = usbTxBuf + 9; /* there are 2 bytes free space at the end of the buffer */
+    uchar value = rq->wValue.bytes[0];
 #if USB_CFG_IMPLEMENT_HALT
-uchar   index = rq->wIndex.bytes[0];
+    uchar index = rq->wIndex.bytes[0];
 #endif
 
     dataPtr[0] = 0; /* default reply common to USBRQ_GET_STATUS and USBRQ_GET_INTERFACE */
     SWITCH_START(rq->bRequest)
-    SWITCH_CASE(USBRQ_GET_STATUS)           /* 0 */
-        uchar recipient = rq->bmRequestType & USBRQ_RCPT_MASK;  /* assign arith ops to variables to enforce byte size */
-        if(USB_CFG_IS_SELF_POWERED && recipient == USBRQ_RCPT_DEVICE)
-            dataPtr[0] =  USB_CFG_IS_SELF_POWERED;
+    SWITCH_CASE(USBRQ_GET_STATUS)                          /* 0 */
+    uchar recipient = rq->bmRequestType & USBRQ_RCPT_MASK; /* assign arith ops to variables to enforce byte size */
+    if (USB_CFG_IS_SELF_POWERED && recipient == USBRQ_RCPT_DEVICE) dataPtr[0] = USB_CFG_IS_SELF_POWERED;
 #if USB_CFG_IMPLEMENT_HALT
-        if(recipient == USBRQ_RCPT_ENDPOINT && index == 0x81)   /* request status for endpoint 1 */
-            dataPtr[0] = usbTxLen1 == USBPID_STALL;
+    if (recipient == USBRQ_RCPT_ENDPOINT && index == 0x81) /* request status for endpoint 1 */
+        dataPtr[0] = usbTxLen1 == USBPID_STALL;
 #endif
-        dataPtr[1] = 0;
-        len = 2;
+    dataPtr[1] = 0;
+    len        = 2;
 #if USB_CFG_IMPLEMENT_HALT
-    SWITCH_CASE2(USBRQ_CLEAR_FEATURE, USBRQ_SET_FEATURE)    /* 1, 3 */
-        if(value == 0 && index == 0x81){    /* feature 0 == HALT for endpoint == 1 */
-            usbTxLen1 = rq->bRequest == USBRQ_CLEAR_FEATURE ? USBPID_NAK : USBPID_STALL;
-            usbResetDataToggling();
-        }
+    SWITCH_CASE2(USBRQ_CLEAR_FEATURE, USBRQ_SET_FEATURE) /* 1, 3 */
+    if (value == 0 && index == 0x81) {                   /* feature 0 == HALT for endpoint == 1 */
+        usbTxLen1 = rq->bRequest == USBRQ_CLEAR_FEATURE ? USBPID_NAK : USBPID_STALL;
+        usbResetDataToggling();
+    }
 #endif
-    SWITCH_CASE(USBRQ_SET_ADDRESS)          /* 5 */
-        usbNewDeviceAddr = value;
-        USB_SET_ADDRESS_HOOK();
-    SWITCH_CASE(USBRQ_GET_DESCRIPTOR)       /* 6 */
-        len = usbDriverDescriptor(rq);
-        goto skipMsgPtrAssignment;
-    SWITCH_CASE(USBRQ_GET_CONFIGURATION)    /* 8 */
-        dataPtr = &usbConfiguration;  /* send current configuration value */
-        len = 1;
-    SWITCH_CASE(USBRQ_SET_CONFIGURATION)    /* 9 */
-        usbConfiguration = value;
-        usbResetStall();
-    SWITCH_CASE(USBRQ_GET_INTERFACE)        /* 10 */
-        len = 1;
+    SWITCH_CASE(USBRQ_SET_ADDRESS) /* 5 */
+    usbNewDeviceAddr = value;
+    USB_SET_ADDRESS_HOOK();
+    SWITCH_CASE(USBRQ_GET_DESCRIPTOR) /* 6 */
+    len = usbDriverDescriptor(rq);
+    goto skipMsgPtrAssignment;
+    SWITCH_CASE(USBRQ_GET_CONFIGURATION) /* 8 */
+    dataPtr = &usbConfiguration;         /* send current configuration value */
+    len     = 1;
+    SWITCH_CASE(USBRQ_SET_CONFIGURATION) /* 9 */
+    usbConfiguration = value;
+    usbResetStall();
+    SWITCH_CASE(USBRQ_GET_INTERFACE) /* 10 */
+    len = 1;
 #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE
-    SWITCH_CASE(USBRQ_SET_INTERFACE)        /* 11 */
-        usbResetDataToggling();
-        usbResetStall();
+    SWITCH_CASE(USBRQ_SET_INTERFACE) /* 11 */
+    usbResetDataToggling();
+    usbResetStall();
 #endif
-    SWITCH_DEFAULT                          /* 7=SET_DESCRIPTOR, 12=SYNC_FRAME */
+    SWITCH_DEFAULT /* 7=SET_DESCRIPTOR, 12=SYNC_FRAME */
         /* Should we add an optional hook here? */
-    SWITCH_END
-    usbMsgPtr = dataPtr;
+        SWITCH_END usbMsgPtr = dataPtr;
 skipMsgPtrAssignment:
     return len;
 }
@@ -419,65 +423,64 @@ skipMsgPtrAssignment:
  * routine. It distinguishes between SETUP and DATA packets and processes
  * them accordingly.
  */
-static inline void usbProcessRx(uchar *data, uchar len)
-{
-usbRequest_t    *rq = (void *)data;
-
-/* usbRxToken can be:
- * 0x2d 00101101 (USBPID_SETUP for setup data)
- * 0xe1 11100001 (USBPID_OUT: data phase of setup transfer)
- * 0...0x0f for OUT on endpoint X
- */
+static inline void usbProcessRx(uchar *data, uchar len) {
+    usbRequest_t *rq = (void *)data;
+
+    /* usbRxToken can be:
+     * 0x2d 00101101 (USBPID_SETUP for setup data)
+     * 0xe1 11100001 (USBPID_OUT: data phase of setup transfer)
+     * 0...0x0f for OUT on endpoint X
+     */
     DBG2(0x10 + (usbRxToken & 0xf), data, len + 2); /* SETUP=1d, SETUP-DATA=11, OUTx=1x */
     USB_RX_USER_HOOK(data, len)
 #if USB_CFG_IMPLEMENT_FN_WRITEOUT
-    if(usbRxToken < 0x10){  /* OUT to endpoint != 0: endpoint number in usbRxToken */
+    if (usbRxToken < 0x10) { /* OUT to endpoint != 0: endpoint number in usbRxToken */
         usbFunctionWriteOut(data, len);
         return;
     }
 #endif
-    if(usbRxToken == (uchar)USBPID_SETUP){
-        if(len != 8)    /* Setup size must be always 8 bytes. Ignore otherwise. */
+    if (usbRxToken == (uchar)USBPID_SETUP) {
+        if (len != 8) /* Setup size must be always 8 bytes. Ignore otherwise. */
             return;
         usbMsgLen_t replyLen;
-        usbTxBuf[0] = USBPID_DATA0;         /* initialize data toggling */
-        usbTxLen = USBPID_NAK;              /* abort pending transmit */
+        usbTxBuf[0] = USBPID_DATA0; /* initialize data toggling */
+        usbTxLen    = USBPID_NAK;   /* abort pending transmit */
         usbMsgFlags = 0;
-        uchar type = rq->bmRequestType & USBRQ_TYPE_MASK;
-        if(type != USBRQ_TYPE_STANDARD){    /* standard requests are handled by driver */
+        uchar type  = rq->bmRequestType & USBRQ_TYPE_MASK;
+        if (type != USBRQ_TYPE_STANDARD) { /* standard requests are handled by driver */
             replyLen = usbFunctionSetup(data);
-        }else{
+        } else {
             replyLen = usbDriverSetup(rq);
         }
 #if USB_CFG_IMPLEMENT_FN_READ || USB_CFG_IMPLEMENT_FN_WRITE
-        if(replyLen == USB_NO_MSG){         /* use user-supplied read/write function */
+        if (replyLen == USB_NO_MSG) { /* use user-supplied read/write function */
             /* do some conditioning on replyLen, but on IN transfers only */
-            if((rq->bmRequestType & USBRQ_DIR_MASK) != USBRQ_DIR_HOST_TO_DEVICE){
-                if(sizeof(replyLen) < sizeof(rq->wLength.word)){ /* help compiler with optimizing */
+            if ((rq->bmRequestType & USBRQ_DIR_MASK) != USBRQ_DIR_HOST_TO_DEVICE) {
+                if (sizeof(replyLen) < sizeof(rq->wLength.word)) { /* help compiler with optimizing */
                     replyLen = rq->wLength.bytes[0];
-                }else{
+                } else {
                     replyLen = rq->wLength.word;
                 }
             }
             usbMsgFlags = USB_FLG_USE_USER_RW;
-        }else   /* The 'else' prevents that we limit a replyLen of USB_NO_MSG to the maximum transfer len. */
+        } else /* The 'else' prevents that we limit a replyLen of USB_NO_MSG to the maximum transfer len. */
 #endif
-        if(sizeof(replyLen) < sizeof(rq->wLength.word)){ /* help compiler with optimizing */
-            if(!rq->wLength.bytes[1] && replyLen > rq->wLength.bytes[0])    /* limit length to max */
+            if (sizeof(replyLen) < sizeof(rq->wLength.word)) {            /* help compiler with optimizing */
+            if (!rq->wLength.bytes[1] && replyLen > rq->wLength.bytes[0]) /* limit length to max */
                 replyLen = rq->wLength.bytes[0];
-        }else{
-            if(replyLen > rq->wLength.word)     /* limit length to max */
+        } else {
+            if (replyLen > rq->wLength.word) /* limit length to max */
                 replyLen = rq->wLength.word;
         }
         usbMsgLen = replyLen;
-    }else{  /* usbRxToken must be USBPID_OUT, which means data phase of setup (control-out) */
+    } else { /* usbRxToken must be USBPID_OUT, which means data phase of setup (control-out) */
 #if USB_CFG_IMPLEMENT_FN_WRITE
-        if(usbMsgFlags & USB_FLG_USE_USER_RW){
+        if (usbMsgFlags & USB_FLG_USE_USER_RW) {
             uchar rval = usbFunctionWrite(data, len);
-            if(rval == 0xff){   /* an error occurred */
+            if (rval == 0xff) { /* an error occurred */
                 usbTxLen = USBPID_STALL;
-            }else if(rval != 0){    /* This was the final package */
-                usbMsgLen = 0;  /* answer with a zero-sized data packet */
+            } else if (rval != 0) { /* This was the final package */
+                usbMsgLen = 0;      /* answer with a zero-sized data packet */
             }
         }
 #endif
@@ -489,26 +492,25 @@ usbRequest_t    *rq = (void *)data;
 /* This function is similar to usbFunctionRead(), but it's also called for
  * data handled automatically by the driver (e.g. descriptor reads).
  */
-static uchar usbDeviceRead(uchar *data, uchar len)
-{
-    if(len > 0){    /* don't bother app with 0 sized reads */
+static uchar usbDeviceRead(uchar *data, uchar len) {
+    if (len > 0) { /* don't bother app with 0 sized reads */
 #if USB_CFG_IMPLEMENT_FN_READ
-        if(usbMsgFlags & USB_FLG_USE_USER_RW){
+        if (usbMsgFlags & USB_FLG_USE_USER_RW) {
             len = usbFunctionRead(data, len);
-        }else
+        } else
 #endif
         {
             uchar i = len, *r = usbMsgPtr;
-            if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){    /* ROM data */
-                do{
-                    uchar c = USB_READ_FLASH(r);    /* assign to char size variable to enforce byte ops */
+            if (usbMsgFlags & USB_FLG_MSGPTR_IS_ROM) { /* ROM data */
+                do {
+                    uchar c = USB_READ_FLASH(r); /* assign to char size variable to enforce byte ops */
                     *data++ = c;
                     r++;
-                }while(--i);
-            }else{  /* RAM data */
-                do{
+                } while (--i);
+            } else { /* RAM data */
+                do {
                     *data++ = *r++;
-                }while(--i);
+                } while (--i);
             }
             usbMsgPtr = r;
         }
@@ -521,39 +523,36 @@ static uchar usbDeviceRead(uchar *data, uchar len)
 /* usbBuildTxBlock() is called when we have data to transmit and the
  * interrupt routine's transmit buffer is empty.
  */
-static inline void usbBuildTxBlock(void)
-{
-usbMsgLen_t wantLen;
-uchar       len;
+static inline void usbBuildTxBlock(void) {
+    usbMsgLen_t wantLen;
+    uchar       len;
 
     wantLen = usbMsgLen;
-    if(wantLen > 8)
-        wantLen = 8;
+    if (wantLen > 8) wantLen = 8;
     usbMsgLen -= wantLen;
     usbTxBuf[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* DATA toggling */
     len = usbDeviceRead(usbTxBuf + 1, wantLen);
-    if(len <= 8){           /* valid data packet */
+    if (len <= 8) { /* valid data packet */
         usbCrc16Append(&usbTxBuf[1], len);
-        len += 4;           /* length including sync byte */
-        if(len < 12)        /* a partial package identifies end of message */
+        len += 4;     /* length including sync byte */
+        if (len < 12) /* a partial package identifies end of message */
             usbMsgLen = USB_NO_MSG;
-    }else{
-        len = USBPID_STALL;   /* stall the endpoint */
+    } else {
+        len       = USBPID_STALL; /* stall the endpoint */
         usbMsgLen = USB_NO_MSG;
     }
     usbTxLen = len;
-    DBG2(0x20, usbTxBuf, len-1);
+    DBG2(0x20, usbTxBuf, len - 1);
 }
 
 /* ------------------------------------------------------------------------- */
 
-static inline void usbHandleResetHook(uchar notResetState)
-{
+static inline void usbHandleResetHook(uchar notResetState) {
 #ifdef USB_RESET_HOOK
-static uchar    wasReset;
-uchar           isReset = !notResetState;
+    static uchar wasReset;
+    uchar        isReset = !notResetState;
 
-    if(wasReset != isReset){
+    if (wasReset != isReset) {
         USB_RESET_HOOK(isReset);
         wasReset = isReset;
     }
@@ -562,40 +561,39 @@ uchar           isReset = !notResetState;
 
 /* ------------------------------------------------------------------------- */
 
-USB_PUBLIC void usbPoll(void)
-{
-schar   len;
-uchar   i;
+USB_PUBLIC void usbPoll(void) {
+    schar len;
+    uchar i;
 
     len = usbRxLen - 3;
-    if(len >= 0){
-/* We could check CRC16 here -- but ACK has already been sent anyway. If you
- * need data integrity checks with this driver, check the CRC in your app
- * code and report errors back to the host. Since the ACK was already sent,
- * retries must be handled on application level.
- * unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3);
- */
+    if (len >= 0) {
+        /* We could check CRC16 here -- but ACK has already been sent anyway. If you
        * need data integrity checks with this driver, check the CRC in your app
        * code and report errors back to the host. Since the ACK was already sent,
        * retries must be handled on application level.
        * unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3);
        */
         usbProcessRx(usbRxBuf + USB_BUFSIZE + 1 - usbInputBufOffset, len);
 #if USB_CFG_HAVE_FLOWCONTROL
-        if(usbRxLen > 0)    /* only mark as available if not inactivated */
+        if (usbRxLen > 0) /* only mark as available if not inactivated */
             usbRxLen = 0;
 #else
-        usbRxLen = 0;       /* mark rx buffer as available */
+        usbRxLen = 0; /* mark rx buffer as available */
 #endif
     }
-    if(usbTxLen & 0x10){    /* transmit system idle */
-        if(usbMsgLen != USB_NO_MSG){    /* transmit data pending? */
+    if (usbTxLen & 0x10) {             /* transmit system idle */
+        if (usbMsgLen != USB_NO_MSG) { /* transmit data pending? */
             usbBuildTxBlock();
         }
     }
-    for(i = 20; i > 0; i--){
+    for (i = 20; i > 0; i--) {
         uchar usbLineStatus = USBIN & USBMASK;
-        if(usbLineStatus != 0)  /* SE0 has ended */
+        if (usbLineStatus != 0) /* SE0 has ended */
             goto isNotReset;
     }
     /* RESET condition, called multiple times during reset */
     usbNewDeviceAddr = 0;
-    usbDeviceAddr = 0;
+    usbDeviceAddr    = 0;
     usbResetStall();
     DBG1(0xff, 0, 0);
 isNotReset:
@@ -604,8 +602,7 @@ isNotReset:
 
 /* ------------------------------------------------------------------------- */
 
-USB_PUBLIC void usbInit(void)
-{
+USB_PUBLIC void usbInit(void) {
 #if USB_INTR_CFG_SET != 0
     USB_INTR_CFG |= USB_INTR_CFG_SET;
 #endif
@@ -616,9 +613,9 @@ USB_PUBLIC void usbInit(void)
     usbResetDataToggling();
 #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE
     usbTxLen1 = USBPID_NAK;
-#if USB_CFG_HAVE_INTRIN_ENDPOINT3
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT3
     usbTxLen3 = USBPID_NAK;
-#endif
+#    endif
 #endif
 }
 
index 42fe1637200d8e8790c1ecb60d6e307f3aa0ed85..88a1bce76eebe68e7bade9106ed7b7587cf26dc7 100644 (file)
@@ -122,7 +122,7 @@ USB messages, even if they address another (low-speed) device on the same bus.
 /* --------------------------- Module Interface ---------------------------- */
 /* ------------------------------------------------------------------------- */
 
-#define USBDRV_VERSION  20100715
+#define USBDRV_VERSION 20100715
 /* This define uniquely identifies a driver version. It is a decimal number
  * constructed from the driver's release date in the form YYYYMMDD. If the
  * driver's behavior or interface changes, you can use this constant to
@@ -130,9 +130,8 @@ USB messages, even if they address another (low-speed) device on the same bus.
  * older than 2006-01-25.
  */
 
-
 #ifndef USB_PUBLIC
-#define USB_PUBLIC
+#    define USB_PUBLIC
 #endif
 /* USB_PUBLIC is used as declaration attribute for all functions exported by
  * the USB driver. The default is no attribute (see above). You may define it
@@ -142,28 +141,28 @@ USB messages, even if they address another (low-speed) device on the same bus.
  */
 
 #ifndef __ASSEMBLER__
-#ifndef uchar
-#define uchar   unsigned char
-#endif
-#ifndef schar
-#define schar   signed char
-#endif
+#    ifndef uchar
+#        define uchar unsigned char
+#    endif
+#    ifndef schar
+#        define schar signed char
+#    endif
 /* shortcuts for well defined 8 bit integer types */
 
-#if USB_CFG_LONG_TRANSFERS  /* if more than 254 bytes transfer size required */
-#   define usbMsgLen_t unsigned
-#else
-#   define usbMsgLen_t uchar
-#endif
+#    if USB_CFG_LONG_TRANSFERS /* if more than 254 bytes transfer size required */
+#        define usbMsgLen_t unsigned
+#    else
+#        define usbMsgLen_t uchar
+#    endif
 /* usbMsgLen_t is the data type used for transfer lengths. By default, it is
  * defined to uchar, allowing a maximum of 254 bytes (255 is reserved for
  * USB_NO_MSG below). If the usbconfig.h defines USB_CFG_LONG_TRANSFERS to 1,
  * a 16 bit data type is used, allowing up to 16384 bytes (the rest is used
  * for flags in the descriptor configuration).
  */
-#define USB_NO_MSG  ((usbMsgLen_t)-1)   /* constant meaning "no message" */
+#    define USB_NO_MSG ((usbMsgLen_t)-1) /* constant meaning "no message" */
 
-struct usbRequest;  /* forward declaration */
+struct usbRequest; /* forward declaration */
 
 USB_PUBLIC void usbInit(void);
 /* This function must be called before interrupts are enabled and the main
@@ -216,7 +215,7 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq);
  * usbFunctionSetup() above, but it is called only to request USB descriptor
  * data. See the documentation of usbFunctionSetup() above for more info.
  */
-#if USB_CFG_HAVE_INTRIN_ENDPOINT
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT
 USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len);
 /* This function sets the message which will be sent during the next interrupt
  * IN transfer. The message is copied to an internal buffer and must not exceed
@@ -224,19 +223,19 @@ USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len);
  * interrupt status to the host.
  * If you need to transfer more bytes, use a control read after the interrupt.
  */
-#define usbInterruptIsReady()   (usbTxLen1 & 0x10)
+#        define usbInterruptIsReady() (usbTxLen1 & 0x10)
 /* This macro indicates whether the last interrupt message has already been
  * sent. If you set a new interrupt message before the old was sent, the
  * message already buffered will be lost.
  */
-#if USB_CFG_HAVE_INTRIN_ENDPOINT3
+#        if USB_CFG_HAVE_INTRIN_ENDPOINT3
 USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len);
-#define usbInterruptIsReady3()   (usbTxLen3 & 0x10)
+#            define usbInterruptIsReady3() (usbTxLen3 & 0x10)
 /* Same as above for endpoint 3 */
-#endif
-#endif /* USB_CFG_HAVE_INTRIN_ENDPOINT */
-#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH    /* simplified interface for backward compatibility */
-#define usbHidReportDescriptor  usbDescriptorHidReport
+#        endif
+#    endif                                   /* USB_CFG_HAVE_INTRIN_ENDPOINT */
+#    if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* simplified interface for backward compatibility */
+#        define usbHidReportDescriptor usbDescriptorHidReport
 /* should be declared as: PROGMEM char usbHidReportDescriptor[]; */
 /* If you implement an HID device, you need to provide a report descriptor.
  * The HID report descriptor syntax is a bit complex. If you understand how
@@ -244,8 +243,8 @@ USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len);
  * Descriptor Tool from usb.org, see http://www.usb.org/developers/hidpage/.
  * Otherwise you should probably start with a working example.
  */
-#endif  /* USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH */
-#if USB_CFG_IMPLEMENT_FN_WRITE
+#    endif /* USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH */
+#    if USB_CFG_IMPLEMENT_FN_WRITE
 USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len);
 /* This function is called by the driver to provide a control transfer's
  * payload data (control-out). It is called in chunks of up to 8 bytes. The
@@ -262,8 +261,8 @@ USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len);
  * In order to get usbFunctionWrite() called, define USB_CFG_IMPLEMENT_FN_WRITE
  * to 1 in usbconfig.h and return 0xff in usbFunctionSetup()..
  */
-#endif /* USB_CFG_IMPLEMENT_FN_WRITE */
-#if USB_CFG_IMPLEMENT_FN_READ
+#    endif /* USB_CFG_IMPLEMENT_FN_WRITE */
+#    if USB_CFG_IMPLEMENT_FN_READ
 USB_PUBLIC uchar usbFunctionRead(uchar *data, uchar len);
 /* This function is called by the driver to ask the application for a control
  * transfer's payload data (control-in). It is called in chunks of up to 8
@@ -274,26 +273,24 @@ USB_PUBLIC uchar usbFunctionRead(uchar *data, uchar len);
  * In order to get usbFunctionRead() called, define USB_CFG_IMPLEMENT_FN_READ
  * to 1 in usbconfig.h and return 0xff in usbFunctionSetup()..
  */
-#endif /* USB_CFG_IMPLEMENT_FN_READ */
+#    endif /* USB_CFG_IMPLEMENT_FN_READ */
 
-extern uchar usbRxToken;    /* may be used in usbFunctionWriteOut() below */
-#if USB_CFG_IMPLEMENT_FN_WRITEOUT
+extern uchar usbRxToken; /* may be used in usbFunctionWriteOut() below */
+#    if USB_CFG_IMPLEMENT_FN_WRITEOUT
 USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len);
 /* This function is called by the driver when data is received on an interrupt-
  * or bulk-out endpoint. The endpoint number can be found in the global
  * variable usbRxToken. You must define USB_CFG_IMPLEMENT_FN_WRITEOUT to 1 in
  * usbconfig.h to get this function called.
  */
-#endif /* USB_CFG_IMPLEMENT_FN_WRITEOUT */
-#ifdef USB_CFG_PULLUP_IOPORTNAME
-#define usbDeviceConnect()      ((USB_PULLUP_DDR |= (1<<USB_CFG_PULLUP_BIT)), \
-                                  (USB_PULLUP_OUT |= (1<<USB_CFG_PULLUP_BIT)))
-#define usbDeviceDisconnect()   ((USB_PULLUP_DDR &= ~(1<<USB_CFG_PULLUP_BIT)), \
-                                  (USB_PULLUP_OUT &= ~(1<<USB_CFG_PULLUP_BIT)))
-#else /* USB_CFG_PULLUP_IOPORTNAME */
-#define usbDeviceConnect()      (USBDDR &= ~(1<<USBMINUS))
-#define usbDeviceDisconnect()   (USBDDR |= (1<<USBMINUS))
-#endif /* USB_CFG_PULLUP_IOPORTNAME */
+#    endif /* USB_CFG_IMPLEMENT_FN_WRITEOUT */
+#    ifdef USB_CFG_PULLUP_IOPORTNAME
+#        define usbDeviceConnect() ((USB_PULLUP_DDR |= (1 << USB_CFG_PULLUP_BIT)), (USB_PULLUP_OUT |= (1 << USB_CFG_PULLUP_BIT)))
+#        define usbDeviceDisconnect() ((USB_PULLUP_DDR &= ~(1 << USB_CFG_PULLUP_BIT)), (USB_PULLUP_OUT &= ~(1 << USB_CFG_PULLUP_BIT)))
+#    else /* USB_CFG_PULLUP_IOPORTNAME */
+#        define usbDeviceConnect() (USBDDR &= ~(1 << USBMINUS))
+#        define usbDeviceDisconnect() (USBDDR |= (1 << USBMINUS))
+#    endif /* USB_CFG_PULLUP_IOPORTNAME */
 /* The macros usbDeviceConnect() and usbDeviceDisconnect() (intended to look
  * like a function) connect resp. disconnect the device from the host's USB.
  * If the constants USB_CFG_PULLUP_IOPORT and USB_CFG_PULLUP_BIT are defined
@@ -307,7 +304,7 @@ USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len);
  * or use cli() to disable interrupts globally.
  */
 extern unsigned usbCrc16(unsigned data, uchar len);
-#define usbCrc16(data, len) usbCrc16((unsigned)(data), len)
+#    define usbCrc16(data, len) usbCrc16((unsigned)(data), len)
 /* This function calculates the binary complement of the data CRC used in
  * USB data packets. The value is used to build raw transmit packets.
  * You may want to use this function for data checksums or to verify received
@@ -315,12 +312,12 @@ extern unsigned usbCrc16(unsigned data, uchar len);
  * tiny memory model.
  */
 extern unsigned usbCrc16Append(unsigned data, uchar len);
-#define usbCrc16Append(data, len)    usbCrc16Append((unsigned)(data), len)
+#    define usbCrc16Append(data, len) usbCrc16Append((unsigned)(data), len)
 /* This function is equivalent to usbCrc16() above, except that it appends
  * the 2 bytes CRC (lowbyte first) in the 'data' buffer after reading 'len'
  * bytes.
  */
-#if USB_CFG_HAVE_MEASURE_FRAME_LENGTH
+#    if USB_CFG_HAVE_MEASURE_FRAME_LENGTH
 extern unsigned usbMeasureFrameLength(void);
 /* This function MUST be called IMMEDIATELY AFTER USB reset and measures 1/7 of
  * the number of CPU cycles during one USB frame minus one low speed bit
@@ -329,59 +326,58 @@ extern unsigned usbMeasureFrameLength(void);
  * calling this function.
  * This can be used to calibrate the AVR's RC oscillator.
  */
-#endif
-extern uchar    usbConfiguration;
+#    endif
+extern uchar usbConfiguration;
 /* This value contains the current configuration set by the host. The driver
  * allows setting and querying of this variable with the USB SET_CONFIGURATION
  * and GET_CONFIGURATION requests, but does not use it otherwise.
  * You may want to reflect the "configured" status with a LED on the device or
  * switch on high power parts of the circuit only if the device is configured.
  */
-#if USB_COUNT_SOF
-extern volatile uchar   usbSofCount;
+#    if USB_COUNT_SOF
+extern volatile uchar usbSofCount;
 /* This variable is incremented on every SOF packet. It is only available if
  * the macro USB_COUNT_SOF is defined to a value != 0.
  */
-#endif
-#if USB_CFG_CHECK_DATA_TOGGLING
-extern uchar    usbCurrentDataToken;
+#    endif
+#    if USB_CFG_CHECK_DATA_TOGGLING
+extern uchar usbCurrentDataToken;
 /* This variable can be checked in usbFunctionWrite() and usbFunctionWriteOut()
  * to ignore duplicate packets.
  */
-#endif
+#    endif
 
-#define USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2*(stringLength)+2) | (3<<8))
+#    define USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2 * (stringLength) + 2) | (3 << 8))
 /* This macro builds a descriptor header for a string descriptor given the
  * string's length. See usbdrv.c for an example how to use it.
  */
-#if USB_CFG_HAVE_FLOWCONTROL
-extern volatile schar   usbRxLen;
-#define usbDisableAllRequests()     usbRxLen = -1
+#    if USB_CFG_HAVE_FLOWCONTROL
+extern volatile schar usbRxLen;
+#        define usbDisableAllRequests() usbRxLen = -1
 /* Must be called from usbFunctionWrite(). This macro disables all data input
  * from the USB interface. Requests from the host are answered with a NAK
  * while they are disabled.
  */
-#define usbEnableAllRequests()      usbRxLen = 0
+#        define usbEnableAllRequests() usbRxLen = 0
 /* May only be called if requests are disabled. This macro enables input from
  * the USB interface after it has been disabled with usbDisableAllRequests().
  */
-#define usbAllRequestsAreDisabled() (usbRxLen < 0)
+#        define usbAllRequestsAreDisabled() (usbRxLen < 0)
 /* Use this macro to find out whether requests are disabled. It may be needed
  * to ensure that usbEnableAllRequests() is never called when requests are
  * enabled.
  */
-#endif
+#    endif
 
-#define USB_SET_DATATOKEN1(token)   usbTxBuf1[0] = token
-#define USB_SET_DATATOKEN3(token)   usbTxBuf3[0] = token
+#    define USB_SET_DATATOKEN1(token) usbTxBuf1[0] = token
+#    define USB_SET_DATATOKEN3(token) usbTxBuf3[0] = token
 /* These two macros can be used by application software to reset data toggling
  * for interrupt-in endpoints 1 and 3. Since the token is toggled BEFORE
  * sending data, you must set the opposite value of the token which should come
  * first.
  */
 
-#endif  /* __ASSEMBLER__ */
-
+#endif /* __ASSEMBLER__ */
 
 /* ------------------------------------------------------------------------- */
 /* ----------------- Definitions for Descriptor Properties ----------------- */
@@ -390,57 +386,57 @@ extern volatile schar   usbRxLen;
  * about the various methods to define USB descriptors. If you do nothing,
  * the default descriptors will be used.
  */
-#define USB_PROP_IS_DYNAMIC     (1 << 14)
+#define USB_PROP_IS_DYNAMIC (1 << 14)
 /* If this property is set for a descriptor, usbFunctionDescriptor() will be
  * used to obtain the particular descriptor. Data directly returned via
  * usbMsgPtr are FLASH data by default, combine (OR) with USB_PROP_IS_RAM to
  * return RAM data.
  */
-#define USB_PROP_IS_RAM         (1 << 15)
+#define USB_PROP_IS_RAM (1 << 15)
 /* If this property is set for a descriptor, the data is read from RAM
  * memory instead of Flash. The property is used for all methods to provide
  * external descriptors.
  */
-#define USB_PROP_LENGTH(len)    ((len) & 0x3fff)
+#define USB_PROP_LENGTH(len) ((len)&0x3fff)
 /* If a static external descriptor is used, this is the total length of the
  * descriptor in bytes.
  */
 
 /* all descriptors which may have properties: */
 #ifndef USB_CFG_DESCR_PROPS_DEVICE
-#define USB_CFG_DESCR_PROPS_DEVICE                  0
+#    define USB_CFG_DESCR_PROPS_DEVICE 0
 #endif
 #ifndef USB_CFG_DESCR_PROPS_CONFIGURATION
-#define USB_CFG_DESCR_PROPS_CONFIGURATION           0
+#    define USB_CFG_DESCR_PROPS_CONFIGURATION 0
 #endif
 #ifndef USB_CFG_DESCR_PROPS_STRINGS
-#define USB_CFG_DESCR_PROPS_STRINGS                 0
+#    define USB_CFG_DESCR_PROPS_STRINGS 0
 #endif
 #ifndef USB_CFG_DESCR_PROPS_STRING_0
-#define USB_CFG_DESCR_PROPS_STRING_0                0
+#    define USB_CFG_DESCR_PROPS_STRING_0 0
 #endif
 #ifndef USB_CFG_DESCR_PROPS_STRING_VENDOR
-#define USB_CFG_DESCR_PROPS_STRING_VENDOR           0
+#    define USB_CFG_DESCR_PROPS_STRING_VENDOR 0
 #endif
 #ifndef USB_CFG_DESCR_PROPS_STRING_PRODUCT
-#define USB_CFG_DESCR_PROPS_STRING_PRODUCT          0
+#    define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0
 #endif
 #ifndef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
-#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    0
+#    define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0
 #endif
 #ifndef USB_CFG_DESCR_PROPS_HID
-#define USB_CFG_DESCR_PROPS_HID                     0
+#    define USB_CFG_DESCR_PROPS_HID 0
 #endif
 #if !(USB_CFG_DESCR_PROPS_HID_REPORT)
-#   undef USB_CFG_DESCR_PROPS_HID_REPORT
-#   if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* do some backward compatibility tricks */
-#       define USB_CFG_DESCR_PROPS_HID_REPORT       USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH
-#   else
-#       define USB_CFG_DESCR_PROPS_HID_REPORT       0
-#   endif
+#    undef USB_CFG_DESCR_PROPS_HID_REPORT
+#    if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* do some backward compatibility tricks */
+#        define USB_CFG_DESCR_PROPS_HID_REPORT USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH
+#    else
+#        define USB_CFG_DESCR_PROPS_HID_REPORT 0
+#    endif
 #endif
 #ifndef USB_CFG_DESCR_PROPS_UNKNOWN
-#define USB_CFG_DESCR_PROPS_UNKNOWN                 0
+#    define USB_CFG_DESCR_PROPS_UNKNOWN 0
 #endif
 
 /* ------------------ forward declaration of descriptors ------------------- */
@@ -449,46 +445,46 @@ extern volatile schar   usbRxLen;
  */
 #ifndef __ASSEMBLER__
 extern
-#if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM)
-PROGMEM
-#endif
-const char usbDescriptorDevice[];
+#    if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM)
+    PROGMEM
+#    endif
+    const char usbDescriptorDevice[];
 
 extern
-#if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM)
-PROGMEM
-#endif
-const char usbDescriptorConfiguration[];
+#    if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM)
+    PROGMEM
+#    endif
+    const char usbDescriptorConfiguration[];
 
 extern
-#if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM)
-PROGMEM
-#endif
-const char usbDescriptorHidReport[];
+#    if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM)
+    PROGMEM
+#    endif
+    const char usbDescriptorHidReport[];
 
 extern
-#if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM)
-PROGMEM
-#endif
-const char usbDescriptorString0[];
+#    if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM)
+    PROGMEM
+#    endif
+    const char usbDescriptorString0[];
 
 extern
-#if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM)
-PROGMEM
-#endif
-const int usbDescriptorStringVendor[];
+#    if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM)
+    PROGMEM
+#    endif
+    const int usbDescriptorStringVendor[];
 
 extern
-#if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM)
-PROGMEM
-#endif
-const int usbDescriptorStringDevice[];
+#    if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM)
+    PROGMEM
+#    endif
+    const int usbDescriptorStringDevice[];
 
 extern
-#if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM)
-PROGMEM
-#endif
-const int usbDescriptorStringSerialNumber[];
+#    if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM)
+    PROGMEM
+#    endif
+    const int usbDescriptorStringSerialNumber[];
 
 #endif /* __ASSEMBLER__ */
 
@@ -496,12 +492,12 @@ const int usbDescriptorStringSerialNumber[];
 /* ------------------------ General Purpose Macros ------------------------- */
 /* ------------------------------------------------------------------------- */
 
-#define USB_CONCAT(a, b)            a ## b
-#define USB_CONCAT_EXPANDED(a, b)   USB_CONCAT(a, b)
+#define USB_CONCAT(a, b) a##b
+#define USB_CONCAT_EXPANDED(a, b) USB_CONCAT(a, b)
 
-#define USB_OUTPORT(name)           USB_CONCAT(PORT, name)
-#define USB_INPORT(name)            USB_CONCAT(PIN, name)
-#define USB_DDRPORT(name)           USB_CONCAT(DDR, name)
+#define USB_OUTPORT(name) USB_CONCAT(PORT, name)
+#define USB_INPORT(name) USB_CONCAT(PIN, name)
+#define USB_DDRPORT(name) USB_CONCAT(DDR, name)
 /* The double-define trick above lets us concatenate strings which are
  * defined by macros.
  */
@@ -511,7 +507,7 @@ const int usbDescriptorStringSerialNumber[];
 /* ------------------------------------------------------------------------- */
 
 #if !defined __ASSEMBLER__ && (!defined USB_CFG_VENDOR_ID || !defined USB_CFG_DEVICE_ID)
-#warning "You should define USB_CFG_VENDOR_ID and USB_CFG_DEVICE_ID in usbconfig.h"
+#    warning "You should define USB_CFG_VENDOR_ID and USB_CFG_DEVICE_ID in usbconfig.h"
 /* If the user has not defined IDs, we default to obdev's free IDs.
  * See USB-IDs-for-free.txt for details.
  */
@@ -519,96 +515,96 @@ const int usbDescriptorStringSerialNumber[];
 
 /* make sure we have a VID and PID defined, byte order is lowbyte, highbyte */
 #ifndef USB_CFG_VENDOR_ID
-#   define  USB_CFG_VENDOR_ID   0xc0, 0x16  /* = 0x16c0 = 5824 = voti.nl */
+#    define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */
 #endif
 
 #ifndef USB_CFG_DEVICE_ID
-#   if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH
-#       define USB_CFG_DEVICE_ID    0xdf, 0x05  /* = 0x5df = 1503, shared PID for HIDs */
-#   elif USB_CFG_INTERFACE_CLASS == 2
-#       define USB_CFG_DEVICE_ID    0xe1, 0x05  /* = 0x5e1 = 1505, shared PID for CDC Modems */
-#   else
-#       define USB_CFG_DEVICE_ID    0xdc, 0x05  /* = 0x5dc = 1500, obdev's free PID */
-#   endif
+#    if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH
+#        define USB_CFG_DEVICE_ID 0xdf, 0x05 /* = 0x5df = 1503, shared PID for HIDs */
+#    elif USB_CFG_INTERFACE_CLASS == 2
+#        define USB_CFG_DEVICE_ID 0xe1, 0x05 /* = 0x5e1 = 1505, shared PID for CDC Modems */
+#    else
+#        define USB_CFG_DEVICE_ID 0xdc, 0x05 /* = 0x5dc = 1500, obdev's free PID */
+#    endif
 #endif
 
 /* Derive Output, Input and DataDirection ports from port names */
 #ifndef USB_CFG_IOPORTNAME
-#error "You must define USB_CFG_IOPORTNAME in usbconfig.h, see usbconfig-prototype.h"
+#    error "You must define USB_CFG_IOPORTNAME in usbconfig.h, see usbconfig-prototype.h"
 #endif
 
-#define USBOUT          USB_OUTPORT(USB_CFG_IOPORTNAME)
-#define USB_PULLUP_OUT  USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME)
-#define USBIN           USB_INPORT(USB_CFG_IOPORTNAME)
-#define USBDDR          USB_DDRPORT(USB_CFG_IOPORTNAME)
-#define USB_PULLUP_DDR  USB_DDRPORT(USB_CFG_PULLUP_IOPORTNAME)
+#define USBOUT USB_OUTPORT(USB_CFG_IOPORTNAME)
+#define USB_PULLUP_OUT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME)
+#define USBIN USB_INPORT(USB_CFG_IOPORTNAME)
+#define USBDDR USB_DDRPORT(USB_CFG_IOPORTNAME)
+#define USB_PULLUP_DDR USB_DDRPORT(USB_CFG_PULLUP_IOPORTNAME)
 
-#define USBMINUS    USB_CFG_DMINUS_BIT
-#define USBPLUS     USB_CFG_DPLUS_BIT
-#define USBIDLE     (1<<USB_CFG_DMINUS_BIT) /* value representing J state */
-#define USBMASK     ((1<<USB_CFG_DPLUS_BIT) | (1<<USB_CFG_DMINUS_BIT))  /* mask for USB I/O bits */
+#define USBMINUS USB_CFG_DMINUS_BIT
+#define USBPLUS USB_CFG_DPLUS_BIT
+#define USBIDLE (1 << USB_CFG_DMINUS_BIT)                              /* value representing J state */
+#define USBMASK ((1 << USB_CFG_DPLUS_BIT) | (1 << USB_CFG_DMINUS_BIT)) /* mask for USB I/O bits */
 
 /* defines for backward compatibility with older driver versions: */
-#define USB_CFG_IOPORT          USB_OUTPORT(USB_CFG_IOPORTNAME)
+#define USB_CFG_IOPORT USB_OUTPORT(USB_CFG_IOPORTNAME)
 #ifdef USB_CFG_PULLUP_IOPORTNAME
-#define USB_CFG_PULLUP_IOPORT   USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME)
+#    define USB_CFG_PULLUP_IOPORT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME)
 #endif
 
-#ifndef USB_CFG_EP3_NUMBER  /* if not defined in usbconfig.h */
-#define USB_CFG_EP3_NUMBER  3
+#ifndef USB_CFG_EP3_NUMBER /* if not defined in usbconfig.h */
+#    define USB_CFG_EP3_NUMBER 3
 #endif
 
 #ifndef USB_CFG_HAVE_INTRIN_ENDPOINT3
-#define USB_CFG_HAVE_INTRIN_ENDPOINT3   0
+#    define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
 #endif
 
-#define USB_BUFSIZE     11  /* PID, 8 bytes data, 2 bytes CRC */
+#define USB_BUFSIZE 11 /* PID, 8 bytes data, 2 bytes CRC */
 
 /* ----- Try to find registers and bits responsible for ext interrupt 0 ----- */
 
-#ifndef USB_INTR_CFG    /* allow user to override our default */
-#   if defined  EICRA
-#       define USB_INTR_CFG EICRA
-#   else
-#       define USB_INTR_CFG MCUCR
-#   endif
-#endif
-#ifndef USB_INTR_CFG_SET    /* allow user to override our default */
-#   if defined(USB_COUNT_SOF) || defined(USB_SOF_HOOK)
-#       define USB_INTR_CFG_SET (1 << ISC01)                    /* cfg for falling edge */
-        /* If any SOF logic is used, the interrupt must be wired to D- where
-         * we better trigger on falling edge
-         */
-#   else
-#       define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01))   /* cfg for rising edge */
-#   endif
-#endif
-#ifndef USB_INTR_CFG_CLR    /* allow user to override our default */
-#   define USB_INTR_CFG_CLR 0    /* no bits to clear */
-#endif
-
-#ifndef USB_INTR_ENABLE     /* allow user to override our default */
-#   if defined GIMSK
-#       define USB_INTR_ENABLE  GIMSK
-#   elif defined EIMSK
-#       define USB_INTR_ENABLE  EIMSK
-#   else
-#       define USB_INTR_ENABLE  GICR
-#   endif
+#ifndef USB_INTR_CFG /* allow user to override our default */
+#    if defined EICRA
+#        define USB_INTR_CFG EICRA
+#    else
+#        define USB_INTR_CFG MCUCR
+#    endif
+#endif
+#ifndef USB_INTR_CFG_SET /* allow user to override our default */
+#    if defined(USB_COUNT_SOF) || defined(USB_SOF_HOOK)
+#        define USB_INTR_CFG_SET (1 << ISC01) /* cfg for falling edge */
+                                              /* If any SOF logic is used, the interrupt must be wired to D- where
+                                               * we better trigger on falling edge
+                                               */
+#    else
+#        define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) /* cfg for rising edge */
+#    endif
+#endif
+#ifndef USB_INTR_CFG_CLR       /* allow user to override our default */
+#    define USB_INTR_CFG_CLR 0 /* no bits to clear */
+#endif
+
+#ifndef USB_INTR_ENABLE /* allow user to override our default */
+#    if defined GIMSK
+#        define USB_INTR_ENABLE GIMSK
+#    elif defined EIMSK
+#        define USB_INTR_ENABLE EIMSK
+#    else
+#        define USB_INTR_ENABLE GICR
+#    endif
 #endif
 #ifndef USB_INTR_ENABLE_BIT /* allow user to override our default */
-#   define USB_INTR_ENABLE_BIT  INT0
+#    define USB_INTR_ENABLE_BIT INT0
 #endif
 
-#ifndef USB_INTR_PENDING    /* allow user to override our default */
-#   if defined  EIFR
-#       define USB_INTR_PENDING EIFR
-#   else
-#       define USB_INTR_PENDING GIFR
-#   endif
+#ifndef USB_INTR_PENDING /* allow user to override our default */
+#    if defined EIFR
+#        define USB_INTR_PENDING EIFR
+#    else
+#        define USB_INTR_PENDING GIFR
+#    endif
 #endif
-#ifndef USB_INTR_PENDING_BIT    /* allow user to override our default */
-#   define USB_INTR_PENDING_BIT INTF0
+#ifndef USB_INTR_PENDING_BIT /* allow user to override our default */
+#    define USB_INTR_PENDING_BIT INTF0
 #endif
 
 /*
@@ -628,46 +624,45 @@ at90s1200, attiny11, attiny12, attiny15, attiny28: these have no RAM
 /* ------------------------------------------------------------------------- */
 
 /* USB Token values */
-#define USBPID_SETUP    0x2d
-#define USBPID_OUT      0xe1
-#define USBPID_IN       0x69
-#define USBPID_DATA0    0xc3
-#define USBPID_DATA1    0x4b
+#define USBPID_SETUP 0x2d
+#define USBPID_OUT 0xe1
+#define USBPID_IN 0x69
+#define USBPID_DATA0 0xc3
+#define USBPID_DATA1 0x4b
 
-#define USBPID_ACK      0xd2
-#define USBPID_NAK      0x5a
-#define USBPID_STALL    0x1e
+#define USBPID_ACK 0xd2
+#define USBPID_NAK 0x5a
+#define USBPID_STALL 0x1e
 
 #ifndef USB_INITIAL_DATATOKEN
-#define USB_INITIAL_DATATOKEN   USBPID_DATA1
+#    define USB_INITIAL_DATATOKEN USBPID_DATA1
 #endif
 
 #ifndef __ASSEMBLER__
 
-typedef struct usbTxStatus{
-    volatile uchar   len;
-    uchar   buffer[USB_BUFSIZE];
-}usbTxStatus_t;
-
-extern usbTxStatus_t   usbTxStatus1, usbTxStatus3;
-#define usbTxLen1   usbTxStatus1.len
-#define usbTxBuf1   usbTxStatus1.buffer
-#define usbTxLen3   usbTxStatus3.len
-#define usbTxBuf3   usbTxStatus3.buffer
-
-
-typedef union usbWord{
-    unsigned    word;
-    uchar       bytes[2];
-}usbWord_t;
-
-typedef struct usbRequest{
-    uchar       bmRequestType;
-    uchar       bRequest;
-    usbWord_t   wValue;
-    usbWord_t   wIndex;
-    usbWord_t   wLength;
-}usbRequest_t;
+typedef struct usbTxStatus {
+    volatile uchar len;
+    uchar          buffer[USB_BUFSIZE];
+} usbTxStatus_t;
+
+extern usbTxStatus_t usbTxStatus1, usbTxStatus3;
+#    define usbTxLen1 usbTxStatus1.len
+#    define usbTxBuf1 usbTxStatus1.buffer
+#    define usbTxLen3 usbTxStatus3.len
+#    define usbTxBuf3 usbTxStatus3.buffer
+
+typedef union usbWord {
+    unsigned word;
+    uchar    bytes[2];
+} usbWord_t;
+
+typedef struct usbRequest {
+    uchar     bmRequestType;
+    uchar     bRequest;
+    usbWord_t wValue;
+    usbWord_t wIndex;
+    usbWord_t wLength;
+} usbRequest_t;
 /* This structure matches the 8 byte setup request */
 #endif
 
@@ -679,56 +674,56 @@ typedef struct usbRequest{
  */
 
 /* USB setup recipient values */
-#define USBRQ_RCPT_MASK         0x1f
-#define USBRQ_RCPT_DEVICE       0
-#define USBRQ_RCPT_INTERFACE    1
-#define USBRQ_RCPT_ENDPOINT     2
+#define USBRQ_RCPT_MASK 0x1f
+#define USBRQ_RCPT_DEVICE 0
+#define USBRQ_RCPT_INTERFACE 1
+#define USBRQ_RCPT_ENDPOINT 2
 
 /* USB request type values */
-#define USBRQ_TYPE_MASK         0x60
-#define USBRQ_TYPE_STANDARD     (0<<5)
-#define USBRQ_TYPE_CLASS        (1<<5)
-#define USBRQ_TYPE_VENDOR       (2<<5)
+#define USBRQ_TYPE_MASK 0x60
+#define USBRQ_TYPE_STANDARD (0 << 5)
+#define USBRQ_TYPE_CLASS (1 << 5)
+#define USBRQ_TYPE_VENDOR (2 << 5)
 
 /* USB direction values: */
-#define USBRQ_DIR_MASK              0x80
-#define USBRQ_DIR_HOST_TO_DEVICE    (0<<7)
-#define USBRQ_DIR_DEVICE_TO_HOST    (1<<7)
+#define USBRQ_DIR_MASK 0x80
+#define USBRQ_DIR_HOST_TO_DEVICE (0 << 7)
+#define USBRQ_DIR_DEVICE_TO_HOST (1 << 7)
 
 /* USB Standard Requests */
-#define USBRQ_GET_STATUS        0
-#define USBRQ_CLEAR_FEATURE     1
-#define USBRQ_SET_FEATURE       3
-#define USBRQ_SET_ADDRESS       5
-#define USBRQ_GET_DESCRIPTOR    6
-#define USBRQ_SET_DESCRIPTOR    7
+#define USBRQ_GET_STATUS 0
+#define USBRQ_CLEAR_FEATURE 1
+#define USBRQ_SET_FEATURE 3
+#define USBRQ_SET_ADDRESS 5
+#define USBRQ_GET_DESCRIPTOR 6
+#define USBRQ_SET_DESCRIPTOR 7
 #define USBRQ_GET_CONFIGURATION 8
 #define USBRQ_SET_CONFIGURATION 9
-#define USBRQ_GET_INTERFACE     10
-#define USBRQ_SET_INTERFACE     11
-#define USBRQ_SYNCH_FRAME       12
+#define USBRQ_GET_INTERFACE 10
+#define USBRQ_SET_INTERFACE 11
+#define USBRQ_SYNCH_FRAME 12
 
 /* USB descriptor constants */
-#define USBDESCR_DEVICE         1
-#define USBDESCR_CONFIG         2
-#define USBDESCR_STRING         3
-#define USBDESCR_INTERFACE      4
-#define USBDESCR_ENDPOINT       5
-#define USBDESCR_HID            0x21
-#define USBDESCR_HID_REPORT     0x22
-#define USBDESCR_HID_PHYS       0x23
+#define USBDESCR_DEVICE 1
+#define USBDESCR_CONFIG 2
+#define USBDESCR_STRING 3
+#define USBDESCR_INTERFACE 4
+#define USBDESCR_ENDPOINT 5
+#define USBDESCR_HID 0x21
+#define USBDESCR_HID_REPORT 0x22
+#define USBDESCR_HID_PHYS 0x23
 
 //#define USBATTR_BUSPOWER        0x80  // USB 1.1 does not define this value any more
-#define USBATTR_SELFPOWER       0x40
-#define USBATTR_REMOTEWAKE      0x20
+#define USBATTR_SELFPOWER 0x40
+#define USBATTR_REMOTEWAKE 0x20
 
 /* USB HID Requests */
-#define USBRQ_HID_GET_REPORT    0x01
-#define USBRQ_HID_GET_IDLE      0x02
-#define USBRQ_HID_GET_PROTOCOL  0x03
-#define USBRQ_HID_SET_REPORT    0x09
-#define USBRQ_HID_SET_IDLE      0x0a
-#define USBRQ_HID_SET_PROTOCOL  0x0b
+#define USBRQ_HID_GET_REPORT 0x01
+#define USBRQ_HID_GET_IDLE 0x02
+#define USBRQ_HID_GET_PROTOCOL 0x03
+#define USBRQ_HID_SET_REPORT 0x09
+#define USBRQ_HID_SET_IDLE 0x0a
+#define USBRQ_HID_SET_PROTOCOL 0x0b
 
 /* ------------------------------------------------------------------------- */
 
index 60e48c3a9cfbcaf5786f2464c804a2604d38de0f..3719b7aa0f8c5fd845ad908e2d97f69c4078b892 100644 (file)
@@ -29,36 +29,38 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "bootloader.h"
 #include <util/delay.h>
 
-
 static uint8_t vusb_keyboard_leds = 0;
-static uint8_t vusb_idle_rate = 0;
+static uint8_t vusb_idle_rate     = 0;
 
 /* Keyboard report send buffer */
 #define KBUF_SIZE 16
 static report_keyboard_t kbuf[KBUF_SIZE];
-static uint8_t kbuf_head = 0;
-static uint8_t kbuf_tail = 0;
+static uint8_t           kbuf_head = 0;
+static uint8_t           kbuf_tail = 0;
 
 typedef struct {
-        uint8_t modifier;
-        uint8_t reserved;
-        uint8_t keycode[6];
+    uint8_t modifier;
+    uint8_t reserved;
+    uint8_t keycode[6];
 } keyboard_report_t;
 
-static keyboard_report_t keyboard_report; // sent to PC
+static keyboard_report_t keyboard_report;  // sent to PC
 
 #define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10
 
 /* transfer keyboard report from buffer */
-void vusb_transfer_keyboard(void)
-{
+void vusb_transfer_keyboard(void) {
     for (int i = 0; i < VUSB_TRANSFER_KEYBOARD_MAX_TRIES; i++) {
         if (usbInterruptIsReady()) {
             if (kbuf_head != kbuf_tail) {
                 usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
                 kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
                 if (debug_keyboard) {
-                    print("V-USB: kbuf["); pdec(kbuf_tail); print("->"); pdec(kbuf_head); print("](");
+                    print("V-USB: kbuf[");
+                    pdec(kbuf_tail);
+                    print("->");
+                    pdec(kbuf_head);
+                    print("](");
                     phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
                     print(")\n");
                 }
@@ -70,39 +72,26 @@ void vusb_transfer_keyboard(void)
     }
 }
 
-
 /*------------------------------------------------------------------*
  * Host driver
  *------------------------------------------------------------------*/
 static uint8_t keyboard_leds(void);
-static void send_keyboard(report_keyboard_t *report);
-static void send_mouse(report_mouse_t *report);
-static void send_system(uint16_t data);
-static void send_consumer(uint16_t data);
-
-static host_driver_t driver = {
-        keyboard_leds,
-        send_keyboard,
-        send_mouse,
-        send_system,
-        send_consumer
-};
+static void    send_keyboard(report_keyboard_t *report);
+static void    send_mouse(report_mouse_t *report);
+static void    send_system(uint16_t data);
+static void    send_consumer(uint16_t data);
 
-host_driver_t *vusb_driver(void)
-{
-    return &driver;
-}
+static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
 
-static uint8_t keyboard_leds(void) {
-    return vusb_keyboard_leds;
-}
+host_driver_t *vusb_driver(void) { return &driver; }
+
+static uint8_t keyboard_leds(void) { return vusb_keyboard_leds; }
 
-static void send_keyboard(report_keyboard_t *report)
-{
+static void send_keyboard(report_keyboard_t *report) {
     uint8_t next = (kbuf_head + 1) % KBUF_SIZE;
     if (next != kbuf_tail) {
         kbuf[kbuf_head] = *report;
-        kbuf_head = next;
+        kbuf_head       = next;
     } else {
         debug("kbuf: full\n");
     }
@@ -112,119 +101,97 @@ static void send_keyboard(report_keyboard_t *report)
     vusb_transfer_keyboard();
 }
 
-
 typedef struct {
-    uint8_t report_id;
+    uint8_t        report_id;
     report_mouse_t report;
-} __attribute__ ((packed)) vusb_mouse_report_t;
-
-static void send_mouse(report_mouse_t *report)
-{
-    vusb_mouse_report_t r = {
-        .report_id = REPORT_ID_MOUSE,
-        .report = *report
-    };
+} __attribute__((packed)) vusb_mouse_report_t;
+
+static void send_mouse(report_mouse_t *report) {
+    vusb_mouse_report_t r = {.report_id = REPORT_ID_MOUSE, .report = *report};
     if (usbInterruptIsReady3()) {
         usbSetInterrupt3((void *)&r, sizeof(vusb_mouse_report_t));
     }
 }
 
-
 typedef struct {
     uint8_t  report_id;
     uint16_t usage;
-} __attribute__ ((packed)) report_extra_t;
+} __attribute__((packed)) report_extra_t;
 
-static void send_system(uint16_t data)
-{
+static void send_system(uint16_t data) {
     static uint16_t last_data = 0;
     if (data == last_data) return;
     last_data = data;
 
-    report_extra_t report = {
-        .report_id = REPORT_ID_SYSTEM,
-        .usage = data
-    };
+    report_extra_t report = {.report_id = REPORT_ID_SYSTEM, .usage = data};
     if (usbInterruptIsReady3()) {
         usbSetInterrupt3((void *)&report, sizeof(report));
     }
 }
 
-static void send_consumer(uint16_t data)
-{
+static void send_consumer(uint16_t data) {
     static uint16_t last_data = 0;
     if (data == last_data) return;
     last_data = data;
 
-    report_extra_t report = {
-        .report_id = REPORT_ID_CONSUMER,
-        .usage = data
-    };
+    report_extra_t report = {.report_id = REPORT_ID_CONSUMER, .usage = data};
     if (usbInterruptIsReady3()) {
         usbSetInterrupt3((void *)&report, sizeof(report));
     }
 }
 
-
-
 /*------------------------------------------------------------------*
  * Request from host                                                *
  *------------------------------------------------------------------*/
 static struct {
-    uint16_t        len;
-    enum {
-        NONE,
-        BOOTLOADER,
-        SET_LED
-    }               kind;
+    uint16_t len;
+    enum { NONE, BOOTLOADER, SET_LED } kind;
 } last_req;
 
-usbMsgLen_t usbFunctionSetup(uchar data[8])
-{
-usbRequest_t    *rq = (void *)data;
+usbMsgLen_t usbFunctionSetup(uchar data[8]) {
+    usbRequest_t *rq = (void *)data;
 
-    if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* class request type */
-        if(rq->bRequest == USBRQ_HID_GET_REPORT){
+    if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */
+        if (rq->bRequest == USBRQ_HID_GET_REPORT) {
             debug("GET_REPORT:");
             /* we only have one report type, so don't look at wValue */
             usbMsgPtr = (void *)&keyboard_report;
             return sizeof(keyboard_report);
-        }else if(rq->bRequest == USBRQ_HID_GET_IDLE){
+        } else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
             debug("GET_IDLE: ");
-            //debug_hex(vusb_idle_rate);
+            // debug_hex(vusb_idle_rate);
             usbMsgPtr = &vusb_idle_rate;
             return 1;
-        }else if(rq->bRequest == USBRQ_HID_SET_IDLE){
+        } else if (rq->bRequest == USBRQ_HID_SET_IDLE) {
             vusb_idle_rate = rq->wValue.bytes[1];
             debug("SET_IDLE: ");
             debug_hex(vusb_idle_rate);
-        }else if(rq->bRequest == USBRQ_HID_SET_REPORT){
+        } else if (rq->bRequest == USBRQ_HID_SET_REPORT) {
             debug("SET_REPORT: ");
             // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard)
             if (rq->wValue.word == 0x0200 && rq->wIndex.word == 0) {
                 debug("SET_LED: ");
                 last_req.kind = SET_LED;
-                last_req.len = rq->wLength.word;
+                last_req.len  = rq->wLength.word;
 #ifdef BOOTLOADER_SIZE
-            } else if(rq->wValue.word == 0x0301) {
+            } else if (rq->wValue.word == 0x0301) {
                 last_req.kind = BOOTLOADER;
-                last_req.len = rq->wLength.word;
+                last_req.len  = rq->wLength.word;
 #endif
             }
-            return USB_NO_MSG; // to get data in usbFunctionWrite
+            return USB_NO_MSG;  // to get data in usbFunctionWrite
         } else {
             debug("UNKNOWN:");
         }
-    }else{
+    } else {
         debug("VENDOR:");
         /* no vendor specific requests implemented */
     }
     debug("\n");
-    return 0;   /* default for not implemented requests: return no data back to host */
+    return 0; /* default for not implemented requests: return no data back to host */
 }
 
-uchar usbFunctionWrite(uchar *data, uchar len)
-{
+uchar usbFunctionWrite(uchar *data, uchar len) {
     if (last_req.len == 0) {
         return -1;
     }
@@ -234,7 +201,7 @@ uchar usbFunctionWrite(uchar *data, uchar len)
             debug_hex(data[0]);
             debug("\n");
             vusb_keyboard_leds = data[0];
-            last_req.len = 0;
+            last_req.len       = 0;
             return 1;
             break;
         case BOOTLOADER:
@@ -250,8 +217,6 @@ uchar usbFunctionWrite(uchar *data, uchar len)
     return 1;
 }
 
-
-
 /*------------------------------------------------------------------*
  * Descriptors                                                      *
  *------------------------------------------------------------------*/
@@ -262,38 +227,38 @@ uchar usbFunctionWrite(uchar *data, uchar len)
  * from an example in HID spec appendix
  */
 const PROGMEM uchar keyboard_hid_report[] = {
-    0x05, 0x01,          // Usage Page (Generic Desktop),
-    0x09, 0x06,          // Usage (Keyboard),
-    0xA1, 0x01,          // Collection (Application),
-    0x75, 0x01,          //   Report Size (1),
-    0x95, 0x08,          //   Report Count (8),
-    0x05, 0x07,          //   Usage Page (Key Codes),
-    0x19, 0xE0,          //   Usage Minimum (224),
-    0x29, 0xE7,          //   Usage Maximum (231),
-    0x15, 0x00,          //   Logical Minimum (0),
-    0x25, 0x01,          //   Logical Maximum (1),
-    0x81, 0x02,          //   Input (Data, Variable, Absolute), ;Modifier byte
-    0x95, 0x01,          //   Report Count (1),
-    0x75, 0x08,          //   Report Size (8),
-    0x81, 0x03,          //   Input (Constant),                 ;Reserved byte
-    0x95, 0x05,          //   Report Count (5),
-    0x75, 0x01,          //   Report Size (1),
-    0x05, 0x08,          //   Usage Page (LEDs),
-    0x19, 0x01,          //   Usage Minimum (1),
-    0x29, 0x05,          //   Usage Maximum (5),
-    0x91, 0x02,          //   Output (Data, Variable, Absolute), ;LED report
-    0x95, 0x01,          //   Report Count (1),
-    0x75, 0x03,          //   Report Size (3),
-    0x91, 0x03,          //   Output (Constant),                 ;LED report padding
-    0x95, 0x06,          //   Report Count (6),
-    0x75, 0x08,          //   Report Size (8),
-    0x15, 0x00,          //   Logical Minimum (0),
-    0x26, 0xFF, 0x00,    //   Logical Maximum(255),
-    0x05, 0x07,          //   Usage Page (Key Codes),
-    0x19, 0x00,          //   Usage Minimum (0),
-    0x29, 0xFF,          //   Usage Maximum (255),
-    0x81, 0x00,          //   Input (Data, Array),
-    0xc0                 // End Collection
+    0x05, 0x01,        // Usage Page (Generic Desktop),
+    0x09, 0x06,        // Usage (Keyboard),
+    0xA1, 0x01,        // Collection (Application),
+    0x75, 0x01,        //   Report Size (1),
+    0x95, 0x08,        //   Report Count (8),
+    0x05, 0x07,        //   Usage Page (Key Codes),
+    0x19, 0xE0,        //   Usage Minimum (224),
+    0x29, 0xE7,        //   Usage Maximum (231),
+    0x15, 0x00,        //   Logical Minimum (0),
+    0x25, 0x01,        //   Logical Maximum (1),
+    0x81, 0x02,        //   Input (Data, Variable, Absolute), ;Modifier byte
+    0x95, 0x01,        //   Report Count (1),
+    0x75, 0x08,        //   Report Size (8),
+    0x81, 0x03,        //   Input (Constant),                 ;Reserved byte
+    0x95, 0x05,        //   Report Count (5),
+    0x75, 0x01,        //   Report Size (1),
+    0x05, 0x08,        //   Usage Page (LEDs),
+    0x19, 0x01,        //   Usage Minimum (1),
+    0x29, 0x05,        //   Usage Maximum (5),
+    0x91, 0x02,        //   Output (Data, Variable, Absolute), ;LED report
+    0x95, 0x01,        //   Report Count (1),
+    0x75, 0x03,        //   Report Size (3),
+    0x91, 0x03,        //   Output (Constant),                 ;LED report padding
+    0x95, 0x06,        //   Report Count (6),
+    0x75, 0x08,        //   Report Size (8),
+    0x15, 0x00,        //   Logical Minimum (0),
+    0x26, 0xFF, 0x00,  //   Logical Maximum(255),
+    0x05, 0x07,        //   Usage Page (Key Codes),
+    0x19, 0x00,        //   Usage Minimum (0),
+    0x29, 0xFF,        //   Usage Maximum (255),
+    0x81, 0x00,        //   Input (Data, Array),
+    0xc0               // End Collection
 };
 
 /*
@@ -306,196 +271,191 @@ const PROGMEM uchar keyboard_hid_report[] = {
  */
 const PROGMEM uchar mouse_hid_report[] = {
     /* mouse */
-    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
-    0x09, 0x02,                    // USAGE (Mouse)
-    0xa1, 0x01,                    // COLLECTION (Application)
-    0x85, REPORT_ID_MOUSE,         //   REPORT_ID (1)
-    0x09, 0x01,                    //   USAGE (Pointer)
-    0xa1, 0x00,                    //   COLLECTION (Physical)
-                                   // ----------------------------  Buttons
-    0x05, 0x09,                    //     USAGE_PAGE (Button)
-    0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
-    0x29, 0x05,                    //     USAGE_MAXIMUM (Button 5)
-    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
-    0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
-    0x75, 0x01,                    //     REPORT_SIZE (1)
-    0x95, 0x05,                    //     REPORT_COUNT (5)
-    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
-    0x75, 0x03,                    //     REPORT_SIZE (3)
-    0x95, 0x01,                    //     REPORT_COUNT (1)
-    0x81, 0x03,                    //     INPUT (Cnst,Var,Abs)
-                                   // ----------------------------  X,Y position
-    0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
-    0x09, 0x30,                    //     USAGE (X)
-    0x09, 0x31,                    //     USAGE (Y)
-    0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
-    0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
-    0x75, 0x08,                    //     REPORT_SIZE (8)
-    0x95, 0x02,                    //     REPORT_COUNT (2)
-    0x81, 0x06,                    //     INPUT (Data,Var,Rel)
-                                   // ----------------------------  Vertical wheel
-    0x09, 0x38,                    //     USAGE (Wheel)
-    0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
-    0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
-    0x35, 0x00,                    //     PHYSICAL_MINIMUM (0)        - reset physical
-    0x45, 0x00,                    //     PHYSICAL_MAXIMUM (0)
-    0x75, 0x08,                    //     REPORT_SIZE (8)
-    0x95, 0x01,                    //     REPORT_COUNT (1)
-    0x81, 0x06,                    //     INPUT (Data,Var,Rel)
-                                   // ----------------------------  Horizontal wheel
-    0x05, 0x0c,                    //     USAGE_PAGE (Consumer Devices)
-    0x0a, 0x38, 0x02,              //     USAGE (AC Pan)
-    0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
-    0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
-    0x75, 0x08,                    //     REPORT_SIZE (8)
-    0x95, 0x01,                    //     REPORT_COUNT (1)
-    0x81, 0x06,                    //     INPUT (Data,Var,Rel)
-    0xc0,                          //   END_COLLECTION
-    0xc0,                          // END_COLLECTION
+    0x05, 0x01,             // USAGE_PAGE (Generic Desktop)
+    0x09, 0x02,             // USAGE (Mouse)
+    0xa1, 0x01,             // COLLECTION (Application)
+    0x85, REPORT_ID_MOUSE,  //   REPORT_ID (1)
+    0x09, 0x01,             //   USAGE (Pointer)
+    0xa1, 0x00,             //   COLLECTION (Physical)
+                            // ----------------------------  Buttons
+    0x05, 0x09,             //     USAGE_PAGE (Button)
+    0x19, 0x01,             //     USAGE_MINIMUM (Button 1)
+    0x29, 0x05,             //     USAGE_MAXIMUM (Button 5)
+    0x15, 0x00,             //     LOGICAL_MINIMUM (0)
+    0x25, 0x01,             //     LOGICAL_MAXIMUM (1)
+    0x75, 0x01,             //     REPORT_SIZE (1)
+    0x95, 0x05,             //     REPORT_COUNT (5)
+    0x81, 0x02,             //     INPUT (Data,Var,Abs)
+    0x75, 0x03,             //     REPORT_SIZE (3)
+    0x95, 0x01,             //     REPORT_COUNT (1)
+    0x81, 0x03,             //     INPUT (Cnst,Var,Abs)
+                            // ----------------------------  X,Y position
+    0x05, 0x01,             //     USAGE_PAGE (Generic Desktop)
+    0x09, 0x30,             //     USAGE (X)
+    0x09, 0x31,             //     USAGE (Y)
+    0x15, 0x81,             //     LOGICAL_MINIMUM (-127)
+    0x25, 0x7f,             //     LOGICAL_MAXIMUM (127)
+    0x75, 0x08,             //     REPORT_SIZE (8)
+    0x95, 0x02,             //     REPORT_COUNT (2)
+    0x81, 0x06,             //     INPUT (Data,Var,Rel)
+                            // ----------------------------  Vertical wheel
+    0x09, 0x38,             //     USAGE (Wheel)
+    0x15, 0x81,             //     LOGICAL_MINIMUM (-127)
+    0x25, 0x7f,             //     LOGICAL_MAXIMUM (127)
+    0x35, 0x00,             //     PHYSICAL_MINIMUM (0)        - reset physical
+    0x45, 0x00,             //     PHYSICAL_MAXIMUM (0)
+    0x75, 0x08,             //     REPORT_SIZE (8)
+    0x95, 0x01,             //     REPORT_COUNT (1)
+    0x81, 0x06,             //     INPUT (Data,Var,Rel)
+                            // ----------------------------  Horizontal wheel
+    0x05, 0x0c,             //     USAGE_PAGE (Consumer Devices)
+    0x0a, 0x38, 0x02,       //     USAGE (AC Pan)
+    0x15, 0x81,             //     LOGICAL_MINIMUM (-127)
+    0x25, 0x7f,             //     LOGICAL_MAXIMUM (127)
+    0x75, 0x08,             //     REPORT_SIZE (8)
+    0x95, 0x01,             //     REPORT_COUNT (1)
+    0x81, 0x06,             //     INPUT (Data,Var,Rel)
+    0xc0,                   //   END_COLLECTION
+    0xc0,                   // END_COLLECTION
     /* system control */
-    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
-    0x09, 0x80,                    // USAGE (System Control)
-    0xa1, 0x01,                    // COLLECTION (Application)
-    0x85, REPORT_ID_SYSTEM,        //   REPORT_ID (2)
-    0x15, 0x01,                    //   LOGICAL_MINIMUM (0x1)
-    0x26, 0xb7, 0x00,              //   LOGICAL_MAXIMUM (0xb7)
-    0x19, 0x01,                    //   USAGE_MINIMUM (0x1)
-    0x29, 0xb7,                    //   USAGE_MAXIMUM (0xb7)
-    0x75, 0x10,                    //   REPORT_SIZE (16)
-    0x95, 0x01,                    //   REPORT_COUNT (1)
-    0x81, 0x00,                    //   INPUT (Data,Array,Abs)
-    0xc0,                          // END_COLLECTION
+    0x05, 0x01,              // USAGE_PAGE (Generic Desktop)
+    0x09, 0x80,              // USAGE (System Control)
+    0xa1, 0x01,              // COLLECTION (Application)
+    0x85, REPORT_ID_SYSTEM,  //   REPORT_ID (2)
+    0x15, 0x01,              //   LOGICAL_MINIMUM (0x1)
+    0x26, 0xb7, 0x00,        //   LOGICAL_MAXIMUM (0xb7)
+    0x19, 0x01,              //   USAGE_MINIMUM (0x1)
+    0x29, 0xb7,              //   USAGE_MAXIMUM (0xb7)
+    0x75, 0x10,              //   REPORT_SIZE (16)
+    0x95, 0x01,              //   REPORT_COUNT (1)
+    0x81, 0x00,              //   INPUT (Data,Array,Abs)
+    0xc0,                    // END_COLLECTION
     /* consumer */
-    0x05, 0x0c,                    // USAGE_PAGE (Consumer Devices)
-    0x09, 0x01,                    // USAGE (Consumer Control)
-    0xa1, 0x01,                    // COLLECTION (Application)
-    0x85, REPORT_ID_CONSUMER,      //   REPORT_ID (3)
-    0x15, 0x01,                    //   LOGICAL_MINIMUM (0x1)
-    0x26, 0x9c, 0x02,              //   LOGICAL_MAXIMUM (0x29c)
-    0x19, 0x01,                    //   USAGE_MINIMUM (0x1)
-    0x2a, 0x9c, 0x02,              //   USAGE_MAXIMUM (0x29c)
-    0x75, 0x10,                    //   REPORT_SIZE (16)
-    0x95, 0x01,                    //   REPORT_COUNT (1)
-    0x81, 0x00,                    //   INPUT (Data,Array,Abs)
-    0xc0,                          // END_COLLECTION
+    0x05, 0x0c,                // USAGE_PAGE (Consumer Devices)
+    0x09, 0x01,                // USAGE (Consumer Control)
+    0xa1, 0x01,                // COLLECTION (Application)
+    0x85, REPORT_ID_CONSUMER,  //   REPORT_ID (3)
+    0x15, 0x01,                //   LOGICAL_MINIMUM (0x1)
+    0x26, 0x9c, 0x02,          //   LOGICAL_MAXIMUM (0x29c)
+    0x19, 0x01,                //   USAGE_MINIMUM (0x1)
+    0x2a, 0x9c, 0x02,          //   USAGE_MAXIMUM (0x29c)
+    0x75, 0x10,                //   REPORT_SIZE (16)
+    0x95, 0x01,                //   REPORT_COUNT (1)
+    0x81, 0x00,                //   INPUT (Data,Array,Abs)
+    0xc0,                      // END_COLLECTION
 };
 
-
-/* 
+/*
  * Descriptor for compite device: Keyboard + Mouse
- * 
+ *
  * contains: device, interface, HID and endpoint descriptors
  */
 #if USB_CFG_DESCR_PROPS_CONFIGURATION
-const PROGMEM char usbDescriptorConfiguration[] = {    /* USB configuration descriptor */
-    9,          /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */
-    USBDESCR_CONFIG,    /* descriptor type */
+const PROGMEM char usbDescriptorConfiguration[] = {
+    /* USB configuration descriptor */
+    9,               /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */
+    USBDESCR_CONFIG, /* descriptor type */
     9 + (9 + 9 + 7) + (9 + 9 + 7), 0,
-    //18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + 9, 0,
-                /* total length of data returned (including inlined descriptors) */
-    2,          /* number of interfaces in this configuration */
-    1,          /* index of this configuration */
-    0,          /* configuration name string index */
-#if USB_CFG_IS_SELF_POWERED
-    (1 << 7) | USBATTR_SELFPOWER,       /* attributes */
-#else
-    (1 << 7),                           /* attributes */
-#endif
-    USB_CFG_MAX_BUS_POWER/2,            /* max USB current in 2mA units */
+    // 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + 9, 0,
+    /* total length of data returned (including inlined descriptors) */
+    2, /* number of interfaces in this configuration */
+    1, /* index of this configuration */
+    0, /* configuration name string index */
+#    if USB_CFG_IS_SELF_POWERED
+    (1 << 7) | USBATTR_SELFPOWER, /* attributes */
+#    else
+    (1 << 7), /* attributes */
+#    endif
+    USB_CFG_MAX_BUS_POWER / 2, /* max USB current in 2mA units */
 
     /*
      * Keyboard interface
      */
     /* Interface descriptor */
-    9,          /* sizeof(usbDescrInterface): length of descriptor in bytes */
-    USBDESCR_INTERFACE, /* descriptor type */
-    0,          /* index of this interface */
-    0,          /* alternate setting for this interface */
-    USB_CFG_HAVE_INTRIN_ENDPOINT, /* endpoints excl 0: number of endpoint descriptors to follow */
-    USB_CFG_INTERFACE_CLASS,
-    USB_CFG_INTERFACE_SUBCLASS,
-    USB_CFG_INTERFACE_PROTOCOL,
-    0,          /* string index for interface */
+    9,                                                                                  /* sizeof(usbDescrInterface): length of descriptor in bytes */
+    USBDESCR_INTERFACE,                                                                 /* descriptor type */
+    0,                                                                                  /* index of this interface */
+    0,                                                                                  /* alternate setting for this interface */
+    USB_CFG_HAVE_INTRIN_ENDPOINT,                                                       /* endpoints excl 0: number of endpoint descriptors to follow */
+    USB_CFG_INTERFACE_CLASS, USB_CFG_INTERFACE_SUBCLASS, USB_CFG_INTERFACE_PROTOCOL, 0, /* string index for interface */
     /* HID descriptor */
-    9,          /* sizeof(usbDescrHID): length of descriptor in bytes */
-    USBDESCR_HID,   /* descriptor type: HID */
-    0x01, 0x01, /* BCD representation of HID version */
-    0x00,       /* target country code */
-    0x01,       /* number of HID Report (or other HID class) Descriptor infos to follow */
-    0x22,       /* descriptor type: report */
-    sizeof(keyboard_hid_report), 0,  /* total length of report descriptor */
-    /* Endpoint descriptor */
-#if USB_CFG_HAVE_INTRIN_ENDPOINT    /* endpoint descriptor for endpoint 1 */
-    7,          /* sizeof(usbDescrEndpoint) */
-    USBDESCR_ENDPOINT,  /* descriptor type = endpoint */
-    (char)0x81, /* IN endpoint number 1 */
-    0x03,       /* attrib: Interrupt endpoint */
-    8, 0,       /* maximum packet size */
-    USB_CFG_INTR_POLL_INTERVAL, /* in ms */
-#endif
+    9,                              /* sizeof(usbDescrHID): length of descriptor in bytes */
+    USBDESCR_HID,                   /* descriptor type: HID */
+    0x01, 0x01,                     /* BCD representation of HID version */
+    0x00,                           /* target country code */
+    0x01,                           /* number of HID Report (or other HID class) Descriptor infos to follow */
+    0x22,                           /* descriptor type: report */
+    sizeof(keyboard_hid_report), 0, /* total length of report descriptor */
+/* Endpoint descriptor */
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT /* endpoint descriptor for endpoint 1 */
+    7,                               /* sizeof(usbDescrEndpoint) */
+    USBDESCR_ENDPOINT,               /* descriptor type = endpoint */
+    (char)0x81,                      /* IN endpoint number 1 */
+    0x03,                            /* attrib: Interrupt endpoint */
+    8, 0,                            /* maximum packet size */
+    USB_CFG_INTR_POLL_INTERVAL,      /* in ms */
+#    endif
 
     /*
      * Mouse interface
      */
     /* Interface descriptor */
-    9,          /* sizeof(usbDescrInterface): length of descriptor in bytes */
-    USBDESCR_INTERFACE, /* descriptor type */
-    1,          /* index of this interface */
-    0,          /* alternate setting for this interface */
+    9,                             /* sizeof(usbDescrInterface): length of descriptor in bytes */
+    USBDESCR_INTERFACE,            /* descriptor type */
+    1,                             /* index of this interface */
+    0,                             /* alternate setting for this interface */
     USB_CFG_HAVE_INTRIN_ENDPOINT3, /* endpoints excl 0: number of endpoint descriptors to follow */
-    0x03,       /* CLASS: HID */
-    0,          /* SUBCLASS: none */
-    0,          /* PROTOCOL: none */
-    0,          /* string index for interface */
+    0x03,                          /* CLASS: HID */
+    0,                             /* SUBCLASS: none */
+    0,                             /* PROTOCOL: none */
+    0,                             /* string index for interface */
     /* HID descriptor */
-    9,          /* sizeof(usbDescrHID): length of descriptor in bytes */
-    USBDESCR_HID,   /* descriptor type: HID */
-    0x01, 0x01, /* BCD representation of HID version */
-    0x00,       /* target country code */
-    0x01,       /* number of HID Report (or other HID class) Descriptor infos to follow */
-    0x22,       /* descriptor type: report */
-    sizeof(mouse_hid_report), 0,  /* total length of report descriptor */
-#if USB_CFG_HAVE_INTRIN_ENDPOINT3   /* endpoint descriptor for endpoint 3 */
+    9,                                /* sizeof(usbDescrHID): length of descriptor in bytes */
+    USBDESCR_HID,                     /* descriptor type: HID */
+    0x01, 0x01,                       /* BCD representation of HID version */
+    0x00,                             /* target country code */
+    0x01,                             /* number of HID Report (or other HID class) Descriptor infos to follow */
+    0x22,                             /* descriptor type: report */
+    sizeof(mouse_hid_report), 0,      /* total length of report descriptor */
+#    if USB_CFG_HAVE_INTRIN_ENDPOINT3 /* endpoint descriptor for endpoint 3 */
     /* Endpoint descriptor */
-    7,          /* sizeof(usbDescrEndpoint) */
-    USBDESCR_ENDPOINT,  /* descriptor type = endpoint */
+    7,                                 /* sizeof(usbDescrEndpoint) */
+    USBDESCR_ENDPOINT,                 /* descriptor type = endpoint */
     (char)(0x80 | USB_CFG_EP3_NUMBER), /* IN endpoint number 3 */
-    0x03,       /* attrib: Interrupt endpoint */
-    8, 0,       /* maximum packet size */
-    USB_CFG_INTR_POLL_INTERVAL, /* in ms */
-#endif
+    0x03,                              /* attrib: Interrupt endpoint */
+    8, 0,                              /* maximum packet size */
+    USB_CFG_INTR_POLL_INTERVAL,        /* in ms */
+#    endif
 };
 #endif
 
-
-USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq)
-{
+USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
     usbMsgLen_t len = 0;
 
-/*
-    debug("usbFunctionDescriptor: ");
-    debug_hex(rq->bmRequestType); debug(" ");
-    debug_hex(rq->bRequest); debug(" ");
-    debug_hex16(rq->wValue.word); debug(" ");
-    debug_hex16(rq->wIndex.word); debug(" ");
-    debug_hex16(rq->wLength.word); debug("\n");
-*/
+    /*
+        debug("usbFunctionDescriptor: ");
+        debug_hex(rq->bmRequestType); debug(" ");
+        debug_hex(rq->bRequest); debug(" ");
+        debug_hex16(rq->wValue.word); debug(" ");
+        debug_hex16(rq->wIndex.word); debug(" ");
+        debug_hex16(rq->wLength.word); debug("\n");
+    */
     switch (rq->wValue.bytes[1]) {
 #if USB_CFG_DESCR_PROPS_CONFIGURATION
         case USBDESCR_CONFIG:
             usbMsgPtr = (unsigned char *)usbDescriptorConfiguration;
-            len = sizeof(usbDescriptorConfiguration);
+            len       = sizeof(usbDescriptorConfiguration);
             break;
 #endif
         case USBDESCR_HID:
             switch (rq->wValue.bytes[0]) {
                 case 0:
                     usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 9 + 9);
-                    len = 9;
+                    len       = 9;
                     break;
                 case 1:
                     usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 9 + (9 + 9 + 7) + 9);
-                    len = 9;
+                    len       = 9;
                     break;
             }
             break;
@@ -504,15 +464,15 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq)
             switch (rq->wIndex.word) {
                 case 0:
                     usbMsgPtr = (unsigned char *)keyboard_hid_report;
-                    len = sizeof(keyboard_hid_report);
+                    len       = sizeof(keyboard_hid_report);
                     break;
                 case 1:
                     usbMsgPtr = (unsigned char *)mouse_hid_report;
-                    len = sizeof(mouse_hid_report);
+                    len       = sizeof(mouse_hid_report);
                     break;
             }
             break;
     }
-    //debug("desc len: "); debug_hex(len); debug("\n");
+    // debug("desc len: "); debug_hex(len); debug("\n");
     return len;
 }
index 5accf233be68d95cdc4b26b1ae5b8b32b0baca80..7e3f8c394dc5b82c38fae04736c117fa4231a033 100644 (file)
@@ -20,8 +20,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "host_driver.h"
 
-
 host_driver_t *vusb_driver(void);
-void vusb_transfer_keyboard(void);
+void           vusb_transfer_keyboard(void);
 
 #endif
index 93bc5daf8221f0923617d7a067690f968338e66b..e7e1a13f4d611f7df9376b0820047385c1c720f9 100644 (file)
@@ -39,33 +39,35 @@ POSSIBILITY OF SUCH DAMAGE.
 #ifndef XT_H
 #define XT_H
 
-#define XT_DATA_IN()        do { \
-    XT_DATA_DDR  &= ~(1<<XT_DATA_BIT); \
-    XT_DATA_PORT |=  (1<<XT_DATA_BIT); \
-} while (0)
-
-#define XT_DATA_READ()      (XT_DATA_PIN&(1<<XT_DATA_BIT))
-
-#define XT_DATA_LO()        do { \
-    XT_DATA_PORT &= ~(1<<XT_DATA_BIT); \
-    XT_DATA_DDR  |=  (1<<XT_DATA_BIT); \
-} while (0)
-
-
-#define XT_CLOCK_IN()       do { \
-    XT_CLOCK_DDR  &= ~(1<<XT_CLOCK_BIT); \
-    XT_CLOCK_PORT |=  (1<<XT_CLOCK_BIT); \
-} while (0)
-
-#define XT_CLOCK_READ()     (XT_CLOCK_PIN&(1<<XT_CLOCK_BIT))
-
-#define XT_CLOCK_LO()       do { \
-    XT_CLOCK_PORT &= ~(1<<XT_CLOCK_BIT); \
-    XT_CLOCK_DDR  |=  (1<<XT_CLOCK_BIT); \
-} while (0)
-
-
-void xt_host_init(void);
+#define XT_DATA_IN()                        \
+    do {                                    \
+        XT_DATA_DDR &= ~(1 << XT_DATA_BIT); \
+        XT_DATA_PORT |= (1 << XT_DATA_BIT); \
+    } while (0)
+
+#define XT_DATA_READ() (XT_DATA_PIN & (1 << XT_DATA_BIT))
+
+#define XT_DATA_LO()                         \
+    do {                                     \
+        XT_DATA_PORT &= ~(1 << XT_DATA_BIT); \
+        XT_DATA_DDR |= (1 << XT_DATA_BIT);   \
+    } while (0)
+
+#define XT_CLOCK_IN()                         \
+    do {                                      \
+        XT_CLOCK_DDR &= ~(1 << XT_CLOCK_BIT); \
+        XT_CLOCK_PORT |= (1 << XT_CLOCK_BIT); \
+    } while (0)
+
+#define XT_CLOCK_READ() (XT_CLOCK_PIN & (1 << XT_CLOCK_BIT))
+
+#define XT_CLOCK_LO()                          \
+    do {                                       \
+        XT_CLOCK_PORT &= ~(1 << XT_CLOCK_BIT); \
+        XT_CLOCK_DDR |= (1 << XT_CLOCK_BIT);   \
+    } while (0)
+
+void    xt_host_init(void);
 uint8_t xt_host_recv(void);
 
 #endif
index 8276f96cd3a9f6be564b99de9aed377a3fe75a68..51e52243fdaf71abd279737c66dadd3623935870 100644 (file)
@@ -44,12 +44,11 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "debug.h"
 
 static inline uint8_t pbuf_dequeue(void);
-static inline void pbuf_enqueue(uint8_t data);
-static inline bool pbuf_has_data(void);
-static inline void pbuf_clear(void);
+static inline void    pbuf_enqueue(uint8_t data);
+static inline bool    pbuf_has_data(void);
+static inline void    pbuf_clear(void);
 
-void xt_host_init(void)
-{
+void xt_host_init(void) {
     XT_INT_INIT();
     XT_INT_OFF();
 
@@ -71,8 +70,7 @@ void xt_host_init(void)
 }
 
 /* get data received by interrupt */
-uint8_t xt_host_recv(void)
-{
+uint8_t xt_host_recv(void) {
     if (pbuf_has_data()) {
         return pbuf_dequeue();
     } else {
@@ -80,8 +78,7 @@ uint8_t xt_host_recv(void)
     }
 }
 
-ISR(XT_INT_VECT)
-{
+ISR(XT_INT_VECT) {
     /*
      * XT signal format consits of 10 or 9 clocks and sends start bits and 8-bit data,
      * which should be read on falling edge of clock.
@@ -93,15 +90,13 @@ ISR(XT_INT_VECT)
      *
      * https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-XT-Keyboard-Protocol
      */
-    static enum {
-        START, BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7
-    } state = START;
-    static uint8_t data = 0;
+    static enum { START, BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7 } state = START;
+    static uint8_t data                                                         = 0;
 
     uint8_t dbit = XT_DATA_READ();
 
     // This is needed if using PCINT which can be called on both falling and rising edge
-    //if (XT_CLOCK_READ()) return;
+    // if (XT_CLOCK_READ()) return;
 
     switch (state) {
         case START:
@@ -110,14 +105,13 @@ ISR(XT_INT_VECT)
             break;
         case BIT0 ... BIT7:
             data >>= 1;
-            if (dbit)
-                data |= 0x80;
+            if (dbit) data |= 0x80;
             break;
     }
     if (state++ == BIT7) {
         pbuf_enqueue(data);
         state = START;
-        data = 0;
+        data  = 0;
     }
     return;
 }
@@ -126,48 +120,44 @@ ISR(XT_INT_VECT)
  * Ring buffer to store scan codes from keyboard
  *------------------------------------------------------------------*/
 #define PBUF_SIZE 32
-static uint8_t pbuf[PBUF_SIZE];
-static uint8_t pbuf_head = 0;
-static uint8_t pbuf_tail = 0;
-static inline void pbuf_enqueue(uint8_t data)
-{
+static uint8_t     pbuf[PBUF_SIZE];
+static uint8_t     pbuf_head = 0;
+static uint8_t     pbuf_tail = 0;
+static inline void pbuf_enqueue(uint8_t data) {
     uint8_t sreg = SREG;
     cli();
     uint8_t next = (pbuf_head + 1) % PBUF_SIZE;
     if (next != pbuf_tail) {
         pbuf[pbuf_head] = data;
-        pbuf_head = next;
+        pbuf_head       = next;
     } else {
         dprintf("pbuf: full\n");
     }
     SREG = sreg;
 }
-static inline uint8_t pbuf_dequeue(void)
-{
+static inline uint8_t pbuf_dequeue(void) {
     uint8_t val = 0;
 
     uint8_t sreg = SREG;
     cli();
     if (pbuf_head != pbuf_tail) {
-        val = pbuf[pbuf_tail];
+        val       = pbuf[pbuf_tail];
         pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE;
     }
     SREG = sreg;
 
     return val;
 }
-static inline bool pbuf_has_data(void)
-{
+static inline bool pbuf_has_data(void) {
     uint8_t sreg = SREG;
     cli();
     bool has_data = (pbuf_head != pbuf_tail);
-    SREG = sreg;
+    SREG          = sreg;
     return has_data;
 }
-static inline void pbuf_clear(void)
-{
+static inline void pbuf_clear(void) {
     uint8_t sreg = SREG;
     cli();
     pbuf_head = pbuf_tail = 0;
-    SREG = sreg;
+    SREG                  = sreg;
 }
index 005d1be61334496a405b087c2daffe332cc39b7f..6bea3509b3328eeb796c780c8f0a4c4cb736d6a3 100644 (file)
@@ -5,47 +5,38 @@
  *------------------------------------------------------------------*/
 #define RBUF_SIZE 32
 #include <util/atomic.h>
-static uint8_t rbuf[RBUF_SIZE];
-static uint8_t rbuf_head = 0;
-static uint8_t rbuf_tail = 0;
-static inline void rbuf_enqueue(uint8_t data)
-{
-  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
-    uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
-    if (next != rbuf_tail) {
-        rbuf[rbuf_head] = data;
-        rbuf_head = next;
-    } else {
-        print("rbuf: full\n");
+static uint8_t     rbuf[RBUF_SIZE];
+static uint8_t     rbuf_head = 0;
+static uint8_t     rbuf_tail = 0;
+static inline void rbuf_enqueue(uint8_t data) {
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+        uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
+        if (next != rbuf_tail) {
+            rbuf[rbuf_head] = data;
+            rbuf_head       = next;
+        } else {
+            print("rbuf: full\n");
+        }
     }
-  }
 }
-static inline uint8_t rbuf_dequeue(void)
-{
+static inline uint8_t rbuf_dequeue(void) {
     uint8_t val = 0;
-  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
-
-    if (rbuf_head != rbuf_tail) {
-        val = rbuf[rbuf_tail];
-        rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+        if (rbuf_head != rbuf_tail) {
+            val       = rbuf[rbuf_tail];
+            rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
+        }
     }
-  }
 
     return val;
 }
-static inline bool rbuf_has_data(void)
-{
-  bool has_data;
-  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
-    has_data = (rbuf_head != rbuf_tail);
-  }
-  return has_data;
+static inline bool rbuf_has_data(void) {
+    bool has_data;
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { has_data = (rbuf_head != rbuf_tail); }
+    return has_data;
 }
-static inline void rbuf_clear(void)
-{
-  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
-    rbuf_head = rbuf_tail = 0;
-  }
+static inline void rbuf_clear(void) {
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { rbuf_head = rbuf_tail = 0; }
 }
 
-#endif  /* RING_BUFFER_H */
+#endif /* RING_BUFFER_H */