# xinyuan-lilygo/t-2can architecture

> Architecture diagram of the GitHub repository xinyuan-lilygo/t-2can, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xinyuan-lilygo/t-2can
- Repository: https://github.com/xinyuan-lilygo/t-2can

## Overview

T-2Can is ESP32-S3 hardware with two CAN buses, offered in classic CAN (MCP2515) and CAN-FD (MCP2518) variants. The documented user workflow is to select a version-appropriate Arduino example or factory firmware, run it on the board, and exchange CAN traffic through the controller and bus. The graph separates board configuration, the two controller-driver stacks, and example/firmware entry points. Application-source excerpts were not provided, so links from examples to driver APIs are not asserted.

Main entry points: [`libraries/arduino-mcp2515-1.2.1/mcp2515.cpp`](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/arduino-mcp2515-1.2.1/mcp2515.cpp) (MCP2515 driver), [`libraries/Longan_CANFD/src/mcp2518fd_can.h`](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp2518fd_can.h) (MCP2518FD API), [`libraries/Longan_CANFD/src/mcp2518fd_can.cpp`](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp2518fd_can.cpp) (MCP2518FD driver), [`libraries/Longan_CANFD/src/mcp_can_fd.h`](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp_can_fd.h) (CAN FD API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_board["Board configuration"]
  node_esp["ESP32-S3"]
  node_pins["Pin configuration<br/>[pin_config.h]"]
end

subgraph group_classic["Classic CAN stack"]
  node_classicchip["MCP2515"]
  node_classicapi["CAN frame types<br/>[can.h]"]
  node_classicdriver["MCP2515 driver<br/>[mcp2515.cpp]"]
  node_classicinterface["MCP2515 API<br/>[mcp2515.h]"]
end

subgraph group_fd["CAN FD stack"]
  node_fdchip["MCP2518"]
  node_fdinterface["CAN FD API<br/>[mcp_can_fd.h]"]
  node_fdbase["CAN FD base<br/>[mcp_can_fd.cpp]"]
  node_fddriver["MCP2518FD driver<br/>[mcp2518fd_can.cpp]"]
  node_fdapi["MCP2518FD API<br/>[mcp2518fd_can.h]"]
  node_fdregisters["FD registers"]
end

subgraph group_apps["Examples and firmware"]
  node_canexample["Classic CAN example<br/>[can.ino]"]
  node_fdexample["ESP32 CAN example<br/>[esp32_can.ino]"]
  node_factoryexample["Factory test example<br/>[original_test.ino]"]
  node_classicfirmware["Classic factory firmware"]
  node_fd_firmware["FD factory firmware"]
end

node_user(("Board user"))
node_canbus{{"CAN buses"}}

node_user -->|"selects example"| node_canexample
node_user -->|"selects example"| node_factoryexample
node_user -->|"flashes firmware"| node_classicfirmware
node_user -->|"flashes firmware"| node_fd_firmware
node_esp -->|"uses pin map"| node_pins
node_classicdriver -->|"controls over SPI"| node_classicchip
node_classicinterface -->|"declares API"| node_classicdriver
node_classicdriver -->|"uses frame types"| node_classicapi
node_fddriver -->|"controls over SPI"| node_fdchip
node_fdapi -->|"includes definitions"| node_fdregisters
node_fdapi -->|"implements interface"| node_fdinterface
node_fddriver -->|"implements operations"| node_fdapi
node_fdbase -->|"defines base"| node_fdinterface
node_classicchip -->|"exchanges CAN"| node_canbus
node_fdchip -->|"exchanges CAN FD"| node_canbus
node_fdexample -.->|"factory variant"| node_fd_firmware

click node_pins "https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/private_library/pin_config.h"
click node_classicapi "https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/arduino-mcp2515-1.2.1/can.h"
click node_classicdriver "https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/arduino-mcp2515-1.2.1/mcp2515.cpp"
click node_classicinterface "https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/arduino-mcp2515-1.2.1/mcp2515.h"
click node_fdinterface "https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp_can_fd.h"
click node_fdbase "https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp_can_fd.cpp"
click node_fddriver "https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp2518fd_can.cpp"
click node_fdapi "https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp2518fd_can.h"
click node_fdregisters "https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp2518fd_can_dfs.h"
click node_canexample "https://github.com/xinyuan-lilygo/t-2can/blob/main/examples/can/can.ino"
click node_fdexample "https://github.com/xinyuan-lilygo/t-2can/blob/main/examples/esp32_can/esp32_can.ino"
click node_factoryexample "https://github.com/xinyuan-lilygo/t-2can/blob/main/examples/original_test/original_test.ino"
click node_classicfirmware "https://github.com/xinyuan-lilygo/t-2can/blob/main/firmware/%5BT-2Can_V1.0%5D%5Boriginal_test%5D_firmware/%5BT-2Can_V1.0%5D%5Boriginal_test%5D_firmware_202607170959.bin"
click node_fd_firmware "https://github.com/xinyuan-lilygo/t-2can/blob/main/firmware/%5BT-2Can-Fd_V1.0%5D%5Boriginal_test%5D_firmware/%5BT-2Can-Fd_V1.0%5D%5Boriginal_test%5D_firmware_202607170958.bin"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_esp,node_pins,node_user toneBlue
class node_classicchip,node_classicapi,node_classicdriver,node_classicinterface toneAmber
class node_fdchip,node_fdinterface,node_fdbase,node_fddriver,node_fdapi,node_fdregisters toneMint
class node_canexample,node_fdexample,node_factoryexample,node_classicfirmware,node_fd_firmware toneRose
class node_canbus toneIndigo
```

## Components

### Board configuration

- **ESP32-S3**
- [Pin configuration](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/private_library/pin_config.h): `libraries/private_library/pin_config.h`

### Classic CAN stack

- **MCP2515**
- [CAN frame types](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/arduino-mcp2515-1.2.1/can.h): `libraries/arduino-mcp2515-1.2.1/can.h`
- [MCP2515 driver](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/arduino-mcp2515-1.2.1/mcp2515.cpp): `libraries/arduino-mcp2515-1.2.1/mcp2515.cpp`
- [MCP2515 API](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/arduino-mcp2515-1.2.1/mcp2515.h): `libraries/arduino-mcp2515-1.2.1/mcp2515.h`

### CAN FD stack

- **MCP2518**
- [CAN FD API](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp_can_fd.h): `libraries/Longan_CANFD/src/mcp_can_fd.h`
- [CAN FD base](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp_can_fd.cpp): `libraries/Longan_CANFD/src/mcp_can_fd.cpp`
- [MCP2518FD driver](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp2518fd_can.cpp): `libraries/Longan_CANFD/src/mcp2518fd_can.cpp`
- [MCP2518FD API](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp2518fd_can.h): `libraries/Longan_CANFD/src/mcp2518fd_can.h`
- [FD registers](https://github.com/xinyuan-lilygo/t-2can/blob/main/libraries/Longan_CANFD/src/mcp2518fd_can_dfs.h): `libraries/Longan_CANFD/src/mcp2518fd_can_dfs.h`

### Examples and firmware

- [Classic CAN example](https://github.com/xinyuan-lilygo/t-2can/blob/main/examples/can/can.ino): `examples/can/can.ino`
- [ESP32 CAN example](https://github.com/xinyuan-lilygo/t-2can/blob/main/examples/esp32_can/esp32_can.ino): `examples/esp32_can/esp32_can.ino`
- [Factory test example](https://github.com/xinyuan-lilygo/t-2can/blob/main/examples/original_test/original_test.ino): `examples/original_test/original_test.ino`
- [Classic factory firmware](https://github.com/xinyuan-lilygo/t-2can/blob/main/firmware/%5BT-2Can_V1.0%5D%5Boriginal_test%5D_firmware/%5BT-2Can_V1.0%5D%5Boriginal_test%5D_firmware_202607170959.bin): `firmware/[T-2Can_V1.0][original_test]_firmware/[T-2Can_V1.0][original_test]_firmware_202607170959.bin`
- [FD factory firmware](https://github.com/xinyuan-lilygo/t-2can/blob/main/firmware/%5BT-2Can-Fd_V1.0%5D%5Boriginal_test%5D_firmware/%5BT-2Can-Fd_V1.0%5D%5Boriginal_test%5D_firmware_202607170958.bin): `firmware/[T-2Can-Fd_V1.0][original_test]_firmware/[T-2Can-Fd_V1.0][original_test]_firmware_202607170958.bin`

### Other components

- **Board user**
- **CAN buses**

## Connections

- Board user → Classic CAN example: selects example (evidence: `README.md`)
- Board user → Factory test example: selects example (evidence: `README.md`)
- Board user → Classic factory firmware: flashes firmware (evidence: `README.md`)
- Board user → FD factory firmware: flashes firmware (evidence: `README.md`)
- ESP32-S3 → Pin configuration: uses pin map (evidence: `libraries/private_library/pin_config.h`)
- MCP2515 driver → MCP2515: controls over SPI (evidence: `README.md`)
- MCP2515 API → MCP2515 driver: declares API (evidence: `libraries/arduino-mcp2515-1.2.1/mcp2515.h`)
- MCP2515 driver → CAN frame types: uses frame types
- MCP2518FD driver → MCP2518: controls over SPI (evidence: `README.md`)
- MCP2518FD API → FD registers: includes definitions (evidence: `libraries/Longan_CANFD/src/mcp2518fd_can.h`)
- MCP2518FD API → CAN FD API: implements interface (evidence: `libraries/Longan_CANFD/src/mcp2518fd_can.h`)
- MCP2518FD driver → MCP2518FD API: implements operations (evidence: `libraries/Longan_CANFD/src/mcp2518fd_can.cpp`)
- CAN FD base → CAN FD API: defines base (evidence: `libraries/Longan_CANFD/src/mcp_can_fd.cpp`)
- MCP2515 → CAN buses: exchanges CAN (evidence: `README.md`)
- MCP2518 → CAN buses: exchanges CAN FD (evidence: `README.md`)
- ESP32 CAN example → FD factory firmware: factory variant
