1 /* 2 * Copyright (c) 2022, Basalte bv 3 * Copyright (c) 2023 Nordic Semiconductor 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 #include <SDL.h> 9 #include "gpio_emul_sdl_bottom.h" 10 sdl_filter_bottom(void * arg,SDL_Event * event)11static int sdl_filter_bottom(void *arg, SDL_Event *event) 12 { 13 struct gpio_sdl_data *data = arg; 14 15 /* Only handle keyboard events */ 16 switch (event->type) { 17 case SDL_KEYDOWN: 18 case SDL_KEYUP: 19 break; 20 default: 21 return 1; 22 } 23 24 data->event_scan_code = event->key.keysym.scancode; 25 data->key_down = event->type == SDL_KEYDOWN; 26 27 return data->callback(arg); 28 } 29 gpio_sdl_init_bottom(struct gpio_sdl_data * data)30void gpio_sdl_init_bottom(struct gpio_sdl_data *data) 31 { 32 SDL_AddEventWatch(sdl_filter_bottom, (void *)data); 33 } 34