|
44 | 44 | help='add an Arduino MEGA as test framework and generate Arduino verification code', |
45 | 45 | default=0) |
46 | 46 |
|
| 47 | + parser.add_argument('-tt', '--tinytapeout', |
| 48 | + action=BooleanOptionalAction, |
| 49 | + help='add default parts used in tinytapeout wokwi template schematic', |
| 50 | + default=0) |
| 51 | + |
47 | 52 | args = parser.parse_args() |
48 | 53 |
|
49 | 54 | # Create and configure logger object |
|
110 | 115 | "left": -500, |
111 | 116 | "rotate": 90, |
112 | 117 | "attrs": {} |
113 | | - } |
| 118 | + } |
| 119 | + |
| 120 | + wokwi_dip_switch8 = { |
| 121 | + "type": "wokwi-dip-switch-8", |
| 122 | + "id": "sw1", |
| 123 | + "top": -188, |
| 124 | + "left": -400, |
| 125 | + "rotate": 90, |
| 126 | + "attrs": {} |
| 127 | + } |
| 128 | + |
| 129 | + wokwi_clock_generator = { |
| 130 | + "type": "wokwi-clock-generator", |
| 131 | + "id": "clock1", |
| 132 | + "top": -300, |
| 133 | + "left": -400, |
| 134 | + "attrs": {} |
| 135 | + } |
| 136 | + |
| 137 | + wokwi_chip_input_8pins = { |
| 138 | + "type": "chip-input-8-pins", |
| 139 | + "id": "chip1", |
| 140 | + "top": -200, |
| 141 | + "left": -230, |
| 142 | + "attrs": { "verilogRole": "input" } |
| 143 | + } |
| 144 | + |
| 145 | + wokwi_chip_output_8pins = { |
| 146 | + "type": "chip-output-8-pins", |
| 147 | + "id": "chip2", |
| 148 | + "top": -200, |
| 149 | + "left": 900, |
| 150 | + "attrs": { "verilogRole": "output" } |
| 151 | + } |
| 152 | + |
| 153 | + wokwi_7segment = { |
| 154 | + "type": "wokwi-7segment", |
| 155 | + "id": "sevseg1", |
| 156 | + "top": -200, |
| 157 | + "left": 1100, |
| 158 | + "attrs": { "common": "cathode" } |
| 159 | + } |
| 160 | + |
| 161 | + wokwi_slide_switch = { |
| 162 | + "type": "wokwi-slide-switch", |
| 163 | + "id": "sw2", |
| 164 | + "top": -320, |
| 165 | + "left": -300, |
| 166 | + "attrs": { "value": "1" } |
| 167 | + } |
| 168 | + |
| 169 | + wokwi_pushbutton = { |
| 170 | + "type": "wokwi-pushbutton", |
| 171 | + "id": "btn1", |
| 172 | + "top": -410, |
| 173 | + "left": -400, |
| 174 | + "attrs": { "color": "grey", "label": "Step", "bounce": "0" } |
| 175 | + } |
| 176 | + |
| 177 | + wokwi_vcc = { |
| 178 | + "type": "wokwi-vcc", |
| 179 | + "id": None, |
| 180 | + "top": 0, |
| 181 | + "left": 0, |
| 182 | + "attrs": {} |
| 183 | + } |
| 184 | + |
| 185 | + wokwi_gnd = { |
| 186 | + "type": "wokwi-gnd", |
| 187 | + "id": None, |
| 188 | + "top": 0, |
| 189 | + "left": 0, |
| 190 | + "attrs": {} |
| 191 | + } |
114 | 192 |
|
115 | 193 | # ------------------------------------------------------------------------------ |
116 | 194 | # user specific output style and laoyut definition |
|
138 | 216 | con_color_or_output = "cyan" |
139 | 217 | con_color_termination = "black" |
140 | 218 | con_color_arduino_interconnect = "black" |
| 219 | + con_color_vcc_interconnect = "red" |
| 220 | + con_color_gnd_interconnect = "black" |
| 221 | + con_color_7seg_interconnect = "green" |
| 222 | + con_color_board_interconnect = "green" |
141 | 223 |
|
142 | 224 | arduino_sketch_template_file = "sketch.ino.template" |
143 | 225 |
|
@@ -474,7 +556,7 @@ def get_expected_bin_out_vals(output_names, output_data, num_inputs): |
474 | 556 | log.debug("---") # we need some visual separator here |
475 | 557 | log.debug(f" Processing first AND stage of term #{term_idx+1} of the CNF function for output {output}...") |
476 | 558 |
|
477 | | - # if the last AND gate has not been fully used, connect any unconnected input to VCC |
| 559 | + # if the last AND gate has not been fully used, terminate it |
478 | 560 | terminate_current_and_gate() |
479 | 561 |
|
480 | 562 | select_next_and_gate() |
@@ -739,6 +821,9 @@ def get_expected_bin_out_vals(output_names, output_data, num_inputs): |
739 | 821 |
|
740 | 822 | log.info(f"Finished the wokwi design!") |
741 | 823 |
|
| 824 | + if args.tinytapeout and args.test: |
| 825 | + log.warn("Cannot combine flags '--test'/'-t' and '--tinytapeout'/'--tt'. Removing '-tt'.") |
| 826 | + args.tinytapeout = False |
742 | 827 |
|
743 | 828 | if args.test: |
744 | 829 | log.info("Generating verification code and test framework") |
@@ -797,6 +882,120 @@ def get_expected_bin_out_vals(output_names, output_data, num_inputs): |
797 | 882 | else: |
798 | 883 | log.error("Unable to open Arduino sketch template file.") |
799 | 884 |
|
| 885 | + if args.tinytapeout: |
| 886 | + log.info("Adding parts from template for tinytapeout") |
| 887 | + |
| 888 | + # add parts to the wokwi schematic's parts list |
| 889 | + wokwi_design["parts"].append(wokwi_dip_switch8) |
| 890 | + wokwi_design["parts"].append(wokwi_clock_generator) |
| 891 | + wokwi_design["parts"].append(wokwi_chip_input_8pins) |
| 892 | + wokwi_design["parts"].append(wokwi_slide_switch) |
| 893 | + wokwi_design["parts"].append(wokwi_pushbutton) |
| 894 | + |
| 895 | + # TODO/FIXME: move the next two parts to the far right, next to the output buffer of the top-most signal |
| 896 | + wokwi_design["parts"].append(wokwi_chip_output_8pins) |
| 897 | + wokwi_design["parts"].append(wokwi_7segment) |
| 898 | + |
| 899 | + vcc_btn = wokwi_vcc.copy() |
| 900 | + vcc_btn["id"] = "vcc_btn" |
| 901 | + vcc_btn["top"] = -450 |
| 902 | + vcc_btn["left"] = -320 |
| 903 | + vcc_dipsw = wokwi_vcc.copy() |
| 904 | + vcc_dipsw["id"] = "vcc_dipsw" |
| 905 | + vcc_dipsw["top"] = -240 |
| 906 | + vcc_dipsw["left"] = -420 |
| 907 | + wokwi_design["parts"].append(vcc_btn) |
| 908 | + wokwi_design["parts"].append(vcc_dipsw) |
| 909 | + |
| 910 | + gnd_7seg = wokwi_gnd.copy() |
| 911 | + gnd_7seg["id"] = "gnd_7seg" |
| 912 | + gnd_7seg["top"] = -70 |
| 913 | + gnd_7seg["left"] = 1100 |
| 914 | + wokwi_design["parts"].append(gnd_7seg) |
| 915 | + |
| 916 | + |
| 917 | + # add connections |
| 918 | + for i in range(1, 8+1): |
| 919 | + con = [ "vcc_dipsw:VCC", f"sw1:{i}a", con_color_vcc_interconnect, default_con_instr ] |
| 920 | + log.debug(" Connection: "+str(con)) |
| 921 | + wokwi_design["connections"].append(con) |
| 922 | + |
| 923 | + con = [ "btn1:2.r", "sw2:3", "orange", [ "h90", "*", "v10" ] ] |
| 924 | + log.debug(" Connection: "+str(con)) |
| 925 | + wokwi_design["connections"].append(con) |
| 926 | + |
| 927 | + con = [ "vcc_btn:VCC", "btn1:1.r", con_color_vcc_interconnect, [ "v0" ] ] |
| 928 | + log.debug(" Connection: "+str(con)) |
| 929 | + wokwi_design["connections"].append(con) |
| 930 | + |
| 931 | + con = [ "sw2:1", "clock1:CLK", "green", [ "v0" ] ] |
| 932 | + log.debug(" Connection: "+str(con)) |
| 933 | + wokwi_design["connections"].append(con) |
| 934 | + |
| 935 | + con = [ "sw2:3", "sw1:1b", "violet", [ "v0" ] ] |
| 936 | + log.debug(" Connection: "+str(con)) |
| 937 | + wokwi_design["connections"].append(con) |
| 938 | + |
| 939 | + con = [ "chip1:EXTIN0", "sw2:2", "green", [ "h0", "v-40", "h-20" ] ] |
| 940 | + log.debug(" Connection: "+str(con)) |
| 941 | + wokwi_design["connections"].append(con) |
| 942 | + |
| 943 | + for i in range(2, 8+1): |
| 944 | + con = [ f"chip1:EXTIN{i-1}", f"sw1:{i}b", "violet", [ "h0" ] ] |
| 945 | + log.debug(" Connection: "+str(con)) |
| 946 | + wokwi_design["connections"].append(con) |
| 947 | + |
| 948 | + con = [ "chip2:EXTOUT0", "sevseg1:A", con_color_7seg_interconnect, [ "h21.01", "v-28.8", "h96" ] ] |
| 949 | + log.debug(" Connection: "+str(con)) |
| 950 | + wokwi_design["connections"].append(con) |
| 951 | + con = [ "chip2:EXTOUT1", "sevseg1:B", con_color_7seg_interconnect, [ "h11.41", "v-48", "h115.2", "v38.4" ] ] |
| 952 | + log.debug(" Connection: "+str(con)) |
| 953 | + wokwi_design["connections"].append(con) |
| 954 | + con = [ "chip2:EXTOUT2", "sevseg1:C", con_color_7seg_interconnect, [ "h30.61", "v-38.4", "h115.2", "v105.6", "h-28.8" ] ] |
| 955 | + log.debug(" Connection: "+str(con)) |
| 956 | + wokwi_design["connections"].append(con) |
| 957 | + con = [ "chip2:EXTOUT3", "sevseg1:D", con_color_7seg_interconnect, [ "h49.81", "v57.6", "h48" ] ] |
| 958 | + log.debug(" Connection: "+str(con)) |
| 959 | + wokwi_design["connections"].append(con) |
| 960 | + con = [ "chip2:EXTOUT4", "sevseg1:E", con_color_7seg_interconnect, [ "v9.6", "h-48", "v-38.4" ] ] |
| 961 | + log.debug(" Connection: "+str(con)) |
| 962 | + wokwi_design["connections"].append(con) |
| 963 | + con = [ "chip2:EXTOUT5", "sevseg1:F", con_color_7seg_interconnect, [ "h69.01", "v-57.6", "h28.8" ] ] |
| 964 | + log.debug(" Connection: "+str(con)) |
| 965 | + wokwi_design["connections"].append(con) |
| 966 | + con = [ "chip2:EXTOUT6", "sevseg1:G", con_color_7seg_interconnect, [ "h78.61", "v-57.6" ] ] |
| 967 | + log.debug(" Connection: "+str(con)) |
| 968 | + wokwi_design["connections"].append(con) |
| 969 | + con = [ "chip2:EXTOUT7", "sevseg1:DP", con_color_7seg_interconnect, [ "v28.8", "h136.21" ] ] |
| 970 | + log.debug(" Connection: "+str(con)) |
| 971 | + wokwi_design["connections"].append(con) |
| 972 | + con = [ "chip2:EXTOUT7", "sevseg1:DP", con_color_7seg_interconnect, [ "v28.8", "h136.21" ] ] |
| 973 | + log.debug(" Connection: "+str(con)) |
| 974 | + wokwi_design["connections"].append(con) |
| 975 | + con = [ "gnd_7seg:GND", "sevseg1:COM.1", con_color_gnd_interconnect, [ "v0" ] ] |
| 976 | + log.debug(" Connection: "+str(con)) |
| 977 | + wokwi_design["connections"].append(con) |
| 978 | + |
| 979 | + # Check number of inputs |
| 980 | + if num_inputs > 8: |
| 981 | + log.warn("Won't be able to connect more than 8 inputs!") |
| 982 | + num_inputs = 8 |
| 983 | + |
| 984 | + for k in range(num_inputs): |
| 985 | + con = [ f"chip1:IN{k}", "input_"+input_names[k]+":IN", con_color_board_interconnect, default_con_instr ] |
| 986 | + log.debug(" Connection: "+str(con)) |
| 987 | + wokwi_design["connections"].append(con) |
| 988 | + |
| 989 | + # Check number of outputs |
| 990 | + if num_outputs > 8: |
| 991 | + log.warn("Won't be able to connect more than 8 outputs!") |
| 992 | + num_outputs = 8 |
| 993 | + |
| 994 | + for k in range(num_outputs): |
| 995 | + con = [ "output_"+output_names[k]+":OUT", f"chip2:OUT{k}", con_color_board_interconnect, default_con_instr ] |
| 996 | + log.debug(" Connection: "+str(con)) |
| 997 | + wokwi_design["connections"].append(con) |
| 998 | + |
800 | 999 | #log.debug( json.dumps(logic_meta, indent=4) ) |
801 | 1000 |
|
802 | 1001 | wokwi_design_dump = wokwi_design |
|
0 commit comments