summaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.cpp2
-rw-r--r--tmk_core/protocol/lufa/descriptor.c11
-rw-r--r--tmk_core/protocol/lufa/lufa.c34
-rw-r--r--tmk_core/protocol/lufa/lufa.h4
-rw-r--r--tmk_core/protocol/vusb.mk3
-rw-r--r--tmk_core/protocol/vusb/main.c6
-rw-r--r--tmk_core/protocol/vusb/vusb.c22
7 files changed, 59 insertions, 23 deletions
diff --git a/tmk_core/protocol/lufa/adafruit_ble.cpp b/tmk_core/protocol/lufa/adafruit_ble.cpp
index 37194e77a..fd6edd42c 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.cpp
+++ b/tmk_core/protocol/lufa/adafruit_ble.cpp
@@ -86,7 +86,7 @@ struct queue_item {
uint16_t consumer;
struct __attribute__((packed)) {
- uint8_t x, y, scroll, pan;
+ int8_t x, y, scroll, pan;
} mousemove;
};
};
diff --git a/tmk_core/protocol/lufa/descriptor.c b/tmk_core/protocol/lufa/descriptor.c
index bf47787d2..feeea76df 100644
--- a/tmk_core/protocol/lufa/descriptor.c
+++ b/tmk_core/protocol/lufa/descriptor.c
@@ -40,6 +40,9 @@
#include "report.h"
#include "descriptor.h"
+#ifndef USB_MAX_POWER_CONSUMPTION
+#define USB_MAX_POWER_CONSUMPTION 500
+#endif
/*******************************************************************************
* HID Report Descriptors
@@ -140,10 +143,10 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ExtrakeyReport[] =
HID_RI_USAGE(8, 0x80), /* System Control */
HID_RI_COLLECTION(8, 0x01), /* Application */
HID_RI_REPORT_ID(8, REPORT_ID_SYSTEM),
- HID_RI_LOGICAL_MINIMUM(16, 0x0081),
- HID_RI_LOGICAL_MAXIMUM(16, 0x00B7),
+ HID_RI_LOGICAL_MINIMUM(16, 0x0001),
+ HID_RI_LOGICAL_MAXIMUM(16, 0x0003),
HID_RI_USAGE_MINIMUM(16, 0x0081), /* System Power Down */
- HID_RI_USAGE_MAXIMUM(16, 0x00B7), /* System Display LCD Autoscale */
+ HID_RI_USAGE_MAXIMUM(16, 0x0083), /* System Wake Up */
HID_RI_REPORT_SIZE(8, 16),
HID_RI_REPORT_COUNT(8, 1),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
@@ -294,7 +297,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_REMOTEWAKEUP),
- .MaxPowerConsumption = USB_CONFIG_POWER_MA(500)
+ .MaxPowerConsumption = USB_CONFIG_POWER_MA(USB_MAX_POWER_CONSUMPTION)
},
/*
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index dd78fe621..6dd5959dc 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -732,7 +732,7 @@ static void send_system(uint16_t data)
report_extra_t r = {
.report_id = REPORT_ID_SYSTEM,
- .usage = data
+ .usage = data - SYSTEM_POWER_DOWN + 1
};
Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM);
@@ -1252,28 +1252,40 @@ void cc_callback(MidiDevice * device,
// midi_send_cc(device, (chan + 1) % 16, num, val);
}
+#ifdef API_SYSEX_ENABLE
uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0};
+#endif
void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) {
#ifdef API_SYSEX_ENABLE
// SEND_STRING("\n");
// send_word(start);
// SEND_STRING(": ");
+ // Don't store the header
+ int16_t pos = start - 4;
for (uint8_t place = 0; place < length; place++) {
// send_byte(*data);
- midi_buffer[start + place] = *data;
- if (*data == 0xF7) {
- // SEND_STRING("\nRD: ");
- // for (uint8_t i = 0; i < start + place + 1; i++){
- // send_byte(midi_buffer[i]);
- // SEND_STRING(" ");
- // }
- uint8_t * decoded = malloc(sizeof(uint8_t) * (sysex_decoded_length(start + place - 4)));
- uint16_t decode_length = sysex_decode(decoded, midi_buffer + 4, start + place - 4);
- process_api(decode_length, decoded);
+ if (pos >= 0) {
+ if (*data == 0xF7) {
+ // SEND_STRING("\nRD: ");
+ // for (uint8_t i = 0; i < start + place + 1; i++){
+ // send_byte(midi_buffer[i]);
+ // SEND_STRING(" ");
+ // }
+ const unsigned decoded_length = sysex_decoded_length(pos);
+ uint8_t decoded[API_SYSEX_MAX_SIZE];
+ sysex_decode(decoded, midi_buffer, pos);
+ process_api(decoded_length, decoded);
+ return;
+ }
+ else if (pos >= MIDI_SYSEX_BUFFER) {
+ return;
+ }
+ midi_buffer[pos] = *data;
}
// SEND_STRING(" ");
data++;
+ pos++;
}
#endif
}
diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h
index b11854101..a049fd43c 100644
--- a/tmk_core/protocol/lufa/lufa.h
+++ b/tmk_core/protocol/lufa/lufa.h
@@ -70,7 +70,6 @@ typedef struct {
#ifdef MIDI_ENABLE
void MIDI_Task(void);
MidiDevice midi_device;
- #define MIDI_SYSEX_BUFFER 32
#endif
#ifdef API_ENABLE
@@ -79,6 +78,9 @@ typedef struct {
#ifdef API_SYSEX_ENABLE
#include "api_sysex.h"
+ // Allocate space for encoding overhead.
+ //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
// #if LUFA_VERSION_INTEGER < 0x120730
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk
index 3cba3f71a..897b833e1 100644
--- a/tmk_core/protocol/vusb.mk
+++ b/tmk_core/protocol/vusb.mk
@@ -18,4 +18,5 @@ endif
# Search Path
-VPATH += $(TMK_DIR)/protocol/vusb:$(TMK_DIR)/protocol/vusb/usbdrv
+VPATH += $(TMK_PATH)/$(VUSB_DIR)
+VPATH += $(TMK_PATH)/$(VUSB_DIR)/usbdrv
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c
index 8e4a266e9..f6a0c7e9a 100644
--- a/tmk_core/protocol/vusb/main.c
+++ b/tmk_core/protocol/vusb/main.c
@@ -48,8 +48,12 @@ int main(void)
uint16_t last_timer = timer_read();
#endif
+#ifdef CLKPR
+ // avoid unintentional changes of clock frequency in devices that have a
+ // clock prescaler
CLKPR = 0x80, CLKPR = 0;
-#ifndef PS2_USE_USART
+#endif
+#ifndef NO_UART
uart_init(UART_BAUD_RATE);
#endif
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index eaa1c512d..a8c13b928 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -15,6 +15,8 @@ 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 <avr/eeprom.h>
+#include <avr/wdt.h>
#include <stdint.h>
#include "usbdrv.h"
#include "usbconfig.h"
@@ -24,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "debug.h"
#include "host_driver.h"
#include "vusb.h"
+#include "bootloader.h"
static uint8_t vusb_keyboard_leds = 0;
@@ -163,6 +166,7 @@ static struct {
uint16_t len;
enum {
NONE,
+ BOOTLOADER,
SET_LED
} kind;
} last_req;
@@ -193,6 +197,11 @@ usbRequest_t *rq = (void *)data;
debug("SET_LED: ");
last_req.kind = SET_LED;
last_req.len = rq->wLength.word;
+#ifdef BOOTLOADER_SIZE
+ } else if(rq->wValue.word == 0x0301) {
+ last_req.kind = BOOTLOADER;
+ last_req.len = rq->wLength.word;
+#endif
}
return USB_NO_MSG; // to get data in usbFunctionWrite
} else {
@@ -220,6 +229,11 @@ uchar usbFunctionWrite(uchar *data, uchar len)
last_req.len = 0;
return 1;
break;
+ case BOOTLOADER:
+ usbDeviceDisconnect();
+ bootloader_jump();
+ return 1;
+ break;
case NONE:
default:
return -1;
@@ -266,7 +280,7 @@ const PROGMEM uchar keyboard_hid_report[] = {
0x95, 0x06, // Report Count (6),
0x75, 0x08, // Report Size (8),
0x15, 0x00, // Logical Minimum (0),
- 0x25, 0xFF, 0x00 // Logical Maximum(255),
+ 0x25, 0xFF, 0x00, // Logical Maximum(255),
0x05, 0x07, // Usage Page (Key Codes),
0x19, 0x00, // Usage Minimum (0),
0x29, 0xFF, // Usage Maximum (255),
@@ -336,7 +350,7 @@ const PROGMEM uchar mouse_hid_report[] = {
0xa1, 0x01, // COLLECTION (Application)
0x85, REPORT_ID_SYSTEM, // REPORT_ID (2)
0x15, 0x01, // LOGICAL_MINIMUM (0x1)
- 0x25, 0xb7, 0x00 // LOGICAL_MAXIMUM (0xb7)
+ 0x25, 0xb7, 0x00, // LOGICAL_MAXIMUM (0xb7)
0x19, 0x01, // USAGE_MINIMUM (0x1)
0x29, 0xb7, // USAGE_MAXIMUM (0xb7)
0x75, 0x10, // REPORT_SIZE (16)
@@ -481,11 +495,11 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq)
/* interface index */
switch (rq->wIndex.word) {
case 0:
- usbMsgPtr = keyboard_hid_report;
+ usbMsgPtr = (unsigned char *)keyboard_hid_report;
len = sizeof(keyboard_hid_report);
break;
case 1:
- usbMsgPtr = mouse_hid_report;
+ usbMsgPtr = (unsigned char *)mouse_hid_report;
len = sizeof(mouse_hid_report);
break;
}