Skip to content

Commit 7382e51

Browse files
Update
Add support for updated TinyUSB version to hopefully make it work better.
1 parent 4f58208 commit 7382e51

File tree

6 files changed

+102
-16
lines changed

6 files changed

+102
-16
lines changed

firmware/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ set(CMAKE_CXX_STANDARD 17)
77

88
# initalize pico_sdk from installed location
99
# (note this can come from environment, CMake cache etc)
10-
set(PICO_SDK_PATH "C:/Pico/pico-sdk-1.5.1")
10+
#set(PICO_SDK_PATH "C:/Pico/pico-sdk-1.5.1")
11+
#set(PICO_TINYUSB_PATH "C:/Pico/tinyusb-0.16.0")
1112

1213
# For TinyUSB
1314
set(FAMILY rp2040)

firmware/include/hid_app.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
#include "pico.h"
33
#include <stdio.h>
44
#include <stdlib.h>
5-
#include "bsp/board.h"
65
#include "pico/stdlib.h"
76

7+
// Needed to account for update in tinyUSB
8+
#if __has_include("bsp/board_api.h")
9+
#include "bsp/board_api.h"
10+
#else
11+
#include "bsp/board.h"
12+
#endif
13+
814
#include "utils.h"
915
#include "ctypes.h"
1016
#include "hid_app.h"
@@ -71,11 +77,11 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
7177

7278
#if DEBUG > 0
7379

74-
// ---------- Print out the type of device connected
75-
const char* protocol_str[] = { "None", "Keyboard", "Mouse" };
76-
const uint8_t itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);
77-
printf("HID device with address %d, instance %d, protocol %d, is a %s, has mounted.\r\n", dev_addr, instance, itf_protocol, protocol_str[itf_protocol]);
78-
fflush(stdout);
80+
// ---------- Print out the type of device connected
81+
const char* protocol_str[] = { "None", "Keyboard", "Mouse" };
82+
const uint8_t itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);
83+
printf("HID device with address %d, instance %d, protocol %d, is a %s, has mounted.\r\n", dev_addr, instance, itf_protocol, protocol_str[itf_protocol]);
84+
fflush(stdout);
7985

8086
#endif
8187

@@ -105,7 +111,8 @@ void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) {
105111
}
106112

107113
#if DEBUG
108-
printf("HID device with address %d, instance %d was unmounted.\r\n", dev_addr, instance);
114+
printf("HID device with address %d, instance %d was unmounted.\r\n", dev_addr, instance);
115+
fflush(stdout);
109116
#endif
110117
}
111118

@@ -118,7 +125,7 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
118125
// ========== Handle Mouse Reports ==========
119126
case HID_ITF_PROTOCOL_MOUSE:
120127
// If the serial terminal is not open
121-
if ( mouse_data.serial_state > 0 ) { break; };
128+
if ( mouse_data.serial_state > 0 ) { break; }
122129

123130
process_mouse_report( (hid_mouse_report_t const*) report );
124131

@@ -132,6 +139,9 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
132139
// Process Generic Report
133140
default:
134141
process_generic_report(dev_addr, instance, report, len);
142+
143+
printf("report222\n");
144+
fflush(stdout);
135145
break;
136146
}
137147

firmware/include/hid_app.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
#ifndef HID_APP_H_
22
#define HID_APP_H_
33

4-
#include "bsp/board.h"
4+
55
#include "tusb.h"
66

7+
// Needed to account for update in tinyUSB
8+
#if __has_include("bsp/board_api.h")
9+
#include "bsp/board_api.h"
10+
#else
11+
#include "bsp/board.h"
12+
#endif
13+
714
#define MAX_HID_REPORT 4
815

916
static struct

firmware/include/serial.c

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ uint8_t ID_Logitech[2][8] = {
7474
{ 0x0D, 0x4D, 0x33, 0x08, 0x01, 0x24, 0x2C, 0x27 },
7575
{ 0x29, 0x18, 0x10, 0x10, 0x11, 0x09, 0x00, 0x00 } };
7676

77+
//{ 0x52, 0x4D, 0x5A, 0x40, 0x00, 0x00, 0x00, 0x08 },
78+
7779
// MS Wheel mouse 'MZ@' + PNP
7880
uint8_t ID_Wheelmouse[11][8] = {
79-
{ 0x52, 0x4D, 0x5A, 0x40, 0x00, 0x00, 0x00, 0x08 },
81+
{ 0x52, 0x4D, 0x5A, 0x40, 0x00, 0x00, 0x00, 0x00 },
8082
{ 0x01, 0x24, 0x2D, 0x33, 0x28, 0x10, 0x10, 0x10 },
8183
{ 0x11, 0x3C, 0x10, 0x10, 0x10, 0x14, 0x10, 0x12 },
8284
{ 0x10, 0x10, 0x3C, 0x2D, 0x2F, 0x35, 0x33, 0x25 },
@@ -95,7 +97,7 @@ void serial_putc(uint8_t *buffer, int size){
9597
}
9698
}
9799

98-
void serialMouseNego() {
100+
void serialMouseNego_old() {
99101

100102
/*---------------------------------------*/
101103
// Serial Mouse negotiation //
@@ -130,7 +132,7 @@ void serialMouseNego() {
130132
// Set Serial data bits to 8 for the pnp info
131133
set_serial_data(8);
132134

133-
for( uint8_t i=0; i < 10; i++ )
135+
for( uint8_t i=0; i < 1; i++ )
134136
{
135137
for( uint8_t j=0; j < 8; j++ ) {
136138
uart_putc_raw( UART_ID, ID_Wheelmouse[i][j] );
@@ -141,7 +143,7 @@ void serialMouseNego() {
141143
}
142144

143145
// Send the last 4 characters
144-
for( uint8_t i=0; i < 4; i++ ) { uart_putc_raw( UART_ID, ID_Wheelmouse[10][i] ); }
146+
//for( uint8_t i=0; i < 4; i++ ) { uart_putc_raw( UART_ID, ID_Wheelmouse[10][i] ); }
145147

146148
// Set back to 7 bits for mouse movement
147149
set_serial_data(7);
@@ -152,13 +154,62 @@ void serialMouseNego() {
152154
sleep_us(mouse_data.serialdelay_1B);
153155
}
154156

157+
158+
void serialMouseNego() {
159+
160+
/*---------------------------------------*/
161+
// Serial Mouse negotiation //
162+
/*---------------------------------------*/
163+
// Byte1:Always M //
164+
// Byte2:[None]=MS 3=Logitech Z=MSWheel //
165+
/*---------------------------------------*/
166+
167+
// Wait for UART to be writable
168+
while ( !uart_is_writable(UART_ID) ) { tight_loop_contents(); }
169+
170+
switch ( mouse_data.persistent.mousetype ) {
171+
// Basic MS Mouse
172+
case TWOBTN:
173+
serial_putc( "\x01\x4D\x00\x00\x00\x00\x00\x00", 7);
174+
175+
break;
176+
177+
// Logitech mouse 'M3' + PNP
178+
case THREEBTN:
179+
serial_putc( "\x0D\x4D\x33\x08\x01\x24\x2C\x27", 7);
180+
serial_putc( "\x29\x18\x10\x10\x11\x09\x00\x00", 7);
181+
182+
break;
183+
184+
// MS Wheel mouse 'MZ@' + PNP
185+
case WHEELBTN:
186+
serial_putc("\x52\x4D\x5A\x40\x00\x00\x00\x00", 7);
187+
//serial_putc("\x01\x24\x2D\x33\x28\x10\x10\x10", 7);
188+
//serial_putc("\x11\x3C\x10\x10\x10\x14\x10\x12", 7);
189+
//serial_putc("\x10\x10\x3C\x2D\x2F\x35\x33\x25", 7);
190+
//serial_putc("\x3C\x30\x2E\x30\x10\x26\x10\x21", 7);
191+
//serial_putc("\x3C\x2D\x29\x23\x32\x2F\x33\x2F", 7);
192+
//serial_putc("\x26\x34\x00\x29\x2E\x34\x25\x2C", 7);
193+
//serial_putc("\x2C\x29\x2D\x2F\x35\x33\x25\x00", 7);
194+
//serial_putc("\x0D\x00\x33\x25\x32\x29\x21\x2C", 7);
195+
//serial_putc("\x00\x36\x25\x32\x33\x29\x2F\x2E", 7);
196+
//serial_putc("\x15\x16\x09\x00\x00\x00\x00\x00", 7);
197+
198+
break;
199+
}
200+
201+
busy_wait_us(mouse_data.serialdelay_1B);
202+
}
203+
155204
void printfMousePacket() {
156205
printf("Mouse: (%d %d %d)", mouse_data.mpkt.x, mouse_data.mpkt.y, mouse_data.mpkt.wheel);
206+
fflush(stdout);
157207

158208
printf(" %c%c%c\n",
159209
mouse_data.mpkt.left ? 'L' : '-',
160210
mouse_data.mpkt.middle ? 'M' : '-',
161211
mouse_data.mpkt.right ? 'R' : '-');
212+
fflush(stdout);
162213

163214
return;
164215
}

firmware/include/utils.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <math.h>
33
#include <stdio.h>
44
#include <stdlib.h>
5-
#include "bsp/board.h"
65
#include "pico/stdlib.h"
76
#include "hardware/sync.h"
87
#include "hardware/gpio.h"
@@ -11,6 +10,13 @@
1110
#include "pico/binary_info.h"
1211
#include "hardware/watchdog.h"
1312

13+
// Needed to account for update in tinyUSB
14+
#if __has_include("bsp/board_api.h")
15+
#include "bsp/board_api.h"
16+
#else
17+
#include "bsp/board.h"
18+
#endif
19+
1420
#include "utils.h"
1521
#include "core_1.h"
1622
#include "ctypes.h"

firmware/usb-2-232.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include "tusb.h"
22
#include <stdio.h>
3-
#include "bsp/board.h"
43
#include "pico/stdlib.h"
54
#include "hardware/gpio.h"
65
#include "hardware/uart.h"
76
#include "hardware/timer.h"
87
#include "pico/multicore.h"
98

9+
// Needed to account for update in tinyUSB
10+
#if __has_include("bsp/board_api.h")
11+
#include "bsp/board_api.h"
12+
#else
13+
#include "bsp/board.h"
14+
#endif
15+
1016
#include "include/utils.h"
1117
#include "include/core_1.h"
1218
#include "include/ctypes.h"
@@ -35,6 +41,11 @@ int main(){
3541
// Mild underclock
3642
set_sys_clock_khz(125000, true);
3743

44+
// If we're using an updated version of TinyUSB then enable the scrollwheel
45+
#if __has_include("bsp/board_api.h")
46+
tuh_hid_set_default_protocol(HID_PROTOCOL_REPORT);
47+
#endif
48+
3849
stdio_init_all(); // pico SDK
3950
board_init(); // init board from TinyUSB
4051
tusb_init(); // init TinyUSB

0 commit comments

Comments
 (0)