Skip to content

Commit

Permalink
Merge branch 'usbgamepad' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rsta2 committed Nov 24, 2018
2 parents a663b2e + 7013e1f commit 4b7aabb
Show file tree
Hide file tree
Showing 43 changed files with 3,081 additions and 542 deletions.
1 change: 1 addition & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Fixing issues for u-boot support
Support while adding CPU clock rate management and sample/26-cpustress
Testing while adding USB transaction queueing and SOF interrupt support
Updating addon/fatfs/ module
Driver for PS4 and Nintendo Switch Pro gamepads

Arjan van Vught
Support while adding Raspberry Pi 3 support
Expand Down
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Circle
======

> Raspberry Pi is a trademark of the Raspberry Pi Foundation.
> If you read this file in an editor you should switch line wrapping on.
Overview
Expand Down Expand Up @@ -138,12 +136,33 @@ Classes

The following C++ classes were added to Circle:

Base library
USB library

* CUSBGamePadPS3Device: Driver for PS3 gamepad
* CUSBGamePadPS4Device: Driver for PS4 gamepad
* CUSBGamePadStandardDevice: Driver for USB gamepads with USB HID class report interface (3-0-0)
* CUSBGamePadSwitchProDevice: Driver for Nintendo Switch Pro gamepad
* CUSBGamePadXbox360Device: Driver for Xbox 360 Wired gamepad

Input library

* CUserTimer: Fine grained user programmable interrupt timer (based on ARM_IRQ_TIMER1)
* CMouseDevice: Generic mouse interface device

The available Circle classes are listed in the file *doc/classes.txt*. If you have doxygen installed on your computer you can build a class documentation in *doc/html/* using:

`./makedoc`

At the moment there are only a few classes described in detail for doxygen.

Trademarks
----------

Raspberry Pi is a trademark of the Raspberry Pi Foundation.

Linux is a trademark of Linus Torvalds.

PS3 and PS4 are registered trademarks of Sony Computer Entertainment Inc.

Xbox 360 is a trademark of the Microsoft group of companies.

(c) 2017 Nintendo. Nintendo Switch is a trademark of Nintendo.
2 changes: 1 addition & 1 deletion addon/ugui/uguicpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ boolean CUGUI::Initialize (void)
return FALSE;
}

m_pMouseDevice = (CUSBMouseDevice *) CDeviceNameService::Get ()->GetDevice ("umouse1", FALSE);
m_pMouseDevice = (CMouseDevice *) CDeviceNameService::Get ()->GetDevice ("mouse1", FALSE);
if (m_pMouseDevice != 0)
{
if (m_pMouseDevice->Setup (m_pScreen->GetWidth (), m_pScreen->GetHeight ()))
Expand Down
4 changes: 2 additions & 2 deletions addon/ugui/uguicpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {
#endif

#include <circle/screen.h>
#include <circle/usb/usbmouse.h>
#include <circle/input/mouse.h>
#include <circle/input/touchscreen.h>

#if DEPTH != 16
Expand Down Expand Up @@ -48,7 +48,7 @@ class CUGUI

UG_GUI m_GUI;

CUSBMouseDevice *m_pMouseDevice;
CMouseDevice *m_pMouseDevice;

CTouchScreenDevice *m_pTouchScreen;
unsigned m_nLastUpdate;
Expand Down
8 changes: 7 additions & 1 deletion doc/classes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ USB library
* CUSBDeviceFactory: Creates the function objects of the different supported USB functions.
* CUSBEndpoint: Encapsulates an endpoint of an USB device (supports control, bulk and interrupt EPs).
* CUSBFunction: Encapsulates a function (represented by an interface descriptor) of an USB device.
* CUSBGamePadDevice: Driver for USB gamepads with USB HID class report interface (3-0-0)
* CUSBGamePadDevice: Base class for USB gamepad drivers
* CUSBGamePadPS3Device: Driver for PS3 gamepad
* CUSBGamePadPS4Device: Driver for PS4 gamepad
* CUSBGamePadStandardDevice: Driver for USB gamepads with USB HID class report interface (3-0-0)
* CUSBGamePadSwitchProDevice: Driver for Nintendo Switch Pro gamepad
* CUSBGamePadXbox360Device: Driver for Xbox 360 Wired gamepad
* CUSBHIDDevice: General USB HID device (e.g. keyboard, mouse, gamepad)
* CUSBHostController: Base class of CDWHCIDevice, some basic functions for host controllers.
* CUSBKeyboardDevice: Driver for USB keyboards
Expand All @@ -90,6 +95,7 @@ Input library
* CKeyMap: Keyboard translation map (six selectable default maps at the moment)
* CLineDiscipline: Implements line editor function
* CMouseBehaviour: Generic mouse function, handles the mouse cursor
* CMouseDevice: Generic mouse interface device
* CTouchScreenDevice: Driver for the official Raspberry Pi touch screen

FS library
Expand Down
31 changes: 29 additions & 2 deletions include/circle/devicenameservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// devicenameservice.h
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2014-2017 R. Stange <[email protected]>
// Copyright (C) 2014-2018 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
Expand Down Expand Up @@ -32,18 +32,45 @@ struct TDeviceInfo
boolean bBlockDevice;
};

class CDeviceNameService
class CDeviceNameService /// Devices can be registered by name and retrieved later by this name
{
public:
CDeviceNameService (void);
~CDeviceNameService (void);

/// \param pName Device name string
/// \param pDevice Pointer to the device object
/// \param bBlockDevice TRUE if this is a block device, otherwise character device
void AddDevice (const char *pName, CDevice *pDevice, boolean bBlockDevice);
/// \param pPrefix Device name prefix string
/// \param nIndex Device name index
/// \param pDevice Pointer to the device object
/// \param bBlockDevice TRUE if this is a block device, otherwise character device
void AddDevice (const char *pPrefix, unsigned nIndex, CDevice *pDevice, boolean bBlockDevice);

/// \param pName Device name string
/// \param bBlockDevice TRUE if this is a block device, otherwise character device
void RemoveDevice (const char *pName, boolean bBlockDevice);
/// \param pPrefix Device name prefix string
/// \param nIndex Device name index
/// \param bBlockDevice TRUE if this is a block device, otherwise character device
void RemoveDevice (const char *pPrefix, unsigned nIndex, boolean bBlockDevice);

/// \param pName Device name string
/// \param bBlockDevice TRUE if this is a block device, otherwise character device
/// \return Pointer to the device object or 0 if not found
CDevice *GetDevice (const char *pName, boolean bBlockDevice);
/// \param pPrefix Device name prefix string
/// \param nIndex Device name index
/// \param bBlockDevice TRUE if this is a block device, otherwise character device
/// \return Pointer to the device object or 0 if not found
CDevice *GetDevice (const char *pPrefix, unsigned nIndex, boolean bBlockDevice);

/// \brief Generate device listing
/// \param pTarget Device to be used for output
void ListDevices (CDevice *pTarget);

/// \return The single CDeviceNameService instance of the system
static CDeviceNameService *Get (void);

private:
Expand Down
78 changes: 78 additions & 0 deletions include/circle/input/mouse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// mouse.h
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2014-2018 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_mouse_h
#define _circle_input_mouse_h

#include <circle/device.h>
#include <circle/input/mousebehaviour.h>
#include <circle/types.h>

#define MOUSE_DISPLACEMENT_MIN -127
#define MOUSE_DISPLACEMENT_MAX 127

typedef void TMouseStatusHandler (unsigned nButtons, int nDisplacementX, int nDisplacementY);

class CMouseDevice : public CDevice /// Generic mouse interface device ("mouse1")
{
public:
CMouseDevice (void);
~CMouseDevice (void);

/// \brief Setup mouse device in cooked mode
/// \param nScreenWidth Width of the screen in pixels
/// \param nScreenHeight Height of the screen in pixels
/// \return FALSE on failure
boolean Setup (unsigned nScreenWidth, unsigned nScreenHeight);

/// \brief Register event handler in cooked mode
/// \param pEventHandler Pointer to the event handler (see: mousebehaviour.h)
void RegisterEventHandler (TMouseEventHandler *pEventHandler);

/// \brief Set mouse cursor to a specific position in cooked mode
/// \param nPosX X-coordinate of the position in pixels (0 is on the left border)
/// \param nPosY Y-coordinate of the position in pixels (0 is on the top border)
/// \return FALSE on failure
boolean SetCursor (unsigned nPosX, unsigned nPosY);
/// \brief Switch mouse cursor on or off in cooked mode
/// \param bShow TRUE shows the mouse cursor
/// \return Previous state
boolean ShowCursor (boolean bShow);

/// \brief Call this frequently from TASK_LEVEL (cooked mode only)
void UpdateCursor (void);

/// \brief Register mouse status handler in raw mode
/// \param pStatusHandler Pointer to the mouse status handler
void RegisterStatusHandler (TMouseStatusHandler *pStatusHandler);

public:
/// \warning Do not call this from application!
void ReportHandler (unsigned nButtons, int nDisplacementX, int nDisplacementY);

private:
CMouseBehaviour m_Behaviour;

TMouseStatusHandler *m_pStatusHandler;

unsigned m_nDeviceNumber;
static unsigned s_nDeviceNumber;
};

#endif
2 changes: 2 additions & 0 deletions include/circle/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define MAXOPT __attribute__ ((optimize (3)))
#define WEAK __attribute__ ((weak))

#define BIT(n) (1 << (n))

// big endian (to be used for constants only)
#define BE(value) ((((value) & 0xFF00) >> 8) | (((value) & 0x00FF) << 8))

Expand Down
7 changes: 6 additions & 1 deletion include/circle/usb/usbfunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// usbfunction.h
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2014-2016 R. Stange <[email protected]>
// Copyright (C) 2014-2018 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
Expand Down Expand Up @@ -51,7 +51,12 @@ class CUSBFunction : public CDevice
const TUSBDescriptor *GetDescriptor (u8 ucType); // returns 0 if not found
void ConfigurationError (const char *pSource) const;

// select a specific USB interface, called in constructor of derived class,
// if device has been detected by vendor/product ID
boolean SelectInterfaceByClass (u8 uchClass, u8 uchSubClass, u8 uchProtocol);

u8 GetInterfaceNumber (void) const;
u8 GetInterfaceClass (void) const;
u8 GetInterfaceSubClass (void) const;
u8 GetInterfaceProtocol (void) const;

Expand Down
Loading

0 comments on commit 4b7aabb

Please sign in to comment.