Skip to content

Commit f7d5da8

Browse files
authored
Merge pull request #61 from facchinm/rpc_threaddebug
RPC improvements and other goodies
2 parents 37cf8b1 + aaebd75 commit f7d5da8

40 files changed

+8201
-11119
lines changed

.github/workflows/compile-examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
additional-sketch-paths: '"libraries/doom" "libraries/KernelDebug" "libraries/Portenta_SDCARD" "libraries/Portenta_System" "libraries/Portenta_Video" '
4646
- board:
4747
fqbn: arduino-beta:mbed:envie_m7
48-
additional-sketch-paths: '"libraries/doom" "libraries/KernelDebug" "libraries/Portenta_Audio" "libraries/Portenta_SDCARD" "libraries/Portenta_System" "libraries/Portenta_Video" "libraries/ThreadDebug" "libraries/USBHOST"'
48+
additional-sketch-paths: '"libraries/doom" "libraries/KernelDebug" "libraries/Portenta_SDCARD" "libraries/Portenta_System" "libraries/Portenta_Video" "libraries/ThreadDebug" "libraries/USBHOST"'
4949

5050
steps:
5151
- name: Checkout repository

boards.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ envie_m4.upload.maximum_size=1048576
9696
envie_m4.upload.maximum_data_size=294248
9797

9898
envie_m4.debug.tool=gdb
99+
envie_m4.bootloader.tool=openocd
100+
envie_m4.bootloader.config=-f target/stm32h7x_dual_bank.cfg
101+
envie_m4.bootloader.programmer=-f interface/stlink.cfg
102+
envie_m4.bootloader.extra_action.preflash=stm32h7x option_write 0 0x01c 0xb86aaf0
103+
envie_m4.bootloader.file=PORTENTA_H7/portentah7_bootloader_mbed_hs_v2.elf
99104

100105
##############################################################
101106

168 Bytes
Binary file not shown.
472 KB
Binary file not shown.
168 Bytes
Binary file not shown.
472 KB
Binary file not shown.
168 Bytes
Binary file not shown.
472 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <lvgl.h>
2+
3+
void portenta_init_video();
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#include "USBHost.h"
2+
#include "RPC_internal.h"
3+
4+
#ifndef CORE_CM4
5+
#error "This sketch should be compiled for Portenta (M4 core)"
6+
#endif
7+
8+
USBHost usb;
9+
10+
#define MOD_CTRL (0x01 | 0x10)
11+
#define MOD_SHIFT (0x02 | 0x20)
12+
#define MOD_ALT (0x04 | 0x40)
13+
#define MOD_WIN (0x08 | 0x80)
14+
15+
#define LED_NUM_LOCK 1
16+
#define LED_CAPS_LOCK 2
17+
#define LED_SCROLL_LOCK 4
18+
19+
static uint8_t key_leds;
20+
static const char knum[] = "1234567890";
21+
static const char ksign[] = "!@#$%^&*()";
22+
static const char tabA[] = "\t -=[]\\#;'`,./";
23+
static const char tabB[] = "\t _+{}|~:\"~<>?";
24+
// route the key event to stdin
25+
26+
static void stdin_recvchar(char ch) {
27+
RPC1.call("on_key", ch);
28+
}
29+
30+
static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys)
31+
{
32+
uint8_t modify = keys[0];
33+
uint8_t key = keys[2];
34+
uint8_t last_leds = key_leds;
35+
if (key >= KEY_A && key <= KEY_Z) {
36+
char ch = 'A' + key - KEY_A;
37+
if ( (!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK)) ) {
38+
ch += 'a' - 'A';
39+
}
40+
stdin_recvchar(ch);
41+
} else if (key >= KEY_1 && key <= KEY_0) {
42+
if (modify & MOD_SHIFT) {
43+
stdin_recvchar(ksign[key - KEY_1]);
44+
} else {
45+
stdin_recvchar(knum[key - KEY_1]);
46+
}
47+
} else if (key >= KEY_TAB && key <= KEY_SLASH) {
48+
if (modify & MOD_SHIFT) {
49+
stdin_recvchar(tabB[key - KEY_TAB]);
50+
} else {
51+
stdin_recvchar(tabA[key - KEY_TAB]);
52+
}
53+
} else if (key == KEY_ENTER) {
54+
stdin_recvchar('\r');
55+
} else if (key == KEY_CAPSLOCK) {
56+
key_leds ^= LED_CAPS_LOCK;
57+
} else if (key == KEY_NUMLOCK) {
58+
key_leds ^= LED_NUM_LOCK;
59+
} else if (key == KEY_SCROLLLOCK) {
60+
key_leds ^= LED_SCROLL_LOCK;
61+
}
62+
63+
if (key_leds != last_leds) {
64+
tusbh_set_keyboard_led(ep, key_leds);
65+
}
66+
return 0;
67+
}
68+
69+
static int process_mouse(tusbh_ep_info_t* ep, const uint8_t* mouse)
70+
{
71+
uint8_t btn = mouse[0];
72+
int8_t x = ((int8_t*)mouse)[1];
73+
int8_t y = ((int8_t*)mouse)[2];
74+
RPC1.call("on_mouse", btn, x, y);
75+
}
76+
77+
static const tusbh_boot_key_class_t cls_boot_key = {
78+
.backend = &tusbh_boot_keyboard_backend,
79+
.on_key = process_key
80+
};
81+
82+
static const tusbh_boot_mouse_class_t cls_boot_mouse = {
83+
.backend = &tusbh_boot_mouse_backend,
84+
.on_mouse = process_mouse
85+
};
86+
87+
static const tusbh_hid_class_t cls_hid = {
88+
.backend = &tusbh_hid_backend,
89+
//.on_recv_data = process_hid_recv,
90+
//.on_send_done = process_hid_sent,
91+
};
92+
93+
static const tusbh_hub_class_t cls_hub = {
94+
.backend = &tusbh_hub_backend,
95+
};
96+
97+
static const tusbh_class_reg_t class_table[] = {
98+
(tusbh_class_reg_t)&cls_boot_key,
99+
(tusbh_class_reg_t)&cls_boot_mouse,
100+
(tusbh_class_reg_t)&cls_hub,
101+
(tusbh_class_reg_t)&cls_hid,
102+
0,
103+
};
104+
105+
void setup()
106+
{
107+
Serial1.begin(115200);
108+
RPC1.begin();
109+
usb.Init(USB_CORE_ID_HS, class_table);
110+
//usb.Init(USB_CORE_ID_FS, class_table);
111+
}
112+
113+
void loop() {
114+
usb.Task();
115+
}

0 commit comments

Comments
 (0)