Skip to content

Beginning touch support #134

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

Open
wants to merge 2 commits into
base: arduino
Choose a base branch
from
Open
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
78 changes: 77 additions & 1 deletion loader/fixups.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,86 @@ SYS_INIT(disable_mpu_rasr_xn, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT)
#include <zephyr/drivers/clock_control.h>
#include <zephyr/logging/log.h>

#include <zephyr/input/input.h>

// experiment to try to capture touch screen events
#define GIGA_TOUCH_SET_CB
#ifdef GIGA_TOUCH_SET_CB
// This version we just register a callback function with the zephyr
// object, which then allows are Arduino Code to register a call back
// to be called...


void (*_giga_touch_callback)(struct input_event *evt, void *user_data) = 0;

void registerGigaTouchCallback(void (*cb)(struct input_event *evt, void *user_data)) {
_giga_touch_callback = cb;
}


void touch_event_callback(struct input_event *evt, void *user_data)
{
//printk("touch_event_callback(%p %p): %p %u %u %u %d\n", evt, user_data,
// evt->dev, evt->sync, evt->type, evt->code, evt->value);
if (_giga_touch_callback) {
(*_giga_touch_callback)(evt, user_data);

}
}
#else
typedef struct {
size_t x;
size_t y;
bool pressed;
} touch_point_t;

touch_point_t last_touch_point;

static struct k_sem touch_event_sync;

bool getVideoTouchEvent(touch_point_t *tp, k_timeout_t timeout) {
if (k_sem_take(&touch_event_sync, timeout) != 0) return false;
// BUGBUG: should probably put stuff in to return only
// data from whole event, but first see if anything works
memcpy(tp, &last_touch_point, sizeof(touch_point_t));
return true;
}


void touch_event_callback(struct input_event *evt, void *user_data)
{
//printk("touch_event_callback(%p %p): %p %u %u %u %d\n", evt, user_data,
// evt->dev, evt->sync, evt->type, evt->code, evt->value);
if (evt->code == INPUT_ABS_X) {
last_touch_point.x = evt->value;
}
if (evt->code == INPUT_ABS_Y) {
last_touch_point.y = evt->value;
}
if (evt->code == INPUT_BTN_TOUCH) {
last_touch_point.pressed = evt->value;
}
if (evt->sync) {
k_sem_give(&touch_event_sync);
}
}
#endif

static const struct device *const touch_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_touch));
INPUT_CALLBACK_DEFINE(touch_dev, touch_event_callback, NULL);



int camera_ext_clock_enable(void)
{
int ret;
uint32_t rate;

#ifndef GIGA_TOUCH_SET_CB
// Hack in init semaphore for touch events
k_sem_init(&touch_event_sync, 0, 1);
#endif

const struct device *cam_ext_clk_dev = DEVICE_DT_GET(DT_NODELABEL(pwmclock));

if (!device_is_ready(cam_ext_clk_dev)) {
Expand Down Expand Up @@ -99,7 +175,7 @@ int smh_init(void) {
return 0;
}

SYS_INIT(smh_init, POST_KERNEL, CONFIG_CLOCK_CONTROL_PWM_INIT_PRIORITY);
SYS_INIT(smh_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
#endif

#if defined(CONFIG_BOARD_ARDUINO_PORTENTA_C33) && defined(CONFIG_LLEXT)
Expand Down
5 changes: 5 additions & 0 deletions loader/llext_exports.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ FORCE_EXPORT_SYM(__stack_chk_fail);
FORCE_EXPORT_SYM(video_buffer_aligned_alloc);
FORCE_EXPORT_SYM(video_buffer_alloc);
FORCE_EXPORT_SYM(video_buffer_release);
#endif
#if defined(CONFIG_BOARD_ARDUINO_GIGA_R1) && defined(CONFIG_VIDEO)
//FORCE_EXPORT_SYM(getVideoTouchEvent);
FORCE_EXPORT_SYM(registerGigaTouchCallback);

#endif

#if defined(CONFIG_SHARED_MULTI_HEAP)
Expand Down
7 changes: 7 additions & 0 deletions variants/arduino_giga_r1_stm32h747xx_m7/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ void _on_1200_bps() {
*(__IO uint32_t *)tmp = (uint32_t)0xDF59;
NVIC_SystemReset();
}

extern "C" void registerGigaTouchCallback(void (*cb)(struct input_event *evt, void *user_data));
void initVariant(void) {
// Make sure to set to NULL in case previous sketch or pvevious build of sketch
// set a callback, whoes pointer may not be valid
registerGigaTouchCallback(nullptr);
}