Skip to content

Commit 086d049

Browse files
committed
USB mouse support added, prepared for Model A(+)
Support for Model A(+) not tested yet and not activated
1 parent b8b2498 commit 086d049

21 files changed

+713
-119
lines changed

uspi/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ OBJS = \
4141
lib/dwhciframeschednper.o \
4242
lib/dwhciframeschedper.o \
4343
lib/dwhciregister.o \
44+
lib/dwhcirootport.o \
4445
lib/dwhcixferstagedata.o \
4546
lib/keymap.o \
4647
lib/macaddress.o \
@@ -53,6 +54,7 @@ OBJS = \
5354
lib/usbgamepad.o \
5455
lib/usbkeyboard.o \
5556
lib/usbmassdevice.o \
57+
lib/usbmouse.o \
5658
lib/usbrequest.o \
5759
lib/usbstandardhub.o \
5860
lib/uspilibrary.o \

uspi/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ USPi was "mechanically" ported from the Circle USB library which is written in C
1313
Interface
1414
---------
1515

16-
The USPi library provides functions to be used by the bare metal environment to access USB devices. There are four groups of functions which are declared in *include/uspi.h*:
16+
The USPi library provides functions to be used by the bare metal environment to access USB devices. There are five groups of functions which are declared in *include/uspi.h*:
1717

1818
* USPi initialization
1919
* Keyboard
20+
* Mouse
2021
* USB Mass storage device
2122
* Ethernet controller
2223

uspi/include/uspi.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
// USPi - An USB driver for Raspberry Pi written in C
77
// Copyright (C) 2014 R. Stange <[email protected]>
8-
//
8+
//
99
// This program is free software: you can redistribute it and/or modify
1010
// it under the terms of the GNU General Public License as published by
1111
// the Free Software Foundation, either version 3 of the License, or
@@ -63,7 +63,35 @@ void USPiKeyboardRegisterKeyStatusHandlerRaw (TUSPiKeyStatusHandlerRaw *pKeyStat
6363
// ucModifiers (bit is set if modifier key is pressed)
6464
#define LCTRL (1 << 0)
6565
#define LSHIFT (1 << 1)
66-
#define ALT (1 << 2)
66+
#define ALT (1 << 2)
67+
#define LWIN (1 << 3)
68+
#define RCTRL (1 << 4)
69+
#define RSHIFT (1 << 5)
70+
#define ALTGR (1 << 6)
71+
#define RWIN (1 << 7)
72+
73+
//
74+
// Mouse device
75+
//
76+
77+
// returns != 0 if available
78+
int USPiMouseAvailable (void);
79+
80+
// The status handler is called when the mouse sends a status report.
81+
typedef void TUSPiMouseStatusHandler (unsigned nButtons,
82+
int nDisplacementX, // -127..127
83+
int nDisplacementY); // -127..127
84+
void USPiMouseRegisterStatusHandler (TUSPiMouseStatusHandler *pStatusHandler);
85+
86+
// nButtons (bit is set if button is pressed)
87+
#define MOUSE_BUTTON1 (1 << 0)
88+
#define MOUSE_BUTTON2 (1 << 1)
89+
#define MOUSE_BUTTON3 (1 << 2)
90+
91+
// ucModifiers (bit is set if modifier key is pressed)
92+
#define LCTRL (1 << 0)
93+
#define LSHIFT (1 << 1)
94+
#define ALT (1 << 2)
6795
#define LWIN (1 << 3)
6896
#define RCTRL (1 << 4)
6997
#define RSHIFT (1 << 5)

uspi/include/uspi/dwhci.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//
22
// dwhci.h
33
//
4+
// The information in this file is from the Linux HS OTG driver
5+
// which is Copyright by Synopsys Inc.
6+
// See the file lib/README!
7+
//
48
// USPi - An USB driver for Raspberry Pi written in C
59
// Copyright (C) 2014 R. Stange <[email protected]>
610
//
@@ -95,6 +99,13 @@
9599
#define DWHCI_CORE_HW_CFG2 (ARM_USB_CORE_BASE + 0x048) // RO
96100
#define DWHCI_CORE_HW_CFG2_OP_MODE(reg) (((reg) >> 0) & 7)
97101
#define DWHCI_CORE_HW_CFG2_ARCHITECTURE(reg) (((reg) >> 3) & 3)
102+
#define DWHCI_CORE_HW_CFG2_HS_PHY_TYPE(reg) (((reg) >> 6) & 3)
103+
#define DWHCI_CORE_HW_CFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
104+
#define DWHCI_CORE_HW_CFG2_HS_PHY_TYPE_UTMI 1
105+
#define DWHCI_CORE_HW_CFG2_HS_PHY_TYPE_ULPI 2
106+
#define DWHCI_CORE_HW_CFG2_HS_PHY_TYPE_UTMI_ULPI 3
107+
#define DWHCI_CORE_HW_CFG2_FS_PHY_TYPE(reg) (((reg) >> 8) & 3)
108+
#define DWHCI_CORE_HW_CFG2_FS_PHY_TYPE_DEDICATED 1
98109
#define DWHCI_CORE_HW_CFG2_NUM_HOST_CHANNELS(reg) ((((reg) >> 14) & 0xF) + 1)
99110
#define DWHCI_CORE_HW_CFG3 (ARM_USB_CORE_BASE + 0x04C) // RO
100111
#define DWHCI_CORE_HW_CFG3_DFIFO_DEPTH(reg) (((reg) >> 16) & 0xFFFF)
@@ -123,6 +134,9 @@
123134
#define DWHCI_HOST_CFG (ARM_USB_HOST_BASE + 0x000)
124135
#define DWHCI_HOST_CFG_FSLS_PCLK_SEL__SHIFT 0
125136
#define DWHCI_HOST_CFG_FSLS_PCLK_SEL__MASK (3 << 0)
137+
#define DWHCI_HOST_CFG_FSLS_PCLK_SEL_30_60_MHZ 0
138+
#define DWHCI_HOST_CFG_FSLS_PCLK_SEL_48_MHZ 1
139+
#define DWHCI_HOST_CFG_FSLS_PCLK_SEL_6_MHZ 2
126140
#define DWHCI_HOST_FRM_INTERVAL (ARM_USB_HOST_BASE + 0x004)
127141
#define DWHCI_HOST_FRM_NUM (ARM_USB_HOST_BASE + 0x008)
128142
#define DWHCI_HOST_FRM_NUM_NUMBER(reg) ((reg) & 0xFFFF)
@@ -139,6 +153,7 @@
139153
#define DWHCI_HOST_PORT_CONNECT_CHANGED (1 << 1)
140154
#define DWHCI_HOST_PORT_ENABLE (1 << 2)
141155
#define DWHCI_HOST_PORT_ENABLE_CHANGED (1 << 3)
156+
#define DWHCI_HOST_PORT_OVERCURRENT (1 << 4)
142157
#define DWHCI_HOST_PORT_OVERCURRENT_CHANGED (1 << 5)
143158
#define DWHCI_HOST_PORT_RESET (1 << 8)
144159
#define DWHCI_HOST_PORT_POWER (1 << 12)

uspi/include/uspi/dwhcidevice.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
#include <uspi/usb.h>
2424
#include <uspi/usbendpoint.h>
2525
#include <uspi/usbrequest.h>
26+
#include <uspi/dwhcirootport.h>
2627
#include <uspi/dwhcixferstagedata.h>
2728
#include <uspi/dwhciregister.h>
2829
#include <uspi/dwhci.h>
30+
#include <uspi/usb.h>
2931
#include <uspi/types.h>
3032
#include <uspios.h>
3133

@@ -41,6 +43,8 @@ typedef struct TDWHCIDevice
4143
TDWHCITransferStageData *m_pStageData[DWHCI_MAX_CHANNELS];
4244

4345
volatile boolean m_bWaiting;
46+
47+
TDWHCIRootPort m_RootPort;
4448
}
4549
TDWHCIDevice;
4650

@@ -70,6 +74,10 @@ int DWHCIDeviceTransfer (TDWHCIDevice *pThis, TUSBEndpoint *pEndpoint, void *pBu
7074
boolean DWHCIDeviceSubmitBlockingRequest (TDWHCIDevice *pThis, TUSBRequest *pURB);
7175
boolean DWHCIDeviceSubmitAsyncRequest (TDWHCIDevice *pThis, TUSBRequest *pURB);
7276

77+
TUSBSpeed DWHCIDeviceGetPortSpeed (TDWHCIDevice *pThis);
78+
boolean DWHCIDeviceOvercurrentDetected (TDWHCIDevice *pThis);
79+
void DWHCIDeviceDisableRootPort (TDWHCIDevice *pThis);
80+
7381
#ifdef __cplusplus
7482
}
7583
#endif

uspi/include/uspi/dwhcirootport.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// dwhcirootport.h
3+
//
4+
// USPi - An USB driver for Raspberry Pi written in C
5+
// Copyright (C) 2014 R. Stange <[email protected]>
6+
//
7+
// This program is free software: you can redistribute it and/or modify
8+
// it under the terms of the GNU General Public License as published by
9+
// the Free Software Foundation, either version 3 of the License, or
10+
// (at your option) any later version.
11+
//
12+
// This program is distributed in the hope that it will be useful,
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
// GNU General Public License for more details.
16+
//
17+
// You should have received a copy of the GNU General Public License
18+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
//
20+
#ifndef _uspi_dwhcirootport_h
21+
#define _uspi_dwhcirootport_h
22+
23+
#include <uspi/usbdevice.h>
24+
#include <uspi/types.h>
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
struct TDWHCIDevice;
31+
32+
typedef struct TDWHCIRootPort
33+
{
34+
struct TDWHCIDevice *m_pHost;
35+
36+
TUSBDevice *m_pDevice;
37+
}
38+
TDWHCIRootPort;
39+
40+
void DWHCIRootPort (TDWHCIRootPort *pThis, struct TDWHCIDevice *pHost);
41+
void _DWHCIRootPort (TDWHCIRootPort *pThis);
42+
43+
boolean DWHCIRootPortInitialize (TDWHCIRootPort *pThis);
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
49+
#endif

uspi/include/uspi/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// USPi - An USB driver for Raspberry Pi written in C
55
// Copyright (C) 2014 R. Stange <[email protected]>
6-
//
6+
//
77
// This program is free software: you can redistribute it and/or modify
88
// it under the terms of the GNU General Public License as published by
99
// the Free Software Foundation, either version 3 of the License, or

uspi/include/uspi/usbhid.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// USPi - An USB driver for Raspberry Pi written in C
55
// Copyright (C) 2014 R. Stange <[email protected]>
6-
//
6+
//
77
// This program is free software: you can redistribute it and/or modify
88
// it under the terms of the GNU General Public License as published by
99
// the Free Software Foundation, either version 3 of the License, or
@@ -70,4 +70,9 @@ PACKED TUSBHIDDescriptor;
7070
#define LED_CAPS_LOCK (1 << 1)
7171
#define LED_SCROLL_LOCK (1 << 2)
7272

73+
// Mouse buttons (boot protocol)
74+
#define USBHID_BUTTON1 (1 << 0)
75+
#define USBHID_BUTTON2 (1 << 1)
76+
#define USBHID_BUTTON3 (1 << 2)
77+
7378
#endif

uspi/include/uspi/usbmouse.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// usbmouse.h
3+
//
4+
// USPi - An USB driver for Raspberry Pi written in C
5+
// Copyright (C) 2014 R. Stange <[email protected]>
6+
//
7+
// This program is free software: you can redistribute it and/or modify
8+
// it under the terms of the GNU General Public License as published by
9+
// the Free Software Foundation, either version 3 of the License, or
10+
// (at your option) any later version.
11+
//
12+
// This program is distributed in the hope that it will be useful,
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
// GNU General Public License for more details.
16+
//
17+
// You should have received a copy of the GNU General Public License
18+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
//
20+
#ifndef _usbmouse_h
21+
#define _usbmouse_h
22+
23+
#include <uspi/usbdevice.h>
24+
#include <uspi/usbendpoint.h>
25+
#include <uspi/usbrequest.h>
26+
#include <uspi/types.h>
27+
28+
#define MOUSE_BOOT_REPORT_SIZE 3
29+
30+
typedef void TMouseStatusHandler (unsigned nButtons, int nDisplacementX, int nDisplacementY);
31+
32+
typedef struct TUSBMouseDevice
33+
{
34+
TUSBDevice m_USBDevice;
35+
36+
u8 m_ucInterfaceNumber;
37+
u8 m_ucAlternateSetting;
38+
39+
TUSBEndpoint *m_pReportEndpoint;
40+
41+
TMouseStatusHandler *m_pStatusHandler;
42+
43+
TUSBRequest *m_pURB;
44+
u8 *m_pReportBuffer;
45+
}
46+
TUSBMouseDevice;
47+
48+
void USBMouseDevice (TUSBMouseDevice *pThis, TUSBDevice *pDevice);
49+
void _CUSBMouseDevice (TUSBMouseDevice *pThis);
50+
51+
boolean USBMouseDeviceConfigure (TUSBDevice *pUSBDevice);
52+
53+
void USBMouseDeviceRegisterStatusHandler (TUSBMouseDevice *pThis, TMouseStatusHandler *pStatusHandler);
54+
55+
#endif

uspi/include/uspi/usbstandardhub.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ typedef struct TUSBStandardHub
4343
}
4444
TUSBStandardHub;
4545

46-
void USBStandardHub (TUSBStandardHub *pThis, TUSBHostController *pHost, TUSBSpeed Speed);
47-
void USBStandardHub2 (TUSBStandardHub *pThis, TUSBDevice *pDevice);
46+
void USBStandardHub (TUSBStandardHub *pThis, TUSBDevice *pDevice);
4847
void _USBStandardHub (TUSBStandardHub *pThis);
4948

5049
boolean USBStandardHubInitialize (TUSBStandardHub *pThis);
51-
boolean USBStandardHubConfigure (TUSBStandardHub *pThis);
50+
boolean USBStandardHubConfigure (TUSBDevice *pUSBDevice);
51+
52+
TString *USBStandardHubGetDeviceNames (TUSBDevice *pDevice);
5253

5354
#ifdef __cplusplus
5455
}

uspi/include/uspi/uspilibrary.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// USPi - An USB driver for Raspberry Pi written in C
55
// Copyright (C) 2014 R. Stange <[email protected]>
6-
//
6+
//
77
// This program is free software: you can redistribute it and/or modify
88
// it under the terms of the GNU General Public License as published by
99
// the Free Software Foundation, either version 3 of the License, or
@@ -22,11 +22,11 @@
2222

2323
#include <uspi/devicenameservice.h>
2424
#include <uspi/dwhcidevice.h>
25-
#include <uspi/usbstandardhub.h>
2625
#include <uspi/usbkeyboard.h>
26+
#include <uspi/usbmouse.h>
27+
#include <uspi/usbgamepad.h>
2728
#include <uspi/usbmassdevice.h>
2829
#include <uspi/smsc951x.h>
29-
#include <uspi/usbgamepad.h>
3030

3131
#ifdef __cplusplus
3232
extern "C" {
@@ -36,8 +36,8 @@ typedef struct TUSPiLibrary
3636
{
3737
TDeviceNameService NameService;
3838
TDWHCIDevice DWHCI;
39-
TUSBStandardHub USBHub1;
4039
TUSBKeyboardDevice *pUKBD1;
40+
TUSBMouseDevice *pUMouse1;
4141
TUSBBulkOnlyMassStorageDevice *pUMSD1;
4242
TSMSC951xDevice *pEth0;
4343
TUSBGamePadDevice *pUPAD1;

uspi/include/uspi/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ char *strncpy (char *pDest, const char *pSrc, size_t nMaxLen);
5757

5858
char *strcat (char *pDest, const char *pSrc);
5959

60+
int uspi_char2int (char chValue); // with sign extension
61+
6062
u16 uspi_le2be16 (u16 usValue);
6163

6264
u32 uspi_le2be32 (u32 ulValue);

0 commit comments

Comments
 (0)