Skip to content

Commit

Permalink
USB mouse support added, prepared for Model A(+)
Browse files Browse the repository at this point in the history
README.md is not updated yet
Model A(+) support is not tested yet and not activated

class CUSBHIDDevice added
class CUSBMouseDevice added
class CUSBKeyboardDevice is based on CUSBHIDDevice now

Library libinput.a added (must be used together with libusb.a)
class CKeyMap moved to input
class CKeyboardBehaviour added to input

class CDWHCIRootPort added
CUSBStandardHub must not be instanciated in CKernel anymore!
sample/10-usbmouse added
Other USB samples updated
  • Loading branch information
rsta2 committed Nov 19, 2014
1 parent 631c22e commit 1bf7a96
Show file tree
Hide file tree
Showing 49 changed files with 1,413 additions and 377 deletions.
3 changes: 3 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ For what

Aurelien Bidon
Improving build and .git support

tufty
Architectural advise
11 changes: 9 additions & 2 deletions doc/classes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ USB library
* CDWHCIFrameSchedulerNonPeriodic: Schedules the transmission of non-interrupt split frames to non-high-speed devices
* CDWHCIFrameSchedulerPeriodic: Schedules the transmission of interrupt split frames to non-high-speed devices
* CDWHCIRegister: Supporting class for CDWHCIDevice, encapsulates a register of the HCI.
* CDWHCIRootPort: Supporting class for CDWHCIDevice, initializes the root port.
* CDWHCITransferStageData: Holds all the data needed for a transfer stage on one HCI channel.
* CKeyMap: Keyboard translation map (two selectable default maps at the moment)
* CMACAddress: Encapsulates an Ethernet MAC address.
* CNetDevice: Base class of CSMSC951xDevice.
* CSMSC951xDevice: Driver for the on-board USB Ethernet device.
Expand All @@ -39,7 +39,14 @@ USB library
* CUSBDevice: Encapsulates a general USB device (basic device initialization, derived from CDevice).
* CUSBDeviceFactory: Creates the device objects of the different supported USB devices.
* CUSBEndpoint: Encapsulates an endpoint of an USB device (supports control, bulk and interrupt EPs).
* CUSBHIDDevice: General USB HID device (e.g. keyboard, mouse), boot protocol only
* CUSBHostController: Base class of CDWHCIDevice, some basic functions for host controllers.
* CUSBKeyboardDevice: Driver for USB keyboards
* CUSBMouseDevice: Driver for USB mice
* CUSBRequest: A request to an USB device (URB).
* CUSBStandardHub: USB hub driver for LAN9512/9514 hub (not tested with external hubs but may work)
* CUSBStandardHub: USB hub driver for LAN9512/9514 and external hubs (max. 8 ports)

Input library

* CKeyboardBehaviour: Generic keyboard function
* CKeyMap: Keyboard translation map (two selectable default maps at the moment)
9 changes: 0 additions & 9 deletions doc/tasklist.txt

This file was deleted.

90 changes: 90 additions & 0 deletions include/circle/input/keyboardbehaviour.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// keyboardbehaviour.h
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2014 R. Stange <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _circle_input_keyboardbehaviour_h
#define _circle_input_keyboardbehaviour_h

#include <circle/input/keymap.h>
#include <circle/types.h>

enum TModifierKey
{
ModifierKeyLeftCtrl = 0x80,
ModifierKeyLeftShift,
ModifierKeyAlt,
ModifierKeyLeftWin,
ModifierKeyRightCtrl,
ModifierKeyRightShift,
ModifierKeyAltGr,
ModifierKeyRightWin,
ModifierKeyUnknown
};

#define KEY_LCTRL_MASK (1 << 0)
#define KEY_LSHIFT_MASK (1 << 1)
#define KEY_ALT_MASK (1 << 2)
#define KEY_LWIN_MASK (1 << 3)
#define KEY_RCTRL_MASK (1 << 4)
#define KEY_RSHIFT_MASK (1 << 5)
#define KEY_ALTGR_MASK (1 << 6)
#define KEY_RWIN_MASK (1 << 7)

#define KEYB_LED_NUM_LOCK (1 << 0)
#define KEYB_LED_CAPS_LOCK (1 << 1)
#define KEYB_LED_SCROLL_LOCK (1 << 2)

typedef void TKeyPressedHandler (const char *pString);
typedef void TSelectConsoleHandler (unsigned nConsole);
typedef void TShutdownHandler (void);

class CKeyboardBehaviour
{
public:
CKeyboardBehaviour (void);
~CKeyboardBehaviour (void);

void RegisterKeyPressedHandler (TKeyPressedHandler *pKeyPressedHandler);
void RegisterSelectConsoleHandler (TSelectConsoleHandler *pSelectConsoleHandler);
void RegisterShutdownHandler (TShutdownHandler *pShutdownHandler);

void KeyPressed (u8 ucKeyCode);
void KeyReleased (u8 ucKeyCode);

u8 GetLEDStatus (void) const;

private:
void GenerateKeyEvent (u8 ucKeyCode);

void TimerHandler (unsigned hTimer);
static void TimerStub (unsigned hTimer, void *pParam, void *pContext);

private:
TKeyPressedHandler *m_pKeyPressedHandler;
TSelectConsoleHandler *m_pSelectConsoleHandler;
TShutdownHandler *m_pShutdownHandler;

u8 m_ucModifiers;
u8 m_ucLastKeyCode;

unsigned m_hTimer;

CKeyMap m_KeyMap;
};

#endif
File renamed without changes.
11 changes: 11 additions & 0 deletions include/circle/usb/dwhci.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
#define DWHCI_CORE_HW_CFG2 (ARM_USB_CORE_BASE + 0x048) // RO
#define DWHCI_CORE_HW_CFG2_OP_MODE(reg) (((reg) >> 0) & 7)
#define DWHCI_CORE_HW_CFG2_ARCHITECTURE(reg) (((reg) >> 3) & 3)
#define DWHCI_CORE_HW_CFG2_HS_PHY_TYPE(reg) (((reg) >> 6) & 3)
#define DWHCI_CORE_HW_CFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
#define DWHCI_CORE_HW_CFG2_HS_PHY_TYPE_UTMI 1
#define DWHCI_CORE_HW_CFG2_HS_PHY_TYPE_ULPI 2
#define DWHCI_CORE_HW_CFG2_HS_PHY_TYPE_UTMI_ULPI 3
#define DWHCI_CORE_HW_CFG2_FS_PHY_TYPE(reg) (((reg) >> 8) & 3)
#define DWHCI_CORE_HW_CFG2_FS_PHY_TYPE_DEDICATED 1
#define DWHCI_CORE_HW_CFG2_NUM_HOST_CHANNELS(reg) ((((reg) >> 14) & 0xF) + 1)
#define DWHCI_CORE_HW_CFG3 (ARM_USB_CORE_BASE + 0x04C) // RO
#define DWHCI_CORE_HW_CFG3_DFIFO_DEPTH(reg) (((reg) >> 16) & 0xFFFF)
Expand Down Expand Up @@ -111,6 +118,9 @@
#define DWHCI_HOST_CFG (ARM_USB_HOST_BASE + 0x000)
#define DWHCI_HOST_CFG_FSLS_PCLK_SEL__SHIFT 0
#define DWHCI_HOST_CFG_FSLS_PCLK_SEL__MASK (3 << 0)
#define DWHCI_HOST_CFG_FSLS_PCLK_SEL_30_60_MHZ 0
#define DWHCI_HOST_CFG_FSLS_PCLK_SEL_48_MHZ 1
#define DWHCI_HOST_CFG_FSLS_PCLK_SEL_6_MHZ 2
#define DWHCI_HOST_FRM_INTERVAL (ARM_USB_HOST_BASE + 0x004)
#define DWHCI_HOST_FRM_NUM (ARM_USB_HOST_BASE + 0x008)
#define DWHCI_HOST_FRM_NUM_NUMBER(reg) ((reg) & 0xFFFF)
Expand All @@ -127,6 +137,7 @@
#define DWHCI_HOST_PORT_CONNECT_CHANGED (1 << 1)
#define DWHCI_HOST_PORT_ENABLE (1 << 2)
#define DWHCI_HOST_PORT_ENABLE_CHANGED (1 << 3)
#define DWHCI_HOST_PORT_OVERCURRENT (1 << 4)
#define DWHCI_HOST_PORT_OVERCURRENT_CHANGED (1 << 5)
#define DWHCI_HOST_PORT_RESET (1 << 8)
#define DWHCI_HOST_PORT_POWER (1 << 12)
Expand Down
12 changes: 11 additions & 1 deletion include/circle/usb/dwhcidevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
#include <circle/timer.h>
#include <circle/usb/usbendpoint.h>
#include <circle/usb/usbrequest.h>
#include <circle/usb/dwhcirootport.h>
#include <circle/usb/dwhcixferstagedata.h>
#include <circle/usb/dwhciregister.h>
#include <circle/usb/dwhci.h>
#include <circle/usb/usb.h>
#include <circle/types.h>

class CDWHCIDevice : public CUSBHostController
Expand All @@ -41,6 +43,12 @@ class CDWHCIDevice : public CUSBHostController
boolean SubmitBlockingRequest (CUSBRequest *pURB);
boolean SubmitAsyncRequest (CUSBRequest *pURB);

private:
TUSBSpeed GetPortSpeed (void);
boolean OvercurrentDetected (void);
void DisableRootPort (void);
friend class CDWHCIRootPort;

private:
boolean InitCore (void);
boolean InitHost (void);
Expand Down Expand Up @@ -89,13 +97,15 @@ class CDWHCIDevice : public CUSBHostController
private:
CInterruptSystem *m_pInterruptSystem;
CTimer *m_pTimer;

unsigned m_nChannels;
volatile unsigned m_nChannelAllocated; // one bit per channel, set if allocated

CDWHCITransferStageData *m_pStageData[DWHCI_MAX_CHANNELS];

volatile boolean m_bWaiting;

CDWHCIRootPort m_RootPort;
};

#endif
42 changes: 42 additions & 0 deletions include/circle/usb/dwhcirootport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// dwhcirootport.h
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2014 R. Stange <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _circle_usb_dwhcirootport_h
#define _circle_usb_dwhcirootport_h

#include <circle/usb/usbdevice.h>
#include <circle/types.h>

class CDWHCIDevice;

class CDWHCIRootPort
{
public:
CDWHCIRootPort (CDWHCIDevice *pHost);
~CDWHCIRootPort (void);

boolean Initialize (void);

private:
CDWHCIDevice *m_pHost;

CUSBDevice *m_pDevice;
};

#endif
5 changes: 5 additions & 0 deletions include/circle/usb/usbhid.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ PACKED;
#define LED_CAPS_LOCK (1 << 1)
#define LED_SCROLL_LOCK (1 << 2)

// Mouse buttons (boot protocol)
#define USBHID_BUTTON1 (1 << 0)
#define USBHID_BUTTON2 (1 << 1)
#define USBHID_BUTTON3 (1 << 2)

#endif
58 changes: 58 additions & 0 deletions include/circle/usb/usbhiddevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// usbhiddevice.h
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2014 R. Stange <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _circle_usb_usbhiddevice_h
#define _circle_usb_usbhiddevice_h

#include <circle/usb/usbdevice.h>
#include <circle/usb/usbendpoint.h>
#include <circle/usb/usbrequest.h>
#include <circle/types.h>

class CUSBHIDDevice : public CUSBDevice
{
public:
CUSBHIDDevice (CUSBDevice *pDevice, unsigned nReportSize);
~CUSBHIDDevice (void);

boolean Configure (void);

private:
virtual void ReportHandler (const u8 *pReport) = 0; // pReport is 0 on failure

private:
boolean StartRequest (void);

void CompletionRoutine (CUSBRequest *pURB);
static void CompletionStub (CUSBRequest *pURB, void *pParam, void *pContext);

private:
unsigned m_nReportSize;

u8 m_ucInterfaceNumber;
u8 m_ucAlternateSetting;

CUSBEndpoint *m_pReportEndpoint;

CUSBRequest *m_pURB;

u8 *m_pReportBuffer;
};

#endif
45 changes: 9 additions & 36 deletions include/circle/usb/usbkeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,17 @@
#ifndef _usbkeyboard_h
#define _usbkeyboard_h

#include <circle/usb/usbdevice.h>
#include <circle/usb/usbendpoint.h>
#include <circle/usb/usbrequest.h>
#include <circle/usb/keymap.h>
#include <circle/usb/usbhiddevice.h>
#include <circle/input/keyboardbehaviour.h>
#include <circle/types.h>

#define BOOT_REPORT_SIZE 8

typedef void TKeyPressedHandler (const char *pString);
typedef void TSelectConsoleHandler (unsigned nConsole);
typedef void TShutdownHandler (void);
#define USBKEYB_REPORT_SIZE 8

// The raw handler is called when the keyboard sends a status report (on status change and/or continously).
typedef void TKeyStatusHandlerRaw (unsigned char ucModifiers, // see usbhid.h
const unsigned char RawKeys[6]); // key code or 0 in each byte

class CUSBKeyboardDevice : public CUSBDevice
class CUSBKeyboardDevice : public CUSBHIDDevice
{
public:
CUSBKeyboardDevice (CUSBDevice *pDevice);
Expand All @@ -53,38 +47,17 @@ class CUSBKeyboardDevice : public CUSBDevice
void RegisterKeyStatusHandlerRaw (TKeyStatusHandlerRaw *pKeyStatusHandlerRaw);

private:
void GenerateKeyEvent (u8 ucPhyCode);

boolean StartRequest (void);

void CompletionRoutine (CUSBRequest *pURB);
static void CompletionStub (CUSBRequest *pURB, void *pParam, void *pContext);
void ReportHandler (const u8 *pReport);

u8 GetModifiers (void) const;
u8 GetKeyCode (void) const;
static boolean FindByte (const u8 *pBuffer, u8 ucByte, unsigned nLength);

void TimerHandler (unsigned hTimer);
static void TimerStub (unsigned hTimer, void *pParam, void *pContext);

private:
u8 m_ucInterfaceNumber;
u8 m_ucAlternateSetting;

CUSBEndpoint *m_pReportEndpoint;

TKeyPressedHandler *m_pKeyPressedHandler;
TSelectConsoleHandler *m_pSelectConsoleHandler;
TShutdownHandler *m_pShutdownHandler;
TKeyStatusHandlerRaw *m_pKeyStatusHandlerRaw;
CKeyboardBehaviour m_Behaviour;

CUSBRequest *m_pURB;
u8 *m_pReportBuffer;
TKeyStatusHandlerRaw *m_pKeyStatusHandlerRaw;

u8 m_ucLastPhyCode;
unsigned m_hTimer;
u8 m_LastReport[USBKEYB_REPORT_SIZE];

CKeyMap m_KeyMap;

static unsigned s_nDeviceNumber;
};

Expand Down
Loading

0 comments on commit 1bf7a96

Please sign in to comment.