mirror of
https://github.com/Epicpkmn11/dsi-camera.git
synced 2025-06-18 14:35:38 -04:00
Update for calico
I really just wanted to see how well calico played with something with custom ARM7 code Doesn't seem too crazy different BUG: Internal camera is initializing upside-down and with incorrect colors?? Swapping to outside and back fixes it?? I think this is new, but not sure why
This commit is contained in:
parent
519e710b01
commit
b236bd1d0c
18
Makefile
18
Makefile
@ -5,16 +5,16 @@ ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
export TARGET := dsi-camera
|
||||
export TOPDIR := $(CURDIR)
|
||||
export TARGET := dsi-camera
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
# specify a directory which contains the nitro filesystem
|
||||
# this is relative to the Makefile
|
||||
NITRO_FILES :=
|
||||
NITRO_FILES :=
|
||||
|
||||
# These set the information text in the nds file
|
||||
GAME_TITLE := DSi camera test
|
||||
GAME_SUBTITLE1 := Pk11
|
||||
GAME_AUTHOR := Pk11
|
||||
|
||||
GAME_ICON := icon.bmp
|
||||
|
||||
@ -30,21 +30,21 @@ all: checkarm7 checkarm9 $(TARGET).nds
|
||||
#---------------------------------------------------------------------------------
|
||||
checkarm7:
|
||||
$(MAKE) -C arm7
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
checkarm9:
|
||||
$(MAKE) -C arm9
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
$(TARGET).nds : $(NITRO_FILES) arm7/$(TARGET).elf arm9/$(TARGET).elf
|
||||
$(TARGET).nds : $(NITRO_FILES) arm7/$(TARGET).elf arm9/$(TARGET).elf
|
||||
ndstool -c $(TARGET).nds -7 arm7/$(TARGET).elf -9 arm9/$(TARGET).elf \
|
||||
-b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1)" \
|
||||
-b $(GAME_ICON) "$(GAME_TITLE);$(GAME_AUTHOR)" \
|
||||
$(_ADDFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
arm7/$(TARGET).elf:
|
||||
$(MAKE) -C arm7
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
arm9/$(TARGET).elf:
|
||||
$(MAKE) -C arm9
|
||||
@ -53,7 +53,7 @@ arm9/$(TARGET).elf:
|
||||
clean:
|
||||
$(MAKE) -C arm9 clean
|
||||
$(MAKE) -C arm7 clean
|
||||
rm -f $(TARGET).nds $(TARGET).arm7 $(TARGET).arm9
|
||||
rm -f $(TARGET).nds
|
||||
|
||||
cppcheck:
|
||||
$(MAKE) -C arm7 cppcheck
|
||||
|
@ -14,36 +14,29 @@ include $(DEVKITARM)/ds_rules
|
||||
# DATA is a list of directories containing binary files
|
||||
# all directories are relative to this makefile
|
||||
#---------------------------------------------------------------------------------
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
INCLUDES := include ../shared/include
|
||||
DATA :=
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
INCLUDES := include ../shared/include build
|
||||
DATA :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -mthumb-interwork
|
||||
ARCH := -march=armv4t -mtune=arm7tdmi -mthumb
|
||||
|
||||
CFLAGS := -g -Wall -O2\
|
||||
-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\
|
||||
-ffast-math \
|
||||
$(ARCH)
|
||||
CFLAGS := -g -Wall -Os -ffunction-sections -fdata-sections\
|
||||
$(ARCH) $(INCLUDE) -DARM7
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -Wl,-Map,$(notdir $*).map
|
||||
|
||||
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
|
||||
LIBS := -lmm7 -lnds7
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(LIBNDS)
|
||||
|
||||
LIBDIRS := $(LIBNDS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
@ -52,39 +45,44 @@ LIBDIRS := $(LIBNDS)
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export ARM7ELF := $(CURDIR)/$(TARGET).elf
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
export ARM7ELF := $(CURDIR)/$(TARGET).elf
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
|
||||
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)/*.*)))
|
||||
|
||||
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)
|
||||
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)
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
|
||||
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
|
||||
|
||||
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
.PHONY: $(BUILD) clean
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
@ -95,7 +93,7 @@ $(BUILD):
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) *.elf
|
||||
@rm -fr $(BUILD) $(TARGET).elf
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
@ -106,15 +104,10 @@ DEPENDS := $(OFILES:.o=.d)
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(ARM7ELF) : $(OFILES)
|
||||
@echo linking $(notdir $@)
|
||||
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
|
||||
|
||||
$(ARM7ELF) : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
%.bin.o %_bin.h : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef APTINA_H
|
||||
#define APTINA_H
|
||||
|
||||
#include "fifo_vars.h"
|
||||
#include "pxi_vars.h"
|
||||
|
||||
#include <nds.h>
|
||||
|
||||
|
@ -1,15 +1,18 @@
|
||||
#ifndef I2C_HANDLER_H
|
||||
#define I2C_HANDLER_H
|
||||
|
||||
#include "fifo_vars.h"
|
||||
#include "pxi_vars.h"
|
||||
|
||||
#include <nds/ndstypes.h>
|
||||
#include <nds.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void i2cFifoHandler(u32 value32, void *userdata);
|
||||
extern Thread s_i2cPxiThread;
|
||||
extern u8 s_i2cPxiThreadStack[1024];
|
||||
|
||||
int i2cPxiThreadMain(void* arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -34,10 +34,11 @@
|
||||
|
||||
#include <nds/bios.h>
|
||||
|
||||
void i2cDelay();
|
||||
void i2cStop(u8 arg0);
|
||||
u8 i2cGetResult();
|
||||
void i2cSetDelay(u8 device);
|
||||
// https://github.com/devkitPro/calico/blob/d0cffb09d3fedc40bf1a6ce52aa22112d8814e99/source/nds/arm7/i2c.twl.c#L54-L58
|
||||
MK_INLINE bool i2cGetResult() {
|
||||
i2cWaitBusy();
|
||||
return (REG_I2C_CNT >> 4) & 0x01;
|
||||
}
|
||||
|
||||
u8 aptGetData(u8 flags) {
|
||||
REG_I2CCNT = 0xC0 | flags;
|
||||
@ -59,20 +60,17 @@ u8 aptSelectDevice(u8 device, u8 flags) {
|
||||
}
|
||||
|
||||
u8 aptSelectRegister(u8 reg, u8 flags) {
|
||||
i2cDelay();
|
||||
REG_I2CDATA = reg;
|
||||
REG_I2CCNT = 0xC0 | flags;
|
||||
return i2cGetResult();
|
||||
}
|
||||
|
||||
u8 aptWriteRegister(u8 device, u16 reg, u16 data) {
|
||||
i2cSetDelay(device);
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 8; i++) {
|
||||
if(aptSelectDevice(device, I2C_START) && aptSelectRegister(reg >> 8, I2C_NONE) &&
|
||||
aptSelectRegister(reg & 0xFF, I2C_NONE)) {
|
||||
i2cDelay();
|
||||
if(aptSetData(data >> 8, I2C_NONE) && aptSetData(data & 0xFF, I2C_STOP))
|
||||
return 1;
|
||||
}
|
||||
@ -83,13 +81,11 @@ u8 aptWriteRegister(u8 device, u16 reg, u16 data) {
|
||||
}
|
||||
|
||||
u16 aptReadRegister(u8 device, u16 reg) {
|
||||
i2cSetDelay(device);
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 8; i++) {
|
||||
if(aptSelectDevice(device, I2C_START) && aptSelectRegister(reg >> 8, I2C_NONE) &&
|
||||
aptSelectRegister(reg & 0xFF, I2C_STOP)) {
|
||||
i2cDelay();
|
||||
if(aptSelectDevice(device | 1, I2C_START)) {
|
||||
return (aptGetData(I2C_READ | I2C_ACK) << 8) | aptGetData(I2C_STOP | I2C_READ);
|
||||
}
|
||||
|
@ -5,38 +5,62 @@
|
||||
|
||||
#include <nds.h>
|
||||
|
||||
void i2cFifoHandler(u32 value32, void *userdata) {
|
||||
switch(value32) {
|
||||
case CAM_INIT:
|
||||
init(I2C_CAM0);
|
||||
init(I2C_CAM1);
|
||||
fifoSendValue32(FIFO_CAMERA, aptReadRegister(I2C_CAM0, 0));
|
||||
break;
|
||||
case CAM0_ACTIVATE:
|
||||
activate(I2C_CAM0);
|
||||
fifoSendValue32(FIFO_CAMERA, CAM0_ACTIVATE);
|
||||
break;
|
||||
case CAM0_DEACTIVATE:
|
||||
deactivate(I2C_CAM0);
|
||||
fifoSendValue32(FIFO_CAMERA, CAM0_DEACTIVATE);
|
||||
break;
|
||||
case CAM1_ACTIVATE:
|
||||
activate(I2C_CAM1);
|
||||
fifoSendValue32(FIFO_CAMERA, CAM1_ACTIVATE);
|
||||
break;
|
||||
case CAM1_DEACTIVATE:
|
||||
deactivate(I2C_CAM1);
|
||||
fifoSendValue32(FIFO_CAMERA, CAM1_DEACTIVATE);
|
||||
break;
|
||||
case CAM_SET_MODE_PREVIEW:
|
||||
setMode(CAPTURE_MODE_PREVIEW);
|
||||
fifoSendValue32(FIFO_CAMERA, CAPTURE_MODE_PREVIEW);
|
||||
break;
|
||||
case CAM_SET_MODE_CAPTURE:
|
||||
setMode(CAPTURE_MODE_CAPTURE);
|
||||
fifoSendValue32(FIFO_CAMERA, CAPTURE_MODE_CAPTURE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
// Management structure and stack space for PXI server thread
|
||||
Thread s_i2cPxiThread;
|
||||
alignas(8) u8 s_i2cPxiThreadStack[1024];
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int i2cPxiThreadMain(void* arg) {
|
||||
//---------------------------------------------------------------------------------
|
||||
// Set up PXI mailbox, used to receive PXI command words
|
||||
Mailbox mb;
|
||||
u32 mb_slots[4];
|
||||
mailboxPrepare(&mb, mb_slots, sizeof(mb_slots)/4);
|
||||
pxiSetMailbox(PxiChannel_User0, &mb);
|
||||
|
||||
// Main PXI message loop
|
||||
for (;;) {
|
||||
// Receive a message
|
||||
u32 msg = mailboxRecv(&mb);
|
||||
u32 retval = 0;
|
||||
|
||||
switch (msg) {
|
||||
case CAM_INIT:
|
||||
init(I2C_CAM0);
|
||||
init(I2C_CAM1);
|
||||
retval = aptReadRegister(I2C_CAM0, 0);
|
||||
break;
|
||||
case CAM0_ACTIVATE:
|
||||
activate(I2C_CAM0);
|
||||
retval = CAM0_ACTIVATE;
|
||||
break;
|
||||
case CAM0_DEACTIVATE:
|
||||
deactivate(I2C_CAM0);
|
||||
retval = CAM0_DEACTIVATE;
|
||||
break;
|
||||
case CAM1_ACTIVATE:
|
||||
activate(I2C_CAM1);
|
||||
retval = CAM1_ACTIVATE;
|
||||
break;
|
||||
case CAM1_DEACTIVATE:
|
||||
deactivate(I2C_CAM1);
|
||||
retval = CAM1_DEACTIVATE;
|
||||
break;
|
||||
case CAM_SET_MODE_PREVIEW:
|
||||
setMode(CAPTURE_MODE_PREVIEW);
|
||||
retval = CAPTURE_MODE_PREVIEW;
|
||||
break;
|
||||
case CAM_SET_MODE_CAPTURE:
|
||||
setMode(CAPTURE_MODE_CAPTURE);
|
||||
retval = CAPTURE_MODE_CAPTURE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Send a reply back to the ARM9
|
||||
pxiReply(PxiChannel_User0, retval);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -28,66 +28,63 @@
|
||||
|
||||
---------------------------------------------------------------------------------*/
|
||||
|
||||
/*******************************************
|
||||
* Modified to have fifo checking for I2C. *
|
||||
* -Pk11, 2020 *
|
||||
******************************************/
|
||||
/******************************************
|
||||
* Modified to have pxi checking for I2C. *
|
||||
* -Pk11, 2020 *
|
||||
*****************************************/
|
||||
|
||||
#include "i2c_handler.h"
|
||||
|
||||
#include <dswifi7.h>
|
||||
#include <maxmod7.h>
|
||||
// #include <calico.h>
|
||||
#include <nds.h>
|
||||
// #include <maxmod7.h>
|
||||
|
||||
void VblankHandler(void) { Wifi_Update(); }
|
||||
|
||||
void VcountHandler() { inputGetAndSend(); }
|
||||
|
||||
volatile bool exitflag = false;
|
||||
|
||||
void powerButtonCB() { exitflag = true; }
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int main() {
|
||||
// clear sound registers
|
||||
dmaFillWords(0, (void *)0x04000400, 0x100);
|
||||
//---------------------------------------------------------------------------------
|
||||
|
||||
REG_SOUNDCNT |= SOUND_ENABLE;
|
||||
writePowerManagement(PM_CONTROL_REG, (readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE) | PM_SOUND_AMP);
|
||||
powerOn(POWER_SOUND);
|
||||
// Read settings from NVRAM
|
||||
envReadNvramSettings();
|
||||
|
||||
readUserSettings();
|
||||
ledBlink(0);
|
||||
// Set up extended keypad server (X/Y/hinge)
|
||||
keypadStartExtServer();
|
||||
|
||||
irqInit();
|
||||
// Start the RTC tracking IRQ
|
||||
initClockIRQ();
|
||||
fifoInit();
|
||||
// Configure and enable VBlank interrupt
|
||||
lcdSetIrqMask(DISPSTAT_IE_ALL, DISPSTAT_IE_VBLANK);
|
||||
irqEnable(IRQ_VBLANK);
|
||||
|
||||
// Set up RTC
|
||||
rtcInit();
|
||||
rtcSyncTime();
|
||||
|
||||
// Initialize power management
|
||||
pmInit();
|
||||
|
||||
// Set up block device peripherals
|
||||
blkInit();
|
||||
|
||||
// Set up touch screen driver
|
||||
touchInit();
|
||||
touchStartServer(80, MAIN_THREAD_PRIO);
|
||||
|
||||
mmInstall(FIFO_MAXMOD);
|
||||
// // Set up sound and mic driver
|
||||
// soundStartServer(MAIN_THREAD_PRIO-0x10);
|
||||
// micStartServer(MAIN_THREAD_PRIO-0x18);
|
||||
|
||||
SetYtrigger(80);
|
||||
// // Set up wireless manager
|
||||
// wlmgrStartServer(MAIN_THREAD_PRIO-8);
|
||||
|
||||
installWifiFIFO();
|
||||
installSoundFIFO();
|
||||
// // Set up Maxmod
|
||||
// mmInstall(MAIN_THREAD_PRIO+1);
|
||||
|
||||
installSystemFIFO();
|
||||
|
||||
irqSet(IRQ_VCOUNT, VcountHandler);
|
||||
irqSet(IRQ_VBLANK, VblankHandler);
|
||||
|
||||
irqEnable(IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);
|
||||
|
||||
setPowerButtonCB(powerButtonCB);
|
||||
|
||||
fifoSetValue32Handler(FIFO_CAMERA, i2cFifoHandler, NULL);
|
||||
// Set up server thread
|
||||
threadPrepare(&s_i2cPxiThread, i2cPxiThreadMain, NULL, &s_i2cPxiThreadStack[sizeof(s_i2cPxiThreadStack)], MAIN_THREAD_PRIO);
|
||||
threadStart(&s_i2cPxiThread);
|
||||
|
||||
// Keep the ARM7 mostly idle
|
||||
while(!exitflag) {
|
||||
if(0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) {
|
||||
exitflag = true;
|
||||
}
|
||||
swiWaitForVBlank();
|
||||
while (pmMainLoop()) {
|
||||
threadWaitForVBlank();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -29,41 +29,37 @@ endif
|
||||
# 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
|
||||
# DATA is a list of directories containing binary files embedded using bin2o
|
||||
# GRAPHICS is a list of directories containing image files to be converted with grit
|
||||
# all directories are relative to this makefile
|
||||
#---------------------------------------------------------------------------------
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
INCLUDES := include ../shared/include
|
||||
DATA :=
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
INCLUDES := include ../shared/include
|
||||
DATA :=
|
||||
GRAPHICS :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -mthumb -mthumb-interwork
|
||||
ARCH := -march=armv5te -mtune=arm946e-s
|
||||
|
||||
CFLAGS := -g -Wall -Wno-psabi -O2\
|
||||
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
|
||||
-ffast-math \
|
||||
$(ARCH)
|
||||
|
||||
CFLAGS += $(INCLUDE) -DARM9
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++20 -Wno-volatile
|
||||
|
||||
ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s
|
||||
|
||||
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
CFLAGS := -g -Wall -O2 -ffunction-sections -fdata-sections\
|
||||
$(ARCH) $(INCLUDE) -DARM9
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lfat -lnds9
|
||||
LIBS := -lfat -lnds9
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(LIBNDS)
|
||||
LIBDIRS := $(LIBNDS) $(PORTLIBS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
@ -72,39 +68,46 @@ LIBDIRS := $(LIBNDS)
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export ARM9ELF := $(CURDIR)/$(TARGET).elf
|
||||
export ARM9ELF := $(CURDIR)/$(TARGET).elf
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
|
||||
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
|
||||
|
||||
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)/*.*)))
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
|
||||
|
||||
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
.PHONY: $(BUILD) clean
|
||||
|
||||
@ -116,7 +119,8 @@ $(BUILD):
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) *.elf *.nds* *.bin
|
||||
@rm -fr $(BUILD) $(TARGET).elf
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
@ -124,18 +128,24 @@ else
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(ARM9ELF) : $(OFILES)
|
||||
@echo linking $(notdir $@)
|
||||
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
|
||||
$(ARM9ELF) : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
%.bin.o %_bin.h : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# This rule creates assembly source files using grit
|
||||
# grit takes an image file and a .grit describing how the file is to be processed
|
||||
# add additional rules like this for each image extension
|
||||
# you use in the graphics folders
|
||||
#---------------------------------------------------------------------------------
|
||||
%.s %.h: %.png %.grit
|
||||
#---------------------------------------------------------------------------------
|
||||
grit $< -fts -o$*
|
||||
|
||||
-include $(DEPSDIR)/*.d
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#include "fifo_vars.h"
|
||||
#include "pxi_vars.h"
|
||||
|
||||
#include <nds/ndstypes.h>
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "camera.h"
|
||||
#include "calico/nds/pxi.h"
|
||||
|
||||
#include <nds.h>
|
||||
|
||||
@ -25,9 +26,7 @@ bool cameraInit() {
|
||||
swiDelay(0x14);
|
||||
|
||||
// issue "aptina_code_list_init" via I2C bus on ARM7 side
|
||||
fifoSendValue32(FIFO_CAMERA, CAM_INIT);
|
||||
fifoWaitValue32(FIFO_CAMERA);
|
||||
u32 val = fifoGetValue32(FIFO_CAMERA);
|
||||
u32 val = pxiSendAndReceive(PXI_CAMERA, CAM_INIT);
|
||||
|
||||
REG_SCFG_CLK &= ~BIT(8); // CamExternal Clock = OFF
|
||||
REG_SCFG_CLK |= BIT(8); // CamExternal Clock = ON
|
||||
@ -41,10 +40,7 @@ bool cameraActivate(Camera cam) {
|
||||
cameraDeactivate(activeCamera);
|
||||
|
||||
u32 command = (cam == CAM_INNER) ? CAM0_ACTIVATE : CAM1_ACTIVATE;
|
||||
fifoSendValue32(FIFO_CAMERA, command);
|
||||
fifoWaitValue32(FIFO_CAMERA);
|
||||
|
||||
if(fifoGetValue32(FIFO_CAMERA) == command) {
|
||||
if(pxiSendAndReceive(PXI_CAMERA, command) == command) {
|
||||
activeCamera = cam;
|
||||
return true;
|
||||
} else {
|
||||
@ -54,10 +50,7 @@ bool cameraActivate(Camera cam) {
|
||||
|
||||
bool cameraDeactivate(Camera cam) {
|
||||
u32 command = (cam == CAM_INNER) ? CAM0_DEACTIVATE : CAM1_DEACTIVATE;
|
||||
fifoSendValue32(FIFO_CAMERA, command);
|
||||
fifoWaitValue32(FIFO_CAMERA);
|
||||
|
||||
if(fifoGetValue32(FIFO_CAMERA) == command) {
|
||||
if(pxiSendAndReceive(PXI_CAMERA, command) == command) {
|
||||
activeCamera = CAM_NONE;
|
||||
return true;
|
||||
} else {
|
||||
@ -69,9 +62,7 @@ void cameraTransferStart(u16 *dst, CaptureMode mode) {
|
||||
bool preview = mode == CAPTURE_MODE_PREVIEW;
|
||||
|
||||
if(mode != activeMode) {
|
||||
fifoSendValue32(FIFO_CAMERA, preview ? CAM_SET_MODE_PREVIEW : CAM_SET_MODE_CAPTURE);
|
||||
fifoWaitValue32(FIFO_CAMERA);
|
||||
fifoGetValue32(FIFO_CAMERA);
|
||||
pxiSendAndReceive(PXI_CAMERA, preview ? CAM_SET_MODE_PREVIEW : CAM_SET_MODE_CAPTURE);
|
||||
activeMode = mode;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
printf("Initializing...\n");
|
||||
pxiWaitRemote(PXI_CAMERA); // Wait for ARM7 to initialize PXI
|
||||
cameraInit();
|
||||
|
||||
Camera camera = CAM_OUTER;
|
||||
@ -129,7 +130,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
free(yuv);
|
||||
|
||||
char imgName[32];
|
||||
char imgName[35];
|
||||
sprintf(imgName, "/DCIM/100DSI00/IMG_%04d.PNG", getImageNumber());
|
||||
lodepng_encode24_file(imgName, rgb, 640, 480);
|
||||
free(rgb);
|
||||
|
@ -1,11 +1,11 @@
|
||||
#ifndef FIFOVARS_H
|
||||
#define FIFOVARS_H
|
||||
#ifndef PXIVARS_H
|
||||
#define PXIVARS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FIFO_CAMERA FIFO_USER_01
|
||||
#define PXI_CAMERA PxiChannel_User0
|
||||
|
||||
typedef enum {
|
||||
CAM_INIT,
|
||||
@ -15,7 +15,7 @@ typedef enum {
|
||||
CAM1_DEACTIVATE,
|
||||
CAM_SET_MODE_PREVIEW,
|
||||
CAM_SET_MODE_CAPTURE
|
||||
} FifoCommand;
|
||||
} PxiCommand;
|
||||
|
||||
typedef enum {
|
||||
CAPTURE_MODE_PREVIEW = 1, // 256x192
|
||||
@ -26,4 +26,4 @@ typedef enum {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // FIFOVARS_H
|
||||
#endif // PXIVARS_H
|
Loading…
Reference in New Issue
Block a user