Skip to content

Commit b0de5eb

Browse files
committed
Added experimental Python wrapper for Pi-Zero Board with LED support
1 parent 3def5fe commit b0de5eb

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

xenium-programmer-pi

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/python3
2+
3+
4+
# Python wrapper for Xenium programming using Pi-ZeroW PC-Board
5+
#
6+
# Copyright (C) 2019 Koos du Preez ([email protected])
7+
#
8+
# This program is free software; you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation; either version 2 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program; if not, write to the Free Software
20+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+
22+
import os
23+
import subprocess
24+
import RPi.GPIO as GPIO
25+
import time
26+
27+
print("██▒▓█████ ███▄ █ ██▓ █ ██ ███▄ ▄███▓")
28+
print("▒▒ █ █ ▒░▓█ ▀ ██ ▀█ █ ▓██▒ ██ ▓██▒▓██▒▀█▀ ██▒")
29+
print("░░ █ ░▒███ ▓██ ▀█ ██▒▒██▒▓██ ▒██░▓██ ▓██░")
30+
print(" ░ █ █ ▒ ▒▓█ ▄ ▓██▒ ▐▌██▒░██░▓▓█ ░██░▒██ ▒██ ")
31+
print("▒██▒ ▒██▒░▒████▒▒██░ ▓██░░██░▒▒█████▓ ▒██▒ ░██▒")
32+
print("▒▒ ░ ░▓ ░░░ ▒░ ░░ ▒░ ▒ ▒ ░▓ ░▒▓▒ ▒ ▒ ░ ▒░ ░ ░")
33+
print("░░ ░▒ ░ ░ ░ ░░ ░░ ░ ▒░ ▒ ░░░▒Programmer░ ░")
34+
print(" ░ ░ ░ ░ ░ ░ ▒kooscode@github ░ ")
35+
print(" ░ ░ ░ ░ ░ ░ ░ ░ ", flush=True)
36+
37+
38+
# git root folder.
39+
programmer_root = os.getcwd()
40+
41+
# Commands
42+
cmd_jtag = os.path.join(programmer_root, "xenium-flash/bin/xenium-jtag")
43+
cmd_jflash = os.path.join(programmer_root, "xenium-flash/bin/xenium-flash")
44+
45+
# Data Files
46+
flash_jed = os.path.join(programmer_root, "xenium-bin/xeniumflash.jed")
47+
xenium_os = os.path.join(programmer_root, "xenium-bin/xenium_blue.bin")
48+
xenium_jed= os.path.join(programmer_root, "xenium-bin/openxenium.jed")
49+
50+
# LED Pins
51+
led1 = 19
52+
led2 = 6
53+
led3 = 7
54+
55+
def set_ok():
56+
GPIO.output(led1, GPIO.HIGH)
57+
GPIO.output(led2, GPIO.LOW)
58+
GPIO.output(led3, GPIO.LOW)
59+
60+
def set_busy():
61+
GPIO.output(led1, GPIO.LOW)
62+
GPIO.output(led2, GPIO.HIGH)
63+
GPIO.output(led3, GPIO.LOW)
64+
65+
def set_error():
66+
GPIO.output(led1, GPIO.LOW)
67+
GPIO.output(led2, GPIO.LOW)
68+
GPIO.output(led3, GPIO.HIGH)
69+
70+
def set_init():
71+
GPIO.output(led1, GPIO.HIGH)
72+
time.sleep(0.1)
73+
GPIO.output(led2, GPIO.HIGH)
74+
time.sleep(0.1)
75+
GPIO.output(led3, GPIO.HIGH)
76+
time.sleep(0.1)
77+
78+
#using Broadcom pin numbering.
79+
GPIO.setmode(GPIO.BCM)
80+
GPIO.setwarnings(False)
81+
82+
#setup pin as output
83+
GPIO.setup(led1, GPIO.OUT)
84+
GPIO.setup(led2, GPIO.OUT)
85+
GPIO.setup(led3, GPIO.OUT)
86+
87+
set_init()
88+
89+
# Program CPLD with BitBus Flash Writer code.
90+
set_busy()
91+
print("-------------------------------------")
92+
print("PROGRAMMING XILINX CPLD: BITBUS BRIDGE")
93+
print("--------------------------------------", flush=True)
94+
sub_proc = subprocess.run([cmd_jtag, flash_jed])
95+
if sub_proc.returncode == 0:
96+
set_ok()
97+
98+
# Write OpenXenium OS to Flash Chip
99+
set_busy()
100+
print("-----------------------------")
101+
print("PROGRAMMING FLASH : XENIUM OS")
102+
print("-----------------------------", flush=True)
103+
sub_proc = subprocess.run([cmd_jflash, xenium_os, "-y"])
104+
if sub_proc.returncode == 0:
105+
set_ok()
106+
107+
set_busy()
108+
# Program CPLD with OpenXenium Firmware.
109+
print("---------------------------------------------")
110+
print("PROGRAMMING XILINX CPLD: OPEN XENIUM FIRMWARE")
111+
print("---------------------------------------------", flush=True)
112+
sub_proc = subprocess.run([cmd_jtag, xenium_jed])
113+
if sub_proc.returncode == 0:
114+
set_ok()
115+
116+
else:
117+
print("ERROR Programming the Xilinx CPLD!")
118+
print("Please double check your JTAG connection and wires!", flush=True)
119+
set_error()
120+
121+
else:
122+
set_error()
123+
print("ERROR Loading XeniumOS into OpenXenium Flash memory!")
124+
print("Please double check your LPC Header connection and wires!", flush=True)
125+
else:
126+
set_error()
127+
print("ERROR Programming the Xilinx CPLD!")
128+
print("Please double check your JTAG connection and wires!", flush=True)
129+
130+
# # cleanup GPIO
131+
# GPIO.cleanup()

0 commit comments

Comments
 (0)