Merge remote-tracking branch 'qmk/master' into vial
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2011 Jun WAKO <wakojun@gmail.com>
|
||||
Copyright 2011-19 Jun WAKO <wakojun@gmail.com>
|
||||
Copyright 2013 Shay Green <gblargg@gmail.com>
|
||||
|
||||
This software is licensed with a Modified BSD License.
|
||||
@@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include "adb.h"
|
||||
#include "print.h"
|
||||
|
||||
// GCC doesn't inline functions normally
|
||||
#define data_lo() (ADB_DDR |= (1 << ADB_DATA_BIT))
|
||||
@@ -59,7 +60,6 @@ static inline void place_bit1(void);
|
||||
static inline void send_byte(uint8_t data);
|
||||
static inline uint16_t wait_data_lo(uint16_t us);
|
||||
static inline uint16_t wait_data_hi(uint16_t us);
|
||||
static inline uint16_t adb_host_dev_recv(uint8_t device);
|
||||
|
||||
void adb_host_init(void) {
|
||||
ADB_PORT &= ~(1 << ADB_DATA_BIT);
|
||||
@@ -81,119 +81,164 @@ bool adb_host_psw(void) { return psw_in(); }
|
||||
* <http://geekhack.org/index.php?topic=14290.msg1068919#msg1068919>
|
||||
* <http://geekhack.org/index.php?topic=14290.msg1070139#msg1070139>
|
||||
*/
|
||||
|
||||
// ADB Bit Cells
|
||||
//
|
||||
// bit cell time: 70-130us
|
||||
// low part of bit0: 60-70% of bit cell
|
||||
// low part of bit1: 30-40% of bit cell
|
||||
//
|
||||
// bit cell time 70us 130us
|
||||
// --------------------------------------------
|
||||
// low part of bit0 42-49 78-91
|
||||
// high part of bit0 21-28 39-52
|
||||
// low part of bit1 21-28 39-52
|
||||
// high part of bit1 42-49 78-91
|
||||
//
|
||||
//
|
||||
// bit0:
|
||||
// 70us bit cell:
|
||||
// ____________~~~~~~
|
||||
// 42-49 21-28
|
||||
//
|
||||
// 130us bit cell:
|
||||
// ____________~~~~~~
|
||||
// 78-91 39-52
|
||||
//
|
||||
// bit1:
|
||||
// 70us bit cell:
|
||||
// ______~~~~~~~~~~~~
|
||||
// 21-28 42-49
|
||||
//
|
||||
// 130us bit cell:
|
||||
// ______~~~~~~~~~~~~
|
||||
// 39-52 78-91
|
||||
//
|
||||
// [from Apple IIgs Hardware Reference Second Edition]
|
||||
|
||||
enum { ADDR_KEYB = 0x20, ADDR_MOUSE = 0x30 };
|
||||
|
||||
uint16_t adb_host_kbd_recv(void) { return adb_host_dev_recv(ADDR_KEYB); }
|
||||
uint16_t adb_host_kbd_recv(void) { return adb_host_talk(ADB_ADDR_KEYBOARD, ADB_REG_0); }
|
||||
|
||||
#ifdef ADB_MOUSE_ENABLE
|
||||
void adb_mouse_init(void) { return; }
|
||||
__attribute__((weak)) void adb_mouse_init(void) { return; }
|
||||
|
||||
uint16_t adb_host_mouse_recv(void) { return adb_host_dev_recv(ADDR_MOUSE); }
|
||||
__attribute__((weak)) void adb_mouse_task(void) { return; }
|
||||
|
||||
uint16_t adb_host_mouse_recv(void) { return adb_host_talk(ADB_ADDR_MOUSE, ADB_REG_0); }
|
||||
#endif
|
||||
|
||||
static inline uint16_t adb_host_dev_recv(uint8_t device) {
|
||||
uint16_t data = 0;
|
||||
// This sends Talk command to read data from register and returns length of the data.
|
||||
uint8_t adb_host_talk_buf(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t len) {
|
||||
for (int8_t i = 0; i < len; i++) buf[i] = 0;
|
||||
|
||||
cli();
|
||||
attention();
|
||||
send_byte(device | 0x0C); // Addr:Keyboard(0010)/Mouse(0011), Cmd:Talk(11), Register0(00)
|
||||
place_bit0(); // Stopbit(0)
|
||||
send_byte((addr << 4) | ADB_CMD_TALK | reg);
|
||||
place_bit0(); // Stopbit(0)
|
||||
// TODO: Service Request(Srq):
|
||||
// Device holds low part of comannd stopbit for 140-260us
|
||||
//
|
||||
// Command:
|
||||
// ......._ ______________________ ___ ............_ -------
|
||||
// | | | | | | |
|
||||
// Command | | | | | Data bytes | |
|
||||
// ........|___| | 140-260 |__| |_............|___|
|
||||
// |stop0 | Tlt Stop-to-Start |start1| |stop0 |
|
||||
//
|
||||
// Command without data:
|
||||
// ......._ __________________________
|
||||
// | |
|
||||
// Command | |
|
||||
// ........|___| | 140-260 |
|
||||
// |stop0 | Tlt Stop-to-Start |
|
||||
//
|
||||
// Service Request:
|
||||
// ......._ ______ ___ ............_ -------
|
||||
// | 140-260 | | | | | |
|
||||
// Command | Service Request | | | | Data bytes | |
|
||||
// ........|___________________| |__| |_............|___|
|
||||
// |stop0 | |start1| |stop0 |
|
||||
// ......._ __________
|
||||
// | 140-260 |
|
||||
// Command | Service Request |
|
||||
// ........|___________________|
|
||||
// |stop0 |
|
||||
// This can be happened?
|
||||
// ......._ ______________________ ___ ............_ -----
|
||||
// | | | | | | 140-260 |
|
||||
// Command | | | | | Data bytes | Service Request |
|
||||
// ........|___| | 140-260 |__| |_............|_________________|
|
||||
// |stop0 | Tlt Stop-to-Start |start1| |stop0 |
|
||||
//
|
||||
// "Service requests are issued by the devices during a very specific time at the
|
||||
// end of the reception of the command packet.
|
||||
// If a device in need of service issues a service request, it must do so within
|
||||
// the 65 µs of the Stop Bit’s low time and maintain the line low for a total of 300 µs."
|
||||
//
|
||||
// "A device sends a Service Request signal by holding the bus low during the low
|
||||
// portion of the stop bit of any command or data transaction. The device must lengthen
|
||||
// the stop by a minimum of 140 J.lS beyond its normal duration, as shown in Figure 8-15."
|
||||
// http://ww1.microchip.com/downloads/en/AppNotes/00591b.pdf
|
||||
if (!wait_data_hi(500)) { // Service Request(310us Adjustable Keyboard): just ignored
|
||||
xprintf("R");
|
||||
sei();
|
||||
return -30; // something wrong
|
||||
return 0;
|
||||
}
|
||||
if (!wait_data_lo(500)) { // Tlt/Stop to Start(140-260us)
|
||||
sei();
|
||||
return 0; // No data to send
|
||||
return 0; // No data from device(not error);
|
||||
}
|
||||
|
||||
uint8_t n = 17; // start bit + 16 data bits
|
||||
// start bit(1)
|
||||
if (!wait_data_hi(40)) {
|
||||
xprintf("S");
|
||||
sei();
|
||||
return 0;
|
||||
}
|
||||
if (!wait_data_lo(100)) {
|
||||
xprintf("s");
|
||||
sei();
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t n = 0; // bit count
|
||||
do {
|
||||
//
|
||||
// |<- bit_cell_max(130) ->|
|
||||
// | |<- lo ->|
|
||||
// | | |<-hi->|
|
||||
// _______
|
||||
// | | |
|
||||
// | 130-lo | lo-hi |
|
||||
// |________| |
|
||||
//
|
||||
uint8_t lo = (uint8_t)wait_data_hi(130);
|
||||
if (!lo) goto error;
|
||||
if (!lo) goto error; // no more bit or after stop bit
|
||||
|
||||
uint8_t hi = (uint8_t)wait_data_lo(lo);
|
||||
if (!hi) goto error;
|
||||
if (!hi) goto error; // stop bit extedned by Srq?
|
||||
|
||||
hi = lo - hi;
|
||||
lo = 130 - lo;
|
||||
if (n / 8 >= len) continue; // can't store in buf
|
||||
|
||||
data <<= 1;
|
||||
if (lo < hi) {
|
||||
data |= 1;
|
||||
} else if (n == 17) {
|
||||
sei();
|
||||
return -20;
|
||||
buf[n / 8] <<= 1;
|
||||
if ((130 - lo) < (lo - hi)) {
|
||||
buf[n / 8] |= 1;
|
||||
}
|
||||
} while (--n);
|
||||
|
||||
// Stop bit can't be checked normally since it could have service request lenghtening
|
||||
// and its high state never goes low.
|
||||
if (!wait_data_hi(351) || wait_data_lo(91)) {
|
||||
sei();
|
||||
return -21;
|
||||
}
|
||||
sei();
|
||||
return data;
|
||||
} while (++n);
|
||||
|
||||
error:
|
||||
sei();
|
||||
return -n;
|
||||
return n / 8;
|
||||
}
|
||||
|
||||
void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l) {
|
||||
uint16_t adb_host_talk(uint8_t addr, uint8_t reg) {
|
||||
uint8_t len;
|
||||
uint8_t buf[8];
|
||||
len = adb_host_talk_buf(addr, reg, buf, 8);
|
||||
if (len != 2) return 0;
|
||||
return (buf[0] << 8 | buf[1]);
|
||||
}
|
||||
|
||||
void adb_host_listen_buf(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t len) {
|
||||
cli();
|
||||
attention();
|
||||
send_byte(cmd);
|
||||
place_bit0(); // Stopbit(0)
|
||||
send_byte((addr << 4) | ADB_CMD_LISTEN | reg);
|
||||
place_bit0(); // Stopbit(0)
|
||||
// TODO: Service Request
|
||||
_delay_us(200); // Tlt/Stop to Start
|
||||
place_bit1(); // Startbit(1)
|
||||
send_byte(data_h);
|
||||
send_byte(data_l);
|
||||
for (int8_t i = 0; i < len; i++) {
|
||||
send_byte(buf[i]);
|
||||
// xprintf("%02X ", buf[i]);
|
||||
}
|
||||
place_bit0(); // Stopbit(0);
|
||||
sei();
|
||||
}
|
||||
|
||||
void adb_host_listen(uint8_t addr, uint8_t reg, uint8_t data_h, uint8_t data_l) {
|
||||
uint8_t buf[2] = {data_h, data_l};
|
||||
adb_host_listen_buf(addr, reg, buf, 2);
|
||||
}
|
||||
|
||||
void adb_host_flush(uint8_t addr) {
|
||||
cli();
|
||||
attention();
|
||||
send_byte((addr << 4) | ADB_CMD_FLUSH);
|
||||
place_bit0(); // Stopbit(0)
|
||||
_delay_us(200); // Tlt/Stop to Start
|
||||
sei();
|
||||
}
|
||||
|
||||
// send state of LEDs
|
||||
void adb_host_kbd_led(uint8_t led) {
|
||||
// Addr:Keyboard(0010), Cmd:Listen(10), Register2(10)
|
||||
// send upper byte (not used)
|
||||
// send lower byte (bit2: ScrollLock, bit1: CapsLock, bit0:
|
||||
adb_host_listen(0x2A, 0, led & 0x07);
|
||||
// Listen Register2
|
||||
// upper byte: not used
|
||||
// lower byte: bit2=ScrollLock, bit1=CapsLock, bit0=NumLock
|
||||
adb_host_listen(ADB_ADDR_KEYBOARD, ADB_REG_2, 0, led & 0x07);
|
||||
}
|
||||
|
||||
#ifdef ADB_PSW_BIT
|
||||
@@ -327,7 +372,7 @@ Commands
|
||||
|
||||
bits commands
|
||||
------------------------------------------------------
|
||||
- - - - 0 0 0 0 Send Request(reset all devices)
|
||||
- - - - 0 0 0 0 Send Reset(reset all devices)
|
||||
A A A A 0 0 0 1 Flush(reset a device)
|
||||
- - - - 0 0 1 0 Reserved
|
||||
- - - - 0 0 1 1 Reserved
|
||||
@@ -435,5 +480,56 @@ Keyboard LEDs & state of keys(Register2)
|
||||
| +----------------------------- Delete
|
||||
+------------------------------- Reserved
|
||||
|
||||
Address, Handler ID and bits(Register3)
|
||||
1514131211 . . 8 7 . . . . . . 0
|
||||
| | | | | | | | | | | | | | | |
|
||||
| | | | | | | | +-+-+-+-+-+-+-+- Handler ID
|
||||
| | | | +-+-+-+----------------- Address
|
||||
| | | +------------------------- 0
|
||||
| | +--------------------------- Service request enable(1 = enabled)
|
||||
| +----------------------------- Exceptional event(alwyas 1 if not used)
|
||||
+------------------------------- 0
|
||||
|
||||
ADB Bit Cells
|
||||
bit cell time: 70-130us
|
||||
low part of bit0: 60-70% of bit cell
|
||||
low part of bit1: 30-40% of bit cell
|
||||
|
||||
bit cell time 70us 130us
|
||||
--------------------------------------------
|
||||
low part of bit0 42-49 78-91
|
||||
high part of bit0 21-28 39-52
|
||||
low part of bit1 21-28 39-52
|
||||
high part of bit1 42-49 78-91
|
||||
|
||||
|
||||
bit0:
|
||||
70us bit cell:
|
||||
____________~~~~~~
|
||||
42-49 21-28
|
||||
|
||||
130us bit cell:
|
||||
____________~~~~~~
|
||||
78-91 39-52
|
||||
|
||||
bit1:
|
||||
70us bit cell:
|
||||
______~~~~~~~~~~~~
|
||||
21-28 42-49
|
||||
|
||||
130us bit cell:
|
||||
______~~~~~~~~~~~~
|
||||
39-52 78-91
|
||||
|
||||
[from Apple IIgs Hardware Reference Second Edition]
|
||||
|
||||
Keyboard Handle ID
|
||||
Apple Standard Keyboard M0116: 0x01
|
||||
Apple Extended Keyboard M0115: 0x02
|
||||
Apple Extended Keyboard II M3501: 0x02
|
||||
Apple Adjustable Keybaord: 0x10
|
||||
|
||||
http://lxr.free-electrons.com/source/drivers/macintosh/adbhid.c?v=4.4#L802
|
||||
|
||||
END_OF_ADB
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2011 Jun WAKO <wakojun@gmail.com>
|
||||
Copyright 2011-19 Jun WAKO <wakojun@gmail.com>
|
||||
|
||||
This software is licensed with a Modified BSD License.
|
||||
All of this is supposed to be Free Software, Open Source, DFSG-free,
|
||||
@@ -35,8 +35,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ADB_H
|
||||
#define ADB_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -48,14 +47,60 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#define ADB_POWER 0x7F
|
||||
#define ADB_CAPS 0x39
|
||||
|
||||
/* ADB commands */
|
||||
// Default Address
|
||||
#define ADB_ADDR_0 0
|
||||
#define ADB_ADDR_DONGLE 1
|
||||
#define ADB_ADDR_KEYBOARD 2
|
||||
#define ADB_ADDR_MOUSE 3
|
||||
#define ADB_ADDR_TABLET 4
|
||||
#define ADB_ADDR_APPLIANCE 7
|
||||
#define ADB_ADDR_8 8
|
||||
#define ADB_ADDR_9 9
|
||||
#define ADB_ADDR_10 10
|
||||
#define ADB_ADDR_11 11
|
||||
#define ADB_ADDR_12 12
|
||||
#define ADB_ADDR_13 13
|
||||
#define ADB_ADDR_14 14
|
||||
#define ADB_ADDR_15 15
|
||||
// for temporary purpose, do not use for polling
|
||||
#define ADB_ADDR_TMP 15
|
||||
#define ADB_ADDR_MOUSE_POLL 10
|
||||
// Command Type
|
||||
#define ADB_CMD_RESET 0
|
||||
#define ADB_CMD_FLUSH 1
|
||||
#define ADB_CMD_LISTEN 8
|
||||
#define ADB_CMD_TALK 12
|
||||
// Register
|
||||
#define ADB_REG_0 0
|
||||
#define ADB_REG_1 1
|
||||
#define ADB_REG_2 2
|
||||
#define ADB_REG_3 3
|
||||
|
||||
/* ADB keyboard handler id */
|
||||
#define ADB_HANDLER_STD 0x01 /* IIGS, M0116 */
|
||||
#define ADB_HANDLER_AEK 0x02 /* M0115, M3501 */
|
||||
#define ADB_HANDLER_AEK_RMOD 0x03 /* M0115, M3501, alternate mode enableing right modifiers */
|
||||
#define ADB_HANDLER_STD_ISO 0x04 /* M0118, ISO swapping keys */
|
||||
#define ADB_HANDLER_AEK_ISO 0x05 /* M0115, M3501, ISO swapping keys */
|
||||
#define ADB_HANDLER_M1242_ANSI 0x10 /* Adjustable keyboard */
|
||||
#define ADB_HANDLER_CLASSIC1_MOUSE 0x01
|
||||
#define ADB_HANDLER_CLASSIC2_MOUSE 0x02
|
||||
#define ADB_HANDLER_EXTENDED_MOUSE 0x04
|
||||
#define ADB_HANDLER_TURBO_MOUSE 0x32
|
||||
|
||||
// ADB host
|
||||
void adb_host_init(void);
|
||||
bool adb_host_psw(void);
|
||||
uint16_t adb_host_talk(uint8_t addr, uint8_t reg);
|
||||
uint8_t adb_host_talk_buf(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t len);
|
||||
void adb_host_listen(uint8_t addr, uint8_t reg, uint8_t data_h, uint8_t data_l);
|
||||
void adb_host_listen_buf(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t len);
|
||||
void adb_host_flush(uint8_t addr);
|
||||
void adb_host_kbd_led(uint8_t led);
|
||||
uint16_t adb_host_kbd_recv(void);
|
||||
uint16_t adb_host_mouse_recv(void);
|
||||
void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l);
|
||||
void adb_host_kbd_led(uint8_t led);
|
||||
void adb_mouse_task(void);
|
||||
void adb_mouse_init(void);
|
||||
|
||||
#endif
|
||||
// ADB Mouse
|
||||
void adb_mouse_task(void);
|
||||
void adb_mouse_init(void);
|
||||
|
||||
@@ -4,9 +4,9 @@ SRC += $(ARM_ATSAM_DIR)/adc.c
|
||||
SRC += $(ARM_ATSAM_DIR)/clks.c
|
||||
SRC += $(ARM_ATSAM_DIR)/d51_util.c
|
||||
SRC += $(ARM_ATSAM_DIR)/i2c_master.c
|
||||
ifeq ($(RGB_MATRIX_ENABLE),custom)
|
||||
SRC += $(ARM_ATSAM_DIR)/led_matrix_programs.c
|
||||
SRC += $(ARM_ATSAM_DIR)/led_matrix.c
|
||||
ifeq ($(RGB_MATRIX_DRIVER),custom)
|
||||
SRC += $(ARM_ATSAM_DIR)/md_rgb_matrix_programs.c
|
||||
SRC += $(ARM_ATSAM_DIR)/md_rgb_matrix.c
|
||||
endif
|
||||
SRC += $(ARM_ATSAM_DIR)/main_arm_atsam.c
|
||||
SRC += $(ARM_ATSAM_DIR)/spi.c
|
||||
|
||||
@@ -35,7 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# include "main_arm_atsam.h"
|
||||
# ifdef RGB_MATRIX_ENABLE
|
||||
# include "led_matrix.h"
|
||||
# include "md_rgb_matrix.h"
|
||||
# include "rgb_matrix.h"
|
||||
# endif
|
||||
# include "issi3733_driver.h"
|
||||
|
||||
@@ -28,6 +28,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# define I2C_LED_USE_DMA 1 // Set 1 to use background DMA transfers for leds, Set 0 to use inline software transfers
|
||||
|
||||
DmacDescriptor dmac_desc;
|
||||
DmacDescriptor dmac_desc_wb;
|
||||
|
||||
static uint8_t i2c_led_q[I2C_Q_SIZE]; // I2C queue circular buffer
|
||||
static uint8_t i2c_led_q_s; // Start of circular buffer
|
||||
static uint8_t i2c_led_q_e; // End of circular buffer
|
||||
|
||||
@@ -24,8 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# include "issi3733_driver.h"
|
||||
# include "config.h"
|
||||
|
||||
__attribute__((__aligned__(16))) DmacDescriptor dmac_desc;
|
||||
__attribute__((__aligned__(16))) DmacDescriptor dmac_desc_wb;
|
||||
extern __attribute__((__aligned__(16))) DmacDescriptor dmac_desc;
|
||||
extern __attribute__((__aligned__(16))) DmacDescriptor dmac_desc_wb;
|
||||
|
||||
uint8_t I2C3733_Init_Control(void);
|
||||
uint8_t I2C3733_Init_Drivers(void);
|
||||
|
||||
@@ -15,16 +15,17 @@ 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 "arm_atsam_protocol.h"
|
||||
#include "tmk_core/common/led.h"
|
||||
#include "rgb_matrix.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
# include "arm_atsam_protocol.h"
|
||||
# include "led.h"
|
||||
# include "rgb_matrix.h"
|
||||
# include <string.h>
|
||||
# include <math.h>
|
||||
|
||||
#ifdef USE_MASSDROP_CONFIGURATOR
|
||||
# ifdef USE_MASSDROP_CONFIGURATOR
|
||||
__attribute__((weak)) led_instruction_t led_instructions[] = {{.end = 1}};
|
||||
static void led_matrix_massdrop_config_override(int i);
|
||||
#endif // USE_MASSDROP_CONFIGURATOR
|
||||
static void md_rgb_matrix_config_override(int i);
|
||||
# endif // USE_MASSDROP_CONFIGURATOR
|
||||
|
||||
void SERCOM1_0_Handler(void) {
|
||||
if (SERCOM1->I2CM.INTFLAG.bit.ERROR) {
|
||||
@@ -58,17 +59,17 @@ RGB led_buffer[ISSI3733_LED_COUNT];
|
||||
uint8_t gcr_desired;
|
||||
uint8_t gcr_actual;
|
||||
uint8_t gcr_actual_last;
|
||||
#ifdef USE_MASSDROP_CONFIGURATOR
|
||||
# ifdef USE_MASSDROP_CONFIGURATOR
|
||||
uint8_t gcr_breathe;
|
||||
float breathe_mult;
|
||||
float pomod;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
#define ACT_GCR_NONE 0
|
||||
#define ACT_GCR_INC 1
|
||||
#define ACT_GCR_DEC 2
|
||||
# define ACT_GCR_NONE 0
|
||||
# define ACT_GCR_INC 1
|
||||
# define ACT_GCR_DEC 2
|
||||
|
||||
#define LED_GCR_STEP_AUTO 2
|
||||
# define LED_GCR_STEP_AUTO 2
|
||||
|
||||
static uint8_t gcr_min_counter;
|
||||
static uint8_t v_5v_cat_hit;
|
||||
@@ -78,11 +79,11 @@ void gcr_compute(void) {
|
||||
uint8_t action = ACT_GCR_NONE;
|
||||
uint8_t gcr_use = gcr_desired;
|
||||
|
||||
#ifdef USE_MASSDROP_CONFIGURATOR
|
||||
# ifdef USE_MASSDROP_CONFIGURATOR
|
||||
if (led_animation_breathing) {
|
||||
gcr_use = gcr_breathe;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
// If the 5v takes a catastrophic hit, disable the LED drivers briefly, assert auto gcr mode, min gcr and let the auto take over
|
||||
if (v_5v < V5_CAT) {
|
||||
@@ -150,7 +151,7 @@ void gcr_compute(void) {
|
||||
gcr_actual -= LED_GCR_STEP_AUTO;
|
||||
gcr_min_counter = 0;
|
||||
|
||||
#ifdef USE_MASSDROP_CONFIGURATOR
|
||||
# ifdef USE_MASSDROP_CONFIGURATOR
|
||||
// If breathe mode is active, the top end can fluctuate if the host can not supply enough current
|
||||
// So set the breathe GCR to where it becomes stable
|
||||
if (led_animation_breathing == 1) {
|
||||
@@ -159,7 +160,7 @@ void gcr_compute(void) {
|
||||
// and the same would happen maybe one or two more times. Therefore I'm favoring
|
||||
// powering through one full breathe and letting gcr settle completely
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,7 +189,7 @@ void issi3733_prepare_arrays(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void led_matrix_prepare(void) {
|
||||
void md_rgb_matrix_prepare(void) {
|
||||
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
|
||||
*led_map[i].rgb.r = 0;
|
||||
*led_map[i].rgb.g = 0;
|
||||
@@ -196,30 +197,30 @@ void led_matrix_prepare(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void led_set_one(int i, uint8_t r, uint8_t g, uint8_t b) {
|
||||
static void led_set_one(int i, uint8_t r, uint8_t g, uint8_t b) {
|
||||
if (i < ISSI3733_LED_COUNT) {
|
||||
#ifdef USE_MASSDROP_CONFIGURATOR
|
||||
led_matrix_massdrop_config_override(i);
|
||||
#else
|
||||
# ifdef USE_MASSDROP_CONFIGURATOR
|
||||
md_rgb_matrix_config_override(i);
|
||||
# else
|
||||
led_buffer[i].r = r;
|
||||
led_buffer[i].g = g;
|
||||
led_buffer[i].b = b;
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
}
|
||||
|
||||
void led_set_all(uint8_t r, uint8_t g, uint8_t b) {
|
||||
static void led_set_all(uint8_t r, uint8_t g, uint8_t b) {
|
||||
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
|
||||
led_set_one(i, r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
void init(void) {
|
||||
static void init(void) {
|
||||
DBGC(DC_LED_MATRIX_INIT_BEGIN);
|
||||
|
||||
issi3733_prepare_arrays();
|
||||
|
||||
led_matrix_prepare();
|
||||
md_rgb_matrix_prepare();
|
||||
|
||||
gcr_min_counter = 0;
|
||||
v_5v_cat_hit = 0;
|
||||
@@ -227,16 +228,16 @@ void init(void) {
|
||||
DBGC(DC_LED_MATRIX_INIT_COMPLETE);
|
||||
}
|
||||
|
||||
void flush(void) {
|
||||
#ifdef USE_MASSDROP_CONFIGURATOR
|
||||
static void flush(void) {
|
||||
# ifdef USE_MASSDROP_CONFIGURATOR
|
||||
if (!led_enabled) {
|
||||
return;
|
||||
} // Prevent calculations and I2C traffic if LED drivers are not enabled
|
||||
#else
|
||||
# else
|
||||
if (!sr_exp_data.bit.SDB_N) {
|
||||
return;
|
||||
} // Prevent calculations and I2C traffic if LED drivers are not enabled
|
||||
#endif
|
||||
# endif
|
||||
|
||||
// Wait for previous transfer to complete
|
||||
while (i2c_led_q_running) {
|
||||
@@ -249,7 +250,7 @@ void flush(void) {
|
||||
*led_map[i].rgb.b = led_buffer[i].b;
|
||||
}
|
||||
|
||||
#ifdef USE_MASSDROP_CONFIGURATOR
|
||||
# ifdef USE_MASSDROP_CONFIGURATOR
|
||||
breathe_mult = 1;
|
||||
|
||||
if (led_animation_breathing) {
|
||||
@@ -275,7 +276,7 @@ void flush(void) {
|
||||
pomod = (uint32_t)pomod % 10000;
|
||||
pomod /= 100.0f;
|
||||
|
||||
#endif // USE_MASSDROP_CONFIGURATOR
|
||||
# endif // USE_MASSDROP_CONFIGURATOR
|
||||
|
||||
uint8_t drvid;
|
||||
|
||||
@@ -290,30 +291,32 @@ void flush(void) {
|
||||
i2c_led_q_run();
|
||||
}
|
||||
|
||||
void led_matrix_indicators(void) {
|
||||
void md_rgb_matrix_indicators(void) {
|
||||
uint8_t kbled = keyboard_leds();
|
||||
if (kbled && rgb_matrix_config.enable) {
|
||||
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
|
||||
if (
|
||||
#if USB_LED_NUM_LOCK_SCANCODE != 255
|
||||
# if USB_LED_NUM_LOCK_SCANCODE != 255
|
||||
(led_map[i].scan == USB_LED_NUM_LOCK_SCANCODE && (kbled & (1 << USB_LED_NUM_LOCK))) ||
|
||||
#endif // NUM LOCK
|
||||
#if USB_LED_CAPS_LOCK_SCANCODE != 255
|
||||
# endif // NUM LOCK
|
||||
# if USB_LED_CAPS_LOCK_SCANCODE != 255
|
||||
(led_map[i].scan == USB_LED_CAPS_LOCK_SCANCODE && (kbled & (1 << USB_LED_CAPS_LOCK))) ||
|
||||
#endif // CAPS LOCK
|
||||
#if USB_LED_SCROLL_LOCK_SCANCODE != 255
|
||||
# endif // CAPS LOCK
|
||||
# if USB_LED_SCROLL_LOCK_SCANCODE != 255
|
||||
(led_map[i].scan == USB_LED_SCROLL_LOCK_SCANCODE && (kbled & (1 << USB_LED_SCROLL_LOCK))) ||
|
||||
#endif // SCROLL LOCK
|
||||
#if USB_LED_COMPOSE_SCANCODE != 255
|
||||
# endif // SCROLL LOCK
|
||||
# if USB_LED_COMPOSE_SCANCODE != 255
|
||||
(led_map[i].scan == USB_LED_COMPOSE_SCANCODE && (kbled & (1 << USB_LED_COMPOSE))) ||
|
||||
#endif // COMPOSE
|
||||
#if USB_LED_KANA_SCANCODE != 255
|
||||
# endif // COMPOSE
|
||||
# if USB_LED_KANA_SCANCODE != 255
|
||||
(led_map[i].scan == USB_LED_KANA_SCANCODE && (kbled & (1 << USB_LED_KANA))) ||
|
||||
#endif // KANA
|
||||
# endif // KANA
|
||||
(0)) {
|
||||
led_buffer[i].r = 255 - led_buffer[i].r;
|
||||
led_buffer[i].g = 255 - led_buffer[i].g;
|
||||
led_buffer[i].b = 255 - led_buffer[i].b;
|
||||
if (rgb_matrix_get_flags() & LED_FLAG_INDICATOR) {
|
||||
led_buffer[i].r = 255 - led_buffer[i].r;
|
||||
led_buffer[i].g = 255 - led_buffer[i].g;
|
||||
led_buffer[i].b = 255 - led_buffer[i].b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,7 +328,7 @@ const rgb_matrix_driver_t rgb_matrix_driver = {.init = init, .flush = flush, .se
|
||||
= Legacy Lighting Support =
|
||||
==============================================================================*/
|
||||
|
||||
#ifdef USE_MASSDROP_CONFIGURATOR
|
||||
# ifdef USE_MASSDROP_CONFIGURATOR
|
||||
// Ported from Massdrop QMK GitHub Repo
|
||||
|
||||
// TODO?: wire these up to keymap.c
|
||||
@@ -395,7 +398,7 @@ static void led_run_pattern(led_setup_t* f, float* ro, float* go, float* bo, flo
|
||||
}
|
||||
}
|
||||
|
||||
static void led_matrix_massdrop_config_override(int i) {
|
||||
static void md_rgb_matrix_config_override(int i) {
|
||||
float ro = 0;
|
||||
float go = 0;
|
||||
float bo = 0;
|
||||
@@ -467,4 +470,5 @@ static void led_matrix_massdrop_config_override(int i) {
|
||||
led_buffer[i].b = (uint8_t)bo;
|
||||
}
|
||||
|
||||
#endif // USE_MASSDROP_CONFIGURATOR
|
||||
# endif // USE_MASSDROP_CONFIGURATOR
|
||||
#endif // RGB_MATRIX_ENABLE
|
||||
@@ -86,7 +86,7 @@ extern uint8_t gcr_actual_last;
|
||||
|
||||
void gcr_compute(void);
|
||||
|
||||
void led_matrix_indicators(void);
|
||||
void md_rgb_matrix_indicators(void);
|
||||
|
||||
/*------------------------- Legacy Lighting Support ------------------------*/
|
||||
|
||||
@@ -15,9 +15,10 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_MASSDROP_CONFIGURATOR
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
# ifdef USE_MASSDROP_CONFIGURATOR
|
||||
|
||||
# include "led_matrix.h"
|
||||
# include "md_rgb_matrix.h"
|
||||
|
||||
// Teal <-> Salmon
|
||||
led_setup_t leds_teal_salmon[] = {
|
||||
@@ -96,4 +97,5 @@ void *led_setups[] = {leds_rainbow_s, leds_rainbow_ns, leds_teal_salmon, leds_ye
|
||||
|
||||
const uint8_t led_setups_count = sizeof(led_setups) / sizeof(led_setups[0]);
|
||||
|
||||
#endif
|
||||
# endif // USE_MASSDROP_CONFIGURATOR
|
||||
#endif // RGB_MATRIX_ENABLE
|
||||
@@ -291,7 +291,7 @@ typedef struct {
|
||||
extern uint8_t udi_hid_kbd_report_set;
|
||||
|
||||
// report buffer (to host)
|
||||
# define UDI_HID_KBD_REPORT_SIZE 8
|
||||
#define UDI_HID_KBD_REPORT_SIZE 8
|
||||
extern uint8_t udi_hid_kbd_report[UDI_HID_KBD_REPORT_SIZE];
|
||||
|
||||
COMPILER_PACK_RESET()
|
||||
@@ -784,7 +784,7 @@ COMPILER_PACK_RESET()
|
||||
COMPILER_PACK_SET(1)
|
||||
|
||||
typedef struct {
|
||||
usb_conf_desc_t conf;
|
||||
usb_conf_desc_t conf;
|
||||
udi_hid_kbd_desc_t hid_kbd;
|
||||
#ifdef MOUSE_ENABLE
|
||||
udi_hid_mou_desc_t hid_mou;
|
||||
|
||||
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define KEYBOARD_EPSIZE 8
|
||||
#define MOUSE_EPSIZE 8
|
||||
#define EXTRAKEY_EPSIZE 8
|
||||
#define RAW_EPSIZE 64
|
||||
#define RAW_EPSIZE 32
|
||||
#define CONSOLE_EPSIZE 32
|
||||
#define NKRO_EPSIZE 32
|
||||
#define MIDI_STREAM_EPSIZE 64
|
||||
|
||||
@@ -120,7 +120,7 @@ UDC_DESC_STORAGE udc_desc_t udc_desc = {
|
||||
.conf.iConfiguration = 0,
|
||||
.conf.bmAttributes = /* USB_CONFIG_ATTR_MUST_SET | */ USB_DEVICE_ATTR,
|
||||
.conf.bMaxPower = USB_CONFIG_MAX_POWER(USB_DEVICE_POWER),
|
||||
.hid_kbd = UDI_HID_KBD_DESC,
|
||||
.hid_kbd = UDI_HID_KBD_DESC,
|
||||
#ifdef RAW_ENABLE
|
||||
.hid_raw = UDI_HID_RAW_DESC,
|
||||
#endif
|
||||
|
||||
@@ -18,4 +18,3 @@ OPT_DEFS += -DFIXED_NUM_CONFIGURATIONS=1
|
||||
ifeq ($(strip $(MIDI_ENABLE)), yes)
|
||||
include $(TMK_PATH)/protocol/midi.mk
|
||||
endif
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "progmem.h"
|
||||
#include "stddef.h"
|
||||
#include "inttypes.h"
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define ATTR_PACKED __attribute__((packed))
|
||||
/** Concatenates the given input into a single token, via the C Preprocessor.
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
* GPL v2 or later.
|
||||
*/
|
||||
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include <ch.h>
|
||||
#include <hal.h>
|
||||
|
||||
#include "usb_main.h"
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "led.h"
|
||||
#include "sendchar.h"
|
||||
#include "debug.h"
|
||||
#include "printf.h"
|
||||
#include "print.h"
|
||||
|
||||
#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
|
||||
// Change this to be TRUE once we've migrated keyboards to the new init system
|
||||
@@ -54,6 +54,9 @@
|
||||
#ifdef STM32_EEPROM_ENABLE
|
||||
# include "eeprom_stm32.h"
|
||||
#endif
|
||||
#ifdef EEPROM_DRIVER
|
||||
# include "eeprom_driver.h"
|
||||
#endif
|
||||
#include "suspend.h"
|
||||
#include "wait.h"
|
||||
|
||||
@@ -150,6 +153,9 @@ int main(void) {
|
||||
#ifdef STM32_EEPROM_ENABLE
|
||||
EEPROM_Init();
|
||||
#endif
|
||||
#ifdef EEPROM_DRIVER
|
||||
eeprom_driver_init();
|
||||
#endif
|
||||
|
||||
// TESTING
|
||||
// chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
|
||||
@@ -157,6 +163,7 @@ int main(void) {
|
||||
keyboard_setup();
|
||||
|
||||
/* Init USB */
|
||||
usb_event_queue_init();
|
||||
init_usb_driver(&USB_DRIVER);
|
||||
|
||||
#ifdef MIDI_ENABLE
|
||||
@@ -215,6 +222,8 @@ int main(void) {
|
||||
|
||||
/* Main loop */
|
||||
while (true) {
|
||||
usb_event_queue_task();
|
||||
|
||||
#if !defined(NO_USB_STARTUP_CHECK)
|
||||
if (USB_DRIVER.state == USB_SUSPENDED) {
|
||||
print("[s]");
|
||||
@@ -230,6 +239,7 @@ int main(void) {
|
||||
/* Remote wakeup */
|
||||
if (suspend_wakeup_condition()) {
|
||||
usbWakeupHost(&USB_DRIVER);
|
||||
restart_usb_driver(&USB_DRIVER);
|
||||
}
|
||||
}
|
||||
/* Woken up */
|
||||
@@ -258,5 +268,9 @@ int main(void) {
|
||||
#ifdef RAW_ENABLE
|
||||
raw_hid_task();
|
||||
#endif
|
||||
|
||||
// Run housekeeping
|
||||
housekeeping_task_kb();
|
||||
housekeeping_task_user();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "hal.h"
|
||||
#include <hal.h>
|
||||
#include "usb_driver.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@@ -22,10 +22,9 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef USB_DRIVER_H
|
||||
# define USB_DRIVER_H
|
||||
#pragma once
|
||||
|
||||
# include "hal_usb_cdc.h"
|
||||
#include <hal_usb_cdc.h>
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
@@ -35,9 +34,9 @@
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
# if HAL_USE_USB == FALSE
|
||||
# error "The USB Driver requires HAL_USE_USB"
|
||||
# endif
|
||||
#if HAL_USE_USB == FALSE
|
||||
# error "The USB Driver requires HAL_USE_USB"
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
@@ -112,21 +111,21 @@ typedef struct {
|
||||
/**
|
||||
* @brief @p SerialDriver specific data.
|
||||
*/
|
||||
# define _qmk_usb_driver_data \
|
||||
_base_asynchronous_channel_data /* Driver state.*/ \
|
||||
qmkusbstate_t state; \
|
||||
/* Input buffers queue.*/ \
|
||||
input_buffers_queue_t ibqueue; \
|
||||
/* Output queue.*/ \
|
||||
output_buffers_queue_t obqueue; \
|
||||
/* End of the mandatory fields.*/ \
|
||||
/* Current configuration data.*/ \
|
||||
const QMKUSBConfig *config;
|
||||
#define _qmk_usb_driver_data \
|
||||
_base_asynchronous_channel_data /* Driver state.*/ \
|
||||
qmkusbstate_t state; \
|
||||
/* Input buffers queue.*/ \
|
||||
input_buffers_queue_t ibqueue; \
|
||||
/* Output queue.*/ \
|
||||
output_buffers_queue_t obqueue; \
|
||||
/* End of the mandatory fields.*/ \
|
||||
/* Current configuration data.*/ \
|
||||
const QMKUSBConfig *config;
|
||||
|
||||
/**
|
||||
* @brief @p SerialUSBDriver specific methods.
|
||||
*/
|
||||
# define _qmk_usb_driver_methods _base_asynchronous_channel_methods
|
||||
#define _qmk_usb_driver_methods _base_asynchronous_channel_methods
|
||||
|
||||
/**
|
||||
* @extends BaseAsynchronousChannelVMT
|
||||
@@ -158,9 +157,9 @@ struct QMKUSBDriver {
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
# ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
#endif
|
||||
void qmkusbInit(void);
|
||||
void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
|
||||
void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
|
||||
@@ -173,10 +172,8 @@ void qmkusbSOFHookI(QMKUSBDriver *qmkusbp);
|
||||
void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep);
|
||||
void qmkusbDataReceived(USBDriver *usbp, usbep_t ep);
|
||||
void qmkusbInterruptTransmitted(USBDriver *usbp, usbep_t ep);
|
||||
# ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif /* USB_DRIVER_H */
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
* makes the assumption this is safe to avoid littering with preprocessor directives.
|
||||
*/
|
||||
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include <ch.h>
|
||||
#include <hal.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "usb_main.h"
|
||||
|
||||
@@ -165,6 +166,19 @@ static const USBEndpointConfig shared_ep_config = {
|
||||
};
|
||||
#endif
|
||||
|
||||
#if STM32_USB_USE_OTG1
|
||||
typedef struct {
|
||||
size_t queue_capacity_in;
|
||||
size_t queue_capacity_out;
|
||||
USBInEndpointState in_ep_state;
|
||||
USBOutEndpointState out_ep_state;
|
||||
USBInEndpointState int_ep_state;
|
||||
USBEndpointConfig inout_ep_config;
|
||||
USBEndpointConfig int_ep_config;
|
||||
const QMKUSBConfig config;
|
||||
QMKUSBDriver driver;
|
||||
} usb_driver_config_t;
|
||||
#else
|
||||
typedef struct {
|
||||
size_t queue_capacity_in;
|
||||
size_t queue_capacity_out;
|
||||
@@ -177,64 +191,112 @@ typedef struct {
|
||||
const QMKUSBConfig config;
|
||||
QMKUSBDriver driver;
|
||||
} usb_driver_config_t;
|
||||
#endif
|
||||
|
||||
#if STM32_USB_USE_OTG1
|
||||
/* Reusable initialization structure - see USBEndpointConfig comment at top of file */
|
||||
#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
|
||||
{ \
|
||||
.queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \
|
||||
.in_ep_config = \
|
||||
{ \
|
||||
stream##_IN_MODE, /* Interrupt EP */ \
|
||||
NULL, /* SETUP packet notification callback */ \
|
||||
qmkusbDataTransmitted, /* IN notification callback */ \
|
||||
NULL, /* OUT notification callback */ \
|
||||
stream##_EPSIZE, /* IN maximum packet size */ \
|
||||
0, /* OUT maximum packet size */ \
|
||||
NULL, /* IN Endpoint state */ \
|
||||
NULL, /* OUT endpoint state */ \
|
||||
2, /* IN multiplier */ \
|
||||
NULL /* SETUP buffer (not a SETUP endpoint) */ \
|
||||
}, \
|
||||
.out_ep_config = \
|
||||
{ \
|
||||
stream##_OUT_MODE, /* Interrupt EP */ \
|
||||
NULL, /* SETUP packet notification callback */ \
|
||||
NULL, /* IN notification callback */ \
|
||||
qmkusbDataReceived, /* OUT notification callback */ \
|
||||
0, /* IN maximum packet size */ \
|
||||
stream##_EPSIZE, /* OUT maximum packet size */ \
|
||||
NULL, /* IN Endpoint state */ \
|
||||
NULL, /* OUT endpoint state */ \
|
||||
2, /* IN multiplier */ \
|
||||
NULL, /* SETUP buffer (not a SETUP endpoint) */ \
|
||||
}, \
|
||||
.int_ep_config = \
|
||||
{ \
|
||||
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ \
|
||||
NULL, /* SETUP packet notification callback */ \
|
||||
qmkusbInterruptTransmitted, /* IN notification callback */ \
|
||||
NULL, /* OUT notification callback */ \
|
||||
CDC_NOTIFICATION_EPSIZE, /* IN maximum packet size */ \
|
||||
0, /* OUT maximum packet size */ \
|
||||
NULL, /* IN Endpoint state */ \
|
||||
NULL, /* OUT endpoint state */ \
|
||||
2, /* IN multiplier */ \
|
||||
NULL, /* SETUP buffer (not a SETUP endpoint) */ \
|
||||
}, \
|
||||
.config = { \
|
||||
.usbp = &USB_DRIVER, \
|
||||
.bulk_in = stream##_IN_EPNUM, \
|
||||
.bulk_out = stream##_OUT_EPNUM, \
|
||||
.int_in = notification, \
|
||||
.in_buffers = stream##_IN_CAPACITY, \
|
||||
.out_buffers = stream##_OUT_CAPACITY, \
|
||||
.in_size = stream##_EPSIZE, \
|
||||
.out_size = stream##_EPSIZE, \
|
||||
.fixed_size = fixedsize, \
|
||||
.ib = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){}, \
|
||||
.ob = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
|
||||
} \
|
||||
}
|
||||
# define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
|
||||
{ \
|
||||
.queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \
|
||||
.inout_ep_config = \
|
||||
{ \
|
||||
stream##_IN_MODE, /* Interrupt EP */ \
|
||||
NULL, /* SETUP packet notification callback */ \
|
||||
qmkusbDataTransmitted, /* IN notification callback */ \
|
||||
qmkusbDataReceived, /* OUT notification callback */ \
|
||||
stream##_EPSIZE, /* IN maximum packet size */ \
|
||||
stream##_EPSIZE, /* OUT maximum packet size */ \
|
||||
NULL, /* IN Endpoint state */ \
|
||||
NULL, /* OUT endpoint state */ \
|
||||
2, /* IN multiplier */ \
|
||||
NULL /* SETUP buffer (not a SETUP endpoint) */ \
|
||||
}, \
|
||||
.int_ep_config = \
|
||||
{ \
|
||||
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ \
|
||||
NULL, /* SETUP packet notification callback */ \
|
||||
qmkusbInterruptTransmitted, /* IN notification callback */ \
|
||||
NULL, /* OUT notification callback */ \
|
||||
CDC_NOTIFICATION_EPSIZE, /* IN maximum packet size */ \
|
||||
0, /* OUT maximum packet size */ \
|
||||
NULL, /* IN Endpoint state */ \
|
||||
NULL, /* OUT endpoint state */ \
|
||||
2, /* IN multiplier */ \
|
||||
NULL, /* SETUP buffer (not a SETUP endpoint) */ \
|
||||
}, \
|
||||
.config = { \
|
||||
.usbp = &USB_DRIVER, \
|
||||
.bulk_in = stream##_IN_EPNUM, \
|
||||
.bulk_out = stream##_OUT_EPNUM, \
|
||||
.int_in = notification, \
|
||||
.in_buffers = stream##_IN_CAPACITY, \
|
||||
.out_buffers = stream##_OUT_CAPACITY, \
|
||||
.in_size = stream##_EPSIZE, \
|
||||
.out_size = stream##_EPSIZE, \
|
||||
.fixed_size = fixedsize, \
|
||||
.ib = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){}, \
|
||||
.ob = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
/* Reusable initialization structure - see USBEndpointConfig comment at top of file */
|
||||
# define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
|
||||
{ \
|
||||
.queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \
|
||||
.in_ep_config = \
|
||||
{ \
|
||||
stream##_IN_MODE, /* Interrupt EP */ \
|
||||
NULL, /* SETUP packet notification callback */ \
|
||||
qmkusbDataTransmitted, /* IN notification callback */ \
|
||||
NULL, /* OUT notification callback */ \
|
||||
stream##_EPSIZE, /* IN maximum packet size */ \
|
||||
0, /* OUT maximum packet size */ \
|
||||
NULL, /* IN Endpoint state */ \
|
||||
NULL, /* OUT endpoint state */ \
|
||||
2, /* IN multiplier */ \
|
||||
NULL /* SETUP buffer (not a SETUP endpoint) */ \
|
||||
}, \
|
||||
.out_ep_config = \
|
||||
{ \
|
||||
stream##_OUT_MODE, /* Interrupt EP */ \
|
||||
NULL, /* SETUP packet notification callback */ \
|
||||
NULL, /* IN notification callback */ \
|
||||
qmkusbDataReceived, /* OUT notification callback */ \
|
||||
0, /* IN maximum packet size */ \
|
||||
stream##_EPSIZE, /* OUT maximum packet size */ \
|
||||
NULL, /* IN Endpoint state */ \
|
||||
NULL, /* OUT endpoint state */ \
|
||||
2, /* IN multiplier */ \
|
||||
NULL, /* SETUP buffer (not a SETUP endpoint) */ \
|
||||
}, \
|
||||
.int_ep_config = \
|
||||
{ \
|
||||
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ \
|
||||
NULL, /* SETUP packet notification callback */ \
|
||||
qmkusbInterruptTransmitted, /* IN notification callback */ \
|
||||
NULL, /* OUT notification callback */ \
|
||||
CDC_NOTIFICATION_EPSIZE, /* IN maximum packet size */ \
|
||||
0, /* OUT maximum packet size */ \
|
||||
NULL, /* IN Endpoint state */ \
|
||||
NULL, /* OUT endpoint state */ \
|
||||
2, /* IN multiplier */ \
|
||||
NULL, /* SETUP buffer (not a SETUP endpoint) */ \
|
||||
}, \
|
||||
.config = { \
|
||||
.usbp = &USB_DRIVER, \
|
||||
.bulk_in = stream##_IN_EPNUM, \
|
||||
.bulk_out = stream##_OUT_EPNUM, \
|
||||
.int_in = notification, \
|
||||
.in_buffers = stream##_IN_CAPACITY, \
|
||||
.out_buffers = stream##_OUT_CAPACITY, \
|
||||
.in_size = stream##_EPSIZE, \
|
||||
.out_size = stream##_EPSIZE, \
|
||||
.fixed_size = fixedsize, \
|
||||
.ib = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){}, \
|
||||
.ob = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
@@ -307,6 +369,69 @@ static usb_driver_configs_t drivers = {
|
||||
* ---------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define USB_EVENT_QUEUE_SIZE 16
|
||||
usbevent_t event_queue[USB_EVENT_QUEUE_SIZE];
|
||||
uint8_t event_queue_head;
|
||||
uint8_t event_queue_tail;
|
||||
|
||||
void usb_event_queue_init(void) {
|
||||
// Initialise the event queue
|
||||
memset(&event_queue, 0, sizeof(event_queue));
|
||||
event_queue_head = 0;
|
||||
event_queue_tail = 0;
|
||||
}
|
||||
|
||||
static inline bool usb_event_queue_enqueue(usbevent_t event) {
|
||||
uint8_t next = (event_queue_head + 1) % USB_EVENT_QUEUE_SIZE;
|
||||
if (next == event_queue_tail) {
|
||||
return false;
|
||||
}
|
||||
event_queue[event_queue_head] = event;
|
||||
event_queue_head = next;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool usb_event_queue_dequeue(usbevent_t *event) {
|
||||
if (event_queue_head == event_queue_tail) {
|
||||
return false;
|
||||
}
|
||||
*event = event_queue[event_queue_tail];
|
||||
event_queue_tail = (event_queue_tail + 1) % USB_EVENT_QUEUE_SIZE;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void usb_event_suspend_handler(void) {
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_enable();
|
||||
#endif /* SLEEP_LED_ENABLE */
|
||||
}
|
||||
|
||||
static inline void usb_event_wakeup_handler(void) {
|
||||
suspend_wakeup_init();
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_disable();
|
||||
// NOTE: converters may not accept this
|
||||
led_set(host_keyboard_leds());
|
||||
#endif /* SLEEP_LED_ENABLE */
|
||||
}
|
||||
|
||||
void usb_event_queue_task(void) {
|
||||
usbevent_t event;
|
||||
while (usb_event_queue_dequeue(&event)) {
|
||||
switch (event) {
|
||||
case USB_EVENT_SUSPEND:
|
||||
usb_event_suspend_handler();
|
||||
break;
|
||||
case USB_EVENT_WAKEUP:
|
||||
usb_event_wakeup_handler();
|
||||
break;
|
||||
default:
|
||||
// Nothing to do, we don't handle it.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Handles the USB driver global events
|
||||
* TODO: maybe disable some things when connection is lost? */
|
||||
static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
|
||||
@@ -327,8 +452,12 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
|
||||
usbInitEndpointI(usbp, SHARED_IN_EPNUM, &shared_ep_config);
|
||||
#endif
|
||||
for (int i = 0; i < NUM_USB_DRIVERS; i++) {
|
||||
#if STM32_USB_USE_OTG1
|
||||
usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].inout_ep_config);
|
||||
#else
|
||||
usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].in_ep_config);
|
||||
usbInitEndpointI(usbp, drivers.array[i].config.bulk_out, &drivers.array[i].out_ep_config);
|
||||
#endif
|
||||
if (drivers.array[i].config.int_in) {
|
||||
usbInitEndpointI(usbp, drivers.array[i].config.int_in, &drivers.array[i].int_ep_config);
|
||||
}
|
||||
@@ -337,9 +466,7 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
|
||||
osalSysUnlockFromISR();
|
||||
return;
|
||||
case USB_EVENT_SUSPEND:
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_enable();
|
||||
#endif /* SLEEP_LED_ENABLE */
|
||||
usb_event_queue_enqueue(USB_EVENT_SUSPEND);
|
||||
/* Falls into.*/
|
||||
case USB_EVENT_UNCONFIGURED:
|
||||
/* Falls into.*/
|
||||
@@ -360,12 +487,7 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
|
||||
qmkusbWakeupHookI(&drivers.array[i].driver);
|
||||
chSysUnlockFromISR();
|
||||
}
|
||||
suspend_wakeup_init();
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_disable();
|
||||
// NOTE: converters may not accept this
|
||||
led_set(host_keyboard_leds());
|
||||
#endif /* SLEEP_LED_ENABLE */
|
||||
usb_event_queue_enqueue(USB_EVENT_WAKEUP);
|
||||
return;
|
||||
|
||||
case USB_EVENT_STALLED:
|
||||
@@ -553,12 +675,21 @@ static const USBConfig usbcfg = {
|
||||
*/
|
||||
void init_usb_driver(USBDriver *usbp) {
|
||||
for (int i = 0; i < NUM_USB_DRIVERS; i++) {
|
||||
#if STM32_USB_USE_OTG1
|
||||
QMKUSBDriver *driver = &drivers.array[i].driver;
|
||||
drivers.array[i].inout_ep_config.in_state = &drivers.array[i].in_ep_state;
|
||||
drivers.array[i].inout_ep_config.out_state = &drivers.array[i].out_ep_state;
|
||||
drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state;
|
||||
qmkusbObjectInit(driver, &drivers.array[i].config);
|
||||
qmkusbStart(driver, &drivers.array[i].config);
|
||||
#else
|
||||
QMKUSBDriver *driver = &drivers.array[i].driver;
|
||||
drivers.array[i].in_ep_config.in_state = &drivers.array[i].in_ep_state;
|
||||
drivers.array[i].out_ep_config.out_state = &drivers.array[i].out_ep_state;
|
||||
drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state;
|
||||
qmkusbObjectInit(driver, &drivers.array[i].config);
|
||||
qmkusbStart(driver, &drivers.array[i].config);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -574,6 +705,24 @@ void init_usb_driver(USBDriver *usbp) {
|
||||
chVTObjectInit(&keyboard_idle_timer);
|
||||
}
|
||||
|
||||
void restart_usb_driver(USBDriver *usbp) {
|
||||
usbStop(usbp);
|
||||
usbDisconnectBus(usbp);
|
||||
|
||||
#if USB_SUSPEND_WAKEUP_DELAY > 0
|
||||
// Some hubs, kvm switches, and monitors do
|
||||
// weird things, with USB device state bouncing
|
||||
// around wildly on wakeup, yielding race
|
||||
// conditions that can corrupt the keyboard state.
|
||||
//
|
||||
// Pause for a while to let things settle...
|
||||
wait_ms(USB_SUSPEND_WAKEUP_DELAY);
|
||||
#endif
|
||||
|
||||
usbStart(usbp, &usbcfg);
|
||||
usbConnectBus(usbp);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------
|
||||
* Keyboard functions
|
||||
* ---------------------------------------------------------
|
||||
@@ -804,15 +953,8 @@ void console_task(void) {
|
||||
} while (size > 0);
|
||||
}
|
||||
|
||||
#else /* CONSOLE_ENABLE */
|
||||
int8_t sendchar(uint8_t c) {
|
||||
(void)c;
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONSOLE_ENABLE */
|
||||
|
||||
void _putchar(char character) { sendchar(character); }
|
||||
|
||||
#ifdef RAW_ENABLE
|
||||
void raw_hid_send(uint8_t *data, uint8_t length) {
|
||||
// TODO: implement variable size packet
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
* GPL v2 or later.
|
||||
*/
|
||||
|
||||
#ifndef _USB_MAIN_H_
|
||||
#define _USB_MAIN_H_
|
||||
#pragma once
|
||||
|
||||
// TESTING
|
||||
// extern uint8_t blinkLed;
|
||||
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include <ch.h>
|
||||
#include <hal.h>
|
||||
|
||||
/* -------------------------
|
||||
* General USB driver header
|
||||
@@ -35,6 +34,20 @@
|
||||
/* Initialize the USB driver and bus */
|
||||
void init_usb_driver(USBDriver *usbp);
|
||||
|
||||
/* Restart the USB driver and bus */
|
||||
void restart_usb_driver(USBDriver *usbp);
|
||||
|
||||
/* ---------------
|
||||
* USB Event queue
|
||||
* ---------------
|
||||
*/
|
||||
|
||||
/* Initialisation of the FIFO */
|
||||
void usb_event_queue_init(void);
|
||||
|
||||
/* Task to dequeue and execute any handlers for the USB events on the main thread */
|
||||
void usb_event_queue_task(void);
|
||||
|
||||
/* ---------------
|
||||
* Keyboard header
|
||||
* ---------------
|
||||
@@ -86,5 +99,3 @@ int8_t sendchar(uint8_t c);
|
||||
void console_flush_output(void);
|
||||
|
||||
#endif /* CONSOLE_ENABLE */
|
||||
|
||||
#endif /* _USB_MAIN_H_ */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
Copyright 2014 Jun WAKO <wakojun@gmail.com>
|
||||
*/
|
||||
#ifndef IBM4704_H
|
||||
#define IBM4704_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#define IBM4704_ERR_NONE 0
|
||||
#define IBM4704_ERR_PARITY 0x70
|
||||
@@ -101,5 +101,3 @@ static inline void inhibit(void) {
|
||||
clock_hi();
|
||||
data_lo();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "spi_master.h"
|
||||
#include "wait.h"
|
||||
#include "analog.h"
|
||||
#include "progmem.h"
|
||||
|
||||
// These are the pin assignments for the 32u4 boards.
|
||||
// You may define them to something else in your config.h
|
||||
@@ -36,10 +37,8 @@
|
||||
#define SAMPLE_BATTERY
|
||||
#define ConnectionUpdateInterval 1000 /* milliseconds */
|
||||
|
||||
#ifdef SAMPLE_BATTERY
|
||||
# ifndef BATTERY_LEVEL_PIN
|
||||
# define BATTERY_LEVEL_PIN B5
|
||||
# endif
|
||||
#ifndef BATTERY_LEVEL_PIN
|
||||
# define BATTERY_LEVEL_PIN B5
|
||||
#endif
|
||||
|
||||
static struct {
|
||||
@@ -118,15 +117,15 @@ enum sdep_type {
|
||||
SdepResponse = 0x20,
|
||||
SdepAlert = 0x40,
|
||||
SdepError = 0x80,
|
||||
SdepSlaveNotReady = 0xfe, // Try again later
|
||||
SdepSlaveOverflow = 0xff, // You read more data than is available
|
||||
SdepSlaveNotReady = 0xFE, // Try again later
|
||||
SdepSlaveOverflow = 0xFF, // You read more data than is available
|
||||
};
|
||||
|
||||
enum ble_cmd {
|
||||
BleInitialize = 0xbeef,
|
||||
BleAtWrapper = 0x0a00,
|
||||
BleUartTx = 0x0a01,
|
||||
BleUartRx = 0x0a02,
|
||||
BleInitialize = 0xBEEF,
|
||||
BleAtWrapper = 0x0A00,
|
||||
BleUartTx = 0x0A01,
|
||||
BleUartRx = 0x0A02,
|
||||
};
|
||||
|
||||
enum ble_system_event_bits {
|
||||
@@ -176,7 +175,7 @@ static bool sdep_send_pkt(const struct sdep_msg *msg, uint16_t timeout) {
|
||||
|
||||
static inline void sdep_build_pkt(struct sdep_msg *msg, uint16_t command, const uint8_t *payload, uint8_t len, bool moredata) {
|
||||
msg->type = SdepCommand;
|
||||
msg->cmd_low = command & 0xff;
|
||||
msg->cmd_low = command & 0xFF;
|
||||
msg->cmd_high = command >> 8;
|
||||
msg->len = len;
|
||||
msg->more = (moredata && len == SdepMaxPayload) ? 1 : 0;
|
||||
@@ -407,11 +406,11 @@ static bool at_command(const char *cmd, char *resp, uint16_t resplen, bool verbo
|
||||
}
|
||||
|
||||
if (resp == NULL) {
|
||||
auto now = timer_read();
|
||||
uint16_t now = timer_read();
|
||||
while (!resp_buf.enqueue(now)) {
|
||||
resp_buf_read_one(false);
|
||||
}
|
||||
auto later = timer_read();
|
||||
uint16_t later = timer_read();
|
||||
if (TIMER_DIFF_16(later, now) > 0) {
|
||||
dprintf("waited %dms for resp_buf\n", TIMER_DIFF_16(later, now));
|
||||
}
|
||||
@@ -422,7 +421,7 @@ static bool at_command(const char *cmd, char *resp, uint16_t resplen, bool verbo
|
||||
}
|
||||
|
||||
bool at_command_P(const char *cmd, char *resp, uint16_t resplen, bool verbose) {
|
||||
auto cmdbuf = (char *)alloca(strlen_P(cmd) + 1);
|
||||
char *cmdbuf = (char *)alloca(strlen_P(cmd) + 1);
|
||||
strcpy_P(cmdbuf, cmd);
|
||||
return at_command(cmdbuf, resp, resplen, verbose);
|
||||
}
|
||||
@@ -484,9 +483,9 @@ fail:
|
||||
static void set_connected(bool connected) {
|
||||
if (connected != state.is_connected) {
|
||||
if (connected) {
|
||||
print("****** BLE CONNECT!!!!\n");
|
||||
dprint("BLE connected\n");
|
||||
} else {
|
||||
print("****** BLE DISCONNECT!!!!\n");
|
||||
dprint("BLE disconnected\n");
|
||||
}
|
||||
state.is_connected = connected;
|
||||
|
||||
@@ -612,7 +611,7 @@ static bool process_queue_item(struct queue_item *item, uint16_t timeout) {
|
||||
}
|
||||
}
|
||||
|
||||
bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys) {
|
||||
void adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys) {
|
||||
struct queue_item item;
|
||||
bool didWait = false;
|
||||
|
||||
@@ -638,30 +637,27 @@ bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nk
|
||||
}
|
||||
|
||||
if (nkeys <= 6) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
nkeys -= 6;
|
||||
keys += 6;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration) {
|
||||
void adafruit_ble_send_consumer_key(uint16_t usage) {
|
||||
struct queue_item item;
|
||||
|
||||
item.queue_type = QTConsumer;
|
||||
item.consumer = keycode;
|
||||
item.consumer = usage;
|
||||
|
||||
while (!send_buf.enqueue(item)) {
|
||||
send_buf_send_one();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef MOUSE_ENABLE
|
||||
bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons) {
|
||||
void adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons) {
|
||||
struct queue_item item;
|
||||
|
||||
item.queue_type = QTMouseMove;
|
||||
@@ -674,7 +670,6 @@ bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan,
|
||||
while (!send_buf.enqueue(item)) {
|
||||
send_buf_send_one();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "config_common.h"
|
||||
#include "progmem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -35,17 +34,17 @@ extern void adafruit_ble_task(void);
|
||||
* this set of keys.
|
||||
* Also sends a key release indicator, so that the keys do not remain
|
||||
* held down. */
|
||||
extern bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys);
|
||||
extern void adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys);
|
||||
|
||||
/* Send a consumer keycode, holding it down for the specified duration
|
||||
/* Send a consumer usage.
|
||||
* (milliseconds) */
|
||||
extern bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration);
|
||||
extern void adafruit_ble_send_consumer_key(uint16_t usage);
|
||||
|
||||
#ifdef MOUSE_ENABLE
|
||||
/* Send a mouse/wheel movement report.
|
||||
* The parameters are signed and indicate positive of negative direction
|
||||
* The parameters are signed and indicate positive or negative direction
|
||||
* change. */
|
||||
extern bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons);
|
||||
extern void adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons);
|
||||
#endif
|
||||
|
||||
/* Compute battery voltage by reading an analog pin.
|
||||
|
||||
@@ -61,7 +61,7 @@ extern keymap_config_t keymap_config;
|
||||
#endif
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
# include <audio.h>
|
||||
# include "audio.h"
|
||||
#endif
|
||||
|
||||
#ifdef BLUETOOTH_ENABLE
|
||||
@@ -435,7 +435,9 @@ void EVENT_USB_Device_Suspend() {
|
||||
*/
|
||||
void EVENT_USB_Device_WakeUp() {
|
||||
print("[W]");
|
||||
#if defined(NO_USB_STARTUP_CHECK)
|
||||
suspend_wakeup_init();
|
||||
#endif
|
||||
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_disable();
|
||||
@@ -669,9 +671,7 @@ static void send_keyboard(report_keyboard_t *report) {
|
||||
uint8_t timeout = 255;
|
||||
|
||||
#ifdef BLUETOOTH_ENABLE
|
||||
uint8_t where = where_to_send();
|
||||
|
||||
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
|
||||
if (where_to_send() == OUTPUT_BLUETOOTH) {
|
||||
# ifdef MODULE_ADAFRUIT_BLE
|
||||
adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys));
|
||||
# elif MODULE_RN42
|
||||
@@ -684,9 +684,6 @@ static void send_keyboard(report_keyboard_t *report) {
|
||||
serial_send(report->keys[i]);
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -727,9 +724,7 @@ static void send_mouse(report_mouse_t *report) {
|
||||
uint8_t timeout = 255;
|
||||
|
||||
# ifdef BLUETOOTH_ENABLE
|
||||
uint8_t where = where_to_send();
|
||||
|
||||
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
|
||||
if (where_to_send() == OUTPUT_BLUETOOTH) {
|
||||
# ifdef MODULE_ADAFRUIT_BLE
|
||||
// FIXME: mouse buttons
|
||||
adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons);
|
||||
@@ -744,9 +739,6 @@ static void send_mouse(report_mouse_t *report) {
|
||||
serial_send(report->h); // should try sending the wheel h here
|
||||
serial_send(0x00);
|
||||
# endif
|
||||
}
|
||||
|
||||
if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
@@ -805,11 +797,9 @@ static void send_system(uint16_t data) {
|
||||
static void send_consumer(uint16_t data) {
|
||||
#ifdef EXTRAKEY_ENABLE
|
||||
# ifdef BLUETOOTH_ENABLE
|
||||
uint8_t where = where_to_send();
|
||||
|
||||
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
|
||||
if (where_to_send() == OUTPUT_BLUETOOTH) {
|
||||
# ifdef MODULE_ADAFRUIT_BLE
|
||||
adafruit_ble_send_consumer_key(data, 0);
|
||||
adafruit_ble_send_consumer_key(data);
|
||||
# elif MODULE_RN42
|
||||
static uint16_t last_data = 0;
|
||||
if (data == last_data) return;
|
||||
@@ -821,9 +811,6 @@ static void send_consumer(uint16_t data) {
|
||||
serial_send(bitmap & 0xFF);
|
||||
serial_send((bitmap >> 8) & 0xFF);
|
||||
# endif
|
||||
}
|
||||
|
||||
if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
@@ -1023,7 +1010,6 @@ static void setup_usb(void) {
|
||||
|
||||
// for Console_Task
|
||||
USB_Device_EnableSOFEvents();
|
||||
print_set_sendchar(sendchar);
|
||||
}
|
||||
|
||||
/** \brief Main
|
||||
@@ -1073,12 +1059,26 @@ int main(void) {
|
||||
print("Keyboard start.\n");
|
||||
while (1) {
|
||||
#if !defined(NO_USB_STARTUP_CHECK)
|
||||
while (USB_DeviceState == DEVICE_STATE_Suspended) {
|
||||
if (USB_DeviceState == DEVICE_STATE_Suspended) {
|
||||
print("[s]");
|
||||
suspend_power_down();
|
||||
if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
|
||||
USB_Device_SendRemoteWakeup();
|
||||
while (USB_DeviceState == DEVICE_STATE_Suspended) {
|
||||
suspend_power_down();
|
||||
if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
|
||||
USB_Device_SendRemoteWakeup();
|
||||
clear_keyboard();
|
||||
|
||||
# if USB_SUSPEND_WAKEUP_DELAY > 0
|
||||
// Some hubs, kvm switches, and monitors do
|
||||
// weird things, with USB device state bouncing
|
||||
// around wildly on wakeup, yielding race
|
||||
// conditions that can corrupt the keyboard state.
|
||||
//
|
||||
// Pause for a while to let things settle...
|
||||
wait_ms(USB_SUSPEND_WAKEUP_DELAY);
|
||||
# endif
|
||||
}
|
||||
}
|
||||
suspend_wakeup_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1104,6 +1104,10 @@ int main(void) {
|
||||
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
|
||||
USB_USBTask();
|
||||
#endif
|
||||
|
||||
// Run housekeeping
|
||||
housekeeping_task_kb();
|
||||
housekeeping_task_user();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@
|
||||
this software.
|
||||
*/
|
||||
|
||||
#ifndef _LUFA_H_
|
||||
#define _LUFA_H_
|
||||
#pragma once
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
@@ -68,5 +67,3 @@ extern host_driver_t lufa_driver;
|
||||
// The header and terminator are not stored to save a few bytes of precious ram
|
||||
# define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,21 +21,11 @@ enum outputs {
|
||||
|
||||
OUTPUT_NONE,
|
||||
OUTPUT_USB,
|
||||
OUTPUT_BLUETOOTH,
|
||||
|
||||
// backward compatibility
|
||||
OUTPUT_USB_AND_BT
|
||||
OUTPUT_BLUETOOTH
|
||||
};
|
||||
|
||||
/**
|
||||
* backward compatibility for BLUETOOTH_ENABLE, send to BT and USB by default
|
||||
*/
|
||||
#ifndef OUTPUT_DEFAULT
|
||||
# ifdef BLUETOOTH_ENABLE
|
||||
# define OUTPUT_DEFAULT OUTPUT_USB_AND_BT
|
||||
# else
|
||||
# define OUTPUT_DEFAULT OUTPUT_AUTO
|
||||
# endif
|
||||
# define OUTPUT_DEFAULT OUTPUT_AUTO
|
||||
#endif
|
||||
|
||||
void set_output(uint8_t output);
|
||||
|
||||
@@ -95,11 +95,11 @@ void m0110_init(void) {
|
||||
uint8_t data;
|
||||
m0110_send(M0110_MODEL);
|
||||
data = m0110_recv();
|
||||
print("m0110_init model: "); phex(data); print("\n");
|
||||
print("m0110_init model: "); print_hex8(data); print("\n");
|
||||
|
||||
m0110_send(M0110_TEST);
|
||||
data = m0110_recv();
|
||||
print("m0110_init test: "); phex(data); print("\n");
|
||||
print("m0110_init test: "); print_hex8(data); print("\n");
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ uint8_t m0110_send(uint8_t data) {
|
||||
return 1;
|
||||
ERROR:
|
||||
print("m0110_send err: ");
|
||||
phex(m0110_error);
|
||||
print_hex8(m0110_error);
|
||||
print("\n");
|
||||
_delay_ms(500);
|
||||
idle();
|
||||
@@ -146,7 +146,7 @@ uint8_t m0110_recv(void) {
|
||||
return data;
|
||||
ERROR:
|
||||
print("m0110_recv err: ");
|
||||
phex(m0110_error);
|
||||
print_hex8(m0110_error);
|
||||
print("\n");
|
||||
_delay_ms(500);
|
||||
idle();
|
||||
|
||||
@@ -35,8 +35,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef M0110_H
|
||||
#define M0110_H
|
||||
#pragma once
|
||||
|
||||
/* port settings for clock and data line */
|
||||
#if !(defined(M0110_CLOCK_PORT) && defined(M0110_CLOCK_PIN) && defined(M0110_CLOCK_DDR) && defined(M0110_CLOCK_BIT))
|
||||
@@ -80,5 +79,3 @@ uint8_t m0110_recv(void);
|
||||
uint8_t m0110_recv_key(void);
|
||||
uint8_t m0110_inquiry(void);
|
||||
uint8_t m0110_instant(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -39,8 +39,7 @@
|
||||
* manual section "Summary of Compile Tokens".
|
||||
*/
|
||||
|
||||
#ifndef _LUFA_CONFIG_H_
|
||||
#define _LUFA_CONFIG_H_
|
||||
#pragma once
|
||||
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
|
||||
@@ -90,4 +89,3 @@
|
||||
# error Unsupported architecture for this LUFA configuration file.
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef BYTEQUEUE_H
|
||||
#define BYTEQUEUE_H
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -54,5 +53,3 @@ void bytequeue_remove(byteQueue_t* queue, byteQueueIndex_t numToRemove);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,7 @@ interrupt_setting_t store_and_clear_interrupt(void) {
|
||||
|
||||
void restore_interrupt_setting(interrupt_setting_t setting) { SREG = setting; }
|
||||
#elif defined(__arm__)
|
||||
# include "ch.h"
|
||||
# include <ch.h>
|
||||
|
||||
interrupt_setting_t store_and_clear_interrupt(void) {
|
||||
chSysLock();
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef INTERRUPT_SETTING_H
|
||||
#define INTERRUPT_SETTING_H
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -34,5 +33,3 @@ void restore_interrupt_setting(interrupt_setting_t setting);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XNOR_MIDI_H
|
||||
#define XNOR_MIDI_H
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -486,5 +485,3 @@ midi_packet_length_t midi_packet_length(uint8_t status);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,8 +21,7 @@
|
||||
* @brief Device implementation functions
|
||||
*/
|
||||
|
||||
#ifndef MIDI_DEVICE_H
|
||||
#define MIDI_DEVICE_H
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -147,5 +146,3 @@ void midi_device_set_pre_input_process_func(MidiDevice* device, midi_no_byte_fun
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,8 +21,7 @@
|
||||
* @brief Function signature definitions
|
||||
*/
|
||||
|
||||
#ifndef MIDI_FUNCTION_TYPES_H
|
||||
#define MIDI_FUNCTION_TYPES_H
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -46,5 +45,3 @@ typedef void (*midi_sysex_func_t)(MidiDevice *device, uint16_t start_byte, uint8
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef SYSEX_TOOLS_H
|
||||
#define SYSEX_TOOLS_H
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -91,5 +90,3 @@ uint16_t sysex_decode(uint8_t *decoded, const uint8_t *source, uint16_t length);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,8 +35,8 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NEWS_H
|
||||
#define NEWS_H
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Primitive PS/2 Library for AVR
|
||||
*/
|
||||
@@ -46,5 +46,3 @@ void news_init(void);
|
||||
uint8_t news_recv(void);
|
||||
|
||||
/* device role */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -45,13 +45,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef NEXT_KBD_H
|
||||
# define NEXT_KBD_H
|
||||
|
||||
# define NEXT_KBD_KMBUS_IDLE 0x300600
|
||||
# define NEXT_KBD_TIMING 50
|
||||
#define NEXT_KBD_KMBUS_IDLE 0x300600
|
||||
#define NEXT_KBD_TIMING 50
|
||||
|
||||
extern uint8_t next_kbd_error;
|
||||
|
||||
@@ -59,5 +58,3 @@ extern uint8_t next_kbd_error;
|
||||
void next_kbd_init(void);
|
||||
void next_kbd_set_leds(bool left, bool right);
|
||||
uint32_t next_kbd_recv(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,8 +35,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PS2_H
|
||||
#define PS2_H
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "wait.h"
|
||||
@@ -138,5 +137,3 @@ static inline void inhibit(void) {
|
||||
clock_lo();
|
||||
data_hi();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef PS2_IO_H
|
||||
#define PS2_IO_H
|
||||
#pragma once
|
||||
|
||||
void clock_init(void);
|
||||
void clock_lo(void);
|
||||
@@ -10,5 +9,3 @@ void data_init(void);
|
||||
void data_lo(void);
|
||||
void data_hi(void);
|
||||
bool data_in(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -190,7 +190,7 @@ static inline void ps2_mouse_clear_report(report_mouse_t *mouse_report) {
|
||||
static inline void ps2_mouse_print_report(report_mouse_t *mouse_report) {
|
||||
if (!debug_mouse) return;
|
||||
print("ps2_mouse: [");
|
||||
phex(mouse_report->buttons);
|
||||
print_hex8(mouse_report->buttons);
|
||||
print("|");
|
||||
print_hex8((uint8_t)mouse_report->x);
|
||||
print(" ");
|
||||
|
||||
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PS2_MOUSE_H
|
||||
#define PS2_MOUSE_H
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "debug.h"
|
||||
@@ -176,5 +175,3 @@ void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
|
||||
void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);
|
||||
|
||||
void ps2_mouse_moved_user(report_mouse_t *mouse_report);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -37,6 +37,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#define SERIAL_UART_DATA UDR1
|
||||
|
||||
/* host role */
|
||||
void serial_init(void);
|
||||
uint8_t serial_recv(void);
|
||||
|
||||
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SERIAL_MOUSE_H
|
||||
#define SERIAL_MOUSE_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -28,5 +27,3 @@ static inline uint8_t serial_mouse_init(void) {
|
||||
}
|
||||
|
||||
void serial_mouse_task(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -40,6 +40,22 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <avr/interrupt.h>
|
||||
#include "serial.h"
|
||||
|
||||
#ifndef SERIAL_UART_BAUD
|
||||
# define SERIAL_UART_BAUD 9600
|
||||
#endif
|
||||
|
||||
#define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
|
||||
#define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
|
||||
#define SERIAL_UART_RXD_VECT USART1_RX_vect
|
||||
|
||||
#ifndef SERIAL_UART_INIT_CUSTOM
|
||||
# define SERIAL_UART_INIT_CUSTOM \
|
||||
/* enable TX */ \
|
||||
UCSR1B = _BV(TXEN1); \
|
||||
/* 8-bit data */ \
|
||||
UCSR1C = _BV(UCSZ11) | _BV(UCSZ10);
|
||||
#endif
|
||||
|
||||
#if defined(SERIAL_UART_RTS_LO) && defined(SERIAL_UART_RTS_HI)
|
||||
// Buffer state
|
||||
// Empty: RBUF_SPACE == RBUF_SIZE(head==tail)
|
||||
@@ -61,7 +77,14 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
# define rbuf_check_rts_hi()
|
||||
#endif
|
||||
|
||||
void serial_init(void) { SERIAL_UART_INIT(); }
|
||||
void serial_init(void) {
|
||||
do {
|
||||
// Set baud rate
|
||||
UBRR1L = SERIAL_UART_UBRR;
|
||||
UBRR1L = SERIAL_UART_UBRR >> 8;
|
||||
SERIAL_UART_INIT_CUSTOM;
|
||||
} while (0);
|
||||
}
|
||||
|
||||
// RX ring buffer
|
||||
#define RBUF_SIZE 256
|
||||
|
||||
@@ -41,6 +41,18 @@
|
||||
#include "usb_descriptor.h"
|
||||
#include "usb_descriptor_common.h"
|
||||
|
||||
#ifdef JOYSTICK_ENABLE
|
||||
# include "joystick.h"
|
||||
#endif
|
||||
|
||||
#ifndef SERIAL_NUMBER
|
||||
#ifdef VIAL_ENABLE
|
||||
# define SERIAL_NUMBER vial:f64c2b3c
|
||||
#else
|
||||
# define SERIAL_NUMBER 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
|
||||
/*
|
||||
@@ -112,19 +124,15 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
|
||||
# endif
|
||||
HID_RI_USAGE(8, 0x01), // Pointer
|
||||
HID_RI_COLLECTION(8, 0x00), // Physical
|
||||
// Buttons (5 bits)
|
||||
// Buttons (8 bits)
|
||||
HID_RI_USAGE_PAGE(8, 0x09), // Button
|
||||
HID_RI_USAGE_MINIMUM(8, 0x01), // Button 1
|
||||
HID_RI_USAGE_MAXIMUM(8, 0x05), // Button 5
|
||||
HID_RI_USAGE_MAXIMUM(8, 0x08), // Button 8
|
||||
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
|
||||
HID_RI_REPORT_COUNT(8, 0x05),
|
||||
HID_RI_REPORT_COUNT(8, 0x08),
|
||||
HID_RI_REPORT_SIZE(8, 0x01),
|
||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
// Button padding (3 bits)
|
||||
HID_RI_REPORT_COUNT(8, 0x01),
|
||||
HID_RI_REPORT_SIZE(8, 0x03),
|
||||
HID_RI_INPUT(8, HID_IOF_CONSTANT),
|
||||
|
||||
// X/Y position (2 bytes)
|
||||
HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
|
||||
@@ -308,10 +316,17 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = {
|
||||
HID_RI_USAGE(8, 0x35), // Rz
|
||||
# endif
|
||||
# if JOYSTICK_AXES_COUNT >= 1
|
||||
HID_RI_LOGICAL_MINIMUM(8, -127),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 127),
|
||||
# if JOYSTICK_AXES_RESOLUTION == 8
|
||||
HID_RI_LOGICAL_MINIMUM(8, -JOYSTICK_RESOLUTION),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, JOYSTICK_RESOLUTION),
|
||||
HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT),
|
||||
HID_RI_REPORT_SIZE(8, 0x08),
|
||||
# else
|
||||
HID_RI_LOGICAL_MINIMUM(16, -JOYSTICK_RESOLUTION),
|
||||
HID_RI_LOGICAL_MAXIMUM(16, JOYSTICK_RESOLUTION),
|
||||
HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT),
|
||||
HID_RI_REPORT_SIZE(8, 0x10),
|
||||
# endif
|
||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
# endif
|
||||
|
||||
@@ -345,7 +360,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
|
||||
.Type = DTYPE_Device
|
||||
},
|
||||
.USBSpecification = VERSION_BCD(1, 1, 0),
|
||||
|
||||
|
||||
#if VIRTSER_ENABLE
|
||||
.Class = USB_CSCP_IADDeviceClass,
|
||||
.SubClass = USB_CSCP_IADDeviceSubclass,
|
||||
@@ -363,7 +378,11 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
|
||||
.ReleaseNumber = DEVICE_VER,
|
||||
.ManufacturerStrIndex = 0x01,
|
||||
.ProductStrIndex = 0x02,
|
||||
#if defined(SERIAL_NUMBER)
|
||||
.SerialNumStrIndex = 0x03,
|
||||
#else
|
||||
.SerialNumStrIndex = 0x00,
|
||||
#endif
|
||||
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
|
||||
};
|
||||
|
||||
@@ -939,14 +958,7 @@ const USB_Descriptor_String_t PROGMEM ProductString = {
|
||||
.UnicodeString = LSTR(PRODUCT)
|
||||
};
|
||||
|
||||
#ifndef SERIAL_NUMBER
|
||||
#ifdef VIAL_ENABLE
|
||||
# define SERIAL_NUMBER vial:f64c2b3c
|
||||
#else
|
||||
# define SERIAL_NUMBER 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SERIAL_NUMBER)
|
||||
const USB_Descriptor_String_t PROGMEM SerialNumberString = {
|
||||
.Header = {
|
||||
.Size = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1), // Subtract 1 for null terminator
|
||||
@@ -954,6 +966,7 @@ const USB_Descriptor_String_t PROGMEM SerialNumberString = {
|
||||
},
|
||||
.UnicodeString = LSTR(SERIAL_NUMBER)
|
||||
};
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
|
||||
@@ -998,11 +1011,13 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
|
||||
Size = pgm_read_byte(&ProductString.Header.Size);
|
||||
|
||||
break;
|
||||
#if defined(SERIAL_NUMBER)
|
||||
case 0x03:
|
||||
Address = &SerialNumberString;
|
||||
Size = pgm_read_byte(&SerialNumberString.Header.Size);
|
||||
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -40,13 +40,13 @@
|
||||
*
|
||||
* Header file for Descriptors.c.
|
||||
*/
|
||||
#ifndef _DESCRIPTORS_H_
|
||||
#define _DESCRIPTORS_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#ifdef PROTOCOL_CHIBIOS
|
||||
# include "hal.h"
|
||||
# include <hal.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -60,6 +60,11 @@ typedef struct {
|
||||
USB_Descriptor_Interface_t Keyboard_Interface;
|
||||
USB_HID_Descriptor_HID_t Keyboard_HID;
|
||||
USB_Descriptor_Endpoint_t Keyboard_INEndpoint;
|
||||
#else
|
||||
// Shared Interface
|
||||
USB_Descriptor_Interface_t Shared_Interface;
|
||||
USB_HID_Descriptor_HID_t Shared_HID;
|
||||
USB_Descriptor_Endpoint_t Shared_INEndpoint;
|
||||
#endif
|
||||
|
||||
#ifdef RAW_ENABLE
|
||||
@@ -77,7 +82,7 @@ typedef struct {
|
||||
USB_Descriptor_Endpoint_t Mouse_INEndpoint;
|
||||
#endif
|
||||
|
||||
#ifdef SHARED_EP_ENABLE
|
||||
#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
|
||||
// Shared Interface
|
||||
USB_Descriptor_Interface_t Shared_Interface;
|
||||
USB_HID_Descriptor_HID_t Shared_HID;
|
||||
@@ -139,6 +144,7 @@ enum usb_interfaces {
|
||||
#ifndef KEYBOARD_SHARED_EP
|
||||
KEYBOARD_INTERFACE,
|
||||
#else
|
||||
SHARED_INTERFACE,
|
||||
# define KEYBOARD_INTERFACE SHARED_INTERFACE
|
||||
#endif
|
||||
|
||||
@@ -153,7 +159,7 @@ enum usb_interfaces {
|
||||
MOUSE_INTERFACE,
|
||||
#endif
|
||||
|
||||
#ifdef SHARED_EP_ENABLE
|
||||
#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
|
||||
SHARED_INTERFACE,
|
||||
#endif
|
||||
|
||||
@@ -198,8 +204,12 @@ enum usb_endpoints {
|
||||
#endif
|
||||
|
||||
#ifdef RAW_ENABLE
|
||||
RAW_IN_EPNUM = NEXT_EPNUM,
|
||||
RAW_OUT_EPNUM = NEXT_EPNUM,
|
||||
RAW_IN_EPNUM = NEXT_EPNUM,
|
||||
# if STM32_USB_USE_OTG1
|
||||
# define RAW_OUT_EPNUM RAW_IN_EPNUM
|
||||
# else
|
||||
RAW_OUT_EPNUM = NEXT_EPNUM,
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef SHARED_EP_ENABLE
|
||||
@@ -210,28 +220,44 @@ enum usb_endpoints {
|
||||
CONSOLE_IN_EPNUM = NEXT_EPNUM,
|
||||
|
||||
# ifdef PROTOCOL_CHIBIOS
|
||||
// ChibiOS has enough memory and descriptor to actually enable the endpoint
|
||||
// It could use the same endpoint numbers, as that's supported by ChibiOS
|
||||
// But the QMK code currently assumes that the endpoint numbers are different
|
||||
// ChibiOS has enough memory and descriptor to actually enable the endpoint
|
||||
// It could use the same endpoint numbers, as that's supported by ChibiOS
|
||||
// But the QMK code currently assumes that the endpoint numbers are different
|
||||
# if STM32_USB_USE_OTG1
|
||||
# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
|
||||
# else
|
||||
CONSOLE_OUT_EPNUM = NEXT_EPNUM,
|
||||
# endif
|
||||
# else
|
||||
# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef MIDI_ENABLE
|
||||
MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
|
||||
MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
|
||||
# if STM32_USB_USE_OTG1
|
||||
# define MIDI_STREAM_OUT_EPNUM MIDI_STREAM_IN_EPNUM
|
||||
# else
|
||||
MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef VIRTSER_ENABLE
|
||||
CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
|
||||
CDC_IN_EPNUM = NEXT_EPNUM,
|
||||
CDC_OUT_EPNUM = NEXT_EPNUM,
|
||||
# if STM32_USB_USE_OTG1
|
||||
# define CDC_OUT_EPNUM CDC_IN_EPNUM
|
||||
# else
|
||||
CDC_OUT_EPNUM = NEXT_EPNUM,
|
||||
# endif
|
||||
#endif
|
||||
#ifdef JOYSTICK_ENABLE
|
||||
JOYSTICK_IN_EPNUM = NEXT_EPNUM,
|
||||
JOYSTICK_OUT_EPNUM = NEXT_EPNUM,
|
||||
JOYSTICK_IN_EPNUM = NEXT_EPNUM,
|
||||
# if STM32_USB_USE_OTG1
|
||||
JOYSTICK_OUT_EPNUM = JOYSTICK_IN_EPNUM,
|
||||
# else
|
||||
JOYSTICK_OUT_EPNUM = NEXT_EPNUM,
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -260,4 +286,3 @@ enum usb_endpoints {
|
||||
#define JOYSTICK_EPSIZE 8
|
||||
|
||||
uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const void** const DescriptorAddress);
|
||||
#endif
|
||||
|
||||
@@ -53,10 +53,10 @@ static void initForUsbConnectivity(void) {
|
||||
usbDeviceConnect();
|
||||
}
|
||||
|
||||
static void usb_remote_wakeup(void) {
|
||||
static void vusb_send_remote_wakeup(void) {
|
||||
cli();
|
||||
|
||||
int8_t ddr_orig = USBDDR;
|
||||
uint8_t ddr_orig = USBDDR;
|
||||
USBOUT |= (1 << USBMINUS);
|
||||
USBDDR = ddr_orig | USBMASK;
|
||||
USBOUT ^= USBMASK;
|
||||
@@ -70,16 +70,34 @@ static void usb_remote_wakeup(void) {
|
||||
sei();
|
||||
}
|
||||
|
||||
bool vusb_suspended = false;
|
||||
|
||||
static void vusb_suspend(void) {
|
||||
vusb_suspended = true;
|
||||
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_enable();
|
||||
#endif
|
||||
|
||||
suspend_power_down();
|
||||
}
|
||||
|
||||
#if USB_COUNT_SOF
|
||||
static void vusb_wakeup(void) {
|
||||
vusb_suspended = false;
|
||||
suspend_wakeup_init();
|
||||
|
||||
# ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_disable();
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/** \brief Setup USB
|
||||
*
|
||||
* FIXME: Needs doc
|
||||
*/
|
||||
static void setup_usb(void) {
|
||||
initForUsbConnectivity();
|
||||
|
||||
// for Console_Task
|
||||
print_set_sendchar(sendchar);
|
||||
}
|
||||
static void setup_usb(void) { initForUsbConnectivity(); }
|
||||
|
||||
/** \brief Main
|
||||
*
|
||||
@@ -87,9 +105,8 @@ static void setup_usb(void) {
|
||||
*/
|
||||
int main(void) __attribute__((weak));
|
||||
int main(void) {
|
||||
bool suspended = false;
|
||||
#if USB_COUNT_SOF
|
||||
uint16_t last_timer = timer_read();
|
||||
uint16_t sof_timer = timer_read();
|
||||
#endif
|
||||
|
||||
#ifdef CLKPR
|
||||
@@ -98,14 +115,13 @@ int main(void) {
|
||||
clock_prescale_set(clock_div_1);
|
||||
#endif
|
||||
keyboard_setup();
|
||||
|
||||
host_set_driver(vusb_driver());
|
||||
setup_usb();
|
||||
sei();
|
||||
keyboard_init();
|
||||
host_set_driver(vusb_driver());
|
||||
|
||||
wait_ms(50);
|
||||
|
||||
keyboard_init();
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_init();
|
||||
#endif
|
||||
@@ -113,23 +129,24 @@ int main(void) {
|
||||
while (1) {
|
||||
#if USB_COUNT_SOF
|
||||
if (usbSofCount != 0) {
|
||||
suspended = false;
|
||||
usbSofCount = 0;
|
||||
last_timer = timer_read();
|
||||
# ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_disable();
|
||||
# endif
|
||||
sof_timer = timer_read();
|
||||
if (vusb_suspended) {
|
||||
vusb_wakeup();
|
||||
}
|
||||
} else {
|
||||
// Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
|
||||
if (timer_elapsed(last_timer) > 5) {
|
||||
suspended = true;
|
||||
# ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_enable();
|
||||
# endif
|
||||
if (!vusb_suspended && timer_elapsed(sof_timer) > 5) {
|
||||
vusb_suspend();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!suspended) {
|
||||
if (vusb_suspended) {
|
||||
vusb_suspend();
|
||||
if (suspend_wakeup_condition()) {
|
||||
vusb_send_remote_wakeup();
|
||||
}
|
||||
} else {
|
||||
usbPoll();
|
||||
|
||||
// TODO: configuration process is inconsistent. it sometime fails.
|
||||
@@ -146,6 +163,7 @@ int main(void) {
|
||||
raw_hid_task();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_ENABLE
|
||||
usbPoll();
|
||||
|
||||
@@ -153,8 +171,10 @@ int main(void) {
|
||||
console_task();
|
||||
}
|
||||
#endif
|
||||
} else if (suspend_wakeup_condition()) {
|
||||
usb_remote_wakeup();
|
||||
|
||||
// Run housekeeping
|
||||
housekeeping_task_kb();
|
||||
housekeeping_task_user();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,19 +46,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Interface indexes
|
||||
*/
|
||||
enum usb_interfaces {
|
||||
#ifndef KEYBOARD_SHARED_EP
|
||||
KEYBOARD_INTERFACE = NEXT_INTERFACE,
|
||||
#else
|
||||
SHARED_INTERFACE = NEXT_INTERFACE,
|
||||
# define KEYBOARD_INTERFACE SHARED_INTERFACE
|
||||
#endif
|
||||
|
||||
// It is important that the Raw HID interface is at a constant
|
||||
// interface number, to support Linux/OSX platforms and chrome.hid
|
||||
// If Raw HID is enabled, let it be always 1.
|
||||
#ifdef RAW_ENABLE
|
||||
RAW_INTERFACE = NEXT_INTERFACE,
|
||||
#endif
|
||||
#if (defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE))
|
||||
MOUSE_EXTRA_INTERFACE = NEXT_INTERFACE,
|
||||
|
||||
#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
|
||||
SHARED_INTERFACE = NEXT_INTERFACE,
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_ENABLE
|
||||
CONSOLE_INTERFACE = NEXT_INTERFACE,
|
||||
#endif
|
||||
|
||||
TOTAL_INTERFACES = NEXT_INTERFACE
|
||||
};
|
||||
|
||||
@@ -90,7 +99,16 @@ void vusb_transfer_keyboard(void) {
|
||||
for (int i = 0; i < VUSB_TRANSFER_KEYBOARD_MAX_TRIES; i++) {
|
||||
if (usbInterruptIsReady()) {
|
||||
if (kbuf_head != kbuf_tail) {
|
||||
#ifndef KEYBOARD_SHARED_EP
|
||||
usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
|
||||
#else
|
||||
// Ugly hack! :(
|
||||
usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t) - 1);
|
||||
while (!usbInterruptIsReady()) {
|
||||
usbPoll();
|
||||
}
|
||||
usbSetInterrupt((void *)(&(kbuf[kbuf_tail].keys[5])), 1);
|
||||
#endif
|
||||
kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
|
||||
if (debug_keyboard) {
|
||||
dprintf("V-USB: kbuf[%d->%d](%02X)\n", kbuf_tail, kbuf_head, (kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
|
||||
@@ -230,16 +248,18 @@ static void send_keyboard(report_keyboard_t *report) {
|
||||
keyboard_report_sent = *report;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint8_t report_id;
|
||||
report_mouse_t report;
|
||||
} __attribute__((packed)) vusb_mouse_report_t;
|
||||
#ifndef KEYBOARD_SHARED_EP
|
||||
# define usbInterruptIsReadyShared usbInterruptIsReady3
|
||||
# define usbSetInterruptShared usbSetInterrupt3
|
||||
#else
|
||||
# define usbInterruptIsReadyShared usbInterruptIsReady
|
||||
# define usbSetInterruptShared usbSetInterrupt
|
||||
#endif
|
||||
|
||||
static void send_mouse(report_mouse_t *report) {
|
||||
#ifdef MOUSE_ENABLE
|
||||
vusb_mouse_report_t r = {.report_id = REPORT_ID_MOUSE, .report = *report};
|
||||
if (usbInterruptIsReady3()) {
|
||||
usbSetInterrupt3((void *)&r, sizeof(vusb_mouse_report_t));
|
||||
if (usbInterruptIsReadyShared()) {
|
||||
usbSetInterruptShared((void *)report, sizeof(report_mouse_t));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -253,8 +273,8 @@ static void send_extra(uint8_t report_id, uint16_t data) {
|
||||
last_data = data;
|
||||
|
||||
report_extra_t report = {.report_id = report_id, .usage = data};
|
||||
if (usbInterruptIsReady3()) {
|
||||
usbSetInterrupt3((void *)&report, sizeof(report));
|
||||
if (usbInterruptIsReadyShared()) {
|
||||
usbSetInterruptShared((void *)&report, sizeof(report_extra_t));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -360,10 +380,18 @@ void usbFunctionWriteOut(uchar *data, uchar len) {
|
||||
* Descriptors *
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
#ifdef KEYBOARD_SHARED_EP
|
||||
const PROGMEM uchar shared_hid_report[] = {
|
||||
# define SHARED_REPORT_STARTED
|
||||
#else
|
||||
const PROGMEM uchar keyboard_hid_report[] = {
|
||||
#endif
|
||||
0x05, 0x01, // Usage Page (Generic Desktop)
|
||||
0x09, 0x06, // Usage (Keyboard)
|
||||
0xA1, 0x01, // Collection (Application)
|
||||
#ifdef KEYBOARD_SHARED_EP
|
||||
0x85, REPORT_ID_KEYBOARD, // Report ID
|
||||
#endif
|
||||
// Modifiers (8 bits)
|
||||
0x05, 0x07, // Usage Page (Keyboard/Keypad)
|
||||
0x19, 0xE0, // Usage Minimum (Keyboard Left Control)
|
||||
@@ -398,12 +426,17 @@ const PROGMEM uchar keyboard_hid_report[] = {
|
||||
0x95, 0x01, // Report Count (1)
|
||||
0x75, 0x03, // Report Size (3)
|
||||
0x91, 0x03, // Output (Constant)
|
||||
0xC0 // End Collection
|
||||
0xC0, // End Collection
|
||||
#ifndef KEYBOARD_SHARED_EP
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
|
||||
const PROGMEM uchar mouse_extra_hid_report[] = {
|
||||
# ifdef MOUSE_ENABLE
|
||||
#if defined(SHARED_EP_ENABLE) && !defined(SHARED_REPORT_STARTED)
|
||||
const PROGMEM uchar shared_hid_report[] = {
|
||||
# define SHARED_REPORT_STARTED
|
||||
#endif
|
||||
|
||||
#ifdef MOUSE_ENABLE
|
||||
// Mouse report descriptor
|
||||
0x05, 0x01, // Usage Page (Generic Desktop)
|
||||
0x09, 0x02, // Usage (Mouse)
|
||||
@@ -411,19 +444,15 @@ const PROGMEM uchar mouse_extra_hid_report[] = {
|
||||
0x85, REPORT_ID_MOUSE, // Report ID
|
||||
0x09, 0x01, // Usage (Pointer)
|
||||
0xA1, 0x00, // Collection (Physical)
|
||||
// Buttons (5 bits)
|
||||
// Buttons (8 bits)
|
||||
0x05, 0x09, // Usage Page (Button)
|
||||
0x19, 0x01, // Usage Minimum (Button 1)
|
||||
0x29, 0x05, // Usage Maximum (Button 5)
|
||||
0x29, 0x08, // Usage Maximum (Button 8)
|
||||
0x15, 0x00, // Logical Minimum (0)
|
||||
0x25, 0x01, // Logical Maximum (1)
|
||||
0x95, 0x05, // Report Count (5)
|
||||
0x95, 0x08, // Report Count (8)
|
||||
0x75, 0x01, // Report Size (1)
|
||||
0x81, 0x02, // Input (Data, Variable, Absolute)
|
||||
// Button padding (3 bits)
|
||||
0x95, 0x01, // Report Count (1)
|
||||
0x75, 0x03, // Report Size (3)
|
||||
0x81, 0x03, // Input (Constant)
|
||||
|
||||
// X/Y position (2 bytes)
|
||||
0x05, 0x01, // Usage Page (Generic Desktop)
|
||||
@@ -452,9 +481,9 @@ const PROGMEM uchar mouse_extra_hid_report[] = {
|
||||
0x81, 0x06, // Input (Data, Variable, Relative)
|
||||
0xC0, // End Collection
|
||||
0xC0, // End Collection
|
||||
# endif
|
||||
#endif
|
||||
|
||||
# ifdef EXTRAKEY_ENABLE
|
||||
#ifdef EXTRAKEY_ENABLE
|
||||
// Extrakeys report descriptor
|
||||
0x05, 0x01, // Usage Page (Generic Desktop)
|
||||
0x09, 0x80, // Usage (System Control)
|
||||
@@ -481,7 +510,8 @@ const PROGMEM uchar mouse_extra_hid_report[] = {
|
||||
0x75, 0x10, // Report Size (16)
|
||||
0x81, 0x00, // Input (Data, Array, Absolute)
|
||||
0xC0 // End Collection
|
||||
# endif
|
||||
#endif
|
||||
#ifdef SHARED_EP_ENABLE
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -573,6 +603,7 @@ const PROGMEM usbStringDescriptor_t usbStringDescriptorProduct = {
|
||||
.bString = LSTR(PRODUCT)
|
||||
};
|
||||
|
||||
#if defined(SERIAL_NUMBER)
|
||||
const PROGMEM usbStringDescriptor_t usbStringDescriptorSerial = {
|
||||
.header = {
|
||||
.bLength = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1),
|
||||
@@ -580,6 +611,7 @@ const PROGMEM usbStringDescriptor_t usbStringDescriptorSerial = {
|
||||
},
|
||||
.bString = LSTR(SERIAL_NUMBER)
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Device descriptor
|
||||
@@ -599,7 +631,11 @@ const PROGMEM usbDeviceDescriptor_t usbDeviceDescriptor = {
|
||||
.bcdDevice = DEVICE_VER,
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
#if defined(SERIAL_NUMBER)
|
||||
.iSerialNumber = 0x03,
|
||||
#else
|
||||
.iSerialNumber = 0x00,
|
||||
#endif
|
||||
.bNumConfigurations = 1
|
||||
};
|
||||
|
||||
@@ -620,6 +656,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
|
||||
.bMaxPower = USB_MAX_POWER_CONSUMPTION / 2
|
||||
},
|
||||
|
||||
# ifndef KEYBOARD_SHARED_EP
|
||||
/*
|
||||
* Keyboard
|
||||
*/
|
||||
@@ -657,6 +694,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
|
||||
.wMaxPacketSize = 8,
|
||||
.bInterval = USB_POLLING_INTERVAL_MS
|
||||
},
|
||||
# endif
|
||||
|
||||
# if defined(RAW_ENABLE)
|
||||
/*
|
||||
@@ -682,7 +720,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
|
||||
},
|
||||
.bcdHID = 0x0101,
|
||||
.bCountryCode = 0x00,
|
||||
.bNumDescriptors = 2,
|
||||
.bNumDescriptors = 1,
|
||||
.bDescriptorType = USBDESCR_HID_REPORT,
|
||||
.wDescriptorLength = sizeof(raw_hid_report)
|
||||
},
|
||||
@@ -707,24 +745,30 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
|
||||
.bInterval = USB_POLLING_INTERVAL_MS
|
||||
},
|
||||
# endif
|
||||
# if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
|
||||
|
||||
# ifdef SHARED_EP_ENABLE
|
||||
/*
|
||||
* Mouse/Extrakeys
|
||||
* Shared
|
||||
*/
|
||||
.mouseExtraInterface = {
|
||||
.sharedInterface = {
|
||||
.header = {
|
||||
.bLength = sizeof(usbInterfaceDescriptor_t),
|
||||
.bDescriptorType = USBDESCR_INTERFACE
|
||||
},
|
||||
.bInterfaceNumber = MOUSE_EXTRA_INTERFACE,
|
||||
.bInterfaceNumber = SHARED_INTERFACE,
|
||||
.bAlternateSetting = 0x00,
|
||||
.bNumEndpoints = 1,
|
||||
.bInterfaceClass = 0x03,
|
||||
# ifdef KEYBOARD_SHARED_EP
|
||||
.bInterfaceSubClass = 0x01,
|
||||
.bInterfaceProtocol = 0x01,
|
||||
# else
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
# endif
|
||||
.iInterface = 0x00
|
||||
},
|
||||
.mouseExtraHID = {
|
||||
.sharedHID = {
|
||||
.header = {
|
||||
.bLength = sizeof(usbHIDDescriptor_t),
|
||||
.bDescriptorType = USBDESCR_HID
|
||||
@@ -733,19 +777,24 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
|
||||
.bCountryCode = 0x00,
|
||||
.bNumDescriptors = 1,
|
||||
.bDescriptorType = USBDESCR_HID_REPORT,
|
||||
.wDescriptorLength = sizeof(mouse_extra_hid_report)
|
||||
.wDescriptorLength = sizeof(shared_hid_report)
|
||||
},
|
||||
.mouseExtraINEndpoint = {
|
||||
.sharedINEndpoint = {
|
||||
.header = {
|
||||
.bLength = sizeof(usbEndpointDescriptor_t),
|
||||
.bDescriptorType = USBDESCR_ENDPOINT
|
||||
},
|
||||
# ifdef KEYBOARD_SHARED_EP
|
||||
.bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | 1),
|
||||
# else
|
||||
.bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP3_NUMBER),
|
||||
# endif
|
||||
.bmAttributes = 0x03,
|
||||
.wMaxPacketSize = 8,
|
||||
.bInterval = USB_POLLING_INTERVAL_MS
|
||||
},
|
||||
# endif
|
||||
|
||||
# if defined(CONSOLE_ENABLE)
|
||||
/*
|
||||
* Console
|
||||
@@ -793,7 +842,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
|
||||
.bmAttributes = 0x03,
|
||||
.wMaxPacketSize = CONSOLE_EPSIZE,
|
||||
.bInterval = 0x01
|
||||
},
|
||||
}
|
||||
# endif
|
||||
};
|
||||
|
||||
@@ -825,30 +874,37 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
|
||||
usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorProduct;
|
||||
len = usbStringDescriptorProduct.header.bLength;
|
||||
break;
|
||||
#if defined(SERIAL_NUMBER)
|
||||
case 3: // iSerialNumber
|
||||
usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorSerial;
|
||||
len = usbStringDescriptorSerial.header.bLength;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case USBDESCR_HID:
|
||||
switch (rq->wValue.bytes[0]) {
|
||||
#ifndef KEYBOARD_SHARED_EP
|
||||
case KEYBOARD_INTERFACE:
|
||||
usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.keyboardHID;
|
||||
len = sizeof(usbHIDDescriptor_t);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(RAW_ENABLE)
|
||||
case RAW_INTERFACE:
|
||||
usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.rawHID;
|
||||
len = sizeof(usbHIDDescriptor_t);
|
||||
break;
|
||||
#endif
|
||||
#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
|
||||
case MOUSE_EXTRA_INTERFACE:
|
||||
usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.mouseExtraHID;
|
||||
|
||||
#ifdef SHARED_EP_ENABLE
|
||||
case SHARED_INTERFACE:
|
||||
usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.sharedHID;
|
||||
len = sizeof(usbHIDDescriptor_t);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(CONSOLE_ENABLE)
|
||||
case CONSOLE_INTERFACE:
|
||||
usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.consoleHID;
|
||||
@@ -860,22 +916,27 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
|
||||
case USBDESCR_HID_REPORT:
|
||||
/* interface index */
|
||||
switch (rq->wIndex.word) {
|
||||
#ifndef KEYBOARD_SHARED_EP
|
||||
case KEYBOARD_INTERFACE:
|
||||
usbMsgPtr = (usbMsgPtr_t)keyboard_hid_report;
|
||||
len = sizeof(keyboard_hid_report);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(RAW_ENABLE)
|
||||
case RAW_INTERFACE:
|
||||
usbMsgPtr = (usbMsgPtr_t)raw_hid_report;
|
||||
len = sizeof(raw_hid_report);
|
||||
break;
|
||||
#endif
|
||||
#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
|
||||
case MOUSE_EXTRA_INTERFACE:
|
||||
usbMsgPtr = (usbMsgPtr_t)mouse_extra_hid_report;
|
||||
len = sizeof(mouse_extra_hid_report);
|
||||
|
||||
#ifdef SHARED_EP_ENABLE
|
||||
case SHARED_INTERFACE:
|
||||
usbMsgPtr = (usbMsgPtr_t)shared_hid_report;
|
||||
len = sizeof(shared_hid_report);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(CONSOLE_ENABLE)
|
||||
case CONSOLE_INTERFACE:
|
||||
usbMsgPtr = (usbMsgPtr_t)console_hid_report;
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#pragma once
|
||||
|
||||
#include "host_driver.h"
|
||||
#include <usbdrv/usbdrv.h>
|
||||
|
||||
typedef struct usbDescriptorHeader {
|
||||
uchar bLength;
|
||||
@@ -85,9 +86,16 @@ typedef struct usbHIDDescriptor {
|
||||
|
||||
typedef struct usbConfigurationDescriptor {
|
||||
usbConfigurationDescriptorHeader_t header;
|
||||
usbInterfaceDescriptor_t keyboardInterface;
|
||||
usbHIDDescriptor_t keyboardHID;
|
||||
usbEndpointDescriptor_t keyboardINEndpoint;
|
||||
|
||||
#ifndef KEYBOARD_SHARED_EP
|
||||
usbInterfaceDescriptor_t keyboardInterface;
|
||||
usbHIDDescriptor_t keyboardHID;
|
||||
usbEndpointDescriptor_t keyboardINEndpoint;
|
||||
#else
|
||||
usbInterfaceDescriptor_t sharedInterface;
|
||||
usbHIDDescriptor_t sharedHID;
|
||||
usbEndpointDescriptor_t sharedINEndpoint;
|
||||
#endif
|
||||
|
||||
#if defined(RAW_ENABLE)
|
||||
usbInterfaceDescriptor_t rawInterface;
|
||||
@@ -96,10 +104,10 @@ typedef struct usbConfigurationDescriptor {
|
||||
usbEndpointDescriptor_t rawOUTEndpoint;
|
||||
#endif
|
||||
|
||||
#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
|
||||
usbInterfaceDescriptor_t mouseExtraInterface;
|
||||
usbHIDDescriptor_t mouseExtraHID;
|
||||
usbEndpointDescriptor_t mouseExtraINEndpoint;
|
||||
#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
|
||||
usbInterfaceDescriptor_t sharedInterface;
|
||||
usbHIDDescriptor_t sharedHID;
|
||||
usbEndpointDescriptor_t sharedINEndpoint;
|
||||
#endif
|
||||
|
||||
#if defined(CONSOLE_ENABLE)
|
||||
@@ -112,5 +120,7 @@ typedef struct usbConfigurationDescriptor {
|
||||
|
||||
#define USB_STRING_LEN(s) (sizeof(usbDescriptorHeader_t) + ((s) << 1))
|
||||
|
||||
extern bool vusb_suspended;
|
||||
|
||||
host_driver_t *vusb_driver(void);
|
||||
void vusb_transfer_keyboard(void);
|
||||
|
||||
@@ -36,8 +36,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef XT_H
|
||||
#define XT_H
|
||||
#pragma once
|
||||
|
||||
#define XT_DATA_IN() \
|
||||
do { \
|
||||
@@ -69,5 +68,3 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
void xt_host_init(void);
|
||||
uint8_t xt_host_recv(void);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user