|
|
@ -14,9 +14,13 @@
|
|
|
|
* 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 "ez.h"
|
|
|
|
#include "ez.h"
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
keyboard_config_t keyboard_config;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef RGB_MATRIX_ENABLE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef RGB_MATRIX_ENABLE
|
|
|
|
void suspend_power_down_kb(void) {
|
|
|
|
void suspend_power_down_kb(void) {
|
|
|
|
rgb_matrix_set_suspend_state(true);
|
|
|
|
rgb_matrix_set_suspend_state(true);
|
|
|
|
suspend_power_down_user();
|
|
|
|
suspend_power_down_user();
|
|
|
@ -114,43 +118,150 @@ led_config_t g_led_config = { {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void matrix_init_kb(void) {
|
|
|
|
// See http://jared.geek.nz/2013/feb/linear-led-pwm
|
|
|
|
matrix_init_user();
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
palSetPadMode(GPIOB, 8, PAL_MODE_OUTPUT_PUSHPULL);
|
|
|
|
static PWMConfig pwmCFG = {
|
|
|
|
palSetPadMode(GPIOB, 9, PAL_MODE_OUTPUT_PUSHPULL);
|
|
|
|
0xFFFF,/* PWM clock frequency */
|
|
|
|
|
|
|
|
256,/* initial PWM period (in ticks) 1S (1/10kHz=0.1mS 0.1ms*10000 ticks=1S) */
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
{PWM_OUTPUT_DISABLED, NULL}, /* channel 0 -> TIM1-CH1 = PA8 */
|
|
|
|
|
|
|
|
{PWM_OUTPUT_DISABLED, NULL}, /* channel 1 -> TIM1-CH2 = PA9 */
|
|
|
|
|
|
|
|
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
|
|
|
|
|
|
|
|
{PWM_OUTPUT_ACTIVE_HIGH, NULL}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
0, /* HW dependent part.*/
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
palClearPad(GPIOB, 8);
|
|
|
|
static uint32_t planck_ez_right_led_duty;
|
|
|
|
palClearPad(GPIOB, 9);
|
|
|
|
static uint32_t planck_ez_left_led_duty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void planck_ez_right_led_level(uint8_t level) {
|
|
|
|
|
|
|
|
planck_ez_right_led_duty = (uint32_t)(cie_lightness(0xFFFF * (uint32_t) level / 255));
|
|
|
|
|
|
|
|
if (level == 0) {
|
|
|
|
|
|
|
|
// Turn backlight off
|
|
|
|
|
|
|
|
pwmDisableChannel(&PWMD4, 2);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Turn backlight on
|
|
|
|
|
|
|
|
pwmEnableChannel(&PWMD4, 2, PWM_FRACTION_TO_WIDTH(&PWMD4,0xFFFF,planck_ez_right_led_duty));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void matrix_scan_kb(void) {
|
|
|
|
|
|
|
|
matrix_scan_user();
|
|
|
|
void planck_ez_right_led_on(void){
|
|
|
|
|
|
|
|
pwmEnableChannel(&PWMD4, 2, PWM_FRACTION_TO_WIDTH(&PWMD4,0xFFFF,planck_ez_right_led_duty));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
layer_state_t layer_state_set_kb(layer_state_t state) {
|
|
|
|
void planck_ez_right_led_off(void){
|
|
|
|
|
|
|
|
pwmDisableChannel(&PWMD4, 2);
|
|
|
|
palClearPad(GPIOB, 8);
|
|
|
|
}
|
|
|
|
palClearPad(GPIOB, 9);
|
|
|
|
|
|
|
|
state = layer_state_set_user(state);
|
|
|
|
void planck_ez_left_led_level(uint8_t level) {
|
|
|
|
uint8_t layer = biton32(state);
|
|
|
|
planck_ez_left_led_duty = (uint32_t)(cie_lightness(0xFFFF * (uint32_t) level / 255));
|
|
|
|
switch (layer) {
|
|
|
|
if (level == 0) {
|
|
|
|
case 3:
|
|
|
|
// Turn backlight off
|
|
|
|
palSetPad(GPIOB, 9);
|
|
|
|
pwmDisableChannel(&PWMD4, 3);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
case 4:
|
|
|
|
// Turn backlight on
|
|
|
|
palSetPad(GPIOB, 8);
|
|
|
|
pwmEnableChannel(&PWMD4, 3, PWM_FRACTION_TO_WIDTH(&PWMD4,0xFFFF,planck_ez_left_led_duty));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
}
|
|
|
|
palSetPad(GPIOB, 9);
|
|
|
|
|
|
|
|
palSetPad(GPIOB, 8);
|
|
|
|
void planck_ez_left_led_on(void){
|
|
|
|
break;
|
|
|
|
pwmEnableChannel(&PWMD4, 3, PWM_FRACTION_TO_WIDTH(&PWMD4,0xFFFF,planck_ez_left_led_duty));
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
void planck_ez_left_led_off(void){
|
|
|
|
|
|
|
|
pwmDisableChannel(&PWMD4, 3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void led_initialize_hardware(void) {
|
|
|
|
|
|
|
|
pwmStart(&PWMD4, &pwmCFG);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set up defaults
|
|
|
|
|
|
|
|
planck_ez_right_led_level((uint8_t)keyboard_config.led_level * 255 / 4 );
|
|
|
|
|
|
|
|
palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(2));
|
|
|
|
|
|
|
|
planck_ez_left_led_level((uint8_t)keyboard_config.led_level * 255 / 4 );
|
|
|
|
|
|
|
|
palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(2));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// turn LEDs off by default
|
|
|
|
|
|
|
|
planck_ez_left_led_off();
|
|
|
|
|
|
|
|
planck_ez_right_led_off();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void keyboard_pre_init_kb(void) {
|
|
|
|
|
|
|
|
// read kb settings from eeprom
|
|
|
|
|
|
|
|
keyboard_config.raw = eeconfig_read_kb();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// initialize settings for front LEDs
|
|
|
|
|
|
|
|
led_initialize_hardware();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void eeconfig_init_kb(void) { // EEPROM is getting reset!
|
|
|
|
|
|
|
|
keyboard_config.raw = 0;
|
|
|
|
|
|
|
|
keyboard_config.led_level = 4;
|
|
|
|
|
|
|
|
eeconfig_update_kb(keyboard_config.raw);
|
|
|
|
|
|
|
|
eeconfig_init_user();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t layer_state_set_kb(uint32_t state) {
|
|
|
|
|
|
|
|
planck_ez_left_led_off();
|
|
|
|
|
|
|
|
planck_ez_right_led_off();
|
|
|
|
|
|
|
|
state = layer_state_set_user(state);
|
|
|
|
|
|
|
|
uint8_t layer = biton32(state);
|
|
|
|
|
|
|
|
switch (layer) {
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
planck_ez_left_led_on();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
planck_ez_right_led_on();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
|
|
|
|
planck_ez_right_led_on();
|
|
|
|
|
|
|
|
planck_ez_left_led_on();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
|
|
|
|
switch (keycode) {
|
|
|
|
|
|
|
|
case LED_LEVEL:
|
|
|
|
|
|
|
|
if (record->event.pressed) {
|
|
|
|
|
|
|
|
keyboard_config.led_level++;
|
|
|
|
|
|
|
|
if (keyboard_config.led_level > 4) {
|
|
|
|
|
|
|
|
keyboard_config.led_level = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
planck_ez_right_led_level((uint8_t)keyboard_config.led_level * 255 / 4 );
|
|
|
|
|
|
|
|
planck_ez_left_led_level((uint8_t)keyboard_config.led_level * 255 / 4 );
|
|
|
|
|
|
|
|
eeconfig_update_kb(keyboard_config.raw);
|
|
|
|
|
|
|
|
layer_state_set_kb(layer_state);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return process_record_user(keycode, record);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef AUDIO_ENABLE
|
|
|
|
#ifdef AUDIO_ENABLE
|
|
|
|
bool music_mask_kb(uint16_t keycode) {
|
|
|
|
bool music_mask_kb(uint16_t keycode) {
|
|
|
|
switch (keycode) {
|
|
|
|
switch (keycode) {
|
|
|
|