Replace HID Injector, USB Gadget, Terminal Shell, CAN Bus with real TinyUSB/UART/SPI implementations - no more stubs
This commit is contained in:
@@ -69,15 +69,42 @@ private:
|
||||
|
||||
void initMcp2515() {
|
||||
SPI.begin(pins::PROBE[3], pins::PROBE[4], pins::PROBE[5], CS);
|
||||
pinMode(CS, OUTPUT); digitalWrite(CS, HIGH);
|
||||
// Reset + config for passive listening (stub; real impl uses full MCP2515 init)
|
||||
say("CAN init %s", speed < 3 ? "ok" : "fail");
|
||||
pinMode(CS, OUTPUT);
|
||||
digitalWrite(CS, HIGH);
|
||||
digitalWrite(CS, LOW); SPI.transfer(0xC0); digitalWrite(CS, HIGH); delay(10);
|
||||
|
||||
// Set CNF registers for desired baud rate
|
||||
digitalWrite(CS, LOW);
|
||||
SPI.transfer(0x80); // Write instruction
|
||||
SPI.transfer(0x2A); // CNF1 address
|
||||
if (speed == 0) { SPI.transfer(0x00); SPI.transfer(0xA3); SPI.transfer(0x13); } // 500k
|
||||
else if (speed == 1) { SPI.transfer(0x00); SPI.transfer(0xA3); SPI.transfer(0x25); } // 250k
|
||||
else { SPI.transfer(0x00); SPI.transfer(0xA3); SPI.transfer(0x2B); } // 125k
|
||||
digitalWrite(CS, HIGH);
|
||||
|
||||
// Set CANCTRL for normal mode
|
||||
digitalWrite(CS, LOW);
|
||||
SPI.transfer(0x80);
|
||||
SPI.transfer(0x0F); // CANCTRL address
|
||||
SPI.transfer(0x00); // Normal mode
|
||||
digitalWrite(CS, HIGH);
|
||||
|
||||
say("CAN %s mode ok", speed == 0 ? "500k" : speed == 1 ? "250k" : "125k");
|
||||
}
|
||||
|
||||
bool readFrame(uint32_t& id, uint8_t& dlc, uint8_t* data) {
|
||||
// Stub: real impl reads MCP2515 RXn buffers via SPI
|
||||
// For now, return false (no frames)
|
||||
return false;
|
||||
digitalWrite(CS, LOW);
|
||||
SPI.transfer(0x03); // Read RX0 buffer status/id
|
||||
uint8_t sidh = SPI.transfer(0);
|
||||
uint8_t sidl = SPI.transfer(0);
|
||||
uint8_t eid8 = SPI.transfer(0);
|
||||
uint8_t eid0 = SPI.transfer(0);
|
||||
dlc = SPI.transfer(0) & 0x0F;
|
||||
for (int i = 0; i < dlc && i < 8; i++) data[i] = SPI.transfer(0);
|
||||
digitalWrite(CS, HIGH);
|
||||
|
||||
id = ((uint32_t)sidh << 3) | ((sidl >> 5) & 0x07);
|
||||
return dlc > 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user