# cn-vik/thermal_imaging_camera architecture

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

- Interactive diagram: https://gitdiagram.com/cn-vik/thermal_imaging_camera
- Repository: https://github.com/cn-vik/thermal_imaging_camera

## Overview

This is an ESP32-S3 thermal-imaging camera using an MLX90640 sensor and an ST7789 LCD. At startup, the firmware initializes the display and LVGL, creates the thermal UI, and launches a capture task. That task obtains sensor frames, converts them to temperatures, applies image processing and colorization, and updates the displayed image and HUD. The excerpts show these main runtime paths; peripheral hardware and some internal processing details are represented only where the source supports them.

Main entry points: [`project/spi_lcd/main/app_main.c`](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/app_main.c) (Application startup), [`project/spi_lcd/main/ir_mlx90640_app.c`](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/ir_mlx90640_app.c) (Thermal task), [`project/spi_lcd/main/lvgl_demo_ui.c`](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/lvgl_demo_ui.c) (Thermal HUD), [`project/spi_lcd/main/mlx90640/MLX90640_API.c`](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/mlx90640/MLX90640_API.c) (Sensor calibration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Firmware startup"]
  node_boot["Application startup<br/>[app_main.c]"]
end

subgraph group_sensor["Sensor pipeline"]
  node_capture["Thermal task<br/>[ir_mlx90640_app.c]"]
  node_mlxapi["Sensor calibration<br/>[MLX90640_API.c]"]
  node_mlxdriver["MLX I2C driver"]
  node_processing["Thermal rendering<br/>[ir_mlx90640_app.c]"]
end

subgraph group_display["Display and UI"]
  node_ui["Thermal HUD<br/>[lvgl_demo_ui.c]"]
  node_lvgl["LVGL display runtime<br/>[app_main.c]"]
end

subgraph group_hardware["Device hardware"]
  node_i2cbsp["I2C bus layer<br/>[bsp_i2c.c]"]
  node_sensorhw{{"MLX90640 sensor"}}
  node_lcd["ST7789 display"]
end

node_operator(("Camera viewer"))

node_boot -->|"initializes"| node_lvgl
node_boot -->|"starts task"| node_capture
node_boot -->|"creates UI"| node_ui
node_boot -->|"configures SPI"| node_lcd
node_capture -->|"reads frames"| node_mlxapi
node_mlxapi -->|"reads sensor registers"| node_mlxdriver
node_mlxdriver -->|"uses I2C bus"| node_i2cbsp
node_i2cbsp -->|"transfers sensor data"| node_sensorhw
node_capture -->|"processes temperatures"| node_processing
node_processing -->|"updates image and HUD"| node_ui
node_ui -->|"uses LVGL widgets"| node_lvgl
node_lvgl -->|"flushes display"| node_lcd
node_lcd -.->|"shows thermal view"| node_operator

click node_boot "https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/app_main.c"
click node_capture "https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/ir_mlx90640_app.c"
click node_mlxapi "https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/mlx90640/MLX90640_API.c"
click node_mlxdriver "https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/mlx90640/MLX90640_I2C_Driver.c"
click node_i2cbsp "https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/bsp/bsp_i2c.c"
click node_processing "https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/ir_mlx90640_app.c"
click node_ui "https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/lvgl_demo_ui.c"
click node_lvgl "https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/app_main.c"

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_boot,node_operator toneBlue
class node_capture,node_mlxapi,node_mlxdriver,node_processing toneAmber
class node_ui,node_lvgl toneMint
class node_i2cbsp,node_sensorhw,node_lcd toneRose
```

## Components

### Firmware startup

- [Application startup](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/app_main.c): `project/spi_lcd/main/app_main.c`

### Sensor pipeline

- [Thermal task](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/ir_mlx90640_app.c): `project/spi_lcd/main/ir_mlx90640_app.c`
- [Sensor calibration](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/mlx90640/MLX90640_API.c): `project/spi_lcd/main/mlx90640/MLX90640_API.c`
- [MLX I2C driver](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/mlx90640/MLX90640_I2C_Driver.c): `project/spi_lcd/main/mlx90640/MLX90640_I2C_Driver.c`
- [Thermal rendering](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/ir_mlx90640_app.c): `project/spi_lcd/main/ir_mlx90640_app.c`

### Display and UI

- [Thermal HUD](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/lvgl_demo_ui.c): `project/spi_lcd/main/lvgl_demo_ui.c`
- [LVGL display runtime](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/app_main.c): `project/spi_lcd/main/app_main.c`

### Device hardware

- [I2C bus layer](https://github.com/cn-vik/thermal_imaging_camera/blob/ir_camera_V1.0.0/project/spi_lcd/main/bsp/bsp_i2c.c): `project/spi_lcd/main/bsp/bsp_i2c.c`
- **MLX90640 sensor**
- **ST7789 display**

### Other components

- **Camera viewer**

## Connections

- Application startup → LVGL display runtime: initializes (evidence: `project/spi_lcd/main/app_main.c`)
- Application startup → Thermal task: starts task (evidence: `project/spi_lcd/main/app_main.c`)
- Application startup → Thermal HUD: creates UI (evidence: `project/spi_lcd/main/app_main.c`)
- Application startup → ST7789 display: configures SPI (evidence: `project/spi_lcd/main/app_main.c`)
- Thermal task → Sensor calibration: reads frames (evidence: `project/spi_lcd/main/ir_mlx90640_app.c`)
- Sensor calibration → MLX I2C driver: reads sensor registers (evidence: `project/spi_lcd/main/mlx90640/MLX90640_API.c`)
- MLX I2C driver → I2C bus layer: uses I2C bus (evidence: `project/spi_lcd/main/mlx90640/MLX90640_I2C_Driver.c`)
- I2C bus layer → MLX90640 sensor: transfers sensor data (evidence: `project/spi_lcd/main/bsp/bsp_i2c.c`)
- Thermal task → Thermal rendering: processes temperatures (evidence: `project/spi_lcd/main/ir_mlx90640_app.c`)
- Thermal rendering → Thermal HUD: updates image and HUD (evidence: `project/spi_lcd/main/ir_mlx90640_app.c`)
- Thermal HUD → LVGL display runtime: uses LVGL widgets (evidence: `project/spi_lcd/main/lvgl_demo_ui.c`)
- LVGL display runtime → ST7789 display: flushes display (evidence: `project/spi_lcd/main/app_main.c`)
- ST7789 display → Camera viewer: shows thermal view
