Finish converting GSL to absl::Span
One less dependency.
Change-Id: Iaac25a3c1312a21a8a2b77b8cfee2463bdb51196
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/motors/peripheral/BUILD b/motors/peripheral/BUILD
index a42d502..7765ce1 100644
--- a/motors/peripheral/BUILD
+++ b/motors/peripheral/BUILD
@@ -45,7 +45,7 @@
hdrs = ["uart_buffer.h"],
visibility = ["//visibility:public"],
deps = [
- "//third_party/GSL",
+ "@com_google_absl//absl/types:span",
],
)
@@ -72,7 +72,7 @@
"//aos/containers:sized_array",
"//motors:util",
"//motors/core",
- "//third_party/GSL",
+ "@com_google_absl//absl/types:span",
],
)
@@ -99,6 +99,6 @@
":uart_buffer",
"//motors:util",
"//motors/core",
- "//third_party/GSL",
+ "@com_google_absl//absl/types:span",
],
)
diff --git a/motors/peripheral/spi.cc b/motors/peripheral/spi.cc
index c0bb767..8c4ad11 100644
--- a/motors/peripheral/spi.cc
+++ b/motors/peripheral/spi.cc
@@ -57,7 +57,7 @@
spi_.FlushInterruptRequests();
}
-void InterruptBufferedSpi::Write(gsl::span<const char> data,
+void InterruptBufferedSpi::Write(absl::Span<const char> data,
DisableInterrupts *disable_interrupts) {
frames_to_receive_ += data.size();
// Until we get all of the data queued, we'll call WriteFrames from our
@@ -82,11 +82,11 @@
}
}
-gsl::span<char> InterruptBufferedSpi::Read(
- gsl::span<char> buffer, DisableInterrupts *disable_interrupts) {
+absl::Span<char> InterruptBufferedSpi::Read(
+ absl::Span<char> buffer, DisableInterrupts *disable_interrupts) {
size_t bytes_read = 0;
{
- const gsl::span<const char> read_data =
+ const absl::Span<const char> read_data =
receive_buffer_.PopSpan(buffer.size());
std::copy(read_data.begin(), read_data.end(), buffer.begin());
bytes_read += read_data.size();
@@ -95,7 +95,7 @@
ReenableInterrupts{disable_interrupts};
{
- const gsl::span<const char> read_data =
+ const absl::Span<const char> read_data =
receive_buffer_.PopSpan(buffer.size() - bytes_read);
std::copy(read_data.begin(), read_data.end(),
buffer.subspan(bytes_read).begin());
diff --git a/motors/peripheral/spi.h b/motors/peripheral/spi.h
index 1cfb385..5361f91 100644
--- a/motors/peripheral/spi.h
+++ b/motors/peripheral/spi.h
@@ -1,10 +1,10 @@
#ifndef MOTORS_PERIPHERAL_SPI_H_
#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"
-#include "third_party/GSL/include/gsl/gsl"
namespace frc971 {
namespace teensy {
@@ -41,21 +41,11 @@
}
// Calling code must synchronize all of these.
- void EnableTransmitInterrupt() {
- rser_value_ |= M_SPI_TFFF_RE;
- }
- void DisableTransmitInterrupt() {
- rser_value_ &= ~M_SPI_TFFF_RE;
- }
- void EnableReceiveInterrupt() {
- rser_value_ |= M_SPI_RFDF_RE;
- }
- void DisableReceiveInterrupt() {
- rser_value_ &= ~M_SPI_RFDF_RE;
- }
- void FlushInterruptRequests() {
- module_->RSER = rser_value_;
- }
+ void EnableTransmitInterrupt() { rser_value_ |= M_SPI_TFFF_RE; }
+ void DisableTransmitInterrupt() { rser_value_ &= ~M_SPI_TFFF_RE; }
+ void EnableReceiveInterrupt() { rser_value_ |= M_SPI_RFDF_RE; }
+ void DisableReceiveInterrupt() { rser_value_ &= ~M_SPI_RFDF_RE; }
+ void FlushInterruptRequests() { module_->RSER = rser_value_; }
private:
KINETISK_SPI_t *const module_;
@@ -88,18 +78,20 @@
// Queues up the given data for immediate writing. Blocks only if the queue
// fills up before all of data is enqueued.
- void Write(gsl::span<const char> data, DisableInterrupts *disable_interrupts);
+ void Write(absl::Span<const char> data,
+ DisableInterrupts *disable_interrupts);
// Reads currently available data.
// Returns all the data which is currently available (possibly none);
// buffer is where to store the result. The return value will be a subspan of
// this.
- gsl::span<char> Read(gsl::span<char> buffer,
- DisableInterrupts *disable_interrupts);
+ absl::Span<char> Read(absl::Span<char> buffer,
+ DisableInterrupts *disable_interrupts);
// Should be called as the body of the interrupt handler.
void HandleInterrupt(const DisableInterrupts &disable_interrupts) {
- while (ReadAndWriteFrame(true, disable_interrupts)) {}
+ while (ReadAndWriteFrame(true, disable_interrupts)) {
+ }
spi_.FlushInterruptRequests();
}
diff --git a/motors/peripheral/uart.cc b/motors/peripheral/uart.cc
index 9cd4014..6e48320 100644
--- a/motors/peripheral/uart.cc
+++ b/motors/peripheral/uart.cc
@@ -52,12 +52,12 @@
module_->RWFIFO = 1;
}
-void Uart::DoWrite(gsl::span<const char> data) {
+void Uart::DoWrite(absl::Span<const char> data) {
// In theory, we could be more efficient about this by writing the number of
// bytes we know there's space for and only calling SpaceAvailable() (or
// otherwise reading S1) before the final one. In practice, the FIFOs are so
// short on this part it probably won't help anything.
- for (int i = 0; i < data.size(); ++i) {
+ for (size_t i = 0; i < data.size(); ++i) {
while (!SpaceAvailable()) {
}
WriteCharacter(data[i]);
@@ -93,7 +93,7 @@
}
}
-void InterruptBufferedUart::Write(gsl::span<const char> data) {
+void InterruptBufferedUart::Write(absl::Span<const char> data) {
DisableInterrupts disable_interrupts;
uart_.EnableTransmitInterrupt(disable_interrupts);
while (!data.empty()) {
@@ -104,18 +104,18 @@
}
}
-gsl::span<char> InterruptBufferedUart::Read(gsl::span<char> buffer) {
+absl::Span<char> InterruptBufferedUart::Read(absl::Span<char> buffer) {
size_t bytes_read = 0;
{
DisableInterrupts disable_interrupts;
- const gsl::span<const char> read_data =
+ const absl::Span<const char> read_data =
receive_buffer_.PopSpan(buffer.size());
std::copy(read_data.begin(), read_data.end(), buffer.begin());
bytes_read += read_data.size();
}
{
DisableInterrupts disable_interrupts;
- const gsl::span<const char> read_data =
+ const absl::Span<const char> read_data =
receive_buffer_.PopSpan(buffer.size() - bytes_read);
std::copy(read_data.begin(), read_data.end(),
buffer.subspan(bytes_read).begin());
diff --git a/motors/peripheral/uart.h b/motors/peripheral/uart.h
index ffb1529..d51bcfe 100644
--- a/motors/peripheral/uart.h
+++ b/motors/peripheral/uart.h
@@ -1,11 +1,11 @@
#ifndef MOTORS_PERIPHERAL_UART_H_
#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"
#include "motors/util.h"
-#include "third_party/GSL/include/gsl/gsl"
namespace frc971 {
namespace teensy {
@@ -22,7 +22,7 @@
void Initialize(int baud_rate);
// Blocks until all of the data is at least queued.
- void Write(gsl::span<const char> data, const DisableInterrupts &) {
+ void Write(absl::Span<const char> data, const DisableInterrupts &) {
DoWrite(data);
}
@@ -77,7 +77,7 @@
module_->C2 = c2_value_;
}
- void DoWrite(gsl::span<const char> data);
+ void DoWrite(absl::Span<const char> data);
aos::SizedArray<char, 4> DoRead();
KINETISK_UART_t *const module_;
@@ -100,13 +100,13 @@
// Queues up the given data for immediate writing. Blocks only if the queue
// fills up before all of data is enqueued.
- void Write(gsl::span<const char> data);
+ void Write(absl::Span<const char> data);
// Reads currently available data.
// Returns all the data which is currently available (possibly none);
// buffer is where to store the result. The return value will be a subspan of
// this.
- gsl::span<char> Read(gsl::span<char> buffer);
+ absl::Span<char> Read(absl::Span<char> buffer);
// Should be called as the body of the interrupt handler.
void HandleInterrupt(const DisableInterrupts &disable_interrupts) {
diff --git a/motors/peripheral/uart_buffer.h b/motors/peripheral/uart_buffer.h
index 19015bb..c324a2d 100644
--- a/motors/peripheral/uart_buffer.h
+++ b/motors/peripheral/uart_buffer.h
@@ -2,8 +2,9 @@
#define MOTORS_PERIPHERAL_UART_BUFFER_H_
#include <array>
+#include <cstring>
-#include "third_party/GSL/include/gsl/gsl"
+#include "absl/types/span.h"
namespace frc971 {
namespace teensy {
@@ -13,14 +14,14 @@
class UartBuffer {
public:
// Returns the number of characters added.
- __attribute__((warn_unused_result)) int PushSpan(gsl::span<const char> data);
+ __attribute__((warn_unused_result)) int PushSpan(absl::Span<const char> data);
// max is the maximum size the returned span should be.
// The data in the result is only valid until another method is called.
// Note that this may not return all available data when doing so would
// require wrapping around, but it will always return a non-empty span if any
// data is available.
- gsl::span<const char> PopSpan(int max);
+ absl::Span<const char> PopSpan(int max);
bool empty() const { return size_ == 0; }
bool full() const { return size_ == kSize; }
@@ -44,7 +45,7 @@
};
template <int kSize>
-int UartBuffer<kSize>::PushSpan(gsl::span<const char> data) {
+int UartBuffer<kSize>::PushSpan(absl::Span<const char> data) {
const int end_location = (start_ + size_) % kSize;
const int remaining_end = ::std::min(kSize - size_, kSize - end_location);
const int on_end = ::std::min<int>(data.size(), remaining_end);
@@ -65,9 +66,10 @@
}
template <int kSize>
-gsl::span<const char> UartBuffer<kSize>::PopSpan(int max) {
+absl::Span<const char> UartBuffer<kSize>::PopSpan(int max) {
const size_t result_size = std::min(max, std::min(kSize - start_, size_));
- const auto result = gsl::span<const char>(data_).subspan(start_, result_size);
+ const auto result =
+ absl::Span<const char>(data_).subspan(start_, result_size);
start_ = (start_ + result_size) % kSize;
size_ -= result_size;
return result;