Skip to content

Commit 7abe8c3

Browse files
committed
GIGA touch - callback to simple forward instead of processing in the fixups.c
Add a callback function for the touch device within the fixups for the GIGA. Needed to add function to set the callback function. Also add clear out the callback in the initVariant such that if new program is launched it does not use old address, and instead uses the new address or not at all if the new sketch does not use touch.
1 parent 6621efb commit 7abe8c3

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

loader/fixups.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,86 @@ 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+
#define GIGA_TOUCH_SET_CB
52+
#ifdef GIGA_TOUCH_SET_CB
53+
// This version we just register a callback function with the zephyr
54+
// object, which then allows are Arduino Code to register a call back
55+
// to be called...
56+
57+
58+
void (*_giga_touch_callback)(struct input_event *evt, void *user_data) = 0;
59+
60+
void registerGigaTouchCallback(void (*cb)(struct input_event *evt, void *user_data)) {
61+
_giga_touch_callback = cb;
62+
}
63+
64+
65+
void touch_event_callback(struct input_event *evt, void *user_data)
66+
{
67+
//printk("touch_event_callback(%p %p): %p %u %u %u %d\n", evt, user_data,
68+
// evt->dev, evt->sync, evt->type, evt->code, evt->value);
69+
if (_giga_touch_callback) {
70+
(*_giga_touch_callback)(evt, user_data);
71+
72+
}
73+
}
74+
#else
75+
typedef struct {
76+
size_t x;
77+
size_t y;
78+
bool pressed;
79+
} touch_point_t;
80+
81+
touch_point_t last_touch_point;
82+
83+
static struct k_sem touch_event_sync;
84+
85+
bool getVideoTouchEvent(touch_point_t *tp, k_timeout_t timeout) {
86+
if (k_sem_take(&touch_event_sync, timeout) != 0) return false;
87+
// BUGBUG: should probably put stuff in to return only
88+
// data from whole event, but first see if anything works
89+
memcpy(tp, &last_touch_point, sizeof(touch_point_t));
90+
return true;
91+
}
92+
93+
94+
void touch_event_callback(struct input_event *evt, void *user_data)
95+
{
96+
//printk("touch_event_callback(%p %p): %p %u %u %u %d\n", evt, user_data,
97+
// evt->dev, evt->sync, evt->type, evt->code, evt->value);
98+
if (evt->code == INPUT_ABS_X) {
99+
last_touch_point.x = evt->value;
100+
}
101+
if (evt->code == INPUT_ABS_Y) {
102+
last_touch_point.y = evt->value;
103+
}
104+
if (evt->code == INPUT_BTN_TOUCH) {
105+
last_touch_point.pressed = evt->value;
106+
}
107+
if (evt->sync) {
108+
k_sem_give(&touch_event_sync);
109+
}
110+
}
111+
#endif
112+
113+
static const struct device *const touch_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_touch));
114+
INPUT_CALLBACK_DEFINE(touch_dev, touch_event_callback, NULL);
115+
116+
117+
48118
int camera_ext_clock_enable(void)
49119
{
50120
int ret;
51121
uint32_t rate;
122+
123+
#ifndef GIGA_TOUCH_SET_CB
124+
// Hack in init semaphore for touch events
125+
k_sem_init(&touch_event_sync, 0, 1);
126+
#endif
127+
52128
const struct device *cam_ext_clk_dev = DEVICE_DT_GET(DT_NODELABEL(pwmclock));
53129

54130
if (!device_is_ready(cam_ext_clk_dev)) {

loader/llext_exports.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ FORCE_EXPORT_SYM(video_buffer_aligned_alloc);
133133
FORCE_EXPORT_SYM(video_buffer_alloc);
134134
FORCE_EXPORT_SYM(video_buffer_release);
135135
FORCE_EXPORT_SYM(video_set_ctrl);
136+
#endif
137+
#if defined(CONFIG_BOARD_ARDUINO_GIGA_R1) && defined(CONFIG_VIDEO)
138+
//FORCE_EXPORT_SYM(getVideoTouchEvent);
139+
FORCE_EXPORT_SYM(registerGigaTouchCallback);
140+
136141
#endif
137142

138143
#if defined(CONFIG_SHARED_MULTI_HEAP)

variants/arduino_giga_r1_stm32h747xx_m7/variant.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ void _on_1200_bps() {
66
*(__IO uint32_t *)tmp = (uint32_t)0xDF59;
77
NVIC_SystemReset();
88
}
9+
10+
extern "C" void registerGigaTouchCallback(void (*cb)(struct input_event *evt, void *user_data));
11+
void initVariant(void) {
12+
// Make sure to set to NULL in case previous sketch or pvevious build of sketch
13+
// set a callback, whoes pointer may not be valid
14+
registerGigaTouchCallback(nullptr);
15+
}

0 commit comments

Comments
 (0)