Skip to content

Commit da8b128

Browse files
author
Felix "xq" Queißner
committed
Fixes PS/2 input code for new prototype PCB, adds program.py to flash EEPROM
1 parent f0f6eac commit da8b128

4 files changed

Lines changed: 148 additions & 7 deletions

File tree

Hardware/Expansions/PS2 Input/Prototype/Quad PS2 Input.kicad_sch

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,86 @@
23812381
(embedded_fonts no)
23822382
)
23832383
)
2384+
(text "+1"
2385+
(exclude_from_sim no)
2386+
(at 40.64 60.325 0)
2387+
(effects
2388+
(font
2389+
(size 1.27 1.27)
2390+
)
2391+
)
2392+
(uuid "04002af5-a0ed-4739-8922-2a5546b4101f")
2393+
)
2394+
(text "+3"
2395+
(exclude_from_sim no)
2396+
(at 40.64 57.15 0)
2397+
(effects
2398+
(font
2399+
(size 1.27 1.27)
2400+
)
2401+
)
2402+
(uuid "157728c6-b376-464c-ab1c-114ed74400f2")
2403+
)
2404+
(text "+0"
2405+
(exclude_from_sim no)
2406+
(at 74.295 60.325 0)
2407+
(effects
2408+
(font
2409+
(size 1.27 1.27)
2410+
)
2411+
)
2412+
(uuid "53521eec-55dd-4472-842d-ad390cac35e7")
2413+
)
2414+
(text "+5"
2415+
(exclude_from_sim no)
2416+
(at 40.64 54.61 0)
2417+
(effects
2418+
(font
2419+
(size 1.27 1.27)
2420+
)
2421+
)
2422+
(uuid "8e7cbd78-89f3-4a99-8a67-b1d5a688e5e5")
2423+
)
2424+
(text "+7"
2425+
(exclude_from_sim no)
2426+
(at 40.64 52.07 0)
2427+
(effects
2428+
(font
2429+
(size 1.27 1.27)
2430+
)
2431+
)
2432+
(uuid "993261e6-324a-4226-b33d-8d8ac6fa01f8")
2433+
)
2434+
(text "+6"
2435+
(exclude_from_sim no)
2436+
(at 74.295 52.07 0)
2437+
(effects
2438+
(font
2439+
(size 1.27 1.27)
2440+
)
2441+
)
2442+
(uuid "be36cb8f-1225-4efd-951c-34f88c4a1c24")
2443+
)
2444+
(text "+4"
2445+
(exclude_from_sim no)
2446+
(at 74.295 55.245 0)
2447+
(effects
2448+
(font
2449+
(size 1.27 1.27)
2450+
)
2451+
)
2452+
(uuid "c27cef4d-690c-48c0-82f2-0310b63af31b")
2453+
)
2454+
(text "+2"
2455+
(exclude_from_sim no)
2456+
(at 74.295 57.785 0)
2457+
(effects
2458+
(font
2459+
(size 1.27 1.27)
2460+
)
2461+
)
2462+
(uuid "dc62684c-ae94-4425-81b1-dc9c99be7d30")
2463+
)
23842464
(junction
23852465
(at 88.9 38.1)
23862466
(diameter 0)

Hardware/Expansions/PS2 Input/firmware.propan

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const PS2_TX_WORD_SIZE = 12 // 1 Start + 8 Data + 1 Parity + 1 Stop + 1 Acknowle
99
// Number of cpu clocks until a true timeout is detected
1010
const PS2_BIT_RCV_TIMEOUT_TICKS = ticks(CLK, us=2500)
1111

12-
const USART_RX_MODE = P_TRUE_A|P_LOCAL_A|P_INVERT_B|P_PLUS2_B|P_PASS_AB|P_LOGIC_A|P_SYNC_IO|P_TRUE_IN|P_TRUE_OUTPUT|P_HIGH_FLOAT|P_LOW_FAST|P_TT_10|P_SYNC_RX
13-
const CLOCK_TIMEOUT_MODE = P_TRUE_A|P_LOCAL_A|P_PASS_AB|P_LOGIC_A|P_SYNC_IO|P_TRUE_IN|P_TRUE_OUTPUT|P_HIGH_FLOAT|P_LOW_FAST|P_TT_00|P_EVENTS_TICKS
14-
const OPEN_DRAIN_MODE = P_TRUE_A|P_LOCAL_A|P_TRUE_B|P_LOCAL_A|P_PASS_AB|P_LOGIC_A|P_SYNC_IO|P_TRUE_IN|P_TRUE_OUTPUT|P_HIGH_FLOAT|P_LOW_FAST|P_TT_00|P_NORMAL
12+
const USART_RX_MODE = P_TRUE_A | P_LOCAL_A | P_INVERT_B | P_PLUS1_B | P_PASS_AB | P_LOGIC_A | P_SYNC_IO | P_TRUE_IN | P_TRUE_OUTPUT | P_HIGH_FLOAT | P_LOW_FAST | P_TT_10 | P_SYNC_RX
13+
const CLOCK_TIMEOUT_MODE = P_TRUE_A | P_LOCAL_A | P_PASS_AB | P_LOGIC_A | P_SYNC_IO | P_TRUE_IN | P_TRUE_OUTPUT | P_HIGH_FLOAT | P_LOW_FAST | P_TT_00 | P_EVENTS_TICKS
14+
const OPEN_DRAIN_MODE = P_TRUE_A | P_LOCAL_A | P_TRUE_B | P_LOCAL_A | P_PASS_AB | P_LOGIC_A | P_SYNC_IO | P_TRUE_IN | P_TRUE_OUTPUT | P_HIGH_FLOAT | P_LOW_FAST | P_TT_00 | P_NORMAL
1515

1616
const RTS_DELAY_TICKS = ticks(CLK, us=100)
1717

@@ -45,10 +45,10 @@ entry:
4545
COGID PS2_DAT
4646
SUB PS2_DAT, 1 // subtract 1 as we're using pins 0...7 with module 1
4747
SHL PS2_DAT, 3 // multiply with 8 to get base pin
48-
ADD PS2_DAT, 4 // 32 => 36
48+
ADD PS2_DAT, 0 // 32 => 36
4949

5050
MOV PS2_CLK, PS2_DAT
51-
ADD PS2_CLK, 2 // 36 => 38
51+
ADD PS2_CLK, 1 // 32 => 33
5252

5353
CALL setup_rx_mode
5454

Hardware/Expansions/justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ compile-expansion folder pid:
1616
{{root_dir}}/Scripts/ExpCard.py \
1717
--output "{{folder}}/eeprom.json" \
1818
"{{vendor_id}}" "{{pid}}" "{{dummy_serial}}"
19-
19+
2020
[ -f "{{folder}}/firmware.propan" ] && propan \
2121
--output "{{folder}}/firmware.bin" \
2222
--format flat \
@@ -29,7 +29,7 @@ compile-expansion folder pid:
2929
[ -f "{{folder}}/firmware.propan" ] || ashet-exp encode \
3030
--output "{{folder}}/eeprom.bin" \
3131
"{{folder}}/eeprom.json" || true
32-
32+
3333
[ -f "{{folder}}/eeprom.json" ]
3434

3535
hexdump -C "{{folder}}/eeprom.bin" \

Hardware/Expansions/program.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
5+
from os import stat_result
6+
7+
from argparse import ArgumentParser
8+
from pathlib import Path
9+
10+
LEGAL_DISK_SIZES: frozenset[int] = frozenset((4096, 8192, 16384))
11+
12+
def main() -> int:
13+
14+
parser = ArgumentParser()
15+
parser.add_argument("image", type=Path)
16+
parser.add_argument("--disk", type=Path, default=Path("/dev/sda"), required=False)
17+
18+
args = parser.parse_args()
19+
20+
image_path: Path = args.image
21+
disk_path :Path = args.disk
22+
23+
image: bytes = image_path.read_bytes()
24+
25+
sys_dir: Path = Path("/sys/class/block/") / disk_path.name
26+
assert sys_dir.is_dir(), f"{sys_dir.as_posix()!r} is not a directory"
27+
28+
def get_sysfs(key: str) -> str:
29+
return (sys_dir / key).read_text('utf-8').strip()
30+
31+
dev_type = get_sysfs("device/model")
32+
if dev_type != "EEPROM2FS":
33+
print(f"Unexpected disk type. Expected {'EEPROM2FS'!r}, but found {dev_type!r}", file=sys.stderr)
34+
return 1
35+
36+
block_count = int(get_sysfs("size"))
37+
disk_size = 512 * block_count
38+
39+
if disk_size not in LEGAL_DISK_SIZES:
40+
print(f"Unexpected disk size {disk_size}. Expected one of {sorted(LEGAL_DISK_SIZES)}", file=sys.stderr)
41+
return 1
42+
43+
print("Writing image file...")
44+
with disk_path.open("rb+") as disk:
45+
disk.write(image)
46+
disk.flush()
47+
48+
print("Validating image file...")
49+
with disk_path.open("rb") as disk:
50+
check = disk.read(len(image))
51+
if image != check:
52+
print("Failed to write image!.", file=sys.stderr)
53+
return 1
54+
55+
print("Success!")
56+
57+
return 0
58+
59+
60+
if __name__ == "__main__":
61+
sys.exit(main())

0 commit comments

Comments
 (0)