parameters: (f)
docstring: setup for a CAN enabled board
docstring_summary: setup for a CAN enabled board
docstring_tokens: setup for a CAN enabled board
function: def enable_can(f):
      '''setup for a CAN enabled board'''
      global mcu_series
      if mcu_series.startswith("STM32H7") or mcu_series.startswith("STM32G4"):
          prefix = "FDCAN"
          cast = "CanType"
      else:
          prefix = "CAN"
          cast = "bxcan::CanType"
  
      # allow for optional CAN_ORDER option giving bus order
      can_order_str = get_config('CAN_ORDER', required=False, aslist=True)
      if can_order_str:
          can_order = [int(s) for s in can_order_str]
      else:
          can_order = []
          for i in range(1,3):
              if 'CAN%u' % i in bytype or (i == 1 and 'CAN' in bytype):
                  can_order.append(i)
  
      base_list = []
      for i in can_order:
          base_list.append("reinterpret_cast<%s*>(uintptr_t(%s%s_BASE))" % (cast, prefix, i))
          f.write("#define HAL_CAN_IFACE%u_ENABLE\n" % i)
  
      can_rev_order = [-1]*3
      for i in range(len(can_order)):
          can_rev_order[can_order[i]-1] = i
  
      f.write('#define HAL_CAN_INTERFACE_LIST %s\n' % ','.join([str(i-1) for i in can_order]))
      f.write('#define HAL_CAN_INTERFACE_REV_LIST %s\n' % ','.join([str(i) for i in can_rev_order]))
      f.write('#define HAL_CAN_BASE_LIST %s\n' % ','.join(base_list))
      f.write('#define HAL_NUM_CAN_IFACES %d\n' % len(base_list))
      global mcu_type
      if 'CAN' in bytype and mcu_type.startswith("STM32F3"):
          f.write('#define CAN1_BASE CAN_BASE\n')
      env_vars['HAL_NUM_CAN_IFACES'] = str(len(base_list))
function_tokens: def enable_can ( f ) : global mcu_series if mcu_series . startswith ( "STM32H7" ) or mcu_series . startswith ( "STM32G4" ) : prefix = "FDCAN" cast = "CanType" else : prefix = "CAN" cast = "bxcan::CanType" # allow for optional CAN_ORDER option giving bus order can_order_str = get_config ( 'CAN_ORDER' , required = False , aslist = True ) if can_order_str : can_order = [ int ( s ) for s in can_order_str ] else : can_order = [ ] for i in range ( 1 , 3 ) : if 'CAN%u' % i in bytype or ( i == 1 and 'CAN' in bytype ) : can_order . append ( i ) base_list = [ ] for i in can_order : base_list . append ( "reinterpret_cast<%s*>(uintptr_t(%s%s_BASE))" % ( cast , prefix , i ) ) f . write ( "#define HAL_CAN_IFACE%u_ENABLE\n" % i ) can_rev_order = [ - 1 ] * 3 for i in range ( len ( can_order ) ) : can_rev_order [ can_order [ i ] - 1 ] = i f . write ( '#define HAL_CAN_INTERFACE_LIST %s\n' % ',' . join ( [ str ( i - 1 ) for i in can_order ] ) ) f . write ( '#define HAL_CAN_INTERFACE_REV_LIST %s\n' % ',' . join ( [ str ( i ) for i in can_rev_order ] ) ) f . write ( '#define HAL_CAN_BASE_LIST %s\n' % ',' . join ( base_list ) ) f . write ( '#define HAL_NUM_CAN_IFACES %d\n' % len ( base_list ) ) global mcu_type if 'CAN' in bytype and mcu_type . startswith ( "STM32F3" ) : f . write ( '#define CAN1_BASE CAN_BASE\n' ) env_vars [ 'HAL_NUM_CAN_IFACES' ] = str ( len ( base_list ) )