Skip to content

Commit f7d5da8

Browse files
authored
Merge pull request arduino#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

+1-1
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

+5
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

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <lvgl.h>
2+
3+
void portenta_init_video();
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include "Portenta_LittleVGL.h"
2+
#include "RPC_internal.h"
3+
#include "USBHost.h"
4+
5+
int16_t touchpad_x = 0;
6+
int16_t touchpad_y = 0;
7+
uint8_t button = 0;
8+
static lv_indev_drv_t indev_drv_mouse;
9+
static lv_indev_drv_t indev_drv_btn;
10+
static lv_obj_t * myCustomLabel;
11+
12+
void btn_event_cb(lv_obj_t * myCustomLabel, lv_event_t event)
13+
{
14+
if (event == LV_EVENT_CLICKED) {
15+
lv_label_set_text(myCustomLabel , "ButtonClicked");
16+
}
17+
}
18+
19+
void on_mouse(uint8_t btn, int8_t x, int8_t y) {
20+
Serial1.print("Mouse: ");
21+
Serial1.print(btn);
22+
Serial1.print(" ");
23+
Serial1.print(x);
24+
Serial1.print(" ");
25+
Serial1.println(y);
26+
touchpad_x += x;
27+
touchpad_y += y;
28+
if (touchpad_x < 0) {
29+
touchpad_x = 0;
30+
}
31+
if (touchpad_y < 0) {
32+
touchpad_y = 0;
33+
}
34+
button = btn;
35+
}
36+
37+
void on_key(char ch) {
38+
Serial1.print("Keyboard: ");
39+
Serial1.println(ch);
40+
}
41+
42+
bool my_input_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
43+
{
44+
data->point.x = touchpad_x;
45+
data->point.y = touchpad_y;
46+
data->state = LV_INDEV_STATE_REL;
47+
return false; /*No buffering now so no more data read*/
48+
}
49+
50+
bool button_read(lv_indev_drv_t * drv, lv_indev_data_t*data){
51+
static uint32_t last_btn = 0; /*Store the last pressed button*/
52+
int btn_pr = button - 1; /*Get the ID (0,1,2...) of the pressed button*/
53+
if(btn_pr >= 0) { /*Is there a button press? (E.g. -1 indicated no button was pressed)*/
54+
last_btn = btn_pr; /*Save the ID of the pressed button*/
55+
data->state = LV_INDEV_STATE_PR; /*Set the pressed state*/
56+
} else {
57+
data->state = LV_INDEV_STATE_REL; /*Set the released state*/
58+
}
59+
60+
data->btn_id = last_btn; /*Save the last button*/
61+
62+
return false; /*No buffering now so no more data read*/
63+
}
64+
void setup() {
65+
// put your setup code here, to run once:
66+
RPC1.begin();
67+
Serial1.begin(115200);
68+
RPC1.bind("on_mouse", on_mouse);
69+
RPC1.bind("on_key", on_key);
70+
portenta_init_video();
71+
72+
// Mouse pointer init
73+
lv_indev_drv_init(&indev_drv_mouse); /*Basic initialization*/
74+
indev_drv_mouse.type = LV_INDEV_TYPE_POINTER;
75+
indev_drv_mouse.read_cb = my_input_read;
76+
lv_indev_t * my_indev_mouse = lv_indev_drv_register(&indev_drv_mouse);
77+
78+
// Mouse pointer
79+
lv_obj_t * cursor_obj = lv_img_create(lv_scr_act(), NULL); //create object
80+
lv_label_set_text(cursor_obj, "Sys layer");
81+
lv_indev_set_cursor(my_indev_mouse, cursor_obj); // connect the object to the driver
82+
83+
// Mouse press
84+
lv_indev_drv_init(&indev_drv_btn); /*Basic initialization*/
85+
indev_drv_btn.type = LV_INDEV_TYPE_BUTTON;
86+
indev_drv_btn.read_cb = button_read;
87+
lv_indev_t * my_indev_btn = lv_indev_drv_register(&indev_drv_btn);
88+
89+
//Set your objects
90+
myCustomLabel = lv_label_create(lv_scr_act(), NULL);
91+
lv_obj_align(myCustomLabel, NULL, LV_ALIGN_CENTER, 0, 0);
92+
lv_label_set_text(myCustomLabel , "Button");
93+
94+
/*Assign buttons to points on the screen*/
95+
static const lv_point_t btn_points[1] = {
96+
{720/2, 480/2}, /*Button 0 -> x:10; y:10*/
97+
};
98+
lv_indev_set_button_points(my_indev_btn, btn_points);
99+
100+
101+
//Create a task
102+
//lv_task_create(label_refresher_task, 1000, LV_TASK_PRIO_MID, NULL);
103+
104+
//Assign a callback to the button
105+
lv_obj_set_event_cb(myCustomLabel, btn_event_cb);
106+
}
107+
108+
void loop() {
109+
// put your main code here, to run repeatedly:
110+
lv_task_handler();
111+
//delay(3);
112+
}

0 commit comments

Comments
 (0)