diff options
| -rw-r--r-- | common_features.mk | 8 | ||||
| -rw-r--r-- | quantum/backlight/backlight.c | 21 | ||||
| -rw-r--r-- | quantum/backlight/backlight.h | 23 | ||||
| -rw-r--r-- | quantum/backlight/backlight_arm.c | 25 | ||||
| -rw-r--r-- | quantum/backlight/backlight_avr.c | 35 | ||||
| -rw-r--r-- | quantum/quantum.h | 24 |
6 files changed, 55 insertions, 81 deletions
diff --git a/common_features.mk b/common_features.mk index 67c64b425..01ceb8278 100644 --- a/common_features.mk +++ b/common_features.mk | |||
| @@ -257,13 +257,11 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) | |||
| 257 | SRC += $(QUANTUM_DIR)/backlight/backlight.c | 257 | SRC += $(QUANTUM_DIR)/backlight/backlight.c |
| 258 | OPT_DEFS += -DBACKLIGHT_ENABLE | 258 | OPT_DEFS += -DBACKLIGHT_ENABLE |
| 259 | 259 | ||
| 260 | ifeq ($(strip $(BACKLIGHT_DRIVER)), software) | 260 | ifeq ($(strip $(BACKLIGHT_DRIVER)), custom) |
| 261 | OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER | ||
| 262 | else ifeq ($(strip $(BACKLIGHT_DRIVER)), software) | ||
| 261 | SRC += $(QUANTUM_DIR)/backlight/backlight_soft.c | 263 | SRC += $(QUANTUM_DIR)/backlight/backlight_soft.c |
| 262 | else | 264 | else |
| 263 | ifeq ($(strip $(BACKLIGHT_DRIVER)), custom) | ||
| 264 | OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER | ||
| 265 | endif | ||
| 266 | |||
| 267 | ifeq ($(PLATFORM),AVR) | 265 | ifeq ($(PLATFORM),AVR) |
| 268 | SRC += $(QUANTUM_DIR)/backlight/backlight_avr.c | 266 | SRC += $(QUANTUM_DIR)/backlight/backlight_avr.c |
| 269 | else | 267 | else |
diff --git a/quantum/backlight/backlight.c b/quantum/backlight/backlight.c index 708022f68..e57b31d10 100644 --- a/quantum/backlight/backlight.c +++ b/quantum/backlight/backlight.c | |||
| @@ -21,6 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 21 | 21 | ||
| 22 | backlight_config_t backlight_config; | 22 | backlight_config_t backlight_config; |
| 23 | 23 | ||
| 24 | // TODO: migrate to backlight_config_t | ||
| 25 | static uint8_t breathing_period = BREATHING_PERIOD; | ||
| 26 | |||
| 24 | /** \brief Backlight initialization | 27 | /** \brief Backlight initialization |
| 25 | * | 28 | * |
| 26 | * FIXME: needs doc | 29 | * FIXME: needs doc |
| @@ -191,3 +194,21 @@ void backlight_disable_breathing(void) { | |||
| 191 | */ | 194 | */ |
| 192 | bool is_backlight_breathing(void) { return backlight_config.breathing; } | 195 | bool is_backlight_breathing(void) { return backlight_config.breathing; } |
| 193 | #endif | 196 | #endif |
| 197 | |||
| 198 | // following are marked as weak purely for backwards compatibility | ||
| 199 | __attribute__((weak)) void breathing_period_set(uint8_t value) { breathing_period = value ? value : 1; } | ||
| 200 | |||
| 201 | __attribute__((weak)) uint8_t get_breathing_period(void) { return breathing_period; } | ||
| 202 | |||
| 203 | __attribute__((weak)) void breathing_period_default(void) { breathing_period_set(BREATHING_PERIOD); } | ||
| 204 | |||
| 205 | __attribute__((weak)) void breathing_period_inc(void) { breathing_period_set(breathing_period + 1); } | ||
| 206 | |||
| 207 | __attribute__((weak)) void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); } | ||
| 208 | |||
| 209 | // defaults for backlight api | ||
| 210 | __attribute__((weak)) void backlight_init_ports(void) {} | ||
| 211 | |||
| 212 | __attribute__((weak)) void backlight_set(uint8_t level) {} | ||
| 213 | |||
| 214 | __attribute__((weak)) void backlight_task(void) {} | ||
diff --git a/quantum/backlight/backlight.h b/quantum/backlight/backlight.h index 1e581055d..9f0a5e81d 100644 --- a/quantum/backlight/backlight.h +++ b/quantum/backlight/backlight.h | |||
| @@ -41,22 +41,39 @@ typedef union { | |||
| 41 | } backlight_config_t; | 41 | } backlight_config_t; |
| 42 | 42 | ||
| 43 | void backlight_init(void); | 43 | void backlight_init(void); |
| 44 | void backlight_increase(void); | ||
| 45 | void backlight_decrease(void); | ||
| 46 | void backlight_toggle(void); | 44 | void backlight_toggle(void); |
| 47 | void backlight_enable(void); | 45 | void backlight_enable(void); |
| 48 | void backlight_disable(void); | 46 | void backlight_disable(void); |
| 49 | bool is_backlight_enabled(void); | 47 | bool is_backlight_enabled(void); |
| 50 | void backlight_step(void); | 48 | void backlight_step(void); |
| 51 | void backlight_set(uint8_t level); | 49 | void backlight_increase(void); |
| 50 | void backlight_decrease(void); | ||
| 52 | void backlight_level(uint8_t level); | 51 | void backlight_level(uint8_t level); |
| 53 | uint8_t get_backlight_level(void); | 52 | uint8_t get_backlight_level(void); |
| 54 | 53 | ||
| 54 | // implementation specific | ||
| 55 | void backlight_init_ports(void); | ||
| 56 | void backlight_set(uint8_t level); | ||
| 57 | void backlight_task(void); | ||
| 58 | |||
| 55 | #ifdef BACKLIGHT_BREATHING | 59 | #ifdef BACKLIGHT_BREATHING |
| 60 | |||
| 56 | void backlight_toggle_breathing(void); | 61 | void backlight_toggle_breathing(void); |
| 57 | void backlight_enable_breathing(void); | 62 | void backlight_enable_breathing(void); |
| 58 | void backlight_disable_breathing(void); | 63 | void backlight_disable_breathing(void); |
| 59 | bool is_backlight_breathing(void); | 64 | bool is_backlight_breathing(void); |
| 65 | |||
| 66 | void breathing_period_set(uint8_t value); | ||
| 67 | uint8_t get_breathing_period(void); | ||
| 68 | void breathing_period_default(void); | ||
| 69 | void breathing_period_inc(void); | ||
| 70 | void breathing_period_dec(void); | ||
| 71 | |||
| 72 | // implementation specific | ||
| 60 | void breathing_enable(void); | 73 | void breathing_enable(void); |
| 61 | void breathing_disable(void); | 74 | void breathing_disable(void); |
| 75 | void breathing_toggle(void); | ||
| 76 | bool is_breathing(void); | ||
| 77 | void breathing_pulse(void); | ||
| 78 | void breathing_task(void); | ||
| 62 | #endif | 79 | #endif |
diff --git a/quantum/backlight/backlight_arm.c b/quantum/backlight/backlight_arm.c index 8c6909a4a..f7065906f 100644 --- a/quantum/backlight/backlight_arm.c +++ b/quantum/backlight/backlight_arm.c | |||
| @@ -106,7 +106,6 @@ void backlight_task(void) {} | |||
| 106 | # define BREATHING_HALT_ON 2 | 106 | # define BREATHING_HALT_ON 2 |
| 107 | # define BREATHING_STEPS 128 | 107 | # define BREATHING_STEPS 128 |
| 108 | 108 | ||
| 109 | static uint8_t breathing_period = BREATHING_PERIOD; | ||
| 110 | static uint8_t breathing_halt = BREATHING_NO_HALT; | 109 | static uint8_t breathing_halt = BREATHING_NO_HALT; |
| 111 | static uint16_t breathing_counter = 0; | 110 | static uint16_t breathing_counter = 0; |
| 112 | 111 | ||
| @@ -114,7 +113,7 @@ bool is_breathing(void) { return BACKLIGHT_PWM_DRIVER.config == &pwmCFG_breathin | |||
| 114 | 113 | ||
| 115 | static inline void breathing_min(void) { breathing_counter = 0; } | 114 | static inline void breathing_min(void) { breathing_counter = 0; } |
| 116 | 115 | ||
| 117 | static inline void breathing_max(void) { breathing_counter = breathing_period * 256 / 2; } | 116 | static inline void breathing_max(void) { breathing_counter = get_breathing_period() * 256 / 2; } |
| 118 | 117 | ||
| 119 | void breathing_interrupt_enable(void) { | 118 | void breathing_interrupt_enable(void) { |
| 120 | pwmStop(&BACKLIGHT_PWM_DRIVER); | 119 | pwmStop(&BACKLIGHT_PWM_DRIVER); |
| @@ -166,17 +165,6 @@ void breathing_toggle(void) { | |||
| 166 | breathing_enable(); | 165 | breathing_enable(); |
| 167 | } | 166 | } |
| 168 | 167 | ||
| 169 | void breathing_period_set(uint8_t value) { | ||
| 170 | if (!value) value = 1; | ||
| 171 | breathing_period = value; | ||
| 172 | } | ||
| 173 | |||
| 174 | void breathing_period_default(void) { breathing_period_set(BREATHING_PERIOD); } | ||
| 175 | |||
| 176 | void breathing_period_inc(void) { breathing_period_set(breathing_period + 1); } | ||
| 177 | |||
| 178 | void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); } | ||
| 179 | |||
| 180 | /* To generate breathing curve in python: | 168 | /* To generate breathing curve in python: |
| 181 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] | 169 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] |
| 182 | */ | 170 | */ |
| @@ -187,7 +175,8 @@ static inline uint16_t scale_backlight(uint16_t v) { return v / BACKLIGHT_LEVELS | |||
| 187 | 175 | ||
| 188 | static void breathing_callback(PWMDriver *pwmp) { | 176 | static void breathing_callback(PWMDriver *pwmp) { |
| 189 | (void)pwmp; | 177 | (void)pwmp; |
| 190 | uint16_t interval = (uint16_t)breathing_period * 256 / BREATHING_STEPS; | 178 | uint8_t breathing_period = get_breathing_period(); |
| 179 | uint16_t interval = (uint16_t)breathing_period * 256 / BREATHING_STEPS; | ||
| 191 | // resetting after one period to prevent ugly reset at overflow. | 180 | // resetting after one period to prevent ugly reset at overflow. |
| 192 | breathing_counter = (breathing_counter + 1) % (breathing_period * 256); | 181 | breathing_counter = (breathing_counter + 1) % (breathing_period * 256); |
| 193 | uint8_t index = breathing_counter / interval % BREATHING_STEPS; | 182 | uint8_t index = breathing_counter / interval % BREATHING_STEPS; |
| @@ -203,12 +192,4 @@ static void breathing_callback(PWMDriver *pwmp) { | |||
| 203 | chSysUnlockFromISR(); | 192 | chSysUnlockFromISR(); |
| 204 | } | 193 | } |
| 205 | 194 | ||
| 206 | #else | ||
| 207 | |||
| 208 | __attribute__((weak)) void backlight_init_ports(void) {} | ||
| 209 | |||
| 210 | __attribute__((weak)) void backlight_set(uint8_t level) {} | ||
| 211 | |||
| 212 | __attribute__((weak)) void backlight_task(void) {} | ||
| 213 | |||
| 214 | #endif | 195 | #endif |
diff --git a/quantum/backlight/backlight_avr.c b/quantum/backlight/backlight_avr.c index edda6ea0b..7cf1e0fb3 100644 --- a/quantum/backlight/backlight_avr.c +++ b/quantum/backlight/backlight_avr.c | |||
| @@ -206,7 +206,7 @@ static const pin_t backlight_pin = BACKLIGHT_PIN; | |||
| 206 | # endif | 206 | # endif |
| 207 | 207 | ||
| 208 | # ifdef NO_HARDWARE_PWM | 208 | # ifdef NO_HARDWARE_PWM |
| 209 | __attribute__((weak)) void backlight_init_ports(void) { | 209 | void backlight_init_ports(void) { |
| 210 | // Setup backlight pin as output and output to on state. | 210 | // Setup backlight pin as output and output to on state. |
| 211 | FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) | 211 | FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) |
| 212 | 212 | ||
| @@ -217,8 +217,6 @@ __attribute__((weak)) void backlight_init_ports(void) { | |||
| 217 | # endif | 217 | # endif |
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | __attribute__((weak)) void backlight_set(uint8_t level) {} | ||
| 221 | |||
| 222 | uint8_t backlight_tick = 0; | 220 | uint8_t backlight_tick = 0; |
| 223 | 221 | ||
| 224 | # ifndef BACKLIGHT_CUSTOM_DRIVER | 222 | # ifndef BACKLIGHT_CUSTOM_DRIVER |
| @@ -303,7 +301,7 @@ static uint16_t cie_lightness(uint16_t v) { | |||
| 303 | static inline void set_pwm(uint16_t val) { OCRxx = val; } | 301 | static inline void set_pwm(uint16_t val) { OCRxx = val; } |
| 304 | 302 | ||
| 305 | # ifndef BACKLIGHT_CUSTOM_DRIVER | 303 | # ifndef BACKLIGHT_CUSTOM_DRIVER |
| 306 | __attribute__((weak)) void backlight_set(uint8_t level) { | 304 | void backlight_set(uint8_t level) { |
| 307 | if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS; | 305 | if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS; |
| 308 | 306 | ||
| 309 | if (level == 0) { | 307 | if (level == 0) { |
| @@ -342,7 +340,6 @@ void backlight_task(void) {} | |||
| 342 | # define BREATHING_HALT_ON 2 | 340 | # define BREATHING_HALT_ON 2 |
| 343 | # define BREATHING_STEPS 128 | 341 | # define BREATHING_STEPS 128 |
| 344 | 342 | ||
| 345 | static uint8_t breathing_period = BREATHING_PERIOD; | ||
| 346 | static uint8_t breathing_halt = BREATHING_NO_HALT; | 343 | static uint8_t breathing_halt = BREATHING_NO_HALT; |
| 347 | static uint16_t breathing_counter = 0; | 344 | static uint16_t breathing_counter = 0; |
| 348 | 345 | ||
| @@ -377,9 +374,9 @@ bool is_breathing(void) { return !!(TIMSKx & _BV(TOIEx)); } | |||
| 377 | do { \ | 374 | do { \ |
| 378 | breathing_counter = 0; \ | 375 | breathing_counter = 0; \ |
| 379 | } while (0) | 376 | } while (0) |
| 380 | # define breathing_max() \ | 377 | # define breathing_max() \ |
| 381 | do { \ | 378 | do { \ |
| 382 | breathing_counter = breathing_period * 244 / 2; \ | 379 | breathing_counter = get_breathing_period() * 244 / 2; \ |
| 383 | } while (0) | 380 | } while (0) |
| 384 | 381 | ||
| 385 | void breathing_enable(void) { | 382 | void breathing_enable(void) { |
| @@ -417,17 +414,6 @@ void breathing_toggle(void) { | |||
| 417 | breathing_enable(); | 414 | breathing_enable(); |
| 418 | } | 415 | } |
| 419 | 416 | ||
| 420 | void breathing_period_set(uint8_t value) { | ||
| 421 | if (!value) value = 1; | ||
| 422 | breathing_period = value; | ||
| 423 | } | ||
| 424 | |||
| 425 | void breathing_period_default(void) { breathing_period_set(BREATHING_PERIOD); } | ||
| 426 | |||
| 427 | void breathing_period_inc(void) { breathing_period_set(breathing_period + 1); } | ||
| 428 | |||
| 429 | void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); } | ||
| 430 | |||
| 431 | /* To generate breathing curve in python: | 417 | /* To generate breathing curve in python: |
| 432 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] | 418 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] |
| 433 | */ | 419 | */ |
| @@ -445,6 +431,7 @@ void breathing_task(void) | |||
| 445 | ISR(TIMERx_OVF_vect) | 431 | ISR(TIMERx_OVF_vect) |
| 446 | # endif | 432 | # endif |
| 447 | { | 433 | { |
| 434 | uint8_t breathing_period = get_breathing_period(); | ||
| 448 | uint16_t interval = (uint16_t)breathing_period * 244 / BREATHING_STEPS; | 435 | uint16_t interval = (uint16_t)breathing_period * 244 / BREATHING_STEPS; |
| 449 | // resetting after one period to prevent ugly reset at overflow. | 436 | // resetting after one period to prevent ugly reset at overflow. |
| 450 | breathing_counter = (breathing_counter + 1) % (breathing_period * 244); | 437 | breathing_counter = (breathing_counter + 1) % (breathing_period * 244); |
| @@ -459,7 +446,7 @@ ISR(TIMERx_OVF_vect) | |||
| 459 | 446 | ||
| 460 | # endif // BACKLIGHT_BREATHING | 447 | # endif // BACKLIGHT_BREATHING |
| 461 | 448 | ||
| 462 | __attribute__((weak)) void backlight_init_ports(void) { | 449 | void backlight_init_ports(void) { |
| 463 | // Setup backlight pin as output and output to on state. | 450 | // Setup backlight pin as output and output to on state. |
| 464 | FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) | 451 | FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) |
| 465 | 452 | ||
| @@ -500,10 +487,4 @@ __attribute__((weak)) void backlight_init_ports(void) { | |||
| 500 | 487 | ||
| 501 | # endif // hardware backlight | 488 | # endif // hardware backlight |
| 502 | 489 | ||
| 503 | #else // no backlight | 490 | #endif // backlight |
| 504 | |||
| 505 | __attribute__((weak)) void backlight_init_ports(void) {} | ||
| 506 | |||
| 507 | __attribute__((weak)) void backlight_set(uint8_t level) {} | ||
| 508 | |||
| 509 | #endif // backlight \ No newline at end of file | ||
diff --git a/quantum/quantum.h b/quantum/quantum.h index 9758374f6..09550fec3 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
| @@ -251,30 +251,6 @@ void register_code16(uint16_t code); | |||
| 251 | void unregister_code16(uint16_t code); | 251 | void unregister_code16(uint16_t code); |
| 252 | void tap_code16(uint16_t code); | 252 | void tap_code16(uint16_t code); |
| 253 | 253 | ||
| 254 | #ifdef BACKLIGHT_ENABLE | ||
| 255 | void backlight_init_ports(void); | ||
| 256 | void backlight_task(void); | ||
| 257 | void backlight_task_internal(void); | ||
| 258 | void backlight_on(pin_t backlight_pin); | ||
| 259 | void backlight_off(pin_t backlight_pin); | ||
| 260 | |||
| 261 | # ifdef BACKLIGHT_BREATHING | ||
| 262 | void breathing_task(void); | ||
| 263 | void breathing_enable(void); | ||
| 264 | void breathing_pulse(void); | ||
| 265 | void breathing_disable(void); | ||
| 266 | void breathing_self_disable(void); | ||
| 267 | void breathing_toggle(void); | ||
| 268 | bool is_breathing(void); | ||
| 269 | |||
| 270 | void breathing_intensity_default(void); | ||
| 271 | void breathing_period_default(void); | ||
| 272 | void breathing_period_set(uint8_t value); | ||
| 273 | void breathing_period_inc(void); | ||
| 274 | void breathing_period_dec(void); | ||
| 275 | # endif | ||
| 276 | #endif | ||
| 277 | |||
| 278 | void send_dword(uint32_t number); | 254 | void send_dword(uint32_t number); |
| 279 | void send_word(uint16_t number); | 255 | void send_word(uint16_t number); |
| 280 | void send_byte(uint8_t number); | 256 | void send_byte(uint8_t number); |
