Skip to content

Commit

Permalink
merge master to unofficial targets
Browse files Browse the repository at this point in the history
  • Loading branch information
sensei-hacker committed Oct 4, 2023
1 parent 7f21cfa commit 21b36be
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/main/build/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ typedef enum {
DEBUG_AUTOTUNE,
DEBUG_RATE_DYNAMICS,
DEBUG_LANDING,
DEBUG_POS_EST,
DEBUG_COUNT
} debugType_e;
10 changes: 10 additions & 0 deletions src/main/common/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

#include "fc/settings.h"

#ifdef SITL_BUILD
#include <time.h>
#endif

// For the "modulo 4" arithmetic to work, we need a leap base year
#define REFERENCE_YEAR 2000
// Offset (seconds) from the UNIX epoch (1970-01-01) to 2000-01-01
Expand Down Expand Up @@ -310,11 +314,16 @@ bool rtcHasTime(void)

bool rtcGet(rtcTime_t *t)
{
#ifdef SITL_BUILD
*t = (rtcTime_t)(time(NULL) * 1000);
return true;
#else
if (!rtcHasTime()) {
return false;
}
*t = started + millis();
return true;
#endif
}

bool rtcSet(rtcTime_t *t)
Expand All @@ -323,6 +332,7 @@ bool rtcSet(rtcTime_t *t)
return true;
}


bool rtcGetDateTime(dateTime_t *dt)
{
rtcTime_t t;
Expand Down
4 changes: 4 additions & 0 deletions src/main/config/config_streamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ int config_streamer_flush(config_streamer_t *c);

int config_streamer_finish(config_streamer_t *c);
int config_streamer_status(config_streamer_t *c);

#if defined(CONFIG_IN_FILE)
bool configFileSetPath(char* path);
#endif
36 changes: 23 additions & 13 deletions src/main/config/config_streamer_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include <string.h>
#include <dirent.h>
#include "platform.h"
#include "drivers/system.h"
#include "config/config_streamer.h"
Expand All @@ -26,21 +27,32 @@
#include <stdio.h>
#include <errno.h>


#define FLASH_PAGE_SIZE (0x400)

static FILE *eepromFd = NULL;

static bool streamerLocked = true;
static char eepromPath[260] = EEPROM_FILENAME;

bool configFileSetPath(char* path)
{
if(!path || strlen(path) > 260) {
return false;
}

strcpy(eepromPath, path);
return true;
}

void config_streamer_impl_unlock(void)
{
if (eepromFd != NULL) {
fprintf(stderr, "[EEPROM] Unable to load %s\n", EEPROM_FILENAME);
fprintf(stderr, "[EEPROM] Unable to load %s\n", eepromPath);
return;
}

// open or create
eepromFd = fopen(EEPROM_FILENAME,"r+");
eepromFd = fopen(eepromPath,"r+");
if (eepromFd != NULL) {
// obtain file size:
fseek(eepromFd , 0 , SEEK_END);
Expand All @@ -49,25 +61,23 @@ void config_streamer_impl_unlock(void)

size_t n = fread(eepromData, 1, sizeof(eepromData), eepromFd);
if (n == size) {
printf("[EEPROM] Loaded '%s' (%ld of %ld bytes)\n", EEPROM_FILENAME, size, sizeof(eepromData));
fprintf(stderr,"[EEPROM] Loaded '%s' (%ld of %ld bytes)\n", eepromPath, size, sizeof(eepromData));
streamerLocked = false;
} else {
fprintf(stderr, "[EEPROM] Failed to load '%s'\n", EEPROM_FILENAME);
fprintf(stderr, "[EEPROM] Failed to load '%s'\n", eepromPath);
}
} else {
printf("[EEPROM] Created '%s', size = %ld\n", EEPROM_FILENAME, sizeof(eepromData));
printf("[EEPROM] Created '%s', size = %ld\n", eepromPath, sizeof(eepromData));
streamerLocked = false;
if ((eepromFd = fopen(EEPROM_FILENAME, "w+")) == NULL) {
fprintf(stderr, "[EEPROM] Failed to create '%s'\n", EEPROM_FILENAME);
if ((eepromFd = fopen(eepromPath, "w+")) == NULL) {
fprintf(stderr, "[EEPROM] Failed to create '%s'\n", eepromPath);
streamerLocked = true;
}
if (fwrite(eepromData, sizeof(eepromData), 1, eepromFd) != 1) {
fprintf(stderr, "[EEPROM] Write failed: %s\n", strerror(errno));
streamerLocked = true;
}
}


}

void config_streamer_impl_lock(void)
Expand All @@ -78,7 +88,7 @@ void config_streamer_impl_lock(void)
fwrite(eepromData, 1, sizeof(eepromData), eepromFd);
fclose(eepromFd);
eepromFd = NULL;
printf("[EEPROM] Saved '%s'\n", EEPROM_FILENAME);
fprintf(stderr, "[EEPROM] Saved '%s'\n", eepromPath);
streamerLocked = false;
} else {
fprintf(stderr, "[EEPROM] Unlock error\n");
Expand All @@ -93,9 +103,9 @@ int config_streamer_impl_write_word(config_streamer_t *c, config_streamer_buffer

if ((c->address >= (uintptr_t)eepromData) && (c->address < (uintptr_t)ARRAYEND(eepromData))) {
*((uint32_t*)c->address) = *buffer;
printf("[EEPROM] Program word %p = %08x\n", (void*)c->address, *((uint32_t*)c->address));
fprintf(stderr, "[EEPROM] Program word %p = %08x\n", (void*)c->address, *((uint32_t*)c->address));
} else {
printf("[EEPROM] Program word %p out of range!\n", (void*)c->address);
fprintf(stderr, "[EEPROM] Program word %p out of range!\n", (void*)c->address);
}

c->address += CONFIG_STREAMER_BUFFER_SIZE;
Expand Down
4 changes: 0 additions & 4 deletions src/main/drivers/accgyro/accgyro_mpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

#include "drivers/sensor.h"
#include "drivers/accgyro/accgyro.h"
#define MPU_I2C_ADDRESS 0x68

// MPU6050
#define MPU_RA_WHO_AM_I_LEGACY 0x00
#define MPUx0x0_WHO_AM_I_CONST (0x68) // MPU6000 and 6050
#define MPU6000_WHO_AM_I_CONST (0x68)
#define MPU6500_WHO_AM_I_CONST (0x70)
#define MPU9250_WHO_AM_I_CONST (0x71)
Expand Down
1 change: 0 additions & 1 deletion src/main/drivers/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ typedef enum {

/* Combined ACC/GYRO chips */
DEVHW_MPU6000,
DEVHW_MPU6050,
DEVHW_MPU6500,
DEVHW_BMI160,
DEVHW_BMI088_GYRO,
Expand Down
1 change: 0 additions & 1 deletion src/main/sensors/acceleration.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
typedef enum {
ACC_NONE = 0,
ACC_AUTODETECT,
ACC_MPU6050,
ACC_MPU6000,
ACC_MPU6500,
ACC_MPU9250,
Expand Down
10 changes: 0 additions & 10 deletions src/main/sensors/gyro.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "drivers/accgyro/accgyro.h"
#include "drivers/accgyro/accgyro_mpu.h"
#include "drivers/accgyro/accgyro_mpu6000.h"
#include "drivers/accgyro/accgyro_mpu6050.h"
#include "drivers/accgyro/accgyro_mpu6500.h"
#include "drivers/accgyro/accgyro_mpu9250.h"

Expand Down Expand Up @@ -135,15 +134,6 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev, gyroSensor_e gyroHard
switch (gyroHardware) {
case GYRO_AUTODETECT:
FALLTHROUGH;

#ifdef USE_IMU_MPU6050
case GYRO_MPU6050:
if (mpu6050GyroDetect(dev)) {
gyroHardware = GYRO_MPU6050;
break;
}
FALLTHROUGH;
#endif

#ifdef USE_IMU_MPU6000
case GYRO_MPU6000:
Expand Down
1 change: 0 additions & 1 deletion src/main/sensors/gyro.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
typedef enum {
GYRO_NONE = 0,
GYRO_AUTODETECT,
GYRO_MPU6050,
GYRO_MPU6000,
GYRO_MPU6500,
GYRO_MPU9250,
Expand Down

0 comments on commit 21b36be

Please sign in to comment.