Skip to content

Add enum generator for Rust. #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pinout_generator_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__( self, parent ):

bSizer4.Add( self.m_staticText11, 0, wx.ALIGN_CENTER|wx.ALL, 5 )

output_formatChoices = [ u"List", u"CSV", u"HTML table", u"Markdown table", u"C/C++ code (#define)", u"C/C++ code (enum)", u"Python (dict)", u"WireViz ", u"FPGA (XDC format)", u"FPGA (PDC format)" ]
output_formatChoices = [ u"List", u"CSV", u"HTML table", u"Markdown table", u"C/C++ code (#define)", u"C/C++ code (enum)", u"Python (dict)", u"WireViz ", u"FPGA (XDC format)", u"FPGA (PDC format)", u"Rust (enum)" ]
self.output_format = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, output_formatChoices, 0 )
self.output_format.SetSelection( 0 )
bSizer4.Add( self.output_format, 0, wx.ALL, 5 )
Expand Down
20 changes: 19 additions & 1 deletion pinout_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
'python_dict':6,
'wireviz':7,
'fpga_xdc':8,
'fpga_pdc':9
'fpga_pdc':9,
'rust':10
}

class PinoutDialog(pinout_generator_result.PinoutDialog):
Expand Down Expand Up @@ -128,6 +129,8 @@ def set_output(self, selection):
output_formater = self.xdc_format
elif selection == SELECTOR['fpga_pdc']:
output_formater = self.pdc_format
elif selection == SELECTOR['rust']:
output_formater = self.rust_format

# checks for format n
for component in self.footprint_selection:
Expand Down Expand Up @@ -270,6 +273,21 @@ def pdc_format(self, component):
output += "set_io "+var_name+" -pinname "+pad.GetNumber()+" -fixed yes"+"\n"
return output

def rust_format(self, component):
added_vars = []
output = "// Pinout generated for "+component.GetReference()+" ("+component.GetValue()+")\n"
output = "pub enum " + component.GetReference() + " {\n"
pinout = get_pins(component)
for pad in pinout:
var_name = str_to_C_variable("pin_" + pad.GetNetname())
if var_name in added_vars:
output += "//"
if pad_is_connected(pad) and not (pad_is_power(pad) or pad_is_passive(pad)):
output += "\t" + var_name+" = "+pad.GetNumber()+",\n"
added_vars.append(var_name)
output += "}\n"
return output


def Run(self):
# Look for selected FP
Expand Down