From 73947c241f50c13efc6882f936da285edf5ab6b1 Mon Sep 17 00:00:00 2001 From: t Date: Fri, 28 Aug 2026 09:43:31 +0900 Subject: [PATCH] feat(boards): add CH340 Uno clone firmware source --- boards/arduino-uno-r3-ch340.ino | 66 ++++++++++++++++++++++++ sources/boards/arduino-uno-r3-ch340.json | 40 ++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 boards/arduino-uno-r3-ch340.ino create mode 100644 sources/boards/arduino-uno-r3-ch340.json diff --git a/boards/arduino-uno-r3-ch340.ino b/boards/arduino-uno-r3-ch340.ino new file mode 100644 index 0000000..3b40af0 --- /dev/null +++ b/boards/arduino-uno-r3-ch340.ino @@ -0,0 +1,66 @@ +// Hanbeon app button-switch firmware for CH340-based Arduino Uno clones. +// +// Reports exactly one "P" per stable press and one "R" per stable release. +// The Mac bridge sends FLASH when Hanbeon advances its scan cursor and OFF +// while the scan is not moving. A physical press keeps the LED on. +// Wiring: button COM -> GND, button NO -> D2, LED -> D9. + +const byte buttonPin = 2; +const byte ledPin = 9; +const unsigned long debounceMs = 30; +const unsigned long flashMs = 120; + +int lastRawReading = HIGH; +int stableState = HIGH; +unsigned long lastChangeMs = 0; +unsigned long flashUntilMs = 0; +String command; +bool commandHadCarriageReturn = false; + +void setup() { + pinMode(buttonPin, INPUT_PULLUP); + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, LOW); + Serial.begin(115200); +} + +void loop() { + readBridgeCommands(); + + const int rawReading = digitalRead(buttonPin); + + if (rawReading != lastRawReading) { + lastChangeMs = millis(); + lastRawReading = rawReading; + } + + if (millis() - lastChangeMs >= debounceMs && rawReading != stableState) { + stableState = rawReading; + Serial.println(stableState == LOW ? "P" : "R"); + } + + const bool buttonPressed = stableState == LOW; + const bool flashing = millis() < flashUntilMs; + digitalWrite(ledPin, buttonPressed || flashing ? HIGH : LOW); +} + +void readBridgeCommands() { + while (Serial.available() > 0) { + const char next = static_cast(Serial.read()); + if (next == '\n') { + if (command == "HELLO" && !commandHadCarriageReturn) { + Serial.print("HANBEON_UNO_V1\n"); + } else if (command == "FLASH") { + flashUntilMs = millis() + flashMs; + } else if (command == "OFF") { + flashUntilMs = 0; + } + command = ""; + commandHadCarriageReturn = false; + } else if (next == '\r') { + commandHadCarriageReturn = true; + } else { + command += next; + } + } +} diff --git a/sources/boards/arduino-uno-r3-ch340.json b/sources/boards/arduino-uno-r3-ch340.json new file mode 100644 index 0000000..43dfec8 --- /dev/null +++ b/sources/boards/arduino-uno-r3-ch340.json @@ -0,0 +1,40 @@ +{ + "schemaVersion": 1, + "id": "arduino.uno-r3-ch340", + "name": "Arduino Uno R3 호환 보드 (CH340)", + "sketch": { + "path": "boards/arduino-uno-r3-ch340.ino", + "fqbn": "arduino:avr:uno" + }, + "detect": { + "usb": [ + { + "vid": "1a86", + "pid": "7523", + "confidence": "ambiguous" + }, + { + "vid": "1a86", + "pid": "7522", + "confidence": "ambiguous" + }, + { + "vid": "1a86", + "pid": "5523", + "confidence": "ambiguous" + } + ] + }, + "wiring": [ + { + "from": "D2", + "to": "순간 누름 스위치 NO 단자", + "note": "스위치 COM 단자는 GND에 연결" + }, + { + "from": "D9", + "to": "LED 양극", + "note": "220~330Ω 직렬 저항을 사용하고 LED 음극은 GND에 연결" + } + ] +}