-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers gpio SDL emul: Split in top and bottom
Split the SDL GPIO emulator driver in a top and bottom to enable using it with embedded libCs. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
- Loading branch information
Showing
4 changed files
with
96 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2022, Basalte bv | ||
* Copyright (c) 2023 Nordic Semiconductor | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <SDL.h> | ||
#include "gpio_emul_sdl_bottom.h" | ||
|
||
static int sdl_filter_bottom(void *arg, SDL_Event *event) | ||
{ | ||
struct gpio_sdl_data_bottom *bottom_data = arg; | ||
|
||
/* Only handle keyboard events */ | ||
switch (event->type) { | ||
case SDL_KEYDOWN: | ||
case SDL_KEYUP: | ||
break; | ||
default: | ||
return 1; | ||
} | ||
|
||
bottom_data->event_scan_code = event->key.keysym.scancode; | ||
bottom_data->key_down = event->type == SDL_KEYDOWN; | ||
|
||
return bottom_data->callback(arg); | ||
} | ||
|
||
void gpio_sdl_init_bottom(struct gpio_sdl_data_bottom *data) | ||
{ | ||
SDL_AddEventWatch(sdl_filter_bottom, (void *)data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2022, Basalte bv | ||
* Copyright (c) 2023 Nordic Semiconductor | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* "Bottom" of the SDL GPIO emulator. | ||
* When built with the native_simulator this will be built in the runner context, | ||
* that is, with the host C library, and with the host include paths. | ||
*/ | ||
|
||
#ifndef DRIVERS_GPIO_GPIO_EMUL_SDL_BOTTOM_H | ||
#define DRIVERS_GPIO_GPIO_EMUL_SDL_BOTTOM_H | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* Note: None of these are public interfaces. But internal to the SDL GPIO emulator */ | ||
|
||
#define GPIOEMULSDL_SCANCODE_UNKNOWN 0 | ||
|
||
struct gpio_sdl_data_bottom { | ||
void *dev; | ||
int (*callback)(struct gpio_sdl_data_bottom *data); | ||
int event_scan_code; | ||
bool key_down; | ||
}; | ||
|
||
void gpio_sdl_init_bottom(struct gpio_sdl_data_bottom *data); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* DRIVERS_GPIO_GPIO_EMUL_SDL_BOTTOM_H */ |