XenevaOS
Loading...
Searching...
No Matches
uspi.h
Go to the documentation of this file.
1//
2// uspi.h
3//
4// Services provided by the USPi library
5//
6// USPi - An USB driver for Raspberry Pi written in C
7// Copyright (C) 2014-2018 R. Stange <rsta2@o2online.de>
8//
9// This program is free software: you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// This program is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with this program. If not, see <http://www.gnu.org/licenses/>.
21//
22#ifndef _uspi_h
23#define _uspi_h
24
25#include "uspi/types.h"
26#include <Mm/pmmngr.h>
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31//
32// Version information
33//
34
35#define USPI_NAME "USPi library"
36
37#define USPI_MAJOR_VERSION 2
38#define USPI_MINOR_VERSION 0
39#define USPI_VERSION_STRING "2.00"
40
41//
42// USPi initialization
43//
44
45// returns 0 on failure
46int USPiInitialize (void);
47
48//
49// Keyboard device
50//
51
52// returns != 0 if available
53int USPiKeyboardAvailable (void);
54
55// "cooked mode"
56typedef void TUSPiKeyPressedHandler (const char *pString);
58
59// This handler is called when Ctrl-Alt-Del is pressed.
60typedef void TUSPiShutdownHandler (void);
62
63// Call this frequently from your application main loop to allow updating the keyboard LEDs.
64void USPiKeyboardUpdateLEDs (void);
65
66// "raw mode" (if this handler is registered the others are ignored)
67// The raw handler is called when the keyboard sends a status report (on status change and/or continously).
68typedef void TUSPiKeyStatusHandlerRaw (unsigned char ucModifiers,
69 const unsigned char RawKeys[6]); // key code or 0 in each byte
71
72// ucModifiers (bit is set if modifier key is pressed)
73#define LCTRL (1 << 0)
74#define LSHIFT (1 << 1)
75#define ALT (1 << 2)
76#define LWIN (1 << 3)
77#define RCTRL (1 << 4)
78#define RSHIFT (1 << 5)
79#define ALTGR (1 << 6)
80#define RWIN (1 << 7)
81
82// Set the keyboard LEDs in "raw mode"
83void USPiKeyboardSetLEDs (unsigned char ucLEDMask);
84#define LED_NUM_LOCK (1 << 0)
85#define LED_CAPS_LOCK (1 << 1)
86#define LED_SCROLL_LOCK (1 << 2)
87
88//
89// Mouse device
90//
91
92// returns != 0 if available
93int USPiMouseAvailable (void);
94
95// The status handler is called when the mouse sends a status report.
96typedef void TUSPiMouseStatusHandler (unsigned nButtons,
97 int nDisplacementX, // -127..127
98 int nDisplacementY); // -127..127
100
101// nButtons (bit is set if button is pressed)
102#define MOUSE_BUTTON1 (1 << 0)
103#define MOUSE_BUTTON2 (1 << 1)
104#define MOUSE_BUTTON3 (1 << 2)
105
106//
107// Mass storage device
108//
109
110// returns number of available devices
112
113#define USPI_BLOCK_SIZE 512 // other block sizes are not supported
114
115// ullOffset and nCount must be multiple of USPI_BLOCK_SIZE
116// returns number of read bytes or < 0 on failure
117// nDeviceIndex is 0-based
118int USPiMassStorageDeviceRead (unsigned long long ullOffset, void *pBuffer, unsigned nCount, unsigned nDeviceIndex);
119
120// ullOffset and nCount must be multiple of USPI_BLOCK_SIZE
121// returns number of written bytes or < 0 on failure
122// nDeviceIndex is 0-based
123int USPiMassStorageDeviceWrite (unsigned long long ullOffset, const void *pBuffer, unsigned nCount, unsigned nDeviceIndex);
124
125// returns the number of available blocks of USPI_BLOCK_SIZE or 0 on failure
126unsigned USPiMassStorageDeviceGetCapacity (unsigned nDeviceIndex);
127
128//
129// Ethernet services
130//
131// (You should delay 2 seconds after USPiInitialize before accessing the Ethernet.)
132//
133
134// checks the controller only, not if Ethernet link is up
135// returns != 0 if available
136int USPiEthernetAvailable (void);
137
138void USPiGetMACAddress (unsigned char Buffer[6]);
139
140// returns != 0 if link is up
141int USPiEthernetIsLinkUp (void);
142
143// returns 0 on failure
144int USPiSendFrame (const void *pBuffer, unsigned nLength);
145
146// pBuffer must have size USPI_FRAME_BUFFER_SIZE
147// returns 0 if no frame is available or on failure
148#define USPI_FRAME_BUFFER_SIZE 1600
149int USPiReceiveFrame (void *pBuffer, unsigned *pResultLength);
150
151//
152// GamePad device
153//
154
155// returns number of available devices
156int USPiGamePadAvailable (void);
157
158#define MAX_AXIS 6
159#define MAX_HATS 6
160
161typedef struct USPiGamePadState
162{
163 int naxes;
164 struct
165 {
166 int value;
170
171 int nhats;
173
175 unsigned int buttons;
176}
178
179// returns 0 on failure
180const USPiGamePadState *USPiGamePadGetStatus (unsigned nDeviceIndex); // nDeviceIndex is 0-based
181
182typedef void TGamePadStatusHandler (unsigned nDeviceIndex, const USPiGamePadState *pGamePadState);
184
185//
186// MIDI device
187//
188
189// returns != 0 if a MIDI device is available
190int USPiMIDIAvailable (void);
191
192// The packet handler is called once for each MIDI event packet received from the device.
193typedef void TUSPiMIDIPacketHandler (unsigned nCable, unsigned nLength, u8 *pPacket);
195
196//
197// USB device information
198//
199
200#define KEYBOARD_CLASS 1
201#define MOUSE_CLASS 2
202#define STORAGE_CLASS 3
203#define ETHERNET_CLASS 4
204#define GAMEPAD_CLASS 5
205#define MIDI_CLASS 6
206
208{
209 // from USB device descriptor
210 unsigned short idVendor;
211 unsigned short idProduct;
212 unsigned short bcdDevice;
213
214 // points to a buffer in the USPi library, empty string if not available
215 const char *pManufacturer;
216 const char *pProduct;
217}
219
220// returns 0 on failure
221int USPiDeviceGetInformation (unsigned nClass, // see above
222 unsigned nDeviceIndex, // 0-based index
223 TUSPiDeviceInformation *pInfo); // provided buffer is filled
224
225#ifdef __cplusplus
226}
227#endif
228
229#endif
uint8_t u8
Definition kernel.h:20
Definition uspi.h:208
const char * pManufacturer
Definition uspi.h:215
unsigned short idVendor
Definition uspi.h:210
unsigned short idProduct
Definition uspi.h:211
unsigned short bcdDevice
Definition uspi.h:212
const char * pProduct
Definition uspi.h:216
Definition uspi.h:162
int value
Definition uspi.h:166
int nbuttons
Definition uspi.h:174
int maximum
Definition uspi.h:168
int nhats
Definition uspi.h:171
struct USPiGamePadState::@472 axes[MAX_AXIS]
int naxes
Definition uspi.h:163
unsigned int buttons
Definition uspi.h:175
int hats[MAX_HATS]
Definition uspi.h:172
int minimum
Definition uspi.h:167
int USPiMassStorageDeviceAvailable(void)
Definition uspilibrary.c:151
void USPiKeyboardRegisterKeyPressedHandler(TUSPiKeyPressedHandler *pKeyPressedHandler)
Definition uspilibrary.c:103
#define MAX_AXIS
Definition uspi.h:158
void TUSPiShutdownHandler(void)
Definition uspi.h:60
int USPiDeviceGetInformation(unsigned nClass, unsigned nDeviceIndex, TUSPiDeviceInformation *pInfo)
Definition uspilibrary.c:338
void USPiMIDIRegisterPacketHandler(TUSPiMIDIPacketHandler *pPacketHandler)
Definition uspilibrary.c:331
int USPiMIDIAvailable(void)
Definition uspilibrary.c:325
int USPiEthernetIsLinkUp(void)
Definition uspilibrary.c:241
const USPiGamePadState * USPiGamePadGetStatus(unsigned nDeviceIndex)
Definition uspilibrary.c:310
#define MAX_HATS
Definition uspi.h:159
void USPiKeyboardUpdateLEDs(void)
Definition uspilibrary.c:117
int USPiReceiveFrame(void *pBuffer, unsigned *pResultLength)
Definition uspilibrary.c:267
void TUSPiMIDIPacketHandler(unsigned nCable, unsigned nLength, u8 *pPacket)
Definition uspi.h:193
int USPiMouseAvailable(void)
Definition uspilibrary.c:138
void TUSPiMouseStatusHandler(unsigned nButtons, int nDisplacementX, int nDisplacementY)
Definition uspi.h:96
int USPiMassStorageDeviceWrite(unsigned long long ullOffset, const void *pBuffer, unsigned nCount, unsigned nDeviceIndex)
Definition uspilibrary.c:185
int USPiEthernetAvailable(void)
Definition uspilibrary.c:216
int USPiMassStorageDeviceRead(unsigned long long ullOffset, void *pBuffer, unsigned nCount, unsigned nDeviceIndex)
Definition uspilibrary.c:167
void USPiKeyboardRegisterShutdownHandler(TUSPiShutdownHandler *pShutdownHandler)
Definition uspilibrary.c:110
void TUSPiKeyPressedHandler(const char *pString)
Definition uspi.h:56
void USPiGetMACAddress(unsigned char Buffer[6])
Definition uspilibrary.c:222
unsigned USPiMassStorageDeviceGetCapacity(unsigned nDeviceIndex)
Definition uspilibrary.c:203
int USPiSendFrame(const void *pBuffer, unsigned nLength)
Definition uspilibrary.c:254
int USPiKeyboardAvailable(void)
Definition uspilibrary.c:97
int USPiInitialize(void)
Definition uspilibrary.c:33
void USPiMouseRegisterStatusHandler(TUSPiMouseStatusHandler *pStatusHandler)
Definition uspilibrary.c:144
void USPiKeyboardRegisterKeyStatusHandlerRaw(TUSPiKeyStatusHandlerRaw *pKeyStatusHandlerRaw)
Definition uspilibrary.c:124
void USPiKeyboardSetLEDs(unsigned char ucLEDMask)
Definition uspilibrary.c:131
void TGamePadStatusHandler(unsigned nDeviceIndex, const USPiGamePadState *pGamePadState)
Definition uspi.h:182
int USPiGamePadAvailable(void)
Definition uspilibrary.c:280
void TUSPiKeyStatusHandlerRaw(unsigned char ucModifiers, const unsigned char RawKeys[6])
Definition uspi.h:68
void USPiGamePadRegisterStatusHandler(TGamePadStatusHandler *pStatusHandler)
Definition uspilibrary.c:296