diff --git a/build/libraries/i2c/ARM7/src/i2c_instruction.c b/build/libraries/i2c/ARM7/src/i2c_instruction.c index fdee45b..ffb83ae 100644 --- a/build/libraries/i2c/ARM7/src/i2c_instruction.c +++ b/build/libraries/i2c/ARM7/src/i2c_instruction.c @@ -1,5 +1,5 @@ /*---------------------------------------------------------------------------* - Project: TwlSDK - libraties - i2c + Project: TwlSDK - libralies - i2c File: i2c_instruction.c Copyright 2007 Nintendo. All rights reserved. @@ -10,7 +10,7 @@ not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. - $Log: I2C_.c,v $ + $Log: $ $NoKeywords: $ *---------------------------------------------------------------------------*/ #include @@ -28,7 +28,7 @@ #endif #ifdef PRINT_DEBUG_MINI #include -#define DBG_PRINT_FUNC() OS_TPrintf("%s(0x%02X, 0x%02X, ...);\n", __func__, I2C_DeviceAddrTable[id], reg) +#define DBG_PRINT_FUNC() OS_TPrintf("%s(0x%02X, 0x%02X, ...);\n", __func__, deviceAddrTable[id], reg) #define DBG_PRINT_ERR() OS_TPrintf(" Failed(%d) @ %d\n", error, r) #else #define DBG_PRINT_FUNC() ((void)0) @@ -37,17 +37,31 @@ #define RETRY_COUNT 8 -static u8 I2C_DeviceAddrTable[I2C_SLAVE_NUM] = { +static const u8 deviceAddrTable[I2C_SLAVE_NUM] = { I2C_ADDR_CODEC, I2C_ADDR_CAMERA_MICRON_IN, I2C_ADDR_CAMERA_MICRON_OUT, I2C_ADDR_CAMERA_SHARP_IN, I2C_ADDR_CAMERA_SHARP_OUT, - }; + I2C_ADDR_MICRO_CONTROLLER, + I2C_ADDR_DEBUG_LED, + }; + +/*static const*/ s32 I2CSlowRateTable[I2C_SLAVE_NUM] = { + 0, // CODEC + 0, // CAMERA_MICRON_IN + 0, // CAMERA_MICRON_OUT + 0, // CAMERA_SHARP_IN + 0, // CAMERA_SHARP_OUT + 0x90, // MICRO_CONTROLLER + 0, // DEBUG_LED + }; static OSMutex mutex; static BOOL isInitialized = FALSE; +static BOOL slowRate = 0; + static inline void I2Ci_Start( void ) { reg_EXI_I2CCNT = (u8)((1 << REG_EXI_I2CCNT_E_SHIFT) | @@ -89,6 +103,26 @@ static inline void I2Ci_StopPhase2( void ) (1 << REG_EXI_I2CCNT_NT_SHIFT)); } +static inline void I2Ci_WaitEx( void ) // support slowRate +{ + I2Ci_Wait(); + SVC_WaitByLoop(slowRate); +} + +static inline void I2Ci_StopEx( I2CReadWrite rw ) // support slowRate +{ + if (slowRate) + { + I2Ci_StopPhase1(rw); + I2Ci_Wait(); + SVC_WaitByLoop(slowRate); + I2Ci_StopPhase2(); + } + else + { + I2Ci_Stop(rw); + } +} static inline void I2Ci_SetData( u8 data ) { @@ -105,23 +139,23 @@ static inline u8 I2Ci_GetData( void ) static inline BOOL I2Ci_GetResult( void ) { - I2Ci_Wait(); + I2Ci_WaitEx(); DBG_PRINTF("%c", (reg_EXI_I2CCNT & REG_EXI_I2CCNT_ACK_MASK) ? '.' : '*'); return (BOOL)((reg_EXI_I2CCNT & REG_EXI_I2CCNT_ACK_MASK) >> REG_EXI_I2CCNT_ACK_SHIFT); } - static inline BOOL I2Ci_SendStart( I2CSlave id ) { DBG_PRINTF("\n"); + slowRate = I2CSlowRateTable[id]; I2Ci_Wait(); - I2Ci_SetData( (u8)(I2C_DeviceAddrTable[id] | (u8)I2C_WRITE) ); + I2Ci_SetData( (u8)(deviceAddrTable[id] | I2C_WRITE) ); I2Ci_Start(); return I2Ci_GetResult(); } static inline BOOL I2Ci_SendMiddle( u8 data ) { - I2Ci_Wait(); + I2Ci_WaitEx(); I2Ci_SetData( data ); I2Ci_Continue( I2C_WRITE ); return I2Ci_GetResult(); @@ -129,43 +163,43 @@ static inline BOOL I2Ci_SendMiddle( u8 data ) static inline BOOL I2Ci_SendLast( u8 data ) { - I2Ci_Wait(); + I2Ci_WaitEx(); I2Ci_SetData( data ); - I2Ci_Stop( I2C_WRITE ); + I2Ci_StopEx( I2C_WRITE ); return I2Ci_GetResult(); } static inline BOOL I2Ci_ReceiveStart( I2CSlave id ) { - I2Ci_Wait(); - I2Ci_SetData( (u8)(I2C_DeviceAddrTable[id] | I2C_READ) ); + I2Ci_WaitEx(); + I2Ci_SetData( (u8)(deviceAddrTable[id] | I2C_READ) ); I2Ci_Start(); return I2Ci_GetResult(); } static inline void I2Ci_ReceiveMiddle( void ) { - I2Ci_Wait(); + I2Ci_WaitEx(); I2Ci_Continue( I2C_READ ); } static inline void I2Ci_ReceiveLast( void ) { - I2Ci_Wait(); - I2Ci_Stop( I2C_READ ); + I2Ci_WaitEx(); + I2Ci_StopEx( I2C_READ ); } static inline u8 I2Ci_WaitReceiveMiddle( void ) { I2Ci_ReceiveMiddle(); - I2Ci_Wait(); + I2Ci_WaitEx(); return I2Ci_GetData(); } static inline u8 I2Ci_WaitReceiveLast( void ) { I2Ci_ReceiveLast(); - I2Ci_Wait(); + I2Ci_WaitEx(); return I2Ci_GetData(); } diff --git a/include/twl.h b/include/twl.h index 103c477..2ce919d 100644 --- a/include/twl.h +++ b/include/twl.h @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef SDK_DEBUGGER_KMC #include #endif // SDK_DEBUGGER_KMC diff --git a/include/twl/i2c/ARM7/i2c.h b/include/twl/i2c/ARM7/i2c.h index 1b13cc9..0d725c6 100644 --- a/include/twl/i2c/ARM7/i2c.h +++ b/include/twl/i2c/ARM7/i2c.h @@ -36,6 +36,8 @@ typedef enum I2C_SLAVE_CAMERA_MICRON_OUT, I2C_SLAVE_CAMERA_SHARP_IN, I2C_SLAVE_CAMERA_SHARP_OUT, + I2C_SLAVE_MICRO_CONTROLLER, + I2C_SLAVE_DEBUG_LED, I2C_SLAVE_NUM } I2CSlave; @@ -55,6 +57,8 @@ I2CReadWrite; #define I2C_ADDR_CAMERA_MICRON_OUT 0x78 // MICRON #define I2C_ADDR_CAMERA_SHARP_IN 0xE0 // SHARP #define I2C_ADDR_CAMERA_SHARP_OUT 0xA0 // SHARP +#define I2C_ADDR_MICRO_CONTROLLER 0x4A +#define I2C_ADDR_DEBUG_LED (0x20 << 1) //---------------------------------------------------------------- // subroutine definition diff --git a/include/twl/mcu.h b/include/twl/mcu.h new file mode 100644 index 0000000..9773b60 --- /dev/null +++ b/include/twl/mcu.h @@ -0,0 +1,25 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - include - MCU + File: mcu.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#ifndef TWL_MCU_H_ +#define TWL_MCU_H_ + +#ifdef SDK_ARM7 +#include +#endif + +/* TWL_MCU_H_ */ +#endif diff --git a/include/twl/mcu/ARM7/i2c.h b/include/twl/mcu/ARM7/i2c.h new file mode 100644 index 0000000..731f917 --- /dev/null +++ b/include/twl/mcu/ARM7/i2c.h @@ -0,0 +1,172 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - libraries - mcu + File: i2c.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#ifndef TWL_MCU_I2C_COMMON_H_ +#define TWL_MCU_I2C_COMMON_H_ + +#include +#include + +#ifdef _cplusplus +extern "C" { +#endif + +//================================================================================ +// I2C ACCESS +//================================================================================ +/*---------------------------------------------------------------------------* + Name: MCUi_WriteRegister + + Description: set value to decive register through I2C. + + Arguments: reg : decive register + data : value to be written + + Returns: None + *---------------------------------------------------------------------------*/ +static inline BOOL MCUi_WriteRegister( u8 reg, u8 data ) +{ + return I2Ci_WriteRegister( I2C_SLAVE_MICRO_CONTROLLER, reg, data ); +} +static inline BOOL MCU_WriteRegister( u8 reg, u8 data ) +{ + return I2C_WriteRegister( I2C_SLAVE_MICRO_CONTROLLER, reg, data ); +} + +/*---------------------------------------------------------------------------* + Name: MCUi_ReadRegister + + Description: get value from decive register through I2C. + + Arguments: reg : decive register + + Returns: value which is read from specified decive register + *---------------------------------------------------------------------------*/ +static inline u8 MCUi_ReadRegister( u8 reg ) +{ + return I2Ci_ReadRegister( I2C_SLAVE_MICRO_CONTROLLER, reg ); +} +static inline u8 MCU_ReadRegister( u8 reg ) +{ + return I2C_ReadRegister( I2C_SLAVE_MICRO_CONTROLLER, reg ); +} + +/*---------------------------------------------------------------------------* + Name: MCUi_WriteRegisters + + Description: set value to decive registers through I2C. + + Arguments: reg : decive register + bufp : data array to be written + size : data size + + Returns: None + *---------------------------------------------------------------------------*/ +static inline BOOL MCUi_WriteRegisters( u8 reg, const u8 *bufp, size_t size ) +{ + return I2Ci_WriteRegisters( I2C_SLAVE_MICRO_CONTROLLER, reg, bufp, size ); +} +static inline BOOL MCU_WriteRegisters( u8 reg, const u8 *bufp, size_t size ) +{ + return I2C_WriteRegisters( I2C_SLAVE_MICRO_CONTROLLER, reg, bufp, size ); +} + +/*---------------------------------------------------------------------------* + Name: MCUi_ReadRegisters + + Description: get value from decive registers through I2C. + + Arguments: reg : decive register + bufp : data array to be read + size : data size + + Returns: value which is read from specified decive register + *---------------------------------------------------------------------------*/ +static inline BOOL MCUi_ReadRegisters( u8 reg, u8 *bufp, size_t size ) +{ + return I2Ci_ReadRegisters( I2C_SLAVE_MICRO_CONTROLLER, reg, bufp, size ); +} +static inline BOOL MCU_ReadRegisters( u8 reg, u8 *bufp, size_t size ) +{ + return I2C_ReadRegisters( I2C_SLAVE_MICRO_CONTROLLER, reg, bufp, size ); +} + +//================================================================================ +// I2C BIT CONTROL +//================================================================================ +/*---------------------------------------------------------------------------* + Name: MCUi_SetParams + + Description: set control bit to device register + + Arguments: reg : device register + setBits : bits to set + maskBits : bits to mask + + Returns: None + *---------------------------------------------------------------------------*/ +static inline BOOL MCUi_SetParams( u8 reg, u8 setBits, u8 maskBits ) +{ + return I2Ci_SetParams( I2C_SLAVE_MICRO_CONTROLLER, reg, setBits, maskBits ); +} +static inline BOOL MCU_SetParams( u8 reg, u8 setBits, u8 maskBits ) +{ + return I2C_SetParams( I2C_SLAVE_MICRO_CONTROLLER, reg, setBits, maskBits ); +} + +/*---------------------------------------------------------------------------* + Name: MCUi_SetFlags + + Description: set control bit to device register + + Arguments: reg : device register + setBits : bits to set + + Returns: None + *---------------------------------------------------------------------------*/ +static inline BOOL MCUi_SetFlags( u8 reg, u8 setBits ) +{ + return MCUi_SetParams( reg, setBits, setBits ); +} +static inline BOOL MCU_SetFlags( u8 reg, u8 setBits ) +{ + return MCU_SetParams( reg, setBits, setBits ); +} + +/*---------------------------------------------------------------------------* + Name: MCUi_ClearFlags + + Description: clear control bit to device register + + Arguments: reg : device register + clrBits : bits to clear + + Returns: None + *---------------------------------------------------------------------------*/ +static inline BOOL MCUi_ClearFlags( u8 reg, u8 clrBits ) +{ + return MCUi_SetParams( reg, 0, clrBits ); +} +static inline BOOL MCU_ClearFlags( u8 reg, u8 clrBits ) +{ + return MCU_SetParams( reg, 0, clrBits ); +} + +#ifdef _cplusplus +} /* extern "C" */ +#endif + +/* TWL_MCU_I2C_COMMON_H_ */ +#endif diff --git a/include/twl/os.h b/include/twl/os.h index 7f341d3..c5b07e9 100644 --- a/include/twl/os.h +++ b/include/twl/os.h @@ -25,6 +25,8 @@ #ifdef SDK_ARM9 #include +#else +#include #endif // SDK_ARM9 #ifdef SDK_DEBUGGER_KMC diff --git a/include/twl/os/ARM7/debugLED.h b/include/twl/os/ARM7/debugLED.h new file mode 100644 index 0000000..73f2240 --- /dev/null +++ b/include/twl/os/ARM7/debugLED.h @@ -0,0 +1,31 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - OS - include + File: debugLED.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef TWL_OS_DEBUG_LED_H_ +#define TWL_OS_DEBUG_LED_H_ + +//#if PLATFORM == TS + +#include + +#define OS_InitDebugLED() I2C_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x03, 0x00) +#define OS_SetDebugLED(pattern) I2C_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, (pattern)) +#define OS_GetDebugLED() I2C_ReadRegister(I2C_SLAVE_DEBUG_LED, 0x01) + +//#endif // PLATFORM == TS + +/* TWL_OS_DEBUG_LED_H_ */ +#endif