Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b438c6f8ea | ||
|
|
bad9468ce1 | ||
|
|
9810756ee0 | ||
|
|
918a85d342 | ||
|
|
116c0e44a1 | ||
|
|
3c0ef04390 |
No files matched your search
@@ -8,39 +8,6 @@ void matrix_init_kb(void) {
|
|||||||
led_init_ports();
|
led_init_ports();
|
||||||
}
|
}
|
||||||
|
|
||||||
void matrix_scan_kb(void) {
|
|
||||||
matrix_scan_user();
|
|
||||||
}
|
|
||||||
|
|
||||||
void backlight_init_ports(void) {
|
|
||||||
print("init_backlight_pin()\n");
|
|
||||||
// Set our LED pins as output
|
|
||||||
//DDRD |= (1<<6); // Esc
|
|
||||||
//DDRB |= (1<<7); // Page Up
|
|
||||||
//DDRD |= (1<<4); // Arrows
|
|
||||||
|
|
||||||
// Set our LED pins low
|
|
||||||
//PORTD &= ~(1<<6); // Esc
|
|
||||||
//PORTB &= ~(1<<7); // Page Up
|
|
||||||
//PORTD &= ~(1<<4); // Arrows
|
|
||||||
}
|
|
||||||
|
|
||||||
void backlight_set(uint8_t level) {
|
|
||||||
/*
|
|
||||||
if ( level == 0 ) {
|
|
||||||
// Turn off light
|
|
||||||
PORTD |= (1<<6); // Esc
|
|
||||||
PORTB |= (1<<7); // Page Up
|
|
||||||
PORTD |= (1<<4); // Arrows
|
|
||||||
} else {
|
|
||||||
// Turn on light
|
|
||||||
PORTD &= ~(1<<6); // Esc
|
|
||||||
PORTB &= ~(1<<7); // Page Up
|
|
||||||
PORTD &= ~(1<<4); // Arrows
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void led_init_ports() {
|
void led_init_ports() {
|
||||||
// Set our LED pins as output
|
// Set our LED pins as output
|
||||||
palSetPadMode(GPIOB, 13, PAL_MODE_OUTPUT_PUSHPULL); // LED1
|
palSetPadMode(GPIOB, 13, PAL_MODE_OUTPUT_PUSHPULL); // LED1
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ MCU = STM32F303
|
|||||||
# Build Options
|
# Build Options
|
||||||
# comment out to disable the options.
|
# comment out to disable the options.
|
||||||
#
|
#
|
||||||
BACKLIGHT_ENABLE = yes
|
|
||||||
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration
|
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration
|
||||||
MOUSEKEY_ENABLE = yes # Mouse keys
|
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||||
EXTRAKEY_ENABLE = yes # Audio control and System control
|
EXTRAKEY_ENABLE = yes # Audio control and System control
|
||||||
@@ -12,7 +11,8 @@ CONSOLE_ENABLE = yes # Console for debug
|
|||||||
COMMAND_ENABLE = no # Commands for debug and configuration
|
COMMAND_ENABLE = no # Commands for debug and configuration
|
||||||
NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
||||||
AUDIO_ENABLE = no
|
AUDIO_ENABLE = no
|
||||||
RGBLIGHT_ENABLE = no # Enable keyboard underlight functionality
|
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
|
||||||
|
RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
|
||||||
MIDI_ENABLE = no # MIDI controls
|
MIDI_ENABLE = no # MIDI controls
|
||||||
UNICODE_ENABLE = no # Unicode
|
UNICODE_ENABLE = no # Unicode
|
||||||
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
|
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
|
||||||
|
|||||||
Executable → Regular
File mode changed.
@@ -63,10 +63,13 @@ void pointing_device_task(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void led_init(void) {
|
void led_init(void) {
|
||||||
DDRD |= (1<<1);
|
setPinOutput(D1);
|
||||||
PORTD |= (1<<1);
|
setPinOutput(F5);
|
||||||
DDRF |= (1<<4) | (1<<5);
|
setPinOutput(F6);
|
||||||
PORTF |= (1<<4) | (1<<5);
|
|
||||||
|
writePinHigh(D1);
|
||||||
|
writePinHigh(F5);
|
||||||
|
writePinHigh(F6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,12 +5,16 @@
|
|||||||
#include "pointing_device.h"
|
#include "pointing_device.h"
|
||||||
#include "quantum.h"
|
#include "quantum.h"
|
||||||
|
|
||||||
#define red_led_off() PORTF |= (1<<6)
|
#define red_led_off() writePinHigh(F6)
|
||||||
#define red_led_on() PORTF &= ~(1<<6)
|
#define red_led_on() writePinLow(F6)
|
||||||
#define blu_led_off() PORTF |= (1<<5)
|
#define blu_led_off() writePinHigh(F5)
|
||||||
#define blu_led_on() PORTF &= ~(1<<5)
|
#define blu_led_on() writePinLow(F5)
|
||||||
#define grn_led_off() PORTD |= (1<<1)
|
#define grn_led_off() writePinHigh(D1)
|
||||||
#define grn_led_on() PORTD &= ~(1<<1)
|
#define grn_led_on() writePinLow(D1)
|
||||||
|
|
||||||
|
#define red_led(flag) if (flag) red_led_on(); else red_led_off()
|
||||||
|
#define blu_led(flag) if (flag) blu_led_on(); else blu_led_off()
|
||||||
|
#define grn_led(flag) if (flag) grn_led_on(); else grn_led_off()
|
||||||
|
|
||||||
#define set_led_off() red_led_off(); grn_led_off(); blu_led_off()
|
#define set_led_off() red_led_off(); grn_led_off(); blu_led_off()
|
||||||
#define set_led_red() red_led_on(); grn_led_off(); blu_led_off()
|
#define set_led_red() red_led_on(); grn_led_off(); blu_led_off()
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
#define TAPPING_TERM 200
|
||||||
|
#define TAPPING_TOGGLE 2
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
enum layer_names {
|
||||||
|
_QWERTY,
|
||||||
|
_LOWER,
|
||||||
|
_RAISE,
|
||||||
|
_MOUSE,
|
||||||
|
_ADJUST
|
||||||
|
};
|
||||||
|
|
||||||
|
enum dichotomy_keycodes {
|
||||||
|
MS_BTN1 = SAFE_RANGE,
|
||||||
|
MS_BTN2,
|
||||||
|
MS_BTN3
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
|
||||||
|
[_QWERTY] = LAYOUT( /* Base layout, nearly qwerty but with modifications because it's not a full keyboard. Obviously. */
|
||||||
|
KC_ESCAPE, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
|
||||||
|
KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT,
|
||||||
|
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, TT(_MOUSE),
|
||||||
|
KC_LGUI, KC_LALT, KC_DEL, KC_RCTL, KC_RALT, KC_RGUI,
|
||||||
|
MS_BTN3, SFT_T(KC_ESCAPE), KC_LCTL, KC_SPC, KC_SPC, TT(_RAISE), TT(_LOWER), MS_BTN3
|
||||||
|
),
|
||||||
|
|
||||||
|
[_RAISE] = LAYOUT( /* Shifted layout, small changes (because angle brackets have been moved to thumb cluster buttons) */
|
||||||
|
_______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, _______,
|
||||||
|
_______, _______, KC_VOLD, KC_VOLU, KC_MPLY, KC_MNXT, KC_MUTE, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, _______,
|
||||||
|
_______, _______, KC_GRV, _______, _______, KC_MPRV, _______, KC_LABK, KC_RABK, KC_BSLS, KC_QUOT, _______,
|
||||||
|
_______, _______, _______, _______, _______, _______,
|
||||||
|
_______, _______, _______, _______, _______, _______, _______, _______
|
||||||
|
),
|
||||||
|
|
||||||
|
[_LOWER] = LAYOUT( /* Number layout, basically the main function layer */
|
||||||
|
_______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______,
|
||||||
|
_______, _______, KC_VOLD, KC_VOLU, KC_MPLY, KC_MNXT, KC_MUTE, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, _______,
|
||||||
|
_______, _______, KC_TILD, _______, _______, KC_MPRV, _______, _______, _______, KC_PIPE, KC_DQT, _______,
|
||||||
|
_______, _______, _______, _______, _______, _______,
|
||||||
|
_______, _______, _______, _______, _______, _______, _______, _______
|
||||||
|
),
|
||||||
|
|
||||||
|
[_ADJUST] = LAYOUT( /* Shifted number/function layout, for per-key control. Only active when shift is held, and number is toggled or held */
|
||||||
|
KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_PSLS, KC_P7, KC_P8, KC_P9, KC_PMNS, _______,
|
||||||
|
KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PAST, KC_P4, KC_P5, KC_P6, KC_PPLS, _______,
|
||||||
|
_______, _______, _______, LGUI(KC_L), KC_PSCR, KC_APP, KC_PCMM, KC_P1, KC_P2, KC_P3, KC_PEQL, _______,
|
||||||
|
_______, _______, _______, _______, KC_P0, KC_PDOT,
|
||||||
|
_______, _______, _______, _______, _______, _______, _______, _______
|
||||||
|
),
|
||||||
|
|
||||||
|
[_MOUSE] = LAYOUT( /* Mouse layer, including buttons for clicking. */
|
||||||
|
_______, _______, _______, _______, _______, _______, KC_VOLU, KC_HOME, KC_WH_U, KC_PGUP, _______, _______,
|
||||||
|
_______, _______, MS_BTN2, MS_BTN3, MS_BTN1, _______, KC_VOLD, MS_BTN1, MS_BTN3, MS_BTN2, _______, _______,
|
||||||
|
_______, _______, _______, _______, _______, _______, KC_HOME, KC_END, KC_WH_D, KC_PGDN, _______, _______,
|
||||||
|
_______, KC_UP, _______, _______, KC_UP, _______,
|
||||||
|
_______, KC_LEFT, KC_DOWN, KC_RGHT, KC_LEFT, KC_DOWN, KC_RGHT, _______
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
layer_state_t layer_state_set_user(layer_state_t state) {
|
||||||
|
red_led(layer_state_cmp(state, _LOWER));
|
||||||
|
grn_led(layer_state_cmp(state, _RAISE));
|
||||||
|
blu_led(layer_state_cmp(state, _MOUSE));
|
||||||
|
return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SetBitMask(variable, mask, on) if (on) variable |= mask; else variable &= ~mask
|
||||||
|
|
||||||
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
report_mouse_t currentReport;
|
||||||
|
switch (keycode) {
|
||||||
|
//mouse buttons, for 1-3, to update the mouse report:
|
||||||
|
//MOUSE_BTN1-3 are consts defined in report.h
|
||||||
|
case MS_BTN1:
|
||||||
|
currentReport = pointing_device_get_report();
|
||||||
|
SetBitMask(currentReport.buttons, MOUSE_BTN1, record->event.pressed);
|
||||||
|
pointing_device_set_report(currentReport);
|
||||||
|
return false;
|
||||||
|
case MS_BTN2:
|
||||||
|
currentReport = pointing_device_get_report();
|
||||||
|
SetBitMask(currentReport.buttons, MOUSE_BTN2, record->event.pressed);
|
||||||
|
pointing_device_set_report(currentReport);
|
||||||
|
return false;
|
||||||
|
case MS_BTN3:
|
||||||
|
currentReport = pointing_device_get_report();
|
||||||
|
SetBitMask(currentReport.buttons, MOUSE_BTN3, record->event.pressed);
|
||||||
|
pointing_device_set_report(currentReport);
|
||||||
|
return false;
|
||||||
|
case KC_WH_U:
|
||||||
|
currentReport = pointing_device_get_report();
|
||||||
|
if(record->event.pressed) {
|
||||||
|
currentReport.v += 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
currentReport.v = 0;
|
||||||
|
}
|
||||||
|
pointing_device_set_report(currentReport);
|
||||||
|
return false;
|
||||||
|
case KC_WH_D:
|
||||||
|
currentReport = pointing_device_get_report();
|
||||||
|
if(record->event.pressed) {
|
||||||
|
currentReport.v -= 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
currentReport.v = 0;
|
||||||
|
}
|
||||||
|
pointing_device_set_report(currentReport);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -92,9 +92,6 @@ uint8_t matrix_cols(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void matrix_init(void) {
|
void matrix_init(void) {
|
||||||
DDRF |= (1<<6);
|
|
||||||
DDRF |= (1<<5);
|
|
||||||
DDRD |= (1<<1);
|
|
||||||
matrix_init_quantum();
|
matrix_init_quantum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,14 +15,62 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "quantum.h"
|
||||||
#include "backlight.h"
|
#include "backlight.h"
|
||||||
#include "eeconfig.h"
|
#include "eeconfig.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
backlight_config_t backlight_config;
|
backlight_config_t backlight_config;
|
||||||
|
|
||||||
|
#ifdef BACKLIGHT_BREATHING
|
||||||
// TODO: migrate to backlight_config_t
|
// TODO: migrate to backlight_config_t
|
||||||
static uint8_t breathing_period = BREATHING_PERIOD;
|
static uint8_t breathing_period = BREATHING_PERIOD;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BACKLIGHT_CUSTOM_DRIVER
|
||||||
|
# if defined(BACKLIGHT_PINS)
|
||||||
|
static const pin_t backlight_pins[] = BACKLIGHT_PINS;
|
||||||
|
# ifndef BACKLIGHT_LED_COUNT
|
||||||
|
# define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t))
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define FOR_EACH_LED(x) \
|
||||||
|
for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \
|
||||||
|
pin_t backlight_pin = backlight_pins[i]; \
|
||||||
|
{ x } \
|
||||||
|
}
|
||||||
|
# else
|
||||||
|
// we support only one backlight pin
|
||||||
|
static const pin_t backlight_pin = BACKLIGHT_PIN;
|
||||||
|
# define FOR_EACH_LED(x) x
|
||||||
|
# endif
|
||||||
|
|
||||||
|
static inline void backlight_on(pin_t backlight_pin) {
|
||||||
|
# if BACKLIGHT_ON_STATE == 0
|
||||||
|
writePinLow(backlight_pin);
|
||||||
|
# else
|
||||||
|
writePinHigh(backlight_pin);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void backlight_off(pin_t backlight_pin) {
|
||||||
|
# if BACKLIGHT_ON_STATE == 0
|
||||||
|
writePinHigh(backlight_pin);
|
||||||
|
# else
|
||||||
|
writePinLow(backlight_pin);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void backlight_pins_init(void) {
|
||||||
|
// Setup backlight pin as output and output to off state.
|
||||||
|
FOR_EACH_LED(setPinOutput(backlight_pin); backlight_off(backlight_pin);)
|
||||||
|
}
|
||||||
|
|
||||||
|
void backlight_pins_on(void) { FOR_EACH_LED(backlight_on(backlight_pin);) }
|
||||||
|
|
||||||
|
void backlight_pins_off(void) { FOR_EACH_LED(backlight_off(backlight_pin);) }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/** \brief Backlight initialization
|
/** \brief Backlight initialization
|
||||||
*
|
*
|
||||||
@@ -205,7 +253,6 @@ void backlight_disable_breathing(void) {
|
|||||||
* FIXME: needs doc
|
* FIXME: needs doc
|
||||||
*/
|
*/
|
||||||
bool is_backlight_breathing(void) { return backlight_config.breathing; }
|
bool is_backlight_breathing(void) { return backlight_config.breathing; }
|
||||||
#endif
|
|
||||||
|
|
||||||
// following are marked as weak purely for backwards compatibility
|
// following are marked as weak purely for backwards compatibility
|
||||||
__attribute__((weak)) void breathing_period_set(uint8_t value) { breathing_period = value ? value : 1; }
|
__attribute__((weak)) void breathing_period_set(uint8_t value) { breathing_period = value ? value : 1; }
|
||||||
@@ -218,6 +265,15 @@ __attribute__((weak)) void breathing_period_inc(void) { breathing_period_set(bre
|
|||||||
|
|
||||||
__attribute__((weak)) void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); }
|
__attribute__((weak)) void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); }
|
||||||
|
|
||||||
|
__attribute__((weak)) void breathing_toggle(void) {
|
||||||
|
if (is_breathing())
|
||||||
|
breathing_disable();
|
||||||
|
else
|
||||||
|
breathing_enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// defaults for backlight api
|
// defaults for backlight api
|
||||||
__attribute__((weak)) void backlight_init_ports(void) {}
|
__attribute__((weak)) void backlight_init_ports(void) {}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
# error "Maximum value of BACKLIGHT_LEVELS is 31"
|
# error "Maximum value of BACKLIGHT_LEVELS is 31"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef BACKLIGHT_ON_STATE
|
||||||
|
# define BACKLIGHT_ON_STATE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef BREATHING_PERIOD
|
#ifndef BREATHING_PERIOD
|
||||||
# define BREATHING_PERIOD 6
|
# define BREATHING_PERIOD 6
|
||||||
#endif
|
#endif
|
||||||
@@ -40,6 +44,10 @@ typedef union {
|
|||||||
};
|
};
|
||||||
} backlight_config_t;
|
} backlight_config_t;
|
||||||
|
|
||||||
|
void backlight_pins_init(void);
|
||||||
|
void backlight_pins_on(void);
|
||||||
|
void backlight_pins_off(void);
|
||||||
|
|
||||||
void backlight_init(void);
|
void backlight_init(void);
|
||||||
void backlight_toggle(void);
|
void backlight_toggle(void);
|
||||||
void backlight_enable(void);
|
void backlight_enable(void);
|
||||||
|
|||||||
@@ -158,13 +158,6 @@ void breathing_self_disable(void) {
|
|||||||
breathing_halt = BREATHING_HALT_ON;
|
breathing_halt = BREATHING_HALT_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
void breathing_toggle(void) {
|
|
||||||
if (is_breathing())
|
|
||||||
breathing_disable();
|
|
||||||
else
|
|
||||||
breathing_enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* To generate breathing curve in python:
|
/* To generate breathing curve in python:
|
||||||
* from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
|
* from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -164,49 +164,7 @@ error("Please set 'BACKLIGHT_DRIVER = custom' within rules.mk")
|
|||||||
error("Please set 'BACKLIGHT_DRIVER = software' within rules.mk")
|
error("Please set 'BACKLIGHT_DRIVER = software' within rules.mk")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef BACKLIGHT_ON_STATE
|
#ifndef BACKLIGHT_PWM_TIMER // pwm through software
|
||||||
# define BACKLIGHT_ON_STATE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void backlight_on(pin_t backlight_pin) {
|
|
||||||
#if BACKLIGHT_ON_STATE == 1
|
|
||||||
writePinHigh(backlight_pin);
|
|
||||||
#else
|
|
||||||
writePinLow(backlight_pin);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void backlight_off(pin_t backlight_pin) {
|
|
||||||
#if BACKLIGHT_ON_STATE == 1
|
|
||||||
writePinLow(backlight_pin);
|
|
||||||
#else
|
|
||||||
writePinHigh(backlight_pin);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef BACKLIGHT_PWM_TIMER // pwm through software
|
|
||||||
|
|
||||||
// we support multiple backlight pins
|
|
||||||
# ifndef BACKLIGHT_LED_COUNT
|
|
||||||
# define BACKLIGHT_LED_COUNT 1
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if BACKLIGHT_LED_COUNT == 1
|
|
||||||
# define BACKLIGHT_PIN_INIT \
|
|
||||||
{ BACKLIGHT_PIN }
|
|
||||||
# else
|
|
||||||
# define BACKLIGHT_PIN_INIT BACKLIGHT_PINS
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# define FOR_EACH_LED(x) \
|
|
||||||
for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \
|
|
||||||
pin_t backlight_pin = backlight_pins[i]; \
|
|
||||||
{ x } \
|
|
||||||
}
|
|
||||||
|
|
||||||
static const pin_t backlight_pins[BACKLIGHT_LED_COUNT] = BACKLIGHT_PIN_INIT;
|
|
||||||
|
|
||||||
#else // full hardware PWM
|
|
||||||
|
|
||||||
static inline void enable_pwm(void) {
|
static inline void enable_pwm(void) {
|
||||||
# if BACKLIGHT_ON_STATE == 1
|
# if BACKLIGHT_ON_STATE == 1
|
||||||
@@ -224,10 +182,6 @@ static inline void disable_pwm(void) {
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// we support only one backlight pin
|
|
||||||
static const pin_t backlight_pin = BACKLIGHT_PIN;
|
|
||||||
# define FOR_EACH_LED(x) x
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BACKLIGHT_PWM_TIMER
|
#ifdef BACKLIGHT_PWM_TIMER
|
||||||
@@ -246,7 +200,7 @@ static const pin_t backlight_pin = BACKLIGHT_PIN;
|
|||||||
// The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz.
|
// The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz.
|
||||||
|
|
||||||
// Triggered when the counter reaches the OCRx value
|
// Triggered when the counter reaches the OCRx value
|
||||||
ISR(TIMERx_COMPA_vect) { FOR_EACH_LED(backlight_off(backlight_pin);) }
|
ISR(TIMERx_COMPA_vect) { backlight_pins_off(); }
|
||||||
|
|
||||||
// Triggered when the counter reaches the TOP value
|
// Triggered when the counter reaches the TOP value
|
||||||
// this one triggers at F_CPU/65536 =~ 244 Hz
|
// this one triggers at F_CPU/65536 =~ 244 Hz
|
||||||
@@ -265,7 +219,7 @@ ISR(TIMERx_OVF_vect) {
|
|||||||
// takes many computation cycles).
|
// takes many computation cycles).
|
||||||
// so better not turn them on while the counter TOP is very low.
|
// so better not turn them on while the counter TOP is very low.
|
||||||
if (OCRxx > 256) {
|
if (OCRxx > 256) {
|
||||||
FOR_EACH_LED(backlight_on(backlight_pin);)
|
backlight_pins_on();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +259,7 @@ void backlight_set(uint8_t level) {
|
|||||||
// Turn off PWM control on backlight pin
|
// Turn off PWM control on backlight pin
|
||||||
disable_pwm();
|
disable_pwm();
|
||||||
#endif
|
#endif
|
||||||
FOR_EACH_LED(backlight_off(backlight_pin);)
|
backlight_pins_off();
|
||||||
} else {
|
} else {
|
||||||
#ifdef BACKLIGHT_PWM_TIMER
|
#ifdef BACKLIGHT_PWM_TIMER
|
||||||
if (!OCRxx) {
|
if (!OCRxx) {
|
||||||
@@ -397,13 +351,6 @@ void breathing_self_disable(void) {
|
|||||||
breathing_halt = BREATHING_HALT_ON;
|
breathing_halt = BREATHING_HALT_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
void breathing_toggle(void) {
|
|
||||||
if (is_breathing())
|
|
||||||
breathing_disable();
|
|
||||||
else
|
|
||||||
breathing_enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* To generate breathing curve in python:
|
/* To generate breathing curve in python:
|
||||||
* from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
|
* from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
|
||||||
*/
|
*/
|
||||||
@@ -438,7 +385,7 @@ ISR(TIMERx_OVF_vect)
|
|||||||
|
|
||||||
void backlight_init_ports(void) {
|
void backlight_init_ports(void) {
|
||||||
// Setup backlight pin as output and output to on state.
|
// Setup backlight pin as output and output to on state.
|
||||||
FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);)
|
backlight_pins_init();
|
||||||
|
|
||||||
// I could write a wall of text here to explain... but TL;DW
|
// I could write a wall of text here to explain... but TL;DW
|
||||||
// Go read the ATmega32u4 datasheet.
|
// Go read the ATmega32u4 datasheet.
|
||||||
|
|||||||
@@ -9,47 +9,7 @@
|
|||||||
# error "Backlight breathing is not available for software PWM. Please disable."
|
# error "Backlight breathing is not available for software PWM. Please disable."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef BACKLIGHT_ON_STATE
|
static uint16_t s_duty_pattern = 0;
|
||||||
# define BACKLIGHT_ON_STATE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BACKLIGHT_PINS
|
|
||||||
# define BACKLIGHT_PIN_INIT BACKLIGHT_PINS
|
|
||||||
#else
|
|
||||||
# define BACKLIGHT_PIN_INIT \
|
|
||||||
{ BACKLIGHT_PIN }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static uint16_t s_duty_pattern = 0;
|
|
||||||
static const pin_t backlight_pins[] = BACKLIGHT_PIN_INIT;
|
|
||||||
#define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t))
|
|
||||||
|
|
||||||
#define FOR_EACH_LED(x) \
|
|
||||||
for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \
|
|
||||||
pin_t backlight_pin = backlight_pins[i]; \
|
|
||||||
{ x } \
|
|
||||||
}
|
|
||||||
|
|
||||||
void backlight_on(pin_t backlight_pin) {
|
|
||||||
#if BACKLIGHT_ON_STATE == 0
|
|
||||||
writePinLow(backlight_pin);
|
|
||||||
#else
|
|
||||||
writePinHigh(backlight_pin);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void backlight_off(pin_t backlight_pin) {
|
|
||||||
#if BACKLIGHT_ON_STATE == 0
|
|
||||||
writePinHigh(backlight_pin);
|
|
||||||
#else
|
|
||||||
writePinLow(backlight_pin);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void backlight_init_ports(void) {
|
|
||||||
// Setup backlight pin as output and output to off state.
|
|
||||||
FOR_EACH_LED(setPinOutput(backlight_pin); backlight_off(backlight_pin);)
|
|
||||||
}
|
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
@@ -58,7 +18,7 @@ void backlight_init_ports(void) {
|
|||||||
* We scale the current backlight level to an index within this array. This allows
|
* 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
|
* backlight_task to focus on just switching LEDs on/off, and we can predict the duty pattern
|
||||||
*/
|
*/
|
||||||
static uint16_t backlight_duty_table[] = {
|
static const uint16_t backlight_duty_table[] = {
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b1000000000000000,
|
0b1000000000000000,
|
||||||
0b1000000010000000,
|
0b1000000010000000,
|
||||||
@@ -75,15 +35,17 @@ static uint16_t backlight_duty_table[] = {
|
|||||||
|
|
||||||
static uint8_t scale_backlight(uint8_t v) { return v * (backlight_duty_table_size - 1) / BACKLIGHT_LEVELS; }
|
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) {
|
void backlight_task(void) {
|
||||||
static uint8_t backlight_tick = 0;
|
static uint8_t backlight_tick = 0;
|
||||||
|
|
||||||
if (s_duty_pattern & ((uint16_t)1 << backlight_tick)) {
|
if (s_duty_pattern & ((uint16_t)1 << backlight_tick)) {
|
||||||
FOR_EACH_LED(backlight_on(backlight_pin);)
|
backlight_pins_on();
|
||||||
} else {
|
} else {
|
||||||
FOR_EACH_LED(backlight_off(backlight_pin);)
|
backlight_pins_off();
|
||||||
}
|
}
|
||||||
backlight_tick = (backlight_tick + 1) % 16;
|
backlight_tick = (backlight_tick + 1) % 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
void backlight_set(uint8_t level) { s_duty_pattern = backlight_duty_table[scale_backlight(level)]; }
|
|
||||||
@@ -45,6 +45,6 @@ stdenv.mkDerivation {
|
|||||||
++ lib.optional arm [ gcc-arm-embedded ]
|
++ lib.optional arm [ gcc-arm-embedded ]
|
||||||
++ lib.optional teensy [ teensy-loader-cli ];
|
++ lib.optional teensy [ teensy-loader-cli ];
|
||||||
|
|
||||||
CFLAGS = lib.optional avr avr_incflags;
|
AVR_CFLAGS = lib.optional avr avr_incflags;
|
||||||
ASFLAGS = lib.optional avr avr_incflags;
|
AVR_ASFLAGS = lib.optional avr avr_incflags;
|
||||||
}
|
}
|
||||||
+3
-1
@@ -21,7 +21,9 @@ COMPILEFLAGS += -fdata-sections
|
|||||||
COMPILEFLAGS += -fpack-struct
|
COMPILEFLAGS += -fpack-struct
|
||||||
COMPILEFLAGS += -fshort-enums
|
COMPILEFLAGS += -fshort-enums
|
||||||
|
|
||||||
CFLAGS += $(COMPILEFLAGS)
|
ASFLAGS += $(AVR_ASFLAGS)
|
||||||
|
|
||||||
|
CFLAGS += $(COMPILEFLAGS) $(AVR_CFLAGS)
|
||||||
CFLAGS += -fno-inline-small-functions
|
CFLAGS += -fno-inline-small-functions
|
||||||
CFLAGS += -fno-strict-aliasing
|
CFLAGS += -fno-strict-aliasing
|
||||||
|
|
||||||
|
|||||||
+27
-12
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__)
|
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__)
|
||||||
# define UDRn UDR0
|
# define UDRn UDR0
|
||||||
# define UBRRn UBRR0
|
# define UBRRnL UBRR0L
|
||||||
# define UCSRnA UCSR0A
|
# define UCSRnA UCSR0A
|
||||||
# define UCSRnB UCSR0B
|
# define UCSRnB UCSR0B
|
||||||
# define UCSRnC UCSR0C
|
# define UCSRnC UCSR0C
|
||||||
@@ -44,11 +44,11 @@
|
|||||||
# define UCSZn1 UCSZ01
|
# define UCSZn1 UCSZ01
|
||||||
# define UCSZn0 UCSZ00
|
# define UCSZn0 UCSZ00
|
||||||
# define UDRIEn UDRIE0
|
# define UDRIEn UDRIE0
|
||||||
# define UDRE_vect USART_UDRE_vect
|
# define USARTn_UDRE_vect USART_UDRE_vect
|
||||||
# define RX_vect USART_RX_vect
|
# define USARTn_RX_vect USART_RX_vect
|
||||||
#elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega32U2__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
#elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega32U2__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
||||||
# define UDRn UDR1
|
# define UDRn UDR1
|
||||||
# define UBRRn UBRR1
|
# define UBRRnL UBRR1L
|
||||||
# define UCSRnA UCSR1A
|
# define UCSRnA UCSR1A
|
||||||
# define UCSRnB UCSR1B
|
# define UCSRnB UCSR1B
|
||||||
# define UCSRnC UCSR1C
|
# define UCSRnC UCSR1C
|
||||||
@@ -59,8 +59,23 @@
|
|||||||
# define UCSZn1 UCSZ11
|
# define UCSZn1 UCSZ11
|
||||||
# define UCSZn0 UCSZ10
|
# define UCSZn0 UCSZ10
|
||||||
# define UDRIEn UDRIE1
|
# define UDRIEn UDRIE1
|
||||||
# define UDRE_vect USART1_UDRE_vect
|
# define USARTn_UDRE_vect USART1_UDRE_vect
|
||||||
# define RX_vect USART1_RX_vect
|
# define USARTn_RX_vect USART1_RX_vect
|
||||||
|
#elif defined(__AVR_ATmega32A__)
|
||||||
|
# define UDRn UDR
|
||||||
|
# define UBRRnL UBRRL
|
||||||
|
# define UCSRnA UCSRA
|
||||||
|
# define UCSRnB UCSRB
|
||||||
|
# define UCSRnC UCSRC
|
||||||
|
# define U2Xn U2X
|
||||||
|
# define RXENn RXEN
|
||||||
|
# define TXENn TXEN
|
||||||
|
# define RXCIEn RXCIE
|
||||||
|
# define UCSZn1 UCSZ1
|
||||||
|
# define UCSZn0 UCSZ0
|
||||||
|
# define UDRIEn UDRIE
|
||||||
|
# define USARTn_UDRE_vect USART_UDRE_vect
|
||||||
|
# define USARTn_RX_vect USART_RX_vect
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// These buffers may be any size from 2 to 256 bytes.
|
// These buffers may be any size from 2 to 256 bytes.
|
||||||
@@ -77,7 +92,7 @@ static volatile uint8_t rx_buffer_tail;
|
|||||||
// Initialize the UART
|
// Initialize the UART
|
||||||
void uart_init(uint32_t baud) {
|
void uart_init(uint32_t baud) {
|
||||||
cli();
|
cli();
|
||||||
UBRRn = (F_CPU / 4 / baud - 1) / 2;
|
UBRRnL = (F_CPU / 4 / baud - 1) / 2;
|
||||||
UCSRnA = (1 << U2Xn);
|
UCSRnA = (1 << U2Xn);
|
||||||
UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn);
|
UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn);
|
||||||
UCSRnC = (1 << UCSZn1) | (1 << UCSZn0);
|
UCSRnC = (1 << UCSZn1) | (1 << UCSZn0);
|
||||||
@@ -99,7 +114,7 @@ void uart_putchar(uint8_t c) {
|
|||||||
// cli();
|
// cli();
|
||||||
tx_buffer[i] = c;
|
tx_buffer[i] = c;
|
||||||
tx_buffer_head = i;
|
tx_buffer_head = i;
|
||||||
UCSRB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn) | (1 << UDRIEn);
|
UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn) | (1 << UDRIEn);
|
||||||
// sei();
|
// sei();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +144,7 @@ uint8_t uart_available(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Transmit Interrupt
|
// Transmit Interrupt
|
||||||
ISR(UDRE_vect) {
|
ISR(USARTn_UDRE_vect) {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
if (tx_buffer_head == tx_buffer_tail) {
|
if (tx_buffer_head == tx_buffer_tail) {
|
||||||
@@ -138,13 +153,13 @@ ISR(UDRE_vect) {
|
|||||||
} else {
|
} else {
|
||||||
i = tx_buffer_tail + 1;
|
i = tx_buffer_tail + 1;
|
||||||
if (i >= TX_BUFFER_SIZE) i = 0;
|
if (i >= TX_BUFFER_SIZE) i = 0;
|
||||||
UDR0 = tx_buffer[i];
|
UDRn = tx_buffer[i];
|
||||||
tx_buffer_tail = i;
|
tx_buffer_tail = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receive Interrupt
|
// Receive Interrupt
|
||||||
ISR(RX_vect) {
|
ISR(USARTn_RX_vect) {
|
||||||
uint8_t c, i;
|
uint8_t c, i;
|
||||||
|
|
||||||
c = UDRn;
|
c = UDRn;
|
||||||
|
|||||||
Reference in new issue
Block a user