No. Enums in C/C++ and enum.Enum in python are two very different things. However, there is a powerful solution. I suggest writing the C/C++/Arduino header from your python code. With python's powerful introspection, it's easy to scan through your python enum/class with __dict__
and write a .h
file that your Arduino code can use. This is how I generate Verilog and SystemVerilog headers that match the enums and constants in related python projects. Running the python applications produces a new header file, always in sync.
EDIT: A MORE EXPLICIT EXAMPLE
I've built an assembler for an FPGA-based microprocessor. The assembler is in python, while the processor is programmed in Verilog. So I create a Verilog header file like this:
# Compute the 'after' content.
content = '// opcodes.vh\n'
content += '`ifndef _opcodes_vh\n'
content += '`define _opcodes_vh\n'
content += '// DO NOT EDIT -- FILE GENERATED BY ASSEMBLER\n'
content += '// ------------------------------------\n'
content += '// OPCODES\n'
content += '// ------------------------------------\n'
A = Arch
for i in A.__dict__:
if i.startswith('OPC_'):
o = i.replace('OPC_', 'OPCODE_')
s = '`define ' + o
while len(s) < 40:
s = s + ' '
hexval = str(hex(A.__dict__[i])).replace('0x', '')
decval = str(A.__dict__[i])
s = s + "7'h" + hexval + '\t\t// ' + str(decval) + '\n'
content += s
content += '// END OF GENERATED FILE.\n'
content += '`endif'
# Write to very specific location for Vivado to see it.
file = open(self.opcodes_filename, 'w', encoding='utf-8')
file.write(content)
file.close()
The final output looks like this:
// opcodes.vh
`ifndef _opcodes_vh
`define _opcodes_vh
// DO NOT EDIT -- FILE GENERATED BY ASSEMBLER
// ------------------------------------
// OPCODES
// ------------------------------------
`define OPCODE_LD_GPR_EXPR 7'h0 // 0
`define OPCODE_LD_GPR_GPTR 7'h1 // 1
`define OPCODE_SV_EXPR_GPR 7'h2 // 2
...
`define OPCODE_IO_T 7'h4a // 74
`define OPCODE_TX_T 7'h4b // 75
// END OF GENERATED FILE.
`endif