Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang format CI action to enforce formatting #177

Merged
merged 5 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Code Style Check

on: [push]

jobs:
formatting-check:
name: Check format of C
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Run clang-format style check for C/C++ sources
uses: Northeastern-Electric-Racing/clang-format-action@main
with:
clang-format-version: '18'
# exclude vl6180x
# use the clang-format from embedded base
format-filepath: "./clang-format"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode/
__pycache__/
*.egg-info/
*.egg-info/

*.nix
1 change: 1 addition & 0 deletions general/.clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./*/vl6180x*
2 changes: 1 addition & 1 deletion general/src/LTC4015.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ HAL_StatusTypeDef LTC4015_Qcounter(LTC4015_T *dev, uint16_t prescaler,
LTC4015_write(dev, CONFIG_BITS, 0x1000); // suspends charger
return (QCOUNT,
highAlert) // Need away to tell its being flagged, but not
// really sure what to return
// really sure what to return
} else if (LIMIT_ALERTS | 0x2000 == 0x2000) {
LTC4015_write(dev, EN_LIMIT_ALERTS, EN_LIMIT_ALERTS ^ 0x2000);
LTC4015_write(dev, CONFIG_BITS, 0x1000); // suspends charger
Expand Down
58 changes: 29 additions & 29 deletions general/src/ltc68041.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void LTC6804_adcv(ltc_config *config)
// 3
wakeup_idle(
config); // This will guarantee that the LTC6804 isoSPI port is
// awake. This command can be removed.
// awake. This command can be removed.

// 4
HAL_GPIO_WritePin(config->gpio, config->cs_pin, GPIO_PIN_RESET);
Expand Down Expand Up @@ -243,7 +243,7 @@ void LTC6804_adax(ltc_config *config)

wakeup_idle(
config); // This will guarantee that the LTC6804 isoSPI port is
// awake. This command can be removed.
// awake. This command can be removed.
HAL_GPIO_WritePin(config->gpio, config->cs_pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(config->spi, cmd, 4, HAL_MAX_DELAY);
HAL_GPIO_WritePin(config->gpio, config->cs_pin, GPIO_PIN_SET);
Expand Down Expand Up @@ -346,7 +346,7 @@ LTC6804_rdcv(ltc_config *config,
cell_data[data_counter] +
(cell_data[data_counter + 1]
<< 8); // Each cell code is received as
// two bytes and is combined to
// two bytes and is combined to
// create the parsed cell voltage code

cell_codes[current_ic][current_cell +
Expand All @@ -363,21 +363,21 @@ LTC6804_rdcv(ltc_config *config,
(cell_data[data_counter] << 8) +
cell_data[data_counter +
1]; // The received PEC for the current_ic
// is transmitted as the 7th and 8th
// is transmitted as the 7th and 8th
// after the 6 cell voltage data bytes
data_pec = pec15_calc(
BYT_IN_REG,
&cell_data[current_ic * NUM_RX_BYT]);
if (received_pec != data_pec) {
pec_error =
-1; // The pec_error variable is simply set negative if
// any PEC errors
// any PEC errors
// are detected in the serial data
}
data_counter =
data_counter +
2; // Because the transmitted PEC code is
// 2 bytes long the data_counter
// 2 bytes long the data_counter
// must be incremented by 2 bytes to point to the next ICs cell voltage
// data
}
Expand All @@ -403,7 +403,7 @@ LTC6804_rdcv(ltc_config *config,
cell_data[data_counter] +
(cell_data[data_counter + 1]
<< 8); // Each cell code is received as
// two bytes and is combined to
// two bytes and is combined to
// create the parsed cell voltage code

cell_codes[current_ic]
Expand All @@ -420,21 +420,21 @@ LTC6804_rdcv(ltc_config *config,
(cell_data[data_counter] << 8) +
cell_data[data_counter +
1]; // The received PEC for the current_ic is
// transmitted as the 7th and 8th
// transmitted as the 7th and 8th
// after the 6 cell voltage data bytes
data_pec =
pec15_calc(BYT_IN_REG,
&cell_data[current_ic * NUM_RX_BYT]);
if (received_pec != data_pec) {
pec_error =
-1; // The pec_error variable is simply set negative if any
// PEC errors
// PEC errors
// are detected in the serial data
}
data_counter =
data_counter +
2; // Because the transmitted PEC code is 2
// bytes long the data_counter
// bytes long the data_counter
// must be incremented by 2 bytes to point to the next ICs cell voltage
// data
}
Expand Down Expand Up @@ -536,7 +536,7 @@ void LTC6804_rdcv_reg(
// 3
wakeup_idle(
config); // This will guarantee that the LTC6804 isoSPI port is
// awake. This command can be removed.
// awake. This command can be removed.

// 4
HAL_GPIO_WritePin(config->gpio, config->cs_pin, GPIO_PIN_RESET);
Expand Down Expand Up @@ -624,7 +624,7 @@ int8_t LTC6804_rdaux(
LTC6804_rdaux_reg(
config, gpio_reg, total_ic,
data); // Reads the raw auxiliary register data into
// the data[] array
// the data[] array

for (uint8_t current_ic = 0;
current_ic < total_ic;
Expand All @@ -644,7 +644,7 @@ int8_t LTC6804_rdaux(
data[data_counter] +
(data[data_counter + 1]
<< 8); // Each gpio codes is received as
// two bytes and is combined to
// two bytes and is combined to
// create the parsed gpio voltage code

aux_codes[current_ic]
Expand All @@ -662,15 +662,15 @@ int8_t LTC6804_rdaux(
(data[data_counter] << 8) +
data[data_counter +
1]; // The received PEC for the current_ic is
// transmitted as the 7th and 8th
// transmitted as the 7th and 8th
// after the 6 gpio voltage data bytes
data_pec = pec15_calc(
BYT_IN_REG,
&data[current_ic * NUM_RX_BYT]);
if (received_pec == data_pec) {
pec_error =
0; // The pec_error variable is simply set negative if
// any PEC errors
// any PEC errors
// are detected in the received serial data
} else if (received_pec != data_pec) {
if (retries ==
Expand All @@ -690,7 +690,7 @@ int8_t LTC6804_rdaux(
data_counter =
data_counter +
2; // Because the transmitted PEC code
// is 2 bytes long the data_counter
// is 2 bytes long the data_counter
// must be incremented by 2 bytes to point to the next ICs gpio
// voltage data
}
Expand All @@ -716,7 +716,7 @@ int8_t LTC6804_rdaux(
(data[data_counter] +
(data[data_counter + 1]
<< 8)); // Each gpio codes is received as
// two bytes and is combined to
// two bytes and is combined to
// create the parsed gpio voltage code
aux_codes[current_ic]
[current_gpio +
Expand All @@ -732,15 +732,15 @@ int8_t LTC6804_rdaux(
(data[data_counter] << 8) +
data[data_counter +
1]; // The received PEC for the current_ic is
// transmitted as the 7th and 8th
// transmitted as the 7th and 8th
// after the 6 gpio voltage data bytes
data_pec = pec15_calc(
BYT_IN_REG,
&data[current_ic * NUM_RX_BYT]);
if (received_pec != data_pec) {
pec_error =
-1; // The pec_error variable is simply set negative if
// any PEC errors
// any PEC errors
// are detected in the received serial data
} else {
pec_error = 0;
Expand All @@ -749,7 +749,7 @@ int8_t LTC6804_rdaux(
data_counter =
data_counter +
2; // Because the transmitted PEC code is
// 2 bytes long the data_counter
// 2 bytes long the data_counter
// must be incremented by 2 bytes to point to the next ICs gpio voltage
// data
}
Expand Down Expand Up @@ -840,7 +840,7 @@ void LTC6804_rdaux_reg(
// 3
wakeup_idle(
config); // This will guarantee that the LTC6804 isoSPI port is
// awake, this command can be removed.
// awake, this command can be removed.
// 4
HAL_GPIO_WritePin(config->gpio, config->cs_pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(config->spi, cmd, 4, HAL_MAX_DELAY);
Expand Down Expand Up @@ -889,7 +889,7 @@ void LTC6804_clrcell(ltc_config *config)
// 3
wakeup_idle(
config); // This will guarantee that the LTC6804 isoSPI port is
// awake. This command can be removed.
// awake. This command can be removed.

// 4

Expand Down Expand Up @@ -944,7 +944,7 @@ void LTC6804_clraux(ltc_config *config)
// 3
wakeup_idle(
config); // This will guarantee that the LTC6804 isoSPI port is
// awake.This command can be removed.
// awake.This command can be removed.
// 4
HAL_GPIO_WritePin(config->gpio, config->cs_pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(config->spi, cmd, 4, HAL_MAX_DELAY);
Expand Down Expand Up @@ -1034,15 +1034,15 @@ void LTC6804_wrcfg(
cmd[cmd_index] =
data_config[current_ic - 1]
[current_byte]; // adding the config data
// to the array to be sent
// to the array to be sent
cmd_index = cmd_index + 1;
}
// 3
cfg_pec = (uint16_t)pec15_calc(
BYTES_IN_REG,
&data_config[current_ic - 1]
[0]); // calculating the PEC for each ICs
// configuration register data
// configuration register data
cmd[cmd_index] = (uint8_t)(cfg_pec >> 8);
cmd[cmd_index + 1] = (uint8_t)cfg_pec;
cmd_index = cmd_index + 2;
Expand All @@ -1051,7 +1051,7 @@ void LTC6804_wrcfg(
// 4
wakeup_idle(
config); // This will guarantee that the LTC6804 isoSPI port is
// awake.This command can be removed.
// awake.This command can be removed.
// 5

HAL_GPIO_WritePin(config->gpio, config->cs_pin, GPIO_PIN_RESET);
Expand Down Expand Up @@ -1134,7 +1134,7 @@ LTC6804_rdcfg(ltc_config *config,
// 2
wakeup_idle(
config); // This will guarantee that the LTC6804 isoSPI port is
// awake. This command can be removed.
// awake. This command can be removed.
// 3
HAL_GPIO_WritePin(config->gpio, config->cs_pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(config->spi, cmd, 4, HAL_MAX_DELAY);
Expand Down Expand Up @@ -1237,7 +1237,7 @@ pec15_calc(uint8_t len, // Number of bytes that will be used to calculate a PEC
}
return (remainder *
2); // The CRC15 has a 0 in the LSB so the remainder must
// be multiplied by 2
// be multiplied by 2
}

void write_68(ltc_config *config,
Expand Down Expand Up @@ -1277,7 +1277,7 @@ void write_68(ltc_config *config,
BYTES_IN_REG,
&data[(current_ic - 1) *
6]); // Calculating the PEC for each ICs
// configuration register data
// configuration register data
cmd[cmd_index] = (uint8_t)(data_pec >> 8);
cmd[cmd_index + 1] = (uint8_t)data_pec;
cmd_index = cmd_index + 2;
Expand Down
12 changes: 6 additions & 6 deletions platforms/stm32f405/include/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
*/

typedef struct {
CAN_HandleTypeDef *hcan;
const uint32_t *id_list;
uint8_t id_list_len;
CAN_HandleTypeDef *hcan;
const uint32_t *id_list;
uint8_t id_list_len;
} can_t;

typedef struct {
uint32_t id;
uint8_t data[8];
uint8_t len;
uint32_t id;
uint8_t data[8];
uint8_t len;
} can_msg_t;

HAL_StatusTypeDef can_init(can_t *can);
Expand Down
Loading
Loading