Skip to content

Commit

Permalink
Run lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Mar 15, 2024
1 parent 73090e9 commit 60d7693
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 141 deletions.
18 changes: 9 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug",
"executable": "D:/Documents/GitHub/stm32-avionics/.pio/build/blink/firmware.elf",
"executable": "/home/matt/stm32-avionics/.pio/build/blink/firmware.elf",
"projectEnvName": "blink",
"toolchainBinDir": "C:/Users/matth/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"toolchainBinDir": "/home/matt/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart",
"svdPath": "C:/Users/matth/.platformio/platforms/atmelsam/misc/svd/ATSAMD21G18A.svd",
"svdPath": "/home/matt/.platformio/platforms/atmelsam/misc/svd/ATSAMD21G18A.svd",
"preLaunchTask": {
"type": "PlatformIO",
"task": "Pre-Debug"
Expand All @@ -185,21 +185,21 @@
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (skip Pre-Debug)",
"executable": "D:/Documents/GitHub/stm32-avionics/.pio/build/blink/firmware.elf",
"executable": "/home/matt/stm32-avionics/.pio/build/blink/firmware.elf",
"projectEnvName": "blink",
"toolchainBinDir": "C:/Users/matth/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"toolchainBinDir": "/home/matt/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart",
"svdPath": "C:/Users/matth/.platformio/platforms/atmelsam/misc/svd/ATSAMD21G18A.svd"
"svdPath": "/home/matt/.platformio/platforms/atmelsam/misc/svd/ATSAMD21G18A.svd"
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (without uploading)",
"executable": "D:/Documents/GitHub/stm32-avionics/.pio/build/blink/firmware.elf",
"executable": "/home/matt/stm32-avionics/.pio/build/blink/firmware.elf",
"projectEnvName": "blink",
"toolchainBinDir": "C:/Users/matth/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"toolchainBinDir": "/home/matt/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart",
"svdPath": "C:/Users/matth/.platformio/platforms/atmelsam/misc/svd/ATSAMD21G18A.svd",
"svdPath": "/home/matt/.platformio/platforms/atmelsam/misc/svd/ATSAMD21G18A.svd",
"loadMode": "manual"
}
]
Expand Down
26 changes: 15 additions & 11 deletions common/system/hardware_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,16 @@ static bool inSim = false;
static CircularBuffer_s *simRxBuffer = NULL;

void hm_hardwareInit() {

HAL_GPIO_WritePin(accelAdx375CsGpioPort[0], accelAdx375CsPin[0], GPIO_PIN_SET);
HAL_GPIO_WritePin(barometerMs5607CsGpioPort[0], barometerMs5607CsPin[0], GPIO_PIN_SET);
HAL_GPIO_WritePin(imuIcm42688CsGpioPort[0], imuIcm42688CsPin[0], GPIO_PIN_SET);
HAL_GPIO_WritePin(flashMb85rsxCsGpioPort[0], flashMb85rsxCsPin[0], GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_11, GPIO_PIN_SET);
HAL_Delay(10);
HAL_GPIO_WritePin(accelAdx375CsGpioPort[0], accelAdx375CsPin[0],
GPIO_PIN_SET);
HAL_GPIO_WritePin(barometerMs5607CsGpioPort[0], barometerMs5607CsPin[0],
GPIO_PIN_SET);
HAL_GPIO_WritePin(imuIcm42688CsGpioPort[0], imuIcm42688CsPin[0],
GPIO_PIN_SET);
HAL_GPIO_WritePin(flashMb85rsxCsGpioPort[0], flashMb85rsxCsPin[0],
GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_11, GPIO_PIN_SET);
HAL_Delay(10);

/* Accelerometers */
#if HAS_DEV(ACCEL_H3LIS331DL)
Expand Down Expand Up @@ -445,8 +448,8 @@ void hm_hardwareInit() {

#if HAS_DEV(MAG_LIS3MDL)
for (int i = 0; i < NUM_MAG_LIS3MDL; i++) {
hardwareStatusMag[FIRST_ID_MAG_LIS3MDL + i] = magLis3mdl[i].begin(
{imuIcm42688Hspi[0], GPIOB, GPIO_PIN_11});
hardwareStatusMag[FIRST_ID_MAG_LIS3MDL + i] =
magLis3mdl[i].begin({imuIcm42688Hspi[0], GPIOB, GPIO_PIN_11});
}
#endif

Expand Down Expand Up @@ -577,9 +580,10 @@ void hm_hardwareInit() {
HAL_GPIO_WritePin(radioTi915HgmGpioPort[i], radioTi915HgmPin[i],
GPIO_PIN_SET);
#else
// No CC1190 -- crank output power since no input power limits (and no cc1190 to protect)
// No CC1190 -- crank output power since no input power limits (and no
// cc1190 to protect)
tiRadio_setOutputPower(radioTi915 + 0, 15);
#endif // RADIO_TI_TYPE == RADIO_TI_TYPE_CC1200
#endif // RADIO_TI_TYPE == RADIO_TI_TYPE_CC1200
}
#endif // HAS_DEV(RADIO_TI_915)

Expand Down
6 changes: 4 additions & 2 deletions common/system/tasks/cli/task_cli_sense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ void CliTasks::sense() {
dtoa(float1, sizeof(float1), data->gpsData[i].generalData.hdop, 3);
snprintf(cliStr, sizeof(cliStr), "GPS %d hdop: %s\r\n", i, float1);
cli_send(cliStr);
snprintf(cliStr, sizeof(cliStr), "GPS %d sats (num): %u\r\n", i, data->gpsData[i].generalData.satsTracked);
snprintf(cliStr, sizeof(cliStr), "GPS %d sats (num): %u\r\n", i,
data->gpsData[i].generalData.satsTracked);
cli_send(cliStr);
snprintf(cliStr, sizeof(cliStr), "GPS %d fix quality: %u\r\n", i, data->gpsData[i].generalData.fixQuality);
snprintf(cliStr, sizeof(cliStr), "GPS %d fix quality: %u\r\n", i,
data->gpsData[i].generalData.fixQuality);
cli_send(cliStr);
}
#endif // HAS_DEV(GPS)
Expand Down
25 changes: 14 additions & 11 deletions common/utils/bit_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

#include <stdint.h>

#ifdef __cplusplus
#include <bit>
#include <algorithm>
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -27,19 +32,17 @@ uint16_t combine_to_u16(uint8_t high, uint8_t low);
#endif

#ifdef __cplusplus
#include <bit>
#include <algorithm>
namespace std {
template<std::integral T>
constexpr T byteswap(T value) noexcept
{
static_assert(std::has_unique_object_representations_v<T>,
"T may not have padding bits");
auto value_representation = std::bit_cast<std::array<std::byte, sizeof(T)>>(value);
std::ranges::reverse(value_representation);
return std::bit_cast<T>(value_representation);
}
template <std::integral T>
constexpr T byteswap(T value) noexcept {
static_assert(std::has_unique_object_representations_v<T>,
"T may not have padding bits");
auto value_representation =
std::bit_cast<std::array<std::byte, sizeof(T)>>(value);
std::ranges::reverse(value_representation);
return std::bit_cast<T>(value_representation);
}
} // namespace std
#endif

#endif // COMMON_UTILS_BIT_HELPER_H_
133 changes: 70 additions & 63 deletions stm32_projects/device_drivers/imu/accel_adx375.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#if HAS_DEV(ACCEL_ADX375)

struct RegisterAddress {
uint8_t address :6;
// if we want the read/write pointer to auto advance
bool multiByteRequest :1;
// set - request is a read. Reset - request is a write
bool isRead :1;
uint8_t address : 6;
// if we want the read/write pointer to auto advance
bool multiByteRequest : 1;
// set - request is a read. Reset - request is a write
bool isRead : 1;
};

#define REG_WHOAMI 0
Expand All @@ -26,73 +26,80 @@ struct RegisterAddress {
constexpr float ACCEL_SENSITIVITY = 20.5 / G_TO_MPS2(1);
#define ACCEL_FS G_TO_MPS2(200)

#include <cstdarg>

#include "usb_std.h"
#include <cstdarg>
void CustomPrintf(const char *format, ...) {
char buffer[256];
va_list args;
va_start(args, format);
int len = vsprintf(buffer, format, args);
usbStd_transmit((uint8_t*) buffer, len);
va_end(args);
char buffer[256];
va_list args;
va_start(args, format);
int len = vsprintf(buffer, format, args);
usbStd_transmit((uint8_t *)buffer, len);
va_end(args);
}

bool AccelAdx375::begin(SpiCtrl_t spi_) {
spi = spi_;

HAL_GPIO_WritePin(spi.port, spi.pin, GPIO_PIN_SET);
HAL_Delay(1);

// adapted from
// https://github.com/adafruit/Adafruit_ADX375/blob/master/Adafruit_ADX375.cpp

auto wireID = spi_readRegister(&spi, to_size_type(RegisterAddress {
.address = REG_WHOAMI, .multiByteRequest = false, .isRead = 1 }));

if (wireID != 0xe5) {
return false;
}

// Interrupts default to off, but just to be sure
spi_writeRegister(&spi, to_size_type(RegisterAddress { .address =
REG_INT_ENABLE, .multiByteRequest = false, .isRead = 0 }), 0);

// data format set to right justified/LSB first/sign extended; 3 wire spi
// enabled; interrupts active high
spi_writeRegister(&spi, to_size_type(RegisterAddress { .address =
REG_DATA_FORMAT, .multiByteRequest = false, .isRead = 0 }), 0b00001011);

// And power up
spi_writeRegister(&spi, to_size_type(RegisterAddress { .address =
REG_POWER_CTL, .multiByteRequest = false, .isRead = 0 }), 0b0001000);

return true;
spi = spi_;

HAL_GPIO_WritePin(spi.port, spi.pin, GPIO_PIN_SET);
HAL_Delay(1);

// adapted from
// https://github.com/adafruit/Adafruit_ADX375/blob/master/Adafruit_ADX375.cpp

auto wireID = spi_readRegister(
&spi,
to_size_type(RegisterAddress{
.address = REG_WHOAMI, .multiByteRequest = false, .isRead = 1}));

if (wireID != 0xe5) {
return false;
}

// Interrupts default to off, but just to be sure
spi_writeRegister(
&spi,
to_size_type(RegisterAddress{
.address = REG_INT_ENABLE, .multiByteRequest = false, .isRead = 0}),
0);

// data format set to right justified/LSB first/sign extended; 3 wire spi
// enabled; interrupts active high
spi_writeRegister(
&spi,
to_size_type(RegisterAddress{
.address = REG_DATA_FORMAT, .multiByteRequest = false, .isRead = 0}),
0b00001011);

// And power up
spi_writeRegister(
&spi,
to_size_type(RegisterAddress{
.address = REG_POWER_CTL, .multiByteRequest = false, .isRead = 0}),
0b0001000);

return true;
}

void AccelAdx375::newData() {

spi_readRegisters(&spi, to_size_type(RegisterAddress {
.address = REG_DATAX0, .multiByteRequest = true, .isRead = true }),
reinterpret_cast<uint8_t*>(&data.raw), sizeof(data.raw));

constexpr Axis3dReal_s accelOffset = {
.x = -2.76,
.y = 6.31,
.z = -5.63
};

// and convert to real units. Note that ticks / (ticks / unit) = unit
data.realMps2.x = data.raw.x / ACCEL_SENSITIVITY;
data.realMps2.y = data.raw.y / ACCEL_SENSITIVITY;
data.realMps2.z = data.raw.z / ACCEL_SENSITIVITY;

data.realMps2.x += accelOffset.x;
data.realMps2.y += accelOffset.y;
data.realMps2.z += accelOffset.z;
spi_readRegisters(
&spi,
to_size_type(RegisterAddress{
.address = REG_DATAX0, .multiByteRequest = true, .isRead = true}),
reinterpret_cast<uint8_t *>(&data.raw), sizeof(data.raw));

constexpr Axis3dReal_s accelOffset = {.x = -2.76, .y = 6.31, .z = -5.63};

// and convert to real units. Note that ticks / (ticks / unit) = unit
data.realMps2.x = data.raw.x / ACCEL_SENSITIVITY;
data.realMps2.y = data.raw.y / ACCEL_SENSITIVITY;
data.realMps2.z = data.raw.z / ACCEL_SENSITIVITY;

data.realMps2.x += accelOffset.x;
data.realMps2.y += accelOffset.y;
data.realMps2.z += accelOffset.z;
}

double AccelAdx375::getAccelFullscaleMps2() {
return ACCEL_FS;
}
double AccelAdx375::getAccelFullscaleMps2() { return ACCEL_FS; }

#endif // HAS_DEV(ACCEL_ADX375)
Loading

0 comments on commit 60d7693

Please sign in to comment.