mirror of
https://gitlab.com/bztsrc/posix-uefi.git
synced 2026-01-03 15:01:33 +01:00
More examples
This commit is contained in:
parent
a76bdb6f2b
commit
6a432a12fe
12 changed files with 130 additions and 0 deletions
4
examples/07_serial/Makefile
Normal file
4
examples/07_serial/Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
TARGET = serial.efi
|
||||
|
||||
#USE_GCC=1
|
||||
include uefi/Makefile
|
||||
BIN
examples/07_serial/screenshot.png
Normal file
BIN
examples/07_serial/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
24
examples/07_serial/serial.c
Normal file
24
examples/07_serial/serial.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include <uefi.h>
|
||||
|
||||
/**
|
||||
* Use serial port
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
FILE *f;
|
||||
char buff[2];
|
||||
|
||||
if((f = fopen("/dev/serial", "r"))) {
|
||||
fwrite("sending bytes as-is with fwrite\r\n", 33, 1, f);
|
||||
fprintf(f, "sending characters automatically wchar_t/char converted with fprintf\n");
|
||||
printf("Press a key on the other side\n");
|
||||
while(!fread(buff, 1, 1, f));
|
||||
buff[1] = 0;
|
||||
printf("Got key: %02x '%s'\n", buff[0], buff);
|
||||
fclose(f);
|
||||
} else
|
||||
fprintf(stderr, "Unable to open serial port\n");
|
||||
return 0;
|
||||
}
|
||||
1
examples/07_serial/uefi
Symbolic link
1
examples/07_serial/uefi
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../uefi
|
||||
4
examples/08_pointer/Makefile
Normal file
4
examples/08_pointer/Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
TARGET = pointer.efi
|
||||
|
||||
#USE_GCC=1
|
||||
include uefi/Makefile
|
||||
32
examples/08_pointer/pointer.c
Normal file
32
examples/08_pointer/pointer.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <uefi.h>
|
||||
|
||||
/**
|
||||
* Get mouse pointer's coordinates
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
efi_status_t status;
|
||||
efi_guid_t ptrGuid = EFI_SIMPLE_POINTER_PROTOCOL_GUID;
|
||||
efi_simple_pointer_protocol_t *ptr = NULL;
|
||||
efi_simple_pointer_state_t state = {0};
|
||||
int x = 0, y = 0;
|
||||
|
||||
status = BS->LocateProtocol(&ptrGuid, NULL, (void**)&ptr);
|
||||
if(!EFI_ERROR(status) && ptr) {
|
||||
/* if we got the interface, loop until a key pressed */
|
||||
printf("move mouse around, press any key to exit\n");
|
||||
while(!getchar_ifany()) {
|
||||
ptr->GetState(ptr, &state);
|
||||
x += state.RelativeMovementX;
|
||||
y += state.RelativeMovementY;
|
||||
printf("\rx %4d y %4d btns %d %d", x, y, state.LeftButton, state.RightButton);
|
||||
/* let the CPU rest a bit */
|
||||
usleep(100);
|
||||
}
|
||||
printf("\n");
|
||||
} else
|
||||
fprintf(stderr, "unable to get simple pointer protocol\n");
|
||||
return 0;
|
||||
}
|
||||
BIN
examples/08_pointer/screenshot.png
Normal file
BIN
examples/08_pointer/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
1
examples/08_pointer/uefi
Symbolic link
1
examples/08_pointer/uefi
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../uefi
|
||||
4
examples/09_vidmodes/Makefile
Normal file
4
examples/09_vidmodes/Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
TARGET = vidmodes.efi
|
||||
|
||||
#USE_GCC=1
|
||||
include uefi/Makefile
|
||||
BIN
examples/09_vidmodes/screenshot.png
Normal file
BIN
examples/09_vidmodes/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
1
examples/09_vidmodes/uefi
Symbolic link
1
examples/09_vidmodes/uefi
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../uefi
|
||||
59
examples/09_vidmodes/vidmodes.c
Normal file
59
examples/09_vidmodes/vidmodes.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include <uefi.h>
|
||||
|
||||
/**
|
||||
* List or set GOP video modes
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
efi_status_t status;
|
||||
efi_guid_t gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
|
||||
efi_gop_t *gop = NULL;
|
||||
efi_gop_mode_info_t *info = NULL;
|
||||
uintn_t isiz = sizeof(efi_gop_mode_info_t), currentMode, i;
|
||||
|
||||
status = BS->LocateProtocol(&gopGuid, NULL, (void**)&gop);
|
||||
if(!EFI_ERROR(status) && gop) {
|
||||
/* if mode given on command line, set it */
|
||||
if(argc > 1) {
|
||||
status = gop->SetMode(gop, atoi(argv[1]));
|
||||
/* changing the resolution might mess up ConOut and StdErr, better to reset them */
|
||||
ST->ConOut->Reset(ST->ConOut, 0);
|
||||
ST->StdErr->Reset(ST->StdErr, 0);
|
||||
if(EFI_ERROR(status)) {
|
||||
fprintf(stderr, "unable to set video mode\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* we got the interface, get current mode */
|
||||
status = gop->QueryMode(gop, gop->Mode ? gop->Mode->Mode : 0, &isiz, &info);
|
||||
if(status == EFI_NOT_STARTED || !gop->Mode) {
|
||||
status = gop->SetMode(gop, 0);
|
||||
ST->ConOut->Reset(ST->ConOut, 0);
|
||||
ST->StdErr->Reset(ST->StdErr, 0);
|
||||
}
|
||||
if(EFI_ERROR(status)) {
|
||||
fprintf(stderr, "unable to get current video mode\n");
|
||||
return 0;
|
||||
}
|
||||
currentMode = gop->Mode->Mode;
|
||||
/* iterate on modes and print info */
|
||||
for(i = 0; i < gop->Mode->MaxMode; i++) {
|
||||
status = gop->QueryMode(gop, i, &isiz, &info);
|
||||
if(EFI_ERROR(status) || info->PixelFormat > PixelBitMask) continue;
|
||||
printf(" %c%3d. %4d x%4d (pitch %4d fmt %d r:%06x g:%06x b:%06x)\n",
|
||||
i == currentMode ? '*' : ' ', i,
|
||||
info->HorizontalResolution, info->VerticalResolution, info->PixelsPerScanLine, info->PixelFormat,
|
||||
info->PixelFormat==PixelRedGreenBlueReserved8BitPerColor?0xff:(
|
||||
info->PixelFormat==PixelBlueGreenRedReserved8BitPerColor?0xff0000:(
|
||||
info->PixelFormat==PixelBitMask?info->PixelInformation.RedMask:0)),
|
||||
info->PixelFormat==PixelRedGreenBlueReserved8BitPerColor ||
|
||||
info->PixelFormat==PixelBlueGreenRedReserved8BitPerColor?0xff00:(
|
||||
info->PixelFormat==PixelBitMask?info->PixelInformation.GreenMask:0),
|
||||
info->PixelFormat==PixelRedGreenBlueReserved8BitPerColor?0xff0000:(
|
||||
info->PixelFormat==PixelBlueGreenRedReserved8BitPerColor?0xff:(
|
||||
info->PixelFormat==PixelBitMask?info->PixelInformation.BlueMask:0)));
|
||||
}
|
||||
} else
|
||||
fprintf(stderr, "unable to get graphics output protocol\n");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue