Better keyboard driver doco and new driver configuration flag for Win32
This commit is contained in:
parent
221b8752b3
commit
610cc917cb
1 changed files with 304 additions and 250 deletions
|
@ -13,32 +13,51 @@
|
|||
#include "gdisp_lld_config.h"
|
||||
#include "src/gdisp/driver.h"
|
||||
|
||||
// Configuration parameters for this driver
|
||||
#ifndef GDISP_SCREEN_WIDTH
|
||||
#define GDISP_SCREEN_WIDTH 640
|
||||
#endif
|
||||
#ifndef GDISP_SCREEN_HEIGHT
|
||||
#define GDISP_SCREEN_HEIGHT 480
|
||||
#endif
|
||||
|
||||
// Setting this to TRUE delays updating the screen
|
||||
// to the windows paint routine. Due to the
|
||||
// drawing lock this does not add as much speed
|
||||
// as might be expected but it is still faster in
|
||||
// all tested circumstances and for all operations
|
||||
// even draw_pixel().
|
||||
// This is probably due to drawing operations being
|
||||
// combined as the update regions are merged.
|
||||
// The only time you might want to turn this off is
|
||||
// if you are debugging drawing and want to see each
|
||||
// pixel as it is set.
|
||||
#ifndef GDISP_WIN32_USE_INDIRECT_UPDATE
|
||||
/**
|
||||
* Setting this to TRUE delays updating the screen
|
||||
* to the windows paint routine. Due to the
|
||||
* drawing lock this does not add as much speed
|
||||
* as might be expected but it is still faster in
|
||||
* all tested circumstances and for all operations
|
||||
* even draw_pixel().
|
||||
* This is probably due to drawing operations being
|
||||
* combined as the update regions are merged.
|
||||
* The only time you might want to turn this off is
|
||||
* if you are debugging drawing and want to see each
|
||||
* pixel as it is set.
|
||||
*/
|
||||
#define GDISP_WIN32_USE_INDIRECT_UPDATE TRUE
|
||||
#endif
|
||||
#ifndef GKEYBOARD_WIN32_NO_LAYOUT
|
||||
/**
|
||||
* Setting this to TRUE turns off the layout engine.
|
||||
* In this situation "cooked" characters are returned but
|
||||
* shift states etc are lost.
|
||||
* As only a limited number of keyboard layouts are currently
|
||||
* defined for Win32 in uGFX (currently only US English), setting this
|
||||
* to TRUE enables the windows keyboard mapping to be pass non-English
|
||||
* characters to uGFX or to handle non-standard keyboard layouts at
|
||||
* the expense of losing special function keys etc.
|
||||
*/
|
||||
#define GKEYBOARD_WIN32_NO_LAYOUT FALSE
|
||||
#endif
|
||||
#ifndef GKEYBOARD_WIN32_DEFAULT_LAYOUT
|
||||
#define GKEYBOARD_WIN32_DEFAULT_LAYOUT KeyboardLayout_Win32_US
|
||||
#endif
|
||||
|
||||
// How far extra windows (multiple displays) should be offset from the first.
|
||||
#define DISPLAY_X_OFFSET 50
|
||||
#define DISPLAY_Y_OFFSET 50
|
||||
|
||||
// Oops - name clashes with Win32 symbols
|
||||
#undef Red
|
||||
#undef Green
|
||||
#undef Blue
|
||||
|
@ -106,14 +125,18 @@
|
|||
#endif
|
||||
|
||||
#if GINPUT_NEED_KEYBOARD
|
||||
// Include mouse support code
|
||||
#define GKEYBOARD_DRIVER_VMT GKEYBOARDVMT_Win32
|
||||
#include "src/ginput/driver_keyboard.h"
|
||||
|
||||
#if !GKEYBOARD_WIN32_NO_LAYOUT
|
||||
#if GKEYBOARD_LAYOUT_OFF
|
||||
#error "The Win32 keyboard driver is using the layout engine. Please set GKEYBOARD_LAYOUT_OFF=FALSE or GKEYBOARD_WIN32_NO_LAYOUT=TRUE."
|
||||
#endif
|
||||
|
||||
#include "src/ginput/keyboard_microcode.h"
|
||||
|
||||
// Forward definitions
|
||||
static bool_t Win32KeyboardInit(GKeyboard *k, unsigned driverinstance);
|
||||
static int Win32KeyboardGetData(GKeyboard *k, uint8_t *pch, int sz);
|
||||
extern uint8_t GKEYBOARD_WIN32_DEFAULT_LAYOUT[];
|
||||
|
||||
// This is the layout code for the English US keyboard.
|
||||
// We make it public so that a user can switch to a different layout if required.
|
||||
|
@ -346,7 +369,17 @@
|
|||
// Anything else
|
||||
/* 40 */KMC_RECORDSTART, 1, // Just send the scan code to the user
|
||||
KMC_ACT_DONE,
|
||||
|
||||
// EOF
|
||||
KMC_RECORDSTART, 0
|
||||
};
|
||||
#elif !GKEYBOARD_LAYOUT_OFF
|
||||
#warning "The WIN32 keyboard driver is not using the layout engine. If no other keyboard is using it consider defining GKEYBOARD_LAYOUT_OFF=TRUE to save code size."
|
||||
#endif
|
||||
|
||||
// Forward definitions
|
||||
static bool_t Win32KeyboardInit(GKeyboard *k, unsigned driverinstance);
|
||||
static int Win32KeyboardGetData(GKeyboard *k, uint8_t *pch, int sz);
|
||||
|
||||
const GKeyboardVMT const GKEYBOARD_DRIVER_VMT[1] = {{
|
||||
{
|
||||
|
@ -355,7 +388,14 @@
|
|||
sizeof(GKeyboard),
|
||||
_gkeyboardInitDriver, _gkeyboardPostInitDriver, _gkeyboardDeInitDriver
|
||||
},
|
||||
KeyboardLayout_Win32_US, // The Win32 keyboard layout
|
||||
|
||||
// The Win32 keyboard layout
|
||||
#if GKEYBOARD_WIN32_NO_LAYOUT
|
||||
0,
|
||||
#else
|
||||
GKEYBOARD_WIN32_DEFAULT_LAYOUT,
|
||||
#endif
|
||||
|
||||
Win32KeyboardInit, // init
|
||||
0, // deinit
|
||||
Win32KeyboardGetData, // getdata
|
||||
|
@ -554,7 +594,8 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|||
case WM_SYSKEYUP:
|
||||
case WM_KEYDOWN:
|
||||
case WM_KEYUP:
|
||||
if (keyboard && keypos < (int)sizeof(keybuffer)-1 && (wParam & 0xFF) > 0x01) {
|
||||
// A layout is being used: Send scan codes to the keyboard buffer
|
||||
if (keyboard && keyboard->pLayout && keypos < (int)sizeof(keybuffer)-1 && (wParam & 0xFF) > 0x01) {
|
||||
if (Msg == WM_KEYUP || Msg == WM_SYSKEYUP)
|
||||
keybuffer[keypos++] = 0x00; // Keyup
|
||||
else if (HIWORD(lParam) & KF_REPEAT)
|
||||
|
@ -564,8 +605,21 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|||
_gkeyboardWakeup(keyboard);
|
||||
}
|
||||
return 0;
|
||||
/*
|
||||
case WM_CHAR:
|
||||
// A layout is not being used: Send character codes to the keyboard buffer
|
||||
if (keyboard && !keyboard->pLayout && keypos < (int)sizeof(keybuffer)) {
|
||||
wchar_t w;
|
||||
int len;
|
||||
|
||||
// Convert from a UTF16 character to a UTF8 string.
|
||||
w = wParam;
|
||||
len = WideCharToMultiByte(CP_UTF8, 0, &w, 1, (char *)(keybuffer+keypos), sizeof(keybuffer)-keypos, 0, 0);
|
||||
keypos += len;
|
||||
if (len && (gkvmt(keyboard)->d.flags & GKEYBOARD_VFLG_NOPOLL)) // For normal setup this is always TRUE
|
||||
_gkeyboardWakeup(keyboard);
|
||||
}
|
||||
return 0;
|
||||
/*
|
||||
case WM_DEADCHAR:
|
||||
case WM_SYSCHAR:
|
||||
case WM_SYSDEADCHAR:
|
||||
|
|
Loading…
Add table
Reference in a new issue