# windymsth/e-mount-impl-on-techart-ea9 architecture

> Architecture diagram of the GitHub repository windymsth/e-mount-impl-on-techart-ea9, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/windymsth/e-mount-impl-on-techart-ea9
- Repository: https://github.com/windymsth/e-mount-impl-on-techart-ea9
- Video tour (about a minute): https://gitdiagram.com/windymsth/e-mount-impl-on-techart-ea9/video

## Overview

This is SAM D21 firmware for the Techart LM-EA9 adapter, presenting a Leica M lens as a Sony E-mount autofocus lens. The principal workflow is: a camera sends E-mount requests and focus targets; firmware responds to protocol messages, converts targets into mechanism positions, moves the lens with encoder feedback, and reports position/status. The README documents that role and the hardware; source-index references identify module dependencies. Main-loop details are only partially excerpted, so uncertain internal links are omitted or marked unverified.

Main entry points: [`src/main.c`](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/main.c) (Firmware loop), [`src/emount.c`](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/emount.c) (Protocol responder), [`src/servo.c`](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/servo.c) (Closed-loop servo), [`src/trail.c`](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/trail.c) (Session trail)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_protocol["E-mount protocol"]
  node_firmware["Firmware loop<br/>[main.c]"]
  node_responder["Protocol responder<br/>[emount.c]"]
  node_reply_packets["Reply packets<br/>[emount_packets.c]"]
end

subgraph group_focus["Focus mechanism"]
  node_focus_commands["Focus commands<br/>[emount.c]"]
  node_distance["Distance mapping<br/>[focus_dist.c]"]
  node_focus_map["Focus map<br/>[focus_map.c]"]
  node_prediction["Focus prediction<br/>[focus_pred.c]"]
  node_servo["Closed-loop servo<br/>[servo.c]"]
end

subgraph group_hardware["Hardware services"]
  node_uart["E-mount UART<br/>[em_uart.c]"]
  node_interrupts["External interrupts<br/>[em_eic.c]"]
  node_motor["Motor driver<br/>[motor.c]"]
  node_encoder["Absolute encoder<br/>[abs_encoder.c]"]
  node_board["Board peripherals<br/>[board.c]"]
  node_clock["Clock setup<br/>[clock.c]"]
  node_delay["Timing services<br/>[delay.c]"]
  node_voltage["Voltage sensing<br/>[vdd.c]"]
end

subgraph group_telemetry["Diagnostics"]
  node_trail["Session trail<br/>[trail.c]"]
  node_diag[("Flash diagnostics<br/>[diag.c]")]
end

node_camera(("Sony camera"))

node_camera -->|"sends requests"| node_responder
node_responder -->|"sends replies"| node_camera
node_firmware -.->|"runs protocol"| node_responder
node_responder -->|"uses bus"| node_uart
node_responder -->|"uses signals"| node_interrupts
node_responder -->|"uses tables"| node_reply_packets
node_firmware -.->|"handles targets"| node_focus_commands
node_firmware -.->|"uses mapping"| node_distance
node_distance -->|"uses map"| node_focus_map
node_firmware -.->|"uses prediction"| node_prediction
node_firmware -.->|"runs moves"| node_servo
node_servo -->|"drives motor"| node_motor
node_servo -->|"reads position"| node_encoder
node_motor -->|"reads position"| node_encoder
node_firmware -.->|"initializes pins"| node_board
node_firmware -.->|"sets clock"| node_clock
node_firmware -.->|"uses timing"| node_delay
node_firmware -.->|"samples voltage"| node_voltage
node_firmware -.->|"records session"| node_trail
node_trail -->|"writes records"| node_diag
node_trail -->|"reads protocol state"| node_responder
node_firmware -.->|"writes diagnostics"| node_diag

click node_firmware "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/main.c"
click node_responder "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/emount.c"
click node_reply_packets "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/emount_packets.c"
click node_uart "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/em_uart.c"
click node_interrupts "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/em_eic.c"
click node_focus_commands "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/emount.c"
click node_distance "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/focus_dist.c"
click node_focus_map "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/focus_map.c"
click node_prediction "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/focus_pred.c"
click node_servo "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/servo.c"
click node_motor "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/motor.c"
click node_encoder "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/abs_encoder.c"
click node_board "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/board.c"
click node_clock "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/clock.c"
click node_delay "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/delay.c"
click node_voltage "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/vdd.c"
click node_trail "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/trail.c"
click node_diag "https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/diag.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_firmware,node_responder,node_reply_packets toneBlue
class node_focus_commands,node_distance,node_focus_map,node_prediction,node_servo toneAmber
class node_uart,node_interrupts,node_motor,node_encoder,node_board,node_clock,node_delay,node_voltage toneMint
class node_trail,node_diag toneRose
class node_camera toneIndigo
```

## Components

### E-mount protocol

- [Firmware loop](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/main.c): `src/main.c`
- [Protocol responder](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/emount.c): `src/emount.c`
- [Reply packets](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/emount_packets.c): `src/emount_packets.c`

### Focus mechanism

- [Focus commands](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/emount.c): `src/emount.c`
- [Distance mapping](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/focus_dist.c): `src/focus_dist.c`
- [Focus map](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/focus_map.c): `src/focus_map.c`
- [Focus prediction](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/focus_pred.c): `src/focus_pred.c`
- [Closed-loop servo](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/servo.c): `src/servo.c`

### Hardware services

- [E-mount UART](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/em_uart.c): `src/em_uart.c`
- [External interrupts](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/em_eic.c): `src/em_eic.c`
- [Motor driver](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/motor.c): `src/motor.c`
- [Absolute encoder](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/abs_encoder.c): `src/abs_encoder.c`
- [Board peripherals](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/board.c): `src/board.c`
- [Clock setup](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/clock.c): `src/clock.c`
- [Timing services](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/delay.c): `src/delay.c`
- [Voltage sensing](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/vdd.c): `src/vdd.c`

### Diagnostics

- [Session trail](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/trail.c): `src/trail.c`
- [Flash diagnostics](https://github.com/windymsth/e-mount-impl-on-techart-ea9/blob/main/src/diag.c): `src/diag.c`

### Other components

- **Sony camera**

## Connections

- Sony camera → Protocol responder: sends requests
- Protocol responder → Sony camera: sends replies
- Firmware loop → Protocol responder: runs protocol
- Protocol responder → E-mount UART: uses bus (evidence: `src/emount.c`)
- Protocol responder → External interrupts: uses signals (evidence: `src/emount.c`)
- Protocol responder → Reply packets: uses tables (evidence: `src/emount.c`)
- Firmware loop → Focus commands: handles targets
- Firmware loop → Distance mapping: uses mapping
- Distance mapping → Focus map: uses map (evidence: `src/focus_dist.c`)
- Firmware loop → Focus prediction: uses prediction
- Firmware loop → Closed-loop servo: runs moves
- Closed-loop servo → Motor driver: drives motor (evidence: `src/servo.c`)
- Closed-loop servo → Absolute encoder: reads position (evidence: `src/servo.c`)
- Motor driver → Absolute encoder: reads position (evidence: `src/motor.c`)
- Firmware loop → Board peripherals: initializes pins
- Firmware loop → Clock setup: sets clock
- Firmware loop → Timing services: uses timing
- Firmware loop → Voltage sensing: samples voltage
- Firmware loop → Session trail: records session
- Session trail → Flash diagnostics: writes records (evidence: `src/trail.c`)
- Session trail → Protocol responder: reads protocol state (evidence: `src/trail.c`)
- Firmware loop → Flash diagnostics: writes diagnostics
