# yashsharda2/canny_edge_detection_in_fpga- architecture

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

- Interactive diagram: https://gitdiagram.com/yashsharda2/canny_edge_detection_in_fpga-
- Repository: https://github.com/yashsharda2/canny_edge_detection_in_fpga-

## Overview

This repository implements a streamed Canny edge detector on an iCE40 FPGA, driven by RP2040 firmware that reads an image, clocks pixels into the FPGA, collects edge bits, and displays and saves the result. The documented FPGA stages form the principal processing path; the README also identifies line buffering, and the tools provide image-to-input and output-to-image conversions. RTL internals were not excerpted, so stage-to-stage links cite the README rather than implying uninspected module calls.

Main entry points: [`firmware/canny.py`](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/firmware/canny.py) (Frame Controller), [`rtl/top.v`](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/top.v) (FPGA Top), [`tools/png2bin.py`](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/tools/png2bin.py) (PNG to Pixels), [`rtl/gaussianBlur.v`](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/gaussianBlur.v) (Gaussian Blur)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Image Preparation"]
  node_encode["PNG to Pixels<br/>[png2bin.py]"]
end

subgraph group_host["RP2040 Interface"]
  node_firmware["Frame Controller<br/>[canny.py]"]
  node_display_driver["ST7789 Driver<br/>[canny.py]"]
end

subgraph group_fpga["FPGA Canny Pipeline"]
  node_fpga_top["FPGA Top<br/>[top.v]"]
  node_window["Window Generator<br/>[imageControl.v]"]
  node_linebuffer["Line Buffer<br/>[lineBuffer.v]"]
  node_blur["Gaussian Blur<br/>[gaussianBlur.v]"]
  node_sobel["Sobel Gradient<br/>[sobel.v]"]
  node_nms["Non-Max Suppression<br/>[non_max_suppr.v]"]
  node_threshold["Double Threshold<br/>[double_threshold.v]"]
  node_tracking["Hysteresis Tracking<br/>[edge_track.v]"]
end

subgraph group_output["Result Outputs"]
  node_decode["Bits to PNG<br/>[bin2png.py]"]
  node_edgefile["Edge Bitstream"]
  node_display["ST7789 Display"]
end

node_pc(("Image Source"))

node_pc -->|"provides image"| node_encode
node_encode -->|"writes input.bin"| node_firmware
node_firmware -->|"streams pixels"| node_fpga_top
node_fpga_top -->|"generates windows"| node_window
node_fpga_top -->|"passes pixels"| node_blur
node_blur -->|"passes pixels"| node_sobel
node_sobel -->|"passes gradients"| node_nms
node_nms -->|"passes ridges"| node_threshold
node_threshold -->|"passes classifications"| node_tracking
node_tracking -->|"returns edge bits"| node_firmware
node_firmware -->|"writes packed bits"| node_edgefile
node_edgefile -->|"reads bitstream"| node_decode
node_firmware -->|"renders rows"| node_display_driver
node_display_driver -->|"updates screen"| node_display

click node_encode "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/tools/png2bin.py"
click node_firmware "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/firmware/canny.py"
click node_display_driver "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/firmware/canny.py"
click node_fpga_top "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/top.v"
click node_window "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/imageControl.v"
click node_linebuffer "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/lineBuffer.v"
click node_blur "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/gaussianBlur.v"
click node_sobel "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/sobel.v"
click node_nms "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/non_max_suppr.v"
click node_threshold "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/double_threshold.v"
click node_tracking "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/edge_track.v"
click node_decode "https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/tools/bin2png.py"

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_encode toneBlue
class node_firmware,node_display_driver toneAmber
class node_fpga_top,node_window,node_linebuffer,node_blur,node_sobel,node_nms,node_threshold,node_tracking toneMint
class node_decode,node_edgefile,node_display toneRose
class node_pc toneIndigo
```

## Components

### Image Preparation

- [PNG to Pixels](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/tools/png2bin.py): `tools/png2bin.py`

### RP2040 Interface

- [Frame Controller](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/firmware/canny.py): `firmware/canny.py`
- [ST7789 Driver](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/firmware/canny.py): `firmware/canny.py`

### FPGA Canny Pipeline

- [FPGA Top](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/top.v): `rtl/top.v`
- [Window Generator](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/imageControl.v): `rtl/imageControl.v`
- [Line Buffer](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/lineBuffer.v): `rtl/lineBuffer.v`
- [Gaussian Blur](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/gaussianBlur.v): `rtl/gaussianBlur.v`
- [Sobel Gradient](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/sobel.v): `rtl/sobel.v`
- [Non-Max Suppression](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/non_max_suppr.v): `rtl/non_max_suppr.v`
- [Double Threshold](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/double_threshold.v): `rtl/double_threshold.v`
- [Hysteresis Tracking](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/rtl/edge_track.v): `rtl/edge_track.v`

### Result Outputs

- [Bits to PNG](https://github.com/yashsharda2/canny_edge_detection_in_fpga-/blob/main/tools/bin2png.py): `tools/bin2png.py`
- **Edge Bitstream**
- **ST7789 Display**

### Other components

- **Image Source**

## Connections

- Image Source → PNG to Pixels: provides image (evidence: `tools/png2bin.py`)
- PNG to Pixels → Frame Controller: writes input.bin (evidence: `tools/png2bin.py`)
- Frame Controller → FPGA Top: streams pixels (evidence: `README.md`)
- FPGA Top → Window Generator: generates windows (evidence: `README.md`)
- FPGA Top → Gaussian Blur: passes pixels (evidence: `README.md`)
- Gaussian Blur → Sobel Gradient: passes pixels (evidence: `README.md`)
- Sobel Gradient → Non-Max Suppression: passes gradients (evidence: `README.md`)
- Non-Max Suppression → Double Threshold: passes ridges (evidence: `README.md`)
- Double Threshold → Hysteresis Tracking: passes classifications (evidence: `README.md`)
- Hysteresis Tracking → Frame Controller: returns edge bits (evidence: `README.md`)
- Frame Controller → Edge Bitstream: writes packed bits (evidence: `firmware/canny.py`)
- Edge Bitstream → Bits to PNG: reads bitstream (evidence: `tools/bin2png.py`)
- Frame Controller → ST7789 Driver: renders rows (evidence: `firmware/canny.py`)
- ST7789 Driver → ST7789 Display: updates screen (evidence: `firmware/canny.py`)
