mirror of
https://github.com/halleysfifthinc/AVCLAN-Mockingboard.git
synced 2026-08-07 01:13:18 +00:00
Add C++ Peripheral class
This commit is contained in:
+35
-14
@@ -53,20 +53,6 @@ uint8_t AVCLAN_readbitsi(uint8_t *bits, uint8_t len);
|
||||
uint8_t AVCLAN_readbitsl(uint16_t *bits, int8_t len);
|
||||
uint8_t AVCLAN_readbyte(uint8_t *byte);
|
||||
|
||||
#define AVCLAN_sendbits(bits, len) \
|
||||
_Generic((bits), \
|
||||
const uint16_t *: AVCLAN_sendbitsl, \
|
||||
uint16_t *: AVCLAN_sendbitsl, \
|
||||
const uint8_t *: AVCLAN_sendbitsi, \
|
||||
uint8_t *: AVCLAN_sendbitsi)(bits, len)
|
||||
|
||||
#define AVCLAN_readbits(bits, len) \
|
||||
_Generic((bits), \
|
||||
const uint16_t *: AVCLAN_readbitsl, \
|
||||
uint16_t *: AVCLAN_readbitsl, \
|
||||
const uint8_t *: AVCLAN_readbitsi, \
|
||||
uint8_t *: AVCLAN_readbitsi)(bits, len)
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Sample and dump bus bit timing over the serial link (REPL `M`).
|
||||
void AVCLan_Measure(void);
|
||||
@@ -75,3 +61,38 @@ void AVCLan_Measure(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
template <class T, auto N> avclan_bit_t AVCLAN_sendbits(T bits);
|
||||
template <class T, auto N> avclan_bit_t AVCLAN_readbits(T *bits);
|
||||
|
||||
// Temporary specializations bridging to legacy C API
|
||||
// Replace with proper (single?) template when phy has been ported
|
||||
template <auto N>
|
||||
requires(N <= 8)
|
||||
avclan_bit_t AVCLAN_sendbits(uint8_t bits) {
|
||||
return AVCLAN_sendbitsi(&bits, N);
|
||||
}
|
||||
template <auto N>
|
||||
requires(N <= 16)
|
||||
avclan_bit_t AVCLAN_sendbits(uint16_t bits) {
|
||||
return AVCLAN_sendbitsl(&bits, N);
|
||||
}
|
||||
template <> inline avclan_bit_t AVCLAN_sendbits<8>(uint8_t byte) {
|
||||
return AVCLAN_sendbyte(&byte);
|
||||
}
|
||||
|
||||
template <auto N>
|
||||
requires(N <= 8)
|
||||
avclan_bit_t AVCLAN_readbits(uint8_t *bits) {
|
||||
return static_cast<avclan_bit_t>(AVCLAN_readbitsi(bits, N));
|
||||
}
|
||||
template <auto N>
|
||||
requires(N <= 16)
|
||||
avclan_bit_t AVCLAN_readbits(uint16_t *bits) {
|
||||
return static_cast<avclan_bit_t>(AVCLAN_readbitsl(bits, N));
|
||||
}
|
||||
template <> inline avclan_bit_t AVCLAN_readbits<8>(uint8_t *byte) {
|
||||
return static_cast<avclan_bit_t>(AVCLAN_readbyte(byte));
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user