feat: adds pairing key
This commit is contained in:
committed by
Florian Didron
parent
40e9813ba2
commit
f3edef8c69
@@ -288,6 +288,10 @@ ifeq ($(strip $(USB_HID_ENABLE)), yes)
|
|||||||
include $(TMK_DIR)/protocol/usb_hid.mk
|
include $(TMK_DIR)/protocol/usb_hid.mk
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(strip $(WEBUSB_ENABLE)), yes)
|
||||||
|
SRC += $(TMK_DIR)/common/webusb.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(strip $(ENCODER_ENABLE)), yes)
|
ifeq ($(strip $(ENCODER_ENABLE)), yes)
|
||||||
SRC += $(QUANTUM_DIR)/encoder.c
|
SRC += $(QUANTUM_DIR)/encoder.c
|
||||||
OPT_DEFS += -DENCODER_ENABLE
|
OPT_DEFS += -DENCODER_ENABLE
|
||||||
|
|||||||
@@ -57,6 +57,10 @@
|
|||||||
# include "encoder.h"
|
# include "encoder.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WEBUSB_ENABLE
|
||||||
|
# include "webusb.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
# ifndef GOODBYE_SONG
|
# ifndef GOODBYE_SONG
|
||||||
# define GOODBYE_SONG SONG(GOODBYE_SOUND)
|
# define GOODBYE_SONG SONG(GOODBYE_SOUND)
|
||||||
@@ -712,6 +716,13 @@ bool process_record_quantum(keyrecord_t *record) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef WEBUSB_ENABLE
|
||||||
|
case WEBUSB_PAIR:
|
||||||
|
if (record->event.pressed) {
|
||||||
|
webusb_state.paired = true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -503,6 +503,9 @@ enum quantum_keycodes {
|
|||||||
MAGIC_UNSWAP_CTL_GUI,
|
MAGIC_UNSWAP_CTL_GUI,
|
||||||
MAGIC_TOGGLE_CTL_GUI,
|
MAGIC_TOGGLE_CTL_GUI,
|
||||||
|
|
||||||
|
#ifdef WEBUSB_ENABLE
|
||||||
|
WEBUSB_PAIR,
|
||||||
|
#endif
|
||||||
// always leave at the end
|
// always leave at the end
|
||||||
SAFE_RANGE
|
SAFE_RANGE
|
||||||
};
|
};
|
||||||
|
|||||||
24
tmk_core/common/webusb.c
Normal file
24
tmk_core/common/webusb.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include "webusb.h"
|
||||||
|
#include "wait.h"
|
||||||
|
|
||||||
|
webusb_state_t webusb_state = {
|
||||||
|
.paired = false,
|
||||||
|
.pairing = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
void webusb_set_pairing_state() {
|
||||||
|
webusb_state.pairing = true;
|
||||||
|
uint8_t tick = 0;
|
||||||
|
do {
|
||||||
|
tick++;
|
||||||
|
wait_ms(1000);
|
||||||
|
//TODO Blink some leds
|
||||||
|
} while(webusb_state.paired == false && tick <= 30);
|
||||||
|
webusb_state.pairing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void webusb_error(uint8_t code) {
|
||||||
|
uint8_t buffer[1];
|
||||||
|
buffer[0] = code;
|
||||||
|
webusb_send(buffer, 1);
|
||||||
|
}
|
||||||
24
tmk_core/common/webusb.h
Normal file
24
tmk_core/common/webusb.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
void webusb_receive(uint8_t *data, uint8_t length);
|
||||||
|
void webusb_send(uint8_t *data, uint8_t length);
|
||||||
|
void webusb_error(uint8_t);
|
||||||
|
void webusb_set_pairing_state(void);
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
bool paired;
|
||||||
|
bool pairing;
|
||||||
|
} webusb_state_t;
|
||||||
|
|
||||||
|
extern webusb_state_t webusb_state;
|
||||||
|
|
||||||
|
enum Webusb_Status_Code {
|
||||||
|
WEBUSB_STATUS_NOT_PAIRED = -1,
|
||||||
|
WEBUSB_STATUS_OK,
|
||||||
|
WEBUSB_STATUS_UNKNOWN_COMMAND,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -37,6 +37,9 @@
|
|||||||
extern keymap_config_t keymap_config;
|
extern keymap_config_t keymap_config;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WEBUSB_ENABLE
|
||||||
|
#include "webusb.h"
|
||||||
|
#endif
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* Global interface variables and declarations
|
* Global interface variables and declarations
|
||||||
* ---------------------------------------------------------
|
* ---------------------------------------------------------
|
||||||
@@ -880,8 +883,13 @@ void webusb_task(void) {
|
|||||||
do {
|
do {
|
||||||
size_t size = chnReadTimeout(&drivers.webusb_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
|
size_t size = chnReadTimeout(&drivers.webusb_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
if(webusb_state.paired == true) {
|
||||||
webusb_receive(buffer, size);
|
webusb_receive(buffer, size);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
webusb_error(WEBUSB_STATUS_NOT_PAIRED);
|
||||||
|
}
|
||||||
|
}
|
||||||
} while (size > 0);
|
} while (size > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,10 @@ extern keymap_config_t keymap_config;
|
|||||||
# include "raw_hid.h"
|
# include "raw_hid.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WEBUSB_ENABLE
|
||||||
|
#include "webusb.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
uint8_t keyboard_idle = 0;
|
uint8_t keyboard_idle = 0;
|
||||||
/* 0: Boot Protocol, 1: Report Protocol(default) */
|
/* 0: Boot Protocol, 1: Report Protocol(default) */
|
||||||
uint8_t keyboard_protocol = 1;
|
uint8_t keyboard_protocol = 1;
|
||||||
@@ -307,8 +311,13 @@ static void webusb_task(void) {
|
|||||||
Endpoint_ClearOUT();
|
Endpoint_ClearOUT();
|
||||||
|
|
||||||
if (data_read) {
|
if (data_read) {
|
||||||
|
if(webusb_state.paired == true) {
|
||||||
webusb_receive(data, sizeof(data));
|
webusb_receive(data, sizeof(data));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
webusb_error(WEBUSB_STATUS_NOT_PAIRED);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
#include "report.h"
|
#include "report.h"
|
||||||
#include "usb_descriptor.h"
|
#include "usb_descriptor.h"
|
||||||
#ifdef WEBUSB_ENABLE
|
#ifdef WEBUSB_ENABLE
|
||||||
#include "webusb.h"
|
#include "webusb_descriptor.h"
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* HID report descriptors
|
* HID report descriptors
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
# include "hal.h"
|
# include "hal.h"
|
||||||
#endif
|
#endif
|
||||||
#ifdef WEBUSB_ENABLE
|
#ifdef WEBUSB_ENABLE
|
||||||
#include "webusb.h"
|
#include "webusb_descriptor.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void webusb_receive(uint8_t *data, uint8_t length);
|
|
||||||
|
|
||||||
void webusb_send(uint8_t *data, uint8_t length);
|
|
||||||
|
|
||||||
#ifndef WORD_TO_BYTES_LE
|
#ifndef WORD_TO_BYTES_LE
|
||||||
# define WORD_TO_BYTES_LE(n) n % 256, (n / 256) % 256
|
# define WORD_TO_BYTES_LE(n) n % 256, (n / 256) % 256
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user