parameters: (f)
docstring: write GPIO config defines
docstring_summary: write GPIO config defines
docstring_tokens: write GPIO config defines
function: def write_GPIO_config(f):
      '''write GPIO config defines'''
      f.write('// GPIO config\n')
      gpios = []
      gpioset = set()
      for l in bylabel:
          p = bylabel[l]
          gpio = p.extra_value('GPIO', type=int)
          if gpio is None:
              continue
          if gpio in gpioset:
              error("Duplicate GPIO value %u" % gpio)
          gpioset.add(gpio)
          # see if it is also a PWM pin
          pwm = p.extra_value('PWM', type=int, default=0)
          port = p.port
          pin = p.pin
          # default config always enabled
          gpios.append((gpio, pwm, port, pin, p, 'true'))
      for alt in altmap.keys():
          for pp in altmap[alt].keys():
              p = altmap[alt][pp]
              gpio = p.extra_value('GPIO', type=int)
              if gpio is None:
                  continue
              if gpio in gpioset:
                  # check existing entry
                  existing_gpio = [item for item in gpios if item[0] == gpio]
                  if (existing_gpio[0][4].label == p.label) and (existing_gpio[0][3] == p.pin) and (existing_gpio[0][2] == p.port):
                      # alt item is identical to exiting, do not add again
                      continue
                  error("Duplicate GPIO value %u, %s != %s" % (gpio, p, existing_gpio[0][4]))
              pwm = p.extra_value('PWM', type=int, default=0)
              if pwm != 0:
                  error("PWM not supported for alt config: %s" % p)
              gpioset.add(gpio)
              port = p.port
              pin = p.pin
              # aux config disabled by defualt
              gpios.append((gpio, pwm, port, pin, p, 'false'))
      gpios = sorted(gpios)
      for (gpio, pwm, port, pin, p, enabled) in gpios:
          f.write('#define HAL_GPIO_LINE_GPIO%u PAL_LINE(GPIO%s,%uU)\n' % (gpio, port, pin))
      f.write('#define HAL_GPIO_PINS { \\\n')
      for (gpio, pwm, port, pin, p, enabled) in gpios:
          f.write('{ %3u, %s, %2u, PAL_LINE(GPIO%s,%uU)}, /* %s */ \\\n' %
                  (gpio, enabled, pwm, port, pin, p))
      # and write #defines for use by config code
      f.write('}\n\n')
      f.write('// full pin define list\n')
      last_label = None
      for l in sorted(list(set(bylabel.keys()))):
          p = bylabel[l]
          label = p.label
          label = label.replace('-', '_')
          if label == last_label:
              continue
          last_label = label
          f.write('#define HAL_GPIO_PIN_%-20s PAL_LINE(GPIO%s,%uU)\n' %
                  (label, p.port, p.pin))
      f.write('\n')
function_tokens: def write_GPIO_config ( f ) : f . write ( '// GPIO config\n' ) gpios = [ ] gpioset = set ( ) for l in bylabel : p = bylabel [ l ] gpio = p . extra_value ( 'GPIO' , type = int ) if gpio is None : continue if gpio in gpioset : error ( "Duplicate GPIO value %u" % gpio ) gpioset . add ( gpio ) # see if it is also a PWM pin pwm = p . extra_value ( 'PWM' , type = int , default = 0 ) port = p . port pin = p . pin # default config always enabled gpios . append ( ( gpio , pwm , port , pin , p , 'true' ) ) for alt in altmap . keys ( ) : for pp in altmap [ alt ] . keys ( ) : p = altmap [ alt ] [ pp ] gpio = p . extra_value ( 'GPIO' , type = int ) if gpio is None : continue if gpio in gpioset : # check existing entry existing_gpio = [ item for item in gpios if item [ 0 ] == gpio ] if ( existing_gpio [ 0 ] [ 4 ] . label == p . label ) and ( existing_gpio [ 0 ] [ 3 ] == p . pin ) and ( existing_gpio [ 0 ] [ 2 ] == p . port ) : # alt item is identical to exiting, do not add again continue error ( "Duplicate GPIO value %u, %s != %s" % ( gpio , p , existing_gpio [ 0 ] [ 4 ] ) ) pwm = p . extra_value ( 'PWM' , type = int , default = 0 ) if pwm != 0 : error ( "PWM not supported for alt config: %s" % p ) gpioset . add ( gpio ) port = p . port pin = p . pin # aux config disabled by defualt gpios . append ( ( gpio , pwm , port , pin , p , 'false' ) ) gpios = sorted ( gpios ) for ( gpio , pwm , port , pin , p , enabled ) in gpios : f . write ( '#define HAL_GPIO_LINE_GPIO%u PAL_LINE(GPIO%s,%uU)\n' % ( gpio , port , pin ) ) f . write ( '#define HAL_GPIO_PINS { \\\n' ) for ( gpio , pwm , port , pin , p , enabled ) in gpios : f . write ( '{ %3u, %s, %2u, PAL_LINE(GPIO%s,%uU)}, /* %s */ \\\n' % ( gpio , enabled , pwm , port , pin , p ) ) # and write #defines for use by config code f . write ( '}\n\n' ) f . write ( '// full pin define list\n' ) last_label = None for l in sorted ( list ( set ( bylabel . keys ( ) ) ) ) : p = bylabel [ l ] label = p . label label = label . replace ( '-' , '_' ) if label == last_label : continue last_label = label f . write ( '#define HAL_GPIO_PIN_%-20s PAL_LINE(GPIO%s,%uU)\n' % ( label , p . port , p . pin ) ) f . write ( '\n' )