Skip to content

RPC improvements and other goodies #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
additional-sketch-paths: '"libraries/doom" "libraries/KernelDebug" "libraries/Portenta_SDCARD" "libraries/Portenta_System" "libraries/Portenta_Video" '
- board:
fqbn: arduino-beta:mbed:envie_m7
additional-sketch-paths: '"libraries/doom" "libraries/KernelDebug" "libraries/Portenta_Audio" "libraries/Portenta_SDCARD" "libraries/Portenta_System" "libraries/Portenta_Video" "libraries/ThreadDebug" "libraries/USBHOST"'
additional-sketch-paths: '"libraries/doom" "libraries/KernelDebug" "libraries/Portenta_SDCARD" "libraries/Portenta_System" "libraries/Portenta_Video" "libraries/ThreadDebug" "libraries/USBHOST"'

steps:
- name: Checkout repository
Expand Down
5 changes: 5 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ envie_m4.upload.maximum_size=1048576
envie_m4.upload.maximum_data_size=294248

envie_m4.debug.tool=gdb
envie_m4.bootloader.tool=openocd
envie_m4.bootloader.config=-f target/stm32h7x_dual_bank.cfg
envie_m4.bootloader.programmer=-f interface/stlink.cfg
envie_m4.bootloader.extra_action.preflash=stm32h7x option_write 0 0x01c 0xb86aaf0
envie_m4.bootloader.file=PORTENTA_H7/portentah7_bootloader_mbed_hs_v2.elf

##############################################################

Expand Down
Binary file modified bootloaders/PORTENTA_H7/portentah7_bootloader_mbed_fs.bin
Binary file not shown.
Binary file modified bootloaders/PORTENTA_H7/portentah7_bootloader_mbed_fs.elf
Binary file not shown.
Binary file modified bootloaders/PORTENTA_H7/portentah7_bootloader_mbed_hs.bin
Binary file not shown.
Binary file modified bootloaders/PORTENTA_H7/portentah7_bootloader_mbed_hs.elf
Binary file not shown.
Binary file modified bootloaders/PORTENTA_H7/portentah7_bootloader_mbed_hs_v2.bin
Binary file not shown.
Binary file modified bootloaders/PORTENTA_H7/portentah7_bootloader_mbed_hs_v2.elf
Binary file not shown.
3 changes: 3 additions & 0 deletions libraries/LittleVGL/Portenta_LittleVGL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <lvgl.h>

void portenta_init_video();
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "USBHost.h"
#include "RPC_internal.h"

#ifndef CORE_CM4
#error "This sketch should be compiled for Portenta (M4 core)"
#endif

USBHost usb;

#define MOD_CTRL (0x01 | 0x10)
#define MOD_SHIFT (0x02 | 0x20)
#define MOD_ALT (0x04 | 0x40)
#define MOD_WIN (0x08 | 0x80)

#define LED_NUM_LOCK 1
#define LED_CAPS_LOCK 2
#define LED_SCROLL_LOCK 4

static uint8_t key_leds;
static const char knum[] = "1234567890";
static const char ksign[] = "!@#$%^&*()";
static const char tabA[] = "\t -=[]\\#;'`,./";
static const char tabB[] = "\t _+{}|~:\"~<>?";
// route the key event to stdin

static void stdin_recvchar(char ch) {
RPC1.call("on_key", ch);
}

static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys)
{
uint8_t modify = keys[0];
uint8_t key = keys[2];
uint8_t last_leds = key_leds;
if (key >= KEY_A && key <= KEY_Z) {
char ch = 'A' + key - KEY_A;
if ( (!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK)) ) {
ch += 'a' - 'A';
}
stdin_recvchar(ch);
} else if (key >= KEY_1 && key <= KEY_0) {
if (modify & MOD_SHIFT) {
stdin_recvchar(ksign[key - KEY_1]);
} else {
stdin_recvchar(knum[key - KEY_1]);
}
} else if (key >= KEY_TAB && key <= KEY_SLASH) {
if (modify & MOD_SHIFT) {
stdin_recvchar(tabB[key - KEY_TAB]);
} else {
stdin_recvchar(tabA[key - KEY_TAB]);
}
} else if (key == KEY_ENTER) {
stdin_recvchar('\r');
} else if (key == KEY_CAPSLOCK) {
key_leds ^= LED_CAPS_LOCK;
} else if (key == KEY_NUMLOCK) {
key_leds ^= LED_NUM_LOCK;
} else if (key == KEY_SCROLLLOCK) {
key_leds ^= LED_SCROLL_LOCK;
}

if (key_leds != last_leds) {
tusbh_set_keyboard_led(ep, key_leds);
}
return 0;
}

static int process_mouse(tusbh_ep_info_t* ep, const uint8_t* mouse)
{
uint8_t btn = mouse[0];
int8_t x = ((int8_t*)mouse)[1];
int8_t y = ((int8_t*)mouse)[2];
RPC1.call("on_mouse", btn, x, y);
}

static const tusbh_boot_key_class_t cls_boot_key = {
.backend = &tusbh_boot_keyboard_backend,
.on_key = process_key
};

static const tusbh_boot_mouse_class_t cls_boot_mouse = {
.backend = &tusbh_boot_mouse_backend,
.on_mouse = process_mouse
};

static const tusbh_hid_class_t cls_hid = {
.backend = &tusbh_hid_backend,
//.on_recv_data = process_hid_recv,
//.on_send_done = process_hid_sent,
};

static const tusbh_hub_class_t cls_hub = {
.backend = &tusbh_hub_backend,
};

static const tusbh_class_reg_t class_table[] = {
(tusbh_class_reg_t)&cls_boot_key,
(tusbh_class_reg_t)&cls_boot_mouse,
(tusbh_class_reg_t)&cls_hub,
(tusbh_class_reg_t)&cls_hid,
0,
};

void setup()
{
Serial1.begin(115200);
RPC1.begin();
usb.Init(USB_CORE_ID_HS, class_table);
//usb.Init(USB_CORE_ID_FS, class_table);
}

void loop() {
usb.Task();
}
112 changes: 112 additions & 0 deletions libraries/LittleVGL/examples/lvgl_rpc_usb_mouse/lvgl_rpc_usb_mouse.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include "Portenta_LittleVGL.h"
#include "RPC_internal.h"
#include "USBHost.h"

int16_t touchpad_x = 0;
int16_t touchpad_y = 0;
uint8_t button = 0;
static lv_indev_drv_t indev_drv_mouse;
static lv_indev_drv_t indev_drv_btn;
static lv_obj_t * myCustomLabel;

void btn_event_cb(lv_obj_t * myCustomLabel, lv_event_t event)
{
if (event == LV_EVENT_CLICKED) {
lv_label_set_text(myCustomLabel , "ButtonClicked");
}
}

void on_mouse(uint8_t btn, int8_t x, int8_t y) {
Serial1.print("Mouse: ");
Serial1.print(btn);
Serial1.print(" ");
Serial1.print(x);
Serial1.print(" ");
Serial1.println(y);
touchpad_x += x;
touchpad_y += y;
if (touchpad_x < 0) {
touchpad_x = 0;
}
if (touchpad_y < 0) {
touchpad_y = 0;
}
button = btn;
}

void on_key(char ch) {
Serial1.print("Keyboard: ");
Serial1.println(ch);
}

bool my_input_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
{
data->point.x = touchpad_x;
data->point.y = touchpad_y;
data->state = LV_INDEV_STATE_REL;
return false; /*No buffering now so no more data read*/
}

bool button_read(lv_indev_drv_t * drv, lv_indev_data_t*data){
static uint32_t last_btn = 0; /*Store the last pressed button*/
int btn_pr = button - 1; /*Get the ID (0,1,2...) of the pressed button*/
if(btn_pr >= 0) { /*Is there a button press? (E.g. -1 indicated no button was pressed)*/
last_btn = btn_pr; /*Save the ID of the pressed button*/
data->state = LV_INDEV_STATE_PR; /*Set the pressed state*/
} else {
data->state = LV_INDEV_STATE_REL; /*Set the released state*/
}

data->btn_id = last_btn; /*Save the last button*/

return false; /*No buffering now so no more data read*/
}
void setup() {
// put your setup code here, to run once:
RPC1.begin();
Serial1.begin(115200);
RPC1.bind("on_mouse", on_mouse);
RPC1.bind("on_key", on_key);
portenta_init_video();

// Mouse pointer init
lv_indev_drv_init(&indev_drv_mouse); /*Basic initialization*/
indev_drv_mouse.type = LV_INDEV_TYPE_POINTER;
indev_drv_mouse.read_cb = my_input_read;
lv_indev_t * my_indev_mouse = lv_indev_drv_register(&indev_drv_mouse);

// Mouse pointer
lv_obj_t * cursor_obj = lv_img_create(lv_scr_act(), NULL); //create object
lv_label_set_text(cursor_obj, "Sys layer");
lv_indev_set_cursor(my_indev_mouse, cursor_obj); // connect the object to the driver

// Mouse press
lv_indev_drv_init(&indev_drv_btn); /*Basic initialization*/
indev_drv_btn.type = LV_INDEV_TYPE_BUTTON;
indev_drv_btn.read_cb = button_read;
lv_indev_t * my_indev_btn = lv_indev_drv_register(&indev_drv_btn);

//Set your objects
myCustomLabel = lv_label_create(lv_scr_act(), NULL);
lv_obj_align(myCustomLabel, NULL, LV_ALIGN_CENTER, 0, 0);
lv_label_set_text(myCustomLabel , "Button");

/*Assign buttons to points on the screen*/
static const lv_point_t btn_points[1] = {
{720/2, 480/2}, /*Button 0 -> x:10; y:10*/
};
lv_indev_set_button_points(my_indev_btn, btn_points);


//Create a task
//lv_task_create(label_refresher_task, 1000, LV_TASK_PRIO_MID, NULL);

//Assign a callback to the button
lv_obj_set_event_cb(myCustomLabel, btn_event_cb);
}

void loop() {
// put your main code here, to run repeatedly:
lv_task_handler();
//delay(3);
}
Loading