mirror of
https://github.com/Keychron/qmk_firmware.git
synced 2024-11-22 00:16:41 +06:00
Update q11
This commit is contained in:
parent
6050049932
commit
95f8cf96cd
|
@ -16,9 +16,8 @@
|
|||
|
||||
#include "quantum.h"
|
||||
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
|
||||
// clang-format off
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
|
||||
const ckled2001_led PROGMEM g_ckled2001_leds[RGB_MATRIX_LED_COUNT] = {
|
||||
/* Refer to CKLED2001 manual for these locations
|
||||
|
@ -179,94 +178,4 @@ led_config_t g_led_config = {
|
|||
}
|
||||
};
|
||||
|
||||
// clang-format on
|
||||
|
||||
#endif
|
||||
|
||||
#define ADC_BUFFER_DEPTH 1
|
||||
#define ADC_NUM_CHANNELS 1
|
||||
#define ADC_SAMPLING_RATE ADC_SMPR_SMP_12P5
|
||||
#define ADC_RESOLUTION ADC_CFGR_RES_10BITS
|
||||
|
||||
static int16_t analogReadPin_my(pin_t pin) {
|
||||
ADCConfig adcCfg = {};
|
||||
adcsample_t sampleBuffer[ADC_NUM_CHANNELS * ADC_BUFFER_DEPTH];
|
||||
ADCDriver *targetDriver = &ADCD1;
|
||||
ADCConversionGroup adcConversionGroup = {
|
||||
.circular = FALSE,
|
||||
.num_channels = (uint16_t)(ADC_NUM_CHANNELS),
|
||||
.cfgr = ADC_RESOLUTION,
|
||||
};
|
||||
|
||||
palSetLineMode(pin, PAL_MODE_INPUT_ANALOG);
|
||||
switch (pin) {
|
||||
case B0:
|
||||
adcConversionGroup.smpr[2] = ADC_SMPR2_SMP_AN15(ADC_SAMPLING_RATE);
|
||||
adcConversionGroup.sqr[0] = ADC_SQR1_SQ1_N(ADC_CHANNEL_IN15);
|
||||
sampleBuffer[0] = 0;
|
||||
break;
|
||||
case B1:
|
||||
adcConversionGroup.smpr[2] = ADC_SMPR2_SMP_AN16(ADC_SAMPLING_RATE);
|
||||
adcConversionGroup.sqr[0] = ADC_SQR1_SQ1_N(ADC_CHANNEL_IN16);
|
||||
sampleBuffer[0] = 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
adcStart(targetDriver, &adcCfg);
|
||||
if (adcConvert(targetDriver, &adcConversionGroup, &sampleBuffer[0], ADC_BUFFER_DEPTH) != MSG_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return *sampleBuffer;
|
||||
}
|
||||
|
||||
#if defined(ENCODER_ENABLE) && defined(PAL_USE_CALLBACKS)
|
||||
|
||||
void encoder0_pad_cb(void *param) {
|
||||
(void)param;
|
||||
|
||||
encoder_inerrupt_read(0);
|
||||
}
|
||||
|
||||
void encoder1_pad_cb(void *param) {
|
||||
(void)param;
|
||||
|
||||
encoder_inerrupt_read(1);
|
||||
}
|
||||
|
||||
void encoder_interrupt_init(void) {
|
||||
pin_t encoders_pad_a[NUM_ENCODERS] = ENCODERS_PAD_A;
|
||||
pin_t encoders_pad_b[NUM_ENCODERS] = ENCODERS_PAD_B;
|
||||
for (uint8_t i = 0; i < NUM_ENCODERS; i++) {
|
||||
palEnableLineEvent(encoders_pad_a[i], PAL_EVENT_MODE_BOTH_EDGES);
|
||||
palEnableLineEvent(encoders_pad_b[i], PAL_EVENT_MODE_BOTH_EDGES);
|
||||
}
|
||||
if (NUM_ENCODERS > 0) {
|
||||
palSetLineCallback(encoders_pad_a[0], encoder0_pad_cb, NULL);
|
||||
palSetLineCallback(encoders_pad_b[0], encoder0_pad_cb, NULL);
|
||||
}
|
||||
if (NUM_ENCODERS > 1) {
|
||||
palSetLineCallback(encoders_pad_a[1], encoder1_pad_cb, NULL);
|
||||
palSetLineCallback(encoders_pad_b[1], encoder1_pad_cb, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void keyboard_post_init_kb(void) {
|
||||
if (is_keyboard_left()) {
|
||||
setPinOutput(A0);
|
||||
writePinHigh(A0);
|
||||
} else {
|
||||
if ((analogReadPin_my(B0) > 1000) || (analogReadPin_my(B1) > 1000)) {
|
||||
setPinInput(A11);
|
||||
setPinInput(A12);
|
||||
}
|
||||
}
|
||||
#if defined(ENCODER_ENABLE) && defined(PAL_USE_CALLBACKS)
|
||||
encoder_interrupt_init();
|
||||
#endif
|
||||
// allow user keymaps to do custom post_init
|
||||
keyboard_post_init_user();
|
||||
}
|
||||
|
|
|
@ -7,9 +7,6 @@ EXTRAKEY_ENABLE = yes # Audio control and System control
|
|||
CONSOLE_ENABLE = no # Console for debug
|
||||
COMMAND_ENABLE = no # Commands for debug and configuration
|
||||
NKRO_ENABLE = yes # Enable USB N-key Rollover
|
||||
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
|
||||
RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
|
||||
AUDIO_ENABLE = no # Audio output
|
||||
ENCODER_ENABLE = yes # Enable Encoder
|
||||
DIP_SWITCH_ENABLE = yes
|
||||
RGB_MATRIX_ENABLE = yes
|
||||
|
|
|
@ -21,18 +21,7 @@
|
|||
// - just mirroring `KC_NO` in the `LAYOUT`
|
||||
// macro to keep it simple
|
||||
const matrix_row_t matrix_mask[] = {
|
||||
0b011111111,
|
||||
0b011111111,
|
||||
0b011111111,
|
||||
0b001111111,
|
||||
0b011111101,
|
||||
0b001011111,
|
||||
0b111111111,
|
||||
0b101111111,
|
||||
0b111111111,
|
||||
0b110111111,
|
||||
0b010111111,
|
||||
0b111011110,
|
||||
0b011111111, 0b011111111, 0b011111111, 0b001111111, 0b011111101, 0b001011111, 0b111111111, 0b101111111, 0b111111111, 0b110111111, 0b010111111, 0b111011110,
|
||||
};
|
||||
|
||||
#ifdef DIP_SWITCH_ENABLE
|
||||
|
@ -47,6 +36,87 @@ bool dip_switch_update_kb(uint8_t index, bool active) {
|
|||
}
|
||||
#endif
|
||||
|
||||
void restart_usb_driver(USBDriver *usbp) {
|
||||
(void)usbp;
|
||||
#define ADC_BUFFER_DEPTH 1
|
||||
#define ADC_NUM_CHANNELS 1
|
||||
#define ADC_SAMPLING_RATE ADC_SMPR_SMP_12P5
|
||||
#define ADC_RESOLUTION ADC_CFGR_RES_10BITS
|
||||
|
||||
static int16_t analogReadPin_my(pin_t pin) {
|
||||
ADCConfig adcCfg = {};
|
||||
adcsample_t sampleBuffer[ADC_NUM_CHANNELS * ADC_BUFFER_DEPTH];
|
||||
ADCDriver *targetDriver = &ADCD1;
|
||||
ADCConversionGroup adcConversionGroup = {
|
||||
.circular = FALSE,
|
||||
.num_channels = (uint16_t)(ADC_NUM_CHANNELS),
|
||||
.cfgr = ADC_RESOLUTION,
|
||||
};
|
||||
|
||||
palSetLineMode(pin, PAL_MODE_INPUT_ANALOG);
|
||||
switch (pin) {
|
||||
case B0:
|
||||
adcConversionGroup.smpr[2] = ADC_SMPR2_SMP_AN15(ADC_SAMPLING_RATE);
|
||||
adcConversionGroup.sqr[0] = ADC_SQR1_SQ1_N(ADC_CHANNEL_IN15);
|
||||
sampleBuffer[0] = 0;
|
||||
break;
|
||||
case B1:
|
||||
adcConversionGroup.smpr[2] = ADC_SMPR2_SMP_AN16(ADC_SAMPLING_RATE);
|
||||
adcConversionGroup.sqr[0] = ADC_SQR1_SQ1_N(ADC_CHANNEL_IN16);
|
||||
sampleBuffer[0] = 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
adcStart(targetDriver, &adcCfg);
|
||||
if (adcConvert(targetDriver, &adcConversionGroup, &sampleBuffer[0], ADC_BUFFER_DEPTH) != MSG_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return *sampleBuffer;
|
||||
}
|
||||
|
||||
#if defined(ENCODER_ENABLE) && defined(PAL_USE_CALLBACKS)
|
||||
|
||||
void encoder_pad_cb(void *param) {
|
||||
encoder_inerrupt_read((uint32_t)param & 0XFF);
|
||||
}
|
||||
|
||||
void encoder_interrupt_init(void) {
|
||||
if (is_keyboard_left()) {
|
||||
pin_t encoders_pad_a_left[NUM_ENCODERS_LEFT] = ENCODERS_PAD_A;
|
||||
pin_t encoders_pad_b_left[NUM_ENCODERS_LEFT] = ENCODERS_PAD_B;
|
||||
for (uint32_t i = 0; i < NUM_ENCODERS_LEFT; i++) {
|
||||
palEnableLineEvent(encoders_pad_a_left[i], PAL_EVENT_MODE_BOTH_EDGES);
|
||||
palEnableLineEvent(encoders_pad_b_left[i], PAL_EVENT_MODE_BOTH_EDGES);
|
||||
palSetLineCallback(encoders_pad_a_left[i], encoder_pad_cb, (void *)i);
|
||||
palSetLineCallback(encoders_pad_b_left[i], encoder_pad_cb, (void *)i);
|
||||
}/* */
|
||||
} else {
|
||||
pin_t encoders_pad_a_right[NUM_ENCODERS_RIGHT] = ENCODERS_PAD_A_RIGHT;
|
||||
pin_t encoders_pad_b_right[NUM_ENCODERS_RIGHT] = ENCODERS_PAD_A_RIGHT;
|
||||
for (uint32_t i = 0; i < NUM_ENCODERS_RIGHT; i++) {
|
||||
palEnableLineEvent(encoders_pad_a_right[i], PAL_EVENT_MODE_BOTH_EDGES);
|
||||
palEnableLineEvent(encoders_pad_b_right[i], PAL_EVENT_MODE_BOTH_EDGES);
|
||||
palSetLineCallback(encoders_pad_a_right[i], encoder_pad_cb, (void *)i);
|
||||
palSetLineCallback(encoders_pad_b_right[i], encoder_pad_cb, (void *)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void keyboard_post_init_kb(void) {
|
||||
if (is_keyboard_left()) {
|
||||
setPinOutput(A0);
|
||||
writePinHigh(A0);
|
||||
} else {
|
||||
if ((analogReadPin_my(B0) > 1000) || (analogReadPin_my(B1) > 1000)) {
|
||||
setPinInput(A11);
|
||||
setPinInput(A12);
|
||||
}
|
||||
}
|
||||
#if defined(ENCODER_ENABLE) && defined(PAL_USE_CALLBACKS)
|
||||
encoder_interrupt_init();
|
||||
#endif
|
||||
// allow user keymaps to do custom post_init
|
||||
keyboard_post_init_user();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user