Skip to content

Commit c6ce0a2

Browse files
committed
Beginning touch support
Add a callback function for the touch device within the fixups for the GIGA. This callback simply remembers the last touch that happened and sets a semaphore. There is also a function added to retrieve this data. Needed to add the callback function into the exports file.
1 parent 42e58a8 commit c6ce0a2

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

loader/fixups.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,58 @@ SYS_INIT(disable_mpu_rasr_xn, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT)
4545
#include <zephyr/drivers/clock_control.h>
4646
#include <zephyr/logging/log.h>
4747

48+
#include <zephyr/input/input.h>
49+
50+
// experiment to try to capture touch screen events
51+
typedef struct {
52+
int32_t x;
53+
int32_t y;
54+
int32_t pressed;
55+
} touch_point_t;
56+
57+
touch_point_t last_touch_point;
58+
59+
static struct k_sem touch_event_sync;
60+
61+
bool getVideoTouchEvent(touch_point_t *tp, k_timeout_t timeout) {
62+
if (k_sem_take(&touch_event_sync, timeout) != 0) return false;
63+
// BUGBUG: should probably put stuff in to return only
64+
// data from whole event, but first see if anything works
65+
memcpy(tp, &last_touch_point, sizeof(touch_point_t));
66+
return true;
67+
}
68+
69+
70+
void touch_event_callback(struct input_event *evt, void *user_data)
71+
{
72+
//printk("touch_event_callback(%p %p): %p %u %u %u %d\n", evt, user_data,
73+
// evt->dev, evt->sync, evt->type, evt->code, evt->value);
74+
if (evt->code == INPUT_ABS_X) {
75+
last_touch_point.x = evt->value;
76+
}
77+
if (evt->code == INPUT_ABS_Y) {
78+
last_touch_point.y = evt->value;
79+
}
80+
if (evt->code == INPUT_BTN_TOUCH) {
81+
last_touch_point.pressed = evt->value;
82+
}
83+
if (evt->sync) {
84+
k_sem_give(&touch_event_sync);
85+
}
86+
}
87+
static const struct device *const touch_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_touch));
88+
INPUT_CALLBACK_DEFINE(touch_dev, touch_event_callback, NULL);
89+
90+
4891
int camera_ext_clock_enable(void)
4992
{
5093
int ret;
5194
uint32_t rate;
95+
96+
// Hack in init semaphore for touch events
97+
k_sem_init(&touch_event_sync, 0, 1);
98+
99+
52100
const struct device *cam_ext_clk_dev = DEVICE_DT_GET(DT_NODELABEL(pwmclock));
53101

54102
if (!device_is_ready(cam_ext_clk_dev)) {
@@ -99,7 +147,7 @@ int smh_init(void) {
99147
return 0;
100148
}
101149

102-
SYS_INIT(smh_init, POST_KERNEL, CONFIG_CLOCK_CONTROL_PWM_INIT_PRIORITY);
150+
SYS_INIT(smh_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
103151
#endif
104152

105153
#if defined(CONFIG_BOARD_ARDUINO_PORTENTA_C33) && defined(CONFIG_LLEXT)

loader/llext_exports.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ FORCE_EXPORT_SYM(video_buffer_aligned_alloc);
130130
FORCE_EXPORT_SYM(video_buffer_alloc);
131131
FORCE_EXPORT_SYM(video_buffer_release);
132132
#endif
133+
#if defined(CONFIG_BOARD_ARDUINO_GIGA_R1) && defined(CONFIG_VIDEO)
134+
FORCE_EXPORT_SYM(getVideoTouchEvent)
135+
#endif
133136

134137
#if defined(CONFIG_SHARED_MULTI_HEAP)
135138
FORCE_EXPORT_SYM(shared_multi_heap_aligned_alloc);

0 commit comments

Comments
 (0)