Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
isage committed Jan 18, 2023
0 parents commit 09b0a73
Show file tree
Hide file tree
Showing 18 changed files with 1,312 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
BasedOnStyle: Webkit
---
Language: Cpp
PointerAlignment: Right
BreakBeforeBraces: Allman
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
Cpp11BracedListStyle: true
Standard: Cpp11
ColumnLimit: 120
IndentWidth: 2
AccessModifierOffset: -2
FixNamespaceComments: true
NamespaceIndentation: None
IncludeBlocks: Regroup
IndentCaseLabels: true
MaxEmptyLinesToKeep: 1
UseTab: Never
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignOperands: true
AlignTrailingComments: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
CommentPragmas: '^ NOLINT'
---
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
43 changes: 43 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.2)

if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(DEFINED ENV{VITASDK})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")
else()
message(FATAL_ERROR "Please define VITASDK to point to your SDK path!")
endif()
endif()

project(vixen)
include("${VITASDK}/share/vita.cmake" REQUIRED)

add_executable(${PROJECT_NAME}
src/main.c
src/unpack.c
src/devicelist.c
src/controller.c
src/controllers/xbox_360_controller.c
src/controllers/xbox_360w_controller.c
)

target_link_libraries(${PROJECT_NAME}
SceDebugForDriver_stub
SceSblAIMgrForDriver_stub
SceCtrlForDriver_stub
SceKernelSuspendForDriver_stub
SceSysclibForDriver_stub
SceSysmemForDriver_stub
SceThreadmgrForDriver_stub
SceUsbdForDriver_stub
SceUsbServForDriver_stub
taihenForKernel_stub
)

set_target_properties(${PROJECT_NAME}
PROPERTIES LINK_FLAGS "-nostdlib"
)

vita_create_self(${PROJECT_NAME}.skprx ${PROJECT_NAME}
CONFIG vixen.yml
UNSAFE
)
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2022 Cat (Epifanov Ivan)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ViXEn - **Vi**ta **X**-input **En**abler

PSVita kernel driver for x-input gamepads (e.g. xbox360)

## Features

* Support for up to 4 wired usb x-input devices.
* Support for up to 4 wireless Xbox 360 gamepads via 1 wired usb receiver.
* Auto turn-off wireless controllers on suspend.

Note: xbox 360 wireless receiver takes over all 4 gamepad ports, so you can't use wired and wireless gamepads simultaniously.

For full list of supported devices see [here](src/devicelist.c)

## Installing
* Add vixen.skprx under `*KERNEL` in tai config and reboot.
* For vita you need usb Y-cable and external power. See [this](https://github.com/isage/vita-usb-ether#hardware) for example.

## Building

* Install vitausb from https://github.com/isage/vita-packages-extra
* `mkdir build && cmake -DCMAKE_BUILD_TYPE=Release .. && make install`

## License

MIT, see LICENSE.md

## Credits

* [xboxdrv](https://github.com/xboxdrv/xboxdrv) - for vid/pid pairs and protocol description
* [xerpi](https://github.com/xerpi) - for ds3vita
* **CBPS discord** - for support and stupid ideas
* **rem** - for being lazy/buzy to do the same :P
67 changes: 67 additions & 0 deletions src/controller.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "controller.h"

#include "controllers/xbox_360_controller.h"
#include "controllers/xbox_360w_controller.h"

#include <psp2kern/kernel/suspend.h>
#include <psp2kern/kernel/threadmgr.h>
#include <psp2kern/usbd.h>

void on_read_data(int32_t result, int32_t count, void *arg)
{
// process buffer
Controller *c = (Controller *)arg;
if (result == 0 && count > 0 && arg)
{
if (c->inited)
{
if (c->type == PAD_XBOX360)
{
if (Xbox360Controller_processReport(c, count))
ksceKernelPowerTick(0); // cancel sleep timers.
}
else
{
if (Xbox360WController_processReport(c, count))
ksceKernelPowerTick(0); // cancel sleep timers.
}
}
}

usb_read(c);
}

void on_write_data(int32_t result, int32_t count, void *arg)
{
// ksceDebugPrintf("write status: %d %d\n", result, count);
// check status
// do nothing?
}

void usb_read(Controller *c)
{
int ret;

if (!c->inited)
return;

ret = ksceUsbdInterruptTransfer(c->pipe_in, c->buffer, c->buffer_size, on_read_data, c);

if (ret < 0)
{
ksceDebugPrintf("ksceUsbdInterruptTransfer(in) error: 0x%08x\n", ret);
// error out
}
}

void usb_write(Controller *c, uint8_t *data, int len)
{
int ret;
ret = ksceUsbdInterruptTransfer(c->pipe_out, data, len, on_write_data, c);

if (ret < 0)
{
ksceDebugPrintf("ksceUsbdInterruptTransfer(out) error: 0x%08x\n", ret);
// error out
}
}
41 changes: 41 additions & 0 deletions src/controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef __CONTROLLER_H__
#define __CONTROLLER_H__

#include "devicelist.h"

#include <psp2common/types.h>
#include <psp2kern/usbd.h>
#include <psp2kern/kernel/debug.h>
#include <stdint.h>

typedef struct
{
uint32_t buttons;
uint8_t leftX;
uint8_t leftY;
uint8_t rightX;
uint8_t rightY;
uint8_t lt;
uint8_t rt;
} ControlData;

typedef struct
{
uint8_t type;
uint8_t attached; // actual gamepad attached
uint8_t inited; // usb device attached and inited
uint8_t battery_level;
ControlData controlData;
int device_id;
uint8_t port;
SceUID pipe_in;
SceUID pipe_out;
unsigned char buffer[32] __attribute__((aligned(64)));
size_t buffer_size;

} Controller;

void usb_read(Controller *c);
void usb_write(Controller *c, uint8_t *data, int len);

#endif // __CONTROLLER_H__
Loading

0 comments on commit 09b0a73

Please sign in to comment.