kopia lustrzana https://github.com/DL7AD/pecanpico9
Added voltage change when using OV5640
Added I2C Lock around voltage change methods Implemented RBAT sleep methods Fixed I2C init problem, reordered initialization methodsDevelop
rodzic
6da0be4483
commit
ea793f8d11
|
@ -10,6 +10,7 @@
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "ssdv.h"
|
#include "ssdv.h"
|
||||||
|
#include "padc.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct regval_list {
|
struct regval_list {
|
||||||
|
@ -741,6 +742,7 @@ static bool analyze_image(uint8_t *image, uint32_t image_len)
|
||||||
uint8_t pkt[SSDV_PKT_SIZE];
|
uint8_t pkt[SSDV_PKT_SIZE];
|
||||||
uint8_t *b;
|
uint8_t *b;
|
||||||
uint32_t bi = 0;
|
uint32_t bi = 0;
|
||||||
|
uint16_t i = 0;
|
||||||
uint8_t c = SSDV_OK;
|
uint8_t c = SSDV_OK;
|
||||||
|
|
||||||
ssdv_enc_init(&ssdv, SSDV_TYPE_NORMAL, "", 0, 7);
|
ssdv_enc_init(&ssdv, SSDV_TYPE_NORMAL, "", 0, 7);
|
||||||
|
@ -755,7 +757,7 @@ static bool analyze_image(uint8_t *image, uint32_t image_len)
|
||||||
bi += r;
|
bi += r;
|
||||||
if(r <= 0)
|
if(r <= 0)
|
||||||
{
|
{
|
||||||
TRACE_ERROR("CAM > Error in image");
|
TRACE_ERROR("CAM > Error in image (Premature end of file %d)", i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ssdv_enc_feed(&ssdv, b, r);
|
ssdv_enc_feed(&ssdv, b, r);
|
||||||
|
@ -766,10 +768,11 @@ static bool analyze_image(uint8_t *image, uint32_t image_len)
|
||||||
|
|
||||||
if(c != SSDV_OK) // Error in JPEG image
|
if(c != SSDV_OK) // Error in JPEG image
|
||||||
{
|
{
|
||||||
TRACE_ERROR("CAM > Error in image");
|
TRACE_ERROR("CAM > Error in image (ssdv_enc_get_packet failed: %d %d)", c, i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
chThdSleepMilliseconds(5);
|
chThdSleepMilliseconds(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1275,6 +1278,11 @@ void OV5640_SetResolution(resolution_t res)
|
||||||
|
|
||||||
void OV5640_init(void)
|
void OV5640_init(void)
|
||||||
{
|
{
|
||||||
|
// The camera need 3V for communication
|
||||||
|
#if !ACTIVATE_3V
|
||||||
|
boost_voltage(true);
|
||||||
|
#endif
|
||||||
|
|
||||||
TRACE_INFO("CAM > Init pins");
|
TRACE_INFO("CAM > Init pins");
|
||||||
OV5640_InitGPIO();
|
OV5640_InitGPIO();
|
||||||
|
|
||||||
|
@ -1294,6 +1302,10 @@ void OV5640_init(void)
|
||||||
|
|
||||||
void OV5640_deinit(void)
|
void OV5640_deinit(void)
|
||||||
{
|
{
|
||||||
|
#if !ACTIVATE_3V
|
||||||
|
boost_voltage(false);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Power off OV5640
|
// Power off OV5640
|
||||||
TRACE_INFO("CAM > Switch off");
|
TRACE_INFO("CAM > Switch off");
|
||||||
|
|
||||||
|
@ -1317,6 +1329,11 @@ void OV5640_deinit(void)
|
||||||
|
|
||||||
bool OV5640_isAvailable(void)
|
bool OV5640_isAvailable(void)
|
||||||
{
|
{
|
||||||
|
// The camera need 3V for communication
|
||||||
|
#if !ACTIVATE_3V
|
||||||
|
boost_voltage(true);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Configure pins
|
// Configure pins
|
||||||
OV5640_InitGPIO();
|
OV5640_InitGPIO();
|
||||||
|
|
||||||
|
@ -1328,13 +1345,16 @@ bool OV5640_isAvailable(void)
|
||||||
|
|
||||||
uint8_t val, val2;
|
uint8_t val, val2;
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
if(I2C_read8_16bitreg(OV5640_I2C_ADR, 0x300A, &val) && I2C_read8_16bitreg(OV5640_I2C_ADR, 0x300B, &val2)) {
|
if(I2C_read8_16bitreg(OV5640_I2C_ADR, 0x300A, &val) && I2C_read8_16bitreg(OV5640_I2C_ADR, 0x300B, &val2)) {
|
||||||
ret = val == 0x56 && val2 == 0x40;
|
ret = val == 0x56 && val2 == 0x40;
|
||||||
} else {
|
} else {
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !ACTIVATE_3V
|
||||||
|
boost_voltage(false);
|
||||||
|
#endif
|
||||||
|
|
||||||
palClearLine(LINE_CAM_EN); // Switch off camera
|
palClearLine(LINE_CAM_EN); // Switch off camera
|
||||||
palSetLineMode(LINE_CAM_RESET, PAL_MODE_INPUT); // CAM_RESET
|
palSetLineMode(LINE_CAM_RESET, PAL_MODE_INPUT); // CAM_RESET
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "padc.h"
|
#include "padc.h"
|
||||||
#include "pac1720.h"
|
#include "pac1720.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "pi2c.h"
|
||||||
|
|
||||||
#define ADC_NUM_CHANNELS 4 /* Amount of channels (solar, battery, temperature) */
|
#define ADC_NUM_CHANNELS 4 /* Amount of channels (solar, battery, temperature) */
|
||||||
#define VCC_REF_LOW 1850 /* mV */
|
#define VCC_REF_LOW 1850 /* mV */
|
||||||
|
@ -117,6 +118,8 @@ uint16_t getSTM32Temperature(void)
|
||||||
|
|
||||||
void boost_voltage(bool boost)
|
void boost_voltage(bool boost)
|
||||||
{
|
{
|
||||||
|
I2C_Lock();
|
||||||
|
|
||||||
if(boost)
|
if(boost)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -133,5 +136,8 @@ void boost_voltage(bool boost)
|
||||||
vcc_ref = VCC_REF_LOW;
|
vcc_ref = VCC_REF_LOW;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chThdSleepMilliseconds(1);
|
||||||
|
I2C_Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,13 +18,13 @@ bool p_sleep(const sleep_conf_t *config)
|
||||||
return getBatteryVoltageMV() < config->vbat_thres;
|
return getBatteryVoltageMV() < config->vbat_thres;
|
||||||
|
|
||||||
case SLEEP_WHEN_RBAT_BELOW_THRES:
|
case SLEEP_WHEN_RBAT_BELOW_THRES:
|
||||||
return 0 < config->rbat_thres; // FIXME
|
return getLastTrackPoint()->adc_rbat < config->rbat_thres; // FIXME
|
||||||
|
|
||||||
case SLEEP_WHEN_VBAT_ABOVE_THRES:
|
case SLEEP_WHEN_VBAT_ABOVE_THRES:
|
||||||
return getBatteryVoltageMV() > config->vbat_thres;
|
return getBatteryVoltageMV() > config->vbat_thres;
|
||||||
|
|
||||||
case SLEEP_WHEN_RBAT_ABOVE_THRES:
|
case SLEEP_WHEN_RBAT_ABOVE_THRES:
|
||||||
return 0 > config->rbat_thres; // FIXME
|
return getLastTrackPoint()->adc_rbat > config->rbat_thres; // FIXME
|
||||||
|
|
||||||
case SLEEP_WHEN_DISCHARGING:
|
case SLEEP_WHEN_DISCHARGING:
|
||||||
case SLEEP_WHEN_CHARGING:
|
case SLEEP_WHEN_CHARGING:
|
||||||
|
|
|
@ -10,13 +10,9 @@
|
||||||
systime_t watchdog_tracking;
|
systime_t watchdog_tracking;
|
||||||
|
|
||||||
void start_essential_threads(void) {
|
void start_essential_threads(void) {
|
||||||
// Init watchdog
|
init_watchdog(); // Init watchdog
|
||||||
init_watchdog();
|
pi2cInit(); // Initialize I2C
|
||||||
|
pac1720_init(); // Initialize current measurement
|
||||||
// Initialize tracking manager (without GPS, GPS is initialized if needed by position thread)
|
init_tracking_manager(false); // Initialize tracking manager (without GPS, GPS is initialized if needed by position thread)
|
||||||
init_tracking_manager(false);
|
|
||||||
|
|
||||||
pi2cInit(); // Initialize I2C
|
|
||||||
pac1720_init(); // Initialize current measurement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ THD_FUNCTION(trackingThread, arg) {
|
||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
uint32_t id = 1;
|
uint32_t id = 1;
|
||||||
lastTrackPoint = &trackPoints[0]; // FIXME: That might not work
|
lastTrackPoint = &trackPoints[0];
|
||||||
|
|
||||||
// Fill initial values by PAC1720 and BME280 and RTC
|
// Fill initial values by PAC1720 and BME280 and RTC
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue