aboutsummaryrefslogtreecommitdiffstats
path: root/src/ginput/ginput_driver_keyboard.h
blob: 1d9fabf9f206eb5fc2a926855ffd3555223fe89e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * This file is subject to the terms of the GFX License. If a copy of
 * the license was not distributed with this file, you can obtain one at:
 *
 *              http://ugfx.org/license.html
 */

/**
 * @file    src/ginput/ginput_driver_keyboard.h
 * @brief   GINPUT LLD header file for keyboard drivers.
 *
 * @defgroup Keyboard Keyboard
 * @ingroup GINPUT
 * @{
 */

#ifndef _LLD_GINPUT_KEYBOARD_H
#define _LLD_GINPUT_KEYBOARD_H

#if GINPUT_NEED_KEYBOARD //|| defined(__DOXYGEN__)

// Include the GDRIVER infrastructure
#include "../gdriver/gdriver.h"

typedef struct GKeyboard {
	GDriver			d;					// The driver overheads and vmt
	uint16_t		cntc;				// The byte count in c
	uint16_t		cntsc;				// The byte count in sc
	char			c[8];				// The utf8 code for the current key
	char			sc[8];				// The scancode for the current key
	uint32_t		keystate;			// The keyboard state.
	uint16_t		flags;
		#define GKEYBOARD_FLG_NEEDREAD	0x0001
	uint16_t		laystate;			// The layout state.
	const uint8_t *	pLayout;			// The current keyboard layout
	// Other driver specific fields may follow.
} GKeyboard;

typedef struct GKeyboardVMT {
	GDriverVMT	d;											// Device flags are part of the general vmt
		#define GKEYBOARD_VFLG_NOPOLL			0x0001		// Do not poll this device - it is purely interrupt driven
		#define GKEYBOARD_VFLG_DYNAMICONLY		0x8000		// This keyboard driver should not be statically initialized eg Win32
	const uint8_t *	defLayout;								// The default keyboard layout
	gBool	(*init)(GKeyboard *m, unsigned driverinstance);	// Required
	void	(*deinit)(GKeyboard *m);						// Optional
	int		(*getdata)(GKeyboard *k, uint8_t *pch, int sz);	// Required. Get zero or more scancode bytes. Returns the number of scancode bytes returns
	void	(*putdata)(GKeyboard *k, char ch);				// Optional. Send a single byte to the keyboard.
} GKeyboardVMT;

#define gkvmt(m)		((const GKeyboardVMT const *)((m)->d.vmt))

/*===========================================================================*/
/* External declarations.                                                    */
/*===========================================================================*/

// If we are not using multiple keyboards then hard-code the VMT name
#if !defined(GINPUT_KEYBOARD_DRIVER_LIST)
	#undef GKEYBOARD_DRIVER_VMT
	#define GKEYBOARD_DRIVER_VMT		GKEYBOARDVMT_OnlyOne
#endif

#ifdef __cplusplus
extern "C" {
#endif
	/**
	 * @brief	Initialize a keyboard driver
	 *
	 * @param[in] g					The keyboard driver
	 * @param[in] param				Unused by keyboard
	 * @param[in] driverinstance	The driver instance		ToDo: Add some more details
	 * @param[in] systeminstance	The mouse instance		ToDo: Add some more details
	 *
	 * @return	gTrue on success, gFalse otherwise
	 * @note	This routine is provided by the high level code for
	 * 			use in the driver VMT's GMouseVMT.d structure.
	 *
	 * @notapi
	 */
	gBool _gkeyboardInitDriver(GDriver *g, void *param, unsigned driverinstance, unsigned systeminstance);

	/**
	 * @brief	Routine that is called after initialization
	 *
	 * @param[in] g		The keyboard driver
	 * @note	This routine is provided by the high level code for
	 * 			use in the driver VMT's GKeyboardVMT.d structure.
	 *
	 * @notapi
	 */
	void _gkeyboardPostInitDriver(GDriver *g);

	/**
	 * @brief	Deinitialize a keyboard driver
	 *
	 * @param[in] g		The kerboard driver
	 * @note	This routine is provided by the high level code for
	 * 			use in the driver VMT's GKeyboardVMT.d structure.
	 *
	 * @notapi
	 */
	void _gkeyboardDeInitDriver(GDriver *g);

	/**
	 * @brief	Wakeup the high level code so that it attempts another read
	 *
	 * @note	This routine is provided to low level drivers by the high level code
	 *
	 * @notapi
	 */
	void _gkeyboardWakeup(GKeyboard *k);

	/**
	 * @brief	Wakeup the high level code so that it attempts another read
	 *
	 * @note	This routine is provided to low level drivers by the high level code
	 *
	 * @iclass
	 * @notapi
	 */
	void _gkeyboardWakeupI(GKeyboard *k);

#ifdef __cplusplus
}
#endif

#endif /* GINPUT_NEED_KEYBOARD */

#endif /* _LLD_GINPUT_KEYBOARD_H */
/** @} */