# Read MSP430 pin configuration from text file and generate macros to access output pins. # p = ParseOrg("launchpad.org") #sc = OClass("port_sim") c = Port() gen.handleExports(c) spi = Spi() gen.handleExports(spi) for i in [1, 2]: pdir = [] pname = "P"+str(i) for bit, direction, name in p.parse()[1:]: bname = "BIT"+str(bit) if direction in ["OUT", "IN/OUT"]: c << OMacro("set_"+name, pname+"OUT |= "+bname) c << OMacro("clr_"+name, pname+"OUT &= ~"+bname) c << OMacro("toggle_"+name, pname+"OUT ^= "+bname) pdir.append(bname) c.add(name, pname+"OUT |= "+bname, pname+"OUT &= ~"+bname) #sc << OMacro("set_"+name, "bit_set(\""+name+"\")") #sc << OMacro("clr_"+name, "bit_clr(\""+name+"\")") #sc << OMacro("toggle_"+name, "bit_toggle(\""+name+"\")")
c = Port() gen.handleExports(c) spi = Spi() gen.handleExports(spi) c.m << "GPIO_InitTypeDef ioInit;" pins = [] for i in ['A', 'B', 'C']: pout = [] pin = [] paf = [] for bit, af, desc, direction in p.parse()[1:]: af = af.strip() #print "AF:",af,len(af) if len(af) > 0: paf.append(["GPIO_Pin_"+bit, af]) continue if direction in ["OUT", "IN/OUT"]: c << OMacro("set_"+desc, "GPIO"+i+"->BSRR = GPIO_Pin_"+bit) c << OMacro("clr_"+desc, "GPIO"+i+"->BRR = GPIO_Pin_"+bit) c << OMacro("toggle_"+desc, "GPIO"+i+"->ODR ^= GPIO_Pin_"+bit) pout.append("GPIO_Pin_"+bit) pins.append([direction, desc, i, bit]) if direction in ["IN"]: #c << OMacro("get_"+name, "("+pname+"IN & BIT"+str(bit)+" == BIT"+str(bit)+")") #c << OMacro("in_"+name, pname+"DIR &= ~BIT"+ str(bit))
return "GPIO" + self.port + "->" + reg # Read STM32 pin configuration from text file and generate macros to access output pins. # p = ParseOrg(FILENAME) c = Port() gen.handleExports(c) spi = Spi() gen.handleExports(spi) c.m << "GPIO_InitTypeDef ioInit;" p.parse() table = p.items[0].items[0] table2 = [PinDef(x) for x in table[1:] if len(x[2]) > 0 and x[2][0] != "["] ports = list(set([pin.port for pin in table2])) # all unique ports in the pins ports.sort() pins = [] for portName in ports: pout = [] pin = [] paf = [] pinDefs = [x for x in table2 if x.port == portName] if pinDefs: c.m << ""