Run clang-format on the entire repo
This patch clang-formats the entire repo. Third-party code is
excluded.
I needed to fix up the .clang-format file so that all the header
includes are ordered properly. I could have sworn that it used to work
without the extra modification, but I guess not.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I64bb9f2c795401393f9dfe2fefc4f04cb36b52f6
diff --git a/motors/algorithms.h b/motors/algorithms.h
index c67383b..20dcbe8 100644
--- a/motors/algorithms.h
+++ b/motors/algorithms.h
@@ -2,6 +2,7 @@
#define MOTORS_ALGORITHMS_H_
#include <stdint.h>
+
#include <array>
namespace frc971 {
diff --git a/motors/algorithms_test.cc b/motors/algorithms_test.cc
index 18b89c3..bdf51d7 100644
--- a/motors/algorithms_test.cc
+++ b/motors/algorithms_test.cc
@@ -1,6 +1,7 @@
#include "motors/algorithms.h"
#include <inttypes.h>
+
#include <cmath>
#include "gtest/gtest.h"
diff --git a/motors/big/medium_salsa.cc b/motors/big/medium_salsa.cc
index 6c3f339..ab0f3d6 100644
--- a/motors/big/medium_salsa.cc
+++ b/motors/big/medium_salsa.cc
@@ -1,10 +1,9 @@
-#include "motors/core/kinetis.h"
-
#include <stdio.h>
#include <atomic>
#include "motors/big/motor_controls.h"
+#include "motors/core/kinetis.h"
#include "motors/core/time.h"
#include "motors/motor.h"
#include "motors/peripheral/adc.h"
@@ -133,9 +132,10 @@
}
const BalancedReadings balanced = BalanceReadings(to_balance);
- global_motor.load(::std::memory_order_relaxed)->CurrentInterrupt(
- balanced,
- global_motor.load(::std::memory_order_relaxed)->wrapped_encoder());
+ global_motor.load(::std::memory_order_relaxed)
+ ->CurrentInterrupt(
+ balanced,
+ global_motor.load(::std::memory_order_relaxed)->wrapped_encoder());
}
} // extern "C"
@@ -210,8 +210,8 @@
// value we store because writing anything resets it to CNTIN (ie 0).
"str %[scratch], [%[cnt]]\n"
: [scratch] "=&l"(scratch)
- : [pdir_word] "l"(&PERIPHERAL_BITBAND(GPIOE_PDIR, 24)),
- [cnt] "l"(&FTM1->CNT));
+ : [pdir_word] "l"(&PERIPHERAL_BITBAND(GPIOE_PDIR, 24)), [cnt] "l"(
+ &FTM1->CNT));
__enable_irq();
#endif
}
@@ -290,7 +290,7 @@
FTM0_EXTTRIG = FTM_EXTTRIG_INITTRIGEN;
// Don't let any memory accesses sneak past here, because we actually
// need everything to be starting up.
- __asm__("" :: : "memory");
+ __asm__("" ::: "memory");
// Give everything a chance to get going.
delay(100);
diff --git a/motors/big/motor_controls.cc b/motors/big/motor_controls.cc
index abc71e8..db9878d 100644
--- a/motors/big/motor_controls.cc
+++ b/motors/big/motor_controls.cc
@@ -166,7 +166,8 @@
const ::Eigen::Matrix<float, 3, 1> measured_current =
(::Eigen::Matrix<float, 3, 1>() << scale_current_reading(raw_currents[0]),
scale_current_reading(raw_currents[1]),
- scale_current_reading(raw_currents[2])).finished();
+ scale_current_reading(raw_currents[2]))
+ .finished();
const ComplexMatrix<3, 1> E1 =
E1Unrotated_ *
diff --git a/motors/big/motor_controls.h b/motors/big/motor_controls.h
index 5c59ef1..8aae5d1 100644
--- a/motors/big/motor_controls.h
+++ b/motors/big/motor_controls.h
@@ -4,11 +4,11 @@
#include <array>
#include <complex>
+#include "Eigen/Dense"
+
#include "motors/math.h"
#include "motors/motor.h"
-#include "Eigen/Dense"
-
namespace frc971 {
namespace motors {
@@ -40,8 +40,8 @@
}
::std::array<float, 3> DoIteration(const float raw_currents[3],
- uint32_t theta,
- const float command_current) override;
+ uint32_t theta,
+ const float command_current) override;
int16_t Debug(uint32_t theta) override;
diff --git a/motors/button_board.cc b/motors/button_board.cc
index 0c0050b..fb17328 100644
--- a/motors/button_board.cc
+++ b/motors/button_board.cc
@@ -2,6 +2,7 @@
#include <inttypes.h>
#include <stdio.h>
+
#include <atomic>
#include <cmath>
@@ -150,8 +151,8 @@
((PERIPHERAL_BITBAND(GPIOA_PDIR, 12) << 0) |
(PERIPHERAL_BITBAND(GPIOD_PDIR, 0) << 1) |
(PERIPHERAL_BITBAND(GPIOB_PDIR, 17) << 2) |
- (PERIPHERAL_BITBAND(GPIOB_PDIR, 16) << 3) | (DecodeAnalog(report1[0]) << 4) |
- (DecodeAnalog(report1[1]) << 6)) ^
+ (PERIPHERAL_BITBAND(GPIOB_PDIR, 16) << 3) |
+ (DecodeAnalog(report1[0]) << 4) | (DecodeAnalog(report1[1]) << 6)) ^
0x0f;
report1[5] = (DecodeAnalog(report1[2])) | (DecodeAnalog(report1[3]) << 2);
diff --git a/motors/core/reg_debug.h b/motors/core/reg_debug.h
index 418c391..8edddf6 100644
--- a/motors/core/reg_debug.h
+++ b/motors/core/reg_debug.h
@@ -1,8 +1,8 @@
#ifndef MOTORS_CORE_REG_DEBUG_H_
#define MOTORS_CORE_REG_DEBUG_H_
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
// Cortex-M4 always has 32 registers according to its Technical Reference
// Manual.
diff --git a/motors/core/semihosting.h b/motors/core/semihosting.h
index af2fa4b..3b7ba46 100644
--- a/motors/core/semihosting.h
+++ b/motors/core/semihosting.h
@@ -26,16 +26,12 @@
uint32_t handle;
// Returns 0 if it succeeds, or -1 if not.
- int Execute() {
- return integer_operation(0x02, this);
- }
+ int Execute() { return integer_operation(0x02, this); }
};
struct Errno {
// Returns the current errno value.
- int Execute() {
- return integer_operation(0x13, nullptr);
- }
+ int Execute() { return integer_operation(0x13, nullptr); }
};
struct FileLength {
@@ -43,9 +39,7 @@
uint32_t handle;
// Returns the current length of the file or -1.
- int Execute() {
- return integer_operation(0x0C, this);
- }
+ int Execute() { return integer_operation(0x0C, this); }
};
struct GetCommandLine {
@@ -62,9 +56,7 @@
}
// Returns 0 if it succeeds, or -1 if not.
- int Execute() {
- return integer_operation(0x15, this);
- }
+ int Execute() { return integer_operation(0x15, this); }
};
struct IsTty {
@@ -73,9 +65,7 @@
// Returns 0 if it's a file, 1 if it's an interactive device, or something
// else otherwise.
- int Execute() {
- return integer_operation(0x09, this);
- }
+ int Execute() { return integer_operation(0x09, this); }
};
struct Open {
@@ -102,9 +92,7 @@
int name_length;
// Returns a non-zero file handle if it succeeds, or -1 if not.
- int Execute() {
- return integer_operation(0x01, this);
- }
+ int Execute() { return integer_operation(0x01, this); }
};
struct Read {
@@ -128,9 +116,7 @@
};
struct ReadCharacter {
- char Execute() {
- return integer_operation(0x07, nullptr);
- }
+ char Execute() { return integer_operation(0x07, nullptr); }
};
struct Seek {
@@ -140,16 +126,12 @@
uint32_t position;
// Returns 0 if it succeeds, or a negative value if not.
- int Execute() {
- return integer_operation(0x0A, this);
- }
+ int Execute() { return integer_operation(0x0A, this); }
};
struct RealtimeTime {
// Returns the number of seconds since 00:00 January 1, 1970.
- uint32_t Execute() {
- return integer_operation(0x11, nullptr);
- }
+ uint32_t Execute() { return integer_operation(0x11, nullptr); }
};
struct Write {
@@ -167,17 +149,13 @@
}
// Returns 0 if it succeeds, or the number of bytes NOT written.
- int Execute() {
- return integer_operation(0x05, this);
- }
+ int Execute() { return integer_operation(0x05, this); }
};
struct WriteDebugCharacter {
const char *character;
- void Execute() {
- integer_operation(0x03, this);
- }
+ void Execute() { integer_operation(0x03, this); }
};
struct WriteDebug {
diff --git a/motors/core/time.cc b/motors/core/time.cc
index 87f34f0..77814b3 100644
--- a/motors/core/time.cc
+++ b/motors/core/time.cc
@@ -7,7 +7,7 @@
namespace {
-template<int kMultiplier>
+template <int kMultiplier>
uint32_t do_time(void) {
__disable_irq();
uint32_t current = SYST_CVR;
diff --git a/motors/core/time.h b/motors/core/time.h
index d03cb10..a131d7f 100644
--- a/motors/core/time.h
+++ b/motors/core/time.h
@@ -6,8 +6,7 @@
// This whole file is deprecated. Use //aos/time instead.
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
// Returns the current number of nanoseconds. This will wrap naturally.
diff --git a/motors/fet12/fet12.cc b/motors/fet12/fet12.cc
index 93b7828..b6f2a45 100644
--- a/motors/fet12/fet12.cc
+++ b/motors/fet12/fet12.cc
@@ -1,10 +1,9 @@
-#include "motors/core/kinetis.h"
-
#include <inttypes.h>
#include <stdio.h>
#include <atomic>
+#include "motors/core/kinetis.h"
#include "motors/core/time.h"
#include "motors/fet12/motor_controls.h"
#include "motors/motor.h"
@@ -189,8 +188,8 @@
// value we store because writing anything resets it to CNTIN (ie 0).
"str %[scratch], [%[cnt]]\n"
: [scratch] "=&l"(scratch)
- : [pdir_word] "l"(&PERIPHERAL_BITBAND(GPIOA_PDIR, 7)),
- [cnt] "l"(&FTM1->CNT));
+ : [pdir_word] "l"(&PERIPHERAL_BITBAND(GPIOA_PDIR, 7)), [cnt] "l"(
+ &FTM1->CNT));
__enable_irq();
#endif
}
@@ -277,7 +276,7 @@
FTM0_EXTTRIG = FTM_EXTTRIG_INITTRIGEN;
// Don't let any memory accesses sneak past here, because we actually
// need everything to be starting up.
- __asm__("" :: : "memory");
+ __asm__("" ::: "memory");
// Give everything a chance to get going.
delay(100);
diff --git a/motors/fet12/fet12v2.cc b/motors/fet12/fet12v2.cc
index 3380631..b0a0acc 100644
--- a/motors/fet12/fet12v2.cc
+++ b/motors/fet12/fet12v2.cc
@@ -1,10 +1,9 @@
-#include "motors/core/kinetis.h"
-
#include <inttypes.h>
#include <stdio.h>
#include <atomic>
+#include "motors/core/kinetis.h"
#include "motors/core/time.h"
#include "motors/fet12/current_equalization.h"
#include "motors/fet12/motor_controls.h"
@@ -134,8 +133,7 @@
adc_dma->Reset();
const uint32_t wrapped_encoder =
global_motor.load(::std::memory_order_relaxed)->wrapped_encoder();
- const BalancedReadings balanced =
- BalanceSimpleReadings(decoupled);
+ const BalancedReadings balanced = BalanceSimpleReadings(decoupled);
#if 1
@@ -216,19 +214,18 @@
: static_cast<float>(kIcc);
const float throttle_limit = ::std::min(
kPeakCurrent,
- (-abs_bemf + ::std::sqrt(static_cast<float>(
- bemf * bemf +
- 4.0f * static_cast<float>(kR) * 1.5f *
- static_cast<float>(kVcc) * max_bat_cur))) /
+ (-abs_bemf +
+ ::std::sqrt(static_cast<float>(
+ bemf * bemf + 4.0f * static_cast<float>(kR) * 1.5f *
+ static_cast<float>(kVcc) * max_bat_cur))) /
(2.0f * 1.5f * static_cast<float>(kR)));
constexpr float kNegativeCurrent = 100.0f;
- float goal_current =
- -::std::min(
- ::std::max(filtered_throttle * (kPeakCurrent + kNegativeCurrent) -
- kNegativeCurrent,
- -throttle_limit),
- throttle_limit);
+ float goal_current = -::std::min(
+ ::std::max(filtered_throttle * (kPeakCurrent + kNegativeCurrent) -
+ kNegativeCurrent,
+ -throttle_limit),
+ throttle_limit);
if (!throttle_zeroed) {
goal_current = 0.0f;
@@ -242,8 +239,8 @@
}
}
- //float goal_current =
- //-::std::min(filtered_throttle * kPeakCurrent, throttle_limit);
+ // float goal_current =
+ //-::std::min(filtered_throttle * kPeakCurrent, throttle_limit);
const float overall_measured_current =
global_motor.load(::std::memory_order_relaxed)
->overall_measured_current();
@@ -254,8 +251,7 @@
const int16_t fuse_current_10 = static_cast<int16_t>(10.0f * fuse_current);
fuse_badness += 0.00002f * (fuse_current * fuse_current - fuse_badness);
- global_motor.load(::std::memory_order_relaxed)
- ->SetGoalCurrent(goal_current);
+ global_motor.load(::std::memory_order_relaxed)->SetGoalCurrent(goal_current);
global_motor.load(::std::memory_order_relaxed)
->CurrentInterrupt(balanced, wrapped_encoder);
@@ -278,11 +274,14 @@
global_debug_buffer.samples[buffer_size].est_omega =
global_motor.load(::std::memory_order_relaxed)->estimated_velocity();
global_debug_buffer.samples[buffer_size].commands[0] =
- global_motor.load(::std::memory_order_relaxed)->get_switching_points_cycles(0);
+ global_motor.load(::std::memory_order_relaxed)
+ ->get_switching_points_cycles(0);
global_debug_buffer.samples[buffer_size].commands[1] =
- global_motor.load(::std::memory_order_relaxed)->get_switching_points_cycles(1);
+ global_motor.load(::std::memory_order_relaxed)
+ ->get_switching_points_cycles(1);
global_debug_buffer.samples[buffer_size].commands[2] =
- global_motor.load(::std::memory_order_relaxed)->get_switching_points_cycles(2);
+ global_motor.load(::std::memory_order_relaxed)
+ ->get_switching_points_cycles(2);
global_debug_buffer.samples[buffer_size].commanded_currents[0] =
global_motor.load(::std::memory_order_relaxed)->i_goal(0);
global_debug_buffer.samples[buffer_size].commanded_currents[1] =
@@ -299,7 +298,8 @@
kNegativeCurrent,
0.0f);
global_debug_buffer.samples[buffer_size].fuse_badness = fuse_badness;
- global_debug_buffer.samples[buffer_size].cycles_since_start = cycles_since_start;
+ global_debug_buffer.samples[buffer_size].cycles_since_start =
+ cycles_since_start;
global_debug_buffer.size.fetch_add(1);
}
@@ -384,7 +384,6 @@
}
++i;
#endif
-
}
} // extern "C"
@@ -468,8 +467,8 @@
// value we store because writing anything resets it to CNTIN (ie 0).
"str %[scratch], [%[cnt]]\n"
: [scratch] "=&l"(scratch)
- : [pdir_word] "l"(&PERIPHERAL_BITBAND(GPIOB_PDIR, 11)),
- [cnt] "l"(&FTM1->CNT));
+ : [pdir_word] "l"(&PERIPHERAL_BITBAND(GPIOB_PDIR, 11)), [cnt] "l"(
+ &FTM1->CNT));
__enable_irq();
#endif
}
@@ -573,16 +572,15 @@
// This has to happen after messing with SYNCONF, and should happen after
// messing with various other things so the values can get flushed out of the
// buffers.
- FTM2->SYNC =
- FTM_SYNC_SWSYNC /* Flush everything out right now */ |
- FTM_SYNC_CNTMAX /* Load new values at the end of the cycle */;
+ FTM2->SYNC = FTM_SYNC_SWSYNC /* Flush everything out right now */ |
+ FTM_SYNC_CNTMAX /* Load new values at the end of the cycle */;
// Wait for the software synchronization to finish.
while (FTM2->SYNC & FTM_SYNC_SWSYNC) {
}
FTM2->SC = FTM_SC_CLKS(1) /* Use the system clock */ |
- FTM_SC_PS(0) /* Don't prescale the clock */;
+ FTM_SC_PS(0) /* Don't prescale the clock */;
// TODO:
- //FTM2->MODE &= ~FTM_MODE_WPDIS;
+ // FTM2->MODE &= ~FTM_MODE_WPDIS;
FTM2->EXTTRIG = FTM_EXTTRIG_CH0TRIG | FTM_EXTTRIG_CH1TRIG;
@@ -616,7 +614,7 @@
FTM0_EXTTRIG = FTM_EXTTRIG_INITTRIGEN;
// Don't let any memory accesses sneak past here, because we actually
// need everything to be starting up.
- __asm__("" :: : "memory");
+ __asm__("" ::: "memory");
// Give everything a chance to get going.
delay(100);
@@ -670,10 +668,9 @@
for (size_t i = 0; i < global_debug_buffer.samples.size(); ++i) {
const auto &sample = global_debug_buffer.samples[i];
#if 1
- printf("%u, %d, %d, %d, %u, %u, %u, %u\n", i,
- sample.currents[0], sample.currents[1], sample.currents[2],
- sample.commands[0], sample.commands[1], sample.commands[2],
- sample.position);
+ printf("%u, %d, %d, %d, %u, %u, %u, %u\n", i, sample.currents[0],
+ sample.currents[1], sample.currents[2], sample.commands[0],
+ sample.commands[1], sample.commands[2], sample.position);
#else
printf("%" PRIu16 ",%" PRIu16 ",%" PRIu16 ",%" PRId16 ",%" PRId16
",%" PRId16 "\n",
@@ -695,7 +692,7 @@
}
printf("Done dumping data\n");
} else {
- //const auto &sample = global_debug_buffer.samples.back();
+ // const auto &sample = global_debug_buffer.samples.back();
const DebugBuffer::Sample sample = global_debug_buffer.samples[0];
#if 1
printf("%" PRIu32
diff --git a/motors/fet12/motor_controls.cc b/motors/fet12/motor_controls.cc
index 9e42ca8..0ef7e3c 100644
--- a/motors/fet12/motor_controls.cc
+++ b/motors/fet12/motor_controls.cc
@@ -163,7 +163,8 @@
const ::Eigen::Matrix<float, 3, 1> measured_current =
(::Eigen::Matrix<float, 3, 1>() << scale_current_reading(raw_currents[0]),
scale_current_reading(raw_currents[1]),
- scale_current_reading(raw_currents[2])).finished();
+ scale_current_reading(raw_currents[2]))
+ .finished();
const ComplexMatrix<3, 1> E1 =
E1Unrotated_ *
diff --git a/motors/fet12/motor_controls.h b/motors/fet12/motor_controls.h
index eea1c30..482eeaf 100644
--- a/motors/fet12/motor_controls.h
+++ b/motors/fet12/motor_controls.h
@@ -4,11 +4,11 @@
#include <array>
#include <complex>
+#include "Eigen/Dense"
+
#include "motors/math.h"
#include "motors/motor.h"
-#include "Eigen/Dense"
-
namespace frc971 {
namespace motors {
@@ -57,8 +57,7 @@
float overall_measured_current_ = 0;
::Eigen::Matrix<float, 3, 1> I_last_ = ::Eigen::Matrix<float, 3, 1>::Zero();
- ::Eigen::Matrix<float, 3, 1> I_prev_ =
- ::Eigen::Matrix<float, 3, 1>::Zero();
+ ::Eigen::Matrix<float, 3, 1> I_prev_ = ::Eigen::Matrix<float, 3, 1>::Zero();
int16_t debug_[9];
};
diff --git a/motors/fet12/power_wheels.cc b/motors/fet12/power_wheels.cc
index fe56348..893d92f 100644
--- a/motors/fet12/power_wheels.cc
+++ b/motors/fet12/power_wheels.cc
@@ -1,11 +1,10 @@
-#include "motors/core/kinetis.h"
-
#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <atomic>
+#include "motors/core/kinetis.h"
#include "motors/core/time.h"
#include "motors/peripheral/adc.h"
#include "motors/usb/cdc.h"
@@ -232,7 +231,7 @@
// Don't let any memory accesses sneak past here, because we actually
// need everything to be starting up.
- __asm__("" :: : "memory");
+ __asm__("" ::: "memory");
// Give everything a chance to get going.
delay(100);
@@ -265,8 +264,8 @@
}
static constexpr int kThrottleMin = 700;
static constexpr int kThrottleMax = 2000;
- //static constexpr int kThrottleMin = 1100;
- //static constexpr int kThrottleMax = 3190;
+ // static constexpr int kThrottleMin = 1100;
+ // static constexpr int kThrottleMax = 3190;
const float pedal_position = ::std::min(
1.0f,
::std::max(0.0f,
diff --git a/motors/math.h b/motors/math.h
index d7bbee4..5151714 100644
--- a/motors/math.h
+++ b/motors/math.h
@@ -100,7 +100,7 @@
extern ::std::array<GenericInitializer *, 10> global_initializers;
// Manages initializing and access to an integer table of a single size.
-template<int kTableSize>
+template <int kTableSize>
class SinCosIntTable {
public:
static const float *sin_int_table() {
@@ -192,7 +192,7 @@
// multiple denominators are needed in the same program, in which case using the
// biggest denominator for all of them will use the least memory.
-template<class Rotation, int kTableSize = Rotation::den>
+template <class Rotation, int kTableSize = Rotation::den>
float FastSinInt(uint32_t theta) {
return math_internal::FastTableLookupInt<Rotation, kTableSize>(
theta, math_internal::SinCosIntTable<kTableSize>::sin_int_table());
@@ -204,7 +204,7 @@
theta, math_internal::SinCosIntTable<kTableSize>::cos_int_table());
}
-template<class Rotation>
+template <class Rotation>
::std::complex<float> ImaginaryExpInt(uint32_t theta) {
return ::std::complex<float>(FastCosInt<Rotation>(theta),
FastSinInt<Rotation>(theta));
diff --git a/motors/math_test.cc b/motors/math_test.cc
index 91100e8..fb72454 100644
--- a/motors/math_test.cc
+++ b/motors/math_test.cc
@@ -1,7 +1,7 @@
#include "motors/math.h"
-#include "gtest/gtest.h"
#include "gmock/gmock.h"
+#include "gtest/gtest.h"
namespace frc971 {
namespace motors {
@@ -9,20 +9,18 @@
class SinCosIntTest : public ::testing::Test {
public:
- void SetUp() override {
- MathInit();
- }
+ void SetUp() override { MathInit(); }
template <class Rotation, int kTableSize>
void CheckSinCos() {
static constexpr float kTolerance = 0.004;
- SCOPED_TRACE("num=" + ::std::to_string(Rotation::num) + " den=" +
- ::std::to_string(Rotation::den) + " table_size=" +
- ::std::to_string(kTableSize));
+ SCOPED_TRACE("num=" + ::std::to_string(Rotation::num) +
+ " den=" + ::std::to_string(Rotation::den) +
+ " table_size=" + ::std::to_string(kTableSize));
for (uint32_t theta = 0; theta < Rotation::den; ++theta) {
const float theta_float = ThetaToFloat<Rotation>(theta);
- SCOPED_TRACE("theta=" + ::std::to_string(theta) + " theta_float=" +
- ::std::to_string(theta_float));
+ SCOPED_TRACE("theta=" + ::std::to_string(theta) +
+ " theta_float=" + ::std::to_string(theta_float));
EXPECT_THAT((FastSinInt<Rotation, kTableSize>(theta)),
::testing::FloatNear(sin(theta_float), kTolerance));
EXPECT_THAT((FastCosInt<Rotation, kTableSize>(theta)),
@@ -77,9 +75,7 @@
class SinCosFloatTest : public ::testing::Test {
public:
- void SetUp() override {
- MathInit();
- }
+ void SetUp() override { MathInit(); }
void CheckSinCos(float theta) {
ASSERT_GE(theta, -0.2f);
diff --git a/motors/motor.cc b/motors/motor.cc
index 33113a1..a343301 100644
--- a/motors/motor.cc
+++ b/motors/motor.cc
@@ -1,13 +1,13 @@
#include "motors/motor.h"
+#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
-#include <inttypes.h>
#include <array>
-#include "motors/peripheral/configuration.h"
#include "motors/peripheral/can.h"
+#include "motors/peripheral/configuration.h"
extern "C" float analog_ratio(uint16_t reading);
extern "C" float absolute_wheel(uint16_t reading);
@@ -184,7 +184,7 @@
static_cast<uint32_t>(switching_points_ratio_[2] * switching_points_max)};
#if USE_CUTOFF
constexpr uint32_t kMax = 2995;
- //constexpr uint32_t kMax = 1445;
+ // constexpr uint32_t kMax = 1445;
static bool done = false;
bool done_now = false;
if (switching_points[0] > kMax || switching_points[1] > kMax ||
@@ -223,7 +223,7 @@
done = true;
}
if (!done) {
-#else // USE_CUTOFF
+#else // USE_CUTOFF
if (true) {
#endif // USE_CUTOFF
output_registers_[0][0] = CalculateOnTime(switching_points[0]);
@@ -262,7 +262,7 @@
constexpr int kStartupWait = 2 * 20000;
#endif
constexpr int kSubsampling = 1;
- //constexpr int kPoints = 5000;
+ // constexpr int kPoints = 5000;
constexpr int kPoints = 1000;
constexpr int kSamplingEnd = kStartupWait + kPoints * kSubsampling;
(void)kSamplingEnd;
@@ -277,7 +277,7 @@
++j;
#if SAMPLE_UNTIL_DONE
} else if (!done) {
-#else // SAMPLE_UNTIL_DONE
+#else // SAMPLE_UNTIL_DONE
} else if (j < kSamplingEnd && (j % kSubsampling) == 0) {
#endif // SAMPLE_UNTIL_DONE
{
@@ -329,14 +329,14 @@
point[5] = pwm_ftm_->C5V - pwm_ftm_->C4V;
#endif
#endif
-// End obnoxious #if 0/#if 1
+ // End obnoxious #if 0/#if 1
point[9] = captured_wrapped_encoder;
- //SmallInitReadings readings;
+ // SmallInitReadings readings;
//{
- //DisableInterrupts disable_interrupts;
- //readings = AdcReadSmallInit(disable_interrupts);
+ // DisableInterrupts disable_interrupts;
+ // readings = AdcReadSmallInit(disable_interrupts);
//}
- //point[10] = readings.motor0_abs;
+ // point[10] = readings.motor0_abs;
}
#if DO_STEP_RESPONSE
@@ -359,12 +359,12 @@
pwm_ftm_->C2V = 0;
pwm_ftm_->C3V = 0;
}
-#endif // DO_STEP_RESPONSE/DO_PULSE_SWEEP
+#endif // DO_STEP_RESPONSE/DO_PULSE_SWEEP
++j;
#if SAMPLE_UNTIL_DONE
} else if (false) {
-#else // SAMPLE_UNTIL_DONE
+#else // SAMPLE_UNTIL_DONE
} else if (j < kSamplingEnd) {
++j;
} else if (j == kSamplingEnd) {
@@ -373,7 +373,7 @@
++j;
#if SAMPLE_UNTIL_DONE
} else if (done) {
-#else // SAMPLE_UNTIL_DONE
+#else // SAMPLE_UNTIL_DONE
} else {
#endif // SAMPLE_UNTIL_DONE
// Time to write the data out.
@@ -382,7 +382,8 @@
if (to_write > 64) {
to_write = 64;
}
- int result = printing_implementation_->Write(((const char *)data) + written, to_write);
+ int result = printing_implementation_->Write(
+ ((const char *)data) + written, to_write);
if (result >= 0) {
written += result;
} else {
diff --git a/motors/motor.h b/motors/motor.h
index 2896b80..3f7b132 100644
--- a/motors/motor.h
+++ b/motors/motor.h
@@ -111,9 +111,7 @@
return static_cast<int32_t>(wrapped_encoder_reading) + encoder_offset_;
}
- int encoder() {
- return encoder_multiplier_ * encoder_ftm_->CNT;
- }
+ int encoder() { return encoder_multiplier_ * encoder_ftm_->CNT; }
uint32_t wrapped_encoder() {
return (encoder() + encoder_calibration_offset_) %
controls_->mechanical_counts_per_revolution();
@@ -155,13 +153,9 @@
return controls_->estimated_velocity();
}
- inline int16_t i_goal(size_t ii) const {
- return controls_->i_goal(ii);
- }
+ inline int16_t i_goal(size_t ii) const { return controls_->i_goal(ii); }
- inline int16_t goal_current() const {
- return goal_current_;
- }
+ inline int16_t goal_current() const { return goal_current_; }
inline float overall_measured_current() const {
return controls_->overall_measured_current();
diff --git a/motors/peripheral/adc.cc b/motors/peripheral/adc.cc
index 6325f9f..64f1557 100644
--- a/motors/peripheral/adc.cc
+++ b/motors/peripheral/adc.cc
@@ -6,7 +6,9 @@
namespace motors {
namespace {
-#define ADC_SC2_BASE (ADC_SC2_REFSEL(0) /* Use the external reference pins. */)
+#define ADC_SC2_BASE \
+ (ADC_SC2_REFSEL(0) /* Use the external reference pins. \
+ */)
#define ADC_FINISH_CALIBRATION(n, PM) \
do { \
diff --git a/motors/peripheral/adc_dma.cc b/motors/peripheral/adc_dma.cc
index bdd84d6..d2dc6c9 100644
--- a/motors/peripheral/adc_dma.cc
+++ b/motors/peripheral/adc_dma.cc
@@ -65,7 +65,8 @@
} // namespace
-AdcDmaSampler::AdcDmaSampler(int counts_per_cycle) : counts_per_cycle_(counts_per_cycle) {
+AdcDmaSampler::AdcDmaSampler(int counts_per_cycle)
+ : counts_per_cycle_(counts_per_cycle) {
for (int adc = 0; adc < 2; ++adc) {
for (int i = 0; i < 2; ++i) {
adc_sc1s_[adc][kNumberAdcSamples + i] = ADC_SC1_ADCH(0x1f);
@@ -117,7 +118,6 @@
static constexpr int kHscAdder = 2 * kAdcClockDivider;
-
static constexpr int kConversionTime =
kSfcAdder + 1 /* AverageNum */ * (kBct + kLstAdder + kHscAdder);
@@ -165,9 +165,8 @@
DMA.CERQ = result_dma_channel(adc);
DMA.CERQ = reconfigure_dma_channel(adc);
- ADC(adc)
- ->SC2 |= ADC_SC2_ADTRG /* Use hardware triggering */ |
- ADC_SC2_DMAEN /* Enable DMA triggers */;
+ ADC(adc)->SC2 |= ADC_SC2_ADTRG /* Use hardware triggering */ |
+ ADC_SC2_DMAEN /* Enable DMA triggers */;
int next_result_channel, next_reconfigure_channel;
if (adc == 0) {
diff --git a/motors/peripheral/adc_dma.h b/motors/peripheral/adc_dma.h
index 6cd0742..a00b730 100644
--- a/motors/peripheral/adc_dma.h
+++ b/motors/peripheral/adc_dma.h
@@ -1,10 +1,10 @@
#ifndef MOTORS_PERIPHERAL_ADC_DMA_H_
#define MOTORS_PERIPHERAL_ADC_DMA_H_
-#include <array>
-
#include <stdint.h>
+#include <array>
+
#include "motors/core/kinetis.h"
#include "motors/peripheral/configuration.h"
#include "motors/util.h"
diff --git a/motors/peripheral/can.c b/motors/peripheral/can.c
index de593c7..7e65ac9 100644
--- a/motors/peripheral/can.c
+++ b/motors/peripheral/can.c
@@ -1,14 +1,13 @@
#include "motors/peripheral/can.h"
+#include <inttypes.h>
#include <stddef.h>
+#include <stdio.h>
#include <string.h>
#include "motors/core/kinetis.h"
#include "motors/util.h"
-#include <stdio.h>
-#include <inttypes.h>
-
// General note: this peripheral is really weird about accessing its memory. It
// goes much farther than normal memory-mapped device semantics. In particular,
// it "locks" various regions of memory under complicated conditions. Because of
@@ -44,7 +43,8 @@
// isn't what we want. It will ignore the attempt to change some of the bits
// because it's not in freeze mode, but whatever.
CAN0_MCR = CAN_MCR_FRZ | CAN_MCR_HALT;
- while (!(CAN0_MCR & CAN_MCR_FRZACK)) {}
+ while (!(CAN0_MCR & CAN_MCR_FRZACK)) {
+ }
// Initializing this before touching the mailboxes because the reference
// manual slightly implies you have to, and the registers and RAM on this
@@ -87,13 +87,13 @@
// We're going with a sample point fraction of 0.875 because that's what
// SocketCAN defaults to.
// This results in a baud rate of 500 kHz.
- CAN0_CTRL1 = CAN_CTRL1_PRESDIV(
- 1) /* Divide the crystal frequency by 2 to get 8 MHz. */ |
- CAN_CTRL1_RJW(0) /* RJW/SJW of 1, which is most common. */ |
- CAN_CTRL1_PSEG1(7) /* 8 time quanta before sampling. */ |
- CAN_CTRL1_PSEG2(1) /* 2 time quanta after sampling. */ |
- CAN_CTRL1_SMP /* Use triple sampling. */ |
- CAN_CTRL1_PROPSEG(4) /* 5 time quanta before sampling. */;
+ CAN0_CTRL1 =
+ CAN_CTRL1_PRESDIV(1) /* Divide the crystal frequency by 2 to get 8 MHz. */
+ | CAN_CTRL1_RJW(0) /* RJW/SJW of 1, which is most common. */ |
+ CAN_CTRL1_PSEG1(7) /* 8 time quanta before sampling. */ |
+ CAN_CTRL1_PSEG2(1) /* 2 time quanta after sampling. */ |
+ CAN_CTRL1_SMP /* Use triple sampling. */ |
+ CAN_CTRL1_PROPSEG(4) /* 5 time quanta before sampling. */;
// TASD calculation:
// 25 - (fcanclk * (maxmb + 3 - (rfen * 8) - (rfen * rffn * 2)) * 2) /
// (fsys * (1 + (pseg1 + 1) + (pseg2 + 1) + (propseg + 1)) * (presdiv + 1))
diff --git a/motors/peripheral/spi.h b/motors/peripheral/spi.h
index 5361f91..f865703 100644
--- a/motors/peripheral/spi.h
+++ b/motors/peripheral/spi.h
@@ -2,6 +2,7 @@
#define MOTORS_PERIPHERAL_SPI_H_
#include "absl/types/span.h"
+
#include "motors/core/kinetis.h"
#include "motors/peripheral/uart_buffer.h"
#include "motors/util.h"
diff --git a/motors/peripheral/uart.h b/motors/peripheral/uart.h
index d51bcfe..bfd630b 100644
--- a/motors/peripheral/uart.h
+++ b/motors/peripheral/uart.h
@@ -2,6 +2,7 @@
#define MOTORS_PERIPHERAL_UART_H_
#include "absl/types/span.h"
+
#include "aos/containers/sized_array.h"
#include "motors/core/kinetis.h"
#include "motors/peripheral/uart_buffer.h"
@@ -27,9 +28,7 @@
}
// Returns all the data which is currently available.
- aos::SizedArray<char, 4> Read(const DisableInterrupts &) {
- return DoRead();
- }
+ aos::SizedArray<char, 4> Read(const DisableInterrupts &) { return DoRead(); }
bool SpaceAvailable() const { return module_->S1 & M_UART_TDRE; }
// Only call this if SpaceAvailable() has just returned true.
diff --git a/motors/peripheral/uart_buffer.h b/motors/peripheral/uart_buffer.h
index c324a2d..9266465 100644
--- a/motors/peripheral/uart_buffer.h
+++ b/motors/peripheral/uart_buffer.h
@@ -10,7 +10,7 @@
namespace teensy {
// Manages a circular buffer of data to send out.
-template<int kSize>
+template <int kSize>
class UartBuffer {
public:
// Returns the number of characters added.
diff --git a/motors/peripheral/uart_buffer_test.cc b/motors/peripheral/uart_buffer_test.cc
index c464f8a..223c029 100644
--- a/motors/peripheral/uart_buffer_test.cc
+++ b/motors/peripheral/uart_buffer_test.cc
@@ -232,14 +232,14 @@
const auto result = buffer.PopSpan(5);
ASSERT_EQ(5u, result.size());
for (int i = 0; i < 5; ++i) {
- EXPECT_EQ(static_cast<char>(i), result[i]);
+ EXPECT_EQ(static_cast<char>(i), result[i]);
}
}
{
const auto result = buffer.PopSpan(10);
ASSERT_EQ(5u, result.size());
for (int i = 0; i < 5; ++i) {
- EXPECT_EQ(static_cast<char>(i + 5), result[i]);
+ EXPECT_EQ(static_cast<char>(i + 5), result[i]);
}
}
ASSERT_TRUE(buffer.PopSpan(5).empty());
@@ -259,7 +259,7 @@
const auto result = buffer.PopSpan(5);
ASSERT_EQ(5u, result.size());
for (int i = 0; i < 5; ++i) {
- EXPECT_EQ(static_cast<char>(i), result[i]);
+ EXPECT_EQ(static_cast<char>(i), result[i]);
}
}
for (int i = 0; i < 5; ++i) {
@@ -269,14 +269,14 @@
const auto result = buffer.PopSpan(10);
ASSERT_EQ(5u, result.size());
for (int i = 0; i < 5; ++i) {
- EXPECT_EQ(static_cast<char>(i + 5), result[i]);
+ EXPECT_EQ(static_cast<char>(i + 5), result[i]);
}
}
{
const auto result = buffer.PopSpan(10);
ASSERT_EQ(5u, result.size());
for (int i = 0; i < 5; ++i) {
- EXPECT_EQ(static_cast<char>(i + 20), result[i]);
+ EXPECT_EQ(static_cast<char>(i + 20), result[i]);
}
}
}
diff --git a/motors/pistol_grip/controller.cc b/motors/pistol_grip/controller.cc
index 32a0285..5a0d5a2 100644
--- a/motors/pistol_grip/controller.cc
+++ b/motors/pistol_grip/controller.cc
@@ -1,5 +1,3 @@
-#include "motors/core/kinetis.h"
-
#include <inttypes.h>
#include <stdio.h>
@@ -8,6 +6,7 @@
#include "frc971/control_loops/drivetrain/integral_haptic_trigger.h"
#include "frc971/control_loops/drivetrain/integral_haptic_wheel.h"
+#include "motors/core/kinetis.h"
#include "motors/core/time.h"
#include "motors/motor.h"
#include "motors/peripheral/can.h"
@@ -41,10 +40,10 @@
return wheel_cogging_torque.load(::std::memory_order_relaxed)[index];
}
-using ::frc971::control_loops::drivetrain::MakeIntegralHapticTriggerPlant;
using ::frc971::control_loops::drivetrain::MakeIntegralHapticTriggerObserver;
-using ::frc971::control_loops::drivetrain::MakeIntegralHapticWheelPlant;
+using ::frc971::control_loops::drivetrain::MakeIntegralHapticTriggerPlant;
using ::frc971::control_loops::drivetrain::MakeIntegralHapticWheelObserver;
+using ::frc971::control_loops::drivetrain::MakeIntegralHapticWheelPlant;
// Returns an identifier for the processor we're running on.
// This isn't guaranteed to be unique, but it should be close enough.
@@ -107,7 +106,8 @@
static_cast<float>(kMax - kMin);
}
-constexpr float InterpolateFloat(float x1, float x0, float y1, float y0, float x) {
+constexpr float InterpolateFloat(float x1, float x0, float y1, float y0,
+ float x) {
return (x - x0) * (y1 - y0) / (x1 - x0) + y0;
}
@@ -188,8 +188,7 @@
}
if (i >= 100) {
printf("reading1: %d %d a:%d e:%d\n", goal,
- static_cast<int>(goal_current * 10000.0f),
- static_cast<int>(encoder),
+ static_cast<int>(goal_current * 10000.0f), static_cast<int>(encoder),
static_cast<int>(error));
static int counting_up = 0;
if (absolute_encoder <= -6900) {
@@ -230,9 +229,9 @@
(void)CoggingCurrent1;
float goal_current = global_wheel_current.load(::std::memory_order_relaxed) +
WheelCoggingTorque(encoder);
- //float goal_current = CoggingCurrent1(encoder, absolute_encoder);
- // float goal_current = kWheelCoggingTorque[encoder];
- // float goal_current = 0.0f;
+ // float goal_current = CoggingCurrent1(encoder, absolute_encoder);
+ // float goal_current = kWheelCoggingTorque[encoder];
+ // float goal_current = 0.0f;
// Controller 0 is mechanical and doesn't need the motor controls.
if (processor_index == 0) {
@@ -244,8 +243,7 @@
->CurrentInterrupt(BalanceSimpleReadings(readings.currents), encoder);
global_wheel_angle.store(angle);
}
- //global_motor1.load(::std::memory_order_relaxed)->CycleFixedPhaseInterupt();
-
+ // global_motor1.load(::std::memory_order_relaxed)->CycleFixedPhaseInterupt();
/*
SmallInitReadings position_readings;
@@ -329,8 +327,7 @@
if (i >= 100) {
printf("reading0: %d %d a:%d e:%d\n", goal,
- static_cast<int>(goal_current * 10000.0f),
- static_cast<int>(encoder),
+ static_cast<int>(goal_current * 10000.0f), static_cast<int>(encoder),
static_cast<int>(error));
static int counting_up = 0;
if (absolute_encoder <= -1390) {
@@ -373,9 +370,9 @@
const float goal_current =
global_trigger_current.load(::std::memory_order_relaxed) +
TriggerCoggingTorque(encoder);
- //const float goal_current = kTriggerCoggingTorque[encoder];
- //const float goal_current = 0.0f;
- //const float goal_current = CoggingCurrent0(encoder, absolute_encoder);
+ // const float goal_current = kTriggerCoggingTorque[encoder];
+ // const float goal_current = 0.0f;
+ // const float goal_current = CoggingCurrent0(encoder, absolute_encoder);
if (processor_index == 0) {
global_motor0.load(::std::memory_order_relaxed)->CycleFixedPhaseInterupt(0);
@@ -386,8 +383,7 @@
->CurrentInterrupt(BalanceSimpleReadings(readings.currents), encoder);
global_trigger_angle.store(trigger_angle);
}
- //global_motor0.load(::std::memory_order_relaxed)->CycleFixedPhaseInterupt();
-
+ // global_motor0.load(::std::memory_order_relaxed)->CycleFixedPhaseInterupt();
/*
SmallInitReadings position_readings;
@@ -974,9 +970,9 @@
printf("stack start: %p\n", __stack_end__);
trigger_cogging_torque.store(processor_index == 0 ? kTriggerCoggingTorque0
- : kTriggerCoggingTorque1);
+ : kTriggerCoggingTorque1);
wheel_cogging_torque.store(processor_index == 0 ? kWheelCoggingTorque0
- : kWheelCoggingTorque1);
+ : kWheelCoggingTorque1);
printf("Zeroing motors for %d:%x\n", static_cast<int>(processor_index),
(unsigned int)ProcessorIdentifier());
diff --git a/motors/pistol_grip/drivers_station.cc b/motors/pistol_grip/drivers_station.cc
index eaa4486..a1cd6d9 100644
--- a/motors/pistol_grip/drivers_station.cc
+++ b/motors/pistol_grip/drivers_station.cc
@@ -2,6 +2,7 @@
// communicates over CAN with the one in the pistol grip controller.
#include <stdio.h>
+
#include <atomic>
#include "motors/core/kinetis.h"
diff --git a/motors/pistol_grip/motor_controls.cc b/motors/pistol_grip/motor_controls.cc
index 70e5464..a9c909f 100644
--- a/motors/pistol_grip/motor_controls.cc
+++ b/motors/pistol_grip/motor_controls.cc
@@ -26,8 +26,7 @@
#endif
constexpr int kPhaseBOffset = kCountsPerRevolution / 3;
-constexpr int kPhaseCOffset =
- 2 * kCountsPerRevolution / 3;
+constexpr int kPhaseCOffset = 2 * kCountsPerRevolution / 3;
// volts
constexpr double vcc = 14.0;
@@ -128,7 +127,8 @@
filtered_current_ = command_current;
}
const float goal_current_in = filtered_current_;
- static constexpr float kMaxEffectiveVcc = static_cast<float>(vcc * kMaxDutyCycle);
+ static constexpr float kMaxEffectiveVcc =
+ static_cast<float>(vcc * kMaxDutyCycle);
const float estimated_velocity_voltage =
estimated_velocity_ / static_cast<float>(Kv / 2.0);
const float max_current = (kMaxEffectiveVcc - estimated_velocity_voltage) /
@@ -143,7 +143,8 @@
const ::Eigen::Matrix<float, 3, 1> measured_current =
(::Eigen::Matrix<float, 3, 1>() << scale_current_reading(raw_currents[0]),
scale_current_reading(raw_currents[1]),
- scale_current_reading(raw_currents[2])).finished();
+ scale_current_reading(raw_currents[2]))
+ .finished();
const ComplexMatrix<3, 1> E1 =
E1Unrotated_ *
diff --git a/motors/pistol_grip/motor_controls.h b/motors/pistol_grip/motor_controls.h
index 5e333dc..253da4b 100644
--- a/motors/pistol_grip/motor_controls.h
+++ b/motors/pistol_grip/motor_controls.h
@@ -4,11 +4,11 @@
#include <array>
#include <complex>
+#include "Eigen/Dense"
+
#include "motors/math.h"
#include "motors/motor.h"
-#include "Eigen/Dense"
-
namespace frc971 {
namespace motors {
@@ -41,8 +41,8 @@
}
::std::array<float, 3> DoIteration(const float raw_currents[3],
- uint32_t theta,
- const float command_current) override;
+ uint32_t theta,
+ const float command_current) override;
int16_t Debug(uint32_t theta) override;
diff --git a/motors/pistol_grip/usb_forward.cc b/motors/pistol_grip/usb_forward.cc
index 19be857..b2a173e 100644
--- a/motors/pistol_grip/usb_forward.cc
+++ b/motors/pistol_grip/usb_forward.cc
@@ -1,11 +1,11 @@
// This file is designed to be compiled for Windows to run on the driver's
// station. It forwards UDP packets to the pistol grip controller over USB.
+#include <errno.h>
+#include <inttypes.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <errno.h>
#include <string.h>
#ifdef __WINNT__
@@ -14,8 +14,8 @@
#define PRId8 "hhd"
#define PRIx8 "hhx"
#else
-#include <netinet/in.h>
#include <arpa/inet.h>
+#include <netinet/in.h>
#endif
#include <string>
diff --git a/motors/print/itm.cc b/motors/print/itm.cc
index 6f9164e..7f472c0 100644
--- a/motors/print/itm.cc
+++ b/motors/print/itm.cc
@@ -3,6 +3,7 @@
#include <cstring>
#include "absl/types/span.h"
+
#include "motors/core/itm.h"
namespace frc971 {
diff --git a/motors/print/itm.h b/motors/print/itm.h
index edcb798..64e3092 100644
--- a/motors/print/itm.h
+++ b/motors/print/itm.h
@@ -2,6 +2,7 @@
#define MOTORS_PRINT_ITM_
#include "absl/types/span.h"
+
#include "motors/print/print.h"
namespace frc971 {
diff --git a/motors/print/print.h b/motors/print/print.h
index 34ba983..7ec7cf2 100644
--- a/motors/print/print.h
+++ b/motors/print/print.h
@@ -4,6 +4,7 @@
#include <memory>
#include "absl/types/span.h"
+
#include "aos/containers/sized_array.h"
#include "motors/core/kinetis.h"
diff --git a/motors/print/semihosting.cc b/motors/print/semihosting.cc
index 13bd78b..a266ad6 100644
--- a/motors/print/semihosting.cc
+++ b/motors/print/semihosting.cc
@@ -1,6 +1,7 @@
#include "motors/print/semihosting.h"
#include "absl/types/span.h"
+
#include "motors/core/semihosting.h"
namespace frc971 {
diff --git a/motors/print/semihosting.h b/motors/print/semihosting.h
index d323a7a..6094a67 100644
--- a/motors/print/semihosting.h
+++ b/motors/print/semihosting.h
@@ -2,6 +2,7 @@
#define MOTORS_PRINT_SEMIHOSTING_H_
#include "absl/types/span.h"
+
#include "motors/print/print.h"
namespace frc971 {
diff --git a/motors/print/uart.cc b/motors/print/uart.cc
index b635d23..4cfb001 100644
--- a/motors/print/uart.cc
+++ b/motors/print/uart.cc
@@ -1,9 +1,9 @@
#include "motors/print/uart.h"
-#include "motors/core/kinetis.h"
-
#include <atomic>
+#include "motors/core/kinetis.h"
+
namespace frc971 {
namespace motors {
namespace {
diff --git a/motors/seems_reasonable/spring.cc b/motors/seems_reasonable/spring.cc
index 4448b33..79ac751 100644
--- a/motors/seems_reasonable/spring.cc
+++ b/motors/seems_reasonable/spring.cc
@@ -1,9 +1,9 @@
#include "motors/seems_reasonable/spring.h"
-#include "frc971/zeroing/wrap.h"
-
#include <cmath>
+#include "frc971/zeroing/wrap.h"
+
namespace motors {
namespace seems_reasonable {
namespace {
diff --git a/motors/simple_receiver.cc b/motors/simple_receiver.cc
index 5f3af0a..bb10353 100644
--- a/motors/simple_receiver.cc
+++ b/motors/simple_receiver.cc
@@ -2,6 +2,7 @@
#include <inttypes.h>
#include <stdio.h>
+
#include <atomic>
#include <chrono>
#include <cmath>
@@ -72,23 +73,27 @@
chrono::duration_cast<chrono::nanoseconds>(
chrono::duration<float>(::motors::seems_reasonable::kDt)),
::motors::seems_reasonable::kRobotRadius,
- ::motors::seems_reasonable::kWheelRadius, ::motors::seems_reasonable::kV,
+ ::motors::seems_reasonable::kWheelRadius,
+ ::motors::seems_reasonable::kV,
::motors::seems_reasonable::kHighGearRatio,
::motors::seems_reasonable::kLowGearRatio,
::motors::seems_reasonable::kJ,
::motors::seems_reasonable::kMass,
kThreeStateDriveShifter,
- kThreeStateDriveShifter, true /* default_high_gear */,
+ kThreeStateDriveShifter,
+ true /* default_high_gear */,
0 /* down_offset if using constants use
- constants::GetValues().down_error */, 0.8 /* wheel_non_linearity */,
- 1.2 /* quickturn_wheel_multiplier */, 1.5 /* wheel_multiplier */,
+ constants::GetValues().down_error */
+ ,
+ 0.8 /* wheel_non_linearity */,
+ 1.2 /* quickturn_wheel_multiplier */,
+ 1.5 /* wheel_multiplier */,
};
return kDrivetrainConfig;
};
-
::std::atomic<PolyDrivetrain<float> *> global_polydrivetrain{nullptr};
::std::atomic<Spring *> global_spring{nullptr};
@@ -381,16 +386,18 @@
return;
}
}
- if (!AccelerometerWrite(
- 0x20, (1 << 5) /* Normal mode */ | (1 << 3) /* 100 Hz */ |
- (1 << 2) /* Z enabled */ | (1 << 1) /* Y enabled */ |
- (1 << 0) /* X enabled */,
- end_micros)) {
+ if (!AccelerometerWrite(0x20,
+ (1 << 5) /* Normal mode */ | (1 << 3) /* 100 Hz */ |
+ (1 << 2) /* Z enabled */ |
+ (1 << 1) /* Y enabled */ |
+ (1 << 0) /* X enabled */,
+ end_micros)) {
}
// If want to read LSB, need to enable BDU to avoid splitting reads.
- if (!AccelerometerWrite(0x23, (0 << 6) /* Data LSB at lower address */ |
- (3 << 4) /* 400g full scale */ |
- (0 << 0) /* 4-wire interface */,
+ if (!AccelerometerWrite(0x23,
+ (0 << 6) /* Data LSB at lower address */ |
+ (3 << 4) /* 400g full scale */ |
+ (0 << 0) /* 4-wire interface */,
end_micros)) {
}
accelerometer_inited = true;
@@ -775,7 +782,7 @@
NVIC_ENABLE_IRQ(IRQ_PIT_CH3);
printf("Done starting up2\n");
- //DoReceiverTest2();
+ // DoReceiverTest2();
while (true) {
}
diff --git a/motors/simpler_receiver.cc b/motors/simpler_receiver.cc
index c3fcec9..808fb83 100644
--- a/motors/simpler_receiver.cc
+++ b/motors/simpler_receiver.cc
@@ -3,6 +3,7 @@
#include <inttypes.h>
#include <stdio.h>
+
#include <atomic>
#include <chrono>
#include <cmath>
@@ -43,20 +44,25 @@
chrono::duration_cast<chrono::nanoseconds>(
chrono::duration<float>(::motors::seems_reasonable::kDt)),
::motors::seems_reasonable::kRobotRadius,
- ::motors::seems_reasonable::kWheelRadius, ::motors::seems_reasonable::kV,
+ ::motors::seems_reasonable::kWheelRadius,
+ ::motors::seems_reasonable::kV,
::motors::seems_reasonable::kHighGearRatio,
- ::motors::seems_reasonable::kLowGearRatio, ::motors::seems_reasonable::kJ,
- ::motors::seems_reasonable::kMass, kThreeStateDriveShifter,
- kThreeStateDriveShifter, true /* default_high_gear */,
- 0 /* down_offset */, 0.8 /* wheel_non_linearity */,
- 1.2 /* quickturn_wheel_multiplier */, 1.5 /* wheel_multiplier */,
+ ::motors::seems_reasonable::kLowGearRatio,
+ ::motors::seems_reasonable::kJ,
+ ::motors::seems_reasonable::kMass,
+ kThreeStateDriveShifter,
+ kThreeStateDriveShifter,
+ true /* default_high_gear */,
+ 0 /* down_offset */,
+ 0.8 /* wheel_non_linearity */,
+ 1.2 /* quickturn_wheel_multiplier */,
+ 1.5 /* wheel_multiplier */,
};
return kDrivetrainConfig;
};
-
::std::atomic<PolyDrivetrain<float> *> global_polydrivetrain{nullptr};
// Last width we received on each channel.
diff --git a/motors/usb/cdc.cc b/motors/usb/cdc.cc
index 575b4c1..e082156 100644
--- a/motors/usb/cdc.cc
+++ b/motors/usb/cdc.cc
@@ -1,7 +1,7 @@
#include "motors/usb/cdc.h"
-#include <string.h>
#include <stdint.h>
+#include <string.h>
#include "motors/core/time.h"
@@ -129,8 +129,8 @@
{
const auto interface_descriptor = CreateDescriptor(
interface_descriptor_length(), UsbDescriptorType::kInterface);
- interface_descriptor->AddByte(status_interface_); // bInterfaceNumber
- interface_descriptor->AddByte(0); // bAlternateSetting
+ interface_descriptor->AddByte(status_interface_); // bInterfaceNumber
+ interface_descriptor->AddByte(0); // bAlternateSetting
interface_descriptor->AddByte(1); // bNumEndpoints
interface_descriptor->AddByte(communications_class()); // bInterfaceClass
interface_descriptor->AddByte(
@@ -157,7 +157,7 @@
call_management->AddByte(
cdc_descriptor_subtype::call_management()); // bDescriptorSubtype
// We don't do call management.
- call_management->AddByte(0); // bmCapabilities
+ call_management->AddByte(0); // bmCapabilities
call_management->AddByte(data_interface_); // bDataInterface
}
@@ -184,7 +184,7 @@
cdc_union_descriptor->AddByte(
cdc_descriptor_subtype::union_function()); // bDescriptorSubtype
cdc_union_descriptor->AddByte(status_interface_); // bMasterInterface
- cdc_union_descriptor->AddByte(data_interface_); // bSlaveInterface
+ cdc_union_descriptor->AddByte(data_interface_); // bSlaveInterface
}
{
diff --git a/motors/usb/cdc.h b/motors/usb/cdc.h
index c02873d..f8f084b 100644
--- a/motors/usb/cdc.h
+++ b/motors/usb/cdc.h
@@ -3,8 +3,8 @@
#include <array>
-#include "motors/usb/usb.h"
#include "motors/usb/queue.h"
+#include "motors/usb/usb.h"
#include "motors/util.h"
// CDC (Communications Device Class) is a "class standard" which takes 30 pages
diff --git a/motors/usb/hid.cc b/motors/usb/hid.cc
index d885e75..f42842b 100644
--- a/motors/usb/hid.cc
+++ b/motors/usb/hid.cc
@@ -60,7 +60,7 @@
endpoint_descriptor->AddByte(
m_endpoint_attributes_interrupt()); // bmAttributes
endpoint_descriptor->AddUint16(in_endpoint_max_size()); // wMaxPacketSize
- endpoint_descriptor->AddByte(0x8); // bInterval
+ endpoint_descriptor->AddByte(0x8); // bInterval
}
}
diff --git a/motors/usb/hid.h b/motors/usb/hid.h
index 019231c..924cf37 100644
--- a/motors/usb/hid.h
+++ b/motors/usb/hid.h
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <string.h>
+
#include <array>
#include "motors/usb/usb.h"
diff --git a/motors/usb/interrupt_out.cc b/motors/usb/interrupt_out.cc
index 9af650a..568e5c5 100644
--- a/motors/usb/interrupt_out.cc
+++ b/motors/usb/interrupt_out.cc
@@ -35,13 +35,12 @@
endpoint_descriptor->AddByte(
m_endpoint_attributes_interrupt()); // bmAttributes
endpoint_descriptor->AddUint16(kSize); // wMaxPacketSize
- endpoint_descriptor->AddByte(1); // bInterval
+ endpoint_descriptor->AddByte(1); // bInterval
}
}
void InterruptOut::HandleOutFinished(int endpoint, BdtEntry *bdt_entry) {
if (endpoint == endpoint_) {
-
DisableInterrupts disable_interrupts;
if (first_rx_held_ == nullptr) {
first_rx_held_ = bdt_entry;
diff --git a/motors/usb/interrupt_out.h b/motors/usb/interrupt_out.h
index 9a7232c..31852f9 100644
--- a/motors/usb/interrupt_out.h
+++ b/motors/usb/interrupt_out.h
@@ -1,12 +1,12 @@
#ifndef MOTORS_USB_INTERRUPT_OUT_H_
#define MOTORS_USB_INTERRUPT_OUT_H_
-#include "motors/usb/usb.h"
-#include "motors/util.h"
-
#include <array>
#include <string>
+#include "motors/usb/usb.h"
+#include "motors/util.h"
+
namespace frc971 {
namespace teensy {
diff --git a/motors/usb/queue.h b/motors/usb/queue.h
index 669abe4..f7a7e77 100644
--- a/motors/usb/queue.h
+++ b/motors/usb/queue.h
@@ -1,8 +1,8 @@
#ifndef MOTORS_USB_QUEUE_H_
#define MOTORS_USB_QUEUE_H_
-#include <memory>
#include <atomic>
+#include <memory>
namespace frc971 {
namespace teensy {
@@ -28,9 +28,7 @@
write_cursor_.load(::std::memory_order_relaxed));
}
- size_t space_available() const {
- return size_ - data_queued() - 1;
- }
+ size_t space_available() const { return size_ - data_queued() - 1; }
bool empty() const {
return read_cursor_.load(::std::memory_order_relaxed) ==
diff --git a/motors/usb/usb.cc b/motors/usb/usb.cc
index e4a2b26..2c64b61 100644
--- a/motors/usb/usb.cc
+++ b/motors/usb/usb.cc
@@ -76,9 +76,9 @@
// The total number of endpoints supported by this hardware.
constexpr int number_endpoints() { return 16; }
-__attribute__((aligned(512))) BdtEntry
- usb0_buffer_descriptor_table[number_endpoints() * 2 /* rx/tx */ *
- 2 /* even/odd */];
+__attribute__((aligned(512)))
+BdtEntry usb0_buffer_descriptor_table[number_endpoints() * 2 /* rx/tx */ *
+ 2 /* even/odd */];
// Returns the specified BDT entry.
BdtEntry *MutableBdtEntry(int endpoint, Direction direction, EvenOdd odd) {
@@ -121,13 +121,13 @@
device_descriptor_ =
device_descriptor_list_.CreateDescriptor(18, UsbDescriptorType::kDevice);
- device_descriptor_->AddUint16(0x0200); // bcdUSB
- device_descriptor_->AddByte(iad_device_class()); // bDeviceClass
+ device_descriptor_->AddUint16(0x0200); // bcdUSB
+ device_descriptor_->AddByte(iad_device_class()); // bDeviceClass
device_descriptor_->AddByte(iad_device_subclass()); // bDeviceSubClass
device_descriptor_->AddByte(iad_device_protocol()); // bDeviceProtocol
- device_descriptor_->AddByte(kEndpoint0MaxSize); // bMaxPacketSize0
- device_descriptor_->AddUint16(vendor_id); // idVendor
- device_descriptor_->AddUint16(product_id); // idProduct
+ device_descriptor_->AddByte(kEndpoint0MaxSize); // bMaxPacketSize0
+ device_descriptor_->AddUint16(vendor_id); // idVendor
+ device_descriptor_->AddUint16(product_id); // idProduct
// Increment this whenever you need Windows boxes to actually pay attention to
// changes.
device_descriptor_->AddUint16(25); // bcdDevice
@@ -211,7 +211,7 @@
config_descriptor_->AddByte(0); // iConfiguration
config_descriptor_->AddByte((1 << 7) /* Reserved */ |
(1 << 6) /* Self-powered */); // bmAttribute
- config_descriptor_->AddByte(2 /* 4mA */); // bMaxPower
+ config_descriptor_->AddByte(2 /* 4mA */); // bMaxPower
device_descriptor_.reset();
config_descriptor_.reset();
@@ -440,9 +440,9 @@
break;
case UsbPid::kOut:
- for (UsbFunction *function : functions_) {
- switch (function->HandleEndpoint0OutPacket(
- bdt_entry->address, G_USB_BD_BC(bdt_entry->buffer_descriptor))) {
+ for (UsbFunction *function : functions_) {
+ switch (function->HandleEndpoint0OutPacket(
+ bdt_entry->address, G_USB_BD_BC(bdt_entry->buffer_descriptor))) {
case SetupResponse::kIgnored:
break;
case SetupResponse::kHandled:
@@ -473,7 +473,7 @@
// TODO(Brian): Keep track of which direction it is and how much we've
// finished so we actually know when to stall it, both here and for
// kOut tokens.
- //StallEndpoint0();
+ // StallEndpoint0();
}
// If we have a new address, there is nothing left in the setup request
@@ -755,19 +755,27 @@
// Microsoft is going to set them to; not like they document it
// anywhere obvious...
if (descriptor_index == 0xEE && setup_packet.index == 0) {
- static uint8_t
- kMicrosoftOsStringDescriptor
- [] = {
- 0x12, // bLength
- static_cast<uint8_t>(
- UsbDescriptorType::kString), // bDescriptorType
- 0x4D,
- 0x00, 0x53, 0x00, 0x46, 0x00, 0x54, 0x00, 0x31,
- 0x00, 0x30, 0x00, 0x30,
- 0x00, // qwSignature
- microsoft_vendor_code(), // bMS_VendorCode
- 0x00 // bPad
- };
+ static uint8_t kMicrosoftOsStringDescriptor[] = {
+ 0x12, // bLength
+ static_cast<uint8_t>(
+ UsbDescriptorType::kString), // bDescriptorType
+ 0x4D,
+ 0x00,
+ 0x53,
+ 0x00,
+ 0x46,
+ 0x00,
+ 0x54,
+ 0x00,
+ 0x31,
+ 0x00,
+ 0x30,
+ 0x00,
+ 0x30,
+ 0x00, // qwSignature
+ microsoft_vendor_code(), // bMS_VendorCode
+ 0x00 // bPad
+ };
QueueEndpoint0Data(
reinterpret_cast<char *>(kMicrosoftOsStringDescriptor),
::std::min<int>(setup_packet.length,
diff --git a/motors/usb/usb.h b/motors/usb/usb.h
index 1273efd..1117bc8 100644
--- a/motors/usb/usb.h
+++ b/motors/usb/usb.h
@@ -3,9 +3,10 @@
#include <assert.h>
#include <string.h>
+
+#include <memory>
#include <string>
#include <vector>
-#include <memory>
#include "aos/macros.h"
#include "motors/core/kinetis.h"
@@ -175,9 +176,7 @@
end_index_(end_index),
next_index_(start_index_) {}
- char *data() const {
- return &descriptor_list_->data_[0];
- }
+ char *data() const { return &descriptor_list_->data_[0]; }
UsbDescriptorList *const descriptor_list_;
const int start_index_, end_index_;
diff --git a/motors/util.h b/motors/util.h
index 3ac6213..8e7ce1c 100644
--- a/motors/util.h
+++ b/motors/util.h
@@ -1,14 +1,13 @@
#ifndef MOTORS_UTIL_H_
#define MOTORS_UTIL_H_
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
#include "motors/core/kinetis.h"
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
// This bitband register for a specific bit of a given peripheral register.
@@ -61,12 +60,12 @@
#define CAN_MCR_IRMQ ((uint32_t)(1 << 16))
#define CAN_MCR_LPRIOEN ((uint32_t)(1 << 13))
#define CAN_MCR_AEN ((uint32_t)(1 << 12))
-#define CAN_MCR_IDAM(n) ((uint32_t)(((n) & 3) << 8))
-#define CAN_MCR_MAXMB(n) ((uint32_t)((n) & 0x7F))
-#define CAN_CTRL1_PRESDIV(n) ((uint32_t)(((n) & 0xFF) << 24))
-#define CAN_CTRL1_RJW(n) ((uint32_t)(((n) & 3) << 22))
-#define CAN_CTRL1_PSEG1(n) ((uint32_t)(((n) & 7) << 19))
-#define CAN_CTRL1_PSEG2(n) ((uint32_t)(((n) & 7) << 16))
+#define CAN_MCR_IDAM(n) ((uint32_t)(((n)&3) << 8))
+#define CAN_MCR_MAXMB(n) ((uint32_t)((n)&0x7F))
+#define CAN_CTRL1_PRESDIV(n) ((uint32_t)(((n)&0xFF) << 24))
+#define CAN_CTRL1_RJW(n) ((uint32_t)(((n)&3) << 22))
+#define CAN_CTRL1_PSEG1(n) ((uint32_t)(((n)&7) << 19))
+#define CAN_CTRL1_PSEG2(n) ((uint32_t)(((n)&7) << 16))
#define CAN_CTRL1_BOFFMSK ((uint32_t)(1 << 15))
#define CAN_CTRL1_ERRMSK ((uint32_t)(1 << 14))
#define CAN_CTRL1_CLKSRC ((uint32_t)(1 << 13))
@@ -78,7 +77,7 @@
#define CAN_CTRL1_TSYN ((uint32_t)(1 << 5))
#define CAN_CTRL1_LBUF ((uint32_t)(1 << 4))
#define CAN_CTRL1_LOM ((uint32_t)(1 << 3))
-#define CAN_CTRL1_PROPSEG(n) ((uint32_t)((n) & 7))
+#define CAN_CTRL1_PROPSEG(n) ((uint32_t)((n)&7))
#define CAN_ESR1_SYNCH ((uint32_t)(1 << 18))
#define CAN_ESR1_TWRNINT ((uint32_t)(1 << 17))
#define CAN_ESR1_RWRNINT ((uint32_t)(1 << 16))
@@ -97,8 +96,8 @@
#define CAN_ESR1_ERRINT ((uint32_t)(1 << 1))
#define CAN_ESR1_WAKINT ((uint32_t)1)
#define CAN_CTRL2_WRMFRZ ((uint32_t)(1 << 28))
-#define CAN_CTRL2_RFFN(n) ((uint32_t)(((n) & 0xF) << 24))
-#define CAN_CTRL2_TASD(n) ((uint32_t)(((n) & 0x1F) << 19))
+#define CAN_CTRL2_RFFN(n) ((uint32_t)(((n)&0xF) << 24))
+#define CAN_CTRL2_TASD(n) ((uint32_t)(((n)&0x1F) << 19))
#define CAN_CTRL2_MRP ((uint32_t)(1 << 18))
#define CAN_CTRL2_RRS ((uint32_t)(1 << 17))
#define CAN_CTRL2_EACEN ((uint32_t)(1 << 16))
@@ -115,13 +114,13 @@
#define CAN0_RXIMRS ((volatile uint32_t *)0x40024880)
#define CAN1_MESSAGES ((volatile CanMessageBuffer *)0x400A4080)
#define CAN1_RXIMRS ((volatile uint32_t *)0x400A4880)
-#define CAN_MB_CONTROL_INSERT_DLC(dlc) ((uint32_t)(((dlc) & 0xF) << 16))
+#define CAN_MB_CONTROL_INSERT_DLC(dlc) ((uint32_t)(((dlc)&0xF) << 16))
#define CAN_MB_CONTROL_EXTRACT_DLC(control_timestamp) \
((control_timestamp >> 16) & 0xF)
#define CAN_MB_CONTROL_RTR ((uint32_t)(1 << 20))
#define CAN_MB_CONTROL_IDE ((uint32_t)(1 << 21))
#define CAN_MB_CONTROL_SRR ((uint32_t)(1 << 22))
-#define CAN_MB_CONTROL_INSERT_CODE(n) ((uint32_t)(((n) & 0xF) << 24))
+#define CAN_MB_CONTROL_INSERT_CODE(n) ((uint32_t)(((n)&0xF) << 24))
#define CAN_MB_CONTROL_EXTRACT_CODE(n) ((uint32_t)(((n) >> 24) & 0xF))
#define CAN_MB_CONTROL_CODE_BUSY_MASK CAN_MB_CONTROL_INSERT_CODE(1)
#define CAN_MB_PRIO_ID_PRIORITY_MASK ((uint32_t)((1 << 29) - 1))
@@ -135,11 +134,11 @@
#define CAN_MB_CODE_TX_DATA 0xC
#define CAN_MB_CODE_TX_REMOTE 0xC
#define CAN_MB_CODE_TX_TANSWER 0xE
-#define CAN_MB_CODE_IS_BUSY(code) ((code) & 1)
+#define CAN_MB_CODE_IS_BUSY(code) ((code)&1)
// We have to define these, and leave them defined, because the C preprocessor
// is annoying...
-#define REALLY_DO_CONCATENATE(x, y, z) x ## y ## z
+#define REALLY_DO_CONCATENATE(x, y, z) x##y##z
#define DO_CONCATENATE(x, y, z) REALLY_DO_CONCATENATE(x, y, z)
// Index-parameterized access to various registers from various peripherals.
@@ -204,7 +203,7 @@
typedef struct {
#define FOR_BIG_FTM_REGISTER(name) const uint32_t _reserved_##name;
#define FOR_LITTLE_FTM_REGISTER(name) volatile uint32_t name;
- ALL_FTM_REGISTERS
+ ALL_FTM_REGISTERS
#undef FOR_BIG_FTM_REGISTER
#undef FOR_LITTLE_FTM_REGISTER
#undef FOR_BOTH_FTM_REGISTER
@@ -248,7 +247,7 @@
// constexpr log base 2, which fails to compile for non-power-of-2 inputs.
// This is a silly implementation to use at runtime.
-template<typename T>
+template <typename T>
constexpr T ConstexprLog2(T i) {
if (i == 0) {
__builtin_abort();