├── LICENSE ├── Makefile ├── README.md ├── demo ├── Makefile └── source │ └── main.c ├── include └── wiidrc │ └── wiidrc.h └── source ├── wiidrc.c └── wiidrc_structs.h /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 FIX94 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/wii_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := libwiidrc 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := include 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | CFLAGS = -g -O2 -Wall -Wextra $(MACHDEP) $(INCLUDE) 28 | 29 | #--------------------------------------------------------------------------------- 30 | # no real need to edit anything past this point unless you need to add additional 31 | # rules for different file extensions 32 | #--------------------------------------------------------------------------------- 33 | ifneq ($(BUILD),$(notdir $(CURDIR))) 34 | #--------------------------------------------------------------------------------- 35 | export OUTPUT := $(CURDIR)/lib/$(TARGET) 36 | 37 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 38 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 39 | 40 | export DEPSDIR := $(CURDIR)/$(BUILD) 41 | 42 | #--------------------------------------------------------------------------------- 43 | # automatically build a list of object files for our project 44 | #--------------------------------------------------------------------------------- 45 | export CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 46 | #--------------------------------------------------------------------------------- 47 | export OFILES := $(CFILES:.c=.o) 48 | export LD := $(CC) 49 | 50 | #--------------------------------------------------------------------------------- 51 | # build a list of include paths 52 | #--------------------------------------------------------------------------------- 53 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 55 | -I$(LIBOGC_INC) 56 | 57 | #--------------------------------------------------------------------------------- 58 | # build a list of library paths 59 | #--------------------------------------------------------------------------------- 60 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 61 | -L$(LIBOGC_LIB) 62 | 63 | .PHONY: $(BUILD) clean 64 | 65 | #--------------------------------------------------------------------------------- 66 | $(BUILD): 67 | @[ -d $@ ] || mkdir -p $@ 68 | @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 69 | 70 | #--------------------------------------------------------------------------------- 71 | clean: 72 | @echo clean ... 73 | @rm -fr $(BUILD) $(OUTPUT).a 74 | 75 | 76 | #--------------------------------------------------------------------------------- 77 | else 78 | 79 | DEPENDS := $(OFILES:.o=.d) 80 | 81 | #--------------------------------------------------------------------------------- 82 | # main targets 83 | #--------------------------------------------------------------------------------- 84 | $(OUTPUT).a: $(OFILES) 85 | 86 | -include $(DEPENDS) 87 | 88 | #--------------------------------------------------------------------------------- 89 | endif 90 | #--------------------------------------------------------------------------------- 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libwiidrc 2 | This is only usable with a special patched fw.img and homebrew injected into a WiiU VC title, details on the patches are below. 3 | Most WiiU VC injector tools already contain the patches required for this, the patches below are only needed if you do it manually. 4 | The usage is quite simple, call WiiDRC_Init on boot and after that call WiiDRC_ScanPads every time you update your pad inputs. 5 | To check if the gamepad is ready to use, call WiiDRC_Inited and WiiDRC_Connected, if both are true its good to go. 6 | The analog stick range goes from about -75 to 75 so make sure to scale it to whatever you need. 7 | The battery status goes from 6 (full) down to 1 (critical), 0 meaning that it is currently charging. 8 | See the "demo" folder for an example on how to use it in a bit more detail. 9 | Both compiled Library and Demo can be grabbed from the Releases tab. 10 | 11 | # Patches 12 | When building a WiiU VC file to install, use my nfs2iso2nfs fork with the "-homebrew -passthrough" command line options to patch the fw.img with all the required libwiidrc patches. 13 | -------------------------------------------------------------------------------- /demo/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/wii_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := boot 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := source 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -lwiidrc -lwiiuse -lm -lbte -logc 37 | 38 | 39 | #--------------------------------------------------------------------------------- 40 | # list of directories containing libraries, this must be the top level containing 41 | # include and lib 42 | #--------------------------------------------------------------------------------- 43 | LIBDIRS := $(DEVKITPPC)/lib $(CURDIR) 44 | 45 | #--------------------------------------------------------------------------------- 46 | # no real need to edit anything past this point unless you need to add additional 47 | # rules for different file extensions 48 | #--------------------------------------------------------------------------------- 49 | ifneq ($(BUILD),$(notdir $(CURDIR))) 50 | #--------------------------------------------------------------------------------- 51 | 52 | export OUTPUT := $(CURDIR)/$(TARGET) 53 | 54 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 55 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 56 | 57 | export DEPSDIR := $(CURDIR)/$(BUILD) 58 | 59 | #--------------------------------------------------------------------------------- 60 | # automatically build a list of object files for our project 61 | #--------------------------------------------------------------------------------- 62 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 63 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 64 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 65 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 66 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 67 | 68 | #--------------------------------------------------------------------------------- 69 | # use CXX for linking C++ projects, CC for standard C 70 | #--------------------------------------------------------------------------------- 71 | ifeq ($(strip $(CPPFILES)),) 72 | export LD := $(CC) 73 | else 74 | export LD := $(CXX) 75 | endif 76 | 77 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 78 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 79 | $(sFILES:.s=.o) $(SFILES:.S=.o) 80 | 81 | #--------------------------------------------------------------------------------- 82 | # build a list of include paths 83 | #--------------------------------------------------------------------------------- 84 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 85 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 86 | -I$(CURDIR)/$(BUILD) \ 87 | -I$(LIBOGC_INC) 88 | 89 | #--------------------------------------------------------------------------------- 90 | # build a list of library paths 91 | #--------------------------------------------------------------------------------- 92 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 93 | -L$(LIBOGC_LIB) 94 | 95 | export OUTPUT := $(CURDIR)/$(TARGET) 96 | .PHONY: $(BUILD) clean 97 | 98 | #--------------------------------------------------------------------------------- 99 | $(BUILD): 100 | @[ -d $@ ] || mkdir -p $@ 101 | @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 102 | 103 | #--------------------------------------------------------------------------------- 104 | clean: 105 | @echo clean ... 106 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 107 | 108 | 109 | #--------------------------------------------------------------------------------- 110 | else 111 | 112 | DEPENDS := $(OFILES:.o=.d) 113 | 114 | #--------------------------------------------------------------------------------- 115 | # main targets 116 | #--------------------------------------------------------------------------------- 117 | $(OUTPUT).dol: $(OUTPUT).elf 118 | $(OUTPUT).elf: $(OFILES) 119 | 120 | #--------------------------------------------------------------------------------- 121 | # This rule links in binary data with the .jpg extension 122 | #--------------------------------------------------------------------------------- 123 | %.png.o : %.png 124 | #--------------------------------------------------------------------------------- 125 | @echo $(notdir $<) 126 | $(bin2o) 127 | 128 | -include $(DEPENDS) 129 | 130 | #--------------------------------------------------------------------------------- 131 | endif 132 | #--------------------------------------------------------------------------------- 133 | -------------------------------------------------------------------------------- /demo/source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 FIX94 3 | * 4 | * This software may be modified and distributed under the terms 5 | * of the MIT license. See the LICENSE file for details. 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | void *xfb = NULL; 17 | GXRModeObj *rmode = NULL; 18 | VIDEO_Init(); 19 | rmode = VIDEO_GetPreferredMode(NULL); 20 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 21 | VIDEO_Configure(rmode); 22 | VIDEO_SetNextFramebuffer(xfb); 23 | VIDEO_SetBlack(FALSE); 24 | VIDEO_Flush(); 25 | VIDEO_WaitVSync(); 26 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 27 | int x = 24, y = 32, w, h; 28 | w = rmode->fbWidth - (32); 29 | h = rmode->xfbHeight - (48); 30 | CON_InitEx(rmode, x, y, w, h); 31 | VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK); 32 | PAD_Init(); 33 | WPAD_Init(); 34 | WiiDRC_Init(); 35 | bool inited = WiiDRC_Inited(); 36 | bool connected = false; 37 | if(inited) //Wii VC can start with gamepad off 38 | connected = WiiDRC_Connected(); 39 | while(1) 40 | { 41 | printf("\x1b[2J"); 42 | printf("\x1b[37m"); 43 | printf("WiiDRC v1.3 Demo by FIX94\n"); 44 | printf("Press any button on a real Wiimote to exit\n"); 45 | if(inited) 46 | { 47 | if(connected) 48 | { 49 | WiiDRC_ScanPads(); 50 | const struct WiiDRCData *drcdat = WiiDRC_Data(); 51 | printf("Left Stick X: %i, Y: %i; Right Stick X: %i, Y: %i\n", 52 | drcdat->xAxisL, drcdat->yAxisL, drcdat->xAxisR, drcdat->yAxisR); 53 | if(drcdat->battery) printf("Battery: %i\n", drcdat->battery); 54 | else printf("Battery: Charging\n"); 55 | if(WiiDRC_ShutdownRequested()) printf("Gamepad is asking for a shutdown\n"); 56 | if(drcdat->button & WIIDRC_BUTTON_A) printf("A pressed\n"); 57 | if(drcdat->button & WIIDRC_BUTTON_B) printf("B pressed\n"); 58 | if(drcdat->button & WIIDRC_BUTTON_X) printf("X pressed\n"); 59 | if(drcdat->button & WIIDRC_BUTTON_Y) printf("Y pressed\n"); 60 | if(drcdat->button & WIIDRC_BUTTON_LEFT) printf("D-Pad Left pressed\n"); 61 | if(drcdat->button & WIIDRC_BUTTON_RIGHT) printf("D-Pad Right pressed\n"); 62 | if(drcdat->button & WIIDRC_BUTTON_UP) printf("D-Pad Up pressed\n"); 63 | if(drcdat->button & WIIDRC_BUTTON_DOWN) printf("D-Pad Down pressed\n"); 64 | if(drcdat->button & WIIDRC_BUTTON_ZL) printf("ZL pressed\n"); 65 | if(drcdat->button & WIIDRC_BUTTON_ZR) printf("ZR pressed\n"); 66 | if(drcdat->button & WIIDRC_BUTTON_L) printf("L pressed\n"); 67 | if(drcdat->button & WIIDRC_BUTTON_R) printf("R pressed\n"); 68 | if(drcdat->button & WIIDRC_BUTTON_PLUS) printf("Plus pressed\n"); 69 | if(drcdat->button & WIIDRC_BUTTON_MINUS) printf("Minus pressed\n"); 70 | if(drcdat->button & WIIDRC_BUTTON_HOME) printf("HOME pressed\n"); 71 | if(drcdat->button & WIIDRC_BUTTON_SYNC) printf("SYNC pressed\n"); 72 | if(drcdat->extra & WIIDRC_EXTRA_BUTTON_L3) printf("L3 pressed\n"); 73 | if(drcdat->extra & WIIDRC_EXTRA_BUTTON_R3) printf("R3 pressed\n"); 74 | if(drcdat->extra & WIIDRC_EXTRA_BUTTON_TV) printf("TV pressed\n"); 75 | if(drcdat->extra & WIIDRC_EXTRA_OVERLAY_TV) printf("TV overlay\n"); 76 | if(drcdat->extra & WIIDRC_EXTRA_OVERLAY_POWER) printf("Shutdown overlay\n"); 77 | } 78 | else 79 | printf("Gamepad was not enabled when starting Wii VC.\n"); 80 | } 81 | else 82 | printf("Not started in Wii VC or used fw.img was not patched for homebrew use.\n"); 83 | VIDEO_WaitVSync(); 84 | VIDEO_WaitVSync(); 85 | PAD_ScanPads(); 86 | WPAD_ScanPads(); 87 | if(PAD_ButtonsHeld(0) || WPAD_ButtonsHeld(0)) 88 | break; 89 | } 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /include/wiidrc/wiidrc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 FIX94 3 | * 4 | * This software may be modified and distributed under the terms 5 | * of the MIT license. See the LICENSE file for details. 6 | */ 7 | #ifndef _WIIDRC_H_ 8 | #define _WIIDRC_H_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | struct WiiDRCData { 15 | s16 xAxisL; 16 | s16 xAxisR; 17 | s16 yAxisL; 18 | s16 yAxisR; 19 | u16 button; 20 | u8 battery; 21 | u8 extra; 22 | }; 23 | 24 | #define WIIDRC_BUTTON_A 0x8000 25 | #define WIIDRC_BUTTON_B 0x4000 26 | #define WIIDRC_BUTTON_X 0x2000 27 | #define WIIDRC_BUTTON_Y 0x1000 28 | #define WIIDRC_BUTTON_LEFT 0x0800 29 | #define WIIDRC_BUTTON_RIGHT 0x0400 30 | #define WIIDRC_BUTTON_UP 0x0200 31 | #define WIIDRC_BUTTON_DOWN 0x0100 32 | #define WIIDRC_BUTTON_ZL 0x0080 33 | #define WIIDRC_BUTTON_ZR 0x0040 34 | #define WIIDRC_BUTTON_L 0x0020 35 | #define WIIDRC_BUTTON_R 0x0010 36 | #define WIIDRC_BUTTON_PLUS 0x0008 37 | #define WIIDRC_BUTTON_MINUS 0x0004 38 | #define WIIDRC_BUTTON_HOME 0x0002 39 | #define WIIDRC_BUTTON_SYNC 0x0001 40 | 41 | #define WIIDRC_EXTRA_BUTTON_L3 0x80 42 | #define WIIDRC_EXTRA_BUTTON_R3 0x40 43 | #define WIIDRC_EXTRA_BUTTON_TV 0x20 44 | #define WIIDRC_EXTRA_OVERLAY_TV 0x10 45 | #define WIIDRC_EXTRA_OVERLAY_POWER 0x01 46 | 47 | bool WiiDRC_Init(); 48 | bool WiiDRC_Inited(); 49 | bool WiiDRC_Recalibrate(); 50 | bool WiiDRC_ScanPads(); 51 | bool WiiDRC_Connected(); 52 | bool WiiDRC_ShutdownRequested(); 53 | const u8 *WiiDRC_GetRawI2CAddr(); 54 | const struct WiiDRCData *WiiDRC_Data(); 55 | u32 WiiDRC_ButtonsUp(); 56 | u32 WiiDRC_ButtonsDown(); 57 | u32 WiiDRC_ButtonsHeld(); 58 | s16 WiiDRC_lStickX(); 59 | s16 WiiDRC_lStickY(); 60 | s16 WiiDRC_rStickX(); 61 | s16 WiiDRC_rStickY(); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /source/wiidrc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 FIX94 3 | * 4 | * This software may be modified and distributed under the terms 5 | * of the MIT license. See the LICENSE file for details. 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include "wiidrc_structs.h" 11 | #include "wiidrc/wiidrc.h" 12 | 13 | static struct WiiDRCStat __WiiDRC_Status; 14 | static struct WiiDRCData __WiiDRC_PadData; 15 | static struct WiiDRCButtons __WiiDRC_PadButtons; 16 | static bool __WiiDRC_ShutdownRequested; 17 | 18 | static u32 __WiiDRC_Inited = 0; 19 | static u8 *__WiiDRC_I2CBuf = NULL; 20 | static u8 *__WiiDRC_DRCStateBuf = NULL; 21 | 22 | static bool __WiiDRC_SetI2CBuf() 23 | { 24 | DCInvalidateRange((void*)0x938B2964, 4); 25 | if(*(vu32*)0x938B2964 == 0x138BB004) //r569 26 | { 27 | __WiiDRC_I2CBuf = (u8*)0x938BB004; 28 | return true; 29 | } 30 | DCInvalidateRange((void*)0x938B2564, 4); 31 | if(*(vu32*)0x938B2564 == 0x138BB004) //r570 32 | { 33 | __WiiDRC_I2CBuf = (u8*)0x938BB004; 34 | return true; 35 | } 36 | else if(*(vu32*)0x938B2564 == 0x138BA004) //r590 37 | { 38 | __WiiDRC_I2CBuf = (u8*)0x938BA004; 39 | return true; 40 | } 41 | return false; 42 | } 43 | 44 | static bool __WiiDRC_SetDRCStateBuf() 45 | { 46 | //TODO r569 47 | DCInvalidateRange((void*)0x938B563C, 4); 48 | if(*(vu32*)0x938B563C == 0x138BE770) //r570 49 | { 50 | __WiiDRC_DRCStateBuf = (u8*)0x938BE770; 51 | return true; 52 | } 53 | DCInvalidateRange((void*)0x938B5724, 4); 54 | if(*(vu32*)0x938B5724 == 0x138BD770) //r590 55 | { 56 | __WiiDRC_DRCStateBuf = (u8*)0x938BD770; 57 | return true; 58 | } 59 | return false; 60 | } 61 | 62 | bool WiiDRC_Init() 63 | { 64 | if(__WiiDRC_Inited == 1) 65 | return false; 66 | if(!__WiiDRC_SetI2CBuf()) 67 | return false; 68 | //can fail on r569 for now 69 | __WiiDRC_SetDRCStateBuf(); 70 | 71 | __WiiDRC_Inited = 1; 72 | 73 | WiiDRC_Recalibrate(); //sets up __WiiDRC_Status 74 | memset(&__WiiDRC_PadData,0,sizeof(struct WiiDRCData)); 75 | memset(&__WiiDRC_PadButtons,0,sizeof(struct WiiDRCButtons)); 76 | __WiiDRC_ShutdownRequested = false; 77 | 78 | return true; 79 | } 80 | 81 | bool WiiDRC_Inited() 82 | { 83 | return !!__WiiDRC_Inited; 84 | } 85 | 86 | bool WiiDRC_Recalibrate() 87 | { 88 | if(__WiiDRC_Inited == 0) 89 | return false; 90 | 91 | DCInvalidateRange(__WiiDRC_I2CBuf,9); 92 | __WiiDRC_Status.xAxisLmid = (s8)(__WiiDRC_I2CBuf[4]-0x80); 93 | __WiiDRC_Status.yAxisLmid = (s8)(__WiiDRC_I2CBuf[5]-0x80); 94 | __WiiDRC_Status.xAxisRmid = (s8)(__WiiDRC_I2CBuf[6]-0x80); 95 | __WiiDRC_Status.yAxisRmid = (s8)(__WiiDRC_I2CBuf[7]-0x80); 96 | 97 | return true; 98 | } 99 | 100 | bool WiiDRC_ScanPads() 101 | { 102 | if(__WiiDRC_Inited == 0) 103 | return false; 104 | 105 | DCInvalidateRange(__WiiDRC_I2CBuf,9); 106 | __WiiDRC_ShutdownRequested = !!(__WiiDRC_I2CBuf[1]&0x80); 107 | __WiiDRC_PadData.button = (__WiiDRC_I2CBuf[2]<<8) | (__WiiDRC_I2CBuf[3]); 108 | __WiiDRC_PadData.xAxisL = ((s8)(__WiiDRC_I2CBuf[4]-0x80)) - __WiiDRC_Status.xAxisLmid; 109 | __WiiDRC_PadData.yAxisL = ((s8)(__WiiDRC_I2CBuf[5]-0x80)) - __WiiDRC_Status.yAxisLmid; 110 | __WiiDRC_PadData.xAxisR = ((s8)(__WiiDRC_I2CBuf[6]-0x80)) - __WiiDRC_Status.xAxisRmid; 111 | __WiiDRC_PadData.yAxisR = ((s8)(__WiiDRC_I2CBuf[7]-0x80)) - __WiiDRC_Status.yAxisRmid; 112 | __WiiDRC_PadData.extra = __WiiDRC_I2CBuf[8]; 113 | __WiiDRC_PadData.battery = (__WiiDRC_PadData.extra>>1)&7; 114 | 115 | u16 newstate, oldstate; 116 | 117 | newstate = __WiiDRC_PadData.button; 118 | oldstate = __WiiDRC_PadButtons.state; 119 | __WiiDRC_PadButtons.state = newstate; 120 | __WiiDRC_PadButtons.up = oldstate & ~newstate; 121 | __WiiDRC_PadButtons.down = newstate & (newstate ^ oldstate); 122 | 123 | return true; 124 | } 125 | 126 | bool WiiDRC_Connected() 127 | { 128 | if(__WiiDRC_DRCStateBuf) 129 | { 130 | DCInvalidateRange(__WiiDRC_DRCStateBuf, 4); 131 | return !!(*(vu32*)__WiiDRC_DRCStateBuf); 132 | } 133 | return true; //default connect 134 | } 135 | 136 | bool WiiDRC_ShutdownRequested() 137 | { 138 | return __WiiDRC_ShutdownRequested; 139 | } 140 | 141 | const u8 *WiiDRC_GetRawI2CAddr() 142 | { 143 | return __WiiDRC_I2CBuf; 144 | } 145 | const struct WiiDRCData *WiiDRC_Data() 146 | { 147 | return &__WiiDRC_PadData; 148 | } 149 | u32 WiiDRC_ButtonsUp() 150 | { 151 | return __WiiDRC_PadButtons.up; 152 | } 153 | u32 WiiDRC_ButtonsDown() 154 | { 155 | return __WiiDRC_PadButtons.down; 156 | } 157 | u32 WiiDRC_ButtonsHeld() 158 | { 159 | return __WiiDRC_PadButtons.state; 160 | } 161 | s16 WiiDRC_lStickX() 162 | { 163 | return __WiiDRC_PadData.xAxisL; 164 | } 165 | s16 WiiDRC_lStickY() 166 | { 167 | return __WiiDRC_PadData.yAxisL; 168 | } 169 | s16 WiiDRC_rStickX() 170 | { 171 | return __WiiDRC_PadData.xAxisR; 172 | } 173 | s16 WiiDRC_rStickY() 174 | { 175 | return __WiiDRC_PadData.yAxisR; 176 | } 177 | -------------------------------------------------------------------------------- /source/wiidrc_structs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 FIX94 3 | * 4 | * This software may be modified and distributed under the terms 5 | * of the MIT license. See the LICENSE file for details. 6 | */ 7 | #ifndef _WIIDRC_STRUCTS_H_ 8 | #define _WIIDRC_STRUCTS_H_ 9 | 10 | struct WiiDRCStat { 11 | s16 xAxisLmid; 12 | s16 xAxisRmid; 13 | s16 yAxisLmid; 14 | s16 yAxisRmid; 15 | }; 16 | 17 | struct WiiDRCButtons { 18 | u32 up; 19 | u32 down; 20 | u32 state; 21 | }; 22 | 23 | #endif 24 | --------------------------------------------------------------------------------