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/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]);
     }
   }
 }