#NEWLINE# def psoc5lp_reader( csv_file ) : #NEWLINE# #INDENT# "Extract pin data from a Cypress PSoC5LP CSV file and return a dictionary of pin data.\n       The CSV file contains one or more groups of rows formatted as follows:\n           A row with a single field containing the part number.\n           Zero or more blank rows.\n           A row containing the column headers:\n               'Pin', 'Unit', 'Type', 'Style', 'Side', and 'Name'.\n               (Only 'Pin' and 'Name' are required. The order of\n               the columns is not important.)\n           Each succeeding row should contain:\n               The 'Pin' column should contain the pin number.\n               The 'Unit' column specifies the bank or unit number for the pin.\n               The 'Type' column specifies the pin type (input, output,...).\n               The 'Style' column specifies the pin's schematic style.\n               The 'Side' column specifies the side of the symbol the pin is on.\n               The 'Name' column contains the pin name.\n           A blank row terminates the pin data for the part and begins\n           a new group of rows for another part.\n    " #NEWLINE# while True : #NEWLINE# #INDENT# pin_data = defaultdict ( ( lambda : defaultdict ( ( lambda : defaultdict ( list ) ) ) ) ) #NEWLINE# csv_reader = csv . reader ( csv_file , skipinitialspace = True ) #NEWLINE# part_num = get_part_num ( csv_reader ) #NEWLINE# if ( part_num is None ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# headers = clean_headers ( get_nonblank_row ( csv_reader ) ) #NEWLINE# dict_reader = csv . DictReader ( csv_file , headers , skipinitialspace = True ) #NEWLINE# for ( index , row ) in enumerate ( dict_reader ) : #NEWLINE# #INDENT# if ( num_row_elements ( list ( row . values ( ) ) ) == 0 ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# pin = copy . copy ( DEFAULT_PIN ) #NEWLINE# pin . index = index #NEWLINE# pin . type = '' #NEWLINE# for ( c , a ) in list ( COLUMN_NAMES . items ( ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( c == 'name' ) : #NEWLINE# #INDENT# row [ c ] = psoc5lp_pin_name_process ( row [ c ] ) #NEWLINE# #UNINDENT# setattr ( pin , a , row [ c ] ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( pin . num is None ) : #NEWLINE# #INDENT# issue ( 'ERROR: No pin number on row {index} of {part_num}' . format ( index = index , part_num = part_num ) , level = 'error' ) #NEWLINE# #UNINDENT# if ( pin . type == '' ) : #NEWLINE# #INDENT# DEFAULT_PIN_TYPE = 'input' #NEWLINE# PIN_TYPE_PREFIXES = [ ( 'P[0-9]+\\[[0-9]+\\]' , 'bidirectional' ) , ( 'VCC' , 'power_out' ) , ( 'VDD' , 'power_in' ) , ( 'VSS' , 'power_in' ) , ( 'IND' , 'passive' ) , ( 'VBOOST' , 'input' ) , ( 'VBAT' , 'power_in' ) , ( 'XRES' , 'input' ) , ( 'NC' , 'no_connect' ) ] #NEWLINE# for ( prefix , typ ) in PIN_TYPE_PREFIXES : #NEWLINE# #INDENT# if re . match ( prefix , pin . name , re . IGNORECASE ) : #NEWLINE# #INDENT# pin . type = typ #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# issue ( 'No match for pin {} on part {}, assigning as {}' . format ( pin . name , part_num , DEFAULT_PIN_TYPE ) ) #NEWLINE# pin . type = DEFAULT_PIN_TYPE #NEWLINE# #UNINDENT# #UNINDENT# pin_data [ pin . unit ] [ pin . side ] [ pin . name ] . append ( pin ) #NEWLINE# #UNINDENT# ( yield ( part_num , pin_data ) )