Skip to content

Commit

Permalink
fixed low power function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Jackson committed Aug 1, 2024
1 parent a92c14a commit 5a92202
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/MSP430/Arducam_Mega/HardWare/arducam/Arducam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
55 changes: 52 additions & 3 deletions examples/MSP430/SmartCamera/HardWare/arducam/Arducam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}


Expand Down
8 changes: 8 additions & 0 deletions examples/MSP430/SmartCamera/HardWare/arducam/Arducam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/RaspberryPi/capture/Arducam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
36 changes: 36 additions & 0 deletions examples/Stm32/USER/DebugConfig/Target_1_STM32F103C8_1.0.0.dbgconf
Original file line number Diff line number Diff line change
@@ -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 >>>

// <h> Debug MCU configuration register (DBGMCU_CR)
// <i> Reserved bits must be kept at reset value
// <o.30> DBG_TIM11_STOP <i> TIM11 counter stopped when core is halted
// <o.29> DBG_TIM10_STOP <i> TIM10 counter stopped when core is halted
// <o.28> DBG_TIM9_STOP <i> TIM9 counter stopped when core is halted
// <o.27> DBG_TIM14_STOP <i> TIM14 counter stopped when core is halted
// <o.26> DBG_TIM13_STOP <i> TIM13 counter stopped when core is halted
// <o.25> DBG_TIM12_STOP <i> TIM12 counter stopped when core is halted
// <o.21> DBG_CAN2_STOP <i> Debug CAN2 stopped when core is halted
// <o.20> DBG_TIM7_STOP <i> TIM7 counter stopped when core is halted
// <o.19> DBG_TIM6_STOP <i> TIM6 counter stopped when core is halted
// <o.18> DBG_TIM5_STOP <i> TIM5 counter stopped when core is halted
// <o.17> DBG_TIM8_STOP <i> TIM8 counter stopped when core is halted
// <o.16> DBG_I2C2_SMBUS_TIMEOUT <i> SMBUS timeout mode stopped when core is halted
// <o.15> DBG_I2C1_SMBUS_TIMEOUT <i> SMBUS timeout mode stopped when core is halted
// <o.14> DBG_CAN1_STOP <i> Debug CAN1 stopped when Core is halted
// <o.13> DBG_TIM4_STOP <i> TIM4 counter stopped when core is halted
// <o.12> DBG_TIM3_STOP <i> TIM3 counter stopped when core is halted
// <o.11> DBG_TIM2_STOP <i> TIM2 counter stopped when core is halted
// <o.10> DBG_TIM1_STOP <i> TIM1 counter stopped when core is halted
// <o.9> DBG_WWDG_STOP <i> Debug window watchdog stopped when core is halted
// <o.8> DBG_IWDG_STOP <i> Debug independent watchdog stopped when core is halted
// <o.2> DBG_STANDBY <i> Debug standby mode
// <o.1> DBG_STOP <i> Debug stop mode
// <o.0> DBG_SLEEP <i> Debug sleep mode
// </h>
DbgMCU_CR = 0x00000007;

// <<< end of configuration section >>>
14 changes: 0 additions & 14 deletions examples/Stm32/USER/RTE/RTE_Components.h

This file was deleted.

9 changes: 4 additions & 5 deletions examples/Stm32/USER/SmartCamera.uvprojx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
<TargetName>Target 1</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5050106::V5.05 update 1 (build 106)::ARMCC</pCCUsed>
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>
<Device>STM32F103C8</Device>
<Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F1xx_DFP.1.0.5</PackID>
<PackID>Keil.STM32F1xx_DFP.2.3.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x5000) IROM(0x08000000,0x10000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec>
Expand Down Expand Up @@ -134,11 +134,11 @@
<RunIndependent>0</RunIndependent>
<UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
<Capability>1</Capability>
<DriverSelection>4101</DriverSelection>
<DriverSelection>4096</DriverSelection>
</Flash1>
<bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3></Flash3>
<Flash3>"" ()</Flash3>
<Flash4></Flash4>
<pFcarmOut></pFcarmOut>
<pFcarmGrp></pFcarmGrp>
Expand Down Expand Up @@ -186,7 +186,6 @@
<RvdsVP>0</RvdsVP>
<RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<nBranchProt>0</nBranchProt>
<hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Arducam_Mega
version=2.0.11
version=2.0.12
author=Arducam <[email protected]>
maintainer=Arducam<[email protected]>
sentence=Examples of spi cameras used on different hardware.
Expand Down
71 changes: 66 additions & 5 deletions src/Arducam/ArducamCamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
}

Expand All @@ -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)
Expand Down

0 comments on commit 5a92202

Please sign in to comment.