mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
spi
This commit is contained in:
13
hid/Makefile
13
hid/Makefile
@@ -4,6 +4,12 @@ ps2:
|
||||
make _build E=ps2
|
||||
mixed:
|
||||
make _build E=mixed
|
||||
usb-spi:
|
||||
make _build E=usb_spi
|
||||
ps2-spi:
|
||||
make _build E=ps2_spi
|
||||
mixed-spi:
|
||||
make _build E=mixed_spi
|
||||
_build:
|
||||
rm -f .current
|
||||
platformio run --environment $(E)
|
||||
@@ -15,11 +21,18 @@ upload:
|
||||
platformio run --environment $(shell cat .current) --target upload
|
||||
|
||||
|
||||
bootloader-spi: install-bootloader-spi
|
||||
install-bootloader-spi: upload-bootloader-spi
|
||||
upload-bootloader-spi:
|
||||
platformio run --environment bootloader_spi --target bootloader
|
||||
|
||||
|
||||
update:
|
||||
platformio platform update
|
||||
|
||||
|
||||
clean-all: clean
|
||||
rm -rf .platformio
|
||||
clean:
|
||||
rm -rf .pio .current
|
||||
|
||||
|
||||
7
hid/avrdude-rpi.conf
Normal file
7
hid/avrdude-rpi.conf
Normal file
@@ -0,0 +1,7 @@
|
||||
programmer
|
||||
id = "rpi";
|
||||
desc = "RPi SPI programmer";
|
||||
type = "linuxspi";
|
||||
reset = 25;
|
||||
baudrate = 400000;
|
||||
;
|
||||
53
hid/avrdude.py
Normal file
53
hid/avrdude.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html
|
||||
|
||||
from os import rename
|
||||
from os import symlink
|
||||
from os.path import exists
|
||||
from os.path import join
|
||||
|
||||
import platform
|
||||
|
||||
Import("env")
|
||||
|
||||
|
||||
# =====
|
||||
def _get_tool_path() -> str:
|
||||
path = env.PioPlatform().get_package_dir("tool-avrdude")
|
||||
assert exists(path)
|
||||
return path
|
||||
|
||||
|
||||
def _fix_ld_arm() -> None:
|
||||
tool_path = _get_tool_path()
|
||||
flag_path = join(tool_path, ".fix-ld-arm.done")
|
||||
|
||||
if not exists(flag_path):
|
||||
def patch(*_, **__) -> None:
|
||||
symlink("/usr/lib/libtinfo.so.6", join(tool_path, "libtinfo.so.5"))
|
||||
open(flag_path, "w").close()
|
||||
|
||||
env.Execute(patch)
|
||||
|
||||
|
||||
def _replace_to_system(new_path: str) -> None:
|
||||
tool_path = _get_tool_path()
|
||||
flag_path = join(tool_path, ".replace-to-system.done")
|
||||
|
||||
if not exists(flag_path):
|
||||
def patch(*_, **__) -> None:
|
||||
old_path = join(tool_path, "avrdude")
|
||||
bak_path = join(tool_path, "_avrdude_bak")
|
||||
rename(old_path, bak_path)
|
||||
symlink(new_path, old_path)
|
||||
open(flag_path, "w").close()
|
||||
|
||||
env.Execute(patch)
|
||||
|
||||
|
||||
# =====
|
||||
if "arm" in platform.machine():
|
||||
_fix_ld_arm()
|
||||
|
||||
_path = "/usr/bin/avrdude"
|
||||
if exists(_path):
|
||||
_replace_to_system(_path)
|
||||
0
hid/lib/.gitignore
vendored
Normal file
0
hid/lib/.gitignore
vendored
Normal file
34
hid/patch.py
34
hid/patch.py
@@ -1,20 +1,32 @@
|
||||
from os.path import join
|
||||
# https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html
|
||||
|
||||
from os.path import exists
|
||||
from os.path import join
|
||||
from os.path import basename
|
||||
|
||||
from typing import Dict
|
||||
|
||||
Import("env")
|
||||
|
||||
|
||||
# =====
|
||||
deps_path = env.get("PROJECT_LIBDEPS_DIR", env.get("PROJECTLIBDEPS_DIR"))
|
||||
assert deps_path, deps_path
|
||||
env_path = join(deps_path, env["PIOENV"])
|
||||
flag_path = join(env_path, ".patched")
|
||||
def _get_libs() -> Dict[str, str]:
|
||||
return {
|
||||
builder.name: builder.path
|
||||
for builder in env.GetLibBuilders()
|
||||
}
|
||||
|
||||
if not exists(flag_path):
|
||||
env.Execute(f"patch -p1 -d {join(env_path, 'HID-Project')} < {join('patches', 'absmouse.patch')}")
|
||||
|
||||
def touch_flag(*_, **__) -> None:
|
||||
with open(flag_path, "w") as flag_file:
|
||||
pass
|
||||
def _patch_lib(lib_path: str, patch_path: str) -> None:
|
||||
assert exists(lib_path)
|
||||
flag_path: str = join(lib_path, f".{basename(patch_path)}.done")
|
||||
if not exists(flag_path):
|
||||
env.Execute(f"patch -p1 -d {lib_path} < {patch_path}")
|
||||
env.Execute(lambda *_, **__: open(flag_path, "w").close())
|
||||
|
||||
env.Execute(touch_flag)
|
||||
|
||||
# =====
|
||||
_libs = _get_libs()
|
||||
assert "TimerOne" in _libs # Just checking
|
||||
if "HID-Project" in _libs:
|
||||
_patch_lib(_libs["HID-Project"], "patches/absmouse.patch")
|
||||
|
||||
@@ -1,59 +1,149 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; http://docs.platformio.org/page/projectconf.html
|
||||
# http://docs.platformio.org/page/projectconf.html
|
||||
[platformio]
|
||||
core_dir = ./.platformio/
|
||||
|
||||
[common]
|
||||
[env]
|
||||
platform = atmelavr
|
||||
board = micro
|
||||
framework = arduino
|
||||
extra_scripts =
|
||||
pre:avrdude.py
|
||||
post:patch.py
|
||||
platform_packages =
|
||||
tool-avrdude
|
||||
|
||||
[_parts_common]
|
||||
lib_deps =
|
||||
TimerOne@1.1
|
||||
|
||||
[_parts_usb_kbd]
|
||||
lib_deps =
|
||||
HID-Project@2.6.1
|
||||
build_flags =
|
||||
-DHID_USB_KBD
|
||||
|
||||
[_parts_usb_mouse]
|
||||
lib_deps =
|
||||
HID-Project@2.6.1
|
||||
build_flags =
|
||||
-DHID_USB_MOUSE
|
||||
|
||||
[_parts_ps2_kbd]
|
||||
lib_deps =
|
||||
git+https://github.com/Harvie/ps2dev#v0.0.3
|
||||
build_flags =
|
||||
-DHID_PS2_KBD
|
||||
-DPS2_KBD_CLOCK_PIN=7
|
||||
-DPS2_KBD_DATA_PIN=5
|
||||
|
||||
[_usb]
|
||||
lib_deps =
|
||||
${_parts_common.lib_deps}
|
||||
${_parts_usb_kbd.lib_deps}
|
||||
# ${_parts_usb_mouse.lib_deps}
|
||||
build_flags =
|
||||
${_parts_usb_kbd.build_flags}
|
||||
${_parts_usb_mouse.build_flags}
|
||||
|
||||
[_ps2]
|
||||
lib_deps =
|
||||
${_parts_common.lib_deps}
|
||||
${_parts_ps2_kbd.lib_deps}
|
||||
build_flags =
|
||||
${_parts_ps2_kbd.build_flags}
|
||||
|
||||
[_mixed]
|
||||
lib_deps =
|
||||
${_parts_common.lib_deps}
|
||||
${_parts_ps2_kbd.lib_deps}
|
||||
${_parts_usb_mouse.lib_deps}
|
||||
build_flags =
|
||||
${_parts_ps2_kbd.build_flags}
|
||||
${_parts_usb_mouse.build_flags}
|
||||
|
||||
|
||||
# ===== Serial =====
|
||||
[_cmd_serial]
|
||||
build_flags =
|
||||
-DCMD_SERIAL=Serial1
|
||||
-DCMD_SERIAL_SPEED=115200
|
||||
upload_port = /dev/ttyACM0
|
||||
|
||||
[env:usb]
|
||||
platform = atmelavr
|
||||
board = micro
|
||||
framework = arduino
|
||||
upload_port = /dev/ttyACM0
|
||||
lib_deps =
|
||||
${common.lib_deps}
|
||||
HID-Project@2.6.1
|
||||
extends =
|
||||
_usb
|
||||
_cmd_serial
|
||||
build_flags =
|
||||
${common.build_flags}
|
||||
-DHID_USB_KBD
|
||||
-DHID_USB_MOUSE
|
||||
extra_scripts = post:patch.py
|
||||
${_usb.build_flags}
|
||||
${_cmd_serial.build_flags}
|
||||
|
||||
[env:ps2]
|
||||
platform = atmelavr
|
||||
board = micro
|
||||
framework = arduino
|
||||
upload_port = /dev/ttyACM0
|
||||
lib_deps =
|
||||
${common.lib_deps}
|
||||
git+https://github.com/Harvie/ps2dev#v0.0.3
|
||||
extends =
|
||||
_ps2
|
||||
_cmd_serial
|
||||
build_flags =
|
||||
${common.build_flags}
|
||||
-DHID_PS2_KBD
|
||||
-DPS2_KBD_CLOCK_PIN=7
|
||||
-DPS2_KBD_DATA_PIN=5
|
||||
${_ps2.build_flags}
|
||||
${_cmd_serial.build_flags}
|
||||
|
||||
[env:mixed]
|
||||
platform = atmelavr
|
||||
board = micro
|
||||
framework = arduino
|
||||
upload_port = /dev/ttyACM0
|
||||
lib_deps =
|
||||
${common.lib_deps}
|
||||
HID-Project@2.6.1
|
||||
git+https://github.com/Harvie/ps2dev#v0.0.3
|
||||
extends =
|
||||
_mixed
|
||||
_cmd_serial
|
||||
build_flags =
|
||||
${common.build_flags}
|
||||
-DHID_PS2_KBD
|
||||
-DHID_USB_MOUSE
|
||||
-DPS2_KBD_CLOCK_PIN=7
|
||||
-DPS2_KBD_DATA_PIN=5
|
||||
${_mixed.build_flags}
|
||||
${_cmd_serial.build_flags}
|
||||
|
||||
|
||||
# ===== RPi SPI =====
|
||||
[env:bootloader_spi]
|
||||
upload_protocol = rpi
|
||||
upload_flags =
|
||||
-C
|
||||
+avrdude-rpi.conf
|
||||
-P
|
||||
/dev/spidev0.0:/dev/gpiochip0
|
||||
extra_scripts =
|
||||
pre:avrdude.py
|
||||
|
||||
[_cmd_spi]
|
||||
build_flags =
|
||||
-DCMD_SERIAL=Serial1
|
||||
-DCMD_SERIAL_SPEED=115200
|
||||
# -DCMD_SPI
|
||||
upload_protocol = custom
|
||||
upload_flags =
|
||||
-C
|
||||
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
|
||||
-C
|
||||
+avrdude-rpi.conf
|
||||
-P
|
||||
/dev/spidev0.0:/dev/gpiochip0
|
||||
-c
|
||||
rpi
|
||||
-p
|
||||
$BOARD_MCU
|
||||
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
|
||||
|
||||
[env:usb_spi]
|
||||
extends =
|
||||
_usb
|
||||
_cmd_spi
|
||||
build_flags =
|
||||
${_usb.build_flags}
|
||||
${_cmd_spi.build_flags}
|
||||
|
||||
[env:ps2_spi]
|
||||
extends =
|
||||
_ps2
|
||||
_cmd_spi
|
||||
build_flags =
|
||||
${_ps2.build_flags}
|
||||
${_cmd_spi.build_flags}
|
||||
|
||||
[env:mixed_spi]
|
||||
extends =
|
||||
_mixed
|
||||
_cmd_spi
|
||||
build_flags =
|
||||
${_mixed.build_flags}
|
||||
${_cmd_spi.build_flags}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
|
||||
// #define CMD_SERIAL Serial1
|
||||
#define CMD_SERIAL_SPEED 115200
|
||||
// #define CMD_SERIAL_SPEED 115200
|
||||
#define CMD_RECV_TIMEOUT 100000
|
||||
|
||||
#define PROTO_MAGIC 0x33
|
||||
|
||||
Reference in New Issue
Block a user