blob: e0c4d903bdcdb5583729cd040830a878f3ab392a [file] [log] [blame]
Brian Silverman246cb222019-02-02 16:38:18 -08001#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
16namespace frc971 {
17namespace jevois {
18
19constexpr 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}
25static_assert(spi_transfer_size() == 41, "hand math is wrong");
26using SpiTransfer = std::array<char, spi_transfer_size()>;
27
28SpiTransfer SpiPackToRoborio(const TeensyToRoborio &message);
29tl::optional<TeensyToRoborio> SpiUnpackToRoborio(const SpiTransfer &transfer);
30
31} // namespace jevois
32} // namespace frc971
33
34#endif // Y2019_JEVOIS_SPI_H_