state_machine_emulator/main.py
def process_file_pio_h(filename):
    """ read and parse a pioasm generated header file """
    # TODO: public, .word
    pio_program = list()
    with open(filename, 'r') as pio_file:
        line = pio_file.readline()
        while line:
            if line[0] == '/' and line[1] == '/':
                pass
            elif ".length" in line:
                d = line.strip().split('=')
                pio_program_length = int(d[1].replace(',', ''))
            elif ".origin" in line:
                d = line.strip().split('=')
                pio_program_origin = int(d[1].replace(',', ''))
            elif "#define" in line:
                if "wrap_target" in line:
                    d = line.strip().split(' ')
                    pio_program_wrap_target = int(d[2])
                elif "wrap" in line:
                    d = line.strip().split(' ')
                    pio_program_wrap = int(d[2])
            elif "static const uint16_t" in line:
                line = pio_file.readline()
                while '};' not in line:
                    d = line.strip().split(', //')
                    if len(d) == 2:
                        pio_program.append(d)
                    line = pio_file.readline()
                # self.program_definitions['pio_program'] = pio_program
            elif "static inline pio_sm_config" in line:
                # add to the c-program at t=0
                line2 = pio_file.readline()
                # print("line2=", line2)
                while '}' not in line2:
                    if 'sm_config_set_sideset' in line2:
                        parts = line2.split(',')
                        # print("parts=", parts)
                        a1 = int(parts[1].strip())
                        c_program.append([0, 'sideset_count', a1])
                        a2 = parts[2].strip().lower() == 'true'
                        c_program.append([0, 'sideset_opt', a2])
                        a3 = parts[3].split(')')[0].strip().lower() == 'true'
                        c_program.append([0, 'sideset_pindirs', a3])
                    line2 = pio_file.readline()
            line = pio_file.readline()
    if len(pio_program) != pio_program_length:
        print("error: program lengths not matching, continuing anyway")
    if len(pio_program) > 32:
        print("error: program too long, continuing anyway")
    return pio_program, pio_program_length, pio_program_origin, pio_program_wrap_target, pio_program_wrap
 read and parse a pioasm generated header file 
read and parse a pioasm generated header file
read and parse a pioasm generated header file
def process_file_pio_h(filename):
    pio_program = list()
    with open(filename, 'r') as pio_file:
        line = pio_file.readline()
        while line:
            if line[0] == '/' and line[1] == '/':
                pass
            elif ".length" in line:
                d = line.strip().split('=')
                pio_program_length = int(d[1].replace(',', ''))
            elif ".origin" in line:
                d = line.strip().split('=')
                pio_program_origin = int(d[1].replace(',', ''))
            elif "#define" in line:
                if "wrap_target" in line:
                    d = line.strip().split(' ')
                    pio_program_wrap_target = int(d[2])
                elif "wrap" in line:
                    d = line.strip().split(' ')
                    pio_program_wrap = int(d[2])
            elif "static const uint16_t" in line:
                line = pio_file.readline()
                while '};' not in line:
                    d = line.strip().split(', //')
                    if len(d) == 2:
                        pio_program.append(d)
                    line = pio_file.readline()
            elif "static inline pio_sm_config" in line:
                line2 = pio_file.readline()
                while '}' not in line2:
                    if 'sm_config_set_sideset' in line2:
                        parts = line2.split(',')
                        a1 = int(parts[1].strip())
                        c_program.append([0, 'sideset_count', a1])
                        a2 = parts[2].strip().lower() == 'true'
                        c_program.append([0, 'sideset_opt', a2])
                        a3 = parts[3].split(')')[0].strip().lower() == 'true'
                        c_program.append([0, 'sideset_pindirs', a3])
                    line2 = pio_file.readline()
            line = pio_file.readline()
    if len(pio_program) != pio_program_length:
        print("error: program lengths not matching, continuing anyway")
    if len(pio_program) > 32:
        print("error: program too long, continuing anyway")
    return pio_program, pio_program_length, pio_program_origin, pio_program_wrap_target, pio_program_wrap
def process_file_pio_h ( filename ) : pio_program = list ( ) with open ( filename , 'r' ) as pio_file : line = pio_file . readline ( ) while line : if line [ 0 ] == '/' and line [ 1 ] == '/' : pass elif ".length" in line : d = line . strip ( ) . split ( '=' ) pio_program_length = int ( d [ 1 ] . replace ( ',' , '' ) ) elif ".origin" in line : d = line . strip ( ) . split ( '=' ) pio_program_origin = int ( d [ 1 ] . replace ( ',' , '' ) ) elif "#define" in line : if "wrap_target" in line : d = line . strip ( ) . split ( ' ' ) pio_program_wrap_target = int ( d [ 2 ] ) elif "wrap" in line : d = line . strip ( ) . split ( ' ' ) pio_program_wrap = int ( d [ 2 ] ) elif "static const uint16_t" in line : line = pio_file . readline ( ) while '};' not in line : d = line . strip ( ) . split ( ', //' ) if len ( d ) == 2 : pio_program . append ( d ) line = pio_file . readline ( ) elif "static inline pio_sm_config" in line : line2 = pio_file . readline ( ) while '}' not in line2 : if 'sm_config_set_sideset' in line2 : parts = line2 . split ( ',' ) a1 = int ( parts [ 1 ] . strip ( ) ) c_program . append ( [ 0 , 'sideset_count' , a1 ] ) a2 = parts [ 2 ] . strip ( ) . lower ( ) == 'true' c_program . append ( [ 0 , 'sideset_opt' , a2 ] ) a3 = parts [ 3 ] . split ( ')' ) [ 0 ] . strip ( ) . lower ( ) == 'true' c_program . append ( [ 0 , 'sideset_pindirs' , a3 ] ) line2 = pio_file . readline ( ) line = pio_file . readline ( ) if len ( pio_program ) != pio_program_length : print ( "error: program lengths not matching, continuing anyway" ) if len ( pio_program ) > 32 : print ( "error: program too long, continuing anyway" ) return pio_program , pio_program_length , pio_program_origin , pio_program_wrap_target , pio_program_wrap
read and parse a pioasm generated header file
read and parse a pioasm generated header file
""" read and parse a pioasm generated header file """ # TODO: public, .word # self.program_definitions['pio_program'] = pio_program # add to the c-program at t=0 # print("line2=", line2) # print("parts=", parts)
filename