Brian Silverman | 246cb22 | 2019-02-02 16:38:18 -0800 | [diff] [blame] | 1 | #ifndef Y2019_JEVOIS_SPI_H_ |
| 2 | #define Y2019_JEVOIS_SPI_H_ |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | |
| 6 | #include <array> |
| 7 | |
| 8 | #include "third_party/optional/tl/optional.hpp" |
| 9 | #include "y2019/jevois/structures.h" |
| 10 | |
| 11 | // This file manages serializing and deserializing the various structures for |
| 12 | // transport via SPI. |
| 13 | // |
| 14 | // Our SPI transfers are fixed-size to simplify everything. |
| 15 | |
| 16 | namespace frc971 { |
| 17 | namespace jevois { |
| 18 | |
| 19 | constexpr size_t spi_transfer_size() { |
| 20 | // The teensy->RoboRIO side is way bigger, so just calculate that. |
| 21 | return 3 /* 3 frames */ * |
| 22 | (1 /* age */ + 3 /* targets */ * 4 /* target size */) + |
| 23 | 2 /* CRC-16 */; |
| 24 | } |
| 25 | static_assert(spi_transfer_size() == 41, "hand math is wrong"); |
| 26 | using SpiTransfer = std::array<char, spi_transfer_size()>; |
| 27 | |
| 28 | SpiTransfer SpiPackToRoborio(const TeensyToRoborio &message); |
| 29 | tl::optional<TeensyToRoborio> SpiUnpackToRoborio(const SpiTransfer &transfer); |
| 30 | |
| 31 | } // namespace jevois |
| 32 | } // namespace frc971 |
| 33 | |
| 34 | #endif // Y2019_JEVOIS_SPI_H_ |