Add C++ Bus class for the physical layer interface

This commit is contained in:
Allen Hill
2026-06-25 20:40:10 -07:00
parent 67ba8e774c
commit d98cc8acad
7 changed files with 344 additions and 202 deletions
+23 -16
View File
@@ -5,6 +5,8 @@
#pragma once
#include "avclan_defs.h"
#include "bus.hpp"
#include <cstdint>
namespace avclan {
@@ -14,33 +16,38 @@ public:
// Error enums are ordered such that a lower numeric value corresponds to
// more progress/success before an error occured, with 0 being no errors
enum class Read : uint8_t {
BAD_DATA_PARITY = rBAD_DATA_PARITY, // = 0x01
BAD_LENGTH_RANGE = rBAD_LENGTH_RANGE,
BAD_LENGTH_PARITY = rBAD_LENGTH_PARITY,
BAD_PERIPHERAL_PARITY = rBAD_PERIPHERAL_PARITY,
BAD_CONTROLLER_PARITY = rBAD_CONTROLLER_PARITY,
BAD_CONTROL_PARITY = rBAD_CONTROL_PARITY,
STARTBIT_TOO_SHORT = rSTARTBIT_TOO_SHORT,
STARTBIT_TOO_LONG = rSTARTBIT_TOO_LONG,
BAD_STARTBIT = rLATCHED_COMPARATOR,
BAD_DATA_PARITY = 0x01,
BAD_LENGTH_RANGE,
BAD_LENGTH_PARITY,
BAD_PERIPHERAL_PARITY,
BAD_CONTROLLER_PARITY,
BAD_CONTROL_PARITY,
STARTBIT_TOO_SHORT =
static_cast<uint8_t>(Bus::Error::Read::STARTBIT_TOO_SHORT),
STARTBIT_TOO_LONG =
static_cast<uint8_t>(Bus::Error::Read::STARTBIT_TOO_LONG),
BAD_STARTBIT = static_cast<uint8_t>(Bus::Error::Read::BAD_STARTBIT),
};
enum class Send : uint8_t {
NAK_DATA = sNAK_DATA, // = 0x01
NAK_MESSAGE_LENGTH = sNAK_MESSAGE_LENGTH,
NAK_CONTROL = sNAK_CONTROL,
NAK_ADDRESS = sNAK_ADDRESS,
BUSY = sBUSY,
MUTED = sMUTED,
NAK_DATA = 0x01,
NAK_MESSAGE_LENGTH,
NAK_CONTROL,
NAK_ADDRESS,
BUSY,
MUTED,
};
};
Peripheral(uint16_t address) : address{address} {}
Peripheral(Bus bus, uint16_t address) : bus{bus}, address{address} {
bus.init();
}
Error::Read read(AVCLAN_frame_t *in, log_t print);
Error::Send send(const AVCLAN_frame_t *out, log_t print);
private:
Bus bus;
const uint16_t address;
};
} // namespace avclan