Merge remote-tracking branch 'upstream/develop' into fl16-sleep-fix
This commit is contained in:
@@ -528,6 +528,13 @@ void process_action(keyrecord_t *record, action_t action) {
|
||||
unregister_code(action.key.code);
|
||||
} else {
|
||||
ac_dprintf("MODS_TAP: No tap: add_mods\n");
|
||||
# if defined(RETRO_TAPPING) && defined(DUMMY_MOD_NEUTRALIZER_KEYCODE)
|
||||
// Send a dummy keycode to neutralize flashing modifiers
|
||||
// if the key was held and then released with no interruptions.
|
||||
if (retro_tapping_counter == 2) {
|
||||
neutralize_flashing_modifiers(get_mods());
|
||||
}
|
||||
# endif
|
||||
unregister_mods(mods);
|
||||
}
|
||||
}
|
||||
@@ -885,7 +892,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
|
||||
} else if (KC_LOCKING_CAPS_LOCK == code) {
|
||||
# ifdef LOCKING_RESYNC_ENABLE
|
||||
// Resync: ignore if caps lock already is on
|
||||
if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return;
|
||||
if (host_keyboard_led_state().caps_lock) return;
|
||||
# endif
|
||||
add_key(KC_CAPS_LOCK);
|
||||
send_keyboard_report();
|
||||
@@ -895,7 +902,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
|
||||
|
||||
} else if (KC_LOCKING_NUM_LOCK == code) {
|
||||
# ifdef LOCKING_RESYNC_ENABLE
|
||||
if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return;
|
||||
if (host_keyboard_led_state().num_lock) return;
|
||||
# endif
|
||||
add_key(KC_NUM_LOCK);
|
||||
send_keyboard_report();
|
||||
@@ -905,7 +912,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
|
||||
|
||||
} else if (KC_LOCKING_SCROLL_LOCK == code) {
|
||||
# ifdef LOCKING_RESYNC_ENABLE
|
||||
if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return;
|
||||
if (host_keyboard_led_state().scroll_lock) return;
|
||||
# endif
|
||||
add_key(KC_SCROLL_LOCK);
|
||||
send_keyboard_report();
|
||||
@@ -955,7 +962,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
|
||||
} else if (KC_LOCKING_CAPS_LOCK == code) {
|
||||
# ifdef LOCKING_RESYNC_ENABLE
|
||||
// Resync: ignore if caps lock already is off
|
||||
if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return;
|
||||
if (!host_keyboard_led_state().caps_lock) return;
|
||||
# endif
|
||||
add_key(KC_CAPS_LOCK);
|
||||
send_keyboard_report();
|
||||
@@ -964,7 +971,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
|
||||
|
||||
} else if (KC_LOCKING_NUM_LOCK == code) {
|
||||
# ifdef LOCKING_RESYNC_ENABLE
|
||||
if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return;
|
||||
if (!host_keyboard_led_state().num_lock) return;
|
||||
# endif
|
||||
add_key(KC_NUM_LOCK);
|
||||
send_keyboard_report();
|
||||
@@ -973,7 +980,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
|
||||
|
||||
} else if (KC_LOCKING_SCROLL_LOCK == code) {
|
||||
# ifdef LOCKING_RESYNC_ENABLE
|
||||
if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return;
|
||||
if (!host_keyboard_led_state().scroll_lock) return;
|
||||
# endif
|
||||
add_key(KC_SCROLL_LOCK);
|
||||
send_keyboard_report();
|
||||
|
||||
@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <stdint.h>
|
||||
#include "keyboard.h"
|
||||
#include "action.h"
|
||||
#include "bitwise.h"
|
||||
|
||||
#ifdef DYNAMIC_KEYMAP_ENABLE
|
||||
# ifndef DYNAMIC_KEYMAP_LAYER_COUNT
|
||||
|
||||
@@ -500,3 +500,28 @@ __attribute__((weak)) void oneshot_layer_changed_kb(uint8_t layer) {
|
||||
uint8_t has_anymod(void) {
|
||||
return bitpop(real_mods);
|
||||
}
|
||||
|
||||
#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE
|
||||
/** \brief Send a dummy keycode in between the register and unregister event of a modifier key, to neutralize the "flashing modifiers" phenomenon.
|
||||
*
|
||||
* \param active_mods 8-bit packed bit-array describing the currently active modifiers (in the format GASCGASC).
|
||||
*
|
||||
* Certain QMK features like key overrides or retro tap must unregister a previously
|
||||
* registered modifier before sending another keycode but this can trigger undesired
|
||||
* keyboard shortcuts if the clean tap of a single modifier key is bound to an action
|
||||
* on the host OS, as is for example the case for the left GUI key on Windows, which
|
||||
* opens the Start Menu when tapped.
|
||||
*/
|
||||
void neutralize_flashing_modifiers(uint8_t active_mods) {
|
||||
// In most scenarios, the flashing modifiers phenomenon is a problem
|
||||
// only for a subset of modifier masks.
|
||||
const static uint8_t mods_to_neutralize[] = MODS_TO_NEUTRALIZE;
|
||||
const static uint8_t n_mods = ARRAY_SIZE(mods_to_neutralize);
|
||||
for (uint8_t i = 0; i < n_mods; ++i) {
|
||||
if (active_mods == mods_to_neutralize[i]) {
|
||||
tap_code(DUMMY_MOD_NEUTRALIZER_KEYCODE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -102,6 +102,19 @@ void use_oneshot_swaphands(void);
|
||||
void clear_oneshot_swaphands(void);
|
||||
#endif
|
||||
|
||||
#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE
|
||||
// KC_A is used as the lowerbound instead of QK_BASIC because the range QK_BASIC...KC_A includes
|
||||
// internal keycodes like KC_NO and KC_TRANSPARENT which are unsuitable for use with `tap_code(kc)`.
|
||||
# if !(KC_A <= DUMMY_MOD_NEUTRALIZER_KEYCODE && DUMMY_MOD_NEUTRALIZER_KEYCODE <= QK_BASIC_MAX)
|
||||
# error "DUMMY_MOD_NEUTRALIZER_KEYCODE must be a basic, unmodified, HID keycode!"
|
||||
# endif
|
||||
void neutralize_flashing_modifiers(uint8_t active_mods);
|
||||
#endif
|
||||
#ifndef MODS_TO_NEUTRALIZE
|
||||
# define MODS_TO_NEUTRALIZE \
|
||||
{ MOD_BIT(KC_LEFT_ALT), MOD_BIT(KC_LEFT_GUI) }
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -547,20 +547,42 @@ void audio_decrease_tempo(uint8_t tempo_change) {
|
||||
note_tempo -= tempo_change;
|
||||
}
|
||||
|
||||
// TODO in the int-math version are some bugs; songs sometimes abruptly end - maybe an issue with the timer/system-tick wrapping around?
|
||||
/**
|
||||
* Converts from units of 1/64ths of a beat to milliseconds.
|
||||
*
|
||||
* Round-off error is at most 1 millisecond.
|
||||
*
|
||||
* Conversion will never overflow for duration_bpm <= 699, provided that
|
||||
* note_tempo is at least 10. This is quite a long duration, over ten beats.
|
||||
*
|
||||
* Beware that for duration_bpm > 699, the result may overflow uint16_t range
|
||||
* when duration_bpm is large compared to note_tempo:
|
||||
*
|
||||
* duration_bpm * 60 * 1000 / (64 * note_tempo) > UINT16_MAX
|
||||
*
|
||||
* duration_bpm > (2 * 65535 / 1875) * note_tempo
|
||||
* = 69.904 * note_tempo.
|
||||
*/
|
||||
uint16_t audio_duration_to_ms(uint16_t duration_bpm) {
|
||||
#if defined(__AVR__)
|
||||
// doing int-math saves us some bytes in the overall firmware size, but the intermediate result is less accurate before being cast to/returned as uint
|
||||
return ((uint32_t)duration_bpm * 60 * 1000) / (64 * note_tempo);
|
||||
// NOTE: beware of uint16_t overflows when note_tempo is low and/or the duration is long
|
||||
#else
|
||||
return ((float)duration_bpm * 60) / (64 * note_tempo) * 1000;
|
||||
#endif
|
||||
return ((uint32_t)duration_bpm * 1875) / ((uint_fast16_t)note_tempo * 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from units of milliseconds to 1/64ths of a beat.
|
||||
*
|
||||
* Round-off error is at most 1/64th of a beat.
|
||||
*
|
||||
* This conversion never overflows: since duration_ms <= UINT16_MAX = 65535
|
||||
* and note_tempo <= 255, the result is always in uint16_t range:
|
||||
*
|
||||
* duration_ms * 64 * note_tempo / 60 / 1000
|
||||
* <= 65535 * 2 * 255 / 1875
|
||||
* = 17825.52
|
||||
* <= UINT16_MAX.
|
||||
*/
|
||||
uint16_t audio_ms_to_duration(uint16_t duration_ms) {
|
||||
#if defined(__AVR__)
|
||||
return ((uint32_t)duration_ms * 64 * note_tempo) / 60 / 1000;
|
||||
#else
|
||||
return ((float)duration_ms * 64 * note_tempo) / 60 / 1000;
|
||||
#endif
|
||||
return ((uint32_t)duration_ms * 2 * note_tempo) / 1875;
|
||||
}
|
||||
|
||||
__attribute__((weak)) void audio_on_user(void) {}
|
||||
__attribute__((weak)) void audio_off_user(void) {}
|
||||
|
||||
@@ -21,12 +21,6 @@
|
||||
#include "musical_notes.h"
|
||||
#include "song_list.h"
|
||||
#include "voices.h"
|
||||
#include "quantum.h"
|
||||
#include <math.h>
|
||||
|
||||
#if defined(__AVR__)
|
||||
# include <avr/io.h>
|
||||
#endif
|
||||
|
||||
#if defined(AUDIO_DRIVER_PWM)
|
||||
# include "audio_pwm.h"
|
||||
@@ -280,3 +274,6 @@ bool audio_update_state(void);
|
||||
#define increase_tempo(t) audio_increase_tempo(t)
|
||||
#define decrease_tempo(t) audio_decrease_tempo(t)
|
||||
// vibrato functions are not used in any keyboards
|
||||
|
||||
void audio_on_user(void);
|
||||
void audio_off_user(void);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "muse.h"
|
||||
|
||||
#include <stdbool.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 };
|
||||
|
||||
bool number_of_ones_to_bool[16] = {1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "quantum.h"
|
||||
#include "process_audio.h"
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t muse_clock_pulse(void);
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
*/
|
||||
#include "voices.h"
|
||||
#include "audio.h"
|
||||
#include "timer.h"
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
uint8_t note_timbre = TIMBRE_DEFAULT;
|
||||
bool glissando = false;
|
||||
|
||||
@@ -15,7 +15,6 @@ 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 "quantum.h"
|
||||
#include "backlight.h"
|
||||
#include "eeprom.h"
|
||||
#include "eeconfig.h"
|
||||
|
||||
@@ -1,473 +0,0 @@
|
||||
#include "quantum.h"
|
||||
#include "backlight.h"
|
||||
#include "backlight_driver_common.h"
|
||||
#include "debug.h"
|
||||
|
||||
// Maximum duty cycle limit
|
||||
#ifndef BACKLIGHT_LIMIT_VAL
|
||||
# define BACKLIGHT_LIMIT_VAL 255
|
||||
#endif
|
||||
|
||||
// This logic is a bit complex, we support 3 setups:
|
||||
//
|
||||
// 1. Hardware PWM when backlight is wired to a PWM pin.
|
||||
// Depending on this pin, we use a different output compare unit.
|
||||
// 2. Software PWM with hardware timers, but the used timer
|
||||
// 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 COMxx0 COM1A0
|
||||
# define COMxx1 COM1A1
|
||||
# define OCRxx OCR1A
|
||||
# elif BACKLIGHT_PIN == B6
|
||||
# define COMxx0 COM1B0
|
||||
# define COMxx1 COM1B1
|
||||
# define OCRxx OCR1B
|
||||
# elif BACKLIGHT_PIN == B7
|
||||
# define COMxx0 COM1C0
|
||||
# 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 COMxx0 COM3C0
|
||||
# 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 COMxx0 COM3B0
|
||||
# define COMxx1 COM3B1
|
||||
# define OCRxx OCR3B
|
||||
# endif
|
||||
# elif BACKLIGHT_PIN == C6
|
||||
# define COMxx0 COM3A0
|
||||
# define COMxx1 COM3A1
|
||||
# define OCRxx OCR3A
|
||||
# endif
|
||||
#elif (defined(__AVR_AT90USB162__) || 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 COMxx0 COM1C0
|
||||
# define COMxx1 COM1C1
|
||||
# define OCRxx OCR1C
|
||||
# elif BACKLIGHT_PIN == C5
|
||||
# define COMxx0 COM1B0
|
||||
# define COMxx1 COM1B1
|
||||
# define OCRxx OCR1B
|
||||
# elif BACKLIGHT_PIN == C6
|
||||
# define COMxx0 COM1A0
|
||||
# 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 COMxx0 COM1B0
|
||||
# define COMxx1 COM1B1
|
||||
# define OCRxx OCR1B
|
||||
# elif BACKLIGHT_PIN == D5
|
||||
# define COMxx0 COM1A0
|
||||
# define COMxx1 COM1A1
|
||||
# define OCRxx OCR1A
|
||||
# endif
|
||||
#elif (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)) && (BACKLIGHT_PIN == B1 || BACKLIGHT_PIN == B2)
|
||||
# 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 == B1
|
||||
# define COMxx0 COM1A0
|
||||
# define COMxx1 COM1A1
|
||||
# define OCRxx OCR1A
|
||||
# elif BACKLIGHT_PIN == B2
|
||||
# define COMxx0 COM1B0
|
||||
# define COMxx1 COM1B1
|
||||
# define OCRxx OCR1B
|
||||
# endif
|
||||
#elif (AUDIO_PIN != B5) && (AUDIO_PIN != B6) && (AUDIO_PIN != B7) && (AUDIO_PIN_ALT != B5) && (AUDIO_PIN_ALT != B6) && (AUDIO_PIN_ALT != B7)
|
||||
// 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 (AUDIO_PIN != C4) && (AUDIO_PIN != C5) && (AUDIO_PIN != C6)
|
||||
# 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
|
||||
#elif defined(BACKLIGHT_CUSTOM_DRIVER)
|
||||
error("Please set 'BACKLIGHT_DRIVER = custom' within rules.mk")
|
||||
#else
|
||||
error("Please set 'BACKLIGHT_DRIVER = software' within rules.mk")
|
||||
#endif
|
||||
|
||||
#ifndef BACKLIGHT_PWM_TIMER // pwm through software
|
||||
|
||||
static inline void enable_pwm(void) {
|
||||
# if BACKLIGHT_ON_STATE == 1
|
||||
TCCRxA |= _BV(COMxx1);
|
||||
# else
|
||||
TCCRxA |= _BV(COMxx1) | _BV(COMxx0);
|
||||
# endif
|
||||
}
|
||||
|
||||
static inline void disable_pwm(void) {
|
||||
# if BACKLIGHT_ON_STATE == 1
|
||||
TCCRxA &= ~(_BV(COMxx1));
|
||||
# else
|
||||
TCCRxA &= ~(_BV(COMxx1) | _BV(COMxx0));
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#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
|
||||
// instead of letting the Output Match Comparator control the led pin
|
||||
// (which is not possible since the backlight is not wired to PWM pins on the
|
||||
// CPU), we do the LED on/off by oursleves.
|
||||
// The timer is setup to count up to 0xFFFF, and we set the Output Compare
|
||||
// register to the current 16bits backlight level (after CIE correction).
|
||||
// This means the CPU will trigger a compare match interrupt when the counter
|
||||
// reaches the backlight level, where we turn off the LEDs,
|
||||
// but also an overflow interrupt when the counter rolls back to 0,
|
||||
// in which we're going to turn on the LEDs.
|
||||
// The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz,
|
||||
// or F_CPU/BACKLIGHT_CUSTOM_RESOLUTION if used.
|
||||
|
||||
// Triggered when the counter reaches the OCRx value
|
||||
ISR(TIMERx_COMPA_vect) {
|
||||
backlight_pins_off();
|
||||
}
|
||||
|
||||
// Triggered when the counter reaches the TOP value
|
||||
// this one triggers at F_CPU/ICRx = 16MHz/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 > ICRx / 250 + 5) {
|
||||
backlight_pins_on();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define TIMER_TOP 0xFFFFU
|
||||
|
||||
// See http://jared.geek.nz/2013/feb/linear-led-pwm
|
||||
static uint16_t cie_lightness(uint16_t v) {
|
||||
if (v <= (uint32_t)ICRx / 12) // If the value is less than or equal to ~8% of max
|
||||
{
|
||||
return v / 9; // Same as dividing by 900%
|
||||
} else {
|
||||
// In the next two lines values are bit-shifted. This is to avoid loosing decimals in integer math.
|
||||
uint32_t y = (((uint32_t)v + (uint32_t)ICRx / 6) << 5) / ((uint32_t)ICRx / 6 + ICRx); // If above 8%, add ~16% of max, and normalize with (max + ~16% max)
|
||||
uint32_t out = (y * y * y * ICRx) >> 15; // Cube it and undo the bit-shifting. (which is now three times as much due to the cubing)
|
||||
|
||||
if (out > ICRx) // Avoid overflows
|
||||
{
|
||||
out = ICRx;
|
||||
}
|
||||
return (uint16_t)out;
|
||||
}
|
||||
}
|
||||
|
||||
// rescale the supplied backlight value to be in terms of the value limit // range for val is [0..ICRx]. PWM pin is high while the timer count is below val.
|
||||
static uint32_t rescale_limit_val(uint32_t val) {
|
||||
return (val * (BACKLIGHT_LIMIT_VAL + 1)) / 256;
|
||||
}
|
||||
|
||||
// range for val is [0..ICRx]. PWM pin is high while the timer count is below val.
|
||||
static inline void set_pwm(uint16_t val) {
|
||||
OCRxx = val;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
#else
|
||||
// Turn off PWM control on backlight pin
|
||||
disable_pwm();
|
||||
#endif
|
||||
backlight_pins_off();
|
||||
} else {
|
||||
#ifdef BACKLIGHT_PWM_TIMER
|
||||
if (!OCRxx) {
|
||||
TIMSKx |= _BV(OCIExA);
|
||||
TIMSKx |= _BV(TOIEx);
|
||||
}
|
||||
#else
|
||||
// Turn on PWM control of backlight pin
|
||||
enable_pwm();
|
||||
#endif
|
||||
}
|
||||
// Set the brightness
|
||||
set_pwm(cie_lightness(rescale_limit_val(ICRx * (uint32_t)level / BACKLIGHT_LEVELS)));
|
||||
}
|
||||
|
||||
void backlight_task(void) {}
|
||||
|
||||
#ifdef BACKLIGHT_BREATHING
|
||||
|
||||
# define BREATHING_NO_HALT 0
|
||||
# define BREATHING_HALT_OFF 1
|
||||
# define BREATHING_HALT_ON 2
|
||||
# define BREATHING_STEPS 128
|
||||
|
||||
static uint8_t breathing_halt = BREATHING_NO_HALT;
|
||||
static uint16_t breathing_counter = 0;
|
||||
|
||||
static uint8_t breath_scale_counter = 1;
|
||||
/* Run the breathing loop at ~120Hz*/
|
||||
const uint8_t breathing_ISR_frequency = 120;
|
||||
static uint16_t breathing_freq_scale_factor = 2;
|
||||
|
||||
# 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 = get_breathing_period() * breathing_ISR_frequency / 2; \
|
||||
} while (0)
|
||||
|
||||
void breathing_enable(void) {
|
||||
breathing_counter = 0;
|
||||
breathing_halt = BREATHING_NO_HALT;
|
||||
breathing_interrupt_enable();
|
||||
}
|
||||
|
||||
void breathing_pulse(void) {
|
||||
if (get_backlight_level() == 0)
|
||||
breathing_min();
|
||||
else
|
||||
breathing_max();
|
||||
breathing_halt = BREATHING_HALT_ON;
|
||||
breathing_interrupt_enable();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* To generate breathing curve in python:
|
||||
* from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
# ifdef BACKLIGHT_PWM_TIMER
|
||||
void breathing_task(void)
|
||||
# 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.
|
||||
*
|
||||
* The following ISR runs at F_CPU/ISRx. With a 16MHz clock and default pwm resolution, that means 244Hz
|
||||
*/
|
||||
ISR(TIMERx_OVF_vect)
|
||||
# endif
|
||||
{
|
||||
|
||||
// Only run this ISR at ~120 Hz
|
||||
if (breath_scale_counter++ == breathing_freq_scale_factor) {
|
||||
breath_scale_counter = 1;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
uint16_t interval = (uint16_t)get_breathing_period() * breathing_ISR_frequency / BREATHING_STEPS;
|
||||
// resetting after one period to prevent ugly reset at overflow.
|
||||
breathing_counter = (breathing_counter + 1) % (get_breathing_period() * breathing_ISR_frequency);
|
||||
uint8_t index = breathing_counter / interval;
|
||||
// limit index to max step value
|
||||
if (index >= BREATHING_STEPS) {
|
||||
index = BREATHING_STEPS - 1;
|
||||
}
|
||||
|
||||
if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) {
|
||||
breathing_interrupt_disable();
|
||||
}
|
||||
|
||||
// Set PWM to a brightnessvalue scaled to the configured resolution
|
||||
set_pwm(cie_lightness(rescale_limit_val(scale_backlight((uint32_t)pgm_read_byte(&breathing_table[index]) * ICRx / 255))));
|
||||
}
|
||||
|
||||
#endif // BACKLIGHT_BREATHING
|
||||
|
||||
void backlight_init_ports(void) {
|
||||
// Setup backlight pin as output and output to on state.
|
||||
backlight_pins_init();
|
||||
|
||||
// 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
|
||||
|
||||
#ifdef BACKLIGHT_CUSTOM_RESOLUTION
|
||||
# if (BACKLIGHT_CUSTOM_RESOLUTION > 0xFFFF || BACKLIGHT_CUSTOM_RESOLUTION < 1)
|
||||
# error "This out of range of the timer capabilities"
|
||||
# elif (BACKLIGHT_CUSTOM_RESOLUTION < 0xFF)
|
||||
# warning "Resolution lower than 0xFF isn't recommended"
|
||||
# endif
|
||||
# ifdef BACKLIGHT_BREATHING
|
||||
breathing_freq_scale_factor = F_CPU / BACKLIGHT_CUSTOM_RESOLUTION / 120;
|
||||
# endif
|
||||
ICRx = BACKLIGHT_CUSTOM_RESOLUTION;
|
||||
#else
|
||||
ICRx = TIMER_TOP;
|
||||
#endif
|
||||
|
||||
backlight_init();
|
||||
#ifdef BACKLIGHT_BREATHING
|
||||
if (is_backlight_breathing()) {
|
||||
breathing_enable();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
#include "quantum.h"
|
||||
#include "backlight.h"
|
||||
#include <hal.h>
|
||||
#include "debug.h"
|
||||
|
||||
// Maximum duty cycle limit
|
||||
#ifndef BACKLIGHT_LIMIT_VAL
|
||||
# define BACKLIGHT_LIMIT_VAL 255
|
||||
#endif
|
||||
|
||||
#ifndef BACKLIGHT_PAL_MODE
|
||||
# if defined(USE_GPIOV1)
|
||||
# define BACKLIGHT_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
|
||||
# else
|
||||
// GPIOV2 && GPIOV3
|
||||
# define BACKLIGHT_PAL_MODE 5
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// GENERIC
|
||||
#ifndef BACKLIGHT_PWM_DRIVER
|
||||
# define BACKLIGHT_PWM_DRIVER PWMD4
|
||||
#endif
|
||||
#ifndef BACKLIGHT_PWM_CHANNEL
|
||||
# define BACKLIGHT_PWM_CHANNEL 3
|
||||
#endif
|
||||
|
||||
// Support for pins which are on TIM1_CH1N - requires STM32_PWM_USE_ADVANCED
|
||||
#ifdef BACKLIGHT_PWM_COMPLEMENTARY_OUTPUT
|
||||
# if BACKLIGHT_ON_STATE == 1
|
||||
# define PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW;
|
||||
# else
|
||||
# define PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH;
|
||||
# endif
|
||||
#else
|
||||
# if BACKLIGHT_ON_STATE == 1
|
||||
# define PWM_OUTPUT_MODE PWM_OUTPUT_ACTIVE_HIGH;
|
||||
# else
|
||||
# define PWM_OUTPUT_MODE PWM_OUTPUT_ACTIVE_LOW;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef BACKLIGHT_PWM_COUNTER_FREQUENCY
|
||||
# define BACKLIGHT_PWM_COUNTER_FREQUENCY 0xFFFF
|
||||
#endif
|
||||
|
||||
#ifndef BACKLIGHT_PWM_PERIOD
|
||||
# define BACKLIGHT_PWM_PERIOD 256
|
||||
#endif
|
||||
|
||||
static PWMConfig pwmCFG = {
|
||||
.frequency = BACKLIGHT_PWM_COUNTER_FREQUENCY, /* PWM clock frequency */
|
||||
.period = BACKLIGHT_PWM_PERIOD, /* PWM period in counter ticks. e.g. clock frequency is 10KHz, period is 256 ticks then t_period is 25.6ms */
|
||||
};
|
||||
|
||||
#ifdef BACKLIGHT_BREATHING
|
||||
static virtual_timer_t breathing_vt;
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t rescale_limit_val(uint32_t val) {
|
||||
// rescale the supplied backlight value to be in terms of the value limit
|
||||
return (val * (BACKLIGHT_LIMIT_VAL + 1)) / 256;
|
||||
}
|
||||
|
||||
void backlight_init_ports(void) {
|
||||
#ifdef USE_GPIOV1
|
||||
palSetPadMode(PAL_PORT(BACKLIGHT_PIN), PAL_PAD(BACKLIGHT_PIN), BACKLIGHT_PAL_MODE);
|
||||
#else
|
||||
palSetPadMode(PAL_PORT(BACKLIGHT_PIN), PAL_PAD(BACKLIGHT_PIN), PAL_MODE_ALTERNATE(BACKLIGHT_PAL_MODE));
|
||||
#endif
|
||||
|
||||
pwmCFG.channels[BACKLIGHT_PWM_CHANNEL - 1].mode = PWM_OUTPUT_MODE;
|
||||
pwmStart(&BACKLIGHT_PWM_DRIVER, &pwmCFG);
|
||||
|
||||
backlight_set(get_backlight_level());
|
||||
|
||||
#ifdef BACKLIGHT_BREATHING
|
||||
chVTObjectInit(&breathing_vt);
|
||||
if (is_backlight_breathing()) {
|
||||
breathing_enable();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void backlight_set(uint8_t level) {
|
||||
if (level > BACKLIGHT_LEVELS) {
|
||||
level = BACKLIGHT_LEVELS;
|
||||
}
|
||||
|
||||
if (level == 0) {
|
||||
// Turn backlight off
|
||||
pwmDisableChannel(&BACKLIGHT_PWM_DRIVER, BACKLIGHT_PWM_CHANNEL - 1);
|
||||
} else {
|
||||
// Turn backlight on
|
||||
uint32_t duty = (uint32_t)(cie_lightness(rescale_limit_val(0xFFFF * (uint32_t)level / BACKLIGHT_LEVELS)));
|
||||
pwmEnableChannel(&BACKLIGHT_PWM_DRIVER, BACKLIGHT_PWM_CHANNEL - 1, PWM_FRACTION_TO_WIDTH(&BACKLIGHT_PWM_DRIVER, 0xFFFF, duty));
|
||||
}
|
||||
}
|
||||
|
||||
void backlight_task(void) {}
|
||||
|
||||
#ifdef BACKLIGHT_BREATHING
|
||||
|
||||
# define BREATHING_STEPS 128
|
||||
|
||||
/* To generate breathing curve in python:
|
||||
* from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
|
||||
*/
|
||||
static const uint8_t breathing_table[BREATHING_STEPS] = {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};
|
||||
|
||||
static void breathing_callback(virtual_timer_t *vtp, void *p);
|
||||
|
||||
bool is_breathing(void) {
|
||||
return chVTIsArmed(&breathing_vt);
|
||||
}
|
||||
|
||||
void breathing_enable(void) {
|
||||
/* Update frequency is 256Hz -> 3906us intervals */
|
||||
chVTSetContinuous(&breathing_vt, TIME_US2I(3906), breathing_callback, NULL);
|
||||
}
|
||||
|
||||
void breathing_disable(void) {
|
||||
chVTReset(&breathing_vt);
|
||||
|
||||
// Restore backlight level
|
||||
backlight_set(get_backlight_level());
|
||||
}
|
||||
|
||||
// Use this before the cie_lightness function.
|
||||
static inline uint16_t scale_backlight(uint16_t v) {
|
||||
return v / BACKLIGHT_LEVELS * get_backlight_level();
|
||||
}
|
||||
|
||||
static void breathing_callback(virtual_timer_t *vtp, void *p) {
|
||||
uint8_t breathing_period = get_breathing_period();
|
||||
uint16_t interval = (uint16_t)breathing_period * 256 / BREATHING_STEPS;
|
||||
|
||||
// resetting after one period to prevent ugly reset at overflow.
|
||||
static uint16_t breathing_counter = 0;
|
||||
breathing_counter = (breathing_counter + 1) % (breathing_period * 256);
|
||||
uint8_t index = breathing_counter / interval % BREATHING_STEPS;
|
||||
uint32_t duty = cie_lightness(rescale_limit_val(scale_backlight(breathing_table[index] * 256)));
|
||||
|
||||
chSysLockFromISR();
|
||||
pwmEnableChannelI(&BACKLIGHT_PWM_DRIVER, BACKLIGHT_PWM_CHANNEL - 1, PWM_FRACTION_TO_WIDTH(&BACKLIGHT_PWM_DRIVER, 0xFFFF, duty));
|
||||
chSysUnlockFromISR();
|
||||
}
|
||||
|
||||
// TODO: integrate generic pulse solution
|
||||
void breathing_pulse(void) {
|
||||
backlight_set(is_backlight_enabled() ? 0 : BACKLIGHT_LEVELS);
|
||||
wait_ms(10);
|
||||
backlight_set(is_backlight_enabled() ? get_backlight_level() : 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "quantum.h"
|
||||
#include "backlight.h"
|
||||
#include "backlight_driver_common.h"
|
||||
#include "gpio.h"
|
||||
#include "util.h"
|
||||
|
||||
#if !defined(BACKLIGHT_PIN) && !defined(BACKLIGHT_PINS)
|
||||
# error "Backlight pin/pins not defined. Please configure."
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#include "quantum.h"
|
||||
#include "backlight.h"
|
||||
#include "backlight_driver_common.h"
|
||||
|
||||
#ifdef BACKLIGHT_BREATHING
|
||||
# error "Backlight breathing is not available for software PWM. Please disable."
|
||||
#endif
|
||||
|
||||
static uint16_t s_duty_pattern = 0;
|
||||
|
||||
// clang-format off
|
||||
|
||||
/** \brief PWM duty patterns
|
||||
*
|
||||
* We scale the current backlight level to an index within this array. This allows
|
||||
* backlight_task to focus on just switching LEDs on/off, and we can predict the duty pattern
|
||||
*/
|
||||
static const uint16_t backlight_duty_table[] = {
|
||||
0b0000000000000000,
|
||||
0b1000000000000000,
|
||||
0b1000000010000000,
|
||||
0b1000001000010000,
|
||||
0b1000100010001000,
|
||||
0b1001001001001000,
|
||||
0b1010101010101010,
|
||||
0b1110111011101110,
|
||||
0b1111111111111111,
|
||||
};
|
||||
#define backlight_duty_table_size ARRAY_SIZE(backlight_duty_table)
|
||||
|
||||
// clang-format on
|
||||
|
||||
static uint8_t scale_backlight(uint8_t v) {
|
||||
return v * (backlight_duty_table_size - 1) / BACKLIGHT_LEVELS;
|
||||
}
|
||||
|
||||
void backlight_init_ports(void) {
|
||||
backlight_pins_init();
|
||||
}
|
||||
|
||||
void backlight_set(uint8_t level) {
|
||||
s_duty_pattern = backlight_duty_table[scale_backlight(level)];
|
||||
}
|
||||
|
||||
void backlight_task(void) {
|
||||
static uint8_t backlight_tick = 0;
|
||||
|
||||
if (s_duty_pattern & ((uint16_t)1 << backlight_tick)) {
|
||||
backlight_pins_on();
|
||||
} else {
|
||||
backlight_pins_off();
|
||||
}
|
||||
backlight_tick = (backlight_tick + 1) % 16;
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
#include "quantum.h"
|
||||
#include "backlight.h"
|
||||
#include "backlight_driver_common.h"
|
||||
#include "debug.h"
|
||||
|
||||
#ifndef BACKLIGHT_GPT_DRIVER
|
||||
# define BACKLIGHT_GPT_DRIVER GPTD15
|
||||
#endif
|
||||
|
||||
// Platform specific implementations
|
||||
static void backlight_timer_configure(bool enable);
|
||||
static void backlight_timer_set_duty(uint16_t duty);
|
||||
static uint16_t backlight_timer_get_duty(void);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
void backlight_init_ports(void) {
|
||||
backlight_pins_init();
|
||||
|
||||
backlight_set(get_backlight_level());
|
||||
|
||||
#ifdef BACKLIGHT_BREATHING
|
||||
if (is_backlight_breathing()) {
|
||||
breathing_enable();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void backlight_set(uint8_t level) {
|
||||
if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS;
|
||||
|
||||
backlight_pins_off();
|
||||
|
||||
backlight_timer_set_duty(cie_lightness(0xFFFFU / BACKLIGHT_LEVELS * level));
|
||||
backlight_timer_configure(level != 0);
|
||||
}
|
||||
|
||||
static void backlight_timer_top(void) {
|
||||
#ifdef BACKLIGHT_BREATHING
|
||||
if (is_breathing()) {
|
||||
breathing_task();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (backlight_timer_get_duty() > 256) {
|
||||
backlight_pins_on();
|
||||
}
|
||||
}
|
||||
|
||||
static void backlight_timer_cmp(void) {
|
||||
backlight_pins_off();
|
||||
}
|
||||
|
||||
void backlight_task(void) {}
|
||||
|
||||
#ifdef BACKLIGHT_BREATHING
|
||||
# define BREATHING_STEPS 128
|
||||
|
||||
static bool breathing = false;
|
||||
static uint16_t breathing_counter = 0;
|
||||
|
||||
/* To generate breathing curve in python:
|
||||
* from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
|
||||
*/
|
||||
static const uint8_t breathing_table[BREATHING_STEPS] = {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();
|
||||
}
|
||||
|
||||
void breathing_task(void) {
|
||||
uint8_t breathing_period = get_breathing_period();
|
||||
uint16_t interval = (uint16_t)breathing_period * 256 / BREATHING_STEPS;
|
||||
// resetting after one period to prevent ugly reset at overflow.
|
||||
breathing_counter = (breathing_counter + 1) % (breathing_period * 256);
|
||||
uint8_t index = breathing_counter / interval % BREATHING_STEPS;
|
||||
|
||||
// printf("index:%u\n", index);
|
||||
|
||||
backlight_timer_set_duty(cie_lightness(scale_backlight((uint16_t)breathing_table[index] * 256)));
|
||||
}
|
||||
|
||||
bool is_breathing(void) {
|
||||
return breathing;
|
||||
}
|
||||
|
||||
void breathing_enable(void) {
|
||||
breathing_counter = 0;
|
||||
breathing = true;
|
||||
}
|
||||
void breathing_disable(void) {
|
||||
breathing = false;
|
||||
}
|
||||
|
||||
void breathing_pulse(void) {
|
||||
backlight_set(is_backlight_enabled() ? 0 : BACKLIGHT_LEVELS);
|
||||
wait_ms(10);
|
||||
backlight_set(is_backlight_enabled() ? get_backlight_level() : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PROTOCOL_CHIBIOS
|
||||
// On Platforms where timers fire every tick and have no capture/top events
|
||||
// - fake event in the normal timer callback
|
||||
uint16_t s_duty = 0;
|
||||
|
||||
static void timerCallback(void) {
|
||||
/* Software PWM
|
||||
* timer:1111 1111 1111 1111
|
||||
* \______/| \_______/____ count(0-255)
|
||||
* \ \______________ unused(1)
|
||||
* \__________________ index of step table(0-127)
|
||||
*/
|
||||
|
||||
// this works for cca 65536 irqs/sec
|
||||
static union {
|
||||
uint16_t raw;
|
||||
struct {
|
||||
uint16_t count : 8;
|
||||
uint8_t dummy : 1;
|
||||
uint8_t index : 7;
|
||||
} pwm;
|
||||
} timer = {.raw = 0};
|
||||
|
||||
timer.raw++;
|
||||
|
||||
if (timer.pwm.count == 0) {
|
||||
// LED on
|
||||
backlight_timer_top();
|
||||
} else if (timer.pwm.count == (s_duty / 256)) {
|
||||
// LED off
|
||||
backlight_timer_cmp();
|
||||
}
|
||||
}
|
||||
|
||||
static void backlight_timer_set_duty(uint16_t duty) {
|
||||
s_duty = duty;
|
||||
}
|
||||
static uint16_t backlight_timer_get_duty(void) {
|
||||
return s_duty;
|
||||
}
|
||||
|
||||
// ChibiOS - Map GPT timer onto Software PWM
|
||||
static void gptTimerCallback(GPTDriver *gptp) {
|
||||
(void)gptp;
|
||||
timerCallback();
|
||||
}
|
||||
|
||||
static void backlight_timer_configure(bool enable) {
|
||||
static const GPTConfig gptcfg = {1000000, gptTimerCallback, 0, 0};
|
||||
|
||||
static bool s_init = false;
|
||||
if (!s_init) {
|
||||
gptStart(&BACKLIGHT_GPT_DRIVER, &gptcfg);
|
||||
s_init = true;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
gptStartContinuous(&BACKLIGHT_GPT_DRIVER, gptcfg.frequency / 0xFFFF);
|
||||
} else {
|
||||
gptStopTimer(&BACKLIGHT_GPT_DRIVER);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -13,7 +13,12 @@
|
||||
* 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 "quantum.h"
|
||||
#include "bootmagic.h"
|
||||
#include "matrix.h"
|
||||
#include "keyboard.h"
|
||||
#include "wait.h"
|
||||
#include "eeconfig.h"
|
||||
#include "bootloader.h"
|
||||
|
||||
/** \brief Reset eeprom
|
||||
*
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "matrix.h"
|
||||
|
||||
/**
|
||||
* @brief Debounce raw matrix events according to the choosen debounce algorithm.
|
||||
*
|
||||
|
||||
@@ -22,9 +22,8 @@ Basic symmetric per-key algorithm. Uses an 8-bit counter per key.
|
||||
When no state changes have occured for DEBOUNCE milliseconds, we push the state.
|
||||
*/
|
||||
|
||||
#include "matrix.h"
|
||||
#include "debounce.h"
|
||||
#include "timer.h"
|
||||
#include "quantum.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef PROTOCOL_CHIBIOS
|
||||
@@ -144,6 +143,8 @@ static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[],
|
||||
static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) {
|
||||
debounce_counter_t *debounce_pointer = debounce_counters;
|
||||
|
||||
matrix_need_update = false;
|
||||
|
||||
for (uint8_t row = 0; row < num_rows; row++) {
|
||||
matrix_row_t delta = raw[row] ^ cooked[row];
|
||||
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "matrix.h"
|
||||
#include "quantum.h"
|
||||
#include <stdlib.h>
|
||||
#include "debounce.h"
|
||||
#include <string.h>
|
||||
|
||||
void debounce_init(uint8_t num_rows) {}
|
||||
|
||||
@@ -17,9 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
Basic global debounce algorithm. Used in 99% of keyboards at time of implementation
|
||||
When no state changes have occured for DEBOUNCE milliseconds, we push the state.
|
||||
*/
|
||||
#include "matrix.h"
|
||||
#include "debounce.h"
|
||||
#include "timer.h"
|
||||
#include "quantum.h"
|
||||
#include <string.h>
|
||||
#ifndef DEBOUNCE
|
||||
# define DEBOUNCE 5
|
||||
|
||||
@@ -19,9 +19,8 @@ Basic symmetric per-key algorithm. Uses an 8-bit counter per key.
|
||||
When no state changes have occured for DEBOUNCE milliseconds, we push the state.
|
||||
*/
|
||||
|
||||
#include "matrix.h"
|
||||
#include "debounce.h"
|
||||
#include "timer.h"
|
||||
#include "quantum.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef PROTOCOL_CHIBIOS
|
||||
|
||||
@@ -17,9 +17,8 @@ Symmetric per-row debounce algorithm. Changes only apply when
|
||||
DEBOUNCE milliseconds have elapsed since the last change.
|
||||
*/
|
||||
|
||||
#include "matrix.h"
|
||||
#include "debounce.h"
|
||||
#include "timer.h"
|
||||
#include "quantum.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef DEBOUNCE
|
||||
|
||||
@@ -19,9 +19,8 @@ After pressing a key, it immediately changes state, and sets a counter.
|
||||
No further inputs are accepted until DEBOUNCE milliseconds have occurred.
|
||||
*/
|
||||
|
||||
#include "matrix.h"
|
||||
#include "debounce.h"
|
||||
#include "timer.h"
|
||||
#include "quantum.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef PROTOCOL_CHIBIOS
|
||||
@@ -125,6 +124,7 @@ static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) {
|
||||
|
||||
// upload from raw_matrix to final matrix;
|
||||
static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) {
|
||||
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];
|
||||
|
||||
@@ -19,9 +19,8 @@ After pressing a key, it immediately changes state, and sets a counter.
|
||||
No further inputs are accepted until DEBOUNCE milliseconds have occurred.
|
||||
*/
|
||||
|
||||
#include "matrix.h"
|
||||
#include "debounce.h"
|
||||
#include "timer.h"
|
||||
#include "quantum.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef PROTOCOL_CHIBIOS
|
||||
@@ -119,6 +118,7 @@ static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) {
|
||||
|
||||
// upload from raw_matrix to final matrix;
|
||||
static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) {
|
||||
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];
|
||||
|
||||
@@ -23,9 +23,8 @@
|
||||
#include <sstream>
|
||||
|
||||
extern "C" {
|
||||
#include "quantum.h"
|
||||
#include "timer.h"
|
||||
#include "debounce.h"
|
||||
#include "timer.h"
|
||||
|
||||
void set_time(uint32_t t);
|
||||
void advance_time(uint32_t ms);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <string>
|
||||
|
||||
extern "C" {
|
||||
#include "quantum.h"
|
||||
#include "matrix.h"
|
||||
#include "timer.h"
|
||||
}
|
||||
|
||||
|
||||
@@ -14,14 +14,16 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "keymap_introspection.h" // to get keymaps[][][]
|
||||
#include "eeprom.h"
|
||||
#include "progmem.h" // to read default from flash
|
||||
#include "quantum.h" // for send_string()
|
||||
#include "dynamic_keymap.h"
|
||||
#include "keymap_introspection.h"
|
||||
#include "action.h"
|
||||
#include "eeprom.h"
|
||||
#include "progmem.h"
|
||||
#include "send_string.h"
|
||||
#include "keycodes.h"
|
||||
|
||||
#ifdef VIA_ENABLE
|
||||
# include "via.h" // for VIA_EEPROM_CONFIG_END
|
||||
# include "via.h"
|
||||
# define DYNAMIC_KEYMAP_EEPROM_START (VIA_EEPROM_CONFIG_END)
|
||||
#else
|
||||
# define DYNAMIC_KEYMAP_EEPROM_START (EECONFIG_SIZE)
|
||||
@@ -152,22 +154,13 @@ void dynamic_keymap_reset(void) {
|
||||
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++) {
|
||||
if (layer < keymap_layer_count()) {
|
||||
dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column));
|
||||
} else {
|
||||
dynamic_keymap_set_keycode(layer, row, column, KC_TRANSPARENT);
|
||||
}
|
||||
dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column));
|
||||
}
|
||||
}
|
||||
#ifdef ENCODER_MAP_ENABLE
|
||||
for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) {
|
||||
if (layer < encodermap_layer_count()) {
|
||||
dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true));
|
||||
dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false));
|
||||
} else {
|
||||
dynamic_keymap_set_encoder(layer, encoder, true, KC_TRANSPARENT);
|
||||
dynamic_keymap_set_encoder(layer, encoder, false, KC_TRANSPARENT);
|
||||
}
|
||||
dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true));
|
||||
dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false));
|
||||
}
|
||||
#endif // ENCODER_MAP_ENABLE
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
*/
|
||||
|
||||
#include "encoder.h"
|
||||
#include "keyboard.h"
|
||||
#include "action.h"
|
||||
#include "keycodes.h"
|
||||
#include "wait.h"
|
||||
|
||||
#ifdef SPLIT_KEYBOARD
|
||||
# include "split_util.h"
|
||||
#endif
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "quantum.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "gpio.h"
|
||||
#include "util.h"
|
||||
|
||||
void encoder_init(void);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
extern "C" {
|
||||
#include "encoder.h"
|
||||
#include "keyboard.h"
|
||||
#include "encoder/tests/mock_split.h"
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "quantum.h"
|
||||
#include "keyboard.h"
|
||||
#include "keycode_config.h"
|
||||
#include "matrix.h"
|
||||
#include "keymap_introspection.h"
|
||||
#include "magic.h"
|
||||
@@ -33,6 +33,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "sendchar.h"
|
||||
#include "eeconfig.h"
|
||||
#include "action_layer.h"
|
||||
#ifdef AUDIO_ENABLE
|
||||
# include "audio.h"
|
||||
#endif
|
||||
#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
|
||||
# include "process_music.h"
|
||||
#endif
|
||||
#ifdef BACKLIGHT_ENABLE
|
||||
# include "backlight.h"
|
||||
#endif
|
||||
@@ -54,9 +60,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#ifdef ENCODER_ENABLE
|
||||
# include "encoder.h"
|
||||
#endif
|
||||
#ifdef HAPTIC_ENABLE
|
||||
# include "haptic.h"
|
||||
#endif
|
||||
#ifdef AUTO_SHIFT_ENABLE
|
||||
# include "process_auto_shift.h"
|
||||
#endif
|
||||
#ifdef COMBO_ENABLE
|
||||
# include "process_combo.h"
|
||||
#endif
|
||||
#ifdef TAP_DANCE_ENABLE
|
||||
# include "process_tap_dance.h"
|
||||
#endif
|
||||
#ifdef STENO_ENABLE
|
||||
# include "process_steno.h"
|
||||
#endif
|
||||
#ifdef KEY_OVERRIDE_ENABLE
|
||||
# include "process_key_override.h"
|
||||
#endif
|
||||
#ifdef SECURE_ENABLE
|
||||
# include "secure.h"
|
||||
#endif
|
||||
#ifdef POINTING_DEVICE_ENABLE
|
||||
# include "pointing_device.h"
|
||||
#endif
|
||||
@@ -64,7 +88,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# include "process_midi.h"
|
||||
#endif
|
||||
#ifdef JOYSTICK_ENABLE
|
||||
# include "process_joystick.h"
|
||||
# include "joystick.h"
|
||||
#endif
|
||||
#ifdef HD44780_ENABLE
|
||||
# include "hd44780.h"
|
||||
@@ -108,6 +132,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#ifdef LEADER_ENABLE
|
||||
# include "leader.h"
|
||||
#endif
|
||||
#ifdef UNICODE_COMMON_ENABLE
|
||||
# include "unicode.h"
|
||||
#endif
|
||||
#ifdef WPM_ENABLE
|
||||
# include "wpm.h"
|
||||
#endif
|
||||
|
||||
static uint32_t last_input_modification_time = 0;
|
||||
uint32_t last_input_activity_time(void) {
|
||||
|
||||
@@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -122,40 +122,36 @@ __attribute__((weak)) uint16_t keycode_config(uint16_t keycode) {
|
||||
*/
|
||||
|
||||
__attribute__((weak)) uint8_t mod_config(uint8_t mod) {
|
||||
/**
|
||||
* Note: This function is for the 5-bit packed mods, NOT the full 8-bit mods.
|
||||
* More info about the mods can be seen in modifiers.h.
|
||||
*/
|
||||
if (keymap_config.swap_lalt_lgui) {
|
||||
if ((mod & MOD_RGUI) == MOD_LGUI) {
|
||||
mod &= ~MOD_LGUI;
|
||||
mod |= MOD_LALT;
|
||||
} else if ((mod & MOD_RALT) == MOD_LALT) {
|
||||
mod &= ~MOD_LALT;
|
||||
mod |= MOD_LGUI;
|
||||
/** If both modifiers pressed or neither pressed, do nothing
|
||||
* Otherwise swap the values
|
||||
* Note: The left mods are ANDed with the right-hand values to check
|
||||
* if they were pressed with the right hand bit set
|
||||
*/
|
||||
if (((mod & MOD_RALT) == MOD_LALT) ^ ((mod & MOD_RGUI) == MOD_LGUI)) {
|
||||
mod ^= (MOD_LALT | MOD_LGUI);
|
||||
}
|
||||
}
|
||||
if (keymap_config.swap_ralt_rgui) {
|
||||
if ((mod & MOD_RGUI) == MOD_RGUI) {
|
||||
mod &= ~MOD_RGUI;
|
||||
mod |= MOD_RALT;
|
||||
} else if ((mod & MOD_RALT) == MOD_RALT) {
|
||||
mod &= ~MOD_RALT;
|
||||
mod |= MOD_RGUI;
|
||||
if (((mod & MOD_RALT) == MOD_RALT) ^ ((mod & MOD_RGUI) == MOD_RGUI)) {
|
||||
/* lefthand values to preserve the right hand bit */
|
||||
mod ^= (MOD_LALT | MOD_LGUI);
|
||||
}
|
||||
}
|
||||
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;
|
||||
/* left mods ANDed with right-hand values to check for right hand bit */
|
||||
if (((mod & MOD_RCTL) == MOD_LCTL) ^ ((mod & MOD_RGUI) == MOD_LGUI)) {
|
||||
mod ^= (MOD_LCTL | 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_RCTL) == MOD_RCTL) ^ ((mod & MOD_RGUI) == MOD_RGUI)) {
|
||||
/* lefthand values to preserve the right hand bit */
|
||||
mod ^= (MOD_LCTL | MOD_LGUI);
|
||||
}
|
||||
}
|
||||
if (keymap_config.no_gui) {
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
Copyright 2012-2016 Jun Wako <wakojun@gmail.com>
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#pragma message("'keymap.h' should no longer be included!")
|
||||
@@ -22,7 +22,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "action_layer.h"
|
||||
#include "action.h"
|
||||
#include "debug.h"
|
||||
#include "quantum.h"
|
||||
#include "keycode_config.h"
|
||||
#include "quantum_keycodes.h"
|
||||
|
||||
#ifdef ENCODER_MAP_ENABLE
|
||||
# include "encoder.h"
|
||||
#endif
|
||||
|
||||
#ifdef BACKLIGHT_ENABLE
|
||||
# include "backlight.h"
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_belgian.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_bepo.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_brazilian_abnt2.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_canadian_multilingual.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_colemak.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_croatian.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_czech.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_danish.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_dvorak.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_dvorak_fr.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_dvorak_programmer.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_estonian.h"
|
||||
#include "quantum"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_finnish.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_french.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_french_afnor.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_french_mac_iso.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_german.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_german_mac_iso.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_hungarian.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_icelandic.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_italian.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_italian_mac_ansi.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_italian_mac_iso.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_japanese.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_latvian.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_lithuanian_azerty.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_lithuanian_qwerty.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_norman.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_norwegian.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_portuguese.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_portuguese_mac_iso.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_romanian.h"
|
||||
#include "quantum"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_serbian_latin.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_slovak.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_slovenian.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_spanish.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_spanish_dvorak.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_swedish.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_swiss_de.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_swiss_fr.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_turkish_f.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_turkish_q.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_uk.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_us_international.h"
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_workman.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "send_string.h"
|
||||
#include "keymap_workman_zxcvm.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
@@ -153,14 +153,14 @@ __attribute__((weak)) void led_set(uint8_t usb_led) {
|
||||
/** \brief Trigger behaviour on transition to suspend
|
||||
*/
|
||||
void led_suspend(void) {
|
||||
uint8_t leds_off = 0;
|
||||
led_t leds_off = {0};
|
||||
#ifdef BACKLIGHT_CAPS_LOCK
|
||||
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);
|
||||
leds_off.caps_lock = true;
|
||||
}
|
||||
#endif
|
||||
led_set(leds_off);
|
||||
led_set(leds_off.raw);
|
||||
}
|
||||
|
||||
/** \brief Trigger behaviour on transition from suspend
|
||||
|
||||
@@ -22,13 +22,6 @@ 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
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -20,8 +20,13 @@
|
||||
#include "led_matrix.h"
|
||||
#include "progmem.h"
|
||||
#include "eeprom.h"
|
||||
#include "eeconfig.h"
|
||||
#include "keyboard.h"
|
||||
#include "sync_timer.h"
|
||||
#include "debug.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include "led_tables.h"
|
||||
|
||||
#include <lib/lib8tion/lib8tion.h>
|
||||
@@ -366,7 +371,10 @@ void led_matrix_task(void) {
|
||||
case RENDERING:
|
||||
led_task_render(effect);
|
||||
if (effect) {
|
||||
led_matrix_indicators();
|
||||
// Only run the basic indicators in the last render iteration (default there are 5 iterations)
|
||||
if (led_effect_params.iter == LED_MATRIX_LED_PROCESS_MAX_ITERATIONS) {
|
||||
led_matrix_indicators();
|
||||
}
|
||||
led_matrix_indicators_advanced(&led_effect_params);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "led_matrix_types.h"
|
||||
#include "quantum.h"
|
||||
#include "keyboard.h"
|
||||
|
||||
#ifdef IS31FL3731
|
||||
# include "is31fl3731-simple.h"
|
||||
@@ -42,8 +42,9 @@
|
||||
#endif
|
||||
|
||||
#ifndef LED_MATRIX_LED_PROCESS_LIMIT
|
||||
# define LED_MATRIX_LED_PROCESS_LIMIT (LED_MATRIX_LED_COUNT + 4) / 5
|
||||
# define LED_MATRIX_LED_PROCESS_LIMIT ((LED_MATRIX_LED_COUNT + 4) / 5)
|
||||
#endif
|
||||
#define LED_MATRIX_LED_PROCESS_MAX_ITERATIONS ((LED_MATRIX_LED_COUNT + LED_MATRIX_LED_PROCESS_LIMIT - 1) / LED_MATRIX_LED_PROCESS_LIMIT)
|
||||
|
||||
#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < LED_MATRIX_LED_COUNT
|
||||
# if defined(LED_MATRIX_SPLIT)
|
||||
|
||||
@@ -20,7 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "util.h"
|
||||
#include "matrix.h"
|
||||
#include "debounce.h"
|
||||
#include "quantum.h"
|
||||
#include "atomic_util.h"
|
||||
|
||||
#ifdef SPLIT_KEYBOARD
|
||||
# include "split_common/split_util.h"
|
||||
# include "split_common/transactions.h"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "quantum.h"
|
||||
#include "matrix.h"
|
||||
#include "debounce.h"
|
||||
#include "wait.h"
|
||||
#include "print.h"
|
||||
#include "debug.h"
|
||||
|
||||
#ifdef SPLIT_KEYBOARD
|
||||
# include "split_common/split_util.h"
|
||||
# include "split_common/transactions.h"
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
#include "usb_descriptor.h"
|
||||
#include "process_midi.h"
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
# include "audio.h"
|
||||
# include <math.h>
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* MIDI
|
||||
******************************************************************************/
|
||||
|
||||
@@ -25,11 +25,16 @@
|
||||
#include "mousekey.h"
|
||||
|
||||
static 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 (0.70703125) is used as an approximation for 1/sqrt(2)
|
||||
// because it is close to the exact value which is 0.707106781
|
||||
const int16_t n = x * 181;
|
||||
const uint16_t d = 256;
|
||||
|
||||
// To ensure that the integer result is rounded accurately after
|
||||
// division, check the sign of the numerator:
|
||||
// If negative, subtract half of the denominator before dividing
|
||||
// Otherwise, add half of the denominator before dividing
|
||||
return n < 0 ? (n - d / 2) / d : (n + d / 2) / d;
|
||||
}
|
||||
|
||||
static report_mouse_t mouse_report = {0};
|
||||
@@ -74,7 +79,7 @@ uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
|
||||
uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10;
|
||||
/* milliseconds between repeated motion events (0-255) */
|
||||
# ifdef MK_KINETIC_SPEED
|
||||
float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
|
||||
uint16_t mk_wheel_interval = 1000U / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
|
||||
# else
|
||||
uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL;
|
||||
# endif
|
||||
@@ -175,7 +180,7 @@ static uint8_t wheel_unit(void) {
|
||||
/*
|
||||
* Kinetic movement acceleration algorithm
|
||||
*
|
||||
* current speed = I + A * T/50 + A * 0.5 * T^2 | maximum B
|
||||
* current speed = I + A * T/50 + A * (T/50)^2 * 1/2 | maximum B
|
||||
*
|
||||
* T: time since the mouse movement started
|
||||
* E: mouse events per second (set through MOUSEKEY_INTERVAL, UHK sends 250, the
|
||||
@@ -190,39 +195,48 @@ const uint16_t mk_decelerated_speed = MOUSEKEY_DECELERATED_SPEED;
|
||||
const uint16_t mk_initial_speed = MOUSEKEY_INITIAL_SPEED;
|
||||
|
||||
static uint8_t move_unit(void) {
|
||||
float speed = mk_initial_speed;
|
||||
uint16_t speed = mk_initial_speed;
|
||||
|
||||
if (mousekey_accel & ((1 << 0) | (1 << 2))) {
|
||||
speed = mousekey_accel & (1 << 2) ? mk_accelerated_speed : mk_decelerated_speed;
|
||||
if (mousekey_accel & (1 << 0)) {
|
||||
speed = mk_decelerated_speed;
|
||||
} else if (mousekey_accel & (1 << 2)) {
|
||||
speed = mk_accelerated_speed;
|
||||
} else if (mousekey_repeat && mouse_timer) {
|
||||
const float time_elapsed = timer_elapsed(mouse_timer) / 50;
|
||||
speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed;
|
||||
|
||||
speed = speed > mk_base_speed ? mk_base_speed : speed;
|
||||
const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50;
|
||||
speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + (MOUSEKEY_MOVE_DELTA * time_elapsed * time_elapsed) / 2;
|
||||
if (speed > mk_base_speed) {
|
||||
speed = mk_base_speed;
|
||||
}
|
||||
}
|
||||
|
||||
/* convert speed to USB mouse speed 1 to 127 */
|
||||
speed = (uint8_t)(speed / (1000.0f / mk_interval));
|
||||
speed = speed < 1 ? 1 : speed;
|
||||
speed = (uint8_t)(speed / (1000U / mk_interval));
|
||||
|
||||
return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed;
|
||||
if (speed > MOUSEKEY_MOVE_MAX) {
|
||||
speed = MOUSEKEY_MOVE_MAX;
|
||||
} else if (speed < 1) {
|
||||
speed = 1;
|
||||
}
|
||||
return speed;
|
||||
}
|
||||
|
||||
static uint8_t wheel_unit(void) {
|
||||
float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
|
||||
uint16_t speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
|
||||
|
||||
if (mousekey_accel & ((1 << 0) | (1 << 2))) {
|
||||
speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS;
|
||||
if (mousekey_accel & (1 << 0)) {
|
||||
speed = MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS;
|
||||
} else if (mousekey_accel & (1 << 2)) {
|
||||
speed = MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS;
|
||||
} else if (mousekey_wheel_repeat && mouse_timer) {
|
||||
if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
|
||||
const float time_elapsed = timer_elapsed(mouse_timer) / 50;
|
||||
speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed;
|
||||
const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50;
|
||||
speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + (1 * time_elapsed * time_elapsed) / 2;
|
||||
}
|
||||
if (speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
|
||||
speed = MOUSEKEY_WHEEL_BASE_MOVEMENTS;
|
||||
}
|
||||
speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed;
|
||||
}
|
||||
mk_wheel_interval = 1000.0f / speed;
|
||||
|
||||
return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1;
|
||||
mk_wheel_interval = 1000U / speed;
|
||||
return 1;
|
||||
}
|
||||
|
||||
# endif /* #ifndef MK_KINETIC_SPEED */
|
||||
|
||||
@@ -44,9 +44,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# define MOUSEKEY_MOVE_DELTA 8
|
||||
# endif
|
||||
# endif
|
||||
# ifndef MOUSEKEY_WHEEL_DELTA
|
||||
# define MOUSEKEY_WHEEL_DELTA 1
|
||||
# endif
|
||||
# ifndef MOUSEKEY_DELAY
|
||||
# if defined(MK_KINETIC_SPEED)
|
||||
# define MOUSEKEY_DELAY 5
|
||||
@@ -85,6 +82,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ifndef MOUSEKEY_WHEEL_INTERVAL
|
||||
# define MOUSEKEY_WHEEL_INTERVAL 80
|
||||
# endif
|
||||
# ifndef MOUSEKEY_WHEEL_DELTA
|
||||
# define MOUSEKEY_WHEEL_DELTA 1
|
||||
# endif
|
||||
# ifndef MOUSEKEY_WHEEL_MAX_SPEED
|
||||
# define MOUSEKEY_WHEEL_MAX_SPEED 8
|
||||
# endif
|
||||
|
||||
@@ -61,7 +61,7 @@ bool qp_lvgl_attach(painter_device_t device) {
|
||||
qp_lvgl_detach();
|
||||
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_lvgl_attach: fail (validation_ok == false)\n");
|
||||
qp_lvgl_detach();
|
||||
return false;
|
||||
|
||||
@@ -30,6 +30,11 @@ bool qp_init(painter_device_t device, painter_rotation_t rotation) {
|
||||
qp_dprintf("qp_init: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
|
||||
if (!driver) {
|
||||
qp_dprintf("qp_init: fail (pointer to NULL)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
driver->validate_ok = false;
|
||||
if (!validate_driver_integrity(driver)) {
|
||||
qp_dprintf("Failed to validate driver integrity in qp_init\n");
|
||||
@@ -65,7 +70,7 @@ bool qp_init(painter_device_t device, painter_rotation_t rotation) {
|
||||
bool qp_power(painter_device_t device, bool power_on) {
|
||||
qp_dprintf("qp_power: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_power: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -87,7 +92,7 @@ bool qp_power(painter_device_t device, bool power_on) {
|
||||
bool qp_clear(painter_device_t device) {
|
||||
qp_dprintf("qp_clear: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_clear: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -109,7 +114,7 @@ bool qp_clear(painter_device_t device) {
|
||||
bool qp_flush(painter_device_t device) {
|
||||
qp_dprintf("qp_flush: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_flush: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -129,9 +134,14 @@ bool qp_flush(painter_device_t device) {
|
||||
// Quantum Painter External API: qp_get_geometry
|
||||
|
||||
void qp_get_geometry(painter_device_t device, uint16_t *width, uint16_t *height, painter_rotation_t *rotation, uint16_t *offset_x, uint16_t *offset_y) {
|
||||
qp_dprintf("qp_geometry: entry\n");
|
||||
qp_dprintf("qp_get_geometry: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
|
||||
if (!driver) {
|
||||
qp_dprintf("qp_get_geometry: fail (pointer to NULL)\n");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (driver->rotation) {
|
||||
default:
|
||||
case QP_ROTATION_0:
|
||||
@@ -166,7 +176,7 @@ void qp_get_geometry(painter_device_t device, uint16_t *width, uint16_t *height,
|
||||
*offset_y = driver->offset_y;
|
||||
}
|
||||
|
||||
qp_dprintf("qp_geometry: ok\n");
|
||||
qp_dprintf("qp_get_geometry: ok\n");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -176,6 +186,11 @@ void qp_set_viewport_offsets(painter_device_t device, uint16_t offset_x, uint16_
|
||||
qp_dprintf("qp_set_viewport_offsets: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
|
||||
if (!driver) {
|
||||
qp_dprintf("qp_set_viewport_offsets: fail (pointer to NULL)\n");
|
||||
return;
|
||||
}
|
||||
|
||||
driver->offset_x = offset_x;
|
||||
driver->offset_y = offset_y;
|
||||
|
||||
@@ -188,7 +203,7 @@ void qp_set_viewport_offsets(painter_device_t device, uint16_t offset_x, uint16_
|
||||
bool qp_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) {
|
||||
qp_dprintf("qp_viewport: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_viewport: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -211,7 +226,7 @@ bool qp_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t
|
||||
bool qp_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) {
|
||||
qp_dprintf("qp_pixdata: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_pixdata: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
bool qp_comms_init(painter_device_t device) {
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_comms_init: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ bool qp_comms_init(painter_device_t device) {
|
||||
|
||||
bool qp_comms_start(painter_device_t device) {
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_comms_start: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -28,7 +28,7 @@ bool qp_comms_start(painter_device_t device) {
|
||||
|
||||
void qp_comms_stop(painter_device_t device) {
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_comms_stop: fail (validation_ok == false)\n");
|
||||
return;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ void qp_comms_stop(painter_device_t device) {
|
||||
|
||||
uint32_t qp_comms_send(painter_device_t device, const void *data, uint32_t byte_count) {
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_comms_send: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ static bool qp_circle_helper_impl(painter_device_t device, uint16_t centerx, uin
|
||||
bool qp_circle(painter_device_t device, uint16_t x, uint16_t y, uint16_t radius, uint8_t hue, uint8_t sat, uint8_t val, bool filled) {
|
||||
qp_dprintf("qp_circle: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_circle: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ bool qp_internal_load_qgf_palette(qp_stream_t *stream, uint8_t bpp) {
|
||||
|
||||
bool qp_setpixel(painter_device_t device, uint16_t x, uint16_t y, uint8_t hue, uint8_t sat, uint8_t val) {
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_setpixel: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -175,7 +175,7 @@ bool qp_line(painter_device_t device, uint16_t x0, uint16_t y0, uint16_t x1, uin
|
||||
|
||||
qp_dprintf("qp_line(%d, %d, %d, %d): entry\n", (int)x0, (int)y0, (int)x1, (int)y1);
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_line: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -253,7 +253,7 @@ bool qp_internal_fillrect_helper_impl(painter_device_t device, uint16_t left, ui
|
||||
bool qp_rect(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint8_t hue, uint8_t sat, uint8_t val, bool filled) {
|
||||
qp_dprintf("qp_rect(%d, %d, %d, %d): entry\n", (int)left, (int)top, (int)right, (int)bottom);
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_rect: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ static bool qp_ellipse_helper_impl(painter_device_t device, uint16_t centerx, ui
|
||||
bool qp_ellipse(painter_device_t device, uint16_t x, uint16_t y, uint16_t sizex, uint16_t sizey, uint8_t hue, uint8_t sat, uint8_t val, bool filled) {
|
||||
qp_dprintf("qp_ellipse: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_ellipse: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) {
|
||||
|
||||
bool qp_close_image(painter_image_handle_t image) {
|
||||
qgf_image_handle_t *qgf_image = (qgf_image_handle_t *)image;
|
||||
if (!qgf_image->validate_ok) {
|
||||
if (!qgf_image || !qgf_image->validate_ok) {
|
||||
qp_dprintf("qp_close_image: fail (invalid image)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -210,13 +210,13 @@ static bool qp_drawimage_prepare_frame_for_stream_read(painter_device_t device,
|
||||
static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint16_t y, painter_image_handle_t image, int frame_number, qgf_frame_info_t *frame_info, qp_pixel_t fg_hsv888, qp_pixel_t bg_hsv888) {
|
||||
qp_dprintf("qp_drawimage_recolor: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_drawimage_recolor: fail (validation_ok == false)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
qgf_image_handle_t *qgf_image = (qgf_image_handle_t *)image;
|
||||
if (!qgf_image->validate_ok) {
|
||||
if (!qgf_image || !qgf_image->validate_ok) {
|
||||
qp_dprintf("qp_drawimage_recolor: fail (invalid image)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) {
|
||||
|
||||
bool qp_close_font(painter_font_handle_t font) {
|
||||
qff_font_handle_t *qff_font = (qff_font_handle_t *)font;
|
||||
if (!qff_font->validate_ok) {
|
||||
if (!qff_font || !qff_font->validate_ok) {
|
||||
qp_dprintf("qp_close_font: fail (invalid font)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -380,7 +380,7 @@ static inline bool qp_font_code_point_handler_drawglyph(qff_font_handle_t *qff_f
|
||||
|
||||
int16_t qp_textwidth(painter_font_handle_t font, const char *str) {
|
||||
qff_font_handle_t *qff_font = (qff_font_handle_t *)font;
|
||||
if (!qff_font->validate_ok) {
|
||||
if (!qff_font || !qff_font->validate_ok) {
|
||||
qp_dprintf("qp_textwidth: fail (invalid font)\n");
|
||||
return false;
|
||||
}
|
||||
@@ -406,13 +406,13 @@ int16_t qp_drawtext(painter_device_t device, uint16_t x, uint16_t y, painter_fon
|
||||
int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, painter_font_handle_t font, const char *str, uint8_t hue_fg, uint8_t sat_fg, uint8_t val_fg, uint8_t hue_bg, uint8_t sat_bg, uint8_t val_bg) {
|
||||
qp_dprintf("qp_drawtext_recolor: entry\n");
|
||||
painter_driver_t *driver = (painter_driver_t *)device;
|
||||
if (!driver->validate_ok) {
|
||||
if (!driver || !driver->validate_ok) {
|
||||
qp_dprintf("qp_drawtext_recolor: fail (validation_ok == false)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
qff_font_handle_t *qff_font = (qff_font_handle_t *)font;
|
||||
if (!qff_font->validate_ok) {
|
||||
if (!qff_font || !qff_font->validate_ok) {
|
||||
qp_dprintf("qp_drawtext_recolor: fail (invalid font)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
|
||||
|
||||
# include "pointing_device_auto_mouse.h"
|
||||
# include "debug.h"
|
||||
# include "action_util.h"
|
||||
# include "quantum_keycodes.h"
|
||||
|
||||
/* local data structure for tracking auto mouse */
|
||||
static auto_mouse_context_t auto_mouse_context = {
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "quantum.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "pointing_device.h"
|
||||
#include "print.h"
|
||||
#include "keycodes.h"
|
||||
#include "action.h"
|
||||
#include "report.h"
|
||||
#include "action_layer.h"
|
||||
#include "action_tapping.h"
|
||||
|
||||
/* check settings and set defaults */
|
||||
#ifndef POINTING_DEVICE_AUTO_MOUSE_ENABLE
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user