mirror of
https://github.com/halleysfifthinc/Toyota-AVC-LAN
synced 2025-06-10 01:16:16 +00:00
Add generic dispatch for AVCLAN_sendbits; simplifies calling use for 12 bit words
This commit is contained in:
parent
208fe2a097
commit
2a5b95c3f5
@ -287,33 +287,15 @@ uint8_t AVCLan_Send_ACK() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t AVCLan_Send_Byte(uint8_t byte, uint8_t len) {
|
#define AVCLAN_sendbits(bits, len) \
|
||||||
uint8_t b;
|
_Generic((bits), \
|
||||||
uint8_t parity = 0;
|
const uint16_t *: AVCLAN_sendbitsl, \
|
||||||
|
uint16_t *: AVCLAN_sendbitsl, \
|
||||||
|
const uint8_t *: AVCLAN_sendbitsi, \
|
||||||
|
uint8_t *: AVCLAN_sendbitsi)(bits, len)
|
||||||
|
|
||||||
if (len == 8) {
|
// Send `len` bits on the AVCLAN bus; returns the even parity
|
||||||
b = byte;
|
uint8_t AVCLAN_sendbitsi(const uint8_t *byte, int8_t len) {
|
||||||
} else {
|
|
||||||
b = byte << (8 - len);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
if (b & 0x80) {
|
|
||||||
AVCLan_Send_Bit1();
|
|
||||||
parity++;
|
|
||||||
} else {
|
|
||||||
AVCLan_Send_Bit0();
|
|
||||||
}
|
|
||||||
len--;
|
|
||||||
if (!len) {
|
|
||||||
// if (INPUT_IS_SET) RS232_Print("SBER\n"); // Send Bit ERror
|
|
||||||
return (parity & 1);
|
|
||||||
}
|
|
||||||
b = b << 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t AVCLAN_sendbits(const uint8_t *byte, int8_t len) {
|
|
||||||
uint8_t b = *byte;
|
uint8_t b = *byte;
|
||||||
uint8_t parity = 0;
|
uint8_t parity = 0;
|
||||||
int8_t len_mod8 = 8;
|
int8_t len_mod8 = 8;
|
||||||
@ -340,6 +322,11 @@ uint8_t AVCLAN_sendbits(const uint8_t *byte, int8_t len) {
|
|||||||
return (parity & 1);
|
return (parity & 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send `len` bits on the AVCLAN bus; returns the even parity
|
||||||
|
uint8_t AVCLAN_sendbitsl(const uint16_t *word, int8_t len) {
|
||||||
|
return AVCLAN_sendbitsi((const uint8_t *)word + 1, len);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t AVCLAN_sendbyte(const uint8_t *byte) {
|
uint8_t AVCLAN_sendbyte(const uint8_t *byte) {
|
||||||
uint8_t b = *byte;
|
uint8_t b = *byte;
|
||||||
uint8_t parity = 0;
|
uint8_t parity = 0;
|
||||||
@ -583,11 +570,10 @@ uint8_t AVCLan_SendData() {
|
|||||||
uint8_t broadcast_control = 0x1;
|
uint8_t broadcast_control = 0x1;
|
||||||
AVCLAN_sendbits(&broadcast_control, 1); // regular communication
|
AVCLAN_sendbits(&broadcast_control, 1); // regular communication
|
||||||
|
|
||||||
uint8_t parity = 0;
|
parity = AVCLAN_sendbits(&CD_ID, 12);
|
||||||
AVCLAN_sendbits((uint8_t *)(&CD_ID) + 1, 12); // CD Changer ID as sender
|
|
||||||
AVCLan_Send_ParityBit(parity);
|
AVCLan_Send_ParityBit(parity);
|
||||||
|
|
||||||
AVCLAN_sendbits((uint8_t *)(&HU_ID) + 1, 12); // HeadUnit ID as responder
|
parity = AVCLAN_sendbits(&HU_ID, 12);
|
||||||
AVCLan_Send_ParityBit(parity);
|
AVCLan_Send_ParityBit(parity);
|
||||||
|
|
||||||
if (AVCLan_Read_ACK()) {
|
if (AVCLan_Read_ACK()) {
|
||||||
@ -664,11 +650,11 @@ uint8_t AVCLan_SendDataBroadcast() {
|
|||||||
AVCLAN_sendbits(&broadcast_control, 1); // broadcast
|
AVCLAN_sendbits(&broadcast_control, 1); // broadcast
|
||||||
|
|
||||||
uint8_t parity = 0;
|
uint8_t parity = 0;
|
||||||
AVCLAN_sendbits((uint8_t *)(&CD_ID) + 1, 12); // CD Changer ID as sender
|
AVCLAN_sendbits(&CD_ID, 12); // CD Changer ID as sender
|
||||||
AVCLan_Send_ParityBit(parity);
|
AVCLan_Send_ParityBit(parity);
|
||||||
|
|
||||||
uint16_t audio_addr = 0x1FF;
|
uint16_t audio_addr = 0x1FF;
|
||||||
AVCLAN_sendbits((uint8_t *)(&audio_addr) + 1, 12); // all audio devices
|
AVCLAN_sendbits(&audio_addr, 12); // all audio devices
|
||||||
AVCLan_Send_ParityBit(parity);
|
AVCLan_Send_ParityBit(parity);
|
||||||
AVCLan_Send_Bit1();
|
AVCLan_Send_Bit1();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user