From 5a92202303b036c6e36df6b21328158e8d702cd7 Mon Sep 17 00:00:00 2001 From: Lee Jackson Date: Thu, 1 Aug 2024 19:16:09 +0800 Subject: [PATCH] fixed low power function --- .../Arducam_Mega/HardWare/arducam/Arducam.c | 2 +- .../SmartCamera/HardWare/arducam/Arducam.c | 55 +++++++++++++- .../SmartCamera/HardWare/arducam/Arducam.h | 8 +++ examples/RaspberryPi/capture/Arducam.c | 2 +- .../Target_1_STM32F103C8_1.0.0.dbgconf | 36 ++++++++++ examples/Stm32/USER/RTE/RTE_Components.h | 14 ---- examples/Stm32/USER/SmartCamera.uvprojx | 9 ++- .../src/libcamera/ArducamCamera.c | 2 +- library.properties | 2 +- src/Arducam/ArducamCamera.c | 71 +++++++++++++++++-- 10 files changed, 170 insertions(+), 31 deletions(-) create mode 100644 examples/Stm32/USER/DebugConfig/Target_1_STM32F103C8_1.0.0.dbgconf delete mode 100644 examples/Stm32/USER/RTE/RTE_Components.h diff --git a/examples/MSP430/Arducam_Mega/HardWare/arducam/Arducam.c b/examples/MSP430/Arducam_Mega/HardWare/arducam/Arducam.c index a4592c8..33852f8 100644 --- a/examples/MSP430/Arducam_Mega/HardWare/arducam/Arducam.c +++ b/examples/MSP430/Arducam_Mega/HardWare/arducam/Arducam.c @@ -569,7 +569,7 @@ void cameraWaitI2cIdle(ArducamCamera*camera) { while ((readReg(camera,CAM_REG_SENSOR_STATE)&0X03) != CAM_REG_SENSOR_STATE_IDLE) { - arducamDelayMs(2); + ;//arducamDelayMs(2); } } diff --git a/examples/MSP430/SmartCamera/HardWare/arducam/Arducam.c b/examples/MSP430/SmartCamera/HardWare/arducam/Arducam.c index a4592c8..132b020 100644 --- a/examples/MSP430/SmartCamera/HardWare/arducam/Arducam.c +++ b/examples/MSP430/SmartCamera/HardWare/arducam/Arducam.c @@ -67,6 +67,7 @@ #define CAM_REG_DEBUG_REGISTER_HIGH 0X0B #define CAM_REG_DEBUG_REGISTER_LOW 0X0C #define CAM_REG_DEBUG_REGISTER_VALUE 0X0D +#define CAM_REG_DEBUG_REGISTER_VALUE_L 0X0E #define CAM_REG_SENSOR_STATE_IDLE (1<<1) #define CAM_SENSOR_RESET_ENABLE (1<<6) @@ -569,7 +570,7 @@ void cameraWaitI2cIdle(ArducamCamera*camera) { while ((readReg(camera,CAM_REG_SENSOR_STATE)&0X03) != CAM_REG_SENSOR_STATE_IDLE) { - arducamDelayMs(2); + ;//arducamDelayMs(2); } } @@ -588,12 +589,60 @@ void cameraDebugWriteRegister(ArducamCamera* camera,uint8_t* buff) void cameraLowPowerOn(ArducamCamera*camera) { - writeReg(camera,CAM_REG_POWER_CONTROL,0X07); + if((camera->cameraId == SENSOR_5MP_2) ||(camera->cameraId == SENSOR_3MP_2 ) ){ + uint16_t reg1 = 0x0028; + uint16_t data1 = 0xD000; + uint16_t reg2 = 0x002A; + uint16_t data2 = 0x107E; + uint16_t reg3 = 0x0F12; + uint16_t data3 = 0x0001; + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg1>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg1)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data1>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data1)&0xFF); waitI2cIdle(camera); + + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg2>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg2)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data2>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data2)&0xFF); waitI2cIdle(camera); + + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg3>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg3)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data3>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data3)&0xFF); waitI2cIdle(camera); + + }else{ + writeReg(camera, CAM_REG_POWER_CONTROL, 0X07); + } } void cameraLowPowerOff(ArducamCamera*camera) { - writeReg(camera,CAM_REG_POWER_CONTROL,0X05); + if((camera->cameraId == SENSOR_5MP_2) ||(camera->cameraId == SENSOR_3MP_2 ) ){ + uint16_t reg1 = 0x0028; + uint16_t data1 = 0xD000; + uint16_t reg2 = 0x002A; + uint16_t data2 = 0x107E; + uint16_t reg3 = 0x0F12; + uint16_t data3 = 0x0000; + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg1>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg1)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data1>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data1)&0xFF); waitI2cIdle(camera); + + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg2>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg2)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data2>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data2)&0xFF); waitI2cIdle(camera); + + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg3>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg3)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data3>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data3)&0xFF); waitI2cIdle(camera); + + }else{ + writeReg(camera, CAM_REG_POWER_CONTROL, 0X05); + } } diff --git a/examples/MSP430/SmartCamera/HardWare/arducam/Arducam.h b/examples/MSP430/SmartCamera/HardWare/arducam/Arducam.h index dc0fe5b..a88f868 100644 --- a/examples/MSP430/SmartCamera/HardWare/arducam/Arducam.h +++ b/examples/MSP430/SmartCamera/HardWare/arducam/Arducam.h @@ -163,6 +163,14 @@ typedef enum { }CAM_SHARPNESS_LEVEL; + +enum { + SENSOR_5MP_1 = 0x81, + SENSOR_3MP_1 = 0x82, + SENSOR_5MP_2 = 0x83, /* 2592x1936 */ + SENSOR_3MP_2 = 0x84, +}; + /** * @enum CAM_VIDEO_MODE * @brief Configure resolution in video streaming mode diff --git a/examples/RaspberryPi/capture/Arducam.c b/examples/RaspberryPi/capture/Arducam.c index a547ec9..bc2689d 100644 --- a/examples/RaspberryPi/capture/Arducam.c +++ b/examples/RaspberryPi/capture/Arducam.c @@ -563,7 +563,7 @@ void cameraWaitI2cIdle(ArducamCamera*MyCamera) { while ((readReg(MyCamera,CAM_REG_SENSOR_STATE)&0X03) != CAM_REG_SENSOR_STATE_IDLE) { - arducamDelayMs(2); + ;//arducamDelayMs(2); } } diff --git a/examples/Stm32/USER/DebugConfig/Target_1_STM32F103C8_1.0.0.dbgconf b/examples/Stm32/USER/DebugConfig/Target_1_STM32F103C8_1.0.0.dbgconf new file mode 100644 index 0000000..66e10b6 --- /dev/null +++ b/examples/Stm32/USER/DebugConfig/Target_1_STM32F103C8_1.0.0.dbgconf @@ -0,0 +1,36 @@ +// File: STM32F101_102_103_105_107.dbgconf +// Version: 1.0.0 +// Note: refer to STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx Reference manual (RM0008) +// STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx datasheets + +// <<< Use Configuration Wizard in Context Menu >>> + +// Debug MCU configuration register (DBGMCU_CR) +// Reserved bits must be kept at reset value +// DBG_TIM11_STOP TIM11 counter stopped when core is halted +// DBG_TIM10_STOP TIM10 counter stopped when core is halted +// DBG_TIM9_STOP TIM9 counter stopped when core is halted +// DBG_TIM14_STOP TIM14 counter stopped when core is halted +// DBG_TIM13_STOP TIM13 counter stopped when core is halted +// DBG_TIM12_STOP TIM12 counter stopped when core is halted +// DBG_CAN2_STOP Debug CAN2 stopped when core is halted +// DBG_TIM7_STOP TIM7 counter stopped when core is halted +// DBG_TIM6_STOP TIM6 counter stopped when core is halted +// DBG_TIM5_STOP TIM5 counter stopped when core is halted +// DBG_TIM8_STOP TIM8 counter stopped when core is halted +// DBG_I2C2_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted +// DBG_I2C1_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted +// DBG_CAN1_STOP Debug CAN1 stopped when Core is halted +// DBG_TIM4_STOP TIM4 counter stopped when core is halted +// DBG_TIM3_STOP TIM3 counter stopped when core is halted +// DBG_TIM2_STOP TIM2 counter stopped when core is halted +// DBG_TIM1_STOP TIM1 counter stopped when core is halted +// DBG_WWDG_STOP Debug window watchdog stopped when core is halted +// DBG_IWDG_STOP Debug independent watchdog stopped when core is halted +// DBG_STANDBY Debug standby mode +// DBG_STOP Debug stop mode +// DBG_SLEEP Debug sleep mode +// +DbgMCU_CR = 0x00000007; + +// <<< end of configuration section >>> diff --git a/examples/Stm32/USER/RTE/RTE_Components.h b/examples/Stm32/USER/RTE/RTE_Components.h deleted file mode 100644 index cd2e60f..0000000 --- a/examples/Stm32/USER/RTE/RTE_Components.h +++ /dev/null @@ -1,14 +0,0 @@ - -/* - * Auto generated Run-Time-Environment Component Configuration File - * *** Do not modify ! *** - * - * Project: 'SmartCamera' - * Target: 'Target 1' - */ - -#ifndef RTE_COMPONENTS_H -#define RTE_COMPONENTS_H - - -#endif /* RTE_COMPONENTS_H */ diff --git a/examples/Stm32/USER/SmartCamera.uvprojx b/examples/Stm32/USER/SmartCamera.uvprojx index 0e2702b..9425d52 100644 --- a/examples/Stm32/USER/SmartCamera.uvprojx +++ b/examples/Stm32/USER/SmartCamera.uvprojx @@ -10,13 +10,13 @@ Target 1 0x4 ARM-ADS - 5050106::V5.05 update 1 (build 106)::ARMCC + 5060960::V5.06 update 7 (build 960)::.\ARMCC 0 STM32F103C8 STMicroelectronics - Keil.STM32F1xx_DFP.1.0.5 + Keil.STM32F1xx_DFP.2.3.0 http://www.keil.com/pack/ IRAM(0x20000000,0x5000) IROM(0x08000000,0x10000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE @@ -134,11 +134,11 @@ 0 1 1 - 4101 + 4096 1 BIN\UL2CM3.DLL - + "" () @@ -186,7 +186,6 @@ 0 0 0 - 0 0 0 8 diff --git a/examples/renesas/EK-RA6M4_arducam_mega/src/libcamera/ArducamCamera.c b/examples/renesas/EK-RA6M4_arducam_mega/src/libcamera/ArducamCamera.c index b26e82c..ec5bad2 100644 --- a/examples/renesas/EK-RA6M4_arducam_mega/src/libcamera/ArducamCamera.c +++ b/examples/renesas/EK-RA6M4_arducam_mega/src/libcamera/ArducamCamera.c @@ -660,7 +660,7 @@ uint8_t cameraBusRead(ArducamCamera* camera, uint8_t address) void cameraWaitI2cIdle(ArducamCamera* camera) { while ((readReg(camera, CAM_REG_SENSOR_STATE) & 0X03) != CAM_REG_SENSOR_STATE_IDLE) { - arducamDelayMs(2); + // arducamDelayMs(2); } } diff --git a/library.properties b/library.properties index b02f9ec..411f677 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arducam_Mega -version=2.0.11 +version=2.0.12 author=Arducam maintainer=Arducam sentence=Examples of spi cameras used on different hardware. diff --git a/src/Arducam/ArducamCamera.c b/src/Arducam/ArducamCamera.c index adb0e68..babb9ad 100644 --- a/src/Arducam/ArducamCamera.c +++ b/src/Arducam/ArducamCamera.c @@ -77,6 +77,7 @@ #define CAM_REG_DEBUG_REGISTER_HIGH 0X0B #define CAM_REG_DEBUG_REGISTER_LOW 0X0C #define CAM_REG_DEBUG_REGISTER_VALUE 0X0D +#define CAM_REG_DEBUG_REGISTER_VALUE_H 0X0E #define CAM_I2C_READ_MODE (1 << 0) #define CAM_REG_SENSOR_STATE_IDLE (1 << 1) @@ -125,7 +126,7 @@ union SdkInfo currentSDK = { .sdkInfo.year = 24, .sdkInfo.month = 6, .sdkInfo.day = 18, - .sdkInfo.version = 0x020B, //V2.0.11 H bit[11:8] M bit[7:4] L bit[3:0] + .sdkInfo.version = 0x020C, //V2.0.11 H bit[11:8] M bit[7:4] L bit[3:0] }; struct cameraDefaultState { @@ -200,6 +201,15 @@ uint8_t ov3640GainValue[] = {0x00, 0x10, 0x18, 0x30, 0x34, 0x38, 0x3b, 0x3f, 0x7 0x78, 0x7a, 0x7c, 0x7e, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}; +void updateCameraInfo(ArducamCamera* camera){ + if(camera->cameraId == SENSOR_5MP_2 || camera->cameraId == SENSOR_3MP_2){ + camera->myCameraInfo.exposureValueMax = 0xFFFF; + camera->myCameraInfo.gainValueMax = 0xFFFF; + + } + +} + void cameraInit(ArducamCamera* camera) { arducamSpiBegin(); @@ -235,6 +245,7 @@ CamStatus cameraBegin(ArducamCamera* camera) writeReg(camera, CAM_REG_SENSOR_RESET, CAM_SENSOR_RESET_ENABLE); waitI2cIdle(camera); // Wait I2c Idle cameraGetSensorConfig(camera); + updateCameraInfo(camera); camera->verDateAndNumber[0] = readReg(camera, CAM_REG_YEAR_ID) & 0x3F; // year waitI2cIdle(camera); camera->verDateAndNumber[1] = readReg(camera, CAM_REG_MONTH_ID) & 0x0F; // month @@ -642,7 +653,7 @@ uint8_t cameraBusWrite(ArducamCamera* camera, int address, int value) arducamSpiTransfer(address); arducamSpiTransfer(value); arducamSpiCsPinHigh(camera->csPin); - arducamDelayMs(1); + //arducamDelayMs(1); return 1; } @@ -669,7 +680,7 @@ uint8_t cameraBusRead(ArducamCamera* camera, int address) void cameraWaitI2cIdle(ArducamCamera* camera) { while ((readReg(camera, CAM_REG_SENSOR_STATE) & 0X03) != CAM_REG_SENSOR_STATE_IDLE) { - arducamDelayMs(2); + ;// arducamDelayMs(2); } } @@ -690,12 +701,62 @@ void cameraDebugWriteRegister(ArducamCamera* camera, uint8_t* buff) void cameraLowPowerOn(ArducamCamera* camera) { - writeReg(camera, CAM_REG_POWER_CONTROL, 0X07); + + if((camera->cameraId == SENSOR_5MP_2) ||(camera->cameraId == SENSOR_3MP_2 ) ){ + uint16_t reg1 = 0x0028; + uint16_t data1 = 0xD000; + uint16_t reg2 = 0x002A; + uint16_t data2 = 0x107E; + uint16_t reg3 = 0x0F12; + uint16_t data3 = 0x0001; + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg1>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg1)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data1>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data1)&0xFF); waitI2cIdle(camera); + + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg2>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg2)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data2>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data2)&0xFF); waitI2cIdle(camera); + + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg3>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg3)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data3>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data3)&0xFF); waitI2cIdle(camera); + + }else{ + writeReg(camera, CAM_REG_POWER_CONTROL, 0X07); + } + } void cameraLowPowerOff(ArducamCamera* camera) { - writeReg(camera, CAM_REG_POWER_CONTROL, 0X05); + if((camera->cameraId == SENSOR_5MP_2) ||(camera->cameraId == SENSOR_3MP_2 ) ){ + uint16_t reg1 = 0x0028; + uint16_t data1 = 0xD000; + uint16_t reg2 = 0x002A; + uint16_t data2 = 0x107E; + uint16_t reg3 = 0x0F12; + uint16_t data3 = 0x0000; + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg1>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg1)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data1>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data1)&0xFF); waitI2cIdle(camera); + + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg2>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg2)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data2>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data2)&0xFF); waitI2cIdle(camera); + + writeReg(camera, CAM_REG_DEBUG_REGISTER_HIGH, (reg3>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_LOW, (reg3)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE_H, (data3>>8)&0xFF); waitI2cIdle(camera); + writeReg(camera, CAM_REG_DEBUG_REGISTER_VALUE, (data3)&0xFF); waitI2cIdle(camera); + + }else{ + writeReg(camera, CAM_REG_POWER_CONTROL, 0X05); + } } CamStatus reset(ArducamCamera* camera)