Add source code.

* Initial commit of modified source code.
* Arm7 for both apps appears to be some form of template arm7 setup.
Perhaps from the ancient version of libnds this used to use. I just used
the default arm7 template code from current version of libnds...seems to
do the job.
This commit is contained in:
ApacheThunder 2023-10-21 23:41:46 -05:00
parent 5122cc9bdf
commit e5a90c1121
54 changed files with 6537 additions and 0 deletions

3
.gitignore vendored
View File

@ -30,3 +30,6 @@
*.exe
*.out
*.app
*.nds
*.ds.gba

Binary file not shown.

51
dsmouse/Makefile Normal file
View File

@ -0,0 +1,51 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
export TARGET := dsmouse
export TOPDIR := $(CURDIR)
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO_FILES :=
include $(DEVKITARM)/ds_rules
.PHONY: checkarm7 checkarm9 clean
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all: checkarm7 checkarm9 $(TARGET).nds
#---------------------------------------------------------------------------------
checkarm7:
$(MAKE) -C arm7
#---------------------------------------------------------------------------------
checkarm9:
$(MAKE) -C arm9
#---------------------------------------------------------------------------------
$(TARGET).nds : $(NITRO_FILES) arm7/$(TARGET).elf arm9/$(TARGET).elf
ndstool -c $(TARGET).nds -7 arm7/$(TARGET).elf -9 arm9/$(TARGET).elf \
-b banner.bmp "NDS MOUSEPAD" \
$(_ADDFILES)
#---------------------------------------------------------------------------------
arm7/$(TARGET).elf:
$(MAKE) -C arm7
#---------------------------------------------------------------------------------
arm9/$(TARGET).elf:
$(MAKE) -C arm9
#---------------------------------------------------------------------------------
clean:
$(MAKE) -C arm9 clean
$(MAKE) -C arm7 clean
rm -f $(TARGET).nds $(TARGET).arm7 $(TARGET).arm9

126
dsmouse/arm7/Makefile Normal file
View File

@ -0,0 +1,126 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := source
INCLUDES := include build
DATA :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb-interwork
CFLAGS := -g -Wall -O2\
-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM7
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -Wl,--nmagic -Wl,-Map,$(notdir $*).map
LIBS := -ldswifi7 -lmm7 -lnds7
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export ARM7ELF := $(CURDIR)/$(TARGET).elf
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(ARM7ELF) : $(OFILES)
@echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

184
dsmouse/arm7/source/main.c Normal file
View File

@ -0,0 +1,184 @@
/*---------------------------------------------------------------------------------
default ARM7 core
Copyright (C) 2005 - 2010
Michael Noland (joat)
Jason Rogers (dovoto)
Dave Murphy (WinterMute)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
---------------------------------------------------------------------------------*/
#include <nds.h>
#include <dswifi7.h>
#include <maxmod7.h>
// I think they used stock arm7? None of this appears to be actually used for anything and doesn't work with modern libnds anyways.
/*
//---------------------------------------------------------------------------------
void startSound(int sampleRate, const void* data, u32 bytes, u8 channel, u8 vol, u8 pan, u8 format) {
//---------------------------------------------------------------------------------
SCHANNEL_TIMER(channel) = SOUND_FREQ(sampleRate);
SCHANNEL_SOURCE(channel) = (u32)data;
SCHANNEL_LENGTH(channel) = bytes >> 2 ;
SCHANNEL_CR(channel) = SCHANNEL_ENABLE | SOUND_ONE_SHOT | SOUND_VOL(vol) | SOUND_PAN(pan) | (format==1?SOUND_8BIT:SOUND_16BIT);
}
//---------------------------------------------------------------------------------
s32 getFreeSoundChannel() {
//---------------------------------------------------------------------------------
int i;
for (i=0; i<16; i++) {
if ( (SCHANNEL_CR(i) & SCHANNEL_ENABLE) == 0 ) return i;
}
return -1;
}
int vcount;
touchPosition first,tempPos;
//---------------------------------------------------------------------------------
void VcountHandler() {
//---------------------------------------------------------------------------------
static int lastbut = -1;
uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0;
but = REG_KEYXY;
if (!( (but ^ lastbut) & (1<<6))) {
tempPos = touchReadXY();
x = tempPos.x;
y = tempPos.y;
xpx = tempPos.px;
ypx = tempPos.py;
z1 = tempPos.z1;
z2 = tempPos.z2;
} else {
lastbut = but;
but |= (1 <<6);
}
if ( vcount == 80 ) {
first = tempPos;
} else {
if ( abs( xpx - first.px) > 10 || abs( ypx - first.py) > 10 ||
(but & ( 1<<6)) ) {
but |= (1 <<6);
lastbut = but;
} else {
IPC->mailBusy = 1;
IPC->touchX = x;
IPC->touchY = y;
IPC->touchXpx = xpx;
IPC->touchYpx = ypx;
IPC->touchZ1 = z1;
IPC->touchZ2 = z2;
IPC->mailBusy = 0;
}
}
IPC->buttons = but;
vcount ^= (80 ^ 130);
SetYtrigger(vcount);
}
*/
//---------------------------------------------------------------------------------
void VblankHandler(void) {
//---------------------------------------------------------------------------------
Wifi_Update();
}
//---------------------------------------------------------------------------------
void VcountHandler() {
//---------------------------------------------------------------------------------
inputGetAndSend();
}
volatile bool exitflag = false;
//---------------------------------------------------------------------------------
void powerButtonCB() {
//---------------------------------------------------------------------------------
exitflag = true;
}
//---------------------------------------------------------------------------------
int main() {
//---------------------------------------------------------------------------------
readUserSettings();
// Reset the clock if needed
// rtcReset();
irqInit();
// Start the RTC tracking IRQ
initClockIRQ();
fifoInit();
touchInit();
//enable sound
/*powerON(POWER_SOUND);
SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F);
IPC->soundData = 0;*/
mmInstall(FIFO_MAXMOD);
SetYtrigger(80);
// vcount = 80;
installWifiFIFO();
installSoundFIFO();
installSystemFIFO();
irqSet(IRQ_VCOUNT, VcountHandler);
irqSet(IRQ_VBLANK, VblankHandler);
irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);
setPowerButtonCB(powerButtonCB);
writePowerManagement(PM_CONTROL_REG,PM_BACKLIGHT_BOTTOM);
// Keep the ARM7 mostly idle
while (!exitflag) {
if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) {
exitflag = true;
}
swiWaitForVBlank();
}
return 0;
}

127
dsmouse/arm9/Makefile Normal file
View File

@ -0,0 +1,127 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := source
INCLUDES := include
DATA :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g -Wall -O2\
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lnds9
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export ARM9ELF := $(CURDIR)/$(TARGET).elf
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf *.nds* *.bin
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(ARM9ELF) : $(OFILES)
@echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@ -0,0 +1,182 @@
#include "D14HAL.H"
u8 D14_SPEED=D14_FULLSPEED;
void D14_SelectEndpoint(u8 EPNum)
{
D14_EPSEL=EPADDR(EPNum);
}
void D14_Init (void)
{;}
void D14_Connect(u8 f)
{
u32 i;
D14_MODE = D14_MODE_SRESET;
for(i=0;i<0x1000000;i++);
D14_MODE = 0;
for(i=0;i<0x1000000;i++);
D14_INTCNT = D14_INTCNT_DDBGMODOUT1|D14_INTCNT_DDBGMODIN1|D14_INTCNT_CDBGMOD1|D14_INTCNT_INTLVL|D14_INTCNT_INTPOL;
D14_IE = D14_IE_BRST|D14_IE_SUSP|D14_IE_RESM|D14_IE_HSSTAT|D14_IE_EP0SETUP|D14_IE_EP0OUT|D14_IE_EP0IN|D14_IE_EP1IN;
D14_IEH = 0x0000;
D14_ADDR = 0x80;
if(f)
D14_MODE = D14_MODE_SOFTCT|D14_MODE_IME|D14_MODE_CLKON;
D14_SPEED=D14_FULLSPEED;
D14_Configure(1);
}
void D14_Reset (void)
{
D14_MODE = D14_MODE_SRESET;
D14_MODE = 0;
D14_INTCNT = D14_INTCNT_DDBGMODOUT1|D14_INTCNT_DDBGMODIN1|D14_INTCNT_CDBGMOD1|D14_INTCNT_INTLVL|D14_INTCNT_INTPOL;
D14_IE = D14_IE_BRST|D14_IE_SUSP|D14_IE_RESM|D14_IE_HSSTAT|D14_IE_EP0SETUP|D14_IE_EP0OUT|D14_IE_EP0IN|D14_IE_EP1IN;
D14_IEH = 0x0000;
D14_ADDR = 0x80;
D14_MODE = D14_MODE_SOFTCT|D14_MODE_IME|D14_MODE_CLKON;
D14_SPEED=D14_FULLSPEED;
D14_Configure(1);
}
void D14_Suspend (void)
{;}
void D14_Resume (void)
{;}
void D14_WakeUp (void)
{;}
void D14_WakeUpCfg (u8 cfg)
{;}
void D14_SetAddress (u8 addr)
{
D14PORT(0x00)=0x0080|addr;
}
void D14_Configure (u8 cfg)
{
//必须先配置好 功能,再配置内存 最后打开 否则无法收到中断
if(D14_SPEED==D14_FULLSPEED)
{
D14_SelectEndpoint(0x81);
D14_EPTYPE = D14_EPTYPE_INT|D14_EPTYPE_DBLBUF;
D14_EPMAX = 0x4;
D14_SelectEndpoint(0x81);
D14_EPTYPE |= D14_EPTYPE_ENABLE;
}
else
{
D14_SelectEndpoint(0x81);
D14_EPTYPE = D14_EPTYPE_INT|D14_EPTYPE_DBLBUF;
D14_EPMAX = 0x4;
D14_SelectEndpoint(0x81);
D14_EPTYPE |= D14_EPTYPE_ENABLE;
}
}
void D14_ConfigEP (void *pEPD)
{;}
void D14_DirCtrlEP (u32 dir)
{;}
void D14_EnableEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = 0;
D14_EPTYPE &= ~D14_EPTYPE_ENABLE;
D14_EPTYPE |= D14_EPTYPE_ENABLE;
}
void D14_DisableEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = D14_EPCNT_STALL;
D14_EPTYPE &= ~D14_EPTYPE_ENABLE;
}
void D14_ResetEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = 0;
D14_EPTYPE &= ~D14_EPTYPE_ENABLE;
D14_EPTYPE |= D14_EPTYPE_ENABLE;
}
void D14_SetStallEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = D14_EPCNT_STALL;
}
void D14_ClrStallEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = 0;
D14_EPTYPE &= ~D14_EPTYPE_ENABLE;
D14_EPTYPE |= D14_EPTYPE_ENABLE;
}
u16 D14_GetFrame (void)
{
return D14_FRAME;
}
void D14_AcknowledgeEndpoint(u8 EPNum) //应答SETUP
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = D14_EPCNT_STATUS;
}
void D14_AcknowledgeSETUP(void)
{
D14_AcknowledgeEndpoint(0);
}
#pragma pack(1)
u16 D14_ReadEP (u8 EPNum, u8 *pData)
{
register u16 len,i,data;
u8 half;
D14_SelectEndpoint(EPNum);
len=D14_EPLEN;
if(!len)return 0;
half=len%2;
for(i=0;i<len/2;i++)
{
data=D14_EPDAT;
*pData++=(u8)data;
*pData++=(u8)(data>>8);
}
if(half)
{
data=D14_EPDAT;
*pData=(u8)data;
}
return len;
}
void D14_ClrBufEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = D14_EPCNT_CLBUF;
}
u16 D14_WriteEP (u8 EPNum, u8 *pData, u16 cnt)
{
register u16 i,data;
u8 half;
D14_SelectEndpoint(EPNum);
D14_EPLEN=cnt;
half=cnt%2;
for(i=0;i<cnt/2;i++)
{
data=*pData++;
data|=(*pData++)<<8;
D14_EPDAT=data;
}
if(half)
{
data=*pData;
D14_EPDAT=data;
}
return cnt;
}
#pragma pack()
//end of file

View File

@ -0,0 +1,170 @@
#ifndef _D14HAL_H_
#define _D14HAL_H_
/*
#define u16 unsigned short
#define u8 unsigned char
#define vu16 unsigned short
#define vu8 unsigned char
#define BIT(a) (1<<(a))
*/
#include <nds.h>
#define D14_FULLSPEED 0
#define D14_HIGHSPEED 1
extern u8 D14_SPEED;
#define D14_BASE 0x08000000
#define D14PORT(addr) (*(vu16*)(D14_BASE|((addr)*0x20000)))
#define EPADDR(addr) (((addr&0x80)?((addr)<<1)|1:((addr)<<1))&0xFF)
#define D14_ADDR D14PORT(0x00)
#define D14_MODE D14PORT(0x0C)
#define D14_INTCNT D14PORT(0x10)
#define D14_IE D14PORT(0x14)
#define D14_IEH D14PORT(0x16)
#define D14_EPSEL D14PORT(0x2C)
#define D14_EPCNT D14PORT(0x28)
#define D14_EPDAT D14PORT(0x20)
#define D14_EPLEN D14PORT(0x1C)
#define D14_EPMAX D14PORT(0x04)
#define D14_EPTYPE D14PORT(0x08)
#define D14_EPSHORT D14PORT(0x24)
#define D14_IF D14PORT(0x18)
#define D14_IFH D14PORT(0x1A)
#define D14_ID D14PORT(0x70)
#define D14_FRAME D14PORT(0x74)
#define D14_REG D14PORT(0X78)
#define D14_UNLOCK D14PORT(0X7C)
#define D14_TEST D14PORT(0X84)
/*D14_ADDR*/
#define D14_ADDR_EN BIT(7)
/*D14_MODE*/
#define D14_MODE_CLKON BIT(7)
#define D14_MODE_SNDRSU BIT(6)
#define D14_MODE_GOSUSP BIT(5)
#define D14_MODE_SRESET BIT(4)
#define D14_MODE_IME BIT(3)
#define D14_MODE_WKUPCS BIT(2)
#define D14_MODE_SOFTCT BIT(0)
/*D14_INTCNT*/
#define D14_INTCNT_DDBGMODOUT0 0
#define D14_INTCNT_DDBGMODOUT1 BIT(2)
#define D14_INTCNT_DDBGMODOUT2 BIT(3)|BIT(2)
#define D14_INTCNT_DDBGMODIN0 0
#define D14_INTCNT_DDBGMODIN1 BIT(4)
#define D14_INTCNT_DDBGMODIN2 BIT(5)|BIT(4)
#define D14_INTCNT_CDBGMOD0 0
#define D14_INTCNT_CDBGMOD1 BIT(6)
#define D14_INTCNT_CDBGMOD2 BIT(7)|BIT(6)
#define D14_INTCNT_INTLVL BIT(1)
#define D14_INTCNT_INTPOL BIT(0)
/*D14_IE*/
#define D14_IE_BRST BIT(0)
#define D14_IE_SOF BIT(1)
#define D14_IE_PSOF BIT(2)
#define D14_IE_SUSP BIT(3)
#define D14_IE_RESM BIT(4)
#define D14_IE_HSSTAT BIT(5)
#define D14_IE_DMA BIT(6)
#define D14_IE_EP0SETUP BIT(8)
#define D14_IE_EP0OUT BIT(10)
#define D14_IE_EP0IN BIT(11)
#define D14_IE_EP1OUT BIT(12)
#define D14_IE_EP1IN BIT(13)
#define D14_IE_EP2OUT BIT(14)
#define D14_IE_EP2IN BIT(15)
#define D14_IE_EP3OUT BIT(16)
#define D14_IE_EP3IN BIT(17)
#define D14_IE_EP4OUT BIT(18)
#define D14_IE_EP4IN BIT(19)
#define D14_IE_EP5OUT BIT(20)
#define D14_IE_EP5IN BIT(21)
#define D14_IE_EP6OUT BIT(22)
#define D14_IE_EP6IN BIT(23)
/*D14_IF*/
#define D14_IF_BRST BIT(0)
#define D14_IF_SOF BIT(1)
#define D14_IF_PSOF BIT(2)
#define D14_IF_SUSP BIT(3)
#define D14_IF_RESM BIT(4)
#define D14_IF_HSSTAT BIT(5)
#define D14_IF_DMA BIT(6)
#define D14_IF_EP0SETUP BIT(8)
#define D14_IF_EP0OUT BIT(10)
#define D14_IF_EP0IN BIT(11)
#define D14_IF_EP1OUT BIT(12)
#define D14_IF_EP1IN BIT(13)
#define D14_IF_EP2OUT BIT(14)
#define D14_IF_EP2IN BIT(15)
#define D14_IF_EP3OUT BIT(16)
#define D14_IF_EP3IN BIT(17)
#define D14_IF_EP4OUT BIT(18)
#define D14_IF_EP4IN BIT(19)
#define D14_IF_EP5OUT BIT(20)
#define D14_IF_EP5IN BIT(21)
#define D14_IF_EP6OUT BIT(22)
#define D14_IF_EP6IN BIT(23)
/*D14_EPSEL*/
#define D14_EPSEL_DIR BIT(0)
#define D14_EPSEL_SETUP BIT(5)
/*D14_EPCNT*/
#define D14_EPCNT_CLBUF BIT(4)
#define D14_EPCNT_VENDP BIT(3)
#define D14_EPCNT_STATUS BIT(1)
#define D14_EPCNT_STALL BIT(0)
/*D14_EPTYPE*/
#define D14_EPTYPE_NONE 0
#define D14_EPTYPE_SYNC BIT(0)
#define D14_EPTYPE_BULK BIT(1)
#define D14_EPTYPE_INT (BIT(1)|BIT(0))
#define D14_EPTYPE_DBLBUF BIT(2)
#define D14_EPTYPE_ENABLE BIT(3)
#define D14_EPTYPE_NOEMPKT BIT(4)
/*D14_UNLOCK*/
#define D14_UNLOCK_KEY 0xAA37
/*D14_TEST*/
#define D14_TEST_SE0_NAK BIT(0)
#define D14_TEST_JSTATE BIT(1)
#define D14_TEST_KSTATE BIT(2)
#define D14_TEST_PRBS BIT(3)
#define D14_TEST_FORCEFS BIT(4)
#define D14_TEST_FORCEHS BIT(7)
void D14_SelectEndpoint(u8 EPNum);
void D14_Init (void);
void D14_Connect(u8 f);
void D14_Reset (void);
void D14_Suspend (void);
void D14_Resume (void);
void D14_WakeUp (void);
void D14_WakeUpCfg (u8 cfg);
void D14_SetAddress (u8 addr);
void D14_Configure (u8 cfg);
void D14_ConfigEP (void *pEPD);
void D14_DirCtrlEP (u32 dir);
void D14_EnableEP (u8 EPNum);
void D14_DisableEP (u8 EPNum);
void D14_ResetEP (u8 EPNum);
void D14_SetStallEP (u8 EPNum);
void D14_ClrStallEP (u8 EPNum);
u16 D14_GetFrame (void);
void D14_AcknowledgeEndpoint(u8 EPNum);
void D14_AcknowledgeSETUP(void);
u16 D14_ReadEP (u8 EPNum, u8 *pData);
void D14_ClrBufEP (u8 EPNum);
u16 D14_WriteEP (u8 EPNum, u8 *pData, u16 cnt);
#endif//_D14HAL_H_

View File

@ -0,0 +1,4 @@
#include <stdio.h>
#include "usbhal.h"
#include "debug.h"

View File

@ -0,0 +1,15 @@
#ifdef ARM9
#else
#include<gba.h>
#endif
#define consolecls() iprintf ("%c[222J",0x1B)
#define consolesetxy(x,y) iprintf ("%c[%d;%dH",0x1B,x,y)
#define testb(c,b) (c&b)
#define REG_KEY *(volatile u16*)0x4000130
void delay();
void showmem(u32 base);

353
dsmouse/arm9/source/hid.h Normal file
View File

@ -0,0 +1,353 @@
/*----------------------------------------------------------------------------
* U S B - K e r n e l
*----------------------------------------------------------------------------
* Name: HID.H
* Purpose: USB HID (Human Interface Device) Definitions
* Version: V1.03
*----------------------------------------------------------------------------
* This file is part of the uVision/ARM development tools.
* Copyright (c) 2005 Keil Software. All rights reserved.
*---------------------------------------------------------------------------*/
#ifndef __HID_H__
#define __HID_H__
/* HID Subclass Codes */
#define HID_SUBCLASS_NONE 0x00
#define HID_SUBCLASS_BOOT 0x01
/* HID Protocol Codes */
#define HID_PROTOCOL_NONE 0x00
#define HID_PROTOCOL_KEYBOARD 0x01
#define HID_PROTOCOL_MOUSE 0x02
/* HID Descriptor Types */
#define HID_HID_DESCRIPTOR_TYPE 0x21
#define HID_REPORT_DESCRIPTOR_TYPE 0x22
#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23
#pragma pack(1)
/* HID Descriptor */
typedef struct _HID_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD bcdHID;
BYTE bCountryCode;
BYTE bNumDescriptors;
/* Array of one or more descriptors */
struct _HID_DESCRIPTOR_LIST {
BYTE bDescriptorType;
WORD wDescriptorLength;
} DescriptorList[1];
} HID_DESCRIPTOR;
#pragma pack()
/* HID Request Codes */
#define HID_REQUEST_GET_REPORT 0x01
#define HID_REQUEST_GET_IDLE 0x02
#define HID_REQUEST_GET_PROTOCOL 0x03
#define HID_REQUEST_SET_REPORT 0x09
#define HID_REQUEST_SET_IDLE 0x0A
#define HID_REQUEST_SET_PROTOCOL 0x0B
/* HID Report Types */
#define HID_REPORT_INPUT 0x01
#define HID_REPORT_OUTPUT 0x02
#define HID_REPORT_FEATURE 0x03
/* Usage Pages */
#define HID_USAGE_PAGE_UNDEFINED 0x00
#define HID_USAGE_PAGE_GENERIC 0x01
#define HID_USAGE_PAGE_SIMULATION 0x02
#define HID_USAGE_PAGE_VR 0x03
#define HID_USAGE_PAGE_SPORT 0x04
#define HID_USAGE_PAGE_GAME 0x05
#define HID_USAGE_PAGE_DEV_CONTROLS 0x06
#define HID_USAGE_PAGE_KEYBOARD 0x07
#define HID_USAGE_PAGE_LED 0x08
#define HID_USAGE_PAGE_BUTTON 0x09
#define HID_USAGE_PAGE_ORDINAL 0x0A
#define HID_USAGE_PAGE_TELEPHONY 0x0B
#define HID_USAGE_PAGE_CONSUMER 0x0C
#define HID_USAGE_PAGE_DIGITIZER 0x0D
#define HID_USAGE_PAGE_UNICODE 0x10
#define HID_USAGE_PAGE_ALPHANUMERIC 0x14
/* ... */
/* Generic Desktop Page (0x01) */
#define HID_USAGE_GENERIC_POINTER 0x01
#define HID_USAGE_GENERIC_MOUSE 0x02
#define HID_USAGE_GENERIC_JOYSTICK 0x04
#define HID_USAGE_GENERIC_GAMEPAD 0x05
#define HID_USAGE_GENERIC_KEYBOARD 0x06
#define HID_USAGE_GENERIC_KEYPAD 0x07
#define HID_USAGE_GENERIC_X 0x30
#define HID_USAGE_GENERIC_Y 0x31
#define HID_USAGE_GENERIC_Z 0x32
#define HID_USAGE_GENERIC_RX 0x33
#define HID_USAGE_GENERIC_RY 0x34
#define HID_USAGE_GENERIC_RZ 0x35
#define HID_USAGE_GENERIC_SLIDER 0x36
#define HID_USAGE_GENERIC_DIAL 0x37
#define HID_USAGE_GENERIC_WHEEL 0x38
#define HID_USAGE_GENERIC_HATSWITCH 0x39
#define HID_USAGE_GENERIC_COUNTED_BUFFER 0x3A
#define HID_USAGE_GENERIC_BYTE_COUNT 0x3B
#define HID_USAGE_GENERIC_MOTION_WAKEUP 0x3C
#define HID_USAGE_GENERIC_VX 0x40
#define HID_USAGE_GENERIC_VY 0x41
#define HID_USAGE_GENERIC_VZ 0x42
#define HID_USAGE_GENERIC_VBRX 0x43
#define HID_USAGE_GENERIC_VBRY 0x44
#define HID_USAGE_GENERIC_VBRZ 0x45
#define HID_USAGE_GENERIC_VNO 0x46
#define HID_USAGE_GENERIC_SYSTEM_CTL 0x80
#define HID_USAGE_GENERIC_SYSCTL_POWER 0x81
#define HID_USAGE_GENERIC_SYSCTL_SLEEP 0x82
#define HID_USAGE_GENERIC_SYSCTL_WAKE 0x83
#define HID_USAGE_GENERIC_SYSCTL_CONTEXT_MENU 0x84
#define HID_USAGE_GENERIC_SYSCTL_MAIN_MENU 0x85
#define HID_USAGE_GENERIC_SYSCTL_APP_MENU 0x86
#define HID_USAGE_GENERIC_SYSCTL_HELP_MENU 0x87
#define HID_USAGE_GENERIC_SYSCTL_MENU_EXIT 0x88
#define HID_USAGE_GENERIC_SYSCTL_MENU_SELECT 0x89
#define HID_USAGE_GENERIC_SYSCTL_MENU_RIGHT 0x8A
#define HID_USAGE_GENERIC_SYSCTL_MENU_LEFT 0x8B
#define HID_USAGE_GENERIC_SYSCTL_MENU_UP 0x8C
#define HID_USAGE_GENERIC_SYSCTL_MENU_DOWN 0x8D
/* ... */
/* Simulation Controls Page (0x02) */
/* ... */
#define HID_USAGE_SIMULATION_RUDDER 0xBA
#define HID_USAGE_SIMULATION_THROTTLE 0xBB
/* ... */
/* Virtual Reality Controls Page (0x03) */
/* ... */
/* Sport Controls Page (0x04) */
/* ... */
/* Game Controls Page (0x05) */
/* ... */
/* Generic Device Controls Page (0x06) */
/* ... */
/* Keyboard/Keypad Page (0x07) */
/* Error "keys" */
#define HID_USAGE_KEYBOARD_NOEVENT 0x00
#define HID_USAGE_KEYBOARD_ROLLOVER 0x01
#define HID_USAGE_KEYBOARD_POSTFAIL 0x02
#define HID_USAGE_KEYBOARD_UNDEFINED 0x03
/* Letters */
#define HID_USAGE_KEYBOARD_aA 0x04
#define HID_USAGE_KEYBOARD_zZ 0x1D
/* Numbers */
#define HID_USAGE_KEYBOARD_ONE 0x1E
#define HID_USAGE_KEYBOARD_ZERO 0x27
#define HID_USAGE_KEYBOARD_RETURN 0x28
#define HID_USAGE_KEYBOARD_ESCAPE 0x29
#define HID_USAGE_KEYBOARD_DELETE 0x2A
/* Funtion keys */
#define HID_USAGE_KEYBOARD_F1 0x3A
#define HID_USAGE_KEYBOARD_F12 0x45
#define HID_USAGE_KEYBOARD_PRINT_SCREEN 0x46
/* Modifier Keys */
#define HID_USAGE_KEYBOARD_LCTRL 0xE0
#define HID_USAGE_KEYBOARD_LSHFT 0xE1
#define HID_USAGE_KEYBOARD_LALT 0xE2
#define HID_USAGE_KEYBOARD_LGUI 0xE3
#define HID_USAGE_KEYBOARD_RCTRL 0xE4
#define HID_USAGE_KEYBOARD_RSHFT 0xE5
#define HID_USAGE_KEYBOARD_RALT 0xE6
#define HID_USAGE_KEYBOARD_RGUI 0xE7
#define HID_USAGE_KEYBOARD_SCROLL_LOCK 0x47
#define HID_USAGE_KEYBOARD_NUM_LOCK 0x53
#define HID_USAGE_KEYBOARD_CAPS_LOCK 0x39
/* ... */
/* LED Page (0x08) */
#define HID_USAGE_LED_NUM_LOCK 0x01
#define HID_USAGE_LED_CAPS_LOCK 0x02
#define HID_USAGE_LED_SCROLL_LOCK 0x03
#define HID_USAGE_LED_COMPOSE 0x04
#define HID_USAGE_LED_KANA 0x05
#define HID_USAGE_LED_POWER 0x06
#define HID_USAGE_LED_SHIFT 0x07
#define HID_USAGE_LED_DO_NOT_DISTURB 0x08
#define HID_USAGE_LED_MUTE 0x09
#define HID_USAGE_LED_TONE_ENABLE 0x0A
#define HID_USAGE_LED_HIGH_CUT_FILTER 0x0B
#define HID_USAGE_LED_LOW_CUT_FILTER 0x0C
#define HID_USAGE_LED_EQUALIZER_ENABLE 0x0D
#define HID_USAGE_LED_SOUND_FIELD_ON 0x0E
#define HID_USAGE_LED_SURROUND_FIELD_ON 0x0F
#define HID_USAGE_LED_REPEAT 0x10
#define HID_USAGE_LED_STEREO 0x11
#define HID_USAGE_LED_SAMPLING_RATE_DETECT 0x12
#define HID_USAGE_LED_SPINNING 0x13
#define HID_USAGE_LED_CAV 0x14
#define HID_USAGE_LED_CLV 0x15
#define HID_USAGE_LED_RECORDING_FORMAT_DET 0x16
#define HID_USAGE_LED_OFF_HOOK 0x17
#define HID_USAGE_LED_RING 0x18
#define HID_USAGE_LED_MESSAGE_WAITING 0x19
#define HID_USAGE_LED_DATA_MODE 0x1A
#define HID_USAGE_LED_BATTERY_OPERATION 0x1B
#define HID_USAGE_LED_BATTERY_OK 0x1C
#define HID_USAGE_LED_BATTERY_LOW 0x1D
#define HID_USAGE_LED_SPEAKER 0x1E
#define HID_USAGE_LED_HEAD_SET 0x1F
#define HID_USAGE_LED_HOLD 0x20
#define HID_USAGE_LED_MICROPHONE 0x21
#define HID_USAGE_LED_COVERAGE 0x22
#define HID_USAGE_LED_NIGHT_MODE 0x23
#define HID_USAGE_LED_SEND_CALLS 0x24
#define HID_USAGE_LED_CALL_PICKUP 0x25
#define HID_USAGE_LED_CONFERENCE 0x26
#define HID_USAGE_LED_STAND_BY 0x27
#define HID_USAGE_LED_CAMERA_ON 0x28
#define HID_USAGE_LED_CAMERA_OFF 0x29
#define HID_USAGE_LED_ON_LINE 0x2A
#define HID_USAGE_LED_OFF_LINE 0x2B
#define HID_USAGE_LED_BUSY 0x2C
#define HID_USAGE_LED_READY 0x2D
#define HID_USAGE_LED_PAPER_OUT 0x2E
#define HID_USAGE_LED_PAPER_JAM 0x2F
#define HID_USAGE_LED_REMOTE 0x30
#define HID_USAGE_LED_FORWARD 0x31
#define HID_USAGE_LED_REVERSE 0x32
#define HID_USAGE_LED_STOP 0x33
#define HID_USAGE_LED_REWIND 0x34
#define HID_USAGE_LED_FAST_FORWARD 0x35
#define HID_USAGE_LED_PLAY 0x36
#define HID_USAGE_LED_PAUSE 0x37
#define HID_USAGE_LED_RECORD 0x38
#define HID_USAGE_LED_ERROR 0x39
#define HID_USAGE_LED_SELECTED_INDICATOR 0x3A
#define HID_USAGE_LED_IN_USE_INDICATOR 0x3B
#define HID_USAGE_LED_MULTI_MODE_INDICATOR 0x3C
#define HID_USAGE_LED_INDICATOR_ON 0x3D
#define HID_USAGE_LED_INDICATOR_FLASH 0x3E
#define HID_USAGE_LED_INDICATOR_SLOW_BLINK 0x3F
#define HID_USAGE_LED_INDICATOR_FAST_BLINK 0x40
#define HID_USAGE_LED_INDICATOR_OFF 0x41
#define HID_USAGE_LED_FLASH_ON_TIME 0x42
#define HID_USAGE_LED_SLOW_BLINK_ON_TIME 0x43
#define HID_USAGE_LED_SLOW_BLINK_OFF_TIME 0x44
#define HID_USAGE_LED_FAST_BLINK_ON_TIME 0x45
#define HID_USAGE_LED_FAST_BLINK_OFF_TIME 0x46
#define HID_USAGE_LED_INDICATOR_COLOR 0x47
#define HID_USAGE_LED_RED 0x48
#define HID_USAGE_LED_GREEN 0x49
#define HID_USAGE_LED_AMBER 0x4A
#define HID_USAGE_LED_GENERIC_INDICATOR 0x4B
/* Button Page (0x09) */
/* There is no need to label these usages. */
/* Ordinal Page (0x0A) */
/* There is no need to label these usages. */
/* Telephony Device Page (0x0B) */
#define HID_USAGE_TELEPHONY_PHONE 0x01
#define HID_USAGE_TELEPHONY_ANSWERING_MACHINE 0x02
#define HID_USAGE_TELEPHONY_MESSAGE_CONTROLS 0x03
#define HID_USAGE_TELEPHONY_HANDSET 0x04
#define HID_USAGE_TELEPHONY_HEADSET 0x05
#define HID_USAGE_TELEPHONY_KEYPAD 0x06
#define HID_USAGE_TELEPHONY_PROGRAMMABLE_BUTTON 0x07
/* ... */
/* Consumer Page (0x0C) */
#define HID_USAGE_CONSUMER_CONTROL 0x01
/* ... */
/* and others ... */
/* HID Report Item Macros */
/* Main Items */
#define HID_Input(x) 0x81,x
#define HID_Output(x) 0x91,x
#define HID_Feature(x) 0xB1,x
#define HID_Collection(x) 0xA1,x
#define HID_EndCollection 0xC0
/* Data (Input, Output, Feature) */
#define HID_Data 0<<0
#define HID_Constant 1<<0
#define HID_Array 0<<1
#define HID_Variable 1<<1
#define HID_Absolute 0<<2
#define HID_Relative 1<<2
#define HID_NoWrap 0<<3
#define HID_Wrap 1<<3
#define HID_Linear 0<<4
#define HID_NonLinear 1<<4
#define HID_PreferredState 0<<5
#define HID_NoPreferred 1<<5
#define HID_NoNullPosition 0<<6
#define HID_NullState 1<<6
#define HID_NonVolatile 0<<7
#define HID_Volatile 1<<7
/* Collection Data */
#define HID_Physical 0x00
#define HID_Application 0x01
#define HID_Logical 0x02
#define HID_Report 0x03
#define HID_NamedArray 0x04
#define HID_UsageSwitch 0x05
#define HID_UsageModifier 0x06
/* Global Items */
#define HID_UsagePage(x) 0x05,x
#define HID_UsagePageVendor(x) 0x06,x,0xFF
#define HID_LogicalMin(x) 0x15,x
#define HID_LogicalMinS(x) 0x16,(x&0xFF),((x>>8)&0xFF)
#define HID_LogicalMinL(x) 0x17,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
#define HID_LogicalMax(x) 0x25,x
#define HID_LogicalMaxS(x) 0x26,(x&0xFF),((x>>8)&0xFF)
#define HID_LogicalMaxL(x) 0x27,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
#define HID_PhysicalMin(x) 0x35,x
#define HID_PhysicalMinS(x) 0x36,(x&0xFF),((x>>8)&0xFF)
#define HID_PhysicalMinL(x) 0x37,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
#define HID_PhysicalMax(x) 0x45,x
#define HID_PhysicalMaxS(x) 0x46,(x&0xFF),((x>>8)&0xFF)
#define HID_PhysicalMaxL(x) 0x47,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
#define HID_UnitExponent(x) 0x55,x
#define HID_Unit(x) 0x65,x
#define HID_UnitS(x) 0x66,(x&0xFF),((x>>8)&0xFF)
#define HID_UnitL(x) 0x67,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
#define HID_ReportSize(x) 0x75,x
#define HID_ReportID(x) 0x85,x
#define HID_ReportCount(x) 0x95,x
#define HID_Push 0xA0
#define HID_Pop 0xB0
/* Local Items */
#define HID_Usage(x) 0x09,x
#define HID_UsageMin(x) 0x19,x
#define HID_UsageMax(x) 0x29,x
#endif /* __HID_H__ */

View File

@ -0,0 +1,213 @@
#include <nds.h>
#include "usb.h"
#include "hid.h"
#include "usbcfg.h"
#include "usbcore.h"
#include "hiduser.h"
#include <nds/touch.h>
BYTE InReport[3];
BYTE OutReport;
BYTE HID_Protocol;
BYTE HID_IdleTime[HID_REPORT_NUM];
u32 lasttouchkey=0;
u32 lasttouchx=0;
u32 lasttouchy=0;
u32 touchcount=0;
u32 touchsumxy=0;
u32 touchmove=0;
void GetInReport()
{
u32 keys;
touchPosition touchXY;
scanKeys();
keys = keysHeld();
touchRead(&touchXY);
InReport[0]=0;
InReport[1]=0;
InReport[2]=0;
if(keys & KEY_TOUCH) {
if(lasttouchkey) {
u32 sp=2;
u32 ax,ay;
if( keys & KEY_UP )sp=3;
if( keys & KEY_DOWN )sp=1;
ax=(touchXY.px*sp)-(lasttouchx*sp);
ay=(touchXY.py*sp)-(lasttouchy*sp);
InReport[1]=ax;
InReport[2]=ay;
sp=1;
ax=(touchXY.px*sp)-(lasttouchx*sp);
ay=(touchXY.py*sp)-(lasttouchy*sp);
if(ax&0x80000000)ax=0-ax;
if(ay&0x80000000)ay=0-ay;
touchsumxy+=ax+ay;
if((touchcount>150)&&(touchsumxy<60))touchmove=1;
}
} else {
if(lasttouchkey) {
if(touchsumxy<20) { if(touchcount<100)InReport[0]|=1<<0; }
}
}
if( keys & KEY_LEFT )InReport[0]|=1<<0;
if( keys & KEY_RIGHT )InReport[0]|=1<<1;
if( keys & KEY_A )InReport[0]|=1<<1;
if( keys & KEY_B )InReport[0]|=1<<0;
if( keys & KEY_X )InReport[0]|=1<<1;
if( keys & KEY_Y )InReport[0]|=1<<0;
if( keys & KEY_R )InReport[0]|=1<<1;
if( keys & KEY_L )InReport[0]|=1<<0;
if(touchmove)InReport[0]|=1<<0;
if(keys & KEY_TOUCH) {
touchcount++;
lasttouchkey=1;
lasttouchx=touchXY.px;
lasttouchy=touchXY.py;
} else {
touchcount=0;
lasttouchkey=0;
lasttouchx=0;
lasttouchy=0;
touchsumxy=0;
touchmove=0;
}
}
void SetOutReport()
{
;
}
/*
* HID Get Report Request Callback
* Called automatically on HID Get Report Request
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_GetReport (void) {
/* ReportID = SetupPacket.wValue.WB.L; */
switch (SetupPacket.wValue.WB.H) {
case HID_REPORT_INPUT:
GetInReport();
EP0Buf[0] = InReport[0];
EP0Buf[1] = InReport[1];
EP0Buf[2] = InReport[2];
break;
case HID_REPORT_OUTPUT:
return (FALSE); /* Not Supported */
case HID_REPORT_FEATURE:
/* EP0Buf[] = ...; */
/* break; */
return (FALSE); /* Not Supported */
}
return (TRUE);
}
/*
* HID Set Report Request Callback
* Called automatically on HID Set Report Request
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_SetReport (void) {
/* ReportID = SetupPacket.wValue.WB.L; */
switch (SetupPacket.wValue.WB.H) {
case HID_REPORT_INPUT:
return (FALSE); /* Not Supported */
case HID_REPORT_OUTPUT:
OutReport = EP0Buf[0];
SetOutReport();
break;
case HID_REPORT_FEATURE:
return (FALSE); /* Not Supported */
}
return (TRUE);
}
/*
* HID Get Idle Request Callback
* Called automatically on HID Get Idle Request
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_GetIdle (void) {
EP0Buf[0] = HID_IdleTime[SetupPacket.wValue.WB.L];
return (TRUE);
}
/*
* HID Set Idle Request Callback
* Called automatically on HID Set Idle Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_SetIdle (void) {
HID_IdleTime[SetupPacket.wValue.WB.L] = SetupPacket.wValue.WB.H;
/* Idle Handling if needed */
/* ... */
return (TRUE);
}
/*
* HID Get Protocol Request Callback
* Called automatically on HID Get Protocol Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_GetProtocol (void) {
EP0Buf[0] = HID_Protocol;
return (TRUE);
}
/*
* HID Set Protocol Request Callback
* Called automatically on HID Set Protocol Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_SetProtocol (void) {
HID_Protocol = SetupPacket.wValue.WB.L;
/* Protocol Handling if needed */
/* ... */
return (TRUE);
}
//end of file

View File

@ -0,0 +1,26 @@
#ifndef __HIDUSER_H__
#define __HIDUSER_H__
/* HID Number of Reports */
#define HID_REPORT_NUM 1
/* HID Global Variables */
extern BYTE HID_Protocol;
extern BYTE HID_IdleTime[HID_REPORT_NUM];
/* HID Requests Callback Functions */
extern BOOL HID_GetReport (void);
extern BOOL HID_SetReport (void);
extern BOOL HID_GetIdle (void);
extern BOOL HID_SetIdle (void);
extern BOOL HID_GetProtocol (void);
extern BOOL HID_SetProtocol (void);
extern BYTE InReport[3];
extern BYTE OutReport;
void GetInReport();
void SetOutReport();
#endif /* __HIDUSER_H__ */

View File

@ -0,0 +1,61 @@
/*---------------------------------------------------------------------------------
---------------------------------------------------------------------------------*/
#include "nds.h"
#include <nds/arm9/console.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "usbhal.h"
#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"
#include "usbcore.h"
#include "debug.h"
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
sysSetBusOwners(1,1);
videoSetMode(0); //not using the main screen
// Enable console
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
REG_BG0CNT_SUB = BG_MAP_BASE(4) | BG_COLOR_16 | BG_TILE_BASE(6) | BG_PRIORITY(0);
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 6, false, true);
printf("NDS Mouse V1.2\n");
u16 tmp=*(vu16*)0x04000204;
tmp&=~0x1F;
tmp|=0x1A;
*(vu16*)0x04000204=tmp;
D14_ID;
D14_ID;
D14_ID;
D14_ID;
if(D14_ID!=0x8151) {
printf("USBCard init failed!\n");
while(1);
}
printf("USBCard init ok!\n");
D14USBInit();
USB_Connect(1);
while(1) { USB_ISR(); }
return 0;
}

86
dsmouse/arm9/source/msc.h Normal file
View File

@ -0,0 +1,86 @@
#ifndef __MSC_H__
#define __MSC_H__
#include "usbhal.h"
/* MSC Subclass Codes */
#define MSC_SUBCLASS_RBC 0x01
#define MSC_SUBCLASS_SFF8020I_MMC2 0x02
#define MSC_SUBCLASS_QIC157 0x03
#define MSC_SUBCLASS_UFI 0x04
#define MSC_SUBCLASS_SFF8070I 0x05
#define MSC_SUBCLASS_SCSI 0x06
/* MSC Protocol Codes */
#define MSC_PROTOCOL_CBI_INT 0x00
#define MSC_PROTOCOL_CBI_NOINT 0x01
#define MSC_PROTOCOL_BULK_ONLY 0x50
/* MSC Request Codes */
#define MSC_REQUEST_RESET 0xFF
#define MSC_REQUEST_GET_MAX_LUN 0xFE
/* MSC Bulk-only Stage */
#define MSC_BS_CBW 0 /* Command Block Wrapper */
#define MSC_BS_DATA_OUT 1 /* Data Out Phase */
#define MSC_BS_DATA_IN 2 /* Data In Phase */
#define MSC_BS_DATA_IN_LAST 3 /* Data In Last Phase */
#define MSC_BS_DATA_IN_LAST_STALL 4 /* Data In Last Phase with Stall */
#define MSC_BS_CSW 5 /* Command Status Wrapper */
#define MSC_BS_ERROR 6 /* Error */
#pragma pack(1)
/* Bulk-only Command Block Wrapper */
typedef struct _MSC_CBW {
DWORD dSignature;
DWORD dTag;
DWORD dDataLength;
BYTE bmFlags;
BYTE bLUN;
BYTE bCBLength;
BYTE CB[16];
} MSC_CBW;
/* Bulk-only Command Status Wrapper */
typedef struct _MSC_CSW {
DWORD dSignature;
DWORD dTag;
DWORD dDataResidue;
BYTE bStatus;
} MSC_CSW;
#pragma pack()
#define MSC_CBW_Signature 0x43425355
#define MSC_CSW_Signature 0x53425355
/* CSW Status Definitions */
#define CSW_CMD_PASSED 0x00
#define CSW_CMD_FAILED 0x01
#define CSW_PHASE_ERROR 0x02
/* SCSI Commands */
#define SCSI_TEST_UNIT_READY 0x00
#define SCSI_REQUEST_SENSE 0x03
#define SCSI_FORMAT_UNIT 0x04
#define SCSI_INQUIRY 0x12
#define SCSI_MODE_SELECT6 0x15
#define SCSI_MODE_SENSE6 0x1A
#define SCSI_START_STOP_UNIT 0x1B
#define SCSI_MEDIA_REMOVAL 0x1E
#define SCSI_READ_FORMAT_CAPACITIES 0x23
#define SCSI_READ_CAPACITY 0x25
#define SCSI_READ10 0x28
#define SCSI_WRITE10 0x2A
#define SCSI_VERIFY10 0x2F
#define SCSI_MODE_SELECT10 0x55
#define SCSI_MODE_SENSE10 0x5A
#endif /* __MSC_H__ */

224
dsmouse/arm9/source/usb.h Normal file
View File

@ -0,0 +1,224 @@
/*----------------------------------------------------------------------------
* U S B - K e r n e l
*----------------------------------------------------------------------------
* Name: USB.H
* Purpose: USB Definitions
* Version: V1.03
*----------------------------------------------------------------------------
* This file is part of the uVision/ARM development tools.
* Copyright (c) 2005 Keil Software. All rights reserved.
*---------------------------------------------------------------------------*/
#ifndef __USB_H__
#define __USB_H__
#include "usbhal.h"
#pragma pack(1)
typedef union {
WORD W;
struct {
BYTE L;
BYTE H;
} WB;
} WORD_BYTE;
/* bmRequestType.Dir */
#define REQUEST_HOST_TO_DEVICE 0
#define REQUEST_DEVICE_TO_HOST 1
/* bmRequestType.Type */
#define REQUEST_STANDARD 0
#define REQUEST_CLASS 1
#define REQUEST_VENDOR 2
#define REQUEST_RESERVED 3
/* bmRequestType.Recipient */
#define REQUEST_TO_DEVICE 0
#define REQUEST_TO_INTERFACE 1
#define REQUEST_TO_ENDPOINT 2
#define REQUEST_TO_OTHER 3
/* bmRequestType Definition */
typedef union _REQUEST_TYPE {
struct _BM {
BYTE Recipient : 5;
BYTE Type : 2;
BYTE Dir : 1;
} BM;
BYTE B;
} REQUEST_TYPE;
/* USB Standard Request Codes */
#define USB_REQUEST_GET_STATUS 0
#define USB_REQUEST_CLEAR_FEATURE 1
#define USB_REQUEST_SET_FEATURE 3
#define USB_REQUEST_SET_ADDRESS 5
#define USB_REQUEST_GET_DESCRIPTOR 6
#define USB_REQUEST_SET_DESCRIPTOR 7
#define USB_REQUEST_GET_CONFIGURATION 8
#define USB_REQUEST_SET_CONFIGURATION 9
#define USB_REQUEST_GET_INTERFACE 10
#define USB_REQUEST_SET_INTERFACE 11
#define USB_REQUEST_SYNC_FRAME 12
/* USB GET_STATUS Bit Values */
#define USB_GETSTATUS_SELF_POWERED 0x01
#define USB_GETSTATUS_REMOTE_WAKEUP 0x02
#define USB_GETSTATUS_ENDPOINT_STALL 0x01
/* USB Standard Feature selectors */
#define USB_FEATURE_ENDPOINT_STALL 0
#define USB_FEATURE_REMOTE_WAKEUP 1
/* USB Default Control Pipe Setup Packet */
typedef struct _USB_SETUP_PACKET {
REQUEST_TYPE bmRequestType;
BYTE bRequest;
WORD_BYTE wValue;
WORD_BYTE wIndex;
WORD wLength;
} USB_SETUP_PACKET;
/* USB Descriptor Types */
#define USB_DEVICE_DESCRIPTOR_TYPE 1
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
#define USB_STRING_DESCRIPTOR_TYPE 3
#define USB_INTERFACE_DESCRIPTOR_TYPE 4
#define USB_ENDPOINT_DESCRIPTOR_TYPE 5
#define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6
#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8
/* USB Device Classes */
#define USB_DEVICE_CLASS_RESERVED 0x00
#define USB_DEVICE_CLASS_AUDIO 0x01
#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
#define USB_DEVICE_CLASS_MONITOR 0x04
#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
#define USB_DEVICE_CLASS_POWER 0x06
#define USB_DEVICE_CLASS_PRINTER 0x07
#define USB_DEVICE_CLASS_STORAGE 0x08
#define USB_DEVICE_CLASS_HUB 0x09
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
/* bmAttributes in Configuration Descriptor */
#define USB_CONFIG_POWERED_MASK 0xC0
#define USB_CONFIG_BUS_POWERED 0x80
#define USB_CONFIG_SELF_POWERED 0x40
#define USB_CONFIG_REMOTE_WAKEUP 0x20
/* bMaxPower in Configuration Descriptor */
#define USB_CONFIG_POWER_MA(mA) ((mA)/2)
/* bEndpointAddress in Endpoint Descriptor */
#define USB_ENDPOINT_DIRECTION_MASK 0x80
#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
#define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
/* bmAttributes in Endpoint Descriptor */
#define USB_ENDPOINT_TYPE_MASK 0x03
#define USB_ENDPOINT_TYPE_CONTROL 0x00
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
#define USB_ENDPOINT_TYPE_BULK 0x02
#define USB_ENDPOINT_TYPE_INTERRUPT 0x03
#define USB_ENDPOINT_SYNC_MASK 0x0C
#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00
#define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04
#define USB_ENDPOINT_SYNC_ADAPTIVE 0x08
#define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C
#define USB_ENDPOINT_USAGE_MASK 0x30
#define USB_ENDPOINT_USAGE_DATA 0x00
#define USB_ENDPOINT_USAGE_FEEDBACK 0x10
#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20
#define USB_ENDPOINT_USAGE_RESERVED 0x30
/* USB Standard Device Descriptor */
typedef struct _USB_DEVICE_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD bcdUSB;
BYTE bDeviceClass;
BYTE bDeviceSubClass;
BYTE bDeviceProtocol;
BYTE bMaxPacketSize0;
WORD idVendor;
WORD idProduct;
WORD bcdDevice;
BYTE iManufacturer;
BYTE iProduct;
BYTE iSerialNumber;
BYTE bNumConfigurations;
} USB_DEVICE_DESCRIPTOR;
/* USB 2.0 Device Qualifier Descriptor */
typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD bcdUSB;
BYTE bDeviceClass;
BYTE bDeviceSubClass;
BYTE bDeviceProtocol;
BYTE bMaxPacketSize0;
BYTE bNumConfigurations;
BYTE bReserved;
} USB_DEVICE_QUALIFIER_DESCRIPTOR;
/* USB Standard Configuration Descriptor */
typedef struct _USB_CONFIGURATION_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD wTotalLength;
BYTE bNumInterfaces;
BYTE bConfigurationValue;
BYTE iConfiguration;
BYTE bmAttributes;
BYTE MaxPower;
} USB_CONFIGURATION_DESCRIPTOR;
/* USB Standard Interface Descriptor */
typedef struct _USB_INTERFACE_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
BYTE bInterfaceNumber;
BYTE bAlternateSetting;
BYTE bNumEndpoints;
BYTE bInterfaceClass;
BYTE bInterfaceSubClass;
BYTE bInterfaceProtocol;
BYTE iInterface;
} USB_INTERFACE_DESCRIPTOR;
/* USB Standard Endpoint Descriptor */
typedef struct _USB_ENDPOINT_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
BYTE bEndpointAddress;
BYTE bmAttributes;
WORD wMaxPacketSize;
BYTE bInterval;
} USB_ENDPOINT_DESCRIPTOR;
/* USB String Descriptor */
typedef struct _USB_STRING_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD bString/*[]*/;
} USB_STRING_DESCRIPTOR;
/* USB Common Descriptor */
typedef struct _USB_COMMON_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
} USB_COMMON_DESCRIPTOR;
#pragma pack()
#endif /* __USB_H__ */

View File

@ -0,0 +1,136 @@
#ifndef __USBCFG_H__
#define __USBCFG_H__
/*
// <h> USB Configuration
// <o0> USB Power
// <i> Default Power Setting
// <0=> Bus-powered
// <1=> Self-powered
// <o1> Max Number of Interfaces <1-256>
// <o2> Max Number of Endpoints <1-32>
// <o3> Max Endpoint 0 Packet Size
// <8=> 8 Bytes <16=> 16 Bytes <32=> 32 Bytes <64=> 64 Bytes
// <e4> DMA Transfer
// <i> Use DMA for selected Endpoints
// <o5.0> Endpoint 0 Out
// <o5.1> Endpoint 0 In
// <o5.2> Endpoint 1 Out
// <o5.3> Endpoint 1 In
// <o5.4> Endpoint 2 Out
// <o5.5> Endpoint 2 In
// <o5.6> Endpoint 3 Out
// <o5.7> Endpoint 3 In
// <o5.8> Endpoint 4 Out
// <o5.9> Endpoint 4 In
// <o5.10> Endpoint 5 Out
// <o5.11> Endpoint 5 In
// <o5.12> Endpoint 6 Out
// <o5.13> Endpoint 6 In
// <o5.14> Endpoint 7 Out
// <o5.15> Endpoint 7 In
// <o5.16> Endpoint 8 Out
// <o5.17> Endpoint 8 In
// <o5.18> Endpoint 9 Out
// <o5.19> Endpoint 9 In
// <o5.20> Endpoint 10 Out
// <o5.21> Endpoint 10 In
// <o5.22> Endpoint 11 Out
// <o5.23> Endpoint 11 In
// <o5.24> Endpoint 12 Out
// <o5.25> Endpoint 12 In
// <o5.26> Endpoint 13 Out
// <o5.27> Endpoint 13 In
// <o5.28> Endpoint 14 Out
// <o5.29> Endpoint 14 In
// <o5.30> Endpoint 15 Out
// <o5.31> Endpoint 15 In
// </e>
// </h>
*/
#define USB_POWER 0
#define USB_IF_NUM 4
#define USB_EP_NUM 6
#define USB_DMA 0
#define USB_DMA_EP 0x00000000
/*
// <h> USB Event Handlers
// <h> Device Events
// <o0.0> Power Event
// <o1.0> Reset Event
// <o2.0> Suspend Event
// <o3.0> Resume Event
// <o4.0> Remote Wakeup Event
// <o5.0> Start of Frame Event
// <o6.0> Error Event
// </h>
// <h> Endpoint Events
// <o7.0> Endpoint 0 Event
// <o7.1> Endpoint 1 Event
// <o7.2> Endpoint 2 Event
// <o7.3> Endpoint 3 Event
// <o7.4> Endpoint 4 Event
// <o7.5> Endpoint 5 Event
// <o7.6> Endpoint 6 Event
// <o7.7> Endpoint 7 Event
// <o7.8> Endpoint 8 Event
// <o7.9> Endpoint 9 Event
// <o7.10> Endpoint 10 Event
// <o7.11> Endpoint 11 Event
// <o7.12> Endpoint 12 Event
// <o7.13> Endpoint 13 Event
// <o7.14> Endpoint 14 Event
// <o7.15> Endpoint 15 Event
// </h>
// <h> USB Core Events
// <o8.0> Set Configuration Event
// <o9.0> Set Interface Event
// <o10.0> Set/Clear Feature Event
// </h>
// </h>
*/
#define USB_POWER_EVENT 0
#define USB_RESET_EVENT 1
#define USB_SUSPEND_EVENT 1
#define USB_RESUME_EVENT 1
#define USB_WAKEUP_EVENT 0
#define USB_SOF_EVENT 0
#define USB_ERROR_EVENT 0
#define USB_EP_EVENT 0x0005
#define USB_CONFIGURE_EVENT 1
#define USB_INTERFACE_EVENT 0
#define USB_FEATURE_EVENT 0
/*
// <e0> USB Class Support
// <e1> Human Interface Device (HID)
// <o2> Interface Number <0-255>
// </e>
// <e3> Mass Storage
// <o4> Interface Number <0-255>
// </e>
// <e5> Audio Device
// <o6> Control Interface Number <0-255>
// <o7> Streaming Interface 1 Number <0-255>
// <o8> Streaming Interface 2 Number <0-255>
// </e>
// </e>
*/
#define USB_CLASS 1
#define USB_HID 1
#define USB_HID_IF_NUM 0
#define USB_MSC 0
#define USB_MSC_IF_NUM 0
#define USB_AUDIO 0
#define USB_ADC_CIF_NUM 0
#define USB_ADC_SIF1_NUM 1
#define USB_ADC_SIF2_NUM 2
#endif /* __USBCFG_H__ */

View File

@ -0,0 +1,775 @@
#include "usbhal.h"
#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"
#include "usbcore.h"
#include "usbdesc.h"
#include "usbuser.h"
#if USB_AUDIO
#include "audio.h"
#include "adcuser.h"
#endif
#if USB_HID
#include "hid.h"
#include "hiduser.h"
#endif
#if USB_MSC
#include "msc.h"
#include "mscuser.h"
#endif
WORD USB_DeviceStatus;
BYTE USB_DeviceAddress;
BYTE USB_Configuration;
DWORD USB_EndPointMask;
DWORD USB_EndPointHalt;
BYTE USB_NumInterfaces;
BYTE USB_AltSetting[USB_IF_NUM];
BYTE EP0Buf[64];
USB_EP_DATA EP0Data;
USB_SETUP_PACKET SetupPacket;
void*PointAdd(void*inp,DWORD len)
{
BYTE*ptr=(BYTE*)inp;
ptr+=len;
return ptr;
}
/*
* Reset USB Core
* Parameters: None
* Return Value: None
*/
void USB_ResetCore (void) {
USB_DeviceStatus = USB_POWER;
USB_DeviceAddress = 0;
USB_Configuration = 0;
USB_EndPointMask = 0x00010001;
USB_EndPointHalt = 0x00000000;
}
/*
* USB Request - Setup Stage
* Parameters: None (global SetupPacket)
* Return Value: None
*/
void USB_SetupStage (void) {
USB_ReadEP(0x10, (BYTE*)&SetupPacket);
if((SetupPacket.bmRequestType.BM.Dir)||(SetupPacket.wLength==0))
{
// For Get command via Control In
// For Set command without Data Stage via Control Out
// First of all, AckSetup to make it available for BUFFER fill in fifo
}
}
/*
* USB Request - Data In Stage
* Parameters: None (global EP0Data)
* Return Value: None
*/
void USB_DataInStage (void) {
DWORD cnt;
if(EP0Data.Count)
{
if (EP0Data.Count > USB_MAX_PACKET0) {
cnt = USB_MAX_PACKET0;
} else {
cnt = EP0Data.Count;
}
cnt = USB_WriteEP(0x80, EP0Data.pData, cnt);
EP0Data.pData += cnt;
EP0Data.Count -= cnt;
}
else
{
USB_AcknowledgeEndpoint(0x00);
USB_SetStallEP(0x80);
}
}
/*
* USB Request - Data Out Stage
* Parameters: None (global EP0Data)
* Return Value: None
*/
void USB_DataOutStage (void) {
DWORD cnt;
cnt = USB_ReadEP(0x00, EP0Data.pData);
EP0Data.pData += cnt;
EP0Data.Count -= cnt;
}
/*
* USB Request - Status In Stage
* Parameters: None
* Return Value: None
*/
void USB_StatusInStage (void)
{
USB_AcknowledgeEndpoint(0x80);
}
/*
* USB Request - Status Out Stage
* Parameters: None
* Return Value: None
*/
void USB_StatusOutStage (void) {
USB_ReadEP(0x00, EP0Buf);
}
/*
* Get Status USB Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
__inline BOOL USB_GetStatus (void) {
DWORD n, m;
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
EP0Data.pData = (BYTE *)&USB_DeviceStatus;
USB_DataInStage();
break;
case REQUEST_TO_INTERFACE:
if ((USB_Configuration != 0) && (SetupPacket.wIndex.WB.L < USB_NumInterfaces)) {
*((WORD *)EP0Buf) = 0;
EP0Data.pData = EP0Buf;
USB_DataInStage();
} else {
return (FALSE);
}
break;
case REQUEST_TO_ENDPOINT:
n = SetupPacket.wIndex.WB.L & 0x8F;
m = (n & 0x80) ? ((1 << 16) << n) : (1 << n);
if (((USB_Configuration != 0) || ((n & 0x0F) == 0)) && (USB_EndPointMask & m)) {
*((WORD *)EP0Buf) = (USB_EndPointHalt & m) ? 1 : 0;
EP0Data.pData = EP0Buf;
USB_DataInStage();
} else {
return (FALSE);
}
break;
default:
return (FALSE);
}
return (TRUE);
}
/*
* Set/Clear Feature USB Request
* Parameters: sc: 0 - Clear, 1 - Set
* None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
__inline BOOL USB_SetClrFeature (DWORD sc) {
DWORD n, m;
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
if (SetupPacket.wValue.W == USB_FEATURE_REMOTE_WAKEUP) {
if (sc) {
USB_WakeUpCfg(TRUE);
USB_DeviceStatus |= USB_GETSTATUS_REMOTE_WAKEUP;
} else {
USB_WakeUpCfg(FALSE);
USB_DeviceStatus &= ~USB_GETSTATUS_REMOTE_WAKEUP;
}
} else {
return (FALSE);
}
break;
case REQUEST_TO_INTERFACE:
return (FALSE);
case REQUEST_TO_ENDPOINT:
n = SetupPacket.wIndex.WB.L & 0x8F;
m = (n & 0x80) ? ((1 << 16) << n) : (1 << n);
if ((USB_Configuration != 0) && ((n & 0x0F) != 0) && (USB_EndPointMask & m)) {
if (SetupPacket.wValue.W == USB_FEATURE_ENDPOINT_STALL) {
if (sc) {
USB_SetStallEP(n);
USB_EndPointHalt |= m;
} else {
USB_ClrStallEP(n);
USB_EndPointHalt &= ~m;
}
} else {
return (FALSE);
}
} else {
return (FALSE);
}
break;
default:
return (FALSE);
}
return (TRUE);
}
/*
* Get Descriptor USB Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
__inline BOOL USB_GetDescriptor (void) {
BYTE *pD;
DWORD len, n;
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
switch (SetupPacket.wValue.WB.H) {
case USB_DEVICE_DESCRIPTOR_TYPE:
EP0Data.pData = (BYTE *)USB_DeviceDescriptor;
len = USB_DEVICE_DESC_SIZE;
break;
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
pD = (BYTE *)USB_ConfigDescriptor;
for (n = 0; n != SetupPacket.wValue.WB.L; n++) {
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength != 0) {
pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
}
}
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength == 0) {
return (FALSE);
}
EP0Data.pData = pD;
len = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
break;
case USB_STRING_DESCRIPTOR_TYPE:
EP0Data.pData = (BYTE *)USB_StringDescriptor + SetupPacket.wValue.WB.L;
len = ((USB_STRING_DESCRIPTOR *)EP0Data.pData)->bLength;
break;
default:
return (FALSE);
}
break;
case REQUEST_TO_INTERFACE:
switch (SetupPacket.wValue.WB.H) {
#if USB_HID
case HID_HID_DESCRIPTOR_TYPE:
if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) {
return (FALSE); /* Only Single HID Interface is supported */
}
EP0Data.pData = (BYTE *)USB_ConfigDescriptor + HID_DESC_OFFSET;
len = HID_DESC_SIZE;
break;
case HID_REPORT_DESCRIPTOR_TYPE:
if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) {
return (FALSE); /* Only Single HID Interface is supported */
}
EP0Data.pData = (BYTE *)HID_ReportDescriptor;
len = HID_ReportDescSize;
break;
case HID_PHYSICAL_DESCRIPTOR_TYPE:
return (FALSE); /* HID Physical Descriptor is not supported */
#endif
default:
return (FALSE);
}
break;
default:
return (FALSE);
}
if (EP0Data.Count > len) {
EP0Data.Count = len;
}
USB_DataInStage();
return (TRUE);
}
/*
* Set Configuration USB Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
bool USB_SetConfiguration (void) {
USB_COMMON_DESCRIPTOR *pD;
DWORD alt=0, n=0, m=0;
if (SetupPacket.wValue.WB.L) {
pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor;
while (pD->bLength) {
switch (pD->bDescriptorType) {
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue == SetupPacket.wValue.WB.L) {
USB_Configuration = SetupPacket.wValue.WB.L;
USB_NumInterfaces = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->bNumInterfaces;
for (n = 0; n < USB_IF_NUM; n++) {
USB_AltSetting[n] = 0;
}
for (n = 1; n < 16; n++) {
if (USB_EndPointMask & (1 << n)) {
USB_DisableEP(n);
}
if (USB_EndPointMask & ((1 << 16) << n)) {
USB_DisableEP(n | 0x80);
}
}
USB_EndPointMask = 0x00010001;
USB_EndPointHalt = 0x00000000;
USB_Configure(TRUE);
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bmAttributes & USB_CONFIG_SELF_POWERED) {
USB_DeviceStatus |= USB_GETSTATUS_SELF_POWERED;
} else {
USB_DeviceStatus &= ~USB_GETSTATUS_SELF_POWERED;
}
} else {
pD=PointAdd(pD,((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength);//(BYTE *)pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
continue;
}
break;
case USB_INTERFACE_DESCRIPTOR_TYPE:
alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting;
break;
case USB_ENDPOINT_DESCRIPTOR_TYPE:
if (alt == 0) {
n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F;
m = (n & 0x80) ? ((1 << 16) << n) : (1 << n);
USB_EndPointMask |= m;
USB_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD);
USB_EnableEP(n);
USB_ResetEP(n);
}
break;
}
pD =PointAdd(pD,pD->bLength);
}
}
else {
USB_Configuration = 0;
for (n = 1; n < 16; n++) {
if (USB_EndPointMask & (1 << n)) {
USB_DisableEP(n);
}
if (USB_EndPointMask & ((1 << 16) << n)) {
USB_DisableEP(n | 0x80);
}
}
USB_EndPointMask = 0x00010001;
USB_EndPointHalt = 0x00000000;
USB_Configure(FALSE);
}
if (USB_Configuration == SetupPacket.wValue.WB.L) {
return (TRUE);
} else {
return (FALSE);
}
}
/*
* Set Interface USB Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
bool USB_SetInterface (void) {
USB_COMMON_DESCRIPTOR *pD;
DWORD ifn=0, alt=0, old=0, msk=0, n=0, m=0;
BOOL set;
if (USB_Configuration == 0) return (FALSE);
set = FALSE;
pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor;
while (pD->bLength) {
switch (pD->bDescriptorType) {
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue != USB_Configuration) {
pD=PointAdd(pD,((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength);//(BYTE *)pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
continue;
}
break;
case USB_INTERFACE_DESCRIPTOR_TYPE:
ifn = ((USB_INTERFACE_DESCRIPTOR *)pD)->bInterfaceNumber;
alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting;
msk = 0;
if ((ifn == SetupPacket.wIndex.WB.L) && (alt == SetupPacket.wValue.WB.L)) {
set = TRUE;
old = USB_AltSetting[ifn];
USB_AltSetting[ifn] = (BYTE)alt;
}
break;
case USB_ENDPOINT_DESCRIPTOR_TYPE:
if (ifn == SetupPacket.wIndex.WB.L) {
n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F;
m = (n & 0x80) ? ((1 << 16) << n) : (1 << n);
if (alt == SetupPacket.wValue.WB.L) {
USB_EndPointMask |= m;
USB_EndPointHalt &= ~m;
USB_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD);
USB_EnableEP(n);
USB_ResetEP(n);
msk |= m;
}
else if ((alt == old) && ((msk & m) == 0)) {
USB_EndPointMask &= ~m;
USB_EndPointHalt &= ~m;
USB_DisableEP(n);
}
}
break;
}
pD=PointAdd(pD,pD->bLength);//(BYTE *)pD += pD->bLength;
}
return (set);
}
/*
* USB Endpoint 0 Event Callback
* Parameter: event
*/
void USB_EndPoint0 (BYTE event) {
switch (event) {
case USB_EVT_SETUP:
USB_SetupStage();
USB_DirCtrlEP(SetupPacket.bmRequestType.BM.Dir);
EP0Data.Count = SetupPacket.wLength;
switch (SetupPacket.bmRequestType.BM.Type) {
case REQUEST_STANDARD:
switch (SetupPacket.bRequest) {
case USB_REQUEST_GET_STATUS:
if (!USB_GetStatus()) {
goto stall_i;
}
break;
case USB_REQUEST_CLEAR_FEATURE:
if (!USB_SetClrFeature(0)) {
goto stall_i;
}
USB_StatusInStage();
#if USB_FEATURE_EVENT
USB_Feature_Event();
#endif
break;
case USB_REQUEST_SET_FEATURE:
if (!USB_SetClrFeature(1)) {
goto stall_i;
}
USB_StatusInStage();
#if USB_FEATURE_EVENT
USB_Feature_Event();
#endif
break;
case USB_REQUEST_SET_ADDRESS:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
USB_DeviceAddress = 0x80 | SetupPacket.wValue.WB.L;
USB_StatusInStage();
USB_SetAddress(USB_DeviceAddress);
break;
default:
goto stall_i;
}
break;
case USB_REQUEST_GET_DESCRIPTOR:
if (!USB_GetDescriptor()) {
goto stall_i;
}
break;
case USB_REQUEST_SET_DESCRIPTOR:
/*stall_o:*/ USB_SetStallEP(0x00);
EP0Data.Count = 0;
break;
case USB_REQUEST_GET_CONFIGURATION:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
EP0Data.pData = &USB_Configuration;
USB_DataInStage();
break;
default:
goto stall_i;
}
break;
case USB_REQUEST_SET_CONFIGURATION:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
if (!USB_SetConfiguration()) {
goto stall_i;
}
USB_StatusInStage();
#if USB_CONFIGURE_EVENT
USB_Configure_Event();
#endif
break;
default:
goto stall_i;
}
break;
case USB_REQUEST_GET_INTERFACE:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_INTERFACE:
if ((USB_Configuration != 0) &&
(SetupPacket.wIndex.WB.L < USB_NumInterfaces)) {
EP0Data.pData = USB_AltSetting + SetupPacket.wIndex.WB.L;
USB_DataInStage();
} else {
goto stall_i;
}
break;
default:
goto stall_i;
}
break;
case USB_REQUEST_SET_INTERFACE:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_INTERFACE:
if (!USB_SetInterface()) {
goto stall_i;
}
USB_StatusInStage();
#if USB_INTERFACE_EVENT
USB_Interface_Event();
#endif
break;
default:
goto stall_i;
}
break;
default:
goto stall_i;
}
break;
case REQUEST_CLASS:
#if USB_CLASS
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_INTERFACE:
#if USB_HID
if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) {
switch (SetupPacket.bRequest) {
case HID_REQUEST_GET_REPORT:
if (HID_GetReport()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
break;
case HID_REQUEST_SET_REPORT:
EP0Data.pData = EP0Buf;
goto class_ok;
case HID_REQUEST_GET_IDLE:
if (HID_GetIdle()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
break;
case HID_REQUEST_SET_IDLE:
if (HID_SetIdle()) {
USB_StatusInStage();
goto class_ok;
}
break;
case HID_REQUEST_GET_PROTOCOL:
if (HID_GetProtocol()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
break;
case HID_REQUEST_SET_PROTOCOL:
if (HID_SetProtocol()) {
USB_StatusInStage();
goto class_ok;
}
break;
}
}
#endif /* USB_HID */
#if USB_MSC
if (SetupPacket.wIndex.WB.L == USB_MSC_IF_NUM) {
switch (SetupPacket.bRequest) {
case MSC_REQUEST_RESET:
if (MSC_Reset()) {
USB_StatusInStage();
goto class_ok;
}
break;
case MSC_REQUEST_GET_MAX_LUN:
if (MSC_GetMaxLUN()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
break;
}
}
#endif /* USB_MSC */
#if USB_AUDIO
if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) ||
(SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) ||
(SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) {
if (SetupPacket.bmRequestType.BM.Dir) {
if (ADC_IF_GetRequest()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
} else {
EP0Data.pData = EP0Buf;
goto class_ok;
}
}
#endif /* USB_AUDIO */
goto stall_i;
#if USB_AUDIO
case REQUEST_TO_ENDPOINT:
if (SetupPacket.bmRequestType.BM.Dir) {
if (ADC_EP_GetRequest()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
} else {
EP0Data.pData = EP0Buf;
goto class_ok;
}
goto stall_i;
#endif /* USB_AUDIO */
default:
goto stall_i;
}
class_ok:
break;
#else
goto stall_i;
#endif /* USB_CLASS */
case REQUEST_VENDOR:
goto stall_i;
default:
stall_i: USB_SetStallEP(0x80);
EP0Data.Count = 0;
break;
}
break;
case USB_EVT_OUT:
if (SetupPacket.bmRequestType.BM.Dir == 0) {
if (EP0Data.Count) {
USB_DataOutStage();
if (EP0Data.Count == 0) {
switch (SetupPacket.bmRequestType.BM.Type) {
case REQUEST_STANDARD:
goto stall_i;
#if (USB_CLASS)
case REQUEST_CLASS:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_INTERFACE:
#if USB_HID
if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) {
if (!HID_SetReport()) {
goto stall_i;
}
break;
}
#endif
#if USB_AUDIO
if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) ||
(SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) ||
(SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) {
if (!ADC_IF_SetRequest()) {
goto stall_i;
}
break;
}
#endif
goto stall_i;
case REQUEST_TO_ENDPOINT:
#if USB_AUDIO
if (ADC_EP_SetRequest()) break;
#endif
goto stall_i;
default:
goto stall_i;
}
break;
#endif
default:
goto stall_i;
}
USB_StatusInStage();
}
}
} else {
USB_StatusOutStage();
}
break;
case USB_EVT_IN:
if (SetupPacket.bmRequestType.BM.Dir == 1) {
USB_DataInStage();
}else {
if (USB_DeviceAddress & 0x80) {
USB_DeviceAddress &= 0x7F;
//USB_SetAddress(USB_DeviceAddress);
}
}
break;
case USB_EVT_IN_STALL:
USB_ClrStallEP(0x80);
break;
case USB_EVT_OUT_STALL:
USB_ClrStallEP(0x00);
break;
}
}

View File

@ -0,0 +1,33 @@
#ifndef __USBCORE_H__
#define __USBCORE_H__
#include "usbhal.h"
#include "usb.h"
#include "usbcfg.h"
/* USB Endpoint Data Structure */
typedef struct _USB_EP_DATA {
BYTE *pData;
WORD Count;
} USB_EP_DATA;
/* USB Core Global Variables */
extern WORD USB_DeviceStatus;
extern BYTE USB_DeviceAddress;
extern BYTE USB_Configuration;
extern DWORD USB_EndPointMask;
extern DWORD USB_EndPointHalt;
extern BYTE USB_AltSetting[USB_IF_NUM];
/* USB Endpoint 0 Buffer */
extern BYTE EP0Buf[64];
/* USB Endpoint 0 Data Info */
extern USB_EP_DATA EP0Data;
/* USB Setup Packet */
extern USB_SETUP_PACKET SetupPacket;
/* USB Core Functions */
extern void USB_ResetCore (void);
#endif /* __USBCORE_H__ */

View File

@ -0,0 +1,172 @@
#include "usb.h"
#include "hid.h"
#include "usbcfg.h"
#include "usbdesc.h"
BYTE HID_ReportDescriptor[] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x02, // USAGE_MAXIMUM (Button 2)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x02, // REPORT_COUNT (2)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x06, // REPORT_SIZE (6)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x06, // INPUT (Data,Var,Rel)
0xc0, // END_COLLECTION
0xc0 // END_COLLECTION
};
WORD HID_ReportDescSize = sizeof(HID_ReportDescriptor);
/* USB Standard Device Descriptor */
BYTE USB_DeviceDescriptor[] = {
USB_DEVICE_DESC_SIZE, /* bLength */
USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(0x0110), /* 1.10 */ /* bcdUSB */
0x00, /* bDeviceClass */
0x00, /* bDeviceSubClass */
0x00, /* bDeviceProtocol */
64, /* bMaxPacketSize0 */
WBVAL(0x6666), /* idVendor */
WBVAL(0x7837), /* idProduct */
WBVAL(0x0100), /* 1.00 */ /* bcdDevice */
0x04, /* iManufacturer */
0x20, /* iProduct */
0x42, /* iSerialNumber */
0x01 /* bNumConfigurations */
};
/* USB Configuration Descriptor */
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
BYTE USB_ConfigDescriptor[] = {
/* Configuration 1 */
USB_CONFIGUARTION_DESC_SIZE, /* bLength */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(( /* wTotalLength */
1*USB_CONFIGUARTION_DESC_SIZE +
1*USB_INTERFACE_DESC_SIZE +
1*HID_DESC_SIZE +
1*USB_ENDPOINT_DESC_SIZE
)),
0x01, /* bNumInterfaces */
0x01, /* bConfigurationValue */
0x00, /* iConfiguration */
USB_CONFIG_BUS_POWERED | /* bmAttributes */
USB_CONFIG_REMOTE_WAKEUP,
USB_CONFIG_POWER_MA(100), /* bMaxPower */
/* Interface 0, Alternate Setting 0, HID Class */
USB_INTERFACE_DESC_SIZE, /* bLength */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
0x00, /* bInterfaceNumber */
0x00, /* bAlternateSetting */
0x01, /* bNumEndpoints */
USB_DEVICE_CLASS_HUMAN_INTERFACE, /* bInterfaceClass */
HID_SUBCLASS_NONE, /* bInterfaceSubClass */
HID_PROTOCOL_NONE, /* bInterfaceProtocol */
0x5C, /* iInterface */
/* HID Class Descriptor */
/* HID_DESC_OFFSET = 0x0012 */
HID_DESC_SIZE, /* bLength */
HID_HID_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(0x0100), /* 1.00 */ /* bcdHID */
0x00, /* bCountryCode */
0x01, /* bNumDescriptors */
HID_REPORT_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(HID_REPORT_DESC_SIZE), /* wDescriptorLength */
/* Endpoint, HID Interrupt In */
USB_ENDPOINT_DESC_SIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_ENDPOINT_IN(1), /* bEndpointAddress */
USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */
WBVAL(0x0004), /* wMaxPacketSize */
10, /* 10ms */ /* bInterval */
/* Terminator */
0 /* bLength */
};
/* USB String Descriptor (optional) */
BYTE USB_StringDescriptor[] = {
/* Index 0x00: LANGID Codes */
0x04, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(0x0409), /* US English */ /* wLANGID */
/* Index 0x04: Manufacturer */
0x1C, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'N',0,
'D',0,
'S',0,
' ',0,
'U',0,
'S',0,
'B',0,
' ',0,
'M',0,
'O',0,
'U',0,
'S',0,
'E',0,
/* Index 0x20: Product */
0x28, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'U',0,
'S',0,
'B',0,
' ',0,
'N',0,
'D',0,
'S',0,
' ',0,
'M',0,
'O',0,
'U',0,
'S',0,
'E',0,
' ',0,
' ',0,
' ',0,
' ',0,
' ',0,
' ',0,
/* Index 0x48: Serial Number */
0x1A, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'U',0,
'S',0,
'B',0,
' ',0,
'G',0,
'A',0,
'O',0,
'J',0,
'I',0,
'A',0,
'N',0,
' ',0,
/* Index 0x62: Interface 0, Alternate Setting 0 */
0x0E, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'M',0,
'O',0,
'U',0,
'S',0,
'E',0,
' ',0,
};

View File

@ -0,0 +1,25 @@
#ifndef _USBDESC_H_
#define _USBDESC_H_
#include "usbhal.h"
#define WBVAL(x) (x & 0xFF),((x >> 8) & 0xFF)
#define USB_DEVICE_DESC_SIZE (sizeof(USB_DEVICE_DESCRIPTOR))
#define USB_CONFIGUARTION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR))
#define USB_INTERFACE_DESC_SIZE (sizeof(USB_INTERFACE_DESCRIPTOR))
#define USB_ENDPOINT_DESC_SIZE (sizeof(USB_ENDPOINT_DESCRIPTOR))
#define HID_DESC_OFFSET 0x0012
#define HID_DESC_SIZE (sizeof(HID_DESCRIPTOR))
#define HID_REPORT_DESC_SIZE (sizeof(HID_ReportDescriptor))
extern BYTE USB_ConfigDescriptor[];
extern BYTE USB_StringDescriptor[];
extern BYTE USB_DeviceDescriptor[];
extern BYTE HID_ReportDescriptor[];
extern WORD HID_ReportDescSize;
#endif //_USBDESC_H_

View File

@ -0,0 +1,61 @@
#include "usbhal.h"
#ifdef ARM9
__inline
void usbwrcmd(u8 val) //D12写命令
{
//*(vu8*)(0x0A000000+val) = 0xFF;
*(vu16*)(0x09FFFFFE) = val;
}
__inline
void usbwrdat(u8 val) //D12写数据
{
//*(vu8*)(0x0A000000+val) = 0xFE;
*(vu16*)(0x09FDFFFE) = val;
}
__inline
u8 usbrddat() //D12读
{
//*(vu8*)(0x0A00FFFF) = 0xFE;
return *(vu16*)(0x09FDFFFE);
}
u16 usbreadid()
{
u16 id=0;
usbwrcmd(0xFD);
id=usbrddat();
id|=(u16)usbrddat()<<8;
return id;
}
#else
void usbwrcmd(u8 val) //D12写命令
{
*(vu8*)(0x08020000) = val;
}
void usbwrdat(u8 val) //D12写数据
{
*(vu8*)(0x08000000) = val;
}
u8 usbrddat() //D12读
{
return *(vu8*)(0x08000000);
}
u16 usbreadid()
{
u16 id=0;
usbwrcmd(0xFD);
id=usbrddat();
id|=(u16)usbrddat()<<8;
return id;
}
#endif

View File

@ -0,0 +1,31 @@
#ifndef _USBHAL_H_
#define _USBHAL_H_
#ifdef ARM9
#include <nds.h>
#else
#include <gba.h>
#endif
#include <stdio.h>
#define BOOL u8
#define WORD u16
#define DWORD u32
#define BYTE u8
#define TRUE 1
#define FALSE 0
void usbwrcmd(u8 val);
void usbwrdat(u8 val);
u8 usbrddat();
u16 usbreadid();
//#define disable() ;
//#define enable() ;
#define D12_ID 0x1012
#define nop() __asm __volatile ("nop\n")
#endif //_USBHAL_H_

View File

@ -0,0 +1,61 @@
#include "usbhw.h"
#include "usbcfg.h"
TUSB_Init USB_Init =0;
TUSB_Connect USB_Connect =0;
TUSB_Reset USB_Reset =0;
TUSB_Suspend USB_Suspend =0;
TUSB_Resume USB_Resume =0;
TUSB_WakeUp USB_WakeUp =0;
TUSB_WakeUpCfg USB_WakeUpCfg =0;
TUSB_SetAddress USB_SetAddress =0;
TUSB_Configure USB_Configure =0;
TUSB_ConfigEP USB_ConfigEP =0;
TUSB_DirCtrlEP USB_DirCtrlEP =0;
TUSB_EnableEP USB_EnableEP =0;
TUSB_DisableEP USB_DisableEP =0;
TUSB_ResetEP USB_ResetEP =0;
TUSB_SetStallEP USB_SetStallEP =0;
TUSB_ClrStallEP USB_ClrStallEP =0;
TUSB_ReadEP USB_ReadEP =0;
TUSB_WriteEP USB_WriteEP =0;
TUSB_GetFrame USB_GetFrame =0;
TUSB_ReadInterruptRegister USB_ReadInterruptRegister =0;
TUSB_ReadLastTransactionStatus USB_ReadLastTransactionStatus =0;
TUSB_ReadEndpointStatus USB_ReadEndpointStatus =0;
TUSB__SelectEndpoint USB__SelectEndpoint =0;
TUSB_AcknowledgeEndpoint USB_AcknowledgeEndpoint =0;
TUSB_AcknowledgeSETUP USB_AcknowledgeSETUP =0;
TUSB_ClrBufEP USB_ClrBufEP =0;
u32 USB_MAX_PACKET0=64;
void D14USBInit()
{
USB_MAX_PACKET0=64;
USB_Init =D14_Init ;
USB_Connect =D14_Connect ;
USB_Reset =D14_Reset ;
USB_Suspend =D14_Suspend ;
USB_Resume =D14_Resume ;
USB_WakeUp =D14_WakeUp ;
USB_WakeUpCfg =D14_WakeUpCfg ;
USB_SetAddress =D14_SetAddress ;
USB_Configure =D14_Configure ;
USB_ConfigEP =D14_ConfigEP ;
USB_DirCtrlEP =D14_DirCtrlEP ;
USB_EnableEP =D14_EnableEP ;
USB_DisableEP =D14_DisableEP ;
USB_ResetEP =D14_ResetEP ;
USB_SetStallEP =D14_SetStallEP ;
USB_ClrStallEP =D14_ClrStallEP ;
USB_ReadEP =D14_ReadEP ;
USB_WriteEP =D14_WriteEP ;
USB_GetFrame =D14_GetFrame ;
USB_AcknowledgeEndpoint =D14_AcknowledgeEndpoint ;
USB_AcknowledgeSETUP =D14_AcknowledgeSETUP ;
USB_ClrBufEP =D14_ClrBufEP ;
}

View File

@ -0,0 +1,64 @@
#ifndef _USBHW_H_
#define _USBHW_H_
#include "usbhal.h"
#include "usbuser.h"
#include "d14hal.h"
typedef void (*TUSB_Init) (void);
typedef void (*TUSB_Connect) (BOOL con);
typedef void (*TUSB_Reset) (void);
typedef void (*TUSB_Suspend) (void);
typedef void (*TUSB_Resume) (void);
typedef void (*TUSB_WakeUp) (void);
typedef void (*TUSB_WakeUpCfg) (BOOL cfg);
typedef void (*TUSB_SetAddress) (BYTE adr);
typedef void (*TUSB_Configure) (BOOL cfg);
typedef void (*TUSB_ConfigEP) (void *pEPD);
typedef void (*TUSB_DirCtrlEP) (DWORD dir);
typedef void (*TUSB_EnableEP) (BYTE EPNum);
typedef void (*TUSB_DisableEP) (BYTE EPNum);
typedef void (*TUSB_ResetEP) (BYTE EPNum);
typedef void (*TUSB_SetStallEP) (BYTE EPNum);
typedef void (*TUSB_ClrStallEP) (BYTE EPNum);
typedef WORD (*TUSB_ReadEP) (BYTE EPNum, BYTE *pData);
typedef WORD (*TUSB_WriteEP) (BYTE EPNum, BYTE *pData, WORD cnt);
typedef WORD (*TUSB_GetFrame) (void);
typedef WORD (*TUSB_ReadInterruptRegister)(void);
typedef BYTE (*TUSB_ReadLastTransactionStatus)(BYTE EPNum);
typedef BYTE (*TUSB_ReadEndpointStatus)(BYTE EPNum);
typedef BYTE (*TUSB__SelectEndpoint)(BYTE EPNum);
typedef void (*TUSB_AcknowledgeEndpoint)(BYTE EPNum);
typedef void (*TUSB_AcknowledgeSETUP)(void);
typedef void (*TUSB_ClrBufEP) (BYTE EPNum);
TUSB_Init USB_Init ;
TUSB_Connect USB_Connect ;
TUSB_Reset USB_Reset ;
TUSB_Suspend USB_Suspend ;
TUSB_Resume USB_Resume ;
TUSB_WakeUp USB_WakeUp ;
TUSB_WakeUpCfg USB_WakeUpCfg ;
TUSB_SetAddress USB_SetAddress ;
TUSB_Configure USB_Configure ;
TUSB_ConfigEP USB_ConfigEP ;
TUSB_DirCtrlEP USB_DirCtrlEP ;
TUSB_EnableEP USB_EnableEP ;
TUSB_DisableEP USB_DisableEP ;
TUSB_ResetEP USB_ResetEP ;
TUSB_SetStallEP USB_SetStallEP ;
TUSB_ClrStallEP USB_ClrStallEP ;
TUSB_ReadEP USB_ReadEP ;
TUSB_WriteEP USB_WriteEP ;
TUSB_GetFrame USB_GetFrame ;
TUSB_ReadInterruptRegister USB_ReadInterruptRegister ;
TUSB_ReadLastTransactionStatus USB_ReadLastTransactionStatus;
TUSB_ReadEndpointStatus USB_ReadEndpointStatus ;
TUSB__SelectEndpoint USB__SelectEndpoint ;
TUSB_AcknowledgeEndpoint USB_AcknowledgeEndpoint ;
TUSB_AcknowledgeSETUP USB_AcknowledgeSETUP ;
TUSB_ClrBufEP USB_ClrBufEP ;
u32 USB_MAX_PACKET0;
void D14USBInit();
#endif //_USBHW_H_

View File

@ -0,0 +1,82 @@
#include "usbhw.h"
#include "usbcore.h"
#include "usbuser.h"
#include "hiduser.h"
#include <stdio.h>
/* USB Endpoint Events Callback Pointers */
void (* const USB_P_EP[USB_EP_NUM/2]) (BYTE event) = {
USB_EndPoint0,
USB_EndPoint1,
USB_EndPoint2,
};
void USB_Configure_Event (void)
{
if (USB_Configuration)
{
GetInReport();
USB_WriteEP(0x81, InReport, 3);
}
}
void USB_EndPoint1 (BYTE event)
{
switch (event)
{
case USB_EVT_IN:
GetInReport();
USB_WriteEP(0x81, InReport, 3);
break;
}
}
void USB_EndPoint2 (BYTE event)
{
}
u16 USB_IF=0;
void USB_ISR()
{
USB_IF|=D14_IF;
D14_IF=USB_IF;
if(USB_IF&D14_IF_BRST)
{
USB_Reset();
USB_IF&=~D14_IF_BRST;
}
if(USB_IF&D14_IF_SUSP)
{
USB_Suspend();
USB_IF&=~D14_IF_SUSP;
}
if(USB_IF&D14_IF_EP0SETUP)
{
USB_P_EP[0](USB_EVT_SETUP);
USB_IF&=~D14_IE_EP0SETUP;
}
if(USB_IF&D14_IF_EP0OUT)
{
USB_P_EP[0](USB_EVT_OUT);
USB_IF&=~D14_IF_EP0OUT;
}
if(USB_IF&D14_IF_EP0IN)
{
USB_P_EP[0](USB_EVT_IN);
USB_IF&=~D14_IF_EP0IN;
}
if(USB_IF&D14_IF_EP1IN)
{
USB_P_EP[1](USB_EVT_IN);
USB_IF&=~D14_IF_EP1IN;
}
}
//end of file

View File

@ -0,0 +1,33 @@
#ifndef _USBUSER_H_
#define _USBUSER_H_
#include "usbhal.h"
#include "usbcfg.h"
/* USB Endpoint Callback Events */
#define USB_EVT_SETUP 1 /* Setup Packet */
#define USB_EVT_OUT 2 /* OUT Packet */
#define USB_EVT_IN 3 /* IN Packet */
#define USB_EVT_OUT_NAK 4 /* OUT Packet - Not Acknowledged */
#define USB_EVT_IN_NAK 5 /* IN Packet - Not Acknowledged */
#define USB_EVT_OUT_STALL 6 /* OUT Packet - Stalled */
#define USB_EVT_IN_STALL 7 /* IN Packet - Stalled */
#define USB_EVT_OUT_DMA_EOT 8 /* DMA OUT EP - End of Transfer */
#define USB_EVT_IN_DMA_EOT 9 /* DMA IN EP - End of Transfer */
#define USB_EVT_OUT_DMA_NDR 10 /* DMA OUT EP - New Descriptor Request */
#define USB_EVT_IN_DMA_NDR 11 /* DMA IN EP - New Descriptor Request */
#define USB_EVT_OUT_DMA_ERR 12 /* DMA OUT EP - Error */
#define USB_EVT_IN_DMA_ERR 13 /* DMA IN EP - Error */
extern void USB_Configure_Event (void);
extern void (* const USB_P_EP[USB_EP_NUM/2]) (BYTE event);
extern void USB_EndPoint0 (BYTE event);
extern void USB_EndPoint1 (BYTE event);
extern void USB_EndPoint2 (BYTE event);
extern void USB_ISR(void);
extern void USB_MAIN(void);
#endif //_USBUSER_H_

BIN
dsmouse/banner.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

51
dspad/Makefile Normal file
View File

@ -0,0 +1,51 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
export TARGET := dspad
export TOPDIR := $(CURDIR)
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO_FILES :=
include $(DEVKITARM)/ds_rules
.PHONY: checkarm7 checkarm9 clean
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all: checkarm7 checkarm9 $(TARGET).nds
#---------------------------------------------------------------------------------
checkarm7:
$(MAKE) -C arm7
#---------------------------------------------------------------------------------
checkarm9:
$(MAKE) -C arm9
#---------------------------------------------------------------------------------
$(TARGET).nds : $(NITRO_FILES) arm7/$(TARGET).elf arm9/$(TARGET).elf
ndstool -c $(TARGET).nds -7 arm7/$(TARGET).elf -9 arm9/$(TARGET).elf \
-b banner.bmp "NDS GAMEPAD" \
$(_ADDFILES)
#---------------------------------------------------------------------------------
arm7/$(TARGET).elf:
$(MAKE) -C arm7
#---------------------------------------------------------------------------------
arm9/$(TARGET).elf:
$(MAKE) -C arm9
#---------------------------------------------------------------------------------
clean:
$(MAKE) -C arm9 clean
$(MAKE) -C arm7 clean
rm -f $(TARGET).nds $(TARGET).arm7 $(TARGET).arm9

126
dspad/arm7/Makefile Normal file
View File

@ -0,0 +1,126 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := source
INCLUDES := include build
DATA :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb-interwork
CFLAGS := -g -Wall -O2\
-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM7
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -Wl,--nmagic -Wl,-Map,$(notdir $*).map
LIBS := -ldswifi7 -lmm7 -lnds7
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export ARM7ELF := $(CURDIR)/$(TARGET).elf
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(ARM7ELF) : $(OFILES)
@echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

184
dspad/arm7/source/main.c Normal file
View File

@ -0,0 +1,184 @@
/*---------------------------------------------------------------------------------
default ARM7 core
Copyright (C) 2005 - 2010
Michael Noland (joat)
Jason Rogers (dovoto)
Dave Murphy (WinterMute)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
---------------------------------------------------------------------------------*/
#include <nds.h>
#include <dswifi7.h>
#include <maxmod7.h>
// I think they used stock arm7? None of this appears to be actually used for anything and doesn't work with modern libnds anyways.
/*
//---------------------------------------------------------------------------------
void startSound(int sampleRate, const void* data, u32 bytes, u8 channel, u8 vol, u8 pan, u8 format) {
//---------------------------------------------------------------------------------
SCHANNEL_TIMER(channel) = SOUND_FREQ(sampleRate);
SCHANNEL_SOURCE(channel) = (u32)data;
SCHANNEL_LENGTH(channel) = bytes >> 2 ;
SCHANNEL_CR(channel) = SCHANNEL_ENABLE | SOUND_ONE_SHOT | SOUND_VOL(vol) | SOUND_PAN(pan) | (format==1?SOUND_8BIT:SOUND_16BIT);
}
//---------------------------------------------------------------------------------
s32 getFreeSoundChannel() {
//---------------------------------------------------------------------------------
int i;
for (i=0; i<16; i++) {
if ( (SCHANNEL_CR(i) & SCHANNEL_ENABLE) == 0 ) return i;
}
return -1;
}
int vcount;
touchPosition first,tempPos;
//---------------------------------------------------------------------------------
void VcountHandler() {
//---------------------------------------------------------------------------------
static int lastbut = -1;
uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0;
but = REG_KEYXY;
if (!( (but ^ lastbut) & (1<<6))) {
tempPos = touchReadXY();
x = tempPos.x;
y = tempPos.y;
xpx = tempPos.px;
ypx = tempPos.py;
z1 = tempPos.z1;
z2 = tempPos.z2;
} else {
lastbut = but;
but |= (1 <<6);
}
if ( vcount == 80 ) {
first = tempPos;
} else {
if ( abs( xpx - first.px) > 10 || abs( ypx - first.py) > 10 ||
(but & ( 1<<6)) ) {
but |= (1 <<6);
lastbut = but;
} else {
IPC->mailBusy = 1;
IPC->touchX = x;
IPC->touchY = y;
IPC->touchXpx = xpx;
IPC->touchYpx = ypx;
IPC->touchZ1 = z1;
IPC->touchZ2 = z2;
IPC->mailBusy = 0;
}
}
IPC->buttons = but;
vcount ^= (80 ^ 130);
SetYtrigger(vcount);
}
*/
//---------------------------------------------------------------------------------
void VblankHandler(void) {
//---------------------------------------------------------------------------------
Wifi_Update();
}
//---------------------------------------------------------------------------------
void VcountHandler() {
//---------------------------------------------------------------------------------
inputGetAndSend();
}
volatile bool exitflag = false;
//---------------------------------------------------------------------------------
void powerButtonCB() {
//---------------------------------------------------------------------------------
exitflag = true;
}
//---------------------------------------------------------------------------------
int main() {
//---------------------------------------------------------------------------------
readUserSettings();
// Reset the clock if needed
// rtcReset();
irqInit();
// Start the RTC tracking IRQ
initClockIRQ();
fifoInit();
touchInit();
//enable sound
/*powerON(POWER_SOUND);
SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F);
IPC->soundData = 0;*/
mmInstall(FIFO_MAXMOD);
SetYtrigger(80);
// vcount = 80;
installWifiFIFO();
installSoundFIFO();
installSystemFIFO();
irqSet(IRQ_VCOUNT, VcountHandler);
irqSet(IRQ_VBLANK, VblankHandler);
irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);
setPowerButtonCB(powerButtonCB);
writePowerManagement(PM_CONTROL_REG,PM_BACKLIGHT_BOTTOM);
// Keep the ARM7 mostly idle
while (!exitflag) {
if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) {
exitflag = true;
}
swiWaitForVBlank();
}
return 0;
}

127
dspad/arm9/Makefile Normal file
View File

@ -0,0 +1,127 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := source
INCLUDES := include
DATA :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g -Wall -O2\
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lnds9
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export ARM9ELF := $(CURDIR)/$(TARGET).elf
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf *.nds* *.bin
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(ARM9ELF) : $(OFILES)
@echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

182
dspad/arm9/source/d14hal.c Normal file
View File

@ -0,0 +1,182 @@
#include "D14HAL.H"
u8 D14_SPEED=D14_FULLSPEED;
void D14_SelectEndpoint(u8 EPNum)
{
D14_EPSEL=EPADDR(EPNum);
}
void D14_Init (void)
{;}
void D14_Connect(u8 f)
{
u32 i;
D14_MODE = D14_MODE_SRESET;
for(i=0;i<0x1000000;i++);
D14_MODE = 0;
for(i=0;i<0x1000000;i++);
D14_INTCNT = D14_INTCNT_DDBGMODOUT1|D14_INTCNT_DDBGMODIN1|D14_INTCNT_CDBGMOD1|D14_INTCNT_INTLVL|D14_INTCNT_INTPOL;
D14_IE = D14_IE_BRST|D14_IE_SUSP|D14_IE_RESM|D14_IE_HSSTAT|D14_IE_EP0SETUP|D14_IE_EP0OUT|D14_IE_EP0IN|D14_IE_EP1IN;
D14_IEH = 0x0000;
D14_ADDR = 0x80;
if(f)
D14_MODE = D14_MODE_SOFTCT|D14_MODE_IME|D14_MODE_CLKON;
D14_SPEED=D14_FULLSPEED;
D14_Configure(1);
}
void D14_Reset (void)
{
D14_MODE = D14_MODE_SRESET;
D14_MODE = 0;
D14_INTCNT = D14_INTCNT_DDBGMODOUT1|D14_INTCNT_DDBGMODIN1|D14_INTCNT_CDBGMOD1|D14_INTCNT_INTLVL|D14_INTCNT_INTPOL;
D14_IE = D14_IE_BRST|D14_IE_SUSP|D14_IE_RESM|D14_IE_HSSTAT|D14_IE_EP0SETUP|D14_IE_EP0OUT|D14_IE_EP0IN|D14_IE_EP1IN;
D14_IEH = 0x0000;
D14_ADDR = 0x80;
D14_MODE = D14_MODE_SOFTCT|D14_MODE_IME|D14_MODE_CLKON;
D14_SPEED=D14_FULLSPEED;
D14_Configure(1);
}
void D14_Suspend (void)
{;}
void D14_Resume (void)
{;}
void D14_WakeUp (void)
{;}
void D14_WakeUpCfg (u8 cfg)
{;}
void D14_SetAddress (u8 addr)
{
D14PORT(0x00)=0x0080|addr;
}
void D14_Configure (u8 cfg)
{
//必须先配置好 功能,再配置内存 最后打开 否则无法收到中断
if(D14_SPEED==D14_FULLSPEED)
{
D14_SelectEndpoint(0x81);
D14_EPTYPE = D14_EPTYPE_INT|D14_EPTYPE_DBLBUF;
D14_EPMAX = 0x4;
D14_SelectEndpoint(0x81);
D14_EPTYPE |= D14_EPTYPE_ENABLE;
}
else
{
D14_SelectEndpoint(0x81);
D14_EPTYPE = D14_EPTYPE_INT|D14_EPTYPE_DBLBUF;
D14_EPMAX = 0x4;
D14_SelectEndpoint(0x81);
D14_EPTYPE |= D14_EPTYPE_ENABLE;
}
}
void D14_ConfigEP (void *pEPD)
{;}
void D14_DirCtrlEP (u32 dir)
{;}
void D14_EnableEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = 0;
D14_EPTYPE &= ~D14_EPTYPE_ENABLE;
D14_EPTYPE |= D14_EPTYPE_ENABLE;
}
void D14_DisableEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = D14_EPCNT_STALL;
D14_EPTYPE &= ~D14_EPTYPE_ENABLE;
}
void D14_ResetEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = 0;
D14_EPTYPE &= ~D14_EPTYPE_ENABLE;
D14_EPTYPE |= D14_EPTYPE_ENABLE;
}
void D14_SetStallEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = D14_EPCNT_STALL;
}
void D14_ClrStallEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = 0;
D14_EPTYPE &= ~D14_EPTYPE_ENABLE;
D14_EPTYPE |= D14_EPTYPE_ENABLE;
}
u16 D14_GetFrame (void)
{
return D14_FRAME;
}
void D14_AcknowledgeEndpoint(u8 EPNum) //应答SETUP
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = D14_EPCNT_STATUS;
}
void D14_AcknowledgeSETUP(void)
{
D14_AcknowledgeEndpoint(0);
}
#pragma pack(1)
u16 D14_ReadEP (u8 EPNum, u8 *pData)
{
register u16 len,i,data;
u8 half;
D14_SelectEndpoint(EPNum);
len=D14_EPLEN;
if(!len)return 0;
half=len%2;
for(i=0;i<len/2;i++)
{
data=D14_EPDAT;
*pData++=(u8)data;
*pData++=(u8)(data>>8);
}
if(half)
{
data=D14_EPDAT;
*pData=(u8)data;
}
return len;
}
void D14_ClrBufEP (u8 EPNum)
{
D14_SelectEndpoint(EPNum);
D14_EPCNT = D14_EPCNT_CLBUF;
}
u16 D14_WriteEP (u8 EPNum, u8 *pData, u16 cnt)
{
register u16 i,data;
u8 half;
D14_SelectEndpoint(EPNum);
D14_EPLEN=cnt;
half=cnt%2;
for(i=0;i<cnt/2;i++)
{
data=*pData++;
data|=(*pData++)<<8;
D14_EPDAT=data;
}
if(half)
{
data=*pData;
D14_EPDAT=data;
}
return cnt;
}
#pragma pack()
//end of file

170
dspad/arm9/source/d14hal.h Normal file
View File

@ -0,0 +1,170 @@
#ifndef _D14HAL_H_
#define _D14HAL_H_
/*
#define u16 unsigned short
#define u8 unsigned char
#define vu16 unsigned short
#define vu8 unsigned char
#define BIT(a) (1<<(a))
*/
#include <nds.h>
#define D14_FULLSPEED 0
#define D14_HIGHSPEED 1
extern u8 D14_SPEED;
#define D14_BASE 0x08000000
#define D14PORT(addr) (*(vu16*)(D14_BASE|((addr)*0x20000)))
#define EPADDR(addr) (((addr&0x80)?((addr)<<1)|1:((addr)<<1))&0xFF)
#define D14_ADDR D14PORT(0x00)
#define D14_MODE D14PORT(0x0C)
#define D14_INTCNT D14PORT(0x10)
#define D14_IE D14PORT(0x14)
#define D14_IEH D14PORT(0x16)
#define D14_EPSEL D14PORT(0x2C)
#define D14_EPCNT D14PORT(0x28)
#define D14_EPDAT D14PORT(0x20)
#define D14_EPLEN D14PORT(0x1C)
#define D14_EPMAX D14PORT(0x04)
#define D14_EPTYPE D14PORT(0x08)
#define D14_EPSHORT D14PORT(0x24)
#define D14_IF D14PORT(0x18)
#define D14_IFH D14PORT(0x1A)
#define D14_ID D14PORT(0x70)
#define D14_FRAME D14PORT(0x74)
#define D14_REG D14PORT(0X78)
#define D14_UNLOCK D14PORT(0X7C)
#define D14_TEST D14PORT(0X84)
/*D14_ADDR*/
#define D14_ADDR_EN BIT(7)
/*D14_MODE*/
#define D14_MODE_CLKON BIT(7)
#define D14_MODE_SNDRSU BIT(6)
#define D14_MODE_GOSUSP BIT(5)
#define D14_MODE_SRESET BIT(4)
#define D14_MODE_IME BIT(3)
#define D14_MODE_WKUPCS BIT(2)
#define D14_MODE_SOFTCT BIT(0)
/*D14_INTCNT*/
#define D14_INTCNT_DDBGMODOUT0 0
#define D14_INTCNT_DDBGMODOUT1 BIT(2)
#define D14_INTCNT_DDBGMODOUT2 BIT(3)|BIT(2)
#define D14_INTCNT_DDBGMODIN0 0
#define D14_INTCNT_DDBGMODIN1 BIT(4)
#define D14_INTCNT_DDBGMODIN2 BIT(5)|BIT(4)
#define D14_INTCNT_CDBGMOD0 0
#define D14_INTCNT_CDBGMOD1 BIT(6)
#define D14_INTCNT_CDBGMOD2 BIT(7)|BIT(6)
#define D14_INTCNT_INTLVL BIT(1)
#define D14_INTCNT_INTPOL BIT(0)
/*D14_IE*/
#define D14_IE_BRST BIT(0)
#define D14_IE_SOF BIT(1)
#define D14_IE_PSOF BIT(2)
#define D14_IE_SUSP BIT(3)
#define D14_IE_RESM BIT(4)
#define D14_IE_HSSTAT BIT(5)
#define D14_IE_DMA BIT(6)
#define D14_IE_EP0SETUP BIT(8)
#define D14_IE_EP0OUT BIT(10)
#define D14_IE_EP0IN BIT(11)
#define D14_IE_EP1OUT BIT(12)
#define D14_IE_EP1IN BIT(13)
#define D14_IE_EP2OUT BIT(14)
#define D14_IE_EP2IN BIT(15)
#define D14_IE_EP3OUT BIT(16)
#define D14_IE_EP3IN BIT(17)
#define D14_IE_EP4OUT BIT(18)
#define D14_IE_EP4IN BIT(19)
#define D14_IE_EP5OUT BIT(20)
#define D14_IE_EP5IN BIT(21)
#define D14_IE_EP6OUT BIT(22)
#define D14_IE_EP6IN BIT(23)
/*D14_IF*/
#define D14_IF_BRST BIT(0)
#define D14_IF_SOF BIT(1)
#define D14_IF_PSOF BIT(2)
#define D14_IF_SUSP BIT(3)
#define D14_IF_RESM BIT(4)
#define D14_IF_HSSTAT BIT(5)
#define D14_IF_DMA BIT(6)
#define D14_IF_EP0SETUP BIT(8)
#define D14_IF_EP0OUT BIT(10)
#define D14_IF_EP0IN BIT(11)
#define D14_IF_EP1OUT BIT(12)
#define D14_IF_EP1IN BIT(13)
#define D14_IF_EP2OUT BIT(14)
#define D14_IF_EP2IN BIT(15)
#define D14_IF_EP3OUT BIT(16)
#define D14_IF_EP3IN BIT(17)
#define D14_IF_EP4OUT BIT(18)
#define D14_IF_EP4IN BIT(19)
#define D14_IF_EP5OUT BIT(20)
#define D14_IF_EP5IN BIT(21)
#define D14_IF_EP6OUT BIT(22)
#define D14_IF_EP6IN BIT(23)
/*D14_EPSEL*/
#define D14_EPSEL_DIR BIT(0)
#define D14_EPSEL_SETUP BIT(5)
/*D14_EPCNT*/
#define D14_EPCNT_CLBUF BIT(4)
#define D14_EPCNT_VENDP BIT(3)
#define D14_EPCNT_STATUS BIT(1)
#define D14_EPCNT_STALL BIT(0)
/*D14_EPTYPE*/
#define D14_EPTYPE_NONE 0
#define D14_EPTYPE_SYNC BIT(0)
#define D14_EPTYPE_BULK BIT(1)
#define D14_EPTYPE_INT (BIT(1)|BIT(0))
#define D14_EPTYPE_DBLBUF BIT(2)
#define D14_EPTYPE_ENABLE BIT(3)
#define D14_EPTYPE_NOEMPKT BIT(4)
/*D14_UNLOCK*/
#define D14_UNLOCK_KEY 0xAA37
/*D14_TEST*/
#define D14_TEST_SE0_NAK BIT(0)
#define D14_TEST_JSTATE BIT(1)
#define D14_TEST_KSTATE BIT(2)
#define D14_TEST_PRBS BIT(3)
#define D14_TEST_FORCEFS BIT(4)
#define D14_TEST_FORCEHS BIT(7)
void D14_SelectEndpoint(u8 EPNum);
void D14_Init (void);
void D14_Connect(u8 f);
void D14_Reset (void);
void D14_Suspend (void);
void D14_Resume (void);
void D14_WakeUp (void);
void D14_WakeUpCfg (u8 cfg);
void D14_SetAddress (u8 addr);
void D14_Configure (u8 cfg);
void D14_ConfigEP (void *pEPD);
void D14_DirCtrlEP (u32 dir);
void D14_EnableEP (u8 EPNum);
void D14_DisableEP (u8 EPNum);
void D14_ResetEP (u8 EPNum);
void D14_SetStallEP (u8 EPNum);
void D14_ClrStallEP (u8 EPNum);
u16 D14_GetFrame (void);
void D14_AcknowledgeEndpoint(u8 EPNum);
void D14_AcknowledgeSETUP(void);
u16 D14_ReadEP (u8 EPNum, u8 *pData);
void D14_ClrBufEP (u8 EPNum);
u16 D14_WriteEP (u8 EPNum, u8 *pData, u16 cnt);
#endif//_D14HAL_H_

View File

@ -0,0 +1,4 @@
#include <stdio.h>
#include "usbhal.h"
#include "debug.h"

15
dspad/arm9/source/debug.h Normal file
View File

@ -0,0 +1,15 @@
#ifdef ARM9
#else
#include<gba.h>
#endif
#define consolecls() iprintf ("%c[222J",0x1B)
#define consolesetxy(x,y) iprintf ("%c[%d;%dH",0x1B,x,y)
#define testb(c,b) (c&b)
#define REG_KEY *(volatile u16*)0x4000130
void delay();
void showmem(u32 base);

353
dspad/arm9/source/hid.h Normal file
View File

@ -0,0 +1,353 @@
/*----------------------------------------------------------------------------
* U S B - K e r n e l
*----------------------------------------------------------------------------
* Name: HID.H
* Purpose: USB HID (Human Interface Device) Definitions
* Version: V1.03
*----------------------------------------------------------------------------
* This file is part of the uVision/ARM development tools.
* Copyright (c) 2005 Keil Software. All rights reserved.
*---------------------------------------------------------------------------*/
#ifndef __HID_H__
#define __HID_H__
/* HID Subclass Codes */
#define HID_SUBCLASS_NONE 0x00
#define HID_SUBCLASS_BOOT 0x01
/* HID Protocol Codes */
#define HID_PROTOCOL_NONE 0x00
#define HID_PROTOCOL_KEYBOARD 0x01
#define HID_PROTOCOL_MOUSE 0x02
/* HID Descriptor Types */
#define HID_HID_DESCRIPTOR_TYPE 0x21
#define HID_REPORT_DESCRIPTOR_TYPE 0x22
#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23
#pragma pack(1)
/* HID Descriptor */
typedef struct _HID_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD bcdHID;
BYTE bCountryCode;
BYTE bNumDescriptors;
/* Array of one or more descriptors */
struct _HID_DESCRIPTOR_LIST {
BYTE bDescriptorType;
WORD wDescriptorLength;
} DescriptorList[1];
} HID_DESCRIPTOR;
#pragma pack()
/* HID Request Codes */
#define HID_REQUEST_GET_REPORT 0x01
#define HID_REQUEST_GET_IDLE 0x02
#define HID_REQUEST_GET_PROTOCOL 0x03
#define HID_REQUEST_SET_REPORT 0x09
#define HID_REQUEST_SET_IDLE 0x0A
#define HID_REQUEST_SET_PROTOCOL 0x0B
/* HID Report Types */
#define HID_REPORT_INPUT 0x01
#define HID_REPORT_OUTPUT 0x02
#define HID_REPORT_FEATURE 0x03
/* Usage Pages */
#define HID_USAGE_PAGE_UNDEFINED 0x00
#define HID_USAGE_PAGE_GENERIC 0x01
#define HID_USAGE_PAGE_SIMULATION 0x02
#define HID_USAGE_PAGE_VR 0x03
#define HID_USAGE_PAGE_SPORT 0x04
#define HID_USAGE_PAGE_GAME 0x05
#define HID_USAGE_PAGE_DEV_CONTROLS 0x06
#define HID_USAGE_PAGE_KEYBOARD 0x07
#define HID_USAGE_PAGE_LED 0x08
#define HID_USAGE_PAGE_BUTTON 0x09
#define HID_USAGE_PAGE_ORDINAL 0x0A
#define HID_USAGE_PAGE_TELEPHONY 0x0B
#define HID_USAGE_PAGE_CONSUMER 0x0C
#define HID_USAGE_PAGE_DIGITIZER 0x0D
#define HID_USAGE_PAGE_UNICODE 0x10
#define HID_USAGE_PAGE_ALPHANUMERIC 0x14
/* ... */
/* Generic Desktop Page (0x01) */
#define HID_USAGE_GENERIC_POINTER 0x01
#define HID_USAGE_GENERIC_MOUSE 0x02
#define HID_USAGE_GENERIC_JOYSTICK 0x04
#define HID_USAGE_GENERIC_GAMEPAD 0x05
#define HID_USAGE_GENERIC_KEYBOARD 0x06
#define HID_USAGE_GENERIC_KEYPAD 0x07
#define HID_USAGE_GENERIC_X 0x30
#define HID_USAGE_GENERIC_Y 0x31
#define HID_USAGE_GENERIC_Z 0x32
#define HID_USAGE_GENERIC_RX 0x33
#define HID_USAGE_GENERIC_RY 0x34
#define HID_USAGE_GENERIC_RZ 0x35
#define HID_USAGE_GENERIC_SLIDER 0x36
#define HID_USAGE_GENERIC_DIAL 0x37
#define HID_USAGE_GENERIC_WHEEL 0x38
#define HID_USAGE_GENERIC_HATSWITCH 0x39
#define HID_USAGE_GENERIC_COUNTED_BUFFER 0x3A
#define HID_USAGE_GENERIC_BYTE_COUNT 0x3B
#define HID_USAGE_GENERIC_MOTION_WAKEUP 0x3C
#define HID_USAGE_GENERIC_VX 0x40
#define HID_USAGE_GENERIC_VY 0x41
#define HID_USAGE_GENERIC_VZ 0x42
#define HID_USAGE_GENERIC_VBRX 0x43
#define HID_USAGE_GENERIC_VBRY 0x44
#define HID_USAGE_GENERIC_VBRZ 0x45
#define HID_USAGE_GENERIC_VNO 0x46
#define HID_USAGE_GENERIC_SYSTEM_CTL 0x80
#define HID_USAGE_GENERIC_SYSCTL_POWER 0x81
#define HID_USAGE_GENERIC_SYSCTL_SLEEP 0x82
#define HID_USAGE_GENERIC_SYSCTL_WAKE 0x83
#define HID_USAGE_GENERIC_SYSCTL_CONTEXT_MENU 0x84
#define HID_USAGE_GENERIC_SYSCTL_MAIN_MENU 0x85
#define HID_USAGE_GENERIC_SYSCTL_APP_MENU 0x86
#define HID_USAGE_GENERIC_SYSCTL_HELP_MENU 0x87
#define HID_USAGE_GENERIC_SYSCTL_MENU_EXIT 0x88
#define HID_USAGE_GENERIC_SYSCTL_MENU_SELECT 0x89
#define HID_USAGE_GENERIC_SYSCTL_MENU_RIGHT 0x8A
#define HID_USAGE_GENERIC_SYSCTL_MENU_LEFT 0x8B
#define HID_USAGE_GENERIC_SYSCTL_MENU_UP 0x8C
#define HID_USAGE_GENERIC_SYSCTL_MENU_DOWN 0x8D
/* ... */
/* Simulation Controls Page (0x02) */
/* ... */
#define HID_USAGE_SIMULATION_RUDDER 0xBA
#define HID_USAGE_SIMULATION_THROTTLE 0xBB
/* ... */
/* Virtual Reality Controls Page (0x03) */
/* ... */
/* Sport Controls Page (0x04) */
/* ... */
/* Game Controls Page (0x05) */
/* ... */
/* Generic Device Controls Page (0x06) */
/* ... */
/* Keyboard/Keypad Page (0x07) */
/* Error "keys" */
#define HID_USAGE_KEYBOARD_NOEVENT 0x00
#define HID_USAGE_KEYBOARD_ROLLOVER 0x01
#define HID_USAGE_KEYBOARD_POSTFAIL 0x02
#define HID_USAGE_KEYBOARD_UNDEFINED 0x03
/* Letters */
#define HID_USAGE_KEYBOARD_aA 0x04
#define HID_USAGE_KEYBOARD_zZ 0x1D
/* Numbers */
#define HID_USAGE_KEYBOARD_ONE 0x1E
#define HID_USAGE_KEYBOARD_ZERO 0x27
#define HID_USAGE_KEYBOARD_RETURN 0x28
#define HID_USAGE_KEYBOARD_ESCAPE 0x29
#define HID_USAGE_KEYBOARD_DELETE 0x2A
/* Funtion keys */
#define HID_USAGE_KEYBOARD_F1 0x3A
#define HID_USAGE_KEYBOARD_F12 0x45
#define HID_USAGE_KEYBOARD_PRINT_SCREEN 0x46
/* Modifier Keys */
#define HID_USAGE_KEYBOARD_LCTRL 0xE0
#define HID_USAGE_KEYBOARD_LSHFT 0xE1
#define HID_USAGE_KEYBOARD_LALT 0xE2
#define HID_USAGE_KEYBOARD_LGUI 0xE3
#define HID_USAGE_KEYBOARD_RCTRL 0xE4
#define HID_USAGE_KEYBOARD_RSHFT 0xE5
#define HID_USAGE_KEYBOARD_RALT 0xE6
#define HID_USAGE_KEYBOARD_RGUI 0xE7
#define HID_USAGE_KEYBOARD_SCROLL_LOCK 0x47
#define HID_USAGE_KEYBOARD_NUM_LOCK 0x53
#define HID_USAGE_KEYBOARD_CAPS_LOCK 0x39
/* ... */
/* LED Page (0x08) */
#define HID_USAGE_LED_NUM_LOCK 0x01
#define HID_USAGE_LED_CAPS_LOCK 0x02
#define HID_USAGE_LED_SCROLL_LOCK 0x03
#define HID_USAGE_LED_COMPOSE 0x04
#define HID_USAGE_LED_KANA 0x05
#define HID_USAGE_LED_POWER 0x06
#define HID_USAGE_LED_SHIFT 0x07
#define HID_USAGE_LED_DO_NOT_DISTURB 0x08
#define HID_USAGE_LED_MUTE 0x09
#define HID_USAGE_LED_TONE_ENABLE 0x0A
#define HID_USAGE_LED_HIGH_CUT_FILTER 0x0B
#define HID_USAGE_LED_LOW_CUT_FILTER 0x0C
#define HID_USAGE_LED_EQUALIZER_ENABLE 0x0D
#define HID_USAGE_LED_SOUND_FIELD_ON 0x0E
#define HID_USAGE_LED_SURROUND_FIELD_ON 0x0F
#define HID_USAGE_LED_REPEAT 0x10
#define HID_USAGE_LED_STEREO 0x11
#define HID_USAGE_LED_SAMPLING_RATE_DETECT 0x12
#define HID_USAGE_LED_SPINNING 0x13
#define HID_USAGE_LED_CAV 0x14
#define HID_USAGE_LED_CLV 0x15
#define HID_USAGE_LED_RECORDING_FORMAT_DET 0x16
#define HID_USAGE_LED_OFF_HOOK 0x17
#define HID_USAGE_LED_RING 0x18
#define HID_USAGE_LED_MESSAGE_WAITING 0x19
#define HID_USAGE_LED_DATA_MODE 0x1A
#define HID_USAGE_LED_BATTERY_OPERATION 0x1B
#define HID_USAGE_LED_BATTERY_OK 0x1C
#define HID_USAGE_LED_BATTERY_LOW 0x1D
#define HID_USAGE_LED_SPEAKER 0x1E
#define HID_USAGE_LED_HEAD_SET 0x1F
#define HID_USAGE_LED_HOLD 0x20
#define HID_USAGE_LED_MICROPHONE 0x21
#define HID_USAGE_LED_COVERAGE 0x22
#define HID_USAGE_LED_NIGHT_MODE 0x23
#define HID_USAGE_LED_SEND_CALLS 0x24
#define HID_USAGE_LED_CALL_PICKUP 0x25
#define HID_USAGE_LED_CONFERENCE 0x26
#define HID_USAGE_LED_STAND_BY 0x27
#define HID_USAGE_LED_CAMERA_ON 0x28
#define HID_USAGE_LED_CAMERA_OFF 0x29
#define HID_USAGE_LED_ON_LINE 0x2A
#define HID_USAGE_LED_OFF_LINE 0x2B
#define HID_USAGE_LED_BUSY 0x2C
#define HID_USAGE_LED_READY 0x2D
#define HID_USAGE_LED_PAPER_OUT 0x2E
#define HID_USAGE_LED_PAPER_JAM 0x2F
#define HID_USAGE_LED_REMOTE 0x30
#define HID_USAGE_LED_FORWARD 0x31
#define HID_USAGE_LED_REVERSE 0x32
#define HID_USAGE_LED_STOP 0x33
#define HID_USAGE_LED_REWIND 0x34
#define HID_USAGE_LED_FAST_FORWARD 0x35
#define HID_USAGE_LED_PLAY 0x36
#define HID_USAGE_LED_PAUSE 0x37
#define HID_USAGE_LED_RECORD 0x38
#define HID_USAGE_LED_ERROR 0x39
#define HID_USAGE_LED_SELECTED_INDICATOR 0x3A
#define HID_USAGE_LED_IN_USE_INDICATOR 0x3B
#define HID_USAGE_LED_MULTI_MODE_INDICATOR 0x3C
#define HID_USAGE_LED_INDICATOR_ON 0x3D
#define HID_USAGE_LED_INDICATOR_FLASH 0x3E
#define HID_USAGE_LED_INDICATOR_SLOW_BLINK 0x3F
#define HID_USAGE_LED_INDICATOR_FAST_BLINK 0x40
#define HID_USAGE_LED_INDICATOR_OFF 0x41
#define HID_USAGE_LED_FLASH_ON_TIME 0x42
#define HID_USAGE_LED_SLOW_BLINK_ON_TIME 0x43
#define HID_USAGE_LED_SLOW_BLINK_OFF_TIME 0x44
#define HID_USAGE_LED_FAST_BLINK_ON_TIME 0x45
#define HID_USAGE_LED_FAST_BLINK_OFF_TIME 0x46
#define HID_USAGE_LED_INDICATOR_COLOR 0x47
#define HID_USAGE_LED_RED 0x48
#define HID_USAGE_LED_GREEN 0x49
#define HID_USAGE_LED_AMBER 0x4A
#define HID_USAGE_LED_GENERIC_INDICATOR 0x4B
/* Button Page (0x09) */
/* There is no need to label these usages. */
/* Ordinal Page (0x0A) */
/* There is no need to label these usages. */
/* Telephony Device Page (0x0B) */
#define HID_USAGE_TELEPHONY_PHONE 0x01
#define HID_USAGE_TELEPHONY_ANSWERING_MACHINE 0x02
#define HID_USAGE_TELEPHONY_MESSAGE_CONTROLS 0x03
#define HID_USAGE_TELEPHONY_HANDSET 0x04
#define HID_USAGE_TELEPHONY_HEADSET 0x05
#define HID_USAGE_TELEPHONY_KEYPAD 0x06
#define HID_USAGE_TELEPHONY_PROGRAMMABLE_BUTTON 0x07
/* ... */
/* Consumer Page (0x0C) */
#define HID_USAGE_CONSUMER_CONTROL 0x01
/* ... */
/* and others ... */
/* HID Report Item Macros */
/* Main Items */
#define HID_Input(x) 0x81,x
#define HID_Output(x) 0x91,x
#define HID_Feature(x) 0xB1,x
#define HID_Collection(x) 0xA1,x
#define HID_EndCollection 0xC0
/* Data (Input, Output, Feature) */
#define HID_Data 0<<0
#define HID_Constant 1<<0
#define HID_Array 0<<1
#define HID_Variable 1<<1
#define HID_Absolute 0<<2
#define HID_Relative 1<<2
#define HID_NoWrap 0<<3
#define HID_Wrap 1<<3
#define HID_Linear 0<<4
#define HID_NonLinear 1<<4
#define HID_PreferredState 0<<5
#define HID_NoPreferred 1<<5
#define HID_NoNullPosition 0<<6
#define HID_NullState 1<<6
#define HID_NonVolatile 0<<7
#define HID_Volatile 1<<7
/* Collection Data */
#define HID_Physical 0x00
#define HID_Application 0x01
#define HID_Logical 0x02
#define HID_Report 0x03
#define HID_NamedArray 0x04
#define HID_UsageSwitch 0x05
#define HID_UsageModifier 0x06
/* Global Items */
#define HID_UsagePage(x) 0x05,x
#define HID_UsagePageVendor(x) 0x06,x,0xFF
#define HID_LogicalMin(x) 0x15,x
#define HID_LogicalMinS(x) 0x16,(x&0xFF),((x>>8)&0xFF)
#define HID_LogicalMinL(x) 0x17,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
#define HID_LogicalMax(x) 0x25,x
#define HID_LogicalMaxS(x) 0x26,(x&0xFF),((x>>8)&0xFF)
#define HID_LogicalMaxL(x) 0x27,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
#define HID_PhysicalMin(x) 0x35,x
#define HID_PhysicalMinS(x) 0x36,(x&0xFF),((x>>8)&0xFF)
#define HID_PhysicalMinL(x) 0x37,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
#define HID_PhysicalMax(x) 0x45,x
#define HID_PhysicalMaxS(x) 0x46,(x&0xFF),((x>>8)&0xFF)
#define HID_PhysicalMaxL(x) 0x47,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
#define HID_UnitExponent(x) 0x55,x
#define HID_Unit(x) 0x65,x
#define HID_UnitS(x) 0x66,(x&0xFF),((x>>8)&0xFF)
#define HID_UnitL(x) 0x67,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
#define HID_ReportSize(x) 0x75,x
#define HID_ReportID(x) 0x85,x
#define HID_ReportCount(x) 0x95,x
#define HID_Push 0xA0
#define HID_Pop 0xB0
/* Local Items */
#define HID_Usage(x) 0x09,x
#define HID_UsageMin(x) 0x19,x
#define HID_UsageMax(x) 0x29,x
#endif /* __HID_H__ */

161
dspad/arm9/source/hiduser.c Normal file
View File

@ -0,0 +1,161 @@
#include <nds.h>
#include "usb.h"
#include "hid.h"
#include "usbcfg.h"
#include "usbcore.h"
#include "hiduser.h"
BYTE InReport[3];
BYTE OutReport;
BYTE HID_Protocol;
BYTE HID_IdleTime[HID_REPORT_NUM];
void GetInReport()
{
u32 keys;
scanKeys();
keys = keysHeld();
InReport[0]=128;
InReport[1]=128;
InReport[2]=0;
if( keys & KEY_LEFT )InReport[0]=0;
if( keys & KEY_RIGHT )InReport[0]=255;
if( keys & KEY_UP )InReport[1]=0;
if( keys & KEY_DOWN )InReport[1]=255;
if( keys & KEY_A )InReport[2]|=1<<0;
if( keys & KEY_B )InReport[2]|=1<<1;
if( keys & KEY_X )InReport[2]|=1<<2;
if( keys & KEY_Y )InReport[2]|=1<<3;
if( keys & KEY_START )InReport[2]|=1<<4;
if( keys & KEY_SELECT )InReport[2]|=1<<5;
if( keys & KEY_L )InReport[2]|=1<<6;
if( keys & KEY_R )InReport[2]|=1<<7;
}
void SetOutReport()
{
;
}
/*
* HID Get Report Request Callback
* Called automatically on HID Get Report Request
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_GetReport (void) {
/* ReportID = SetupPacket.wValue.WB.L; */
switch (SetupPacket.wValue.WB.H) {
case HID_REPORT_INPUT:
GetInReport();
EP0Buf[0] = InReport[0];
EP0Buf[1] = InReport[1];
EP0Buf[2] = InReport[2];
break;
case HID_REPORT_OUTPUT:
return (FALSE); /* Not Supported */
case HID_REPORT_FEATURE:
/* EP0Buf[] = ...; */
/* break; */
return (FALSE); /* Not Supported */
}
return (TRUE);
}
/*
* HID Set Report Request Callback
* Called automatically on HID Set Report Request
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_SetReport (void) {
/* ReportID = SetupPacket.wValue.WB.L; */
switch (SetupPacket.wValue.WB.H) {
case HID_REPORT_INPUT:
return (FALSE); /* Not Supported */
case HID_REPORT_OUTPUT:
OutReport = EP0Buf[0];
SetOutReport();
break;
case HID_REPORT_FEATURE:
return (FALSE); /* Not Supported */
}
return (TRUE);
}
/*
* HID Get Idle Request Callback
* Called automatically on HID Get Idle Request
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_GetIdle (void) {
EP0Buf[0] = HID_IdleTime[SetupPacket.wValue.WB.L];
return (TRUE);
}
/*
* HID Set Idle Request Callback
* Called automatically on HID Set Idle Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_SetIdle (void) {
HID_IdleTime[SetupPacket.wValue.WB.L] = SetupPacket.wValue.WB.H;
/* Idle Handling if needed */
/* ... */
return (TRUE);
}
/*
* HID Get Protocol Request Callback
* Called automatically on HID Get Protocol Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_GetProtocol (void) {
EP0Buf[0] = HID_Protocol;
return (TRUE);
}
/*
* HID Set Protocol Request Callback
* Called automatically on HID Set Protocol Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
BOOL HID_SetProtocol (void) {
HID_Protocol = SetupPacket.wValue.WB.L;
/* Protocol Handling if needed */
/* ... */
return (TRUE);
}
//end of file

View File

@ -0,0 +1,26 @@
#ifndef __HIDUSER_H__
#define __HIDUSER_H__
/* HID Number of Reports */
#define HID_REPORT_NUM 1
/* HID Global Variables */
extern BYTE HID_Protocol;
extern BYTE HID_IdleTime[HID_REPORT_NUM];
/* HID Requests Callback Functions */
extern BOOL HID_GetReport (void);
extern BOOL HID_SetReport (void);
extern BOOL HID_GetIdle (void);
extern BOOL HID_SetIdle (void);
extern BOOL HID_GetProtocol (void);
extern BOOL HID_SetProtocol (void);
extern BYTE InReport[3];
extern BYTE OutReport;
void GetInReport();
void SetOutReport();
#endif /* __HIDUSER_H__ */

61
dspad/arm9/source/main.c Normal file
View File

@ -0,0 +1,61 @@
/*---------------------------------------------------------------------------------
---------------------------------------------------------------------------------*/
#include "nds.h"
#include <nds/arm9/console.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "usbhal.h"
#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"
#include "usbcore.h"
#include "debug.h"
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
sysSetBusOwners(1,1);
videoSetMode(0); //not using the main screen
// Enable console
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
REG_BG0CNT_SUB = BG_MAP_BASE(4) | BG_COLOR_16 | BG_TILE_BASE(6) | BG_PRIORITY(0);
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 6, false, true);
printf("NDS GAMEPAD V1.3\n");
u16 tmp=*(vu16*)0x04000204;
tmp&=~0x1F;
tmp|=0x1A;
*(vu16*)0x04000204=tmp;
D14_ID;
D14_ID;
D14_ID;
D14_ID;
if(D14_ID!=0x8151) {
printf("USBCard init failed!\n");
while(1);
}
printf("USBCard init ok!\n");
D14USBInit();
USB_Connect(1);
while(1) { USB_ISR(); }
return 0;
}

86
dspad/arm9/source/msc.h Normal file
View File

@ -0,0 +1,86 @@
#ifndef __MSC_H__
#define __MSC_H__
#include "usbhal.h"
/* MSC Subclass Codes */
#define MSC_SUBCLASS_RBC 0x01
#define MSC_SUBCLASS_SFF8020I_MMC2 0x02
#define MSC_SUBCLASS_QIC157 0x03
#define MSC_SUBCLASS_UFI 0x04
#define MSC_SUBCLASS_SFF8070I 0x05
#define MSC_SUBCLASS_SCSI 0x06
/* MSC Protocol Codes */
#define MSC_PROTOCOL_CBI_INT 0x00
#define MSC_PROTOCOL_CBI_NOINT 0x01
#define MSC_PROTOCOL_BULK_ONLY 0x50
/* MSC Request Codes */
#define MSC_REQUEST_RESET 0xFF
#define MSC_REQUEST_GET_MAX_LUN 0xFE
/* MSC Bulk-only Stage */
#define MSC_BS_CBW 0 /* Command Block Wrapper */
#define MSC_BS_DATA_OUT 1 /* Data Out Phase */
#define MSC_BS_DATA_IN 2 /* Data In Phase */
#define MSC_BS_DATA_IN_LAST 3 /* Data In Last Phase */
#define MSC_BS_DATA_IN_LAST_STALL 4 /* Data In Last Phase with Stall */
#define MSC_BS_CSW 5 /* Command Status Wrapper */
#define MSC_BS_ERROR 6 /* Error */
#pragma pack(1)
/* Bulk-only Command Block Wrapper */
typedef struct _MSC_CBW {
DWORD dSignature;
DWORD dTag;
DWORD dDataLength;
BYTE bmFlags;
BYTE bLUN;
BYTE bCBLength;
BYTE CB[16];
} MSC_CBW;
/* Bulk-only Command Status Wrapper */
typedef struct _MSC_CSW {
DWORD dSignature;
DWORD dTag;
DWORD dDataResidue;
BYTE bStatus;
} MSC_CSW;
#pragma pack()
#define MSC_CBW_Signature 0x43425355
#define MSC_CSW_Signature 0x53425355
/* CSW Status Definitions */
#define CSW_CMD_PASSED 0x00
#define CSW_CMD_FAILED 0x01
#define CSW_PHASE_ERROR 0x02
/* SCSI Commands */
#define SCSI_TEST_UNIT_READY 0x00
#define SCSI_REQUEST_SENSE 0x03
#define SCSI_FORMAT_UNIT 0x04
#define SCSI_INQUIRY 0x12
#define SCSI_MODE_SELECT6 0x15
#define SCSI_MODE_SENSE6 0x1A
#define SCSI_START_STOP_UNIT 0x1B
#define SCSI_MEDIA_REMOVAL 0x1E
#define SCSI_READ_FORMAT_CAPACITIES 0x23
#define SCSI_READ_CAPACITY 0x25
#define SCSI_READ10 0x28
#define SCSI_WRITE10 0x2A
#define SCSI_VERIFY10 0x2F
#define SCSI_MODE_SELECT10 0x55
#define SCSI_MODE_SENSE10 0x5A
#endif /* __MSC_H__ */

224
dspad/arm9/source/usb.h Normal file
View File

@ -0,0 +1,224 @@
/*----------------------------------------------------------------------------
* U S B - K e r n e l
*----------------------------------------------------------------------------
* Name: USB.H
* Purpose: USB Definitions
* Version: V1.03
*----------------------------------------------------------------------------
* This file is part of the uVision/ARM development tools.
* Copyright (c) 2005 Keil Software. All rights reserved.
*---------------------------------------------------------------------------*/
#ifndef __USB_H__
#define __USB_H__
#include "usbhal.h"
#pragma pack(1)
typedef union {
WORD W;
struct {
BYTE L;
BYTE H;
} WB;
} WORD_BYTE;
/* bmRequestType.Dir */
#define REQUEST_HOST_TO_DEVICE 0
#define REQUEST_DEVICE_TO_HOST 1
/* bmRequestType.Type */
#define REQUEST_STANDARD 0
#define REQUEST_CLASS 1
#define REQUEST_VENDOR 2
#define REQUEST_RESERVED 3
/* bmRequestType.Recipient */
#define REQUEST_TO_DEVICE 0
#define REQUEST_TO_INTERFACE 1
#define REQUEST_TO_ENDPOINT 2
#define REQUEST_TO_OTHER 3
/* bmRequestType Definition */
typedef union _REQUEST_TYPE {
struct _BM {
BYTE Recipient : 5;
BYTE Type : 2;
BYTE Dir : 1;
} BM;
BYTE B;
} REQUEST_TYPE;
/* USB Standard Request Codes */
#define USB_REQUEST_GET_STATUS 0
#define USB_REQUEST_CLEAR_FEATURE 1
#define USB_REQUEST_SET_FEATURE 3
#define USB_REQUEST_SET_ADDRESS 5
#define USB_REQUEST_GET_DESCRIPTOR 6
#define USB_REQUEST_SET_DESCRIPTOR 7
#define USB_REQUEST_GET_CONFIGURATION 8
#define USB_REQUEST_SET_CONFIGURATION 9
#define USB_REQUEST_GET_INTERFACE 10
#define USB_REQUEST_SET_INTERFACE 11
#define USB_REQUEST_SYNC_FRAME 12
/* USB GET_STATUS Bit Values */
#define USB_GETSTATUS_SELF_POWERED 0x01
#define USB_GETSTATUS_REMOTE_WAKEUP 0x02
#define USB_GETSTATUS_ENDPOINT_STALL 0x01
/* USB Standard Feature selectors */
#define USB_FEATURE_ENDPOINT_STALL 0
#define USB_FEATURE_REMOTE_WAKEUP 1
/* USB Default Control Pipe Setup Packet */
typedef struct _USB_SETUP_PACKET {
REQUEST_TYPE bmRequestType;
BYTE bRequest;
WORD_BYTE wValue;
WORD_BYTE wIndex;
WORD wLength;
} USB_SETUP_PACKET;
/* USB Descriptor Types */
#define USB_DEVICE_DESCRIPTOR_TYPE 1
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
#define USB_STRING_DESCRIPTOR_TYPE 3
#define USB_INTERFACE_DESCRIPTOR_TYPE 4
#define USB_ENDPOINT_DESCRIPTOR_TYPE 5
#define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6
#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8
/* USB Device Classes */
#define USB_DEVICE_CLASS_RESERVED 0x00
#define USB_DEVICE_CLASS_AUDIO 0x01
#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
#define USB_DEVICE_CLASS_MONITOR 0x04
#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
#define USB_DEVICE_CLASS_POWER 0x06
#define USB_DEVICE_CLASS_PRINTER 0x07
#define USB_DEVICE_CLASS_STORAGE 0x08
#define USB_DEVICE_CLASS_HUB 0x09
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
/* bmAttributes in Configuration Descriptor */
#define USB_CONFIG_POWERED_MASK 0xC0
#define USB_CONFIG_BUS_POWERED 0x80
#define USB_CONFIG_SELF_POWERED 0x40
#define USB_CONFIG_REMOTE_WAKEUP 0x20
/* bMaxPower in Configuration Descriptor */
#define USB_CONFIG_POWER_MA(mA) ((mA)/2)
/* bEndpointAddress in Endpoint Descriptor */
#define USB_ENDPOINT_DIRECTION_MASK 0x80
#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
#define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
/* bmAttributes in Endpoint Descriptor */
#define USB_ENDPOINT_TYPE_MASK 0x03
#define USB_ENDPOINT_TYPE_CONTROL 0x00
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
#define USB_ENDPOINT_TYPE_BULK 0x02
#define USB_ENDPOINT_TYPE_INTERRUPT 0x03
#define USB_ENDPOINT_SYNC_MASK 0x0C
#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00
#define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04
#define USB_ENDPOINT_SYNC_ADAPTIVE 0x08
#define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C
#define USB_ENDPOINT_USAGE_MASK 0x30
#define USB_ENDPOINT_USAGE_DATA 0x00
#define USB_ENDPOINT_USAGE_FEEDBACK 0x10
#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20
#define USB_ENDPOINT_USAGE_RESERVED 0x30
/* USB Standard Device Descriptor */
typedef struct _USB_DEVICE_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD bcdUSB;
BYTE bDeviceClass;
BYTE bDeviceSubClass;
BYTE bDeviceProtocol;
BYTE bMaxPacketSize0;
WORD idVendor;
WORD idProduct;
WORD bcdDevice;
BYTE iManufacturer;
BYTE iProduct;
BYTE iSerialNumber;
BYTE bNumConfigurations;
} USB_DEVICE_DESCRIPTOR;
/* USB 2.0 Device Qualifier Descriptor */
typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD bcdUSB;
BYTE bDeviceClass;
BYTE bDeviceSubClass;
BYTE bDeviceProtocol;
BYTE bMaxPacketSize0;
BYTE bNumConfigurations;
BYTE bReserved;
} USB_DEVICE_QUALIFIER_DESCRIPTOR;
/* USB Standard Configuration Descriptor */
typedef struct _USB_CONFIGURATION_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD wTotalLength;
BYTE bNumInterfaces;
BYTE bConfigurationValue;
BYTE iConfiguration;
BYTE bmAttributes;
BYTE MaxPower;
} USB_CONFIGURATION_DESCRIPTOR;
/* USB Standard Interface Descriptor */
typedef struct _USB_INTERFACE_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
BYTE bInterfaceNumber;
BYTE bAlternateSetting;
BYTE bNumEndpoints;
BYTE bInterfaceClass;
BYTE bInterfaceSubClass;
BYTE bInterfaceProtocol;
BYTE iInterface;
} USB_INTERFACE_DESCRIPTOR;
/* USB Standard Endpoint Descriptor */
typedef struct _USB_ENDPOINT_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
BYTE bEndpointAddress;
BYTE bmAttributes;
WORD wMaxPacketSize;
BYTE bInterval;
} USB_ENDPOINT_DESCRIPTOR;
/* USB String Descriptor */
typedef struct _USB_STRING_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD bString/*[]*/;
} USB_STRING_DESCRIPTOR;
/* USB Common Descriptor */
typedef struct _USB_COMMON_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
} USB_COMMON_DESCRIPTOR;
#pragma pack()
#endif /* __USB_H__ */

136
dspad/arm9/source/usbcfg.h Normal file
View File

@ -0,0 +1,136 @@
#ifndef __USBCFG_H__
#define __USBCFG_H__
/*
// <h> USB Configuration
// <o0> USB Power
// <i> Default Power Setting
// <0=> Bus-powered
// <1=> Self-powered
// <o1> Max Number of Interfaces <1-256>
// <o2> Max Number of Endpoints <1-32>
// <o3> Max Endpoint 0 Packet Size
// <8=> 8 Bytes <16=> 16 Bytes <32=> 32 Bytes <64=> 64 Bytes
// <e4> DMA Transfer
// <i> Use DMA for selected Endpoints
// <o5.0> Endpoint 0 Out
// <o5.1> Endpoint 0 In
// <o5.2> Endpoint 1 Out
// <o5.3> Endpoint 1 In
// <o5.4> Endpoint 2 Out
// <o5.5> Endpoint 2 In
// <o5.6> Endpoint 3 Out
// <o5.7> Endpoint 3 In
// <o5.8> Endpoint 4 Out
// <o5.9> Endpoint 4 In
// <o5.10> Endpoint 5 Out
// <o5.11> Endpoint 5 In
// <o5.12> Endpoint 6 Out
// <o5.13> Endpoint 6 In
// <o5.14> Endpoint 7 Out
// <o5.15> Endpoint 7 In
// <o5.16> Endpoint 8 Out
// <o5.17> Endpoint 8 In
// <o5.18> Endpoint 9 Out
// <o5.19> Endpoint 9 In
// <o5.20> Endpoint 10 Out
// <o5.21> Endpoint 10 In
// <o5.22> Endpoint 11 Out
// <o5.23> Endpoint 11 In
// <o5.24> Endpoint 12 Out
// <o5.25> Endpoint 12 In
// <o5.26> Endpoint 13 Out
// <o5.27> Endpoint 13 In
// <o5.28> Endpoint 14 Out
// <o5.29> Endpoint 14 In
// <o5.30> Endpoint 15 Out
// <o5.31> Endpoint 15 In
// </e>
// </h>
*/
#define USB_POWER 0
#define USB_IF_NUM 4
#define USB_EP_NUM 6
#define USB_DMA 0
#define USB_DMA_EP 0x00000000
/*
// <h> USB Event Handlers
// <h> Device Events
// <o0.0> Power Event
// <o1.0> Reset Event
// <o2.0> Suspend Event
// <o3.0> Resume Event
// <o4.0> Remote Wakeup Event
// <o5.0> Start of Frame Event
// <o6.0> Error Event
// </h>
// <h> Endpoint Events
// <o7.0> Endpoint 0 Event
// <o7.1> Endpoint 1 Event
// <o7.2> Endpoint 2 Event
// <o7.3> Endpoint 3 Event
// <o7.4> Endpoint 4 Event
// <o7.5> Endpoint 5 Event
// <o7.6> Endpoint 6 Event
// <o7.7> Endpoint 7 Event
// <o7.8> Endpoint 8 Event
// <o7.9> Endpoint 9 Event
// <o7.10> Endpoint 10 Event
// <o7.11> Endpoint 11 Event
// <o7.12> Endpoint 12 Event
// <o7.13> Endpoint 13 Event
// <o7.14> Endpoint 14 Event
// <o7.15> Endpoint 15 Event
// </h>
// <h> USB Core Events
// <o8.0> Set Configuration Event
// <o9.0> Set Interface Event
// <o10.0> Set/Clear Feature Event
// </h>
// </h>
*/
#define USB_POWER_EVENT 0
#define USB_RESET_EVENT 1
#define USB_SUSPEND_EVENT 1
#define USB_RESUME_EVENT 1
#define USB_WAKEUP_EVENT 0
#define USB_SOF_EVENT 0
#define USB_ERROR_EVENT 0
#define USB_EP_EVENT 0x0005
#define USB_CONFIGURE_EVENT 1
#define USB_INTERFACE_EVENT 0
#define USB_FEATURE_EVENT 0
/*
// <e0> USB Class Support
// <e1> Human Interface Device (HID)
// <o2> Interface Number <0-255>
// </e>
// <e3> Mass Storage
// <o4> Interface Number <0-255>
// </e>
// <e5> Audio Device
// <o6> Control Interface Number <0-255>
// <o7> Streaming Interface 1 Number <0-255>
// <o8> Streaming Interface 2 Number <0-255>
// </e>
// </e>
*/
#define USB_CLASS 1
#define USB_HID 1
#define USB_HID_IF_NUM 0
#define USB_MSC 0
#define USB_MSC_IF_NUM 0
#define USB_AUDIO 0
#define USB_ADC_CIF_NUM 0
#define USB_ADC_SIF1_NUM 1
#define USB_ADC_SIF2_NUM 2
#endif /* __USBCFG_H__ */

775
dspad/arm9/source/usbcore.c Normal file
View File

@ -0,0 +1,775 @@
#include "usbhal.h"
#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"
#include "usbcore.h"
#include "usbdesc.h"
#include "usbuser.h"
#if USB_AUDIO
#include "audio.h"
#include "adcuser.h"
#endif
#if USB_HID
#include "hid.h"
#include "hiduser.h"
#endif
#if USB_MSC
#include "msc.h"
#include "mscuser.h"
#endif
WORD USB_DeviceStatus;
BYTE USB_DeviceAddress;
BYTE USB_Configuration;
DWORD USB_EndPointMask;
DWORD USB_EndPointHalt;
BYTE USB_NumInterfaces;
BYTE USB_AltSetting[USB_IF_NUM];
BYTE EP0Buf[64];
USB_EP_DATA EP0Data;
USB_SETUP_PACKET SetupPacket;
void*PointAdd(void*inp,DWORD len)
{
BYTE*ptr=(BYTE*)inp;
ptr+=len;
return ptr;
}
/*
* Reset USB Core
* Parameters: None
* Return Value: None
*/
void USB_ResetCore (void) {
USB_DeviceStatus = USB_POWER;
USB_DeviceAddress = 0;
USB_Configuration = 0;
USB_EndPointMask = 0x00010001;
USB_EndPointHalt = 0x00000000;
}
/*
* USB Request - Setup Stage
* Parameters: None (global SetupPacket)
* Return Value: None
*/
void USB_SetupStage (void) {
USB_ReadEP(0x10, (BYTE*)&SetupPacket);
if((SetupPacket.bmRequestType.BM.Dir)||(SetupPacket.wLength==0))
{
// For Get command via Control In
// For Set command without Data Stage via Control Out
// First of all, AckSetup to make it available for BUFFER fill in fifo
}
}
/*
* USB Request - Data In Stage
* Parameters: None (global EP0Data)
* Return Value: None
*/
void USB_DataInStage (void) {
DWORD cnt;
if(EP0Data.Count)
{
if (EP0Data.Count > USB_MAX_PACKET0) {
cnt = USB_MAX_PACKET0;
} else {
cnt = EP0Data.Count;
}
cnt = USB_WriteEP(0x80, EP0Data.pData, cnt);
EP0Data.pData += cnt;
EP0Data.Count -= cnt;
}
else
{
USB_AcknowledgeEndpoint(0x00);
USB_SetStallEP(0x80);
}
}
/*
* USB Request - Data Out Stage
* Parameters: None (global EP0Data)
* Return Value: None
*/
void USB_DataOutStage (void) {
DWORD cnt;
cnt = USB_ReadEP(0x00, EP0Data.pData);
EP0Data.pData += cnt;
EP0Data.Count -= cnt;
}
/*
* USB Request - Status In Stage
* Parameters: None
* Return Value: None
*/
void USB_StatusInStage (void)
{
USB_AcknowledgeEndpoint(0x80);
}
/*
* USB Request - Status Out Stage
* Parameters: None
* Return Value: None
*/
void USB_StatusOutStage (void) {
USB_ReadEP(0x00, EP0Buf);
}
/*
* Get Status USB Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
__inline BOOL USB_GetStatus (void) {
DWORD n, m;
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
EP0Data.pData = (BYTE *)&USB_DeviceStatus;
USB_DataInStage();
break;
case REQUEST_TO_INTERFACE:
if ((USB_Configuration != 0) && (SetupPacket.wIndex.WB.L < USB_NumInterfaces)) {
*((WORD *)EP0Buf) = 0;
EP0Data.pData = EP0Buf;
USB_DataInStage();
} else {
return (FALSE);
}
break;
case REQUEST_TO_ENDPOINT:
n = SetupPacket.wIndex.WB.L & 0x8F;
m = (n & 0x80) ? ((1 << 16) << n) : (1 << n);
if (((USB_Configuration != 0) || ((n & 0x0F) == 0)) && (USB_EndPointMask & m)) {
*((WORD *)EP0Buf) = (USB_EndPointHalt & m) ? 1 : 0;
EP0Data.pData = EP0Buf;
USB_DataInStage();
} else {
return (FALSE);
}
break;
default:
return (FALSE);
}
return (TRUE);
}
/*
* Set/Clear Feature USB Request
* Parameters: sc: 0 - Clear, 1 - Set
* None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
__inline BOOL USB_SetClrFeature (DWORD sc) {
DWORD n, m;
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
if (SetupPacket.wValue.W == USB_FEATURE_REMOTE_WAKEUP) {
if (sc) {
USB_WakeUpCfg(TRUE);
USB_DeviceStatus |= USB_GETSTATUS_REMOTE_WAKEUP;
} else {
USB_WakeUpCfg(FALSE);
USB_DeviceStatus &= ~USB_GETSTATUS_REMOTE_WAKEUP;
}
} else {
return (FALSE);
}
break;
case REQUEST_TO_INTERFACE:
return (FALSE);
case REQUEST_TO_ENDPOINT:
n = SetupPacket.wIndex.WB.L & 0x8F;
m = (n & 0x80) ? ((1 << 16) << n) : (1 << n);
if ((USB_Configuration != 0) && ((n & 0x0F) != 0) && (USB_EndPointMask & m)) {
if (SetupPacket.wValue.W == USB_FEATURE_ENDPOINT_STALL) {
if (sc) {
USB_SetStallEP(n);
USB_EndPointHalt |= m;
} else {
USB_ClrStallEP(n);
USB_EndPointHalt &= ~m;
}
} else {
return (FALSE);
}
} else {
return (FALSE);
}
break;
default:
return (FALSE);
}
return (TRUE);
}
/*
* Get Descriptor USB Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
__inline BOOL USB_GetDescriptor (void) {
BYTE *pD;
DWORD len, n;
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
switch (SetupPacket.wValue.WB.H) {
case USB_DEVICE_DESCRIPTOR_TYPE:
EP0Data.pData = (BYTE *)USB_DeviceDescriptor;
len = USB_DEVICE_DESC_SIZE;
break;
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
pD = (BYTE *)USB_ConfigDescriptor;
for (n = 0; n != SetupPacket.wValue.WB.L; n++) {
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength != 0) {
pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
}
}
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength == 0) {
return (FALSE);
}
EP0Data.pData = pD;
len = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
break;
case USB_STRING_DESCRIPTOR_TYPE:
EP0Data.pData = (BYTE *)USB_StringDescriptor + SetupPacket.wValue.WB.L;
len = ((USB_STRING_DESCRIPTOR *)EP0Data.pData)->bLength;
break;
default:
return (FALSE);
}
break;
case REQUEST_TO_INTERFACE:
switch (SetupPacket.wValue.WB.H) {
#if USB_HID
case HID_HID_DESCRIPTOR_TYPE:
if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) {
return (FALSE); /* Only Single HID Interface is supported */
}
EP0Data.pData = (BYTE *)USB_ConfigDescriptor + HID_DESC_OFFSET;
len = HID_DESC_SIZE;
break;
case HID_REPORT_DESCRIPTOR_TYPE:
if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) {
return (FALSE); /* Only Single HID Interface is supported */
}
EP0Data.pData = (BYTE *)HID_ReportDescriptor;
len = HID_ReportDescSize;
break;
case HID_PHYSICAL_DESCRIPTOR_TYPE:
return (FALSE); /* HID Physical Descriptor is not supported */
#endif
default:
return (FALSE);
}
break;
default:
return (FALSE);
}
if (EP0Data.Count > len) {
EP0Data.Count = len;
}
USB_DataInStage();
return (TRUE);
}
/*
* Set Configuration USB Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
bool USB_SetConfiguration (void) {
USB_COMMON_DESCRIPTOR *pD;
DWORD alt=0, n=0, m=0;
if (SetupPacket.wValue.WB.L) {
pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor;
while (pD->bLength) {
switch (pD->bDescriptorType) {
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue == SetupPacket.wValue.WB.L) {
USB_Configuration = SetupPacket.wValue.WB.L;
USB_NumInterfaces = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->bNumInterfaces;
for (n = 0; n < USB_IF_NUM; n++) {
USB_AltSetting[n] = 0;
}
for (n = 1; n < 16; n++) {
if (USB_EndPointMask & (1 << n)) {
USB_DisableEP(n);
}
if (USB_EndPointMask & ((1 << 16) << n)) {
USB_DisableEP(n | 0x80);
}
}
USB_EndPointMask = 0x00010001;
USB_EndPointHalt = 0x00000000;
USB_Configure(TRUE);
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bmAttributes & USB_CONFIG_SELF_POWERED) {
USB_DeviceStatus |= USB_GETSTATUS_SELF_POWERED;
} else {
USB_DeviceStatus &= ~USB_GETSTATUS_SELF_POWERED;
}
} else {
pD=PointAdd(pD,((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength);//(BYTE *)pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
continue;
}
break;
case USB_INTERFACE_DESCRIPTOR_TYPE:
alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting;
break;
case USB_ENDPOINT_DESCRIPTOR_TYPE:
if (alt == 0) {
n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F;
m = (n & 0x80) ? ((1 << 16) << n) : (1 << n);
USB_EndPointMask |= m;
USB_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD);
USB_EnableEP(n);
USB_ResetEP(n);
}
break;
}
pD =PointAdd(pD,pD->bLength);
}
}
else {
USB_Configuration = 0;
for (n = 1; n < 16; n++) {
if (USB_EndPointMask & (1 << n)) {
USB_DisableEP(n);
}
if (USB_EndPointMask & ((1 << 16) << n)) {
USB_DisableEP(n | 0x80);
}
}
USB_EndPointMask = 0x00010001;
USB_EndPointHalt = 0x00000000;
USB_Configure(FALSE);
}
if (USB_Configuration == SetupPacket.wValue.WB.L) {
return (TRUE);
} else {
return (FALSE);
}
}
/*
* Set Interface USB Request
* Parameters: None (global SetupPacket)
* Return Value: TRUE - Success, FALSE - Error
*/
__inline BOOL USB_SetInterface (void) {
USB_COMMON_DESCRIPTOR *pD;
DWORD ifn=0, alt=0, old=0, msk=0, n=0, m=0;
BOOL set;
if (USB_Configuration == 0) return (FALSE);
set = FALSE;
pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor;
while (pD->bLength) {
switch (pD->bDescriptorType) {
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue != USB_Configuration) {
pD=PointAdd(pD,((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength);//(BYTE *)pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
continue;
}
break;
case USB_INTERFACE_DESCRIPTOR_TYPE:
ifn = ((USB_INTERFACE_DESCRIPTOR *)pD)->bInterfaceNumber;
alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting;
msk = 0;
if ((ifn == SetupPacket.wIndex.WB.L) && (alt == SetupPacket.wValue.WB.L)) {
set = TRUE;
old = USB_AltSetting[ifn];
USB_AltSetting[ifn] = (BYTE)alt;
}
break;
case USB_ENDPOINT_DESCRIPTOR_TYPE:
if (ifn == SetupPacket.wIndex.WB.L) {
n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F;
m = (n & 0x80) ? ((1 << 16) << n) : (1 << n);
if (alt == SetupPacket.wValue.WB.L) {
USB_EndPointMask |= m;
USB_EndPointHalt &= ~m;
USB_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD);
USB_EnableEP(n);
USB_ResetEP(n);
msk |= m;
}
else if ((alt == old) && ((msk & m) == 0)) {
USB_EndPointMask &= ~m;
USB_EndPointHalt &= ~m;
USB_DisableEP(n);
}
}
break;
}
pD=PointAdd(pD,pD->bLength);//(BYTE *)pD += pD->bLength;
}
return (set);
}
/*
* USB Endpoint 0 Event Callback
* Parameter: event
*/
void USB_EndPoint0 (BYTE event) {
switch (event) {
case USB_EVT_SETUP:
USB_SetupStage();
USB_DirCtrlEP(SetupPacket.bmRequestType.BM.Dir);
EP0Data.Count = SetupPacket.wLength;
switch (SetupPacket.bmRequestType.BM.Type) {
case REQUEST_STANDARD:
switch (SetupPacket.bRequest) {
case USB_REQUEST_GET_STATUS:
if (!USB_GetStatus()) {
goto stall_i;
}
break;
case USB_REQUEST_CLEAR_FEATURE:
if (!USB_SetClrFeature(0)) {
goto stall_i;
}
USB_StatusInStage();
#if USB_FEATURE_EVENT
USB_Feature_Event();
#endif
break;
case USB_REQUEST_SET_FEATURE:
if (!USB_SetClrFeature(1)) {
goto stall_i;
}
USB_StatusInStage();
#if USB_FEATURE_EVENT
USB_Feature_Event();
#endif
break;
case USB_REQUEST_SET_ADDRESS:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
USB_DeviceAddress = 0x80 | SetupPacket.wValue.WB.L;
USB_StatusInStage();
USB_SetAddress(USB_DeviceAddress);
break;
default:
goto stall_i;
}
break;
case USB_REQUEST_GET_DESCRIPTOR:
if (!USB_GetDescriptor()) {
goto stall_i;
}
break;
case USB_REQUEST_SET_DESCRIPTOR:
/*stall_o:*/ USB_SetStallEP(0x00);
EP0Data.Count = 0;
break;
case USB_REQUEST_GET_CONFIGURATION:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
EP0Data.pData = &USB_Configuration;
USB_DataInStage();
break;
default:
goto stall_i;
}
break;
case USB_REQUEST_SET_CONFIGURATION:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_DEVICE:
if (!USB_SetConfiguration()) {
goto stall_i;
}
USB_StatusInStage();
#if USB_CONFIGURE_EVENT
USB_Configure_Event();
#endif
break;
default:
goto stall_i;
}
break;
case USB_REQUEST_GET_INTERFACE:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_INTERFACE:
if ((USB_Configuration != 0) &&
(SetupPacket.wIndex.WB.L < USB_NumInterfaces)) {
EP0Data.pData = USB_AltSetting + SetupPacket.wIndex.WB.L;
USB_DataInStage();
} else {
goto stall_i;
}
break;
default:
goto stall_i;
}
break;
case USB_REQUEST_SET_INTERFACE:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_INTERFACE:
if (!USB_SetInterface()) {
goto stall_i;
}
USB_StatusInStage();
#if USB_INTERFACE_EVENT
USB_Interface_Event();
#endif
break;
default:
goto stall_i;
}
break;
default:
goto stall_i;
}
break;
case REQUEST_CLASS:
#if USB_CLASS
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_INTERFACE:
#if USB_HID
if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) {
switch (SetupPacket.bRequest) {
case HID_REQUEST_GET_REPORT:
if (HID_GetReport()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
break;
case HID_REQUEST_SET_REPORT:
EP0Data.pData = EP0Buf;
goto class_ok;
case HID_REQUEST_GET_IDLE:
if (HID_GetIdle()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
break;
case HID_REQUEST_SET_IDLE:
if (HID_SetIdle()) {
USB_StatusInStage();
goto class_ok;
}
break;
case HID_REQUEST_GET_PROTOCOL:
if (HID_GetProtocol()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
break;
case HID_REQUEST_SET_PROTOCOL:
if (HID_SetProtocol()) {
USB_StatusInStage();
goto class_ok;
}
break;
}
}
#endif /* USB_HID */
#if USB_MSC
if (SetupPacket.wIndex.WB.L == USB_MSC_IF_NUM) {
switch (SetupPacket.bRequest) {
case MSC_REQUEST_RESET:
if (MSC_Reset()) {
USB_StatusInStage();
goto class_ok;
}
break;
case MSC_REQUEST_GET_MAX_LUN:
if (MSC_GetMaxLUN()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
break;
}
}
#endif /* USB_MSC */
#if USB_AUDIO
if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) ||
(SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) ||
(SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) {
if (SetupPacket.bmRequestType.BM.Dir) {
if (ADC_IF_GetRequest()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
} else {
EP0Data.pData = EP0Buf;
goto class_ok;
}
}
#endif /* USB_AUDIO */
goto stall_i;
#if USB_AUDIO
case REQUEST_TO_ENDPOINT:
if (SetupPacket.bmRequestType.BM.Dir) {
if (ADC_EP_GetRequest()) {
EP0Data.pData = EP0Buf;
USB_DataInStage();
goto class_ok;
}
} else {
EP0Data.pData = EP0Buf;
goto class_ok;
}
goto stall_i;
#endif /* USB_AUDIO */
default:
goto stall_i;
}
class_ok:
break;
#else
goto stall_i;
#endif /* USB_CLASS */
case REQUEST_VENDOR:
goto stall_i;
default:
stall_i: USB_SetStallEP(0x80);
EP0Data.Count = 0;
break;
}
break;
case USB_EVT_OUT:
if (SetupPacket.bmRequestType.BM.Dir == 0) {
if (EP0Data.Count) {
USB_DataOutStage();
if (EP0Data.Count == 0) {
switch (SetupPacket.bmRequestType.BM.Type) {
case REQUEST_STANDARD:
goto stall_i;
#if (USB_CLASS)
case REQUEST_CLASS:
switch (SetupPacket.bmRequestType.BM.Recipient) {
case REQUEST_TO_INTERFACE:
#if USB_HID
if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) {
if (!HID_SetReport()) {
goto stall_i;
}
break;
}
#endif
#if USB_AUDIO
if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) ||
(SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) ||
(SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) {
if (!ADC_IF_SetRequest()) {
goto stall_i;
}
break;
}
#endif
goto stall_i;
case REQUEST_TO_ENDPOINT:
#if USB_AUDIO
if (ADC_EP_SetRequest()) break;
#endif
goto stall_i;
default:
goto stall_i;
}
break;
#endif
default:
goto stall_i;
}
USB_StatusInStage();
}
}
} else {
USB_StatusOutStage();
}
break;
case USB_EVT_IN:
if (SetupPacket.bmRequestType.BM.Dir == 1) {
USB_DataInStage();
}else {
if (USB_DeviceAddress & 0x80) {
USB_DeviceAddress &= 0x7F;
//USB_SetAddress(USB_DeviceAddress);
}
}
break;
case USB_EVT_IN_STALL:
USB_ClrStallEP(0x80);
break;
case USB_EVT_OUT_STALL:
USB_ClrStallEP(0x00);
break;
}
}

View File

@ -0,0 +1,33 @@
#ifndef __USBCORE_H__
#define __USBCORE_H__
#include "usbhal.h"
#include "usb.h"
#include "usbcfg.h"
/* USB Endpoint Data Structure */
typedef struct _USB_EP_DATA {
BYTE *pData;
WORD Count;
} USB_EP_DATA;
/* USB Core Global Variables */
extern WORD USB_DeviceStatus;
extern BYTE USB_DeviceAddress;
extern BYTE USB_Configuration;
extern DWORD USB_EndPointMask;
extern DWORD USB_EndPointHalt;
extern BYTE USB_AltSetting[USB_IF_NUM];
/* USB Endpoint 0 Buffer */
extern BYTE EP0Buf[64];
/* USB Endpoint 0 Data Info */
extern USB_EP_DATA EP0Data;
/* USB Setup Packet */
extern USB_SETUP_PACKET SetupPacket;
/* USB Core Functions */
extern void USB_ResetCore (void);
#endif /* __USBCORE_H__ */

168
dspad/arm9/source/usbdesc.c Normal file
View File

@ -0,0 +1,168 @@
#include "usb.h"
#include "hid.h"
#include "usbcfg.h"
#include "usbdesc.h"
BYTE HID_ReportDescriptor[] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x05, // USAGE (Game Pad)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0, // END_COLLECTION
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x08, // USAGE_MAXIMUM (Button 8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0 // END_COLLECTION
};
WORD HID_ReportDescSize = sizeof(HID_ReportDescriptor);
/* USB Standard Device Descriptor */
BYTE USB_DeviceDescriptor[] = {
USB_DEVICE_DESC_SIZE, /* bLength */
USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(0x0110), /* 1.10 */ /* bcdUSB */
0x00, /* bDeviceClass */
0x00, /* bDeviceSubClass */
0x00, /* bDeviceProtocol */
64, /* bMaxPacketSize0 */
WBVAL(0x6666), /* idVendor */
WBVAL(0x1870), /* idProduct */
WBVAL(0x0100), /* 1.00 */ /* bcdDevice */
0x04, /* iManufacturer */
0x20, /* iProduct */
0x42, /* iSerialNumber */
0x01 /* bNumConfigurations */
};
/* USB Configuration Descriptor */
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
BYTE USB_ConfigDescriptor[] = {
/* Configuration 1 */
USB_CONFIGUARTION_DESC_SIZE, /* bLength */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(( /* wTotalLength */
1*USB_CONFIGUARTION_DESC_SIZE +
1*USB_INTERFACE_DESC_SIZE +
1*HID_DESC_SIZE +
1*USB_ENDPOINT_DESC_SIZE
)),
0x01, /* bNumInterfaces */
0x01, /* bConfigurationValue */
0x00, /* iConfiguration */
USB_CONFIG_BUS_POWERED | /* bmAttributes */
USB_CONFIG_REMOTE_WAKEUP,
USB_CONFIG_POWER_MA(100), /* bMaxPower */
/* Interface 0, Alternate Setting 0, HID Class */
USB_INTERFACE_DESC_SIZE, /* bLength */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
0x00, /* bInterfaceNumber */
0x00, /* bAlternateSetting */
0x01, /* bNumEndpoints */
USB_DEVICE_CLASS_HUMAN_INTERFACE, /* bInterfaceClass */
HID_SUBCLASS_NONE, /* bInterfaceSubClass */
HID_PROTOCOL_NONE, /* bInterfaceProtocol */
0x5C, /* iInterface */
/* HID Class Descriptor */
/* HID_DESC_OFFSET = 0x0012 */
HID_DESC_SIZE, /* bLength */
HID_HID_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(0x0100), /* 1.00 */ /* bcdHID */
0x00, /* bCountryCode */
0x01, /* bNumDescriptors */
HID_REPORT_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(HID_REPORT_DESC_SIZE), /* wDescriptorLength */
/* Endpoint, HID Interrupt In */
USB_ENDPOINT_DESC_SIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_ENDPOINT_IN(1), /* bEndpointAddress */
USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */
WBVAL(0x0004), /* wMaxPacketSize */
10, /* 10ms */ /* bInterval */
/* Terminator */
0 /* bLength */
};
/* USB String Descriptor (optional) */
BYTE USB_StringDescriptor[] = {
/* Index 0x00: LANGID Codes */
0x04, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(0x0409), /* US English */ /* wLANGID */
/* Index 0x04: Manufacturer */
0x1C, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'N',0,
'D',0,
'S',0,
' ',0,
'G',0,
'A',0,
'M',0,
'E',0,
' ',0,
'P',0,
'A',0,
'D',0,
' ',0,
/* Index 0x20: Product */
0x28, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'U',0,
'S',0,
'B',0,
' ',0,
'N',0,
'D',0,
'S',0,
' ',0,
'G',0,
'A',0,
'M',0,
'E',0,
' ',0,
'P',0,
'A',0,
'D',0,
' ',0,
' ',0,
' ',0,
/* Index 0x48: Serial Number */
0x1A, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'U',0,
'S',0,
'B',0,
' ',0,
'G',0,
'A',0,
'O',0,
'J',0,
'I',0,
'A',0,
'N',0,
' ',0,
/* Index 0x62: Interface 0, Alternate Setting 0 */
0x0E, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'N',0,
'D',0,
'S',0,
'P',0,
'A',0,
'D',0,
};

View File

@ -0,0 +1,25 @@
#ifndef _USBDESC_H_
#define _USBDESC_H_
#include "usbhal.h"
#define WBVAL(x) (x & 0xFF),((x >> 8) & 0xFF)
#define USB_DEVICE_DESC_SIZE (sizeof(USB_DEVICE_DESCRIPTOR))
#define USB_CONFIGUARTION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR))
#define USB_INTERFACE_DESC_SIZE (sizeof(USB_INTERFACE_DESCRIPTOR))
#define USB_ENDPOINT_DESC_SIZE (sizeof(USB_ENDPOINT_DESCRIPTOR))
#define HID_DESC_OFFSET 0x0012
#define HID_DESC_SIZE (sizeof(HID_DESCRIPTOR))
#define HID_REPORT_DESC_SIZE (sizeof(HID_ReportDescriptor))
extern BYTE USB_ConfigDescriptor[];
extern BYTE USB_StringDescriptor[];
extern BYTE USB_DeviceDescriptor[];
extern BYTE HID_ReportDescriptor[];
extern WORD HID_ReportDescSize;
#endif //_USBDESC_H_

View File

@ -0,0 +1,61 @@
#include "usbhal.h"
#ifdef ARM9
__inline
void usbwrcmd(u8 val) //D12写命令
{
//*(vu8*)(0x0A000000+val) = 0xFF;
*(vu16*)(0x09FFFFFE) = val;
}
__inline
void usbwrdat(u8 val) //D12写数据
{
//*(vu8*)(0x0A000000+val) = 0xFE;
*(vu16*)(0x09FDFFFE) = val;
}
__inline
u8 usbrddat() //D12读
{
//*(vu8*)(0x0A00FFFF) = 0xFE;
return *(vu16*)(0x09FDFFFE);
}
u16 usbreadid()
{
u16 id=0;
usbwrcmd(0xFD);
id=usbrddat();
id|=(u16)usbrddat()<<8;
return id;
}
#else
void usbwrcmd(u8 val) //D12写命令
{
*(vu8*)(0x08020000) = val;
}
void usbwrdat(u8 val) //D12写数据
{
*(vu8*)(0x08000000) = val;
}
u8 usbrddat() //D12读
{
return *(vu8*)(0x08000000);
}
u16 usbreadid()
{
u16 id=0;
usbwrcmd(0xFD);
id=usbrddat();
id|=(u16)usbrddat()<<8;
return id;
}
#endif

View File

@ -0,0 +1,31 @@
#ifndef _USBHAL_H_
#define _USBHAL_H_
#ifdef ARM9
#include <nds.h>
#else
#include <gba.h>
#endif
#include <stdio.h>
#define BOOL u8
#define WORD u16
#define DWORD u32
#define BYTE u8
#define TRUE 1
#define FALSE 0
void usbwrcmd(u8 val);
void usbwrdat(u8 val);
u8 usbrddat();
u16 usbreadid();
//#define disable() ;
//#define enable() ;
#define D12_ID 0x1012
#define nop() __asm __volatile ("nop\n")
#endif //_USBHAL_H_

61
dspad/arm9/source/usbhw.c Normal file
View File

@ -0,0 +1,61 @@
#include "usbhw.h"
#include "usbcfg.h"
TUSB_Init USB_Init =0;
TUSB_Connect USB_Connect =0;
TUSB_Reset USB_Reset =0;
TUSB_Suspend USB_Suspend =0;
TUSB_Resume USB_Resume =0;
TUSB_WakeUp USB_WakeUp =0;
TUSB_WakeUpCfg USB_WakeUpCfg =0;
TUSB_SetAddress USB_SetAddress =0;
TUSB_Configure USB_Configure =0;
TUSB_ConfigEP USB_ConfigEP =0;
TUSB_DirCtrlEP USB_DirCtrlEP =0;
TUSB_EnableEP USB_EnableEP =0;
TUSB_DisableEP USB_DisableEP =0;
TUSB_ResetEP USB_ResetEP =0;
TUSB_SetStallEP USB_SetStallEP =0;
TUSB_ClrStallEP USB_ClrStallEP =0;
TUSB_ReadEP USB_ReadEP =0;
TUSB_WriteEP USB_WriteEP =0;
TUSB_GetFrame USB_GetFrame =0;
TUSB_ReadInterruptRegister USB_ReadInterruptRegister =0;
TUSB_ReadLastTransactionStatus USB_ReadLastTransactionStatus =0;
TUSB_ReadEndpointStatus USB_ReadEndpointStatus =0;
TUSB__SelectEndpoint USB__SelectEndpoint =0;
TUSB_AcknowledgeEndpoint USB_AcknowledgeEndpoint =0;
TUSB_AcknowledgeSETUP USB_AcknowledgeSETUP =0;
TUSB_ClrBufEP USB_ClrBufEP =0;
u32 USB_MAX_PACKET0=64;
void D14USBInit()
{
USB_MAX_PACKET0=64;
USB_Init =D14_Init ;
USB_Connect =D14_Connect ;
USB_Reset =D14_Reset ;
USB_Suspend =D14_Suspend ;
USB_Resume =D14_Resume ;
USB_WakeUp =D14_WakeUp ;
USB_WakeUpCfg =D14_WakeUpCfg ;
USB_SetAddress =D14_SetAddress ;
USB_Configure =D14_Configure ;
USB_ConfigEP =D14_ConfigEP ;
USB_DirCtrlEP =D14_DirCtrlEP ;
USB_EnableEP =D14_EnableEP ;
USB_DisableEP =D14_DisableEP ;
USB_ResetEP =D14_ResetEP ;
USB_SetStallEP =D14_SetStallEP ;
USB_ClrStallEP =D14_ClrStallEP ;
USB_ReadEP =D14_ReadEP ;
USB_WriteEP =D14_WriteEP ;
USB_GetFrame =D14_GetFrame ;
USB_AcknowledgeEndpoint =D14_AcknowledgeEndpoint ;
USB_AcknowledgeSETUP =D14_AcknowledgeSETUP ;
USB_ClrBufEP =D14_ClrBufEP ;
}

64
dspad/arm9/source/usbhw.h Normal file
View File

@ -0,0 +1,64 @@
#ifndef _USBHW_H_
#define _USBHW_H_
#include "usbhal.h"
#include "usbuser.h"
#include "d14hal.h"
typedef void (*TUSB_Init) (void);
typedef void (*TUSB_Connect) (BOOL con);
typedef void (*TUSB_Reset) (void);
typedef void (*TUSB_Suspend) (void);
typedef void (*TUSB_Resume) (void);
typedef void (*TUSB_WakeUp) (void);
typedef void (*TUSB_WakeUpCfg) (BOOL cfg);
typedef void (*TUSB_SetAddress) (BYTE adr);
typedef void (*TUSB_Configure) (BOOL cfg);
typedef void (*TUSB_ConfigEP) (void *pEPD);
typedef void (*TUSB_DirCtrlEP) (DWORD dir);
typedef void (*TUSB_EnableEP) (BYTE EPNum);
typedef void (*TUSB_DisableEP) (BYTE EPNum);
typedef void (*TUSB_ResetEP) (BYTE EPNum);
typedef void (*TUSB_SetStallEP) (BYTE EPNum);
typedef void (*TUSB_ClrStallEP) (BYTE EPNum);
typedef WORD (*TUSB_ReadEP) (BYTE EPNum, BYTE *pData);
typedef WORD (*TUSB_WriteEP) (BYTE EPNum, BYTE *pData, WORD cnt);
typedef WORD (*TUSB_GetFrame) (void);
typedef WORD (*TUSB_ReadInterruptRegister)(void);
typedef BYTE (*TUSB_ReadLastTransactionStatus)(BYTE EPNum);
typedef BYTE (*TUSB_ReadEndpointStatus)(BYTE EPNum);
typedef BYTE (*TUSB__SelectEndpoint)(BYTE EPNum);
typedef void (*TUSB_AcknowledgeEndpoint)(BYTE EPNum);
typedef void (*TUSB_AcknowledgeSETUP)(void);
typedef void (*TUSB_ClrBufEP) (BYTE EPNum);
TUSB_Init USB_Init ;
TUSB_Connect USB_Connect ;
TUSB_Reset USB_Reset ;
TUSB_Suspend USB_Suspend ;
TUSB_Resume USB_Resume ;
TUSB_WakeUp USB_WakeUp ;
TUSB_WakeUpCfg USB_WakeUpCfg ;
TUSB_SetAddress USB_SetAddress ;
TUSB_Configure USB_Configure ;
TUSB_ConfigEP USB_ConfigEP ;
TUSB_DirCtrlEP USB_DirCtrlEP ;
TUSB_EnableEP USB_EnableEP ;
TUSB_DisableEP USB_DisableEP ;
TUSB_ResetEP USB_ResetEP ;
TUSB_SetStallEP USB_SetStallEP ;
TUSB_ClrStallEP USB_ClrStallEP ;
TUSB_ReadEP USB_ReadEP ;
TUSB_WriteEP USB_WriteEP ;
TUSB_GetFrame USB_GetFrame ;
TUSB_ReadInterruptRegister USB_ReadInterruptRegister ;
TUSB_ReadLastTransactionStatus USB_ReadLastTransactionStatus;
TUSB_ReadEndpointStatus USB_ReadEndpointStatus ;
TUSB__SelectEndpoint USB__SelectEndpoint ;
TUSB_AcknowledgeEndpoint USB_AcknowledgeEndpoint ;
TUSB_AcknowledgeSETUP USB_AcknowledgeSETUP ;
TUSB_ClrBufEP USB_ClrBufEP ;
u32 USB_MAX_PACKET0;
void D14USBInit();
#endif //_USBHW_H_

View File

@ -0,0 +1,82 @@
#include "usbhw.h"
#include "usbcore.h"
#include "usbuser.h"
#include "hiduser.h"
#include <stdio.h>
/* USB Endpoint Events Callback Pointers */
void (* const USB_P_EP[USB_EP_NUM/2]) (BYTE event) = {
USB_EndPoint0,
USB_EndPoint1,
USB_EndPoint2,
};
void USB_Configure_Event (void)
{
if (USB_Configuration)
{
GetInReport();
USB_WriteEP(0x81, InReport, 3);
}
}
void USB_EndPoint1 (BYTE event)
{
switch (event)
{
case USB_EVT_IN:
GetInReport();
USB_WriteEP(0x81, InReport, 3);
break;
}
}
void USB_EndPoint2 (BYTE event)
{
}
u16 USB_IF=0;
void USB_ISR()
{
USB_IF|=D14_IF;
D14_IF=USB_IF;
if(USB_IF&D14_IF_BRST)
{
USB_Reset();
USB_IF&=~D14_IF_BRST;
}
if(USB_IF&D14_IF_SUSP)
{
USB_Suspend();
USB_IF&=~D14_IF_SUSP;
}
if(USB_IF&D14_IF_EP0SETUP)
{
USB_P_EP[0](USB_EVT_SETUP);
USB_IF&=~D14_IE_EP0SETUP;
}
if(USB_IF&D14_IF_EP0OUT)
{
USB_P_EP[0](USB_EVT_OUT);
USB_IF&=~D14_IF_EP0OUT;
}
if(USB_IF&D14_IF_EP0IN)
{
USB_P_EP[0](USB_EVT_IN);
USB_IF&=~D14_IF_EP0IN;
}
if(USB_IF&D14_IF_EP1IN)
{
USB_P_EP[1](USB_EVT_IN);
USB_IF&=~D14_IF_EP1IN;
}
}
//end of file

View File

@ -0,0 +1,33 @@
#ifndef _USBUSER_H_
#define _USBUSER_H_
#include "usbhal.h"
#include "usbcfg.h"
/* USB Endpoint Callback Events */
#define USB_EVT_SETUP 1 /* Setup Packet */
#define USB_EVT_OUT 2 /* OUT Packet */
#define USB_EVT_IN 3 /* IN Packet */
#define USB_EVT_OUT_NAK 4 /* OUT Packet - Not Acknowledged */
#define USB_EVT_IN_NAK 5 /* IN Packet - Not Acknowledged */
#define USB_EVT_OUT_STALL 6 /* OUT Packet - Stalled */
#define USB_EVT_IN_STALL 7 /* IN Packet - Stalled */
#define USB_EVT_OUT_DMA_EOT 8 /* DMA OUT EP - End of Transfer */
#define USB_EVT_IN_DMA_EOT 9 /* DMA IN EP - End of Transfer */
#define USB_EVT_OUT_DMA_NDR 10 /* DMA OUT EP - New Descriptor Request */
#define USB_EVT_IN_DMA_NDR 11 /* DMA IN EP - New Descriptor Request */
#define USB_EVT_OUT_DMA_ERR 12 /* DMA OUT EP - Error */
#define USB_EVT_IN_DMA_ERR 13 /* DMA IN EP - Error */
extern void USB_Configure_Event (void);
extern void (* const USB_P_EP[USB_EP_NUM/2]) (BYTE event);
extern void USB_EndPoint0 (BYTE event);
extern void USB_EndPoint1 (BYTE event);
extern void USB_EndPoint2 (BYTE event);
extern void USB_ISR(void);
extern void USB_MAIN(void);
#endif //_USBUSER_H_

BIN
dspad/banner.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B